fixing some whitespace issues - checkstyle

This commit is contained in:
David Nalley 2012-02-10 19:22:03 -05:00
parent fbf47f2f4c
commit 66b33b4f57
5 changed files with 142 additions and 113 deletions

View File

@ -666,7 +666,7 @@ public class Agent implements HandlerFactory, IAgentControl {
@Override
public AgentControlAnswer sendRequest(AgentControlCommand cmd, int timeoutInMilliseconds) throws AgentControlChannelException {
Request request = new Request(this.getId(), -1, new Command[] { cmd }, true, false);
Request request = new Request(this.getId(), -1, new Command[] { cmd } , true, false);
request.setSequence(getNextSequence());
AgentControlListener listener = new AgentControlListener(request);
@ -690,7 +690,7 @@ public class Agent implements HandlerFactory, IAgentControl {
@Override
public void postRequest(AgentControlCommand cmd) throws AgentControlChannelException {
Request request = new Request(this.getId(), -1, new Command[] { cmd }, true, false);
Request request = new Request(this.getId(), -1, new Command[] { cmd } , true, false);
request.setSequence(getNextSequence());
postRequest(request);
}

View File

@ -125,7 +125,7 @@ public class CloudZonesComputingResource extends LibvirtComputingResource {
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
boolean success = super.configure(name, params);
if (! success) {
if (!success) {
return false;
}

View File

@ -423,7 +423,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
boolean success = super.configure(name, params);
if (! success) {
if (!success) {
return false;
}
@ -462,7 +462,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
storageScriptsDir = getDefaultStorageScriptsDir();
}
if ( ! success) {
if ( !success) {
return false;
}

View File

@ -256,7 +256,7 @@ public class JettyVmDataServer implements VmDataServer {
connector1.setMaxIdleTime(30000);
connector1.setRequestBufferSize(8192);
_jetty.setConnectors(new Connector[]{ connector0, connector1});
_jetty.setConnectors(new Connector[] {connector0, connector1});
Context root = new Context(_jetty,"/latest",Context.SESSIONS);
root.setResourceBase(_vmDataDir);
@ -267,7 +267,7 @@ public class JettyVmDataServer implements VmDataServer {
resource_handler.setResourceBase("/var/lib/images/");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { root, resource_handler, new DefaultHandler() });
handlers.setHandlers(new Handler[] {root, resource_handler, new DefaultHandler() });
_jetty.setHandler(handlers);
_jetty.start();

View File

@ -37,113 +37,132 @@ import com.cloud.utils.db.SearchCriteria2;
import com.cloud.utils.exception.CloudRuntimeException;
import com.cloud.utils.ssh.SSHCmdHelper;
@Local(value=Discoverer.class)
public class OvmDiscoverer extends DiscovererBase implements Discoverer, ResourceStateAdapter {
private static final Logger s_logger = Logger.getLogger(OvmDiscoverer.class);
@Local(value = Discoverer.class)
public class OvmDiscoverer extends DiscovererBase implements Discoverer,
ResourceStateAdapter {
private static final Logger s_logger = Logger
.getLogger(OvmDiscoverer.class);
protected String _publicNetworkDevice;
protected String _privateNetworkDevice;
protected String _guestNetworkDevice;
@Inject ClusterDao _clusterDao;
@Inject ResourceManager _resourceMgr;
@Inject
ClusterDao _clusterDao;
@Inject
ResourceManager _resourceMgr;
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
super.configure(name, params);
_publicNetworkDevice = _params.get(Config.OvmPublicNetwork.key());
_privateNetworkDevice = _params.get(Config.OvmPrivateNetwork.key());
_guestNetworkDevice = _params.get(Config.OvmGuestNetwork.key());
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
_resourceMgr.registerResourceStateAdapter(this.getClass()
.getSimpleName(), this);
return true;
}
protected OvmDiscoverer() {
}
@Override
public boolean stop() {
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
return super.stop();
}
@Override
public boolean stop() {
_resourceMgr.unregisterResourceStateAdapter(this.getClass()
.getSimpleName());
return super.stop();
}
private boolean checkIfExisted(String guid) {
SearchCriteria2<HostVO, Long> sc = SearchCriteria2.create(HostVO.class, Long.class);
SearchCriteria2<HostVO, Long> sc = SearchCriteria2.create(HostVO.class,
Long.class);
sc.addAnd(sc.getEntity().getGuid(), SearchCriteria.Op.EQ, guid);
sc.addAnd(sc.getEntity().getHypervisorType(), SearchCriteria.Op.EQ, HypervisorType.Ovm);
sc.addAnd(sc.getEntity().getHypervisorType(), SearchCriteria.Op.EQ,
HypervisorType.Ovm);
List<Long> hosts = sc.list();
return !hosts.isEmpty();
}
@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId,
Long podId, Long clusterId, URI url, String username,
String password, List<String> hostTags) throws DiscoveryException {
Connection conn = null;
if (!url.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
s_logger.debug(msg);
return null;
}
if (clusterId == null) {
String msg = "must specify cluster Id when add host";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
if (!url.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of the discovery for this: "
+ url;
s_logger.debug(msg);
return null;
}
if (clusterId == null) {
String msg = "must specify cluster Id when add host";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
if (podId == null) {
String msg = "must specify pod Id when add host";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
ClusterVO cluster = _clusterDao.findById(clusterId);
if(cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm)) {
if(s_logger.isInfoEnabled())
s_logger.info("invalid cluster id or cluster is not for Ovm hypervisors");
return null;
}
String agentUsername = _params.get("agentusername");
if (agentUsername == null) {
throw new CloudRuntimeException("Agent user name must be specified");
}
String agentPassword = _params.get("agentpassword");
if (agentPassword == null) {
throw new CloudRuntimeException("Agent password must be specified");
}
try {
String hostname = url.getHost();
InetAddress ia = InetAddress.getByName(hostname);
String hostIp = ia.getHostAddress();
String guid = UUID.nameUUIDFromBytes(hostIp.getBytes()).toString();
if (checkIfExisted(guid)) {
throw new CloudRuntimeException("The host " + hostIp + " has been added before");
}
s_logger.debug("Ovm discover is going to disover host having guid " + guid);
ClusterVO clu = _clusterDao.findById(clusterId);
ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null
|| (cluster.getHypervisorType() != HypervisorType.Ovm)) {
if (s_logger.isInfoEnabled())
s_logger.info("invalid cluster id or cluster is not for Ovm hypervisors");
return null;
}
String agentUsername = _params.get("agentusername");
if (agentUsername == null) {
throw new CloudRuntimeException("Agent user name must be specified");
}
String agentPassword = _params.get("agentpassword");
if (agentPassword == null) {
throw new CloudRuntimeException("Agent password must be specified");
}
try {
String hostname = url.getHost();
InetAddress ia = InetAddress.getByName(hostname);
String hostIp = ia.getHostAddress();
String guid = UUID.nameUUIDFromBytes(hostIp.getBytes()).toString();
if (checkIfExisted(guid)) {
throw new CloudRuntimeException("The host " + hostIp
+ " has been added before");
}
s_logger.debug("Ovm discover is going to disover host having guid "
+ guid);
ClusterVO clu = _clusterDao.findById(clusterId);
if (clu.getGuid() == null) {
clu.setGuid(UUID.randomUUID().toString());
_clusterDao.update(clusterId, clu);
}
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(hostIp, 22);
sshConnection.connect(null, 60000, 60000);
sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp, username, password);
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(
hostIp, 22);
sshConnection.connect(null, 60000, 60000);
sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp,
username, password);
if (sshConnection == null) {
throw new DiscoveryException(
String.format("Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s, discover failed", hostIp, username, password));
String.format(
"Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s, discover failed",
hostIp, username, password));
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/etc/ovs-agent/agent.ini' ]")) {
throw new DiscoveryException("Can not find /etc/ovs-agent/agent.ini " + hostIp);
if (!SSHCmdHelper.sshExecuteCmd(sshConnection,
"[ -f '/etc/ovs-agent/agent.ini' ]")) {
throw new DiscoveryException(
"Can not find /etc/ovs-agent/agent.ini " + hostIp);
}
Map<String, String> details = new HashMap<String, String>();
OvmResourceBase ovmResource = new OvmResourceBase();
details.put("ip", hostIp);
@ -164,35 +183,40 @@ public class OvmDiscoverer extends DiscovererBase implements Discoverer, Resourc
if (_guestNetworkDevice != null) {
details.put("guest.network.device", _guestNetworkDevice);
}
Map<String, Object> params = new HashMap<String, Object>();
params.putAll(details);
ovmResource.configure("Ovm Server", params);
ovmResource.start();
conn = new Connection(hostIp, "oracle", agentPassword);
/* After resource start, we are able to execute our agent api*/
conn = new Connection(hostIp, "oracle", agentPassword);
/* After resource start, we are able to execute our agent api */
OvmHost.Details d = OvmHost.getDetails(conn);
details.put("agentVersion", d.agentVersion);
details.put(HostInfo.HOST_OS_KERNEL_VERSION, d.dom0KernelVersion);
details.put(HostInfo.HYPERVISOR_VERSION, d.hypervisorVersion);
Map<OvmResourceBase, Map<String, String>> resources = new HashMap<OvmResourceBase, Map<String, String>>();
resources.put(ovmResource, details);
return resources;
} catch (XmlRpcException e) {
s_logger.debug("XmlRpc exception, Unable to discover OVM: " + url, e);
return null;
} catch (XmlRpcException e) {
s_logger.debug("XmlRpc exception, Unable to discover OVM: " + url,
e);
return null;
} catch (UnknownHostException e) {
s_logger.debug("Host name resolve failed exception, Unable to discover OVM: " + url, e);
s_logger.debug(
"Host name resolve failed exception, Unable to discover OVM: "
+ url, e);
return null;
} catch (ConfigurationException e) {
s_logger.debug("Configure resource failed, Unable to discover OVM: " + url, e);
s_logger.debug(
"Configure resource failed, Unable to discover OVM: " + url,
e);
return null;
} catch (Exception e) {
s_logger.debug("Unable to discover OVM: " + url, e);
return null;
}
s_logger.debug("Unable to discover OVM: " + url, e);
return null;
}
}
@Override
@ -213,35 +237,40 @@ public class OvmDiscoverer extends DiscovererBase implements Discoverer, Resourc
}
@Override
public HostVO createHostVOForConnectedAgent(HostVO host, StartupCommand[] cmd) {
// TODO Auto-generated method stub
return null;
}
public HostVO createHostVOForConnectedAgent(HostVO host,
StartupCommand[] cmd) {
// TODO Auto-generated method stub
return null;
}
@Override
public HostVO createHostVOForDirectConnectAgent(HostVO host, StartupCommand[] startup, ServerResource resource, Map<String, String> details,
List<String> hostTags) {
public HostVO createHostVOForDirectConnectAgent(HostVO host,
StartupCommand[] startup, ServerResource resource,
Map<String, String> details, List<String> hostTags) {
StartupCommand firstCmd = startup[0];
if (!(firstCmd instanceof StartupRoutingCommand)) {
return null;
}
StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
if (ssCmd.getHypervisorType() != HypervisorType.Ovm) {
return null;
}
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Ovm, details, hostTags);
}
@Override
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
if (host.getType() != com.cloud.host.Host.Type.Routing || host.getHypervisorType() != HypervisorType.Ovm) {
if (!(firstCmd instanceof StartupRoutingCommand)) {
return null;
}
StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
if (ssCmd.getHypervisorType() != HypervisorType.Ovm) {
return null;
}
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Ovm,
details, hostTags);
}
@Override
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
boolean isForceDeleteStorage) throws UnableDeleteHostException {
if (host.getType() != com.cloud.host.Host.Type.Routing
|| host.getHypervisorType() != HypervisorType.Ovm) {
return null;
}
_resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
return new DeleteHostAnswer(true);
}
}
}