Search in sources :

Example 51 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException 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 52 with OperationTimedoutException

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

the class ManagementServerImpl method stopSystemVM.

@Override
@ActionEvent(eventType = "", eventDescription = "", async = true)
public VMInstanceVO stopSystemVM(final StopSystemVmCmd cmd) throws ResourceUnavailableException, ConcurrentOperationException {
    final Long id = cmd.getId();
    // verify parameters
    final VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(id, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm);
    if (systemVm == null) {
        final InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a system vm with specified vmId");
        ex.addProxyObject(id.toString(), "vmId");
        throw ex;
    }
    try {
        if (systemVm.getType() == VirtualMachine.Type.ConsoleProxy) {
            ActionEventUtils.startNestedActionEvent(EventTypes.EVENT_PROXY_STOP, "stopping console proxy Vm");
            return stopConsoleProxy(systemVm, cmd.isForced());
        } else if (systemVm.getType() == VirtualMachine.Type.SecondaryStorageVm) {
            ActionEventUtils.startNestedActionEvent(EventTypes.EVENT_SSVM_STOP, "stopping secondary storage Vm");
            return stopSecondaryStorageVm(systemVm, cmd.isForced());
        }
        return null;
    } catch (final OperationTimedoutException e) {
        throw new CloudRuntimeException("Unable to stop " + systemVm, e);
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VMInstanceVO(com.cloud.vm.VMInstanceVO) ActionEvent(com.cloud.event.ActionEvent)

Example 53 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException 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 54 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException 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 55 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException 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

OperationTimedoutException (com.cloud.exception.OperationTimedoutException)65 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)55 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)32 Answer (com.cloud.agent.api.Answer)25 HostVO (com.cloud.host.HostVO)23 Commands (com.cloud.agent.manager.Commands)16 ArrayList (java.util.ArrayList)13 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)12 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)11 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)10 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)10 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)10 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)9 VolumeObjectTO (org.apache.cloudstack.storage.to.VolumeObjectTO)9 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)8 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)8 GuestOSVO (com.cloud.storage.GuestOSVO)8 UserVmVO (com.cloud.vm.UserVmVO)7 ClusterVMMetaDataSyncAnswer (com.cloud.agent.api.ClusterVMMetaDataSyncAnswer)6 RebootAnswer (com.cloud.agent.api.RebootAnswer)6