public static boolean isServiceIndexed(Service s) { return s.hasOption(ServiceOption.PERSISTENCE); }
public static boolean isServiceImmutable(Service s) { return s.hasOption(ServiceOption.IMMUTABLE); }
private static void populateServicesForHealthCheck(ServiceHost host, Service serviceInstance, Class<? extends Service> serviceClass, Set<String> servicesForHelathceck, boolean factory) { String factoryOrSelfLink = factory ? "FACTORY_LINK" : "SELF_LINK"; if (serviceInstance.hasOption(ServiceOption.REPLICATION)) { try { Field selfLink = serviceClass.getDeclaredField(factoryOrSelfLink); if (selfLink != null) { Object value = selfLink.get(serviceInstance); servicesForHelathceck.add(value.toString()); } } catch (NoSuchFieldException | IllegalAccessException | IllegalArgumentException e) { host.log(Level.SEVERE, "Exception while getting %s field for Service: %s :%s", factoryOrSelfLink, serviceClass, e); } } }
/** * 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()); }
/** * Initiates periodic maintenance for a service. Called on service start or when maintenance is * dynamically toggled on */ protected void scheduleServiceMaintenance(Service s) { if (!s.hasOption(ServiceOption.PERIODIC_MAINTENANCE)) { return; } this.serviceMaintTracker.schedule(s, Utils.getSystemNowMicrosUtc()); }
private static ServiceStat getOrCreateStat(Service service, String name, boolean createHistogram, Supplier<TimeSeriesStats> timeSeriesStatsSupplier) { if (!service.hasOption(ServiceOption.INSTRUMENTATION)) { return null; } ServiceStat stat = service.getStat(name); synchronized (stat) { if (stat.logHistogram == null && createHistogram) { stat.logHistogram = new ServiceStatLogHistogram(); } if (stat.timeSeriesStats == null && timeSeriesStatsSupplier != null) { stat.timeSeriesStats = timeSeriesStatsSupplier.get(); } } return stat; } }
/** * IllegalArgumentException if HTTPMethod is not mappable to Xenon Service.Action * * @param xenonService * @return */ public static RequestRouter parseJaxRsAnnotations(Service xenonService, Class<?>... interfaces) { if (!xenonService.hasOption(URI_NAMESPACE_OWNER)) { throw new IllegalArgumentException("URI_NAMESPACE_OWNER option needs to be enabled"); } List<MethodInfo> httpMethods = MethodInfoBuilder.parseServiceForJaxRsInfo(xenonService.getClass(), Collections.emptyMap()); RequestRouter router = new RequestRouter(); registerRoutes(router, xenonService, httpMethods); Stream.of(interfaces) .filter(Objects::nonNull) .filter(iFace -> iFace.isAssignableFrom(xenonService.getClass())) .forEach(iFace -> registerRoutes(router, xenonService, MethodInfoBuilder.parseInterfaceForJaxRsInfo(iFace, Collections.emptyMap()))); return router; }
/** * Infrastructure use only. Service authors should never call this method. * To stop a service issue a DELETE operation to its a URI. To only stop but not * mark as deleted in the index, use {@link Operation#PRAGMA_DIRECTIVE_NO_INDEX_UPDATE} * * Detaches service from service host, sets processing stage to stop. */ public void stopService(Service service) { if (service == null) { throw new IllegalArgumentException("service is required"); } String path = service.getSelfLink(); synchronized (this.state) { AttachedServiceInfo serviceInfo = this.attachedServices.remove(path); if (serviceInfo == null) { path = UriUtils.normalizeUriPath(path); serviceInfo = this.attachedServices.remove(path); } if (serviceInfo != null) { serviceInfo.service.setProcessingStage(ProcessingStage.STOPPED); if (serviceInfo.service.hasOption(ServiceOption.URI_NAMESPACE_OWNER)) { this.attachedNamespaceServices.remove(path); } } this.serviceSynchTracker.removeService(path); this.serviceResourceTracker.clearCachedServiceState(service, null); this.state.serviceCount--; } }
if (childService.hasOption(ServiceOption.REPLICATION)) { toggleOption(ServiceOption.REPLICATION, true); if (!ServiceUriPaths.DEFAULT_NODE_SELECTOR.equals(childService if (childService.hasOption(ServiceOption.PERSISTENCE)) { if (!ServiceUriPaths.CORE_DOCUMENT_INDEX.equals(childService .getDocumentIndexPath())) { if (childService.hasOption(ServiceOption.HTML_USER_INTERFACE)) { toggleOption(ServiceOption.HTML_USER_INTERFACE, true); if (childService.hasOption(ServiceOption.INSTRUMENTATION)) { toggleOption(ServiceOption.INSTRUMENTATION, true);
public void failRequestServiceAlreadyStarted(String path, Service s, Operation post) { ProcessingStage st = ProcessingStage.AVAILABLE; if (s != null) { st = s.getProcessingStage(); } Exception e; if (s != null && s.hasOption(ServiceOption.IMMUTABLE)) { // Even though we were able to detect violation of self-link uniqueness // in this case, generally we do not try to enforce uniqueness for // IMMUTABLE services in all cases. Instead it is the responsibility of // the caller to ensure uniqueness of self-links. e = new ServiceAlreadyStartedException(path, "Self-link uniqueness not guaranteed for Immutable Services."); log(Level.WARNING, e.getMessage()); } else { e = new ServiceAlreadyStartedException(path, st); } Operation.fail(post, Operation.STATUS_CODE_CONFLICT, ServiceErrorResponse.ERROR_CODE_SERVICE_ALREADY_EXISTS, e); }
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); }
public void setFactoriesAvailabilityIfOwner(boolean isAvailable) { for (String serviceLink : this.synchronizationRequiredServices.keySet()) { Service factoryService = this.host.findService(serviceLink, true); if (factoryService == null || !factoryService.hasOption(ServiceOption.FACTORY)) { this.host.log(Level.WARNING, "%s does not exist on host or is not a factory - cannot set availability", serviceLink); continue; } Utils.setFactoryAvailabilityIfOwner(this.host, serviceLink, factoryService.getPeerNodeSelectorPath(), isAvailable); } }
private void checkAndPopulateAuthzContext(Operation op, OperationProcessingContext context) { Service authzService = context.getHost().getAuthorizationService(); // We only authorize kryo requests for System users. if (Utils.isContentTypeKryoBinary(op.getContentType()) && !op.getAuthorizationContext().isSystemUser()) { String msg = String.format( "%s requests are only authorized for System Users", op.getContentType()); IllegalAccessException ex = new IllegalAccessException(msg); context.resumeProcessingRequest(op, OperationProcessingChain.FilterReturnCode.FAILED_STOP_PROCESSING, ex); ServiceErrorResponse response = new ServiceErrorResponse(); response.message = msg; response.statusCode = Operation.STATUS_CODE_UNAUTHORIZED; op.fail(Operation.STATUS_CODE_UNAUTHORIZED, ex, response); return; } long dispatchTime = System.nanoTime(); op.nestCompletion(o -> { if (authzService.hasOption(ServiceOption.INSTRUMENTATION)) { long dispatchDuration = System.nanoTime() - dispatchTime; AuthUtils.setAuthDurationStat(authzService, AuthorizationConstants.STAT_NAME_DURATION_MICROS_PREFIX, TimeUnit.NANOSECONDS.toMicros(dispatchDuration)); } context.resumeProcessingRequest(op, FilterReturnCode.CONTINUE_PROCESSING, null); }); // TODO: fix AuthenticationContextService and just send it a POST context.getHost().queueOrScheduleRequest(authzService, op); }
private void startUiFileContentServices(Service s) throws Exception { if (!s.hasOption(ServiceOption.HTML_USER_INTERFACE)) { return;
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; }); }
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; }); }
service.hasOption(ServiceOption.REPLICATION) && start.getAction() == Action.POST && !start.isFromReplication() &&
&& childService.hasOption(ServiceOption.PERSISTENCE)) { childService.sendRequest(TransactionServiceHelper.notifyTransactionCoordinatorOfNewServiceOp(this, childService, o).setCompletion((notifyOp, notifyFailure) -> {