Search in sources :

Example 11 with OperationTimedoutException

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

the class SimulatorFencer method fenceOff.

@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
    if (host.getHypervisorType() != HypervisorType.Simulator) {
        s_logger.debug("Don't know how to fence non simulator hosts " + host.getHypervisorType());
        return null;
    }
    List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
    FenceCommand fence = new FenceCommand(vm, host);
    for (HostVO h : hosts) {
        if (h.getHypervisorType() == HypervisorType.Simulator) {
            if (h.getStatus() != Status.Up) {
                continue;
            }
            if (h.getId() == host.getId()) {
                continue;
            }
            FenceAnswer answer = null;
            try {
                answer = (FenceAnswer) _agentMgr.send(h.getId(), fence);
            } catch (AgentUnavailableException e) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
                }
                continue;
            } catch (OperationTimedoutException e) {
                if (s_logger.isDebugEnabled()) {
                    s_logger.debug("Moving on to the next host because " + h.toString() + " is unavailable");
                }
                continue;
            }
            if (answer != null && answer.getResult()) {
                return true;
            }
        }
    }
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Unable to fence off " + vm.toString() + " on " + host.toString());
    }
    return false;
}
Also used : FenceCommand(com.cloud.agent.api.FenceCommand) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) FenceAnswer(com.cloud.agent.api.FenceAnswer) HostVO(com.cloud.host.HostVO)

Example 12 with OperationTimedoutException

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

the class UserVmManagerImpl method setupVmForPvlan.

@Override
public boolean setupVmForPvlan(boolean add, Long hostId, NicProfile nic) {
    if (!nic.getBroadCastUri().getScheme().equals("pvlan")) {
        return false;
    }
    String op = "add";
    if (!add) {
        // "delete" would remove all the rules(if using ovs) related to this vm
        op = "delete";
    }
    Network network = _networkDao.findById(nic.getNetworkId());
    Host host = _hostDao.findById(hostId);
    String networkTag = _networkModel.getNetworkTag(host.getHypervisorType(), network);
    PvlanSetupCommand cmd = PvlanSetupCommand.createVmSetup(op, nic.getBroadCastUri(), networkTag, nic.getMacAddress());
    Answer answer = null;
    try {
        answer = _agentMgr.send(hostId, cmd);
    } catch (OperationTimedoutException e) {
        s_logger.warn("Timed Out", e);
        return false;
    } catch (AgentUnavailableException e) {
        s_logger.warn("Agent Unavailable ", e);
        return false;
    }
    boolean result = true;
    if (answer == null || !answer.getResult()) {
        result = false;
    }
    return result;
}
Also used : GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) Answer(com.cloud.agent.api.Answer) StartAnswer(com.cloud.agent.api.StartAnswer) RestoreVMSnapshotAnswer(com.cloud.agent.api.RestoreVMSnapshotAnswer) GetVmDiskStatsAnswer(com.cloud.agent.api.GetVmDiskStatsAnswer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Network(com.cloud.network.Network) PhysicalNetwork(com.cloud.network.PhysicalNetwork) Host(com.cloud.host.Host) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand)

Example 13 with OperationTimedoutException

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

the class XenServerStorageMotionStrategy method migrateVmWithVolumesAcrossCluster.

private Answer migrateVmWithVolumesAcrossCluster(VMInstanceVO vm, VirtualMachineTO to, Host srcHost, Host destHost, Map<VolumeInfo, DataStore> volumeToPool) throws AgentUnavailableException {
    try {
        List<Pair<VolumeTO, String>> volumeToStorageUuid = new ArrayList<>();
        for (Map.Entry<VolumeInfo, DataStore> entry : volumeToPool.entrySet()) {
            VolumeInfo volumeInfo = entry.getKey();
            StoragePool storagePool = storagePoolDao.findById(volumeInfo.getPoolId());
            VolumeTO volumeTo = new VolumeTO(volumeInfo, storagePool);
            if (storagePool.isManaged()) {
                String iqn = handleManagedVolumePreMigration(volumeInfo, storagePool, destHost);
                volumeToStorageUuid.add(new Pair<>(volumeTo, iqn));
            } else {
                volumeToStorageUuid.add(new Pair<>(volumeTo, ((StoragePool) entry.getValue()).getPath()));
            }
        }
        // Migration across cluster needs to be done in three phases.
        // 1. Send a migrate receive command to the destination host so that it is ready to receive a vm.
        // 2. Send a migrate send command to the source host. This actually migrates the vm to the destination.
        // 3. Complete the process. Update the volume details.
        MigrateWithStorageReceiveCommand receiveCmd = new MigrateWithStorageReceiveCommand(to, volumeToStorageUuid);
        MigrateWithStorageReceiveAnswer receiveAnswer = (MigrateWithStorageReceiveAnswer) agentMgr.send(destHost.getId(), receiveCmd);
        if (receiveAnswer == null) {
            s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!receiveAnswer.getResult()) {
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + receiveAnswer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        }
        MigrateWithStorageSendCommand sendCmd = new MigrateWithStorageSendCommand(to, receiveAnswer.getVolumeToSr(), receiveAnswer.getNicToNetwork(), receiveAnswer.getToken());
        MigrateWithStorageSendAnswer sendAnswer = (MigrateWithStorageSendAnswer) agentMgr.send(srcHost.getId(), sendCmd);
        if (sendAnswer == null) {
            handleManagedVolumesAfterFailedMigration(volumeToPool, destHost);
            s_logger.error("Migration with storage of vm " + vm + " to host " + destHost + " failed.");
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        } else if (!sendAnswer.getResult()) {
            handleManagedVolumesAfterFailedMigration(volumeToPool, destHost);
            s_logger.error("Migration with storage of vm " + vm + " failed. Details: " + sendAnswer.getDetails());
            throw new CloudRuntimeException("Error while migrating the vm " + vm + " to host " + destHost);
        }
        MigrateWithStorageCompleteCommand command = new MigrateWithStorageCompleteCommand(to);
        MigrateWithStorageCompleteAnswer answer = (MigrateWithStorageCompleteAnswer) agentMgr.send(destHost.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);
        } else {
            // Update the volume details after migration.
            updateVolumePathsAfterMigration(volumeToPool, answer.getVolumeTos(), srcHost);
        }
        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 : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) StoragePool(com.cloud.storage.StoragePool) MigrateWithStorageSendAnswer(com.cloud.agent.api.MigrateWithStorageSendAnswer) ArrayList(java.util.ArrayList) MigrateWithStorageCompleteCommand(com.cloud.agent.api.MigrateWithStorageCompleteCommand) VolumeInfo(org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo) MigrateWithStorageCompleteAnswer(com.cloud.agent.api.MigrateWithStorageCompleteAnswer) MigrateWithStorageReceiveCommand(com.cloud.agent.api.MigrateWithStorageReceiveCommand) VolumeTO(com.cloud.agent.api.to.VolumeTO) MigrateWithStorageReceiveAnswer(com.cloud.agent.api.MigrateWithStorageReceiveAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) MigrateWithStorageSendCommand(com.cloud.agent.api.MigrateWithStorageSendCommand) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 14 with OperationTimedoutException

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

the class XenServerStorageMotionStrategy 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 its 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);
        MigrateWithStorageAnswer answer = (MigrateWithStorageAnswer) agentMgr.send(destHost.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.
            updateVolumePathsAfterMigration(volumeToPool, answer.getVolumeTos(), srcHost);
        }
        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) HashMap(java.util.HashMap) Map(java.util.Map) Pair(com.cloud.utils.Pair)

Example 15 with OperationTimedoutException

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

the class HighAvailabilityManagerImpl method scheduleRestart.

@Override
public void scheduleRestart(VMInstanceVO vm, boolean investigate) {
    Long hostId = vm.getHostId();
    if (hostId == null) {
        try {
            s_logger.debug("Found a vm that is scheduled to be restarted but has no host id: " + vm);
            _itMgr.advanceStop(vm.getUuid(), true);
        } catch (ResourceUnavailableException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        } catch (OperationTimedoutException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        } catch (ConcurrentOperationException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        }
    }
    if (vm.getHypervisorType() == HypervisorType.VMware || vm.getHypervisorType() == HypervisorType.Hyperv) {
        s_logger.info("Skip HA for VMware VM or Hyperv VM" + vm.getInstanceName());
        return;
    }
    if (!investigate) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("VM does not require investigation so I'm marking it as Stopped: " + vm.toString());
        }
        AlertManager.AlertType alertType = AlertManager.AlertType.ALERT_TYPE_USERVM;
        if (VirtualMachine.Type.DomainRouter.equals(vm.getType())) {
            alertType = AlertManager.AlertType.ALERT_TYPE_DOMAIN_ROUTER;
        } else if (VirtualMachine.Type.ConsoleProxy.equals(vm.getType())) {
            alertType = AlertManager.AlertType.ALERT_TYPE_CONSOLE_PROXY;
        } else if (VirtualMachine.Type.SecondaryStorageVm.equals(vm.getType())) {
            alertType = AlertManager.AlertType.ALERT_TYPE_SSVM;
        }
        if (!(_forceHA || vm.isHaEnabled())) {
            String hostDesc = "id:" + vm.getHostId() + ", availability zone id:" + vm.getDataCenterId() + ", pod id:" + vm.getPodIdToDeployIn();
            _alertMgr.sendAlert(alertType, vm.getDataCenterId(), vm.getPodIdToDeployIn(), "VM (name: " + vm.getHostName() + ", id: " + vm.getId() + ") stopped unexpectedly on host " + hostDesc, "Virtual Machine " + vm.getHostName() + " (id: " + vm.getId() + ") running on host [" + vm.getHostId() + "] stopped unexpectedly.");
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("VM is not HA enabled so we're done.");
            }
        }
        try {
            _itMgr.advanceStop(vm.getUuid(), true);
            vm = _instanceDao.findByUuid(vm.getUuid());
        } catch (ResourceUnavailableException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        } catch (OperationTimedoutException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        } catch (ConcurrentOperationException e) {
            assert false : "How do we hit this when force is true?";
            throw new CloudRuntimeException("Caught exception even though it should be handled.", e);
        }
    }
    if (vm.getHypervisorType() == HypervisorType.VMware) {
        s_logger.info("Skip HA for VMware VM " + vm.getInstanceName());
        return;
    }
    List<HaWorkVO> items = _haDao.findPreviousHA(vm.getId());
    int timesTried = 0;
    for (HaWorkVO item : items) {
        if (timesTried < item.getTimesTried() && !item.canScheduleNew(_timeBetweenFailures)) {
            timesTried = item.getTimesTried();
            break;
        }
    }
    if (hostId == null) {
        hostId = vm.getLastHostId();
    }
    HaWorkVO work = new HaWorkVO(vm.getId(), vm.getType(), WorkType.HA, investigate ? Step.Investigating : Step.Scheduled, hostId != null ? hostId : 0L, vm.getState(), timesTried, vm.getUpdated());
    _haDao.persist(work);
    if (s_logger.isInfoEnabled()) {
        s_logger.info("Schedule vm for HA:  " + vm);
    }
    wakeupWorkers();
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AlertManager(com.cloud.alert.AlertManager) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) ConcurrentOperationException(com.cloud.exception.ConcurrentOperationException)

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