Search in sources :

Example 1 with YarnScalingServiceV1Response

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

the class CronTimeEvaluatorTest method getMockYarnScalingResponse.

private YarnScalingServiceV1Response getMockYarnScalingResponse(String instanceType, int yarnGivenDecommissionCount) {
    YarnScalingServiceV1Response yarnScalingReponse = new YarnScalingServiceV1Response();
    List decommissionCandidates = new ArrayList();
    for (int i = 1; i <= yarnGivenDecommissionCount; i++) {
        YarnScalingServiceV1Response.DecommissionCandidate decommissionCandidate = new YarnScalingServiceV1Response.DecommissionCandidate();
        decommissionCandidate.setAmCount(2);
        decommissionCandidate.setNodeId(fqdnBase + testHostGroup + i + ":8042");
        decommissionCandidates.add(decommissionCandidate);
    }
    yarnScalingReponse.setDecommissionCandidates(Map.of("candidates", decommissionCandidates));
    return yarnScalingReponse;
}
Also used : YarnScalingServiceV1Response(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with YarnScalingServiceV1Response

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

the class CronTimeEvaluatorTest method validateScheduleBasedScaling.

private ScalingEvent validateScheduleBasedScaling(String testMode, Integer currentHostGroupCount, Integer desiredNodeCount, Optional<Integer> yarnGivenDecommissionCount) throws Exception {
    TimeAlert alert = getAAlert(desiredNodeCount);
    StackV4Response stackV4Response = MockStackResponseGenerator.getMockStackV4Response(clusterCrn, testHostGroup, "testFqdn" + testHostGroup, currentHostGroupCount, 0);
    when(cloudbreakCommunicator.getByCrn(anyString())).thenReturn(stackV4Response);
    when(stackResponseUtils.getNodeCountForHostGroup(stackV4Response, testHostGroup)).thenCallRealMethod();
    when(scalingPolicyTargetCalculator.getDesiredAbsoluteNodeCount(any(ScalingEvent.class), anyInt())).thenCallRealMethod();
    when(dateService.isTrigger(any(TimeAlert.class), anyLong())).thenReturn(true);
    if (!"SCALE_UP_MODE".equals(testMode)) {
        YarnScalingServiceV1Response yarnScalingServiceV1Response = getMockYarnScalingResponse("test", yarnGivenDecommissionCount.get());
        when(stackResponseUtils.getCloudInstanceIdsForHostGroup(any(), any())).thenCallRealMethod();
        when(yarnMetricsClient.getYarnMetricsForCluster(any(Cluster.class), any(StackV4Response.class), anyString(), any(), any(Optional.class))).thenReturn(yarnScalingServiceV1Response);
        when(yarnResponseUtils.getYarnRecommendedDecommissionHostsForHostGroup(anyString(), any(YarnScalingServiceV1Response.class), any(Map.class), anyInt(), any(Optional.class), anyInt())).thenCallRealMethod();
    }
    underTest.publishIfNeeded(List.of(alert));
    VerificationMode verificationMode = "SCALE_UP_MODE".equals(testMode) ? never() : times(1);
    ArgumentCaptor<ScalingEvent> captor = ArgumentCaptor.forClass(ScalingEvent.class);
    verify(eventPublisher).publishEvent(captor.capture());
    verify(stackResponseUtils, verificationMode).getCloudInstanceIdsForHostGroup(any(), any());
    verify(yarnMetricsClient, verificationMode).getYarnMetricsForCluster(any(Cluster.class), any(StackV4Response.class), anyString(), anyString(), any(Optional.class));
    verify(yarnResponseUtils, verificationMode).getYarnRecommendedDecommissionHostsForHostGroup(anyString(), any(YarnScalingServiceV1Response.class), any(Map.class), anyInt(), any(Optional.class), anyInt());
    return captor.getValue();
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) Optional(java.util.Optional) YarnScalingServiceV1Response(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response) TimeAlert(com.sequenceiq.periscope.domain.TimeAlert) ScalingEvent(com.sequenceiq.periscope.monitor.event.ScalingEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) Map(java.util.Map) VerificationMode(org.mockito.verification.VerificationMode)

Example 3 with YarnScalingServiceV1Response

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

the class YarnLoadEvaluatorTest method getMockYarnScalingResponse.

private YarnScalingServiceV1Response getMockYarnScalingResponse(String instanceType, int upScaleCount, int downScaleCount) {
    NewNodeManagerCandidates.Candidate candidate = new NewNodeManagerCandidates.Candidate();
    candidate.setCount(upScaleCount);
    candidate.setModelName(instanceType);
    NewNodeManagerCandidates candidates = new NewNodeManagerCandidates();
    candidates.setCandidates(List.of(candidate));
    YarnScalingServiceV1Response yarnScalingReponse = new YarnScalingServiceV1Response();
    if (upScaleCount > 0) {
        yarnScalingReponse.setNewNMCandidates(candidates);
    }
    List decommissionCandidates = new ArrayList();
    for (int i = 1; i <= downScaleCount; i++) {
        DecommissionCandidate decommissionCandidate = new DecommissionCandidate();
        decommissionCandidate.setAmCount(2);
        decommissionCandidate.setNodeId(fqdnBase + i + ":8042");
        decommissionCandidates.add(decommissionCandidate);
    }
    yarnScalingReponse.setDecommissionCandidates(Map.of("candidates", decommissionCandidates));
    return yarnScalingReponse;
}
Also used : DecommissionCandidate(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response.DecommissionCandidate) DecommissionCandidate(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response.DecommissionCandidate) NewNodeManagerCandidates(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response.NewNodeManagerCandidates) YarnScalingServiceV1Response(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with YarnScalingServiceV1Response

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

the class YarnMetricsClient method getYarnMetricsForCluster.

@Retryable(value = Exception.class, maxAttempts = 2, backoff = @Backoff(delay = 5000))
public YarnScalingServiceV1Response getYarnMetricsForCluster(Cluster cluster, StackV4Response stackV4Response, String hostGroup, String pollingUserCrn, Optional<Integer> mandatoryDownScaleCount) throws Exception {
    TlsConfiguration tlsConfig = tlsSecurityService.getTls(cluster.getId());
    String clusterProxyUrl = clusterProxyConfigurationService.getClusterProxyUrl().orElseThrow(() -> new RuntimeException(String.format("ClusterProxy Not Configured for Cluster %s, " + " cannot query YARN Metrics.", cluster.getStackCrn())));
    Client restClient = RestClientUtil.createClient(tlsConfig.getServerCert(), tlsConfig.getClientCert(), tlsConfig.getClientKey(), true);
    String yarnApiUrl = String.format(YARN_API_URL, clusterProxyUrl, cluster.getStackCrn());
    InstanceConfig instanceConfig = yarnServiceConfigClient.getInstanceConfigFromCM(cluster, stackV4Response, hostGroup);
    YarnScalingServiceV1Request yarnScalingServiceV1Request = new YarnScalingServiceV1Request();
    yarnScalingServiceV1Request.setInstanceTypes(List.of(new HostGroupInstanceType(instanceConfig.getInstanceName(), instanceConfig.getMemoryInMb().intValue(), instanceConfig.getCoreCPU())));
    LOGGER.debug("Using actorCrn '{}' for Cluster '{}' yarn polling.", pollingUserCrn, cluster.getStackCrn());
    UriBuilder yarnMetricsURI = UriBuilder.fromPath(yarnApiUrl).queryParam(PARAM_UPSCALE_FACTOR_NODE_RESOURCE_TYPE, DEFAULT_UPSCALE_RESOURCE_TYPE);
    mandatoryDownScaleCount.ifPresent(scaleDownCount -> yarnMetricsURI.queryParam(PARAM_DOWNSCALE_FACTOR_IN_NODE_COUNT, stackV4Response.getNodeCount()));
    YarnScalingServiceV1Response yarnResponse = requestLogging.logResponseTime(() -> restClient.target(yarnMetricsURI).request().accept(MediaType.APPLICATION_JSON_VALUE).header(HEADER_ACTOR_CRN, pollingUserCrn).post(Entity.json(yarnScalingServiceV1Request), YarnScalingServiceV1Response.class), String.format("YarnScalingAPI query for cluster crn '%s'", cluster.getStackCrn()));
    LOGGER.info("YarnScalingAPI response for cluster crn '{}',  response '{}'", cluster.getStackCrn(), yarnResponse);
    return yarnResponse;
}
Also used : YarnScalingServiceV1Request(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Request) InstanceConfig(com.sequenceiq.periscope.model.InstanceConfig) YarnScalingServiceV1Response(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response) TlsConfiguration(com.sequenceiq.periscope.model.TlsConfiguration) HostGroupInstanceType(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Request.HostGroupInstanceType) Client(javax.ws.rs.client.Client) UriBuilder(javax.ws.rs.core.UriBuilder) Retryable(org.springframework.retry.annotation.Retryable)

Example 5 with YarnScalingServiceV1Response

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

the class YarnLoadEvaluatorTest method captureScalingEvent.

private Optional<ScalingEvent> captureScalingEvent(int runningNodeHostGroupCount, int stoppedNodeHostGroupCount, int yarnUpscaleCount, int yarnDownscaleCount, boolean scalingEventExpected) throws Exception {
    MockitoAnnotations.openMocks(this);
    Cluster cluster = getARunningCluster();
    cluster.setStopStartScalingEnabled(true);
    String hostGroup = "compute";
    StackV4Response stackV4Response = MockStackResponseGenerator.getMockStackV4ResponseWithStoppedAndRunningNodes(CLOUDBREAK_STACK_CRN, hostGroup, fqdnBase, runningNodeHostGroupCount, stoppedNodeHostGroupCount);
    YarnScalingServiceV1Response upScale = getMockYarnScalingResponse(hostGroup, yarnUpscaleCount, yarnDownscaleCount);
    setupMocks(cluster, upScale, stackV4Response);
    underTest.setContext(new ClusterIdEvaluatorContext(AUTOSCALE_CLUSTER_ID));
    underTest.execute();
    Optional<ScalingEvent> scalingEventCaptured = Optional.empty();
    if (scalingEventExpected) {
        ArgumentCaptor<ScalingEvent> captor = ArgumentCaptor.forClass(ScalingEvent.class);
        verify(eventPublisher).publishEvent(captor.capture());
        scalingEventCaptured = Optional.of(captor.getValue());
    }
    return scalingEventCaptured;
}
Also used : StackV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response) YarnScalingServiceV1Response(com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response) ScalingEvent(com.sequenceiq.periscope.monitor.event.ScalingEvent) Cluster(com.sequenceiq.periscope.domain.Cluster) ClusterIdEvaluatorContext(com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString)

Aggregations

YarnScalingServiceV1Response (com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response)7 StackV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.StackV4Response)3 Cluster (com.sequenceiq.periscope.domain.Cluster)3 ScalingEvent (com.sequenceiq.periscope.monitor.event.ScalingEvent)3 List (java.util.List)3 ClusterIdEvaluatorContext (com.sequenceiq.periscope.monitor.context.ClusterIdEvaluatorContext)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Optional (java.util.Optional)2 LoadAlert (com.sequenceiq.periscope.domain.LoadAlert)1 LoadAlertConfiguration (com.sequenceiq.periscope.domain.LoadAlertConfiguration)1 TimeAlert (com.sequenceiq.periscope.domain.TimeAlert)1 UpdateFailedDetails (com.sequenceiq.periscope.domain.UpdateFailedDetails)1 InstanceConfig (com.sequenceiq.periscope.model.InstanceConfig)1 TlsConfiguration (com.sequenceiq.periscope.model.TlsConfiguration)1 YarnScalingServiceV1Request (com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Request)1 HostGroupInstanceType (com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Request.HostGroupInstanceType)1 DecommissionCandidate (com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response.DecommissionCandidate)1 NewNodeManagerCandidates (com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response.NewNodeManagerCandidates)1 YarnMetricsClient (com.sequenceiq.periscope.monitor.client.YarnMetricsClient)1