Search in sources :

Example 26 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class IncrementalBackupDUnitTest method assertBackupStatus.

/**
   * Used to confirm valid BackupStatus data. Confirms fix for defect #45657
   * 
   * @param backupStatus contains a list of members that were backed up.
   */
private void assertBackupStatus(final BackupStatus backupStatus) {
    Map<DistributedMember, Set<PersistentID>> backupMap = backupStatus.getBackedUpDiskStores();
    assertFalse(backupMap.isEmpty());
    for (DistributedMember member : backupMap.keySet()) {
        for (PersistentID id : backupMap.get(member)) {
            assertNotNull(id.getHost());
            assertNotNull(id.getUUID());
            assertNotNull(id.getDirectory());
        }
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) DistributedMember(org.apache.geode.distributed.DistributedMember) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 27 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class IncrementalBackupDUnitTest method getPersistentID.

/**
   * Locates the PersistentID for the testStore disk store for a distributed member.
   * 
   * @param vm a distributed member.
   * @return a PersistentID for a member's disk store.
   */
private PersistentID getPersistentID(final VM vm, final String diskStoreName) {
    return vm.invoke(() -> {
        PersistentID id = null;
        Collection<DiskStore> diskStores = ((InternalCache) getCache()).listDiskStores();
        for (DiskStore diskStore : diskStores) {
            if (diskStore.getName().equals(diskStoreName)) {
                id = ((DiskStoreImpl) diskStore).getPersistentID();
                break;
            }
        }
        return id;
    });
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) PersistentID(org.apache.geode.cache.persistence.PersistentID)

Example 28 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class IncrementalBackupDUnitTest method testBackupUserDeployedJarFiles.

/**
   * Successful if a user deployed jar file is included as part of the backup.
   */
@Test
public void testBackupUserDeployedJarFiles() throws Exception {
    final String jarName = "BackupJarDeploymentDUnit";
    final String jarNameRegex = ".*" + jarName + ".*";
    final ClassBuilder classBuilder = new ClassBuilder();
    final byte[] classBytes = classBuilder.createJarFromName(jarName);
    VM vm0 = Host.getHost(0).getVM(0);
    /*
     * Deploy a "dummy" jar to the VM.
     */
    File deployedJarFile = vm0.invoke(() -> {
        DeployedJar deployedJar = ClassPathLoader.getLatest().getJarDeployer().deploy(jarName, classBytes);
        return deployedJar.getFile();
    });
    assertTrue(deployedJarFile.exists());
    /*
     * Perform backup. Make sure it is successful.
     */
    assertBackupStatus(baseline(vm0));
    /*
     * Make sure the user deployed jar is part of the backup.
     */
    Collection<File> memberDeployedJarFiles = FileUtils.listFiles(getBackupDirForMember(getBaselineDir(), getMemberId(vm0)), new RegexFileFilter(jarNameRegex), DirectoryFileFilter.DIRECTORY);
    assertFalse(memberDeployedJarFiles.isEmpty());
    // Shut down our member so we can perform a restore
    PersistentID id = getPersistentID(vm0);
    closeCache(vm0);
    /*
     * Get the VM's user directory.
     */
    final String vmDir = vm0.invoke(() -> System.getProperty("user.dir"));
    File backupDir = getBackupDirForMember(getBaselineDir(), getMemberId(vm0));
    vm0.bounce();
    /*
     * Cleanup "dummy" jar from file system.
     */
    Pattern pattern = Pattern.compile('^' + jarName + ".*#\\d++$");
    deleteMatching(new File("."), pattern);
    // Execute the restore
    performRestore(new File(id.getDirectory()), backupDir);
    /*
     * Make sure the user deployed jar is part of the restore.
     */
    Collection<File> restoredJars = FileUtils.listFiles(new File(vmDir), new RegexFileFilter(jarNameRegex), DirectoryFileFilter.DIRECTORY);
    assertFalse(restoredJars.isEmpty());
    List<String> restoredJarNames = new LinkedList<>();
    TransformUtils.transform(memberDeployedJarFiles, restoredJarNames, TransformUtils.fileNameTransformer);
    for (String name : restoredJarNames) {
        assertTrue(name.contains(jarName));
    }
    // Restart the member
    openCache(vm0);
    /*
     * Remove the "dummy" jar from the VM.
     */
    vm0.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            for (DeployedJar jarClassLoader : ClassPathLoader.getLatest().getJarDeployer().findDeployedJars()) {
                if (jarClassLoader.getJarName().startsWith(jarName)) {
                    ClassPathLoader.getLatest().getJarDeployer().undeploy(jarClassLoader.getJarName());
                }
            }
            return null;
        }
    });
    /*
     * Cleanup "dummy" jar from file system.
     */
    pattern = Pattern.compile('^' + jarName + ".*#\\d++$");
    deleteMatching(new File(vmDir), pattern);
}
Also used : DeployedJar(org.apache.geode.internal.DeployedJar) Pattern(java.util.regex.Pattern) RegexFileFilter(org.apache.commons.io.filefilter.RegexFileFilter) ClassBuilder(org.apache.geode.internal.ClassBuilder) LinkedList(java.util.LinkedList) AdminException(org.apache.geode.admin.AdminException) IOException(java.io.IOException) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) File(java.io.File) PersistentID(org.apache.geode.cache.persistence.PersistentID) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Example 29 with PersistentID

use of org.apache.geode.cache.persistence.PersistentID in project geode by apache.

the class IncrementalBackupDUnitTest method disconnect.

/**
   * Invokes {@link DistributedSystem#disconnect()} on a member.
   * 
   * @param disconnectVM a member of the distributed system to disconnect.
   * @param testVM a member of the distributed system to test for the missing member (just
   *        disconnected).
   */
private PersistentID disconnect(final VM disconnectVM, final VM testVM) {
    final PersistentID id = disconnectVM.invoke(() -> {
        PersistentID persistentID = null;
        Collection<DiskStore> diskStores = ((InternalCache) getCache()).listDiskStores();
        for (DiskStore diskStore : diskStores) {
            if (diskStore.getName().equals("fooStore")) {
                persistentID = ((DiskStoreImpl) diskStore).getPersistentID();
                break;
            }
        }
        getSystem().disconnect();
        return persistentID;
    });
    final Set<PersistentID> missingMembers = new HashSet<>();
    Wait.waitForCriterion(new WaitCriterion() {

        @Override
        public boolean done() {
            missingMembers.clear();
            missingMembers.addAll(getMissingMembers(testVM));
            return missingMembers.contains(id);
        }

        @Override
        public String description() {
            return "[IncrementalBackupDUnitTest] Waiting for missing member " + id;
        }
    }, 10000, 500, false);
    return id;
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) PersistentID(org.apache.geode.cache.persistence.PersistentID) HashSet(java.util.HashSet)

Aggregations

PersistentID (org.apache.geode.cache.persistence.PersistentID)29 HashSet (java.util.HashSet)11 File (java.io.File)8 Set (java.util.Set)8 IOException (java.io.IOException)7 DiskStore (org.apache.geode.cache.DiskStore)7 InternalCache (org.apache.geode.internal.cache.InternalCache)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)5 DistributedMember (org.apache.geode.distributed.DistributedMember)5 Map (java.util.Map)4 AdminException (org.apache.geode.admin.AdminException)4 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)4 LinkedList (java.util.LinkedList)3 TreeSet (java.util.TreeSet)3 RegexFileFilter (org.apache.commons.io.filefilter.RegexFileFilter)3 AdminDistributedSystem (org.apache.geode.admin.AdminDistributedSystem)3 BackupStatus (org.apache.geode.admin.BackupStatus)3 DistributedSystemConfig (org.apache.geode.admin.DistributedSystemConfig)3