use of org.apache.geode.admin.AdminDistributedSystem in project geode by apache.
the class PersistentPartitionedRegionTestBase method backup.
// used for above test
protected BackupStatus backup(VM vm) {
return (BackupStatus) vm.invoke(new SerializableCallable("Backup all members") {
public Object call() {
DistributedSystemConfig config;
AdminDistributedSystem adminDS = null;
try {
config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
adminDS.waitToBeConnected(MAX_WAIT);
return adminDS.backupAllMembers(getBackupDir());
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
});
}
use of org.apache.geode.admin.AdminDistributedSystem in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testCompactFromAdmin.
/**
* Tests to make sure that we stop waiting for a member that we revoke.
*
* @throws Exception
*/
@Test
public void testCompactFromAdmin() throws Exception {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
createPersistentRegionWithoutCompaction(vm0);
createPersistentRegionWithoutCompaction(vm1);
vm1.invoke(new SerializableRunnable("Create some data") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 1024; i++) {
region.put(i, new byte[1024]);
}
for (int i = 2; i < 1024; i++) {
assertTrue(region.destroy(i) != null);
}
DiskStore store = cache.findDiskStore(REGION_NAME);
store.forceRoll();
}
});
// vm1.invoke(new SerializableRunnable("compact") {
// public void run() {
// Cache cache = getCache();
// DiskStore ds = cache.findDiskStore(REGION_NAME);
// assertTrue(ds.forceCompaction());
// }
// });
//
// vm0.invoke(new SerializableRunnable("compact") {
// public void run() {
// Cache cache = getCache();
// DiskStore ds = cache.findDiskStore(REGION_NAME);
// assertTrue(ds.forceCompaction());
// }
// });
vm2.invoke(new SerializableRunnable("Compact") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
DistributedSystemConfig config;
AdminDistributedSystem adminDS = null;
try {
config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
Map<DistributedMember, Set<PersistentID>> missingIds = adminDS.compactAllDiskStores();
assertEquals(2, missingIds.size());
for (Set<PersistentID> value : missingIds.values()) {
assertEquals(1, value.size());
}
} catch (AdminException e) {
throw new RuntimeException(e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
});
SerializableRunnable compactVM = new SerializableRunnable("compact") {
public void run() {
Cache cache = getCache();
DiskStore ds = cache.findDiskStore(REGION_NAME);
assertFalse(ds.forceCompaction());
}
};
vm0.invoke(compactVM);
vm1.invoke(compactVM);
}
use of org.apache.geode.admin.AdminDistributedSystem in project geode by apache.
the class IncrementalBackupDUnitTest method testMissingBaseline.
/**
* Successful if all members perform a full backup when they share the baseline directory and it
* is missing.
*/
@Test
public void testMissingBaseline() throws Exception {
/*
* Get the member ID for VM 1 and perform a baseline.
*/
String memberId = getMemberId(Host.getHost(0).getVM(1));
assertBackupStatus(performBaseline());
/*
* Find all of the member's oplogs in the baseline (*.crf,*.krf,*.drf)
*/
Collection<File> memberBaselineOplogs = FileUtils.listFiles(getBackupDirForMember(getBaselineDir(), memberId), new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
assertFalse(memberBaselineOplogs.isEmpty());
List<String> memberBaselineOplogNames = new LinkedList<>();
TransformUtils.transform(memberBaselineOplogs, memberBaselineOplogNames, TransformUtils.fileNameTransformer);
/*
* Custom incremental backup callable that retrieves the current baseline before deletion.
*/
SerializableCallable callable = new SerializableCallable("Backup all members.") {
private final File baselineDir = getBaselineBackupDir();
@Override
public Object call() {
AdminDistributedSystem adminDS = null;
try {
DistributedSystemConfig config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
return adminDS.backupAllMembers(getIncrementalDir(), this.baselineDir);
} catch (AdminException e) {
throw new RuntimeException(e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
};
/*
* Do an incremental after deleting the baseline. It should discover that the baseline is gone
* and backup all of the operation logs that are in the baseline.
*/
FileUtils.deleteDirectory(getBaselineDir());
Host.getHost(0).getVM(1).invoke(callable);
/*
* Find all of the member's oplogs in the incremental (*.crf,*.krf,*.drf)
*/
Collection<File> memberIncrementalOplogs = FileUtils.listFiles(getBackupDirForMember(getIncrementalDir(), memberId), new RegexFileFilter(OPLOG_REGEX), DirectoryFileFilter.DIRECTORY);
assertFalse(memberIncrementalOplogs.isEmpty());
List<String> memberIncrementalOplogNames = new LinkedList<>();
TransformUtils.transform(memberIncrementalOplogs, memberIncrementalOplogNames, TransformUtils.fileNameTransformer);
/*
* Assert that all of the baseline operation logs are in the incremental backup. If so, then the
* missing baseline was discovered by the incremental backup process.
*/
for (String oplog : memberBaselineOplogNames) {
assertTrue(memberIncrementalOplogNames.contains(oplog));
}
}
use of org.apache.geode.admin.AdminDistributedSystem in project geode by apache.
the class IncrementalBackupDUnitTest method incremental2.
/**
* Invokes {@link AdminDistributedSystem#backupAllMembers(File, File)} on a member.
*
* @param vm a member of the distributed system.
* @return a status of the backup operation.
*/
private BackupStatus incremental2(VM vm) {
return (BackupStatus) vm.invoke(new SerializableCallable("Backup all members.") {
@Override
public Object call() {
DistributedSystemConfig config;
AdminDistributedSystem adminDS = null;
try {
config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
return adminDS.backupAllMembers(getIncremental2Dir(), getIncrementalBackupDir());
} catch (AdminException e) {
throw new RuntimeException(e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
});
}
use of org.apache.geode.admin.AdminDistributedSystem in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method testRevokeAHostBeforeInitialization.
/**
* Tests to make sure that we can revoke a member before initialization, and that member will stay
* revoked
*
* @throws Exception
*/
@Test
public void testRevokeAHostBeforeInitialization() throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
LogWriterUtils.getLogWriter().info("Creating region in VM1");
createPersistentRegion(vm1);
putAnEntry(vm0);
vm0.invoke(new SerializableRunnable("Check for waiting regions") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
PersistentMemberManager mm = cache.getPersistentMemberManager();
Map<String, Set<PersistentMemberID>> waitingRegions = mm.getWaitingRegions();
assertEquals(0, waitingRegions.size());
}
});
LogWriterUtils.getLogWriter().info("closing region in vm0");
closeRegion(vm0);
updateTheEntry(vm1);
LogWriterUtils.getLogWriter().info("closing region in vm1");
closeRegion(vm1);
final File dirToRevoke = getDiskDirForVM(vm1);
vm2.invoke(new SerializableRunnable("Revoke the member") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
DistributedSystemConfig config;
AdminDistributedSystem adminDS = null;
try {
config = AdminDistributedSystemFactory.defineDistributedSystem(getSystem(), "");
adminDS = AdminDistributedSystemFactory.getDistributedSystem(config);
adminDS.connect();
adminDS.revokePersistentMember(InetAddress.getLocalHost(), dirToRevoke.getCanonicalPath());
} catch (Exception e) {
Assert.fail("Unexpected exception", e);
} finally {
if (adminDS != null) {
adminDS.disconnect();
}
}
}
});
// This shouldn't wait, because we revoked the member
LogWriterUtils.getLogWriter().info("Creating region in VM0");
createPersistentRegion(vm0);
checkForRecoveryStat(vm0, true);
// Check to make sure we recovered the old
// value of the entry.
SerializableRunnable checkForEntry = new SerializableRunnable("check for the entry") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
assertEquals("B", region.get("A"));
}
};
vm0.invoke(checkForEntry);
// Now, we should not be able to create a region
// in vm1, because the this member was revoked
LogWriterUtils.getLogWriter().info("Creating region in VM1");
IgnoredException e = IgnoredException.addIgnoredException(RevokedPersistentDataException.class.getSimpleName(), vm1);
try {
createPersistentRegion(vm1);
fail("We should have received a split distributed system exception");
} catch (RuntimeException expected) {
if (!(expected.getCause() instanceof RevokedPersistentDataException)) {
throw expected;
}
// Do nothing
} finally {
e.remove();
}
}
Aggregations