use of com.sequenceiq.periscope.model.yarn.YarnScalingServiceV1Request 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;
}
Aggregations