aboutsummaryrefslogtreecommitdiffstats
path: root/saltstack-adapter/saltstack-adapter-provider/src/main
diff options
context:
space:
mode:
authorGanesh Chandrasekaran <ganesh.c@samsung.com>2018-07-23 14:27:22 +0900
committerGanesh Chandrasekaran <ganesh.c@samsung.com>2018-07-23 14:27:37 +0900
commit021cae43d3b22dcbd41e7b34ca4215c167714ab4 (patch)
tree7ef08cca0a2a169fc7456c7416e3557969cd8582 /saltstack-adapter/saltstack-adapter-provider/src/main
parente70da25135855b88571b19c108089b74181996a6 (diff)
Use ByteStream instead of FileStream
Issue-ID: CCSDK-393 Change-Id: Id004f0bce1768e00f3e326efc204532acdb22546 Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
Diffstat (limited to 'saltstack-adapter/saltstack-adapter-provider/src/main')
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/ConnectionBuilder.java51
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SaltstackAdapterImpl.java45
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/impl/SshConnection.java8
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackMessageParser.java57
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java8
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java24
-rwxr-xr-xsaltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml13
-rw-r--r--saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties5
8 files changed, 99 insertions, 112 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 f6b3b70c..6e5feb4e 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
@@ -26,18 +26,11 @@ package org.onap.ccsdk.sli.adaptors.saltstack.impl;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import org.apache.commons.io.IOUtils;
-import org.apache.commons.lang.RandomStringUtils;
import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResult;
import org.onap.ccsdk.sli.adaptors.saltstack.model.SaltstackResultCodes;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.OutputStream;
-import java.io.StringWriter;
/**
* Returns a custom SSH client
@@ -98,11 +91,11 @@ public class ConnectionBuilder {
* @return command execution status
*/
public SaltstackResult connectNExecute(String cmd, int retryCount, int retryDelay, long execTimeout)
- throws IOException{
+ throws IOException {
SaltstackResult result = new SaltstackResult();
- OutputStream out = null;
- OutputStream errs = null;
+ ByteArrayOutputStream out = null;
+ ByteArrayOutputStream errs = null;
if (execTimeout >= 0) {
sshConnection.setExecTimeout(execTimeout);
}
@@ -116,69 +109,59 @@ public class ConnectionBuilder {
if (result.getStatusCode() != SaltstackResultCodes.SUCCESS.getValue()) {
return result;
}
- String outFilePath = "/tmp/" + RandomStringUtils.random(5, true, true);
- String errFilePath = "/tmp/" + RandomStringUtils.random(5, true, true);
- out = new FileOutputStream(outFilePath);
- errs = new FileOutputStream(errFilePath);
+ out = new ByteArrayOutputStream();
+ errs = new ByteArrayOutputStream();
result = sshConnection.execCommand(cmd, out, errs, result);
sshConnection.disconnect();
if (result.getSshExitStatus() != 0) {
- return sortExitStatus(result.getSshExitStatus(), errFilePath, cmd);
+ return sortExitStatus(result.getSshExitStatus(), errs.toString(), cmd);
}
if (result.getStatusCode() != SaltstackResultCodes.SUCCESS.getValue()) {
return result;
}
result.setStatusMessage("Success");
- result.setOutputFileName(outFilePath);
+ result.setOutputMessage(out);
} catch (Exception io) {
logger.error("Caught Exception", io);
result.setStatusCode(SaltstackResultCodes.UNKNOWN_EXCEPTION.getValue());
result.setStatusMessage(io.getMessage());
} finally {
- if( out != null )
+ if (out != null) {
out.close();
- if( errs != null )
+ }
+ if (errs != null) {
errs.close();
+ }
}
return result;
}
- public SaltstackResult sortExitStatus(int exitStatus, String errFilePath, String cmd) {
+ public SaltstackResult sortExitStatus(int exitStatus, String errMess, String cmd) {
SaltstackResult result = new SaltstackResult();
- String err = "";
- StringWriter writer = new StringWriter();
- try {
- IOUtils.copy(new FileInputStream(new File(errFilePath)), writer, "UTF-8");
- err = writer.toString();
- } catch (FileNotFoundException e){
- logger.info("Error stream file doesn't exist");
- } catch (IOException e){
- logger.info("Error stream file doesn't exist");
- }
if (exitStatus == 255 || exitStatus == 1) {
String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString()
+ "]. Exit Code " + exitStatus + " and Error message : " +
- "Malformed configuration. " + err;
+ "Malformed configuration. " + errMess;
logger.error(errMessage);
result.setStatusCode(SaltstackResultCodes.INVALID_COMMAND.getValue());
result.setStatusMessage(errMessage);
} else if (exitStatus == 5 || exitStatus == 65) {
String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString()
+ "]. Exit Code " + exitStatus + " and Error message : " +
- "Host not allowed to connect. " + err;
+ "Host not allowed to connect. " + errMess;
logger.error(errMessage);
result.setStatusCode(SaltstackResultCodes.USER_UNAUTHORIZED.getValue());
result.setStatusMessage(errMessage);
} else if (exitStatus == 67 || exitStatus == 73) {
String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString()
+ "]. Exit Code " + exitStatus + " and Error message : " +
- "Key exchange failed. " + err;
+ "Key exchange failed. " + errMess;
logger.error(errMessage);
result.setStatusCode(SaltstackResultCodes.CERTIFICATE_ERROR.getValue());
result.setStatusMessage(errMessage);
} else {
String errMessage = "Error executing command [" + cmd + "] over SSH [" + sshConnection.toString()
- + "]. Exit Code " + exitStatus + " and Error message : " + err;
+ + "]. Exit Code " + exitStatus + " and Error message : " + errMess;
logger.error(errMessage);
result.setStatusCode(SaltstackResultCodes.UNKNOWN_EXCEPTION.getValue());
result.setStatusMessage(errMessage);
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 5e0cc77e..a48b67ad 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
@@ -108,11 +108,11 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
/**
* This default constructor is used as a work around because the activator wasn't getting called
*/
- public SaltstackAdapterImpl() throws SvcLogicException{
+ public SaltstackAdapterImpl() throws SvcLogicException {
initialize(new SaltstackAdapterPropertiesProviderImpl());
}
- public SaltstackAdapterImpl(SaltstackAdapterPropertiesProvider propProvider) throws SvcLogicException{
+ public SaltstackAdapterImpl(SaltstackAdapterPropertiesProvider propProvider) throws SvcLogicException {
initialize(propProvider);
}
@@ -152,7 +152,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
/**
* initialize the Saltstack adapter based on default and over-ride configuration data
*/
- private void initialize(SaltstackAdapterPropertiesProvider propProvider) throws SvcLogicException{
+ private void initialize(SaltstackAdapterPropertiesProvider propProvider) throws SvcLogicException {
Properties props = propProvider.getProperties();
@@ -176,7 +176,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
logger.info("Creating ssh client connection");
// set path to keystore file
String sshHost = props.getProperty(SS_SERVER_HOSTNAME);
- String sshPort = reqServerPort(props) ;
+ String sshPort = reqServerPort(props);
String sshUserName = props.getProperty(SS_SERVER_USERNAME);
String sshPassword = props.getProperty(SS_SERVER_PASSWD);
sshClient = new ConnectionBuilder(sshHost, sshPort, sshUserName, sshPassword);
@@ -212,8 +212,9 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
private String reqServerPort(Properties props) {
// use default port if null
- if (props.getProperty(SS_SERVER_PORT) == null)
+ if (props.getProperty(SS_SERVER_PORT) == null) {
return "22";
+ }
return props.getProperty(SS_SERVER_PORT);
}
@@ -235,11 +236,11 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
private String parseEnvParam(JSONObject envParams) {
StringBuilder envParamBuilder = new StringBuilder();
if (envParams != null) {
- for(Object key : envParams.keySet()) {
- if(envParamBuilder.length() > 0) {
+ for (Object key : envParams.keySet()) {
+ if (envParamBuilder.length() > 0) {
envParamBuilder.append(", ");
}
- envParamBuilder.append(key+"="+envParams.get((String) key));
+ envParamBuilder.append(key + "=" + envParams.get((String) key));
logger.info("EnvParameters : " + envParamBuilder);
}
}
@@ -249,7 +250,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
private String parseFileParam(JSONObject fileParams) {
StringBuilder fileParamBuilder = new StringBuilder();
if (fileParams != null) {
- for(Object key : fileParams.keySet()) {
+ for (Object key : fileParams.keySet()) {
fileParamBuilder.append("echo -e \"" + fileParams.get((String) key) + "\" > /srv/salt/" + key).append("; ");
logger.info("FileParameters : " + fileParamBuilder);
}
@@ -258,7 +259,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
}
private String putToCommands(SvcLogicContext ctx, String slsFileName,
- String applyTo, JSONObject envParams, JSONObject fileParams) throws SvcLogicException {
+ String applyTo, JSONObject envParams, JSONObject fileParams) throws SvcLogicException {
StringBuilder constructedCommand = new StringBuilder();
try {
@@ -283,10 +284,10 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
} catch (FileNotFoundException e) {
doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input SLS file " +
- "not found in path : " + slsFileName+". "+ e.getMessage());
+ "not found in path : " + slsFileName + ". " + e.getMessage());
} catch (IOException e) {
doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input SLS file " +
- "error in path : " + slsFileName +". "+ e.getMessage());
+ "error in path : " + slsFileName + ". " + e.getMessage());
} catch (StringIndexOutOfBoundsException e) {
doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(), "Input file " +
"is not of type .sls");
@@ -294,10 +295,14 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
return constructedCommand.toString();
}
- private String stripExtension (String str) {
- if (str == null) return null;
+ private String stripExtension(String str) {
+ if (str == null) {
+ return null;
+ }
int pos = str.lastIndexOf(".");
- if (pos == -1) return str;
+ if (pos == -1) {
+ return str;
+ }
return str.substring(0, pos);
}
@@ -348,7 +353,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
checkResponseStatus(testResult, ctx, reqID, slsExec);
} catch (IOException e) {
doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(),
- "IOException in file stream : "+ e.getMessage());
+ "IOException in file stream : " + e.getMessage());
}
}
@@ -379,7 +384,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
checkResponseStatus(testResult, ctx, reqID, true);
} catch (IOException e) {
doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(),
- "IOException in file stream : "+ e.getMessage());
+ "IOException in file stream : " + e.getMessage());
} catch (JSONException e) {
doFailure(ctx, SaltstackResultCodes.INVALID_COMMAND.getValue(), e.getMessage());
}
@@ -412,13 +417,13 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
checkResponseStatus(testResult, ctx, reqID, true);
} catch (IOException e) {
doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(),
- "IOException in file stream : "+ e.getMessage());
+ "IOException in file stream : " + e.getMessage());
}
}
public SaltstackResult execCommand(SvcLogicContext ctx, Map<String, String> params, String commandToExecute,
long execTimeout)
- throws SvcLogicException{
+ throws SvcLogicException {
SaltstackResult testResult = new SaltstackResult();
try {
@@ -439,7 +444,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter {
}
} catch (IOException e) {
doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(),
- "IOException in file stream : "+ e.getMessage());
+ "IOException in file stream : " + e.getMessage());
}
return testResult;
}
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 62724c36..71ca5cf7 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
@@ -163,19 +163,19 @@ class SshConnection {
public void setExecTimeout(long timeout) {
//convert seconds to milliseconds
- this.timeout = timeout*1000;
+ this.timeout = timeout * 1000;
}
- public SaltstackResult execCommand(String cmd, OutputStream out, OutputStream err, SaltstackResult result ) {
+ 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, SaltstackResult result ) {
+ 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 ) {
+ boolean usePty, SaltstackResult result) {
try {
if (logger.isDebugEnabled()) {
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 8548efc0..2d810aee 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
@@ -31,16 +31,14 @@ package org.onap.ccsdk.sli.adaptors.saltstack.model;
import com.google.common.base.Strings;
import org.json.JSONException;
-import org.json.JSONArray;
import org.json.JSONObject;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
@@ -79,8 +77,9 @@ public class SaltstackMessageParser {
*/
public String reqPortResult(Map<String, String> params) throws SvcLogicException {
// use default port if null
- if (params.get(SS_AGENT_PORT_KEY) == null)
+ if (params.get(SS_AGENT_PORT_KEY) == null) {
return "22";
+ }
return params.get(SS_AGENT_PORT_KEY);
}
@@ -200,7 +199,7 @@ public class SaltstackMessageParser {
public JSONObject reqEnvParameters(Map<String, String> params) throws JSONException {
JSONObject jsonPayload = new JSONObject();
- final String[] optionalTestParam = { SaltstackMessageParser.ENV_PARAMETERS_OPT_KEY };
+ final String[] optionalTestParam = {SaltstackMessageParser.ENV_PARAMETERS_OPT_KEY};
parseParam(params, optionalTestParam, jsonPayload);
return (JSONObject) jsonPayload.remove(SaltstackMessageParser.ENV_PARAMETERS_OPT_KEY);
@@ -214,7 +213,7 @@ public class SaltstackMessageParser {
public JSONObject reqFileParameters(Map<String, String> params) throws JSONException {
JSONObject jsonPayload = new JSONObject();
- final String[] optionalTestParam = { SaltstackMessageParser.FILE_PARAMETERS_OPT_KEY };
+ final String[] optionalTestParam = {SaltstackMessageParser.FILE_PARAMETERS_OPT_KEY};
parseParam(params, optionalTestParam, jsonPayload);
return (JSONObject) jsonPayload.remove(SaltstackMessageParser.FILE_PARAMETERS_OPT_KEY);
@@ -308,19 +307,13 @@ public class SaltstackMessageParser {
public SaltstackResult parseResponse(SvcLogicContext ctx, String pfx,
SaltstackResult saltstackResult, boolean slsExec) throws IOException {
int code = saltstackResult.getStatusCode();
- InputStream in = null;
boolean executionStatus = true, retCodeFound = false;
if (code != SaltstackResultCodes.SUCCESS.getValue()) {
return saltstackResult;
}
+ ByteArrayOutputStream str = saltstackResult.getOutputMessage();
try {
- File file = new File(saltstackResult.getOutputFileName());
- in = new FileInputStream(file);
- byte[] data = new byte[(int) file.length()];
- in.read(data);
- String str = new String(data, "UTF-8");
- in.close();
- Map<String, String> mm = JsonParser.convertToProperties(str);
+ Map<String, String> mm = JsonParser.convertToProperties(str.toString());
if (mm != null) {
for (Map.Entry<String, String> entry : mm.entrySet()) {
if (entry.getKey().contains("retcode")) {
@@ -333,18 +326,19 @@ public class SaltstackMessageParser {
LOGGER.info("+++ " + pfx + "." + entry.getKey() + ": [" + entry.getValue() + "]");
}
}
- } catch (FileNotFoundException e) {
- return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "error parsing response file "
- + saltstackResult.getOutputFileName() + " : " + e.getMessage());
} catch (org.codehaus.jettison.json.JSONException e) {
+ if (slsExec) {
+ return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE.getValue(), "error parsing response file"
+ + " : Output has to be in JSON format");
+ }
LOGGER.info("Output not in JSON format");
return putToProperties(ctx, pfx, saltstackResult);
} catch (Exception e) {
- return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "error parsing response file "
- + saltstackResult.getOutputFileName() + " : " + e.getMessage());
+ return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "error parsing response file"
+ + " : " + e.getMessage());
} finally {
- if (in != null) {
- in.close();
+ if (str != null) {
+ str.close();
}
}
if (slsExec) {
@@ -363,12 +357,14 @@ public class SaltstackMessageParser {
public SaltstackResult putToProperties(SvcLogicContext ctx, String pfx,
SaltstackResult saltstackResult) throws IOException {
- InputStream in = null;
+
+ ByteArrayOutputStream buffer = saltstackResult.getOutputMessage();
+ InputStream inputStream = null;
try {
- File file = new File(saltstackResult.getOutputFileName());
- in = new FileInputStream(file);
+ byte[] bytes = buffer.toByteArray();
Properties prop = new Properties();
- prop.load(in);
+ inputStream = new ByteArrayInputStream(bytes);
+ prop.load(inputStream);
ctx.setAttribute(pfx + "completeResult", prop.toString());
for (Object key : prop.keySet()) {
String name = (String) key;
@@ -379,11 +375,12 @@ public class SaltstackMessageParser {
}
}
} catch (Exception e) {
- saltstackResult = new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "Error parsing response file = "
- + saltstackResult.getOutputFileName() + ". Error = " + e.getMessage());
+ saltstackResult = new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "Error parsing response file." +
+ " Error = " + e.getMessage());
} finally {
- if (in != null) {
- in.close();
+ if (buffer != null && inputStream != null) {
+ buffer.close();
+ inputStream.close();
}
}
saltstackResult.setStatusCode(SaltstackResultCodes.FINAL_SUCCESS.getValue());
diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java
index b29dd8e8..727cfe31 100644
--- a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java
+++ b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackResult.java
@@ -24,6 +24,8 @@
package org.onap.ccsdk.sli.adaptors.saltstack.model;
+import java.io.ByteArrayOutputStream;
+
/**
* Simple class to store code and message returned by POST/GET to an Saltstack Server
*/
@@ -34,7 +36,7 @@ public class SaltstackResult {
private int statusCode;
private String statusMessage;
private String results;
- private String out;
+ private ByteArrayOutputStream out;
private int sshExitStatus;
public SaltstackResult() {
@@ -58,11 +60,11 @@ public class SaltstackResult {
this.results = results;
}
- public String getOutputFileName() {
+ public ByteArrayOutputStream getOutputMessage() {
return out;
}
- public void setOutputFileName(String out) {
+ public void setOutputMessage(ByteArrayOutputStream out) {
this.out = out;
}
diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java
index 55beb229..bac2cfe5 100644
--- a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java
+++ b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/SaltstackServerEmulator.java
@@ -34,12 +34,13 @@ package org.onap.ccsdk.sli.adaptors.saltstack.model;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import org.apache.commons.lang.StringUtils;
-import org.json.JSONObject;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
public class SaltstackServerEmulator {
@@ -60,13 +61,10 @@ public class SaltstackServerEmulator {
result = rejectRequest(result, "Mocked: Fail");
} else {
String fileName = params.get(SALTSTATE_FILE_NAME);
- if (fileName == null)
- result = acceptRequest(result, "");
- else
- result = acceptRequest(result, fileName);
+ result = acceptRequest(result, fileName);
}
} catch (Exception e) {
- logger.error("JSONException caught", e);
+ logger.error("Exception caught", e);
rejectRequest(result, e.getMessage());
}
return result;
@@ -78,10 +76,14 @@ public class SaltstackServerEmulator {
return result;
}
- private SaltstackResult acceptRequest(SaltstackResult result, String fileName) {
+ private SaltstackResult acceptRequest(SaltstackResult result, String fileName) throws IOException {
result.setStatusCode(SaltstackResultCodes.SUCCESS.getValue());
result.setStatusMessage("Success");
- result.setOutputFileName(fileName);
+ Path path = Paths.get(fileName);
+ byte[] data = Files.readAllBytes(path);
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream(data.length);
+ byteOut.write(data, 0, data.length);
+ result.setOutputMessage(byteOut);
return result;
}
} \ No newline at end of file
diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml b/saltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml
index 446ab3e4..e360f818 100755
--- a/saltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml
+++ b/saltstack-adapter/saltstack-adapter-provider/src/main/resources/org/opendaylight/blueprint/saltstack-adapter-blueprint.xml
@@ -20,19 +20,22 @@
============LICENSE_END=========================================================
-->
-<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
- xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+<blueprint xmlns:odl="http://opendaylight.org/xmlns/blueprint/v1.0.0"
+ xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
odl:use-default-for-reference-types="true">
- <bean id="propProvider" class="org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterPropertiesProviderImpl" />
+ <bean id="propProvider"
+ class="org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterPropertiesProviderImpl"/>
- <bean id="saltstackAdapterInstance" class="org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterImpl">
+ <bean id="saltstackAdapterInstance"
+ class="org.onap.ccsdk.sli.adaptors.saltstack.impl.SaltstackAdapterImpl">
<argument ref="propProvider"/>
</bean>
<service ref="saltstackAdapterInstance">
<interfaces>
- <value>org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdapter</value>
+ <value>org.onap.ccsdk.sli.adaptors.saltstack.SaltstackAdapter
+ </value>
</interfaces>
</service>
diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties b/saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties
index 0b077524..1755f7ad 100644
--- a/saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties
+++ b/saltstack-adapter/saltstack-adapter-provider/src/main/resources/saltstack-adapter.properties
@@ -21,7 +21,6 @@
#
# ============LICENSE_END=========================================================
###
-
#
# Default properties for the APP-C TestService Adapter
#
@@ -31,17 +30,13 @@
# to supply configuration options
org.onap.appc.bootstrap.file=appc.properties
org.onap.appc.bootstrap.path=${user.home},/opt/opendaylight/current/properties
-
appc.application.name=APPC
-
#
# Define the message resource bundle name to be loaded
org.onap.appc.resources=org.onap/appc/i18n/MessageResources
#
# The name of the adapter.
org.onap.appc.provider.adaptor.name=org.onap.appc.appc_saltstack_adapter
-
-
# Default truststore path and password
org.onap.appc.adapter.saltstack.trustStore=/opt/opendaylight/tls-client/mykeystore.js
org.onap.appc.adapter.saltstack.trustStore.trustPasswd=changeit