Search in sources :

Example 6 with AgentUnavailableException

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

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

the class KVMFencer method fenceOff.

@Override
public Boolean fenceOff(VirtualMachine vm, Host host) {
    if (host.getHypervisorType() != HypervisorType.KVM && host.getHypervisorType() != HypervisorType.LXC) {
        s_logger.warn("Don't know how to fence non kvm hosts " + host.getHypervisorType());
        return null;
    }
    List<HostVO> hosts = _resourceMgr.listAllHostsInCluster(host.getClusterId());
    FenceCommand fence = new FenceCommand(vm, host);
    int i = 0;
    for (HostVO h : hosts) {
        if (h.getHypervisorType() == HypervisorType.KVM || h.getHypervisorType() == HypervisorType.LXC) {
            if (h.getStatus() != Status.Up) {
                continue;
            }
            i++;
            if (h.getId() == host.getId()) {
                continue;
            }
            FenceAnswer answer;
            try {
                answer = (FenceAnswer) _agentMgr.send(h.getId(), fence);
            } catch (AgentUnavailableException e) {
                s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
                continue;
            } catch (OperationTimedoutException e) {
                s_logger.info("Moving on to the next host because " + h.toString() + " is unavailable");
                continue;
            }
            if (answer != null && answer.getResult()) {
                return true;
            }
        }
    }
    _alertMgr.sendAlert(AlertManager.AlertType.ALERT_TYPE_HOST, host.getDataCenterId(), host.getPodId(), "Unable to fence off host: " + host.getId(), "Fencing off host " + host.getId() + " did not succeed after asking " + i + " hosts. " + "Check Agent logs for more information.");
    s_logger.error("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 8 with AgentUnavailableException

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

the class NetworkHelperImpl method sendCommandsToRouter.

@Override
public boolean sendCommandsToRouter(final VirtualRouter router, final Commands cmds) throws AgentUnavailableException, ResourceUnavailableException {
    if (!checkRouterVersion(router)) {
        s_logger.debug("Router requires upgrade. Unable to send command to router:" + router.getId() + ", router template version : " + router.getTemplateVersion() + ", minimal required version : " + NetworkOrchestrationService.MinVRVersion.valueIn(router.getDataCenterId()));
        throw new ResourceUnavailableException("Unable to send command. Router requires upgrade", VirtualRouter.class, router.getId());
    }
    Answer[] answers = null;
    try {
        answers = _agentMgr.send(router.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Timed Out", e);
        throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId(), e);
    }
    if (answers == null || answers.length != cmds.size()) {
        return false;
    }
    // FIXME: Have to return state for individual command in the future
    boolean result = true;
    for (final Answer answer : answers) {
        if (!answer.getResult()) {
            result = false;
            break;
        }
    }
    return result;
}
Also used : Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException)

Example 9 with AgentUnavailableException

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

the class VirtualNetworkApplianceManagerImpl method startRemoteAccessVpn.

@Override
public boolean startRemoteAccessVpn(final Network network, final RemoteAccessVpn vpn, final List<? extends VirtualRouter> routers) throws ResourceUnavailableException {
    if (routers == null || routers.isEmpty()) {
        s_logger.warn("Failed to start remote access VPN: no router found for account and zone");
        throw new ResourceUnavailableException("Failed to start remote access VPN: no router found for account and zone", DataCenter.class, network.getDataCenterId());
    }
    for (final VirtualRouter router : routers) {
        if (router.getState() != VirtualMachine.State.Running) {
            s_logger.warn("Failed to start remote access VPN: router not in right state " + router.getState());
            throw new ResourceUnavailableException("Failed to start remote access VPN: router not in right state " + router.getState(), DataCenter.class, network.getDataCenterId());
        }
        final Commands cmds = new Commands(Command.OnError.Stop);
        _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);
        if (!_nwHelper.sendCommandsToRouter(router, cmds)) {
            throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId());
        }
        Answer answer = cmds.getAnswer("users");
        if (!answer.getResult()) {
            s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
            throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
        }
        answer = cmds.getAnswer("startVpn");
        if (!answer.getResult()) {
            s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
            throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
        }
    }
    return true;
}
Also used : NetworkUsageAnswer(com.cloud.agent.api.NetworkUsageAnswer) Answer(com.cloud.agent.api.Answer) CheckRouterAnswer(com.cloud.agent.api.CheckRouterAnswer) AgentControlAnswer(com.cloud.agent.api.AgentControlAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) CheckS2SVpnConnectionsAnswer(com.cloud.agent.api.CheckS2SVpnConnectionsAnswer) GetRouterAlertsAnswer(com.cloud.agent.api.GetRouterAlertsAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Commands(com.cloud.agent.manager.Commands)

Example 10 with AgentUnavailableException

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

the class VpcVirtualNetworkApplianceManagerImpl method startRemoteAccessVpn.

@Override
public boolean startRemoteAccessVpn(final RemoteAccessVpn vpn, final VirtualRouter router) throws ResourceUnavailableException {
    if (router.getState() != State.Running) {
        s_logger.warn("Unable to apply remote access VPN configuration, virtual router is not in the right state " + router.getState());
        throw new ResourceUnavailableException("Unable to apply remote access VPN configuration," + " virtual router is not in the right state", DataCenter.class, router.getDataCenterId());
    }
    final Commands cmds = new Commands(Command.OnError.Stop);
    _commandSetupHelper.createApplyVpnCommands(true, vpn, router, cmds);
    try {
        _agentMgr.send(router.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
        s_logger.debug("Failed to start remote access VPN: ", e);
        throw new AgentUnavailableException("Unable to send commands to virtual router ", router.getHostId(), e);
    }
    Answer answer = cmds.getAnswer("users");
    if (!answer.getResult()) {
        s_logger.error("Unable to start vpn: unable add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
        throw new ResourceUnavailableException("Unable to start vpn: Unable to add users to vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
    }
    answer = cmds.getAnswer("startVpn");
    if (!answer.getResult()) {
        s_logger.error("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails());
        throw new ResourceUnavailableException("Unable to start vpn in zone " + router.getDataCenterId() + " for account " + vpn.getAccountId() + " on domR: " + router.getInstanceName() + " due to " + answer.getDetails(), DataCenter.class, router.getDataCenterId());
    }
    return true;
}
Also used : Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ResourceUnavailableException(com.cloud.exception.ResourceUnavailableException) Commands(com.cloud.agent.manager.Commands)

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