diff options
Diffstat (limited to 'UniversalVesAdapter/src/main/java')
36 files changed, 2521 insertions, 0 deletions
diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/GenericAdapter.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/GenericAdapter.java new file mode 100644 index 0000000..fa3b89c --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/GenericAdapter.java @@ -0,0 +1,51 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.adapter; + +import org.onap.universalvesadapter.exception.ConfigFileReadException; +import org.onap.universalvesadapter.exception.ConfigFileSmooksConversionException; +import org.onap.universalvesadapter.exception.VesException; + +/** + * This interface defines contract for adapter to convert an incoming json + * to VES format + * + * @author kmalbari + * + */ +public interface GenericAdapter { + +// String transform(String incomingJsonString) throws ConfigFileReadException; + + /** + * It will take in an incoming json and identify the json type for different + * events. Based on the event type it will retrieve the corresponding config + * file and convert the json to VES format using mappings in the config file. + * + * @param incomingJsonString json that is received on DMaap topic + * @param eventType type identified from incoming json + * @return VES format json + * @throws ConfigFileReadException if unable to read the configuration file + * @throws ConfigFileSmooksConversionException if unable to convert config file data to smooks object + * @throws VesException if unable to convert into ves json + */ + String transform(String incomingJsonString, String eventType) throws ConfigFileReadException, ConfigFileSmooksConversionException, VesException; + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java new file mode 100644 index 0000000..318c8cd --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/adapter/UniversalEventAdapter.java @@ -0,0 +1,136 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.adapter; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +import javax.annotation.PreDestroy; +import javax.annotation.Resource; + +import org.milyn.Smooks; +import org.onap.dcaegen2.ves.domain.VesEvent; +import org.onap.universalvesadapter.configs.UniversalEventConfiguration; +import org.onap.universalvesadapter.exception.ConfigFileReadException; +import org.onap.universalvesadapter.exception.ConfigFileSmooksConversionException; +import org.onap.universalvesadapter.exception.VesException; +import org.onap.universalvesadapter.service.ConfigFileService; +import org.onap.universalvesadapter.utils.SmooksUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; +import org.xml.sax.SAXException; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/** + * Default implementation of the Generic Adapter + * + * @author kmalbari + * + */ +@Component +public class UniversalEventAdapter implements GenericAdapter{ + + private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private UniversalEventConfiguration configuration; + + @Resource(name="diskRepoConfigFileService") + private ConfigFileService configFileService; + +// private Smooks smooks; + + private Map<String, Smooks> eventToSmooksMapping = new ConcurrentHashMap<>(); + + /*public String transform(String incomingJsonString) throws ConfigFileReadException { + String result = ""; + try { + //reading config file.. for now, looking at it as just one time operation + if(null == smooks){ + String configFileData = configFileService.readConfigFile(configuration.getConfigFile()); + smooks = new Smooks(new ByteArrayInputStream(configFileData.getBytes(StandardCharsets.UTF_8))); + } + + VesEvent vesEvent = SmooksUtils.getTransformedObjectForInput(smooks, incomingJsonString); + ObjectMapper objectMapper = new ObjectMapper(); + result = objectMapper.writeValueAsString(vesEvent); + } catch (IOException | SAXException e) { + e.printStackTrace(); + } + + return result; + }*/ + + + + @Override + public String transform(String incomingJsonString, String eventType) throws ConfigFileReadException, + ConfigFileSmooksConversionException, VesException { + String result = ""; + try { + if(null == eventToSmooksMapping.get(eventType)){ + LOGGER.debug("No smooks mapping for this event type " + eventType + ".. reading config file"); + String configFileData = configFileService.readConfigFile(configuration.getConfigForEvent(eventType)); + LOGGER.debug("Read config file " + configFileData); + Smooks smooksTemp = new Smooks(new ByteArrayInputStream(configFileData.getBytes(StandardCharsets.UTF_8))); + eventToSmooksMapping.put(eventType, smooksTemp); + LOGGER.debug("Added smooks mapping for event type" + eventType); + } + + + LOGGER.debug("Read smooks mapping for event type" + eventType); + LOGGER.debug("Transforming incoming json now"); + VesEvent vesEvent = SmooksUtils.getTransformedObjectForInput(eventToSmooksMapping.get(eventType), incomingJsonString); + LOGGER.debug("Incoming json transformed to VES format successfully"); + ObjectMapper objectMapper = new ObjectMapper(); + result = objectMapper.writeValueAsString(vesEvent); + LOGGER.debug("Serialized VES json"); + } catch (JsonProcessingException exception) { + throw new VesException("Unable to convert pojo to VES format" + "\n Reason :" + exception.getMessage()); + } catch (SAXException | IOException exception) { + throw new ConfigFileSmooksConversionException("Unable to convert config file into smooks for event type " + eventType + + "\n Reason :" + exception.getMessage()); + } + return result; + } + + + /** + * Closes all open smooks' instances before bean is destroyed + */ + @PreDestroy + public void destroy(){ +// if(null != smooks) +// smooks.close(); + + for(Smooks smooks : eventToSmooksMapping.values()) + smooks.close(); + + LOGGER.debug("All Smooks objects closed"); + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/Configuration.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/Configuration.java new file mode 100644 index 0000000..e47af70 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/Configuration.java @@ -0,0 +1,24 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.configs; + +public abstract class Configuration { + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DMaapMrUrlConfiguration.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DMaapMrUrlConfiguration.java new file mode 100644 index 0000000..2b9a820 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DMaapMrUrlConfiguration.java @@ -0,0 +1,56 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.configs; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * Configuration for Dmaap MR Service + * + * @author kmalbari + * + */ +@Component +public class DMaapMrUrlConfiguration extends Configuration { + + @Value("${dmaap.url}") + private String url; + + @Value("${dmaap.consumer_props}") + private String consumerProperties; + + @Value("${dmaap.publisher_props}") + private String publisherProperties; + + public String getPublisherProperties() { + return publisherProperties; + } + + public String getConsumerProperties() { + return consumerProperties; + } + + public String getUrl() { + return url; + } + + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DiskRepoConfiguration.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DiskRepoConfiguration.java new file mode 100644 index 0000000..b1daf0d --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/DiskRepoConfiguration.java @@ -0,0 +1,42 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.configs; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * + * Configuration for disk repository service + * + * @author kmalbari + * + */ +@Component +public class DiskRepoConfiguration extends Configuration { + + @Value("${fileService.url}") + private String fileRepositoryUrl; + + public String getFileRepositoryUrl() { + return fileRepositoryUrl; + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/UniversalEventConfiguration.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/UniversalEventConfiguration.java new file mode 100644 index 0000000..3edca56 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/configs/UniversalEventConfiguration.java @@ -0,0 +1,73 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.configs; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * Configuration for universal adapter service + * + * @author kmalbari + * + */ +@Component +public class UniversalEventConfiguration extends Configuration { + + private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + + @Value("${snmpTrap.configFile}") + private String configFile; + + @Value("${universal.configFiles}") + private String configFiles; + + private Map<String, String> eventToConfigFileMap = new ConcurrentHashMap<>(); + + + /** + * Returns config file for a particular event from the mapping. + * If mapping is empty, populates its + * + * @param eventType + * + * @return config file name + */ + public String getConfigForEvent(String eventType){ + LOGGER.debug("Getting config file name for event:" + eventType); + if(null != configFiles && eventToConfigFileMap.isEmpty()){ + for(String entry : configFiles.split(",")){ + eventToConfigFileMap.put(entry.split(":")[0], entry.split(":")[1]); + } + LOGGER.debug("Populated mappings for event type to config files"); + } + + return (null == eventToConfigFileMap.get(eventType)) ? "default" : eventToConfigFileMap.get(eventType) ; + + } + + + //think about adding mapping files on runtime as well + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/MockDmaapController.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/MockDmaapController.java new file mode 100644 index 0000000..e844270 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/MockDmaapController.java @@ -0,0 +1,37 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.controller; + +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + + +@RestController +public class MockDmaapController { + + @RequestMapping("/greeting") + public String greeting(@RequestParam(value="name", defaultValue="World") String name) { +// return new Greeting(counter.incrementAndGet(), +// String.format(template, name)); + return "{ \"protocol version\": \"v2c\", \"notify OID\": \".1.3.6.1.4.1.74.2.46.12.1.1\", \"cambria.partition\": \"dcae-snmp.client.research.att.com\" , \"trap category\": \"UCSNMP-HEARTBEAT\", \"epoch_serno\": 15161177410000, \"community\" : \"public\", \"time received\": 1516117741, \"agent name\": \"localhost\", \"agent address\": \"127.0.0.1\", \"community len\": 6, \"notify OID len\": 12, \"varbinds\": [ { \"varbind_type\": \"octet\", \"varbind_oid\": \".1.3.6.1.4.1.74.2.46.12.1.1.1\", \"varbind_value\": \"ucsnmp heartbeat - ignore\" }, { \"varbind_type\": \"octet\", \"varbind_oid\": \".1.3.6.1.4.1.74.2.46.12.1.1.2\", \"varbind_value\": \"Tue Jan 16 10:49:01 EST 2018\" } ] }"; + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/VesController.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/VesController.java new file mode 100644 index 0000000..588c912 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/controller/VesController.java @@ -0,0 +1,64 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.controller; + +import org.onap.universalvesadapter.service.VesService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +/** + * This controller will be starting point for this micro service. On triggering, it will listen to Dmaap topic for events. + * + * @author kmalbari + */ +@RestController +public class VesController { + + private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private VesService vesService; + + /** + * @return message that application is started + */ + @RequestMapping("/start") + public String start() { + + LOGGER.debug("UniversalVesAdapter Application starting..."); + vesService.start(); + return "Application started"; + } + + /** + * @return message that application stop process is triggered + */ + @RequestMapping("/stop") + public String stop() { + + vesService.stop(); + LOGGER.debug("UniversalVesAdapter Application is stopping..."); + return "Application will be stopped soon"; + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/ConfigFileData.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/ConfigFileData.java new file mode 100644 index 0000000..796fe70 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/ConfigFileData.java @@ -0,0 +1,57 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +import org.springframework.data.annotation.Id; + +/** + * A domain wrapper class for saving the config file in Mongo DB + * + * @author kmalbari + * + */ +public class ConfigFileData { + + + @Id private String id; + + private String xmlFileName; + + private String xmlContent; + + public String getXmlFileName() { + return xmlFileName; + } + + public void setXmlFileName(String xmlFileName) { + this.xmlFileName = xmlFileName; + } + + public String getXmlContent() { + return xmlContent; + } + + public void setXmlContent(String xmlContent) { + this.xmlContent = xmlContent; + } + + + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Domains.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Domains.java new file mode 100644 index 0000000..55812c4 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Domains.java @@ -0,0 +1,55 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum Domains { + + DOMAIN_FAULT("fault"), + /** A Fault event. */ + DOMAIN_HEARTBEAT("heartbeat"), + /** A Heartbeat event (event header only). */ + DOMAIN_MEASUREMENT_FOR_VFSCALLING("measurementsForVfScaling"), + /** A Measurement for VF Scaling event. */ + DOMAIN_MOBILE_FLOW("mobileFlow"), + /** A Mobile Flow event. */ + DOMAIN_OTHER("other"), + /** Another event. */ + DOMAIN_SIPSIGNALING("sipSignaling"), + /** A Signaling event. */ + DOMAIN_STATE_CHANGE("stateChange"), + /** A State Change event. */ + DOMAIN_SYSLOG("syslog"), + /** A Syslog event. */ + DOMAIN_THRESHOLD_CROSSING_ALERT("thresholdCrossingAlert"), + /** A Threshold crossing alert Event */ + DOMAIN_VOICE_QUALITY("voiceQuality"); + /** A Voice Quality Event */ + + private final String value; + + private Domains(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Priorities.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Priorities.java new file mode 100644 index 0000000..6b3ddfd --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Priorities.java @@ -0,0 +1,35 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum Priorities { + HIGH("High"), MEDIUM("Medium"), NORMAL("Normal"), LOW("Low"); + + private final String value; + + private Priorities(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Severity.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Severity.java new file mode 100644 index 0000000..1e200f5 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/Severity.java @@ -0,0 +1,36 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum Severity { + SEVERITY_CRITICAL("CRITICAL"), + SEVERITY_MAJOR("MAJOR"), + SEVERITY_MINOR("MINOR"), + SEVERITY_WARNING("WARNING"), + SEVERITY_NORMAL("NORMAL"); + + private final String value; + + private Severity(final String value) { + this.value = value; + } + + public String getValue() { return value; } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/State.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/State.java new file mode 100644 index 0000000..b6b8851 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/State.java @@ -0,0 +1,33 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum State { + STATE_IN_SERVICE("inService"), STATE_MAINTENANCE("maintenance"), STATE_OUT_OF_SERVICE("outOfService"); + private final String value; + + private State(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/SysLogSeverity.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/SysLogSeverity.java new file mode 100644 index 0000000..5cee6ad --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/SysLogSeverity.java @@ -0,0 +1,50 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum SysLogSeverity { + + SEVERITY_EMERGENCY("Emergency"), + /** system is unusable */ + SEVERITY_ALERT("Alert"), + /** action must be taken immediately */ + SEVERITY_CRITICAL("Critical"), + /** critical conditions */ + SEVERITY_ERROR("Error"), + /** error conditions */ + SEVERITY_WARNING("Warning"), + /** warning conditions */ + SEVERITY_NOTICE("Notice"), + /** normal but significant condition */ + SEVERITY_INFO("Info"), + /** Informational: informational messages */ + SEVERITY_DEBUG("Debug"); + /** debug-level messages */ + + private final String value; + + private SysLogSeverity(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaAlertAction.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaAlertAction.java new file mode 100644 index 0000000..928698f --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaAlertAction.java @@ -0,0 +1,33 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum TcaAlertAction { + SET("SET"), CONTINUE("CONT"), CLEAR("CLEAR"); + private final String value; + + private TcaAlertAction(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaAlertType.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaAlertType.java new file mode 100644 index 0000000..5130378 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaAlertType.java @@ -0,0 +1,34 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum TcaAlertType { + CARD_ANOMALY("CARD-ANOMALY"), INTERFACE_ANOMALY("INTERFACE_ANOMALY"), ELEMENT_ANOMALY( + "ELEMENT-ANOMALY"), SERVICE_ANOMALY("SERVICE-ANOMALY"); + private final String value; + + private TcaAlertType(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaCounterCriticality.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaCounterCriticality.java new file mode 100644 index 0000000..9f8e126 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaCounterCriticality.java @@ -0,0 +1,33 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum TcaCounterCriticality { + CRITICAL("CRIT"), MAJOR("MAJ"); + private final String value; + + private TcaCounterCriticality(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaEventSeverity.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaEventSeverity.java new file mode 100644 index 0000000..6e73fa2 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/TcaEventSeverity.java @@ -0,0 +1,36 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum TcaEventSeverity { + SEVERITY_CRITICAL("CRITICAL"), SEVERITY_MAJOR("MAJOR"), SEVERITY_MINOR("MINOR"), SEVERITY_WARNING( + "WARNING"), SEVERITY_NORMAL("NORMAL"); + + private final String value; + + private TcaEventSeverity(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/VnfStatus.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/VnfStatus.java new file mode 100644 index 0000000..828c71e --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/domain/VnfStatus.java @@ -0,0 +1,37 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.domain; + +public enum VnfStatus { + + VFSTATUS_ACTIVE("Active"), + VFSTATUS_IDLE("Idle"), + VFSTATUS_PREP_TERMINATE("Preparing to terminate"), + VFSTATUS_READY_TERMINATE("Ready to terminate"), + VFSTATUS_REQ_TERMINATE("Requesting Termination"); + + private final String value; + + private VnfStatus(final String value) { + this.value = value; + } + + public String getValue() { return value; } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/ConfigFileReadException.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/ConfigFileReadException.java new file mode 100644 index 0000000..3a64247 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/ConfigFileReadException.java @@ -0,0 +1,38 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.exception; + +/** + * Exception when unable to connect to Config file Disk repository + * + * @author kmalbari + * + */ +public class ConfigFileReadException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 414953072485703000L; + + public ConfigFileReadException(String exceptionMessage) { + super(exceptionMessage); + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/ConfigFileSmooksConversionException.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/ConfigFileSmooksConversionException.java new file mode 100644 index 0000000..1daa939 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/ConfigFileSmooksConversionException.java @@ -0,0 +1,40 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.exception; + +/** + * + * Exception thrown when config file data is unable to be parsed correctly in Smooks configuration + * + * @author kmalbari + * + */ +public class ConfigFileSmooksConversionException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 7128340575013771888L; + + public ConfigFileSmooksConversionException(String string) { + super(string); + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/DMaapException.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/DMaapException.java new file mode 100644 index 0000000..5af0205 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/DMaapException.java @@ -0,0 +1,41 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.exception; + +/** + * Exception generated when dealing with communication to DMaap MR API + * + * @author kmalbari + * + */ +public class DMaapException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 7045766597511192878L; + + public DMaapException(String string) { + super(string); + } + + + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/MapperConfigException.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/MapperConfigException.java new file mode 100644 index 0000000..a8414d8 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/MapperConfigException.java @@ -0,0 +1,45 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.exception; + +import java.io.IOException; + +/** + * Exception thrown during mapping config operations + * + * @author kmalbari + * + */ +public class MapperConfigException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -7876042513908918292L; + + public MapperConfigException(String string) { + // TODO Auto-generated constructor stub + } + + public MapperConfigException(String string, IOException exception) { + // TODO Auto-generated constructor stub + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/VesException.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/VesException.java new file mode 100644 index 0000000..31134c8 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/exception/VesException.java @@ -0,0 +1,40 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.exception; + +/** + * + * Exception thrown when VES Event was not generated correctly + * + * @author kmalbari + * + */ +public class VesException extends Exception { + + + /** + * + */ + private static final long serialVersionUID = -8549819066568432382L; + + public VesException(String string) { + super(string); + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/Entry.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/Entry.java new file mode 100644 index 0000000..54a77a0 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/Entry.java @@ -0,0 +1,114 @@ + +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.mappingconfig; + +import java.util.HashMap; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "priority", + "evaluation", + "result" +}) +public class Entry { + + @JsonProperty("priority") + private Integer priority; + @JsonProperty("evaluation") + private Evaluation evaluation; + @JsonProperty("result") + private String result; + @JsonIgnore + private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + + @JsonProperty("priority") + public Integer getPriority() { + return priority; + } + + @JsonProperty("priority") + public void setPriority(Integer priority) { + this.priority = priority; + } + + @JsonProperty("evaluation") + public Evaluation getEvaluation() { + return evaluation; + } + + @JsonProperty("evaluation") + public void setEvaluation(Evaluation evaluation) { + this.evaluation = evaluation; + } + + @JsonProperty("result") + public String getResult() { + return result; + } + + @JsonProperty("result") + public void setResult(String result) { + this.result = result; + } + + @JsonAnyGetter + public Map<String, Object> getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("priority", priority).append("evaluation", evaluation).append("result", result).append("additionalProperties", additionalProperties).toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(result).append(additionalProperties).append(priority).append(evaluation).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof Entry) == false) { + return false; + } + Entry rhs = ((Entry) other); + return new EqualsBuilder().append(result, rhs.result).append(additionalProperties, rhs.additionalProperties).append(priority, rhs.priority).append(evaluation, rhs.evaluation).isEquals(); + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/Evaluation.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/Evaluation.java new file mode 100644 index 0000000..e34b98a --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/Evaluation.java @@ -0,0 +1,208 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.mappingconfig; + +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.lang.builder.ToStringBuilder; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "operand", + "field", + "value", + "datatype", + "lhs", + "rhs" +}) +public class Evaluation { + + + @JsonProperty("operand") + private String operand; + @JsonProperty("field") + private String field; + @JsonProperty("value") + private String value; + @JsonProperty("datatype") + private String datatype; + @JsonProperty("lhs") + private Evaluation lhs; + @JsonProperty("rhs") + private Evaluation rhs; + @JsonIgnore + private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + + @JsonProperty("operand") + public String getOperand() { + return operand; + } + + @JsonProperty("operand") + public void setOperand(String operand) { + this.operand = operand; + } + + @JsonProperty("field") + public String getField() { + return field; + } + + @JsonProperty("field") + public void setField(String field) { + this.field = field; + } + + @JsonProperty("value") + public String getValue() { + return value; + } + + @JsonProperty("value") + public void setValue(String value) { + this.value = value; + } + + @JsonProperty("datatype") + public String getDatatype() { + return datatype; + } + + @JsonProperty("datatype") + public void setDatatype(String datatype) { + this.datatype = datatype; + } + + @JsonProperty("lhs") + public Evaluation getLhs() { + return lhs; + } + + @JsonProperty("lhs") + public void setLhs(Evaluation lhs) { + this.lhs = lhs; + } + + @JsonProperty("rhs") + public Evaluation getRhs() { + return rhs; + } + + @JsonProperty("rhs") + public void setRhs(Evaluation rhs) { + this.rhs = rhs; + } + + @JsonAnyGetter + public Map<String, Object> getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("operand", operand).append("field", field).append("value", value).append("datatype", datatype).append("lhs", lhs).append("rhs", rhs).append("additionalProperties", additionalProperties).toString(); + } + /* + @Override + public int hashCode() { + return new HashCodeBuilder().append(field).append(additionalProperties).append(value).append(rhs).append(datatype).append(operand).append(lhs).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof Evaluation) == false) { + return false; + } + Evaluation rhs = ((Evaluation) other); + return new EqualsBuilder().append(field, rhs.field).append(additionalProperties, rhs.additionalProperties).append(value, rhs.value).append(rhs, rhs.rhs).append(datatype, rhs.datatype).append(operand, rhs.operand).append(lhs, rhs.lhs).isEquals(); + } +*/ + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((datatype == null) ? 0 : datatype.hashCode()); + result = prime * result + ((field == null) ? 0 : field.hashCode()); + result = prime * result + ((lhs == null) ? 0 : lhs.hashCode()); + result = prime * result + ((operand == null) ? 0 : operand.hashCode()); + result = prime * result + ((rhs == null) ? 0 : rhs.hashCode()); + result = prime * result + ((value == null) ? 0 : value.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Evaluation other = (Evaluation) obj; + if (datatype == null) { + if (other.datatype != null) + return false; + } else if (!datatype.equals(other.datatype)) + return false; + if (field == null) { + if (other.field != null) + return false; + } else if (!field.equals(other.field)) + return false; + if (lhs == null) { + if (other.lhs != null) + return false; + } else if (!lhs.equals(other.lhs)) + return false; + if (operand == null) { + if (other.operand != null) + return false; + } else if (!operand.equals(other.operand)) + return false; + if (rhs == null) { + if (other.rhs != null) + return false; + } else if (!rhs.equals(other.rhs)) + return false; + if (value == null) { + if (other.value != null) + return false; + } else if (!value.equals(other.value)) + return false; + return true; + } + + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/MapperConfig.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/MapperConfig.java new file mode 100644 index 0000000..6055e86 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/mappingconfig/MapperConfig.java @@ -0,0 +1,88 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.mappingconfig; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import org.apache.commons.lang.builder.EqualsBuilder; +import org.apache.commons.lang.builder.HashCodeBuilder; +import org.apache.commons.lang.builder.ToStringBuilder; +import com.fasterxml.jackson.annotation.JsonAnyGetter; +import com.fasterxml.jackson.annotation.JsonAnySetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; + +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder({ + "entries" +}) +public class MapperConfig { + + @JsonProperty("entries") + private Set<Entry> entries = null; + @JsonIgnore + private Map<String, Object> additionalProperties = new HashMap<String, Object>(); + + @JsonProperty("entries") + public Set<Entry> getEntries() { + return entries; + } + + @JsonProperty("entries") + public void setEntries(Set<Entry> entries) { + this.entries = entries; + } + + @JsonAnyGetter + public Map<String, Object> getAdditionalProperties() { + return this.additionalProperties; + } + + @JsonAnySetter + public void setAdditionalProperty(String name, Object value) { + this.additionalProperties.put(name, value); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("entries", entries).append("additionalProperties", additionalProperties).toString(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(additionalProperties).append(entries).toHashCode(); + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + if ((other instanceof MapperConfig) == false) { + return false; + } + MapperConfig rhs = ((MapperConfig) other); + return new EqualsBuilder().append(additionalProperties, rhs.additionalProperties).append(entries, rhs.entries).isEquals(); + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/AdapterService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/AdapterService.java new file mode 100644 index 0000000..14c5a83 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/AdapterService.java @@ -0,0 +1,57 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ + +package org.onap.universalvesadapter.service; + +//import org.onap.universalvesadapter.adapter.GenericAdapter; +//import org.onap.universalvesadapter.adapter.UniversalEventAdapter; +//import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * This service is written to identify the different type of events + * + * @author kmalbari + * + */ +@Component +public class AdapterService { + + /*@Autowired + private UniversalEventAdapter snmpTrapEventAdapter; + public GenericAdapter identifyIncomingJsonFormatAndReturnAdapter() { + return snmpTrapEventAdapter; + }*/ + + + /** + * Identifies eventype by parsing the incoming json file. + * + * @param incomingJsonString + * + * @return the event type + */ + public String identifyEventTypeFromIncomingJson(String incomingJsonString) { + + //TODO A proper logic to identify diffeent events is needed here + return "snmp"; + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/ConfigFileService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/ConfigFileService.java new file mode 100644 index 0000000..09e2592 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/ConfigFileService.java @@ -0,0 +1,41 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.service; + +import org.onap.universalvesadapter.exception.ConfigFileReadException; + +/** + * A contract defined for services that will handle the operations of config file + * + * @author kmalbari + * + */ +public interface ConfigFileService { + + /** + * Returns the config file data + * + * @param fileName + * @return config file content + * @throws ConfigFileReadException if unable to read config file + */ + String readConfigFile(String fileName) throws ConfigFileReadException; + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DMaapService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DMaapService.java new file mode 100644 index 0000000..0b318eb --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DMaapService.java @@ -0,0 +1,155 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.service; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.util.List; +import java.util.Map; +import org.onap.universalvesadapter.configs.DMaapMrUrlConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +//import com.att.nsa.mr.client.MRBatchingPublisher; +//import com.att.nsa.mr.client.MRClientFactory; +//import com.att.nsa.mr.client.MRConsumer; + +/** + * + * This service will handle all the communication with the DMaap MR API + * + * + * @author kmalbari + * + */ +@Component +public class DMaapService { + + @Autowired + private DMaapMrUrlConfiguration dmaapMrUrlObject; + +// private MRConsumer cc; +// +// private MRBatchingPublisher pub; + + /** + * reads the messages on DMaap MR Topic + * + * @return iterable of messages that will be received on DMaap MR Topic + * + * @throws DMaapException + */ + /*public Iterable<String> consumeFromDMaap() throws DMaapException{ + if(null == cc){ + try { + cc = MRClientFactory.createConsumer (dmaapMrUrlObject.getConsumerProperties()); + } catch (IOException exception) { + throw new DMaapException("Problem creating consumer \nReason : " + exception.getMessage()); + } + + try { + return cc.fetch(); + } catch (Exception exception) { + throw new DMaapException("Problem while fetching messaged from consumer \nReason : " + exception.getMessage()); + } + } + return () -> Collections.emptyIterator(); + + }*/ + + + /** + * sends the messages to DMaap MR Topic + * + * + * @throws DMaapException + */ + /*public void publishToDMaap() throws DMaapException{ + if(null == cc){ + try { + pub = MRClientFactory.createBatchingPublisher (dmaapMrUrlObject.getPublisherProperties()); + } catch (IOException exception) { + throw new DMaapException("Problem creating consumer \nReason : " + exception.getMessage()); + } + + } + + }*/ + + + + + /** + * @return + */ + public String consume(){ + URL url; + StringBuffer incomingJson = null; + incomingJson = new StringBuffer(); + try { + url = new URL(dmaapMrUrlObject.getUrl()); + + //open the connection to the above URL. + URLConnection urlcon = url.openConnection(); + + Map<String, List<String>> header = urlcon.getHeaderFields(); + + //print all the fields along with their value. + for (Map.Entry<String, List<String>> mp : header.entrySet()) + { + System.out.print(mp.getKey() + " : "); + System.out.println(mp.getValue().toString()); + } + System.out.println(); + System.out.println("Complete source code of the URL is-"); + System.out.println("---------------------------------"); + + //get the inputstream of the open connection. + BufferedReader br = new BufferedReader(new InputStreamReader + (urlcon.getInputStream())); + String tempString; + //print the source code line by line. + while ((tempString = br.readLine()) != null) + { + System.out.println(tempString); + incomingJson.append(tempString); + } + + } catch (MalformedURLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + return incomingJson.toString(); + } + + + + + + + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java new file mode 100644 index 0000000..c2a30f0 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/DiskRepoConfigFileService.java @@ -0,0 +1,73 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.service; + +import java.net.URI; +import java.net.URISyntaxException; + +import org.onap.universalvesadapter.configs.DiskRepoConfiguration; +import org.onap.universalvesadapter.exception.ConfigFileReadException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +/** + * Implementation of {@code ConfigFileService} using disk repository + * + * @author kmalbari + * + */ +@Component +public class DiskRepoConfigFileService implements ConfigFileService { + + private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + + @Autowired + private DiskRepoConfiguration diskRepoConfiguration; + + private RestTemplate restTemplate = new RestTemplate(); + + private URI uri = null; + + /* (non-Javadoc) + * @see org.onap.universalvesadapter.service.ConfigFileService#readConfigFile(java.lang.String) + */ + @Override + public String readConfigFile(String fileName) throws ConfigFileReadException { + LOGGER.debug("Reading config file for " + fileName); + if(null == uri){ + try { + uri = new URI(diskRepoConfiguration.getFileRepositoryUrl()+fileName); + LOGGER.debug("Read URI for " + fileName); + } catch (URISyntaxException exception) { + throw new ConfigFileReadException("Unable to read config file for file " + + fileName + "\n Reason : " + exception.getMessage()); + } + } + LOGGER.debug("Calling file repo service for URI" + uri); + ResponseEntity<String> fileDataEntity = restTemplate.getForEntity(uri, String.class); + LOGGER.debug("Call completed successfully"); + return fileDataEntity.getBody(); + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/MongoDbConfigFileService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/MongoDbConfigFileService.java new file mode 100644 index 0000000..bab304a --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/MongoDbConfigFileService.java @@ -0,0 +1,46 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.service; + +import org.onap.universalvesadapter.domain.ConfigFileData; +import org.springframework.stereotype.Component; + +/** + * Service to use mongo db as config file repository + * + * @author kmalbari + * + */ +@Component +public class MongoDbConfigFileService implements ConfigFileService { + + /* (non-Javadoc) + * @see org.onap.universalvesadapter.service.ConfigFileService#readConfigFile(java.lang.String) + */ + public String readConfigFile(String configFileName){ + //HERE CONFIG FILE DATA WOULD COME FROM MONGO DB + ConfigFileData configFileData = new ConfigFileData(); + configFileData.setXmlFileName(""); + configFileData.setXmlContent("<?xml version=\"1.0\" encoding=\"UTF-8\"?> <smooks-resource-list xmlns=\"http://www.milyn.org/xsd/smooks-1.1.xsd\" xmlns:json=\"http://www.milyn.org/xsd/smooks/json-1.1.xsd\" xmlns:jb=\"http://www.milyn.org/xsd/smooks/javabean-1.2.xsd\"> <json:reader rootName=\"simple\" keyWhitspaceReplacement=\"-\"> </json:reader> <!-- <jb:bean class=\"com.example.demo.Simple\" beanId=\"simple\" createOnElement=\"simple\"> <jb:value property=\"orderId\" data=\"#/orderId\" /> <jb:value property=\"username\" data=\"#/username\" /> <jb:wiring property=\"customer\" beanIdRef=\"customer\"/> <jb:wiring property=\"orderItems\" beanIdRef=\"orderItems\"/> </jb:bean> --> <jb:bean class=\"org.onap.dcaegen2.ves.domain.VesEvent\" beanId=\"vesEvent\" createOnElement=\"simple\"> <jb:wiring property=\"event\" beanIdRef=\"event\"/> </jb:bean> <jb:bean class=\"org.onap.dcaegen2.ves.domain.Event\" beanId=\"event\" createOnElement=\"simple\"> <jb:wiring property=\"commonEventHeader\" beanIdRef=\"commonEventHeader\"/> <jb:wiring property=\"faultFields\" beanIdRef=\"faultFields\"/> <jb:wiring property=\"measurementsForVfScalingFields\" beanIdRef=\"measurementsForVfScalingFields\"/> </jb:bean> <jb:bean class=\"org.onap.dcaegen2.ves.domain.MeasurementsForVfScalingFields\" beanId=\"measurementsForVfScalingFields\" createOnElement=\"simple\"> <jb:wiring property=\"additionalMeasurements\" beanIdRef=\"additionalMeasurements\"/> </jb:bean> <jb:bean class=\"org.onap.dcaegen2.ves.domain.CommonEventHeader\" beanId=\"commonEventHeader\" createOnElement=\"simple\"> <jb:value property=\"eventId\" data=\"#/community\" /> <jb:value property=\"eventName\" data=\"#/protocol-version\" /> <jb:value property=\"domain\" data=\"#/trap-category\" /> <jb:value property=\"sequence\" data=\"#/time-received\" decoder=\"Long\"/> <jb:value property=\"lastEpochMicrosec\" data=\"#/community-len\" decoder=\"Double\" /> <jb:value property=\"startEpochMicrosec\" data=\"#/notify-OID-len\" /> </jb:bean> <jb:bean class=\"org.onap.dcaegen2.ves.domain.FaultFields\" beanId=\"faultFields\" createOnElement=\"simple\"> <jb:value property=\"alarmCondition\" data=\"#/cambria.partition\" /> <jb:value property=\"eventSeverity\" data=\"#/notify-OID\" /> <jb:value property=\"eventSourceType\" data=\"#/agent-name\" /> <jb:value property=\"specificProblem\" data=\"#/agent-address\" /> <jb:value property=\"faultFieldsVersion\" data=\"#/epoch_serno\" decoder=\"Double\" /> </jb:bean> <jb:bean class=\"java.util.ArrayList\" beanId=\"additionalMeasurements\" createOnElement=\"simple\"> <jb:wiring beanIdRef=\"additionalMeasurement\"/> </jb:bean> <jb:bean class=\"org.onap.dcaegen2.ves.domain.AdditionalMeasurement\" beanId=\"additionalMeasurement\" createOnElement=\"varbinds/element\"> <jb:value property=\"name\" data=\"#/varbind_value\" /> </jb:bean> </smooks-resource-list>"); + return configFileData.getXmlContent(); + } + + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java new file mode 100644 index 0000000..81cb4b8 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/service/VesService.java @@ -0,0 +1,128 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.service; + +import javax.annotation.Resource; +import org.onap.universalvesadapter.adapter.GenericAdapter; +import org.onap.universalvesadapter.exception.ConfigFileReadException; +import org.onap.universalvesadapter.exception.ConfigFileSmooksConversionException; +import org.onap.universalvesadapter.exception.VesException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * Service that starts the universal ves adapter module to listen for events + * + * @author kmalbari + * + */ +@Component +public class VesService { + + private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + + private boolean isRunning = true; + + @Autowired + private DMaapService dmaapService; + + @Autowired + private AdapterService adapterService; + + @Resource(name="universalEventAdapter") + private GenericAdapter eventAdapter; + + @Value("${messagesInBatch}") + private int messagesInBatch; + + /*public void start(){ + + String incomingJsonString = dmaapService.consume(); + if(!"".equals(incomingJsonString)){ + GenericAdapter eventAdapter = adapterService.identifyIncomingJsonFormatAndReturnAdapter(); + String outgoingJsonString = eventAdapter.transform(incomingJsonString); + System.out.println(outgoingJsonString); + } + }*/ + + + /** + * method triggers universal ves adapter module + */ + public void start() { + /*ParallelTasks parallelTasks = new ParallelTasks(); + int processingNumberOfMessage = 0; + while (isRunning) { + try { + for(String incomingJsonString : dmaapService.consumeFromDMaap()){ + parallelTasks.add(() -> processReceivedJson(incomingJsonString)); + processingNumberOfMessage++; + if(processingNumberOfMessage == messagesInBatch){ + parallelTasks.startParallelTasks(); + processingNumberOfMessage=0; + parallelTasks = new ParallelTasks(); + try + { + Thread.sleep(1000); + } + catch (InterruptedException e) + { + } + } + } + } catch (DMaapException e) { + } + }*/ + String incomingJsonString = dmaapService.consume(); + processReceivedJson(incomingJsonString); + } + + /** + * It finds mapping file for received json, transforms json to VES format + * and publishes it to outgoing DMaap MR Topic + * + * @param incomingJsonString + */ + private void processReceivedJson(String incomingJsonString) { + try { + LOGGER.debug("Received incoming message" + incomingJsonString); + if (!"".equals(incomingJsonString)) { + String eventType = adapterService.identifyEventTypeFromIncomingJson(incomingJsonString); + LOGGER.debug("Event identified as " + eventType); + String outgoingJsonString; + outgoingJsonString = eventAdapter.transform(incomingJsonString, eventType); + LOGGER.debug("Output VES json to be sent " + outgoingJsonString); + } + } catch (ConfigFileReadException | ConfigFileSmooksConversionException | VesException exception) { + LOGGER.error(exception.getMessage()); + } + } + + /** + * method stops universal ves adapter module + */ + public void stop() { + + isRunning = false; + } +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java new file mode 100644 index 0000000..e94cdf5 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/MapperConfigUtils.java @@ -0,0 +1,322 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.utils; + +import com.att.aft.dme2.internal.apache.commons.lang3.EnumUtils; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import java.io.IOException; +import java.util.Set; +import java.util.TreeSet; +import org.onap.universalvesadapter.exception.MapperConfigException; +import org.onap.universalvesadapter.mappingconfig.Entry; +import org.onap.universalvesadapter.mappingconfig.Evaluation; +import org.onap.universalvesadapter.mappingconfig.MapperConfig; + +/** + * This class will be utility class to read the mapper config file and parse the + * config to prepare the grammar to detect the incoming json's event type. + * + * @author kmalbari + * + */ +public class MapperConfigUtils { + + private static Set<Entry> entries = new TreeSet<>((o1, o2) -> o1.getPriority().compareTo(o2.getPriority())); + + private enum JoinOperator { + AND("AND"), OR("OR"); + + private final String value; + + private JoinOperator(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + private enum ExpressionOperator { + EQUALS("EQUALS"), STARTSWITH("STARTSWITH"), ENDSWITH("ENDSWITH"), CONTAINS("CONTAINS"); + + private final String value; + + private ExpressionOperator(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + private enum DataType { + STRING("STRING"), DOUBLE("DOUBLE"); + + private final String value; + + private DataType(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + } + + /** + * main method. + * + * @param args + * arguments + */ + public static void main(String[] args) { + + String mappingFile = " { " + " \"entries\": [{ " + " \"priority\": 4, " + " \"evaluation\": { " + + " \"operand\": \"AND\", " + " \"field\": null, " + " \"value\": null, " + + " \"datatype\": null, " + " \"lhs\": { " + " \"operand\": \"OR\", " + + " \"field\": null, " + " \"value\": null, " + + " \"datatype\": null, " + " \"lhs\": { " + + " \"operand\": \"EQUALS\", " + " \"field\": \"domain\", " + + " \"value\": \"snmp-heartbeat\", " + " \"datatype\": \"string\", " + + " \"lhs\": null, " + " \"rhs\": null " + " }, " + + " \"rhs\": { " + " \"operand\": \"EQUALS\", " + + " \"field\": \"domain\", " + " \"value\": \"snmp-fault\", " + + " \"datatype\": \"string\", " + " \"lhs\": null, " + + " \"rhs\": null " + " } " + " }, " + " \"rhs\": { " + + " \"operand\": \"EQUALS\", " + " \"field\": \"trap version\", " + + " \"value\": \"1.2\", " + " \"datatype\": \"float\", " + + " \"lhs\": null, " + " \"rhs\": null " + " } " + " }, " + + " \"result\": \"smooks.config\" " + " }, { " + " \"priority\": 1, " + + " \"evaluation\": { " + " \"operand\": \"AND\", " + " \"field\": null, " + + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " + + " \"operand\": \"OR\", " + " \"field\": null, " + + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " + + " \"operand\": \"EQUALS\", " + " \"field\": \"domain\", " + + " \"value\": \"snmp-heartbeat\", " + " \"datatype\": \"string\", " + + " \"lhs\": null, " + " \"rhs\": null " + " }, " + + " \"rhs\": { " + " \"operand\": \"EQUALS\", " + + " \"field\": \"domain\", " + " \"value\": \"snmp-fault\", " + + " \"datatype\": \"string\", " + " \"lhs\": null, " + + " \"rhs\": null " + " } " + " }, " + " \"rhs\": { " + + " \"operand\": \"EQUALS\", " + " \"field\": \"trap version\", " + + " \"value\": \"1.2\", " + " \"datatype\": \"float\", " + + " \"lhs\": null, " + " \"rhs\": null " + " } " + " }, " + + " \"result\": \"smooks.config\" " + " }, { " + " \"priority\": 3, " + + " \"evaluation\": { " + " \"operand\": \"AND\", " + " \"field\": null, " + + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " + + " \"operand\": \"OR\", " + " \"field\": null, " + + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " + + " \"operand\": \"EQUALS\", " + " \"field\": \"domain\", " + + " \"value\": \"snmp-heartbeat\", " + " \"datatype\": \"string\", " + + " \"lhs\": null, " + " \"rhs\": null " + " }, " + + " \"rhs\": { " + " \"operand\": \"EQUALS\", " + + " \"field\": \"domain\", " + " \"value\": \"snmp-fault\", " + + " \"datatype\": \"string\", " + " \"lhs\": null, " + + " \"rhs\": null " + " } " + " }, " + " \"rhs\": { " + + " \"operand\": \"EQUALS\", " + " \"field\": \"trap version\", " + + " \"value\": \"1.2\", " + " \"datatype\": \"float\", " + + " \"lhs\": null, " + " \"rhs\": null " + " } " + " }, " + + " \"result\": \"smooks.config\" " + " }, { " + " \"priority\": 2, " + + " \"evaluation\": { " + " \"operand\": \"AND\", " + " \"field\": null, " + + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " + + " \"operand\": \"OR\", " + " \"field\": null, " + + " \"value\": null, " + " \"datatype\": null, " + " \"lhs\": { " + + " \"operand\": \"EQUALS\", " + " \"field\": \"domain\", " + + " \"value\": \"snmp-heartbeat\", " + " \"datatype\": \"string\", " + + " \"lhs\": null, " + " \"rhs\": null " + " }, " + + " \"rhs\": { " + " \"operand\": \"EQUALS\", " + + " \"field\": \"domain\", " + " \"value\": \"snmp-fault\", " + + " \"datatype\": \"string\", " + " \"lhs\": null, " + + " \"rhs\": null " + " } " + " }, " + " \"rhs\": { " + + " \"operand\": \"EQUALS\", " + " \"field\": \"trap version\", " + + " \"value\": \"1.2\", " + " \"datatype\": \"float\", " + + " \"lhs\": null, " + " \"rhs\": null " + " } " + " }, " + + " \"result\": \"smooks.config\" " + " }] " + "}"; + String incomingJsonString = "{\"domain\":\"snmp-heartbeat\",\"trap version\":1.2}"; + + try { + readMapperConfigFile(mappingFile); + checkIncomingJsonForMatchingDomain(incomingJsonString); + } catch (MapperConfigException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + /** + * Checks incoming json to see which of the domain it mathces as per mapper + * config entries. If nothing matches, a default mapping will be used. + * + * @param incomingJsonString + * incoming json + * @throws MapperConfigException + * if error occurs in operation + */ + public static String checkIncomingJsonForMatchingDomain(String incomingJsonString) throws MapperConfigException { + ObjectMapper mapper = new ObjectMapper(); + JsonNode actualObj = null; + try { + actualObj = mapper.readTree(incomingJsonString); + } catch (IOException exception) { + throw new MapperConfigException("Unable to read incoming json in a tree " + exception.getMessage(), + exception); + } + for (Entry entry : entries) { + + boolean result = false; + result = evaluateEntryMatch(entry.getEvaluation(), actualObj); + if (result) { + return entry.getResult(); + } + } + return "default"; + } + + /** + * Reads the mapper config file. + * + * @param mappingFileData + * string json for mapper config + * @throws MapperConfigException + * if error in mapper config + */ + public static void readMapperConfigFile(String mappingFileData) throws MapperConfigException { + + ObjectMapper name = new ObjectMapper(); + MapperConfig config = null; + try { + config = name.readValue(mappingFileData, MapperConfig.class); + } catch (IOException exception) { + throw new MapperConfigException("Unable to read config file for reason...\n " + exception.getMessage(), + exception); + } + System.out.println("Read config file content into :" + config); + if (null != config) { + entries.addAll(config.getEntries()); + } else { + throw new MapperConfigException("Unable to generate configuration for different domains."); + } + } + + /** + * Evaluates the passed in {@code Evaluation} instance and return boolean + * result. + * + * @param evaluation + * evaluation instance + * @param actualObj + * Json node with values to compare with + * @return true if matches evaluation else false + * @throws MapperConfigException + * error in evaluation + */ + public static boolean evaluateEntryMatch(Evaluation evaluation, JsonNode actualObj) throws MapperConfigException { + if (null == evaluation) { + throw new MapperConfigException("Cannot have null evaluation"); + } + if (null != evaluation.getOperand()) { + + if (EnumUtils.isValidEnum(JoinOperator.class, evaluation.getOperand())) { + // if(JOIN_OPERATOR.contains(evaluation.getOperand())){ + switch (JoinOperator.valueOf(evaluation.getOperand())) { + case AND: + return evaluateEntryMatch(evaluation.getLhs(), actualObj) + && evaluateEntryMatch(evaluation.getRhs(), actualObj); + case OR: + return evaluateEntryMatch(evaluation.getLhs(), actualObj) + || evaluateEntryMatch(evaluation.getRhs(), actualObj); + default: + break; + } + } + + if (EnumUtils.isValidEnum(ExpressionOperator.class, evaluation.getOperand())) { + // if(EXPR_OPERATOR.contains(evaluation.getOperand())){ + + // currently it is assumed field being compared is first level + // child of incoming JSON structure. + // If needed, can write a JsonPath implementation later + String field = evaluation.getField(); + if (null != field && null != evaluation.getDatatype() && actualObj.has(field)) { + switch (ExpressionOperator.valueOf(evaluation.getOperand())) { + case EQUALS: + if (EnumUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { + switch (DataType.valueOf(evaluation.getDatatype())) { + case STRING: + if (null != actualObj.get(field)) + return actualObj.get(field).asText().equals(evaluation.getValue()); + case DOUBLE: + if (null != actualObj.get(field)) + return actualObj.get(field).asDouble() == Double + .valueOf(evaluation.getValue()); + default: + return false; + } + } else + return false; + case STARTSWITH: + if (EnumUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { + switch (DataType.valueOf(evaluation.getDatatype())) { + case STRING: + if (null != actualObj.get(field)) + return actualObj.get(field).asText().startsWith(evaluation.getValue()); + default: + return false; + } + } else + return false; + case ENDSWITH: + if (EnumUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { + switch (DataType.valueOf(evaluation.getDatatype())) { + case STRING: + if (null != actualObj.get(field)) + return actualObj.get(field).asText().endsWith(evaluation.getValue()); + default: + return false; + } + } else + return false; + case CONTAINS: + if (EnumUtils.isValidEnum(DataType.class, evaluation.getDatatype())) { + switch (DataType.valueOf(evaluation.getDatatype())) { + case STRING: + if (null != actualObj.get(field)) + return actualObj.get(field).asText().contains(evaluation.getValue()); + default: + return false; + } + } else + return false; + default: + return false; + } + } + } + } else + throw new MapperConfigException("Not an expected operand as per config for " + evaluation.getField()); + + return false; + } + +} diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/ParallelTasks.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/ParallelTasks.java new file mode 100644 index 0000000..45fdf96 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/ParallelTasks.java @@ -0,0 +1,87 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.utils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * + * Utility class to execute parallel tasks + * + * @author kmalbari + * + */ +public class ParallelTasks +{ + private final Collection<Runnable> tasks = new ArrayList<Runnable>(); + + public ParallelTasks() + { + } + + /** + * + * Add task to be executed in parallel + * + * @param task + */ + public void add(final Runnable task) + { + tasks.add(task); + } + + /** + * starts all the added tasks in parallel + * + * @throws InterruptedException + */ + public void startParallelTasks() throws InterruptedException + { + final ExecutorService threads = Executors.newFixedThreadPool(Runtime.getRuntime() + .availableProcessors()); + try + { + final CountDownLatch latch = new CountDownLatch(tasks.size()); + for (final Runnable task : tasks) + threads.execute(new Runnable() { + public void run() + { + try + { + task.run(); + } + finally + { + latch.countDown(); + } + } + }); + latch.await(); + } + finally + { + threads.shutdown(); + } + } +}
\ No newline at end of file diff --git a/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/SmooksUtils.java b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/SmooksUtils.java new file mode 100644 index 0000000..df36da6 --- /dev/null +++ b/UniversalVesAdapter/src/main/java/org/onap/universalvesadapter/utils/SmooksUtils.java @@ -0,0 +1,76 @@ +/* +* ============LICENSE_START======================================================= +* ONAP : DCAE +* ================================================================================ +* Copyright 2018 TechMahindra +*================================================================================= +* 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========================================================= +*/ +package org.onap.universalvesadapter.utils; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import java.util.Locale; +import javax.xml.transform.stream.StreamSource; +import org.milyn.Smooks; +import org.milyn.container.ExecutionContext; +import org.milyn.payload.StringResult; +import org.onap.dcaegen2.ves.domain.VesEvent; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +/** + * Utility methods for smooks module + * + * @author kmalbari + * + */ +public class SmooksUtils { + + + private final static Logger LOGGER = LoggerFactory.getLogger(SmooksUtils.class); + + /** + * converts the incoming json using passed smooks instance and return the pojo representation of VES event + * + * @param smooks smooks object for the event type + * @param incomingJsonString + * @return VES json's pojo representation + * @throws IOException + */ + public static VesEvent getTransformedObjectForInput(Smooks smooks, String incomingJsonString) { + + LOGGER.debug("Transforming json " + incomingJsonString); + ExecutionContext executionContext = smooks.createExecutionContext(); + LOGGER.debug("Context created"); + Locale defaultLocale = Locale.getDefault(); + Locale.setDefault(new Locale("en", "IE")); + + StringResult result = new StringResult(); + + // Configure the execution context to generate a report... +// executionContext.setEventListener(new HtmlReportGenerator("target/report/report.html")); + + // Filter the input message to the outputWriter, using the execution context... + smooks.filterSource(executionContext, new StreamSource(new ByteArrayInputStream(incomingJsonString.getBytes(StandardCharsets.UTF_8))), result); + LOGGER.debug("Transformed incoming json now"); + Locale.setDefault(defaultLocale); + VesEvent vesEvent = (VesEvent) executionContext.getBeanContext().getBean("vesEvent"); + LOGGER.debug("Converted vesEvent from incoming json"); + return vesEvent; + } + +} |