Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 ///////////////////////
/////////////////////////////////////////////////////
Expand Down Expand Up @@ -121,6 +124,10 @@ public boolean getArchived() {
return archived != null && archived;
}

public String getState() {
return state;
}

/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
Expand Down
15 changes: 14 additions & 1 deletion server/src/main/java/com/cloud/api/query/QueryManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
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;
Expand Down Expand Up @@ -868,6 +869,7 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
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) {
Expand Down Expand Up @@ -897,6 +899,13 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
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<Long, Boolean, ListProjectResourcesCriteria> domainIdRecursiveListProject = new Ternary<>(cmd.getDomainId(), cmd.isRecursive(), null);
accountMgr.buildACLSearchParameters(caller, id, cmd.getAccountName(), cmd.getProjectId(), permittedAccounts, domainIdRecursiveListProject, cmd.listAll(), false);
Expand All @@ -920,7 +929,7 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, are we sure we never depend on a search for states except for…? It seems strange just reversing the condition.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"state" was not being used in the search criteria before this. So I think it is fine to do so.

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);
Expand Down Expand Up @@ -989,6 +998,10 @@ private Pair<List<Long>, Integer> searchForEventIdsAndCount(ListEventsCmd cmd) {
sc.setParameters("archived", cmd.getArchived());
}

if (state != null) {
sc.setParameters("state", state);
}

Pair<List<Long>, Integer> eventPair;
// event_view will not have duplicate rows for each event, so
// searchAndCount should be good enough.
Expand Down
3 changes: 3 additions & 0 deletions ui/public/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,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",
Expand Down Expand Up @@ -2150,6 +2151,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",
Expand Down Expand Up @@ -2318,6 +2320,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",
Expand Down
19 changes: 19 additions & 0 deletions ui/src/components/view/SearchView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,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
},
Expand Down
2 changes: 1 addition & 1 deletion ui/src/config/section/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Loading