import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashSet;
* and returns an SaltstackResult object.
*/
public SaltstackResult parseResponse(SvcLogicContext ctx, String pfx,
- SaltstackResult saltstackResult, boolean slsExec) {
+ 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;
}
try {
File file = new File(saltstackResult.getOutputFileName());
- InputStream in = new FileInputStream(file);
+ in = new FileInputStream(file);
byte[] data = new byte[(int) file.length()];
in.read(data);
String str = new String(data, "UTF-8");
} catch (Exception e) {
return new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "error parsing response file "
+ saltstackResult.getOutputFileName() + " : " + e.getMessage());
+ } finally {
+ if( in != null )
+ in.close();
}
if (slsExec) {
if (!retCodeFound)
return saltstackResult;
}
- public SaltstackResult putToProperties(SvcLogicContext ctx, String pfx, SaltstackResult saltstackResult) {
+ public SaltstackResult putToProperties(SvcLogicContext ctx, String pfx,
+ SaltstackResult saltstackResult) throws IOException{
+ InputStream in = null;
try {
File file = new File(saltstackResult.getOutputFileName());
- InputStream in = new FileInputStream(file);
+ in = new FileInputStream(file);
Properties prop = new Properties();
prop.load(in);
ctx.setAttribute(pfx + "completeResult", prop.toString());
} catch (Exception e) {
saltstackResult = new SaltstackResult(SaltstackResultCodes.INVALID_RESPONSE_FILE.getValue(), "Error parsing response file = "
+ saltstackResult.getOutputFileName() + ". Error = " + e.getMessage());
+ } finally {
+ if( in != null )
+ in.close();
}
saltstackResult.setStatusCode(SaltstackResultCodes.FINAL_SUCCESS.getValue());
return saltstackResult;