use of com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight in project cloudbreak by hortonworks.
the class EnvironmentInitHandlerTest method testInitSuccess.
@Test
void testInitSuccess() {
EnvironmentDto dto = getEnvironmentDto();
NetworkDto networkDto = NetworkDto.builder().withRegistrationType(RegistrationType.EXISTING).build();
dto.setNetwork(networkDto);
Event<EnvironmentDto> event = new Event<>(dto);
Environment environment = getEnvironment();
EnvironmentNetworkConverter environmentNetworkConverter = mock(EnvironmentNetworkConverter.class);
Network network = mock(Network.class);
String cidr = "10.0.0.0/16";
when(environmentNetworkConverterMap.get(any(CloudPlatform.class))).thenReturn(environmentNetworkConverter);
when(environmentNetworkConverter.convertToNetwork(environment.getNetwork())).thenReturn(network);
when(environmentNetworkService.getNetworkCidr(any(), anyString(), any())).thenReturn(new NetworkCidr(cidr));
when(environmentService.findEnvironmentById(dto.getId())).thenReturn(Optional.of(environment));
Map<UmsVirtualGroupRight, String> virtualGroups = Map.of(UmsVirtualGroupRight.HBASE_ADMIN, "apple1", UmsVirtualGroupRight.ENVIRONMENT_ACCESS, "apple2");
when(virtualGroupService.createVirtualGroups(ACCOUNT_ID, CRN)).thenReturn(virtualGroups);
CloudRegions cloudRegions = new CloudRegions(Collections.emptyMap(), Collections.emptyMap(), Collections.emptyMap(), "apple", true);
when(environmentService.getRegionsByEnvironment(environment)).thenReturn(cloudRegions);
environmentInitHandler.accept(event);
assertEquals(cidr, environment.getNetwork().getNetworkCidr());
verify(environmentNetworkService, times(1)).getNetworkCidr(eq(network), eq(CloudPlatform.AWS.name()), eq(environment.getCredential()));
verify(environmentService, times(0)).setAdminGroupName(environment, null);
verify(environmentService, times(1)).assignEnvironmentAdminRole(CREATOR, CRN);
verify(environmentService, times(1)).setLocation(environment, environment.getRegionWrapper(), cloudRegions);
verify(environmentService, times(1)).setRegions(environment, environment.getRegionWrapper().getRegions(), cloudRegions);
verify(environmentService, times(1)).save(environment);
verify(eventSender, times(1)).sendEvent(any(), any());
}
use of com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight in project cloudbreak by hortonworks.
the class EnvironmentUtil method getEnvironmentVirtualGroups.
public Map<UmsVirtualGroupRight, String> getEnvironmentVirtualGroups(TestContext testContext, UmsClient client) {
String accountId = testContext.getActingUserCrn().getAccountId();
String environmentCrn = testContext.given(EnvironmentTestDto.class).getCrn();
Map<UmsVirtualGroupRight, String> virtualGroups = new HashMap<>();
String virtualGroup = null;
for (UmsVirtualGroupRight right : UmsVirtualGroupRight.values()) {
try {
virtualGroup = client.getDefaultClient().getWorkloadAdministrationGroupName(accountId, MDCUtils.getRequestId(), right, environmentCrn, regionAwareInternalCrnGeneratorFactory);
} catch (StatusRuntimeException ex) {
if (Status.Code.NOT_FOUND != ex.getStatus().getCode()) {
LOGGER.info(format(" Virtual groups are missing for right: '%s' ", right.getRight()));
}
}
if (StringUtils.hasText(virtualGroup)) {
virtualGroups.put(right, virtualGroup);
}
}
if (MapUtils.isNotEmpty(virtualGroups)) {
Log.then(LOGGER, format(" Virtual groups are present [%s] for environment '%s' ", virtualGroups, environmentCrn));
LOGGER.info(String.format(" Virtual groups are present [%s] for environment '%s' ", virtualGroups, environmentCrn));
} else {
throw new TestFailException(String.format(" Cannot find virtual groups for environment '%s' ", environmentCrn));
}
return virtualGroups;
}
use of com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight in project cloudbreak by hortonworks.
the class MockUserManagementService method listWorkloadAdministrationGroups.
@Override
public void listWorkloadAdministrationGroups(ListWorkloadAdministrationGroupsRequest request, StreamObserver<ListWorkloadAdministrationGroupsResponse> responseObserver) {
mockCrnService.ensureInternalActor();
String accountId = request.getAccountId();
LOGGER.info("List workload administration groups: {}", accountId);
ListWorkloadAdministrationGroupsResponse.Builder responseBuilder = ListWorkloadAdministrationGroupsResponse.newBuilder();
for (UmsVirtualGroupRight right : UmsVirtualGroupRight.values()) {
Group group = mockGroupManagementService.createGroup(accountId, mockGroupManagementService.generateWorkloadGroupName(right.getRight()));
responseBuilder.addWorkloadAdministrationGroup(WorkloadAdministrationGroup.newBuilder().setWorkloadAdministrationGroupName(group.getGroupName()).setRightName(right.getRight()).setResource(MOCK_RESOURCE).build());
}
responseObserver.onNext(responseBuilder.build());
responseObserver.onCompleted();
}
use of com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight in project cloudbreak by hortonworks.
the class MockGroupManagementService method createWorkloadGroups.
private Map<String, Group> createWorkloadGroups(String accountId) {
Map<String, Group> groups = new HashMap<>();
for (UmsVirtualGroupRight right : UmsVirtualGroupRight.values()) {
Group group = createGroup(accountId, generateWorkloadGroupName(right.getRight()));
groups.put(group.getCrn(), group);
}
LOGGER.info("workload groups for user: {}", groups);
return groups;
}
Aggregations