-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controller): support aliyun oss
- Loading branch information
Showing
16 changed files
with
243 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../storage-access-layer/src/main/java/ai/starwhale/mlops/storage/LengthAbleInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2022 Starwhale, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 ai.starwhale.mlops.storage; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class LengthAbleInputStream extends InputStream { | ||
private final InputStream inputStream; | ||
|
||
private final long size; | ||
|
||
public LengthAbleInputStream(InputStream inputStream, long size) { | ||
this.inputStream = inputStream; | ||
this.size = size; | ||
} | ||
|
||
|
||
@Override | ||
public int read() throws IOException { | ||
return this.inputStream.read(); | ||
} | ||
|
||
public long getSize() { | ||
return this.size; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...ess-layer/src/main/java/ai/starwhale/mlops/storage/aliyun/StorageAccessServiceAliyun.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2022 Starwhale, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 ai.starwhale.mlops.storage.aliyun; | ||
|
||
import ai.starwhale.mlops.storage.LengthAbleInputStream; | ||
import ai.starwhale.mlops.storage.StorageAccessService; | ||
import ai.starwhale.mlops.storage.StorageObjectInfo; | ||
import ai.starwhale.mlops.storage.s3.S3Config; | ||
import ai.starwhale.mlops.storage.util.MetaHelper; | ||
import com.aliyun.oss.OSS; | ||
import com.aliyun.oss.OSSClientBuilder; | ||
import com.aliyun.oss.model.GetObjectRequest; | ||
import com.aliyun.oss.model.HeadObjectRequest; | ||
import com.aliyun.oss.model.OSSObjectSummary; | ||
import com.aliyun.oss.model.ObjectMetadata; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.stream.Stream; | ||
|
||
public class StorageAccessServiceAliyun implements StorageAccessService { | ||
final String bucket; | ||
|
||
final OSS ossClient; | ||
|
||
public StorageAccessServiceAliyun(S3Config s3Config) { | ||
this.bucket = s3Config.getBucket(); | ||
this.ossClient = new OSSClientBuilder() | ||
.build(s3Config.getEndpoint(), s3Config.getAccessKey(), s3Config.getSecretKey()); | ||
} | ||
|
||
@Override | ||
public StorageObjectInfo head(String path) throws IOException { | ||
var resp = this.ossClient.headObject(new HeadObjectRequest(this.bucket, path)); | ||
return new StorageObjectInfo(true, resp.getContentLength(), MetaHelper.mapToString(resp.getUserMetadata())); | ||
} | ||
|
||
@Override | ||
public void put(String path, InputStream inputStream, long size) throws IOException { | ||
var meta = new ObjectMetadata(); | ||
meta.setContentLength(size); | ||
this.ossClient.putObject(this.bucket, path, inputStream); | ||
} | ||
|
||
@Override | ||
public void put(String path, byte[] body) throws IOException { | ||
this.ossClient.putObject(this.bucket, path, new ByteArrayInputStream(body)); | ||
} | ||
|
||
@Override | ||
public LengthAbleInputStream get(String path) throws IOException { | ||
var resp = this.ossClient.getObject(this.bucket, path); | ||
return new LengthAbleInputStream(resp.getObjectContent(), resp.getObjectMetadata().getContentLength()); | ||
} | ||
|
||
@Override | ||
public LengthAbleInputStream get(String path, Long offset, Long size) throws IOException { | ||
var req = new GetObjectRequest(bucket, path).withRange(offset, offset + size - 1); | ||
var resp = this.ossClient.getObject(req); | ||
return new LengthAbleInputStream(resp.getObjectContent(), resp.getObjectMetadata().getContentLength()); | ||
} | ||
|
||
@Override | ||
public Stream<String> list(String path) throws IOException { | ||
var resp = this.ossClient.listObjects(this.bucket, path); | ||
return resp.getObjectSummaries().stream().map(OSSObjectSummary::getKey); | ||
} | ||
|
||
@Override | ||
public void delete(String path) throws IOException { | ||
this.ossClient.deleteObject(this.bucket, path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.