本文整理汇总了Java中com.hazelcast.config.AwsConfig类的典型用法代码示例。如果您正苦于以下问题:Java AwsConfig类的具体用法?Java AwsConfig怎么用?Java AwsConfig使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AwsConfig类属于com.hazelcast.config包,在下文中一共展示了AwsConfig类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reviewConfiguration
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
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!");
}
}
}
示例2: testSigning
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@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);
}
示例3: testIamRole
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@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"));
}
示例4: getAwsConfig
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
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;
}
示例5: AWSClient
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
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() + "."));
}
}
示例6: TcpIpJoinerOverAWS
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
public TcpIpJoinerOverAWS(Node node) {
super(node);
logger = node.getLogger(getClass());
AwsConfig awsConfig = node.getConfig().getNetworkConfig().getJoin().getAwsConfig();
aws = new AWSClient(awsConfig);
}
示例7: deriveSigningKeyTest
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@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));
}
示例8: testLocalMetaData
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@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);
}
示例9: setup
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Before
public void setup() {
awsConfig = new AwsConfig();
awsConfig.setAccessKey("some-access-key");
awsConfig.setSecretKey("some-secret-key");
awsConfig.setSecurityGroupName("hazelcast");
}
示例10: testUnmarshalling
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@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());
}
示例11: testAwsClient_getEndPoint
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@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());
}
示例12: testAwsClient_withDifferentHostHeader
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@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());
}
示例13: testAwsClient_withInvalidHostHeader
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test(expected = InvalidConfigurationException.class)
public void testAwsClient_withInvalidHostHeader() {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setIamRole("test");
awsConfig.setHostHeader("ec3.amazonaws.com.cn");
new AWSClient(awsConfig);
}
示例14: test_whenAccessKey_And_IamRole_And_IamTaskRoleEnvVar_Null_With_No_DefaultRole
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@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();
}
示例15: test_whenAccessKeyExistsInConfig
import com.hazelcast.config.AwsConfig; //导入依赖的package包/类
@Test
public void test_whenAccessKeyExistsInConfig() throws IOException {
AwsConfig awsConfig = new AwsConfig();
awsConfig.setAccessKey("accesskey");
awsConfig.setSecretKey("secretkey");
new DescribeInstances(awsConfig, "endpoint");
}