Search in sources :

Example 1 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class RegistryStoreCleanupHandler method handleEvent.

@Override
public void handleEvent(Event event) {
    Object eventProperty = event.getProperty(EventConstants.EVENT);
    if (!cleanupRelatedMetacards || eventProperty == null || !(eventProperty instanceof ServiceEvent)) {
        return;
    }
    if (((ServiceEvent) eventProperty).getType() != ServiceEvent.UNREGISTERING) {
        return;
    }
    Object servicePid = ((ServiceEvent) event.getProperty(EventConstants.EVENT)).getServiceReference().getProperty(Constants.SERVICE_PID);
    if (servicePid == null) {
        return;
    }
    RegistryStore service = registryStorePidToServiceMap.get(servicePid);
    if (service == null) {
        return;
    }
    registryStorePidToServiceMap.remove(servicePid);
    LOGGER.info("Removing registry entries associated with remote registry {}", service.getId());
    executor.execute(() -> {
        String registryId = service.getRegistryId();
        try {
            Security security = Security.getInstance();
            List<Metacard> metacards = security.runAsAdminWithException(() -> federationAdminService.getInternalRegistryMetacards().stream().filter(m -> RegistryUtility.getStringAttribute(m, RegistryObjectMetacardType.REMOTE_REGISTRY_ID, "").equals(registryId)).collect(Collectors.toList()));
            List<String> idsToDelete = metacards.stream().map(Metacard::getId).collect(Collectors.toList());
            if (!idsToDelete.isEmpty()) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Removing {} registry entries that came from {}. Removed entries: {}", metacards.size(), service.getId(), metacards.stream().map(m -> m.getTitle() + ":" + m.getId()).collect(Collectors.joining(", ")));
                }
                security.runAsAdminWithException(() -> {
                    federationAdminService.deleteRegistryEntriesByMetacardIds(idsToDelete);
                    return null;
                });
            }
        } catch (PrivilegedActionException e) {
            LOGGER.info("Unable to clean up registry metacards after registry store {} was deleted", service.getId(), e);
        }
    });
}
Also used : Metacard(ddf.catalog.data.Metacard) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) PrivilegedActionException(java.security.PrivilegedActionException) ServiceEvent(org.osgi.framework.ServiceEvent) Security(org.codice.ddf.security.common.Security)

Example 2 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class FederationAdminTest method testRegistryStatus.

@Test
public void testRegistryStatus() throws Exception {
    RegistryStore source = mock(RegistryStore.class);
    Configuration config = mock(Configuration.class);
    Dictionary<String, Object> props = new Hashtable<>();
    props.put("service.pid", "servicePid");
    when(config.getProperties()).thenReturn(props);
    when(source.isAvailable()).thenReturn(true);
    when(helper.getRegistrySources()).thenReturn(Collections.singletonList(source));
    when(helper.getConfiguration(any(ConfiguredService.class))).thenReturn(config);
    assertThat(federationAdmin.registryStatus("servicePid"), is(true));
}
Also used : RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) RegistrySourceConfiguration(org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) ConfiguredService(ddf.catalog.service.ConfiguredService) Test(org.junit.Test)

Example 3 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class RegistryStorePublisher method unbindRegistryStore.

public void unbindRegistryStore(ServiceReference<RegistryStore> reference) {
    BundleContext bundleContext = getBundleContext();
    if (reference != null && bundleContext != null) {
        RegistryStore registryStore = bundleContext.getService(reference);
        registryStoreMap.remove(registryStore.getConfigurationPid());
    }
}
Also used : RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) BundleContext(org.osgi.framework.BundleContext)

Example 4 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class RegistryPublicationServiceImpl method bindRegistryStore.

public void bindRegistryStore(ServiceReference serviceReference) {
    BundleContext bundleContext = getBundleContext();
    if (serviceReference != null && bundleContext != null) {
        RegistryStore registryStore = (RegistryStore) bundleContext.getService(serviceReference);
        registryStores.add(registryStore);
    }
}
Also used : RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) BundleContext(org.osgi.framework.BundleContext)

Example 5 with RegistryStore

use of org.codice.ddf.registry.api.internal.RegistryStore in project ddf by codice.

the class RefreshRegistryEntries method getRemoteRegistryMetacardsMap.

/**
     * Directly queries the stores without going through the catalog framework
     */
private RemoteRegistryResults getRemoteRegistryMetacardsMap() throws FederationAdminException {
    Map<String, Metacard> remoteRegistryMetacards = new HashMap<>();
    List<String> failedQueries = new ArrayList<>();
    List<String> storesQueried = new ArrayList<>();
    List<String> localMetacardRegIds = getLocalRegistryIds();
    Map<String, Serializable> queryProps = new HashMap<>();
    queryProps.put(SecurityConstants.SECURITY_SUBJECT, security.runAsAdmin(() -> security.getSystemSubject()));
    LOGGER.debug("Querying {} remote registries", registryStores.size());
    //Create the remote query task to be run.
    List<Callable<RemoteResult>> tasks = new ArrayList<>();
    for (RegistryStore store : registryStores) {
        if (!store.isPullAllowed() || !store.isAvailable()) {
            LOGGER.debug("Skipping store {} because pull is disabled or it is unavailable", store.getId());
            continue;
        }
        storesQueried.add(store.getRegistryId());
        tasks.add(() -> {
            SourceResponse response = store.query(new QueryRequestImpl(getBasicRegistryQuery(), queryProps));
            Map<String, Metacard> results = response.getResults().stream().map(Result::getMetacard).filter(e -> !localMetacardRegIds.contains(RegistryUtility.getRegistryId(e))).collect(Collectors.toMap(Metacard::getId, Function.identity()));
            LOGGER.debug("Retrieved {} registry entries from {} with {} local entries filtered.", results.size(), store.getId(), response.getResults().size());
            logRegistryMetacards("Filtered remote entries", results.values());
            return new RemoteResult(store.getRegistryId(), results);
        });
    }
    failedQueries.addAll(storesQueried);
    List<RemoteResult> results = executeTasks(tasks);
    results.stream().forEach(result -> {
        failedQueries.remove(result.getRegistryId());
        remoteRegistryMetacards.putAll(result.getRemoteRegistryMetacards());
    });
    return new RemoteRegistryResults(remoteRegistryMetacards, failedQueries, storesQueried);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) FilterBuilder(ddf.catalog.filter.FilterBuilder) PropertyNameImpl(ddf.catalog.filter.impl.PropertyNameImpl) FederationAdminService(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminService) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) FederationAdminException(org.codice.ddf.registry.federationadmin.service.internal.FederationAdminException) SortBy(org.opengis.filter.sort.SortBy) CollectionUtils(org.apache.commons.collections.CollectionUtils) Metacard(ddf.catalog.data.Metacard) Map(java.util.Map) SecurityConstants(ddf.security.SecurityConstants) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) RegistryConstants(org.codice.ddf.registry.common.RegistryConstants) Result(ddf.catalog.data.Result) SortOrder(org.opengis.filter.sort.SortOrder) SortByImpl(org.geotools.filter.SortByImpl) PrivilegedActionException(java.security.PrivilegedActionException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Logger(org.slf4j.Logger) Security(org.codice.ddf.security.common.Security) RegistryUtility(org.codice.ddf.registry.common.metacard.RegistryUtility) Collection(java.util.Collection) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) Collectors(java.util.stream.Collectors) Serializable(java.io.Serializable) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Query(ddf.catalog.operation.Query) List(java.util.List) SourceResponse(ddf.catalog.operation.SourceResponse) PropertyName(org.opengis.filter.expression.PropertyName) Filter(org.opengis.filter.Filter) RegistryObjectMetacardType(org.codice.ddf.registry.common.metacard.RegistryObjectMetacardType) Serializable(java.io.Serializable) RegistryStore(org.codice.ddf.registry.api.internal.RegistryStore) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) Result(ddf.catalog.data.Result) Metacard(ddf.catalog.data.Metacard) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl)

Aggregations

RegistryStore (org.codice.ddf.registry.api.internal.RegistryStore)13 BundleContext (org.osgi.framework.BundleContext)6 Test (org.junit.Test)5 Metacard (ddf.catalog.data.Metacard)3 ConfiguredService (ddf.catalog.service.ConfiguredService)3 SourceResponse (ddf.catalog.operation.SourceResponse)2 Serializable (java.io.Serializable)2 PrivilegedActionException (java.security.PrivilegedActionException)2 ArrayList (java.util.ArrayList)2 Hashtable (java.util.Hashtable)2 Attribute (ddf.catalog.data.Attribute)1 Result (ddf.catalog.data.Result)1 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 ResultImpl (ddf.catalog.data.impl.ResultImpl)1 FilterBuilder (ddf.catalog.filter.FilterBuilder)1 PropertyNameImpl (ddf.catalog.filter.impl.PropertyNameImpl)1 Query (ddf.catalog.operation.Query)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1