incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prachida...@apache.org
Subject git commit: refs/heads/4.1 - CLOUDSTACK-1136: [EC2 Query API] AssociateAdress, DisassociateAddress and ReleaseAddress fail with NPE
Date Mon, 11 Feb 2013 20:09:05 GMT
Updated Branches:
  refs/heads/4.1 d592ea10b -> 203fb466d


CLOUDSTACK-1136: [EC2 Query API] AssociateAdress, DisassociateAddress and ReleaseAddress fail
with NPE

When invalid parameter is provided as input for any of these API's we get an NPE


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

Branch: refs/heads/4.1
Commit: 203fb466deae775b373d6f00aa22bd008c0d3d39
Parents: d592ea1
Author: Likitha Shetty <Likitha.Shetty@citrix.com>
Authored: Mon Feb 11 12:04:55 2013 -0800
Committer: Prachi Damle <prachi@cloud.com>
Committed: Mon Feb 11 12:08:03 2013 -0800

----------------------------------------------------------------------
 .../cloud/bridge/service/core/ec2/EC2Engine.java   |   24 ++++++++++++--
 1 files changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/203fb466/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
----------------------------------------------------------------------
diff --git a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
index 9573d5b..b729f77 100644
--- a/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
+++ b/awsapi/src/com/cloud/bridge/service/core/ec2/EC2Engine.java
@@ -767,7 +767,10 @@ public class EC2Engine extends ManagerBase {
      */
     public boolean releaseAddress(EC2ReleaseAddress request) {
         try {
-            CloudStackIpAddress cloudIp = getApi().listPublicIpAddresses(null, null, null,
null, null, request.getPublicIp(), null, null, null).get(0);
+            List<CloudStackIpAddress> cloudIps = getApi().listPublicIpAddresses(null,
null, null, null, null, request.getPublicIp(), null, null, null);
+            if (cloudIps == null)
+                throw new EC2ServiceException(ServerError.InternalError, "Specified ipAddress
doesn't exist");
+            CloudStackIpAddress cloudIp = cloudIps.get(0);
             CloudStackInfoResponse resp = getApi().disassociateIpAddress(cloudIp.getId());
             if (resp != null) {
                 return resp.getSuccess();
@@ -787,8 +790,17 @@ public class EC2Engine extends ManagerBase {
      */
     public boolean associateAddress( EC2AssociateAddress request ) {
         try {
-            CloudStackIpAddress cloudIp = getApi().listPublicIpAddresses(null, null, null,
null, null, request.getPublicIp(), null, null, null).get(0);
-            CloudStackUserVm cloudVm = getApi().listVirtualMachines(null, null, true, null,
null, null, null, request.getInstanceId(), null, null, null, null, null, null, null, null,
null).get(0);
+            List<CloudStackIpAddress> cloudIps = getApi().listPublicIpAddresses(null,
null, null, null, null, request.getPublicIp(), null, null, null);
+            if (cloudIps == null)
+                throw new EC2ServiceException(ServerError.InternalError, "Specified ipAddress
doesn't exist");
+            CloudStackIpAddress cloudIp = cloudIps.get(0);
+
+            List<CloudStackUserVm> vmList = getApi().listVirtualMachines(null, null,
true, null, null, null, null,
+                    request.getInstanceId(), null, null, null, null, null, null, null, null,
null);
+            if (vmList == null || vmList.size() == 0) {
+                throw new EC2ServiceException(ServerError.InternalError, "Specified instance-id
doesn't exist");
+            }
+            CloudStackUserVm cloudVm = vmList.get(0);
 
             CloudStackInfoResponse resp = getApi().enableStaticNat(cloudIp.getId(), cloudVm.getId());
             if (resp != null) {
@@ -809,7 +821,11 @@ public class EC2Engine extends ManagerBase {
      */
     public boolean disassociateAddress( EC2DisassociateAddress request ) {
         try {
-            CloudStackIpAddress cloudIp = getApi().listPublicIpAddresses(null, null, null,
null, null, request.getPublicIp(), null, null, null).get(0);
+            List<CloudStackIpAddress> cloudIps = getApi().listPublicIpAddresses(null,
null, null, null, null, request.getPublicIp(), null, null, null);
+            if (cloudIps == null)
+                throw new EC2ServiceException(ServerError.InternalError, "Specified ipAddress
doesn't exist");
+            CloudStackIpAddress cloudIp = cloudIps.get(0);
+
             CloudStackInfoResponse resp = getApi().disableStaticNat(cloudIp.getId());
             if (resp != null) {
                 return resp.getSuccess();


Mime
View raw message