|
16 | 16 | package com.obs.services; |
17 | 17 |
|
18 | 18 | import java.util.List; |
| 19 | +import java.util.function.Function; |
| 20 | +import java.util.function.Supplier; |
19 | 21 |
|
20 | 22 | import com.obs.services.exception.ObsException; |
| 23 | +import com.obs.services.internal.ObsConstraint; |
21 | 24 | import com.obs.services.internal.ServiceException; |
22 | 25 | import com.obs.services.internal.utils.ServiceUtils; |
23 | 26 | import com.obs.services.model.AccessControlList; |
|
34 | 37 | import com.obs.services.model.BucketStoragePolicyConfiguration; |
35 | 38 | import com.obs.services.model.BucketVersioningConfiguration; |
36 | 39 | import com.obs.services.model.CreateBucketRequest; |
| 40 | +import com.obs.services.model.CreateSnapshotRequest; |
| 41 | +import com.obs.services.model.CreateSnapshotResponse; |
37 | 42 | import com.obs.services.model.CreateVirtualBucketRequest; |
38 | 43 | import com.obs.services.model.CreateVirtualBucketResult; |
39 | 44 | import com.obs.services.model.CustomDomainCertificateConfig; |
40 | 45 | import com.obs.services.model.DeleteBucketCustomDomainRequest; |
| 46 | +import com.obs.services.model.DeleteBucketLifecycleRequest; |
| 47 | +import com.obs.services.model.DeleteSnapshotRequest; |
41 | 48 | import com.obs.services.model.GetBucketCustomDomainRequest; |
| 49 | +import com.obs.services.model.GetSnapshottableDirListRequest; |
| 50 | +import com.obs.services.model.GetSnapshottableDirListResult; |
| 51 | +import com.obs.services.model.GetSnapshotListRequest; |
| 52 | +import com.obs.services.model.GetSnapshotListResponse; |
42 | 53 | import com.obs.services.model.HeaderResponse; |
43 | 54 | import com.obs.services.model.ListBucketAliasResult; |
44 | 55 | import com.obs.services.model.ListBucketsRequest; |
45 | 56 | import com.obs.services.model.ListBucketsResult; |
46 | 57 | import com.obs.services.model.ObsBucket; |
| 58 | +import com.obs.services.model.Qos.DeleteBucketQosRequest; |
| 59 | +import com.obs.services.model.Qos.GetBucketQoSRequest; |
| 60 | +import com.obs.services.model.Qos.GetBucketQoSResult; |
| 61 | +import com.obs.services.model.Qos.SetBucketQosRequest; |
| 62 | +import com.obs.services.model.Qos.QosRule; |
| 63 | +import com.obs.services.model.RenameSnapshotRequest; |
| 64 | +import com.obs.services.model.RenameSnapshotResponse; |
47 | 65 | import com.obs.services.model.RequestPaymentConfiguration; |
48 | 66 | import com.obs.services.model.RequestPaymentEnum; |
49 | 67 | import com.obs.services.model.SetBucketAclRequest; |
|
54 | 72 | import com.obs.services.model.SetBucketRequestPaymentRequest; |
55 | 73 | import com.obs.services.model.SetBucketStoragePolicyRequest; |
56 | 74 | import com.obs.services.model.SetBucketVersioningRequest; |
| 75 | +import com.obs.services.model.SetDisallowSnapshotRequest; |
| 76 | +import com.obs.services.model.SetSnapshotAllowRequest; |
57 | 77 | import com.obs.services.model.inventory.SetInventoryConfigurationRequest; |
58 | 78 | import com.obs.services.model.inventory.GetInventoryConfigurationRequest; |
59 | 79 | import com.obs.services.model.inventory.DeleteInventoryConfigurationRequest; |
60 | 80 | import com.obs.services.model.inventory.ListInventoryConfigurationRequest; |
61 | 81 | import com.obs.services.model.inventory.GetInventoryConfigurationResult; |
62 | 82 | import com.obs.services.model.inventory.ListInventoryConfigurationResult; |
63 | 83 |
|
| 84 | +import static com.obs.services.internal.ObsConstraint.SNAPSHOT; |
| 85 | +import static com.obs.services.internal.ObsConstraint.SNAPSHOT_FULL_PATH; |
| 86 | + |
64 | 87 |
|
65 | 88 | public abstract class AbstractBucketClient extends AbstractDeprecatedBucketClient { |
| 89 | + |
| 90 | + private <T, R> T executeAction(String actionName, |
| 91 | + R request, |
| 92 | + Function<R, String> nameExtractor, |
| 93 | + Runnable additionalValidation, |
| 94 | + Supplier<T> implementation) throws ObsException { |
| 95 | + ServiceUtils.assertParameterNotNull(request, "request is null"); |
| 96 | + |
| 97 | + String bucketName = nameExtractor.apply(request); |
| 98 | + ServiceUtils.assertParameterNotNull2(bucketName, "bucketName is null"); |
| 99 | + |
| 100 | + if (additionalValidation != null) { |
| 101 | + additionalValidation.run(); |
| 102 | + } |
| 103 | + return this.doActionWithResult(actionName, bucketName, |
| 104 | + new ActionCallbackWithResult<T>() { |
| 105 | + @Override |
| 106 | + public T action() throws ServiceException { |
| 107 | + return implementation.get(); |
| 108 | + } |
| 109 | + }); |
| 110 | + } |
| 111 | + |
66 | 112 | /* |
67 | 113 | * (non-Javadoc) |
68 | 114 | * |
@@ -987,4 +1033,140 @@ public HeaderResponse action() throws ServiceException { |
987 | 1033 | }); |
988 | 1034 |
|
989 | 1035 | } |
| 1036 | + |
| 1037 | + @Override |
| 1038 | + public HeaderResponse setBucketQos(SetBucketQosRequest request) throws ObsException { |
| 1039 | + ServiceUtils.assertParameterNotNull(request,"setBucketQosRequest is null"); |
| 1040 | + ServiceUtils.assertParameterNotNull(request.getBucketName(),"bucketName is null"); |
| 1041 | + ServiceUtils.assertParameterNotNull(request.getQosConfig(),"QosConfig is null"); |
| 1042 | + ServiceUtils.assertParameterNotNull(request.getQosConfig().getRules(),"rules is null"); |
| 1043 | + |
| 1044 | + List<QosRule> rules = request.getQosConfig().getRules(); |
| 1045 | + |
| 1046 | + if (rules.isEmpty()) { |
| 1047 | + throw new IllegalArgumentException("rules is empty"); |
| 1048 | + } |
| 1049 | + |
| 1050 | + for (QosRule rule : rules) { |
| 1051 | + ServiceUtils.assertParameterNotNull(rule.getNetworkType(), "networkType is null"); |
| 1052 | + ServiceUtils.assertParameterNotNull(rule.getQpsLimit(), "qpsLimit is null"); |
| 1053 | + ServiceUtils.assertParameterNotNull(rule.getBpsLimit(), "bpsLimit is null"); |
| 1054 | + } |
| 1055 | + return this.doActionWithResult("setBucketQoS", request.getBucketName(), |
| 1056 | + new ActionCallbackWithResult<HeaderResponse>() { |
| 1057 | + @Override |
| 1058 | + public HeaderResponse action() throws ServiceException { |
| 1059 | + return AbstractBucketClient.this.setBucketQosImpl(request); |
| 1060 | + } |
| 1061 | + }); |
| 1062 | + } |
| 1063 | + |
| 1064 | + @Override |
| 1065 | + public GetBucketQoSResult getBucketQoS(GetBucketQoSRequest request) { |
| 1066 | + ServiceUtils.assertParameterNotNull(request.getBucketName(), "bucketName is null"); |
| 1067 | + return this.doActionWithResult("getBucketQos", request.getBucketName(), new ActionCallbackWithResult<GetBucketQoSResult>() { |
| 1068 | + @Override |
| 1069 | + public GetBucketQoSResult action() throws ServiceException { |
| 1070 | + return AbstractBucketClient.this.getBucketQosImpl(request); |
| 1071 | + } |
| 1072 | + }); |
| 1073 | + } |
| 1074 | + @Override |
| 1075 | + public HeaderResponse deleteBucketQoS(DeleteBucketQosRequest request) throws ObsException{ |
| 1076 | + ServiceUtils.assertParameterNotNull(request.getBucketName(),"bucketName is null"); |
| 1077 | + return this.doActionWithResult("deleteBucketQos", request.getBucketName(), new ActionCallbackWithResult<HeaderResponse>() { |
| 1078 | + @Override |
| 1079 | + public HeaderResponse action() throws ServiceException { |
| 1080 | + return AbstractBucketClient.this.deleteBucketQosImpl(request); |
| 1081 | + } |
| 1082 | + }); |
| 1083 | + } |
| 1084 | + |
| 1085 | + public HeaderResponse deleteSnapshot(DeleteSnapshotRequest request) throws ObsException { |
| 1086 | + return executeAction("deleteSnapshot", request, DeleteSnapshotRequest::getBucketName, |
| 1087 | + () -> { |
| 1088 | + ServiceUtils.assertParameterNotNull2(request.getObjectKey(), "objectKey is null"); |
| 1089 | + ServiceUtils.assertParameterNotNull2(request.getSnapshotName(), "snapshotName is null"); |
| 1090 | + }, |
| 1091 | + () -> AbstractBucketClient.this.deleteSnapshotImpl(request) |
| 1092 | + ); |
| 1093 | + } |
| 1094 | + |
| 1095 | + @Override |
| 1096 | + public HeaderResponse setSnapshotAllow(SetSnapshotAllowRequest request) throws ObsException { |
| 1097 | + return executeAction("setSnapshotAllow", request, SetSnapshotAllowRequest::getBucketName, |
| 1098 | + () -> { |
| 1099 | + ServiceUtils.assertParameterNotNull2(request.getObjectKey(), "objectKey is null"); |
| 1100 | + }, |
| 1101 | + () -> AbstractBucketClient.this.setSnapshotAllowImpl(request) |
| 1102 | + ); |
| 1103 | + } |
| 1104 | + |
| 1105 | + @Override |
| 1106 | + public HeaderResponse setDisallowSnapshot(SetDisallowSnapshotRequest request) throws ObsException { |
| 1107 | + return executeAction("setDisallowSnapshot", request, SetDisallowSnapshotRequest::getBucketName, |
| 1108 | + () -> { |
| 1109 | + ServiceUtils.assertParameterNotNull2(request.getObjectKey(), "objectKey is null"); |
| 1110 | + }, |
| 1111 | + () -> AbstractBucketClient.this.setDisallowSnapshotImpl(request) |
| 1112 | + ); |
| 1113 | + } |
| 1114 | + |
| 1115 | + @Override |
| 1116 | + public GetSnapshottableDirListResult getSnapshottableDirList(GetSnapshottableDirListRequest request) throws ObsException { |
| 1117 | + return executeAction("getSnapshottableDirList", request, GetSnapshottableDirListRequest::getBucketName, |
| 1118 | + () -> { |
| 1119 | + ServiceUtils.assertParameterNotNegative(request.getMaxKeys(), "maxKeys is negative"); |
| 1120 | + }, |
| 1121 | + () -> AbstractBucketClient.this.getSnapshottableDirListImpl(request) |
| 1122 | + ); |
| 1123 | + } |
| 1124 | + |
| 1125 | + /** |
| 1126 | + * Get snapshot list for a bucket or object |
| 1127 | + */ |
| 1128 | + @Override |
| 1129 | + public GetSnapshotListResponse getSnapshotList(GetSnapshotListRequest request) throws ObsException { |
| 1130 | + return executeAction("getSnapshotList", request, GetSnapshotListRequest::getBucketName, |
| 1131 | + () -> { |
| 1132 | + ServiceUtils.assertParameterNotNegative(request.getMaxKeys(), "maxKeys is negative"); |
| 1133 | + }, |
| 1134 | + () -> AbstractBucketClient.this.getSnapshotListImpl(request) |
| 1135 | + ); |
| 1136 | + } |
| 1137 | + |
| 1138 | + /** |
| 1139 | + * Create snapshot for an object |
| 1140 | + */ |
| 1141 | + @Override |
| 1142 | + public CreateSnapshotResponse createSnapshot(CreateSnapshotRequest request) throws ObsException { |
| 1143 | + return executeAction("createSnapshot", request, CreateSnapshotRequest::getBucketName, |
| 1144 | + () -> { |
| 1145 | + ServiceUtils.assertParameterNotNull2(request.getObjectKey(), "objectKey is null"); |
| 1146 | + ServiceUtils.assertParameterNotNull2(request.getSnapshotName(), "snapshotName is null"); |
| 1147 | + ServiceUtils.checkParameterLength(SNAPSHOT, request.getSnapshotName(), |
| 1148 | + 1, ObsConstraint.SNAPSHOT_NAME_MAX_LENGTH); |
| 1149 | + ServiceUtils.checkParameterLength(SNAPSHOT_FULL_PATH, request.getObjectKey(), |
| 1150 | + 1, ObsConstraint.SNAPSHOT_FULL_PATH_MAX_LENGTH); |
| 1151 | + }, |
| 1152 | + () -> AbstractBucketClient.this.createSnapshotImpl(request) |
| 1153 | + ); |
| 1154 | + } |
| 1155 | + |
| 1156 | + /** |
| 1157 | + * Rename snapshot for an object |
| 1158 | + */ |
| 1159 | + @Override |
| 1160 | + public RenameSnapshotResponse renameSnapshot(RenameSnapshotRequest request) throws ObsException { |
| 1161 | + return executeAction("renameSnapshot", request, RenameSnapshotRequest::getBucketName, |
| 1162 | + () -> { |
| 1163 | + ServiceUtils.assertParameterNotNull2(request.getObjectKey(), "objectKey is null"); |
| 1164 | + ServiceUtils.assertParameterNotNull2(request.getOldSnapshotName(), "oldSnapshotName is null"); |
| 1165 | + ServiceUtils.assertParameterNotNull2(request.getNewSnapshotName(), "newSnapshotName is null"); |
| 1166 | + }, |
| 1167 | + () -> AbstractBucketClient.this.renameSnapshotImpl(request) |
| 1168 | + ); |
| 1169 | + } |
| 1170 | + |
| 1171 | + public abstract HeaderResponse deleteBucketLifecycle(DeleteBucketLifecycleRequest request) throws ObsException; |
990 | 1172 | } |
0 commit comments