use of com.hortonworks.streamline.common.Config in project streamline by hortonworks.
the class StormTopologyTimeSeriesMetricsImplTest method getSourceLayoutForTest.
private Component getSourceLayoutForTest() {
StreamlineSource source = new StreamlineSource() {
@Override
public void accept(TopologyDagVisitor visitor) {
}
};
source.setId("11");
source.setName("device");
Map<String, String> configurations = buildSourceConfigWithKafkaTopic(TOPIC_NAME);
source.setConfig(new Config(configurations));
return source;
}
use of com.hortonworks.streamline.common.Config in project streamline by hortonworks.
the class ServiceCatalogResource method registerService.
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/clusters/{clusterId}/services/register/{serviceName}")
@Timed
public Response registerService(@PathParam("clusterId") Long clusterId, @PathParam("serviceName") String serviceName, FormDataMultiPart form) {
ServiceBundle serviceBundle = environmentService.getServiceBundleByName(serviceName);
if (serviceBundle == null) {
throw BadRequestException.message("Not supported service: " + serviceName);
}
ManualServiceRegistrar registrar;
try {
Class<?> clazz = Class.forName(serviceBundle.getRegisterClass());
registrar = (ManualServiceRegistrar) clazz.newInstance();
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
throw new RuntimeException(e);
}
Cluster cluster = environmentService.getCluster(clusterId);
if (cluster == null) {
throw EntityNotFoundException.byId("Cluster " + clusterId);
}
Service service = environmentService.getServiceByName(clusterId, serviceName);
if (service != null) {
throw EntityAlreadyExistsException.byName("Service " + serviceName + " is already exist in Cluster " + clusterId);
}
registrar.init(environmentService);
ComponentUISpecification specification = serviceBundle.getServiceUISpecification();
List<String> fileFieldNames = specification.getFields().stream().filter(uiField -> uiField.getType().equals(ComponentUISpecification.UIFieldType.FILE)).map(uiField -> uiField.getFieldName()).collect(toList());
Map<String, List<FormDataBodyPart>> fields = form.getFields();
List<FormDataBodyPart> cfgFormList = fields.getOrDefault("config", Collections.emptyList());
Config config;
if (!cfgFormList.isEmpty()) {
String jsonConfig = cfgFormList.get(0).getEntityAs(String.class);
try {
config = objectMapper.readValue(jsonConfig, Config.class);
} catch (IOException e) {
throw BadRequestException.message("config is missing");
}
} else {
config = new Config();
}
List<ManualServiceRegistrar.ConfigFileInfo> configFileInfos = fields.entrySet().stream().filter(entry -> fileFieldNames.contains(entry.getKey())).flatMap(entry -> {
String key = entry.getKey();
List<FormDataBodyPart> values = entry.getValue();
return values.stream().map(val -> new ManualServiceRegistrar.ConfigFileInfo(key, val.getEntityAs(InputStream.class)));
}).collect(toList());
try {
Service registeredService = registrar.register(cluster, config, configFileInfos);
return WSUtils.respondEntity(buildManualServiceRegisterResult(registeredService), CREATED);
} catch (IllegalArgumentException e) {
throw BadRequestException.message(e.getMessage());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of com.hortonworks.streamline.common.Config in project streamline by hortonworks.
the class ZookeeperServiceRegistrar method createZookeeperServerComponent.
private Pair<Component, List<ComponentProcess>> createZookeeperServerComponent(Config config, Map<String, String> flattenConfigMap) {
if (!config.contains(PARAM_ZOOKEEPER_SERVER_HOSTNAMES)) {
throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_SERVER_HOSTNAMES + " not present.");
}
if (!config.contains(PARAM_ZOOKEEPER_PORT)) {
throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_PORT + " not present.");
}
List<String> zookeeperServerHosts;
try {
zookeeperServerHosts = config.getAny(PARAM_ZOOKEEPER_SERVER_HOSTNAMES);
} catch (ClassCastException e) {
throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_SERVER_HOSTNAMES + " should be list of string.");
}
Number zookeeperPort;
try {
zookeeperPort = config.getAny(PARAM_ZOOKEEPER_PORT);
} catch (ClassCastException e) {
throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_PORT + " should be number.");
}
Component zookeeperServer = new Component();
zookeeperServer.setName(COMPONENT_ZOOKEEPER_SERVER);
List<ComponentProcess> componentProcesses = zookeeperServerHosts.stream().map(host -> {
ComponentProcess cp = new ComponentProcess();
cp.setHost(host);
cp.setPort(zookeeperPort.intValue());
return cp;
}).collect(toList());
return new Pair<>(zookeeperServer, componentProcesses);
}
use of com.hortonworks.streamline.common.Config in project streamline by hortonworks.
the class DruidServiceRegistrarTest method testRegister.
@Test
public void testRegister() throws Exception {
Cluster cluster = getTestCluster(1L);
DruidServiceRegistrar registerer = initializeServiceRegistrar();
Config config = new Config();
config.put(DruidServiceRegistrar.PARAM_ZOOKEEPER_CONNECTION_STRING, "zookeeper-1:2181,zookeeper-2:2181,zookeeper-3:2181");
config.put(DruidServiceRegistrar.PARAM_INDEXING_SERVICE_NAME, "druid/overlord");
config.put(DruidServiceRegistrar.PARAM_DISCOVERY_CURATOR_PATH, "/prod/discovery");
registerer.register(cluster, config, Collections.emptyList());
Service druidService = environmentService.getServiceByName(cluster.getId(), Constants.Druid.SERVICE_NAME);
assertNotNull(druidService);
ServiceConfiguration commonRuntimePropertiesConf = environmentService.getServiceConfigurationByName(druidService.getId(), CONFIGURATION_NAME_COMMON_RUNTIME_PROPERTIES);
assertNotNull(commonRuntimePropertiesConf);
Map<String, String> confMap = commonRuntimePropertiesConf.getConfigurationMap();
assertEquals(config.get(DruidServiceRegistrar.PARAM_ZOOKEEPER_CONNECTION_STRING), confMap.get(DruidServiceRegistrar.PARAM_ZOOKEEPER_CONNECTION_STRING));
assertEquals(config.get(DruidServiceRegistrar.PARAM_INDEXING_SERVICE_NAME), confMap.get(DruidServiceRegistrar.PARAM_INDEXING_SERVICE_NAME));
assertEquals(config.get(DruidServiceRegistrar.PARAM_DISCOVERY_CURATOR_PATH), confMap.get(DruidServiceRegistrar.PARAM_DISCOVERY_CURATOR_PATH));
}
use of com.hortonworks.streamline.common.Config in project streamline by hortonworks.
the class DruidServiceRegistrarTest method testRegisterWithoutOptionalParams.
@Test
public void testRegisterWithoutOptionalParams() throws Exception {
Cluster cluster = getTestCluster(1L);
DruidServiceRegistrar registerer = initializeServiceRegistrar();
Config config = new Config();
config.put(DruidServiceRegistrar.PARAM_ZOOKEEPER_CONNECTION_STRING, "zookeeper-1:2181,zookeeper-2:2181,zookeeper-3:2181");
registerer.register(cluster, config, Collections.emptyList());
Service druidService = environmentService.getServiceByName(cluster.getId(), Constants.Druid.SERVICE_NAME);
assertNotNull(druidService);
ServiceConfiguration commonRuntimePropertiesConf = environmentService.getServiceConfigurationByName(druidService.getId(), CONFIGURATION_NAME_COMMON_RUNTIME_PROPERTIES);
assertNotNull(commonRuntimePropertiesConf);
Map<String, String> confMap = commonRuntimePropertiesConf.getConfigurationMap();
assertEquals(config.get(DruidServiceRegistrar.PARAM_ZOOKEEPER_CONNECTION_STRING), confMap.get(DruidServiceRegistrar.PARAM_ZOOKEEPER_CONNECTION_STRING));
}
Aggregations