use of com.hortonworks.streamline.streams.cluster.catalog.Component 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";
}
use of com.hortonworks.streamline.streams.cluster.catalog.Component 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;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Component 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);
}
use of com.hortonworks.streamline.streams.cluster.catalog.Component in project streamline by hortonworks.
the class ServiceCatalogResource method buildManualServiceRegisterResult.
private ServiceWithComponents buildManualServiceRegisterResult(Service service) {
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);
return s;
}
use of com.hortonworks.streamline.streams.cluster.catalog.Component in project streamline by hortonworks.
the class EnvironmentService method removeComponent.
public Component removeComponent(Long componentId) {
Component component = new Component();
component.setId(componentId);
return dao.remove(new StorableKey(COMPONENT_NAMESPACE, component.getPrimaryKey()));
}
Aggregations