Add Region APIs

Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/ccf15cb5
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/ccf15cb5
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/ccf15cb5

Branch: refs/heads/master
Commit: ccf15cb5f6b50821af53e1a58ae499d983a4ac64
Parents: 8d436e9
Author: kishan <[email protected]>
Authored: Tue Jul 3 12:59:28 2012 -0700
Committer: kishan <[email protected]>
Committed: Tue Jul 3 12:59:28 2012 -0700

----------------------------------------------------------------------
 api/src/com/cloud/api/commands/AddRegionCmd.java   |   89 ++++++++++++++
 api/src/com/cloud/api/commands/ListRegionsCmd.java |   85 +++++++++++++
 .../com/cloud/api/commands/RemoveRegionCmd.java    |   78 ++++++++++++
 .../com/cloud/api/commands/UpdateRegionCmd.java    |   93 +++++++++++++++
 api/src/com/cloud/api/response/RegionResponse.java |   57 +++++++++
 5 files changed, 402 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ccf15cb5/api/src/com/cloud/api/commands/AddRegionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/AddRegionCmd.java 
b/api/src/com/cloud/api/commands/AddRegionCmd.java
new file mode 100644
index 0000000..0338b91
--- /dev/null
+++ b/api/src/com/cloud/api/commands/AddRegionCmd.java
@@ -0,0 +1,89 @@
+// 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.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.ServerApiException;
+import com.cloud.api.response.RegionResponse;
+import com.cloud.region.Region;
+import com.cloud.user.Account;
+
+@Implementation(description="Adds a Region", 
responseObject=RegionResponse.class)
+public class AddRegionCmd extends BaseCmd {
+    public static final Logger s_logger = 
Logger.getLogger(AddRegionCmd.class.getName());
+
+    private static final String s_name = "addregionresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, 
description="Id of the Region")
+    private Long id;
+    
+    @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, required=true, 
description="adds Region with this name")
+    private String regionName;
+
+    @Parameter(name=ApiConstants.END_POINT, type=CommandType.STRING, 
required=true, description="end_point of the Region")
+    private String endPoint;
+    
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+    
+    public String getRegionName() {
+        return regionName;
+    }
+
+    public String getEndPoint() {
+        return endPoint;
+    }  
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+    
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+    
+    @Override
+    public void execute(){
+        Region region = _regionService.addRegion(getId(), getRegionName(), 
getEndPoint());
+        if (region != null) {
+               RegionResponse response = 
_responseGenerator.createRegionResponse(region);
+            response.setResponseName(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
add Region");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ccf15cb5/api/src/com/cloud/api/commands/ListRegionsCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/ListRegionsCmd.java 
b/api/src/com/cloud/api/commands/ListRegionsCmd.java
new file mode 100644
index 0000000..38f24d4
--- /dev/null
+++ b/api/src/com/cloud/api/commands/ListRegionsCmd.java
@@ -0,0 +1,85 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.api.commands;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseListCmd;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.response.DomainResponse;
+import com.cloud.api.response.ListResponse;
+import com.cloud.api.response.RegionResponse;
+import com.cloud.region.Region;
+
+@Implementation(description="Lists Regions", 
responseObject=DomainResponse.class)
+public class ListRegionsCmd extends BaseListCmd {
+       public static final Logger s_logger = 
Logger.getLogger(ListDomainsCmd.class.getName());
+       
+    private static final String s_name = "listregionsresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="List 
domain by domain ID.")
+    private Long id;
+
+    @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, 
description="List domain by domain name.")
+    private String domainName;
+    
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    public String getRegionName() {
+        return domainName;
+    }
+    
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public void execute(){
+        List<? extends Region> result = _regionService.listRegions(this);
+        ListResponse<RegionResponse> response = new 
ListResponse<RegionResponse>();
+        List<RegionResponse> regionResponses = new ArrayList<RegionResponse>();
+        for (Region region : result) {
+               RegionResponse regionResponse = 
_responseGenerator.createRegionResponse(region);
+               regionResponse.setObjectName("region");
+               regionResponses.add(regionResponse);
+        }
+
+        response.setResponses(regionResponses);
+        response.setResponseName(getCommandName());
+        this.setResponseObject(response);
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ccf15cb5/api/src/com/cloud/api/commands/RemoveRegionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/RemoveRegionCmd.java 
b/api/src/com/cloud/api/commands/RemoveRegionCmd.java
new file mode 100644
index 0000000..2facc10
--- /dev/null
+++ b/api/src/com/cloud/api/commands/RemoveRegionCmd.java
@@ -0,0 +1,78 @@
+// 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.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.SuccessResponse;
+import com.cloud.domain.Domain;
+import com.cloud.event.EventTypes;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Removes specified region", 
responseObject=SuccessResponse.class)
+public class RemoveRegionCmd extends BaseCmd {
+    public static final Logger s_logger = 
Logger.getLogger(RemoveRegionCmd.class.getName());
+    private static final String s_name = "updateregionresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, 
description="ID of the region to delete")
+    private Long id;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM; 
+    }
+
+    @Override
+    public void execute(){
+        boolean result = _regionService.removeRegion(id);
+        if (result) {
+            SuccessResponse response = new SuccessResponse(getCommandName());
+            this.setResponseObject(response);
+        } else {
+            throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
remove region");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ccf15cb5/api/src/com/cloud/api/commands/UpdateRegionCmd.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/commands/UpdateRegionCmd.java 
b/api/src/com/cloud/api/commands/UpdateRegionCmd.java
new file mode 100644
index 0000000..bbdb3b0
--- /dev/null
+++ b/api/src/com/cloud/api/commands/UpdateRegionCmd.java
@@ -0,0 +1,93 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+package com.cloud.api.commands;
+
+import org.apache.log4j.Logger;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.api.BaseCmd;
+import com.cloud.api.IdentityMapper;
+import com.cloud.api.Implementation;
+import com.cloud.api.Parameter;
+import com.cloud.api.ServerApiException;
+import com.cloud.api.response.DomainResponse;
+import com.cloud.api.response.RegionResponse;
+import com.cloud.domain.Domain;
+import com.cloud.region.Region;
+import com.cloud.user.Account;
+import com.cloud.user.UserContext;
+
+@Implementation(description="Updates a region", 
responseObject=DomainResponse.class)
+public class UpdateRegionCmd extends BaseCmd {
+    public static final Logger s_logger = 
Logger.getLogger(UpdateRegionCmd.class.getName());
+    private static final String s_name = "updateregionresponse";
+
+    /////////////////////////////////////////////////////
+    //////////////// API parameters /////////////////////
+    /////////////////////////////////////////////////////
+
+    @Parameter(name=ApiConstants.ID, type=CommandType.LONG, required=true, 
description="ID of region to update")
+    private Long id;
+
+    @Parameter(name=ApiConstants.NAME, type=CommandType.STRING, 
description="updates region with this name")
+    private String regionName;
+    
+    @Parameter(name=ApiConstants.END_POINT, type=CommandType.STRING, 
description="updates region with this end point")
+    private String endPoint;
+
+    /////////////////////////////////////////////////////
+    /////////////////// Accessors ///////////////////////
+    /////////////////////////////////////////////////////
+
+    public Long getId() {
+        return id;
+    }
+
+    public String getRegionName() {
+        return regionName;
+    }
+    
+    public String getEndPoint() {
+        return endPoint;
+    }
+
+    /////////////////////////////////////////////////////
+    /////////////// API Implementation///////////////////
+    /////////////////////////////////////////////////////
+
+    @Override
+    public String getCommandName() {
+        return s_name;
+    }
+    
+    @Override
+    public long getEntityOwnerId() {
+        return Account.ACCOUNT_ID_SYSTEM;
+    }
+    
+    @Override
+    public void execute(){
+       Region region = _regionService.updateRegion(getId(), getRegionName(), 
getEndPoint());
+       if (region != null) {
+               RegionResponse response = 
_responseGenerator.createRegionResponse(region);
+               response.setResponseName(getCommandName());
+               this.setResponseObject(response);
+       } else {
+               throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to 
update Region");
+       }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/ccf15cb5/api/src/com/cloud/api/response/RegionResponse.java
----------------------------------------------------------------------
diff --git a/api/src/com/cloud/api/response/RegionResponse.java 
b/api/src/com/cloud/api/response/RegionResponse.java
new file mode 100644
index 0000000..c507621
--- /dev/null
+++ b/api/src/com/cloud/api/response/RegionResponse.java
@@ -0,0 +1,57 @@
+// 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.response;
+
+import com.cloud.api.ApiConstants;
+import com.cloud.serializer.Param;
+import com.google.gson.annotations.SerializedName;
+
+public class RegionResponse extends BaseResponse {
+    @SerializedName(ApiConstants.ID) @Param(description="the ID of the region")
+    private Long id;
+
+    @SerializedName(ApiConstants.NAME) @Param(description="the name of the 
region")
+    private String name;
+
+    @SerializedName(ApiConstants.END_POINT) @Param(description="the end point 
of the region")
+    private String endPoint;
+
+       public Long getId() {
+               return id;
+       }
+
+       public void setId(Long id) {
+               this.id = id;
+       }
+
+       public String getName() {
+               return name;
+       }
+
+       public void setName(String name) {
+               this.name = name;
+       }
+
+       public String getEndPoint() {
+               return endPoint;
+       }
+
+       public void setEndPoint(String endPoint) {
+               this.endPoint = endPoint;
+       }
+
+  }

Reply via email to