Search in sources :

Example 6 with BundleInformation

use of org.motechproject.admin.bundles.BundleInformation in project motech by motech.

the class ModuleAdminServiceImpl method installWithDependenciesFromFile.

private BundleInformation installWithDependenciesFromFile(File bundleFile, boolean startBundle) throws IOException {
    JarInformation jarInformation = getJarInformations(bundleFile);
    List<Bundle> bundlesInstalled = new ArrayList<>();
    BundleInformation bundleInformation = null;
    if (jarInformation == null) {
        throw new IOException("Unable to read bundleFile " + bundleFile.getAbsolutePath());
    }
    try {
        List<ArtifactResult> artifactResults = new LinkedList<>();
        bundleWatcherSuspensionService.suspendBundleProcessing();
        for (Dependency dependency : jarInformation.getPomInformation().getDependencies()) {
            artifactResults.addAll(resolveDependencies(dependency, jarInformation.getPomInformation()));
        }
        artifactResults = removeDuplicatedArtifacts(artifactResults);
        bundlesInstalled = installBundlesFromArtifacts(artifactResults);
        final Bundle requestedModule = installBundleFromFile(bundleFile, true, false);
        if (requestedModule != null) {
            if (!isFragmentBundle(requestedModule) && startBundle) {
                requestedModule.start();
            }
            bundlesInstalled.add(requestedModule);
            bundleInformation = null;
        } else {
            bundleInformation = new BundleInformation(null);
        }
    } catch (BundleException | RepositoryException e) {
        throw new MotechException("Error while installing bundle and dependencies.", e);
    } finally {
        bundleWatcherSuspensionService.restoreBundleProcessing();
    }
    // start bundles after all bundles installed to avoid any dependency resolution problems.
    startBundles(bundlesInstalled, startBundle);
    return bundleInformation;
}
Also used : Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) RepositoryException(org.sonatype.aether.RepositoryException) IOException(java.io.IOException) Dependency(org.sonatype.aether.graph.Dependency) JarInformation(org.motechproject.admin.bundles.JarInformation) LinkedList(java.util.LinkedList) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult) MotechException(org.motechproject.commons.api.MotechException) BundleInformation(org.motechproject.admin.bundles.BundleInformation) ExtendedBundleInformation(org.motechproject.admin.bundles.ExtendedBundleInformation) BundleException(org.osgi.framework.BundleException)

Example 7 with BundleInformation

use of org.motechproject.admin.bundles.BundleInformation in project motech by motech.

the class ModuleAdminServiceImpl method installFromRepository.

private BundleInformation installFromRepository(Dependency dependency, boolean start) throws RepositoryException, IOException, BundleException {
    LOGGER.info("Installing {} from repository", dependency);
    final String featureStrNoVersion = buildFeatureStrNoVersion(dependency);
    List<Bundle> bundlesInstalled = new ArrayList<>();
    BundleInformation bundleInformation = null;
    try {
        bundleWatcherSuspensionService.suspendBundleProcessing();
        List<ArtifactResult> dependencies = resolveDependencies(dependency, null);
        LOGGER.trace("Resolved the following dependencies for {}: {}", dependency, dependencies);
        for (ArtifactResult artifact : dependencies) {
            if (isOSGiFramework(artifact)) {
                // skip the framework jar
                continue;
            }
            LOGGER.info("Installing " + artifact);
            final File bundleFile = artifact.getArtifact().getFile();
            boolean isRequestedModule = isRequestedModule(artifact, featureStrNoVersion);
            final Bundle bundle = installBundleFromFile(bundleFile, isRequestedModule, true);
            if (bundle != null) {
                bundlesInstalled.add(bundle);
                if (isRequestedModule) {
                    bundleInformation = new BundleInformation(bundle);
                }
            }
        }
    } finally {
        bundleWatcherSuspensionService.restoreBundleProcessing();
    }
    // start bundles after all bundles installed to avoid any dependency resolution problems.
    startBundles(bundlesInstalled, start);
    return bundleInformation;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleInformation(org.motechproject.admin.bundles.BundleInformation) ExtendedBundleInformation(org.motechproject.admin.bundles.ExtendedBundleInformation) ArrayList(java.util.ArrayList) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) ArtifactResult(org.sonatype.aether.resolution.ArtifactResult)

Example 8 with BundleInformation

use of org.motechproject.admin.bundles.BundleInformation in project motech by motech.

the class ModuleAdminServiceImpl method getBundles.

@Override
public List<BundleInformation> getBundles() {
    List<BundleInformation> bundles = new ArrayList<>();
    List<Bundle> motechBundles = motechBundleFilter.filter(bundleContext.getBundles());
    for (Bundle bundle : motechBundles) {
        BundleInformation bundleInformation = new BundleInformation(bundle);
        ModuleRegistrationData moduleRegistrationData = uiFrameworkService.getModuleDataByBundle(bundle);
        if (moduleRegistrationData != null) {
            bundleInformation.setSettingsURL(moduleRegistrationData.getSettingsURL());
            bundleInformation.setModuleName(moduleRegistrationData.getModuleName());
            List<String> angularModules = moduleRegistrationData.getAngularModules();
            String angularModuleName = isEmpty(angularModules) ? moduleRegistrationData.getModuleName() : angularModules.get(0);
            bundleInformation.setAngularModule(angularModuleName);
        }
        bundles.add(bundleInformation);
    }
    return bundles;
}
Also used : Bundle(org.osgi.framework.Bundle) BundleInformation(org.motechproject.admin.bundles.BundleInformation) ExtendedBundleInformation(org.motechproject.admin.bundles.ExtendedBundleInformation) ArrayList(java.util.ArrayList) ModuleRegistrationData(org.motechproject.osgi.web.ModuleRegistrationData)

Example 9 with BundleInformation

use of org.motechproject.admin.bundles.BundleInformation in project motech by motech.

the class ModuleAdminServiceImpl method stopBundle.

@Override
public BundleInformation stopBundle(long bundleId) throws BundleException {
    Bundle bundle = getBundle(bundleId);
    bundle.stop();
    return new BundleInformation(bundle);
}
Also used : Bundle(org.osgi.framework.Bundle) BundleInformation(org.motechproject.admin.bundles.BundleInformation) ExtendedBundleInformation(org.motechproject.admin.bundles.ExtendedBundleInformation)

Example 10 with BundleInformation

use of org.motechproject.admin.bundles.BundleInformation in project motech by motech.

the class BundleAdminServiceTest method testGetBundleInfo.

@Test
public void testGetBundleInfo() {
    setupBundleRetrieval();
    BundleInformation bundleInfo = moduleAdminService.getBundleInfo(BUNDLE_ID);
    assertEquals(new BundleInformation(bundle), bundleInfo);
    verify(bundleContext).getBundle(BUNDLE_ID);
}
Also used : BundleInformation(org.motechproject.admin.bundles.BundleInformation) ExtendedBundleInformation(org.motechproject.admin.bundles.ExtendedBundleInformation) Test(org.junit.Test)

Aggregations

BundleInformation (org.motechproject.admin.bundles.BundleInformation)15 ExtendedBundleInformation (org.motechproject.admin.bundles.ExtendedBundleInformation)10 Test (org.junit.Test)9 Bundle (org.osgi.framework.Bundle)6 ArrayList (java.util.ArrayList)3 ArtifactResult (org.sonatype.aether.resolution.ArtifactResult)2 File (java.io.File)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 JarInformation (org.motechproject.admin.bundles.JarInformation)1 MotechException (org.motechproject.commons.api.MotechException)1 ModuleRegistrationData (org.motechproject.osgi.web.ModuleRegistrationData)1 BundleException (org.osgi.framework.BundleException)1 RepositoryException (org.sonatype.aether.RepositoryException)1 Dependency (org.sonatype.aether.graph.Dependency)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1