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;
}
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);
}
Aggregations