Search in sources :

Example 1 with BadServerResponse

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

the class Xenserver625StorageProcessor method createTemplateFromSnapshot2.

private Answer createTemplateFromSnapshot2(final CopyCommand cmd) {
    final Connection conn = hypervisorResource.getConnection();
    final SnapshotObjectTO snapshotObjTO = (SnapshotObjectTO) cmd.getSrcTO();
    final TemplateObjectTO templateObjTO = (TemplateObjectTO) cmd.getDestTO();
    if (!(snapshotObjTO.getDataStore() instanceof PrimaryDataStoreTO) || !(templateObjTO.getDataStore() instanceof NfsTO)) {
        return null;
    }
    NfsTO destStore;
    URI destUri;
    try {
        destStore = (NfsTO) templateObjTO.getDataStore();
        destUri = new URI(destStore.getUrl());
    } catch (final Exception ex) {
        s_logger.debug("Invalid URI", ex);
        return new CopyCmdAnswer("Invalid URI: " + ex.toString());
    }
    SR srcSr = null;
    SR destSr = null;
    final String destDir = templateObjTO.getPath();
    VDI destVdi = null;
    boolean result = false;
    try {
        final Map<String, String> srcDetails = cmd.getOptions();
        final String iScsiName = srcDetails.get(DiskTO.IQN);
        final String storageHost = srcDetails.get(DiskTO.STORAGE_HOST);
        final String chapInitiatorUsername = srcDetails.get(DiskTO.CHAP_INITIATOR_USERNAME);
        final String chapInitiatorSecret = srcDetails.get(DiskTO.CHAP_INITIATOR_SECRET);
        String srType;
        srType = CitrixResourceBase.SRType.LVMOISCSI.toString();
        srcSr = hypervisorResource.getIscsiSR(conn, iScsiName, storageHost, iScsiName, chapInitiatorUsername, chapInitiatorSecret, false, srType, true);
        final String destNfsPath = destUri.getHost() + ":" + destUri.getPath();
        final String localDir = BASE_MOUNT_POINT_ON_REMOTE + UUID.nameUUIDFromBytes(destNfsPath.getBytes());
        String nfsVersion = destStore.getNfsVersion();
        mountNfs(conn, destNfsPath, localDir, nfsVersion);
        makeDirectory(conn, localDir + "/" + destDir);
        destSr = createFileSR(conn, localDir + "/" + destDir);
        // there should only be one VDI in this SR
        final VDI srcVdi = srcSr.getVDIs(conn).iterator().next();
        destVdi = srcVdi.copy(conn, destSr);
        final String nameLabel = "cloud-" + UUID.randomUUID().toString();
        destVdi.setNameLabel(conn, nameLabel);
        // scan makes XenServer pick up VDI physicalSize
        destSr.scan(conn);
        final String templateUuid = destVdi.getUuid(conn);
        final String templateFilename = templateUuid + ".vhd";
        final long virtualSize = destVdi.getVirtualSize(conn);
        final long physicalSize = destVdi.getPhysicalUtilisation(conn);
        // create the template.properties file
        String templatePath = destNfsPath + "/" + destDir;
        templatePath = templatePath.replaceAll("//", "/");
        result = hypervisorResource.postCreatePrivateTemplate(conn, templatePath, templateFilename, templateUuid, nameLabel, null, physicalSize, virtualSize, templateObjTO.getId(), nfsVersion);
        if (!result) {
            throw new CloudRuntimeException("Could not create the template.properties file on secondary storage dir");
        }
        final TemplateObjectTO newTemplate = new TemplateObjectTO();
        newTemplate.setPath(destDir + "/" + templateFilename);
        newTemplate.setFormat(Storage.ImageFormat.VHD);
        newTemplate.setHypervisorType(HypervisorType.XenServer);
        newTemplate.setSize(virtualSize);
        newTemplate.setPhysicalSize(physicalSize);
        newTemplate.setName(templateUuid);
        result = true;
        return new CopyCmdAnswer(newTemplate);
    } catch (final BadServerResponse e) {
        s_logger.error("Failed to create a template from a snapshot due to incomprehensible server response", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } catch (final XenAPIException e) {
        s_logger.error("Failed to create a template from a snapshot due to xenapi error", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } catch (final XmlRpcException e) {
        s_logger.error("Failed to create a template from a snapshot due to rpc error", e);
        return new CopyCmdAnswer("Failed to create a template from a snapshot: " + e.toString());
    } finally {
        if (!result) {
            if (destVdi != null) {
                try {
                    destVdi.destroy(conn);
                } catch (final Exception e) {
                    s_logger.debug("Cleaned up leftover VDI on destination storage due to failure: ", e);
                }
            }
        }
        if (srcSr != null) {
            hypervisorResource.removeSR(conn, srcSr);
        }
        if (destSr != null) {
            hypervisorResource.removeSR(conn, destSr);
        }
    }
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) NfsTO(com.cloud.agent.api.to.NfsTO) URI(java.net.URI) InternalErrorException(com.cloud.exception.InternalErrorException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) VDI(com.xensource.xenapi.VDI) TemplateObjectTO(org.apache.cloudstack.storage.to.TemplateObjectTO) CopyCmdAnswer(org.apache.cloudstack.storage.command.CopyCmdAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 2 with BadServerResponse

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

the class XenServerConnectionPool method join.

protected void join(Connection conn, String masterIp, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException, Types.JoiningHostCannotContainSharedSrs {
    boolean logged_in = false;
    Exception ex = null;
    while (!logged_in) {
        try {
            Pool.join(conn, masterIp, username, password.peek());
            logged_in = true;
        } catch (BadServerResponse e) {
            logged_in = false;
            ex = e;
        } catch (XenAPIException e) {
            logged_in = false;
            ex = e;
        } catch (XmlRpcException e) {
            logged_in = false;
            ex = e;
        }
        if (logged_in && conn != null) {
            break;
        } else {
            if (password.size() > 1) {
                password.remove();
                continue;
            } else {
                // the last password did not work leave it and flag error
                if (ex instanceof BadServerResponse) {
                    throw (BadServerResponse) ex;
                } else if (ex instanceof XmlRpcException) {
                    throw (XmlRpcException) ex;
                } else if (ex instanceof Types.SessionAuthenticationFailed) {
                    throw (Types.SessionAuthenticationFailed) ex;
                } else if (ex instanceof XenAPIException) {
                    throw (XenAPIException) ex;
                }
                break;
            }
        }
    }
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) XenAPIException(com.xensource.xenapi.Types.XenAPIException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) XenAPIException(com.xensource.xenapi.Types.XenAPIException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 3 with BadServerResponse

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

the class XenServerStorageProcessor method deleteSnapshot.

@Override
public Answer deleteSnapshot(final DeleteCommand cmd) {
    final SnapshotObjectTO snapshot = (SnapshotObjectTO) cmd.getData();
    final DataStoreTO store = snapshot.getDataStore();
    if (store.getRole() == DataStoreRole.Primary) {
        final Connection conn = hypervisorResource.getConnection();
        final VDI snapshotVdi = getVDIbyUuid(conn, snapshot.getPath());
        if (snapshotVdi == null) {
            return new Answer(null);
        }
        String errMsg = null;
        try {
            deleteVDI(conn, snapshotVdi);
        } catch (final BadServerResponse e) {
            s_logger.debug("delete snapshot failed:" + e.toString());
            errMsg = e.toString();
        } catch (final XenAPIException e) {
            s_logger.debug("delete snapshot failed:" + e.toString());
            errMsg = e.toString();
        } catch (final XmlRpcException e) {
            s_logger.debug("delete snapshot failed:" + e.toString());
            errMsg = e.toString();
        }
        return new Answer(cmd, false, errMsg);
    }
    return new Answer(cmd, false, "unsupported storage type");
}
Also used : SnapshotObjectTO(org.apache.cloudstack.storage.to.SnapshotObjectTO) CreateObjectAnswer(org.apache.cloudstack.storage.command.CreateObjectAnswer) ResignatureAnswer(org.apache.cloudstack.storage.command.ResignatureAnswer) Answer(com.cloud.agent.api.Answer) IntroduceObjectAnswer(org.apache.cloudstack.storage.command.IntroduceObjectAnswer) 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) PrimaryDataStoreTO(org.apache.cloudstack.storage.to.PrimaryDataStoreTO) DataStoreTO(com.cloud.agent.api.to.DataStoreTO) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 4 with BadServerResponse

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

the class CitrixOvsCreateGreTunnelCommandWrapper method execute.

@Override
public Answer execute(final OvsCreateGreTunnelCommand command, final CitrixResourceBase citrixResourceBase) {
    citrixResourceBase.setIsOvs(true);
    final Connection conn = citrixResourceBase.getConnection();
    String bridge = "unkonwn";
    try {
        final Network nw = citrixResourceBase.setupvSwitchNetwork(conn);
        bridge = nw.getBridge(conn);
        final String result = citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_create_gre", "bridge", bridge, "remoteIP", command.getRemoteIp(), "greKey", command.getKey(), "from", Long.toString(command.getFrom()), "to", Long.toString(command.getTo()));
        final String[] res = result.split(":");
        if (res.length != 2 || res.length == 2 && res[1].equalsIgnoreCase("[]")) {
            return new OvsCreateGreTunnelAnswer(command, false, result, citrixResourceBase.getHost().getIp(), bridge);
        } else {
            return new OvsCreateGreTunnelAnswer(command, true, result, citrixResourceBase.getHost().getIp(), bridge, Integer.parseInt(res[1]));
        }
    } catch (final BadServerResponse e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    } catch (final XenAPIException e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    } catch (final XmlRpcException e) {
        s_logger.error("An error occurred while creating a GRE tunnel to " + command.getRemoteIp() + " on host " + citrixResourceBase.getHost().getIp(), e);
    }
    return new OvsCreateGreTunnelAnswer(command, false, "EXCEPTION", citrixResourceBase.getHost().getIp(), bridge);
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) Network(com.xensource.xenapi.Network) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsCreateGreTunnelAnswer(com.cloud.agent.api.OvsCreateGreTunnelAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 5 with BadServerResponse

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

the class CitrixOvsFetchInterfaceCommandWrapper method execute.

@Override
public Answer execute(final OvsFetchInterfaceCommand command, final CitrixResourceBase citrixResourceBase) {
    String label = command.getLabel();
    // FIXME: this is a tricky to pass the network checking in XCP. I temporary get default label from Host.
    if (citrixResourceBase.isXcp()) {
        label = citrixResourceBase.getLabel();
    }
    s_logger.debug("Will look for network with name-label:" + label + " on host " + citrixResourceBase.getHost().getIp());
    final Connection conn = citrixResourceBase.getConnection();
    try {
        final XsLocalNetwork nw = citrixResourceBase.getNetworkByName(conn, label);
        if (nw == null) {
            throw new CloudRuntimeException("Unable to locate the network with name-label: " + label + " on host: " + citrixResourceBase.getHost().getIp());
        }
        s_logger.debug("Network object:" + nw.getNetwork().getUuid(conn));
        final PIF pif = nw.getPif(conn);
        final PIF.Record pifRec = pif.getRecord(conn);
        s_logger.debug("PIF object:" + pifRec.uuid + "(" + pifRec.device + ")");
        return new OvsFetchInterfaceAnswer(command, true, "Interface " + pifRec.device + " retrieved successfully", pifRec.IP, pifRec.netmask, pifRec.MAC);
    } catch (final BadServerResponse e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    } catch (final XenAPIException e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    } catch (final XmlRpcException e) {
        s_logger.error("An error occurred while fetching the interface for " + label + " on host " + citrixResourceBase.getHost().getIp(), e);
        return new OvsFetchInterfaceAnswer(command, false, "EXCEPTION:" + e.getMessage());
    }
}
Also used : XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsFetchInterfaceAnswer(com.cloud.agent.api.OvsFetchInterfaceAnswer) PIF(com.xensource.xenapi.PIF) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)36 XenAPIException (com.xensource.xenapi.Types.XenAPIException)36 XmlRpcException (org.apache.xmlrpc.XmlRpcException)36 Connection (com.xensource.xenapi.Connection)25 Answer (com.cloud.agent.api.Answer)20 Network (com.xensource.xenapi.Network)14 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)14 Test (org.junit.Test)13 VDI (com.xensource.xenapi.VDI)12 RebootAnswer (com.cloud.agent.api.RebootAnswer)11 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)11 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)11 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)11 SR (com.xensource.xenapi.SR)8 FileNotFoundException (java.io.FileNotFoundException)6 IOException (java.io.IOException)6 KeyManagementException (java.security.KeyManagementException)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 XmlRpcClientException (org.apache.xmlrpc.client.XmlRpcClientException)6