private Function<? super List<Object>, Object> packAndReturnResults(Operation get, ServiceDocumentQueryResult result) { return a -> { result.documentOwner = this.getHost().getId(); result.documentCount = (long) result.documents.size(); result.documentLinks = new ArrayList<>(result.documents.keySet()); Collections.sort(result.documentLinks); get.setBodyNoCloning(result); get.complete(); return null; }; }
private void log(Operation op, OperationProcessingContext context, String msg, Level logLevel) { String hostId = context.host != null ? context.host.getId() : ""; String path = op.getUri() != null ? op.getUri().getPath() : ""; Filter filter = this.filters.get(context.currentFilterPosition); String filterName = filter != null ? filter.getClass().getSimpleName() : ""; String logMsg = String.format("(host: %s, op %d %s %s) filter %s: %s", hostId, op.getId(), op.getAction(), path, filterName, msg); Level level = logLevel != null ? logLevel : Level.INFO; Utils.log(getClass(), op.getUri().getPath(), level, logMsg); } }
public boolean removeHost(String hostId) { return this.hosts.removeIf(host -> host.getId().equals(hostId)); }
public boolean removeHost(String hostId) { return this.hosts.removeIf(host -> host.getId().equals(hostId)); }
/** * Issues a convergence request to the node group service on all peers and returns success * if all nodes confirm that they are converged (in terms of last membership update). * * It is expected the supplied host is listed as a peer in node group state */ public static void checkConvergence(ServiceHost host, NodeGroupState ngs, Operation parentOp) { NodeState self = ngs.nodes.get(host.getId()); if (self == null) { parentOp.fail(new IllegalStateException("Self node is required")); return; } if (self.membershipQuorum == 1 && ngs.nodes.size() == 1) { parentOp.complete(); return; } checkConvergenceAcrossPeers(host, ngs, parentOp); }
public Optional<ServiceHost> getHost(String hostId) { return this.hosts.stream().filter(h -> h.getId().equals(hostId)).findAny(); }
public Optional<ServiceHost> getHost(String hostId) { return this.hosts.stream().filter(h -> h.getId().equals(hostId)).findAny(); }
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 waitForOwnerChangeOnHost(ServiceHost host, String oldOwner, String serviceLink) throws Throwable { String error = String.format("Failed waiting for ownership change on host %s", host.getId()); waitFor(error, () -> { return !getDocument(host, serviceLink).documentOwner.equals(oldOwner); }); }
private void handleQueryTaskPatch(Operation op, QueryTask task) throws Exception { if (task.querySpec.options.contains(QueryOption.CONTINUOUS)) { if (handleContinuousQueryTaskPatch(op, task, task.querySpec)) { return; } // intentional fall through for tasks just starting and need to execute a query } ServiceDocumentQueryResult rsp = dao.queryDocuments(op, task); if (rsp == null) { rsp = new ServiceDocumentQueryResult(); rsp.queryTimeMicros = 0L; rsp.documentOwner = getHost().getId(); rsp.documentCount = 0L; if (task.querySpec.options.contains(QueryOption.EXPAND_CONTENT)) { rsp.documents = Collections.emptyMap(); } } op.setBodyNoCloning(rsp).complete(); }
public DockerDriverBase(ServiceHost serviceHost, DriverRegistry driverRegistry, ClosureDockerClientFactory dockerClientFactory) { this.serviceHost = serviceHost; this.driverRegistry = driverRegistry; this.dockerClientFactory = dockerClientFactory; this.trustCertificates = new AtomicReference<>(); this.subscriptionManager = new SubscriptionManager<>(serviceHost, serviceHost.getId() + getDockerImage(), SSL_TRUST_CONFIG_SUBSCRIBE_FOR_LINK, ConfigurationService.ConfigurationState.class, true); this.sslTrustQuery = new ServiceDocumentQuery<SslTrustCertificateState>(serviceHost, SslTrustCertificateState.class); queryHandler = new ClosureSslTrustQueryCompletionHandler(); subscribeForSslTrustCertNotifications(); loadSslTrustCertServices(); }
private void sendAvailableSelfPatch(NodeState local) { // mark self as available by issuing self PATCH NodeGroupState body = new NodeGroupState(); body.config = null; body.documentOwner = getHost().getId(); body.documentSelfLink = UriUtils.buildUriPath(getSelfLink(), body.documentOwner); local.status = NodeStatus.AVAILABLE; body.nodes.put(local.id, local); sendRequest(Operation.createPatch(getUri()).setBody( body)); }
public void stopHostAndPreserveState(ServiceHost host) { log("Stopping host %s", host.getUri()); // Do not delete the temporary directory with the lucene index. Notice that // we do not call host.tearDown(), which will delete disk state, we simply // stop the host and remove it from the peer node tracking tables host.stop(); this.peerHostIdToNodeState.remove(host.getId()); this.peerNodeGroups.remove(host.getUri()); this.localPeerHosts.remove(host.getUri()); }
public void stopHostAndPreserveState(ServiceHost host) { log("Stopping host %s", host.getUri()); // Do not delete the temporary directory with the lucene index. Notice that // we do not call host.tearDown(), which will delete disk state, we simply // stop the host and remove it from the peer node tracking tables host.stop(); this.peerHostIdToNodeState.remove(host.getId()); this.peerNodeGroups.remove(host.getUri()); this.localPeerHosts.remove(host.getUri()); }
public void waitForNodeUnavailable(String NodeGroupLink, Collection<? extends ServiceHost> peerHosts, ServiceHost stoppedHost) { this.waitFor("wait node unavailable timeout", () -> { for (ServiceHost h : peerHosts) { Operation op = Operation.createGet(UriUtils.buildUri(h, NodeGroupLink)); NodeGroupState ngs = this.sender.sendAndWait(op, NodeGroupState.class); NodeState ns = ngs.nodes.get(stoppedHost.getId()); if (!(ns == null || ns.status == NodeStatus.UNAVAILABLE)) { return false; } } return true; }); }
public void waitForNodeUnavailable(String NodeGroupLink, Collection<? extends ServiceHost> peerHosts, ServiceHost stoppedHost) { this.waitFor("wait node unavailable timeout", () -> { for (ServiceHost h : peerHosts) { Operation op = Operation.createGet(UriUtils.buildUri(h, NodeGroupLink)); NodeGroupState ngs = this.sender.sendAndWait(op, NodeGroupState.class); NodeState ns = ngs.nodes.get(stoppedHost.getId()); if (!(ns == null || ns.status == NodeStatus.UNAVAILABLE)) { return false; } } return true; }); }
@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 handleGet(Operation get) { ServiceDocument doc = new ServiceDocument(); doc.documentOwner = this.getHost().getId(); doc.documentSelfLink = this.getSelfLink(); get.setBody(doc); get.complete(); } }
static ServiceHost createAndStartHost(String... args) throws Throwable { ServiceHost host = ServiceHost.create(args); host.start(); host.startDefaultCoreServicesSynchronously(); host.startService(new RootNamespaceService()); host.startFactory(new UpgradeDemoEmployeeService()); // In order to support upgrading your Xenon application, you need to start the MigrationTaskService host.startFactory(new MigrationTaskService()); // Added for 'add-logging' project. host.log(Level.INFO, "Starting host [add-logging] with args these args:%n[id=%s]%n[port=%d]%n[sandbox=%s]%n[peerNodes=%s]", host.getId(), host.getPort(), host.getStorageSandbox(), host.getInitialPeerHosts()); return host; }
static ServiceHost createAndStartHost(String... args) throws Throwable { ServiceHost host = ServiceHost.create(args); host.start(); host.startDefaultCoreServicesSynchronously(); host.startService(new RootNamespaceService()); host.startFactory(new UpgradeDemoEmployeeService()); // In order to support upgrading your Xenon application, you need to start the MigrationTaskService host.startFactory(new MigrationTaskService()); host.startService(new UpgradeDemoEmployeeServiceTransformService()); host.log(Level.INFO, "Starting host [add-logging] with args these args:%n[id=%s]%n[port=%d]%n[sandbox=%s]%n[peerNodes=%s]", host.getId(), host.getPort(), host.getStorageSandbox(), host.getInitialPeerHosts()); return host; }