Revision 6405
Added by Chris Jones about 13 years ago
src/edu/ucsb/nceas/metacat/dataone/CNReplicationTask.java | ||
---|---|---|
1 |
/** |
|
2 |
* This work was created by participants in the DataONE project, and is |
|
3 |
* jointly copyrighted by participating institutions in DataONE. For |
|
4 |
* more information on DataONE, see our web site at http://dataone.org. |
|
5 |
* |
|
6 |
* Copyright ${year} |
|
7 |
* |
|
8 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
9 |
* you may not use this file except in compliance with the License. |
|
10 |
* You may obtain a copy of the License at |
|
11 |
* |
|
12 |
* http://www.apache.org/licenses/LICENSE-2.0 |
|
13 |
* |
|
14 |
* Unless required by applicable law or agreed to in writing, software |
|
15 |
* distributed under the License is distributed on an "AS IS" BASIS, |
|
16 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
17 |
* See the License for the specific language governing permissions and |
|
18 |
* limitations under the License. |
|
19 |
*/ |
|
20 |
|
|
21 |
package edu.ucsb.nceas.metacat.dataone; |
|
22 |
|
|
23 |
import java.io.Serializable; |
|
24 |
import java.util.concurrent.Callable; |
|
25 |
|
|
26 |
import org.dataone.client.D1Client; |
|
27 |
import org.dataone.client.MNode; |
|
28 |
import org.dataone.configuration.Settings; |
|
29 |
import org.dataone.service.exceptions.InsufficientResources; |
|
30 |
import org.dataone.service.exceptions.InvalidRequest; |
|
31 |
import org.dataone.service.exceptions.NotAuthorized; |
|
32 |
import org.dataone.service.exceptions.NotImplemented; |
|
33 |
import org.dataone.service.exceptions.ServiceFailure; |
|
34 |
import org.dataone.service.exceptions.UnsupportedType; |
|
35 |
import org.dataone.service.types.v1.Identifier; |
|
36 |
import org.dataone.service.types.v1.Node; |
|
37 |
import org.dataone.service.types.v1.Permission; |
|
38 |
import org.dataone.service.types.v1.Session; |
|
39 |
import org.dataone.service.types.v1.Subject; |
|
40 |
import org.dataone.service.types.v1.SystemMetadata; |
|
41 |
|
|
42 |
import com.hazelcast.core.Hazelcast; |
|
43 |
import com.hazelcast.core.HazelcastInstance; |
|
44 |
import com.hazelcast.core.IMap; |
|
45 |
|
|
46 |
/** |
|
47 |
* A single CN replication task to be executed by the CN Replication Service. This |
|
48 |
* applies to replication of system metadata, science metadata, and resource maps |
|
49 |
* across CNs. |
|
50 |
* |
|
51 |
* The task is built when a change occurs in the hzSystemMetadata map in the |
|
52 |
* storage cluster initiated by Metacat for a given PID. If the change involves |
|
53 |
* only modifications to system metadata, those changes will occur in the shared |
|
54 |
* map and in the backing store of the member that owns the map entry. Other |
|
55 |
* members must be updated using this task. Likewise, changes to the system |
|
56 |
* metadata map that involve science metadata creation or changes will be |
|
57 |
* distributed to all members via this task. The same is for OAI-ORE resource maps. |
|
58 |
* |
|
59 |
* @author cjones |
|
60 |
* |
|
61 |
*/ |
|
62 |
public class CNReplicationTask implements Serializable, Callable<String> { |
|
63 |
|
|
64 |
/* The identifier of this task */ |
|
65 |
private String taskid; |
|
66 |
|
|
67 |
/* The identifier of the object to replicate */ |
|
68 |
private String pid; |
|
69 |
|
|
70 |
/* The object format type stated in the system metadata (DATA/METADATA/RESOURCE) */ |
|
71 |
private String formatType; |
|
72 |
|
|
73 |
/* The target Node object */ |
|
74 |
private Node targetNode; |
|
75 |
|
|
76 |
/* The originating Node object */ |
|
77 |
private Node originatingNode; |
|
78 |
|
|
79 |
/* The subject of the target node, extracted from the Node object */ |
|
80 |
private String targetNodeSubject; |
|
81 |
|
|
82 |
/* The subject of the originating node, extracted from the Node object */ |
|
83 |
private String originatingNodeSubject; |
|
84 |
|
|
85 |
/* The permission to be executed (in this case, always 'replicate') */ |
|
86 |
String permission; |
|
87 |
|
|
88 |
/** |
|
89 |
* Constructor - create an empty replication task instance |
|
90 |
*/ |
|
91 |
public CNReplicationTask() { |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Constructor - create a replication task instance |
|
96 |
* |
|
97 |
* @param taskid |
|
98 |
* @param pid |
|
99 |
* @param targetNode |
|
100 |
*/ |
|
101 |
public CNReplicationTask(String taskid, Identifier pid, String formatType, |
|
102 |
Node originatingNode, Node targetNode, |
|
103 |
Permission replicatePermission) { |
|
104 |
|
|
105 |
this.taskid = taskid; |
|
106 |
this.pid = pid.getValue(); |
|
107 |
this.formatType = formatType; |
|
108 |
this.originatingNode = originatingNode; |
|
109 |
this.targetNode = targetNode; |
|
110 |
this.originatingNodeSubject = originatingNode.getSubject(0).getValue(); |
|
111 |
this.targetNodeSubject = targetNode.getSubject(0).getValue(); |
|
112 |
this.permission = replicatePermission.name(); |
|
113 |
|
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Get the task identifier for this task |
|
118 |
* @return the taskid |
|
119 |
*/ |
|
120 |
public String getTaskid() { |
|
121 |
return taskid; |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* Set the task identifier for this task |
|
126 |
* @param taskid the taskid to set |
|
127 |
*/ |
|
128 |
public void setTaskid(String taskid) { |
|
129 |
this.taskid = taskid; |
|
130 |
} |
|
131 |
|
|
132 |
/** |
|
133 |
* Get the object identifier to be replicated |
|
134 |
* @return the pid |
|
135 |
*/ |
|
136 |
public Identifier getPid() { |
|
137 |
Identifier identifier = new Identifier(); |
|
138 |
identifier.setValue(pid); |
|
139 |
return identifier; |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* Set the object identifier to be replicated |
|
144 |
* @param pid the pid to set |
|
145 |
*/ |
|
146 |
public void setPid(Identifier pid) { |
|
147 |
this.pid = pid.getValue(); |
|
148 |
} |
|
149 |
|
|
150 |
|
|
151 |
/** |
|
152 |
* Get the format type of the object to be replicated |
|
153 |
* @return the pid |
|
154 |
*/ |
|
155 |
public String getFormatType() { |
|
156 |
return this.formatType; |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Set the format type of the object to be replicated |
|
162 |
* @param pid the pid to set |
|
163 |
*/ |
|
164 |
public void setFormatType(String formatType) { |
|
165 |
this.formatType = formatType; |
|
166 |
|
|
167 |
} |
|
168 |
|
|
169 |
/** |
|
170 |
* Get the target node |
|
171 |
* @return the targetNode |
|
172 |
*/ |
|
173 |
public Node getTargetNode() { |
|
174 |
return targetNode; |
|
175 |
} |
|
176 |
|
|
177 |
/** |
|
178 |
* Set the target node |
|
179 |
* @param targetNode the targetNode to set |
|
180 |
*/ |
|
181 |
public void setTargetNode(Node targetNode) { |
|
182 |
this.targetNode = targetNode; |
|
183 |
} |
|
184 |
|
|
185 |
/** |
|
186 |
* Get the originating node |
|
187 |
* @return the originatingNode |
|
188 |
*/ |
|
189 |
public Node getOriginatingNode() { |
|
190 |
return originatingNode; |
|
191 |
} |
|
192 |
|
|
193 |
/** |
|
194 |
* Set the originating node |
|
195 |
* @param originatingNode the originatingNode to set |
|
196 |
*/ |
|
197 |
public void setOriginatingNode(Node originatingNode) { |
|
198 |
this.originatingNode = originatingNode; |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* For the given Replication task, return the Subject listed in the target |
|
203 |
* node. Usually used in authorizing a replication event. |
|
204 |
* |
|
205 |
* @return subject - the subject listed in the target Node object as a string |
|
206 |
*/ |
|
207 |
public String getTargetNodeSubject() { |
|
208 |
|
|
209 |
return this.targetNodeSubject; |
|
210 |
|
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Set the target node subject identifying the node |
|
215 |
* @param subject the targetNode subject |
|
216 |
*/ |
|
217 |
public void setTargetNodeSubject(String subject) { |
|
218 |
this.targetNodeSubject = subject; |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* For the given Replication task, return the Subject listed in the target |
|
223 |
* node. Usually used in authorizing a replication event. |
|
224 |
* |
|
225 |
* @return subject - the subject listed in the target Node object as a string |
|
226 |
*/ |
|
227 |
public String getOriginatingNodeSubject() { |
|
228 |
|
|
229 |
return this.originatingNodeSubject; |
|
230 |
|
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* Set the target node subject identifying the node |
|
235 |
* @param subject the targetNode subject |
|
236 |
*/ |
|
237 |
public void setOriginatingNodeSubject(String subject) { |
|
238 |
this.originatingNodeSubject = subject; |
|
239 |
} |
|
240 |
|
|
241 |
/** |
|
242 |
* Get the permission being allowed for this task |
|
243 |
* |
|
244 |
* @return subject - the subject listed in the target Node object |
|
245 |
*/ |
|
246 |
public String getPermission() { |
|
247 |
return this.permission; |
|
248 |
|
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* Set the permission being allowed for this task |
|
253 |
* @param subject the targetNode subject |
|
254 |
*/ |
|
255 |
public void setPermission(Permission permission) { |
|
256 |
this.permission = permission.name(); |
|
257 |
|
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Implement the Callable interface, providing code that initiates replication. |
|
262 |
* |
|
263 |
* @return pid - the identifier of the replicated object upon success |
|
264 |
*/ |
|
265 |
public String call() { |
|
266 |
|
|
267 |
// Get the D1 Hazelcast configuration parameters |
|
268 |
String hzSystemMetadata = |
|
269 |
Settings.getConfiguration().getString("dataone.hazelcast.systemMetadata"); |
|
270 |
|
|
271 |
// get the system metadata for the pid |
|
272 |
IMap<Identifier, SystemMetadata> sysMetaMap = Hazelcast.getMap(hzSystemMetadata); |
|
273 |
|
|
274 |
// TODO: Store the object in Metacat by calling the appropriate class |
|
275 |
|
|
276 |
|
|
277 |
return null; |
|
278 |
} |
|
279 |
|
|
280 |
} |
|
0 | 281 |
Also available in: Unified diff
Add a CNReplicationTask class that will be submitted to the CN storage cluster when there are changes to the object store involving system metadata, science metadata, and resource maps. When a new entry is added to the hzSystemMetadata map, a new data, science metadata, or resource map was added to the VO, and all CN cluster members need to be updated with the object and it's system metadata. This task is executed on each CN to replicate the information. If the event is an update to an existing system metadata entry, it may only involve a change to system metadata, or may involve a change to science metadata as well. The task will return with the PID of the object replicated, be it a sysmeta, scimeta, or resource object. Locking of the PID will be handled by the task.