@Test public void doesNothingIfNoEnvironmentRevisionIsActive() throws Exception { DescribeEnvironmentRequest describeEnvironmentRequest = DescribeEnvironmentRequest.builder().environmentId(environmentId).build(); when(dataService.describeEnvironment(describeEnvironmentRequest)) .thenReturn( DescribeEnvironmentResponse.builder() .environment(environmentWithActiveRevision(null)) .build()); SchedulerHandler handler = new SchedulerHandler(dataService, ecs, schedulerFactory); SchedulerOutput output = handler.handleRequest(new SchedulerInput(EMPTY_CLUSTER, environmentId), null); verify(dataService, never()).describeEnvironmentRevision(any()); assertThat(output) .hasFieldOrPropertyWithValue("failedActions", 0L) .hasFieldOrPropertyWithValue("successfulActions", 0L); }
@SneakyThrows @Override public SchedulerOutput handleRequest(SchedulerInput input, Context context) { log.debug("Request: {}", input); EnvironmentId environmentId = input.getEnvironmentId(); Environment environment = data.describeEnvironment( DescribeEnvironmentRequest.builder().environmentId(environmentId).build()) .getEnvironment(); String activeEnvironmentRevisionId = environment.getActiveEnvironmentRevisionId(); if (activeEnvironmentRevisionId == null) { return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), 0, 0); } EnvironmentRevision activeEnvironmentRevision = data.describeEnvironmentRevision( DescribeEnvironmentRevisionRequest.builder() .environmentId(environmentId) .environmentRevisionId(activeEnvironmentRevisionId) .build()) .getEnvironmentRevision(); EnvironmentDescription environmentDescription = EnvironmentDescription.builder() .clusterName(environmentId.getCluster()) .environmentName(environmentId.getEnvironmentName()) .activeEnvironmentRevisionId(activeEnvironmentRevisionId) .environmentType( EnvironmentDescription.EnvironmentType.valueOf( environment.getEnvironmentType().toString())) .taskDefinitionArn(activeEnvironmentRevision.getTaskDefinition()) .deploymentMethod(environment.getDeploymentMethod()) .build(); Scheduler s = schedulerFactory.schedulerFor(environmentDescription); List<SchedulingAction> actions = s.schedule(input.getSnapshot(), environmentDescription); List<Boolean> outcomes = actions.stream().map(a -> a.execute(ecs)).collect(CompletableFutures.joinList()).join(); Map<Boolean, Long> outcomeCounts = outcomes .stream() .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), outcomeCounts.getOrDefault(false, 0L), outcomeCounts.getOrDefault(true, 0L)); }
SchedulerHandler implements RequestHandler<SchedulerInput, SchedulerOutput> { @SneakyThrows @Override public SchedulerOutput handleRequest(SchedulerInput input, Context context) { log.debug("Request: {}", input); EnvironmentId environmentId = input.getEnvironmentId(); Environment environment = data.describeEnvironment( DescribeEnvironmentRequest.builder().environmentId(environmentId).build()) .getEnvironment(); String activeEnvironmentRevisionId = environment.getActiveEnvironmentRevisionId(); if (activeEnvironmentRevisionId == null) { return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), 0, 0); } EnvironmentRevision activeEnvironmentRevision = data.describeEnvironmentRevision( DescribeEnvironmentRevisionRequest.builder() .environmentId(environmentId) .environmentRevisionId(activeEnvironmentRevisionId) .build()) .getEnvironmentRevision(); EnvironmentDescription environmentDescription = EnvironmentDescription.builder() .clusterName(environmentId.getCluster()) .environmentName(environmentId.getEnvironmentName()) .activeEnvironmentRevisionId(activeEnvironmentRevisionId) .environmentType( EnvironmentDescription.EnvironmentType.valueOf( environment.getEnvironmentType().toString())) .taskDefinitionArn(activeEnvironmentRevision.getTaskDefinition()) .deploymentMethod(environment.getDeploymentMethod()) .build(); Scheduler s = schedulerFactory.schedulerFor(environmentDescription); List<SchedulingAction> actions = s.schedule(input.getSnapshot(), environmentDescription); List<Boolean> outcomes = actions.stream().map(a -> a.execute(ecs)).collect(CompletableFutures.joinList()).join(); Map<Boolean, Long> outcomeCounts = outcomes .stream() .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), outcomeCounts.getOrDefault(false, 0L), outcomeCounts.getOrDefault(true, 0L)); } }
SchedulerHandler implements RequestHandler<SchedulerInput, SchedulerOutput> { @SneakyThrows @Override public SchedulerOutput handleRequest(SchedulerInput input, Context context) { log.debug("Request: {}", input); EnvironmentId environmentId = input.getEnvironmentId(); Environment environment = data.describeEnvironment( DescribeEnvironmentRequest.builder().environmentId(environmentId).build()) .getEnvironment(); String activeEnvironmentRevisionId = environment.getActiveEnvironmentRevisionId(); if (activeEnvironmentRevisionId == null) { return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), 0, 0); } EnvironmentRevision activeEnvironmentRevision = data.describeEnvironmentRevision( DescribeEnvironmentRevisionRequest.builder() .environmentId(environmentId) .environmentRevisionId(activeEnvironmentRevisionId) .build()) .getEnvironmentRevision(); EnvironmentDescription environmentDescription = EnvironmentDescription.builder() .clusterName(environmentId.getCluster()) .environmentName(environmentId.getEnvironmentName()) .activeEnvironmentRevisionId(activeEnvironmentRevisionId) .environmentType( EnvironmentDescription.EnvironmentType.valueOf( environment.getEnvironmentType().toString())) .taskDefinitionArn(activeEnvironmentRevision.getTaskDefinition()) .deploymentMethod(environment.getDeploymentMethod()) .build(); Scheduler s = schedulerFactory.schedulerFor(environmentDescription); List<SchedulingAction> actions = s.schedule(input.getSnapshot(), environmentDescription); List<Boolean> outcomes = actions.stream().map(a -> a.execute(ecs)).collect(CompletableFutures.joinList()).join(); Map<Boolean, Long> outcomeCounts = outcomes .stream() .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), outcomeCounts.getOrDefault(false, 0L), outcomeCounts.getOrDefault(true, 0L)); }  }
SchedulerHandler implements RequestHandler<SchedulerInput, SchedulerOutput> { @SneakyThrows @Override public SchedulerOutput handleRequest(SchedulerInput input, Context context) { log.debug("Request: {}", input); EnvironmentId environmentId = input.getEnvironmentId(); Environment environment = data.describeEnvironment( DescribeEnvironmentRequest.builder().environmentId(environmentId).build()) .getEnvironment(); String activeEnvironmentRevisionId = environment.getActiveEnvironmentRevisionId(); if (activeEnvironmentRevisionId == null) { return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), 0, 0); } EnvironmentRevision activeEnvironmentRevision = data.describeEnvironmentRevision( DescribeEnvironmentRevisionRequest.builder() .environmentId(environmentId) .environmentRevisionId(activeEnvironmentRevisionId) .build()) .getEnvironmentRevision(); EnvironmentDescription environmentDescription = EnvironmentDescription.builder() .clusterName(environmentId.getCluster()) .environmentName(environmentId.getEnvironmentName()) .activeEnvironmentRevisionId(activeEnvironmentRevisionId) .environmentType( EnvironmentDescription.EnvironmentType.valueOf( environment.getEnvironmentType().toString())) .taskDefinitionArn(activeEnvironmentRevision.getTaskDefinition()) .deploymentMethod(environment.getDeploymentMethod()) .build(); Scheduler s = schedulerFactory.schedulerFor(environmentDescription); List<SchedulingAction> actions = s.schedule(input.getSnapshot(), environmentDescription); List<Boolean> outcomes = actions.stream().map(a -> a.execute(ecs)).collect(CompletableFutures.joinList()).join(); Map<Boolean, Long> outcomeCounts = outcomes .stream() .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), outcomeCounts.getOrDefault(false, 0L), outcomeCounts.getOrDefault(true, 0L)); }  @SneakyThrows @Override SchedulerOutput handleRequest(SchedulerInput input, Context context); }
SchedulerHandler implements RequestHandler<SchedulerInput, SchedulerOutput> { @SneakyThrows @Override public SchedulerOutput handleRequest(SchedulerInput input, Context context) { log.debug("Request: {}", input); EnvironmentId environmentId = input.getEnvironmentId(); Environment environment = data.describeEnvironment( DescribeEnvironmentRequest.builder().environmentId(environmentId).build()) .getEnvironment(); String activeEnvironmentRevisionId = environment.getActiveEnvironmentRevisionId(); if (activeEnvironmentRevisionId == null) { return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), 0, 0); } EnvironmentRevision activeEnvironmentRevision = data.describeEnvironmentRevision( DescribeEnvironmentRevisionRequest.builder() .environmentId(environmentId) .environmentRevisionId(activeEnvironmentRevisionId) .build()) .getEnvironmentRevision(); EnvironmentDescription environmentDescription = EnvironmentDescription.builder() .clusterName(environmentId.getCluster()) .environmentName(environmentId.getEnvironmentName()) .activeEnvironmentRevisionId(activeEnvironmentRevisionId) .environmentType( EnvironmentDescription.EnvironmentType.valueOf( environment.getEnvironmentType().toString())) .taskDefinitionArn(activeEnvironmentRevision.getTaskDefinition()) .deploymentMethod(environment.getDeploymentMethod()) .build(); Scheduler s = schedulerFactory.schedulerFor(environmentDescription); List<SchedulingAction> actions = s.schedule(input.getSnapshot(), environmentDescription); List<Boolean> outcomes = actions.stream().map(a -> a.execute(ecs)).collect(CompletableFutures.joinList()).join(); Map<Boolean, Long> outcomeCounts = outcomes .stream() .collect(Collectors.groupingBy(Function.identity(), Collectors.counting())); return new SchedulerOutput( input.getSnapshot().getClusterName(), input.getEnvironmentId(), outcomeCounts.getOrDefault(false, 0L), outcomeCounts.getOrDefault(true, 0L)); }  @SneakyThrows @Override SchedulerOutput handleRequest(SchedulerInput input, Context context);  }