Search in sources :

Example 6 with IdBroker

use of com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker in project cloudbreak by hortonworks.

the class StackToTemplatePreparationObjectConverter method convert.

public TemplatePreparationObject convert(Stack source) {
    try {
        Map<String, Collection<ClusterExposedServiceView>> views = serviceEndpointCollector.prepareClusterExposedServicesViews(source.getCluster(), stackUtil.extractClusterManagerAddress(source));
        DetailedEnvironmentResponse environment = environmentClientService.getByCrn(source.getEnvironmentCrn());
        Credential credential = credentialConverter.convert(environment.getCredential());
        Cluster cluster = clusterService.getById(source.getCluster().getId());
        FileSystem fileSystem = cluster.getFileSystem();
        Optional<LdapView> ldapView = ldapConfigService.get(source.getEnvironmentCrn(), source.getName());
        ClouderaManagerRepo cm = clusterComponentConfigProvider.getClouderaManagerRepoDetails(cluster.getId());
        List<ClouderaManagerProduct> products = clusterComponentConfigProvider.getClouderaManagerProductDetails(cluster.getId());
        BaseFileSystemConfigurationsView fileSystemConfigurationView = getFileSystemConfigurationView(credential, source, fileSystem);
        updateFileSystemViewWithBackupLocation(environment, fileSystemConfigurationView);
        StackInputs stackInputs = getStackInputs(source);
        Map<String, Object> fixInputs = stackInputs.getFixInputs() == null ? new HashMap<>() : stackInputs.getFixInputs();
        fixInputs.putAll(stackInputs.getDatalakeInputs() == null ? new HashMap<>() : stackInputs.getDatalakeInputs());
        Gateway gateway = cluster.getGateway();
        String gatewaySignKey = null;
        if (gateway != null) {
            gatewaySignKey = gateway.getSignKey();
        }
        IdBroker idbroker = idBrokerService.getByCluster(cluster);
        if (idbroker == null) {
            idbroker = idBrokerConverterUtil.generateIdBrokerSignKeys(cluster);
            idBrokerService.save(idbroker);
        }
        String envCrnForVirtualGroups = getEnvironmentCrnForVirtualGroups(environment);
        VirtualGroupRequest virtualGroupRequest = new VirtualGroupRequest(envCrnForVirtualGroups, ldapView.map(LdapView::getAdminGroup).orElse(""));
        String accountId = Crn.safeFromString(source.getResourceCrn()).getAccountId();
        List<UserManagementProto.ServicePrincipalCloudIdentities> servicePrincipalCloudIdentities = grpcUmsClient.listServicePrincipalCloudIdentities(accountId, source.getEnvironmentCrn(), MDCUtils.getRequestId());
        BlueprintView blueprintView = blueprintViewProvider.getBlueprintView(cluster.getBlueprint());
        Optional<String> version = Optional.ofNullable(blueprintView.getVersion());
        Builder builder = Builder.builder().withCloudPlatform(CloudPlatform.valueOf(source.getCloudPlatform())).withRdsConfigs(postgresConfigService.createRdsConfigIfNeeded(source, cluster)).withRdsSslCertificateFilePath(dbCertificateProvider.getSslCertsFilePath()).withGateway(gateway, gatewaySignKey, exposedServiceCollector.getAllKnoxExposed(version)).withIdBroker(idbroker).withCustomConfigurationsView(getCustomConfigurationsView(source, cluster)).withCustomInputs(stackInputs.getCustomInputs() == null ? new HashMap<>() : stackInputs.getCustomInputs()).withFixInputs(fixInputs).withBlueprintView(blueprintView).withFileSystemConfigurationView(fileSystemConfigurationView).withGeneralClusterConfigs(calculateGeneralClusterConfigs(source, cluster)).withLdapConfig(ldapView.orElse(null)).withKerberosConfig(kerberosConfigService.get(source.getEnvironmentCrn(), source.getName()).orElse(null)).withProductDetails(cm, products).withExposedServices(views).withDefaultTags(getStackTags(source)).withSharedServiceConfigs(datalakeService.createSharedServiceConfigsView(source)).withStackType(source.getType()).withVirtualGroupView(virtualGroupRequest);
        transactionService.required(() -> {
            builder.withHostgroups(hostGroupService.getByCluster(cluster.getId()));
        });
        decorateBuilderWithPlacement(source, builder);
        decorateBuilderWithAccountMapping(source, environment, credential, builder, virtualGroupRequest);
        decorateBuilderWithServicePrincipals(source, builder, servicePrincipalCloudIdentities);
        decorateDatalakeView(source, builder);
        return builder.build();
    } catch (AccountTagValidationFailed aTVF) {
        throw new CloudbreakServiceException(aTVF);
    } catch (BlueprintProcessingException | IOException | TransactionService.TransactionExecutionException e) {
        throw new CloudbreakServiceException(e.getMessage(), e);
    }
}
Also used : HashMap(java.util.HashMap) BaseFileSystemConfigurationsView(com.sequenceiq.cloudbreak.template.filesystem.BaseFileSystemConfigurationsView) CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) Builder(com.sequenceiq.cloudbreak.template.TemplatePreparationObject.Builder) IdBroker(com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker) AccountTagValidationFailed(com.sequenceiq.cloudbreak.tag.AccountTagValidationFailed) StackInputs(com.sequenceiq.cloudbreak.cloud.model.StackInputs) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) FileSystem(com.sequenceiq.cloudbreak.domain.FileSystem) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) BlueprintProcessingException(com.sequenceiq.cloudbreak.template.BlueprintProcessingException) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) BlueprintView(com.sequenceiq.cloudbreak.template.views.BlueprintView) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) IOException(java.io.IOException) LdapView(com.sequenceiq.cloudbreak.dto.LdapView) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) VirtualGroupRequest(com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Collection(java.util.Collection) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject)

Example 7 with IdBroker

use of com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker in project cloudbreak by hortonworks.

the class IdBrokerConverterUtil method generateIdBrokerSignKeys.

public IdBroker generateIdBrokerSignKeys(Cluster cluster) {
    IdBroker idBroker = new IdBroker();
    KeyPair identityKey = PkiUtil.generateKeypair();
    KeyPair signKey = PkiUtil.generateKeypair();
    X509Certificate cert = PkiUtil.cert(identityKey, "signing", signKey);
    idBroker.setSignKey(PkiUtil.convert(identityKey.getPrivate()));
    idBroker.setSignPub(PkiUtil.convert(identityKey.getPublic()));
    idBroker.setSignCert(PkiUtil.convert(cert));
    idBroker.setMasterSecret(PasswordUtil.generatePassword());
    idBroker.setCluster(cluster);
    idBroker.setWorkspace(cluster.getWorkspace());
    return idBroker;
}
Also used : KeyPair(java.security.KeyPair) IdBroker(com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker) X509Certificate(java.security.cert.X509Certificate)

Example 8 with IdBroker

use of com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker in project cloudbreak by hortonworks.

the class StackToTemplatePreparationObjectConverterTest method setUp.

@BeforeEach
public void setUp() throws IOException, TransactionService.TransactionExecutionException {
    MockitoAnnotations.initMocks(this);
    doAnswer(invocation -> {
        invocation.getArgument(0, Runnable.class).run();
        return null;
    }).when(transactionService).required(any(Runnable.class));
    User user = new User();
    user.setUserName("applebob@apple.com");
    user.setUserCrn("user-crn");
    Tenant tenant = new Tenant();
    tenant.setId(1L);
    tenant.setName("account");
    user.setTenant(tenant);
    when(stackMock.getCreator()).thenReturn(user);
    when(stackMock.getEnvironmentCrn()).thenReturn("env");
    when(stackMock.getCloudPlatform()).thenReturn(TEST_CLOUD_PLATFORM);
    when(stackMock.cloudPlatform()).thenReturn(TEST_CLOUD_PLATFORM);
    when(stackMock.getType()).thenReturn(StackType.DATALAKE);
    when(stackMock.getRegion()).thenReturn(REGION);
    when(stackMock.getAvailabilityZone()).thenReturn(AVAILABILITY_ZONE);
    when(stackMock.getName()).thenReturn("stackname");
    when(sourceCluster.getId()).thenReturn(TEST_CLUSTER_ID);
    when(cluster.getId()).thenReturn(TEST_CLUSTER_ID);
    when(instanceGroupMetadataCollector.collectMetadata(stackMock)).thenReturn(groupInstances);
    when(cluster.getBlueprint()).thenReturn(blueprint);
    when(blueprint.getBlueprintText()).thenReturn(TEST_BLUEPRINT_TEXT);
    when(blueprint.getStackVersion()).thenReturn("7.2.11");
    when(stackMock.getInputs()).thenReturn(stackInputs);
    when(stackInputs.get(StackInputs.class)).thenReturn(null);
    when(stackMock.getEnvironmentCrn()).thenReturn(TestConstants.CRN);
    when(stackMock.getCluster()).thenReturn(sourceCluster);
    when(sourceCluster.getCustomConfigurations()).thenReturn(customConfigurations);
    when(customConfigurations.getCrn()).thenReturn("test-custom-configs-crn");
    when(stackMock.getResourceCrn()).thenReturn("crn:cdp:datahub:us-west-1:account:cluster:cluster");
    when(clusterService.findOneWithCustomConfigurations(anyLong())).thenReturn(sourceCluster);
    when(accountTagClientService.list()).thenReturn(new HashMap<>());
    when(entitlementService.internalTenant(anyString())).thenReturn(true);
    when(loadBalancerConfigService.getLoadBalancerUserFacingFQDN(anyLong())).thenReturn(null);
    Credential credential = Credential.builder().crn("aCredentialCRN").attributes(new Json("")).build();
    DetailedEnvironmentResponse environmentResponse = DetailedEnvironmentResponse.builder().withIdBrokerMappingSource(IdBrokerMappingSource.MOCK).withCredential(new CredentialResponse()).withAdminGroupName(ADMIN_GROUP_NAME).withCrn(TestConstants.CRN).build();
    when(credentialToCloudCredentialConverter.convert(credential)).thenReturn(cloudCredential);
    when(environmentClientService.getByCrn(anyString())).thenReturn(environmentResponse);
    when(credentialConverter.convert(any(CredentialResponse.class))).thenReturn(credential);
    when(awsMockAccountMappingService.getGroupMappings(REGION, cloudCredential, ADMIN_GROUP_NAME)).thenReturn(MOCK_GROUP_MAPPINGS);
    when(awsMockAccountMappingService.getUserMappings(REGION, cloudCredential)).thenReturn(MOCK_USER_MAPPINGS);
    when(ldapConfigService.get(anyString(), anyString())).thenReturn(Optional.empty());
    when(clusterService.getById(anyLong())).thenReturn(cluster);
    when(customConfigurationsService.getByNameOrCrn(any(NameOrCrn.class))).thenReturn(customConfigurations);
    when(exposedServiceCollector.getAllKnoxExposed(any())).thenReturn(Set.of());
    when(resourceService.getAllByStackId(anyLong())).thenReturn(Collections.EMPTY_LIST);
    IdBroker idbroker = idBrokerConverterUtil.generateIdBrokerSignKeys(cluster);
    when(idBrokerService.getByCluster(any(Cluster.class))).thenReturn(idbroker);
    when(idBrokerService.save(any(IdBroker.class))).thenReturn(idbroker);
    when(grpcUmsClient.listServicePrincipalCloudIdentities(anyString(), anyString(), any(Optional.class))).thenReturn(Collections.EMPTY_LIST);
    when(dbCertificateProvider.getSslCertsFilePath()).thenReturn(SSL_CERTS_FILE_PATH);
    when(stackMock.getId()).thenReturn(1L);
    when(generalClusterConfigsProvider.generalClusterConfigs(any(Stack.class), any(Cluster.class))).thenReturn(new GeneralClusterConfigs());
}
Also used : CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Credential(com.sequenceiq.cloudbreak.dto.credential.Credential) CloudbreakUser(com.sequenceiq.cloudbreak.common.user.CloudbreakUser) User(com.sequenceiq.cloudbreak.workspace.model.User) Optional(java.util.Optional) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) CredentialResponse(com.sequenceiq.environment.api.v1.credential.model.response.CredentialResponse) Json(com.sequenceiq.cloudbreak.common.json.Json) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) IdBroker(com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Tenant(com.sequenceiq.cloudbreak.workspace.model.Tenant) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 9 with IdBroker

use of com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker in project cloudbreak by hortonworks.

the class IdBrokerServiceTest method testGenerateIdBrokerSignKeyWhenKeysNotExist.

@Test
public void testGenerateIdBrokerSignKeyWhenKeysNotExist() {
    Cluster cluster = new Cluster();
    cluster.setId(CLUSTER_ID);
    IdBroker idBroker = new IdBroker();
    when(clusterService.findOneByStackIdOrNotFoundError(STACK_ID)).thenReturn(cluster);
    when(repository.findByClusterId(cluster.getId())).thenReturn(null);
    when(idBrokerConverterUtil.generateIdBrokerSignKeys(cluster)).thenReturn(idBroker);
    ArgumentCaptor<IdBroker> argumentCaptor = ArgumentCaptor.forClass(IdBroker.class);
    underTest.generateIdBrokerSignKey(STACK_ID);
    verify(repository).save(argumentCaptor.capture());
    Assertions.assertEquals(idBroker, argumentCaptor.getValue());
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) IdBroker(com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker) Test(org.junit.jupiter.api.Test)

Example 10 with IdBroker

use of com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker in project cloudbreak by hortonworks.

the class KnoxGatewayConfigProviderTest method roleConfigsWithoutGateway.

@Test
public void roleConfigsWithoutGateway() {
    GeneralClusterConfigs gcc = new GeneralClusterConfigs();
    gcc.setPassword("secret");
    gcc.setAccountId(Optional.of("1234"));
    IdBroker idBroker = new IdBroker();
    idBroker.setMasterSecret("supersecret");
    BlueprintTextProcessor blueprintTextProcessor = mock(BlueprintTextProcessor.class);
    BlueprintView blueprintView = new BlueprintView("text", "7.2.11", "CDH", blueprintTextProcessor);
    TemplatePreparationObject source = Builder.builder().withGeneralClusterConfigs(gcc).withVirtualGroupView(new VirtualGroupRequest(TestConstants.CRN, "")).withIdBroker(idBroker).withBlueprintView(blueprintView).withProductDetails(new ClouderaManagerRepo().withVersion("7.4.2"), List.of(new ClouderaManagerProduct().withVersion("7.2.10").withName("CDH"))).build();
    when(virtualGroupService.createOrGetVirtualGroup(source.getVirtualGroupRequest(), UmsVirtualGroupRight.KNOX_ADMIN)).thenReturn("");
    assertEquals(List.of(config("idbroker_master_secret", "supersecret"), config("idbroker_gateway_knox_admin_groups", ""), config("idbroker_gateway_signing_keystore_name", "signing.jks"), config("idbroker_gateway_signing_keystore_type", "JKS"), config("idbroker_gateway_signing_key_alias", "signing-identity")), underTest.getRoleConfigs(KnoxRoles.IDBROKER, source));
    assertEquals(List.of(config("gateway_master_secret", gcc.getPassword()), config("gateway_default_topology_name", "cdp-proxy"), config("gateway_knox_admin_groups", ""), config("gateway_auto_discovery_enabled", "false"), config("gateway_service_tokenstate_impl", "org.apache.knox.gateway.services.token.impl.JDBCTokenStateService")), underTest.getRoleConfigs(KnoxRoles.KNOX_GATEWAY, source));
    assertEquals(List.of(), underTest.getRoleConfigs("NAMENODE", source));
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) GeneralClusterConfigs(com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs) VirtualGroupRequest(com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest) BlueprintTextProcessor(com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor) BlueprintView(com.sequenceiq.cloudbreak.template.views.BlueprintView) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) IdBroker(com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker) Test(org.junit.Test)

Aggregations

IdBroker (com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker)12 VirtualGroupRequest (com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest)6 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)6 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)6 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)6 GeneralClusterConfigs (com.sequenceiq.cloudbreak.template.model.GeneralClusterConfigs)6 BlueprintView (com.sequenceiq.cloudbreak.template.views.BlueprintView)6 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)5 Gateway (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway)5 BlueprintTextProcessor (com.sequenceiq.cloudbreak.template.processor.BlueprintTextProcessor)5 Test (org.junit.Test)5 LdapView (com.sequenceiq.cloudbreak.dto.LdapView)3 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)2 ExposedServices (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.ExposedServices)2 GatewayTopology (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.GatewayTopology)2 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)2 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2