protected OperationProcessingChain constructOpProcessingChain() { this.authorizationFilter = new AuthorizationFilter(); return OperationProcessingChain.create( new AuthenticationFilter(), this.authorizationFilter, new RequestRateLimitsFilter(), new ForwardRequestFilter(), new ServiceAvailabilityFilter()); }
private DeferredResult<Void> deleteRole(String roleLink) { Operation roleDeleteOp = Operation .createDelete(service, UriUtils.buildUriPath(RoleService.FACTORY_LINK, roleLink)); return service.sendWithDeferredResult(roleDeleteOp).thenAccept(ignore -> { }); }
private void performIOMaintenance(Operation post, long now, MaintenanceStage nextStage, long deadline) { try { this.operationTracker.performMaintenance(now); performMaintenanceStage(post, nextStage, deadline); } catch (Exception e) { log(Level.WARNING, "Exception: %s", Utils.toString(e)); performMaintenanceStage(post, nextStage, deadline); } }
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); }
@Override public void handleGet(Operation get) { ServiceDocument emptyDoc = new ServiceDocument(); // stop this service to simulate the case that op has returned but target service is not in attachedService. getHost().stopService(this); // return a doc that doesn't have documentKind get.setBody(Utils.toJson(emptyDoc)).complete(); } };
@Override public void handleGet(Operation get) { ServiceDocument doc = new ServiceDocument(); doc.documentOwner = this.getHost().getId(); doc.documentSelfLink = this.getSelfLink(); get.setBody(doc); get.complete(); } }
@Override public void handleStart(Operation startPost) { if (startPost.hasBody()) { DefaultHandlerState s = startPost.getBody(DefaultHandlerState.class); logFine("Initial state is %s", Utils.toJsonHtml(s)); } startPost.complete(); } }
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); }
@Override public void handlePut(Operation op) { ServiceDocument body = new ServiceDocument(); body.documentSelfLink = getSelfLink(); op.setBody(body); validateAndComplete(op); }
private void handleStopCompletion(Operation op) { if (checkServiceStopped(op, true)) { return; } getHost().stopService(this); op.complete(); }
/** * Stops the service */ protected void handleStopCompletion(Operation op) { getHost().stopService(this); op.complete(); }
private void setExpiration(Operation op) { if (op.getExpirationMicrosUtc() != 0) { return; } long expMicros = this.host != null ? this.host.getOperationTimeoutMicros() : ServiceHostState.DEFAULT_OPERATION_TIMEOUT_MICROS; op.setExpiration(Utils.fromNowMicrosUtc(expMicros)); }
private void associateAuthorizationContext(Service service, Operation op, String token) { Claims claims = getClaims(); AuthorizationContext.Builder ab = AuthorizationContext.Builder.create(); ab.setClaims(claims); ab.setToken(token); ab.setPropagateToClient(true); // associate resulting authorization context with operation. service.setAuthorizationContext(op, ab.getResult()); }
@Override public void handleRequest(Operation op) { if (Action.PUT == op.getAction()) { handleOperationValidationException(op); return; } else if (Action.PATCH == op.getAction()) { handleOperationFail(op); return; } super.handleRequest(op); } }
@Override public FilterReturnCode processRequest(Operation op, OperationProcessingContext context) { context.setSuspendConsumer(o -> { this.service.getHost().run(() -> { this.service.handleRequest(op, OperationProcessingStage.EXECUTING_SERVICE_HANDLER); }); }); return FilterReturnCode.SUSPEND_PROCESSING; } }
@RouteDocumentation(description = "Read the service document") public void handleGet(Operation get) { if (!hasPendingTransactions()) { handleGetSimple(get); return; } handleGetWithinTransaction(this, get, this::handleGetSimple, this::failRequest, getHost().getSystemAuthorizationContext()); }
@Override public void handleStop(Operation op) { if (!ServiceHost.isServiceStop(op)) { logWarning("Abrupt stop of factory %s", this.getSelfLink()); } super.handleStop(op); }
@Override public void handleGet(Operation get) { ServiceDocument doc = new ServiceDocument(); doc.documentOwner = this.getHost().getId(); doc.documentSelfLink = this.getSelfLink(); get.setBody(doc); get.complete(); } }
@Override public void handlePut(Operation op) { ServiceDocument body = new ServiceDocument(); body.documentSelfLink = getSelfLink(); op.setBody(body); validateAndComplete(op); }
@Override public FilterReturnCode processRequest(Operation op, OperationProcessingContext context) { context.setSuspendConsumer(o -> { this.service.getHost().run(() -> { this.service.handleRequest(op, OperationProcessingStage.EXECUTING_SERVICE_HANDLER); }); }); return FilterReturnCode.SUSPEND_PROCESSING; } }