use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceForStandaloneChildContainersIT method installRollupPatch.
@Test
public void installRollupPatch() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInPatches();
freshKarafStandaloneDistro();
PatchManagement management = (PatchManagement) pm;
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
repository.prepareCommit(fork, "artificial change, not treated as user change (could be a patch)").call();
repository.prepareCommit(fork, "artificial change, not treated as user change").call();
// no changes, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
FileUtils.write(new File(karafBase, "bin/start"), "echo \"another user change\"\n", true);
// conflicting change, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
FileUtils.write(new File(karafBase, "bin/test"), "echo \"another user change\"\n");
// non-conflicting
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.closeRepository(fork, true);
preparePatchZip("src/test/resources/content/patch7", "target/karaf/patches/source/patch-7.zip", false);
List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-7.zip").toURI().toURL());
Patch patch = management.trackPatch(patches.get(0));
String tx = management.beginInstallation(PatchKind.ROLLUP);
management.install(tx, patch, null);
@SuppressWarnings("unchecked") Map<String, Git> transactions = (Map<String, Git>) getField(management, "pendingTransactions");
assertThat(transactions.size(), equalTo(1));
fork = transactions.values().iterator().next();
ObjectId since = fork.getRepository().resolve("baseline-child-2.4.0.redhat-620133^{commit}");
ObjectId to = fork.getRepository().resolve(tx);
Iterable<RevCommit> commits = fork.log().addRange(since, to).call();
// only one "user change", because we had two conflicts with new baseline - they were resolved
// by picking what already comes from rollup patch ("ours"):
/*
* Problem with applying the change 657f11c4b65bb7893a2b82f888bb9731a6d5f7d0:
* - bin/start: BOTH_MODIFIED
* Choosing "ours" change
* Problem with applying the change d9272b97582582f4b056f7170130ec91fc21aeac:
* - bin/start: BOTH_MODIFIED
* Choosing "ours" change
*/
List<String> commitList = Arrays.asList("[PATCH] Apply user changes", "[PATCH] Apply user changes", "[PATCH] Apply user changes", "[PATCH] Rollup patch patch-7 - resetting etc/overrides.properties", "[PATCH/baseline] Installing baseline-child-2.4.0.redhat-621084");
int n = 0;
for (RevCommit c : commits) {
String msg = c.getShortMessage();
assertThat(msg, equalTo(commitList.get(n++)));
}
assertThat(n, equalTo(commitList.size()));
assertThat(fork.tagList().call().size(), equalTo(4));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
assertFalse(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-620133"));
assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
}
use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceForStandaloneChildContainersIT method rollbackInstalledRollupPatch.
@Test
public void rollbackInstalledRollupPatch() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInPatches();
freshKarafStandaloneDistro();
PatchManagement management = (PatchManagement) pm;
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
preparePatchZip("src/test/resources/content/patch7", "target/karaf/patches/source/patch-7.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-7.zip").toURI().toURL());
Patch patch7 = management.trackPatch(patches.get(0));
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
ObjectId master1 = fork.getRepository().resolve(GitPatchRepository.ADMIN_HISTORY_BRANCH + "-child");
String tx = management.beginInstallation(PatchKind.ROLLUP);
management.install(tx, patch7, 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);
assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
assertTrue(repository.containsTag(fork, "patch-my-patch-1-child"));
assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-620133"));
assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
management.rollback(patch7.getPatchData());
repository.closeRepository(fork, true);
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
ObjectId master2 = fork.getRepository().resolve(GitPatchRepository.ADMIN_HISTORY_BRANCH + "-child");
assertThat(master1, not(equalTo(master2)));
assertThat(fork.tagList().call().size(), equalTo(4));
assertTrue(repository.containsTag(fork, "patch-management"));
assertFalse("P patch1 should be not visible as installed", repository.containsTag(fork, "patch-my-patch-1-child"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-620133"));
assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
assertFalse(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084-child"));
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-child-2.4.0.redhat-620133"));
}
use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method addPatch4.
/**
* Patch 4 is rollup patch (doesn't contain descriptor, contains default.profile/io.fabric8.version.properties)
* Adding it is not different that adding non-rollup patch. Installation is different
* @throws IOException
* @throws GitAPIException
*/
@Test
public void addPatch4() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInSystem();
// prepare some ZIP patches
preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
PatchManagement service = (PatchManagement) pm;
PatchData patchData = service.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL()).get(0);
assertThat(patchData.getId(), equalTo("patch-4"));
Patch patch = service.trackPatch(patchData);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
// we should see remote branch for the patch, but without checking it out, it won't be available in the clone's local branches
List<Ref> branches = fork.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
Ref patchBranch = null;
for (Ref remoteBranch : branches) {
if (String.format("refs/remotes/origin/patch-%s", patchData.getId()).equals(remoteBranch.getName())) {
patchBranch = remoteBranch;
break;
}
}
assertNotNull("Should find remote branch for the added patch", patchBranch);
assertThat(patch.getManagedPatch().getCommitId(), equalTo(patchBranch.getObjectId().getName()));
RevCommit patchCommit = new RevWalk(fork.getRepository()).parseCommit(patchBranch.getObjectId());
// patch commit should be child of baseline commit
RevCommit baselineCommit = new RevWalk(fork.getRepository()).parseCommit(patchCommit.getParent(0));
// this baseline commit should be tagged "baseline-VERSION"
Ref tag = fork.tagList().call().get(0);
assertThat(tag.getName(), equalTo("refs/tags/baseline-6.2.0"));
RevCommit baselineCommitFromTag = new RevWalk(fork.getRepository()).parseCommit(tag.getTarget().getObjectId());
assertThat(baselineCommit.getId(), equalTo(baselineCommitFromTag.getId()));
List<DiffEntry> patchDiff = repository.diff(fork, baselineCommit, patchCommit);
int changes = SystemUtils.IS_OS_WINDOWS ? 8 : 9;
assertThat("patch-4 should lead to " + changes + " changes", patchDiff.size(), equalTo(changes));
for (Iterator<DiffEntry> iterator = patchDiff.iterator(); iterator.hasNext(); ) {
DiffEntry de = iterator.next();
if ("bin/start".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
iterator.remove();
}
if ("bin/stop".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
iterator.remove();
}
if (!SystemUtils.IS_OS_WINDOWS && "bin/setenv".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
iterator.remove();
}
if ("etc/startup.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
iterator.remove();
}
if ("etc/my.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.ADD) {
iterator.remove();
}
if ("etc/system.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
iterator.remove();
}
if ("fabric/import/fabric/profiles/default.profile/io.fabric8.agent.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
iterator.remove();
}
if ("fabric/import/fabric/profiles/default.profile/io.fabric8.version.properties".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.MODIFY) {
iterator.remove();
}
if ("patch-info.txt".equals(de.getNewPath()) && de.getChangeType() == DiffEntry.ChangeType.ADD) {
iterator.remove();
}
}
assertThat("Unknown changes in patch-4", patchDiff.size(), equalTo(0));
// let's see the patch applied to baseline-6.2.0
fork.checkout().setName("patch-4").setStartPoint("origin/patch-patch-4").setCreateBranch(true).call();
String startupProperties = FileUtils.readFileToString(new File(fork.getRepository().getWorkTree(), "etc/startup.properties"));
assertTrue(startupProperties.contains("org/ops4j/pax/url/pax-url-gopher/2.4.0/pax-url-gopher-2.4.0.jar=5"));
repository.closeRepository(fork, true);
}
use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method installPPatchAndThenRPatch.
@Test
public void installPPatchAndThenRPatch() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInSystem();
// prepare some ZIP patches
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);
// simulation of P patch installed using old patching mechanism
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
FileUtils.write(new File(karafHome, "etc/overrides.properties"), "mvn:io.fabric8/fabric-oceans/1.4.2\n");
// non-conflicting
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.closeRepository(fork, true);
// overrides.properties as after installing P patch with old mechanism
String etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
assertThat(etcOverridesProperties, equalTo("mvn:io.fabric8/fabric-oceans/1.4.2\n"));
PatchManagement service = (PatchManagement) pm;
PatchData patchData1 = service.fetchPatches(new File("target/karaf/patches/source/patch-1.zip").toURI().toURL()).get(0);
Patch patch1 = service.trackPatch(patchData1);
PatchData patchData4 = service.fetchPatches(new File("target/karaf/patches/source/patch-4.zip").toURI().toURL()).get(0);
Patch patch4 = service.trackPatch(patchData4);
String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
service.install(tx, patch1, null);
service.commitInstallation(tx);
assertTrue("There should be etc/overrides.properties after installing non-rollup patch", new File(karafHome, "etc/overrides.properties").exists());
// overrides.properties as after installing P patch with new mechanism
etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
assertThat(etcOverridesProperties, equalTo("mvn:io.fabric8/fabric-oceans/1.4.2\n" + "mvn:io.fabric8/fabric-tranquility/1.2.3\n"));
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
assertFalse(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
repository.closeRepository(fork, true);
tx = service.beginInstallation(PatchKind.ROLLUP);
service.install(tx, patch4, null);
service.commitInstallation(tx);
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
assertFalse("There should be no etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
repository.closeRepository(fork, true);
}
use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method installNonRollupPatchWithUberJars.
@Test
public void installNonRollupPatchWithUberJars() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement("baseline4");
PatchManagement management = (PatchManagement) pm;
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
// no changes, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.prepareCommit(fork, "artificial change, not treated as user change (could be a patch)").call();
repository.push(fork);
repository.closeRepository(fork, true);
preparePatchZip("src/test/resources/content/patch8", "target/karaf/patches/source/patch-8.zip", false);
List<PatchData> patches = management.fetchPatches(new File("target/karaf/patches/source/patch-8.zip").toURI().toURL());
Patch patch = management.trackPatch(patches.get(0));
String tx = management.beginInstallation(PatchKind.NON_ROLLUP);
/*
* bundle.0 = mvn:io.fabric8/pax-romana/1.0.1
* bundle.1 = mvn:io.fabric8/pax-hellenica/1.0.1/jar
* # for these two, bundle.getLocation() will return non-matching location
* bundle.2 = mvn:io.fabric8/pax-bohemia/1.0.1
* bundle.3 = mvn:io.fabric8/pax-pomerania/1.0.1/jar
* # for these two, bundle.getLocation() will return matching location
* bundle.4 = mvn:io.fabric8/pax-avaria/1.0.1/jar/uber
* bundle.5 = mvn:io.fabric8/pax-mazovia/1.0.1//uber
* # for these two, bundle.getLocation() will return non-matching location
* bundle.6 = mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber
* bundle.7 = mvn:io.fabric8/pax-castile/1.0.1//uber
*/
LinkedList<BundleUpdate> bundleUpdatesInThisPatch = new LinkedList<>();
bundleUpdatesInThisPatch.add(new BundleUpdate("pax-romana", "1.0.1", "mvn:io.fabric8/pax-romana/1.0.1", "1.0.0", "mvn:io.fabric8/pax-romana/1.0.0"));
bundleUpdatesInThisPatch.add(new BundleUpdate("pax-hellenica", "1.0.1", "mvn:io.fabric8/pax-hellenica/1.0.1/jar", "1.0.0", "mvn:io.fabric8/pax-hellenica/1.0.0/jar"));
bundleUpdatesInThisPatch.add(new BundleUpdate("pax-bohemia", "1.0.1", "mvn:io.fabric8/pax-bohemia/1.0.1", "1.0.0", "mvn:io.fabric8/pax-bohemia/1.0.0/jar"));
bundleUpdatesInThisPatch.add(new BundleUpdate("pax-pomerania", "1.0.1", "mvn:io.fabric8/pax-pomerania/1.0.1/jar", "1.0.0", "mvn:io.fabric8/pax-pomerania/1.0.0"));
bundleUpdatesInThisPatch.add(new BundleUpdate("pax-avaria", "1.0.1", "mvn:io.fabric8/pax-avaria/1.0.1/jar/uber", "1.0.0", "mvn:io.fabric8/pax-avaria/1.0.0/jar/uber"));
bundleUpdatesInThisPatch.add(new BundleUpdate("pax-mazovia", "1.0.1", "mvn:io.fabric8/pax-mazovia/1.0.1//uber", "1.0.0", "mvn:io.fabric8/pax-mazovia/1.0.0//uber"));
bundleUpdatesInThisPatch.add(new BundleUpdate("pax-novgorod", "1.0.1", "mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber", "1.0.0", "mvn:io.fabric8/pax-novgorod/1.0.0//uber"));
bundleUpdatesInThisPatch.add(new BundleUpdate("pax-castile", "1.0.1", "mvn:io.fabric8/pax-castile/1.0.1//uber", "1.0.0", "mvn:io.fabric8/pax-castile/1.0.0/jar/uber"));
management.install(tx, patch, bundleUpdatesInThisPatch);
@SuppressWarnings("unchecked") Map<String, Git> transactions = (Map<String, Git>) getField(management, "pendingTransactions");
assertThat(transactions.size(), equalTo(1));
fork = transactions.values().iterator().next();
ObjectId since = fork.getRepository().resolve("baseline-6.2.0^{commit}");
ObjectId to = fork.getRepository().resolve(tx);
Iterable<RevCommit> commits = fork.log().addRange(since, to).call();
List<String> commitList = Arrays.asList("[PATCH] Installing patch my-patch-8", "artificial change, not treated as user change (could be a patch)", "[PATCH] Apply user changes");
int n = 0;
for (RevCommit c : commits) {
String msg = c.getShortMessage();
assertThat(msg, equalTo(commitList.get(n++)));
}
assertThat(n, equalTo(commitList.size()));
assertThat(fork.tagList().call().size(), equalTo(3));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
assertTrue(repository.containsTag(fork, "patch-my-patch-8"));
Properties startup = new Properties();
try (FileReader reader = new FileReader(new File(fork.getRepository().getWorkTree(), "etc/startup.properties"))) {
startup.load(reader);
assertTrue(startup.containsKey("io/fabric8/pax-romana/1.0.1/pax-romana-1.0.1.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-hellenica/1.0.1/pax-hellenica-1.0.1.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-bohemia/1.0.1/pax-bohemia-1.0.1.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-pomerania/1.0.1/pax-pomerania-1.0.1.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-avaria/1.0.1/pax-avaria-1.0.1-uber.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-mazovia/1.0.1/pax-mazovia-1.0.1-uber.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-novgorod/1.0.1/pax-novgorod-1.0.1-uber.jar"));
assertTrue(startup.containsKey("io/fabric8/pax-castile/1.0.1/pax-castile-1.0.1-uber.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-romana/1.0.0/pax-romana-1.0.0.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-hellenica/1.0.0/pax-hellenica-1.0.0.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-bohemia/1.0.0/pax-bohemia-1.0.0.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-pomerania/1.0.0/pax-pomerania-1.0.0.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-avaria/1.0.0/pax-avaria-1.0.0-uber.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-mazovia/1.0.0/pax-mazovia-1.0.0-uber.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-novgorod/1.0.0/pax-novgorod-1.0.0-uber.jar"));
assertFalse(startup.containsKey("io/fabric8/pax-castile/1.0.0/pax-castile-1.0.0-uber.jar"));
}
}
Aggregations