2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.datarouter.policy;
23 import java.io.FileNotFoundException;
24 import java.io.IOException;
25 import java.util.List;
27 import org.apache.camel.Exchange;
28 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
29 import org.onap.aai.datarouter.entity.SpikeAggregationEntity;
30 import org.onap.aai.datarouter.entity.SpikeEventVertex;
31 import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs;
33 import com.fasterxml.jackson.databind.JsonNode;
36 public class SpikeAggregateGenericVnfProcessor extends AbstractSpikeEntityEventProcessor {
38 public static final String additionalInfo = "Response of SpikeEntityEventPolicy";
40 /** Agent for communicating with the Search Service. */
42 public SpikeAggregateGenericVnfProcessor(SpikeEventPolicyConfig config)
43 throws FileNotFoundException {
48 protected void startup() {
49 // Create the indexes in the search service if they do not already exist.
50 searchAgent.createSearchIndex(searchIndexName, searchIndexSchema, createIndexUrl);
51 logger.info(EntityEventPolicyMsgs.ENTITY_EVENT_POLICY_REGISTERED);
55 public void process(Exchange exchange) throws Exception {
57 long startTime = System.currentTimeMillis();
58 String uebPayload = getExchangeBody(exchange);
59 if (uebPayload == null) {
62 JsonNode uebAsJson = null;
64 uebAsJson = mapper.readTree(uebPayload);
65 } catch (IOException e) {
66 returnWithError(exchange, uebPayload, "Invalid Payload");
70 String action = getSpikeEventAction(exchange, uebPayload);
74 SpikeEventVertex eventVertex = populateEventVertex(exchange, uebPayload);
75 if (eventVertex == null) {
78 String entityType = getEntityType(exchange, eventVertex, uebPayload);
79 if (entityType == null) {
82 String entityLink = getEntityLink(exchange, eventVertex, uebPayload);
83 if (entityLink == null) {
86 DynamicJAXBContext oxmJaxbContext = readOxm(exchange, uebPayload);
87 if (oxmJaxbContext == null) {
90 String oxmEntityType = getOxmEntityType(entityType);
91 List<String> searchableAttr = getSearchableAttibutes(oxmJaxbContext, oxmEntityType, entityType, uebPayload,
93 if (searchableAttr == null) {
98 // log the fact that all data are in good shape
99 logger.info(EntityEventPolicyMsgs.PROCESS_ENTITY_EVENT_POLICY_NONVERBOSE, action, entityType);
100 logger.debug(EntityEventPolicyMsgs.PROCESS_ENTITY_EVENT_POLICY_VERBOSE, action, entityType,
103 SpikeAggregationEntity spikeAgregationEntity = new SpikeAggregationEntity();
104 spikeAgregationEntity.setLink(entityLink);
105 spikeAgregationEntity.deriveFields(uebAsJson);
106 handleSearchServiceOperation(spikeAgregationEntity, action, searchIndexName);
108 long stopTime = System.currentTimeMillis();
109 metricsLogger.info(EntityEventPolicyMsgs.OPERATION_RESULT_NO_ERRORS, PROCESS_SPIKE_EVENT,
110 String.valueOf(stopTime - startTime));
111 setResponse(exchange, ResponseType.SUCCESS, additionalInfo);