|
| 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 | +} |
0 commit comments