Skip to content

Commit 0855298

Browse files
author
Henrique Sato
committed
quota tariff events
1 parent 746bae7 commit 0855298

File tree

5 files changed

+21
-2
lines changed

5 files changed

+21
-2
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,11 @@ public class EventTypes {
727727
public static final String EVENT_BUCKET_DELETE = "BUCKET.DELETE";
728728
public static final String EVENT_BUCKET_UPDATE = "BUCKET.UPDATE";
729729

730+
// Quota
731+
public static final String EVENT_QUOTA_TARIFF_CREATE = "QUOTA.TARIFF.CREATE";
732+
public static final String EVENT_QUOTA_TARIFF_DELETE = "QUOTA.TARIFF.DELETE";
733+
public static final String EVENT_QUOTA_TARIFF_UPDATE = "QUOTA.TARIFF.UPDATE";
734+
730735
static {
731736

732737
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@@ -1175,6 +1180,11 @@ public class EventTypes {
11751180
entityEventDetails.put(EVENT_BUCKET_CREATE, Bucket.class);
11761181
entityEventDetails.put(EVENT_BUCKET_UPDATE, Bucket.class);
11771182
entityEventDetails.put(EVENT_BUCKET_DELETE, Bucket.class);
1183+
1184+
// Quota
1185+
entityEventDetails.put(EVENT_QUOTA_TARIFF_CREATE, "QuotaTariff");
1186+
entityEventDetails.put(EVENT_QUOTA_TARIFF_DELETE, "QuotaTariff");
1187+
entityEventDetails.put(EVENT_QUOTA_TARIFF_UPDATE, "QuotaTariff");
11781188
}
11791189

11801190
public static String getEntityForEvent(String eventName) {

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffCreateCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
2929
import org.apache.cloudstack.api.response.QuotaTariffResponse;
30+
import org.apache.cloudstack.context.CallContext;
3031
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
3132
import org.apache.log4j.Logger;
3233

@@ -70,6 +71,7 @@ public class QuotaTariffCreateCmd extends BaseCmd {
7071

7172
@Override
7273
public void execute() {
74+
CallContext.current().setEventDetails(String.format("Tariff: %s, description: %s, value: %s", getName(), getDescription(), getValue()));
7375
QuotaTariffVO result = responseBuilder.createQuotaTariff(this);
7476

7577
if (result == null) {
@@ -133,5 +135,4 @@ public Date getEndDate() {
133135
public void setEndDate(Date endDate) {
134136
this.endDate = endDate;
135137
}
136-
137138
}

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffDeleteCmd.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
2828
import org.apache.cloudstack.api.response.QuotaTariffResponse;
2929
import org.apache.cloudstack.api.response.SuccessResponse;
30+
import org.apache.cloudstack.context.CallContext;
3031
import org.apache.log4j.Logger;
3132

3233
import javax.inject.Inject;
@@ -49,6 +50,7 @@ public String getId() {
4950

5051
@Override
5152
public void execute() {
53+
CallContext.current().setEventDetails(String.format("Tariff id: %s", getId()));
5254
boolean result = responseBuilder.deleteQuotaTariff(getId());
5355
SuccessResponse response = new SuccessResponse(getCommandName());
5456
response.setSuccess(result);
@@ -59,5 +61,4 @@ public void execute() {
5961
public long getEntityOwnerId() {
6062
return Account.ACCOUNT_ID_SYSTEM;
6163
}
62-
6364
}

plugins/database/quota/src/main/java/org/apache/cloudstack/api/command/QuotaTariffUpdateCmd.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.ServerApiException;
2828
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
2929
import org.apache.cloudstack.api.response.QuotaTariffResponse;
30+
import org.apache.cloudstack.context.CallContext;
3031
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
3132
import org.apache.log4j.Logger;
3233

@@ -111,6 +112,7 @@ public QuotaTariffUpdateCmd() {
111112

112113
@Override
113114
public void execute() {
115+
CallContext.current().setEventDetails(String.format("Tariff: %s, description: %s, value: %s", getName(), getDescription(), getValue()));
114116
final QuotaTariffVO result = _responseBuilder.updateQuotaTariffPlan(this);
115117
if (result == null) {
116118
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update quota tariff plan");

plugins/database/quota/src/main/java/org/apache/cloudstack/api/response/QuotaResponseBuilderImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
import com.cloud.user.dao.UserDao;
7676
import com.cloud.utils.Pair;
7777
import com.cloud.utils.db.Filter;
78+
import com.cloud.event.ActionEvent;
79+
import com.cloud.event.EventTypes;
7880

7981
@Component
8082
public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
@@ -380,6 +382,7 @@ public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffPlans(final QuotaTariff
380382
}
381383

382384
@Override
385+
@ActionEvent(eventType = EventTypes.EVENT_QUOTA_TARIFF_UPDATE, eventDescription = "updating Quota Tariff")
383386
public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) {
384387
String name = cmd.getName();
385388
Double value = cmd.getValue();
@@ -619,6 +622,7 @@ private Date createDateAtTheStartOfNextDay(LocalDate localDate) {
619622
}
620623

621624
@Override
625+
@ActionEvent(eventType = EventTypes.EVENT_QUOTA_TARIFF_CREATE, eventDescription = "creating Quota Tariff")
622626
public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) {
623627
String name = cmd.getName();
624628
int usageType = cmd.getUsageType();
@@ -643,6 +647,7 @@ public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) {
643647
return persistNewQuotaTariff(null, name, usageType, startDate, cmd.getEntityOwnerId(), endDate, value, description, activationRule);
644648
}
645649

650+
@ActionEvent(eventType = EventTypes.EVENT_QUOTA_TARIFF_DELETE, eventDescription = "removing Quota Tariff")
646651
public boolean deleteQuotaTariff(String quotaTariffUuid) {
647652
QuotaTariffVO quotaTariff = _quotaTariffDao.findByUuid(quotaTariffUuid);
648653

0 commit comments

Comments
 (0)