Search in sources :

Example 1 with PropertyInfo

use of com.datatorrent.stram.client.AppPackage.PropertyInfo in project apex-core by apache.

the class ApexCli method getLaunchAppPackageProperties.

DTConfiguration getLaunchAppPackageProperties(AppPackage ap, ConfigPackage cp, LaunchCommandLineInfo commandLineInfo, String appName) throws Exception {
    DTConfiguration launchProperties = new DTConfiguration();
    List<AppInfo> applications = getAppsFromPackageAndConfig(ap, cp, commandLineInfo.useConfigApps);
    AppInfo selectedApp = null;
    for (AppInfo app : applications) {
        if (app.name.equals(appName)) {
            selectedApp = app;
            break;
        }
    }
    Map<String, PropertyInfo> defaultProperties = selectedApp == null ? ap.getDefaultProperties() : selectedApp.defaultProperties;
    Set<String> requiredProperties = new TreeSet<>(selectedApp == null ? ap.getRequiredProperties() : selectedApp.requiredProperties);
    for (Map.Entry<String, PropertyInfo> entry : defaultProperties.entrySet()) {
        launchProperties.set(entry.getKey(), entry.getValue().getValue(), Scope.TRANSIENT, entry.getValue().getDescription());
        requiredProperties.remove(entry.getKey());
    }
    // settings specified in the user's environment take precedence over defaults in package.
    // since both are merged into a single -conf option below, apply them on top of the defaults here.
    File confFile = new File(StramClientUtils.getUserDTDirectory(), StramClientUtils.DT_SITE_XML_FILE);
    if (confFile.exists()) {
        Configuration userConf = new Configuration(false);
        userConf.addResource(new Path(confFile.toURI()));
        Iterator<Entry<String, String>> it = userConf.iterator();
        while (it.hasNext()) {
            Entry<String, String> entry = it.next();
            // filter relevant entries
            String key = entry.getKey();
            if (key.startsWith(StreamingApplication.DT_PREFIX) || key.startsWith(StreamingApplication.APEX_PREFIX)) {
                launchProperties.set(key, entry.getValue(), Scope.TRANSIENT, null);
                requiredProperties.remove(key);
            }
        }
    }
    if (commandLineInfo.apConfigFile != null) {
        DTConfiguration givenConfig = new DTConfiguration();
        givenConfig.loadFile(new File(ap.tempDirectory() + "/conf/" + commandLineInfo.apConfigFile));
        for (Map.Entry<String, String> entry : givenConfig) {
            launchProperties.set(entry.getKey(), entry.getValue(), Scope.TRANSIENT, null);
            requiredProperties.remove(entry.getKey());
        }
    }
    if (cp != null) {
        Map<String, String> properties = cp.getProperties(appName);
        for (Map.Entry<String, String> entry : properties.entrySet()) {
            launchProperties.set(entry.getKey(), entry.getValue(), Scope.TRANSIENT, null);
            requiredProperties.remove(entry.getKey());
        }
    } else if (commandLineInfo.configFile != null) {
        DTConfiguration givenConfig = new DTConfiguration();
        givenConfig.loadFile(new File(commandLineInfo.configFile));
        for (Map.Entry<String, String> entry : givenConfig) {
            launchProperties.set(entry.getKey(), entry.getValue(), Scope.TRANSIENT, null);
            requiredProperties.remove(entry.getKey());
        }
    }
    if (commandLineInfo.overrideProperties != null) {
        for (Map.Entry<String, String> entry : commandLineInfo.overrideProperties.entrySet()) {
            launchProperties.set(entry.getKey(), entry.getValue(), Scope.TRANSIENT, null);
            requiredProperties.remove(entry.getKey());
        }
    }
    // now look at whether it is in default configuration
    for (Map.Entry<String, String> entry : conf) {
        if (StringUtils.isNotBlank(entry.getValue())) {
            requiredProperties.remove(entry.getKey());
        }
    }
    if (!requiredProperties.isEmpty()) {
        throw new CliException("Required properties not set: " + StringUtils.join(requiredProperties, ", "));
    }
    //StramClientUtils.evalProperties(launchProperties);
    return launchProperties;
}
Also used : Path(org.apache.hadoop.fs.Path) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) DTConfiguration(com.datatorrent.stram.client.DTConfiguration) LogicalPlanConfiguration(com.datatorrent.stram.plan.logical.LogicalPlanConfiguration) DTConfiguration(com.datatorrent.stram.client.DTConfiguration) AppInfo(com.datatorrent.stram.client.AppPackage.AppInfo) Entry(java.util.Map.Entry) TreeSet(java.util.TreeSet) PropertyInfo(com.datatorrent.stram.client.AppPackage.PropertyInfo) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) File(java.io.File)

Example 2 with PropertyInfo

use of com.datatorrent.stram.client.AppPackage.PropertyInfo in project apex-core by apache.

the class AppPackageTest method testPropertyInfoSerializer.

@Test
public void testPropertyInfoSerializer() throws JsonGenerationException, JsonMappingException, IOException {
    AppPackage.PropertyInfo propertyInfo = new AppPackage.PropertyInfo("test-value", "test-description");
    JSONSerializationProvider jomp = new JSONSerializationProvider();
    jomp.addSerializer(PropertyInfo.class, new AppPackage.PropertyInfoSerializer(false));
    String result = jomp.getContext(null).writeValueAsString(propertyInfo);
    Assert.assertEquals("\"test-value\"", result);
    jomp = new JSONSerializationProvider();
    jomp.addSerializer(PropertyInfo.class, new AppPackage.PropertyInfoSerializer(true));
    result = jomp.getContext(null).writeValueAsString(propertyInfo);
    Assert.assertEquals("{\"value\":\"test-value\",\"description\":\"test-description\"}", result);
}
Also used : PropertyInfo(com.datatorrent.stram.client.AppPackage.PropertyInfo) JSONSerializationProvider(com.datatorrent.stram.util.JSONSerializationProvider) PropertyInfo(com.datatorrent.stram.client.AppPackage.PropertyInfo) Test(org.junit.Test)

Aggregations

PropertyInfo (com.datatorrent.stram.client.AppPackage.PropertyInfo)2 AppInfo (com.datatorrent.stram.client.AppPackage.AppInfo)1 DTConfiguration (com.datatorrent.stram.client.DTConfiguration)1 LogicalPlanConfiguration (com.datatorrent.stram.plan.logical.LogicalPlanConfiguration)1 JSONSerializationProvider (com.datatorrent.stram.util.JSONSerializationProvider)1 File (java.io.File)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)1 Test (org.junit.Test)1