Skip to content

Commit

Permalink
VBV-577 - Rename "Policies" tab to "Placement"
Browse files Browse the repository at this point in the history
Main changes:
- GroupResourcePolicyService -> GroupResourcePlacementService
- URL: ../group-policies -> ../group-placement
- Default name: "default-resource-policy" -> "default-resource-placement"

And all related changes in tests and UI.

All unit tests are passing locally.

Change-Id: Ifc9163cac3231adfb4c1591276d2054a5ae60876
Reviewed-on: http://bellevue-ci.eng.vmware.com:8080/2496
Reviewed-by: Rostislav Georgiev <[email protected]>
Bellevue-Verified: e_vcoauto_glob_1 <[email protected]>
CS-Verified: e_vcoauto_glob_1 <[email protected]>
  • Loading branch information
Sergio Sanchez committed Sep 27, 2016
1 parent f23aa1d commit e05315a
Show file tree
Hide file tree
Showing 83 changed files with 2,411 additions and 2,387 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

* Groups are now Projects

* (Group Resource) Policies are now (Group Resource) Placements.

## 0.5.0

* Initial open source release.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public interface ManagementUriParts {
String EXPAND_SUFFIX = "?$expand=true";

String RESOURCES = "/resources";
String RESOURCE_GROUP_POLICIES = RESOURCES + "/group-policies";
String RESOURCE_GROUP_PLACEMENTS = RESOURCES + "/group-placements";
String RESOURCE_NAME_PREFIXES = RESOURCES + "/name-prefixes";
String DEPLOYMENT_POLICIES = RESOURCES + "/deployment-policies";
String ELASTIC_PLACEMENT_ZONES = RESOURCES + "/elastic-placement-zones";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ComputeConstants {

public static final String COMPUTE_CONFIG_CONTENT_PROP_NAME = "__computeConfigContent";

public static final String GROUP_RESOURCE_POLICY_LINK_NAME = "__groupResourcePolicyLink";
public static final String GROUP_RESOURCE_PLACEMENT_LINK_NAME = "__groupResourcePlacementLink";

public static final String DOCKER_URI_PROP_NAME = "__dockerUri";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import com.vmware.admiral.compute.ResourcePoolQueryHelper;
import com.vmware.admiral.compute.ResourcePoolQueryHelper.QueryResult.ResourcePoolData;
import com.vmware.admiral.compute.container.ContainerService.ContainerState;
import com.vmware.admiral.compute.container.GroupResourcePolicyService.GroupResourcePolicyState;
import com.vmware.admiral.compute.container.GroupResourcePlacementService.GroupResourcePlacementState;
import com.vmware.admiral.compute.container.HostContainerListDataCollection.ContainerListCallback;
import com.vmware.admiral.compute.container.HostContainerListDataCollection.HostContainerListDataCollectionFactoryService;
import com.vmware.admiral.service.common.AbstractCallbackServiceHandler;
Expand Down Expand Up @@ -335,7 +335,7 @@ private void updateResourcePool(ComputeState computeState, Collection<String> rp
logSevere("Unable to update the resource pool with link "
+ resourcePoolState.documentSelfLink);
}
updatePolicies(resourcePoolState);
updatePlacements(resourcePoolState);
}));
};

Expand All @@ -348,85 +348,84 @@ private void updateResourcePool(ComputeState computeState, Collection<String> rp
}

/**
* Update the policies if we have more resources reserved than what's actually in the resource
* pool. Sort the policies by priority and decrease from their reservations
* Update the placements if we have more resources reserved than what's actually in the resource
* pool. Sort the placements by priority and decrease from their reservations
*
* @param resourcePoolState
*/
private void updatePolicies(ResourcePoolService.ResourcePoolState resourcePoolState) {
private void updatePlacements(ResourcePoolService.ResourcePoolState resourcePoolState) {
QueryTask queryTask = QueryUtil.buildPropertyQuery(
GroupResourcePolicyService.GroupResourcePolicyState.class,
GroupResourcePolicyService.GroupResourcePolicyState.FIELD_NAME_RESOURCE_POOL_LINK,
GroupResourcePlacementService.GroupResourcePlacementState.class,
GroupResourcePlacementService.GroupResourcePlacementState.FIELD_NAME_RESOURCE_POOL_LINK,
resourcePoolState.documentSelfLink);
QueryUtil.addExpandOption(queryTask);
ServiceDocumentQuery<GroupResourcePolicyState> query = new ServiceDocumentQuery<>(
getHost(), GroupResourcePolicyState.class);
List<GroupResourcePolicyState> policies = new ArrayList<>();
ServiceDocumentQuery<GroupResourcePlacementState> query = new ServiceDocumentQuery<>(
getHost(), GroupResourcePlacementState.class);
List<GroupResourcePlacementState> placements = new ArrayList<>();
query.query(queryTask, (r) -> {
if (r.hasException()) {
logSevere(r.getException());
} else if (r.hasResult()) {
policies.add(r.getResult());
placements.add(r.getResult());
} else {
if (policies.isEmpty()) {
if (placements.isEmpty()) {
return;
}

long diff = policies.stream()
long diff = placements.stream()
.map(q -> q.memoryLimit).reduce(0L, (a, b) -> a + b)
- resourcePoolState.maxMemoryBytes;
if (diff <= 0) {
return;
}

// Sort the policies by their "normalized" priority (priority divided by the sum of
// all
// priorities in the group). We do that because the priorities are relative within
// the group. E.g. Group A has two policies with priorities 1 and 2; group B has two
// policies with priorities 100 and 200 thus the normalized priorities will be:
// Sort the placements by their "normalized" priority (priority divided by the sum of
// all priorities in the group). We do that because the priorities are relative within
// the group. E.g. Group A has two placements with priorities 1 and 2; group B has two
// placements with priorities 100 and 200 thus the normalized priorities will be:
// 0.33; 0.66 for A and 0.33 and 0.66 for B
Map<String, Integer> sumOfPrioritiesByGroup = policies
Map<String, Integer> sumOfPrioritiesByGroup = placements
.stream().collect(
Collectors.groupingBy(
(GroupResourcePolicyState policy) -> getGroup(policy),
(GroupResourcePlacementState placement) -> getGroup(placement),
Collectors.summingInt((
GroupResourcePolicyState policy) -> policy.priority)));
GroupResourcePlacementState placement) -> placement.priority)));

Comparator<GroupResourcePolicyService.GroupResourcePolicyState> comparator = (q1,
Comparator<GroupResourcePlacementService.GroupResourcePlacementState> comparator = (q1,
q2) -> Double.compare(
((double) q2.priority) / sumOfPrioritiesByGroup.get(getGroup(q2)),
((double) q1.priority) / sumOfPrioritiesByGroup.get(getGroup(q1)));

policies.sort(comparator);
Set<GroupResourcePolicyService.GroupResourcePolicyState> policiesToUpdate = new HashSet<>();
for (GroupResourcePolicyService.GroupResourcePolicyState policy : policies) {
if (policy.availableMemory == 0 || policy.memoryLimit == 0) {
placements.sort(comparator);
Set<GroupResourcePlacementService.GroupResourcePlacementState> placementsToUpdate = new HashSet<>();
for (GroupResourcePlacementService.GroupResourcePlacementState placement : placements) {
if (placement.availableMemory == 0 || placement.memoryLimit == 0) {
continue;
}

policiesToUpdate.add(policy);
if (diff > policy.availableMemory) {
policy.memoryLimit -= policy.availableMemory;
diff -= policy.availableMemory;
placementsToUpdate.add(placement);
if (diff > placement.availableMemory) {
placement.memoryLimit -= placement.availableMemory;
diff -= placement.availableMemory;
} else {
policy.memoryLimit -= diff;
placement.memoryLimit -= diff;
break;
}
}

for (GroupResourcePolicyService.GroupResourcePolicyState policyToUpdate : policiesToUpdate) {
sendRequest(Operation.createPut(this, policyToUpdate.documentSelfLink)
.setBody(policyToUpdate));
for (GroupResourcePlacementService.GroupResourcePlacementState placementToUpdate : placementsToUpdate) {
sendRequest(Operation.createPut(this, placementToUpdate.documentSelfLink)
.setBody(placementToUpdate));
}

}
});
}

// Assume for now there's only one
private static String getGroup(GroupResourcePolicyService.GroupResourcePolicyState policy) {
if (policy.tenantLinks != null) {
return policy.tenantLinks.get(0);
private static String getGroup(GroupResourcePlacementService.GroupResourcePlacementState placement) {
if (placement.tenantLinks != null) {
return placement.tenantLinks.get(0);
} else {
return "";
}
Expand Down Expand Up @@ -499,7 +498,7 @@ private void updateResourcePool(ResourcePoolState resourcePoolState,
logSevere("Unable to update the resource pool with link "
+ rpPutState.documentSelfLink);
}
updatePolicies(rpPutState);
updatePlacements(rpPutState);
}));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,12 @@ public boolean isUnmanaged() {
public String parentLink;

/**
* Link to the resource policy associated with a given container instance. Null if no policy
* Link to the resource placement associated with a given container instance. Null if no
* placement
*/
@Documentation(description = "Link to the resource policy associated with a given container instance. Null if no policy")
@Documentation(description = "Link to the resource placement associated with a given container instance. Null if no placement")
@PropertyOptions(usage = { PropertyUsageOption.LINK, PropertyUsageOption.OPTIONAL })
public String groupResourcePolicyLink;
public String groupResourcePlacementLink;

/** Status of the container */
@Documentation(description = "Status of the container")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.vmware.admiral.common.ManagementUriParts;
import com.vmware.admiral.common.util.QueryUtil;
import com.vmware.admiral.compute.ContainerHostService;
import com.vmware.admiral.compute.container.GroupResourcePolicyService.GroupResourcePolicyState;
import com.vmware.admiral.compute.container.GroupResourcePlacementService.GroupResourcePlacementState;
import com.vmware.admiral.service.common.MultiTenantDocument;
import com.vmware.photon.controller.model.resources.ComputeService.ComputeState;
import com.vmware.xenon.common.Operation;
Expand Down Expand Up @@ -56,8 +56,8 @@ public void handleDelete(Operation delete) {
Operation[] ops = new Operation[] {
createReferenceCountOperation(ComputeState.class, QuerySpecification.buildCompositeFieldName(
ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, ContainerHostService.CUSTOM_PROPERTY_DEPLOYMENT_POLICY)),
createReferenceCountOperation(GroupResourcePolicyState.class,
GroupResourcePolicyState.FIELD_NAME_DEPLOYMENT_POLICY_LINK)
createReferenceCountOperation(GroupResourcePlacementState.class,
GroupResourcePlacementState.FIELD_NAME_DEPLOYMENT_POLICY_LINK)
};

OperationJoin.create(ops).setCompletion((os, es) -> {
Expand Down
Loading

0 comments on commit e05315a

Please sign in to comment.