@Override public ServiceDocument getDocumentTemplate() { ServiceDocument td = super.getDocumentTemplate(); // enable indexing of custom properties map. ServiceDocumentDescription.PropertyDescription pdCustomProperties = td.documentDescription.propertyDescriptions .get(AuthCredentialsServiceState.FIELD_NAME_CUSTOM_PROPERTIES); pdCustomProperties.indexingOptions = EnumSet .of(ServiceDocumentDescription.PropertyIndexingOption.EXPAND); AuthCredentialsServiceState template = (AuthCredentialsServiceState) td; return template; } }
public ContainerHostDataCollectionService() { super(ContainerHostDataCollectionState.class); super.toggleOption(ServiceOption.PERSISTENCE, true); super.toggleOption(ServiceOption.REPLICATION, true); super.toggleOption(ServiceOption.OWNER_SELECTION, true); super.toggleOption(ServiceOption.PERIODIC_MAINTENANCE, true); super.setMaintenanceIntervalMicros(MAINTENANCE_INTERVAL_MICROS); }
case DELETE: if (ServiceHost.isServiceStop(request)) { handleStop(request); } else { handleStop(request); }); handleDelete(request); handleGet(request); break; case PATCH: handlePatch(request); break; case POST: handlePost(request); break; case PUT: handlePut(request); break; case OPTIONS: handleOptions(request); break; default:
@Override public void setMaintenanceIntervalMicros(long micros) { if (micros < 0) { throw new IllegalArgumentException("micros must be positive"); } if (micros > 0 && micros < Service.MIN_MAINTENANCE_INTERVAL_MICROS) { logWarning("Maintenance interval %d is less than the minimum interval %d" + ", reducing to min interval", micros, Service.MIN_MAINTENANCE_INTERVAL_MICROS); micros = Service.MIN_MAINTENANCE_INTERVAL_MICROS; } allocateExtraContext(); this.context.extras.maintenanceInterval = micros; if (getHost() != null && getProcessingStage() == ProcessingStage.AVAILABLE && micros < getHost().getMaintenanceCheckIntervalMicros()) { getHost().scheduleServiceMaintenance(this); } }
private void handleStopCompletion(Operation op) { if (checkServiceStopped(op, true)) { return; } getHost().stopService(this); op.complete(); }
public TenantService() { super(TenantState.class); super.toggleOption(ServiceOption.PERSISTENCE, true); super.toggleOption(ServiceOption.REPLICATION, true); super.toggleOption(ServiceOption.OWNER_SELECTION, true); }
ResolutionRequest resolutionRequest = op.getBody(ResolutionRequest.class); Operation subscribeToCoordinator = Operation.createPost( UriUtils.buildSubscriptionUri(this.parent.getUri())) .setCompletion((o, e) -> { if (e != null) { .createPatch(this.parent.getUri()) .setBody(resolutionRequest) .setTransactionId(null) this.parent.sendRequest(operation); }).setReferer(this.parent.getUri()); this.parent.getHost().startSubscriptionService(subscribeToCoordinator, (notifyOp) -> { ResolutionRequest resolve = notifyOp.getBody(ResolutionRequest.class); notifyOp.complete(); this.parent.logInfo("Received notification: action=%s, resolution=%s", notifyOp.getAction(), resolve.resolutionKind); (resolve.resolutionKind.equals(ResolutionKind.ABORTED) && resolutionRequest.resolutionKind.equals(ResolutionKind.ABORT))) { this.parent.logInfo("Resolution of transaction %s is complete", this.parent.getSelfLink()); op.setBodyNoCloning(notifyOp.getBodyRaw()); op.setStatusCode(notifyOp.getStatusCode()); String errorMsg = String.format(
service.sendRequest(Operation .createDelete( service, notificationTaskLink) .setReferer(service.getUri()) .setCompletion( (delOp, delEx) -> { if (delEx != null) { service.logWarning(() -> String.format("Stopping subscriber failed" + " %s", Utils.toString(delEx))); return; service.getHost().stopSubscriptionService(deleteOp, UriUtils.buildPublicUri(service.getHost(), update.getUri().getPath())); service.sendRequest(Operation .createDelete( service, notificationTaskLink)
@Override public void handleDelete(Operation delete) { ContainerState currentState = getState(delete); super.handleDelete(delete); deleteContainerDescription(currentState, DELETE_DESCRIPTION_RETRY_COUNT); }
|| a == Action.DELETE || a == Action.POST) { stopped = queueUpdateRequestInternal(op, stopped); } else { if (a == Action.OPTIONS) { return false; } else if (hasOption(ServiceOption.CONCURRENT_GET_HANDLING)) { stopped = queueGetRequestInternal(op, stopped); if (stopped != 0 && !getHost().isStopping()) { logWarning("Service in stage %s, retrying request", this.context.processingStage); getHost().retryOnDemandLoadConflict(op, this); return true; if (checkServiceStopped(op, false)) { return true;
/** * Helper method to send a patch to the specified service * * @param service sevice to send the patch to * @param body patch body */ private static void sendPatch(StatefulService service, Object body) { Operation patch = Operation .createPatch(service.getUri()) .setBody(body) .setCompletion( (o, ex) -> { if (ex != null) { service.logWarning("Self patch failed: %s", Utils.toString(ex)); } }); service.sendRequest(patch); }
service.logFine("Skipping updating ports for container [%s].", oldContainerState.documentSelfLink); return; service.sendRequest(Operation.createGet(service, hostPortProfileLink) .setCompletion((o, e) -> { if (o.getStatusCode() == Operation.STATUS_CODE_NOT_FOUND || e instanceof CancellationException) { service.logWarning("Cannot find host port profile [%s]", hostPortProfileLink); return; service.logWarning("Failed retrieving HostPortProfileState: %s. %s", hostPortProfileLink, Utils.toString(e)); return; request.containerLink = oldContainerState.documentSelfLink; service.sendRequest( Operation.createPatch(service, profile.documentSelfLink) .setBody(request) .setCompletion((op, ex) -> { if (ex != null) { service.logWarning("Failed updating port allocation" + " for profile [%s] and container" + " [%s]. Error: [%s]",
public boolean queueRequest(Operation op) { if (checkServiceStopped(op, false)) { return true; getHost().retryOnDemandLoadConflict(op, this); return true; logWarning("Service in %s stage, cancelling operation", this.context.processingStage); op.fail(new CancellationException("Service is not available")); if (hasOption(Service.ServiceOption.INSTRUMENTATION)) { op.setEnqueueTime(System.nanoTime() / 1000); if (!hasOption(ServiceOption.CONCURRENT_UPDATE_HANDLING) && queueRequestInternal(op)) { return true;
if (!hasOption(ServiceOption.DOCUMENT_OWNER)) { long delta = latestState.documentUpdateTimeMicros - this.context.lastCommitTimeMicros; if (op.getAction() != Action.DELETE && delta < getHost().getMaintenanceIntervalMicros()) { return; URI u = getUri(); Operation commitOp = Operation .createPut(u) .setReferer(u) .setExpiration( Utils.fromNowMicrosUtc(getHost().getOperationTimeoutMicros())); commitOp.setCompletion((o, e) -> { processCompletionStageIndexing(op); }); getHost().replicateRequest(this.context.options, latestState, getPeerNodeSelectorPath(), getSelfLink(), commitOp); return; return; processCompletionStageIndexing(op);
Boolean.TRUE.toString()); service.sendRequest(Operation .createPatch(service, patch.documentSelfLink) .addPragmaDirective(Operation.PRAGMA_DIRECTIVE_QUEUE_FOR_SERVICE_AVAILABILITY) .setCompletion((o, e) -> { if (e != null) { service.logWarning("Failed to update ContainerDescription: %s." + " Error: %s", patch.documentSelfLink, Utils.toString(e)); return; service.logInfo("Discovered ContainerDescription: %s, was successfully" + " updated.", patch.documentSelfLink); service.sendRequest(Operation .createPatch(service, containerState.documentSelfLink) .setBody(patchState) .setCompletion((oo, ee) -> { if (ee != null) { service.logWarning("Failed to update ContainerState: %s." + " Error: %s", containerState.documentSelfLink, service.logInfo("Discovered ContainerState: %s, was" + " successfully updated.", containerState.documentSelfLink);
@Override @GET @Path(INSTANCE_PATH) @ApiOperation( value = "Get specific favorite image.", notes = "Retrieve a specific favorite image instance based on the provided id.", nickname = "getSingle", response = FavoriteImage.class) @ApiResponses(value = { @ApiResponse(code = Operation.STATUS_CODE_OK, message = "Successfully retrieved image."), @ApiResponse(code = Operation.STATUS_CODE_NOT_FOUND, message = "Image with specified id not in favorites.")}) @ApiImplicitParams({ @ApiImplicitParam( name = "id", value = "The id of the image", dataType = DATA_TYPE_STRING, paramType = PARAM_TYPE_PATH, required = true)}) public void handleGet(Operation get) { super.handleGet(get); }
s.removePendingTransaction(txRefLink); s.getHost().clearTransactionalCachedServiceState(s, UriUtils.getLastPathSegment(txRefLink)); QueryTask.Query selfLinkClause = new QueryTask.Query().setTermPropertyName( ServiceDocument.FIELD_NAME_SELF_LINK) .setTermMatchValue(s.getSelfLink()); selfLinkClause.occurance = QueryTask.Query.Occurance.MUST_OCCUR; q.query.addBooleanClause(selfLinkClause); QueryTask.QuerySpecification.QueryOption.INCLUDE_ALL_VERSIONS); QueryTask task = QueryTask.create(q).setDirect(true); URI uri = UriUtils.buildUri(s.getHost(), ServiceUriPaths.CORE_QUERY_TASKS); Operation startPost = Operation .createPost(uri) .setCompletion((o, f) -> unshadowQueryCompletion(s, st, o, f, request)); startPost.setAuthorizationContext(authContext); s.sendRequest(startPost); s.removePendingTransaction(txRefLink); s.getHost().clearTransactionalCachedServiceState(s, UriUtils.getLastPathSegment(txRefLink)); request.complete();
/** * Gets the cached ServiceDocumentDescription instance for the service state. */ public ServiceDocumentDescription getStateDescription() { return getHost().buildDocumentDescription(this); }
/** * Patch a service to failure after logging all errors * * @param service * Service to patch * @param tList * List of throwable objects */ public static void sendFailurePatch(StatefulService service, TaskServiceState taskState, Collection<Throwable> tList) { Throwable errorToPatch = null; for (Throwable t : tList) { errorToPatch = t; service.logWarning(() -> String.format("Operation failed: %s", Utils.toString(t))); } sendFailurePatch(service, taskState, errorToPatch); }
private void handleRequestUnhandledException(Operation request, boolean isCompletionNested, Throwable e) { if (Utils.isValidationError(e)) { logFine("Validation Error: %s", Utils.toString(e)); } else { logWarning("Uncaught exception: %s", e.toString()); // log stack trace in a new log messages in case out of memory prevents us from forming // the stack trace string logWarning("Exception trace: %s", Utils.toString(e)); } if (isCompletionNested) { request.fail(e); } else { handleRequestCompletion(request, e); } }