Search in sources :

Example 1 with XmlRpcException

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

the class XmlRpcDataFormat method unmarshalResponse.

protected Object unmarshalResponse(Exchange exchange, InputStream stream) throws Exception {
    InputSource isource = new InputSource(stream);
    XMLReader xr = newXMLReader();
    XmlRpcResponseParser xp;
    try {
        xp = new XmlRpcResponseParser(xmlRpcStreamRequestConfig, typeFactory);
        xr.setContentHandler(xp);
        xr.parse(isource);
    } catch (SAXException e) {
        throw new XmlRpcClientException("Failed to parse server's response: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new XmlRpcClientException("Failed to read server's response: " + e.getMessage(), e);
    }
    if (xp.isSuccess()) {
        return xp.getResult();
    }
    Throwable t = xp.getErrorCause();
    if (t == null) {
        throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage());
    }
    if (t instanceof XmlRpcException) {
        throw (XmlRpcException) t;
    }
    if (t instanceof RuntimeException) {
        throw (RuntimeException) t;
    }
    throw new XmlRpcException(xp.getErrorCode(), xp.getErrorMessage(), t);
}
Also used : InputSource(org.xml.sax.InputSource) XmlRpcClientException(org.apache.xmlrpc.client.XmlRpcClientException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcResponseParser(org.apache.xmlrpc.parser.XmlRpcResponseParser) SAXException(org.xml.sax.SAXException)

Example 2 with XmlRpcException

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

the class XmlRpcDataFormat method getXMLWriter.

protected XMLWriter getXMLWriter(Exchange exchange, OutputStream outputStream) throws XmlRpcException {
    XMLWriter writer = new CharSetXMLWriter();
    String encoding = IOHelper.getCharsetName(exchange);
    writer.setEncoding(encoding);
    writer.setIndenting(false);
    writer.setFlushing(true);
    try {
        writer.setWriter(new BufferedWriter(new OutputStreamWriter(outputStream, encoding)));
    } catch (UnsupportedEncodingException e) {
        throw new XmlRpcException("Unsupported encoding: " + encoding, e);
    }
    return writer;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) CharSetXMLWriter(org.apache.ws.commons.serialize.CharSetXMLWriter) OutputStreamWriter(java.io.OutputStreamWriter) CharSetXMLWriter(org.apache.ws.commons.serialize.CharSetXMLWriter) XMLWriter(org.apache.ws.commons.serialize.XMLWriter) XmlRpcException(org.apache.xmlrpc.XmlRpcException) BufferedWriter(java.io.BufferedWriter)

Example 3 with XmlRpcException

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

the class OvmResourceBase method execute.

protected Answer execute(PrepareOCFS2NodesCommand cmd) {
    List<Ternary<Integer, String, String>> nodes = cmd.getNodes();
    StringBuffer params = new StringBuffer();
    for (Ternary<Integer, String, String> node : nodes) {
        String param = String.format("%1$s:%2$s:%3$s", node.first(), node.second(), node.third());
        params.append(param);
        params.append(";");
    }
    try {
        OvmStoragePool.prepareOCFS2Nodes(_conn, cmd.getClusterName(), params.toString());
        return new Answer(cmd, true, "Success");
    } catch (XmlRpcException e) {
        s_logger.debug("OCFS2 prepare nodes failed", e);
        return new Answer(cmd, false, e.getMessage());
    }
}
Also used : FenceAnswer(com.cloud.agent.api.FenceAnswer) MaintainAnswer(com.cloud.agent.api.MaintainAnswer) GetHostStatsAnswer(com.cloud.agent.api.GetHostStatsAnswer) GetVncPortAnswer(com.cloud.agent.api.GetVncPortAnswer) RebootAnswer(com.cloud.agent.api.RebootAnswer) CreatePrivateTemplateAnswer(com.cloud.agent.api.storage.CreatePrivateTemplateAnswer) ModifyStoragePoolAnswer(com.cloud.agent.api.ModifyStoragePoolAnswer) PrimaryStorageDownloadAnswer(com.cloud.agent.api.storage.PrimaryStorageDownloadAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) StartAnswer(com.cloud.agent.api.StartAnswer) GetStorageStatsAnswer(com.cloud.agent.api.GetStorageStatsAnswer) MigrateAnswer(com.cloud.agent.api.MigrateAnswer) CheckNetworkAnswer(com.cloud.agent.api.CheckNetworkAnswer) GetVmStatsAnswer(com.cloud.agent.api.GetVmStatsAnswer) StopAnswer(com.cloud.agent.api.StopAnswer) Answer(com.cloud.agent.api.Answer) CheckVirtualMachineAnswer(com.cloud.agent.api.CheckVirtualMachineAnswer) CopyVolumeAnswer(com.cloud.agent.api.storage.CopyVolumeAnswer) ReadyAnswer(com.cloud.agent.api.ReadyAnswer) PrepareForMigrationAnswer(com.cloud.agent.api.PrepareForMigrationAnswer) SecurityGroupRuleAnswer(com.cloud.agent.api.SecurityGroupRuleAnswer) Ternary(com.cloud.utils.Ternary) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 4 with XmlRpcException

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

the class Connection method callTimeoutInSec.

public Object callTimeoutInSec(String method, List<?> params, int timeout, boolean debug) throws XmlRpcException {
    TimingOutCallback callback = new TimingOutCallback(timeout * 1000);
    if (debug) {
        LOGGER.debug("Call Ovm3 agent " + hostName + "(" + hostIp + "): " + method + " with " + params);
    }
    long startTime = System.currentTimeMillis();
    try {
        /* returns actual xml */
        XmlRpcClientRequestImpl req = new XmlRpcClientRequestImpl(xmlClient.getClientConfig(), method, params);
        xmlClient.executeAsync(req, callback);
        return callback.waitForResponse();
    } catch (TimingOutCallback.TimeoutException e) {
        LOGGER.info("Timeout: ", e);
        throw new XmlRpcException(e.getMessage());
    } catch (XmlRpcException e) {
        LOGGER.info("XML RPC Exception occured: ", e);
        throw e;
    } catch (RuntimeException e) {
        LOGGER.info("Runtime Exception: ", e);
        throw new XmlRpcException(e.getMessage());
    } catch (Throwable e) {
        LOGGER.error("Holy crap batman!: ", e);
        throw new XmlRpcException(e.getMessage(), e);
    } finally {
        long endTime = System.currentTimeMillis();
        /* in seconds */
        float during = (endTime - startTime) / (float) 1000;
        LOGGER.debug("Ovm3 call " + method + " finished in " + during + " secs, on " + hostIp + ":" + hostPort);
    }
}
Also used : XmlRpcClientRequestImpl(org.apache.xmlrpc.client.XmlRpcClientRequestImpl) TimingOutCallback(org.apache.xmlrpc.client.TimingOutCallback) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Example 5 with XmlRpcException

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

the class OvmResourceBase method execute.

@Override
public StopAnswer execute(StopCommand cmd) {
    String vmName = cmd.getVmName();
    try {
        OvmVm.Details vm = null;
        try {
            vm = OvmVm.getDetails(_conn, vmName);
        } catch (XmlRpcException e) {
            s_logger.debug("Unable to get details of vm: " + vmName + ", treating it as stopped", e);
            return new StopAnswer(cmd, "success", true);
        }
        deleteAllNetworkRulesForVm(vmName);
        OvmVm.stop(_conn, vmName);
        cleanup(vm);
        return new StopAnswer(cmd, "success", true);
    } catch (Exception e) {
        s_logger.debug("Stop " + vmName + "failed", e);
        return new StopAnswer(cmd, e.getMessage(), false);
    }
}
Also used : OvmVm(com.cloud.ovm.object.OvmVm) StopAnswer(com.cloud.agent.api.StopAnswer) XmlRpcException(org.apache.xmlrpc.XmlRpcException) XmlRpcException(org.apache.xmlrpc.XmlRpcException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ConfigurationException(javax.naming.ConfigurationException)

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