Search in sources :

Example 11 with Component

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

the class ClusterUpgradeTargetImageService method saveImage.

public void saveImage(Long stackId, StatedImage targetImage) {
    Optional<Component> existingTargetImage = findTargetImageComponent(stackId);
    if (existingTargetImage.isPresent() && isTheSameImage(targetImage, existingTargetImage.get())) {
        LOGGER.debug("The target image {} is already present for stack {}", targetImage.getImage().getUuid(), stackId);
    } else {
        existingTargetImage.ifPresent(this::removeOldTargetImage);
        Component targetImageComponent = createTargetImageComponent(stackId, targetImage);
        LOGGER.debug("Saving target image component for cluster upgrade. {}", targetImageComponent);
        componentConfigProviderService.store(targetImageComponent);
    }
}
Also used : Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Example 12 with Component

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

the class StackImageService method replaceStackImageComponent.

private void replaceStackImageComponent(Stack stack, StatedImage targetImage) {
    try {
        Image newImage = getImageModelFromStatedImage(stack, componentConfigProviderService.getImage(stack.getId()), targetImage);
        Component imageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(newImage), stack);
        componentConfigProviderService.replaceImageComponentWithNew(imageComponent);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info("Could not find image", e);
        throw new CloudbreakServiceException("Could not find image", e);
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Example 13 with Component

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

the class StackService method addCloudbreakDetailsForStack.

private void addCloudbreakDetailsForStack(Stack stack) {
    CloudbreakDetails cbDetails = new CloudbreakDetails(cbVersion);
    try {
        Component cbDetailsComponent = new Component(ComponentType.CLOUDBREAK_DETAILS, ComponentType.CLOUDBREAK_DETAILS.name(), new Json(cbDetails), stack);
        componentConfigProviderService.store(cbDetailsComponent);
    } catch (IllegalArgumentException e) {
        LOGGER.info("Could not create Cloudbreak details component.", e);
    }
}
Also used : CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) Json(com.sequenceiq.cloudbreak.common.json.Json) Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Example 14 with Component

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

the class StackService method addTemplateForStack.

private void addTemplateForStack(Stack stack, String template) {
    StackTemplate stackTemplate = new StackTemplate(template, cbVersion);
    try {
        Component stackTemplateComponent = new Component(ComponentType.STACK_TEMPLATE, ComponentType.STACK_TEMPLATE.name(), new Json(stackTemplate), stack);
        componentConfigProviderService.store(stackTemplateComponent);
    } catch (IllegalArgumentException e) {
        LOGGER.info("Could not create Cloudbreak details component.", e);
    }
}
Also used : StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) Json(com.sequenceiq.cloudbreak.common.json.Json) Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Example 15 with Component

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

the class StackService method create.

@Measure(StackService.class)
public Stack create(Stack stack, String platformString, StatedImage imgFromCatalog, User user, Workspace workspace, Optional<String> externalCrn) {
    if (stack.getGatewayPort() == null) {
        stack.setGatewayPort(nginxPort);
    }
    stack.setCreator(user);
    stack.setWorkspace(workspace);
    setPlatformVariant(stack);
    String stackName = stack.getName();
    MDCBuilder.buildMdcContext(stack);
    GetPlatformTemplateRequest templateRequest = connector.triggerGetTemplate(stack);
    if (!stack.getStackAuthentication().passwordAuthenticationRequired() && !Strings.isNullOrEmpty(stack.getStackAuthentication().getPublicKey())) {
        rsaPublicKeyValidator.validate(stack.getStackAuthentication().getPublicKey());
    }
    if (stack.getOrchestrator() != null) {
        orchestratorService.save(stack.getOrchestrator());
    }
    stack.getStackAuthentication().setLoginUserName(SSH_USER_CB);
    String accountId = ThreadBasedUserCrnProvider.getAccountId();
    if (externalCrn.isPresent()) {
        // it means it is a DL cluster, double check it in sdx service
        sdxClientService.getByCrn(externalCrn.get());
        stack.setResourceCrn(externalCrn.get());
    } else {
        stack.setResourceCrn(createCRN(accountId));
    }
    setDefaultTags(stack);
    Stack savedStack = measure(() -> stackRepository.save(stack), LOGGER, "Stackrepository save took {} ms for stack {}", stackName);
    MDCBuilder.buildMdcContext(savedStack);
    measure(() -> addCloudbreakDetailsForStack(savedStack), LOGGER, "Add Cloudbreak details took {} ms for stack {}", stackName);
    measure(() -> storeTelemetryForStack(savedStack), LOGGER, "Add Telemetry settings took {} ms for stack {}", stackName);
    measure(() -> instanceGroupService.saveAll(savedStack.getInstanceGroups()), LOGGER, "Instance groups saved in {} ms for stack {}", stackName);
    measure(() -> instanceMetaDataService.saveAll(savedStack.getInstanceMetaDataAsList()), LOGGER, "Instance metadatas saved in {} ms for stack {}", stackName);
    measure(() -> loadBalancerPersistenceService.saveAll(savedStack.getLoadBalancers()), LOGGER, "Load balancers saved in {} ms for stack {}", stackName);
    measure(() -> targetGroupPersistenceService.saveAll(savedStack.getTargetGroupAsList()), LOGGER, "Target groups saved in {} ms for stack {}", stackName);
    try {
        Set<Component> components = imageService.create(stack, imgFromCatalog);
        setRuntime(stack, components);
    } catch (CloudbreakImageNotFoundException e) {
        LOGGER.info("Cloudbreak Image not found", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    } catch (CloudbreakImageCatalogException e) {
        LOGGER.info("Cloudbreak Image Catalog error", e);
        throw new CloudbreakApiException(e.getMessage(), e);
    }
    measure(() -> addTemplateForStack(savedStack, connector.waitGetTemplate(templateRequest)), LOGGER, "Save cluster template took {} ms for stack {}", stackName);
    return savedStack;
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) Component(com.sequenceiq.cloudbreak.domain.stack.Component) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) GetPlatformTemplateRequest(com.sequenceiq.cloudbreak.cloud.event.platform.GetPlatformTemplateRequest) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) AutoscaleStack(com.sequenceiq.cloudbreak.domain.projection.AutoscaleStack) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Measure(com.sequenceiq.cloudbreak.aspect.Measure)

Aggregations

Component (com.sequenceiq.cloudbreak.domain.stack.Component)37 Json (com.sequenceiq.cloudbreak.common.json.Json)16 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)14 Image (com.sequenceiq.cloudbreak.cloud.model.Image)12 Test (org.junit.jupiter.api.Test)11 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)6 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)6 ClusterComponent (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent)6 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)5 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)5 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)5 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)4 StackMatrixV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.StackMatrixV4Response)4 ImageBasedDefaultCDHInfo (com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHInfo)4 StackType (com.sequenceiq.cloudbreak.cloud.model.component.StackType)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 CmSyncOperationResult (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationResult)4 DefaultCDHInfo (com.sequenceiq.cloudbreak.cloud.model.component.DefaultCDHInfo)3 ComponentType (com.sequenceiq.cloudbreak.common.type.ComponentType)3 CmParcelSyncOperationResult (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmParcelSyncOperationResult)3