Search in sources :

Example 6 with TakeOfflineManager

use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.

the class XSiteResourceTest method testBackups.

@Test
public void testBackups() {
    RestCacheClient cache = getCacheClient(LON);
    Json status = jsonResponseBody(cache.xsiteBackups());
    assertEquals(ONLINE, status.at(NYC).at("status").asString());
    // add a second node
    TestSite site = site(LON);
    EmbeddedCacheManager cm = site.addCacheManager(null, defaultGlobalConfigurationForSite(site.getSiteIndex()), defaultConfigurationForSite(site.getSiteIndex()), false);
    site.waitForClusterToForm(CACHE_1);
    site.waitForClusterToForm(CACHE_2);
    TakeOfflineManager takeOfflineManager = TestingUtil.extractComponent(cm.getCache(CACHE_1), TakeOfflineManager.class);
    takeOfflineManager.takeSiteOffline(NYC);
    String node1 = String.valueOf(site.cacheManagers().get(0).getAddress());
    String node2 = String.valueOf(cm.getAddress());
    status = jsonResponseBody(cache.xsiteBackups());
    assertEquals("mixed", status.at(NYC).at("status").asString());
    assertEquals(status.at(NYC).at("online").asJsonList().iterator().next().asString(), node1);
    assertEquals(status.at(NYC).at("offline").asJsonList().iterator().next().asString(), node2);
    assertFalse(status.at(NYC).has("mixed"));
    status = jsonResponseBody(cache.backupStatus(NYC));
    assertEquals(ONLINE, status.at(node1).asString());
    assertEquals(OFFLINE, status.at(node2).asString());
    // bring NYC online
    takeOfflineManager.bringSiteOnline(NYC);
    status = jsonResponseBody(cache.xsiteBackups());
    assertEquals(ONLINE, status.at(NYC).at("status").asString());
    status = jsonResponseBody(cache.backupStatus(NYC));
    assertEquals(ONLINE, status.at(node1).asString());
    assertEquals(ONLINE, status.at(node2).asString());
}
Also used : RestCacheClient(org.infinispan.client.rest.RestCacheClient) Json(org.infinispan.commons.dataconversion.internal.Json) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 7 with TakeOfflineManager

use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.

the class IracTombstoneUnitTest method createTakeOfflineManager.

private static TakeOfflineManager createTakeOfflineManager() {
    TakeOfflineManager tom = Mockito.mock(TakeOfflineManager.class);
    // hack to prevent creating and mocking xsite commands. Local command needs to be mocked
    Mockito.when(tom.getSiteState(ArgumentMatchers.anyString())).thenReturn(SiteState.OFFLINE);
    return tom;
}
Also used : TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager)

Example 8 with TakeOfflineManager

use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.

the class XSiteAutoStateTransferTest method testSyncStrategyDoNotTriggerStateTransfer.

public void testSyncStrategyDoNotTriggerStateTransfer() throws InterruptedException {
    // site2 is the sync one
    String remoteSite = siteName(2);
    // make the remote site offline.
    for (int i = 0; i < defaultNumberOfNodes(); ++i) {
        TakeOfflineManager manager = takeOfflineManager(i);
        assertNotSame(TakeSiteOfflineResponse.NO_SUCH_SITE, manager.takeSiteOffline(remoteSite));
        assertSame(SiteState.OFFLINE, manager.getSiteState(remoteSite));
    }
    SiteMasterController controller = findSiteMaster();
    // block sites up event and wait until received
    SiteUpEvent event = controller.getStateTransferManager().blockSiteUpEvent();
    triggerSiteUpEvent(controller, remoteSite);
    Collection<String> sitesUp = event.waitForEvent();
    // check if it is the correct event
    assertEquals(1, sitesUp.size());
    assertEquals(remoteSite, sitesUp.iterator().next());
    // let the event continue, it will be handled in this thread, which is fine
    event.continueRunnable();
    // coordinator don't even query other nodes state
    controller.getRpcManager().expectNoCommand(10, TimeUnit.SECONDS);
    // site status must not change
    for (int i = 0; i < defaultNumberOfNodes(); ++i) {
        TakeOfflineManager manager = takeOfflineManager(i);
        assertSame(SiteState.OFFLINE, manager.getSiteState(remoteSite));
    }
}
Also used : TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager)

Example 9 with TakeOfflineManager

use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.

the class XSiteAdminOperationsTest method amendTakeOffline.

public void amendTakeOffline() {
    assertEquals(admin(LON, 0).siteStatus(NYC), XSiteAdminOperations.ONLINE);
    assertEquals(admin(LON, 1).siteStatus(NYC), XSiteAdminOperations.ONLINE);
    TakeOfflineManager tom = takeOfflineManager(LON, 0);
    assertEquals(tom.getConfiguration(NYC), new TakeOfflineConfigurationBuilder(null, null).afterFailures(0).minTimeToWait(0).create());
    assertEquals(XSiteAdminOperations.SUCCESS, admin(LON, 1).amendTakeOffline(NYC, 7, 12));
    assertEquals(tom.getConfiguration(NYC), new TakeOfflineConfigurationBuilder(null, null).afterFailures(7).minTimeToWait(12).create());
    assertEquals(XSiteAdminOperations.SUCCESS, admin(LON, 1).setTakeOfflineAfterFailures(NYC, 8));
    assertEquals(tom.getConfiguration(NYC), new TakeOfflineConfigurationBuilder(null, null).afterFailures(8).minTimeToWait(12).create());
    assertEquals(XSiteAdminOperations.SUCCESS, admin(LON, 1).setTakeOfflineMinTimeToWait(NYC, 13));
    assertEquals(tom.getConfiguration(NYC), new TakeOfflineConfigurationBuilder(null, null).afterFailures(8).minTimeToWait(13).create());
    assertEquals(admin(LON, 0).getTakeOfflineAfterFailures(NYC), "8");
    assertEquals(admin(LON, 0).getTakeOfflineMinTimeToWait(NYC), "13");
    assertEquals(admin(LON, 1).getTakeOfflineAfterFailures(NYC), "8");
    assertEquals(admin(LON, 1).getTakeOfflineMinTimeToWait(NYC), "13");
}
Also used : TakeOfflineConfigurationBuilder(org.infinispan.configuration.cache.TakeOfflineConfigurationBuilder) TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager)

Example 10 with TakeOfflineManager

use of org.infinispan.xsite.status.TakeOfflineManager in project infinispan by infinispan.

the class XSiteResourceTest method testGetStatusAllCaches.

@Test
public void testGetStatusAllCaches() {
    RestClient restClient = clientPerSite.get(LON);
    assertAllSitesOnline(restClient);
    assertSuccessful(restClient.cache(CACHE_2).takeSiteOffline(NYC));
    Json json = jsonResponseBody(restClient.cacheManager(CACHE_MANAGER).backupStatuses());
    assertEquals(json.at(NYC).at("status").asString(), "mixed");
    assertEquals(json.at(NYC).at("online").asJsonList().iterator().next().asString(), CACHE_1);
    assertEquals(json.at(NYC).at("offline").asJsonList().iterator().next().asString(), CACHE_2);
    json = jsonResponseBody(restClient.cacheManager(CACHE_MANAGER).backupStatus(NYC));
    assertEquals(json.at("status").asString(), "mixed");
    assertEquals(json.at("online").asJsonList().iterator().next().asString(), CACHE_1);
    assertEquals(json.at("offline").asJsonList().iterator().next().asString(), CACHE_2);
    assertSuccessful(restClient.cache(CACHE_2).bringSiteOnline(NYC));
    assertAllSitesOnline(restClient);
    // add a second node
    TestSite site = site(LON);
    EmbeddedCacheManager cm = site.addCacheManager(null, defaultGlobalConfigurationForSite(site.getSiteIndex()), defaultConfigurationForSite(site.getSiteIndex()), true);
    site.waitForClusterToForm(CACHE_1);
    site.waitForClusterToForm(CACHE_2);
    TakeOfflineManager takeOfflineManager = TestingUtil.extractComponent(cm.getCache(CACHE_1), TakeOfflineManager.class);
    takeOfflineManager.takeSiteOffline(NYC);
    json = jsonResponseBody(restClient.cacheManager(CACHE_MANAGER).backupStatuses());
    assertEquals(json.at(NYC).at("status").asString(), "mixed");
    assertEquals(json.at(NYC).at("online").asJsonList().iterator().next().asString(), CACHE_2);
    assertTrue(json.at(NYC).at("offline").asJsonList().isEmpty());
    assertEquals(json.at(NYC).at("mixed").asJsonList().iterator().next().asString(), CACHE_1);
    json = jsonResponseBody(restClient.cacheManager(CACHE_MANAGER).backupStatus(NYC));
    assertEquals(json.at("status").asString(), "mixed");
    assertEquals(json.at("online").asJsonList().iterator().next().asString(), CACHE_2);
    assertTrue(json.at("offline").asJsonList().isEmpty());
    assertEquals(json.at("mixed").asJsonList().iterator().next().asString(), CACHE_1);
    takeOfflineManager.bringSiteOnline(NYC);
}
Also used : RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) TakeOfflineManager(org.infinispan.xsite.status.TakeOfflineManager) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Aggregations

TakeOfflineManager (org.infinispan.xsite.status.TakeOfflineManager)10 Json (org.infinispan.commons.dataconversion.internal.Json)2 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)2 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)2 Test (org.testng.annotations.Test)2 RestCacheClient (org.infinispan.client.rest.RestCacheClient)1 RestClient (org.infinispan.client.rest.RestClient)1 TakeOfflineConfigurationBuilder (org.infinispan.configuration.cache.TakeOfflineConfigurationBuilder)1 ControlledRpcManager (org.infinispan.util.ControlledRpcManager)1 XSiteAutoTransferStatusCommand (org.infinispan.xsite.commands.XSiteAutoTransferStatusCommand)1