Skip to content

Commit d9766c8

Browse files
committed
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 <[email protected]>
1 parent 76cfcb4 commit d9766c8

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.22.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
@@ -572,6 +572,7 @@
572572
"label.communities": "Communities",
573573
"label.community": "Community",
574574
"label.complete": "Complete",
575+
"label.completed": "Completed",
575576
"label.compute": "Compute",
576577
"label.compute.offerings": "Compute Offerings",
577578
"label.compute.offering.for.sharedfs.instance": "Compute Offering for Instance",
@@ -2150,6 +2151,7 @@
21502151
"label.scaleup.policy": "ScaleUp policy",
21512152
"label.scaling": "Scaling",
21522153
"label.schedule": "Schedule",
2154+
"label.scheduled": "Scheduled",
21532155
"label.schedule.add": "Add schedule",
21542156
"label.scheduled.backups": "Scheduled backups",
21552157
"label.schedules": "Schedules",
@@ -2318,6 +2320,7 @@
23182320
"label.standard.us.keyboard": "Standard (US) keyboard",
23192321
"label.start": "Start",
23202322
"label.startasn": "Start AS Number",
2323+
"label.started": "Started",
23212324
"label.start.date": "Start date",
23222325
"label.start.date.and.time": "Start date and time",
23232326
"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
@@ -1360,6 +1360,25 @@ export default {
13601360
name: 'label.disabled'
13611361
}
13621362
]
1363+
} else if (this.apiName.indexOf('listEvents') > -1) {
1364+
state = [
1365+
{
1366+
id: 'Created',
1367+
name: 'label.created'
1368+
},
1369+
{
1370+
id: 'Scheduled',
1371+
name: 'label.scheduled'
1372+
},
1373+
{
1374+
id: 'Started',
1375+
name: 'label.started'
1376+
},
1377+
{
1378+
id: 'Completed',
1379+
name: 'label.completed'
1380+
}
1381+
]
13631382
}
13641383
return state
13651384
},

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)