Search in sources :

Example 1 with InstanceConfig

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;
}
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 2 with InstanceConfig

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;
}
Also used : InstanceConfig(com.sequenceiq.periscope.model.InstanceConfig) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

InstanceConfig (com.sequenceiq.periscope.model.InstanceConfig)2 ApiConfig (com.cloudera.api.swagger.model.ApiConfig)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 Cacheable (org.springframework.cache.annotation.Cacheable)1 Retryable (org.springframework.retry.annotation.Retryable)1