Project

General

Profile

« Previous | Next » 

Revision 6570

In CNodeService, separate the CN.create() functionality from the MN.create() functionality while still using the superclass to call create(). Deal with Hazelcast locks and setting serial versions only in the CN implementation.

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
56 56
import org.dataone.service.types.v1.Node;
57 57
import org.dataone.service.types.v1.NodeList;
58 58
import org.dataone.service.types.v1.NodeReference;
59
import org.dataone.service.types.v1.NodeType;
59 60
import org.dataone.service.types.v1.ObjectFormat;
60 61
import org.dataone.service.types.v1.ObjectFormatIdentifier;
61 62
import org.dataone.service.types.v1.ObjectFormatList;
......
906 907
  }
907 908

  
908 909
  /**
909
   * Adds a new object to the Node, where the object is either a data 
910
   * object or a science metadata object. This method is called by clients 
911
   * to create new data objects on Member Nodes or internally for Coordinating
912
   * Nodes
910
   * Adds a new object to the Node, where the object is a science metadata object.
913 911
   * 
914 912
   * @param session - the Session object containing the credentials for the Subject
915 913
   * @param pid - The object identifier to be created
......
933 931
    throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, 
934 932
    UnsupportedType, InsufficientResources, InvalidSystemMetadata, 
935 933
    NotImplemented, InvalidRequest {
936
        
934
      
935
      
936
      try {
937
        // are we allowed?
938
          boolean isAllowed = false;
939
          CNode cn = D1Client.getCN();
940
          List<Node> nodes = (List<Node>) cn.listNodes();
941
          
942
          for (Node node : nodes) {
943
              if ( node.getType().equals(NodeType.CN) ) {
944
                  
945
                  List<Subject> subjects = node.getSubjectList();
946
                  for (Subject subject : subjects) {
947
                     if (subject.getValue().equals(session.getSubject().getValue())) {
948
                         isAllowed = true;
949
                         break;
950
                     }
951
                  }
952
              }
953
          }
954

  
955
          // proceed if we're called by a CN
956
          if ( isAllowed ) {
957
              // create the coordinating node version of the document      
958
              HazelcastService.getInstance().getSystemMetadataMap().lock(pid);
959
              sysmeta.setSerialVersion(BigInteger.ONE);
960
              sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
961
              pid = super.create(session, pid, object, sysmeta);
962
              HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
963

  
964
          } else {
965
              String msg = "The subject listed as " + session.getSubject().getValue() + 
966
                  " isn't allowed to call create() on a Coordinating Node.";
967
              logMetacat.info(msg);
968
              throw new NotAuthorized("1100", msg);
969
          }
970
          
971
      } catch (Exception e) {
972
          // Convert Hazelcast runtime exceptions to service failures
973
          String msg = "There was a problem creating the object identified by " +
974
              pid.getValue() + ". There error message was: " + e.getMessage();
975
          
976
      } finally {
977
          HazelcastService.getInstance().getSystemMetadataMap().unlock(pid);
978
      
979
      }
980
      
937 981
      return pid;
938 982

  
939 983
  }

Also available in: Unified diff