Project

General

Profile

1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2000-2011 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *
6
 *   '$Author:  $'
7
 *     '$Date:  $'
8
 *
9
 * This program is free software; you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation; either version 2 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 */
23

    
24
package edu.ucsb.nceas.metacat.dataone;
25

    
26
import java.io.IOException;
27
import java.io.InputStream;
28
import java.security.NoSuchAlgorithmException;
29
import java.sql.SQLException;
30
import java.util.Calendar;
31
import java.util.Date;
32
import java.util.List;
33
import java.util.Timer;
34

    
35
import javax.servlet.http.HttpServletRequest;
36

    
37
import org.apache.commons.io.IOUtils;
38
import org.apache.log4j.Logger;
39
import org.dataone.client.CNode;
40
import org.dataone.client.D1Client;
41
import org.dataone.client.MNode;
42
import org.dataone.client.auth.CertificateManager;
43
import org.dataone.configuration.Settings;
44
import org.dataone.service.exceptions.BaseException;
45
import org.dataone.service.exceptions.IdentifierNotUnique;
46
import org.dataone.service.exceptions.InsufficientResources;
47
import org.dataone.service.exceptions.InvalidRequest;
48
import org.dataone.service.exceptions.InvalidSystemMetadata;
49
import org.dataone.service.exceptions.InvalidToken;
50
import org.dataone.service.exceptions.NotAuthorized;
51
import org.dataone.service.exceptions.NotFound;
52
import org.dataone.service.exceptions.NotImplemented;
53
import org.dataone.service.exceptions.ServiceFailure;
54
import org.dataone.service.exceptions.SynchronizationFailed;
55
import org.dataone.service.exceptions.UnsupportedType;
56
import org.dataone.service.exceptions.VersionMismatch;
57
import org.dataone.service.mn.tier1.v1.MNCore;
58
import org.dataone.service.mn.tier1.v1.MNRead;
59
import org.dataone.service.mn.tier2.v1.MNAuthorization;
60
import org.dataone.service.mn.tier3.v1.MNStorage;
61
import org.dataone.service.mn.tier4.v1.MNReplication;
62
import org.dataone.service.types.v1.Checksum;
63
import org.dataone.service.types.v1.Event;
64
import org.dataone.service.types.v1.Group;
65
import org.dataone.service.types.v1.Identifier;
66
import org.dataone.service.types.v1.Log;
67
import org.dataone.service.types.v1.LogEntry;
68
import org.dataone.service.types.v1.MonitorInfo;
69
import org.dataone.service.types.v1.MonitorList;
70
import org.dataone.service.types.v1.Node;
71
import org.dataone.service.types.v1.NodeList;
72
import org.dataone.service.types.v1.NodeReference;
73
import org.dataone.service.types.v1.NodeState;
74
import org.dataone.service.types.v1.NodeType;
75
import org.dataone.service.types.v1.ObjectFormatIdentifier;
76
import org.dataone.service.types.v1.ObjectList;
77
import org.dataone.service.types.v1.Permission;
78
import org.dataone.service.types.v1.Ping;
79
import org.dataone.service.types.v1.ReplicationStatus;
80
import org.dataone.service.types.v1.Schedule;
81
import org.dataone.service.types.v1.Service;
82
import org.dataone.service.types.v1.Services;
83
import org.dataone.service.types.v1.Session;
84
import org.dataone.service.types.v1.Subject;
85
import org.dataone.service.types.v1.Synchronization;
86
import org.dataone.service.types.v1.SystemMetadata;
87
import org.dataone.service.types.v1.util.ChecksumUtil;
88
import org.dataone.service.util.Constants;
89

    
90
import edu.ucsb.nceas.metacat.DocumentImpl;
91
import edu.ucsb.nceas.metacat.EventLog;
92
import edu.ucsb.nceas.metacat.IdentifierManager;
93
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
94
import edu.ucsb.nceas.metacat.MetacatHandler;
95
import edu.ucsb.nceas.metacat.client.InsufficientKarmaException;
96
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
97
import edu.ucsb.nceas.metacat.properties.PropertyService;
98
import edu.ucsb.nceas.metacat.util.SystemUtil;
99
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
100

    
101
/**
102
 * Represents Metacat's implementation of the DataONE Member Node 
103
 * service API. Methods implement the various MN* interfaces, and methods common
104
 * to both Member Node and Coordinating Node interfaces are found in the
105
 * D1NodeService base class.
106
 * 
107
 * Implements:
108
 * MNCore.ping()
109
 * MNCore.getLogRecords()
110
 * MNCore.getObjectStatistics()
111
 * MNCore.getOperationStatistics()
112
 * MNCore.getStatus()
113
 * MNCore.getCapabilities()
114
 * MNRead.get()
115
 * MNRead.getSystemMetadata()
116
 * MNRead.describe()
117
 * MNRead.getChecksum()
118
 * MNRead.listObjects()
119
 * MNRead.synchronizationFailed()
120
 * MNAuthorization.isAuthorized()
121
 * MNAuthorization.setAccessPolicy()
122
 * MNStorage.create()
123
 * MNStorage.update()
124
 * MNStorage.delete()
125
 * MNReplication.replicate()
126
 * 
127
 */
128
public class MNodeService extends D1NodeService 
129
    implements MNAuthorization, MNCore, MNRead, MNReplication, MNStorage {
130

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

    
140

    
141
    /**
142
     * Singleton accessor to get an instance of MNodeService.
143
     * 
144
     * @return instance - the instance of MNodeService
145
     */
146
    public static MNodeService getInstance(HttpServletRequest request) {
147
        return new MNodeService(request);
148
    }
149

    
150
    /**
151
     * Constructor, private for singleton access
152
     */
153
    private MNodeService(HttpServletRequest request) {
154
        super(request);
155
        logMetacat = Logger.getLogger(MNodeService.class);
156
        
157
        // set the Member Node certificate file location
158
        CertificateManager.getInstance().setCertificateLocation(Settings.getConfiguration().getString("D1Client.certificate.file"));
159
    }
160

    
161
    /**
162
     * Deletes an object from the Member Node, where the object is either a 
163
     * data object or a science metadata object.
164
     * 
165
     * @param session - the Session object containing the credentials for the Subject
166
     * @param pid - The object identifier to be deleted
167
     * 
168
     * @return pid - the identifier of the object used for the deletion
169
     * 
170
     * @throws InvalidToken
171
     * @throws ServiceFailure
172
     * @throws NotAuthorized
173
     * @throws NotFound
174
     * @throws NotImplemented
175
     * @throws InvalidRequest
176
     */
177
    @Override
178
    public Identifier delete(Session session, Identifier pid) 
179
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
180

    
181
        String localId = null;
182
        boolean allowed = false;
183
        String username = Constants.SUBJECT_PUBLIC;
184
        String[] groupnames = null;
185
        if (session == null) {
186
        	throw new InvalidToken("1330", "No session has been provided");
187
        } else {
188
            username = session.getSubject().getValue();
189
            if (session.getSubjectInfo() != null) {
190
                List<Group> groupList = session.getSubjectInfo().getGroupList();
191
                if (groupList != null) {
192
                    groupnames = new String[groupList.size()];
193
                    for (int i = 0; i > groupList.size(); i++) {
194
                        groupnames[i] = groupList.get(i).getGroupName();
195
                    }
196
                }
197
            }
198
        }
199

    
200
        // do we have a valid pid?
201
        if (pid == null || pid.getValue().trim().equals("")) {
202
            throw new ServiceFailure("1350", "The provided identifier was invalid.");
203
        }
204

    
205
        // check for the existing identifier
206
        try {
207
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
208
        } catch (McdbDocNotFoundException e) {
209
            throw new NotFound("1340", "The object with the provided " + "identifier was not found.");
210
        }
211

    
212
        // does the subject have DELETE (a D1 CHANGE_PERMISSION level) priveleges on the pid?
213
        allowed = isAuthorized(session, pid, Permission.CHANGE_PERMISSION);
214
            
215

    
216
        if (allowed) {
217
            try {
218
                // delete the document
219
                DocumentImpl.delete(localId, username, groupnames, null);
220
                EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), username, localId, Event.DELETE.xmlValue());
221

    
222
                // archive it
223
                SystemMetadata sysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
224
                sysMeta.setArchived(true);
225
                HazelcastService.getInstance().getSystemMetadataMap().put(pid, sysMeta);
226
                
227
                // remove the system metadata for it
228
                //HazelcastService.getInstance().getSystemMetadataMap().remove(pid);
229
                
230
            } catch (McdbDocNotFoundException e) {
231
                throw new NotFound("1340", "The provided identifier was invalid.");
232

    
233
            } catch (SQLException e) {
234
                throw new ServiceFailure("1350", "There was a problem deleting the object." + "The error message was: " + e.getMessage());
235

    
236
            } catch (InsufficientKarmaException e) {
237
                throw new NotAuthorized("1320", "The provided identity does not have " + "permission to DELETE objects on the Member Node.");
238

    
239
            } catch (Exception e) { // for some reason DocumentImpl throws a general Exception
240
                throw new ServiceFailure("1350", "There was a problem deleting the object." + "The error message was: " + e.getMessage());
241
            }
242

    
243
        } else {
244
            throw new NotAuthorized("1320", "The provided identity does not have " + "permission to DELETE objects on the Member Node.");
245
        }
246

    
247
        return pid;
248
    }
249

    
250
    /**
251
     * Updates an existing object by creating a new object identified by 
252
     * newPid on the Member Node which explicitly obsoletes the object 
253
     * identified by pid through appropriate changes to the SystemMetadata 
254
     * of pid and newPid
255
     * 
256
     * @param session - the Session object containing the credentials for the Subject
257
     * @param pid - The identifier of the object to be updated
258
     * @param object - the new object bytes
259
     * @param sysmeta - the new system metadata describing the object
260
     * 
261
     * @return newPid - the identifier of the new object
262
     * 
263
     * @throws InvalidToken
264
     * @throws ServiceFailure
265
     * @throws NotAuthorized
266
     * @throws NotFound
267
     * @throws NotImplemented
268
     * @throws IdentifierNotUnique
269
     * @throws UnsupportedType
270
     * @throws InsufficientResources
271
     * @throws InvalidSystemMetadata
272
     * @throws InvalidRequest
273
     */
274
    @Override
275
    public Identifier update(Session session, Identifier pid, InputStream object, 
276
        Identifier newPid, SystemMetadata sysmeta) 
277
        throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
278
        UnsupportedType, InsufficientResources, NotFound, 
279
        InvalidSystemMetadata, NotImplemented, InvalidRequest {
280

    
281
        String localId = null;
282
        boolean allowed = false;
283
        boolean isScienceMetadata = false;
284
        
285
        if (session == null) {
286
        	throw new InvalidToken("1210", "No session has been provided");
287
        }
288
        Subject subject = session.getSubject();
289

    
290
        // do we have a valid pid?
291
        if (pid == null || pid.getValue().trim().equals("")) {
292
            throw new InvalidRequest("1202", "The provided identifier was invalid.");
293
            
294
        }
295

    
296
        // check for the existing identifier
297
        try {
298
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
299
            
300
        } catch (McdbDocNotFoundException e) {
301
            throw new InvalidRequest("1202", "The object with the provided " + 
302
                "identifier was not found.");
303
            
304
        }
305
        
306
        // set the originating node
307
        NodeReference originMemberNode = this.getCapabilities().getIdentifier();
308
        sysmeta.setOriginMemberNode(originMemberNode);
309
        
310
        // set the submitter to match the certificate
311
        sysmeta.setSubmitter(subject);
312
        // set the dates
313
        Date now = Calendar.getInstance().getTime();
314
        sysmeta.setDateSysMetadataModified(now);
315
        sysmeta.setDateUploaded(now);
316

    
317
        // does the subject have WRITE ( == update) priveleges on the pid?
318
        allowed = isAuthorized(session, pid, Permission.WRITE);
319

    
320
        if (allowed) {
321
        	
322
        	// check quality of SM
323
        	if (sysmeta.getObsoletedBy() != null) {
324
        		throw new InvalidSystemMetadata("1300", "Cannot include obsoletedBy when updating object");
325
        	}
326
        	if (sysmeta.getObsoletes() != null && !sysmeta.getObsoletes().getValue().equals(pid.getValue())) {
327
        		throw new InvalidSystemMetadata("1300", "The identifier provided in obsoletes does not match old Identifier");
328
        	}
329

    
330
            // get the existing system metadata for the object
331
            SystemMetadata existingSysMeta = getSystemMetadata(session, pid);
332

    
333
            // add the newPid to the obsoletedBy list for the existing sysmeta
334
            existingSysMeta.setObsoletedBy(newPid);
335

    
336
            // then update the existing system metadata
337
            updateSystemMetadata(existingSysMeta);
338

    
339
            // prep the new system metadata, add pid to the affected lists
340
            sysmeta.setObsoletes(pid);
341
            //sysmeta.addDerivedFrom(pid);
342

    
343
            isScienceMetadata = isScienceMetadata(sysmeta);
344

    
345
            // do we have XML metadata or a data object?
346
            if (isScienceMetadata) {
347

    
348
                // update the science metadata XML document
349
                // TODO: handle non-XML metadata/data documents (like netCDF)
350
                // TODO: don't put objects into memory using stream to string
351
                String objectAsXML = "";
352
                try {
353
                    objectAsXML = IOUtils.toString(object, "UTF-8");
354
                    localId = insertOrUpdateDocument(objectAsXML, newPid, session, "update");
355
                    // register the newPid and the generated localId
356
                    if (newPid != null) {
357
                        IdentifierManager.getInstance().createMapping(newPid.getValue(), localId);
358

    
359
                    }
360

    
361
                } catch (IOException e) {
362
                    String msg = "The Node is unable to create the object. " + "There was a problem converting the object to XML";
363
                    logMetacat.info(msg);
364
                    throw new ServiceFailure("1310", msg + ": " + e.getMessage());
365

    
366
                }
367

    
368
            } else {
369

    
370
                // update the data object
371
                localId = insertDataObject(object, newPid, session);
372

    
373
            }
374

    
375
            // and insert the new system metadata
376
            insertSystemMetadata(sysmeta);
377

    
378
            // log the update event
379
            EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), subject.getValue(), localId, Event.UPDATE.toString());
380

    
381
        } else {
382
            throw new NotAuthorized("1200", "The provided identity does not have " + "permission to UPDATE the object identified by " + pid.getValue()
383
                    + " on the Member Node.");
384
        }
385

    
386
        return newPid;
387
    }
388

    
389
    public Identifier create(Session session, Identifier pid, InputStream object, SystemMetadata sysmeta) throws InvalidToken, ServiceFailure, NotAuthorized,
390
            IdentifierNotUnique, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, InvalidRequest {
391

    
392
        // check for null session
393
        if (session == null) {
394
          throw new InvalidToken("1110", "Session is required to WRITE to the Node.");
395
        }
396
        // set the submitter to match the certificate
397
        sysmeta.setSubmitter(session.getSubject());
398
        // set the originating node
399
        NodeReference originMemberNode = this.getCapabilities().getIdentifier();
400
        sysmeta.setOriginMemberNode(originMemberNode);
401
        sysmeta.setArchived(false);
402

    
403
        // set the dates
404
        Date now = Calendar.getInstance().getTime();
405
        sysmeta.setDateSysMetadataModified(now);
406
        sysmeta.setDateUploaded(now);
407
        // call the shared impl
408
        return super.create(session, pid, object, sysmeta);
409
    }
410

    
411
    /**
412
     * Called by a Coordinating Node to request that the Member Node create a 
413
     * copy of the specified object by retrieving it from another Member 
414
     * Node and storing it locally so that it can be made accessible to 
415
     * the DataONE system.
416
     * 
417
     * @param session - the Session object containing the credentials for the Subject
418
     * @param sysmeta - Copy of the CN held system metadata for the object
419
     * @param sourceNode - A reference to node from which the content should be 
420
     *                     retrieved. The reference should be resolved by 
421
     *                     checking the CN node registry.
422
     * 
423
     * @return true if the replication succeeds
424
     * 
425
     * @throws ServiceFailure
426
     * @throws NotAuthorized
427
     * @throws NotImplemented
428
     * @throws UnsupportedType
429
     * @throws InsufficientResources
430
     * @throws InvalidRequest
431
     */
432
    @Override
433
    public boolean replicate(Session session, SystemMetadata sysmeta,
434
            NodeReference sourceNode) throws NotImplemented, ServiceFailure,
435
            NotAuthorized, InvalidRequest, InsufficientResources,
436
            UnsupportedType {
437

    
438
        if (session != null && sysmeta != null && sourceNode != null) {
439
            logMetacat.info("MNodeService.replicate() called with parameters: \n" +
440
                            "\tSession.Subject      = "                           +
441
                            session.getSubject().getValue() + "\n"                +
442
                            "\tSystemMetadata       = " + sysmeta.toString()      +
443
                            "\n" + "\tSource NodeReference ="                     +
444
                            sourceNode.getValue());
445
        }
446
        boolean result = false;
447
        String nodeIdStr = null;
448
        NodeReference nodeId = null;
449

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

    
453
        // get from the membernode
454
        // TODO: switch credentials for the server retrieval?
455
        this.mn = D1Client.getMN(sourceNode);
456
        this.cn = D1Client.getCN();
457
        InputStream object = null;
458
        Session thisNodeSession = null;
459
        SystemMetadata localSystemMetadata = null;
460
        BaseException failure = null;
461
        String localId = null;
462
        
463
        // TODO: check credentials
464
        // cannot be called by public
465
        if (session.getSubject() == null) {
466
            String msg = "No session was provided.";
467
            failure = new NotAuthorized("2152", msg);
468
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
469
            logMetacat.info(msg);
470
            return true;
471
        }
472

    
473

    
474
        // get the local node id
475
        try {
476
            nodeIdStr = PropertyService.getProperty("dataone.memberNodeId");
477
            nodeId = new NodeReference();
478
            nodeId.setValue(nodeIdStr);
479

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

    
487
        }
488
        
489

    
490
        try {
491
            // do we already have a replica?
492
            try {
493
                localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
494

    
495
                String msg = "Can't read the object bytes properly, replica is invalid.";
496
                ServiceFailure serviceFailure = new ServiceFailure("2151", msg);
497
                
498
                // if we have a local id, get the local object
499
                try {
500
                    object = MetacatHandler.read(localId);
501
                    
502
                } catch (Exception e) {
503
                    // let the CN know that the replication failed
504
                    setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, serviceFailure);  
505
                    throw serviceFailure;
506
                    
507
                }
508

    
509
            } catch (McdbDocNotFoundException e) {
510
                logMetacat.info("No replica found. Continuing.");
511
                
512
            }
513
            
514
            // no local replica, get a replica
515
            if ( object == null ) {
516
                // session should be null to use the default certificate
517
                // location set in the Certificate manager
518
                object = mn.getReplica(thisNodeSession, pid);
519
                logMetacat.info("MNodeService.replicate() called for identifier "
520
                                + pid.getValue());
521

    
522
            }
523

    
524
        } catch (InvalidToken e) {            
525
            String msg = "Could not retrieve object to replicate (InvalidToken): "+ e.getMessage();
526
            failure = new ServiceFailure("2151", msg);
527
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
528
            logMetacat.error(msg);
529
            throw new ServiceFailure("2151", msg);
530

    
531
        } catch (NotFound e) {
532
            String msg = "Could not retrieve object to replicate (NotFound): "+ e.getMessage();
533
            failure = new ServiceFailure("2151", msg);
534
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
535
            logMetacat.error(msg);
536
            throw new ServiceFailure("2151", msg);
537

    
538
        }
539

    
540
        // verify checksum on the object, if supported
541
        if (object.markSupported()) {
542
            Checksum givenChecksum = sysmeta.getChecksum();
543
            Checksum computedChecksum = null;
544
            try {
545
                computedChecksum = ChecksumUtil.checksum(object,
546
                        givenChecksum.getAlgorithm());
547
                object.reset();
548

    
549
            } catch (Exception e) {
550
                String msg = "Error computing checksum on replica: "
551
                        + e.getMessage();
552
                ServiceFailure sf = new ServiceFailure("2151", msg);
553
                sf.initCause(e);
554
                throw sf;
555
            }
556
            if (!givenChecksum.getValue().equals(computedChecksum.getValue())) {
557
                logMetacat.debug("Given    checksum for " + pid.getValue() + 
558
                    "is " + givenChecksum.getValue());
559
                logMetacat.debug("Computed checksum for " + pid.getValue() + 
560
                    "is " + computedChecksum.getValue());
561
                throw new ServiceFailure("2151",
562
                        "Computed checksum does not match declared checksum");
563
            }
564
        }
565

    
566
        // add it to local store
567
        Identifier retPid;
568
        try {
569
            // skip the MN.create -- this mutates the system metadata and we
570
            // dont want it to
571
            if ( localId == null ) {
572
                
573
                retPid = super.create(session, pid, object, sysmeta);
574
                result = (retPid.getValue().equals(pid.getValue()));
575
            }
576
            
577
        } catch (InvalidToken e) {
578
            String msg = "Could not save object to local store (InvalidToken): " + e.getMessage();
579
            failure = new ServiceFailure("2151", msg);
580
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
581
            logMetacat.error(msg);
582
            throw new ServiceFailure("2151", msg);
583
        
584
        } catch (IdentifierNotUnique e) {
585
            String msg = "Could not save object to local store (IdentifierNotUnique): " + e.getMessage();
586
            failure = new ServiceFailure("2151", msg);
587
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
588
            logMetacat.error(msg);
589
            throw new ServiceFailure("2151", msg);
590
        
591
        } catch (InvalidSystemMetadata e) {
592
            String msg = "Could not save object to local store (InvalidSystemMetadata): " + e.getMessage();
593
            failure = new ServiceFailure("2151", msg);
594
            setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.FAILED, failure);
595
            logMetacat.error(msg);
596
            throw new ServiceFailure("2151", msg);
597
            
598
        }
599

    
600
        // finish by setting the replication status
601
        setReplicationStatus(thisNodeSession, pid, nodeId, ReplicationStatus.COMPLETED, null);
602
        return result;
603

    
604
    }
605

    
606
    /**
607
     * Return the object identified by the given object identifier
608
     * 
609
     * @param session - the Session object containing the credentials for the Subject
610
     * @param pid - the object identifier for the given object
611
     * 
612
     * @return inputStream - the input stream of the given object
613
     * 
614
     * @throws InvalidToken
615
     * @throws ServiceFailure
616
     * @throws NotAuthorized
617
     * @throws InvalidRequest
618
     * @throws NotImplemented
619
     */
620
    @Override
621
    public InputStream get(Session session, Identifier pid) 
622
    throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented {
623

    
624
        return super.get(session, pid);
625

    
626
    }
627

    
628
    /**
629
     * Returns a Checksum for the specified object using an accepted hashing algorithm
630
     * 
631
     * @param session - the Session object containing the credentials for the Subject
632
     * @param pid - the object identifier for the given object
633
     * @param algorithm -  the name of an algorithm that will be used to compute 
634
     *                     a checksum of the bytes of the object
635
     * 
636
     * @return checksum - the checksum of the given object
637
     * 
638
     * @throws InvalidToken
639
     * @throws ServiceFailure
640
     * @throws NotAuthorized
641
     * @throws NotFound
642
     * @throws InvalidRequest
643
     * @throws NotImplemented
644
     */
645
    @Override
646
    public Checksum getChecksum(Session session, Identifier pid, String algorithm) 
647
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
648
        InvalidRequest, NotImplemented {
649

    
650
        Checksum checksum = null;
651

    
652
        InputStream inputStream = get(session, pid);
653

    
654
        try {
655
            checksum = ChecksumUtil.checksum(inputStream, algorithm);
656

    
657
        } catch (NoSuchAlgorithmException e) {
658
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned due to an internal error: "
659
                    + e.getMessage());
660
        } catch (IOException e) {
661
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned due to an internal error: "
662
                    + e.getMessage());
663
        }
664

    
665
        if (checksum == null) {
666
            throw new ServiceFailure("1410", "The checksum for the object specified by " + pid.getValue() + "could not be returned.");
667
        }
668

    
669
        return checksum;
670
    }
671

    
672
    /**
673
     * Return the system metadata for a given object
674
     * 
675
     * @param session - the Session object containing the credentials for the Subject
676
     * @param pid - the object identifier for the given object
677
     * 
678
     * @return inputStream - the input stream of the given system metadata object
679
     * 
680
     * @throws InvalidToken
681
     * @throws ServiceFailure
682
     * @throws NotAuthorized
683
     * @throws NotFound
684
     * @throws InvalidRequest
685
     * @throws NotImplemented
686
     */
687
    @Override
688
    public SystemMetadata getSystemMetadata(Session session, Identifier pid) 
689
        throws InvalidToken, ServiceFailure, NotAuthorized, NotFound,
690
        NotImplemented {
691

    
692
        return super.getSystemMetadata(session, pid);
693
    }
694

    
695
    /**
696
     * Retrieve the list of objects present on the MN that match the calling parameters
697
     * 
698
     * @param session - the Session object containing the credentials for the Subject
699
     * @param startTime - Specifies the beginning of the time range from which 
700
     *                    to return object (>=)
701
     * @param endTime - Specifies the beginning of the time range from which 
702
     *                  to return object (>=)
703
     * @param objectFormat - Restrict results to the specified object format
704
     * @param replicaStatus - Indicates if replicated objects should be returned in the list
705
     * @param start - The zero-based index of the first value, relative to the 
706
     *                first record of the resultset that matches the parameters.
707
     * @param count - The maximum number of entries that should be returned in 
708
     *                the response. The Member Node may return less entries 
709
     *                than specified in this value.
710
     * 
711
     * @return objectList - the list of objects matching the criteria
712
     * 
713
     * @throws InvalidToken
714
     * @throws ServiceFailure
715
     * @throws NotAuthorized
716
     * @throws InvalidRequest
717
     * @throws NotImplemented
718
     */
719
    @Override
720
    public ObjectList listObjects(Session session, Date startTime, Date endTime, ObjectFormatIdentifier objectFormatId, Boolean replicaStatus, Integer start,
721
            Integer count) throws NotAuthorized, InvalidRequest, NotImplemented, ServiceFailure, InvalidToken {
722

    
723
        ObjectList objectList = null;
724

    
725
        try {
726
            objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime, objectFormatId, replicaStatus, start, count);
727
        } catch (Exception e) {
728
            throw new ServiceFailure("1580", "Error querying system metadata: " + e.getMessage());
729
        }
730

    
731
        return objectList;
732
    }
733

    
734
    /**
735
     * Return a description of the node's capabilities and services.
736
     * 
737
     * @return node - the technical capabilities of the Member Node
738
     * 
739
     * @throws ServiceFailure
740
     * @throws NotAuthorized
741
     * @throws InvalidRequest
742
     * @throws NotImplemented
743
     */
744
    @Override
745
    public Node getCapabilities() 
746
        throws NotImplemented, ServiceFailure {
747

    
748
        String nodeName = null;
749
        String nodeId = null;
750
        String subject = null;
751
        String contactSubject = null;
752
        String nodeDesc = null;
753
        String nodeTypeString = null;
754
        NodeType nodeType = null;
755
        String mnCoreServiceVersion = null;
756
        String mnReadServiceVersion = null;
757
        String mnAuthorizationServiceVersion = null;
758
        String mnStorageServiceVersion = null;
759
        String mnReplicationServiceVersion = null;
760

    
761
        boolean nodeSynchronize = false;
762
        boolean nodeReplicate = false;
763
        boolean mnCoreServiceAvailable = false;
764
        boolean mnReadServiceAvailable = false;
765
        boolean mnAuthorizationServiceAvailable = false;
766
        boolean mnStorageServiceAvailable = false;
767
        boolean mnReplicationServiceAvailable = false;
768

    
769
        try {
770
            // get the properties of the node based on configuration information
771
            nodeName = PropertyService.getProperty("dataone.nodeName");
772
            nodeId = PropertyService.getProperty("dataone.memberNodeId");
773
            subject = PropertyService.getProperty("dataone.subject");
774
            contactSubject = PropertyService.getProperty("dataone.contactSubject");
775
            nodeDesc = PropertyService.getProperty("dataone.nodeDescription");
776
            nodeTypeString = PropertyService.getProperty("dataone.nodeType");
777
            nodeType = NodeType.convert(nodeTypeString);
778
            nodeSynchronize = new Boolean(PropertyService.getProperty("dataone.nodeSynchronize")).booleanValue();
779
            nodeReplicate = new Boolean(PropertyService.getProperty("dataone.nodeReplicate")).booleanValue();
780

    
781
            mnCoreServiceVersion = PropertyService.getProperty("dataone.mnCore.serviceVersion");
782
            mnReadServiceVersion = PropertyService.getProperty("dataone.mnRead.serviceVersion");
783
            mnAuthorizationServiceVersion = PropertyService.getProperty("dataone.mnAuthorization.serviceVersion");
784
            mnStorageServiceVersion = PropertyService.getProperty("dataone.mnStorage.serviceVersion");
785
            mnReplicationServiceVersion = PropertyService.getProperty("dataone.mnReplication.serviceVersion");
786

    
787
            mnCoreServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnCore.serviceAvailable")).booleanValue();
788
            mnReadServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnRead.serviceAvailable")).booleanValue();
789
            mnAuthorizationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnAuthorization.serviceAvailable")).booleanValue();
790
            mnStorageServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnStorage.serviceAvailable")).booleanValue();
791
            mnReplicationServiceAvailable = new Boolean(PropertyService.getProperty("dataone.mnReplication.serviceAvailable")).booleanValue();
792

    
793
            // Set the properties of the node based on configuration information and
794
            // calls to current status methods
795
            String serviceName = SystemUtil.getContextURL() + "/" + PropertyService.getProperty("dataone.serviceName");
796
            Node node = new Node();
797
            node.setBaseURL(serviceName + "/" + nodeTypeString);
798
            node.setDescription(nodeDesc);
799

    
800
            // set the node's health information
801
            node.setState(NodeState.UP);
802
            
803
            // set the ping response to the current value
804
            Ping canPing = new Ping();
805
            canPing.setSuccess(false);
806
            try {
807
            	Date pingDate = ping();
808
                canPing.setSuccess(pingDate != null);
809
            } catch (BaseException e) {
810
                e.printStackTrace();
811
                // guess it can't be pinged
812
            }
813
            
814
            node.setPing(canPing);
815

    
816
            NodeReference identifier = new NodeReference();
817
            identifier.setValue(nodeId);
818
            node.setIdentifier(identifier);
819
            Subject s = new Subject();
820
            s.setValue(subject);
821
            node.addSubject(s);
822
            Subject contact = new Subject();
823
            contact.setValue(contactSubject);
824
            node.addContactSubject(contact);
825
            node.setName(nodeName);
826
            node.setReplicate(nodeReplicate);
827
            node.setSynchronize(nodeSynchronize);
828

    
829
            // services: MNAuthorization, MNCore, MNRead, MNReplication, MNStorage
830
            Services services = new Services();
831

    
832
            Service sMNCore = new Service();
833
            sMNCore.setName("MNCore");
834
            sMNCore.setVersion(mnCoreServiceVersion);
835
            sMNCore.setAvailable(mnCoreServiceAvailable);
836

    
837
            Service sMNRead = new Service();
838
            sMNRead.setName("MNRead");
839
            sMNRead.setVersion(mnReadServiceVersion);
840
            sMNRead.setAvailable(mnReadServiceAvailable);
841

    
842
            Service sMNAuthorization = new Service();
843
            sMNAuthorization.setName("MNAuthorization");
844
            sMNAuthorization.setVersion(mnAuthorizationServiceVersion);
845
            sMNAuthorization.setAvailable(mnAuthorizationServiceAvailable);
846

    
847
            Service sMNStorage = new Service();
848
            sMNStorage.setName("MNStorage");
849
            sMNStorage.setVersion(mnStorageServiceVersion);
850
            sMNStorage.setAvailable(mnStorageServiceAvailable);
851

    
852
            Service sMNReplication = new Service();
853
            sMNReplication.setName("MNReplication");
854
            sMNReplication.setVersion(mnReplicationServiceVersion);
855
            sMNReplication.setAvailable(mnReplicationServiceAvailable);
856

    
857
            services.addService(sMNRead);
858
            services.addService(sMNCore);
859
            services.addService(sMNAuthorization);
860
            services.addService(sMNStorage);
861
            services.addService(sMNReplication);
862
            node.setServices(services);
863

    
864
            // Set the schedule for synchronization
865
            Synchronization synchronization = new Synchronization();
866
            Schedule schedule = new Schedule();
867
            Date now = new Date();
868
            schedule.setYear(PropertyService.getProperty("dataone.nodeSynchronization.schedule.year"));
869
            schedule.setMon(PropertyService.getProperty("dataone.nodeSynchronization.schedule.mon"));
870
            schedule.setMday(PropertyService.getProperty("dataone.nodeSynchronization.schedule.mday"));
871
            schedule.setWday(PropertyService.getProperty("dataone.nodeSynchronization.schedule.wday"));
872
            schedule.setHour(PropertyService.getProperty("dataone.nodeSynchronization.schedule.hour"));
873
            schedule.setMin(PropertyService.getProperty("dataone.nodeSynchronization.schedule.min"));
874
            schedule.setSec(PropertyService.getProperty("dataone.nodeSynchronization.schedule.sec"));
875
            synchronization.setSchedule(schedule);
876
            synchronization.setLastHarvested(now);
877
            synchronization.setLastCompleteHarvest(now);
878
            node.setSynchronization(synchronization);
879

    
880
            node.setType(nodeType);
881
            return node;
882

    
883
        } catch (PropertyNotFoundException pnfe) {
884
            String msg = "MNodeService.getCapabilities(): " + "property not found: " + pnfe.getMessage();
885
            logMetacat.error(msg);
886
            throw new ServiceFailure("2162", msg);
887
        }
888
    }
889

    
890
    /**
891
     * Returns the number of operations that have been serviced by the node 
892
     * over time periods of one and 24 hours.
893
     * 
894
     * @param session - the Session object containing the credentials for the Subject
895
     * @param period - An ISO8601 compatible DateTime range specifying the time 
896
     *                 range for which to return operation statistics.
897
     * @param requestor - Limit to operations performed by given requestor identity.
898
     * @param event -  Enumerated value indicating the type of event being examined
899
     * @param format - Limit to events involving objects of the specified format
900
     * 
901
     * @return the desired log records
902
     * 
903
     * @throws InvalidToken
904
     * @throws ServiceFailure
905
     * @throws NotAuthorized
906
     * @throws InvalidRequest
907
     * @throws NotImplemented
908
     */
909
    public MonitorList getOperationStatistics(Session session, Date startTime, 
910
        Date endTime, Subject requestor, Event event, ObjectFormatIdentifier formatId)
911
        throws NotImplemented, ServiceFailure, NotAuthorized, InsufficientResources, UnsupportedType {
912

    
913
        MonitorList monitorList = new MonitorList();
914

    
915
        try {
916

    
917
            // get log records first
918
            Log logs = getLogRecords(session, startTime, endTime, event, 0, null);
919

    
920
            // TODO: aggregate by day or hour -- needs clarification
921
            int count = 1;
922
            for (LogEntry logEntry : logs.getLogEntryList()) {
923
                Identifier pid = logEntry.getIdentifier();
924
                Date logDate = logEntry.getDateLogged();
925
                // if we are filtering by format
926
                if (formatId != null) {
927
                    SystemMetadata sysmeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
928
                    if (!sysmeta.getFormatId().getValue().equals(formatId.getValue())) {
929
                        // does not match
930
                        continue;
931
                    }
932
                }
933
                MonitorInfo item = new MonitorInfo();
934
                item.setCount(count);
935
                item.setDate(new java.sql.Date(logDate.getTime()));
936
                monitorList.addMonitorInfo(item);
937

    
938
            }
939
        } catch (Exception e) {
940
            e.printStackTrace();
941
            throw new ServiceFailure("2081", "Could not retrieve statistics: " + e.getMessage());
942
        }
943

    
944
        return monitorList;
945

    
946
    }
947

    
948
    /**
949
     * A callback method used by a CN to indicate to a MN that it cannot 
950
     * complete synchronization of the science metadata identified by pid.  Log
951
     * the event in the metacat event log.
952
     * 
953
     * @param session
954
     * @param syncFailed
955
     * 
956
     * @throws ServiceFailure
957
     * @throws NotAuthorized
958
     * @throws NotImplemented
959
     */
960
    @Override
961
    public void synchronizationFailed(Session session, SynchronizationFailed syncFailed) 
962
        throws NotImplemented, ServiceFailure, NotAuthorized {
963

    
964
        String localId;
965

    
966
        try {
967
            localId = IdentifierManager.getInstance().getLocalId(syncFailed.getPid());
968
        } catch (McdbDocNotFoundException e) {
969
            throw new ServiceFailure("2161", "The identifier specified by " + syncFailed.getPid() + " was not found on this node.");
970

    
971
        }
972
        // TODO: update the CN URL below when the CNRead.SynchronizationFailed
973
        // method is changed to include the URL as a parameter
974
        logMetacat.debug("Synchronization for the object identified by " + syncFailed.getPid() + " failed from " + syncFailed.getNodeId()
975
                + " Logging the event to the Metacat EventLog as a 'syncFailed' event.");
976
        // TODO: use the event type enum when the SYNCHRONIZATION_FAILED event is added
977
        String principal = Constants.SUBJECT_PUBLIC;
978
        if (session != null && session.getSubject() != null) {
979
          principal = session.getSubject().getValue();
980
        }
981
        try {
982
          EventLog.getInstance().log(request.getRemoteAddr(), request.getHeader("User-Agent"), principal, localId, "synchronization_failed");
983
        } catch (Exception e) {
984
            throw new ServiceFailure("2161", "Could not log the error for: " + syncFailed.getPid());
985
    }
986
        //EventLog.getInstance().log("CN URL WILL GO HERE", 
987
        //  session.getSubject().getValue(), localId, Event.SYNCHRONIZATION_FAILED);
988

    
989
    }
990

    
991
    /**
992
     * Essentially a get() but with different logging behavior
993
     */
994
    @Override
995
    public InputStream getReplica(Session session, Identifier pid) 
996
        throws NotAuthorized, NotImplemented, ServiceFailure, InvalidToken {
997

    
998
        logMetacat.info("MNodeService.getReplica() called.");
999

    
1000
        // cannot be called by public
1001
        if (session == null) {
1002
        	throw new InvalidToken("2183", "No session was provided.");
1003
        }
1004
        
1005
        logMetacat.info("MNodeService.getReplica() called with parameters: \n" +
1006
             "\tSession.Subject      = " + session.getSubject().getValue() + "\n" +
1007
             "\tIdentifier           = " + pid.getValue());
1008

    
1009
        InputStream inputStream = null; // bytes to be returned
1010
        handler = new MetacatHandler(new Timer());
1011
        boolean allowed = false;
1012
        String localId; // the metacat docid for the pid
1013

    
1014
        // get the local docid from Metacat
1015
        try {
1016
            localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
1017
        } catch (McdbDocNotFoundException e) {
1018
            throw new ServiceFailure("2181", "The object specified by " + 
1019
                    pid.getValue() + " does not exist at this node.");
1020
            
1021
        }
1022

    
1023
        Subject targetNodeSubject = session.getSubject();
1024

    
1025
        // check for authorization to replicate, null session to act as this source MN
1026
        try {
1027
            allowed = D1Client.getCN().isNodeAuthorized(null, targetNodeSubject, pid);
1028
        } catch (InvalidToken e1) {
1029
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
1030
                + e1.getMessage());
1031
            
1032
        } catch (NotFound e1) {
1033
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
1034
                    + e1.getMessage());
1035

    
1036
        } catch (InvalidRequest e1) {
1037
            throw new ServiceFailure("2181", "Could not determine if node is authorized: " 
1038
                    + e1.getMessage());
1039

    
1040
        }
1041

    
1042
        logMetacat.info("Called D1Client.isNodeAuthorized(). Allowed = " + allowed +
1043
            " for identifier " + pid.getValue());
1044

    
1045
        // if the person is authorized, perform the read
1046
        if (allowed) {
1047
            try {
1048
                inputStream = handler.read(localId);
1049
            } catch (Exception e) {
1050
                throw new ServiceFailure("1020", "The object specified by " + 
1051
                    pid.getValue() + "could not be returned due to error: " + e.getMessage());
1052
            }
1053
        }
1054

    
1055
        // if we fail to set the input stream
1056
        if (inputStream == null) {
1057
            throw new ServiceFailure("2181", "The object specified by " + 
1058
                pid.getValue() + "does not exist at this node.");
1059
        }
1060

    
1061
        // log the replica event
1062
        String principal = null;
1063
        if (session.getSubject() != null) {
1064
            principal = session.getSubject().getValue();
1065
        }
1066
        EventLog.getInstance().log(request.getRemoteAddr(), 
1067
            request.getHeader("User-Agent"), principal, localId, "replicate");
1068

    
1069
        return inputStream;
1070
    }
1071

    
1072
    /**
1073
     * A method to notify the Member Node that the authoritative copy of 
1074
     * system metadata on the Coordinating Nodes has changed.
1075
     * 
1076
     * @param session   Session information that contains the identity of the 
1077
     *                  calling user as retrieved from the X.509 certificate 
1078
     *                  which must be traceable to the CILogon service.
1079
     * @param serialVersion   The serialVersion of the system metadata
1080
     * @param dateSysMetaLastModified  The time stamp for when the system metadata was changed
1081
     * @throws NotImplemented
1082
     * @throws ServiceFailure
1083
     * @throws NotAuthorized
1084
     * @throws InvalidRequest
1085
     * @throws InvalidToken
1086
     */
1087
    public void systemMetadataChanged(Session session, Identifier pid,
1088
        long serialVersion, Date dateSysMetaLastModified) 
1089
        throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest,
1090
        InvalidToken {
1091
        
1092
        SystemMetadata currentLocalSysMeta = null;
1093
        SystemMetadata newSysMeta = null;
1094
        CNode cn = D1Client.getCN();
1095
        NodeList nodeList = null;
1096
        Subject callingSubject = null;
1097
        boolean allowed = false;
1098
        
1099
        // are we allowed to call this?
1100
        callingSubject = session.getSubject();
1101
        nodeList = cn.listNodes();
1102
        
1103
        for(Node node : nodeList.getNodeList()) {
1104
            // must be a CN
1105
            if ( node.getType().equals(NodeType.CN)) {
1106
               List<Subject> subjectList = node.getSubjectList();
1107
               // the calling subject must be in the subject list
1108
               if ( subjectList.contains(callingSubject)) {
1109
                   allowed = true;
1110
                   
1111
               }
1112
               
1113
            }
1114
        }
1115
        
1116
        if (!allowed ) {
1117
            String msg = "The subject identified by " + callingSubject.getValue() +
1118
              " is not authorized to call this service.";
1119
            throw new NotAuthorized("1331", msg);
1120
            
1121
        }
1122
        
1123
        // compare what we have locally to what is sent in the change notification
1124
        try {
1125
            currentLocalSysMeta = HazelcastService.getInstance().getSystemMetadataMap().get(pid);
1126
             
1127
        } catch (RuntimeException e) {
1128
            String msg = "SystemMetadata for pid " + pid.getValue() +
1129
              " couldn't be updated because it couldn't be found locally: " +
1130
              e.getMessage();
1131
            logMetacat.error(msg);
1132
            ServiceFailure sf = new ServiceFailure("1333", msg);
1133
            sf.initCause(e);
1134
            throw sf; 
1135
        }
1136
        
1137
        if (currentLocalSysMeta.getSerialVersion().longValue() < serialVersion ) {
1138
            try {
1139
                newSysMeta = cn.getSystemMetadata(null, pid);
1140
            } catch (NotFound e) {
1141
                // huh? you just said you had it
1142
            	String msg = "On updating the local copy of system metadata " + 
1143
                "for pid " + pid.getValue() +", the CN reports it is not found." +
1144
                " The error message was: " + e.getMessage();
1145
                logMetacat.error(msg);
1146
                ServiceFailure sf = new ServiceFailure("1333", msg);
1147
                sf.initCause(e);
1148
                throw sf;
1149
            }
1150
            
1151
            // update the local copy of system metadata for the pid
1152
            try {
1153
                HazelcastService.getInstance().getSystemMetadataMap().put(newSysMeta.getIdentifier(), newSysMeta);
1154
                logMetacat.info("Updated local copy of system metadata for pid " +
1155
                    pid.getValue() + " after change notification from the CN.");
1156
                
1157
            } catch (RuntimeException e) {
1158
                String msg = "SystemMetadata for pid " + pid.getValue() +
1159
                  " couldn't be updated: " +
1160
                  e.getMessage();
1161
                logMetacat.error(msg);
1162
                ServiceFailure sf = new ServiceFailure("1333", msg);
1163
                sf.initCause(e);
1164
                throw sf;
1165
            }
1166
        }
1167
        
1168
    }
1169
    
1170
    /*
1171
     * Set the replication status for the object on the Coordinating Node
1172
     * 
1173
     * @param session - the session for the this target node
1174
     * @param pid - the identifier of the object being updated
1175
     * @param nodeId - the identifier of this target node
1176
     * @param status - the replication status to set
1177
     * @param failure - the exception to include, if any
1178
     */
1179
    private void setReplicationStatus(Session session, Identifier pid, 
1180
        NodeReference nodeId, ReplicationStatus status, BaseException failure) 
1181
        throws ServiceFailure, NotImplemented, NotAuthorized, 
1182
        InvalidRequest {
1183
        
1184
        // call the CN as the MN to set the replication status
1185
        try {
1186
            this.cn = D1Client.getCN();
1187
            this.cn.setReplicationStatus(session, pid, nodeId,
1188
                    status, failure);
1189
            
1190
        } catch (InvalidToken e) {
1191
            throw new ServiceFailure("2151",
1192
                    "Could not set the replication status on the CN (InvalidToken): " + 
1193
                    e.getMessage());
1194
            
1195
        } catch (NotFound e) {
1196
            throw new ServiceFailure("2151",
1197
                    "Could not set the replication status on the CN (NotFound): " + 
1198
                    e.getMessage());
1199
            
1200
        }
1201

    
1202

    
1203
    }
1204
    
1205
}
(3-3/5)