@Test public void testRoleAssignmentFail() { when(grpcUmsClient.getBuiltInEnvironmentAdminResourceRoleCrn()).thenReturn("EnvAdminResourceRoleCrn"); doThrow(new RuntimeException("Bad")) .when(grpcUmsClient).assignResourceRole(anyString(), anyString(), anyString(), any()); ThreadBasedUserCrnProvider.doAs(TestConstants.CRN, () -> { environmentServiceUnderTest.assignEnvironmentAdminRole(TestConstants.CRN, "envCrn"); }); verify(grpcUmsClient).assignResourceRole(eq(TestConstants.CRN), eq("envCrn"), eq("EnvAdminResourceRoleCrn"), any()); verifyNoMoreInteractions(grpcUmsClient); }
public void assignEnvironmentAdminRole(String userCrn, String environmentCrn) { try { grpcUmsClient.assignResourceRole(userCrn, environmentCrn, grpcUmsClient.getBuiltInEnvironmentAdminResourceRoleCrn(), MDCUtils.getRequestId()); LOGGER.debug("EnvironmentAdmin role of {} environemnt is successfully assigned to the {} user", environmentCrn, userCrn); } catch (StatusRuntimeException ex) { if (Code.ALREADY_EXISTS.equals(ex.getStatus().getCode())) { LOGGER.debug("EnvironmentAdmin role of {} environemnt is already assigned to the {} user", environmentCrn, userCrn); } else { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), ex); } } catch (RuntimeException rex) { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), rex); } }
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public void assignEnvironmentAdminRole(String userCrn, String environmentCrn) { try { grpcUmsClient.assignResourceRole(userCrn, environmentCrn, grpcUmsClient.getBuiltInEnvironmentAdminResourceRoleCrn(), MDCUtils.getRequestId()); LOGGER.debug("EnvironmentAdmin role of {} environemnt is successfully assigned to the {} user", environmentCrn, userCrn); } catch (StatusRuntimeException ex) { if (Code.ALREADY_EXISTS.equals(ex.getStatus().getCode())) { LOGGER.debug("EnvironmentAdmin role of {} environemnt is already assigned to the {} user", environmentCrn, userCrn); } else { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), ex); } } catch (RuntimeException rex) { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), rex); } } }
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public void assignEnvironmentAdminRole(String userCrn, String environmentCrn) { try { grpcUmsClient.assignResourceRole(userCrn, environmentCrn, grpcUmsClient.getBuiltInEnvironmentAdminResourceRoleCrn(), MDCUtils.getRequestId()); LOGGER.debug("EnvironmentAdmin role of {} environemnt is successfully assigned to the {} user", environmentCrn, userCrn); } catch (StatusRuntimeException ex) { if (Code.ALREADY_EXISTS.equals(ex.getStatus().getCode())) { LOGGER.debug("EnvironmentAdmin role of {} environemnt is already assigned to the {} user", environmentCrn, userCrn); } else { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), ex); } } catch (RuntimeException rex) { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), rex); } } EnvironmentService(
            EnvironmentValidatorService validatorService,
            EnvironmentRepository environmentRepository,
            PlatformParameterService platformParameterService,
            EnvironmentDtoConverter environmentDtoConverter,
            DelegatingCliEnvironmentRequestConverter delegatingCliEnvironmentRequestConverter,
            GrpcUmsClient grpcUmsClient,
            TransactionService transactionService); }
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public void assignEnvironmentAdminRole(String userCrn, String environmentCrn) { try { grpcUmsClient.assignResourceRole(userCrn, environmentCrn, grpcUmsClient.getBuiltInEnvironmentAdminResourceRoleCrn(), MDCUtils.getRequestId()); LOGGER.debug("EnvironmentAdmin role of {} environemnt is successfully assigned to the {} user", environmentCrn, userCrn); } catch (StatusRuntimeException ex) { if (Code.ALREADY_EXISTS.equals(ex.getStatus().getCode())) { LOGGER.debug("EnvironmentAdmin role of {} environemnt is already assigned to the {} user", environmentCrn, userCrn); } else { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), ex); } } catch (RuntimeException rex) { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), rex); } } EnvironmentService(
            EnvironmentValidatorService validatorService,
            EnvironmentRepository environmentRepository,
            PlatformParameterService platformParameterService,
            EnvironmentDtoConverter environmentDtoConverter,
            DelegatingCliEnvironmentRequestConverter delegatingCliEnvironmentRequestConverter,
            GrpcUmsClient grpcUmsClient,
            TransactionService transactionService); Environment save(Environment environment); Environment saveWithOwnerRoleAssignment(Environment environment); EnvironmentDto getEnvironmentDto(Environment environment); EnvironmentDto getByNameAndAccountId(String environmentName, String accountId); EnvironmentDto getByCrnAndAccountId(String crn, String accountId); List<EnvironmentDto> listByAccountId(String accountId); void setRegions(Environment environment, Set<String> requestedRegions, CloudRegions cloudRegions); CloudRegions getRegionsByEnvironment(Environment environment); Environment findEnvironmentByIdOrThrow(Long id); Optional<Environment> findEnvironmentById(Long id); Optional<EnvironmentDto> findById(Long id); void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions); List<EnvironmentDto> findAllByIdInAndStatusIn(Collection<Long> resourceIds, Collection<EnvironmentStatus> environmentStatuses); List<EnvironmentDto> findAllByStatusIn(Collection<EnvironmentStatus> environmentStatuses); Object getCreateEnvironmentForCli(EnvironmentRequest environmentRequest, String cloudPlatform); Object getCreateEnvironmentForCli(EnvironmentDto environmentDto); void setAdminGroupName(Environment environment, String adminGroupName); Collection<Environment> findByResourceCrnInAndAccountIdAndArchivedIsFalse(Collection<String> crns, String accountId); Collection<Environment> findByNameInAndAccountIdAndArchivedIsFalse(Collection<String> environmentNames, String accountId); String getCrnByNameAndAccountId(String environmentName, String accountId); @Override Long getResourceIdByResourceCrn(String resourceCrn); @Override Long getResourceIdByResourceName(String resourceName); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType(); List<String> findNameWithAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); List<Environment> findAllByAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); void assignEnvironmentAdminRole(String userCrn, String environmentCrn); List<Environment> findAllForAutoSync(); }
EnvironmentService extends AbstractAccountAwareResourceService<Environment> implements ResourceIdProvider, ResourceBasedCrnProvider { public void assignEnvironmentAdminRole(String userCrn, String environmentCrn) { try { grpcUmsClient.assignResourceRole(userCrn, environmentCrn, grpcUmsClient.getBuiltInEnvironmentAdminResourceRoleCrn(), MDCUtils.getRequestId()); LOGGER.debug("EnvironmentAdmin role of {} environemnt is successfully assigned to the {} user", environmentCrn, userCrn); } catch (StatusRuntimeException ex) { if (Code.ALREADY_EXISTS.equals(ex.getStatus().getCode())) { LOGGER.debug("EnvironmentAdmin role of {} environemnt is already assigned to the {} user", environmentCrn, userCrn); } else { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), ex); } } catch (RuntimeException rex) { LOGGER.warn(String.format("EnvironmentAdmin role of %s environment cannot be assigned to the %s user", environmentCrn, userCrn), rex); } } EnvironmentService(
            EnvironmentValidatorService validatorService,
            EnvironmentRepository environmentRepository,
            PlatformParameterService platformParameterService,
            EnvironmentDtoConverter environmentDtoConverter,
            DelegatingCliEnvironmentRequestConverter delegatingCliEnvironmentRequestConverter,
            GrpcUmsClient grpcUmsClient,
            TransactionService transactionService); Environment save(Environment environment); Environment saveWithOwnerRoleAssignment(Environment environment); EnvironmentDto getEnvironmentDto(Environment environment); EnvironmentDto getByNameAndAccountId(String environmentName, String accountId); EnvironmentDto getByCrnAndAccountId(String crn, String accountId); List<EnvironmentDto> listByAccountId(String accountId); void setRegions(Environment environment, Set<String> requestedRegions, CloudRegions cloudRegions); CloudRegions getRegionsByEnvironment(Environment environment); Environment findEnvironmentByIdOrThrow(Long id); Optional<Environment> findEnvironmentById(Long id); Optional<EnvironmentDto> findById(Long id); void setLocation(Environment environment, RegionWrapper regionWrapper, CloudRegions cloudRegions); List<EnvironmentDto> findAllByIdInAndStatusIn(Collection<Long> resourceIds, Collection<EnvironmentStatus> environmentStatuses); List<EnvironmentDto> findAllByStatusIn(Collection<EnvironmentStatus> environmentStatuses); Object getCreateEnvironmentForCli(EnvironmentRequest environmentRequest, String cloudPlatform); Object getCreateEnvironmentForCli(EnvironmentDto environmentDto); void setAdminGroupName(Environment environment, String adminGroupName); Collection<Environment> findByResourceCrnInAndAccountIdAndArchivedIsFalse(Collection<String> crns, String accountId); Collection<Environment> findByNameInAndAccountIdAndArchivedIsFalse(Collection<String> environmentNames, String accountId); String getCrnByNameAndAccountId(String environmentName, String accountId); @Override Long getResourceIdByResourceCrn(String resourceCrn); @Override Long getResourceIdByResourceName(String resourceName); @Override String getResourceCrnByResourceName(String resourceName); @Override List<String> getResourceCrnListByResourceNameList(List<String> resourceNames); @Override List<String> getResourceCrnsInAccount(); @Override AuthorizationResourceType getResourceType(); List<String> findNameWithAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); List<Environment> findAllByAccountIdAndParentEnvIdAndArchivedIsFalse(String accountId, Long parentEnvironmentId); void assignEnvironmentAdminRole(String userCrn, String environmentCrn); List<Environment> findAllForAutoSync();  }