use of com.sun.enterprise.universal.glassfish.TokenResolver in project Payara by payara.
the class UpdateNodeCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Logger logger = context.getLogger();
Node node = nodes.getNode(name);
if (node == null) {
// node doesn't exist
String msg = Strings.get("noSuchNode", name);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
// validate installdir if passed and running on localhost
if (StringUtils.ok(nodehost)) {
if (NetUtils.isThisHostLocal(nodehost) && StringUtils.ok(installdir)) {
TokenResolver resolver = null;
// Create a resolver that can replace system properties in strings
Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
resolver = new TokenResolver(systemPropsMap);
String resolvedInstallDir = resolver.resolve(installdir);
File actualInstallDir = new File(resolvedInstallDir + "/" + NodeUtils.LANDMARK_FILE);
if (!actualInstallDir.exists()) {
report.setMessage(Strings.get("invalid.installdir", installdir));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
// like the install directory or node directory.
if (node.nodeInUse()) {
String badparam = null;
String configNodedir = node.getNodeDir();
String configInstalldir = node.getInstallDir();
if (!allowableChange(nodedir, configNodedir)) {
badparam = "nodedir";
}
if (!allowableChange(installdir, configInstalldir)) {
badparam = "installdir";
}
if (StringUtils.ok(badparam)) {
String msg = Strings.get("noUpdate.nodeInUse", name, badparam);
logger.warning(msg);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(msg);
return;
}
}
try {
updateNodeElement(name);
} catch (TransactionFailure e) {
logger.warning("failed.to.update.node " + name);
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
report.setMessage(e.getMessage());
}
}
use of com.sun.enterprise.universal.glassfish.TokenResolver in project Payara by payara.
the class GFLauncher method resolveAllTokens.
private void resolveAllTokens() {
// resolve jvm-options against:
// 1. itself
// 2. <system-property>'s from domain.xml
// 3. system properties -- essential there is, e.g. "${path.separator}" in domain.xml
// 4. asenvProps
// 5. env variables
// i.e. add in reverse order to get the precedence right
Map<String, String> all = new HashMap<String, String>();
Map<String, String> envProps = System.getenv();
Map<String, String> sysProps = CollectionUtils.propertiesToStringMap(System.getProperties());
// TODO: Uncomment when admin password processing & aliasing is sorted out.
// Map<String, String> passwordAliases = new HashMap<String, String>();
// try {
// String masterPassword = "changeit";
// if (IdentityManager.getMasterPassword() != null)
// masterPassword = IdentityManager.getMasterPassword();
// PasswordAdapter pa = new PasswordAdapter(masterPassword.toCharArray());
// Enumeration e = pa.getAliases();
// if (e.hasMoreElements()) {
// String alias = (String) e.nextElement();
// passwordAliases.put(alias, pa.getPasswordForAlias(alias));
// }
// } catch (Exception e) {
// // TODO: ignore now. Defaults to not resolving password aliases
// }
// all.putAll(passwordAliases);
all.putAll(envProps);
all.putAll(asenvProps);
all.putAll(sysProps);
all.put(SystemPropertyConstants.SERVER_NAME, getInfo().getInstanceName());
all.putAll(sysPropsFromXml);
all.putAll(jvmOptions.getCombinedMap());
all.putAll(profiler.getConfig());
TokenResolver resolver = new TokenResolver(all);
resolver.resolve(jvmOptions.xProps);
resolver.resolve(jvmOptions.xxProps);
resolver.resolve(jvmOptions.plainProps);
resolver.resolve(jvmOptions.sysProps);
resolver.resolve(javaConfig.getMap());
resolver.resolve(profiler.getConfig());
resolver.resolve(debugOptions);
// resolver.resolve(sysPropsFromXml);
logFilename = resolver.resolve(logFilename);
adminFileRealmKeyFile = resolver.resolve(adminFileRealmKeyFile);
// TODO ?? Resolve sysPropsFromXml ???
}
use of com.sun.enterprise.universal.glassfish.TokenResolver in project Payara by payara.
the class AppClientFacade method replaceTokensForParsing.
private static InputSource replaceTokensForParsing(final Reader reader) throws FileNotFoundException, IOException, URISyntaxException {
char[] buffer = new char[1024];
CharArrayWriter writer = new CharArrayWriter();
int charsRead;
while ((charsRead = reader.read(buffer)) != -1) {
writer.write(buffer, 0, charsRead);
}
writer.close();
reader.close();
Map<String, String> mapping = new HashMap<String, String>();
Properties props = System.getProperties();
for (Enumeration e = props.propertyNames(); e.hasMoreElements(); ) {
String propName = (String) e.nextElement();
mapping.put(propName, props.getProperty(propName));
}
TokenResolver resolver = new TokenResolver(mapping);
String configWithTokensReplaced = resolver.resolve(writer.toString());
InputSource inputSource = new InputSource(new StringReader(configWithTokensReplaced));
return inputSource;
}
use of com.sun.enterprise.universal.glassfish.TokenResolver in project Payara by payara.
the class CreateNodeConfigCommand method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
// validate installdir if passed and running on localhost
if (StringUtils.ok(nodehost)) {
if (NetUtils.isThisHostLocal(nodehost) && StringUtils.ok(installdir)) {
TokenResolver resolver = null;
// Create a resolver that can replace system properties in strings
Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
resolver = new TokenResolver(systemPropsMap);
String resolvedInstallDir = resolver.resolve(installdir);
File actualInstallDir = new File(resolvedInstallDir + "/" + NodeUtils.LANDMARK_FILE);
if (!actualInstallDir.exists()) {
report.setMessage(Strings.get("invalid.installdir", installdir));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
}
}
CommandInvocation ci = cr.getCommandInvocation("_create-node", report, context.getSubject());
ParameterMap map = new ParameterMap();
map.add("DEFAULT", name);
if (StringUtils.ok(nodedir))
map.add(NodeUtils.PARAM_NODEDIR, nodedir);
if (StringUtils.ok(installdir))
map.add(NodeUtils.PARAM_INSTALLDIR, installdir);
if (StringUtils.ok(nodehost))
map.add(NodeUtils.PARAM_NODEHOST, nodehost);
map.add(NodeUtils.PARAM_TYPE, "CONFIG");
ci.parameters(map);
ci.execute();
NodeUtils.sanitizeReport(report);
}
use of com.sun.enterprise.universal.glassfish.TokenResolver in project Payara by payara.
the class UpdateNodeCommand method allowableChange.
/**
* If the node is in use, is it OK to change currentvalue to newvalue?
*/
private static boolean allowableChange(String newvalue, String currentvalue) {
// If the new value is not specified, then we aren't changing anything
if (newvalue == null) {
return true;
}
// that was created without one.
if (!StringUtils.ok(currentvalue)) {
return true;
}
// If the values are the same, then we aren't changing anything.
if (newvalue.equals(currentvalue)) {
return true;
}
if (newvalue.contains("$") || currentvalue.contains("$")) {
// One or both of the values may contain an unexpanded
// property. Expand them then compare
Map<String, String> systemPropsMap = new HashMap<String, String>((Map) (System.getProperties()));
TokenResolver resolver = new TokenResolver(systemPropsMap);
newvalue = resolver.resolve(newvalue);
currentvalue = resolver.resolve(currentvalue);
return newvalue.equals(currentvalue);
}
// Values don't match.
return false;
}
Aggregations