summaryrefslogtreecommitdiffstats
path: root/ms/neng/src/main/java
diff options
context:
space:
mode:
authorBT2983 <BT2983@att.com>2018-09-16 21:30:20 -0600
committerTimoney, Dan (dt5972) <dt5972@att.com>2018-09-17 12:35:14 -0400
commit9783a8b7515eaaec310e404650d0dd9092eb90a8 (patch)
tree90101018aa23a5e91c0d9f85aec0fa5ff407e184 /ms/neng/src/main/java
parent4f44000fef9608150811e0b9f9b140c580f5822b (diff)
naming micro-service updates.
More tests, changes for maria DB, support for UUID and timestamp etc. Change-Id: I17bdf3acbe970ef4104f2ec0d59d5777c0a9928e Issue-ID: CCSDK-342 Signed-off-by: BT2983 <BT2983@att.com>
Diffstat (limited to 'ms/neng/src/main/java')
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java49
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java25
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java2
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java10
-rw-r--r--ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImpl.java14
5 files changed, 71 insertions, 29 deletions
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java
index 8cfe7c88..ec04960f 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/gen/NameGenerator.java
@@ -42,6 +42,7 @@ import org.onap.ccsdk.apps.ms.neng.core.exceptions.NengException;
import org.onap.ccsdk.apps.ms.neng.core.persistence.NamePersister;
import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyFinder;
import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyParameters;
+import org.onap.ccsdk.apps.ms.neng.core.policy.PolicyPropertyMethodUtils;
import org.onap.ccsdk.apps.ms.neng.core.policy.PolicySequence;
import org.onap.ccsdk.apps.ms.neng.core.policy.PropertyOperator;
import org.onap.ccsdk.apps.ms.neng.core.policy.RecipeParser;
@@ -73,21 +74,21 @@ public class NameGenerator {
/**
* Constructor.
*
- * @param policyFinder a way to find policies
- * @param policyParams parameters related to policy
- * @param seqGenerator a way to generate sequences
- * @param dbValidator a way to validate generated names against DB
- * @param aaiValidator a way to validate generated names against A&AI
- * @param namePersister a way to persist names
- * @param requestElement the request element for which the name is generated, containing data such
- * as policy name, naming-type, external-key and resource-name
- * @param allElements all the elements in the request (including the current request element for
- * which name is generated), as this is needed to re-use names generated from other request elements
- * within the same transaction
- * @param earlierNames names generated earlier in the same transaction, as a map from naming-type
- * to names (which is a map with keys "resource-name", "resource-value" and "external-key")
- * @param policyCache cache containing policies retrieved in this transaction, to avoid repeated
- * calls to policy manager within the same transaction
+ * @param policyFinder a way to find policies
+ * @param policyParams parameters related to policy
+ * @param seqGenerator a way to generate sequences
+ * @param dbValidator a way to validate generated names against DB
+ * @param aaiValidator a way to validate generated names against A&AI
+ * @param namePersister a way to persist names
+ * @param requestElement the request element for which the name is generated, containing data such
+ * as policy name, naming-type, external-key and resource-name
+ * @param allElements all the elements in the request (including the current request element for
+ * which name is generated), as this is needed to re-use names generated from other request elements
+ * within the same transaction
+ * @param earlierNames names generated earlier in the same transaction, as a map from naming-type
+ * to names (which is a map with keys "resource-name", "resource-value" and "external-key")
+ * @param policyCache cache containing policies retrieved in this transaction, to avoid repeated
+ * calls to policy manager within the same transaction
*/
public NameGenerator(PolicyFinder policyFinder, PolicyParameters policyParams, SequenceGenerator seqGenerator,
DbNameValidator dbValidator, AaiNameValidator aaiValidator, NamePersister namePersister,
@@ -146,7 +147,7 @@ public class NameGenerator {
response.put(RESOURCE_VALUE_ELEMENT_ITEM, value);
return response;
}
-
+
String buildSequenceSuffix(Map<String, Object> recipeValues, String recipeName, List<String> recipe)
throws Exception {
StringBuffer buf = new StringBuffer();
@@ -184,7 +185,7 @@ public class NameGenerator {
Map<String, ?> namingModel = namingModel(namingModels, namingType);
if (namingModel == null) {
throw new NengException(
- "Could not find the policy data for " + policyName + " and naming-type " + namingType);
+ "Could not find the policy data for " + policyName + " and naming-type " + namingType);
}
return generateNew(policyName, namingType, namingModels, namingModel);
} else {
@@ -211,6 +212,12 @@ public class NameGenerator {
if ("SEQUENCE".equals(recipeItem)) {
PolicySequence seq = seq(propMap);
recipeValues.put(recipeItem, seq);
+ } else if ("UUID".equals(recipeItem)) {
+ String uuid = PolicyPropertyMethodUtils.genUuid();
+ recipeValues.put(recipeItem, uuid);
+ } else if ("TIMESTAMP".equals(recipeItem)) {
+ String ts = PolicyPropertyMethodUtils.getIsoDateString();
+ recipeValues.put(recipeItem, ts);
} else {
String val = generateNonSequenceValue(namingModels, policyName, namingType, namingModel, propMap,
recipeItem);
@@ -311,8 +318,8 @@ public class NameGenerator {
if (val instanceof PolicySequence) {
PolicySequence seq = (PolicySequence) val;
if (scope.equals(seq.getScope())) {
- SeqGenData seqVal = generateSequenceValue(
- seq, policyName, namingType, recipeValues, item, lastSeq, attemptCount, recipe);
+ SeqGenData seqVal = generateSequenceValue(seq, policyName, namingType, recipeValues, item,
+ lastSeq, attemptCount, recipe);
String seqStr = SequenceFormatter.formatSequence(seqVal.getSeq(), seq);
seqVal.setSeqEncoded(seqStr);
seq.setKey(item);
@@ -434,7 +441,7 @@ public class NameGenerator {
}
return policy;
}
-
+
void storeGeneratedName(String key, String name, String namingType,
SeqGenData seqData) throws Exception {
String prefix = null;
@@ -465,7 +472,7 @@ public class NameGenerator {
record.setSequenceNumberEnc(seqEncoded);
this.namePersister.persist(record);
}
-
+
void validateAllItemsPresent(String policyName, String namingType, List<String> recipe,
Map<String, Object> recipeValues) throws Exception {
List<String> missing = new ArrayList<>();
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java
index 9f4725fb..67805246 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/policy/PolicyPropertyMethodUtils.java
@@ -20,13 +20,18 @@
package org.onap.ccsdk.apps.ms.neng.core.policy;
+import java.time.ZoneOffset;
+import java.time.ZonedDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.UUID;
+
/**
* Utility methods equivalent to the JavaScript like functions used in policies by the policy-manager.
*/
public class PolicyPropertyMethodUtils {
/**
- * Equivalent to the substring function used by policy-manager (which works similar to JavaScript
+ * Equivalent to the substring function used by policy-manager (which works similar to JavaScript
* substring function).
*/
public static String substring(String sourceStr, String startIndex, String endIndex) {
@@ -34,7 +39,7 @@ public class PolicyPropertyMethodUtils {
}
/**
- * Equivalent to the substring function used by policy-manager (which works similar to JavaScript
+ * Equivalent to the substring function used by policy-manager (which works similar to JavaScript
* substring function).
*/
public static String substring(String sourceStr, String length) {
@@ -66,4 +71,20 @@ public class PolicyPropertyMethodUtils {
public static String toLowerCase(String sourceStr) {
return sourceStr.toLowerCase();
}
+
+ /**
+ * Generates a random UUID and returns it.
+ */
+ public static String genUuid() {
+ UUID uuid = UUID.randomUUID();
+ return uuid.toString();
+ }
+
+ /**
+ * Generates a date timestamp.
+ */
+ public static String getIsoDateString() {
+ String utcDate = ZonedDateTime.now(ZoneOffset.UTC).format(DateTimeFormatter.ISO_INSTANT);
+ return utcDate.replaceAll("-", "").replaceAll(":", "").replaceAll("\\.", "");
+ }
}
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java
index daf8f574..a8ca4bb6 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/core/service/SpringServiceImpl.java
@@ -196,7 +196,7 @@ public class SpringServiceImpl implements SpringService {
void validateRequest(NameGenRequest request) throws Exception {
List<Map<String, String>> elems = request.getElements();
- if (!elems.isEmpty()) {
+ if (elems != null && !elems.isEmpty()) {
boolean error = false;
Set<String> externalKeySet = elems.stream().map(s -> s.get("external-key")).collect(Collectors.toSet());
if (externalKeySet.size() != request.getElements().size()) {
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java
index a401d214..db8d4429 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/AaiServiceImpl.java
@@ -74,6 +74,15 @@ public class AaiServiceImpl {
return !resp.isRecFound();
}
+
+ public void setAaiRestTempBuilder(RestTemplateBuilder aaiRestTempBuilder) {
+ this.aaiRestTempBuilder = aaiRestTempBuilder;
+ }
+
+ public void setRestTemplate(RestTemplate restTemplate) {
+ this.restTemplate = restTemplate;
+ }
+
AaiResponse makeOutboundCall(String url, String name) throws Exception {
String uri = aaiProps.getUriBase() + url + name;
log.info("AAI URI - " + uri);
@@ -128,4 +137,5 @@ public class AaiServiceImpl {
}
return keyStore;
}
+
}
diff --git a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImpl.java b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImpl.java
index a19c9153..392567b7 100644
--- a/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImpl.java
+++ b/ms/neng/src/main/java/org/onap/ccsdk/apps/ms/neng/service/extinf/impl/PolicyFinderServiceImpl.java
@@ -59,9 +59,7 @@ public class PolicyFinderServiceImpl implements PolicyFinder {
private static Logger log = Logger.getLogger(PolicyFinderServiceImpl.class.getName());
@Autowired PolicyManagerProps policManProps;
- @Autowired
- @Qualifier("policyMgrRestTempBuilder")
- RestTemplateBuilder policyMgrRestTempBuilder;
+ @Autowired @Qualifier("policyMgrRestTempBuilder") RestTemplateBuilder policyMgrRestTempBuilder;
@Autowired PolicyManagerAuthorizationInterceptor authInt;
RestTemplate restTemplate;
@@ -73,7 +71,7 @@ public class PolicyFinderServiceImpl implements PolicyFinder {
Object response = getConfig(policyName).getResponse();
if (response instanceof List) {
@SuppressWarnings("unchecked")
- List<Map<String, Object>> policyList = (List<Map<String, Object>>)response;
+ List<Map<String, Object>> policyList = (List<Map<String, Object>>) response;
return ((policyList != null && policyList.size() > 0) ? policyList.get(0) : null);
} else {
return null;
@@ -98,7 +96,7 @@ public class PolicyFinderServiceImpl implements PolicyFinder {
System.out.println(objectmapper.writeValueAsString(resp.getBody()));
List<Map<Object, Object>> respObj = objectmapper.readValue(
objectmapper.writeValueAsString(resp.getBody()),
- new TypeReference<List<Map<Object, Object>>>() {});
+ new TypeReference<List<Map<Object, Object>>>() {});
transformConfigObject(objectmapper, respObj);
GetConfigResponse getConfigResp = new GetConfigResponse();
getConfigResp.setResponse(respObj);
@@ -113,6 +111,12 @@ public class PolicyFinderServiceImpl implements PolicyFinder {
void handleError(HttpStatusCodeException e) throws Exception {
String respString = e.getResponseBodyAsString();
log.info(respString);
+ if (e.getStatusText() != null) {
+ log.info(e.getStatusText());
+ }
+ if (e.getResponseHeaders() != null && e.getResponseHeaders().toSingleValueMap() != null) {
+ log.info(e.getResponseHeaders().toSingleValueMap().toString());
+ }
if (HttpStatus.NOT_FOUND.equals(e.getStatusCode()) && (respString != null && respString.contains(""))) {
throw new NengException("Policy not found in policy manager.");
}