2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.datarouter.policy;
25 import java.io.FileNotFoundException;
26 import java.io.IOException;
27 import java.util.List;
29 import org.apache.camel.Exchange;
30 import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext;
31 import org.onap.aai.datarouter.entity.SpikeAggregationEntity;
32 import org.onap.aai.datarouter.entity.SpikeEventVertex;
33 import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs;
35 import com.fasterxml.jackson.databind.JsonNode;
38 public class SpikeAggregateGenericVnfProcessor extends AbstractSpikeEntityEventProcessor {
40 public static final String additionalInfo = "Response of SpikeEntityEventPolicy";
42 /** Agent for communicating with the Search Service. */
44 public SpikeAggregateGenericVnfProcessor(SpikeEventPolicyConfig config)
45 throws FileNotFoundException {
50 protected void startup() {
51 // Create the indexes in the search service if they do not already exist.
52 searchAgent.createSearchIndex(searchIndexName, searchIndexSchema, createIndexUrl);
53 logger.info(EntityEventPolicyMsgs.ENTITY_EVENT_POLICY_REGISTERED);
57 public void process(Exchange exchange) throws Exception {
59 long startTime = System.currentTimeMillis();
60 String uebPayload = getExchangeBody(exchange);
61 if (uebPayload == null) {
64 JsonNode uebAsJson = null;
66 uebAsJson = mapper.readTree(uebPayload);
67 } catch (IOException e) {
68 returnWithError(exchange, uebPayload, "Invalid Payload");
72 String action = getSpikeEventAction(exchange, uebPayload);
76 SpikeEventVertex eventVertex = populateEventVertex(exchange, uebPayload);
77 if (eventVertex == null) {
80 String entityType = getEntityType(exchange, eventVertex, uebPayload);
81 if (entityType == null) {
84 String entityLink = getEntityLink(exchange, eventVertex, uebPayload);
85 if (entityLink == null) {
88 DynamicJAXBContext oxmJaxbContext = readOxm(exchange, uebPayload);
89 if (oxmJaxbContext == null) {
92 String oxmEntityType = getOxmEntityType(entityType);
93 List<String> searchableAttr = getSearchableAttibutes(oxmJaxbContext, oxmEntityType, entityType, uebPayload,
95 if (searchableAttr == null) {
100 // log the fact that all data are in good shape
101 logger.info(EntityEventPolicyMsgs.PROCESS_ENTITY_EVENT_POLICY_NONVERBOSE, action, entityType);
102 logger.debug(EntityEventPolicyMsgs.PROCESS_ENTITY_EVENT_POLICY_VERBOSE, action, entityType,
105 SpikeAggregationEntity spikeAgregationEntity = new SpikeAggregationEntity();
106 spikeAgregationEntity.setLink(entityLink);
107 spikeAgregationEntity.deriveFields(uebAsJson);
108 handleSearchServiceOperation(spikeAgregationEntity, action, searchIndexName);
110 long stopTime = System.currentTimeMillis();
111 metricsLogger.info(EntityEventPolicyMsgs.OPERATION_RESULT_NO_ERRORS, PROCESS_SPIKE_EVENT,
112 String.valueOf(stopTime - startTime));
113 setResponse(exchange, ResponseType.SUCCESS, additionalInfo);