Search in sources :

Example 16 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method migrateVM.

public void migrateVM(final Connection conn, final Host destHost, final VM vm, final String vmName) throws Exception {
    Task task = null;
    try {
        final Map<String, String> other = new HashMap<String, String>();
        other.put("live", "true");
        task = vm.poolMigrateAsync(conn, destHost, other);
        try {
            // poll every 1 seconds
            final long timeout = _migratewait * 1000L;
            waitForTask(conn, task, 1000, timeout);
            checkForSuccess(conn, task);
        } catch (final Types.HandleInvalid e) {
            if (vm.getResidentOn(conn).equals(destHost)) {
                task = null;
                return;
            }
            throw new CloudRuntimeException("migrate VM catch HandleInvalid and VM is not running on dest host");
        }
    } catch (final XenAPIException e) {
        final String msg = "Unable to migrate VM(" + vmName + ") from host(" + _host.getUuid() + ")";
        s_logger.warn(msg, e);
        throw new CloudRuntimeException(msg);
    } finally {
        if (task != null) {
            try {
                task.destroy(conn);
            } catch (final Exception e1) {
                s_logger.debug("unable to destroy task(" + task.toString() + ") on host(" + _host.getUuid() + ") due to " + e1.toString());
            }
        }
    }
}
Also used : Types(com.xensource.xenapi.Types) Task(com.xensource.xenapi.Task) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 17 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method destroyPatchVbd.

public void destroyPatchVbd(final Connection conn, final String vmName) throws XmlRpcException, XenAPIException {
    try {
        if (!vmName.startsWith("r-") && !vmName.startsWith("s-") && !vmName.startsWith("v-")) {
            return;
        }
        final Set<VM> vms = VM.getByNameLabel(conn, vmName);
        for (final VM vm : vms) {
            final Set<VBD> vbds = vm.getVBDs(conn);
            for (final VBD vbd : vbds) {
                if (vbd.getType(conn) == Types.VbdType.CD) {
                    vbd.eject(conn);
                    vbd.destroy(conn);
                    break;
                }
            }
        }
    } catch (final Exception e) {
        s_logger.debug("Cannot destory CD-ROM device for VM " + vmName + " due to " + e.toString(), e);
    }
}
Also used : VM(com.xensource.xenapi.VM) VBD(com.xensource.xenapi.VBD) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 18 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method callHostPlugin.

public String callHostPlugin(final Connection conn, final String plugin, final String cmd, final String... params) {
    final Map<String, String> args = new HashMap<String, String>();
    String msg;
    try {
        for (int i = 0; i < params.length; i += 2) {
            args.put(params[i], params[i + 1]);
        }
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
        }
        final Host host = Host.getByUuid(conn, _host.getUuid());
        final String result = host.callPlugin(conn, plugin, cmd, args);
        if (s_logger.isTraceEnabled()) {
            s_logger.trace("callHostPlugin Result: " + result);
        }
        return result.replace("\n", "");
    } catch (final XenAPIException e) {
        msg = "callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString();
        s_logger.warn(msg);
    } catch (final XmlRpcException e) {
        msg = "callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage();
        s_logger.debug(msg);
    }
    throw new CloudRuntimeException(msg);
}
Also used : HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 19 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method getIscsiSR.

public SR getIscsiSR(final Connection conn, final String srNameLabel, final String target, String path, final String chapInitiatorUsername, final String chapInitiatorPassword, final boolean resignature, final String srType, final boolean ignoreIntroduceException) {
    synchronized (srNameLabel.intern()) {
        final Map<String, String> deviceConfig = new HashMap<String, String>();
        try {
            if (path.endsWith("/")) {
                path = path.substring(0, path.length() - 1);
            }
            final String[] tmp = path.split("/");
            if (tmp.length != 3) {
                final String msg = "Wrong iscsi path " + path + " it should be /targetIQN/LUN";
                s_logger.warn(msg);
                throw new CloudRuntimeException(msg);
            }
            final String targetiqn = tmp[1].trim();
            final String lunid = tmp[2].trim();
            String scsiid = "";
            //Throws an exception if SR already exists and is attached
            checkIfIscsiSrExisits(conn, srNameLabel, target, targetiqn, lunid);
            // We now know the SR is not attached to the XenServer. We probe the
            // LUN to see if an SR was already exists on it, if so, we just
            // attach it or else we create a brand new SR
            deviceConfig.put("target", target);
            deviceConfig.put("targetIQN", targetiqn);
            if (StringUtils.isNotBlank(chapInitiatorUsername) && StringUtils.isNotBlank(chapInitiatorPassword)) {
                deviceConfig.put("chapuser", chapInitiatorUsername);
                deviceConfig.put("chappassword", chapInitiatorPassword);
            }
            final Host host = Host.getByUuid(conn, _host.getUuid());
            final Map<String, String> smConfig = new HashMap<String, String>();
            SR sr = null;
            String pooluuid = null;
            if (SRType.LVMOISCSI.equals(srType)) {
                scsiid = probeScisiId(conn, host, deviceConfig, srType, srNameLabel, lunid, smConfig);
                deviceConfig.put("SCSIid", scsiid);
                String result = SR.probe(conn, host, deviceConfig, srType, smConfig);
                if (result.indexOf("<UUID>") != -1) {
                    pooluuid = result.substring(result.indexOf("<UUID>") + 6, result.indexOf("</UUID>")).trim();
                }
            }
            if (pooluuid == null || pooluuid.length() != 36) {
                sr = SR.create(conn, host, deviceConfig, new Long(0), srNameLabel, srNameLabel, srType, "user", true, smConfig);
            } else {
                if (resignature) {
                    // We resignature the SR for managed storage if needed. At the end of this
                    // we have an SR which is ready to be attached. For VHDoISCSI SR,
                    // we don't need to resignature
                    pooluuid = resignatureIscsiSr(conn, host, deviceConfig, srNameLabel, smConfig);
                }
                sr = introduceAndPlugIscsiSr(conn, pooluuid, srNameLabel, srType, smConfig, deviceConfig, ignoreIntroduceException);
            }
            sr.scan(conn);
            return sr;
        } catch (final XenAPIException e) {
            final String msg = "Unable to create Iscsi SR  " + deviceConfig + " due to  " + e.toString();
            s_logger.warn(msg, e);
            throw new CloudRuntimeException(msg, e);
        } catch (final Exception e) {
            final String msg = "Unable to create Iscsi SR  " + deviceConfig + " due to  " + e.getMessage();
            s_logger.warn(msg, e);
            throw new CloudRuntimeException(msg, e);
        }
    }
}
Also used : HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SR(com.xensource.xenapi.SR)

Example 20 with XenAPIException

use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.

the class CitrixResourceBase method cleanupTemplateSR.

public void cleanupTemplateSR(final Connection conn) {
    Set<PBD> pbds = null;
    try {
        final Host host = Host.getByUuid(conn, _host.getUuid());
        pbds = host.getPBDs(conn);
    } catch (final XenAPIException e) {
        s_logger.warn("Unable to get the SRs " + e.toString(), e);
        throw new CloudRuntimeException("Unable to get SRs " + e.toString(), e);
    } catch (final Exception e) {
        throw new CloudRuntimeException("Unable to get SRs " + e.getMessage(), e);
    }
    for (final PBD pbd : pbds) {
        SR sr = null;
        SR.Record srRec = null;
        try {
            sr = pbd.getSR(conn);
            srRec = sr.getRecord(conn);
        } catch (final Exception e) {
            s_logger.warn("pbd.getSR get Exception due to ", e);
            continue;
        }
        final String type = srRec.type;
        if (srRec.shared) {
            continue;
        }
        if (SRType.NFS.equals(type) || SRType.ISO.equals(type) && srRec.nameDescription.contains("template")) {
            try {
                pbd.unplug(conn);
                pbd.destroy(conn);
                sr.forget(conn);
            } catch (final Exception e) {
                s_logger.warn("forget SR catch Exception due to ", e);
            }
        }
    }
}
Also used : PBD(com.xensource.xenapi.PBD) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) TimeoutException(java.util.concurrent.TimeoutException) SAXException(org.xml.sax.SAXException) InternalErrorException(com.cloud.exception.InternalErrorException) ConfigurationException(javax.naming.ConfigurationException) MalformedURLException(java.net.MalformedURLException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SR(com.xensource.xenapi.SR)

Aggregations

XenAPIException (com.xensource.xenapi.Types.XenAPIException)101 XmlRpcException (org.apache.xmlrpc.XmlRpcException)93 Connection (com.xensource.xenapi.Connection)56 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)53 Answer (com.cloud.agent.api.Answer)33 InternalErrorException (com.cloud.exception.InternalErrorException)31 SR (com.xensource.xenapi.SR)30 Host (com.xensource.xenapi.Host)29 Network (com.xensource.xenapi.Network)27 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)26 VDI (com.xensource.xenapi.VDI)25 IOException (java.io.IOException)25 HashMap (java.util.HashMap)25 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)25 Test (org.junit.Test)25 ConfigurationException (javax.naming.ConfigurationException)22 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 MalformedURLException (java.net.MalformedURLException)21 URISyntaxException (java.net.URISyntaxException)21 TimeoutException (java.util.concurrent.TimeoutException)21