TCA: Replace any openecomp reference by onap
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / main / java / org / onap / dcae / apod / analytics / cdap / tca / flowlet / TCAVESAAIEnrichmentFlowlet.java
-/*\r
- * ===============================LICENSE_START======================================\r
- *  dcae-analytics\r
- * ================================================================================\r
- *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * ================================================================================\r
- *  Licensed under the Apache License, Version 2.0 (the "License");\r
- *  you may not use this file except in compliance with the License.\r
- *   You may obtain a copy of the License at\r
- *\r
- *          http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- *  Unless required by applicable law or agreed to in writing, software\r
- *  distributed under the License is distributed on an "AS IS" BASIS,\r
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- *  See the License for the specific language governing permissions and\r
- *  limitations under the License.\r
- *  ============================LICENSE_END===========================================\r
- */\r
-\r
-package org.openecomp.dcae.apod.analytics.cdap.tca.flowlet;\r
-\r
-import co.cask.cdap.api.annotation.Output;\r
-import co.cask.cdap.api.annotation.ProcessInput;\r
-import co.cask.cdap.api.flow.flowlet.AbstractFlowlet;\r
-import co.cask.cdap.api.flow.flowlet.FlowletContext;\r
-import co.cask.cdap.api.flow.flowlet.OutputEmitter;\r
-import org.openecomp.dcae.apod.analytics.aai.AAIClientFactory;\r
-import org.openecomp.dcae.apod.analytics.aai.domain.config.AAIHttpClientConfig;\r
-import org.openecomp.dcae.apod.analytics.aai.service.AAIEnrichmentClient;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;\r
-import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCAAppPreferences;\r
-import org.openecomp.dcae.apod.analytics.cdap.tca.utils.CDAPTCAUtils;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.ClosedLoopEventStatus;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.ControlLoopSchemaType;\r
-import org.openecomp.dcae.apod.analytics.model.facade.tca.TCAVESResponse;\r
-import org.openecomp.dcae.apod.analytics.tca.utils.TCAUtils;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.io.IOException;\r
-\r
-/**\r
- * Flowlet responsible for doing A&AI Enrichment\r
- *\r
- * @author Rajiv Singla . Creation Date: 9/20/2017.\r
- */\r
-public class TCAVESAAIEnrichmentFlowlet extends AbstractFlowlet {\r
-\r
-    private static final Logger LOG = LoggerFactory.getLogger(TCAVESAAIEnrichmentFlowlet.class);\r
-\r
-    @Output(CDAPComponentsConstants.TCA_FIXED_VES_AAI_ENRICHMENT_NAME_OUTPUT)\r
-    protected OutputEmitter<String> aaiEnrichmentOutputEmitter;\r
-\r
-    private TCAAppPreferences tcaAppPreferences;\r
-    private AAIEnrichmentClient aaiEnrichmentClient;\r
-\r
-    @Override\r
-    public void configure() {\r
-        setName(CDAPComponentsConstants.TCA_FIXED_VES_AAI_ENRICHMENT_NAME_FLOWLET);\r
-        setDescription(CDAPComponentsConstants.TCA_FIXED_VES_AAI_ENRICHMENT_DESCRIPTION_FLOWLET);\r
-    }\r
-\r
-    @Override\r
-    public void initialize(FlowletContext flowletContext) throws Exception {\r
-        super.initialize(flowletContext);\r
-        tcaAppPreferences = CDAPTCAUtils.getValidatedTCAAppPreferences(flowletContext);\r
-        if (tcaAppPreferences.getEnableAAIEnrichment()) {\r
-            final AAIHttpClientConfig aaiHttpClientConfig =\r
-                    CDAPTCAUtils.createAAIEnrichmentClientConfig(tcaAppPreferences);\r
-            aaiEnrichmentClient = AAIClientFactory.create().getEnrichmentClient(aaiHttpClientConfig);\r
-        }\r
-    }\r
-\r
-    @ProcessInput(CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_ABATEMENT_NAME_OUTPUT)\r
-    public void performAAIEnrichment(final String alertMessageString) throws IOException {\r
-\r
-        // if A&AI enrichment is disabled - no A&AI lookups are required\r
-        if (!tcaAppPreferences.getEnableAAIEnrichment()) {\r
-\r
-            LOG.debug("A&AI Enrichment is disabled. Skip A&AI Enrichment for alert: {}", alertMessageString);\r
-            aaiEnrichmentOutputEmitter.emit(alertMessageString);\r
-\r
-        } else {\r
-\r
-            // determine closed Loop Event Status\r
-            final TCAVESResponse tcavesResponse = TCAUtils.readValue(alertMessageString, TCAVESResponse.class);\r
-            final ClosedLoopEventStatus closedLoopEventStatus =\r
-                    ClosedLoopEventStatus.valueOf(tcavesResponse.getClosedLoopEventStatus());\r
-\r
-            if (closedLoopEventStatus == ClosedLoopEventStatus.ONSET) {\r
-                LOG.debug("Performing A&AI Enrichment of ONSET Alert: {}", alertMessageString);\r
-                final ControlLoopSchemaType controlLoopSchemaType =\r
-                        TCAUtils.determineControlLoopSchemaType(tcavesResponse);\r
-                final String sourceName = TCAUtils.determineSourceName(tcavesResponse);\r
-                LOG.debug("A&AI Source Name: {}, Control Loop Schema Type: {} for ONSET Alert: {}",\r
-                        sourceName, controlLoopSchemaType, alertMessageString);\r
-\r
-                if (controlLoopSchemaType == ControlLoopSchemaType.VM) {\r
-                    final String aaiVMEnrichmentAPIPath = tcaAppPreferences.getAaiVMEnrichmentAPIPath();\r
-                    TCAUtils.doAAIVMEnrichment(tcavesResponse, aaiEnrichmentClient, aaiVMEnrichmentAPIPath,\r
-                            alertMessageString, sourceName);\r
-                } else {\r
-                    final String aaiVNFEnrichmentAPIPath = tcaAppPreferences.getAaiVNFEnrichmentAPIPath();\r
-                    TCAUtils.doAAIVNFEnrichment(tcavesResponse, aaiEnrichmentClient, aaiVNFEnrichmentAPIPath,\r
-                            alertMessageString, sourceName);\r
-                }\r
-\r
-                final String aaiEnrichedAlert = TCAUtils.writeValueAsString(tcavesResponse);\r
-                LOG.debug("Emitting Alert after A&AI Enrichment: {}", aaiEnrichedAlert);\r
-                aaiEnrichmentOutputEmitter.emit(aaiEnrichedAlert);\r
-\r
-                // skip A&AI Enrichment of alerts with closed Loop Event Status - ABATED\r
-            } else if (closedLoopEventStatus == ClosedLoopEventStatus.ABATED) {\r
-                LOG.debug("Skipping Enrichment of Abated Alert: {}", alertMessageString);\r
-                aaiEnrichmentOutputEmitter.emit(alertMessageString);\r
-\r
-            } else {\r
-                // unsupported closed loop event status\r
-                final String errorMessage = String.format(\r
-                        "Unexpected ClosedLoopEventStatus: %s. Only ONSET and ABATED are supported." +\r
-                                "Ignoring alert: %s", closedLoopEventStatus, alertMessageString);\r
-                throw new CDAPSettingsException(errorMessage, LOG, new IllegalStateException(errorMessage));\r
-            }\r
-        }\r
-    }\r
-}\r
+/*
+ * ===============================LICENSE_START======================================
+ *  dcae-analytics
+ * ================================================================================
+ *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ *  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.dcae.apod.analytics.cdap.tca.flowlet;
+
+import co.cask.cdap.api.annotation.Output;
+import co.cask.cdap.api.annotation.ProcessInput;
+import co.cask.cdap.api.flow.flowlet.AbstractFlowlet;
+import co.cask.cdap.api.flow.flowlet.FlowletContext;
+import co.cask.cdap.api.flow.flowlet.OutputEmitter;
+import org.onap.dcae.apod.analytics.aai.AAIClientFactory;
+import org.onap.dcae.apod.analytics.aai.domain.config.AAIHttpClientConfig;
+import org.onap.dcae.apod.analytics.aai.service.AAIEnrichmentClient;
+import org.onap.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
+import org.onap.dcae.apod.analytics.cdap.common.exception.CDAPSettingsException;
+import org.onap.dcae.apod.analytics.cdap.tca.settings.TCAAppPreferences;
+import org.onap.dcae.apod.analytics.cdap.tca.utils.CDAPTCAUtils;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.ClosedLoopEventStatus;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.ControlLoopSchemaType;
+import org.onap.dcae.apod.analytics.model.facade.tca.TCAVESResponse;
+import org.onap.dcae.apod.analytics.tca.utils.TCAUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+
+/**
+ * Flowlet responsible for doing A&AI Enrichment
+ *
+ * @author Rajiv Singla . Creation Date: 9/20/2017.
+ */
+public class TCAVESAAIEnrichmentFlowlet extends AbstractFlowlet {
+
+    private static final Logger LOG = LoggerFactory.getLogger(TCAVESAAIEnrichmentFlowlet.class);
+
+    @Output(CDAPComponentsConstants.TCA_FIXED_VES_AAI_ENRICHMENT_NAME_OUTPUT)
+    protected OutputEmitter<String> aaiEnrichmentOutputEmitter;
+
+    private TCAAppPreferences tcaAppPreferences;
+    private AAIEnrichmentClient aaiEnrichmentClient;
+
+    @Override
+    public void configure() {
+        setName(CDAPComponentsConstants.TCA_FIXED_VES_AAI_ENRICHMENT_NAME_FLOWLET);
+        setDescription(CDAPComponentsConstants.TCA_FIXED_VES_AAI_ENRICHMENT_DESCRIPTION_FLOWLET);
+    }
+
+    @Override
+    public void initialize(FlowletContext flowletContext) throws Exception {
+        super.initialize(flowletContext);
+        tcaAppPreferences = CDAPTCAUtils.getValidatedTCAAppPreferences(flowletContext);
+        if (tcaAppPreferences.getEnableAAIEnrichment()) {
+            final AAIHttpClientConfig aaiHttpClientConfig =
+                    CDAPTCAUtils.createAAIEnrichmentClientConfig(tcaAppPreferences);
+            aaiEnrichmentClient = AAIClientFactory.create().getEnrichmentClient(aaiHttpClientConfig);
+        }
+    }
+
+    @ProcessInput(CDAPComponentsConstants.TCA_FIXED_VES_ALERTS_ABATEMENT_NAME_OUTPUT)
+    public void performAAIEnrichment(final String alertMessageString) throws IOException {
+
+        // if A&AI enrichment is disabled - no A&AI lookups are required
+        if (!tcaAppPreferences.getEnableAAIEnrichment()) {
+
+            LOG.debug("A&AI Enrichment is disabled. Skip A&AI Enrichment for alert: {}", alertMessageString);
+            aaiEnrichmentOutputEmitter.emit(alertMessageString);
+
+        } else {
+
+            // determine closed Loop Event Status
+            final TCAVESResponse tcavesResponse = TCAUtils.readValue(alertMessageString, TCAVESResponse.class);
+            final ClosedLoopEventStatus closedLoopEventStatus =
+                    ClosedLoopEventStatus.valueOf(tcavesResponse.getClosedLoopEventStatus());
+
+            if (closedLoopEventStatus == ClosedLoopEventStatus.ONSET) {
+                LOG.debug("Performing A&AI Enrichment of ONSET Alert: {}", alertMessageString);
+                final ControlLoopSchemaType controlLoopSchemaType =
+                        TCAUtils.determineControlLoopSchemaType(tcavesResponse);
+                final String sourceName = TCAUtils.determineSourceName(tcavesResponse);
+                LOG.debug("A&AI Source Name: {}, Control Loop Schema Type: {} for ONSET Alert: {}",
+                        sourceName, controlLoopSchemaType, alertMessageString);
+
+                if (controlLoopSchemaType == ControlLoopSchemaType.VM) {
+                    final String aaiVMEnrichmentAPIPath = tcaAppPreferences.getAaiVMEnrichmentAPIPath();
+                    TCAUtils.doAAIVMEnrichment(tcavesResponse, aaiEnrichmentClient, aaiVMEnrichmentAPIPath,
+                            alertMessageString, sourceName);
+                } else {
+                    final String aaiVNFEnrichmentAPIPath = tcaAppPreferences.getAaiVNFEnrichmentAPIPath();
+                    TCAUtils.doAAIVNFEnrichment(tcavesResponse, aaiEnrichmentClient, aaiVNFEnrichmentAPIPath,
+                            alertMessageString, sourceName);
+                }
+
+                final String aaiEnrichedAlert = TCAUtils.writeValueAsString(tcavesResponse);
+                LOG.debug("Emitting Alert after A&AI Enrichment: {}", aaiEnrichedAlert);
+                aaiEnrichmentOutputEmitter.emit(aaiEnrichedAlert);
+
+                // skip A&AI Enrichment of alerts with closed Loop Event Status - ABATED
+            } else if (closedLoopEventStatus == ClosedLoopEventStatus.ABATED) {
+                LOG.debug("Skipping Enrichment of Abated Alert: {}", alertMessageString);
+                aaiEnrichmentOutputEmitter.emit(alertMessageString);
+
+            } else {
+                // unsupported closed loop event status
+                final String errorMessage = String.format(
+                        "Unexpected ClosedLoopEventStatus: %s. Only ONSET and ABATED are supported." +
+                                "Ignoring alert: %s", closedLoopEventStatus, alertMessageString);
+                throw new CDAPSettingsException(errorMessage, LOG, new IllegalStateException(errorMessage));
+            }
+        }
+    }
+}