use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.
the class NotificationServiceImpl method findNotifications.
@Override
public List<Notification> findNotifications(List<QueryParam> queryParams) {
LOG.debug("findNotifications with queryParams {}", queryParams);
CriteriaImpl<Notification> criteria = new CriteriaImpl<>(Notification.class);
for (QueryParam qp : queryParams) {
if (qp.name.equalsIgnoreCase(QUERY_PARAM_NUM_ROWS)) {
criteria.setNumRows(Integer.parseInt(qp.value));
} else if (qp.name.equals(QUERY_PARAM_START_TS)) {
criteria.setStartTs(Long.parseLong(qp.value));
} else if (qp.name.equals((QUERY_PARAM_END_TS))) {
criteria.setEndTs(Long.parseLong(qp.value));
} else if (qp.name.equals((QUERY_PARAM_DESC))) {
criteria.setDescending(true);
} else {
criteria.addFieldRestriction(qp.name, qp.value);
}
}
LOG.debug("Finding entities from notification store with criteria {}", criteria);
return notificationStore.map(s -> s.findEntities(criteria)).orElse(Collections.emptyList());
}
use of com.hortonworks.registries.common.QueryParam 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.registries.common.QueryParam in project streamline by hortonworks.
the class TopologyComponentBundleResource method downloadCustomProcessorFile.
@Timed
@GET
@Produces(MediaType.APPLICATION_OCTET_STREAM)
@Path("/componentbundles/{processor}/custom/{name}")
public Response downloadCustomProcessorFile(@PathParam("processor") TopologyComponentBundle.TopologyComponentType componentType, @PathParam("name") String name, @Context SecurityContext securityContext) throws IOException {
SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_USER);
if (!TopologyComponentBundle.TopologyComponentType.PROCESSOR.equals(componentType)) {
throw new CustomProcessorOnlyException();
}
List<QueryParam> queryParams = new ArrayList<>();
queryParams.add(new QueryParam(CustomProcessorInfo.NAME, name));
Collection<CustomProcessorInfo> customProcessorInfos = catalogService.listCustomProcessorsFromBundleWithFilter(queryParams);
if (!customProcessorInfos.isEmpty()) {
final InputStream inputStream = catalogService.getFileFromJarStorage(customProcessorInfos.iterator().next().getJarFileName());
StreamingOutput streamOutput = WSUtils.wrapWithStreamingOutput(inputStream);
return Response.ok(streamOutput).build();
}
throw EntityNotFoundException.byId(name);
}
use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.
the class CatalogTagService method getTags.
@Override
public List<Tag> getTags(TaggedEntity taggedEntity) {
List<Tag> tags = new ArrayList<>();
QueryParam qp1 = new QueryParam(TagStorableMapping.FIELD_STORABLE_ID, String.valueOf(taggedEntity.getId()));
QueryParam qp2 = new QueryParam(TagStorableMapping.FIELD_STORABLE_NAMESPACE, String.valueOf(taggedEntity.getNamespace()));
for (TagStorableMapping mapping : listTagStorableMapping(ImmutableList.of(qp1, qp2))) {
tags.add(getTag(mapping.getTagId()));
}
return tags;
}
use of com.hortonworks.registries.common.QueryParam in project registry by hortonworks.
the class MLModelRegistryService method getModelInfo.
public MLModel getModelInfo(String name) {
List<QueryParam> queryParams = Collections.singletonList(new QueryParam(MLModel.NAME, name));
Collection<MLModel> modelInfos = this.storageManager.find(ML_MODEL_NAME_SPACE, queryParams);
if (modelInfos.size() == 0) {
throw EntityNotFoundException.byName(name);
}
return modelInfos.iterator().next();
}
Aggregations