use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method rollbackNonRollupPatchInstallation.
@Test
public void rollbackNonRollupPatchInstallation() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
Patch patch = management.trackPatch(patches.get(0));
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
ObjectId master1 = fork.getRepository().resolve("master");
String tx = management.beginInstallation(PatchKind.NON_ROLLUP);
management.install(tx, patch, null);
management.rollbackInstallation(tx);
fork.pull().call();
ObjectId master2 = fork.getRepository().resolve("master");
assertThat(master1, equalTo(master2));
assertThat(fork.tagList().call().size(), equalTo(2));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
}
use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method rollbackInstalledRollupPatch.
@Test
public void rollbackInstalledRollupPatch() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL());
Patch patch1 = management.trackPatch(patches.get(0));
patches = management.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL());
Patch patch4 = management.trackPatch(patches.get(0));
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
ObjectId master1 = fork.getRepository().resolve(GitPatchRepository.HISTORY_BRANCH);
String tx = management.beginInstallation(PatchKind.ROLLUP);
management.install(tx, patch4, null);
management.commitInstallation(tx);
// install P patch to check if rolling back rollup patch will remove P patch's tag
tx = management.beginInstallation(PatchKind.NON_ROLLUP);
management.install(tx, patch1, null);
management.commitInstallation(tx);
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
management.rollback(patch4.getPatchData());
repository.closeRepository(fork, true);
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
ObjectId master2 = fork.getRepository().resolve(GitPatchRepository.HISTORY_BRANCH);
assertThat(master1, not(equalTo(master2)));
assertThat(fork.tagList().call().size(), equalTo(2));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
assertFalse("When rolling back rollup patch, newer P patches' tags should be removed", repository.containsTag(fork, "patch-my-patch-1"));
assertThat(repository.findCurrentBaseline(fork).getTagName(), equalTo("baseline-6.2.0"));
// TODO: There should be version restored from backed up conflict
// but we've changed the way rolledback R patch handled - we copy entire WC after rollback
// String binStart = FileUtils.readFileToString(new File(karafHome, "bin/start"));
// assertTrue("bin/start should be at previous version",
// binStart.contains("echo \"This is user's change\""));
}
use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class FileBackupTest method backupSomeDataFiles.
@Test
public void backupSomeDataFiles() throws IOException {
PatchData patchData = new PatchData("my-patch");
patchData.setPatchLocation(new File(karafHome, "patches"));
PatchResult result = new PatchResult(patchData);
// updates installed bundle, has data dir
BundleUpdate b3 = new BundleUpdate("com.irrelevant.services", "1.2", "file:/dev/null", "1.1.0", "file:/dev/random");
// updates installed bundle, has data dir, but special case
BundleUpdate b4 = new BundleUpdate("org.apache.karaf.features.core", "1.3", "file:/dev/null", "1.2.1", "file:/dev/random");
// reinstalled bundle, has data dir
BundleUpdate b5 = new BundleUpdate("com.irrelevant.iot", null, null, "1.2.5", "file:/dev/random");
// reinstalled bundle, no data dir
BundleUpdate b6 = new BundleUpdate("com.irrelevant.space", null, null, "1.1.0", "file:/dev/random");
// update, but not for installed bundle
BundleUpdate b7 = new BundleUpdate("com.irrelevant.the.final.frontier", "1.5", "file:/dev/null", "1.1.3", "file:/dev/random");
result.getBundleUpdates().add(b3);
result.getBundleUpdates().add(b4);
result.getBundleUpdates().add(b5);
result.getBundleUpdates().add(b6);
result.getBundleUpdates().add(b7);
new FileBackupService(sys).backupDataFiles(result, Pending.ROLLUP_INSTALLATION);
Properties props = new Properties();
props.load(new FileInputStream(new File(karafHome, "patches/my-patch.datafiles/backup-install.properties")));
assertThat(props.getProperty("com.irrelevant.services$$1.1.0"), equalTo("com.irrelevant.services$$1.1.0"));
assertThat(props.getProperty("com.irrelevant.services$$1.2"), equalTo("com.irrelevant.services$$1.1.0"));
assertThat(props.getProperty("com.irrelevant.iot$$1.2.5"), equalTo("com.irrelevant.iot$$1.2.5"));
assertThat(props.stringPropertyNames().size(), equalTo(3));
assertTrue(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.services$$1.1.0/data/x").isDirectory());
assertTrue(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.iot$$1.2.5/data/z").isDirectory());
assertFalse(new File(karafHome, "patches/my-patch.datafiles/install/com.irrelevant.the.final.frontier$$1.5").isDirectory());
}
use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class ServiceImplTest method testLoadWithPrereqs.
@Test
public void testLoadWithPrereqs() throws IOException {
ServiceImpl service = createMockServiceImpl();
PatchData pd = PatchData.load(getClass().getClassLoader().getResourceAsStream("test-with-prereq.patch"));
assertEquals(2, pd.getBundles().size());
assertEquals(1, pd.getRequirements().size());
assertTrue(pd.getRequirements().contains("prereq1"));
assertNull(pd.getVersionRange("mvn:io.fabric8.test/test2/1.0.0"));
}
use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class ServiceImplTest method testVersionHistory.
@Test
public void testVersionHistory() {
// the same bundle has been patched twice
Patch patch1 = new Patch(new PatchData("patch1", "First patch", null, null, null, null, null), null);
patch1.setResult(new PatchResult(patch1.getPatchData(), true, System.currentTimeMillis(), new LinkedList<io.fabric8.patch.management.BundleUpdate>(), null));
patch1.getResult().getBundleUpdates().add(new BundleUpdate("my-bsn", "1.1.0", "mvn:groupId/my-bsn/1.1.0", "1.0.0", "mvn:groupId/my-bsn/1.0.0"));
Patch patch2 = new Patch(new PatchData("patch2", "Second patch", null, null, null, null, null), null);
patch2.setResult(new PatchResult(patch1.getPatchData(), true, System.currentTimeMillis(), new LinkedList<io.fabric8.patch.management.BundleUpdate>(), null));
patch2.getResult().getBundleUpdates().add(new BundleUpdate("my-bsn;directive1=true", "1.2.0", "mvn:groupId/my-bsn/1.2.0", "1.1.0", "mvn:groupId/my-bsn/1.1.0"));
Map<String, Patch> patches = new HashMap<String, Patch>();
patches.put("patch1", patch1);
patches.put("patch2", patch2);
// the version history should return the correct URL, even when bundle.getLocation() does not
ServiceImpl.BundleVersionHistory history = new ServiceImpl.BundleVersionHistory(patches);
assertEquals("Should return version from patch result instead of the original location", "mvn:groupId/my-bsn/1.2.0", history.getLocation(createMockBundle("my-bsn", "1.2.0", "mvn:groupId/my-bsn/1.0.0")));
assertEquals("Should return version from patch result instead of the original location", "mvn:groupId/my-bsn/1.1.0", history.getLocation(createMockBundle("my-bsn", "1.1.0", "mvn:groupId/my-bsn/1.0.0")));
assertEquals("Should return original bundle location if no maching version is found in the history", "mvn:groupId/my-bsn/1.0.0", history.getLocation(createMockBundle("my-bsn", "1.0.0", "mvn:groupId/my-bsn/1.0.0")));
assertEquals("Should return original bundle location if no maching version is found in the history", "mvn:groupId/my-bsn/0.9.0", history.getLocation(createMockBundle("my-bsn", "0.9.0", "mvn:groupId/my-bsn/0.9.0")));
}
Aggregations