Search in sources :

Example 1 with ServiceNotFoundException

use of com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException in project streamline by hortonworks.

the class NotificationSinkBundleHintProvider method getHintsOnCluster.

@Override
public Map<String, Object> getHintsOnCluster(Cluster cluster, SecurityContext securityContext, Subject subject) {
    Map<String, Object> hintMap = new HashMap<>();
    try {
        Service email = environmentService.getServiceByName(cluster.getId(), Constants.Email.SERVICE_NAME);
        if (email == null) {
            throw new ServiceNotFoundException(Constants.Email.SERVICE_NAME);
        }
        ServiceConfiguration properties = environmentService.getServiceConfigurationByName(email.getId(), Constants.Email.CONF_TYPE_PROPERTIES);
        if (properties == null) {
            throw new ServiceConfigurationNotFoundException(Constants.Email.CONF_TYPE_PROPERTIES);
        }
        Map<String, String> configurationMap = properties.getConfigurationMap();
        putToHintMapIfAvailable(configurationMap, hintMap, Constants.Email.PROPERTY_KEY_HOST, FIELD_NAME_HOST);
        putToHintMapIfAvailable(configurationMap, hintMap, Constants.Email.PROPERTY_KEY_PORT, FIELD_NAME_PORT);
        putToHintMapIfAvailable(configurationMap, hintMap, Constants.Email.PROPERTY_KEY_SSL, FIELD_NAME_SSL);
        putToHintMapIfAvailable(configurationMap, hintMap, Constants.Email.PROPERTY_KEY_STARTTLS, FIELD_NAME_STARTTLS);
        putToHintMapIfAvailable(configurationMap, hintMap, Constants.Email.PROPERTY_KEY_PROTOCOL, FIELD_NAME_PROTOCOL);
        putToHintMapIfAvailable(configurationMap, hintMap, Constants.Email.PROPERTY_KEY_AUTH, FIELD_NAME_AUTH);
    } catch (ServiceNotFoundException e) {
        // we access it from mapping information so shouldn't be here
        throw new IllegalStateException("Service " + Constants.Email.SERVICE_NAME + " in cluster " + cluster.getName() + " not found but mapping information exists.");
    } catch (ServiceConfigurationNotFoundException e) {
    // there's Email service configuration but not having enough information
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return hintMap;
}
Also used : ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) HashMap(java.util.HashMap) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) ServiceConfigurationNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException) ServiceConfigurationNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException)

Example 2 with ServiceNotFoundException

use of com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException in project streamline by hortonworks.

the class AbstractKafkaBundleHintProviderTest method getHintsOnClusterWithZkServiceNotAvailable.

protected void getHintsOnClusterWithZkServiceNotAvailable() throws Exception {
    final List<String> topics = Lists.newArrayList("test1", "test2", "test3");
    new Expectations() {

        {
            kafkaMetadataService.getTopicsFromZk();
            result = new KafkaTopics(topics, security);
            zookeeperMetadataService.getZookeeperServers();
            result = new ServiceNotFoundException(1L, ServiceConfigurations.ZOOKEEPER.name());
        }
    };
    Cluster cluster = new Cluster();
    cluster.setId(1L);
    cluster.setName("cluster1");
    Map<String, Object> hints = provider.getHintsOnCluster(cluster, null, null);
    Assert.assertNotNull(hints);
    Assert.assertEquals(4, hints.size());
    Assert.assertEquals(topics, hints.get(KafkaBundleHintProvider.FIELD_NAME_TOPIC));
    new Verifications() {

        {
            kafkaMetadataService.getTopicsFromZk();
            zookeeperMetadataService.getZookeeperServers();
        }
    };
}
Also used : Expectations(mockit.Expectations) KafkaTopics(com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Verifications(mockit.Verifications)

Example 3 with ServiceNotFoundException

use of com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException in project streamline by hortonworks.

the class ZookeeperMetadataService method getZookeeperServers.

public List<HostPort> getZookeeperServers() throws ServiceNotFoundException, ServiceComponentNotFoundException {
    final Long serviceId = environmentService.getServiceIdByName(clusterId, STREAMS_JSON_SCHEMA_SERVICE_ZOOKEEPER);
    if (serviceId == null) {
        throw new ServiceNotFoundException(clusterId, ServiceConfigurations.ZOOKEEPER.name());
    }
    final Component zookeeperServer = environmentService.getComponentByName(serviceId, STREAMS_JSON_SCHEMA_COMPONENT_ZOOKEEPER_SERVER);
    if (zookeeperServer == null) {
        throw new ServiceComponentNotFoundException(clusterId, ServiceConfigurations.STORM.name(), ComponentPropertyPattern.ZOOKEEPER_SERVER.name());
    }
    final Collection<ComponentProcess> zookeeperServers = environmentService.listComponentProcesses(zookeeperServer.getId());
    return zookeeperServers.stream().map(cp -> new HostPort(cp.getHost(), cp.getPort())).collect(Collectors.toList());
}
Also used : ServiceComponentNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceComponentNotFoundException) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) ComponentPropertyPattern(com.hortonworks.streamline.streams.cluster.discovery.ambari.ComponentPropertyPattern) List(java.util.List) ServiceConfigurations(com.hortonworks.streamline.streams.cluster.discovery.ambari.ServiceConfigurations) Collection(java.util.Collection) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) HostPort(com.hortonworks.streamline.streams.cluster.service.metadata.common.HostPort) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) ComponentProcess(com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess) Collectors(java.util.stream.Collectors) ServiceComponentNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceComponentNotFoundException) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) HostPort(com.hortonworks.streamline.streams.cluster.service.metadata.common.HostPort) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) ComponentProcess(com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess)

Example 4 with ServiceNotFoundException

use of com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException in project streamline by hortonworks.

the class AbstractKafkaBundleHintProvider method getHintsOnCluster.

@Override
public Map<String, Object> getHintsOnCluster(Cluster cluster, SecurityContext securityContext, Subject subject) {
    Map<String, Object> hintClusterMap = new HashMap<>();
    try (KafkaMetadataService kms = KafkaMetadataService.newInstance(environmentService, cluster.getId(), securityContext)) {
        KafkaTopics topics = kms.getTopicsFromZk();
        hintClusterMap.put(FIELD_NAME_TOPIC, topics.list());
        fillZookeeperHints(cluster, hintClusterMap);
        final Map<KafkaBrokerListeners.Protocol, List<String>> protocolToHostsWithPort = kms.getKafkaBrokerListeners().getProtocolToHostsWithPort();
        hintClusterMap.put(FIELD_NAME_BOOTSTRAP_SERVERS, mapValuesJoiner(protocolToHostsWithPort, ","));
        hintClusterMap.put(FIELD_NAME_SECURITY_PROTOCOL, protocolToHostsWithPort.keySet());
        hintClusterMap.put(FIELD_NAME_KAFKA_SERVICE_NAME, kms.getKafkaServiceName());
    } catch (ServiceNotFoundException e) {
        // we access it from mapping information so shouldn't be here
        throw new IllegalStateException("Service " + Constants.Kafka.SERVICE_NAME + " in cluster " + cluster.getName() + " not found but mapping information exists.");
    } catch (ServiceConfigurationNotFoundException e) {
    // there's KAFKA service but not enough configuration info.
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return hintClusterMap;
}
Also used : HashMap(java.util.HashMap) KafkaMetadataService(com.hortonworks.streamline.streams.cluster.service.metadata.KafkaMetadataService) ServiceComponentNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceComponentNotFoundException) ServiceConfigurationNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) KafkaTopics(com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) ServiceConfigurationNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 5 with ServiceNotFoundException

use of com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException in project streamline by hortonworks.

the class AbstractHDFSBundleHintProvider method getHintsOnCluster.

@Override
public Map<String, Object> getHintsOnCluster(Cluster cluster, SecurityContext securityContext, Subject subject) {
    Map<String, Object> hintMap = new HashMap<>();
    try {
        HDFSMetadataService hdfsMetadataService = HDFSMetadataService.newInstance(environmentService, cluster.getId());
        hintMap.put(getFieldNameForFSUrl(), hdfsMetadataService.getDefaultFsUrl());
    } catch (ServiceNotFoundException e) {
        // we access it from mapping information so shouldn't be here
        throw new IllegalStateException("Service " + Constants.HDFS.SERVICE_NAME + " in cluster " + cluster.getName() + " not found but mapping information exists.");
    } catch (ServiceConfigurationNotFoundException e) {
    // there's HBASE service but not enough configuration info.
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return hintMap;
}
Also used : HashMap(java.util.HashMap) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException) ServiceConfigurationNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException) HDFSMetadataService(com.hortonworks.streamline.streams.cluster.service.metadata.HDFSMetadataService) ServiceConfigurationNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException) ServiceNotFoundException(com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException)

Aggregations

ServiceNotFoundException (com.hortonworks.streamline.streams.cluster.exception.ServiceNotFoundException)6 ServiceConfigurationNotFoundException (com.hortonworks.streamline.streams.cluster.exception.ServiceConfigurationNotFoundException)4 HashMap (java.util.HashMap)4 Service (com.hortonworks.streamline.streams.cluster.catalog.Service)2 ServiceConfiguration (com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration)2 ServiceComponentNotFoundException (com.hortonworks.streamline.streams.cluster.exception.ServiceComponentNotFoundException)2 KafkaTopics (com.hortonworks.streamline.streams.cluster.service.metadata.json.KafkaTopics)2 List (java.util.List)2 Cluster (com.hortonworks.streamline.streams.cluster.catalog.Cluster)1 Component (com.hortonworks.streamline.streams.cluster.catalog.Component)1 ComponentProcess (com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess)1 ComponentPropertyPattern (com.hortonworks.streamline.streams.cluster.discovery.ambari.ComponentPropertyPattern)1 ServiceConfigurations (com.hortonworks.streamline.streams.cluster.discovery.ambari.ServiceConfigurations)1 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)1 HDFSMetadataService (com.hortonworks.streamline.streams.cluster.service.metadata.HDFSMetadataService)1 KafkaMetadataService (com.hortonworks.streamline.streams.cluster.service.metadata.KafkaMetadataService)1 HostPort (com.hortonworks.streamline.streams.cluster.service.metadata.common.HostPort)1 Collection (java.util.Collection)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1