@Test public void invokesSchedulerCoreForDeploymentMethod() throws Exception { DescribeEnvironmentRequest describeEnvironmentRequest = DescribeEnvironmentRequest.builder().environmentId(environmentId).build(); DescribeEnvironmentRevisionRequest describeEnvironmentRevisionRequest = DescribeEnvironmentRevisionRequest.builder() .environmentId(environmentId) .environmentRevisionId(ACTIVE_ENVIRONMENT_REVISION_ID) .build(); when(dataService.describeEnvironment(describeEnvironmentRequest)) .thenReturn( DescribeEnvironmentResponse.builder() .environment(environmentWithActiveRevision(ACTIVE_ENVIRONMENT_REVISION_ID)) .build()); when(dataService.describeEnvironmentRevision(describeEnvironmentRevisionRequest)) .thenReturn( DescribeEnvironmentRevisionResponse.builder() .environmentRevision( EnvironmentRevision.builder() .environmentId(environmentId) .environmentRevisionId(ACTIVE_ENVIRONMENT_REVISION_ID) .taskDefinition(TASK_DEFINITION) .createdTime(Instant.now()) .build()) .build()); SchedulingAction successfulAction = e -> CompletableFuture.completedFuture(true); SchedulingAction failedAction = e -> CompletableFuture.completedFuture(false); Scheduler mockScheduler = mock(Scheduler.class); when(mockScheduler.schedule(any(), any())) .thenReturn(Arrays.asList(successfulAction, failedAction)); when(schedulerFactory.schedulerFor(any())).thenReturn(mockScheduler); SchedulerHandler handler = new SchedulerHandler(dataService, ecs, schedulerFactory); SchedulerOutput output = handler.handleRequest(new SchedulerInput(EMPTY_CLUSTER, environmentId), null); verify(dataService).describeEnvironment(describeEnvironmentRequest); verify(dataService).describeEnvironmentRevision(describeEnvironmentRevisionRequest); ArgumentCaptor<EnvironmentDescription> environmentDescription = ArgumentCaptor.forClass(EnvironmentDescription.class); verify(mockScheduler).schedule(eq(EMPTY_CLUSTER), environmentDescription.capture()); assertThat(environmentDescription.getValue()) .isEqualTo( EnvironmentDescription.builder() .clusterName(CLUSTER_NAME) .environmentName(ENVIRONMENT_NAME) .activeEnvironmentRevisionId(ACTIVE_ENVIRONMENT_REVISION_ID) .environmentType(EnvironmentDescription.EnvironmentType.SingleTask) .taskDefinitionArn(TASK_DEFINITION) .deploymentMethod(DEPLOYMENT_METHOD) .build()); assertThat(output.getClusterName()).isEqualTo(CLUSTER_NAME); assertThat(output.getEnvironmentId()).isEqualTo(environmentId); assertThat(output.getSuccessfulActions()).isEqualTo(1L); assertThat(output.getFailedActions()).isEqualTo(1L); }
@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);  }