Search in sources :

Example 1 with AmbariRepo

use of com.sequenceiq.cloudbreak.cloud.model.AmbariRepo in project cloudbreak by hortonworks.

the class AmbariClusterUpgradeService method upgradeCluster.

public void upgradeCluster(Long stackId) throws CloudbreakOrchestratorException {
    Stack stack = stackRepository.findOneWithLists(stackId);
    Cluster cluster = stack.getCluster();
    try {
        OrchestratorType orchestratorType = orchestratorTypeResolver.resolveType(stack.getOrchestrator().getType());
        if (orchestratorType.hostOrchestrator()) {
            HostOrchestrator hostOrchestrator = hostOrchestratorResolver.get(stack.getOrchestrator().getType());
            InstanceMetaData gatewayInstance = stack.getPrimaryGatewayInstance();
            GatewayConfig gatewayConfig = gatewayConfigService.getGatewayConfig(stack, gatewayInstance, cluster.getGateway().getEnableGateway());
            Set<String> gatewayFQDN = Collections.singleton(gatewayInstance.getDiscoveryFQDN());
            ExitCriteriaModel exitCriteriaModel = clusterDeletionBasedModel(stack.getId(), cluster.getId());
            AmbariRepo ambariRepo = componentConfigProvider.getAmbariRepo(cluster.getId());
            Map<String, SaltPillarProperties> servicePillar = new HashMap<>();
            Map<String, Object> credentials = new HashMap<>();
            credentials.put("username", ambariSecurityConfigProvider.getAmbariUserName(cluster));
            credentials.put("password", ambariSecurityConfigProvider.getAmbariPassword(cluster));
            servicePillar.put("ambari-credentials", new SaltPillarProperties("/ambari/credentials.sls", singletonMap("ambari", credentials)));
            if (ambariRepo != null) {
                servicePillar.put("ambari-repo", new SaltPillarProperties("/ambari/repo.sls", singletonMap("ambari", singletonMap("repo", ambariRepo))));
            }
            SaltConfig pillar = new SaltConfig(servicePillar);
            hostOrchestrator.upgradeAmbari(gatewayConfig, gatewayFQDN, stackUtil.collectNodes(stack), pillar, exitCriteriaModel);
        } else {
            throw new UnsupportedOperationException("Ambari upgrade works only with host orchestrator");
        }
    } catch (CloudbreakException e) {
        throw new CloudbreakOrchestratorFailedException(e);
    }
}
Also used : ExitCriteriaModel(com.sequenceiq.cloudbreak.orchestrator.state.ExitCriteriaModel) HostOrchestrator(com.sequenceiq.cloudbreak.orchestrator.host.HostOrchestrator) HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) SaltConfig(com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig) OrchestratorType(com.sequenceiq.cloudbreak.common.model.OrchestratorType) SaltPillarProperties(com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties) Stack(com.sequenceiq.cloudbreak.domain.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) CloudbreakOrchestratorFailedException(com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)

Example 2 with AmbariRepo

use of com.sequenceiq.cloudbreak.cloud.model.AmbariRepo in project cloudbreak by hortonworks.

the class StackToStackResponseConverterTest method setUp.

@Before
public void setUp() throws CloudbreakImageNotFoundException {
    underTest = new StackToStackResponseConverter();
    MockitoAnnotations.initMocks(this);
    when(imageService.getImage(anyLong())).thenReturn(new Image("cb-centos66-amb200-2015-05-25", new HashMap<>(), "redhat6", "", "default", "default-id"));
    when(componentConfigProvider.getCloudbreakDetails(anyLong())).thenReturn(new CloudbreakDetails("version"));
    when(componentConfigProvider.getStackTemplate(anyLong())).thenReturn(new StackTemplate("{}", "version"));
    when(clusterComponentConfigProvider.getHDPRepo(anyLong())).thenReturn(new StackRepoDetails());
    when(clusterComponentConfigProvider.getAmbariDatabase(anyLong())).thenReturn(new AmbariDatabase());
    when(clusterComponentConfigProvider.getAmbariRepo(anyLong())).thenReturn(new AmbariRepo());
}
Also used : AmbariDatabase(com.sequenceiq.cloudbreak.cloud.model.AmbariDatabase) StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) HashMap(java.util.HashMap) CloudbreakDetails(com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails) StackTemplate(com.sequenceiq.cloudbreak.cloud.model.StackTemplate) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) Image(com.sequenceiq.cloudbreak.cloud.model.Image) Before(org.junit.Before)

Example 3 with AmbariRepo

use of com.sequenceiq.cloudbreak.cloud.model.AmbariRepo 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 4 with AmbariRepo

use of com.sequenceiq.cloudbreak.cloud.model.AmbariRepo in project cloudbreak by hortonworks.

the class ClusterV1Controller method upgradeCluster.

@Override
public Response upgradeCluster(Long stackId, AmbariRepoDetailsJson ambariRepoDetails) {
    Stack stack = stackService.get(stackId);
    MDCBuilder.buildMdcContext(stack);
    AmbariRepo ambariRepo = conversionService.convert(ambariRepoDetails, AmbariRepo.class);
    clusterService.upgrade(stackId, ambariRepo);
    return Response.accepted().build();
}
Also used : AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo) Stack(com.sequenceiq.cloudbreak.domain.Stack)

Example 5 with AmbariRepo

use of com.sequenceiq.cloudbreak.cloud.model.AmbariRepo in project cloudbreak by hortonworks.

the class AmbariRepositoryVersionService method setBaseRepoURL.

public void setBaseRepoURL(String stackName, long clusterId, Orchestrator orchestrator, StackService ambariClient) throws CloudbreakException {
    StackRepoDetails stackRepoDetails = getStackRepoDetails(clusterId, orchestrator);
    if (stackRepoDetails != null) {
        try {
            LOGGER.info("Use specific Ambari repository: {}", stackRepoDetails);
            AmbariRepo ambariRepoDetails = clusterComponentConfigProvider.getAmbariRepo(clusterId);
            if (isVersionNewerOrEqualThanLimited(ambariRepoDetails::getVersion, AMBARI_VERSION_2_6_0_0)) {
                addVersionDefinitionFileToAmbari(stackName, ambariClient, stackRepoDetails);
            } else {
                setRepositoryVersionOnApi(ambariClient, stackRepoDetails);
            }
        } catch (HttpResponseException e) {
            String exceptionErrorMsg = AmbariClientExceptionUtil.getErrorMessage(e);
            String msg = String.format("Cannot use the specified Ambari stack: %s. Error: %s", stackRepoDetails.toString(), exceptionErrorMsg);
            throw new AmbariServiceException(msg, e);
        }
    } else {
        LOGGER.info("Using latest HDP repository");
    }
}
Also used : StackRepoDetails(com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails) HttpResponseException(groovyx.net.http.HttpResponseException) AmbariRepo(com.sequenceiq.cloudbreak.cloud.model.AmbariRepo)

Aggregations

AmbariRepo (com.sequenceiq.cloudbreak.cloud.model.AmbariRepo)16 StackRepoDetails (com.sequenceiq.cloudbreak.cloud.model.component.StackRepoDetails)7 HashMap (java.util.HashMap)4 CloudbreakDetails (com.sequenceiq.cloudbreak.cloud.model.CloudbreakDetails)3 Stack (com.sequenceiq.cloudbreak.domain.Stack)3 AmbariRepoDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariRepoDetailsJson)2 Image (com.sequenceiq.cloudbreak.cloud.model.Image)2 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)2 ClusterComponent (com.sequenceiq.cloudbreak.domain.ClusterComponent)2 Json (com.sequenceiq.cloudbreak.domain.json.Json)2 SaltConfig (com.sequenceiq.cloudbreak.orchestrator.model.SaltConfig)2 SaltPillarProperties (com.sequenceiq.cloudbreak.orchestrator.model.SaltPillarProperties)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 AmbariStackDetailsJson (com.sequenceiq.cloudbreak.api.model.AmbariStackDetailsJson)1 AmbariStackDetailsResponse (com.sequenceiq.cloudbreak.api.model.AmbariStackDetailsResponse)1 BlueprintInputJson (com.sequenceiq.cloudbreak.api.model.BlueprintInputJson)1 BlueprintParameterJson (com.sequenceiq.cloudbreak.api.model.BlueprintParameterJson)1 CloudbreakDetailsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakDetailsJson)1 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)1 UserNamePasswordJson (com.sequenceiq.cloudbreak.api.model.UserNamePasswordJson)1