Search in sources :

Example 1 with UpgradeTask

use of org.talend.dataprep.upgrade.model.UpgradeTask in project data-prep by Talend.

the class UpgradeService method upgradeUser.

public void upgradeUser(String userId) {
    LOG.info("Upgrade process starting for user {}", userId);
    int numberOfTasksApplied = 0;
    for (UpgradeTask task : tasks) {
        // skip non user upgrade task
        if (task.getTarget() != USER) {
            LOG.debug("{} does not target users", task.getId());
            continue;
        }
        final String targetId = USER.name() + '-' + userId;
        if (repository.isAlreadyApplied(targetId, task.getId())) {
            LOG.debug("{} already applied for user {}, let's skip it", task.getId(), userId);
        } else {
            LOG.debug("apply upgrade {} for user {}", task.getId(), userId);
            task.run();
            repository.applied(targetId, task.getId());
            numberOfTasksApplied++;
        }
    }
    LOG.info("Upgrade process finished for user {}, {} upgrade(s) performed", userId, numberOfTasksApplied);
}
Also used : UpgradeTask(org.talend.dataprep.upgrade.model.UpgradeTask)

Example 2 with UpgradeTask

use of org.talend.dataprep.upgrade.model.UpgradeTask in project data-prep by Talend.

the class UpgradeService method upgradeVersion.

/**
 * Apply all upgrade tasks that need to be applied once per version.
 */
public void upgradeVersion() {
    LOG.info("Global upgrade process starting");
    int numberOfTasksApplied = 0;
    for (UpgradeTask task : tasks) {
        final UpgradeTaskId taskId = task.getId();
        // skip non version upgrade task
        if (task.getTarget() != VERSION) {
            LOG.debug("{} does not target version", taskId);
            continue;
        }
        final String targetId = VERSION.name() + '-' + taskId.getVersion();
        if (repository.isAlreadyApplied(targetId, taskId)) {
            LOG.debug("{} already applied, let's skip it", taskId);
        } else {
            LOG.debug("apply upgrade {}", taskId);
            try {
                task.run();
            } catch (Exception exception) {
                LOG.error("Failed to apply upgrade {}", taskId);
                break;
            }
            repository.applied(targetId, taskId);
            numberOfTasksApplied++;
        }
    }
    LOG.info("Global upgrade process finished, {} upgrade(s) performed", numberOfTasksApplied);
}
Also used : UpgradeTaskId(org.talend.dataprep.upgrade.model.UpgradeTaskId) UpgradeTask(org.talend.dataprep.upgrade.model.UpgradeTask)

Example 3 with UpgradeTask

use of org.talend.dataprep.upgrade.model.UpgradeTask in project data-prep by Talend.

the class UpgradeServiceTest method shouldAllowUpgrade_tooManyTasksApplied.

@Test
public void shouldAllowUpgrade_tooManyTasksApplied() {
    // given
    when(repository.countUpgradeTask(anyString())).thenReturn(2);
    final UpgradeTask upgradeTask = mock(UpgradeTask.class);
    when(upgradeTask.getTarget()).thenReturn(VERSION);
    service.setTasks(Collections.singletonList(upgradeTask));
    // when
    assertTrue(service.needUpgrade());
}
Also used : UpgradeTask(org.talend.dataprep.upgrade.model.UpgradeTask) Test(org.junit.Test)

Example 4 with UpgradeTask

use of org.talend.dataprep.upgrade.model.UpgradeTask in project data-prep by Talend.

the class UpgradeServiceTest method shouldNotAllowUpgrade.

@Test
public void shouldNotAllowUpgrade() {
    // given
    when(repository.countUpgradeTask(anyString())).thenReturn(1);
    final UpgradeTask upgradeTask = mock(UpgradeTask.class);
    when(upgradeTask.getTarget()).thenReturn(VERSION);
    service.setTasks(Collections.singletonList(upgradeTask));
    // when
    assertFalse(service.needUpgrade());
}
Also used : UpgradeTask(org.talend.dataprep.upgrade.model.UpgradeTask) Test(org.junit.Test)

Example 5 with UpgradeTask

use of org.talend.dataprep.upgrade.model.UpgradeTask in project data-prep by Talend.

the class UpgradeServiceTest method shouldApplyTasksForVersion.

@Test
public void shouldApplyTasksForVersion() throws Exception {
    // given
    List<UpgradeTask> expected = new ArrayList<>();
    expected.add(new MockUpgradeTask("1.2.0-PE", "1.2.0-preums", 1, VERSION));
    expected.add(new MockUpgradeTask("1.2.0-PE", "1.2.0-deuz", 2, VERSION));
    expected.add(new MockUpgradeTask("1.2.0-PE", "1.2.0-troiz", 3, VERSION));
    List<UpgradeTask> unexpected = new ArrayList<>();
    unexpected.add(new MockUpgradeTask("1.2.0-PE", "1.2.0-deuz", 2, USER));
    unexpected.add(new MockUpgradeTask("1.3.0-PE", "1.3.0-1-troiz", 3, USER));
    unexpected.add(new MockUpgradeTask("1.4.0-PE", "1.4.0-preums", 1, USER));
    tasks.addAll(expected);
    tasks.addAll(unexpected);
    // when
    when(repository.isAlreadyApplied(anyString(), any())).thenReturn(false);
    service.upgradeVersion();
    // then
    for (UpgradeTask task : expected) {
        final MockUpgradeTask mockTask = (MockUpgradeTask) task;
        assertTrue(mockTask.applied);
    }
    for (UpgradeTask task : unexpected) {
        final MockUpgradeTask mockTask = (MockUpgradeTask) task;
        assertFalse(mockTask.applied);
    }
}
Also used : UpgradeTask(org.talend.dataprep.upgrade.model.UpgradeTask) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

UpgradeTask (org.talend.dataprep.upgrade.model.UpgradeTask)9 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)2 UpgradeTaskId (org.talend.dataprep.upgrade.model.UpgradeTaskId)1