use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class PaloAltoResource method validResponse.
/* A default response handler to validate that the request was successful. */
public boolean validResponse(String response) throws ExecutionException {
NodeList response_body;
Document doc = getDocument(response);
XPath xpath = XPathFactory.newInstance().newXPath();
try {
XPathExpression expr = xpath.compile("/response[@status='success']");
response_body = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
throw new ExecutionException(e.getCause().getMessage());
}
if (response_body.getLength() > 0) {
return true;
} else {
NodeList error_details;
try {
XPathExpression expr = xpath.compile("/response/msg/line/line");
error_details = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
throw new ExecutionException(e.getCause().getMessage());
}
if (error_details.getLength() == 0) {
try {
XPathExpression expr = xpath.compile("/response/msg/line");
error_details = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
throw new ExecutionException(e.getCause().getMessage());
}
if (error_details.getLength() == 0) {
try {
XPathExpression expr = xpath.compile("/response/result/msg");
error_details = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
} catch (XPathExpressionException e) {
throw new ExecutionException(e.getCause().getMessage());
}
}
}
String error = "";
for (int i = 0; i < error_details.getLength(); i++) {
error = error + error_details.item(i).getTextContent() + "\n";
}
throw new ExecutionException(error);
}
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class F5BigIpResource method addVirtualServer.
// Virtual server methods
private void addVirtualServer(String virtualServerName, LbProtocol protocol, String srcIp, int srcPort, StickinessPolicyTO[] stickyPolicies) throws ExecutionException {
try {
if (!virtualServerExists(virtualServerName)) {
s_logger.debug("Adding virtual server " + virtualServerName);
_virtualServerApi.create(genVirtualServerDefinition(virtualServerName, protocol, srcIp, srcPort), new String[] { "255.255.255.255" }, genVirtualServerResource(virtualServerName), genVirtualServerProfile(protocol));
_virtualServerApi.set_snat_automap(genStringArray(virtualServerName));
if (!virtualServerExists(virtualServerName)) {
throw new ExecutionException("Failed to add virtual server " + virtualServerName);
}
}
if ((stickyPolicies != null) && (stickyPolicies.length > 0) && (stickyPolicies[0] != null)) {
StickinessPolicyTO stickinessPolicy = stickyPolicies[0];
if (StickinessMethodType.LBCookieBased.getName().equalsIgnoreCase(stickinessPolicy.getMethodName())) {
String[] profileNames = genStringArray("Cookie-profile-" + virtualServerName);
if (!persistenceProfileExists(profileNames[0])) {
LocalLBPersistenceMode[] lbPersistenceMode = new iControl.LocalLBPersistenceMode[1];
lbPersistenceMode[0] = iControl.LocalLBPersistenceMode.PERSISTENCE_MODE_COOKIE;
_persistenceProfileApi.create(profileNames, lbPersistenceMode);
_virtualServerApi.add_persistence_profile(genStringArray(virtualServerName), genPersistenceProfile(profileNames[0]));
}
List<Pair<String, String>> paramsList = stickinessPolicy.getParams();
for (Pair<String, String> param : paramsList) {
if ("holdtime".equalsIgnoreCase(param.first())) {
//F5 default
long timeout = 180;
if (param.second() != null) {
timeout = Long.parseLong(param.second());
}
LocalLBProfileULong[] cookieTimeout = new LocalLBProfileULong[1];
cookieTimeout[0] = new LocalLBProfileULong();
cookieTimeout[0].setValue(timeout);
_persistenceProfileApi.set_cookie_expiration(profileNames, cookieTimeout);
}
}
}
} else {
_virtualServerApi.remove_all_persistence_profiles(genStringArray(virtualServerName));
}
} catch (RemoteException e) {
throw new ExecutionException(e.getMessage());
}
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class F5BigIpResource method getIpBytesSentAndReceived.
// Stats methods
private ExternalNetworkResourceUsageAnswer getIpBytesSentAndReceived(ExternalNetworkResourceUsageCommand cmd) throws ExecutionException {
ExternalNetworkResourceUsageAnswer answer = new ExternalNetworkResourceUsageAnswer(cmd);
try {
LocalLBVirtualServerVirtualServerStatistics stats = _virtualServerApi.get_all_statistics();
for (LocalLBVirtualServerVirtualServerStatisticEntry entry : stats.getStatistics()) {
String virtualServerIp = entry.getVirtual_server().getAddress();
virtualServerIp = stripRouteDomainFromAddress(virtualServerIp);
long[] bytesSentAndReceived = answer.ipBytes.get(virtualServerIp);
if (bytesSentAndReceived == null) {
bytesSentAndReceived = new long[] { 0, 0 };
}
for (CommonStatistic stat : entry.getStatistics()) {
int index;
if (stat.getType().equals(CommonStatisticType.STATISTIC_CLIENT_SIDE_BYTES_OUT)) {
// Add to the outgoing bytes
index = 0;
} else if (stat.getType().equals(CommonStatisticType.STATISTIC_CLIENT_SIDE_BYTES_IN)) {
// Add to the incoming bytes
index = 1;
} else {
continue;
}
long high = stat.getValue().getHigh();
long low = stat.getValue().getLow();
long full = getFullUsage(high, low);
bytesSentAndReceived[index] += full;
}
if (bytesSentAndReceived[0] >= 0 && bytesSentAndReceived[1] >= 0) {
answer.ipBytes.put(virtualServerIp, bytesSentAndReceived);
}
}
} catch (Exception e) {
s_logger.error(e);
throw new ExecutionException(e.getMessage());
}
return answer;
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class F5BigIpResource method getStrippedVlans.
//getVlans retuns vlan names without user partition information
//ex: if vlanname is vlan-100 then the get_list() will return /Common/vlan-100
// This method will strip the partition information and only returns a list with vlan name (vlan-100)
private List<String> getStrippedVlans() throws ExecutionException {
try {
List<String> vlans = new ArrayList<String>();
String[] vlansArray = _vlanApi.get_list();
for (String vlan : vlansArray) {
if (vlan.contains("/")) {
vlans.add(vlan.substring(vlan.lastIndexOf("/") + 1));
} else {
vlans.add(vlan);
}
}
return vlans;
} catch (RemoteException e) {
throw new ExecutionException(e.getMessage());
}
}
use of com.cloud.utils.exception.ExecutionException in project cloudstack by apache.
the class F5BigIpResource method deletePoolMember.
private void deletePoolMember(String virtualServerName, String destIp, int destPort) throws ExecutionException {
try {
String memberIdentifier = destIp + "-" + destPort;
List<String> lbPools = getAllStrippedLbPools();
if (lbPools.contains(virtualServerName) && memberExists(virtualServerName, memberIdentifier)) {
s_logger.debug("Deleting member " + memberIdentifier + " from pool for virtual server " + virtualServerName);
_loadbalancerApi.remove_member(genStringArray(virtualServerName), genMembers(destIp, destPort));
if (memberExists(virtualServerName, memberIdentifier)) {
throw new ExecutionException("Failed to delete member " + memberIdentifier + " from pool for virtual server " + virtualServerName);
}
if (nodeExists(destIp)) {
boolean nodeNeeded = false;
done: for (String poolToCheck : lbPools) {
for (String memberInPool : getMembers(poolToCheck)) {
if (getIpAndPort(memberInPool)[0].equals(destIp)) {
nodeNeeded = true;
break done;
}
}
}
if (!nodeNeeded) {
s_logger.debug("Deleting node " + destIp);
_nodeApi.delete_node_address(genStringArray(destIp));
if (nodeExists(destIp)) {
throw new ExecutionException("Failed to delete node " + destIp);
}
}
}
}
} catch (RemoteException e) {
throw new ExecutionException(e.getMessage());
}
}
Aggregations