Project

General

Profile

« Previous | Next » 

Revision 6862

update authoritative member node id when we change it (reconfiguration) and when we initially register as a MN with the CN.

View differences:

src/edu/ucsb/nceas/metacat/admin/D1Admin.java
26 26

  
27 27
package edu.ucsb.nceas.metacat.admin;
28 28

  
29
import java.io.File;
30 29
import java.util.Vector;
31 30

  
32 31
import javax.servlet.http.HttpServletRequest;
......
37 36
import org.dataone.client.D1Client;
38 37
import org.dataone.client.auth.CertificateManager;
39 38
import org.dataone.service.exceptions.BaseException;
40
import org.dataone.service.exceptions.IdentifierNotUnique;
41
import org.dataone.service.exceptions.InvalidRequest;
42
import org.dataone.service.exceptions.InvalidToken;
43
import org.dataone.service.exceptions.NotAuthorized;
44
import org.dataone.service.exceptions.NotFound;
45
import org.dataone.service.exceptions.NotImplemented;
46
import org.dataone.service.exceptions.ServiceFailure;
47 39
import org.dataone.service.types.v1.Node;
48 40
import org.dataone.service.types.v1.NodeList;
49 41
import org.dataone.service.types.v1.NodeReference;
50 42
import org.dataone.service.types.v1.Session;
51 43

  
44
import edu.ucsb.nceas.metacat.IdentifierManager;
52 45
import edu.ucsb.nceas.metacat.dataone.MNodeService;
53 46
import edu.ucsb.nceas.metacat.properties.PropertyService;
54 47
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
55 48
import edu.ucsb.nceas.metacat.util.RequestUtil;
56
import edu.ucsb.nceas.metacat.util.SystemUtil;
57
import edu.ucsb.nceas.utilities.FileUtil;
58 49
import edu.ucsb.nceas.utilities.GeneralPropertyException;
59 50
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
60 51

  
......
257 248
					
258 249
					PropertyService.setPropertyNoPersist("dataone.nodeName", nodeName);
259 250
					PropertyService.setPropertyNoPersist("dataone.nodeDescription", nodeDescription);
251
					
252
					// check if we have updated the memberNodeId
253
					String existingMemberNodeId = PropertyService.getProperty("dataone.memberNodeId");
254
					if (!existingMemberNodeId.equals(memberNodeId)) {
255
						// update all existing system Metadata for this node id
256
						IdentifierManager.getInstance().updateAuthoritativeMemberNodeId(existingMemberNodeId, memberNodeId);
257
					}
258
					// TODO: persist in DB?
260 259
					PropertyService.setPropertyNoPersist("dataone.memberNodeId", memberNodeId);
260
					
261 261
					PropertyService.setPropertyNoPersist("dataone.nodeSynchronize", Boolean.toString(synchronize));
262 262
					PropertyService.setPropertyNoPersist("dataone.nodeReplicate", Boolean.toString(replicate));
263 263
					PropertyService.setPropertyNoPersist("dataone.subject", subject);
......
319 319
			}
320 320
		}
321 321
	}
322
	
322

  
323 323
	/**
324 324
	 * Register as a member node on the DataONE network.  The node description is
325 325
	 * retrieved from the getCapabilities() service, and so this should only be called
......
352 352
            } else {
353 353
	            logMetacat.debug("Registering node with DataONE. " + cn.getNodeBaseServiceUrl());
354 354
	            NodeReference mnodeRef = cn.register(session, node);
355
	            
356
	            String memberNodeId = mnodeRef.getValue();
357
	            String existingMemberNodeId = PropertyService.getProperty("dataone.memberNodeId");
358
				if (!existingMemberNodeId.equals(memberNodeId)) {
359
					// update all existing system Metadata for this node id
360
					IdentifierManager.getInstance().updateAuthoritativeMemberNodeId(existingMemberNodeId, memberNodeId);
361
				}
355 362
	            // save this assigned node id
356
	            PropertyService.setProperty("dataone.memberNodeId", mnodeRef.getValue());
363
	            PropertyService.setProperty("dataone.memberNodeId", memberNodeId);
357 364
	            
358 365
            }
359 366
        } catch (BaseException e) {
src/edu/ucsb/nceas/metacat/IdentifierManager.java
1694 1694
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1695 1695
        }
1696 1696
    }
1697
    
1698
    public void updateAuthoritativeMemberNodeId(String existingMemberNodeId, String newMemberNodeId)
1699
    {
1700
        DBConnection dbConn = null;
1701
        int serialNumber = -1;
1702
        
1703
        try {
1704
            // Get a database connection from the pool
1705
            dbConn = DBConnectionPool.getDBConnection("IdentifierManager.updateAuthoritativeMemberNodeId");
1706
            serialNumber = dbConn.getCheckOutSerialNumber();
1707

  
1708
            // Execute the insert statement
1709
            String query = "update " + TYPE_SYSTEM_METADATA + 
1710
                " set authoritive_member_node = ? " +
1711
                " where authoritive_member_node = ?";
1712
            PreparedStatement stmt = dbConn.prepareStatement(query);
1713
            
1714
            //data values
1715
            stmt.setString(1, newMemberNodeId);
1716
            stmt.setString(2, existingMemberNodeId);
1717

  
1718
            logMetacat.debug("stmt: " + stmt.toString());
1719
            //execute
1720
            int rows = stmt.executeUpdate();
1721

  
1722
            stmt.close();
1723
        } catch (SQLException e) {
1724
            e.printStackTrace();
1725
            logMetacat.error("updateSystemMetadataFields: SQL error while updating system metadata: " 
1726
                    + e.getMessage());
1727
        } catch (NumberFormatException e) {
1728
            e.printStackTrace();
1729
            logMetacat.error("updateSystemMetadataFields: NumberFormat error while updating system metadata: " 
1730
                    + e.getMessage());
1731
        } finally {
1732
            // Return database connection to the pool
1733
            DBConnectionPool.returnDBConnection(dbConn, serialNumber);
1734
        }
1735
    }
1697 1736
}
1698 1737

  

Also available in: Unified diff