diff options
author | renealr <reneal.rogers@amdocs.com> | 2018-11-06 12:32:41 -0500 |
---|---|---|
committer | renealr <reneal.rogers@amdocs.com> | 2018-11-06 13:16:39 -0500 |
commit | 206e44d57c0b1800abc2faf313a5c0c1b4945a8a (patch) | |
tree | 28567262b09cff9d3d0fcf7966a92457cb509a64 /sparkybe-onap-service/src/main | |
parent | 97d1b45603ad3c860ac733810ff3064990433c50 (diff) |
update sparky with configurable features
Allow end user calls and sync calls to be configurable
expose the ability to set shallow entities configuration from a
delimited string
add proper exit condition for auto suggestion if the suggestible type
list is empty
enable a configurable domain
add the ability to personalize html header and title
Issue-ID: AAI-1874
Change-Id: Iec7183e0e82dba7f63780eeab824d000fe5f558c
Signed-off-by: renealr <reneal.rogers@amdocs.com>
Diffstat (limited to 'sparkybe-onap-service/src/main')
17 files changed, 407 insertions, 222 deletions
diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java index 0b9733f..dc6bdc0 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/aggregation/sync/AggregationSynchronizer.java @@ -478,7 +478,7 @@ public class AggregationSynchronizer extends AbstractEntitySynchronizer aaiWorkOnHand.incrementAndGet(); - supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter), aaiExecutor) + supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter,"sync"), aaiExecutor) .whenComplete((result, error) -> { aaiWorkOnHand.decrementAndGet(); diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java index 583f260..0cb7922 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/autosuggestion/sync/AutosuggestionSynchronizer.java @@ -158,6 +158,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer suggestionEntityLookup.getSuggestionSearchEntityDescriptors(); if (descriptorMap.isEmpty()) { + this.allWorkEnumerated = true; LOG.error(AaiUiMsgs.ERROR_LOADING_OXM_SUGGESTIBLE_ENTITIES); LOG.info(AaiUiMsgs.ERROR_LOADING_OXM_SUGGESTIBLE_ENTITIES); return OperationState.ERROR; @@ -335,7 +336,7 @@ public class AutosuggestionSynchronizer extends AbstractEntitySynchronizer aaiWorkOnHand.incrementAndGet(); - supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter), aaiExecutor) + supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter,"sync"), aaiExecutor) .whenComplete((result, error) -> { aaiWorkOnHand.decrementAndGet(); diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java index cf7908b..9481173 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/crossentityreference/sync/CrossEntityReferenceSynchronizer.java @@ -320,7 +320,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer aaiWorkOnHand.incrementAndGet(); - supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter), aaiExecutor) + supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter,"sync"), aaiExecutor) .whenComplete((result, error) -> { aaiWorkOnHand.decrementAndGet(); @@ -534,7 +534,7 @@ public class CrossEntityReferenceSynchronizer extends AbstractEntitySynchronizer OperationResult aaiQueryResult = aaiAdapter.queryActiveInventoryWithRetries( genericQueryStr, "application/json", - aaiAdapter.getEndpointConfig().getNumRequestRetries()); + aaiAdapter.getEndpointConfig().getNumRequestRetries(),"sync"); aaiWorkOnHand.decrementAndGet(); diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java index bd00d20..ebcc56a 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/ActiveInventoryAdapter.java @@ -69,12 +69,19 @@ public class ActiveInventoryAdapter { private static final String TRANSACTION_ID_PREFIX = "txnId-"; private static final String UI_APP_NAME = "AAI-UI"; + private static final String UI_REQUEST_TYPE = "req"; private OxmModelLoader oxmModelLoader; private OxmEntityLookup oxmEntityLookup; private RestEndpointConfig endpointConfig; private RestClient restClient; + private String domain; + + + private String appPartnerName = ""; + private String syncPartnerName = ""; + private Map<String, List<String>> messageHeaders; /** * Instantiates a new active inventory adapter. @@ -83,12 +90,13 @@ public class ActiveInventoryAdapter { */ public ActiveInventoryAdapter(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup, - RestEndpointConfig endpointConfig) + RestEndpointConfig endpointConfig,String domain) throws ElasticSearchOperationException, IOException, RestClientConstructionException { this.oxmModelLoader = oxmModelLoader; this.oxmEntityLookup = oxmEntityLookup; this.endpointConfig = endpointConfig; + this.domain = domain; /* * Add support for de-obfuscating basic auth password (if obfuscated) @@ -107,13 +115,47 @@ public class ActiveInventoryAdapter { this.restClient = RestClientFactory.buildClient(endpointConfig); } + + public String getAppPartnerName() { + return appPartnerName; + } + + public void setAppPartnerName(String appPartnerName) { + this.appPartnerName = appPartnerName; + } + + public String getSyncPartnerName() { + return syncPartnerName; + } + + public void setSyncPartnerName(String syncPartnerName) { + this.syncPartnerName = syncPartnerName; + } protected Map<String, List<String>> getMessageHeaders() { Map<String, List<String>> headers = new HashMap<String, List<String>>(); headers.putIfAbsent(HEADER_FROM_APP_ID, new ArrayList<String>()); - headers.get(HEADER_FROM_APP_ID).add(UI_APP_NAME); + headers.get(HEADER_FROM_APP_ID).add(appPartnerName); + + headers.putIfAbsent(HEADER_TRANS_ID, new ArrayList<String>()); + headers.get(HEADER_TRANS_ID).add(TRANSACTION_ID_PREFIX + NodeUtils.getRandomTxnId()); + + if (endpointConfig.getRestAuthenticationMode() == RestAuthenticationMode.SSL_BASIC) { + headers.putIfAbsent(HEADER_AUTHORIZATION, new ArrayList<String>()); + headers.get(HEADER_AUTHORIZATION).add(getBasicAuthenticationCredentials()); + } + + return headers; + } + + protected Map<String, List<String>> getSyncMessageHeaders() { + + Map<String, List<String>> headers = new HashMap<String, List<String>>(); + + headers.putIfAbsent(HEADER_FROM_APP_ID, new ArrayList<String>()); + headers.get(HEADER_FROM_APP_ID).add(syncPartnerName); headers.putIfAbsent(HEADER_TRANS_ID, new ArrayList<String>()); headers.get(HEADER_TRANS_ID).add(TRANSACTION_ID_PREFIX + NodeUtils.getRandomTxnId()); @@ -150,7 +192,7 @@ public class ActiveInventoryAdapter { throw new RuntimeException("Unable to resolve aai version."); } - return "/aai/" + versionStr.toLowerCase(); + return "/" + domain + "/" + versionStr.toLowerCase(); } @@ -271,7 +313,7 @@ public class ActiveInventoryAdapter { } return queryActiveInventoryWithRetries(link, "application/json", - endpointConfig.getNumRequestRetries()); + endpointConfig.getNumRequestRetries(),"sync"); } @@ -310,9 +352,14 @@ public class ActiveInventoryAdapter { * @return the operation result */ // package protected for test classes instead of private - OperationResult queryActiveInventory(String url, String acceptContentType) { + OperationResult queryActiveInventory(String url, String acceptContentType, String uiRequestType) { - return restClient.get(url, getMessageHeaders(), MediaType.APPLICATION_JSON_TYPE); + if (uiRequestType == UI_REQUEST_TYPE) { + messageHeaders = getMessageHeaders(); + } else { + messageHeaders = getSyncMessageHeaders(); + } + return restClient.get(url, messageHeaders, MediaType.APPLICATION_JSON_TYPE); } @@ -325,7 +372,7 @@ public class ActiveInventoryAdapter { } public OperationResult queryActiveInventoryWithRetries(String url, String responseType, - int numRetries) { + int numRetries,String uiRequestType) { OperationResult result = null; @@ -333,7 +380,7 @@ public class ActiveInventoryAdapter { LOG.debug(AaiUiMsgs.QUERY_AAI_RETRY_SEQ, url, String.valueOf(retryCount + 1)); - result = queryActiveInventory(url, responseType); + result = queryActiveInventory(url, responseType,uiRequestType); /** * Record number of times we have attempted the request to later summarize how many times we @@ -415,5 +462,9 @@ public class ActiveInventoryAdapter { characters such as '?', '&', etc. remain intact as needed by the synchronizer */ return (builder.build().toString() + (includeQueryParams ? queryParams : "")); } + + public String getDomain() { + return domain; + } } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/GizmoAdapter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/GizmoAdapter.java index a888c8b..c958054 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/GizmoAdapter.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/dal/GizmoAdapter.java @@ -50,229 +50,231 @@ import org.onap.aai.sparky.util.NodeUtils; public class GizmoAdapter { - private static final Logger LOG = LoggerFactory.getInstance().getLogger(GizmoAdapter.class); + private static final Logger LOG = LoggerFactory.getInstance().getLogger(GizmoAdapter.class); - private static final String HEADER_TRANS_ID = "X-TransactionId"; - private static final String HEADER_FROM_APP_ID = "X-FromAppId"; - private static final String HEADER_AUTHORIZATION = "Authorization"; + private static final String HEADER_TRANS_ID = "X-TransactionId"; + private static final String HEADER_FROM_APP_ID = "X-FromAppId"; + private static final String HEADER_AUTHORIZATION = "Authorization"; - private static final String HTTP_SCHEME = "http"; - private static final String HTTPS_SCHEME = "https"; + private static final String HTTP_SCHEME = "http"; + private static final String HTTPS_SCHEME = "https"; - private static final String TRANSACTION_ID_PREFIX = "txnId-"; - private static final String UI_APP_NAME = "AAI-UI"; + private static final String TRANSACTION_ID_PREFIX = "txnId-"; + private static final String UI_APP_NAME = "AAI-UI"; - private OxmModelLoader oxmModelLoader; + private OxmModelLoader oxmModelLoader; - private RestEndpointConfig endpointConfig; + private RestEndpointConfig endpointConfig; - private RestClient restClient; + private RestClient restClient; - private String inventoryBasePath; - private String relationshipsBasePath; + private String inventoryBasePath; + private String relationshipsBasePath; + private String appPartnerName = ""; - /** - * Instantiates a new active inventory adapter. - * - * @throws RestClientConstructionException - * - */ + /** + * Instantiates a new active inventory adapter. + * + * @throws RestClientConstructionException + * + */ - public GizmoAdapter(OxmModelLoader oxmModelLoader, RestEndpointConfig endpointConfig) - throws ElasticSearchOperationException, IOException, RestClientConstructionException { + public GizmoAdapter(OxmModelLoader oxmModelLoader, RestEndpointConfig endpointConfig) + throws ElasticSearchOperationException, IOException, RestClientConstructionException { - this.oxmModelLoader = oxmModelLoader; - this.endpointConfig = endpointConfig; - this.restClient = RestClientFactory.buildClient(endpointConfig); + this.oxmModelLoader = oxmModelLoader; + this.endpointConfig = endpointConfig; + this.restClient = RestClientFactory.buildClient(endpointConfig); - } + } + + public String getAppPartnerName() { + return appPartnerName; + } + + public void setAppPartnerName(String appPartnerName) { + this.appPartnerName = appPartnerName; + } - public String getRelationshipsBasePath() { - return relationshipsBasePath; - } - public void setRelationshipsBasePath(String relationshipsBasePath) { - this.relationshipsBasePath = relationshipsBasePath; - } + public String getRelationshipsBasePath() { + return relationshipsBasePath; + } - public String getInventoryBasePath() { - return inventoryBasePath; - } + public void setRelationshipsBasePath(String relationshipsBasePath) { + this.relationshipsBasePath = relationshipsBasePath; + } - public void setInventoryBasePath(String inventoryBasePath) { - this.inventoryBasePath = inventoryBasePath; - } + public String getInventoryBasePath() { + return inventoryBasePath; + } + + public void setInventoryBasePath(String inventoryBasePath) { + this.inventoryBasePath = inventoryBasePath; + } - public String getFullInventoryUrl(String resourceUrl) throws Exception { - final String host = endpointConfig.getEndpointIpAddress(); - final String port = endpointConfig.getEndpointServerPort(); - final String basePath = getInventoryBasePath(); - return String.format("https://%s:%s%s%s", host, port, basePath, resourceUrl); - } + public String getFullInventoryUrl(String resourceUrl) throws Exception { + final String host = endpointConfig.getEndpointIpAddress(); + final String port = endpointConfig.getEndpointServerPort(); + final String basePath = getInventoryBasePath(); + return String.format("https://%s:%s%s%s", host, port, basePath, resourceUrl); + } - public String addServerDetailsToUrl(String resourceUrl) throws Exception { - final String host = endpointConfig.getEndpointIpAddress(); - final String port = endpointConfig.getEndpointServerPort(); - return String.format("https://%s:%s/%s", host, port, resourceUrl); - } + public String addServerDetailsToUrl(String resourceUrl) throws Exception { + final String host = endpointConfig.getEndpointIpAddress(); + final String port = endpointConfig.getEndpointServerPort(); + return String.format("https://%s:%s/%s", host, port, resourceUrl); + } - public String getFullRelationshipUrl(String resourceUrl) throws Exception { - final String host = endpointConfig.getEndpointIpAddress(); - final String port = endpointConfig.getEndpointServerPort(); - final String basePath = getRelationshipsBasePath(); - return String.format("https://%s:%s%s%s", host, port, basePath, resourceUrl); - } + public String getFullRelationshipUrl(String resourceUrl) throws Exception { + final String host = endpointConfig.getEndpointIpAddress(); + final String port = endpointConfig.getEndpointServerPort(); + final String basePath = getRelationshipsBasePath(); + return String.format("https://%s:%s%s%s", host, port, basePath, resourceUrl); + } - protected Map<String, List<String>> getMessageHeaders() { + protected Map<String, List<String>> getMessageHeaders() { - Map<String, List<String>> headers = new HashMap<String, List<String>>(); + Map<String, List<String>> headers = new HashMap<String, List<String>>(); - headers.putIfAbsent(HEADER_FROM_APP_ID, new ArrayList<String>()); - headers.get(HEADER_FROM_APP_ID).add(UI_APP_NAME); + headers.putIfAbsent(HEADER_FROM_APP_ID, new ArrayList<String>()); + headers.get(HEADER_FROM_APP_ID).add(appPartnerName); - headers.putIfAbsent(HEADER_TRANS_ID, new ArrayList<String>()); - headers.get(HEADER_TRANS_ID).add(TRANSACTION_ID_PREFIX + NodeUtils.getRandomTxnId()); + headers.putIfAbsent(HEADER_TRANS_ID, new ArrayList<String>()); + headers.get(HEADER_TRANS_ID).add(TRANSACTION_ID_PREFIX + NodeUtils.getRandomTxnId()); - if (endpointConfig.getRestAuthenticationMode() == RestAuthenticationMode.SSL_BASIC) { + if (endpointConfig.getRestAuthenticationMode() == RestAuthenticationMode.SSL_BASIC) { - headers.putIfAbsent(HEADER_AUTHORIZATION, new ArrayList<String>()); - headers.get(HEADER_AUTHORIZATION).add(getBasicAuthenticationCredentials()); + headers.putIfAbsent(HEADER_AUTHORIZATION, new ArrayList<String>()); + headers.get(HEADER_AUTHORIZATION).add(getBasicAuthenticationCredentials()); - } + } - return headers; - } + return headers; + } - protected String getBasicAuthenticationCredentials() { - String usernameAndPassword = String.join(":", endpointConfig.getBasicAuthUserName(), - endpointConfig.getBasicAuthPassword()); - return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes()); - } + protected String getBasicAuthenticationCredentials() { + String usernameAndPassword = String.join(":", endpointConfig.getBasicAuthUserName(), + endpointConfig.getBasicAuthPassword()); + return "Basic " + java.util.Base64.getEncoder().encodeToString(usernameAndPassword.getBytes()); + } - /** - * Our retry conditions should be very specific. - * - * @param r - * the r - * @return true, if successful - */ - private boolean shouldRetryRequest(OperationResult r) { + /** + * Our retry conditions should be very specific. + * + * @param r the r + * @return true, if successful + */ + private boolean shouldRetryRequest(OperationResult r) { - if (r == null) { - return true; - } + if (r == null) { + return true; + } - int rc = r.getResultCode(); + int rc = r.getResultCode(); - if (rc == 200) { - return false; - } + if (rc == 200) { + return false; + } - if (rc == 404) { - return false; - } + if (rc == 404) { + return false; + } - return true; + return true; - } + } - /** - * Query active inventory. - * - * @param url - * the url - * @param acceptContentType - * the accept content type - * @return the operation result - */ - OperationResult queryGizmo(String url, String acceptContentType) { + /** + * Query active inventory. + * + * @param url the url + * @param acceptContentType the accept content type + * @return the operation result + */ + OperationResult queryGizmo(String url, String acceptContentType) { - return restClient.get(url, getMessageHeaders(), MediaType.APPLICATION_JSON_TYPE); + return restClient.get(url, getMessageHeaders(), MediaType.APPLICATION_JSON_TYPE); - } + } - public RestEndpointConfig getEndpointConfig() { - return endpointConfig; - } + public RestEndpointConfig getEndpointConfig() { + return endpointConfig; + } - public void setEndpointConfig(RestEndpointConfig endpointConfig) { - this.endpointConfig = endpointConfig; - } + public void setEndpointConfig(RestEndpointConfig endpointConfig) { + this.endpointConfig = endpointConfig; + } - public OperationResult queryGizmoWithRetries(String url, String responseType, int numRetries) { + public OperationResult queryGizmoWithRetries(String url, String responseType, int numRetries) { - OperationResult result = null; + OperationResult result = null; - for (int retryCount = 0; retryCount < numRetries; retryCount++) { + for (int retryCount = 0; retryCount < numRetries; retryCount++) { - LOG.debug(AaiUiMsgs.QUERY_AAI_RETRY_SEQ, url, String.valueOf(retryCount + 1)); + LOG.debug(AaiUiMsgs.QUERY_AAI_RETRY_SEQ, url, String.valueOf(retryCount + 1)); - result = queryGizmo(url, responseType); + result = queryGizmo(url, responseType); - /** - * Record number of times we have attempted the request to later - * summarize how many times we are generally retrying over thousands - * of messages in a sync. - * - * If the number of retries is surprisingly high, then we need to - * understand why that is as the number of retries is also causing a - * heavier load on AAI beyond the throttling controls we already - * have in place in term of the transaction rate controller and - * number of parallelized threads per task processor. - */ + /** + * Record number of times we have attempted the request to later summarize how many times we + * are generally retrying over thousands of messages in a sync. + * + * If the number of retries is surprisingly high, then we need to understand why that is as + * the number of retries is also causing a heavier load on AAI beyond the throttling controls + * we already have in place in term of the transaction rate controller and number of + * parallelized threads per task processor. + */ - result.setNumRetries(retryCount); + result.setNumRetries(retryCount); - if (!shouldRetryRequest(result)) { + if (!shouldRetryRequest(result)) { - result.setFromCache(false); - LOG.debug(AaiUiMsgs.QUERY_AAI_RETRY_DONE_SEQ, url, String.valueOf(retryCount + 1)); + result.setFromCache(false); + LOG.debug(AaiUiMsgs.QUERY_AAI_RETRY_DONE_SEQ, url, String.valueOf(retryCount + 1)); - return result; - } + return result; + } - try { - /* - * Sleep between re-tries to be nice to the target system. - */ - Thread.sleep(50); - } catch (InterruptedException exc) { - LOG.error(AaiUiMsgs.QUERY_AAI_WAIT_INTERRUPTION, exc.getLocalizedMessage()); - Thread.currentThread().interrupt(); - break; - } - LOG.error(AaiUiMsgs.QUERY_AAI_RETRY_FAILURE_WITH_SEQ, url, String.valueOf(retryCount + 1)); + try { + /* + * Sleep between re-tries to be nice to the target system. + */ + Thread.sleep(50); + } catch (InterruptedException exc) { + LOG.error(AaiUiMsgs.QUERY_AAI_WAIT_INTERRUPTION, exc.getLocalizedMessage()); + Thread.currentThread().interrupt(); + break; + } + LOG.error(AaiUiMsgs.QUERY_AAI_RETRY_FAILURE_WITH_SEQ, url, String.valueOf(retryCount + 1)); - } + } - LOG.info(AaiUiMsgs.QUERY_AAI_RETRY_MAXED_OUT, url); + LOG.info(AaiUiMsgs.QUERY_AAI_RETRY_MAXED_OUT, url); - return result; + return result; - } + } - /** - * This method adds a scheme, host and port (if missing) to the passed-in - * URI. If these parts of the URI are already present, they will not be - * duplicated. - * - * @param selflink - * The URI to repair - * @param queryParams - * The query parameters as a single string - * @return The corrected URI (i.e. includes a scheme/host/port) - */ + /** + * This method adds a scheme, host and port (if missing) to the passed-in URI. If these parts of + * the URI are already present, they will not be duplicated. + * + * @param selflink The URI to repair + * @param queryParams The query parameters as a single string + * @return The corrected URI (i.e. includes a scheme/host/port) + */ private String repairGizmoSelfLink(String baseUrlPath, String selfLink, String queryParams) { if (selfLink == null) { return selfLink; } - + if (selfLink.startsWith("http") || selfLink.startsWith("https")) { return selfLink; } - + UriBuilder builder = UriBuilder.fromPath(baseUrlPath + "/" + selfLink) .host(endpointConfig.getEndpointIpAddress()) .port(Integer.parseInt(endpointConfig.getEndpointServerPort())); @@ -300,7 +302,7 @@ public class GizmoAdapter { return (builder.build().toString() + (includeQueryParams ? queryParams : "")); } - + public String repairRelationshipSelfLink(String selflink, String queryParams) { return repairGizmoSelfLink(relationshipsBasePath, selflink, queryParams); } @@ -309,25 +311,27 @@ public class GizmoAdapter { return repairGizmoSelfLink(inventoryBasePath, selflink, queryParams); } - public OperationResult getSelfLinksByEntityType(String entityType) throws Exception { - - if (entityType == null) { - throw new NullPointerException("Failed to getSelfLinksByEntityType() because entityType is null"); - } - - String link = getFullInventoryUrl(entityType); - - return queryGizmoWithRetries(link, "application/json", endpointConfig.getNumRequestRetries()); - - } - - public static String extractResourcePath(String selflink) { - try { - return new URI(selflink).getRawPath(); - } catch (URISyntaxException uriSyntaxException) { - LOG.error(AaiUiMsgs.ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK, uriSyntaxException.getMessage()); - return selflink; - } - } + public OperationResult getSelfLinksByEntityType(String entityType) throws Exception { + + if (entityType == null) { + throw new NullPointerException( + "Failed to getSelfLinksByEntityType() because entityType is null"); + } + + String link = getFullInventoryUrl(entityType); + + return queryGizmoWithRetries(link, "application/json", endpointConfig.getNumRequestRetries()); + + } + + public static String extractResourcePath(String selflink) { + try { + return new URI(selflink).getRawPath(); + } catch (URISyntaxException uriSyntaxException) { + LOG.error(AaiUiMsgs.ERROR_EXTRACTING_RESOURCE_PATH_FROM_LINK, + uriSyntaxException.getMessage()); + return selflink; + } + } } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java index 9371a4a..23928a5 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/editattributes/AttributeUpdater.java @@ -133,16 +133,18 @@ public class AttributeUpdater { private UserValidator validator; private OxmModelLoader oxmModelLoader; private OxmEntityLookup oxmEntityLookup; + private String domain; /** * Instantiates a new attribute updater. * @throws AttributeUpdateException */ - public AttributeUpdater(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup, ActiveInventoryAdapter activeInventoryAdapter) throws AttributeUpdateException { + public AttributeUpdater(OxmModelLoader oxmModelLoader, OxmEntityLookup oxmEntityLookup, ActiveInventoryAdapter activeInventoryAdapter,String domain) throws AttributeUpdateException { super(); this.oxmModelLoader = oxmModelLoader; this.oxmEntityLookup = oxmEntityLookup; this.aaiAdapter = activeInventoryAdapter; + this.domain = domain; try { this.validator = new UserValidator(); @@ -159,7 +161,7 @@ public class AttributeUpdater { versionStr = String.valueOf(oxmModelLoader.getOxmApiVersion()); } - return "/aai/v" + versionStr; + return "/" + domain + "/v" + versionStr; } diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/personalization/PersonalizationServiceProvider.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/personalization/PersonalizationServiceProvider.java new file mode 100644 index 0000000..69298a9 --- /dev/null +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/personalization/PersonalizationServiceProvider.java @@ -0,0 +1,76 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sparky.personalization; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.camel.Exchange; +import org.json.JSONObject; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aai.restclient.client.OperationResult; +import org.onap.aai.sparky.logging.AaiUiMsgs; +import org.onap.aai.sparky.logging.util.ServletUtils; +import org.onap.aai.sparky.personalization.config.PersonalizationConfig; + +public class PersonalizationServiceProvider { + + private static final String EMPTY_RESPONSE = "{}"; + + private static final Logger LOG = + LoggerFactory.getInstance().getLogger(PersonalizationServiceProvider.class); + + PersonalizationConfig personalizationConfig; + + + public PersonalizationServiceProvider(PersonalizationConfig personalizationConfig) { + this.personalizationConfig = personalizationConfig; + } + + + public void getPersonalizedValues(Exchange exchange) { + + HttpServletRequest request = exchange.getIn().getBody(HttpServletRequest.class); + ServletUtils.setUpMdcContext(exchange, request); + + OperationResult personalizedValuesResult = new OperationResult(); + + try { + personalizedValuesResult.setResultCode(200); + JSONObject personalizedValuesResponse = new JSONObject(); + personalizedValuesResponse.put("topLeftHeader", personalizationConfig.getTopLeftHeader()); + personalizedValuesResponse.put("htmlDocumentTitle", + personalizationConfig.getHtmlDocumentTitle()); + personalizedValuesResult.setResult(personalizedValuesResponse.toString()); + + } catch (Exception exc) { + personalizedValuesResult.setResultCode(500); + personalizedValuesResult.setResult(EMPTY_RESPONSE); + LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, + "Exception thrown during personalization processing: " + exc.getLocalizedMessage()); + } + + exchange.getOut().setBody(personalizedValuesResult.getResult()); + + + } + +} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/personalization/config/PersonalizationConfig.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/personalization/config/PersonalizationConfig.java new file mode 100644 index 0000000..e92372c --- /dev/null +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/personalization/config/PersonalizationConfig.java @@ -0,0 +1,42 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.aai.sparky.personalization.config; + +public class PersonalizationConfig { + private String topLeftHeader = ""; + private String htmlDocumentTitle = ""; + + public String getHtmlDocumentTitle() { + return htmlDocumentTitle; + } + + public void setHtmlDocumentTitle(String htmlDocumentTitle) { + this.htmlDocumentTitle = htmlDocumentTitle; + } + + public String getTopLeftHeader() { + return topLeftHeader; + } + + public void setTopLeftHeader(String topLeftHeader) { + this.topLeftHeader = topLeftHeader; + } +} diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java index a22170a..a00aa75 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/search/SearchServiceAdapter.java @@ -54,6 +54,7 @@ public class SearchServiceAdapter { private RestClient client; private RestEndpointConfig endpointConfig; private String serviceApiVersion; + private String appPartnerName = ""; private Map<String, List<String>> commonHeaders; @@ -69,11 +70,19 @@ public class SearchServiceAdapter { commonHeaders = new HashMap<String, List<String>>(); commonHeaders.put("Accept", Arrays.asList("application/json")); - commonHeaders.put(Headers.FROM_APP_ID, Arrays.asList("AAI-UI")); + commonHeaders.put(Headers.FROM_APP_ID, Arrays.asList(appPartnerName)); this.serviceApiVersion = serviceApiVersion; this.endpointConfig = endpointConfig; } + + public String getAppPartnerName() { + return appPartnerName; + } + + public void setAppPartnerName(String appPartnerName) { + this.appPartnerName = appPartnerName; + } public String getServiceApiVersion() { return serviceApiVersion; diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java index 3a60cca..4d6041e 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/sync/task/PerformActiveInventoryRetrieval.java @@ -46,6 +46,7 @@ public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransact private NetworkTransaction txn; private ActiveInventoryAdapter aaiAdapter; private Map<String, String> contextMap; + private String uiRequestType; /** * Instantiates a new perform active inventory retrieval. @@ -54,10 +55,11 @@ public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransact * @param aaiProvider the aai provider */ public PerformActiveInventoryRetrieval(NetworkTransaction txn, - ActiveInventoryAdapter aaiAdapter) { + ActiveInventoryAdapter aaiAdapter,String uiRequestType) { this.txn = txn; this.aaiAdapter = aaiAdapter; this.contextMap = MDC.getCopyOfContextMap(); + this.uiRequestType = uiRequestType; } /* (non-Javadoc) @@ -74,7 +76,7 @@ public class PerformActiveInventoryRetrieval implements Supplier<NetworkTransact try { final String absoluteSelfLink = aaiAdapter.repairSelfLink(txn.getLink(), txn.getQueryParameters()); - result = aaiAdapter.queryActiveInventoryWithRetries(absoluteSelfLink, "application/json", 5); + result = aaiAdapter.queryActiveInventoryWithRetries(absoluteSelfLink, "application/json", 5,uiRequestType); } catch (Exception exc) { logger.error(AaiUiMsgs.ERROR_GENERIC,"Failure to resolve self link from AAI. Error = " + exc.getMessage()); result = new OperationResult(500, diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/NodeUtils.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/NodeUtils.java index b75fa91..8772afa 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/NodeUtils.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/util/NodeUtils.java @@ -70,7 +70,7 @@ import com.google.common.util.concurrent.ThreadFactoryBuilder; public class NodeUtils { private static SecureRandom sRandom = new SecureRandom(); - private static final Pattern AAI_VERSION_PREFIX = Pattern.compile("/aai/v[0-9]+/(.*)"); + private static final Pattern URL_VERSION_PREFIX = Pattern.compile("/v[0-9]+/(.*)"); private static final Pattern OXM_VERSION_PREFIX = Pattern.compile(".*_v([0-9]+).*"); private static final Pattern GIZMO_VERSION_PREFIX = Pattern.compile("[/]*services/inventory/v[0-9]+/(.*)"); private static final Pattern GIZMO_RELATIONSHIP_VERSION_PREFIX = Pattern.compile("services/inventory/relationships/v[0-9]+/(.*)"); @@ -125,7 +125,7 @@ public class NodeUtils { String rawPath = new URI(selfLinkUri).getRawPath(); - Matcher m = AAI_VERSION_PREFIX.matcher(rawPath); + Matcher m = URL_VERSION_PREFIX.matcher(rawPath); if (m.matches()) { diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java index 6dc8441..52714ff 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/SparkyConstants.java @@ -91,7 +91,7 @@ public class SparkyConstants { // Injected Attributes public static String URI_ATTR_NAME = "uri"; - public static final String URI_VERSION_REGEX_PATTERN = "aai/v[\\d]+/"; + public static final String URI_VERSION_REGEX_PATTERN = "/v[\\d]+/"; public static final String getConfigPath(String configFile){ return CONFIG_HOME + FILESEP + configFile; diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java index acca775..80328d3 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/config/VisualizationConfigs.java @@ -21,6 +21,7 @@ package org.onap.aai.sparky.viewandinspect.config; import java.util.ArrayList; +import java.util.Arrays; import org.onap.aai.sparky.config.SparkyResourceLoader; @@ -61,6 +62,22 @@ public class VisualizationConfigs { public void setShallowEntities(ArrayList<String> shallowEntities) { this.shallowEntities = shallowEntities; } + + public void setDelimitedShallowEntities(String delimitedShallowEntites) { + + if (delimitedShallowEntites == null) { + this.shallowEntities = new ArrayList<>(); + return; + } + + try { + this.shallowEntities = + new ArrayList<String>(Arrays.asList(delimitedShallowEntites.split(","))); + } catch (Exception exc) { + this.shallowEntities = new ArrayList<>(); + } + + } /** * Make all neighbors bidirectional. diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java index 4d83509..1a91a1b 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/entity/ActiveInventoryNode.java @@ -31,8 +31,6 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; @@ -54,7 +52,6 @@ public class ActiveInventoryNode { private static final Logger LOG = LoggerFactory.getInstance().getLogger( ActiveInventoryNode.class); - private static final String URIRegexPattern = "aai/v[\\d]/"; public static final int DEFAULT_INIT_NODE_DEPTH = 1000; @@ -570,22 +567,6 @@ public class ActiveInventoryNode { } /** - * Calculate edit attribute uri. - * - * @param link the link - * @return the string - */ - public String calculateEditAttributeUri(String link) { - String uri = null; - Pattern pattern = Pattern.compile(URIRegexPattern); - Matcher matcher = pattern.matcher(link); - if (matcher.find()) { - uri = link.substring(matcher.end()); - } - return uri; - } - - /** * Analyze self link relationship list. * * @param jsonResult the json result diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java index 797aa69..783bee4 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformNodeSelfLinkProcessingTask.java @@ -106,7 +106,7 @@ public class PerformNodeSelfLinkProcessingTask implements Supplier<NodeProcessin try { opResult = aaiAdapter.queryActiveInventoryWithRetries(link, "application/json", - aaiAdapter.getEndpointConfig().getNumRequestRetries()); + aaiAdapter.getEndpointConfig().getNumRequestRetries(),"req"); } catch (Exception exc) { opResult = new OperationResult(); opResult.setResult(500, "Querying AAI with retry failed due to an exception."); diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java index e16be76..75ae87d 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewandinspect/task/PerformSelfLinkDeterminationTask.java @@ -72,7 +72,7 @@ public class PerformSelfLinkDeterminationTask implements Supplier<SelfLinkDeterm OperationResult opResult = null; try { opResult = aaiAdapter.queryActiveInventoryWithRetries(txn.getQueryString(), "application/json", - aaiAdapter.getEndpointConfig().getNumRequestRetries()); + aaiAdapter.getEndpointConfig().getNumRequestRetries(),"req"); } catch (Exception exc) { opResult = new OperationResult(); opResult.setResult(500, "Querying AAI with retry failed due to an exception."); diff --git a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java index 79eded1..4877ad0 100644 --- a/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java +++ b/sparkybe-onap-service/src/main/java/org/onap/aai/sparky/viewinspect/sync/ViewInspectEntitySynchronizer.java @@ -333,7 +333,7 @@ public class ViewInspectEntitySynchronizer extends AbstractEntitySynchronizer aaiWorkOnHand.incrementAndGet(); - supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter), aaiExecutor) + supplyAsync(new PerformActiveInventoryRetrieval(txn, aaiAdapter,"sync"), aaiExecutor) .whenComplete((result, error) -> { aaiWorkOnHand.decrementAndGet(); |