List of usage examples for com.amazonaws.services.autoscaling.model Tag Tag
Tag
From source file:gobblin.aws.GobblinAWSClusterLauncher.java
License:Apache License
@VisibleForTesting Optional<String> getReconnectableClusterId() throws IOException { // List ASGs with Tag of cluster name final Tag clusterNameTag = new Tag().withKey(CLUSTER_NAME_ASG_TAG).withValue(this.clusterName); final List<AutoScalingGroup> autoScalingGroups = this.awsSdkClient .getAutoScalingGroupsWithTag(clusterNameTag); // If no auto scaling group is found, we don't have an existing cluster to connect to if (autoScalingGroups.size() == 0) { return Optional.absent(); }//ww w . ja v a2s . co m // If more than 0 auto scaling groups are found, validate the setup if (autoScalingGroups.size() != 2) { throw new IOException("Expected 2 auto scaling groups (1 each for master and workers) but found: " + autoScalingGroups.size()); } // Retrieve cluster information from ASGs Optional<String> clusterId = Optional.absent(); Optional<AutoScalingGroup> masterAsg = Optional.absent(); Optional<AutoScalingGroup> workersAsg = Optional.absent(); for (TagDescription tagDescription : autoScalingGroups.get(0).getTags()) { LOGGER.info("Found tag: " + tagDescription); if (tagDescription.getKey().equalsIgnoreCase(CLUSTER_ID_ASG_TAG)) { clusterId = Optional.of(tagDescription.getValue()); } if (tagDescription.getKey().equalsIgnoreCase(ASG_TYPE_ASG_TAG)) { if (tagDescription.getValue().equalsIgnoreCase(ASG_TYPE_MASTER)) { masterAsg = Optional.of(autoScalingGroups.get(0)); workersAsg = Optional.of(autoScalingGroups.get(1)); } else { masterAsg = Optional.of(autoScalingGroups.get(1)); workersAsg = Optional.of(autoScalingGroups.get(0)); } } } if (!clusterId.isPresent()) { throw new IOException("Found 2 auto scaling group names for: " + this.clusterName + " but tags seem to be corrupted, hence could not determine cluster id"); } if (!masterAsg.isPresent() || !workersAsg.isPresent()) { throw new IOException("Found 2 auto scaling group names for: " + this.clusterName + " but tags seem to be corrupted, hence could not determine master and workers ASG"); } // Get Master and Workers launch config name and auto scaling group name this.masterAutoScalingGroupName = masterAsg.get().getAutoScalingGroupName(); this.masterLaunchConfigName = masterAsg.get().getLaunchConfigurationName(); this.workerAutoScalingGroupName = workersAsg.get().getAutoScalingGroupName(); this.workerLaunchConfigName = workersAsg.get().getLaunchConfigurationName(); LOGGER.info("Trying to find cluster master public ip"); this.masterPublicIp = getMasterPublicIp(); LOGGER.info("Master public ip: " + this.masterPublicIp); return clusterId; }
From source file:gobblin.aws.GobblinAWSClusterLauncher.java
License:Apache License
private String launchClusterMaster(String uuid, String keyName, String securityGroups, AvailabilityZone availabilityZone) { // Get cloud-init script to launch cluster master final String userData = CloudInitScriptBuilder.buildClusterMasterCommand(this.clusterName, this.nfsParentDir, this.sinkLogRootDir, this.awsConfDir, this.appWorkDir, this.masterS3ConfUri, this.masterS3ConfFiles, this.masterS3JarsUri, this.masterS3JarsFiles, this.masterJarsDir, this.masterJvmMemory, this.masterJvmArgs, this.gobblinVersion); // Create launch config for Cluster master this.masterLaunchConfigName = MASTER_LAUNCH_CONFIG_NAME_PREFIX + uuid; this.awsSdkClient.createLaunchConfig(this.masterLaunchConfigName, this.masterAmiId, this.masterInstanceType, keyName, securityGroups, Optional.<String>absent(), Optional.<String>absent(), Optional.<BlockDeviceMapping>absent(), Optional.<String>absent(), Optional.<InstanceMonitoring>absent(), userData); // Create ASG for Cluster master // TODO: Make size configurable when we have support multi-master this.masterAutoScalingGroupName = MASTER_ASG_NAME_PREFIX + uuid; final int minNumMasters = 1; final int maxNumMasters = 1; final int desiredNumMasters = 1; final Tag clusterNameTag = new Tag().withKey(CLUSTER_NAME_ASG_TAG).withValue(this.clusterName); final Tag clusterUuidTag = new Tag().withKey(CLUSTER_ID_ASG_TAG).withValue(uuid); final Tag asgTypeTag = new Tag().withKey(ASG_TYPE_ASG_TAG).withValue(ASG_TYPE_MASTER); this.awsSdkClient.createAutoScalingGroup(this.masterAutoScalingGroupName, this.masterLaunchConfigName, minNumMasters, maxNumMasters, desiredNumMasters, Optional.of(availabilityZone.getZoneName()), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<String>absent(), Lists.newArrayList(clusterNameTag, clusterUuidTag, asgTypeTag)); LOGGER.info("Waiting for cluster master to launch"); this.masterPublicIp = getMasterPublicIp(); LOGGER.info("Master public ip: " + this.masterPublicIp); return uuid;//from www .j a va 2s . c o m }
From source file:gobblin.aws.GobblinAWSClusterLauncher.java
License:Apache License
private void launchWorkUnitRunners(String uuid, String keyName, String securityGroups, AvailabilityZone availabilityZone) { // Get cloud-init script to launch cluster worker final String userData = CloudInitScriptBuilder.buildClusterWorkerCommand(this.clusterName, this.nfsParentDir, this.sinkLogRootDir, this.awsConfDir, this.appWorkDir, this.masterPublicIp, this.workerS3ConfUri, this.workerS3ConfFiles, this.workerS3JarsUri, this.workerS3JarsFiles, this.workerJarsDir, this.workerJvmMemory, this.workerJvmArgs, this.gobblinVersion); // Create launch config for Cluster worker this.workerLaunchConfigName = WORKERS_LAUNCH_CONFIG_PREFIX + uuid; this.awsSdkClient.createLaunchConfig(this.workerLaunchConfigName, this.workerAmiId, this.workerInstanceType, keyName, securityGroups, Optional.<String>absent(), Optional.<String>absent(), Optional.<BlockDeviceMapping>absent(), Optional.<String>absent(), Optional.<InstanceMonitoring>absent(), userData); // Create ASG for Cluster workers this.workerAutoScalingGroupName = WORKERS_ASG_NAME_PREFIX + uuid; final Tag clusterNameTag = new Tag().withKey(CLUSTER_NAME_ASG_TAG).withValue(this.clusterName); final Tag clusterUuidTag = new Tag().withKey(CLUSTER_ID_ASG_TAG).withValue(uuid); final Tag asgTypeTag = new Tag().withKey(ASG_TYPE_ASG_TAG).withValue(ASG_TYPE_WORKERS); this.awsSdkClient.createAutoScalingGroup(this.workerAutoScalingGroupName, this.workerLaunchConfigName, this.minWorkers, this.maxWorkers, this.desiredWorkers, Optional.of(availabilityZone.getZoneName()), Optional.<Integer>absent(), Optional.<Integer>absent(), Optional.<String>absent(), Optional.<String>absent(), Optional.<String>absent(), Lists.newArrayList(clusterNameTag, clusterUuidTag, asgTypeTag)); }