/** * @return a new {@link ResourcePool} which is a copy of this {@link ResourcePool} except its resource vector has been * reduced by the input {@link ResourceRequirement}. */ protected ResourcePool contractPool(ResourceRequirement requirement) { return new ResourcePool(VectorAlgebra.addVector(this.softBound, requirement.getResourceVector(), -1., null), VectorAlgebra.addVector(this.hardBound, requirement.getResourceVector(), -1., null), this.defaultResourceUse, this.dimensionIndex); }
/** * @return true if input {@link ResourceRequirement} exceeds the soft bound long any dimension. If the parameter * orEqual is true, then matching along any dimension will also return true. */ public boolean exceedsSoftBound(ResourceRequirement requirement, boolean orEqual) { return VectorAlgebra.exceedsVector(this.softBound, requirement.getResourceVector(), orEqual); }
/** * Stringify a {@link ResourceRequirement} with the appropriate dimension labels. */ public String stringifyRequirement(ResourceRequirement requirement) { return vectorToString(requirement.getResourceVector()); }
@Test public void test() { ResourcePool pool = ResourcePool.builder().maxResource(MEMORY, 1000.).maxResource(TIME, 200.).tolerance(MEMORY, 2.) .defaultRequirement(TIME, 1.).build(); Assert.assertEquals(pool.getNumDimensions(), 2); Assert.assertEquals(pool.getSoftBound(), new double[]{1000, 200}); // Default tolerance is 1.2 Assert.assertEquals(pool.getHardBound(), new double[]{2000, 240}); // Test default resource use Assert.assertEquals(pool.getResourceRequirementBuilder().build().getResourceVector(), new double[]{0, 1}); ResourceRequirement requirement = pool.getResourceRequirementBuilder().setRequirement(MEMORY, 10.).build(); Assert.assertEquals(requirement.getResourceVector(), new double[]{10, 1}); }
@Override public <T extends Request<T>> RequestAllocator<T> createRequestAllocator(RequestAllocatorConfig<T> cofiguration) { Preconditions.checkArgument(cofiguration.getPrioritizer() instanceof HierarchicalPrioritizer, "Prioritizer must be a " + HierarchicalPrioritizer.class.getSimpleName()); RequestAllocator<T> underlying = RequestAllocatorUtils.inferFromConfig(cofiguration); return new HierarchicalAllocator<>((HierarchicalPrioritizer<T>) cofiguration.getPrioritizer(), underlying); } }
@Override public T next() { RequestWithResourceRequirement<T> nextElement = this.underlying.next(); VectorAlgebra.addVector(this.currentRequirement, nextElement.getResourceRequirement().getResourceVector(), 1.0, this.currentRequirement); return nextElement.getT(); }
@Override public <T extends Request<T>> RequestAllocator<T> createRequestAllocator(RequestAllocatorConfig<T> configuration) { return new GreedyAllocator<>(configuration); } }
public static ResourceRequirement add(ResourceRequirement r1, ResourceRequirement r2, ResourceRequirement reuse) { if (reuse == null) { reuse = new ResourceRequirement(r1.resourceVector.clone()); } VectorAlgebra.addVector(r1.resourceVector, r2.resourceVector, 1., reuse.resourceVector); return reuse; }
/** * Use to create a {@link ResourceRequirement} compatible with this {@link ResourcePool}. */ public ResourceRequirement.Builder getResourceRequirementBuilder() { return new ResourceRequirement.Builder(this); }
/** * Vector addition of this and other {@link ResourceRequirement}. */ public void subtract(ResourceRequirement other) { VectorAlgebra.addVector(this.resourceVector, other.resourceVector, -1., this.resourceVector); }
@Override public <T extends Request<T>> RequestAllocator<T> createRequestAllocator(RequestAllocatorConfig<T> configuration) { return new BruteForceAllocator<>(configuration); } }
@Override public Boolean call() throws Exception { return requestIterable.isFull(); } });
@Override public int compare(Requestor<T> o1, Requestor<T> o2) { return prioritizer.compareRequestors(o1, o2); } };
@Override public T apply(RequestWithResourceRequirement<T> ttAndRequirement) { return ttAndRequirement.getT(); } }
/** * @return Whether the list has reached its soft bound. */ public synchronized boolean isFull() { return this.resourcePool.exceedsSoftBound(this.currentRequirement, true); }
public ResourceRequirement build() { return new ResourceRequirement(this.requirement); } }
@Override public String apply(StringRequest input) { return input.getString(); } })), Sets.newHashSet("a-50", "f-50"));
@Override public StringRequest apply(String input) { return new StringRequest(StringRequestor.this, input); } });
/** * @return true if input {@link ResourceRequirement} exceeds the hard bound long any dimension. If the parameter * orEqual is true, then matching along any dimension will also return true. */ public boolean exceedsHardBound(ResourceRequirement requirement, boolean orEqual) { return VectorAlgebra.exceedsVector(this.hardBound, requirement.getResourceVector(), orEqual); }
/** * Vector addition of this and other {@link ResourceRequirement}. */ public void add(ResourceRequirement other) { VectorAlgebra.addVector(this.resourceVector, other.resourceVector, 1., this.resourceVector); }