use of ddf.catalog.source.Source in project ddf by codice.
the class CatalogBundle method waitForSource.
private <T extends Source> T waitForSource(String id, Class<T> type) throws InterruptedException, InvalidSyntaxException {
T source = null;
long timeoutLimit = System.currentTimeMillis() + CATALOG_PROVIDER_TIMEOUT;
boolean available = false;
while (!available) {
ServiceReference<CatalogFramework> frameworkRef = serviceManager.getServiceReference(CatalogFramework.class);
CatalogFramework framework = null;
if (frameworkRef != null) {
framework = serviceManager.getService(frameworkRef);
}
if (source == null) {
source = serviceManager.getServiceReferences(type, null).stream().map(serviceManager::getService).filter(src -> id.equals(src.getId())).findFirst().orElse(null);
}
if (source != null && framework != null) {
SourceInfoRequestEnterprise sourceInfoRequestEnterprise = new SourceInfoRequestEnterprise(true);
try {
SourceInfoResponse sources = framework.getSourceInfo(sourceInfoRequestEnterprise);
Set<SourceDescriptor> sourceInfo = sources.getSourceInfo();
for (SourceDescriptor sourceDescriptor : sourceInfo) {
if (sourceDescriptor.getSourceId().equals(source.getId())) {
available = sourceDescriptor.isAvailable() && source.isAvailable();
LOGGER.info("Source.isAvailable = {} Framework.isAvailable = {}", source.isAvailable(), sourceDescriptor.isAvailable());
}
}
} catch (SourceUnavailableException e) {
available = false;
}
} else {
LOGGER.info("Currently no source of type {} and name {} could be found", type.getName(), id);
}
if (!available) {
if (System.currentTimeMillis() > timeoutLimit) {
fail("Source (" + id + ") was not created in a timely manner.");
}
Thread.sleep(1000);
}
}
LOGGER.info("Source {} is available.", id);
return source;
}
use of ddf.catalog.source.Source in project ddf by codice.
the class TestRegistryReportActionProvider method setup.
@Before
public void setup() {
metacard = new MetacardImpl();
source = mock(Source.class);
configurationAdmin = mock(ConfigurationAdmin.class);
configuration = mock(Configuration.class);
actionProvider = new RegistryReportActionProvider(ACTION_PROVIDER_ID);
metacard.setId(SAMPLE_ID);
metacard.setTags(SAMPLE_REGISTRY_TAGS);
metacard.setSourceId(SAMPLE_SOURCE_ID);
metacard.setAttribute(RegistryObjectMetacardType.REGISTRY_ID, SAMPLE_REGISTRY_ID);
}
use of ddf.catalog.source.Source in project ddf by codice.
the class FederationAdminTest method testRegistryStatusNotConfiguredService.
@Test
public void testRegistryStatusNotConfiguredService() throws Exception {
Source source = mock(Source.class);
when(helper.getRegistrySources()).thenReturn(Collections.singletonList(source));
assertThat(federationAdmin.registryStatus("servicePid"), is(false));
}
use of ddf.catalog.source.Source in project admin-console-beta by connexta.
the class SourceUtilCommons method getAllSourceReferences.
public static List<Source> getAllSourceReferences(ConfiguratorFactory configuratorFactory) {
List<Source> sources = new ArrayList<>();
ConfigReader configReader = configuratorFactory.getConfigReader();
sources.addAll(configReader.getServices(FederatedSource.class, null));
sources.addAll(configReader.getServices(ConnectedSource.class, null));
return sources;
}
use of ddf.catalog.source.Source in project ddf by codice.
the class SourceMetricsImpl method createMetric.
private boolean createMetric(List<? extends Source> sources, String sourceId) {
for (Source source : sources) {
if (source.getId().equals(sourceId)) {
LOGGER.debug("Found sourceId = {} in sources list", sourceId);
if (sourceToSourceIdMap.containsKey(source)) {
// Source's ID must have changed since it is in this map but not in the metrics
// map
// Delete SourceMetrics for Source's "old" sourceId
String oldSourceId = sourceToSourceIdMap.get(source);
LOGGER.debug("CASE 2: source {} exists but has oldSourceId = {}", sourceId, oldSourceId);
deleteMetric(oldSourceId, QUERIES_TOTAL_RESULTS_SCOPE);
deleteMetric(oldSourceId, QUERIES_SCOPE);
deleteMetric(oldSourceId, EXCEPTIONS_SCOPE);
// Create metrics for Source with new sourceId
createMetric(sourceId, QUERIES_TOTAL_RESULTS_SCOPE, MetricType.HISTOGRAM);
createMetric(sourceId, QUERIES_SCOPE, MetricType.METER);
createMetric(sourceId, EXCEPTIONS_SCOPE, MetricType.METER);
// Add Source to map with its new sourceId
sourceToSourceIdMap.put(source, sourceId);
} else {
// This is a brand new Source - create metrics for it
// (Should rarely happen since Sources typically have their metrics created
// when the Source itself is created via the addingSource() method. This could
// happen if sourceId = null when Source originally created and then its metric
// needs updating because client, e.g., SortedFederationStrategy, knows the
// Source exists.)
LOGGER.debug("CASE 3: New source {} detected - creating metrics", sourceId);
createMetric(sourceId, QUERIES_TOTAL_RESULTS_SCOPE, MetricType.HISTOGRAM);
createMetric(sourceId, QUERIES_SCOPE, MetricType.METER);
createMetric(sourceId, EXCEPTIONS_SCOPE, MetricType.METER);
sourceToSourceIdMap.put(source, sourceId);
}
return true;
}
}
LOGGER.debug("Did not find source {} in Sources - cannot create metrics", sourceId);
return false;
}
Aggregations