use of com.facebook.presto.client.NodeVersion in project urban-eureka by errir503.
the class TestDiscoveryNodeManager method setup.
@BeforeMethod
public void setup() {
testHttpClient = new TestingHttpClient(input -> new TestingResponse(OK, ArrayListMultimap.create(), ACTIVE.name().getBytes()));
expectedVersion = new NodeVersion("1");
coordinator = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.8"), expectedVersion, true);
resourceManager = new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.2.9"), expectedVersion, false, true);
currentNode = new InternalNode(nodeInfo.getNodeId(), URI.create("http://192.0.1.1"), expectedVersion, false);
activeNodes = ImmutableSet.of(currentNode, new InternalNode(UUID.randomUUID().toString(), URI.create("http://192.0.2.1:8080"), expectedVersion, false), new InternalNode(UUID.randomUUID().toString(), URI.create("http://192.0.2.3"), expectedVersion, false), coordinator, resourceManager);
inactiveNodes = ImmutableSet.of(new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.3.9"), NodeVersion.UNKNOWN, false), new InternalNode(UUID.randomUUID().toString(), URI.create("https://192.0.4.9"), new NodeVersion("2"), false));
selector.announceNodes(activeNodes, inactiveNodes);
}
use of com.facebook.presto.client.NodeVersion in project urban-eureka by errir503.
the class DiscoveryNodeManager method findCurrentNode.
private static InternalNode findCurrentNode(List<ServiceDescriptor> allServices, String currentNodeId, NodeVersion expectedNodeVersion, boolean httpsRequired) {
for (ServiceDescriptor service : allServices) {
URI uri = getHttpUri(service, httpsRequired);
OptionalInt thriftPort = getThriftServerPort(service);
NodeVersion nodeVersion = getNodeVersion(service);
if (uri != null && nodeVersion != null) {
InternalNode node = new InternalNode(service.getNodeId(), uri, thriftPort, nodeVersion, isCoordinator(service), isResourceManager(service), ALIVE);
if (node.getNodeIdentifier().equals(currentNodeId)) {
checkState(node.getNodeVersion().equals(expectedNodeVersion), "INVARIANT: current node version (%s) should be equal to %s", node.getNodeVersion(), expectedNodeVersion);
return node;
}
}
}
throw new IllegalStateException("INVARIANT: current node not returned from service selector");
}
use of com.facebook.presto.client.NodeVersion in project urban-eureka by errir503.
the class DiscoveryNodeManager method refreshNodesInternal.
private synchronized void refreshNodesInternal() {
// This is currently a blacklist.
// TODO: make it a whitelist (a failure-detecting service selector) and maybe build in support for injecting this in airlift
Set<ServiceDescriptor> services = serviceSelector.selectAllServices().stream().filter(service -> !failureDetector.getFailed().contains(service)).filter(service -> !nodeStatusService.isPresent() || nodeStatusService.get().isAllowed(service.getLocation()) || isCoordinator(service) || isResourceManager(service)).collect(toImmutableSet());
ImmutableSet.Builder<InternalNode> activeNodesBuilder = ImmutableSortedSet.orderedBy(comparing(InternalNode::getNodeIdentifier));
ImmutableSet.Builder<InternalNode> inactiveNodesBuilder = ImmutableSet.builder();
ImmutableSet.Builder<InternalNode> shuttingDownNodesBuilder = ImmutableSet.builder();
ImmutableSet.Builder<InternalNode> coordinatorsBuilder = ImmutableSet.builder();
ImmutableSet.Builder<InternalNode> resourceManagersBuilder = ImmutableSet.builder();
ImmutableSetMultimap.Builder<ConnectorId, InternalNode> byConnectorIdBuilder = ImmutableSetMultimap.builder();
Map<String, InternalNode> nodes = new HashMap<>();
SetMultimap<String, ConnectorId> connectorIdsByNodeId = HashMultimap.create();
// For a given connectorId, sort the nodes based on their nodeIdentifier
byConnectorIdBuilder.orderValuesBy(comparing(InternalNode::getNodeIdentifier));
if (isMemoizeDeadNodesEnabled && this.nodes != null) {
nodes.putAll(this.nodes);
}
if (isMemoizeDeadNodesEnabled && this.connectorIdsByNodeId != null) {
connectorIdsByNodeId.putAll(this.connectorIdsByNodeId);
}
for (ServiceDescriptor service : services) {
URI uri = getHttpUri(service, httpsRequired);
OptionalInt thriftPort = getThriftServerPort(service);
NodeVersion nodeVersion = getNodeVersion(service);
// Currently, a node may have the roles of both a coordinator and a worker. In the future, a resource manager may also
// take the form of a coordinator, hence these flags are not exclusive.
boolean coordinator = isCoordinator(service);
boolean resourceManager = isResourceManager(service);
if (uri != null && nodeVersion != null) {
InternalNode node = new InternalNode(service.getNodeId(), uri, thriftPort, nodeVersion, coordinator, resourceManager, ALIVE);
NodeState nodeState = getNodeState(node);
switch(nodeState) {
case ACTIVE:
activeNodesBuilder.add(node);
if (coordinator) {
coordinatorsBuilder.add(node);
}
if (resourceManager) {
resourceManagersBuilder.add(node);
}
nodes.put(node.getNodeIdentifier(), node);
// record available active nodes organized by connector id
String connectorIds = service.getProperties().get("connectorIds");
if (connectorIds != null) {
connectorIds = connectorIds.toLowerCase(ENGLISH);
for (String id : CONNECTOR_ID_SPLITTER.split(connectorIds)) {
ConnectorId connectorId = new ConnectorId(id);
byConnectorIdBuilder.put(connectorId, node);
connectorIdsByNodeId.put(node.getNodeIdentifier(), connectorId);
}
}
// always add system connector
byConnectorIdBuilder.put(new ConnectorId(GlobalSystemConnector.NAME), node);
break;
case INACTIVE:
inactiveNodesBuilder.add(node);
break;
case SHUTTING_DOWN:
shuttingDownNodesBuilder.add(node);
break;
default:
log.error("Unknown state %s for node %s", nodeState, node);
}
}
}
if (allNodes != null) {
// log node that are no longer active (but not shutting down)
SetView<InternalNode> missingNodes = difference(allNodes.getActiveNodes(), Sets.union(activeNodesBuilder.build(), shuttingDownNodesBuilder.build()));
for (InternalNode missingNode : missingNodes) {
log.info("Previously active node is missing: %s (last seen at %s)", missingNode.getNodeIdentifier(), missingNode.getHost());
}
}
// nodes by connector id changes anytime a node adds or removes a connector (note: this is not part of the listener system)
activeNodesByConnectorId = byConnectorIdBuilder.build();
if (isMemoizeDeadNodesEnabled) {
SetView<String> deadNodeIds = difference(nodes.keySet(), activeNodesBuilder.build().stream().map(InternalNode::getNodeIdentifier).collect(toImmutableSet()));
for (String nodeId : deadNodeIds) {
InternalNode deadNode = nodes.get(nodeId);
Set<ConnectorId> deadNodeConnectorIds = connectorIdsByNodeId.get(nodeId);
for (ConnectorId id : deadNodeConnectorIds) {
byConnectorIdBuilder.put(id, new InternalNode(deadNode.getNodeIdentifier(), deadNode.getInternalUri(), deadNode.getThriftPort(), deadNode.getNodeVersion(), deadNode.isCoordinator(), deadNode.isResourceManager(), DEAD));
}
}
}
this.nodes = ImmutableMap.copyOf(nodes);
this.nodesByConnectorId = byConnectorIdBuilder.build();
this.connectorIdsByNodeId = ImmutableSetMultimap.copyOf(connectorIdsByNodeId);
AllNodes allNodes = new AllNodes(activeNodesBuilder.build(), inactiveNodesBuilder.build(), shuttingDownNodesBuilder.build(), coordinatorsBuilder.build(), resourceManagersBuilder.build());
// only update if all nodes actually changed (note: this does not include the connectors registered with the nodes)
if (!allNodes.equals(this.allNodes)) {
// assign allNodes to a local variable for use in the callback below
this.allNodes = allNodes;
coordinators = coordinatorsBuilder.build();
resourceManagers = resourceManagersBuilder.build();
// notify listeners
List<Consumer<AllNodes>> listeners = ImmutableList.copyOf(this.listeners);
nodeStateEventExecutor.submit(() -> listeners.forEach(listener -> listener.accept(allNodes)));
}
}
use of com.facebook.presto.client.NodeVersion in project urban-eureka by errir503.
the class TestClusterSizeMonitor method addWorker.
private void addWorker(InMemoryNodeManager nodeManager) {
String identifier = "worker/" + numWorkers.incrementAndGet();
nodeManager.addNode(CONNECTOR_ID, new InternalNode(identifier, URI.create("localhost/" + identifier), new NodeVersion("1"), false));
}
use of com.facebook.presto.client.NodeVersion in project urban-eureka by errir503.
the class TestClusterSizeMonitor method addResourceManager.
private void addResourceManager(InMemoryNodeManager nodeManager) {
String identifier = "resource_manager/" + numResourceManagers.incrementAndGet();
nodeManager.addNode(CONNECTOR_ID, new InternalNode(identifier, URI.create("localhost/" + identifier), new NodeVersion("1"), false, true));
}
Aggregations