Search in sources :

Example 81 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method orchestrateReboot.

private void orchestrateReboot(final String vmUuid, final Map<VirtualMachineProfile.Param, Object> params) throws InsufficientCapacityException, ConcurrentOperationException, ResourceUnavailableException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    // if there are active vm snapshots task, state change is not allowed
    if (_vmSnapshotMgr.hasActiveVMSnapshotTasks(vm.getId())) {
        s_logger.error("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
        throw new CloudRuntimeException("Unable to reboot VM " + vm + " due to: " + vm.getInstanceName() + " has active VM snapshots tasks");
    }
    final Zone zone = _zoneRepository.findOne(vm.getDataCenterId());
    final Host host = _hostDao.findById(vm.getHostId());
    if (host == null) {
        // Should findById throw an Exception is the host is not found?
        throw new CloudRuntimeException("Unable to retrieve host with id " + vm.getHostId());
    }
    final Cluster cluster = _entityMgr.findById(Cluster.class, host.getClusterId());
    final Pod pod = _entityMgr.findById(Pod.class, host.getPodId());
    final DeployDestination dest = new DeployDestination(zone, pod, cluster, host);
    try {
        final Commands cmds = new Commands(Command.OnError.Stop);
        cmds.addCommand(new RebootCommand(vm.getInstanceName(), getExecuteInSequence(vm.getHypervisorType())));
        _agentMgr.send(host.getId(), cmds);
        final Answer rebootAnswer = cmds.getAnswer(RebootAnswer.class);
        if (rebootAnswer != null && rebootAnswer.getResult()) {
            return;
        }
        s_logger.info("Unable to reboot VM " + vm + " on " + dest.getHost() + " due to " + (rebootAnswer == null ? " no reboot answer" : rebootAnswer.getDetails()));
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Unable to send the reboot command to host " + dest.getHost() + " for the vm " + vm + " due to operation timeout", e);
        throw new CloudRuntimeException("Failed to reboot the vm on host " + dest.getHost());
    }
}
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) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) RebootCommand(com.cloud.agent.api.RebootCommand) Pod(com.cloud.dc.Pod) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Zone(com.cloud.db.model.Zone) TimeZone(java.util.TimeZone) DeployDestination(com.cloud.deploy.DeployDestination) Commands(com.cloud.agent.manager.Commands) Cluster(com.cloud.org.Cluster) Host(com.cloud.host.Host)

Example 82 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.

the class VirtualMachineManagerImpl method orchestrateMigrateAway.

private void orchestrateMigrateAway(final String vmUuid, final long srcHostId, final DeploymentPlanner planner) throws InsufficientServerCapacityException {
    final VMInstanceVO vm = _vmDao.findByUuid(vmUuid);
    if (vm == null) {
        s_logger.debug("Unable to find a VM for " + vmUuid);
        throw new CloudRuntimeException("Unable to find " + vmUuid);
    }
    final ServiceOfferingVO offeringVO = _offeringDao.findById(vm.getId(), vm.getServiceOfferingId());
    final VirtualMachineProfile profile = new VirtualMachineProfileImpl(vm, null, offeringVO, null, null);
    final Long hostId = vm.getHostId();
    if (hostId == null) {
        s_logger.debug("Unable to migrate because the VM doesn't have a host id: " + vm);
        throw new CloudRuntimeException("Unable to migrate " + vmUuid);
    }
    final Host host = _hostDao.findById(hostId);
    Long poolId = null;
    final List<VolumeVO> vols = _volsDao.findReadyRootVolumesByInstance(vm.getId());
    for (final VolumeVO rootVolumeOfVm : vols) {
        final StoragePoolVO rootDiskPool = _storagePoolDao.findById(rootVolumeOfVm.getPoolId());
        if (rootDiskPool != null) {
            poolId = rootDiskPool.getId();
        }
    }
    final DataCenterDeployment plan = new DataCenterDeployment(host.getDataCenterId(), host.getPodId(), host.getClusterId(), null, poolId, null);
    final ExcludeList excludes = new ExcludeList();
    excludes.addHost(hostId);
    DeployDestination dest = null;
    while (true) {
        try {
            dest = _dpMgr.planDeployment(profile, plan, excludes, planner);
        } catch (final AffinityConflictException e2) {
            s_logger.warn("Unable to create deployment, affinity rules associted to the VM conflict", e2);
            throw new CloudRuntimeException("Unable to create deployment, affinity rules associted to the VM conflict");
        }
        if (dest != null) {
            s_logger.debug("Found destination " + dest + " for migrating to.");
        } else {
            s_logger.debug("Unable to find destination for migrating the vm " + profile);
            throw new InsufficientServerCapacityException("Unable to find a server to migrate to.", host.getClusterId());
        }
        excludes.addHost(dest.getHost().getId());
        try {
            migrate(vm, srcHostId, dest);
            return;
        } catch (final ResourceUnavailableException e) {
            s_logger.debug("Unable to migrate to unavailable " + dest);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("Unable to migrate VM due to: " + e.getMessage());
        }
        try {
            advanceStop(vmUuid, true);
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ResourceUnavailableException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final ConcurrentOperationException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        } catch (final OperationTimedoutException e) {
            s_logger.debug("Unable to stop VM due to " + e.getMessage());
            throw new CloudRuntimeException("Unable to migrate " + vm);
        }
    }
}
Also used : ExcludeList(com.cloud.deploy.DeploymentPlanner.ExcludeList) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) DataCenterDeployment(com.cloud.deploy.DataCenterDeployment) InsufficientServerCapacityException(com.cloud.exception.InsufficientServerCapacityException) Host(com.cloud.host.Host) AffinityConflictException(com.cloud.exception.AffinityConflictException) ServiceOfferingVO(com.cloud.service.ServiceOfferingVO) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException) VolumeVO(com.cloud.storage.VolumeVO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) DeployDestination(com.cloud.deploy.DeployDestination) StoragePoolVO(com.cloud.storage.datastore.db.StoragePoolVO) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 83 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.

the class KVMStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.

@Override
protected Answer migrateVmWithVolumesAcrossCluster(final VMInstanceVO instanceTo, final VirtualMachineTO vmTo, final Host srcHost, final Host destHost, final Map<VolumeInfo, DataStore> volumeToPoolMap) throws AgentUnavailableException {
    try {
        final List<Pair<VolumeTO, StorageFilerTO>> volumeMapping = buildVolumeMapping(volumeToPoolMap);
        final MigrateWithStorageAcrossClustersCommand command = new MigrateWithStorageAcrossClustersCommand(vmTo, volumeMapping, destHost.getPrivateIpAddress());
        final MigrateWithStorageAcrossClustersAnswer answer = (MigrateWithStorageAcrossClustersAnswer) agentMgr.send(srcHost.getId(), command);
        if (answer == null) {
            final String errorMessage = String.format("Error when trying to migrate VM %s (with storage) to host %s", instanceTo, destHost);
            s_logger.error(errorMessage);
            throw new CloudRuntimeException(errorMessage);
        } else if (!answer.getResult()) {
            final String errorMessage = String.format("Error when trying to migrate VM %s (with storage) to host %s => Details: %s", instanceTo, destHost, answer.getDetails());
            s_logger.error(errorMessage);
            throw new CloudRuntimeException(errorMessage);
        } else {
            // Update the volume details after migration.
            updateVolumePathsAfterMigration(volumeToPoolMap, answer.getVolumes());
        }
        return answer;
    } catch (final OperationTimedoutException e) {
        final String errorMessage = String.format("Operation timed out when attempting to migrate VM %s to host %s", instanceTo, destHost);
        s_logger.error(errorMessage, e);
        throw new AgentUnavailableException(errorMessage, srcHost.getId());
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) MigrateWithStorageAcrossClustersAnswer(com.cloud.agent.api.MigrateWithStorageAcrossClustersAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) MigrateWithStorageAcrossClustersCommand(com.cloud.agent.api.MigrateWithStorageAcrossClustersCommand) Pair(com.cloud.utils.Pair)

Example 84 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.

the class XcpServerDiscoverer method processConnect.

@Override
public void processConnect(final com.cloud.host.Host agent, final StartupCommand cmd, final boolean forRebalance) throws ConnectionException {
    if (!(cmd instanceof StartupRoutingCommand)) {
        return;
    }
    final long agentId = agent.getId();
    final StartupRoutingCommand startup = (StartupRoutingCommand) cmd;
    if (startup.getHypervisorType() != HypervisorType.XenServer) {
        s_logger.debug("Not XenServer so moving on.");
        return;
    }
    final HostVO host = _hostDao.findById(agentId);
    final ClusterVO cluster = _clusterDao.findById(host.getClusterId());
    if (cluster.getGuid() == null) {
        cluster.setGuid(startup.getPool());
        _clusterDao.update(cluster.getId(), cluster);
    } else if (!cluster.getGuid().equals(startup.getPool())) {
        final String msg = "pool uuid for cluster " + cluster.getId() + " changed from " + cluster.getGuid() + " to " + startup.getPool();
        s_logger.warn(msg);
        throw new CloudRuntimeException(msg);
    }
    final Map<String, String> details = startup.getHostDetails();
    final String prodBrand = details.get("product_brand").trim();
    final String prodVersion = details.get("product_version").trim();
    final String hotfix = details.get(XenserverConfigs.XS620HotFix);
    final String prodVersionTextShort = details.get("product_version_text_short");
    final String resource = createServerResource(prodBrand, prodVersion, prodVersionTextShort, hotfix).getClass().getName();
    if (!resource.equals(host.getResource())) {
        final String msg = "host " + host.getPrivateIpAddress() + " changed from " + host.getResource() + " to " + resource;
        s_logger.debug(msg);
        host.setResource(resource);
        host.setSetup(false);
        _hostDao.update(agentId, host);
        throw new HypervisorVersionChangedException(msg);
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Setting up host " + agentId);
    }
    final HostEnvironment env = new HostEnvironment();
    final SetupCommand setup = new SetupCommand(env);
    if (_setupMultipath) {
        setup.setMultipathOn();
    }
    if (!host.isSetup()) {
        setup.setNeedSetup(true);
    }
    try {
        final Answer answer = _agentMgr.send(agentId, setup);
        if (answer != null && answer.getResult() && answer instanceof SetupAnswer) {
            host.setSetup(true);
            host.setLastPinged((System.currentTimeMillis() >> 10) - 5 * 60);
            host.setHypervisorVersion(prodVersion);
            _hostDao.update(host.getId(), host);
            if (((SetupAnswer) answer).needReconnect()) {
                throw new ConnectionException(false, "Reinitialize agent after setup.");
            }
            return;
        } else {
            s_logger.warn("Unable to setup agent " + agentId + " due to " + ((answer != null) ? answer.getDetails() : "return null"));
        }
    } catch (final AgentUnavailableException e) {
        s_logger.warn("Unable to setup agent " + agentId + " because it became unavailable.", e);
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Unable to setup agent " + agentId + " because it timed out", e);
    }
    throw new ConnectionException(true, "Reinitialize agent after setup.");
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ClusterVO(com.cloud.dc.ClusterVO) HostEnvironment(com.cloud.host.HostEnvironment) SetupCommand(com.cloud.agent.api.SetupCommand) HostVO(com.cloud.host.HostVO) SetupAnswer(com.cloud.agent.api.SetupAnswer) HypervisorVersionChangedException(com.cloud.utils.exception.HypervisorVersionChangedException) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) Answer(com.cloud.agent.api.Answer) SetupAnswer(com.cloud.agent.api.SetupAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) StartupRoutingCommand(com.cloud.agent.api.StartupRoutingCommand) ConnectionException(com.cloud.exception.ConnectionException)

Example 85 with OperationTimedoutException

use of com.cloud.exception.OperationTimedoutException in project cosmic by MissionCriticalCloud.

the class DefaultVMSnapshotStrategy method takeVMSnapshot.

@Override
public VMSnapshot takeVMSnapshot(final VMSnapshot vmSnapshot) {
    final Long hostId = vmSnapshotHelper.pickRunningHost(vmSnapshot.getVmId());
    final UserVm userVm = userVmDao.findById(vmSnapshot.getVmId());
    final VMSnapshotVO vmSnapshotVO = (VMSnapshotVO) vmSnapshot;
    try {
        vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshotVO, VMSnapshot.Event.CreateRequested);
    } catch (final NoTransitionException e) {
        throw new CloudRuntimeException(e.getMessage());
    }
    CreateVMSnapshotAnswer answer = null;
    boolean result = false;
    try {
        final GuestOSVO guestOS = guestOSDao.findById(userVm.getGuestOSId());
        final List<VolumeObjectTO> volumeTOs = vmSnapshotHelper.getVolumeTOList(userVm.getId());
        VMSnapshotTO current = null;
        final VMSnapshotVO currentSnapshot = vmSnapshotDao.findCurrentSnapshotByVmId(userVm.getId());
        if (currentSnapshot != null) {
            current = vmSnapshotHelper.getSnapshotWithParents(currentSnapshot);
        }
        final VMSnapshotOptions options = ((VMSnapshotVO) vmSnapshot).getOptions();
        boolean quiescevm = true;
        if (options != null) {
            quiescevm = options.needQuiesceVM();
        }
        final VMSnapshotTO target = new VMSnapshotTO(vmSnapshot.getId(), vmSnapshot.getName(), vmSnapshot.getType(), null, vmSnapshot.getDescription(), false, current, quiescevm);
        if (current == null) {
            vmSnapshotVO.setParent(null);
        } else {
            vmSnapshotVO.setParent(current.getId());
        }
        final HostVO host = hostDao.findById(hostId);
        final GuestOSHypervisorVO guestOsMapping = guestOsHypervisorDao.findByOsIdAndHypervisor(guestOS.getId(), host.getHypervisorType().toString(), host.getHypervisorVersion());
        final CreateVMSnapshotCommand ccmd = new CreateVMSnapshotCommand(userVm.getInstanceName(), userVm.getUuid(), target, volumeTOs, guestOS.getDisplayName());
        if (guestOsMapping == null) {
            ccmd.setPlatformEmulator(null);
        } else {
            ccmd.setPlatformEmulator(guestOsMapping.getGuestOsName());
        }
        ccmd.setWait(_wait);
        answer = (CreateVMSnapshotAnswer) agentMgr.send(hostId, ccmd);
        if (answer != null && answer.getResult()) {
            processAnswer(vmSnapshotVO, userVm, answer, hostId);
            s_logger.debug("Create vm snapshot " + vmSnapshot.getName() + " succeeded for vm: " + userVm.getInstanceName());
            result = true;
            return vmSnapshot;
        } else {
            String errMsg = "Creating VM snapshot: " + vmSnapshot.getName() + " failed";
            if (answer != null && answer.getDetails() != null) {
                errMsg = errMsg + " due to " + answer.getDetails();
            }
            s_logger.error(errMsg);
            throw new CloudRuntimeException(errMsg);
        }
    } catch (final OperationTimedoutException e) {
        s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
        throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
    } catch (final AgentUnavailableException e) {
        s_logger.debug("Creating VM snapshot: " + vmSnapshot.getName() + " failed", e);
        throw new CloudRuntimeException("Creating VM snapshot: " + vmSnapshot.getName() + " failed: " + e.toString());
    } finally {
        if (!result) {
            try {
                vmSnapshotHelper.vmSnapshotStateTransitTo(vmSnapshot, VMSnapshot.Event.OperationFailed);
            } catch (final NoTransitionException e1) {
                s_logger.error("Cannot set vm snapshot state due to: " + e1.getMessage());
            }
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) VMSnapshotOptions(com.cloud.engine.subsystem.api.storage.VMSnapshotOptions) GuestOSVO(com.cloud.storage.GuestOSVO) CreateVMSnapshotCommand(com.cloud.agent.api.CreateVMSnapshotCommand) HostVO(com.cloud.host.HostVO) GuestOSHypervisorVO(com.cloud.storage.GuestOSHypervisorVO) VMSnapshotVO(com.cloud.vm.snapshot.VMSnapshotVO) UserVm(com.cloud.uservm.UserVm) CreateVMSnapshotAnswer(com.cloud.agent.api.CreateVMSnapshotAnswer) VMSnapshotTO(com.cloud.agent.api.VMSnapshotTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) NoTransitionException(com.cloud.utils.fsm.NoTransitionException) VolumeObjectTO(com.cloud.storage.to.VolumeObjectTO)

Aggregations

OperationTimedoutException (com.cloud.exception.OperationTimedoutException)131 AgentUnavailableException (com.cloud.exception.AgentUnavailableException)108 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)73 Answer (com.cloud.agent.api.Answer)50 HostVO (com.cloud.host.HostVO)45 ResourceUnavailableException (com.cloud.exception.ResourceUnavailableException)31 ArrayList (java.util.ArrayList)27 Commands (com.cloud.agent.manager.Commands)26 ConcurrentOperationException (com.cloud.exception.ConcurrentOperationException)23 AgentControlAnswer (com.cloud.agent.api.AgentControlAnswer)22 NoTransitionException (com.cloud.utils.fsm.NoTransitionException)22 UnPlugNicAnswer (com.cloud.agent.api.UnPlugNicAnswer)21 PlugNicAnswer (com.cloud.agent.api.PlugNicAnswer)19 CheckVirtualMachineAnswer (com.cloud.agent.api.CheckVirtualMachineAnswer)18 RestoreVMSnapshotAnswer (com.cloud.agent.api.RestoreVMSnapshotAnswer)17 StartAnswer (com.cloud.agent.api.StartAnswer)17 GuestOSVO (com.cloud.storage.GuestOSVO)17 VMSnapshotVO (com.cloud.vm.snapshot.VMSnapshotVO)16 Host (com.cloud.host.Host)15 UserVmVO (com.cloud.vm.UserVmVO)15