/**
* 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);
}
/**
* 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();
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);
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);
}
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);
}
}
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);
}
}
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 {
} 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");
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);
}
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());
}
}
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());
}
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 {
}
} catch (IOException e) {
doFailure(ctx, SaltstackResultCodes.IO_EXCEPTION.getValue(),
- "IOException in file stream : "+ e.getMessage());
+ "IOException in file stream : " + e.getMessage());
}
return testResult;
}