From 62b332e0ded9ed8f4d3be3b36e56b6d24f5aa274 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Tue, 11 Apr 2023 22:26:41 +0530 Subject: [PATCH] api, ui: listing archived events (#7396) Fixes #7217 Signed-off-by: Abhishek Kumar --- .../apache/cloudstack/api/ApiConstants.java | 1 + .../api/command/user/event/ListEventsCmd.java | 7 ++++ .../api/response/EventResponse.java | 8 +++++ .../com/cloud/api/query/QueryManagerImpl.java | 4 ++- .../com/cloud/event/dao/EventJoinDaoImpl.java | 3 ++ ui/public/locales/en.json | 2 ++ ui/src/components/view/InfoCard.vue | 3 ++ ui/src/config/section/event.js | 9 ++++++ ui/src/views/AutogenView.vue | 32 +++++++++++++++---- 9 files changed, 62 insertions(+), 7 deletions(-) diff --git a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java index 5b7b4f674ca..6e93d45abdb 100644 --- a/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java +++ b/api/src/main/java/org/apache/cloudstack/api/ApiConstants.java @@ -32,6 +32,7 @@ public class ApiConstants { public static final String ALLOCATED_ONLY = "allocatedonly"; public static final String ANNOTATION = "annotation"; public static final String API_KEY = "apikey"; + public static final String ARCHIVED = "archived"; public static final String ASYNC_BACKUP = "asyncbackup"; public static final String AUTO_SELECT = "autoselect"; public static final String USER_API_KEY = "userapikey"; diff --git a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java index 202bd36bdb5..89f1c7090e0 100644 --- a/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java +++ b/api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java @@ -72,6 +72,9 @@ public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd { @Parameter(name = ApiConstants.RESOURCE_TYPE, type = CommandType.STRING, description = "the type of the resource associated with the event", since="4.17.0") private String resourceType; + @Parameter(name = ApiConstants.ARCHIVED, type = CommandType.BOOLEAN, description = "true to list archived events otherwise false", since="4.19.0") + private Boolean archived; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -116,6 +119,10 @@ public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd { return resourceType; } + public boolean getArchived() { + return archived != null && archived; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// diff --git a/api/src/main/java/org/apache/cloudstack/api/response/EventResponse.java b/api/src/main/java/org/apache/cloudstack/api/response/EventResponse.java index a3ca777be5a..8f65492cb70 100644 --- a/api/src/main/java/org/apache/cloudstack/api/response/EventResponse.java +++ b/api/src/main/java/org/apache/cloudstack/api/response/EventResponse.java @@ -93,6 +93,10 @@ public class EventResponse extends BaseResponse implements ControlledViewEntityR @Param(description = "whether the event is parented") private String parentId; + @SerializedName(ApiConstants.ARCHIVED) + @Param(description = "whether the event has been archived or not") + private Boolean archived; + public void setId(String id) { this.id = id; } @@ -173,4 +177,8 @@ public class EventResponse extends BaseResponse implements ControlledViewEntityR public void setProjectName(String projectName) { this.projectName = projectName; } + + public void setArchived(Boolean archived) { + this.archived = archived; + } } diff --git a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java index 6fecd2c3c6d..c33aac83b40 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -790,7 +790,9 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q sc.setParameters("resourceType", resourceType.toString()); } - sc.setParameters("archived", false); + if (id == null) { + sc.setParameters("archived", cmd.getArchived()); + } Pair, Integer> eventPair = null; // event_view will not have duplicate rows for each event, so diff --git a/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java b/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java index c73f57529b8..24c699a35ad 100644 --- a/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java +++ b/server/src/main/java/com/cloud/event/dao/EventJoinDaoImpl.java @@ -110,6 +110,9 @@ public class EventJoinDaoImpl extends GenericDaoBase implemen responseEvent.setParentId(event.getStartUuid()); responseEvent.setState(event.getState()); responseEvent.setUsername(event.getUserName()); + if (event.getArchived()) { + responseEvent.setArchived(true); + } Long resourceId = event.getResourceId(); responseEvent.setResourceType(event.getResourceType()); ApiCommandResourceType resourceType = ApiCommandResourceType.fromString(event.getResourceType()); diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index ac109e70c1f..cdc013f82dc 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -187,6 +187,7 @@ "label.action.vmsnapshot.revert": "Revert to VM snapshot", "label.action.vmstoragesnapshot.create": "Take VM volume snapshot", "label.actions": "Actions", +"label.active": "Active", "label.activate.project": "Activate project", "label.activeviewersessions": "Active sessions", "label.add": "Add", @@ -329,6 +330,7 @@ "label.apply.tungsten.network.policy": "Apply Network Policy", "label.apply.tungsten.tag": "Apply tag", "label.archive": "Archive", +"label.archived": "Archived", "label.archive.alerts": "Archive alerts", "label.archive.events": "Archive events", "label.as.default": "as default", diff --git a/ui/src/components/view/InfoCard.vue b/ui/src/components/view/InfoCard.vue index 9f449f3a0dd..f28f19c7d0e 100644 --- a/ui/src/components/view/InfoCard.vue +++ b/ui/src/components/view/InfoCard.vue @@ -84,6 +84,9 @@ {{ resource.internetprotocol ? $t('label.ip.v4.v6') : resource.internetprotocol }} + + {{ $t('label.archived') }} +