Project

General

Profile

« Previous | Next » 

Revision 6999

refactor D1-specific upgrade utilities into their own package

View differences:

test/edu/ucsb/nceas/metacat/admin/upgrade/GenerateSystemMetadataTest.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *  Purpose: To test the Access Controls in metacat by JUnit
6
 *
7
 *   '$Author$'
8
 *     '$Date$'
9
 * '$Revision$'
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
 */
25

  
26
package edu.ucsb.nceas.metacat.admin.upgrade;
27

  
28
import junit.framework.Test;
29
import junit.framework.TestSuite;
30
import edu.ucsb.nceas.MCTestCase;
31

  
32
/**
33
 * A JUnit test for testing system metadata generation
34
 */
35
public class GenerateSystemMetadataTest
36
    extends MCTestCase {
37
    
38
	/**
39
     * Constructor to build the test
40
     *
41
     * @param name the name of the test method
42
     */
43
    public GenerateSystemMetadataTest(String name) {
44
        super(name);
45
    }
46

  
47
    /**
48
     * Establish a testing framework by initializing appropriate objects
49
     */
50
    public void setUp() {
51
        
52
    }
53

  
54
    /**
55
     * Release any objects after tests are complete
56
     */
57
    public void tearDown() {
58
    }
59

  
60
    /**
61
     * Create a suite of tests to be run together
62
     */
63
    public static Test suite() {
64
        TestSuite suite = new TestSuite();
65
        suite.addTest(new GenerateSystemMetadataTest("initialize"));
66
        // Test basic functions
67
        suite.addTest(new GenerateSystemMetadataTest("upgrade"));
68
        
69
        return suite;
70
    }
71

  
72
    /**
73
     * Run an initial test that always passes to check that the test
74
     * harness is working.
75
     */
76
    public void initialize() {
77
        assertTrue(1 == 1);
78
    }
79
    
80
    public void upgrade() throws Exception {
81
    	GenerateSystemMetadata upgrader = new GenerateSystemMetadata();
82
        upgrader.upgrade();
83
    }
84
    
85
}
86

  
87 0

  
src/edu/ucsb/nceas/metacat/admin/upgrade/GenerateORE.java
1
package edu.ucsb.nceas.metacat.admin.upgrade;
2
/**
3
 *  '$RCSfile$'
4
 *    Purpose: A Class for upgrading the database to version 1.5
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Saurabh Garg
8
 *
9
 *   '$Author$'
10
 *     '$Date$'
11
 * '$Revision$'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28

  
29
import java.util.Collections;
30
import java.util.List;
31

  
32
import org.apache.commons.logging.Log;
33
import org.apache.commons.logging.LogFactory;
34

  
35
import edu.ucsb.nceas.metacat.DBUtil;
36
import edu.ucsb.nceas.metacat.admin.AdminException;
37
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
38
import edu.ucsb.nceas.metacat.properties.PropertyService;
39
import edu.ucsb.nceas.utilities.SortedProperties;
40

  
41
public class GenerateORE implements UpgradeUtilityInterface {
42

  
43
	private static Log log = LogFactory.getLog(GenerateORE.class);
44
	
45
    public boolean upgrade() throws AdminException {
46
        boolean success = true;
47
        
48
        // include ORE, data, for this server only
49
        boolean includeOre = true;
50
        boolean downloadData = true;
51
        int serverLocation = 1;
52

  
53
        try {
54
        	// get only local ids for this server
55
            List<String> idList = DBUtil.getAllDocidsByType(null, true, serverLocation);
56
            Collections.sort(idList);
57

  
58
            // generate based on this list
59
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
60
		} catch (Exception e) {
61
			String msg = "Problem generating missing system metadata: " + e.getMessage();
62
			log.error(msg, e);
63
			success = false;
64
			throw new AdminException(msg);
65
		}
66
    	return success;
67
    }
68
    
69
    public static void main(String [] ags){
70

  
71
        try {
72
        	// set up the properties based on the test/deployed configuration of the workspace
73
        	SortedProperties testProperties = 
74
				new SortedProperties("test/test.properties");
75
			testProperties.load();
76
			String metacatContextDir = testProperties.getProperty("metacat.contextDir");
77
			PropertyService.getInstance(metacatContextDir + "/WEB-INF");
78
			// now run it
79
            GenerateORE upgrader = new GenerateORE();
80
	        upgrader.upgrade();
81
	        
82
        } catch (Exception ex) {
83
            System.out.println("Exception:" + ex.getMessage());
84
            ex.printStackTrace();
85
        }
86
    }
87
}
88 0

  
src/edu/ucsb/nceas/metacat/admin/upgrade/GenerateSystemMetadata.java
1
package edu.ucsb.nceas.metacat.admin.upgrade;
2
/**
3
 *  '$RCSfile$'
4
 *    Purpose: A Class for upgrading the database to version 1.5
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Saurabh Garg
8
 *
9
 *   '$Author: leinfelder $'
10
 *     '$Date: 2011-03-29 18:23:38 +0000 (Tue, 29 Mar 2011) $'
11
 * '$Revision: 6025 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28

  
29
import java.util.Collections;
30
import java.util.List;
31
import java.util.concurrent.ExecutorService;
32
import java.util.concurrent.Executors;
33
import java.util.concurrent.TimeUnit;
34

  
35
import org.apache.commons.logging.Log;
36
import org.apache.commons.logging.LogFactory;
37

  
38
import edu.ucsb.nceas.metacat.DBUtil;
39
import edu.ucsb.nceas.metacat.admin.AdminException;
40
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
41
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
42
import edu.ucsb.nceas.metacat.properties.PropertyService;
43
import edu.ucsb.nceas.utilities.SortedProperties;
44

  
45
public class GenerateSystemMetadata implements UpgradeUtilityInterface {
46

  
47
	private static Log log = LogFactory.getLog(GenerateSystemMetadata.class);
48
	
49
    public boolean upgrade() throws AdminException {
50
    	
51
    	// do this in a thread too so that we don't have to hang the UI (web)
52
    	ExecutorService executor = Executors.newSingleThreadExecutor();
53
    	Runnable command = new Runnable() {
54
			@Override
55
			public void run() {
56
				// just run it
57
				try {
58
					boolean success = multiThreadUpgrade();
59
				} catch (AdminException e) {
60
					throw new RuntimeException(e);
61
				}
62
			}
63
    	};
64
		executor.execute(command);
65
		executor.shutdown();
66
		
67
		// wait for it to finish before returning?
68
        boolean wait = false;
69
        if (wait) {
70
            log.debug("Waiting for upgrade to complete");
71
            try {
72
				executor.awaitTermination(Long.MAX_VALUE, TimeUnit.HOURS);
73
			} catch (InterruptedException e) {
74
				AdminException ae = new AdminException(e.getMessage());
75
				ae.initCause(e);
76
				throw ae;
77
			}
78
            log.debug("Done waiting for upgrade thread");
79
        }
80
		
81
    	return true;
82
        //return singleThreadUpgrade();
83
    }
84
    
85
    /**
86
     * Use multiple threads to process parts of the complete ID list concurrently
87
     * @return
88
     * @throws AdminException
89
     */
90
    public boolean multiThreadUpgrade() throws AdminException {
91
    	
92
        boolean success = true;
93
        
94
        // do not include ORE or data, but can generate SystemMetadata for ALL records
95
        final boolean includeOre = false;
96
        final boolean downloadData = false;
97
        int serverLocation = -1;
98
        
99
        try {
100
        	
101
        	// get list of ALL docids at ALL server locations
102
            List<String> idList = DBUtil.getAllDocidsByType(null, true, serverLocation);
103
            Collections.sort(idList);
104
            
105
            // executor
106
            int availableProcessors = Runtime.getRuntime().availableProcessors();
107
            int nThreads = availableProcessors * 1;
108
            //availableProcessors++;
109
        	log.debug("Using nThreads: " + nThreads);
110

  
111
            ExecutorService executor = Executors.newFixedThreadPool(nThreads);
112
            int taskCount = 0;
113

  
114
            // init HZ
115
            log.debug("Making sure Hazelcast is up");
116
            HazelcastService.getInstance();
117
            
118
            // chunk into groups
119
			int fromIndex = 0;
120
            int toIndex = 0;
121
            String prefix = null;
122
            for (String docid: idList) {
123

  
124
            	// increment the next entry, exclusive
125
            	toIndex++;
126
            	
127
            	// use scope.docid (without revision) to determine groups
128
            	if (prefix == null || !docid.startsWith(prefix)) {
129
            		
130
            		// construct a sublist for this previous group of docids
131
					final List<String> subList = idList.subList(fromIndex, toIndex);
132
	            	log.debug("Grouping docid prefix: " + prefix);
133
					log.debug("subList.size: " + subList.size());
134
					
135
					// add the task for this sublist
136
					Runnable command = new Runnable() {
137
						@Override
138
						public void run() {
139
							// generate based on this list
140
				            try {
141
				            	log.debug("Processing subList.size: " + subList.size());
142
								SystemMetadataFactory.generateSystemMetadata(subList, includeOre, downloadData);
143
								log.debug("Done processing subList.size: " + subList.size());
144
								
145
							} catch (Exception e) {
146
								throw new RuntimeException(e);
147
							}
148
						}
149
					};
150
					
151
					// execute the task 
152
					executor.execute(command);
153
					taskCount++;
154
					
155
					// start at the end of this sublist
156
					fromIndex = toIndex;
157

  
158
            	}
159

  
160
            	log.debug("docid: " + docid);
161

  
162
            	// get the previous docid prefix
163
            	String previousId = docid;
164
            	prefix = previousId.substring(0, previousId.lastIndexOf("."));
165
				
166
            }
167

  
168
            log.info("done launching threaded tasks, count: " + taskCount);
169

  
170
            // wait for executor to finish
171
            executor.shutdown();
172
            
173
			// wait a long time
174
            log.debug("Waiting for all threads to complete");
175
            executor.awaitTermination(Long.MAX_VALUE, TimeUnit.HOURS);
176
            log.debug("Done waiting for all threads to complete");
177
            // now we are ready to be a data one node
178
            PropertyService.setProperty("dataone.systemmetadata.generated", Boolean.TRUE.toString());
179
            
180
		} catch (Exception e) {
181
			String msg = "Problem generating missing system metadata: " + e.getMessage();
182
			log.error(msg, e);
183
			success = false;
184
			throw new AdminException(msg);
185
		}
186
    	return success;
187
    }
188
    
189
    public static void main(String [] ags){
190

  
191
        try {
192
        	// set up the properties based on the test/deployed configuration of the workspace
193
        	SortedProperties testProperties = 
194
				new SortedProperties("test/test.properties");
195
			testProperties.load();
196
			String metacatContextDir = testProperties.getProperty("metacat.contextDir");
197
			PropertyService.getInstance(metacatContextDir + "/WEB-INF");
198
			// now run it
199
            GenerateSystemMetadata upgrader = new GenerateSystemMetadata();
200
	        upgrader.upgrade();
201
	        
202
        } catch (Exception ex) {
203
            System.out.println("Exception:" + ex.getMessage());
204
            ex.printStackTrace();
205
        }
206
    }
207
}
test/edu/ucsb/nceas/metacat/admin/upgrade/dataone/GenerateSystemMetadataTest.java
1
/**
2
 *  '$RCSfile$'
3
 *  Copyright: 2004 Regents of the University of California and the
4
 *              National Center for Ecological Analysis and Synthesis
5
 *  Purpose: To test the Access Controls in metacat by JUnit
6
 *
7
 *   '$Author$'
8
 *     '$Date$'
9
 * '$Revision$'
10
 *
11
 * This program is free software; you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation; either version 2 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program; if not, write to the Free Software
23
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
 */
25

  
26
package edu.ucsb.nceas.metacat.admin.upgrade.dataone;
27

  
28
import junit.framework.Test;
29
import junit.framework.TestSuite;
30
import edu.ucsb.nceas.MCTestCase;
31
import edu.ucsb.nceas.metacat.admin.upgrade.dataone.GenerateSystemMetadata;
32

  
33
/**
34
 * A JUnit test for testing system metadata generation
35
 */
36
public class GenerateSystemMetadataTest
37
    extends MCTestCase {
38
    
39
	/**
40
     * Constructor to build the test
41
     *
42
     * @param name the name of the test method
43
     */
44
    public GenerateSystemMetadataTest(String name) {
45
        super(name);
46
    }
47

  
48
    /**
49
     * Establish a testing framework by initializing appropriate objects
50
     */
51
    public void setUp() {
52
        
53
    }
54

  
55
    /**
56
     * Release any objects after tests are complete
57
     */
58
    public void tearDown() {
59
    }
60

  
61
    /**
62
     * Create a suite of tests to be run together
63
     */
64
    public static Test suite() {
65
        TestSuite suite = new TestSuite();
66
        suite.addTest(new GenerateSystemMetadataTest("initialize"));
67
        // Test basic functions
68
        suite.addTest(new GenerateSystemMetadataTest("upgrade"));
69
        
70
        return suite;
71
    }
72

  
73
    /**
74
     * Run an initial test that always passes to check that the test
75
     * harness is working.
76
     */
77
    public void initialize() {
78
        assertTrue(1 == 1);
79
    }
80
    
81
    public void upgrade() throws Exception {
82
    	GenerateSystemMetadata upgrader = new GenerateSystemMetadata();
83
        upgrader.upgrade();
84
    }
85
    
86
}
87

  
0 88

  
src/edu/ucsb/nceas/metacat/admin/upgrade/dataone/GenerateORE.java
1
package edu.ucsb.nceas.metacat.admin.upgrade.dataone;
2
/**
3
 *  '$RCSfile$'
4
 *    Purpose: A Class for upgrading the database to version 1.5
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Saurabh Garg
8
 *
9
 *   '$Author$'
10
 *     '$Date$'
11
 * '$Revision$'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28

  
29
import java.util.Collections;
30
import java.util.List;
31

  
32
import org.apache.commons.logging.Log;
33
import org.apache.commons.logging.LogFactory;
34

  
35
import edu.ucsb.nceas.metacat.DBUtil;
36
import edu.ucsb.nceas.metacat.admin.AdminException;
37
import edu.ucsb.nceas.metacat.admin.upgrade.UpgradeUtilityInterface;
38
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
39
import edu.ucsb.nceas.metacat.properties.PropertyService;
40
import edu.ucsb.nceas.utilities.SortedProperties;
41

  
42
public class GenerateORE implements UpgradeUtilityInterface {
43

  
44
	private static Log log = LogFactory.getLog(GenerateORE.class);
45
	
46
    public boolean upgrade() throws AdminException {
47
        boolean success = true;
48
        
49
        // include ORE, data, for this server only
50
        boolean includeOre = true;
51
        boolean downloadData = true;
52
        int serverLocation = 1;
53

  
54
        try {
55
        	// get only local ids for this server
56
            List<String> idList = DBUtil.getAllDocidsByType(null, true, serverLocation);
57
            Collections.sort(idList);
58

  
59
            // generate based on this list
60
            SystemMetadataFactory.generateSystemMetadata(idList, includeOre, downloadData);
61
		} catch (Exception e) {
62
			String msg = "Problem generating missing system metadata: " + e.getMessage();
63
			log.error(msg, e);
64
			success = false;
65
			throw new AdminException(msg);
66
		}
67
    	return success;
68
    }
69
    
70
    public static void main(String [] ags){
71

  
72
        try {
73
        	// set up the properties based on the test/deployed configuration of the workspace
74
        	SortedProperties testProperties = 
75
				new SortedProperties("test/test.properties");
76
			testProperties.load();
77
			String metacatContextDir = testProperties.getProperty("metacat.contextDir");
78
			PropertyService.getInstance(metacatContextDir + "/WEB-INF");
79
			// now run it
80
            GenerateORE upgrader = new GenerateORE();
81
	        upgrader.upgrade();
82
	        
83
        } catch (Exception ex) {
84
            System.out.println("Exception:" + ex.getMessage());
85
            ex.printStackTrace();
86
        }
87
    }
88
}
0 89

  
src/edu/ucsb/nceas/metacat/admin/upgrade/dataone/GenerateSystemMetadata.java
1
package edu.ucsb.nceas.metacat.admin.upgrade.dataone;
2
/**
3
 *  '$RCSfile$'
4
 *    Purpose: A Class for upgrading the database to version 1.5
5
 *  Copyright: 2000 Regents of the University of California and the
6
 *             National Center for Ecological Analysis and Synthesis
7
 *    Authors: Saurabh Garg
8
 *
9
 *   '$Author: leinfelder $'
10
 *     '$Date: 2011-03-29 18:23:38 +0000 (Tue, 29 Mar 2011) $'
11
 * '$Revision: 6025 $'
12
 *
13
 * This program is free software; you can redistribute it and/or modify
14
 * it under the terms of the GNU General Public License as published by
15
 * the Free Software Foundation; either version 2 of the License, or
16
 * (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU General Public License
24
 * along with this program; if not, write to the Free Software
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26
 */
27

  
28

  
29
import java.util.Collections;
30
import java.util.List;
31
import java.util.concurrent.ExecutorService;
32
import java.util.concurrent.Executors;
33
import java.util.concurrent.TimeUnit;
34

  
35
import org.apache.commons.logging.Log;
36
import org.apache.commons.logging.LogFactory;
37

  
38
import edu.ucsb.nceas.metacat.DBUtil;
39
import edu.ucsb.nceas.metacat.admin.AdminException;
40
import edu.ucsb.nceas.metacat.admin.upgrade.UpgradeUtilityInterface;
41
import edu.ucsb.nceas.metacat.dataone.SystemMetadataFactory;
42
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
43
import edu.ucsb.nceas.metacat.properties.PropertyService;
44
import edu.ucsb.nceas.utilities.SortedProperties;
45

  
46
public class GenerateSystemMetadata implements UpgradeUtilityInterface {
47

  
48
	private static Log log = LogFactory.getLog(GenerateSystemMetadata.class);
49
	
50
    public boolean upgrade() throws AdminException {
51
    	
52
    	// do this in a thread too so that we don't have to hang the UI (web)
53
    	ExecutorService executor = Executors.newSingleThreadExecutor();
54
    	Runnable command = new Runnable() {
55
			@Override
56
			public void run() {
57
				// just run it
58
				try {
59
					boolean success = multiThreadUpgrade();
60
				} catch (AdminException e) {
61
					throw new RuntimeException(e);
62
				}
63
			}
64
    	};
65
		executor.execute(command);
66
		executor.shutdown();
67
		
68
		// wait for it to finish before returning?
69
        boolean wait = false;
70
        if (wait) {
71
            log.debug("Waiting for upgrade to complete");
72
            try {
73
				executor.awaitTermination(Long.MAX_VALUE, TimeUnit.HOURS);
74
			} catch (InterruptedException e) {
75
				AdminException ae = new AdminException(e.getMessage());
76
				ae.initCause(e);
77
				throw ae;
78
			}
79
            log.debug("Done waiting for upgrade thread");
80
        }
81
		
82
    	return true;
83
        //return singleThreadUpgrade();
84
    }
85
    
86
    /**
87
     * Use multiple threads to process parts of the complete ID list concurrently
88
     * @return
89
     * @throws AdminException
90
     */
91
    public boolean multiThreadUpgrade() throws AdminException {
92
    	
93
        boolean success = true;
94
        
95
        // do not include ORE or data, but can generate SystemMetadata for ALL records
96
        final boolean includeOre = false;
97
        final boolean downloadData = false;
98
        int serverLocation = -1;
99
        
100
        try {
101
        	
102
        	// get list of ALL docids at ALL server locations
103
            List<String> idList = DBUtil.getAllDocidsByType(null, true, serverLocation);
104
            Collections.sort(idList);
105
            
106
            // executor
107
            int availableProcessors = Runtime.getRuntime().availableProcessors();
108
            int nThreads = availableProcessors * 1;
109
            //availableProcessors++;
110
        	log.debug("Using nThreads: " + nThreads);
111

  
112
            ExecutorService executor = Executors.newFixedThreadPool(nThreads);
113
            int taskCount = 0;
114

  
115
            // init HZ
116
            log.debug("Making sure Hazelcast is up");
117
            HazelcastService.getInstance();
118
            
119
            // chunk into groups
120
			int fromIndex = 0;
121
            int toIndex = 0;
122
            String prefix = null;
123
            for (String docid: idList) {
124

  
125
            	// increment the next entry, exclusive
126
            	toIndex++;
127
            	
128
            	// use scope.docid (without revision) to determine groups
129
            	if (prefix == null || !docid.startsWith(prefix)) {
130
            		
131
            		// construct a sublist for this previous group of docids
132
					final List<String> subList = idList.subList(fromIndex, toIndex);
133
	            	log.debug("Grouping docid prefix: " + prefix);
134
					log.debug("subList.size: " + subList.size());
135
					
136
					// add the task for this sublist
137
					Runnable command = new Runnable() {
138
						@Override
139
						public void run() {
140
							// generate based on this list
141
				            try {
142
				            	log.debug("Processing subList.size: " + subList.size());
143
								SystemMetadataFactory.generateSystemMetadata(subList, includeOre, downloadData);
144
								log.debug("Done processing subList.size: " + subList.size());
145
								
146
							} catch (Exception e) {
147
								throw new RuntimeException(e);
148
							}
149
						}
150
					};
151
					
152
					// execute the task 
153
					executor.execute(command);
154
					taskCount++;
155
					
156
					// start at the end of this sublist
157
					fromIndex = toIndex;
158

  
159
            	}
160

  
161
            	log.debug("docid: " + docid);
162

  
163
            	// get the previous docid prefix
164
            	String previousId = docid;
165
            	prefix = previousId.substring(0, previousId.lastIndexOf("."));
166
				
167
            }
168

  
169
            log.info("done launching threaded tasks, count: " + taskCount);
170

  
171
            // wait for executor to finish
172
            executor.shutdown();
173
            
174
			// wait a long time
175
            log.debug("Waiting for all threads to complete");
176
            executor.awaitTermination(Long.MAX_VALUE, TimeUnit.HOURS);
177
            log.debug("Done waiting for all threads to complete");
178
            // now we are ready to be a data one node
179
            PropertyService.setProperty("dataone.systemmetadata.generated", Boolean.TRUE.toString());
180
            
181
		} catch (Exception e) {
182
			String msg = "Problem generating missing system metadata: " + e.getMessage();
183
			log.error(msg, e);
184
			success = false;
185
			throw new AdminException(msg);
186
		}
187
    	return success;
188
    }
189
    
190
    public static void main(String [] ags){
191

  
192
        try {
193
        	// set up the properties based on the test/deployed configuration of the workspace
194
        	SortedProperties testProperties = 
195
				new SortedProperties("test/test.properties");
196
			testProperties.load();
197
			String metacatContextDir = testProperties.getProperty("metacat.contextDir");
198
			PropertyService.getInstance(metacatContextDir + "/WEB-INF");
199
			// now run it
200
            GenerateSystemMetadata upgrader = new GenerateSystemMetadata();
201
	        upgrader.upgrade();
202
	        
203
        } catch (Exception ex) {
204
            System.out.println("Exception:" + ex.getMessage());
205
            ex.printStackTrace();
206
        }
207
    }
208
}
src/edu/ucsb/nceas/metacat/admin/D1Admin.java
41 41
import org.dataone.service.types.v1.Session;
42 42

  
43 43
import edu.ucsb.nceas.metacat.IdentifierManager;
44
import edu.ucsb.nceas.metacat.admin.upgrade.GenerateORE;
45
import edu.ucsb.nceas.metacat.admin.upgrade.GenerateSystemMetadata;
44
import edu.ucsb.nceas.metacat.admin.upgrade.dataone.GenerateORE;
45
import edu.ucsb.nceas.metacat.admin.upgrade.dataone.GenerateSystemMetadata;
46 46
import edu.ucsb.nceas.metacat.dataone.MNodeService;
47 47
import edu.ucsb.nceas.metacat.properties.PropertyService;
48 48
import edu.ucsb.nceas.metacat.shared.MetacatUtilException;
build.xml
280 280
			value="./test/edu/ucsb/nceas/metacattest" />
281 281
		<property name="junitnettestsdir"
282 282
			value="./test/edu/ucsb/nceas/metacatnettest" />
283
		<property name="classtorun" value="edu.ucsb.nceas.metacat.admin.upgrade.GenerateSystemMetadata" />
283
		<property name="classtorun" value="edu.ucsb.nceas.metacat.admin.upgrade.dataone.GenerateSystemMetadata" />
284 284
		<property name="build.dir" value="./build" />
285 285
		<property name="build.src" value="${build.dir}/src" />
286 286
		<property name="build.dest" value="${build.dir}/classes" />

Also available in: Unified diff