Java 类com.hazelcast.config.AwsConfig 实例源码

项目:hazelcast-aws    文件:AwsDiscoveryStrategy.java   
private void reviewConfiguration(AwsConfig config) {
    if (StringUtil.isNullOrEmptyAfterTrim(config.getSecretKey())
            || StringUtil.isNullOrEmptyAfterTrim(config.getAccessKey())) {

        if (!StringUtil.isNullOrEmptyAfterTrim(config.getIamRole())) {
            getLogger().info("Describe instances will be queried with iam-role, "
                    + "please make sure given iam-role have ec2:DescribeInstances policy attached.");
        } else {
            getLogger().warning("Describe instances will be queried with iam-role assigned to EC2 instance, "
                    + "please make sure given iam-role have ec2:DescribeInstances policy attached.");
        }
    } else {
        if (!StringUtil.isNullOrEmptyAfterTrim(config.getIamRole())) {
            getLogger().info("No need to define iam-role, when access and secret keys are configured!");
        }
    }
}
项目:hazelcast-aws    文件:EC2RequestSignerTest.java   
@Test
public void testSigning() throws NoSuchFieldException, IllegalAccessException, IOException {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setRegion(TEST_REGION).
            setHostHeader(TEST_HOST).
            setAccessKey(TEST_ACCESS_KEY).
            setSecretKey(TEST_SECRET_KEY);

    DescribeInstances di = new DescribeInstances(awsConfig, TEST_HOST);
    di.getRequestSigner();

    Field attributesField = di.getClass().getDeclaredField("attributes");
    attributesField.setAccessible(true);
    Map<String, String> attributes = (Map<String, String>) attributesField.get(di);
    attributes.put("X-Amz-Date", TEST_REQUEST_DATE);

    EC2RequestSigner actual = new EC2RequestSigner(awsConfig, TEST_REQUEST_DATE, TEST_HOST);
    attributes.put("X-Amz-Credential", actual.createFormattedCredential());
    String signature = actual.sign(TEST_SERVICE, attributes);

    assertEquals(TEST_SIGNATURE_EXPECTED, signature);
}
项目:hazelcast-aws    文件:CloudyUtilityTest.java   
@Test
public void testIamRole() throws IOException {
    String s = "{\n"
            + "  \"Code\" : \"Success\",\n"
            + "  \"LastUpdated\" : \"2015-09-06T21:17:26Z\",\n"
            + "  \"Type\" : \"AWS-HMAC\",\n"
            + "  \"AccessKeyId\" : \"ASIAIEXAMPLEOXYDA\",\n"
            + "  \"SecretAccessKey\" : \"hOCVge3EXAMPLExSJ+B\",\n"
            + "  \"Token\" : \"AQoDYXdzEE4EXAMPLE2UGAFshkTsyw7gojLdiEXAMPLE+1SfSRTfLR\",\n"
            + "  \"Expiration\" : \"2015-09-07T03:19:56Z\"\n}";
    StringReader sr = new StringReader(s);
    BufferedReader br = new BufferedReader(sr);
    AwsConfig awsConfig1 = new AwsConfig();
    awsConfig1.setAccessKey("some-access-key");
    awsConfig1.setSecretKey("some-secret-key");
    awsConfig1.setSecurityGroupName("hazelcast");
    DescribeInstances describeInstances = new DescribeInstances(awsConfig, "");

    Map map = describeInstances.parseIamRole(br);
    assertEquals("Success", map.get("Code"));
    assertEquals("2015-09-06T21:17:26Z", map.get("LastUpdated"));
    assertEquals("AWS-HMAC", map.get("Type"));
    assertEquals("ASIAIEXAMPLEOXYDA", map.get("AccessKeyId"));
    assertEquals("hOCVge3EXAMPLExSJ+B", map.get("SecretAccessKey"));
    assertEquals("AQoDYXdzEE4EXAMPLE2UGAFshkTsyw7gojLdiEXAMPLE+1SfSRTfLR", map.get("Token"));
}
项目:hazelcast-aws    文件:AwsDiscoveryStrategy.java   
private AwsConfig getAwsConfig() throws IllegalArgumentException {
    final AwsConfig config = new AwsConfig()
            .setEnabled(true)
            .setSecurityGroupName(getOrNull(SECURITY_GROUP_NAME))
            .setTagKey(getOrNull(TAG_KEY))
            .setTagValue(getOrNull(TAG_VALUE))
            .setIamRole(getOrNull(IAM_ROLE));

    String property = getOrNull(ACCESS_KEY);
    if (property != null) {
        config.setAccessKey(property);
    }

    property = getOrNull(SECRET_KEY);
    if (property != null) {
        config.setSecretKey(property);
    }

    final Integer timeout = getOrDefault(CONNECTION_TIMEOUT_SECONDS.getDefinition(), 10);
    config.setConnectionTimeoutSeconds(timeout);

    final String region = getOrNull(REGION);
    if (region != null) {
        config.setRegion(region);
    }

    final String hostHeader = getOrNull(HOST_HEADER);
    if (hostHeader != null) {
        config.setHostHeader(hostHeader);
    }

    reviewConfiguration(config);
    return config;
}
项目:hazelcast-aws    文件:AWSClient.java   
public AWSClient(AwsConfig awsConfig) {
    if (awsConfig == null) {
        throw new IllegalArgumentException("AwsConfig is required!");
    }
    this.awsConfig = awsConfig;
    this.endpoint = awsConfig.getHostHeader();
    if (awsConfig.getRegion() != null && awsConfig.getRegion().length() > 0) {
        if (!awsConfig.getHostHeader().startsWith("ec2.")) {
            throw new InvalidConfigurationException("HostHeader should start with \"ec2.\" prefix");
        }
        setEndpoint(awsConfig.getHostHeader().replace("ec2.", "ec2." + awsConfig.getRegion() + "."));
    }
}
项目:hazelcast-aws    文件:TcpIpJoinerOverAWS.java   
public TcpIpJoinerOverAWS(Node node) {
    super(node);
    logger = node.getLogger(getClass());

    AwsConfig awsConfig = node.getConfig().getNetworkConfig().getJoin().getAwsConfig();
    aws = new AWSClient(awsConfig);
}
项目:hazelcast-aws    文件:EC2RequestSignerTest.java   
@Test
public void deriveSigningKeyTest() throws Exception {
    // this is from http://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setRegion(TEST_REGION).
            setHostHeader(TEST_HOST).
            setAccessKey(TEST_ACCESS_KEY).
            setSecretKey(TEST_SECRET_KEY);

    DescribeInstances di = new DescribeInstances(awsConfig, TEST_HOST);
    // Override the attributes map. We need to change values. Not pretty, but
    // no real alternative, and in this case : testing only

    Field field = di.getClass().getDeclaredField("attributes");
    field.setAccessible(true);
    Map<String, String> attributes = (Map<String, String>) field.get(di);
    attributes.put("X-Amz-Date", TEST_REQUEST_DATE);
    field.set(di, attributes);

    // Override private method
    EC2RequestSigner rs = new EC2RequestSigner(awsConfig, TEST_REQUEST_DATE, TEST_HOST);
    field = rs.getClass().getDeclaredField("service");
    field.setAccessible(true);
    field.set(rs, "ec2");

    Method method = rs.getClass().getDeclaredMethod("deriveSigningKey", null);
    method.setAccessible(true);
    byte[] derivedKey = (byte[]) method.invoke(rs);

    assertEquals(TEST_DERIVED_EXPECTED, bytesToHex(derivedKey));
}
项目:hazelcast-aws    文件:AwsDiscoveryStrategyTest.java   
@Test
public void testLocalMetaData() {
    AWSClient mockClient = spy(new AWSClient(new AwsConfig()));
    doReturn("us-east-1a").when(mockClient).getAvailabilityZone();
    AwsDiscoveryStrategy awsDiscoveryStrategy
            = new AwsDiscoveryStrategy(Collections.<String, Comparable>emptyMap(), mockClient);
    Map<String, Object> localMetaData = awsDiscoveryStrategy.discoverLocalMetadata();
    String zone = (String) localMetaData.get(PARTITION_GROUP_ZONE);
    assertEquals("us-east-1a", zone);
}
项目:hazelcast-aws    文件:CloudyUtilityTest.java   
@Before
public void setup() {
    awsConfig = new AwsConfig();
    awsConfig.setAccessKey("some-access-key");
    awsConfig.setSecretKey("some-secret-key");
    awsConfig.setSecurityGroupName("hazelcast");
}
项目:hazelcast-aws    文件:CloudyUtilityTest.java   
@Test
public void testUnmarshalling() throws IOException {
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    AwsConfig awsConfig1 = new AwsConfig();
    awsConfig1.setAccessKey("some-access-key");
    awsConfig1.setSecretKey("some-secret-key");

    Map<String, String> result = CloudyUtility.unmarshalTheResponse(is);
    assertEquals(2, result.size());
}
项目:hazelcast-aws    文件:AwsClientTest.java   
@Test
public void testAwsClient_getEndPoint() {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setIamRole("test");
    AWSClient awsClient = new AWSClient(awsConfig);
    assertEquals("ec2.us-east-1.amazonaws.com", awsClient.getEndpoint());
}
项目:hazelcast-aws    文件:AwsClientTest.java   
@Test
public void testAwsClient_withDifferentHostHeader() {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setIamRole("test");
    awsConfig.setHostHeader("ec2.amazonaws.com.cn");
    awsConfig.setRegion("cn-north-1");
    AWSClient awsClient = new AWSClient(awsConfig);
    assertEquals("ec2.cn-north-1.amazonaws.com.cn", awsClient.getEndpoint());
}
项目:hazelcast-aws    文件:AwsClientTest.java   
@Test(expected = InvalidConfigurationException.class)
public void testAwsClient_withInvalidHostHeader() {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setIamRole("test");
    awsConfig.setHostHeader("ec3.amazonaws.com.cn");
    new AWSClient(awsConfig);
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test(expected = IllegalArgumentException.class)
public void test_whenAccessKey_And_IamRole_And_IamTaskRoleEnvVar_Null_With_No_DefaultRole() throws IOException {
    Environment mockedEnv = mock(Environment.class);
    when(mockedEnv.getEnvVar(Constants.ECS_CREDENTIALS_ENV_VAR_NAME)).thenReturn(null);

    final String uri = INSTANCE_METADATA_URI + IAM_SECURITY_CREDENTIALS_URI;

    DescribeInstances descriptor = spy(new DescribeInstances(new AwsConfig()));
    doReturn("").when(descriptor).retrieveRoleFromURI(uri);
    doReturn(mockedEnv).when(descriptor).getEnvironment();
    descriptor.fillKeysFromIamRoles();
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test
public void test_whenAccessKeyExistsInConfig() throws IOException {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setAccessKey("accesskey");
    awsConfig.setSecretKey("secretkey");
    new DescribeInstances(awsConfig, "endpoint");
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test
public void test_whenIamRoleExistsInConfig() throws IOException {
    final String someRole = "someRole";
    final String uri = INSTANCE_METADATA_URI + IAM_SECURITY_CREDENTIALS_URI + someRole;

    // some dummy creds. Look real, but they aren't.
    final String accessKeyId = "ASIAJDOR231233BVE7GQ";
    final String secretAccessKey = "QU5mTd40xnAbC5Mz2T3Fy7afQVrow+/tYq5GXMf7";
    final String token = "FQoDYXdzEKX//////////wEaDN2Xh+ekVbV1KJrCqCK3A/Quuw8xCdZZbOPjzKLNc89n72z61BLt96hzlxTV6Vx1hDXLQNWRIx07hZVgmgGzzyr0DzYAcqKq7s2GUznWlaXhGHxhyo4nJUeBFbLyYPjbDAcnl84HItjy5bvtQ6fbDM7h2ZGuJrHi51KAhxWN/uEHyBKAIJd5RdXxVH4UTNxJFiqEw8GdaXDGK07186TfqSFCdlG+rhL35bN7WcJZuykIpynbeQpPeY4rJ0WJGoSJwt/RSkGwP+JRcYmv8Y7L1uSD2spJWO6etFeyyU63y0BL42MXWL38SQypxjLz+s1PozSDrV7zxsp4DQONn+adbSyAoveskD3xtDYsip1Ra0UCSYNKzmmh2XXF4fBBb6EPRixc1fnCIVDp0rfyCGO0VMuIloF5nWP9XsaRcR1mbJ7K/TuWgugduRBgyV2s1KgJuPni5cZ6ptEkPBb2b+92DjxEdQCAi6+WAdWliFiJ/P3T+qSJGLaxAeu0P0yb8E2xfCjEH6qOH3EM0KfgyJM5WJbXlYZTOZZXHaj26rlhe2k3wdL+UXf4geAzczphyOyp4QIGqaxe0xj08BKvSqngQb5X44oVR40oi7fOvwU=";

    final String someDummyIamRole =
            "        {\n" +
                    "          \"Code\" : \"Success\",\n" +
                    "          \"LastUpdated\" : \"2016-10-04T12:08:24Z\",\n" +
                    "          \"Type\" : \"AWS-HMAC\",\n" +
                    "          \"AccessKeyId\" : \"" + accessKeyId + "\",\n" +
                    "          \"SecretAccessKey\" : \"" + secretAccessKey + "\",\n" +
                    "          \"Token\" : \"" + token + "\",\n" +
                    "          \"Expiration\" : \"2016-10-04T18:19:39Z\"\n" +
                    "        }\n";


    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setIamRole(someRole);

    DescribeInstances descriptor = spy(new DescribeInstances(awsConfig));
    doReturn(someDummyIamRole).when(descriptor).retrieveRoleFromURI(uri);
    descriptor.fillKeysFromIamRoles();

    Assert.assertEquals("Could not parse access key from IAM role", accessKeyId, awsConfig.getAccessKey());
    Assert.assertEquals("Could not parse secret key from IAM role", secretAccessKey, awsConfig.getSecretKey());

}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test
public void test_when_Empty_IamRole_And_DefaultIamRole_But_IamTaskRoleEnvVar_Exists() throws IOException {

    final String accessKeyId = "ASIAJZ6Y3MXO7SRJ1234";
    final String secretAccessKey = "p00VnhQ//HeT7W7V123f7BgYZaBlPZTxj9mcvSlc";
    final String token = "FQoDYXdzEKX//////////wEaDDS1irrM7Wkt1VxNUyKoAxdXWEDQJUXpIGmBG4qCCiNLOXkF5mak8ZDVqS2PV+X7nsRF9C4mZwqMkGfRmxpZzGc+QTRfbncdZzEOeHcBea38mM7kJUJyNagWfNpwgzimgJzLqn5tNirs7+MXVw5rfblWCjngzjrovlsl6+q0K9LZM0W5OTRSKmEZQnJFjZh9w+BZHo5pair1ZqrxhfOcW6UaMpfOfRH/VI1n3u+De7YCqdq5jhmaDzWxewxccfH/BI2SRHaC1OEq0L3kMhwj1JrLjrOTJn4nBwjGZAlODFhoMec1cUW0GdIJN6+KZDbt8TuKlqDutKMDe1CNIH/697J0lLPMC8tgbgu3MrLSVxtQkMPdDMzJWNPXNQhQa+Nvw5w7gV7+27s9oat+dJBp3lLmTe4PZ810IQGa2NLZHKrv7kqGncLu5mURj+UVZHlueyYyPBWhVdHn4tCJ/cX2RaeqiVTbMILrduZePw7wTS8+19RnnPxA9wp45OZE5otSvNegJ9XhEJiU7RyJPhdSezMVoGsnzvgbCnBUAzHAe4ZuQZo7iIBWNXkcKBsCAU0MY8ym6NVn5VQohKrOvwU=";

    // Note the below role is different from the regular IAM role, in that it doesn't contain new lines.
    final String someDummyIamTaskRole =
            "{" +
                    "  \"RoleArn\":\"arn:aws:iam::123456789012:role/hazelcastIamTaskRole\"," +
                    "  \"AccessKeyId\":\"" + accessKeyId + "\"," +
                    "  \"SecretAccessKey\":\"" + secretAccessKey + "\"," +
                    "  \"Token\":\"" + token + "\"," +
                    "  \"Expiration\":\"2016-10-04T17:39:48Z\"" +
                    "  }";


    final String ecsEnvVarCredsUri = "someURL";
    final String uri = DescribeInstances.IAM_TASK_ROLE_ENDPOINT + ecsEnvVarCredsUri;
    final String defaultRoleUri = INSTANCE_METADATA_URI + IAM_SECURITY_CREDENTIALS_URI;

    Environment mockedEnv = mock(Environment.class);
    when(mockedEnv.getEnvVar(Constants.ECS_CREDENTIALS_ENV_VAR_NAME)).thenReturn(ecsEnvVarCredsUri);

    AwsConfig awsConfig = new AwsConfig();

    // test when default role is null
    DescribeInstances descriptor = spy(new DescribeInstances(awsConfig));
    doReturn(someDummyIamTaskRole).when(descriptor).retrieveRoleFromURI(uri);
    doReturn("").when(descriptor).retrieveRoleFromURI(defaultRoleUri);
    doReturn(mockedEnv).when(descriptor).getEnvironment();

    descriptor.fillKeysFromIamRoles();

    Assert.assertEquals("Could not parse access key from IAM task role", accessKeyId, awsConfig.getAccessKey());
    Assert.assertEquals("Could not parse secret key from IAM task role", secretAccessKey, awsConfig.getSecretKey());

}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test
public void test_DescribeInstances_SecurityGroup()
        throws Exception {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setEnabled(true).setAccessKey(System.getenv("AWS_ACCESS_KEY_ID"))
            .setSecretKey(System.getenv("AWS_SECRET_ACCESS_KEY")).setSecurityGroupName("launch-wizard-147");

    getInstancesAndVerify(awsConfig);
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test
public void test_DescribeInstances_when_Tag_and_Value_Set()
        throws Exception {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setEnabled(true).setAccessKey(System.getenv("AWS_ACCESS_KEY_ID"))
            .setSecretKey(System.getenv("AWS_SECRET_ACCESS_KEY")).setTagKey("aws-test-tag").setTagValue("aws-tag-value-1");

    getInstancesAndVerify(awsConfig);
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test
public void test_DescribeInstances_when_Only_TagKey_Set()
        throws Exception {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setEnabled(true).setAccessKey(System.getenv("AWS_ACCESS_KEY_ID"))
            .setSecretKey(System.getenv("AWS_SECRET_ACCESS_KEY")).setTagKey("aws-test-tag");

    getInstancesAndVerify(awsConfig);
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test
public void test_DescribeInstances_when_Only_TagValue_Set()
        throws Exception {
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setEnabled(true).setAccessKey(System.getenv("AWS_ACCESS_KEY_ID"))
            .setSecretKey(System.getenv("AWS_SECRET_ACCESS_KEY")).setTagValue("aws-tag-value-1");

    getInstancesAndVerify(awsConfig);
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test(timeout = TIMEOUT_FACTOR * CALL_SERVICE_TIMEOUT, expected = SocketTimeoutException.class)
public void test_CallService_Timeout() throws Exception {
    final String nonRoutable = "10.255.255.254";
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setConnectionTimeoutSeconds((int) TimeUnit.MILLISECONDS.toSeconds(CALL_SERVICE_TIMEOUT));
    DescribeInstances describeInstances = new DescribeInstances(awsConfig);
    describeInstances.callService(nonRoutable);
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
@Test(timeout = TIMEOUT_FACTOR * CALL_SERVICE_TIMEOUT, expected = InvalidConfigurationException.class)
public void test_RetrieveMetaData_Timeout() {
    final String nonRoutable = "http://10.255.255.254";
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setConnectionTimeoutSeconds((int) TimeUnit.MILLISECONDS.toSeconds(CALL_SERVICE_TIMEOUT));

    DescribeInstances describeInstances = new DescribeInstances(awsConfig);
    describeInstances.retrieveRoleFromURI(nonRoutable);
}
项目:hazelcast-aws    文件:DescribeInstancesTest.java   
private void getInstancesAndVerify(AwsConfig awsConfig)
        throws Exception {
    DescribeInstances describeInstances = new DescribeInstances(awsConfig, awsConfig.getHostHeader());
    Map<String, String> result = describeInstances.execute();
    Assert.assertNotNull(result);
    Assert.assertEquals(1, result.size());
    String expectedPrivateIp = System.getenv("HZ_TEST_AWS_INSTANCE_PRIVATE_IP");
    Assert.assertNotNull(expectedPrivateIp);
    Assert.assertNotNull(result.get(expectedPrivateIp));
}
项目:eet.osslite.cz    文件:HazelcastConfiguration.java   
private void setNetworkJoin(JoinConfig join) {
    join.getMulticastConfig().setEnabled(false);

    AwsConfig aws = join.getAwsConfig();
    aws.setEnabled(false);
    aws.setAccessKey("AKIAIA2GXRFAH4OTZN4A");
    aws.setSecretKey("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");

    setTcpIpConfig(join.getTcpIpConfig());
}
项目:hazelcast-jclouds    文件:JCloudsDiscoveryFactoryTest.java   
@Test
public void testParsing() {
    String xmlFileName = "test-jclouds-config.xml";
    InputStream xmlResource = JCloudsDiscoveryFactoryTest.class.getClassLoader().getResourceAsStream(xmlFileName);
    Config config = new XmlConfigBuilder(xmlResource).build();

    JoinConfig joinConfig = config.getNetworkConfig().getJoin();

    AwsConfig awsConfig = joinConfig.getAwsConfig();
    assertFalse(awsConfig.isEnabled());

    TcpIpConfig tcpIpConfig = joinConfig.getTcpIpConfig();
    assertFalse(tcpIpConfig.isEnabled());

    MulticastConfig multicastConfig = joinConfig.getMulticastConfig();
    assertFalse(multicastConfig.isEnabled());

    DiscoveryConfig discoveryConfig = joinConfig.getDiscoveryConfig();
    assertTrue(discoveryConfig.isEnabled());

    assertEquals(1, discoveryConfig.getDiscoveryStrategyConfigs().size());

    DiscoveryStrategyConfig providerConfig = discoveryConfig.getDiscoveryStrategyConfigs().iterator().next();

    assertEquals(12, providerConfig.getProperties().size());
    assertEquals("aws-ec2", providerConfig.getProperties().get("provider"));
    assertEquals("test", providerConfig.getProperties().get("identity"));
    assertEquals("test", providerConfig.getProperties().get("credential"));
    assertEquals("zone1,zone2", providerConfig.getProperties().get("zones"));
    assertEquals("region1,region2", providerConfig.getProperties().get("regions"));
    assertEquals("zone1,zone2", providerConfig.getProperties().get("zones"));
    assertEquals("tag1,tag2", providerConfig.getProperties().get("tag-keys"));
    assertEquals("tagvalue1,tagvalue2", providerConfig.getProperties().get("tag-values"));
    assertEquals("group", providerConfig.getProperties().get("group"));
    assertEquals("5702", providerConfig.getProperties().get("hz-port"));
    assertEquals("myfile.json", providerConfig.getProperties().get("credentialPath"));
    assertEquals("myRole", providerConfig.getProperties().get("role-name"));
    assertEquals("http://foo/bar", providerConfig.getProperties().get("endpoint"));
}
项目:hazelcast-archive    文件:CloudyUtility.java   
private static Object parse(InputStream in, AwsConfig awsConfig) {
        final DocumentBuilder builder;
        try {
            builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(in);
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            Util.streamXML(doc, baos);
            final byte[] bytes = baos.toByteArray();
//            final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
//            Reader reader = new BufferedReader(new InputStreamReader(bais));
//            int n;
//            char[] buffer = new char[1024];
//            Writer writer = new StringWriter();
//            while ((n = reader.read(buffer)) != -1) {
//                writer.write(buffer, 0, n);
//            }
//            System.out.println(writer.toString());
            Element element = doc.getDocumentElement();
            NodeHolder elementNodeHolder = new NodeHolder(element);
            List<String> names = new ArrayList<String>();
            List<NodeHolder> reservationset = elementNodeHolder.getSubNodes("reservationset");
            for (NodeHolder reservation : reservationset) {
                List<NodeHolder> items = reservation.getSubNodes("item");
                for (NodeHolder item : items) {
                    NodeHolder instancesset = item.getSub("instancesset");
                    names.addAll(instancesset.getList("privateipaddress", awsConfig));
                }
            }
            return names;
        } catch (Exception e) {
            logger.log(Level.WARNING, e.getMessage(), e);
        }
        return new ArrayList<String>();
    }
项目:hazelcast-archive    文件:DescribeInstances.java   
public DescribeInstances(AwsConfig awsConfig) {
    rs = new EC2RequestSigner(awsConfig.getSecretKey());
    attributes.put("Action", this.getClass().getSimpleName());
    attributes.put("Version", DOC_VERSION);
    attributes.put("SignatureVersion", SIGNATURE_VERSION);
    attributes.put("SignatureMethod", SIGNATURE_METHOD);
    attributes.put("AWSAccessKeyId", awsConfig.getAccessKey());
    attributes.put("Timestamp", getFormattedTimestamp());
    this.awsConfig = awsConfig;
}
项目:hazelcast-archive    文件:TcpIpJoinerOverAWS.java   
public TcpIpJoinerOverAWS(Node node) {
    super(node);
    AwsConfig awsConfig = node.getConfig().getNetworkConfig().getJoin().getAwsConfig();
    aws = new AWSClient(awsConfig);
    if (awsConfig.getRegion() != null && awsConfig.getRegion().length() > 0) {
        aws.setEndpoint("ec2." + awsConfig.getRegion() + ".amazonaws.com");
    }
    this.groupName = awsConfig.getSecurityGroupName();
}
项目:hazelcast-archive    文件:CloudyUtilityTest.java   
@Test
public void testNoTags() throws IOException {
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setAccessKey("");
    awsConfig.setSecretKey("");
    awsConfig.setSecurityGroupName("hazelcast");
    List<String> result = (List<String>) CloudyUtility.unmarshalTheResponse(is, awsConfig);
    assertEquals(2, result.size());
}
项目:hazelcast-archive    文件:CloudyUtilityTest.java   
@Test
public void testTagsBothNodeHave() throws IOException {
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setAccessKey("");
    awsConfig.setSecretKey("");
    awsConfig.setSecurityGroupName("hazelcast");
    awsConfig.setTagKey("Name1");
    awsConfig.setTagValue("value1");
    List<String> result = (List<String>) CloudyUtility.unmarshalTheResponse(is, awsConfig);
    assertEquals(2, result.size());
}
项目:hazelcast-archive    文件:CloudyUtilityTest.java   
@Test
public void testTagOnlyOneNodeHave() throws IOException {
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setAccessKey("");
    awsConfig.setSecretKey("");
    awsConfig.setSecurityGroupName("hazelcast");
    awsConfig.setTagKey("name");
    awsConfig.setTagValue("");
    List<String> result = (List<String>) CloudyUtility.unmarshalTheResponse(is, awsConfig);
    assertEquals(1, result.size());
}
项目:health-and-care-developer-network    文件:CloudyUtility.java   
private static Object parse(InputStream in, AwsConfig awsConfig) {
        final DocumentBuilder builder;
        try {
            builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document doc = builder.parse(in);
            final ByteArrayOutputStream baos = new ByteArrayOutputStream();
            Util.streamXML(doc, baos);
            final byte[] bytes = baos.toByteArray();
//            final ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
//            Reader reader = new BufferedReader(new InputStreamReader(bais));
//            int n;
//            char[] buffer = new char[1024];
//            Writer writer = new StringWriter();
//            while ((n = reader.read(buffer)) != -1) {
//                writer.write(buffer, 0, n);
//            }
//            System.out.println(writer.toString());
            Element element = doc.getDocumentElement();
            NodeHolder elementNodeHolder = new NodeHolder(element);
            List<String> names = new ArrayList<String>();
            List<NodeHolder> reservationset = elementNodeHolder.getSubNodes("reservationset");
            for (NodeHolder reservation : reservationset) {
                List<NodeHolder> items = reservation.getSubNodes("item");
                for (NodeHolder item : items) {
                    NodeHolder instancesset = item.getSub("instancesset");
                    names.addAll(instancesset.getList("privateipaddress", awsConfig));
                }
            }
            return names;
        } catch (Exception e) {
            logger.log(Level.WARNING, e.getMessage(), e);
        }
        return new ArrayList<String>();
    }
项目:health-and-care-developer-network    文件:DescribeInstances.java   
public DescribeInstances(AwsConfig awsConfig) {
    rs = new EC2RequestSigner(awsConfig.getSecretKey());
    attributes.put("Action", this.getClass().getSimpleName());
    attributes.put("Version", DOC_VERSION);
    attributes.put("SignatureVersion", SIGNATURE_VERSION);
    attributes.put("SignatureMethod", SIGNATURE_METHOD);
    attributes.put("AWSAccessKeyId", awsConfig.getAccessKey());
    attributes.put("Timestamp", getFormattedTimestamp());
    this.awsConfig = awsConfig;
}
项目:health-and-care-developer-network    文件:TcpIpJoinerOverAWS.java   
public TcpIpJoinerOverAWS(Node node) {
    super(node);
    AwsConfig awsConfig = node.getConfig().getNetworkConfig().getJoin().getAwsConfig();
    aws = new AWSClient(awsConfig);
    if (awsConfig.getRegion() != null && awsConfig.getRegion().length() > 0) {
        aws.setEndpoint("ec2." + awsConfig.getRegion() + ".amazonaws.com");
    }
    this.groupName = awsConfig.getSecurityGroupName();
}
项目:health-and-care-developer-network    文件:CloudyUtilityTest.java   
@Test
public void testNoTags() throws IOException {
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setAccessKey("");
    awsConfig.setSecretKey("");
    awsConfig.setSecurityGroupName("hazelcast");
    List<String> result = (List<String>) CloudyUtility.unmarshalTheResponse(is, awsConfig);
    assertEquals(2, result.size());
}
项目:health-and-care-developer-network    文件:CloudyUtilityTest.java   
@Test
public void testTagsBothNodeHave() throws IOException {
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setAccessKey("");
    awsConfig.setSecretKey("");
    awsConfig.setSecurityGroupName("hazelcast");
    awsConfig.setTagKey("Name1");
    awsConfig.setTagValue("value1");
    List<String> result = (List<String>) CloudyUtility.unmarshalTheResponse(is, awsConfig);
    assertEquals(2, result.size());
}
项目:health-and-care-developer-network    文件:CloudyUtilityTest.java   
@Test
public void testTagOnlyOneNodeHave() throws IOException {
    InputStream is = new ByteArrayInputStream(xml.getBytes());
    AwsConfig awsConfig = new AwsConfig();
    awsConfig.setAccessKey("");
    awsConfig.setSecretKey("");
    awsConfig.setSecurityGroupName("hazelcast");
    awsConfig.setTagKey("name");
    awsConfig.setTagValue("");
    List<String> result = (List<String>) CloudyUtility.unmarshalTheResponse(is, awsConfig);
    assertEquals(1, result.size());
}
项目:hazelcast-aws    文件:EC2RequestSigner.java   
public EC2RequestSigner(AwsConfig config, String timeStamp, String endpoint) {
    this.config = config;
    this.timestamp = timeStamp;
    this.service = null;
    this.endpoint = endpoint;
}
项目:hazelcast-aws    文件:DescribeInstances.java   
public DescribeInstances(AwsConfig awsConfig, String endpoint) throws IOException {
    this.awsConfig = awsConfig;
    this.endpoint = endpoint;
}