private Resource assignNodeLocalContainers(Resource clusterResource, ResourceRequest nodeLocalResourceRequest, FiCaSchedulerNode node, FiCaSchedulerApp application, Priority priority, RMContainer reservedContainer, MutableObject allocatedContainer, ResourceLimits currentResoureLimits) { if (canAssign(application, priority, node, NodeType.NODE_LOCAL, reservedContainer)) { return assignContainer(clusterResource, node, application, priority, nodeLocalResourceRequest, NodeType.NODE_LOCAL, reservedContainer, allocatedContainer, currentResoureLimits); } return Resources.none(); }
private Resource assignRackLocalContainers(Resource clusterResource, ResourceRequest rackLocalResourceRequest, FiCaSchedulerNode node, FiCaSchedulerApp application, Priority priority, RMContainer reservedContainer, MutableObject allocatedContainer, ResourceLimits currentResoureLimits) { if (canAssign(application, priority, node, NodeType.RACK_LOCAL, reservedContainer)) { return assignContainer(clusterResource, node, application, priority, rackLocalResourceRequest, NodeType.RACK_LOCAL, reservedContainer, allocatedContainer, currentResoureLimits); } return Resources.none(); }
private Resource assignOffSwitchContainers(Resource clusterResource, ResourceRequest offSwitchResourceRequest, FiCaSchedulerNode node, FiCaSchedulerApp application, Priority priority, RMContainer reservedContainer, MutableObject allocatedContainer, ResourceLimits currentResoureLimits) { if (canAssign(application, priority, node, NodeType.OFF_SWITCH, reservedContainer)) { return assignContainer(clusterResource, node, application, priority, offSwitchResourceRequest, NodeType.OFF_SWITCH, reservedContainer, allocatedContainer, currentResoureLimits); } return Resources.none(); }
@Override public ActivityQueryResponse queryByExpiryTime(CallingContext context, final String nextBatchId, Long batchSize, final Long lastSeen) { if (batchSize > MAX_BATCH_SIZE) { log.warn(String.format("Batch size %s is too large, resetting to maximum of %s", batchSize, MAX_BATCH_SIZE)); batchSize = MAX_BATCH_SIZE; } final MutableObject lastId = new MutableObject(); final long finalBatchSize = batchSize; final List<Activity> activities = new LinkedList<>(); ActivityStorage.visitAll(new RepoVisitor() { @Override public boolean visit(String name, JsonContent content, boolean isFolder) { if (activities.size() < finalBatchSize) { Activity activity = ActivityStorage.readFromJson(content); String currentId = activity.getId(); if ((nextBatchId.length() == 0 || currentId.compareTo(nextBatchId) > 0) && activity.getLastSeen() > lastSeen) { activities.add(activity); lastId.setValue(currentId); } return true; } else { return false; } } }); ActivityQueryResponse response = new ActivityQueryResponse(); response.setActivities(activities); boolean isLast = activities.size() < batchSize; response.setIsLast(isLast); if (!isLast) { String responseNextId = lastId.getValue().toString(); response.setNextBatchId(responseNextId); } return response; }
@Override public <R> R run(Supplier<R> function) { // runBackground synchronously on JavaFX thread if (Platform.isFxApplicationThread()) { return function.get(); } // queue on JavaFX thread and wait for completion final CountDownLatch doneLatch = new CountDownLatch(1); final MutableObject result = new MutableObject(); Platform.runLater(() -> { try { result.setValue(function.get()); } finally { doneLatch.countDown(); } }); try { doneLatch.await(); } catch (InterruptedException e) { // ignore exception } return (R) result.getValue(); }
public static int shell(String[] command, final StringBuilder stdout, final StringBuilder stderr, MutableObject processCapture) throws InterruptedException, IOException { return shell(Collections.EMPTY_MAP, command, stdout, stderr, processCapture); }
public static int shell(String command, final StringBuilder stdout, final StringBuilder stderr, MutableObject processCapture) throws InterruptedException, IOException { return shell(Commandline.translateCommandline(command), stdout, stderr, processCapture); }
private void doTestReplace(String expectedResult, String replaceTemplate, boolean substring) { String expectedShortResult = expectedResult.substring(1, expectedResult.length() - 1); StrSubstitutor sub = new StrSubstitutor(values); // replace using String assertEquals(expectedResult, sub.replace(replaceTemplate)); if (substring) { assertEquals(expectedShortResult, sub.replace(replaceTemplate, 1, replaceTemplate.length() - 2)); } // replace using char[] char[] chars = replaceTemplate.toCharArray(); assertEquals(expectedResult, sub.replace(chars)); if (substring) { assertEquals(expectedShortResult, sub.replace(chars, 1, chars.length - 2)); } // replace using StringBuffer StringBuffer buf = new StringBuffer(replaceTemplate); assertEquals(expectedResult, sub.replace(buf)); if (substring) { assertEquals(expectedShortResult, sub.replace(buf, 1, buf.length() - 2)); } // replace using StrBuilder StrBuilder bld = new StrBuilder(replaceTemplate); assertEquals(expectedResult, sub.replace(bld)); if (substring) { assertEquals(expectedShortResult, sub.replace(bld, 1, bld.length() - 2)); } // replace using object MutableObject obj = new MutableObject(replaceTemplate); // toString returns template assertEquals(expectedResult, sub.replace(obj)); // replace in StringBuffer buf = new StringBuffer(replaceTemplate); assertEquals(true, sub.replaceIn(buf)); assertEquals(expectedResult, buf.toString()); if (substring) { buf = new StringBuffer(replaceTemplate); assertEquals(true, sub.replaceIn(buf, 1, buf.length() - 2)); assertEquals(expectedResult, buf.toString()); // expect full result as remainder is untouched } // replace in StrBuilder bld = new StrBuilder(replaceTemplate); assertEquals(true, sub.replaceIn(bld)); assertEquals(expectedResult, bld.toString()); if (substring) { bld = new StrBuilder(replaceTemplate); assertEquals(true, sub.replaceIn(bld, 1, bld.length() - 2)); assertEquals(expectedResult, bld.toString()); // expect full result as remainder is untouched } }