cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bfede...@apache.org
Subject [62/81] [abbrv] git commit: updated refs/heads/ui-restyle to e901b82
Date Mon, 14 Oct 2013 17:17:54 GMT
Fixes for resource details code: 1) Fixed the NPE happening when the resource detail couldn't
be located by the key passed through API 2) Added ResourceDetails interface, made all resource
details VO objects to implement it.


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

Branch: refs/heads/ui-restyle
Commit: c4084a7c3497ed959cd37cbd9d36d94df41b4eed
Parents: 52c2bc0
Author: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Authored: Thu Oct 10 11:03:15 2013 -0700
Committer: Alena Prokharchyk <alena.prokharchyk@citrix.com>
Committed: Thu Oct 10 11:13:47 2013 -0700

----------------------------------------------------------------------
 .../apache/cloudstack/api/ResourceDetail.java   | 27 ++++++++
 engine/schema/src/com/cloud/dc/DcDetailVO.java  | 12 +++-
 .../src/com/cloud/storage/VolumeDetailVO.java   | 12 +++-
 engine/schema/src/com/cloud/vm/NicDetailVO.java | 12 +++-
 .../schema/src/com/cloud/vm/UserVmDetailVO.java | 12 +++-
 .../com/cloud/api/query/QueryManagerImpl.java   | 67 ++++++--------------
 6 files changed, 83 insertions(+), 59 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c4084a7c/api/src/org/apache/cloudstack/api/ResourceDetail.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/api/ResourceDetail.java b/api/src/org/apache/cloudstack/api/ResourceDetail.java
new file mode 100644
index 0000000..0c5dcab
--- /dev/null
+++ b/api/src/org/apache/cloudstack/api/ResourceDetail.java
@@ -0,0 +1,27 @@
+// 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;
+
+public interface ResourceDetail {
+    
+    public long getResourceDetail();
+    
+    public String getName();
+    
+    public String getValue();
+
+}

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c4084a7c/engine/schema/src/com/cloud/dc/DcDetailVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/dc/DcDetailVO.java b/engine/schema/src/com/cloud/dc/DcDetailVO.java
index 15bfacb..158a8ed 100644
--- a/engine/schema/src/com/cloud/dc/DcDetailVO.java
+++ b/engine/schema/src/com/cloud/dc/DcDetailVO.java
@@ -16,8 +16,6 @@
 // under the License.
 package com.cloud.dc;
 
-import org.apache.cloudstack.api.InternalIdentity;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
@@ -25,9 +23,12 @@ import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.api.ResourceDetail;
+
 @Entity
 @Table(name="data_center_details")
-public class DcDetailVO implements InternalIdentity {
+public class DcDetailVO implements InternalIdentity, ResourceDetail {
     @Id
     @GeneratedValue(strategy=GenerationType.IDENTITY)
     @Column(name="id")
@@ -70,4 +71,9 @@ public class DcDetailVO implements InternalIdentity {
     public long getId() {
         return id;
     }
+
+    @Override
+    public long getResourceDetail() {
+        return dcId;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c4084a7c/engine/schema/src/com/cloud/storage/VolumeDetailVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/storage/VolumeDetailVO.java b/engine/schema/src/com/cloud/storage/VolumeDetailVO.java
index b0c8c1d..6d2a618 100644
--- a/engine/schema/src/com/cloud/storage/VolumeDetailVO.java
+++ b/engine/schema/src/com/cloud/storage/VolumeDetailVO.java
@@ -16,8 +16,6 @@
 // under the License.
 package com.cloud.storage;
 
-import org.apache.cloudstack.api.InternalIdentity;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
@@ -25,9 +23,12 @@ import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.api.ResourceDetail;
+
 @Entity
 @Table(name="volume_details")
-public class VolumeDetailVO implements InternalIdentity {
+public class VolumeDetailVO implements InternalIdentity, ResourceDetail {
     @Id
     @GeneratedValue(strategy=GenerationType.IDENTITY)
     @Column(name="id")
@@ -82,4 +83,9 @@ public class VolumeDetailVO implements InternalIdentity {
         this.value = value;
     }
 
+    @Override
+    public long getResourceDetail() {
+        return volumeId;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c4084a7c/engine/schema/src/com/cloud/vm/NicDetailVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/NicDetailVO.java b/engine/schema/src/com/cloud/vm/NicDetailVO.java
index 9149972..5d05501 100644
--- a/engine/schema/src/com/cloud/vm/NicDetailVO.java
+++ b/engine/schema/src/com/cloud/vm/NicDetailVO.java
@@ -16,8 +16,6 @@
 // under the License.
 package com.cloud.vm;
 
-import org.apache.cloudstack.api.InternalIdentity;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
@@ -25,9 +23,12 @@ import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.api.ResourceDetail;
+
 @Entity
 @Table(name="nic_details")
-public class NicDetailVO implements InternalIdentity {
+public class NicDetailVO implements InternalIdentity, ResourceDetail {
     @Id
     @GeneratedValue(strategy=GenerationType.IDENTITY)
     @Column(name="id")
@@ -82,4 +83,9 @@ public class NicDetailVO implements InternalIdentity {
         this.value = value;
     }
 
+    @Override
+    public long getResourceDetail() {
+        return nicId;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c4084a7c/engine/schema/src/com/cloud/vm/UserVmDetailVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/com/cloud/vm/UserVmDetailVO.java b/engine/schema/src/com/cloud/vm/UserVmDetailVO.java
index 245b577..5811ab4 100644
--- a/engine/schema/src/com/cloud/vm/UserVmDetailVO.java
+++ b/engine/schema/src/com/cloud/vm/UserVmDetailVO.java
@@ -16,8 +16,6 @@
 // under the License.
 package com.cloud.vm;
 
-import org.apache.cloudstack.api.InternalIdentity;
-
 import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.GeneratedValue;
@@ -25,9 +23,12 @@ import javax.persistence.GenerationType;
 import javax.persistence.Id;
 import javax.persistence.Table;
 
+import org.apache.cloudstack.api.InternalIdentity;
+import org.apache.cloudstack.api.ResourceDetail;
+
 @Entity
 @Table(name="user_vm_details")
-public class UserVmDetailVO implements InternalIdentity {
+public class UserVmDetailVO implements InternalIdentity, ResourceDetail {
     @Id
     @GeneratedValue(strategy=GenerationType.IDENTITY)
     @Column(name="id")
@@ -81,5 +82,10 @@ public class UserVmDetailVO implements InternalIdentity {
 	public void setValue(String value) {
 		this.value = value;
 	}
+
+    @Override
+    public long getResourceDetail() {
+        return vmId;
+    }
 	
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/c4084a7c/server/src/com/cloud/api/query/QueryManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/QueryManagerImpl.java b/server/src/com/cloud/api/query/QueryManagerImpl.java
index 21fa25e..3b247fa 100644
--- a/server/src/com/cloud/api/query/QueryManagerImpl.java
+++ b/server/src/com/cloud/api/query/QueryManagerImpl.java
@@ -19,7 +19,6 @@ package com.cloud.api.query;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashSet;
-import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -34,6 +33,7 @@ import org.apache.cloudstack.affinity.AffinityGroupVMMapVO;
 import org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDao;
 import org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDao;
 import org.apache.cloudstack.api.BaseListProjectAndAccountResourcesCmd;
+import org.apache.cloudstack.api.ResourceDetail;
 import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
 import org.apache.cloudstack.api.command.admin.internallb.ListInternalLBVMsCmd;
 import org.apache.cloudstack.api.command.admin.router.ListRoutersCmd;
@@ -128,7 +128,6 @@ import com.cloud.api.query.vo.TemplateJoinVO;
 import com.cloud.api.query.vo.UserAccountJoinVO;
 import com.cloud.api.query.vo.UserVmJoinVO;
 import com.cloud.api.query.vo.VolumeJoinVO;
-import com.cloud.dc.DcDetailVO;
 import com.cloud.dc.DedicatedResourceVO;
 import com.cloud.dc.dao.DcDetailsDao;
 import com.cloud.dc.dao.DedicatedResourceDao;
@@ -166,7 +165,6 @@ import com.cloud.storage.Storage.ImageFormat;
 import com.cloud.storage.Storage.TemplateType;
 import com.cloud.storage.VMTemplateVO;
 import com.cloud.storage.Volume;
-import com.cloud.storage.VolumeDetailVO;
 import com.cloud.storage.dao.VMTemplateDao;
 import com.cloud.storage.dao.VolumeDetailsDao;
 import com.cloud.template.VirtualMachineTemplate.TemplateFilter;
@@ -185,8 +183,6 @@ import com.cloud.utils.db.SearchCriteria;
 import com.cloud.utils.db.SearchCriteria.Func;
 import com.cloud.utils.db.SearchCriteria.Op;
 import com.cloud.vm.DomainRouterVO;
-import com.cloud.vm.NicDetailVO;
-import com.cloud.vm.UserVmDetailVO;
 import com.cloud.vm.UserVmVO;
 import com.cloud.vm.VirtualMachine;
 import com.cloud.vm.dao.DomainRouterDao;
@@ -3226,71 +3222,48 @@ public class QueryManagerImpl extends ManagerBase implements QueryService
{
         String resourceId = cmd.getResourceId();
         Long id = _taggedResourceMgr.getResourceId(resourceId, resourceType);
         List<ResourceDetailResponse> responseList = new ArrayList<ResourceDetailResponse>();
+        List<? extends ResourceDetail> detailList = new ArrayList<ResourceDetail>();
+        ResourceDetail requestedDetail = null;
+
         
         if (resourceType == ResourceTag.TaggedResourceType.Volume) {
-            List<VolumeDetailVO> detailList;
             if (key == null) {
                 detailList = _volumeDetailDao.findDetails(id);
             } else {
-                VolumeDetailVO volumeDetail = _volumeDetailDao.findDetail(id, key);
-                detailList = new LinkedList<VolumeDetailVO>();
-                detailList.add(volumeDetail);
-            }
-
-            for (VolumeDetailVO detail : detailList) {
-                ResourceDetailResponse detailResponse = createResourceDetailsResponse(id,
detail.getName(), detail.getValue(),
-                        ResourceTag.TaggedResourceType.Volume);
-                responseList.add(detailResponse);
+                requestedDetail = _volumeDetailDao.findDetail(id, key);
             }
-
         } else if (resourceType == ResourceTag.TaggedResourceType.Nic){
-            List<NicDetailVO> detailList;
             if (key == null) {
                 detailList = _nicDetailDao.findDetails(id);
             } else {
-                NicDetailVO nicDetail = _nicDetailDao.findDetail(id, key);
-                detailList = new LinkedList<NicDetailVO>();
-                detailList.add(nicDetail);
-            }
-
-            for (NicDetailVO detail : detailList) {
-                ResourceDetailResponse detailResponse = createResourceDetailsResponse(id,
detail.getName(), detail.getValue(),
-                        ResourceTag.TaggedResourceType.Nic);
-                responseList.add(detailResponse);
+                requestedDetail = _nicDetailDao.findDetail(id, key);
             }
         } else if (resourceType == ResourceTag.TaggedResourceType.UserVm){
-            List<UserVmDetailVO> detailList;
             if (key == null) {
                 detailList = _userVmDetailDao.findDetailsList(id);
             } else {
-                UserVmDetailVO vmDetail = _userVmDetailDao.findDetail(id, key);
-                detailList = new LinkedList<UserVmDetailVO>();
-                detailList.add(vmDetail);
-            }
-            for (UserVmDetailVO detail : detailList) {
-                ResourceDetailResponse detailResponse = createResourceDetailsResponse(id,
detail.getName(), detail.getValue(),
-                        ResourceTag.TaggedResourceType.UserVm);
-                responseList.add(detailResponse);
+                requestedDetail = _userVmDetailDao.findDetail(id, key);
             }
         } else if (resourceType == ResourceTag.TaggedResourceType.Zone){
-
-            List<DcDetailVO> details;
             if (key == null) {
-                details = _dcDetailsDao.findDetailsList(id);
+                detailList = _dcDetailsDao.findDetailsList(id);
             } else {
-                DcDetailVO zoneDetail = _dcDetailsDao.findDetail(id, key);
-                details = new LinkedList<DcDetailVO>();
-                details.add(zoneDetail);
+                requestedDetail = _dcDetailsDao.findDetail(id, key);
             }
-
-            List<ResourceDetailResponse> dcDetailResponseList = new ArrayList<ResourceDetailResponse>();
-            for (DcDetailVO detail : details) {
+        } else {
+            throw new UnsupportedServiceException("Resource type " + resourceType + " is
not supported by the cloudStack");
+        }
+        
+        if (requestedDetail != null) {
+            ResourceDetailResponse detailResponse = createResourceDetailsResponse(id, requestedDetail.getName(),
requestedDetail.getValue(),
+                    resourceType);
+            responseList.add(detailResponse);
+        } else {
+            for (ResourceDetail detail : detailList) {
                 ResourceDetailResponse detailResponse = createResourceDetailsResponse(id,
detail.getName(), detail.getValue(),
-                        ResourceTag.TaggedResourceType.Zone);
+                        resourceType);
                 responseList.add(detailResponse);
             }
-        } else {
-            throw new UnsupportedServiceException("Resource type " + resourceType + " is
not supported by the cloudStack");
         }
         
         return responseList;


Mime
View raw message