Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
Prev Previous commit
Next Next commit
Address reviews
  • Loading branch information
BryanMLima committed Nov 10, 2023
commit 2f456948492a8298fbe6177162aba3b29067673c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

import static org.apache.cloudstack.api.ApiConstants.HEURISTIC_PURPOSE_VALID_OPTIONS;

@APICommand(name = "createSecondaryStorageSelector", description = "Creates a secondary storage selector, described by the heuristic rule.", responseObject =
@APICommand(name = "createSecondaryStorageSelector", description = "Creates a secondary storage selector, described by the heuristic rule.", since = "4.19.0", responseObject =
SecondaryStorageHeuristicsResponse.class, entityType = {Heuristic.class}, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false, authorized = {RoleType.Admin})
public class CreateSecondaryStorageSelectorCmd extends BaseCmd{

Expand All @@ -49,7 +49,8 @@ public class CreateSecondaryStorageSelectorCmd extends BaseCmd{
private String purpose;

@Parameter(name = ApiConstants.HEURISTIC_RULE, required = true, type = BaseCmd.CommandType.STRING, description = "The heuristic rule, in JavaScript language. It is required " +
"that it returns the UUID of a secondary storage pool.", length = 65535)
"that it returns the UUID of a secondary storage pool. An example of a rule is `if (snapshot.hypervisorType === 'KVM') { '7832f261-c602-4e8e-8580-2496ffbbc45d'; " +
"}` would allocate all snapshots with the KVM hypervisor to the specified secondary storage UUID.", length = 65535)
private String heuristicRule;

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@

import static org.apache.cloudstack.api.ApiConstants.HEURISTIC_PURPOSE_VALID_OPTIONS;

@APICommand(name = "listSecondaryStorageSelectors", description = "Lists the secondary storage selectors and their rules.", responseObject = SecondaryStorageHeuristicsResponse.class,
requestHasSensitiveInfo = false, entityType = {Heuristic.class}, responseHasSensitiveInfo = false, authorized = {RoleType.Admin})
@APICommand(name = "listSecondaryStorageSelectors", description = "Lists the secondary storage selectors and their rules.", since = "4.19.0", responseObject =
SecondaryStorageHeuristicsResponse.class, requestHasSensitiveInfo = false, entityType = {Heuristic.class}, responseHasSensitiveInfo = false, authorized = {RoleType.Admin})
public class ListSecondaryStorageSelectorsCmd extends BaseListCmd {

@Parameter(name = ApiConstants.ZONE_ID, required = true, entityType = ZoneResponse.class, type = CommandType.UUID, description = "The zone ID to be used in the search filter.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
import org.apache.cloudstack.api.response.SuccessResponse;
import org.apache.cloudstack.secstorage.heuristics.Heuristic;

@APICommand(name = "removeSecondaryStorageSelector", description = "Removes an existing secondary storage selector.", responseObject = SecondaryStorageHeuristicsResponse.class,
requestHasSensitiveInfo = false, entityType = {Heuristic.class}, responseHasSensitiveInfo = false, authorized = {RoleType.Admin})
@APICommand(name = "removeSecondaryStorageSelector", description = "Removes an existing secondary storage selector.", since = "4.19.0", responseObject =
SecondaryStorageHeuristicsResponse.class, requestHasSensitiveInfo = false, entityType = {Heuristic.class}, responseHasSensitiveInfo = false, authorized = {RoleType.Admin})
public class RemoveSecondaryStorageSelectorCmd extends BaseCmd {
@Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, entityType = SecondaryStorageHeuristicsResponse.class, required = true,
description = "The unique identifier of the secondary storage selector to be removed.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@
import org.apache.cloudstack.api.response.SecondaryStorageHeuristicsResponse;
import org.apache.cloudstack.secstorage.heuristics.Heuristic;

@APICommand(name = "updateSecondaryStorageSelector", description = "Updates an existing secondary storage selector.", responseObject = SecondaryStorageHeuristicsResponse.class,
requestHasSensitiveInfo = false, entityType = {Heuristic.class}, responseHasSensitiveInfo = false, authorized = {RoleType.Admin})
@APICommand(name = "updateSecondaryStorageSelector", description = "Updates an existing secondary storage selector.", since = "4.19.0", responseObject =
SecondaryStorageHeuristicsResponse.class, requestHasSensitiveInfo = false, entityType = {Heuristic.class}, responseHasSensitiveInfo = false, authorized = {RoleType.Admin})
public class UpdateSecondaryStorageSelectorCmd extends BaseCmd {
@Parameter(name = ApiConstants.ID, type = BaseCmd.CommandType.UUID, entityType = SecondaryStorageHeuristicsResponse.class, required = true,
description = "The unique identifier of the secondary storage selector.")
private Long id;

@Parameter(name = ApiConstants.HEURISTIC_RULE, required = true, type = BaseCmd.CommandType.STRING, description = "The heuristic rule, in JavaScript language. It is required " +
"that it returns the UUID of a secondary storage pool.", length = 65535)
"that it returns the UUID of a secondary storage pool. An example of a rule is `if (snapshot.hypervisorType === 'KVM') { '7832f261-c602-4e8e-8580-2496ffbbc45d'; " +
"}` would allocate all snapshots with the KVM hypervisor to the specified secondary storage UUID.", length = 65535)
private String heuristicRule;

public Long getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,17 @@ public class SecondaryStorageHeuristicsResponse extends BaseResponse {
@Param(description = "When the heuristic was removed.")
private Date removed;

public SecondaryStorageHeuristicsResponse() {

public SecondaryStorageHeuristicsResponse(String id, String name, String description, String zoneId, String purpose, String heuristicRule, Date created, Date removed) {
super("heuristics");
this.id = id;
this.name = name;
this.description = description;
this.zoneId = zoneId;
this.purpose = purpose;
this.heuristicRule = heuristicRule;
this.created = created;
this.removed = removed;
Copy link
Member

Choose a reason for hiding this comment

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

@BryanMLima Do we need a removed field in response?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the API listSecondaryStorageSelectors has the parameter showRemoved. When this parameter is set to true, the removed field is used.

}

public String getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ public class HeuristicVO implements Heuristic {
public HeuristicVO() {
}

public HeuristicVO(String name, String description, Long zoneId, String purpose, String heuristicRule, Date created, Date removed) {
public HeuristicVO(String name, String description, Long zoneId, String purpose, String heuristicRule) {
this.name = name;
this.description = description;
this.zoneId = zoneId;
this.purpose = purpose;
this.heuristicRule = heuristicRule;
this.created = created;
this.removed = removed;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public HeuristicVO findByZoneIdAndPurpose(long zoneId, HeuristicPurpose purpose)
searchCriteria.setParameters("purpose", purpose.toString());
final Filter filter = new Filter(HeuristicVO.class, "created", false);

return findOneIncludingRemovedBy(searchCriteria, filter);
return findOneBy(searchCriteria, filter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ public ImageStoreVO findOneByZoneAndProtocol(long dataCenterId, String protocol)
@Override
public List<ImageStoreVO> listImageStoresByZoneIds(Long... zoneIds) {
SearchCriteria<ImageStoreVO> sc = zonesInSearch.create();
sc.setParametersIfNotNull("zonesIn" ,zoneIds);
sc.setParametersIfNotNull("zonesIn", zoneIds);
return listBy(sc);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public interface GenericDao<T, ID extends Serializable> {

public T findOneBy(final SearchCriteria<T> sc);

T findOneIncludingRemovedBy(SearchCriteria<T> sc, Filter filter);
T findOneBy(SearchCriteria<T> sc, Filter filter);

/**
* @return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ public T findOneBy(SearchCriteria<T> sc) {

@Override
@DB()
public T findOneIncludingRemovedBy(SearchCriteria<T> sc, final Filter filter) {
public T findOneBy(SearchCriteria<T> sc, final Filter filter) {
sc = checkAndSetRemovedIsNull(sc);
filter.setLimit(1L);
List<T> results = searchIncludingRemoved(sc, filter, null, false);
Expand Down
12 changes: 2 additions & 10 deletions server/src/main/java/com/cloud/api/ApiResponseHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5093,17 +5093,9 @@ public FirewallResponse createIpv6FirewallRuleResponse(FirewallRule fwRule) {

@Override
public SecondaryStorageHeuristicsResponse createSecondaryStorageSelectorResponse(Heuristic heuristic) {
SecondaryStorageHeuristicsResponse secondaryStorageHeuristicsResponse = new SecondaryStorageHeuristicsResponse();
String zoneUuid = ApiDBUtils.findZoneById(heuristic.getZoneId()).getUuid();

secondaryStorageHeuristicsResponse.setId(heuristic.getUuid());
secondaryStorageHeuristicsResponse.setName(heuristic.getName());
secondaryStorageHeuristicsResponse.setDescription(heuristic.getDescription());
secondaryStorageHeuristicsResponse.setZoneId(zoneUuid);
secondaryStorageHeuristicsResponse.setPurpose(heuristic.getPurpose());
secondaryStorageHeuristicsResponse.setHeuristicRule(heuristic.getHeuristicRule());
secondaryStorageHeuristicsResponse.setCreated(heuristic.getCreated());
secondaryStorageHeuristicsResponse.setRemoved(heuristic.getRemoved());
SecondaryStorageHeuristicsResponse secondaryStorageHeuristicsResponse = new SecondaryStorageHeuristicsResponse(heuristic.getUuid(), heuristic.getName(),
heuristic.getDescription(), zoneUuid, heuristic.getPurpose(), heuristic.getHeuristicRule(), heuristic.getCreated(), heuristic.getRemoved());
secondaryStorageHeuristicsResponse.setResponseName("secondarystorageheuristics");

return secondaryStorageHeuristicsResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1924,7 +1924,7 @@ public Heuristic createSecondaryStorageHeuristic(CreateSecondaryStorageSelectorC

validateHeuristicRule(heuristicRule);

HeuristicVO heuristicVO = new HeuristicVO(name, description, zoneId, formattedPurpose.toString(), heuristicRule, new Date(), null);
HeuristicVO heuristicVO = new HeuristicVO(name, description, zoneId, formattedPurpose.toString(), heuristicRule);
return secondaryStorageHeuristicDao.persist(heuristicVO);
}

Expand All @@ -1948,7 +1948,7 @@ public void removeSecondaryStorageHeuristic(RemoveSecondaryStorageSelectorCmd cm
if (heuristicVO != null) {
secondaryStorageHeuristicDao.remove(heuristicId);
} else {
throw new CloudRuntimeException(String.format("Unable to find an active heuristic with the specified UUID."));
throw new CloudRuntimeException("Unable to find an active heuristic with the specified UUID.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// under the License.
package org.apache.cloudstack.storage.heuristics.presetvariables;

public class Account extends GenericHeuristicPresetVariable{
public class Account extends GenericHeuristicPresetVariable {
private String id;

private Domain domain;
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/java/com/cloud/user/MockUsageEventDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public UsageEventVO findOneBy(SearchCriteria<UsageEventVO> sc) {
}

@Override
public UsageEventVO findOneIncludingRemovedBy(SearchCriteria<UsageEventVO> sc, Filter filter) {
public UsageEventVO findOneBy(SearchCriteria<UsageEventVO> sc, Filter filter) {
return null;
}

Expand Down