Search in sources :

Example 1 with Service

use of com.hortonworks.streamline.streams.cluster.catalog.Service in project streamline by hortonworks.

the class NamespaceAwareContainer method buildStormRestApiRootUrl.

protected String buildStormRestApiRootUrl(Namespace namespace, String streamingEngine) {
    // Assuming that a namespace has one mapping of streaming engine
    Service streamingEngineService = getFirstOccurenceServiceForNamespace(namespace, streamingEngine);
    if (streamingEngineService == null) {
        throw new RuntimeException("Streaming Engine " + streamingEngine + " is not associated to the namespace " + namespace.getName() + "(" + namespace.getId() + ")");
    }
    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 any process for " + COMPONENT_NAME_STORM_UI_SERVER + " as component");
    }
    ComponentProcess uiServerProcess = uiServerProcesses.iterator().next();
    String uiHost = uiServerProcess.getHost();
    Integer uiPort = uiServerProcess.getPort();
    assertHostAndPort(uiServer.getName(), uiHost, uiPort);
    return "http://" + uiHost + ":" + uiPort + "/api/v1";
}
Also used : 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)

Example 2 with Service

use of com.hortonworks.streamline.streams.cluster.catalog.Service in project streamline by hortonworks.

the class NamespaceAwareContainer method getServiceForNamespace.

protected Collection<Service> getServiceForNamespace(Namespace namespace, String serviceName) {
    Collection<NamespaceServiceClusterMap> serviceClusterMappings = environmentService.listServiceClusterMapping(namespace.getId(), serviceName);
    if (serviceClusterMappings == null) {
        throw new RuntimeException("Service name " + serviceName + " is not set in namespace " + namespace.getName() + "(" + namespace.getId() + ")");
    }
    Collection<Service> services = new ArrayList<>(serviceClusterMappings.size());
    for (NamespaceServiceClusterMap mapping : serviceClusterMappings) {
        Long clusterId = mapping.getClusterId();
        Cluster cluster = environmentService.getCluster(clusterId);
        if (cluster == null) {
            throw new RuntimeException("Cluster " + clusterId + " is not found");
        }
        Service service = environmentService.getServiceByName(clusterId, serviceName);
        if (service == null) {
            throw new RuntimeException("Service name " + serviceName + " is not found in Cluster " + clusterId);
        }
        services.add(service);
    }
    return services;
}
Also used : ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) NamespaceServiceClusterMap(com.hortonworks.streamline.streams.cluster.catalog.NamespaceServiceClusterMap)

Example 3 with Service

use of com.hortonworks.streamline.streams.cluster.catalog.Service in project streamline by hortonworks.

the class AbstractServiceRegistrar method register.

@Override
public Service register(Cluster cluster, Config config, List<ConfigFileInfo> configFileInfos) throws IOException {
    Service service = environmentService.createService(cluster, getServiceName());
    List<ServiceConfiguration> configurations = new ArrayList<>();
    Map<String, String> flattenConfigMap = new HashMap<>();
    List<ServiceConfiguration> serviceConfigurations = createServiceConfigurations(config);
    if (serviceConfigurations != null && !serviceConfigurations.isEmpty()) {
        serviceConfigurations.forEach(sc -> {
            configurations.add(sc);
            try {
                flattenConfigMap.putAll(sc.getConfigurationMap());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        });
    }
    for (ConfigFileInfo configFileInfo : configFileInfos) {
        Map<String, String> configMap = readConfigFile(configFileInfo);
        String fileName = FilenameUtils.getName(configFileInfo.getName());
        String confType = getConfType(fileName);
        String actualFileName = ConfigFilePattern.getOriginFileName(confType);
        ServiceConfiguration configuration = environmentService.createServiceConfiguration(service.getId(), confType, actualFileName, new HashMap<>(configMap));
        configurations.add(configuration);
        flattenConfigMap.putAll(configMap);
    }
    Map<Component, List<ComponentProcess>> components = createComponents(config, flattenConfigMap);
    if (!validateComponents(components)) {
        throw new IllegalArgumentException("Validation failed for components.");
    }
    if (!validateServiceConfigurations(configurations)) {
        throw new IllegalArgumentException("Validation failed for service configurations.");
    }
    if (!validateServiceConfiguationsAsFlattenedMap(flattenConfigMap)) {
        throw new IllegalArgumentException("Validation failed for service configurations.");
    }
    // here we are storing actual catalogs
    // before that we need to replace dummy service id to the actual one
    service = environmentService.addService(service);
    for (Map.Entry<Component, List<ComponentProcess>> entry : components.entrySet()) {
        Component component = entry.getKey();
        List<ComponentProcess> componentProcesses = entry.getValue();
        component.setServiceId(service.getId());
        component = environmentService.addComponent(component);
        for (ComponentProcess componentProcess : componentProcesses) {
            componentProcess.setComponentId(component.getId());
            environmentService.addComponentProcess(componentProcess);
        }
    }
    for (ServiceConfiguration configuration : configurations) {
        configuration.setServiceId(service.getId());
        environmentService.addServiceConfiguration(configuration);
    }
    return service;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) IOException(java.io.IOException) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) HashMap(java.util.HashMap) Map(java.util.Map) ComponentProcess(com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess)

Example 4 with Service

use of com.hortonworks.streamline.streams.cluster.catalog.Service 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 5 with Service

use of com.hortonworks.streamline.streams.cluster.catalog.Service in project streamline by hortonworks.

the class ComponentCatalogResource method addComponent.

@POST
@Path("/services/{serviceId}/components")
@Timed
public Response addComponent(@PathParam("serviceId") Long serviceId, Component component, @Context SecurityContext securityContext) {
    SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, getClusterId(serviceId), WRITE);
    // overwrite service id to given path param
    component.setServiceId(serviceId);
    Service service = environmentService.getService(serviceId);
    if (service == null) {
        throw EntityNotFoundException.byId("service: " + serviceId.toString());
    }
    String componentName = component.getName();
    Component result = environmentService.getComponentByName(serviceId, componentName);
    if (result != null) {
        throw EntityAlreadyExistsException.byName("service id " + serviceId + " and component name " + componentName);
    }
    Component createdComponent = environmentService.addComponent(component);
    return WSUtils.respondEntity(createdComponent, CREATED);
}
Also used : EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Aggregations

Service (com.hortonworks.streamline.streams.cluster.catalog.Service)50 Cluster (com.hortonworks.streamline.streams.cluster.catalog.Cluster)31 Test (org.junit.Test)26 Config (com.hortonworks.streamline.common.Config)25 ServiceConfiguration (com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration)22 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)21 Component (com.hortonworks.streamline.streams.cluster.catalog.Component)14 Timed (com.codahale.metrics.annotation.Timed)9 ManualServiceRegistrar (com.hortonworks.streamline.streams.cluster.register.ManualServiceRegistrar)9 InputStream (java.io.InputStream)9 Path (javax.ws.rs.Path)9 ComponentProcess (com.hortonworks.streamline.streams.cluster.catalog.ComponentProcess)8 HashMap (java.util.HashMap)7 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Map (java.util.Map)4 POST (javax.ws.rs.POST)4 ArrayList (java.util.ArrayList)3 Collection (java.util.Collection)3 DELETE (javax.ws.rs.DELETE)3 PUT (javax.ws.rs.PUT)3