From 6a032e0295809105adedfadcc5c322e6c03730c4 Mon Sep 17 00:00:00 2001 From: Prasanna Santhanam Date: Fri, 21 Dec 2012 14:25:01 -0800 Subject: [PATCH 1/2] api: annotate the vpc related Cmds Signed-off-by: Prasanna Santhanam --- .../user/vpc/CreateStaticRouteCmd.java | 7 +++-- .../api/command/user/vpc/CreateVPCCmd.java | 24 +++++++++-------- .../user/vpc/ListPrivateGatewaysCmd.java | 10 +++---- .../command/user/vpc/ListStaticRoutesCmd.java | 15 ++++++----- .../command/user/vpc/ListVPCOfferingsCmd.java | 5 ++-- .../api/command/user/vpc/ListVPCsCmd.java | 26 ++++++++++--------- .../api/command/user/vpc/RestartVPCCmd.java | 5 ++-- .../api/command/user/vpc/UpdateVPCCmd.java | 5 ++-- .../api/response/StaticRouteResponse.java | 3 +++ .../api/response/VpcOfferingResponse.java | 3 +++ 10 files changed, 55 insertions(+), 48 deletions(-) diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java index a1d2c5de6e9..9b674d98589 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateStaticRouteCmd.java @@ -16,12 +16,12 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; +import org.apache.cloudstack.api.response.PrivateGatewayResponse; 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; @@ -41,9 +41,8 @@ public class CreateStaticRouteCmd extends BaseAsyncCreateCmd{ private static final String s_name = "createstaticrouteresponse"; public static final Logger s_logger = Logger.getLogger(CreateStaticRouteCmd.class.getName()); - @IdentityMapper(entityTableName="vpc_gateways") - @Parameter(name=ApiConstants.GATEWAY_ID, type=CommandType.LONG, required=true, - description="the gateway id we are creating static route for") + @Parameter(name=ApiConstants.GATEWAY_ID, type=CommandType.UUID, entityType=PrivateGatewayResponse.class, + required=true, description="the gateway id we are creating static route for") private Long gatewayId; @Parameter(name = ApiConstants.CIDR, required = true, type = CommandType.STRING, description = "static route cidr") diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java index 111f9fac24f..b5ad04eb256 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java @@ -16,16 +16,19 @@ // under the License. package org.apache.cloudstack.api.command.user.vpc; +import org.apache.cloudstack.api.response.VpcResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ProjectResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.api.response.VpcOfferingResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; 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 org.apache.cloudstack.api.response.VpcResponse; import com.cloud.event.EventTypes; import com.cloud.exception.ConcurrentOperationException; import com.cloud.exception.InsufficientCapacityException; @@ -47,17 +50,17 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ "Must be used with the domainId parameter.") private String accountName; - @IdentityMapper(entityTableName="domain") - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="the domain ID associated with the VPC. " + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class, + description="the domain ID associated with the VPC. " + "If used with the account parameter returns the VPC associated with the account for the specified domain.") private Long domainId; - @IdentityMapper(entityTableName="projects") - @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.LONG, description="create VPC for the project") + @Parameter(name=ApiConstants.PROJECT_ID, type=CommandType.UUID, entityType=ProjectResponse.class, + description="create VPC for the project") private Long projectId; - @IdentityMapper(entityTableName="data_center") - @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, required=true, description="the ID of the availability zone") + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class, + required=true, description="the ID of the availability zone") private Long zoneId; @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, description="the name of the VPC") @@ -71,9 +74,8 @@ public class CreateVPCCmd extends BaseAsyncCreateCmd{ "guest networks' cidrs should be within this CIDR") private String cidr; - - @IdentityMapper(entityTableName="vpc_offerings") - @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, required=true, description="the ID of the VPC offering") + @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.UUID, entityType=VpcOfferingResponse.class, + required=true, description="the ID of the VPC offering") private Long vpcOffering; @Parameter(name=ApiConstants.NETWORK_DOMAIN, type=CommandType.STRING, diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java index 3cde18c3c1f..12062c831e4 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/ListPrivateGatewaysCmd.java @@ -19,11 +19,11 @@ package org.apache.cloudstack.api.command.user.vpc; import java.util.ArrayList; import java.util.List; +import org.apache.cloudstack.api.response.VpcResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd; -import org.apache.cloudstack.api.IdentityMapper; import org.apache.cloudstack.api.Implementation; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; @@ -40,8 +40,8 @@ public class ListPrivateGatewaysCmd extends BaseListProjectAndAccountResourcesCm ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @IdentityMapper(entityTableName="vpc_gateways") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list private gateway by id") + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=PrivateGatewayResponse.class, + description="list private gateway by id") private Long id; @Parameter(name=ApiConstants.IP_ADDRESS, type=CommandType.STRING, description="list gateways by ip address") @@ -50,8 +50,8 @@ public class ListPrivateGatewaysCmd extends BaseListProjectAndAccountResourcesCm @Parameter(name=ApiConstants.VLAN, type=CommandType.STRING, description="list gateways by vlan") private String vlan; - @IdentityMapper(entityTableName="vpc") - @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="list gateways by vpc") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.UUID, entityType=VpcResponse.class, + description="list gateways by vpc") private Long vpcId; @Parameter(name=ApiConstants.STATE, type=CommandType.STRING, description="list gateways by state") diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/ListStaticRoutesCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/ListStaticRoutesCmd.java index 173db0cb02e..9efcc6d8e83 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/ListStaticRoutesCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/ListStaticRoutesCmd.java @@ -20,13 +20,14 @@ import java.util.ArrayList; import java.util.List; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListTaggedResourcesCmd; -import org.apache.cloudstack.api.IdentityMapper; import org.apache.cloudstack.api.Implementation; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; +import org.apache.cloudstack.api.response.PrivateGatewayResponse; import org.apache.cloudstack.api.response.StaticRouteResponse; import com.cloud.network.vpc.StaticRoute; import com.cloud.utils.Pair; +import org.apache.cloudstack.api.response.VpcResponse; @Implementation(description="Lists all static routes", responseObject=StaticRouteResponse.class) public class ListStaticRoutesCmd extends BaseListTaggedResourcesCmd { @@ -35,16 +36,16 @@ public class ListStaticRoutesCmd extends BaseListTaggedResourcesCmd { ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @IdentityMapper(entityTableName="static_routes") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list static route by id") + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=StaticRouteResponse.class, + description="list static route by id") private Long id; - @IdentityMapper(entityTableName="vpc") - @Parameter(name=ApiConstants.VPC_ID, type=CommandType.LONG, description="list static routes by vpc id") + @Parameter(name=ApiConstants.VPC_ID, type=CommandType.UUID, entityType=VpcResponse.class, + description="list static routes by vpc id") private Long vpcId; - @IdentityMapper(entityTableName="vpc_gateways") - @Parameter(name=ApiConstants.GATEWAY_ID, type=CommandType.LONG, description="list static routes by gateway id") + @Parameter(name=ApiConstants.GATEWAY_ID, type=CommandType.UUID, entityType=PrivateGatewayResponse.class, + description="list static routes by gateway id") private Long gatewayId; public Long getId() { diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java index 04b2d9a4c41..d10eac787de 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCOfferingsCmd.java @@ -23,7 +23,6 @@ import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListCmd; -import org.apache.cloudstack.api.IdentityMapper; import org.apache.cloudstack.api.Implementation; import org.apache.cloudstack.api.Parameter; import org.apache.cloudstack.api.response.ListResponse; @@ -38,8 +37,8 @@ public class ListVPCOfferingsCmd extends BaseListCmd{ ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @IdentityMapper(entityTableName="vpc_offerings") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list VPC offerings by id") + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=VpcOfferingResponse.class, + description="list VPC offerings by id") private Long id; @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list VPC offerings by name") diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java index 9a244c349d5..e9a7e290422 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/ListVPCsCmd.java @@ -19,15 +19,17 @@ package org.apache.cloudstack.api.command.user.vpc; import java.util.ArrayList; import java.util.List; +import org.apache.cloudstack.api.response.VpcResponse; +import org.apache.cloudstack.api.response.ZoneResponse; +import org.apache.cloudstack.api.response.VpcOfferingResponse; +import org.apache.cloudstack.api.response.DomainResponse; +import org.apache.cloudstack.api.response.ListResponse; import org.apache.log4j.Logger; import org.apache.cloudstack.api.ApiConstants; import org.apache.cloudstack.api.BaseListTaggedResourcesCmd; -import org.apache.cloudstack.api.IdentityMapper; import org.apache.cloudstack.api.Implementation; import org.apache.cloudstack.api.Parameter; -import org.apache.cloudstack.api.response.ListResponse; -import org.apache.cloudstack.api.response.VpcResponse; import com.cloud.network.vpc.Vpc; @@ -38,13 +40,13 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd{ ///////////////////////////////////////////////////// //////////////// API parameters ///////////////////// - ///////////////////////////////////////////////////// - @IdentityMapper(entityTableName="vpc") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="list VPC by id") + //////////////////////////////////////////////////// + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=VpcResponse.class, + description="list VPC by id") private Long id; - @IdentityMapper(entityTableName="data_center") - @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.LONG, description="list by zone") + @Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class, + description="list by zone") private Long zoneId; @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="list by name of the VPC") @@ -58,16 +60,16 @@ public class ListVPCsCmd extends BaseListTaggedResourcesCmd{ "guest networks' cidrs should be within this CIDR") private String cidr; - @IdentityMapper(entityTableName="vpc_offerings") - @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.LONG, description="list by ID of the VPC offering") + @Parameter(name=ApiConstants.VPC_OFF_ID, type=CommandType.UUID, entityType=VpcOfferingResponse.class + , description="list by ID of the VPC offering") private Long VpcOffId; @Parameter(name=ApiConstants.ACCOUNT, type=CommandType.STRING, description="list by account associated with the VPC. " + "Must be used with the domainId parameter.") private String accountName; - @IdentityMapper(entityTableName="domain") - @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.LONG, description="list by domain ID associated with the VPC. " + + @Parameter(name=ApiConstants.DOMAIN_ID, type=CommandType.UUID, entityType=DomainResponse.class, + description="list by domain ID associated with the VPC. " + "If used with the account parameter returns the VPC associated with the account for the specified domain.") private Long domainId; diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java index e954474ab29..47065b4d239 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/RestartVPCCmd.java @@ -21,7 +21,6 @@ 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; @@ -43,8 +42,8 @@ public class RestartVPCCmd extends BaseAsyncCmd{ //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @IdentityMapper(entityTableName="vpc") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC") + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=VpcResponse.class, + description="the id of the VPC") private Long id; diff --git a/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java b/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java index a0c16e15a0a..3299035bd15 100644 --- a/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java +++ b/api/src/org/apache/cloudstack/api/command/user/vpc/UpdateVPCCmd.java @@ -21,7 +21,6 @@ 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; @@ -39,8 +38,8 @@ public class UpdateVPCCmd extends BaseAsyncCmd{ //////////////// API parameters ///////////////////// ///////////////////////////////////////////////////// - @IdentityMapper(entityTableName="vpc") - @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="the id of the VPC") + @Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType=VpcResponse.class, + description="the id of the VPC") private Long id; @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, description="the name of the VPC") diff --git a/api/src/org/apache/cloudstack/api/response/StaticRouteResponse.java b/api/src/org/apache/cloudstack/api/response/StaticRouteResponse.java index 54831fe4a49..bfd2bb16a55 100644 --- a/api/src/org/apache/cloudstack/api/response/StaticRouteResponse.java +++ b/api/src/org/apache/cloudstack/api/response/StaticRouteResponse.java @@ -18,11 +18,14 @@ package org.apache.cloudstack.api.response; import java.util.List; +import com.cloud.network.vpc.StaticRoute; import org.apache.cloudstack.api.ApiConstants; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.Entity; +@Entity(value=StaticRoute.class) @SuppressWarnings("unused") public class StaticRouteResponse extends BaseResponse implements ControlledEntityResponse{ @SerializedName(ApiConstants.ID) @Param(description="the ID of static route") diff --git a/api/src/org/apache/cloudstack/api/response/VpcOfferingResponse.java b/api/src/org/apache/cloudstack/api/response/VpcOfferingResponse.java index 9ea47f9bd3c..8395612a8de 100644 --- a/api/src/org/apache/cloudstack/api/response/VpcOfferingResponse.java +++ b/api/src/org/apache/cloudstack/api/response/VpcOfferingResponse.java @@ -19,11 +19,14 @@ package org.apache.cloudstack.api.response; import java.util.Date; import java.util.List; +import com.cloud.network.vpc.VpcOffering; import org.apache.cloudstack.api.ApiConstants; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; import org.apache.cloudstack.api.BaseResponse; +import org.apache.cloudstack.api.Entity; +@Entity(value=VpcOffering.class) @SuppressWarnings("unused") public class VpcOfferingResponse extends BaseResponse { @SerializedName("id") @Param(description="the id of the vpc offering") From 03b47cb5010f0244b861cf0f9b6c9f12ce4dced3 Mon Sep 17 00:00:00 2001 From: Rohit Yadav Date: Fri, 21 Dec 2012 14:39:04 -0800 Subject: [PATCH 2/2] api: Temp. fix to be backward compatible to old way of id passing For some apis, the param=-1 is used to evaluate conditionals. Allow -1 to be passed for now. This is a APITODO/FIXME to fix stuff in service layer and then only get rid of it. Signed-off-by: Rohit Yadav --- server/src/com/cloud/api/ApiDispatcher.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java index 99ba05da833..839073edad7 100755 --- a/server/src/com/cloud/api/ApiDispatcher.java +++ b/server/src/com/cloud/api/ApiDispatcher.java @@ -617,6 +617,12 @@ public class ApiDispatcher { case UUID: if (paramObj.toString().isEmpty()) break; + if (paramObj.toString().equals("-1")) { + // FIXME: This is to handle a lot of hardcoded special cases where -1 is sent + // APITODO: Find and get rid of all hardcoded params in API Cmds and service layer + field.set(cmdObj, -1L); + break; + } // There may be multiple entities defined on the @Entity of a Response.class // UUID CommandType would expect only one entityType, so use the first entityType Class[] entities = annotation.entityType()[0].getAnnotation(Entity.class).value();