Search in sources :

Example 1 with StackInputs

use of com.sequenceiq.cloudbreak.cloud.model.StackInputs 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 2 with StackInputs

use of com.sequenceiq.cloudbreak.cloud.model.StackInputs in project cloudbreak by hortonworks.

the class StackToTemplatePreparationObjectConverterTest method testConvertWhenStackInputsDoesNotContainsCustomInputsThenEmptyMapBeStored.

@Test
public void testConvertWhenStackInputsDoesNotContainsCustomInputsThenEmptyMapBeStored() throws IOException {
    StackInputs stackInputs = mock(StackInputs.class);
    when(this.stackInputs.get(StackInputs.class)).thenReturn(stackInputs);
    when(stackInputs.getCustomInputs()).thenReturn(null);
    when(blueprintViewProvider.getBlueprintView(any())).thenReturn(getBlueprintView());
    TemplatePreparationObject result = underTest.convert(stackMock);
    assertThat(result.getCustomInputs().isEmpty()).isTrue();
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) StackInputs(com.sequenceiq.cloudbreak.cloud.model.StackInputs) Test(org.junit.jupiter.api.Test)

Example 3 with StackInputs

use of com.sequenceiq.cloudbreak.cloud.model.StackInputs in project cloudbreak by hortonworks.

the class StackToTemplatePreparationObjectConverterTest method testConvertWhenStackInputsContainsCustomInputsThenThisShouldBeStored.

@Test
public void testConvertWhenStackInputsContainsCustomInputsThenThisShouldBeStored() throws IOException {
    StackInputs stackInputs = mock(StackInputs.class);
    Map<String, Object> customInputs = new LinkedHashMap<>();
    when(this.stackInputs.get(StackInputs.class)).thenReturn(stackInputs);
    when(stackInputs.getCustomInputs()).thenReturn(customInputs);
    when(blueprintViewProvider.getBlueprintView(any())).thenReturn(getBlueprintView());
    TemplatePreparationObject result = underTest.convert(stackMock);
    assertThat(result.getCustomInputs()).isEqualTo(customInputs);
}
Also used : TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) TemplatePreparationObject(com.sequenceiq.cloudbreak.template.TemplatePreparationObject) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackInputs(com.sequenceiq.cloudbreak.cloud.model.StackInputs) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.jupiter.api.Test)

Example 4 with StackInputs

use of com.sequenceiq.cloudbreak.cloud.model.StackInputs in project cloudbreak by hortonworks.

the class StackV4RequestToStackConverter method convert.

public Stack convert(StackV4Request source) {
    Workspace workspace = workspaceService.getForCurrentUser();
    Stack stack = new Stack();
    stack.setEnvironmentCrn(source.getEnvironmentCrn());
    DetailedEnvironmentResponse environment = null;
    if (!StringUtils.isEmpty(source.getEnvironmentCrn())) {
        environment = measure(() -> environmentClientService.getByCrn(source.getEnvironmentCrn()), LOGGER, "Environment responded in {} ms for stack {}", source.getName());
    }
    if (isTemplate(source)) {
        updateCustomDomainOrKerberos(source, stack);
        updateCloudPlatformAndRelatedFields(source, stack, environment);
        convertAsStackTemplate(source, stack, environment);
        setNetworkAsTemplate(source, stack);
    } else {
        convertAsStack(source, stack);
        updateCloudPlatformAndRelatedFields(source, stack, environment);
        setNetworkIfApplicable(source, stack, environment);
        setInstanceGroupNetworkIfApplicable(source, stack, environment);
        stack.getComponents().add(getTelemetryComponent(stack, source));
    }
    Map<String, Object> asMap = providerParameterCalculator.get(source).asMap();
    if (asMap != null) {
        Map<String, String> parameter = new HashMap<>();
        asMap.forEach((key, value) -> parameter.put(key, value.toString()));
        stack.setParameters(parameter);
    }
    setTimeToLive(source, stack);
    stack.setWorkspace(workspace);
    stack.setDisplayName(source.getName());
    stack.setDatalakeCrn(datalakeService.getDatalakeCrn(source, workspace));
    stack.setStackAuthentication(stackAuthenticationV4RequestToStackAuthenticationConverter.convert(source.getAuthentication()));
    stack.setStackStatus(new StackStatus(stack, DetailedStackStatus.PROVISION_REQUESTED));
    stack.setCreated(clock.getCurrentTimeMillis());
    stack.setInstanceGroups(convertInstanceGroups(source, stack));
    Optional<String> parentEnvCloudPlatform = Optional.ofNullable(environment).map(EnvironmentBaseResponse::getParentEnvironmentCloudPlatform);
    measure(() -> updateCluster(source, stack, parentEnvCloudPlatform), LOGGER, "Converted cluster and updated the stack in {} ms for stack {}", source.getName());
    stack.setGatewayPort(source.getGatewayPort());
    stack.setUuid(UUID.randomUUID().toString());
    stack.setType(source.getType());
    stack.setInputs(Json.silent(new StackInputs(source.getInputs(), new HashMap<>(), new HashMap<>())));
    if (source.getImage() != null) {
        stack.getComponents().add(getImageComponent(source, stack));
    }
    if (!isTemplate(source) && environment != null) {
        gatewaySecurityGroupDecorator.extendGatewaySecurityGroupWithDefaultGatewayCidrs(stack, environment.getTunnel());
    }
    stack.setExternalDatabaseCreationType(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getAvailabilityType));
    stack.setExternalDatabaseEngineVersion(getIfNotNull(source.getExternalDatabase(), DatabaseRequest::getDatabaseEngineVersion));
    stack.setDomainDnsResolver(targetedUpscaleSupportService.isUnboundEliminationSupported(Crn.safeFromString(source.getEnvironmentCrn()).getAccountId()) ? DnsResolverType.FREEIPA_FOR_ENV : DnsResolverType.LOCAL_UNBOUND);
    determineServiceTypeTag(stack, source.getTags());
    determineServiceFeatureTag(stack, source.getTags());
    Set<LoadBalancer> loadBalancers = loadBalancerConfigService.createLoadBalancers(stack, environment, source);
    stack.setLoadBalancers(loadBalancers);
    return stack;
}
Also used : HashMap(java.util.HashMap) StackStatus(com.sequenceiq.cloudbreak.domain.stack.StackStatus) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) LoadBalancer(com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer) EnvironmentBaseResponse(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentBaseResponse) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) StackInputs(com.sequenceiq.cloudbreak.cloud.model.StackInputs) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace)

Aggregations

StackInputs (com.sequenceiq.cloudbreak.cloud.model.StackInputs)4 TemplatePreparationObject (com.sequenceiq.cloudbreak.template.TemplatePreparationObject)3 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)1 VirtualGroupRequest (com.sequenceiq.cloudbreak.auth.altus.VirtualGroupRequest)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)1 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)1 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)1 FileSystem (com.sequenceiq.cloudbreak.domain.FileSystem)1 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)1 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)1 IdBroker (com.sequenceiq.cloudbreak.domain.stack.cluster.IdBroker)1 Gateway (com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway)1 LoadBalancer (com.sequenceiq.cloudbreak.domain.stack.loadbalancer.LoadBalancer)1 LdapView (com.sequenceiq.cloudbreak.dto.LdapView)1 Credential (com.sequenceiq.cloudbreak.dto.credential.Credential)1