-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enhance(controller): support virtual host path configuration
- Loading branch information
Showing
9 changed files
with
265 additions
and
8 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
29 changes: 29 additions & 0 deletions
29
server/storage-access-layer/src/main/java/ai/starwhale/mlops/storage/fs/AliyunEnv.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,29 @@ | ||
/* | ||
* 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.fs; | ||
|
||
public class AliyunEnv extends S3Env { | ||
public static final String ENV_EXTRA_S3_CONFIGS = "SW_S3_EXTRA_CONFIGS"; | ||
|
||
public AliyunEnv() { | ||
super(FileSystemEnvType.ALIYUN); | ||
} | ||
|
||
public void setExtraS3Configs(String extraS3Configs) { | ||
this.add(ENV_EXTRA_S3_CONFIGS, extraS3Configs); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
server/storage-access-layer/src/main/java/ai/starwhale/mlops/storage/fs/BotoS3Config.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,37 @@ | ||
/* | ||
* 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.fs; | ||
|
||
/** | ||
* BotoS3Config is for boto3 configuration communicate with starwhale python sdk | ||
* see <a href="https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html">doc of config</a> | ||
*/ | ||
public class BotoS3Config { | ||
public final AddressingStyleType addressingStyle; | ||
|
||
public enum AddressingStyleType { | ||
VIRTUAL, AUTO, PATH | ||
} | ||
|
||
public BotoS3Config(AddressingStyleType addressingStyle) { | ||
this.addressingStyle = addressingStyle; | ||
} | ||
|
||
public String toEnvStr() { | ||
return "{\"addressing_style\": \"" + this.addressingStyle.name().toLowerCase() + "\"}"; | ||
} | ||
} |
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
33 changes: 33 additions & 0 deletions
33
server/storage-access-layer/src/test/java/ai/starwhale/mlops/storage/fs/AliyunEnvTest.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,33 @@ | ||
/* | ||
* 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.fs; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class AliyunEnvTest extends S3EnvTest { | ||
@Test | ||
public void testSet() { | ||
var aliyunEnv = new AliyunEnv(); | ||
assertThat(aliyunEnv.getEnvType(), is(FileStorageEnv.FileSystemEnvType.ALIYUN)); | ||
var conf = randomString(); | ||
aliyunEnv.setExtraS3Configs(conf); | ||
assertThat(mapContains(aliyunEnv.getEnvs(), AliyunEnv.ENV_EXTRA_S3_CONFIGS, conf), is(true)); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
...er/storage-access-layer/src/test/java/ai/starwhale/mlops/storage/fs/BotoS3ConfigTest.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,40 @@ | ||
/* | ||
* 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.fs; | ||
|
||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class BotoS3ConfigTest { | ||
@Test | ||
public void testEnvStr() { | ||
var tests = Map.of( | ||
BotoS3Config.AddressingStyleType.AUTO, "{\"addressing_style\": \"auto\"}", | ||
BotoS3Config.AddressingStyleType.VIRTUAL, "{\"addressing_style\": \"virtual\"}", | ||
BotoS3Config.AddressingStyleType.PATH, "{\"addressing_style\": \"path\"}" | ||
); | ||
|
||
tests.forEach((BotoS3Config.AddressingStyleType t, String expect) -> { | ||
var botoS3Config = new BotoS3Config(t); | ||
assertThat(botoS3Config.toEnvStr(), is(expect)); | ||
}); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
server/storage-access-layer/src/test/java/ai/starwhale/mlops/storage/fs/S3EnvTest.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,59 @@ | ||
/* | ||
* 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.fs; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import java.util.Map; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class S3EnvTest { | ||
@Test | ||
public void testSet() { | ||
var s3Env = new S3Env(); | ||
assertThat(s3Env.getEnvType(), is(FileStorageEnv.FileSystemEnvType.S3)); | ||
var envValue = randomString(); | ||
s3Env.setEndPoint(envValue); | ||
assertThat(mapContains(s3Env.getEnvs(), S3Env.ENV_ENDPOINT, envValue), is(true)); | ||
|
||
envValue = randomString(); | ||
s3Env.setBucket(envValue); | ||
assertThat(mapContains(s3Env.getEnvs(), S3Env.ENV_BUCKET, envValue), is(true)); | ||
|
||
envValue = randomString(); | ||
s3Env.setAccessKey(envValue); | ||
assertThat(mapContains(s3Env.getEnvs(), S3Env.ENV_SECRET_ID, envValue), is(true)); | ||
|
||
envValue = randomString(); | ||
s3Env.setSecret(envValue); | ||
assertThat(mapContains(s3Env.getEnvs(), S3Env.ENV_SECRET_KEY, envValue), is(true)); | ||
|
||
envValue = randomString(); | ||
s3Env.setRegion(envValue); | ||
assertThat(mapContains(s3Env.getEnvs(), S3Env.ENV_REGION, envValue), is(true)); | ||
} | ||
|
||
public String randomString() { | ||
return UUID.randomUUID().toString(); | ||
} | ||
|
||
public boolean mapContains(Map<String, String> map, String key, String val) { | ||
return map.containsKey(key) && map.get(key).equals(val); | ||
} | ||
} |