Search in sources :

Example 16 with PBD

use of com.xensource.xenapi.PBD in project cloudstack by apache.

the class Xenserver625StorageProcessor method createFileSR.

protected SR createFileSR(final Connection conn, final String path) {
    SR sr = null;
    PBD pbd = null;
    try {
        final String srname = path.trim();
        synchronized (srname.intern()) {
            final Set<SR> srs = SR.getByNameLabel(conn, srname);
            if (srs != null && !srs.isEmpty()) {
                return srs.iterator().next();
            }
            final Map<String, String> smConfig = new HashMap<String, String>();
            final Host host = Host.getByUuid(conn, hypervisorResource.getHost().getUuid());
            final String uuid = UUID.randomUUID().toString();
            sr = SR.introduce(conn, uuid, srname, srname, "file", "file", false, smConfig);
            final PBD.Record record = new PBD.Record();
            record.host = host;
            record.SR = sr;
            smConfig.put("location", path);
            record.deviceConfig = smConfig;
            pbd = PBD.create(conn, record);
            pbd.plug(conn);
            sr.scan(conn);
        }
        return sr;
    } catch (final Exception ex) {
        try {
            if (pbd != null) {
                pbd.destroy(conn);
            }
        } catch (final Exception e1) {
            s_logger.debug("Failed to destroy PBD", ex);
        }
        try {
            if (sr != null) {
                sr.forget(conn);
            }
        } catch (final Exception e2) {
            s_logger.error("Failed to forget SR", ex);
        }
        final String msg = "createFileSR failed! due to the following: " + ex.toString();
        s_logger.warn(msg, ex);
        throw new CloudRuntimeException(msg, ex);
    }
}
Also used : PBD(com.xensource.xenapi.PBD) HashMap(java.util.HashMap) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Host(com.xensource.xenapi.Host) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) SR(com.xensource.xenapi.SR)

Aggregations

PBD (com.xensource.xenapi.PBD)16 SR (com.xensource.xenapi.SR)15 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 Host (com.xensource.xenapi.Host)10 XenAPIException (com.xensource.xenapi.Types.XenAPIException)10 XmlRpcException (org.apache.xmlrpc.XmlRpcException)9 HashMap (java.util.HashMap)5 InternalErrorException (com.cloud.exception.InternalErrorException)4 VDI (com.xensource.xenapi.VDI)3 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 Map (java.util.Map)2 TimeoutException (java.util.concurrent.TimeoutException)2 ConfigurationException (javax.naming.ConfigurationException)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 SAXException (org.xml.sax.SAXException)2 Answer (com.cloud.agent.api.Answer)1 Connection (com.xensource.xenapi.Connection)1 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)1