Project

General

Profile

« Previous | Next » 

Revision 6493

Register as a MN on the DataONE network as part of the properties setup. This is currently done always, but it needs to be conditional rather than automatically triggered.

View differences:

src/edu/ucsb/nceas/metacat/admin/PropertiesAdmin.java
32 32
import javax.servlet.http.HttpServletResponse;
33 33

  
34 34
import org.apache.log4j.Logger;
35
import org.dataone.client.CNode;
36
import org.dataone.client.D1Client;
37
import org.dataone.client.auth.CertificateManager;
38
import org.dataone.service.exceptions.IdentifierNotUnique;
39
import org.dataone.service.exceptions.InvalidRequest;
40
import org.dataone.service.exceptions.NotAuthorized;
41
import org.dataone.service.exceptions.NotImplemented;
42
import org.dataone.service.exceptions.ServiceFailure;
43
import org.dataone.service.types.v1.Node;
44
import org.dataone.service.types.v1.NodeReference;
45
import org.dataone.service.types.v1.Session;
35 46

  
36 47
import edu.ucsb.nceas.metacat.MetacatVersion;
37 48
import edu.ucsb.nceas.metacat.database.DBVersion;
49
import edu.ucsb.nceas.metacat.dataone.MNodeService;
38 50
import edu.ucsb.nceas.metacat.properties.PropertyService;
39 51
import edu.ucsb.nceas.metacat.service.ServiceService;
40 52
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
41 53
import edu.ucsb.nceas.metacat.shared.ServiceException;
42 54
import edu.ucsb.nceas.metacat.util.RequestUtil;
43 55
import edu.ucsb.nceas.metacat.util.SystemUtil;
44

  
45 56
import edu.ucsb.nceas.utilities.FileUtil;
46 57
import edu.ucsb.nceas.utilities.GeneralPropertyException;
47 58
import edu.ucsb.nceas.utilities.PropertiesMetaData;
......
251 262
					validationErrors.add(errorString);
252 263
				}
253 264

  
265
		        // Register as a DataONE Member Node
266
				registerDataONEMemberNode();
267
				
254 268
				// write the backup properties to a location outside the 
255 269
				// application directories so they will be available after
256 270
				// the next upgrade
......
331 345

  
332 346
		return errorVector;
333 347
	}
348
	
349
	/**
350
	 * Register as a member node on the DataONE network.  The node description is
351
	 * retrieved from the getCapabilities() service, and so this should only be called
352
	 * after the properties have been properly set up in Metacat.
353
	 */
354
	private void registerDataONEMemberNode() {
355
        CNode cn;
356
        try {
357
            logMetacat.debug("Setting client certificate location.");
358
            String mnCertificatePath = "/etc/dataone/client/certs/DEMO01.pem";
359
            CertificateManager.getInstance().setCertificateLocation(mnCertificatePath);
360
            cn = D1Client.getCN();
361
            logMetacat.debug("Get the Node description.");
362
            Node node = MNodeService.getInstance().getCapabilities();
363
            logMetacat.debug("Registering node with DataONE.");
364
            // Session is null, because the libclient code automatically sets up an
365
            // SSL session for us using the client certificate provided
366
            Session session = null;
367
            NodeReference mnode = cn.register(session, node);
368
        } catch (ServiceFailure e) {
369
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
370
        } catch (NotImplemented e) {
371
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
372
        } catch (NotAuthorized e) {
373
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
374
        } catch (InvalidRequest e) {
375
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
376
        } catch (IdentifierNotUnique e) {
377
            logMetacat.warn("Could not register as node with DataONE (" + e.getCode() + "/" + e.getDetail_code() + "): " + e.getDescription());
378
        }
379
	}
334 380
}

Also available in: Unified diff