Search in sources :

Example 46 with OperationTimedoutException

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

the class AccountManagerImpl method doDisableAccount.

private boolean doDisableAccount(long accountId) throws ConcurrentOperationException, ResourceUnavailableException {
    List<VMInstanceVO> vms = _vmDao.listByAccountId(accountId);
    boolean success = true;
    for (VMInstanceVO vm : vms) {
        try {
            try {
                _itMgr.advanceStop(vm.getUuid(), false);
            } catch (OperationTimedoutException ote) {
                s_logger.warn("Operation for stopping vm timed out, unable to stop vm " + vm.getHostName(), ote);
                success = false;
            }
        } catch (AgentUnavailableException aue) {
            s_logger.warn("Agent running on host " + vm.getHostId() + " is unavailable, unable to stop vm " + vm.getHostName(), aue);
            success = false;
        }
    }
    return success;
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) VMInstanceVO(com.cloud.vm.VMInstanceVO)

Example 47 with OperationTimedoutException

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

the class OvsTunnelManagerImpl method checkAndCreateVpcTunnelNetworks.

@DB
protected void checkAndCreateVpcTunnelNetworks(Host host, long vpcId) {
    long hostId = host.getId();
    String bridgeName = generateBridgeNameForVpc(vpcId);
    List<Long> vmIds = _ovsNetworkToplogyGuru.getActiveVmsInVpcOnHost(vpcId, hostId);
    if (vmIds == null || vmIds.isEmpty()) {
        // since this is the first VM from the VPC being launched on the host, first setup the bridge
        try {
            Commands cmds = new Commands(new OvsSetupBridgeCommand(bridgeName, hostId, null));
            s_logger.debug("Ask host " + hostId + " to create bridge for vpc " + vpcId + " and configure the " + " bridge for distributed routing.");
            Answer[] answers = _agentMgr.send(hostId, cmds);
            handleSetupBridgeAnswer(answers);
        } catch (OperationTimedoutException | AgentUnavailableException e) {
            s_logger.warn("Ovs Tunnel network created tunnel failed", e);
        }
        // now that bridge is setup, populate network acl's before the VM gets created
        OvsVpcRoutingPolicyConfigCommand cmd = prepareVpcRoutingPolicyUpdate(vpcId);
        cmd.setSequenceNumber(getNextRoutingPolicyUpdateSequenceNumber(vpcId));
        if (!sendVpcRoutingPolicyChangeUpdate(cmd, hostId, bridgeName)) {
            s_logger.debug("Failed to send VPC routing policy change update to host : " + hostId + ". But moving on with sending the updates to the rest of the hosts.");
        }
    }
    List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
    List<Long> vpcSpannedHostIds = _ovsNetworkToplogyGuru.getVpcSpannedHosts(vpcId);
    for (Network vpcNetwork : vpcNetworks) {
        if (vpcNetwork.getState() != Network.State.Implemented && vpcNetwork.getState() != Network.State.Implementing && vpcNetwork.getState() != Network.State.Setup)
            continue;
        int key = getGreKey(vpcNetwork);
        List<Long> toHostIds = new ArrayList<Long>();
        List<Long> fromHostIds = new ArrayList<Long>();
        OvsTunnelNetworkVO tunnelRecord = null;
        for (Long rh : vpcSpannedHostIds) {
            if (rh == hostId) {
                continue;
            }
            tunnelRecord = _tunnelNetworkDao.getByFromToNetwork(hostId, rh.longValue(), vpcNetwork.getId());
            // Try and create the tunnel if does not exit or previous attempt failed
            if (tunnelRecord == null || tunnelRecord.getState().equals(OvsTunnel.State.Failed.name())) {
                s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + rh.longValue());
                if (tunnelRecord == null) {
                    createTunnelRecord(hostId, rh.longValue(), vpcNetwork.getId(), key);
                }
                if (!toHostIds.contains(rh)) {
                    toHostIds.add(rh);
                }
            }
            tunnelRecord = _tunnelNetworkDao.getByFromToNetwork(rh.longValue(), hostId, vpcNetwork.getId());
            // Try and create the tunnel if does not exit or previous attempt failed
            if (tunnelRecord == null || tunnelRecord.getState().equals(OvsTunnel.State.Failed.name())) {
                s_logger.debug("Attempting to create tunnel from:" + rh.longValue() + " to:" + hostId);
                if (tunnelRecord == null) {
                    createTunnelRecord(rh.longValue(), hostId, vpcNetwork.getId(), key);
                }
                if (!fromHostIds.contains(rh)) {
                    fromHostIds.add(rh);
                }
            }
        }
        try {
            String myIp = getGreEndpointIP(host, vpcNetwork);
            if (myIp == null)
                throw new GreTunnelException("Unable to retrieve the source " + "endpoint for the GRE tunnel." + "Failure is on host:" + host.getId());
            boolean noHost = true;
            for (Long i : toHostIds) {
                HostVO rHost = _hostDao.findById(i);
                String otherIp = getGreEndpointIP(rHost, vpcNetwork);
                if (otherIp == null)
                    throw new GreTunnelException("Unable to retrieve the remote endpoint for the GRE tunnel." + "Failure is on host:" + rHost.getId());
                Commands cmds = new Commands(new OvsCreateTunnelCommand(otherIp, key, Long.valueOf(hostId), i, vpcNetwork.getId(), myIp, bridgeName, vpcNetwork.getUuid()));
                s_logger.debug("Attempting to create tunnel from:" + hostId + " to:" + i + " for the network " + vpcNetwork.getId());
                s_logger.debug("Ask host " + hostId + " to create gre tunnel to " + i);
                Answer[] answers = _agentMgr.send(hostId, cmds);
                handleCreateTunnelAnswer(answers);
            }
            for (Long i : fromHostIds) {
                HostVO rHost = _hostDao.findById(i);
                String otherIp = getGreEndpointIP(rHost, vpcNetwork);
                Commands cmds = new Commands(new OvsCreateTunnelCommand(myIp, key, i, Long.valueOf(hostId), vpcNetwork.getId(), otherIp, bridgeName, vpcNetwork.getUuid()));
                s_logger.debug("Ask host " + i + " to create gre tunnel to " + hostId);
                Answer[] answers = _agentMgr.send(i, cmds);
                handleCreateTunnelAnswer(answers);
            }
        } catch (GreTunnelException | OperationTimedoutException | AgentUnavailableException e) {
            // I really thing we should do a better handling of these exceptions
            s_logger.warn("Ovs Tunnel network created tunnel failed", e);
        }
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) OvsTunnelNetworkVO(com.cloud.network.ovs.dao.OvsTunnelNetworkVO) OvsCreateTunnelCommand(com.cloud.agent.api.OvsCreateTunnelCommand) ArrayList(java.util.ArrayList) OvsVpcRoutingPolicyConfigCommand(com.cloud.agent.api.OvsVpcRoutingPolicyConfigCommand) HostVO(com.cloud.host.HostVO) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) Answer(com.cloud.agent.api.Answer) OvsCreateTunnelAnswer(com.cloud.agent.api.OvsCreateTunnelAnswer) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) OvsSetupBridgeCommand(com.cloud.agent.api.OvsSetupBridgeCommand) DB(com.cloud.utils.db.DB)

Example 48 with OperationTimedoutException

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

the class StorageManagerImpl method sendToPool.

@Override
public Pair<Long, Answer[]> sendToPool(StoragePool pool, long[] hostIdsToTryFirst, List<Long> hostIdsToAvoid, Commands cmds) throws StorageUnavailableException {
    List<Long> hostIds = getUpHostsInPool(pool.getId());
    Collections.shuffle(hostIds);
    if (hostIdsToTryFirst != null) {
        for (int i = hostIdsToTryFirst.length - 1; i >= 0; i--) {
            if (hostIds.remove(hostIdsToTryFirst[i])) {
                hostIds.add(0, hostIdsToTryFirst[i]);
            }
        }
    }
    if (hostIdsToAvoid != null) {
        hostIds.removeAll(hostIdsToAvoid);
    }
    if (hostIds == null || hostIds.isEmpty()) {
        throw new StorageUnavailableException("Unable to send command to the pool " + pool.getId() + " due to there is no enabled hosts up in this cluster", pool.getId());
    }
    for (Long hostId : hostIds) {
        try {
            List<Answer> answers = new ArrayList<Answer>();
            Command[] cmdArray = cmds.toCommands();
            for (Command cmd : cmdArray) {
                long targetHostId = _hvGuruMgr.getGuruProcessedCommandTargetHost(hostId, cmd);
                answers.add(_agentMgr.send(targetHostId, cmd));
            }
            return new Pair<Long, Answer[]>(hostId, answers.toArray(new Answer[answers.size()]));
        } catch (AgentUnavailableException e) {
            s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostId, e);
        } catch (OperationTimedoutException e) {
            s_logger.debug("Unable to send storage pool command to " + pool + " via " + hostId, e);
        }
    }
    throw new StorageUnavailableException("Unable to send command to the pool ", pool.getId());
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) ArrayList(java.util.ArrayList) EndPoint(org.apache.cloudstack.engine.subsystem.api.storage.EndPoint) Answer(com.cloud.agent.api.Answer) StorageUnavailableException(com.cloud.exception.StorageUnavailableException) DettachCommand(org.apache.cloudstack.storage.command.DettachCommand) Command(com.cloud.agent.api.Command) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Pair(com.cloud.utils.Pair)

Example 49 with OperationTimedoutException

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

the class SimulatorInvestigator method isVmAlive.

@Override
public boolean isVmAlive(VirtualMachine vm, Host host) throws UnknownVM {
    CheckVirtualMachineCommand cmd = new CheckVirtualMachineCommand(vm.getInstanceName());
    try {
        Answer answer = _agentMgr.send(vm.getHostId(), cmd);
        if (!answer.getResult()) {
            s_logger.debug("Unable to get vm state on " + vm.toString());
            throw new UnknownVM();
        }
        CheckVirtualMachineAnswer cvmAnswer = (CheckVirtualMachineAnswer) answer;
        s_logger.debug("Agent responded with state " + cvmAnswer.getState().toString());
        return cvmAnswer.getState() == PowerState.PowerOn;
    } catch (AgentUnavailableException e) {
        s_logger.debug("Unable to reach the agent for " + vm.toString() + ": " + e.getMessage());
        throw new UnknownVM();
    } catch (OperationTimedoutException e) {
        s_logger.debug("Operation timed out for " + vm.toString() + ": " + e.getMessage());
        throw new UnknownVM();
    }
}
Also used : CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) CheckVirtualMachineCommand(com.cloud.agent.api.CheckVirtualMachineCommand)

Example 50 with OperationTimedoutException

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

the class StorageSystemDataMotionStrategy method performResignature.

private CopyCmdAnswer performResignature(DataObject dataObj, HostVO hostVO, boolean keepGrantedAccess) {
    long storagePoolId = dataObj.getDataStore().getId();
    DataStore dataStore = dataStoreMgr.getDataStore(storagePoolId, DataStoreRole.Primary);
    Map<String, String> details = getDetails(dataObj);
    ResignatureCommand command = new ResignatureCommand(details);
    ResignatureAnswer answer = null;
    try {
        _volumeService.grantAccess(dataObj, hostVO, dataStore);
        answer = (ResignatureAnswer) _agentMgr.send(hostVO.getId(), command);
    } catch (CloudRuntimeException | AgentUnavailableException | OperationTimedoutException ex) {
        keepGrantedAccess = false;
        String msg = "Failed to resign the DataObject with the following ID: " + dataObj.getId();
        LOGGER.warn(msg, ex);
        throw new CloudRuntimeException(msg + ex.getMessage());
    } finally {
        if (keepGrantedAccess == false) {
            _volumeService.revokeAccess(dataObj, hostVO, dataStore);
        }
    }
    if (answer == null || !answer.getResult()) {
        final String errMsg;
        if (answer != null && answer.getDetails() != null && !answer.getDetails().isEmpty()) {
            errMsg = answer.getDetails();
        } else {
            errMsg = "Unable to perform resignature operation in 'StorageSystemDataMotionStrategy.performResignature'";
        }
        throw new CloudRuntimeException(errMsg);
    }
    VolumeObjectTO newVolume = new VolumeObjectTO();
    newVolume.setSize(answer.getSize());
    newVolume.setPath(answer.getPath());
    newVolume.setFormat(answer.getFormat());
    return new CopyCmdAnswer(newVolume);
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) DataStore(org.apache.cloudstack.engine.subsystem.api.storage.DataStore) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) VolumeObjectTO(org.apache.cloudstack.storage.to.VolumeObjectTO) ResignatureCommand(org.apache.cloudstack.storage.command.ResignatureCommand) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer)

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