|
44 | 44 | import org.apache.submarine.commons.utils.SubmarineConfiguration;
|
45 | 45 | import org.apache.submarine.commons.utils.exception.SubmarineRuntimeException;
|
46 | 46 |
|
47 |
| -/** |
48 |
| - * S3(Minio) default client |
49 |
| - */ |
50 |
| -public class Client { |
51 | 47 |
|
52 |
| - /* minio client */ |
53 |
| - public MinioClient minioClient; |
| 48 | +public enum Client { |
| 49 | + DEFAULT(S3Constants.ENDPOINT), CUSTOMER("http://localhost:9000"); |
| 50 | + |
54 | 51 | public static Map<String, Client> clientFactory = new HashMap<String, Client>();
|
| 52 | + private final String endpoint; |
| 53 | + private final MinioClient minioClient; |
55 | 54 |
|
56 |
| - public static Client getClient(String endpoint) { |
57 |
| - Client client = clientFactory.get(endpoint); |
58 |
| - Map<String, Client> clientLocalFactory = clientFactory; |
59 | 55 |
|
60 |
| - if (client == null) { |
61 |
| - synchronized (Client.class) { |
62 |
| - if (client == null) { |
63 |
| - client = new Client(endpoint); |
64 |
| - clientLocalFactory.put(endpoint, client); |
65 |
| - clientFactory = clientLocalFactory; |
66 |
| - } |
67 |
| - } |
| 56 | + static { |
| 57 | + for (Client clientSingleton : Client.values()) { |
| 58 | + clientFactory.put(clientSingleton.endpoint, clientSingleton); |
68 | 59 | }
|
69 |
| - return client; |
70 | 60 | }
|
71 | 61 |
|
72 |
| - public static Client getInstance() { |
73 |
| - return getClient(S3Constants.ENDPOINT); |
| 62 | + Client(String endpoint) { |
| 63 | + this.endpoint = endpoint; |
| 64 | + this.minioClient = MinioClient.builder() |
| 65 | + .endpoint(endpoint) |
| 66 | + .credentials(S3Constants.ACCESSKEY, S3Constants.SECRETKEY) |
| 67 | + .build(); |
74 | 68 | }
|
75 | 69 |
|
76 |
| - public static Client getInstance(String endpoint) { |
77 |
| - return getClient(endpoint); |
| 70 | + public static Client getInstance() { |
| 71 | + return clientFactory.get(S3Constants.ENDPOINT); |
78 | 72 | }
|
79 | 73 |
|
80 |
| - private Client(String endpoint) { |
81 |
| - minioClient = MinioClient.builder() |
82 |
| - .endpoint(endpoint) |
83 |
| - .credentials(S3Constants.ACCESSKEY, S3Constants.SECRETKEY) |
84 |
| - .build(); |
| 74 | + public static Client getInstance(String endpoint) { |
| 75 | + try { |
| 76 | + return clientFactory.get(endpoint); |
| 77 | + } catch (Exception e) { |
| 78 | + throw new SubmarineRuntimeException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), |
| 79 | + e.getMessage()); |
| 80 | + } |
85 | 81 | }
|
86 | 82 |
|
87 | 83 | /**
|
|
0 commit comments