Project

General

Profile

« Previous | Next » 

Revision 6600

Add in the systemMetadataChanged() method in MNodeService to respond to notifications. Only allow subjects from CNs listed in the node list to make the call. Update the local copy of the system metadata document for the given pid.

View differences:

src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
27 27
import java.io.InputStream;
28 28
import java.security.NoSuchAlgorithmException;
29 29
import java.sql.SQLException;
30
import java.util.ArrayList;
30 31
import java.util.Calendar;
31 32
import java.util.Date;
32 33
import java.util.List;
......
68 69
import org.dataone.service.types.v1.MonitorInfo;
69 70
import org.dataone.service.types.v1.MonitorList;
70 71
import org.dataone.service.types.v1.Node;
72
import org.dataone.service.types.v1.NodeList;
71 73
import org.dataone.service.types.v1.NodeReference;
72 74
import org.dataone.service.types.v1.NodeState;
73 75
import org.dataone.service.types.v1.NodeType;
......
81 83
import org.dataone.service.types.v1.Services;
82 84
import org.dataone.service.types.v1.Session;
83 85
import org.dataone.service.types.v1.Subject;
86
import org.dataone.service.types.v1.SubjectList;
84 87
import org.dataone.service.types.v1.Synchronization;
85 88
import org.dataone.service.types.v1.SystemMetadata;
86 89
import org.dataone.service.types.v1.util.ChecksumUtil;
......
976 979
    }
977 980

  
978 981
    /**
979
     * A method to notifiy the Member Node that the authoritative copy of 
982
     * A method to notify the Member Node that the authoritative copy of 
980 983
     * system metadata on the Coordinating Nodes has changed.
981 984
     * 
982 985
     * @param session   Session information that contains the identity of the 
......
995 998
        throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest,
996 999
        InvalidToken {
997 1000
        
1001
        SystemMetadata currentLocalSysMeta = null;
1002
        SystemMetadata newSysMeta = null;
1003
        CNode cn = D1Client.getCN();
1004
        NodeList nodeList = null;
1005
        Subject callingSubject = null;
1006
        boolean allowed = false;
1007
        
1008
        // are we allowed to call this?
1009
        callingSubject = session.getSubject();
1010
        nodeList = cn.listNodes();
1011
        
1012
        for(Node node : nodeList.getNodeList()) {
1013
            // must be a CN
1014
            if ( node.getType().equals(NodeType.CN)) {
1015
               List<Subject> subjectList = node.getSubjectList();
1016
               // the calling subject must be in the subject list
1017
               if ( subjectList.contains(callingSubject)) {
1018
                   allowed = true;
1019
                   
1020
               }
1021
               
1022
            }
1023
        }
1024
        
1025
        if (!allowed ) {
1026
            String msg = "The subject identified by " + callingSubject.getValue() +
1027
              " is not authorized to call this service.";
1028
            throw new NotAuthorized("1331", msg);
1029
            
1030
        }
1031
        
1032
        // compare what we have locally to what is sent in the change notification
1033
        try {
1034
            currentLocalSysMeta = 
1035
                IdentifierManager.getInstance().getSystemMetadata(pid.getValue());
1036
        
1037
        } catch (McdbDocNotFoundException e) {
1038
            String msg = "SystemMetadata for pid " + pid.getValue() +
1039
              " cpouldn't be updated because it couldn't be found locally: " +
1040
              e.getMessage();
1041
            logMetacat.warn(msg);
1042
            
1043
        }
1044
        
1045
        if (currentLocalSysMeta.getSerialVersion().longValue() < serialVersion ) {
1046
            try {
1047
                newSysMeta = cn.getSystemMetadata(null, pid);
1048
            } catch (NotFound e) {
1049
                // huh? you just said you had it
1050
                logMetacat.error("On updating the local copy of system metadata " + 
1051
                    "for pid " + pid.getValue() +", the CN reports it is not found." +
1052
                    " The error message was: " + e.getMessage());
1053
                
1054
            }
1055
            // update the local copy of system metadata for the pid
1056
            try {
1057
                IdentifierManager.getInstance().updateSystemMetadata(newSysMeta);
1058
                logMetacat.info("Updated local copy of system metadata for pid " +
1059
                    pid.getValue() + " after change notification from the CN.");
1060
                
1061
            } catch (McdbDocNotFoundException e) {
1062
                String msg = "SystemMetadata for pid " + pid.getValue() +
1063
                  " cpouldn't be updated because it couldn't be found: " +
1064
                  e.getMessage();
1065
                logMetacat.warn(msg);
1066
                
1067
            }
1068
        }
1069
        
998 1070
    }
999 1071
    
1000 1072
}

Also available in: Unified diff