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.util.ArrayList;
25 import java.util.List;
27 import org.apache.camel.Exchange;
28 import org.onap.aai.datarouter.entity.SpikeAggregationEntity;
29 import org.onap.aai.datarouter.entity.SpikeEventMeta;
30 import org.onap.aai.datarouter.logging.EntityEventPolicyMsgs;
31 import org.onap.aai.util.EntityOxmReferenceHelper;
32 import org.onap.aai.util.Version;
33 import org.onap.aai.util.VersionedOxmEntities;
35 import com.fasterxml.jackson.databind.JsonNode;
38 public class SpikeAggregateGenericVnfProcessor extends AbstractSpikeEntityEventProcessor {
40 public static final String additionalInfo = "Response of SpikeEntityEventPolicy";
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);
56 public void process(Exchange exchange) throws Exception {
58 long startTime = System.currentTimeMillis();
60 SpikeEventMeta meta = processSpikeEvent(exchange);
66 String oxmEntityType = getOxmEntityType(meta.getSpikeEventVertex().getType());
68 VersionedOxmEntities oxmEntities =
69 EntityOxmReferenceHelper.getInstance().getVersionedOxmEntities(Version.valueOf(oxmVersion.toLowerCase()));
71 List<String> suggestibleAttrInPayload = new ArrayList<>();
72 List<String> suggestibleAttrInOxm = extractSuggestableAttr(oxmEntities, meta.getSpikeEventVertex().getType());
73 if (suggestibleAttrInOxm != null) {
74 for (String attr: suggestibleAttrInOxm){
75 if (meta.getVertexProperties().has(attr)) {
76 suggestibleAttrInPayload.add(attr);
81 if (suggestibleAttrInPayload.isEmpty()) {
85 JsonNode propertiesNode =
86 mapper.readValue(meta.getVertexProperties().toString(), JsonNode.class);
88 SpikeAggregationEntity spikeAgregationEntity = new SpikeAggregationEntity();
89 spikeAgregationEntity.setLink(meta.getSpikeEventVertex().getEntityLink());
90 spikeAgregationEntity.deriveFields(propertiesNode);
92 handleSearchServiceOperation(spikeAgregationEntity, meta.getBodyOperationType(),
95 long stopTime = System.currentTimeMillis();
96 metricsLogger.info(EntityEventPolicyMsgs.OPERATION_RESULT_NO_ERRORS, PROCESS_SPIKE_EVENT,
97 String.valueOf(stopTime - startTime));
98 setResponse(exchange, ResponseType.SUCCESS, additionalInfo);