Search in sources :

Example 1 with AmbariAddressJson

use of com.sequenceiq.cloudbreak.api.model.AmbariAddressJson in project cloudbreak by hortonworks.

the class ScalingRequest method scaleUp.

private void scaleUp(int scalingAdjustment, int totalNodes) {
    String hostGroup = policy.getHostGroup();
    String ambari = cluster.getHost();
    AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
    ambariAddressJson.setAmbariAddress(ambari);
    History history = null;
    try {
        LOGGER.info("Sending request to add {} instance(s) into host group '{}', triggered policy '{}'", scalingAdjustment, hostGroup, policy.getName());
        Long stackId = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson).getId();
        UpdateStackJson updateStackJson = new UpdateStackJson();
        updateStackJson.setWithClusterEvent(true);
        InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
        instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        instanceGroupAdjustmentJson.setInstanceGroup(hostGroup);
        updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
        cloudbreakClient.stackV1Endpoint().put(stackId, updateStackJson);
        history = historyService.createEntry(ScalingStatus.SUCCESS, "Upscale successfully triggered", totalNodes, policy);
    } catch (RuntimeException e) {
        history = historyService.createEntry(ScalingStatus.FAILED, "Couldn't trigger upscaling due to: " + e.getMessage(), totalNodes, policy);
        LOGGER.error("Error adding nodes to cluster", e);
    } finally {
        if (history != null) {
            notificationSender.send(history);
        }
    }
}
Also used : UpdateStackJson(com.sequenceiq.cloudbreak.api.model.UpdateStackJson) AmbariAddressJson(com.sequenceiq.cloudbreak.api.model.AmbariAddressJson) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) History(com.sequenceiq.periscope.domain.History)

Example 2 with AmbariAddressJson

use of com.sequenceiq.cloudbreak.api.model.AmbariAddressJson 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 3 with AmbariAddressJson

use of com.sequenceiq.cloudbreak.api.model.AmbariAddressJson in project cloudbreak by hortonworks.

the class ScalingRequest method scaleDown.

private void scaleDown(int scalingAdjustment, int totalNodes) {
    String hostGroup = policy.getHostGroup();
    String ambari = cluster.getHost();
    AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
    ambariAddressJson.setAmbariAddress(ambari);
    History history = null;
    try {
        LOGGER.info("Sending request to remove {} node(s) from host group '{}', triggered policy '{}'", scalingAdjustment, hostGroup, policy.getName());
        Long stackId = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson).getId();
        UpdateClusterJson updateClusterJson = new UpdateClusterJson();
        HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
        hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        hostGroupAdjustmentJson.setWithStackUpdate(true);
        hostGroupAdjustmentJson.setHostGroup(hostGroup);
        updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
        cloudbreakClient.clusterEndpoint().put(stackId, updateClusterJson);
        history = historyService.createEntry(ScalingStatus.SUCCESS, "Downscale successfully triggered", totalNodes, policy);
    } catch (Exception e) {
        history = historyService.createEntry(ScalingStatus.FAILED, "Couldn't trigger downscaling due to: " + e.getMessage(), totalNodes, policy);
        LOGGER.error("Error removing nodes from the cluster", e);
    } finally {
        if (history != null) {
            notificationSender.send(history);
        }
    }
}
Also used : AmbariAddressJson(com.sequenceiq.cloudbreak.api.model.AmbariAddressJson) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) History(com.sequenceiq.periscope.domain.History) UpdateClusterJson(com.sequenceiq.cloudbreak.api.model.UpdateClusterJson)

Example 4 with AmbariAddressJson

use of com.sequenceiq.cloudbreak.api.model.AmbariAddressJson in project cloudbreak by hortonworks.

the class ClusterSecurityService method hasAccess.

private boolean hasAccess(String userId, String account, String ambariAddress, Long stackId) {
    StackResponse stack;
    if (stackId != null) {
        stack = cloudbreakClient.stackV1Endpoint().get(stackId, new HashSet<>());
    } else {
        AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
        ambariAddressJson.setAmbariAddress(ambariAddress);
        stack = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson);
    }
    return stack.getOwner().equals(userId) || (stack.isPublicInAccount() && stack.getAccount().equals(account));
}
Also used : AmbariAddressJson(com.sequenceiq.cloudbreak.api.model.AmbariAddressJson) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) HashSet(java.util.HashSet)

Aggregations

AmbariAddressJson (com.sequenceiq.cloudbreak.api.model.AmbariAddressJson)4 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)2 History (com.sequenceiq.periscope.domain.History)2 AutoscaleClusterResponse (com.sequenceiq.cloudbreak.api.model.AutoscaleClusterResponse)1 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)1 InstanceGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson)1 UpdateClusterJson (com.sequenceiq.cloudbreak.api.model.UpdateClusterJson)1 UpdateStackJson (com.sequenceiq.cloudbreak.api.model.UpdateStackJson)1 Ambari (com.sequenceiq.periscope.domain.Ambari)1 SecurityConfig (com.sequenceiq.periscope.domain.SecurityConfig)1 AmbariStack (com.sequenceiq.periscope.model.AmbariStack)1 HashSet (java.util.HashSet)1