cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [05/50] git commit: updated refs/heads/ui-cisco-asa1000v-support to ac07a54
Date Thu, 02 May 2013 17:31:11 GMT
CLOUDSTACK-2292: GSLB: server object need to be created when 'zone load
balancer' is configured on different LB service provider

creating a server object before creating GSLB service


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/09af1503
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/09af1503
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/09af1503

Branch: refs/heads/ui-cisco-asa1000v-support
Commit: 09af15035b9febe6f55e73a1389f950ab042564f
Parents: e7f4bfe
Author: Murali Reddy <murali.reddy@citrix.com>
Authored: Tue Apr 30 14:13:51 2013 +0530
Committer: Murali Reddy <murali.reddy@citrix.com>
Committed: Tue Apr 30 14:15:54 2013 +0530

----------------------------------------------------------------------
 .../cloud/network/resource/NetscalerResource.java  |   64 ++++++++++++++-
 1 files changed, 60 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/09af1503/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
index b82176b..677bc78 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/network/resource/NetscalerResource.java
@@ -1211,6 +1211,18 @@ public class NetscalerResource implements ServerResource {
             try {
                 gslbservice service;
                 service = getServiceObject(client, serviceName);
+                String gslbServerName = generateGslbServerName(serviceIp);
+
+                if (!gslbServerExists(client, gslbServerName)) {
+                    base_response apiCallResult;
+                    com.citrix.netscaler.nitro.resource.config.basic.server nsServer = new
com.citrix.netscaler.nitro.resource.config.basic.server();
+                    nsServer.set_name(gslbServerName);
+                    nsServer.set_ipaddress(serviceIp);
+                    apiCallResult = com.citrix.netscaler.nitro.resource.config.basic.server.add(client,
nsServer);
+                    if ((apiCallResult.errorcode != 0) && (apiCallResult.errorcode
!= NitroError.NS_RESOURCE_EXISTS)) {
+                        throw new ExecutionException("Failed to add server " + gslbServerName
+ " due to" + apiCallResult.message);
+                    }
+                }
 
                 boolean isUpdateSite = false;
                 if (service == null) {
@@ -1220,7 +1232,7 @@ public class NetscalerResource implements ServerResource {
                 }
 
                 service.set_sitename(siteName);
-                service.set_servername(serviceIp);
+                service.set_servername(gslbServerName);
                 int port = Integer.parseInt(servicePort);
                 service.set_port(port);
                 service.set_servicename(serviceName);
@@ -1236,7 +1248,7 @@ public class NetscalerResource implements ServerResource {
                     s_logger.debug("Successfully created service: " + serviceName + " at
site: " + siteName);
                 }
             } catch (Exception e) {
-                String errMsg = "Failed to created service: " + serviceName + " at site:
" + siteName;
+                String errMsg = "Failed to created service: " + serviceName + " at site:
" + siteName + " due to " + e.getMessage();
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug(errMsg);
                 }
@@ -1284,7 +1296,7 @@ public class NetscalerResource implements ServerResource {
                     }
                 }
             } catch (Exception e) {
-                String errMsg = "Failed to update service: " + serviceName + " at site: "
+ siteName;
+                String errMsg = "Failed to update service: " + serviceName + " at site: "
+ siteName + "due to " + e.getMessage();
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug(errMsg);
                 }
@@ -1294,6 +1306,7 @@ public class NetscalerResource implements ServerResource {
 
         private static void createVserverServiceBinding(nitro_service client, String serviceName,
String vserverName)
                     throws ExecutionException {
+            String errMsg;
             try {
                 gslbvserver_gslbservice_binding binding = new gslbvserver_gslbservice_binding();
                 binding.set_name(vserverName);
@@ -1303,8 +1316,18 @@ public class NetscalerResource implements ServerResource {
                     s_logger.debug("Successfully created service: " + serviceName + " and
virtual server: "
                             + vserverName + " binding");
                 }
+            } catch (nitro_exception ne) {
+                if (ne.getErrorCode() == 273) {
+                    return;
+                }
+                errMsg = "Failed to create service: " + serviceName + " and virtual server:
"
+                        + vserverName + " binding due to " + ne.getMessage();
+                if (s_logger.isDebugEnabled()) {
+                    s_logger.debug(errMsg);
+                }
+                throw new ExecutionException(errMsg);
             } catch (Exception e) {
-                String errMsg = "Failed to create service: " + serviceName + " and virtual
server: "
+                errMsg = "Failed to create service: " + serviceName + " and virtual server:
"
                         + vserverName + " binding due to " + e.getMessage();
                 if (s_logger.isDebugEnabled()) {
                     s_logger.debug(errMsg);
@@ -1437,6 +1460,39 @@ public class NetscalerResource implements ServerResource {
         private static String generateUniqueServiceName(String siteName, String publicIp,
String publicPort) {
             return "cloud-gslb-service-" + siteName + "-" + publicIp + "-" + publicPort;
         }
+
+        private static boolean gslbServerExists(nitro_service client, String serverName)
throws ExecutionException {
+            try {
+                if (com.citrix.netscaler.nitro.resource.config.basic.server.get(client, serverName)
!= null) {
+                    return true;
+                } else {
+                    return false;
+                }
+            } catch (nitro_exception e) {
+                if (e.getErrorCode() == NitroError.NS_RESOURCE_NOT_EXISTS) {
+                    return false;
+                } else {
+                    throw new ExecutionException("Failed to verify Server " + serverName
+ " exists on the NetScaler device due to " + e.getMessage());
+                }
+            } catch (Exception e) {
+                throw new ExecutionException("Failed to verify Server " + serverName + "
exists on the NetScaler device due to " + e.getMessage());
+            }
+        }
+
+        private static String generateGslbServerName(String serverIP) {
+            return genGslbObjectName("Cloud-Server-",  serverIP);
+        }
+
+        private static String genGslbObjectName(Object... args) {
+            String objectName = "";
+            for (int i = 0; i < args.length; i++) {
+                objectName += args[i];
+                if (i != args.length -1) {
+                    objectName += "-";
+                }
+            }
+            return objectName;
+        }
     }
 
 


Mime
View raw message