Search in sources :

Example 6 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class FeaturesServiceMBeanImpl method removeRepository.

public void removeRepository(String uri, boolean uninstall) throws Exception {
    List<URI> uris = new ArrayList<>();
    Pattern pattern = Pattern.compile(uri);
    for (Repository repository : featuresService.listRepositories()) {
        if (repository.getName() != null && !repository.getName().isEmpty()) {
            // first regex on the repository name
            Matcher nameMatcher = pattern.matcher(repository.getName());
            if (nameMatcher.matches()) {
                uris.add(repository.getURI());
            } else {
                // fallback to repository URI regex
                Matcher uriMatcher = pattern.matcher(repository.getURI().toString());
                if (uriMatcher.matches()) {
                    uris.add(repository.getURI());
                }
            }
        } else {
            // repository name is not defined, fallback to repository URI regex
            Matcher uriMatcher = pattern.matcher(repository.getURI().toString());
            if (uriMatcher.matches()) {
                uris.add(repository.getURI());
            }
        }
    }
    for (URI u : uris) {
        featuresService.removeRepository(u, uninstall);
    }
}
Also used : Pattern(java.util.regex.Pattern) Repository(org.apache.karaf.features.Repository) JmxRepository(org.apache.karaf.features.management.codec.JmxRepository) Matcher(java.util.regex.Matcher) URI(java.net.URI)

Example 7 with Repository

use of org.apache.karaf.features.Repository in project karaf by apache.

the class FeaturesServiceMBeanImpl method refreshRepository.

public void refreshRepository(String uri) throws Exception {
    if (uri == null || uri.isEmpty()) {
        for (Repository repository : featuresService.listRepositories()) {
            featuresService.refreshRepository(repository.getURI());
        }
    } else {
        // regex support
        Pattern pattern = Pattern.compile(uri);
        List<URI> uris = new ArrayList<>();
        for (Repository repository : featuresService.listRepositories()) {
            URI u = repository.getURI();
            Matcher matcher = pattern.matcher(u.toString());
            if (matcher.matches()) {
                uris.add(u);
            }
        }
        for (URI u : uris) {
            featuresService.refreshRepository(u);
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) Repository(org.apache.karaf.features.Repository) JmxRepository(org.apache.karaf.features.management.codec.JmxRepository) Matcher(java.util.regex.Matcher) URI(java.net.URI)

Example 8 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled.

/**
     * Test method for
     * {@link ApplicationService#getApplicationStatus(Application)}
     * <p>
     * Verifies method returns an {@link ApplicationState#FAILED } state for an
     * {@code Application} under the following conditions:
     * <p>
     * <ul>
     * <li>Main feature is installed</li>
     * <li>One dependency feature is not installed</li>
     * <li>Dependency feature that is not installed contains Bundle(s) whose
     * states and extended states are inactive</li>
     * </ul>
     *
     * @throws Exception
     */
@Test
public void testGetApplicationStatusReturnsFailedStatusWhenOneFeatureConsistingOfInactiveBundlesIsNotInstalled() throws Exception {
    Set<Repository> mainFeaturesRepoSet = new HashSet<Repository>();
    Set<Feature> notInstalledFeatures = new HashSet<Feature>();
    Set<BundleInfo> inactiveBundles = new HashSet<BundleInfo>();
    for (Feature feature : mainFeatureRepo2.getFeatures()) {
        if (feature.getName().equals(TEST_MAIN_FEATURES_2_MAIN_FEATURE_NAME)) {
            notInstalledFeatures.add(feature);
            inactiveBundles.addAll(feature.getBundles());
            break;
        }
    }
    assertEquals("Feature is not included in repository the expected number of times", 1, notInstalledFeatures.size());
    assertTrue("No bundles included in Feature", inactiveBundles.size() > 0);
    mainFeaturesRepoSet.add(mainFeatureRepo2);
    FeaturesService featuresService = createMockFeaturesService(mainFeaturesRepoSet, notInstalledFeatures, inactiveBundles);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    assertEquals(ApplicationService.class.getName() + " does not contain the expected number of Applications", 1, appService.getApplications().size());
    assertEquals(mainFeatureRepo2.getName() + " returned unexpected state", ApplicationState.FAILED, appService.getApplicationStatus(appService.getApplications().toArray(new Application[] {})[0]).getState());
}
Also used : Repository(org.apache.karaf.features.Repository) BundleInfo(org.apache.karaf.features.BundleInfo) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 9 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testRemoveApplicationUninstallAllFeaturesException.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(Application)} method
     * for the case where an exception is thrown within uninstallAllFeatures(Application)
     *
     * @throws Exception
     */
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testRemoveApplicationUninstallAllFeaturesException() throws Exception {
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    final Appender mockAppender = mock(Appender.class);
    when(mockAppender.getName()).thenReturn("MOCK");
    root.addAppender(mockAppender);
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1, noMainFeatureRepo2));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Application testApp = mock(ApplicationImpl.class);
    Feature testFeature1 = mock(Feature.class);
    Feature testFeature2 = mock(Feature.class);
    Set<Feature> featureSet = new HashSet<>();
    featureSet.add(testFeature1);
    featureSet.add(testFeature2);
    when(featuresService.isInstalled(any(Feature.class))).thenReturn(true);
    when(testApp.getFeatures()).thenReturn(featureSet);
    doThrow(new Exception()).when(featuresService).uninstallFeature(anyString(), anyString(), any(EnumSet.class));
    appService.removeApplication(testApp);
    verify(mockAppender, times(2)).doAppend(argThat(new ArgumentMatcher() {

        @Override
        public boolean matches(final Object argument) {
            return ((LoggingEvent) argument).getFormattedMessage().contains(UNINSTALL_FAIL);
        }
    }));
}
Also used : Appender(ch.qos.logback.core.Appender) EnumSet(java.util.EnumSet) Logger(org.slf4j.Logger) Feature(org.apache.karaf.features.Feature) ApplicationServiceException(org.codice.ddf.admin.application.service.ApplicationServiceException) Repository(org.apache.karaf.features.Repository) ArgumentMatcher(org.mockito.ArgumentMatcher) FeaturesService(org.apache.karaf.features.FeaturesService) Application(org.codice.ddf.admin.application.service.Application) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Example 10 with Repository

use of org.apache.karaf.features.Repository in project ddf by codice.

the class ApplicationServiceImplTest method testRemoveApplicationStringParam.

/**
     * Tests the {@link ApplicationServiceImpl#removeApplication(String)} method
     *
     * @throws Exception
     */
@Test
public void testRemoveApplicationStringParam() throws Exception {
    Set<Repository> activeRepos = new HashSet<Repository>(Arrays.asList(mainFeatureRepo, noMainFeatureRepo1));
    FeaturesService featuresService = createMockFeaturesService(activeRepos, null, null);
    when(bundleContext.getService(mockFeatureRef)).thenReturn(featuresService);
    ApplicationService appService = createPermittedApplicationServiceImpl();
    Feature[] featureList = mainFeatureRepo.getFeatures();
    appService.removeApplication(TEST_APP);
    verify(featuresService).uninstallFeature(featureList[0].getName(), featureList[0].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
    verify(featuresService).uninstallFeature(featureList[1].getName(), featureList[1].getVersion(), EnumSet.of(Option.NoAutoRefreshBundles));
}
Also used : Repository(org.apache.karaf.features.Repository) FeaturesService(org.apache.karaf.features.FeaturesService) Feature(org.apache.karaf.features.Feature) HashSet(java.util.HashSet) ApplicationService(org.codice.ddf.admin.application.service.ApplicationService) Test(org.junit.Test)

Aggregations

Repository (org.apache.karaf.features.Repository)84 Test (org.junit.Test)52 HashSet (java.util.HashSet)51 FeaturesService (org.apache.karaf.features.FeaturesService)44 Feature (org.apache.karaf.features.Feature)38 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)37 URI (java.net.URI)20 Application (org.codice.ddf.admin.application.service.Application)20 LinkedHashSet (java.util.LinkedHashSet)9 ArrayList (java.util.ArrayList)8 ApplicationServiceException (org.codice.ddf.admin.application.service.ApplicationServiceException)8 Logger (org.slf4j.Logger)7 Appender (ch.qos.logback.core.Appender)6 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 ArgumentMatcher (org.mockito.ArgumentMatcher)6 Mockito.anyString (org.mockito.Mockito.anyString)6 EnumSet (java.util.EnumSet)5 Map (java.util.Map)5 TreeMap (java.util.TreeMap)4