diff options
author | Ganesh Chandrasekaran <ganesh.c@samsung.com> | 2018-07-16 16:08:08 +0900 |
---|---|---|
committer | Ganesh Chandrasekaran <ganesh.c@samsung.com> | 2018-07-16 16:24:56 +0900 |
commit | aeeba1d69f0498808252d5555b06b8fb6cae9269 (patch) | |
tree | e2fedca5c0231237d6d5c853b8e9aa81dde5d313 /saltstack-adapter/saltstack-adapter-provider/src/main/java | |
parent | 3323c0829fa0492a5c7b3544a83cc24412c9934c (diff) |
Saltstack sample server config doc
Issue-ID: CCSDK-361
Change-Id: I6a5407d7359dd84ea5fb71d5c7fab417abd31c55
Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
Diffstat (limited to 'saltstack-adapter/saltstack-adapter-provider/src/main/java')
4 files changed, 45 insertions, 20 deletions
diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java index cc4ce95c1..3469103b5 100644 --- a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java +++ b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java @@ -84,8 +84,8 @@ public class ConnectionBuilder { * @param cmd Commands to execute * @return command execution status */ - public SaltstackResult connectNExecute(String cmd) throws IOException { - return connectNExecute(cmd, -1, -1); + public SaltstackResult connectNExecute(String cmd, long execTimeout) throws IOException { + return connectNExecute(cmd, -1, -1, execTimeout); } /** @@ -98,12 +98,16 @@ public class ConnectionBuilder { * @param retryCount number of count retry to make a SSH connection. * @return command execution status */ - public SaltstackResult connectNExecute(String cmd, int retryCount, int retryDelay) + public SaltstackResult connectNExecute(String cmd, int retryCount, int retryDelay, long execTimeout) throws IOException{ SaltstackResult result = new SaltstackResult(); OutputStream out = null; OutputStream errs = null; + if (execTimeout >= 0) { + sshConnection.setExecTimeout(execTimeout); + } + try { if (retryCount != -1) { result = sshConnection.connectWithRetry(retryCount, retryDelay); @@ -117,7 +121,7 @@ public class ConnectionBuilder { String errFilePath = "/tmp/" + RandomStringUtils.random(5, true, true); out = new FileOutputStream(outFilePath); errs = new FileOutputStream(errFilePath); - result = sshConnection.execCommand(cmd, out, errs); + result = sshConnection.execCommand(cmd, out, errs, result); sshConnection.disconnect(); if (result.getSshExitStatus() != 0) { return sortExitStatus(result.getSshExitStatus(), errFilePath, cmd); diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java index 0b6a5bb22..e4bceb5ba 100644 --- a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java +++ b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java @@ -318,7 +318,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { reqID = messageProcessor.reqId(params); String commandToExecute = messageProcessor.reqCmd(params); slsExec = messageProcessor.reqIsSLSExec(params); - testResult = execCommand(ctx, params, commandToExecute); + testResult = execCommand(ctx, params, commandToExecute, -1); testResult = messageProcessor.parseResponse(ctx, reqID, testResult, slsExec); checkResponseStatus(testResult, ctx, reqID, slsExec); } catch (IOException e) { @@ -344,8 +344,9 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { reqID = messageProcessor.reqId(params); String slsName = messageProcessor.reqSlsName(params); String applyTo = messageProcessor.reqApplyToDevices(params); + long execTimeout = messageProcessor.reqExecTimeout(params); String commandToExecute = putToCommands(slsName, applyTo); - testResult = execCommand(ctx, params, commandToExecute); + testResult = execCommand(ctx, params, commandToExecute, execTimeout); testResult = messageProcessor.parseResponse(ctx, reqID, testResult, true); checkResponseStatus(testResult, ctx, reqID, true); } catch (IOException e) { @@ -371,8 +372,9 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { reqID = messageProcessor.reqId(params); String slsFile = messageProcessor.reqSlsFile(params); String applyTo = messageProcessor.reqApplyToDevices(params); + long execTimeout = messageProcessor.reqExecTimeout(params); String commandToExecute = putToCommands(ctx, slsFile, applyTo); - testResult = execCommand(ctx, params, commandToExecute); + testResult = execCommand(ctx, params, commandToExecute, execTimeout); testResult = messageProcessor.parseResponse(ctx, reqID, testResult, true); checkResponseStatus(testResult, ctx, reqID, true); } catch (IOException e) { @@ -394,7 +396,8 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { } - public SaltstackResult execCommand(SvcLogicContext ctx, Map<String, String> params, String commandToExecute) + public SaltstackResult execCommand(SvcLogicContext ctx, Map<String, String> params, String commandToExecute, + long execTimeout) throws SvcLogicException{ SaltstackResult testResult = new SaltstackResult(); @@ -403,13 +406,13 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { int retryDelay = Integer.parseInt(params.get(CONNECTION_RETRY_DELAY)); int retryCount = Integer.parseInt(params.get(CONNECTION_RETRY_COUNT)); if (!testMode) { - testResult = sshClient.connectNExecute(commandToExecute, retryCount, retryDelay); + testResult = sshClient.connectNExecute(commandToExecute, retryCount, retryDelay, execTimeout); } else { testResult = testServer.mockReqExec(params); } } else { if (!testMode) { - testResult = sshClient.connectNExecute(commandToExecute); + testResult = sshClient.connectNExecute(commandToExecute, execTimeout); } else { testResult = testServer.mockReqExec(params); } diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java index 96ed7d2d6..fd66eb100 100644 --- a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java +++ b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java @@ -50,6 +50,7 @@ class SshConnection { public static final int DEFAULT_CONNECTION_RETRY_COUNT = 5; private static final EELFLogger logger = EELFManager.getInstance().getApplicationLogger(); private static final long AUTH_TIMEOUT = 60000; + //TODO : change back to 120000 private static final long EXEC_TIMEOUT = 120000; private String host; private int port; @@ -165,16 +166,17 @@ class SshConnection { this.timeout = timeout; } - public SaltstackResult execCommand(String cmd, OutputStream out, OutputStream err) { - return execCommand(cmd, out, err, false); + public SaltstackResult execCommand(String cmd, OutputStream out, OutputStream err, SaltstackResult result ) { + return execCommand(cmd, out, err, false, result); } - public SaltstackResult execCommandWithPty(String cmd, OutputStream out) { - return execCommand(cmd, out, out, true); + public SaltstackResult execCommandWithPty(String cmd, OutputStream out, SaltstackResult result ) { + return execCommand(cmd, out, out, true, result); } - private SaltstackResult execCommand(String cmd, OutputStream out, OutputStream err, boolean usePty) { - SaltstackResult result = new SaltstackResult(); + private SaltstackResult execCommand(String cmd, OutputStream out, OutputStream err, + boolean usePty, SaltstackResult result ) { + try { if (logger.isDebugEnabled()) { logger.debug("SSH: executing command"); diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java index 0a6e4eb89..16ab8dca4 100644 --- a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java +++ b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java @@ -72,6 +72,7 @@ public class SaltstackMessageParser { private static final String SLS_FILE_LOCATION = "slsFile"; private static final String SLS_NAME = "slsName"; private static final String MINION_TO_APPLY = "applyTo"; + private static final String EXEC_TIMEOUT_TO_APPLY = "execTimeout"; private static final String LOCAL_PARAMETERS_OPT_KEY = "LocalParameters"; private static final String FILE_PARAMETERS_OPT_KEY = "FileParameters"; @@ -240,6 +241,21 @@ public class SaltstackMessageParser { /** * Method that validates that the Map has enough information * to query Saltstack server for a result. If so, it returns + * the appropriate minions/vnfc to execute the SLS file to. + */ + public long reqExecTimeout(Map<String, String> params) { + + if (params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY) == null) { + return -1; + } else if (params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY).equalsIgnoreCase("")) { + return -1; + } + return Long.parseLong(params.get(SaltstackMessageParser.EXEC_TIMEOUT_TO_APPLY)); + } + + /** + * Method that validates that the Map has enough information + * to query Saltstack server for a result. If so, it returns * the appropriate IsSLSExec true or false. */ public boolean reqIsSLSExec(Map<String, String> params) throws SvcLogicException { @@ -333,10 +349,10 @@ public class SaltstackMessageParser { if (slsExec) { if (!retCodeFound) return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), - "error in parsing response Json after SLS file execution in server"); + "error in executing configuration at the server"); if (!executionStatus) return new SaltstackResult(SaltstackResultCodes.COMMAND_EXEC_FAILED_STATUS.getValue(), - "error in parsing response Json after SLS file execution in server"); + "error in executing configuration at the server"); } saltstackResult.setStatusCode(SaltstackResultCodes.FINAL_SUCCESS.getValue()); return saltstackResult; @@ -355,8 +371,8 @@ public class SaltstackMessageParser { String name = (String) key; String value = prop.getProperty(name); if (value != null && value.trim().length() > 0) { - ctx.setAttribute(pfx + name, value.trim()); - LOGGER.info("+++ " + pfx + name + ": [" + value + "]"); + ctx.setAttribute(pfx + "." + name, value.trim()); + LOGGER.info("+++ " + pfx + "." + name + ": [" + value + "]"); } } } catch (Exception e) { |