Project

General

Profile

« Previous | Next » 

Revision 6795

In the call to MNReplication.replicate(), call back to CNReplication.setReplicationStatus() and set the status to failed when we get local exceptions, exceptions from the source MN when calling getReplica(). Send back an exception with a description when setting the status. Add a private setReplicationStatus() method to refactor these calls out.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
41 41
import org.dataone.client.MNode;
42 42
import org.dataone.client.auth.CertificateManager;
43 43
import org.dataone.configuration.Settings;
44
import org.dataone.service.exceptions.BaseException;
44 45
import org.dataone.service.exceptions.IdentifierNotUnique;
45 46
import org.dataone.service.exceptions.InsufficientResources;
46 47
import org.dataone.service.exceptions.InvalidRequest;
......
133 134

  
134 135
    /* the logger instance */
135 136
    private Logger logMetacat = null;
137
    
138
    /* A reference to a remote Memeber Node */
139
    private MNode mn;
140
    
141
    /* A reference to a Coordinating Node */
142
    private CNode cn;
136 143

  
144

  
137 145
    /**
138 146
     * Singleton accessor to get an instance of MNodeService.
139 147
     * 
......
429 437
            NotAuthorized, InvalidRequest, InsufficientResources,
430 438
            UnsupportedType {
431 439

  
432
        // cannot be called by public
433
        if (session == null) {
434
            throw new NotAuthorized("2152", "No session was provided.");
435
        }
436

  
437 440
        logMetacat.info("MNodeService.replicate() called with parameters: \n"
438 441
                + "\tSession.Subject      = " + session.getSubject().getValue()
439 442
                + "\n" + "\tSystemMetadata       = " + sysmeta.toString()
......
443 446
        String nodeIdStr = null;
444 447
        NodeReference nodeId = null;
445 448

  
449
        // get the referenced object
450
        Identifier pid = sysmeta.getIdentifier();
451

  
452
        // get from the membernode
453
        // TODO: switch credentials for the server retrieval?
454
        this.mn = D1Client.getMN(sourceNode);
455
        this.cn = D1Client.getCN();
456
        InputStream object = null;
457
        Session thisNodeSession = null;
458
        SystemMetadata localSystemMetadata = null;
459
        BaseException failure = null;
460

  
461
        // TODO: check credentials
462
        // cannot be called by public
463
        if (session == null) {
464
            String msg = "No session was provided.";
465
            failure = new NotAuthorized("2152", msg);
466
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
467
            logMetacat.info(msg);
468
            return true;
469
        }
470

  
471

  
446 472
        // get the local node id
447 473
        try {
448 474
            nodeIdStr = PropertyService.getProperty("dataone.memberNodeId");
......
450 476
            nodeId.setValue(nodeIdStr);
451 477

  
452 478
        } catch (PropertyNotFoundException e1) {
453
            logMetacat.error("Couldn't get dataone.memberNodeId property: "
454
                    + e1.getMessage());
479
            String msg = "Couldn't get dataone.memberNodeId property: " + e1.getMessage();
480
            failure = new ServiceFailure("2151", msg);
481
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
482
            logMetacat.error(msg);
483
            return true;
455 484

  
456 485
        }
457
        // TODO: check credentials
486
        
458 487

  
459
        // get the referenced object
460
        Identifier pid = sysmeta.getIdentifier();
461

  
462
        // get from the membernode
463
        // TODO: switch credentials for the server retrieval?
464
        MNode mn = D1Client.getMN(sourceNode);
465
        CNode cn = D1Client.getCN();
466
        long serialVersion = sysmeta.getSerialVersion().longValue();
467
        InputStream object = null;
468
        Session thisNodeSession = null;
469
        Identifier localPid = null;
470
        SystemMetadata localSystemMetadata = null;
471

  
472 488
        try {
473 489
            // do we already have a replica?
474 490
            try {
......
477 493
                object = getReplica(thisNodeSession, pid);
478 494
                
479 495
            } catch (RuntimeException e) {
480
                logMetacat.info("An error occurred getting system metadata for "
481
                                + pid.getValue());
496
                String msg = "An error occurred getting system metadata for " +
497
                    pid.getValue();
498
                failure = new ServiceFailure("2151", msg);
499
                setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
500
                logMetacat.error(msg);
501
                return true;
482 502

  
483 503
            }
484 504

  
......
492 512

  
493 513
            }
494 514

  
495
        } catch (InvalidToken e) {
496
            throw new ServiceFailure("2151",
497
                    "Could not retrieve object to replicate (InvalidToken): "
498
                            + e.getMessage());
515
        } catch (InvalidToken e) {            
516
            String msg = "Could not retrieve object to replicate (InvalidToken): "+ e.getMessage();
517
            failure = new ServiceFailure("2151", msg);
518
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
519
            logMetacat.error(msg);
520
            throw new ServiceFailure("2151", msg);
499 521

  
500 522
        } catch (NotFound e) {
501
            throw new ServiceFailure("2151",
502
                    "Could not retrieve object to replicate (NotFound): "
503
                            + e.getMessage());
523
            String msg = "Could not retrieve object to replicate (NotFound): "+ e.getMessage();
524
            failure = new ServiceFailure("2151", msg);
525
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
526
            logMetacat.error(msg);
527
            throw new ServiceFailure("2151", msg);
504 528

  
505 529
        }
506 530

  
......
532 556
            // dont want it to
533 557
            retPid = super.create(session, pid, object, sysmeta);
534 558
            result = (retPid.getValue().equals(pid.getValue()));
559
            
535 560
        } catch (InvalidToken e) {
536
            e.printStackTrace();
537
            throw new ServiceFailure("2151",
538
                    "Could not save object to local store (InvalidToken): "
539
                            + e.getMessage());
561
            String msg = "Could not save object to local store (InvalidToken): " + e.getMessage();
562
            failure = new ServiceFailure("2151", msg);
563
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
564
            logMetacat.error(msg);
565
            throw new ServiceFailure("2151", msg);
566
        
540 567
        } catch (IdentifierNotUnique e) {
541
            e.printStackTrace();
542
            throw new ServiceFailure("2151",
543
                    "Could not save object to local store (IdentifierNotUnique): "
544
                            + e.getMessage());
568
            String msg = "Could not save object to local store (IdentifierNotUnique): " + e.getMessage();
569
            failure = new ServiceFailure("2151", msg);
570
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
571
            logMetacat.error(msg);
572
            throw new ServiceFailure("2151", msg);
573
        
545 574
        } catch (InvalidSystemMetadata e) {
546
            e.printStackTrace();
547
            throw new ServiceFailure("2151",
548
                    "Could not save object to local store (InvalidSystemMetadata): "
549
                            + e.getMessage());
575
            String msg = "Could not save object to local store (InvalidSystemMetadata): " + e.getMessage();
576
            failure = new ServiceFailure("2151", msg);
577
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
578
            logMetacat.error(msg);
579
            throw new ServiceFailure("2151", msg);
580
            
550 581
        }
551 582

  
552
        try {
553
            // call the CN as the MN to set the replication status
554
            cn.setReplicationStatus(thisNodeSession, pid, nodeId,
555
                    ReplicationStatus.COMPLETED, serialVersion);
556

  
557
        } catch (InvalidToken e) {
558
            // TODO Auto-generated catch block
559
            e.printStackTrace();
560
        } catch (NotFound e) {
561
            // TODO Auto-generated catch block
562
            e.printStackTrace();
563
        } catch (VersionMismatch e) {
564
            // TODO Auto-generated catch block
565
            e.printStackTrace();
566
        }
583
        // finish by setting the replication status
584
        setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.COMPLETED, null);
567 585
        return result;
568 586

  
569 587
    }
......
1204 1222
        
1205 1223
    }
1206 1224
    
1225
    /*
1226
     * Set the replication status for the object on the Coordinating Node
1227
     * 
1228
     * @param session - the session for the this target node
1229
     * @param pid - the identifier of the object being updated
1230
     * @param nodeId - the identifier of this target node
1231
     * @param status - the replication status to set
1232
     * @param failure - the exception to include, if any
1233
     */
1234
    private void setReplicationStatus(Session session, Identifier pid, 
1235
        NodeReference nodeId, ReplicationStatus status, BaseException failure) 
1236
        throws ServiceFailure, NotImplemented, NotAuthorized, 
1237
        InvalidRequest {
1238
        
1239
        // call the CN as the MN to set the replication status
1240
        try {
1241
            this.cn = D1Client.getCN();
1242
            this.cn.setReplicationStatus(session, pid, nodeId,
1243
                    status, failure);
1244
            
1245
        } catch (InvalidToken e) {
1246
            throw new ServiceFailure("2151",
1247
                    "Could not set the replication status on the CN (InvalidToken): " + 
1248
                    e.getMessage());
1249
            
1250
        } catch (NotFound e) {
1251
            throw new ServiceFailure("2151",
1252
                    "Could not set the replication status on the CN (NotFound): " + 
1253
                    e.getMessage());
1254
            
1255
        } catch (VersionMismatch e) {
1256
            throw new ServiceFailure("2151",
1257
                    "Could not set the replication status on the CN (VersionMismatch): " + 
1258
                    e.getMessage());
1259
            
1260
        }
1261

  
1262

  
1263
    }
1264
    
1207 1265
}

Also available in: Unified diff