コード例 #1
0
 @Override
 public ResourceAction perform(
     ResourceAction oldResourceAction, ResourceAction newResourceAction) throws Exception {
   AWSEC2VolumeResourceAction oldAction = (AWSEC2VolumeResourceAction) oldResourceAction;
   AWSEC2VolumeResourceAction newAction = (AWSEC2VolumeResourceAction) newResourceAction;
   ServiceConfiguration configuration = Topology.lookup(Compute.class);
   DescribeVolumeAttributeType describeVolumeAttributeType =
       MessageHelper.createMessage(
           DescribeVolumeAttributeType.class, newAction.info.getEffectiveUserId());
   describeVolumeAttributeType.setVolumeId(newAction.info.getPhysicalResourceId());
   describeVolumeAttributeType.setAttribute("autoEnableIO");
   DescribeVolumeAttributeResponseType describeVolumeAttributeResponseType =
       AsyncRequests.sendSync(configuration, describeVolumeAttributeType);
   Boolean originalValue = null;
   if (describeVolumeAttributeResponseType != null) {
     originalValue = describeVolumeAttributeResponseType.getAutoEnableIO();
   }
   if (!Objects.equals(originalValue, newAction.properties.getAutoEnableIO())) {
     ModifyVolumeAttributeType modifyVolumeAttributeTypeType =
         MessageHelper.createMessage(
             ModifyVolumeAttributeType.class, newAction.info.getEffectiveUserId());
     modifyVolumeAttributeTypeType.setVolumeId(newAction.info.getPhysicalResourceId());
     modifyVolumeAttributeTypeType.setAutoEnableIO(newAction.properties.getAutoEnableIO());
     AsyncRequests.sendSync(configuration, modifyVolumeAttributeTypeType);
   }
   return newAction;
 }
コード例 #2
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSEC2VolumeResourceAction action = (AWSEC2VolumeResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Compute.class);
   // Create 'system' tags as admin user
   String effectiveAdminUserId =
       Accounts.lookupPrincipalByAccountNumber(
               Accounts.lookupPrincipalByUserId(action.info.getEffectiveUserId())
                   .getAccountNumber())
           .getUserId();
   CreateTagsType createSystemTagsType =
       MessageHelper.createPrivilegedMessage(CreateTagsType.class, effectiveAdminUserId);
   createSystemTagsType.setResourcesSet(
       Lists.newArrayList(action.info.getPhysicalResourceId()));
   createSystemTagsType.setTagSet(
       EC2Helper.createTagSet(
           TagHelper.getEC2SystemTags(action.info, action.getStackEntity())));
   AsyncRequests.<CreateTagsType, CreateTagsResponseType>sendSync(
       configuration, createSystemTagsType);
   // Create non-system tags as regular user
   List<EC2Tag> tags = TagHelper.getEC2StackTags(action.getStackEntity());
   if (action.properties.getTags() != null && !action.properties.getTags().isEmpty()) {
     TagHelper.checkReservedEC2TemplateTags(action.properties.getTags());
     tags.addAll(action.properties.getTags());
   }
   if (!tags.isEmpty()) {
     CreateTagsType createTagsType =
         MessageHelper.createMessage(CreateTagsType.class, action.info.getEffectiveUserId());
     createTagsType.setResourcesSet(Lists.newArrayList(action.info.getPhysicalResourceId()));
     createTagsType.setTagSet(EC2Helper.createTagSet(tags));
     AsyncRequests.<CreateTagsType, CreateTagsResponseType>sendSync(
         configuration, createTagsType);
   }
   return action;
 }
コード例 #3
0
 @Override
 public ResourceAction perform(
     ResourceAction oldResourceAction, ResourceAction newResourceAction) throws Exception {
   AWSIAMInstanceProfileResourceAction oldAction =
       (AWSIAMInstanceProfileResourceAction) oldResourceAction;
   AWSIAMInstanceProfileResourceAction newAction =
       (AWSIAMInstanceProfileResourceAction) newResourceAction;
   ServiceConfiguration configuration = Topology.lookup(Euare.class);
   // This is a weird case.  There can be only 1 role per instance profile, but the API might
   // allow more.
   // As such, we delete the current role if it exists.
   GetInstanceProfileType getInstanceProfileType =
       MessageHelper.createMessage(
           GetInstanceProfileType.class, newAction.info.getEffectiveUserId());
   getInstanceProfileType.setInstanceProfileName(newAction.info.getPhysicalResourceId());
   GetInstanceProfileResponseType getInstanceProfileResponseType =
       AsyncRequests.<GetInstanceProfileType, GetInstanceProfileResponseType>sendSync(
           configuration, getInstanceProfileType);
   for (String roleName : getRoleNames(getInstanceProfileResponseType)) {
     RemoveRoleFromInstanceProfileType removeRoleFromInstanceProfileType =
         MessageHelper.createMessage(
             RemoveRoleFromInstanceProfileType.class, newAction.info.getEffectiveUserId());
     removeRoleFromInstanceProfileType.setInstanceProfileName(
         newAction.info.getPhysicalResourceId());
     removeRoleFromInstanceProfileType.setRoleName(roleName);
     AsyncRequests
         .<RemoveRoleFromInstanceProfileType, RemoveRoleFromInstanceProfileResponseType>
             sendSync(configuration, removeRoleFromInstanceProfileType);
   }
   if (newAction.properties.getRoles() != null) {
     if (newAction.properties.getRoles().size() == 0)
       throw new ValidationErrorException("Property Roles can not be empty.");
     if (newAction.properties.getRoles().size() > 1)
       throw new ValidationErrorException("Roles has too many elements. The limit is 1.");
     for (String roleName : newAction.properties.getRoles()) {
       AddRoleToInstanceProfileType addRoleToInstanceProfileType =
           MessageHelper.createMessage(
               AddRoleToInstanceProfileType.class, newAction.info.getEffectiveUserId());
       addRoleToInstanceProfileType.setInstanceProfileName(
           newAction.info.getPhysicalResourceId());
       addRoleToInstanceProfileType.setRoleName(roleName);
       AsyncRequests
           .<AddRoleToInstanceProfileType, AddRoleToInstanceProfileResponseType>sendSync(
               configuration, addRoleToInstanceProfileType);
     }
   }
   return newAction;
 }
コード例 #4
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSEC2VolumeResourceAction action = (AWSEC2VolumeResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Compute.class);
   if (volumeDeleted(action, configuration)) return action;
   if (!("Snapshot".equals(action.info.getDeletionPolicy()))) return action;
   DescribeSnapshotsType describeSnapshotsType =
       MessageHelper.createMessage(
           DescribeSnapshotsType.class, action.info.getEffectiveUserId());
   String snapshotId =
       JsonHelper.getJsonNodeFromString(action.info.getSnapshotIdForDelete()).asText();
   describeSnapshotsType.getFilterSet().add(Filter.filter("snapshot-id", snapshotId));
   DescribeSnapshotsResponseType describeSnapshotsResponseType =
       AsyncRequests.sendSync(configuration, describeSnapshotsType);
   if (describeSnapshotsResponseType.getSnapshotSet() == null
       || describeSnapshotsResponseType.getSnapshotSet().isEmpty()) {
     throw new RetryAfterConditionCheckFailedException(
         "Snapshot " + snapshotId + " not yet complete");
   }
   if ("error".equals(describeSnapshotsResponseType.getSnapshotSet().get(0).getStatus())) {
     throw new ResourceFailureException(
         "Error creating snapshot "
             + snapshotId
             + ", while deleting volume "
             + action.info.getPhysicalResourceId());
   } else if (!"completed"
       .equals(describeSnapshotsResponseType.getSnapshotSet().get(0).getStatus())) {
     throw new RetryAfterConditionCheckFailedException(
         "Snapshot " + snapshotId + " not yet complete");
   }
   return action;
 }
コード例 #5
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSEC2VolumeResourceAction action = (AWSEC2VolumeResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Compute.class);
   DescribeVolumesType describeVolumesType =
       MessageHelper.createMessage(
           DescribeVolumesType.class, action.info.getEffectiveUserId());
   describeVolumesType
       .getFilterSet()
       .add(Filter.filter("volume-id", action.info.getPhysicalResourceId()));
   DescribeVolumesResponseType describeVolumesResponseType;
   try {
     describeVolumesResponseType = AsyncRequests.sendSync(configuration, describeVolumesType);
   } catch (final Exception e) {
     throw new ValidationErrorException(
         "Error describing volume "
             + action.info.getPhysicalResourceId()
             + ":"
             + asWebServiceErrorMessage(e, e.getMessage()));
   }
   if (describeVolumesResponseType.getVolumeSet().size() == 0) {
     throw new RetryAfterConditionCheckFailedException(
         "Volume " + action.info.getPhysicalResourceId() + " not yet available");
   }
   if (!"available".equals(describeVolumesResponseType.getVolumeSet().get(0).getStatus())) {
     throw new RetryAfterConditionCheckFailedException(
         "Volume " + action.info.getPhysicalResourceId() + " not yet available");
   }
   return action;
 }
コード例 #6
0
      @Override
      public ResourceAction perform(ResourceAction resourceAction) throws Exception {
        AWSEC2VolumeResourceAction action = (AWSEC2VolumeResourceAction) resourceAction;
        ServiceConfiguration configuration = Topology.lookup(Compute.class);
        CreateVolumeType createVolumeType =
            MessageHelper.createMessage(CreateVolumeType.class, action.info.getEffectiveUserId());
        createVolumeType.setAvailabilityZone(action.properties.getAvailabilityZone());
        if (action.properties.getEncrypted() != null) {
          createVolumeType.setEncrypted(action.properties.getEncrypted());
        }
        // KmsKeyId not supported
        if (action.properties.getIops() != null) {
          createVolumeType.setIops(action.properties.getIops());
        }
        if (action.properties.getSize() != null) {
          createVolumeType.setSize(action.properties.getSize());
        }
        if (action.properties.getSnapshotId() != null) {
          createVolumeType.setSnapshotId(action.properties.getSnapshotId());
        }
        if (action.properties.getVolumeType() != null) {
          createVolumeType.setVolumeType(action.properties.getVolumeType());
        } else {
          createVolumeType.setVolumeType("standard");
        }

        CreateVolumeResponseType createVolumeResponseType =
            AsyncRequests.<CreateVolumeType, CreateVolumeResponseType>sendSync(
                configuration, createVolumeType);
        action.info.setPhysicalResourceId(createVolumeResponseType.getVolume().getVolumeId());
        action.info.setCreatedEnoughToDelete(true);
        action.info.setReferenceValueJson(
            JsonHelper.getStringFromJsonNode(new TextNode(action.info.getPhysicalResourceId())));
        return action;
      }
コード例 #7
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSIAMInstanceProfileResourceAction action =
       (AWSIAMInstanceProfileResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Euare.class);
   String instanceProfileName = action.getDefaultPhysicalResourceId();
   CreateInstanceProfileType createInstanceProfileType =
       MessageHelper.createMessage(
           CreateInstanceProfileType.class, action.info.getEffectiveUserId());
   createInstanceProfileType.setPath(action.properties.getPath());
   createInstanceProfileType.setInstanceProfileName(instanceProfileName);
   CreateInstanceProfileResponseType createInstanceProfileResponseType =
       AsyncRequests.<CreateInstanceProfileType, CreateInstanceProfileResponseType>sendSync(
           configuration, createInstanceProfileType);
   String arn =
       createInstanceProfileResponseType
           .getCreateInstanceProfileResult()
           .getInstanceProfile()
           .getArn();
   action.info.setPhysicalResourceId(instanceProfileName);
   action.info.setCreatedEnoughToDelete(true);
   action.info.setArn(JsonHelper.getStringFromJsonNode(new TextNode(arn)));
   action.info.setReferenceValueJson(
       JsonHelper.getStringFromJsonNode(new TextNode(action.info.getPhysicalResourceId())));
   return action;
 }
コード例 #8
0
 private static boolean volumeDeleted(
     AWSEC2VolumeResourceAction action, ServiceConfiguration configuration) throws Exception {
   if (!Boolean.TRUE.equals(action.info.getCreatedEnoughToDelete())) return true;
   DescribeVolumesType describeVolumesType =
       MessageHelper.createMessage(DescribeVolumesType.class, action.info.getEffectiveUserId());
   describeVolumesType
       .getFilterSet()
       .add(Filter.filter("volume-id", action.info.getPhysicalResourceId()));
   DescribeVolumesResponseType describeVolumesResponseType;
   try {
     describeVolumesResponseType = AsyncRequests.sendSync(configuration, describeVolumesType);
   } catch (final Exception e) {
     throw new ValidationErrorException(
         "Error describing volume "
             + action.info.getPhysicalResourceId()
             + ":"
             + asWebServiceErrorMessage(e, e.getMessage()));
   }
   if (describeVolumesResponseType.getVolumeSet().size() == 0) {
     return true; // already deleted
   }
   if ("deleted".equals(describeVolumesResponseType.getVolumeSet().get(0).getStatus())) {
     return true;
   }
   return false;
 }
 private void disassociateRouteTable(ServiceConfiguration configuration, String associationId)
     throws Exception {
   DisassociateRouteTableType disassociateRouteTableType =
       MessageHelper.createMessage(DisassociateRouteTableType.class, info.getEffectiveUserId());
   disassociateRouteTableType.setAssociationId(associationId);
   AsyncRequests.<DisassociateRouteTableType, DisassociateRouteTableResponseType>sendSync(
       configuration, disassociateRouteTableType);
 }
コード例 #10
0
 public static void handleOrphan(Cluster cluster, ClusterAddressInfo address) {
   Integer orphanCount = 1;
   orphanCount = orphans.putIfAbsent(address, orphanCount);
   orphanCount = (orphanCount == null) ? 1 : orphanCount;
   orphans.put(address, orphanCount + 1);
   EventRecord.caller(
           ClusterState.class,
           EventType.ADDRESS_STATE,
           "Updated orphaned public ip address: "
               + LogUtil.dumpObject(address)
               + " count="
               + orphanCount)
       .debug();
   if (orphanCount > AddressingConfiguration.getInstance().getMaxKillOrphans()) {
     EventRecord.caller(
             ClusterState.class,
             EventType.ADDRESS_STATE,
             "Unassigning orphaned public ip address: "
                 + LogUtil.dumpObject(address)
                 + " count="
                 + orphanCount)
         .warn();
     try {
       final Address addr = Addresses.getInstance().lookup(address.getAddress());
       if (addr.isPending()) {
         try {
           addr.clearPending();
         } catch (Exception ex) {
         }
       }
       try {
         if (addr.isAssigned() && "0.0.0.0".equals(address.getInstanceIp())) {
           addr.unassign().clearPending();
           if (addr.isSystemOwned()) {
             addr.release();
           }
         } else if (addr.isAssigned() && !"0.0.0.0".equals(address.getInstanceIp())) {
           AsyncRequests.newRequest(new UnassignAddressCallback(address))
               .sendSync(cluster.getConfiguration());
           if (addr.isSystemOwned()) {
             addr.release();
           }
         } else if (!addr.isAssigned() && addr.isAllocated() && addr.isSystemOwned()) {
           addr.release();
         }
       } catch (ExecutionException ex) {
         if (!addr.isAssigned() && addr.isAllocated() && addr.isSystemOwned()) {
           addr.release();
         }
       }
     } catch (InterruptedException ex) {
       Exceptions.maybeInterrupted(ex);
     } catch (NoSuchElementException ex) {
     } finally {
       orphans.remove(address);
     }
   }
 }
 private String associateRouteTable(
     ServiceConfiguration configuration, String subnetId, String routeTableId) throws Exception {
   AssociateRouteTableType associateRouteTableType =
       MessageHelper.createMessage(AssociateRouteTableType.class, info.getEffectiveUserId());
   associateRouteTableType.setRouteTableId(routeTableId);
   associateRouteTableType.setSubnetId(subnetId);
   AssociateRouteTableResponseType associateRouteTableResponseType =
       AsyncRequests.<AssociateRouteTableType, AssociateRouteTableResponseType>sendSync(
           configuration, associateRouteTableType);
   return associateRouteTableResponseType.getAssociationId();
 }
コード例 #12
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSEC2VolumeResourceAction action = (AWSEC2VolumeResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Compute.class);
   if (volumeDeleted(action, configuration)) return action;
   DeleteVolumeType deleteVolumeType =
       MessageHelper.createMessage(DeleteVolumeType.class, action.info.getEffectiveUserId());
   deleteVolumeType.setVolumeId(action.info.getPhysicalResourceId());
   AsyncRequests.<DeleteVolumeType, DeleteVolumeResponseType>sendSync(
       configuration, deleteVolumeType);
   return action;
 }
 private void checkSubnetExists(ServiceConfiguration configuration) throws Exception {
   DescribeSubnetsType describeSubnetsType =
       MessageHelper.createMessage(DescribeSubnetsType.class, info.getEffectiveUserId());
   describeSubnetsType.getFilterSet().add(Filter.filter("subnet-id", properties.getSubnetId()));
   DescribeSubnetsResponseType describeSubnetsResponseType =
       AsyncRequests.sendSync(configuration, describeSubnetsType);
   if (describeSubnetsResponseType.getSubnetSet() == null
       || describeSubnetsResponseType.getSubnetSet().getItem() == null
       || describeSubnetsResponseType.getSubnetSet().getItem().isEmpty()) {
     throw new ValidationErrorException("No such subnet with id '" + properties.getSubnetId());
   }
 }
 private boolean subnetExistsForDelete(ServiceConfiguration configuration) throws Exception {
   DescribeSubnetsType describeSubnetsType =
       MessageHelper.createMessage(DescribeSubnetsType.class, info.getEffectiveUserId());
   describeSubnetsType.getFilterSet().add(Filter.filter("subnet-id", properties.getSubnetId()));
   DescribeSubnetsResponseType describeSubnetsResponseType =
       AsyncRequests.sendSync(configuration, describeSubnetsType);
   if (describeSubnetsResponseType.getSubnetSet() == null
       || describeSubnetsResponseType.getSubnetSet().getItem() == null
       || describeSubnetsResponseType.getSubnetSet().getItem().isEmpty()) {
     return false;
   }
   return true;
 }
 @Override
 public void delete() throws Exception {
   if (info.getPhysicalResourceId() == null) return;
   ServiceConfiguration configuration = Topology.lookup(LoadBalancing.class);
   // if lb gone, done
   DescribeLoadBalancersType describeLoadBalancersType = new DescribeLoadBalancersType();
   LoadBalancerNames loadBalancerNames = new LoadBalancerNames();
   ArrayList<String> member = Lists.newArrayList(info.getPhysicalResourceId());
   loadBalancerNames.setMember(member);
   describeLoadBalancersType.setLoadBalancerNames(loadBalancerNames);
   describeLoadBalancersType.setEffectiveUserId(info.getEffectiveUserId());
   DescribeLoadBalancersResponseType describeLoadBalancersResponseType =
       AsyncRequests.<DescribeLoadBalancersType, DescribeLoadBalancersResponseType>sendSync(
           configuration, describeLoadBalancersType);
   if (describeLoadBalancersResponseType != null
       && describeLoadBalancersResponseType.getDescribeLoadBalancersResult() != null
       && describeLoadBalancersResponseType
               .getDescribeLoadBalancersResult()
               .getLoadBalancerDescriptions()
           != null
       && describeLoadBalancersResponseType
               .getDescribeLoadBalancersResult()
               .getLoadBalancerDescriptions()
               .getMember()
           != null
       && describeLoadBalancersResponseType
               .getDescribeLoadBalancersResult()
               .getLoadBalancerDescriptions()
               .getMember()
               .size()
           > 0) {
     return;
   }
   DeleteLoadBalancerType deleteLoadBalancerType = new DeleteLoadBalancerType();
   deleteLoadBalancerType.setLoadBalancerName(info.getPhysicalResourceId());
   deleteLoadBalancerType.setEffectiveUserId(info.getEffectiveUserId());
   AsyncRequests.<DeleteLoadBalancerType, DeleteLoadBalancerResponseType>sendSync(
       configuration, deleteLoadBalancerType);
 }
 private String replaceAssociation(
     ServiceConfiguration configuration, String oldAssociationId, String routeTableId)
     throws Exception {
   ReplaceRouteTableAssociationType replaceRouteTableAssociationType =
       MessageHelper.createMessage(
           ReplaceRouteTableAssociationType.class, info.getEffectiveUserId());
   replaceRouteTableAssociationType.setRouteTableId(routeTableId);
   replaceRouteTableAssociationType.setAssociationId(oldAssociationId);
   ReplaceRouteTableAssociationResponseType replaceRouteTableAssociationResponseType =
       AsyncRequests
           .<ReplaceRouteTableAssociationType, ReplaceRouteTableAssociationResponseType>sendSync(
               configuration, replaceRouteTableAssociationType);
   return replaceRouteTableAssociationResponseType.getNewAssociationId();
 }
コード例 #17
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSEC2VolumeResourceAction action = (AWSEC2VolumeResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Compute.class);
   if (action.properties.getAutoEnableIO() != null) {
     ModifyVolumeAttributeType modifyVolumeAttributeTypeType =
         MessageHelper.createMessage(
             ModifyVolumeAttributeType.class, action.info.getEffectiveUserId());
     modifyVolumeAttributeTypeType.setVolumeId(action.info.getPhysicalResourceId());
     modifyVolumeAttributeTypeType.setAutoEnableIO(action.properties.getAutoEnableIO());
     AsyncRequests.sendSync(configuration, modifyVolumeAttributeTypeType);
   }
   return action;
 }
コード例 #18
0
 @Override
 public void fireException(Throwable e) {
   LOG.debug(e);
   Logs.extreme().error(e, e);
   LOG.debug(
       "Trying to remove invalid volume attachment "
           + this.getRequest().getVolumeId()
           + " from instance "
           + this.getRequest().getInstanceId());
   try {
     VmInstance vm = VmInstances.lookup(this.getRequest().getInstanceId());
     Partition partition = vm.lookupPartition();
     ServiceConfiguration sc = Topology.lookup(Storage.class, partition);
     /** clean up SC session state * */
     try {
       LOG.debug(
           "Sending detach after async failure in attach volume: "
               + this.getRequest().getVolumeId()
               + " sc="
               + sc);
       AsyncRequests.sendSync(sc, new DetachStorageVolumeType(this.getRequest().getVolumeId()));
     } catch (Exception ex) {
       LOG.error(ex);
       Logs.extreme().error(ex, ex);
     }
     /** clean up internal attachment state * */
     final Function<String, VmInstance> removeVolAttachment =
         new Function<String, VmInstance>() {
           public VmInstance apply(final String input) {
             VmInstance vm = VmInstances.lookup(input);
             vm.removeVolumeAttachment(VolumeAttachCallback.this.getRequest().getVolumeId());
             return vm;
           }
         };
     Entities.asTransaction(VmInstance.class, removeVolAttachment)
         .apply(this.getRequest().getInstanceId());
     LOG.debug(
         "Removed failed attachment: "
             + this.getRequest().getVolumeId()
             + " -> "
             + vm.getInstanceId());
   } catch (Exception e1) {
     LOG.error(e1);
     Logs.extreme().error(e1, e1);
   }
 }
コード例 #19
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSIAMPolicyResourceAction action = (AWSIAMPolicyResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Euare.class);
   if (action.properties.getGroups() != null) {
     for (String groupName : action.properties.getGroups()) {
       PutGroupPolicyType putGroupPolicyType =
           MessageHelper.createMessage(
               PutGroupPolicyType.class, action.info.getEffectiveUserId());
       putGroupPolicyType.setGroupName(groupName);
       putGroupPolicyType.setPolicyName(action.properties.getPolicyName());
       putGroupPolicyType.setPolicyDocument(action.properties.getPolicyDocument().toString());
       AsyncRequests.<PutGroupPolicyType, PutGroupPolicyResponseType>sendSync(
           configuration, putGroupPolicyType);
     }
   }
   return action;
 }
コード例 #20
0
      @Override
      public ResourceAction perform(ResourceAction resourceAction) throws Exception {
        AWSIAMInstanceProfileResourceAction action =
            (AWSIAMInstanceProfileResourceAction) resourceAction;
        ServiceConfiguration configuration = Topology.lookup(Euare.class);
        if (!Boolean.TRUE.equals(action.info.getCreatedEnoughToDelete())) return action;

        if (!IAMHelper.instanceProfileExists(
            configuration, action.info.getPhysicalResourceId(), action.info.getEffectiveUserId()))
          return action;

        // we can delete the instance profile without detaching the role
        DeleteInstanceProfileType deleteInstanceProfileType =
            MessageHelper.createMessage(
                DeleteInstanceProfileType.class, action.info.getEffectiveUserId());
        deleteInstanceProfileType.setInstanceProfileName(action.info.getPhysicalResourceId());
        AsyncRequests.<DeleteInstanceProfileType, DeleteInstanceProfileResponseType>sendSync(
            configuration, deleteInstanceProfileType);
        return action;
      }
コード例 #21
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSIAMInstanceProfileResourceAction action =
       (AWSIAMInstanceProfileResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Euare.class);
   if (action.properties.getRoles() != null) {
     for (String roleName : action.properties.getRoles()) {
       AddRoleToInstanceProfileType addRoleToInstanceProfileType =
           MessageHelper.createMessage(
               AddRoleToInstanceProfileType.class, action.info.getEffectiveUserId());
       addRoleToInstanceProfileType.setInstanceProfileName(
           action.info.getPhysicalResourceId());
       addRoleToInstanceProfileType.setRoleName(roleName);
       AsyncRequests
           .<AddRoleToInstanceProfileType, AddRoleToInstanceProfileResponseType>sendSync(
               configuration, addRoleToInstanceProfileType);
     }
   }
   return action;
 }
 private boolean associationIdExistsForDelete(ServiceConfiguration configuration)
     throws Exception {
   DescribeRouteTablesType describeRouteTablesType =
       MessageHelper.createMessage(DescribeRouteTablesType.class, info.getEffectiveUserId());
   ArrayList<Filter> filterSet = Lists.newArrayList();
   ;
   Filter filter = new Filter();
   filter.setName("association.route-table-association-id");
   filter.setValueSet(Lists.<String>newArrayList(info.getPhysicalResourceId()));
   filterSet.add(filter);
   describeRouteTablesType.setFilterSet(filterSet);
   DescribeRouteTablesResponseType describeRouteTablesResponseType =
       AsyncRequests.<DescribeRouteTablesType, DescribeRouteTablesResponseType>sendSync(
           configuration, describeRouteTablesType);
   if (describeRouteTablesResponseType.getRouteTableSet() == null
       || describeRouteTablesResponseType.getRouteTableSet().getItem() == null
       || describeRouteTablesResponseType.getRouteTableSet().getItem().isEmpty()) {
     return false;
   }
   return true;
 }
コード例 #23
0
ファイル: Volumes.java プロジェクト: hughe/eucalyptus
 static Map<String, StorageVolume> updateVolumesInPartition(final String partition) {
   final Map<String, StorageVolume> idStorageVolumeMap = Maps.newHashMap();
   final ServiceConfiguration scConfig =
       Topology.lookup(Storage.class, Partitions.lookupByName(partition));
   try {
     final DescribeStorageVolumesResponseType volState =
         AsyncRequests.sendSync(scConfig, new DescribeStorageVolumesType());
     for (final StorageVolume vol : volState.getVolumeSet()) {
       LOG.trace(
           "Volume states: "
               + vol.getVolumeId()
               + " "
               + vol.getStatus()
               + " "
               + vol.getActualDeviceName());
       idStorageVolumeMap.put(vol.getVolumeId(), vol);
     }
   } catch (final Exception ex) {
     LOG.error(ex);
     Logs.extreme().error(ex, ex);
   }
   return idStorageVolumeMap;
 }
コード例 #24
0
 private void clearState() {
   EventRecord.here(
           AssignAddressCallback.class,
           EventType.ADDRESS_ASSIGNING,
           Transition.assigning.toString(),
           "FAILED",
           this.address.toString())
       .debug();
   if (this.address.isPending()) {
     try {
       this.address.clearPending();
     } catch (Exception ex) {
     }
   }
   if (this.address.isSystemOwned()) {
     Addresses.release(this.address);
   } else if (this.address.isAssigned() && this.vm != null) {
     AddressingDispatcher.dispatch(
         AsyncRequests.newRequest(this.address.unassign().getCallback()), vm.getPartition());
   } else if (this.address.isAssigned() && this.vm == null) {
     this.address.unassign().clearPending();
   }
 }
コード例 #25
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSEC2VolumeResourceAction action = (AWSEC2VolumeResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Compute.class);
   if (volumeDeleted(action, configuration)) return action;
   if (!("Snapshot".equals(action.info.getDeletionPolicy()))) return action;
   CreateSnapshotType createSnapshotType =
       MessageHelper.createMessage(CreateSnapshotType.class, action.info.getEffectiveUserId());
   createSnapshotType.setVolumeId(action.info.getPhysicalResourceId());
   CreateSnapshotResponseType createSnapshotResponseType =
       AsyncRequests.<CreateSnapshotType, CreateSnapshotResponseType>sendSync(
           configuration, createSnapshotType);
   if (createSnapshotResponseType.getSnapshot() == null
       || createSnapshotResponseType.getSnapshot().getSnapshotId() == null) {
     throw new ResourceFailureException(
         "Unable to create snapshot on delete for volume "
             + action.info.getPhysicalResourceId());
   } else {
     action.info.setSnapshotIdForDelete(
         JsonHelper.getStringFromJsonNode(
             new TextNode(createSnapshotResponseType.getSnapshot().getSnapshotId())));
   }
   return action;
 }
コード例 #26
0
 @Override
 public ResourceAction perform(ResourceAction resourceAction) throws Exception {
   AWSIAMInstanceProfileResourceAction action =
       (AWSIAMInstanceProfileResourceAction) resourceAction;
   ServiceConfiguration configuration = Topology.lookup(Euare.class);
   if (action.properties.getRoles() != null) {
     if (action.properties.getRoles().size() > 1)
       throw new ValidationErrorException("Roles has too many elements. The limit is 1.");
     if (action.properties.getRoles().size() == 0)
       throw new ValidationErrorException("Property Roles can not be empty.");
     for (String roleName : action.properties.getRoles()) {
       AddRoleToInstanceProfileType addRoleToInstanceProfileType =
           MessageHelper.createMessage(
               AddRoleToInstanceProfileType.class, action.info.getEffectiveUserId());
       addRoleToInstanceProfileType.setInstanceProfileName(
           action.info.getPhysicalResourceId());
       addRoleToInstanceProfileType.setRoleName(roleName);
       AsyncRequests
           .<AddRoleToInstanceProfileType, AddRoleToInstanceProfileResponseType>sendSync(
               configuration, addRoleToInstanceProfileType);
     }
   }
   return action;
 }
コード例 #27
0
      @Override
      public ResourceAction perform(ResourceAction resourceAction) throws Exception {
        AWSIAMInstanceProfileResourceAction action =
            (AWSIAMInstanceProfileResourceAction) resourceAction;
        ServiceConfiguration configuration = Topology.lookup(Euare.class);
        if (action.info.getPhysicalResourceId() == null) return action;

        // if no instance profile, bye...
        boolean seenAllInstanceProfiles = false;
        boolean foundInstanceProfile = false;
        String instanceProfileMarker = null;
        while (!seenAllInstanceProfiles && !foundInstanceProfile) {
          ListInstanceProfilesType listInstanceProfilesType =
              MessageHelper.createMessage(
                  ListInstanceProfilesType.class, action.info.getEffectiveUserId());
          if (instanceProfileMarker != null) {
            listInstanceProfilesType.setMarker(instanceProfileMarker);
          }
          ListInstanceProfilesResponseType listInstanceProfilesResponseType =
              AsyncRequests.<ListInstanceProfilesType, ListInstanceProfilesResponseType>sendSync(
                  configuration, listInstanceProfilesType);
          if (listInstanceProfilesResponseType.getListInstanceProfilesResult().getIsTruncated()
              == Boolean.TRUE) {
            instanceProfileMarker =
                listInstanceProfilesResponseType.getListInstanceProfilesResult().getMarker();
          } else {
            seenAllInstanceProfiles = true;
          }
          if (listInstanceProfilesResponseType.getListInstanceProfilesResult().getInstanceProfiles()
                  != null
              && listInstanceProfilesResponseType
                      .getListInstanceProfilesResult()
                      .getInstanceProfiles()
                      .getMember()
                  != null) {
            for (InstanceProfileType instanceProfileType :
                listInstanceProfilesResponseType
                    .getListInstanceProfilesResult()
                    .getInstanceProfiles()
                    .getMember()) {
              if (instanceProfileType
                  .getInstanceProfileName()
                  .equals(action.info.getPhysicalResourceId())) {
                foundInstanceProfile = true;
                break;
              }
            }
          }
        }
        // we can delete the instance profile without detaching the role

        if (!foundInstanceProfile) return action;

        DeleteInstanceProfileType deleteInstanceProfileType =
            MessageHelper.createMessage(
                DeleteInstanceProfileType.class, action.info.getEffectiveUserId());
        deleteInstanceProfileType.setInstanceProfileName(action.info.getPhysicalResourceId());
        AsyncRequests.<DeleteInstanceProfileType, DeleteInstanceProfileResponseType>sendSync(
            configuration, deleteInstanceProfileType);
        return action;
      }
コード例 #28
0
ファイル: VolumeManager.java プロジェクト: sosilent/euca
  public DetachVolumeResponseType detach(DetachVolumeType request) throws EucalyptusCloudException {
    DetachVolumeResponseType reply = (DetachVolumeResponseType) request.getReply();
    Context ctx = Contexts.lookup();

    Volume vol;
    try {
      vol = Volumes.lookup(ctx.getUserFullName().asAccountFullName(), request.getVolumeId());
    } catch (Exception ex1) {
      throw new EucalyptusCloudException("Volume does not exist: " + request.getVolumeId());
    }
    if (!RestrictedTypes.filterPrivileged().apply(vol)) {
      throw new EucalyptusCloudException(
          "Not authorized to detach volume "
              + request.getVolumeId()
              + " by "
              + ctx.getUser().getName());
    }

    VmInstance vm = null;
    AttachedVolume volume = null;
    try {
      VmVolumeAttachment vmVolAttach = VmInstances.lookupVolumeAttachment(request.getVolumeId());
      volume = VmVolumeAttachment.asAttachedVolume(vmVolAttach.getVmInstance()).apply(vmVolAttach);
      vm = vmVolAttach.getVmInstance();
    } catch (NoSuchElementException ex) {
      /** no such attachment * */
    }
    if (volume == null) {
      throw new EucalyptusCloudException("Volume is not attached: " + request.getVolumeId());
    }
    if (!RestrictedTypes.filterPrivileged().apply(vm)) {
      throw new EucalyptusCloudException(
          "Not authorized to detach volume from instance "
              + request.getInstanceId()
              + " by "
              + ctx.getUser().getName());
    }
    if (!vm.getInstanceId().equals(request.getInstanceId())
        && request.getInstanceId() != null
        && !request.getInstanceId().equals("")) {
      throw new EucalyptusCloudException(
          "Volume is not attached to instance: " + request.getInstanceId());
    }
    if (request.getDevice() != null
        && !request.getDevice().equals("")
        && !volume.getDevice().equals(request.getDevice())) {
      throw new EucalyptusCloudException(
          "Volume is not attached to device: " + request.getDevice());
    }

    Cluster cluster = null;
    ServiceConfiguration ccConfig = null;
    try {
      ccConfig = Topology.lookup(ClusterController.class, vm.lookupPartition());
      cluster = Clusters.lookup(ccConfig);
    } catch (NoSuchElementException e) {
      LOG.debug(e, e);
      throw new EucalyptusCloudException(
          "Cluster does not exist in partition: " + vm.getPartition());
    }
    ServiceConfiguration scVm;
    try {
      scVm = Topology.lookup(Storage.class, vm.lookupPartition());
    } catch (Exception ex) {
      LOG.error(ex, ex);
      throw new EucalyptusCloudException(
          "Failed to lookup SC for partition: " + vm.getPartition(), ex);
    }
    request.setVolumeId(volume.getVolumeId());
    request.setRemoteDevice(volume.getRemoteDevice());
    request.setDevice(volume.getDevice().replaceAll("unknown,requested:", ""));
    request.setInstanceId(vm.getInstanceId());
    VolumeDetachCallback ncDetach = new VolumeDetachCallback(request);
    try {
      AsyncRequests.sendSync(scVm, new DetachStorageVolumeType(volume.getVolumeId()));
    } catch (Exception e) {
      LOG.debug(e);
      Logs.extreme().debug(e, e);
      // GRZE: attach is idempotent, failure here is ok.      throw new EucalyptusCloudException(
      // e.getMessage( ) );
    }
    AsyncRequests.newRequest(ncDetach).dispatch(cluster.getConfiguration());
    EventRecord.here(VolumeManager.class, EventClass.VOLUME, EventType.VOLUME_DETACH)
        .withDetails(vm.getOwner().toString(), volume.getVolumeId(), "instance", vm.getInstanceId())
        .withDetails("cluster", ccConfig.getFullName().toString())
        .info();
    volume.setStatus("detaching");
    reply.setDetachedVolume(volume);
    return reply;
  }
コード例 #29
0
      @Override
      public ResourceAction perform(
          ResourceAction oldResourceAction, ResourceAction newResourceAction) throws Exception {
        AWSEC2VolumeResourceAction oldAction = (AWSEC2VolumeResourceAction) oldResourceAction;
        AWSEC2VolumeResourceAction newAction = (AWSEC2VolumeResourceAction) newResourceAction;
        ServiceConfiguration configuration = Topology.lookup(Compute.class);
        DescribeTagsType describeTagsType =
            MessageHelper.createMessage(
                DescribeTagsType.class, newAction.info.getEffectiveUserId());
        describeTagsType.setFilterSet(
            Lists.newArrayList(
                Filter.filter("resource-id", newAction.info.getPhysicalResourceId())));
        DescribeTagsResponseType describeTagsResponseType =
            AsyncRequests.sendSync(configuration, describeTagsType);
        Set<EC2Tag> existingTags = Sets.newLinkedHashSet();
        if (describeTagsResponseType != null && describeTagsResponseType.getTagSet() != null) {
          for (TagInfo tagInfo : describeTagsResponseType.getTagSet()) {
            EC2Tag tag = new EC2Tag();
            tag.setKey(tagInfo.getKey());
            tag.setValue(tagInfo.getValue());
            existingTags.add(tag);
          }
        }
        Set<EC2Tag> newTags = Sets.newLinkedHashSet();
        if (newAction.properties.getTags() != null) {
          newTags.addAll(newAction.properties.getTags());
        }
        List<EC2Tag> newStackTags = TagHelper.getEC2StackTags(newAction.getStackEntity());
        if (newStackTags != null) {
          newTags.addAll(newStackTags);
        }
        TagHelper.checkReservedEC2TemplateTags(newTags);
        // add only 'new' tags
        Set<EC2Tag> onlyNewTags = Sets.difference(newTags, existingTags);
        if (!onlyNewTags.isEmpty()) {
          CreateTagsType createTagsType =
              MessageHelper.createMessage(
                  CreateTagsType.class, newAction.info.getEffectiveUserId());
          createTagsType.setResourcesSet(
              Lists.newArrayList(newAction.info.getPhysicalResourceId()));
          createTagsType.setTagSet(EC2Helper.createTagSet(onlyNewTags));
          AsyncRequests.<CreateTagsType, CreateTagsResponseType>sendSync(
              configuration, createTagsType);
        }
        //  Get old tags...
        Set<EC2Tag> oldTags = Sets.newLinkedHashSet();
        if (oldAction.properties.getTags() != null) {
          oldTags.addAll(oldAction.properties.getTags());
        }
        List<EC2Tag> oldStackTags = TagHelper.getEC2StackTags(oldAction.getStackEntity());
        if (oldStackTags != null) {
          oldTags.addAll(oldStackTags);
        }

        // remove only the old tags that are not new and that exist
        Set<EC2Tag> tagsToRemove =
            Sets.intersection(oldTags, Sets.difference(existingTags, newTags));
        if (!tagsToRemove.isEmpty()) {
          DeleteTagsType deleteTagsType =
              MessageHelper.createMessage(
                  DeleteTagsType.class, newAction.info.getEffectiveUserId());
          deleteTagsType.setResourcesSet(
              Lists.newArrayList(newAction.info.getPhysicalResourceId()));
          deleteTagsType.setTagSet(EC2Helper.deleteTagSet(tagsToRemove));
          AsyncRequests.<DeleteTagsType, DeleteTagsResponseType>sendSync(
              configuration, deleteTagsType);
        }
        return newAction;
      }
  @Override
  public void create(int stepNum) throws Exception {
    ServiceConfiguration configuration = Topology.lookup(LoadBalancing.class);
    switch (stepNum) {
      case 0: // create load balancer
        CreateLoadBalancerType createLoadBalancerType = new CreateLoadBalancerType();
        createLoadBalancerType.setEffectiveUserId(info.getEffectiveUserId());
        if (properties.getLoadBalancerName() == null) {

          // The name here is a little weird.  It needs to be no more than 32 characters
          createLoadBalancerType.setLoadBalancerName(getDefaultPhysicalResourceId(32));
        } else {
          createLoadBalancerType.setLoadBalancerName(properties.getLoadBalancerName());
        }
        if (properties.getAvailabilityZones() != null) {
          AvailabilityZones availabilityZones = new AvailabilityZones();
          ArrayList<String> member = Lists.newArrayList(properties.getAvailabilityZones());
          availabilityZones.setMember(member);
          createLoadBalancerType.setAvailabilityZones(availabilityZones);
        }
        if (properties.getListeners() != null) {
          Listeners listeners = new Listeners();
          ArrayList<Listener> member = Lists.newArrayList();
          for (ElasticLoadBalancingListener elasticLoadBalancingListener :
              properties.getListeners()) {
            Listener listener = new Listener();
            listener.setInstancePort(elasticLoadBalancingListener.getInstancePort());
            listener.setInstanceProtocol(elasticLoadBalancingListener.getInstanceProtocol());
            listener.setLoadBalancerPort(elasticLoadBalancingListener.getLoadBalancerPort());
            listener.setProtocol(elasticLoadBalancingListener.getProtocol());
            listener.setSSLCertificateId(elasticLoadBalancingListener.getSslCertificateId());
            // TO set the policies, look at the next step
            member.add(listener);
          }
          listeners.setMember(member);
          createLoadBalancerType.setListeners(listeners);
        }
        createLoadBalancerType.setScheme(properties.getScheme());
        if (properties.getSecurityGroups() != null) {
          SecurityGroups securityGroups = new SecurityGroups();
          ArrayList<String> member = Lists.newArrayList(properties.getSecurityGroups());
          securityGroups.setMember(member);
          createLoadBalancerType.setSecurityGroups(securityGroups);
        }
        if (properties.getSubnets() != null) {
          Subnets subnets = new Subnets();
          ArrayList<String> member = Lists.newArrayList(properties.getSubnets());
          subnets.setMember(member);
          createLoadBalancerType.setSubnets(subnets);
        }
        CreateLoadBalancerResponseType createLoadBalancerResponseType =
            AsyncRequests.<CreateLoadBalancerType, CreateLoadBalancerResponseType>sendSync(
                configuration, createLoadBalancerType);
        info.setPhysicalResourceId(createLoadBalancerType.getLoadBalancerName());
        info.setDnsName(
            JsonHelper.getStringFromJsonNode(
                new TextNode(
                    createLoadBalancerResponseType.getCreateLoadBalancerResult().getDnsName())));
        info.setReferenceValueJson(
            JsonHelper.getStringFromJsonNode(new TextNode(info.getPhysicalResourceId())));
        break;
      case 1: // add instances to load balancer
        if (properties.getInstances() != null) {
          RegisterInstancesWithLoadBalancerType registerInstancesWithLoadBalancerType =
              new RegisterInstancesWithLoadBalancerType();
          registerInstancesWithLoadBalancerType.setLoadBalancerName(info.getPhysicalResourceId());
          Instances instances = new Instances();
          ArrayList<Instance> member = Lists.newArrayList();
          for (String instanceId : properties.getInstances()) {
            Instance instance = new Instance();
            instance.setInstanceId(instanceId);
            member.add(instance);
          }
          instances.setMember(member);
          registerInstancesWithLoadBalancerType.setInstances(instances);
          registerInstancesWithLoadBalancerType.setEffectiveUserId(info.getEffectiveUserId());
          AsyncRequests
              .<RegisterInstancesWithLoadBalancerType,
                  RegisterInstancesWithLoadBalancerResponseType>
                  sendSync(configuration, registerInstancesWithLoadBalancerType);
        }
        break;
      case 2: // add health check to load balancer
        if (properties.getHealthCheck() != null) {
          ConfigureHealthCheckType configureHealthCheckType = new ConfigureHealthCheckType();
          configureHealthCheckType.setLoadBalancerName(info.getPhysicalResourceId());
          HealthCheck healthCheck = new HealthCheck();
          healthCheck.setHealthyThreshold(properties.getHealthCheck().getHealthyThreshold());
          healthCheck.setInterval(properties.getHealthCheck().getInterval());
          healthCheck.setTarget(properties.getHealthCheck().getTarget());
          healthCheck.setTimeout(properties.getHealthCheck().getTimeout());
          healthCheck.setUnhealthyThreshold(properties.getHealthCheck().getUnhealthyThreshold());
          configureHealthCheckType.setHealthCheck(healthCheck);
          configureHealthCheckType.setEffectiveUserId(info.getEffectiveUserId());
          AsyncRequests.<ConfigureHealthCheckType, ConfigureHealthCheckResponseType>sendSync(
              configuration, configureHealthCheckType);
        }
        break;
      case 3: // add policies to load balancer
        if (properties.getPolicies() != null) {
          for (ElasticLoadBalancingPolicyType elasticLoadBalancingPropertyType :
              properties.getPolicies()) {
            CreateLoadBalancerPolicyType createLoadBalancerPolicyType =
                new CreateLoadBalancerPolicyType();
            createLoadBalancerPolicyType.setLoadBalancerName(info.getPhysicalResourceId());
            if (elasticLoadBalancingPropertyType.getAttributes() != null) {
              PolicyAttributes policyAttributes = new PolicyAttributes();
              ArrayList<PolicyAttribute> member = Lists.newArrayList();
              for (ElasticLoadBalancingPolicyTypeAttribute elasticLoadBalancingPolicyTypeAttribute :
                  elasticLoadBalancingPropertyType.getAttributes()) {
                PolicyAttribute policyAttribute = new PolicyAttribute();
                policyAttribute.setAttributeName(elasticLoadBalancingPolicyTypeAttribute.getName());
                policyAttribute.setAttributeValue(
                    elasticLoadBalancingPolicyTypeAttribute.getValue());
                member.add(policyAttribute);
              }
              policyAttributes.setMember(member);
              createLoadBalancerPolicyType.setPolicyAttributes(policyAttributes);
            }
            createLoadBalancerPolicyType.setPolicyName(
                elasticLoadBalancingPropertyType.getPolicyName());
            createLoadBalancerPolicyType.setPolicyTypeName(
                elasticLoadBalancingPropertyType.getPolicyType());
            createLoadBalancerPolicyType.setEffectiveUserId(info.getEffectiveUserId());
            // NOTE: Cloudformation says that policies have two more fields, "InstanceIds" (which
            // bind to the back end, but which we don't currently support), and
            // "LoadBalancerPorts" which seems redundant since Listeners have PolicyNames associated
            // with them (the docs say load balancer ports are only associated with
            // some policy types).  The first one we don't support and the second we don't know what
            // it means in a non-circular way (TODO: figure that out) so we don't
            // support either currently
            AsyncRequests
                .<CreateLoadBalancerPolicyType, CreateLoadBalancerPolicyResponseType>sendSync(
                    configuration, createLoadBalancerPolicyType);
          }
        }
        break;
      case 4: // add load balancer policies to listeners
        if (properties.getListeners() != null) {
          for (ElasticLoadBalancingListener elasticLoadBalancingListener :
              properties.getListeners()) {
            if (elasticLoadBalancingListener.getPolicyNames() != null) {
              SetLoadBalancerPoliciesOfListenerType setLoadBalancerPoliciesOfListenerType =
                  new SetLoadBalancerPoliciesOfListenerType();
              setLoadBalancerPoliciesOfListenerType.setLoadBalancerName(
                  info.getPhysicalResourceId());
              setLoadBalancerPoliciesOfListenerType.setLoadBalancerPort(
                  elasticLoadBalancingListener.getLoadBalancerPort());
              PolicyNames policyNames = new PolicyNames();
              ArrayList<String> member =
                  Lists.newArrayList(elasticLoadBalancingListener.getPolicyNames());
              policyNames.setMember(member);
              setLoadBalancerPoliciesOfListenerType.setPolicyNames(policyNames);
              setLoadBalancerPoliciesOfListenerType.setEffectiveUserId(info.getEffectiveUserId());
              AsyncRequests
                  .<SetLoadBalancerPoliciesOfListenerType,
                      SetLoadBalancerPoliciesOfListenerResponseType>
                      sendSync(configuration, setLoadBalancerPoliciesOfListenerType);
            }
          }
        }
        break;
      case 5: // add app stickiness policy load balancer
        if (properties.getAppCookieStickinessPolicy() != null) {
          CreateAppCookieStickinessPolicyType createAppCookieStickinessPolicyType =
              new CreateAppCookieStickinessPolicyType();
          createAppCookieStickinessPolicyType.setPolicyName(
              properties.getAppCookieStickinessPolicy().getPolicyName());
          createAppCookieStickinessPolicyType.setLoadBalancerName(info.getPhysicalResourceId());
          createAppCookieStickinessPolicyType.setCookieName(
              properties.getAppCookieStickinessPolicy().getCookieName());
          createAppCookieStickinessPolicyType.setEffectiveUserId(info.getEffectiveUserId());
          AsyncRequests
              .<CreateAppCookieStickinessPolicyType, CreateAppCookieStickinessPolicyResponseType>
                  sendSync(configuration, createAppCookieStickinessPolicyType);
        }
        break;
      case 6: // add lb stickiness policy load balancer
        if (properties.getLbCookieStickinessPolicy() != null) {
          CreateLBCookieStickinessPolicyType createLBCookieStickinessPolicyType =
              new CreateLBCookieStickinessPolicyType();
          createLBCookieStickinessPolicyType.setPolicyName(
              properties.getLbCookieStickinessPolicy().getPolicyName());
          createLBCookieStickinessPolicyType.setLoadBalancerName(info.getPhysicalResourceId());
          createLBCookieStickinessPolicyType.setCookieExpirationPeriod(
              properties.getLbCookieStickinessPolicy().getCookieExpirationPeriod());
          createLBCookieStickinessPolicyType.setEffectiveUserId(info.getEffectiveUserId());
          AsyncRequests
              .<CreateLBCookieStickinessPolicyType, CreateLBCookieStickinessPolicyResponseType>
                  sendSync(configuration, createLBCookieStickinessPolicyType);
        }
        break;
      case 7: // placeholder for "AccessLoggingPolicy", "ConnectionDrainingPolicy", "CrossZone" :
              // Boolean,
        break;
      case 8: // describe load balancer to get attributes
        DescribeLoadBalancersType describeLoadBalancersType = new DescribeLoadBalancersType();
        LoadBalancerNames loadBalancerNames = new LoadBalancerNames();
        ArrayList<String> member = Lists.newArrayList(info.getPhysicalResourceId());
        loadBalancerNames.setMember(member);
        describeLoadBalancersType.setLoadBalancerNames(loadBalancerNames);
        describeLoadBalancersType.setEffectiveUserId(info.getEffectiveUserId());
        DescribeLoadBalancersResponseType describeLoadBalancersResponseType =
            AsyncRequests.<DescribeLoadBalancersType, DescribeLoadBalancersResponseType>sendSync(
                configuration, describeLoadBalancersType);
        if (describeLoadBalancersResponseType != null
            && describeLoadBalancersResponseType.getDescribeLoadBalancersResult() != null
            && describeLoadBalancersResponseType
                    .getDescribeLoadBalancersResult()
                    .getLoadBalancerDescriptions()
                != null
            && describeLoadBalancersResponseType
                    .getDescribeLoadBalancersResult()
                    .getLoadBalancerDescriptions()
                    .getMember()
                != null
            && describeLoadBalancersResponseType
                    .getDescribeLoadBalancersResult()
                    .getLoadBalancerDescriptions()
                    .getMember()
                    .size()
                > 0) {
          LoadBalancerDescription loadBalancerDescription =
              describeLoadBalancersResponseType
                  .getDescribeLoadBalancersResult()
                  .getLoadBalancerDescriptions()
                  .getMember()
                  .get(0);
          String canonicalHostedZoneName = loadBalancerDescription.getCanonicalHostedZoneName();
          String canonicalHostedZoneNameId = loadBalancerDescription.getCanonicalHostedZoneNameID();
          String sourceSecurityGroupGroupName =
              loadBalancerDescription.getSourceSecurityGroup().getGroupName();
          String sourceSecurityGroupGroupOwnerAlias =
              loadBalancerDescription.getSourceSecurityGroup().getOwnerAlias();
          if ("internal".equals(loadBalancerDescription.getScheme())) {
            canonicalHostedZoneName = loadBalancerDescription.getDnsName();
          }
          info.setReferenceValueJson(
              JsonHelper.getStringFromJsonNode(new TextNode(info.getPhysicalResourceId())));
          info.setSourceSecurityGroupGroupName(
              JsonHelper.getStringFromJsonNode(new TextNode(sourceSecurityGroupGroupName)));
          info.setSourceSecurityGroupOwnerAlias(
              JsonHelper.getStringFromJsonNode(new TextNode(sourceSecurityGroupGroupOwnerAlias)));
          info.setCanonicalHostedZoneNameID(
              JsonHelper.getStringFromJsonNode(new TextNode(canonicalHostedZoneNameId)));
          info.setCanonicalHostedZoneName(
              JsonHelper.getStringFromJsonNode(new TextNode(canonicalHostedZoneName)));
        }
        break;
      default:
        throw new IllegalStateException("Invalid step " + stepNum);
    }
  }