use of com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle in project streamline by hortonworks.
the class TopologyComponentBundleResource method addOrUpdateTopologyComponentBundleById.
/**
* Update a topology component bundle by id.
* <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/1
* </p>
*/
@PUT
@Path("/componentbundles/{component}/{id}")
@Timed
public Response addOrUpdateTopologyComponentBundleById(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("id") Long id, 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 (!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);
topologyComponentBundle.setType(componentType);
TopologyComponentBundle updatedBundle = catalogService.addOrUpdateTopologyComponentBundle(id, topologyComponentBundle, tmpFile);
return WSUtils.respondEntity(updatedBundle, OK);
} 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 TopologyComponentBundleResource method addTopologyComponentBundle.
/**
* Add a new topology component bundle.
* <p>
* curl -sS -X POST -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>
*/
@POST
@Path("/componentbundles/{component}")
@Timed
public Response addTopologyComponentBundle(@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);
}
List<QueryParam> queryParams;
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
params.putSingle(TopologyComponentBundle.STREAMING_ENGINE, topologyComponentBundle.getStreamingEngine());
params.putSingle(TopologyComponentBundle.SUB_TYPE, topologyComponentBundle.getSubType());
queryParams = WSUtils.buildQueryParameters(params);
Collection<TopologyComponentBundle> topologyComponentBundles = catalogService.listTopologyComponentBundlesForTypeWithFilter(componentType, queryParams);
if (topologyComponentBundles != null && !topologyComponentBundles.isEmpty()) {
LOG.warn("Received a post request for an already registered bundle. Not creating entity for " + topologyComponentBundle);
return WSUtils.respondEntity(topologyComponentBundle, CONFLICT);
}
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);
topologyComponentBundle.setType(componentType);
TopologyComponentBundle createdBundle = catalogService.addTopologyComponentBundle(topologyComponentBundle, tmpFile);
return WSUtils.respondEntity(createdBundle, CREATED);
} catch (RuntimeException e) {
LOG.debug("Error occured while adding 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 TopologyComponentBundleResource method getFieldHints.
@GET
@Path("/componentbundles/{component}/{id}/hints/namespaces/{namespaceId}")
@Timed
public Response getFieldHints(@PathParam("component") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("id") Long id, @PathParam("namespaceId") Long namespaceId, @Context SecurityContext securityContext) throws Exception {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_USER);
TopologyComponentBundle bundle = catalogService.getTopologyComponentBundle(id);
if (bundle == null || !bundle.getType().equals(componentType)) {
throw EntityNotFoundException.byId("component bundle id: " + id + " with type: " + componentType);
}
String providerClass = bundle.getFieldHintProviderClass();
if (StringUtils.isNotEmpty(providerClass)) {
ComponentBundleHintProvider provider;
if (bundle.getBuiltin()) {
Class<ComponentBundleHintProvider> clazz = (Class<ComponentBundleHintProvider>) Class.forName(providerClass);
provider = clazz.newInstance();
} else {
provider = hintProviderProxyUtil.loadClassFromJar(bundle.getBundleJar(), providerClass);
}
provider.init(environmentService);
Namespace namespace = environmentService.getNamespace(namespaceId);
if (namespace == null) {
throw EntityNotFoundException.byId("namespace id: " + namespaceId);
}
Map<Long, ComponentBundleHintProvider.BundleHintsResponse> hints = provider.provide(namespace, securityContext, subject);
return WSUtils.respondEntity(hints, OK);
} else {
return WSUtils.respondEntity(Collections.emptyMap(), OK);
}
}
Aggregations