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 b5273c64922..cb935c13e97 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 @@ -73,6 +73,9 @@ public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd { @Parameter(name = ApiConstants.ARCHIVED, type = CommandType.BOOLEAN, description = "true to list archived events otherwise false", since="4.19.0") private Boolean archived; + @Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "The state of the events", since="4.21.0") + private String state; + ///////////////////////////////////////////////////// /////////////////// Accessors /////////////////////// ///////////////////////////////////////////////////// @@ -121,6 +124,10 @@ public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd { return archived != null && archived; } + public String getState() { + return state; + } + ///////////////////////////////////////////////////// /////////////// API Implementation/////////////////// ///////////////////////////////////////////////////// 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 59e37c9f4df..1b60bdcc9e1 100644 --- a/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java +++ b/server/src/main/java/com/cloud/api/query/QueryManagerImpl.java @@ -243,6 +243,7 @@ import com.cloud.dc.dao.HostPodDao; import com.cloud.domain.Domain; import com.cloud.domain.DomainVO; import com.cloud.domain.dao.DomainDao; +import com.cloud.event.Event; import com.cloud.event.EventVO; import com.cloud.event.dao.EventDao; import com.cloud.event.dao.EventJoinDao; @@ -868,6 +869,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q Long startId = cmd.getStartId(); final String resourceUuid = cmd.getResourceId(); final String resourceTypeStr = cmd.getResourceType(); + final String stateStr = cmd.getState(); ApiCommandResourceType resourceType = null; Long resourceId = null; if (resourceTypeStr != null) { @@ -897,6 +899,13 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q accountMgr.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.ListEntry, entity.getAccountId() == caller.getId(), entity); } } + Event.State state = null; + if (StringUtils.isNotBlank(stateStr)) { + state = EnumUtils.getEnum(Event.State.class, stateStr); + if (state == null) { + throw new InvalidParameterValueException(String.format("Invalid %s specified: %s", ApiConstants.STATE, stateStr)); + } + } Ternary domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null); accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false); @@ -920,7 +929,7 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q eventSearchBuilder.and("createDateB", eventSearchBuilder.entity().getCreateDate(), SearchCriteria.Op.BETWEEN); eventSearchBuilder.and("createDateG", eventSearchBuilder.entity().getCreateDate(), SearchCriteria.Op.GTEQ); eventSearchBuilder.and("createDateL", eventSearchBuilder.entity().getCreateDate(), SearchCriteria.Op.LTEQ); - eventSearchBuilder.and("state", eventSearchBuilder.entity().getState(), SearchCriteria.Op.NEQ); + eventSearchBuilder.and("state", eventSearchBuilder.entity().getState(), SearchCriteria.Op.EQ); eventSearchBuilder.or("startId", eventSearchBuilder.entity().getStartId(), SearchCriteria.Op.EQ); eventSearchBuilder.and("createDate", eventSearchBuilder.entity().getCreateDate(), SearchCriteria.Op.BETWEEN); eventSearchBuilder.and("displayEvent", eventSearchBuilder.entity().isDisplay(), SearchCriteria.Op.EQ); @@ -989,6 +998,10 @@ public class QueryManagerImpl extends MutualExclusiveIdsManagerBase implements Q sc.setParameters("archived", cmd.getArchived()); } + if (state != null) { + sc.setParameters("state", state); + } + Pair, Integer> eventPair; // event_view will not have duplicate rows for each event, so // searchAndCount should be good enough. diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json index 753eec2e6f6..4eace1c810e 100644 --- a/ui/public/locales/en.json +++ b/ui/public/locales/en.json @@ -573,6 +573,7 @@ "label.communities": "Communities", "label.community": "Community", "label.complete": "Complete", +"label.completed": "Completed", "label.compute": "Compute", "label.compute.offerings": "Compute Offerings", "label.compute.offering.for.sharedfs.instance": "Compute Offering for Instance", @@ -2157,6 +2158,7 @@ "label.scaleup.policy": "ScaleUp policy", "label.scaling": "Scaling", "label.schedule": "Schedule", +"label.scheduled": "Scheduled", "label.schedule.add": "Add schedule", "label.scheduled.backups": "Scheduled backups", "label.schedules": "Schedules", @@ -2328,6 +2330,7 @@ "label.standard.us.keyboard": "Standard (US) keyboard", "label.start": "Start", "label.startasn": "Start AS Number", +"label.started": "Started", "label.start.date": "Start date", "label.start.date.and.time": "Start date and time", "label.start.ip": "Start IP", diff --git a/ui/src/components/view/SearchView.vue b/ui/src/components/view/SearchView.vue index 9288b248969..409a5020ad0 100644 --- a/ui/src/components/view/SearchView.vue +++ b/ui/src/components/view/SearchView.vue @@ -1380,6 +1380,25 @@ export default { name: 'label.disabled' } ] + } else if (this.apiName.indexOf('listEvents') > -1) { + state = [ + { + id: 'Created', + name: 'label.created' + }, + { + id: 'Scheduled', + name: 'label.scheduled' + }, + { + id: 'Started', + name: 'label.started' + }, + { + id: 'Completed', + name: 'label.completed' + } + ] } return state }, diff --git a/ui/src/config/section/event.js b/ui/src/config/section/event.js index 5ab87e86964..b07f3ba37c4 100644 --- a/ui/src/config/section/event.js +++ b/ui/src/config/section/event.js @@ -32,7 +32,7 @@ export default { return fields }, details: ['username', 'id', 'description', 'resourcetype', 'resourceid', 'state', 'level', 'type', 'account', 'domain', 'created'], - searchFilters: ['level', 'domainid', 'account', 'keyword', 'resourcetype'], + searchFilters: ['level', 'domainid', 'account', 'keyword', 'resourcetype', 'state'], related: [{ name: 'event', title: 'label.event.timeline',