CollectionsResource implements Managed { @POST @Path("/{collection}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) public Response postConfig(@PathParam("collection") String collection, byte[] configBytes) throws IOException { File collectionDir = new File(rootDir, collection); if (!collectionDir.exists()) { FileUtils.forceMkdir(collectionDir); } File configFile = new File(collectionDir, StarTreeConstants.CONFIG_FILE_NAME); if (!configFile.exists()) { IOUtils.copy(new ByteArrayInputStream(configBytes), new FileOutputStream(configFile)); } else { throw new ConflictException(configFile.getPath()+" already exists. A DELETE of /collections/{collection} is required first"); } return Response.ok().build(); } CollectionsResource(StarTreeManager manager,
                             MetricRegistry metricRegistry,
                             DataUpdateManager dataUpdateManager,
                             File rootDir); @Override void start(); @Override void stop(); @GET List<String> getCollections(); @GET @Path("/{collection}") StarTreeConfig getConfig(@PathParam("collection") String collection); @DELETE @Path("/{collection}") Response deleteCollection(@PathParam("collection") String collection); @POST @Path("/{collection}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) Response postConfig(@PathParam("collection") String collection, byte[] configBytes); @GET @Path("/{collection}/kafkaConfig") byte[] getKafkaConfig(@PathParam("collection") String collection); @POST @Path("/{collection}/kafkaConfig") Response postKafkaConfig(@PathParam("collection") String collection, byte[] kafkaConfigBytes); @DELETE @Path("/{collection}/kafkaConfig") Response deleteKafkaConfig(@PathParam("collection") String collection); @POST @Path("/{collection}/data/{minTime}/{maxTime}") @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Timed Response postData(@PathParam("collection") String collection,
                           @PathParam("minTime") long minTimeMillis,
                           @PathParam("maxTime") long maxTimeMillis,
                           @QueryParam("schedule") @DefaultValue("UNKNOWN") String schedule,
                           InputStream dataBytes); @GET @Path("/{collection}/segments") List<SegmentDescriptor> getSegments(@PathParam("collection") String collection);  }
@Test public void testPostConfig() throws Exception { byte[] configBytes = "Dummy config file".getBytes(); Response postConfigResponse = testCollectionsResource.postConfig(collection, configBytes); Assert.assertEquals(postConfigResponse.getStatus(), Response.Status.OK.getStatusCode()); }
@Test(expectedExceptions = ConflictException.class) public void testPostConfigOverwrite() throws Exception { File collectionDir = new File(rootDir, collection); if (!collectionDir.exists()) { FileUtils.forceMkdir(collectionDir); } File configFile = new File(collectionDir, StarTreeConstants.CONFIG_FILE_NAME); FileUtils.writeByteArrayToFile(configFile, "Dummy existing config file".getBytes()); byte[] configBytes = "Dummy config file to overwrite".getBytes(); Response postConfigResponse = testCollectionsResource.postConfig(collection, configBytes); }