erikbocks commented on code in PR #11443:
URL: https://github.com/apache/cloudstack/pull/11443#discussion_r3498500617


##########
server/src/main/java/com/cloud/server/ManagementServerImpl.java:
##########
@@ -1225,57 +1224,64 @@ protected void checkPortParameters(final String 
publicPort, final String private
     }
 
     @Override
-    public boolean archiveEvents(final ArchiveEventsCmd cmd) {
-        final Account caller = getCaller();
-        final List<Long> ids = cmd.getIds();
-        boolean result = true;
-        List<Long> permittedAccountIds = new ArrayList<>();
+    public boolean archiveEvents(ArchiveEventsCmd cmd) {
+        List<Long> ids = cmd.getIds();
+        String type = cmd.getType();
+        Date startDate = cmd.getStartDate();
+        Date endDate = cmd.getEndDate();
+
+        validateEventOperationParameters(ids, type, endDate, startDate);
+
+        Long accountId = null;
+        List<Long> domainIds = null;
+        Account caller = getCaller();
+        Account.Type callerType = caller.getType();
 
-        if (_accountService.isNormalUser(caller.getId()) || caller.getType() 
== Account.Type.PROJECT) {
-            permittedAccountIds.add(caller.getId());
+        if (callerType == Account.Type.NORMAL || callerType == 
Account.Type.PROJECT) {
+            accountId = caller.getId();
         } else {
-            final DomainVO domain = _domainDao.findById(caller.getDomainId());
-            final List<Long> permittedDomainIds = 
_domainDao.getDomainChildrenIds(domain.getPath());
-            permittedAccountIds = 
_accountDao.getAccountIdsForDomains(permittedDomainIds);
+            domainIds = 
_domainDao.getDomainAndChildrenIds(caller.getDomainId());
         }
 
-        final List<EventVO> events = 
_eventDao.listToArchiveOrDeleteEvents(ids, cmd.getType(), cmd.getStartDate(), 
cmd.getEndDate(), permittedAccountIds);
-        final ControlledEntity[] sameOwnerEvents = events.toArray(new 
ControlledEntity[events.size()]);
-        _accountMgr.checkAccess(CallContext.current().getCallingAccount(), 
null, false, sameOwnerEvents);
+        long totalArchived = _eventDao.archiveEvents(ids, type, startDate, 
endDate, accountId, domainIds,
+                ConfigurationManagerImpl.DELETE_QUERY_BATCH_SIZE.value());

Review Comment:
   ```suggestion
           ConfigurationManagerImpl.DELETE_QUERY_BATCH_SIZE.value());
   ```



##########
server/src/main/java/com/cloud/server/ManagementServerImpl.java:
##########
@@ -1225,57 +1224,64 @@ protected void checkPortParameters(final String 
publicPort, final String private
     }
 
     @Override
-    public boolean archiveEvents(final ArchiveEventsCmd cmd) {
-        final Account caller = getCaller();
-        final List<Long> ids = cmd.getIds();
-        boolean result = true;
-        List<Long> permittedAccountIds = new ArrayList<>();
+    public boolean archiveEvents(ArchiveEventsCmd cmd) {
+        List<Long> ids = cmd.getIds();
+        String type = cmd.getType();
+        Date startDate = cmd.getStartDate();
+        Date endDate = cmd.getEndDate();
+
+        validateEventOperationParameters(ids, type, endDate, startDate);
+
+        Long accountId = null;
+        List<Long> domainIds = null;
+        Account caller = getCaller();
+        Account.Type callerType = caller.getType();
 
-        if (_accountService.isNormalUser(caller.getId()) || caller.getType() 
== Account.Type.PROJECT) {
-            permittedAccountIds.add(caller.getId());
+        if (callerType == Account.Type.NORMAL || callerType == 
Account.Type.PROJECT) {
+            accountId = caller.getId();
         } else {
-            final DomainVO domain = _domainDao.findById(caller.getDomainId());
-            final List<Long> permittedDomainIds = 
_domainDao.getDomainChildrenIds(domain.getPath());
-            permittedAccountIds = 
_accountDao.getAccountIdsForDomains(permittedDomainIds);
+            domainIds = 
_domainDao.getDomainAndChildrenIds(caller.getDomainId());
         }
 
-        final List<EventVO> events = 
_eventDao.listToArchiveOrDeleteEvents(ids, cmd.getType(), cmd.getStartDate(), 
cmd.getEndDate(), permittedAccountIds);
-        final ControlledEntity[] sameOwnerEvents = events.toArray(new 
ControlledEntity[events.size()]);
-        _accountMgr.checkAccess(CallContext.current().getCallingAccount(), 
null, false, sameOwnerEvents);
+        long totalArchived = _eventDao.archiveEvents(ids, type, startDate, 
endDate, accountId, domainIds,
+                ConfigurationManagerImpl.DELETE_QUERY_BATCH_SIZE.value());
 
-        if (ids != null && events.size() < ids.size()) {
-            return false;
-        }
-        _eventDao.archiveEvents(events);
-        return result;
+        return totalArchived > 0;
     }
 
     @Override
-    public boolean deleteEvents(final DeleteEventsCmd cmd) {
-        final Account caller = getCaller();
-        final List<Long> ids = cmd.getIds();
-        boolean result = true;
-        List<Long> permittedAccountIds = new ArrayList<>();
+    public boolean deleteEvents(DeleteEventsCmd cmd) {
+        List<Long> ids = cmd.getIds();
+        String type = cmd.getType();
+        Date startDate = cmd.getStartDate();
+        Date endDate = cmd.getEndDate();
 
-        if (_accountMgr.isNormalUser(caller.getId()) || caller.getType() == 
Account.Type.PROJECT) {
-            permittedAccountIds.add(caller.getId());
+        validateEventOperationParameters(ids, type, endDate, startDate);
+
+        Long accountId = null;
+        List<Long> domainIds = null;
+        Account caller = getCaller();
+        Account.Type callerType = caller.getType();
+
+        if (callerType == Account.Type.NORMAL || callerType == 
Account.Type.PROJECT) {
+            accountId = caller.getId();
         } else {
-            final DomainVO domain = _domainDao.findById(caller.getDomainId());
-            final List<Long> permittedDomainIds = 
_domainDao.getDomainChildrenIds(domain.getPath());
-            permittedAccountIds = 
_accountDao.getAccountIdsForDomains(permittedDomainIds);
+            domainIds = 
_domainDao.getDomainAndChildrenIds(caller.getDomainId());
         }
 
-        final List<EventVO> events = 
_eventDao.listToArchiveOrDeleteEvents(ids, cmd.getType(), cmd.getStartDate(), 
cmd.getEndDate(), permittedAccountIds);
-        final ControlledEntity[] sameOwnerEvents = events.toArray(new 
ControlledEntity[events.size()]);
-        _accountMgr.checkAccess(CallContext.current().getCallingAccount(), 
null, false, sameOwnerEvents);
+        long totalRemoved = _eventDao.purgeAll(ids, startDate, endDate, null, 
type, accountId, domainIds,
+                ConfigurationManagerImpl.DELETE_QUERY_BATCH_SIZE.value());

Review Comment:
   ```suggestion
           ConfigurationManagerImpl.DELETE_QUERY_BATCH_SIZE.value());
   ```



##########
engine/schema/src/main/java/com/cloud/upgrade/dao/Upgrade42210to42300.java:
##########
@@ -89,4 +90,10 @@ protected void 
updateJsInterpretationEnabledFields(Connection conn, String encry
             logger.warn("Error while decrypting configuration 
'js.interpretation.enabled'. The configuration may already be decrypted.");
         }
     }
+
+    private void addIndexes(Connection conn) {
+        DbUpgradeUtils.addIndexWithNameIfNeeded(conn, "event", 
"i_event__multiple_columns_for_generic_search",
+                "account_id", "domain_id", "archived",  "display", 
"resource_type", "resource_id", "start_id", "type", "level",
+                "created", "id");

Review Comment:
   @winterhazel 
   can you take a look at this comment?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to