aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-11-16 13:40:22 +0100
committerDeterme, Sebastien (sd378r) <sd378r@intl.att.com>2017-11-16 14:00:03 +0100
commit98344de96ed80b839929be0bd272753675009a5d (patch)
treea8f8c8e42ecde5c2ef0558bd812dcfd4b3fa0b27
parent37677f517e384685ba9056a9e8d79f2fa734f192 (diff)
Refactor the java packages
Refactor the java packages, moving classes to others packages Change-Id: I5cd2a6477876ce187502afff37a862029a081ab3 Issue-ID: CLAMP-74 Signed-off-by: Determe, Sebastien (sd378r) <sd378r@intl.att.com>
-rw-r--r--src/main/java/org/onap/clamp/clds/Application.java15
-rw-r--r--src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java8
-rw-r--r--src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java21
-rw-r--r--src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java9
-rw-r--r--src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java14
-rw-r--r--src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java35
-rw-r--r--src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java3
-rw-r--r--src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java9
-rw-r--r--src/main/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegate.java1
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java (renamed from src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java)29
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java (renamed from src/main/java/org/onap/clamp/clds/client/PolicyClient.java)97
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java (renamed from src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java)231
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/sdc/SdcReq.java (renamed from src/main/java/org/onap/clamp/clds/client/req/SdcReq.java)101
-rw-r--r--src/main/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatter.java (renamed from src/main/java/org/onap/clamp/clds/client/req/TcaRequestFormatter.java)95
-rw-r--r--src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java6
-rw-r--r--src/main/java/org/onap/clamp/clds/dao/CldsDao.java55
-rw-r--r--src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java62
-rw-r--r--src/main/java/org/onap/clamp/clds/dao/ValueItemMapper.java42
-rw-r--r--src/main/java/org/onap/clamp/clds/exception/ModelPropertiesException.java61
-rw-r--r--src/main/java/org/onap/clamp/clds/model/prop/ModelBpmn.java68
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsService.java42
-rw-r--r--src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java17
-rw-r--r--src/test/java/org/onap/clamp/clds/AbstractItCase.java2
-rw-r--r--src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java1
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java27
-rw-r--r--src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java90
-rw-r--r--src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java3
-rw-r--r--src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java15
-rw-r--r--src/test/java/org/onap/clamp/clds/it/RefPropItCase.java8
-rw-r--r--src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java2
-rw-r--r--src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java7
-rw-r--r--src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java2
32 files changed, 592 insertions, 586 deletions
diff --git a/src/main/java/org/onap/clamp/clds/Application.java b/src/main/java/org/onap/clamp/clds/Application.java
index 0304a680..e2bfbd77 100644
--- a/src/main/java/org/onap/clamp/clds/Application.java
+++ b/src/main/java/org/onap/clamp/clds/Application.java
@@ -65,28 +65,22 @@ import org.springframework.scheduling.annotation.EnableAsync;
ManagementWebSecurityAutoConfiguration.class })
@EnableAsync
public class Application extends SpringBootServletInitializer {
-
- protected static final EELFLogger eelfLogger = EELFManager.getInstance().getLogger(Application.class);
-
+ protected static final EELFLogger EELF_LOGGER = EELFManager.getInstance().getLogger(Application.class);
@Autowired
- protected ApplicationContext appContext;
-
+ private ApplicationContext appContext;
private static final String CAMEL_SERVLET_NAME = "CamelServlet";
private static final String CAMEL_URL_MAPPING = "/restservices/clds/v1/*";
-
// This settings is an additional one to Spring config,
// only if we want to have an additional port automatically redirected to
// HTTPS
@Value("${server.http-to-https-redirection.port:none}")
private String httpRedirectedPort;
-
/**
* This 8080 is the default port used by spring if this parameter is not
* specified in application.properties.
*/
@Value("${server.port:8080}")
private String springServerPort;
-
@Value("${server.ssl.key-store:none}")
private String sslKeystoreFile;
@@ -139,15 +133,13 @@ public class Application extends SpringBootServletInitializer {
if (newConnector != null) {
tomcat.addAdditionalTomcatConnectors(newConnector);
}
-
}
return tomcat;
-
}
private Connector createRedirectConnector(int redirectSecuredPort) {
if (redirectSecuredPort <= 0) {
- eelfLogger.warn(
+ EELF_LOGGER.warn(
"HTTP port redirection to HTTPS is disabled because the HTTPS port is 0 (random port) or -1 (Connector disabled)");
return null;
}
@@ -158,5 +150,4 @@ public class Application extends SpringBootServletInitializer {
connector.setRedirectPort(redirectSecuredPort);
return connector;
}
-
}
diff --git a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
index 7662a9fc..53d17aaf 100644
--- a/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/DcaeInventoryServices.java
@@ -32,6 +32,7 @@ import java.security.GeneralSecurityException;
import java.util.Date;
import java.util.List;
+import org.apache.commons.codec.DecoderException;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
@@ -74,8 +75,11 @@ public class DcaeInventoryServices {
* In case of issue when decryting the DCAE password
* @throws ParseException
* In case of DCAE Json parse exception
+ * @throws DecoderException
+ * In case of issues with HexString decoding
*/
- public void setEventInventory(CldsModel cldsModel, String userId) throws GeneralSecurityException, ParseException {
+ public void setEventInventory(CldsModel cldsModel, String userId)
+ throws GeneralSecurityException, ParseException, DecoderException {
String artifactName = cldsModel.getControlName();
DcaeEvent dcaeEvent = new DcaeEvent();
String isDcaeInfoAvailable = null;
@@ -152,7 +156,9 @@ public class DcaeInventoryServices {
* The resource UUID
* @return The DCAE inventory for the artifact
* @throws IOException
+ * In case of issues with the stream
* @throws ParseException
+ * In case of issues with the Json parsing
*
*/
public String getDcaeInformation(String artifactName, String serviceUuid, String resourceUuid)
diff --git a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java
index 5e0d470e..aaa4a2c0 100644
--- a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDelegate.java
@@ -30,6 +30,7 @@ import java.util.UUID;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
import org.onap.clamp.clds.model.prop.Holmes;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.refprop.RefProp;
@@ -41,10 +42,8 @@ import org.springframework.beans.factory.annotation.Autowired;
public class HolmesPolicyDelegate implements JavaDelegate {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(HolmesPolicyDelegate.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-
@Autowired
private PolicyClient policyClient;
-
@Autowired
private RefProp refProp;
@@ -54,22 +53,30 @@ public class HolmesPolicyDelegate implements JavaDelegate {
* @param execution
*/
@Override
- public void execute(DelegateExecution execution) throws Exception {
+ public void execute(DelegateExecution execution) {
String holmesPolicyRequestUuid = UUID.randomUUID().toString();
execution.setVariable("holmesPolicyRequestUuid", holmesPolicyRequestUuid);
-
ModelProperties prop = ModelProperties.create(execution);
Holmes holmes = prop.getType(Holmes.class);
if (holmes.isFound()) {
- String responseMessage = policyClient.sendBasePolicyInOther(formatHolmesConfigBody(prop, holmes), holmes.getConfigPolicyName(), prop,
- holmesPolicyRequestUuid);
+ String responseMessage = policyClient.sendBasePolicyInOther(formatHolmesConfigBody(prop, holmes),
+ holmes.getConfigPolicyName(), prop, holmesPolicyRequestUuid);
if (responseMessage != null) {
execution.setVariable("holmesPolicyResponseMessage", responseMessage.getBytes());
}
}
}
- public static String formatHolmesConfigBody (ModelProperties prop, Holmes holmes) {
+ /**
+ * This method is used to create the Payload that must be sent to Holmes.
+ *
+ * @param prop
+ * The ModelProperties containing all the closed loop props
+ * @param holmes
+ * The holmes object extracted from the closed loop
+ * @return The String that must be sent to policy for holmes
+ */
+ public static String formatHolmesConfigBody(ModelProperties prop, Holmes holmes) {
return prop.getControlName() + "$$$" + holmes.getCorrelationLogic();
}
}
diff --git a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java
index c3c91fa8..72db3285 100644
--- a/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/HolmesPolicyDeleteDelegate.java
@@ -26,8 +26,11 @@ package org.onap.clamp.clds.client;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import java.io.IOException;
+
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
import org.onap.clamp.clds.model.prop.Holmes;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,7 +42,6 @@ public class HolmesPolicyDeleteDelegate implements JavaDelegate {
protected static final EELFLogger logger = EELFManager.getInstance()
.getLogger(HolmesPolicyDeleteDelegate.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-
@Autowired
private PolicyClient policyClient;
@@ -47,16 +49,15 @@ public class HolmesPolicyDeleteDelegate implements JavaDelegate {
* Perform activity. Delete Holmes Policy via policy api.
*
* @param execution
+ * @throws IOException
*/
@Override
- public void execute(DelegateExecution execution) throws Exception {
+ public void execute(DelegateExecution execution) {
ModelProperties prop = ModelProperties.create(execution);
Holmes holmes = prop.getType(Holmes.class);
if (holmes.isFound()) {
prop.setCurrentModelElementId(holmes.getId());
-
policyClient.deleteBasePolicy(prop);
}
}
-
}
diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
index 493b3b3c..e6af4336 100644
--- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDelegate.java
@@ -26,12 +26,13 @@ package org.onap.clamp.clds.client;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.Map;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
-import org.onap.clamp.clds.client.req.OperationalPolicyReq;
+import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.prop.Policy;
import org.onap.clamp.clds.model.prop.PolicyChain;
@@ -51,13 +52,11 @@ public class OperationalPolicyDelegate implements JavaDelegate {
protected static final EELFLogger logger = EELFManager.getInstance()
.getLogger(OperationalPolicyDelegate.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-
/**
* Automatically injected by Spring, define in CldsConfiguration as a bean.
*/
@Autowired
private PolicyClient policyClient;
-
/**
* Automatically injected by Spring, define in CldsConfiguration as a bean.
*/
@@ -71,13 +70,13 @@ public class OperationalPolicyDelegate implements JavaDelegate {
* The DelegateExecution
* @throws BuilderException
* In case of issues with OperationalPolicyReq
- * @throws IOException
- * In case of issues with the stream
* @throws PolicyEngineException
* In case of issues with the PolicyEngine creation
+ * @throws UnsupportedEncodingException
*/
@Override
- public void execute(DelegateExecution execution) throws IOException, BuilderException, PolicyEngineException {
+ public void execute(DelegateExecution execution)
+ throws BuilderException, PolicyEngineException, UnsupportedEncodingException {
String responseMessage = null;
String operationalPolicyRequestUuid = null;
ModelProperties prop = ModelProperties.create(execution);
@@ -94,5 +93,4 @@ public class OperationalPolicyDelegate implements JavaDelegate {
}
}
}
-
}
diff --git a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
index 2c60941c..2bca639e 100644
--- a/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/OperationalPolicyDeleteDelegate.java
@@ -23,16 +23,19 @@
package org.onap.clamp.clds.client;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.io.IOException;
+
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.prop.Policy;
import org.onap.clamp.clds.model.prop.PolicyChain;
import org.springframework.beans.factory.annotation.Autowired;
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
/**
* Delete Operational Policy via policy api.
*/
@@ -40,31 +43,29 @@ public class OperationalPolicyDeleteDelegate implements JavaDelegate {
protected static final EELFLogger logger = EELFManager.getInstance()
.getLogger(OperationalPolicyDeleteDelegate.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-
@Autowired
- private PolicyClient policyClient;
+ private PolicyClient policyClient;
/**
* Perform activity. Delete Operational Policy via policy api.
*
* @param execution
+ * @throws IOException
*/
@Override
- public void execute(DelegateExecution execution) throws Exception {
+ public void execute(DelegateExecution execution) {
ModelProperties prop = ModelProperties.create(execution);
Policy policy = prop.getType(Policy.class);
prop.setCurrentModelElementId(policy.getId());
-
String responseMessage = "";
- if(policy.isFound()){
- for (PolicyChain policyChain : policy.getPolicyChains()) {
- prop.setPolicyUniqueId(policyChain.getPolicyId());
- responseMessage = policyClient.deleteBrms(prop);
- }
- if (responseMessage != null) {
- execution.setVariable("operationalPolicyDeleteResponseMessage", responseMessage.getBytes());
- }
- }
+ if (policy.isFound()) {
+ for (PolicyChain policyChain : policy.getPolicyChains()) {
+ prop.setPolicyUniqueId(policyChain.getPolicyId());
+ responseMessage = policyClient.deleteBrms(prop);
+ }
+ if (responseMessage != null) {
+ execution.setVariable("operationalPolicyDeleteResponseMessage", responseMessage.getBytes());
+ }
+ }
}
-
}
diff --git a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java
index 90bdcb3a..b582349f 100644
--- a/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/SdcSendReqDelegate.java
@@ -30,7 +30,8 @@ import java.util.List;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
-import org.onap.clamp.clds.client.req.SdcReq;
+import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
+import org.onap.clamp.clds.client.req.sdc.SdcReq;
import org.onap.clamp.clds.model.DcaeEvent;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.refprop.RefProp;
diff --git a/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java b/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java
index 7de12683..2d7df844 100644
--- a/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/TcaPolicyDelegate.java
@@ -30,7 +30,8 @@ import java.util.UUID;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
-import org.onap.clamp.clds.client.req.TcaRequestFormatter;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
+import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.prop.Tca;
import org.onap.clamp.clds.model.refprop.RefProp;
@@ -44,10 +45,8 @@ import org.springframework.beans.factory.annotation.Autowired;
public class TcaPolicyDelegate implements JavaDelegate {
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(TcaPolicyDelegate.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-
@Autowired
private RefProp refProp;
-
@Autowired
PolicyClient policyClient;
@@ -60,16 +59,14 @@ public class TcaPolicyDelegate implements JavaDelegate {
public void execute(DelegateExecution execution) throws Exception {
String tcaPolicyRequestUuid = UUID.randomUUID().toString();
execution.setVariable("tcaPolicyRequestUuid", tcaPolicyRequestUuid);
-
ModelProperties prop = ModelProperties.create(execution);
Tca tca = prop.getType(Tca.class);
if (tca.isFound()) {
String policyJson = TcaRequestFormatter.createPolicyJson(refProp, prop);
- String responseMessage = policyClient.sendMicroServiceInOther(policyJson, prop, tcaPolicyRequestUuid);
+ String responseMessage = policyClient.sendMicroServiceInOther(policyJson, prop);
if (responseMessage != null) {
execution.setVariable("tcaPolicyResponseMessage", responseMessage.getBytes());
}
}
}
-
}
diff --git a/src/main/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegate.java b/src/main/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegate.java
index d3fb3f73..e88b720a 100644
--- a/src/main/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegate.java
+++ b/src/main/java/org/onap/clamp/clds/client/TcaPolicyDeleteDelegate.java
@@ -25,6 +25,7 @@ package org.onap.clamp.clds.client;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.camunda.bpm.engine.delegate.JavaDelegate;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.prop.Tca;
import org.springframework.beans.factory.annotation.Autowired;
diff --git a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java
index a5506da9..fcf6cda5 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/OperationalPolicyReq.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/OperationalPolicyReq.java
@@ -21,7 +21,7 @@
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.clamp.clds.client.req;
+package org.onap.clamp.clds.client.req.policy;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFLogger.Level;
@@ -67,7 +67,6 @@ public class OperationalPolicyReq {
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
private OperationalPolicyReq() {
-
}
/**
@@ -84,7 +83,6 @@ public class OperationalPolicyReq {
Global global = prop.getGlobal();
prop.setCurrentModelElementId(modelElementId);
prop.setPolicyUniqueId(policyChain.getPolicyId());
-
String templateName = "";
String operationTopic = "";
String notificationTopic = "";
@@ -110,24 +108,19 @@ public class OperationalPolicyReq {
controller = refProp.getStringValue("op.controller", global.getService());
}
String recipeTopic = refProp.getStringValue("op.recipeTopic", global.getService());
-
// ruleAttributes
Map<String, String> ruleAttributes = new HashMap<>();
-
if (operationTopic == null || operationTopic.isEmpty()) {
logger.info("templateName=" + templateName);
logger.info("recipeTopic=" + recipeTopic);
logger.info("notificationTopic=" + notificationTopic);
-
// if no operationTopic, then don't format yaml - use first policy
// from list
PolicyItem policyItem = policyChain.getPolicyItems().get(0);
-
ruleAttributes.put("templateName", templateName);
ruleAttributes.put("ClosedLoopControlName", prop.getControlNameAndPolicyUniqueId());
ruleAttributes.put("RecipeTopic", recipeTopic);
ruleAttributes.put("NotificationTopic", notificationTopic);
-
String recipe = policyItem.getRecipe();
String maxRetries = String.valueOf(policyItem.getMaxRetries());
String retryTimeLimit = String.valueOf(policyItem.getRetryTimeLimit());
@@ -140,32 +133,25 @@ public class OperationalPolicyReq {
ruleAttributes.put("MaxRetries", maxRetries);
ruleAttributes.put("RetryTimeLimit", retryTimeLimit);
ruleAttributes.put("ResourceId", targetResourceId);
-
} else {
logger.info("templateName=" + templateName);
logger.info("operationTopic=" + operationTopic);
logger.info("notificationTopic=" + notificationTopic);
-
// format yaml
String yaml = (tca != null && tca.isFound()) ? formateNodeBYaml(refProp, prop, modelElementId, policyChain)
: formatYaml(refProp, prop, modelElementId, policyChain);
-
ruleAttributes.put("templateName", templateName);
ruleAttributes.put("ClosedLoopControlName", prop.getControlNameAndPolicyUniqueId());
ruleAttributes.put("OperationTopic", operationTopic);
ruleAttributes.put("NotificationTopic", notificationTopic);
-
ruleAttributes.put("ControlLoopYaml", yaml);
}
-
// matchingAttributes
Map<String, String> matchingAttributes = new HashMap<>();
matchingAttributes.put("controller", controller);
-
Map<AttributeType, Map<String, String>> attributes = new HashMap<>();
attributes.put(AttributeType.RULE, ruleAttributes);
attributes.put(AttributeType.MATCHING, matchingAttributes);
-
return attributes;
}
@@ -180,22 +166,18 @@ public class OperationalPolicyReq {
*/
public static String formatYaml(RefProp refProp, ModelProperties prop, String modelElementId,
PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException {
-
// get property objects
Global global = prop.getGlobal();
prop.setCurrentModelElementId(modelElementId);
prop.setPolicyUniqueId(policyChain.getPolicyId());
-
// convert values to SDC objects
Service service = new Service(global.getService());
Resource[] vfResources = convertToResource(global.getResourceVf(), ResourceType.VF);
Resource[] vfcResources = convertToResource(global.getResourceVfc(), ResourceType.VFC);
-
// create builder
ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(prop.getControlName(),
policyChain.getTimeout(), service, vfResources);
builder.addResource(vfcResources);
-
// process each policy
Map<String, Policy> policyObjMap = new HashMap<>();
List<PolicyItem> policyItemList = orderParentFirst(policyChain.getPolicyItems());
@@ -219,12 +201,10 @@ public class OperationalPolicyReq {
refProp.getStringValue("op.policy.appc"), target, policyItem.getRecipe(), null,
policyItem.getMaxRetries(), policyItem.getRetryTimeLimit(), parentPolicyObj.getId(),
convertToPolicyResult(policyItem.getParentPolicyConditions()));
-
logger.info("policyObj.id=" + policyObj.getId() + "; parentPolicyObj.id=" + parentPolicyObj.getId());
}
policyObjMap.put(policyItem.getId(), policyObj);
}
-
//
// Build the specification
//
@@ -255,27 +235,22 @@ public class OperationalPolicyReq {
*/
public static String formateNodeBYaml(RefProp refProp, ModelProperties prop, String modelElementId,
PolicyChain policyChain) throws BuilderException, UnsupportedEncodingException {
-
// get property objects
Global global = prop.getGlobal();
prop.setCurrentModelElementId(modelElementId);
prop.setPolicyUniqueId(policyChain.getPolicyId());
-
// convert values to SDC objects
Service service = new Service(global.getService());
Resource[] vfResources = convertToResource(global.getResourceVf(), ResourceType.VF);
Resource[] vfcResources = convertToResource(global.getResourceVfc(), ResourceType.VFC);
-
// create builder
ControlLoopPolicyBuilder builder = ControlLoopPolicyBuilder.Factory.buildControlLoop(prop.getControlName(),
policyChain.getTimeout(), service, vfResources);
builder.addResource(vfcResources);
-
// process each policy
Map<String, Policy> policyObjMap = new HashMap<>();
List<PolicyItem> policyItemList = addAOTSActorRecipe(refProp, global.getService(),
policyChain.getPolicyItems());
-
Policy lastPolicyObj = new Policy();
for (PolicyItem policyItem : policyItemList) {
Target target = new Target();
@@ -309,7 +284,6 @@ public class OperationalPolicyReq {
operationsAccumulateParams.setLimit(Integer.valueOf(refProp.getStringValue("op.eNodeB.limit")));
operationsAccumulateParams.setPeriod(refProp.getStringValue("op.eNodeB.period"));
builder.addOperationsAccumulateParams(lastPolicyObj.getId(), operationsAccumulateParams);
-
//
// Build the specification
//
@@ -447,5 +421,4 @@ public class OperationalPolicyReq {
}
return prList.stream().map(stringElem -> PolicyResult.toResult(stringElem)).toArray(PolicyResult[]::new);
}
-
} \ No newline at end of file
diff --git a/src/main/java/org/onap/clamp/clds/client/PolicyClient.java b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
index ed29afe7..e01a68fa 100644
--- a/src/main/java/org/onap/clamp/clds/client/PolicyClient.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/policy/PolicyClient.java
@@ -21,7 +21,7 @@
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.clamp.clds.client;
+package org.onap.clamp.clds.client.req.policy;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -62,22 +62,19 @@ import org.springframework.context.ApplicationContext;
* Policy utility methods - specifically, send the policy.
*/
public class PolicyClient {
- protected static final String POLICY_PREFIX_BASE = "Config_";
- protected static final String POLICY_PREFIX_BRMS_PARAM = "Config_BRMS_Param_";
- protected static final String POLICY_PREFIX_MICROSERVICE = "Config_MS_";
-
- protected static final String LOG_POLICY_PREFIX = "Response is ";
-
- protected static final EELFLogger logger = EELFManager.getInstance()
+ protected static final String POLICY_PREFIX_BASE = "Config_";
+ protected static final String POLICY_PREFIX_BRMS_PARAM = "Config_BRMS_Param_";
+ protected static final String POLICY_PREFIX_MICROSERVICE = "Config_MS_";
+ protected static final String LOG_POLICY_PREFIX = "Response is ";
+ protected static final EELFLogger logger = EELFManager.getInstance()
.getLogger(PolicyClient.class);
- protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-
+ protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ protected static final String POLICY_MSTYPE_PROPERTY_NAME = "policy.ms.type";
+ protected static final String POLICY_ONAPNAME_PROPERTY_NAME = "policy.onap.name";
@Value("${org.onap.clamp.config.files.cldsPolicyConfig:'classpath:/clds/clds-policy-config.properties'}")
protected String cldsPolicyConfigFile;
-
@Autowired
protected ApplicationContext appContext;
-
@Autowired
protected RefProp refProp;
@@ -95,15 +92,11 @@ public class PolicyClient {
*/
public String sendBrmsPolicy(Map<AttributeType, Map<String, String>> attributes, ModelProperties prop,
String policyRequestUuid) {
-
PolicyParameters policyParameters = new PolicyParameters();
-
// Set Policy Type(Mandatory)
policyParameters.setPolicyConfigType(PolicyConfigType.BRMS_PARAM);
-
// Set Policy Name(Mandatory)
policyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId());
-
// documentation says this is options, but when tested, got the
// following failure: java.lang.Exception: Policy send failed: PE300 -
// Data Issue: No policyDescription given.
@@ -113,10 +106,8 @@ public class PolicyClient {
policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
String policyNamePrefix = refProp.getStringValue("policy.op.policyNamePrefix");
String rtnMsg = send(policyParameters, prop, policyNamePrefix);
-
String policyType = refProp.getStringValue("policy.op.type");
push(policyType, prop);
-
return rtnMsg;
}
@@ -132,28 +123,21 @@ public class PolicyClient {
* @return The response message of policy
*/
public String sendMicroServiceInJson(String policyJson, ModelProperties prop, String policyRequestUuid) {
-
PolicyParameters policyParameters = new PolicyParameters();
-
// Set Policy Type
policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
- policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
+ policyParameters.setEcompName(refProp.getStringValue(POLICY_ONAPNAME_PROPERTY_NAME));
policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
-
policyParameters.setConfigBody(policyJson);
policyParameters.setConfigBodyType(PolicyType.JSON);
-
policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
String policyNamePrefix = refProp.getStringValue("policy.ms.policyNamePrefix");
-
// Adding this line to clear the policy id from policy name while
// pushing to policy engine
prop.setPolicyUniqueId("");
-
String rtnMsg = send(policyParameters, prop, policyNamePrefix);
- String policyType = refProp.getStringValue("policy.ms.type");
+ String policyType = refProp.getStringValue(POLICY_MSTYPE_PROPERTY_NAME);
push(policyType, prop);
-
return rtnMsg;
}
@@ -174,26 +158,20 @@ public class PolicyClient {
public String sendBasePolicyInOther(String configBody, String configPolicyName, ModelProperties prop,
String policyRequestUuid) {
PolicyParameters policyParameters = new PolicyParameters();
-
// Set Policy Type
policyParameters.setPolicyConfigType(PolicyConfigType.Base);
- policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
+ policyParameters.setEcompName(refProp.getStringValue(POLICY_ONAPNAME_PROPERTY_NAME));
policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
-
policyParameters.setConfigBody(configBody);
policyParameters.setConfigBodyType(PolicyType.OTHER);
policyParameters.setConfigName("HolmesPolicy");
policyParameters.setPolicyName(configPolicyName);
-
policyParameters.setRequestID(UUID.fromString(policyRequestUuid));
-
// Adding this line to clear the policy id from policy name while
// pushing to policy engine
prop.setPolicyUniqueId("");
-
String rtnMsg = send(policyParameters, prop, POLICY_PREFIX_BASE);
push(PolicyConfigType.Base.toString(), prop);
-
return rtnMsg;
}
@@ -204,29 +182,23 @@ public class PolicyClient {
* The config policy string body
* @param prop
* The ModelProperties
- * @param policyRequestUuid
- * The policy request UUID
* @return The answer from policy call
*/
- public String sendMicroServiceInOther(String configBody, ModelProperties prop, String policyRequestUuid) {
-
+ public String sendMicroServiceInOther(String configBody, ModelProperties prop) {
PolicyParameters policyParameters = new PolicyParameters();
- // Set Policy Type
+ // Set Policy Type
policyParameters.setPolicyConfigType(PolicyConfigType.MicroService);
- policyParameters.setOnapName("DCAE");
- policyParameters.setEcompName(refProp.getStringValue("policy.onap.name"));
+ // policyParameters.setOnapName(refProp.getStringValue(POLICY_ONAPNAME_PROPERTY_NAME));
+ policyParameters.setEcompName(refProp.getStringValue(POLICY_ONAPNAME_PROPERTY_NAME));
policyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
policyParameters.setConfigBody(configBody);
String policyNamePrefix = refProp.getStringValue("policy.ms.policyNamePrefix");
-
// Adding this line to clear the policy id from policy name while
// pushing to policy engine
prop.setPolicyUniqueId("");
-
String rtnMsg = send(policyParameters, prop, policyNamePrefix);
- String policyType = refProp.getStringValue("policy.ms.type");
+ String policyType = refProp.getStringValue(POLICY_MSTYPE_PROPERTY_NAME);
push(policyType, prop);
-
return rtnMsg;
}
@@ -241,10 +213,9 @@ public class PolicyClient {
*/
protected String send(PolicyParameters policyParameters, ModelProperties prop, String policyNamePrefix) {
// Verify whether it is triggered by Validation Test button from UI
- if (prop.isTest()) {
+ if (prop.isTestOnly()) {
return "send not executed for test action";
}
-
// API method to create or update Policy.
PolicyChangeResponse response = null;
String responseMessage = "";
@@ -267,9 +238,7 @@ public class PolicyClient {
throw new PolicyClientException("Exception while communicating with Policy", e);
}
logger.info(LOG_POLICY_PREFIX + responseMessage);
-
LoggingUtils.setTimeContext(startTime, new Date());
-
if (response.getResponseCode() == 200) {
logger.info("Policy send successful");
metricsLogger.info("Policy send success");
@@ -278,7 +247,6 @@ public class PolicyClient {
metricsLogger.info("Policy send failure");
throw new BadRequestException("Policy send failed: " + responseMessage);
}
-
return responseMessage;
}
@@ -293,12 +261,10 @@ public class PolicyClient {
*/
protected String push(String policyType, ModelProperties prop) {
// Verify whether it is triggered by Validation Test button from UI
- if (prop.isTest()) {
+ if (prop.isTestOnly()) {
return "push not executed for test action";
}
-
PushPolicyParameters pushPolicyParameters = new PushPolicyParameters();
-
// Parameter arguments
if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
pushPolicyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId());
@@ -306,31 +272,29 @@ public class PolicyClient {
pushPolicyParameters.setPolicyName(prop.getCurrentPolicyScopeAndPolicyName());
}
logger.info("Policy Name in Push policy method - " + pushPolicyParameters.getPolicyName());
-
pushPolicyParameters.setPolicyType(policyType);
pushPolicyParameters.setPdpGroup(refProp.getStringValue("policy.pdp.group"));
pushPolicyParameters.setRequestID(null);
-
// API method to create or update Policy.
- PolicyChangeResponse response = null;
+ PolicyChangeResponse response;
String responseMessage = "";
try {
logger.info("Attempting to push policy...");
response = getPolicyEngine().pushPolicy(pushPolicyParameters);
- responseMessage = response.getResponseMessage();
+ if (response != null) {
+ responseMessage = response.getResponseMessage();
+ }
} catch (Exception e) {
logger.error("Exception occurred during policy communication", e);
throw new PolicyClientException("Exception while communicating with Policy", e);
}
logger.info(LOG_POLICY_PREFIX + responseMessage);
-
if (response != null && (response.getResponseCode() == 200 || response.getResponseCode() == 204)) {
logger.info("Policy push successful");
} else {
logger.warn("Policy push failed: " + responseMessage);
throw new BadRequestException("Policy push failed: " + responseMessage);
}
-
return responseMessage;
}
@@ -347,17 +311,14 @@ public class PolicyClient {
* In case of issues with policy engine
*/
protected List<Integer> getVersions(String policyNamePrefix, ModelProperties prop) throws PolicyConfigException {
-
ArrayList<Integer> versions = new ArrayList<>();
ConfigRequestParameters configRequestParameters = new ConfigRequestParameters();
String policyName = "";
-
if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
policyName = prop.getCurrentPolicyScopeAndFullPolicyName(policyNamePrefix) + "_" + prop.getPolicyUniqueId();
} else {
policyName = prop.getCurrentPolicyScopeAndFullPolicyName(policyNamePrefix);
}
-
logger.info("policyName=" + policyName);
configRequestParameters.setPolicyName(policyName);
try {
@@ -373,7 +334,6 @@ public class PolicyClient {
logger.warn("warning: policy not found...policy name - " + policyName, e.getMessage());
}
return versions;
-
}
/**
@@ -401,7 +361,7 @@ public class PolicyClient {
* @return The response message from Policy
*/
public String deleteMicrosService(ModelProperties prop) {
- String policyType = refProp.getStringValue("policy.ms.type");
+ String policyType = refProp.getStringValue(POLICY_MSTYPE_PROPERTY_NAME);
return deletePolicy(prop, policyType);
}
@@ -438,7 +398,6 @@ public class PolicyClient {
*/
protected String deletePolicy(ModelProperties prop, String policyType) {
DeletePolicyParameters deletePolicyParameters = new DeletePolicyParameters();
-
if (prop.getPolicyUniqueId() != null && !prop.getPolicyUniqueId().isEmpty()) {
deletePolicyParameters.setPolicyName(prop.getPolicyScopeAndNameWithUniqueId());
} else {
@@ -451,14 +410,11 @@ public class PolicyClient {
deletePolicyParameters.setPolicyType(policyType);
// send delete request
StringBuilder responseMessage = new StringBuilder(sendDeletePolicy(deletePolicyParameters, prop));
-
logger.info("Deleting policy from PAP...");
deletePolicyParameters.setPolicyComponent("PAP");
deletePolicyParameters.setDeleteCondition(DeletePolicyCondition.ALL);
-
// send delete request
responseMessage.append(sendDeletePolicy(deletePolicyParameters, prop));
-
return responseMessage.toString();
}
@@ -473,10 +429,9 @@ public class PolicyClient {
*/
protected String sendDeletePolicy(DeletePolicyParameters deletePolicyParameters, ModelProperties prop) {
// Verify whether it is triggered by Validation Test button from UI
- if (prop.isTest()) {
+ if (prop.isTestOnly()) {
return "delete not executed for test action";
}
-
// API method to create or update Policy.
PolicyChangeResponse response = null;
String responseMessage = "";
@@ -488,14 +443,12 @@ public class PolicyClient {
logger.error("Exception occurred during policy communnication", e);
}
logger.info(LOG_POLICY_PREFIX + responseMessage);
-
if (response != null && response.getResponseCode() == 200) {
logger.info("Policy delete successful");
} else {
logger.warn("Policy delete failed: " + responseMessage);
throw new BadRequestException("Policy delete failed: " + responseMessage);
}
-
return responseMessage;
}
} \ No newline at end of file
diff --git a/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java
index 36265e83..c725be2b 100644
--- a/src/main/java/org/onap/clamp/clds/client/SdcCatalogServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcCatalogServices.java
@@ -21,7 +21,7 @@
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.clamp.clds.client;
+package org.onap.clamp.clds.client.req.sdc;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -40,8 +40,10 @@ import java.io.Reader;
import java.io.StringReader;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
+import java.util.Base64;
import java.util.Collections;
import java.util.Date;
import java.util.Iterator;
@@ -49,10 +51,13 @@ import java.util.List;
import javax.ws.rs.BadRequestException;
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
-import org.onap.clamp.clds.client.req.SdcReq;
+import org.apache.http.HttpHeaders;
import org.onap.clamp.clds.exception.SdcCommunicationException;
import org.onap.clamp.clds.model.CldsAlarmCondition;
import org.onap.clamp.clds.model.CldsDBServiceCache;
@@ -68,20 +73,45 @@ import org.onap.clamp.clds.model.CldsVfcData;
import org.onap.clamp.clds.model.prop.Global;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.refprop.RefProp;
+import org.onap.clamp.clds.util.CryptoUtils;
import org.onap.clamp.clds.util.LoggingUtils;
import org.springframework.beans.factory.annotation.Autowired;
public class SdcCatalogServices {
- protected static final EELFLogger logger = EELFManager.getInstance()
+ protected static final EELFLogger logger = EELFManager.getInstance()
.getLogger(SdcCatalogServices.class);
- protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
- private static final String RESOURCE_VF_TYPE = "VF";
- private static final String RESOURCE_VFC_TYPE = "VFC";
- private static final String RESOURCE_CVFC_TYPE = "CVFC";
+ protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ private static final String RESOURCE_VF_TYPE = "VF";
+ private static final String RESOURCE_VFC_TYPE = "VFC";
+ private static final String RESOURCE_CVFC_TYPE = "CVFC";
+ public static final String SDC_REQUESTID_PROPERTY_NAME = "sdc.header.requestId";
+ private static final String SDC_METADATA_URL_PREFIX = "/metadata";
+ private static final String SDC_INSTANCE_ID_PROPERTY_NAME = "sdc.InstanceID";
+ private static final String SDC_CATALOG_URL_PROPERTY_NAME = "sdc.catalog.url";
+ private static final String SDC_SERVICE_URL_PROPERTY_NAME = "sdc.serviceUrl";
+ private static final String SDC_INSTANCE_ID_CLAMP = "CLAMP-Tool";
+ private static final String RESOURCE_URL_PREFIX = "resources";
@Autowired
private RefProp refProp;
- @Autowired
- private SdcReq sdcReq;
+ protected CryptoUtils cryptoUtils = new CryptoUtils();
+
+ /**
+ * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic
+ * dGVzdDoxMjM0NTY=).
+ *
+ * @return The String with Basic Auth and password
+ * @throws GeneralSecurityException
+ * In case of issue when decryting the SDC password
+ * @throws DecoderException
+ * In case of issues with the decoding of the HexString message
+ */
+ private String getSdcBasicAuth() throws GeneralSecurityException, DecoderException {
+ String sdcId = refProp.getStringValue("sdc.serviceUsername");
+ String sdcPw = refProp.getStringValue("sdc.servicePassword");
+ String password = cryptoUtils.decrypt(sdcPw);
+ String idPw = Base64.getEncoder().encodeToString((sdcId + ":" + password).getBytes(StandardCharsets.UTF_8));
+ return "Basic " + idPw;
+ }
/**
* This method get the SDC services Information with the corresponding
@@ -92,31 +122,31 @@ public class SdcCatalogServices {
* @return A Json String with all the service list
* @throws GeneralSecurityException
* In case of issue when decryting the SDC password
+ * @throws DecoderException
+ * In case of issues with the decoding of the Hex String
*/
- public String getSdcServicesInformation(String uuid) throws GeneralSecurityException {
+ public String getSdcServicesInformation(String uuid) throws GeneralSecurityException, DecoderException {
Date startTime = new Date();
- String baseUrl = refProp.getStringValue("sdc.serviceUrl");
- String basicAuth = sdcReq.getSdcBasicAuth();
+ String baseUrl = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);
+ String basicAuth = getSdcBasicAuth();
LoggingUtils.setTargetContext("SDC", "getSdcServicesInformation");
try {
String url = baseUrl;
if (uuid != null) {
- url = baseUrl + "/" + uuid + "/metadata";
+ url = baseUrl + "/" + uuid + SDC_METADATA_URL_PREFIX;
}
URL urlObj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
- conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
- conn.setRequestProperty("Authorization", basicAuth);
- conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
- conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());
+ conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);
+ conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
+ conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
+ conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
conn.setRequestMethod("GET");
String resp = getResponse(conn);
- if (resp != null) {
- logger.info(resp);
- // metrics log
- LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
- return resp;
- }
+ logger.info(resp);
+ // metrics log
+ LoggingUtils.setResponseContext("0", "Get sdc services success", this.getClass().getName());
+ return resp;
} catch (IOException e) {
LoggingUtils.setResponseContext("900", "Get sdc services failed", this.getClass().getName());
LoggingUtils.setErrorContext("900", "Get sdc services error");
@@ -223,8 +253,11 @@ public class SdcCatalogServices {
* @return The service UUID
* @throws GeneralSecurityException
* In case of issue when decryting the SDC password
+ * @throws DecoderException
+ * In case of issues with the decoding of the Hex String
*/
- public String getServiceUuidFromServiceInvariantId(String invariantId) throws GeneralSecurityException {
+ public String getServiceUuidFromServiceInvariantId(String invariantId)
+ throws GeneralSecurityException, DecoderException {
String serviceUuid = "";
String responseStr = getSdcServicesInformation(null);
List<CldsSdcServiceInfo> rawCldsSdcServicesList = getCldsSdcServicesListFromJson(responseStr);
@@ -326,15 +359,14 @@ public class SdcCatalogServices {
public String uploadArtifactToSdc(ModelProperties prop, String userid, String url, String formattedSdcReq)
throws GeneralSecurityException {
// Verify whether it is triggered by Validation Test button from UI
- if (prop.isTest()) {
+ if (prop.isTestOnly()) {
return "sdc artifact upload not executed for test action";
}
try {
logger.info("userid=" + userid);
- String md5Text = sdcReq.calculateMD5ByString(formattedSdcReq);
- byte[] postData = sdcReq.stringToByteArray(formattedSdcReq);
+ byte[] postData = formattedSdcReq.getBytes(StandardCharsets.UTF_8);
int postDataLength = postData.length;
- HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, md5Text);
+ HttpURLConnection conn = getSdcHttpUrlConnection(userid, postDataLength, url, formattedSdcReq);
try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
wr.write(postData);
}
@@ -356,45 +388,43 @@ public class SdcCatalogServices {
}
}
- private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String md5Text)
+ private HttpURLConnection getSdcHttpUrlConnection(String userid, int postDataLength, String url, String content)
throws GeneralSecurityException {
try {
logger.info("userid=" + userid);
- String basicAuth = sdcReq.getSdcBasicAuth();
+ String basicAuth = getSdcBasicAuth();
String sdcXonapInstanceId = refProp.getStringValue("sdc.sdcX-InstanceID");
URL urlObj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
conn.setDoOutput(true);
- conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), sdcXonapInstanceId);
- conn.setRequestProperty("Authorization", basicAuth);
- conn.setRequestProperty("Content-Type", "application/json");
- conn.setRequestProperty("Content-MD5", md5Text);
+ conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), sdcXonapInstanceId);
+ conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
+ conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json");
+ conn.setRequestProperty(HttpHeaders.CONTENT_MD5,
+ Base64.getEncoder().encodeToString(DigestUtils.md5Hex(content).getBytes("UTF-8")));
conn.setRequestProperty("USER_ID", userid);
conn.setRequestMethod("POST");
conn.setRequestProperty("charset", "utf-8");
- conn.setRequestProperty("Content-Length", Integer.toString(postDataLength));
+ conn.setRequestProperty(HttpHeaders.CONTENT_LENGTH, Integer.toString(postDataLength));
conn.setUseCaches(false);
- conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());
+ conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
return conn;
} catch (IOException e) {
logger.error("Exception when attempting to open connection with SDC", e);
throw new SdcCommunicationException("Exception when attempting to open connection with SDC", e);
+ } catch (DecoderException e) {
+ logger.error("Exception when attempting to decode the Hex string", e);
+ throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);
+ } catch (GeneralSecurityException e) {
+ logger.error("Exception when attempting to decrypt the encrypted password", e);
+ throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);
}
}
private String getResponse(HttpURLConnection conn) {
try (InputStream is = getInputStream(conn)) {
- if (is != null) {
- try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
- StringBuilder response = new StringBuilder();
- String inputLine;
- while ((inputLine = in.readLine()) != null) {
- response.append(inputLine);
- }
- return response.toString();
- }
- } else {
- return null;
+ try (BufferedReader in = new BufferedReader(new InputStreamReader(is))) {
+ return IOUtils.toString(in);
}
} catch (IOException e) {
logger.error("Exception when attempting to open SDC response", e);
@@ -434,8 +464,12 @@ public class SdcCatalogServices {
* @param cldsServiceData
* @return
* @throws GeneralSecurityException
+ * In case of issues with the decryting the encrypted password
+ * @throws DecoderException
+ * In case of issues with the decoding of the Hex String
*/
- public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData) throws GeneralSecurityException {
+ public boolean isCldsSdcCacheDataExpired(CldsServiceData cldsServiceData)
+ throws GeneralSecurityException, DecoderException {
boolean expired = false;
if (cldsServiceData != null && cldsServiceData.getServiceUUID() != null) {
String cachedServiceUuid = cldsServiceData.getServiceUUID();
@@ -458,13 +492,16 @@ public class SdcCatalogServices {
* @param invariantServiceUuid
* @return
* @throws GeneralSecurityException
+ * In case of issues with the decryting the encrypted password
+ * @throws DecoderException
+ * In case of issues with the decoding of the Hex String
*/
public CldsServiceData getCldsServiceDataWithAlarmConditions(String invariantServiceUuid)
- throws GeneralSecurityException {
- String url = refProp.getStringValue("sdc.serviceUrl");
- String catalogUrl = refProp.getStringValue("sdc.catalog.url");
+ throws GeneralSecurityException, DecoderException {
+ String url = refProp.getStringValue(SDC_SERVICE_URL_PROPERTY_NAME);
+ String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
String serviceUuid = getServiceUuidFromServiceInvariantId(invariantServiceUuid);
- String serviceDetailUrl = url + "/" + serviceUuid + "/metadata";
+ String serviceDetailUrl = url + "/" + serviceUuid + SDC_METADATA_URL_PREFIX;
String responseStr = getCldsServicesOrResourcesBasedOnURL(serviceDetailUrl, false);
ObjectMapper objectMapper = new ObjectMapper();
CldsServiceData cldsServiceData = new CldsServiceData();
@@ -476,11 +513,11 @@ public class SdcCatalogServices {
logger.error("Exception when decoding the CldsServiceData JSON from SDC", e);
throw new SdcCommunicationException("Exception when decoding the CldsServiceData JSON from SDC", e);
}
- cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());
- cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());
// To remove duplicate resources from serviceDetail and add valid
// vfs to service
if (cldsSdcServiceDetail != null && cldsSdcServiceDetail.getResources() != null) {
+ cldsServiceData.setServiceUUID(cldsSdcServiceDetail.getUuid());
+ cldsServiceData.setServiceInvariantUUID(cldsSdcServiceDetail.getInvariantUUID());
List<CldsSdcResource> cldsSdcResourceList = removeDuplicateSdcResourceInstances(
cldsSdcServiceDetail.getResources());
if (cldsSdcResourceList != null && !cldsSdcResourceList.isEmpty()) {
@@ -519,7 +556,8 @@ public class SdcCatalogServices {
String resourceUuid = getResourceUuidFromResourceInvariantUuid(
currCldsVfData.getVfInvariantResourceUUID(), allVfResources);
if (resourceUuid != null) {
- String vfResourceUuidUrl = catalogUrl + "resources" + "/" + resourceUuid + "/metadata";
+ String vfResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUuid
+ + SDC_METADATA_URL_PREFIX;
String vfResponse = getCldsServicesOrResourcesBasedOnURL(vfResourceUuidUrl, false);
if (vfResponse != null) {
// Below 2 line are to get the KPI(field path) data
@@ -538,8 +576,8 @@ public class SdcCatalogServices {
String resourceVfcUuid = getResourceUuidFromResourceInvariantUuid(
currCldsVfcData.getVfcInvariantResourceUUID(), allVfcResources);
if (resourceVfcUuid != null) {
- String vfcResourceUuidUrl = catalogUrl + "resources" + "/"
- + resourceVfcUuid + "/metadata";
+ String vfcResourceUuidUrl = catalogUrl + RESOURCE_URL_PREFIX + "/"
+ + resourceVfcUuid + SDC_METADATA_URL_PREFIX;
String vfcResponse = getCldsServicesOrResourcesBasedOnURL(
vfcResourceUuidUrl, false);
if (vfcResponse != null) {
@@ -601,10 +639,10 @@ public class SdcCatalogServices {
}
private List<CldsVfcData> getVFCfromCVFC(String resourceUUID) throws GeneralSecurityException {
- String catalogUrl = refProp.getStringValue("sdc.catalog.url");
+ String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
List<CldsVfcData> cldsVfcDataList = new ArrayList<>();
if (resourceUUID != null) {
- String vfcResourceUUIDUrl = catalogUrl + "resources" + "/" + resourceUUID + "/metadata";
+ String vfcResourceUUIDUrl = catalogUrl + RESOURCE_URL_PREFIX + "/" + resourceUUID + SDC_METADATA_URL_PREFIX;
try {
String vfcResponse = getCldsServicesOrResourcesBasedOnURL(vfcResourceUUIDUrl, false);
ObjectMapper mapper = new ObjectMapper();
@@ -809,34 +847,30 @@ public class SdcCatalogServices {
String urlReworked = removeUnwantedBracesFromString(url);
URL urlObj = new URL(urlReworked);
HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
- String basicAuth = sdcReq.getSdcBasicAuth();
- conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
- conn.setRequestProperty("Authorization", basicAuth);
- conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
- conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());
+ String basicAuth = getSdcBasicAuth();
+ conn.setRequestProperty(refProp.getStringValue(SDC_INSTANCE_ID_PROPERTY_NAME), SDC_INSTANCE_ID_CLAMP);
+ conn.setRequestProperty(HttpHeaders.AUTHORIZATION, basicAuth);
+ conn.setRequestProperty(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
+ conn.setRequestProperty(refProp.getStringValue(SDC_REQUESTID_PROPERTY_NAME), LoggingUtils.getRequestId());
conn.setRequestMethod("GET");
int responseCode = conn.getResponseCode();
logger.info("Sdc resource url - " + urlReworked + " , responseCode=" + responseCode);
- StringBuilder response;
try (BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
- response = new StringBuilder();
- String inputLine;
- while ((inputLine = in.readLine()) != null) {
- if (!inputLine.isEmpty()) {
- response.append(inputLine);
- }
- if (alarmConditions) {
- response.append("\n");
- }
- }
+ String response = IOUtils.toString(in);
+ LoggingUtils.setResponseContext("0", "Get sdc resources success", this.getClass().getName());
+ return response;
}
- LoggingUtils.setResponseContext("0", "Get sdc resources success", this.getClass().getName());
- return response.toString();
} catch (IOException e) {
LoggingUtils.setResponseContext("900", "Get sdc resources failed", this.getClass().getName());
LoggingUtils.setErrorContext("900", "Get sdc resources error");
logger.error("Exception occurred during query to SDC", e);
return "";
+ } catch (DecoderException e) {
+ logger.error("Exception when attempting to decode the Hex string", e);
+ throw new SdcCommunicationException("Exception when attempting to decode the Hex string", e);
+ } catch (GeneralSecurityException e) {
+ logger.error("Exception when attempting to decrypt the encrypted password", e);
+ throw new SdcCommunicationException("Exception when attempting to decrypt the encrypted password", e);
} finally {
LoggingUtils.setTimeContext(startTime, new Date());
metricsLogger.info("getCldsServicesOrResourcesBasedOnURL completed");
@@ -1161,41 +1195,6 @@ public class SdcCatalogServices {
return artifactUuid;
}
- public String updateControlLoopStatusToDcae(String dcaeUrl, String invariantResourceUuid,
- String invariantServiceUuid, String artifactName) throws GeneralSecurityException {
- String baseUrl = refProp.getStringValue("sdc.serviceUrl");
- String basicAuth = sdcReq.getSdcBasicAuth();
- String postStatusData = "{ \n" + "\"event\" : \"" + "Created" + "\",\n" + "\"serviceUUID\" : \""
- + invariantServiceUuid + "\",\n" + "\"resourceUUID\" :\"" + invariantResourceUuid + "\",\n"
- + "\"artifactName\" : \"" + artifactName + "\",\n" + "} \n";
- try {
- String url = baseUrl;
- if (invariantServiceUuid != null) {
- url = dcaeUrl + "/closed-loops";
- }
- URL urlObj = new URL(url);
- HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
- conn.setRequestProperty(refProp.getStringValue("sdc.InstanceID"), "CLAMP-Tool");
- conn.setRequestProperty("Authorization", basicAuth);
- conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");
- conn.setRequestProperty("X-ECOMP-RequestID", LoggingUtils.getRequestId());
- conn.setRequestMethod("POST");
- byte[] postData = sdcReq.stringToByteArray(postStatusData);
- try (DataOutputStream wr = new DataOutputStream(conn.getOutputStream())) {
- wr.write(postData);
- }
- int responseCode = conn.getResponseCode();
- logger.info("responseCode=" + responseCode);
- String resp = getResponse(conn);
- if (resp != null) {
- return resp;
- }
- } catch (IOException e) {
- logger.error("Not able to get any service information from sdc for uuid:" + invariantServiceUuid, e);
- }
- return "";
- }
-
/**
* To get all sdc VF/VFC Resources basic info.
*
@@ -1208,7 +1207,7 @@ public class SdcCatalogServices {
*/
private List<CldsSdcResourceBasicInfo> getAllSdcVForVfcResourcesBasedOnResourceType(String resourceType)
throws GeneralSecurityException {
- String catalogUrl = refProp.getStringValue("sdc.catalog.url");
+ String catalogUrl = refProp.getStringValue(SDC_CATALOG_URL_PROPERTY_NAME);
String resourceUrl = catalogUrl + "resources?resourceType=" + resourceType;
String allSdcVfcResources = getCldsServicesOrResourcesBasedOnURL(resourceUrl, false);
return removeDuplicateSdcResourceBasicInfo(getAllSdcResourcesListFromJson(allSdcVfcResources));
@@ -1264,11 +1263,13 @@ public class SdcCatalogServices {
* The location artifact name from where we can get the Artifact
* UUID
* @throws GeneralSecurityException
- * In case of issues to decrypt the SDC password
+ * In case of issues with the decryting the encrypted password
+ * @throws DecoderException
+ * In case of issues with the decoding of the Hex String
*/
public void uploadToSdc(ModelProperties prop, String userid, List<String> sdcReqUrlsList, String formattedSdcReq,
String formattedSdcLocationReq, String artifactName, String locationArtifactName)
- throws GeneralSecurityException {
+ throws GeneralSecurityException, DecoderException {
logger.info("userid=" + userid);
String serviceInvariantUuid = getServiceInvariantUuidFromProps(prop);
if (sdcReqUrlsList != null && !sdcReqUrlsList.isEmpty()) {
diff --git a/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcReq.java
index 38e3b15a..d4b5b086 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/SdcReq.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/sdc/SdcReq.java
@@ -21,7 +21,7 @@
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.clamp.clds.client.req;
+package org.onap.clamp.clds.client.req.sdc;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -41,24 +41,21 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map.Entry;
-import org.apache.commons.codec.digest.DigestUtils;
+import org.apache.commons.codec.DecoderException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
-import org.onap.clamp.clds.client.SdcCatalogServices;
+import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter;
import org.onap.clamp.clds.model.CldsSdcResource;
import org.onap.clamp.clds.model.CldsSdcServiceDetail;
import org.onap.clamp.clds.model.prop.Global;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.prop.Tca;
import org.onap.clamp.clds.model.refprop.RefProp;
-import org.onap.clamp.clds.util.CryptoUtils;
import org.springframework.beans.factory.annotation.Autowired;
/**
* Construct a Sdc request given CLDS objects.
*/
public class SdcReq {
- @Autowired
- protected CryptoUtils cryptoUtils;
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(SdcReq.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
@Autowired
@@ -136,7 +133,7 @@ public class SdcReq {
public String formatSdcReq(String payloadData, String artifactName, String artifactLabel, String artifactType)
throws IOException {
logger.info("artifact=" + payloadData);
- String base64Artifact = base64Encode(payloadData);
+ String base64Artifact = Base64.getEncoder().encodeToString(payloadData.getBytes(StandardCharsets.UTF_8));
return "{ \n" + "\"payloadData\" : \"" + base64Artifact + "\",\n" + "\"artifactLabel\" : \"" + artifactLabel
+ "\",\n" + "\"artifactName\" :\"" + artifactName + "\",\n" + "\"artifactType\" : \"" + artifactType
+ "\",\n" + "\"artifactGroupType\" : \"DEPLOYMENT\",\n" + "\"description\" : \"from CLAMP Cockpit\"\n"
@@ -144,32 +141,6 @@ public class SdcReq {
}
/**
- * Get the SDC Request URL
- *
- * @param prop
- * The ModelProperties describing the clds model
- * @param url
- * url
- * @return SDC Request URL
- */
- public String getSdcReqUrl(ModelProperties prop, String url) {
- Global globalProps = prop.getGlobal();
- String serviceUUID = "";
- String resourceInstanceName = "";
- if (globalProps != null) {
- List<String> resourceVf = globalProps.getResourceVf();
- if (resourceVf != null && !resourceVf.isEmpty()) {
- resourceInstanceName = resourceVf.get(0);
- }
- if (globalProps.getService() != null) {
- serviceUUID = globalProps.getService();
- }
- }
- String normalizedResourceInstanceName = normalizeResourceInstanceName(resourceInstanceName);
- return url + "/" + serviceUUID + "/resourceInstances/" + normalizedResourceInstanceName + "/artifacts";
- }
-
- /**
* To get List of urls for all vfresources
*
* @param prop
@@ -178,9 +149,12 @@ public class SdcReq {
* @param execution
* @return
* @throws GeneralSecurityException
+ * In case of issues when decrypting the password
+ * @throws DecoderException
+ * In case of issues when decoding the Hex String
*/
public List<String> getSdcReqUrlsList(ModelProperties prop, String baseUrl, SdcCatalogServices sdcCatalogServices,
- DelegateExecution execution) throws GeneralSecurityException {
+ DelegateExecution execution) throws GeneralSecurityException, DecoderException {
// TODO : refact and regroup with very similar code
List<String> urlList = new ArrayList<>();
Global globalProps = prop.getGlobal();
@@ -227,65 +201,6 @@ public class SdcReq {
}
/**
- * from michael
- *
- * @param data
- * @return
- */
- public String calculateMD5ByString(String data) {
- String calculatedMd5 = DigestUtils.md5Hex(data);
- // encode base-64 result
- return base64Encode(calculatedMd5.getBytes());
- }
-
- /**
- * Base 64 encode a String.
- *
- * @param inText
- * @return
- */
- public String base64Encode(String inText) {
- return base64Encode(stringToByteArray(inText));
- }
-
- /**
- * Convert String to byte array.
- *
- * @param inText
- * @return
- */
- public byte[] stringToByteArray(String inText) {
- return inText.getBytes(StandardCharsets.UTF_8);
- }
-
- /**
- * Base 64 encode a byte array.
- *
- * @param bytes
- * @return
- */
- public String base64Encode(byte[] bytes) {
- Base64.Encoder encoder = Base64.getEncoder();
- return encoder.encodeToString(bytes);
- }
-
- /**
- * Return SDC id and pw as a HTTP Basic Auth string (for example: Basic
- * dGVzdDoxMjM0NTY=).
- *
- * @return The String with Basic Auth and password
- * @throws GeneralSecurityException
- * In case of issue when decryting the SDC password
- */
- public String getSdcBasicAuth() throws GeneralSecurityException {
- String sdcId = refProp.getStringValue("sdc.serviceUsername");
- String sdcPw = refProp.getStringValue("sdc.servicePassword");
- String password = cryptoUtils.decrypt(sdcPw);
- String idPw = base64Encode(sdcId + ":" + password);
- return "Basic " + idPw;
- }
-
- /**
* Method to get yaml/template properties value from json
*
* @param docText
diff --git a/src/main/java/org/onap/clamp/clds/client/req/TcaRequestFormatter.java b/src/main/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatter.java
index 3646e574..385a4e41 100644
--- a/src/main/java/org/onap/clamp/clds/client/req/TcaRequestFormatter.java
+++ b/src/main/java/org/onap/clamp/clds/client/req/tca/TcaRequestFormatter.java
@@ -21,7 +21,7 @@
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.clamp.clds.client.req;
+package org.onap.clamp.clds.client.req.tca;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
@@ -30,6 +30,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml;
+import java.io.IOException;
import java.util.Map;
import org.onap.clamp.clds.exception.TcaRequestFormatterException;
@@ -77,7 +78,7 @@ public class TcaRequestFormatter {
String tcaPolicyReq = rootNode.toString();
logger.info("tcaPolicyReq=" + tcaPolicyReq);
return tcaPolicyReq;
- } catch (Exception e) {
+ } catch (IOException e) {
throw new TcaRequestFormatterException("Exception caught when attempting to create the policy JSON", e);
}
}
@@ -90,31 +91,45 @@ public class TcaRequestFormatter {
* clds-references.properties file
* @param modelProperties
* The Model Prop created from BPMN JSON and BPMN properties JSON
- * @return The Json string containing that should be sent to policy
+ * @param service
+ * The service ID, if not specified getGlobal.getService will be
+ * used
+ * @param policyName
+ * The policyName, if not specified the
+ * modelProperties.getCurrentPolicyScopeAndPolicyName will be
+ * used
+ * @param tca
+ * The Tca object, if not specified the
+ * modelProperties.setCurrentModelElementId will be used
+ * @return The Json node containing what should be sent to policy
*/
public static JsonNode createPolicyContent(RefProp refProp, ModelProperties modelProperties, String service,
String policyName, Tca tca) {
try {
- if (null == service) {
- service = modelProperties.getGlobal().getService();
+ String serviceToUse = service;
+ String policyNameToUse = policyName;
+ Tca tcaToUse = tca;
+ if (serviceToUse == null) {
+ serviceToUse = modelProperties.getGlobal().getService();
}
- if (null == tca) {
- tca = modelProperties.getType(Tca.class);
- modelProperties.setCurrentModelElementId(tca.getId());
+ if (tcaToUse == null) {
+ tcaToUse = modelProperties.getType(Tca.class);
+ modelProperties.setCurrentModelElementId(tcaToUse.getId());
}
- if (null == policyName) {
- policyName = modelProperties.getCurrentPolicyScopeAndPolicyName();
+ if (policyNameToUse == null) {
+ policyNameToUse = modelProperties.getCurrentPolicyScopeAndPolicyName();
}
- ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.template", service);
- ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("eventName", tca.getTcaItem().getEventName());
- ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("policyName", policyName);
+ ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("tca.template", serviceToUse);
+ ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("eventName",
+ tcaToUse.getTcaItem().getEventName());
+ ((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("policyName", policyNameToUse);
((ObjectNode) rootNode.get("metricsPerEventName").get(0)).put("controlLoopSchemaType",
- tca.getTcaItem().getControlLoopSchemaType());
+ tcaToUse.getTcaItem().getControlLoopSchemaType());
ObjectNode thresholdsParent = ((ObjectNode) rootNode.get("metricsPerEventName").get(0));
- addThresholds(refProp, service, thresholdsParent, tca.getTcaItem(), modelProperties);
+ addThresholds(refProp, serviceToUse, thresholdsParent, tcaToUse.getTcaItem(), modelProperties);
logger.info("tcaPolicyContent=" + rootNode.toString());
return rootNode;
- } catch (Exception e) {
+ } catch (IOException e) {
throw new TcaRequestFormatterException("Exception caught when attempting to create the policy content JSON",
e);
}
@@ -140,9 +155,10 @@ public class TcaRequestFormatter {
*/
private static void addThresholds(RefProp refProp, String service, ObjectNode appendToNode, TcaItem tcaItem,
ModelProperties modelProperties) {
+ ArrayNode tcaNodes = appendToNode.withArray("thresholds");
+ ObjectNode tcaNode;
try {
- ArrayNode tcaNodes = appendToNode.withArray("thresholds");
- ObjectNode tcaNode = (ObjectNode) refProp.getJsonTemplate("tca.thresholds.template", service);
+ tcaNode = (ObjectNode) refProp.getJsonTemplate("tca.thresholds.template", service);
for (TcaThreshold tcaThreshold : tcaItem.getTcaThresholds()) {
tcaNode.put("closedLoopControlName", modelProperties.getControlNameAndPolicyUniqueId());
tcaNode.put("fieldPath", tcaThreshold.getFieldPath());
@@ -151,7 +167,7 @@ public class TcaRequestFormatter {
tcaNode.put("closedLoopEventStatus", tcaThreshold.getClosedLoopEventStatus());
tcaNodes.add(tcaNode);
}
- } catch (Exception e) {
+ } catch (IOException e) {
throw new TcaRequestFormatterException("Exception caught when attempting to create the thresholds JSON", e);
}
}
@@ -171,34 +187,17 @@ public class TcaRequestFormatter {
*/
public static String updatedBlueprintWithConfiguration(RefProp refProp, ModelProperties modelProperties,
String yamlValue) {
- try {
- String jsonPolicy = ((ObjectNode) createPolicyContent(refProp, modelProperties, null, null, null))
- .toString();
- logger.info("Yaml that will be updated:" + yamlValue);
- Yaml yaml = new Yaml();
- Map<String, Object> loadedYaml = (Map<String, Object>) yaml.load(yamlValue);
- Map<String, Object> nodeTemplates = (Map<String, Object>) loadedYaml.get("node_templates");
- // add policy_0 section in blueprint
- /*
- * Map<String, Object> policyObject = new HashMap<String, Object>
- * (); Map<String, Object> policyIdObject = new HashMap<String,
- * Object> (); String policyPrefix =
- * refProp.getStringValue("tca.policyid.prefix");
- * policyIdObject.put("policy_id", policyPrefix +
- * modelProperties.getCurrentPolicyScopeAndPolicyName());
- * policyObject.put("type", "dcae.nodes.policy");
- * policyObject.put("properties", policyIdObject);
- * nodeTemplates.put("policy_0", policyObject);
- */
- Map<String, Object> tcaObject = (Map<String, Object>) nodeTemplates.get("tca_tca");
- Map<String, Object> propsObject = (Map<String, Object>) tcaObject.get("properties");
- Map<String, Object> appPreferences = (Map<String, Object>) propsObject.get("app_preferences");
- appPreferences.put("tca_policy", jsonPolicy);
- String blueprint = yaml.dump(loadedYaml);
- logger.info("Yaml updated:" + blueprint);
- return blueprint;
- } catch (Exception e) {
- throw new TcaRequestFormatterException("Exception caught when attempting to update the blueprint", e);
- }
+ String jsonPolicy = ((ObjectNode) createPolicyContent(refProp, modelProperties, null, null, null)).toString();
+ logger.info("Yaml that will be updated:" + yamlValue);
+ Yaml yaml = new Yaml();
+ Map<String, Object> loadedYaml = (Map<String, Object>) yaml.load(yamlValue);
+ Map<String, Object> nodeTemplates = (Map<String, Object>) loadedYaml.get("node_templates");
+ Map<String, Object> tcaObject = (Map<String, Object>) nodeTemplates.get("tca_tca");
+ Map<String, Object> propsObject = (Map<String, Object>) tcaObject.get("properties");
+ Map<String, Object> appPreferences = (Map<String, Object>) propsObject.get("app_preferences");
+ appPreferences.put("tca_policy", jsonPolicy);
+ String blueprint = yaml.dump(loadedYaml);
+ logger.info("Yaml updated:" + blueprint);
+ return blueprint;
}
} \ No newline at end of file
diff --git a/src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java b/src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java
index 0c73ac71..45d2786a 100644
--- a/src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java
+++ b/src/main/java/org/onap/clamp/clds/config/CldsConfiguration.java
@@ -40,12 +40,12 @@ import org.onap.clamp.clds.client.HolmesPolicyDelegate;
import org.onap.clamp.clds.client.HolmesPolicyDeleteDelegate;
import org.onap.clamp.clds.client.OperationalPolicyDelegate;
import org.onap.clamp.clds.client.OperationalPolicyDeleteDelegate;
-import org.onap.clamp.clds.client.PolicyClient;
-import org.onap.clamp.clds.client.SdcCatalogServices;
import org.onap.clamp.clds.client.SdcSendReqDelegate;
import org.onap.clamp.clds.client.TcaPolicyDelegate;
import org.onap.clamp.clds.client.TcaPolicyDeleteDelegate;
-import org.onap.clamp.clds.client.req.SdcReq;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
+import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
+import org.onap.clamp.clds.client.req.sdc.SdcReq;
import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.model.refprop.RefProp;
import org.onap.clamp.clds.transform.XslTransformer;
diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java
index c5332a6b..2c052c1a 100644
--- a/src/main/java/org/onap/clamp/clds/dao/CldsDao.java
+++ b/src/main/java/org/onap/clamp/clds/dao/CldsDao.java
@@ -26,12 +26,7 @@ package org.onap.clamp.clds.dao;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import java.io.IOException;
import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.sql.Blob;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -49,7 +44,6 @@ import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.model.ValueItem;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
-import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.simple.SimpleJdbcCall;
@@ -60,10 +54,8 @@ import org.springframework.stereotype.Repository;
*/
@Repository("cldsDao")
public class CldsDao {
-
protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDao.class);
protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
-
private JdbcTemplate jdbcTemplateObject;
private SimpleJdbcCall procGetModel;
private SimpleJdbcCall procGetModelTemplate;
@@ -75,7 +67,6 @@ public class CldsDao {
private SimpleJdbcCall procDelAllModelInstances;
private SimpleJdbcCall procInsModelInstance;
private SimpleJdbcCall procDelModelInstance;
-
private static final String HEALTHCHECK = "Select 1";
/**
@@ -202,7 +193,6 @@ public class CldsDao {
model.getEvent().setUserid((String) out.get("v_event_user_id"));
model.setTypeId((String) out.get("v_service_type_id"));
model.setDeploymentId((String) out.get("v_deployment_id"));
-
Map<String, Object> modelResults = logSqlExecution(procGetModel, in);
Object modelResultObject = modelResults.get("#result-set-1");
if (modelResultObject != null && modelResultObject instanceof ArrayList) {
@@ -266,7 +256,6 @@ public class CldsDao {
// Delete all existing model instances for given controlNameUUID
logger.debug("deleting instances for: {}", model.getControlNameUuid());
delAllModelInstances(model.getControlNameUuid());
-
if (modelInstancesList == null) {
logger.debug("modelInstancesList == null");
} else {
@@ -359,41 +348,6 @@ public class CldsDao {
}
/**
- * Generic mapper for list of values
- */
- private static final class ValueItemMapper implements RowMapper<ValueItem> {
- @Override
- public ValueItem mapRow(ResultSet rs, int rowNum) throws SQLException {
- ValueItem item = new ValueItem();
- item.setValue(rs.getString(1));
- return item;
- }
- }
-
- /**
- * Generic mapper for CldsDBServiceCache
- */
- private static final class CldsServiceDataMapper implements RowMapper<CldsServiceData> {
- @Override
- public CldsServiceData mapRow(ResultSet rs, int rowNum) throws SQLException {
- CldsServiceData cldsServiceData = new CldsServiceData();
- long age;
- age = rs.getLong(5);
- Blob blob = rs.getBlob(4);
- InputStream is = blob.getBinaryStream();
- ObjectInputStream oip;
- try {
- oip = new ObjectInputStream(is);
- cldsServiceData = (CldsServiceData) oip.readObject();
- cldsServiceData.setAgeOfRecord(age);
- } catch (IOException | ClassNotFoundException e) {
- logger.error("Error caught while retrieving cldsServiceData from database", e);
- }
- return cldsServiceData;
- }
- }
-
- /**
* Return list of model names
*
* @return model names
@@ -503,14 +457,14 @@ public class CldsDao {
}
/**
- * Method to get all models with model properties.
+ * Method to get deployed/active models with model properties.
*
* @return list of CldsModelProp
*/
- public List<CldsModelProp> getAllModelProperties() {
+ public List<CldsModelProp> getDeployedModelProperties() {
List<CldsModelProp> cldsModelPropList = new ArrayList<CldsModelProp>();
- String modelsSql = "select m.model_id, m.model_name, mp.model_prop_id, mp.model_prop_text FROM model m, model_properties mp"
- + " WHERE m.model_prop_id = mp.model_prop_id";
+ String modelsSql = "select m.model_id, m.model_name, mp.model_prop_id, mp.model_prop_text FROM model m, model_properties mp, event e "
+ + "WHERE m.model_prop_id = mp.model_prop_id and m.event_id = e.event_id and e.action_cd = 'DEPLOY'";
List<Map<String, Object>> rows = jdbcTemplateObject.queryForList(modelsSql);
CldsModelProp cldsModelProp = null;
for (Map<String, Object> row : rows) {
@@ -523,5 +477,4 @@ public class CldsDao {
}
return cldsModelPropList;
}
-
}
diff --git a/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java b/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java
new file mode 100644
index 00000000..91d89505
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/dao/CldsServiceDataMapper.java
@@ -0,0 +1,62 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.dao;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import org.apache.commons.io.serialization.ValidatingObjectInputStream;
+import java.sql.Blob;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.onap.clamp.clds.model.CldsServiceData;
+import org.springframework.jdbc.core.RowMapper;
+
+/**
+ * Generic mapper for CldsDBServiceCache
+ */
+public final class CldsServiceDataMapper implements RowMapper<CldsServiceData> {
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(CldsDao.class);
+
+ @Override
+ public CldsServiceData mapRow(ResultSet rs, int rowNum) throws SQLException {
+ CldsServiceData cldsServiceData = new CldsServiceData();
+ long age;
+ age = rs.getLong(5);
+ Blob blob = rs.getBlob(4);
+ InputStream is = blob.getBinaryStream();
+ try (ValidatingObjectInputStream oip = new ValidatingObjectInputStream(is)) {
+ oip.accept(CldsServiceData.class);
+ cldsServiceData = (CldsServiceData) oip.readObject();
+ cldsServiceData.setAgeOfRecord(age);
+ } catch (IOException | ClassNotFoundException e) {
+ logger.error("Error caught while retrieving cldsServiceData from database", e);
+ }
+ return cldsServiceData;
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/dao/ValueItemMapper.java b/src/main/java/org/onap/clamp/clds/dao/ValueItemMapper.java
new file mode 100644
index 00000000..12367284
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/dao/ValueItemMapper.java
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.dao;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.onap.clamp.clds.model.ValueItem;
+import org.springframework.jdbc.core.RowMapper;
+
+/**
+ * Generic mapper for list of values
+ */
+public final class ValueItemMapper implements RowMapper<ValueItem> {
+ @Override
+ public ValueItem mapRow(ResultSet rs, int rowNum) throws SQLException {
+ ValueItem item = new ValueItem();
+ item.setValue(rs.getString(1));
+ return item;
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/exception/ModelPropertiesException.java b/src/main/java/org/onap/clamp/clds/exception/ModelPropertiesException.java
new file mode 100644
index 00000000..09fb5dba
--- /dev/null
+++ b/src/main/java/org/onap/clamp/clds/exception/ModelPropertiesException.java
@@ -0,0 +1,61 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP CLAMP
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * 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.
+ * ============LICENSE_END============================================
+ * ===================================================================
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ */
+
+package org.onap.clamp.clds.exception;
+
+/**
+ * The exception used in case of issues when decoding the ModelProperties JSON
+ * generated by the Designer UI.
+ *
+ *
+ */
+public class ModelPropertiesException extends RuntimeException {
+ /**
+ * Generated ID.
+ */
+ private static final long serialVersionUID = 8452294782552680344L;
+
+ /**
+ * This constructor can be used to create a new ModelPropertiesException.
+ *
+ * @param message
+ * A string message detailing the problem
+ * @param e
+ * The exception sent by the code
+ */
+ public ModelPropertiesException(String message, Throwable e) {
+ super(message, e);
+ }
+
+ /**
+ * This constructor can be used to create a new ModelPropertiesException.
+ * Use this constructor only if you are creating a new exception stack, not
+ * if an exception was already raised by another code.
+ *
+ * @param message
+ * A string message detailing the problem
+ */
+ public ModelPropertiesException(String message) {
+ super(message);
+ }
+}
diff --git a/src/main/java/org/onap/clamp/clds/model/prop/ModelBpmn.java b/src/main/java/org/onap/clamp/clds/model/prop/ModelBpmn.java
index f3d344a7..9738396a 100644
--- a/src/main/java/org/onap/clamp/clds/model/prop/ModelBpmn.java
+++ b/src/main/java/org/onap/clamp/clds/model/prop/ModelBpmn.java
@@ -25,8 +25,6 @@ package org.onap.clamp.clds.model.prop;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -40,25 +38,22 @@ import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.onap.clamp.clds.exception.ModelBpmnException;
import org.onap.clamp.clds.service.CldsService;
/**
* Parse Model BPMN properties.
* <p>
- * Example json: {"policy"
- * :[{"id":"Policy_0oxeocn", "from":"StartEvent_1"}]}
+ * Example json: {"policy" :[{"id":"Policy_0oxeocn", "from":"StartEvent_1"}]}
*/
public class ModelBpmn {
protected static final EELFLogger logger = EELFManager.getInstance()
.getLogger(CldsService.class);
protected static final EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
-
// for each type, an array of entries
private final Map<String, List<ModelBpmnEntry>> entriesByType = new HashMap<>();
-
// for each id, an array of entries
private final Map<String, List<ModelBpmnEntry>> entriesById = new HashMap<>();
-
// List of all elementIds
private List<String> bpmnElementIds;
@@ -67,36 +62,37 @@ public class ModelBpmn {
*
* @param modelBpmnPropText
* @return
- * @throws IOException
- * @throws JsonMappingException
- * @throws JsonParseException
*/
- public static ModelBpmn create(String modelBpmnPropText) throws IOException {
- ModelBpmn modelBpmn = new ModelBpmn();
- ObjectMapper objectMapper = new ObjectMapper();
- ObjectNode root = objectMapper.readValue(modelBpmnPropText, ObjectNode.class);
- // iterate over each entry like:
- // "Policy":[{"id":"Policy","from":"StartEvent_1"}]
- Iterator<Entry<String, JsonNode>> entryItr = root.fields();
- List<String> bpmnElementIdList = new ArrayList<>();
- while (entryItr.hasNext()) {
- // process the entry
- Entry<String, JsonNode> entry = entryItr.next();
- String type = entry.getKey();
- ArrayNode arrayNode = (ArrayNode) entry.getValue();
- // process each id/from object, like:
- // {"id":"Policy","from":"StartEvent_1"}
- for (JsonNode anArrayNode : arrayNode) {
- ObjectNode node = (ObjectNode) anArrayNode;
- String id = node.get("id").asText();
- String fromId = node.get("from").asText();
- ModelBpmnEntry modelBpmnEntry = new ModelBpmnEntry(type, id, fromId);
- modelBpmn.addEntry(modelBpmnEntry);
- bpmnElementIdList.add(id);
+ public static ModelBpmn create(String modelBpmnPropText) {
+ try {
+ ModelBpmn modelBpmn = new ModelBpmn();
+ ObjectMapper objectMapper = new ObjectMapper();
+ ObjectNode root = objectMapper.readValue(modelBpmnPropText, ObjectNode.class);
+ // iterate over each entry like:
+ // "Policy":[{"id":"Policy","from":"StartEvent_1"}]
+ Iterator<Entry<String, JsonNode>> entryItr = root.fields();
+ List<String> bpmnElementIdList = new ArrayList<>();
+ while (entryItr.hasNext()) {
+ // process the entry
+ Entry<String, JsonNode> entry = entryItr.next();
+ String type = entry.getKey();
+ ArrayNode arrayNode = (ArrayNode) entry.getValue();
+ // process each id/from object, like:
+ // {"id":"Policy","from":"StartEvent_1"}
+ for (JsonNode anArrayNode : arrayNode) {
+ ObjectNode node = (ObjectNode) anArrayNode;
+ String id = node.get("id").asText();
+ String fromId = node.get("from").asText();
+ ModelBpmnEntry modelBpmnEntry = new ModelBpmnEntry(type, id, fromId);
+ modelBpmn.addEntry(modelBpmnEntry);
+ bpmnElementIdList.add(id);
+ }
+ modelBpmn.setBpmnElementIds(bpmnElementIdList);
}
- modelBpmn.setBpmnElementIds(bpmnElementIdList);
+ return modelBpmn;
+ } catch (IOException e) {
+ throw new ModelBpmnException("Exception occurred during the decoding of the bpmn JSON", e);
}
- return modelBpmn;
}
/**
@@ -122,8 +118,8 @@ public class ModelBpmn {
}
/**
- * This method verifies if the ModelElement Type (holmes, tca,
- * ...) is in the list.
+ * This method verifies if the ModelElement Type (holmes, tca, ...) is in
+ * the list.
*
* @param type
* A model Element type (tca, ...)
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsService.java b/src/main/java/org/onap/clamp/clds/service/CldsService.java
index f9eeeb58..bbcfd5d2 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsService.java
@@ -56,13 +56,14 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.xml.transform.TransformerException;
+import org.apache.commons.codec.DecoderException;
import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.engine.RuntimeService;
import org.camunda.bpm.engine.runtime.ProcessInstance;
import org.json.simple.parser.ParseException;
import org.onap.clamp.clds.client.DcaeDispatcherServices;
import org.onap.clamp.clds.client.DcaeInventoryServices;
-import org.onap.clamp.clds.client.SdcCatalogServices;
+import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.exception.CldsConfigException;
import org.onap.clamp.clds.exception.SdcCommunicationException;
@@ -337,12 +338,6 @@ public class CldsService extends SecureServiceBase {
logger.info("PUT propText={}", cldsModel.getPropText());
logger.info("PUT imageText={}", cldsModel.getImageText());
cldsModel.setName(modelName);
- try {
- duplicateCheckforServiceVf(modelName, cldsModel.getPropText());
- } catch (IOException | BadRequestException e) {
- logger.error("Exception occured during duplicate check for service and VF", e);
- throw new CldsConfigException(e.getMessage(), e);
- }
if (cldsModel.getTemplateName() != null) {
CldsTemplate template = cldsDao.getTemplate(cldsModel.getTemplateName());
if (template != null) {
@@ -390,8 +385,13 @@ public class CldsService extends SecureServiceBase {
* @param model
* @return
* @throws TransformerException
+ * In case of issues when doing the XSLT of the BPMN flow
* @throws ParseException
+ * In case of issues when parsing the JSON
* @throws GeneralSecurityException
+ * In case of issues when decrypting the password
+ * @throws DecoderException
+ * In case of issues with the Hex String decoding
*/
@ApiOperation(value = "Saves and processes an action for a CLDS model by name", notes = "", response = String.class)
@PUT
@@ -400,7 +400,7 @@ public class CldsService extends SecureServiceBase {
@Produces(MediaType.APPLICATION_JSON)
public CldsModel putModelAndProcessAction(@PathParam("action") String action,
@PathParam("modelName") String modelName, @QueryParam("test") String test, CldsModel model)
- throws TransformerException, ParseException, GeneralSecurityException {
+ throws TransformerException, ParseException, GeneralSecurityException, DecoderException {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: Process model action", getPrincipalName());
String actionCd = action.toUpperCase();
@@ -558,13 +558,15 @@ public class CldsService extends SecureServiceBase {
*
* @throws GeneralSecurityException
* In case of issue when decryting the SDC password
+ * @throws DecoderException
+ * In case of issues with the decoding of the Hex String
*
*/
@ApiOperation(value = "Retrieves sdc services", notes = "", response = String.class)
@GET
@Path("/sdc/services")
@Produces(MediaType.APPLICATION_JSON)
- public String getSdcServices() throws GeneralSecurityException {
+ public String getSdcServices() throws GeneralSecurityException, DecoderException {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: GET sdc services", getPrincipalName());
String retStr;
@@ -603,7 +605,9 @@ public class CldsService extends SecureServiceBase {
* on refresh and non refresh
*
* @throws GeneralSecurityException
- * In case of issue when decryting the SDC password
+ * In case of issues with the decryting the encrypted password
+ * @throws DecoderException
+ * In case of issues with the decoding of the Hex String
*
*/
@ApiOperation(value = "Retrieves total properties by using invariantUUID based on refresh and non refresh", notes = "", response = String.class)
@@ -612,7 +616,8 @@ public class CldsService extends SecureServiceBase {
@Produces(MediaType.APPLICATION_JSON)
public String getSdcPropertiesByServiceUUIDForRefresh(
@PathParam("serviceInvariantUUID") String serviceInvariantUUID,
- @DefaultValue("false") @QueryParam("refresh") String refresh) throws GeneralSecurityException {
+ @DefaultValue("false") @QueryParam("refresh") String refresh)
+ throws GeneralSecurityException, DecoderException {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: GET sdc properties by uuid", getPrincipalName());
CldsServiceData cldsServiceData = new CldsServiceData();
@@ -831,6 +836,12 @@ public class CldsService extends SecureServiceBase {
@QueryParam("test") String test, CldsModel model) throws IOException {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsService: Deploy model", getPrincipalName());
+ try {
+ checkForDuplicateServiceVf(modelName, model.getPropText());
+ } catch (IOException | BadRequestException e) {
+ logger.error("Exception occured during duplicate check for service and VF", e);
+ throw new CldsConfigException(e.getMessage(), e);
+ }
String deploymentId = "";
// If model is already deployed then pass same deployment id
if (model.getDeploymentId() != null && !model.getDeploymentId().isEmpty()) {
@@ -932,13 +943,13 @@ public class CldsService extends SecureServiceBase {
}
}
- private void duplicateCheckforServiceVf(String modelName, String modelPropText) throws IOException {
+ private void checkForDuplicateServiceVf(String modelName, String modelPropText) throws IOException {
JsonNode modelJson = new ObjectMapper().readTree(modelPropText);
JsonNode globalNode = modelJson.get("global");
String service = AbstractModelElement.getValueByName(globalNode, "service");
List<String> resourceVf = AbstractModelElement.getValuesByName(globalNode, "vf");
if (service != null && resourceVf != null && !resourceVf.isEmpty()) {
- List<CldsModelProp> cldsModelPropList = cldsDao.getAllModelProperties();
+ List<CldsModelProp> cldsModelPropList = cldsDao.getDeployedModelProperties();
for (CldsModelProp cldsModelProp : cldsModelPropList) {
JsonNode currentJson = new ObjectMapper().readTree(cldsModelProp.getPropText());
JsonNode currentNode = currentJson.get("global");
@@ -947,8 +958,9 @@ public class CldsService extends SecureServiceBase {
if (currentVf != null && !currentVf.isEmpty()) {
if (!modelName.equalsIgnoreCase(cldsModelProp.getName()) && service.equalsIgnoreCase(currentService)
&& resourceVf.get(0).equalsIgnoreCase(currentVf.get(0))) {
- throw new BadRequestException("Same service/VF already exists in " + cldsModelProp.getName()
- + " model, please select different service/VF.");
+ throw new BadRequestException("Same Service/VF already exists in " + cldsModelProp.getName()
+ + " model, please select different Service/VF.");
+
}
}
}
diff --git a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java
index c84f5efb..070c0667 100644
--- a/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java
+++ b/src/main/java/org/onap/clamp/clds/service/CldsTemplateService.java
@@ -44,7 +44,6 @@ import javax.xml.transform.TransformerException;
import org.onap.clamp.clds.dao.CldsDao;
import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.model.ValueItem;
-import org.onap.clamp.clds.transform.XslTransformer;
import org.onap.clamp.clds.util.LoggingUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -55,15 +54,11 @@ import org.springframework.beans.factory.annotation.Value;
@AjscService
@Path("/cldsTempate")
public class CldsTemplateService extends SecureServiceBase {
-
@Value("${CLDS_PERMISSION_TYPE_TEMPLATE:permission-type-template}")
private String cldsPermissionTypeTemplate;
-
@Value("${CLDS_PERMISSION_INSTANCE:dev}")
private String cldsPermissionInstance;
-
private SecureServicePermission permissionReadTemplate;
-
private SecureServicePermission permissionUpdateTemplate;
@PostConstruct
@@ -75,12 +70,7 @@ public class CldsTemplateService extends SecureServiceBase {
}
@Autowired
- private CldsDao cldsDao;
-
- @Autowired
- private XslTransformer cldsBpmnTransformer;
-
- private static String userid;
+ private CldsDao cldsDao;
/**
* REST service that retrieves BPMN for a CLDS template name from the
@@ -170,7 +160,6 @@ public class CldsTemplateService extends SecureServiceBase {
Date startTime = new Date();
LoggingUtils.setRequestContext("CldsTemplateService: PUT template", getPrincipalName());
isAuthorized(permissionUpdateTemplate);
-
logger.info("PUT Template for templateName=" + templateName);
logger.info("PUT bpmnText=" + cldsTemplate.getBpmnText());
logger.info("PUT propText=" + cldsTemplate.getPropText());
@@ -185,13 +174,11 @@ public class CldsTemplateService extends SecureServiceBase {
logger.info(" bpmnText : " + cldsTemplate.getBpmnText());
logger.info(" Image Text : " + cldsTemplate.getImageText());
logger.info(" Prop Text : " + cldsTemplate.getPropText());
- cldsTemplate.save(cldsDao, userid);
-
+ cldsTemplate.save(cldsDao, null);
// audit log
LoggingUtils.setTimeContext(startTime, new Date());
LoggingUtils.setResponseContext("0", "Put template success", this.getClass().getName());
auditLogger.info("PUT template completed");
-
return cldsTemplate;
}
diff --git a/src/test/java/org/onap/clamp/clds/AbstractItCase.java b/src/test/java/org/onap/clamp/clds/AbstractItCase.java
index 9be8a13b..d3f64240 100644
--- a/src/test/java/org/onap/clamp/clds/AbstractItCase.java
+++ b/src/test/java/org/onap/clamp/clds/AbstractItCase.java
@@ -24,7 +24,7 @@
package org.onap.clamp.clds;
import org.junit.BeforeClass;
-import org.onap.clamp.clds.client.PolicyClient;
+import org.onap.clamp.clds.client.req.policy.PolicyClient;
import org.onap.clamp.clds.model.refprop.RefProp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ActiveProfiles;
diff --git a/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java b/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java
index 734b6052..9b8f4aad 100644
--- a/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java
+++ b/src/test/java/org/onap/clamp/clds/client/req/OperationalPolicyReqTest.java
@@ -31,6 +31,7 @@ import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
+import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq;
import org.onap.policy.controlloop.policy.PolicyResult;
import org.onap.policy.sdc.Resource;
import org.onap.policy.sdc.ResourceType;
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
index 1427c329..78b24013 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsDaoItCase.java
@@ -25,6 +25,8 @@ package org.onap.clamp.clds.it;
import static org.junit.Assert.assertEquals;
+import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils;
+
import java.io.IOException;
import javax.ws.rs.NotFoundException;
@@ -51,10 +53,8 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
@TestPropertySource(locations = "classpath:application-no-camunda.properties")
public class CldsDaoItCase extends AbstractItCase {
-
@Autowired
public CldsDao cldsDao;
-
private String bpmnText;
private String imageText;
private String bpmnPropText;
@@ -74,40 +74,37 @@ public class CldsDaoItCase extends AbstractItCase {
@Test
public void testModelSave() throws IOException {
+ String randomNameTemplate = RandomStringUtils.randomAlphanumeric(5);
+ String randomNameModel = RandomStringUtils.randomAlphanumeric(5);
// Add the template first
CldsTemplate newTemplate = new CldsTemplate();
- newTemplate.setName("test-template");
-
+ newTemplate.setName(randomNameTemplate);
newTemplate.setBpmnText(bpmnText);
newTemplate.setImageText(imageText);
-
// Save the template in DB
cldsDao.setTemplate(newTemplate, "user");
// Test if it's well there
- CldsTemplate newTemplateRead = cldsDao.getTemplate("test-template");
+ CldsTemplate newTemplateRead = cldsDao.getTemplate(randomNameTemplate);
assertEquals(bpmnText, newTemplateRead.getBpmnText());
assertEquals(imageText, newTemplateRead.getImageText());
-
// Save the model
CldsModel newModel = new CldsModel();
- newModel.setName("test-model");
-
+ newModel.setName(randomNameModel);
newModel.setBpmnText(bpmnText);
newModel.setImageText(imageText);
newModel.setPropText(bpmnPropText);
newModel.setControlNamePrefix("ClosedLoop-");
- newModel.setTemplateName("test-template");
+ newModel.setTemplateName(randomNameTemplate);
newModel.setTemplateId(newTemplate.getId());
newModel.setDocText(newTemplate.getPropText());
newModel.setDocId(newTemplate.getPropId());
// Save the model in DB
cldsDao.setModel(newModel, "user");
// Test if the model can be retrieved
- CldsModel newCldsModel = cldsDao.getModelTemplate("test-model");
+ CldsModel newCldsModel = cldsDao.getModelTemplate(randomNameModel);
assertEquals(bpmnText, newCldsModel.getBpmnText());
assertEquals(imageText, newCldsModel.getImageText());
assertEquals(bpmnPropText, newCldsModel.getPropText());
-
}
@Test(expected = NotFoundException.class)
@@ -125,21 +122,16 @@ public class CldsDaoItCase extends AbstractItCase {
// Add the template first
CldsTemplate newTemplate = new CldsTemplate();
newTemplate.setName("test-template-for-event");
-
newTemplate.setBpmnText(bpmnText);
newTemplate.setImageText(imageText);
-
newTemplate.save(cldsDao, "user");
-
// Test if it's well there
CldsTemplate newTemplateRead = CldsTemplate.retrieve(cldsDao, "test-template-for-event", false);
assertEquals(bpmnText, newTemplateRead.getBpmnText());
assertEquals(imageText, newTemplateRead.getImageText());
-
// Save the model
CldsModel newModel = new CldsModel();
newModel.setName("test-model-for-event");
-
newModel.setBpmnText(bpmnText);
newModel.setImageText(imageText);
newModel.setPropText(bpmnPropText);
@@ -148,7 +140,6 @@ public class CldsDaoItCase extends AbstractItCase {
newModel.setTemplateId(newTemplate.getId());
newModel.setDocText(newTemplate.getPropText());
newModel.setDocId(newTemplate.getPropId());
-
CldsEvent.insEvent(cldsDao, newModel, "user", CldsEvent.ACTION_RESTART, CldsEvent.ACTION_STATE_COMPLETED,
"process-instance-id");
}
diff --git a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
index a1882eaa..f6e9abdd 100644
--- a/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/CldsServiceItCase.java
@@ -25,20 +25,30 @@ package org.onap.clamp.clds.it;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import com.att.aft.dme2.internal.apache.commons.lang.RandomStringUtils;
+
+import java.io.IOException;
import java.io.InputStream;
import java.security.Principal;
import java.util.Properties;
import javax.ws.rs.core.SecurityContext;
+import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.onap.clamp.clds.AbstractItCase;
+import org.onap.clamp.clds.dao.CldsDao;
+import org.onap.clamp.clds.model.CldsHealthCheck;
import org.onap.clamp.clds.model.CldsInfo;
+import org.onap.clamp.clds.model.CldsModel;
+import org.onap.clamp.clds.model.CldsTemplate;
import org.onap.clamp.clds.service.CldsService;
+import org.onap.clamp.clds.util.ResourceFileUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
@@ -52,19 +62,34 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(locations = "classpath:application-no-camunda.properties")
public class CldsServiceItCase extends AbstractItCase {
-
@Autowired
- CldsService cldsService;
+ CldsService cldsService;
+ private String bpmnText;
+ private String imageText;
+ private String bpmnPropText;
+ @Autowired
+ public CldsDao cldsDao;
+
+ /**
+ * Setup the variable before the tests execution.
+ *
+ * @throws IOException
+ * In case of issues when opening the files
+ */
+ @Before
+ public void setupBefore() throws IOException {
+ bpmnText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-template.xml");
+ imageText = ResourceFileUtil.getResourceAsString("example/dao/image-template.xml");
+ bpmnPropText = ResourceFileUtil.getResourceAsString("example/dao/bpmn-prop.json");
+ }
@Test
public void testCldsInfoNotAuthorized() throws Exception {
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
Principal principal = Mockito.mock(Principal.class);
Mockito.when(principal.getName()).thenReturn("admin");
-
Mockito.when(securityContext.getUserPrincipal()).thenReturn(principal);
cldsService.setSecurityContext(securityContext);
-
CldsInfo cldsInfo = cldsService.getCldsInfo();
assertFalse(cldsInfo.isPermissionReadCl());
assertFalse(cldsInfo.isPermissionReadTemplate());
@@ -74,32 +99,75 @@ public class CldsServiceItCase extends AbstractItCase {
@Test
public void testCldsInfoAuthorized() throws Exception {
-
SecurityContext securityContext = Mockito.mock(SecurityContext.class);
Principal p = Mockito.mock(Principal.class);
Mockito.when(p.getName()).thenReturn("admin");
-
Mockito.when(securityContext.getUserPrincipal()).thenReturn(p);
Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|read")).thenReturn(true);
Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|update")).thenReturn(true);
Mockito.when(securityContext.isUserInRole("permission-type-template|dev|read")).thenReturn(true);
Mockito.when(securityContext.isUserInRole("permission-type-template|dev|update")).thenReturn(true);
-
cldsService.setSecurityContext(securityContext);
-
CldsInfo cldsInfo = cldsService.getCldsInfo();
assertTrue(cldsInfo.isPermissionReadCl());
assertTrue(cldsInfo.isPermissionReadTemplate());
assertTrue(cldsInfo.isPermissionUpdateCl());
assertTrue(cldsInfo.isPermissionUpdateTemplate());
-
Properties prop = new Properties();
-
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("clds-version.properties");
prop.load(in);
in.close();
-
assertEquals(cldsInfo.getCldsVersion(), prop.getProperty("clds.version"));
assertEquals(cldsInfo.getUserName(), "admin");
}
+
+ @Test
+ public void testGetHealthCheck() throws Exception {
+ CldsHealthCheck cldsHealthCheck = cldsService.gethealthcheck();
+ assertNotNull(cldsHealthCheck);
+ assertEquals("UP", cldsHealthCheck.getHealthCheckStatus());
+ assertEquals("CLDS-APP", cldsHealthCheck.getHealthCheckComponent());
+ assertEquals("OK", cldsHealthCheck.getDescription());
+ }
+
+ @Test
+ public void testPutModel() throws Exception {
+ String randomNameTemplate = RandomStringUtils.randomAlphanumeric(5);
+ String randomNameModel = RandomStringUtils.randomAlphanumeric(5);
+ SecurityContext securityContext = Mockito.mock(SecurityContext.class);
+ Principal p = Mockito.mock(Principal.class);
+ Mockito.when(p.getName()).thenReturn("admin");
+ Mockito.when(securityContext.getUserPrincipal()).thenReturn(p);
+ Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|read")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-cl|dev|update")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-template|dev|read")).thenReturn(true);
+ Mockito.when(securityContext.isUserInRole("permission-type-template|dev|update")).thenReturn(true);
+ cldsService.setSecurityContext(securityContext);
+ // Add the template first
+ CldsTemplate newTemplate = new CldsTemplate();
+ newTemplate.setName(randomNameTemplate);
+ newTemplate.setBpmnText(bpmnText);
+ newTemplate.setImageText(imageText);
+ // Save the template in DB
+ cldsDao.setTemplate(newTemplate, "user");
+ // Test if it's well there
+ CldsTemplate newTemplateRead = cldsDao.getTemplate(randomNameTemplate);
+ assertEquals(bpmnText, newTemplateRead.getBpmnText());
+ assertEquals(imageText, newTemplateRead.getImageText());
+ // Save the model
+ CldsModel newModel = new CldsModel();
+ newModel.setName(randomNameTemplate);
+ newModel.setBpmnText(bpmnText);
+ newModel.setImageText(imageText);
+ newModel.setPropText(bpmnPropText);
+ newModel.setControlNamePrefix("ClosedLoop-");
+ newModel.setTemplateName("test-template");
+ newModel.setTemplateId(newTemplate.getId());
+ newModel.setDocText(newTemplate.getPropText());
+ newModel.setDocId(newTemplate.getPropId());
+ // Test the PutModel method
+ cldsService.putModel(randomNameModel, newModel);
+ // Verify whether it has been added properly or not
+ assertNotNull(cldsDao.getModel(randomNameModel));
+ }
}
diff --git a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java
index c87bbf62..30091995 100644
--- a/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/OperationPolicyReqItCase.java
@@ -36,7 +36,7 @@ import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.AbstractItCase;
-import org.onap.clamp.clds.client.req.OperationalPolicyReq;
+import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq;
import org.onap.clamp.clds.model.CldsEvent;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.prop.Policy;
@@ -52,7 +52,6 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
@TestPropertySource(locations = "classpath:application-no-camunda.properties")
public class OperationPolicyReqItCase extends AbstractItCase {
-
@Test
public void formatAttributesTest() throws IOException, BuilderException {
String modelProp = ResourceFileUtil.getResourceAsString("example/modelProp.json");
diff --git a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
index c129800d..27573776 100644
--- a/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/PolicyClientItCase.java
@@ -34,8 +34,8 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.AbstractItCase;
-import org.onap.clamp.clds.client.req.OperationalPolicyReq;
-import org.onap.clamp.clds.client.req.TcaRequestFormatter;
+import org.onap.clamp.clds.client.req.policy.OperationalPolicyReq;
+import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter;
import org.onap.clamp.clds.model.CldsEvent;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.model.prop.Policy;
@@ -77,7 +77,6 @@ public class PolicyClientItCase extends AbstractItCase {
if (policy.isFound()) {
for (PolicyChain policyChain : policy.getPolicyChains()) {
String operationalPolicyRequestUuid = UUID.randomUUID().toString();
-
Map<AttributeType, Map<String, String>> attributes = OperationalPolicyReq.formatAttributes(refProp,
prop, policy.getId(), policyChain);
policyClient.sendBrmsPolicy(attributes, prop, operationalPolicyRequestUuid);
@@ -91,7 +90,6 @@ public class PolicyClientItCase extends AbstractItCase {
if (tca.isFound()) {
String tcaPolicyRequestUuid = UUID.randomUUID().toString();
String policyJson = TcaRequestFormatter.createPolicyJson(refProp, prop);
-
try {
policyClient.sendMicroServiceInJson(policyJson, prop, tcaPolicyRequestUuid);
} catch (Exception e) {
@@ -102,7 +100,6 @@ public class PolicyClientItCase extends AbstractItCase {
private void deleteOperationalPolicy(String actionCd) throws Exception {
ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp);
-
Policy policy = prop.getType(Policy.class);
if (policy.isFound()) {
prop.setCurrentModelElementId(policy.getId());
@@ -115,11 +112,9 @@ public class PolicyClientItCase extends AbstractItCase {
private void deleteTcaPolicy(String actionCd) throws Exception {
ModelProperties prop = new ModelProperties(modelName, controlName, actionCd, false, modelBpmnProp, modelProp);
-
Tca tca = prop.getType(Tca.class);
if (tca.isFound()) {
prop.setCurrentModelElementId(tca.getId());
-
try {
policyClient.deleteMicrosService(prop);
} catch (Exception e) {
@@ -133,21 +128,15 @@ public class PolicyClientItCase extends AbstractItCase {
* Temporarily disabled Test.
*/
public void testCreateUpdateDeleteOperationalPolicy() throws Exception {
-
createUpdateOperationalPolicy(CldsEvent.ACTION_SUBMIT);
-
TimeUnit.SECONDS.sleep(20);
-
deleteOperationalPolicy(CldsEvent.ACTION_DELETE);
}
@Test
public void testCreateUpdateDeleteTcaPolicy() throws Exception {
-
createUpdateTcaPolicy(CldsEvent.ACTION_SUBMIT);
-
TimeUnit.SECONDS.sleep(20);
-
deleteTcaPolicy(CldsEvent.ACTION_DELETE);
}
}
diff --git a/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java b/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java
index 478a7b38..7ccda5a8 100644
--- a/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/RefPropItCase.java
@@ -23,6 +23,8 @@
package org.onap.clamp.clds.it;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
@@ -42,6 +44,7 @@ import org.springframework.test.context.junit4.SpringRunner;
@SpringBootTest
@TestPropertySource(locations = "classpath:application-no-camunda.properties")
public class RefPropItCase extends AbstractItCase {
+ protected static final EELFLogger logger = EELFManager.getInstance().getLogger(RefPropItCase.class);
/**
* Test getting prop value as a JSON Node / template.
@@ -53,12 +56,9 @@ public class RefPropItCase extends AbstractItCase {
public void testJsonTemplate() throws IOException {
ObjectNode root = (ObjectNode) refProp.getJsonTemplate("tca.template");
root.put("closedLoopControlName", "ClosedLoop-FRWL-SIG-1582f840-2881-11e6-b4ec-005056a9d756");
-
ObjectMapper mapper = new ObjectMapper();
String jsonText = mapper.writeValueAsString(root);
- System.out.println("jsonText=" + jsonText);
-
+ logger.error("Exception caught IllegalArgumentException as expected");
// assertEquals(topicsJson, ref.getTopicsToJson());
}
-
}
diff --git a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java
index b684a506..5d3b7703 100644
--- a/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/SdcCatalogServicesItCase.java
@@ -33,7 +33,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.onap.clamp.clds.AbstractItCase;
-import org.onap.clamp.clds.client.SdcCatalogServices;
+import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
import org.onap.clamp.clds.model.CldsAlarmCondition;
import org.onap.clamp.clds.model.CldsSdcResource;
import org.onap.clamp.clds.model.CldsSdcResourceBasicInfo;
diff --git a/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java b/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java
index faff2846..757d85b5 100644
--- a/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/SdcReqItCase.java
@@ -30,12 +30,13 @@ import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.List;
+import org.apache.commons.codec.DecoderException;
import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
-import org.onap.clamp.clds.client.SdcCatalogServices;
-import org.onap.clamp.clds.client.req.SdcReq;
+import org.onap.clamp.clds.client.req.sdc.SdcCatalogServices;
+import org.onap.clamp.clds.client.req.sdc.SdcReq;
import org.onap.clamp.clds.model.CldsSdcResource;
import org.onap.clamp.clds.model.CldsSdcServiceDetail;
import org.onap.clamp.clds.model.prop.Global;
@@ -55,7 +56,7 @@ public class SdcReqItCase {
private SdcReq sdcReq;
@Test
- public void getSdcReqUrlsListNoGlobalPropTest() throws GeneralSecurityException {
+ public void getSdcReqUrlsListNoGlobalPropTest() throws GeneralSecurityException, DecoderException {
ModelProperties prop = mock(ModelProperties.class);
SdcCatalogServices sdcCatalogServices = mock(SdcCatalogServices.class);
DelegateExecution delegateExecution = mock(DelegateExecution.class);
diff --git a/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java b/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java
index a32743a6..ccbcb0ea 100644
--- a/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/TcaRequestFormatterItCase.java
@@ -32,7 +32,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.onap.clamp.clds.AbstractItCase;
-import org.onap.clamp.clds.client.req.TcaRequestFormatter;
+import org.onap.clamp.clds.client.req.tca.TcaRequestFormatter;
import org.onap.clamp.clds.model.CldsEvent;
import org.onap.clamp.clds.model.prop.ModelProperties;
import org.onap.clamp.clds.util.ResourceFileUtil;