Search in sources :

Example 31 with GitPatchManagementServiceImpl

use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl 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());
}
Also used : GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) PatchData(io.fabric8.patch.management.PatchData) ComponentContext(org.osgi.service.component.ComponentContext) Bundle(org.osgi.framework.Bundle) PatchManagement(io.fabric8.patch.management.PatchManagement) GitPatchManagementServiceImpl(io.fabric8.patch.management.impl.GitPatchManagementServiceImpl) GitPatchRepository(io.fabric8.patch.management.impl.GitPatchRepository) FrameworkWiring(org.osgi.framework.wiring.FrameworkWiring) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 32 with GitPatchManagementServiceImpl

use of io.fabric8.patch.management.impl.GitPatchManagementServiceImpl in project fabric8 by jboss-fuse.

the class Activator method start.

@Override
@SuppressWarnings("unchecked")
public void start(final BundleContext context) throws Exception {
    bundle = context.getBundle();
    systemContext = context.getBundle(0).getBundleContext();
    logServiceTracker = new ServiceTracker(context, "org.osgi.service.log.LogService", null);
    logServiceTracker.open();
    patchManagementService = new GitPatchManagementServiceImpl(context);
    final int targetStartLevel = Integer.parseInt(System.getProperty("org.osgi.framework.startlevel.beginning"));
    sl = context.getBundle(0).adapt(FrameworkStartLevel.class);
    activatedAt = sl.getStartLevel();
    if (!patchManagementService.isEnabled()) {
        log(LogService.LOG_INFO, "\nPatch management is disabled");
        return;
    }
    switch(activatedAt) {
        case PATCH_MANAGEMENT_START_LEVEL:
            // this bundle is configured in etc/startup.properties, we can handle registered tasks
            // like updating critical bundles
            startupVersion = context.getBundle().getVersion();
            // we're started before fileinstall, so we can remove this bundle if it is available in deploy/
            patchManagementService.cleanupDeployDir();
            break;
        default:
            // this bundle was activated from deploy/ directory or osgi:install. But this doesn't mean there's no
            // patch-management bundle configured in etc/startup.properties
            // the point is that when etc/startup.properties already has this bundle, there should be no such bundle in deploy/
            // TODO (there may be newer version however)
            deployVersion = context.getBundle().getVersion();
            break;
    }
    patchManagementService.start();
    patchManagementRegistration = systemContext.registerService(PatchManagement.class, PatchManagement.class.cast(patchManagementService), null);
    backupServiceRegistration = systemContext.registerService(BackupService.class, new FileBackupService(systemContext), null);
    if (startupVersion != null) {
        // we should be at start level 2. let's check if there are any rollup paatches being installed or
        // rolled back - we've got some work to do at this early stage of Karaf
        patchManagementService.checkPendingPatches();
    }
    if (sl.getStartLevel() == targetStartLevel) {
        // dropped to deploy/ when framework was already at target start-level
        patchManagementService.ensurePatchManagementInitialized();
    } else {
        // let's wait for last start level
        startLevelNotificationFrameworkListener = new StartLevelNotificationFrameworkListener(targetStartLevel);
        systemContext.addFrameworkListener(startLevelNotificationFrameworkListener);
    }
}
Also used : BackupService(io.fabric8.patch.management.BackupService) ServiceTracker(org.osgi.util.tracker.ServiceTracker) PatchManagement(io.fabric8.patch.management.PatchManagement) FrameworkStartLevel(org.osgi.framework.startlevel.FrameworkStartLevel)

Aggregations

GitPatchManagementServiceImpl (io.fabric8.patch.management.impl.GitPatchManagementServiceImpl)27 Test (org.junit.Test)25 GitPatchRepository (io.fabric8.patch.management.impl.GitPatchRepository)20 File (java.io.File)20 Git (org.eclipse.jgit.api.Git)16 LinkedList (java.util.LinkedList)7 ObjectId (org.eclipse.jgit.lib.ObjectId)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)7 BundleUpdate (io.fabric8.patch.management.BundleUpdate)5 PatchManagement (io.fabric8.patch.management.PatchManagement)5 Map (java.util.Map)5 Bundle (org.osgi.framework.Bundle)5 BundleContext (org.osgi.framework.BundleContext)5 Ref (org.eclipse.jgit.lib.Ref)4 ComponentContext (org.osgi.service.component.ComponentContext)4 Patch (io.fabric8.patch.management.Patch)3 IOException (java.io.IOException)3 Version (org.osgi.framework.Version)3 BundleStartLevel (org.osgi.framework.startlevel.BundleStartLevel)3 FrameworkWiring (org.osgi.framework.wiring.FrameworkWiring)3