Search in sources :

Example 6 with IPentahoObjectFactory

use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project pentaho-platform by pentaho.

the class PentahoSystemPluginManager method reload.

@Override
public boolean reload(IPentahoSession session) {
    boolean anyErrors = false;
    IPluginProvider pluginProvider = PentahoSystem.get(IPluginProvider.class, "IPluginProvider", session);
    List<IPlatformPlugin> providedPlugins = Collections.emptyList();
    try {
        this.unloadPlugins();
        // the plugin may fail to load during getPlugins without an exception thrown if the provider
        // is capable of discovering the plugin fine but there are structural problems with the plugin
        // itself. In this case a warning should be logged by the provider, but, again, no exception
        // is expected.
        providedPlugins = pluginProvider.getPlugins(session);
    } catch (PlatformPluginRegistrationException e1) {
        String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0012_PLUGIN_DISCOVERY_FAILED");
        org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, e1);
        PluginMessageLogger.add(msg);
        anyErrors = true;
    }
    for (IPlatformPlugin plugin : providedPlugins) {
        try {
            IPlatformPlugin existingPlugin = PentahoSystem.get(IPlatformPlugin.class, null, Collections.singletonMap(PLUGIN_ID, plugin.getId()));
            if (existingPlugin != null) {
                throw new PlatformPluginRegistrationException(Messages.getInstance().getErrorString("PluginManager.ERROR_0024_PLUGIN_ALREADY_LOADED_BY_SAME_NAME", plugin.getId()));
            }
            final ClassLoader classloader = createClassloader(plugin);
            // Register the classloader, Spring App Context and Object Factory with PentahoSystem
            IPentahoObjectRegistration handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<IPlatformPlugin>(IPlatformPlugin.class).object(plugin).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), IPlatformPlugin.class);
            registerReference(plugin.getId(), handle);
            handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<ClassLoader>(ClassLoader.class).object(classloader).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), ClassLoader.class);
            registerReference(plugin.getId(), handle);
            final GenericApplicationContext beanFactory = createBeanFactory(plugin, classloader);
            final StandaloneSpringPentahoObjectFactory pentahoFactory = new StandaloneSpringPentahoObjectFactory("Plugin Factory ( " + plugin.getId() + " )");
            pentahoFactory.init(null, beanFactory);
            beanFactory.refresh();
            handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<GenericApplicationContext>(GenericApplicationContext.class).object(beanFactory).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), IPentahoRegistrableObjectFactory.Types.ALL);
            registerReference(plugin.getId(), handle);
            handle = PentahoSystem.registerReference(new SingletonPentahoObjectReference.Builder<IPentahoObjectFactory>(IPentahoObjectFactory.class).object(pentahoFactory).attributes(Collections.<String, Object>singletonMap(PLUGIN_ID, plugin.getId())).build(), IPentahoObjectFactory.class);
            registerReference(plugin.getId(), handle);
        } catch (Throwable t) {
            // this has been logged already
            anyErrors = true;
            String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", plugin.getId());
            org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, t);
            PluginMessageLogger.add(msg);
        }
    }
    for (IPlatformPlugin plugin : providedPlugins) {
        try {
            registerPlugin(plugin);
        } catch (Throwable t) {
            // this has been logged already
            anyErrors = true;
            String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0011_FAILED_TO_REGISTER_PLUGIN", plugin.getId());
            org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, t);
            PluginMessageLogger.add(msg);
        }
    }
    IServiceManager svcManager = PentahoSystem.get(IServiceManager.class, null);
    if (svcManager != null) {
        try {
            svcManager.initServices();
        } catch (ServiceInitializationException e) {
            String msg = Messages.getInstance().getErrorString("PluginManager.ERROR_0022_SERVICE_INITIALIZATION_FAILED");
            org.pentaho.platform.util.logging.Logger.error(getClass().toString(), msg, e);
            PluginMessageLogger.add(msg);
        }
    }
    for (IPluginManagerListener listener : listeners) {
        listener.onReload();
    }
    return !anyErrors;
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) SingletonPentahoObjectReference(org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPluginManagerListener(org.pentaho.platform.api.engine.IPluginManagerListener) IPentahoObjectRegistration(org.pentaho.platform.api.engine.IPentahoObjectRegistration) PlatformPluginRegistrationException(org.pentaho.platform.api.engine.PlatformPluginRegistrationException) IServiceManager(org.pentaho.platform.api.engine.IServiceManager) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) ServiceInitializationException(org.pentaho.platform.api.engine.ServiceInitializationException)

Example 7 with IPentahoObjectFactory

use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project pentaho-platform by pentaho.

the class BootTest method testBootSettings.

@Test
public void testBootSettings() throws Exception {
    PentahoSystemBoot boot = new PentahoSystemBoot();
    boot.setFilePath("src/test/resources/solution");
    IPentahoObjectFactory factory = boot.getFactory();
    assertNotNull("object factory is null", factory);
    SystemSettings settings = new SystemSettings();
    boot.setSettingsProvider(settings);
    assertEquals(settings, boot.getSettingsProvider());
}
Also used : PentahoSystemBoot(org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) SystemSettings(org.pentaho.platform.engine.core.system.SystemSettings) Test(org.junit.Test)

Example 8 with IPentahoObjectFactory

use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project pentaho-platform by pentaho.

the class BootTest method testBootListeners.

@Test
public void testBootListeners() throws Exception {
    PentahoSystemBoot boot = new PentahoSystemBoot();
    boot.setFilePath("src/test/resources/solution");
    boot.define(ISolutionEngine.class.getSimpleName(), Object1.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
    TestLifecycleListener lifecycleListener1 = new TestLifecycleListener();
    TestLifecycleListener lifecycleListener2 = new TestLifecycleListener();
    boot.addLifecycleListener(lifecycleListener1);
    List<IPentahoSystemListener> lifecycleListeners1 = boot.getLifecycleListeners();
    assertEquals(1, lifecycleListeners1.size());
    assertEquals(lifecycleListener1, lifecycleListeners1.get(0));
    assertFalse(TestLifecycleListener.startupCalled);
    assertFalse(TestLifecycleListener.shutdownCalled);
    List<IPentahoSystemListener> lifecycleListeners2 = new ArrayList<IPentahoSystemListener>();
    lifecycleListeners2.add(lifecycleListener2);
    boot.setLifecycleListeners(lifecycleListeners2);
    List<IPentahoSystemListener> lifecycleListeners3 = boot.getLifecycleListeners();
    assertEquals(1, lifecycleListeners3.size());
    assertEquals(lifecycleListener2, lifecycleListeners3.get(0));
    assertEquals(lifecycleListeners2, lifecycleListeners3);
    IPentahoObjectFactory factory = boot.getFactory();
    assertNotNull("object factory is null", factory);
    assertTrue("object factory not definable", factory instanceof IPentahoDefinableObjectFactory);
    assertFalse(boot.isInitialized());
    boolean ok = boot.start();
    assertNull(boot.getSettingsProvider());
    assertTrue(boot.isInitialized());
    assertTrue(ok);
    assertTrue(TestLifecycleListener.startupCalled);
    assertFalse(TestLifecycleListener.shutdownCalled);
    boot.stop();
    assertFalse(boot.isInitialized());
    assertTrue(TestLifecycleListener.startupCalled);
    assertTrue(TestLifecycleListener.shutdownCalled);
}
Also used : PentahoSystemBoot(org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot) IPentahoDefinableObjectFactory(org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 9 with IPentahoObjectFactory

use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project pentaho-platform by pentaho.

the class SolutionContextListener method setObjectFactory.

private void setObjectFactory(final ServletContext context) {
    // $NON-NLS-1$
    final String SYSTEM_FOLDER = "/system";
    // $NON-NLS-1$
    String pentahoObjectFactoryClassName = getServerParameter("pentahoObjectFactory");
    // $NON-NLS-1$
    String pentahoObjectFactoryConfigFile = getServerParameter("pentahoObjectFactoryCfgFile");
    // if web.xml doesnt specify a config file, use the default path.
    if (StringUtils.isEmpty(pentahoObjectFactoryConfigFile)) {
        pentahoObjectFactoryConfigFile = // $NON-NLS-1$
        solutionPath + SYSTEM_FOLDER + "/" + DEFAULT_SPRING_CONFIG_FILE_NAME;
    } else if (-1 == pentahoObjectFactoryConfigFile.indexOf("/")) {
        // $NON-NLS-1$
        pentahoObjectFactoryConfigFile = // $NON-NLS-1$
        solutionPath + SYSTEM_FOLDER + "/" + pentahoObjectFactoryConfigFile;
    }
    // else objectFactoryCreatorCfgFile contains the full path.
    IPentahoObjectFactory pentahoObjectFactory;
    try {
        Class<?> classObject = Class.forName(pentahoObjectFactoryClassName);
        pentahoObjectFactory = (IPentahoObjectFactory) classObject.newInstance();
    } catch (Exception e) {
        String msg = Messages.getInstance().getErrorString("SolutionContextListener.ERROR_0002_BAD_OBJECT_FACTORY", // $NON-NLS-1$
        pentahoObjectFactoryClassName);
        // we were trying to do throw a runtime exception
        throw new RuntimeException(msg, e);
    }
    pentahoObjectFactory.init(pentahoObjectFactoryConfigFile, context);
    PentahoSystem.registerPrimaryObjectFactory(pentahoObjectFactory);
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IOException(java.io.IOException)

Example 10 with IPentahoObjectFactory

use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project pentaho-platform by pentaho.

the class PentahoBoot method enableOlap.

/**
 * Enables the components necessary to create reports
 */
public void enableOlap() {
    IPentahoObjectFactory objectFactory = getFactory();
    if (objectFactory instanceof IPentahoDefinableObjectFactory) {
        // $NON-NLS-1$
        define("connection-MDX", MDXConnection.class.getName(), Scope.LOCAL);
    }
    addLifecycleListener(new MondrianSystemListener());
}
Also used : IPentahoDefinableObjectFactory(org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory) MDXConnection(org.pentaho.platform.plugin.services.connections.mondrian.MDXConnection) MondrianSystemListener(org.pentaho.platform.plugin.action.mondrian.MondrianSystemListener) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory)

Aggregations

IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)30 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)9 Test (org.junit.Test)7 StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)7 IPentahoDefinableObjectFactory (org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory)6 IPentahoObjectReference (org.pentaho.platform.api.engine.IPentahoObjectReference)6 PathBasedSystemSettings (org.pentaho.platform.engine.core.system.PathBasedSystemSettings)6 ArrayList (java.util.ArrayList)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)5 PentahoSystemBoot (org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 HashSet (java.util.HashSet)3 ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)3 ApplicationContext (org.springframework.context.ApplicationContext)3 File (java.io.File)2 Map (java.util.Map)2 Properties (java.util.Properties)2 IConfiguration (org.pentaho.platform.api.engine.IConfiguration)2 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)2