Skip to content

Commit 433a631

Browse files
author
Alex Huang
committed
Reformat of source code to set a stable base for the future. I couldn't get checkstyle enabled. There's still about a thousand errors from checkstyle. Most of it from length errors from comments and strings. Will attempt to remove those tonight. This change is so large I just want to get it in before any merge nightmares. The changes are fairly minor though and I did a full compile and start a server with the reformat code.
2 parents 3a414a8 + 170f32f commit 433a631

4,708 files changed

Lines changed: 923947 additions & 1093583 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

agent/src/com/cloud/agent/Agent.java

Lines changed: 86 additions & 84 deletions
Large diffs are not rendered by default.

agent/src/com/cloud/agent/AgentShell.java

Lines changed: 39 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@
5555
import com.cloud.utils.exception.CloudRuntimeException;
5656

5757
public class AgentShell implements IAgentShell, Daemon {
58-
private static final Logger s_logger = Logger.getLogger(AgentShell.class
59-
.getName());
58+
private static final Logger s_logger = Logger.getLogger(AgentShell.class.getName());
6059

6160
private final Properties _properties = new Properties();
6261
private final Map<String, Object> _cmdLineProperties = new HashMap<String, Object>();
@@ -76,7 +75,6 @@ public class AgentShell implements IAgentShell, Daemon {
7675
private int _pingRetries;
7776
private final List<Agent> _agents = new ArrayList<Agent>();
7877

79-
8078
public AgentShell() {
8179
}
8280

@@ -180,18 +178,15 @@ void loadProperties() throws ConfigurationException {
180178
propertiesStream = new FileInputStream(file);
181179
_properties.load(propertiesStream);
182180
} catch (final FileNotFoundException ex) {
183-
throw new CloudRuntimeException("Cannot find the file: "
184-
+ file.getAbsolutePath(), ex);
181+
throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
185182
} catch (final IOException ex) {
186-
throw new CloudRuntimeException("IOException in reading "
187-
+ file.getAbsolutePath(), ex);
183+
throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
188184
} finally {
189185
IOUtils.closeQuietly(propertiesStream);
190186
}
191187
}
192188

193-
protected boolean parseCommand(final String[] args)
194-
throws ConfigurationException {
189+
protected boolean parseCommand(final String[] args) throws ConfigurationException {
195190
String host = null;
196191
String workers = null;
197192
String port = null;
@@ -233,8 +228,7 @@ protected boolean parseCommand(final String[] args)
233228

234229
_port = NumberUtils.toInt(port, 8250);
235230

236-
_proxyPort = NumberUtils.toInt(
237-
getProperty(null, "consoleproxy.httpListenPort"), 443);
231+
_proxyPort = NumberUtils.toInt(getProperty(null, "consoleproxy.httpListenPort"), 443);
238232

239233
if (workers == null) {
240234
workers = getProperty(null, "workers");
@@ -268,8 +262,7 @@ protected boolean parseCommand(final String[] args)
268262
}
269263

270264
if (_host == null || (_host.startsWith("@") && _host.endsWith("@"))) {
271-
throw new ConfigurationException(
272-
"Host is not configured correctly: " + _host);
265+
throw new ConfigurationException("Host is not configured correctly: " + _host);
273266
}
274267

275268
final String retries = getProperty(null, "ping.retries");
@@ -292,7 +285,7 @@ protected boolean parseCommand(final String[] args)
292285

293286
return true;
294287
}
295-
288+
296289
@Override
297290
public void init(DaemonContext dc) throws DaemonInitException {
298291
s_logger.debug("Initializing AgentShell from JSVC");
@@ -302,26 +295,25 @@ public void init(DaemonContext dc) throws DaemonInitException {
302295
throw new DaemonInitException("Initialization failed", ex);
303296
}
304297
}
305-
298+
306299
public void init(String[] args) throws ConfigurationException {
307300

308-
// PropertiesUtil is used both in management server and agent packages,
309-
// it searches path under class path and common J2EE containers
310-
// For KVM agent, do it specially here
311-
312-
File file = new File("/etc/cloudstack/agent/log4j-cloud.xml");
313-
if(!file.exists()) {
314-
file = PropertiesUtil.findConfigFile("log4j-cloud.xml");
315-
}
316-
DOMConfigurator.configureAndWatch(file.getAbsolutePath());
317-
318-
s_logger.info("Agent started");
319-
301+
// PropertiesUtil is used both in management server and agent packages,
302+
// it searches path under class path and common J2EE containers
303+
// For KVM agent, do it specially here
304+
305+
File file = new File("/etc/cloudstack/agent/log4j-cloud.xml");
306+
if (!file.exists()) {
307+
file = PropertiesUtil.findConfigFile("log4j-cloud.xml");
308+
}
309+
DOMConfigurator.configureAndWatch(file.getAbsolutePath());
310+
311+
s_logger.info("Agent started");
312+
320313
final Class<?> c = this.getClass();
321314
_version = c.getPackage().getImplementationVersion();
322315
if (_version == null) {
323-
throw new CloudRuntimeException(
324-
"Unable to find the implementation version of this agent");
316+
throw new CloudRuntimeException("Unable to find the implementation version of this agent");
325317
}
326318
s_logger.info("Implementation Version is " + _version);
327319

@@ -330,19 +322,18 @@ public void init(String[] args) throws ConfigurationException {
330322

331323
if (s_logger.isDebugEnabled()) {
332324
List<String> properties = Collections.list((Enumeration<String>)_properties.propertyNames());
333-
for (String property:properties){
325+
for (String property : properties) {
334326
s_logger.debug("Found property: " + property);
335327
}
336328
}
337-
329+
338330
s_logger.info("Defaulting to using properties file for storage");
339331
_storage = new PropertiesStorage();
340332
_storage.configure("Storage", new HashMap<String, Object>());
341333

342334
// merge with properties from command line to let resource access
343335
// command line parameters
344-
for (Map.Entry<String, Object> cmdLineProp : getCmdLineProperties()
345-
.entrySet()) {
336+
for (Map.Entry<String, Object> cmdLineProp : getCmdLineProperties().entrySet()) {
346337
_properties.put(cmdLineProp.getKey(), cmdLineProp.getValue());
347338
}
348339

@@ -362,46 +353,30 @@ private void launchAgent() throws ConfigurationException {
362353
launchAgentFromTypeInfo();
363354
}
364355

365-
private void launchAgentFromClassInfo(String resourceClassNames)
366-
throws ConfigurationException {
356+
private void launchAgentFromClassInfo(String resourceClassNames) throws ConfigurationException {
367357
String[] names = resourceClassNames.split("\\|");
368358
for (String name : names) {
369359
Class<?> impl;
370360
try {
371361
impl = Class.forName(name);
372-
final Constructor<?> constructor = impl
373-
.getDeclaredConstructor();
362+
final Constructor<?> constructor = impl.getDeclaredConstructor();
374363
constructor.setAccessible(true);
375-
ServerResource resource = (ServerResource) constructor
376-
.newInstance();
364+
ServerResource resource = (ServerResource)constructor.newInstance();
377365
launchAgent(getNextAgentId(), resource);
378366
} catch (final ClassNotFoundException e) {
379-
throw new ConfigurationException("Resource class not found: "
380-
+ name + " due to: " + e.toString());
367+
throw new ConfigurationException("Resource class not found: " + name + " due to: " + e.toString());
381368
} catch (final SecurityException e) {
382-
throw new ConfigurationException(
383-
"Security excetion when loading resource: " + name
384-
+ " due to: " + e.toString());
369+
throw new ConfigurationException("Security excetion when loading resource: " + name + " due to: " + e.toString());
385370
} catch (final NoSuchMethodException e) {
386-
throw new ConfigurationException(
387-
"Method not found excetion when loading resource: "
388-
+ name + " due to: " + e.toString());
371+
throw new ConfigurationException("Method not found excetion when loading resource: " + name + " due to: " + e.toString());
389372
} catch (final IllegalArgumentException e) {
390-
throw new ConfigurationException(
391-
"Illegal argument excetion when loading resource: "
392-
+ name + " due to: " + e.toString());
373+
throw new ConfigurationException("Illegal argument excetion when loading resource: " + name + " due to: " + e.toString());
393374
} catch (final InstantiationException e) {
394-
throw new ConfigurationException(
395-
"Instantiation excetion when loading resource: " + name
396-
+ " due to: " + e.toString());
375+
throw new ConfigurationException("Instantiation excetion when loading resource: " + name + " due to: " + e.toString());
397376
} catch (final IllegalAccessException e) {
398-
throw new ConfigurationException(
399-
"Illegal access exception when loading resource: "
400-
+ name + " due to: " + e.toString());
377+
throw new ConfigurationException("Illegal access exception when loading resource: " + name + " due to: " + e.toString());
401378
} catch (final InvocationTargetException e) {
402-
throw new ConfigurationException(
403-
"Invocation target exception when loading resource: "
404-
+ name + " due to: " + e.toString());
379+
throw new ConfigurationException("Invocation target exception when loading resource: " + name + " due to: " + e.toString());
405380
}
406381
}
407382
}
@@ -410,14 +385,12 @@ private void launchAgentFromTypeInfo() throws ConfigurationException {
410385
String typeInfo = getProperty(null, "type");
411386
if (typeInfo == null) {
412387
s_logger.error("Unable to retrieve the type");
413-
throw new ConfigurationException(
414-
"Unable to retrieve the type of this agent.");
388+
throw new ConfigurationException("Unable to retrieve the type of this agent.");
415389
}
416390
s_logger.trace("Launching agent based on type=" + typeInfo);
417391
}
418392

419-
private void launchAgent(int localAgentId, ServerResource resource)
420-
throws ConfigurationException {
393+
private void launchAgent(int localAgentId, ServerResource resource) throws ConfigurationException {
421394
// we don't track agent after it is launched for now
422395
Agent agent = new Agent(this, localAgentId, resource);
423396
_agents.add(agent);
@@ -428,6 +401,7 @@ public synchronized int getNextAgentId() {
428401
return _nextAgentId++;
429402
}
430403

404+
@Override
431405
public void start() {
432406
try {
433407
/* By default we only search for log4j.xml */
@@ -471,10 +445,12 @@ public void start() {
471445
}
472446
}
473447

448+
@Override
474449
public void stop() {
475450
_exit = true;
476451
}
477452

453+
@Override
478454
public void destroy() {
479455

480456
}

agent/src/com/cloud/agent/dao/StorageComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import com.cloud.utils.component.Manager;
2020

2121
/**
22-
*
22+
*
2323
*/
2424
public interface StorageComponent extends Manager {
2525
String get(String key);

agent/src/com/cloud/agent/dao/impl/PropertiesStorage.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@
3333

3434
/**
3535
* Uses Properties to implement storage.
36-
*
36+
*
3737
* @config {@table || Param Name | Description | Values | Default || || path |
3838
* path to the properties _file | String | db/db.properties || * }
3939
**/
40-
@Local(value = { StorageComponent.class })
40+
@Local(value = {StorageComponent.class})
4141
public class PropertiesStorage implements StorageComponent {
42-
private static final Logger s_logger = Logger
43-
.getLogger(PropertiesStorage.class);
42+
private static final Logger s_logger = Logger.getLogger(PropertiesStorage.class);
4443
Properties _properties = new Properties();
4544
File _file;
4645
String _name;
@@ -69,7 +68,7 @@ public synchronized void persist(String key, String value) {
6968
@Override
7069
public boolean configure(String name, Map<String, Object> params) {
7170
_name = name;
72-
String path = (String) params.get("path");
71+
String path = (String)params.get("path");
7372
if (path == null) {
7473
path = "agent.properties";
7574
}
@@ -79,13 +78,11 @@ public boolean configure(String name, Map<String, Object> params) {
7978
file = new File(path);
8079
try {
8180
if (!file.createNewFile()) {
82-
s_logger.error("Unable to create _file: "
83-
+ file.getAbsolutePath());
81+
s_logger.error("Unable to create _file: " + file.getAbsolutePath());
8482
return false;
8583
}
8684
} catch (IOException e) {
87-
s_logger.error(
88-
"Unable to create _file: " + file.getAbsolutePath(), e);
85+
s_logger.error("Unable to create _file: " + file.getAbsolutePath(), e);
8986
return false;
9087
}
9188
}

agent/src/com/cloud/agent/dhcp/DhcpProtocolParserServer.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.net.DatagramPacket;
2121
import java.net.DatagramSocket;
2222
import java.net.InetAddress;
23-
2423
import java.util.concurrent.ExecutorService;
2524
import java.util.concurrent.LinkedBlockingQueue;
2625
import java.util.concurrent.ThreadPoolExecutor;
@@ -31,25 +30,22 @@
3130
import com.cloud.utils.concurrency.NamedThreadFactory;
3231

3332
public class DhcpProtocolParserServer extends Thread {
34-
private static final Logger s_logger = Logger
35-
.getLogger(DhcpProtocolParserServer.class);;
33+
private static final Logger s_logger = Logger.getLogger(DhcpProtocolParserServer.class);;
3634
protected ExecutorService _executor;
3735
private int dhcpServerPort = 67;
3836
private int bufferSize = 300;
3937
protected boolean _running = false;
4038

4139
public DhcpProtocolParserServer(int workers) {
42-
_executor = new ThreadPoolExecutor(workers, 10 * workers, 1,
43-
TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(),
44-
new NamedThreadFactory("DhcpListener"));
40+
_executor = new ThreadPoolExecutor(workers, 10 * workers, 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("DhcpListener"));
4541
_running = true;
4642
}
4743

44+
@Override
4845
public void run() {
4946
while (_running) {
5047
try {
51-
DatagramSocket dhcpSocket = new DatagramSocket(dhcpServerPort,
52-
InetAddress.getByAddress(new byte[] { 0, 0, 0, 0 }));
48+
DatagramSocket dhcpSocket = new DatagramSocket(dhcpServerPort, InetAddress.getByAddress(new byte[] {0, 0, 0, 0}));
5349
dhcpSocket.setBroadcast(true);
5450

5551
while (true) {

agent/src/com/cloud/agent/dhcp/DhcpSnooper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public interface DhcpSnooper extends Adapter {
3333

3434
public Map<String, InetAddress> syncIpAddr();
3535

36+
@Override
3637
public boolean stop();
3738

3839
public void initializeMacTable(List<Pair<String, String>> macVmNameList);

0 commit comments

Comments
 (0)