public static Operation createPatch(ServiceHost sender, String targetPath) { return createPatch(UriUtils.buildUri(sender, targetPath)); }
private void sendHostServiceRequest(Object body, URI adapterReference) { sendRequest(Operation.createPatch(adapterReference).setBody(body) .setCompletion((o, e) -> { if (e != null) { failTask(e); return; } })); }
private DeferredResult<Operation> patchContainerState(ContainerState cs) { Operation operation = Operation.createPatch(host, UriUtils.buildUriPath(cs.documentSelfLink)) .setBody(cs) .setReferer(host.getUri()) .setCompletion((o, ex) -> { if (ex != null) { logger.warning(String.format("Error patching container state [%s]. Error: [%s]", cs.documentSelfLink, ex.getMessage())); } }); return host.sendWithDeferredResult(operation); } }
private DeferredResult patchComputeState(String documentSelfLink, ComputeState computeState) { URI uri = UriUtils.buildUri(host, documentSelfLink); Operation op = Operation.createPatch(uri) .setBody(computeState) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { logger.warning(String.format("Failed to patch compute state: [%s]", Utils.toString(e))); return; } logger.info(String.format("Successfully patched compute state [%s]", documentSelfLink)); }); return host.sendWithDeferredResult(op); }
private void sendSelfPatch(SshCommandTaskState state, TaskStage stage, Map<String, String> commandResponse, Throwable t) { SshCommandTaskState patch = new SshCommandTaskState(); patch.taskInfo = new TaskState(); patch.taskInfo.stage = stage; patch.commandResponse = commandResponse; if (t != null) { patch.taskInfo.failure = Utils.toServiceErrorResponse(t); } Operation patchOperation = Operation.createPatch( UriUtils.buildUri(getHost(), state.documentSelfLink)).setBody( patch); sendRequest(patchOperation); }
private void listHostNetworks(NetworkListCallback body, Operation.CompletionHandler c) { AdapterRequest request = new AdapterRequest(); request.operationTypeId = ContainerHostOperationType.LIST_NETWORKS.id; request.serviceTaskCallback = ServiceTaskCallback.createEmpty(); request.resourceReference = UriUtils.buildUri(getHost(), body.containerHostLink); sendRequest(Operation .createPatch(body.hostAdapterReference) .setBodyNoCloning(request) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY) .setCompletion(c)); }
/** * Send ourselves a PATCH. The caller is responsible for creating the PATCH body */ protected void sendSelfPatch(T task) { Operation patch = Operation.createPatch(getUri()) .setBody(task); sendRequest(patch); }
private void updateVolumePowerState(ContainerVolumeState volumeState) { ContainerVolumeState patchState = new ContainerVolumeState(); patchState.powerState = PowerState.CONNECTED; sendRequest(Operation.createPatch(this, volumeState.documentSelfLink) .setBodyNoCloning(patchState) .setCompletion((o, e) -> { if (e != null) { logWarning("Could not update volume %s to state %s", volumeState.documentSelfLink, PowerState.CONNECTED); } })); }
private DeferredResult<Object> sendSynchronizationRequest(String factoryLink, String selectorPath, SynchronizationRequest synchRequest, Operation op) { DeferredResult<Object> factoryStatus = new DeferredResult<>(); URI nodeSelectorUri = UriUtils.buildUri(getHost(), selectorPath); NodeSelectorService.SelectAndForwardRequest req = new NodeSelectorService.SelectAndForwardRequest(); req.key = factoryLink; Operation selectorPost = Operation.createPost(nodeSelectorUri) .setReferer(getUri()) .setBodyNoCloning(req); // URI will be filled after factory owner is determined from the Node Selector. Operation factorySynchPost = Operation.createPatch(null) .setBody(synchRequest) .setReferer(getUri()); // Chain of operations executed in sequence to start factory's synchronization. DeferredResult .allOf(getNodeSelectorAvailability(selectorPost, factoryStatus)) .thenCompose(a -> getFactoryOwnerFromNodeSelector(selectorPost, factorySynchPost, factorySynchPost)) .thenAccept(a -> sendSynchronizationRequest(factoryLink, factorySynchPost, op)); return factoryStatus; }
private void sendAvailableSelfPatch(NodeState local) { // mark self as available by issuing self PATCH NodeGroupState body = new NodeGroupState(); body.config = null; body.documentOwner = getHost().getId(); body.documentSelfLink = UriUtils.buildUriPath(getSelfLink(), body.documentOwner); local.status = NodeStatus.AVAILABLE; body.nodes.put(local.id, local); sendRequest(Operation.createPatch(getUri()).setBody( body)); }
private void updateContainerHostInfo(String documentSelfLink) { URI uri = UriUtils.buildUri(getHost(), ContainerHostDataCollectionService.HOST_INFO_DATA_COLLECTION_LINK); ContainerHostDataCollectionState state = new ContainerHostDataCollectionState(); state.createOrUpdateHost = true; state.computeContainerHostLinks = Collections.singleton(documentSelfLink); sendRequest(Operation.createPatch(uri) .setBody(state) .setCompletion((o, ex) -> { if (ex != null) { logWarning("Failed to update host data collection: %s", ex.getMessage()); } })); }
private void sendHostServiceRequest(Object body, URI adapterReference) { sendRequest(Operation.createPatch(adapterReference).setBody(body) .setCompletion((o, e) -> { if (e != null) { failTask(e); return; } })); }
private void sendSelfPatch(SshCommandTaskState state, TaskStage stage, Map<String, String> commandResponse, Throwable t) { SshCommandTaskState patch = new SshCommandTaskState(); patch.taskInfo = new TaskState(); patch.taskInfo.stage = stage; patch.commandResponse = commandResponse; if (t != null) { patch.taskInfo.failure = Utils.toServiceErrorResponse(t); } Operation patchOperation = Operation.createPatch( UriUtils.buildUri(getHost(), state.documentSelfLink)).setBody( patch); sendRequest(patchOperation); }
private void listHostContainers(ContainerListCallback body, Operation.CompletionHandler c) { String containerHostLink = body.containerHostLink; AdapterRequest request = new AdapterRequest(); request.operationTypeId = ContainerHostOperationType.LIST_CONTAINERS.id; request.serviceTaskCallback = ServiceTaskCallback.createEmpty(); request.resourceReference = UriUtils.buildUri(getHost(), containerHostLink); sendRequest(Operation .createPatch(body.hostAdapterReference) .setBodyNoCloning(request) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY) .setCompletion(c)); }
public static Operation buildCommitRequest(ServiceHost host, String transactionId) { EndTransactionRequest body = new EndTransactionRequest(); body.transactionOutcome = EndTransactionRequest.TransactionOutcome.COMMIT; return Operation .createPatch(buildTransactionUri(host, transactionId)) .setBody(body); }
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 static void registerServiceForMigration(ServiceHost host, Set<String> services) { NodeMigrationService nodeMigration = new NodeMigrationService(); nodeMigration.services = services; host.sendRequest(Operation .createPatch(UriUtils.buildUri(host, NodeMigrationService.SELF_LINK)) .setBody(nodeMigration) .setReferer(host.getUri()) .setCompletion((o, e) -> { if (e != null) { host.log(Level.SEVERE, "Exception while register services for migration: %s", e); } })); }
/** * Sends the Stats request to the Stats adapter */ private void sendStatsRequestToAdapter(SingleResourceStatsCollectionTaskState currentState, URI patchUri, Object patchBody) { sendRequest(Operation.createPatch(patchUri) .setBody(patchBody) .setCompletion((patchOp, patchEx) -> { if (patchEx != null) { TaskUtils.sendFailurePatch(this, currentState, patchEx); } })); }
public void updateServiceOptions(Collection<String> selfLinks, ServiceConfigUpdateRequest cfgBody) { List<Operation> ops = new ArrayList<>(); for (String link : selfLinks) { URI bUri = UriUtils.buildUri(getUri(), link, ServiceHost.SERVICE_URI_SUFFIX_CONFIG); ops.add(Operation.createPatch(bUri).setBody(cfgBody)); } this.sender.sendAndWait(ops); }
private void forwardToLucene(QueryTask task, Operation get) { try { Operation localPatch = Operation.createPatch(UriUtils.buildUri(getHost(), task.indexLink)) .setBodyNoCloning(task) .setCompletion((o, e) -> { if (e == null) { task.results = (ServiceDocumentQueryResult) o.getBodyRaw(); } handleQueryCompletion(task, e, get); }); sendRequest(localPatch); } catch (Exception e) { handleQueryCompletion(task, e, get); } }