TDRCollectorInstanceWatcher implements IEntryListener<String, ArrayList<Instance>> { public void init() { if (logger.isDebugEnabled()) { logger.debug("Starting TDRCollectorInstanceWatcher ..."); logger.debug("Getting TDRCollectorInstance list ..."); } List<Instance> nodeList; nodeList = topologyClient.getAllInstancesOfType(E3Constant.E3MANAGER); if (nodeList != null && nodeList.size() != 0) { for (Instance instance : nodeList) { verifyCredentials(instance); } if (this.key == null || this.user == null) { logger.warn("No credentials were set for instances of type " + E3Constant.TDR_COLLECTOR + ". There will likely be problems with downstream TDR collection. "); } } nodeList = topologyClient.getAllInstancesOfType(E3Constant.TDR_COLLECTOR); if (nodeList != null && nodeList.size() != 0) { TDRCollectors.addAll(nodeList); for (Instance instance : nodeList) { verifyCredentialsUser(instance); } if (logger.isDebugEnabled()) { logger.debug("Writing TDR Transfer Script configuration file."); } writeConfigFile(); } else { if (logger.isDebugEnabled()) { logger.debug("No instances of type " + E3Constant.TDR_COLLECTOR + " were found."); } } listenInstanceTypeListener(); getMyName(); if (logger.isDebugEnabled()) { logger.debug("TDRCollectorInstanceWatcher init'd."); } }  void init(); void destroy(); void setWriteLocation(String value); String getWriteLocation(); void setConfigName(String value); String getConfigName(); void setKeyName(String value); String getKeyName(); void setTopologyClient(ITopologyClient topologyClient); void listenInstanceTypeListener(); ITopologyClient getTopologyClient(); @Override void entryAdded(DataEntryEvent<String, ArrayList<Instance>> event); @Override void entryUpdated(DataEntryEvent<String, ArrayList<Instance>> event); @Override void entryRemoved(DataEntryEvent<String, ArrayList<Instance>> event); static final String HOST_CFG; static final String KEY_CFG; static final String USER_CFG; static final String ID_CFG; static final String CONFIG_KEYVAL_CHAR; }
@Test public void testInitialCreation() { initializeTestSetup(1, 1, 1, true); tdrCollectorInstanceWatcher.init(); assertTrue("Key file was not created.", verifyKeyExists()); assertTrue("Config file was not created.", verifyConfigExists()); assertTrue("Config file was not correctly built.", verifyValidConfig(1)); }
@Test public void testInitialCreationWithNoTdrCollectors() { initializeTestSetup(1, 1, 0, false); tdrCollectorInstanceWatcher.init(); assertTrue("Key file was created.", !verifyKeyExists()); assertTrue("Config file was created.", !verifyConfigExists()); }
@Test public void testNonTdrCollectorInstances() { initializeTestSetup(1, 1, 1, true); tdrCollectorInstanceWatcher.init(); assertTrue("Key file was not created.", verifyKeyExists()); assertTrue("Config file was not created.", verifyConfigExists()); assertTrue("Config file was not correctly built.", verifyValidConfig(1)); Instance gate = createInstance(E3Constant.E3GATEWAY, "1.1.1.1", "2.1.1.1", null); Instance manager = createInstance(E3Constant.E3MANAGER, "1.1.2.1", "2.1.2.1", null); addInstance(gate); addInstance(manager); assertTrue("Key file did not remain after adding non-collection instances.", verifyKeyExists()); assertTrue("Config file did not remain after adding non-collection instances.", verifyConfigExists()); assertTrue("Config file did not remain correctly built after adding non-collection instances.", verifyValidConfig(1)); deleteInstance(gate); deleteInstance(manager); assertTrue("Key file did not remain after removing non-collection instances.", verifyKeyExists()); assertTrue("Config file did not remain after removing non-collection instances.", verifyConfigExists()); assertTrue("Config file did not remain correctly built after removing non-collection instances.", verifyValidConfig(1)); }
@Test public void testTdrCollectorInstances() { initializeTestSetup(1, 1, 2, true); tdrCollectorInstanceWatcher.init(); assertTrue("Key file was not created.", verifyKeyExists()); assertTrue("Config file was not created.", verifyConfigExists()); assertTrue("Config file was not correctly built.", verifyValidConfig(2)); Instance inst1 = createInstance(E3Constant.TDR_COLLECTOR, "1.1.3.2", "2.1.3.2", null); Instance inst2 = createInstance(E3Constant.TDR_COLLECTOR, "1.1.3.3", "2.1.3.3", null); addInstance(inst1); addInstance(inst2); assertTrue("Key file did not remain after adding collection instances.", verifyKeyExists()); assertTrue("Config file did not remain after adding collection instances.", verifyConfigExists()); assertTrue("Config file did not remain correctly built after adding collection instances.", verifyValidConfig(4)); deleteInstance(inst2); assertTrue("Key file did not remain after removing collection instance.", verifyKeyExists()); assertTrue("Config file did not remain after removing collection instance.", verifyConfigExists()); assertTrue("Config file did not remain correctly built after removing collection instance.", verifyValidConfig(3)); }