@Test public void testSaveOnlineDetectionData() throws Exception { String suffix = this.anomalyDetectionResource.generateSuffix(this.user); String payload = IOUtils.toString(this.getClass().getResourceAsStream("payload-good-custom.json")); JsonNode node = this.objectMapper.readTree(payload); DatasetConfigDTO datasetConfigDTO = this.anomalyDetectionResource .generateDatasetConfig(node, suffix); MetricConfigDTO metricConfigDTO = this.anomalyDetectionResource .generateMetricConfig(node, suffix); try { this.anomalyDetectionResource.saveOnlineDetectionData(node, datasetConfigDTO, metricConfigDTO); } catch (IllegalArgumentException e) { Assert.fail("Unexpected exception: " + e); } suffix = this.anomalyDetectionResource.generateSuffix(this.user); payload = IOUtils.toString(this.getClass().getResourceAsStream("payload-bad-custom.json")); node = this.objectMapper.readTree(payload); datasetConfigDTO = this.anomalyDetectionResource .generateDatasetConfig(node, suffix); metricConfigDTO = this.anomalyDetectionResource .generateMetricConfig(node, suffix); try { this.anomalyDetectionResource.saveOnlineDetectionData(node, datasetConfigDTO, metricConfigDTO); Assert.fail("Inconsistent metric name should throw illegal arg exception"); } catch (IllegalArgumentException e) { } catch (Exception e) { Assert.fail("Unexpected exception: " + e); } }
OnlineDetectionDataDTO saveOnlineDetectionData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO) throws JsonProcessingException { JsonNode dataNode = payloadNode.get(DATA_FIELD); String timeColumnName = datasetConfigDTO.getTimeColumn(); String datasetName = datasetConfigDTO.getDataset(); String metricName = metricConfigDTO.getName(); Preconditions.checkArgument(validateOnlineDetectionData(dataNode, timeColumnName, metricName), String.format("metric: %s or time: %s not found in adhoc data.", metricName, timeColumnName)); OnlineDetectionDataDTO onlineDetectionDataDTO = new OnlineDetectionDataDTO(); onlineDetectionDataDTO.setDataset(datasetName); onlineDetectionDataDTO.setMetric(metricName); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); onlineDetectionDataDAO.save(onlineDetectionDataDTO); LOG.info("Saved online data with dataset: {} and metric: {}", onlineDetectionDataDTO.getDataset(), onlineDetectionDataDTO.getMetric()); return onlineDetectionDataDTO; }
AnomalyDetectionResource { OnlineDetectionDataDTO saveOnlineDetectionData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO) throws JsonProcessingException { JsonNode dataNode = payloadNode.get(DATA_FIELD); String timeColumnName = datasetConfigDTO.getTimeColumn(); String datasetName = datasetConfigDTO.getDataset(); String metricName = metricConfigDTO.getName(); Preconditions.checkArgument(validateOnlineDetectionData(dataNode, timeColumnName, metricName), String.format("metric: %s or time: %s not found in adhoc data.", metricName, timeColumnName)); OnlineDetectionDataDTO onlineDetectionDataDTO = new OnlineDetectionDataDTO(); onlineDetectionDataDTO.setDataset(datasetName); onlineDetectionDataDTO.setMetric(metricName); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); onlineDetectionDataDAO.save(onlineDetectionDataDTO); LOG.info("Saved online data with dataset: {} and metric: {}", onlineDetectionDataDTO.getDataset(), onlineDetectionDataDTO.getMetric()); return onlineDetectionDataDTO; } }
AnomalyDetectionResource { OnlineDetectionDataDTO saveOnlineDetectionData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO) throws JsonProcessingException { JsonNode dataNode = payloadNode.get(DATA_FIELD); String timeColumnName = datasetConfigDTO.getTimeColumn(); String datasetName = datasetConfigDTO.getDataset(); String metricName = metricConfigDTO.getName(); Preconditions.checkArgument(validateOnlineDetectionData(dataNode, timeColumnName, metricName), String.format("metric: %s or time: %s not found in adhoc data.", metricName, timeColumnName)); OnlineDetectionDataDTO onlineDetectionDataDTO = new OnlineDetectionDataDTO(); onlineDetectionDataDTO.setDataset(datasetName); onlineDetectionDataDTO.setMetric(metricName); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); onlineDetectionDataDAO.save(onlineDetectionDataDTO); LOG.info("Saved online data with dataset: {} and metric: {}", onlineDetectionDataDTO.getDataset(), onlineDetectionDataDTO.getMetric()); return onlineDetectionDataDTO; } @Inject  AnomalyDetectionResource(UserDashboardResource userDashboardResource); }
AnomalyDetectionResource { OnlineDetectionDataDTO saveOnlineDetectionData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO) throws JsonProcessingException { JsonNode dataNode = payloadNode.get(DATA_FIELD); String timeColumnName = datasetConfigDTO.getTimeColumn(); String datasetName = datasetConfigDTO.getDataset(); String metricName = metricConfigDTO.getName(); Preconditions.checkArgument(validateOnlineDetectionData(dataNode, timeColumnName, metricName), String.format("metric: %s or time: %s not found in adhoc data.", metricName, timeColumnName)); OnlineDetectionDataDTO onlineDetectionDataDTO = new OnlineDetectionDataDTO(); onlineDetectionDataDTO.setDataset(datasetName); onlineDetectionDataDTO.setMetric(metricName); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); onlineDetectionDataDAO.save(onlineDetectionDataDTO); LOG.info("Saved online data with dataset: {} and metric: {}", onlineDetectionDataDTO.getDataset(), onlineDetectionDataDTO.getMetric()); return onlineDetectionDataDTO; } @Inject  AnomalyDetectionResource(UserDashboardResource userDashboardResource); @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Request an anomaly detection online task") Response onlineApi(
          @QueryParam("start") Long start,
          @QueryParam("end") Long end,
          @QueryParam("data-id") Long dataId,
          @ApiParam("jsonPayload") String payload,
          @Auth ThirdEyePrincipal principal); @POST @Path("/data") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Register ad hoc data used in online service and created dataset/metric configs") Response createOnlineData(@ApiParam("jsonPayload") String payload,
      @Auth ThirdEyePrincipal principal); @PUT @Path("/data/{data-id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Update ad hoc data used in online service and corresponding dataset/metric configs") Response updateOnlineData(
      @ApiParam("jsonPayload") String payload,
      @PathParam("data-id") Long dataId,
      @Auth ThirdEyePrincipal principal); @DELETE @Path("/data/{data-id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Delete ad hoc data used in online service and corresponding dataset/metric configs") Response deleteOnlineData(@PathParam("data-id") Long dataId); @GET @Path("/data/{data-id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Get ad hoc data used in online service and corresponding dataset/metric configs") Response getOnlineData(@PathParam("data-id") Long dataId); @POST @Path("/tasks") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.TEXT_PLAIN) @ApiOperation("Submit an anomaly detection task") Response taskSubmitApi(
      @QueryParam("start") long start,
      @QueryParam("end") long end,
      @QueryParam("detection-name") String detectionName); @GET @Path("/task/{task-id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.TEXT_PLAIN) @ApiOperation("Query a task status") Response taskStatusApi(@PathParam("task-id") long taskId); }
AnomalyDetectionResource { OnlineDetectionDataDTO saveOnlineDetectionData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO) throws JsonProcessingException { JsonNode dataNode = payloadNode.get(DATA_FIELD); String timeColumnName = datasetConfigDTO.getTimeColumn(); String datasetName = datasetConfigDTO.getDataset(); String metricName = metricConfigDTO.getName(); Preconditions.checkArgument(validateOnlineDetectionData(dataNode, timeColumnName, metricName), String.format("metric: %s or time: %s not found in adhoc data.", metricName, timeColumnName)); OnlineDetectionDataDTO onlineDetectionDataDTO = new OnlineDetectionDataDTO(); onlineDetectionDataDTO.setDataset(datasetName); onlineDetectionDataDTO.setMetric(metricName); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); onlineDetectionDataDAO.save(onlineDetectionDataDTO); LOG.info("Saved online data with dataset: {} and metric: {}", onlineDetectionDataDTO.getDataset(), onlineDetectionDataDTO.getMetric()); return onlineDetectionDataDTO; } @Inject  AnomalyDetectionResource(UserDashboardResource userDashboardResource); @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Request an anomaly detection online task") Response onlineApi(
          @QueryParam("start") Long start,
          @QueryParam("end") Long end,
          @QueryParam("data-id") Long dataId,
          @ApiParam("jsonPayload") String payload,
          @Auth ThirdEyePrincipal principal); @POST @Path("/data") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Register ad hoc data used in online service and created dataset/metric configs") Response createOnlineData(@ApiParam("jsonPayload") String payload,
      @Auth ThirdEyePrincipal principal); @PUT @Path("/data/{data-id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Update ad hoc data used in online service and corresponding dataset/metric configs") Response updateOnlineData(
      @ApiParam("jsonPayload") String payload,
      @PathParam("data-id") Long dataId,
      @Auth ThirdEyePrincipal principal); @DELETE @Path("/data/{data-id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Delete ad hoc data used in online service and corresponding dataset/metric configs") Response deleteOnlineData(@PathParam("data-id") Long dataId); @GET @Path("/data/{data-id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Get ad hoc data used in online service and corresponding dataset/metric configs") Response getOnlineData(@PathParam("data-id") Long dataId); @POST @Path("/tasks") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.TEXT_PLAIN) @ApiOperation("Submit an anomaly detection task") Response taskSubmitApi(
      @QueryParam("start") long start,
      @QueryParam("end") long end,
      @QueryParam("detection-name") String detectionName); @GET @Path("/task/{task-id}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.TEXT_PLAIN) @ApiOperation("Query a task status") Response taskStatusApi(@PathParam("task-id") long taskId);  }