@Test public void testDoUpdateOnlineData() throws Exception { String initPayload = IOUtils.toString(this.getClass().getResourceAsStream("payload-good.json")); JsonNode initNode = this.objectMapper.readTree(initPayload); String updatePayload; JsonNode updateNode; OnlineDetectionDataDTO onlineDetectionDataDTO; updatePayload = IOUtils.toString(this.getClass().getResourceAsStream("payload-update-test1.json")); updateNode = this.objectMapper.readTree(updatePayload); onlineDetectionDataDTO = updateOnlineDataWithPayload(initNode, updateNode); checkUpdate(onlineDetectionDataDTO, "time_update", "online_metric", 3); updatePayload = IOUtils.toString(this.getClass().getResourceAsStream("payload-update-test2.json")); updateNode = this.objectMapper.readTree(updatePayload); onlineDetectionDataDTO = updateOnlineDataWithPayload(initNode, updateNode); checkUpdate(onlineDetectionDataDTO, "date", "metric_update", 3); updatePayload = IOUtils.toString(this.getClass().getResourceAsStream("payload-update-test3.json")); updateNode = this.objectMapper.readTree(updatePayload); onlineDetectionDataDTO = updateOnlineDataWithPayload(initNode, updateNode); checkUpdate(onlineDetectionDataDTO, "time_update", "metric_update", 5); }
OnlineDetectionDataDTO doUpdateOnlineData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO, OnlineDetectionDataDTO onlineDetectionDataDTO) throws JsonProcessingException { if (payloadNode.has(DATASET_FIELD)) { updateDatasetCustomFields(payloadNode, datasetConfigDTO); LOG.info("Update dataset config to {}", datasetConfigDTO); } if (payloadNode.has(METRIC_FIELD)) { updateMetricCustomFields(payloadNode, metricConfigDTO); onlineDetectionDataDTO.setMetric(metricConfigDTO.getName()); LOG.info("Update metric config to {}", metricConfigDTO); } JsonNode dataNode = payloadNode.get(DATA_FIELD); Preconditions.checkArgument( validateOnlineDetectionData(dataNode, datasetConfigDTO.getTimeColumn(), metricConfigDTO.getName()), String.format("metric: %s or time: %s not found in adhoc data.", metricConfigDTO.getName(), datasetConfigDTO.getTimeColumn())); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); datasetConfigDAO.update(datasetConfigDTO); metricConfigDAO.update(metricConfigDTO); onlineDetectionDataDAO.update(onlineDetectionDataDTO); LOG.info("Save updated online detection data for {}", onlineDetectionDataDTO.getId()); return onlineDetectionDataDTO; }
AnomalyDetectionResource { OnlineDetectionDataDTO doUpdateOnlineData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO, OnlineDetectionDataDTO onlineDetectionDataDTO) throws JsonProcessingException { if (payloadNode.has(DATASET_FIELD)) { updateDatasetCustomFields(payloadNode, datasetConfigDTO); LOG.info("Update dataset config to {}", datasetConfigDTO); } if (payloadNode.has(METRIC_FIELD)) { updateMetricCustomFields(payloadNode, metricConfigDTO); onlineDetectionDataDTO.setMetric(metricConfigDTO.getName()); LOG.info("Update metric config to {}", metricConfigDTO); } JsonNode dataNode = payloadNode.get(DATA_FIELD); Preconditions.checkArgument( validateOnlineDetectionData(dataNode, datasetConfigDTO.getTimeColumn(), metricConfigDTO.getName()), String.format("metric: %s or time: %s not found in adhoc data.", metricConfigDTO.getName(), datasetConfigDTO.getTimeColumn())); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); datasetConfigDAO.update(datasetConfigDTO); metricConfigDAO.update(metricConfigDTO); onlineDetectionDataDAO.update(onlineDetectionDataDTO); LOG.info("Save updated online detection data for {}", onlineDetectionDataDTO.getId()); return onlineDetectionDataDTO; } }
AnomalyDetectionResource { OnlineDetectionDataDTO doUpdateOnlineData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO, OnlineDetectionDataDTO onlineDetectionDataDTO) throws JsonProcessingException { if (payloadNode.has(DATASET_FIELD)) { updateDatasetCustomFields(payloadNode, datasetConfigDTO); LOG.info("Update dataset config to {}", datasetConfigDTO); } if (payloadNode.has(METRIC_FIELD)) { updateMetricCustomFields(payloadNode, metricConfigDTO); onlineDetectionDataDTO.setMetric(metricConfigDTO.getName()); LOG.info("Update metric config to {}", metricConfigDTO); } JsonNode dataNode = payloadNode.get(DATA_FIELD); Preconditions.checkArgument( validateOnlineDetectionData(dataNode, datasetConfigDTO.getTimeColumn(), metricConfigDTO.getName()), String.format("metric: %s or time: %s not found in adhoc data.", metricConfigDTO.getName(), datasetConfigDTO.getTimeColumn())); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); datasetConfigDAO.update(datasetConfigDTO); metricConfigDAO.update(metricConfigDTO); onlineDetectionDataDAO.update(onlineDetectionDataDTO); LOG.info("Save updated online detection data for {}", onlineDetectionDataDTO.getId()); return onlineDetectionDataDTO; } @Inject  AnomalyDetectionResource(UserDashboardResource userDashboardResource); }
AnomalyDetectionResource { OnlineDetectionDataDTO doUpdateOnlineData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO, OnlineDetectionDataDTO onlineDetectionDataDTO) throws JsonProcessingException { if (payloadNode.has(DATASET_FIELD)) { updateDatasetCustomFields(payloadNode, datasetConfigDTO); LOG.info("Update dataset config to {}", datasetConfigDTO); } if (payloadNode.has(METRIC_FIELD)) { updateMetricCustomFields(payloadNode, metricConfigDTO); onlineDetectionDataDTO.setMetric(metricConfigDTO.getName()); LOG.info("Update metric config to {}", metricConfigDTO); } JsonNode dataNode = payloadNode.get(DATA_FIELD); Preconditions.checkArgument( validateOnlineDetectionData(dataNode, datasetConfigDTO.getTimeColumn(), metricConfigDTO.getName()), String.format("metric: %s or time: %s not found in adhoc data.", metricConfigDTO.getName(), datasetConfigDTO.getTimeColumn())); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); datasetConfigDAO.update(datasetConfigDTO); metricConfigDAO.update(metricConfigDTO); onlineDetectionDataDAO.update(onlineDetectionDataDTO); LOG.info("Save updated online detection data for {}", onlineDetectionDataDTO.getId()); 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 doUpdateOnlineData(JsonNode payloadNode, DatasetConfigDTO datasetConfigDTO, MetricConfigDTO metricConfigDTO, OnlineDetectionDataDTO onlineDetectionDataDTO) throws JsonProcessingException { if (payloadNode.has(DATASET_FIELD)) { updateDatasetCustomFields(payloadNode, datasetConfigDTO); LOG.info("Update dataset config to {}", datasetConfigDTO); } if (payloadNode.has(METRIC_FIELD)) { updateMetricCustomFields(payloadNode, metricConfigDTO); onlineDetectionDataDTO.setMetric(metricConfigDTO.getName()); LOG.info("Update metric config to {}", metricConfigDTO); } JsonNode dataNode = payloadNode.get(DATA_FIELD); Preconditions.checkArgument( validateOnlineDetectionData(dataNode, datasetConfigDTO.getTimeColumn(), metricConfigDTO.getName()), String.format("metric: %s or time: %s not found in adhoc data.", metricConfigDTO.getName(), datasetConfigDTO.getTimeColumn())); onlineDetectionDataDTO.setOnlineDetectionData(this.objectMapper.writeValueAsString(dataNode)); datasetConfigDAO.update(datasetConfigDTO); metricConfigDAO.update(metricConfigDTO); onlineDetectionDataDAO.update(onlineDetectionDataDTO); LOG.info("Save updated online detection data for {}", onlineDetectionDataDTO.getId()); 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);  }