Search in sources :

Example 1 with ComponentConfigException

use of com.hortonworks.streamline.common.exception.ComponentConfigException in project streamline by hortonworks.

the class NormalizationBoltFluxComponent method validateConfig.

@Override
public void validateConfig() throws ComponentConfigException {
    super.validateConfig();
    String fieldName = TopologyLayoutConstants.JSON_KEY_NORMALIZATION_PROCESSOR_CONFIG;
    Map normalizationProcessorConfig = (Map) conf.get(fieldName);
    if (normalizationProcessorConfig == null) {
        throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_MISSING_INVALID_CONFIG, fieldName));
    }
}
Also used : ComponentConfigException(com.hortonworks.streamline.common.exception.ComponentConfigException) Map(java.util.Map)

Example 2 with ComponentConfigException

use of com.hortonworks.streamline.common.exception.ComponentConfigException in project streamline by hortonworks.

the class TopologyLayoutValidator method validateDataSinks.

private void validateDataSinks() throws ComponentConfigException {
    List<Map> dataSinks = (List<Map>) jsonMap.get(TopologyLayoutConstants.JSON_KEY_DATA_SINKS);
    for (Map dataSink : dataSinks) {
        // data sink name given by the user in UI
        String dataSinkName = (String) dataSink.get(TopologyLayoutConstants.JSON_KEY_UINAME);
        if (componentKeys.contains(dataSinkName)) {
            throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_UINAME_DUP, dataSinkName));
        }
        dataSinkComponentKeys.add(dataSinkName);
        componentKeys.add(dataSinkName);
    }
}
Also used : ComponentConfigException(com.hortonworks.streamline.common.exception.ComponentConfigException) List(java.util.List) Map(java.util.Map)

Example 3 with ComponentConfigException

use of com.hortonworks.streamline.common.exception.ComponentConfigException in project streamline by hortonworks.

the class TopologyLayoutValidator method validateDataSources.

private void validateDataSources() throws ComponentConfigException {
    List<Map> dataSources = (List<Map>) jsonMap.get(TopologyLayoutConstants.JSON_KEY_DATA_SOURCES);
    for (Map dataSource : dataSources) {
        // data source name given by the user in UI
        String dataSourceName = (String) dataSource.get(TopologyLayoutConstants.JSON_KEY_UINAME);
        if (componentKeys.contains(dataSourceName)) {
            throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_UINAME_DUP, dataSourceName));
        }
        dataSourceComponentKeys.add(dataSourceName);
        componentKeys.add(dataSourceName);
    }
}
Also used : ComponentConfigException(com.hortonworks.streamline.common.exception.ComponentConfigException) List(java.util.List) Map(java.util.Map)

Example 4 with ComponentConfigException

use of com.hortonworks.streamline.common.exception.ComponentConfigException in project streamline by hortonworks.

the class TopologyLayoutValidator method validateLinks.

private void validateLinks() throws ComponentConfigException {
    List<Map> links = (List<Map>) jsonMap.get(TopologyLayoutConstants.JSON_KEY_LINKS);
    for (Map link : links) {
        // link name given by the user in UI
        String linkName = (String) link.get(TopologyLayoutConstants.JSON_KEY_UINAME);
        if (componentKeys.contains(linkName)) {
            throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_UINAME_DUP, linkName));
        }
        Map linkConfig = (Map) link.get(TopologyLayoutConstants.JSON_KEY_CONFIG);
        String linkFrom = (String) linkConfig.get(TopologyLayoutConstants.JSON_KEY_FROM);
        String linkTo = (String) linkConfig.get(TopologyLayoutConstants.JSON_KEY_TO);
        if (linkFrom.equals(linkTo)) {
            throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_LOOP, linkFrom, linkTo));
        }
        // linkFrom can only be a source or a processor
        if ((!dataSourceComponentKeys.contains(linkFrom) && !processorComponentKeys.contains(linkFrom)) || dataSinkComponentKeys.contains(linkFrom)) {
            throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_LINK_FROM, linkFrom));
        }
        // linkTo can only be a sink or a processor
        if ((!dataSinkComponentKeys.contains(linkTo) && !processorComponentKeys.contains(linkTo)) || dataSourceComponentKeys.contains(linkTo)) {
            throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_LINK_TO, linkTo));
        }
        linkFromComponentKeys.add(linkFrom);
        linkToComponentKeys.add(linkTo);
    }
}
Also used : ComponentConfigException(com.hortonworks.streamline.common.exception.ComponentConfigException) List(java.util.List) Map(java.util.Map)

Example 5 with ComponentConfigException

use of com.hortonworks.streamline.common.exception.ComponentConfigException in project streamline by hortonworks.

the class StormTopologyValidator method validateCustomProcessorLinks.

private void validateCustomProcessorLinks() throws ComponentConfigException {
    List<Map> dataSources = (List) this.topologyConfig.get(TopologyLayoutConstants.JSON_KEY_DATA_SOURCES);
    Set<String> dataSourceNames = new HashSet<>();
    for (Map dataSource : dataSources) {
        dataSourceNames.add((String) dataSource.get(TopologyLayoutConstants.JSON_KEY_UINAME));
    }
    List<Map> processors = (List) this.topologyConfig.get(TopologyLayoutConstants.JSON_KEY_PROCESSORS);
    Map<String, Map<String, Schema>> outputSchemas = new LinkedHashMap<>();
    for (Map processor : processors) {
        String type = (String) processor.get(TopologyLayoutConstants.JSON_KEY_TYPE);
        if ("CUSTOM".equals(type)) {
            Map config = (Map) processor.get(TopologyLayoutConstants.JSON_KEY_CONFIG);
            try {
                getCustomProcessorInputSchema(config);
                outputSchemas.put((String) processor.get(TopologyLayoutConstants.JSON_KEY_UINAME), getCustomProcessorOutputSchema(config));
            } catch (IOException e) {
                String message = "Invalid custom processor input or output schema config.";
                LOG.error(message);
                throw new ComponentConfigException(message, e);
            }
        }
    }
    Set<String> customProcessorKeys = outputSchemas.keySet();
    List<Map> links = (List) this.topologyConfig.get(TopologyLayoutConstants.JSON_KEY_LINKS);
    for (Map link : links) {
        Map linkConfig = (Map) link.get(TopologyLayoutConstants.JSON_KEY_CONFIG);
        String from = (String) linkConfig.get(TopologyLayoutConstants.JSON_KEY_FROM);
        String to = (String) linkConfig.get(TopologyLayoutConstants.JSON_KEY_TO);
        if (customProcessorKeys.contains(from)) {
            String streamId = (String) linkConfig.get(TopologyLayoutConstants.JSON_KEY_STREAM_ID);
            if (StringUtils.isEmpty(streamId)) {
                throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_INVALID_STREAM_ID, link.get(TopologyLayoutConstants.JSON_KEY_UINAME)));
            }
            Map<String, Schema> streamIdToOutput = outputSchemas.get(from);
            Set<String> outputStreams = streamIdToOutput.keySet();
            if (!outputStreams.contains(streamId)) {
                throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_INVALID_STREAM_ID, link.get(TopologyLayoutConstants.JSON_KEY_UINAME)));
            }
            if ("FIELDS".equals(link.get(TopologyLayoutConstants.JSON_KEY_TYPE))) {
                Set<String> outputFields = getTopLevelFieldNamesFromSchema(streamIdToOutput.get(streamId));
                List<String> groupingFields = (List) linkConfig.get(TopologyLayoutConstants.JSON_KEY_GROUPING_FIELDS);
                if (!outputFields.containsAll(groupingFields)) {
                    throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_INVALID_GROUPING_FIELDS, link.get(TopologyLayoutConstants.JSON_KEY_UINAME)));
                }
            }
        }
        if (customProcessorKeys.contains(to)) {
            // link to a custom processor can not go from a data source
            if (dataSourceNames.contains(from)) {
                throw new ComponentConfigException(String.format(TopologyLayoutConstants.ERR_MSG_INVALID_LINK_TO_PROCESSOR, link.get(TopologyLayoutConstants.JSON_KEY_UINAME)));
            }
        }
    }
}
Also used : ComponentConfigException(com.hortonworks.streamline.common.exception.ComponentConfigException) Schema(com.hortonworks.registries.common.Schema) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

ComponentConfigException (com.hortonworks.streamline.common.exception.ComponentConfigException)11 Map (java.util.Map)10 List (java.util.List)6 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 LinkedHashMap (java.util.LinkedHashMap)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Schema (com.hortonworks.registries.common.Schema)1 CustomProcessorInfo (com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo)1 BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 HashMap (java.util.HashMap)1 TarArchiveInputStream (org.apache.commons.compress.archivers.tar.TarArchiveInputStream)1