69 |
69 |
import org.dataone.service.types.v1.Subject;
|
70 |
70 |
import org.dataone.service.types.v1.SystemMetadata;
|
71 |
71 |
|
|
72 |
import com.hazelcast.core.ILock;
|
|
73 |
|
72 |
74 |
import edu.ucsb.nceas.metacat.EventLog;
|
73 |
75 |
import edu.ucsb.nceas.metacat.IdentifierManager;
|
74 |
76 |
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
|
... | ... | |
123 |
125 |
throws NotImplemented, NotFound, NotAuthorized, ServiceFailure,
|
124 |
126 |
InvalidRequest, InvalidToken {
|
125 |
127 |
|
|
128 |
// The lock to be used for thyis identifier
|
|
129 |
ILock lock = null;
|
|
130 |
|
126 |
131 |
// get the subject
|
127 |
132 |
Subject subject = session.getSubject();
|
128 |
133 |
|
... | ... | |
134 |
139 |
|
135 |
140 |
SystemMetadata systemMetadata = null;
|
136 |
141 |
try {
|
137 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
142 |
lock = HazelcastService.getInstance().getLock(pid);
|
|
143 |
lock.lock();
|
138 |
144 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
|
139 |
145 |
|
140 |
146 |
|
... | ... | |
160 |
166 |
systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
|
161 |
167 |
systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
|
162 |
168 |
HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
|
163 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier());
|
164 |
169 |
|
165 |
170 |
} catch (Exception e) {
|
166 |
171 |
throw new ServiceFailure("4882", e.getMessage());
|
167 |
172 |
|
168 |
173 |
} finally {
|
169 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier());
|
|
174 |
lock.unlock();
|
170 |
175 |
|
171 |
176 |
}
|
172 |
177 |
|
... | ... | |
196 |
201 |
throws ServiceFailure, NotImplemented, InvalidToken, NotAuthorized,
|
197 |
202 |
InvalidRequest, NotFound {
|
198 |
203 |
|
|
204 |
// The lock to be used for this identifier
|
|
205 |
ILock lock = null;
|
|
206 |
|
199 |
207 |
boolean allowed = false;
|
200 |
208 |
int replicaEntryIndex = -1;
|
201 |
209 |
List<Replica> replicas = null;
|
... | ... | |
206 |
214 |
|
207 |
215 |
SystemMetadata systemMetadata = null;
|
208 |
216 |
try {
|
209 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
217 |
lock = HazelcastService.getInstance().getLock(pid);
|
|
218 |
lock.lock();
|
210 |
219 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
|
211 |
220 |
|
212 |
221 |
if ( systemMetadata == null ) {
|
... | ... | |
307 |
316 |
systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
|
308 |
317 |
systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
|
309 |
318 |
HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
|
310 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier());
|
311 |
319 |
|
312 |
320 |
} catch (Exception e) {
|
313 |
321 |
throw new ServiceFailure("4700", e.getMessage());
|
314 |
322 |
|
315 |
323 |
} finally {
|
316 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier());
|
|
324 |
lock.unlock();
|
317 |
325 |
|
318 |
326 |
}
|
319 |
327 |
|
... | ... | |
341 |
349 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
342 |
350 |
InvalidRequest, NotImplemented {
|
343 |
351 |
|
|
352 |
// The lock to be used for thyis identifier
|
|
353 |
ILock lock = null;
|
|
354 |
|
344 |
355 |
boolean asserted = false;
|
345 |
356 |
|
346 |
357 |
// are we allowed to do this?
|
... | ... | |
350 |
361 |
|
351 |
362 |
SystemMetadata systemMetadata = null;
|
352 |
363 |
try {
|
353 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(pidOfSubject);
|
|
364 |
lock = HazelcastService.getInstance().getLock(pidOfSubject);
|
|
365 |
lock.lock();
|
354 |
366 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pidOfSubject);
|
355 |
367 |
|
356 |
368 |
|
... | ... | |
384 |
396 |
}
|
385 |
397 |
//return systemMetadata.getObsoletedByList().contains(pidOfObject);
|
386 |
398 |
}
|
387 |
|
|
388 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pidOfSubject);
|
389 |
|
|
|
399 |
|
390 |
400 |
} catch (Exception e) {
|
391 |
401 |
throw new ServiceFailure("4270", "Could not assert relation for: " +
|
392 |
402 |
pidOfSubject.getValue() +
|
393 |
403 |
". The error message was: " + e.getMessage());
|
394 |
404 |
|
395 |
405 |
} finally {
|
396 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pidOfSubject);
|
|
406 |
lock.unlock();
|
397 |
407 |
|
398 |
408 |
}
|
399 |
409 |
|
... | ... | |
419 |
429 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
|
420 |
430 |
NotImplemented {
|
421 |
431 |
|
|
432 |
// The lock to be used for thyis identifier
|
|
433 |
ILock lock = null;
|
|
434 |
|
422 |
435 |
if (!isAuthorized(session, pid, Permission.READ)) {
|
423 |
436 |
throw new NotAuthorized("1400", Permission.READ + " not allowed on " + pid.getValue());
|
424 |
437 |
}
|
... | ... | |
427 |
440 |
Checksum checksum = null;
|
428 |
441 |
|
429 |
442 |
try {
|
430 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
443 |
lock = HazelcastService.getInstance().getLock(pid);
|
|
444 |
lock.lock();
|
431 |
445 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
|
432 |
446 |
checksum = systemMetadata.getChecksum();
|
433 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
|
434 |
447 |
|
435 |
448 |
} catch (Exception e) {
|
436 |
449 |
throw new ServiceFailure("1410", "An error occurred getting the checksum for " +
|
437 |
450 |
pid.getValue() + ". The error message was: " + e.getMessage());
|
438 |
451 |
|
439 |
452 |
} finally {
|
440 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
|
|
453 |
lock.unlock();
|
441 |
454 |
|
442 |
455 |
}
|
443 |
456 |
|
... | ... | |
636 |
649 |
throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest,
|
637 |
650 |
InvalidSystemMetadata {
|
638 |
651 |
|
|
652 |
// The lock to be used for this identifier
|
|
653 |
ILock lock = null;
|
|
654 |
|
639 |
655 |
// TODO: control who can call this?
|
640 |
656 |
if (session == null) {
|
641 |
657 |
//TODO: many of the thrown exceptions do not use the correct error codes
|
... | ... | |
665 |
681 |
// insert the system metadata into the object store
|
666 |
682 |
logMetacat.debug("Starting to insert SystemMetadata...");
|
667 |
683 |
try {
|
668 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(sysmeta.getIdentifier());
|
|
684 |
lock = HazelcastService.getInstance().getLock(sysmeta.getIdentifier());
|
669 |
685 |
sysmeta.setSerialVersion(BigInteger.ONE);
|
670 |
686 |
sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
|
671 |
687 |
HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta);
|
672 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier());
|
673 |
688 |
|
674 |
689 |
} catch (Exception e) {
|
675 |
690 |
logMetacat.error("Problem registering system metadata: " + pid.getValue(), e);
|
... | ... | |
677 |
692 |
e.getClass() + ": " + e.getMessage());
|
678 |
693 |
|
679 |
694 |
} finally {
|
680 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier());
|
|
695 |
lock.unlock();
|
681 |
696 |
|
682 |
697 |
}
|
683 |
698 |
|
... | ... | |
778 |
793 |
throws InvalidToken, ServiceFailure, NotFound, NotAuthorized,
|
779 |
794 |
NotImplemented, InvalidRequest {
|
780 |
795 |
|
|
796 |
// The lock to be used for this identifier
|
|
797 |
ILock lock = null;
|
|
798 |
|
781 |
799 |
// get the subject
|
782 |
800 |
Subject subject = session.getSubject();
|
783 |
801 |
|
... | ... | |
788 |
806 |
|
789 |
807 |
SystemMetadata systemMetadata = null;
|
790 |
808 |
try {
|
791 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
809 |
lock = HazelcastService.getInstance().getLock(pid);
|
792 |
810 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
|
793 |
811 |
|
794 |
812 |
// does the request have the most current system metadata?
|
... | ... | |
813 |
831 |
systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
|
814 |
832 |
systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
|
815 |
833 |
HazelcastService.getInstance().getSystemMetadataMap().put(pid, systemMetadata);
|
816 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
|
817 |
834 |
|
818 |
835 |
} catch (Exception e) {
|
819 |
836 |
throw new ServiceFailure("4490", e.getMessage());
|
820 |
837 |
|
821 |
838 |
} finally {
|
822 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
|
|
839 |
lock.unlock();
|
823 |
840 |
}
|
824 |
841 |
|
825 |
842 |
return pid;
|
... | ... | |
849 |
866 |
throws NotImplemented, NotAuthorized, InvalidToken, ServiceFailure,
|
850 |
867 |
NotFound, InvalidRequest {
|
851 |
868 |
|
|
869 |
// The lock to be used for this identifier
|
|
870 |
ILock lock = null;
|
|
871 |
|
852 |
872 |
boolean isAllowed = false;
|
853 |
873 |
SystemMetadata sysmeta = null;
|
854 |
874 |
NodeReference targetNode = null;
|
... | ... | |
880 |
900 |
|
881 |
901 |
}
|
882 |
902 |
//lock, get, and unlock the pid
|
883 |
|
//HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
903 |
lock = HazelcastService.getInstance().getLock(pid);
|
|
904 |
lock.lock();
|
884 |
905 |
logMetacat.debug("Getting system metadata for identifier " + pid.getValue());
|
885 |
906 |
|
886 |
907 |
sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
|
... | ... | |
914 |
935 |
" is null.");
|
915 |
936 |
|
916 |
937 |
}
|
917 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
|
918 |
938 |
|
919 |
939 |
} catch (RuntimeException e) {
|
920 |
940 |
ServiceFailure sf = new ServiceFailure("4872",
|
... | ... | |
925 |
945 |
|
926 |
946 |
} finally {
|
927 |
947 |
// always unlock the pid
|
928 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
|
|
948 |
lock.unlock();
|
929 |
949 |
|
930 |
950 |
}
|
931 |
951 |
|
... | ... | |
960 |
980 |
NotImplemented, InvalidRequest {
|
961 |
981 |
|
962 |
982 |
|
|
983 |
// The lock to be used for this identifier
|
|
984 |
ILock lock = null;
|
|
985 |
|
963 |
986 |
try {
|
964 |
987 |
// are we allowed?
|
965 |
988 |
boolean isAllowed = false;
|
... | ... | |
982 |
1005 |
// proceed if we're called by a CN
|
983 |
1006 |
if ( isAllowed ) {
|
984 |
1007 |
// create the coordinating node version of the document
|
985 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
1008 |
lock = HazelcastService.getInstance().getLock(pid);
|
|
1009 |
lock.lock();
|
986 |
1010 |
sysmeta.setSerialVersion(BigInteger.ONE);
|
987 |
1011 |
sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
|
988 |
1012 |
pid = super.create(session, pid, object, sysmeta);
|
989 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
|
990 |
1013 |
|
991 |
1014 |
} else {
|
992 |
1015 |
String msg = "The subject listed as " + session.getSubject().getValue() +
|
... | ... | |
1002 |
1025 |
throw new ServiceFailure("4893", msg);
|
1003 |
1026 |
|
1004 |
1027 |
} finally {
|
1005 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
|
|
1028 |
lock.unlock();
|
1006 |
1029 |
|
1007 |
1030 |
}
|
1008 |
1031 |
|
... | ... | |
1031 |
1054 |
throws InvalidToken, ServiceFailure, NotFound, NotAuthorized,
|
1032 |
1055 |
NotImplemented, InvalidRequest {
|
1033 |
1056 |
|
|
1057 |
// The lock to be used for this identifier
|
|
1058 |
ILock lock = null;
|
|
1059 |
|
1034 |
1060 |
boolean success = false;
|
1035 |
1061 |
|
1036 |
1062 |
// get the subject
|
... | ... | |
1044 |
1070 |
|
1045 |
1071 |
SystemMetadata systemMetadata = null;
|
1046 |
1072 |
try {
|
1047 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
1073 |
lock = HazelcastService.getInstance().getLock(pid);
|
|
1074 |
lock.lock();
|
1048 |
1075 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
|
1049 |
1076 |
|
1050 |
1077 |
// does the request have the most current system metadata?
|
... | ... | |
1070 |
1097 |
systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
|
1071 |
1098 |
systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
|
1072 |
1099 |
HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
|
1073 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier());
|
1074 |
1100 |
|
1075 |
1101 |
} catch (Exception e) {
|
1076 |
1102 |
// convert Hazelcast RuntimeException to ServiceFailure
|
1077 |
1103 |
throw new ServiceFailure("4430", e.getMessage());
|
1078 |
1104 |
|
1079 |
1105 |
} finally {
|
1080 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier());
|
|
1106 |
lock.unlock();
|
1081 |
1107 |
|
1082 |
1108 |
}
|
1083 |
1109 |
|
... | ... | |
1106 |
1132 |
throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest,
|
1107 |
1133 |
NotFound {
|
1108 |
1134 |
|
|
1135 |
// The lock to be used for this identifier
|
|
1136 |
ILock lock = null;
|
|
1137 |
|
1109 |
1138 |
// get the subject
|
1110 |
1139 |
Subject subject = session.getSubject();
|
1111 |
1140 |
|
... | ... | |
1125 |
1154 |
|
1126 |
1155 |
SystemMetadata systemMetadata = null;
|
1127 |
1156 |
try {
|
1128 |
|
HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
|
|
1157 |
lock = HazelcastService.getInstance().getLock(pid);
|
|
1158 |
lock.lock();
|
1129 |
1159 |
systemMetadata = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
|
1130 |
1160 |
|
1131 |
1161 |
// does the request have the most current system metadata?
|
... | ... | |
1167 |
1197 |
systemMetadata.setSerialVersion(systemMetadata.getSerialVersion().add(BigInteger.ONE));
|
1168 |
1198 |
systemMetadata.setDateSysMetadataModified(Calendar.getInstance().getTime());
|
1169 |
1199 |
HazelcastService.getInstance().getSystemMetadataMap().put(systemMetadata.getIdentifier(), systemMetadata);
|
1170 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier());
|
1171 |
1200 |
|
1172 |
1201 |
} catch (Exception e) {
|
1173 |
1202 |
throw new ServiceFailure("4852", e.getMessage());
|
1174 |
1203 |
|
1175 |
1204 |
} finally {
|
1176 |
|
HazelcastService.getInstance().getSystemMetadataMap().unlock(systemMetadata.getIdentifier());
|
|
1205 |
lock.unlock();
|
1177 |
1206 |
|
1178 |
1207 |
}
|
1179 |
1208 |
|
Use the Hazelcast ILock mechanism to lock the system metadata identifier rather than using IMap.lock(pid).