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