Search in sources :

Example 41 with AgentUnavailableException

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

the class LibvirtServerDiscoverer method deleteHost.

@Override
public DeleteHostAnswer deleteHost(HostVO host, boolean isForced, boolean isForceDeleteStorage) throws UnableDeleteHostException {
    if (host.getType() != Host.Type.Routing || (host.getHypervisorType() != HypervisorType.KVM && host.getHypervisorType() != HypervisorType.LXC)) {
        return null;
    }
    _resourceMgr.deleteRoutingHost(host, isForced, isForceDeleteStorage);
    try {
        ShutdownCommand cmd = new ShutdownCommand(ShutdownCommand.DeleteHost, null);
        _agentMgr.send(host.getId(), cmd);
    } catch (AgentUnavailableException e) {
        s_logger.warn("Sending ShutdownCommand failed: ", e);
    } catch (OperationTimedoutException e) {
        s_logger.warn("Sending ShutdownCommand failed: ", e);
    }
    return new DeleteHostAnswer(true);
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) ShutdownCommand(com.cloud.agent.api.ShutdownCommand)

Example 42 with AgentUnavailableException

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

the class SecurityGroupManagerImpl method handleVmMigrated.

protected void handleVmMigrated(VMInstanceVO vm) {
    if (!isVmSecurityGroupEnabled(vm.getId()))
        return;
    if (vm.getType() != VirtualMachine.Type.User) {
        Commands cmds = null;
        NetworkRulesSystemVmCommand nrc = new NetworkRulesSystemVmCommand(vm.getInstanceName(), vm.getType());
        cmds = new Commands(nrc);
        try {
            _agentMgr.send(vm.getHostId(), cmds);
        } catch (AgentUnavailableException e) {
            s_logger.debug(e.toString());
        } catch (OperationTimedoutException e) {
            s_logger.debug(e.toString());
        }
    } else {
        List<Long> affectedVms = new ArrayList<Long>();
        affectedVms.add(vm.getId());
        scheduleRulesetUpdateToHosts(affectedVms, true, null);
    }
}
Also used : OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) NetworkRulesSystemVmCommand(com.cloud.agent.api.NetworkRulesSystemVmCommand) ArrayList(java.util.ArrayList)

Example 43 with AgentUnavailableException

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

the class SecurityGroupManagerImpl method securityGroupRulesForVmSecIp.

@Override
public boolean securityGroupRulesForVmSecIp(long nicId, String secondaryIp, boolean ruleAction) {
    Account caller = CallContext.current().getCallingAccount();
    if (secondaryIp == null) {
        throw new InvalidParameterValueException("Vm secondaryIp can't be null");
    }
    NicVO nic = _nicDao.findById(nicId);
    long vmId = nic.getInstanceId();
    UserVm vm = _userVMDao.findById(vmId);
    if (vm == null || vm.getType() != VirtualMachine.Type.User) {
        throw new InvalidParameterValueException("Can't configure the SG ipset, arprules rules for the non existing or non user vm");
    }
    // Verify permissions
    _accountMgr.checkAccess(caller, null, false, vm);
    // Validate parameters
    List<SecurityGroupVO> vmSgGrps = getSecurityGroupsForVm(vmId);
    if (vmSgGrps.isEmpty()) {
        s_logger.debug("Vm is not in any Security group ");
        return true;
    }
    //If network does not support SG service, no need add SG rules for secondary ip
    Network network = _networkModel.getNetwork(nic.getNetworkId());
    if (!_networkModel.isSecurityGroupSupportedInNetwork(network)) {
        s_logger.debug("Network " + network + " is not enabled with security group service, " + "so not applying SG rules for secondary ip");
        return true;
    }
    String vmMac = vm.getPrivateMacAddress();
    String vmName = vm.getInstanceName();
    if (vmMac == null || vmName == null) {
        throw new InvalidParameterValueException("vm name or vm mac can't be null");
    }
    //create command for the to add ip in ipset and arptables rules
    NetworkRulesVmSecondaryIpCommand cmd = new NetworkRulesVmSecondaryIpCommand(vmName, vmMac, secondaryIp, ruleAction);
    s_logger.debug("Asking agent to configure rules for vm secondary ip");
    Commands cmds = null;
    cmds = new Commands(cmd);
    try {
        _agentMgr.send(vm.getHostId(), cmds);
    } catch (AgentUnavailableException e) {
        s_logger.debug(e.toString());
    } catch (OperationTimedoutException e) {
        s_logger.debug(e.toString());
    }
    return true;
}
Also used : Account(com.cloud.user.Account) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) NetworkRulesVmSecondaryIpCommand(com.cloud.agent.api.NetworkRulesVmSecondaryIpCommand) UserVm(com.cloud.uservm.UserVm) InvalidParameterValueException(com.cloud.exception.InvalidParameterValueException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Network(com.cloud.network.Network) Commands(com.cloud.agent.manager.Commands) NicVO(com.cloud.vm.NicVO)

Example 44 with AgentUnavailableException

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

the class SecurityGroupManagerImpl2 method sendRulesetUpdates.

public void sendRulesetUpdates(SecurityGroupWork work) {
    Long userVmId = work.getInstanceId();
    UserVm vm = _userVMDao.findById(userVmId);
    if (vm != null && vm.getState() == State.Running) {
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("SecurityGroupManager v2: found vm, " + userVmId + " state=" + vm.getState());
        }
        Map<PortAndProto, Set<String>> ingressRules = generateRulesForVM(userVmId, SecurityRuleType.IngressRule);
        Map<PortAndProto, Set<String>> egressRules = generateRulesForVM(userVmId, SecurityRuleType.EgressRule);
        Long agentId = vm.getHostId();
        if (agentId != null) {
            String privateIp = vm.getPrivateIpAddress();
            NicVO nic = _nicDao.findByIp4AddressAndVmId(privateIp, vm.getId());
            List<String> nicSecIps = null;
            if (nic != null) {
                if (nic.getSecondaryIp()) {
                    nicSecIps = _nicSecIpDao.getSecondaryIpAddressesForNic(nic.getId());
                }
            }
            SecurityGroupRulesCmd cmd = generateRulesetCmd(vm.getInstanceName(), vm.getPrivateIpAddress(), nic.getIPv6Address(), vm.getPrivateMacAddress(), vm.getId(), null, work.getLogsequenceNumber(), ingressRules, egressRules, nicSecIps);
            cmd.setMsId(_serverId);
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("SecurityGroupManager v2: sending ruleset update for vm " + vm.getInstanceName() + ":ingress num rules=" + cmd.getIngressRuleSet().size() + ":egress num rules=" + cmd.getEgressRuleSet().size() + " num cidrs=" + cmd.getTotalNumCidrs() + " sig=" + cmd.getSignature());
            }
            Commands cmds = new Commands(cmd);
            try {
                _agentMgr.send(agentId, cmds, _answerListener);
                if (s_logger.isTraceEnabled()) {
                    s_logger.trace("SecurityGroupManager v2: sent ruleset updates for " + vm.getInstanceName() + " curr queue size=" + _workQueue.size());
                }
            } catch (AgentUnavailableException e) {
                s_logger.debug("Unable to send updates for vm: " + userVmId + "(agentid=" + agentId + ")");
                _workTracker.handleException(agentId);
            }
        }
    } else {
        if (s_logger.isDebugEnabled()) {
            if (vm != null)
                s_logger.debug("No rules sent to vm " + vm + "state=" + vm.getState());
            else
                s_logger.debug("Could not find vm: No rules sent to vm " + userVmId);
        }
    }
}
Also used : UserVm(com.cloud.uservm.UserVm) Set(java.util.Set) TreeSet(java.util.TreeSet) SecurityGroupRulesCmd(com.cloud.agent.api.SecurityGroupRulesCmd) AgentUnavailableException(com.cloud.exception.AgentUnavailableException) Commands(com.cloud.agent.manager.Commands) NicVO(com.cloud.vm.NicVO)

Example 45 with AgentUnavailableException

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

the class InternalLoadBalancerVMManagerImpl method sendCommandsToInternalLbVm.

protected boolean sendCommandsToInternalLbVm(final VirtualRouter internalLbVm, final Commands cmds) throws AgentUnavailableException {
    Answer[] answers = null;
    try {
        answers = _agentMgr.send(internalLbVm.getHostId(), cmds);
    } catch (final OperationTimedoutException e) {
        s_logger.warn("Timed Out", e);
        throw new AgentUnavailableException("Unable to send commands to virtual router ", internalLbVm.getHostId(), e);
    }
    if (answers == null) {
        return false;
    }
    if (answers.length != cmds.size()) {
        return false;
    }
    boolean result = true;
    if (answers.length > 0) {
        for (final Answer answer : answers) {
            if (!answer.getResult()) {
                result = false;
                break;
            }
        }
    }
    return result;
}
Also used : CheckSshAnswer(com.cloud.agent.api.check.CheckSshAnswer) GetDomRVersionAnswer(com.cloud.agent.api.GetDomRVersionAnswer) Answer(com.cloud.agent.api.Answer) OperationTimedoutException(com.cloud.exception.OperationTimedoutException) AgentUnavailableException(com.cloud.exception.AgentUnavailableException)

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