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);
}
}
}
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));
}
}
}
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;
}
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;
}
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);
}
}
Aggregations