incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject [3/3] api: Refactoring ListEventsCmd and EventResponse, and create Event db view.
Date Sat, 08 Dec 2012 01:05:21 GMT
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30941c2d/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
index 3224bc9..966dfbd 100644
--- a/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
+++ b/server/src/com/cloud/tags/TaggedResourceManagerImpl.java
@@ -77,10 +77,10 @@ import com.cloud.vm.dao.UserVmDao;
 public class TaggedResourceManagerImpl implements TaggedResourceService, Manager{
     public static final Logger s_logger = Logger.getLogger(TaggedResourceManagerImpl.class);
     private String _name;
-    
-    private static Map<TaggedResourceType, GenericDao<?, Long>> _daoMap= 
+
+    private static Map<TaggedResourceType, GenericDao<?, Long>> _daoMap=
             new HashMap<TaggedResourceType, GenericDao<?, Long>>();
-    
+
     @Inject
     AccountManager _accountMgr;
     @Inject
@@ -122,7 +122,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
 
     @Override
     public boolean configure(String name, Map<String, Object> params) throws ConfigurationException
{
-        _name = name; 
+        _name = name;
         _daoMap.put(TaggedResourceType.UserVm, _userVmDao);
         _daoMap.put(TaggedResourceType.Volume, _volumeDao);
         _daoMap.put(TaggedResourceType.Template, _templateDao);
@@ -157,16 +157,16 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
         return _name;
     }
 
-    
-    private Long getResourceId(String resourceId, TaggedResourceType resourceType) {   
+
+    private Long getResourceId(String resourceId, TaggedResourceType resourceType) {
         GenericDao<?, Long> dao = _daoMap.get(resourceType);
         if (dao == null) {
             throw new CloudRuntimeException("Dao is not loaded for the resource type " +
resourceType);
         }
         Class<?> claz = DbUtil.getEntityBeanType(dao);
-        
+
         Long identityId = null;
-        
+
         while (claz != null && claz != Object.class) {
             try {
                 String tableName = DbUtil.getTableName(claz);
@@ -182,7 +182,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
             }
             claz = claz.getSuperclass();
         }
-       
+
         if (identityId == null) {
             throw new InvalidParameterValueException("Unable to find resource by id " + resourceId
+ " and type " + resourceType);
         }
@@ -194,9 +194,9 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
         Class<?> claz = DbUtil.getEntityBeanType(dao);
         return DbUtil.getTableName(claz);
     }
-    
+
     private Pair<Long, Long> getAccountDomain(long resourceId, TaggedResourceType resourceType)
{
-       
+
         Pair<Long, Long> pair = null;
         GenericDao<?, Long> dao = _daoMap.get(resourceType);
         Class<?> claz = DbUtil.getEntityBeanType(dao);
@@ -218,21 +218,21 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
 
         Long accountId = pair.first();
         Long domainId = pair.second();
-        
+
         if (accountId == null) {
             accountId = Account.ACCOUNT_ID_SYSTEM;
         }
-        
+
         if (domainId == null) {
             domainId = Domain.ROOT_DOMAIN;
         }
-        
+
         return new Pair<Long, Long>(accountId, domainId);
     }
 
     @Override
     public TaggedResourceType getResourceType(String resourceTypeStr) {
-        
+
         for (TaggedResourceType type : ResourceTag.TaggedResourceType.values()) {
             if (type.toString().equalsIgnoreCase(resourceTypeStr)) {
                 return type;
@@ -244,26 +244,26 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
     @Override
     @DB
     @ActionEvent(eventType = EventTypes.EVENT_TAGS_CREATE, eventDescription = "creating resource
tags")
-    public List<ResourceTag> createTags(List<String> resourceIds, TaggedResourceType
resourceType, 
+    public List<ResourceTag> createTags(List<String> resourceIds, TaggedResourceType
resourceType,
             Map<String, String> tags, String customer) {
         Account caller = UserContext.current().getCaller();
-        
+
         List<ResourceTag> resourceTags = new ArrayList<ResourceTag>(tags.size());
-        
+
         Transaction txn = Transaction.currentTxn();
         txn.start();
-        
+
         for (String key : tags.keySet()) {
             for (String resourceId : resourceIds) {
                 Long id = getResourceId(resourceId, resourceType);
                 String resourceUuid = getUuid(resourceId, resourceType);
-                
+
                 //check if object exists
                 if (_daoMap.get(resourceType).findById(id) == null) {
-                    throw new InvalidParameterValueException("Unable to find resource by
id " + resourceId + 
+                    throw new InvalidParameterValueException("Unable to find resource by
id " + resourceId +
                             " and type " + resourceType);
                 }
-                
+
                 Pair<Long, Long> accountDomainPair = getAccountDomain(id, resourceType);
                 Long domainId = accountDomainPair.second();
                 Long accountId = accountDomainPair.first();
@@ -276,53 +276,53 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
                     throw new PermissionDeniedException("Account " + caller + " doesn't have
permissions to create tags" +
                             " for resource " + key);
                 }
-                
+
                 String value = tags.get(key);
-                
+
                 if (value == null || value.isEmpty()) {
                     throw new InvalidParameterValueException("Value for the key " + key +
" is either null or empty");
                 }
-               
+
                 ResourceTagVO resourceTag = new ResourceTagVO(key, value, accountDomainPair.first(),
-                        accountDomainPair.second(), 
+                        accountDomainPair.second(),
                         id, resourceType, customer, resourceUuid);
                 resourceTag = _resourceTagDao.persist(resourceTag);
                 resourceTags.add(resourceTag);
             }
         }
-        
+
         txn.commit();
-        
+
         return resourceTags;
     }
-    
+
     @Override
     public String getUuid(String resourceId, TaggedResourceType resourceType) {
         GenericDao<?, Long> dao = _daoMap.get(resourceType);
         Class<?> claz = DbUtil.getEntityBeanType(dao);
-        
+
        String identiyUUId = null;
-       
+
        while (claz != null && claz != Object.class) {
            try {
                String tableName = DbUtil.getTableName(claz);
                if (tableName == null) {
                    throw new InvalidParameterValueException("Unable to find resource of type
" + resourceType + " in the database");
                }
-               
+
                claz = claz.getSuperclass();
                if (claz == Object.class) {
                    identiyUUId = _identityDao.getIdentityUuid(tableName, resourceId);
-               } 
+               }
            } catch (Exception ex) {
                //do nothing here, it might mean uuid field is missing and we have to search
further
            }
        }
-       
+
        if (identiyUUId == null) {
            return resourceId;
        }
-       
+
        return identiyUUId;
     }
 
@@ -337,7 +337,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
         String customerName = cmd.getCustomer();
         boolean listAll = cmd.listAll();
 
-        Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject
= 
+        Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject
=
                 new Ternary<Long, Boolean, ListProjectResourcesCriteria>(cmd.getDomainId(),
cmd.isRecursive(), null);
 
         _accountMgr.buildACLSearchParameters(caller, null, cmd.getAccountName(),
@@ -388,7 +388,7 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
         }
 
         Pair<List<ResourceTagJoinVO>, Integer> result = _resourceTagJoinDao.searchAndCount(sc,
searchFilter);
-        return new Pair<List<ResourceTagJoinVO>, Integer> (result.first(), result.second());
+        return result;
     }
 
     @Override
@@ -396,21 +396,21 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
     @ActionEvent(eventType = EventTypes.EVENT_TAGS_DELETE, eventDescription = "deleting resource
tags")
     public boolean deleteTags(List<String> resourceIds, TaggedResourceType resourceType,
Map<String, String> tags) {
         Account caller = UserContext.current().getCaller();
-        
+
         SearchBuilder<ResourceTagVO> sb = _resourceTagDao.createSearchBuilder();
         sb.and().op("resourceId", sb.entity().getResourceId(), SearchCriteria.Op.IN);
         sb.or("resourceUuid", sb.entity().getResourceUuid(), SearchCriteria.Op.IN);
         sb.cp();
         sb.and("resourceType", sb.entity().getResourceType(), SearchCriteria.Op.EQ);
-        
+
         SearchCriteria<ResourceTagVO> sc = sb.create();
         sc.setParameters("resourceId", resourceIds.toArray());
         sc.setParameters("resourceUuid", resourceIds.toArray());
         sc.setParameters("resourceType", resourceType);
-        
+
         List<? extends ResourceTag> resourceTags = _resourceTagDao.search(sc, null);;
         List<ResourceTag> tagsToRemove = new ArrayList<ResourceTag>();
-        
+
         // Finalize which tags should be removed
         for (ResourceTag resourceTag : resourceTags) {
             //1) validate the permissions
@@ -434,16 +434,16 @@ public class TaggedResourceManagerImpl implements TaggedResourceService,
Manager
                             break;
                         }
                     }
-                } 
+                }
             } else {
                 tagsToRemove.add(resourceTag);
             }
         }
-        
+
         if (tagsToRemove.isEmpty()) {
             throw new InvalidParameterValueException("Unable to find tags by parameters specified");
         }
-        
+
         //Remove the tags
         Transaction txn = Transaction.currentTxn();
         txn.start();

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30941c2d/server/src/com/cloud/tags/dao/ResourceTagJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/tags/dao/ResourceTagJoinDaoImpl.java b/server/src/com/cloud/tags/dao/ResourceTagJoinDaoImpl.java
index 6593f90..55b2f7f 100644
--- a/server/src/com/cloud/tags/dao/ResourceTagJoinDaoImpl.java
+++ b/server/src/com/cloud/tags/dao/ResourceTagJoinDaoImpl.java
@@ -94,13 +94,7 @@ public class ResourceTagJoinDaoImpl extends GenericDaoBase<ResourceTagJoinVO,
Lo
             response.setResourceType(resourceTag.getResourceType().toString());
             response.setResourceId(resourceTag.getResourceUuid());
 
-            if (resourceTag.getAccountType() == Account.ACCOUNT_TYPE_PROJECT) {
-
-                response.setProjectId(resourceTag.getProjectUuid());
-                response.setProjectName(resourceTag.getProjectName());
-            } else {
-                response.setAccountName(resourceTag.getAccountName());
-            }
+            ApiResponseHelper.populateOwner(response, resourceTag);
 
             response.setDomainId(resourceTag.getDomainUuid());
             response.setDomainName(resourceTag.getDomainName());

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/30941c2d/setup/db/create-schema.sql
----------------------------------------------------------------------
diff --git a/setup/db/create-schema.sql b/setup/db/create-schema.sql
index 3129fd5..d0c49c8 100755
--- a/setup/db/create-schema.sql
+++ b/setup/db/create-schema.sql
@@ -2802,3 +2802,36 @@ inner join account on resource_tags.account_id=account.id
 inner join domain on resource_tags.domain_id=domain.id
 left join projects on projects.project_account_id = resource_tags.account_id;
 
+
+DROP VIEW IF EXISTS `cloud`.`event_view`;
+CREATE VIEW event_view AS
+select
+event.id,
+event.uuid,
+event.type,
+event.state,
+event.description,
+event.created,
+event.level,
+event.parameters,
+event.start_id,
+eve.uuid start_uuid,
+event.user_id,
+user.username user_name,
+account.id account_id,
+account.uuid account_uuid,
+account.account_name account_name,
+account.type account_type,
+domain.id domain_id,
+domain.uuid domain_uuid,
+domain.name domain_name,
+domain.path domain_path,
+projects.id project_id,
+projects.uuid project_uuid,
+projects.name project_name
+from event
+inner join account on event.account_id=account.id
+inner join domain on event.domain_id=domain.id
+inner join user on event.user_id = user.id
+left join projects on projects.project_account_id = event.account_id
+left join event eve on event.start_id = eve.id;


Mime
View raw message