@Test public void deploys_flag_data_to_targets() throws IOException { FlagsClient flagsClient = mock(FlagsClient.class); when(flagsClient.listFlagData(controllerTarget)).thenReturn(List.of()); when(flagsClient.listFlagData(prodUsWest1Target)).thenReturn(List.of(flagData("existing-prod.us-west-1.json"))); FlagData existingProdUsEast3Data = flagData("existing-prod.us-east-3.json"); when(flagsClient.listFlagData(prodUsEast3Target)).thenReturn(List.of(existingProdUsEast3Data)); FlagData defaultData = flagData("flags/my-flag/main.json"); FlagData prodUsEast3Data = flagData("flags/my-flag/main.prod.us-east-3.json"); SystemFlagsDataArchive archive = new SystemFlagsDataArchive.Builder() .addFile("main.json", defaultData) .addFile("main.prod.us-east-3.json", prodUsEast3Data) .build(); SystemFlagsDeployer deployer = new SystemFlagsDeployer(flagsClient, SYSTEM, Set.of(controllerTarget, prodUsWest1Target, prodUsEast3Target)); SystemFlagsDeployResult result = deployer.deployFlags(archive, false); verify(flagsClient).putFlagData(controllerTarget, defaultData); verify(flagsClient).putFlagData(prodUsEast3Target, prodUsEast3Data); verify(flagsClient, never()).putFlagData(prodUsWest1Target, defaultData); List<FlagDataChange> changes = result.flagChanges(); assertThat(changes).containsOnly( FlagDataChange.created(FLAG_ID, controllerTarget, defaultData), FlagDataChange.updated(FLAG_ID, prodUsEast3Target, prodUsEast3Data, existingProdUsEast3Data)); }
SystemFlagsDeployResult deployFlags(SystemFlagsDataArchive archive, boolean dryRun) { Map<FlagsTarget, Future<SystemFlagsDeployResult>> futures = new HashMap<>(); for (FlagsTarget target : targets) { futures.put(target, executor.submit(() -> deployFlags(target, archive.flagData(target), dryRun))); } List<SystemFlagsDeployResult> results = new ArrayList<>(); futures.forEach((target, future) -> { try { results.add(future.get()); } catch (InterruptedException | ExecutionException e) { log.log(Level.SEVERE, String.format("Failed to deploy flags for target '%s': %s", target, e.getMessage()), e); throw new RuntimeException(e); } }); try { archive.validateAllFilesAreForTargets(system, targets); } catch (IllegalArgumentException e) { results.add(new SystemFlagsDeployResult(List.of(OperationError.archiveValidationFailed(e.getMessage())))); } return SystemFlagsDeployResult.merge(results); }
SystemFlagsDeployer { SystemFlagsDeployResult deployFlags(SystemFlagsDataArchive archive, boolean dryRun) { Map<FlagsTarget, Future<SystemFlagsDeployResult>> futures = new HashMap<>(); for (FlagsTarget target : targets) { futures.put(target, executor.submit(() -> deployFlags(target, archive.flagData(target), dryRun))); } List<SystemFlagsDeployResult> results = new ArrayList<>(); futures.forEach((target, future) -> { try { results.add(future.get()); } catch (InterruptedException | ExecutionException e) { log.log(Level.SEVERE, String.format("Failed to deploy flags for target '%s': %s", target, e.getMessage()), e); throw new RuntimeException(e); } }); try { archive.validateAllFilesAreForTargets(system, targets); } catch (IllegalArgumentException e) { results.add(new SystemFlagsDeployResult(List.of(OperationError.archiveValidationFailed(e.getMessage())))); } return SystemFlagsDeployResult.merge(results); } }
SystemFlagsDeployer { SystemFlagsDeployResult deployFlags(SystemFlagsDataArchive archive, boolean dryRun) { Map<FlagsTarget, Future<SystemFlagsDeployResult>> futures = new HashMap<>(); for (FlagsTarget target : targets) { futures.put(target, executor.submit(() -> deployFlags(target, archive.flagData(target), dryRun))); } List<SystemFlagsDeployResult> results = new ArrayList<>(); futures.forEach((target, future) -> { try { results.add(future.get()); } catch (InterruptedException | ExecutionException e) { log.log(Level.SEVERE, String.format("Failed to deploy flags for target '%s': %s", target, e.getMessage()), e); throw new RuntimeException(e); } }); try { archive.validateAllFilesAreForTargets(system, targets); } catch (IllegalArgumentException e) { results.add(new SystemFlagsDeployResult(List.of(OperationError.archiveValidationFailed(e.getMessage())))); } return SystemFlagsDeployResult.merge(results); } SystemFlagsDeployer(ServiceIdentityProvider identityProvider, SystemName system, Set<FlagsTarget> targets);   SystemFlagsDeployer(FlagsClient client, SystemName system, Set<FlagsTarget> targets); }
SystemFlagsDeployer { SystemFlagsDeployResult deployFlags(SystemFlagsDataArchive archive, boolean dryRun) { Map<FlagsTarget, Future<SystemFlagsDeployResult>> futures = new HashMap<>(); for (FlagsTarget target : targets) { futures.put(target, executor.submit(() -> deployFlags(target, archive.flagData(target), dryRun))); } List<SystemFlagsDeployResult> results = new ArrayList<>(); futures.forEach((target, future) -> { try { results.add(future.get()); } catch (InterruptedException | ExecutionException e) { log.log(Level.SEVERE, String.format("Failed to deploy flags for target '%s': %s", target, e.getMessage()), e); throw new RuntimeException(e); } }); try { archive.validateAllFilesAreForTargets(system, targets); } catch (IllegalArgumentException e) { results.add(new SystemFlagsDeployResult(List.of(OperationError.archiveValidationFailed(e.getMessage())))); } return SystemFlagsDeployResult.merge(results); } SystemFlagsDeployer(ServiceIdentityProvider identityProvider, SystemName system, Set<FlagsTarget> targets);   SystemFlagsDeployer(FlagsClient client, SystemName system, Set<FlagsTarget> targets);  }
SystemFlagsDeployer { SystemFlagsDeployResult deployFlags(SystemFlagsDataArchive archive, boolean dryRun) { Map<FlagsTarget, Future<SystemFlagsDeployResult>> futures = new HashMap<>(); for (FlagsTarget target : targets) { futures.put(target, executor.submit(() -> deployFlags(target, archive.flagData(target), dryRun))); } List<SystemFlagsDeployResult> results = new ArrayList<>(); futures.forEach((target, future) -> { try { results.add(future.get()); } catch (InterruptedException | ExecutionException e) { log.log(Level.SEVERE, String.format("Failed to deploy flags for target '%s': %s", target, e.getMessage()), e); throw new RuntimeException(e); } }); try { archive.validateAllFilesAreForTargets(system, targets); } catch (IllegalArgumentException e) { results.add(new SystemFlagsDeployResult(List.of(OperationError.archiveValidationFailed(e.getMessage())))); } return SystemFlagsDeployResult.merge(results); } SystemFlagsDeployer(ServiceIdentityProvider identityProvider, SystemName system, Set<FlagsTarget> targets);   SystemFlagsDeployer(FlagsClient client, SystemName system, Set<FlagsTarget> targets);   }