Search in sources :

Example 61 with QueryParam

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());
}
Also used : Logger(org.slf4j.Logger) ProxyUtil(com.hortonworks.streamline.common.util.ProxyUtil) QueryParam(com.hortonworks.registries.common.QueryParam) LoggerFactory(org.slf4j.LoggerFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Notification(com.hortonworks.streamline.streams.notification.Notification) HBaseNotificationStore(com.hortonworks.streamline.streams.notification.store.hbase.HBaseNotificationStore) CriteriaImpl(com.hortonworks.streamline.streams.notification.store.CriteriaImpl) List(java.util.List) Future(java.util.concurrent.Future) StreamlineEvent(com.hortonworks.streamline.streams.StreamlineEvent) Map(java.util.Map) Notifier(com.hortonworks.streamline.streams.notification.Notifier) Optional(java.util.Optional) Collections(java.util.Collections) NotificationStore(com.hortonworks.streamline.streams.notification.store.NotificationStore) NotificationContext(com.hortonworks.streamline.streams.notification.NotificationContext) CriteriaImpl(com.hortonworks.streamline.streams.notification.store.CriteriaImpl) QueryParam(com.hortonworks.registries.common.QueryParam) Notification(com.hortonworks.streamline.streams.notification.Notification)

Example 62 with QueryParam

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);
        }
    }
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) QueryParam(com.hortonworks.registries.common.QueryParam) InputStream(java.io.InputStream) 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) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 63 with QueryParam

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);
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) StreamingOutput(javax.ws.rs.core.StreamingOutput) CustomProcessorOnlyException(com.hortonworks.streamline.common.exception.service.exception.request.CustomProcessorOnlyException) CustomProcessorInfo(com.hortonworks.streamline.streams.catalog.processor.CustomProcessorInfo) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 64 with QueryParam

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;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList) Tag(com.hortonworks.registries.tag.Tag) TagStorableMapping(com.hortonworks.registries.tag.TagStorableMapping)

Example 65 with QueryParam

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();
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) MLModel(com.hortonworks.registries.model.data.MLModel)

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