Search in sources :

Example 6 with EnvironmentService

use of com.hortonworks.streamline.streams.cluster.service.EnvironmentService in project streamline by hortonworks.

the class DruidSinkBundleHintProviderTest method getHintsOnCluster.

@Test
public void getHintsOnCluster() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setName("cluster1");
    Service service = new Service();
    service.setId(1L);
    service.setName(Constants.Druid.SERVICE_NAME);
    Map<String, String> confMap = new HashMap<>();
    confMap.put(Constants.Druid.PROPERTY_KEY_ZK_SERVICE_HOSTS, "svr1:2181,svr2:2181");
    confMap.put(Constants.Druid.PROPERTY_KEY_INDEXING_SERVICE_NAME, "druid/overlord");
    confMap.put(Constants.Druid.PROPERTY_KEY_DISCOVERY_CURATOR_PATH, "/discovery");
    ServiceConfiguration serviceConfiguration = new ServiceConfiguration();
    serviceConfiguration.setId(1L);
    serviceConfiguration.setName(Constants.Druid.CONF_TYPE_COMMON_RUNTIME);
    serviceConfiguration.setConfiguration(objectMapper.writeValueAsString(confMap));
    new Expectations() {

        {
            environmentService.getServiceByName(cluster.getId(), Constants.Druid.SERVICE_NAME);
            result = service;
            environmentService.getServiceConfigurationByName(service.getId(), Constants.Druid.CONF_TYPE_COMMON_RUNTIME);
            result = serviceConfiguration;
        }
    };
    provider.init(environmentService);
    Map<String, Object> hints = provider.getHintsOnCluster(cluster, null, null);
    Assert.assertNotNull(hints);
    Assert.assertEquals("svr1:2181,svr2:2181", hints.get(DruidSinkBundleHintProvider.FIELD_NAME_ZK_CONNECT));
    Assert.assertEquals("druid/overlord", hints.get(DruidSinkBundleHintProvider.FIELD_NAME_INDEX_SERVICE));
    Assert.assertEquals("/discovery", hints.get(DruidSinkBundleHintProvider.FIELD_NAME_DISCOVERY_PATH));
}
Also used : Expectations(mockit.Expectations) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) HashMap(java.util.HashMap) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with EnvironmentService

use of com.hortonworks.streamline.streams.cluster.service.EnvironmentService in project streamline by hortonworks.

the class AbstractServiceRegistrarTest method resetEnvironmentService.

protected void resetEnvironmentService() {
    dao = new InMemoryStorageManager();
    transactionManager = new NOOPTransactionManager();
    environmentService = new EnvironmentService(dao);
}
Also used : InMemoryStorageManager(com.hortonworks.registries.storage.impl.memory.InMemoryStorageManager) NOOPTransactionManager(com.hortonworks.registries.storage.NOOPTransactionManager) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService)

Example 8 with EnvironmentService

use of com.hortonworks.streamline.streams.cluster.service.EnvironmentService in project streamline by hortonworks.

the class ClusterResourceUtil method enrichCluster.

public static ClusterServicesImportResult enrichCluster(Cluster cluster, EnvironmentService environmentService) {
    ClusterServicesImportResult result = new ClusterServicesImportResult(cluster);
    for (Service service : environmentService.listServices(cluster.getId())) {
        Collection<ServiceConfiguration> configurations = environmentService.listServiceConfigurations(service.getId());
        Collection<Component> components = environmentService.listComponents(service.getId());
        ServiceWithComponents s = new ServiceWithComponents(service);
        s.setComponents(components);
        s.setConfigurations(configurations);
        result.addService(s);
    }
    return result;
}
Also used : ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) ServiceWithComponents(com.hortonworks.streamline.streams.cluster.model.ServiceWithComponents)

Example 9 with EnvironmentService

use of com.hortonworks.streamline.streams.cluster.service.EnvironmentService in project streamline by hortonworks.

the class NotificationSinkBundleSourceHintProviderTest method getHintsOnCluster.

@Test
public void getHintsOnCluster() throws Exception {
    ObjectMapper objectMapper = new ObjectMapper();
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setName("cluster1");
    Service service = new Service();
    service.setId(1L);
    service.setName(Constants.Email.SERVICE_NAME);
    Map<String, String> confMap = new HashMap<>();
    confMap.put(Constants.Email.PROPERTY_KEY_HOST, "svr1");
    confMap.put(Constants.Email.PROPERTY_KEY_PORT, "1111");
    confMap.put(Constants.Email.PROPERTY_KEY_SSL, "true");
    confMap.put(Constants.Email.PROPERTY_KEY_STARTTLS, "true");
    confMap.put(Constants.Email.PROPERTY_KEY_PROTOCOL, "smtp");
    confMap.put(Constants.Email.PROPERTY_KEY_AUTH, "true");
    ServiceConfiguration serviceConfiguration = new ServiceConfiguration();
    serviceConfiguration.setId(1L);
    serviceConfiguration.setName(Constants.Email.CONF_TYPE_PROPERTIES);
    serviceConfiguration.setConfiguration(objectMapper.writeValueAsString(confMap));
    new Expectations() {

        {
            environmentService.getServiceByName(cluster.getId(), Constants.Email.SERVICE_NAME);
            result = service;
            environmentService.getServiceConfigurationByName(service.getId(), Constants.Email.CONF_TYPE_PROPERTIES);
            result = serviceConfiguration;
        }
    };
    provider.init(environmentService);
    Map<String, Object> hints = provider.getHintsOnCluster(cluster, null, null);
    Assert.assertNotNull(hints);
    Assert.assertEquals("svr1", hints.get(NotificationSinkBundleHintProvider.FIELD_NAME_HOST));
    Assert.assertEquals("1111", hints.get(NotificationSinkBundleHintProvider.FIELD_NAME_PORT));
    Assert.assertEquals("true", hints.get(NotificationSinkBundleHintProvider.FIELD_NAME_SSL));
    Assert.assertEquals("true", hints.get(NotificationSinkBundleHintProvider.FIELD_NAME_STARTTLS));
    Assert.assertEquals("smtp", hints.get(NotificationSinkBundleHintProvider.FIELD_NAME_PROTOCOL));
    Assert.assertEquals("true", hints.get(NotificationSinkBundleHintProvider.FIELD_NAME_AUTH));
}
Also used : Expectations(mockit.Expectations) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) HashMap(java.util.HashMap) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with EnvironmentService

use of com.hortonworks.streamline.streams.cluster.service.EnvironmentService in project streamline by hortonworks.

the class TopologyActionsContainer method buildStormTopologyActionsConfigMap.

private Map<String, Object> buildStormTopologyActionsConfigMap(Namespace namespace, String streamingEngine, Subject subject) {
    // Assuming that a namespace has one mapping of streaming engine except test environment
    Service streamingEngineService = getFirstOccurenceServiceForNamespace(namespace, streamingEngine);
    if (streamingEngineService == null) {
        if (!namespace.getInternal()) {
            throw new RuntimeException("Streaming Engine " + streamingEngine + " is not associated to the namespace " + namespace.getName() + "(" + namespace.getId() + ")");
        } else {
            // the namespace is purposed for test run
            return buildStormTopologyActionsConfigMapForTestRun(namespace, subject);
        }
    }
    Component uiServer = getComponent(streamingEngineService, COMPONENT_NAME_STORM_UI_SERVER).orElseThrow(() -> new RuntimeException(streamingEngine + " doesn't have " + COMPONENT_NAME_STORM_UI_SERVER + " as component"));
    Collection<ComponentProcess> uiServerProcesses = environmentService.listComponentProcesses(uiServer.getId());
    if (uiServerProcesses.isEmpty()) {
        throw new RuntimeException(streamingEngine + " doesn't have component process " + COMPONENT_NAME_STORM_UI_SERVER);
    }
    ComponentProcess uiServerProcess = uiServerProcesses.iterator().next();
    final String uiHost = uiServerProcess.getHost();
    Integer uiPort = uiServerProcess.getPort();
    assertHostAndPort(uiServer.getName(), uiHost, uiPort);
    Component nimbus = getComponent(streamingEngineService, COMPONENT_NAME_NIMBUS).orElseThrow(() -> new RuntimeException(streamingEngine + " doesn't have " + COMPONENT_NAME_NIMBUS + " as component"));
    Collection<ComponentProcess> nimbusProcesses = environmentService.listComponentProcesses(nimbus.getId());
    if (nimbusProcesses.isEmpty()) {
        throw new RuntimeException(streamingEngine + " doesn't have component process " + COMPONENT_NAME_NIMBUS);
    }
    List<String> nimbusHosts = nimbusProcesses.stream().map(ComponentProcess::getHost).collect(Collectors.toList());
    Integer nimbusPort = nimbusProcesses.stream().map(ComponentProcess::getPort).findAny().get();
    assertHostsAndPort(nimbus.getName(), nimbusHosts, nimbusPort);
    Map<String, Object> conf = new HashMap<>();
    // We need to have some local configurations anyway because topology submission can't be done with REST API.
    String stormJarLocation = streamlineConf.get(STREAMLINE_STORM_JAR);
    if (stormJarLocation == null) {
        String jarFindDir = applyReservedPaths(DEFAULT_STORM_JAR_LOCATION_DIR);
        stormJarLocation = findFirstMatchingJarLocation(jarFindDir);
    } else {
        stormJarLocation = applyReservedPaths(stormJarLocation);
    }
    conf.put(STREAMLINE_STORM_JAR, stormJarLocation);
    conf.put(STORM_HOME_DIR, streamlineConf.get(STORM_HOME_DIR));
    // Since we're loading the class dynamically so we can't rely on any enums or constants from there
    conf.put(NIMBUS_SEEDS, String.join(",", nimbusHosts));
    conf.put(NIMBUS_PORT, String.valueOf(nimbusPort));
    conf.put(TopologyLayoutConstants.STORM_API_ROOT_URL_KEY, buildStormRestApiRootUrl(uiHost, uiPort));
    conf.put(TopologyLayoutConstants.SUBJECT_OBJECT, subject);
    putStormConfigurations(streamingEngineService, conf);
    // Topology during run-time will require few critical configs such as schemaRegistryUrl and catalogRootUrl
    // Hence its important to pass StreamlineConfig to TopologyConfig
    conf.putAll(streamlineConf);
    // TopologyActionImpl needs 'EnvironmentService' and namespace ID to load service configurations
    // for specific cluster associated to the namespace
    conf.put(TopologyLayoutConstants.ENVIRONMENT_SERVICE_OBJECT, environmentService);
    conf.put(TopologyLayoutConstants.NAMESPACE_ID, namespace.getId());
    return conf;
}
Also used : HashMap(java.util.HashMap) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) ComponentProcess(com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess)

Aggregations

EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)10 Service (com.hortonworks.streamline.streams.cluster.catalog.Service)5 ServiceConfiguration (com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration)4 ArrayList (java.util.ArrayList)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 TopologyActionsService (com.hortonworks.streamline.streams.actions.topology.service.TopologyActionsService)3 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)3 Cluster (com.hortonworks.streamline.streams.cluster.catalog.Cluster)3 StreamlineAuthorizer (com.hortonworks.streamline.streams.security.StreamlineAuthorizer)3 IOException (java.io.IOException)3 Collection (java.util.Collection)3 List (java.util.List)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Timed (com.codahale.metrics.annotation.Timed)2 QueryParam (com.hortonworks.registries.common.QueryParam)2 BadRequestException (com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException)2 EntityNotFoundException (com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException)2 WSUtils (com.hortonworks.streamline.common.util.WSUtils)2 Topology (com.hortonworks.streamline.streams.catalog.Topology)2