use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class CiscoVnmcConnectionImpl method sendRequest.
private String sendRequest(String service, String xmlRequest) throws ExecutionException {
HttpClient client = new HttpClient();
String response = null;
PostMethod method = new PostMethod("/xmlIM/" + service);
method.setRequestBody(xmlRequest);
try {
org.apache.commons.httpclient.protocol.Protocol myhttps = new org.apache.commons.httpclient.protocol.Protocol("https", new EasySSLProtocolSocketFactory(), 443);
client.getHostConfiguration().setHost(_ip, 443, myhttps);
int statusCode = client.executeMethod(method);
if (statusCode != HttpStatus.SC_OK) {
throw new Exception("Error code : " + statusCode);
}
response = method.getResponseBodyAsString();
} catch (Exception e) {
System.out.println(e.getMessage());
throw new ExecutionException(e.getMessage());
}
System.out.println(response);
return response;
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class CiscoVnmcConnectionImpl method getDocument.
/*
* XML utils
*/
private Document getDocument(String xml) throws ExecutionException {
StringReader xmlReader = new StringReader("<?xml version=\"1.0\"?> \n" + xml.trim());
InputSource xmlSource = new InputSource(xmlReader);
Document doc = null;
try {
doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlSource);
} catch (Exception e) {
s_logger.error(e);
throw new ExecutionException(e.getMessage());
}
if (doc == null) {
throw new ExecutionException("Failed to parse xml " + xml);
} else {
return doc;
}
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class NetscalerResource method createAutoScaleConfig.
private synchronized boolean createAutoScaleConfig(final LoadBalancerTO loadBalancerTO) throws ExecutionException, Exception {
final String srcIp = loadBalancerTO.getSrcIp();
final int srcPort = loadBalancerTO.getSrcPort();
final String lbProtocol = getNetScalerProtocol(loadBalancerTO);
final String lbAlgorithm = loadBalancerTO.getAlgorithm();
generateAutoScaleVmGroupIdentifier(loadBalancerTO);
final String nsVirtualServerName = generateNSVirtualServerName(srcIp, srcPort);
final AutoScaleVmGroupTO vmGroupTO = loadBalancerTO.getAutoScaleVmGroupTO();
if (s_logger.isDebugEnabled()) {
s_logger.debug("Created load balancing virtual server " + nsVirtualServerName + " on the Netscaler device");
}
addLBVirtualServer(nsVirtualServerName, srcIp, srcPort, lbAlgorithm, lbProtocol, loadBalancerTO.getStickinessPolicies(), vmGroupTO);
final String serviceGroupName = generateAutoScaleServiceGroupName(loadBalancerTO);
if (!nsServiceGroupExists(serviceGroupName)) {
// add servicegroup lb_autoscaleGroup -autoscale POLICY -memberPort 80
final int memberPort = vmGroupTO.getMemberPort();
try {
final servicegroup serviceGroup = new servicegroup();
serviceGroup.set_servicegroupname(serviceGroupName);
serviceGroup.set_servicetype(lbProtocol);
serviceGroup.set_autoscale("POLICY");
serviceGroup.set_memberport(memberPort);
servicegroup.add(_netscalerService, serviceGroup);
} catch (final Exception e) {
throw e;
}
}
if (!isServiceGroupBoundToVirtualServer(nsVirtualServerName, serviceGroupName)) {
// Bind autoscale service group
// bind lb vserver lb lb_autoscaleGroup
final lbvserver_servicegroup_binding vserver_servicegroup_binding = new lbvserver_servicegroup_binding();
try {
vserver_servicegroup_binding.set_name(nsVirtualServerName);
vserver_servicegroup_binding.set_servicegroupname(serviceGroupName);
lbvserver_servicegroup_binding.add(_netscalerService, vserver_servicegroup_binding);
} catch (final Exception e) {
throw e;
}
}
// Create the autoscale config
if (!loadBalancerTO.getAutoScaleVmGroupTO().getState().equals("disabled")) {
// on restart of network, there might be vmgrps in disabled state, no need to create autoscale config for them
enableAutoScaleConfig(loadBalancerTO, false);
} else if (loadBalancerTO.getAutoScaleVmGroupTO().getState().equals("disabled")) {
disableAutoScaleConfig(loadBalancerTO, false);
}
return true;
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class NetscalerResource method validateInterfaces.
private void validateInterfaces(final String publicInterface, final String privateInterface) throws ExecutionException {
try {
if (!_isSdx && !_cloudManaged) {
final Interface publicIf = Interface.get(_netscalerService, publicInterface);
final Interface privateIf = Interface.get(_netscalerService, privateInterface);
if (publicIf != null || privateIf != null) {
return;
} else {
throw new ExecutionException("Invalid interface name specified for public/private interfaces.");
}
}
} catch (final nitro_exception e) {
if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
throw new ExecutionException("Invalid interface name specified for public and private interfaces.");
} else {
throw new ExecutionException("Failed to verify public interface and private intefaces are valid due to " + e.getMessage());
}
} catch (final Exception e) {
throw new ExecutionException("Failed to verify public interface and private intefaces are valid due to " + e.getMessage());
}
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class NetscalerResource method nsSnipExists.
private boolean nsSnipExists(final String subnetIp) throws ExecutionException {
try {
final nsip tmpSubnetIp = new nsip();
tmpSubnetIp.set_ipaddress(subnetIp);
final nsip snip = nsip.get(_netscalerService, tmpSubnetIp);
return snip != null;
} catch (final nitro_exception e) {
if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
return false;
} else {
throw new ExecutionException("Failed to verify if SNIP exists on the NetScaler device due to " + e.getMessage());
}
} catch (final Exception e) {
throw new ExecutionException("Failed to verify if SNIP exists on the NetScaler device due to " + e.getMessage());
}
}
Aggregations