use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf 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", "UTF-8", true);
// conflicting change, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
FileUtils.write(new File(karafBase, "bin/test"), "echo \"another user change\"\n", "UTF-8");
// 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-4.2.0.redhat-700001^{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 overrides", "[PATCH/baseline] Installing baseline-child-4.2.0.redhat-700002");
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-7.0.0"));
assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700001"));
assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700002"));
}
use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceForStandaloneChildContainersIT method installPPatchAndThenRPatch.
@Test
public void installPPatchAndThenRPatch() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInPatches();
// prepare some ZIP patches
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);
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);
String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
service.install(tx, patch1, null);
service.commitInstallation(tx);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(repository.containsTag(fork, "patch-my-patch-1-child"));
// tag from baseline
assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700001"));
// tag from patch (root and child) - not available yet
assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
assertFalse(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084"));
assertFalse(repository.containsTag(fork, "baseline-child-2.4.0.redhat-621084-child"));
repository.closeRepository(fork, true);
PatchData patchData7 = service.fetchPatches(new File("target/karaf/patches/source/patch-7.zip").toURI().toURL()).get(0);
Patch patch7 = service.trackPatch(patchData7);
tx = service.beginInstallation(PatchKind.ROLLUP);
service.install(tx, patch7, null);
service.commitInstallation(tx);
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertFalse(repository.containsTag(fork, "patch-my-patch-1-child"));
// there's no such tag - we're not in STANDALONE container
assertFalse(repository.containsTag(fork, "baseline-7.0.0.redhat-002"));
assertTrue(repository.containsTag(fork, "baseline-child-4.2.0.redhat-700002"));
repository.closeRepository(fork, true);
}
use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf by jboss-fuse.
the class PatchServiceImplTest method createMockServiceImpl.
/*
* Create a mock patch service implementation with a provided patch storage location
*/
private PatchServiceImpl createMockServiceImpl(File patches) throws IOException {
ComponentContext componentContext = mock(ComponentContext.class);
BundleContext bundleContext = mock(BundleContext.class);
Bundle sysBundle = mock(Bundle.class);
BundleContext sysBundleContext = mock(BundleContext.class);
Bundle bundle = mock(Bundle.class);
GitPatchRepository repository = mock(GitPatchRepository.class);
//
// Create a new service, download a patch
//
when(bundle.getVersion()).thenReturn(new Version(1, 2, 0));
when(componentContext.getBundleContext()).thenReturn(bundleContext);
when(bundleContext.getBundle(0)).thenReturn(sysBundle);
when(bundleContext.getBundle()).thenReturn(bundle);
when(sysBundle.getBundleContext()).thenReturn(sysBundleContext);
when(sysBundleContext.getProperty(PatchService.PATCH_LOCATION)).thenReturn(patches.toString());
when(sysBundleContext.getProperty("karaf.default.repository")).thenReturn("system");
when(sysBundleContext.getProperty("karaf.data")).thenReturn(patches.getParent() + "/data");
when(sysBundleContext.getProperty("karaf.etc")).thenReturn(karaf.getCanonicalPath() + "/etc");
try {
when(repository.getManagedPatch(anyString())).thenReturn(null);
when(repository.findOrCreateMainGitRepository()).thenReturn(null);
when(sysBundleContext.getProperty("karaf.home")).thenReturn(karaf.getCanonicalPath());
when(sysBundleContext.getProperty("karaf.base")).thenReturn(karaf.getCanonicalPath());
when(sysBundleContext.getProperty("karaf.name")).thenReturn("root");
when(sysBundleContext.getProperty("karaf.instances")).thenReturn(karaf.getCanonicalPath() + "/instances");
} catch (GitAPIException | IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
PatchManagement pm = new GitPatchManagementServiceImpl(bundleContext);
((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
PatchServiceImpl service = new PatchServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
return service;
}
use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf by jboss-fuse.
the class GitPatchManagementServiceIT method installThreeNonRollupPatchesWithExternalizedVersionsProperties.
@Test
public void installThreeNonRollupPatchesWithExternalizedVersionsProperties() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInSystem();
try (FileOutputStream fos = new FileOutputStream(new File(karafHome, "etc/org.apache.karaf.features.xml"))) {
FileUtils.copyFile(new File("src/test/resources/processing/oakf.2.xml"), fos);
}
FileUtils.write(new File(karafHome, "etc/versions.properties"), "version.zen = 1.1.9\n", "UTF-8");
// prepare some ZIP patches
preparePatchZip("src/test/resources/content/patch1", "target/karaf/patches/source/patch-1.zip", false);
preparePatchZip("src/test/resources/content/patch5", "target/karaf/patches/source/patch-5.zip", false);
preparePatchZip("src/test/resources/content/patch6", "target/karaf/patches/source/patch-6.zip", false);
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 patchData5 = service.fetchPatches(new File("target/karaf/patches/source/patch-5.zip").toURI().toURL()).get(0);
Patch patch5 = service.trackPatch(patchData5);
PatchData patchData6 = service.fetchPatches(new File("target/karaf/patches/source/patch-6.zip").toURI().toURL()).get(0);
Patch patch6 = service.trackPatch(patchData6);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(FileUtils.readFileToString(new File(karafHome, "etc/versions.properties"), "UTF-8").contains("version.zen = 1.1.9"));
String tx = service.beginInstallation(PatchKind.NON_ROLLUP);
List<BundleUpdate> patch1Updates = new LinkedList<>();
patch1Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-tranquility/1.2.0").to("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
service.install(tx, patch1, patch1Updates);
List<BundleUpdate> patch5Updates = new LinkedList<>();
patch5Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.1.44/war").to("mvn:org.jboss.fuse/fuse-zen/1.2.0/war"));
service.install(tx, patch5, patch5Updates);
List<BundleUpdate> patch6Updates = new LinkedList<>();
patch6Updates.add(BundleUpdate.from("mvn:org.jboss.fuse/fuse-zen/1.2.4/war").to("mvn:org.jboss.fuse/fuse-zen/1.3.0/war"));
service.install(tx, patch6, patch6Updates);
service.commitInstallation(tx);
String binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
String etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
// version from patch-5 should be chosen, because there's 1.1.44->1.2.0
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
assertFalse(new File(karafHome, "etc/overrides.properties").exists());
FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(3));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/${version.zen}/war".equals(b.getReplacement())));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
assertTrue(FileUtils.readFileToString(new File(karafHome, "etc/versions.properties"), "UTF-8").contains("version.zen = 1.2.0"));
/* rollback time! */
Patch p5 = service.loadPatch(new PatchDetailsRequest("my-patch-5"));
service.rollback(p5.getPatchData());
binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
// rollback wasn't successful
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
assertFalse(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.1.44/war = 42"));
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(3));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-tranquility/[1.2.0,1.3.0)".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-tranquility/1.2.3".equals(b.getReplacement())));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.2)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/${version.zen}/war".equals(b.getReplacement())));
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
assertTrue(FileUtils.readFileToString(new File(karafHome, "etc/versions.properties"), "UTF-8").contains("version.zen = 1.2.0"));
Patch p6 = service.loadPatch(new PatchDetailsRequest("my-patch-6"));
service.rollback(p6.getPatchData());
binAdmin = FileUtils.readFileToString(new File(karafHome, "bin/instance"), "UTF-8");
assertTrue(binAdmin.contains("system/org/jboss/fuse/fuse-tranquility/1.2.3/fuse-tranquility-1.2.3.jar"));
etcStartupProperties = FileUtils.readFileToString(new File(karafHome, "etc/startup.properties"), "UTF-8");
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-zen/1.2.0/war = 42"));
assertTrue(etcStartupProperties.contains("mvn\\:org.jboss.fuse/fuse-tranquility/1.2.3 = 42"));
fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(2));
assertTrue(bundles.stream().noneMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.3.0,1.4.0)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/1.3.3/war".equals(b.getReplacement())));
// after rolling back patch 6 we can rollback patch 5
p5 = service.loadPatch(new PatchDetailsRequest("my-patch-5"));
service.rollback(p5.getPatchData());
fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
bundles = fp.getBundleReplacements().getOverrideBundles();
assertTrue(bundles.stream().anyMatch(b -> "mvn:org.jboss.fuse/fuse-zen/[1.1,1.1.9)/war".equals(b.getOriginalUri()) && "mvn:org.jboss.fuse/fuse-zen/${version.zen}/war".equals(b.getReplacement())));
assertTrue(FileUtils.readFileToString(new File(karafHome, "etc/versions.properties"), "UTF-8").contains("version.zen = 1.1.9"));
repository.closeRepository(fork, true);
}
use of org.jboss.fuse.patch.management.impl.GitPatchRepository in project fuse-karaf 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:org.jboss.fuse/fuse-oceans/1.4.2\n", "UTF-8");
// 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"), "UTF-8");
assertThat(etcOverridesProperties, equalTo("mvn:org.jboss.fuse/fuse-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 no changes to 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"), "UTF-8");
assertThat(etcOverridesProperties, equalTo("mvn:org.jboss.fuse/fuse-oceans/1.4.2\n"));
// override from P-Patch should go to etc/org.apache.karaf.features.xml
FeaturesProcessing fp = InternalUtils.loadFeatureProcessing(new File(karafHome, "etc/org.apache.karaf.features.xml"), null);
List<BundleReplacements.OverrideBundle> bundles = fp.getBundleReplacements().getOverrideBundles();
assertThat(bundles.size(), equalTo(1));
assertThat(bundles.get(0).getReplacement(), equalTo("mvn:org.jboss.fuse/fuse-tranquility/1.2.3"));
fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
assertFalse(repository.containsTag(fork, "baseline-7.0.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-7.0.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);
}
Aggregations