Search in sources :

Example 1 with EntrySource

use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testFallbackEphemeralStoreWhenMigrating.

@Test
public void testFallbackEphemeralStoreWhenMigrating() throws Exception {
    EphemeralStore destination = EphemeralStore.getFactory().getStore();
    EntrySource source = new DummyEntrySource(acct);
    Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    //DummyMigrationCallback will store attributes in InMemoryEphemeralStore, and track deletions in deletedAttrs map
    MigrationCallback callback = new DummyMigrationCallback(destination, deletedAttrs);
    AttributeMigration migration = new AttributeMigration(attrsToMigrate, source, callback, null);
    migration.beginMigration();
    //set to in-memory backend because fallback won't be enabled with default LDAP backend
    EphemeralStore.setFactory(InMemoryEphemeralStore.Factory.class);
    Factory factory = EphemeralStore.getFactory();
    EphemeralStore store = factory.getStore();
    //in-memory backend will be wrapped in a FallbackEphemeralStore, with LDAP as the fallback
    assertTrue(store instanceof FallbackEphemeralStore);
    FallbackEphemeralStore fallbackStore = (FallbackEphemeralStore) store;
    assertTrue(fallbackStore.getPrimaryStore() instanceof InMemoryEphemeralStore);
    assertTrue(fallbackStore.getSecondaryStore() instanceof LdapEphemeralStore);
    migration.endMigration();
    EphemeralStore.setFactory(InMemoryEphemeralStore.Factory.class);
    //when migration is finished, fallback won't be enabled anymore
    factory = EphemeralStore.getFactory();
    store = factory.getStore();
    assertTrue(store instanceof InMemoryEphemeralStore);
}
Also used : InMemoryEphemeralStore(com.zimbra.cs.ephemeral.InMemoryEphemeralStore) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) Factory(com.zimbra.cs.ephemeral.EphemeralStore.Factory) MigrationCallback(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) FallbackEphemeralStore(com.zimbra.cs.ephemeral.FallbackEphemeralStore) FallbackEphemeralStore(com.zimbra.cs.ephemeral.FallbackEphemeralStore) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) InMemoryEphemeralStore(com.zimbra.cs.ephemeral.InMemoryEphemeralStore) Test(org.junit.Test)

Example 2 with EntrySource

use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testMigrateAlreadyMigratedAccount.

@Test
public void testMigrateAlreadyMigratedAccount() throws Exception {
    Provisioning prov = Provisioning.getInstance();
    // create a new account that will not have any data to migrate
    Account acct = prov.createAccount("user2", "test123", new HashMap<String, Object>());
    EntrySource source = new DummyEntrySource(acct);
    Multimap<String, Object> deletedAttrs = LinkedListMultimap.create();
    List<EphemeralInput> results = new LinkedList<EphemeralInput>();
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    DummyMigrationCallback callback = new DummyMigrationCallback(results);
    callback.throwErrorDuringMigration = false;
    AttributeMigration.setCallback(callback);
    AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
    migration.migrateAllAccounts();
    assertTrue(results.isEmpty());
}
Also used : Account(com.zimbra.cs.account.Account) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) Provisioning(com.zimbra.cs.account.Provisioning) LinkedList(java.util.LinkedList) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) Test(org.junit.Test)

Example 3 with EntrySource

use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testMigrationInfo.

@Test
public void testMigrationInfo() throws Exception {
    MigrationInfo info = MigrationInfo.getFactory().getInfo();
    try {
        EphemeralStore destination = EphemeralStore.getFactory().getStore();
        EntrySource source = new DummyEntrySource(acct);
        List<String> attrsToMigrate = new ArrayList<String>();
        MigrationCallback callback = new DummyMigrationCallback(destination);
        AttributeMigration.setCallback(callback);
        AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
        assertEquals(Status.NONE, info.getStatus());
        migration.beginMigration();
        assertEquals(Status.IN_PROGRESS, info.getStatus());
        migration.endMigration();
        assertEquals(Status.COMPLETED, info.getStatus());
    } finally {
        info.clearData();
    }
}
Also used : ArrayList(java.util.ArrayList) MigrationCallback(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) Test(org.junit.Test)

Example 4 with EntrySource

use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testAttributeMigration.

/*
     * Test end-to-end AttributeMigration
     */
@Test
public void testAttributeMigration() throws Exception {
    EphemeralStore destination = EphemeralStore.getFactory().getStore();
    EntrySource source = new DummyEntrySource(acct);
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    // DummyMigrationCallback will store attributes in InMemoryEphemeralStore, and track deletions in deletedAttrs map
    MigrationCallback callback = new DummyMigrationCallback(destination);
    AttributeMigration.setCallback(callback);
    AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
    MigrationInfo info = MigrationInfo.getFactory().getInfo();
    // disable running in separate thread
    // run migration
    migration.migrateAllAccounts();
    EphemeralLocation location = new LdapEntryLocation(acct);
    EphemeralResult result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "1234"), location);
    assertEquals("server_1", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraAuthTokens, "5678"), location);
    assertEquals("server_2", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb1"), location);
    assertEquals("data1", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraCsrfTokenData, "crumb2"), location);
    assertEquals("data2", result.getValue());
    result = destination.get(new EphemeralKey(Provisioning.A_zimbraLastLogonTimestamp), location);
    assertEquals("currentdate", result.getValue());
    assertTrue(info.getStatus() == Status.COMPLETED);
}
Also used : EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) MigrationCallback(com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) EphemeralResult(com.zimbra.cs.ephemeral.EphemeralResult) LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) Test(org.junit.Test)

Example 5 with EntrySource

use of com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource in project zm-mailbox by Zimbra.

the class MigrateAttributesTest method testErrorDuringMigration.

@Test
public void testErrorDuringMigration() throws Exception {
    List<EphemeralInput> results = new LinkedList<EphemeralInput>();
    EntrySource source = new DummyEntrySource(acct, acct, acct);
    List<String> attrsToMigrate = Arrays.asList(new String[] { Provisioning.A_zimbraAuthTokens, Provisioning.A_zimbraCsrfTokenData, Provisioning.A_zimbraLastLogonTimestamp });
    DummyMigrationCallback callback = new DummyMigrationCallback(results);
    callback.throwErrorDuringMigration = true;
    AttributeMigration.setCallback(callback);
    AttributeMigration migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, null);
    MigrationInfo info = MigrationInfo.getFactory().getInfo();
    info.clearData();
    try {
        migration.migrateAllAccounts();
        fail("synchronous migration should throw an exception");
    } catch (ServiceException e) {
        // make sure the root exception got thrown
        assertTrue(e.getMessage().contains("Failure during migration"));
    }
    // make sure nothing got migrated
    assertEquals(0, results.size());
    migration = new AttributeMigration("testAttributeMigration", attrsToMigrate, source, 3);
    info.clearData();
    try {
        migration.migrateAllAccounts();
        fail("async migration should throw an exception");
    } catch (ServiceException e) {
        assertTrue(e.getMessage().contains("Failure during migration"));
        assertTrue(info.getStatus() == Status.FAILED);
    }
    assertEquals(0, results.size());
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) LinkedList(java.util.LinkedList) EntrySource(com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource) Test(org.junit.Test)

Aggregations

EntrySource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.EntrySource)6 Test (org.junit.Test)5 MigrationCallback (com.zimbra.cs.ephemeral.migrate.AttributeMigration.MigrationCallback)4 EphemeralStore (com.zimbra.cs.ephemeral.EphemeralStore)3 ServiceException (com.zimbra.common.service.ServiceException)2 EphemeralInput (com.zimbra.cs.ephemeral.EphemeralInput)2 LinkedList (java.util.LinkedList)2 Account (com.zimbra.cs.account.Account)1 Provisioning (com.zimbra.cs.account.Provisioning)1 EphemeralKey (com.zimbra.cs.ephemeral.EphemeralKey)1 EphemeralLocation (com.zimbra.cs.ephemeral.EphemeralLocation)1 EphemeralResult (com.zimbra.cs.ephemeral.EphemeralResult)1 Factory (com.zimbra.cs.ephemeral.EphemeralStore.Factory)1 FallbackEphemeralStore (com.zimbra.cs.ephemeral.FallbackEphemeralStore)1 InMemoryEphemeralStore (com.zimbra.cs.ephemeral.InMemoryEphemeralStore)1 LdapEntryLocation (com.zimbra.cs.ephemeral.LdapEntryLocation)1 LdapEphemeralStore (com.zimbra.cs.ephemeral.LdapEphemeralStore)1 AllAccountsSource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.AllAccountsSource)1 DryRunMigrationCallback (com.zimbra.cs.ephemeral.migrate.AttributeMigration.DryRunMigrationCallback)1 SomeAccountsSource (com.zimbra.cs.ephemeral.migrate.AttributeMigration.SomeAccountsSource)1