Revision 9478
Added by Jing Tao about 9 years ago
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java | ||
---|---|---|
146 | 146 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
147 | 147 |
import edu.ucsb.nceas.metacat.MetaCatServlet; |
148 | 148 |
import edu.ucsb.nceas.metacat.MetacatHandler; |
149 |
import edu.ucsb.nceas.metacat.ReadOnlyChecker; |
|
149 | 150 |
import edu.ucsb.nceas.metacat.common.query.EnabledQueryEngines; |
150 | 151 |
import edu.ucsb.nceas.metacat.common.query.stream.ContentTypeByteArrayInputStream; |
151 | 152 |
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService; |
... | ... | |
252 | 253 |
public Identifier delete(Session session, Identifier pid) |
253 | 254 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
254 | 255 |
|
256 |
if(isReadOnlyMode()) { |
|
257 |
throw new ServiceFailure("2902", "The Metacat member node is on the read-only mode and your request can't be fulfiled. Please try again later."); |
|
258 |
} |
|
255 | 259 |
// only admin of the MN or the CN is allowed a full delete |
256 | 260 |
boolean allowed = false; |
257 | 261 |
allowed = isAdminAuthorized(session); |
... | ... | |
305 | 309 |
throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, |
306 | 310 |
UnsupportedType, InsufficientResources, NotFound, |
307 | 311 |
InvalidSystemMetadata, NotImplemented, InvalidRequest { |
312 |
|
|
313 |
if(isReadOnlyMode()) { |
|
314 |
throw new InvalidRequest("1202", "The Metacat member node is on the read-only mode and your request can't be fulfiled. Please try again later."); |
|
315 |
} |
|
308 | 316 |
|
309 | 317 |
//transform a sid to a pid if it is applicable |
310 | 318 |
String serviceFailureCode = "1310"; |
... | ... | |
527 | 535 |
public Identifier create(Session session, Identifier pid, InputStream object, SystemMetadata sysmeta) throws InvalidToken, ServiceFailure, NotAuthorized, |
528 | 536 |
IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest { |
529 | 537 |
|
538 |
if(isReadOnlyMode()) { |
|
539 |
throw new InvalidRequest("1102", "The Metacat member node is on the read-only mode and your request can't be fulfiled. Please try again later."); |
|
540 |
} |
|
530 | 541 |
// check for null session |
531 | 542 |
if (session == null) { |
532 | 543 |
throw new InvalidToken("1110", "Session is required to WRITE to the Node."); |
... | ... | |
634 | 645 |
NodeReference sourceNode) throws NotImplemented, ServiceFailure, |
635 | 646 |
NotAuthorized, InvalidRequest, InsufficientResources, |
636 | 647 |
UnsupportedType { |
648 |
if(isReadOnlyMode()) { |
|
649 |
throw new InvalidRequest("2153", "The Metacat member node is on the read-only mode and your request can't be fulfiled. Please try again later."); |
|
650 |
} |
|
637 | 651 |
|
638 | 652 |
if (session != null && sysmeta != null && sourceNode != null) { |
639 | 653 |
logMetacat.info("MNodeService.replicate() called with parameters: \n" + |
... | ... | |
1407 | 1421 |
throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest, |
1408 | 1422 |
InvalidToken { |
1409 | 1423 |
|
1424 |
if(isReadOnlyMode()) { |
|
1425 |
throw new InvalidRequest("1334", "The Metacat member node is on the read-only mode and your request can't be fulfiled. Please try again later."); |
|
1426 |
} |
|
1410 | 1427 |
// cannot be called by public |
1411 | 1428 |
if (session == null) { |
1412 | 1429 |
throw new InvalidToken("1332", "No session was provided."); |
... | ... | |
2461 | 2478 |
*/ |
2462 | 2479 |
public Identifier archive(Session session, Identifier pid) |
2463 | 2480 |
throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented { |
2481 |
if(isReadOnlyMode()) { |
|
2482 |
throw new ServiceFailure("2912", "The Metacat member node is on the read-only mode and your request can't be fulfiled. Please try again later."); |
|
2483 |
} |
|
2464 | 2484 |
boolean allowed = false; |
2465 | 2485 |
// do we have a valid pid? |
2466 | 2486 |
if (pid == null || pid.getValue().trim().equals("")) { |
... | ... | |
2507 | 2527 |
public boolean updateSystemMetadata(Session session, Identifier pid, |
2508 | 2528 |
SystemMetadata sysmeta) throws NotImplemented, NotAuthorized, |
2509 | 2529 |
ServiceFailure, InvalidRequest, InvalidSystemMetadata, InvalidToken { |
2530 |
|
|
2531 |
if(isReadOnlyMode()) { |
|
2532 |
throw new InvalidRequest("4869", "The Metacat member node is on the read-only mode and your request can't be fulfiled. Please try again later."); |
|
2533 |
} |
|
2510 | 2534 |
if(sysmeta == null) { |
2511 |
throw new InvalidRequest("4863", "The system metadata object should NOT be null in the updateSystemMetadata request.");
|
|
2535 |
throw new InvalidRequest("4869", "The system metadata object should NOT be null in the updateSystemMetadata request.");
|
|
2512 | 2536 |
} |
2513 | 2537 |
if(pid == null || pid.getValue() == null) { |
2514 |
throw new InvalidRequest("4863", "Please specify the id in the updateSystemMetadata request ") ;
|
|
2538 |
throw new InvalidRequest("4869", "Please specify the id in the updateSystemMetadata request ") ;
|
|
2515 | 2539 |
} |
2516 | 2540 |
|
2517 | 2541 |
if (session == null) { |
... | ... | |
2536 | 2560 |
throw new NotAuthorized("4861", "The client -"+ session.getSubject().getValue()+ "is not authorized for updating the system metadata of the object "+pid.getValue()); |
2537 | 2561 |
} |
2538 | 2562 |
} catch (NotFound e) { |
2539 |
throw new InvalidRequest("4863", "Can't determine if the client has the permission to update the system metacat of the object with id "+pid.getValue()+" since "+e.getDescription());
|
|
2563 |
throw new InvalidRequest("4869", "Can't determine if the client has the permission to update the system metacat of the object with id "+pid.getValue()+" since "+e.getDescription());
|
|
2540 | 2564 |
} |
2541 | 2565 |
|
2542 | 2566 |
} |
... | ... | |
2546 | 2570 |
HazelcastService.getInstance().getSystemMetadataMap().lock(pid); |
2547 | 2571 |
SystemMetadata currentSysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid); |
2548 | 2572 |
if(currentSysmeta == null) { |
2549 |
throw new InvalidRequest("4863", "We can't find the current system metadata on the member node for the id "+pid.getValue());
|
|
2573 |
throw new InvalidRequest("4869", "We can't find the current system metadata on the member node for the id "+pid.getValue());
|
|
2550 | 2574 |
} |
2551 | 2575 |
Date currentModiDate = currentSysmeta.getDateSysMetadataModified(); |
2552 | 2576 |
Date commingModiDate = sysmeta.getDateSysMetadataModified(); |
2553 | 2577 |
if(commingModiDate == null) { |
2554 |
throw new InvalidRequest("4863", "The system metadata modification date can't be null.");
|
|
2578 |
throw new InvalidRequest("4869", "The system metadata modification date can't be null.");
|
|
2555 | 2579 |
} |
2556 | 2580 |
if(currentModiDate != null && commingModiDate.getTime() != currentModiDate.getTime()) { |
2557 |
throw new InvalidRequest("4863", "Your system metadata modification date is "+commingModiDate.toString()+
|
|
2581 |
throw new InvalidRequest("4869", "Your system metadata modification date is "+commingModiDate.toString()+
|
|
2558 | 2582 |
". It doesn't match our current system metadata modification date in the member node - "+currentModiDate.toString()+ |
2559 | 2583 |
". Please check if you have got the newest version of the system metadata before the modification."); |
2560 | 2584 |
} |
... | ... | |
2651 | 2675 |
|
2652 | 2676 |
} |
2653 | 2677 |
|
2678 |
/** |
|
2679 |
* Check if the metacat is in the read-only mode. |
|
2680 |
* @return true if it is; otherwise false. |
|
2681 |
*/ |
|
2682 |
protected boolean isReadOnlyMode() { |
|
2683 |
boolean readOnly = false; |
|
2684 |
ReadOnlyChecker checker = new ReadOnlyChecker(); |
|
2685 |
readOnly = checker.isReadOnly(); |
|
2686 |
return readOnly; |
|
2687 |
} |
|
2688 |
|
|
2654 | 2689 |
} |
Also available in: Unified diff
Add the code to check if the mn is on the read-only mode.