You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@submarine.apache.org by GitBox <gi...@apache.org> on 2021/12/25 02:28:28 UTC

[GitHub] [submarine] jeff-901 commented on a change in pull request #845: SUBMARINE-1074. S3 client for server

jeff-901 commented on a change in pull request #845:
URL: https://github.com/apache/submarine/pull/845#discussion_r775099168



##########
File path: submarine-server/server-core/src/main/java/org/apache/submarine/server/s3/Client.java
##########
@@ -0,0 +1,175 @@
+/*
+ * 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.submarine.server.s3;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import javax.ws.rs.core.Response;
+import io.minio.GetObjectArgs;
+import io.minio.ListObjectsArgs;
+import io.minio.MinioClient;
+import io.minio.PutObjectArgs;
+import io.minio.RemoveObjectsArgs;
+import io.minio.Result;
+import io.minio.messages.DeleteError;
+import io.minio.messages.DeleteObject;
+import io.minio.messages.Item;
+import org.apache.submarine.commons.utils.exception.SubmarineRuntimeException;
+
+
+public class Client {
+  public MinioClient minioClient;
+
+  public Client() {
+    minioClient = MinioClient.builder()
+        .endpoint(S3Constants.ENDPOINT)
+        .credentials(S3Constants.ACCESSKEY, S3Constants.SECRETKEY)
+        .build();
+  }
+
+  public Client(String endpoint) {
+    minioClient = MinioClient.builder()
+        .endpoint(endpoint)
+        .credentials(S3Constants.ACCESSKEY, S3Constants.SECRETKEY)
+        .build();
+  }
+
+  /**
+   * Get a list of artifact path under the experiment
+   *
+   * @param experimentId experiment id
+   * @return a list of artifact path
+   */
+  public List<String> listArtifactByExperimentId(String experimentId) throws SubmarineRuntimeException {
+    Iterable<Result<Item>> artifactNames = minioClient.listObjects(ListObjectsArgs.builder()
+        .bucket(S3Constants.BUCKET).prefix(experimentId + "/").delimiter("/").build());
+    List<String> response = new ArrayList<>();
+    Iterable<Result<Item>> artifacts;
+    for (Result<Item> artifactName : artifactNames) {
+      try {
+        artifacts = minioClient.listObjects(ListObjectsArgs.builder().bucket(S3Constants.BUCKET)
+            .prefix(artifactName.get().objectName()).delimiter("/").build());
+        for (Result<Item> artifact: artifacts) {
+          response.add("s3://" + S3Constants.BUCKET + "/" + artifact.get().objectName());
+        }
+      } catch (Exception e) {
+        throw new SubmarineRuntimeException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
+          e.getMessage());
+      }
+    }
+    return response;
+  }
+
+  /**
+   * Delete all the artifacts under given experiment name
+   *
+   * @param experimentId experiment id
+   */
+  public void deleteArtifactsByExperiment(String experimentId) {
+    deleteAllArtifactsByFolder(experimentId);
+  }
+
+  /**
+   * Delete all the artifacts under s3://submarine
+   */
+  public void deleteAllArtifacts() {
+    deleteAllArtifactsByFolder("");
+  }
+
+  /**
+   * Download an artifact
+   *
+   * @param path artifact path
+   * @return an array of byte
+   */
+  public byte[] downloadArtifact(String path) {
+    InputStream is;
+    byte[] buffer;
+    int b;
+    try {

Review comment:
       ok




-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@submarine.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org