Search in sources :

Example 56 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class VmwareStorageMotionStrategy method migrateVmWithVolumesWithinCluster.

private Answer migrateVmWithVolumesWithinCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
    // Initiate migration of a virtual machine with it's volumes.
    try {
        List<Pair<VolumeTO, StorageFilerTO>> volumeToFilerto = new ArrayList<Pair<VolumeTO, StorageFilerTO>>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
            VolumeInfo volume = entry.getKey();
            VolumeTO volumeTo = new VolumeTO(volume, storagePoolDao.findById(volume.getPoolId()));
            StorageFilerTO filerTo = new StorageFilerTO((StoragePool) entry.getValue());
            volumeToFilerto.add(new Pair<VolumeTO, StorageFilerTO>(volumeTo, filerTo));
        }
        MigrateWithStorageCommand command = new MigrateWithStorageCommand(to, volumeToFilerto, destHost.getGuid());
        MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(srcHost.getId(), command);
        if (answer == null) {
            s_logger.error("Migration with storage of vm " + vm + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!answer.getResult()) {
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + answer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost + ". " + answer.getDetails());
        } else {
            // Update the volume details after migration.
            updateVolumesAfterMigration(volumeToPool, answer.getVolumeTos());
        }
        return answer;
    } catch (OperationTimedoutException e) {
        s_logger.error("Error while migrating vm " + vm + " to host " + destHost, e);
        throw new AgentUnavailableException("Operation timed out on storage motion for " + vm, destHost.getId());
    }
}
Also used : MigrateWithStorageAnswer(com.cloud.agent.api.MigrateWithStorageAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateWithStorageCommand(com.cloud.agent.api.MigrateWithStorageCommand) ArrayList(java.util.ArrayList) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) StorageFilerTO(com.cloud.agent.api.to.StorageFilerTO) VolumeTO(com.cloud.agent.api.to.VolumeTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 57 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class VirtualMachineManagerImpl method sendStop.

protected boolean sendStop(final VirtualMachineGuru guru, final VirtualMachineProfile profile, final boolean force, final boolean checkBeforeCleanup) {
    final VirtualMachine vm = profile.getVirtualMachine();
    StopCommand stpCmd = new StopCommand(vm, getExecuteInSequence(vm.getHypervisorType()), checkBeforeCleanup);
    stpCmd.setControlIp(getControlNicIpForVM(vm));
    final StopCommand stop = stpCmd;
    try {
        Answer answer = null;
        if (vm.getHostId() != null) {
            answer = _agentMgr.send(vm.getHostId(), stop);
        }
        if (answer != null && answer instanceof StopAnswer) {
            final StopAnswer stopAns = (StopAnswer) answer;
            if (vm.getType() == VirtualMachine.Type.User) {
                final String platform = stopAns.getPlatform();
                if (platform != null) {
                    final UserVmVO userVm = _userVmDao.findById(vm.getId());
                    _userVmDao.loadDetails(userVm);
                    userVm.setDetail("platform", platform);
                    _userVmDao.saveDetails(userVm);
                }
            }
            final GPUDeviceTO gpuDevice = stop.getGpuDevice();
            if (gpuDevice != null) {
                _resourceMgr.updateGPUDetails(vm.getHostId(), gpuDevice.getGroupDetails());
            }
            if (!answer.getResult()) {
                final String details = answer.getDetails();
                s_logger.debug("Unable to stop VM due to " + details);
                return false;
            }
            guru.finalizeStop(profile, answer);
        } else {
            s_logger.error("Invalid answer received in response to a StopCommand for " + vm.getInstanceName());
            return false;
        }
    } catch (final AgentUnavailableException e) {
        if (!force) {
            return false;
        }
    } catch (final OperationTimedoutException e) {
        if (!force) {
            return false;
        }
    }
    return true;
}
Also used : AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) StopCommand(com.cloud.agent.api.StopCommand) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) GPUDeviceTO(com.cloud.agent.api.to.GPUDeviceTO) StopAnswer(com.cloud.agent.api.StopAnswer)

Example 58 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class VirtualMachineManagerImpl method processConnect.

@Override
public void processConnect(final Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Received startup command from hypervisor host. host id: " + agent.getId());
    }
    _syncMgr.resetHostSyncState(agent.getId());
    if (forRebalance) {
        s_logger.debug("Not processing listener " + this + " as connect happens on rebalance process");
        return;
    }
    final Long clusterId = agent.getClusterId();
    final long agentId = agent.getId();
    if (agent.getHypervisorType() == HypervisorType.XenServer) {
        // only for Xen
        // initiate the cron job
        final ClusterVMMetaDataSyncCommand syncVMMetaDataCmd = new ClusterVMMetaDataSyncCommand(ClusterVMMetaDataSyncInterval.value(), clusterId);
        try {
            final long seq_no = _agentMgr.send(agentId, new Commands(syncVMMetaDataCmd), this);
            s_logger.debug("Cluster VM metadata sync started with jobid " + seq_no);
        } catch (final AgentUnavailableException e) {
            s_logger.fatal("The Cluster VM metadata sync process failed for cluster id " + clusterId + " with ", e);
        }
    }
}
Also used : ClusterVMMetaDataSyncCommand(com.cloud.agent.api.ClusterVMMetaDataSyncCommand) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand)

Example 59 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class VirtualMachineManagerImpl method orchestrateStorageMigration.

private void orchestrateStorageMigration(final String vmUuid, final StoragePool destPool) {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (destPool == null) {
        throw new CloudRuntimeException("Unable to migrate vm: missing destination storage pool");
    }
    try {
        stateTransitTo(vm, VirtualMachine.Event.StorageMigrationRequested, null);
    } catch (final NoTransitionException e) {
        s_logger.debug("Unable to migrate vm: " + e.toString());
        throw new CloudRuntimeException("Unable to migrate vm: " + e.toString());
    }
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm);
    boolean migrationResult = false;
    try {
        migrationResult = volumeMgr.storageMigration(profile, destPool);
        if (migrationResult) {
            if (destPool.getPodId() != null && !destPool.getPodId().equals(vm.getPodIdToDeployIn())) {
                final DataCenterDeployment plan = new DataCenterDeployment(vm.getDataCenterId(), destPool.getPodId(), null, null, null, null);
                final VirtualMachineProfileImpl vmProfile = new VirtualMachineProfileImpl(vm, null, null, null, null);
                _networkMgr.reallocate(vmProfile, plan);
            }
            //when start the vm next time, don;'t look at last_host_id, only choose the host based on volume/storage pool
            vm.setLastHostId(null);
            vm.setPodIdToDeployIn(destPool.getPodId());
            // unregister the VM from the source host and cleanup the associated VM files.
            if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
                Long srcClusterId = null;
                Long srcHostId = vm.getHostId() != null ? vm.getHostId() : vm.getLastHostId();
                if (srcHostId != null) {
                    HostVO srcHost = _hostDao.findById(srcHostId);
                    srcClusterId = srcHost.getClusterId();
                }
                final Long destClusterId = destPool.getClusterId();
                if (srcClusterId != null && destClusterId != null && !srcClusterId.equals(destClusterId)) {
                    final String srcDcName = _clusterDetailsDao.getVmwareDcName(srcClusterId);
                    final String destDcName = _clusterDetailsDao.getVmwareDcName(destClusterId);
                    if (srcDcName != null && destDcName != null && !srcDcName.equals(destDcName)) {
                        s_logger.debug("Since VM's storage was successfully migrated across VMware Datacenters, unregistering VM: " + vm.getInstanceName() + " from source host: " + srcHostId);
                        final UnregisterVMCommand uvc = new UnregisterVMCommand(vm.getInstanceName());
                        uvc.setCleanupVmFiles(true);
                        try {
                            _agentMgr.send(srcHostId, uvc);
                        } catch (final AgentUnavailableException | OperationTimedoutException e) {
                            throw new CloudRuntimeException("Failed to unregister VM: " + vm.getInstanceName() + " from source host: " + srcHostId + " after successfully migrating VM's storage across VMware Datacenters");
                        }
                    }
                }
            }
        } else {
            s_logger.debug("Storage migration failed");
        }
    } catch (final ConcurrentOperationException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientVirtualNetworkCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientAddressCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final InsufficientCapacityException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } catch (final StorageUnavailableException e) {
        s_logger.debug("Failed to migration: " + e.toString());
        throw new CloudRuntimeException("Failed to migration: " + e.toString());
    } finally {
        try {
            stateTransitTo(vm, VirtualMachine.Event.AgentReportStopped, null);
        } catch (final NoTransitionException e) {
            s_logger.debug("Failed to change vm state: " + e.toString());
            throw new CloudRuntimeException("Failed to change vm state: " + e.toString());
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientAddressCapacityException(com.cloud.exception.InsufficientAddressCapacityException) UnregisterVMCommand(com.cloud.agent.api.UnregisterVMCommand) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) HostVO(com.cloud.host.HostVO) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) InsufficientVirtualNetworkCapacityException(com.cloud.exception.InsufficientVirtualNetworkCapacityException) InsufficientCapacityException(com.cloud.exception.InsufficientCapacityException)

Example 60 with AgentUnavailableException

use of com.cloud.exception.AgentUnavailableException in project cloudstack by apache.

the class VirtualMachineManagerImpl method orchestrateReConfigureVm.

private VMInstanceVO orchestrateReConfigureVm(final String vmUuid, final ServiceOffering oldServiceOffering, final boolean reconfiguringOnExistingHost) throws ResourceUnavailableException, ConcurrentOperationException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    final long newServiceofferingId = vm.getServiceOfferingId();
    final ServiceOffering newServiceOffering = _offeringDao.findById(vm.getId(), newServiceofferingId);
    final HostVO hostVo = _hostDao.findById(vm.getHostId());
    final Float memoryOvercommitRatio = CapacityManager.MemOverprovisioningFactor.valueIn(hostVo.getClusterId());
    final Float cpuOvercommitRatio = CapacityManager.CpuOverprovisioningFactor.valueIn(hostVo.getClusterId());
    final long minMemory = (long) (newServiceOffering.getRamSize() / memoryOvercommitRatio);
    final ScaleVmCommand reconfigureCmd = new ScaleVmCommand(vm.getInstanceName(), newServiceOffering.getCpu(), (int) (newServiceOffering.getSpeed() / cpuOvercommitRatio), newServiceOffering.getSpeed(), minMemory * 1024L * 1024L, newServiceOffering.getRamSize() * 1024L * 1024L, newServiceOffering.getLimitCpuUse());
    final Long dstHostId = vm.getHostId();
    if (vm.getHypervisorType().equals(HypervisorType.VMware)) {
        final HypervisorGuru hvGuru = _hvGuruMgr.getGuru(vm.getHypervisorType());
        Map<String, String> details = null;
        details = hvGuru.getClusterSettings(vm.getId());
        reconfigureCmd.getVirtualMachine().setDetails(details);
    }
    final ItWorkVO work = new ItWorkVO(UUID.randomUUID().toString(), _nodeId, State.Running, vm.getType(), vm.getId());
    work.setStep(Step.Prepare);
    work.setResourceType(ItWorkVO.ResourceType.Host);
    work.setResourceId(vm.getHostId());
    _workDao.persist(work);
    boolean success = false;
    try {
        if (reconfiguringOnExistingHost) {
            vm.setServiceOfferingId(oldServiceOffering.getId());
            //release the old capacity
            _capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId());
            vm.setServiceOfferingId(newServiceofferingId);
            // lock the new capacity
            _capacityMgr.allocateVmCapacity(vm, false);
        }
        final Answer reconfigureAnswer = _agentMgr.send(vm.getHostId(), reconfigureCmd);
        if (reconfigureAnswer == null || !reconfigureAnswer.getResult()) {
            s_logger.error("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
            throw new CloudRuntimeException("Unable to scale vm due to " + (reconfigureAnswer == null ? "" : reconfigureAnswer.getDetails()));
        }
        success = true;
    } catch (final OperationTimedoutException e) {
        throw new AgentUnavailableException("Operation timed out on reconfiguring " + vm, dstHostId);
    } catch (final AgentUnavailableException e) {
        throw e;
    } finally {
        if (!success) {
            // release the new capacity
            _capacityMgr.releaseVmCapacity(vm, false, false, vm.getHostId());
            vm.setServiceOfferingId(oldServiceOffering.getId());
            // allocate the old capacity
            _capacityMgr.allocateVmCapacity(vm, false);
        }
    }
    return vm;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ServiceOffering(com.cloud.offering.ServiceOffering) HostVO(com.cloud.host.HostVO) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) PlugNicAnswer(com.cloud.agent.api.PlugNicAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) UnPlugNicAnswer(com.cloud.agent.api.UnPlugNicAnswer) ClusterVMMetaDataSyncAnswer(com.cloud.agent.api.ClusterVMMetaDataSyncAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) HypervisorGuru(com.cloud.hypervisor.HypervisorGuru) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ScaleVmCommand(com.cloud.agent.api.ScaleVmCommand)

Aggregations

AgentUnavailableException (com.cloud.exception.AgentUnavailableException)74 OperationTimedoutException (com.cloud.exception.OperationTimedoutException)56 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)30 Answer (com.cloud.agent.api.Answer)27 HostVO (com.cloud.host.HostVO)25 Commands (com.cloud.agent.manager.Commands)21 ArrayList (java.util.ArrayList)15 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)11 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 Command (com.cloud.agent.api.Command)9 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)9 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 StartupRoutingCommand (com.cloud.agent.api.StartupRoutingCommand)8 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)8 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)8 GuestOSVO (com.cloud.storage.GuestOSVO)8 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)7 FenceCommand (com.cloud.agent.api.FenceCommand)6 VMSnapshotTO (com.cloud.agent.api.VMSnapshotTO)6 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)6