Skip to content
Open
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 @@ -428,7 +428,7 @@ protected BigDecimal getQuotaTariffValueToBeApplied(QuotaTariffVO quotaTariff, J
}

injectPresetVariablesIntoJsInterpreter(jsInterpreter, presetVariables);
jsInterpreter.injectVariable("lastTariffs", lastAppliedTariffsList.toString());
jsInterpreter.injectVariable("lastTariffs", lastAppliedTariffsList);

String scriptResult = jsInterpreter.executeScript(activationRule).toString();

Expand Down Expand Up @@ -458,18 +458,18 @@ protected BigDecimal getQuotaTariffValueToBeApplied(QuotaTariffVO quotaTariff, J
protected void injectPresetVariablesIntoJsInterpreter(JsInterpreter jsInterpreter, PresetVariables presetVariables) {
jsInterpreter.discardCurrentVariables();

jsInterpreter.injectVariable("account", presetVariables.getAccount().toString());
jsInterpreter.injectVariable("domain", presetVariables.getDomain().toString());
jsInterpreter.injectVariable("account", presetVariables.getAccount());
jsInterpreter.injectVariable("domain", presetVariables.getDomain());

GenericPresetVariable project = presetVariables.getProject();
if (project != null) {
jsInterpreter.injectVariable("project", project.toString());
jsInterpreter.injectVariable("project", project);

}

jsInterpreter.injectVariable("resourceType", presetVariables.getResourceType());
jsInterpreter.injectVariable("value", presetVariables.getValue().toString());
jsInterpreter.injectVariable("zone", presetVariables.getZone().toString());
jsInterpreter.injectVariable("value", presetVariables.getValue());
jsInterpreter.injectVariable("zone", presetVariables.getZone());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public Role getRole() {

public void setRole(Role role) {
this.role = role;
fieldNamesToIncludeInToString.add("role");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@ public String getExternalId() {

public void setExternalId(String externalId) {
this.externalId = externalId;
fieldNamesToIncludeInToString.add("externalId");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public boolean isCustomized() {

public void setCustomized(boolean customized) {
this.customized = customized;
fieldNamesToIncludeInToString.add("customized");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public String getPath() {

public void setPath(String path) {
this.path = path;
fieldNamesToIncludeInToString.add("path");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@

package org.apache.cloudstack.quota.activationrule.presetvariables;

import java.util.HashSet;
import java.util.Set;

import org.apache.cloudstack.utils.reflectiontostringbuilderutils.ReflectionToStringBuilderUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

public class GenericPresetVariable {
@PresetVariableDefinition(description = "ID of the resource.")
Expand All @@ -29,15 +27,12 @@ public class GenericPresetVariable {
@PresetVariableDefinition(description = "Name of the resource.")
private String name;

protected transient Set<String> fieldNamesToIncludeInToString = new HashSet<>();

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
fieldNamesToIncludeInToString.add("id");
}

public String getName() {
Expand All @@ -46,15 +41,10 @@ public String getName() {

public void setName(String name) {
this.name = name;
fieldNamesToIncludeInToString.add("name");
}

/***
* Converts the preset variable into a valid JSON object that will be injected into the JS interpreter.
* This method should not be overridden or changed.
*/
@Override
public final String toString() {
return ReflectionToStringBuilderUtils.reflectOnlySelectedFields(this, fieldNamesToIncludeInToString.toArray(new String[0]));
public String toString() {
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public List<String> getTags() {

public void setTags(List<String> tags) {
this.tags = tags;
fieldNamesToIncludeInToString.add("tags");
}

public Boolean getIsTagARule() {
Expand All @@ -41,6 +40,5 @@ public Boolean getIsTagARule() {

public void setIsTagARule(Boolean isTagARule) {
this.isTagARule = isTagARule;
fieldNamesToIncludeInToString.add("isTagARule");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected Role getPresetVariableRole(Long roleId) {
Role role = new Role();
role.setId(roleVo.getUuid());
role.setName(roleVo.getName());
role.setType(roleVo.getRoleType());
role.setType(roleVo.getRoleType().toString());

return role;
}
Expand Down Expand Up @@ -490,7 +490,7 @@ protected void loadPresetVariableValueForVolume(UsageVO usageRecord, Value value
value.setDiskOffering(getPresetVariableValueDiskOffering(volumeVo.getDiskOfferingId()));
value.setId(volumeVo.getUuid());
value.setName(volumeVo.getName());
value.setProvisioningType(volumeVo.getProvisioningType());
value.setProvisioningType(volumeVo.getProvisioningType().toString());

Long poolId = volumeVo.getPoolId();
if (poolId == null) {
Expand Down Expand Up @@ -533,7 +533,7 @@ protected Storage getPresetVariableValueStorage(Long storageId, int usageType) {
storage = new Storage();
storage.setId(storagePoolVo.getUuid());
storage.setName(storagePoolVo.getName());
storage.setScope(storagePoolVo.getScope());
storage.setScope(storagePoolVo.getScope().toString());
List<StoragePoolTagVO> storagePoolTagVOList = storagePoolTagsDao.findStoragePoolTags(storageId);
List<String> storageTags = new ArrayList<>();
boolean isTagARule = false;
Expand Down Expand Up @@ -602,7 +602,7 @@ protected void loadPresetVariableValueForSnapshot(UsageVO usageRecord, Value val
value.setId(snapshotVo.getUuid());
value.setName(snapshotVo.getName());
value.setSize(ByteScaleUtils.bytesToMebibytes(snapshotVo.getSize()));
value.setSnapshotType(Snapshot.Type.values()[snapshotVo.getSnapshotType()]);
value.setSnapshotType(Snapshot.Type.values()[snapshotVo.getSnapshotType()].toString());
value.setStorage(getPresetVariableValueStorage(getSnapshotDataStoreId(snapshotId, usageRecord.getZoneId()), usageType));
value.setTags(getPresetVariableValueResourceTags(snapshotId, ResourceObjectType.Snapshot));
Hypervisor.HypervisorType hypervisorType = snapshotVo.getHypervisorType();
Expand Down Expand Up @@ -671,7 +671,7 @@ protected void loadPresetVariableValueForVmSnapshot(UsageVO usageRecord, Value v
value.setId(vmSnapshotVo.getUuid());
value.setName(vmSnapshotVo.getName());
value.setTags(getPresetVariableValueResourceTags(vmSnapshotId, ResourceObjectType.VMSnapshot));
value.setVmSnapshotType(vmSnapshotVo.getType());
value.setVmSnapshotType(vmSnapshotVo.getType().toString());

VMInstanceVO vmVo = vmInstanceDao.findByIdIncludingRemoved(vmSnapshotVo.getVmId());
if (vmVo != null && vmVo.getHypervisorType() != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@

package org.apache.cloudstack.quota.activationrule.presetvariables;

import org.apache.cloudstack.acl.RoleType;

public class Role extends GenericPresetVariable {
@PresetVariableDefinition(description = "Role type of the resource's owner.")
private RoleType type;
private String type;

public RoleType getType() {
public String getType() {
return type;
}

public void setType(RoleType type) {
public void setType(String type) {
this.type = type;
fieldNamesToIncludeInToString.add("type");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@

import java.util.List;

import com.cloud.storage.ScopeType;

public class Storage extends GenericPresetVariable {
@PresetVariableDefinition(description = "List of string representing the tags of the storage where the volume is (i.e.: [\"a\", \"b\"]).")
private List<String> tags;
Expand All @@ -29,15 +27,14 @@ public class Storage extends GenericPresetVariable {
private Boolean isTagARule;

@PresetVariableDefinition(description = "Scope of the storage where the volume is. Values can be: ZONE, CLUSTER or HOST. Applicable only for primary storages.")
private ScopeType scope;
private String scope;

public List<String> getTags() {
return tags;
}

public void setTags(List<String> tags) {
this.tags = tags;
fieldNamesToIncludeInToString.add("tags");
}

public Boolean getIsTagARule() {
Expand All @@ -46,16 +43,14 @@ public Boolean getIsTagARule() {

public void setIsTagARule(Boolean isTagARule) {
this.isTagARule = isTagARule;
fieldNamesToIncludeInToString.add("isTagARule");
}

public ScopeType getScope() {
public String getScope() {
return scope;
}

public void setScope(ScopeType scope) {
public void setScope(String scope) {
this.scope = scope;
fieldNamesToIncludeInToString.add("scope");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ public BigDecimal getValue() {

public void setValue(BigDecimal value) {
this.value = value;
fieldNamesToIncludeInToString.add("value");
}
}
Loading
Loading