Search in sources :

Example 51 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project intellij-community by JetBrains.

the class GitSSHXmlRpcClient method getLastSuccessful.

/**
   * {@inheritDoc}
   */
@Override
@SuppressWarnings("unchecked")
public String getLastSuccessful(String token, String userName) {
    if (myClient == null) {
        return "";
    }
    Vector parameters = new Vector();
    parameters.add(token);
    parameters.add(userName);
    try {
        return (String) myClient.execute(methodName("getLastSuccessful"), parameters);
    } catch (XmlRpcException | IOException e) {
        log("getLastSuccessful failed. token: " + token + ", userName: " + userName + ", client: " + myClient.getURL());
        throw new RuntimeException("Invocation failed " + e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) Vector(java.util.Vector) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 52 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class ConnectionTest method callTimeoutInSec.

@Override
public Object callTimeoutInSec(String method, List<?> params, int timeout, boolean debug) throws XmlRpcException {
    XmlRpcStreamConfig config = new XmlRpcHttpRequestConfigImpl();
    XmlRpcClient client = new XmlRpcClient();
    client.setTypeFactory(new RpcTypeFactory(client));
    XmlRpcResponseParser parser = new XmlRpcResponseParser((XmlRpcStreamRequestConfig) config, client.getTypeFactory());
    XMLReader xr = SAXParsers.newXMLReader();
    xr.setContentHandler(parser);
    try {
        String result = null;
        if (getMethodResponse(method) != null) {
            result = getMethodResponse(method);
            LOGGER.debug("methodresponse call: " + method + " - " + params);
            LOGGER.trace("methodresponse reply: " + result);
        }
        if (result == null && multiRes.size() >= 0) {
            result = getResult();
            LOGGER.debug("getresult call: " + method + " - " + params);
            LOGGER.trace("getresult reply: " + result);
        }
        xr.parse(new InputSource(new StringReader(result)));
    } catch (Exception e) {
        throw new XmlRpcException("Exception: " + e.getMessage(), e);
    }
    if (parser.getErrorCode() != 0) {
        throw new XmlRpcException("Fault received[" + parser.getErrorCode() + "]: " + parser.getErrorMessage());
    }
    return parser.getResult();
}
Also used : XmlRpcHttpRequestConfigImpl(org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl) InputSource(org.xml.sax.InputSource) XmlRpcClient(org.apache.xmlrpc.client.XmlRpcClient) StringReader(java.io.StringReader) XmlRpcStreamConfig(org.apache.xmlrpc.common.XmlRpcStreamConfig) XMLReader(org.xml.sax.XMLReader) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcResponseParser(org.apache.xmlrpc.parser.XmlRpcResponseParser)

Example 53 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class CitrixAttachOrDettachConfigDriveCommandWrapper method execute.

@Override
public Answer execute(final AttachOrDettachConfigDriveCommand command, final CitrixResourceBase citrixResourceBase) {
    final Connection conn = citrixResourceBase.getConnection();
    String vmName = command.getVmName();
    List<String[]> vmData = command.getVmData();
    String label = command.getConfigDriveLabel();
    Boolean isAttach = command.isAttach();
    try {
        Set<VM> vms = VM.getByNameLabel(conn, vmName);
        for (VM vm : vms) {
            if (isAttach) {
                if (!citrixResourceBase.createAndAttachConfigDriveIsoForVM(conn, vm, vmData, label)) {
                    s_logger.debug("Failed to attach config drive iso to VM " + vmName);
                }
            } else {
                // delete the config drive iso attached to VM
                Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + ".iso");
                if (vdis != null && !vdis.isEmpty()) {
                    s_logger.debug("Deleting config drive for the VM " + vmName);
                    VDI vdi = vdis.iterator().next();
                    // Find the VM's CD-ROM VBD
                    Set<VBD> vbds = vdi.getVBDs(conn);
                    for (VBD vbd : vbds) {
                        VBD.Record vbdRec = vbd.getRecord(conn);
                        if (vbdRec.type.equals(Types.VbdType.CD) && !vbdRec.empty && !vbdRec.userdevice.equals(citrixResourceBase._attachIsoDeviceNum)) {
                            if (vbdRec.currentlyAttached) {
                                vbd.eject(conn);
                            }
                            vbd.destroy(conn);
                        }
                    }
                    vdi.destroy(conn);
                }
                s_logger.debug("Successfully dettached config drive iso from the VM " + vmName);
            }
        }
    } catch (Types.XenAPIException ex) {
        s_logger.debug("Failed to attach config drive iso to VM " + vmName + " " + ex.getMessage());
    } catch (XmlRpcException ex) {
        s_logger.debug("Failed to attach config drive iso to VM " + vmName + " " + ex.getMessage());
    }
    return new Answer(command, true, "success");
}
Also used : Types(com.xensource.xenapi.Types) Connection(com.xensource.xenapi.Connection) Answer(com.cloud.agent.api.Answer) VM(com.xensource.xenapi.VM) VBD(com.xensource.xenapi.VBD) VDI(com.xensource.xenapi.VDI) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 54 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class XenServerStorageProcessor method deleteVolume.

@Override
public Answer deleteVolume(final DeleteCommand cmd) {
    final DataTO volume = cmd.getData();
    final Connection conn = hypervisorResource.getConnection();
    String errorMsg = null;
    try {
        final VDI vdi = VDI.getByUuid(conn, volume.getPath());
        for (VDI svdi : vdi.getSnapshots(conn)) {
            deleteVDI(conn, svdi);
        }
        deleteVDI(conn, vdi);
        return new Answer(null);
    } catch (final BadServerResponse e) {
        s_logger.debug("Failed to delete volume", e);
        errorMsg = e.toString();
    } catch (final XenAPIException e) {
        s_logger.debug("Failed to delete volume", e);
        errorMsg = e.toString();
    } catch (final XmlRpcException e) {
        s_logger.debug("Failed to delete volume", e);
        errorMsg = e.toString();
    }
    return new Answer(null, false, errorMsg);
}
Also used : 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) DataTO(com.cloud.agent.api.to.DataTO) 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 55 with XmlRpcException

use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.

the class OvmDiscoverer method find.

@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException {
    Connection conn = null;
    if (!url.getScheme().equals("http")) {
        String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
        s_logger.debug(msg);
        return null;
    }
    if (clusterId == null) {
        String msg = "must specify cluster Id when add host";
        s_logger.debug(msg);
        throw new CloudRuntimeException(msg);
    }
    if (podId == null) {
        String msg = "must specify pod Id when add host";
        s_logger.debug(msg);
        throw new CloudRuntimeException(msg);
    }
    ClusterVO cluster = _clusterDao.findById(clusterId);
    if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm)) {
        if (s_logger.isInfoEnabled())
            s_logger.info("invalid cluster id or cluster is not for Ovm hypervisors");
        return null;
    }
    String agentUsername = _params.get("agentusername");
    if (agentUsername == null) {
        throw new CloudRuntimeException("Agent user name must be specified");
    }
    String agentPassword = _params.get("agentpassword");
    if (agentPassword == null) {
        throw new CloudRuntimeException("Agent password must be specified");
    }
    try {
        String hostname = url.getHost();
        InetAddress ia = InetAddress.getByName(hostname);
        String hostIp = ia.getHostAddress();
        String guid = UUID.nameUUIDFromBytes(hostIp.getBytes()).toString();
        if (checkIfExisted(guid)) {
            throw new CloudRuntimeException("The host " + hostIp + " has been added before");
        }
        s_logger.debug("Ovm discover is going to disover host having guid " + guid);
        ClusterVO clu = _clusterDao.findById(clusterId);
        if (clu.getGuid() == null) {
            clu.setGuid(UUID.randomUUID().toString());
            _clusterDao.update(clusterId, clu);
        }
        com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(hostIp, 22);
        sshConnection.connect(null, 60000, 60000);
        sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp, username, password);
        if (sshConnection == null) {
            throw new DiscoveryException(String.format("Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s, discover failed", hostIp, username, password));
        }
        if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/etc/ovs-agent/agent.ini' ]")) {
            throw new DiscoveryException("Can not find /etc/ovs-agent/agent.ini " + hostIp);
        }
        Map<String, String> details = new HashMap<String, String>();
        OvmResourceBase ovmResource = new OvmResourceBase();
        details.put("ip", hostIp);
        details.put("username", username);
        details.put("password", password);
        details.put("zone", Long.toString(dcId));
        details.put("guid", guid);
        details.put("pod", Long.toString(podId));
        details.put("cluster", Long.toString(clusterId));
        details.put("agentusername", agentUsername);
        details.put("agentpassword", agentPassword);
        if (_publicNetworkDevice != null) {
            details.put("public.network.device", _publicNetworkDevice);
        }
        if (_privateNetworkDevice != null) {
            details.put("private.network.device", _privateNetworkDevice);
        }
        if (_guestNetworkDevice != null) {
            details.put("guest.network.device", _guestNetworkDevice);
        }
        Map<String, Object> params = new HashMap<String, Object>();
        params.putAll(details);
        ovmResource.configure("Ovm Server", params);
        ovmResource.start();
        conn = new Connection(hostIp, "oracle", agentPassword);
        /* After resource start, we are able to execute our agent api */
        OvmHost.Details d = OvmHost.getDetails(conn);
        details.put("agentVersion", d.agentVersion);
        details.put(HostInfo.HOST_OS_KERNEL_VERSION, d.dom0KernelVersion);
        details.put(HostInfo.HYPERVISOR_VERSION, d.hypervisorVersion);
        Map<OvmResourceBase, Map<String, String>> resources = new HashMap<OvmResourceBase, Map<String, String>>();
        resources.put(ovmResource, details);
        return resources;
    } catch (XmlRpcException e) {
        s_logger.debug("XmlRpc exception, Unable to discover OVM: " + url, e);
        return null;
    } catch (UnknownHostException e) {
        s_logger.debug("Host name resolve failed exception, Unable to discover OVM: " + url, e);
        return null;
    } catch (ConfigurationException e) {
        s_logger.debug("Configure resource failed, Unable to discover OVM: " + url, e);
        return null;
    } catch (Exception e) {
        s_logger.debug("Unable to discover OVM: " + url, e);
        return null;
    }
}
Also used : ClusterVO(com.cloud.dc.ClusterVO) OvmHost(com.cloud.ovm.object.OvmHost) UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) Connection(com.cloud.ovm.object.Connection) DiscoveryException(com.cloud.exception.DiscoveryException) ConfigurationException(javax.naming.ConfigurationException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnknownHostException(java.net.UnknownHostException) UnableDeleteHostException(com.cloud.resource.UnableDeleteHostException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) InetAddress(java.net.InetAddress) DiscoveryException(com.cloud.exception.DiscoveryException) HashMap(java.util.HashMap) Map(java.util.Map) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

XmlRpcException (org.apache.xmlrpc.XmlRpcException)100 XenAPIException (com.xensource.xenapi.Types.XenAPIException)75 Connection (com.xensource.xenapi.Connection)49 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)35 Answer (com.cloud.agent.api.Answer)33 IOException (java.io.IOException)27 BadServerResponse (com.xensource.xenapi.Types.BadServerResponse)26 Network (com.xensource.xenapi.Network)25 Test (org.junit.Test)25 AttachAnswer (org.apache.cloudstack.storage.command.AttachAnswer)22 XsLocalNetwork (com.cloud.hypervisor.xenserver.resource.XsLocalNetwork)21 Host (com.xensource.xenapi.Host)21 RebootAnswer (com.cloud.agent.api.RebootAnswer)20 CreateAnswer (com.cloud.agent.api.storage.CreateAnswer)20 HashMap (java.util.HashMap)20 VM (com.xensource.xenapi.VM)17 VDI (com.xensource.xenapi.VDI)16 ConfigurationException (javax.naming.ConfigurationException)16 SR (com.xensource.xenapi.SR)15 InternalErrorException (com.cloud.exception.InternalErrorException)13