use of org.apache.xmlrpc.XmlRpcException in project intellij-community by JetBrains.
the class GitSSHXmlRpcClient method getLastSuccessful.
/**
* {@inheritDoc}
*/
@Override
@SuppressWarnings("unchecked")
public String getLastSuccessful(String token, String userName) {
if (myClient == null) {
return "";
}
Vector parameters = new Vector();
parameters.add(token);
parameters.add(userName);
try {
return (String) myClient.execute(methodName("getLastSuccessful"), parameters);
} catch (XmlRpcException | IOException e) {
log("getLastSuccessful failed. token: " + token + ", userName: " + userName + ", client: " + myClient.getURL());
throw new RuntimeException("Invocation failed " + e.getMessage(), e);
}
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class ConnectionTest method callTimeoutInSec.
@Override
public Object callTimeoutInSec(String method, List<?> params, int timeout, boolean debug) throws XmlRpcException {
XmlRpcStreamConfig config = new XmlRpcHttpRequestConfigImpl();
XmlRpcClient client = new XmlRpcClient();
client.setTypeFactory(new RpcTypeFactory(client));
XmlRpcResponseParser parser = new XmlRpcResponseParser((XmlRpcStreamRequestConfig) config, client.getTypeFactory());
XMLReader xr = SAXParsers.newXMLReader();
xr.setContentHandler(parser);
try {
String result = null;
if (getMethodResponse(method) != null) {
result = getMethodResponse(method);
LOGGER.debug("methodresponse call: " + method + " - " + params);
LOGGER.trace("methodresponse reply: " + result);
}
if (result == null && multiRes.size() >= 0) {
result = getResult();
LOGGER.debug("getresult call: " + method + " - " + params);
LOGGER.trace("getresult reply: " + result);
}
xr.parse(new InputSource(new StringReader(result)));
} catch (Exception e) {
throw new XmlRpcException("Exception: " + e.getMessage(), e);
}
if (parser.getErrorCode() != 0) {
throw new XmlRpcException("Fault received[" + parser.getErrorCode() + "]: " + parser.getErrorMessage());
}
return parser.getResult();
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class CitrixAttachOrDettachConfigDriveCommandWrapper method execute.
@Override
public Answer execute(final AttachOrDettachConfigDriveCommand command, final CitrixResourceBase citrixResourceBase) {
final Connection conn = citrixResourceBase.getConnection();
String vmName = command.getVmName();
List<String[]> vmData = command.getVmData();
String label = command.getConfigDriveLabel();
Boolean isAttach = command.isAttach();
try {
Set<VM> vms = VM.getByNameLabel(conn, vmName);
for (VM vm : vms) {
if (isAttach) {
if (!citrixResourceBase.createAndAttachConfigDriveIsoForVM(conn, vm, vmData, label)) {
s_logger.debug("Failed to attach config drive iso to VM " + vmName);
}
} else {
// delete the config drive iso attached to VM
Set<VDI> vdis = VDI.getByNameLabel(conn, vmName + ".iso");
if (vdis != null && !vdis.isEmpty()) {
s_logger.debug("Deleting config drive for the VM " + vmName);
VDI vdi = vdis.iterator().next();
// Find the VM's CD-ROM VBD
Set<VBD> vbds = vdi.getVBDs(conn);
for (VBD vbd : vbds) {
VBD.Record vbdRec = vbd.getRecord(conn);
if (vbdRec.type.equals(Types.VbdType.CD) && !vbdRec.empty && !vbdRec.userdevice.equals(citrixResourceBase._attachIsoDeviceNum)) {
if (vbdRec.currentlyAttached) {
vbd.eject(conn);
}
vbd.destroy(conn);
}
}
vdi.destroy(conn);
}
s_logger.debug("Successfully dettached config drive iso from the VM " + vmName);
}
}
} catch (Types.XenAPIException ex) {
s_logger.debug("Failed to attach config drive iso to VM " + vmName + " " + ex.getMessage());
} catch (XmlRpcException ex) {
s_logger.debug("Failed to attach config drive iso to VM " + vmName + " " + ex.getMessage());
}
return new Answer(command, true, "success");
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class XenServerStorageProcessor method deleteVolume.
@Override
public Answer deleteVolume(final DeleteCommand cmd) {
final DataTO volume = cmd.getData();
final Connection conn = hypervisorResource.getConnection();
String errorMsg = null;
try {
final VDI vdi = VDI.getByUuid(conn, volume.getPath());
for (VDI svdi : vdi.getSnapshots(conn)) {
deleteVDI(conn, svdi);
}
deleteVDI(conn, vdi);
return new Answer(null);
} catch (final BadServerResponse e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
} catch (final XenAPIException e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
} catch (final XmlRpcException e) {
s_logger.debug("Failed to delete volume", e);
errorMsg = e.toString();
}
return new Answer(null, false, errorMsg);
}
use of org.apache.xmlrpc.XmlRpcException in project cloudstack by apache.
the class OvmDiscoverer method find.
@Override
public Map<? extends ServerResource, Map<String, String>> find(long dcId, Long podId, Long clusterId, URI url, String username, String password, List<String> hostTags) throws DiscoveryException {
Connection conn = null;
if (!url.getScheme().equals("http")) {
String msg = "urlString is not http so we're not taking care of the discovery for this: " + url;
s_logger.debug(msg);
return null;
}
if (clusterId == null) {
String msg = "must specify cluster Id when add host";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
if (podId == null) {
String msg = "must specify pod Id when add host";
s_logger.debug(msg);
throw new CloudRuntimeException(msg);
}
ClusterVO cluster = _clusterDao.findById(clusterId);
if (cluster == null || (cluster.getHypervisorType() != HypervisorType.Ovm)) {
if (s_logger.isInfoEnabled())
s_logger.info("invalid cluster id or cluster is not for Ovm hypervisors");
return null;
}
String agentUsername = _params.get("agentusername");
if (agentUsername == null) {
throw new CloudRuntimeException("Agent user name must be specified");
}
String agentPassword = _params.get("agentpassword");
if (agentPassword == null) {
throw new CloudRuntimeException("Agent password must be specified");
}
try {
String hostname = url.getHost();
InetAddress ia = InetAddress.getByName(hostname);
String hostIp = ia.getHostAddress();
String guid = UUID.nameUUIDFromBytes(hostIp.getBytes()).toString();
if (checkIfExisted(guid)) {
throw new CloudRuntimeException("The host " + hostIp + " has been added before");
}
s_logger.debug("Ovm discover is going to disover host having guid " + guid);
ClusterVO clu = _clusterDao.findById(clusterId);
if (clu.getGuid() == null) {
clu.setGuid(UUID.randomUUID().toString());
_clusterDao.update(clusterId, clu);
}
com.trilead.ssh2.Connection sshConnection = new com.trilead.ssh2.Connection(hostIp, 22);
sshConnection.connect(null, 60000, 60000);
sshConnection = SSHCmdHelper.acquireAuthorizedConnection(hostIp, username, password);
if (sshConnection == null) {
throw new DiscoveryException(String.format("Cannot connect to ovm host(IP=%1$s, username=%2$s, password=%3$s, discover failed", hostIp, username, password));
}
if (!SSHCmdHelper.sshExecuteCmd(sshConnection, "[ -f '/etc/ovs-agent/agent.ini' ]")) {
throw new DiscoveryException("Can not find /etc/ovs-agent/agent.ini " + hostIp);
}
Map<String, String> details = new HashMap<String, String>();
OvmResourceBase ovmResource = new OvmResourceBase();
details.put("ip", hostIp);
details.put("username", username);
details.put("password", password);
details.put("zone", Long.toString(dcId));
details.put("guid", guid);
details.put("pod", Long.toString(podId));
details.put("cluster", Long.toString(clusterId));
details.put("agentusername", agentUsername);
details.put("agentpassword", agentPassword);
if (_publicNetworkDevice != null) {
details.put("public.network.device", _publicNetworkDevice);
}
if (_privateNetworkDevice != null) {
details.put("private.network.device", _privateNetworkDevice);
}
if (_guestNetworkDevice != null) {
details.put("guest.network.device", _guestNetworkDevice);
}
Map<String, Object> params = new HashMap<String, Object>();
params.putAll(details);
ovmResource.configure("Ovm Server", params);
ovmResource.start();
conn = new Connection(hostIp, "oracle", agentPassword);
/* After resource start, we are able to execute our agent api */
OvmHost.Details d = OvmHost.getDetails(conn);
details.put("agentVersion", d.agentVersion);
details.put(HostInfo.HOST_OS_KERNEL_VERSION, d.dom0KernelVersion);
details.put(HostInfo.HYPERVISOR_VERSION, d.hypervisorVersion);
Map<OvmResourceBase, Map<String, String>> resources = new HashMap<OvmResourceBase, Map<String, String>>();
resources.put(ovmResource, details);
return resources;
} catch (XmlRpcException e) {
s_logger.debug("XmlRpc exception, Unable to discover OVM: " + url, e);
return null;
} catch (UnknownHostException e) {
s_logger.debug("Host name resolve failed exception, Unable to discover OVM: " + url, e);
return null;
} catch (ConfigurationException e) {
s_logger.debug("Configure resource failed, Unable to discover OVM: " + url, e);
return null;
} catch (Exception e) {
s_logger.debug("Unable to discover OVM: " + url, e);
return null;
}
}
Aggregations