use of com.cloud.vm.ConsoleProxyVO in project cosmic by MissionCriticalCloud.
the class ConsoleProxyAlertAdapter method onProxyAlert.
public void onProxyAlert(final Object sender, final ConsoleProxyAlertEventArgs args) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("received console proxy alert");
}
final Zone zone = zoneRepository.findOne(args.getZoneId());
ConsoleProxyVO proxy = args.getProxy();
// FIXME - Proxy can be null in case of creation failure. Have a better fix than checking for != 0
if (proxy == null && args.getProxyId() != 0) {
proxy = _consoleProxyDao.findById(args.getProxyId());
}
if (proxy == null && args.getType() != ConsoleProxyAlertEventArgs.PROXY_CREATE_FAILURE) {
throw new CloudRuntimeException("Invalid alert arguments, proxy must be set");
}
switch(args.getType()) {
case ConsoleProxyAlertEventArgs.PROXY_CREATED:
if (s_logger.isDebugEnabled()) {
s_logger.debug("New console proxy created, zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + proxy.getPrivateIpAddress());
}
break;
case ConsoleProxyAlertEventArgs.PROXY_UP:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy is up, zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + proxy.getPrivateIpAddress());
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY, args.getZoneId(), proxy.getPodIdToDeployIn(), "Console proxy up in zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()), "Console proxy up (zone " + zone.getName() + ")");
break;
case ConsoleProxyAlertEventArgs.PROXY_DOWN:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy is down, zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()));
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY, args.getZoneId(), proxy.getPodIdToDeployIn(), "Console proxy down in zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()), "Console proxy down (zone " + zone.getName() + ")");
break;
case ConsoleProxyAlertEventArgs.PROXY_REBOOTED:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy is rebooted, zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()));
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY, args.getZoneId(), proxy.getPodIdToDeployIn(), "Console proxy rebooted in zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()), "Console proxy rebooted (zone " + zone.getName() + ")");
break;
case ConsoleProxyAlertEventArgs.PROXY_CREATE_FAILURE:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy creation failure, zone: " + zone.getName());
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY, args.getZoneId(), null, "Console proxy creation failure. zone: " + zone.getName() + ", error details: " + args.getMessage(), "Console proxy creation failure (zone " + zone.getName() + ")");
break;
case ConsoleProxyAlertEventArgs.PROXY_START_FAILURE:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy startup failure, zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()));
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY, args.getZoneId(), proxy.getPodIdToDeployIn(), "Console proxy startup failure. zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()) + ", error details: " + args.getMessage(), "Console proxy startup failure (zone " + zone.getName() + ")");
break;
case ConsoleProxyAlertEventArgs.PROXY_FIREWALL_ALERT:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy firewall alert, zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()));
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY, args.getZoneId(), proxy.getPodIdToDeployIn(), "Failed to open console proxy firewall port. zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + (proxy.getPrivateIpAddress() == null ? "N/A" : proxy.getPrivateIpAddress()), "Console proxy alert (zone " + zone.getName() + ")");
break;
case ConsoleProxyAlertEventArgs.PROXY_STORAGE_ALERT:
if (s_logger.isDebugEnabled()) {
s_logger.debug("Console proxy storage alert, zone: " + zone.getName() + ", proxy: " + proxy.getHostName() + ", public IP: " + proxy.getPublicIpAddress() + ", private IP: " + proxy.getPrivateIpAddress() + ", message: " + args.getMessage());
}
_alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_STORAGE_MISC, args.getZoneId(), proxy.getPodIdToDeployIn(), "Console proxy storage issue. zone: " + zone.getName() + ", message: " + args.getMessage(), "Console proxy alert (zone " + zone.getName() + ")");
break;
}
}
use of com.cloud.vm.ConsoleProxyVO in project cosmic by MissionCriticalCloud.
the class ConsoleProxyDaoImpl method remove.
@Override
public boolean remove(final Long id) {
final TransactionLegacy txn = TransactionLegacy.currentTxn();
txn.start();
final ConsoleProxyVO proxy = createForUpdate();
proxy.setPublicIpAddress(null);
proxy.setPrivateIpAddress(null);
final UpdateBuilder ub = getUpdateBuilder(proxy);
ub.set(proxy, "state", State.Destroyed);
ub.set(proxy, "privateIpAddress", null);
update(id, ub, proxy);
final boolean result = super.remove(id);
txn.commit();
return result;
}
use of com.cloud.vm.ConsoleProxyVO in project cosmic by MissionCriticalCloud.
the class ConsoleProxyDaoImpl method update.
@Override
public void update(final long id, final int activeSession, final Date updateTime, final byte[] sessionDetails) {
final ConsoleProxyVO ub = createForUpdate();
ub.setActiveSession(activeSession);
ub.setLastUpdateTime(updateTime);
ub.setSessionDetails(sessionDetails);
update(id, ub);
}
use of com.cloud.vm.ConsoleProxyVO in project cosmic by MissionCriticalCloud.
the class StoragePoolAutomationImpl method maintain.
@Override
public boolean maintain(final DataStore store) {
final Long userId = CallContext.current().getCallingUserId();
final User user = _userDao.findById(userId);
final Account account = CallContext.current().getCallingAccount();
final StoragePoolVO pool = primaryDataStoreDao.findById(store.getId());
try {
List<StoragePoolVO> spes = null;
// if the storage is ZONE wide then we pass podid and cluster id as null as they will be empty for ZWPS
if (pool.getScope() == ScopeType.ZONE) {
spes = primaryDataStoreDao.listBy(pool.getDataCenterId(), null, null, ScopeType.ZONE);
} else {
spes = primaryDataStoreDao.listBy(pool.getDataCenterId(), pool.getPodId(), pool.getClusterId(), ScopeType.CLUSTER);
}
for (final StoragePoolVO sp : spes) {
if (sp.getStatus() == StoragePoolStatus.PrepareForMaintenance) {
throw new CloudRuntimeException("Only one storage pool in a cluster can be in PrepareForMaintenance mode, " + sp.getId() + " is already in PrepareForMaintenance mode ");
}
}
final StoragePool storagePool = (StoragePool) store;
// Handeling the Zone wide and cluster wide primay storage
List<HostVO> hosts = new ArrayList<>();
// TODO: if it's zone wide, this code will list a lot of hosts in the zone, which may cause performance/OOM issue.
if (pool.getScope().equals(ScopeType.ZONE)) {
if (HypervisorType.Any.equals(pool.getHypervisor())) {
hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZone(pool.getDataCenterId());
} else {
hosts = _resourceMgr.listAllUpAndEnabledHostsInOneZoneByHypervisor(pool.getHypervisor(), pool.getDataCenterId());
}
} else {
hosts = _resourceMgr.listHostsInClusterByStatus(pool.getClusterId(), Status.Up);
}
if (hosts == null || hosts.size() == 0) {
pool.setStatus(StoragePoolStatus.Maintenance);
primaryDataStoreDao.update(pool.getId(), pool);
return true;
} else {
// set the pool state to prepare for maintenance
pool.setStatus(StoragePoolStatus.PrepareForMaintenance);
primaryDataStoreDao.update(pool.getId(), pool);
}
// remove heartbeat
for (final HostVO host : hosts) {
final ModifyStoragePoolCommand cmd = new ModifyStoragePoolCommand(false, storagePool);
final Answer answer = agentMgr.easySend(host.getId(), cmd);
if (answer == null || !answer.getResult()) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("ModifyStoragePool false failed due to " + ((answer == null) ? "answer null" : answer.getDetails()));
}
} else {
if (s_logger.isDebugEnabled()) {
s_logger.debug("ModifyStoragePool false succeeded");
}
}
}
// check to see if other ps exist
// if they do, then we can migrate over the system vms to them
// if they dont, then just stop all vms on this one
final List<StoragePoolVO> upPools = primaryDataStoreDao.listByStatusInZone(pool.getDataCenterId(), StoragePoolStatus.Up);
boolean restart = true;
if (upPools == null || upPools.size() == 0) {
restart = false;
}
// 2. Get a list of all the ROOT volumes within this storage pool
final List<VolumeVO> allVolumes = volumeDao.findByPoolId(pool.getId());
// 3. Enqueue to the work queue
for (final VolumeVO volume : allVolumes) {
final VMInstanceVO vmInstance = vmDao.findById(volume.getInstanceId());
if (vmInstance == null) {
continue;
}
// enqueue sp work
if (vmInstance.getState().equals(State.Running) || vmInstance.getState().equals(State.Starting) || vmInstance.getState().equals(State.Stopping)) {
try {
final StoragePoolWorkVO work = new StoragePoolWorkVO(vmInstance.getId(), pool.getId(), false, false, server.getId());
_storagePoolWorkDao.persist(work);
} catch (final Exception e) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Work record already exists, re-using by re-setting values");
}
final StoragePoolWorkVO work = _storagePoolWorkDao.findByPoolIdAndVmId(pool.getId(), vmInstance.getId());
work.setStartedAfterMaintenance(false);
work.setStoppedForMaintenance(false);
work.setManagementServerId(server.getId());
_storagePoolWorkDao.update(work.getId(), work);
}
}
}
// 4. Process the queue
final List<StoragePoolWorkVO> pendingWork = _storagePoolWorkDao.listPendingWorkForPrepareForMaintenanceByPoolId(pool.getId());
for (final StoragePoolWorkVO work : pendingWork) {
// shut down the running vms
final VMInstanceVO vmInstance = vmDao.findById(work.getVmId());
if (vmInstance == null) {
continue;
}
// proxy
if (vmInstance.getType().equals(VirtualMachine.Type.ConsoleProxy)) {
// call the consoleproxymanager
final ConsoleProxyVO consoleProxy = _consoleProxyDao.findById(vmInstance.getId());
vmMgr.advanceStop(consoleProxy.getUuid(), false);
// update work status
work.setStoppedForMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
if (restart) {
vmMgr.advanceStart(consoleProxy.getUuid(), null, null);
// update work status
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
}
// if the instance is of type uservm, call the user vm manager
if (vmInstance.getType() == VirtualMachine.Type.User) {
final UserVmVO userVm = userVmDao.findById(vmInstance.getId());
vmMgr.advanceStop(userVm.getUuid(), false);
// update work status
work.setStoppedForMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
// secondary storage vm manager
if (vmInstance.getType().equals(VirtualMachine.Type.SecondaryStorageVm)) {
final SecondaryStorageVmVO secStrgVm = _secStrgDao.findById(vmInstance.getId());
vmMgr.advanceStop(secStrgVm.getUuid(), false);
// update work status
work.setStoppedForMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
if (restart) {
vmMgr.advanceStart(secStrgVm.getUuid(), null, null);
// update work status
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
}
// manager
if (vmInstance.getType().equals(VirtualMachine.Type.DomainRouter)) {
final DomainRouterVO domR = _domrDao.findById(vmInstance.getId());
vmMgr.advanceStop(domR.getUuid(), false);
// update work status
work.setStoppedForMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
if (restart) {
vmMgr.advanceStart(domR.getUuid(), null, null);
// update work status
work.setStartedAfterMaintenance(true);
_storagePoolWorkDao.update(work.getId(), work);
}
}
}
} catch (final Exception e) {
s_logger.error("Exception in enabling primary storage maintenance:", e);
pool.setStatus(StoragePoolStatus.ErrorInMaintenance);
primaryDataStoreDao.update(pool.getId(), pool);
throw new CloudRuntimeException(e.getMessage());
}
return true;
}
use of com.cloud.vm.ConsoleProxyVO in project cloudstack by apache.
the class ConsoleProxyManagerImpl method destroyProxy.
@Override
public boolean destroyProxy(long vmId) {
ConsoleProxyVO proxy = consoleProxyDao.findById(vmId);
try {
virtualMachineManager.expunge(proxy.getUuid());
proxy.setPublicIpAddress(null);
proxy.setPublicMacAddress(null);
proxy.setPublicNetmask(null);
proxy.setPrivateMacAddress(null);
proxy.setPrivateIpAddress(null);
consoleProxyDao.update(proxy.getId(), proxy);
consoleProxyDao.remove(vmId);
HostVO host = hostDao.findByTypeNameAndZoneId(proxy.getDataCenterId(), proxy.getHostName(), Host.Type.ConsoleProxy);
if (host != null) {
s_logger.debug(String.format("Removing host [%s] entry for proxy [%s].", host.toString(), vmId));
return hostDao.remove(host.getId());
}
return true;
} catch (ResourceUnavailableException e) {
s_logger.warn(String.format("Unable to destroy console proxy [%s] due to [%s].", proxy, e.getMessage()), e);
return false;
}
}
Aggregations