@Test public void testTranslateMetricToYaml() { DatasetConfigDTO datasetConfigDTO = new DatasetConfigDTO(); datasetConfigDTO.setTimeColumn("timeCol"); datasetConfigDTO.setTimeUnit(TimeUnit.DAYS); datasetConfigDTO.setTimeDuration(1); datasetConfigDTO.setTimeFormat("SIMPLE_DATE_FORMAT:yyyyMMdd"); datasetConfigDTO.setTimezone("US/Pacific"); String datasetConfigYaml = this.anomalyDetectionResource.translateDatasetToYaml(datasetConfigDTO); Map<String, Object> restoredConfigs = ConfigUtils.getMap(yaml.load(datasetConfigYaml)); Assert.assertTrue(restoredConfigs.containsKey("timeColumn") && restoredConfigs.get("timeColumn").equals("timeCol"), "Incorrect timeColumn: " + restoredConfigs.get("timeColumn")); Assert.assertTrue(restoredConfigs.containsKey("timeUnit") && restoredConfigs.get("timeUnit").equals("DAYS"), "Incorrect timeUnit: " + restoredConfigs.get("timeUnit")); Assert.assertTrue(restoredConfigs.containsKey("timeDuration") && (restoredConfigs.get("timeDuration")).equals("1"), "Incorrect timeDuration: " + restoredConfigs.get("timeDuration")); Assert.assertTrue(restoredConfigs.containsKey("timeFormat") && restoredConfigs.get("timeFormat").equals("SIMPLE_DATE_FORMAT:yyyyMMdd"), "Incorrect timeFormat: " + restoredConfigs.get("timeFormat")); Assert.assertTrue(restoredConfigs.containsKey("timezone") && restoredConfigs.get("timezone").equals("US/Pacific"), "Incorrect timezone: " + restoredConfigs.get("timezone")); }
String translateMetricToYaml(MetricConfigDTO metricConfigDTO) { Map<String, String> configurations = new HashMap<>(); configurations.put(METRIC_CONFIG_DATA_TYPE, metricConfigDTO.getDatatype().toString()); configurations.put(METRIC_CONFIG_METRIC_COLUMN, metricConfigDTO.getName()); return yaml.dump(configurations); }
AnomalyDetectionResource { String translateMetricToYaml(MetricConfigDTO metricConfigDTO) { Map<String, String> configurations = new HashMap<>(); configurations.put(METRIC_CONFIG_DATA_TYPE, metricConfigDTO.getDatatype().toString()); configurations.put(METRIC_CONFIG_METRIC_COLUMN, metricConfigDTO.getName()); return yaml.dump(configurations); } }
AnomalyDetectionResource { String translateMetricToYaml(MetricConfigDTO metricConfigDTO) { Map<String, String> configurations = new HashMap<>(); configurations.put(METRIC_CONFIG_DATA_TYPE, metricConfigDTO.getDatatype().toString()); configurations.put(METRIC_CONFIG_METRIC_COLUMN, metricConfigDTO.getName()); return yaml.dump(configurations); } @Inject  AnomalyDetectionResource(UserDashboardResource userDashboardResource); }
AnomalyDetectionResource { String translateMetricToYaml(MetricConfigDTO metricConfigDTO) { Map<String, String> configurations = new HashMap<>(); configurations.put(METRIC_CONFIG_DATA_TYPE, metricConfigDTO.getDatatype().toString()); configurations.put(METRIC_CONFIG_METRIC_COLUMN, metricConfigDTO.getName()); return yaml.dump(configurations); } @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 { String translateMetricToYaml(MetricConfigDTO metricConfigDTO) { Map<String, String> configurations = new HashMap<>(); configurations.put(METRIC_CONFIG_DATA_TYPE, metricConfigDTO.getDatatype().toString()); configurations.put(METRIC_CONFIG_METRIC_COLUMN, metricConfigDTO.getName()); return yaml.dump(configurations); } @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);  }