List of usage examples for com.google.common.base Predicates isNull
@GwtCompatible(serializable = true) public static <T> Predicate<T> isNull()
From source file:com.eucalyptus.autoscaling.AutoScalingService.java
public CreateAutoScalingGroupResponseType createAutoScalingGroup(final CreateAutoScalingGroupType request) throws EucalyptusCloudException { final CreateAutoScalingGroupResponseType reply = request.getReply(); final Context ctx = Contexts.lookup(); if (request.getTags() != null) { for (final TagType tagType : request.getTags().getMember()) { final String key = tagType.getKey(); if (com.google.common.base.Strings.isNullOrEmpty(key) || key.trim().length() > 128 || isReserved(key)) { throw new ValidationErrorException( "Invalid key (max length 128, must not be empty, reserved prefixes " + reservedPrefixes + "): " + key); }/* w ww. j a v a2 s. c om*/ } if (request.getTags().getMember().size() >= MAX_TAGS_PER_RESOURCE) { throw Exceptions.toUndeclared(new LimitExceededException("Tag limit exceeded")); } } final Supplier<AutoScalingGroup> allocator = new Supplier<AutoScalingGroup>() { @Override public AutoScalingGroup get() { try { final Integer minSize = Numbers.intValue(request.getMinSize()); final Integer maxSize = Numbers.intValue(request.getMaxSize()); final Integer desiredCapacity = Numbers.intValue(request.getDesiredCapacity()); if (desiredCapacity != null && desiredCapacity < minSize) { throw Exceptions.toUndeclared( new ValidationErrorException("DesiredCapacity must not be less than MinSize")); } if (desiredCapacity != null && desiredCapacity > maxSize) { throw Exceptions.toUndeclared( new ValidationErrorException("DesiredCapacity must not be greater than MaxSize")); } final List<String> referenceErrors = activityManager.validateReferences(ctx.getUserFullName(), request.availabilityZones(), request.loadBalancerNames()); verifyUnsupportedReferences(referenceErrors, request.getPlacementGroup(), request.getVpcZoneIdentifier()); if (!referenceErrors.isEmpty()) { throw Exceptions.toUndeclared( new ValidationErrorException("Invalid parameters " + referenceErrors)); } final AutoScalingGroups.PersistingBuilder builder = autoScalingGroups .create(ctx.getUserFullName(), request.getAutoScalingGroupName(), launchConfigurations.lookup(ctx.getUserFullName().asAccountFullName(), request.getLaunchConfigurationName(), Functions.<LaunchConfiguration>identity()), minSize, maxSize) .withAvailabilityZones(request.availabilityZones()) .withDefaultCooldown(Numbers.intValue(request.getDefaultCooldown())) .withDesiredCapacity(desiredCapacity) .withHealthCheckGracePeriod(Numbers.intValue(request.getHealthCheckGracePeriod())) .withHealthCheckType(request.getHealthCheckType() == null ? null : HealthCheckType.valueOf(request.getHealthCheckType())) .withLoadBalancerNames( request.loadBalancerNames()) .withTerminationPolicyTypes(request.terminationPolicies() == null ? null : Collections2.filter( Collections2.transform(request.terminationPolicies(), Enums.valueOfFunction(TerminationPolicyType.class)), Predicates.not(Predicates.isNull()))) .withTags(request.getTags() == null ? null : Iterables.transform(request.getTags().getMember(), TypeMappers.lookup(TagType.class, AutoScalingGroupTag.class))); return builder.persist(); } catch (AutoScalingMetadataNotFoundException e) { throw Exceptions.toUndeclared(new ValidationErrorException( "Launch configuration not found: " + request.getLaunchConfigurationName())); } catch (IllegalArgumentException e) { throw Exceptions.toUndeclared(new ValidationErrorException( "Invalid health check type: " + request.getHealthCheckType())); } catch (Exception ex) { throw new RuntimeException(ex); } } }; try { RestrictedTypes.allocateUnitlessResource(allocator); } catch (Exception e) { handleException(e, true); } return reply; }
From source file:com.eucalyptus.autoscaling.backend.AutoScalingBackendService.java
public CreateAutoScalingGroupResponseType createAutoScalingGroup(final CreateAutoScalingGroupType request) throws EucalyptusCloudException { final CreateAutoScalingGroupResponseType reply = request.getReply(); final Context ctx = Contexts.lookup(); if (request.getTags() != null) { for (final TagType tagType : request.getTags().getMember()) { final String key = tagType.getKey(); if (com.google.common.base.Strings.isNullOrEmpty(key) || key.trim().length() > 128 || isReserved(key)) { throw new ValidationErrorException( "Invalid key (max length 128, must not be empty, reserved prefixes " + reservedPrefixes + "): " + key); }//from w w w . j a va2 s.c o m } if (request.getTags().getMember().size() >= MAX_TAGS_PER_RESOURCE) { throw Exceptions.toUndeclared(new LimitExceededException("Tag limit exceeded")); } } final Supplier<AutoScalingGroup> allocator = new Supplier<AutoScalingGroup>() { @Override public AutoScalingGroup get() { try { final Integer minSize = Numbers.intValue(request.getMinSize()); final Integer maxSize = Numbers.intValue(request.getMaxSize()); final Integer desiredCapacity = Numbers.intValue(request.getDesiredCapacity()); if (desiredCapacity != null && desiredCapacity < minSize) { throw Exceptions.toUndeclared( new ValidationErrorException("DesiredCapacity must not be less than MinSize")); } if (desiredCapacity != null && desiredCapacity > maxSize) { throw Exceptions.toUndeclared( new ValidationErrorException("DesiredCapacity must not be greater than MaxSize")); } final List<String> referenceErrors = activityManager.validateReferences(ctx.getUserFullName(), request.availabilityZones(), request.loadBalancerNames()); verifyUnsupportedReferences(referenceErrors, request.getPlacementGroup(), request.getVpcZoneIdentifier()); if (!referenceErrors.isEmpty()) { throw Exceptions.toUndeclared( new ValidationErrorException("Invalid parameters " + referenceErrors)); } final AccountFullName accountFullName = ctx.getUserFullName().asAccountFullName(); final AutoScalingGroups.PersistingBuilder builder = autoScalingGroups .create(ctx.getUserFullName(), request.getAutoScalingGroupName(), verifyOwnership(accountFullName, launchConfigurations.lookup(accountFullName, request.getLaunchConfigurationName(), Functions.<LaunchConfiguration>identity())), minSize, maxSize) .withAvailabilityZones(request.availabilityZones()) .withDefaultCooldown(Numbers.intValue(request.getDefaultCooldown())) .withDesiredCapacity(desiredCapacity) .withHealthCheckGracePeriod(Numbers.intValue(request.getHealthCheckGracePeriod())) .withHealthCheckType(request.getHealthCheckType() == null ? null : HealthCheckType.valueOf(request.getHealthCheckType())) .withLoadBalancerNames( request.loadBalancerNames()) .withTerminationPolicyTypes(request.terminationPolicies() == null ? null : Collections2.filter( Collections2.transform(request.terminationPolicies(), Enums.valueOfFunction(TerminationPolicyType.class)), Predicates.not(Predicates.isNull()))) .withTags(request.getTags() == null ? null : Iterables.transform(request.getTags().getMember(), TypeMappers.lookup(TagType.class, AutoScalingGroupTag.class))); return builder.persist(); } catch (AutoScalingMetadataNotFoundException e) { throw Exceptions.toUndeclared(new ValidationErrorException( "Launch configuration not found: " + request.getLaunchConfigurationName())); } catch (IllegalArgumentException e) { throw Exceptions.toUndeclared(new ValidationErrorException( "Invalid health check type: " + request.getHealthCheckType())); } catch (Exception ex) { throw new RuntimeException(ex); } } }; try { RestrictedTypes.allocateUnitlessResource(allocator); } catch (Exception e) { handleException(e, true); } return reply; }
From source file:com.eucalyptus.autoscaling.AutoScalingService.java
public UpdateAutoScalingGroupResponseType updateAutoScalingGroup(final UpdateAutoScalingGroupType request) throws EucalyptusCloudException { final UpdateAutoScalingGroupResponseType reply = request.getReply(); final Context ctx = Contexts.lookup(); try {//ww w . jav a 2s . c o m final AccountFullName accountFullName = ctx.getUserFullName().asAccountFullName(); final Callback<AutoScalingGroup> groupCallback = new Callback<AutoScalingGroup>() { @Override public void fire(final AutoScalingGroup autoScalingGroup) { if (RestrictedTypes.filterPrivileged().apply(autoScalingGroup)) { if (request.availabilityZones() != null && !request.availabilityZones().isEmpty()) autoScalingGroup.updateAvailabilityZones( Lists.newArrayList(Sets.newLinkedHashSet(request.availabilityZones()))); if (request.getDefaultCooldown() != null) autoScalingGroup.setDefaultCooldown(Numbers.intValue(request.getDefaultCooldown())); if (request.getHealthCheckGracePeriod() != null) autoScalingGroup.setHealthCheckGracePeriod( Numbers.intValue(request.getHealthCheckGracePeriod())); if (request.getHealthCheckType() != null) autoScalingGroup.setHealthCheckType(Enums.valueOfFunction(HealthCheckType.class) .apply(request.getHealthCheckType())); if (request.getLaunchConfigurationName() != null) try { autoScalingGroup.setLaunchConfiguration(launchConfigurations.lookup(accountFullName, request.getLaunchConfigurationName(), Functions.<LaunchConfiguration>identity())); } catch (AutoScalingMetadataNotFoundException e) { throw Exceptions.toUndeclared(new ValidationErrorException( "Launch configuration not found: " + request.getLaunchConfigurationName())); } catch (AutoScalingMetadataException e) { throw Exceptions.toUndeclared(e); } if (request.getMaxSize() != null) autoScalingGroup.setMaxSize(Numbers.intValue(request.getMaxSize())); if (request.getMinSize() != null) autoScalingGroup.setMinSize(Numbers.intValue(request.getMinSize())); if (request.terminationPolicies() != null && !request.terminationPolicies().isEmpty()) autoScalingGroup .setTerminationPolicies( Lists.newArrayList( Sets.newLinkedHashSet(Iterables.filter( Iterables.transform(request.terminationPolicies(), Enums.valueOfFunction( TerminationPolicyType.class)), Predicates.not(Predicates.isNull()))))); if (request.getDesiredCapacity() != null) { Integer updatedDesiredCapacity = Numbers.intValue(request.getDesiredCapacity()); autoScalingGroup.updateDesiredCapacity(updatedDesiredCapacity, String.format( "a user request update of AutoScalingGroup constraints to min: %1$d, max: %2$d, desired: %4$d changing the desired capacity from %3$d to %4$d", autoScalingGroup.getMinSize(), autoScalingGroup.getMaxSize(), autoScalingGroup.getDesiredCapacity(), updatedDesiredCapacity)); } if (autoScalingGroup.getDesiredCapacity() < autoScalingGroup.getMinSize()) { throw Exceptions.toUndeclared( new ValidationErrorException("DesiredCapacity must not be less than MinSize")); } if (autoScalingGroup.getDesiredCapacity() > autoScalingGroup.getMaxSize()) { throw Exceptions.toUndeclared(new ValidationErrorException( "DesiredCapacity must not be greater than MaxSize")); } final List<String> referenceErrors = activityManager.validateReferences( autoScalingGroup.getOwner(), autoScalingGroup.getAvailabilityZones(), Collections.<String>emptyList() // load balancer names cannot be updated ); verifyUnsupportedReferences(referenceErrors, request.getPlacementGroup(), request.getVpcZoneIdentifier()); if (!referenceErrors.isEmpty()) { throw Exceptions.toUndeclared( new ValidationErrorException("Invalid parameters " + referenceErrors)); } } } }; autoScalingGroups.update(accountFullName, request.getAutoScalingGroupName(), groupCallback); } catch (AutoScalingMetadataNotFoundException e) { throw new ValidationErrorException( "Auto scaling group not found: " + request.getAutoScalingGroupName()); } catch (Exception e) { handleException(e); } return reply; }
From source file:com.eucalyptus.autoscaling.backend.AutoScalingBackendService.java
public UpdateAutoScalingGroupResponseType updateAutoScalingGroup(final UpdateAutoScalingGroupType request) throws EucalyptusCloudException { final UpdateAutoScalingGroupResponseType reply = request.getReply(); final Context ctx = Contexts.lookup(); try {//from ww w.ja v a2 s . c o m final AccountFullName accountFullName = ctx.getUserFullName().asAccountFullName(); final Callback<AutoScalingGroup> groupCallback = new Callback<AutoScalingGroup>() { @Override public void fire(final AutoScalingGroup autoScalingGroup) { if (RestrictedTypes.filterPrivileged().apply(autoScalingGroup)) { if (request.availabilityZones() != null && !request.availabilityZones().isEmpty()) autoScalingGroup.updateAvailabilityZones( Lists.newArrayList(Sets.newLinkedHashSet(request.availabilityZones()))); if (request.getDefaultCooldown() != null) autoScalingGroup.setDefaultCooldown(Numbers.intValue(request.getDefaultCooldown())); if (request.getHealthCheckGracePeriod() != null) autoScalingGroup.setHealthCheckGracePeriod( Numbers.intValue(request.getHealthCheckGracePeriod())); if (request.getHealthCheckType() != null) autoScalingGroup.setHealthCheckType(Enums.valueOfFunction(HealthCheckType.class) .apply(request.getHealthCheckType())); if (request.getLaunchConfigurationName() != null) try { autoScalingGroup.setLaunchConfiguration(verifyOwnership(accountFullName, launchConfigurations.lookup(accountFullName, request.getLaunchConfigurationName(), Functions.<LaunchConfiguration>identity()))); } catch (AutoScalingMetadataNotFoundException e) { throw Exceptions.toUndeclared(new ValidationErrorException( "Launch configuration not found: " + request.getLaunchConfigurationName())); } catch (AutoScalingMetadataException e) { throw Exceptions.toUndeclared(e); } if (request.getMaxSize() != null) autoScalingGroup.setMaxSize(Numbers.intValue(request.getMaxSize())); if (request.getMinSize() != null) autoScalingGroup.setMinSize(Numbers.intValue(request.getMinSize())); if (request.terminationPolicies() != null && !request.terminationPolicies().isEmpty()) autoScalingGroup .setTerminationPolicies( Lists.newArrayList( Sets.newLinkedHashSet(Iterables.filter( Iterables.transform(request.terminationPolicies(), Enums.valueOfFunction( TerminationPolicyType.class)), Predicates.not(Predicates.isNull()))))); if (request.getDesiredCapacity() != null) { Integer updatedDesiredCapacity = Numbers.intValue(request.getDesiredCapacity()); autoScalingGroup.updateDesiredCapacity(updatedDesiredCapacity, String.format( "a user request update of AutoScalingGroup constraints to min: %1$d, max: %2$d, desired: %4$d changing the desired capacity from %3$d to %4$d", autoScalingGroup.getMinSize(), autoScalingGroup.getMaxSize(), autoScalingGroup.getDesiredCapacity(), updatedDesiredCapacity)); } if (autoScalingGroup.getDesiredCapacity() < autoScalingGroup.getMinSize()) { throw Exceptions.toUndeclared( new ValidationErrorException("DesiredCapacity must not be less than MinSize")); } if (autoScalingGroup.getDesiredCapacity() > autoScalingGroup.getMaxSize()) { throw Exceptions.toUndeclared(new ValidationErrorException( "DesiredCapacity must not be greater than MaxSize")); } final List<String> referenceErrors = activityManager.validateReferences( autoScalingGroup.getOwner(), autoScalingGroup.getAvailabilityZones(), Collections.<String>emptyList() // load balancer names cannot be updated ); verifyUnsupportedReferences(referenceErrors, request.getPlacementGroup(), request.getVpcZoneIdentifier()); if (!referenceErrors.isEmpty()) { throw Exceptions.toUndeclared( new ValidationErrorException("Invalid parameters " + referenceErrors)); } } } }; autoScalingGroups.update(accountFullName, request.getAutoScalingGroupName(), groupCallback); } catch (AutoScalingMetadataNotFoundException e) { throw new ValidationErrorException( "Auto scaling group not found: " + request.getAutoScalingGroupName()); } catch (Exception e) { handleException(e); } return reply; }