Search in sources :

Example 56 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixScaleVmCommandWrapper method execute.

@Override
public Answer execute(final ScaleVmCommand command, final CitrixResourceBase citrixResourceBase) {
    final VirtualMachineTO vmSpec = command.getVirtualMachine();
    final String vmName = vmSpec.getName();
    try {
        final Connection conn = citrixResourceBase.getConnection();
        final Set<VM> vms = VM.getByNameLabel(conn, vmName);
        final Host host = Host.getByUuid(conn, citrixResourceBase.getHost().getUuid());
        // If DMC is not enable then don't execute this command.
        if (!citrixResourceBase.isDmcEnabled(conn, host)) {
            throw new CloudRuntimeException("Unable to scale the vm: " + vmName + " as DMC - Dynamic memory control is not enabled for the XenServer:" + citrixResourceBase.getHost().getUuid() + " ,check your license and hypervisor version.");
        }
        if (vms == null || vms.size() == 0) {
            s_logger.info("No running VM " + vmName + " exists on XenServer" + citrixResourceBase.getHost().getUuid());
            return new ScaleVmAnswer(command, false, "VM does not exist");
        }
        // stop vm which is running on this host or is in halted state
        final Iterator<VM> iter = vms.iterator();
        while (iter.hasNext()) {
            final VM vm = iter.next();
            final VM.Record vmr = vm.getRecord(conn);
            if (vmr.powerState == VmPowerState.HALTED || vmr.powerState == VmPowerState.RUNNING && !citrixResourceBase.isRefNull(vmr.residentOn) && !vmr.residentOn.getUuid(conn).equals(citrixResourceBase.getHost().getUuid())) {
                iter.remove();
            }
        }
        for (final VM vm : vms) {
            vm.getRecord(conn);
            try {
                citrixResourceBase.scaleVM(conn, vm, vmSpec, host);
            } catch (final Exception e) {
                final String msg = "Catch exception " + e.getClass().getName() + " when scaling VM:" + vmName + " due to " + e.toString();
                s_logger.debug(msg);
                return new ScaleVmAnswer(command, false, msg);
            }
        }
        final String msg = "scaling VM " + vmName + " is successful on host " + host;
        s_logger.debug(msg);
        return new ScaleVmAnswer(command, true, msg);
    } catch (final XenAPIException e) {
        final String msg = "Upgrade Vm " + vmName + " fail due to " + e.toString();
        s_logger.warn(msg, e);
        return new ScaleVmAnswer(command, false, msg);
    } catch (final XmlRpcException e) {
        final String msg = "Upgrade Vm " + vmName + " fail due to " + e.getMessage();
        s_logger.warn(msg, e);
        return new ScaleVmAnswer(command, false, msg);
    } catch (final Exception e) {
        final String msg = "Unable to upgrade " + vmName + " due to " + e.getMessage();
        s_logger.warn(msg, e);
        return new ScaleVmAnswer(command, false, msg);
    }
}
Also used : Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) VirtualMachineTO(com.cloud.agent.api.to.VirtualMachineTO) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) ScaleVmAnswer(com.cloud.agent.api.ScaleVmAnswer) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VM(com.xensource.xenapi.VM) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 57 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixGetStorageStatsCommandWrapper method execute.

@Override
public Answer execute(final GetStorageStatsCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Set<SR> srs = SR.getByNameLabel(conn, command.getStorageId());
        if (srs.size() != 1) {
            final String msg = "There are " + srs.size() + " storageid: " + command.getStorageId();
            s_logger.warn(msg);
            return new GetStorageStatsAnswer(command, msg);
        }
        final SR sr = srs.iterator().next();
        sr.scan(conn);
        final long capacity = sr.getPhysicalSize(conn);
        final long used = sr.getPhysicalUtilisation(conn);
        return new GetStorageStatsAnswer(command, capacity, used);
    } catch (final XenAPIException e) {
        final String msg = "GetStorageStats Exception:" + e.toString() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    } catch (final XmlRpcException e) {
        final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    } catch (final Exception e) {
        final String msg = "GetStorageStats Exception:" + e.getMessage() + "host:" + citrixResourceBase.getHost().getUuid() + "storageid: " + command.getStorageId();
        s_logger.warn(msg);
        return new GetStorageStatsAnswer(command, msg);
    }
}
Also used : GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SR(com.xensource.xenapi.SR)

Example 58 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixGetVmIpAddressCommandWrapper method execute.

@Override
public Answer execute(final GetVmIpAddressCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    String vmName = command.getVmName();
    String networkCidr = command.getVmNetworkCidr();
    boolean result = false;
    String errorMsg = null;
    String vmIp = null;
    try {
        VM vm = citrixResourceBase.getVM(conn, vmName);
        VMGuestMetrics mtr = vm.getGuestMetrics(conn);
        VMGuestMetrics.Record rec = mtr.getRecord(conn);
        Map<String, String> vmIpsMap = rec.networks;
        for (String ipAddr : vmIpsMap.values()) {
            if (NetUtils.isIpWithtInCidrRange(ipAddr, networkCidr)) {
                vmIp = ipAddr;
                break;
            }
        }
        if (vmIp != null) {
            s_logger.debug("VM " + vmName + " ip address got retrieved " + vmIp);
            result = true;
            return new Answer(command, result, vmIp);
        }
    } catch (Types.XenAPIException e) {
        s_logger.debug("Got exception in GetVmIpAddressCommand " + e.getMessage());
        errorMsg = "Failed to retrived vm ip addr, exception: " + e.getMessage();
    } catch (XmlRpcException e) {
        s_logger.debug("Got exception in GetVmIpAddressCommand " + e.getMessage());
        errorMsg = "Failed to retrived vm ip addr, exception: " + e.getMessage();
    }
    return new Answer(command, result, errorMsg);
}
Also used : Answer(com.cloud.agent.api.Answer) Types(com.xensource.xenapi.Types) VMGuestMetrics(com.xensource.xenapi.VMGuestMetrics) VM(com.xensource.xenapi.VM) Connection(com.xensource.xenapi.Connection) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 59 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixMaintainCommandWrapper method execute.

@Override
public Answer execute(final MaintainCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final XsHost xsHost = citrixResourceBase.getHost();
        final String uuid = xsHost.getUuid();
        final Host host = Host.getByUuid(conn, uuid);
        // remove all tags cloud stack
        final Host.Record hr = host.getRecord(conn);
        // Adding this check because could not get the mock to work. Will push the code and fix it afterwards.
        if (hr == null) {
            s_logger.warn("Host.Record is null.");
            return new MaintainAnswer(command, false, "Host.Record is null");
        }
        final Iterator<String> it = hr.tags.iterator();
        while (it.hasNext()) {
            final String tag = it.next();
            if (tag.contains("cloud")) {
                it.remove();
            }
        }
        host.setTags(conn, hr.tags);
        return new MaintainAnswer(command);
    } catch (final XenAPIException e) {
        s_logger.warn("Unable to put server in maintainence mode", e);
        return new MaintainAnswer(command, false, e.getMessage());
    } catch (final XmlRpcException e) {
        s_logger.warn("Unable to put server in maintainence mode", e);
        return new MaintainAnswer(command, false, e.getMessage());
    }
}
Also used : XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XsHost(com.cloud.hypervisor.xenserver.resource.XsHost) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 60 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixOvsSetTagAndFlowCommandWrapper method execute.

@Override
public Answer execute(final OvsSetTagAndFlowCommand command, final CitrixResourceBase citrixResourceBase) {
    citrixResourceBase.setIsOvs(true);
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final Network nw = citrixResourceBase.setupvSwitchNetwork(conn);
        final String bridge = nw.getBridge(conn);
        /*
             * If VM is domainRouter, this will try to set flow and tag on its
             * none guest network nic. don't worry, it will fail silently at
             * host plugin side
             */
        final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_set_tag_and_flow", "bridge", bridge, "vmName", command.getVmName(), "tag", command.getTag(), "vlans", command.getVlans(), "seqno", command.getSeqNo());
        s_logger.debug("set flow for " + command.getVmName() + " " + result);
        if (result != null && result.equalsIgnoreCase("SUCCESS")) {
            return new OvsSetTagAndFlowAnswer(command, true, result);
        } else {
            return new OvsSetTagAndFlowAnswer(command, false, result);
        }
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to set tag and flow", e);
    } catch (final XenAPIException e) {
        s_logger.error("Failed to set tag and flow", e);
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to set tag and flow", e);
    }
    return new OvsSetTagAndFlowAnswer(command, false, "EXCEPTION");
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsSetTagAndFlowAnswer(com.cloud.agent.api.OvsSetTagAndFlowAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

XmlRpcException (org.apache.xmlrpc.XmlRpcException)100 XenAPIException (com.xensource.xenapi.Types.XenAPIException)75 Connection (com.xensource.xenapi.Connection)49 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)35 Answer (com.cloud.agent.api.Answer)33 IOException (java.io.IOException)27 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)26 Network (com.xensource.xenapi.Network)25 Test (org.junit.Test)25 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)22 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 Host (com.xensource.xenapi.Host)21 RebootAnswer (com.cloud.agent.api.RebootAnswer)20 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)20 HashMap (java.util.HashMap)20 VM (com.xensource.xenapi.VM)17 VDI (com.xensource.xenapi.VDI)16 ConfigurationException (javax.naming.ConfigurationException)16 SR (com.xensource.xenapi.SR)15 InternalErrorException (com.cloud.exception.InternalErrorException)13