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());
}
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());
}
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());
}
}
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);
}
}
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);
}
}
Aggregations