diff options
Diffstat (limited to 'ms/neng/src/main')
9 files changed, 100 insertions, 30 deletions
diff --git a/ms/neng/src/main/docker/Dockerfile b/ms/neng/src/main/docker/Dockerfile index dd239ebc..e8594e5f 100644 --- a/ms/neng/src/main/docker/Dockerfile +++ b/ms/neng/src/main/docker/Dockerfile @@ -19,7 +19,7 @@ #================================================================================ # Docker setup for the micro-service #================================================================================ -FROM onap/ccsdk-ubuntu-image:latest +FROM onap/ccsdk-ubuntu-image:0.3.0-SNAPSHOT VOLUME /tmp ADD NetworkElementNameGen.jar app.jar VOLUME /opt/etc 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."); } diff --git a/ms/neng/src/main/resources/db/changelog/db.changelog-master.xml b/ms/neng/src/main/resources/db/changelog/db.changelog-master.xml index dbbd71b6..e481be8c 100644 --- a/ms/neng/src/main/resources/db/changelog/db.changelog-master.xml +++ b/ms/neng/src/main/resources/db/changelog/db.changelog-master.xml @@ -29,5 +29,9 @@ <include file="db/changelog/scripts/rel_18_10/01_initial_ref_data_v1.sql" /> <include file="db/changelog/scripts/rel_18_10/02_create_indexes_ddl.sql" /> <include file="db/changelog/scripts/rel_18_10/04_ref_data_extrn_int.sql" /> + + <include file="db/changelog/scripts/rel_18_10/create_message_table.sql" /> + <include file="db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql" /> + </databaseChangeLog> diff --git a/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql b/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql new file mode 100644 index 00000000..bf16b621 --- /dev/null +++ b/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/10_identifier_map_upd_dml.sql @@ -0,0 +1,10 @@ +--liquibase formatted sql +--changeset identifier_map_update_sql_recipefunction:18_10.identifier_map_upd_dml.sql + +delete from IDENTIFIER_MAP where POLICY_FN_NAME='UUID'; + +INSERT INTO IDENTIFIER_MAP(POLICY_FN_NAME, JS_FN_NAME, CREATED_BY) VALUES ('UUID','genUUID', 'Initial'); + +delete from IDENTIFIER_MAP where POLICY_FN_NAME='TIMESTAMP'; + +INSERT INTO IDENTIFIER_MAP(POLICY_FN_NAME, JS_FN_NAME, CREATED_BY) VALUES ('TIMESTAMP','getISODateString', 'Initial'); diff --git a/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/create_message_table.sql b/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/create_message_table.sql new file mode 100644 index 00000000..33b42434 --- /dev/null +++ b/ms/neng/src/main/resources/db/changelog/scripts/rel_18_10/create_message_table.sql @@ -0,0 +1,14 @@ +--liquibase formatted sql +--changeset message_table:18_10.create_message_table.sql + +CREATE TABLE NELGEN_MESSAGE (NELGEN_MESSAGE_ID VARCHAR(500) PRIMARY KEY, +MESSAGE_ID VARCHAR(500) COMMENT 'Message id', +CONVERSATION_ID VARCHAR(500) COMMENT 'Conversation id for the transaction', +SERVICE_NAME VARCHAR(100) COMMENT 'Service name', +START_TIME DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT 'Transaction start time', +ELAPSED_MILLIS INTEGER , +STATUS VARCHAR(20) COMMENT 'Transaction status', +REQUEST VARCHAR(10000) NOT NULL COMMENT 'Request JSON', +RESPONSE VARCHAR(20000) COMMENT 'Request JSON', +REQUESTER VARCHAR(50) COMMENT 'Requester' +); |