use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class AdminPollerTest method testAllSourceInfo.
@Test
public void testAllSourceInfo() {
Action operatorActionOne = getTestAction("operationIdOne", "operationTitle1", "operationDescription1", "https://localhost:8993/provider/someAction");
Action operatorActionTwo = getTestAction("operationIdTwo", "operationTitleTwo", "operationDescriptionTwo", "https://localhost:8993/provider/someAction");
ImmutableList<MultiActionProvider> operationActions = ImmutableList.of(getHandleableTestActionProvider(operatorActionOne), getNotHandleableTestActionProvider(), getHandleableTestActionProvider(operatorActionTwo));
poller.setOperationActionProviders(operationActions);
Action reportActionOne = getTestAction("reportId", "reportTitle", "reportDescription", "https://localhost:8993/provider/someAction");
ImmutableList<MultiActionProvider> reportActions = ImmutableList.of(getHandleableTestActionProvider(reportActionOne), getNotHandleableTestActionProvider(), getNotHandleableTestActionProvider());
poller.setReportActionProviders(reportActions);
List<Service> sources = poller.allSourceInfo();
assertThat(sources, notNullValue());
assertThat(sources.size(), is(2));
assertThat(sources.get(0), not(hasKey("configurations")));
assertThat(sources.get(1), hasKey("configurations"));
List<Map<String, Object>> configurations = (List) sources.get(1).get("configurations");
assertThat(configurations, hasSize(2));
Map<String, Object> configurationMap = configurations.get(0);
assertThat(configurationMap, hasKey("operation_actions"));
assertThat(configurationMap, hasKey("report_actions"));
List<Map<String, Object>> operationActionsList = (List) configurationMap.get("operation_actions");
Map<String, String> operatorActionOneMap = getMapFromAction(operatorActionOne);
Map<String, String> operatorActionTwoMap = getMapFromAction(operatorActionTwo);
assertThat(operationActionsList, contains(operatorActionOneMap, operatorActionTwoMap));
List<Map<String, Object>> reportActionsList = (List) configurationMap.get("report_actions");
Map<String, String> reportActionMap = getMapFromAction(reportActionOne);
assertThat(reportActionsList, contains(reportActionMap));
}
use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class AdminPollerServiceBean method allSourceInfo.
@Override
public List<Service> allSourceInfo() {
// Get list of metatypes
List<Service> metatypes = helper.getMetatypes();
// Loop through each metatype and find its configurations
for (Service metatype : metatypes) {
try {
List<Configuration> configs = helper.getConfigurations(metatype);
List<ConfigurationDetails> configurations = new ArrayList<>();
if (configs != null) {
for (Configuration config : configs) {
ConfigurationDetails source = new ConfigurationDetailsImpl();
String pid = config.getPid();
String fPid = config.getFactoryPid();
boolean disabled = pid.endsWith(ConfigurationStatus.DISABLED_EXTENSION);
if (fPid != null) {
disabled = disabled || fPid.endsWith(ConfigurationStatus.DISABLED_EXTENSION);
}
source.setId(pid);
source.setEnabled(!disabled);
source.setFactoryPid(fPid);
if (!disabled) {
source.setName(helper.getName(config));
source.setBundleName(helper.getBundleName(config));
source.setBundleLocation(config.getBundleLocation());
source.setBundle(helper.getBundleId(config));
} else {
source.setName(config.getPid());
}
Dictionary<String, Object> properties = config.getProperties();
ConfigurationProperties plist = new ConfigurationPropertiesImpl();
for (String key : Collections.list(properties.keys())) {
plist.put(key, properties.get(key));
}
source.setConfigurationProperties(plist);
source.put(MAP_ENTRY_REPORT_ACTIONS, getActions(config, reportActionProviders));
source.put(MAP_ENTRY_OPERATION_ACTIONS, getActions(config, operationActionProviders));
configurations.add(source);
}
metatype.setConfigurations(configurations);
}
} catch (Exception e) {
LOGGER.debug("Error getting source info: {}", e.getMessage());
}
}
metatypes.sort(Comparator.comparing(Service::getId, String.CASE_INSENSITIVE_ORDER));
return metatypes;
}
use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class ApplicationServiceBeanTest method testGetServicesASE.
/**
* Tests the {@link ApplicationServiceBean#getServices(String)} method for the case where an
* ApplicationServiceException is thrown
*
* @throws Exception
*/
// TODO RAP 29 Aug 16: DDF-2443 - Fix test to not depend on specific log output
@Test
public void testGetServicesASE() 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);
root.setLevel(Level.ALL);
ApplicationServiceBean serviceBean = newApplicationServiceBean();
Bundle testBundle = mock(Bundle.class);
Bundle[] bundles = { testBundle };
when(bundleContext.getBundles()).thenReturn(bundles);
List<Service> services = new ArrayList<>();
Service testService1 = new ServiceImpl();
services.add(testService1);
when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(services);
serviceBean.getServices(TEST_APP_NAME);
}
use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class ApplicationServiceBean method getServices.
/**
* {@inheritDoc}.
*/
@Override
public List<Map<String, Object>> getServices(String applicationID) {
try {
List<Service> services = configAdmin.listServices(getDefaultFactoryLdapFilter(), getDefaultLdapFilter());
if (services.isEmpty()) {
return Collections.emptyList();
}
Set<BundleInfo> bundleInfos = getBundleInfosForApplication(applicationID);
if (bundleInfos == null) {
return Collections.emptyList();
}
Set<String> bundleLocations = bundleInfos.stream().map(BundleInfo::getLocation).collect(Collectors.toSet());
MetaTypeService metatypeService = getMetaTypeService();
Set<MetaTypeInformation> metatypeInformation = (metatypeService == null) ? Collections.emptySet() : Arrays.stream(getContext().getBundles()).filter(b -> bundleLocations.contains(computeLocation(b))).map(metatypeService::getMetaTypeInformation).collect(Collectors.toSet());
return services.stream().filter(service -> hasBundleLocation(service, bundleLocations) || hasMetatypesForService(service, metatypeInformation)).collect(Collectors.toList());
} catch (VirtualMachineError e) {
throw e;
} catch (Throwable e) {
LOGGER.info("Could not retrieve services", e);
throw new ApplicationServiceBeanException("Could not retrieve services");
}
}
use of org.codice.ddf.admin.core.api.Service in project ddf by codice.
the class ApplicationServiceBeanTest method testGetServicesMetatypeInfo.
/**
* Tests the {@link ApplicationServiceBean#getServices(String)} method for the case where the
* services do not have the "configurations" key and there is MetatypeInformation present for each
* service.
*
* <p>This test mostly just checks that
*
* @throws Exception
*/
@Test
public void testGetServicesMetatypeInfo() throws Exception {
ApplicationServiceBean serviceBean = newApplicationServiceBean();
ServiceTracker testServiceTracker = mock(ServiceTracker.class);
serviceBean.setServiceTracker(testServiceTracker);
MetaTypeService testMTS = mock(MetaTypeService.class);
MetaTypeInformation testMTI = mock(MetaTypeInformation.class);
when(testServiceTracker.getService()).thenReturn(testMTS);
when(testMTS.getMetaTypeInformation(any(Bundle.class))).thenReturn(testMTI);
when(testMTI.getPids()).thenReturn(new String[] { "001", "002" });
when(testMTI.getFactoryPids()).thenReturn(new String[] { "001", "002" });
Bundle testBundle = mock(Bundle.class);
Bundle[] bundles = { testBundle };
when(bundleContext.getBundles()).thenReturn(bundles);
when(testBundle.getLocation()).thenReturn(TEST_LOCATION);
List<Service> services = new ArrayList<>();
Service testService2 = mock(Service.class);
Service testService1 = mock(Service.class);
services.add(testService1);
services.add(testService2);
List<Map<String, Object>> testService1Configs = new ArrayList<>();
Map<String, Object> testConfig1 = new HashMap<>();
testConfig1.put("bundle_location", TEST_LOCATION);
testService1Configs.add(testConfig1);
List<Map<String, Object>> testService2Configs = new ArrayList<>();
Map<String, Object> testConfig2 = new HashMap<>();
testConfig2.put("bundle_location", TEST_LOCATION);
testService1Configs.add(testConfig2);
when(testService1.get("factory")).thenReturn(true);
when(testService2.get("factory")).thenReturn(false);
when(testService1.get("configurations")).thenReturn(testService1Configs);
when(testService2.get("configurations")).thenReturn(testService2Configs);
when(testService1.get("id")).thenReturn("001");
when(testService2.get("id")).thenReturn("002");
BundleInfo testBundle1 = mock(BundleInfo.class);
Set<BundleInfo> testBundles = new HashSet<>();
testBundles.add(testBundle1);
when(testApp.getBundles()).thenReturn(testBundles);
when(testBundle1.getLocation()).thenReturn(TEST_LOCATION);
when(testAppService.getApplication(TEST_APP_NAME)).thenReturn(testApp);
when(testConfigAdminExt.listServices(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(services);
assertThat("Should find the given services.", serviceBean.getServices(TEST_APP_NAME).get(0), is(testService1));
}
Aggregations