void clearTransactionalCachedServiceState(Service s, String transactionId) { this.serviceResourceTracker.clearTransactionalCachedServiceState(s.getSelfLink(), transactionId); }
/** * 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()); }
private String buildLogTransactionUpdateMsg(Operation request, ServiceDocument currentState) { return String.format( "Transaction %s set on service %s: operation: %s, previous transaction: %s", request.getTransactionId(), this.service.getSelfLink(), request.getAction(), currentState.documentTransactionId); }
void markAsPendingDelete(Service service) { if (isServiceIndexed(service)) { this.pendingServiceDeletions.add(service.getSelfLink()); this.managementService.adjustStat( ServiceHostManagementService.STAT_NAME_PENDING_SERVICE_DELETION_COUNT, 1); } }
void unmarkAsPendingDelete(Service service) { if (isServiceIndexed(service)) { this.pendingServiceDeletions.remove(service.getSelfLink()); this.managementService.adjustStat( ServiceHostManagementService.STAT_NAME_PENDING_SERVICE_DELETION_COUNT, -1); } }
/** * Builds an URI to the subject of the claims object. * Default behavior treats {@link Claims#getSubject()} as a selfLink and is * used by the built-in {@link com.vmware.xenon.services.common.authn.BasicAuthenticationService}. * This can be customized using {@link #registerUserLinkBuilder(String, Function)} to register * a global link builder. * * @param host * @param claims * @return */ public static URI buildUserUriFromClaims(ServiceHost host, Claims claims) { String authnServiceLink = host.getAuthenticationService().getSelfLink(); String userLink = claims.getSubject(); Function<Claims, String> func = URI_BUILDERS.get(authnServiceLink); if (func != null) { userLink = func.apply(claims); } return buildAuthProviderHostUri(host, userLink); }
public void checkReplicatedServiceAvailable(CompletionHandler ch, String servicePath, String nodeSelectorPath) { Service s = this.findService(servicePath, true); if (s == null) { ch.handle(null, new IllegalStateException("service not found")); return; } String peerNodeSelectorPath = s.getPeerNodeSelectorPath(); if (peerNodeSelectorPath != null && !peerNodeSelectorPath.equals(nodeSelectorPath)) { nodeSelectorPath = peerNodeSelectorPath; } NodeGroupUtils.checkServiceAvailability(ch, s.getHost(), s.getSelfLink(), nodeSelectorPath); }
/** * 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()); }
private boolean serviceActive(long lastAccessTime, Service s, long now) { long cacheClearDelayMicros = s.getCacheClearDelayMicros(); if (ServiceHost.isServiceImmutable(s)) { cacheClearDelayMicros = 0; } boolean active = (cacheClearDelayMicros + lastAccessTime) > now; if (!active) { this.host.log(Level.FINE, "Considering stopping service %s, isOwner: %b, because it was inactive for %d seconds", s.getSelfLink(), this.host.isDocumentOwner(s), TimeUnit.MICROSECONDS.toSeconds(now - lastAccessTime)); } return active; }
public void clearCachedServiceState(Service s, Operation op) { String servicePath = s.getSelfLink(); if (!isTransactional(op)) { AttachedServiceInfo serviceInfo = this.attachedServices.get(servicePath); if (serviceInfo != null) { synchronized (serviceInfo) { serviceInfo.cachedState = null; serviceInfo.lastAccessTime = 0; } } updateCacheClearStats(); return; } clearTransactionalCachedServiceState(servicePath, op.getTransactionId()); }
private ServiceStats populateDocumentProperties(ServiceStats stats) { ServiceStats clone = new ServiceStats(); // sort entries by key (natural ordering) clone.entries = new TreeMap<>(stats.entries); clone.documentUpdateTimeMicros = stats.documentUpdateTimeMicros; clone.documentSelfLink = UriUtils.buildUriPath(this.parent.getSelfLink(), ServiceHost.SERVICE_URI_SUFFIX_STATS); clone.documentOwner = getHost().getId(); clone.documentKind = Utils.buildKind(ServiceStats.class); return clone; }
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); }
public NodeSelectorReplicationService(Service parent) { this.parent = parent; super.setHost(parent.getHost()); super.setSelfLink(UriUtils.buildUriPath(parent.getSelfLink(), ServiceHost.SERVICE_URI_SUFFIX_REPLICATION)); if (parent.getHost().getLocation() != null) { this.nodeCountPerLocation = new ConcurrentHashMap<>(); this.locationPerNodeURI = new ConcurrentHashMap<>(); } super.setProcessingStage(ProcessingStage.AVAILABLE); }
void cacheServiceState(Service s, ServiceDocument st, Operation op) { if (op != null && op.hasBody()) { Object rsp = op.getBodyRaw(); // if the response body is of type Document set its common // properties to that of the service state if (rsp.getClass().equals(st.getClass())) { ServiceDocument r = (ServiceDocument) rsp; st.copyTo(r); } } if (op != null && op.getAction() == Action.DELETE) { return; } if (st != null && st.documentKind == null) { log(Level.WARNING, "documentKind is null for %s", s.getSelfLink()); st.documentKind = Utils.buildKind(s.getStateType()); } this.serviceResourceTracker.updateCachedServiceState(s, st, op); }
private static void registerRoutes(RequestRouter router, Service xenonService, List<MethodInfo> httpMethods) { httpMethods.forEach(methodInfo -> { String path = buildUriPath(xenonService.getSelfLink(), methodInfo.getUriPath()); Predicate<Operation> predicate = newUriMatcher(path); RoutingOperationHandler routingOperationHandler = new RoutingOperationHandler(path, methodInfo, xenonService); routingOperationHandler.init(); router.register(methodInfo.getAction(), predicate, routingOperationHandler, "JaxRs annotation based Router"); log.info("Registered {} on {} to {}", methodInfo.getAction(), path, methodInfo.getName()); }); }
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 stopServiceAndClearFromCache(Service s, ServiceDocument state) { // Issue DELETE to stop the service and clear it from cache Operation deleteExp = Operation.createDelete(this.host, s.getSelfLink()) .setBody(state) .disableFailureLogging(true) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_NO_INDEX_UPDATE) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_NO_FORWARDING) .setReferer(this.host.getUri()); this.host.sendRequest(deleteExp); }
protected void stopService(Service s) throws Throwable { if (s == null || s.getSelfLink() == null || s.getSelfLink().isEmpty()) { return; } TestContext ctx = testCreate(1); Operation deleteOp = Operation.createDelete(UriUtils.buildUri(host, s.getSelfLink())) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_NO_INDEX_UPDATE) .setReplicationDisabled(true) .setCompletion(ctx.getCompletion()) .setReferer(host.getUri()); host.send(deleteOp); ctx.await(); }
static void checkAndUpdateDocumentOwnership(ServiceHost host, Service service, long expirationTimeMicrosUtc, CompletionHandler ch) { Operation selectOwnerOp = Operation.createPost(null) .setExpiration(expirationTimeMicrosUtc); CompletionHandler c = (o, e) -> { if (e != null) { ch.handle(selectOwnerOp, e); return; } SelectOwnerResponse rsp = o.getBody(SelectOwnerResponse.class); service.toggleOption(ServiceOption.DOCUMENT_OWNER, rsp.isLocalHostOwner); ch.handle(selectOwnerOp, null); }; selectOwnerOp.setCompletion(c); host.selectOwner(service.getPeerNodeSelectorPath(), service.getSelfLink(), selectOwnerOp); }
@Ignore("https://jira.eng.vmware.com/browse/VRXEN-65") @Test public void testSendWithDeferredResultWithNoResponseBody() throws Throwable { MinimalTestServiceState initialState = this.host.buildMinimalTestState(10); Service service = this.host.doThroughputServiceStart( 1, MinimalTestService.class, initialState, EnumSet.noneOf(Service.ServiceOption.class), null).get(0); // patch with same state to receive status NOT MODIFIED(304) and empty body MinimalTestServiceState patchState = new MinimalTestServiceState(); patchState.documentSelfLink = service.getSelfLink(); patchState.id = initialState.id; this.host.testStart(1); DeferredResult<MinimalTestServiceState> deferredResult = this.host .sendWithDeferredResult( Operation .createPatch(this.host, patchState.documentSelfLink) .setBodyNoCloning(patchState), MinimalTestServiceState.class) .whenComplete(this.host.getCompletionDeferred()); this.host.testWait(); Assert.assertNull(deferredResult.getNow(new MinimalTestServiceState())); }