From ee0a4a41d0f8db2f895a1699150c60cac6facab8 Mon Sep 17 00:00:00 2001 From: Fang Wang Date: Wed, 5 Dec 2012 11:50:23 -0800 Subject: [PATCH] api_refactor: entity annotation and fix parameter - Add Entity annotation - Annotate few responses - Fix Parameter annotation to have entityType Signed-off-by: Rohit Yadav --- .../cloud/api/response/DomainResponse.java | 3 ++ .../api/response/InstanceGroupResponse.java | 3 ++ .../cloud/api/response/NetworkResponse.java | 3 ++ .../api/response/SecurityGroupResponse.java | 3 ++ .../cloud/api/response/UserVmResponse.java | 3 ++ .../com/cloud/api/response/ZoneResponse.java | 3 ++ api/src/org/apache/cloudstack/api/Entity.java | 28 +++++++++++++++++++ .../org/apache/cloudstack/api/Parameter.java | 2 ++ 8 files changed, 48 insertions(+) create mode 100644 api/src/org/apache/cloudstack/api/Entity.java diff --git a/api/src/com/cloud/api/response/DomainResponse.java b/api/src/com/cloud/api/response/DomainResponse.java index 03738a28527..4568f910695 100644 --- a/api/src/com/cloud/api/response/DomainResponse.java +++ b/api/src/com/cloud/api/response/DomainResponse.java @@ -17,10 +17,13 @@ package com.cloud.api.response; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.Entity; +import com.cloud.domain.Domain; import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; +@Entity(value = Domain.class) public class DomainResponse extends BaseResponse { @SerializedName(ApiConstants.ID) @Param(description="the ID of the domain") private IdentityProxy id = new IdentityProxy("domain"); diff --git a/api/src/com/cloud/api/response/InstanceGroupResponse.java b/api/src/com/cloud/api/response/InstanceGroupResponse.java index ba9963af10c..ec450c39c62 100644 --- a/api/src/com/cloud/api/response/InstanceGroupResponse.java +++ b/api/src/com/cloud/api/response/InstanceGroupResponse.java @@ -19,11 +19,14 @@ package com.cloud.api.response; import java.util.Date; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.Entity; +import com.cloud.vm.InstanceGroup; import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") +@Entity(value = InstanceGroup.class) public class InstanceGroupResponse extends BaseResponse implements ControlledEntityResponse{ @SerializedName(ApiConstants.ID) @Param(description="the id of the instance group") private IdentityProxy id = new IdentityProxy("instance_group"); diff --git a/api/src/com/cloud/api/response/NetworkResponse.java b/api/src/com/cloud/api/response/NetworkResponse.java index 78bae94ed79..5b6c4acc895 100644 --- a/api/src/com/cloud/api/response/NetworkResponse.java +++ b/api/src/com/cloud/api/response/NetworkResponse.java @@ -19,11 +19,14 @@ package com.cloud.api.response; import java.util.List; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.Entity; +import com.cloud.projects.ProjectAccount; import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") +@Entity(value = ProjectAccount.class) public class NetworkResponse extends BaseResponse implements ControlledEntityResponse{ @SerializedName(ApiConstants.ID) @Param(description="the id of the network") diff --git a/api/src/com/cloud/api/response/SecurityGroupResponse.java b/api/src/com/cloud/api/response/SecurityGroupResponse.java index 46dbd046b9c..e9931167499 100644 --- a/api/src/com/cloud/api/response/SecurityGroupResponse.java +++ b/api/src/com/cloud/api/response/SecurityGroupResponse.java @@ -19,11 +19,14 @@ package com.cloud.api.response; import java.util.List; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.Entity; +import com.cloud.network.security.SecurityGroup; import com.cloud.serializer.Param; import com.cloud.utils.IdentityProxy; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") +@Entity(value = SecurityGroup.class) public class SecurityGroupResponse extends BaseResponse implements ControlledEntityResponse{ @SerializedName(ApiConstants.ID) @Param(description="the ID of the security group") private IdentityProxy id = new IdentityProxy("security_group"); diff --git a/api/src/com/cloud/api/response/UserVmResponse.java b/api/src/com/cloud/api/response/UserVmResponse.java index d1f70e065bc..e7665b5404b 100755 --- a/api/src/com/cloud/api/response/UserVmResponse.java +++ b/api/src/com/cloud/api/response/UserVmResponse.java @@ -20,11 +20,14 @@ import java.util.Date; import java.util.List; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.Entity; +import com.cloud.vm.VirtualMachine; import com.cloud.serializer.Param; import com.cloud.utils.IdentityProxy; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") +@Entity(value = VirtualMachine.class) public class UserVmResponse extends BaseResponse implements ControlledEntityResponse { @SerializedName(ApiConstants.ID) @Param(description="the ID of the virtual machine") private IdentityProxy id = new IdentityProxy("vm_instance"); diff --git a/api/src/com/cloud/api/response/ZoneResponse.java b/api/src/com/cloud/api/response/ZoneResponse.java index 147e8a70db4..12967449791 100755 --- a/api/src/com/cloud/api/response/ZoneResponse.java +++ b/api/src/com/cloud/api/response/ZoneResponse.java @@ -19,11 +19,14 @@ package com.cloud.api.response; import java.util.List; import org.apache.cloudstack.api.ApiConstants; +import org.apache.cloudstack.api.Entity; +import com.cloud.dc.DataCenter; import com.cloud.utils.IdentityProxy; import com.cloud.serializer.Param; import com.google.gson.annotations.SerializedName; @SuppressWarnings("unused") +@Entity(value = DataCenter.class) public class ZoneResponse extends BaseResponse { @SerializedName(ApiConstants.ID) @Param(description="Zone id") private IdentityProxy id = new IdentityProxy("data_center"); diff --git a/api/src/org/apache/cloudstack/api/Entity.java b/api/src/org/apache/cloudstack/api/Entity.java new file mode 100644 index 00000000000..58c27bacc36 --- /dev/null +++ b/api/src/org/apache/cloudstack/api/Entity.java @@ -0,0 +1,28 @@ +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +package org.apache.cloudstack.api; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +/* There is a one on one mapping between the Entity and the EntityResponse + * to the OTW layer. Value is the actual entity class it refers to. + */ +@Retention(RetentionPolicy.RUNTIME) +public @interface Entity { + Class[] value() default {}; +} \ No newline at end of file diff --git a/api/src/org/apache/cloudstack/api/Parameter.java b/api/src/org/apache/cloudstack/api/Parameter.java index 2364d4f97c2..470ad260d70 100644 --- a/api/src/org/apache/cloudstack/api/Parameter.java +++ b/api/src/org/apache/cloudstack/api/Parameter.java @@ -37,6 +37,8 @@ public @interface Parameter { CommandType collectionType() default CommandType.OBJECT; + Class[] entityType() default Object.class; + boolean expose() default true; boolean includeInApiDoc() default true;