use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class ServiceImplTest method bundleUpdatesInPatch.
@Test
public void bundleUpdatesInPatch() throws Exception {
BundleContext context = EasyMock.createMock(BundleContext.class);
Bundle bundle0 = createMock(Bundle.class);
expect(bundle0.getBundleContext()).andReturn(context);
replay(bundle0);
expect(context.getProperty("karaf.home")).andReturn("target/bundleUpdatesInPatch").anyTimes();
expect(context.getProperty("karaf.base")).andReturn("target/bundleUpdatesInPatch").anyTimes();
expect(context.getProperty("karaf.data")).andReturn("target/bundleUpdatesInPatch/data").anyTimes();
expect(context.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(context.getProperty("karaf.instances")).andReturn("instances").anyTimes();
expect(context.getProperty("karaf.default.repository")).andReturn("system");
expect(context.getProperty("fuse.patch.location")).andReturn(null);
expect(context.getBundle(0)).andReturn(bundle0);
replay(context);
ServiceImpl service = new ServiceImpl();
Method m = service.getClass().getDeclaredMethod("bundleUpdatesInPatch", Patch.class, Bundle[].class, Map.class, ServiceImpl.BundleVersionHistory.class, Map.class, PatchKind.class, Map.class, List.class);
m.setAccessible(true);
Field f = service.getClass().getDeclaredField("helper");
f.setAccessible(true);
f.set(service, new OSGiPatchHelper(new File("target/bundleUpdatesInPatch"), context) {
@Override
public String[] getBundleIdentity(String url) throws IOException {
Artifact a = Utils.mvnurlToArtifact(url, false);
return new String[] { a.getArtifactId(), a.getVersion() };
}
});
PatchData pd = new PatchData("patch-x");
// for these two, bundle.getLocation() will return matching location
pd.getBundles().add("mvn:io.fabric8/pax-romana/1.0.1");
pd.getBundles().add("mvn:io.fabric8/pax-hellenica/1.0.1/jar");
// for these two, bundle.getLocation() will return non-matching location
pd.getBundles().add("mvn:io.fabric8/pax-bohemia/1.0.1");
pd.getBundles().add("mvn:io.fabric8/pax-pomerania/1.0.1/jar");
// for these two, bundle.getLocation() will return matching location
pd.getBundles().add("mvn:io.fabric8/pax-avaria/1.0.1/jar/uber");
pd.getBundles().add("mvn:io.fabric8/pax-mazovia/1.0.1//uber");
// for these two, bundle.getLocation() will return non-matching location
pd.getBundles().add("mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber");
pd.getBundles().add("mvn:io.fabric8/pax-castile/1.0.1//uber");
f = pd.getClass().getDeclaredField("versionRanges");
f.setAccessible(true);
f.set(pd, new HashMap<>());
Patch patch = new Patch(pd, null);
Bundle[] bundles = new Bundle[8];
bundles[0] = bundle("mvn:io.fabric8/pax-romana/1.0.0");
bundles[1] = bundle("mvn:io.fabric8/pax-hellenica/1.0.0/jar");
bundles[2] = bundle("mvn:io.fabric8/pax-bohemia/1.0.0/jar");
bundles[3] = bundle("mvn:io.fabric8/pax-pomerania/1.0.0");
bundles[4] = bundle("mvn:io.fabric8/pax-avaria/1.0.0/jar/uber");
bundles[5] = bundle("mvn:io.fabric8/pax-mazovia/1.0.0//uber");
bundles[6] = bundle("mvn:io.fabric8/pax-novgorod/1.0.0//uber");
bundles[7] = bundle("mvn:io.fabric8/pax-castile/1.0.0/jar/uber");
Object _list = m.invoke(service, patch, bundles, new HashMap<>(), new ServiceImpl.BundleVersionHistory(new HashMap<String, Patch>()), new HashMap<>(), PatchKind.NON_ROLLUP, new HashMap<>(), null);
List<BundleUpdate> list = (List<BundleUpdate>) _list;
assertThat(list.size(), equalTo(8));
assertThat(list.get(0).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-romana/1.0.0"));
assertThat(list.get(1).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-hellenica/1.0.0/jar"));
assertThat(list.get(2).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-bohemia/1.0.0/jar"));
assertThat(list.get(3).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-pomerania/1.0.0"));
assertThat(list.get(4).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-avaria/1.0.0/jar/uber"));
assertThat(list.get(5).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-mazovia/1.0.0//uber"));
assertThat(list.get(6).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-novgorod/1.0.0//uber"));
assertThat(list.get(7).getPreviousLocation(), equalTo("mvn:io.fabric8/pax-castile/1.0.0/jar/uber"));
assertThat(list.get(0).getNewLocation(), equalTo("mvn:io.fabric8/pax-romana/1.0.1"));
assertThat(list.get(1).getNewLocation(), equalTo("mvn:io.fabric8/pax-hellenica/1.0.1/jar"));
assertThat(list.get(2).getNewLocation(), equalTo("mvn:io.fabric8/pax-bohemia/1.0.1"));
assertThat(list.get(3).getNewLocation(), equalTo("mvn:io.fabric8/pax-pomerania/1.0.1/jar"));
assertThat(list.get(4).getNewLocation(), equalTo("mvn:io.fabric8/pax-avaria/1.0.1/jar/uber"));
assertThat(list.get(5).getNewLocation(), equalTo("mvn:io.fabric8/pax-mazovia/1.0.1//uber"));
assertThat(list.get(6).getNewLocation(), equalTo("mvn:io.fabric8/pax-novgorod/1.0.1/jar/uber"));
assertThat(list.get(7).getNewLocation(), equalTo("mvn:io.fabric8/pax-castile/1.0.1//uber"));
// ---
Repository repository = createMock(Repository.class);
File tmp = new File("target/bundleUpdatesInPatch/" + UUID.randomUUID().toString());
tmp.mkdirs();
File startupProperties = new File(tmp, "etc/startup.properties");
FileUtils.copyFile(new File("src/test/resources/uber-startup.properties"), startupProperties);
expect(repository.getWorkTree()).andReturn(tmp).anyTimes();
replay(repository);
Git fork = createMock(Git.class);
expect(fork.getRepository()).andReturn(repository).anyTimes();
replay(fork);
GitPatchManagementServiceImpl gitPatchManagementService = new GitPatchManagementServiceImpl(context);
m = gitPatchManagementService.getClass().getDeclaredMethod("updateFileReferences", Git.class, PatchData.class, List.class);
m.setAccessible(true);
m.invoke(gitPatchManagementService, fork, pd, list);
try (FileReader reader = new FileReader(startupProperties)) {
Properties startup = new 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"));
}
}
use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceForStandaloneChildContainersIT method installNonRollupPatch.
@Test
public void installNonRollupPatch() throws IOException, GitAPIException {
initializationPerformedBaselineDistributionFoundInPatches();
freshKarafStandaloneDistro();
PatchManagement management = (PatchManagement) pm;
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
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);
FileUtils.write(new File(karafBase, "bin/shutdown"), "#!/bin/bash\nexit 42");
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.closeRepository(fork, true);
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));
String tx = management.beginInstallation(PatchKind.NON_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();
List<String> commitList = Arrays.asList("[PATCH] Installing patch my-patch-1", "[PATCH] Apply user changes", "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(4));
assertTrue(repository.containsTag(fork, "patch-management"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0"));
assertTrue(repository.containsTag(fork, "baseline-child-2.4.0.redhat-620133"));
assertFalse(repository.containsTag(fork, "patch-my-patch-1"));
assertTrue(repository.containsTag(fork, "patch-my-patch-1-child"));
assertThat("The conflict should be resolved in special way", FileUtils.readFileToString(new File(karafHome, "bin/setenv")), equalTo("JAVA_MIN_MEM=2G # Minimum memory for the JVM\n"));
}
use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method rollbackRollupPatchInstallation.
@Test
public void rollbackRollupPatchInstallation() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
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-4.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.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 installPPatchHotFixPPatchAndThenRPatch.
/**
* Installation of R patch <strong>may</strong> leave P patches installed when they provide <strong>only</strong>
* bundles and the bundles are at higher version
* @throws IOException
* @throws GitAPIException
*/
@Test
public void installPPatchHotFixPPatchAndThenRPatch() 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/patch2", "target/karaf/patches/source/patch-2.zip", false);
preparePatchZip("src/test/resources/content/patch4", "target/karaf/patches/source/patch-4.zip", false);
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
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 patchData2 = service.fetchPatches(new File("target/karaf/patches/source/patch-2.zip").toURI().toURL()).get(0);
Patch patch2 = service.trackPatch(patchData2);
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);
tx = service.beginInstallation(PatchKind.NON_ROLLUP);
service.install(tx, patch2, null);
service.commitInstallation(tx);
assertTrue("There should be etc/overrides.properties after installing non-rollup patches", new File(karafHome, "etc/overrides.properties").exists());
// overrides.properties as after installing P patches with new mechanism
String etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
assertThat(etcOverridesProperties, equalTo("mvn:io.fabric8/fabric-tranquility/1.2.5\n"));
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
assertTrue(repository.containsTag(fork, "patch-my-patch-1"));
assertTrue(repository.containsTag(fork, "patch-my-patch-2"));
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"));
assertFalse(repository.containsTag(fork, "patch-my-patch-2"));
assertTrue(repository.containsTag(fork, "baseline-6.2.0.redhat-002"));
assertTrue("There still should be etc/overrides.properties after installing rollup patch", new File(karafHome, "etc/overrides.properties").exists());
// overrides.properties as after installing R patch with new mechanism
etcOverridesProperties = FileUtils.readFileToString(new File(karafHome, "etc/overrides.properties"));
assertThat(etcOverridesProperties, equalTo("mvn:io.fabric8/fabric-tranquility/1.2.5\n"));
repository.closeRepository(fork, true);
}
use of io.fabric8.patch.management.PatchData in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceIT method installRollupPatch.
@Test
public void installRollupPatch() throws IOException, GitAPIException {
freshKarafStandaloneDistro();
GitPatchRepository repository = patchManagement();
PatchManagement management = (PatchManagement) pm;
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(karafHome, "bin/start"), "echo \"another user change\"\n", true);
// conflicting change, but commit
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
FileUtils.write(new File(karafHome, "bin/test"), "echo \"another user change\"\n");
// non-conflicting
((GitPatchManagementServiceImpl) pm).applyUserChanges(fork);
repository.closeRepository(fork, true);
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-4.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-6.2.0^{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-4 - resetting etc/overrides.properties", "[PATCH] Installing rollup patch patch-4");
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, "baseline-6.2.0.redhat-002"));
}
Aggregations