Search in sources :

Example 1 with StreamingAppFactory

use of org.apache.apex.engine.util.StreamingAppFactory in project apex-core by apache.

the class StramAppLauncher method findAppConfigClasses.

/**
   * Scan the application jar file entries for configuration classes.
   * This needs to occur in a class loader with access to the application dependencies.
   */
private void findAppConfigClasses(List<String> classFileNames) {
    URLClassLoader cl = URLClassLoader.newInstance(launchDependencies.toArray(new URL[launchDependencies.size()]));
    for (final String classFileName : classFileNames) {
        final String className = classFileName.replace('/', '.').substring(0, classFileName.length() - 6);
        try {
            final Class<?> clazz = cl.loadClass(className);
            if (!Modifier.isAbstract(clazz.getModifiers()) && StreamingApplication.class.isAssignableFrom(clazz)) {
                final AppFactory appConfig = new StreamingAppFactory(classFileName, clazz) {

                    @Override
                    public LogicalPlan createApp(LogicalPlanConfiguration planConfig) {
                        // load class from current context class loader
                        Class<? extends StreamingApplication> c = StramUtils.classForName(className, StreamingApplication.class);
                        StreamingApplication app = StramUtils.newInstance(c);
                        return super.createApp(app, planConfig);
                    }
                };
                appResourceList.add(appConfig);
            }
        } catch (Throwable e) {
            // java.lang.NoClassDefFoundError
            LOG.error("Unable to load class: " + className + " " + e);
        }
    }
}
Also used : LogicalPlanConfiguration(com.datatorrent.stram.plan.logical.LogicalPlanConfiguration) StreamingAppFactory(org.apache.apex.engine.util.StreamingAppFactory) URLClassLoader(java.net.URLClassLoader) StreamingApplication(com.datatorrent.api.StreamingApplication) StreamingAppFactory(org.apache.apex.engine.util.StreamingAppFactory) URL(java.net.URL)

Example 2 with StreamingAppFactory

use of org.apache.apex.engine.util.StreamingAppFactory in project apex-core by apache.

the class YarnAppLauncherImpl method launchApp.

@Override
public YarnAppHandleImpl launchApp(final StreamingApplication app, Configuration conf, Attribute.AttributeMap launchParameters) throws LauncherException {
    if (launchParameters != null) {
        for (Map.Entry<Attribute<?>, Object> entry : launchParameters.entrySet()) {
            String property = propMapping.get(entry.getKey());
            if (property != null) {
                setConfiguration(conf, property, entry.getValue());
            }
        }
    }
    try {
        String name = app.getClass().getName();
        StramAppLauncher appLauncher = new StramAppLauncher(name, conf);
        appLauncher.loadDependencies();
        StreamingAppFactory appFactory = new StreamingAppFactory(name, app.getClass()) {

            @Override
            public LogicalPlan createApp(LogicalPlanConfiguration planConfig) {
                return super.createApp(app, planConfig);
            }
        };
        ApplicationId appId = appLauncher.launchApp(appFactory);
        return new YarnAppHandleImpl(appId);
    } catch (Exception ex) {
        throw new LauncherException(ex);
    }
}
Also used : LogicalPlanConfiguration(com.datatorrent.stram.plan.logical.LogicalPlanConfiguration) StramAppLauncher(com.datatorrent.stram.client.StramAppLauncher) Attribute(com.datatorrent.api.Attribute) StreamingAppFactory(org.apache.apex.engine.util.StreamingAppFactory) ApplicationId(org.apache.hadoop.yarn.api.records.ApplicationId) HashMap(java.util.HashMap) Map(java.util.Map) IOException(java.io.IOException) YarnException(org.apache.hadoop.yarn.exceptions.YarnException)

Example 3 with StreamingAppFactory

use of org.apache.apex.engine.util.StreamingAppFactory in project apex-core by apache.

the class DAGSetupPluginTests method testJavaApplication.

@Test
public void testJavaApplication() {
    Configuration conf = getConfiguration();
    StreamingAppFactory factory = new StreamingAppFactory(Application.class.getName(), Application.class) {

        @Override
        public LogicalPlan createApp(LogicalPlanConfiguration planConfig) {
            Class<? extends StreamingApplication> c = StramUtils.classForName(Application.class.getName(), StreamingApplication.class);
            StreamingApplication app = StramUtils.newInstance(c);
            return super.createApp(app, planConfig);
        }
    };
    LogicalPlan dag = factory.createApp(new LogicalPlanConfiguration(conf));
    validateProperties(dag);
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) StreamingAppFactory(org.apache.apex.engine.util.StreamingAppFactory) StreamingApplication(com.datatorrent.api.StreamingApplication) StreamingApplication(com.datatorrent.api.StreamingApplication) Test(org.junit.Test)

Aggregations

StreamingAppFactory (org.apache.apex.engine.util.StreamingAppFactory)3 StreamingApplication (com.datatorrent.api.StreamingApplication)2 LogicalPlanConfiguration (com.datatorrent.stram.plan.logical.LogicalPlanConfiguration)2 Attribute (com.datatorrent.api.Attribute)1 StramAppLauncher (com.datatorrent.stram.client.StramAppLauncher)1 IOException (java.io.IOException)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Configuration (org.apache.hadoop.conf.Configuration)1 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)1 YarnException (org.apache.hadoop.yarn.exceptions.YarnException)1 Test (org.junit.Test)1