Search in sources :

Example 11 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method getHostVmStateReport.

protected HashMap<String, HostVmStateReportEntry> getHostVmStateReport(final Connection conn) {
    // TODO : new VM sync model does not require a cluster-scope report, we
    // need to optimize
    // the report accordingly
    final HashMap<String, HostVmStateReportEntry> vmStates = new HashMap<>();
    Map<VM, VM.Record> vm_map = null;
    for (int i = 0; i < 2; i++) {
        try {
            // USE THIS TO GET ALL VMS FROM
            vm_map = VM.getAllRecords(conn);
            // A CLUSTER
            break;
        } catch (XmlRpcException | XenAPIException e) {
            s_logger.warn("Unable to get vms", e);
        }
        try {
            Thread.sleep(1000);
        } catch (final InterruptedException e) {
            s_logger.warn("Caught (previously ignored) interrupted exception", e);
        }
    }
    if (vm_map == null) {
        return vmStates;
    }
    for (final VM.Record record : vm_map.values()) {
        if (record.isControlDomain || record.isASnapshot || record.isATemplate) {
            // Skip DOM0
            continue;
        }
        final VmPowerState ps = record.powerState;
        final Host host = record.residentOn;
        String host_uuid = null;
        if (!isRefNull(host)) {
            try {
                host_uuid = host.getUuid(conn);
            } catch (final BadServerResponse e) {
                s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
            } catch (final XenAPIException e) {
                s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
            } catch (final XmlRpcException e) {
                s_logger.error("Failed to get host uuid for host " + host.toWireString(), e);
            }
            if (host_uuid.equalsIgnoreCase(_host.getUuid())) {
                vmStates.put(record.nameLabel, new HostVmStateReportEntry(convertToPowerState(ps), host_uuid));
            }
        }
    }
    return vmStates;
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) HostVmStateReportEntry(com.cloud.agent.api.HostVmStateReportEntry) HashMap(java.util.HashMap) XenAPIException(com.xensource.xenapi.Types.XenAPIException) Host(com.xensource.xenapi.Host) VM(com.xensource.xenapi.VM) VmPowerState(com.xensource.xenapi.Types.VmPowerState) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 12 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.

the class CitrixResourceBase method attachConfigDriveToMigratedVm.

public boolean attachConfigDriveToMigratedVm(final Connection conn, final String vmName, final String ipAddr) {
    try {
        s_logger.debug("Attaching config drive iso device for the VM " + vmName + " In host " + ipAddr);
        final Set<VM> vms = VM.getByNameLabel(conn, vmName);
        final SR sr = getSRByNameLabel(conn, _configDriveSRName + ipAddr);
        // Here you will find only two vdis with the <vmname>.iso.
        // one is from source host and second from dest host
        final Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + ".iso");
        if (vdis.isEmpty()) {
            s_logger.debug("Could not find config drive ISO: " + vmName);
            return false;
        }
        VDI configdriveVdi = null;
        for (final VDI vdi : vdis) {
            final SR vdiSr = vdi.getSR(conn);
            if (vdiSr.getUuid(conn).equals(sr.getUuid(conn))) {
                // get this vdi to attach to vbd
                configdriveVdi = vdi;
                s_logger.debug("VDI for the config drive ISO  " + vdi);
            } else {
                // delete the vdi in source host so that the <vmname>.iso file is get removed
                s_logger.debug("Removing the source host VDI for the config drive ISO  " + vdi);
                vdi.destroy(conn);
            }
        }
        if (configdriveVdi == null) {
            s_logger.debug("Config drive ISO VDI is not found ");
            return false;
        }
        for (final VM vm : vms) {
            // create vbd
            final VBD.Record cfgDriveVbdr = new VBD.Record();
            cfgDriveVbdr.VM = vm;
            cfgDriveVbdr.empty = true;
            cfgDriveVbdr.bootable = false;
            cfgDriveVbdr.userdevice = "autodetect";
            cfgDriveVbdr.mode = Types.VbdMode.RO;
            cfgDriveVbdr.type = Types.VbdType.CD;
            final VBD cfgDriveVBD = VBD.create(conn, cfgDriveVbdr);
            s_logger.debug("Inserting vbd " + configdriveVdi);
            cfgDriveVBD.insert(conn, configdriveVdi);
            break;
        }
        return true;
    } catch (final BadServerResponse e) {
        s_logger.warn("Failed to attach config drive ISO to the VM  " + vmName + " In host " + ipAddr + " due to a bad server response.", e);
        return false;
    } catch (final XenAPIException e) {
        s_logger.warn("Failed to attach config drive ISO to the VM  " + vmName + " In host " + ipAddr + " due to a xapi problem.", e);
        return false;
    } catch (final XmlRpcException e) {
        s_logger.warn("Failed to attach config drive ISO to the VM  " + vmName + " In host " + ipAddr + " due to a problem in a remote call.", e);
        return false;
    }
}
Also used : BadServerResponse(com.xensource.xenapi.Types.BadServerResponse) VM(com.xensource.xenapi.VM) VBD(com.xensource.xenapi.VBD) XenAPIException(com.xensource.xenapi.Types.XenAPIException) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException) SR(com.xensource.xenapi.SR)

Example 13 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.

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(com.cloud.storage.command.CreateObjectAnswer) IntroduceObjectAnswer(com.cloud.storage.command.IntroduceObjectAnswer) Answer(com.cloud.agent.api.Answer) SnapshotAndCopyAnswer(com.cloud.storage.command.SnapshotAndCopyAnswer) AttachPrimaryDataStoreAnswer(com.cloud.storage.command.AttachPrimaryDataStoreAnswer) DettachAnswer(com.cloud.storage.command.DettachAnswer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) AttachAnswer(com.cloud.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 14 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.

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(com.cloud.storage.to.SnapshotObjectTO) CreateObjectAnswer(com.cloud.storage.command.CreateObjectAnswer) IntroduceObjectAnswer(com.cloud.storage.command.IntroduceObjectAnswer) Answer(com.cloud.agent.api.Answer) SnapshotAndCopyAnswer(com.cloud.storage.command.SnapshotAndCopyAnswer) AttachPrimaryDataStoreAnswer(com.cloud.storage.command.AttachPrimaryDataStoreAnswer) DettachAnswer(com.cloud.storage.command.DettachAnswer) CopyCmdAnswer(com.cloud.storage.command.CopyCmdAnswer) AttachAnswer(com.cloud.storage.command.AttachAnswer) PrimaryDataStoreTO(com.cloud.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 15 with BadServerResponse

use of com.xensource.xenapi.Types.BadServerResponse in project cosmic by MissionCriticalCloud.

the class XenServerConnectionPool method slaveLocalLoginWithPassword.

protected Session slaveLocalLoginWithPassword(final Connection conn, final String username, final Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
    Session s = null;
    boolean logged_in = false;
    Exception ex = null;
    while (!logged_in) {
        try {
            s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
            logged_in = true;
        } catch (final BadServerResponse e) {
            logged_in = false;
            ex = e;
        } catch (final XenAPIException e) {
            logged_in = false;
            ex = e;
        } catch (final 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;
            }
        }
    }
    return s;
}
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) Session(com.xensource.xenapi.Session) SSLSession(javax.net.ssl.SSLSession)

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