use of com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle in project streamline by hortonworks.
the class TopologyComponentBundleResource method getTopologyComponentBundleById.
/**
* Get component bundle registered for a type(SOURCE, SINK, etc) matching the id
* <p>
* GET api/v1/catalog/streams/componentbundles/SOURCE/5
* </p>
*/
@GET
@Path("/componentbundles/{component}/{id}")
@Timed
@Produces(MediaType.APPLICATION_JSON)
public Response getTopologyComponentBundleById(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("id") Long id, @Context SecurityContext securityContext) {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_USER);
TopologyComponentBundle result = catalogService.getTopologyComponentBundle(id);
if (result != null) {
return WSUtils.respondEntity(result, OK);
}
throw EntityNotFoundException.byId(id.toString());
}
use of com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle 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.streamline.streams.catalog.topology.TopologyComponentBundle in project streamline by hortonworks.
the class StreamCatalogService method removeTopologyComponentBundle.
public TopologyComponentBundle removeTopologyComponentBundle(Long id) throws IOException {
TopologyComponentBundle topologyComponentBundle = new TopologyComponentBundle();
topologyComponentBundle.setId(id);
TopologyComponentBundle existing = this.dao.get(topologyComponentBundle.getStorableKey());
if (!existing.getBuiltin()) {
deleteFileFromStorage(existing.getBundleJar());
}
return dao.remove(existing.getStorableKey());
}
use of com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle in project streamline by hortonworks.
the class StreamCatalogService method getTopologyComponentBundle.
public TopologyComponentBundle getTopologyComponentBundle(Long topologyComponentBundleId) {
TopologyComponentBundle topologyComponentBundle = new TopologyComponentBundle();
topologyComponentBundle.setId(topologyComponentBundleId);
return this.dao.get(topologyComponentBundle.getStorableKey());
}
use of com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle in project streamline by hortonworks.
the class StreamCatalogService method addCustomProcessorInfoAsBundle.
public CustomProcessorInfo addCustomProcessorInfoAsBundle(CustomProcessorInfo customProcessorInfo, InputStream jarFile) throws IOException, ComponentConfigException, NoSuchAlgorithmException {
List<QueryParam> queryParams = new ArrayList<>();
queryParams.add(new QueryParam(CustomProcessorInfo.NAME, customProcessorInfo.getName()));
Collection<TopologyComponentBundle> result = this.listCustomProcessorBundlesWithFilter(queryParams);
if (!result.isEmpty()) {
throw new IOException("Custom processor already exists with name:" + customProcessorInfo.getName());
}
this.handleCustomProcessorJar(jarFile, customProcessorInfo, true);
TopologyComponentBundle topologyComponentBundle = customProcessorInfo.toTopologyComponentBundle();
this.addTopologyComponentBundle(topologyComponentBundle, null);
return customProcessorInfo;
}
Aggregations