Search in sources :

Example 6 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class TopologyComponentBundleResource method addOrUpdateTopologyComponentBundle.

/**
 * Update a topology component bundle by trying to find id using type, sub type and streaming engine.
 * <p>
 * curl -sS -X PUT -i -F topologyComponentBundle=@kafka-topology-bundle -F bundleJar=@/Users/pshah/dev/IoTaS/streams/runners/storm/layout/target/streams-layout-storm-0.6.0-SNAPSHOT.jar  http://localhost:8080/api/v1/catalog/streams/componentbundles/SOURCE/
 * </p>
 */
@PUT
@Path("/componentbundles/{component}")
@Timed
public Response addOrUpdateTopologyComponentBundle(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, FormDataMultiPart form, @Context SecurityContext securityContext) throws IOException, ComponentConfigException {
    SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_ADMIN);
    InputStream bundleJar = null;
    File tmpFile = null;
    try {
        String bundleJsonString = this.getFormDataFromMultiPartRequestAs(String.class, form, TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME);
        TopologyComponentBundle topologyComponentBundle = new ObjectMapper().readValue(bundleJsonString, TopologyComponentBundle.class);
        if (topologyComponentBundle == null) {
            LOG.debug(TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME + " is missing or invalid");
            throw BadRequestException.missingParameter(TOPOLOGY_COMPONENT_BUNDLE_PARAM_NAME);
        }
        if (!componentType.equals(topologyComponentBundle.getType())) {
            String message = "Cant update a " + topologyComponentBundle.getType() + " on " + componentType + " endpoint. Verify PUT request";
            LOG.debug(message);
            throw BadRequestException.message(message);
        }
        if (!topologyComponentBundle.getBuiltin()) {
            bundleJar = this.getFormDataFromMultiPartRequestAs(InputStream.class, form, BUNDLE_JAR_FILE_PARAM_NAME);
            if (bundleJar == null) {
                LOG.debug(BUNDLE_JAR_FILE_PARAM_NAME + " is missing or invalid");
                throw BadRequestException.missingParameter(BUNDLE_JAR_FILE_PARAM_NAME);
            } else {
                tmpFile = FileUtil.writeInputStreamToTempFile(bundleJar, ".jar");
            }
        }
        validateTopologyBundle(topologyComponentBundle);
        List<QueryParam> queryParams = new ArrayList<>();
        queryParams.add(new QueryParam(TopologyComponentBundle.STREAMING_ENGINE, topologyComponentBundle.getStreamingEngine()));
        queryParams.add(new QueryParam(TopologyComponentBundle.TYPE, topologyComponentBundle.getType().name()));
        queryParams.add(new QueryParam(TopologyComponentBundle.SUB_TYPE, topologyComponentBundle.getSubType()));
        Collection<TopologyComponentBundle> existing = catalogService.listTopologyComponentBundlesForTypeWithFilter(componentType, queryParams);
        if (existing != null && existing.size() == 1) {
            TopologyComponentBundle updatedBundle = catalogService.addOrUpdateTopologyComponentBundle(existing.iterator().next().getId(), topologyComponentBundle, tmpFile);
            return WSUtils.respondEntity(updatedBundle, OK);
        } else {
            String message = "Cant update because lookup using streaming engine, type and subtype returned either no existing bundle or more than one";
            LOG.debug(message);
            throw BadRequestException.message(message);
        }
    } catch (RuntimeException e) {
        LOG.debug("Error occured while updating topology component bundle", e);
        throw e;
    } finally {
        try {
            if (bundleJar != null) {
                bundleJar.close();
            }
        } catch (IOException e) {
            LOG.debug("Error while closing jar file stream", e);
        }
    }
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TopologyComponentBundle(com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 7 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class StreamCatalogService method copyTopologyDependencies.

private void copyTopologyDependencies(Long topologyId, Long oldVersionId, Long newVersionId) throws Exception {
    List<QueryParam> topologyIdVersionIdQueryParams = WSUtils.buildTopologyIdAndVersionIdAwareQueryParams(topologyId, oldVersionId, null);
    // topology editor metadata
    TopologyEditorMetadata metadata = getTopologyEditorMetadata(topologyId, oldVersionId);
    if (metadata != null) {
        addTopologyEditorMetadata(topologyId, newVersionId, new TopologyEditorMetadata(metadata));
    }
    // sources, output streams
    Collection<TopologySource> sources = listTopologySources(topologyIdVersionIdQueryParams);
    for (TopologySource source : sources) {
        addTopologySource(topologyId, newVersionId, new TopologySource(source));
    }
    // processors, output streams
    Collection<TopologyProcessor> processors = listTopologyProcessors(topologyIdVersionIdQueryParams);
    for (TopologyProcessor processor : processors) {
        addTopologyProcessor(topologyId, newVersionId, new TopologyProcessor(processor));
    }
    // add sinks
    Collection<TopologySink> sinks = listTopologySinks(topologyIdVersionIdQueryParams);
    for (TopologySink sink : sinks) {
        addTopologySink(topologyId, newVersionId, new TopologySink(sink));
    }
    // branch rules
    Collection<TopologyBranchRule> topologyBranchRules = listBranchRules(topologyIdVersionIdQueryParams);
    for (TopologyBranchRule topologyBranchRule : topologyBranchRules) {
        addBranchRule(topologyId, newVersionId, new TopologyBranchRule(topologyBranchRule));
    }
    // windowed rules
    Collection<TopologyWindow> topologyWindows = listWindows(topologyIdVersionIdQueryParams);
    for (TopologyWindow topologyWindow : topologyWindows) {
        addWindow(topologyId, newVersionId, new TopologyWindow(topologyWindow));
    }
    // rules
    Collection<TopologyRule> topologyRules = listRules(topologyIdVersionIdQueryParams);
    for (TopologyRule topologyRule : topologyRules) {
        addRule(topologyId, newVersionId, new TopologyRule(topologyRule));
    }
    // add edges
    Collection<TopologyEdge> edges = listTopologyEdges(topologyIdVersionIdQueryParams);
    for (TopologyEdge edge : edges) {
        addTopologyEdge(topologyId, newVersionId, new TopologyEdge(edge));
    }
    // add topology test run case
    Collection<TopologyTestRunCase> runCases = listTopologyTestRunCase(topologyIdVersionIdQueryParams);
    for (TopologyTestRunCase runCase : runCases) {
        Collection<TopologyTestRunCaseSource> runCaseSources = listTopologyTestRunCaseSource(runCase.getId());
        Collection<TopologyTestRunCaseSink> runCaseSinks = listTopologyTestRunCaseSink(runCase.getId());
        TopologyTestRunCase newCase = addTopologyTestRunCase(topologyId, newVersionId, new TopologyTestRunCase(runCase));
        // add topology test run case source
        for (TopologyTestRunCaseSource runCaseSource : runCaseSources) {
            addTopologyTestRunCaseSource(newCase.getId(), newVersionId, new TopologyTestRunCaseSource(runCaseSource));
        }
        // add topology test run case sink
        for (TopologyTestRunCaseSink runCaseSink : runCaseSinks) {
            addTopologyTestRunCaseSink(newCase.getId(), newVersionId, new TopologyTestRunCaseSink(runCaseSink));
        }
    }
}
Also used : TopologyWindow(com.hortonworks.streamline.streams.catalog.TopologyWindow) TopologySink(com.hortonworks.streamline.streams.catalog.TopologySink) TopologyBranchRule(com.hortonworks.streamline.streams.catalog.TopologyBranchRule) TopologySource(com.hortonworks.streamline.streams.catalog.TopologySource) TopologyEditorMetadata(com.hortonworks.streamline.streams.catalog.TopologyEditorMetadata) TopologyRule(com.hortonworks.streamline.streams.catalog.TopologyRule) BaseTopologyRule(com.hortonworks.streamline.streams.catalog.BaseTopologyRule) TopologyEdge(com.hortonworks.streamline.streams.catalog.TopologyEdge) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) QueryParam(com.hortonworks.registries.common.QueryParam) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) TopologyProcessor(com.hortonworks.streamline.streams.catalog.TopologyProcessor)

Example 8 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class StreamCatalogService method getOutputStreams.

private List<TopologyStream> getOutputStreams(TopologyProcessor topologyProcessor) {
    List<TopologyStream> streams = new ArrayList<>();
    if (topologyProcessor != null) {
        QueryParam qp1 = new QueryParam(TopologyProcessorStreamMap.FIELD_PROCESSOR_ID, String.valueOf(topologyProcessor.getId()));
        QueryParam qp2 = new QueryParam(TopologyProcessorStreamMap.FIELD_VERSION_ID, String.valueOf(topologyProcessor.getVersionId()));
        for (TopologyProcessorStreamMap mapping : listTopologyProcessorStreamMapping(ImmutableList.of(qp1, qp2))) {
            TopologyStream topologyStream = getStreamInfo(topologyProcessor.getTopologyId(), mapping.getStreamId(), topologyProcessor.getVersionId());
            if (topologyStream != null) {
                streams.add(topologyStream);
            }
        }
    }
    return streams;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam) ArrayList(java.util.ArrayList) TopologyProcessorStreamMap(com.hortonworks.streamline.streams.catalog.TopologyProcessorStreamMap) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream)

Example 9 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class StreamCatalogService method getOutputStreams.

private List<TopologyStream> getOutputStreams(TopologySource topologySource) {
    List<TopologyStream> streams = new ArrayList<>();
    if (topologySource != null) {
        QueryParam qp1 = new QueryParam(TopologySourceStreamMap.FIELD_SOURCE_ID, String.valueOf(topologySource.getId()));
        QueryParam qp2 = new QueryParam(TopologySourceStreamMap.FIELD_VERSION_ID, String.valueOf(topologySource.getVersionId()));
        for (TopologySourceStreamMap mapping : listTopologySourceStreamMapping(ImmutableList.of(qp1, qp2))) {
            TopologyStream topologyStream = getStreamInfo(topologySource.getTopologyId(), mapping.getStreamId(), topologySource.getVersionId());
            if (topologyStream != null) {
                streams.add(topologyStream);
            }
        }
    }
    return streams;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam) ArrayList(java.util.ArrayList) TopologyStream(com.hortonworks.streamline.streams.catalog.TopologyStream) TopologySourceStreamMap(com.hortonworks.streamline.streams.catalog.TopologySourceStreamMap)

Example 10 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class StreamCatalogService method checkDuplicateEdge.

// check if edge already exists for given topology between same source and dest
private void checkDuplicateEdge(TopologyEdge edge) {
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam(TopologyEdge.TOPOLOGYID, edge.getTopologyId().toString()));
    queryParams.add(new QueryParam(TopologyEdge.VERSIONID, edge.getVersionId().toString()));
    queryParams.add(new QueryParam(TopologyEdge.FROMID, edge.getFromId().toString()));
    queryParams.add(new QueryParam(TopologyEdge.TOID, edge.getToId().toString()));
    try {
        Collection<TopologyEdge> existingEdges = listTopologyEdges(queryParams);
        if (existingEdges != null && !existingEdges.isEmpty()) {
            throw new IllegalArgumentException("Edge already exists between source and destination, use update api");
        }
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    }
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) WSUtils.versionIdQueryParam(com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam) WSUtils.buildEdgesFromQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam) WSUtils.currentVersionQueryParam(com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam) WSUtils.buildEdgesToQueryParam(com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam) ArrayList(java.util.ArrayList) TopologyEdge(com.hortonworks.streamline.streams.catalog.TopologyEdge) ComponentConfigException(com.hortonworks.streamline.common.exception.ComponentConfigException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) StorageException(com.hortonworks.registries.storage.exception.StorageException)

Aggregations

QueryParam (com.hortonworks.registries.common.QueryParam)72 ArrayList (java.util.ArrayList)42 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)22 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)22 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)22 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)22 IOException (java.io.IOException)8 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)7 StorableKey (com.hortonworks.registries.storage.StorableKey)7 OrderByField (com.hortonworks.registries.storage.OrderByField)6 HashSet (java.util.HashSet)6 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)5 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)5 Timed (com.codahale.metrics.annotation.Timed)4 Preconditions (com.google.common.base.Preconditions)4 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)4 StorageException (com.hortonworks.registries.storage.exception.StorageException)4 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4