Search in sources :

Example 36 with Cluster

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

the class StackToAutoscaleStackResponseJsonConverter method convert.

@Override
public AutoscaleStackResponse convert(Stack source) {
    AutoscaleStackResponse result = new AutoscaleStackResponse();
    result.setStackId(source.getId());
    result.setName(source.getName());
    result.setOwner(source.getOwner());
    result.setAccount(source.getOwner());
    result.setGatewayPort(source.getGatewayPort());
    result.setCreated(source.getCreated());
    result.setStatus(source.getStatus());
    if (source.getCluster() != null) {
        Cluster cluster = source.getCluster();
        String gatewayIp = gatewayConfigService.getPrimaryGatewayIp(source);
        result.setAmbariServerIp(gatewayIp);
        result.setUserName(cluster.getUserName());
        result.setPassword(cluster.getPassword());
        result.setClusterStatus(cluster.getStatus());
    }
    return result;
}
Also used : AutoscaleStackResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleStackResponse) Cluster(com.sequenceiq.cloudbreak.domain.Cluster)

Example 37 with Cluster

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

the class StackToStatusConverter method convert.

@Override
public Map<String, Object> convert(Stack source) {
    Map<String, Object> stackStatus = new HashMap<>();
    stackStatus.put("id", source.getId());
    stackStatus.put("status", source.getStatus().name());
    stackStatus.put("statusReason", source.getStatusReason());
    Cluster cluster = source.getCluster();
    if (cluster != null) {
        stackStatus.put("clusterStatus", cluster.getStatus().name());
        stackStatus.put("clusterStatusReason", cluster.getStatusReason());
    }
    return stackStatus;
}
Also used : HashMap(java.util.HashMap) Cluster(com.sequenceiq.cloudbreak.domain.Cluster)

Example 38 with Cluster

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

the class StackService method updateStatus.

@Transactional(TxType.NEVER)
public void updateStatus(Long stackId, StatusRequest status, boolean updateCluster) {
    Stack stack = getByIdWithLists(stackId);
    Cluster cluster = null;
    if (stack.getCluster() != null) {
        cluster = clusterRepository.findOneWithLists(stack.getCluster().getId());
    }
    switch(status) {
        case SYNC:
            sync(stack, false);
            break;
        case FULL_SYNC:
            sync(stack, true);
            break;
        case REPAIR_FAILED_NODES:
            repairFailedNodes(stack);
            break;
        case STOPPED:
            stop(stack, cluster, updateCluster);
            break;
        case STARTED:
            start(stack, cluster, updateCluster);
            break;
        default:
            throw new BadRequestException("Cannot update the status of stack because status request not valid.");
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) Stack(com.sequenceiq.cloudbreak.domain.Stack) Transactional(javax.transaction.Transactional)

Example 39 with Cluster

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

the class AmbariClusterSecurityService method changeOriginalAmbariCredentialsAndCreateCloudbreakUser.

@Override
public void changeOriginalAmbariCredentialsAndCreateCloudbreakUser(Stack stack) throws CloudbreakException {
    Cluster cluster = stack.getCluster();
    LOGGER.info("Changing ambari credentials for cluster: {}, ambari ip: {}", cluster.getName(), cluster.getAmbariIp());
    AmbariClient client = clientFactory.getDefaultAmbariClient(stack);
    String cloudbreakUserName = ambariSecurityConfigProvider.getAmbariUserName(cluster);
    String cloudbreakPassword = ambariSecurityConfigProvider.getAmbariPassword(cluster);
    ambariUserHandler.createAmbariUser(cloudbreakUserName, cloudbreakPassword, stack, client);
    if (ADMIN.equals(cluster.getUserName())) {
        if (!ADMIN.equals(cluster.getPassword())) {
            changeAmbariPassword(ADMIN, ADMIN, cluster.getPassword(), stack, client);
        }
    } else {
        client = ambariUserHandler.createAmbariUser(cluster.getUserName(), cluster.getPassword(), stack, client);
        client.deleteUser(ADMIN);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) AmbariClient(com.sequenceiq.ambari.client.AmbariClient)

Example 40 with Cluster

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

the class AmbariClusterSetupService method buildCluster.

@Override
public void buildCluster(Stack stack) {
    Cluster cluster = stack.getCluster();
    try {
        clusterService.updateCreationDateOnCluster(cluster);
        AmbariClient ambariClient = clientFactory.getAmbariClient(stack, stack.getCluster());
        Set<HostGroup> hostGroups = hostGroupService.getByCluster(cluster.getId());
        BlueprintPreparationObject blueprintPreparationObject = conversionService.convert(stack, BlueprintPreparationObject.class);
        Map<String, List<Map<String, String>>> hostGroupMappings = hostGroupAssociationBuilder.buildHostGroupAssociations(hostGroups);
        Set<HostMetadata> hostsInCluster = hostMetadataRepository.findHostsInCluster(cluster.getId());
        recipeEngine.executePostAmbariStartRecipes(stack, hostGroups);
        ambariRepositoryVersionService.setBaseRepoURL(stack.getName(), cluster.getId(), stack.getOrchestrator(), ambariClient);
        String blueprintText = centralBlueprintUpdater.getBlueprintText(blueprintPreparationObject);
        addBlueprint(stack.getId(), ambariClient, blueprintText, cluster.getTopologyValidation());
        cluster.setExtendedBlueprintText(blueprintText);
        clusterService.updateCluster(cluster);
        PollingResult waitForHostsResult = ambariPollingServiceProvider.hostsPollingService(stack, ambariClient, hostsInCluster);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(waitForHostsResult, cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_HOST_JOIN_FAILED.code()));
        ambariClusterTemplateService.addClusterTemplate(cluster, hostGroupMappings, ambariClient);
        Pair<PollingResult, Exception> pollingResult = ambariOperationService.waitForOperationsToStart(stack, ambariClient, singletonMap("INSTALL_START", 1), START_OPERATION_STATE);
        String message = pollingResult.getRight() == null ? cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()) : pollingResult.getRight().getMessage();
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResult.getLeft(), message);
        Pair<PollingResult, Exception> pollingResultExceptionPair = ambariOperationService.waitForOperations(stack, ambariClient, new HashMap<String, Integer>() {

            {
                put("CLUSTER_INSTALL", 1);
            }
        }, INSTALL_AMBARI_PROGRESS_STATE);
        ambariClusterConnectorPollingResultChecker.checkPollingResult(pollingResultExceptionPair.getLeft(), cloudbreakMessagesService.getMessage(AMBARI_CLUSTER_INSTALL_FAILED.code()));
        recipeEngine.executePostInstall(stack);
        ambariSmartSenseCapturer.capture(0, ambariClient);
        cluster = ambariViewProvider.provideViewInformation(ambariClient, cluster);
        ambariClusterCreationSuccessHandler.handleClusterCreationSuccess(stack, cluster);
    } catch (CancellationException cancellationException) {
        throw cancellationException;
    } catch (HttpResponseException hre) {
        throw new AmbariOperationFailedException("Ambari could not create the cluster: " + AmbariClientExceptionUtil.getErrorMessage(hre), hre);
    } catch (Exception e) {
        LOGGER.error("Error while building the Ambari cluster. Message {}, throwable: {}", e.getMessage(), e);
        throw new AmbariOperationFailedException(e.getMessage(), e);
    }
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) HttpResponseException(groovyx.net.http.HttpResponseException) CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HttpResponseException(groovyx.net.http.HttpResponseException) CloudbreakSecuritySetupException(com.sequenceiq.cloudbreak.core.CloudbreakSecuritySetupException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) CloudbreakServiceException(com.sequenceiq.cloudbreak.service.CloudbreakServiceException) CancellationException(com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException) PollingResult(com.sequenceiq.cloudbreak.service.PollingResult) BlueprintPreparationObject(com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject) List(java.util.List) AmbariClient(com.sequenceiq.ambari.client.AmbariClient) HostMetadata(com.sequenceiq.cloudbreak.domain.HostMetadata)

Aggregations

Cluster (com.sequenceiq.cloudbreak.domain.Cluster)144 Stack (com.sequenceiq.cloudbreak.domain.Stack)68 Test (org.junit.Test)64 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)31 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)26 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)22 CloudbreakException (com.sequenceiq.cloudbreak.service.CloudbreakException)22 HashMap (java.util.HashMap)22 HashSet (java.util.HashSet)15 List (java.util.List)15 ArrayList (java.util.ArrayList)13 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)12 BlueprintPreparationObject (com.sequenceiq.cloudbreak.blueprint.BlueprintPreparationObject)11 Matchers.anyString (org.mockito.Matchers.anyString)11 CancellationException (com.sequenceiq.cloudbreak.cloud.scheduler.CancellationException)10 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)10 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)9 Json (com.sequenceiq.cloudbreak.domain.json.Json)9 PollingResult (com.sequenceiq.cloudbreak.service.PollingResult)9