@Test public void testExecuteSuccess() throws Exception { DeploymentEntity deploymentEntity = new DeploymentEntity(); deploymentEntity.setOauthSecurityGroups(ImmutableList.of("adminGroup1", "adminGroup2")); List<DeploymentEntity> deploymentEntities = ImmutableList.of(deploymentEntity); Tenant tenant = new Tenant(); tenant.setId("id"); tenant.setSecurityGroups(ImmutableList.of(new SecurityGroup("adminGroup3", false), new SecurityGroup("adminGroup4", false))); ResourceList<Tenant> tenants = new ResourceList<>(ImmutableList.of(tenant)); doReturn(deploymentEntities).when(stepEntity).getTransientResourceEntities(null); doReturn(tenants).when(tenantBackend).filter(Optional.<String>absent(), Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE)); DeploymentPushSecurityGroupsStepCmd cmd = new DeploymentPushSecurityGroupsStepCmd(taskCommand, stepBackend, stepEntity, tenantBackend); cmd.execute(); verify(tenantBackend, times(1)).setSecurityGroups(eq("id"), anyObject()); verify(stepEntity, times(0)).addWarning(isA(SecurityGroupsAlreadyInheritedException.class)); }
@Override protected void execute() throws ExternalException { List<DeploymentEntity> deploymentEntities = step.getTransientResourceEntities(null); checkArgument(deploymentEntities.size() == 1); DeploymentEntity deploymentEntity = deploymentEntities.get(0); logger.info("Propagating the security groups of deployment {}", deploymentEntity.getId()); ResourceList<Tenant> tenants = tenantBackend.filter(Optional.absent(), Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE)); ResourceList<Tenant> currentPage; List<String> deploymentSecurityGroups = deploymentEntity.getOauthSecurityGroups(); do { for (Tenant tenant : tenants.getItems()) { logger.info("Updating the security groups of tenant {} using the ones from deployment {}", tenant.getId(), deploymentEntity.getId()); List<SecurityGroup> currSecurityGroups = tenant.getSecurityGroups(); Pair<List<SecurityGroup>, List<String>> result = SecurityGroupUtils.mergeParentSecurityGroups(currSecurityGroups, deploymentSecurityGroups); tenantBackend.setSecurityGroups(tenant.getId(), result.getLeft()); if (result.getRight() != null && !result.getRight().isEmpty()) { step.addWarning(new SecurityGroupsAlreadyInheritedException(result.getRight())); } } currentPage = tenants; if (tenants.getNextPageLink() != null && !tenants.getNextPageLink().isEmpty()) { tenants = tenantBackend.getPage(tenants.getNextPageLink()); } } while (currentPage.getNextPageLink() != null && !currentPage.getNextPageLink().isEmpty()); }
DeploymentPushSecurityGroupsStepCmd extends StepCommand { @Override protected void execute() throws ExternalException { List<DeploymentEntity> deploymentEntities = step.getTransientResourceEntities(null); checkArgument(deploymentEntities.size() == 1); DeploymentEntity deploymentEntity = deploymentEntities.get(0); logger.info("Propagating the security groups of deployment {}", deploymentEntity.getId()); ResourceList<Tenant> tenants = tenantBackend.filter(Optional.absent(), Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE)); ResourceList<Tenant> currentPage; List<String> deploymentSecurityGroups = deploymentEntity.getOauthSecurityGroups(); do { for (Tenant tenant : tenants.getItems()) { logger.info("Updating the security groups of tenant {} using the ones from deployment {}", tenant.getId(), deploymentEntity.getId()); List<SecurityGroup> currSecurityGroups = tenant.getSecurityGroups(); Pair<List<SecurityGroup>, List<String>> result = SecurityGroupUtils.mergeParentSecurityGroups(currSecurityGroups, deploymentSecurityGroups); tenantBackend.setSecurityGroups(tenant.getId(), result.getLeft()); if (result.getRight() != null && !result.getRight().isEmpty()) { step.addWarning(new SecurityGroupsAlreadyInheritedException(result.getRight())); } } currentPage = tenants; if (tenants.getNextPageLink() != null && !tenants.getNextPageLink().isEmpty()) { tenants = tenantBackend.getPage(tenants.getNextPageLink()); } } while (currentPage.getNextPageLink() != null && !currentPage.getNextPageLink().isEmpty()); } }
DeploymentPushSecurityGroupsStepCmd extends StepCommand { @Override protected void execute() throws ExternalException { List<DeploymentEntity> deploymentEntities = step.getTransientResourceEntities(null); checkArgument(deploymentEntities.size() == 1); DeploymentEntity deploymentEntity = deploymentEntities.get(0); logger.info("Propagating the security groups of deployment {}", deploymentEntity.getId()); ResourceList<Tenant> tenants = tenantBackend.filter(Optional.absent(), Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE)); ResourceList<Tenant> currentPage; List<String> deploymentSecurityGroups = deploymentEntity.getOauthSecurityGroups(); do { for (Tenant tenant : tenants.getItems()) { logger.info("Updating the security groups of tenant {} using the ones from deployment {}", tenant.getId(), deploymentEntity.getId()); List<SecurityGroup> currSecurityGroups = tenant.getSecurityGroups(); Pair<List<SecurityGroup>, List<String>> result = SecurityGroupUtils.mergeParentSecurityGroups(currSecurityGroups, deploymentSecurityGroups); tenantBackend.setSecurityGroups(tenant.getId(), result.getLeft()); if (result.getRight() != null && !result.getRight().isEmpty()) { step.addWarning(new SecurityGroupsAlreadyInheritedException(result.getRight())); } } currentPage = tenants; if (tenants.getNextPageLink() != null && !tenants.getNextPageLink().isEmpty()) { tenants = tenantBackend.getPage(tenants.getNextPageLink()); } } while (currentPage.getNextPageLink() != null && !currentPage.getNextPageLink().isEmpty()); } DeploymentPushSecurityGroupsStepCmd(TaskCommand taskCommand, StepBackend stepBackend,
                                             StepEntity stepEntity, TenantBackend tenantBackend); }
DeploymentPushSecurityGroupsStepCmd extends StepCommand { @Override protected void execute() throws ExternalException { List<DeploymentEntity> deploymentEntities = step.getTransientResourceEntities(null); checkArgument(deploymentEntities.size() == 1); DeploymentEntity deploymentEntity = deploymentEntities.get(0); logger.info("Propagating the security groups of deployment {}", deploymentEntity.getId()); ResourceList<Tenant> tenants = tenantBackend.filter(Optional.absent(), Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE)); ResourceList<Tenant> currentPage; List<String> deploymentSecurityGroups = deploymentEntity.getOauthSecurityGroups(); do { for (Tenant tenant : tenants.getItems()) { logger.info("Updating the security groups of tenant {} using the ones from deployment {}", tenant.getId(), deploymentEntity.getId()); List<SecurityGroup> currSecurityGroups = tenant.getSecurityGroups(); Pair<List<SecurityGroup>, List<String>> result = SecurityGroupUtils.mergeParentSecurityGroups(currSecurityGroups, deploymentSecurityGroups); tenantBackend.setSecurityGroups(tenant.getId(), result.getLeft()); if (result.getRight() != null && !result.getRight().isEmpty()) { step.addWarning(new SecurityGroupsAlreadyInheritedException(result.getRight())); } } currentPage = tenants; if (tenants.getNextPageLink() != null && !tenants.getNextPageLink().isEmpty()) { tenants = tenantBackend.getPage(tenants.getNextPageLink()); } } while (currentPage.getNextPageLink() != null && !currentPage.getNextPageLink().isEmpty()); } DeploymentPushSecurityGroupsStepCmd(TaskCommand taskCommand, StepBackend stepBackend,
                                             StepEntity stepEntity, TenantBackend tenantBackend);  }
DeploymentPushSecurityGroupsStepCmd extends StepCommand { @Override protected void execute() throws ExternalException { List<DeploymentEntity> deploymentEntities = step.getTransientResourceEntities(null); checkArgument(deploymentEntities.size() == 1); DeploymentEntity deploymentEntity = deploymentEntities.get(0); logger.info("Propagating the security groups of deployment {}", deploymentEntity.getId()); ResourceList<Tenant> tenants = tenantBackend.filter(Optional.absent(), Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE)); ResourceList<Tenant> currentPage; List<String> deploymentSecurityGroups = deploymentEntity.getOauthSecurityGroups(); do { for (Tenant tenant : tenants.getItems()) { logger.info("Updating the security groups of tenant {} using the ones from deployment {}", tenant.getId(), deploymentEntity.getId()); List<SecurityGroup> currSecurityGroups = tenant.getSecurityGroups(); Pair<List<SecurityGroup>, List<String>> result = SecurityGroupUtils.mergeParentSecurityGroups(currSecurityGroups, deploymentSecurityGroups); tenantBackend.setSecurityGroups(tenant.getId(), result.getLeft()); if (result.getRight() != null && !result.getRight().isEmpty()) { step.addWarning(new SecurityGroupsAlreadyInheritedException(result.getRight())); } } currentPage = tenants; if (tenants.getNextPageLink() != null && !tenants.getNextPageLink().isEmpty()) { tenants = tenantBackend.getPage(tenants.getNextPageLink()); } } while (currentPage.getNextPageLink() != null && !currentPage.getNextPageLink().isEmpty()); } DeploymentPushSecurityGroupsStepCmd(TaskCommand taskCommand, StepBackend stepBackend,
                                             StepEntity stepEntity, TenantBackend tenantBackend);   }