@Override public void sendRequest(Operation op) { this.parent.sendRequest(op); }
/** * Retrieves the property value from the configuration properties service. */ public static void getConfigProperty(Service service, String propName, Consumer<String> callback) { service.sendRequest(Operation .createGet(service, UriUtils.buildUriPath(CONFIG_PROPS, propName)) .setCompletion((res, ex) -> { if (ex != null) { logger.warning(String.format("Unable to get config property: %s", ex.getMessage())); callback.accept(null); return; } ConfigurationState body = res.getBody(ConfigurationState.class); callback.accept(body.value); })); }
public void sendResponse(Service sender, ServiceTaskCallbackResponse<E> response) { sender.sendRequest(Operation.createPatch(this.serviceURI).setBody(response)); }
public void sendResponse(Service sender, ServiceTaskCallbackResponse<E> response) { sender.sendRequest(Operation.createPatch(this.serviceURI).setBody(response)); }
private static void fetchSslTrust(Service sender, HostSpec hostSpec, Operation op, String sslTrustLink, Runnable callbackFunction) { logger.fine("Fetching ssl trust: " + sslTrustLink); Operation fetchSslTrust = Operation.createGet(sender, sslTrustLink) .setCompletion((o, ex) -> { if (ex != null) { logger.severe(ex.getMessage()); failOperation(hostSpec, op, ex); return; } hostSpec.sslTrust = o.getBody(SslTrustCertificateState.class); callbackFunction.run(); }); sender.sendRequest(fetchSslTrust); }
/** * Sends {@code DELETE} request to service {@code s}. Result is ignored. */ public static void sendSelfDelete(Service s) { s.sendRequest(Operation.createDelete(s.getUri()).setBody(new ServiceDocument())); }
public static void notifyCompositionComponent(Service service, String compositeComponentLink, Action action) { if (compositeComponentLink == null || compositeComponentLink.isEmpty()) { return; } service.sendRequest(Operation.createGet(service, compositeComponentLink) .setCompletion((o, e) -> { if (o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) { Utils.log(service.getClass(), service.getUri().toString(), Level.FINE, "CompositeComponent not found %s", compositeComponentLink); return; } if (e != null) { Utils.log(service.getClass(), service.getUri().toString(), Level.WARNING, "Can't find composite component. Error: %s", Utils.toString(e)); return; } notify(service, compositeComponentLink, action); })); }
public static void notifyCompositionComponent(Service service, ResourceState state, String compositeComponentLink, Action action) { if (compositeComponentLink == null || compositeComponentLink.isEmpty()) { return; } service.sendRequest(Operation.createGet(service, compositeComponentLink) .setCompletion((o, e) -> { if (o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND) { Utils.log(service.getClass(), service.getUri().toString(), Level.FINE, "CompositeComponent not found %s", compositeComponentLink); return; } if (e != null) { Utils.log(service.getClass(), service.getUri().toString(), Level.WARNING, "Can't find composite component. Error: %s", Utils.toString(e)); return; } notify(service, state, compositeComponentLink, action); })); }
private static void notify(Service service, ResourceState state, String compositeComponentLink, Action action) { CompositeComponent body = new CompositeComponent(); body.documentSelfLink = compositeComponentLink; body.componentLinks = new ArrayList<>(1); body.componentLinks.add(state.documentSelfLink); URI uri = UriUtils.buildUri(service.getHost(), compositeComponentLink); if (Action.DELETE == action) { uri = UriUtils.extendUriWithQuery(uri, UriUtils.URI_PARAM_INCLUDE_DELETED, Boolean.TRUE.toString()); } service.sendRequest(Operation.createPatch(uri) .setBody(body) .setCompletion((op, ex) -> { if (ex != null) { Utils.log(service.getClass(), service.getUri().toString(), Level.WARNING, "Error notifying CompositeContainer: %s. Exception: %s", compositeComponentLink, ex instanceof CancellationException ? "CancellationException" : Utils.toString(ex)); } })); }
private static void notify(Service service, String compositeComponentLink, Action action) { CompositeComponent body = new CompositeComponent(); body.documentSelfLink = compositeComponentLink; body.componentLinks = new ArrayList<>(1); body.componentLinks.add(service.getSelfLink()); URI uri = UriUtils.buildUri(service.getHost(), compositeComponentLink); if (Action.DELETE == action) { uri = UriUtils.extendUriWithQuery(uri, UriUtils.URI_PARAM_INCLUDE_DELETED, Boolean.TRUE.toString()); } service.sendRequest(Operation.createPatch(uri) .setBody(body) .setCompletion((op, ex) -> { if (ex != null) { Utils.log(service.getClass(), service.getUri().toString(), Level.WARNING, "Error notifying CompositeContainer: %s. Exception: %s", compositeComponentLink, ex instanceof CancellationException ? "CancellationException" : Utils.toString(ex)); } })); }
private void notifySubscriber(long now, Operation clone, ServiceSubscriber s) { synchronized (s) { if (s.failedNotificationCount != null) { // indicate to the subscriber that they missed notifications and should retrieve latest state clone.addPragmaDirective(Operation.PRAGMA_DIRECTIVE_SKIPPED_NOTIFICATIONS); } } CompletionHandler c = (o, ex) -> { s.documentUpdateTimeMicros = Utils.getNowMicrosUtc(); synchronized (s) { if (ex != null) { if (s.failedNotificationCount == null) { s.failedNotificationCount = 0L; s.initialFailedNotificationTimeMicros = now; } s.failedNotificationCount++; return; } if (s.failedNotificationCount != null) { // the subscriber is available again. s.failedNotificationCount = null; s.initialFailedNotificationTimeMicros = null; } } }; this.parent.sendRequest(clone.setUri(s.reference).setCompletion(c)); }
public static DeferredResult<Void> freeProperty(Service service, String propertiesId, String propertyName) { assertNotNull(service, "service"); assertNotNullOrEmpty(propertiesId, "propertiesId"); assertNotNullOrEmpty(propertyName, "propertyName"); UniquePropertiesRequest request = new UniquePropertiesRequest(); request.toRemove = Collections.singletonList(propertyName); String uriPath = UriUtils.buildUriPath(UniquePropertiesService.FACTORY_LINK, propertiesId); DeferredResult<Void> result = new DeferredResult<>(); Operation patch = Operation.createPatch(service, uriPath) .setBody(request) .setCompletion((o, ex) -> { if (ex != null) { result.fail(ex); return; } result.complete(null); }); service.sendRequest(patch); return result; }
}); service.sendRequest(patch); return result;
}); sender.sendRequest(forwardOp);
}); service.sendRequest(patch); return result;
@Override public void doLogout(Operation op) { AuthenticationRequest logout = new AuthenticationRequest(); logout.requestType = AuthenticationRequestType.LOGOUT; service.sendRequest(Operation.createPost(service, BasicAuthenticationService.SELF_LINK) .setBody(logout) .forceRemote() .setCompletion((o, e) -> { if (e != null) { service.getHost().log(Level.SEVERE, "Logout failed: %s", Utils.toString(e)); op.fail(e); return; } // clears auth token and cookie AuthUtils.cleanupSessionData(op); op.complete(); })); }
@Override public FilterReturnCode processRequest(Operation op, OperationProcessingContext context) { if (op.getAction() != Action.DELETE) { return FilterReturnCode.CONTINUE_PROCESSING; } context.setSuspendConsumer(o -> { s.sendRequest(Operation.createGet(s, TestFailingStatefulService.FACTORY_LINK) .setCompletion((oo, e) -> { context.resumeProcessingRequest(op, FilterReturnCode.FAILED_STOP_PROCESSING, e); op.fail(ex); })); }); return FilterReturnCode.SUSPEND_PROCESSING; } });
@Override public FilterReturnCode processRequest(Operation op, OperationProcessingContext context) { if (op.getAction() != Action.DELETE) { return FilterReturnCode.CONTINUE_PROCESSING; } context.setSuspendConsumer(o -> { s.sendRequest(Operation.createGet(s, TestFailingStatefulService.FACTORY_LINK) .setCompletion((oo, e) -> { context.resumeProcessingRequest(op, FilterReturnCode.FAILED_STOP_PROCESSING, e); op.fail(ex); })); }); return FilterReturnCode.SUSPEND_PROCESSING; } });
public static DeferredResult<Void> handleDelete(Service service, Operation op) { DeferredResult<Void> dr = new DeferredResult<>(); service.sendRequest(Operation.createPost(service, ServiceUriPaths.CORE_QUERY_TASKS) .setBody(QueryUtil.addCountOption(QueryUtil.buildPropertyQuery(ComputeState.class, QuerySpecification.buildCompositeFieldName( ComputeState.FIELD_NAME_CUSTOM_PROPERTIES, ComputeConstants.HOST_AUTH_CREDENTIALS_PROP_NAME), service.getSelfLink()))) .setCompletion((o, e) -> { if (e != null) { service.getHost().log(Level.WARNING, Utils.toString(e)); dr.fail(e); } ServiceDocumentQueryResult result = o.getBody(QueryTask.class).results; if (result.documentCount != 0) { op.fail(new LocalizableValidationException(CREDENTIALS_IN_USE_MESSAGE, CREDENTIALS_IN_USE_MESSAGE_CODE)); } dr.complete(null); })); return dr; }
childService.sendRequest(TransactionServiceHelper.notifyTransactionCoordinatorOfNewServiceOp(this, childService, o).setCompletion((notifyOp, notifyFailure) -> { if (notifyFailure != null) {