cleaning up a few more whitespace issues

This commit is contained in:
David Nalley 2012-01-25 02:56:55 -05:00
parent 49ebeb901e
commit 79b1584e74
12 changed files with 213 additions and 213 deletions

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.mockvm;

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.mockvm;
@ -37,7 +37,7 @@ public class MockVmMgr implements VmMgr {
private final Map<String, MockVm> vms = new HashMap<String, MockVm>();
private long vncPortMap = 0;
private Map<String, Object> _params = null;
public MockVmMgr() {
@ -185,7 +185,7 @@ public class MockVmMgr implements VmMgr {
@Override
public int getHostCpuCount() {
return getConfiguredProperty("cpus", 4);
}
@ -255,10 +255,10 @@ public class MockVmMgr implements VmMgr {
@Override
public MockVm createVmFromSpec(VirtualMachineTO vmSpec) {
String vmName = vmSpec.getName();
long ramSize = vmSpec.getMinRam();
long ramSize = vmSpec.getMinRam();
int utilizationPercent = randSeed.nextInt() % 100;
MockVm vm = null;
synchronized(this) {
vm = vms.get(vmName);
if(vm == null) {
@ -266,13 +266,13 @@ public class MockVmMgr implements VmMgr {
s_logger.debug("host is out of memory");
throw new CloudRuntimeException("Host is out of Memory");
}
int vncPort = allocVncPort();
if(vncPort < 0){
s_logger.debug("Unable to allocate VNC port");
throw new CloudRuntimeException("Unable to allocate vnc port");
}
vm = new MockVm(vmName, State.Running, ramSize, vmSpec.getCpus(), utilizationPercent, vncPort);
vms.put(vmName, vm);
}
@ -283,33 +283,33 @@ public class MockVmMgr implements VmMgr {
@Override
public void createVbd(VirtualMachineTO vmSpec, String vmName, MockVm vm) {
// TODO Auto-generated method stub
}
@Override
public void createVif(VirtualMachineTO vmSpec, String vmName, MockVm vm) {
// TODO Auto-generated method stub
}
@Override
public void configure(Map<String, Object> params) {
_params = params;
}
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 Integer getConfiguredProperty(String key, Integer defaultValue) {
String val = (String)_params.get(key);
if (val != null) {
Integer result = Integer.parseInt(val);
return result;

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.mockvm;
@ -59,6 +59,6 @@ public interface VmMgr {
public void createVbd(VirtualMachineTO vmSpec, String vmName, MockVm vm);
public void createVif(VirtualMachineTO vmSpec, String vmName, MockVm vm);
public void configure(Map<String, Object> params);
}

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;
@ -55,7 +55,7 @@ public class DummyResource implements ServerResource {
@Override
public void disconnected() {
}
@Override
public Answer executeRequest(Command cmd) {
if (cmd instanceof CheckNetworkCommand) {
@ -76,15 +76,15 @@ public class DummyResource implements ServerResource {
public Type getType() {
return _type;
}
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;
@ -105,55 +105,55 @@ public class DummyResource implements ServerResource {
info.add(speed);
info.add(ram);
info.add(cap);
info.add(dom0ram);
info.add(dom0ram);
return info;
}
protected void fillNetworkInformation(final StartupCommand cmd) {
cmd.setPrivateIpAddress((String)getConfiguredProperty("private.ip.address", "127.0.0.1"));
cmd.setPrivateMacAddress((String)getConfiguredProperty("private.mac.address", "8A:D2:54:3F:7C:C3"));
cmd.setPrivateNetmask((String)getConfiguredProperty("private.ip.netmask", "255.255.255.0"));
cmd.setStorageIpAddress((String)getConfiguredProperty("private.ip.address", "127.0.0.1"));
cmd.setStorageMacAddress((String)getConfiguredProperty("private.mac.address", "8A:D2:54:3F:7C:C3"));
cmd.setStorageNetmask((String)getConfiguredProperty("private.ip.netmask", "255.255.255.0"));
cmd.setGatewayIpAddress((String)getConfiguredProperty("gateway.ip.address", "127.0.0.1"));
}
private Map<String, String> getVersionStrings() {
Map<String, String> result = new HashMap<String, String>();
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;
}
protected StoragePoolInfo initializeLocalStorage() {
String hostIp = (String)getConfiguredProperty("private.ip.address", "127.0.0.1");
String localStoragePath = (String)getConfiguredProperty("local.storage.path", "/mnt");
String lh = hostIp + localStoragePath;
String uuid = UUID.nameUUIDFromBytes(lh.getBytes()).toString();
String capacity = (String)getConfiguredProperty("local.storage.capacity", "1000000000");
String available = (String)getConfiguredProperty("local.storage.avail", "10000000");
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 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);
@ -173,16 +173,16 @@ public class DummyResource implements ServerResource {
@Override
public boolean configure(String name, Map<String, Object> params) {
_name = name;
String value = (String)params.get("type");
_type = Host.Type.valueOf(value);
value = (String)params.get("negative.reply");
_negative = Boolean.parseBoolean(value);
setParams(params);
return true;
}
public void setParams(Map<String, Object> _params) {
this._params = _params;
}
@ -201,12 +201,12 @@ public class DummyResource implements ServerResource {
public boolean stop() {
return true;
}
@Override
public IAgentControl getAgentControl() {
return _agentControl;
}
@Override
public void setAgentControl(IAgentControl agentControl) {
_agentControl = agentControl;

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.consoleproxy;
@ -63,7 +63,7 @@ import com.cloud.utils.net.NetUtils;
import com.cloud.utils.script.Script;
/**
*
*
* I don't want to introduce extra cross-cutting concerns into console proxy process, as it involves configurations like
* zone/pod, agent auto self-upgrade etc. I also don't want to introduce more module dependency issues into our build system,
* cross-communication between this resource and console proxy will be done through reflection. As a result, come out with
@ -71,22 +71,22 @@ import com.cloud.utils.script.Script;
*
* We will deploy an agent shell inside console proxy VM, and this agent shell will launch current console proxy from within
* this special server resource, through it console proxy can build a communication channel with management server.
*
*
*/
public class ConsoleProxyResource extends ServerResourceBase implements ServerResource {
static final Logger s_logger = Logger.getLogger(ConsoleProxyResource.class);
private final Properties _properties = new Properties();
private Thread _consoleProxyMain = null;
long _proxyVmId;
int _proxyPort;
String _localgw;
String _eth1ip;
String _eth1mask;
String _eth1ip;
String _eth1mask;
String _pubIp;
@Override
public Answer executeRequest(final Command cmd) {
if (cmd instanceof CheckConsoleProxyLoadCommand) {
@ -98,7 +98,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
return new ReadyAnswer((ReadyCommand)cmd);
} else if(cmd instanceof CheckHealthCommand) {
return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
} else if(cmd instanceof StartConsoleProxyAgentHttpHandlerCommand) {
} else if(cmd instanceof StartConsoleProxyAgentHttpHandlerCommand) {
return execute((StartConsoleProxyAgentHttpHandlerCommand)cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
@ -109,7 +109,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
launchConsoleProxy(cmd.getKeystoreBits(), cmd.getKeystorePassword());
return new Answer(cmd);
}
private void disableRpFilter() {
try {
FileWriter fstream = new FileWriter("/proc/sys/net/ipv4/conf/eth2/rp_filter");
@ -177,16 +177,16 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
return new ConsoleProxyLoadAnswer(cmd, proxyVmId, proxyVmName, success, result);
}
@Override
protected String getDefaultScriptsDir() {
return null;
}
public Type getType() {
return Host.Type.ConsoleProxy;
}
@Override
public synchronized StartupCommand [] initialize() {
final StartupProxyCommand cmd = new StartupProxyCommand();
@ -201,12 +201,12 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
@Override
public void disconnected() {
}
@Override
public PingCommand getCurrentStatus(long id) {
return new PingCommand(Type.ConsoleProxy, id);
}
@Override
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
_localgw = (String)params.get("localgw");
@ -217,20 +217,20 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
} else {
s_logger.warn("WARNING: eth1ip parameter is not found!");
}
String eth2ip = (String) params.get("eth2ip");
if (eth2ip != null) {
params.put("public.network.device", "eth2");
} else {
s_logger.warn("WARNING: eth2ip parameter is not found!");
}
super.configure(name, params);
for(Map.Entry<String, Object> entry : params.entrySet()) {
_properties.put(entry.getKey(), entry.getValue());
}
String value = (String)params.get("premium");
if(value != null && value.equals("premium"))
_proxyPort = 443;
@ -238,7 +238,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
value = (String)params.get("consoleproxy.httpListenPort");
_proxyPort = NumbersUtil.parseInt(value, 80);
}
value = (String)params.get("proxy_vm");
_proxyVmId = NumbersUtil.parseLong(value, 0);
@ -258,20 +258,20 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
addRouteToInternalIpOrCidr(_localgw, _eth1ip, _eth1mask, internalDns2);
}
}
_pubIp = (String)params.get("public.ip");
value = (String)params.get("disable_rp_filter");
if(value != null && value.equalsIgnoreCase("true")) {
disableRpFilter();
}
if(s_logger.isInfoEnabled())
s_logger.info("Receive proxyVmId in ConsoleProxyResource configuration as " + _proxyVmId);
return true;
}
private void addRouteToInternalIpOrCidr(String localgw, String eth1ip, String eth1mask, String destIpOrCidr) {
s_logger.debug("addRouteToInternalIp: localgw=" + localgw + ", eth1ip=" + eth1ip + ", eth1mask=" + eth1mask + ",destIp=" + destIpOrCidr);
if (destIpOrCidr == null) {
@ -310,12 +310,12 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
s_logger.debug("addRouteToInternalIp: added route to internal ip=" + destIpOrCidr + " via " + localgw);
}
}
@Override
public String getName() {
return _name;
}
private void launchConsoleProxy(final byte[] ksBits, final String ksPassword) {
final Object resource = this;
if(_consoleProxyMain == null) {
@ -357,7 +357,7 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
public boolean authenticateConsoleAccess(String host, String port, String vmId, String sid, String ticket) {
ConsoleAccessAuthenticationCommand cmd = new ConsoleAccessAuthenticationCommand(host, port, vmId, sid, ticket);
try {
AgentControlAnswer answer = getAgentControl().sendRequest(cmd, 10000);
if(answer != null) {
@ -365,31 +365,31 @@ public class ConsoleProxyResource extends ServerResourceBase implements ServerRe
} else {
s_logger.error("Authentication failed for vm: " + vmId + " with sid: " + sid);
}
} catch (AgentControlChannelException e) {
s_logger.error("Unable to send out console access authentication request due to " + e.getMessage(), e);
}
return false;
}
public void reportLoadInfo(String gsonLoadInfo) {
ConsoleProxyLoadReportCommand cmd = new ConsoleProxyLoadReportCommand(_proxyVmId, gsonLoadInfo);
try {
getAgentControl().postRequest(cmd);
if(s_logger.isDebugEnabled())
s_logger.debug("Report proxy load info, proxy : " + _proxyVmId + ", load: " + gsonLoadInfo);
} catch (AgentControlChannelException e) {
s_logger.error("Unable to send out load info due to " + e.getMessage(), e);
}
}
public void ensureRoute(String address) {
if(_localgw != null) {
if(s_logger.isDebugEnabled())
s_logger.debug("Ensure route for " + address + " via " + _localgw);
// this method won't be called in high frequency, serialize access to script execution
synchronized(this) {
try {

View File

@ -18,45 +18,45 @@ public class KVMPhysicalDisk {
private PhysicalDiskFormat format;
private long size;
private long virtualSize;
public KVMPhysicalDisk(String path, String name, KVMStoragePool pool) {
this.path = path;
this.name = name;
this.pool = pool;
}
public void setFormat(PhysicalDiskFormat format) {
this.format = format;
}
public PhysicalDiskFormat getFormat() {
return this.format;
}
public void setSize(long size) {
this.size = size;
}
public long getSize() {
return this.size;
}
public void setVirtualSize(long size) {
this.virtualSize = size;
}
public long getVirtualSize() {
return this.virtualSize;
}
public String getName() {
return this.name;
}
public String getPath() {
return this.path;
}
public KVMStoragePool getPool() {
return this.pool;
}

View File

@ -1,6 +1,6 @@
package com.cloud.agent.storage;
public class KVMVirtualDisk {
}

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.storage;
@ -53,13 +53,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
private StorageLayer _storageLayer;
private String _mountPoint = "/mnt";
private String _manageSnapshotPath;
public LibvirtStorageAdaptor(StorageLayer storage
) {
_storageLayer = storage;
_manageSnapshotPath = Script.findScript("scripts/storage/qcow2/", "managesnapshot.sh");
}
@Override
public boolean createFolder(String uuid, String path) {
String mountPoint = _mountPoint + File.separator + uuid;
@ -69,14 +69,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
}
return true;
}
public StorageVol getVolume(StoragePool pool, String volName) {
StorageVol vol = null;
try {
vol = pool.storageVolLookupByName(volName);
} catch (LibvirtException e) {
}
if (vol == null) {
storagePoolRefresh(pool);
@ -88,13 +88,13 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
}
return vol;
}
public StorageVol createVolume(Connect conn, StoragePool pool, String uuid, long size, volFormat format) throws LibvirtException {
LibvirtStorageVolumeDef volDef = new LibvirtStorageVolumeDef(UUID.randomUUID().toString(), size, format, null, null);
s_logger.debug(volDef.toString());
return pool.storageVolCreateXML(volDef.toString(), 0);
}
public StoragePool getStoragePoolbyURI(Connect conn, URI uri) throws LibvirtException {
String sourcePath;
String uuid;
@ -112,8 +112,8 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
uuid = UUID.nameUUIDFromBytes(new String(sourceHost + sourcePath).getBytes()).toString();
protocal = "NFS";
}
String targetPath = _mountPoint + File.separator + uuid;
StoragePool sp = null;
try {
@ -136,7 +136,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid,
null, null, sourcePath);
}
synchronized (getStoragePool(uuid)) {
sp = conn.storagePoolDefineXML(spd.toString(), 0);
@ -167,17 +167,17 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
return sp;
}
}
public void storagePoolRefresh(StoragePool pool) {
try {
synchronized (getStoragePool(pool.getUUIDString())) {
pool.refresh(0);
}
} catch (LibvirtException e) {
}
}
private StoragePool createNfsStoragePool(Connect conn, String uuid, String host, String path) {
String targetPath = _mountPoint + File.separator + uuid;
LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.NETFS, uuid, uuid,
@ -202,7 +202,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
return null;
}
}
private StoragePool CreateSharedStoragePool(Connect conn, String uuid, String host, String path) {
String mountPoint = path;
if (!_storageLayer.exists(mountPoint)) {
@ -215,7 +215,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
s_logger.debug(spd.toString());
sp = conn.storagePoolDefineXML(spd.toString(), 0);
sp.create(0);
return sp;
} catch (LibvirtException e) {
s_logger.debug(e.toString());
@ -230,9 +230,9 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
return null;
}
}
private StoragePool createCLVMStoragePool(Connect conn, String uuid, String host, String path) {
String volgroupPath = "/dev/" + path;
LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.LOGICAL, uuid, uuid,
@ -257,7 +257,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
}
}
public StorageVol copyVolume(StoragePool destPool, LibvirtStorageVolumeDef destVol, StorageVol srcVol, int timeout) throws LibvirtException {
StorageVol vol = destPool.storageVolCreateXML(destVol.toString(), 0);
String srcPath = srcVol.getKey();
@ -265,7 +265,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
Script.runSimpleBashScript("cp " + srcPath + " " + destPath, timeout);
return vol;
}
public boolean copyVolume(String srcPath, String destPath, String volumeName, int timeout) throws InternalErrorException{
_storageLayer.mkdirs(destPath);
if (!_storageLayer.exists(srcPath)) {
@ -278,19 +278,19 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
return true;
}
}
public LibvirtStoragePoolDef getStoragePoolDef(Connect conn, StoragePool pool) throws LibvirtException {
String poolDefXML = pool.getXMLDesc(0);
LibvirtStoragePoolXMLParser parser = new LibvirtStoragePoolXMLParser();
return parser.parseStoragePoolXML(poolDefXML);
}
public LibvirtStorageVolumeDef getStorageVolumeDef(Connect conn, StorageVol vol) throws LibvirtException {
String volDefXML = vol.getXMLDesc(0);
LibvirtStorageVolumeXMLParser parser = new LibvirtStorageVolumeXMLParser();
return parser.parseStorageVolumeXML(volDefXML);
}
public StorageVol getVolumeFromURI(Connect conn, String volPath) throws LibvirtException, URISyntaxException {
int index = volPath.lastIndexOf("/");
URI volDir = null;
@ -315,25 +315,25 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
}
}
}
public StoragePool createFileBasedStoragePool(Connect conn, String localStoragePath, String uuid) {
if (!(_storageLayer.exists(localStoragePath) && _storageLayer.isDirectory(localStoragePath))) {
return null;
}
File path = new File(localStoragePath);
if (!(path.canWrite() && path.canRead() && path.canExecute())) {
return null;
}
StoragePool pool = null;
try {
pool = conn.storagePoolLookupByUUIDString(uuid);
} catch (LibvirtException e) {
}
if (pool == null) {
LibvirtStoragePoolDef spd = new LibvirtStoragePoolDef(poolType.DIR, uuid, uuid,
null, null, localStoragePath);
@ -352,20 +352,20 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
throw new CloudRuntimeException(e.toString());
}
}
try {
StoragePoolInfo spi = pool.getInfo();
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
pool.create(0);
}
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
return pool;
}
private void getStats(LibvirtStoragePool pool) {
Script statsScript = new Script("/bin/bash", s_logger);
statsScript.add("-c");
@ -383,14 +383,14 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
}
}
}
@Override
public KVMStoragePool getStoragePool(String uuid) {
StoragePool storage = null;
try {
Connect conn = LibvirtConnection.getConnection();
storage = conn.storagePoolLookupByUUIDString(uuid);
if (storage.getInfo().state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
storage.create(0);
}
@ -415,12 +415,12 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
throw new CloudRuntimeException(e.toString());
}
}
@Override
public KVMPhysicalDisk getPhysicalDisk(
String volumeUuid, KVMStoragePool pool) {
LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool;
try {
StorageVol vol = this.getVolume(libvirtPool.getPool(), volumeUuid);
KVMPhysicalDisk disk;
@ -439,9 +439,9 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
@Override
public KVMStoragePool createStoragePool(String name, String host, String path, StoragePoolType type) {
StoragePool sp = null;
@ -451,7 +451,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
try {
sp = conn.storagePoolLookupByUUIDString(name);
} catch (LibvirtException e) {
@ -473,7 +473,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
if (spi.state != StoragePoolState.VIR_STORAGE_POOL_RUNNING) {
sp.create(0);
}
LibvirtStoragePoolDef spd = getStoragePoolDef(conn, sp);
LibvirtStoragePool pool = new LibvirtStoragePool(name, sp.getName(), type, this, sp);
pool.setLocalPath(spd.getTargetPath());
@ -488,7 +488,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
} catch (LibvirtException e) {
throw new CloudRuntimeException(e.toString());
}
}
@Override
public boolean deleteStoragePool(String uuid) {
@ -516,7 +516,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
throw new CloudRuntimeException(e.toString());
}
}
@Override
public KVMPhysicalDisk createPhysicalDisk(String name,
KVMStoragePool pool, PhysicalDiskFormat format, long size) {
@ -598,20 +598,20 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
String sourcePath = disk.getPath();
String destPath = newDisk.getPath();
Script.runSimpleBashScript("qemu-img convert -f " + disk.getFormat() + " -O " + newDisk.getFormat() + " " + sourcePath + " " + destPath);
Script.runSimpleBashScript("qemu-img convert -f " + disk.getFormat() + " -O " + newDisk.getFormat() + " " + sourcePath + " " + destPath);
return newDisk;
}
@Override
public KVMStoragePool getStoragePoolByUri(String uri) {
URI storageUri = null;
try {
storageUri = new URI(uri);
} catch (URISyntaxException e) {
throw new CloudRuntimeException(e.toString());
}
String sourcePath = null;
String uuid = null;
String sourceHost = "";
@ -623,7 +623,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
uuid = UUID.randomUUID().toString();
protocal = StoragePoolType.NetworkFilesystem;
}
return createStoragePool(uuid, sourceHost, sourcePath, protocal);
}
@ -638,7 +638,7 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
String snapshotName, String name, KVMStoragePool destPool) {
return null;
}
@Override
public boolean refresh(KVMStoragePool pool) {
LibvirtStoragePool libvirtPool = (LibvirtStoragePool)pool;
@ -663,10 +663,10 @@ public class LibvirtStorageAdaptor implements StorageAdaptor {
} catch (LibvirtException e) {
return false;
}
return true;
}
}

View File

@ -18,7 +18,7 @@ public class LibvirtStoragePool implements KVMStoragePool {
protected StoragePoolType type;
protected StorageAdaptor _storageAdaptor;
protected StoragePool _pool;
public LibvirtStoragePool(String uuid, String name, StoragePoolType type, StorageAdaptor adaptor, StoragePool pool) {
this.uuid = uuid;
this.name = name;
@ -27,43 +27,43 @@ public class LibvirtStoragePool implements KVMStoragePool {
this.capacity = 0;
this.used = 0;
this._pool = pool;
}
public void setCapacity(long capacity) {
this.capacity = capacity;
}
@Override
public long getCapacity() {
return this.capacity;
}
public void setUsed(long used) {
this.used = used;
}
@Override
public long getUsed() {
return this.used;
}
public StoragePoolType getStoragePoolType() {
return this.type;
}
public String getName() {
return this.name;
}
public String getUuid() {
return this.uuid;
}
public String uri() {
return this.uri;
}
@Override
public PhysicalDiskFormat getDefaultFormat() {
if (getStoragePoolType() == StoragePoolType.CLVM) {
@ -72,27 +72,27 @@ public class LibvirtStoragePool implements KVMStoragePool {
return PhysicalDiskFormat.QCOW2;
}
}
@Override
public KVMPhysicalDisk createPhysicalDisk(String name, PhysicalDiskFormat format, long size) {
return this._storageAdaptor.createPhysicalDisk(name, this, format, size);
}
@Override
public KVMPhysicalDisk createPhysicalDisk(String name, long size) {
return this._storageAdaptor.createPhysicalDisk(name, this, this.getDefaultFormat(), size);
}
@Override
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid) {
return this._storageAdaptor.getPhysicalDisk(volumeUuid, this);
}
@Override
public boolean deletePhysicalDisk(String uuid) {
return this._storageAdaptor.deletePhysicalDisk(uuid, this);
}
@Override
public List<KVMPhysicalDisk> listPhysicalDisks() {
return this._storageAdaptor.listPhysicalDisks(this.uuid, this);
@ -108,7 +108,7 @@ public class LibvirtStoragePool implements KVMStoragePool {
if (this.type == StoragePoolType.Filesystem) {
return false;
}
return true;
}
@ -116,7 +116,7 @@ public class LibvirtStoragePool implements KVMStoragePool {
public String getLocalPath() {
return this.localPath;
}
public void setLocalPath(String localPath) {
this.localPath = localPath;
}
@ -125,7 +125,7 @@ public class LibvirtStoragePool implements KVMStoragePool {
public StoragePoolType getType() {
return this.type;
}
public StoragePool getPool() {
return this._pool;
}
@ -134,7 +134,7 @@ public class LibvirtStoragePool implements KVMStoragePool {
public boolean delete() {
return this._storageAdaptor.deleteStoragePool(this);
}
@Override
public boolean createFolder(String path) {
return this._storageAdaptor.createFolder(this.uuid, path);

View File

@ -8,7 +8,7 @@ import com.cloud.agent.storage.KVMPhysicalDisk.PhysicalDiskFormat;
import com.cloud.storage.Storage.StoragePoolType;
public interface StorageAdaptor {
public KVMStoragePool getStoragePool(String uuid);
public KVMPhysicalDisk getPhysicalDisk(String volumeUuid, KVMStoragePool pool);
public KVMStoragePool createStoragePool(String name, String host, String path, StoragePoolType type);

View File

@ -1,7 +1,7 @@
/**
* Copyright (C) 2011 Cloud.com. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
* 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
@ -69,7 +69,7 @@ import com.cloud.utils.script.Script;
@Local (value={VmDataServer.class})
public class JettyVmDataServer implements VmDataServer {
private static final Logger s_logger = Logger.getLogger(JettyVmDataServer.class);
public static final String USER_DATA = "user-data";
public static final String META_DATA = "meta-data";
protected String _vmDataDir;
@ -77,20 +77,20 @@ public class JettyVmDataServer implements VmDataServer {
protected String _hostIp;
protected Map<String, String> _ipVmMap = new HashMap<String, String>();
protected StorageLayer _fs = new JavaStorageLayer();
public class VmDataServlet extends HttpServlet {
private static final long serialVersionUID = -1640031398971742349L;
JettyVmDataServer _vmDataServer;
String _dataType; //userdata or meta-data
public VmDataServlet(JettyVmDataServer dataServer, String dataType) {
this._vmDataServer = dataServer;
this._dataType = dataType;
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
@ -105,8 +105,8 @@ public class JettyVmDataServer implements VmDataServer {
handleMetaData(req, resp);
}
}
protected void handleUserData(HttpServletRequest req, HttpServletResponse resp)
protected void handleUserData(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String metadataItem = req.getPathInfo();
String requester = req.getRemoteAddr();
@ -119,20 +119,20 @@ public class JettyVmDataServer implements VmDataServer {
metadataItem = path[1];
}
}
if (metadataItem != null)
data = _vmDataServer.getVmDataItem(requester, metadataItem);
if (data != null){
resp.getWriter().print(data);
} else {
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Request not found");
}
}
protected void handleMetaData(HttpServletRequest req, HttpServletResponse resp)
protected void handleMetaData(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String metadataItem = req.getPathInfo();
String requester = req.getRemoteAddr();
@ -145,9 +145,9 @@ public class JettyVmDataServer implements VmDataServer {
resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Request not found");
}
}
}
@Override
public boolean configure(String name, Map<String, Object> params)
throws ConfigurationException {
@ -165,7 +165,7 @@ public class JettyVmDataServer implements VmDataServer {
fileservingPort = Integer.parseInt(port);
}
_hostIp = (String) params.get("host.ip");
if (_vmDataDir == null) {
_vmDataDir = "/var/www/html";
}
@ -180,7 +180,7 @@ public class JettyVmDataServer implements VmDataServer {
}
return success;
}
protected boolean buildIpVmMap() {
String[] dirs = _fs.listFiles(_vmDataDir);
for (String dir: dirs) {
@ -194,7 +194,7 @@ public class JettyVmDataServer implements VmDataServer {
if (ipv4file.equalsIgnoreCase("local-ipv4")){
try {
BufferedReader input = new BufferedReader(new FileReader(dfile));
String line = null;
String line = null;
while (( line = input.readLine()) != null){
if (NetUtils.isValidIp(line)) {
_ipVmMap.put(line, vm);
@ -208,7 +208,7 @@ public class JettyVmDataServer implements VmDataServer {
} catch (IOException e) {
s_logger.warn("Failed to get ip address of " + vm);
}
}
}
}
@ -225,7 +225,7 @@ public class JettyVmDataServer implements VmDataServer {
try {
BufferedReader input = new BufferedReader(new FileReader(vmDataFile));
StringBuilder result = new StringBuilder();
String line = null;
String line = null;
while ((line = input.readLine()) != null) {
result.append(line);
}
@ -237,39 +237,39 @@ public class JettyVmDataServer implements VmDataServer {
} catch (IOException e) {
s_logger.warn("Failed to read requested file " + vmDataFile);
return null;
}
}
}
private void setupJetty(int vmDataPort, int fileservingPort) throws Exception {
_jetty = new Server();
SelectChannelConnector connector0 = new SelectChannelConnector();
connector0.setHost(_hostIp);
connector0.setPort(fileservingPort);
connector0.setMaxIdleTime(30000);
connector0.setRequestBufferSize(8192);
SelectChannelConnector connector1 = new SelectChannelConnector();
connector1.setHost(_hostIp);
connector1.setPort(vmDataPort);
connector1.setThreadPool(new QueuedThreadPool(5));
connector1.setMaxIdleTime(30000);
connector1.setRequestBufferSize(8192);
_jetty.setConnectors(new Connector[]{ connector0, connector1});
Context root = new Context(_jetty,"/latest",Context.SESSIONS);
root.setResourceBase(_vmDataDir);
root.addServlet(new ServletHolder(new VmDataServlet(this, USER_DATA)), "/*");
ResourceHandler resource_handler = new ResourceHandler();
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setResourceBase("/var/lib/images/");
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { root, resource_handler, new DefaultHandler() });
_jetty.setHandler(handlers);
_jetty.start();
//_jetty.join();
}
@ -298,7 +298,7 @@ public class JettyVmDataServer implements VmDataServer {
Script.runSimpleBashScript("rm -rf " + vmDataDir);
_fs.mkdirs(vmDataDir);
for (String [] item : cmd.getVmData()) {
try {
_fs.create(vmDataDir, item[1]);
@ -330,7 +330,7 @@ public class JettyVmDataServer implements VmDataServer {
public void handleVmStarted(VirtualMachineTO vm) {
for (NicTO nic: vm.getNics()) {
if (nic.getType() == TrafficType.Guest) {
if (nic.getIp() != null) {
if (nic.getIp() != null) {
String ipv4File = _vmDataDir + File.separator + vm.getName() + File.separator + "local-ipv4";
try {
_fs.create(_vmDataDir + File.separator + vm.getName(), "local-ipv4");
@ -342,9 +342,9 @@ public class JettyVmDataServer implements VmDataServer {
s_logger.warn("Failed to create or write to local-ipv4 file " + ipv4File,e);
}
}
}
}
}

View File

@ -1,7 +1,7 @@
/**
* Copyright (C) 2011 Cloud.com. All rights reserved.
*
* This software is licensed under the GNU General Public License v3 or later.
* 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
@ -29,10 +29,10 @@ import com.cloud.utils.component.Manager;
*
*/
public interface VmDataServer extends Manager {
public Answer handleVmDataCommand(VmDataCommand cmd);
public void handleVmStarted(VirtualMachineTO vm);
public void handleVmStopped(String vmName);
}