use of com.sequenceiq.periscope.model.InstanceConfig 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;
}
use of com.sequenceiq.periscope.model.InstanceConfig in project cloudbreak by hortonworks.
the class YarnServiceConfigClient method getInstanceConfigFromCM.
@Cacheable(cacheNames = "instanceConfigCache", unless = "#result.getDefaultValueUsed() == true", key = "#cluster.id + #hostGroup")
public InstanceConfig getInstanceConfigFromCM(Cluster cluster, StackV4Response stackV4Response, String hostGroup) throws Exception {
String nodeManagerRoleConfigName = stackResponseUtils.getRoleConfigNameForHostGroup(stackV4Response, hostGroup, YARN_SERVICE, NODEMANAGER_ROLE);
Map<String, ApiConfig> roleConfigProperties = clouderaManagerCommunicator.getRoleConfigPropertiesFromCM(cluster, YARN_SERVICE, nodeManagerRoleConfigName, Set.of(YARN_NODEMANAGER_VCORES, YARN_NODEMANAGER_MEMORY));
ApiConfig apiConfigVCores = roleConfigProperties.get(YARN_NODEMANAGER_VCORES);
ApiConfig apiConfigMemory = roleConfigProperties.get(YARN_NODEMANAGER_MEMORY);
InstanceConfig instanceConfig = new InstanceConfig(hostGroup);
String hostVCores = Optional.ofNullable(apiConfigVCores.getValue()).orElseGet(() -> {
instanceConfig.setDefaultValueUsed(true);
return apiConfigVCores.getDefault();
});
String hostMemory = Optional.ofNullable(apiConfigMemory.getValue()).orElseGet(() -> {
instanceConfig.setDefaultValueUsed(true);
return apiConfigMemory.getDefault();
});
instanceConfig.setCoreCPU(Integer.valueOf(hostVCores));
instanceConfig.setMemoryInMb(Long.valueOf(hostMemory));
return instanceConfig;
}
Aggregations