use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method getLocalEXTSR.
protected SR getLocalEXTSR(final Connection conn) {
try {
final Map<SR, SR.Record> map = SR.getAllRecords(conn);
if (map != null && !map.isEmpty()) {
for (final Map.Entry<SR, SR.Record> entry : map.entrySet()) {
final SR.Record srRec = entry.getValue();
if (SRType.FILE.equals(srRec.type) || SRType.EXT.equals(srRec.type)) {
final Set<PBD> pbds = srRec.PBDs;
if (pbds == null) {
continue;
}
for (final PBD pbd : pbds) {
final Host host = pbd.getHost(conn);
if (!isRefNull(host) && host.getUuid(conn).equals(_host.getUuid())) {
if (!pbd.getCurrentlyAttached(conn)) {
pbd.plug(conn);
}
final SR sr = entry.getKey();
sr.scan(conn);
return sr;
}
}
}
}
}
} catch (final XenAPIException e) {
final String msg = "Unable to get local EXTSR in host:" + _host.getUuid() + e.toString();
s_logger.warn(msg);
} catch (final XmlRpcException e) {
final String msg = "Unable to get local EXTSR in host:" + _host.getUuid() + e.getCause();
s_logger.warn(msg);
}
return null;
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class CitrixResourceBase method probeScisiId.
private String probeScisiId(Connection conn, Host host, Map<String, String> deviceConfig, String type, String srNameLabel, String lunid, Map<String, String> smConfig) throws XenAPIException, XmlRpcException {
SR sr = null;
String scsiid = null;
try {
sr = SR.create(conn, host, deviceConfig, new Long(0), srNameLabel, srNameLabel, type, "user", true, smConfig);
} catch (final XenAPIException e) {
final String errmsg = e.toString();
if (errmsg.contains("SR_BACKEND_FAILURE_107")) {
final String[] lun = errmsg.split("<LUN>");
boolean found = false;
for (int i = 1; i < lun.length; i++) {
final int blunindex = lun[i].indexOf("<LUNid>") + 7;
final int elunindex = lun[i].indexOf("</LUNid>");
String ilun = lun[i].substring(blunindex, elunindex);
ilun = ilun.trim();
if (ilun.equals(lunid)) {
final int bscsiindex = lun[i].indexOf("<SCSIid>") + 8;
final int escsiindex = lun[i].indexOf("</SCSIid>");
scsiid = lun[i].substring(bscsiindex, escsiindex);
scsiid = scsiid.trim();
found = true;
break;
}
}
if (!found) {
final String msg = "can not find LUN " + lunid + " in " + errmsg;
s_logger.warn(msg);
throw new CloudRuntimeException(msg);
}
} else {
final String msg = "Unable to create Iscsi SR " + deviceConfig + " due to " + e.toString();
s_logger.warn(msg, e);
throw new CloudRuntimeException(msg, e);
}
}
return scsiid;
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class NotAValidCommand method testClusterVMMetaDataSyncCommand.
@Test
public void testClusterVMMetaDataSyncCommand() {
final String uuid = "6172d8b7-ba10-4a70-93f9-ecaf41f51d53";
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final Pool pool = PowerMockito.mock(Pool.class);
final Pool.Record poolr = Mockito.mock(Pool.Record.class);
final Host.Record hostr = Mockito.mock(Host.Record.class);
final Host master = Mockito.mock(Host.class);
final ClusterVMMetaDataSyncCommand vmDataSync = new ClusterVMMetaDataSyncCommand(10, 1l);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
try {
when(citrixResourceBase.getHost()).thenReturn(xsHost);
when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
PowerMockito.mockStatic(Pool.Record.class);
when(pool.getRecord(conn)).thenReturn(poolr);
poolr.master = master;
when(poolr.master.getRecord(conn)).thenReturn(hostr);
hostr.uuid = uuid;
} catch (final BadServerResponse e) {
fail(e.getMessage());
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(vmDataSync, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertTrue(answer.getResult());
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class NotAValidCommand method testOvsDeleteFlowCommandFailure.
@Test
public void testOvsDeleteFlowCommandFailure() {
final String bridge = "gre";
final Connection conn = Mockito.mock(Connection.class);
final Network network = Mockito.mock(Network.class);
final OvsDeleteFlowCommand deleteFlowCommand = new OvsDeleteFlowCommand("Test");
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.setupvSwitchNetwork(conn)).thenReturn(network);
try {
when(network.getBridge(conn)).thenReturn(bridge);
when(citrixResourceBase.callHostPlugin(conn, "ovsgre", "ovs_delete_flow", "bridge", bridge, "vmName", deleteFlowCommand.getVmName())).thenReturn("FAILED");
} catch (final BadServerResponse e) {
fail(e.getMessage());
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(deleteFlowCommand, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
verify(citrixResourceBase, times(1)).setIsOvs(true);
assertFalse(answer.getResult());
}
use of com.xensource.xenapi.Types.XenAPIException in project cloudstack by apache.
the class NotAValidCommand method testScaleVmCommand.
@Test
public void testScaleVmCommand() {
final String uuid = "6172d8b7-ba10-4a70-93f9-ecaf41f51d53";
final VirtualMachineTO machineTO = Mockito.mock(VirtualMachineTO.class);
final Connection conn = Mockito.mock(Connection.class);
final XsHost xsHost = Mockito.mock(XsHost.class);
final Host host = Mockito.mock(Host.class);
final ScaleVmCommand scaleVm = new ScaleVmCommand(machineTO);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
when(citrixResourceBase.getConnection()).thenReturn(conn);
when(citrixResourceBase.getHost()).thenReturn(xsHost);
when(citrixResourceBase.getHost().getUuid()).thenReturn(uuid);
try {
when(citrixResourceBase.isDmcEnabled(conn, host)).thenReturn(true);
} catch (final XenAPIException e) {
fail(e.getMessage());
} catch (final XmlRpcException e) {
fail(e.getMessage());
}
final Answer answer = wrapper.execute(scaleVm, citrixResourceBase);
verify(citrixResourceBase, times(1)).getConnection();
assertFalse(answer.getResult());
}
Aggregations