Search in sources :

Example 1 with ClusterExposedServiceV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response in project cloudbreak by hortonworks.

the class ClusterToClusterV4ResponseConverter method convert.

public ClusterV4Response convert(Cluster source) {
    ClusterV4Response clusterResponse = new ClusterV4Response();
    clusterResponse.setId(source.getId());
    clusterResponse.setName(source.getName());
    Stack stack = source.getStack();
    clusterResponse.setStatus(stack.getStatus());
    clusterResponse.setStatusReason(stack.getStatusReason());
    setUptime(source, clusterResponse);
    clusterResponse.setDescription(source.getDescription() == null ? "" : source.getDescription());
    String managerAddress = stackUtil.extractClusterManagerAddress(stack);
    Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServicesForTopologies = serviceEndpointCollector.prepareClusterExposedServices(source, managerAddress);
    clusterResponse.setExposedServices(clusterExposedServicesForTopologies);
    convertCustomQueue(source, clusterResponse);
    convertNullableProperties(source, clusterResponse);
    convertContainerConfig(source, clusterResponse);
    clusterResponse.setCreationFinished(source.getCreationFinished());
    decorateResponseWithProxyConfig(source, clusterResponse);
    clusterResponse.setCloudStorage(getCloudStorage(source));
    clusterResponse.setCm(ClusterToClouderaManagerV4ResponseConverter.convert(source));
    clusterResponse.setDatabases(source.getRdsConfigs().stream().filter(rds -> ResourceStatus.USER_MANAGED.equals(rds.getStatus())).map(rds -> rdsConfigToDatabaseV4ResponseConverter.convert(rds)).collect(Collectors.toList()));
    clusterResponse.setWorkspace(workspaceToWorkspaceResourceV4ResponseConverter.convert(source.getWorkspace()));
    clusterResponse.setBlueprint(getIfNotNull(source.getBlueprint(), blueprintToBlueprintV4ResponseConverter::convert));
    clusterResponse.setExtendedBlueprintText(getExtendedBlueprintText(source));
    convertDpSecrets(source, clusterResponse);
    clusterResponse.setServerIp(stackUtil.extractClusterManagerIp(stack));
    clusterResponse.setServerFqdn(source.getFqdn());
    clusterResponse.setServerUrl(serviceEndpointCollector.getManagerServerUrl(source, managerAddress));
    clusterResponse.setCustomConfigurationsName(getIfNotNull(source.getCustomConfigurations(), configurations -> configurations.getName()));
    clusterResponse.setCustomConfigurationsCrn(getIfNotNull(source.getCustomConfigurations(), configurations -> configurations.getCrn()));
    clusterResponse.setDatabaseServerCrn(source.getDatabaseServerCrn());
    clusterResponse.setRangerRazEnabled(source.isRangerRazEnabled());
    clusterResponse.setCertExpirationState(source.getCertExpirationState());
    return clusterResponse;
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) AwsStorageParameters(com.sequenceiq.common.api.cloudstorage.AwsStorageParameters) NullUtil.getIfNotNull(com.sequenceiq.cloudbreak.util.NullUtil.getIfNotNull) ResourceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.common.ResourceStatus) ClusterExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response) AwsEfsParameters(com.sequenceiq.common.api.cloudstorage.AwsEfsParameters) ClusterToClouderaManagerV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.clouderamanager.ClusterToClouderaManagerV4ResponseConverter) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) ProxyConfigDtoService(com.sequenceiq.cloudbreak.service.proxy.ProxyConfigDtoService) StringUtils(org.apache.commons.lang3.StringUtils) StringToSecretResponseConverter(com.sequenceiq.cloudbreak.service.secret.model.StringToSecretResponseConverter) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) CUSTOM_QUEUE(com.sequenceiq.cloudbreak.domain.ClusterAttributes.CUSTOM_QUEUE) Map(java.util.Map) RDSConfigToDatabaseV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.database.RDSConfigToDatabaseV4ResponseConverter) WorkspaceToWorkspaceResourceV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.workspaces.WorkspaceToWorkspaceResourceV4ResponseConverter) AnonymizerUtil.anonymize(com.sequenceiq.cloudbreak.common.anonymizer.AnonymizerUtil.anonymize) GatewayV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.GatewayV4Response) CloudbreakApiException(com.sequenceiq.cloudbreak.exception.CloudbreakApiException) Logger(org.slf4j.Logger) Collection(java.util.Collection) CustomContainerV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.customcontainer.CustomContainerV4Response) CloudStorageResponse(com.sequenceiq.common.api.cloudstorage.CloudStorageResponse) IOException(java.io.IOException) BlueprintToBlueprintV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.blueprint.BlueprintToBlueprintV4ResponseConverter) Collectors(java.util.stream.Collectors) Json(com.sequenceiq.cloudbreak.common.json.Json) Component(org.springframework.stereotype.Component) StackUtil(com.sequenceiq.cloudbreak.util.StackUtil) ServiceEndpointCollector(com.sequenceiq.cloudbreak.service.ServiceEndpointCollector) Entry(java.util.Map.Entry) ClusterV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response) GatewayToGatewayV4ResponseConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.gateway.GatewayToGatewayV4ResponseConverter) ClusterV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.ClusterV4Response) Collection(java.util.Collection) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with ClusterExposedServiceV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response in project cloudbreak by hortonworks.

the class ServiceEndpointCollector method generateGatewayTopology.

private void generateGatewayTopology(Cluster cluster, String managerIp, Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServiceMap, Collection<ExposedService> knownExposedServices, Gateway gateway, Map<String, List<String>> privateIps, GatewayTopology gatewayTopology, Optional<String> version) {
    LOGGER.debug("Generating the topology for '{}' topologies", gatewayTopology.getTopologyName());
    Set<String> exposedServicesInTopology = gateway.getTopologies().stream().flatMap(e -> getExposedServiceStream(e, version)).filter(Objects::nonNull).collect(Collectors.toSet());
    List<ClusterExposedServiceV4Response> uiServices = new ArrayList<>();
    List<ClusterExposedServiceV4Response> apiServices = new ArrayList<>();
    boolean autoTlsEnabled = cluster.getAutoTlsEnabled();
    LOGGER.debug("AutoTls enabled '{}' for the cluster", autoTlsEnabled);
    SecurityConfig securityConfig = cluster.getStack().getSecurityConfig();
    String managerServerUrl = getManagerServerUrl(cluster, managerIp);
    for (ExposedService exposedService : knownExposedServices) {
        if (exposedService.isCmProxied()) {
            List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createCmProxiedServiceEntries(exposedService, gateway, gatewayTopology, managerServerUrl, cluster.getName());
            uiServices.addAll(uiServiceOnPrivateIps);
        } else {
            if (!exposedService.isApiOnly()) {
                List<ClusterExposedServiceV4Response> uiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, false, autoTlsEnabled, securityConfig, version);
                uiServices.addAll(uiServiceOnPrivateIps);
            }
            if (exposedService.isApiIncluded()) {
                List<ClusterExposedServiceV4Response> apiServiceOnPrivateIps = createServiceEntries(exposedService, gateway, gatewayTopology, managerIp, privateIps, exposedServicesInTopology, true, autoTlsEnabled, securityConfig, version);
                apiServices.addAll(apiServiceOnPrivateIps);
            }
        }
    }
    clusterExposedServiceMap.put(gatewayTopology.getTopologyName(), uiServices);
    clusterExposedServiceMap.put(gatewayTopology.getTopologyName() + API_TOPOLOGY_POSTFIX, apiServices);
}
Also used : SecurityConfig(com.sequenceiq.cloudbreak.domain.SecurityConfig) ExposedService(com.sequenceiq.cloudbreak.api.service.ExposedService) ArrayList(java.util.ArrayList) ClusterExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response)

Example 3 with ClusterExposedServiceV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response in project cloudbreak by hortonworks.

the class ServiceEndpointCollector method createExposedServiceResponse.

private ClusterExposedServiceV4Response createExposedServiceResponse(ExposedService exposedService, Gateway gateway, Set<String> exposedServicesInTopology, boolean api, String url) {
    ClusterExposedServiceV4Response service = new ClusterExposedServiceV4Response();
    service.setMode(api ? SSOType.PAM : getSSOType(exposedService, gateway));
    service.setDisplayName(exposedService.getDisplayName());
    service.setKnoxService(exposedService.getKnoxService());
    service.setServiceName(exposedService.getServiceName());
    service.setOpen(isExposed(exposedService, exposedServicesInTopology));
    if (isNotEmpty(url)) {
        service.setServiceUrl(url);
    }
    return service;
}
Also used : ClusterExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response)

Example 4 with ClusterExposedServiceV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response in project cloudbreak by hortonworks.

the class ServiceEndpointCollector method prepareClusterExposedServicesViews.

public Map<String, Collection<ClusterExposedServiceView>> prepareClusterExposedServicesViews(Cluster cluster, String managerIp) {
    Map<String, Collection<ClusterExposedServiceView>> result = new HashMap<>();
    for (Map.Entry<String, Collection<ClusterExposedServiceV4Response>> entry : prepareClusterExposedServices(cluster, managerIp).entrySet()) {
        Set<ClusterExposedServiceView> views = new HashSet<>();
        for (ClusterExposedServiceV4Response response : entry.getValue()) {
            views.add(new ClusterExposedServiceView(response.getServiceName(), response.getDisplayName(), response.getKnoxService(), response.getServiceUrl()));
        }
        result.put(entry.getKey(), views);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Collection(java.util.Collection) HashMap(java.util.HashMap) Map(java.util.Map) ClusterExposedServiceView(com.sequenceiq.cloudbreak.template.views.ClusterExposedServiceView) ClusterExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response) HashSet(java.util.HashSet)

Example 5 with ClusterExposedServiceV4Response

use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response in project cloudbreak by hortonworks.

the class ServiceEndpointCollectorTest method testPrepareClusterExposedServicesByGeneratedBlueprint.

@Test
public void testPrepareClusterExposedServicesByGeneratedBlueprint() {
    Cluster cluster = createClusterWithComponents(new ExposedService[] { exposedService("ATLAS") }, new ExposedService[] { exposedService("HIVE_SERVER"), exposedService("WEBHDFS") }, GatewayType.INDIVIDUAL);
    cluster.getGateway().setGatewayPort(443);
    cluster.setExtendedBlueprintText("extended-blueprint");
    mockBlueprintTextProcessor();
    mockComponentLocator(Lists.newArrayList("10.0.0.1"));
    Map<String, Collection<ClusterExposedServiceV4Response>> clusterExposedServicesMap = underTest.prepareClusterExposedServices(cluster, "10.0.0.1");
    assertEquals(4L, clusterExposedServicesMap.keySet().size());
    Collection<ClusterExposedServiceV4Response> topology2ClusterExposedServiceV4Responses = clusterExposedServicesMap.get("topology2");
    Optional<ClusterExposedServiceV4Response> webHDFS = topology2ClusterExposedServiceV4Responses.stream().filter(service -> "WEBHDFS".equals(service.getKnoxService())).findFirst();
    if (webHDFS.isPresent()) {
        assertEquals("https://10.0.0.1/gateway-path/topology2/webhdfs/v1", webHDFS.get().getServiceUrl());
        assertEquals("WEBHDFS", webHDFS.get().getKnoxService());
        assertEquals("WebHDFS", webHDFS.get().getDisplayName());
        assertEquals("NAMENODE", webHDFS.get().getServiceName());
        assertTrue(webHDFS.get().isOpen());
    }
    Optional<ClusterExposedServiceV4Response> sparkHistoryUI = topology2ClusterExposedServiceV4Responses.stream().filter(service -> "SPARKHISTORYUI".equals(service.getKnoxService())).findFirst();
    if (sparkHistoryUI.isPresent()) {
        assertEquals("https://10.0.0.1/gateway-path/topology2/sparkhistory/", sparkHistoryUI.get().getServiceUrl());
        assertEquals("SPARKHISTORYUI", sparkHistoryUI.get().getKnoxService());
        assertEquals("Spark 1.x History Server", sparkHistoryUI.get().getDisplayName());
        assertEquals("SPARK_YARN_HISTORY_SERVER", sparkHistoryUI.get().getServiceName());
        assertFalse(sparkHistoryUI.get().isOpen());
    }
    Optional<ClusterExposedServiceV4Response> hiveServer = topology2ClusterExposedServiceV4Responses.stream().filter(service -> "HIVE".equals(service.getKnoxService())).findFirst();
    if (hiveServer.isPresent()) {
        assertEquals("jdbc:hive2://10.0.0.1/;ssl=true;sslTrustStore=/cert/gateway.jks;trustStorePassword=${GATEWAY_JKS_PASSWORD};" + "transportMode=http;httpPath=gateway-path/topology2/hive", hiveServer.get().getServiceUrl());
        assertEquals("HIVE", hiveServer.get().getKnoxService());
        assertEquals("Hive Server", hiveServer.get().getDisplayName());
        assertEquals("HIVE_SERVER", hiveServer.get().getServiceName());
        assertTrue(hiveServer.get().isOpen());
    }
}
Also used : Arrays(java.util.Arrays) EntitlementService(com.sequenceiq.cloudbreak.auth.altus.EntitlementService) ClusterExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) GatewayTopologyV4RequestToExposedServicesConverter(com.sequenceiq.cloudbreak.converter.v4.stacks.cluster.gateway.topology.GatewayTopologyV4RequestToExposedServicesConverter) CmTemplateProcessorFactory(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessorFactory) Orchestrator(com.sequenceiq.cloudbreak.domain.Orchestrator) ValidationResult(com.sequenceiq.cloudbreak.validation.ValidationResult) Map(java.util.Map) Gateway(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.Gateway) ExposedServiceCollector(com.sequenceiq.cloudbreak.api.service.ExposedServiceCollector) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) ExposedServiceListValidator(com.sequenceiq.cloudbreak.controller.validation.stack.cluster.gateway.ExposedServiceListValidator) Collection(java.util.Collection) Set(java.util.Set) ExposedService(com.sequenceiq.cloudbreak.api.service.ExposedService) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) GatewayType(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.GatewayType) StackServiceComponentDescriptors(com.sequenceiq.cloudbreak.cmtemplate.validation.StackServiceComponentDescriptors) Assert.assertFalse(org.junit.Assert.assertFalse) Tenant(com.sequenceiq.cloudbreak.workspace.model.Tenant) Optional(java.util.Optional) ExposedServices(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.ExposedServices) CmTemplateProcessor(com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) GatewayTopologyV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) ExposedServiceUtil.exposedService(com.sequenceiq.cloudbreak.controller.validation.stack.cluster.gateway.ExposedServiceUtil.exposedService) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.ExposedServiceV4Response) FileReaderUtils(com.sequenceiq.cloudbreak.util.FileReaderUtils) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) Collections.emptyMap(java.util.Collections.emptyMap) Assert.assertTrue(org.junit.Assert.assertTrue) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Maps(com.google.common.collect.Maps) Workspace(com.sequenceiq.cloudbreak.workspace.model.Workspace) GatewayTopology(com.sequenceiq.cloudbreak.domain.stack.cluster.gateway.GatewayTopology) BlueprintService(com.sequenceiq.cloudbreak.service.blueprint.BlueprintService) ComponentLocatorService(com.sequenceiq.cloudbreak.service.blueprint.ComponentLocatorService) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Collection(java.util.Collection) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) ClusterExposedServiceV4Response(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response) Test(org.junit.Test)

Aggregations

ClusterExposedServiceV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.response.cluster.gateway.topology.ClusterExposedServiceV4Response)11 Collection (java.util.Collection)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ExposedService (com.sequenceiq.cloudbreak.api.service.ExposedService)4 Json (com.sequenceiq.cloudbreak.common.json.Json)4 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)4 IOException (java.io.IOException)4 Collectors (java.util.stream.Collectors)4 Test (org.junit.Test)4 Lists (com.google.common.collect.Lists)3 Maps (com.google.common.collect.Maps)3 GatewayType (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.GatewayType)3 GatewayTopologyV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.gateway.topology.GatewayTopologyV4Request)3 ExposedServiceCollector (com.sequenceiq.cloudbreak.api.service.ExposedServiceCollector)3 EntitlementService (com.sequenceiq.cloudbreak.auth.altus.EntitlementService)3 CmTemplateProcessor (com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessor)3 CmTemplateProcessorFactory (com.sequenceiq.cloudbreak.cmtemplate.CmTemplateProcessorFactory)3 StackServiceComponentDescriptors (com.sequenceiq.cloudbreak.cmtemplate.validation.StackServiceComponentDescriptors)3