jihoonson commented on a change in pull request #8088: Add intermediary data 
server for shuffle
URL: https://github.com/apache/incubator-druid/pull/8088#discussion_r304107143
 
 

 ##########
 File path: 
indexing-service/src/main/java/org/apache/druid/indexing/worker/http/ShuffleResource.java
 ##########
 @@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.indexing.worker.http;
+
+import com.google.common.io.ByteStreams;
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.indexing.worker.IntermediaryDataManager;
+import org.apache.druid.java.util.common.DateTimes;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.http.security.TaskShuffleResourceFilter;
+import org.joda.time.Interval;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.StreamingOutput;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.List;
+
+@Path("/druid/worker/v1/shuffle")
+@ResourceFilters(TaskShuffleResourceFilter.class)
+public class ShuffleResource
+{
+  private static final Logger log = new Logger(ShuffleResource.class);
+
+  private final IntermediaryDataManager intermediaryDataManager;
+
+  @Inject
+  public ShuffleResource(IntermediaryDataManager intermediaryDataManager)
+  {
+    this.intermediaryDataManager = intermediaryDataManager;
+  }
+
+  @GET
+  @Path("/task/{supervisorTaskId}/partition")
+  @Produces(MediaType.APPLICATION_OCTET_STREAM)
+  public Response getPartition(
+      @PathParam("supervisorTaskId") String supervisorTaskId,
+      @QueryParam("dataSource") String dataSource,
+      @QueryParam("startTime") String startTime,
+      @QueryParam("endTime") String endTime,
+      @QueryParam("partitionId") int partitionId
+  )
+  {
+    final Interval interval = new Interval(DateTimes.of(startTime), 
DateTimes.of(endTime));
+    final List<File> partitionFiles = 
intermediaryDataManager.findPartitionFiles(
+        supervisorTaskId,
+        interval,
+        partitionId
+    );
+
+    if (partitionFiles.isEmpty()) {
+      final String errorMessage = StringUtils.format(
+          "Can't find the partition for supervisor[%s], interval[%s], and 
partitionId[%s]",
+          supervisorTaskId,
+          interval,
+          partitionId
+      );
+      return Response.status(Status.NOT_FOUND).entity(errorMessage).build();
+    } else {
+      return Response.ok(
+          (StreamingOutput) output -> {
+            for (File partitionFile : partitionFiles) {
+              try (final FileInputStream fileInputStream = new 
FileInputStream(partitionFile)) {
+                ByteStreams.copy(fileInputStream, output);
+              }
+            }
+          }
+      ).build();
+    }
+  }
+
+  @DELETE
+  @Path("/task/{supervisorTaskId}")
+  public Response deletePartitions(
+      @PathParam("supervisorTaskId") String supervisorTaskId,
+      @QueryParam("dataSource") String dataSource
 
 Review comment:
   It's.. used in `TaskShuffleResourceFilter` to check authorization. I know 
this is weird and, ideally, the resourceFilter should check authorization for 
task data instead of dataSource. However, the current security system only 
supports dataSource-level authorization. Added a comment.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to