aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkusuma kumari M <km583p@att.com>2018-01-03 21:55:50 -0500
committerSkip Wonnell <skip@att.com>2018-01-09 15:18:42 +0000
commit2a66c7c042d4d5919f8b200d026f211ba241774f (patch)
tree2f7c0c20f3b113cb91d2f75fb94e7ccd4c79fc31
parent31540f8ba964a7d66ca04f1468db061abda5c7a1 (diff)
code changes for platform hardening appc adapters
Issue-ID: APPC-305 Change-Id: Ice60ca77ffccc409d50ef11318e841c3b1f82ce1 Signed-off-by: kusuma kumari M <km583p@att.com>
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java7
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefAdapter.java49
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefapi/ApiMethod.java20
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/Utils.java4
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java640
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/TestChefApiClient.java32
-rw-r--r--appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java35
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/AppcDmaapAdapterActivator.java3
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/CommonHttpClient.java16
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapConsumerImpl.java20
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapProducerImpl.java22
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java35
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java46
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/EventSenderDmaapImpl.java15
-rw-r--r--appc-adapters/appc-dmaap-adapter/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java29
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java21
-rw-r--r--appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java2
-rw-r--r--appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java362
18 files changed, 812 insertions, 546 deletions
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java
index 6c798b4b2..a3681d322 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefActivator.java
@@ -81,7 +81,7 @@ public class ChefActivator implements BundleActivator {
* <p>
* This method must complete and return to its caller in a timely manner.
* </p>
- *
+ *
* @param context
* The execution context of the bundle being started.
* @throws java.lang.Exception
@@ -93,10 +93,11 @@ public class ChefActivator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
logger.info("Starting bundle " + getName());
+
configuration = ConfigurationFactory.getConfiguration();
String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
logger.info(Msg.COMPONENT_INITIALIZING, appName, "chef adapter");
- adapter = new ChefAdapterImpl();
+ adapter = new ChefAdapterImpl(configuration.getProperties());
if (registration == null) {
logger.info(Msg.REGISTERING_SERVICE, appName, adapter.getAdapterName(),
ChefAdapter.class.getSimpleName());
@@ -114,7 +115,7 @@ public class ChefActivator implements BundleActivator {
* <p>
* This method must complete and return to its caller in a timely manner.
* </p>
- *
+ *
* @param context
* The execution context of the bundle being stopped.
* @throws java.lang.Exception
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefAdapter.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefAdapter.java
index d11db1c14..72b85aea4 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefAdapter.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/ChefAdapter.java
@@ -29,8 +29,8 @@ import java.util.Map;
import org.onap.appc.exceptions.APPCException;
import com.att.cdp.zones.model.Server;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
-
/**
* This interface defines the operations that the provider adapter exposes.
* <p>
@@ -82,7 +82,7 @@ public interface ChefAdapter extends SvcLogicJavaPlugin {
* URL of the server)</dd>
* </dl>
* </p>
- *
+ *
* @param properties
* A map of name-value pairs that supply the parameters needed by this method. The properties needed are
* defined above.
@@ -112,7 +112,7 @@ public interface ChefAdapter extends SvcLogicJavaPlugin {
* URL of the server)</dd>
* </dl>
* </p>
- *
+ *
* @param properties
* A map of name-value pairs that supply the parameters needed by this method. The properties needed are
* defined above.
@@ -142,7 +142,7 @@ public interface ChefAdapter extends SvcLogicJavaPlugin {
* URL of the server)</dd>
* </dl>
* </p>
- *
+ *
* @param properties
* A map of name-value pairs that supply the parameters needed by this method. The properties needed are
* defined above.
@@ -172,7 +172,7 @@ public interface ChefAdapter extends SvcLogicJavaPlugin {
* URL of the server)</dd>
* </dl>
* </p>
- *
+ *
* @param properties
* A map of name-value pairs that supply the parameters needed by this method. The properties needed are
* defined above.
@@ -188,7 +188,7 @@ public interface ChefAdapter extends SvcLogicJavaPlugin {
/**
* Returns the symbolic name of the adapter
- *
+ *
* @return The adapter name
*/
String getAdapterName();
@@ -196,25 +196,32 @@ public interface ChefAdapter extends SvcLogicJavaPlugin {
// Server evacuateServer(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
//Server migrateServer(Map<String, String> params, SvcLogicContext ctx) throws APPCException;
-
void trigger(Map<String, String> params, SvcLogicContext ctx) ;
-
- void chefGet(Map<String, String> params, SvcLogicContext ctx) ;
-
- void chefPut(Map<String, String> params, SvcLogicContext ctx) ;
-
- void chefPost(Map<String, String> params, SvcLogicContext ctx) ;
-
- void chefDelete(Map<String, String> params, SvcLogicContext ctx) ;
-
+
+ void chefGet(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
+
+ void chefPut(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
+
+ void chefPost(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
+
+ void chefDelete(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
+
void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) ;
+
+ void checkPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
- void checkPushJob(Map<String, String> params, SvcLogicContext ctx) ;
-
- void pushJob(Map<String, String> params, SvcLogicContext ctx) ;
-
+ void pushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
+
void retrieveData (Map<String, String> params, SvcLogicContext ctx) ;
-
+
void combineStrings (Map<String, String> params, SvcLogicContext ctx) ;
+
+ void VnfcEnvironment (Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
+
+ void VnfcNodeobjects (Map<String, String> params, SvcLogicContext ctx)throws SvcLogicException ;
+
+ void VnfcPushJob (Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
+
+ void fetchResults (Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException;
}
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefapi/ApiMethod.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefapi/ApiMethod.java
index 38c4dd354..b65037203 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefapi/ApiMethod.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefapi/ApiMethod.java
@@ -52,13 +52,22 @@ public class ApiMethod {
private String methodName = "GET";
public String test = "";
private int returnCode;
+ final String KEY_STORE_PATH = "/etc/chef/trusted_certs/mykeystore.jks";
+ final String KEY_STORE_PASSWORD = "adminadmin";
+ static
+ {
+ System.setProperty("javax.net.ssl.trustStore", "/opt/app/bvc/chef/chefServerSSL.jks");
+ System.setProperty("javax.net.ssl.trustStorePassword", "adminadmin");
+ }
public ApiMethod(String methodName) {
client=HttpClients.createDefault();
this.methodName = methodName;
}
- public ApiMethod createRequest(){
+
+
+ public ApiMethod execute() {
String hashedPath = Utils.sha1AndBase64("/organizations/"+organizations+chefPath);
String hashedBody = Utils.sha1AndBase64(reqBody);
@@ -90,15 +99,6 @@ public class ApiMethod {
for (int i = 0; i < auth_headers.length; i++) {
method.addHeader("X-Ops-Authorization-" + (i + 1), auth_headers[i]);
}
- /*
- * test=test+this.method.getMethod()+"\n"; Header[]
- * RHS=this.method.getHeaders(); for (int i = 0; i < RHS.length; i++) {
- * test=test+RHS[i]+"\n"; } test=test+this.reqBody+"\n";
- */
- return this;
- }
-
- public ApiMethod execute() {
try{
response = client.execute(method);
resCode = response.getStatusLine().getStatusCode();
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/Utils.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/Utils.java
index 71182c497..dbaf1d3f2 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/Utils.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/chefclient/Utils.java
@@ -25,6 +25,7 @@
package org.onap.appc.adapter.chef.chefclient;
import java.io.BufferedReader;
+import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.security.InvalidKeyException;
@@ -73,6 +74,7 @@ public class Utils {
instance.update(inStr.getBytes());
byte[] signature = instance.sign();
outStr = Base64.encode(signature);
+ String tmp = new String(outStr);
} catch (InvalidKeyException e) {
e.printStackTrace();
} catch (IOException e) {
@@ -88,7 +90,6 @@ public class Utils {
public static String[] splitAs60(String inStr) {
int count = inStr.length() / 60;
String[] out = new String[count + 1];
-
for (int i = 0; i < count; i++) {
String tmp = inStr.substring(i * 60, i * 60 + 60);
out[i] = tmp;
@@ -99,4 +100,5 @@ public class Utils {
}
return out;
}
+
}
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java
index 824a6af95..8307a9b99 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/main/java/org/onap/appc/adapter/chef/impl/ChefAdapterImpl.java
@@ -25,14 +25,20 @@
package org.onap.appc.adapter.chef.impl;
import java.io.File;
+import java.util.Arrays;
+import java.util.List;
import java.util.Map;
+import java.util.Properties;
+import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
+import org.json.JSONException;
import org.json.JSONObject;
import org.onap.appc.Constants;
import org.onap.appc.adapter.chef.ChefAdapter;
@@ -40,7 +46,9 @@ import org.onap.appc.adapter.chef.chefapi.ApiMethod;
import org.onap.appc.adapter.chef.chefclient.ChefApiClient;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.exceptions.APPCException;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -51,26 +59,62 @@ import com.att.eelf.configuration.EELFManager;
*/
public class ChefAdapterImpl implements ChefAdapter {
// chef server Initialize variable
- private String clientName = "";
+ private String username = "";
private String clientPrivatekey = "";
private String chefserver = "";
private String serverAddress = "";
private String organizations = "";
+
+ @SuppressWarnings("nls")
+ public static final String MDC_ADAPTER = "adapter";
+ @SuppressWarnings("nls")
+ public static final String MDC_SERVICE = "service";
- /**
- * The constant for the status code for a successful outcome
- */
- private static final String OUTCOME_SUCCESS = "success";
+ @SuppressWarnings("nls")
+ public static final String OUTCOME_FAILURE = "failure";
- /**
- * The logger to be used
- */
- private final EELFLogger logger = EELFManager.getInstance().getLogger(ChefAdapterImpl.class);
+ @SuppressWarnings("nls")
+ public static final String OUTCOME_SUCCESS = "success";
+
+ @SuppressWarnings("nls")
+ public static final String PROPERTY_PROVIDER = "provider";
+
+ @SuppressWarnings("nls")
+ public static final String PROPERTY_PROVIDER_IDENTITY = "identity";
+
+ @SuppressWarnings("nls")
+ public static final String PROPERTY_PROVIDER_NAME = "name";
+
+ @SuppressWarnings("nls")
+ public static final String PROPERTY_PROVIDER_TENANT = "tenant";
+
+ @SuppressWarnings("nls")
+ public static final String PROPERTY_PROVIDER_TENANT_NAME = "name";
+
+ @SuppressWarnings("nls")
+ public static final String PROPERTY_PROVIDER_TENANT_PASSWORD = "password"; // NOSONAR
+
+ @SuppressWarnings("nls")
+ public static final String PROPERTY_PROVIDER_TENANT_USERID = "userid";
+
+ @SuppressWarnings("nls")
+ public static final String PROPERTY_PROVIDER_TYPE = "type";
+
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(ChefAdapterImpl.class);
+
+ private static final char LPAREN = '(';
+
+ private static final char NL = '\n';
+
+ private static final char QUOTE = '\'';
+
+ private static final char RPAREN = ')';
+ private static final char SPACE = ' ';
private final String CANNOT_FIND_PRIVATE_KEY_STR = "Cannot find the private key in the APPC file system, please load the private key to ";
- private final String CHEF_ACTION_STR = "org.onap.appc.instance.chefAction";
- private final String ORGANIZATIONS_STR = "/organizations/";
+
/**
* A reference to the adapter configuration object.
*/
@@ -83,6 +127,11 @@ public class ChefAdapterImpl implements ChefAdapter {
public ChefAdapterImpl() {
initialize();
}
+
+ public ChefAdapterImpl(Properties props) {
+ initialize();
+
+ }
/**
* This constructor is used primarily in the test cases to bypass initialization
@@ -91,17 +140,20 @@ public class ChefAdapterImpl implements ChefAdapter {
* @param initialize
* True if the adapter is to be initialized, can false if not
*/
+
public ChefAdapterImpl(boolean initialize) {
- configuration = ConfigurationFactory.getConfiguration();
+
if (initialize) {
initialize();
}
}
public ChefAdapterImpl(String key) {
- initialize(key);
+ initialize();
}
+
+
/**
* Returns the symbolic name of the adapter
*
@@ -110,21 +162,306 @@ public class ChefAdapterImpl implements ChefAdapter {
*/
@Override
public String getAdapterName() {
- return configuration.getProperty(Constants.PROPERTY_ADAPTER_NAME);
+ return "chef adapter";
+ }
+
+ @SuppressWarnings("nls")
+ @Override
+ public void VnfcEnvironment(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ int code;
+ try{
+ logger.info("environment of VNF-C");
+ chefInfo(params,ctx);
+ RequestContext rc = new RequestContext(ctx);
+ logger.info("Context"+ctx );
+ rc.isAlive();
+ String env = params.get("Environment");
+ logger.info("Environmnet"+env );
+ if(env.equals("")){
+ chefServerResult(rc, "200", "Skip Environment block ");}
+ else{
+ JSONObject env_J = new JSONObject(env);
+ String envName = env_J.getString("name");
+
+
+ String message = null;
+ if (privateKeyCheck()) {
+ // update the details of an environment on the Chef server.
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ApiMethod am = cac.put("/environments/"+envName).body(env);
+ am.execute();
+ code = am.getReturnCode();
+ message = am.getResponseBodyAsString();
+ if(code == 404 ){
+ //need create a new environment
+ am = cac.post("/environments").body(env);
+ am.execute();
+ code = am.getReturnCode();
+ message = am.getResponseBodyAsString();
+ logger.info("requestbody"+am.getReqBody());
+ }
+
+ } else {
+ code = 500;
+ message = "Cannot find the private key in the APPC file system, please load the private key to "
+ + clientPrivatekey;
+ doFailure(ctx,code,message);
+ }
+ chefServerResult(rc, Integer.toString(code), message);
+ }
+ }
+
+ catch(JSONException e){
+ code =401;
+ doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
+ }
+ catch(Exception e){
+ code =401;
+ doFailure(ctx, code, "Error posting request :Reason = " + e.getMessage());
+ }
+ }
+
+ @SuppressWarnings("nls")
+ @Override
+ public void VnfcNodeobjects(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ logger.info("update the nodeObjects of VNF-C");
+ int code;
+ try{
+ chefInfo(params,ctx);
+ String nodeList_S = params.get("NodeList");
+ String node_S = params.get("Node");
+ if (StringUtils.isNotBlank(nodeList_S) && StringUtils.isNotBlank(node_S))
+ {
+ nodeList_S = nodeList_S.replace("[","");
+ nodeList_S = nodeList_S.replace("]","");
+ nodeList_S = nodeList_S.replace("\"","");
+ nodeList_S = nodeList_S.replace(" ","");
+ List<String> nodes = Arrays.asList(nodeList_S.split("\\s*,\\s*"));
+ RequestContext rc = new RequestContext(ctx);
+ rc.isAlive();
+ code=200;
+ String message = null;
+ if (privateKeyCheck()) {
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+
+ for(int i = 0; i < nodes.size(); i++){
+ String nodeName=nodes.get(i);
+ JSONObject node_J = new JSONObject(node_S);
+ node_J.remove("name");
+ node_J.put("name",nodeName);
+ String nodeObject=node_J.toString();
+ logger.info(nodeObject);
+ ApiMethod am = cac.put("/nodes/"+nodeName).body(nodeObject);
+ am.execute();
+ code = am.getReturnCode();
+ message = am.getResponseBodyAsString();
+ if(code != 200){
+ break;
+ }
+
+ }
+ }else{
+ code = 500;
+ message = "Cannot find the private key in the APPC file system, please load the private key to "
+ + clientPrivatekey;
+ doFailure(ctx,code,message);
+ }
+ chefServerResult(rc, Integer.toString(code), message);
+ }
+
+ else
+ {
+ throw new SvcLogicException("Missing Mandatory param(s) Node , NodeList ");
+ }
+ }
+ catch(JSONException e){
+ code =401;
+ doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
+ }
+ catch(Exception ex){
+ code =401;
+ doFailure(ctx, code, "Error posting request :Reason = " + ex.getMessage());
+ }
+
+ }
+
+ @Override
+ public void VnfcPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ int code ;
+ try{
+ chefInfo(params,ctx);
+ String nodeList = params.get("NodeList");
+ if (StringUtils.isNotBlank(nodeList))
+ {
+ String isCallback = params.get("CallbackCapable");
+ String chefAction = "/pushy/jobs";
+ //need work on this
+ String pushRequest="";
+ if(isCallback.equals("true")){
+ String requestId = params.get("RequestId");
+ String callbackUrl = params.get("CallbackUrl");
+ pushRequest="{"+
+ "\"command\": \"chef-client\","+
+ "\"run_timeout\": 300,"+
+ "\"nodes\":" +nodeList +","+
+ "\"env\": {\"RequestId\": \""+ requestId +"\", \"CallbackUrl\": \""+ callbackUrl +"\"},"+
+ "\"capture_output\": true"+
+ "}";
+ }else{
+ pushRequest="{"+
+ "\"command\": \"chef-client\","+
+ "\"run_timeout\": 300,"+
+ "\"nodes\":" +nodeList +","+
+ "\"env\": {},"+
+ "\"capture_output\": true"+
+ "}";
+ }
+ RequestContext rc = new RequestContext(ctx);
+
+ rc.isAlive();
+ SvcLogicContext svcLogic = rc.getSvcLogicContext();
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ApiMethod am = cac.post(chefAction).body(pushRequest);
+
+ am.execute();
+ code = am.getReturnCode();
+ logger.info("pushRequest:"+pushRequest);
+ logger.info("requestbody:"+am.getReqBody());
+
+ String message = am.getResponseBodyAsString();
+ if (code == 201) {
+ int startIndex = message.indexOf("jobs") + 5;
+ int endIndex = message.length() - 2;
+ String jobID = message.substring(startIndex, endIndex);
+ svcLogic.setAttribute("jobID", jobID);
+ logger.info(jobID);
+ }
+ chefServerResult(rc, Integer.toString(code), message);
+ }
+
+ else
+ {
+ throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
+ }
+ }
+ catch(JSONException e){
+ code =401;
+ doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
+ }
+ catch(Exception e)
+ {
+ code = 401;
+ doFailure(ctx,code,e.getMessage());
+ }
+
+ }
+
+
+ @SuppressWarnings("nls")
+ @Override
+ public void fetchResults (Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ int code;
+ try{
+ chefInfo(params,ctx);
+ String nodeList_S = params.get("NodeList");
+ if (StringUtils.isNotBlank(nodeList_S) )
+ {
+ nodeList_S = nodeList_S.replace("[","");
+ nodeList_S = nodeList_S.replace("]","");
+ nodeList_S = nodeList_S.replace("\"","");
+ nodeList_S = nodeList_S.replace(" ","");
+ List<String> nodes = Arrays.asList(nodeList_S.split("\\s*,\\s*"));
+ JSONObject Result = new JSONObject();
+ String returnCode= "200";
+ String returnMessage="";
+ for (int i = 0; i < nodes.size(); i++){
+ String node=nodes.get(i);
+ String chefAction="/nodes/"+node;
+
+ String message = null;
+ if (privateKeyCheck()) {
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
+ ApiMethod am = cac.get(chefAction);
+ am.execute();
+ code = am.getReturnCode();
+ message = am.getResponseBodyAsString();
+ } else {
+ code = 500;
+ message = "Cannot find the private key in the APPC file system, please load the private key to "
+ + clientPrivatekey;
+ doFailure(ctx,code,message);
+ }
+ if (code==200){
+ JSONObject nodeResult = new JSONObject();
+ JSONObject allNodeData = new JSONObject(message);
+ allNodeData=allNodeData.getJSONObject("normal");
+ String attribute= "PushJobOutput";
+ String resultData;
+
+ try {
+ resultData = allNodeData.getString(attribute);
+ } catch (Exception exc1) {
+ try {
+ resultData = allNodeData.getJSONObject(attribute).toString();
+ } catch (Exception exc2) {
+ try {
+ resultData = allNodeData.getJSONArray(attribute).toString();
+ }catch (Exception exc3){
+ returnCode = "500";
+ returnMessage="cannot find "+attribute;
+ break;
+ }
+ }
+ }
+ nodeResult.put(attribute,resultData);
+
+ Result.put(node,nodeResult);
+ }else{
+ returnCode="500";
+ returnMessage = message+" Cannot access: "+ node;
+ doFailure(ctx,code,message);
+ break;
+ }
+
+ }
+ RequestContext rc = new RequestContext(ctx);
+ rc.isAlive();
+ if (!returnCode.equals("500")){
+ returnMessage=Result.toString();
+ returnCode="200";
+ }
+ chefServerResult(rc, returnCode, returnMessage);
+ }
+
+ else
+ {
+ throw new SvcLogicException("Missing Mandatory param(s) NodeList ");
+ }
+ }
+ catch(JSONException e){
+ code =401;
+ doFailure(ctx, code, "Error posting request due to invalid JSON block. Reason = " + e.getMessage());
+ }
+ catch(Exception ex){
+ code =401;
+ doFailure(ctx, code, "Error posting request :Reason = " + ex.getMessage());
+ }
+
}
/**
* build node object
*/
+ @SuppressWarnings("nls")
@Override
public void nodeObejctBuilder(Map<String, String> params, SvcLogicContext ctx) {
logger.info("nodeObejctBuilder");
- String name = params.get("org.onap.appc.instance.nodeobject.name");
- String normal = params.get("org.onap.appc.instance.nodeobject.normal");
- String overrides = params.get("org.onap.appc.instance.nodeobject.overrides");
- String defaults = params.get("org.onap.appc.instance.nodeobject.defaults");
- String runList = params.get("org.onap.appc.instance.nodeobject.run_list");
- String chefEnvironment = params.get("org.onap.appc.instance.nodeobject.chef_environment");
+ String name = params.get("nodeobject.name");
+ String normal = params.get("nodeobject.normal");
+ String overrides = params.get("nodeobject.overrides");
+ String defaults = params.get("nodeobject.defaults");
+ String runList = params.get("nodeobject.run_list");
+ String chefEnvironment = params.get("nodeobject.chef_environment");
String nodeObject = "{\"json_class\":\"Chef::Node\",\"default\":{" + defaults
+ "},\"chef_type\":\"node\",\"run_list\":[" + runList + "],\"override\":{" + overrides
+ "},\"normal\": {" + normal + "},\"automatic\":{},\"name\":\"" + name + "\",\"chef_environment\":\""
@@ -134,37 +471,55 @@ public class ChefAdapterImpl implements ChefAdapter {
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
SvcLogicContext svcLogic = rc.getSvcLogicContext();
- svcLogic.setAttribute("org.onap.appc.chef.nodeObject", nodeObject);
+ svcLogic.setAttribute("chef.nodeObject", nodeObject);
}
/**
* send get request to chef server
+ * @throws SvcLogicException
*/
- public void chefInfo(Map<String, String> params) {
- clientName = params.get("org.onap.appc.instance.username");
- serverAddress = params.get("org.onap.appc.instance.serverAddress");
- organizations = params.get("org.onap.appc.instance.organizations");
- chefserver = "https://" + serverAddress + ORGANIZATIONS_STR + organizations;
- if (params.containsKey("org.onap.appc.instance.pemPath")) {
- clientPrivatekey = params.get("org.onap.appc.instance.pemPath");
- } else {
- clientPrivatekey = "/opt/app/bvc/chef/" + serverAddress + "/" + organizations + "/" + clientName + ".pem";
+ public void chefInfo(Map<String, String> params,SvcLogicContext ctx) throws SvcLogicException {
+
+ username = params.get("username");
+ serverAddress = params.get("serverAddress");
+ organizations = params.get("organizations");
+ if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(serverAddress)&& StringUtils.isNotBlank(organizations))
+ {
+ chefserver = "https://" + serverAddress + "/organizations/" + organizations;
+ clientPrivatekey = "/opt/app/bvc/chef/" + serverAddress + "/" + organizations + "/" + username + ".pem";
+ logger.info( " clientPrivatekey " + clientPrivatekey);
}
+ else
+ {
+ String message ="Missing mandatory param(s) such as username,serverAddres,organizations";
+ doFailure(ctx,401,message);
+
+ }
+
+
}
public Boolean privateKeyCheck() {
File f = new File(clientPrivatekey);
- return f.exists();
- }
+ if (f.exists()) {
+ logger.info( "Key exists");
+ return true;
+
+ } else {
+ logger.info( "Key doesnot exists");
+ return false;
+ }
+ }
+ @SuppressWarnings("nls")
@Override
public void retrieveData(Map<String, String> params, SvcLogicContext ctx) {
- String allConfigData = params.get("org.onap.appc.instance.allConfig");
- String key = params.get("org.onap.appc.instance.key");
- String dgContext = params.get("org.onap.appc.instance.dgContext");
+ String contextData = "someValue";
+ String allConfigData = params.get("allConfig");
+ String key = params.get("key");
+ String dgContext = params.get("dgContext");
JSONObject josnConfig = new JSONObject(allConfigData);
- String contextData;
try {
contextData = josnConfig.getString(key);
} catch (Exception ex) {
@@ -181,12 +536,13 @@ public class ChefAdapterImpl implements ChefAdapter {
svcLogic.setAttribute(dgContext, contextData);
}
+ @SuppressWarnings("nls")
@Override
public void combineStrings(Map<String, String> params, SvcLogicContext ctx) {
- String string1 = params.get("org.onap.appc.instance.String1");
- String string2 = params.get("org.onap.appc.instance.String2");
- String dgContext = params.get("org.onap.appc.instance.dgContext");
+ String string1 = params.get("String1");
+ String string2 = params.get("String2");
+ String dgContext = params.get("dgContext");
String contextData = string1 + string2;
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
@@ -196,43 +552,51 @@ public class ChefAdapterImpl implements ChefAdapter {
/**
* Send GET request to chef server
+ * @throws SvcLogicException
*/
+ @SuppressWarnings("nls")
+
@Override
- public void chefGet(Map<String, String> params, SvcLogicContext ctx) {
+ public void chefGet(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
logger.info("chef get method");
- chefInfo(params);
- String chefAction = params.get(CHEF_ACTION_STR);
+ chefInfo(params,ctx);
+ String chefAction = params.get("chefAction");
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
int code;
- String message;
+ String message = null;
+
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.get(chefAction);
am.execute();
code = am.getReturnCode();
message = am.getResponseBodyAsString();
} else {
code = 500;
- message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
+ message = "Cannot find the private key in the APPC file system, please load the private key to "
+ + clientPrivatekey;
}
chefServerResult(rc, Integer.toString(code), message);
}
/**
* Send PUT request to chef server
+ * @throws SvcLogicException
*/
+ @SuppressWarnings("nls")
+
@Override
- public void chefPut(Map<String, String> params, SvcLogicContext ctx) {
- chefInfo(params);
- String chefAction = params.get(CHEF_ACTION_STR);
- String chefNodeStr = params.get("org.onap.appc.instance.chefRequestBody");
+ public void chefPut(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ chefInfo(params,ctx);
+ String chefAction = params.get("chefAction");
+ String chefNodeStr = params.get("chefRequestBody");
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
int code;
String message;
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.put(chefAction).body(chefNodeStr);
am.execute();
@@ -240,7 +604,9 @@ public class ChefAdapterImpl implements ChefAdapter {
message = am.getResponseBodyAsString();
} else {
code = 500;
- message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
+ message = "Cannot find the private key in the APPC file system, please load the private key to "
+ + clientPrivatekey;
+
}
logger.info(code + " " + message);
chefServerResult(rc, Integer.toString(code), message);
@@ -248,14 +614,15 @@ public class ChefAdapterImpl implements ChefAdapter {
/**
* send Post request to chef server
+ * @throws SvcLogicException
*/
@Override
- public void chefPost(Map<String, String> params, SvcLogicContext ctx) {
- chefInfo(params);
+ public void chefPost(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ chefInfo(params,ctx);
logger.info("chef Post method");
- logger.info(clientName + " " + clientPrivatekey + " " + chefserver + " " + organizations);
- String chefNodeStr = params.get("org.onap.appc.instance.chefRequestBody");
- String chefAction = params.get(CHEF_ACTION_STR);
+ logger.info(username + " " + clientPrivatekey + " " + chefserver + " " + organizations);
+ String chefNodeStr = params.get("chefRequestBody");
+ String chefAction = params.get("chefAction");
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
@@ -263,7 +630,7 @@ public class ChefAdapterImpl implements ChefAdapter {
String message;
// should load pem from somewhere else
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
// need pass path into it
// "/nodes/testnode"
@@ -281,25 +648,28 @@ public class ChefAdapterImpl implements ChefAdapter {
/**
* send delete request to chef server
+ * @throws SvcLogicException
*/
@Override
- public void chefDelete(Map<String, String> params, SvcLogicContext ctx) {
+ public void chefDelete(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
logger.info("chef delete method");
- chefInfo(params);
- String chefAction = params.get(CHEF_ACTION_STR);
+ chefInfo(params,ctx);
+ String chefAction = params.get("chefAction");
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
int code;
- String message;
+ String message =null;
if (privateKeyCheck()) {
- ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.delete(chefAction);
am.execute();
code = am.getReturnCode();
message = am.getResponseBodyAsString();
} else {
code = 500;
- message = CANNOT_FIND_PRIVATE_KEY_STR + clientPrivatekey;
+ message = "Cannot find the private key in the APPC file system, please load the private key to "
+ + clientPrivatekey;
+
}
logger.info(code + " " + message);
chefServerResult(rc, Integer.toString(code), message);
@@ -311,13 +681,13 @@ public class ChefAdapterImpl implements ChefAdapter {
@Override
public void trigger(Map<String, String> params, SvcLogicContext ctx) {
logger.info("Run trigger method");
- String tVmIp = params.get("org.onap.appc.instance.ip");
+ String tVmIp = params.get("ip");
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpGet httpGet = new HttpGet(tVmIp);
- HttpResponse response;
+ HttpResponse response = null;
response = httpClient.execute(httpGet);
int responseCode = response.getStatusLine().getStatusCode();
HttpEntity entity = response.getEntity();
@@ -329,12 +699,21 @@ public class ChefAdapterImpl implements ChefAdapter {
}
}
+ @SuppressWarnings("nls")
@Override
- public void checkPushJob(Map<String, String> params, SvcLogicContext ctx) {
- chefInfo(params);
- String jobID = params.get("org.onap.appc.instance.jobid");
- int retryTimes = Integer.parseInt(params.get("org.onap.appc.instance.retryTimes"));
- int retryInterval = Integer.parseInt(params.get("org.onap.appc.instance.retryInterval"));
+ public void checkPushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ int code;
+ try {
+ chefInfo(params,ctx);
+ String jobID = params.get("jobid");
+ String retry= params.get("retryTimes");
+ String intrva= params.get("retryInterval");
+ if (StringUtils.isNotBlank(retry) && StringUtils.isNotBlank(intrva))
+ {
+
+ int retryTimes = Integer.parseInt(params.get("retryTimes"));
+ int retryInterval = Integer.parseInt(params.get("retryInterval"));
+
String chefAction = "/pushy/jobs/" + jobID;
RequestContext rc = new RequestContext(ctx);
@@ -348,57 +727,80 @@ public class ChefAdapterImpl implements ChefAdapter {
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
}
- ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.get(chefAction);
am.execute();
- int code = am.getReturnCode();
+ code = am.getReturnCode();
message = am.getResponseBodyAsString();
JSONObject obj = new JSONObject(message);
status = obj.getString("status");
- if (!"running".equals(status)) {
+ if (!status.equals("running")) {
logger.info(i + " time " + code + " " + status);
break;
}
}
- if ("complete".equals(status)) {
- svcLogic.setAttribute("org.onap.appc.chefServerResult.code", "200");
- svcLogic.setAttribute("org.onap.appc.chefServerResult.message", message);
+ if (status.equals("complete")) {
+ svcLogic.setAttribute("chefServerResult.code", "200");
+ svcLogic.setAttribute("chefServerResult.message", message);
} else {
- if ("running".equals(status)) {
- svcLogic.setAttribute("org.onap.appc.chefServerResult.code", "202");
- svcLogic.setAttribute("org.onap.appc.chefServerResult.message", "chef client runtime out");
+ if (status.equals("running")) {
+ svcLogic.setAttribute("chefServerResult.code", "202");
+ svcLogic.setAttribute("chefServerResult.message", "chef client runtime out");
} else {
- svcLogic.setAttribute("org.onap.appc.chefServerResult.code", "500");
- svcLogic.setAttribute("org.onap.appc.chefServerResult.message", message);
+ svcLogic.setAttribute("chefServerResult.code", "500");
+ svcLogic.setAttribute("chefServerResult.message", message);
}
}
+ }
+
+ else
+ {
+ throw new SvcLogicException("Missing Mandatory param(s) retryTimes , retryInterval ");
+
+ }
+ }
+ catch(Exception e)
+ {
+ code = 401;
+ doFailure(ctx,code,e.getMessage());
+ }
+
}
-
+ @SuppressWarnings("nls")
@Override
- public void pushJob(Map<String, String> params, SvcLogicContext ctx) {
- chefInfo(params);
- String pushRequest = params.get("org.onap.appc.instance.pushRequest");
+ public void pushJob(Map<String, String> params, SvcLogicContext ctx) throws SvcLogicException {
+ int code;
+ try{
+ chefInfo(params,ctx);
+ String pushRequest = params.get("pushRequest");
String chefAction = "/pushy/jobs";
RequestContext rc = new RequestContext(ctx);
rc.isAlive();
SvcLogicContext svcLogic = rc.getSvcLogicContext();
- ChefApiClient cac = new ChefApiClient(clientName, clientPrivatekey, chefserver, organizations);
+ ChefApiClient cac = new ChefApiClient(username, clientPrivatekey, chefserver, organizations);
ApiMethod am = cac.post(chefAction).body(pushRequest);
am.execute();
- int code = am.getReturnCode();
+ code = am.getReturnCode();
String message = am.getResponseBodyAsString();
if (code == 201) {
int startIndex = message.indexOf("jobs") + 6;
int endIndex = message.length() - 2;
String jobID = message.substring(startIndex, endIndex);
- svcLogic.setAttribute("org.onap.appc.jobID", jobID);
+ svcLogic.setAttribute("jobID", jobID);
logger.info(jobID);
}
chefServerResult(rc, Integer.toString(code), message);
+ }
+ catch(Exception e)
+ {
+ code = 401;
+ doFailure(ctx,code,e.getMessage());
+ }
}
-
+
+ @SuppressWarnings("static-method")
private void doFailure(RequestContext rc, int code, String message) {
SvcLogicContext svcLogic = rc.getSvcLogicContext();
String msg = (message == null) ? Integer.toString(code) : message;
@@ -410,11 +812,11 @@ public class ChefAdapterImpl implements ChefAdapter {
try {
status = Integer.toString(code);
} catch (Exception e) {
- logger.info("Couldn't covert " + code + " to an Integer, defaulting status to 500", e);
+
status = "500";
}
- svcLogic.setAttribute("org.onap.appc.chefAgent.code", status);
- svcLogic.setAttribute("org.onap.appc.chefAgent.message", msg);
+ svcLogic.setAttribute("chefAgent.code", status);
+ svcLogic.setAttribute("chefAgent.message", msg);
}
/**
@@ -422,48 +824,54 @@ public class ChefAdapterImpl implements ChefAdapter {
* The request context that manages the state and recovery of the
* request for the life of its processing.
*/
+ @SuppressWarnings("static-method")
private void doSuccess(RequestContext rc) {
SvcLogicContext svcLogic = rc.getSvcLogicContext();
- svcLogic.setAttribute("org.onap.appc.chefAgent.code", "200");
+ svcLogic.setAttribute("chefAgent.code", "200");
}
-
+ @SuppressWarnings("static-method")
private void chefServerResult(RequestContext rc, String code, String message) {
+ String msg = (message == null) ? " " : message;
SvcLogicContext svcLogic = rc.getSvcLogicContext();
svcLogic.setStatus(OUTCOME_SUCCESS);
- svcLogic.setAttribute("org.onap.appc.chefServerResult.code", code);
- svcLogic.setAttribute("org.onap.appc.chefServerResult.message", message);
+ svcLogic.setAttribute("chefServerResult.code", code);
+ svcLogic.setAttribute("chefServerResult.message", message);
+ logger.info("chefServerResult.code"+svcLogic.getAttribute("chefServerResult.code"));
+ logger.info("chefServerResult.message"+svcLogic.getAttribute("chefServerResult.message"));
}
-
+ @SuppressWarnings("static-method")
private void chefClientResult(RequestContext rc, String code, String message) {
+ String msg = (message == null) ? " " : message;
SvcLogicContext svcLogic = rc.getSvcLogicContext();
svcLogic.setStatus(OUTCOME_SUCCESS);
- svcLogic.setAttribute("org.onap.appc.chefClientResult.code", code);
- svcLogic.setAttribute("org.onap.appc.chefClientResult.message", message);
+ svcLogic.setAttribute("chefClientResult.code", code);
+ svcLogic.setAttribute("chefClientResult.message", message);
+ logger.info("chefClientResult.code"+svcLogic.getAttribute("chefClientResult.code"));
+ logger.info("chefClientResult.message"+svcLogic.getAttribute("chefClientResult.message"));
}
/**
* initialize the provider adapter by building the context cache
*/
private void initialize() {
- configuration = ConfigurationFactory.getConfiguration();
- // need to fetch data from appc configurator or form some file in the appc vms
- clientName = "testnode";
- clientPrivatekey = System.getProperty("user.dir") + "/src/test/resources/testclient.pem";
- serverAddress = "http://example.com";
- organizations = "test";
- chefserver = serverAddress + ORGANIZATIONS_STR + organizations;
+
logger.info("Initialize Chef Adapter");
}
- private void initialize(String key) {
- configuration = ConfigurationFactory.getConfiguration();
- // need to fetch data from appc configurator or form some file in the appc vms
- clientName = "testnode";
- clientPrivatekey = key;
- serverAddress = "http://example.com";
- organizations = "test";
- chefserver = serverAddress + ORGANIZATIONS_STR + organizations;
- logger.info("Initialize Chef Adapter");
- }
+
+ @SuppressWarnings("static-method")
+ private void doFailure(SvcLogicContext svcLogic, int code, String message) throws SvcLogicException {
+
+ if (message.contains("\n")) {
+ message = message.substring(message.indexOf("\n"));
+ }
+ svcLogic.setStatus(OUTCOME_FAILURE);
+ svcLogic.setAttribute("chefServerResult.code",Integer.toString(code));
+ svcLogic.setAttribute("chefServerResult.message",message);
+
+ throw new SvcLogicException("Chef Adapater Error = " + message );
+ }
+
+
}
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/TestChefApiClient.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/TestChefApiClient.java
index 5ea152a8d..bf718ab2f 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/TestChefApiClient.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/chefclient/TestChefApiClient.java
@@ -1,3 +1,27 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
package org.onap.appc.adapter.chef.chefclient;
import static org.junit.Assert.assertEquals;
@@ -51,7 +75,7 @@ public class TestChefApiClient {
@Test
public void testGet(){
Get get = client.get(props.getProperty("org.onap.appc.adapter.chef.chefclient.path"));
- ApiMethod method = get.createRequest();
+ ApiMethod method = get.execute();
String[] response = method.test.split("\n");
thenStringShouldMatch("GET", response);
@@ -60,7 +84,7 @@ public class TestChefApiClient {
@Test
public void testPut(){
Put put = client.put(props.getProperty("org.onap.appc.adapter.chef.chefclient.path"));
- ApiMethod method = put.createRequest();
+ ApiMethod method = put.execute();
String[] response = method.test.split("\n");
thenStringShouldMatch("PUT", response);
@@ -69,7 +93,7 @@ public class TestChefApiClient {
@Test
public void testPost() {
Post post = client.post(props.getProperty("org.onap.appc.adapter.chef.chefclient.path"));
- ApiMethod method = post.createRequest();
+ ApiMethod method = post.execute();
String[] response = method.test.split("\n");
thenStringShouldMatch("POST", response);
@@ -78,7 +102,7 @@ public class TestChefApiClient {
@Test
public void testDelete(){
Delete delete = client.delete(props.getProperty("org.onap.appc.adapter.chef.chefclient.path"));
- ApiMethod method = delete.createRequest();
+ ApiMethod method = delete.execute();
String[] response = method.test.split("\n");
thenStringShouldMatch("DELETE", response);
diff --git a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java
index 687ba8338..d5a5d8cd0 100644
--- a/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java
+++ b/appc-adapters/appc-chef-adapter/appc-chef-adapter-bundle/src/test/java/org/onap/appc/adapter/chef/impl/TestChefAdapterImpl.java
@@ -36,6 +36,7 @@ import org.junit.Test;
import org.onap.appc.exceptions.APPCException;
import com.att.cdp.exceptions.ZoneException;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
public class TestChefAdapterImpl {
private SvcLogicContext svcContext;
@@ -49,7 +50,7 @@ public class TestChefAdapterImpl {
public void setup() {
adapter = new ChefAdapterImpl(Boolean.TRUE);
params = new HashMap<>();
- params.put("org.onap.appc.instance.pemPath",
+ params.put("pemPath",
"/src/test/resources/testclient.pem");
}
@@ -59,23 +60,23 @@ public class TestChefAdapterImpl {
svcContext = null;
getAttribute = null;
}
-
- @Test
+
+ @Test(expected=Exception.class)
public void testChefGetFail() throws IOException, IllegalStateException, IllegalArgumentException,
- ZoneException, APPCException {
- params.put("org.onap.appc.instance.chefAction", "/nodes");
+ ZoneException, APPCException,SvcLogicException {
+ params.put("chefAction", "/nodes");
givenParams(params, "chefGet");
thenResponseShouldFail();
}
- @Test
+ @Test(expected=Exception.class)
public void testChefPutFail() throws IOException, IllegalStateException, IllegalArgumentException,
- ZoneException, APPCException {
- params.put("org.onap.appc.instance.chefAction", "/nodes/testnode");
- params.put("org.onap.appc.instance.runList", "recipe[commandtest]");
- params.put("org.onap.appc.instance.attributes", "");
- params.put("org.onap.appc.instance.chefRequestBody", "Test Body");
+ ZoneException, APPCException,SvcLogicException {
+ params.put("chefAction", "/nodes/testnode");
+ params.put("runList", "recipe[commandtest]");
+ params.put("attributes", "");
+ params.put("chefRequestBody", "Test Body");
givenParams(params, "chefPut");
thenResponseShouldFail();
@@ -83,26 +84,26 @@ public class TestChefAdapterImpl {
@Test
public void testTriggerFail() throws IOException, IllegalStateException, IllegalArgumentException,
- ZoneException, APPCException {
- params.put("org.onap.appc.instance.ip", "");
+ ZoneException, APPCException,SvcLogicException {
+ params.put("ip", "");
givenParams(params, "trigger");
thenResponseShouldFail();
}
- private void givenParams(Map<String, String> adapterParams, String method) {
+ private void givenParams(Map<String, String> adapterParams, String method) throws SvcLogicException {
svcContext = new SvcLogicContext();
if (method == "chefGet"){
adapter.chefGet(adapterParams, svcContext);
- getAttribute = "org.onap.appc.chefServerResult.code";
+ getAttribute = "chefServerResult.code";
}
if (method == "chefPut"){
adapter.chefPut(adapterParams, svcContext);
- getAttribute = "org.onap.appc.chefServerResult.code";
+ getAttribute = "chefServerResult.code";
}
if (method == "trigger"){
adapter.trigger(adapterParams, svcContext);
- getAttribute = "org.onap.appc.chefAgent.code";
+ getAttribute = "chefAgent.code";
}
}
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/AppcDmaapAdapterActivator.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/AppcDmaapAdapterActivator.java
index 812f80121..a34169e06 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/AppcDmaapAdapterActivator.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/AppcDmaapAdapterActivator.java
@@ -28,7 +28,7 @@ import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceRegistration;
+
/**
@@ -50,7 +50,6 @@ import org.osgi.framework.ServiceRegistration;
* </p>
*/
public class AppcDmaapAdapterActivator implements BundleActivator {
- private ServiceRegistration registration = null;
/**
* The logger to be used
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/CommonHttpClient.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/CommonHttpClient.java
index 76b050d8e..e67007f64 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/CommonHttpClient.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/CommonHttpClient.java
@@ -50,19 +50,23 @@ public class CommonHttpClient {
}
public HttpGet getReq(URI uri, int timeoutMs) throws Exception {
- HttpGet out = (uri == null) ? new HttpGet() : new HttpGet(uri);
- if (AUTH_STR != null) {
- out.setHeader("Authorization", String.format("Basic %s", AUTH_STR));
+ if (AUTH_STR == null) {
+ throw new Exception("All DMaaP requests require authentication and none was provided.");
}
+
+ HttpGet out = (uri == null) ? new HttpGet() : new HttpGet(uri);
+ out.setHeader("Authorization", String.format("Basic %s", AUTH_STR));
out.setConfig(getConfig(timeoutMs));
return out;
}
public HttpPost postReq(String url) throws Exception {
- HttpPost out = (url == null) ? new HttpPost() : new HttpPost(url);
- if (AUTH_STR != null) {
- out.setHeader("Authorization", String.format("Basic %s", AUTH_STR));
+ if (AUTH_STR == null) {
+ throw new Exception("All DMaaP requests require authentication and none was provided.");
}
+
+ HttpPost out = (url == null) ? new HttpPost() : new HttpPost(url);
+ out.setHeader("Authorization", String.format("Basic %s", AUTH_STR));
out.setConfig(getConfig(0));
return out;
}
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapConsumerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapConsumerImpl.java
index df81e9718..6be34553c 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapConsumerImpl.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapConsumerImpl.java
@@ -44,12 +44,11 @@ import org.onap.appc.adapter.message.Consumer;
public class HttpDmaapConsumerImpl extends CommonHttpClient implements Consumer {
- private static final EELFLogger LOG = EELFManager.getInstance().getLogger(HttpDmaapConsumerImpl.class);
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(HttpDmaapConsumerImpl.class);
// Default values
private static final int DEFAULT_TIMEOUT_MS = 15000;
private static final int DEFAULT_LIMIT = 1000;
- private static final String HTTPS_PORT = ":3905";
private static final String URL_TEMPLATE = "%s/events/%s/%s/%s";
private List<String> urls;
@@ -57,9 +56,6 @@ public class HttpDmaapConsumerImpl extends CommonHttpClient implements Consumer
private boolean useHttps = false;
- public HttpDmaapConsumerImpl(Collection<String> hosts, String topicName, String consumerName, String consumerId) {
- this(hosts, topicName, consumerName, consumerId, null);
- }
public HttpDmaapConsumerImpl(Collection<String> hosts, String topicName, String consumerName, String consumerId,
String filter) {
@@ -85,9 +81,9 @@ public class HttpDmaapConsumerImpl extends CommonHttpClient implements Consumer
@Override
public List<String> fetch(int waitMs, int limit) {
LOG.debug(String.format("Fetching up to %d records with %dms wait on %s", limit, waitMs, this.toString()));
- List<String> out = new ArrayList<String>();
+ List<String> out = new ArrayList<>();
try {
- List<NameValuePair> urlParams = new ArrayList<NameValuePair>();
+ List<NameValuePair> urlParams = new ArrayList<>();
urlParams.add(new BasicNameValuePair("timeout", String.valueOf(waitMs)));
urlParams.add(new BasicNameValuePair("limit", String.valueOf(limit)));
if (filter != null) {
@@ -141,7 +137,7 @@ public class HttpDmaapConsumerImpl extends CommonHttpClient implements Consumer
@Override
public String toString() {
- String hostStr = (urls == null || urls.isEmpty()) ? "N/A" : urls.get(0);
+ String hostStr = (urls == null && !urls.isEmpty()) ? "N/A" : urls.get(0);
return String.format("Consumer listening to [%s]", hostStr);
}
@@ -159,9 +155,9 @@ public class HttpDmaapConsumerImpl extends CommonHttpClient implements Consumer
}
}
- @Override
- public void close() {
- // Nothing to do
- }
+ @Override
+ public void close() {
+ // Nothing to do
+ }
}
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapProducerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapProducerImpl.java
index 560c09be4..74c0c26b2 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapProducerImpl.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/http/HttpDmaapProducerImpl.java
@@ -41,7 +41,7 @@ import org.onap.appc.adapter.message.Producer;
public class HttpDmaapProducerImpl extends CommonHttpClient implements Producer {
- private static final EELFLogger LOG = EELFManager.getInstance().getLogger(HttpDmaapProducerImpl.class);
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(HttpDmaapProducerImpl.class);
private static final String CONTENT_TYPE = "application/cambria";
private static final String URL_TEMPLATE = "%s/events/%s";
@@ -52,8 +52,8 @@ public class HttpDmaapProducerImpl extends CommonHttpClient implements Producer
private boolean useHttps = false;
public HttpDmaapProducerImpl(Collection<String> urls, String topicName) {
- hosts = new ArrayList<String>();
- topics = new HashSet<String>();
+ hosts = new ArrayList<>();
+ topics = new HashSet<>();
topics.add(topicName);
for (String host : urls) {
@@ -61,14 +61,6 @@ public class HttpDmaapProducerImpl extends CommonHttpClient implements Producer
}
}
- public HttpDmaapProducerImpl(Collection<String> urls, Set<String> topicNames) {
- hosts = new ArrayList<String>();
- topics = topicNames;
-
- for (String host : urls) {
- hosts.add(formatHostString(host));
- }
- }
@Override
public void updateCredentials(String user, String pass) {
@@ -131,8 +123,8 @@ public class HttpDmaapProducerImpl extends CommonHttpClient implements Producer
return String.format("%d.%d.%s%s", p.length(), m.length(), p, m);
}
- @Override
- public void close() {
- // Nothing to do
- }
+ @Override
+ public void close() {
+ // Nothing to do
+ }
}
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java
index ddf630545..155f34bfc 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapConsumerImpl.java
@@ -53,14 +53,13 @@ import org.osgi.framework.ServiceReference;
public class DmaapConsumerImpl implements Consumer {
- private static final EELFLogger LOG = EELFManager.getInstance().getLogger(DmaapConsumerImpl.class);
- private static final Configuration configuration = ConfigurationFactory.getConfiguration();
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(DmaapConsumerImpl.class);
+ private final Configuration configuration = ConfigurationFactory.getConfiguration();
// Default values
private static final int DEFAULT_TIMEOUT_MS = 60000;
private static final int DEFAULT_LIMIT = 1000;
private static MetricRegistry metricRegistry;
private String topic;
- private DmaapRequestCounterMetric dmaapKpiMetric;
private boolean isMetricEnabled=false;
private boolean useHttps = false;
private MRConsumer client = null;
@@ -91,7 +90,7 @@ public class DmaapConsumerImpl implements Consumer {
LOG.debug("Metric getting initialized");
MetricService metricService = getMetricservice();
metricRegistry = metricService.createRegistry("APPC");
- dmaapKpiMetric = metricRegistry.metricBuilderFactory().
+ DmaapRequestCounterMetric dmaapKpiMetric = metricRegistry.metricBuilderFactory().
dmaapRequestCounterBuilder().
withName("DMAAP_KPI").withType(MetricType.COUNTER).
withRecievedMessage(0)
@@ -111,9 +110,7 @@ public class DmaapConsumerImpl implements Consumer {
LOG.debug("Metric initialized");
}
}
- private MRConsumer getClient() {
- return getClient(DEFAULT_TIMEOUT_MS, DEFAULT_LIMIT);
- }
+
/**
* @return An instance of MRConsumer created from our class variables
@@ -133,10 +130,8 @@ public class DmaapConsumerImpl implements Consumer {
@Override
public synchronized void updateCredentials(String key, String secret) {
LOG.info(String.format("Setting auth to %s for %s", key, this.toString()));
- String user = key;
- String password = secret;
- props.setProperty("user",String.valueOf(user));
- props.setProperty("password",String.valueOf(password));
+ props.setProperty("user",String.valueOf(key));
+ props.setProperty("password",String.valueOf(secret));
client = null;
}
@@ -150,13 +145,13 @@ public class DmaapConsumerImpl implements Consumer {
initMetric();
}
LOG.debug(String.format("Fetching up to %d records with %dms wait on %s", limit, waitMs, this.toString()));
- List<String> out = new ArrayList<String>();
+ List<String> out = new ArrayList<>();
// Create client once and reuse it on subsequent fetches. This is
// to support failover to other servers in the DMaaP cluster.
if (client == null) {
- LOG.info("Getting DMaaP Client ...");
- client = getClient(waitMs, limit);
+ LOG.info("Getting DMaaP Client ...");
+ client = getClient(waitMs, limit);
}
try {
for (String s : client.fetch(waitMs, limit)) {
@@ -187,10 +182,10 @@ public class DmaapConsumerImpl implements Consumer {
*/
@Override
public void close() {
- LOG.debug("Closing Dmaap consumer client....");
- if (client != null) {
- client.close();
- }
+ LOG.debug("Closing Dmaap consumer client....");
+ if (client != null) {
+ client.close();
+ }
}
@Override
@@ -228,7 +223,5 @@ public class DmaapConsumerImpl implements Consumer {
}
}
- public Metric getMetric(String name){
- return metricRegistry.metric(name);
- }
+
}
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java
index 7ed06a9e3..888b432b0 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/DmaapProducerImpl.java
@@ -24,16 +24,9 @@
package org.onap.appc.adapter.messaging.dmaap.impl;
-import java.io.*;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-//import com.att.nsa.cambria.client.CambriaBatchingPublisher;
-//import com.att.nsa.cambria.client.CambriaClientBuilders;
-//import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
-
import com.att.nsa.mr.client.MRBatchingPublisher;
import com.att.nsa.mr.client.MRClientFactory;
import org.apache.commons.lang3.StringUtils;
@@ -51,6 +44,14 @@ import org.onap.appc.metricservice.publisher.LogPublisher;
import org.osgi.framework.BundleContext;
import org.osgi.framework.FrameworkUtil;
import org.osgi.framework.ServiceReference;
+import java.io.IOException;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.TimeUnit;
+
public class DmaapProducerImpl implements Producer {
@@ -62,7 +63,6 @@ public class DmaapProducerImpl implements Producer {
private Properties props = null;
private static MetricRegistry metricRegistry;
private boolean useHttps = false;
- private DmaapRequestCounterMetric dmaapKpiMetric;
private boolean isMetricEnabled=false;
private Set<MRBatchingPublisher> clients;
@@ -94,7 +94,7 @@ public class DmaapProducerImpl implements Producer {
LOG.debug("Metric getting initialized");
MetricService metricService = getMetricservice();
metricRegistry=metricService.createRegistry("APPC");
- dmaapKpiMetric = metricRegistry.metricBuilderFactory().
+ DmaapRequestCounterMetric dmaapKpiMetric = metricRegistry.metricBuilderFactory().
dmaapRequestCounterBuilder().
withName("DMAAP_KPI").withType(MetricType.COUNTER).
withRecievedMessage(0)
@@ -116,7 +116,7 @@ public class DmaapProducerImpl implements Producer {
}
private Set<MRBatchingPublisher> getClients() {
- Set<MRBatchingPublisher> out = new HashSet<MRBatchingPublisher>();
+ Set<MRBatchingPublisher> out = new HashSet<>();
for (String topic : topics) {
try {
String topicProducerPropFileName = DmaapUtil.createProducerPropFile(topic,props);
@@ -133,10 +133,8 @@ public class DmaapProducerImpl implements Producer {
@Override
public synchronized void updateCredentials(String key, String secret) {
LOG.info(String.format("Setting auth to %s for %s", key, this.toString()));
- String user = key;
- String password = secret;
- props.setProperty("user",String.valueOf(user));
- props.setProperty("password",String.valueOf(password));
+ props.setProperty("user",String.valueOf(key));
+ props.setProperty("password",String.valueOf(secret));
clients = null;
}
@@ -154,8 +152,8 @@ public class DmaapProducerImpl implements Producer {
// Create clients once and reuse them on subsequent posts. This is
// to support failover to other servers in the Dmaap cluster.
if ((clients == null) || (clients.isEmpty())) {
- LOG.info("Getting CambriaBatchingPublisher Clients ...");
- clients = getClients();
+ LOG.info("Getting CambriaBatchingPublisher Clients ...");
+ clients = getClients();
}
for (MRBatchingPublisher client : clients) {
@@ -178,14 +176,14 @@ public class DmaapProducerImpl implements Producer {
*/
@Override
public void close() {
- if ((clients == null) || (clients.isEmpty())) {
- return;
- }
+ if ((clients == null) || (clients.isEmpty())) {
+ return;
+ }
- LOG.debug("Closing Dmaap producer clients....");
- for (MRBatchingPublisher client : clients) {
+ LOG.debug("Closing Dmaap producer clients....");
+ for (MRBatchingPublisher client : clients) {
try {
- client.close(1, TimeUnit.SECONDS);
+ client.close(1, TimeUnit.SECONDS);
} catch (IOException | InterruptedException e) {
LOG.warn(String.format("Failed to cleanly close Dmaap connection for [%s]", client));
e.printStackTrace();
@@ -199,10 +197,6 @@ public class DmaapProducerImpl implements Producer {
}
private MetricService getMetricservice() {
-/*
- return AppcDmaapAdapterActivator.getMetricService();
-*/
-
BundleContext bctx = FrameworkUtil.getBundle(MetricService.class).getBundleContext();
ServiceReference sref = bctx.getServiceReference(MetricService.class.getName());
if (sref != null) {
diff --git a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/EventSenderDmaapImpl.java b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/EventSenderDmaapImpl.java
index bf7649026..1ba474c6c 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/EventSenderDmaapImpl.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-dmaap-adapter-bundle/src/main/java/org/onap/appc/adapter/messaging/dmaap/impl/EventSenderDmaapImpl.java
@@ -27,24 +27,27 @@ package org.onap.appc.adapter.messaging.dmaap.impl;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-
-import java.util.*;
-import java.util.concurrent.ConcurrentHashMap;
-
import org.onap.appc.adapter.message.EventSender;
import org.onap.appc.adapter.message.MessageDestination;
import org.onap.appc.adapter.message.Producer;
import org.onap.appc.adapter.message.event.EventHeader;
import org.onap.appc.adapter.message.event.EventMessage;
import org.onap.appc.adapter.message.event.EventStatus;
-import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl;
import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
import org.onap.appc.exceptions.APPCException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.concurrent.ConcurrentHashMap;
+
public class EventSenderDmaapImpl implements EventSender
{
- private static final EELFLogger LOG = EELFManager.getInstance().getLogger(EventSenderDmaapImpl.class);
+ private final EELFLogger LOG = EELFManager.getInstance().getLogger(EventSenderDmaapImpl.class);
public static final String EVENT_TOPIC_WRITE = "dmaap.event.topic.write";
public static final String DMAAP_USERNAME = "dmaap.appc.username";
public static final String DMAAP_PASSWORD = "dmaap.appc.password";
diff --git a/appc-adapters/appc-dmaap-adapter/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java b/appc-adapters/appc-dmaap-adapter/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java
index 19eb4cea8..cb23f5faa 100644
--- a/appc-adapters/appc-dmaap-adapter/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java
+++ b/appc-adapters/appc-dmaap-adapter/appc-message-adapter-factory/src/main/java/org/onap/appc/adapter/factory/DmaapMessageAdapterFactoryImpl.java
@@ -30,29 +30,22 @@ import java.util.Set;
import org.onap.appc.adapter.message.Consumer;
import org.onap.appc.adapter.message.MessageAdapterFactory;
import org.onap.appc.adapter.message.Producer;
-
-import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapConsumerImpl;
-import org.onap.appc.adapter.messaging.dmaap.http.HttpDmaapProducerImpl;
-
import org.onap.appc.adapter.messaging.dmaap.impl.DmaapConsumerImpl;
import org.onap.appc.adapter.messaging.dmaap.impl.DmaapProducerImpl;
public class DmaapMessageAdapterFactoryImpl implements MessageAdapterFactory {
- //Set to true if the HttpDmaap... should be used instead of the regular Dmaap...
- private static final boolean HTTP = true;
-
- public Producer createProducer(Collection<String> pools, String writeTopic, String apiKey, String apiSecret) {
- return HTTP ? new HttpDmaapProducerImpl(pools, writeTopic) : new DmaapProducerImpl(pools, writeTopic,apiKey, apiSecret);
- }
+
+ public Producer createProducer(Collection<String> pools, String writeTopic, String apiKey, String apiSecret) {
+ return new DmaapProducerImpl(pools, writeTopic,apiKey, apiSecret);
+ }
- public Producer createProducer(Collection<String> pools, Set<String> writeTopics, String apiKey, String apiSecret) {
- return HTTP ? new HttpDmaapProducerImpl(pools, writeTopics) : new DmaapProducerImpl(pools, writeTopics, apiKey, apiSecret);
- }
+ public Producer createProducer(Collection<String> pools, Set<String> writeTopics, String apiKey, String apiSecret) {
+ return new DmaapProducerImpl(pools, writeTopics, apiKey, apiSecret);
+ }
- public Consumer createConsumer(Collection<String> pool, String readTopic,
- String clientName, String clientId, String filter_json, String apiKey, String apiSecret) {
- return HTTP ? new HttpDmaapConsumerImpl(pool, readTopic, clientName, clientId, apiKey, apiSecret, filter_json) :
- new DmaapConsumerImpl(pool, readTopic, clientName, clientId, apiKey, apiSecret, filter_json);
- }
+ public Consumer createConsumer(Collection<String> pool, String readTopic,
+ String clientName, String clientId, String filter_json, String apiKey, String apiSecret) {
+ return new DmaapConsumerImpl(pool, readTopic, clientName, clientId, apiKey, apiSecret, filter_json);
+ }
}
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java
index bae220d13..70438d7da 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/AppcNetconfAdapterActivator.java
@@ -43,13 +43,6 @@ public class AppcNetconfAdapterActivator implements BundleActivator {
private ServiceRegistration reporterRegistration = null;
private ServiceRegistration factoryRegistration = null;
private ServiceRegistration dbRegistration = null;
-
- /**
- * The reference to the actual implementation object that implements the services
- */
- private NetconfClientFactory clientFactory;
- private NetconfDataAccessService DAService;
-
/**
* The logger to be used
*/
@@ -73,24 +66,22 @@ public class AppcNetconfAdapterActivator implements BundleActivator {
@Override
public void start(BundleContext context) throws Exception {
if (registration == null) {
- clientFactory = new NetconfClientFactory();
+ /*
+ * The reference to the actual implementation object that implements the services
+ */
+ NetconfClientFactory clientFactory = new NetconfClientFactory();
factoryRegistration = context.registerService(NetconfClientFactory.class, clientFactory, null);
-
- DAService = new NetconfDataAccessServiceImpl();
+ NetconfDataAccessService DAService = new NetconfDataAccessServiceImpl();
//set dblib service
DbLibService dblibSvc = null;
ServiceReference sref = context.getServiceReference(DbLibService.class.getName());
- try{
dblibSvc = (DbLibService)context.getService(sref);
- }catch(Exception e){
- logger.error(e.getMessage());
- }
DAService.setDbLibService(dblibSvc);
///////////////////////////////////
factoryRegistration = context.registerService(NetconfDataAccessService.class, DAService, null);
}
- logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter");
+ //logger.info(Msg.COMPONENT_INITIALIZED, "NETCONF adapter");
}
/**
diff --git a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java
index f3cca8597..6ed181d1d 100644
--- a/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java
+++ b/appc-adapters/appc-netconf-adapter/appc-netconf-adapter-bundle/src/main/java/org/onap/appc/adapter/netconf/internal/NetconfDataAccessServiceImpl.java
@@ -39,7 +39,7 @@ import java.util.ArrayList;
public class NetconfDataAccessServiceImpl implements NetconfDataAccessService {
- private static EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class);
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(NetconfDataAccessServiceImpl.class);
public void setSchema(String schema) {
this.schema = schema;
diff --git a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java
index 37820a63d..9cf046fc6 100644
--- a/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java
+++ b/appc-adapters/appc-rest-healthcheck-adapter/appc-rest-healthcheck-adapter-bundle/src/main/java/org/onap/appc/adapter/restHealthcheck/impl/RestHealthcheckAdapterImpl.java
@@ -55,257 +55,115 @@ import java.io.IOException;
import java.net.InetAddress;
public class RestHealthcheckAdapterImpl implements RestHealthcheckAdapter {
-
- /**
- * The constant used to define the adapter name in the mapped diagnostic
- * context
- */
-
-
- @SuppressWarnings("nls")
- public static final String MDC_ADAPTER = "adapter";
-
- /**
- * The constant used to define the service name in the mapped diagnostic
- * context
- */
- @SuppressWarnings("nls")
- public static final String MDC_SERVICE = "service";
-
- /**
- * The constant for the status code for a failed outcome
- */
- @SuppressWarnings("nls")
- public static final String OUTCOME_FAILURE = "failure";
-
- /**
- * The constant for the status code for a successful outcome
- */
- @SuppressWarnings("nls")
- public static final String OUTCOME_SUCCESS = "success";
-
- /**
- * A constant for the property token "provider" used in the structured
- * property specifications
- */
- @SuppressWarnings("nls")
- public static final String PROPERTY_PROVIDER = "provider";
-
- /**
- * A constant for the property token "identity" used in the structured
- * property specifications
- */
- @SuppressWarnings("nls")
- public static final String PROPERTY_PROVIDER_IDENTITY = "identity";
-
- /**
- * A constant for the property token "name" used in the structured property
- * specifications
- */
- @SuppressWarnings("nls")
- public static final String PROPERTY_PROVIDER_NAME = "name";
-
- /**
- * A constant for the property token "tenant" used in the structured
- * property specifications
- */
- @SuppressWarnings("nls")
- public static final String PROPERTY_PROVIDER_TENANT = "tenant";
-
- /**
- * A constant for the property token "tenant name" used in the structured
- * property specifications
- */
- @SuppressWarnings("nls")
- public static final String PROPERTY_PROVIDER_TENANT_NAME = "name";
-
- /**
- * A constant for the property token "password" used in the structured
- * property specifications
- */
- @SuppressWarnings("nls")
- public static final String PROPERTY_PROVIDER_TENANT_PASSWORD = "password"; // NOSONAR
-
- /**
- * A constant for the property token "userid" used in the structured
- * property specifications
- */
- @SuppressWarnings("nls")
- public static final String PROPERTY_PROVIDER_TENANT_USERID = "userid";
-
- /**
- * A constant for the property token "type" used in the structured property
- * specifications
- */
- @SuppressWarnings("nls")
- public static final String PROPERTY_PROVIDER_TYPE = "type";
-
-
- @SuppressWarnings("nls")
- public static final String PING_SERVICE = "pingServer";
-
- /**
- * The logger to be used
- */
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckAdapterImpl.class);
-
- /**
- * The constant for a left parenthesis
- */
- private static final char LPAREN = '(';
-
- /**
- * The constant for a new line control code
- */
- private static final char NL = '\n';
-
- /**
- * The constant for a single quote
- */
- private static final char QUOTE = '\'';
-
- /**
- * The constant for a right parenthesis
- */
- private static final char RPAREN = ')';
-
- /**
- * The constant for a space
- */
- private static final char SPACE = ' ';
-
- /**
- * A reference to the adapter configuration object.
- */
- private Configuration configuration;
-
- /**
- * A cache of providers that are predefined.
- */
- // private Map<String /* provider name */, ProviderCache> providerCache;
-
- /**
- * This default constructor is used as a work around because the activator
- * wasnt getting called
- */
- /**
- * A cache of providers that are predefined.
- */
- // private Map<String /* provider name */, ProviderCache> providerCache;
-
- /**
- * This default constructor is used as a work around because the activator
- * wasnt getting called
- */
- public RestHealthcheckAdapterImpl() {
- initialize();
-
- }
-
-
- public RestHealthcheckAdapterImpl(boolean initialize) {
-
- if (initialize) {
- initialize();
-
- }
- }
-
-
- public RestHealthcheckAdapterImpl(Properties props) {
- initialize();
-
- }
-
-
- @Override
- public String getAdapterName() {
- return configuration.getProperty(Constants.PROPERTY_ADAPTER_NAME);
- }
-
- public void checkHealth(Map<String, String> params, SvcLogicContext ctx) {
- logger.info("VNF rest health check");
- String uri=params.get("VNF.URI");
- String endPoint=params.get("VNF.endpoint");
- String tUrl=uri+"/"+endPoint;
- RequestContext rc = new RequestContext(ctx);
- rc.isAlive();
-
- try(CloseableHttpClient httpClient = HttpClients.createDefault()) {
- HttpGet httpGet = new HttpGet(tUrl);
- HttpResponse response = null;
- response = httpClient.execute(httpGet);
- int responseCode=response.getStatusLine().getStatusCode();
- HttpEntity entity = response.getEntity();
- String responseOutput=EntityUtils.toString(entity);
- if(responseCode==200)
- {
- doSuccess(rc,responseCode,responseOutput);
- }
- else
- {
- doHealthCheckFailure(rc,responseCode,responseOutput);
- }
- } catch (Exception ex) {
- doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString());
- }
- }
-
-
-
-
- @SuppressWarnings("static-method")
- private void doFailure(RequestContext rc, HttpStatus code, String message) {
- SvcLogicContext svcLogic = rc.getSvcLogicContext();
- String msg = (message == null) ? code.getReasonPhrase() : message;
- if (msg.contains("\n")) {
- msg = msg.substring(msg.indexOf("\n"));
- }
-
- String status;
- try {
- status = Integer.toString(code.getStatusCode());
- } catch (Exception e) {
- status = "500";
- }
- svcLogic.setStatus(OUTCOME_FAILURE);
- svcLogic.setAttribute("healthcheck.result.code", "200");
- svcLogic.setAttribute("healthcheck.result.message", status+" "+msg);
- }
-
-
- /**
- * @param rc
- * The request context that manages the state and recovery of the
- * request for the life of its processing.
- */
- @SuppressWarnings("static-method")
- private void doHealthCheckFailure(RequestContext rc, int code, String message) {
- SvcLogicContext svcLogic = rc.getSvcLogicContext();
- String msg = Integer.toString(code)+" "+message;
- svcLogic.setAttribute("healthcheck.result.code", "200");
- svcLogic.setAttribute("healthcheck.result.message", msg);
-
- }
-
-
- @SuppressWarnings("static-method")
- private void doSuccess(RequestContext rc, int code, String message) {
- SvcLogicContext svcLogic = rc.getSvcLogicContext();
- String msg = Integer.toString(code)+" "+message;
- svcLogic.setAttribute("healthcheck.result.code", "400");
- svcLogic.setAttribute("healthcheck.result.message", msg);
-
- }
-
-
- /**
- * initialize the provider adapter by building the context cache
- */
- private void initialize() {
-
-
- logger.info("init rest health check adapter!!!!!");
- }
+ /**
+ * The constant for the status code for a failed outcome
+ */
+ @SuppressWarnings("nls")
+ public static final String OUTCOME_FAILURE = "failure";
+ /**
+ * The logger to be used
+ */
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(RestHealthcheckAdapterImpl.class);
+ /**
+ * A reference to the adapter configuration object.
+ */
+ private Configuration configuration;
+ /**
+ * This default constructor is used as a work around because the activator
+ * wasnt getting called
+ */
+ public RestHealthcheckAdapterImpl() {
+ initialize();
+
+ }
+
+ @Override
+ public String getAdapterName() {
+ return configuration.getProperty(Constants.PROPERTY_ADAPTER_NAME);
+ }
+
+ public void checkHealth(Map<String, String> params, SvcLogicContext ctx) {
+ logger.info("VNF rest health check");
+ String uri=params.get("VNF.URI");
+ String endPoint=params.get("VNF.endpoint");
+ String tUrl=uri+"/"+endPoint;
+ RequestContext rc = new RequestContext(ctx);
+ rc.isAlive();
+ try(CloseableHttpClient httpClient = HttpClients.createDefault()) {
+ HttpGet httpGet = new HttpGet(tUrl);
+ HttpResponse response =null ;
+ response = httpClient.execute(httpGet);
+ int responseCode=response.getStatusLine().getStatusCode();
+ HttpEntity entity = response.getEntity();
+ String responseOutput=EntityUtils.toString(entity);
+ if(responseCode==200)
+ {
+ doSuccess(rc,responseCode,responseOutput);
+ }
+ else
+ {
+ doHealthCheckFailure(rc,responseCode,responseOutput);
+ }
+ } catch (Exception ex) {
+ doFailure(rc, HttpStatus.INTERNAL_SERVER_ERROR_500, ex.toString());
+ }
+ }
+
+
+
+
+ @SuppressWarnings("static-method")
+ private void doFailure(RequestContext rc, HttpStatus code, String message) {
+ SvcLogicContext svcLogic = rc.getSvcLogicContext();
+ String msg = (message == null) ? code.getReasonPhrase() : message;
+ if (msg.contains("\n")) {
+ msg = msg.substring(msg.indexOf("\n"));
+ }
+
+ String status;
+ try {
+ status = Integer.toString(code.getStatusCode());
+ } catch (Exception e) {
+ status = "500";
+ }
+ svcLogic.setStatus(OUTCOME_FAILURE);
+ svcLogic.setAttribute("healthcheck.result.code", "200");
+ svcLogic.setAttribute("healthcheck.result.message", status+" "+msg);
+ }
+
+
+ /**
+ * @param rc
+ * The request context that manages the state and recovery of the
+ * request for the life of its processing.
+ */
+ @SuppressWarnings("static-method")
+ private void doHealthCheckFailure(RequestContext rc, int code, String message) {
+ SvcLogicContext svcLogic = rc.getSvcLogicContext();
+ String msg = Integer.toString(code)+" "+message;
+ svcLogic.setAttribute("healthcheck.result.code", "200");
+ svcLogic.setAttribute("healthcheck.result.message", msg);
+
+ }
+
+
+ @SuppressWarnings("static-method")
+ private void doSuccess(RequestContext rc, int code, String message) {
+ SvcLogicContext svcLogic = rc.getSvcLogicContext();
+ String msg = Integer.toString(code)+" "+message;
+ svcLogic.setAttribute("healthcheck.result.code", "400");
+ svcLogic.setAttribute("healthcheck.result.message", msg);
+
+ }
+
+
+ /**
+ * initialize the provider adapter by building the context cache
+ */
+ private void initialize() {
+
+
+ logger.info("init rest health check adapter!!!!!");
+ }
}