Search in sources :

Example 1 with ScalingStatus

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

the class AutoScaleClusterCommonService method createAutoscalingConfigChangedHistoryAndNotify.

protected void createAutoscalingConfigChangedHistoryAndNotify(Cluster cluster) {
    ScalingStatus scalingStatus = ScalingStatus.DISABLED;
    String statusMessage = messagesService.getMessage(MessageCode.AUTOSCALING_DISABLED);
    if (!cluster.getLoadAlerts().isEmpty()) {
        String loadBasedHostGroups = cluster.getLoadAlerts().stream().map(loadAlert -> loadAlert.getScalingPolicy().getHostGroup()).collect(Collectors.joining(","));
        statusMessage = messagesService.getMessage(MessageCode.AUTOSCALING_CONFIG_UPDATED, List.of(AlertType.LOAD, loadBasedHostGroups));
        scalingStatus = ScalingStatus.CONFIG_UPDATED;
    } else if (!cluster.getTimeAlerts().isEmpty()) {
        String timeBasedHostGroups = cluster.getTimeAlerts().stream().map(timeAlert -> timeAlert.getScalingPolicy().getHostGroup()).distinct().collect(Collectors.joining(","));
        statusMessage = messagesService.getMessage(MessageCode.AUTOSCALING_CONFIG_UPDATED, List.of(AlertType.TIME, timeBasedHostGroups));
        scalingStatus = ScalingStatus.CONFIG_UPDATED;
    }
    notificationSender.sendConfigUpdateNotification(cluster);
    notificationSender.sendHistoryUpdateNotification(historyService.createEntry(scalingStatus, statusMessage, cluster), cluster);
}
Also used : AUTOSCALING_DISABLED(com.sequenceiq.periscope.common.MessageCode.AUTOSCALING_DISABLED) CloudbreakCommunicator(com.sequenceiq.periscope.monitor.handler.CloudbreakCommunicator) EntitlementValidationService(com.sequenceiq.periscope.service.EntitlementValidationService) LoggerFactory(org.slf4j.LoggerFactory) AlertType(com.sequenceiq.periscope.api.model.AlertType) Inject(javax.inject.Inject) CloudbreakMessagesService(com.sequenceiq.cloudbreak.message.CloudbreakMessagesService) HistoryService(com.sequenceiq.periscope.service.HistoryService) AuthorizationResourceType(com.sequenceiq.authorization.resource.AuthorizationResourceType) LoadAlert(com.sequenceiq.periscope.domain.LoadAlert) AuthorizationResourceCrnProvider(com.sequenceiq.authorization.service.AuthorizationResourceCrnProvider) History(com.sequenceiq.periscope.domain.History) AuthorizationEnvironmentCrnProvider(com.sequenceiq.authorization.service.AuthorizationEnvironmentCrnProvider) NameOrCrn(com.sequenceiq.periscope.model.NameOrCrn) Retryable(org.springframework.retry.annotation.Retryable) StateJson(com.sequenceiq.periscope.api.model.StateJson) Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) HttpNotificationSender(com.sequenceiq.periscope.notification.HttpNotificationSender) MessageCode(com.sequenceiq.periscope.common.MessageCode) Collectors(java.util.stream.Collectors) Backoff(org.springframework.retry.annotation.Backoff) AutoscaleClusterState(com.sequenceiq.periscope.api.model.AutoscaleClusterState) ClusterProxyConfigurationService(com.sequenceiq.periscope.service.configuration.ClusterProxyConfigurationService) UsageReportingService(com.sequenceiq.periscope.service.UsageReportingService) WORKLOAD(com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType.WORKLOAD) List(java.util.List) Component(org.springframework.stereotype.Component) AutoscaleRecommendationService(com.sequenceiq.periscope.service.AutoscaleRecommendationService) Optional(java.util.Optional) ScalingStatus(com.sequenceiq.periscope.api.model.ScalingStatus) NotFoundException(com.sequenceiq.periscope.service.NotFoundException) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) AutoscaleRestRequestThreadLocalService(com.sequenceiq.periscope.service.AutoscaleRestRequestThreadLocalService) AUTOSCALING_ENABLED(com.sequenceiq.periscope.common.MessageCode.AUTOSCALING_ENABLED) AlertService(com.sequenceiq.periscope.service.AlertService) ClusterService(com.sequenceiq.periscope.service.ClusterService) ScalingStatus(com.sequenceiq.periscope.api.model.ScalingStatus)

Example 2 with ScalingStatus

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

the class ScalingRequest method scaleUp.

private void scaleUp(int scalingAdjustment, int hostGroupNodeCount) {
    metricService.incrementMetricCounter(MetricType.CLUSTER_UPSCALE_TRIGGERED);
    if (scalingHardLimitsService.isViolatingAutoscaleMaxStepInNodeCount(scalingAdjustment)) {
        LOGGER.info("Upscale requested for '{}' nodes. Upscaling with the maximum allowed step size of '{}' node(s)", scalingAdjustment, scalingHardLimitsService.getMaxAutoscaleStepInNodeCount());
        scalingAdjustment = scalingHardLimitsService.getMaxAutoscaleStepInNodeCount();
    }
    String hostGroup = policy.getHostGroup();
    String statusReason = null;
    ScalingStatus scalingStatus = null;
    String stackCrn = cluster.getStackCrn();
    String userCrn = cluster.getClusterPertain().getUserCrn();
    try {
        LOGGER.info("Sending request to add '{}' instance(s) into host group '{}', triggered adjustmentType '{}', cluster '{}', user '{}'", scalingAdjustment, hostGroup, policy.getAdjustmentType(), stackCrn, userCrn);
        UpdateStackV4Request updateStackJson = new UpdateStackV4Request();
        updateStackJson.setWithClusterEvent(true);
        InstanceGroupAdjustmentV4Request instanceGroupAdjustmentJson = new InstanceGroupAdjustmentV4Request();
        instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        instanceGroupAdjustmentJson.setInstanceGroup(hostGroup);
        updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
        if (Boolean.TRUE.equals(cluster.isStopStartScalingEnabled())) {
            cloudbreakCrnClient.withInternalCrn().autoscaleEndpoint().putStackStartInstancesByCrn(stackCrn, updateStackJson);
        } else {
            cloudbreakCrnClient.withInternalCrn().autoscaleEndpoint().putStack(stackCrn, cluster.getClusterPertain().getUserId(), updateStackJson);
        }
        scalingStatus = ScalingStatus.SUCCESS;
        statusReason = getMessageForCBSuccess();
        metricService.incrementMetricCounter(MetricType.CLUSTER_UPSCALE_SUCCESSFUL);
    } catch (RuntimeException e) {
        scalingStatus = ScalingStatus.FAILED;
        statusReason = getMessageForCBException(e);
        LOGGER.error("Couldn't trigger upscaling for host group '{}', cluster '{}', desiredNodeCount '{}', error '{}' ", hostGroup, cluster.getStackCrn(), desiredHostGroupNodeCount, statusReason, e);
        metricService.incrementMetricCounter(MetricType.CLUSTER_UPSCALE_FAILED);
    } finally {
        processAutoscalingTriggered(scalingAdjustment, hostGroupNodeCount, statusReason, scalingStatus);
    }
}
Also used : ScalingStatus(com.sequenceiq.periscope.api.model.ScalingStatus) UpdateStackV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request) InstanceGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)

Example 3 with ScalingStatus

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

the class ScalingRequest method scaleDownByNodeIds.

private void scaleDownByNodeIds(List<String> decommissionNodeIds) {
    metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_TRIGGERED);
    String hostGroup = policy.getHostGroup();
    String statusReason = null;
    ScalingStatus scalingStatus = null;
    try {
        LOGGER.info("Sending request to remove  nodeIdCount '{}', nodeId(s) '{}' from host group '{}', cluster '{}', user '{}'", decommissionNodeIds.size(), decommissionNodeIds, hostGroup, cluster.getStackCrn(), cluster.getClusterPertain().getUserCrn());
        cloudbreakCommunicator.decommissionInstancesForCluster(cluster, decommissionNodeIds);
        scalingStatus = ScalingStatus.SUCCESS;
        statusReason = getMessageForCBSuccess();
        metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_SUCCESSFUL);
    } catch (Exception e) {
        scalingStatus = ScalingStatus.FAILED;
        metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_FAILED);
        statusReason = getMessageForCBException(e);
        LOGGER.error("Couldn't trigger decommissioning for host group '{}', cluster '{}', decommissionNodeCount '{}', " + "decommissionNodeIds '{}', error '{}' ", hostGroup, cluster.getStackCrn(), decommissionNodeIds.size(), decommissionNodeIds, statusReason, e);
    } finally {
        processAutoscalingTriggered(-decommissionNodeIds.size(), existingHostGroupNodeCount, statusReason, scalingStatus);
    }
}
Also used : ScalingStatus(com.sequenceiq.periscope.api.model.ScalingStatus) ClientErrorException(javax.ws.rs.ClientErrorException)

Example 4 with ScalingStatus

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

the class ScalingRequest method scaleDown.

private void scaleDown(int scalingAdjustment, int totalNodes) {
    metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_TRIGGERED);
    String hostGroup = policy.getHostGroup();
    String statusReason = null;
    ScalingStatus scalingStatus = null;
    String stackCrn = cluster.getStackCrn();
    String userCrn = cluster.getClusterPertain().getUserCrn();
    try {
        LOGGER.info("Sending request to remove '{}' node(s) from host group '{}', triggered adjustmentType '{}', cluster '{}', user '{}'", scalingAdjustment, hostGroup, policy.getAdjustmentType(), stackCrn, userCrn);
        UpdateClusterV4Request updateClusterJson = new UpdateClusterV4Request();
        HostGroupAdjustmentV4Request hostGroupAdjustmentJson = new HostGroupAdjustmentV4Request();
        hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        hostGroupAdjustmentJson.setWithStackUpdate(true);
        hostGroupAdjustmentJson.setHostGroup(hostGroup);
        hostGroupAdjustmentJson.setValidateNodeCount(false);
        updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
        // TODO CB-14929: CB-15153 List of nodes not provided. Do we really need to support this? Can Periscope always specify the list of nodes?
        cloudbreakCrnClient.withInternalCrn().autoscaleEndpoint().putCluster(stackCrn, cluster.getClusterPertain().getUserId(), updateClusterJson);
        scalingStatus = ScalingStatus.SUCCESS;
        statusReason = getMessageForCBSuccess();
        metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_SUCCESSFUL);
    } catch (Exception e) {
        scalingStatus = ScalingStatus.FAILED;
        metricService.incrementMetricCounter(MetricType.CLUSTER_DOWNSCALE_FAILED);
        statusReason = getMessageForCBException(e);
        LOGGER.error("Couldn't trigger downscaling for host group '{}', cluster '{}', desiredNodeCount '{}', error '{}' ", hostGroup, cluster.getStackCrn(), desiredHostGroupNodeCount, statusReason, e);
    } finally {
        processAutoscalingTriggered(scalingAdjustment, totalNodes, statusReason, scalingStatus);
    }
}
Also used : ScalingStatus(com.sequenceiq.periscope.api.model.ScalingStatus) HostGroupAdjustmentV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request) UpdateClusterV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request) ClientErrorException(javax.ws.rs.ClientErrorException)

Aggregations

ScalingStatus (com.sequenceiq.periscope.api.model.ScalingStatus)4 ClientErrorException (javax.ws.rs.ClientErrorException)2 AuthorizationResourceType (com.sequenceiq.authorization.resource.AuthorizationResourceType)1 AuthorizationEnvironmentCrnProvider (com.sequenceiq.authorization.service.AuthorizationEnvironmentCrnProvider)1 AuthorizationResourceCrnProvider (com.sequenceiq.authorization.service.AuthorizationResourceCrnProvider)1 InstanceGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.InstanceGroupAdjustmentV4Request)1 UpdateStackV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.autoscales.request.UpdateStackV4Request)1 WORKLOAD (com.sequenceiq.cloudbreak.api.endpoint.v4.common.StackType.WORKLOAD)1 HostGroupAdjustmentV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.HostGroupAdjustmentV4Request)1 UpdateClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.UpdateClusterV4Request)1 CloudbreakMessagesService (com.sequenceiq.cloudbreak.message.CloudbreakMessagesService)1 AlertType (com.sequenceiq.periscope.api.model.AlertType)1 AutoscaleClusterState (com.sequenceiq.periscope.api.model.AutoscaleClusterState)1 StateJson (com.sequenceiq.periscope.api.model.StateJson)1 MessageCode (com.sequenceiq.periscope.common.MessageCode)1 AUTOSCALING_DISABLED (com.sequenceiq.periscope.common.MessageCode.AUTOSCALING_DISABLED)1 AUTOSCALING_ENABLED (com.sequenceiq.periscope.common.MessageCode.AUTOSCALING_ENABLED)1 Cluster (com.sequenceiq.periscope.domain.Cluster)1 History (com.sequenceiq.periscope.domain.History)1 LoadAlert (com.sequenceiq.periscope.domain.LoadAlert)1