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);
}
}
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();
}
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);
}
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;
}
Aggregations