use of org.osgi.framework.wiring.FrameworkWiring in project opennms by OpenNMS.
the class Activator method start.
@Override
public void start(BundleContext context) throws Exception {
// Determine if any vaadin theme fragments are unresoled
final Set<Bundle> unresolvedVaadinThemeFragments = getUnresolvedVaadinThemeFragments(context);
if (!unresolvedVaadinThemeFragments.isEmpty()) {
// Get vaadin theme host bundle to initialize refresh
final Bundle vaadinThemeHostBundle = getVaadinThemeHostbundle(context);
final List<Bundle> bundlesToRefresh = new ArrayList<>();
bundlesToRefresh.add(vaadinThemeHostBundle);
// Refresh
final Bundle systemBundle = context.getBundle(0);
FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
frameworkWiring.refreshBundles(bundlesToRefresh);
}
}
use of org.osgi.framework.wiring.FrameworkWiring in project fabric8 by jboss-fuse.
the class ServiceImpl method applyChanges.
private void applyChanges(Map<Bundle, String> toUpdate) throws BundleException, IOException {
List<Bundle> toStop = new ArrayList<Bundle>();
Map<Bundle, String> lessToUpdate = new HashMap<>();
for (Bundle b : toUpdate.keySet()) {
if (b.getState() != Bundle.UNINSTALLED) {
toStop.add(b);
lessToUpdate.put(b, toUpdate.get(b));
}
}
while (!toStop.isEmpty()) {
List<Bundle> bs = getBundlesToDestroy(toStop);
for (Bundle bundle : bs) {
String hostHeader = bundle.getHeaders().get(Constants.FRAGMENT_HOST);
if (hostHeader == null && (bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STARTING)) {
if (!"org.ops4j.pax.url.mvn".equals(bundle.getSymbolicName())) {
bundle.stop();
}
}
toStop.remove(bundle);
}
}
// eagerly load some classes
try {
getClass().getClassLoader().loadClass(Parser.class.getName());
getClass().getClassLoader().loadClass(Clause.class.getName());
getClass().getClassLoader().loadClass(Attribute.class.getName());
getClass().getClassLoader().loadClass(Directive.class.getName());
getClass().getClassLoader().loadClass(RefreshListener.class.getName());
} catch (Exception ignored) {
}
Set<Bundle> toRefresh = new HashSet<Bundle>();
Set<Bundle> toStart = new HashSet<Bundle>();
for (Map.Entry<Bundle, String> e : lessToUpdate.entrySet()) {
Bundle bundle = e.getKey();
if (!"org.ops4j.pax.url.mvn".equals(bundle.getSymbolicName())) {
System.out.println("updating: " + bundle.getSymbolicName());
try {
BundleUtils.update(bundle, new URL(e.getValue()));
} catch (BundleException ex) {
System.err.println("Failed to update: " + bundle.getSymbolicName() + ", due to: " + e);
}
toStart.add(bundle);
toRefresh.add(bundle);
}
}
findBundlesWithOptionalPackagesToRefresh(toRefresh);
findBundlesWithFragmentsToRefresh(toRefresh);
if (!toRefresh.isEmpty()) {
final CountDownLatch l = new CountDownLatch(1);
FrameworkListener listener = new RefreshListener(l);
FrameworkWiring wiring = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
wiring.refreshBundles(toRefresh, listener);
try {
l.await();
} catch (InterruptedException e) {
throw new PatchException("Bundle refresh interrupted", e);
}
}
for (Bundle bundle : toStart) {
String hostHeader = bundle.getHeaders().get(Constants.FRAGMENT_HOST);
if (hostHeader == null) {
try {
bundle.start();
} catch (BundleException e) {
System.err.println("Failed to start: " + bundle.getSymbolicName() + ", due to: " + e);
}
}
}
}
use of org.osgi.framework.wiring.FrameworkWiring in project fabric8 by jboss-fuse.
the class ServiceImplTest method testPatchWithVersionRanges.
@Test
public void testPatchWithVersionRanges() 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);
Iterable<Patch> patches = service.download(patch140.toURI().toURL());
assertNotNull(patches);
Iterator<Patch> it = patches.iterator();
assertTrue(it.hasNext());
Patch patch = it.next();
assertNotNull(patch);
assertEquals("patch-1.4.0", 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.4.0", 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);
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);
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());
assertEquals(1, result.getBundleUpdates().size());
assertTrue(result.isSimulation());
}
use of org.osgi.framework.wiring.FrameworkWiring in project fabric8 by jboss-fuse.
the class ServiceImplTest method testLoadWithoutRanges.
@Test
public void testLoadWithoutRanges() throws IOException, GitAPIException {
BundleContext bundleContext = createMock(BundleContext.class);
ComponentContext componentContext = createMock(ComponentContext.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 = new GitPatchManagementServiceImpl(bundleContext);
((GitPatchManagementServiceImpl) pm).setGitPatchRepository(repository);
ServiceImpl service = new ServiceImpl();
setField(service, "patchManagement", pm);
service.activate(componentContext);
PatchData pd = PatchData.load(getClass().getClassLoader().getResourceAsStream("test1.patch"));
assertEquals(2, pd.getBundles().size());
assertTrue(pd.getRequirements().isEmpty());
}
use of org.osgi.framework.wiring.FrameworkWiring in project motech by motech.
the class MdsBundleWatcher method refreshBundles.
private void refreshBundles(List<Bundle> bundles, SchemaHolder schemaHolder) {
if (LOGGER.isInfoEnabled()) {
for (Bundle bundle : bundles) {
LOGGER.info("Refreshing wiring for bundle {}", bundle.getSymbolicName());
}
}
// we generate the entities bundle but not start it to avoid exceptions when the framework
// will refresh bundles
jarGeneratorService.regenerateMdsDataBundle(schemaHolder, false);
FrameworkWiring framework = bundleContext.getBundle(0).adapt(FrameworkWiring.class);
framework.refreshBundles(bundles);
// give the framework 3 seconds to do a refresh
ThreadSuspender.sleep(3000);
// after refreshing all bundles we can start the entities bundle
monitor.start();
}
Aggregations