use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixResourceBase method cleanupHaltedVms.
public boolean cleanupHaltedVms(final Connection conn) throws XenAPIException, XmlRpcException {
final Host host = Host.getByUuid(conn, _host.getUuid());
final Map<VM, VM.Record> vms = VM.getAllRecords(conn);
boolean success = true;
if (vms != null && !vms.isEmpty()) {
for (final Map.Entry<VM, VM.Record> entry : vms.entrySet()) {
final VM vm = entry.getKey();
final VM.Record vmRec = entry.getValue();
if (vmRec.isATemplate || vmRec.isControlDomain) {
continue;
}
if (VmPowerState.HALTED.equals(vmRec.powerState) && vmRec.affinity.equals(host) && !isAlienVm(vm, conn)) {
try {
vm.destroy(conn);
} catch (final Exception e) {
s_logger.warn("Catch Exception " + e.getClass().getName() + ": unable to destroy VM " + vmRec.nameLabel + " due to ", e);
success = false;
}
}
}
}
return success;
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixResourceBase method getLowestAvailableVIFDeviceNum.
public String getLowestAvailableVIFDeviceNum(final Connection conn, final VM vm) {
String vmName = "";
try {
vmName = vm.getNameLabel(conn);
final List<Integer> usedDeviceNums = new ArrayList<Integer>();
final Set<VIF> vifs = vm.getVIFs(conn);
final Iterator<VIF> vifIter = vifs.iterator();
while (vifIter.hasNext()) {
final VIF vif = vifIter.next();
try {
final String deviceId = vif.getDevice(conn);
if (vm.getIsControlDomain(conn) || vif.getCurrentlyAttached(conn)) {
usedDeviceNums.add(Integer.valueOf(deviceId));
} else {
s_logger.debug("Found unplugged VIF " + deviceId + " in VM " + vmName + " destroy it");
vif.destroy(conn);
}
} catch (final NumberFormatException e) {
final String msg = "Obtained an invalid value for an allocated VIF device number for VM: " + vmName;
s_logger.debug(msg, e);
throw new CloudRuntimeException(msg);
}
}
for (Integer i = 0; i < _maxNics; i++) {
if (!usedDeviceNums.contains(i)) {
s_logger.debug("Lowest available Vif device number: " + i + " for VM: " + vmName);
return i.toString();
}
}
} catch (final XmlRpcException e) {
final String msg = "Caught XmlRpcException: " + e.getMessage();
s_logger.warn(msg, e);
} catch (final XenAPIException e) {
final String msg = "Caught XenAPIException: " + e.toString();
s_logger.warn(msg, e);
}
throw new CloudRuntimeException("Could not find available VIF slot in VM with name: " + vmName);
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class XenServerConnectionPool method loginWithPassword.
protected Session loginWithPassword(Connection conn, String username, Queue<String> password, String version) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.loginWithPassword(conn, username, password.peek(), APIVersion.latest().toString());
logged_in = true;
} catch (BadServerResponse e) {
logged_in = false;
ex = e;
} catch (XenAPIException e) {
logged_in = false;
ex = e;
} catch (XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
}
}
}
return s;
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class XenServerConnectionPool method slaveLocalLoginWithPassword.
protected Session slaveLocalLoginWithPassword(Connection conn, String username, Queue<String> password) throws BadServerResponse, XenAPIException, XmlRpcException {
Session s = null;
boolean logged_in = false;
Exception ex = null;
while (!logged_in) {
try {
s = Session.slaveLocalLoginWithPassword(conn, username, password.peek());
logged_in = true;
} catch (BadServerResponse e) {
logged_in = false;
ex = e;
} catch (XenAPIException e) {
logged_in = false;
ex = e;
} catch (XmlRpcException e) {
logged_in = false;
ex = e;
}
if (logged_in && conn != null) {
break;
} else {
if (password.size() > 1) {
password.remove();
continue;
} else {
// the last password did not work leave it and flag error
if (ex instanceof BadServerResponse) {
throw (BadServerResponse) ex;
} else if (ex instanceof XmlRpcException) {
throw (XmlRpcException) ex;
} else if (ex instanceof Types.SessionAuthenticationFailed) {
throw (Types.SessionAuthenticationFailed) ex;
} else if (ex instanceof XenAPIException) {
throw (XenAPIException) ex;
}
break;
}
}
}
return s;
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixResourceBase method callHostPluginThroughMaster.
protected String callHostPluginThroughMaster(final Connection conn, final String plugin, final String cmd, final String... params) {
final Map<String, String> args = new HashMap<String, String>();
try {
final Map<Pool, Pool.Record> poolRecs = Pool.getAllRecords(conn);
if (poolRecs.size() != 1) {
throw new CloudRuntimeException("There are " + poolRecs.size() + " pool for host :" + _host.getUuid());
}
final Host master = poolRecs.values().iterator().next().master;
for (int i = 0; i < params.length; i += 2) {
args.put(params[i], params[i + 1]);
}
if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin executing for command " + cmd + " with " + getArgsString(args));
}
final String result = master.callPlugin(conn, plugin, cmd, args);
if (s_logger.isTraceEnabled()) {
s_logger.trace("callHostPlugin Result: " + result);
}
return result.replace("\n", "");
} catch (final Types.HandleInvalid e) {
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to HandleInvalid clazz:" + e.clazz + ", handle:" + e.handle);
} catch (final XenAPIException e) {
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.toString(), e);
} catch (final XmlRpcException e) {
s_logger.warn("callHostPlugin failed for cmd: " + cmd + " with args " + getArgsString(args) + " due to " + e.getMessage(), e);
}
return null;
}
Aggregations