Search in sources :

Example 36 with XmlRpcException

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

the class NotAValidCommand method testPvlanSetupCommandVmFailure.

@Test
public void testPvlanSetupCommandVmFailure() {
    final String label = "net";
    final Connection conn = Mockito.mock(Connection.class);
    final XsLocalNetwork network = Mockito.mock(XsLocalNetwork.class);
    final Network network2 = Mockito.mock(Network.class);
    final PvlanSetupCommand lanSetup = PvlanSetupCommand.createVmSetup("add", URI.create("http://127.0.0.1"), "tag", "0:0:0:0:0:0");
    final String primaryPvlan = lanSetup.getPrimary();
    final String isolatedPvlan = lanSetup.getIsolated();
    final String op = lanSetup.getOp();
    final String vmMac = lanSetup.getVmMac();
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    try {
        when(citrixResourceBase.getNativeNetworkForTraffic(conn, TrafficType.Guest, "tag")).thenReturn(network);
        when(network.getNetwork()).thenReturn(network2);
        when(network2.getNameLabel(conn)).thenReturn(label);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    when(citrixResourceBase.callHostPlugin(conn, "ovs-pvlan", "setup-pvlan-vm", "op", op, "nw-label", label, "primary-pvlan", primaryPvlan, "isolated-pvlan", isolatedPvlan, "vm-mac", vmMac)).thenReturn("false");
    final Answer answer = wrapper.execute(lanSetup, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    assertFalse(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) PvlanSetupCommand(com.cloud.agent.api.PvlanSetupCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 37 with XmlRpcException

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

the class NotAValidCommand method testOvsDestroyBridgeCommand.

@Test
public void testOvsDestroyBridgeCommand() {
    final Connection conn = Mockito.mock(Connection.class);
    final Network network = Mockito.mock(Network.class);
    final OvsDestroyBridgeCommand destroyBridge = new OvsDestroyBridgeCommand(1l, "bridge", 1l);
    final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
    assertNotNull(wrapper);
    when(citrixResourceBase.getConnection()).thenReturn(conn);
    when(citrixResourceBase.findOrCreateTunnelNetwork(conn, destroyBridge.getBridgeName())).thenReturn(network);
    final Answer answer = wrapper.execute(destroyBridge, citrixResourceBase);
    verify(citrixResourceBase, times(1)).getConnection();
    try {
        verify(citrixResourceBase, times(1)).cleanUpTmpDomVif(conn, network);
    } catch (final XenAPIException e) {
        fail(e.getMessage());
    } catch (final XmlRpcException e) {
        fail(e.getMessage());
    }
    verify(citrixResourceBase, times(1)).destroyTunnelNetwork(conn, network, destroyBridge.getHostId());
    assertTrue(answer.getResult());
}
Also used : RebootAnswer(com.cloud.agent.api.RebootAnswer) CreateAnswer(com.cloud.agent.api.storage.CreateAnswer) AttachAnswer(org.apache.cloudstack.storage.command.AttachAnswer) Answer(com.cloud.agent.api.Answer) Network(com.xensource.xenapi.Network) XsLocalNetwork(com.cloud.hypervisor.xenserver.resource.XsLocalNetwork) Connection(com.xensource.xenapi.Connection) XenAPIException(com.xensource.xenapi.Types.XenAPIException) OvsDestroyBridgeCommand(com.cloud.agent.api.OvsDestroyBridgeCommand) XmlRpcException(org.apache.xmlrpc.XmlRpcException) Test(org.junit.Test)

Example 38 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 39 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 40 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