router-core 1.3.0 changes
[aai/data-router.git] / src / main / java / org / onap / aai / datarouter / policy / SpikeAggregateGenericVnfProcessor.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
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=========================================================
20  */
21 package org.onap.aai.datarouter.policy;
22
23 import java.io.FileNotFoundException;
24 import java.util.List;
25
26 import org.apache.camel.Exchange;
27 import org.onap.aai.datarouter.entity.SpikeAggregationEntity;
28 import org.onap.aai.datarouter.entity.SpikeEventMeta;
29 import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs;
30
31 import com.fasterxml.jackson.databind.JsonNode;
32
33
34 public class SpikeAggregateGenericVnfProcessor extends AbstractSpikeEntityEventProcessor {
35
36   public static final String additionalInfo = "Response of SpikeEntityEventPolicy";
37
38   public SpikeAggregateGenericVnfProcessor(SpikeEventPolicyConfig config)
39       throws FileNotFoundException {
40     super(config);
41   }
42
43   @Override
44   protected void startup() {
45     // Create the indexes in the search service if they do not already exist.
46     searchAgent.createSearchIndex(searchIndexName, searchIndexSchema, createIndexUrl);
47     logger.info(EntityEventPolicyMsgs.ENTITY_EVENT_POLICY_REGISTERED);
48   }
49
50   @Override
51   public void process(Exchange exchange) throws Exception {
52
53     long startTime = System.currentTimeMillis();
54
55     SpikeEventMeta meta = processSpikeEvent(exchange);
56
57     if (meta == null) {
58       return;
59     }
60
61     String oxmEntityType = getOxmEntityType(meta.getSpikeEventVertex().getType());
62
63     List<String> searchableAttr = getSearchableAttibutes(meta.getOxmJaxbContext(), oxmEntityType,
64         meta.getSpikeEventVertex().getType(), meta.getEventEntity().toString(), exchange);
65
66     if (searchableAttr == null) {
67       return;
68     }
69
70     JsonNode propertiesNode =
71         mapper.readValue(meta.getVertexProperties().toString(), JsonNode.class);
72
73     SpikeAggregationEntity spikeAgregationEntity = new SpikeAggregationEntity();
74     spikeAgregationEntity.setLink(meta.getSpikeEventVertex().getEntityLink());
75     spikeAgregationEntity.deriveFields(propertiesNode);
76
77     handleSearchServiceOperation(spikeAgregationEntity, meta.getBodyOperationType(),
78         searchIndexName);
79
80     long stopTime = System.currentTimeMillis();
81     metricsLogger.info(EntityEventPolicyMsgs.OPERATION_RESULT_NO_ERRORS, PROCESS_SPIKE_EVENT,
82         String.valueOf(stopTime - startTime));
83     setResponse(exchange, ResponseType.SUCCESS, additionalInfo);
84     return;
85   }
86
87 }