use of org.apache.commons.lang.text.StrSubstitutor in project kylo by Teradata.
the class PropertyExpressionResolver method replaceAll.
public String replaceAll(String str, String replacement) {
if (str != null) {
StrLookup lookup = new StrLookup() {
@Override
public String lookup(String key) {
return replacement;
}
};
StrSubstitutor ss = new StrSubstitutor(lookup);
return ss.replace(str);
}
return null;
}
use of org.apache.commons.lang.text.StrSubstitutor in project kylo by Teradata.
the class PropertyExpressionResolver method resolveVariables.
/**
* Resolves the variables in the value of the specified property.
*
* @param property the property
* @param metadata the feed
* @return the result of the transformation
*/
private ResolveResult resolveVariables(@Nonnull final NifiProperty property, @Nonnull final FeedMetadata metadata) {
// Filter blank values
final String value = property.getValue();
if (StringUtils.isBlank(value)) {
return new ResolveResult(false, false);
}
final boolean[] hasConfig = { false };
final boolean[] isModified = { false };
StrLookup resolver = new StrLookup() {
@Override
public String lookup(String variable) {
// Resolve configuration variables
final String configValue = getConfigurationPropertyValue(property, variable);
if (configValue != null && property.getValue() != null && !property.getValue().equalsIgnoreCase(configValue)) {
hasConfig[0] = true;
isModified[0] = true;
// if this is the first time we found the config var, set the template value correctly
if (!property.isContainsConfigurationVariables()) {
property.setTemplateValue(property.getValue());
property.setContainsConfigurationVariables(true);
}
return configValue;
}
// Resolve metadata variables
try {
final String metadataValue = getMetadataPropertyValue(metadata, variable);
if (metadataValue != null) {
isModified[0] = true;
return metadataValue;
}
} catch (Exception e) {
log.error("Unable to resolve variable: " + variable, e);
}
return null;
}
};
StrSubstitutor ss = new StrSubstitutor(resolver);
ss.setEnableSubstitutionInVariables(true);
// escape
String val = StringUtils.trim(ss.replace(value));
// fix
property.setValue(val);
return new ResolveResult(hasConfig[0], isModified[0]);
}
use of org.apache.commons.lang.text.StrSubstitutor in project mycore by MyCoRe-Org.
the class MCRCommandLineInterface method expandCommand.
/**
* Expands variables in a command.
* Replaces any variables in form ${propertyName} to the value defined by {@link MCRConfiguration#getString(String)}.
* If the property is not defined not variable replacement takes place.
* @param command a CLI command that should be expanded
* @return expanded command
*/
public static String expandCommand(final String command) {
StrSubstitutor strSubstitutor = new StrSubstitutor(MCRConfiguration.instance().getPropertiesMap());
String expandedCommand = strSubstitutor.replace(command);
if (!expandedCommand.equals(command)) {
LOGGER.info("{} --> {}", command, expandedCommand);
}
return expandedCommand;
}
use of org.apache.commons.lang.text.StrSubstitutor in project apex-core by apache.
the class LaunchContainerRunnable method getChildVMCommand.
/**
* Build the command to launch the child VM in the container
*
* @param jvmID
* @return
*/
public List<CharSequence> getChildVMCommand(String jvmID) {
List<CharSequence> vargs = new ArrayList<>(8);
if (!StringUtils.isBlank(System.getenv(Environment.JAVA_HOME.key()))) {
// node manager provides JAVA_HOME
vargs.add(Environment.JAVA_HOME.$() + "/bin/java");
} else {
vargs.add("java");
}
String jvmOpts = dag.getAttributes().get(LogicalPlan.CONTAINER_JVM_OPTIONS);
if (jvmOpts == null) {
if (dag.isDebug()) {
vargs.add(JAVA_REMOTE_DEBUG_OPTS);
}
} else {
Map<String, String> params = new HashMap<>();
params.put("applicationId", Integer.toString(container.getId().getApplicationAttemptId().getApplicationId().getId()));
params.put("containerId", Integer.toString(container.getId().getId()));
StrSubstitutor sub = new StrSubstitutor(params, "%(", ")");
vargs.add(sub.replace(jvmOpts));
if (dag.isDebug() && !jvmOpts.contains("-agentlib:jdwp=")) {
vargs.add(JAVA_REMOTE_DEBUG_OPTS);
}
}
List<DAG.OperatorMeta> operatorMetaList = Lists.newArrayList();
int bufferServerMemory = 0;
for (PTOperator operator : sca.getContainer().getOperators()) {
bufferServerMemory += operator.getBufferServerMemory();
operatorMetaList.add(operator.getOperatorMeta());
}
Context.ContainerOptConfigurator containerOptConfigurator = dag.getAttributes().get(LogicalPlan.CONTAINER_OPTS_CONFIGURATOR);
jvmOpts = containerOptConfigurator.getJVMOptions(operatorMetaList);
jvmOpts = parseJvmOpts(jvmOpts, ((long) bufferServerMemory) * MB_TO_B);
LOG.info("Jvm opts {} for container {}", jvmOpts, container.getId());
vargs.add(jvmOpts);
Path childTmpDir = new Path(Environment.PWD.$(), YarnConfiguration.DEFAULT_CONTAINER_TEMP_DIR);
vargs.add(String.format("-D%s=%s", StreamingContainer.PROP_APP_PATH, dag.assertAppPath()));
vargs.add("-Djava.io.tmpdir=" + childTmpDir);
vargs.add(String.format("-D%scid=%s", StreamingApplication.DT_PREFIX, jvmID));
vargs.add("-Dhadoop.root.logger=" + (dag.isDebug() ? "DEBUG" : "INFO") + ",RFA");
vargs.add("-Dhadoop.log.dir=" + ApplicationConstants.LOG_DIR_EXPANSION_VAR);
StramClientUtils.addAttributeToArgs(LogicalPlan.APPLICATION_NAME, dag, vargs);
StramClientUtils.addAttributeToArgs(LogicalPlan.LOGGER_APPENDER, dag, vargs);
String loggersLevel = System.getProperty(StramUtils.DT_LOGGERS_LEVEL);
if (loggersLevel != null) {
vargs.add(String.format("-D%s=%s", StramUtils.DT_LOGGERS_LEVEL, loggersLevel));
}
// Add main class and its arguments
// main of Child
vargs.add(StreamingContainer.class.getName());
vargs.add("1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stdout");
vargs.add("2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stderr");
// Final commmand
StringBuilder mergedCommand = new StringBuilder(256);
for (CharSequence str : vargs) {
mergedCommand.append(str).append(" ");
}
List<CharSequence> vargsFinal = new ArrayList<>(1);
vargsFinal.add(mergedCommand.toString());
return vargsFinal;
}
use of org.apache.commons.lang.text.StrSubstitutor in project openlmis-stockmanagement by OpenLMIS.
the class StockoutNotifier method notifyStockEditors.
/**
* Notify user with "Edit stock inventories" right for the facility/program that
* facility has stocked out of a product.
*
* @param stockCard StockCard for a product
*/
public void notifyStockEditors(StockCard stockCard) {
Collection<UserDto> recipients = getEditors(stockCard);
String subject = getMessage(EMAIL_ACTION_REQUIRED_SUBJECT);
String content = getMessage(EMAIL_ACTION_REQUIRED_CONTENT);
Map<String, String> valuesMap = getValuesMap(stockCard);
StrSubstitutor sub = new StrSubstitutor(valuesMap);
for (UserDto recipient : recipients) {
if (recipient.getHomeFacilityId().equals(stockCard.getFacilityId()) && canBeNotified(recipient)) {
valuesMap.put("username", recipient.getUsername());
notificationService.notify(recipient, sub.replace(subject), sub.replace(content));
}
}
}
Aggregations