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);
}
});
}
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));
}
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());
}
}
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);
}
}
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);
}
Aggregations