use of io.fabric8.kubernetes.model.annotation.Version 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")));
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class ServiceImplTest method testPatch.
@Test
public void testPatch() throws Exception {
ComponentContext componentContext = createMock(ComponentContext.class);
BundleContext bundleContext = createMock(BundleContext.class);
Bundle sysBundle = createMock(Bundle.class);
BundleContext sysBundleContext = createMock(BundleContext.class);
Bundle bundle = createMock(Bundle.class);
Bundle bundle2 = createMock(Bundle.class);
FrameworkWiring wiring = createMock(FrameworkWiring.class);
GitPatchRepository repository = createMock(GitPatchRepository.class);
//
// Create a new service, download a patch
//
expect(componentContext.getBundleContext()).andReturn(bundleContext);
expect(bundleContext.getBundle(0)).andReturn(sysBundle).anyTimes();
expect(sysBundle.getBundleContext()).andReturn(sysBundleContext).anyTimes();
expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
expect(repository.findOrCreateMainGitRepository()).andReturn(null).anyTimes();
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
expect(sysBundleContext.getProperty("karaf.data")).andReturn(karaf.getCanonicalPath() + "/data").anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
PatchManagement pm = mockManagementService(bundleContext);
((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
ServiceImpl service = new ServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
try {
service.download(new URL("file:" + storage + "/temp/f00.zip"));
fail("Should have thrown exception on non existent patch file.");
} catch (Exception e) {
}
Iterable<Patch> patches = service.download(patch132.toURI().toURL());
assertNotNull(patches);
Iterator<Patch> it = patches.iterator();
assertTrue(it.hasNext());
Patch patch = it.next();
assertNotNull(patch);
assertEquals("patch-1.3.2", patch.getPatchData().getId());
assertNotNull(patch.getPatchData().getBundles());
assertEquals(1, patch.getPatchData().getBundles().size());
Iterator<String> itb = patch.getPatchData().getBundles().iterator();
assertEquals("mvn:foo/my-bsn/1.3.2", itb.next());
assertNull(patch.getResult());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle);
//
// Simulate the patch
//
reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle);
expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
expect(sysBundleContext.getServiceReference("io.fabric8.api.FabricService")).andReturn(null).anyTimes();
expect(bundle.getSymbolicName()).andReturn("my-bsn").anyTimes();
expect(bundle.getVersion()).andReturn(new Version("1.3.1")).anyTimes();
expect(bundle.getLocation()).andReturn("location").anyTimes();
expect(bundle.getBundleId()).andReturn(123L).anyTimes();
BundleStartLevel bsl = createMock(BundleStartLevel.class);
expect(bsl.getStartLevel()).andReturn(30).anyTimes();
expect(bundle.adapt(BundleStartLevel.class)).andReturn(bsl).anyTimes();
expect(bundle.getState()).andReturn(1);
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
PatchResult result = service.install(patch, true);
assertNotNull(result);
assertNull(patch.getResult());
assertTrue(result.isSimulation());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
//
// Recreate a new service and verify the downloaded patch is still available
//
reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository, bsl);
expect(componentContext.getBundleContext()).andReturn(bundleContext);
expect(bundleContext.getBundle(0)).andReturn(sysBundle);
expect(sysBundle.getBundleContext()).andReturn(sysBundleContext);
expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.toString()).anyTimes();
expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
expect(repository.findOrCreateMainGitRepository()).andReturn(null).anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository, bsl);
service = new ServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
patches = service.getPatches();
assertNotNull(patches);
it = patches.iterator();
assertTrue(it.hasNext());
patch = it.next();
assertNotNull(patch);
assertEquals("patch-1.3.2", patch.getPatchData().getId());
assertNotNull(patch.getPatchData().getBundles());
assertEquals(1, patch.getPatchData().getBundles().size());
itb = patch.getPatchData().getBundles().iterator();
assertEquals("mvn:foo/my-bsn/1.3.2", itb.next());
assertNull(patch.getResult());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
//
// Install the patch
//
reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bsl);
expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
expect(sysBundleContext.getServiceReference("io.fabric8.api.FabricService")).andReturn(null).anyTimes();
expect(bundle.getSymbolicName()).andReturn("my-bsn").anyTimes();
expect(bundle.getVersion()).andReturn(new Version("1.3.1")).anyTimes();
expect(bundle.getLocation()).andReturn("location").anyTimes();
expect(bundle.getHeaders()).andReturn(new Hashtable<String, String>()).anyTimes();
expect(bundle.getBundleId()).andReturn(123L).anyTimes();
bundle.update(EasyMock.<InputStream>anyObject());
expect(sysBundleContext.getBundles()).andReturn(new Bundle[] { bundle });
expect(bundle.getState()).andReturn(Bundle.INSTALLED).anyTimes();
expect(bundle.getRegisteredServices()).andReturn(null);
expect(bundle.adapt(BundleStartLevel.class)).andReturn(bsl).anyTimes();
expect(bsl.getStartLevel()).andReturn(30).anyTimes();
expect(sysBundleContext.getBundle(0)).andReturn(sysBundle);
expect(sysBundle.adapt(FrameworkWiring.class)).andReturn(wiring);
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
bundle.start();
wiring.refreshBundles(eq(asSet(bundle)), anyObject(FrameworkListener[].class));
expectLastCall().andAnswer(new IAnswer<Object>() {
@Override
public Object answer() throws Throwable {
((FrameworkListener) (EasyMock.getCurrentArguments()[1])).frameworkEvent(null);
return null;
}
});
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, bundle2, wiring, bsl);
result = service.install(patch, false);
assertNotNull(result);
assertSame(result, patch.getResult());
assertFalse(patch.getResult().isSimulation());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, wiring);
//
// Recreate a new service and verify the downloaded patch is still available and installed
//
reset(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
expect(componentContext.getBundleContext()).andReturn(bundleContext);
expect(bundleContext.getBundle(0)).andReturn(sysBundle);
expect(sysBundle.getBundleContext()).andReturn(sysBundleContext);
expect(repository.getManagedPatch(anyString())).andReturn(null).anyTimes();
expect(sysBundleContext.getProperty(Service.NEW_PATCH_LOCATION)).andReturn(storage.toString()).anyTimes();
expect(sysBundleContext.getProperty("karaf.home")).andReturn(karaf.toString()).anyTimes();
expect(sysBundleContext.getProperty("karaf.base")).andReturn(karaf.getCanonicalPath()).anyTimes();
expect(sysBundleContext.getProperty("karaf.name")).andReturn("root").anyTimes();
expect(sysBundleContext.getProperty("karaf.instances")).andReturn(karaf.getCanonicalPath() + "/instances").anyTimes();
expect(sysBundleContext.getProperty("karaf.default.repository")).andReturn("system").anyTimes();
replay(componentContext, sysBundleContext, sysBundle, bundleContext, bundle, repository);
service = new ServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
patches = service.getPatches();
assertNotNull(patches);
it = patches.iterator();
assertTrue(it.hasNext());
patch = it.next();
assertNotNull(patch);
assertEquals("patch-1.3.2", patch.getPatchData().getId());
assertNotNull(patch.getPatchData().getBundles());
assertEquals(1, patch.getPatchData().getBundles().size());
itb = patch.getPatchData().getBundles().iterator();
assertEquals("mvn:foo/my-bsn/1.3.2", itb.next());
assertNotNull(patch.getResult());
verify(componentContext, sysBundleContext, sysBundle, bundleContext, bundle);
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class FabricHTTPGateway method getGatewayVersion.
/**
* Returns the default profile version used to filter out the current versions of services
* if no version expression is used the URI template
*/
String getGatewayVersion() {
assertValid();
Container currentContainer = fabricService.get().getCurrentContainer();
if (currentContainer != null) {
Version version = currentContainer.getVersion();
if (version != null) {
return version.getId();
}
}
return null;
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class MappingConfigurationTest method addService.
protected void addService(String path, String service, String version) {
Map<String, String> params = new HashMap<String, String>();
params.put("version", version);
String container = path.contains("HelloWorld") ? "soapy" : "resty";
params.put("container", container);
ServiceDTO serviceDetails = new ServiceDTO();
serviceDetails.setContainer(container);
serviceDetails.setVersion(version);
config.updateMappingRules(false, path, Arrays.asList(service), params, serviceDetails);
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class GitPatchManagementServiceForStandaloneChildContainersIT method validateInitialGitRepository.
private void validateInitialGitRepository() throws IOException, GitAPIException {
pm = new GitPatchManagementServiceImpl(bundleContext);
pm.start();
pm.ensurePatchManagementInitialized();
GitPatchRepository repository = ((GitPatchManagementServiceImpl) pm).getGitPatchRepository();
verify(bsl, atLeastOnce()).setStartLevel(2);
Git fork = repository.cloneRepository(repository.findOrCreateMainGitRepository(), true);
List<Ref> tags = fork.tagList().call();
boolean found1 = false;
boolean found2 = false;
for (Ref tag : tags) {
if ("refs/tags/baseline-6.2.0".equals(tag.getName())) {
found1 = true;
}
if ("refs/tags/baseline-child-2.4.0.redhat-620133".equals(tag.getName())) {
found2 = true;
}
}
assertTrue("Repository should contain baseline tags for version 6.2.0 (both for root and admin:create based child containrs)", found1 && found2);
repository.closeRepository(fork, true);
}
Aggregations