Skip to content
This repository was archived by the owner on Mar 31, 2023. It is now read-only.

Commit d9105a6

Browse files
authored
Merge pull request #149 from corindwyer/visibility-improvements
add tier resource numbers to no guaranteed capacity message
2 parents be8a1a3 + 6132bd5 commit d9105a6

6 files changed

Lines changed: 56 additions & 22 deletions

File tree

fenzo-core/src/main/java/com/netflix/fenzo/AssignableVMs.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,6 @@ private int addLeases(List<VirtualMachineLease> leases) {
162162
return rejected;
163163
}
164164

165-
// TODO Remove after confirming new VMCollection class is ready
166-
// private void createAvmIfAbsent(String hostname) {
167-
// if(virtualMachinesMap.get(hostname) == null)
168-
// virtualMachinesMap.putIfAbsent(hostname,
169-
// new AssignableVirtualMachine(vmIdToHostnameMap, leaseIdToHostnameMap, hostname,
170-
// leaseRejectAction, leaseOfferExpirySecs, taskTracker, singleLeaseMode));
171-
// }
172-
173165
void expireLease(String leaseId) {
174166
final String hostname = leaseIdToHostnameMap.get(leaseId);
175167
if(hostname==null) {

fenzo-core/src/main/java/com/netflix/fenzo/ScaleDownConstraintEvaluator.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
import java.util.Optional;
1919

2020
/**
21-
* An evaluator that for each VM computes a score from 0 to 1, with 0 being the lowest, and 1 highest. Evaluation
22-
* equal to 0, means that the VM should not be terminated at all. To allow state sharing during evaluation of a
21+
* An evaluator that for each VM computes a score from 0.0 to 1.0, with 0.0 being the lowest, and 1.0 highest. Evaluation
22+
* equal to 0.0, means that the VM should not be terminated at all. To allow state sharing during evaluation of a
2323
* sequence of candidate VMs, an evaluator implementation specific context is provided on each invocation. A new
24-
* context value is returned as part of {@link Result}.
24+
* context value is returned as part of the {@link Result}.
2525
*/
2626
public interface ScaleDownConstraintEvaluator<CONTEXT> {
2727

@@ -64,11 +64,11 @@ default String getName() {
6464
}
6565

6666
/**
67-
* Return score from 0 to 1 for a candidate VM to be terminating. The higher the score, the higher priority of
68-
* the VM to get terminated. Value 0 means that it should not be terminated.
67+
* Return score from 0.0 to 1.0 for a candidate VM to be terminating. The higher the score, the higher priority of
68+
* the VM to get terminated. Value 0.0 means that it should not be terminated.
6969
*
7070
* @param candidate candidate VM to be removed
71-
* @param context evaluator specific data, hold for single evaluation cycle. Initial value is set to Optional.empty().
71+
* @param context evaluator specific data, held for single evaluation cycle. Initial value is set to Optional.empty().
7272
* Evaluator should return new context as part of {@link Result} result. The new state will be passed
7373
* during subsequent method invocation.
7474
*

fenzo-core/src/main/java/com/netflix/fenzo/VMCollection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class VMCollection {
4343

4444
Collection<AssignableVirtualMachine> getAllVMs() {
4545
List<AssignableVirtualMachine> result = new LinkedList<>();
46-
vms.values().forEach(m -> m.values().forEach(result::add));
46+
vms.values().forEach(m -> result.addAll(m.values()));
4747
return result;
4848
}
4949

@@ -175,7 +175,7 @@ boolean addLease(VirtualMachineLease l) {
175175

176176
public int size() {
177177
final Optional<Integer> size = vms.values().stream().map(Map::size).reduce((i1, i2) -> i1 + i2);
178-
return size.isPresent()? size.get() : 0;
178+
return size.orElse(0);
179179
}
180180

181181
public int size(String group) {

fenzo-core/src/main/java/com/netflix/fenzo/queues/tiered/QueueBucket.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ void setBucketGuarantees(ResAllocs bucketGuarantees) {
7373
updateEffectiveUsage();
7474
}
7575

76+
ResAllocs getBucketGuarantees() {
77+
return bucketGuarantees;
78+
}
79+
7680
@Override
7781
public void queueTask(QueuableTask t) throws TaskQueueException {
7882
if (iterator != null)
@@ -178,6 +182,17 @@ public ResAllocs getEffectiveUsage() {
178182
return effectiveUsage;
179183
}
180184

185+
public String getBucketCapacityAsString() {
186+
StringBuilder sb = new StringBuilder();
187+
if (bucketGuarantees != null) {
188+
sb.append("Bucket ").append(name).append(" Total Capacity: ").append(bucketGuarantees.getAsString());
189+
}
190+
if (effectiveUsage != null) {
191+
sb.append("\nBucket ").append(name).append(" Used Capacity: ").append(effectiveUsage.getAsString());
192+
}
193+
return sb.toString();
194+
}
195+
181196
@Override
182197
public void reset() {
183198
iterator = null;

fenzo-core/src/main/java/com/netflix/fenzo/queues/tiered/Tier.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616

1717
package com.netflix.fenzo.queues.tiered;
1818

19+
import java.util.*;
20+
import java.util.function.BiFunction;
21+
1922
import com.netflix.fenzo.AssignmentFailure;
2023
import com.netflix.fenzo.VMResource;
2124
import com.netflix.fenzo.queues.*;
22-
import com.netflix.fenzo.queues.TaskQueue;
2325
import com.netflix.fenzo.sla.ResAllocs;
2426
import com.netflix.fenzo.sla.ResAllocsUtil;
2527
import org.slf4j.Logger;
2628
import org.slf4j.LoggerFactory;
2729

28-
import java.util.*;
29-
import java.util.function.BiFunction;
30-
3130
/**
3231
* This class represents a tier of the multi-tiered queue that {@link TieredQueue} represents. The tier holds one or
3332
* more buckets for queues, {@link QueueBucket} and maintains them in an order defined by the dynamic value for
@@ -133,8 +132,10 @@ public Assignable<QueuableTask> nextTaskToLaunch() throws TaskQueueException {
133132
return taskOrFailure;
134133
}
135134
return Assignable.error(task, new AssignmentFailure(VMResource.ResAllocs, 0, 0, 0,
136-
"No guaranteed capacity left for queue " + bucket.getName()
137-
+ ", and no spare capacity is available"));
135+
"No guaranteed capacity left for queue."
136+
+ "\n" + bucket.getBucketCapacityAsString()
137+
+ "\n" + getTierCapacityAsString()
138+
));
138139
}
139140
}
140141
return null;
@@ -270,6 +271,20 @@ private String getSortedListString() {
270271
return b.toString();
271272
}
272273

274+
private String getTierCapacityAsString() {
275+
StringBuilder sb = new StringBuilder();
276+
if (tierResources != null) {
277+
sb.append("Tier ").append(tierNumber).append(" Total Capacity: ").append(tierResources.getAsString());
278+
}
279+
if (effectiveUsedResources != null) {
280+
sb.append("\nTier ").append(tierNumber).append(" Used Capacity: ").append(effectiveUsedResources.getAsString());
281+
}
282+
if (remainingResources != null) {
283+
sb.append("\nTier ").append(tierNumber).append(" Remaining Capacity: ").append(remainingResources.getAsString());
284+
}
285+
return sb.toString();
286+
}
287+
273288
@Override
274289
public void setTotalResources(Map<VMResource, Double> totalResourcesMap) {
275290
if (totalResMapChanged(currTotalResourcesMap, totalResourcesMap)) {

fenzo-core/src/main/java/com/netflix/fenzo/sla/ResAllocs.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,16 @@ public interface ResAllocs {
5656
* @return the maximum disk space, in MB
5757
*/
5858
double getDisk();
59+
60+
/**
61+
* Returns the the resource allocations in a string representation.
62+
*
63+
* @return the resources as a string
64+
*/
65+
default String getAsString() {
66+
return "{ cpu: " + getCores() +
67+
", memory: " + getMemory() +
68+
", disk: " + getDisk() +
69+
", networkMbps: " + getNetworkMbps() + " }";
70+
}
5971
}

0 commit comments

Comments
 (0)