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);
}
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);
}
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());
}
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");
}
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());
}
Aggregations