Project

General

Profile

« Previous | Next » 

Revision 10376

Added by Jing Tao over 6 years ago

Add the client code to submit the index task to the message broker. Now I only added the code for the create method.

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
44 44
import org.dataone.client.v2.CNode;
45 45
import org.dataone.client.v2.MNode;
46 46
import org.dataone.client.v2.itk.D1Client;
47
import org.dataone.cn.index.messaging.IndexTaskMessagingClient;
48
import org.dataone.cn.index.messaging.IndexTaskMessagingClientFactory;
49
import org.dataone.cn.index.task.IndexTask;
50
import org.dataone.cn.index.task.IndexTaskGenerator;
47 51
import org.dataone.exceptions.MarshallingException;
48 52
import org.dataone.service.cn.v2.CNAuthorization;
49 53
import org.dataone.service.cn.v2.CNCore;
......
87 91
import org.dataone.service.types.v2.SystemMetadata;
88 92
import org.dataone.service.util.TypeMarshaller;
89 93

  
90

  
91 94
import edu.ucsb.nceas.metacat.DBUtil;
92 95
import edu.ucsb.nceas.metacat.EventLog;
93 96
import edu.ucsb.nceas.metacat.IdentifierManager;
......
110 113
  private Logger logMetacat = null;
111 114
  public final static String V2V1MISSMATCH = "The Coordinating Node is not authorized to make systemMetadata changes on this object. Please make changes directly on the authoritative Member Node.";
112 115

  
116
  private IndexTaskMessagingClient indexTaskClient = null;
113 117
  /**
114 118
   * singleton accessor
115 119
   */
......
123 127
  private CNodeService(HttpServletRequest request) {
124 128
    super(request);
125 129
    logMetacat = Logger.getLogger(CNodeService.class);
126
        
130
    try {
131
        getIndexTaskClient();
132
    } catch (Exception e) {
133
        logMetacat.warn("CNodeService.constructorr - the client for sumbitting the index tasks couldn't be initialized since "+e.getMessage(), e);
134
    } 
127 135
  }
136
  
137
  /*
138
   * Method to get the index tasks client.
139
   */
140
  private void getIndexTaskClient() throws InstantiationException, IllegalAccessException, ClassNotFoundException {
141
      if(indexTaskClient == null) {
142
          indexTaskClient = IndexTaskMessagingClientFactory.getClient();
143
      }
144
  }
145
  
146
  /*
147
   * Submit a index task to the message broker.
148
   */
149
  private void submitIndexTask(SystemMetadata sysmeta, String objectURI) throws ServiceFailure, InvalidSystemMetadata, InstantiationException, IllegalAccessException, ClassNotFoundException {
150
      if(indexTaskClient == null) {
151
          getIndexTaskClient();
152
      }
153
      IndexTaskGenerator generator = new IndexTaskGenerator();
154
      IndexTask task = generator.generateAddTask(sysmeta, objectURI);
155
      indexTaskClient.submit(task);
156

  
157
  }
128 158
    
129 159
  /**
130 160
   * Set the replication policy for an object given the object identifier
......
1869 1899
                  
1870 1900
              }
1871 1901
              pid = super.create(session, pid, object, sysmeta);
1872

  
1902
              // submit the index task to the message broker.
1903
              try {
1904
                  String localId = IdentifierManager.getInstance().getLocalId(pid.getValue());
1905
                  String objectURI = IdentifierManager.getInstance().getObjectFilePath(localId, isScienceMetadata(sysmeta));
1906
                  submitIndexTask(sysmeta, objectURI);
1907
                  logMetacat.info("CNodeService.create - Metacat successfully submitted the index task for the object "+sysmeta.getIdentifier().getValue()+" to the message broker. But it is NOT guarranteed that the broker can get it.");
1908
              } catch (Exception e) {
1909
                  logMetacat.warn("CNodeService.create - the index task for the object "+sysmeta.getIdentifier().getValue()+" failed to be submitted to the message broker since "+e.getMessage(), e);
1910
              }
1911
              
1873 1912
          } else {
1874 1913
              String msg = "The subject listed as " + session.getSubject().getValue() + 
1875 1914
                  " isn't allowed to call create() on a Coordinating Node for pid "+pid.getValue();

Also available in: Unified diff