Search in sources :

Example 1 with ClusterComponent

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

the class AmbariClusterServiceTest method setup.

@Before
public void setup() throws CloudbreakException {
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setBlueprint(new Blueprint());
    cluster.getBlueprint().setId(1L);
    Stack stack = new Stack();
    stack.setOrchestrator(new Orchestrator());
    stack.setCluster(cluster);
    when(clusterRepository.findById(any(Long.class))).thenReturn(cluster);
    when(stackService.getByIdWithLists(any(Long.class))).thenReturn(stack);
    when(orchestratorTypeResolver.resolveType(any(Orchestrator.class))).thenReturn(OrchestratorType.HOST);
    when(orchestratorTypeResolver.resolveType(anyString())).thenReturn(OrchestratorType.HOST);
    when(clusterComponentConfigProvider.getHDPRepo(any(Long.class))).thenReturn(new StackRepoDetails());
    when(clusterComponentConfigProvider.store(any(ClusterComponent.class))).thenAnswer(invocation -> invocation.getArgumentAt(0, ClusterComponent.class));
    when(clusterComponentConfigProvider.getComponent(any(Long.class), any(ComponentType.class))).thenReturn(new ClusterComponent());
    when(blueprintService.get(any(Long.class))).thenReturn(cluster.getBlueprint());
}
Also used : ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) Stack(com.sequenceiq.cloudbreak.domain.Stack) Before(org.junit.Before)

Example 2 with ClusterComponent

use of com.sequenceiq.cloudbreak.domain.ClusterComponent 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 3 with ClusterComponent

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

the class ClusterCreationSetupService method determineHDPRepoConfig.

private ClusterComponent determineHDPRepoConfig(Blueprint blueprint, long stackId, Optional<Component> stackHdpRepoConfig, ClusterRequest request, Cluster cluster, IdentityUser user, Optional<Component> stackImageComponent) throws JsonProcessingException {
    Json stackRepoDetailsJson;
    if (!stackHdpRepoConfig.isPresent()) {
        AmbariStackDetailsJson ambariStackDetails = request.getAmbariStackDetails();
        if (ambariStackDetails != null) {
            setOsTypeFromImageIfMissing(cluster, stackImageComponent, ambariStackDetails);
            StackRepoDetails stackRepoDetails = conversionService.convert(ambariStackDetails, StackRepoDetails.class);
            stackRepoDetailsJson = new Json(stackRepoDetails);
        } else {
            StackRepoDetails stackRepoDetails = SerializationUtils.clone(defaultHDPInfo(blueprint, request, user).getRepo());
            Optional<String> vdfUrl = getVDFUrlByOsType(stackId, stackRepoDetails);
            vdfUrl.ifPresent(s -> stackRepoDetails.getStack().put(CUSTOM_VDF_REPO_KEY, s));
            stackRepoDetailsJson = new Json(stackRepoDetails);
        }
    } else {
        stackRepoDetailsJson = stackHdpRepoConfig.get().getAttributes();
    }
    return new ClusterComponent(ComponentType.HDP_REPO_DETAILS, stackRepoDetailsJson, cluster);
}
Also used : AmbariStackDetailsJson(com.sequenceiq.cloudbreak.api.model.AmbariStackDetailsJson) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) AmbariRepoDetailsJson(com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson) AmbariStackDetailsJson(com.sequenceiq.cloudbreak.api.model.AmbariStackDetailsJson) Json(com.sequenceiq.cloudbreak.domain.json.Json)

Example 4 with ClusterComponent

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

the class AmbariClusterService method upgrade.

@Override
public void upgrade(Long stackId, AmbariRepo ambariRepoUpgrade) {
    if (ambariRepoUpgrade != null) {
        Stack stack = stackService.getByIdWithLists(stackId);
        Cluster cluster = clusterRepository.findById(stack.getCluster().getId());
        if (cluster == null) {
            throw new BadRequestException(String.format("Cluster does not exist on stack with '%s' id.", stackId));
        }
        if (!stack.isAvailable()) {
            throw new BadRequestException(String.format("Stack '%s' is currently in '%s' state. Upgrade requests to a cluster can only be made if the underlying stack is 'AVAILABLE'.", stackId, stack.getStatus()));
        }
        if (!cluster.isAvailable()) {
            throw new BadRequestException(String.format("Cluster '%s' is currently in '%s' state. Upgrade requests to a cluster can only be made if the underlying stack is 'AVAILABLE'.", stackId, stack.getStatus()));
        }
        AmbariRepo ambariRepo = clusterComponentConfigProvider.getAmbariRepo(cluster.getId());
        if (ambariRepo == null) {
            try {
                clusterComponentConfigProvider.store(new ClusterComponent(ComponentType.AMBARI_REPO_DETAILS, new Json(ambariRepoUpgrade), stack.getCluster()));
            } catch (JsonProcessingException ignored) {
                throw new BadRequestException(String.format("Ambari repo details cannot be saved. %s", ambariRepoUpgrade));
            }
        } else {
            ClusterComponent component = clusterComponentConfigProvider.getComponent(cluster.getId(), ComponentType.AMBARI_REPO_DETAILS);
            ambariRepo.setBaseUrl(ambariRepoUpgrade.getBaseUrl());
            ambariRepo.setGpgKeyUrl(ambariRepoUpgrade.getGpgKeyUrl());
            ambariRepo.setPredefined(false);
            ambariRepo.setVersion(ambariRepoUpgrade.getVersion());
            try {
                component.setAttributes(new Json(ambariRepo));
                clusterComponentConfigProvider.store(component);
            } catch (JsonProcessingException ignored) {
                throw new BadRequestException(String.format("Ambari repo details cannot be saved. %s", ambariRepoUpgrade));
            }
        }
        try {
            flowManager.triggerClusterUpgrade(stack.getId());
        } catch (RuntimeException e) {
            throw new CloudbreakServiceException(e);
        }
    }
}
Also used : ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) BlueprintParameterJson(com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson) UserNamePasswordJson(com.sequenceiq.cloudbreak.api.model.UserNamePasswordJson) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) Json(com.sequenceiq.cloudbreak.domain.json.Json) BlueprintInputJson(com.sequenceiq.cloudbreak.api.model.BlueprintInputJson) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 5 with ClusterComponent

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

the class ClusterComponentConfigProvider method store.

public ClusterComponent store(ClusterComponent component) {
    LOGGER.debug("Component is going to be saved: {}", component);
    ClusterComponent ret = componentRepository.save(component);
    LOGGER.debug("Component saved: stackId: {}, component: {}", ret.getCluster().getId(), ret);
    return ret;
}
Also used : ClusterComponent(com.sequenceiq.cloudbreak.domain.ClusterComponent)

Aggregations

ClusterComponent (com.sequenceiq.cloudbreak.domain.ClusterComponent)10 Json (com.sequenceiq.cloudbreak.domain.json.Json)6 StackRepoDetails (com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails)4 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 AmbariRepoDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson)3 AmbariStackDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariStackDetailsJson)3 AmbariRepo (com.sequenceiq.cloudbreak.cloud.model.AmbariRepo)3 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)2 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)2 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)2 UserNamePasswordJson (com.sequenceiq.cloudbreak.api.model.UserNamePasswordJson)2 ComponentType (com.sequenceiq.cloudbreak.common.type.ComponentType)2 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)2 HostBootstrapApiContext (com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostBootstrapApiContext)2 HostOrchestratorClusterContext (com.sequenceiq.cloudbreak.core.bootstrap.service.host.context.HostOrchestratorClusterContext)2 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)2 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)2 Orchestrator (com.sequenceiq.cloudbreak.domain.Orchestrator)2