Search in sources :

Example 1 with NoCredentialsException

use of com.hazelcast.spi.exception.NoCredentialsException 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();
}
Also used : DiscoveryNode(com.hazelcast.spi.discovery.DiscoveryNode) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) Address(com.hazelcast.cluster.Address) NoCredentialsException(com.hazelcast.spi.exception.NoCredentialsException) ArrayList(java.util.ArrayList) NoCredentialsException(com.hazelcast.spi.exception.NoCredentialsException) InvalidConfigurationException(com.hazelcast.config.InvalidConfigurationException) RestClientException(com.hazelcast.spi.exception.RestClientException) RestClientException(com.hazelcast.spi.exception.RestClientException) SimpleDiscoveryNode(com.hazelcast.spi.discovery.SimpleDiscoveryNode) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with NoCredentialsException

use of com.hazelcast.spi.exception.NoCredentialsException in project hazelcast by hazelcast.

the class AzureMetadataApi method accessToken.

String accessToken() {
    try {
        String urlString = String.format("%s/metadata/identity/oauth2/token?api-version=%s&resource=%s", endpoint, API_VERSION, RESOURCE);
        String accessTokenResponse = callGet(urlString);
        return extractAccessToken(accessTokenResponse);
    } catch (Exception e) {
        throw new NoCredentialsException("Error while fetching access token from Azure API using managed identity.", e);
    }
}
Also used : NoCredentialsException(com.hazelcast.spi.exception.NoCredentialsException) NoCredentialsException(com.hazelcast.spi.exception.NoCredentialsException)

Aggregations

NoCredentialsException (com.hazelcast.spi.exception.NoCredentialsException)2 Address (com.hazelcast.cluster.Address)1 InvalidConfigurationException (com.hazelcast.config.InvalidConfigurationException)1 DiscoveryNode (com.hazelcast.spi.discovery.DiscoveryNode)1 SimpleDiscoveryNode (com.hazelcast.spi.discovery.SimpleDiscoveryNode)1 RestClientException (com.hazelcast.spi.exception.RestClientException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1