Search in sources :

Example 91 with Stack

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

the class ClouderaManagerClusterCreationSetupService method determineCdhRepoConfig.

private Set<ClouderaManagerProduct> determineCdhRepoConfig(Cluster cluster, List<Component> stackCdhRepoConfig, String osType, String blueprintCdhVersion, String imageCatalogName) throws CloudbreakImageCatalogException {
    if (Objects.isNull(stackCdhRepoConfig) || stackCdhRepoConfig.isEmpty()) {
        DefaultCDHInfo defaultCDHInfo = getDefaultCDHInfo(cluster, blueprintCdhVersion, osType, imageCatalogName);
        Map<String, String> stack = defaultCDHInfo.getRepo().getStack();
        Set<ClouderaManagerProduct> cdhProduct = Set.of(new ClouderaManagerProduct().withVersion(defaultCDHInfo.getVersion()).withName(stack.get("repoid").split("-")[0]).withParcel(stack.get(osType)));
        LOGGER.debug("Determined CDH product: {}", cdhProduct);
        return cdhProduct;
    } else {
        Set<ClouderaManagerProduct> products = stackCdhRepoConfig.stream().map(Component::getAttributes).map(json -> json.getSilent(ClouderaManagerProduct.class)).collect(Collectors.toSet());
        return filterParcelsIfNecessary(cluster, products);
    }
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) LoggerFactory(org.slf4j.LoggerFactory) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) ImageBasedDefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHInfo) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) DefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.DefaultCDHInfo) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ClouderaManagerProductsProvider(com.sequenceiq.cloudbreak.cluster.service.ClouderaManagerProductsProvider) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) Service(org.springframework.stereotype.Service) Map(java.util.Map) ClouderaManagerProductV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.product.ClouderaManagerProductV4Request) CDH_PRODUCT_DETAILS(com.sequenceiq.cloudbreak.common.type.ComponentType.CDH_PRODUCT_DETAILS) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Component(com.sequenceiq.cloudbreak.domain.stack.Component) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) PlatformStringTransformer(com.sequenceiq.cloudbreak.service.image.PlatformStringTransformer) ClouderaManagerRepositoryV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.repository.ClouderaManagerRepositoryV4Request) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) Set(java.util.Set) StackMatrixV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.StackMatrixV4Response) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) IOException(java.io.IOException) ClouderaManagerStackDescriptorV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.ClouderaManagerStackDescriptorV4Response) StackType(com.sequenceiq.cloudbreak.cloud.model.component.StackType) ParcelFilterService(com.sequenceiq.cloudbreak.service.parcel.ParcelFilterService) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) List(java.util.List) BlueprintUtils(com.sequenceiq.cloudbreak.cmtemplate.utils.BlueprintUtils) Optional(java.util.Optional) ClouderaManagerV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.ClouderaManagerV4Request) ImageBasedDefaultCDHEntries(com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHEntries) Collections(java.util.Collections) ImageBasedDefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHInfo) DefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.DefaultCDHInfo) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) Component(com.sequenceiq.cloudbreak.domain.stack.Component) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent)

Example 92 with Stack

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

the class ClouderaManagerClusterCreationSetupService method getDefaultCDHInfo.

private DefaultCDHInfo getDefaultCDHInfo(Cluster cluster, String blueprintCdhVersion, String osType, String imageCatalogName) throws CloudbreakImageCatalogException {
    DefaultCDHInfo defaultCDHInfo = null;
    Stack stack = cluster.getStack();
    ImageCatalogPlatform platformString = platformStringTransformer.getPlatformStringForImageCatalog(stack.getCloudPlatform(), stack.getPlatformVariant());
    Map<String, ImageBasedDefaultCDHInfo> entries = imageBasedDefaultCDHEntries.getEntries(cluster.getWorkspace().getId(), platformString, imageCatalogName);
    if (blueprintCdhVersion != null && entries.containsKey(blueprintCdhVersion)) {
        defaultCDHInfo = entries.get(blueprintCdhVersion).getDefaultCDHInfo();
    }
    if (defaultCDHInfo == null) {
        defaultCDHInfo = entries.entrySet().stream().filter(e -> Objects.nonNull(e.getValue().getDefaultCDHInfo().getRepo().getStack().get(osType))).max(ImageBasedDefaultCDHEntries.IMAGE_BASED_CDH_ENTRY_COMPARATOR).orElseThrow(notFound("Default Product Info with OS type:", osType)).getValue().getDefaultCDHInfo();
    }
    return defaultCDHInfo;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) LoggerFactory(org.slf4j.LoggerFactory) ClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request) ImageBasedDefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHInfo) JsonUtil(com.sequenceiq.cloudbreak.common.json.JsonUtil) DefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.DefaultCDHInfo) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ClouderaManagerProductsProvider(com.sequenceiq.cloudbreak.cluster.service.ClouderaManagerProductsProvider) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) Service(org.springframework.stereotype.Service) Map(java.util.Map) ClouderaManagerProductV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.product.ClouderaManagerProductV4Request) CDH_PRODUCT_DETAILS(com.sequenceiq.cloudbreak.common.type.ComponentType.CDH_PRODUCT_DETAILS) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Component(com.sequenceiq.cloudbreak.domain.stack.Component) NotFoundException.notFound(com.sequenceiq.cloudbreak.common.exception.NotFoundException.notFound) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) PlatformStringTransformer(com.sequenceiq.cloudbreak.service.image.PlatformStringTransformer) ClouderaManagerRepositoryV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.repository.ClouderaManagerRepositoryV4Request) Logger(org.slf4j.Logger) Benchmark.measure(com.sequenceiq.cloudbreak.util.Benchmark.measure) Set(java.util.Set) StackMatrixV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.StackMatrixV4Response) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) IOException(java.io.IOException) ClouderaManagerStackDescriptorV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.ClouderaManagerStackDescriptorV4Response) StackType(com.sequenceiq.cloudbreak.cloud.model.component.StackType) ParcelFilterService(com.sequenceiq.cloudbreak.service.parcel.ParcelFilterService) Collectors(java.util.stream.Collectors) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Objects(java.util.Objects) Json(com.sequenceiq.cloudbreak.common.json.Json) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) List(java.util.List) BlueprintUtils(com.sequenceiq.cloudbreak.cmtemplate.utils.BlueprintUtils) Optional(java.util.Optional) ClouderaManagerV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.cm.ClouderaManagerV4Request) ImageBasedDefaultCDHEntries(com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHEntries) Collections(java.util.Collections) ImageBasedDefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHInfo) DefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.DefaultCDHInfo) ImageCatalogPlatform(com.sequenceiq.cloudbreak.service.image.catalog.model.ImageCatalogPlatform) ImageBasedDefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHInfo) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 93 with Stack

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

the class ClusterCommonService method put.

public FlowIdentifier put(String crn, UpdateClusterV4Request updateJson) {
    Stack stack = stackService.getByCrnWithLists(crn);
    Long stackId = stack.getId();
    MDCBuilder.buildMdcContext(stack);
    UserNamePasswordV4Request userNamePasswordJson = updateJson.getUserNamePassword();
    FlowIdentifier flowIdentifier;
    if (userNamePasswordJson != null) {
        flowIdentifier = clusterManagerUserNamePasswordChange(stack, userNamePasswordJson);
    } else if (updateJson.getStatus() != null) {
        LOGGER.debug("Cluster status update request received. Stack id:  {}, status: {} ", stackId, updateJson.getStatus());
        flowIdentifier = clusterOperationService.updateStatus(stackId, updateJson.getStatus());
    } else if (updateJson.getBlueprintName() != null && updateJson.getHostgroups() != null && stack.getCluster().isCreateFailed()) {
        LOGGER.debug("Cluster rebuild request received. Stack id:  {}", stackId);
        try {
            flowIdentifier = recreateCluster(stack, updateJson);
        } catch (TransactionExecutionException e) {
            throw new TransactionRuntimeExecutionException(e);
        }
    } else if (updateJson.getHostGroupAdjustment() != null) {
        environmentService.checkEnvironmentStatus(stack, EnvironmentStatus.upscalable());
        flowIdentifier = clusterHostgroupAdjustmentChange(stackId, updateJson, stack);
    } else {
        LOGGER.info("Invalid cluster update request received. Stack id: {}", stackId);
        throw new BadRequestException("Invalid update cluster request!");
    }
    return flowIdentifier;
}
Also used : TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException)

Example 94 with Stack

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

the class ClusterCommonService method getHostNamesAsIniString.

/**
 * Get cluster host details (ips + cluster name) - ini format
 *
 * @param stack     stack object that is used to fill the cluster details ini
 * @param loginUser ssh username that will be used as a default user in the inventory
 * @return Ini file content in string
 */
public String getHostNamesAsIniString(Stack stack, String loginUser) {
    Cluster cluster = stack.getCluster();
    String clusterName = cluster.getName();
    String serverHost = cluster.getClusterManagerIp();
    List<InstanceMetaData> agentHostsSet = instanceMetaDataService.getAllInstanceMetadataByStackId(stack.getId()).stream().filter(i -> i.getInstanceStatus() != InstanceStatus.TERMINATED).collect(Collectors.toList());
    if (agentHostsSet.isEmpty()) {
        throw new NotFoundException(String.format("Not found any agent hosts (yet) for cluster '%s'", cluster.getId()));
    }
    String agentHosts = agentHostsSet.stream().map(InstanceMetaData::getPublicIpWrapper).collect(Collectors.joining("\n"));
    List<String> hostGroupHostsStrings = agentHostsSet.stream().collect(Collectors.groupingBy(InstanceMetaData::getInstanceGroupName)).entrySet().stream().map(s -> addSectionWithBody(s.getKey(), s.getValue().stream().map(InstanceMetaData::getPublicIpWrapper).collect(Collectors.joining("\n")))).collect(Collectors.toList());
    return String.join("\n", addSectionWithBody("cluster", "name=" + clusterName), addSectionWithBody("server", serverHost), String.join("\n", hostGroupHostsStrings), addSectionWithBody("agent", agentHosts), addSectionWithBody("all:vars", String.join("\n", String.format("ansible_ssh_user=%s", loginUser), "ansible_ssh_common_args='-o StrictHostKeyChecking=no'", "ansible_become=yes")));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DetailedStackStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus) AttachRecipeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.AttachRecipeV4Response) LoggerFactory(org.slf4j.LoggerFactory) UserNamePasswordV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UserNamePasswordV4Request) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) TransactionRuntimeExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionRuntimeExecutionException) InstanceGroupService(com.sequenceiq.cloudbreak.service.stack.InstanceGroupService) HostGroupDecorator(com.sequenceiq.cloudbreak.service.decorator.HostGroupDecorator) CloudbreakEventService(com.sequenceiq.cloudbreak.structuredevent.event.CloudbreakEventService) CmTemplateValidator(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateValidator) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) CertificatesRotationV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.CertificatesRotationV4Request) UpdateRecipesV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.UpdateRecipesV4Response) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) Status(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status) CertificatesRotationV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.CertificatesRotationV4Response) Crn(com.sequenceiq.cloudbreak.auth.crn.Crn) Collectors(java.util.stream.Collectors) List(java.util.List) AttachRecipeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.recipe.AttachRecipeV4Request) ClusterOperationService(com.sequenceiq.cloudbreak.service.cluster.flow.ClusterOperationService) TransactionExecutionException(com.sequenceiq.cloudbreak.common.service.TransactionService.TransactionExecutionException) EnvironmentStatus(com.sequenceiq.environment.api.v1.environment.model.response.EnvironmentStatus) UpdateRecipeService(com.sequenceiq.cloudbreak.service.recipe.UpdateRecipeService) HostGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupV4Request) StackService(com.sequenceiq.cloudbreak.service.stack.StackService) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) UpdateNodeCountValidator(com.sequenceiq.cloudbreak.service.stack.flow.UpdateNodeCountValidator) HostGroupV4RequestToHostGroupConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.updates.HostGroupV4RequestToHostGroupConverter) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) HostGroupService(com.sequenceiq.cloudbreak.service.hostgroup.HostGroupService) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Service(org.springframework.stereotype.Service) FlowIdentifier(com.sequenceiq.flow.api.model.FlowIdentifier) InstanceMetaDataService(com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService) ClusterComponentConfigProvider(com.sequenceiq.cloudbreak.cluster.service.ClusterComponentConfigProvider) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) Logger(org.slf4j.Logger) MaintenanceModeStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.MaintenanceModeStatus) ResourceEvent(com.sequenceiq.cloudbreak.event.ResourceEvent) UpdateRecipesV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.recipe.UpdateRecipesV4Request) NameOrCrn(com.sequenceiq.cloudbreak.api.endpoint.v4.dto.NameOrCrn) DetachRecipeV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.recipe.DetachRecipeV4Response) MAINTENANCE_MODE_ENABLED(com.sequenceiq.cloudbreak.api.endpoint.v4.common.Status.MAINTENANCE_MODE_ENABLED) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) DetachRecipeV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.recipe.DetachRecipeV4Request) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) EnvironmentService(com.sequenceiq.cloudbreak.service.environment.EnvironmentService) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException)

Example 95 with Stack

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

the class ClusterCommonService method refreshRecipes.

public UpdateRecipesV4Response refreshRecipes(NameOrCrn nameOrCrn, Long workspaceId, UpdateRecipesV4Request request) {
    Stack stack = stackService.getByNameOrCrnInWorkspace(nameOrCrn, workspaceId);
    MDCBuilder.buildMdcContext(stack);
    return updateRecipeService.refreshRecipesForCluster(workspaceId, stack, request.getHostGroupRecipes());
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)1041 Test (org.junit.jupiter.api.Test)326 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)255 Test (org.junit.Test)208 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)158 Map (java.util.Map)114 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)113 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)112 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)111 List (java.util.List)101 Set (java.util.Set)101 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)100 Collectors (java.util.stream.Collectors)84 Optional (java.util.Optional)83 HashSet (java.util.HashSet)82 Inject (javax.inject.Inject)80 Logger (org.slf4j.Logger)78 LoggerFactory (org.slf4j.LoggerFactory)78 DetailedStackStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.common.DetailedStackStatus)69 StackStatus (com.sequenceiq.cloudbreak.domain.stack.StackStatus)67