Search in sources :

Example 1 with RegionAwareInternalCrnGeneratorFactory

use of com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory in project cloudbreak by hortonworks.

the class DistroXRepairTests method testEphemeralDistroXMasterRepairWithTerminatedInstances.

@Test(dataProvider = TEST_CONTEXT)
@UseSpotInstances
@Description(given = "there is a running environment with FreeIPA and SDX in available state", when = "a new DistroX should be created", and = "MASTER host group should be recovered, where the instance had been terminated", then = "DistroX recovery should be successful, the cluster should be up and running with same volumes")
public void testEphemeralDistroXMasterRepairWithTerminatedInstances(TestContext testContext) {
    String distrox = resourcePropertyProvider().getName();
    List<String> actualVolumeIds = new ArrayList<>();
    List<String> expectedVolumeIds = new ArrayList<>();
    String userCrn = testContext.getActingUserCrn().toString();
    String workloadUsername = testContext.given(UmsTestDto.class).assignTarget(EnvironmentTestDto.class.getSimpleName()).when(umsTestClient.getUserDetails(userCrn, regionAwareInternalCrnGeneratorFactory)).getResponse().getWorkloadUsername();
    testContext.given(FreeIpaTestDto.class).when(freeIpaTestClient.describe()).given(FreeIpaUserSyncTestDto.class).when(freeIpaTestClient.getLastSyncOperationStatus()).await(OperationState.COMPLETED).given(UmsTestDto.class).assignTarget(EnvironmentTestDto.class.getSimpleName()).when(umsTestClient.setWorkloadPassword(workloadPassword, regionAwareInternalCrnGeneratorFactory)).given(FreeIpaUserSyncTestDto.class).when(freeIpaTestClient.syncAll()).await(OperationState.COMPLETED).given(FreeIpaTestDto.class).when(freeIpaTestClient.describe()).validate();
    testContext.given(DistroXTestDto.class).when(distroXTestClient.get()).then(this::verifyMountedDisks).then((tc, testDto, client) -> {
        List<InstanceGroupV4Response> instanceGroups = testDto.getResponse().getInstanceGroups();
        return sshJUtil.checkMeteringStatus(testDto, instanceGroups, List.of(MASTER.getName()));
    }).then((tc, testDto, client) -> {
        CloudFunctionality cloudFunctionality = tc.getCloudProvider().getCloudFunctionality();
        List<String> instancesToDelete = distroxUtil.getInstanceIds(testDto, client, MASTER.getName());
        expectedVolumeIds.addAll(cloudFunctionality.listInstanceVolumeIds(testDto.getName(), instancesToDelete));
        cloudFunctionality.deleteInstances(testDto.getName(), instancesToDelete);
        return testDto;
    }).awaitForHostGroup(MASTER.getName(), InstanceStatus.DELETED_ON_PROVIDER_SIDE).when(distroXTestClient.repair(MASTER), key(distrox)).await(STACK_AVAILABLE, key(distrox)).awaitForHealthyInstances().then(this::verifyMountedDisks).then((tc, testDto, client) -> clouderaManagerUtil.checkClouderaManagerYarnNodemanagerRoleConfigGroups(testDto, workloadUsername, workloadPassword)).then((tc, testDto, client) -> {
        CloudFunctionality cloudFunctionality = tc.getCloudProvider().getCloudFunctionality();
        List<String> instanceIds = distroxUtil.getInstanceIds(testDto, client, MASTER.getName());
        actualVolumeIds.addAll(cloudFunctionality.listInstanceVolumeIds(testDto.getName(), instanceIds));
        return testDto;
    }).then((tc, testDto, client) -> VolumeUtils.compareVolumeIdsAfterRepair(testDto, actualVolumeIds, expectedVolumeIds)).validate();
}
Also used : UmsTestDto(com.sequenceiq.it.cloudbreak.dto.ums.UmsTestDto) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) RunningParameter.key(com.sequenceiq.it.cloudbreak.context.RunningParameter.key) Test(org.testng.annotations.Test) CloudPlatform(com.sequenceiq.cloudbreak.common.mappable.CloudPlatform) ArrayList(java.util.ArrayList) Description(com.sequenceiq.it.cloudbreak.context.Description) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) UmsTestClient(com.sequenceiq.it.cloudbreak.client.UmsTestClient) TestContext(com.sequenceiq.it.cloudbreak.context.TestContext) OperationState(com.sequenceiq.freeipa.api.v1.operation.model.OperationState) ClouderaManagerUtil(com.sequenceiq.it.cloudbreak.util.clouderamanager.ClouderaManagerUtil) MASTER(com.sequenceiq.it.cloudbreak.cloud.HostGroupType.MASTER) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) UseSpotInstances(com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) FreeIpaTestClient(com.sequenceiq.it.cloudbreak.client.FreeIpaTestClient) SshJUtil(com.sequenceiq.it.cloudbreak.util.ssh.SshJUtil) List(java.util.List) EnvironmentTestDto(com.sequenceiq.it.cloudbreak.dto.environment.EnvironmentTestDto) DistroXTestClient(com.sequenceiq.it.cloudbreak.client.DistroXTestClient) DistroxUtil(com.sequenceiq.it.cloudbreak.util.DistroxUtil) CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) CloudbreakClient(com.sequenceiq.it.cloudbreak.CloudbreakClient) VolumeUtils(com.sequenceiq.it.cloudbreak.util.VolumeUtils) HostGroupType(com.sequenceiq.it.cloudbreak.cloud.HostGroupType) FreeIpaUserSyncTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaUserSyncTestDto) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) DistroXTestDto(com.sequenceiq.it.cloudbreak.dto.distrox.DistroXTestDto) CloudFunctionality(com.sequenceiq.it.cloudbreak.util.CloudFunctionality) ArrayList(java.util.ArrayList) FreeIpaUserSyncTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaUserSyncTestDto) ArrayList(java.util.ArrayList) List(java.util.List) InstanceGroupV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.instancegroup.InstanceGroupV4Response) FreeIpaTestDto(com.sequenceiq.it.cloudbreak.dto.freeipa.FreeIpaTestDto) Description(com.sequenceiq.it.cloudbreak.context.Description) Test(org.testng.annotations.Test) AbstractE2ETest(com.sequenceiq.it.cloudbreak.testcase.e2e.AbstractE2ETest) UseSpotInstances(com.sequenceiq.it.cloudbreak.util.spot.UseSpotInstances)

Example 2 with RegionAwareInternalCrnGeneratorFactory

use of com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory in project cloudbreak by hortonworks.

the class DefaultUmsUsersStateProviderTest method setupMocks.

private void setupMocks() {
    doAnswer(invocation -> {
        String environmentCrn = invocation.getArgument(0, String.class);
        return new EnvironmentAccessChecker(grpcUmsClient, environmentCrn, authorizationRightChecksFactory.create(environmentCrn), regionAwareInternalCrnGeneratorFactory);
    }).when(environmentAccessCheckerFactory).create(anyString());
    when(grpcUmsClient.listAllGroups(eq(ACCOUNT_ID), any(Optional.class), any())).thenReturn(testData.groups);
    when(grpcUmsClient.listWorkloadAdministrationGroups(eq(ACCOUNT_ID), any(Optional.class), any())).thenReturn(testData.allWags);
    when(grpcUmsClient.listAllUsers(eq(ACCOUNT_ID), any(Optional.class), any())).thenReturn(testData.users);
    when(grpcUmsClient.listAllMachineUsers(eq(ACCOUNT_ID), eq(DefaultUmsUsersStateProvider.DONT_INCLUDE_INTERNAL_MACHINE_USERS), eq(DefaultUmsUsersStateProvider.INCLUDE_WORKLOAD_MACHINE_USERS), any(Optional.class), any())).thenReturn(testData.machineUsers);
    doAnswer(invocation -> {
        String crn = invocation.getArgument(0, String.class);
        Map<String, Boolean> actorRights = testData.memberCrnToActorRights.get(crn);
        return UserSyncConstants.RIGHTS.stream().map(right -> actorRights.get(right)).collect(Collectors.toList());
    }).when(grpcUmsClient).hasRightsNoCache(anyString(), any(List.class), any(Optional.class), any());
    doAnswer(invocation -> {
        String memberCrn = invocation.getArgument(1, String.class);
        return testData.memberCrnToGroupMembership.get(memberCrn).entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).collect(Collectors.toList());
    }).when(grpcUmsClient).listGroupsForMember(eq(ACCOUNT_ID), anyString(), any(Optional.class), any());
    doAnswer(invocation -> {
        String memberCrn = invocation.getArgument(0, String.class);
        return testData.memberCrnToWagMembership.get(memberCrn).entrySet().stream().filter(Map.Entry::getValue).map(Map.Entry::getKey).collect(Collectors.toList());
    }).when(grpcUmsClient).listWorkloadAdministrationGroupsForMember(anyString(), any(Optional.class), any());
    doAnswer(invocation -> workloadCredentialConverter.toWorkloadCredential(testData.memberCrnToWorkloadCredentials.get(invocation.getArgument(0, String.class)))).when(umsCredentialProvider).getCredentials(anyString(), any(Optional.class));
    setupServicePrincipals();
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) UmsUsersState(com.sequenceiq.freeipa.service.freeipa.user.model.UmsUsersState) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) Set(java.util.Set) Mockito.when(org.mockito.Mockito.when) FmsGroupConverter(com.sequenceiq.freeipa.service.freeipa.user.conversion.FmsGroupConverter) FmsUserConverter(com.sequenceiq.freeipa.service.freeipa.user.conversion.FmsUserConverter) Collectors(java.util.stream.Collectors) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Map(java.util.Map) Spy(org.mockito.Spy) Optional(java.util.Optional) WorkloadCredentialConverter(com.sequenceiq.freeipa.service.freeipa.user.conversion.WorkloadCredentialConverter) UserSyncConstants(com.sequenceiq.freeipa.service.freeipa.user.UserSyncConstants) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Optional(java.util.Optional) List(java.util.List) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Map(java.util.Map)

Example 3 with RegionAwareInternalCrnGeneratorFactory

use of com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory in project cloudbreak by hortonworks.

the class UtilAuthorizationService method checkRights.

public CheckRightV4Response checkRights(CheckRightV4Request rightReq) {
    String userCrn = ThreadBasedUserCrnProvider.getUserCrn();
    List<AuthorizationProto.RightCheck> rightChecks = rightReq.getRights().stream().map(rightV4 -> createRightCheckObject(umsRightProvider.getRight(rightV4.getAction()), null)).collect(Collectors.toList());
    List<Boolean> results = grpcUmsClient.hasRights(userCrn, rightChecks, MDCUtils.getRequestId(), regionAwareInternalCrnGeneratorFactory);
    return new CheckRightV4Response(rightReq.getRights().stream().map(rightV4 -> new CheckRightV4SingleResponse(rightV4, results.get(rightReq.getRights().indexOf(rightV4)))).collect(Collectors.toList()));
}
Also used : CheckRightOnResourcesV4Response(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response) CheckRightV4Request(com.sequenceiq.authorization.info.model.CheckRightV4Request) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) LoggerFactory(org.slf4j.LoggerFactory) ResourceFilteringService(com.sequenceiq.authorization.service.list.ResourceFilteringService) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) StringUtils(org.apache.commons.lang3.StringUtils) AuthorizationRule(com.sequenceiq.authorization.service.model.AuthorizationRule) Inject(javax.inject.Inject) CheckResourceRightV4SingleResponse(com.sequenceiq.authorization.info.model.CheckResourceRightV4SingleResponse) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) RightV4(com.sequenceiq.authorization.info.model.RightV4) ThreadBasedUserCrnProvider(com.sequenceiq.cloudbreak.auth.ThreadBasedUserCrnProvider) Lists(com.google.common.collect.Lists) Resource(com.sequenceiq.authorization.service.list.Resource) CheckRightV4Response(com.sequenceiq.authorization.info.model.CheckRightV4Response) Service(org.springframework.stereotype.Service) Map(java.util.Map) AuthorizationProto(com.cloudera.thunderhead.service.authorization.AuthorizationProto) CheckResourceRightsV4Request(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request) ResourceListProvider(com.sequenceiq.authorization.service.list.ResourceListProvider) CheckResourceRightsV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response) CheckRightOnResourcesV4Request(com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request) LinkedListMultimap(com.google.common.collect.LinkedListMultimap) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) Collection(java.util.Collection) CheckRightV4SingleResponse(com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) GrpcUmsClient(com.sequenceiq.cloudbreak.auth.altus.GrpcUmsClient) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) RegionAwareInternalCrnGeneratorFactory(com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory) List(java.util.List) CheckResourceRightV4Response(com.sequenceiq.authorization.info.model.CheckResourceRightV4Response) MDCUtils(com.sequenceiq.cloudbreak.logger.MDCUtils) Optional(java.util.Optional) CheckRightV4Response(com.sequenceiq.authorization.info.model.CheckRightV4Response) CheckRightV4SingleResponse(com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse)

Aggregations

RegionAwareInternalCrnGeneratorFactory (com.sequenceiq.cloudbreak.auth.crn.RegionAwareInternalCrnGeneratorFactory)3 List (java.util.List)3 Map (java.util.Map)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 AuthorizationProto (com.cloudera.thunderhead.service.authorization.AuthorizationProto)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 LinkedListMultimap (com.google.common.collect.LinkedListMultimap)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 CheckResourceRightV4Response (com.sequenceiq.authorization.info.model.CheckResourceRightV4Response)1 CheckResourceRightV4SingleResponse (com.sequenceiq.authorization.info.model.CheckResourceRightV4SingleResponse)1 CheckResourceRightsV4Request (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Request)1 CheckResourceRightsV4Response (com.sequenceiq.authorization.info.model.CheckResourceRightsV4Response)1 CheckRightOnResourcesV4Request (com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Request)1 CheckRightOnResourcesV4Response (com.sequenceiq.authorization.info.model.CheckRightOnResourcesV4Response)1 CheckRightV4Request (com.sequenceiq.authorization.info.model.CheckRightV4Request)1 CheckRightV4Response (com.sequenceiq.authorization.info.model.CheckRightV4Response)1 CheckRightV4SingleResponse (com.sequenceiq.authorization.info.model.CheckRightV4SingleResponse)1