Search in sources :

Example 36 with Consumes

use of javax.ws.rs.Consumes in project jersey by jersey.

the class MessageStreamResource method putMessage.

/**
     * Put a new message to the stream.
     *
     * The message will be broadcast to all registered SSE clients.
     *
     * @param message message to be broadcast.
     */
@PUT
@Consumes(MediaType.APPLICATION_JSON)
public void putMessage(final Message message) {
    LOGGER.info("--> Message received.");
    final OutboundEvent event = new OutboundEvent.Builder().id(String.valueOf(nextMessageId.getAndIncrement())).mediaType(MediaType.APPLICATION_JSON_TYPE).data(Message.class, message).build();
    broadcaster.broadcast(event);
}
Also used : OutboundEvent(org.glassfish.jersey.media.sse.OutboundEvent) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 37 with Consumes

use of javax.ws.rs.Consumes in project pinot by linkedin.

the class AnomalyFunctionResource method analyze.

@POST
@Path("/analyze")
@Consumes(MediaType.APPLICATION_JSON)
public Response analyze(AnomalyFunctionDTO anomalyFunctionSpec, @QueryParam("startTime") Long startTime, @QueryParam("endTime") Long endTime) throws Exception {
    // TODO: replace this with Job/Task framework and job tracker page
    BaseAnomalyFunction anomalyFunction = anomalyFunctionFactory.fromSpec(anomalyFunctionSpec);
    List<Pair<Long, Long>> startEndTimeRanges = anomalyFunction.getDataRangeIntervals(startTime, endTime);
    Map<DimensionKey, MetricTimeSeries> dimensionKeyMetricTimeSeriesMap = TimeSeriesUtil.getTimeSeriesForAnomalyDetection(anomalyFunctionSpec, startEndTimeRanges);
    List<RawAnomalyResultDTO> anomalyResults = new ArrayList<>();
    List<RawAnomalyResultDTO> results = new ArrayList<>();
    List<String> collectionDimensions = DAO_REGISTRY.getDatasetConfigDAO().findByDataset(anomalyFunctionSpec.getCollection()).getDimensions();
    for (Map.Entry<DimensionKey, MetricTimeSeries> entry : dimensionKeyMetricTimeSeriesMap.entrySet()) {
        DimensionKey dimensionKey = entry.getKey();
        DimensionMap dimensionMap = DimensionMap.fromDimensionKey(dimensionKey, collectionDimensions);
        if (entry.getValue().getTimeWindowSet().size() < 2) {
            LOG.warn("Insufficient data for {} to run anomaly detection function", dimensionMap);
            continue;
        }
        try {
            // Run algorithm
            MetricTimeSeries metricTimeSeries = entry.getValue();
            LOG.info("Analyzing anomaly function with dimensionKey: {}, windowStart: {}, windowEnd: {}", dimensionMap, startTime, endTime);
            List<RawAnomalyResultDTO> resultsOfAnEntry = anomalyFunction.analyze(dimensionMap, metricTimeSeries, new DateTime(startTime), new DateTime(endTime), new ArrayList<>());
            if (resultsOfAnEntry.size() != 0) {
                results.addAll(resultsOfAnEntry);
            }
            LOG.info("{} has {} anomalies in window {} to {}", dimensionMap, resultsOfAnEntry.size(), new DateTime(startTime), new DateTime(endTime));
        } catch (Exception e) {
            LOG.error("Could not compute for {}", dimensionMap, e);
        }
    }
    if (results.size() > 0) {
        List<RawAnomalyResultDTO> validResults = new ArrayList<>();
        for (RawAnomalyResultDTO anomaly : results) {
            if (!anomaly.isDataMissing()) {
                LOG.info("Found anomaly, sev [{}] start [{}] end [{}]", anomaly.getWeight(), new DateTime(anomaly.getStartTime()), new DateTime(anomaly.getEndTime()));
                validResults.add(anomaly);
            }
        }
        anomalyResults.addAll(validResults);
    }
    return Response.ok(anomalyResults).build();
}
Also used : BaseAnomalyFunction(com.linkedin.thirdeye.detector.function.BaseAnomalyFunction) ArrayList(java.util.ArrayList) MetricTimeSeries(com.linkedin.thirdeye.api.MetricTimeSeries) DateTime(org.joda.time.DateTime) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) RawAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.RawAnomalyResultDTO) DimensionKey(com.linkedin.thirdeye.api.DimensionKey) DimensionMap(com.linkedin.thirdeye.api.DimensionMap) HashMap(java.util.HashMap) Map(java.util.Map) DimensionMap(com.linkedin.thirdeye.api.DimensionMap) Pair(com.linkedin.pinot.pql.parsers.utils.Pair) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 38 with Consumes

use of javax.ws.rs.Consumes in project jersey by jersey.

the class BookmarkResource method putBookmark.

@PUT
@Consumes("application/json")
public void putBookmark(JSONObject jsonEntity) throws JSONException {
    bookmarkEntity.setLdesc(jsonEntity.getString("ldesc"));
    bookmarkEntity.setSdesc(jsonEntity.getString("sdesc"));
    bookmarkEntity.setUpdated(new Date());
    TransactionManager.manage(utx, new Transactional(em) {

        public void transact() {
            em.merge(bookmarkEntity);
        }
    });
}
Also used : Date(java.util.Date) Transactional(org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT)

Example 39 with Consumes

use of javax.ws.rs.Consumes in project jersey by jersey.

the class BookmarksResource method postForm.

@POST
@Consumes("application/json")
public Response postForm(JSONObject bookmark) throws JSONException {
    final BookmarkEntity bookmarkEntity = new BookmarkEntity(getBookmarkId(bookmark.getString("uri")), userResource.getUserEntity().getUserid());
    bookmarkEntity.setUri(bookmark.getString("uri"));
    bookmarkEntity.setUpdated(new Date());
    bookmarkEntity.setSdesc(bookmark.getString("sdesc"));
    bookmarkEntity.setLdesc(bookmark.getString("ldesc"));
    userResource.getUserEntity().getBookmarkEntityCollection().add(bookmarkEntity);
    TransactionManager.manage(utx, new Transactional(em) {

        public void transact() {
            em.merge(userResource.getUserEntity());
        }
    });
    URI bookmarkUri = uriInfo.getAbsolutePathBuilder().path(bookmarkEntity.getBookmarkEntityPK().getBmid()).build();
    return Response.created(bookmarkUri).build();
}
Also used : BookmarkEntity(org.glassfish.jersey.examples.bookmark_em.entity.BookmarkEntity) URI(java.net.URI) Date(java.util.Date) Transactional(org.glassfish.jersey.examples.bookmark_em.util.tx.Transactional) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes)

Example 40 with Consumes

use of javax.ws.rs.Consumes in project jersey by jersey.

the class ConsumeProduceTest method testConsumesString.

@Test
public void testConsumesString() {
    final Consumes c = ConsumesStringClass.class.getAnnotation(Consumes.class);
    final List<MediaType> l = MediaTypes.createFrom(c);
    checkMediaTypes(l);
}
Also used : Consumes(javax.ws.rs.Consumes) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Aggregations

Consumes (javax.ws.rs.Consumes)1565 Path (javax.ws.rs.Path)1221 Produces (javax.ws.rs.Produces)1217 POST (javax.ws.rs.POST)892 ApiOperation (io.swagger.annotations.ApiOperation)503 ApiResponses (io.swagger.annotations.ApiResponses)445 PUT (javax.ws.rs.PUT)417 GET (javax.ws.rs.GET)223 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)215 URI (java.net.URI)202 IOException (java.io.IOException)147 WebApplicationException (javax.ws.rs.WebApplicationException)139 Response (javax.ws.rs.core.Response)136 ArrayList (java.util.ArrayList)134 Authorizable (org.apache.nifi.authorization.resource.Authorizable)100 DELETE (javax.ws.rs.DELETE)86 TimedResource (org.killbill.commons.metrics.TimedResource)84 CallContext (org.killbill.billing.util.callcontext.CallContext)83 Timed (com.codahale.metrics.annotation.Timed)78 HashMap (java.util.HashMap)76