-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOMMultipartupload.java
163 lines (125 loc) · 4.2 KB
/
OMMultipartupload.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/**
* 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.hadoop.ozone.om.helpers;
import java.time.Instant;
import org.apache.hadoop.hdds.client.ReplicationConfig;
import static org.apache.hadoop.ozone.OzoneConsts.OM_KEY_PREFIX;
/**
* Information about one initialized upload.
*/
public class OmMultipartUpload {
private String volumeName;
private String bucketName;
private String keyName;
private String uploadId;
private Instant creationTime;
private ReplicationConfig replicationConfig;
public OmMultipartUpload(Builder objectBuild) {
this.volumeName = objectBuild.volumeName;
this.bucketName = objectBuild.bucketName;
this.keyName = objectBuild.keyName;
this.uploadId = objectBuild.uploadId;
this.creationTime = objectBuild.creationTime;
this.replicationConfig = objectBuild.replicationConfig;
}
public static OmMultipartUpload from(String key) {
String[] split = key.split(OM_KEY_PREFIX);
if (split.length < 5) {
throw new IllegalArgumentException("Key " + key
+ " doesn't have enough segments to be a valid multipart upload key");
}
String uploadId = split[split.length - 1];
String volume = split[1];
String bucket = split[2];
return new OmMultipartUpload.Builder()
.setVolumeName(volume)
.setBucketName(bucket)
.setKeyName(key.substring(volume.length() + bucket.length() + 3,
key.length() - uploadId.length() - 1))
.setUploadID(uploadId).build();
}
public String getDbKey() {
return OmMultipartUpload
.getDbKey(volumeName, bucketName, keyName, uploadId);
}
public static String getDbKey(String volume, String bucket, String key,
String uploadId) {
return getDbKey(volume, bucket, key) + OM_KEY_PREFIX + uploadId;
}
public static String getDbKey(String volume, String bucket, String key) {
return OM_KEY_PREFIX + volume + OM_KEY_PREFIX + bucket +
OM_KEY_PREFIX + key;
}
public String getVolumeName() {
return volumeName;
}
public String getBucketName() {
return bucketName;
}
public String getKeyName() {
return keyName;
}
public String getUploadId() {
return uploadId;
}
public Instant getCreationTime() {
return creationTime;
}
public ReplicationConfig getReplicationConfig() {
return replicationConfig;
}
/**
* Builder class of OmMultipartUpload.
*/
public static class Builder {
private String volumeName;
private String bucketName;
private String keyName;
private String uploadId;
private Instant creationTime;
private ReplicationConfig replicationConfig;
public Builder setVolumeName(String volumename) {
this.volumeName = volumename;
return this;
}
public Builder setBucketName(String bucketname) {
this.bucketName = bucketname;
return this;
}
public Builder setKeyName(String keyname) {
this.keyName = keyname;
return this;
}
public Builder setUploadID(String uploadId) {
this.uploadId = uploadId;
return this;
}
public Builder setCreationTime(Instant creationtime) {
this.creationTime = creationtime;
return this;
}
public Builder setReplicationConfig(ReplicationConfig replicationconfig) {
this.replicationConfig = replicationconfig;
return this;
}
//Return the final constructed builder object
public OmMultipartUpload build() {
return new OmMultipartUpload(this);
}
}
}