Skip to content

Commit f539f40

Browse files
sanjaytripathiminchen07
authored andcommitted
CLOUDSTACK-874: Ability to delete Events and Alerts
This feature will provide the functionality to delete or archive the Alerts/Events. Delete or archive alerts APIs are available only for root-admin, delete or archive events are available for regular users.
1 parent bd45085 commit f539f40

23 files changed

Lines changed: 1019 additions & 120 deletions

File tree

api/src/com/cloud/alert/Alert.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ public interface Alert extends Identity, InternalIdentity {
3030
Date getCreatedDate();
3131
Date getLastSent();
3232
Date getResolved();
33+
boolean getArchived();
3334
}

api/src/com/cloud/event/Event.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,5 @@ public enum State {
4040
String getLevel();
4141
long getStartId();
4242
String getParameters();
43+
boolean getArchived();
4344
}

api/src/com/cloud/server/ManagementService.java

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.apache.cloudstack.api.command.admin.host.ListHostsCmd;
3030
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
3131
import org.apache.cloudstack.api.command.admin.pod.ListPodsByCmd;
32+
import org.apache.cloudstack.api.command.admin.resource.ArchiveAlertsCmd;
33+
import org.apache.cloudstack.api.command.admin.resource.DeleteAlertsCmd;
3234
import org.apache.cloudstack.api.command.admin.resource.ListAlertsCmd;
3335
import org.apache.cloudstack.api.command.admin.resource.ListCapacityCmd;
3436
import org.apache.cloudstack.api.command.admin.resource.UploadCustomCertificateCmd;
@@ -40,12 +42,12 @@
4042
import org.apache.cloudstack.api.command.admin.vlan.ListVlanIpRangesCmd;
4143
import org.apache.cloudstack.api.command.user.address.ListPublicIpAddressesCmd;
4244
import org.apache.cloudstack.api.command.user.config.ListCapabilitiesCmd;
45+
import org.apache.cloudstack.api.command.user.event.ArchiveEventsCmd;
46+
import org.apache.cloudstack.api.command.user.event.DeleteEventsCmd;
4347
import org.apache.cloudstack.api.command.user.guest.ListGuestOsCategoriesCmd;
4448
import org.apache.cloudstack.api.command.user.guest.ListGuestOsCmd;
4549
import org.apache.cloudstack.api.command.user.iso.ListIsosCmd;
4650
import org.apache.cloudstack.api.command.user.iso.UpdateIsoCmd;
47-
import org.apache.cloudstack.api.command.user.offering.ListDiskOfferingsCmd;
48-
import org.apache.cloudstack.api.command.user.offering.ListServiceOfferingsCmd;
4951
import org.apache.cloudstack.api.command.user.ssh.CreateSSHKeyPairCmd;
5052
import org.apache.cloudstack.api.command.user.ssh.DeleteSSHKeyPairCmd;
5153
import org.apache.cloudstack.api.command.user.ssh.ListSSHKeyPairsCmd;
@@ -55,12 +57,10 @@
5557
import org.apache.cloudstack.api.command.user.vm.GetVMPasswordCmd;
5658
import org.apache.cloudstack.api.command.user.vmgroup.UpdateVMGroupCmd;
5759
import org.apache.cloudstack.api.command.user.volume.ExtractVolumeCmd;
58-
import org.apache.cloudstack.api.command.user.zone.ListZonesByCmd;
5960

6061
import com.cloud.alert.Alert;
6162
import com.cloud.capacity.Capacity;
6263
import com.cloud.configuration.Configuration;
63-
import com.cloud.dc.DataCenter;
6464
import com.cloud.dc.Pod;
6565
import com.cloud.dc.Vlan;
6666
import com.cloud.domain.Domain;
@@ -72,8 +72,6 @@
7272
import com.cloud.hypervisor.Hypervisor.HypervisorType;
7373
import com.cloud.hypervisor.HypervisorCapabilities;
7474
import com.cloud.network.IpAddress;
75-
import com.cloud.offering.DiskOffering;
76-
import com.cloud.offering.ServiceOffering;
7775
import com.cloud.org.Cluster;
7876
import com.cloud.storage.GuestOS;
7977
import com.cloud.storage.GuestOsCategory;
@@ -194,6 +192,34 @@ public interface ManagementService {
194192
*/
195193
Pair<List<? extends Alert>, Integer> searchForAlerts(ListAlertsCmd cmd);
196194

195+
/**
196+
* Archive alerts
197+
* @param cmd
198+
* @return True on success. False otherwise.
199+
*/
200+
boolean archiveAlerts(ArchiveAlertsCmd cmd);
201+
202+
/**
203+
* Delete alerts
204+
* @param cmd
205+
* @return True on success. False otherwise.
206+
*/
207+
boolean deleteAlerts(DeleteAlertsCmd cmd);
208+
209+
/**
210+
* Archive events
211+
* @param cmd
212+
* @return True on success. False otherwise.
213+
*/
214+
boolean archiveEvents(ArchiveEventsCmd cmd);
215+
216+
/**
217+
* Delete events
218+
* @param cmd
219+
* @return True on success. False otherwise.
220+
*/
221+
boolean deleteEvents(DeleteEventsCmd cmd);
222+
197223
/**
198224
* list all the capacity rows in capacity operations table
199225
*

api/src/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ public class ApiConstants {
459459
public static final String UCS_BLADE_DN = "bladedn";
460460
public static final String UCS_BLADE_ID = "bladeid";
461461
public static final String VM_GUEST_IP = "vmguestip";
462+
public static final String OLDER_THAN = "olderthan";
462463

463464
public enum HostDetails {
464465
all, capacity, events, stats, min;
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.admin.resource;
18+
19+
import java.util.Date;
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.AlertResponse;
29+
import org.apache.cloudstack.api.response.ConditionResponse;
30+
import org.apache.cloudstack.api.response.SuccessResponse;
31+
import org.apache.log4j.Logger;
32+
33+
import com.cloud.exception.InvalidParameterValueException;
34+
import com.cloud.user.Account;
35+
36+
@APICommand(name = "archiveAlerts", description = "Archive one or more alerts.", responseObject = SuccessResponse.class)
37+
public class ArchiveAlertsCmd extends BaseCmd {
38+
39+
public static final Logger s_logger = Logger.getLogger(ArchiveAlertsCmd.class.getName());
40+
41+
private static final String s_name = "archivealertsresponse";
42+
43+
// ///////////////////////////////////////////////////
44+
// ////////////// API parameters /////////////////////
45+
// ///////////////////////////////////////////////////
46+
47+
@Parameter(name = ApiConstants.IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AlertResponse.class,
48+
description = "the IDs of the alerts")
49+
private List<Long> ids;
50+
51+
@Parameter(name=ApiConstants.OLDER_THAN, type=CommandType.DATE, description="archive alerts older than this date (use format \"yyyy-MM-dd\")")
52+
private Date olderThan;
53+
54+
@Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "archive by alert type")
55+
private String type;
56+
57+
// ///////////////////////////////////////////////////
58+
// ///////////////// Accessors ///////////////////////
59+
// ///////////////////////////////////////////////////
60+
61+
public List<Long> getIds() {
62+
return ids;
63+
}
64+
65+
public Date getOlderThan() {
66+
return olderThan;
67+
}
68+
69+
public String getType() {
70+
return type;
71+
}
72+
73+
// ///////////////////////////////////////////////////
74+
// ///////////// API Implementation///////////////////
75+
// ///////////////////////////////////////////////////
76+
77+
@Override
78+
public String getCommandName() {
79+
return s_name;
80+
}
81+
82+
@Override
83+
public long getEntityOwnerId() {
84+
return Account.ACCOUNT_ID_SYSTEM;
85+
}
86+
87+
@Override
88+
public void execute() {
89+
if(ids == null && type == null && olderThan == null) {
90+
throw new InvalidParameterValueException("either ids, type or olderthan must be specified");
91+
}
92+
boolean result = _mgr.archiveAlerts(this);
93+
if (result) {
94+
SuccessResponse response = new SuccessResponse(getCommandName());
95+
this.setResponseObject(response);
96+
} else {
97+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to archive Alerts, one or more parameters has invalid values");
98+
}
99+
}
100+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.admin.resource;
18+
19+
import java.util.Date;
20+
import java.util.List;
21+
22+
import org.apache.cloudstack.api.APICommand;
23+
import org.apache.cloudstack.api.ApiConstants;
24+
import org.apache.cloudstack.api.ApiErrorCode;
25+
import org.apache.cloudstack.api.BaseCmd;
26+
import org.apache.cloudstack.api.Parameter;
27+
import org.apache.cloudstack.api.ServerApiException;
28+
import org.apache.cloudstack.api.response.AlertResponse;
29+
import org.apache.cloudstack.api.response.SuccessResponse;
30+
import org.apache.log4j.Logger;
31+
32+
import com.cloud.exception.InvalidParameterValueException;
33+
import com.cloud.user.Account;
34+
35+
@APICommand(name = "deleteAlerts", description = "Delete one or more alerts.", responseObject = SuccessResponse.class)
36+
public class DeleteAlertsCmd extends BaseCmd {
37+
38+
public static final Logger s_logger = Logger.getLogger(DeleteAlertsCmd.class.getName());
39+
40+
private static final String s_name = "deletealertsresponse";
41+
42+
// ///////////////////////////////////////////////////
43+
// ////////////// API parameters /////////////////////
44+
// ///////////////////////////////////////////////////
45+
46+
@Parameter(name = ApiConstants.IDS, type = CommandType.LIST, collectionType = CommandType.UUID, entityType = AlertResponse.class,
47+
description = "the IDs of the alerts")
48+
private List<Long> ids;
49+
50+
@Parameter(name=ApiConstants.OLDER_THAN, type=CommandType.DATE, description="delete alerts older than (including) this date (use format \"yyyy-MM-dd\")")
51+
private Date olderThan;
52+
53+
@Parameter(name = ApiConstants.TYPE, type = CommandType.STRING, description = "delete by alert type")
54+
private String type;
55+
56+
// ///////////////////////////////////////////////////
57+
// ///////////////// Accessors ///////////////////////
58+
// ///////////////////////////////////////////////////
59+
60+
public List<Long> getIds() {
61+
return ids;
62+
}
63+
64+
public Date getOlderThan() {
65+
return olderThan;
66+
}
67+
68+
public String getType() {
69+
return type;
70+
}
71+
72+
// ///////////////////////////////////////////////////
73+
// ///////////// API Implementation///////////////////
74+
// ///////////////////////////////////////////////////
75+
76+
@Override
77+
public String getCommandName() {
78+
return s_name;
79+
}
80+
81+
@Override
82+
public long getEntityOwnerId() {
83+
return Account.ACCOUNT_ID_SYSTEM;
84+
}
85+
86+
@Override
87+
public void execute() {
88+
if(ids == null && type == null && olderThan == null) {
89+
throw new InvalidParameterValueException("either ids, type or olderthan must be specified");
90+
}
91+
boolean result = _mgr.deleteAlerts(this);
92+
if (result) {
93+
SuccessResponse response = new SuccessResponse(getCommandName());
94+
this.setResponseObject(response);
95+
} else {
96+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Unable to delete Alerts, one or more parameters has invalid values");
97+
}
98+
}
99+
}

0 commit comments

Comments
 (0)