use of com.hazelcast.spi.discovery.SimpleDiscoveryNode in project hazelcast by hazelcast.
the class SimplePredefinedDiscoveryServiceTest method discoverNodes.
@Test
public void discoverNodes() {
final SimpleDiscoveryNode node = new SimpleDiscoveryNode(new Address());
final Iterable<DiscoveryNode> nodes = Arrays.<DiscoveryNode>asList(node, node);
final PredefinedDiscoveryService service = new PredefinedDiscoveryService(new ExtendableDiscoveryStrategy() {
@Override
public Iterable<DiscoveryNode> discoverNodes() {
return nodes;
}
});
assertEquals(nodes, service.discoverNodes());
}
use of com.hazelcast.spi.discovery.SimpleDiscoveryNode in project hazelcast by hazelcast.
the class GcpDiscoveryStrategy method createDiscoveryNode.
private static DiscoveryNode createDiscoveryNode(GcpAddress gcpAddress, int port) throws UnknownHostException {
Address privateAddress = new Address(gcpAddress.getPrivateAddress(), port);
Address publicAddress = new Address(gcpAddress.getPublicAddress(), port);
return new SimpleDiscoveryNode(privateAddress, publicAddress);
}
use of com.hazelcast.spi.discovery.SimpleDiscoveryNode in project hazelcast-eureka by hazelcast.
the class EurekaOneDiscoveryStrategy method discoverNodes.
public Iterable<DiscoveryNode> discoverNodes() {
List<DiscoveryNode> nodes = new ArrayList<DiscoveryNode>();
String applicationName = applicationInfoManager.getEurekaInstanceConfig().getAppname();
Application application = null;
for (int i = 0; i < NUM_RETRIES; i++) {
application = eurekaClient.getApplication(applicationName);
if (application != null) {
break;
}
try {
TimeUnit.SECONDS.sleep(DISCOVERY_RETRY_TIMEOUT);
} catch (InterruptedException almostIgnore) {
Thread.currentThread().interrupt();
}
}
if (application != null) {
List<InstanceInfo> instances = application.getInstances();
for (InstanceInfo instance : instances) {
// Only recognize up and running instances
if (instance.getStatus() != InstanceInfo.InstanceStatus.UP) {
continue;
}
InetAddress address = mapAddress(instance);
if (null == address) {
continue;
}
int port = instance.getPort();
Map<String, Object> metadata = (Map) instance.getMetadata();
nodes.add(new SimpleDiscoveryNode(new Address(address, port), metadata));
}
}
return nodes;
}
use of com.hazelcast.spi.discovery.SimpleDiscoveryNode in project hazelcast by hazelcast.
the class Node method createDiscoveryService.
public DiscoveryService createDiscoveryService(DiscoveryConfig discoveryConfig, List<DiscoveryStrategyConfig> aliasedDiscoveryConfigs, boolean isAutoDetectionEnabled, Member localMember) {
DiscoveryServiceProvider factory = discoveryConfig.getDiscoveryServiceProvider();
if (factory == null) {
factory = new DefaultDiscoveryServiceProvider();
}
ILogger logger = getLogger(DiscoveryService.class);
DiscoveryServiceSettings settings = new DiscoveryServiceSettings().setConfigClassLoader(configClassLoader).setLogger(logger).setDiscoveryMode(DiscoveryMode.Member).setDiscoveryConfig(discoveryConfig).setAliasedDiscoveryConfigs(aliasedDiscoveryConfigs).setAutoDetectionEnabled(isAutoDetectionEnabled).setDiscoveryNode(new SimpleDiscoveryNode(localMember.getAddress(), localMember.getAttributes()));
return factory.newDiscoveryService(settings);
}
use of com.hazelcast.spi.discovery.SimpleDiscoveryNode in project hazelcast by hazelcast.
the class AwsDiscoveryStrategy method discoverNodes.
@Override
public Iterable<DiscoveryNode> discoverNodes() {
try {
Map<String, String> addresses = awsClient.getAddresses();
logResult(addresses);
List<DiscoveryNode> result = new ArrayList<>();
for (Map.Entry<String, String> entry : addresses.entrySet()) {
for (int port = portRange.getFromPort(); port <= portRange.getToPort(); port++) {
Address privateAddress = new Address(entry.getKey(), port);
Address publicAddress = new Address(entry.getValue(), port);
result.add(new SimpleDiscoveryNode(privateAddress, publicAddress));
}
}
return result;
} catch (NoCredentialsException e) {
if (!isKnownExceptionAlreadyLogged) {
LOGGER.warning("No AWS credentials found! Starting standalone. To use Hazelcast AWS discovery, configure" + " properties (access-key, secret-key) or assign the required IAM Role to your EC2 instance");
LOGGER.finest(e);
isKnownExceptionAlreadyLogged = true;
}
} catch (RestClientException e) {
if (e.getHttpErrorCode() == HTTP_FORBIDDEN) {
if (!isKnownExceptionAlreadyLogged) {
LOGGER.warning("AWS IAM Role Policy missing 'ec2:DescribeInstances' Action! Starting standalone.");
isKnownExceptionAlreadyLogged = true;
}
LOGGER.finest(e);
} else {
LOGGER.warning("Cannot discover nodes. Starting standalone.", e);
}
} catch (Exception e) {
LOGGER.warning("Cannot discover nodes. Starting standalone.", e);
}
return Collections.emptyList();
}
Aggregations