Project

General

Profile

« Previous | Next » 

Revision 6437

initialize Hazelcast from the custom configuration when initializing the Metacat service.

View differences:

test/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastServiceTest.java
52 52
public class HazelcastServiceTest extends MCTestCase {   
53 53
    
54 54
	static {
55
		// initialize using custom configuration
56
	    String configFileName = null;
55
	
57 56
		try {
58
			// if we use the system property, we probably don't need to do this explicitly!
59
			Settings.getConfiguration().addProperty("hazelcast.config", "/Users/leinfelder/workspace/d1_replication/src/main/resources/hazelcast.xml");
60
		    configFileName = Settings.getConfiguration().getString("hazelcast.config");
61
			Config config = new FileSystemXmlConfig(configFileName);
62
			Hazelcast.init(config);
57
			// initialize the configuration
58
			HazelcastService.getInstance();
63 59
			
64 60
			// initialize the entry listeners
65 61
			CNodeService.getInstance();
66
			
67
		} catch (FileNotFoundException e) {
62
		} catch (Exception e) {
68 63
			e.printStackTrace();
69 64
			fail();
70 65
		}
66
			
71 67
	}
72 68
		
73 69
    /**
......
75 71
    */
76 72
    public HazelcastServiceTest(String name) {
77 73
        super(name);
78
        
79
     
74

  
80 75
    }
81 76
    
82 77
    /**
......
101 96
			pid = cnst.testRegisterSystemMetadata();
102 97
			assertNotNull(pid);
103 98
			// look it up from the "shared" map
104
			HazelcastService.getInstance();
105 99
			IMap<Object, Object> systemMetadataMap = Hazelcast.getMap(PropertyService.getProperty("dataone.hazelcast.storageCluster.systemMetadataMap"));
106 100
			SystemMetadata sm = (SystemMetadata) systemMetadataMap.get(pid);
107 101
			assertNotNull(sm);
src/edu/ucsb/nceas/metacat/MetaCatServlet.java
54 54
import edu.ucsb.nceas.metacat.database.DBConnection;
55 55
import edu.ucsb.nceas.metacat.database.DBConnectionPool;
56 56
import edu.ucsb.nceas.metacat.database.DatabaseService;
57
import edu.ucsb.nceas.metacat.dataone.hazelcast.HazelcastService;
57 58
import edu.ucsb.nceas.metacat.plugin.MetacatHandlerPlugin;
58 59
import edu.ucsb.nceas.metacat.plugin.MetacatHandlerPluginManager;
59 60
import edu.ucsb.nceas.metacat.properties.PropertyService;
......
432 433
			
433 434
			// initialize the plugins
434 435
			MetacatHandlerPluginManager.getInstance();
436
			
437
			// initialize the HazelcastService
438
			ServiceService.registerService("HazelcastService", HazelcastService.getInstance());
435 439

  
436 440
			_fullyInitialized = true;
437 441
			
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
110 110
  /* The Hazelcast distributed task id generator namespace */
111 111
  private String taskIds;
112 112
  
113
  /* The name of the pending replication tasks map */
114
  private String pendingTasksQueue;
115
  
116 113
  /* The Hazelcast distributed system metadata map */
117 114
  private IMap<NodeReference, Node> nodes;
118 115

  
......
157 154
        PropertyService.getProperty("dataone.hazelcast.processCluster.nodesMap");
158 155
      systemMetadataMap = 
159 156
        PropertyService.getProperty("dataone.hazelcast.storageCluster.systemMetadataMap");
160
      pendingTasksQueue = 
161
    	PropertyService.getProperty("dataone.hazelcast.replicationPendingTasks");
162
      
157

  
163 158
      // Become a DataONE-process cluster client
164 159
      //TODO: where should this be?
165 160
//      String[] addresses = addressList.split(",");
src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java
26 26

  
27 27
package edu.ucsb.nceas.metacat.dataone.hazelcast;
28 28

  
29
import java.io.File;
30

  
31 29
import org.apache.log4j.Logger;
32
import org.dataone.service.types.v1.Identifier;
33
import org.dataone.service.types.v1.SystemMetadata;
34 30

  
35 31
import com.hazelcast.config.Config;
32
import com.hazelcast.config.FileSystemXmlConfig;
36 33
import com.hazelcast.core.Hazelcast;
37
import com.hazelcast.core.HazelcastInstance;
38
import com.hazelcast.core.IMap;
39
import com.hazelcast.core.IdGenerator;
40 34
import com.hazelcast.core.InstanceEvent;
41 35
import com.hazelcast.core.InstanceListener;
42 36

  
43 37
import edu.ucsb.nceas.metacat.properties.PropertyService;
44 38
import edu.ucsb.nceas.metacat.shared.BaseService;
45 39
import edu.ucsb.nceas.metacat.shared.ServiceException;
46
import edu.ucsb.nceas.utilities.PropertyNotFoundException;
47 40
/**
48 41
 * The Hazelcast service enables Metacat as a Hazelcast cluster member
49 42
 */
......
56 49
  /* The singleton instance of the hazelcast service */
57 50
  private static HazelcastService hzService = null;
58 51
  
59
  /* The Hazelcast instance that is a cluster member */
60
  private HazelcastInstance hzMember;
61
  
62 52
  /* The Hazelcast configuration */
63 53
  private Config hzConfig;
64 54
  
65
  /* The task id namespace (for generating cluster-wide unqique task ids */
66
  private String taskIds;
67
  
68
  /* The Hazelcast Id Genrator used to generate unique task ids */
69
  IdGenerator idGenerator;
70
  
71 55
  /*
72 56
   * Constructor: Creates an instance of the hazelcast service. Since
73 57
   * this uses a singleton pattern, use getInstance() to gain the instance.
......
81 65
      init();
82 66
      
83 67
    } catch (ServiceException se) {
84
      logMetacat.debug("There was a problem creating the HazelcastService. " +
68
      logMetacat.error("There was a problem creating the HazelcastService. " +
85 69
                       "The error message was: " + se.getMessage());
86 70
      
87 71
    }
......
112 96
    logMetacat.debug("HazelcastService.doRefresh() called.");
113 97
    
114 98
    try {
115
      File hzConfigFile =
116
        new File(PropertyService.getProperty("dataone.hazelcast.configFilePath"));
117
      hzConfig = new Config();
118
      hzConfig.setConfigurationFile(hzConfigFile);
119
      hzMember = Hazelcast.init(hzConfig);
120
      taskIds = 
121
        PropertyService.getProperty("dataone.hazelcast.storageCluster.tasksIdNamespace");
122
      
123
      idGenerator = hzMember.getIdGenerator(taskIds);
124

  
125
    } catch (PropertyNotFoundException e) {
126
      String msg = "Couldn't find the Hazelcast configuration file.";
99
    	String configFileName = PropertyService.getProperty("dataone.hazelcast.configFilePath");
100
//    	System.setProperty("hazelcast.config", configFileName);
101
		Config config = new FileSystemXmlConfig(configFileName);
102
		Hazelcast.init(config);
103
    } catch (Exception e) {
104
      String msg = e.getMessage();
127 105
      logMetacat.error(msg);
128 106
      throw new ServiceException(msg);
129 107
    
130
    } catch (IllegalStateException e) {
131

  
132
      String msg = "This instance of Hazelcast has already been created.";
133
      logMetacat.error(msg);
134
      throw new ServiceException(msg);
135

  
136 108
    }
137 109
    
138 110
    return;
......
180 152
        event.getInstance().getInstanceType());
181 153
    
182 154
  }
183

  
184 155
  
185 156
  /**
186 157
   * Refresh the Hazelcast service by restarting it

Also available in: Unified diff