Search in sources :

Example 66 with XenAPIException

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

the class XenServerStorageProcessor method getNfsSR.

protected SR getNfsSR(final Connection conn, final StorageFilerTO pool) {
    final Map<String, String> deviceConfig = new HashMap<String, String>();
    try {
        final String server = pool.getHost();
        String serverpath = pool.getPath();
        serverpath = serverpath.replace("//", "/");
        final Set<SR> srs = SR.getAll(conn);
        for (final SR sr : srs) {
            if (!SRType.NFS.equals(sr.getType(conn))) {
                continue;
            }
            final Set<PBD> pbds = sr.getPBDs(conn);
            if (pbds.isEmpty()) {
                continue;
            }
            final PBD pbd = pbds.iterator().next();
            final Map<String, String> dc = pbd.getDeviceConfig(conn);
            if (dc == null) {
                continue;
            }
            if (dc.get("server") == null) {
                continue;
            }
            if (dc.get("serverpath") == null) {
                continue;
            }
            if (server.equals(dc.get("server")) && serverpath.equals(dc.get("serverpath"))) {
                throw new CloudRuntimeException("There is a SR using the same configuration server:" + dc.get("server") + ", serverpath:" + dc.get("serverpath") + " for pool " + pool.getUuid() + "on host:" + hypervisorResource.getHost().getUuid());
            }
        }
        deviceConfig.put("server", server);
        deviceConfig.put("serverpath", serverpath);
        final Host host = Host.getByUuid(conn, hypervisorResource.getHost().getUuid());
        final Map<String, String> smConfig = new HashMap<String, String>();
        smConfig.put("nosubdir", "true");
        final SR sr = SR.create(conn, host, deviceConfig, new Long(0), pool.getUuid(), Long.toString(pool.getId()), SRType.NFS.toString(), "user", true, smConfig);
        sr.scan(conn);
        return sr;
    } catch (final XenAPIException e) {
        throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
    } catch (final XmlRpcException e) {
        throw new CloudRuntimeException("Unable to create NFS SR " + pool.toString(), e);
    }
}
Also used : PBD(com.xensource.xenapi.PBD) 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) SR(com.xensource.xenapi.SR)

Example 67 with XenAPIException

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

the class XenServerStorageProcessor method directDownloadHttpTemplate.

protected Answer directDownloadHttpTemplate(final CopyCommand cmd, final DecodedDataObject srcObj, final DecodedDataObject destObj) {
    final Connection conn = hypervisorResource.getConnection();
    SR poolsr = null;
    VDI vdi = null;
    boolean result = false;
    try {
        if (destObj.getPath() == null) {
        //need to create volume at first
        }
        vdi = VDI.getByUuid(conn, destObj.getPath());
        if (vdi == null) {
            throw new CloudRuntimeException("can't find volume: " + destObj.getPath());
        }
        final String destStoreUuid = destObj.getStore().getUuid();
        final Set<SR> srs = SR.getByNameLabel(conn, destStoreUuid);
        if (srs.size() != 1) {
            throw new CloudRuntimeException("storage uuid: " + destStoreUuid + " is not unique");
        }
        poolsr = srs.iterator().next();
        final VDI.Record vdir = vdi.getRecord(conn);
        final String vdiLocation = vdir.location;
        String pbdLocation = null;
        if (destObj.getStore().getScheme().equalsIgnoreCase(DataStoreProtocol.NFS.toString())) {
            pbdLocation = "/run/sr-mount/" + poolsr.getUuid(conn);
        } else {
            final Set<PBD> pbds = poolsr.getPBDs(conn);
            if (pbds.size() != 1) {
                throw new CloudRuntimeException("Don't how to handle multiple pbds:" + pbds.size() + " for sr: " + poolsr.getUuid(conn));
            }
            final PBD pbd = pbds.iterator().next();
            final Map<String, String> deviceCfg = pbd.getDeviceConfig(conn);
            pbdLocation = deviceCfg.get("location");
        }
        if (pbdLocation == null) {
            throw new CloudRuntimeException("Can't get pbd location");
        }
        final String vdiPath = pbdLocation + "/" + vdiLocation + ".vhd";
        //download a url into vdipath
        //downloadHttpToLocalFile(vdiPath, template.getPath());
        hypervisorResource.callHostPlugin(conn, "storagePlugin", "downloadTemplateFromUrl", "destPath", vdiPath, "srcUrl", srcObj.getPath());
        result = true;
    //return new CopyCmdAnswer(cmd, vdi.getUuid(conn));
    } catch (final BadServerResponse e) {
        s_logger.debug("Failed to download template", e);
    } catch (final XenAPIException e) {
        s_logger.debug("Failed to download template", e);
    } catch (final XmlRpcException e) {
        s_logger.debug("Failed to download template", e);
    } catch (final Exception e) {
        s_logger.debug("Failed to download template", e);
    } finally {
        if (!result && vdi != null) {
            try {
                vdi.destroy(conn);
            } catch (final BadServerResponse e) {
                s_logger.debug("Failed to cleanup newly created vdi");
            } catch (final XenAPIException e) {
                s_logger.debug("Failed to cleanup newly created vdi");
            } catch (final XmlRpcException e) {
                s_logger.debug("Failed to cleanup newly created vdi");
            }
        }
    }
    return new Answer(cmd, false, "Failed to download template");
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) Answer(com.cloud.agent.api.Answer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) AttachPrimaryDataStoreAnswer(org.apache.cloudstack.storage.command.AttachPrimaryDataStoreAnswer) DettachAnswer(org.apache.cloudstack.storage.command.DettachAnswer) SnapshotAndCopyAnswer(org.apache.cloudstack.storage.command.SnapshotAndCopyAnswer) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) PBD(com.xensource.xenapi.PBD) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 68 with XenAPIException

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

the class CitrixResourceBase method getIsoVDIByURL.

public VDI getIsoVDIByURL(final Connection conn, final String vmName, final String isoURL) {
    SR isoSR = null;
    String mountpoint = null;
    if (isoURL.startsWith("xs-tools")) {
        try {
            final Set<VDI> vdis = VDI.getByNameLabel(conn, isoURL);
            if (vdis.isEmpty()) {
                throw new CloudRuntimeException("Could not find ISO with URL: " + isoURL);
            }
            return vdis.iterator().next();
        } catch (final XenAPIException e) {
            throw new CloudRuntimeException("Unable to get pv iso: " + isoURL + " due to " + e.toString());
        } catch (final Exception e) {
            throw new CloudRuntimeException("Unable to get pv iso: " + isoURL + " due to " + e.toString());
        }
    }
    final int index = isoURL.lastIndexOf("/");
    mountpoint = isoURL.substring(0, index);
    URI uri;
    try {
        uri = new URI(mountpoint);
    } catch (final URISyntaxException e) {
        throw new CloudRuntimeException("isoURL is wrong: " + isoURL);
    }
    isoSR = getISOSRbyVmName(conn, vmName);
    if (isoSR == null) {
        isoSR = createIsoSRbyURI(conn, uri, vmName, false);
    }
    final String isoName = isoURL.substring(index + 1);
    final VDI isoVDI = getVDIbyLocationandSR(conn, isoName, isoSR);
    if (isoVDI != null) {
        return isoVDI;
    } else {
        throw new CloudRuntimeException("Could not find ISO with URL: " + isoURL);
    }
}
Also used : CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) 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 69 with XenAPIException

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

the class CitrixResourceBase method getLocalLVMSR.

protected SR getLocalLVMSR(final Connection conn) {
    try {
        final Map<SR, SR.Record> map = SR.getAllRecords(conn);
        if (map != null && !map.isEmpty()) {
            for (final Map.Entry<SR, SR.Record> entry : map.entrySet()) {
                final SR.Record srRec = entry.getValue();
                if (SRType.LVM.equals(srRec.type)) {
                    final Set<PBD> pbds = srRec.PBDs;
                    if (pbds == null) {
                        continue;
                    }
                    for (final PBD pbd : pbds) {
                        final Host host = pbd.getHost(conn);
                        if (!isRefNull(host) && host.getUuid(conn).equals(_host.getUuid())) {
                            if (!pbd.getCurrentlyAttached(conn)) {
                                pbd.plug(conn);
                            }
                            final SR sr = entry.getKey();
                            sr.scan(conn);
                            return sr;
                        }
                    }
                }
            }
        }
    } catch (final XenAPIException e) {
        final String msg = "Unable to get local LVMSR in host:" + _host.getUuid() + e.toString();
        s_logger.warn(msg);
    } catch (final XmlRpcException e) {
        final String msg = "Unable to get local LVMSR in host:" + _host.getUuid() + e.getCause();
        s_logger.warn(msg);
    }
    return null;
}
Also used : PBD(com.xensource.xenapi.PBD) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) Map(java.util.Map) HashMap(java.util.HashMap) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 70 with XenAPIException

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

the class CitrixResourceBase method cleanupHaltedVms.

public boolean cleanupHaltedVms(final Connection conn) throws XenAPIException, XmlRpcException {
    final Host host = Host.getByUuid(conn, _host.getUuid());
    final Map<VM, VM.Record> vms = VM.getAllRecords(conn);
    boolean success = true;
    if (vms != null && !vms.isEmpty()) {
        for (final Map.Entry<VM, VM.Record> entry : vms.entrySet()) {
            final VM vm = entry.getKey();
            final VM.Record vmRec = entry.getValue();
            if (vmRec.isATemplate || vmRec.isControlDomain) {
                continue;
            }
            if (VmPowerState.HALTED.equals(vmRec.powerState) && vmRec.affinity.equals(host) && !isAlienVm(vm, conn)) {
                try {
                    vm.destroy(conn);
                } catch (final Exception e) {
                    s_logger.warn("Catch Exception " + e.getClass().getName() + ": unable to destroy VM " + vmRec.nameLabel + " due to ", e);
                    success = false;
                }
            }
        }
    }
    return success;
}
Also used : VM(com.xensource.xenapi.VM) Host(com.xensource.xenapi.Host) Map(java.util.Map) HashMap(java.util.HashMap) 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)

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