Search in sources :

Example 1 with AmbariStack

use of com.sequenceiq.periscope.model.AmbariStack in project cloudbreak by hortonworks.

the class AutoScaleClusterCommonService method setCluster.

private AutoscaleClusterResponse setCluster(PeriscopeUser user, AutoscaleClusterRequest json, Long clusterId) {
    Ambari ambari = ambariConverter.convert(json);
    Long stackId = json.getStackId();
    boolean access = clusterSecurityService.hasAccess(user, ambari, stackId);
    if (!access) {
        String host = ambari.getHost();
        LOGGER.info("Illegal access to Ambari cluster '{}' from user '{}'", host, user.getEmail());
        throw new AccessDeniedException(String.format("Accessing Ambari cluster '%s' is not allowed", host));
    } else {
        Cluster cluster = clusterRequestConverter.convert(json);
        if (!hasAmbariConnectionDetailsSpecified(json)) {
            AmbariStack ambariStack = new AmbariStack(ambari, stackId, null);
            cluster = clusterService.create(cluster, user, ambariStack, PENDING);
        } else {
            AmbariStack resolvedAmbari = clusterSecurityService.tryResolve(ambari);
            cluster = clusterId == null ? clusterService.create(cluster, user, resolvedAmbari, RUNNING) : clusterService.update(clusterId, resolvedAmbari, cluster.isAutoscalingEnabled());
        }
        createHistoryAndNotification(cluster);
        return createClusterJsonResponse(cluster);
    }
}
Also used : AmbariStack(com.sequenceiq.periscope.model.AmbariStack) AccessDeniedException(org.springframework.security.access.AccessDeniedException) Cluster(com.sequenceiq.periscope.domain.Cluster) Ambari(com.sequenceiq.periscope.domain.Ambari)

Example 2 with AmbariStack

use of com.sequenceiq.periscope.model.AmbariStack in project cloudbreak by hortonworks.

the class ClusterCreationEvaluator method createAmbariStack.

private AmbariStack createAmbariStack(AutoscaleStackResponse stack) {
    String host = stack.getAmbariServerIp();
    String gatewayPort = String.valueOf(stack.getGatewayPort());
    SecurityConfig securityConfig = tlsSecurityService.prepareSecurityConfig(stack.getStackId());
    return new AmbariStack(new Ambari(host, gatewayPort, stack.getUserName(), stack.getPassword()), stack.getStackId(), securityConfig);
}
Also used : AmbariStack(com.sequenceiq.periscope.model.AmbariStack) SecurityConfig(com.sequenceiq.periscope.domain.SecurityConfig) Ambari(com.sequenceiq.periscope.domain.Ambari)

Example 3 with AmbariStack

use of com.sequenceiq.periscope.model.AmbariStack in project cloudbreak by hortonworks.

the class ClusterSecurityService method tryResolve.

public AmbariStack tryResolve(Ambari ambari) {
    try {
        String host = ambari.getHost();
        String user = ambari.getUser();
        String pass = ambari.getPass();
        AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
        ambariAddressJson.setAmbariAddress(host);
        StackResponse stack = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson);
        Long id = stack.getId();
        SecurityConfig securityConfig = tlsSecurityService.prepareSecurityConfig(id);
        if (user == null || pass == null) {
            AutoscaleClusterResponse clusterResponse = cloudbreakClient.clusterEndpoint().getForAutoscale(id);
            return new AmbariStack(new Ambari(host, ambari.getPort(), clusterResponse.getUserName(), clusterResponse.getPassword()), id, securityConfig);
        } else {
            return new AmbariStack(ambari, id, securityConfig);
        }
    } catch (RuntimeException ignored) {
        return new AmbariStack(ambari);
    }
}
Also used : AmbariStack(com.sequenceiq.periscope.model.AmbariStack) AutoscaleClusterResponse(com.sequenceiq.cloudbreak.api.model.AutoscaleClusterResponse) AmbariAddressJson(com.sequenceiq.cloudbreak.api.model.AmbariAddressJson) SecurityConfig(com.sequenceiq.periscope.domain.SecurityConfig) Ambari(com.sequenceiq.periscope.domain.Ambari) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse)

Example 4 with AmbariStack

use of com.sequenceiq.periscope.model.AmbariStack in project cloudbreak by hortonworks.

the class ClusterCreationEvaluator method createOrUpdateCluster.

private void createOrUpdateCluster(AutoscaleStackResponse stack, Optional<Cluster> clusterOptional) {
    AmbariStack resolvedAmbari = createAmbariStack(stack);
    Cluster cluster;
    boolean sendNotification = false;
    if (clusterOptional.isPresent()) {
        cluster = clusterOptional.get();
        MDCBuilder.buildMdcContext(cluster);
        if (PENDING.equals(cluster.getState()) || SUSPENDED.equals(cluster.getState())) {
            ambariHealthCheck(cluster.getUser(), resolvedAmbari);
            LOGGER.info("Update cluster and set it's state to 'RUNNING' for Ambari host: {}", resolvedAmbari.getAmbari().getHost());
            cluster = clusterService.update(cluster.getId(), resolvedAmbari, false, RUNNING, cluster.isAutoscalingEnabled());
            sendNotification = true;
        }
    } else {
        PeriscopeUser user = new PeriscopeUser(stack.getOwner(), null, stack.getAccount());
        MDCBuilder.buildMdcContext(user, stack.getStackId(), null);
        LOGGER.info("Creating cluster for Ambari host: {}", resolvedAmbari.getAmbari().getHost());
        ambariHealthCheck(user, resolvedAmbari);
        cluster = clusterService.create(user, resolvedAmbari, null);
        sendNotification = true;
    }
    if (sendNotification) {
        History history = historyService.createEntry(ScalingStatus.ENABLED, "Autoscaling has been enabled for the cluster.", 0, cluster);
        notificationSender.send(history);
    }
}
Also used : AmbariStack(com.sequenceiq.periscope.model.AmbariStack) PeriscopeUser(com.sequenceiq.periscope.domain.PeriscopeUser) Cluster(com.sequenceiq.periscope.domain.Cluster) History(com.sequenceiq.periscope.domain.History)

Aggregations

AmbariStack (com.sequenceiq.periscope.model.AmbariStack)4 Ambari (com.sequenceiq.periscope.domain.Ambari)3 Cluster (com.sequenceiq.periscope.domain.Cluster)2 SecurityConfig (com.sequenceiq.periscope.domain.SecurityConfig)2 AmbariAddressJson (com.sequenceiq.cloudbreak.api.model.AmbariAddressJson)1 AutoscaleClusterResponse (com.sequenceiq.cloudbreak.api.model.AutoscaleClusterResponse)1 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)1 History (com.sequenceiq.periscope.domain.History)1 PeriscopeUser (com.sequenceiq.periscope.domain.PeriscopeUser)1 AccessDeniedException (org.springframework.security.access.AccessDeniedException)1