From e70da25135855b88571b19c108089b74181996a6 Mon Sep 17 00:00:00 2001 From: Ganesh Chandrasekaran Date: Fri, 20 Jul 2018 17:53:04 +0900 Subject: Saltstack port not mandatory Issue-ID: CCSDK-390 Change-Id: Ie9448d3a3fbbc7e52e8103ca5da1e2a3e080d58c Signed-off-by: Ganesh Chandrasekaran --- .../saltstack/impl/SaltstackAdapterImpl.java | 16 ++++--- .../sli/adaptors/saltstack/model/JsonParser.java | 2 +- .../saltstack/model/SaltstackMessageParser.java | 51 ++++------------------ .../blueprint/saltstack-adapter-blueprint.xml | 2 +- ...TestSaltstackAdapterPropertiesProviderImpl.java | 6 +-- .../onap/ccsdk/adapter/model/TestJsonParser.java | 2 +- .../APPC_saltstack-adapter-1.0-exe-nonSLS.xml | 16 +++---- .../APPC_saltstack-adapter-1.0-exec-SLSFile.json | 8 ++-- .../APPC_saltstack-adapter-1.0-exec-SLSFile.xml | 30 ++++++------- .../APPC_saltstack-adapter-1.0-exec-multi-sls.json | 8 ++-- .../APPC_saltstack-adapter-1.0-exec-multi-sls.xml | 14 +++--- ..._saltstack-adapter-1.0-exec-single-SLSComm.json | 6 +-- ...C_saltstack-adapter-1.0-exec-single-SLSComm.xml | 16 +++---- 13 files changed, 75 insertions(+), 102 deletions(-) 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 5373c227a..5e0cc77eb 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 @@ -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 = props.getProperty(SS_SERVER_PORT); + 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); @@ -184,7 +184,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { // set path to keystore file String sshKey = props.getProperty(SS_SERVER_SSH_KEY); String sshHost = props.getProperty(SS_SERVER_HOSTNAME); - String sshPort = props.getProperty(SS_SERVER_PORT); + String sshPort = reqServerPort(props); logger.info("Creating ssh client with ssh KEY from " + sshKey); sshClient = new ConnectionBuilder(sshHost, sshPort, sshKey); } else if ("BOTH".equalsIgnoreCase(clientType)) { @@ -193,7 +193,7 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { String sshHost = props.getProperty(SS_SERVER_HOSTNAME); String sshUserName = props.getProperty(SS_SERVER_USERNAME); String sshPassword = props.getProperty(SS_SERVER_PASSWD); - String sshPort = props.getProperty(SS_SERVER_PORT); + String sshPort = reqServerPort(props); logger.info("Creating ssh client with ssh KEY from " + sshKey); sshClient = new ConnectionBuilder(sshHost, sshPort, sshUserName, sshPassword, sshKey); } else { @@ -204,13 +204,19 @@ public class SaltstackAdapterImpl implements SaltstackAdapter { logger.error("Error Initializing Saltstack Adapter due to Unknown Exception", e); throw new SvcLogicException("Saltstack Adapter Property file parsing Error = port in property file has to be an integer."); } catch (Exception e) { - logger.error("Error Initializing Saltstack Adapter due to Unknown Exception", e); + logger.error("Error Initializing Saltstack Adapter due to Exception", e); throw new SvcLogicException("Saltstack Adapter Property file parsing Error = " + e.getMessage()); } - logger.info("Initialized Saltstack Adapter"); } + private String reqServerPort(Properties props) { + // use default port if null + if (props.getProperty(SS_SERVER_PORT) == null) + return "22"; + return props.getProperty(SS_SERVER_PORT); + } + private void setSSHClient(Map params) throws SvcLogicException { if (sshClient == null) { logger.info("saltstack-adapter.properties not defined so reading saltstack host and " + diff --git a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java index 0eb1fc0e8..3eb353a17 100644 --- a/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java +++ b/saltstack-adapter/saltstack-adapter-provider/src/main/java/org/onap/ccsdk/sli/adaptors/saltstack/model/JsonParser.java @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * openECOMP : SDN-C + * ONAP : CCSDK * ================================================================================ * Copyright (C) 2018 Samsung Electronics. All rights * reserved. 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 3095fca9b..8548efc06 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 @@ -78,13 +78,9 @@ public class SaltstackMessageParser { * the appropriate PORT number. */ public String reqPortResult(Map params) throws SvcLogicException { - - final String[] mandatoryTestParams = {SS_AGENT_HOSTNAME_KEY, SS_AGENT_PORT_KEY, USER_KEY, - PASS_KEY}; - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } + // use default port if null + if (params.get(SS_AGENT_PORT_KEY) == null) + return "22"; return params.get(SS_AGENT_PORT_KEY); } @@ -95,12 +91,7 @@ public class SaltstackMessageParser { */ public String reqHostNameResult(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {SS_AGENT_HOSTNAME_KEY, SS_AGENT_PORT_KEY, USER_KEY, - PASS_KEY}; - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } + throwIfMissingMandatoryParam(params, SS_AGENT_HOSTNAME_KEY); return params.get(SS_AGENT_HOSTNAME_KEY); } @@ -126,12 +117,7 @@ public class SaltstackMessageParser { */ public String reqCmd(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {CMD_EXEC, IS_SLS_EXEC}; - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } - + throwIfMissingMandatoryParam(params, CMD_EXEC); return params.get(SaltstackMessageParser.CMD_EXEC); } @@ -142,12 +128,7 @@ public class SaltstackMessageParser { */ public String reqSlsFile(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {SLS_FILE_LOCATION}; - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } - + throwIfMissingMandatoryParam(params, SLS_FILE_LOCATION); return params.get(SaltstackMessageParser.SLS_FILE_LOCATION); } @@ -158,11 +139,7 @@ public class SaltstackMessageParser { */ public String reqSlsName(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {SLS_NAME}; - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } + throwIfMissingMandatoryParam(params, SLS_NAME); String slsName = params.get(SaltstackMessageParser.SLS_NAME); try { if (slsName.substring(slsName.lastIndexOf("."), slsName.length()).equalsIgnoreCase(".sls")) { @@ -309,12 +286,7 @@ public class SaltstackMessageParser { */ public String reqUserNameResult(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {SS_AGENT_HOSTNAME_KEY, SS_AGENT_PORT_KEY, USER_KEY, - PASS_KEY}; - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } + throwIfMissingMandatoryParam(params, USER_KEY); return params.get(USER_KEY); } @@ -325,12 +297,7 @@ public class SaltstackMessageParser { */ public String reqPasswordResult(Map params) throws SvcLogicException { - final String[] mandatoryTestParams = {SS_AGENT_HOSTNAME_KEY, SS_AGENT_PORT_KEY, USER_KEY, - PASS_KEY}; - - for (String key : mandatoryTestParams) { - throwIfMissingMandatoryParam(params, key); - } + throwIfMissingMandatoryParam(params, PASS_KEY); return params.get(PASS_KEY); } 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 2c3b7b04e..446ab3e44 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 @@ -1,7 +1,7 @@