api_refactor: vpc admin apis Signed-off-by: Rohit Yadav <[email protected]>
Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/8d8285a8 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/8d8285a8 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/8d8285a8 Branch: refs/heads/api_refactoring Commit: 8d8285a8d4976dd3790e0262e183fd864b912a79 Parents: c24118e Author: Rohit Yadav <[email protected]> Authored: Wed Dec 5 14:13:09 2012 -0800 Committer: Rohit Yadav <[email protected]> Committed: Wed Dec 5 14:13:09 2012 -0800 ---------------------------------------------------------------------- .../api/commands/CreatePrivateGatewayCmd.java | 182 --------------- .../api/commands/DeletePrivateGatewayCmd.java | 114 --------- .../admin/vpc/command/CreatePrivateGatewayCmd.java | 182 +++++++++++++++ .../admin/vpc/command/DeletePrivateGatewayCmd.java | 114 +++++++++ client/tomcatconf/commands.properties.in | 4 +- 5 files changed, 298 insertions(+), 298 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8d8285a8/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 191354f..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 org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.cloudstack.api.BaseAsyncCreateCmd; -import org.apache.cloudstack.api.BaseCmd; -import org.apache.cloudstack.api.IdentityMapper; -import org.apache.cloudstack.api.Implementation; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.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/8d8285a8/api/src/com/cloud/api/commands/DeletePrivateGatewayCmd.java ---------------------------------------------------------------------- diff --git a/api/src/com/cloud/api/commands/DeletePrivateGatewayCmd.java b/api/src/com/cloud/api/commands/DeletePrivateGatewayCmd.java deleted file mode 100644 index 1fac808..0000000 --- a/api/src/com/cloud/api/commands/DeletePrivateGatewayCmd.java +++ /dev/null @@ -1,114 +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 org.apache.cloudstack.api.ApiConstants; -import org.apache.cloudstack.api.BaseAsyncCmd; -import org.apache.cloudstack.api.BaseCmd; -import org.apache.cloudstack.api.IdentityMapper; -import org.apache.cloudstack.api.Implementation; -import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.ServerApiException; -import com.cloud.api.response.SuccessResponse; -import com.cloud.async.AsyncJob; -import com.cloud.event.EventTypes; -import com.cloud.exception.ConcurrentOperationException; -import com.cloud.exception.InvalidParameterValueException; -import com.cloud.exception.ResourceUnavailableException; -import com.cloud.network.vpc.VpcGateway; -import com.cloud.user.Account; -import com.cloud.user.UserContext; - -@Implementation(description="Deletes a Private gateway", responseObject=SuccessResponse.class) -public class DeletePrivateGatewayCmd extends BaseAsyncCmd { - public static final Logger s_logger = Logger.getLogger(DeletePrivateGatewayCmd.class.getName()); - private static final String s_name = "deleteprivategatewayresponse"; - - ///////////////////////////////////////////////////// - //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - - @IdentityMapper(entityTableName="vpc_gateways") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the private gateway") - private Long id; - - ///////////////////////////////////////////////////// - /////////////////// Accessors /////////////////////// - ///////////////////////////////////////////////////// - - public Long getId() { - return id; - } - - ///////////////////////////////////////////////////// - /////////////// API Implementation/////////////////// - ///////////////////////////////////////////////////// - @Override - public String getCommandName() { - return s_name; - } - - @Override - public String getEventType() { - return EventTypes.EVENT_PRIVATE_GATEWAY_DELETE; - } - - @Override - public String getEventDescription() { - return ("Deleting private gateway id=" + id); - } - - @Override - public long getEntityOwnerId() { - return Account.ACCOUNT_ID_SYSTEM; - } - - @Override - public void execute() throws ResourceUnavailableException, ConcurrentOperationException { - UserContext.current().setEventDetails("Network ACL Id: " + id); - boolean result = _vpcService.deleteVpcPrivateGateway(id); - if (result) { - SuccessResponse response = new SuccessResponse(getCommandName()); - this.setResponseObject(response); - } else { - throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete private gateway"); - } - } - - - @Override - public String getSyncObjType() { - return BaseAsyncCmd.vpcSyncObject; - } - - @Override - public Long getSyncObjId() { - VpcGateway gateway = _vpcService.getVpcPrivateGateway(getId()); - if (gateway == null) { - throw new InvalidParameterValueException("Invalid private gateway id"); - } - return gateway.getVpcId(); - } - - @Override - public AsyncJob.Type getInstanceType() { - return AsyncJob.Type.PrivateGateway; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8d8285a8/api/src/org/apache/cloudstack/api/admin/vpc/command/CreatePrivateGatewayCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/admin/vpc/command/CreatePrivateGatewayCmd.java b/api/src/org/apache/cloudstack/api/admin/vpc/command/CreatePrivateGatewayCmd.java new file mode 100644 index 0000000..8abb0be --- /dev/null +++ b/api/src/org/apache/cloudstack/api/admin/vpc/command/CreatePrivateGatewayCmd.java @@ -0,0 +1,182 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.admin.vpc.command; + +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.BaseAsyncCreateCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.IdentityMapper; +import org.apache.cloudstack.api.Implementation; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.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/8d8285a8/api/src/org/apache/cloudstack/api/admin/vpc/command/DeletePrivateGatewayCmd.java ---------------------------------------------------------------------- diff --git a/api/src/org/apache/cloudstack/api/admin/vpc/command/DeletePrivateGatewayCmd.java b/api/src/org/apache/cloudstack/api/admin/vpc/command/DeletePrivateGatewayCmd.java new file mode 100644 index 0000000..4128e10 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/admin/vpc/command/DeletePrivateGatewayCmd.java @@ -0,0 +1,114 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api.admin.vpc.command; + +import org.apache.log4j.Logger; + +import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.BaseAsyncCmd; +import org.apache.cloudstack.api.BaseCmd; +import org.apache.cloudstack.api.IdentityMapper; +import org.apache.cloudstack.api.Implementation; +import org.apache.cloudstack.api.Parameter; +import org.apache.cloudstack.api.ServerApiException; +import com.cloud.api.response.SuccessResponse; +import com.cloud.async.AsyncJob; +import com.cloud.event.EventTypes; +import com.cloud.exception.ConcurrentOperationException; +import com.cloud.exception.InvalidParameterValueException; +import com.cloud.exception.ResourceUnavailableException; +import com.cloud.network.vpc.VpcGateway; +import com.cloud.user.Account; +import com.cloud.user.UserContext; + +@Implementation(description="Deletes a Private gateway", responseObject=SuccessResponse.class) +public class DeletePrivateGatewayCmd extends BaseAsyncCmd { + public static final Logger s_logger = Logger.getLogger(DeletePrivateGatewayCmd.class.getName()); + private static final String s_name = "deleteprivategatewayresponse"; + + ///////////////////////////////////////////////////// + //////////////// API parameters ///////////////////// + ///////////////////////////////////////////////////// + + @IdentityMapper(entityTableName="vpc_gateways") + @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, description="the ID of the private gateway") + private Long id; + + ///////////////////////////////////////////////////// + /////////////////// Accessors /////////////////////// + ///////////////////////////////////////////////////// + + public Long getId() { + return id; + } + + ///////////////////////////////////////////////////// + /////////////// API Implementation/////////////////// + ///////////////////////////////////////////////////// + @Override + public String getCommandName() { + return s_name; + } + + @Override + public String getEventType() { + return EventTypes.EVENT_PRIVATE_GATEWAY_DELETE; + } + + @Override + public String getEventDescription() { + return ("Deleting private gateway id=" + id); + } + + @Override + public long getEntityOwnerId() { + return Account.ACCOUNT_ID_SYSTEM; + } + + @Override + public void execute() throws ResourceUnavailableException, ConcurrentOperationException { + UserContext.current().setEventDetails("Network ACL Id: " + id); + boolean result = _vpcService.deleteVpcPrivateGateway(id); + if (result) { + SuccessResponse response = new SuccessResponse(getCommandName()); + this.setResponseObject(response); + } else { + throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete private gateway"); + } + } + + + @Override + public String getSyncObjType() { + return BaseAsyncCmd.vpcSyncObject; + } + + @Override + public Long getSyncObjId() { + VpcGateway gateway = _vpcService.getVpcPrivateGateway(getId()); + if (gateway == null) { + throw new InvalidParameterValueException("Invalid private gateway id"); + } + return gateway.getVpcId(); + } + + @Override + public AsyncJob.Type getInstanceType() { + return AsyncJob.Type.PrivateGateway; + } + +} http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/8d8285a8/client/tomcatconf/commands.properties.in ---------------------------------------------------------------------- diff --git a/client/tomcatconf/commands.properties.in b/client/tomcatconf/commands.properties.in index af0e45f..cb3f078 100755 --- a/client/tomcatconf/commands.properties.in +++ b/client/tomcatconf/commands.properties.in @@ -388,9 +388,9 @@ deleteVPCOffering=org.apache.cloudstack.api.admin.vpc.command.DeleteVPCOfferingC listVPCOfferings=org.apache.cloudstack.api.user.vpc.command.ListVPCOfferingsCmd;15 #### Private gateway commands -createPrivateGateway=com.cloud.api.commands.CreatePrivateGatewayCmd;1 +createPrivateGateway=org.apache.cloudstack.api.admin.vpc.command.CreatePrivateGatewayCmd;1 listPrivateGateways=org.apache.cloudstack.api.user.vpc.command.ListPrivateGatewaysCmd;15 -deletePrivateGateway=com.cloud.api.commands.DeletePrivateGatewayCmd;1 +deletePrivateGateway=org.apache.cloudstack.api.admin.vpc.command.DeletePrivateGatewayCmd;1 #### Network ACL commands createNetworkACL=org.apache.cloudstack.api.user.network.command.CreateNetworkACLCmd;15
