private boolean processQueryResultsForOwnerSelection(String json, ServiceDocument state, String nodeSelectorPath) { String documentSelfLink; if (state == null) { documentSelfLink = Utils.fromJson(json, ServiceDocument.class).documentSelfLink; } else { documentSelfLink = state.documentSelfLink; } // when node-selector is not specified via query, use the one for index-service which may be // null if (nodeSelectorPath == null) { nodeSelectorPath = this.service.getPeerNodeSelectorPath(); } SelectOwnerResponse ownerResponse = this.host.findOwnerNode(nodeSelectorPath, documentSelfLink); // omit the result if the documentOwner is not the same as the local owner return ownerResponse != null && ownerResponse.isLocalHostOwner; }
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()); }
/** * Construct common data in {@link ServiceConfiguration}. */ public static <T extends ServiceConfiguration> T buildServiceConfig(T config, Service service) { ServiceDocumentDescription desc = service.getHost().buildDocumentDescription(service); config.options = service.getOptions(); config.maintenanceIntervalMicros = service.getMaintenanceIntervalMicros(); config.versionRetentionLimit = desc.versionRetentionLimit; config.versionRetentionFloor = desc.versionRetentionFloor; config.peerNodeSelectorPath = service.getPeerNodeSelectorPath(); config.documentIndexPath = service.getDocumentIndexPath(); return config; } }
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); } }
continue; String selectorPath = s.getPeerNodeSelectorPath(); Long selectorSynchTime = this.synchronizationTimes.get(selectorPath); if (selectorSynchTime == null) { this.host.log(Level.FINE, "Service %s started at %d, last synch at %d", link, lastSynchTime, selectorSynchTime); selectorPathsToSynch.add(s.getPeerNodeSelectorPath());
private void selectAndForwardRequestToOwner(Service s, String path, Operation op, Service parent, OperationProcessingContext context) { String nodeSelectorPath = parent != null ? parent.getPeerNodeSelectorPath() : s.getPeerNodeSelectorPath(); ServiceHost host = context.getHost(); CompletionHandler ch = (o, e) -> { if (e != null) { host.log(Level.SEVERE, "Owner selection failed for service %s, op %d. Error: %s", op .getUri().getPath(), op.getId(), e.toString()); context.resumeProcessingRequest(op, FilterReturnCode.FAILED_STOP_PROCESSING, e); op.setRetryCount(0).fail(e); return; } SelectOwnerResponse rsp = o.getBody(SelectOwnerResponse.class); if (rsp.isLocalHostOwner) { context.resumeProcessingRequest(op, FilterReturnCode.CONTINUE_PROCESSING, null); } else { forwardRequestToOwner(op, rsp, context); } }; Operation selectOwnerOp = Operation .createPost(null) .setExpiration(op.getExpirationMicrosUtc()) .setCompletion(ch); host.selectOwner(nodeSelectorPath, path, selectOwnerOp); }
toggleOption(ServiceOption.REPLICATION, true); if (!ServiceUriPaths.DEFAULT_NODE_SELECTOR.equals(childService .getPeerNodeSelectorPath())) { this.nodeSelectorLink = childService.getPeerNodeSelectorPath(); } else if (!ServiceUriPaths.DEFAULT_NODE_SELECTOR.equals(this.nodeSelectorLink)) { childService.setPeerNodeSelectorPath(this.nodeSelectorLink);
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); }
String serviceSelectorPath = s.getPeerNodeSelectorPath(); if (!nodeSelectorPath.equals(serviceSelectorPath)) { continue;
void failWithNotFoundOrSynchronize(Service parent, String path, Operation op) { if (parent.getPeerNodeSelectorPath().equals(ServiceUriPaths.DEFAULT_1X_NODE_SELECTOR)) { Operation.failServiceNotFound(op); return;
.setCompletion(c); this.host.selectOwner(s.getPeerNodeSelectorPath(), s.getSelfLink(), selectOwnerOp);
UriUtils.buildUri(this.host, s.getPeerNodeSelectorPath()), ServiceUriPaths.SERVICE_URI_SUFFIX_SYNCHRONIZATION); Operation synchPost = Operation
@Test public void testBuildServiceConfig() { Service exampleService = new ExampleService(); exampleService.setHost(VerificationHost.create()); ServiceConfiguration config = new ServiceConfiguration(); Utils.buildServiceConfig(config, exampleService); assertEquals(exampleService.getOptions(), config.options); assertEquals(exampleService.getMaintenanceIntervalMicros(), config.maintenanceIntervalMicros); assertEquals(ExampleServiceState.VERSION_RETENTION_LIMIT, config.versionRetentionLimit); assertEquals(ExampleServiceState.VERSION_RETENTION_FLOOR, config.versionRetentionFloor); assertEquals(exampleService.getPeerNodeSelectorPath(), config.peerNodeSelectorPath); assertEquals(exampleService.getDocumentIndexPath(), config.documentIndexPath); }
@Test public void testBuildServiceConfig() { Service exampleService = new ExampleService(); exampleService.setHost(VerificationHost.create()); ServiceConfiguration config = new ServiceConfiguration(); Utils.buildServiceConfig(config, exampleService); assertEquals(exampleService.getOptions(), config.options); assertEquals(exampleService.getMaintenanceIntervalMicros(), config.maintenanceIntervalMicros); assertEquals(ExampleServiceState.VERSION_RETENTION_LIMIT, config.versionRetentionLimit); assertEquals(ExampleServiceState.VERSION_RETENTION_FLOOR, config.versionRetentionFloor); assertEquals(exampleService.getPeerNodeSelectorPath(), config.peerNodeSelectorPath); assertEquals(exampleService.getDocumentIndexPath(), config.documentIndexPath); }
this.replicateRequest(s.getOptions(), clonedInitState, s.getPeerNodeSelectorPath(), originalLink, post); break;