mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
more files changed
This commit is contained in:
parent
f922c6fc03
commit
fac2270240
@ -29,6 +29,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.regex.PatternSyntaxException;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@ -43,9 +44,6 @@ import com.cloud.agent.api.GetHostStatsCommand;
|
||||
import com.cloud.agent.api.HostStatsEntry;
|
||||
import com.cloud.agent.api.MaintainAnswer;
|
||||
import com.cloud.agent.api.PingTestCommand;
|
||||
import com.cloud.agent.api.PrepareForMigrationAnswer;
|
||||
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.dc.dao.HostPodDao;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.resource.AgentResourceBase;
|
||||
@ -58,7 +56,6 @@ import com.cloud.simulator.MockVMVO;
|
||||
import com.cloud.simulator.dao.MockHostDao;
|
||||
import com.cloud.simulator.dao.MockVMDao;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
@ -67,393 +64,393 @@ import com.cloud.utils.net.NetUtils;
|
||||
|
||||
@Local(value = { MockAgentManager.class })
|
||||
public class MockAgentManagerImpl implements MockAgentManager {
|
||||
private static final Logger s_logger = Logger.getLogger(MockAgentManagerImpl.class);
|
||||
@Inject
|
||||
HostPodDao _podDao = null;
|
||||
@Inject
|
||||
MockHostDao _mockHostDao = null;
|
||||
@Inject
|
||||
MockVMDao _mockVmDao = null;
|
||||
@Inject
|
||||
SimulatorManager _simulatorMgr = null;
|
||||
@Inject
|
||||
AgentManager _agentMgr = null;
|
||||
@Inject
|
||||
MockStorageManager _storageMgr = null;
|
||||
@Inject
|
||||
ResourceManager _resourceMgr;
|
||||
private SecureRandom random;
|
||||
private Map<String, AgentResourceBase> _resources = new ConcurrentHashMap<String, AgentResourceBase>();
|
||||
private ThreadPoolExecutor _executor;
|
||||
private static final Logger s_logger = Logger.getLogger(MockAgentManagerImpl.class);
|
||||
@Inject
|
||||
HostPodDao _podDao = null;
|
||||
@Inject
|
||||
MockHostDao _mockHostDao = null;
|
||||
@Inject
|
||||
MockVMDao _mockVmDao = null;
|
||||
@Inject
|
||||
SimulatorManager _simulatorMgr = null;
|
||||
@Inject
|
||||
AgentManager _agentMgr = null;
|
||||
@Inject
|
||||
MockStorageManager _storageMgr = null;
|
||||
@Inject
|
||||
ResourceManager _resourceMgr;
|
||||
private SecureRandom random;
|
||||
private final Map<String, AgentResourceBase> _resources = new ConcurrentHashMap<String, AgentResourceBase>();
|
||||
private ThreadPoolExecutor _executor;
|
||||
|
||||
private Pair<String, Long> getPodCidr(long podId, long dcId) {
|
||||
try {
|
||||
private Pair<String, Long> getPodCidr(long podId, long dcId) {
|
||||
try {
|
||||
|
||||
HashMap<Long, List<Object>> podMap = _podDao.getCurrentPodCidrSubnets(dcId, 0);
|
||||
List<Object> cidrPair = podMap.get(podId);
|
||||
String cidrAddress = (String) cidrPair.get(0);
|
||||
Long cidrSize = (Long) cidrPair.get(1);
|
||||
return new Pair<String, Long>(cidrAddress, cidrSize);
|
||||
} catch (PatternSyntaxException e) {
|
||||
s_logger.error("Exception while splitting pod cidr");
|
||||
return null;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
s_logger.error("Invalid pod cidr. Please check");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
HashMap<Long, List<Object>> podMap = _podDao.getCurrentPodCidrSubnets(dcId, 0);
|
||||
List<Object> cidrPair = podMap.get(podId);
|
||||
String cidrAddress = (String) cidrPair.get(0);
|
||||
Long cidrSize = (Long) cidrPair.get(1);
|
||||
return new Pair<String, Long>(cidrAddress, cidrSize);
|
||||
} catch (PatternSyntaxException e) {
|
||||
s_logger.error("Exception while splitting pod cidr");
|
||||
return null;
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
s_logger.error("Invalid pod cidr. Please check");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private String getIpAddress(long instanceId, long dcId, long podId) {
|
||||
Pair<String, Long> cidr = this.getPodCidr(podId, dcId);
|
||||
return NetUtils.long2Ip(NetUtils.ip2Long(cidr.first()) + instanceId);
|
||||
}
|
||||
private String getIpAddress(long instanceId, long dcId, long podId) {
|
||||
Pair<String, Long> cidr = this.getPodCidr(podId, dcId);
|
||||
return NetUtils.long2Ip(NetUtils.ip2Long(cidr.first()) + instanceId);
|
||||
}
|
||||
|
||||
private String getMacAddress(long dcId, long podId, long clusterId, int instanceId) {
|
||||
return NetUtils.long2Mac((dcId << 40 + podId << 32 + clusterId << 24 + instanceId));
|
||||
}
|
||||
private String getMacAddress(long dcId, long podId, long clusterId, int instanceId) {
|
||||
return NetUtils.long2Mac((dcId << 40 + podId << 32 + clusterId << 24 + instanceId));
|
||||
}
|
||||
|
||||
public synchronized int getNextAgentId(long cidrSize) {
|
||||
return random.nextInt((int) cidrSize);
|
||||
}
|
||||
public synchronized int getNextAgentId(long cidrSize) {
|
||||
return random.nextInt((int) cidrSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public Map<AgentResourceBase, Map<String, String>> createServerResources(Map<String, Object> params) {
|
||||
@Override
|
||||
@DB
|
||||
public Map<AgentResourceBase, Map<String, String>> createServerResources(Map<String, Object> params) {
|
||||
|
||||
Map<String, String> args = new HashMap<String, String>();
|
||||
Map<AgentResourceBase, Map<String, String>> newResources = new HashMap<AgentResourceBase, Map<String, String>>();
|
||||
AgentResourceBase agentResource;
|
||||
long cpuCore = Long.parseLong((String) params.get("cpucore"));
|
||||
long cpuSpeed = Long.parseLong((String) params.get("cpuspeed"));
|
||||
long memory = Long.parseLong((String) params.get("memory"));
|
||||
long localStorageSize = Long.parseLong((String) params.get("localstorage"));
|
||||
synchronized (this) {
|
||||
long dataCenterId = Long.parseLong((String) params.get("zone"));
|
||||
long podId = Long.parseLong((String) params.get("pod"));
|
||||
long clusterId = Long.parseLong((String) params.get("cluster"));
|
||||
long cidrSize = getPodCidr(podId, dataCenterId).second();
|
||||
Map<String, String> args = new HashMap<String, String>();
|
||||
Map<AgentResourceBase, Map<String, String>> newResources = new HashMap<AgentResourceBase, Map<String, String>>();
|
||||
AgentResourceBase agentResource;
|
||||
long cpuCore = Long.parseLong((String) params.get("cpucore"));
|
||||
long cpuSpeed = Long.parseLong((String) params.get("cpuspeed"));
|
||||
long memory = Long.parseLong((String) params.get("memory"));
|
||||
long localStorageSize = Long.parseLong((String) params.get("localstorage"));
|
||||
synchronized (this) {
|
||||
long dataCenterId = Long.parseLong((String) params.get("zone"));
|
||||
long podId = Long.parseLong((String) params.get("pod"));
|
||||
long clusterId = Long.parseLong((String) params.get("cluster"));
|
||||
long cidrSize = getPodCidr(podId, dataCenterId).second();
|
||||
|
||||
int agentId = getNextAgentId(cidrSize);
|
||||
String ipAddress = getIpAddress(agentId, dataCenterId, podId);
|
||||
String macAddress = getMacAddress(dataCenterId, podId, clusterId, agentId);
|
||||
MockHostVO mockHost = new MockHostVO();
|
||||
mockHost.setDataCenterId(dataCenterId);
|
||||
mockHost.setPodId(podId);
|
||||
mockHost.setClusterId(clusterId);
|
||||
mockHost.setCapabilities("hvm");
|
||||
mockHost.setCpuCount(cpuCore);
|
||||
mockHost.setCpuSpeed(cpuSpeed);
|
||||
mockHost.setMemorySize(memory);
|
||||
String guid = UUID.randomUUID().toString();
|
||||
mockHost.setGuid(guid);
|
||||
mockHost.setName("SimulatedAgent." + guid);
|
||||
mockHost.setPrivateIpAddress(ipAddress);
|
||||
mockHost.setPublicIpAddress(ipAddress);
|
||||
mockHost.setStorageIpAddress(ipAddress);
|
||||
mockHost.setPrivateMacAddress(macAddress);
|
||||
mockHost.setPublicMacAddress(macAddress);
|
||||
mockHost.setStorageMacAddress(macAddress);
|
||||
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
|
||||
mockHost.setResource("com.cloud.agent.AgentRoutingResource");
|
||||
int agentId = getNextAgentId(cidrSize);
|
||||
String ipAddress = getIpAddress(agentId, dataCenterId, podId);
|
||||
String macAddress = getMacAddress(dataCenterId, podId, clusterId, agentId);
|
||||
MockHostVO mockHost = new MockHostVO();
|
||||
mockHost.setDataCenterId(dataCenterId);
|
||||
mockHost.setPodId(podId);
|
||||
mockHost.setClusterId(clusterId);
|
||||
mockHost.setCapabilities("hvm");
|
||||
mockHost.setCpuCount(cpuCore);
|
||||
mockHost.setCpuSpeed(cpuSpeed);
|
||||
mockHost.setMemorySize(memory);
|
||||
String guid = UUID.randomUUID().toString();
|
||||
mockHost.setGuid(guid);
|
||||
mockHost.setName("SimulatedAgent." + guid);
|
||||
mockHost.setPrivateIpAddress(ipAddress);
|
||||
mockHost.setPublicIpAddress(ipAddress);
|
||||
mockHost.setStorageIpAddress(ipAddress);
|
||||
mockHost.setPrivateMacAddress(macAddress);
|
||||
mockHost.setPublicMacAddress(macAddress);
|
||||
mockHost.setStorageMacAddress(macAddress);
|
||||
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
|
||||
mockHost.setResource("com.cloud.agent.AgentRoutingResource");
|
||||
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
mockHost = _mockHostDao.persist(mockHost);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
s_logger.error("Error while configuring mock agent " + ex.getMessage());
|
||||
throw new CloudRuntimeException("Error configuring agent", ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
mockHost = _mockHostDao.persist(mockHost);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
s_logger.error("Error while configuring mock agent " + ex.getMessage());
|
||||
throw new CloudRuntimeException("Error configuring agent", ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
_storageMgr.getLocalStorage(guid, localStorageSize);
|
||||
_storageMgr.getLocalStorage(guid, localStorageSize);
|
||||
|
||||
agentResource = new AgentRoutingResource();
|
||||
if (agentResource != null) {
|
||||
try {
|
||||
params.put("guid", mockHost.getGuid());
|
||||
agentResource.start();
|
||||
agentResource.configure(mockHost.getName(), params);
|
||||
agentResource = new AgentRoutingResource();
|
||||
if (agentResource != null) {
|
||||
try {
|
||||
params.put("guid", mockHost.getGuid());
|
||||
agentResource.start();
|
||||
agentResource.configure(mockHost.getName(), params);
|
||||
|
||||
newResources.put(agentResource, args);
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.error("error while configuring server resource" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return newResources;
|
||||
}
|
||||
newResources.put(agentResource, args);
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.error("error while configuring server resource" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
return newResources;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
try {
|
||||
random = SecureRandom.getInstance("SHA1PRNG");
|
||||
_executor = new ThreadPoolExecutor(1, 5, 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(),
|
||||
new NamedThreadFactory("Simulator-Agent-Mgr"));
|
||||
// ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
// _simulatorMgr = (SimulatorManager)
|
||||
// locator.getComponent(SimulatorManager.Name);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
s_logger.debug("Failed to initialize random:" + e.toString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
try {
|
||||
random = SecureRandom.getInstance("SHA1PRNG");
|
||||
_executor = new ThreadPoolExecutor(1, 5, 1, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(),
|
||||
new NamedThreadFactory("Simulator-Agent-Mgr"));
|
||||
// ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
// _simulatorMgr = (SimulatorManager)
|
||||
// locator.getComponent(SimulatorManager.Name);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
s_logger.debug("Failed to initialize random:" + e.toString());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSystemVMStart(long vmId, String privateIpAddress, String privateMacAddress,
|
||||
String privateNetMask, long dcId, long podId, String name, String vmType, String url) {
|
||||
_executor.execute(new SystemVMHandler(vmId, privateIpAddress, privateMacAddress, privateNetMask, dcId, podId,
|
||||
name, vmType, _simulatorMgr, url));
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean handleSystemVMStart(long vmId, String privateIpAddress, String privateMacAddress,
|
||||
String privateNetMask, long dcId, long podId, String name, String vmType, String url) {
|
||||
_executor.execute(new SystemVMHandler(vmId, privateIpAddress, privateMacAddress, privateNetMask, dcId, podId,
|
||||
name, vmType, _simulatorMgr, url));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleSystemVMStop(long vmId) {
|
||||
_executor.execute(new SystemVMHandler(vmId));
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean handleSystemVMStop(long vmId) {
|
||||
_executor.execute(new SystemVMHandler(vmId));
|
||||
return true;
|
||||
}
|
||||
|
||||
private class SystemVMHandler implements Runnable {
|
||||
private long vmId;
|
||||
private String privateIpAddress;
|
||||
private String privateMacAddress;
|
||||
private String privateNetMask;
|
||||
private long dcId;
|
||||
private long podId;
|
||||
private String guid;
|
||||
private String name;
|
||||
private String vmType;
|
||||
private SimulatorManager mgr;
|
||||
private String mode;
|
||||
private String url;
|
||||
private class SystemVMHandler implements Runnable {
|
||||
private final long vmId;
|
||||
private String privateIpAddress;
|
||||
private String privateMacAddress;
|
||||
private String privateNetMask;
|
||||
private long dcId;
|
||||
private long podId;
|
||||
private String guid;
|
||||
private String name;
|
||||
private String vmType;
|
||||
private SimulatorManager mgr;
|
||||
private final String mode;
|
||||
private String url;
|
||||
|
||||
public SystemVMHandler(long vmId, String privateIpAddress, String privateMacAddress, String privateNetMask,
|
||||
long dcId, long podId, String name, String vmType, SimulatorManager mgr, String url) {
|
||||
this.vmId = vmId;
|
||||
this.privateIpAddress = privateIpAddress;
|
||||
this.privateMacAddress = privateMacAddress;
|
||||
this.privateNetMask = privateNetMask;
|
||||
this.dcId = dcId;
|
||||
this.guid = "SystemVM-" + UUID.randomUUID().toString();
|
||||
this.name = name;
|
||||
this.vmType = vmType;
|
||||
this.mgr = mgr;
|
||||
this.mode = "Start";
|
||||
this.url = url;
|
||||
this.podId = podId;
|
||||
}
|
||||
public SystemVMHandler(long vmId, String privateIpAddress, String privateMacAddress, String privateNetMask,
|
||||
long dcId, long podId, String name, String vmType, SimulatorManager mgr, String url) {
|
||||
this.vmId = vmId;
|
||||
this.privateIpAddress = privateIpAddress;
|
||||
this.privateMacAddress = privateMacAddress;
|
||||
this.privateNetMask = privateNetMask;
|
||||
this.dcId = dcId;
|
||||
this.guid = "SystemVM-" + UUID.randomUUID().toString();
|
||||
this.name = name;
|
||||
this.vmType = vmType;
|
||||
this.mgr = mgr;
|
||||
this.mode = "Start";
|
||||
this.url = url;
|
||||
this.podId = podId;
|
||||
}
|
||||
|
||||
public SystemVMHandler(long vmId) {
|
||||
this.vmId = vmId;
|
||||
this.mode = "Stop";
|
||||
}
|
||||
public SystemVMHandler(long vmId) {
|
||||
this.vmId = vmId;
|
||||
this.mode = "Stop";
|
||||
}
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public void run() {
|
||||
@Override
|
||||
@DB
|
||||
public void run() {
|
||||
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
if (this.mode.equalsIgnoreCase("Stop")) {
|
||||
txn.start();
|
||||
MockHost host = _mockHostDao.findByVmId(this.vmId);
|
||||
if (host != null) {
|
||||
String guid = host.getGuid();
|
||||
if (guid != null) {
|
||||
AgentResourceBase res = _resources.get(guid);
|
||||
if (res != null) {
|
||||
res.stop();
|
||||
_resources.remove(guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
return;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
if (this.mode.equalsIgnoreCase("Stop")) {
|
||||
txn.start();
|
||||
MockHost host = _mockHostDao.findByVmId(this.vmId);
|
||||
if (host != null) {
|
||||
String guid = host.getGuid();
|
||||
if (guid != null) {
|
||||
AgentResourceBase res = _resources.get(guid);
|
||||
if (res != null) {
|
||||
res.stop();
|
||||
_resources.remove(guid);
|
||||
}
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
return;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
String resource = null;
|
||||
if (vmType.equalsIgnoreCase("secstorage")) {
|
||||
resource = "com.cloud.agent.AgentStorageResource";
|
||||
}
|
||||
MockHostVO mockHost = new MockHostVO();
|
||||
mockHost.setDataCenterId(this.dcId);
|
||||
mockHost.setPodId(this.podId);
|
||||
mockHost.setCpuCount(DEFAULT_HOST_CPU_CORES);
|
||||
mockHost.setCpuSpeed(DEFAULT_HOST_SPEED_MHZ);
|
||||
mockHost.setMemorySize(DEFAULT_HOST_MEM_SIZE);
|
||||
mockHost.setGuid(this.guid);
|
||||
mockHost.setName(name);
|
||||
mockHost.setPrivateIpAddress(this.privateIpAddress);
|
||||
mockHost.setPublicIpAddress(this.privateIpAddress);
|
||||
mockHost.setStorageIpAddress(this.privateIpAddress);
|
||||
mockHost.setPrivateMacAddress(this.privateMacAddress);
|
||||
mockHost.setPublicMacAddress(this.privateMacAddress);
|
||||
mockHost.setStorageMacAddress(this.privateMacAddress);
|
||||
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
|
||||
mockHost.setResource(resource);
|
||||
mockHost.setVmId(vmId);
|
||||
Transaction simtxn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
simtxn.start();
|
||||
mockHost = _mockHostDao.persist(mockHost);
|
||||
simtxn.commit();
|
||||
} catch (Exception ex) {
|
||||
simtxn.rollback();
|
||||
throw new CloudRuntimeException("Unable to persist host " + mockHost.getGuid() + " due to "
|
||||
+ ex.getMessage(), ex);
|
||||
} finally {
|
||||
simtxn.close();
|
||||
String resource = null;
|
||||
if (vmType.equalsIgnoreCase("secstorage")) {
|
||||
resource = "com.cloud.agent.AgentStorageResource";
|
||||
}
|
||||
MockHostVO mockHost = new MockHostVO();
|
||||
mockHost.setDataCenterId(this.dcId);
|
||||
mockHost.setPodId(this.podId);
|
||||
mockHost.setCpuCount(DEFAULT_HOST_CPU_CORES);
|
||||
mockHost.setCpuSpeed(DEFAULT_HOST_SPEED_MHZ);
|
||||
mockHost.setMemorySize(DEFAULT_HOST_MEM_SIZE);
|
||||
mockHost.setGuid(this.guid);
|
||||
mockHost.setName(name);
|
||||
mockHost.setPrivateIpAddress(this.privateIpAddress);
|
||||
mockHost.setPublicIpAddress(this.privateIpAddress);
|
||||
mockHost.setStorageIpAddress(this.privateIpAddress);
|
||||
mockHost.setPrivateMacAddress(this.privateMacAddress);
|
||||
mockHost.setPublicMacAddress(this.privateMacAddress);
|
||||
mockHost.setStorageMacAddress(this.privateMacAddress);
|
||||
mockHost.setVersion(this.getClass().getPackage().getImplementationVersion());
|
||||
mockHost.setResource(resource);
|
||||
mockHost.setVmId(vmId);
|
||||
Transaction simtxn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
simtxn.start();
|
||||
mockHost = _mockHostDao.persist(mockHost);
|
||||
simtxn.commit();
|
||||
} catch (Exception ex) {
|
||||
simtxn.rollback();
|
||||
throw new CloudRuntimeException("Unable to persist host " + mockHost.getGuid() + " due to "
|
||||
+ ex.getMessage(), ex);
|
||||
} finally {
|
||||
simtxn.close();
|
||||
simtxn = Transaction.open(Transaction.CLOUD_DB);
|
||||
simtxn.close();
|
||||
}
|
||||
}
|
||||
|
||||
if (vmType.equalsIgnoreCase("secstorage")) {
|
||||
AgentStorageResource storageResource = new AgentStorageResource();
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
params.put("guid", this.guid);
|
||||
details.put("guid", this.guid);
|
||||
storageResource.configure("secondaryStorage", params);
|
||||
storageResource.start();
|
||||
// on the simulator the ssvm is as good as a direct
|
||||
// agent
|
||||
_resourceMgr.addHost(mockHost.getDataCenterId(), storageResource, Host.Type.SecondaryStorageVM,
|
||||
details);
|
||||
_resources.put(this.guid, storageResource);
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.debug("Failed to load secondary storage resource: " + e.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vmType.equalsIgnoreCase("secstorage")) {
|
||||
AgentStorageResource storageResource = new AgentStorageResource();
|
||||
try {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
params.put("guid", this.guid);
|
||||
details.put("guid", this.guid);
|
||||
storageResource.configure("secondaryStorage", params);
|
||||
storageResource.start();
|
||||
// on the simulator the ssvm is as good as a direct
|
||||
// agent
|
||||
_resourceMgr.addHost(mockHost.getDataCenterId(), storageResource, Host.Type.SecondaryStorageVM,
|
||||
details);
|
||||
_resources.put(this.guid, storageResource);
|
||||
} catch (ConfigurationException e) {
|
||||
s_logger.debug("Failed to load secondary storage resource: " + e.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MockHost getHost(String guid) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockHost _host = _mockHostDao.findByGuid(guid);
|
||||
txn.commit();
|
||||
if (_host != null) {
|
||||
return _host;
|
||||
} else {
|
||||
s_logger.error("Host with guid " + guid + " was not found");
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
@Override
|
||||
public MockHost getHost(String guid) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockHost _host = _mockHostDao.findByGuid(guid);
|
||||
txn.commit();
|
||||
if (_host != null) {
|
||||
return _host;
|
||||
} else {
|
||||
s_logger.error("Host with guid " + guid + " was not found");
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to get host " + guid + " due to " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
|
||||
String hostGuid = cmd.getHostGuid();
|
||||
MockHost host = null;
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
host = _mockHostDao.findByGuid(hostGuid);
|
||||
txn.commit();
|
||||
if (host == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to get host " + hostGuid + " due to " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
@Override
|
||||
public GetHostStatsAnswer getHostStatistic(GetHostStatsCommand cmd) {
|
||||
String hostGuid = cmd.getHostGuid();
|
||||
MockHost host = null;
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
host = _mockHostDao.findByGuid(hostGuid);
|
||||
txn.commit();
|
||||
if (host == null) {
|
||||
return null;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to get host " + hostGuid + " due to " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
Transaction vmtxn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
vmtxn.start();
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
|
||||
vmtxn.commit();
|
||||
double usedMem = 0.0;
|
||||
double usedCpu = 0.0;
|
||||
for (MockVMVO vm : vms) {
|
||||
usedMem += vm.getMemory();
|
||||
usedCpu += vm.getCpu();
|
||||
}
|
||||
Transaction vmtxn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
vmtxn.start();
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostId(host.getId());
|
||||
vmtxn.commit();
|
||||
double usedMem = 0.0;
|
||||
double usedCpu = 0.0;
|
||||
for (MockVMVO vm : vms) {
|
||||
usedMem += vm.getMemory();
|
||||
usedCpu += vm.getCpu();
|
||||
}
|
||||
|
||||
HostStatsEntry hostStats = new HostStatsEntry();
|
||||
hostStats.setTotalMemoryKBs(host.getMemorySize());
|
||||
hostStats.setFreeMemoryKBs(host.getMemorySize() - usedMem);
|
||||
hostStats.setNetworkReadKBs(32768);
|
||||
hostStats.setNetworkWriteKBs(16384);
|
||||
hostStats.setCpuUtilization(usedCpu / (host.getCpuCount() * host.getCpuSpeed()));
|
||||
hostStats.setEntityType("simulator-host");
|
||||
hostStats.setHostId(cmd.getHostId());
|
||||
return new GetHostStatsAnswer(cmd, hostStats);
|
||||
} catch (Exception ex) {
|
||||
vmtxn.rollback();
|
||||
throw new CloudRuntimeException("Unable to get Vms on host " + host.getGuid() + " due to "
|
||||
+ ex.getMessage(), ex);
|
||||
} finally {
|
||||
vmtxn.close();
|
||||
HostStatsEntry hostStats = new HostStatsEntry();
|
||||
hostStats.setTotalMemoryKBs(host.getMemorySize());
|
||||
hostStats.setFreeMemoryKBs(host.getMemorySize() - usedMem);
|
||||
hostStats.setNetworkReadKBs(32768);
|
||||
hostStats.setNetworkWriteKBs(16384);
|
||||
hostStats.setCpuUtilization(usedCpu / (host.getCpuCount() * host.getCpuSpeed()));
|
||||
hostStats.setEntityType("simulator-host");
|
||||
hostStats.setHostId(cmd.getHostId());
|
||||
return new GetHostStatsAnswer(cmd, hostStats);
|
||||
} catch (Exception ex) {
|
||||
vmtxn.rollback();
|
||||
throw new CloudRuntimeException("Unable to get Vms on host " + host.getGuid() + " due to "
|
||||
+ ex.getMessage(), ex);
|
||||
} finally {
|
||||
vmtxn.close();
|
||||
vmtxn = Transaction.open(Transaction.CLOUD_DB);
|
||||
vmtxn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer checkHealth(CheckHealthCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
@Override
|
||||
public Answer checkHealth(CheckHealthCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer pingTest(PingTestCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
@Override
|
||||
public Answer pingTest(PingTestCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean stop() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaintainAnswer maintain(com.cloud.agent.api.MaintainCommand cmd) {
|
||||
return new MaintainAnswer(cmd);
|
||||
}
|
||||
@Override
|
||||
public MaintainAnswer maintain(com.cloud.agent.api.MaintainCommand cmd) {
|
||||
return new MaintainAnswer(cmd);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer checkNetworkCommand(CheckNetworkCommand cmd) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Checking if network name setup is done on the resource");
|
||||
}
|
||||
return new CheckNetworkAnswer(cmd, true, "Network Setup check by names is done");
|
||||
}
|
||||
@Override
|
||||
public Answer checkNetworkCommand(CheckNetworkCommand cmd) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Checking if network name setup is done on the resource");
|
||||
}
|
||||
return new CheckNetworkAnswer(cmd, true, "Network Setup check by names is done");
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -23,20 +23,56 @@ import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.agent.api.*;
|
||||
import com.cloud.agent.api.routing.*;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.BumpUpPriorityCommand;
|
||||
import com.cloud.agent.api.CheckRouterAnswer;
|
||||
import com.cloud.agent.api.CheckRouterCommand;
|
||||
import com.cloud.agent.api.CheckVirtualMachineAnswer;
|
||||
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||
import com.cloud.agent.api.CleanupNetworkRulesCmd;
|
||||
import com.cloud.agent.api.GetDomRVersionAnswer;
|
||||
import com.cloud.agent.api.GetDomRVersionCmd;
|
||||
import com.cloud.agent.api.GetVmStatsAnswer;
|
||||
import com.cloud.agent.api.GetVmStatsCommand;
|
||||
import com.cloud.agent.api.GetVncPortAnswer;
|
||||
import com.cloud.agent.api.GetVncPortCommand;
|
||||
import com.cloud.agent.api.MigrateAnswer;
|
||||
import com.cloud.agent.api.MigrateCommand;
|
||||
import com.cloud.agent.api.NetworkUsageAnswer;
|
||||
import com.cloud.agent.api.NetworkUsageCommand;
|
||||
import com.cloud.agent.api.PrepareForMigrationAnswer;
|
||||
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||
import com.cloud.agent.api.RebootAnswer;
|
||||
import com.cloud.agent.api.RebootCommand;
|
||||
import com.cloud.agent.api.SecurityGroupRuleAnswer;
|
||||
import com.cloud.agent.api.SecurityGroupRulesCmd;
|
||||
import com.cloud.agent.api.StartAnswer;
|
||||
import com.cloud.agent.api.StartCommand;
|
||||
import com.cloud.agent.api.StopAnswer;
|
||||
import com.cloud.agent.api.StopCommand;
|
||||
import com.cloud.agent.api.VmStatsEntry;
|
||||
import com.cloud.agent.api.check.CheckSshAnswer;
|
||||
import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||
import com.cloud.agent.api.routing.NetworkElementCommand;
|
||||
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||
import com.cloud.agent.api.routing.SetFirewallRulesCommand;
|
||||
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.to.NicTO;
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
import com.cloud.network.router.VirtualRouter;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.simulator.MockSecurityRulesVO;
|
||||
import com.cloud.simulator.MockVMVO;
|
||||
@ -46,7 +82,6 @@ import com.cloud.simulator.dao.MockSecurityRulesDao;
|
||||
import com.cloud.simulator.dao.MockVMDao;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.Ternary;
|
||||
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
@ -55,46 +90,46 @@ import com.cloud.vm.VirtualMachine.State;
|
||||
public class MockVmManagerImpl implements MockVmManager {
|
||||
private static final Logger s_logger = Logger.getLogger(MockVmManagerImpl.class);
|
||||
|
||||
@Inject MockVMDao _mockVmDao = null;
|
||||
@Inject MockAgentManager _mockAgentMgr = null;
|
||||
@Inject MockHostDao _mockHostDao = null;
|
||||
@Inject MockSecurityRulesDao _mockSecurityDao = null;
|
||||
private Map<String, Map<String, Ternary<String, Long, Long>>> _securityRules = new ConcurrentHashMap<String, Map<String, Ternary<String, Long, Long>>>();
|
||||
@Inject MockVMDao _mockVmDao = null;
|
||||
@Inject MockAgentManager _mockAgentMgr = null;
|
||||
@Inject MockHostDao _mockHostDao = null;
|
||||
@Inject MockSecurityRulesDao _mockSecurityDao = null;
|
||||
private final Map<String, Map<String, Ternary<String, Long, Long>>> _securityRules = new ConcurrentHashMap<String, Map<String, Ternary<String, Long, Long>>>();
|
||||
|
||||
public MockVmManagerImpl() {
|
||||
}
|
||||
public MockVmManagerImpl() {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public String startVM(String vmName, NicTO[] nics,
|
||||
int cpuHz, long ramSize,
|
||||
String bootArgs, String hostGuid) {
|
||||
int cpuHz, long ramSize,
|
||||
String bootArgs, String hostGuid) {
|
||||
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
MockHost host = null;
|
||||
MockVm vm = null;
|
||||
try {
|
||||
txn.start();
|
||||
host = _mockHostDao.findByGuid(hostGuid);
|
||||
if (host == null) {
|
||||
return "can't find host";
|
||||
}
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
MockHost host = null;
|
||||
MockVm vm = null;
|
||||
try {
|
||||
txn.start();
|
||||
host = _mockHostDao.findByGuid(hostGuid);
|
||||
if (host == null) {
|
||||
return "can't find host";
|
||||
}
|
||||
|
||||
vm = _mockVmDao.findByVmName(vmName);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to start VM " + vmName, ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
vm = _mockVmDao.findByVmName(vmName);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to start VM " + vmName, ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
if(vm == null) {
|
||||
int vncPort = 0;
|
||||
@ -109,43 +144,43 @@ public class MockVmManagerImpl implements MockVmManager {
|
||||
vm.setHostId(host.getId());
|
||||
vm.setBootargs(bootArgs);
|
||||
if(vmName.startsWith("s-")) {
|
||||
vm.setType("SecondaryStorageVm");
|
||||
vm.setType("SecondaryStorageVm");
|
||||
} else if (vmName.startsWith("v-")) {
|
||||
vm.setType("ConsoleProxy");
|
||||
vm.setType("ConsoleProxy");
|
||||
} else if (vmName.startsWith("r-")) {
|
||||
vm.setType("DomainRouter");
|
||||
vm.setType("DomainRouter");
|
||||
} else if (vmName.startsWith("i-")) {
|
||||
vm.setType("User");
|
||||
vm.setType("User");
|
||||
}
|
||||
txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
vm = _mockVmDao.persist((MockVMVO) vm);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to save vm to db " + vm.getName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
try {
|
||||
txn.start();
|
||||
vm = _mockVmDao.persist((MockVMVO) vm);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to save vm to db " + vm.getName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(vm.getState() == State.Stopped) {
|
||||
vm.setState(State.Running);
|
||||
txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO)vm);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to update vm " + vm.getName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
try {
|
||||
txn.start();
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO)vm);
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to update vm " + vm.getName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -192,49 +227,49 @@ public class MockVmManagerImpl implements MockVmManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean rebootVM(String vmName) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Running);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO) vm);
|
||||
public boolean rebootVM(String vmName) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Running);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO) vm);
|
||||
|
||||
}
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to reboot vm " + vmName, ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
txn.commit();
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to reboot vm " + vmName, ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, MockVMVO> getVms(String hostGuid) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
|
||||
Map<String, MockVMVO> vmMap = new HashMap<String, MockVMVO>();
|
||||
for (MockVMVO vm : vms) {
|
||||
vmMap.put(vm.getName(), vm);
|
||||
}
|
||||
txn.commit();
|
||||
return vmMap;
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
@Override
|
||||
public Map<String, MockVMVO> getVms(String hostGuid) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
|
||||
Map<String, MockVMVO> vmMap = new HashMap<String, MockVMVO>();
|
||||
for (MockVMVO vm : vms) {
|
||||
vmMap.put(vm.getName(), vm);
|
||||
}
|
||||
txn.commit();
|
||||
return vmMap;
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckRouterAnswer checkRouter(CheckRouterCommand cmd) {
|
||||
@ -267,30 +302,30 @@ public class MockVmManagerImpl implements MockVmManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, State> getVmStates(String hostGuid) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
Map<String, State> states = new HashMap<String, State>();
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
|
||||
if (vms.isEmpty()) {
|
||||
txn.commit();
|
||||
return states;
|
||||
}
|
||||
for (MockVm vm : vms) {
|
||||
states.put(vm.getName(), vm.getState());
|
||||
}
|
||||
txn.commit();
|
||||
return states;
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
public Map<String, State> getVmStates(String hostGuid) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
Map<String, State> states = new HashMap<String, State>();
|
||||
List<MockVMVO> vms = _mockVmDao.findByHostGuid(hostGuid);
|
||||
if (vms.isEmpty()) {
|
||||
txn.commit();
|
||||
return states;
|
||||
}
|
||||
for (MockVm vm : vms) {
|
||||
states.put(vm.getName(), vm.getState());
|
||||
}
|
||||
txn.commit();
|
||||
return states;
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to fetch vms from host " + hostGuid, ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
@ -323,26 +358,26 @@ public class MockVmManagerImpl implements MockVmManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName());
|
||||
if (vm == null) {
|
||||
return new CheckVirtualMachineAnswer(cmd, "can't find vm:" + cmd.getVmName());
|
||||
}
|
||||
public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockVMVO vm = _mockVmDao.findByVmName(cmd.getVmName());
|
||||
if (vm == null) {
|
||||
return new CheckVirtualMachineAnswer(cmd, "can't find vm:" + cmd.getVmName());
|
||||
}
|
||||
|
||||
txn.commit();
|
||||
return new CheckVirtualMachineAnswer(cmd, vm.getState(), vm.getVncPort());
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn.commit();
|
||||
return new CheckVirtualMachineAnswer(cmd, vm.getState(), vm.getVncPort());
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to fetch vm state " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer startVM(StartCommand cmd, SimulatorInfo info) {
|
||||
@ -372,7 +407,7 @@ public class MockVmManagerImpl implements MockVmManager {
|
||||
|
||||
@Override
|
||||
public Answer SetFirewallRules(SetFirewallRulesCommand cmd) {
|
||||
return new Answer(cmd);
|
||||
return new Answer(cmd);
|
||||
}
|
||||
|
||||
|
||||
@ -382,38 +417,38 @@ public class MockVmManagerImpl implements MockVmManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
String vmName = cmd.getVmName();
|
||||
String destGuid = cmd.getHostGuid();
|
||||
MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, info.getHostUuid());
|
||||
if (vm == null) {
|
||||
return new MigrateAnswer(cmd, false, "can't find vm:" + vmName + " on host:" + info.getHostUuid(), null);
|
||||
} else {
|
||||
public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
String vmName = cmd.getVmName();
|
||||
String destGuid = cmd.getHostGuid();
|
||||
MockVMVO vm = _mockVmDao.findByVmNameAndHost(vmName, info.getHostUuid());
|
||||
if (vm == null) {
|
||||
return new MigrateAnswer(cmd, false, "can't find vm:" + vmName + " on host:" + info.getHostUuid(), null);
|
||||
} else {
|
||||
if (vm.getState() == State.Migrating) {
|
||||
vm.setState(State.Running);
|
||||
}
|
||||
}
|
||||
|
||||
MockHost destHost = _mockHostDao.findByGuid(destGuid);
|
||||
if (destHost == null) {
|
||||
return new MigrateAnswer(cmd, false, "can;t find host:" + info.getHostUuid(), null);
|
||||
}
|
||||
vm.setHostId(destHost.getId());
|
||||
_mockVmDao.update(vm.getId(), vm);
|
||||
txn.commit();
|
||||
return new MigrateAnswer(cmd, true, null, 0);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to migrate vm " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
MockHost destHost = _mockHostDao.findByGuid(destGuid);
|
||||
if (destHost == null) {
|
||||
return new MigrateAnswer(cmd, false, "can;t find host:" + info.getHostUuid(), null);
|
||||
}
|
||||
vm.setHostId(destHost.getId());
|
||||
_mockVmDao.update(vm.getId(), vm);
|
||||
txn.commit();
|
||||
return new MigrateAnswer(cmd, true, null, 0);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to migrate vm " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd) {
|
||||
@ -457,81 +492,81 @@ public class MockVmManagerImpl implements MockVmManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(info.getHostUuid());
|
||||
for (MockSecurityRulesVO rule : rules) {
|
||||
MockVMVO vm = _mockVmDao.findByVmNameAndHost(rule.getVmName(), info.getHostUuid());
|
||||
if (vm == null) {
|
||||
_mockSecurityDao.remove(rule.getId());
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
return new Answer(cmd);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to clean up rules", ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
List<MockSecurityRulesVO> rules = _mockSecurityDao.findByHost(info.getHostUuid());
|
||||
for (MockSecurityRulesVO rule : rules) {
|
||||
MockVMVO vm = _mockVmDao.findByVmNameAndHost(rule.getVmName(), info.getHostUuid());
|
||||
if (vm == null) {
|
||||
_mockSecurityDao.remove(rule.getId());
|
||||
}
|
||||
}
|
||||
txn.commit();
|
||||
return new Answer(cmd);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to clean up rules", ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer stopVM(StopCommand cmd) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
String vmName = cmd.getVmName();
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO) vm);
|
||||
}
|
||||
public Answer stopVM(StopCommand cmd) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
String vmName = cmd.getVmName();
|
||||
MockVm vm = _mockVmDao.findByVmName(vmName);
|
||||
if (vm != null) {
|
||||
vm.setState(State.Stopped);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO) vm);
|
||||
}
|
||||
|
||||
if (vmName.startsWith("s-")) {
|
||||
_mockAgentMgr.handleSystemVMStop(vm.getId());
|
||||
}
|
||||
txn.commit();
|
||||
return new StopAnswer(cmd, null, new Integer(0), true);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
if (vmName.startsWith("s-")) {
|
||||
_mockAgentMgr.handleSystemVMStop(vm.getId());
|
||||
}
|
||||
txn.commit();
|
||||
return new StopAnswer(cmd, null, new Integer(0), true);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer rebootVM(RebootCommand cmd) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockVm vm = _mockVmDao.findByVmName(cmd.getVmName());
|
||||
if (vm != null) {
|
||||
vm.setState(State.Running);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO) vm);
|
||||
}
|
||||
txn.commit();
|
||||
return new RebootAnswer(cmd, "Rebooted " + cmd.getVmName(), true);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
public Answer rebootVM(RebootCommand cmd) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockVm vm = _mockVmDao.findByVmName(cmd.getVmName());
|
||||
if (vm != null) {
|
||||
vm.setState(State.Running);
|
||||
_mockVmDao.update(vm.getId(), (MockVMVO) vm);
|
||||
}
|
||||
txn.commit();
|
||||
return new RebootAnswer(cmd, "Rebooted " + cmd.getVmName(), true);
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("unable to stop vm " + cmd.getVmName(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer getVncPort(GetVncPortCommand cmd) {
|
||||
return new GetVncPortAnswer(cmd, 0);
|
||||
return new GetVncPortAnswer(cmd, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -546,13 +581,13 @@ public class MockVmManagerImpl implements MockVmManager {
|
||||
|
||||
@Override
|
||||
public GetDomRVersionAnswer getDomRVersion(GetDomRVersionCmd cmd) {
|
||||
return new GetDomRVersionAnswer(cmd, null, null, null);
|
||||
return new GetDomRVersionAnswer(cmd, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SecurityGroupRuleAnswer AddSecurityGroupRules(SecurityGroupRulesCmd cmd, SimulatorInfo info) {
|
||||
if (!info.isEnabled()) {
|
||||
return new SecurityGroupRuleAnswer(cmd, false, "Disabled", SecurityGroupRuleAnswer.FailureReason.CANNOT_BRIDGE_FIREWALL);
|
||||
return new SecurityGroupRuleAnswer(cmd, false, "Disabled", SecurityGroupRuleAnswer.FailureReason.CANNOT_BRIDGE_FIREWALL);
|
||||
}
|
||||
|
||||
Map<String, Ternary<String,Long, Long>> rules = _securityRules.get(info.getHostUuid());
|
||||
|
||||
@ -16,30 +16,84 @@
|
||||
// under the License.
|
||||
package com.cloud.agent.manager;
|
||||
|
||||
import com.cloud.agent.api.*;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.AttachIsoCommand;
|
||||
import com.cloud.agent.api.AttachVolumeCommand;
|
||||
import com.cloud.agent.api.BackupSnapshotCommand;
|
||||
import com.cloud.agent.api.BumpUpPriorityCommand;
|
||||
import com.cloud.agent.api.CheckHealthCommand;
|
||||
import com.cloud.agent.api.CheckNetworkCommand;
|
||||
import com.cloud.agent.api.CheckRouterCommand;
|
||||
import com.cloud.agent.api.CheckVirtualMachineCommand;
|
||||
import com.cloud.agent.api.CleanupNetworkRulesCmd;
|
||||
import com.cloud.agent.api.ClusterSyncCommand;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.ComputeChecksumCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromSnapshotCommand;
|
||||
import com.cloud.agent.api.CreatePrivateTemplateFromVolumeCommand;
|
||||
import com.cloud.agent.api.CreateStoragePoolCommand;
|
||||
import com.cloud.agent.api.CreateVolumeFromSnapshotCommand;
|
||||
import com.cloud.agent.api.DeleteSnapshotBackupCommand;
|
||||
import com.cloud.agent.api.DeleteStoragePoolCommand;
|
||||
import com.cloud.agent.api.GetDomRVersionCmd;
|
||||
import com.cloud.agent.api.GetHostStatsCommand;
|
||||
import com.cloud.agent.api.GetStorageStatsCommand;
|
||||
import com.cloud.agent.api.GetVmStatsCommand;
|
||||
import com.cloud.agent.api.GetVncPortCommand;
|
||||
import com.cloud.agent.api.MaintainCommand;
|
||||
import com.cloud.agent.api.ManageSnapshotCommand;
|
||||
import com.cloud.agent.api.MigrateCommand;
|
||||
import com.cloud.agent.api.ModifyStoragePoolCommand;
|
||||
import com.cloud.agent.api.NetworkUsageCommand;
|
||||
import com.cloud.agent.api.PingTestCommand;
|
||||
import com.cloud.agent.api.PrepareForMigrationCommand;
|
||||
import com.cloud.agent.api.RebootCommand;
|
||||
import com.cloud.agent.api.SecStorageSetupCommand;
|
||||
import com.cloud.agent.api.SecStorageVMSetupCommand;
|
||||
import com.cloud.agent.api.SecurityGroupRulesCmd;
|
||||
import com.cloud.agent.api.StartCommand;
|
||||
import com.cloud.agent.api.StopCommand;
|
||||
import com.cloud.agent.api.StoragePoolInfo;
|
||||
import com.cloud.agent.api.check.CheckSshCommand;
|
||||
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
|
||||
import com.cloud.agent.api.routing.*;
|
||||
import com.cloud.agent.api.storage.*;
|
||||
import com.cloud.agent.api.routing.DhcpEntryCommand;
|
||||
import com.cloud.agent.api.routing.IpAssocCommand;
|
||||
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
|
||||
import com.cloud.agent.api.routing.SavePasswordCommand;
|
||||
import com.cloud.agent.api.routing.SetFirewallRulesCommand;
|
||||
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
|
||||
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
|
||||
import com.cloud.agent.api.routing.VmDataCommand;
|
||||
import com.cloud.agent.api.storage.CopyVolumeCommand;
|
||||
import com.cloud.agent.api.storage.CreateCommand;
|
||||
import com.cloud.agent.api.storage.DeleteTemplateCommand;
|
||||
import com.cloud.agent.api.storage.DestroyCommand;
|
||||
import com.cloud.agent.api.storage.DownloadCommand;
|
||||
import com.cloud.agent.api.storage.DownloadProgressCommand;
|
||||
import com.cloud.agent.api.storage.ListTemplateCommand;
|
||||
import com.cloud.agent.api.storage.ListVolumeCommand;
|
||||
import com.cloud.agent.api.storage.PrimaryStorageDownloadCommand;
|
||||
import com.cloud.simulator.MockConfigurationVO;
|
||||
import com.cloud.simulator.MockHost;
|
||||
import com.cloud.simulator.MockVMVO;
|
||||
import com.cloud.simulator.dao.MockConfigurationDao;
|
||||
import com.cloud.simulator.dao.MockHostDao;
|
||||
import com.cloud.utils.Pair;
|
||||
|
||||
import com.cloud.utils.db.ConnectionConcierge;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import com.cloud.vm.VirtualMachine.State;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Local(value = { SimulatorManager.class })
|
||||
public class SimulatorManagerImpl implements SimulatorManager {
|
||||
@ -57,7 +111,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
|
||||
private ConnectionConcierge _concierge;
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
/*
|
||||
/*
|
||||
try {
|
||||
Connection conn = Transaction.getStandaloneSimulatorConnection();
|
||||
conn.setAutoCommit(true);
|
||||
@ -65,7 +119,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
|
||||
} catch (SQLException e) {
|
||||
throw new CloudRuntimeException("Unable to get a db connection to simulator", e);
|
||||
}
|
||||
*/
|
||||
*/
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -146,7 +200,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
|
||||
} else if (cmd instanceof PingTestCommand) {
|
||||
return _mockAgentMgr.pingTest((PingTestCommand) cmd);
|
||||
} else if (cmd instanceof PrepareForMigrationCommand) {
|
||||
return _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
|
||||
return _mockVmMgr.prepareForMigrate((PrepareForMigrationCommand) cmd);
|
||||
} else if (cmd instanceof MigrateCommand) {
|
||||
return _mockVmMgr.Migrate((MigrateCommand) cmd, info);
|
||||
} else if (cmd instanceof StartCommand) {
|
||||
@ -154,11 +208,11 @@ public class SimulatorManagerImpl implements SimulatorManager {
|
||||
} else if (cmd instanceof CheckSshCommand) {
|
||||
return _mockVmMgr.checkSshCommand((CheckSshCommand) cmd);
|
||||
} else if (cmd instanceof CheckVirtualMachineCommand) {
|
||||
return _mockVmMgr.checkVmState((CheckVirtualMachineCommand) cmd);
|
||||
return _mockVmMgr.checkVmState((CheckVirtualMachineCommand) cmd);
|
||||
} else if (cmd instanceof SetStaticNatRulesCommand) {
|
||||
return _mockVmMgr.SetStaticNatRules((SetStaticNatRulesCommand) cmd);
|
||||
} else if (cmd instanceof SetFirewallRulesCommand) {
|
||||
return _mockVmMgr.SetFirewallRules((SetFirewallRulesCommand) cmd);
|
||||
return _mockVmMgr.SetFirewallRules((SetFirewallRulesCommand) cmd);
|
||||
} else if (cmd instanceof SetPortForwardingRulesCommand) {
|
||||
return _mockVmMgr.SetPortForwardingRules((SetPortForwardingRulesCommand) cmd);
|
||||
} else if (cmd instanceof NetworkUsageCommand) {
|
||||
@ -174,7 +228,7 @@ public class SimulatorManagerImpl implements SimulatorManager {
|
||||
} else if (cmd instanceof CleanupNetworkRulesCmd) {
|
||||
return _mockVmMgr.CleanupNetworkRules((CleanupNetworkRulesCmd) cmd, info);
|
||||
} else if (cmd instanceof CheckNetworkCommand) {
|
||||
return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
|
||||
return _mockAgentMgr.checkNetworkCommand((CheckNetworkCommand) cmd);
|
||||
}else if (cmd instanceof StopCommand) {
|
||||
return _mockVmMgr.stopVM((StopCommand)cmd);
|
||||
} else if (cmd instanceof RebootCommand) {
|
||||
@ -244,11 +298,11 @@ public class SimulatorManagerImpl implements SimulatorManager {
|
||||
} else if (cmd instanceof BumpUpPriorityCommand) {
|
||||
return _mockVmMgr.bumpPriority((BumpUpPriorityCommand) cmd);
|
||||
} else if (cmd instanceof GetDomRVersionCmd) {
|
||||
return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
|
||||
return _mockVmMgr.getDomRVersion((GetDomRVersionCmd) cmd);
|
||||
} else if (cmd instanceof ClusterSyncCommand) {
|
||||
return new Answer(cmd);
|
||||
return new Answer(cmd);
|
||||
} else if (cmd instanceof CopyVolumeCommand) {
|
||||
return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
|
||||
return _mockStorageMgr.CopyVolume((CopyVolumeCommand) cmd);
|
||||
} else {
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
@ -270,49 +324,49 @@ public class SimulatorManagerImpl implements SimulatorManager {
|
||||
|
||||
@Override
|
||||
public Map<String, State> getVmStates(String hostGuid) {
|
||||
return _mockVmMgr.getVmStates(hostGuid);
|
||||
return _mockVmMgr.getVmStates(hostGuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, MockVMVO> getVms(String hostGuid) {
|
||||
return _mockVmMgr.getVms(hostGuid);
|
||||
return _mockVmMgr.getVms(hostGuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid) {
|
||||
SimulatorInfo info = new SimulatorInfo();
|
||||
info.setHostUuid(hostGuid);
|
||||
return _mockVmMgr.syncNetworkGroups(info);
|
||||
SimulatorInfo info = new SimulatorInfo();
|
||||
info.setHostUuid(hostGuid);
|
||||
return _mockVmMgr.syncNetworkGroups(info);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command,
|
||||
String values) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockConfigurationVO config = _mockConfigDao.findByCommand(zoneId, podId, clusterId, hostId, command);
|
||||
if (config == null) {
|
||||
config = new MockConfigurationVO();
|
||||
config.setClusterId(clusterId);
|
||||
config.setDataCenterId(zoneId);
|
||||
config.setPodId(podId);
|
||||
config.setHostId(hostId);
|
||||
config.setName(command);
|
||||
config.setValues(values);
|
||||
_mockConfigDao.persist(config);
|
||||
txn.commit();
|
||||
} else {
|
||||
config.setValues(values);
|
||||
_mockConfigDao.update(config.getId(), config);
|
||||
txn.commit();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to configure simulator because of " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command,
|
||||
String values) {
|
||||
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
|
||||
try {
|
||||
txn.start();
|
||||
MockConfigurationVO config = _mockConfigDao.findByCommand(zoneId, podId, clusterId, hostId, command);
|
||||
if (config == null) {
|
||||
config = new MockConfigurationVO();
|
||||
config.setClusterId(clusterId);
|
||||
config.setDataCenterId(zoneId);
|
||||
config.setPodId(podId);
|
||||
config.setHostId(hostId);
|
||||
config.setName(command);
|
||||
config.setValues(values);
|
||||
_mockConfigDao.persist(config);
|
||||
txn.commit();
|
||||
} else {
|
||||
config.setValues(values);
|
||||
_mockConfigDao.update(config.getId(), config);
|
||||
txn.commit();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
txn.rollback();
|
||||
throw new CloudRuntimeException("Unable to configure simulator because of " + ex.getMessage(), ex);
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -16,20 +16,21 @@
|
||||
// under the License.
|
||||
package com.cloud.api.commands;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.agent.manager.SimulatorManager;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.BaseCmd;
|
||||
import org.apache.cloudstack.api.APICommand;
|
||||
import org.apache.cloudstack.api.Parameter;
|
||||
import org.apache.cloudstack.api.ServerApiException;
|
||||
import org.apache.cloudstack.api.response.SuccessResponse;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.manager.SimulatorManager;
|
||||
import com.cloud.exception.ConcurrentOperationException;
|
||||
import com.cloud.exception.InsufficientCapacityException;
|
||||
import com.cloud.exception.ResourceAllocationException;
|
||||
import com.cloud.exception.ResourceUnavailableException;
|
||||
import com.cloud.server.ManagementService;
|
||||
import com.cloud.user.Account;
|
||||
|
||||
|
||||
@ -38,6 +39,8 @@ public class ConfigureSimulator extends BaseCmd {
|
||||
public static final Logger s_logger = Logger.getLogger(ConfigureSimulator.class.getName());
|
||||
private static final String s_name = "configuresimulatorresponse";
|
||||
|
||||
@Inject SimulatorManager _simMgr;
|
||||
|
||||
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="configure range: in a zone")
|
||||
private Long zoneId;
|
||||
|
||||
@ -58,8 +61,6 @@ public class ConfigureSimulator extends BaseCmd {
|
||||
|
||||
@Override
|
||||
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
|
||||
SimulatorManager _simMgr = locator.getManager(SimulatorManager.class);
|
||||
boolean result = _simMgr.configureSimulator(zoneId, podId, clusterId, hostId, command, values);
|
||||
if (!result) {
|
||||
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to configure simulator");
|
||||
|
||||
@ -26,6 +26,7 @@ import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@ -46,239 +47,237 @@ import com.cloud.simulator.MockHost;
|
||||
|
||||
|
||||
public class AgentResourceBase implements ServerResource {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(AgentResourceBase.class);
|
||||
private static final Logger s_logger = Logger.getLogger(AgentResourceBase.class);
|
||||
|
||||
protected String _name;
|
||||
private List<String> _warnings = new LinkedList<String>();
|
||||
private List<String> _errors = new LinkedList<String>();
|
||||
protected String _name;
|
||||
private List<String> _warnings = new LinkedList<String>();
|
||||
private List<String> _errors = new LinkedList<String>();
|
||||
|
||||
private transient IAgentControl _agentControl;
|
||||
private transient IAgentControl _agentControl;
|
||||
|
||||
protected long _instanceId;
|
||||
protected long _instanceId;
|
||||
|
||||
private Type _type;
|
||||
private Type _type;
|
||||
|
||||
private transient ComponentLocator _locator = null;
|
||||
protected transient SimulatorManager _simMgr;
|
||||
protected MockHost agentHost = null;
|
||||
protected boolean stopped = false;
|
||||
protected String hostGuid = null;
|
||||
@Inject protected SimulatorManager _simMgr;
|
||||
protected MockHost agentHost = null;
|
||||
protected boolean stopped = false;
|
||||
protected String hostGuid = null;
|
||||
|
||||
|
||||
public AgentResourceBase(long instanceId, AgentType agentType, SimulatorManager simMgr, String hostGuid) {
|
||||
_instanceId = instanceId;
|
||||
public AgentResourceBase(long instanceId, AgentType agentType, SimulatorManager simMgr, String hostGuid) {
|
||||
_instanceId = instanceId;
|
||||
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.info("New Routing host instantiated with guid:" + hostGuid);
|
||||
}
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.info("New Routing host instantiated with guid:" + hostGuid);
|
||||
}
|
||||
|
||||
if (agentType == AgentType.Routing) {
|
||||
_type = Host.Type.Routing;
|
||||
} else {
|
||||
_type = Host.Type.Storage;
|
||||
}
|
||||
if (agentType == AgentType.Routing) {
|
||||
_type = Host.Type.Routing;
|
||||
} else {
|
||||
_type = Host.Type.Storage;
|
||||
}
|
||||
|
||||
this.hostGuid = hostGuid;
|
||||
}
|
||||
this.hostGuid = hostGuid;
|
||||
}
|
||||
|
||||
protected MockVmManager getVmMgr() {
|
||||
return _simMgr.getVmMgr();
|
||||
}
|
||||
protected MockVmManager getVmMgr() {
|
||||
return _simMgr.getVmMgr();
|
||||
}
|
||||
|
||||
protected MockStorageManager getStorageMgr() {
|
||||
return _simMgr.getStorageMgr();
|
||||
}
|
||||
protected MockStorageManager getStorageMgr() {
|
||||
return _simMgr.getStorageMgr();
|
||||
}
|
||||
|
||||
protected MockAgentManager getAgentMgr() {
|
||||
return _simMgr.getAgentMgr();
|
||||
}
|
||||
protected MockAgentManager getAgentMgr() {
|
||||
return _simMgr.getAgentMgr();
|
||||
}
|
||||
|
||||
protected long getInstanceId() {
|
||||
return _instanceId;
|
||||
}
|
||||
protected long getInstanceId() {
|
||||
return _instanceId;
|
||||
}
|
||||
|
||||
public AgentResourceBase() {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Deserializing simulated agent on reconnect");
|
||||
}
|
||||
public AgentResourceBase() {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Deserializing simulated agent on reconnect");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
@Override
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
_name = name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
_name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
hostGuid = (String)params.get("guid");
|
||||
_locator = ComponentLocator.getLocator("management-server");
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
hostGuid = (String)params.get("guid");
|
||||
_locator = ComponentLocator.getLocator("management-server");
|
||||
_simMgr = _locator.getManager(SimulatorManager.class);
|
||||
|
||||
agentHost = getAgentMgr().getHost(hostGuid);
|
||||
return true;
|
||||
}
|
||||
agentHost = getAgentMgr().getHost(hostGuid);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void reconnect(MockHost host) {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Reconfiguring existing simulated host w/ name: " + host.getName() + " and guid: " + host.getGuid());
|
||||
}
|
||||
this.agentHost = host;
|
||||
}
|
||||
private void reconnect(MockHost host) {
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Reconfiguring existing simulated host w/ name: " + host.getName() + " and guid: " + host.getGuid());
|
||||
}
|
||||
this.agentHost = host;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void disconnected() {
|
||||
this.stopped = true;
|
||||
}
|
||||
@Override
|
||||
public void disconnected() {
|
||||
this.stopped = true;
|
||||
}
|
||||
|
||||
protected void recordWarning(String msg, Throwable th) {
|
||||
String str = getLogStr(msg, th);
|
||||
synchronized (_warnings) {
|
||||
_warnings.add(str);
|
||||
}
|
||||
}
|
||||
protected void recordWarning(String msg, Throwable th) {
|
||||
String str = getLogStr(msg, th);
|
||||
synchronized (_warnings) {
|
||||
_warnings.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
protected void recordWarning(String msg) {
|
||||
recordWarning(msg, null);
|
||||
}
|
||||
protected void recordWarning(String msg) {
|
||||
recordWarning(msg, null);
|
||||
}
|
||||
|
||||
protected List<String> getWarnings() {
|
||||
synchronized (this) {
|
||||
List<String> results = _warnings;
|
||||
_warnings = new ArrayList<String>();
|
||||
return results;
|
||||
}
|
||||
}
|
||||
protected List<String> getWarnings() {
|
||||
synchronized (this) {
|
||||
List<String> results = _warnings;
|
||||
_warnings = new ArrayList<String>();
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
protected List<String> getErrors() {
|
||||
synchronized (this) {
|
||||
List<String> result = _errors;
|
||||
_errors = new ArrayList<String>();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
protected List<String> getErrors() {
|
||||
synchronized (this) {
|
||||
List<String> result = _errors;
|
||||
_errors = new ArrayList<String>();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
protected void recordError(String msg, Throwable th) {
|
||||
String str = getLogStr(msg, th);
|
||||
synchronized (_errors) {
|
||||
_errors.add(str);
|
||||
}
|
||||
}
|
||||
protected void recordError(String msg, Throwable th) {
|
||||
String str = getLogStr(msg, th);
|
||||
synchronized (_errors) {
|
||||
_errors.add(str);
|
||||
}
|
||||
}
|
||||
|
||||
protected void recordError(String msg) {
|
||||
recordError(msg, null);
|
||||
}
|
||||
protected void recordError(String msg) {
|
||||
recordError(msg, null);
|
||||
}
|
||||
|
||||
protected Answer createErrorAnswer(Command cmd, String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
if (msg != null) {
|
||||
writer.append(msg);
|
||||
}
|
||||
writer.append("===>Stack<===");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
return new Answer(cmd, false, writer.toString());
|
||||
}
|
||||
protected Answer createErrorAnswer(Command cmd, String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
if (msg != null) {
|
||||
writer.append(msg);
|
||||
}
|
||||
writer.append("===>Stack<===");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
return new Answer(cmd, false, writer.toString());
|
||||
}
|
||||
|
||||
protected String createErrorDetail(String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
if (msg != null) {
|
||||
writer.append(msg);
|
||||
}
|
||||
writer.append("===>Stack<===");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
return writer.toString();
|
||||
}
|
||||
protected String createErrorDetail(String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
if (msg != null) {
|
||||
writer.append(msg);
|
||||
}
|
||||
writer.append("===>Stack<===");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
protected String getLogStr(String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.append(new Date().toString()).append(": ").append(msg);
|
||||
if (th != null) {
|
||||
writer.append("\n Exception: ");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
protected String getLogStr(String msg, Throwable th) {
|
||||
StringWriter writer = new StringWriter();
|
||||
writer.append(new Date().toString()).append(": ").append(msg);
|
||||
if (th != null) {
|
||||
writer.append("\n Exception: ");
|
||||
th.printStackTrace(new PrintWriter(writer));
|
||||
}
|
||||
return writer.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean start() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
this.stopped = true;
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public boolean stop() {
|
||||
this.stopped = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAgentControl getAgentControl() {
|
||||
return _agentControl;
|
||||
}
|
||||
@Override
|
||||
public IAgentControl getAgentControl() {
|
||||
return _agentControl;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAgentControl(IAgentControl agentControl) {
|
||||
_agentControl = agentControl;
|
||||
}
|
||||
@Override
|
||||
public void setAgentControl(IAgentControl agentControl) {
|
||||
_agentControl = agentControl;
|
||||
}
|
||||
|
||||
protected String findScript(String script) {
|
||||
s_logger.debug("Looking for " + script + " in the classpath");
|
||||
URL url = ClassLoader.getSystemResource(script);
|
||||
File file = null;
|
||||
if (url == null) {
|
||||
file = new File("./" + script);
|
||||
s_logger.debug("Looking for " + script + " in "
|
||||
+ file.getAbsolutePath());
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
file = new File(url.getFile());
|
||||
}
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
protected String findScript(String script) {
|
||||
s_logger.debug("Looking for " + script + " in the classpath");
|
||||
URL url = ClassLoader.getSystemResource(script);
|
||||
File file = null;
|
||||
if (url == null) {
|
||||
file = new File("./" + script);
|
||||
s_logger.debug("Looking for " + script + " in "
|
||||
+ file.getAbsolutePath());
|
||||
if (!file.exists()) {
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
file = new File(url.getFile());
|
||||
}
|
||||
return file.getAbsolutePath();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
return _type;
|
||||
}
|
||||
@Override
|
||||
public Type getType() {
|
||||
return _type;
|
||||
}
|
||||
|
||||
public void setType(Host.Type _type) {
|
||||
this._type = _type;
|
||||
}
|
||||
public void setType(Host.Type _type) {
|
||||
this._type = _type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public SimulatorManager getSimulatorManager() {
|
||||
return _simMgr;
|
||||
}
|
||||
public SimulatorManager getSimulatorManager() {
|
||||
return _simMgr;
|
||||
}
|
||||
|
||||
public void setSimulatorManager(SimulatorManager simMgr) {
|
||||
_simMgr = simMgr;
|
||||
}
|
||||
public void setSimulatorManager(SimulatorManager simMgr) {
|
||||
_simMgr = simMgr;
|
||||
}
|
||||
|
||||
public boolean isStopped() {
|
||||
return this.stopped;
|
||||
}
|
||||
public boolean isStopped() {
|
||||
return this.stopped;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,6 +25,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@ -43,12 +44,10 @@ import com.cloud.dc.ClusterVO;
|
||||
import com.cloud.dc.dao.ClusterDao;
|
||||
import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.exception.DiscoveryException;
|
||||
import com.cloud.host.Host;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.host.dao.HostDao;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.VMTemplateHostVO;
|
||||
import com.cloud.storage.VMTemplateVO;
|
||||
import com.cloud.storage.VMTemplateZoneVO;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
@ -58,11 +57,11 @@ import com.cloud.storage.dao.VMTemplateZoneDao;
|
||||
|
||||
@Local(value = Discoverer.class)
|
||||
public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, Listener, ResourceStateAdapter {
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(SimulatorDiscoverer.class);
|
||||
private static final Logger s_logger = Logger
|
||||
.getLogger(SimulatorDiscoverer.class);
|
||||
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject VMTemplateDao _vmTemplateDao;
|
||||
@Inject HostDao _hostDao;
|
||||
@Inject VMTemplateDao _vmTemplateDao;
|
||||
@Inject VMTemplateHostDao _vmTemplateHostDao;
|
||||
@Inject VMTemplateZoneDao _vmTemplateZoneDao;
|
||||
@Inject ClusterDao _clusterDao;
|
||||
@ -71,166 +70,166 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L
|
||||
@Inject MockStorageManager _mockStorageMgr = null;
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
|
||||
/**
|
||||
* Finds ServerResources of an in-process simulator
|
||||
*
|
||||
* @see com.cloud.resource.Discoverer#find(long, java.lang.Long,
|
||||
* java.lang.Long, java.net.URI, java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId,
|
||||
Long podId, Long clusterId, URI uri, String username,
|
||||
String password, List<String> hostTags) throws DiscoveryException {
|
||||
Map<AgentResourceBase, Map<String, String>> resources;
|
||||
/**
|
||||
* Finds ServerResources of an in-process simulator
|
||||
*
|
||||
* @see com.cloud.resource.Discoverer#find(long, java.lang.Long,
|
||||
* java.lang.Long, java.net.URI, java.lang.String, java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public Map<? extends ServerResource, Map<String, String>> find(long dcId,
|
||||
Long podId, Long clusterId, URI uri, String username,
|
||||
String password, List<String> hostTags) throws DiscoveryException {
|
||||
Map<AgentResourceBase, Map<String, String>> resources;
|
||||
|
||||
try {
|
||||
//http://sim/count=$count, it will add $count number of hosts into the cluster
|
||||
String scheme = uri.getScheme();
|
||||
String host = uri.getAuthority();
|
||||
String commands = URLDecoder.decode(uri.getPath());
|
||||
try {
|
||||
//http://sim/count=$count, it will add $count number of hosts into the cluster
|
||||
String scheme = uri.getScheme();
|
||||
String host = uri.getAuthority();
|
||||
String commands = URLDecoder.decode(uri.getPath());
|
||||
|
||||
long cpuSpeed = _mockAgentMgr.DEFAULT_HOST_SPEED_MHZ;
|
||||
long cpuCores = _mockAgentMgr.DEFAULT_HOST_CPU_CORES;
|
||||
long memory = _mockAgentMgr.DEFAULT_HOST_MEM_SIZE;
|
||||
long localstorageSize = _mockStorageMgr.DEFAULT_HOST_STORAGE_SIZE;
|
||||
if (scheme.equals("http")) {
|
||||
if (host == null || !host.startsWith("sim")) {
|
||||
String msg = "uri is not of simulator type so we're not taking care of the discovery for this: "
|
||||
+ uri;
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (commands != null) {
|
||||
int index = commands.lastIndexOf("/");
|
||||
if (index != -1) {
|
||||
commands = commands.substring(index+1);
|
||||
long cpuSpeed = _mockAgentMgr.DEFAULT_HOST_SPEED_MHZ;
|
||||
long cpuCores = _mockAgentMgr.DEFAULT_HOST_CPU_CORES;
|
||||
long memory = _mockAgentMgr.DEFAULT_HOST_MEM_SIZE;
|
||||
long localstorageSize = _mockStorageMgr.DEFAULT_HOST_STORAGE_SIZE;
|
||||
if (scheme.equals("http")) {
|
||||
if (host == null || !host.startsWith("sim")) {
|
||||
String msg = "uri is not of simulator type so we're not taking care of the discovery for this: "
|
||||
+ uri;
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (commands != null) {
|
||||
int index = commands.lastIndexOf("/");
|
||||
if (index != -1) {
|
||||
commands = commands.substring(index+1);
|
||||
|
||||
String[] cmds = commands.split("&");
|
||||
for (String cmd : cmds) {
|
||||
String[] parameter = cmd.split("=");
|
||||
if (parameter[0].equalsIgnoreCase("cpuspeed") && parameter[1] != null) {
|
||||
cpuSpeed = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("cpucore") && parameter[1] != null) {
|
||||
cpuCores = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("memory") && parameter[1] != null) {
|
||||
memory = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("localstorage") && parameter[1] != null) {
|
||||
localstorageSize = Long.parseLong(parameter[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String msg = "uriString is not http so we're not taking care of the discovery for this: "
|
||||
+ uri;
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
String[] cmds = commands.split("&");
|
||||
for (String cmd : cmds) {
|
||||
String[] parameter = cmd.split("=");
|
||||
if (parameter[0].equalsIgnoreCase("cpuspeed") && parameter[1] != null) {
|
||||
cpuSpeed = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("cpucore") && parameter[1] != null) {
|
||||
cpuCores = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("memory") && parameter[1] != null) {
|
||||
memory = Long.parseLong(parameter[1]);
|
||||
} else if (parameter[0].equalsIgnoreCase("localstorage") && parameter[1] != null) {
|
||||
localstorageSize = Long.parseLong(parameter[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String msg = "uriString is not http so we're not taking care of the discovery for this: "
|
||||
+ uri;
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
String cluster = null;
|
||||
if (clusterId == null) {
|
||||
String msg = "must specify cluster Id when adding host";
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
throw new RuntimeException(msg);
|
||||
} else {
|
||||
ClusterVO clu = _clusterDao.findById(clusterId);
|
||||
if (clu == null
|
||||
|| (clu.getHypervisorType() != HypervisorType.Simulator)) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("invalid cluster id or cluster is not for Simulator hypervisors");
|
||||
return null;
|
||||
}
|
||||
cluster = Long.toString(clusterId);
|
||||
if(clu.getGuid() == null) {
|
||||
clu.setGuid(UUID.randomUUID().toString());
|
||||
}
|
||||
_clusterDao.update(clusterId, clu);
|
||||
}
|
||||
String cluster = null;
|
||||
if (clusterId == null) {
|
||||
String msg = "must specify cluster Id when adding host";
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
throw new RuntimeException(msg);
|
||||
} else {
|
||||
ClusterVO clu = _clusterDao.findById(clusterId);
|
||||
if (clu == null
|
||||
|| (clu.getHypervisorType() != HypervisorType.Simulator)) {
|
||||
if (s_logger.isInfoEnabled())
|
||||
s_logger.info("invalid cluster id or cluster is not for Simulator hypervisors");
|
||||
return null;
|
||||
}
|
||||
cluster = Long.toString(clusterId);
|
||||
if(clu.getGuid() == null) {
|
||||
clu.setGuid(UUID.randomUUID().toString());
|
||||
}
|
||||
_clusterDao.update(clusterId, clu);
|
||||
}
|
||||
|
||||
String pod;
|
||||
if (podId == null) {
|
||||
String msg = "must specify pod Id when adding host";
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
throw new RuntimeException(msg);
|
||||
} else {
|
||||
pod = Long.toString(podId);
|
||||
}
|
||||
String pod;
|
||||
if (podId == null) {
|
||||
String msg = "must specify pod Id when adding host";
|
||||
if(s_logger.isDebugEnabled()) {
|
||||
s_logger.debug(msg);
|
||||
}
|
||||
throw new RuntimeException(msg);
|
||||
} else {
|
||||
pod = Long.toString(podId);
|
||||
}
|
||||
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
details.put("username", username);
|
||||
params.put("username", username);
|
||||
details.put("password", password);
|
||||
params.put("password", password);
|
||||
params.put("zone", Long.toString(dcId));
|
||||
params.put("pod", pod);
|
||||
params.put("cluster", cluster);
|
||||
params.put("cpuspeed", Long.toString(cpuSpeed));
|
||||
params.put("cpucore", Long.toString(cpuCores));
|
||||
params.put("memory", Long.toString(memory));
|
||||
params.put("localstorage", Long.toString(localstorageSize));
|
||||
Map<String, String> details = new HashMap<String, String>();
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
details.put("username", username);
|
||||
params.put("username", username);
|
||||
details.put("password", password);
|
||||
params.put("password", password);
|
||||
params.put("zone", Long.toString(dcId));
|
||||
params.put("pod", pod);
|
||||
params.put("cluster", cluster);
|
||||
params.put("cpuspeed", Long.toString(cpuSpeed));
|
||||
params.put("cpucore", Long.toString(cpuCores));
|
||||
params.put("memory", Long.toString(memory));
|
||||
params.put("localstorage", Long.toString(localstorageSize));
|
||||
|
||||
resources = createAgentResources(params);
|
||||
return resources;
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception when discovering simulator hosts: "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<AgentResourceBase, Map<String, String>> createAgentResources(
|
||||
Map<String, Object> params) {
|
||||
try {
|
||||
s_logger.info("Creating Simulator Resources");
|
||||
return _mockAgentMgr.createServerResources(params);
|
||||
} catch (Exception ex) {
|
||||
s_logger.warn("Caught exception at agent resource creation: "
|
||||
+ ex.getMessage(), ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postDiscovery(List<HostVO> hosts, long msId) {
|
||||
|
||||
for (HostVO h : hosts) {
|
||||
associateTemplatesToZone(h.getId(), h.getDataCenterId());
|
||||
}
|
||||
}
|
||||
|
||||
private void associateTemplatesToZone(long hostId, long dcId){
|
||||
VMTemplateZoneVO tmpltZone;
|
||||
|
||||
List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
|
||||
for (VMTemplateVO vt: allTemplates){
|
||||
if (vt.isCrossZones()) {
|
||||
tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, vt.getId());
|
||||
if (tmpltZone == null) {
|
||||
VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, vt.getId(), new Date());
|
||||
_vmTemplateZoneDao.persist(vmTemplateZone);
|
||||
}
|
||||
}
|
||||
}
|
||||
resources = createAgentResources(params);
|
||||
return resources;
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("Exception when discovering simulator hosts: "
|
||||
+ ex.getMessage());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorType getHypervisorType() {
|
||||
return HypervisorType.Simulator;
|
||||
}
|
||||
private Map<AgentResourceBase, Map<String, String>> createAgentResources(
|
||||
Map<String, Object> params) {
|
||||
try {
|
||||
s_logger.info("Creating Simulator Resources");
|
||||
return _mockAgentMgr.createServerResources(params);
|
||||
} catch (Exception ex) {
|
||||
s_logger.warn("Caught exception at agent resource creation: "
|
||||
+ ex.getMessage(), ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchHypervisor(String hypervisor) {
|
||||
return hypervisor.equalsIgnoreCase(HypervisorType.Simulator.toString());
|
||||
}
|
||||
@Override
|
||||
public void postDiscovery(List<HostVO> hosts, long msId) {
|
||||
|
||||
for (HostVO h : hosts) {
|
||||
associateTemplatesToZone(h.getId(), h.getDataCenterId());
|
||||
}
|
||||
}
|
||||
|
||||
private void associateTemplatesToZone(long hostId, long dcId){
|
||||
VMTemplateZoneVO tmpltZone;
|
||||
|
||||
List<VMTemplateVO> allTemplates = _vmTemplateDao.listAll();
|
||||
for (VMTemplateVO vt: allTemplates){
|
||||
if (vt.isCrossZones()) {
|
||||
tmpltZone = _vmTemplateZoneDao.findByZoneTemplate(dcId, vt.getId());
|
||||
if (tmpltZone == null) {
|
||||
VMTemplateZoneVO vmTemplateZone = new VMTemplateZoneVO(dcId, vt.getId(), new Date());
|
||||
_vmTemplateZoneDao.persist(vmTemplateZone);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HypervisorType getHypervisorType() {
|
||||
return HypervisorType.Simulator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchHypervisor(String hypervisor) {
|
||||
return hypervisor.equalsIgnoreCase(HypervisorType.Simulator.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
@ -298,38 +297,38 @@ public class SimulatorDiscoverer extends DiscovererBase implements Discoverer, L
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO createHostVOForConnectedAgent(HostVO host,
|
||||
StartupCommand[] cmd) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public HostVO createHostVOForConnectedAgent(HostVO host,
|
||||
StartupCommand[] cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
@Override
|
||||
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.Simulator) {
|
||||
return null;
|
||||
}
|
||||
StartupRoutingCommand ssCmd = ((StartupRoutingCommand) firstCmd);
|
||||
if (ssCmd.getHypervisorType() != HypervisorType.Simulator) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Simulator, details, hostTags);
|
||||
}
|
||||
return _resourceMgr.fillRoutingHostVO(host, ssCmd, HypervisorType.Simulator, details, hostTags);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
|
||||
boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
|
||||
boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
|
||||
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
|
||||
return super.stop();
|
||||
}
|
||||
|
||||
|
||||
@ -21,8 +21,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.Listener;
|
||||
import com.cloud.agent.api.AgentControlAnswer;
|
||||
@ -38,9 +41,7 @@ import com.cloud.host.Status;
|
||||
import com.cloud.storage.SnapshotVO;
|
||||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.storage.secondary.SecondaryStorageDiscoverer;
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
@Local(value=Discoverer.class)
|
||||
public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer implements ResourceStateAdapter, Listener {
|
||||
@ -52,7 +53,7 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer imp
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
_agentMgr.registerForHostEvents(this, true, false, false);
|
||||
_agentMgr.registerForHostEvents(this, true, false, false);
|
||||
_resourceMgr.registerResourceStateAdapter(this.getClass().getSimpleName(), this);
|
||||
return super.configure(name, params);
|
||||
}
|
||||
@ -88,40 +89,40 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer imp
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO createHostVOForConnectedAgent(HostVO host,
|
||||
StartupCommand[] cmd) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public HostVO createHostVOForConnectedAgent(HostVO host,
|
||||
StartupCommand[] cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HostVO createHostVOForDirectConnectAgent(HostVO host,
|
||||
StartupCommand[] startup, ServerResource resource,
|
||||
Map<String, String> details, List<String> hostTags) {
|
||||
//for detecting SSVM dispatch
|
||||
StartupCommand firstCmd = startup[0];
|
||||
if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public HostVO createHostVOForDirectConnectAgent(HostVO host,
|
||||
StartupCommand[] startup, ServerResource resource,
|
||||
Map<String, String> details, List<String> hostTags) {
|
||||
//for detecting SSVM dispatch
|
||||
StartupCommand firstCmd = startup[0];
|
||||
if (!(firstCmd instanceof StartupSecondaryStorageCommand)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
host.setType(com.cloud.host.Host.Type.SecondaryStorageVM);
|
||||
return host;
|
||||
}
|
||||
host.setType(com.cloud.host.Host.Type.SecondaryStorageVM);
|
||||
return host;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
|
||||
boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
||||
long hostId = host.getId();
|
||||
List<SnapshotVO> snapshots = _snapshotDao.listByHostId(hostId);
|
||||
if (snapshots != null && !snapshots.isEmpty()) {
|
||||
throw new CloudRuntimeException("Cannot delete this secondary storage because there are still snapshots on it ");
|
||||
}
|
||||
_vmTemplateHostDao.deleteByHost(hostId);
|
||||
host.setGuid(null);
|
||||
_hostDao.update(hostId, host);
|
||||
_hostDao.remove(hostId);
|
||||
return new DeleteHostAnswer(true);
|
||||
}
|
||||
@Override
|
||||
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced,
|
||||
boolean isForceDeleteStorage) throws UnableDeleteHostException {
|
||||
long hostId = host.getId();
|
||||
List<SnapshotVO> snapshots = _snapshotDao.listByHostId(hostId);
|
||||
if (snapshots != null && !snapshots.isEmpty()) {
|
||||
throw new CloudRuntimeException("Cannot delete this secondary storage because there are still snapshots on it ");
|
||||
}
|
||||
_vmTemplateHostDao.deleteByHost(hostId);
|
||||
host.setGuid(null);
|
||||
_hostDao.update(hostId, host);
|
||||
_hostDao.remove(hostId);
|
||||
return new DeleteHostAnswer(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean start() {
|
||||
@ -130,49 +131,49 @@ public class SimulatorSecondaryDiscoverer extends SecondaryStorageDiscoverer imp
|
||||
|
||||
@Override
|
||||
public boolean stop() {
|
||||
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
|
||||
_resourceMgr.unregisterResourceStateAdapter(this.getClass().getSimpleName());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
return 0;
|
||||
}
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRecurring() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isRecurring() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean processAnswers(long agentId, long seq, Answer[] answers) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processCommands(long agentId, long seq, Command[] commands) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean processCommands(long agentId, long seq, Command[] commands) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processConnect(HostVO host, StartupCommand cmd,
|
||||
boolean forRebalance) throws ConnectionException {
|
||||
@Override
|
||||
public void processConnect(HostVO host, StartupCommand cmd,
|
||||
boolean forRebalance) throws ConnectionException {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public AgentControlAnswer processControlCommand(long agentId,
|
||||
AgentControlCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public AgentControlAnswer processControlCommand(long agentId,
|
||||
AgentControlCommand cmd) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processDisconnect(long agentId, Status state) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean processDisconnect(long agentId, Status state) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean processTimeout(long agentId, long seq) {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean processTimeout(long agentId, long seq) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,14 +17,14 @@
|
||||
package com.cloud.simulator;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.hypervisor.HypervisorGuru;
|
||||
import com.cloud.hypervisor.HypervisorGuruBase;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.storage.GuestOSVO;
|
||||
import com.cloud.storage.dao.GuestOSDao;
|
||||
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
|
||||
@ -52,8 +52,8 @@ public class SimulatorGuru extends HypervisorGuruBase implements HypervisorGuru
|
||||
return to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean trackVmHostChange() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean trackVmHostChange() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -21,11 +21,11 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import com.cloud.simulator.MockHostVO;
|
||||
import com.cloud.simulator.MockVMVO;
|
||||
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.JoinBuilder;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
|
||||
@ -23,40 +23,38 @@ import java.security.SecureRandom;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.bouncycastle.util.encoders.Base64;
|
||||
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.servlet.CloudStartupServlet;
|
||||
import com.cloud.user.UserAccount;
|
||||
import com.cloud.user.dao.UserAccountDao;
|
||||
|
||||
|
||||
import com.cloud.utils.exception.CloudRuntimeException;
|
||||
|
||||
@Local(value={UserAuthenticator.class})
|
||||
public class SHA256SaltedUserAuthenticator extends DefaultUserAuthenticator {
|
||||
public static final Logger s_logger = Logger.getLogger(SHA256SaltedUserAuthenticator.class);
|
||||
|
||||
@Inject
|
||||
private UserAccountDao _userAccountDao;
|
||||
private static int s_saltlen = 20;
|
||||
public static final Logger s_logger = Logger.getLogger(SHA256SaltedUserAuthenticator.class);
|
||||
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.server.auth.UserAuthenticator#authenticate(java.lang.String, java.lang.String, java.lang.Long, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public boolean authenticate(String username, String password,
|
||||
Long domainId, Map<String, Object[]> requestParameters) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@Inject
|
||||
private UserAccountDao _userAccountDao;
|
||||
private static int s_saltlen = 20;
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params)
|
||||
throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
return true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.server.auth.UserAuthenticator#authenticate(java.lang.String, java.lang.String, java.lang.Long, java.util.Map)
|
||||
*/
|
||||
@Override
|
||||
public boolean authenticate(String username, String password,
|
||||
Long domainId, Map<String, Object[]> requestParameters) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Retrieving user: " + username);
|
||||
}
|
||||
UserAccount user = _userAccountDao.getUserAccount(username, domainId);
|
||||
@ -64,59 +62,59 @@ public class SHA256SaltedUserAuthenticator extends DefaultUserAuthenticator {
|
||||
s_logger.debug("Unable to find user with " + username + " in domain " + domainId);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
String storedPassword[] = user.getPassword().split(":");
|
||||
if (storedPassword.length != 2) {
|
||||
s_logger.warn("The stored password for " + username + " isn't in the right format for this authenticator");
|
||||
return false;
|
||||
}
|
||||
byte salt[] = Base64.decode(storedPassword[0]);
|
||||
String hashedPassword = encode(password, salt);
|
||||
return storedPassword[1].equals(hashedPassword);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new CloudRuntimeException("Unable to hash password", e);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new CloudRuntimeException("Unable to hash password", e);
|
||||
}
|
||||
}
|
||||
String storedPassword[] = user.getPassword().split(":");
|
||||
if (storedPassword.length != 2) {
|
||||
s_logger.warn("The stored password for " + username + " isn't in the right format for this authenticator");
|
||||
return false;
|
||||
}
|
||||
byte salt[] = Base64.decode(storedPassword[0]);
|
||||
String hashedPassword = encode(password, salt);
|
||||
return storedPassword[1].equals(hashedPassword);
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new CloudRuntimeException("Unable to hash password", e);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new CloudRuntimeException("Unable to hash password", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.server.auth.UserAuthenticator#encode(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String encode(String password) {
|
||||
// 1. Generate the salt
|
||||
SecureRandom randomGen;
|
||||
try {
|
||||
randomGen = SecureRandom.getInstance("SHA1PRNG");
|
||||
|
||||
byte salt[] = new byte[s_saltlen];
|
||||
randomGen.nextBytes(salt);
|
||||
|
||||
String saltString = new String(Base64.encode(salt));
|
||||
String hashString = encode(password, salt);
|
||||
|
||||
// 3. concatenate the two and return
|
||||
return saltString + ":" + hashString;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new CloudRuntimeException("Unable to hash password", e);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new CloudRuntimeException("Unable to hash password", e);
|
||||
}
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see com.cloud.server.auth.UserAuthenticator#encode(java.lang.String)
|
||||
*/
|
||||
@Override
|
||||
public String encode(String password) {
|
||||
// 1. Generate the salt
|
||||
SecureRandom randomGen;
|
||||
try {
|
||||
randomGen = SecureRandom.getInstance("SHA1PRNG");
|
||||
|
||||
public String encode(String password, byte[] salt) throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
byte[] passwordBytes = password.getBytes("UTF-8");
|
||||
byte[] hashSource = new byte[passwordBytes.length + s_saltlen];
|
||||
System.arraycopy(passwordBytes, 0, hashSource, 0, passwordBytes.length);
|
||||
System.arraycopy(salt, 0, hashSource, passwordBytes.length, s_saltlen);
|
||||
|
||||
// 2. Hash the password with the salt
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
md.update(hashSource);
|
||||
byte[] digest = md.digest();
|
||||
|
||||
return new String(Base64.encode(digest));
|
||||
}
|
||||
byte salt[] = new byte[s_saltlen];
|
||||
randomGen.nextBytes(salt);
|
||||
|
||||
String saltString = new String(Base64.encode(salt));
|
||||
String hashString = encode(password, salt);
|
||||
|
||||
// 3. concatenate the two and return
|
||||
return saltString + ":" + hashString;
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new CloudRuntimeException("Unable to hash password", e);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new CloudRuntimeException("Unable to hash password", e);
|
||||
}
|
||||
}
|
||||
|
||||
public String encode(String password, byte[] salt) throws UnsupportedEncodingException, NoSuchAlgorithmException {
|
||||
byte[] passwordBytes = password.getBytes("UTF-8");
|
||||
byte[] hashSource = new byte[passwordBytes.length + s_saltlen];
|
||||
System.arraycopy(passwordBytes, 0, hashSource, 0, passwordBytes.length);
|
||||
System.arraycopy(salt, 0, hashSource, passwordBytes.length, s_saltlen);
|
||||
|
||||
// 2. Hash the password with the salt
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
md.update(hashSource);
|
||||
byte[] digest = md.digest();
|
||||
|
||||
return new String(Base64.encode(digest));
|
||||
}
|
||||
}
|
||||
|
||||
@ -20,7 +20,6 @@ import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URLDecoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
@ -32,16 +31,20 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
|
||||
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.AddSecondaryStorageCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.ReconnectHostCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.ListS3sCmd;
|
||||
import org.apache.cloudstack.api.command.admin.swift.AddSwiftCmd;
|
||||
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.*;
|
||||
import org.apache.cloudstack.api.command.admin.swift.ListSwiftsCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.AddS3Cmd;
|
||||
import com.cloud.storage.S3;
|
||||
import com.cloud.storage.S3VO;
|
||||
import com.cloud.storage.s3.S3Manager;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ -59,12 +62,7 @@ import com.cloud.agent.api.UpdateHostPasswordCommand;
|
||||
import com.cloud.agent.manager.AgentAttache;
|
||||
import com.cloud.agent.manager.allocator.PodAllocator;
|
||||
import com.cloud.agent.transport.Request;
|
||||
import org.apache.cloudstack.api.ApiConstants;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.CancelMaintenanceCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.PrepareForMaintenanceCmd;
|
||||
import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
|
||||
import com.cloud.capacity.Capacity;
|
||||
import com.cloud.capacity.CapacityVO;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
@ -112,6 +110,8 @@ import com.cloud.org.Grouping.AllocationState;
|
||||
import com.cloud.org.Managed;
|
||||
import com.cloud.service.ServiceOfferingVO;
|
||||
import com.cloud.storage.GuestOSCategoryVO;
|
||||
import com.cloud.storage.S3;
|
||||
import com.cloud.storage.S3VO;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.StoragePool;
|
||||
import com.cloud.storage.StoragePoolHostVO;
|
||||
@ -125,6 +125,7 @@ import com.cloud.storage.dao.GuestOSCategoryDao;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
import com.cloud.storage.dao.StoragePoolHostDao;
|
||||
import com.cloud.storage.dao.VMTemplateDao;
|
||||
import com.cloud.storage.s3.S3Manager;
|
||||
import com.cloud.storage.secondary.SecondaryStorageVmManager;
|
||||
import com.cloud.storage.swift.SwiftManager;
|
||||
import com.cloud.template.VirtualMachineTemplate;
|
||||
@ -135,7 +136,6 @@ import com.cloud.user.UserContext;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.StringUtils;
|
||||
import com.cloud.utils.UriUtils;
|
||||
import com.cloud.utils.component.Adapters;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
@ -219,7 +219,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
||||
// @com.cloud.utils.component.Inject(adapter = PodAllocator.class)
|
||||
@Inject
|
||||
protected List<PodAllocator> _podAllocators = null;
|
||||
|
||||
|
||||
@Inject
|
||||
protected VMTemplateDao _templateDao;
|
||||
@Inject
|
||||
@ -236,9 +236,9 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// TODO initialize pod allocators here instead
|
||||
// TODO initialize pod allocators here instead
|
||||
}
|
||||
|
||||
|
||||
private void insertListener(Integer event, ResourceListener listener) {
|
||||
List<ResourceListener> lst = _lifeCycleListeners.get(event);
|
||||
if (lst == null) {
|
||||
@ -510,10 +510,10 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
||||
|
||||
@Override
|
||||
public Discoverer getMatchingDiscover(Hypervisor.HypervisorType hypervisorType) {
|
||||
for(Discoverer discoverer : _discoverers) {
|
||||
for(Discoverer discoverer : _discoverers) {
|
||||
if (discoverer.getHypervisorType() == hypervisorType)
|
||||
return discoverer;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -1629,7 +1629,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
new Request(-1l, -1l, cmds, true, false).logD("Startup request from directly connected host: ", true);
|
||||
}
|
||||
@ -1670,7 +1670,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (tempHost != null) {
|
||||
/* Change agent status to Alert */
|
||||
_agentMgr.agentStatusTransitTo(tempHost, Status.Event.AgentDisconnected, _nodeId);
|
||||
@ -2179,7 +2179,7 @@ public class ResourceManagerImpl implements ResourceManager, ResourceService, Ma
|
||||
|
||||
@Override
|
||||
public Pair<HostPodVO, Long> findPod(VirtualMachineTemplate template, ServiceOfferingVO offering, DataCenterVO dc, long accountId, Set<Long> avoids) {
|
||||
for(PodAllocator allocator : _podAllocators) {
|
||||
for(PodAllocator allocator : _podAllocators) {
|
||||
final Pair<HostPodVO, Long> pod = allocator.allocateTo(template, offering, dc, accountId, avoids);
|
||||
if (pod != null) {
|
||||
return pod;
|
||||
|
||||
@ -27,15 +27,16 @@ import java.util.Map;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.apache.cloudstack.api.IdentityService;
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.apache.cloudstack.api.IdentityService;
|
||||
import com.cloud.exception.PermissionDeniedException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.server.ManagementServer;
|
||||
@ -46,7 +47,6 @@ import com.cloud.user.User;
|
||||
import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.Ternary;
|
||||
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
@ -63,10 +63,10 @@ public class ConsoleProxyServlet extends HttpServlet {
|
||||
private static final int DEFAULT_THUMBNAIL_WIDTH = 144;
|
||||
private static final int DEFAULT_THUMBNAIL_HEIGHT = 110;
|
||||
|
||||
private final static AccountManager _accountMgr = ComponentLocator.getLocator(ManagementServer.Name).getManager(AccountManager.class);
|
||||
private final static VirtualMachineManager _vmMgr = ComponentLocator.getLocator(ManagementServer.Name).getManager(VirtualMachineManager.class);
|
||||
private final static ManagementServer _ms = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name);
|
||||
private final static IdentityService _identityService = ComponentLocator.getLocator(ManagementServer.Name).getManager(IdentityService.class);
|
||||
@Inject AccountManager _accountMgr;
|
||||
@Inject VirtualMachineManager _vmMgr;
|
||||
@Inject ManagementServer _ms;
|
||||
@Inject IdentityService _identityService;
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
||||
|
||||
@ -19,9 +19,9 @@ package com.cloud.servlet;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@ -30,7 +30,6 @@ import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.configuration.Configuration;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.user.Account;
|
||||
import com.cloud.user.AccountService;
|
||||
import com.cloud.user.User;
|
||||
@ -40,104 +39,90 @@ import com.cloud.utils.SerialVersionUID;
|
||||
|
||||
|
||||
public class RegisterCompleteServlet extends HttpServlet implements ServletContextListener {
|
||||
public static final Logger s_logger = Logger.getLogger(RegisterCompleteServlet.class.getName());
|
||||
|
||||
public static final Logger s_logger = Logger.getLogger(RegisterCompleteServlet.class.getName());
|
||||
|
||||
static final long serialVersionUID = SerialVersionUID.CloudStartupServlet;
|
||||
|
||||
protected static AccountService _accountSvc = null;
|
||||
protected static ConfigurationDao _configDao = null;
|
||||
protected static UserDao _userDao = null;
|
||||
|
||||
@Override
|
||||
public void init() throws ServletException {
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
_accountSvc = locator.getManager(AccountService.class);
|
||||
_configDao = locator.getDao(ConfigurationDao.class);
|
||||
_userDao = locator.getDao(UserDao.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
try {
|
||||
init();
|
||||
} catch (ServletException e) {
|
||||
s_logger.error("Exception starting management server ", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@Inject AccountService _accountSvc = null;
|
||||
@Inject ConfigurationDao _configDao = null;
|
||||
@Inject UserDao _userDao = null;
|
||||
|
||||
@Override
|
||||
public void contextInitialized(ServletContextEvent sce) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void contextDestroyed(ServletContextEvent sce) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
||||
doGet(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
doGet(req, resp);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
|
||||
String registrationToken = req.getParameter("token");
|
||||
String expires = req.getParameter("expires");
|
||||
int statusCode = HttpServletResponse.SC_OK;
|
||||
String responseMessage = null;
|
||||
|
||||
if (registrationToken == null || registrationToken.trim().length() == 0) {
|
||||
statusCode = 503;
|
||||
responseMessage = "{ \"registration_info\" : { \"errorcode\" : \"503\", \"errortext\" : \"Missing token\" } }";
|
||||
} else {
|
||||
s_logger.info("Attempting to register user account with token = "+registrationToken);
|
||||
User resourceAdminUser = _accountSvc.getActiveUserByRegistrationToken(registrationToken);
|
||||
if (resourceAdminUser != null) {
|
||||
if(resourceAdminUser.isRegistered()) {
|
||||
statusCode = 503;
|
||||
responseMessage = "{ \"registration_info\" : { \"errorcode\" : \"503\", \"errortext\" : \"Expired token = " + registrationToken + "\" } }";
|
||||
} else {
|
||||
if(expires != null && expires.toLowerCase().equals("true")){
|
||||
_accountSvc.markUserRegistered(resourceAdminUser.getId());
|
||||
}
|
||||
|
||||
Account resourceAdminAccount = _accountSvc.getActiveAccountById(resourceAdminUser.getAccountId());
|
||||
Account rsUserAccount = _accountSvc.getActiveAccountByName(resourceAdminAccount.getAccountName()+"-user", resourceAdminAccount.getDomainId());
|
||||
|
||||
List<UserVO> users = _userDao.listByAccount(rsUserAccount.getId());
|
||||
User rsUser = users.get(0);
|
||||
|
||||
Configuration config = _configDao.findByName("endpointe.url");
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("{ \"registration_info\" : { \"endpoint_url\" : \""+encodeParam(config.getValue())+"\", ");
|
||||
sb.append("\"domain_id\" : \""+resourceAdminAccount.getDomainId()+"\", ");
|
||||
sb.append("\"admin_account\" : \""+encodeParam(resourceAdminUser.getUsername())+"\", ");
|
||||
sb.append("\"admin_account_api_key\" : \""+resourceAdminUser.getApiKey()+"\", ");
|
||||
sb.append("\"admin_account_secret_key\" : \""+resourceAdminUser.getSecretKey()+"\", ");
|
||||
sb.append("\"user_account\" : \""+encodeParam(rsUser.getUsername())+"\", ");
|
||||
sb.append("\"user_account_api_key\" : \""+rsUser.getApiKey()+"\", ");
|
||||
sb.append("\"user_account_secret_key\" : \""+rsUser.getSecretKey()+"\" ");
|
||||
sb.append("} }");
|
||||
responseMessage = sb.toString();
|
||||
}
|
||||
} else {
|
||||
statusCode = 503;
|
||||
responseMessage = "{ \"registration_info\" : { \"errorcode\" : \"503\", \"errortext\" : \"Invalid token = " + registrationToken + "\" } }";
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
resp.setContentType("text/javascript; charset=UTF-8");
|
||||
resp.setStatus(statusCode);
|
||||
resp.getWriter().print(responseMessage);
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("unknown exception writing register complete response", ex);
|
||||
String registrationToken = req.getParameter("token");
|
||||
String expires = req.getParameter("expires");
|
||||
int statusCode = HttpServletResponse.SC_OK;
|
||||
String responseMessage = null;
|
||||
|
||||
if (registrationToken == null || registrationToken.trim().length() == 0) {
|
||||
statusCode = 503;
|
||||
responseMessage = "{ \"registration_info\" : { \"errorcode\" : \"503\", \"errortext\" : \"Missing token\" } }";
|
||||
} else {
|
||||
s_logger.info("Attempting to register user account with token = "+registrationToken);
|
||||
User resourceAdminUser = _accountSvc.getActiveUserByRegistrationToken(registrationToken);
|
||||
if (resourceAdminUser != null) {
|
||||
if(resourceAdminUser.isRegistered()) {
|
||||
statusCode = 503;
|
||||
responseMessage = "{ \"registration_info\" : { \"errorcode\" : \"503\", \"errortext\" : \"Expired token = " + registrationToken + "\" } }";
|
||||
} else {
|
||||
if(expires != null && expires.toLowerCase().equals("true")){
|
||||
_accountSvc.markUserRegistered(resourceAdminUser.getId());
|
||||
}
|
||||
|
||||
Account resourceAdminAccount = _accountSvc.getActiveAccountById(resourceAdminUser.getAccountId());
|
||||
Account rsUserAccount = _accountSvc.getActiveAccountByName(resourceAdminAccount.getAccountName()+"-user", resourceAdminAccount.getDomainId());
|
||||
|
||||
List<UserVO> users = _userDao.listByAccount(rsUserAccount.getId());
|
||||
User rsUser = users.get(0);
|
||||
|
||||
Configuration config = _configDao.findByName("endpointe.url");
|
||||
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("{ \"registration_info\" : { \"endpoint_url\" : \""+encodeParam(config.getValue())+"\", ");
|
||||
sb.append("\"domain_id\" : \""+resourceAdminAccount.getDomainId()+"\", ");
|
||||
sb.append("\"admin_account\" : \""+encodeParam(resourceAdminUser.getUsername())+"\", ");
|
||||
sb.append("\"admin_account_api_key\" : \""+resourceAdminUser.getApiKey()+"\", ");
|
||||
sb.append("\"admin_account_secret_key\" : \""+resourceAdminUser.getSecretKey()+"\", ");
|
||||
sb.append("\"user_account\" : \""+encodeParam(rsUser.getUsername())+"\", ");
|
||||
sb.append("\"user_account_api_key\" : \""+rsUser.getApiKey()+"\", ");
|
||||
sb.append("\"user_account_secret_key\" : \""+rsUser.getSecretKey()+"\" ");
|
||||
sb.append("} }");
|
||||
responseMessage = sb.toString();
|
||||
}
|
||||
} else {
|
||||
statusCode = 503;
|
||||
responseMessage = "{ \"registration_info\" : { \"errorcode\" : \"503\", \"errortext\" : \"Invalid token = " + registrationToken + "\" } }";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String encodeParam(String value) {
|
||||
try {
|
||||
return URLEncoder.encode(value, "UTF-8").replaceAll("\\+", "%20");
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to encode: " + value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
try {
|
||||
resp.setContentType("text/javascript; charset=UTF-8");
|
||||
resp.setStatus(statusCode);
|
||||
resp.getWriter().print(responseMessage);
|
||||
} catch (Exception ex) {
|
||||
s_logger.error("unknown exception writing register complete response", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private String encodeParam(String value) {
|
||||
try {
|
||||
return URLEncoder.encode(value, "UTF-8").replaceAll("\\+", "%20");
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to encode: " + value);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,7 +28,6 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -45,7 +44,10 @@ import javax.ejb.Local;
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.cloudstack.api.command.admin.storage.*;
|
||||
import org.apache.cloudstack.api.command.admin.storage.CancelPrimaryStorageMaintenanceCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.DeletePoolCmd;
|
||||
import org.apache.cloudstack.api.command.admin.storage.UpdateStoragePoolCmd;
|
||||
import org.apache.cloudstack.api.command.user.volume.CreateVolumeCmd;
|
||||
import org.apache.cloudstack.api.command.user.volume.UploadVolumeCmd;
|
||||
import org.apache.log4j.Logger;
|
||||
@ -76,14 +78,12 @@ import com.cloud.agent.api.to.VolumeTO;
|
||||
import com.cloud.agent.manager.Commands;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.api.ApiDBUtils;
|
||||
import org.apache.cloudstack.api.command.admin.storage.CreateStoragePoolCmd;
|
||||
import com.cloud.async.AsyncJobManager;
|
||||
import com.cloud.capacity.Capacity;
|
||||
import com.cloud.capacity.CapacityManager;
|
||||
import com.cloud.capacity.CapacityState;
|
||||
import com.cloud.capacity.CapacityVO;
|
||||
import com.cloud.capacity.dao.CapacityDao;
|
||||
import com.cloud.cluster.CheckPointManager;
|
||||
import com.cloud.cluster.ClusterManagerListener;
|
||||
import com.cloud.cluster.ManagementServerHostVO;
|
||||
import com.cloud.configuration.Config;
|
||||
@ -172,8 +172,7 @@ import com.cloud.utils.EnumUtils;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.UriUtils;
|
||||
import com.cloud.utils.component.Adapters;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.DB;
|
||||
@ -322,8 +321,6 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
@Inject
|
||||
protected ResourceManager _resourceMgr;
|
||||
@Inject
|
||||
protected CheckPointManager _checkPointMgr;
|
||||
@Inject
|
||||
protected DownloadMonitor _downloadMonitor;
|
||||
@Inject
|
||||
protected ResourceTagDao _resourceTagDao;
|
||||
@ -355,14 +352,14 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
protected BigDecimal _overProvisioningFactor = new BigDecimal(1);
|
||||
private long _maxVolumeSizeInGb;
|
||||
private long _serverId;
|
||||
private StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
|
||||
private final StateMachine2<Volume.State, Volume.Event, Volume> _volStateMachine;
|
||||
private int _customDiskOfferingMinSize = 1;
|
||||
private int _customDiskOfferingMaxSize = 1024;
|
||||
private double _storageUsedThreshold = 1.0d;
|
||||
private double _storageAllocatedThreshold = 1.0d;
|
||||
protected BigDecimal _storageOverprovisioningFactor = new BigDecimal(1);
|
||||
|
||||
private boolean _recreateSystemVmEnabled;
|
||||
private boolean _recreateSystemVmEnabled;
|
||||
|
||||
public boolean share(VMInstanceVO vm, List<VolumeVO> vols, HostVO host, boolean cancelPreviousShare) throws StorageUnavailableException {
|
||||
|
||||
@ -653,9 +650,9 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
Pair<VolumeVO, String> volumeDetails = createVolumeFromSnapshot(volume, snapshot);
|
||||
if (volumeDetails != null) {
|
||||
createdVolume = volumeDetails.first();
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, createdVolume.getAccountId(), createdVolume.getDataCenterId(), createdVolume.getId(), createdVolume.getName(),
|
||||
createdVolume.getDiskOfferingId(), null, createdVolume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, createdVolume.getAccountId(), createdVolume.getDataCenterId(), createdVolume.getId(), createdVolume.getName(),
|
||||
createdVolume.getDiskOfferingId(), null, createdVolume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
return createdVolume;
|
||||
}
|
||||
@ -739,32 +736,32 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
@DB
|
||||
public VolumeVO copyVolumeFromSecToPrimary(VolumeVO volume, VMInstanceVO vm, VMTemplateVO template, DataCenterVO dc, HostPodVO pod, Long clusterId, ServiceOfferingVO offering, DiskOfferingVO diskOffering,
|
||||
List<StoragePoolVO> avoids, long size, HypervisorType hyperType) throws NoTransitionException {
|
||||
|
||||
final HashSet<StoragePool> avoidPools = new HashSet<StoragePool>(avoids);
|
||||
DiskProfile dskCh = createDiskCharacteristics(volume, template, dc, diskOffering);
|
||||
dskCh.setHyperType(vm.getHypervisorType());
|
||||
// Find a suitable storage to create volume on
|
||||
StoragePoolVO destPool = findStoragePool(dskCh, dc, pod, clusterId, null, vm, avoidPools);
|
||||
|
||||
// Copy the volume from secondary storage to the destination storage pool
|
||||
stateTransitTo(volume, Event.CopyRequested);
|
||||
VolumeHostVO volumeHostVO = _volumeHostDao.findByVolumeId(volume.getId());
|
||||
HostVO secStorage = _hostDao.findById(volumeHostVO.getHostId());
|
||||
String secondaryStorageURL = secStorage.getStorageUrl();
|
||||
String[] volumePath = volumeHostVO.getInstallPath().split("/");
|
||||
String volumeUUID = volumePath[volumePath.length - 1].split("\\.")[0];
|
||||
|
||||
|
||||
final HashSet<StoragePool> avoidPools = new HashSet<StoragePool>(avoids);
|
||||
DiskProfile dskCh = createDiskCharacteristics(volume, template, dc, diskOffering);
|
||||
dskCh.setHyperType(vm.getHypervisorType());
|
||||
// Find a suitable storage to create volume on
|
||||
StoragePoolVO destPool = findStoragePool(dskCh, dc, pod, clusterId, null, vm, avoidPools);
|
||||
|
||||
// Copy the volume from secondary storage to the destination storage pool
|
||||
stateTransitTo(volume, Event.CopyRequested);
|
||||
VolumeHostVO volumeHostVO = _volumeHostDao.findByVolumeId(volume.getId());
|
||||
HostVO secStorage = _hostDao.findById(volumeHostVO.getHostId());
|
||||
String secondaryStorageURL = secStorage.getStorageUrl();
|
||||
String[] volumePath = volumeHostVO.getInstallPath().split("/");
|
||||
String volumeUUID = volumePath[volumePath.length - 1].split("\\.")[0];
|
||||
|
||||
CopyVolumeCommand cvCmd = new CopyVolumeCommand(volume.getId(), volumeUUID, destPool, secondaryStorageURL, false, _copyvolumewait);
|
||||
CopyVolumeAnswer cvAnswer;
|
||||
try {
|
||||
try {
|
||||
cvAnswer = (CopyVolumeAnswer) sendToPool(destPool, cvCmd);
|
||||
} catch (StorageUnavailableException e1) {
|
||||
stateTransitTo(volume, Event.CopyFailed);
|
||||
stateTransitTo(volume, Event.CopyFailed);
|
||||
throw new CloudRuntimeException("Failed to copy the volume from secondary storage to the destination primary storage pool.");
|
||||
}
|
||||
|
||||
if (cvAnswer == null || !cvAnswer.getResult()) {
|
||||
stateTransitTo(volume, Event.CopyFailed);
|
||||
stateTransitTo(volume, Event.CopyFailed);
|
||||
throw new CloudRuntimeException("Failed to copy the volume from secondary storage to the destination primary storage pool.");
|
||||
}
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
@ -778,11 +775,11 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), volume.getDiskOfferingId(), null, volume.getSize());
|
||||
_usageEventDao.persist(usageEvent);
|
||||
_volumeHostDao.remove(volumeHostVO.getId());
|
||||
txn.commit();
|
||||
return volume;
|
||||
|
||||
txn.commit();
|
||||
return volume;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@DB
|
||||
public VolumeVO createVolume(VolumeVO volume, VMInstanceVO vm, VMTemplateVO template, DataCenterVO dc, HostPodVO pod, Long clusterId, ServiceOfferingVO offering, DiskOfferingVO diskOffering,
|
||||
@ -848,11 +845,11 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
String fullTmpltUrl = tmpltHostUrl + "/" + tmpltHostOn.getInstallPath();
|
||||
cmd = new CreateCommand(dskCh, fullTmpltUrl, new StorageFilerTO(pool));
|
||||
} else {
|
||||
tmpltStoredOn = _tmpltMgr.prepareTemplateForCreate(template, pool);
|
||||
if (tmpltStoredOn == null) {
|
||||
continue;
|
||||
}
|
||||
cmd = new CreateCommand(dskCh, tmpltStoredOn.getLocalDownloadPath(), new StorageFilerTO(pool));
|
||||
tmpltStoredOn = _tmpltMgr.prepareTemplateForCreate(template, pool);
|
||||
if (tmpltStoredOn == null) {
|
||||
continue;
|
||||
}
|
||||
cmd = new CreateCommand(dskCh, tmpltStoredOn.getLocalDownloadPath(), new StorageFilerTO(pool));
|
||||
}
|
||||
} else {
|
||||
if (volume.getVolumeType() == Type.ROOT && Storage.ImageFormat.ISO == template.getFormat()) {
|
||||
@ -969,7 +966,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
|
||||
value = _configDao.getValue(Config.RecreateSystemVmEnabled.key());
|
||||
_recreateSystemVmEnabled = Boolean.parseBoolean(value);
|
||||
|
||||
|
||||
value = _configDao.getValue(Config.StorageTemplateCleanupEnabled.key());
|
||||
_templateCleanupEnabled = (value == null ? true : Boolean.parseBoolean(value));
|
||||
|
||||
@ -995,7 +992,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
int wrks = NumbersUtil.parseInt(workers, 10);
|
||||
_executor = Executors.newScheduledThreadPool(wrks, new NamedThreadFactory("StorageManager-Scavenger"));
|
||||
|
||||
_agentMgr.registerForHostEvents(ComponentLocator.inject(LocalStoragePoolListener.class), true, false, false);
|
||||
_agentMgr.registerForHostEvents(ComponentContext.inject(LocalStoragePoolListener.class), true, false, false);
|
||||
|
||||
String maxVolumeSizeInGbString = _configDao.getValue("storage.max.volume.size");
|
||||
_maxVolumeSizeInGb = NumbersUtil.parseLong(maxVolumeSizeInGbString, 2000);
|
||||
@ -1536,10 +1533,10 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
// If it does , then you cannot delete the pool
|
||||
if (vlms.first() > 0) {
|
||||
throw new CloudRuntimeException("Cannot delete pool " + sPool.getName() + " as there are associated vols" +
|
||||
" for this pool");
|
||||
" for this pool");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// First get the host_id from storage_pool_host_ref for given pool id
|
||||
StoragePoolVO lock = _storagePoolDao.acquireInLockTable(sPool.getId());
|
||||
@ -1733,7 +1730,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
return _volsDao.findById(volume.getId());
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Upload the volume to secondary storage.
|
||||
*
|
||||
@ -1742,19 +1739,19 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
@DB
|
||||
@ActionEvent(eventType = EventTypes.EVENT_VOLUME_UPLOAD, eventDescription = "uploading volume", async = true)
|
||||
public VolumeVO uploadVolume(UploadVolumeCmd cmd) throws ResourceAllocationException{
|
||||
Account caller = UserContext.current().getCaller();
|
||||
Account caller = UserContext.current().getCaller();
|
||||
long ownerId = cmd.getEntityOwnerId();
|
||||
Long zoneId = cmd.getZoneId();
|
||||
String volumeName = cmd.getVolumeName();
|
||||
String url = cmd.getUrl();
|
||||
String format = cmd.getFormat();
|
||||
|
||||
validateVolume(caller, ownerId, zoneId, volumeName, url, format);
|
||||
VolumeVO volume = persistVolume(caller, ownerId, zoneId, volumeName, url, cmd.getFormat());
|
||||
_downloadMonitor.downloadVolumeToStorage(volume, zoneId, url, cmd.getChecksum(), ImageFormat.valueOf(format.toUpperCase()));
|
||||
return volume;
|
||||
|
||||
validateVolume(caller, ownerId, zoneId, volumeName, url, format);
|
||||
VolumeVO volume = persistVolume(caller, ownerId, zoneId, volumeName, url, cmd.getFormat());
|
||||
_downloadMonitor.downloadVolumeToStorage(volume, zoneId, url, cmd.getChecksum(), ImageFormat.valueOf(format.toUpperCase()));
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
||||
private boolean validateVolume(Account caller, long ownerId, Long zoneId, String volumeName, String url, String format) throws ResourceAllocationException{
|
||||
|
||||
// permission check
|
||||
@ -1762,7 +1759,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
|
||||
// Check that the resource limit for volumes won't be exceeded
|
||||
_resourceLimitMgr.checkResourceLimit(_accountMgr.getAccount(ownerId), ResourceType.volume);
|
||||
|
||||
|
||||
|
||||
// Verify that zone exists
|
||||
DataCenterVO zone = _dcDao.findById(zoneId);
|
||||
@ -1774,75 +1771,75 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
if (Grouping.AllocationState.Disabled == zone.getAllocationState() && !_accountMgr.isRootAdmin(caller.getType())) {
|
||||
throw new PermissionDeniedException("Cannot perform this operation, Zone is currently disabled: " + zoneId);
|
||||
}
|
||||
|
||||
if (url.toLowerCase().contains("file://")) {
|
||||
throw new InvalidParameterValueException("File:// type urls are currently unsupported");
|
||||
}
|
||||
|
||||
ImageFormat imgfmt = ImageFormat.valueOf(format.toUpperCase());
|
||||
if (imgfmt == null) {
|
||||
throw new IllegalArgumentException("Image format is incorrect " + format + ". Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
|
||||
}
|
||||
|
||||
|
||||
if (url.toLowerCase().contains("file://")) {
|
||||
throw new InvalidParameterValueException("File:// type urls are currently unsupported");
|
||||
}
|
||||
|
||||
ImageFormat imgfmt = ImageFormat.valueOf(format.toUpperCase());
|
||||
if (imgfmt == null) {
|
||||
throw new IllegalArgumentException("Image format is incorrect " + format + ". Supported formats are " + EnumUtils.listValues(ImageFormat.values()));
|
||||
}
|
||||
|
||||
String userSpecifiedName = volumeName;
|
||||
if (userSpecifiedName == null) {
|
||||
userSpecifiedName = getRandomVolumeName();
|
||||
}
|
||||
if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip"))
|
||||
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz"))
|
||||
&&(!url.toLowerCase().endsWith("ova"))&&(!url.toLowerCase().endsWith("ova.zip"))
|
||||
&&(!url.toLowerCase().endsWith("ova.bz2"))&&(!url.toLowerCase().endsWith("ova.gz"))
|
||||
&&(!url.toLowerCase().endsWith("img"))&&(!url.toLowerCase().endsWith("raw"))){
|
||||
throw new InvalidParameterValueException("Please specify a valid " + format.toLowerCase());
|
||||
}
|
||||
|
||||
if ((format.equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith(".vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith("vhd.gz") ))
|
||||
|| (format.equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith(".qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url.toLowerCase().endsWith("qcow2.gz") ))
|
||||
|| (format.equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith(".ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase().endsWith("ova.gz")))
|
||||
|| (format.equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith(".img") && !url.toLowerCase().endsWith("raw")))) {
|
||||
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + format.toLowerCase());
|
||||
}
|
||||
validateUrl(url);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private String validateUrl(String url){
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("http")
|
||||
&& !uri.getScheme().equalsIgnoreCase("https") && !uri.getScheme().equalsIgnoreCase("file"))) {
|
||||
throw new IllegalArgumentException("Unsupported scheme for url: " + url);
|
||||
}
|
||||
if((!url.toLowerCase().endsWith("vhd"))&&(!url.toLowerCase().endsWith("vhd.zip"))
|
||||
&&(!url.toLowerCase().endsWith("vhd.bz2"))&&(!url.toLowerCase().endsWith("vhd.gz"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2"))&&(!url.toLowerCase().endsWith("qcow2.zip"))
|
||||
&&(!url.toLowerCase().endsWith("qcow2.bz2"))&&(!url.toLowerCase().endsWith("qcow2.gz"))
|
||||
&&(!url.toLowerCase().endsWith("ova"))&&(!url.toLowerCase().endsWith("ova.zip"))
|
||||
&&(!url.toLowerCase().endsWith("ova.bz2"))&&(!url.toLowerCase().endsWith("ova.gz"))
|
||||
&&(!url.toLowerCase().endsWith("img"))&&(!url.toLowerCase().endsWith("raw"))){
|
||||
throw new InvalidParameterValueException("Please specify a valid " + format.toLowerCase());
|
||||
}
|
||||
|
||||
int port = uri.getPort();
|
||||
if (!(port == 80 || port == 443 || port == -1)) {
|
||||
throw new IllegalArgumentException("Only ports 80 and 443 are allowed");
|
||||
}
|
||||
String host = uri.getHost();
|
||||
try {
|
||||
InetAddress hostAddr = InetAddress.getByName(host);
|
||||
if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) {
|
||||
throw new IllegalArgumentException("Illegal host specified in url");
|
||||
}
|
||||
if (hostAddr instanceof Inet6Address) {
|
||||
throw new IllegalArgumentException("IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")");
|
||||
}
|
||||
} catch (UnknownHostException uhe) {
|
||||
throw new IllegalArgumentException("Unable to resolve " + host);
|
||||
}
|
||||
|
||||
return uri.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid URL " + url);
|
||||
}
|
||||
|
||||
if ((format.equalsIgnoreCase("vhd") && (!url.toLowerCase().endsWith(".vhd") && !url.toLowerCase().endsWith("vhd.zip") && !url.toLowerCase().endsWith("vhd.bz2") && !url.toLowerCase().endsWith("vhd.gz") ))
|
||||
|| (format.equalsIgnoreCase("qcow2") && (!url.toLowerCase().endsWith(".qcow2") && !url.toLowerCase().endsWith("qcow2.zip") && !url.toLowerCase().endsWith("qcow2.bz2") && !url.toLowerCase().endsWith("qcow2.gz") ))
|
||||
|| (format.equalsIgnoreCase("ova") && (!url.toLowerCase().endsWith(".ova") && !url.toLowerCase().endsWith("ova.zip") && !url.toLowerCase().endsWith("ova.bz2") && !url.toLowerCase().endsWith("ova.gz")))
|
||||
|| (format.equalsIgnoreCase("raw") && (!url.toLowerCase().endsWith(".img") && !url.toLowerCase().endsWith("raw")))) {
|
||||
throw new InvalidParameterValueException("Please specify a valid URL. URL:" + url + " is an invalid for the format " + format.toLowerCase());
|
||||
}
|
||||
validateUrl(url);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private String validateUrl(String url){
|
||||
try {
|
||||
URI uri = new URI(url);
|
||||
if ((uri.getScheme() == null) || (!uri.getScheme().equalsIgnoreCase("http")
|
||||
&& !uri.getScheme().equalsIgnoreCase("https") && !uri.getScheme().equalsIgnoreCase("file"))) {
|
||||
throw new IllegalArgumentException("Unsupported scheme for url: " + url);
|
||||
}
|
||||
|
||||
int port = uri.getPort();
|
||||
if (!(port == 80 || port == 443 || port == -1)) {
|
||||
throw new IllegalArgumentException("Only ports 80 and 443 are allowed");
|
||||
}
|
||||
String host = uri.getHost();
|
||||
try {
|
||||
InetAddress hostAddr = InetAddress.getByName(host);
|
||||
if (hostAddr.isAnyLocalAddress() || hostAddr.isLinkLocalAddress() || hostAddr.isLoopbackAddress() || hostAddr.isMulticastAddress()) {
|
||||
throw new IllegalArgumentException("Illegal host specified in url");
|
||||
}
|
||||
if (hostAddr instanceof Inet6Address) {
|
||||
throw new IllegalArgumentException("IPV6 addresses not supported (" + hostAddr.getHostAddress() + ")");
|
||||
}
|
||||
} catch (UnknownHostException uhe) {
|
||||
throw new IllegalArgumentException("Unable to resolve " + host);
|
||||
}
|
||||
|
||||
return uri.toString();
|
||||
} catch (URISyntaxException e) {
|
||||
throw new IllegalArgumentException("Invalid URL " + url);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private VolumeVO persistVolume(Account caller, long ownerId, Long zoneId, String volumeName, String url, String format) {
|
||||
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
txn.start();
|
||||
|
||||
@ -1861,21 +1858,21 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
|
||||
volume = _volsDao.persist(volume);
|
||||
try {
|
||||
stateTransitTo(volume, Event.UploadRequested);
|
||||
} catch (NoTransitionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
stateTransitTo(volume, Event.UploadRequested);
|
||||
} catch (NoTransitionException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
UserContext.current().setEventDetails("Volume Id: " + volume.getId());
|
||||
|
||||
// Increment resource count during allocation; if actual creation fails, decrement it
|
||||
_resourceLimitMgr.incrementResourceCount(volume.getAccountId(), ResourceType.volume);
|
||||
|
||||
txn.commit();
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
||||
return volume;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Just allocate a volume in the database, don't send the createvolume cmd to hypervisor. The volume will be finally
|
||||
* created
|
||||
@ -2049,9 +2046,9 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
|
||||
volume = _volsDao.persist(volume);
|
||||
if(cmd.getSnapshotId() == null){
|
||||
//for volume created from snapshot, create usage event after volume creation
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOfferingId, null, size);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
//for volume created from snapshot, create usage event after volume creation
|
||||
UsageEventVO usageEvent = new UsageEventVO(EventTypes.EVENT_VOLUME_CREATE, volume.getAccountId(), volume.getDataCenterId(), volume.getId(), volume.getName(), diskOfferingId, null, size);
|
||||
_usageEventDao.persist(usageEvent);
|
||||
}
|
||||
|
||||
UserContext.current().setEventDetails("Volume Id: " + volume.getId());
|
||||
@ -2161,7 +2158,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
if (capacities.size() == 0) {
|
||||
CapacityVO capacity = new CapacityVO(storagePool.getId(), storagePool.getDataCenterId(), storagePool.getPodId(), storagePool.getClusterId(), allocated, totalOverProvCapacity, capacityType);
|
||||
CapacityState capacityState = _configMgr.findClusterAllocationState(ApiDBUtils.findClusterById(storagePool.getClusterId())) == AllocationState.Disabled ?
|
||||
CapacityState.Disabled : CapacityState.Enabled;
|
||||
CapacityState.Disabled : CapacityState.Enabled;
|
||||
capacity.setCapacityState(capacityState);
|
||||
_capacityDao.persist(capacity);
|
||||
} else {
|
||||
@ -2182,7 +2179,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
s_logger.debug("Successfully set Capacity - " + totalOverProvCapacity + " for capacity type - " + capacityType + " , DataCenterId - "
|
||||
+ storagePool.getDataCenterId() + ", HostOrPoolId - " + storagePool.getId() + ", PodId " + storagePool.getPodId());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Long> getUpHostsInPool(long poolId) {
|
||||
SearchCriteria<Long> sc = UpHostsInPoolSearch.create();
|
||||
@ -2283,7 +2280,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
s_logger.warn("Unable to destroy " + vol.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// remove snapshots in Error state
|
||||
List<SnapshotVO> snapshots = _snapshotDao.listAllByStatus(Snapshot.Status.Error);
|
||||
for (SnapshotVO snapshotVO : snapshots) {
|
||||
@ -2293,7 +2290,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
s_logger.warn("Unable to destroy " + snapshotVO.getId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
} finally {
|
||||
scanLock.unlock();
|
||||
}
|
||||
@ -2432,7 +2429,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
s_logger.warn("problem cleaning up snapshots in secondary storage " + secondaryStorageHost, e2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//CleanUp volumes on Secondary Storage.
|
||||
for (HostVO secondaryStorageHost : secondaryStorageHosts) {
|
||||
try {
|
||||
@ -2460,7 +2457,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
_volumeHostDao.remove(destroyedVolumeHostVO.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}catch (Exception e2) {
|
||||
s_logger.warn("problem cleaning up volumes in secondary storage " + secondaryStorageHost, e2);
|
||||
}
|
||||
@ -2894,12 +2891,12 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
|
||||
// Check that volume is completely Uploaded
|
||||
if (volume.getState() == Volume.State.UploadOp){
|
||||
VolumeHostVO volumeHost = _volumeHostDao.findByVolumeId(volume.getId());
|
||||
VolumeHostVO volumeHost = _volumeHostDao.findByVolumeId(volume.getId());
|
||||
if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS){
|
||||
throw new InvalidParameterValueException("Please specify a volume that is not uploading");
|
||||
throw new InvalidParameterValueException("Please specify a volume that is not uploading");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Check that the volume is not already destroyed
|
||||
if (volume.getState() != Volume.State.Destroy) {
|
||||
if (!destroyVolume(volume)) {
|
||||
@ -3109,7 +3106,6 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
volIds.add(volume.getId());
|
||||
}
|
||||
|
||||
checkPointTaskId = _checkPointMgr.pushCheckPoint(new StorageMigrationCleanupMaid(StorageMigrationCleanupMaid.StorageMigrationState.MIGRATING, volIds));
|
||||
transitResult = true;
|
||||
} finally {
|
||||
if (!transitResult) {
|
||||
@ -3166,7 +3162,6 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
s_logger.debug("Failed to change volume state: " + e.toString());
|
||||
}
|
||||
}
|
||||
_checkPointMgr.popCheckPoint(checkPointTaskId);
|
||||
} else {
|
||||
// Need a transaction, make sure all the volumes get migrated to new storage pool
|
||||
txn = Transaction.currentTxn();
|
||||
@ -3192,11 +3187,6 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
}
|
||||
}
|
||||
transitResult = true;
|
||||
try {
|
||||
_checkPointMgr.popCheckPoint(checkPointTaskId);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
} finally {
|
||||
if (!transitResult) {
|
||||
txn.rollback();
|
||||
@ -3259,7 +3249,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Checking if we need to prepare " + vols.size() + " volumes for " + vm);
|
||||
}
|
||||
|
||||
|
||||
boolean recreate = _recreateSystemVmEnabled;
|
||||
|
||||
List<VolumeVO> recreateVols = new ArrayList<VolumeVO>(vols.size());
|
||||
@ -3270,8 +3260,8 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
assignedPool = dest.getStorageForDisks().get(vol);
|
||||
}
|
||||
if (assignedPool == null && recreate) {
|
||||
assignedPool = _storagePoolDao.findById(vol.getPoolId());
|
||||
|
||||
assignedPool = _storagePoolDao.findById(vol.getPoolId());
|
||||
|
||||
}
|
||||
if (assignedPool != null || recreate) {
|
||||
Volume.State state = vol.getState();
|
||||
@ -3312,7 +3302,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
|
||||
vm.addDisk(new VolumeTO(vol, pool));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -3331,10 +3321,10 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
VolumeVO newVol;
|
||||
StoragePool existingPool = null;
|
||||
if (recreate && (dest.getStorageForDisks() == null || dest.getStorageForDisks().get(vol) == null)) {
|
||||
existingPool = _storagePoolDao.findById(vol.getPoolId());
|
||||
s_logger.debug("existing pool: " + existingPool.getId());
|
||||
existingPool = _storagePoolDao.findById(vol.getPoolId());
|
||||
s_logger.debug("existing pool: " + existingPool.getId());
|
||||
}
|
||||
|
||||
|
||||
if (vol.getState() == Volume.State.Allocated || vol.getState() == Volume.State.Creating) {
|
||||
newVol = vol;
|
||||
} else {
|
||||
@ -3429,12 +3419,12 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
if (toBeCreated.getTemplateId() != null) {
|
||||
template = _templateDao.findById(toBeCreated.getTemplateId());
|
||||
}
|
||||
|
||||
|
||||
StoragePool pool = null;
|
||||
if (sPool != null) {
|
||||
pool = sPool;
|
||||
pool = sPool;
|
||||
} else {
|
||||
pool = dest.getStorageForDisks().get(toBeCreated);
|
||||
pool = dest.getStorageForDisks().get(toBeCreated);
|
||||
}
|
||||
|
||||
if (pool != null) {
|
||||
@ -3465,12 +3455,12 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
String fullTmpltUrl = tmpltHostUrl + "/" + tmpltHostOn.getInstallPath();
|
||||
cmd = new CreateCommand(diskProfile, fullTmpltUrl, new StorageFilerTO(pool));
|
||||
} else {
|
||||
tmpltStoredOn = _tmpltMgr.prepareTemplateForCreate(template, pool);
|
||||
if (tmpltStoredOn == null) {
|
||||
s_logger.debug("Cannot use this pool " + pool + " because we can't propagate template " + template);
|
||||
return null;
|
||||
}
|
||||
cmd = new CreateCommand(diskProfile, tmpltStoredOn.getLocalDownloadPath(), new StorageFilerTO(pool));
|
||||
tmpltStoredOn = _tmpltMgr.prepareTemplateForCreate(template, pool);
|
||||
if (tmpltStoredOn == null) {
|
||||
s_logger.debug("Cannot use this pool " + pool + " because we can't propagate template " + template);
|
||||
return null;
|
||||
}
|
||||
cmd = new CreateCommand(diskProfile, tmpltStoredOn.getLocalDownloadPath(), new StorageFilerTO(pool));
|
||||
}
|
||||
} else {
|
||||
if (template != null && Storage.ImageFormat.ISO == template.getFormat()) {
|
||||
@ -3513,27 +3503,27 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Expunging " + vol);
|
||||
}
|
||||
|
||||
|
||||
//Find out if the volume is present on secondary storage
|
||||
VolumeHostVO volumeHost = _volumeHostDao.findByVolumeId(vol.getId());
|
||||
if(volumeHost != null){
|
||||
if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED){
|
||||
HostVO ssHost = _hostDao.findById(volumeHost.getHostId());
|
||||
DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(ssHost.getStorageUrl(), volumeHost.getInstallPath());
|
||||
Answer answer = _agentMgr.sendToSecStorage(ssHost, dtCommand);
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.debug("Failed to delete " + volumeHost + " due to " + ((answer == null) ? "answer is null" : answer.getDetails()));
|
||||
return;
|
||||
}
|
||||
}else if(volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS){
|
||||
s_logger.debug("Volume: " + vol.getName() + " is currently being uploaded; cant' delete it.");
|
||||
throw new CloudRuntimeException("Please specify a volume that is not currently being uploaded.");
|
||||
}
|
||||
if (volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOADED){
|
||||
HostVO ssHost = _hostDao.findById(volumeHost.getHostId());
|
||||
DeleteVolumeCommand dtCommand = new DeleteVolumeCommand(ssHost.getStorageUrl(), volumeHost.getInstallPath());
|
||||
Answer answer = _agentMgr.sendToSecStorage(ssHost, dtCommand);
|
||||
if (answer == null || !answer.getResult()) {
|
||||
s_logger.debug("Failed to delete " + volumeHost + " due to " + ((answer == null) ? "answer is null" : answer.getDetails()));
|
||||
return;
|
||||
}
|
||||
}else if(volumeHost.getDownloadState() == VMTemplateStorageResourceAssoc.Status.DOWNLOAD_IN_PROGRESS){
|
||||
s_logger.debug("Volume: " + vol.getName() + " is currently being uploaded; cant' delete it.");
|
||||
throw new CloudRuntimeException("Please specify a volume that is not currently being uploaded.");
|
||||
}
|
||||
_volumeHostDao.remove(volumeHost.getId());
|
||||
_volumeDao.remove(vol.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
String vmName = null;
|
||||
if (vol.getVolumeType() == Type.ROOT && vol.getInstanceId() != null) {
|
||||
VirtualMachine vm = _vmInstanceDao.findByIdIncludingRemoved(vol.getInstanceId());
|
||||
@ -3578,7 +3568,7 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
} catch (RuntimeException ex) {
|
||||
if (force) {
|
||||
s_logger.info("Failed to expunge volume, but marking volume id=" + vol.getId() + " as expunged anyway " +
|
||||
"due to force=true. Volume failed to expunge due to ", ex);
|
||||
"due to force=true. Volume failed to expunge due to ", ex);
|
||||
removeVolume = true;
|
||||
} else {
|
||||
throw ex;
|
||||
@ -3869,14 +3859,14 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public HypervisorType getHypervisorTypeFromFormat(ImageFormat format) {
|
||||
|
||||
if(format == null) {
|
||||
|
||||
if(format == null) {
|
||||
return HypervisorType.None;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (format == ImageFormat.VHD) {
|
||||
return HypervisorType.XenServer;
|
||||
} else if (format == ImageFormat.OVA) {
|
||||
@ -3965,5 +3955,5 @@ public class StorageManagerImpl implements StorageManager, Manager, ClusterManag
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,121 +0,0 @@
|
||||
// Licensed to the Apache Software Foundation (ASF) under one
|
||||
// or more contributor license agreements. See the NOTICE file
|
||||
// distributed with this work for additional information
|
||||
// regarding copyright ownership. The ASF licenses this file
|
||||
// to you under the Apache License, Version 2.0 (the
|
||||
// "License"); you may not use this file except in compliance
|
||||
// with the License. You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing,
|
||||
// software distributed under the License is distributed on an
|
||||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
// KIND, either express or implied. See the License for the
|
||||
// specific language governing permissions and limitations
|
||||
// under the License.
|
||||
package com.cloud.storage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.cluster.CheckPointManager;
|
||||
import com.cloud.cluster.CleanupMaid;
|
||||
import com.cloud.server.ManagementServer;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.fsm.NoTransitionException;
|
||||
import com.cloud.utils.fsm.StateMachine2;
|
||||
import com.cloud.vm.VMInstanceVO;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineManager;
|
||||
import com.cloud.vm.dao.VMInstanceDao;
|
||||
|
||||
public class StorageMigrationCleanupMaid implements CleanupMaid {
|
||||
private static final Logger s_logger = Logger.getLogger(StorageMigrationCleanupMaid.class);
|
||||
public static enum StorageMigrationState {
|
||||
MIGRATING,
|
||||
MIGRATINGFAILED,
|
||||
MIGRATINGSUCCESS;
|
||||
}
|
||||
|
||||
private List<Long> _volumesIds = new ArrayList<Long>();
|
||||
private StorageMigrationState _migrateState;
|
||||
|
||||
public StorageMigrationCleanupMaid() {
|
||||
|
||||
}
|
||||
|
||||
public StorageMigrationCleanupMaid(StorageMigrationState state, List<Long> volumes) {
|
||||
_migrateState = state;
|
||||
_volumesIds = volumes;
|
||||
}
|
||||
|
||||
public void updateStaste(StorageMigrationState state) {
|
||||
_migrateState = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cleanup(CheckPointManager checkPointMgr) {
|
||||
StateMachine2<Volume.State, Volume.Event, Volume> _stateMachine = Volume.State.getStateMachine();
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
VolumeDao volDao = locator.getDao(VolumeDao.class);
|
||||
VMInstanceDao vmDao = locator.getDao(VMInstanceDao.class);
|
||||
VirtualMachineManager vmMgr = locator.getManager(VirtualMachineManager.class);
|
||||
Long vmInstanceId = null;
|
||||
boolean success = true;
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
try {
|
||||
txn.start();
|
||||
for (Long volumeId : _volumesIds) {
|
||||
VolumeVO volume = volDao.findById(volumeId);
|
||||
if (volume == null) {
|
||||
continue;
|
||||
}
|
||||
vmInstanceId = volume.getInstanceId();
|
||||
if (_migrateState == StorageMigrationState.MIGRATING && volume.getState() == Volume.State.Migrating) {
|
||||
try {
|
||||
_stateMachine.transitTo(volume, Volume.Event.OperationFailed, null, volDao);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Failed to transit volume state: " + e.toString());
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vmInstanceId != null) {
|
||||
VMInstanceVO vm = vmDao.findById(vmInstanceId);
|
||||
if (vm != null && vm.getState() == VirtualMachine.State.Migrating) {
|
||||
try {
|
||||
vmMgr.stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.debug("Failed to transit vm state");
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (success) {
|
||||
txn.commit();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
s_logger.debug("storage migration cleanup failed:" + e.toString());
|
||||
txn.rollback();
|
||||
}finally {
|
||||
txn.close();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCleanupProcedure() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@ -31,7 +31,7 @@ import com.cloud.deploy.DeploymentPlan;
|
||||
import com.cloud.deploy.DeploymentPlanner.ExcludeList;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.StoragePool;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.vm.DiskProfile;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
import com.cloud.vm.VirtualMachineProfile;
|
||||
@ -40,68 +40,66 @@ import com.cloud.vm.VirtualMachineProfile;
|
||||
@Local(value=StoragePoolAllocator.class)
|
||||
public class GarbageCollectingStoragePoolAllocator extends AbstractStoragePoolAllocator {
|
||||
private static final Logger s_logger = Logger.getLogger(GarbageCollectingStoragePoolAllocator.class);
|
||||
|
||||
|
||||
StoragePoolAllocator _firstFitStoragePoolAllocator;
|
||||
StoragePoolAllocator _localStoragePoolAllocator;
|
||||
@Inject StorageManager _storageMgr;
|
||||
@Inject ConfigurationDao _configDao;
|
||||
boolean _storagePoolCleanupEnabled;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean allocatorIsCorrectType(DiskProfile dskCh) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public Integer getStorageOverprovisioningFactor() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public Long getExtraBytesPerVolume() {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<StoragePool> allocateToPool(DiskProfile dskCh, VirtualMachineProfile<? extends VirtualMachine> vmProfile, DeploymentPlan plan, ExcludeList avoid, int returnUpTo) {
|
||||
|
||||
if (!_storagePoolCleanupEnabled) {
|
||||
s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Clean up all storage pools
|
||||
_storageMgr.cleanupStorage(false);
|
||||
// Determine what allocator to use
|
||||
StoragePoolAllocator allocator;
|
||||
if (localStorageAllocationNeeded(dskCh)) {
|
||||
allocator = _localStoragePoolAllocator;
|
||||
} else {
|
||||
allocator = _firstFitStoragePoolAllocator;
|
||||
}
|
||||
|
||||
// Try to find a storage pool after cleanup
|
||||
if (!_storagePoolCleanupEnabled) {
|
||||
s_logger.debug("Storage pool cleanup is not enabled, so GarbageCollectingStoragePoolAllocator is being skipped.");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Clean up all storage pools
|
||||
_storageMgr.cleanupStorage(false);
|
||||
// Determine what allocator to use
|
||||
StoragePoolAllocator allocator;
|
||||
if (localStorageAllocationNeeded(dskCh)) {
|
||||
allocator = _localStoragePoolAllocator;
|
||||
} else {
|
||||
allocator = _firstFitStoragePoolAllocator;
|
||||
}
|
||||
|
||||
// Try to find a storage pool after cleanup
|
||||
ExcludeList myAvoids = new ExcludeList(avoid.getDataCentersToAvoid(), avoid.getPodsToAvoid(), avoid.getClustersToAvoid(), avoid.getHostsToAvoid(), avoid.getPoolsToAvoid());
|
||||
|
||||
|
||||
return allocator.allocateToPool(dskCh, vmProfile, plan, myAvoids, returnUpTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
|
||||
_firstFitStoragePoolAllocator = ComponentLocator.inject(FirstFitStoragePoolAllocator.class);
|
||||
|
||||
_firstFitStoragePoolAllocator = ComponentContext.inject(FirstFitStoragePoolAllocator.class);
|
||||
_firstFitStoragePoolAllocator.configure("GCFirstFitStoragePoolAllocator", params);
|
||||
_localStoragePoolAllocator = ComponentLocator.inject(LocalStoragePoolAllocator.class);
|
||||
_localStoragePoolAllocator = ComponentContext.inject(LocalStoragePoolAllocator.class);
|
||||
_localStoragePoolAllocator.configure("GCLocalStoragePoolAllocator", params);
|
||||
|
||||
|
||||
String storagePoolCleanupEnabled = _configDao.getValue("storage.pool.cleanup.enabled");
|
||||
_storagePoolCleanupEnabled = (storagePoolCleanupEnabled == null) ? true : Boolean.parseBoolean(storagePoolCleanupEnabled);
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public GarbageCollectingStoragePoolAllocator() {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -18,6 +18,8 @@ package com.cloud.storage.listener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.Listener;
|
||||
@ -31,96 +33,93 @@ import com.cloud.exception.ConnectionException;
|
||||
import com.cloud.host.HostVO;
|
||||
import com.cloud.host.Status;
|
||||
import com.cloud.hypervisor.Hypervisor.HypervisorType;
|
||||
import com.cloud.server.ManagementService;
|
||||
import com.cloud.storage.OCFS2Manager;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.StorageManagerImpl;
|
||||
import com.cloud.storage.StoragePoolStatus;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.storage.Storage.StoragePoolType;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
|
||||
|
||||
public class StoragePoolMonitor implements Listener {
|
||||
private static final Logger s_logger = Logger.getLogger(StoragePoolMonitor.class);
|
||||
private final StorageManagerImpl _storageManager;
|
||||
private final StoragePoolDao _poolDao;
|
||||
OCFS2Manager _ocfs2Mgr;
|
||||
|
||||
private final StorageManagerImpl _storageManager;
|
||||
private final StoragePoolDao _poolDao;
|
||||
@Inject OCFS2Manager _ocfs2Mgr;
|
||||
|
||||
public StoragePoolMonitor(StorageManagerImpl mgr, StoragePoolDao poolDao) {
|
||||
this._storageManager = mgr;
|
||||
this._poolDao = poolDao;
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementService.Name);
|
||||
this._ocfs2Mgr = locator.getManager(OCFS2Manager.class);
|
||||
this._storageManager = mgr;
|
||||
this._poolDao = poolDao;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isRecurring() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean processAnswers(long agentId, long seq, Answer[] resp) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public synchronized boolean processDisconnect(long agentId, Status state) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void processConnect(HostVO host, StartupCommand cmd, boolean forRebalance) throws ConnectionException {
|
||||
if (cmd instanceof StartupRoutingCommand) {
|
||||
StartupRoutingCommand scCmd = (StartupRoutingCommand)cmd;
|
||||
if (scCmd.getHypervisorType() == HypervisorType.XenServer || scCmd.getHypervisorType() == HypervisorType.KVM ||
|
||||
scCmd.getHypervisorType() == HypervisorType.VMware || scCmd.getHypervisorType() == HypervisorType.Simulator || scCmd.getHypervisorType() == HypervisorType.Ovm) {
|
||||
List<StoragePoolVO> pools = _poolDao.listBy(host.getDataCenterId(), host.getPodId(), host.getClusterId());
|
||||
for (StoragePoolVO pool : pools) {
|
||||
if (pool.getStatus() != StoragePoolStatus.Up) {
|
||||
continue;
|
||||
}
|
||||
if (!pool.getPoolType().isShared()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pool.getPoolType() == StoragePoolType.OCFS2 && !_ocfs2Mgr.prepareNodes(pool.getClusterId())) {
|
||||
throw new ConnectionException(true, "Unable to prepare OCFS2 nodes for pool " + pool.getId());
|
||||
}
|
||||
|
||||
Long hostId = host.getId();
|
||||
s_logger.debug("Host " + hostId + " connected, sending down storage pool information ...");
|
||||
try {
|
||||
_storageManager.connectHostToSharedPool(hostId, pool);
|
||||
_storageManager.createCapacityEntry(pool);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to connect host " + hostId + " to pool " + pool + " due to " + e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cmd instanceof StartupRoutingCommand) {
|
||||
StartupRoutingCommand scCmd = (StartupRoutingCommand)cmd;
|
||||
if (scCmd.getHypervisorType() == HypervisorType.XenServer || scCmd.getHypervisorType() == HypervisorType.KVM ||
|
||||
scCmd.getHypervisorType() == HypervisorType.VMware || scCmd.getHypervisorType() == HypervisorType.Simulator || scCmd.getHypervisorType() == HypervisorType.Ovm) {
|
||||
List<StoragePoolVO> pools = _poolDao.listBy(host.getDataCenterId(), host.getPodId(), host.getClusterId());
|
||||
for (StoragePoolVO pool : pools) {
|
||||
if (pool.getStatus() != StoragePoolStatus.Up) {
|
||||
continue;
|
||||
}
|
||||
if (!pool.getPoolType().isShared()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pool.getPoolType() == StoragePoolType.OCFS2 && !_ocfs2Mgr.prepareNodes(pool.getClusterId())) {
|
||||
throw new ConnectionException(true, "Unable to prepare OCFS2 nodes for pool " + pool.getId());
|
||||
}
|
||||
|
||||
Long hostId = host.getId();
|
||||
s_logger.debug("Host " + hostId + " connected, sending down storage pool information ...");
|
||||
try {
|
||||
_storageManager.connectHostToSharedPool(hostId, pool);
|
||||
_storageManager.createCapacityEntry(pool);
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Unable to connect host " + hostId + " to pool " + pool + " due to " + e.toString(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processCommands(long agentId, long seq, Command[] req) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AgentControlAnswer processControlCommand(long agentId, AgentControlCommand cmd) {
|
||||
return null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean processTimeout(long agentId, long seq) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getTimeout() {
|
||||
return -1;
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -21,6 +21,7 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.naming.ConfigurationException;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
@ -54,38 +55,38 @@ import com.cloud.storage.template.TemplateInfo;
|
||||
|
||||
public class DummySecondaryStorageResource extends ServerResourceBase implements ServerResource {
|
||||
private static final Logger s_logger = Logger.getLogger(DummySecondaryStorageResource.class);
|
||||
|
||||
|
||||
String _dc;
|
||||
String _pod;
|
||||
String _guid;
|
||||
String _dummyPath;
|
||||
VMTemplateDao _tmpltDao;
|
||||
private boolean _useServiceVm;
|
||||
|
||||
|
||||
public DummySecondaryStorageResource(boolean useServiceVM) {
|
||||
setUseServiceVm(useServiceVM);
|
||||
}
|
||||
@Inject VMTemplateDao _tmpltDao;
|
||||
private boolean _useServiceVm;
|
||||
|
||||
@Override
|
||||
protected String getDefaultScriptsDir() {
|
||||
return "dummy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
public DummySecondaryStorageResource(boolean useServiceVM) {
|
||||
setUseServiceVm(useServiceVM);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultScriptsDir() {
|
||||
return "dummy";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Answer executeRequest(Command cmd) {
|
||||
if (cmd instanceof DownloadProgressCommand) {
|
||||
return new DownloadAnswer(null, 100, cmd,
|
||||
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
|
||||
"dummyFS",
|
||||
"/dummy");
|
||||
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
|
||||
"dummyFS",
|
||||
"/dummy");
|
||||
} else if (cmd instanceof DownloadCommand) {
|
||||
return new DownloadAnswer(null, 100, cmd,
|
||||
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
|
||||
"dummyFS",
|
||||
"/dummy");
|
||||
com.cloud.storage.VMTemplateStorageResourceAssoc.Status.DOWNLOADED,
|
||||
"dummyFS",
|
||||
"/dummy");
|
||||
} else if (cmd instanceof GetStorageStatsCommand) {
|
||||
return execute((GetStorageStatsCommand)cmd);
|
||||
return execute((GetStorageStatsCommand)cmd);
|
||||
} else if (cmd instanceof CheckHealthCommand) {
|
||||
return new CheckHealthAnswer((CheckHealthCommand)cmd, true);
|
||||
} else if (cmd instanceof ReadyCommand) {
|
||||
@ -93,33 +94,33 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements
|
||||
} else {
|
||||
return Answer.createUnsupportedCommandAnswer(cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
@Override
|
||||
public PingCommand getCurrentStatus(long id) {
|
||||
return new PingStorageCommand(Host.Type.Storage, id, new HashMap<String, Boolean>());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getType() {
|
||||
@Override
|
||||
public Type getType() {
|
||||
return Host.Type.SecondaryStorage;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
@Override
|
||||
public StartupCommand[] initialize() {
|
||||
final StartupStorageCommand cmd = new StartupStorageCommand("dummy",
|
||||
StoragePoolType.NetworkFilesystem, 1024*1024*1024*100L,
|
||||
new HashMap<String, TemplateInfo>());
|
||||
|
||||
StoragePoolType.NetworkFilesystem, 1024*1024*1024*100L,
|
||||
new HashMap<String, TemplateInfo>());
|
||||
|
||||
cmd.setResourceType(Storage.StorageResourceType.SECONDARY_STORAGE);
|
||||
cmd.setIqn(null);
|
||||
cmd.setNfsShare(_guid);
|
||||
|
||||
|
||||
fillNetworkInformation(cmd);
|
||||
cmd.setDataCenter(_dc);
|
||||
cmd.setPod(_pod);
|
||||
cmd.setGuid(_guid);
|
||||
|
||||
|
||||
cmd.setName(_guid);
|
||||
cmd.setVersion(DummySecondaryStorageResource.class.getPackage().getImplementationVersion());
|
||||
/* gather TemplateInfo in second storage */
|
||||
@ -127,62 +128,57 @@ public class DummySecondaryStorageResource extends ServerResourceBase implements
|
||||
cmd.getHostDetails().put("mount.parent", "dummy");
|
||||
cmd.getHostDetails().put("mount.path", "dummy");
|
||||
cmd.getHostDetails().put("orig.url", _guid);
|
||||
|
||||
|
||||
String tok[] = _dummyPath.split(":");
|
||||
cmd.setPrivateIpAddress(tok[0]);
|
||||
return new StartupCommand [] {cmd};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected GetStorageStatsAnswer execute(GetStorageStatsCommand cmd) {
|
||||
long size = 1024*1024*1024*100L;
|
||||
return new GetStorageStatsAnswer(cmd, 0, size);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
|
||||
|
||||
_guid = (String)params.get("guid");
|
||||
if (_guid == null) {
|
||||
throw new ConfigurationException("Unable to find the guid");
|
||||
}
|
||||
|
||||
|
||||
_dc = (String)params.get("zone");
|
||||
if (_dc == null) {
|
||||
throw new ConfigurationException("Unable to find the zone");
|
||||
}
|
||||
_pod = (String)params.get("pod");
|
||||
|
||||
|
||||
_dummyPath = (String)params.get("mount.path");
|
||||
if (_dummyPath == null) {
|
||||
throw new ConfigurationException("Unable to find mount.path");
|
||||
}
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getLocator("management-server");
|
||||
_tmpltDao = locator.getDao(VMTemplateDao.class);
|
||||
if (_tmpltDao == null) {
|
||||
throw new ConfigurationException("Unable to find VMTemplate dao");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setUseServiceVm(boolean _useServiceVm) {
|
||||
this._useServiceVm = _useServiceVm;
|
||||
}
|
||||
public void setUseServiceVm(boolean _useServiceVm) {
|
||||
this._useServiceVm = _useServiceVm;
|
||||
}
|
||||
|
||||
public boolean useServiceVm() {
|
||||
return _useServiceVm;
|
||||
}
|
||||
|
||||
public Map<String, TemplateInfo> getDefaultSystemVmTemplateInfo() {
|
||||
List<VMTemplateVO> tmplts = _tmpltDao.listAllSystemVMTemplates();
|
||||
Map<String, TemplateInfo> tmpltInfo = new HashMap<String, TemplateInfo>();
|
||||
if (tmplts != null) {
|
||||
for (VMTemplateVO tmplt : tmplts) {
|
||||
TemplateInfo routingInfo = new TemplateInfo(tmplt.getUniqueName(), TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, false, false);
|
||||
tmpltInfo.put(tmplt.getUniqueName(), routingInfo);
|
||||
}
|
||||
}
|
||||
return tmpltInfo;
|
||||
}
|
||||
public boolean useServiceVm() {
|
||||
return _useServiceVm;
|
||||
}
|
||||
|
||||
public Map<String, TemplateInfo> getDefaultSystemVmTemplateInfo() {
|
||||
List<VMTemplateVO> tmplts = _tmpltDao.listAllSystemVMTemplates();
|
||||
Map<String, TemplateInfo> tmpltInfo = new HashMap<String, TemplateInfo>();
|
||||
if (tmplts != null) {
|
||||
for (VMTemplateVO tmplt : tmplts) {
|
||||
TemplateInfo routingInfo = new TemplateInfo(tmplt.getUniqueName(), TemplateConstants.DEFAULT_SYSTEM_VM_TEMPLATE_PATH + tmplt.getId() + File.separator, false, false);
|
||||
tmpltInfo.put(tmplt.getUniqueName(), routingInfo);
|
||||
}
|
||||
}
|
||||
return tmpltInfo;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -25,194 +25,194 @@ import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.cloud.network.Networks.TrafficType;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.db.DB;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.net.NetUtils;
|
||||
|
||||
public class PodZoneConfig {
|
||||
|
||||
public static void main(String[] args) {
|
||||
PodZoneConfig config = ComponentLocator.inject(PodZoneConfig.class);
|
||||
//config.run(args);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void savePod(boolean printOutput, long id, String name, long dcId, String gateway, String cidr, int vlanStart, int vlanEnd) {
|
||||
// Check that the cidr was valid
|
||||
if (!IPRangeConfig.validCIDR(cidr)) printError("Please enter a valid CIDR for pod: " + name);
|
||||
|
||||
// Get the individual cidrAddress and cidrSize values
|
||||
String[] cidrPair = cidr.split("\\/");
|
||||
String cidrAddress = cidrPair[0];
|
||||
String cidrSize = cidrPair[1];
|
||||
|
||||
String sql = null;
|
||||
if (id != -1) sql = "INSERT INTO `cloud`.`host_pod_ref` (id, name, data_center_id, gateway, cidr_address, cidr_size) " + "VALUES ('" + id + "','" + name + "','" + dcId + "','" + gateway + "','" + cidrAddress + "','" + cidrSize + "')";
|
||||
else sql = "INSERT INTO `cloud`.`host_pod_ref` (name, data_center_id, gateway, cidr_address, cidr_size) " + "VALUES ('" + name + "','" + dcId + "','" + gateway + "','" + cidrAddress + "','" + cidrSize + "')";
|
||||
|
||||
public static void main(String[] args) {
|
||||
PodZoneConfig config = ComponentContext.inject(PodZoneConfig.class);
|
||||
//config.run(args);
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void savePod(boolean printOutput, long id, String name, long dcId, String gateway, String cidr, int vlanStart, int vlanEnd) {
|
||||
// Check that the cidr was valid
|
||||
if (!IPRangeConfig.validCIDR(cidr)) printError("Please enter a valid CIDR for pod: " + name);
|
||||
|
||||
// Get the individual cidrAddress and cidrSize values
|
||||
String[] cidrPair = cidr.split("\\/");
|
||||
String cidrAddress = cidrPair[0];
|
||||
String cidrSize = cidrPair[1];
|
||||
|
||||
String sql = null;
|
||||
if (id != -1) sql = "INSERT INTO `cloud`.`host_pod_ref` (id, name, data_center_id, gateway, cidr_address, cidr_size) " + "VALUES ('" + id + "','" + name + "','" + dcId + "','" + gateway + "','" + cidrAddress + "','" + cidrSize + "')";
|
||||
else sql = "INSERT INTO `cloud`.`host_pod_ref` (name, data_center_id, gateway, cidr_address, cidr_size) " + "VALUES ('" + name + "','" + dcId + "','" + gateway + "','" + cidrAddress + "','" + cidrSize + "')";
|
||||
|
||||
DatabaseConfig.saveSQL(sql, "Failed to save pod due to exception. Please contact Cloud Support.");
|
||||
|
||||
|
||||
if (printOutput) System.out.println("Successfuly saved pod.");
|
||||
}
|
||||
|
||||
public void checkAllPodCidrSubnets() {
|
||||
Vector<Long> allZoneIDs = getAllZoneIDs();
|
||||
for (Long dcId : allZoneIDs) {
|
||||
HashMap<Long, Vector<Object>> currentPodCidrSubnets = getCurrentPodCidrSubnets(dcId.longValue());
|
||||
String result = checkPodCidrSubnets(dcId.longValue(), currentPodCidrSubnets);
|
||||
if (!result.equals("success")) printError(result);
|
||||
}
|
||||
}
|
||||
|
||||
private String checkPodCidrSubnets(long dcId, HashMap<Long, Vector<Object>> currentPodCidrSubnets) {
|
||||
|
||||
}
|
||||
|
||||
public void checkAllPodCidrSubnets() {
|
||||
Vector<Long> allZoneIDs = getAllZoneIDs();
|
||||
for (Long dcId : allZoneIDs) {
|
||||
HashMap<Long, Vector<Object>> currentPodCidrSubnets = getCurrentPodCidrSubnets(dcId.longValue());
|
||||
String result = checkPodCidrSubnets(dcId.longValue(), currentPodCidrSubnets);
|
||||
if (!result.equals("success")) printError(result);
|
||||
}
|
||||
}
|
||||
|
||||
private String checkPodCidrSubnets(long dcId, HashMap<Long, Vector<Object>> currentPodCidrSubnets) {
|
||||
|
||||
// DataCenterDao _dcDao = null;
|
||||
// final ComponentLocator locator = ComponentLocator.getLocator("management-server");
|
||||
|
||||
|
||||
// _dcDao = locator.getDao(DataCenterDao.class);
|
||||
// For each pod, return an error if any of the following is true:
|
||||
// 1. The pod's CIDR subnet conflicts with the guest network subnet
|
||||
// 2. The pod's CIDR subnet conflicts with the CIDR subnet of any other pod
|
||||
|
||||
String zoneName = PodZoneConfig.getZoneName(dcId);
|
||||
|
||||
//get the guest network cidr and guest netmask from the zone
|
||||
// For each pod, return an error if any of the following is true:
|
||||
// 1. The pod's CIDR subnet conflicts with the guest network subnet
|
||||
// 2. The pod's CIDR subnet conflicts with the CIDR subnet of any other pod
|
||||
|
||||
String zoneName = PodZoneConfig.getZoneName(dcId);
|
||||
|
||||
//get the guest network cidr and guest netmask from the zone
|
||||
// DataCenterVO dcVo = _dcDao.findById(dcId);
|
||||
|
||||
String guestNetworkCidr = IPRangeConfig.getGuestNetworkCidr(dcId);
|
||||
|
||||
if (guestNetworkCidr == null || guestNetworkCidr.isEmpty()) return "Please specify a valid guest cidr";
|
||||
|
||||
String guestNetworkCidr = IPRangeConfig.getGuestNetworkCidr(dcId);
|
||||
|
||||
if (guestNetworkCidr == null || guestNetworkCidr.isEmpty()) return "Please specify a valid guest cidr";
|
||||
String[] cidrTuple = guestNetworkCidr.split("\\/");
|
||||
|
||||
String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]));
|
||||
long guestCidrSize = Long.parseLong(cidrTuple[1]);
|
||||
|
||||
|
||||
String guestIpNetwork = NetUtils.getIpRangeStartIpFromCidr(cidrTuple[0], Long.parseLong(cidrTuple[1]));
|
||||
long guestCidrSize = Long.parseLong(cidrTuple[1]);
|
||||
|
||||
// Iterate through all pods in this zone
|
||||
for (Long podId : currentPodCidrSubnets.keySet()) {
|
||||
String podName;
|
||||
if (podId.longValue() == -1) podName = "newPod";
|
||||
else podName = PodZoneConfig.getPodName(podId.longValue(), dcId);
|
||||
|
||||
Vector<Object> cidrPair = currentPodCidrSubnets.get(podId);
|
||||
String cidrAddress = (String) cidrPair.get(0);
|
||||
long cidrSize = ((Long) cidrPair.get(1)).longValue();
|
||||
|
||||
long cidrSizeToUse = -1;
|
||||
if (cidrSize < guestCidrSize) cidrSizeToUse = cidrSize;
|
||||
else cidrSizeToUse = guestCidrSize;
|
||||
|
||||
String cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse);
|
||||
String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse);
|
||||
|
||||
// Check that cidrSubnet does not equal guestSubnet
|
||||
if (cidrSubnet.equals(guestSubnet)) {
|
||||
if (podName.equals("newPod")) {
|
||||
return "The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR.";
|
||||
} else {
|
||||
return "Warning: The subnet of pod " + podName + " in zone " + zoneName + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management.";
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through the rest of the pods
|
||||
for (Long otherPodId : currentPodCidrSubnets.keySet()) {
|
||||
if (podId.equals(otherPodId)) continue;
|
||||
|
||||
// Check that cidrSubnet does not equal otherCidrSubnet
|
||||
Vector<Object> otherCidrPair = currentPodCidrSubnets.get(otherPodId);
|
||||
String otherCidrAddress = (String) otherCidrPair.get(0);
|
||||
long otherCidrSize = ((Long) otherCidrPair.get(1)).longValue();
|
||||
|
||||
if (cidrSize < otherCidrSize) cidrSizeToUse = cidrSize;
|
||||
else cidrSizeToUse = otherCidrSize;
|
||||
|
||||
cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse);
|
||||
String otherCidrSubnet = NetUtils.getCidrSubNet(otherCidrAddress, cidrSizeToUse);
|
||||
|
||||
if (cidrSubnet.equals(otherCidrSubnet)) {
|
||||
String otherPodName = PodZoneConfig.getPodName(otherPodId.longValue(), dcId);
|
||||
if (podName.equals("newPod")) {
|
||||
return "The subnet of the pod you are adding conflicts with the subnet of pod " + otherPodName + " in zone " + zoneName + ". Please specify a different CIDR.";
|
||||
} else {
|
||||
return "Warning: The pods " + podName + " and " + otherPodName + " in zone " + zoneName + " have conflicting CIDR subnets. Please change the CIDR of one of these pods.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
@DB
|
||||
protected HashMap<Long, Vector<Object>> getCurrentPodCidrSubnets(long dcId) {
|
||||
HashMap<Long, Vector<Object>> currentPodCidrSubnets = new HashMap<Long, Vector<Object>>();
|
||||
|
||||
String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + dcId;
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Long podId = rs.getLong("id");
|
||||
String cidrAddress = rs.getString("cidr_address");
|
||||
long cidrSize = rs.getLong("cidr_size");
|
||||
Vector<Object> cidrPair = new Vector<Object>();
|
||||
cidrPair.add(0, cidrAddress);
|
||||
cidrPair.add(1, new Long(cidrSize));
|
||||
currentPodCidrSubnets.put(podId, cidrPair);
|
||||
}
|
||||
for (Long podId : currentPodCidrSubnets.keySet()) {
|
||||
String podName;
|
||||
if (podId.longValue() == -1) podName = "newPod";
|
||||
else podName = PodZoneConfig.getPodName(podId.longValue(), dcId);
|
||||
|
||||
Vector<Object> cidrPair = currentPodCidrSubnets.get(podId);
|
||||
String cidrAddress = (String) cidrPair.get(0);
|
||||
long cidrSize = ((Long) cidrPair.get(1)).longValue();
|
||||
|
||||
long cidrSizeToUse = -1;
|
||||
if (cidrSize < guestCidrSize) cidrSizeToUse = cidrSize;
|
||||
else cidrSizeToUse = guestCidrSize;
|
||||
|
||||
String cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse);
|
||||
String guestSubnet = NetUtils.getCidrSubNet(guestIpNetwork, cidrSizeToUse);
|
||||
|
||||
// Check that cidrSubnet does not equal guestSubnet
|
||||
if (cidrSubnet.equals(guestSubnet)) {
|
||||
if (podName.equals("newPod")) {
|
||||
return "The subnet of the pod you are adding conflicts with the subnet of the Guest IP Network. Please specify a different CIDR.";
|
||||
} else {
|
||||
return "Warning: The subnet of pod " + podName + " in zone " + zoneName + " conflicts with the subnet of the Guest IP Network. Please change either the pod's CIDR or the Guest IP Network's subnet, and re-run install-vmops-management.";
|
||||
}
|
||||
}
|
||||
|
||||
// Iterate through the rest of the pods
|
||||
for (Long otherPodId : currentPodCidrSubnets.keySet()) {
|
||||
if (podId.equals(otherPodId)) continue;
|
||||
|
||||
// Check that cidrSubnet does not equal otherCidrSubnet
|
||||
Vector<Object> otherCidrPair = currentPodCidrSubnets.get(otherPodId);
|
||||
String otherCidrAddress = (String) otherCidrPair.get(0);
|
||||
long otherCidrSize = ((Long) otherCidrPair.get(1)).longValue();
|
||||
|
||||
if (cidrSize < otherCidrSize) cidrSizeToUse = cidrSize;
|
||||
else cidrSizeToUse = otherCidrSize;
|
||||
|
||||
cidrSubnet = NetUtils.getCidrSubNet(cidrAddress, cidrSizeToUse);
|
||||
String otherCidrSubnet = NetUtils.getCidrSubNet(otherCidrAddress, cidrSizeToUse);
|
||||
|
||||
if (cidrSubnet.equals(otherCidrSubnet)) {
|
||||
String otherPodName = PodZoneConfig.getPodName(otherPodId.longValue(), dcId);
|
||||
if (podName.equals("newPod")) {
|
||||
return "The subnet of the pod you are adding conflicts with the subnet of pod " + otherPodName + " in zone " + zoneName + ". Please specify a different CIDR.";
|
||||
} else {
|
||||
return "Warning: The pods " + podName + " and " + otherPodName + " in zone " + zoneName + " have conflicting CIDR subnets. Please change the CIDR of one of these pods.";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
@DB
|
||||
protected HashMap<Long, Vector<Object>> getCurrentPodCidrSubnets(long dcId) {
|
||||
HashMap<Long, Vector<Object>> currentPodCidrSubnets = new HashMap<Long, Vector<Object>>();
|
||||
|
||||
String selectSql = "SELECT id, cidr_address, cidr_size FROM host_pod_ref WHERE data_center_id=" + dcId;
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Long podId = rs.getLong("id");
|
||||
String cidrAddress = rs.getString("cidr_address");
|
||||
long cidrSize = rs.getLong("cidr_size");
|
||||
Vector<Object> cidrPair = new Vector<Object>();
|
||||
cidrPair.add(0, cidrAddress);
|
||||
cidrPair.add(1, new Long(cidrSize));
|
||||
currentPodCidrSubnets.put(podId, cidrPair);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println(ex.getMessage());
|
||||
printError("There was an issue with reading currently saved pod CIDR subnets. Please contact Cloud Support.");
|
||||
System.out.println(ex.getMessage());
|
||||
printError("There was an issue with reading currently saved pod CIDR subnets. Please contact Cloud Support.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return currentPodCidrSubnets;
|
||||
}
|
||||
|
||||
public void deletePod(String name, long dcId) {
|
||||
String sql = "DELETE FROM `cloud`.`host_pod_ref` WHERE name=\"" + name + "\" AND data_center_id=\"" + dcId + "\"";
|
||||
DatabaseConfig.saveSQL(sql, "Failed to delete pod due to exception. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public long getVlanDbId(String zone, String vlanId) {
|
||||
long zoneId = getZoneId(zone);
|
||||
|
||||
return DatabaseConfig.getDatabaseValueLong("SELECT * FROM `cloud`.`vlan` WHERE data_center_id=\"" + zoneId + "\" AND vlan_id =\"" + vlanId + "\"", "id",
|
||||
"Unable to start DB connection to read vlan DB id. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public List<String> modifyVlan(String zone, boolean add, String vlanId, String vlanGateway, String vlanNetmask, String pod, String vlanType, String ipRange, long networkId, long physicalNetworkId) {
|
||||
// Check if the zone is valid
|
||||
long zoneId = getZoneId(zone);
|
||||
if (zoneId == -1)
|
||||
return genReturnList("false", "Please specify a valid zone.");
|
||||
|
||||
//check if physical network is valid
|
||||
|
||||
public void deletePod(String name, long dcId) {
|
||||
String sql = "DELETE FROM `cloud`.`host_pod_ref` WHERE name=\"" + name + "\" AND data_center_id=\"" + dcId + "\"";
|
||||
DatabaseConfig.saveSQL(sql, "Failed to delete pod due to exception. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public long getVlanDbId(String zone, String vlanId) {
|
||||
long zoneId = getZoneId(zone);
|
||||
|
||||
return DatabaseConfig.getDatabaseValueLong("SELECT * FROM `cloud`.`vlan` WHERE data_center_id=\"" + zoneId + "\" AND vlan_id =\"" + vlanId + "\"", "id",
|
||||
"Unable to start DB connection to read vlan DB id. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public List<String> modifyVlan(String zone, boolean add, String vlanId, String vlanGateway, String vlanNetmask, String pod, String vlanType, String ipRange, long networkId, long physicalNetworkId) {
|
||||
// Check if the zone is valid
|
||||
long zoneId = getZoneId(zone);
|
||||
if (zoneId == -1)
|
||||
return genReturnList("false", "Please specify a valid zone.");
|
||||
|
||||
//check if physical network is valid
|
||||
long physicalNetworkDbId = checkPhysicalNetwork(physicalNetworkId);
|
||||
if (physicalNetworkId == -1)
|
||||
return genReturnList("false", "Please specify a valid physical network.");
|
||||
|
||||
|
||||
Long podId = pod!=null?getPodId(pod, zone):null;
|
||||
if (podId != null && podId == -1)
|
||||
return genReturnList("false", "Please specify a valid pod.");
|
||||
|
||||
if (add) {
|
||||
|
||||
// Make sure the gateway is valid
|
||||
if (!NetUtils.isValidIp(vlanGateway))
|
||||
return genReturnList("false", "Please specify a valid gateway.");
|
||||
|
||||
// Make sure the netmask is valid
|
||||
if (!NetUtils.isValidIp(vlanNetmask))
|
||||
return genReturnList("false", "Please specify a valid netmask.");
|
||||
|
||||
// Check if a vlan with the same vlanId already exists in the specified zone
|
||||
if (getVlanDbId(zone, vlanId) != -1)
|
||||
return genReturnList("false", "A VLAN with the specified VLAN ID already exists in zone " + zone + ".");
|
||||
|
||||
/*
|
||||
|
||||
|
||||
Long podId = pod!=null?getPodId(pod, zone):null;
|
||||
if (podId != null && podId == -1)
|
||||
return genReturnList("false", "Please specify a valid pod.");
|
||||
|
||||
if (add) {
|
||||
|
||||
// Make sure the gateway is valid
|
||||
if (!NetUtils.isValidIp(vlanGateway))
|
||||
return genReturnList("false", "Please specify a valid gateway.");
|
||||
|
||||
// Make sure the netmask is valid
|
||||
if (!NetUtils.isValidIp(vlanNetmask))
|
||||
return genReturnList("false", "Please specify a valid netmask.");
|
||||
|
||||
// Check if a vlan with the same vlanId already exists in the specified zone
|
||||
if (getVlanDbId(zone, vlanId) != -1)
|
||||
return genReturnList("false", "A VLAN with the specified VLAN ID already exists in zone " + zone + ".");
|
||||
|
||||
/*
|
||||
// Check if another vlan in the same zone has the same subnet
|
||||
String newVlanSubnet = NetUtils.getSubNet(vlanGateway, vlanNetmask);
|
||||
List<VlanVO> vlans = _vlanDao.findByZone(zoneId);
|
||||
@ -221,146 +221,146 @@ public class PodZoneConfig {
|
||||
if (newVlanSubnet.equals(currentVlanSubnet))
|
||||
return genReturnList("false", "The VLAN with ID " + vlan.getVlanId() + " in zone " + zone + " has the same subnet. Please specify a different gateway/netmask.");
|
||||
}
|
||||
*/
|
||||
|
||||
// Everything was fine, so persist the VLAN
|
||||
saveVlan(zoneId, podId, vlanId, vlanGateway, vlanNetmask, vlanType, ipRange, networkId, physicalNetworkDbId);
|
||||
*/
|
||||
|
||||
// Everything was fine, so persist the VLAN
|
||||
saveVlan(zoneId, podId, vlanId, vlanGateway, vlanNetmask, vlanType, ipRange, networkId, physicalNetworkDbId);
|
||||
if (podId != null) {
|
||||
long vlanDbId = getVlanDbId(zone, vlanId);
|
||||
String sql = "INSERT INTO `cloud`.`pod_vlan_map` (pod_id, vlan_db_id) " + "VALUES ('" + podId + "','" + vlanDbId + "')";
|
||||
long vlanDbId = getVlanDbId(zone, vlanId);
|
||||
String sql = "INSERT INTO `cloud`.`pod_vlan_map` (pod_id, vlan_db_id) " + "VALUES ('" + podId + "','" + vlanDbId + "')";
|
||||
DatabaseConfig.saveSQL(sql, "Failed to save pod_vlan_map due to exception vlanDbId=" + vlanDbId + ", podId=" + podId + ". Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
return genReturnList("true", "Successfully added VLAN.");
|
||||
|
||||
} else {
|
||||
return genReturnList("false", "That operation is not suppored.");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
return genReturnList("true", "Successfully added VLAN.");
|
||||
|
||||
} else {
|
||||
return genReturnList("false", "That operation is not suppored.");
|
||||
}
|
||||
|
||||
/*
|
||||
else {
|
||||
|
||||
|
||||
// Check if a VLAN actually exists in the specified zone
|
||||
long vlanDbId = getVlanDbId(zone, vlanId);
|
||||
if (vlanDbId == -1)
|
||||
return genReturnList("false", "A VLAN with ID " + vlanId + " does not exist in zone " + zone);
|
||||
|
||||
|
||||
// Check if there are any public IPs that are in the specified vlan.
|
||||
List<IPAddressVO> ips = _publicIpAddressDao.listByVlanDbId(vlanDbId);
|
||||
if (ips.size() != 0)
|
||||
return genReturnList("false", "Please delete all IP addresses that are in VLAN " + vlanId + " before deleting the VLAN.");
|
||||
|
||||
|
||||
// Delete the vlan
|
||||
_vlanDao.delete(vlanDbId);
|
||||
|
||||
|
||||
return genReturnList("true", "Successfully deleted VLAN.");
|
||||
}
|
||||
*/
|
||||
*/
|
||||
}
|
||||
|
||||
@DB
|
||||
public void saveZone(boolean printOutput, long id, String name, String dns1, String dns2, String dns3, String dns4, String guestNetworkCidr, String networkType) {
|
||||
|
||||
if (printOutput) System.out.println("Saving zone, please wait...");
|
||||
|
||||
String columns = null;
|
||||
String values = null;
|
||||
|
||||
if (id != -1) {
|
||||
columns = "(id, name";
|
||||
values = "('" + id + "','" + name + "'";
|
||||
} else {
|
||||
columns = "(name";
|
||||
values = "('" + name + "'";
|
||||
}
|
||||
|
||||
if (dns1 != null) {
|
||||
columns += ", dns1";
|
||||
values += ",'" + dns1 + "'";
|
||||
}
|
||||
|
||||
if (dns2 != null) {
|
||||
columns += ", dns2";
|
||||
values += ",'" + dns2 + "'";
|
||||
}
|
||||
|
||||
if (dns3 != null) {
|
||||
columns += ", internal_dns1";
|
||||
values += ",'" + dns3 + "'";
|
||||
}
|
||||
|
||||
if (dns4 != null) {
|
||||
columns += ", internal_dns2";
|
||||
values += ",'" + dns4 + "'";
|
||||
}
|
||||
|
||||
if(guestNetworkCidr != null) {
|
||||
columns += ", guest_network_cidr";
|
||||
values += ",'" + guestNetworkCidr + "'";
|
||||
}
|
||||
|
||||
if(networkType != null) {
|
||||
columns += ", networktype";
|
||||
values += ",'" + networkType + "'";
|
||||
}
|
||||
|
||||
columns += ", uuid";
|
||||
values += ", UUID()";
|
||||
|
||||
columns += ")";
|
||||
values += ")";
|
||||
|
||||
String sql = "INSERT INTO `cloud`.`data_center` " + columns + " VALUES " + values;
|
||||
|
||||
DatabaseConfig.saveSQL(sql, "Failed to save zone due to exception. Please contact Cloud Support.");
|
||||
|
||||
if (printOutput) System.out.println("Successfully saved zone.");
|
||||
}
|
||||
|
||||
@DB
|
||||
public void savePhysicalNetwork(boolean printOutput, long id, long dcId, int vnetStart, int vnetEnd) {
|
||||
|
||||
if (printOutput) System.out.println("Saving physical network, please wait...");
|
||||
|
||||
@DB
|
||||
public void saveZone(boolean printOutput, long id, String name, String dns1, String dns2, String dns3, String dns4, String guestNetworkCidr, String networkType) {
|
||||
|
||||
if (printOutput) System.out.println("Saving zone, please wait...");
|
||||
|
||||
String columns = null;
|
||||
String values = null;
|
||||
|
||||
|
||||
if (id != -1) {
|
||||
columns = "(id, name";
|
||||
values = "('" + id + "','" + name + "'";
|
||||
} else {
|
||||
columns = "(name";
|
||||
values = "('" + name + "'";
|
||||
}
|
||||
|
||||
if (dns1 != null) {
|
||||
columns += ", dns1";
|
||||
values += ",'" + dns1 + "'";
|
||||
}
|
||||
|
||||
if (dns2 != null) {
|
||||
columns += ", dns2";
|
||||
values += ",'" + dns2 + "'";
|
||||
}
|
||||
|
||||
if (dns3 != null) {
|
||||
columns += ", internal_dns1";
|
||||
values += ",'" + dns3 + "'";
|
||||
}
|
||||
|
||||
if (dns4 != null) {
|
||||
columns += ", internal_dns2";
|
||||
values += ",'" + dns4 + "'";
|
||||
}
|
||||
|
||||
if(guestNetworkCidr != null) {
|
||||
columns += ", guest_network_cidr";
|
||||
values += ",'" + guestNetworkCidr + "'";
|
||||
}
|
||||
|
||||
if(networkType != null) {
|
||||
columns += ", networktype";
|
||||
values += ",'" + networkType + "'";
|
||||
}
|
||||
|
||||
columns += ", uuid";
|
||||
values += ", UUID()";
|
||||
|
||||
columns += ")";
|
||||
values += ")";
|
||||
|
||||
String sql = "INSERT INTO `cloud`.`data_center` " + columns + " VALUES " + values;
|
||||
|
||||
DatabaseConfig.saveSQL(sql, "Failed to save zone due to exception. Please contact Cloud Support.");
|
||||
|
||||
if (printOutput) System.out.println("Successfully saved zone.");
|
||||
}
|
||||
|
||||
@DB
|
||||
public void savePhysicalNetwork(boolean printOutput, long id, long dcId, int vnetStart, int vnetEnd) {
|
||||
|
||||
if (printOutput) System.out.println("Saving physical network, please wait...");
|
||||
|
||||
String columns = null;
|
||||
String values = null;
|
||||
|
||||
columns = "(id ";
|
||||
values = "('" + id + "'";
|
||||
|
||||
|
||||
columns += ", name ";
|
||||
values += ",'physical network'";
|
||||
|
||||
|
||||
columns += ", data_center_id ";
|
||||
values += ",'" + dcId + "'";
|
||||
|
||||
|
||||
//save vnet information
|
||||
columns += ", vnet";
|
||||
values += ",'" + vnetStart + "-" + vnetEnd + "'";
|
||||
|
||||
|
||||
columns += ", state";
|
||||
values += ", 'Enabled'";
|
||||
|
||||
|
||||
columns += ", uuid";
|
||||
values += ", UUID()";
|
||||
|
||||
|
||||
columns += ")";
|
||||
values += ")";
|
||||
|
||||
|
||||
String sql = "INSERT INTO `cloud`.`physical_network` " + columns + " VALUES " + values;
|
||||
|
||||
|
||||
DatabaseConfig.saveSQL(sql, "Failed to save physical network due to exception. Please contact Cloud Support.");
|
||||
|
||||
|
||||
// Hardcode the vnet range to be the full range
|
||||
int begin = 0x64;
|
||||
int end = 64000;
|
||||
|
||||
|
||||
// If vnet arguments were passed in, use them
|
||||
if (vnetStart != -1 && vnetEnd != -1) {
|
||||
begin = vnetStart;
|
||||
end = vnetEnd;
|
||||
}
|
||||
|
||||
|
||||
String insertVnet = "INSERT INTO `cloud`.`op_dc_vnet_alloc` (vnet, data_center_id, physical_network_id) VALUES ( ?, ?, ?)";
|
||||
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
@ -376,17 +376,17 @@ public class PodZoneConfig {
|
||||
} catch (SQLException ex) {
|
||||
printError("Error creating vnet for the physical network. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
|
||||
//add default traffic types
|
||||
|
||||
|
||||
//get default Xen network labels
|
||||
String defaultXenPrivateNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Management);
|
||||
String defaultXenPublicNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Public);
|
||||
String defaultXenStorageNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Storage);
|
||||
String defaultXenGuestNetworkLabel = getDefaultXenNetworkLabel(TrafficType.Guest);
|
||||
|
||||
|
||||
String insertTraficType = "INSERT INTO `cloud`.`physical_network_traffic_types` " +
|
||||
"(physical_network_id, traffic_type, xen_network_label) VALUES ( ?, ?, ?)";
|
||||
"(physical_network_id, traffic_type, xen_network_label) VALUES ( ?, ?, ?)";
|
||||
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(insertTraficType);
|
||||
@ -406,128 +406,128 @@ public class PodZoneConfig {
|
||||
}else if(traffic.equals(TrafficType.Guest)){
|
||||
stmt.setString(3, defaultXenGuestNetworkLabel);
|
||||
}
|
||||
|
||||
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
} catch (SQLException ex) {
|
||||
printError("Error adding default traffic types for the physical network. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
|
||||
if (printOutput) System.out.println("Successfully saved physical network.");
|
||||
}
|
||||
|
||||
|
||||
private String getDefaultXenNetworkLabel(TrafficType trafficType){
|
||||
String xenLabel = null;
|
||||
String configName = null;
|
||||
switch(trafficType){
|
||||
case Public: configName = "xen.public.network.device";
|
||||
break;
|
||||
case Guest: configName = "xen.guest.network.device";
|
||||
break;
|
||||
case Storage: configName = "xen.storage.network.device1";
|
||||
break;
|
||||
case Management: configName = "xen.private.network.device";
|
||||
break;
|
||||
case Public: configName = "xen.public.network.device";
|
||||
break;
|
||||
case Guest: configName = "xen.guest.network.device";
|
||||
break;
|
||||
case Storage: configName = "xen.storage.network.device1";
|
||||
break;
|
||||
case Management: configName = "xen.private.network.device";
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if(configName != null){
|
||||
xenLabel = getConfiguredValue(configName);
|
||||
}
|
||||
return xenLabel;
|
||||
}
|
||||
|
||||
|
||||
public static String getConfiguredValue(String configName)
|
||||
{
|
||||
return DatabaseConfig.getDatabaseValueString("SELECT value FROM `cloud`.`configuration` where name = \"" + configName + "\"","value",
|
||||
"Unable to start DB connection to read configuration. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public void deleteZone(String name) {
|
||||
String sql = "DELETE FROM `cloud`.`data_center` WHERE name=\"" + name + "\"";
|
||||
DatabaseConfig.saveSQL(sql, "Failed to delete zone due to exception. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public void saveVlan(long zoneId, Long podId, String vlanId, String vlanGateway, String vlanNetmask, String vlanType, String ipRange, long networkId, long physicalNetworkId) {
|
||||
String sql = "INSERT INTO `cloud`.`vlan` (vlan_id, vlan_gateway, vlan_netmask, data_center_id, vlan_type, description, network_id, physical_network_id) " + "VALUES ('" + vlanId + "','" + vlanGateway + "','" + vlanNetmask + "','" + zoneId + "','" + vlanType + "','" + ipRange + "','" + networkId + "','" + physicalNetworkId + "')";
|
||||
|
||||
public void deleteZone(String name) {
|
||||
String sql = "DELETE FROM `cloud`.`data_center` WHERE name=\"" + name + "\"";
|
||||
DatabaseConfig.saveSQL(sql, "Failed to delete zone due to exception. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public void saveVlan(long zoneId, Long podId, String vlanId, String vlanGateway, String vlanNetmask, String vlanType, String ipRange, long networkId, long physicalNetworkId) {
|
||||
String sql = "INSERT INTO `cloud`.`vlan` (vlan_id, vlan_gateway, vlan_netmask, data_center_id, vlan_type, description, network_id, physical_network_id) " + "VALUES ('" + vlanId + "','" + vlanGateway + "','" + vlanNetmask + "','" + zoneId + "','" + vlanType + "','" + ipRange + "','" + networkId + "','" + physicalNetworkId + "')";
|
||||
DatabaseConfig.saveSQL(sql, "Failed to save vlan due to exception. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public static long getPodId(String pod, String zone) {
|
||||
long dcId = getZoneId(zone);
|
||||
String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
|
||||
String errorMsg = "Could not read pod ID fro mdatabase. Please contact Cloud Support.";
|
||||
return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
|
||||
}
|
||||
|
||||
public static long getPodId(String pod, long dcId) {
|
||||
}
|
||||
|
||||
public static long getPodId(String pod, String zone) {
|
||||
long dcId = getZoneId(zone);
|
||||
String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
|
||||
String errorMsg = "Could not read pod ID fro mdatabase. Please contact Cloud Support.";
|
||||
return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
|
||||
}
|
||||
|
||||
public static long getZoneId(String zone) {
|
||||
String selectSql = "SELECT * FROM `cloud`.`data_center` WHERE name = \"" + zone + "\"";
|
||||
String errorMsg = "Could not read zone ID from database. Please contact Cloud Support.";
|
||||
return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
|
||||
}
|
||||
|
||||
|
||||
public static long getPodId(String pod, long dcId) {
|
||||
String selectSql = "SELECT * FROM `cloud`.`host_pod_ref` WHERE name = \"" + pod + "\" AND data_center_id = \"" + dcId + "\"";
|
||||
String errorMsg = "Could not read pod ID fro mdatabase. Please contact Cloud Support.";
|
||||
return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
|
||||
}
|
||||
|
||||
public static long getZoneId(String zone) {
|
||||
String selectSql = "SELECT * FROM `cloud`.`data_center` WHERE name = \"" + zone + "\"";
|
||||
String errorMsg = "Could not read zone ID from database. Please contact Cloud Support.";
|
||||
return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
|
||||
}
|
||||
|
||||
public static long checkPhysicalNetwork(long physicalNetworkId) {
|
||||
String selectSql = "SELECT * FROM `cloud`.`physical_network` WHERE id = \"" + physicalNetworkId + "\"";
|
||||
String errorMsg = "Could not read physicalNetwork ID from database. Please contact Cloud Support.";
|
||||
return DatabaseConfig.getDatabaseValueLong(selectSql, "id", errorMsg);
|
||||
}
|
||||
|
||||
@DB
|
||||
public Vector<Long> getAllZoneIDs() {
|
||||
Vector<Long> allZoneIDs = new Vector<Long>();
|
||||
|
||||
String selectSql = "SELECT id FROM data_center";
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Long dcId = rs.getLong("id");
|
||||
allZoneIDs.add(dcId);
|
||||
}
|
||||
|
||||
@DB
|
||||
public Vector<Long> getAllZoneIDs() {
|
||||
Vector<Long> allZoneIDs = new Vector<Long>();
|
||||
|
||||
String selectSql = "SELECT id FROM data_center";
|
||||
Transaction txn = Transaction.currentTxn();
|
||||
try {
|
||||
PreparedStatement stmt = txn.prepareAutoCloseStatement(selectSql);
|
||||
ResultSet rs = stmt.executeQuery();
|
||||
while (rs.next()) {
|
||||
Long dcId = rs.getLong("id");
|
||||
allZoneIDs.add(dcId);
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
System.out.println(ex.getMessage());
|
||||
printError("There was an issue with reading zone IDs. Please contact Cloud Support.");
|
||||
System.out.println(ex.getMessage());
|
||||
printError("There was an issue with reading zone IDs. Please contact Cloud Support.");
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return allZoneIDs;
|
||||
}
|
||||
|
||||
|
||||
public static boolean validPod(String pod, String zone) {
|
||||
return (getPodId(pod, zone) != -1);
|
||||
}
|
||||
|
||||
public static boolean validZone(String zone) {
|
||||
return (getZoneId(zone) != -1);
|
||||
}
|
||||
|
||||
public static String getPodName(long podId, long dcId) {
|
||||
return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`host_pod_ref` WHERE id=" + podId + " AND data_center_id=" + dcId, "name",
|
||||
"Unable to start DB connection to read pod name. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public static String getZoneName(long dcId) {
|
||||
return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE id=" + dcId, "name",
|
||||
"Unable to start DB connection to read zone name. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
private static void printError(String message) {
|
||||
DatabaseConfig.printError(message);
|
||||
}
|
||||
|
||||
private List<String> genReturnList(String success, String message) {
|
||||
List<String> returnList = new ArrayList<String>();
|
||||
returnList.add(0, success);
|
||||
returnList.add(1, message);
|
||||
return returnList;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean validPod(String pod, String zone) {
|
||||
return (getPodId(pod, zone) != -1);
|
||||
}
|
||||
|
||||
public static boolean validZone(String zone) {
|
||||
return (getZoneId(zone) != -1);
|
||||
}
|
||||
|
||||
public static String getPodName(long podId, long dcId) {
|
||||
return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`host_pod_ref` WHERE id=" + podId + " AND data_center_id=" + dcId, "name",
|
||||
"Unable to start DB connection to read pod name. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
public static String getZoneName(long dcId) {
|
||||
return DatabaseConfig.getDatabaseValueString("SELECT * FROM `cloud`.`data_center` WHERE id=" + dcId, "name",
|
||||
"Unable to start DB connection to read zone name. Please contact Cloud Support.");
|
||||
}
|
||||
|
||||
private static void printError(String message) {
|
||||
DatabaseConfig.printError(message);
|
||||
}
|
||||
|
||||
private List<String> genReturnList(String success, String message) {
|
||||
List<String> returnList = new ArrayList<String>();
|
||||
returnList.add(0, success);
|
||||
returnList.add(1, message);
|
||||
return returnList;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -22,7 +22,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.cluster.StackMaid;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.db.GlobalLock;
|
||||
@ -32,27 +31,27 @@ import com.cloud.utils.db.Transaction;
|
||||
// TODO: simple load scanner, to minimize code changes required in console proxy manager and SSVM, we still leave most of work at handler
|
||||
//
|
||||
public class SystemVmLoadScanner<T> {
|
||||
public enum AfterScanAction { nop, expand, shrink }
|
||||
|
||||
public enum AfterScanAction { nop, expand, shrink }
|
||||
|
||||
private static final Logger s_logger = Logger.getLogger(SystemVmLoadScanner.class);
|
||||
|
||||
private static final int ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION = 3; // 3 seconds
|
||||
|
||||
private final SystemVmLoadScanHandler<T> _scanHandler;
|
||||
|
||||
private final SystemVmLoadScanHandler<T> _scanHandler;
|
||||
private final ScheduledExecutorService _capacityScanScheduler;
|
||||
private final GlobalLock _capacityScanLock;
|
||||
|
||||
public SystemVmLoadScanner(SystemVmLoadScanHandler<T> scanHandler) {
|
||||
_scanHandler = scanHandler;
|
||||
_capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory(scanHandler.getScanHandlerName()));
|
||||
_capacityScanLock = GlobalLock.getInternLock(scanHandler.getScanHandlerName() + ".scan.lock");
|
||||
}
|
||||
|
||||
public void initScan(long startupDelayMs, long scanIntervalMs) {
|
||||
|
||||
public SystemVmLoadScanner(SystemVmLoadScanHandler<T> scanHandler) {
|
||||
_scanHandler = scanHandler;
|
||||
_capacityScanScheduler = Executors.newScheduledThreadPool(1, new NamedThreadFactory(scanHandler.getScanHandlerName()));
|
||||
_capacityScanLock = GlobalLock.getInternLock(scanHandler.getScanHandlerName() + ".scan.lock");
|
||||
}
|
||||
|
||||
public void initScan(long startupDelayMs, long scanIntervalMs) {
|
||||
_capacityScanScheduler.scheduleAtFixedRate(getCapacityScanTask(), startupDelayMs, scanIntervalMs, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
_capacityScanScheduler.shutdownNow();
|
||||
|
||||
try {
|
||||
@ -61,8 +60,8 @@ public class SystemVmLoadScanner<T> {
|
||||
}
|
||||
|
||||
_capacityScanLock.releaseRef();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Runnable getCapacityScanTask() {
|
||||
return new Runnable() {
|
||||
|
||||
@ -74,56 +73,55 @@ public class SystemVmLoadScanner<T> {
|
||||
} catch (Throwable e) {
|
||||
s_logger.warn("Unexpected exception " + e.getMessage(), e);
|
||||
} finally {
|
||||
StackMaid.current().exitCleanup();
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void reallyRun() {
|
||||
loadScan();
|
||||
loadScan();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private void loadScan() {
|
||||
if(!_scanHandler.canScan()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(!_scanHandler.canScan()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_capacityScanLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_COOPERATION)) {
|
||||
if (s_logger.isTraceEnabled()) {
|
||||
s_logger.trace("Capacity scan lock is used by others, skip and wait for my turn");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
_scanHandler.onScanStart();
|
||||
|
||||
T[] pools = _scanHandler.getScannablePools();
|
||||
for(T p : pools) {
|
||||
if(_scanHandler.isPoolReadyForScan(p)) {
|
||||
Pair<AfterScanAction, Object> actionInfo = _scanHandler.scanPool(p);
|
||||
|
||||
switch(actionInfo.first()) {
|
||||
case nop:
|
||||
break;
|
||||
|
||||
case expand:
|
||||
_scanHandler.expandPool(p, actionInfo.second());
|
||||
break;
|
||||
|
||||
case shrink:
|
||||
_scanHandler.shrinkPool(p, actionInfo.second());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_scanHandler.onScanEnd();
|
||||
|
||||
_scanHandler.onScanStart();
|
||||
|
||||
T[] pools = _scanHandler.getScannablePools();
|
||||
for(T p : pools) {
|
||||
if(_scanHandler.isPoolReadyForScan(p)) {
|
||||
Pair<AfterScanAction, Object> actionInfo = _scanHandler.scanPool(p);
|
||||
|
||||
switch(actionInfo.first()) {
|
||||
case nop:
|
||||
break;
|
||||
|
||||
case expand:
|
||||
_scanHandler.expandPool(p, actionInfo.second());
|
||||
break;
|
||||
|
||||
case shrink:
|
||||
_scanHandler.shrinkPool(p, actionInfo.second());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_scanHandler.onScanEnd();
|
||||
|
||||
} finally {
|
||||
_capacityScanLock.unlock();
|
||||
_capacityScanLock.unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,7 +214,6 @@ import com.cloud.uservm.UserVm;
|
||||
import com.cloud.utils.NumbersUtil;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.PasswordGenerator;
|
||||
|
||||
import com.cloud.utils.component.Manager;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
import com.cloud.utils.crypt.RSAHelper;
|
||||
@ -381,7 +380,7 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
protected String _instance;
|
||||
protected String _zone;
|
||||
|
||||
private ConfigurationDao _configDao;
|
||||
@Inject ConfigurationDao _configDao;
|
||||
private int _createprivatetemplatefromvolumewait;
|
||||
private int _createprivatetemplatefromsnapshotwait;
|
||||
|
||||
@ -1333,8 +1332,6 @@ public class UserVmManagerImpl implements UserVmManager, UserVmService, Manager
|
||||
throws ConfigurationException {
|
||||
_name = name;
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getCurrentLocator();
|
||||
_configDao = locator.getDao(ConfigurationDao.class);
|
||||
if (_configDao == null) {
|
||||
throw new ConfigurationException(
|
||||
"Unable to get the configuration dao.");
|
||||
|
||||
@ -71,7 +71,6 @@ import com.cloud.agent.manager.allocator.HostAllocator;
|
||||
import com.cloud.alert.AlertManager;
|
||||
import com.cloud.capacity.CapacityManager;
|
||||
import com.cloud.cluster.ClusterManager;
|
||||
import com.cloud.cluster.StackMaid;
|
||||
import com.cloud.configuration.Config;
|
||||
import com.cloud.configuration.ConfigurationManager;
|
||||
import com.cloud.configuration.dao.ConfigurationDao;
|
||||
@ -238,7 +237,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
|
||||
@Inject
|
||||
protected ConfigurationDao _configDao;
|
||||
|
||||
|
||||
Map<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>> _vmGurus = new HashMap<VirtualMachine.Type, VirtualMachineGuru<? extends VMInstanceVO>>();
|
||||
protected StateMachine2<State, VirtualMachine.Event, VirtualMachine> _stateMachine;
|
||||
|
||||
@ -288,7 +287,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Allocating nics for " + vm);
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
_networkMgr.allocate(vmProfile, networks);
|
||||
} catch (ConcurrentOperationException e) {
|
||||
@ -673,7 +672,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
StoragePoolVO pool = _storagePoolDao.findById(vol.getPoolId());
|
||||
if (!pool.isInMaintenance()) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
@ -707,7 +706,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
VirtualMachineProfileImpl<T> vmProfile = new VirtualMachineProfileImpl<T>(vm, template, offering, account, params);
|
||||
DeployDestination dest = null;
|
||||
for (DeploymentPlanner planner : _planners) {
|
||||
@ -757,7 +756,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
if(!reuseVolume){
|
||||
reuseVolume = true;
|
||||
}
|
||||
|
||||
|
||||
Commands cmds = null;
|
||||
vmGuru.finalizeVirtualMachineProfile(vmProfile, dest, ctx);
|
||||
|
||||
@ -776,10 +775,10 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
_workDao.updateStep(work, Step.Starting);
|
||||
|
||||
_agentMgr.send(destHostId, cmds);
|
||||
|
||||
|
||||
_workDao.updateStep(work, Step.Started);
|
||||
|
||||
|
||||
|
||||
|
||||
StartAnswer startAnswer = cmds.getAnswer(StartAnswer.class);
|
||||
if (startAnswer != null && startAnswer.getResult()) {
|
||||
String host_guid = startAnswer.getHost_guid();
|
||||
@ -803,7 +802,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.info("The guru did not like the answers so stopping " + vm);
|
||||
}
|
||||
|
||||
|
||||
StopCommand cmd = new StopCommand(vm.getInstanceName());
|
||||
StopAnswer answer = (StopAnswer) _agentMgr.easySend(destHostId, cmd);
|
||||
if (answer == null || !answer.getResult()) {
|
||||
@ -815,7 +814,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
}
|
||||
}
|
||||
s_logger.info("Unable to start VM on " + dest.getHost() + " due to " + (startAnswer == null ? " no start answer" : startAnswer.getDetails()));
|
||||
|
||||
|
||||
} catch (OperationTimedoutException e) {
|
||||
s_logger.debug("Unable to send the start command to host " + dest.getHost());
|
||||
if (e.isActive()) {
|
||||
@ -1071,7 +1070,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
}
|
||||
|
||||
vmGuru.prepareStop(profile);
|
||||
|
||||
|
||||
StopCommand stop = new StopCommand(vm, vm.getInstanceName(), null);
|
||||
boolean stopped = false;
|
||||
StopAnswer answer = null;
|
||||
@ -1560,13 +1559,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
public boolean isVirtualMachineUpgradable(VirtualMachine vm, ServiceOffering offering) {
|
||||
boolean isMachineUpgradable = true;
|
||||
for(HostAllocator allocator : _hostAllocators) {
|
||||
isMachineUpgradable = allocator.isVirtualMachineUpgradable(vm, offering);
|
||||
if(isMachineUpgradable)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
isMachineUpgradable = allocator.isVirtualMachineUpgradable(vm, offering);
|
||||
if(isMachineUpgradable)
|
||||
continue;
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
return isMachineUpgradable;
|
||||
}
|
||||
|
||||
@ -1644,7 +1643,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
commands.addCommand(command);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (final AgentVmInfo left : infos.values()) {
|
||||
boolean found = false;
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : _vmGurus.values()) {
|
||||
@ -1740,7 +1739,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
|
||||
|
||||
public void fullSync(final long clusterId, Map<String, Pair<String, State>> newStates) {
|
||||
if (newStates==null)return;
|
||||
if (newStates==null)return;
|
||||
Map<Long, AgentVmInfo> infos = convertToInfos(newStates);
|
||||
Set<VMInstanceVO> set_vms = Collections.synchronizedSet(new HashSet<VMInstanceVO>());
|
||||
set_vms.addAll(_vmDao.listByClusterId(clusterId));
|
||||
@ -1750,11 +1749,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
AgentVmInfo info = infos.remove(vm.getId());
|
||||
VMInstanceVO castedVm = null;
|
||||
if ((info == null && (vm.getState() == State.Running || vm.getState() == State.Starting))
|
||||
|| (info != null && (info.state == State.Running && vm.getState() == State.Starting)))
|
||||
|| (info != null && (info.state == State.Running && vm.getState() == State.Starting)))
|
||||
{
|
||||
s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") + " on agent");
|
||||
s_logger.info("Found vm " + vm.getInstanceName() + " in inconsistent state. " + vm.getState() + " on CS while " + (info == null ? "Stopped" : "Running") + " on agent");
|
||||
info = new AgentVmInfo(vm.getInstanceName(), getVmGuru(vm), vm, State.Stopped);
|
||||
|
||||
|
||||
// Bug 13850- grab outstanding work item if any for this VM state so that we mark it as DONE after we change VM state, else it will remain pending
|
||||
ItWorkVO work = _workDao.findByOutstandingWork(vm.getId(), vm.getState());
|
||||
if (work != null) {
|
||||
@ -1763,8 +1762,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
}
|
||||
}
|
||||
vm.setState(State.Running); // set it as running and let HA take care of it
|
||||
_vmDao.persist(vm);
|
||||
|
||||
_vmDao.persist(vm);
|
||||
|
||||
if (work != null) {
|
||||
if (s_logger.isDebugEnabled()) {
|
||||
s_logger.debug("Updating outstanding work item to Done, id:" + work.getId());
|
||||
@ -1772,7 +1771,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
work.setStep(Step.Done);
|
||||
_workDao.update(work.getId(), work);
|
||||
}
|
||||
|
||||
|
||||
castedVm = info.guru.findById(vm.getId());
|
||||
try {
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
@ -1812,20 +1811,20 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
}
|
||||
}
|
||||
else
|
||||
// host id can change
|
||||
if (info != null && vm.getState() == State.Running){
|
||||
// check for host id changes
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
if (host != null && (vm.getHostId() == null || host.getId() != vm.getHostId())){
|
||||
s_logger.info("Found vm " + vm.getInstanceName() + " with inconsistent host in db, new host is " + host.getId());
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportMigrated, host.getId());
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
/* else if(info == null && vm.getState() == State.Stopping) { //Handling CS-13376
|
||||
// host id can change
|
||||
if (info != null && vm.getState() == State.Running){
|
||||
// check for host id changes
|
||||
Host host = _hostDao.findByGuid(info.getHostUuid());
|
||||
if (host != null && (vm.getHostId() == null || host.getId() != vm.getHostId())){
|
||||
s_logger.info("Found vm " + vm.getInstanceName() + " with inconsistent host in db, new host is " + host.getId());
|
||||
try {
|
||||
stateTransitTo(vm, VirtualMachine.Event.AgentReportMigrated, host.getId());
|
||||
} catch (NoTransitionException e) {
|
||||
s_logger.warn(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
/* else if(info == null && vm.getState() == State.Stopping) { //Handling CS-13376
|
||||
s_logger.warn("Marking the VM as Stopped as it was still stopping on the CS" +vm.getName());
|
||||
vm.setState(State.Stopped); // Setting the VM as stopped on the DB and clearing it from the host
|
||||
vm.setLastHostId(vm.getHostId());
|
||||
@ -1863,7 +1862,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
boolean is_alien_vm = true;
|
||||
long alien_vm_count = -1;
|
||||
for (Map.Entry<String, Pair<String, State>> entry : newStates.entrySet()) {
|
||||
is_alien_vm = true;
|
||||
is_alien_vm = true;
|
||||
for (VirtualMachineGuru<? extends VMInstanceVO> vmGuru : vmGurus) {
|
||||
String name = entry.getKey();
|
||||
VMInstanceVO vm = vmGuru.findByName(name);
|
||||
@ -1881,8 +1880,8 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
}
|
||||
// alien VMs
|
||||
if (is_alien_vm){
|
||||
map.put(alien_vm_count--, new AgentVmInfo(entry.getKey(), null, null, entry.getValue().second(), entry.getValue().first()));
|
||||
s_logger.warn("Found an alien VM " + entry.getKey());
|
||||
map.put(alien_vm_count--, new AgentVmInfo(entry.getKey(), null, null, entry.getValue().second(), entry.getValue().first()));
|
||||
s_logger.warn("Found an alien VM " + entry.getKey());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
@ -2267,13 +2266,13 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
Long clusterId = agent.getClusterId();
|
||||
long agentId = agent.getId();
|
||||
if (agent.getHypervisorType() == HypervisorType.XenServer) { // only for Xen
|
||||
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
|
||||
HashMap<String, Pair<String, State>> allStates = startup.getClusterVMStateChanges();
|
||||
if (allStates != null){
|
||||
this.fullSync(clusterId, allStates);
|
||||
}
|
||||
|
||||
// initiate the cron job
|
||||
StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
|
||||
HashMap<String, Pair<String, State>> allStates = startup.getClusterVMStateChanges();
|
||||
if (allStates != null){
|
||||
this.fullSync(clusterId, allStates);
|
||||
}
|
||||
|
||||
// initiate the cron job
|
||||
ClusterSyncCommand syncCmd = new ClusterSyncCommand(Integer.parseInt(Config.ClusterDeltaSyncInterval.getDefaultValue()), clusterId);
|
||||
try {
|
||||
long seq_no = _agentMgr.send(agentId, new Commands(syncCmd), this);
|
||||
@ -2340,7 +2339,6 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
} catch (Exception e) {
|
||||
s_logger.warn("Caught the following exception on transition checking", e);
|
||||
} finally {
|
||||
StackMaid.current().exitCleanup();
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
@ -2375,7 +2373,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
public VMInstanceVO findById(long vmId) {
|
||||
return _vmDao.findById(vmId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void checkIfCanUpgrade(VirtualMachine vmInstance, long newServiceOfferingId) {
|
||||
ServiceOfferingVO newServiceOffering = _offeringDao.findById(newServiceOfferingId);
|
||||
@ -2387,7 +2385,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
if (!vmInstance.getState().equals(State.Stopped)) {
|
||||
s_logger.warn("Unable to upgrade virtual machine " + vmInstance.toString() + " in state " + vmInstance.getState());
|
||||
throw new InvalidParameterValueException("Unable to upgrade virtual machine " + vmInstance.toString() + " " +
|
||||
"in state " + vmInstance.getState()
|
||||
"in state " + vmInstance.getState()
|
||||
+ "; make sure the virtual machine is stopped and not in an error state before upgrading.");
|
||||
}
|
||||
|
||||
@ -2395,11 +2393,11 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
if (vmInstance.getServiceOfferingId() == newServiceOffering.getId()) {
|
||||
if (s_logger.isInfoEnabled()) {
|
||||
s_logger.info("Not upgrading vm " + vmInstance.toString() + " since it already has the requested " +
|
||||
"service offering (" + newServiceOffering.getName() + ")");
|
||||
"service offering (" + newServiceOffering.getName() + ")");
|
||||
}
|
||||
|
||||
throw new InvalidParameterValueException("Not upgrading vm " + vmInstance.toString() + " since it already " +
|
||||
"has the requested service offering (" + newServiceOffering.getName() + ")");
|
||||
"has the requested service offering (" + newServiceOffering.getName() + ")");
|
||||
}
|
||||
|
||||
ServiceOfferingVO currentServiceOffering = _offeringDao.findByIdIncludingRemoved(vmInstance.getServiceOfferingId());
|
||||
@ -2421,7 +2419,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
"useLocalStorage=" + currentServiceOffering.getUseLocalStorage()
|
||||
+ ", target offering useLocalStorage=" + newServiceOffering.getUseLocalStorage());
|
||||
}
|
||||
|
||||
|
||||
// if vm is a system vm, check if it is a system service offering, if yes return with error as it cannot be used for user vms
|
||||
if (currentServiceOffering.getSystemUse() != newServiceOffering.getSystemUse()) {
|
||||
throw new InvalidParameterValueException("isSystem property is different for current service offering and new service offering");
|
||||
@ -2430,7 +2428,7 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
// Check that there are enough resources to upgrade the service offering
|
||||
if (!isVirtualMachineUpgradable(vmInstance, newServiceOffering)) {
|
||||
throw new InvalidParameterValueException("Unable to upgrade virtual machine, not enough resources available " +
|
||||
"for an offering of " + newServiceOffering.getCpu() + " cpu(s) at "
|
||||
"for an offering of " + newServiceOffering.getCpu() + " cpu(s) at "
|
||||
+ newServiceOffering.getSpeed() + " Mhz, and " + newServiceOffering.getRamSize() + " MB of memory");
|
||||
}
|
||||
|
||||
@ -2439,12 +2437,12 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
List<String> newTags = _configMgr.csvTagsToList(newServiceOffering.getTags());
|
||||
if (!newTags.containsAll(currentTags)) {
|
||||
throw new InvalidParameterValueException("Unable to upgrade virtual machine; the new service offering " +
|
||||
"does not have all the tags of the "
|
||||
"does not have all the tags of the "
|
||||
+ "current service offering. Current service offering tags: " + currentTags + "; " + "new service " +
|
||||
"offering tags: " + newTags);
|
||||
"offering tags: " + newTags);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean upgradeVmDb(long vmId, long serviceOfferingId) {
|
||||
VMInstanceVO vmForUpdate = _vmDao.createForUpdate();
|
||||
@ -2455,38 +2453,38 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
vmForUpdate.setServiceOfferingId(newSvcOff.getId());
|
||||
return _vmDao.update(vmId, vmForUpdate);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NicProfile addVmToNetwork(VirtualMachine vm, Network network, NicProfile requested) throws ConcurrentOperationException,
|
||||
ResourceUnavailableException, InsufficientCapacityException {
|
||||
|
||||
ResourceUnavailableException, InsufficientCapacityException {
|
||||
|
||||
s_logger.debug("Adding vm " + vm + " to network " + network + "; requested nic profile " + requested);
|
||||
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
|
||||
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
|
||||
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
|
||||
|
||||
|
||||
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
|
||||
null, null, null);
|
||||
|
||||
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
Host host = _hostDao.findById(vm.getHostId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, host);
|
||||
|
||||
|
||||
//check vm state
|
||||
if (vm.getState() == State.Running) {
|
||||
//1) allocate and prepare nic
|
||||
NicProfile nic = _networkMgr.createNicForVm(network, requested, context, vmProfile, true);
|
||||
|
||||
|
||||
//2) Convert vmProfile to vmTO
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
||||
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
|
||||
|
||||
|
||||
//3) Convert nicProfile to NicTO
|
||||
NicTO nicTO = toNicTO(nic, vmProfile.getVirtualMachine().getHypervisorType());
|
||||
|
||||
|
||||
//4) plug the nic to the vm
|
||||
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
||||
|
||||
|
||||
s_logger.debug("Plugging nic for vm " + vm + " in network " + network);
|
||||
if (vmGuru.plugNic(network, nicTO, vmTO, context, dest)) {
|
||||
s_logger.debug("Nic is plugged successfully for vm " + vm + " in network " + network + ". Vm is a part of network now");
|
||||
@ -2509,40 +2507,40 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
@Override
|
||||
public NicTO toNicTO(NicProfile nic, HypervisorType hypervisorType) {
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(hypervisorType);
|
||||
|
||||
|
||||
NicTO nicTO = hvGuru.toNicTO(nic);
|
||||
return nicTO;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean removeVmFromNetwork(VirtualMachine vm, Network network, URI broadcastUri) throws ConcurrentOperationException, ResourceUnavailableException {
|
||||
VMInstanceVO vmVO = _vmDao.findById(vm.getId());
|
||||
ReservationContext context = new ReservationContextImpl(null, null, _accountMgr.getActiveUser(User.UID_SYSTEM),
|
||||
_accountMgr.getAccount(Account.ACCOUNT_ID_SYSTEM));
|
||||
|
||||
|
||||
VirtualMachineProfileImpl<VMInstanceVO> vmProfile = new VirtualMachineProfileImpl<VMInstanceVO>(vmVO, null,
|
||||
null, null, null);
|
||||
|
||||
|
||||
DataCenter dc = _configMgr.getZone(network.getDataCenterId());
|
||||
Host host = _hostDao.findById(vm.getHostId());
|
||||
DeployDestination dest = new DeployDestination(dc, null, null, host);
|
||||
VirtualMachineGuru<VMInstanceVO> vmGuru = getVmGuru(vmVO);
|
||||
HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vmProfile.getVirtualMachine().getHypervisorType());
|
||||
VirtualMachineTO vmTO = hvGuru.implement(vmProfile);
|
||||
|
||||
|
||||
Nic nic = null;
|
||||
|
||||
|
||||
if (broadcastUri != null) {
|
||||
nic = _nicsDao.findByNetworkIdInstanceIdAndBroadcastUri(network.getId(), vm.getId(), broadcastUri.toString());
|
||||
} else {
|
||||
nic = _networkMgr.getNicInNetwork(vm.getId(), network.getId());
|
||||
}
|
||||
|
||||
|
||||
NicProfile nicProfile = new NicProfile(nic, network, nic.getBroadcastUri(), nic.getIsolationUri(),
|
||||
_networkMgr.getNetworkRate(network.getId(), vm.getId()),
|
||||
_networkMgr.isSecurityGroupSupportedInNetwork(network),
|
||||
_networkMgr.getNetworkTag(vmProfile.getVirtualMachine().getHypervisorType(), network));
|
||||
|
||||
|
||||
//1) Unplug the nic
|
||||
NicTO nicTO = toNicTO(nicProfile, vmProfile.getVirtualMachine().getHypervisorType());
|
||||
s_logger.debug("Un-plugging nic for vm " + vm + " from network " + network);
|
||||
@ -2553,14 +2551,14 @@ public class VirtualMachineManagerImpl implements VirtualMachineManager, Listene
|
||||
s_logger.warn("Failed to unplug nic for the vm " + vm + " from network " + network);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//2) Release the nic
|
||||
_networkMgr.releaseNic(vmProfile, nic);
|
||||
s_logger.debug("Successfully released nic " + nic + "for vm " + vm);
|
||||
|
||||
|
||||
//3) Remove the nic
|
||||
_networkMgr.removeNic(vmProfile, nic);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -19,18 +19,13 @@ package com.cloud.async;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import com.cloud.async.AsyncJobVO;
|
||||
import com.cloud.cluster.StackMaid;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.cluster.CheckPointVO;
|
||||
import com.cloud.cluster.dao.StackMaidDao;
|
||||
import com.cloud.cluster.dao.StackMaidDaoImpl;
|
||||
import com.cloud.serializer.Param;
|
||||
import com.cloud.utils.ActionDelegate;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.db.Transaction;
|
||||
import com.cloud.utils.testcase.Log4jEnabledTestCase;
|
||||
|
||||
@ -42,15 +37,15 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
public static class SampleAsyncResult {
|
||||
@Param(name="name", propName="name")
|
||||
private final String _name;
|
||||
|
||||
|
||||
@Param
|
||||
private final int count;
|
||||
|
||||
|
||||
public SampleAsyncResult(String name, int count) {
|
||||
_name = name;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
|
||||
public String getName() { return _name; }
|
||||
public int getCount() { return count; }
|
||||
}
|
||||
@ -60,31 +55,31 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
AsyncJobVO job = new AsyncJobVO(1, 1, "TestCmd", null);
|
||||
job.setInstanceType("user_vm");
|
||||
job.setInstanceId(1000L);
|
||||
|
||||
|
||||
char[] buf = new char[1024];
|
||||
for(int i = 0; i < 1024; i++)
|
||||
buf[i] = 'a';
|
||||
|
||||
|
||||
job.setResult(new String(buf));
|
||||
dao.persist(job);
|
||||
|
||||
|
||||
AsyncJobVO jobVerify = dao.findById(job.getId());
|
||||
|
||||
|
||||
Assert.assertTrue(jobVerify.getCmd().equals(job.getCmd()));
|
||||
Assert.assertTrue(jobVerify.getUserId() == 1);
|
||||
Assert.assertTrue(jobVerify.getAccountId() == 1);
|
||||
|
||||
|
||||
String result = jobVerify.getResult();
|
||||
for(int i = 0; i < 1024; i++)
|
||||
Assert.assertTrue(result.charAt(i) == 'a');
|
||||
|
||||
|
||||
jobVerify = dao.findInstancePendingAsyncJob("user_vm", 1000L);
|
||||
Assert.assertTrue(jobVerify != null);
|
||||
Assert.assertTrue(jobVerify.getCmd().equals(job.getCmd()));
|
||||
Assert.assertTrue(jobVerify.getUserId() == 1);
|
||||
Assert.assertTrue(jobVerify.getAccountId() == 1);
|
||||
}
|
||||
|
||||
|
||||
public void testSerialization() {
|
||||
List<Pair<String, Object>> l;
|
||||
int value = 1;
|
||||
@ -93,23 +88,23 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
Assert.assertTrue(l.get(0).first().equals("result"));
|
||||
Assert.assertTrue(l.get(0).second().equals("1"));
|
||||
l.clear();
|
||||
|
||||
|
||||
SampleAsyncResult result = new SampleAsyncResult("vmops", 1);
|
||||
l = SerializerHelper.toPairList(result, "result");
|
||||
|
||||
|
||||
Assert.assertTrue(l.size() == 2);
|
||||
Assert.assertTrue(l.get(0).first().equals("name"));
|
||||
Assert.assertTrue(l.get(0).second().equals("vmops"));
|
||||
Assert.assertTrue(l.get(1).first().equals("count"));
|
||||
Assert.assertTrue(l.get(1).second().equals("1"));
|
||||
}
|
||||
|
||||
|
||||
public void testAsyncResult() {
|
||||
AsyncJobResult result = new AsyncJobResult(1);
|
||||
|
||||
|
||||
result.setResultObject(100);
|
||||
Assert.assertTrue(result.getResult().equals("java.lang.Integer/100"));
|
||||
|
||||
|
||||
Object obj = result.getResultObject();
|
||||
Assert.assertTrue(obj instanceof Integer);
|
||||
Assert.assertTrue(((Integer)obj).intValue() == 100);
|
||||
@ -119,7 +114,7 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
Transaction txn = Transaction.open("testTransaction");
|
||||
try {
|
||||
txn.start();
|
||||
|
||||
|
||||
AsyncJobDao dao = new AsyncJobDaoImpl();
|
||||
AsyncJobVO job = new AsyncJobVO(1, 1, "TestCmd", null);
|
||||
job.setInstanceType("user_vm");
|
||||
@ -131,11 +126,11 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void testMorevingian() {
|
||||
int threadCount = 10;
|
||||
final int testCount = 10;
|
||||
|
||||
|
||||
Thread[] threads = new Thread[threadCount];
|
||||
for(int i = 0; i < threadCount; i++) {
|
||||
final int threadNum = i + 1;
|
||||
@ -145,35 +140,35 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
try {
|
||||
AsyncJobDao dao = new AsyncJobDaoImpl();
|
||||
|
||||
|
||||
s_logger.info("Thread " + threadNum + " acquiring lock");
|
||||
AsyncJobVO job = dao.acquire(1L, 30);
|
||||
if(job != null) {
|
||||
s_logger.info("Thread " + threadNum + " acquired lock");
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(Log4jEnabledTestCase.getRandomMilliseconds(1000, 3000));
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
|
||||
s_logger.info("Thread " + threadNum + " acquiring lock nestly");
|
||||
AsyncJobVO job2 = dao.acquire(1L, 30);
|
||||
if(job2 != null) {
|
||||
s_logger.info("Thread " + threadNum + " acquired lock nestly");
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(Log4jEnabledTestCase.getRandomMilliseconds(1000, 3000));
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
|
||||
s_logger.info("Thread " + threadNum + " releasing lock (nestly acquired)");
|
||||
dao.release(1L);
|
||||
s_logger.info("Thread " + threadNum + " released lock (nestly acquired)");
|
||||
|
||||
|
||||
} else {
|
||||
s_logger.info("Thread " + threadNum + " was unable to acquire lock nestly");
|
||||
}
|
||||
|
||||
|
||||
s_logger.info("Thread " + threadNum + " releasing lock");
|
||||
dao.release(1L);
|
||||
s_logger.info("Thread " + threadNum + " released lock");
|
||||
@ -183,7 +178,7 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
} finally {
|
||||
txn.close();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
Thread.sleep(Log4jEnabledTestCase.getRandomMilliseconds(1000, 10000));
|
||||
} catch (InterruptedException e) {
|
||||
@ -192,11 +187,11 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < threadCount; i++) {
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
|
||||
for(int i = 0; i < threadCount; i++) {
|
||||
try {
|
||||
threads[i].join();
|
||||
@ -204,88 +199,83 @@ public class TestAsync extends Log4jEnabledTestCase {
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public void testMaid() {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
StackMaidDao dao = new StackMaidDaoImpl();
|
||||
dao.pushCleanupDelegate(1L, 0, "delegate1", "Hello, world");
|
||||
dao.pushCleanupDelegate(1L, 1, "delegate2", new Long(100));
|
||||
dao.pushCleanupDelegate(1L, 2, "delegate3", null);
|
||||
|
||||
CheckPointVO item = dao.popCleanupDelegate(1L);
|
||||
Assert.assertTrue(item.getDelegate().equals("delegate3"));
|
||||
Assert.assertTrue(item.getContext() == null);
|
||||
|
||||
item = dao.popCleanupDelegate(1L);
|
||||
Assert.assertTrue(item.getDelegate().equals("delegate2"));
|
||||
s_logger.info(item.getContext());
|
||||
*/
|
||||
|
||||
item = dao.popCleanupDelegate(1L);
|
||||
Assert.assertTrue(item.getDelegate().equals("delegate1"));
|
||||
s_logger.info(item.getContext());
|
||||
|
||||
txn.close();
|
||||
}
|
||||
|
||||
public void testMaidClear() {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
StackMaidDao dao = new StackMaidDaoImpl();
|
||||
dao.pushCleanupDelegate(1L, 0, "delegate1", "Hello, world");
|
||||
dao.pushCleanupDelegate(1L, 1, "delegate2", new Long(100));
|
||||
dao.pushCleanupDelegate(1L, 2, "delegate3", null);
|
||||
|
||||
dao.clearStack(1L);
|
||||
Assert.assertTrue(dao.popCleanupDelegate(1L) == null);
|
||||
txn.close();
|
||||
}
|
||||
|
||||
public void testMaidExitCleanup() {
|
||||
StackMaid.current().push(1L, "com.cloud.async.CleanupDelegate", "Hello, world1");
|
||||
StackMaid.current().push(1L, "com.cloud.async.CleanupDelegate", "Hello, world2");
|
||||
|
||||
StackMaid.current().exitCleanup(1L);
|
||||
}
|
||||
|
||||
public void testMaidLeftovers() {
|
||||
public void testMaid() {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
Thread[] threads = new Thread[3];
|
||||
for(int i = 0; i < 3; i++) {
|
||||
final int threadNum = i+1;
|
||||
threads[i] = new Thread(new Runnable() {
|
||||
public void run() {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
StackMaidDao dao = new StackMaidDaoImpl();
|
||||
dao.pushCleanupDelegate(1L, 0, "delegate-" + threadNum, "Hello, world");
|
||||
dao.pushCleanupDelegate(1L, 1, "delegate-" + threadNum, new Long(100));
|
||||
dao.pushCleanupDelegate(1L, 2, "delegate-" + threadNum, null);
|
||||
|
||||
txn.close();
|
||||
}
|
||||
});
|
||||
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
try {
|
||||
threads[i].join();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
StackMaidDao dao = new StackMaidDaoImpl();
|
||||
dao.pushCleanupDelegate(1L, 0, "delegate1", "Hello, world");
|
||||
dao.pushCleanupDelegate(1L, 1, "delegate2", new Long(100));
|
||||
dao.pushCleanupDelegate(1L, 2, "delegate3", null);
|
||||
|
||||
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
StackMaidDao dao = new StackMaidDaoImpl();
|
||||
List<CheckPointVO> l = dao.listLeftoversByMsid(1L);
|
||||
for(CheckPointVO maid : l) {
|
||||
s_logger.info("" + maid.getThreadId() + " " + maid.getDelegate() + " " + maid.getContext());
|
||||
}
|
||||
|
||||
txn.close();
|
||||
}
|
||||
CheckPointVO item = dao.popCleanupDelegate(1L);
|
||||
Assert.assertTrue(item.getDelegate().equals("delegate3"));
|
||||
Assert.assertTrue(item.getContext() == null);
|
||||
|
||||
item = dao.popCleanupDelegate(1L);
|
||||
Assert.assertTrue(item.getDelegate().equals("delegate2"));
|
||||
s_logger.info(item.getContext());
|
||||
|
||||
item = dao.popCleanupDelegate(1L);
|
||||
Assert.assertTrue(item.getDelegate().equals("delegate1"));
|
||||
s_logger.info(item.getContext());
|
||||
|
||||
txn.close();
|
||||
}
|
||||
|
||||
public void testMaidClear() {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
StackMaidDao dao = new StackMaidDaoImpl();
|
||||
dao.pushCleanupDelegate(1L, 0, "delegate1", "Hello, world");
|
||||
dao.pushCleanupDelegate(1L, 1, "delegate2", new Long(100));
|
||||
dao.pushCleanupDelegate(1L, 2, "delegate3", null);
|
||||
|
||||
dao.clearStack(1L);
|
||||
Assert.assertTrue(dao.popCleanupDelegate(1L) == null);
|
||||
txn.close();
|
||||
}
|
||||
|
||||
|
||||
public void testMaidLeftovers() {
|
||||
|
||||
Thread[] threads = new Thread[3];
|
||||
for(int i = 0; i < 3; i++) {
|
||||
final int threadNum = i+1;
|
||||
threads[i] = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
StackMaidDao dao = new StackMaidDaoImpl();
|
||||
dao.pushCleanupDelegate(1L, 0, "delegate-" + threadNum, "Hello, world");
|
||||
dao.pushCleanupDelegate(1L, 1, "delegate-" + threadNum, new Long(100));
|
||||
dao.pushCleanupDelegate(1L, 2, "delegate-" + threadNum, null);
|
||||
|
||||
txn.close();
|
||||
}
|
||||
});
|
||||
|
||||
threads[i].start();
|
||||
}
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
try {
|
||||
threads[i].join();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Transaction txn = Transaction.open(Transaction.CLOUD_DB);
|
||||
|
||||
StackMaidDao dao = new StackMaidDaoImpl();
|
||||
List<CheckPointVO> l = dao.listLeftoversByMsid(1L);
|
||||
for(CheckPointVO maid : l) {
|
||||
s_logger.info("" + maid.getThreadId() + " " + maid.getDelegate() + " " + maid.getContext());
|
||||
}
|
||||
|
||||
txn.close();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user