public SshResult runScriptWithToken(String scriptName, Map token) { String scriptPath = PathUtil.findFileOnClassPath(scriptName, true).getAbsolutePath(); if (token == null) { token = new HashMap(); } String contents = null; try { contents = FileUtils.readFileToString(new File(scriptPath)); } catch (IOException e) { throw new RuntimeException(e); } String script = s(contents).formatByMap(token); return runScript(script); }
ScriptRunner(String script) { String remoteScript = ln( "/bin/bash << EOF", "cat << EOF1 > {remotePath}", "{scriptContent}", "EOF1", "/bin/bash {remotePath} 1>{stdout} 2>{stderr}", "ret=$?", "test -f {stdout} && cat {stdout}", "test -f {stderr} && cat {stderr} 1>&2", "rm -f {remotePath}", "rm -f {stdout}", "rm -f {stderr}", "exit $ret", "EOF" ).formatByMap(map(e("remotePath", String.format("/tmp/%s", UUID.randomUUID().toString())), e("scriptContent", script), e("stdout", String.format("/tmp/%s", UUID.randomUUID().toString())), e("stderr", String.format("/tmp/%s", UUID.randomUUID().toString())) )); scriptCommand = createCommand(remoteScript); }
public static String i18n(String str, Map<String, String> args) { Map<String, String> nargs = new HashMap<>(); args.forEach((k, v) -> nargs.put(k, toI18nString(v))); return ln(toI18nString(str)).formatByMap(nargs); }
agentYamlContent = ln(agentYamlContent).formatByMap(map( e("remoteRoot", AgentConstant.DST_ANSIBLE_ROOT), e("srcRoot", srcRootFolder),
var.put("foreignVO", foreignVOClass.getSimpleName()); if (where.isEmpty()) { return s("{entity}.{primaryKey} in (select {subEntity}.{foreignKey} from {foreignVO} {subEntity})").formatByMap(var); } else { var.put("condition", StringUtils.join(where, " and ").trim()); return s("{entity}.{primaryKey} in (select {subEntity}.{foreignKey} from {foreignVO} {subEntity} where {condition})").formatByMap(var); return s("{entity}.{foreignKey} in (select {expandedEntity}.{expandedKey} from {expandedVO} {expandedEntity})").formatByMap(var); } else { var.put("condition", StringUtils.join(where, " and ").trim()); return s("{entity}.{foreignKey} in (select {expandedEntity}.{expandedKey} from {expandedVO} {expandedEntity} where {condition})").formatByMap(var);
return s("{entity}.{primaryKey} not in (select {subEntity}.{foreignKey} from {foreignVO} {subEntity} where {condition})").formatByMap(var); } else { var.put("condition", formatSql(foreignVOClass.getSimpleName().toLowerCase(), refName, op)); return s("{entity}.{primaryKey} in (select {subEntity}.{foreignKey} from {foreignVO} {subEntity} where {condition})").formatByMap(var);
String url; if (dbUrl.contains("{database}")) { url = ln(dbUrl).formatByMap( map(e("database", "zstack")) ); String url; if (dbUrl.contains("{database}")) { url = ln(dbUrl).formatByMap( map(e("database", "zstack_rest")) );
"fi", "exit 0" ).formatByMap(map( e("pubkey", asf.getPublicKey()) ));
String srcScript = String.format("zstack-script-%s", UUID.randomUUID().toString()); scriptFile = new File(PathUtil.join(PathUtil.getFolderUnderZStackHomeFolder("temp-scripts"), srcScript)); scriptContent = s(contents).formatByMap(token); "exit $ret", "EOF" ).formatByMap(map(e("remotePath", String.format("/tmp/%s", UUID.randomUUID().toString())), e("scriptContent", scriptContent), e("parameters", parameters),
void init() { evtf.on(s(GlobalConfigCanonicalEvents.UPDATE_EVENT_PATH).formatByMap(map( e("category", category), e("name", name) )), new EventCallback() { @Override public void run(Map tokens, Object data) { String nodeUuid = (String) tokens.get("nodeUuid"); if (Platform.getManagementServerId().equals(nodeUuid)) { return; } UpdateEvent evt = (UpdateEvent)data; update(evt.getNewValue(), false); logger.info(String.format("GlobalConfig[category: %s, name: %s] was updated in other management node[uuid:%s]," + "in line with that change, updated ours. %s --> %s", category, name, nodeUuid, evt.getOldValue(), value)); } }); }
public String instantiateTag(Map tokens) { return s(tagFormat).formatByMap(tokens); }
private String makeUpdateEventPath() { return s(GlobalConfigCanonicalEvents.UPDATE_EVENT_PATH).formatByMap(map( e("nodeUuid", Platform.getManagementServerId()), e("category", category), e("name", name) )); }
@Override public String toString() { return ln(template).formatByMap(tokens); } }