private void clearEnforcedClusterStatus(String resourcePoolLink) { Map<String, Collection<Object>> keysToRemove = new HashMap<>(); keysToRemove.put(ResourcePoolState.FIELD_NAME_CUSTOM_PROPERTIES, Collections.singleton(ENFORCED_CLUSTER_STATUS_PROP)); ServiceStateMapUpdateRequest x = ServiceStateMapUpdateRequest.create(null, keysToRemove); Operation.createPatch(this, resourcePoolLink) .setBodyNoCloning(x) .sendWith(this); }
private void getCompute(Operation op, String hostLink, Consumer<ComputeState> consumer) { Operation.createGet(this, hostLink).setCompletion((o, e) -> { if (e != null) { op.fail(e); return; } consumer.accept(o.getBody(ComputeState.class)); }).sendWith(this); } }
private void getClusterDto(String clusterLink, Consumer<ClusterService.ClusterDto> consumer) { Operation.createGet(this, clusterLink) .setCompletion((o, e) -> { if (e != null) { failTask("Failed to get cluster " + clusterLink, e); return; } consumer.accept(o.getBody(ClusterService.ClusterDto.class)); }) .sendWith(this); }
private void getNetwork(String networkLink, Consumer<ContainerNetworkState> callback) { Operation.createGet(this, networkLink).setCompletion((op, ex) -> { if (ex != null) { failTask("Failed retrieving network: " + Utils.toString(ex), null); return; } ContainerNetworkState network = op.getBody(ContainerNetworkState.class); callback.accept(network); }).sendWith(this); }
private void getHost(String hostLink, Consumer<ComputeState> callback) { Operation.createGet(this, hostLink).setCompletion((op, ex) -> { if (ex != null) { failTask("Failed retrieving host: " + Utils.toString(ex), null); return; } ComputeState host = op.getBody(ComputeState.class); callback.accept(host); }).sendWith(this); }
private void getHost(String hostLink, Consumer<ComputeState> callback) { Operation.createGet(this, hostLink).setCompletion((op, ex) -> { if (ex != null) { failTask("Failed retrieving host: " + Utils.toString(ex), null); return; } ComputeState host = op.getBody(ComputeState.class); callback.accept(host); }).sendWith(this); }
private void registerClientCred(String caCert, String caKey, Operation startOp) { createClientCredentials(caCert, caKey) .setCompletion((o, e) -> { if (e != null) { startOp.fail(e); return; } startOp.complete(); }) .sendWith(this); }
private void registerClientCredIfNeeded(AuthCredentialsServiceState caCred, String caCert, String caKey, Operation startOp) { Operation.createGet(this, ManagementUriParts.AUTH_CREDENTIALS_CLIENT_LINK) .setCompletion((o, e) -> { if (e != null) { registerClientCred(caCert, caKey, startOp); return; } startOp.complete(); }) .sendWith(this); }
@Test public void testSendWithOnService() throws Throwable { testSendWith((o) -> o.sendWith(this.services.get(0))); }
@Test public void testSendWithOnService() throws Throwable { testSendWith((o) -> o.sendWith(this.services.get(0))); }
/** * Patch the task state to finished. */ private void patchToFinished(Long lastUpdateTime) { State patch = new State(); patch.taskInfo = TaskState.createAsFinished(); if (lastUpdateTime != null) { patch.latestSourceUpdateTimeMicros = lastUpdateTime; } Operation.createPatch(getUri()).setBody(patch).sendWith(this); }
@Test public void testSendWithOnHost() throws Throwable { testSendWith((o) -> o.sendWith(this.host)); }
@Test public void testSendWithOnHost() throws Throwable { testSendWith((o) -> o.sendWith(this.host)); }
private void updateRequestTrackerName(RequestBrokerState state, String name) { RequestStatus requestStatus = new RequestStatus(); requestStatus.name = name; requestStatus.documentSelfLink = state.requestTrackerLink; requestStatus.taskInfo = new TaskState(); Operation.createPatch(getHost(), state.requestTrackerLink) .setBodyNoCloning(requestStatus) .setCompletion((o, e) -> { if (e != null) { logFine("Couldn't set name to the request status because of: %s", e.getMessage()); } }).sendWith(this); }
private void failTask(Throwable t) { State patch = new State(); patch.taskInfo = TaskState.createAsFailed(); patch.taskInfo.failure = Utils.toServiceErrorResponse(t); Operation.createPatch(getUri()) .setBody(patch) .sendWith(this); }
public static void checkConvergence(ServiceHost host, URI nodegroupReference, Operation parentOp) { Operation.createGet(nodegroupReference) .transferRefererFrom(parentOp) .setCompletion((o, t) -> { if (t != null) { parentOp.fail(t); return; } NodeGroupState ngs = o.getBody(NodeGroupState.class); checkConvergenceAcrossPeers(host, ngs, parentOp); }).sendWith(host); }
@Test public void testSendWithOnServiceClient() throws Throwable { testSendWith((o) -> o.sendWith(this.host.getClient())); }
@Test public void testSendWithOnServiceClient() throws Throwable { testSendWith((o) -> o.sendWith(this.host.getClient())); }
@Override public void handleStart(Operation start) { Operation.createPost(UriUtils.buildUri(this.serverUri, EventStreamService.SELF_LINK)) .setBody(new ServiceDocument()) .setHeadersReceivedHandler(i -> { setStat(STAT_NAME_IS_CONNECTED, 1.0); start.complete(); }) .setServerSentEventHandler(i -> adjustStat(STAT_NAME_EVENT_COUNT, 1.0)) .setCompletion((o, e) -> setStat(STAT_NAME_IS_CONNECTED, 0.0)) .sendWith(this); } }
@Override public void handleStart(Operation start) { Operation.createPost(UriUtils.buildUri(this.serverUri, EventStreamService.SELF_LINK)) .setBody(new ServiceDocument()) .setHeadersReceivedHandler(i -> { setStat(STAT_NAME_IS_CONNECTED, 1.0); start.complete(); }) .setServerSentEventHandler(i -> adjustStat(STAT_NAME_EVENT_COUNT, 1.0)) .setCompletion((o, e) -> setStat(STAT_NAME_IS_CONNECTED, 0.0)) .sendWith(this); } }