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
[43/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/CreateNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateNetworkCmd.java b/api/src/com/cloud/api/commands/CreateNetworkCmd.java
deleted file mode 100644
index a536357..0000000
--- a/api/src/com/cloud/api/commands/CreateNetworkCmd.java
+++ /dev/null
@@ -1,234 +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.NetworkResponse;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.network.Network;
-import com.cloud.network.Network.GuestType;
-import com.cloud.offering.NetworkOffering;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Creates a network", responseObject=NetworkResponse.class)
-public class CreateNetworkCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreateNetworkCmd.class.getName());
-
- private static final String s_name = "createnetworkresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network")
- private String name;
-
- @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network")
- private String displayText;
-
- @IdentityMapper(entityTableName="network_offerings")
- @Parameter(name=ApiConstants.NETWORK_OFFERING_ID, type=CommandType.LONG, required=true, description="the network offering id")
- private Long networkOfferingId;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the network")
- private Long zoneId;
-
- @IdentityMapper(entityTableName="physical_network")
- @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
- private Long physicalNetworkId;
-
- @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, description="the gateway of the network. Required " +
- "for Shared networks and Isolated networks when it belongs to VPC")
- private String gateway;
-
- @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, description="the netmask of the network. Required " +
- "for Shared networks and Isolated networks when it belongs to VPC")
- private String netmask;
-
- @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, description="the beginning IP address in the network IP range")
- private String startIp;
-
- @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP" +
- " range. If not specified, will be defaulted to startIP")
- private String endIp;
-
- @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the ID or VID of the network")
- private String vlan;
-
- @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, description="network domain")
- private String networkDomain;
-
- @Parameter(name=ApiConstants.ACL_TYPE, type=CommandType.STRING, description="Access control type; supported values" +
- " are account and domain. In 3.0 all shared networks should have aclType=Domain, and all Isolated networks" +
- " - Account. Account means that only the account owner can use the network, domain - all accouns in the domain can use the network")
- private String aclType;
-
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network")
- private String accountName;
-
- @IdentityMapper(entityTableName="projects")
- @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project for the ssh key")
- private Long projectId;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network")
- private Long domainId;
-
- @Parameter(name=ApiConstants.SUBDOMAIN_ACCESS, type=CommandType.BOOLEAN, description="Defines whether to allow" +
- " subdomains to use networks dedicated to their parent domain(s). Should be used with aclType=Domain, defaulted to allow.subdomain.network.access global config if not specified")
- private Boolean subdomainAccess;
-
- @IdentityMapper(entityTableName="vpc")
- @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="the VPC network belongs to")
- private Long vpcId;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
- public Long getNetworkOfferingId() {
- return networkOfferingId;
- }
-
- public String getGateway() {
- return gateway;
- }
-
- public String getVlan() {
- return vlan;
- }
-
- public String getAccountName() {
- return accountName;
- }
-
- public Long getDomainId() {
- return domainId;
- }
-
- public String getNetmask() {
- return netmask;
- }
-
- public String getStartIp() {
- return startIp;
- }
-
- public String getEndIp() {
- return endIp;
- }
-
- public String getNetworkName() {
- return name;
- }
-
- public String getDisplayText() {
- return displayText;
- }
-
- public String getNetworkDomain() {
- return networkDomain;
- }
-
- public Long getProjectId() {
- return projectId;
- }
-
- public String getAclType() {
- return aclType;
- }
-
- public Boolean getSubdomainAccess() {
- return subdomainAccess;
- }
-
- public Long getVpcId() {
- return vpcId;
- }
-
- public Long getZoneId() {
- Long physicalNetworkId = getPhysicalNetworkId();
-
- if (physicalNetworkId == null && zoneId == null) {
- throw new InvalidParameterValueException("Zone id is required");
- }
-
- return zoneId;
- }
-
- public Long getPhysicalNetworkId() {
- NetworkOffering offering = _configService.getNetworkOffering(networkOfferingId);
- if (offering == null) {
- throw new InvalidParameterValueException("Unable to find network offering by id " + networkOfferingId);
- }
-
- if (physicalNetworkId != null) {
- if (offering.getGuestType() == GuestType.Shared) {
- return physicalNetworkId;
- } else {
- throw new InvalidParameterValueException("Physical network id can be specified for networks of guest ip type " + GuestType.Shared + " only.");
- }
- } else {
- if (zoneId == null) {
- throw new InvalidParameterValueException("ZoneId is required as physicalNetworkId is null");
- }
- return _networkService.findPhysicalNetworkId(zoneId, offering.getTags(), offering.getTrafficType());
- }
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
- if (accountId == null) {
- return UserContext.current().getCaller().getId();
- }
-
- return accountId;
- }
-
- @Override
- // an exception thrown by createNetwork() will be caught by the dispatcher.
- public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{
- Network result = _networkService.createGuestNetwork(this);
- if (result != null) {
- NetworkResponse response = _responseGenerator.createNetworkResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java b/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java
deleted file mode 100644
index 748f96e..0000000
--- a/api/src/com/cloud/api/commands/CreateNetworkOfferingCmd.java
+++ /dev/null
@@ -1,234 +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.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-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.NetworkOfferingResponse;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.network.Network.Capability;
-import com.cloud.network.Network.Service;
-import com.cloud.offering.NetworkOffering;
-import com.cloud.offering.NetworkOffering.Availability;
-import com.cloud.user.Account;
-
-@Implementation(description="Creates a network offering.", responseObject=NetworkOfferingResponse.class, since="3.0.0")
-public class CreateNetworkOfferingCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreateNetworkOfferingCmd.class.getName());
- private static final String _name = "createnetworkofferingresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network offering")
- private String networkOfferingName;
-
- @Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network offering")
- private String displayText;
-
- @Parameter(name=ApiConstants.TRAFFIC_TYPE, type=CommandType.STRING, required=true, description="the traffic type for the network offering. Supported type in current release is GUEST only")
- private String traffictype;
-
- @Parameter(name=ApiConstants.TAGS, type=CommandType.STRING, description="the tags for the network offering.", length=4096)
- private String tags;
-
- @Parameter(name=ApiConstants.SPECIFY_VLAN, type=CommandType.BOOLEAN, description="true if network offering supports vlans")
- private Boolean specifyVlan;
-
- @Parameter(name=ApiConstants.AVAILABILITY, type=CommandType.STRING, description="the availability of network offering. Default value is Optional")
- private String availability;
-
- @Parameter(name=ApiConstants.NETWORKRATE, type=CommandType.INTEGER, description="data transfer rate in megabits per second allowed")
- private Integer networkRate;
-
- @Parameter(name=ApiConstants.CONSERVE_MODE, type=CommandType.BOOLEAN, description="true if the network offering is IP conserve mode enabled")
- private Boolean conserveMode;
-
- @IdentityMapper(entityTableName="disk_offering")
- @Parameter(name=ApiConstants.SERVICE_OFFERING_ID, type=CommandType.LONG, description="the service offering ID used by virtual router provider")
- private Long serviceOfferingId;
-
- @Parameter(name=ApiConstants.GUEST_IP_TYPE, type=CommandType.STRING, required=true, description="guest type of the network offering: Shared or Isolated")
- private String guestIptype;
-
- @Parameter(name=ApiConstants.SUPPORTED_SERVICES, type=CommandType.LIST, required=true, collectionType=CommandType.STRING, description="services supported by the network offering")
- private List<String> supportedServices;
-
- @Parameter(name = ApiConstants.SERVICE_PROVIDER_LIST, type = CommandType.MAP, description = "provider to service mapping. If not specified, the provider for the service will be mapped to the default provider on the physical network")
- private Map serviceProviderList;
-
- @Parameter(name = ApiConstants.SERVICE_CAPABILITY_LIST, type = CommandType.MAP, description = "desired service capabilities as part of network offering")
- private Map serviceCapabilitystList;
-
- @Parameter(name=ApiConstants.SPECIFY_IP_RANGES, type=CommandType.BOOLEAN, description="true if network offering supports specifying ip ranges; defaulted to false if not specified")
- private Boolean specifyIpRanges;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getNetworkOfferingName() {
- return networkOfferingName;
- }
-
- public String getDisplayText() {
- return displayText;
- }
-
- public String getTags() {
- return tags;
- }
-
- public String getTraffictype() {
- return traffictype;
- }
-
- public Boolean getSpecifyVlan() {
- return specifyVlan == null ? false : specifyVlan;
- }
-
- public String getAvailability() {
- return availability == null ? Availability.Optional.toString() : availability;
- }
-
- public Integer getNetworkRate() {
- return networkRate;
- }
-
- public static String getName() {
- return _name;
- }
-
- public Long getServiceOfferingId() {
- return serviceOfferingId;
- }
-
- public List<String> getSupportedServices() {
- return supportedServices;
- }
-
- public String getGuestIpType() {
- return guestIptype;
- }
-
- public Boolean getSpecifyIpRanges() {
- return specifyIpRanges == null ? false : specifyIpRanges;
- }
-
- public Boolean getConserveMode() {
- if (conserveMode == null) {
- return true;
- }
- return conserveMode;
- }
-
- public Map<String, List<String>> getServiceProviders() {
- Map<String, List<String>> serviceProviderMap = null;
- if (serviceProviderList != null && !serviceProviderList.isEmpty()) {
- serviceProviderMap = new HashMap<String, List<String>>();
- Collection servicesCollection = serviceProviderList.values();
- Iterator iter = servicesCollection.iterator();
- while (iter.hasNext()) {
- HashMap<String, String> services = (HashMap<String, String>) iter.next();
- String service = services.get("service");
- String provider = services.get("provider");
- List<String> providerList = null;
- if (serviceProviderMap.containsKey(service)) {
- providerList = serviceProviderMap.get(service);
- } else {
- providerList = new ArrayList<String>();
- }
- providerList.add(provider);
- serviceProviderMap.put(service, providerList);
- }
- }
-
- return serviceProviderMap;
- }
-
- public Map<Capability, String> getServiceCapabilities(Service service) {
- Map<Capability, String> capabilityMap = null;
-
- if (serviceCapabilitystList != null && !serviceCapabilitystList.isEmpty()) {
- capabilityMap = new HashMap <Capability, String>();
- Collection serviceCapabilityCollection = serviceCapabilitystList.values();
- Iterator iter = serviceCapabilityCollection.iterator();
- while (iter.hasNext()) {
- HashMap<String, String> svcCapabilityMap = (HashMap<String, String>) iter.next();
- Capability capability = null;
- String svc = (String) svcCapabilityMap.get("service");
- String capabilityName = (String) svcCapabilityMap.get("capabilitytype");
- String capabilityValue = (String) svcCapabilityMap.get("capabilityvalue");
-
- if (capabilityName != null) {
- capability = Capability.getCapability(capabilityName);
- }
-
- if ((capability == null) || (capabilityName == null) || (capabilityValue == null) ) {
- throw new InvalidParameterValueException("Invalid capability:" + capabilityName + " capability value:" + capabilityValue);
- }
-
- if (svc.equalsIgnoreCase(service.getName())) {
- capabilityMap.put(capability, capabilityValue);
- } else {
- //throw new InvalidParameterValueException("Service is not equal ")
- }
- }
- }
-
- return capabilityMap;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public String getCommandName() {
- return _name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public void execute(){
- NetworkOffering result = _configService.createNetworkOffering(this);
- if (result != null) {
- NetworkOfferingResponse response = _responseGenerator.createNetworkOfferingResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create network offering");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreatePhysicalNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreatePhysicalNetworkCmd.java b/api/src/com/cloud/api/commands/CreatePhysicalNetworkCmd.java
deleted file mode 100644
index 537b9be..0000000
--- a/api/src/com/cloud/api/commands/CreatePhysicalNetworkCmd.java
+++ /dev/null
@@ -1,175 +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.PhysicalNetworkResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.network.PhysicalNetwork;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Creates a physical network", responseObject=PhysicalNetworkResponse.class, since="3.0.0")
-public class CreatePhysicalNetworkCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(CreatePhysicalNetworkCmd.class.getName());
-
- private static final String s_name = "createphysicalnetworkresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID for the physical network")
- private Long zoneId;
-
- @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="the VLAN for the physical network")
- private String vlan;
-
- @Parameter(name=ApiConstants.NETWORK_SPEED, type=CommandType.STRING, description="the speed for the physical network[1G/10G]")
- private String speed;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a physical network")
- private Long domainId;
-
- @Parameter(name=ApiConstants.BROADCAST_DOMAIN_RANGE, type=CommandType.STRING, description="the broadcast domain range for the physical network[Pod or Zone]. In Acton release it can be Zone only in Advance zone, and Pod in Basic")
- private String broadcastDomainRange;
-
- @Parameter(name=ApiConstants.TAGS, type=CommandType.LIST, collectionType=CommandType.STRING, description="Tag the physical network")
- private List<String> tags;
-
- @Parameter(name=ApiConstants.ISOLATION_METHODS, type=CommandType.LIST, collectionType=CommandType.STRING, description="the isolation method for the physical network[VLAN/L3/GRE]")
- private List<String> isolationMethods;
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the physical network")
- private String networkName;
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public List<String> getTags() {
- return tags;
- }
-
- @Override
- public String getEntityTable() {
- return "physical_network";
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public String getVlan() {
- return vlan;
- }
-
- public Long getDomainId() {
- return domainId;
- }
-
- public String getBroadcastDomainRange() {
- return broadcastDomainRange;
- }
-
- public List<String> getIsolationMethods() {
- return isolationMethods;
- }
-
- public String getNetworkSpeed() {
- return speed;
- }
-
- public String getNetworkName() {
- return networkName;
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_PHYSICAL_NETWORK_CREATE;
- }
-
- @Override
- public String getCreateEventType() {
- return EventTypes.EVENT_PHYSICAL_NETWORK_CREATE;
- }
-
- @Override
- public String getCreateEventDescription() {
- return "creating Physical Network";
- }
-
- @Override
- public String getEventDescription() {
- return "creating Physical Network. Id: "+getEntityId();
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public void execute(){
- UserContext.current().setEventDetails("Physical Network Id: "+getEntityId());
- PhysicalNetwork result = _networkService.getCreatedPhysicalNetwork(getEntityId());
- if (result != null) {
- PhysicalNetworkResponse response = _responseGenerator.createPhysicalNetworkResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- }else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create physical network");
- }
- }
-
- @Override
- public void create() throws ResourceAllocationException {
- PhysicalNetwork result = _networkService.createPhysicalNetwork(getZoneId(),getVlan(),getNetworkSpeed(), getIsolationMethods(),getBroadcastDomainRange(),getDomainId(), getTags(), getNetworkName());
- if (result != null) {
- setEntityId(result.getId());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create physical network entity");
- }
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.PhysicalNetwork;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreatePodCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreatePodCmd.java b/api/src/com/cloud/api/commands/CreatePodCmd.java
deleted file mode 100755
index 99a161b..0000000
--- a/api/src/com/cloud/api/commands/CreatePodCmd.java
+++ /dev/null
@@ -1,119 +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.PodResponse;
-import com.cloud.dc.Pod;
-import com.cloud.user.Account;
-
-@Implementation(description="Creates a new Pod.", responseObject=PodResponse.class)
-public class CreatePodCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreatePodCmd.class.getName());
-
- private static final String s_name = "createpodresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the Pod")
- private String podName;
-
- @IdentityMapper(entityTableName="data_center")
- @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the Zone ID in which the Pod will be created ")
- private Long zoneId;
-
- @Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, required=true, description="the starting IP address for the Pod")
- private String startIp;
-
- @Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address for the Pod")
- private String endIp;
-
- @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask for the Pod")
- private String netmask;
-
- @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway for the Pod")
- private String gateway;
-
- @Parameter(name=ApiConstants.ALLOCATION_STATE, type=CommandType.STRING, description="Allocation state of this Pod for allocation of new resources")
- private String allocationState;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getNetmask() {
- return netmask;
- }
-
- public String getEndIp() {
- return endIp;
- }
-
- public String getGateway() {
- return gateway;
- }
-
- public String getPodName() {
- return podName;
- }
-
- public String getStartIp() {
- return startIp;
- }
-
- public Long getZoneId() {
- return zoneId;
- }
-
- public String getAllocationState() {
- return allocationState;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public void execute(){
- Pod result = _configService.createPod(getZoneId(), getPodName(), getStartIp(), getEndIp(), getGateway(), getNetmask(), getAllocationState());
- if (result != null) {
- PodResponse response = _responseGenerator.createPodResponse(result, false);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create pod");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java b/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
deleted file mode 100644
index 3f3915a..0000000
--- a/api/src/com/cloud/api/commands/CreatePortForwardingRuleCmd.java
+++ /dev/null
@@ -1,373 +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.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.PortForwardingRule;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-import com.cloud.utils.net.Ip;
-
-@Implementation(description = "Creates a port forwarding rule", responseObject = FirewallRuleResponse.class)
-public class CreatePortForwardingRuleCmd extends BaseAsyncCreateCmd implements PortForwardingRule {
- public static final Logger s_logger = Logger.getLogger(CreatePortForwardingRuleCmd.class.getName());
-
- private static final String s_name = "createportforwardingruleresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// 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.PRIVATE_START_PORT, type = CommandType.INTEGER, required = true,
- description = "the starting port of port forwarding rule's private port range")
- private Integer privateStartPort;
-
- @Parameter(name = ApiConstants.PROTOCOL, type = CommandType.STRING, required = true,
- description = "the protocol for the port fowarding rule. Valid values are TCP or UDP.")
- private String protocol;
-
- @Parameter(name = ApiConstants.PRIVATE_END_PORT, type = CommandType.INTEGER, required = false, description = "the ending port of port forwarding rule's private port range")
- private Integer privateEndPort;
-
- @Parameter(name = ApiConstants.PUBLIC_START_PORT, type = CommandType.INTEGER, required = true,
- description = "the starting port of port forwarding rule's public port range")
- private Integer publicStartPort;
-
- @Parameter(name = ApiConstants.PUBLIC_END_PORT, type = CommandType.INTEGER, required = false, description = "the ending port of port forwarding rule's private port range")
- private Integer publicEndPort;
-
- @IdentityMapper(entityTableName = "vm_instance")
- @Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.LONG, required = true,
- description = "the ID of the virtual machine for the port forwarding rule")
- private Long virtualMachineId;
-
- @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.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 PF" +
- " rule is being created for VPC guest network 2) in all other cases defaulted to true")
- private Boolean openFirewall;
-
- @IdentityMapper(entityTableName="networks")
- @Parameter(name=ApiConstants.NETWORK_ID, type=CommandType.LONG,
- description="The network of the vm the Port Forwarding 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 getEntityTable() {
- return "firewall_rules";
- }
-
- public Long getIpAddressId() {
- return ipAddressId;
- }
-
- @Override
- public String getProtocol() {
- return protocol.trim();
- }
-
- @Override
- public long getVirtualMachineId() {
- return virtualMachineId;
- }
-
- 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;
- }
-
- 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;
- }
- }
-
- private Long getVpcId() {
- if (ipAddressId != null) {
- IpAddress ipAddr = _networkService.getIp(ipAddressId);
- if (ipAddr == null || !ipAddr.readyToUse()) {
- throw new InvalidParameterValueException("Unable to create PF rule, invalid IP address id " + ipAddr.getId());
- } else {
- return ipAddr.getVpcId();
- }
- }
- return null;
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
-
- @Override
- public void execute() throws ResourceUnavailableException {
- UserContext callerContext = UserContext.current();
- boolean success = true;
- PortForwardingRule rule = null;
- try {
- UserContext.current().setEventDetails("Rule Id: " + getEntityId());
-
- if (getOpenFirewall()) {
- success = success && _firewallService.applyFirewallRules(ipAddressId, callerContext.getCaller());
- }
-
- success = success && _rulesService.applyPortForwardingRules(ipAddressId, callerContext.getCaller());
-
- // State is different after the rule is applied, so get new object here
- rule = _entityMgr.findById(PortForwardingRule.class, getEntityId());
- FirewallRuleResponse fwResponse = new FirewallRuleResponse();
- if (rule != null) {
- fwResponse = _responseGenerator.createPortForwardingRuleResponse(rule);
- setResponseObject(fwResponse);
- }
- fwResponse.setResponseName(getCommandName());
- } finally {
- if (!success || rule == null) {
-
- if (getOpenFirewall()) {
- _firewallService.revokeRelatedFirewallRule(getEntityId(), true);
- }
-
- _rulesService.revokePortForwardingRule(getEntityId(), true);
-
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to apply port forwarding 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() {
- return publicStartPort.intValue();
- }
-
- @Override
- public Integer getSourcePortEnd() {
- return (publicEndPort == null)? publicStartPort.intValue() : publicEndPort.intValue();
- }
-
- @Override
- public Purpose getPurpose() {
- return Purpose.PortForwarding;
- }
-
- @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();
- } else {
- ntwkId = networkId;
- }
- if (ntwkId == null) {
- throw new InvalidParameterValueException("Unable to create port forwarding 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 Ip getDestinationIpAddress() {
- return null;
- }
-
- @Override
- public void setDestinationIpAddress(Ip destinationIpAddress) {
- return;
- }
-
- @Override
- public int getDestinationPortStart() {
- return privateStartPort.intValue();
- }
-
- @Override
- public int getDestinationPortEnd() {
- return (privateEndPort == null)? privateStartPort.intValue() : privateEndPort.intValue();
- }
-
- @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 {
- PortForwardingRule result = _rulesService.createPortForwardingRule(this, virtualMachineId, getOpenFirewall());
- setEntityId(result.getId());
- } catch (NetworkRuleConflictException ex) {
- s_logger.info("Network rule conflict: " , ex);
- s_logger.trace("Network Rule Conflict: ", ex);
- throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, ex.getMessage());
- }
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_NET_RULE_ADD;
- }
-
- @Override
- public String getEventDescription() {
- IpAddress ip = _networkService.getIp(ipAddressId);
- return ("Applying port forwarding rule for Ip: " + ip.getAddress() + " with virtual machine:" + virtualMachineId);
- }
-
- @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() {
- return null;
- }
-
- @Override
- public Integer getIcmpType() {
- 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/CreatePrivateGatewayCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreatePrivateGatewayCmd.java b/api/src/com/cloud/api/commands/CreatePrivateGatewayCmd.java
deleted file mode 100644
index c56f9af..0000000
--- a/api/src/com/cloud/api/commands/CreatePrivateGatewayCmd.java
+++ /dev/null
@@ -1,182 +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.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.PrivateGatewayResponse;
-import com.cloud.async.AsyncJob;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.ConcurrentOperationException;
-import com.cloud.exception.InsufficientCapacityException;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.exception.ResourceUnavailableException;
-import com.cloud.network.vpc.PrivateGateway;
-import com.cloud.network.vpc.Vpc;
-import com.cloud.user.Account;
-
-@Implementation(description="Creates a private gateway", responseObject=PrivateGatewayResponse.class)
-public class CreatePrivateGatewayCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(CreatePrivateGatewayCmd.class.getName());
-
- private static final String s_name = "createprivategatewayresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @IdentityMapper(entityTableName="physical_network")
- @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, description="the Physical Network ID the network belongs to")
- private Long physicalNetworkId;
-
- @Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway of the Private gateway")
- private String gateway;
-
- @Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask of the Private gateway")
- private String netmask;
-
- @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, required=true, description="the IP address of the Private gateaway")
- private String ipAddress;
-
- @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, required=true, description="the Vlan for the private gateway")
- private String vlan;
-
- @IdentityMapper(entityTableName="vpc")
- @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, required=true, description="the VPC network belongs to")
- private Long vpcId;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getGateway() {
- return gateway;
- }
-
- public String getVlan() {
- return vlan;
- }
-
- public String getNetmask() {
- return netmask;
- }
-
- public String getStartIp() {
- return ipAddress;
- }
-
- public Long getPhysicalNetworkId() {
- return physicalNetworkId;
- }
-
- public Long getVpcId() {
- return vpcId;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public String getCommandName() {
- return s_name;
- }
-
-
- @Override
- public void create() throws ResourceAllocationException {
- PrivateGateway result = null;
- try {
- result = _vpcService.createVpcPrivateGateway(getVpcId(), getPhysicalNetworkId(),
- getVlan(), getStartIp(), getGateway(), getNetmask(), getEntityOwnerId());
- } catch (InsufficientCapacityException ex){
- s_logger.info(ex);
- s_logger.trace(ex);
- throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, ex.getMessage());
- } catch (ConcurrentOperationException ex) {
- s_logger.warn("Exception: ", ex);
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
- }
-
- if (result != null) {
- this.setEntityId(result.getId());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway");
- }
- }
-
- @Override
- public void execute() throws InsufficientCapacityException, ConcurrentOperationException,
- ResourceAllocationException, ResourceUnavailableException {
- PrivateGateway result = _vpcService.applyVpcPrivateGateway(getEntityId(), true);
- if (result != null) {
- PrivateGatewayResponse response = _responseGenerator.createPrivateGatewayResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private gateway");
- }
- }
-
- @Override
- public long getEntityOwnerId() {
- return Account.ACCOUNT_ID_SYSTEM;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_PRIVATE_GATEWAY_CREATE;
- }
-
- @Override
- public String getEventDescription() {
- return "creating private gateway";
- }
-
- @Override
- public String getEntityTable() {
- return "vpc_gateways";
- }
-
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.vpcSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- Vpc vpc = _vpcService.getVpc(vpcId);
- if (vpc == null) {
- throw new InvalidParameterValueException("Invalid id is specified for the vpc");
- }
- return vpc.getId();
- }
-
- @Override
- public AsyncJob.Type getInstanceType() {
- return AsyncJob.Type.PrivateGateway;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java b/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java
index 99fd48f..92c7ac5 100644
--- a/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java
+++ b/api/src/com/cloud/api/commands/CreatePrivateNetworkCmd.java
@@ -16,16 +16,14 @@
// under the License.
package com.cloud.api.commands;
+import org.apache.cloudstack.api.*;
+import org.apache.cloudstack.api.response.DomainResponse;
+import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
+import org.apache.cloudstack.api.response.ProjectResponse;
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.NetworkResponse;
+import org.apache.cloudstack.api.APICommand;
+import org.apache.cloudstack.api.response.NetworkResponse;
import com.cloud.event.EventTypes;
import com.cloud.exception.ConcurrentOperationException;
import com.cloud.exception.InsufficientCapacityException;
@@ -33,7 +31,7 @@ import com.cloud.exception.ResourceAllocationException;
import com.cloud.network.Network;
import com.cloud.user.UserContext;
-@Implementation(description="Creates a private network", responseObject=NetworkResponse.class)
+@APICommand(description="Creates a private network", responseObject=NetworkResponse.class)
public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
public static final Logger s_logger = Logger.getLogger(CreatePrivateNetworkCmd.class.getName());
@@ -42,42 +40,42 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
-
+
@Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the network")
private String name;
-
+
@Parameter(name=ApiConstants.DISPLAY_TEXT, type=CommandType.STRING, required=true, description="the display text of the network")
private String displayText;
-
- @IdentityMapper(entityTableName="physical_network")
- @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.LONG, required=true, description="the Physical Network ID the network belongs to")
+
+ @Parameter(name=ApiConstants.PHYSICAL_NETWORK_ID, type=CommandType.UUID, entityType = PhysicalNetworkResponse.class,
+ required=true, description="the Physical Network ID the network belongs to")
private Long physicalNetworkId;
@Parameter(name=ApiConstants.GATEWAY, type=CommandType.STRING, required=true, description="the gateway of the network")
private String gateway;
-
+
@Parameter(name=ApiConstants.NETMASK, type=CommandType.STRING, required=true, description="the netmask of the network")
private String netmask;
-
+
@Parameter(name=ApiConstants.START_IP, type=CommandType.STRING, required=true, description="the beginning IP address in the network IP range")
private String startIp;
-
+
@Parameter(name=ApiConstants.END_IP, type=CommandType.STRING, description="the ending IP address in the network IP" +
" range. If not specified, will be defaulted to startIP")
private String endIp;
-
+
@Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, required=true, description="the ID or VID of the network")
private String vlan;
@Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="account who will own the network")
private String accountName;
-
- @IdentityMapper(entityTableName="projects")
- @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project for the ssh key")
+
+ @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType = ProjectResponse.class,
+ description="an optional project for the ssh key")
private Long projectId;
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="domain ID of the account owning a network")
+ @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType = DomainResponse.class,
+ description="domain ID of the account owning a network")
private Long domainId;
@@ -100,7 +98,7 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
public Long getDomainId() {
return domainId;
}
-
+
public String getNetmask() {
return netmask;
}
@@ -108,23 +106,23 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
public String getStartIp() {
return startIp;
}
-
+
public String getNetworkName() {
return name;
}
-
+
public String getDisplayText() {
return displayText;
}
-
+
public Long getProjectId() {
return projectId;
}
-
+
public long getPhysicalNetworkId() {
return physicalNetworkId;
}
-
+
public String getEndIp() {
return endIp;
}
@@ -136,8 +134,8 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
public String getCommandName() {
return s_name;
}
-
-
+
+
@Override
public void create() throws ResourceAllocationException {
Network result = null;
@@ -152,14 +150,14 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
s_logger.warn("Exception: ", ex);
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, ex.getMessage());
}
-
+
if (result != null) {
this.setEntityId(result.getId());
} else {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a Private network");
}
}
-
+
@Override
public void execute() throws InsufficientCapacityException, ConcurrentOperationException, ResourceAllocationException{
Network result = _networkService.getNetwork(getEntityId());
@@ -171,7 +169,7 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create private network");
}
}
-
+
@Override
public long getEntityOwnerId() {
Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
@@ -191,7 +189,7 @@ public class CreatePrivateNetworkCmd extends BaseAsyncCreateCmd {
return "creating private network";
}
-
+
@Override
public String getEntityTable() {
return "networks";
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateProjectCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateProjectCmd.java b/api/src/com/cloud/api/commands/CreateProjectCmd.java
deleted file mode 100644
index 12d1a2c..0000000
--- a/api/src/com/cloud/api/commands/CreateProjectCmd.java
+++ /dev/null
@@ -1,149 +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.ProjectResponse;
-import com.cloud.event.EventTypes;
-import com.cloud.exception.InvalidParameterValueException;
-import com.cloud.exception.ResourceAllocationException;
-import com.cloud.projects.Project;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(description = "Creates a project", responseObject = ProjectResponse.class, since = "3.0.0")
-public class CreateProjectCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(CreateProjectCmd.class.getName());
-
- private static final String s_name = "createprojectresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account who will be Admin for the project")
- private String accountName;
-
- @IdentityMapper(entityTableName = "domain")
- @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "domain ID of the account owning a project")
- private Long domainId;
-
- @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the project")
- private String name;
-
- @Parameter(name = ApiConstants.DISPLAY_TEXT, type = CommandType.STRING, required = true, description = "display text of the project")
- private String displayText;
-
- // ///////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- public String getEntityTable() {
- return "projects";
- }
-
- public String getAccountName() {
- if (accountName != null) {
- return accountName;
- } else {
- return UserContext.current().getCaller().getAccountName();
- }
- }
-
- public Long getDomainId() {
- if (domainId != null) {
- return domainId;
- } else {
- return UserContext.current().getCaller().getDomainId();
- }
-
- }
-
- public String getName() {
- return name;
- }
-
- public String getDisplayText() {
- return displayText;
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- Account caller = UserContext.current().getCaller();
-
- if ((accountName != null && domainId == null) || (domainId != null && accountName == null)) {
- throw new InvalidParameterValueException("Account name and domain id must be specified together");
- }
-
- if (accountName != null) {
- return _accountService.finalizeOwner(caller, accountName, domainId, null).getId();
- }
-
- return caller.getId();
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public void execute() {
- Project project = _projectService.enableProject(this.getEntityId());
- if (project != null) {
- ProjectResponse response = _responseGenerator.createProjectResponse(project);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
- }
- }
-
- @Override
- public void create() throws ResourceAllocationException {
- UserContext.current().setEventDetails("Project Name: " + getName());
- Project project = _projectService.createProject(getName(), getDisplayText(), getAccountName(), getDomainId());
- if (project != null) {
- this.setEntityId(project.getId());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create a project");
- }
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_PROJECT_CREATE;
- }
-
- @Override
- public String getEventDescription() {
- return "creating project";
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateRemoteAccessVpnCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateRemoteAccessVpnCmd.java b/api/src/com/cloud/api/commands/CreateRemoteAccessVpnCmd.java
deleted file mode 100644
index 6787d1f..0000000
--- a/api/src/com/cloud/api/commands/CreateRemoteAccessVpnCmd.java
+++ /dev/null
@@ -1,198 +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.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.RemoteAccessVpnResponse;
-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.RemoteAccessVpn;
-
-@Implementation(description="Creates a l2tp/ipsec remote access vpn", responseObject=RemoteAccessVpnResponse.class)
-public class CreateRemoteAccessVpnCmd extends BaseAsyncCreateCmd {
- public static final Logger s_logger = Logger.getLogger(CreateRemoteAccessVpnCmd.class.getName());
-
- private static final String s_name = "createremoteaccessvpnresponse";
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
- @IdentityMapper(entityTableName="user_ip_address")
- @Parameter(name=ApiConstants.PUBLIC_IP_ID, type=CommandType.LONG, required=true, description="public ip address id of the vpn server")
- private Long publicIpId;
-
- @Parameter(name="iprange", type=CommandType.STRING, required=false, description="the range of ip addresses to allocate to vpn clients. The first ip in the range will be taken by the vpn server")
- private String ipRange;
-
- @Deprecated
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the VPN. Must be used with domainId.")
- private String accountName;
-
- @Deprecated
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the VPN. If the account parameter is used, domainId must also be used.")
- private Long domainId;
-
- @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;
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getEntityTable() {
- return "user_ip_address";
- }
-
- public Long getPublicIpId() {
- return publicIpId;
- }
-
- public String getAccountName() {
- return accountName;
- }
-
- public Long getDomainId() {
- return domainId;
- }
-
- public String getIpRange() {
- return ipRange;
- }
-
- public void setIpRange(String ipRange) {
- this.ipRange = ipRange;
- }
-
- public Boolean getOpenFirewall() {
- if (openFirewall != null) {
- return openFirewall;
- } else {
- return true;
- }
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
-
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- IpAddress ip = _networkService.getIp(publicIpId);
-
- if (ip == null) {
- throw new InvalidParameterValueException("Unable to find ip address by id=" + publicIpId);
- }
-
- return ip.getAccountId();
- }
-
- @Override
- public String getEventDescription() {
- return "Create Remote Access VPN for account " + getEntityOwnerId() + " using public ip id=" + publicIpId;
- }
-
- @Override
- public String getEventType() {
- return EventTypes.EVENT_REMOTE_ACCESS_VPN_CREATE;
- }
-
- public long getNetworkId() {
- IpAddress ip = _entityMgr.findById(IpAddress.class, getPublicIpId());
- Long ntwkId = null;
-
- if (ip.getAssociatedWithNetworkId() != null) {
- ntwkId = ip.getAssociatedWithNetworkId();
- }
-
- if (ntwkId == null) {
- throw new InvalidParameterValueException("Unable to create remote access vpn for the ipAddress id=" + getPublicIpId() +
- " as ip is not associated with any network and no networkId is passed in");
- }
- return ntwkId;
- }
-
- @Override
- public void create() {
- try {
- RemoteAccessVpn vpn = _ravService.createRemoteAccessVpn(publicIpId, ipRange, getOpenFirewall(), getNetworkId());
- if (vpn != null) {
- this.setEntityId(vpn.getServerAddressId());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create remote access vpn");
- }
- } catch (NetworkRuleConflictException e) {
- s_logger.info("Network rule conflict: " + e.getMessage());
- s_logger.trace("Network Rule Conflict: ", e);
- throw new ServerApiException(BaseCmd.NETWORK_RULE_CONFLICT_ERROR, e.getMessage());
- }
- }
-
- @Override
- public void execute(){
- try {
- RemoteAccessVpn result = _ravService.startRemoteAccessVpn(publicIpId, getOpenFirewall());
- if (result != null) {
- RemoteAccessVpnResponse response = _responseGenerator.createRemoteAccessVpnResponse(result);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create remote access vpn");
- }
- } catch (ResourceUnavailableException ex) {
- s_logger.warn("Exception: ", ex);
- throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
- }
- }
-
-
- @Override
- public String getSyncObjType() {
- return BaseAsyncCmd.networkSyncObject;
- }
-
- @Override
- public Long getSyncObjId() {
- return getIp().getAssociatedWithNetworkId();
- }
-
- private IpAddress getIp() {
- IpAddress ip = _networkService.getIp(publicIpId);
- if (ip == null) {
- throw new InvalidParameterValueException("Unable to find ip address by id " + publicIpId);
- }
- return ip;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java b/api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java
deleted file mode 100644
index f750ee8..0000000
--- a/api/src/com/cloud/api/commands/CreateSSHKeyPairCmd.java
+++ /dev/null
@@ -1,102 +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.response.SSHKeyPairResponse;
-import com.cloud.user.SSHKeyPair;
-import com.cloud.user.UserContext;
-
-@Implementation(description="Create a new keypair and returns the private key", responseObject=SSHKeyPairResponse.class)
-public class CreateSSHKeyPairCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreateSSHKeyPairCmd.class.getName());
- private static final String s_name = "createsshkeypairresponse";
-
-
- /////////////////////////////////////////////////////
- //////////////// API parameters /////////////////////
- /////////////////////////////////////////////////////
-
- @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="Name of the keypair")
- private String name;
-
- //Owner information
- @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="an optional account for the ssh key. Must be used with domainId.")
- private String accountName;
-
- @IdentityMapper(entityTableName="domain")
- @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="an optional domainId for the ssh key. If the account parameter is used, domainId must also be used.")
- private Long domainId;
-
- @IdentityMapper(entityTableName="projects")
- @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="an optional project for the ssh key")
- private Long projectId;
-
-
- /////////////////////////////////////////////////////
- /////////////////// Accessors ///////////////////////
- /////////////////////////////////////////////////////
-
- public String getName() {
- return name;
- }
-
- public String getAccountName() {
- return accountName;
- }
-
- public Long getDomainId() {
- return domainId;
- }
-
- public Long getProjectId() {
- return projectId;
- }
-
- /////////////////////////////////////////////////////
- /////////////// API Implementation///////////////////
- /////////////////////////////////////////////////////
- @Override
- public long getEntityOwnerId() {
- Long accountId = finalyzeAccountId(accountName, domainId, projectId, true);
- if (accountId == null) {
- return UserContext.current().getCaller().getId();
- }
-
- return accountId;
- }
-
- @Override
- public void execute() {
- SSHKeyPair r = _mgr.createSSHKeyPair(this);
- SSHKeyPairResponse response = new SSHKeyPairResponse(r.getName(), r.getFingerprint(), r.getPrivateKey());
- response.setResponseName(getCommandName());
- response.setObjectName("keypair");
- this.setResponseObject(response);
- }
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/c4c9d2d8/api/src/com/cloud/api/commands/CreateSecurityGroupCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/CreateSecurityGroupCmd.java b/api/src/com/cloud/api/commands/CreateSecurityGroupCmd.java
deleted file mode 100644
index 62fae92..0000000
--- a/api/src/com/cloud/api/commands/CreateSecurityGroupCmd.java
+++ /dev/null
@@ -1,123 +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.SecurityGroupResponse;
-import com.cloud.network.security.SecurityGroup;
-import com.cloud.user.Account;
-import com.cloud.user.UserContext;
-
-@Implementation(responseObject = SecurityGroupResponse.class, description = "Creates a security group")
-public class CreateSecurityGroupCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(CreateSecurityGroupCmd.class.getName());
-
- private static final String s_name = "createsecuritygroupresponse";
-
- // ///////////////////////////////////////////////////
- // ////////////// API parameters /////////////////////
- // ///////////////////////////////////////////////////
-
- @Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "an optional account for the security group. Must be used with domainId.")
- private String accountName;
-
- @IdentityMapper(entityTableName = "domain")
- @Parameter(name = ApiConstants.DOMAIN_ID, type = CommandType.LONG, description = "an optional domainId for the security group. If the account parameter is used, domainId must also be used.")
- private Long domainId;
-
- @Parameter(name = ApiConstants.DESCRIPTION, type = CommandType.STRING, description = "the description of the security group")
- private String description;
-
- @Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "name of the security group")
- private String securityGroupName;
-
- @IdentityMapper(entityTableName = "projects")
- @Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.LONG, description = "Deploy vm for the project")
- private Long projectId;
-
- // ///////////////////////////////////////////////////
- // ///////////////// Accessors ///////////////////////
- // ///////////////////////////////////////////////////
-
- public String getAccountName() {
- return accountName;
- }
-
- public String getDescription() {
- return description;
- }
-
- public Long getDomainId() {
- return domainId;
- }
-
- public String getSecurityGroupName() {
- return securityGroupName;
- }
-
- public Long getProjectId() {
- return projectId;
- }
-
- // ///////////////////////////////////////////////////
- // ///////////// API Implementation///////////////////
- // ///////////////////////////////////////////////////
-
- @Override
- public String getCommandName() {
- return s_name;
- }
-
- @Override
- public long getEntityOwnerId() {
- Account account = UserContext.current().getCaller();
- if ((account == null) || isAdmin(account.getType())) {
- if ((domainId != null) && (accountName != null)) {
- Account userAccount = _responseGenerator.findAccountByNameDomain(accountName, domainId);
- if (userAccount != null) {
- return userAccount.getId();
- }
- }
- }
-
- 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() {
- SecurityGroup group = _securityGroupService.createSecurityGroup(this);
- if (group != null) {
- SecurityGroupResponse response = _responseGenerator.createSecurityGroupResponse(group);
- response.setResponseName(getCommandName());
- this.setResponseObject(response);
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to create security group");
- }
- }
-}