You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mu...@apache.org on 2013/03/27 13:30:53 UTC
[4/4] git commit: updated refs/heads/master to c5fb834
CLOUDSTACK-653 : High Availability: implement GSLB (Global Server Load
Balancing) capability for ELB service
merging GSLB feature
Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/c5fb8349
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/c5fb8349
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/c5fb8349
Branch: refs/heads/master
Commit: c5fb8349bf92b48bca6d06370112f5ec04a9d098
Parents: c7be3b4
Author: Murali Reddy <mu...@citrix.com>
Authored: Wed Mar 27 17:54:07 2013 +0530
Committer: Murali Reddy <mu...@citrix.com>
Committed: Wed Mar 27 17:54:07 2013 +0530
----------------------------------------------------------------------
.../routing/GlobalLoadBalancerConfigAnswer.java | 27 +
.../routing/GlobalLoadBalancerConfigCommand.java | 100 ++
.../agent/api/routing/SiteLoadBalancerConfig.java | 121 ++
api/src/com/cloud/async/AsyncJob.java | 7 +-
api/src/com/cloud/event/EventTypes.java | 6 +
.../cloud/region/ha/GlobalLoadBalancerRule.java | 89 ++
.../region/ha/GlobalLoadBalancingRulesService.java | 47 +
.../org/apache/cloudstack/api/ApiConstants.java | 8 +
.../org/apache/cloudstack/api/BaseAsyncCmd.java | 1 +
.../apache/cloudstack/api/ResponseGenerator.java | 39 +-
.../ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java | 128 ++
.../ha/gslb/CreateGlobalLoadBalancerRuleCmd.java | 179 +++
.../ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java | 108 ++
.../ha/gslb/ListGlobalLoadBalancerRuleCmd.java | 92 ++
.../gslb/RemoveFromGlobalLoadBalancerRuleCmd.java | 125 ++
.../ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java | 96 ++
.../api/response/GlobalLoadBalancerResponse.java | 125 ++
api/src/org/apache/cloudstack/region/Region.java | 49 +
client/tomcatconf/commands.properties.in | 8 +
.../element/F5ExternalLoadBalancerElement.java | 46 +-
.../api/commands/AddNetscalerLoadBalancerCmd.java | 41 +-
.../cloud/network/element/NetscalerElement.java | 155 ++-
.../cloud/network/resource/NetscalerResource.java | 660 +++++++++-
server/src/com/cloud/api/ApiResponseHelper.java | 36 +-
server/src/com/cloud/api/ApiServer.java | 149 +--
server/src/com/cloud/configuration/Config.java | 8 +-
.../network/ExternalLoadBalancerDeviceManager.java | 4 +-
.../ExternalLoadBalancerDeviceManagerImpl.java | 51 +-
.../network/dao/ExternalLoadBalancerDeviceDao.java | 11 +-
.../dao/ExternalLoadBalancerDeviceDaoImpl.java | 25 +-
.../network/dao/ExternalLoadBalancerDeviceVO.java | 51 +-
.../network/lb/LoadBalancingRulesManagerImpl.java | 117 +--
.../src/com/cloud/server/ManagementServerImpl.java | 328 ++---
.../cloudstack/region/RegionServiceProvider.java | 25 +
.../src/org/apache/cloudstack/region/RegionVO.java | 19 +
.../region/gslb/GlobalLoadBalancerDaoImpl.java | 58 +
.../gslb/GlobalLoadBalancerLbRuleMapDao.java | 30 +
.../gslb/GlobalLoadBalancerLbRuleMapDaoImpl.java | 63 +
.../region/gslb/GlobalLoadBalancerLbRuleMapVO.java | 83 ++
.../region/gslb/GlobalLoadBalancerRuleDao.java | 28 +
.../region/gslb/GlobalLoadBalancerRuleVO.java | 183 +++
.../gslb/GlobalLoadBalancingRulesServiceImpl.java | 592 +++++++++
.../region/gslb/GslbServiceProvider.java | 36 +
.../GlobalLoadBalancingRulesServiceImplTest.java | 974 +++++++++++++++
setup/db/db/schema-410to420.sql | 38 +
45 files changed, 4549 insertions(+), 617 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/com/cloud/agent/api/routing/GlobalLoadBalancerConfigAnswer.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/routing/GlobalLoadBalancerConfigAnswer.java b/api/src/com/cloud/agent/api/routing/GlobalLoadBalancerConfigAnswer.java
new file mode 100644
index 0000000..e5167fe
--- /dev/null
+++ b/api/src/com/cloud/agent/api/routing/GlobalLoadBalancerConfigAnswer.java
@@ -0,0 +1,27 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.agent.api.routing;
+
+import com.cloud.agent.api.Answer;
+
+public class GlobalLoadBalancerConfigAnswer extends Answer{
+
+ public GlobalLoadBalancerConfigAnswer(boolean success, String details) {
+ this.result = success;
+ this.details = details;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/com/cloud/agent/api/routing/GlobalLoadBalancerConfigCommand.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/routing/GlobalLoadBalancerConfigCommand.java b/api/src/com/cloud/agent/api/routing/GlobalLoadBalancerConfigCommand.java
new file mode 100644
index 0000000..b3603c8
--- /dev/null
+++ b/api/src/com/cloud/agent/api/routing/GlobalLoadBalancerConfigCommand.java
@@ -0,0 +1,100 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.agent.api.routing;
+
+import com.cloud.agent.api.Command;
+
+import java.util.List;
+
+/**
+ * GlobalLoadBalancerConfigCommand used for sending the GSLB configuration to GSLB service provider
+ */
+public class GlobalLoadBalancerConfigCommand extends Command {
+
+ // FQDN that represents the globally load balanced service
+ String domainName;
+
+ // type of the globally load balanced service
+ String serviceType;
+
+ // load balancing method to distribute traffic across the sites participating in global service load balancing
+ String lbMethod;
+
+ // session persistence type
+ String persistenceType;
+
+ // unique Id given per gslb rule, that is uniquely represents glsb rule on all participant sites
+ long gslbId;
+
+ // true if global load balancer rule is being deleted
+ boolean revoked;
+
+ // list of the site details that are participating in the GSLB service
+ List<SiteLoadBalancerConfig> siteLoadBalancers;
+
+ public GlobalLoadBalancerConfigCommand(String domainName,
+ String lbMethod,
+ String persistenceType,
+ String serviceType,
+ long gslbId,
+ boolean revoked) {
+ this.domainName = domainName;
+ this.serviceType = serviceType;
+ this.lbMethod = lbMethod;
+ this.persistenceType = persistenceType;
+ this.gslbId = gslbId;
+ this.revoked = revoked;
+ }
+
+ public List<SiteLoadBalancerConfig> getSiteDetails() {
+ return siteLoadBalancers;
+ }
+
+ public void setSiteLoadBalancers(List<SiteLoadBalancerConfig> siteLoadBalancers) {
+ this.siteLoadBalancers = siteLoadBalancers;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public String getLoadBalancerMethod() {
+ return lbMethod;
+ }
+
+ public String getPersistenceType() {
+ return persistenceType;
+ }
+
+ public long getGslbId() {
+ return this.gslbId;
+ }
+
+ public String getDomainName() {
+ return domainName;
+ }
+
+ public boolean isForRevoke() {
+ return revoked;
+ }
+
+ @Override
+ public boolean executeInSequence() {
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/com/cloud/agent/api/routing/SiteLoadBalancerConfig.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/agent/api/routing/SiteLoadBalancerConfig.java b/api/src/com/cloud/agent/api/routing/SiteLoadBalancerConfig.java
new file mode 100644
index 0000000..cca5de8
--- /dev/null
+++ b/api/src/com/cloud/agent/api/routing/SiteLoadBalancerConfig.java
@@ -0,0 +1,121 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.agent.api.routing;
+
+// details of site participating in the GLSB service, represents configuration load balancer rule and the zone
+// in which the rule is configured
+public class SiteLoadBalancerConfig {
+
+ // true if the site details are local to the zone receiving 'GlobalLoadBalancerConfigCommand'
+ boolean local;
+
+ // true if the site needs to be removed from GSLB service
+ boolean revoked;
+
+ // service type of the 'site load balanced' service
+ String serviceType;
+
+ // public IP corresponding to the site load balanced service
+ String servicePublicIp;
+
+ // port corresponding to the site load balanced service
+ String servicePort;
+
+ // Private IP corresponding to the GSLB service provider in the site.
+ String gslbProviderPrivateIp;
+
+ // Public IP corresponding to the GSLB service provider in the site.
+ String gslbProviderPublicIp;
+
+ // zone id in which site is located
+ long dataCenterId;
+
+ public SiteLoadBalancerConfig(boolean revoked, String serviceType, String servicePublicIp, String servicePort,
+ long dataCenterId) {
+ this.revoked = revoked;
+ this.serviceType = serviceType;
+ this.servicePublicIp = servicePublicIp;
+ this.servicePort = servicePort;
+ this.dataCenterId = dataCenterId;
+ }
+
+ public SiteLoadBalancerConfig(String gslbProviderPublicIP, String gslbProviderPrivateIp, boolean local,
+ boolean revoked, String serviceType, String servicePublicIp, String port,
+ long dataCenterId) {
+ this(revoked, serviceType, servicePublicIp, port, dataCenterId);
+ this.gslbProviderPrivateIp = gslbProviderPrivateIp;
+ this.gslbProviderPublicIp = gslbProviderPublicIP;
+ this.local = local;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ public void setServiceType(String serviceType) {
+ this.serviceType = serviceType;
+ }
+
+ public String getServicePublicIp() {
+ return servicePublicIp;
+ }
+
+ public void SetServicePublicIp(String servicePublicIp) {
+ this.servicePublicIp = servicePublicIp;
+ }
+
+ public String getServicePort() {
+ return servicePort;
+ }
+
+ public void setServicePort(String port) {
+ this.servicePort = port;
+ }
+
+ public String getGslbProviderPrivateIp() {
+ return gslbProviderPrivateIp;
+ }
+
+ public void setGslbProviderPrivateIp(String privateIp) {
+ this.gslbProviderPrivateIp = privateIp;
+ }
+
+ public String getGslbProviderPublicIp() {
+ return gslbProviderPublicIp;
+ }
+
+ public long getDataCenterId() {
+ return dataCenterId;
+ }
+
+ public void setGslbProviderPublicIp(String publicIp) {
+ this.gslbProviderPublicIp = publicIp;
+ }
+
+ public boolean isLocal() {
+ return local;
+ }
+
+ public void setLocal(boolean local) {
+ this.local = local;
+ }
+
+ public boolean forRevoke() {
+ return revoked;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/com/cloud/async/AsyncJob.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/async/AsyncJob.java b/api/src/com/cloud/async/AsyncJob.java
index 034c853..8e4aec0 100644
--- a/api/src/com/cloud/async/AsyncJob.java
+++ b/api/src/com/cloud/async/AsyncJob.java
@@ -16,11 +16,11 @@
// under the License.
package com.cloud.async;
-import java.util.Date;
-
import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;
+import java.util.Date;
+
public interface AsyncJob extends Identity, InternalIdentity {
public enum Type {
None,
@@ -48,7 +48,8 @@ public interface AsyncJob extends Identity, InternalIdentity {
Condition,
AutoScalePolicy,
AutoScaleVmProfile,
- AutoScaleVmGroup
+ AutoScaleVmGroup,
+ GlobalLoadBalancerRule
}
long getUserId();
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/com/cloud/event/EventTypes.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/event/EventTypes.java b/api/src/com/cloud/event/EventTypes.java
index f38865c..6fdd28c 100755
--- a/api/src/com/cloud/event/EventTypes.java
+++ b/api/src/com/cloud/event/EventTypes.java
@@ -114,6 +114,12 @@ public class EventTypes {
public static final String EVENT_LB_HEALTHCHECKPOLICY_DELETE = "LB.HEALTHCHECKPOLICY.DELETE";
public static final String EVENT_LOAD_BALANCER_UPDATE = "LB.UPDATE";
+ // Global Load Balancer rules
+ public static final String EVENT_ASSIGN_TO_GLOBAL_LOAD_BALANCER_RULE = "GLOBAL.LB.ASSIGN";
+ public static final String EVENT_REMOVE_FROM_GLOBAL_LOAD_BALANCER_RULE = "GLOBAL.LB.REMOVE";
+ public static final String EVENT_GLOBAL_LOAD_BALANCER_CREATE = "GLOBAL.LB.CREATE";
+ public static final String EVENT_GLOBAL_LOAD_BALANCER_DELETE = "GLOBAL.LB.DELETE";
+
// Account events
public static final String EVENT_ACCOUNT_DISABLE = "ACCOUNT.DISABLE";
public static final String EVENT_ACCOUNT_CREATE = "ACCOUNT.CREATE";
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/com/cloud/region/ha/GlobalLoadBalancerRule.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/region/ha/GlobalLoadBalancerRule.java b/api/src/com/cloud/region/ha/GlobalLoadBalancerRule.java
new file mode 100644
index 0000000..597304f
--- /dev/null
+++ b/api/src/com/cloud/region/ha/GlobalLoadBalancerRule.java
@@ -0,0 +1,89 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.region.ha;
+
+import org.apache.cloudstack.acl.ControlledEntity;
+import org.apache.cloudstack.api.Identity;
+import org.apache.cloudstack.api.InternalIdentity;
+
+/**
+ * GlobalLoadBalancerRule defines a global (multi zone) load balancing configuration.
+ */
+public interface GlobalLoadBalancerRule extends Identity, InternalIdentity, ControlledEntity {
+
+ enum Algorithm {
+
+ RoundRobin,
+ LeastConn,
+ Proximity;
+
+ public static boolean isValidAlgorithm(String algorithm) {
+ if (RoundRobin.name().equalsIgnoreCase(algorithm) ||
+ LeastConn.name().equalsIgnoreCase(algorithm) ||
+ Proximity.name().equalsIgnoreCase(algorithm)) {
+ return true;
+ }
+ return false;
+ }
+ }
+ enum Persistence {
+
+ sourceip;
+
+ public static boolean isValidPersistence(String persistence) {
+ if (sourceip.name().equalsIgnoreCase(persistence)) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ enum ServiceType {
+ tcp,
+ udp;
+ public static boolean isValidServiceType(String serviceType) {
+ if (tcp.name().equalsIgnoreCase(serviceType) || udp.name().equalsIgnoreCase(serviceType)) {
+ return true;
+ }
+ return false;
+ }
+ }
+ enum State {
+ Staged,
+ Add,
+ Active,
+ Revoke
+ }
+
+ public String getName();
+
+ public String getDescription();
+
+ public String getGslbDomain();
+
+ public String getAlgorithm();
+
+ public String getPersistence();
+
+ public int getRegion();
+
+ public long getAccountId();
+
+ public State getState();
+
+ public String getServiceType();
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java b/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java
new file mode 100644
index 0000000..e2f097e
--- /dev/null
+++ b/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java
@@ -0,0 +1,47 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package com.cloud.region.ha;
+
+import org.apache.cloudstack.api.command.user.region.ha.gslb.*;
+
+import java.util.List;
+
+public interface GlobalLoadBalancingRulesService {
+
+ /*
+ * methods for managing life cycle of global load balancing rules
+ */
+ GlobalLoadBalancerRule createGlobalLoadBalancerRule(CreateGlobalLoadBalancerRuleCmd createGslbCmd);
+
+ boolean deleteGlobalLoadBalancerRule(DeleteGlobalLoadBalancerRuleCmd deleteGslbCmd);
+
+ GlobalLoadBalancerRule updateGlobalLoadBalancerRule(UpdateGlobalLoadBalancerRuleCmd updateGslbCmd);
+
+ /*
+ * methods for managing sites participating in global load balancing
+ */
+ boolean assignToGlobalLoadBalancerRule(AssignToGlobalLoadBalancerRuleCmd assignToGslbCmd);
+
+ boolean removeFromGlobalLoadBalancerRule(RemoveFromGlobalLoadBalancerRuleCmd removeFromGslbCmd);
+
+
+ GlobalLoadBalancerRule findById(long gslbRuleId);
+
+ List<GlobalLoadBalancerRule> listGlobalLoadBalancerRule(ListGlobalLoadBalancerRuleCmd listGslbCmd);
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/ApiConstants.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ApiConstants.java b/api/src/org/apache/cloudstack/api/ApiConstants.java
index f4c6c52..c518830 100755
--- a/api/src/org/apache/cloudstack/api/ApiConstants.java
+++ b/api/src/org/apache/cloudstack/api/ApiConstants.java
@@ -80,6 +80,10 @@ public class ApiConstants {
public static final String IP6_GATEWAY = "ip6gateway";
public static final String GROUP = "group";
public static final String GROUP_ID = "groupid";
+ public static final String GSLB_LB_METHOD = "gslblbmethod";
+ public static final String GSLB_SERVICE_DOMAIN_NAME = "gslbdomainname";
+ public static final String GSLB_SERVICE_TYPE = "gslbservicetype";
+ public static final String GSLB_STICKY_SESSION_METHOD = "gslbstickysessionmethodname";
public static final String GUEST_CIDR_ADDRESS = "guestcidraddress";
public static final String HA_ENABLE = "haenable";
public static final String HOST_ID = "hostid";
@@ -329,6 +333,7 @@ public class ApiConstants {
public static final String LOAD_BALANCER_DEVICE_STATE = "lbdevicestate";
public static final String LOAD_BALANCER_DEVICE_CAPACITY = "lbdevicecapacity";
public static final String LOAD_BALANCER_DEVICE_DEDICATED = "lbdevicededicated";
+ public static final String LOAD_BALANCER_RULE_LIST = "loadbalancerrulelist";
public static final String FIREWALL_DEVICE_ID = "fwdeviceid";
public static final String FIREWALL_DEVICE_NAME = "fwdevicename";
public static final String FIREWALL_DEVICE_STATE = "fwdevicestate";
@@ -445,6 +450,9 @@ public class ApiConstants {
public static final String AUTOSCALE_USER_ID = "autoscaleuserid";
public static final String BAREMETAL_DISCOVER_NAME = "baremetaldiscovername";
public static final String UCS_DN = "ucsdn";
+ public static final String GSLB_PROVIDER = "gslbprovider";
+ public static final String GSLB_PROVIDER_PUBLIC_IP = "gslbproviderpublicip";
+ public static final String GSLB_PROVIDER_PRIVATE_IP = "gslbproviderprivateip";
public static final String VM_SNAPSHOT_DESCRIPTION = "description";
public static final String VM_SNAPSHOT_DISPLAYNAME = "name";
public static final String VM_SNAPSHOT_ID = "vmsnapshotid";
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java b/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java
index 97edb4c..f3b3170 100644
--- a/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java
+++ b/api/src/org/apache/cloudstack/api/BaseAsyncCmd.java
@@ -31,6 +31,7 @@ public abstract class BaseAsyncCmd extends BaseCmd {
public static final String networkSyncObject = "network";
public static final String vpcSyncObject = "vpc";
public static final String snapshotHostSyncObject = "snapshothost";
+ public static final String gslbSyncObject = "globalserverloadbalacner";
private AsyncJob job;
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/ResponseGenerator.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResponseGenerator.java b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
index 628a185..d1e1302 100644
--- a/api/src/org/apache/cloudstack/api/ResponseGenerator.java
+++ b/api/src/org/apache/cloudstack/api/ResponseGenerator.java
@@ -115,23 +115,9 @@ import com.cloud.domain.Domain;
import com.cloud.event.Event;
import com.cloud.host.Host;
import com.cloud.hypervisor.HypervisorCapabilities;
-import com.cloud.network.IpAddress;
-import com.cloud.network.Network;
+import com.cloud.network.*;
import com.cloud.network.Network.Service;
-import com.cloud.network.PhysicalNetwork;
-import com.cloud.network.PhysicalNetworkServiceProvider;
-import com.cloud.network.PhysicalNetworkTrafficType;
-import com.cloud.network.RemoteAccessVpn;
-import com.cloud.network.Site2SiteCustomerGateway;
-import com.cloud.network.Site2SiteVpnConnection;
-import com.cloud.network.Site2SiteVpnGateway;
-import com.cloud.network.VirtualRouterProvider;
-import com.cloud.network.VpnUser;
-import com.cloud.network.as.AutoScalePolicy;
-import com.cloud.network.as.AutoScaleVmGroup;
-import com.cloud.network.as.AutoScaleVmProfile;
-import com.cloud.network.as.Condition;
-import com.cloud.network.as.Counter;
+import com.cloud.network.as.*;
import com.cloud.network.router.VirtualRouter;
import com.cloud.network.rules.FirewallRule;
import com.cloud.network.rules.HealthCheckPolicy;
@@ -152,13 +138,9 @@ import com.cloud.org.Cluster;
import com.cloud.projects.Project;
import com.cloud.projects.ProjectAccount;
import com.cloud.projects.ProjectInvitation;
+import com.cloud.region.ha.GlobalLoadBalancerRule;
import com.cloud.server.ResourceTag;
-import com.cloud.storage.GuestOS;
-import com.cloud.storage.S3;
-import com.cloud.storage.Snapshot;
-import com.cloud.storage.StoragePool;
-import com.cloud.storage.Swift;
-import com.cloud.storage.Volume;
+import com.cloud.storage.*;
import com.cloud.storage.snapshot.SnapshotPolicy;
import com.cloud.storage.snapshot.SnapshotSchedule;
import com.cloud.template.VirtualMachineTemplate;
@@ -169,8 +151,17 @@ import com.cloud.uservm.UserVm;
import com.cloud.vm.InstanceGroup;
import com.cloud.vm.Nic;
import com.cloud.vm.NicSecondaryIp;
-import com.cloud.vm.VirtualMachine;
import com.cloud.vm.snapshot.VMSnapshot;
+import com.cloud.vm.VirtualMachine;
+import org.apache.cloudstack.api.ApiConstants.HostDetails;
+import org.apache.cloudstack.api.ApiConstants.VMDetails;
+import org.apache.cloudstack.api.command.user.job.QueryAsyncJobResultCmd;
+import org.apache.cloudstack.api.response.*;
+import org.apache.cloudstack.region.Region;
+
+import java.text.DecimalFormat;
+import java.util.EnumSet;
+import java.util.List;
public interface ResponseGenerator {
UserResponse createUserResponse(UserAccount user);
@@ -209,6 +200,8 @@ public interface ResponseGenerator {
IPAddressResponse createIPAddressResponse(IpAddress ipAddress);
+ GlobalLoadBalancerResponse createGlobalLoadBalancerResponse(GlobalLoadBalancerRule globalLoadBalancerRule);
+
LoadBalancerResponse createLoadBalancerResponse(LoadBalancer loadBalancer);
LBStickinessResponse createLBStickinessPolicyResponse(List<? extends StickinessPolicy> stickinessPolicies, LoadBalancer lb);
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java
new file mode 100644
index 0000000..1c07a0a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java
@@ -0,0 +1,128 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.user.region.ha.gslb;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.region.ha.GlobalLoadBalancerRule;
+import com.cloud.region.ha.GlobalLoadBalancingRulesService;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.utils.StringUtils;
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.FirewallRuleResponse;
+import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+import java.util.List;
+
+@APICommand(name = "assignToGlobalLoadBalancerRule", description="Assign load balancer rule or list of load " +
+ "balancer rules to a global load balancer rules.", responseObject=SuccessResponse.class)
+public class AssignToGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
+
+ public static final Logger s_logger = Logger.getLogger(AssignToGlobalLoadBalancerRuleCmd.class.getName());
+
+ private static final String s_name = "assigntogloballoadbalancerruleresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = GlobalLoadBalancerResponse.class,
+ required=true, description="the ID of the global load balancer rule")
+ private Long id;
+
+ @Parameter(name=ApiConstants.LOAD_BALANCER_RULE_LIST, type=CommandType.LIST, collectionType=CommandType.UUID,
+ entityType = FirewallRuleResponse.class, required=true, description="the list load balancer rules that " +
+ "will be assigned to gloabal load balacner rule")
+ private List<Long> loadBalancerRulesIds;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getGlobalLoadBalancerRuleId() {
+ return id;
+ }
+
+ public List<Long> getLoadBalancerRulesIds() {
+ return loadBalancerRulesIds;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Inject
+ public GlobalLoadBalancingRulesService _gslbService;
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ GlobalLoadBalancerRule globalLoadBalancerRule = _entityMgr.findById(GlobalLoadBalancerRule.class,
+ getGlobalLoadBalancerRuleId());
+ if (globalLoadBalancerRule == null) {
+ return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked
+ }
+ return globalLoadBalancerRule.getAccountId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_ASSIGN_TO_GLOBAL_LOAD_BALANCER_RULE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "applying load balancer rules " + StringUtils.join(getLoadBalancerRulesIds(), ",") +
+ " to global load balancer rule " + getGlobalLoadBalancerRuleId();
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("Global Load balancer rule Id: "+ getGlobalLoadBalancerRuleId()+ " VmIds: "
+ + StringUtils.join(getLoadBalancerRulesIds(), ","));
+ boolean result = _gslbService.assignToGlobalLoadBalancerRule(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to assign global load balancer rule");
+ }
+ }
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.gslbSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ GlobalLoadBalancerRule gslb = _gslbService.findById(id);
+ if(gslb == null){
+ throw new InvalidParameterValueException("Unable to find load balancer rule: " + id);
+ }
+ return gslb.getId();
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java
new file mode 100644
index 0000000..cd559d8
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java
@@ -0,0 +1,179 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.user.region.ha.gslb;
+
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.region.ha.GlobalLoadBalancerRule;
+import com.cloud.region.ha.GlobalLoadBalancingRulesService;
+import com.cloud.user.UserContext;
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
+import org.apache.cloudstack.api.response.RegionResponse;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+@APICommand(name = "createGlobalLoadBalancerRule", description="Creates a global load balancer rule",
+ responseObject=GlobalLoadBalancerResponse.class)
+public class CreateGlobalLoadBalancerRuleCmd extends BaseAsyncCreateCmd {
+
+ public static final Logger s_logger = Logger.getLogger(CreateGlobalLoadBalancerRuleCmd.class.getName());
+
+ private static final String s_name = "creategloballoadbalancerruleresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="name of the load balancer rule")
+ private String globalLoadBalancerRuleName;
+
+ @Parameter(name=ApiConstants.DESCRIPTION, type=CommandType.STRING, description="the description of the load balancer rule", length=4096)
+ private String description;
+
+ @Parameter(name=ApiConstants.REGION_ID, type=CommandType.INTEGER, entityType = RegionResponse.class, required=true, description="region where the global load balancer is going to be created.")
+ private Integer regionId;
+
+ @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the global load balancer. Must be used with the domainId parameter.")
+ private String accountName;
+
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class, description="the domain ID associated with the load balancer")
+ private Long domainId;
+
+ @Parameter(name=ApiConstants.GSLB_LB_METHOD, type=CommandType.STRING, required=false, description="load balancer algorithm (roundrobin, leastconn, proximity) " +
+ "that method is used to distribute traffic across the zones participating in global server load balancing, if not specified defaults to 'round robin'")
+ private String algorithm;
+
+ @Parameter(name=ApiConstants.GSLB_STICKY_SESSION_METHOD, type=CommandType.STRING, required=false, description="session sticky method (sourceip) if not specified defaults to sourceip")
+ private String stickyMethod;
+
+ @Parameter(name=ApiConstants.GSLB_SERVICE_DOMAIN_NAME, type = CommandType.STRING, required = true, description = "domain name for the GSLB service.")
+ private String serviceDomainName;
+
+ @Parameter(name=ApiConstants.GSLB_SERVICE_TYPE, type = CommandType.STRING, required = true, description = "GSLB service type (tcp, udp)")
+ private String serviceType;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public String getName() {
+ return globalLoadBalancerRuleName;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ public String getGslbMethod() {
+ return algorithm;
+ }
+
+ public String getStickyMethod() {
+ return stickyMethod;
+ }
+
+ public String getServiceDomainName() {
+ return serviceDomainName;
+ }
+
+ public Integer getRegionId() {
+ return regionId;
+ }
+
+ public String getServiceType() {
+ return serviceType;
+ }
+
+ @Inject
+ private GlobalLoadBalancingRulesService _gslbService;
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() throws ResourceAllocationException, ResourceUnavailableException {
+
+ UserContext callerContext = UserContext.current();
+ GlobalLoadBalancerRule rule = _entityMgr.findById(GlobalLoadBalancerRule.class, getEntityId());
+ GlobalLoadBalancerResponse response = null;
+ if (rule != null) {
+ response = _responseGenerator.createGlobalLoadBalancerResponse(rule);
+ setResponseObject(response);
+ }
+ response.setResponseName(getCommandName());
+ }
+
+ @Override
+ public void create() {
+ try {
+ GlobalLoadBalancerRule gslbRule = _gslbService.createGlobalLoadBalancerRule(this);
+ this.setEntityId(gslbRule.getId());
+ this.setEntityUuid(gslbRule.getUuid());
+ UserContext.current().setEventDetails("Rule Id: " + getEntityId());
+ } catch (Exception ex) {
+ s_logger.warn("Exception: ", ex);
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage());
+ }finally {
+
+ }
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_GLOBAL_LOAD_BALANCER_CREATE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "creating a global load balancer: " + getName() + " for account: " + getAccountName();
+
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.GlobalLoadBalancerRule;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ Long accountId = finalyzeAccountId(accountName, domainId, null, true);
+ if (accountId == null) {
+ return UserContext.current().getCaller().getId();
+ }
+ return accountId;
+ }
+
+ public String getAccountName() {
+ return accountName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java
new file mode 100644
index 0000000..424b107
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java
@@ -0,0 +1,108 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.user.region.ha.gslb;
+
+import com.cloud.async.AsyncJob;
+import com.cloud.event.EventTypes;
+import com.cloud.region.ha.GlobalLoadBalancerRule;
+import com.cloud.region.ha.GlobalLoadBalancingRulesService;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+@APICommand(name = "deleteGlobalLoadBalancerRule", description="Deletes a global load balancer rule.", responseObject=SuccessResponse.class)
+public class DeleteGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
+
+ public static final Logger s_logger = Logger.getLogger(DeleteGlobalLoadBalancerRuleCmd.class.getName());
+
+ private static final String s_name = "deletegloballoadbalancerruleresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = GlobalLoadBalancerResponse.class, required=true, description="the ID of the global load balancer rule")
+ private Long id;
+
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getGlobalLoadBalancerId() {
+ return id;
+ }
+
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Inject
+ public GlobalLoadBalancingRulesService _gslbService;
+
+ @Override
+ public long getEntityOwnerId() {
+ GlobalLoadBalancerRule lb = _entityMgr.findById(GlobalLoadBalancerRule.class, getGlobalLoadBalancerId());
+ if (lb != null) {
+ return lb.getAccountId();
+ }
+
+ return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_LOAD_BALANCER_DELETE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "deleting global load balancer: " + getGlobalLoadBalancerId();
+ }
+
+ @Override
+ public void execute(){
+ _gslbService.deleteGlobalLoadBalancerRule(this);
+ UserContext.current().setEventDetails("Deleting global Load balancer Id: " + getGlobalLoadBalancerId());
+ }
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.networkSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ return null;
+ }
+
+ @Override
+ public AsyncJob.Type getInstanceType() {
+ return AsyncJob.Type.GlobalLoadBalancerRule;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java
new file mode 100644
index 0000000..dae861a
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java
@@ -0,0 +1,92 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.user.region.ha.gslb;
+
+import com.cloud.region.ha.GlobalLoadBalancerRule;
+import com.cloud.region.ha.GlobalLoadBalancingRulesService;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
+import org.apache.cloudstack.api.response.ListResponse;
+import org.apache.cloudstack.api.response.RegionResponse;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+
+@APICommand(name = "listGlobalLoadBalancerRules", description = "Lists load balancer rules.", responseObject = GlobalLoadBalancerResponse.class)
+public class ListGlobalLoadBalancerRuleCmd extends BaseListTaggedResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(ListGlobalLoadBalancerRuleCmd.class.getName());
+
+ private static final String s_name = "listgloballoadbalancerrulesresponse";
+
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = GlobalLoadBalancerResponse.class, description = "the ID of the global load balancer rule")
+ private Long id;
+
+ @Parameter(name = ApiConstants.REGION_ID, type = CommandType.UUID, entityType = RegionResponse.class, description = "region ID")
+ private Integer regionId;
+
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ public Integer getRegionId() {
+ return regionId;
+ }
+
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
+
+ @Inject
+ public GlobalLoadBalancingRulesService _gslbService;
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() {
+ List<GlobalLoadBalancerRule> globalLoadBalancers = _gslbService.listGlobalLoadBalancerRule(this);
+ ListResponse<GlobalLoadBalancerResponse> gslbRuleResponse = new ListResponse<GlobalLoadBalancerResponse>();
+ List<GlobalLoadBalancerResponse> gslbResponses = new ArrayList<GlobalLoadBalancerResponse>();
+ if (globalLoadBalancers != null) {
+ for (GlobalLoadBalancerRule gslbRule: globalLoadBalancers) {
+ GlobalLoadBalancerResponse gslbResponse = _responseGenerator.createGlobalLoadBalancerResponse(gslbRule);
+ gslbResponse.setObjectName("globalloadbalancerrule");
+ gslbResponses.add(gslbResponse);
+ }
+ }
+ gslbRuleResponse.setResponses(gslbResponses);
+ gslbRuleResponse.setResponseName(getCommandName());
+ this.setResponseObject(gslbRuleResponse);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java
new file mode 100644
index 0000000..fa051af
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java
@@ -0,0 +1,125 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.user.region.ha.gslb;
+
+import com.cloud.event.EventTypes;
+import com.cloud.exception.InvalidParameterValueException;
+import com.cloud.region.ha.GlobalLoadBalancerRule;
+import com.cloud.region.ha.GlobalLoadBalancingRulesService;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+import com.cloud.utils.StringUtils;
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.FirewallRuleResponse;
+import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
+import org.apache.cloudstack.api.response.SuccessResponse;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+import java.util.List;
+
+@APICommand(name = "removeFromGlobalLoadBalancerRule", description="Removes a load balancer rule association with" +
+ " global load balancer rule", responseObject=SuccessResponse.class)
+public class RemoveFromGlobalLoadBalancerRuleCmd extends BaseAsyncCmd {
+ public static final Logger s_logger = Logger.getLogger(RemoveFromGlobalLoadBalancerRuleCmd.class.getName());
+
+ private static final String s_name = "removefromloadbalancerruleresponse";
+
+ /////////////////////////////////////////////////////
+ //////////////// API parameters /////////////////////
+ /////////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = GlobalLoadBalancerResponse.class,
+ required=true, description="The ID of the load balancer rule")
+ private Long id;
+
+ @Parameter(name=ApiConstants.LOAD_BALANCER_RULE_LIST, type=CommandType.LIST, collectionType=CommandType.UUID,
+ entityType = FirewallRuleResponse.class, required=true, description="the list load balancer rules that "
+ + "will be assigned to gloabal load balacner rule")
+ private List<Long> loadBalancerRulesIds;
+
+ /////////////////////////////////////////////////////
+ /////////////////// Accessors ///////////////////////
+ /////////////////////////////////////////////////////
+
+ public Long getGlobalLoadBalancerRuleId() {
+ return id;
+ }
+
+ public List<Long> getLoadBalancerRulesIds() {
+ return loadBalancerRulesIds;
+ }
+ /////////////////////////////////////////////////////
+ /////////////// API Implementation///////////////////
+ /////////////////////////////////////////////////////
+
+ @Inject
+ public GlobalLoadBalancingRulesService _gslbService;
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public long getEntityOwnerId() {
+ GlobalLoadBalancerRule globalLoadBalancerRule = _entityMgr.findById(GlobalLoadBalancerRule.class, getGlobalLoadBalancerRuleId());
+ if (globalLoadBalancerRule == null) {
+ return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked
+ }
+ return globalLoadBalancerRule.getAccountId();
+ }
+
+ @Override
+ public String getEventType() {
+ return EventTypes.EVENT_REMOVE_FROM_GLOBAL_LOAD_BALANCER_RULE;
+ }
+
+ @Override
+ public String getEventDescription() {
+ return "removing load balancer rules:" + StringUtils.join(getLoadBalancerRulesIds(), ",") +
+ " from global load balancer: " + getGlobalLoadBalancerRuleId();
+ }
+
+ @Override
+ public void execute(){
+ UserContext.current().setEventDetails("Global Load balancer rule Id: "+ getGlobalLoadBalancerRuleId()+ " VmIds: "
+ + StringUtils.join(getLoadBalancerRulesIds(), ","));
+ boolean result = _gslbService.removeFromGlobalLoadBalancerRule(this);
+ if (result) {
+ SuccessResponse response = new SuccessResponse(getCommandName());
+ this.setResponseObject(response);
+ } else {
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to remove load balancer rule from global load balancer rule");
+ }
+ }
+
+ @Override
+ public String getSyncObjType() {
+ return BaseAsyncCmd.gslbSyncObject;
+ }
+
+ @Override
+ public Long getSyncObjId() {
+ GlobalLoadBalancerRule gslb = _gslbService.findById(id);
+ if(gslb == null){
+ throw new InvalidParameterValueException("Unable to find load balancer rule: " + id);
+ }
+ return gslb.getId();
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java
new file mode 100644
index 0000000..10694e1
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java
@@ -0,0 +1,96 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package org.apache.cloudstack.api.command.user.region.ha.gslb;
+
+import com.cloud.region.ha.GlobalLoadBalancingRulesService;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseListTaggedResourcesCmd;
+import org.apache.cloudstack.api.Parameter;
+import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse;
+import org.apache.cloudstack.api.response.LoadBalancerResponse;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
+
+@APICommand(name = "updateGlobalLoadBalancerRule", description = "update global load balancer rules.", responseObject = LoadBalancerResponse.class)
+public class UpdateGlobalLoadBalancerRuleCmd extends BaseListTaggedResourcesCmd {
+ public static final Logger s_logger = Logger.getLogger(GlobalLoadBalancerResponse.class.getName());
+
+ private static final String s_name = "updategloballoadbalancerruleresponse";
+
+ // ///////////////////////////////////////////////////
+ // ////////////// API parameters /////////////////////
+ // ///////////////////////////////////////////////////
+
+ @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = GlobalLoadBalancerResponse.class,
+ required=true, description="the ID of the global load balancer rule")
+ private Long id;
+
+ @Parameter(name=ApiConstants.DESCRIPTION, type=CommandType.STRING, description="the description of the load balancer rule", length=4096)
+ private String description;
+
+ @Parameter(name=ApiConstants.GSLB_LB_METHOD, type=CommandType.STRING, required=false, description="load balancer algorithm (roundrobin, leastconn, proximity) " +
+ "that is used to distributed traffic across the zones participating in global server load balancing, if not specified defaults to 'round robin'")
+ private String algorithm;
+
+ @Parameter(name=ApiConstants.GSLB_STICKY_SESSION_METHOD, type=CommandType.STRING, required=false, description="session sticky method (sourceip) if not specified defaults to sourceip")
+ private String stickyMethod;
+
+ // ///////////////////////////////////////////////////
+ // ///////////////// Accessors ///////////////////////
+ // ///////////////////////////////////////////////////
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public String getAlgorithm() {
+ return algorithm;
+ }
+
+ public String getGslbMethod() {
+ return algorithm;
+ }
+
+ public String getStickyMethod() {
+ return stickyMethod;
+ }
+
+ // ///////////////////////////////////////////////////
+ // ///////////// API Implementation///////////////////
+ // ///////////////////////////////////////////////////
+
+ @Inject
+ public GlobalLoadBalancingRulesService _gslbService;
+
+ @Override
+ public String getCommandName() {
+ return s_name;
+ }
+
+ @Override
+ public void execute() {
+ _gslbService.updateGlobalLoadBalancerRule(this);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/api/response/GlobalLoadBalancerResponse.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/response/GlobalLoadBalancerResponse.java b/api/src/org/apache/cloudstack/api/response/GlobalLoadBalancerResponse.java
new file mode 100644
index 0000000..0fd064f
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/response/GlobalLoadBalancerResponse.java
@@ -0,0 +1,125 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package org.apache.cloudstack.api.response;
+
+import com.cloud.region.ha.GlobalLoadBalancerRule;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.BaseResponse;
+import org.apache.cloudstack.api.EntityReference;
+
+@EntityReference(value= GlobalLoadBalancerRule.class)
+public class GlobalLoadBalancerResponse extends BaseResponse implements ControlledEntityResponse {
+
+ @SerializedName(ApiConstants.ID)
+ @Param(description = "global load balancer rule ID")
+ private String id;
+
+ @SerializedName(ApiConstants.NAME)
+ @Param(description = "name of the global load balancer rule")
+ private String name;
+
+ @SerializedName(ApiConstants.DESCRIPTION)
+ @Param(description = "the description of the global load balancer rule")
+ private String description;
+
+ @SerializedName(ApiConstants.GSLB_SERVICE_DOMAIN_NAME)
+ @Param(description = "DNS domain name given for the global load balancer")
+ private String gslbDomainName;
+
+ @SerializedName(ApiConstants.GSLB_LB_METHOD)
+ @Param(description = "Load balancing method used for the global load balancer")
+ private String algorithm;
+
+ @SerializedName(ApiConstants.GSLB_STICKY_SESSION_METHOD)
+ @Param(description = "session persistence method used for the global load balancer")
+ private String stickyMethod;
+
+ @SerializedName(ApiConstants.REGION_ID)
+ @Param(description = "Region Id in which global load balancer is created")
+ private Integer regionId;
+
+ @SerializedName(ApiConstants.ACCOUNT)
+ @Param(description = "the account of the load balancer rule")
+ private String accountName;
+
+ @SerializedName(ApiConstants.PROJECT_ID) @Param(description="the project id of the load balancer")
+ private String projectId;
+
+ @SerializedName(ApiConstants.PROJECT) @Param(description="the project name of the load balancer")
+ private String projectName;
+
+ @SerializedName(ApiConstants.DOMAIN_ID)
+ @Param(description = "the domain ID of the load balancer rule")
+ private String domainId;
+
+ @SerializedName(ApiConstants.DOMAIN)
+ @Param(description = "the domain of the load balancer rule")
+ private String domainName;
+
+ public void setRegionIdId(Integer regionId) {
+ this.regionId = regionId;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public void setAlgorithm(String algorithm) {
+ this.algorithm = algorithm;
+ }
+
+ public void setStickyMethod(String stickyMethod) {
+ this.stickyMethod = stickyMethod;
+ }
+
+ public void setServiceDomainName(String domainName) {
+ this.gslbDomainName = domainName;
+ }
+
+ public void setAccountName(String accountName) {
+ this.accountName = accountName;
+ }
+
+ @Override
+ public void setProjectId(String projectId) {
+ this.projectId = projectId;
+ }
+
+ @Override
+ public void setProjectName(String projectName) {
+ this.projectName = projectName;
+ }
+
+ @Override
+ public void setDomainId(String domainId) {
+ this.domainId = domainId;
+ }
+
+ public void setDomainName(String domainName) {
+ this.domainName = domainName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/api/src/org/apache/cloudstack/region/Region.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/region/Region.java b/api/src/org/apache/cloudstack/region/Region.java
index f8926ee..7119f1b 100644
--- a/api/src/org/apache/cloudstack/region/Region.java
+++ b/api/src/org/apache/cloudstack/region/Region.java
@@ -16,6 +16,9 @@
// under the License.
package org.apache.cloudstack.region;
+import java.util.ArrayList;
+import java.util.List;
+
/**
*
*/
@@ -29,4 +32,50 @@ public interface Region {
public String getEndPoint();
+
+ public boolean checkIfServiceEnabled(Service service);
+
+ /**
+ * A region level service, is a service that constitute services across one or more zones in the region or a service
+ * made available to all the zones in the region.
+ */
+ public static class Service {
+
+ private String name;
+ private static List<Service> regionServices = new ArrayList<Service>();
+
+ public static final Service Gslb = new Service("Gslb");
+
+ public Service(String name ) {
+ this.name = name;
+ regionServices.add(this);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ }
+
+ /**
+ * A provider provides the region level service in a zone.
+ */
+ public static class Provider {
+
+ private static List<Provider> supportedProviders = new ArrayList<Provider>();
+ private String name;
+ private Service service;
+
+ public static final Provider Netscaler = new Provider("Netscaler", Service.Gslb);
+
+ public Provider(String name, Service service) {
+ this.name = name;
+ this.service = service;
+ supportedProviders.add(this);
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/client/tomcatconf/commands.properties.in
----------------------------------------------------------------------
diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in
index 492f7f9..3b3ffdf 100644
--- a/client/tomcatconf/commands.properties.in
+++ b/client/tomcatconf/commands.properties.in
@@ -551,6 +551,14 @@ updateRegion=1
removeRegion=1
listRegions=15
+#### GSLB (Global Server Load Balancing) commands
+createGlobalLoadBalancerRule=15
+deleteGlobalLoadBalancerRule=15
+updateGlobalLoadBalancerRule=15
+listGlobalLoadBalancerRules=15
+assignToGlobalLoadBalancerRule=15
+removeFromGlobalLoadBalancerRule=15
+
### VM Snapshot commands
listVMSnapshot=15
createVMSnapshot=15
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java b/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java
index 3e75c3f..77f6b60 100644
--- a/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java
+++ b/plugins/network-elements/f5/src/com/cloud/network/element/F5ExternalLoadBalancerElement.java
@@ -31,14 +31,7 @@ import org.apache.log4j.Logger;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.api.ApiDBUtils;
-import com.cloud.api.commands.AddExternalLoadBalancerCmd;
-import com.cloud.api.commands.AddF5LoadBalancerCmd;
-import com.cloud.api.commands.ConfigureF5LoadBalancerCmd;
-import com.cloud.api.commands.DeleteExternalLoadBalancerCmd;
-import com.cloud.api.commands.DeleteF5LoadBalancerCmd;
-import com.cloud.api.commands.ListExternalLoadBalancersCmd;
-import com.cloud.api.commands.ListF5LoadBalancerNetworksCmd;
-import com.cloud.api.commands.ListF5LoadBalancersCmd;
+import com.cloud.api.commands.*;
import com.cloud.api.response.F5LoadBalancerResponse;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
@@ -47,35 +40,17 @@ import com.cloud.dc.DataCenter;
import com.cloud.dc.DataCenterVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.deploy.DeployDestination;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InsufficientNetworkCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.*;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
-import com.cloud.network.ExternalLoadBalancerDeviceManager;
-import com.cloud.network.ExternalLoadBalancerDeviceManagerImpl;
-import com.cloud.network.Network;
+import com.cloud.network.*;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
-import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.TrafficType;
-import com.cloud.network.PhysicalNetwork;
-import com.cloud.network.PhysicalNetworkServiceProvider;
-import com.cloud.network.PublicIpAddress;
-import com.cloud.network.dao.ExternalLoadBalancerDeviceDao;
-import com.cloud.network.dao.ExternalLoadBalancerDeviceVO;
-import com.cloud.network.dao.NetworkDao;
-import com.cloud.network.dao.NetworkExternalLoadBalancerDao;
-import com.cloud.network.dao.NetworkExternalLoadBalancerVO;
-import com.cloud.network.dao.NetworkServiceMapDao;
-import com.cloud.network.dao.NetworkVO;
-import com.cloud.network.dao.PhysicalNetworkDao;
-import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.network.dao.*;
import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceState;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.resource.F5BigIpResource;
@@ -89,6 +64,13 @@ import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.google.gson.Gson;
+import org.apache.cloudstack.api.response.ExternalLoadBalancerResponse;
+import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
+import org.apache.log4j.Logger;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import java.util.*;
@Local(value = {NetworkElement.class, LoadBalancingServiceProvider.class, IpDeployer.class})
public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, IpDeployer, F5ExternalLoadBalancerElementService, ExternalLoadBalancerDeviceManager {
@@ -295,7 +277,8 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
pNetwork = physicalNetworks.get(0);
String deviceType = NetworkDevice.F5BigIpLoadBalancer.getName();
- lbDeviceVO = addExternalLoadBalancer(pNetwork.getId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceType, new F5BigIpResource());
+ lbDeviceVO = addExternalLoadBalancer(pNetwork.getId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(),
+ deviceType, new F5BigIpResource(), false, null, null);
if (lbDeviceVO != null) {
lbHost = _hostDao.findById(lbDeviceVO.getHostId());
@@ -348,7 +331,8 @@ public class F5ExternalLoadBalancerElement extends ExternalLoadBalancerDeviceMan
throw new InvalidParameterValueException("Invalid F5 load balancer device type");
}
- return addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, new F5BigIpResource());
+ return addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(),
+ deviceName, new F5BigIpResource(), false, null, null);
}
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java
index 80c8cb9..e4327b4 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java
@@ -15,23 +15,18 @@
package com.cloud.api.commands;
-import javax.inject.Inject;
-
-import org.apache.cloudstack.api.*;
-import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
-import org.apache.log4j.Logger;
-import org.apache.cloudstack.api.APICommand;
import com.cloud.api.response.NetscalerLoadBalancerResponse;
import com.cloud.event.EventTypes;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.*;
import com.cloud.network.dao.ExternalLoadBalancerDeviceVO;
import com.cloud.network.element.NetscalerLoadBalancerElementService;
import com.cloud.user.UserContext;
import com.cloud.utils.exception.CloudRuntimeException;
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
+import org.apache.log4j.Logger;
+
+import javax.inject.Inject;
@APICommand(name = "addNetscalerLoadBalancer", responseObject=NetscalerLoadBalancerResponse.class, description="Adds a netscaler load balancer device")
public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd {
@@ -60,6 +55,18 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd {
@Parameter(name = ApiConstants.NETWORK_DEVICE_TYPE, type = CommandType.STRING, required = true, description = "Netscaler device type supports NetscalerMPXLoadBalancer, NetscalerVPXLoadBalancer, NetscalerSDXLoadBalancer")
private String deviceType;
+ @Parameter(name = ApiConstants.GSLB_PROVIDER, type = CommandType.BOOLEAN, required = false,
+ description = "true if NetScaler device being added is for providing GSLB service")
+ private boolean isGslbProvider;
+
+ @Parameter(name = ApiConstants.GSLB_PROVIDER_PUBLIC_IP, type = CommandType.STRING, required = false,
+ description = "public IP of the site")
+ private String gslbSitePublicIp;
+
+ @Parameter(name = ApiConstants.GSLB_PROVIDER_PRIVATE_IP, type = CommandType.STRING, required = false,
+ description = "public IP of the site")
+ private String gslbSitePrivateIp;
+
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@@ -84,6 +91,18 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd {
return deviceType;
}
+ public boolean isGslbProvider() {
+ return isGslbProvider;
+ }
+
+ public String getSitePublicIp() {
+ return gslbSitePublicIp;
+ }
+
+ public String getSitePrivateIp() {
+ return gslbSitePrivateIp;
+ }
+
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c5fb8349/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
index a90440c..17bb7cc 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/network/element/NetscalerElement.java
@@ -16,35 +16,16 @@
// under the License.
package com.cloud.network.element;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.ejb.Local;
-import javax.inject.Inject;
-
-import org.apache.cloudstack.api.ApiConstants;
-import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
-import org.apache.log4j.Logger;
-import org.springframework.stereotype.Component;
-
import com.cloud.agent.AgentManager;
import com.cloud.agent.api.Answer;
+import com.cloud.agent.api.routing.GlobalLoadBalancerConfigCommand;
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
import com.cloud.agent.api.routing.SetStaticNatRulesAnswer;
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
import com.cloud.agent.api.to.LoadBalancerTO;
import com.cloud.agent.api.to.StaticNatRuleTO;
import com.cloud.api.ApiDBUtils;
-import com.cloud.api.commands.AddNetscalerLoadBalancerCmd;
-import com.cloud.api.commands.ConfigureNetscalerLoadBalancerCmd;
-import com.cloud.api.commands.DeleteNetscalerLoadBalancerCmd;
-import com.cloud.api.commands.ListNetscalerLoadBalancerNetworksCmd;
-import com.cloud.api.commands.ListNetscalerLoadBalancersCmd;
+import com.cloud.api.commands.*;
import com.cloud.api.response.NetscalerLoadBalancerResponse;
import com.cloud.configuration.Config;
import com.cloud.configuration.ConfigurationManager;
@@ -56,40 +37,19 @@ import com.cloud.dc.HostPodVO;
import com.cloud.dc.dao.DataCenterDao;
import com.cloud.dc.dao.DataCenterIpAddressDao;
import com.cloud.deploy.DeployDestination;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InsufficientNetworkCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceUnavailableException;
+import com.cloud.exception.*;
import com.cloud.host.Host;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.host.dao.HostDetailsDao;
-import com.cloud.network.ExternalLoadBalancerDeviceManager;
-import com.cloud.network.ExternalLoadBalancerDeviceManagerImpl;
-import com.cloud.network.IpAddress;
-import com.cloud.network.NetScalerPodVO;
-import com.cloud.network.Network;
+import com.cloud.network.*;
import com.cloud.network.Network.Capability;
import com.cloud.network.Network.Provider;
import com.cloud.network.Network.Service;
-import com.cloud.network.NetworkModel;
import com.cloud.network.Networks.TrafficType;
-import com.cloud.network.PhysicalNetwork;
-import com.cloud.network.PhysicalNetworkServiceProvider;
-import com.cloud.network.PublicIpAddress;
import com.cloud.network.as.AutoScaleCounter;
import com.cloud.network.as.AutoScaleCounter.AutoScaleCounterType;
-import com.cloud.network.dao.ExternalLoadBalancerDeviceDao;
-import com.cloud.network.dao.ExternalLoadBalancerDeviceVO;
-import com.cloud.network.dao.NetScalerPodDao;
-import com.cloud.network.dao.NetworkDao;
-import com.cloud.network.dao.NetworkExternalLoadBalancerDao;
-import com.cloud.network.dao.NetworkExternalLoadBalancerVO;
-import com.cloud.network.dao.NetworkServiceMapDao;
-import com.cloud.network.dao.NetworkVO;
-import com.cloud.network.dao.PhysicalNetworkDao;
-import com.cloud.network.dao.PhysicalNetworkVO;
+import com.cloud.network.dao.*;
import com.cloud.network.dao.ExternalLoadBalancerDeviceVO.LBDeviceState;
import com.cloud.network.lb.LoadBalancingRule;
import com.cloud.network.lb.LoadBalancingRule.LbDestination;
@@ -110,10 +70,20 @@ import com.cloud.vm.ReservationContext;
import com.cloud.vm.VirtualMachine;
import com.cloud.vm.VirtualMachineProfile;
import com.google.gson.Gson;
+import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.network.ExternalNetworkDeviceManager.NetworkDevice;
+import org.apache.cloudstack.region.gslb.GslbServiceProvider;
+import org.apache.log4j.Logger;
+
+import javax.ejb.Local;
+import javax.inject.Inject;
+import java.net.URI;
+import java.util.*;
-@Local(value = {NetworkElement.class, StaticNatServiceProvider.class, LoadBalancingServiceProvider.class})
-public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider, NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager, IpDeployer,
-StaticNatServiceProvider {
+@Local(value = {NetworkElement.class, StaticNatServiceProvider.class, LoadBalancingServiceProvider.class, GslbServiceProvider.class})
+public class NetscalerElement extends ExternalLoadBalancerDeviceManagerImpl implements LoadBalancingServiceProvider,
+ NetscalerLoadBalancerElementService, ExternalLoadBalancerDeviceManager, IpDeployer, StaticNatServiceProvider,
+ GslbServiceProvider {
private static final Logger s_logger = Logger.getLogger(NetscalerElement.class);
public static final AutoScaleCounterType AutoScaleCounterSnmp = new AutoScaleCounterType("snmp");
@@ -149,6 +119,8 @@ StaticNatServiceProvider {
NetScalerPodDao _netscalerPodDao;
@Inject
DataCenterIpAddressDao _privateIpAddressDao;
+ @Inject
+ ExternalLoadBalancerDeviceDao _externalLoadBalancerDeviceDao;
private boolean canHandle(Network config, Service service) {
DataCenter zone = _dcDao.findById(config.getDataCenterId());
@@ -336,7 +308,26 @@ StaticNatServiceProvider {
throw new InvalidParameterValueException(msg);
}
- ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(), cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource());
+ if (cmd.isGslbProvider()) {
+
+ if (!deviceName.equals(NetworkDevice.NetscalerVPXLoadBalancer.getName()) &&
+ !deviceName.equals(NetworkDevice.NetscalerMPXLoadBalancer.getName())) {
+ String msg = "Only Netscaler VPX or MPX load balancers can be specified as GSLB service provider";
+ s_logger.debug(msg);
+ throw new InvalidParameterValueException(msg);
+ }
+
+ if (cmd.getSitePublicIp() == null || cmd.getSitePrivateIp() == null) {
+ String msg = "Public and Privae IP needs to provided for NetScaler that will be GSLB provider";
+ s_logger.debug(msg);
+ throw new InvalidParameterValueException(msg);
+ }
+ }
+
+ ExternalLoadBalancerDeviceVO lbDeviceVO = addExternalLoadBalancer(cmd.getPhysicalNetworkId(), cmd.getUrl(),
+ cmd.getUsername(), cmd.getPassword(), deviceName, new NetscalerResource(), cmd.isGslbProvider(),
+ cmd.getSitePublicIp(), cmd.getSitePrivateIp());
+
return lbDeviceVO;
}
@@ -816,7 +807,6 @@ StaticNatServiceProvider {
return null;
}
- @Override
public List<LoadBalancerTO> updateHealthChecks(Network network, List<LoadBalancingRule> lbrules) {
if (canHandle(network, Service.Lb)) {
@@ -831,10 +821,73 @@ StaticNatServiceProvider {
return null;
}
- @Override
public List<LoadBalancerTO> getLBHealthChecks(Network network, List<? extends FirewallRule> rules)
throws ResourceUnavailableException {
return super.getLBHealthChecks(network, rules);
+ }
+
+ @Override
+ public boolean applyGlobalLoadBalancerRule(long zoneId, GlobalLoadBalancerConfigCommand gslbConfigCmd)
+ throws ResourceUnavailableException {
+
+ long zoneGslbProviderHosId = 0;
+
+ // find the NetScaler device configured as gslb service provider in the zone
+ ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId);
+ if (nsGslbProvider == null) {
+ String msg = "Unable to find a NetScaler configured as gslb service provider in zone " + zoneId;
+ s_logger.debug(msg);
+ throw new ResourceUnavailableException(msg, DataCenter.class, zoneId);
+ }
+
+ // get the host Id corresponding to NetScaler acting as GSLB service provider in the zone
+ zoneGslbProviderHosId = nsGslbProvider.getHostId();
+
+ // send gslb configuration to NetScaler device
+ Answer answer = _agentMgr.easySend(zoneGslbProviderHosId, gslbConfigCmd);
+ if (answer == null || !answer.getResult()) {
+ String msg = "Unable to apply global load balancer rule to the gslb service provider in zone " + zoneId;
+ s_logger.debug(msg);
+ throw new ResourceUnavailableException(msg, DataCenter.class, zoneId);
+ }
+
+ return true;
+ }
+
+ private ExternalLoadBalancerDeviceVO findGslbProvider(long zoneId) {
+ List<PhysicalNetworkVO> pNtwks = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, TrafficType.Guest);
+ if (pNtwks.isEmpty() || pNtwks.size() > 1) {
+ throw new InvalidParameterValueException("Unable to get physical network in zone id = " + zoneId);
+ }
+ PhysicalNetworkVO physNetwork = pNtwks.get(0);
+ ExternalLoadBalancerDeviceVO nsGslbProvider = _externalLoadBalancerDeviceDao.findGslbServiceProvider(
+ physNetwork.getId(), Provider.Netscaler.getName());
+ return nsGslbProvider;
+ }
+
+ @Override
+ public boolean isServiceEnabledInZone(long zoneId) {
+
+ ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId);
+ //return true if a NetScaler device is configured in the zone
+ return (nsGslbProvider != null);
+ }
+
+ @Override
+ public String getZoneGslbProviderPublicIp(long zoneId) {
+ ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId);
+ if (nsGslbProvider != null) {
+ return nsGslbProvider.getGslbSitePublicIP();
+ }
+ return null;
+ }
+ @Override
+ public String getZoneGslbProviderPrivateIp(long zoneId) {
+ ExternalLoadBalancerDeviceVO nsGslbProvider = findGslbProvider(zoneId);
+ if (nsGslbProvider != null) {
+ return nsGslbProvider.getGslbSitePrivateIP();
+ }
+ return null;
}
}