Search in sources :

Example 1 with ComponentUISpecification

use of com.hortonworks.streamline.common.ComponentUISpecification in project streamline by hortonworks.

the class CustomProcessorInfo method fromTopologyComponentBundle.

public static CustomProcessorInfo fromTopologyComponentBundle(TopologyComponentBundle topologyComponentBundle) throws IOException {
    Preconditions.checkNotNull(topologyComponentBundle, "topologyComponentBundle can not bre null");
    ComponentUISpecification topologyComponentUISpecification = topologyComponentBundle.getTopologyComponentUISpecification();
    List<ComponentUISpecification.UIField> uiFields = topologyComponentUISpecification.getFields();
    Map<String, String> config = getPropertiesFromUIFields(uiFields);
    return new CustomProcessorInfo(config.get(NAME), config.get(DESCRIPTION), topologyComponentBundle.getStreamingEngine(), config.get(JAR_FILE_NAME), config.get(CUSTOM_PROCESSOR_IMPL), Utils.getSchemaFromConfig(config.get(INPUT_SCHEMA)), Utils.getSchemaFromConfig(config.get(OUTPUT_SCHEMA)), getCustomProcessorUISpecification(topologyComponentUISpecification), config.get(DIGEST));
}
Also used : ComponentUISpecification(com.hortonworks.streamline.common.ComponentUISpecification)

Example 2 with ComponentUISpecification

use of com.hortonworks.streamline.common.ComponentUISpecification 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);
    }
}
Also used : Produces(javax.ws.rs.Produces) BadRequestException(com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException) QueryParam(com.hortonworks.registries.common.QueryParam) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) SecurityContext(javax.ws.rs.core.SecurityContext) ComponentUISpecification(com.hortonworks.streamline.common.ComponentUISpecification) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) WSUtils(com.hortonworks.streamline.common.util.WSUtils) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) READ(com.hortonworks.streamline.streams.security.Permission.READ) StreamlineAuthorizer(com.hortonworks.streamline.streams.security.StreamlineAuthorizer) DELETE(javax.ws.rs.DELETE) Config(com.hortonworks.streamline.common.Config) SecurityUtil(com.hortonworks.streamline.streams.security.SecurityUtil) Context(javax.ws.rs.core.Context) ServiceWithComponents(com.hortonworks.streamline.streams.cluster.model.ServiceWithComponents) OK(javax.ws.rs.core.Response.Status.OK) Collection(java.util.Collection) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) CREATED(javax.ws.rs.core.Response.Status.CREATED) PathParam(javax.ws.rs.PathParam) EntityNotFoundException(com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException) GET(javax.ws.rs.GET) ServiceBundle(com.hortonworks.streamline.streams.cluster.catalog.ServiceBundle) FormDataMultiPart(org.glassfish.jersey.media.multipart.FormDataMultiPart) ArrayList(java.util.ArrayList) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) ServiceConfiguration(com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration) WRITE(com.hortonworks.streamline.streams.security.Permission.WRITE) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) EntityAlreadyExistsException(com.hortonworks.streamline.common.exception.service.exception.request.EntityAlreadyExistsException) Component(com.hortonworks.streamline.streams.cluster.catalog.Component) ManualServiceRegistrar(com.hortonworks.streamline.streams.cluster.register.ManualServiceRegistrar) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Collectors.toList(java.util.stream.Collectors.toList) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) InputStream(java.io.InputStream) Config(com.hortonworks.streamline.common.Config) InputStream(java.io.InputStream) Cluster(com.hortonworks.streamline.streams.cluster.catalog.Cluster) Service(com.hortonworks.streamline.streams.cluster.catalog.Service) EnvironmentService(com.hortonworks.streamline.streams.cluster.service.EnvironmentService) IOException(java.io.IOException) ManualServiceRegistrar(com.hortonworks.streamline.streams.cluster.register.ManualServiceRegistrar) ServiceBundle(com.hortonworks.streamline.streams.cluster.catalog.ServiceBundle) FormDataBodyPart(org.glassfish.jersey.media.multipart.FormDataBodyPart) List(java.util.List) ArrayList(java.util.ArrayList) Collectors.toList(java.util.stream.Collectors.toList) ComponentUISpecification(com.hortonworks.streamline.common.ComponentUISpecification) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with ComponentUISpecification

use of com.hortonworks.streamline.common.ComponentUISpecification in project streamline by hortonworks.

the class CustomProcessorInfo method getCustomProcessorUISpecification.

private static ComponentUISpecification getCustomProcessorUISpecification(ComponentUISpecification componentUISpecification) {
    ComponentUISpecification result = new ComponentUISpecification();
    List<ComponentUISpecification.UIField> fields = new ArrayList<>();
    for (ComponentUISpecification.UIField uiField : componentUISpecification.getFields()) {
        if (uiField.getFieldName().startsWith(TopologyLayoutConstants.JSON_KEY_CUSTOM_PROCESSOR_PREFIX)) {
            ComponentUISpecification.UIField newUIField = new ComponentUISpecification.UIField(uiField);
            newUIField.setFieldName(uiField.getFieldName().replaceFirst(TopologyLayoutConstants.JSON_KEY_CUSTOM_PROCESSOR_PREFIX_REGEX, ""));
            fields.add(newUIField);
        }
    }
    result.setFields(fields);
    return (result.getFields().isEmpty() ? null : result);
}
Also used : ComponentUISpecification(com.hortonworks.streamline.common.ComponentUISpecification)

Example 4 with ComponentUISpecification

use of com.hortonworks.streamline.common.ComponentUISpecification in project streamline by hortonworks.

the class CustomProcessorInfo method toTopologyComponentBundle.

public TopologyComponentBundle toTopologyComponentBundle() throws IOException {
    TopologyComponentBundle result = new TopologyComponentBundle();
    result.setTimestamp(System.currentTimeMillis());
    result.setType(TopologyComponentBundle.TopologyComponentType.PROCESSOR);
    result.setSubType(TopologyLayoutConstants.JSON_KEY_CUSTOM_PROCESSOR_SUB_TYPE);
    result.setStreamingEngine(this.streamingEngine);
    if (TopologyLayoutConstants.STORM_STREAMING_ENGINE.equals(this.streamingEngine)) {
        result.setName("customProcessorBoltComponent");
    }
    result.setBuiltin(true);
    result.setTransformationClass("com.hortonworks.streamline.streams.layout.storm.CustomProcessorBoltFluxComponent");
    List<ComponentUISpecification.UIField> uiFields = new ArrayList<>();
    uiFields.addAll(getCustomProcessorUIFieldsWithPrefix());
    uiFields.add(this.createUIField(TopologyLayoutConstants.JSON_KEY_PARALLELISM, TopologyLayoutConstants.JSON_KEY_PARALLELISM, true, true, TopologyLayoutConstants.JSON_KEY_PARALLELISM_TOOLTIP, ComponentUISpecification.UIFieldType.NUMBER.NUMBER, 1));
    uiFields.add(this.createUIField(NAME, NAME, false, false, "Custom processor name", ComponentUISpecification.UIFieldType.STRING, this.name));
    uiFields.add(this.createUIField(DESCRIPTION, DESCRIPTION, false, false, "Custom processor description", ComponentUISpecification.UIFieldType.STRING, this.description));
    uiFields.add(this.createUIField(JAR_FILE_NAME, JAR_FILE_NAME, false, false, "Custom processor jar file", ComponentUISpecification.UIFieldType.STRING, this.jarFileName));
    uiFields.add(this.createUIField(CUSTOM_PROCESSOR_IMPL, CUSTOM_PROCESSOR_IMPL, false, false, "Custom processor interface implementation class", ComponentUISpecification.UIFieldType.STRING, this.customProcessorImpl));
    ObjectMapper objectMapper = new ObjectMapper();
    uiFields.add(this.createUIField(INPUT_SCHEMA, INPUT_SCHEMA, true, false, "Custom processor input schema", ComponentUISpecification.UIFieldType.STRING, objectMapper.writeValueAsString(this.inputSchema)));
    uiFields.add(this.createUIField(OUTPUT_SCHEMA, OUTPUT_SCHEMA, true, false, "Custom processor output schema", ComponentUISpecification.UIFieldType.STRING, objectMapper.writeValueAsString(this.outputSchema)));
    uiFields.add(this.createUIField(DIGEST, DIGEST, false, false, "MD5 digest of the jar file for this CP implementation", ComponentUISpecification.UIFieldType.STRING, this.digest));
    ComponentUISpecification componentUISpecification = new ComponentUISpecification();
    componentUISpecification.setFields(uiFields);
    result.setTopologyComponentUISpecification(componentUISpecification);
    return result;
}
Also used : ComponentUISpecification(com.hortonworks.streamline.common.ComponentUISpecification) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)

Aggregations

ComponentUISpecification (com.hortonworks.streamline.common.ComponentUISpecification)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Timed (com.codahale.metrics.annotation.Timed)1 QueryParam (com.hortonworks.registries.common.QueryParam)1 Config (com.hortonworks.streamline.common.Config)1 BadRequestException (com.hortonworks.streamline.common.exception.service.exception.request.BadRequestException)1 EntityAlreadyExistsException (com.hortonworks.streamline.common.exception.service.exception.request.EntityAlreadyExistsException)1 EntityNotFoundException (com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException)1 WSUtils (com.hortonworks.streamline.common.util.WSUtils)1 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)1 Cluster (com.hortonworks.streamline.streams.cluster.catalog.Cluster)1 Component (com.hortonworks.streamline.streams.cluster.catalog.Component)1 Service (com.hortonworks.streamline.streams.cluster.catalog.Service)1 ServiceBundle (com.hortonworks.streamline.streams.cluster.catalog.ServiceBundle)1 ServiceConfiguration (com.hortonworks.streamline.streams.cluster.catalog.ServiceConfiguration)1 ServiceWithComponents (com.hortonworks.streamline.streams.cluster.model.ServiceWithComponents)1 ManualServiceRegistrar (com.hortonworks.streamline.streams.cluster.register.ManualServiceRegistrar)1 EnvironmentService (com.hortonworks.streamline.streams.cluster.service.EnvironmentService)1 READ (com.hortonworks.streamline.streams.security.Permission.READ)1 WRITE (com.hortonworks.streamline.streams.security.Permission.WRITE)1