Search in sources :

Example 1 with RestCacheManagerClient

use of org.infinispan.client.rest.RestCacheManagerClient in project infinispan by infinispan.

the class BackupManagerIT method testManagerBackupParameters.

@Test
public void testManagerBackupParameters() throws Exception {
    String name = "testManagerBackupParameters";
    performTest(client -> {
        Map<String, List<String>> params = new HashMap<>();
        params.put("caches", Collections.singletonList("*"));
        params.put("counters", Collections.singletonList("weak-volatile"));
        RestCacheManagerClient cm = client.cacheManager("clustered");
        RestResponse response = await(cm.createBackup(name, params));
        assertEquals(202, response.getStatus());
        return awaitOk(() -> cm.getBackup(name, false));
    }, client -> await(client.cacheManager("clustered").deleteBackup(name)), (zip, client) -> {
        Map<String, List<String>> params = new HashMap<>();
        params.put("caches", Collections.singletonList("cache1"));
        params.put("counters", Collections.singletonList("*"));
        RestCacheManagerClient cm = client.cacheManager("clustered");
        RestResponse response = await(cm.restore(name, zip, params));
        assertEquals(202, response.getStatus());
        return awaitCreated(() -> cm.getRestore(name));
    }, client -> {
        // Assert that only caches and the specified "weak-volatile" counter have been backed up. Internal caches will still be present
        assertEquals("[\"___protobuf_metadata\",\"memcachedCache\",\"cache1\",\"___script_cache\"]", await(client.caches()).getBody());
        assertEquals("[\"weak-volatile\"]", await(client.counters()).getBody());
        assertEquals(404, await(client.schemas().get("schema.proto")).getStatus());
        assertEquals("[]", await(client.tasks().list(RestTaskClient.ResultType.USER)).getBody());
    }, false);
}
Also used : HashMap(java.util.HashMap) RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestResponse(org.infinispan.client.rest.RestResponse) List(java.util.List) Test(org.junit.Test)

Example 2 with RestCacheManagerClient

use of org.infinispan.client.rest.RestCacheManagerClient in project infinispan by infinispan.

the class BackupManagerIT method testManagerBackupFromFile.

@Test
public void testManagerBackupFromFile() throws Exception {
    String name = "testManagerBackup";
    performTest(client -> {
        RestCacheManagerClient cm = client.cacheManager("clustered");
        RestResponse response = await(cm.createBackup(name));
        assertEquals(202, response.getStatus());
        response.close();
        return awaitOk(() -> cm.getBackup(name, false));
    }, client -> await(client.cacheManager("clustered").deleteBackup(name)), (zip, client) -> {
        RestCacheManagerClient cm = client.cacheManager("clustered");
        RestResponse response = await(cm.restore(name, zip.getPath(), null));
        assertEquals(202, response.getStatus());
        return awaitCreated(() -> cm.getRestore(name));
    }, this::assertWildcardContent, true);
}
Also used : RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestResponse(org.infinispan.client.rest.RestResponse) Test(org.junit.Test)

Example 3 with RestCacheManagerClient

use of org.infinispan.client.rest.RestCacheManagerClient in project infinispan-quarkus by infinispan.

the class NativeCliIT method testCliBatch.

@Test
public void testCliBatch() throws Exception {
    RestClient client = SERVER_TEST.rest().create();
    RestCacheManagerClient cm = client.cacheManager("default");
    RestResponse restResponse = sync(cm.healthStatus());
    assertEquals(200, restResponse.getStatus());
    assertEquals("HEALTHY", restResponse.getBody());
    String cliPath = resource("ispn-cli");
    String batchFile = resource("batch.file");
    String hostname = SERVERS.getTestServer().getDriver().getServerAddress(0).getHostAddress() + ":11222";
    String cliCmd = String.format("%s --connect %s --file=%s", cliPath, hostname, batchFile);
    ProcessBuilder pb = new ProcessBuilder("bash", "-c", cliCmd);
    pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
    Process p = pb.start();
    StringBuilder sb = new StringBuilder();
    new Thread(() -> {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }).start();
    p.waitFor(5, TimeUnit.SECONDS);
    assertEquals(0, p.exitValue());
    String stderr = sb.toString();
    if (!stderr.isEmpty()) {
        System.err.println(stderr);
        fail("Unexpected CLI output in stderr");
    }
    restResponse = sync(client.cache("mybatch").exists());
    assertEquals(204, restResponse.getStatus());
}
Also used : InputStreamReader(java.io.InputStreamReader) RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with RestCacheManagerClient

use of org.infinispan.client.rest.RestCacheManagerClient in project infinispan by infinispan.

the class XSiteResourceTest method testBringAllCachesOnlineOffline.

@Test
public void testBringAllCachesOnlineOffline() {
    RestClient restClient = clientPerSite.get(LON);
    RestCacheManagerClient restCacheManagerClient = restClient.cacheManager(CACHE_MANAGER);
    assertSuccessful(restCacheManagerClient.takeOffline(SFO));
    Json json = jsonResponseBody(restCacheManagerClient.backupStatuses());
    assertEquals(json.at(SFO).at("status").asString(), "offline");
    assertSuccessful(restCacheManagerClient.bringBackupOnline(SFO));
    json = jsonResponseBody(restCacheManagerClient.backupStatuses());
    assertEquals(json.at(SFO).at("status").asString(), "online");
}
Also used : RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestClient(org.infinispan.client.rest.RestClient) Json(org.infinispan.commons.dataconversion.internal.Json) Test(org.testng.annotations.Test) AbstractMultipleSitesTest(org.infinispan.xsite.AbstractMultipleSitesTest)

Example 5 with RestCacheManagerClient

use of org.infinispan.client.rest.RestCacheManagerClient in project infinispan by infinispan.

the class BackupManagerIT method testCreateDuplicateBackupResources.

@Test
public void testCreateDuplicateBackupResources() throws Exception {
    String backupName = "testCreateDuplicateBackupResources";
    // Start the source cluster
    startSourceCluster();
    RestClient client = source.getClient();
    populateContainer(client);
    RestCacheManagerClient cm = client.cacheManager("clustered");
    RestResponse response = await(cm.createBackup(backupName));
    assertEquals(202, response.getStatus());
    response = await(cm.createBackup(backupName));
    assertEquals(409, response.getStatus());
    response = await(cm.deleteBackup(backupName));
    // Expect a 202 response as the previous backup will be in progress, so the request is accepted for now
    assertEquals(202, response.getStatus());
    // Now wait until the backup has actually been deleted so that we successfully create another with the same name
    Common.awaitStatus(() -> cm.deleteBackup(backupName), 202, 404);
    response = await(cm.createBackup(backupName));
    assertEquals(202, response.getStatus());
    // Wait for the backup operation to finish
    awaitOk(() -> cm.getBackup(backupName, false));
    response = await(cm.deleteBackup(backupName));
    assertEquals(204, response.getStatus());
}
Also used : RestCacheManagerClient(org.infinispan.client.rest.RestCacheManagerClient) RestResponse(org.infinispan.client.rest.RestResponse) RestClient(org.infinispan.client.rest.RestClient) Test(org.junit.Test)

Aggregations

RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)8 RestResponse (org.infinispan.client.rest.RestResponse)6 Test (org.junit.Test)6 RestClient (org.infinispan.client.rest.RestClient)4 HashMap (java.util.HashMap)2 List (java.util.List)2 Json (org.infinispan.commons.dataconversion.internal.Json)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 RestCacheClient (org.infinispan.client.rest.RestCacheClient)1 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)1 AbstractMultipleSitesTest (org.infinispan.xsite.AbstractMultipleSitesTest)1 Test (org.testng.annotations.Test)1