use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class NetscalerResource method addLBMonitor.
// Monitor related methods
private void addLBMonitor(final String nsMonitorName, final String lbProtocol, final HealthCheckPolicyTO hcp) throws ExecutionException {
try {
// check if the monitor exists
boolean csMonitorExisis = false;
final lbmonitor csMonitor = getMonitorIfExisits(nsMonitorName);
if (csMonitor != null) {
if (!csMonitor.get_type().equalsIgnoreCase(lbProtocol)) {
throw new ExecutionException("Can not update monitor :" + nsMonitorName + " as current protocol:" + csMonitor.get_type() + " of monitor is different from the " + " intended protocol:" + lbProtocol);
}
csMonitorExisis = true;
}
if (!csMonitorExisis) {
final lbmonitor csMon = new lbmonitor();
csMon.set_monitorname(nsMonitorName);
csMon.set_type(lbProtocol);
if (lbProtocol.equalsIgnoreCase("HTTP")) {
csMon.set_httprequest(hcp.getpingPath());
s_logger.trace("LB Protocol is HTTP, Applying ping path on HealthCheck Policy");
} else {
s_logger.debug("LB Protocol is not HTTP, Skipping to apply ping path on HealthCheck Policy");
}
csMon.set_interval(hcp.getHealthcheckInterval());
csMon.set_retries(Math.max(hcp.getHealthcheckThresshold(), hcp.getUnhealthThresshold()) + 1);
csMon.set_resptimeout(hcp.getResponseTime());
csMon.set_failureretries(hcp.getUnhealthThresshold());
csMon.set_successretries(hcp.getHealthcheckThresshold());
s_logger.debug("Monitor properites going to get created :interval :: " + csMon.get_interval() + "respTimeOUt:: " + csMon.get_resptimeout() + "failure retires(unhealththresshold) :: " + csMon.get_failureretries() + "successtries(healththresshold) ::" + csMon.get_successretries());
lbmonitor.add(_netscalerService, csMon);
} else {
s_logger.debug("Monitor :" + nsMonitorName + " is already existing. Skipping to delete and create it");
}
} catch (final nitro_exception e) {
throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage());
} catch (final Exception e) {
throw new ExecutionException("Failed to create new monitor :" + nsMonitorName + " due to " + e.getMessage());
}
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class NetscalerResource method execute.
private synchronized Answer execute(final IpAssocCommand cmd, final int numRetries) {
if (_isSdx) {
return Answer.createUnsupportedCommandAnswer(cmd);
}
final String[] results = new String[cmd.getIpAddresses().length];
int i = 0;
try {
final IpAddressTO[] ips = cmd.getIpAddresses();
for (final IpAddressTO ip : ips) {
final long guestVlanTag = Long.parseLong(ip.getBroadcastUri());
final String vlanSelfIp = ip.getVlanGateway();
final String vlanNetmask = ip.getVlanNetmask();
if (ip.isAdd()) {
// Add a new guest VLAN and its subnet and bind it to private interface
addGuestVlanAndSubnet(guestVlanTag, vlanSelfIp, vlanNetmask, true);
} else {
// Check and delete guest VLAN with this tag, self IP, and netmask
deleteGuestVlan(guestVlanTag, vlanSelfIp, vlanNetmask);
}
saveConfiguration();
results[i++] = ip.getPublicIp() + " - success";
final String action = ip.isAdd() ? "associate" : "remove";
if (s_logger.isDebugEnabled()) {
s_logger.debug("Netscaler load balancer " + _ip + " successfully executed IPAssocCommand to " + action + " IP " + ip);
}
}
} catch (final ExecutionException e) {
s_logger.error("Netscaler loadbalancer " + _ip + " failed to execute IPAssocCommand due to " + e.getMessage());
if (shouldRetry(numRetries)) {
return retry(cmd, numRetries);
} else {
results[i++] = IpAssocAnswer.errorResult;
}
}
return new IpAssocAnswer(cmd, results);
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class NetscalerResource method removeLBVirtualServer.
private void removeLBVirtualServer(final String virtualServerName) throws ExecutionException {
try {
final lbvserver vserver = lbvserver.get(_netscalerService, virtualServerName);
if (vserver == null) {
return;
}
apiCallResult = lbvserver.delete(_netscalerService, vserver);
if (apiCallResult.errorcode != 0) {
throw new ExecutionException("Failed to delete virtual server:" + virtualServerName + " due to " + apiCallResult.message);
}
} catch (final nitro_exception e) {
if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
return;
} else {
throw new ExecutionException("Failed remove virtual server:" + virtualServerName + " due to " + e.getMessage());
}
} catch (final Exception e) {
throw new ExecutionException("Failed to remove virtual server:" + virtualServerName + " due to " + e.getMessage());
}
}
Aggregations