ASGroupLoader implements LocalResourceLoader { AutoScalingPolicy createPolicy(String resourceId, String name, String cpu, String last, String adjustment) { AutoScalingPolicy policy = new AutoScalingPolicy(resourceId + "-" + name); Asserts.isTrue(cpu.matches("[>|<]=\\d+%"), "cpu should be like >=80%"); if (cpu.startsWith(">=")) { policy.comparisonOperator = ComparisonOperator.GreaterThanOrEqualToThreshold; } else { policy.comparisonOperator = ComparisonOperator.LessThanOrEqualToThreshold; } policy.cpuUtilizationPercentage = Integer.parseInt(cpu.substring(2, cpu.length() - 1)); Asserts.isTrue(last.endsWith("min"), "last should be like 3min"); policy.lastMinutes = Integer.parseInt(last.substring(0, last.length() - 3)); Asserts.isTrue(adjustment.endsWith("%"), "adjustment should be like 15%"); policy.adjustmentPercentage = Integer.parseInt(adjustment.substring(0, adjustment.length() - 1)); return policy; }  @Override void load(ResourceNode node, Resources resources, DependencyResolvers resolvers, Environment env); AutoScalingPolicy scale(String resourceId, Map<String, Object> params);  }
@Test void createPolicy() { AutoScalingPolicy policy = loader.createPolicy("as", "scale-out", ">=80%", "3min", "15%"); assertEquals("as-scale-out", policy.id); assertEquals(80d, policy.cpuUtilizationPercentage, 0.0001); assertEquals(ComparisonOperator.GreaterThanOrEqualToThreshold, policy.comparisonOperator); assertEquals(3, policy.lastMinutes); assertEquals(15, policy.adjustmentPercentage); }