fixing more whitespace issues

This commit is contained in:
David Nalley 2012-01-25 00:18:37 -05:00
parent 48943f52bf
commit 49ebeb901e
15 changed files with 564 additions and 564 deletions

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2011 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -109,7 +109,7 @@ import com.cloud.vm.VirtualMachine.State;
/**
* Pretends to be a computing resource
*
*
*/
@Local(value={ServerResource.class})
public class FakeComputingResource extends ServerResourceBase implements ServerResource {
@ -130,7 +130,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
public StartupCommand[] initialize() {
Map<String, VmState> changes = null;
final List<Object> info = getHostInfo();
final StartupRoutingCommand cmd = new StartupRoutingCommand((Integer)info.get(0), (Long)info.get(1), (Long)info.get(2), (Long)info.get(4), (String)info.get(3), HypervisorType.KVM, RouterPrivateIpStrategy.HostLocal, changes);
@ -145,7 +145,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
sscmd.setResourceType(Storage.StorageResourceType.STORAGE_POOL);
return new StartupCommand[]{cmd, sscmd};
}
private Map<String, String> getVersionStrings() {
@ -153,8 +153,8 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
String hostOs = (String) _params.get("Host.OS");
String hostOsVer = (String) _params.get("Host.OS.Version");
String hostOsKernVer = (String) _params.get("Host.OS.Kernel.Version");
result.put("Host.OS", hostOs==null?"Fedora":hostOs);
result.put("Host.OS.Version", hostOsVer==null?"14":hostOsVer);
result.put("Host.OS", hostOs==null?"Fedora":hostOs);
result.put("Host.OS.Version", hostOsVer==null?"14":hostOsVer);
result.put("Host.OS.Kernel.Version", hostOsKernVer==null?"2.6.35.6-45.fc14.x86_64":hostOsKernVer);
return result;
}
@ -164,29 +164,29 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
cmd.setPrivateIpAddress((String)_params.get("private.ip.address"));
cmd.setPrivateMacAddress((String)_params.get("private.mac.address"));
cmd.setPrivateNetmask((String)_params.get("private.ip.netmask"));
cmd.setStorageIpAddress((String)_params.get("private.ip.address"));
cmd.setStorageMacAddress((String)_params.get("private.mac.address"));
cmd.setStorageNetmask((String)_params.get("private.ip.netmask"));
cmd.setGatewayIpAddress((String)_params.get("gateway.ip.address"));
}
protected StoragePoolInfo initializeLocalStorage() {
String hostIp = (String)_params.get("private.ip.address");
String localStoragePath = (String)_params.get("local.storage.path");
String lh = hostIp + localStoragePath;
String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
String capacity = (String)_params.get("local.storage.capacity");
String available = (String)_params.get("local.storage.avail");
return new StoragePoolInfo(uuid, hostIp, localStoragePath,
localStoragePath, StoragePoolType.Filesystem,
return new StoragePoolInfo(uuid, hostIp, localStoragePath,
localStoragePath, StoragePoolType.Filesystem,
Long.parseLong(capacity), Long.parseLong(available));
}
@Override
public PingCommand getCurrentStatus(long id) {
final HashMap<String, State> newStates = new HashMap<String, State>();
@ -205,7 +205,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
return execute((GetHostStatsCommand)cmd);
} else if (cmd instanceof PrimaryStorageDownloadCommand) {
return execute((PrimaryStorageDownloadCommand) cmd);
} else if (cmd instanceof StopCommand) {
return execute((StopCommand)cmd);
} else if (cmd instanceof GetVmStatsCommand) {
@ -295,7 +295,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
protected synchronized ReadyAnswer execute(ReadyCommand cmd) {
return new ReadyAnswer(cmd);
}
private Answer execute(PrimaryStorageDownloadCommand cmd) {
return new PrimaryStorageDownloadAnswer(cmd.getLocalPath(), 16000000L);
}
@ -308,23 +308,23 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
protected String getDefaultScriptsDir() {
return null;
}
protected String getConfiguredProperty(String key, String defaultValue) {
String val = (String)_params.get(key);
return val==null?defaultValue:val;
}
protected Long getConfiguredProperty(String key, Long defaultValue) {
String val = (String)_params.get(key);
if (val != null) {
Long result = Long.parseLong(val);
return result;
}
return defaultValue;
}
protected List<Object> getHostInfo() {
final ArrayList<Object> info = new ArrayList<Object>();
long speed = getConfiguredProperty("cpuspeed", 4000L) ;
@ -338,9 +338,9 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
info.add(speed);
info.add(ram);
info.add(cap);
info.add(dom0ram);
info.add(dom0ram);
return info;
}
private Map<String, Object> getSimulatorProperties() throws ConfigurationException {
final File file = PropertiesUtil.findConfigFile("simulator.properties");
@ -353,10 +353,10 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
try {
properties.load(new FileInputStream(file));
final Map<String, Object> params = PropertiesUtil.toMap(properties);
return params;
} catch (final FileNotFoundException ex) {
throw new CloudRuntimeException("Cannot find the file: " + file.getAbsolutePath(), ex);
@ -364,9 +364,9 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
throw new CloudRuntimeException("IOException in reading " + file.getAbsolutePath(), ex);
}
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
@ -387,7 +387,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
return _params;
}
protected synchronized StartAnswer execute(StartCommand cmd) {
VmMgr vmMgr = getVmManager();
@ -404,7 +404,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
MockVm vm = vmMgr.createVmFromSpec(vmSpec);
vmMgr.createVbd(vmSpec, vmName, vm);
vmMgr.createVif(vmSpec, vmName, vm);
state = State.Running;
for (NicTO nic: cmd.getVirtualMachine().getNics()) {
if (nic.getType() == TrafficType.Guest) {
@ -440,7 +440,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
Long bytesReceived = null;
Long bytesSent = null;
State state = null;
synchronized (_vms) {
@ -471,7 +471,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
answer = new StopAnswer(cmd, result, port, bytesSent,
bytesReceived);
}
_dhcpSnooper.cleanup(vmName, null);
return answer;
@ -487,11 +487,11 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
protected Answer execute(final VmDataCommand cmd) {
return _vmDataServer.handleVmDataCommand(cmd);
}
protected Answer execute(final SavePasswordCommand cmd) {
return new Answer(cmd);
}
protected Answer execute(RebootCommand cmd) {
VmMgr vmMgr = getVmManager();
vmMgr.rebootVM(cmd.getVmName());
@ -501,15 +501,15 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
private Answer execute(PingTestCommand cmd) {
return new Answer(cmd);
}
protected GetVmStatsAnswer execute(GetVmStatsCommand cmd) {
return null;
}
private VmMgr getVmManager() {
return _vmManager;
}
protected Answer execute(GetHostStatsCommand cmd) {
VmMgr vmMgr = getVmManager();
return new GetHostStatsAnswer(cmd, vmMgr.getHostCpuUtilization(), vmMgr
@ -526,7 +526,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
return new CheckHealthAnswer(cmd, true);
}
protected CheckVirtualMachineAnswer execute(
final CheckVirtualMachineCommand cmd) {
VmMgr vmMgr = getVmManager();
@ -565,7 +565,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
return new CreateAnswer(cmd, new Exception("Unexpected exception"));
}
}
protected HashMap<String, State> sync() {
@ -645,7 +645,7 @@ public class FakeComputingResource extends ServerResourceBase implements ServerR
return changes;
}
protected Answer execute(DestroyCommand cmd) {
return new Answer(cmd, true, null);
}

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -45,7 +45,7 @@ public class KVMGuestOsMapper {
s_mapper.put("CentOS 5.5 (64-bit)", "CentOS 5.5");
s_mapper.put("Red Hat Enterprise Linux 2", "Red Hat Enterprise Linux 2");
s_mapper.put("Red Hat Enterprise Linux 3 (32-bit)", "Red Hat Enterprise Linux 3");
s_mapper.put("Red Hat Enterprise Linux 3 (64-bit)", "Red Hat Enterprise Linux 3");
s_mapper.put("Red Hat Enterprise Linux 3 (64-bit)", "Red Hat Enterprise Linux 3");
s_mapper.put("Red Hat Enterprise Linux 4(64-bit)", "Red Hat Enterprise Linux 4");
s_mapper.put("Red Hat Enterprise Linux 4.5 (32-bit)", "Red Hat Enterprise Linux 4.5");
s_mapper.put("Red Hat Enterprise Linux 4.6 (32-bit)", "Red Hat Enterprise Linux 4.6");
@ -127,7 +127,7 @@ public class KVMGuestOsMapper {
s_mapper.put("Other PV (64-bit)", "Other PV");
}
public static String getGuestOsName(String guestOsName) {
String guestOS = s_mapper.get(guestOsName);
if (guestOS == null) {

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -46,13 +46,13 @@ public class KVMHABase {
PrimaryStorage,
SecondaryStorage
}
public static class NfsStoragePool {
public static class NfsStoragePool {
String _poolUUID;
String _poolIp;
String _poolMountSourcePath;
String _mountDestPath;
PoolType _type;
public NfsStoragePool(String poolUUID, String poolIp, String poolSourcePath, String mountDestPath, PoolType type) {
this._poolUUID = poolUUID;
this._poolIp = poolIp;
@ -61,12 +61,12 @@ public class KVMHABase {
this._type = type;
}
}
protected String checkingMountPoint(NfsStoragePool pool, String poolName) {
String mountSource = pool._poolIp + ":" + pool._poolMountSourcePath;
String mountPaths = Script.runSimpleBashScript("cat /proc/mounts | grep " + mountSource);
String destPath = pool._mountDestPath;
if (mountPaths != null) {
String token[] = mountPaths.split(" ");
String mountType = token[2];
@ -97,16 +97,16 @@ public class KVMHABase {
if (result != null) {
destPath = null;
}
destroyVMs(destPath);
}
}
return destPath;
}
protected String getMountPoint(NfsStoragePool storagePool) {
StoragePool pool = null;
String poolName = null;
try {
@ -121,7 +121,7 @@ public class KVMHABase {
}
poolName = pool.getName();
} catch (LibvirtException e) {
} finally {
try {
if (pool != null) {
@ -131,9 +131,9 @@ public class KVMHABase {
}
}
return checkingMountPoint(storagePool, poolName);
}
}
protected void destroyVMs(String mountPath) {
/*if there are VMs using disks under this mount path, destroy them*/
@ -142,25 +142,25 @@ public class KVMHABase {
cmd.add("ps axu|grep qemu|grep " + mountPath + "* |awk '{print $2}'");
AllLinesParser parser = new OutputInterpreter.AllLinesParser();
String result = cmd.execute(parser);
if (result != null) {
return;
}
String pids[] = parser.getLines().split("\n");
for (String pid : pids) {
Script.runSimpleBashScript("kill -9 " + pid);
}
}
protected String getHBFile(String mountPoint, String hostIP) {
return mountPoint + File.separator + "KVMHA" + File.separator + "hb-" + hostIP;
}
protected String getHBFolder(String mountPoint) {
return mountPoint + File.separator + "KVMHA" + File.separator;
}
protected String runScriptRetry(String cmdString, OutputInterpreter interpreter) {
String result = null;
for (int i = 0; i < 3; i++) {
@ -172,31 +172,31 @@ public class KVMHABase {
else {
result = cmd.execute();
}
if (result == Script.ERR_TIMEOUT) {
if (result == Script.ERR_TIMEOUT) {
continue;
} else if (result == null) {
break;
}
}
return result;
}
public static void main(String[] args) {
NfsStoragePool pool = new KVMHAMonitor.NfsStoragePool(null,null,null,null, PoolType.PrimaryStorage);
KVMHAMonitor haWritter = new KVMHAMonitor(pool, "192.168.1.163", null);
Thread ha = new Thread(haWritter);
ha.start();
KVMHAChecker haChecker = new KVMHAChecker(haWritter.getStoragePools(), "192.168.1.163");
ExecutorService exe = Executors.newFixedThreadPool(1);
Future<Boolean> future = exe.submit((Callable<Boolean>)haChecker);
try {
for (int i = 0; i < 10; i++) {
System.out.println(future.get());
System.out.println(future.get());
future = exe.submit((Callable<Boolean>)haChecker);
}
} catch (InterruptedException e) {
@ -206,7 +206,7 @@ public class KVMHABase {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -38,12 +38,12 @@ public class KVMHAChecker extends KVMHABase implements Callable<Boolean> {
this._pools = pools;
this._hostIP = host;
}
/*True means heartbeaing is on going, or we can't get it's status. False means heartbeating is stopped definitely */
private Boolean checkingHB() {
List<Boolean> results = new ArrayList<Boolean>();
for (NfsStoragePool pool : _pools) {
Script cmd = new Script(_heartBeatPath, _heartBeatCheckerTimeout, s_logger);
cmd.add("-i", pool._poolIp);
cmd.add("-p", pool._poolMountSourcePath);
@ -63,20 +63,20 @@ public class KVMHAChecker extends KVMHABase implements Callable<Boolean> {
results.add(true);
}
}
for (Boolean r : results) {
if (r) {
return true;
}
}
return false;
}
@Override
public Boolean call() throws Exception {
//s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new org.apache.log4j.PatternLayout(), "System.out"));
return checkingHB();
return checkingHB();
}
}

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -54,12 +54,12 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser {
_domainTypeKVM = false;
} else if (qName.equalsIgnoreCase("emulator")) {
_emulatorFlag = false;
} else if (_host) {
_capXML.append("<").append("/").append(qName).append(">");
}
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (_host) {
@ -70,7 +70,7 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser {
_emulator.append(ch, start, length);
}
}
@Override
public void startElement(String uri, String localName, String qName,
@ -102,7 +102,7 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser {
}
}
public String parseCapabilitiesXML(String capXML) {
if (!_initialized){
return null;
@ -110,22 +110,22 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser {
try {
_sp.parse(new InputSource(new StringReader(capXML)), this);
return _capXML.toString();
}catch(SAXException se) {
} catch(SAXException se) {
s_logger.warn(se.getMessage());
}catch (IOException ie) {
} catch (IOException ie) {
s_logger.error(ie.getMessage());
}
return null;
}
public ArrayList<String> getGuestOsType() {
return guestOsTypes;
}
public String getEmulator() {
return _emulator.toString();
}
public static void main(String [] args) {
String capXML = "<capabilities>"+
" <host>"+
@ -218,7 +218,7 @@ public class LibvirtCapXMLParser extends LibvirtXMLParser {
" </features>"+
" </guest>"+
"</capabilities>";
LibvirtCapXMLParser parser = new LibvirtCapXMLParser();
String cap = parser.parseCapabilitiesXML(capXML);
System.out.println(parser.getGuestOsType());

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -38,10 +38,10 @@ public class LibvirtConnection {
_connection = new Connect(_hypervisorURI, false);
}
}
return _connection;
}
static void initialize(String hypervisorURI) {
_hypervisorURI = hypervisorURI;
}

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -51,20 +51,20 @@ public class LibvirtDomainXMLParser {
private final List<DiskDef> diskDefs = new ArrayList<DiskDef>();
private Integer vncPort;
private String desc;
public boolean parseDomainXML(String domXML) {
DocumentBuilder builder;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(domXML));
Document doc = builder.parse(is);
Element rootElement = doc.getDocumentElement();
desc = getTagValue("description", rootElement);
Element devices = (Element)rootElement.getElementsByTagName("devices").item(0);
NodeList disks = devices.getElementsByTagName("disk");
for (int i = 0; i < disks.getLength(); i++) {
@ -77,7 +77,7 @@ public class LibvirtDomainXMLParser {
String bus = getAttrValue("target", "bus", disk);
String type = disk.getAttribute("type");
String device = disk.getAttribute("device");
DiskDef def = new DiskDef();
if (type.equalsIgnoreCase("file")) {
if (device.equalsIgnoreCase("disk")) {
@ -94,11 +94,11 @@ public class LibvirtDomainXMLParser {
}
diskDefs.add(def);
}
NodeList nics = devices.getElementsByTagName("interface");
for (int i = 0; i < nics.getLength(); i++ ) {
Element nic = (Element)nics.item(i);
String type = nic.getAttribute("type");
String mac = getAttrValue("mac", "address", nic);
String dev = getAttrValue("target", "dev", nic);
@ -114,7 +114,7 @@ public class LibvirtDomainXMLParser {
}
interfaces.add(def);
}
Element graphic = (Element)devices.getElementsByTagName("graphics").item(0);
String port = graphic.getAttribute("port");
if (port != null) {
@ -140,18 +140,18 @@ public class LibvirtDomainXMLParser {
}
return false;
}
private static String getTagValue(String tag, Element eElement){
NodeList tagNodeList = eElement.getElementsByTagName(tag);
if (tagNodeList == null || tagNodeList.getLength() == 0) {
return null;
}
NodeList nlList= tagNodeList.item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
return nValue.getNodeValue();
}
private static String getAttrValue(String tag, String attr, Element eElement){
@ -162,19 +162,19 @@ public class LibvirtDomainXMLParser {
Element node = (Element)tagNode.item(0);
return node.getAttribute(attr);
}
public Integer getVncPort() {
return vncPort;
}
public List<InterfaceDef> getInterfaces() {
return interfaces;
}
public List<DiskDef> getDisks() {
return diskDefs;
}
public String getDescription() {
return desc;
}
@ -244,7 +244,7 @@ public class LibvirtDomainXMLParser {
}
System.out.println(parser.getVncPort());
System.out.println(parser.getDescription());
List<String> test = new ArrayList<String>(1);
test.add("1");
test.add("2");

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -56,7 +56,7 @@ public class LibvirtNetworkDef {
_end = end;
}
}
public LibvirtNetworkDef(String netName, String uuid, String domName) {
_networkName = netName;
_uuid = uuid;

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -39,7 +39,7 @@ public class LibvirtStoragePoolDef {
private String _sourceHost;
private String _sourceDir;
private String _targetPath;
public LibvirtStoragePoolDef(poolType type, String poolName, String uuid, String host, String dir, String targetPath) {
_poolType = type;
_poolName = poolName;
@ -48,27 +48,27 @@ public class LibvirtStoragePoolDef {
_sourceDir = dir;
_targetPath = targetPath;
}
public String getPoolName() {
return _poolName;
}
public poolType getPoolType() {
return _poolType;
}
public String getSourceHost() {
return _sourceHost;
}
public String getSourceDir() {
return _sourceDir;
}
public String getTargetPath() {
return _targetPath;
}
@Override
public String toString() {
StringBuilder storagePoolBuilder = new StringBuilder();

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -38,25 +38,25 @@ public class LibvirtStoragePoolXMLParser{
DocumentBuilder builder;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(poolXML));
Document doc = builder.parse(is);
Element rootElement = doc.getDocumentElement();
String type = rootElement.getAttribute("type");
String uuid = getTagValue("uuid", rootElement);
String poolName = getTagValue("name", rootElement);
Element source = (Element)rootElement.getElementsByTagName("source").item(0);
String host = getAttrValue("host", "name", source);
String path = getAttrValue("dir", "path", source);
Element target = (Element)rootElement.getElementsByTagName("target").item(0);
String targetPath = getTagValue("path", target);
return new LibvirtStoragePoolDef(LibvirtStoragePoolDef.poolType.valueOf(type.toUpperCase()), poolName, uuid, host, path, targetPath);
} catch (ParserConfigurationException e) {
s_logger.debug(e.toString());
@ -67,14 +67,14 @@ public class LibvirtStoragePoolXMLParser{
}
return null;
}
private static String getTagValue(String tag, Element eElement){
NodeList nlList= eElement.getElementsByTagName(tag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
private static String getAttrValue(String tag, String attr, Element eElement){
NodeList tagNode = eElement.getElementsByTagName(tag);
if (tagNode.getLength() == 0) {
@ -84,7 +84,7 @@ public class LibvirtStoragePoolXMLParser{
return node.getAttribute(attr);
}
public static void main(String[] args) {
s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new org.apache.log4j.PatternLayout(), "System.out"));
String storagePool = "<pool type='dir'>" +
@ -107,7 +107,7 @@ public class LibvirtStoragePoolXMLParser{
"</permissions>" +
"</target>" +
"</pool>";
LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
s_logger.debug(pool.toString());

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -31,7 +31,7 @@ public class LibvirtStorageVolumeDef {
public String toString() {
return _format;
}
public static volFormat getFormat(String format) {
if (format == null) {
return null;
@ -49,7 +49,7 @@ public class LibvirtStorageVolumeDef {
private volFormat _volFormat;
private String _backingPath;
private volFormat _backingFormat;
public LibvirtStorageVolumeDef(String volName, Long size, volFormat format, String tmplPath, volFormat tmplFormat) {
_volName = volName;
_volSize = size;
@ -57,7 +57,7 @@ public class LibvirtStorageVolumeDef {
_backingPath = tmplPath;
_backingFormat = tmplFormat;
}
public volFormat getFormat() {
return this._volFormat;
}
@ -66,7 +66,7 @@ public class LibvirtStorageVolumeDef {
StringBuilder storageVolBuilder = new StringBuilder();
storageVolBuilder.append("<volume>\n");
storageVolBuilder.append("<name>" + _volName + "</name>\n");
if (_volSize != null) {
if (_volSize != null) {
storageVolBuilder.append("<capacity >" + _volSize + "</capacity>\n");
}
storageVolBuilder.append("<target>\n");
@ -84,5 +84,5 @@ public class LibvirtStorageVolumeDef {
storageVolBuilder.append("</volume>\n");
return storageVolBuilder.toString();
}
}

View File

@ -21,13 +21,13 @@ public class LibvirtStorageVolumeXMLParser{
DocumentBuilder builder;
try {
builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputSource is = new InputSource();
is.setCharacterStream(new StringReader(volXML));
Document doc = builder.parse(is);
Element rootElement = doc.getDocumentElement();
String VolName = getTagValue("name", rootElement);
Element target = (Element)rootElement.getElementsByTagName("target").item(0);
String format = getAttrValue("type", "format", target);
@ -42,14 +42,14 @@ public class LibvirtStorageVolumeXMLParser{
}
return null;
}
private static String getTagValue(String tag, Element eElement){
NodeList nlList= eElement.getElementsByTagName(tag).item(0).getChildNodes();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
Node nValue = (Node) nlList.item(0);
return nValue.getNodeValue();
}
private static String getAttrValue(String tag, String attr, Element eElement){
NodeList tagNode = eElement.getElementsByTagName(tag);
if (tagNode.getLength() == 0) {
@ -59,7 +59,7 @@ public class LibvirtStorageVolumeXMLParser{
return node.getAttribute(attr);
}
public static void main(String[] args) {
s_logger.addAppender(new org.apache.log4j.ConsoleAppender(new org.apache.log4j.PatternLayout(), "System.out"));
String storagePool = "<pool type='dir'>" +
@ -82,7 +82,7 @@ public class LibvirtStorageVolumeXMLParser{
"</permissions>" +
"</target>" +
"</pool>";
LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
LibvirtStoragePoolDef pool = parser.parseStoragePoolXML(storagePool);
s_logger.debug(pool.toString());

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -31,7 +31,7 @@ public class LibvirtVMDef {
private String _domUUID;
private String _desc;
private final Map<String, Object> components = new HashMap<String,Object>();
public static class GuestDef {
enum guestType {
KVM,
@ -106,7 +106,7 @@ public class LibvirtVMDef {
return null;
}
}
public static class GuestResourceDef {
private long _mem;
private int _currentMem = -1;
@ -140,7 +140,7 @@ public class LibvirtVMDef {
return resBuidler.toString();
}
}
public static class FeaturesDef {
private final List<String> _features = new ArrayList<String>();
public void addFeatures(String feature) {
@ -182,14 +182,14 @@ public class LibvirtVMDef {
return term.toString();
}
}
public static class ClockDef {
public enum ClockOffset {
UTC("utc"),
LOCALTIME("localtime"),
TIMEZONE("timezone"),
VARIABLE("variable");
private String _offset;
private ClockOffset(String offset) {
_offset = offset;
@ -203,21 +203,21 @@ public class LibvirtVMDef {
private String _timerName;
private String _tickPolicy;
private String _track;
public ClockDef() {
_offset = ClockOffset.UTC;
}
public void setClockOffset(ClockOffset offset) {
_offset = offset;
}
public void setTimer(String timerName, String tickPolicy, String track) {
_timerName = timerName;
_tickPolicy = tickPolicy;
_track = track;
}
@Override
public String toString() {
StringBuilder clockBuilder = new StringBuilder();
@ -228,19 +228,19 @@ public class LibvirtVMDef {
clockBuilder.append("<timer name='");
clockBuilder.append(_timerName);
clockBuilder.append("' ");
if (_tickPolicy != null) {
clockBuilder.append("tickpolicy='");
clockBuilder.append(_tickPolicy);
clockBuilder.append("' ");
}
if (_track != null) {
clockBuilder.append("track='");
clockBuilder.append(_track);
clockBuilder.append("' ");
}
clockBuilder.append(">\n");
clockBuilder.append("</timer>\n");
}
@ -248,13 +248,13 @@ public class LibvirtVMDef {
return clockBuilder.toString();
}
}
public static class DevicesDef {
private String _emulator;
private final Map<String, List<?>> devices = new HashMap<String, List<?>>();
public boolean addDevice(Object device) {
Object dev = devices.get(device.getClass().toString());
if (dev == null) {
if (dev == null) {
List<Object> devs = new ArrayList<Object>();
devs.add(device);
devices.put(device.getClass().toString(), devs);
@ -274,7 +274,7 @@ public class LibvirtVMDef {
if (_emulator != null) {
devicesBuilder.append("<emulator>" + _emulator + "</emulator>\n");
}
for (List<?> devs : devices.values()) {
for (Object dev : devs) {
devicesBuilder.append(dev.toString());
@ -289,7 +289,7 @@ public class LibvirtVMDef {
public List<InterfaceDef> getInterfaces() {
return (List<InterfaceDef>)devices.get(InterfaceDef.class.toString());
}
}
public static class DiskDef {
enum deviceType {
@ -347,7 +347,7 @@ public class LibvirtVMDef {
return _fmtType;
}
}
private deviceType _deviceType; /*floppy, disk, cdrom*/
private diskType _diskType;
private String _sourcePath;
@ -374,7 +374,7 @@ public class LibvirtVMDef {
if ( devId == 2 ) {
devId++;
}
char suffix = (char)('a' + devId);
if (bus == diskBus.SCSI) {
return "sd" + suffix;
@ -382,11 +382,11 @@ public class LibvirtVMDef {
return "vd" + suffix;
}
return "hd" + suffix;
}
public void defFileBasedDisk(String filePath, int devId, diskBus bus, diskFmtType diskFmtType) {
_diskType = diskType.FILE;
_deviceType = deviceType.DISK;
_sourcePath = filePath;
@ -484,7 +484,7 @@ public class LibvirtVMDef {
return diskBuilder.toString();
}
}
public static class InterfaceDef {
enum guestNetType {
BRIDGE("bridge"),
@ -543,15 +543,15 @@ public class LibvirtVMDef {
_macAddr = macAddr;
_model = model;
}
public void setHostNetType(hostNicType hostNetType) {
_hostNetType = hostNetType;
}
public hostNicType getHostNetType() {
return _hostNetType;
}
public String getBrName() {
return _sourceName;
}
@ -564,7 +564,7 @@ public class LibvirtVMDef {
public String getMacAddress() {
return _macAddr;
}
@Override
public String toString() {
StringBuilder netBuilder = new StringBuilder();
@ -738,75 +738,75 @@ public class LibvirtVMDef {
vmBuilder.append("</domain>\n");
return vmBuilder.toString();
}
public static void main(String [] args){
System.out.println("testing");
LibvirtVMDef vm = new LibvirtVMDef();
vm.setHvsType("kvm");
vm.setDomainName("testing");
vm.setDomUUID(UUID.randomUUID().toString());
GuestDef guest = new GuestDef();
guest.setGuestType(GuestDef.guestType.KVM);
guest.setGuestArch("x86_64");
guest.setMachineType("pc-0.11");
guest.setBootOrder(GuestDef.bootOrder.HARDISK);
vm.addComp(guest);
GuestResourceDef grd = new GuestResourceDef();
grd.setMemorySize(512*1024);
grd.setVcpuNum(1);
vm.addComp(grd);
FeaturesDef features = new FeaturesDef();
features.addFeatures("pae");
features.addFeatures("apic");
features.addFeatures("acpi");
vm.addComp(features);
TermPolicy term = new TermPolicy();
term.setCrashPolicy("destroy");
term.setPowerOffPolicy("destroy");
term.setRebootPolicy("destroy");
vm.addComp(term);
DevicesDef devices = new DevicesDef();
devices.setEmulatorPath("/usr/bin/cloud-qemu-system-x86_64");
DiskDef hda = new DiskDef();
hda.defFileBasedDisk("/path/to/hda1", 0, DiskDef.diskBus.VIRTIO, DiskDef.diskFmtType.QCOW2);
devices.addDevice(hda);
DiskDef hdb = new DiskDef();
hdb.defFileBasedDisk("/path/to/hda2", 1, DiskDef.diskBus.VIRTIO, DiskDef.diskFmtType.QCOW2);
devices.addDevice(hdb);
InterfaceDef pubNic = new InterfaceDef();
pubNic.defBridgeNet("cloudbr0", "vnet1", "00:16:3e:77:e2:a1", InterfaceDef.nicModel.VIRTIO);
devices.addDevice(pubNic);
InterfaceDef privNic = new InterfaceDef();
privNic.defPrivateNet("cloud-private", null, "00:16:3e:77:e2:a2", InterfaceDef.nicModel.VIRTIO);
devices.addDevice(privNic);
InterfaceDef vlanNic = new InterfaceDef();
vlanNic.defBridgeNet("vnbr1000", "tap1", "00:16:3e:77:e2:a2", InterfaceDef.nicModel.VIRTIO);
devices.addDevice(vlanNic);
SerialDef serial = new SerialDef("pty", null, (short)0);
devices.addDevice(serial);
ConsoleDef console = new ConsoleDef("pty", null, null, (short)0);
devices.addDevice(console);
GraphicDef grap = new GraphicDef("vnc", (short)0, true, null, null, null);
devices.addDevice(grap);
InputDef input = new InputDef("tablet", "usb");
devices.addDevice(input);
vm.addComp(devices);
System.out.println(vm.toString());
}

View File

@ -1,8 +1,8 @@
/**
* Copyright (C) 2010 Cloud.com, Inc. All rights reserved.
*
*
* This software is licensed under the GNU General Public License v3 or later.
*
*
* It is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or any later version.
@ -10,10 +10,10 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*
*/
package com.cloud.agent.resource.computing;
@ -35,14 +35,14 @@ public class LibvirtXMLParser extends DefaultHandler{
static {
s_spf = SAXParserFactory.newInstance();
}
protected SAXParser _sp;
protected boolean _initialized = false;
public LibvirtXMLParser(){
try {
_sp = s_spf.newSAXParser();
_initialized = true;
@ -50,7 +50,7 @@ public class LibvirtXMLParser extends DefaultHandler{
}
}
public boolean parseDomainXML(String domXML) {
if (!_initialized){
return false;
@ -65,18 +65,18 @@ public class LibvirtXMLParser extends DefaultHandler{
}
return false;
}
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
}
}