Search in sources :

Example 91 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class ManagedServiceFactoryConfigurationFile method createConfig.

@Override
public void createConfig() throws ConfigurationFileException {
    String factoryPid = getFactoryPid();
    try {
        Configuration configuration = configAdmin.createFactoryConfiguration(factoryPid, null);
        configuration.update(properties);
    } catch (IOException e) {
        String message = String.format("Unable to get or update Configuration for factory pid [%s].", factoryPid);
        LOGGER.info(message, e);
        throw new ConfigurationFileException(message, e);
    }
}
Also used : Configuration(org.osgi.service.cm.Configuration) ConfigurationFileException(org.codice.ddf.configuration.status.ConfigurationFileException) IOException(java.io.IOException)

Example 92 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class CswSubscriptionEndpoint method getSubscriptionConfiguration.

private Configuration getSubscriptionConfiguration(String subscriptionUuid) {
    String methodName = "getSubscriptionConfiguration";
    LOGGER.trace("ENTERING: {}", methodName);
    String filterStr = getSubscriptionUuidFilter(subscriptionUuid);
    LOGGER.debug("filterStr = {}", filterStr);
    Configuration config = null;
    try {
        org.osgi.framework.Filter filter = getBundleContext().createFilter(filterStr);
        LOGGER.debug("filter.toString() = {}", filter.toString());
        ConfigurationAdmin configAdmin = getConfigAdmin();
        if (configAdmin != null) {
            Configuration[] configs = configAdmin.listConfigurations(filter.toString());
            if (configs == null) {
                LOGGER.debug("Did NOT find a configuration for filter {}", filterStr);
            } else if (configs.length != 1) {
                LOGGER.debug("Found multiple configurations for filter {}", filterStr);
            } else {
                LOGGER.debug("Found exactly one configuration for filter {}", filterStr);
                config = configs[0];
            }
        }
    } catch (InvalidSyntaxException e) {
        LOGGER.debug("Invalid syntax for filter used for searching configuration instances", e);
    } catch (IOException e) {
        LOGGER.debug("IOException trying to list configurations for filter {}", filterStr, e);
    }
    LOGGER.trace("EXITING: {}", methodName);
    return config;
}
Also used : Configuration(org.osgi.service.cm.Configuration) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 93 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class CswSubscriptionEndpoint method deleteCswSubscription.

private synchronized CswSubscription deleteCswSubscription(String subscriptionId) throws CswException {
    String methodName = "deleteCswSubscription";
    LOGGER.trace("ENTERING: {}", methodName);
    LOGGER.trace("subscriptionId = {}", subscriptionId);
    if (StringUtils.isEmpty(subscriptionId)) {
        throw new CswException("Unable to delete subscription because subscription ID is null or empty");
    }
    CswSubscription subscription = getSubscription(subscriptionId);
    try {
        LOGGER.debug("Removing (unregistering) subscription: {}", subscriptionId);
        ServiceRegistration sr = (ServiceRegistration) registeredSubscriptions.remove(subscriptionId);
        if (sr != null) {
            sr.unregister();
        } else {
            LOGGER.debug("No ServiceRegistration found for subscription: {}", subscriptionId);
        }
        Configuration subscriptionConfig = getSubscriptionConfiguration(subscriptionId);
        try {
            if (subscriptionConfig != null) {
                LOGGER.debug("Deleting subscription for subscriptionId = {}", subscriptionId);
                subscriptionConfig.delete();
            } else {
                LOGGER.debug("subscriptionConfig is NULL for ID = {}", subscriptionId);
            }
        } catch (IOException e) {
            LOGGER.debug("IOException trying to delete subscription's configuration for subscription ID {}", subscriptionId, e);
        }
        LOGGER.debug("Subscription removal complete");
    } catch (Exception e) {
        LOGGER.debug("Could not delete subscription for {}", subscriptionId, e);
    }
    LOGGER.trace("EXITING: {}    (status = {})", methodName, false);
    return subscription;
}
Also used : Configuration(org.osgi.service.cm.Configuration) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) IOException(java.io.IOException) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) CswException(org.codice.ddf.spatial.ogc.csw.catalog.common.CswException) JAXBException(javax.xml.bind.JAXBException) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) IOException(java.io.IOException) ServiceRegistration(org.osgi.framework.ServiceRegistration)

Example 94 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class CswSubscriptionEndpoint method persistSubscription.

/**
     * Persist the subscription to the OSGi ConfigAdmin service. Persisted registeredSubscriptions can then be restored if DDF
     * is restarted after a DDF outage or DDF is shutdown.
     * Pass in client-provided subscriptionId and subscription UUID because the filter XML to be persisted for this subscription will be used to
     * restore this subscription and should consist of the exact values the
     * client originally provided.
     */
private void persistSubscription(CswSubscription subscription, String deliveryMethodUrl, String subscriptionUuid) {
    String methodName = "persistSubscription";
    LOGGER.trace("ENTERING: {}", methodName);
    try {
        StringWriter sw = new StringWriter();
        CswQueryFactory.getJaxBContext().createMarshaller().marshal(objectFactory.createGetRecords(subscription.getOriginalRequest()), sw);
        String filterXml = sw.toString();
        // Store filter XML, deliveryMethod URL, this endpoint's factory PID, and subscription ID into OSGi CongiAdmin
        if (filterXml != null) {
            Configuration config = getConfigAdmin().createFactoryConfiguration(CswSubscriptionConfigFactory.FACTORY_PID, null);
            Dictionary<String, String> props = new Hashtable<>();
            props.put(CswSubscriptionConfigFactory.SUBSCRIPTION_ID, subscriptionUuid);
            props.put(CswSubscriptionConfigFactory.FILTER_XML, filterXml);
            props.put(CswSubscriptionConfigFactory.DELIVERY_METHOD_URL, deliveryMethodUrl);
            props.put(CswSubscriptionConfigFactory.SUBSCRIPTION_UUID, subscriptionUuid);
            LOGGER.debug("Done adding persisting subscription to ConfigAdmin");
            config.update(props);
        }
    } catch (JAXBException | IOException e) {
        LOGGER.debug("Unable to persist subscription {}", subscriptionUuid, e);
    }
    LOGGER.trace("EXITING: {}", methodName);
}
Also used : StringWriter(java.io.StringWriter) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) JAXBException(javax.xml.bind.JAXBException) IOException(java.io.IOException)

Example 95 with Configuration

use of org.osgi.service.cm.Configuration in project ddf by codice.

the class TestCatalog method testIngestPlugin.

@Test
public void testIngestPlugin() throws Exception {
    //ingest a data set to make sure we don't have any issues initially
    String id1 = ingestGeoJson(getFileContent(JSON_RECORD_RESOURCE_PATH + "/SimpleGeoJsonRecord"));
    String xPath1 = format(METACARD_X_PATH, id1);
    //verify ingest by querying
    ValidatableResponse response = executeOpenSearch("xml", "q=*");
    response.body(hasXPath(xPath1));
    //change ingest plugin role to ingest
    CatalogPolicyProperties catalogPolicyProperties = new CatalogPolicyProperties();
    catalogPolicyProperties.put("createPermissions", new String[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=ingest" });
    Configuration config = configAdmin.getConfiguration("org.codice.ddf.catalog.security.CatalogPolicy", null);
    Dictionary<String, Object> configProps = new Hashtable<>(catalogPolicyProperties);
    config.update(configProps);
    getServiceManager().waitForAllBundles();
    //try ingesting again - it should fail this time
    given().body(getFileContent(JSON_RECORD_RESOURCE_PATH + "/SimpleGeoJsonRecord")).header(HttpHeaders.CONTENT_TYPE, "application/json").expect().log().all().statusCode(400).when().post(REST_PATH.getUrl());
    //verify query for first id works
    response = executeOpenSearch("xml", "q=*");
    response.body(hasXPath(xPath1));
    //revert to original configuration
    configProps.put("createPermissions", new String[] { "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=guest" });
    config.update(configProps);
    getServiceManager().waitForAllBundles();
    deleteMetacard(id1);
}
Also used : ValidatableResponse(com.jayway.restassured.response.ValidatableResponse) Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) JSONObject(org.json.simple.JSONObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) SkipUnstableTest(org.codice.ddf.itests.common.annotations.SkipUnstableTest) Test(org.junit.Test) AbstractIntegrationTest(org.codice.ddf.itests.common.AbstractIntegrationTest)

Aggregations

Configuration (org.osgi.service.cm.Configuration)226 Test (org.junit.Test)85 Hashtable (java.util.Hashtable)75 IOException (java.io.IOException)55 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)49 Dictionary (java.util.Dictionary)36 ArrayList (java.util.ArrayList)19 HashMap (java.util.HashMap)19 ServiceReference (org.osgi.framework.ServiceReference)19 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)18 Matchers.anyString (org.mockito.Matchers.anyString)16 BundleContext (org.osgi.framework.BundleContext)15 RegistrySourceConfiguration (org.codice.ddf.registry.federationadmin.service.internal.RegistrySourceConfiguration)11 Map (java.util.Map)10 Bundle (org.osgi.framework.Bundle)10 File (java.io.File)9 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)9 Mockito.anyString (org.mockito.Mockito.anyString)9 AbstractIntegrationTest (org.codice.ddf.itests.common.AbstractIntegrationTest)8 SkipUnstableTest (org.codice.ddf.itests.common.annotations.SkipUnstableTest)7