/** * Returns the AccountId of the user who is running the instance. * * @return String representing the AccountId or the owner-id * @throws java.io.IOException if failed to retrieve the AccountId using the * Cloud infrastructure */ public static String getAccountId() throws IOException { // Get the MAC address of the machine. String macUrl = getMetadataUrl() + "/network/interfaces/macs/"; String mac = invokeUrl(macUrl).trim(); // Use the MAC address to obtain the owner-id or the // AWS AccountId. String idUrl = macUrl + mac + "owner-id"; String acctId = invokeUrl(idUrl).trim(); assert acctId != null; return acctId; }
throw new IllegalArgumentException("Conflicting multicast discovery addresses in cluster configuration"); } else if (multicastAddressesCount > 0) { if (AwsUtils.isDeployedToAWS() && !InternalSystemProperty.CLUSTER_BYPASS_AWS_CHECK.getBooleanProperty(gatewayConfiguration)) { throw new IllegalArgumentException("Multicast cluster configuration not supported on AWS, use " + "aws://security-group/<security-group-name> in connect tag"); groupName = AwsUtils.getSecurityGroupName(); awsConfig.setAccessKey(connectOptions.getAwsAccessKeyId()); awsConfig.setSecretKey(connectOptions.getAwsSecretKey()); awsConfig.setRegion(AwsUtils.getRegion()); awsConfig.setSecurityGroupName(groupName); String localIPv4 = AwsUtils.getLocalIPv4(); networkConfig.getInterfaces().setEnabled(true); networkConfig.getInterfaces().clear();
params.put("SignatureMethod", HMAC_SHA256_ALGORITHM); params.put("SignatureVersion", "2"); params.put("Timestamp", getTimestamp()); String canonicalQS = getV2CanonicalizedQueryString(params); String stringToSign = requestMethod + "\n" + endpoint + "\n" + requestURI + "\n" + canonicalQS; String signature = createSignature(stringToSign, awsSecretKey, HMAC_SHA256_ALGORITHM);
params.put("Timestamp", getTimestamp()); String stringToSign = getV1StringToSign(params); String signature = createV1Signature(stringToSign, awsSecretKey, HMAC_SHA1_ALGORITHM);
response = getResponse(inStream); inStream.close(); response = getResponse(inStream);
/** * Returns the local address (IPv4) of the instance. The local address * is defined to be * Public IP address if launched with direct addressing; private IP * address if launched with public addressing. * * @return local IP address (IPv4) of the instance * @throws java.io.IOException */ public static String getLocalIPv4() throws IOException { String url = getMetadataUrl() + "/local-ipv4"; String localIPv4 = invokeUrl(url); if ((localIPv4 == null) || (localIPv4.trim().length() == 0)) { String msg = "No local IPv4 assigned to the instance"; throw new IllegalStateException(msg); } return localIPv4.trim(); }
/** * Returns the region in which the instance is running. * * @return String representing the region where the instance is * running * @throws java.io.IOException if failed to retrieve the region information * using the Cloud infrastructure */ public static String getRegion() throws IOException { String url = getMetadataUrl() + "/placement/availability-zone"; String zone = invokeUrl(url); zone = zone.trim(); // In case of AWS, the zone includes an extra character // at the end such as "us-east-1a", "us-east-1b", "eu-west-1a", // etc. We have to strip that last character to get the // correct region. String region = zone.substring(0, zone.length() - 1); assert region != null; return region; }
/** * Returns the name of the security group from the list that is * obtained from the resource vendor. An instance may belong to multiple * security groups. And, the list of security groups obtained from the * vendor may not be ordered. If the vendor supports the notion of * a default security group, then that should be returned. Otherwise, * the implementation will be vendor-specific. * * @return * @throws java.io.IOException */ public static String getSecurityGroupName() throws IOException { // For AWS, we are returning the first security group from the list // that is obtained by querying the meta-data. String url = getMetadataUrl() + "/security-groups"; String groups = invokeUrl(url); if ((groups == null) || (groups.trim().length() == 0)) { String msg = "No security-group assigned to the instance"; throw new IllegalStateException(msg); } StringTokenizer tokenizer = new StringTokenizer(groups, "\n"); return tokenizer.nextToken(); // We only need the first one. }