Skip to content

Commit a60c8ca

Browse files
api,server,ui: allow listing events by state (#11355)
* api,server,ui: allow listing events by state This change allows listing events by a particular state - Created, Scheduled, Started, Completed. A new parameter - state has been added to the listEvents API and corresponding changes have been added in the UI. Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> * Update api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java --------- Signed-off-by: Abhishek Kumar <abhishek.mrt22@gmail.com> Co-authored-by: Suresh Kumar Anaparti <sureshkumar.anaparti@gmail.com>
1 parent adccdf2 commit a60c8ca

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

api/src/main/java/org/apache/cloudstack/api/command/user/event/ListEventsCmd.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ public class ListEventsCmd extends BaseListProjectAndAccountResourcesCmd {
7373
@Parameter(name = ApiConstants.ARCHIVED, type = CommandType.BOOLEAN, description = "true to list archived events otherwise false", since="4.19.0")
7474
private Boolean archived;
7575

76+
@Parameter(name = ApiConstants.STATE, type = CommandType.STRING, description = "The state of the events", since="4.21.0")
77+
private String state;
78+
7679
/////////////////////////////////////////////////////
7780
/////////////////// Accessors ///////////////////////
7881
/////////////////////////////////////////////////////
@@ -121,6 +124,10 @@ public boolean getArchived() {
121124
return archived != null && archived;
122125
}
123126

127+
public String getState() {
128+
return state;
129+
}
130+
124131
/////////////////////////////////////////////////////
125132
/////////////// API Implementation///////////////////
126133
/////////////////////////////////////////////////////

server/src/main/java/com/cloud/api/query/QueryManagerImpl.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@
243243
import com.cloud.domain.Domain;
244244
import com.cloud.domain.DomainVO;
245245
import com.cloud.domain.dao.DomainDao;
246+
import com.cloud.event.Event;
246247
import com.cloud.event.EventVO;
247248
import com.cloud.event.dao.EventDao;
248249
import com.cloud.event.dao.EventJoinDao;
@@ -868,6 +869,7 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
868869
Long startId = cmd.getStartId();
869870
final String resourceUuid = cmd.getResourceId();
870871
final String resourceTypeStr = cmd.getResourceType();
872+
final String stateStr = cmd.getState();
871873
ApiCommandResourceType resourceType = null;
872874
Long resourceId = null;
873875
if (resourceTypeStr != null) {
@@ -897,6 +899,13 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
897899
accountMgr.checkAccess(CallContext.current().getCallingAccount(), SecurityChecker.AccessType.ListEntry, entity.getAccountId() == caller.getId(), entity);
898900
}
899901
}
902+
Event.State state = null;
903+
if (StringUtils.isNotBlank(stateStr)) {
904+
state = EnumUtils.getEnum(Event.State.class, stateStr);
905+
if (state == null) {
906+
throw new InvalidParameterValueException(String.format("Invalid %s specified: %s", ApiConstants.STATE, stateStr));
907+
}
908+
}
900909

901910
Ternary<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
902911
accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
@@ -920,7 +929,7 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
920929
eventSearchBuilder.and("createDateB", eventSearchBuilder.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
921930
eventSearchBuilder.and("createDateG", eventSearchBuilder.entity().getCreateDate(), SearchCriteria.Op.GTEQ);
922931
eventSearchBuilder.and("createDateL", eventSearchBuilder.entity().getCreateDate(), SearchCriteria.Op.LTEQ);
923-
eventSearchBuilder.and("state", eventSearchBuilder.entity().getState(), SearchCriteria.Op.NEQ);
932+
eventSearchBuilder.and("state", eventSearchBuilder.entity().getState(), SearchCriteria.Op.EQ);
924933
eventSearchBuilder.or("startId", eventSearchBuilder.entity().getStartId(), SearchCriteria.Op.EQ);
925934
eventSearchBuilder.and("createDate", eventSearchBuilder.entity().getCreateDate(), SearchCriteria.Op.BETWEEN);
926935
eventSearchBuilder.and("displayEvent", eventSearchBuilder.entity().isDisplay(), SearchCriteria.Op.EQ);
@@ -989,6 +998,10 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
989998
sc.setParameters("archived", cmd.getArchived());
990999
}
9911000

1001+
if (state != null) {
1002+
sc.setParameters("state", state);
1003+
}
1004+
9921005
Pair<List<Long>, Integer> eventPair;
9931006
// event_view will not have duplicate rows for each event, so
9941007
// searchAndCount should be good enough.

ui/public/locales/en.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@
573573
"label.communities": "Communities",
574574
"label.community": "Community",
575575
"label.complete": "Complete",
576+
"label.completed": "Completed",
576577
"label.compute": "Compute",
577578
"label.compute.offerings": "Compute Offerings",
578579
"label.compute.offering.for.sharedfs.instance": "Compute Offering for Instance",
@@ -2157,6 +2158,7 @@
21572158
"label.scaleup.policy": "ScaleUp policy",
21582159
"label.scaling": "Scaling",
21592160
"label.schedule": "Schedule",
2161+
"label.scheduled": "Scheduled",
21602162
"label.schedule.add": "Add schedule",
21612163
"label.scheduled.backups": "Scheduled backups",
21622164
"label.schedules": "Schedules",
@@ -2328,6 +2330,7 @@
23282330
"label.standard.us.keyboard": "Standard (US) keyboard",
23292331
"label.start": "Start",
23302332
"label.startasn": "Start AS Number",
2333+
"label.started": "Started",
23312334
"label.start.date": "Start date",
23322335
"label.start.date.and.time": "Start date and time",
23332336
"label.start.ip": "Start IP",

ui/src/components/view/SearchView.vue

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1380,6 +1380,25 @@ export default {
13801380
name: 'label.disabled'
13811381
}
13821382
]
1383+
} else if (this.apiName.indexOf('listEvents') > -1) {
1384+
state = [
1385+
{
1386+
id: 'Created',
1387+
name: 'label.created'
1388+
},
1389+
{
1390+
id: 'Scheduled',
1391+
name: 'label.scheduled'
1392+
},
1393+
{
1394+
id: 'Started',
1395+
name: 'label.started'
1396+
},
1397+
{
1398+
id: 'Completed',
1399+
name: 'label.completed'
1400+
}
1401+
]
13831402
}
13841403
return state
13851404
},

ui/src/config/section/event.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default {
3232
return fields
3333
},
3434
details: ['username', 'id', 'description', 'resourcetype', 'resourceid', 'state', 'level', 'type', 'account', 'domain', 'created'],
35-
searchFilters: ['level', 'domainid', 'account', 'keyword', 'resourcetype'],
35+
searchFilters: ['level', 'domainid', 'account', 'keyword', 'resourcetype', 'state'],
3636
related: [{
3737
name: 'event',
3838
title: 'label.event.timeline',

0 commit comments

Comments
 (0)