use of com.cloud.vm.ConsoleProxyVO in project cosmic by MissionCriticalCloud.
the class StoragePoolAutomationImpl method cancelMaintain.
@Override
public boolean cancelMaintain(final DataStore store) {
// Change the storage state back to up
final Long userId = CallContext.current().getCallingUserId();
final User user = _userDao.findById(userId);
final Account account = CallContext.current().getCallingAccount();
final StoragePoolVO poolVO = primaryDataStoreDao.findById(store.getId());
final StoragePool pool = (StoragePool) store;
// Handeling the Zone wide and cluster wide primay storage
List<HostVO> hosts = new ArrayList<>();
// if the storage scope is ZONE wide, then get all the hosts for which hypervisor ZWSP created to send Modifystoragepoolcommand
if (poolVO.getScope().equals(ScopeType.ZONE)) {
if (HypervisorType.Any.equals(pool.getHypervisor())) {
hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId());
} else {
hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(poolVO.getHypervisor(), pool.getDataCenterId());
}
} else {
hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up);
}
if (hosts == null || hosts.size() == 0) {
return true;
}
// add heartbeat
for (final HostVO host : hosts) {
final ModifyStoragePoolCommand msPoolCmd = new ModifyStoragePoolCommand(true, pool);
final Answer answer = agentMgr.easySend(host.getId(), msPoolCmd);
if (answer == null || !answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("ModifyStoragePool add failed due to " + ((answer == null) ? "answer null" : answer.getDetails()));
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("ModifyStoragePool add secceeded");
}
}
}
// 2. Get a list of pending work for this queue
final List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao.listPendingWorkForCancelMaintenanceByPoolId(poolVO.getId());
// 3. work through the queue
for (final StoragePoolWorkVO work : pendingWork) {
try {
final VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
if (vmInstance == null) {
continue;
}
// proxy
if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
final ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId());
vmMgr.advanceStart(consoleProxy.getUuid(), null, null);
// update work queue
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
// if the instance is of type ssvm, call the ssvm manager
if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
final SecondaryStorageVmVO ssVm = _secStrgDao.findById(vmInstance.getId());
vmMgr.advanceStart(ssVm.getUuid(), null, null);
// update work queue
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
// manager
if (vmInstance.getType().equals(VirtualMachine.Type.DomainRouter)) {
final DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
vmMgr.advanceStart(domR.getUuid(), null, null);
// update work queue
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
// if the instance is of type user vm, call the user vm manager
if (vmInstance.getType().equals(VirtualMachine.Type.User)) {
// don't allow to start vm that doesn't have a root volume
if (volumeDao.findByInstanceAndType(vmInstance.getId(), Volume.Type.ROOT).isEmpty()) {
_storagePoolWorkDao.remove(work.getId());
} else {
final UserVmVO userVm = userVmDao.findById(vmInstance.getId());
vmMgr.advanceStart(userVm.getUuid(), null, null);
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
}
} catch (final Exception e) {
s_logger.debug("Failed start vm", e);
throw new CloudRuntimeException(e.toString());
}
}
return false;
}
use of com.cloud.vm.ConsoleProxyVO in project cloudstack by apache.
the class ConsoleProxyDaoImpl method remove.
@Override
public boolean remove(Long id) {
TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
ConsoleProxyVO proxy = createForUpdate();
proxy.setPublicIpAddress(null);
proxy.setPrivateIpAddress(null);
UpdateBuilder ub = getUpdateBuilder(proxy);
ub.set(proxy, "state", State.Destroyed);
ub.set(proxy, "privateIpAddress", null);
update(id, ub, proxy);
boolean result = super.remove(id);
txn.commit();
return result;
}
use of com.cloud.vm.ConsoleProxyVO in project cloudstack by apache.
the class ConsoleProxyManagerImpl method startProxy.
@Override
public ConsoleProxyVO startProxy(long proxyVmId, boolean ignoreRestartSetting) {
try {
ConsoleProxyVO proxy = consoleProxyDao.findById(proxyVmId);
if (proxy.getState() == VirtualMachine.State.Running) {
return proxy;
}
String restart = configurationDao.getValue(Config.ConsoleProxyRestart.key());
if (!ignoreRestartSetting && restart != null && restart.equalsIgnoreCase("false")) {
return null;
}
if (proxy.getState() == VirtualMachine.State.Stopped) {
virtualMachineManager.advanceStart(proxy.getUuid(), null, null);
proxy = consoleProxyDao.findById(proxy.getId());
return proxy;
}
s_logger.warn(String.format("Console proxy [%s] must be in \"Stopped\" state to start proxy. Current state [%s].", proxy.toString(), proxy.getState()));
} catch (ConcurrentOperationException | InsufficientCapacityException | OperationTimedoutException | ResourceUnavailableException ex) {
s_logger.warn(String.format("Unable to start proxy [%s] due to [%s].", proxyVmId, ex.getMessage()), ex);
}
return null;
}
use of com.cloud.vm.ConsoleProxyVO in project cloudstack by apache.
the class ConsoleProxyManagerImpl method handleResetSuspending.
private void handleResetSuspending() {
List<ConsoleProxyVO> runningProxies = consoleProxyDao.getProxyListInStates(State.Running);
for (ConsoleProxyVO proxy : runningProxies) {
s_logger.info("Stop console proxy " + proxy.getId() + " because of we are currently in ResetSuspending management mode");
stopProxy(proxy.getId());
}
List<ConsoleProxyVO> proxiesInTransition = consoleProxyDao.getProxyListInStates(State.Running, State.Starting, State.Stopping);
if (CollectionUtils.isEmpty(proxiesInTransition)) {
s_logger.info("All previous console proxy VMs in transition mode ceased the mode, we will now resume to last management state");
resumeLastManagementState();
}
}
use of com.cloud.vm.ConsoleProxyVO in project cloudstack by apache.
the class ConsoleProxyManagerImpl method doAssignProxy.
public ConsoleProxyVO doAssignProxy(long dataCenterId, long vmId) {
ConsoleProxyVO proxy = null;
VMInstanceVO vm = vmInstanceDao.findById(vmId);
if (vm == null) {
s_logger.warn("VM " + vmId + " no longer exists, return a null proxy for vm:" + vmId);
return null;
}
if (!availableVmStateOnAssignProxy.contains(vm.getState())) {
if (s_logger.isInfoEnabled()) {
s_logger.info(String.format("Detected that %s is not currently in \"Starting\", \"Running\", \"Stopping\" or \"Migrating\" state, it will fail the proxy assignment.", vm.toString()));
}
return null;
}
if (allocProxyLock.lock(ACQUIRE_GLOBAL_LOCK_TIMEOUT_FOR_SYNC_IN_SECONDS)) {
try {
if (vm.getProxyId() != null) {
proxy = consoleProxyDao.findById(vm.getProxyId());
if (proxy != null) {
if (!isInAssignableState(proxy)) {
if (s_logger.isInfoEnabled()) {
s_logger.info("A previous assigned proxy is not assignable now, reassign console proxy for user vm : " + vmId);
}
proxy = null;
} else {
if (consoleProxyDao.getProxyActiveLoad(proxy.getId()) < capacityPerProxy || hasPreviousSession(proxy, vm)) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Assign previous allocated console proxy for user vm : " + vmId);
}
if (proxy.getActiveSession() >= capacityPerProxy) {
s_logger.warn("Assign overloaded proxy to user VM as previous session exists, user vm : " + vmId);
}
} else {
proxy = null;
}
}
}
}
if (proxy == null) {
proxy = assignProxyFromRunningPool(dataCenterId);
}
} finally {
allocProxyLock.unlock();
}
} else {
s_logger.error("Unable to acquire synchronization lock to get/allocate proxy resource for vm :" + vmId + ". Previous console proxy allocation is taking too long");
}
if (proxy == null) {
s_logger.warn("Unable to find or allocate console proxy resource");
return null;
}
if (vm.getProxyId() == null || vm.getProxyId() != proxy.getId()) {
vmInstanceDao.updateProxyId(vmId, proxy.getId(), DateUtil.currentGMTTime());
}
proxy.setSslEnabled(sslEnabled);
if (sslEnabled) {
proxy.setPort(443);
} else {
proxy.setPort(80);
}
return proxy;
}
Aggregations