public String getRequestId() { if (serviceTaskCallback == null) { return null; } return serviceTaskCallback.serviceSelfLink != null ? Service.getId(serviceTaskCallback.serviceSelfLink) : null; } }
/** * Issues a GET to service/stats and looks for {@link Service#STAT_NAME_AVAILABLE} * The request is issued on the node selected as owner, by the node selector co-located * with the service. The stat must have been modified after the most recent node group * change * * This method should be used only on replicated, owner selected factory services * * For xenon based applications, use {@link ServiceHost#registerForServiceAvailability(CompletionHandler, boolean, String...)} * with boolean set to true. */ public static void checkServiceAvailability(CompletionHandler ch, Service s) { checkServiceAvailability(ch, s.getHost(), s.getSelfLink(), s.getPeerNodeSelectorPath()); }
public URI getDocumentIndexServiceUri() { if (this.documentIndexService == null) { return null; } if (this.documentIndexServiceUri == null) { this.documentIndexServiceUri = this.documentIndexService.getUri(); } return this.documentIndexServiceUri; }
public static void authorizeOperationIfProjectService(Service requestorService, Operation op) { if (requestorService instanceof ProjectService || requestorService instanceof ProjectFactoryService) { requestorService.setAuthorizationContext(op, requestorService.getSystemAuthorizationContext()); } }
void markAsPendingDelete(Service service) { if (isServiceIndexed(service)) { this.pendingServiceDeletions.add(service.getSelfLink()); this.managementService.adjustStat( ServiceHostManagementService.STAT_NAME_PENDING_SERVICE_DELETION_COUNT, 1); } }
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)); } })); }
String nextPageLink) { URI nextPageUri = AuthUtils.buildAuthProviderHostUri(context.authContextService.getHost(), nextPageLink); Operation get = Operation.createGet(nextPageUri) .setConnectionSharing(true) context.authContextService.setAuthorizationContext(get, context.authContextService.getSystemAuthorizationContext()); context.authContextService.sendRequest(get);
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)); } })); }
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; }
/** * 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())); }
private void handleUiRequest(Operation op) { if (op.getAction() != Action.GET) { op.fail(new IllegalArgumentException("Action not supported")); return; } if (!this.parent.hasOption(ServiceOption.HTML_USER_INTERFACE)) { String servicePath = UriUtils.buildUriPath(ServiceUriPaths.UI_SERVICE_BASE_URL, op .getUri().getPath()); String defaultHtmlPath = UriUtils.buildUriPath(servicePath.substring(0, servicePath.length() - ServiceUriPaths.UI_PATH_SUFFIX.length()), ServiceUriPaths.UI_SERVICE_HOME); redirectGetToHtmlUiResource(op, defaultHtmlPath); return; } if (this.uiService == null) { this.uiService = new UiContentService() { }; this.uiService.setHost(this.parent.getHost()); } // simulate a full service deployed at the utility endpoint /service/ui String selfLink = this.parent.getSelfLink() + ServiceHost.SERVICE_URI_SUFFIX_UI; this.uiService.handleUiGet(selfLink, this.parent, op); }
private void logTransactionConflict(Operation request, ServiceDocument currentState) { this.service .getHost() .log(Level.INFO, "Transaction %s conflicts on service %s: operation: %s, current state transaction: %s", request.getTransactionId(), this.service.getSelfLink(), request.getAction(), currentState.documentTransactionId); }
private static DeferredResult<UserState> getUserState(Service requestorService, String principalId) { Operation getUserStateOp = Operation.createGet(requestorService, AuthUtil.buildUserServicePathFromPrincipalId(encode(principalId))); requestorService.setAuthorizationContext(getUserStateOp, requestorService.getSystemAuthorizationContext()); return requestorService.sendWithDeferredResult(getUserStateOp, UserState.class) .exceptionally((ex) -> { if (ex.getCause() instanceof ServiceNotFoundException) { return new UserState(); } return null; }); }
@Override public ServiceHost getHost() { return this.parent.getHost(); } }
@Override public DeferredResult<List<Principal>> getPrincipals(Operation op, String criteria) { String filterQuery = buildFilterBasedOnCriteria(criteria); URI uri = UriUtils.buildUri(service.getHost(), LocalPrincipalFactoryService.SELF_LINK); uri = UriUtils.extendUriWithQuery(uri, EXPAND_QUERY_KEY, Boolean.TRUE.toString()); uri = UriUtils.extendUriWithQuery(uri, FILTER_QUERY_KEY, filterQuery); Operation get = Operation.createGet(uri); service.setAuthorizationContext(get, service.getSystemAuthorizationContext()); return service.sendWithDeferredResult(get, ServiceDocumentQueryResult.class) .thenApply(q -> fromQueryResultToPrincipalList(q)) .thenCompose(principals -> { List<DeferredResult<Principal>> results = new ArrayList<>(); for (Principal p : principals) { results.add(getAllGroupsForPrincipal(op, p.id) .thenApply(groups -> { p.groups = groups; return p; })); } return DeferredResult.allOf(results); }); }
private void doCheckPeriodicMaintenance(Service s) throws Throwable { // Start service Service service = this.host.startServiceAndWait(s, UUID.randomUUID().toString(), null); int expectedMaintCount = PERIODIC_MAINTENANCE_MAX; if (!s.hasOption(ServiceOption.PERIODIC_MAINTENANCE)) { this.host.log("Toggling %s on", ServiceOption.PERIODIC_MAINTENANCE); this.host.toggleServiceOptions(s.getUri(), EnumSet.of(ServiceOption.PERIODIC_MAINTENANCE), null); expectedMaintCount = 1; } this.host.log("waiting for maintenance stat increment, expecting %d repeats", expectedMaintCount); final int limit = expectedMaintCount; this.host.waitFor("maint. count incorrect", () -> { ServiceStat stat = service.getStat(STAT_NAME_HANDLE_PERIODIC_MAINTENANCE); if (stat.latestValue < limit) { return false; } return true; }); }
void clearTransactionalCachedServiceState(Service s, String transactionId) { this.serviceResourceTracker.clearTransactionalCachedServiceState(s.getSelfLink(), transactionId); }
@Override public void sendRequest(Operation op) { this.parent.sendRequest(op); }
@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(); })); }
/** * Returns value indicating whether the request targets the service itself, * or, if ServiceOption.URI_NAMESPACE_OWNER is set, and does not match the self link, * targets portion the name space */ public static boolean isForServiceNamespace(Service s, Operation op) { return s.hasOption(ServiceOption.URI_NAMESPACE_OWNER) && !op.getUri().getPath().equals(s.getSelfLink()); }