You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ml...@apache.org on 2013/01/10 01:48:36 UTC
[44/52] [partial] Summary: Fixes for api_refactoring
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateAutoScaleVmProfileCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateAutoScaleVmProfileCmd.java b/api/src/com/cloud/api/commands/CreateAutoScaleVmProfileCmd.java
deleted file mode 100644
index 68c85d0..0000000
--- a/api/src/com/cloud/api/commands/CreateAutoScaleVmProfileCmd.java
+++ /dev/null
@@ -1,236 +0,0 @@
-// 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.api.commands;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCreateCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.AutoScaleVmProfileResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.network.as.AutoScaleVmProfile;
-import com.cloud.user.Account;
-import com.cloud.user.User;
-import com.cloud.user.UserContext;
-
-@Implementation(description = "Creates a profile that contains information about the virtual machine which will be provisioned automatically by autoscale feature.", responseObject = AutoScaleVmProfileResponse.class)
-@SuppressWarnings("rawtypes")
-public class CreateAutoScaleVmProfileCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(CreateAutoScaleVmProfileCmd.class.getName());
-
- private static final String s_name = "autoscalevmprofileresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName = "data_center")
- @Parameter(name = ApiConstants.ZONE_ID, type = CommandType.LONG, required = true, description = "availability zone for the auto deployed virtual machine")
- private Long zoneId;
-
- @IdentityMapper(entityTableName = "disk_offering")
- @Parameter(name = ApiConstants.SERVICE_OFFERING_ID, type = CommandType.LONG, required = true, description = "the service offering of the auto deployed virtual machine")
- private Long serviceOfferingId;
-
- @IdentityMapper(entityTableName = "vm_template")
- @Parameter(name = ApiConstants.TEMPLATE_ID, type = CommandType.LONG, required = true, description = "the template of the auto deployed virtual machine")
- private Long templateId;
-
- @Parameter(name = ApiConstants.OTHER_DEPLOY_PARAMS, type = CommandType.STRING, description = "parameters other than zoneId/serviceOfferringId/templateId of the auto deployed virtual machine")
- private String otherDeployParams;
-
- @Parameter(name = ApiConstants.AUTOSCALE_VM_DESTROY_TIME, type = CommandType.INTEGER, description = "the time allowed for existing connections to get closed before a vm is destroyed")
- private Integer destroyVmGraceperiod;
-
- @Parameter(name = ApiConstants.COUNTERPARAM_LIST, type = CommandType.MAP, description = "counterparam list. Example: counterparam[0].name=snmpcommunity&counterparam[0].value=public&counterparam[1].name=snmpport&counterparam[1].value=161")
- private Map counterParamList;
-
- @IdentityMapper(entityTableName = "user")
- @Parameter(name = ApiConstants.AUTOSCALE_USER_ID, type = CommandType.LONG, description = "the ID of the user used to launch and destroy the VMs")
- private Long autoscaleUserId;
-
- private Map<String, String> otherDeployParamMap;
-
- // ///////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- private Long domainId;
- private Long accountId;
-
- @Override
- public String getEntityTable() {
- return "autoscale_vmprofiles";
- }
-
- public Long getDomainId() {
- if (domainId == null) {
- getAccountId();
- }
- return domainId;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public Long getServiceOfferingId() {
- return serviceOfferingId;
- }
-
- public Long getTemplateId() {
- return templateId;
- }
-
- public Map getCounterParamList() {
- return counterParamList;
- }
-
- public String getOtherDeployParams() {
- return otherDeployParams;
- }
-
- public Long getAutoscaleUserId() {
- if (autoscaleUserId != null) {
- return autoscaleUserId;
- } else {
- return UserContext.current().getCaller().getId();
- }
- }
-
- public Integer getDestroyVmGraceperiod() {
- return destroyVmGraceperiod;
- }
-
- public long getAccountId() {
- if (accountId != null) {
- return accountId;
- }
- Account account = null;
- if (autoscaleUserId != null) {
- User user = _entityMgr.findById(User.class, autoscaleUserId);
- account = _entityMgr.findById(Account.class, user.getAccountId());
- } else {
- account = UserContext.current().getCaller();
- }
- accountId = account.getAccountId();
- domainId = account.getDomainId();
- return accountId;
- }
-
- private void createOtherDeployParamMap()
- {
- if (otherDeployParamMap == null) {
- otherDeployParamMap = new HashMap<String, String>();
- }
- if (otherDeployParams == null)
- return;
- String[] keyValues = otherDeployParams.split("&"); // hostid=123, hypervisor=xenserver
- for (String keyValue : keyValues) { // keyValue == "hostid=123"
- String[] keyAndValue = keyValue.split("="); // keyValue = hostid, 123
- if (keyAndValue.length != 2) {
- throw new InvalidParameterValueException("Invalid parameter in otherDeployParam : " + keyValue);
- }
- String paramName = keyAndValue[0]; // hostid
- String paramValue = keyAndValue[1]; // 123
- otherDeployParamMap.put(paramName, paramValue);
- }
- }
-
- public HashMap<String, String> getDeployParamMap()
- {
- createOtherDeployParamMap();
- HashMap<String, String> deployParams = new HashMap<String, String>(otherDeployParamMap);
- deployParams.put("command", "deployVirtualMachine");
- deployParams.put("zoneId", zoneId.toString());
- deployParams.put("serviceOfferingId", serviceOfferingId.toString());
- deployParams.put("templateId", templateId.toString());
- return deployParams;
- }
-
- public String getOtherDeployParam(String param)
- {
- if (param == null) {
- return null;
- }
- createOtherDeployParamMap();
- return otherDeployParamMap.get(param);
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public static String getResultObjectName() {
- return "autoscalevmprofile";
- }
-
- @Override
- public long getEntityOwnerId() {
- return getAccountId();
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_AUTOSCALEVMPROFILE_CREATE;
- }
-
- @Override
- public String getEventDescription() {
- return "creating AutoScale Vm Profile";
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.AutoScaleVmProfile;
- }
-
- @Override
- public void execute() {
- AutoScaleVmProfile result = _entityMgr.findById(AutoScaleVmProfile.class, getEntityId());
- AutoScaleVmProfileResponse response = _responseGenerator.createAutoScaleVmProfileResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-
- @Override
- public void create() throws ResourceAllocationException {
-
- AutoScaleVmProfile result = _autoScaleService.createAutoScaleVmProfile(this);
- if (result != null) {
- this.setEntityId(result.getId());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Autoscale Vm Profile");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateConditionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateConditionCmd.java b/api/src/com/cloud/api/commands/CreateConditionCmd.java
deleted file mode 100644
index eafd8a0..0000000
--- a/api/src/com/cloud/api/commands/CreateConditionCmd.java
+++ /dev/null
@@ -1,152 +0,0 @@
-// 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.api.commands;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCreateCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.ConditionResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.network.as.Condition;
-import com.cloud.user.UserContext;
-
-@Implementation(description = "Creates a condition", responseObject = ConditionResponse.class)
-public class CreateConditionCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(CreateConditionCmd.class.getName());
- private static final String s_name = "conditionresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName = "counter")
- @Parameter(name = ApiConstants.COUNTER_ID, type = CommandType.LONG, required = true, description = "ID of the Counter.")
- private long counterId;
-
- @Parameter(name = ApiConstants.RELATIONAL_OPERATOR, type = CommandType.STRING, required = true, description = "Relational Operator to be used with threshold.")
- private String relationalOperator;
-
- @Parameter(name = ApiConstants.THRESHOLD, type = CommandType.LONG, required = true, description = "Threshold value.")
- private Long threshold;
-
- @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "the account of the condition. " +
- "Must be used with the domainId parameter.")
- private String accountName;
-
- @IdentityMapper(entityTableName = "domain")
- @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "the domain ID of the account.")
- private Long domainId;
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public void create() throws ResourceAllocationException {
- Condition condition = null;
- condition = _autoScaleService.createCondition(this);
-
- if (condition != null) {
- this.setEntityId(condition.getId());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create condition.");
- }
- }
-
- @Override
- public void execute() {
- Condition condition = _entityMgr.findById(Condition.class, getEntityId());
- ConditionResponse response = _responseGenerator.createConditionResponse(condition);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }
-
- // /////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public Long getCounterId() {
- return counterId;
- }
-
- public String getRelationalOperator() {
- return relationalOperator;
- }
-
- public String getAccountName() {
- if (accountName == null) {
- return UserContext.current().getCaller().getAccountName();
- }
-
- return accountName;
- }
-
- public Long getDomainId() {
- if (domainId == null) {
- return UserContext.current().getCaller().getDomainId();
- }
- return domainId;
- }
-
- public Long getThreshold() {
- return threshold;
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.Condition;
- }
-
- @Override
- public String getEventDescription() {
- return "creating a condition";
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_CONDITION_CREATE;
- }
-
- @Override
- public long getEntityOwnerId() {
- Long accountId = finalyzeAccountId(accountName, domainId, null, true);
- if (accountId == null) {
- return UserContext.current().getCaller().getId();
- }
-
- return accountId;
- }
-
- @Override
- public String getEntityTable() {
- return "conditions";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateCounterCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateCounterCmd.java b/api/src/com/cloud/api/commands/CreateCounterCmd.java
deleted file mode 100644
index cc7d78c..0000000
--- a/api/src/com/cloud/api/commands/CreateCounterCmd.java
+++ /dev/null
@@ -1,120 +0,0 @@
-// 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.api.commands;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCreateCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.CounterResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.network.as.Counter;
-import com.cloud.user.Account;
-
-@Implementation(description = "Adds metric counter", responseObject = CounterResponse.class)
-public class CreateCounterCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(CreateCounterCmd.class.getName());
- private static final String s_name = "counterresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "Name of the counter.")
- private String name;
-
- @Parameter(name = ApiConstants.SOURCE, type = CommandType.STRING, required = true, description = "Source of the counter.")
- private String source;
-
- @Parameter(name = ApiConstants.VALUE, type = CommandType.STRING, required = true, description = "Value of the counter e.g. oid in case of snmp.")
- private String value;
-
- // /////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- public String getName() {
- return name;
- }
-
- public String getSource() {
- return source;
- }
-
- public String getValue() {
- return value;
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void create() {
- Counter ctr = null;
- ctr = _autoScaleService.createCounter(this);
-
- if (ctr != null) {
- this.setEntityId(ctr.getId());
- CounterResponse response = _responseGenerator.createCounterResponse(ctr);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create Counter with name " + getName());
- }
- }
-
- @Override
- public void execute() {
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.Counter;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_COUNTER_CREATE;
- }
-
- @Override
- public String getEventDescription() {
- return "creating a new Counter";
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public String getEntityTable() {
- return "counter";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateDiskOfferingCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateDiskOfferingCmd.java b/api/src/com/cloud/api/commands/CreateDiskOfferingCmd.java
deleted file mode 100755
index 779221e..0000000
--- a/api/src/com/cloud/api/commands/CreateDiskOfferingCmd.java
+++ /dev/null
@@ -1,121 +0,0 @@
-// 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.api.commands;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.DiskOfferingResponse;
-import com.cloud.offering.DiskOffering;
-import com.cloud.offering.ServiceOffering;
-import com.cloud.user.Account;
-
-@Implementation(description="Creates a disk offering.", responseObject=DiskOfferingResponse.class)
-public class CreateDiskOfferingCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreateDiskOfferingCmd.class.getName());
-
- private static final String s_name = "creatediskofferingresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.DISK_SIZE, type=CommandType.LONG, required=false, description="size of the disk offering in GB")
- private Long diskSize;
-
- @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="alternate display text of the disk offering", length=4096)
- private String displayText;
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="name of the disk offering")
- private String offeringName;
-
- @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="tags for the disk offering", length=4096)
- private String tags;
-
- @Parameter(name=ApiConstants.CUSTOMIZED, type=CommandType.BOOLEAN, description="whether disk offering is custom or not")
- private Boolean customized;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the ID of the containing domain, null for public offerings")
- private Long domainId;
-
- @Parameter(name=ApiConstants.STORAGE_TYPE, type=CommandType.STRING, description="the storage type of the disk offering. Values are local and shared.")
- private String storageType = ServiceOffering.StorageType.shared.toString();
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public Long getDiskSize() {
- return diskSize;
- }
-
- public String getDisplayText() {
- return displayText;
- }
-
- public String getOfferingName() {
- return offeringName;
- }
-
- public String getTags() {
- return tags;
- }
-
- public Boolean isCustomized(){
- return customized;
- }
-
- public Long getDomainId(){
- return domainId;
- }
-
- public String getStorageType() {
- return storageType;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public void execute(){
- DiskOffering offering = _configService.createDiskOffering(this);
- if (offering != null) {
- DiskOfferingResponse response = _responseGenerator.createDiskOfferingResponse(offering);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create disk offering");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateDomainCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateDomainCmd.java b/api/src/com/cloud/api/commands/CreateDomainCmd.java
deleted file mode 100644
index 92ee7ec..0000000
--- a/api/src/com/cloud/api/commands/CreateDomainCmd.java
+++ /dev/null
@@ -1,94 +0,0 @@
-// 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.api.commands;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.DomainResponse;
-import com.cloud.domain.Domain;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Creates a domain", responseObject=DomainResponse.class)
-public class CreateDomainCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreateDomainCmd.class.getName());
-
- private static final String s_name = "createdomainresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="creates domain with this name")
- private String domainName;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.PARENT_DOMAIN_ID, type=CommandType.LONG, description="assigns new domain a parent domain by domain ID of the parent. If no parent domain is specied, the ROOT domain is assumed.")
- private Long parentDomainId;
-
- @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="Network domain for networks in the domain")
- private String networkDomain;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getDomainName() {
- return domainName;
- }
-
- public Long getParentDomainId() {
- return parentDomainId;
- }
-
- public String getNetworkDomain() {
- return networkDomain;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("Domain Name: "+getDomainName()+((getParentDomainId()!=null)?", Parent DomainId :"+getParentDomainId():""));
- Domain domain = _domainService.createDomain(getDomainName(), getParentDomainId(), getNetworkDomain());
- if (domain != null) {
- DomainResponse response = _responseGenerator.createDomainResponse(domain);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create domain");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateFirewallRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateFirewallRuleCmd.java b/api/src/com/cloud/api/commands/CreateFirewallRuleCmd.java
deleted file mode 100644
index 937e9aa..0000000
--- a/api/src/com/cloud/api/commands/CreateFirewallRuleCmd.java
+++ /dev/null
@@ -1,325 +0,0 @@
-// 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.api.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCmd;
-import com.cloud.api.BaseAsyncCreateCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.FirewallResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.IpAddress;
-import com.cloud.network.rules.FirewallRule;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-import com.cloud.utils.net.NetUtils;
-
-@Implementation(description = "Creates a firewall rule for a given ip address", responseObject = FirewallResponse.class)
-public class CreateFirewallRuleCmd extends BaseAsyncCreateCmd implements FirewallRule {
- public static final Logger s_logger = Logger.getLogger(CreateFirewallRuleCmd.class.getName());
-
- private static final String s_name = "createfirewallruleresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="user_ip_address")
- @Parameter(name = ApiConstants.IP_ADDRESS_ID, type = CommandType.LONG, required=true, description = "the IP address id of the port forwarding rule")
- private Long ipAddressId;
-
- @Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, description = "the protocol for the firewall rule. Valid values are TCP/UDP/ICMP.")
- private String protocol;
-
- @Parameter(name = ApiConstants.START_PORT, type = CommandType.INTEGER, description = "the starting port of firewall rule")
- private Integer publicStartPort;
-
- @Parameter(name = ApiConstants.END_PORT, type = CommandType.INTEGER, description = "the ending port of firewall rule")
- private Integer publicEndPort;
-
- @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
- private List<String> cidrlist;
-
- @Parameter(name = ApiConstants.ICMP_TYPE, type = CommandType.INTEGER, description = "type of the icmp message being sent")
- private Integer icmpType;
-
- @Parameter(name = ApiConstants.ICMP_CODE, type = CommandType.INTEGER, description = "error code for this icmp message")
- private Integer icmpCode;
-
- @Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "type of firewallrule: system/user")
- private String type;
-
- // ///////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- public String getEntityTable() {
- return "firewall_rules";
- }
-
- public Long getIpAddressId() {
- return ipAddressId;
- }
-
- @Override
- public String getProtocol() {
- return protocol.trim();
- }
-
- public List<String> getSourceCidrList() {
- if (cidrlist != null) {
- return cidrlist;
- } else {
- List<String> oneCidrList = new ArrayList<String>();
- oneCidrList.add(NetUtils.ALL_CIDRS);
- return oneCidrList;
- }
-
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public void setSourceCidrList(List<String> cidrs){
- cidrlist = cidrs;
- }
-
- @Override
- public void execute() throws ResourceUnavailableException {
- UserContext callerContext = UserContext.current();
- boolean success = false;
- FirewallRule rule = _entityMgr.findById(FirewallRule.class, getEntityId());
- try {
- UserContext.current().setEventDetails("Rule Id: " + getEntityId());
- success = _firewallService.applyFirewallRules(rule.getSourceIpAddressId(), callerContext.getCaller());
-
- // State is different after the rule is applied, so get new object here
- rule = _entityMgr.findById(FirewallRule.class, getEntityId());
- FirewallResponse fwResponse = new FirewallResponse();
- if (rule != null) {
- fwResponse = _responseGenerator.createFirewallResponse(rule);
- setResponseObject(fwResponse);
- }
- fwResponse.setResponseName(getCommandName());
- } finally {
- if (!success || rule == null) {
- _firewallService.revokeFirewallRule(getEntityId(), true);
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create firewall rule");
- }
- }
- }
-
- @Override
- public long getId() {
- throw new UnsupportedOperationException("database id can only provided by VO objects");
- }
-
- @Override
- public String getXid() {
- // FIXME: We should allow for end user to specify Xid.
- return null;
- }
-
- @Override
- public Long getSourceIpAddressId() {
- return ipAddressId;
- }
-
- @Override
- public Integer getSourcePortStart() {
- if (publicStartPort != null) {
- return publicStartPort.intValue();
- }
- return null;
- }
-
- @Override
- public Integer getSourcePortEnd() {
- if (publicEndPort == null) {
- if (publicStartPort != null) {
- return publicStartPort.intValue();
- }
- } else {
- return publicEndPort.intValue();
- }
-
- return null;
- }
-
- @Override
- public Purpose getPurpose() {
- return Purpose.Firewall;
- }
-
- @Override
- public State getState() {
- throw new UnsupportedOperationException("Should never call me to find the state");
- }
-
- @Override
- public long getNetworkId() {
- IpAddress ip = _entityMgr.findById(IpAddress.class, getIpAddressId());
- Long ntwkId = null;
-
- if (ip.getAssociatedWithNetworkId() != null) {
- ntwkId = ip.getAssociatedWithNetworkId();
- }
-
- if (ntwkId == null) {
- throw new InvalidParameterValueException("Unable to create firewall rule for the ipAddress id=" + ipAddressId +
- " as ip is not associated with any network and no networkId is passed in");
- }
- return ntwkId;
- }
-
- @Override
- public long getEntityOwnerId() {
- Account account = UserContext.current().getCaller();
-
- if (account != null) {
- return account.getId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
- @Override
- public long getDomainId() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- return ip.getDomainId();
- }
-
- @Override
- public void create() {
- if (getSourceCidrList() != null) {
- for (String cidr: getSourceCidrList()){
- if (!NetUtils.isValidCIDR(cidr)){
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Source cidrs formatting error " + cidr);
- }
- }
- }
-
- try {
- FirewallRule result = _firewallService.createFirewallRule(this);
- setEntityId(result.getId());
- } catch (NetworkRuleConflictException ex) {
- s_logger.info("Network rule conflict: " + ex.getMessage());
- s_logger.trace("Network Rule Conflict: ", ex);
- throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
- }
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_FIREWALL_OPEN;
- }
-
- @Override
- public String getEventDescription() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- return ("Createing firewall rule for Ip: " + ip.getAddress() + " for protocol:" + this.getProtocol());
- }
-
- @Override
- public long getAccountId() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- return ip.getAccountId();
- }
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return getIp().getAssociatedWithNetworkId();
- }
-
- private IpAddress getIp() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- if (ip == null) {
- throw new InvalidParameterValueException("Unable to find ip address by id " + ipAddressId);
- }
- return ip;
- }
-
- @Override
- public Integer getIcmpCode() {
- if (icmpCode != null) {
- return icmpCode;
- } else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
- return -1;
- }
- return null;
- }
-
- @Override
- public Integer getIcmpType() {
- if (icmpType != null) {
- return icmpType;
- } else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
- return -1;
-
- }
- return null;
- }
-
- @Override
- public Long getRelated() {
- return null;
- }
-
- @Override
- public FirewallRuleType getType() {
- if (type != null && type.equalsIgnoreCase("system")) {
- return FirewallRuleType.System;
- } else {
- return FirewallRuleType.User;
- }
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.FirewallRule;
- }
-
- @Override
- public TrafficType getTrafficType() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java b/api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java
deleted file mode 100644
index a688d13..0000000
--- a/api/src/com/cloud/api/commands/CreateIpForwardingRuleCmd.java
+++ /dev/null
@@ -1,311 +0,0 @@
-// 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.api.commands;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCmd;
-import com.cloud.api.BaseAsyncCreateCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.FirewallRuleResponse;
-import com.cloud.api.response.IpForwardingRuleResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.IpAddress;
-import com.cloud.network.rules.FirewallRule;
-import com.cloud.network.rules.StaticNatRule;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Creates an ip forwarding rule", responseObject=FirewallRuleResponse.class)
-public class CreateIpForwardingRuleCmd extends BaseAsyncCreateCmd implements StaticNatRule {
- public static final Logger s_logger = Logger.getLogger(CreateIpForwardingRuleCmd.class.getName());
-
- private static final String s_name = "createipforwardingruleresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="user_ip_address")
- @Parameter(name=ApiConstants.IP_ADDRESS_ID, type=CommandType.LONG, required=true, description="the public IP address id of the forwarding rule, already associated via associateIp")
- private Long ipAddressId;
-
- @Parameter(name=ApiConstants.START_PORT, type=CommandType.INTEGER, required=true, description="the start port for the rule")
- private Integer startPort;
-
- @Parameter(name=ApiConstants.END_PORT, type=CommandType.INTEGER, description="the end port for the rule")
- private Integer endPort;
-
- @Parameter(name=ApiConstants.PROTOCOL, type=CommandType.STRING, required=true, description="the protocol for the rule. Valid values are TCP or UDP.")
- private String protocol;
-
- @Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, description = "if true, firewall rule for source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. Has value true by default")
- private Boolean openFirewall;
-
- @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
- private List<String> cidrlist;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getEntityTable() {
- return "firewall_rules";
- }
-
- public Long getIpAddressId() {
- return ipAddressId;
- }
-
- public int getStartPort() {
- return startPort;
- }
-
- public int getEndPort() {
- return endPort;
- }
-
- public Boolean getOpenFirewall() {
- if (openFirewall != null) {
- return openFirewall;
- } else {
- return true;
- }
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void execute() throws ResourceUnavailableException{
-
- boolean result = true;
- FirewallRule rule = null;
- try {
- UserContext.current().setEventDetails("Rule Id: "+ getEntityId());
-
- if (getOpenFirewall()) {
- result = result && _firewallService.applyFirewallRules(ipAddressId, UserContext.current().getCaller());
- }
-
- result = result && _rulesService.applyStaticNatRules(ipAddressId, UserContext.current().getCaller());
- rule = _entityMgr.findById(FirewallRule.class, getEntityId());
- StaticNatRule staticNatRule = _rulesService.buildStaticNatRule(rule, false);
- IpForwardingRuleResponse fwResponse = _responseGenerator.createIpForwardingRuleResponse(staticNatRule);
- fwResponse.setResponseName(getCommandName());
- this.setResponseObject(fwResponse);
- } finally {
- if (!result || rule == null) {
-
- if (getOpenFirewall()) {
- _firewallService.revokeRelatedFirewallRule(getEntityId(), true);
- }
-
- _rulesService.revokeStaticNatRule(getEntityId(), true);
-
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Error in creating ip forwarding rule on the domr");
- }
- }
- }
-
- @Override
- public void create() {
-
- //cidr list parameter is deprecated
- if (cidrlist != null) {
- throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
- }
-
- try {
- StaticNatRule rule = _rulesService.createStaticNatRule(this, getOpenFirewall());
- this.setEntityId(rule.getId());
- } catch (NetworkRuleConflictException e) {
- s_logger.info("Unable to create Static Nat Rule due to ", e);
- throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
- }
- }
-
- @Override
- public long getEntityOwnerId() {
- Account account = UserContext.current().getCaller();
-
- if (account != null) {
- return account.getId();
- }
-
- 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_NET_RULE_ADD;
- }
-
- @Override
- public String getEventDescription() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- return ("Applying an ipforwarding 1:1 NAT rule for Ip: "+ip.getAddress()+" with virtual machine:"+ this.getVirtualMachineId());
- }
-
- private long getVirtualMachineId() {
- Long vmId = _networkService.getIp(ipAddressId).getAssociatedWithVmId();
-
- if (vmId == null) {
- throw new InvalidParameterValueException("Ip address is not associated with any network, unable to create static nat rule");
- }
- return vmId;
- }
-
- @Override
- public String getDestIpAddress(){
- return null;
- }
-
- @Override
- public long getId() {
- throw new UnsupportedOperationException("Don't call me");
- }
-
- @Override
- public Long getSourceIpAddressId() {
- return ipAddressId;
- }
-
- @Override
- public Integer getSourcePortStart() {
- return startPort;
- }
-
- @Override
- public Integer getSourcePortEnd() {
- if (endPort == null) {
- return startPort;
- } else {
- return endPort;
- }
- }
-
- @Override
- public String getProtocol() {
- return protocol;
- }
-
- @Override
- public FirewallRule.Purpose getPurpose() {
- return FirewallRule.Purpose.StaticNat;
- }
-
- @Override
- public FirewallRule.State getState() {
- throw new UnsupportedOperationException("Don't call me");
- }
-
- @Override
- public long getNetworkId() {
- return -1;
- }
-
- @Override
- public long getDomainId() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- return ip.getDomainId();
- }
-
- @Override
- public long getAccountId() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- return ip.getAccountId();
- }
-
- @Override
- public String getXid() {
- // FIXME: We should allow for end user to specify Xid.
- return null;
- }
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return getIp().getAssociatedWithNetworkId();
- }
-
- private IpAddress getIp() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- if (ip == null) {
- throw new InvalidParameterValueException("Unable to find ip address by id " + ipAddressId);
- }
- return ip;
- }
-
- @Override
- public Integer getIcmpCode() {
- return null;
- }
-
- @Override
- public Integer getIcmpType() {
- return null;
- }
-
- @Override
- public List<String> getSourceCidrList() {
- return null;
- }
-
- @Override
- public Long getRelated() {
- return null;
- }
-
- @Override
- public FirewallRuleType getType() {
- return FirewallRuleType.User;
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.FirewallRule;
- }
-
- @Override
- public TrafficType getTrafficType() {
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateLBStickinessPolicyCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateLBStickinessPolicyCmd.java b/api/src/com/cloud/api/commands/CreateLBStickinessPolicyCmd.java
deleted file mode 100644
index c2410c8..0000000
--- a/api/src/com/cloud/api/commands/CreateLBStickinessPolicyCmd.java
+++ /dev/null
@@ -1,161 +0,0 @@
-// 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.api.commands;
-
-
-import java.util.Map;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCreateCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.rules.StickinessPolicy;
-import com.cloud.api.response.LBStickinessResponse;
-import com.cloud.network.rules.LoadBalancer;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-
-@Implementation(description = "Creates a Load Balancer stickiness policy ", responseObject = LBStickinessResponse.class, since="3.0.0")
-@SuppressWarnings("rawtypes")
-public class CreateLBStickinessPolicyCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger
- .getLogger(CreateLBStickinessPolicyCmd.class.getName());
-
- private static final String s_name = "createLBStickinessPolicy";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="firewall_rules")
- @Parameter(name = ApiConstants.LBID, type = CommandType.LONG, required = true, description = "the ID of the load balancer rule")
- private Long lbRuleId;
-
- @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "the description of the LB Stickiness policy")
- private String description;
-
- @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the LB Stickiness policy")
- private String lbStickinessPolicyName;
-
- @Parameter(name = ApiConstants.METHOD_NAME, type = CommandType.STRING, required = true, description = "name of the LB Stickiness policy method, possible values can be obtained from ListNetworks API ")
- private String stickinessMethodName;
-
- @Parameter(name = ApiConstants.PARAM_LIST, type = CommandType.MAP, description = "param list. Example: param[0].name=cookiename¶m[0].value=LBCookie ")
- private Map paramList;
-
- // ///////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- public Long getLbRuleId() {
- return lbRuleId;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getLBStickinessPolicyName() {
- return lbStickinessPolicyName;
- }
-
- public String getStickinessMethodName() {
- return stickinessMethodName;
- }
-
- public Map getparamList() {
- return paramList;
- }
-
- public String getEntityTable() {
- return "firewall_rules";
- }
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- Account account = UserContext.current().getCaller();
- if (account != null) {
- return account.getId();
- }
-
- return Account.ACCOUNT_ID_SYSTEM; // no account info given, parent this command to SYSTEM so ERROR events are tracked
- }
-
- @Override
- public void execute() throws ResourceAllocationException, ResourceUnavailableException {
- StickinessPolicy policy = null;
- boolean success = false;
-
- try {
- UserContext.current().setEventDetails("Rule Id: " + getEntityId());
- success = _lbService.applyLBStickinessPolicy(this);
- if (success) {
- // State might be different after the rule is applied, so get new object here
- policy = _entityMgr.findById(StickinessPolicy.class, getEntityId());
- LoadBalancer lb = _lbService.findById(policy.getLoadBalancerId());
- LBStickinessResponse spResponse = _responseGenerator.createLBStickinessPolicyResponse(policy, lb);
- setResponseObject(spResponse);
- spResponse.setResponseName(getCommandName());
- }
- } finally {
- if (!success || (policy == null)) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create stickiness policy ");
- }
- }
- }
-
- @Override
- public void create() {
- try {
- StickinessPolicy result = _lbService.createLBStickinessPolicy(this);
- this.setEntityId(result.getId());
- } catch (NetworkRuleConflictException e) {
- s_logger.warn("Exception: ", e);
- throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
- }
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_LB_STICKINESSPOLICY_CREATE;
- }
-
- @Override
- public String getEventDescription() {
- return "creating a Load Balancer Stickiness policy: " + getLBStickinessPolicyName();
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java b/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java
deleted file mode 100644
index 80a8684..0000000
--- a/api/src/com/cloud/api/commands/CreateLoadBalancerRuleCmd.java
+++ /dev/null
@@ -1,381 +0,0 @@
-// 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.api.commands;
-
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCreateCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.LoadBalancerResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.dc.DataCenter;
-import com.cloud.dc.DataCenter.NetworkType;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InsufficientAddressCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.IpAddress;
-import com.cloud.network.Network;
-import com.cloud.network.rules.LoadBalancer;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-import com.cloud.utils.net.NetUtils;
-
-@Implementation(description="Creates a load balancer rule", responseObject=LoadBalancerResponse.class)
-public class CreateLoadBalancerRuleCmd extends BaseAsyncCreateCmd /*implements LoadBalancer */{
- public static final Logger s_logger = Logger.getLogger(CreateLoadBalancerRuleCmd.class.getName());
-
- private static final String s_name = "createloadbalancerruleresponse";
-
- /////////////////////////////////////////////////////
- //////////////// 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 loadBalancerRuleName;
-
- @Parameter(name=ApiConstants.PRIVATE_PORT, type=CommandType.INTEGER, required=true, description="the private port of the private ip address/virtual machine where the network traffic will be load balanced to")
- private Integer privatePort;
-
- @IdentityMapper(entityTableName="user_ip_address")
- @Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, description="public ip address id from where the network traffic will be load balanced from")
- private Long publicIpId;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=false, description="zone where the load balancer is going to be created. This parameter is required when LB service provider is ElasticLoadBalancerVm")
- private Long zoneId;
-
- @Parameter(name=ApiConstants.PUBLIC_PORT, type=CommandType.INTEGER, required=true, description="the public port from where the network traffic will be load balanced from")
- private Integer publicPort;
-
- @Parameter(name = ApiConstants.OPEN_FIREWALL, type = CommandType.BOOLEAN, description = "if true, firewall rule for" +
- " source/end pubic port is automatically created; if false - firewall rule has to be created explicitely. If not specified 1) defaulted to false when LB" +
- " rule is being created for VPC guest network 2) in all other cases defaulted to true")
- private Boolean openFirewall;
-
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="the account associated with the load balancer. Must be used with the domainId parameter.")
- private String accountName;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the load balancer")
- private Long domainId;
-
- @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING, description = "the cidr list to forward traffic from")
- private List<String> cidrlist;
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, description="The guest network this " +
- "rule will be created for. Required when public Ip address is not associated with any Guest network yet (VPC case)")
- private Long networkId;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getAlgorithm() {
- return algorithm;
- }
-
- public String getDescription() {
- return description;
- }
-
- public String getLoadBalancerRuleName() {
- return loadBalancerRuleName;
- }
-
- public Integer getPrivatePort() {
- return privatePort;
- }
-
- public String getEntityTable() {
- return "firewall_rules";
- }
-
- public Long getSourceIpAddressId() {
- if (publicIpId != null) {
- IpAddress ipAddr = _networkService.getIp(publicIpId);
- if (ipAddr == null || !ipAddr.readyToUse()) {
- throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id " + ipAddr.getId());
- }
- } else if (getEntityId() != null) {
- LoadBalancer rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
- return rule.getSourceIpAddressId();
- }
-
- return publicIpId;
- }
-
- private Long getVpcId() {
- if (publicIpId != null) {
- IpAddress ipAddr = _networkService.getIp(publicIpId);
- if (ipAddr == null || !ipAddr.readyToUse()) {
- throw new InvalidParameterValueException("Unable to create load balancer rule, invalid IP address id " + ipAddr.getId());
- } else {
- return ipAddr.getVpcId();
- }
- }
- return null;
- }
-
-
- public Long getNetworkId() {
- if (networkId != null) {
- return networkId;
- }
- Long zoneId = getZoneId();
-
- if (zoneId == null) {
- Long ipId = getSourceIpAddressId();
- if (ipId == null) {
- throw new InvalidParameterValueException("Either networkId or zoneId or publicIpId has to be specified");
- }
- }
-
- if (zoneId != null) {
- DataCenter zone = _configService.getZone(zoneId);
- if (zone.getNetworkType() == NetworkType.Advanced) {
- List<? extends Network> networks = _networkService.getIsolatedNetworksOwnedByAccountInZone(getZoneId(), _accountService.getAccount(getEntityOwnerId()));
- if (networks.size() == 0) {
- String domain = _domainService.getDomain(getDomainId()).getName();
- throw new InvalidParameterValueException("Account name=" + getAccountName() + " domain=" + domain + " doesn't have virtual networks in zone=" + zone.getName());
- }
-
- if (networks.size() < 1) {
- throw new InvalidParameterValueException("Account doesn't have any Isolated networks in the zone");
- } else if (networks.size() > 1) {
- throw new InvalidParameterValueException("Account has more than one Isolated network in the zone");
- }
-
- return networks.get(0).getId();
- } else {
- Network defaultGuestNetwork = _networkService.getExclusiveGuestNetwork(zoneId);
- if (defaultGuestNetwork == null) {
- throw new InvalidParameterValueException("Unable to find a default Guest network for account " + getAccountName() + " in domain id=" + getDomainId());
- } else {
- return defaultGuestNetwork.getId();
- }
- }
- } else {
- IpAddress ipAddr = _networkService.getIp(publicIpId);
- if (ipAddr.getAssociatedWithNetworkId() != null) {
- return ipAddr.getAssociatedWithNetworkId();
- } else {
- throw new InvalidParameterValueException("Ip address id=" + publicIpId + " is not associated with any network");
- }
- }
- }
-
- public Integer getPublicPort() {
- return publicPort;
- }
-
- public String getName() {
- return loadBalancerRuleName;
- }
-
- public Boolean getOpenFirewall() {
- boolean isVpc = getVpcId() == null ? false : true;
- if (openFirewall != null) {
- if (isVpc && openFirewall) {
- throw new InvalidParameterValueException("Can't have openFirewall=true when IP address belongs to VPC");
- }
- return openFirewall;
- } else {
- if (isVpc) {
- return false;
- }
- return true;
- }
- }
-
- public List<String> getSourceCidrList() {
- if (cidrlist != null) {
- throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
- }
- return null;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public void execute() throws ResourceAllocationException, ResourceUnavailableException {
-
- UserContext callerContext = UserContext.current();
- boolean success = true;
- LoadBalancer rule = null;
- try {
- UserContext.current().setEventDetails("Rule Id: " + getEntityId());
-
- if (getOpenFirewall()) {
- success = success && _firewallService.applyFirewallRules(getSourceIpAddressId(), callerContext.getCaller());
- }
-
- // State might be different after the rule is applied, so get new object here
- rule = _entityMgr.findById(LoadBalancer.class, getEntityId());
- LoadBalancerResponse lbResponse = new LoadBalancerResponse();
- if (rule != null) {
- lbResponse = _responseGenerator.createLoadBalancerResponse(rule);
- setResponseObject(lbResponse);
- }
- lbResponse.setResponseName(getCommandName());
- } catch (Exception ex) {
- s_logger.warn("Failed to create LB rule due to exception ", ex);
- }finally {
- if (!success || rule == null) {
-
- if (getOpenFirewall()) {
- _firewallService.revokeRelatedFirewallRule(getEntityId(), true);
- }
- // no need to apply the rule on the backend as it exists in the db only
- _lbService.deleteLoadBalancerRule(getEntityId(), false);
-
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create load balancer rule");
- }
- }
- }
-
- @Override
- public void create() {
- //cidr list parameter is deprecated
- if (cidrlist != null) {
- throw new InvalidParameterValueException("Parameter cidrList is deprecated; if you need to open firewall rule for the specific cidr, please refer to createFirewallRule command");
- }
- try {
- LoadBalancer result = _lbService.createLoadBalancerRule(this, getOpenFirewall());
- this.setEntityId(result.getId());
- } catch (NetworkRuleConflictException e) {
- s_logger.warn("Exception: ", e);
- throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
- } catch (InsufficientAddressCapacityException e) {
- s_logger.warn("Exception: ", e);
- throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, e.getMessage());
- }
- }
-
- public Integer getSourcePortStart() {
- return publicPort.intValue();
- }
-
- public Integer getSourcePortEnd() {
- return publicPort.intValue();
- }
-
- public String getProtocol() {
- return NetUtils.TCP_PROTO;
- }
-
- public long getAccountId() {
- if (publicIpId != null)
- return _networkService.getIp(getSourceIpAddressId()).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");
- }
- }
-
- public long getDomainId() {
- if (publicIpId != null)
- return _networkService.getIp(getSourceIpAddressId()).getDomainId();
- if (domainId != null) {
- return domainId;
- }
- return UserContext.current().getCaller().getDomainId();
- }
-
- public int getDefaultPortStart() {
- return privatePort.intValue();
- }
-
- public int getDefaultPortEnd() {
- return privatePort.intValue();
- }
-
- @Override
- public long getEntityOwnerId() {
- return getAccountId();
- }
-
- public String getAccountName() {
- return accountName;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public void setPublicIpId(Long publicIpId) {
- this.publicIpId = publicIpId;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_LOAD_BALANCER_CREATE;
- }
-
- @Override
- public String getEventDescription() {
- return "creating load balancer: " + getName() + " account: " + getAccountName();
-
- }
-
- public String getXid() {
- /*FIXME*/
- return null;
- }
-
- public void setSourceIpAddressId(Long ipId) {
- this.publicIpId = ipId;
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.FirewallRule;
- }
-
-}
-
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateNetworkACLCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateNetworkACLCmd.java b/api/src/com/cloud/api/commands/CreateNetworkACLCmd.java
deleted file mode 100644
index 033a496..0000000
--- a/api/src/com/cloud/api/commands/CreateNetworkACLCmd.java
+++ /dev/null
@@ -1,328 +0,0 @@
-// 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.api.commands;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.log4j.Logger;
-
-import com.cloud.api.ApiConstants;
-import com.cloud.api.BaseAsyncCmd;
-import com.cloud.api.BaseAsyncCreateCmd;
-import com.cloud.api.BaseCmd;
-import com.cloud.api.IdentityMapper;
-import com.cloud.api.Implementation;
-import com.cloud.api.Parameter;
-import com.cloud.api.ServerApiException;
-import com.cloud.api.response.NetworkACLResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.NetworkRuleConflictException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.Network;
-import com.cloud.network.rules.FirewallRule;
-import com.cloud.network.vpc.Vpc;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-import com.cloud.utils.net.NetUtils;
-
-@Implementation(description = "Creates a ACL rule the given network (the network has to belong to VPC)",
-responseObject = NetworkACLResponse.class)
-public class CreateNetworkACLCmd extends BaseAsyncCreateCmd implements FirewallRule {
- public static final Logger s_logger = Logger.getLogger(CreateNetworkACLCmd.class.getName());
-
- private static final String s_name = "createnetworkaclresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true, description =
- "the protocol for the ACL rule. Valid values are TCP/UDP/ICMP.")
- private String protocol;
-
- @Parameter(name = ApiConstants.START_PORT, type = CommandType.INTEGER, description = "the starting port of ACL")
- private Integer publicStartPort;
-
- @Parameter(name = ApiConstants.END_PORT, type = CommandType.INTEGER, description = "the ending port of ACL")
- private Integer publicEndPort;
-
- @Parameter(name = ApiConstants.CIDR_LIST, type = CommandType.LIST, collectionType = CommandType.STRING,
- description = "the cidr list to allow traffic from/to")
- private List<String> cidrlist;
-
- @Parameter(name = ApiConstants.ICMP_TYPE, type = CommandType.INTEGER, description = "type of the icmp message being sent")
- private Integer icmpType;
-
- @Parameter(name = ApiConstants.ICMP_CODE, type = CommandType.INTEGER, description = "error code for this icmp message")
- private Integer icmpCode;
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG, required=true,
- description="The network of the vm the ACL will be created for")
- private Long networkId;
-
- @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, description="the traffic type for the ACL," +
- "can be Ingress or Egress, defaulted to Ingress if not specified")
- private String trafficType;
-
- // ///////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- public String getEntityTable() {
- return "firewall_rules";
- }
-
- public Long getIpAddressId() {
- return null;
- }
-
- @Override
- public String getProtocol() {
- return protocol.trim();
- }
-
- public List<String> getSourceCidrList() {
- if (cidrlist != null) {
- return cidrlist;
- } else {
- List<String> oneCidrList = new ArrayList<String>();
- oneCidrList.add(NetUtils.ALL_CIDRS);
- return oneCidrList;
- }
- }
-
- public long getVpcId() {
- Network network = _networkService.getNetwork(getNetworkId());
- if (network == null) {
- throw new InvalidParameterValueException("Invalid networkId is given");
- }
-
- Long vpcId = network.getVpcId();
- if (vpcId == null) {
- throw new InvalidParameterValueException("Can create network ACL only for the network belonging to the VPC");
- }
-
- return vpcId;
- }
-
- @Override
- public FirewallRule.TrafficType getTrafficType() {
- if (trafficType == null) {
- return FirewallRule.TrafficType.Ingress;
- }
- for (FirewallRule.TrafficType type : FirewallRule.TrafficType.values()) {
- if (type.toString().equalsIgnoreCase(trafficType)) {
- return type;
- }
- }
- throw new InvalidParameterValueException("Invalid traffic type " + trafficType);
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- public void setSourceCidrList(List<String> cidrs){
- cidrlist = cidrs;
- }
-
- @Override
- public void execute() throws ResourceUnavailableException {
- UserContext callerContext = UserContext.current();
- boolean success = false;
- FirewallRule rule = _networkACLService.getNetworkACL(getEntityId());
- try {
- UserContext.current().setEventDetails("Rule Id: " + getEntityId());
- success = _networkACLService.applyNetworkACLs(rule.getNetworkId(), callerContext.getCaller());
-
- // State is different after the rule is applied, so get new object here
- NetworkACLResponse aclResponse = new NetworkACLResponse();
- if (rule != null) {
- aclResponse = _responseGenerator.createNetworkACLResponse(rule);
- setResponseObject(aclResponse);
- }
- aclResponse.setResponseName(getCommandName());
- } finally {
- if (!success || rule == null) {
- _networkACLService.revokeNetworkACL(getEntityId(), true);
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network ACL");
- }
- }
- }
-
- @Override
- public long getId() {
- throw new UnsupportedOperationException("database id can only provided by VO objects");
- }
-
- @Override
- public String getXid() {
- // FIXME: We should allow for end user to specify Xid.
- return null;
- }
-
- @Override
- public Long getSourceIpAddressId() {
- return null;
- }
-
- @Override
- public Integer getSourcePortStart() {
- if (publicStartPort != null) {
- return publicStartPort.intValue();
- }
- return null;
- }
-
- @Override
- public Integer getSourcePortEnd() {
- if (publicEndPort == null) {
- if (publicStartPort != null) {
- return publicStartPort.intValue();
- }
- } else {
- return publicEndPort.intValue();
- }
-
- return null;
- }
-
- @Override
- public Purpose getPurpose() {
- return Purpose.Firewall;
- }
-
- @Override
- public State getState() {
- throw new UnsupportedOperationException("Should never call me to find the state");
- }
-
- @Override
- public long getNetworkId() {
- return networkId;
- }
-
- @Override
- public long getEntityOwnerId() {
- Vpc vpc = _vpcService.getVpc(getVpcId());
- if (vpc == null) {
- throw new InvalidParameterValueException("Invalid vpcId is given");
- }
-
- Account account = _accountService.getAccount(vpc.getAccountId());
- return account.getId();
- }
-
- @Override
- public long getDomainId() {
- Vpc vpc = _vpcService.getVpc(getVpcId());
- return vpc.getDomainId();
- }
-
- @Override
- public void create() {
- if (getSourceCidrList() != null) {
- for (String cidr: getSourceCidrList()){
- if (!NetUtils.isValidCIDR(cidr)){
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Source cidrs formatting error " + cidr);
- }
- }
- }
-
- try {
- FirewallRule result = _networkACLService.createNetworkACL(this);
- setEntityId(result.getId());
- } catch (NetworkRuleConflictException ex) {
- s_logger.info("Network rule conflict: " + ex.getMessage());
- s_logger.trace("Network Rule Conflict: ", ex);
- throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
- }
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_FIREWALL_OPEN;
- }
-
- @Override
- public String getEventDescription() {
- Network network = _networkService.getNetwork(networkId);
- return ("Createing Network ACL for Netowrk: " + network + " for protocol:" + this.getProtocol());
- }
-
- @Override
- public long getAccountId() {
- Vpc vpc = _vpcService.getVpc(getVpcId());
- return vpc.getAccountId();
- }
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return getNetworkId();
- }
-
- @Override
- public Integer getIcmpCode() {
- if (icmpCode != null) {
- return icmpCode;
- } else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
- return -1;
- }
- return null;
- }
-
- @Override
- public Integer getIcmpType() {
- if (icmpType != null) {
- return icmpType;
- } else if (protocol.equalsIgnoreCase(NetUtils.ICMP_PROTO)) {
- return -1;
-
- }
- return null;
- }
-
- @Override
- public Long getRelated() {
- return null;
- }
-
- @Override
- public FirewallRuleType getType() {
- return FirewallRuleType.User;
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.FirewallRule;
- }
-
-}