Search in sources :

Example 71 with Path

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

the class SseEventSinkToEventSourceTest method testWithJerseyApi.

@Test
public void testWithJerseyApi() throws InterruptedException {
    final WebTarget endpoint = target().path("events");
    final EventSource eventSource = EventSource.target(endpoint).build();
    transmitLatch = new CountDownLatch(MSG_COUNT);
    final CountDownLatch receiveLatch = new CountDownLatch(MSG_COUNT);
    final List<Integer> results = new ArrayList<>();
    final EventListener listener = inboundEvent -> {
        try {
            results.add(inboundEvent.readData(Integer.class));
            receiveLatch.countDown();
            Assert.assertEquals(INTEGER_SSE_NAME, inboundEvent.getName());
        } catch (ProcessingException ex) {
            throw new RuntimeException("Error when deserializing of data.", ex);
        }
    };
    eventSource.register(listener, INTEGER_SSE_NAME);
    eventSource.open();
    Assert.assertTrue(transmitLatch.await(5000, TimeUnit.MILLISECONDS));
    Assert.assertTrue(receiveLatch.await(5000, TimeUnit.MILLISECONDS));
    Assert.assertEquals(10, results.size());
}
Also used : SseEventSource(javax.ws.rs.sse.SseEventSource) SseEventSink(javax.ws.rs.sse.SseEventSink) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Application(javax.ws.rs.core.Application) Singleton(javax.inject.Singleton) ArrayList(java.util.ArrayList) MediaType(javax.ws.rs.core.MediaType) JerseyTest(org.glassfish.jersey.test.JerseyTest) Sse(javax.ws.rs.sse.Sse) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) ExecutorService(java.util.concurrent.ExecutorService) Context(javax.ws.rs.core.Context) EventListener(org.glassfish.jersey.media.sse.EventListener) EventSource(org.glassfish.jersey.media.sse.EventSource) Test(org.junit.Test) Logger(java.util.logging.Logger) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) InboundSseEvent(javax.ws.rs.sse.InboundSseEvent) ProcessingException(javax.ws.rs.ProcessingException) WebTarget(javax.ws.rs.client.WebTarget) Assert(org.junit.Assert) SseEventSource(javax.ws.rs.sse.SseEventSource) EventSource(org.glassfish.jersey.media.sse.EventSource) ArrayList(java.util.ArrayList) WebTarget(javax.ws.rs.client.WebTarget) EventListener(org.glassfish.jersey.media.sse.EventListener) CountDownLatch(java.util.concurrent.CountDownLatch) ProcessingException(javax.ws.rs.ProcessingException) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Example 72 with Path

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

the class TestExceptionResource method getUnmappedException.

@GET
@Path("unmapped")
public void getUnmappedException(@Suspended final AsyncResponse asyncResponse) {
    lastProcessingThread = Thread.currentThread();
    asyncResponse.resume(new UnmappedException());
}
Also used : UnmappedException(org.glassfish.jersey.tests.integration.jersey2730.exception.UnmappedException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 73 with Path

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

the class TestExceptionResource method getUnmappedRuntimeException.

@GET
@Path("runtime")
public void getUnmappedRuntimeException(@Suspended final AsyncResponse asyncResponse) {
    lastProcessingThread = Thread.currentThread();
    asyncResponse.resume(new UnmappedRuntimeException());
}
Also used : UnmappedRuntimeException(org.glassfish.jersey.tests.integration.jersey2730.exception.UnmappedRuntimeException) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 74 with Path

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

the class DetectionJobResource method computeSeverity.

/**
   * Returns the weight of the metric at the given window. The calculation of baseline (history) data is specified by
   * seasonal period (in days) and season count. Seasonal period is the difference of duration from one window to the
   * other. For instance, to use the data that is one week before current window, set seasonal period to 7. The season
   * count specify how many seasons of history data to retrieve. If there are more than 1 season, then the baseline is
   * the average of all seasons.
   *
   * Examples of the configuration of baseline:
   * 1. Week-Over-Week: seasonalPeriodInDays = 7, seasonCount = 1
   * 2. Week-Over-4-Weeks-Mean: seasonalPeriodInDays = 7, seasonCount = 4
   * 3. Month-Over-Month: seasonalPeriodInDays = 30, seasonCount = 1
   *
   * @param collectionName the collection to which the metric belong
   * @param metricName the metric name
   * @param startTimeIso start time of current window, inclusive
   * @param endTimeIso end time of current window, exclusive
   * @param seasonalPeriodInDays the difference of duration between the start time of each window
   * @param seasonCount the number of history windows
   *
   * @return the weight of the metric at the given window
   * @throws Exception
   */
@POST
@Path("/anomaly-weight")
public Response computeSeverity(@NotNull @QueryParam("collection") String collectionName, @NotNull @QueryParam("metric") String metricName, @NotNull @QueryParam("start") String startTimeIso, @NotNull @QueryParam("end") String endTimeIso, @QueryParam("period") String seasonalPeriodInDays, @QueryParam("seasonCount") String seasonCount) throws Exception {
    DateTime startTime = null;
    DateTime endTime = null;
    if (StringUtils.isNotBlank(startTimeIso)) {
        startTime = ISODateTimeFormat.dateTimeParser().parseDateTime(startTimeIso);
    }
    if (StringUtils.isNotBlank(endTimeIso)) {
        endTime = ISODateTimeFormat.dateTimeParser().parseDateTime(endTimeIso);
    }
    long currentWindowStart = startTime.getMillis();
    long currentWindowEnd = endTime.getMillis();
    // Default is using one week data priors current values for calculating weight
    long seasonalPeriodMillis = TimeUnit.DAYS.toMillis(7);
    if (StringUtils.isNotBlank(seasonalPeriodInDays)) {
        seasonalPeriodMillis = TimeUnit.DAYS.toMillis(Integer.parseInt(seasonalPeriodInDays));
    }
    int seasonCountInt = 1;
    if (StringUtils.isNotBlank(seasonCount)) {
        seasonCountInt = Integer.parseInt(seasonCount);
    }
    ThirdEyeClient thirdEyeClient = CACHE_REGISTRY_INSTANCE.getQueryCache().getClient();
    SeverityComputationUtil util = new SeverityComputationUtil(thirdEyeClient, collectionName, metricName);
    Map<String, Object> severity = util.computeSeverity(currentWindowStart, currentWindowEnd, seasonalPeriodMillis, seasonCountInt);
    return Response.ok(severity.toString(), MediaType.TEXT_PLAIN_TYPE).build();
}
Also used : SeverityComputationUtil(com.linkedin.thirdeye.util.SeverityComputationUtil) ThirdEyeClient(com.linkedin.thirdeye.client.ThirdEyeClient) DateTime(org.joda.time.DateTime) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 75 with Path

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

the class DetectionJobResource method tuneAlertFilter.

/**
   *
   * @param id anomaly function id
   * @param startTime start time of anomalies to tune alert filter
   * @param endTime end time of anomalies to tune alert filter
   * @param autoTuneType the type of auto tune to invoke (default is "AUTOTUNE")
   * @return HTTP response of request: string of alert filter
   */
@POST
@Path("/autotune/filter/{functionId}")
public Response tuneAlertFilter(@PathParam("functionId") long id, @QueryParam("startTime") long startTime, @QueryParam("endTime") long endTime, @QueryParam("autoTuneType") String autoTuneType) {
    // get anomalies by function id, start time and end time
    AnomalyFunctionDTO anomalyFunctionSpec = DAO_REGISTRY.getAnomalyFunctionDAO().findById(id);
    AnomalyFunctionManager anomalyFunctionDAO = DAO_REGISTRY.getAnomalyFunctionDAO();
    MergedAnomalyResultManager anomalyMergedResultDAO = DAO_REGISTRY.getMergedAnomalyResultDAO();
    List<MergedAnomalyResultDTO> anomalyResultDTOS = anomalyMergedResultDAO.findByStartTimeInRangeAndFunctionId(startTime, endTime, id);
    // create alert filter and evaluator
    AlertFilter alertFilter = alertFilterFactory.fromSpec(anomalyFunctionSpec.getAlertFilter());
    AlertFilterEvaluationUtil evaluator = new AlertFilterEvaluationUtil(alertFilter);
    // create alert filter auto tune
    AlertFilterAutoTune alertFilterAutotune = alertFilterAutotuneFactory.fromSpec(autoTuneType);
    LOG.info("initiated alertFilterAutoTune of Type {}", alertFilterAutotune.getClass().toString());
    try {
        //evaluate current alert filter (calculate current precision and recall)
        evaluator.updatePrecisionAndRecall(anomalyResultDTOS);
        LOG.info("AlertFilter of Type {}, has been evaluated with precision: {}, recall: {}", alertFilter.getClass().toString(), evaluator.getPrecision(), evaluator.getRecall());
        // get tuned alert filter
        Map<String, String> tunedAlertFilter = alertFilterAutotune.tuneAlertFilter(anomalyResultDTOS, evaluator.getPrecision(), evaluator.getRecall());
        LOG.info("tuned AlertFilter");
        // otherwise do nothing and return alert filter
        if (alertFilterAutotune.isUpdated()) {
            anomalyFunctionSpec.setAlertFilter(tunedAlertFilter);
            anomalyFunctionDAO.update(anomalyFunctionSpec);
            LOG.info("Model has been updated");
        } else {
            LOG.info("Model hasn't been updated because tuned model cannot beat original model");
        }
    } catch (Exception e) {
        LOG.warn("AutoTune throws exception due to: {}", e.getMessage());
    }
    return Response.ok(alertFilterAutotune.isUpdated()).build();
}
Also used : AnomalyFunctionManager(com.linkedin.thirdeye.datalayer.bao.AnomalyFunctionManager) AlertFilterAutoTune(com.linkedin.thirdeye.anomalydetection.alertFilterAutotune.AlertFilterAutoTune) MergedAnomalyResultDTO(com.linkedin.thirdeye.datalayer.dto.MergedAnomalyResultDTO) AlertFilter(com.linkedin.thirdeye.detector.email.filter.AlertFilter) AnomalyFunctionDTO(com.linkedin.thirdeye.datalayer.dto.AnomalyFunctionDTO) MergedAnomalyResultManager(com.linkedin.thirdeye.datalayer.bao.MergedAnomalyResultManager) AlertFilterEvaluationUtil(com.linkedin.thirdeye.detector.email.filter.AlertFilterEvaluationUtil) NullArgumentException(org.apache.commons.lang.NullArgumentException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Aggregations

Path (javax.ws.rs.Path)6273 Produces (javax.ws.rs.Produces)3678 GET (javax.ws.rs.GET)3072 POST (javax.ws.rs.POST)1783 Consumes (javax.ws.rs.Consumes)1440 ApiOperation (io.swagger.annotations.ApiOperation)1213 ApiResponses (io.swagger.annotations.ApiResponses)997 PUT (javax.ws.rs.PUT)850 IOException (java.io.IOException)677 DELETE (javax.ws.rs.DELETE)662 ArrayList (java.util.ArrayList)591 WebApplicationException (javax.ws.rs.WebApplicationException)556 Response (javax.ws.rs.core.Response)540 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)490 HashMap (java.util.HashMap)394 Timed (com.codahale.metrics.annotation.Timed)383 URI (java.net.URI)374 List (java.util.List)287 Map (java.util.Map)259 NotFoundException (javax.ws.rs.NotFoundException)258