Search in sources :

Example 1 with UmsVirtualGroupRight

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());
}
Also used : NetworkDto(com.sequenceiq.environment.network.dto.NetworkDto) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) EnvironmentDto(com.sequenceiq.environment.environment.dto.EnvironmentDto) CloudRegions(com.sequenceiq.cloudbreak.cloud.model.CloudRegions) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EnvironmentNetworkConverter(com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter) UmsVirtualGroupRight(com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight) NetworkCidr(com.sequenceiq.cloudbreak.cloud.network.NetworkCidr) AwsNetwork(com.sequenceiq.environment.network.dao.domain.AwsNetwork) Network(com.sequenceiq.cloudbreak.cloud.model.Network) BaseNetwork(com.sequenceiq.environment.network.dao.domain.BaseNetwork) Event(reactor.bus.Event) Environment(com.sequenceiq.environment.environment.domain.Environment) Test(org.junit.jupiter.api.Test)

Example 2 with UmsVirtualGroupRight

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;
}
Also used : UmsVirtualGroupRight(com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) HashMap(java.util.HashMap) StatusRuntimeException(io.grpc.StatusRuntimeException) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException)

Example 3 with UmsVirtualGroupRight

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();
}
Also used : UmsVirtualGroupRight(com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight) Group(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group) WorkloadAdministrationGroup(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadAdministrationGroup) ListWorkloadAdministrationGroupsResponse(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListWorkloadAdministrationGroupsResponse)

Example 4 with UmsVirtualGroupRight

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;
}
Also used : UmsVirtualGroupRight(com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight) Group(com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

UmsVirtualGroupRight (com.sequenceiq.cloudbreak.auth.altus.UmsVirtualGroupRight)4 Group (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.Group)2 HashMap (java.util.HashMap)2 ListWorkloadAdministrationGroupsResponse (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.ListWorkloadAdministrationGroupsResponse)1 WorkloadAdministrationGroup (com.cloudera.thunderhead.service.usermanagement.UserManagementProto.WorkloadAdministrationGroup)1 CloudRegions (com.sequenceiq.cloudbreak.cloud.model.CloudRegions)1 Network (com.sequenceiq.cloudbreak.cloud.model.Network)1 NetworkCidr (com.sequenceiq.cloudbreak.cloud.network.NetworkCidr)1 CloudPlatform (com.sequenceiq.cloudbreak.common.mappable.CloudPlatform)1 Environment (com.sequenceiq.environment.environment.domain.Environment)1 EnvironmentDto (com.sequenceiq.environment.environment.dto.EnvironmentDto)1 AwsNetwork (com.sequenceiq.environment.network.dao.domain.AwsNetwork)1 BaseNetwork (com.sequenceiq.environment.network.dao.domain.BaseNetwork)1 NetworkDto (com.sequenceiq.environment.network.dto.NetworkDto)1 EnvironmentNetworkConverter (com.sequenceiq.environment.network.v1.converter.EnvironmentNetworkConverter)1 EnvironmentTestDto (com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto)1 TestFailException (com.sequenceiq.it.cloudbreak.exception.TestFailException)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Test (org.junit.jupiter.api.Test)1