add API and service layer skeletons
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/02b16535 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/02b16535 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/02b16535 Branch: refs/heads/gslb Commit: 02b165358ce43c95ee87aa6b65ee6cb3a30b630f Parents: 8f70ee0 Author: Murali Reddy <[email protected]> Authored: Thu Feb 7 18:34:34 2013 +0530 Committer: Murali Reddy <[email protected]> Committed: Thu Feb 7 18:34:34 2013 +0530 ---------------------------------------------------------------------- api/src/com/cloud/async/AsyncJob.java | 4 +- api/src/com/cloud/event/EventTypes.java | 6 + .../com/cloud/region/ha/GlobalLoadBalancer.java | 28 +++ .../region/ha/GlobalLoadBalancingRulesService.java | 22 ++ .../org/apache/cloudstack/api/ApiConstants.java | 1 + .../ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java | 123 ++++++++++++ .../ha/gslb/CreateGlobalLoadBalancerRuleCmd.java | 153 +++++++++++++++ .../ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java | 101 ++++++++++ .../ha/gslb/ListGlobalLoadBalancerRuleCmd.java | 77 ++++++++ .../gslb/RemoveFromGlobalLoadBalancerRuleCmd.java | 107 ++++++++++ .../ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java | 66 ++++++ .../api/response/GlobalLoadBalancerResponse.java | 47 +++++ 12 files changed, 734 insertions(+), 1 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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..5c4db79 100644 --- a/api/src/com/cloud/async/AsyncJob.java +++ b/api/src/com/cloud/async/AsyncJob.java @@ -18,6 +18,7 @@ package com.cloud.async; import java.util.Date; +import com.cloud.region.ha.GlobalLoadBalancer; import org.apache.cloudstack.api.Identity; import org.apache.cloudstack.api.InternalIdentity; @@ -48,7 +49,8 @@ public interface AsyncJob extends Identity, InternalIdentity { Condition, AutoScalePolicy, AutoScaleVmProfile, - AutoScaleVmGroup + AutoScaleVmGroup, + GlobalLoadBalancerRule } long getUserId(); http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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 0dd97cb..8620e2d 100755 --- a/api/src/com/cloud/event/EventTypes.java +++ b/api/src/com/cloud/event/EventTypes.java @@ -112,6 +112,12 @@ public class EventTypes { public static final String EVENT_LB_STICKINESSPOLICY_DELETE = "LB.STICKINESSPOLICY.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/incubator-cloudstack/blob/02b16535/api/src/com/cloud/region/ha/GlobalLoadBalancer.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/region/ha/GlobalLoadBalancer.java b/api/src/com/cloud/region/ha/GlobalLoadBalancer.java new file mode 100644 index 0000000..dcbd749 --- /dev/null +++ b/api/src/com/cloud/region/ha/GlobalLoadBalancer.java @@ -0,0 +1,28 @@ +// 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; + +/** + * Definition for a GlobalLoadBalancer + */ +public interface GlobalLoadBalancer extends ControlledEntity, Identity, InternalIdentity { + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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..6984561 --- /dev/null +++ b/api/src/com/cloud/region/ha/GlobalLoadBalancingRulesService.java @@ -0,0 +1,22 @@ +// 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; + +public interface GlobalLoadBalancingRulesService { + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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 d29408e..2df1472 100755 --- a/api/src/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/org/apache/cloudstack/api/ApiConstants.java @@ -324,6 +324,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"; http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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..7e2cc5b --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/AssignToGlobalLoadBalancerRuleCmd.java @@ -0,0 +1,123 @@ +// 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.network.rules.LoadBalancer; +import com.cloud.region.ha.GlobalLoadBalancer; +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.GlobalLoadBalancerResponse; +import org.apache.cloudstack.api.response.LoadBalancerResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.log4j.Logger; + +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 load balancer rule") + private Long id; + + @Parameter(name=ApiConstants.LOAD_BALANCER_RULE_LIST, type=CommandType.LIST, collectionType=CommandType.UUID, + entityType = LoadBalancerResponse.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 getGlobalLoadBalancerId() { + return id; + } + + public List<Long> getLoadBalancerRulesId() { + return loadBalancerRulesIds; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + GlobalLoadBalancer globalLoadBalancer = _entityMgr.findById(GlobalLoadBalancer.class, getGlobalLoadBalancerId()); + if (globalLoadBalancer == null) { + return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked + } + return globalLoadBalancer.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(getLoadBalancerRulesId(), ",") + + " to global load balancer rule " + getGlobalLoadBalancerId(); + } + + @Override + public void execute(){ + UserContext.current().setEventDetails("Global Load balancer rule Id: "+ getGlobalLoadBalancerId()+ " VmIds: " + + StringUtils.join(getLoadBalancerRulesId(), ",")); + boolean result = _lbService.assignToLoadBalancer(getGlobalLoadBalancerId(), loadBalancerRulesIds); + 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.networkSyncObject; + } + + @Override + public Long getSyncObjId() { + LoadBalancer lb = _lbService.findById(id); + if(lb == null){ + throw new InvalidParameterValueException("Unable to find load balancer rule: " + id); + } + return lb.getNetworkId(); + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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..f010f81 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/CreateGlobalLoadBalancerRuleCmd.java @@ -0,0 +1,153 @@ +// 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.InvalidParameterValueException; +import com.cloud.exception.ResourceAllocationException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.user.Account; +import com.cloud.user.UserContext; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCreateCmd; +import org.apache.cloudstack.api.Parameter; +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; + +@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.ALGORITHM, type=CommandType.STRING, required=true, description="load balancer algorithm (source, roundrobin, leastconn)") + private String algorithm; + + @Parameter(name=ApiConstants.DESCRIPTION, type=CommandType.STRING, description="the description of the load balancer rule", length=4096) + private String description; + + @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="name of the load balancer rule") + private String globalLoadBalancerRuleName; + + @Parameter(name=ApiConstants.REGION_ID, type= CommandType.UUID, entityType = RegionResponse.class, required=true, description="region where the global load balancer is going to be created.") + private Long 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; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public String getAlgorithm() { + return algorithm; + } + + public String getDescription() { + return description; + } + + public String getGlobalLoadBalancerRuleName() { + return globalLoadBalancerRuleName; + } + + + public String getName() { + return globalLoadBalancerRuleName; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public void execute() throws ResourceAllocationException, ResourceUnavailableException { + + UserContext callerContext = UserContext.current(); + + try { + UserContext.current().setEventDetails("Rule Id: " + getEntityId()); + } catch (Exception ex) { + + }finally { + + } + } + + @Override + public void create() { + + } + + @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.FirewallRule; + } + + @Override + public long getEntityOwnerId() { + return getAccountId(); + } + + public String getAccountName() { + return accountName; + } + + public long getAccountId() { + Account account = null; + if ((domainId != null) && (accountName != null)) { + account = _responseGenerator.findAccountByNameDomain(accountName, domainId); + if (account != null) { + return account.getId(); + } else { + throw new InvalidParameterValueException("Unable to find account " + account + " in domain id=" + domainId); + } + } else { + throw new InvalidParameterValueException("Can't define IP owner. Either specify account/domainId or publicIpId"); + } + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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..690e5d0 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/DeleteGlobalLoadBalancerRuleCmd.java @@ -0,0 +1,101 @@ +// 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.GlobalLoadBalancer; +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; + +@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; + } + + @Override + public long getEntityOwnerId() { + GlobalLoadBalancer lb = _entityMgr.findById(GlobalLoadBalancer.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(){ + 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/incubator-cloudstack/blob/02b16535/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..e759a82 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/ListGlobalLoadBalancerRuleCmd.java @@ -0,0 +1,77 @@ +// 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 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.RegionResponse; +import org.apache.log4j.Logger; + +@APICommand(name = "listLoadBalancerRules", 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.NAME, type = CommandType.STRING, description = "the name of the global load balancer rule") + private String loadBalancerRuleName; + + @Parameter(name = ApiConstants.REGION_ID, type = CommandType.UUID, entityType = RegionResponse.class, description = "region ID") + private Long regionId; + + // /////////////////////////////////////////////////// + // ///////////////// Accessors /////////////////////// + // /////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + public String getLoadBalancerRuleName() { + return loadBalancerRuleName; + } + + public Long getRegionId() { + return regionId; + } + + // /////////////////////////////////////////////////// + // ///////////// API Implementation/////////////////// + // /////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public void execute() { + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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..9f114dc --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/RemoveFromGlobalLoadBalancerRuleCmd.java @@ -0,0 +1,107 @@ +// 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.region.ha.GlobalLoadBalancer; +import com.cloud.user.Account; +import com.cloud.utils.StringUtils; +import org.apache.cloudstack.api.APICommand; +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse; +import org.apache.cloudstack.api.response.LoadBalancerResponse; +import org.apache.cloudstack.api.response.SuccessResponse; +import org.apache.log4j.Logger; + +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 = LoadBalancerResponse.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 getGlobalLoadBalancerId() { + return id; + } + + public List<Long> getLoadBalancerRulesId() { + return loadBalancerRulesIds; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public long getEntityOwnerId() { + GlobalLoadBalancer globalLoadBalancer = _entityMgr.findById(GlobalLoadBalancer.class, getGlobalLoadBalancerId()); + if (globalLoadBalancer == null) { + return Account.ACCOUNT_ID_SYSTEM; // bad id given, parent this command to SYSTEM so ERROR events are tracked + } + return globalLoadBalancer.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(getLoadBalancerRulesId(), ",") + " from global load balancer: " + getGlobalLoadBalancerId(); + } + + @Override + public void execute(){ + + } + + @Override + public String getSyncObjType() { + return null; + } + + @Override + public Long getSyncObjId() { + return null; + } +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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..85ced6d --- /dev/null +++ b/api/src/org/apache/cloudstack/api/command/user/region/ha/gslb/UpdateGlobalLoadBalancerRuleCmd.java @@ -0,0 +1,66 @@ +// 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 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.FirewallRuleResponse; +import org.apache.cloudstack.api.response.GlobalLoadBalancerResponse; +import org.apache.cloudstack.api.response.LoadBalancerResponse; +import org.apache.log4j.Logger; + +@APICommand(name = "updateGlobalLoadBalancerRules", 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 = "updategloballoadbalancerrulesresponse"; + + // /////////////////////////////////////////////////// + // ////////////// API parameters ///////////////////// + // /////////////////////////////////////////////////// + + @Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = FirewallRuleResponse.class, + description = "the ID of the load balancer rule") + private Long id; + + + // /////////////////////////////////////////////////// + // ///////////////// Accessors /////////////////////// + // /////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + // /////////////////////////////////////////////////// + // ///////////// API Implementation/////////////////// + // /////////////////////////////////////////////////// + + @Override + public String getCommandName() { + return s_name; + } + + @Override + public void execute() { + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/02b16535/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..cb16391 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/response/GlobalLoadBalancerResponse.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 org.apache.cloudstack.api.response; + +import org.apache.cloudstack.api.BaseResponse; + +public class GlobalLoadBalancerResponse extends BaseResponse implements ControlledEntityResponse { + + @Override + public void setAccountName(String accountName) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void setProjectId(String projectId) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void setProjectName(String projectName) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void setDomainId(String domainId) { + //To change body of implemented methods use File | Settings | File Templates. + } + + @Override + public void setDomainName(String domainName) { + //To change body of implemented methods use File | Settings | File Templates. + } +}
