use of org.apache.geode.distributed.Locator in project geode by apache.
the class ManagementListener method handleEvent.
/**
* Handles various GFE resource life-cycle methods vis-a-vis Management and Monitoring
*
* It checks for race conditions cases by calling shouldProceed();
*
* @param event Management event for which invocation has happened
* @param resource the GFE resource type
*/
public void handleEvent(ResourceEvent event, Object resource) {
if (!shouldProceed(event)) {
return;
}
switch(event) {
case CACHE_CREATE:
InternalCache createdCache = (InternalCache) resource;
adapter.handleCacheCreation(createdCache);
break;
case CACHE_REMOVE:
InternalCache removedCache = (InternalCache) resource;
adapter.handleCacheRemoval(removedCache);
break;
case REGION_CREATE:
Region createdRegion = (Region) resource;
adapter.handleRegionCreation(createdRegion);
break;
case REGION_REMOVE:
Region removedRegion = (Region) resource;
adapter.handleRegionRemoval(removedRegion);
break;
case DISKSTORE_CREATE:
DiskStore createdDisk = (DiskStore) resource;
adapter.handleDiskCreation(createdDisk);
break;
case DISKSTORE_REMOVE:
DiskStore removedDisk = (DiskStore) resource;
adapter.handleDiskRemoval(removedDisk);
break;
case GATEWAYRECEIVER_CREATE:
GatewayReceiver createdRecv = (GatewayReceiver) resource;
adapter.handleGatewayReceiverCreate(createdRecv);
break;
case GATEWAYRECEIVER_START:
GatewayReceiver startedRecv = (GatewayReceiver) resource;
adapter.handleGatewayReceiverStart(startedRecv);
break;
case GATEWAYRECEIVER_STOP:
GatewayReceiver stoppededRecv = (GatewayReceiver) resource;
adapter.handleGatewayReceiverStop(stoppededRecv);
break;
case GATEWAYSENDER_CREATE:
GatewaySender sender = (GatewaySender) resource;
adapter.handleGatewaySenderCreation(sender);
break;
case GATEWAYSENDER_START:
GatewaySender startedSender = (GatewaySender) resource;
adapter.handleGatewaySenderStart(startedSender);
break;
case GATEWAYSENDER_STOP:
GatewaySender stoppedSender = (GatewaySender) resource;
adapter.handleGatewaySenderStop(stoppedSender);
break;
case GATEWAYSENDER_PAUSE:
GatewaySender pausedSender = (GatewaySender) resource;
adapter.handleGatewaySenderPaused(pausedSender);
break;
case GATEWAYSENDER_RESUME:
GatewaySender resumedSender = (GatewaySender) resource;
adapter.handleGatewaySenderResumed(resumedSender);
break;
case LOCKSERVICE_CREATE:
DLockService createdLockService = (DLockService) resource;
adapter.handleLockServiceCreation(createdLockService);
break;
case LOCKSERVICE_REMOVE:
DLockService removedLockService = (DLockService) resource;
adapter.handleLockServiceRemoval(removedLockService);
break;
case MANAGER_CREATE:
adapter.handleManagerCreation();
break;
case MANAGER_START:
adapter.handleManagerStart();
break;
case MANAGER_STOP:
adapter.handleManagerStop();
break;
case ASYNCEVENTQUEUE_CREATE:
AsyncEventQueue queue = (AsyncEventQueue) resource;
adapter.handleAsyncEventQueueCreation(queue);
break;
case ASYNCEVENTQUEUE_REMOVE:
AsyncEventQueue removedQueue = (AsyncEventQueue) resource;
adapter.handleAsyncEventQueueRemoval(removedQueue);
break;
case SYSTEM_ALERT:
AlertDetails details = (AlertDetails) resource;
adapter.handleSystemNotification(details);
break;
case CACHE_SERVER_START:
CacheServer startedServer = (CacheServer) resource;
adapter.handleCacheServerStart(startedServer);
break;
case CACHE_SERVER_STOP:
CacheServer stoppedServer = (CacheServer) resource;
adapter.handleCacheServerStop(stoppedServer);
break;
case LOCATOR_START:
Locator loc = (Locator) resource;
adapter.handleLocatorStart(loc);
break;
case CACHE_SERVICE_CREATE:
CacheService service = (CacheService) resource;
adapter.handleCacheServiceCreation(service);
break;
default:
break;
}
}
use of org.apache.geode.distributed.Locator in project geode by apache.
the class LocatorTestBase method startLocator.
protected void startLocator(final String hostName, final int locatorPort, final String otherLocators) {
final String testName = getUniqueName();
disconnectFromDS();
Properties props = new Properties();
props.setProperty(MCAST_PORT, String.valueOf(0));
props.setProperty(LOCATORS, otherLocators);
props.setProperty(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
try {
File logFile = new File(testName + "-locator" + locatorPort + ".log");
InetAddress bindAddr = null;
try {
bindAddr = InetAddress.getByName(hostName);
} catch (UnknownHostException uhe) {
Assert.fail("While resolving bind address ", uhe);
}
Locator locator = Locator.startLocatorAndDS(locatorPort, logFile, bindAddr, props);
remoteObjects.put(LOCATOR_KEY, locator);
} catch (IOException ex) {
Assert.fail("While starting locator on port " + locatorPort, ex);
}
}
use of org.apache.geode.distributed.Locator in project geode by apache.
the class LocatorTestBase method stopLocator.
protected void stopLocator() {
Locator locator = (Locator) remoteObjects.remove(LOCATOR_KEY);
locator.stop();
}
use of org.apache.geode.distributed.Locator in project geode by apache.
the class ReconnectDUnitTest method testReconnectALocator.
@Test
public void testReconnectALocator() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM locatorVm = host.getVM(3);
DistributedMember dm, newdm;
final int locPort = locatorPort;
final int secondLocPort = AvailablePortHelper.getRandomAvailableTCPPort();
DistributedTestUtils.deleteLocatorStateFile(locPort, secondLocPort);
final String xmlFileLoc = (new File(".")).getAbsolutePath();
// This locator was started in setUp.
File locatorViewLog = new File(locatorVm.getWorkingDirectory(), "locator" + locatorPort + "views.log");
assertTrue("Expected to find " + locatorViewLog.getPath() + " file", locatorViewLog.exists());
long logSize = locatorViewLog.length();
vm0.invoke("Create a second locator", () -> {
locatorPort = locPort;
Properties props = getDistributedSystemProperties();
props.put(MAX_WAIT_TIME_RECONNECT, "1000");
props.put(MAX_NUM_RECONNECT_TRIES, "2");
props.put(LOCATORS, props.get(LOCATORS) + ",localhost[" + locPort + "]");
props.put(ENABLE_CLUSTER_CONFIGURATION, "false");
try {
Locator.startLocatorAndDS(secondLocPort, null, props);
} catch (IOException e) {
Assert.fail("exception starting locator", e);
}
});
File locator2ViewLog = new File(vm0.getWorkingDirectory(), "locator" + secondLocPort + "views.log");
assertTrue("Expected to find " + locator2ViewLog.getPath() + " file", locator2ViewLog.exists());
long log2Size = locator2ViewLog.length();
// create a cache in vm1 so there is more weight in the system
vm1.invoke("Create Cache and Regions from cache.xml", () -> {
locatorPort = locPort;
Properties props = getDistributedSystemProperties();
props.put(CACHE_XML_FILE, xmlFileLoc + fileSeparator + "MyDisconnect-cache.xml");
props.put(MAX_WAIT_TIME_RECONNECT, "1000");
props.put(MAX_NUM_RECONNECT_TRIES, "2");
ReconnectDUnitTest.savedSystem = getSystem(props);
Cache cache = getCache();
Region myRegion = cache.getRegion("root/myRegion");
myRegion.put("MyKey1", "MyValue1");
return savedSystem.getDistributedMember();
});
try {
dm = getDMID(vm0);
createGfshWaitingThread(vm0);
forceDisconnect(vm0);
newdm = waitForReconnect(vm0);
assertGfshWaitingThreadAlive(vm0);
assertTrue("Expected the restarted member to be hosting a running locator", vm0.invoke("check for running locator", () -> {
Awaitility.await("waiting for locator to restart").atMost(30, TimeUnit.SECONDS).until(Locator::getLocator, notNullValue());
if (((InternalLocator) Locator.getLocator()).isStopped()) {
LogWriterUtils.getLogWriter().error("found a stopped locator");
return false;
}
return true;
}));
assertNotSame("expected a reconnect to occur in the locator", dm, newdm);
// the log should have been opened and appended with a new view
assertTrue("expected " + locator2ViewLog.getPath() + " to grow in size", locator2ViewLog.length() > log2Size);
// the other locator should have logged a new view
assertTrue("expected " + locatorViewLog.getPath() + " to grow in size", locatorViewLog.length() > logSize);
} finally {
vm0.invoke(new SerializableRunnable("stop locator") {
public void run() {
Locator loc = Locator.getLocator();
if (loc != null) {
loc.stop();
}
if (gfshThread != null && gfshThread.isAlive()) {
gfshThread.interrupt();
}
gfshThread = null;
}
});
DistributedTestUtils.deleteLocatorStateFile(locPort);
DistributedTestUtils.deleteLocatorStateFile(secondLocPort);
}
}
use of org.apache.geode.distributed.Locator in project geode by apache.
the class GMSLocatorRecoveryJUnitTest method testRecoverFromOther.
@Test
public void testRecoverFromOther() throws Exception {
MembershipManager m1 = null, m2 = null;
Locator l = null;
try {
// boot up a locator
int port = AvailablePortHelper.getRandomAvailableTCPPort();
InetAddress localHost = SocketCreator.getLocalHost();
// this locator will hook itself up with the first MembershipManager
// to be created
// l = Locator.startLocator(port, new File(""), localHost);
l = InternalLocator.startLocator(port, new File(""), null, null, null, localHost, false, new Properties(), null);
// create configuration objects
Properties nonDefault = new Properties();
nonDefault.put(DISABLE_TCP, "true");
nonDefault.put(MCAST_PORT, "0");
nonDefault.put(LOG_FILE, "");
nonDefault.put(LOG_LEVEL, "fine");
nonDefault.put(LOCATORS, localHost.getHostAddress() + '[' + port + ']');
nonDefault.put(BIND_ADDRESS, localHost.getHostAddress());
DistributionConfigImpl config = new DistributionConfigImpl(nonDefault);
RemoteTransportConfig transport = new RemoteTransportConfig(config, DistributionManager.NORMAL_DM_TYPE);
// start the first membership manager
DistributedMembershipListener listener1 = mock(DistributedMembershipListener.class);
DMStats stats1 = mock(DMStats.class);
m1 = MemberFactory.newMembershipManager(listener1, config, transport, stats1);
// hook up the locator to the membership manager
((InternalLocator) l).getLocatorHandler().setMembershipManager(m1);
GMSLocator l2 = new GMSLocator(SocketCreator.getLocalHost(), new File("l2.dat"), m1.getLocalMember().getHost() + "[" + port + "]", true, true, new LocatorStats(), "");
l2.init(null);
assertTrue("expected view to contain " + m1.getLocalMember() + ": " + l2.getMembers(), l2.getMembers().contains(m1.getLocalMember()));
} finally {
if (m1 != null) {
m1.shutdown();
}
if (l != null) {
l.stop();
}
}
}
Aggregations