Search in sources :

Example 61 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.

the class AbstractTransactionTest method clearConfiguration.

private void clearConfiguration() {
    ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
    org.osgi.service.cm.Configuration[] cfgs = null;
    try {
        cfgs = cm.listConfigurations(null);
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    if (cfgs != null) {
        for (org.osgi.service.cm.Configuration cfg : cfgs) {
            try {
                cfg.delete();
            } catch (Exception e) {
            }
        }
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
Also used : Configuration(org.ops4j.pax.exam.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) SQLException(java.sql.SQLException) NoSuchElementException(java.util.NoSuchElementException) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) IOException(java.io.IOException)

Example 62 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.

the class JPALifecycleTest method testDeleteOfConfig.

@Test
public void testDeleteOfConfig() throws Exception {
    Message m = new Message();
    m.message = "Hello World";
    txControl.required(() -> {
        em.persist(m);
        return null;
    });
    assertEquals(m.message, txControl.notSupported(() -> em.find(Message.class, m.id).message));
    ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
    Configuration[] configurations = cm.listConfigurations("(service.factoryPid=org.apache.aries.tx.control.jpa.*)");
    assertNotNull(configurations);
    assertEquals(1, configurations.length);
    configurations[0].delete();
    Thread.sleep(2000);
    try {
        assertEquals(m.message, txControl.notSupported(() -> em.find(Message.class, m.id).message));
        fail("Should not be accessible " + (Boolean.getBoolean(IS_XA) ? "xa" : "local"));
    } catch (ScopedWorkException swe) {
        assertTrue(swe.getCause().toString(), swe.getCause() instanceof TransactionException);
        assertEquals("There was a problem getting hold of a database connection", swe.getCause().getMessage());
    }
}
Also used : ScopedWorkException(org.osgi.service.transaction.control.ScopedWorkException) TransactionException(org.osgi.service.transaction.control.TransactionException) Message(org.apache.aries.tx.control.itests.entity.Message) Configuration(org.osgi.service.cm.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Example 63 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project aries by apache.

the class JPALifecycleTest method testUpdateOfConfig.

@Test
public void testUpdateOfConfig() throws Exception {
    Message m = new Message();
    m.message = "Hello World";
    txControl.required(() -> {
        em.persist(m);
        return null;
    });
    assertEquals(m.message, txControl.notSupported(() -> em.find(Message.class, m.id).message));
    ConfigurationAdmin cm = getService(ConfigurationAdmin.class, 5000);
    Configuration[] configurations = cm.listConfigurations("(service.factoryPid=org.apache.aries.tx.control.jpa.*)");
    assertNotNull(configurations);
    assertEquals(1, configurations.length);
    configurations[0].update();
    Thread.sleep(2000);
    try {
        assertEquals(m.message, txControl.notSupported(() -> em.find(Message.class, m.id).message));
        fail("Should not be accessible " + (Boolean.getBoolean(IS_XA) ? "xa" : "local"));
    } catch (ScopedWorkException swe) {
        assertTrue(swe.getCause().toString(), swe.getCause() instanceof TransactionException);
        assertEquals("There was a problem getting hold of a database connection", swe.getCause().getMessage());
    }
}
Also used : ScopedWorkException(org.osgi.service.transaction.control.ScopedWorkException) TransactionException(org.osgi.service.transaction.control.TransactionException) Message(org.apache.aries.tx.control.itests.entity.Message) Configuration(org.osgi.service.cm.Configuration) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) Test(org.junit.Test)

Example 64 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.

the class Activator method doStart.

@Override
protected void doStart() throws Exception {
    ConfigurationAdmin configurationAdmin = getTrackedService(ConfigurationAdmin.class);
    JdbcServiceImpl service = new JdbcServiceImpl();
    service.setBundleContext(bundleContext);
    service.setConfigAdmin(configurationAdmin);
    register(JdbcService.class, service);
    JdbcMBeanImpl mbean = new JdbcMBeanImpl();
    mbean.setJdbcService(service);
    registerMBean(mbean, "type=jdbc");
}
Also used : JdbcServiceImpl(org.apache.karaf.jdbc.internal.JdbcServiceImpl) JdbcMBeanImpl(org.apache.karaf.jdbc.internal.JdbcMBeanImpl) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Example 65 with ConfigurationAdmin

use of org.osgi.service.cm.ConfigurationAdmin in project karaf by apache.

the class AppendTest method testLoad.

public void testLoad() throws Exception {
    System.setProperty("karaf.data", "data");
    System.setProperty("karaf.etc", "etc");
    RepositoryImpl r = new RepositoryImpl(getClass().getResource("internal/service/f08.xml").toURI());
    // Check repo
    Feature[] features = r.getFeatures();
    assertNotNull(features);
    assertEquals(1, features.length);
    Feature feature = features[0];
    ConfigInfo configInfo = feature.getConfigurations().get(0);
    assertNotNull(configInfo);
    assertTrue(configInfo.isAppend());
    Properties properties = configInfo.getProperties();
    assertNotNull(properties);
    String property = properties.getProperty("javax.servlet.context.tempdir");
    assertNotNull(property);
    assertFalse(property.contains("${"));
    assertEquals(property, "data/pax-web-jsp");
    ConfigurationAdmin admin = EasyMock.createMock(ConfigurationAdmin.class);
    Configuration config = EasyMock.createMock(Configuration.class);
    EasyMock.expect(admin.listConfigurations(EasyMock.eq("(service.pid=org.ops4j.pax.web)"))).andReturn(new Configuration[] { config });
    Hashtable<String, Object> original = new Hashtable<>();
    original.put("javax.servlet.context.tempdir", "data/pax-web-jsp");
    EasyMock.expect(config.getProperties()).andReturn(original);
    Hashtable<String, Object> expected = new Hashtable<>();
    expected.put("org.ops4j.pax.web", "data/pax-web-jsp");
    expected.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web");
    expected.put("foo", "bar");
    EasyMock.expectLastCall();
    EasyMock.replay(admin, config);
    FeatureConfigInstaller installer = new FeatureConfigInstaller(admin);
    installer.installFeatureConfigs(feature);
    EasyMock.verify(admin, config);
    EasyMock.reset(admin, config);
    EasyMock.expect(admin.listConfigurations(EasyMock.eq("(service.pid=org.ops4j.pax.web)"))).andReturn(new Configuration[] { config });
    original = new Hashtable<>();
    original.put("org.apache.karaf.features.configKey", "org.ops4j.pax.web");
    original.put("javax.servlet.context.tempdir", "value");
    original.put("foo", "bar");
    EasyMock.expect(config.getProperties()).andReturn(original);
    EasyMock.replay(admin, config);
    installer.installFeatureConfigs(feature);
    EasyMock.verify(admin, config);
}
Also used : Configuration(org.osgi.service.cm.Configuration) Hashtable(java.util.Hashtable) Properties(java.util.Properties) FeatureConfigInstaller(org.apache.karaf.features.internal.service.FeatureConfigInstaller) RepositoryImpl(org.apache.karaf.features.internal.service.RepositoryImpl) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin)

Aggregations

ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)108 Configuration (org.osgi.service.cm.Configuration)42 Subject (javax.security.auth.Subject)24 Test (org.junit.Test)19 Hashtable (java.util.Hashtable)14 BundleContext (org.osgi.framework.BundleContext)14 ServiceReference (org.osgi.framework.ServiceReference)13 IOException (java.io.IOException)9 Dictionary (java.util.Dictionary)8 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)7 Method (java.lang.reflect.Method)6 Bundle (org.osgi.framework.Bundle)6 File (java.io.File)4 Properties (java.util.Properties)4 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 KarafMBeanServerGuard (org.apache.karaf.management.KarafMBeanServerGuard)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 CompositeData (javax.management.openmbean.CompositeData)3