diff options
author | richarv <richard.vondadelszen@amdocs.com> | 2018-01-18 15:57:11 -0500 |
---|---|---|
committer | richarv <richard.vondadelszen@amdocs.com> | 2018-01-18 15:58:03 -0500 |
commit | cca7620c8e1d779db9ed59a994530f6d6226f009 (patch) | |
tree | 1fd3635bfed8dae63e22f8face37a22ad970b31f /src | |
parent | a31c1cb7240b28f9ee5b0a4a847545ae3ea8039d (diff) |
Routes and beans for subscription
Issue-ID: AAI-677
Change-Id: I50cdd02a765c81421338162530c8d1060b6af053
Signed-off-by: richarv <richard.vondadelszen@amdocs.com>
Diffstat (limited to 'src')
7 files changed, 222 insertions, 169 deletions
diff --git a/src/main/java/org/onap/aai/sparky/subscription/SubscriptionServiceProcessor.java b/src/main/java/org/onap/aai/sparky/subscription/SubscriptionServiceProcessor.java new file mode 100644 index 0000000..e64c27a --- /dev/null +++ b/src/main/java/org/onap/aai/sparky/subscription/SubscriptionServiceProcessor.java @@ -0,0 +1,104 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 Amdocs + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ +package org.onap.aai.sparky.subscription; + +import org.apache.camel.Exchange; +import org.apache.camel.component.restlet.RestletConstants; +import org.onap.aai.cl.api.Logger; +import org.onap.aai.cl.eelf.LoggerFactory; +import org.onap.aai.cl.mdc.MdcContext; +import org.onap.aai.restclient.client.OperationResult; +import org.onap.aai.sparky.logging.AaiUiMsgs; +import org.onap.aai.sparky.subscription.services.SubscriptionService; +import org.onap.aai.sparky.util.NodeUtils; +import org.restlet.Request; +import org.restlet.Response; +import org.restlet.data.ClientInfo; +import org.restlet.data.MediaType; +import org.restlet.data.Status; + +public class SubscriptionServiceProcessor { + + private static final String EMPTY_RESPONSE = "{}"; + + private static final Logger LOG = + LoggerFactory.getInstance().getLogger(SubscriptionServiceProcessor.class); + + SubscriptionService subService; + + + public SubscriptionServiceProcessor(SubscriptionService subscriptionService) { + this.subService = subscriptionService; + } + + + public void getSubscription(Exchange exchange) { + + Object xTransactionId = exchange.getIn().getHeader("X-TransactionId"); + if (xTransactionId == null) { + xTransactionId = NodeUtils.getRandomTxnId(); + } + + Object partnerName = exchange.getIn().getHeader("X-FromAppId"); + if (partnerName == null) { + partnerName = "Browser"; + } + + Request request = exchange.getIn().getHeader(RestletConstants.RESTLET_REQUEST, Request.class); + + /* + * Disables automatic Apache Camel Restlet component logging which prints out an undesirable log + * entry which includes client (e.g. browser) information + */ + request.setLoggable(false); + + ClientInfo clientInfo = request.getClientInfo(); + MdcContext.initialize((String) xTransactionId, "AAI-UI", "", (String) partnerName, + clientInfo.getAddress() + ":" + clientInfo.getPort()); + + Response response = + exchange.getIn().getHeader(RestletConstants.RESTLET_RESPONSE, Response.class); + + OperationResult subscriptionResult = null; + Status responseStatus = null; + + try { + + subscriptionResult = subService.buildSubscriptionPayload(); + responseStatus = Status.SUCCESS_OK; + + } catch (Exception exc) { + responseStatus = Status.SERVER_ERROR_INTERNAL; + subscriptionResult = new OperationResult(); + subscriptionResult.setResult(EMPTY_RESPONSE); + LOG.error(AaiUiMsgs.FAILURE_TO_PROCESS_REQUEST, + "Exception thrown during subscription processing: " + exc.getLocalizedMessage()); + } + + + response.setStatus(responseStatus); + response.setEntity(subscriptionResult.getResult(), MediaType.APPLICATION_JSON); + exchange.getOut().setBody(response); + + } +} diff --git a/src/main/java/org/onap/aai/sparky/subscription/config/SubscriptionConfig.java b/src/main/java/org/onap/aai/sparky/subscription/config/SubscriptionConfig.java index 96228a5..f331667 100644 --- a/src/main/java/org/onap/aai/sparky/subscription/config/SubscriptionConfig.java +++ b/src/main/java/org/onap/aai/sparky/subscription/config/SubscriptionConfig.java @@ -22,12 +22,7 @@ */ package org.onap.aai.sparky.subscription.config; -import java.util.Arrays; import java.util.Collection; -import java.util.Properties; - -import org.onap.aai.sparky.util.ConfigHelper; -import org.onap.aai.sparky.viewandinspect.config.SparkyConstants; /** @@ -35,170 +30,108 @@ import org.onap.aai.sparky.viewandinspect.config.SparkyConstants; */ public class SubscriptionConfig { - public static final String CONFIG_FILE = - SparkyConstants.DYNAMIC_CONFIG_APP_LOCATION + "subscription.properties"; - - private static SubscriptionConfig instance; - - private String subscriptionTarget; - - private String subscriptionOrigin; - - private String subscriptionMessageType; - - private String subscriptionTopic; - - private String launchOITarget; - - private String launchOIOrigin; - - private String launchOIMessageType; - - private String launchOITopic; - - private Boolean isLaunchOIEnabled; - - private Collection<String> annEntitiyTypes; - - private static final String TARGET = ""; - - private static final String ORIGIN = ""; - - private static final String MESSAGE_TYPE = ""; - - private static final String TOPIC = ""; - + private static final String EMPTY_TARGET = ""; + private static final String EMPTY_ORIGIN = ""; + private static final String EMPTY_MESSAGE_TYPE = ""; + private static final String EMPTY_TOPIC = ""; + private String subscriptionTarget = EMPTY_TARGET; + private String subscriptionOrigin = EMPTY_ORIGIN; + private String subscriptionMessageType = EMPTY_MESSAGE_TYPE; + private String subscriptionTopic = EMPTY_TOPIC; - public static SubscriptionConfig getConfig(){ + private String launchOITarget = EMPTY_TARGET; + private String launchOIOrigin = EMPTY_ORIGIN; + private String launchOIMessageType = EMPTY_MESSAGE_TYPE; + private String launchOITopic = EMPTY_TOPIC; - if (instance == null) { - instance = new SubscriptionConfig(); - instance.initializeProperties(); - } - return instance; - } + private Boolean isLaunchOIEnabled = false; - public static void setConfig(SubscriptionConfig config) { - /* - * Explicitly allow setting the configuration singleton. This will be useful for automation. - */ - - SubscriptionConfig.instance = config; - } + private Collection<String> annEntitiyTypes; /** * Instantiates a new Subscription config. */ - public SubscriptionConfig() { - // test method - } - + public SubscriptionConfig() {} - /** - * Initialize properties. - */ - private void initializeProperties() { - Properties props = ConfigHelper.loadConfigFromExplicitPath(CONFIG_FILE); - - if (props == null || props.isEmpty()) { - //Disable subscription launch if the file is missing - this.setIsLaunchOIEnabled(false); - return; - } - subscriptionTarget = props.getProperty("subscription.target", TARGET); - subscriptionOrigin = props.getProperty("subscription.origin", ORIGIN); - subscriptionMessageType = props.getProperty("subscription.messageType", MESSAGE_TYPE); - subscriptionTopic = props.getProperty("subscription.topic", TOPIC); - - this.setLaunchOITarget(props.getProperty("launchOI.target", TARGET)); - this.setLaunchOIOrigin(props.getProperty("launchOI.origin", ORIGIN)); - this.setLaunchOIMessageType(props.getProperty("launchOI.messageType", MESSAGE_TYPE)); - this.setLaunchOITopic(props.getProperty("launchOI.topic", TOPIC)); - - this.setAnnEntitiyTypes(Arrays.asList(props.getProperty("launchOI.entityTypes", "").split(","))); - this.setIsLaunchOIEnabled(Boolean.parseBoolean(props.getProperty("launchOI.enable", "false"))); - } - - public String getSubscriptionTarget() { return subscriptionTarget; } public void setSubscriptionTarget(String target) { this.subscriptionTarget = target; - } - + } + public String getSubscriptionOrigin() { - return subscriptionOrigin; + return subscriptionOrigin; } public void setSubscriptionOrigin(String origin) { this.subscriptionOrigin = origin; - } - + } + public String getSubscriptionMessageType() { - return subscriptionMessageType; + return subscriptionMessageType; } public void setSubscriptionMessageType(String messageType) { - this.subscriptionMessageType = messageType; - } - + this.subscriptionMessageType = messageType; + } + public String getSubscriptionTopic() { - return subscriptionTopic; + return subscriptionTopic; } public void setSubscriptionTopic(String topic) { this.subscriptionTopic = topic; } -public String getLaunchOITarget() { - return launchOITarget; -} + public String getLaunchOITarget() { + return launchOITarget; + } -public void setLaunchOITarget(String launchOITarget) { - this.launchOITarget = launchOITarget; -} + public void setLaunchOITarget(String launchOITarget) { + this.launchOITarget = launchOITarget; + } -public String getLaunchOIOrigin() { - return launchOIOrigin; -} + public String getLaunchOIOrigin() { + return launchOIOrigin; + } -public void setLaunchOIOrigin(String launchOIOrigin) { - this.launchOIOrigin = launchOIOrigin; -} + public void setLaunchOIOrigin(String launchOIOrigin) { + this.launchOIOrigin = launchOIOrigin; + } -public String getLaunchOIMessageType() { - return launchOIMessageType; -} + public String getLaunchOIMessageType() { + return launchOIMessageType; + } -public void setLaunchOIMessageType(String launchOIMessageType) { - this.launchOIMessageType = launchOIMessageType; -} + public void setLaunchOIMessageType(String launchOIMessageType) { + this.launchOIMessageType = launchOIMessageType; + } -public String getLaunchOITopic() { - return launchOITopic; -} + public String getLaunchOITopic() { + return launchOITopic; + } -public void setLaunchOITopic(String launchOITopic) { - this.launchOITopic = launchOITopic; -} + public void setLaunchOITopic(String launchOITopic) { + this.launchOITopic = launchOITopic; + } -public Collection<String> getAnnEntitiyTypes() { - return annEntitiyTypes; -} + public Collection<String> getAnnEntitiyTypes() { + return annEntitiyTypes; + } -public void setAnnEntitiyTypes(Collection<String> annEntitiyTypes) { - this.annEntitiyTypes = annEntitiyTypes; -} + public void setAnnEntitiyTypes(Collection<String> annEntitiyTypes) { + this.annEntitiyTypes = annEntitiyTypes; + } -public Boolean getIsLaunchOIEnabled() { - return isLaunchOIEnabled; -} + public Boolean getIsLaunchOIEnabled() { + return isLaunchOIEnabled; + } -public void setIsLaunchOIEnabled(Boolean isLaunchOIEnabled) { - this.isLaunchOIEnabled = isLaunchOIEnabled; -} + public void setIsLaunchOIEnabled(Boolean isLaunchOIEnabled) { + this.isLaunchOIEnabled = isLaunchOIEnabled; + } } diff --git a/src/main/java/org/onap/aai/sparky/subscription/payload/entity/ObjectInspectorPayload.java b/src/main/java/org/onap/aai/sparky/subscription/payload/entity/ObjectInspectorPayload.java index b4f2502..7c98818 100644 --- a/src/main/java/org/onap/aai/sparky/subscription/payload/entity/ObjectInspectorPayload.java +++ b/src/main/java/org/onap/aai/sparky/subscription/payload/entity/ObjectInspectorPayload.java @@ -101,19 +101,18 @@ public class ObjectInspectorPayload { } private static ObjectInspectorPayload lic; - public static ObjectInspectorPayload getOIPayload() throws JsonParseException, JsonMappingException, IOException{ + public static ObjectInspectorPayload getOIPayload(SubscriptionConfig subscriptionConf) throws JsonParseException, JsonMappingException, IOException{ if(lic == null){ ObjectMapper mapper = new ObjectMapper(); lic = mapper.readValue(new File(SparkyConstants.SUBSCRIPTION_OI_MAPPING), ObjectInspectorPayload.class); - lic.intitializeOIPayload(); + lic.intitializeOIPayload(subscriptionConf); } return lic; } - private void intitializeOIPayload(){ + private void intitializeOIPayload(SubscriptionConfig subscriptionConf) { try { - SubscriptionConfig subscriptionConf = SubscriptionConfig.getConfig(); lic.setOrigin(subscriptionConf.getLaunchOIOrigin()); lic.setTarget(subscriptionConf.getLaunchOITarget()); lic.setTopic(subscriptionConf.getLaunchOITopic()); diff --git a/src/main/java/org/onap/aai/sparky/subscription/services/SubscriptionService.java b/src/main/java/org/onap/aai/sparky/subscription/services/SubscriptionService.java index f0b0733..0048ea3 100644 --- a/src/main/java/org/onap/aai/sparky/subscription/services/SubscriptionService.java +++ b/src/main/java/org/onap/aai/sparky/subscription/services/SubscriptionService.java @@ -27,31 +27,37 @@ import org.onap.aai.restclient.client.OperationResult; import org.onap.aai.sparky.subscription.config.SubscriptionConfig; -public class SubscriptionService { - +public class SubscriptionService { + + SubscriptionConfig config; + + public SubscriptionService(SubscriptionConfig subscriptionConfig) { + this.config = subscriptionConfig; + } + public OperationResult buildSubscriptionPayload() throws Exception { OperationResult returnValue = new OperationResult(); returnValue.setResultCode(200); - SubscriptionConfig subscriptionConf = getSubscriptionPayload(); - JSONObject subscriptionRequest = new JSONObject(); - + JSONObject subscriptionResponse = new JSONObject(); + JSONObject subscriptionDetails = new JSONObject(); + - if(subscriptionConf.getSubscriptionTarget().isEmpty() && subscriptionConf.getSubscriptionTopic().isEmpty() && - subscriptionConf.getSubscriptionMessageType().isEmpty() && subscriptionConf.getSubscriptionOrigin().isEmpty()) { - returnValue.setResult(500,"{}"); + if (config.getSubscriptionTarget().isEmpty() + && config.getSubscriptionTopic().isEmpty() + && config.getSubscriptionMessageType().isEmpty() + && config.getSubscriptionOrigin().isEmpty()) { + subscriptionResponse.put("subscriptionEnabled", false); } else { - subscriptionRequest.put("target", subscriptionConf.getSubscriptionTarget()); - subscriptionRequest.put("topic", subscriptionConf.getSubscriptionTopic()); - subscriptionRequest.put("messageType", subscriptionConf.getSubscriptionMessageType()); - subscriptionRequest.put("origin", subscriptionConf.getSubscriptionOrigin()); - returnValue.setResult(subscriptionRequest.toString()); - returnValue.setResultCode(200); - } - return returnValue; + subscriptionResponse.put("subscriptionEnabled", true); + subscriptionDetails.put("target", config.getSubscriptionTarget()); + subscriptionDetails.put("topic", config.getSubscriptionTopic()); + subscriptionDetails.put("messageType", config.getSubscriptionMessageType()); + subscriptionDetails.put("origin", config.getSubscriptionOrigin()); + } + subscriptionResponse.put("subscriptionDetails", subscriptionDetails); + returnValue.setResult(subscriptionResponse.toString()); - } - public SubscriptionConfig getSubscriptionPayload() throws Exception { - return SubscriptionConfig.getConfig(); - } + return returnValue; + } } diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphNode.java b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphNode.java index 1fb5272..07bb253 100644 --- a/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphNode.java +++ b/src/main/java/org/onap/aai/sparky/viewandinspect/entity/SparkyGraphNode.java @@ -87,14 +87,14 @@ public class SparkyGraphNode { private static final Logger LOG = LoggerFactory.getInstance().getLogger(SparkyGraphNode.class); private VisualizationConfigs visualizationConfigs; - + private SubscriptionConfig subConfig; /** - * Instantiates a new json node. + * Instantiates a new SparkyGraphNode. * * @param ain the ain */ - public SparkyGraphNode(ActiveInventoryNode ain, VisualizationConfigs visualizationConfigs) { + public SparkyGraphNode(ActiveInventoryNode ain, VisualizationConfigs visualizationConfigs, SubscriptionConfig subConfig) { this.resourceKey = ain.getNodeId(); this.itemProperties = ain.getProperties(); this.setItemType(ain.getEntityType()); @@ -103,6 +103,7 @@ public class SparkyGraphNode { this.setId(ain.getNodeId()); this.isRootNode = ain.isRootNode(); this.visualizationConfigs = visualizationConfigs; + this.setSubConfig(subConfig); if (LOG.isDebugEnabled()) { LOG.debug("---"); @@ -127,13 +128,13 @@ public class SparkyGraphNode { nodeMeta.setProcessingErrorOccurred(ain.isProcessingErrorOccurred()); nodeMeta.setHasNeighbors( ain.getOutboundNeighbors().size() > 0 || ain.getInboundNeighbors().size() > 0); - SubscriptionConfig subscriptionConf = SubscriptionConfig.getConfig(); - if (subscriptionConf.getIsLaunchOIEnabled()) { + + if (subConfig.getIsLaunchOIEnabled()) { try { - Collection<String> entityTypes = subscriptionConf.getAnnEntitiyTypes(); + Collection<String> entityTypes = subConfig.getAnnEntitiyTypes(); for (String entityType : entityTypes) { if (entityType.equals(this.getItemType())) { - ObjectInspectorPayload lic = ObjectInspectorPayload.getOIPayload(); + ObjectInspectorPayload lic = ObjectInspectorPayload.getOIPayload(subConfig); lic.getMessage().getPayload().getParams().setObjectName(this.getItemNameValue()); this.setExternalResourcePayload(lic); break; @@ -216,6 +217,14 @@ public class SparkyGraphNode { public void setExternalResourcePayload(ObjectInspectorPayload externalResourcePayload) { this.externalResourcePayload = externalResourcePayload; } + + public SubscriptionConfig getSubConfig() { + return subConfig; + } + + public void setSubConfig(SubscriptionConfig subConfig) { + this.subConfig = subConfig; + } /* * (non-Javadoc) @@ -234,6 +243,4 @@ public class SparkyGraphNode { + (inboundNeighbors != null ? "inboundNeighbors=" + inboundNeighbors + ", " : "") + (outboundNeighbors != null ? "outboundNeighbors=" + outboundNeighbors : "") + "]"; } - - } diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java b/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java index eb6f8f3..ed5ec8d 100644 --- a/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java +++ b/src/main/java/org/onap/aai/sparky/viewandinspect/services/BaseVisualizationService.java @@ -38,6 +38,7 @@ import org.onap.aai.sparky.config.oxm.OxmModelLoader; import org.onap.aai.sparky.dal.ActiveInventoryAdapter; import org.onap.aai.sparky.dal.ElasticSearchAdapter; import org.onap.aai.sparky.logging.AaiUiMsgs; +import org.onap.aai.sparky.subscription.config.SubscriptionConfig; import org.onap.aai.sparky.sync.config.ElasticSearchEndpointConfig; import org.onap.aai.sparky.sync.config.ElasticSearchSchemaConfig; import org.onap.aai.sparky.sync.entity.SearchableEntity; @@ -70,19 +71,21 @@ public class BaseVisualizationService implements VisualizationService { private final SecureRandom secureRandom; private VisualizationConfigs visualizationConfigs; + private SubscriptionConfig subConfig; private ElasticSearchEndpointConfig endpointEConfig; private ElasticSearchSchemaConfig schemaEConfig; private OxmEntityLookup oxmEntityLookup; - public BaseVisualizationService(OxmModelLoader loader,VisualizationConfigs visualizationConfigs, + public BaseVisualizationService(OxmModelLoader loader, VisualizationConfigs visualizationConfigs, ActiveInventoryAdapter aaiAdapter,ElasticSearchAdapter esAdapter, ElasticSearchEndpointConfig endpointConfig, ElasticSearchSchemaConfig schemaConfig, int numActiveInventoryWorkers, - OxmEntityLookup oxmEntityLookup) throws Exception { + OxmEntityLookup oxmEntityLookup, SubscriptionConfig subscriptionConfig) throws Exception { this.visualizationConfigs = visualizationConfigs; this.endpointEConfig = endpointConfig; this.schemaEConfig = schemaConfig; this.oxmEntityLookup = oxmEntityLookup; + this.subConfig = subscriptionConfig; secureRandom = new SecureRandom(); @@ -264,7 +267,7 @@ public class BaseVisualizationService implements VisualizationService { VisualizationTransformer transformer = null; try { - transformer = new VisualizationTransformer(visualizationConfigs); + transformer = new VisualizationTransformer(visualizationConfigs, subConfig); } catch (Exception exc) { throw new ServletException( "Failed to create VisualizationTransformer instance because of execption", exc); diff --git a/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java b/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java index ec76ac1..9a7879c 100644 --- a/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java +++ b/src/main/java/org/onap/aai/sparky/viewandinspect/services/VisualizationTransformer.java @@ -32,6 +32,7 @@ import java.util.UUID; import org.onap.aai.cl.api.Logger; import org.onap.aai.cl.eelf.LoggerFactory; import org.onap.aai.sparky.logging.AaiUiMsgs; +import org.onap.aai.sparky.subscription.config.SubscriptionConfig; import org.onap.aai.sparky.util.ConfigHelper; import org.onap.aai.sparky.viewandinspect.config.VisualizationConfigs; import org.onap.aai.sparky.viewandinspect.entity.ActiveInventoryNode; @@ -69,19 +70,19 @@ public class VisualizationTransformer { */ List<SparkyGraphLink> linkArrayOutput = new ArrayList<SparkyGraphLink>(); - - private VisualizationConfigs visualizationConfigs; - + private SubscriptionConfig subConfig; /** * Instantiates a new visualization transformer. * * @throws Exception the exception */ - public VisualizationTransformer(VisualizationConfigs visualizationConfigs )throws Exception{ + public VisualizationTransformer(VisualizationConfigs visualizationConfigs, + SubscriptionConfig subConfig) throws Exception { this.visualizationConfigs = visualizationConfigs; + this.subConfig = subConfig; } @@ -266,7 +267,7 @@ public class VisualizationTransformer { if (n.getNodeDepth() <= this.visualizationConfigs.getMaxSelfLinkTraversalDepth()) { - SparkyGraphNode jsonNode = new SparkyGraphNode(n,this.visualizationConfigs); + SparkyGraphNode jsonNode = new SparkyGraphNode(n, this.visualizationConfigs, this.subConfig); jsonNode.getNodeMeta().setClassName(this.visualizationConfigs.getGeneralNodeClassName()); |