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
11 changes: 11 additions & 0 deletions api/src/main/java/com/cloud/event/EventTypes.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.cloudstack.config.Configuration;
import org.apache.cloudstack.ha.HAConfig;
import org.apache.cloudstack.quota.QuotaTariff;
import org.apache.cloudstack.usage.Usage;

import com.cloud.dc.DataCenter;
Expand Down Expand Up @@ -693,6 +694,11 @@ public class EventTypes {
// SystemVM
public static final String EVENT_LIVE_PATCH_SYSTEMVM = "LIVE.PATCH.SYSTEM.VM";

// Quota
public static final String EVENT_QUOTA_TARIFF_CREATE = "QUOTA.TARIFF.CREATE";
public static final String EVENT_QUOTA_TARIFF_DELETE = "QUOTA.TARIFF.DELETE";
public static final String EVENT_QUOTA_TARIFF_UPDATE = "QUOTA.TARIFF.UPDATE";

static {

// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
Expand Down Expand Up @@ -1118,6 +1124,11 @@ public class EventTypes {

entityEventDetails.put(EVENT_IMAGE_STORE_DATA_MIGRATE, ImageStore.class);
entityEventDetails.put(EVENT_LIVE_PATCH_SYSTEMVM, "SystemVMs");

// Quota
entityEventDetails.put(EVENT_QUOTA_TARIFF_CREATE, QuotaTariff.class);
entityEventDetails.put(EVENT_QUOTA_TARIFF_DELETE, QuotaTariff.class);
entityEventDetails.put(EVENT_QUOTA_TARIFF_UPDATE, QuotaTariff.class);
}

public static String getEntityForEvent(String eventName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ public enum ApiCommandResourceType {
Pod(com.cloud.dc.Pod.class),
VmSnapshot(com.cloud.vm.snapshot.VMSnapshot.class),
Role(org.apache.cloudstack.acl.Role.class),
VpnCustomerGateway(com.cloud.network.Site2SiteCustomerGateway.class);
VpnCustomerGateway(com.cloud.network.Site2SiteCustomerGateway.class),
QuotaTariff(org.apache.cloudstack.quota.QuotaTariff.class);

private final Class<?> clazz;

Expand Down
25 changes: 25 additions & 0 deletions api/src/main/java/org/apache/cloudstack/quota/QuotaTariff.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.cloudstack.quota;
Comment thread
hsato03 marked this conversation as resolved.

import org.apache.cloudstack.api.Identity;
import org.apache.cloudstack.api.InternalIdentity;

public interface QuotaTariff extends InternalIdentity, Identity {

}
Original file line number Diff line number Diff line change
Expand Up @@ -1461,9 +1461,9 @@ public T persist(final T entity) {
} else {
_idField.set(entity, id);
}
} else {
id = (ID)_idField.get(entity);
}

id = (ID)_idField.get(entity);
}
} catch (final IllegalAccessException e) {
throw new CloudRuntimeException("Yikes! ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,14 @@ public QuotaTariffVO findByUuid(String uuid) {

return quotaTariffs.get(0);
}

@Override
public QuotaTariffVO findByIdIncludingRemoved(Long id) {
return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<QuotaTariffVO>) status -> super.findByIdIncludingRemoved(id));
}

@Override
public QuotaTariffVO findByUuidIncludingRemoved(String uuid) {
return Transaction.execute(TransactionLegacy.USAGE_DB, (TransactionCallback<QuotaTariffVO>) status -> super.findByUuidIncludingRemoved(uuid));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//under the License.
package org.apache.cloudstack.quota.vo;

import org.apache.cloudstack.api.InternalIdentity;
import org.apache.cloudstack.quota.QuotaTariff;
import org.apache.cloudstack.quota.constant.QuotaTypes;
import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;

Expand All @@ -37,7 +37,7 @@

@Entity
@Table(name = "quota_tariff")
public class QuotaTariffVO implements InternalIdentity {
public class QuotaTariffVO implements QuotaTariff {
private static final long serialVersionUID = -7117933766387653203L;

@Id
Expand Down Expand Up @@ -240,6 +240,7 @@ public String getDescription() {
return description;
}

@Override
public String getUuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
import org.apache.cloudstack.api.response.QuotaTariffResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -70,6 +72,7 @@ public class QuotaTariffCreateCmd extends BaseCmd {

@Override
public void execute() {
CallContext.current().setEventDetails(String.format("Tariff: %s, description: %s, value: %s", getName(), getDescription(), getValue()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

IMO, It would be better to override getApiResourceType() & getApiResourceId() methods. This would also link the events with the quota resources.

@harikrishna-patnala @DaanHoogland What do you think?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you mean to add the fields resource_type and resource_id to the quota_tariffs table and set and return those values?
As tarriffs can change and need to keep historic data, I am not sure, but it might work. @GutoVeronezi can you chime in?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No. I meant for Quota resource itself. Here is the javadoc for getApiResourceId() method.
This will require adding a key ApiCommandResourceType.java as well.

/**
     * Commands that generate action events associated to a resource and
     * async commands that want to be tracked as part of the listXXX commands
     * need to provide implementations of the two following methods,
     * getApiResourceId() and getApiResourceType()
     *
     * getApiResourceId() should return the id of the object the async command is executing on
     * getApiResourceType() should return a type from the ApiCommandResourceType enumeration
     */

As per my understanding, this will add a link in UI for events view. And allows to filter events per resource type & resource id which is quota in this case.
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@hsato03 can you have a look at this?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Hi @vishesh92 @DaanHoogland,

I made the changes to allow users filter quota tariff events in UI. Could you guys take a look?

QuotaTariffVO result = responseBuilder.createQuotaTariff(this);

if (result == null) {
Expand Down Expand Up @@ -134,4 +137,8 @@ public void setEndDate(Date endDate) {
this.endDate = endDate;
}

@Override
public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.QuotaTariff;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,14 @@
import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiArgValidator;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
import org.apache.cloudstack.api.response.QuotaTariffResponse;
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.log4j.Logger;

import javax.inject.Inject;
Expand All @@ -49,6 +51,7 @@ public String getId() {

@Override
public void execute() {
CallContext.current().setEventDetails(String.format("Tariff id: %s", getId()));
boolean result = responseBuilder.deleteQuotaTariff(getId());
SuccessResponse response = new SuccessResponse(getCommandName());
response.setSuccess(result);
Expand All @@ -60,4 +63,8 @@ public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}

@Override
public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.QuotaTariff;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@

import org.apache.cloudstack.acl.RoleType;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiCommandResourceType;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.Parameter;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.cloudstack.api.response.QuotaResponseBuilder;
import org.apache.cloudstack.api.response.QuotaTariffResponse;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.quota.vo.QuotaTariffVO;
import org.apache.log4j.Logger;

Expand Down Expand Up @@ -111,6 +113,7 @@ public QuotaTariffUpdateCmd() {

@Override
public void execute() {
CallContext.current().setEventDetails(String.format("Tariff: %s, description: %s, value: %s", getName(), getDescription(), getValue()));
final QuotaTariffVO result = _responseBuilder.updateQuotaTariffPlan(this);
if (result == null) {
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update quota tariff plan");
Expand All @@ -125,4 +128,8 @@ public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}

@Override
public ApiCommandResourceType getApiResourceType() {
return ApiCommandResourceType.QuotaTariff;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.apache.cloudstack.api.command.QuotaTariffCreateCmd;
import org.apache.cloudstack.api.command.QuotaTariffListCmd;
import org.apache.cloudstack.api.command.QuotaTariffUpdateCmd;
import org.apache.cloudstack.context.CallContext;
import org.apache.cloudstack.quota.QuotaManager;
import org.apache.cloudstack.quota.QuotaService;
import org.apache.cloudstack.quota.QuotaStatement;
Expand Down Expand Up @@ -75,6 +76,8 @@
import com.cloud.user.dao.UserDao;
import com.cloud.utils.Pair;
import com.cloud.utils.db.Filter;
import com.cloud.event.ActionEvent;
import com.cloud.event.EventTypes;

@Component
public class QuotaResponseBuilderImpl implements QuotaResponseBuilder {
Expand Down Expand Up @@ -380,6 +383,7 @@ public Pair<List<QuotaTariffVO>, Integer> listQuotaTariffPlans(final QuotaTariff
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_QUOTA_TARIFF_UPDATE, eventDescription = "updating Quota Tariff")
public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) {
String name = cmd.getName();
Double value = cmd.getValue();
Expand All @@ -403,6 +407,9 @@ public QuotaTariffVO updateQuotaTariffPlan(QuotaTariffUpdateCmd cmd) {
QuotaTariffVO newQuotaTariff = persistNewQuotaTariff(currentQuotaTariff, name, 0, currentQuotaTariffStartDate, cmd.getEntityOwnerId(), endDate, value, description,
activationRule);
_quotaTariffDao.updateQuotaTariff(currentQuotaTariff);

CallContext.current().setEventResourceId(newQuotaTariff.getId());

return newQuotaTariff;
}

Expand Down Expand Up @@ -619,6 +626,7 @@ private Date createDateAtTheStartOfNextDay(LocalDate localDate) {
}

@Override
@ActionEvent(eventType = EventTypes.EVENT_QUOTA_TARIFF_CREATE, eventDescription = "creating Quota Tariff")
public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) {
String name = cmd.getName();
int usageType = cmd.getUsageType();
Expand All @@ -640,9 +648,14 @@ public QuotaTariffVO createQuotaTariff(QuotaTariffCreateCmd cmd) {
throw new InvalidParameterValueException(String.format("The quota tariff's start date [%s] cannot be less than now [%s]", startDate, now));
}

return persistNewQuotaTariff(null, name, usageType, startDate, cmd.getEntityOwnerId(), endDate, value, description, activationRule);
QuotaTariffVO newQuotaTariff = persistNewQuotaTariff(null, name, usageType, startDate, cmd.getEntityOwnerId(), endDate, value, description, activationRule);

CallContext.current().setEventResourceId(newQuotaTariff.getId());

return newQuotaTariff;
}

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

Expand All @@ -651,6 +664,9 @@ public boolean deleteQuotaTariff(String quotaTariffUuid) {
}

quotaTariff.setRemoved(_quotaService.computeAdjustedTime(new Date()));

CallContext.current().setEventResourceId(quotaTariff.getId());

return _quotaTariffDao.updateQuotaTariff(quotaTariff);
}
}
3 changes: 2 additions & 1 deletion ui/src/components/view/SearchView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ export default {
{ value: 'Template' },
{ value: 'User' },
{ value: 'VirtualMachine' },
{ value: 'Volume' }
{ value: 'Volume' },
{ value: 'QuotaTariff' }
]
this.fields[resourceTypeIndex].loading = false
}
Expand Down
4 changes: 2 additions & 2 deletions ui/src/components/widgets/ResourceLabel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ export default {
created () {
if (this.resourceType) {
var routePrefix = this.$getRouteFromResourceType(this.resourceType)
if (routePrefix && this.resourceId) {
if (routePrefix && this.resourceId && this.resourceType !== 'QuotaTariff') {
this.resourceRoute = '/' + routePrefix + '/' + this.resourceId
}
this.resourceIcon = this.$getIconFromResourceType(this.resourceType)
this.resourceIconTooltip = this.$t('label.' + this.resourceType.toString().toLowerCase())
this.resourceIconTooltip = this.$t('label.' + this.resourceType.toString().match(/[A-Z][a-z]*/g).join('.').toLowerCase())
}
}
}
Expand Down
1 change: 1 addition & 0 deletions ui/src/utils/plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ export const resourceTypePlugin = {
case 'AffinityGroup':
case 'VpnCustomerGateway':
case 'AutoScaleVmGroup':
case 'QuotaTariff':
return resourceType.toLowerCase()
}
return ''
Expand Down