Search in sources :

Example 1 with ClusterManager

use of com.sequenceiq.periscope.domain.ClusterManager in project cloudbreak by hortonworks.

the class ClouderaManagerCommunicator method getRoleConfigPropertiesFromCM.

public Map<String, ApiConfig> getRoleConfigPropertiesFromCM(Cluster cluster, String serviceName, String roleGroupRef, Set roleConfigPropertyNames) {
    LOGGER.debug("Retrieving roleConfigProperties for cluster '{}', service '{}', roleGroupRef '{}'", cluster.getStackCrn(), serviceName, roleGroupRef);
    HttpClientConfig httpClientConfig = tlsHttpClientConfigurationService.buildTLSClientConfig(cluster.getStackCrn(), cluster.getClusterManager().getHost(), cluster.getTunnel());
    ClusterManager cm = cluster.getClusterManager();
    String user = secretService.get(cm.getUser());
    String pass = secretService.get(cm.getPass());
    Map<String, ApiConfig> roleConfigProperties = requestLogging.logResponseTime(() -> {
        try {
            ApiClient client = clouderaManagerApiClientProvider.getV31Client(Integer.valueOf(cm.getPort()), user, pass, httpClientConfig);
            client.getHttpClient().interceptors().add(cmOkHttpTracingInterceptor);
            client.getHttpClient().interceptors().add(cmRequestIdProviderInterceptor);
            RoleConfigGroupsResourceApi roleConfigGroupsResourceApi = clouderaManagerApiFactory.getRoleConfigGroupsResourceApi(client);
            return roleConfigGroupsResourceApi.readConfig(cluster.getStackName(), roleGroupRef, serviceName, DataView.FULL.name()).getItems().stream().filter(apiConfig -> roleConfigPropertyNames.contains(apiConfig.getName())).collect(Collectors.toMap(ApiConfig::getName, apiConfig -> apiConfig));
        } catch (Exception ex) {
            throw new RuntimeException(String.format("Error retrieving roleConfigProperties for cluster '%s', service '%s', roleGroupRef '%s'", cluster.getStackCrn(), serviceName, roleGroupRef), ex);
        }
    }, String.format("getRoleConfigPropertiesFromCM for cluster crn '%s'", cluster.getStackCrn()));
    LOGGER.debug("Retrieved roleConfigPropertyValues for cluster '{}', service '{}', roleGroupRef '{}', roleConfigProperties '{}", cluster.getStackCrn(), serviceName, roleGroupRef, roleConfigProperties.values().stream().map(apiConfig -> String.format("ApiConfig Name '%s, Value '%s', Default '%s", apiConfig.getName(), apiConfig.getValue(), apiConfig.getDefault())).collect(Collectors.toSet()));
    return roleConfigProperties;
}
Also used : RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) CmRequestIdProviderInterceptor(com.sequenceiq.cloudbreak.cm.client.tracing.CmRequestIdProviderInterceptor) CmOkHttpTracingInterceptor(com.sequenceiq.cloudbreak.cm.client.tracing.CmOkHttpTracingInterceptor) ApiClient(com.cloudera.api.swagger.client.ApiClient) LoggerFactory(org.slf4j.LoggerFactory) SecretService(com.sequenceiq.cloudbreak.service.secret.service.SecretService) Set(java.util.Set) DataView(com.sequenceiq.cloudbreak.cm.DataView) RequestLogging(com.sequenceiq.periscope.aspects.RequestLogging) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) RoleConfigGroupsResourceApi(com.cloudera.api.swagger.RoleConfigGroupsResourceApi) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) ClusterManager(com.sequenceiq.periscope.domain.ClusterManager) Service(org.springframework.stereotype.Service) Map(java.util.Map) TlsHttpClientConfigurationService(com.sequenceiq.periscope.service.security.TlsHttpClientConfigurationService) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ClusterService(com.sequenceiq.periscope.service.ClusterService) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ApiClient(com.cloudera.api.swagger.client.ApiClient) ClusterManager(com.sequenceiq.periscope.domain.ClusterManager)

Example 2 with ClusterManager

use of com.sequenceiq.periscope.domain.ClusterManager in project cloudbreak by hortonworks.

the class ClusterService method validateClusterUniqueness.

public void validateClusterUniqueness(MonitoredStack stack) {
    Iterable<Cluster> clusters = clusterRepository.findAll();
    boolean clusterForTheSameStackAndClusterManager = StreamSupport.stream(clusters.spliterator(), false).anyMatch(cluster -> {
        boolean equalityOfStackCrn = cluster.getStackCrn() != null && Objects.equals(cluster.getStackCrn(), stack.getStackCrn());
        ClusterManager clusterManager = cluster.getClusterManager();
        ClusterManager newClusterManager = stack.getClusterManager();
        boolean clrMgrObjectsNotNull = clusterManager != null && newClusterManager != null;
        boolean clrMgrHostsNotEmpty = clrMgrObjectsNotNull && !isEmpty(clusterManager.getHost()) && !isEmpty(newClusterManager.getHost());
        boolean equalityOfCMHost = clrMgrObjectsNotNull && clrMgrHostsNotEmpty && clusterManager.getHost().equals(newClusterManager.getHost());
        return equalityOfStackCrn && equalityOfCMHost;
    });
    if (clusterForTheSameStackAndClusterManager) {
        throw new BadRequestException(messagesService.getMessage(CLUSTER_EXISTS_FOR_CRN, Set.of(stack.getStackCrn(), stack.getClusterManager().getVariant().name())));
    }
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) BadRequestException(javax.ws.rs.BadRequestException) ClusterManager(com.sequenceiq.periscope.domain.ClusterManager)

Example 3 with ClusterManager

use of com.sequenceiq.periscope.domain.ClusterManager in project cloudbreak by hortonworks.

the class ClusterService method create.

public Cluster create(AutoscaleStackV4Response stack) {
    Cluster cluster = new Cluster();
    cluster.setStackName(stack.getName());
    cluster.setStackCrn(stack.getStackCrn());
    cluster.setStackId(stack.getStackId());
    cluster.setStackType(stack.getStackType());
    cluster.setTunnel(stack.getTunnel());
    cluster.setState(ClusterState.PENDING);
    cluster.setEnvironmentCrn(stack.getEnvironmentCrn());
    if (stack.getCloudPlatform() != null) {
        cluster.setCloudPlatform(stack.getCloudPlatform().toUpperCase());
    }
    String gatewayPort = String.valueOf(stack.getGatewayPort());
    ClusterManager clusterManager = new ClusterManager(stack.getClusterManagerIp(), gatewayPort, stack.getUserNamePath(), stack.getPasswordPath(), ClusterManagerVariant.CLOUDERA_MANAGER);
    cluster.setClusterManager(clusterManager);
    ClusterPertain clusterPertain = new ClusterPertain(stack.getTenant(), stack.getWorkspaceId(), stack.getUserId(), stack.getUserCrn());
    cluster.setClusterPertain(clusterPertainRepository.findByUserCrn(clusterPertain.getUserCrn()).orElseGet(() -> clusterPertainRepository.save(clusterPertain)));
    cluster = save(cluster);
    securityConfigService.syncSecurityConfigForCluster(cluster.getId());
    altusMachineUserService.initializeMachineUserForEnvironment(cluster);
    calculateClusterStateMetrics();
    return cluster;
}
Also used : ClusterPertain(com.sequenceiq.periscope.domain.ClusterPertain) Cluster(com.sequenceiq.periscope.domain.Cluster) ClusterManager(com.sequenceiq.periscope.domain.ClusterManager)

Example 4 with ClusterManager

use of com.sequenceiq.periscope.domain.ClusterManager in project cloudbreak by hortonworks.

the class MetricTest method getACluster.

private Cluster getACluster(ClusterState clusterState) {
    Cluster cluster = new Cluster();
    cluster.setId(CLUSTER_ID);
    cluster.setStackCrn(STACK_CRN);
    cluster.setClusterPertain(getClusterPertain());
    cluster.setClusterManager(new ClusterManager("host", "port", USER_A_ID, "", ClusterManagerVariant.AMBARI));
    cluster.setState(clusterState);
    return cluster;
}
Also used : Cluster(com.sequenceiq.periscope.domain.Cluster) ClusterManager(com.sequenceiq.periscope.domain.ClusterManager)

Aggregations

Cluster (com.sequenceiq.periscope.domain.Cluster)4 ClusterManager (com.sequenceiq.periscope.domain.ClusterManager)4 RoleConfigGroupsResourceApi (com.cloudera.api.swagger.RoleConfigGroupsResourceApi)1 ApiClient (com.cloudera.api.swagger.client.ApiClient)1 ApiConfig (com.cloudera.api.swagger.model.ApiConfig)1 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)1 DataView (com.sequenceiq.cloudbreak.cm.DataView)1 ClouderaManagerApiClientProvider (com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider)1 ClouderaManagerApiFactory (com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory)1 CmOkHttpTracingInterceptor (com.sequenceiq.cloudbreak.cm.client.tracing.CmOkHttpTracingInterceptor)1 CmRequestIdProviderInterceptor (com.sequenceiq.cloudbreak.cm.client.tracing.CmRequestIdProviderInterceptor)1 SecretService (com.sequenceiq.cloudbreak.service.secret.service.SecretService)1 RequestLogging (com.sequenceiq.periscope.aspects.RequestLogging)1 ClusterPertain (com.sequenceiq.periscope.domain.ClusterPertain)1 ClusterService (com.sequenceiq.periscope.service.ClusterService)1 TlsHttpClientConfigurationService (com.sequenceiq.periscope.service.security.TlsHttpClientConfigurationService)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Inject (javax.inject.Inject)1