Search in sources :

Example 1 with Component

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

the class ClusterCreationSetupService method prepare.

public Cluster prepare(ClusterRequest request, Stack stack, Blueprint blueprint, IdentityUser user) throws Exception {
    String stackName = stack.getName();
    long start = System.currentTimeMillis();
    Cluster cluster = conversionService.convert(request, Cluster.class);
    cluster.setStack(stack);
    LOGGER.info("Cluster conversion took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    start = System.currentTimeMillis();
    cluster = clusterDecorator.decorate(cluster, request, blueprint, user, stack);
    LOGGER.info("Cluster object decorated in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    start = System.currentTimeMillis();
    List<ClusterComponent> components = new ArrayList<>();
    Set<Component> allComponent = componentConfigProvider.getAllComponentsByStackIdAndType(stack.getId(), Sets.newHashSet(ComponentType.AMBARI_REPO_DETAILS, ComponentType.HDP_REPO_DETAILS, ComponentType.IMAGE));
    Optional<Component> stackAmbariRepoConfig = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.AMBARI_REPO_DETAILS) && c.getName().equalsIgnoreCase(ComponentType.AMBARI_REPO_DETAILS.name())).findAny();
    Optional<Component> stackHdpRepoConfig = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.HDP_REPO_DETAILS) && c.getName().equalsIgnoreCase(ComponentType.HDP_REPO_DETAILS.name())).findAny();
    Optional<Component> stackImageComponent = allComponent.stream().filter(c -> c.getComponentType().equals(ComponentType.IMAGE) && c.getName().equalsIgnoreCase(ComponentType.IMAGE.name())).findAny();
    ClusterComponent ambariRepoConfig = determineAmbariRepoConfig(stackAmbariRepoConfig, request.getAmbariRepoDetailsJson(), stackImageComponent, cluster);
    components.add(ambariRepoConfig);
    ClusterComponent hdpRepoConfig = determineHDPRepoConfig(blueprint, stack.getId(), stackHdpRepoConfig, request, cluster, user, stackImageComponent);
    components.add(hdpRepoConfig);
    checkVDFFile(ambariRepoConfig, hdpRepoConfig, stackName);
    LOGGER.info("Cluster components saved in {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    start = System.currentTimeMillis();
    Cluster savedCluster = clusterService.create(user, stack, cluster, components);
    LOGGER.info("Cluster object creation took {} ms for stack {}", System.currentTimeMillis() - start, stackName);
    return savedCluster;
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) Component(com.sequenceiq.cloudbreak.domain.Component) IdentityUser(com.sequenceiq.cloudbreak.common.model.user.IdentityUser) LoggerFactory(org.slf4j.LoggerFactory) FileSystemValidator(com.sequenceiq.cloudbreak.controller.validation.filesystem.FileSystemValidator) ClusterService(com.sequenceiq.cloudbreak.service.cluster.ClusterService) StringUtils(org.apache.commons.lang3.StringUtils) CUSTOM_VDF_REPO_KEY(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails.CUSTOM_VDF_REPO_KEY) JsonNode(com.fasterxml.jackson.databind.JsonNode) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) DefaultHDPInfo(com.sequenceiq.cloudbreak.cloud.model.component.DefaultHDPInfo) VDF_REPO_KEY_PREFIX(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails.VDF_REPO_KEY_PREFIX) Set(java.util.Set) AMBARI_VERSION_2_6_0_0(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariRepositoryVersionService.AMBARI_VERSION_2_6_0_0) Sets(com.google.common.collect.Sets) List(java.util.List) AmbariRepoDetailsJson(com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson) DefaultHDFInfo(com.sequenceiq.cloudbreak.cloud.model.component.DefaultHDFInfo) Entry(java.util.Map.Entry) ComponentConfigProvider(com.sequenceiq.cloudbreak.service.ComponentConfigProvider) Optional(java.util.Optional) AmbariStackDetailsJson(com.sequenceiq.cloudbreak.api.model.AmbariStackDetailsJson) MDCBuilder(com.sequenceiq.cloudbreak.logger.MDCBuilder) SerializationUtils(org.apache.commons.lang3.SerializationUtils) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) Named(javax.inject.Named) Json(com.sequenceiq.cloudbreak.domain.json.Json) StackInfo(com.sequenceiq.cloudbreak.cloud.model.component.StackInfo) CredentialToCloudCredentialConverter(com.sequenceiq.cloudbreak.converter.spi.CredentialToCloudCredentialConverter) Stack(com.sequenceiq.cloudbreak.domain.Stack) ConversionService(org.springframework.core.convert.ConversionService) ClusterDecorator(com.sequenceiq.cloudbreak.service.decorator.ClusterDecorator) AmbariRepositoryVersionService(com.sequenceiq.cloudbreak.service.cluster.ambari.AmbariRepositoryVersionService) Logger(org.slf4j.Logger) ClusterRequest(com.sequenceiq.cloudbreak.api.model.ClusterRequest) DefaultHDFEntries(com.sequenceiq.cloudbreak.cloud.model.component.DefaultHDFEntries) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) CloudCredential(com.sequenceiq.cloudbreak.cloud.model.CloudCredential) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) DefaultHDPEntries(com.sequenceiq.cloudbreak.cloud.model.component.DefaultHDPEntries) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) BlueprintUtils(com.sequenceiq.cloudbreak.blueprint.utils.BlueprintUtils) DefaultAmbariRepoService(com.sequenceiq.cloudbreak.service.DefaultAmbariRepoService) JsonUtil(com.sequenceiq.cloudbreak.util.JsonUtil) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Component(com.sequenceiq.cloudbreak.domain.Component) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent)

Example 2 with Component

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

the class ComponentConfigProvider method getImage.

public Image getImage(Long stackId) throws CloudbreakImageNotFoundException {
    try {
        Component component = getComponent(stackId, ComponentType.IMAGE, ComponentType.IMAGE.name());
        if (component == null) {
            throw new CloudbreakImageNotFoundException(String.format("Image not found: stackId: %d, componentType: %s, name: %s", stackId, ComponentType.IMAGE.name(), ComponentType.IMAGE.name()));
        }
        LOGGER.debug("Image found! stackId: {}, component: {}", stackId, component);
        return component.getAttributes().get(Image.class);
    } catch (IOException e) {
        throw new CloudbreakServiceException("Failed to read image", e);
    }
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) IOException(java.io.IOException) Component(com.sequenceiq.cloudbreak.domain.Component)

Example 3 with Component

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

the class ContainerConfigService method create.

private Component create(Stack stack, DockerContainer dc) throws CloudbreakException {
    try {
        ContainerConfig config;
        ContainerOrchestrator orchestrator = containerOrchestratorResolver.get(stack.getOrchestrator().getType());
        Map<String, String> customContainerConfig = getCustomContainerConfig(stack);
        Optional<String> customContainerName = Optional.ofNullable(customContainerConfig.get(dc.name()));
        Optional<String> customQueue = getCustomQueue(stack);
        switch(dc) {
            case AMBARI_SERVER:
                config = new Builder(orchestrator.ambariServerContainer(customContainerName), customQueue).build();
                break;
            case AMBARI_AGENT:
                config = new Builder(orchestrator.ambariClientContainer(customContainerName), customQueue).build();
                break;
            case AMBARI_DB:
                config = new Builder(orchestrator.ambariDbContainer(customContainerName), customQueue).build();
                break;
            default:
                throw new CloudbreakServiceException(String.format("No configuration exist for %s", dc));
        }
        Component component = new Component(ComponentType.CONTAINER, dc.name(), new Json(config), stack);
        return componentConfigProvider.store(component);
    } catch (IOException ignored) {
        throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
    }
}
Also used : ContainerConfig(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConfig) ContainerOrchestrator(com.sequenceiq.cloudbreak.orchestrator.container.ContainerOrchestrator) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) Builder(com.sequenceiq.cloudbreak.core.bootstrap.config.ContainerConfigBuilder.Builder) Json(com.sequenceiq.cloudbreak.domain.json.Json) IOException(java.io.IOException) Component(com.sequenceiq.cloudbreak.domain.Component)

Example 4 with Component

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

the class ContainerConfigService method get.

public ContainerConfig get(Stack stack, DockerContainer dc) {
    try {
        Component component = componentConfigProvider.getComponent(stack.getId(), ComponentType.CONTAINER, dc.name());
        if (component == null) {
            component = create(stack, dc);
            LOGGER.info("Container component definition created: {}", component);
        } else {
            LOGGER.info("Container component definition found in database: {}", component);
        }
        return component.getAttributes().get(ContainerConfig.class);
    } catch (CloudbreakException | IOException ignored) {
        throw new CloudbreakServiceException(String.format("Failed to parse component ContainerConfig for stack: %d, container: %s", stack.getId(), dc.getName()));
    }
}
Also used : CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) IOException(java.io.IOException) Component(com.sequenceiq.cloudbreak.domain.Component)

Example 5 with Component

use of com.sequenceiq.cloudbreak.domain.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);
        componentConfigProvider.store(cbDetailsComponent);
    } catch (JsonProcessingException e) {
        LOGGER.error("Could not create Cloudbreak details component.", e);
    }
}
Also used : CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) Json(com.sequenceiq.cloudbreak.domain.json.Json) Component(com.sequenceiq.cloudbreak.domain.Component) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Aggregations

Component (com.sequenceiq.cloudbreak.domain.Component)9 Json (com.sequenceiq.cloudbreak.domain.json.Json)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 IOException (java.io.IOException)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.service.CloudbreakServiceException)3 InstanceGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 StackRepoDetails (com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails)2 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)2 ArrayList (java.util.ArrayList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Sets (com.google.common.collect.Sets)1 AmbariRepoDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson)1 AmbariStackDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariStackDetailsJson)1 ClusterRequest (com.sequenceiq.cloudbreak.api.model.ClusterRequest)1 InstanceGroupType (com.sequenceiq.cloudbreak.api.model.InstanceGroupType)1 BlueprintUtils (com.sequenceiq.cloudbreak.blueprint.utils.BlueprintUtils)1 AmbariRepo (com.sequenceiq.cloudbreak.cloud.model.AmbariRepo)1 CloudCredential (com.sequenceiq.cloudbreak.cloud.model.CloudCredential)1 CloudbreakDetails (com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails)1