Search in sources :

Example 1 with HostGroupInstanceType

use of com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Request.HostGroupInstanceType 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)

Aggregations

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 YarnScalingServiceV1Response (com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Response)1 Client (javax.ws.rs.client.Client)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 Retryable (org.springframework.retry.annotation.Retryable)1