-/*\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.common.persistance.tca;\r
-\r
-import co.cask.cdap.api.data.schema.Schema;\r
-import co.cask.cdap.api.data.schema.UnsupportedTypeException;\r
-import co.cask.cdap.api.dataset.DatasetProperties;\r
-import co.cask.cdap.api.dataset.lib.IndexedTable;\r
-import co.cask.cdap.api.dataset.lib.ObjectMappedTable;\r
-import co.cask.cdap.api.dataset.lib.ObjectMappedTableProperties;\r
-import com.google.common.base.Joiner;\r
-import com.google.common.collect.ImmutableList;\r
-import org.openecomp.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;\r
-import org.openecomp.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;\r
-import org.openecomp.dcae.apod.analytics.common.utils.PersistenceUtils;\r
-import org.openecomp.dcae.apod.analytics.model.domain.cef.EventListener;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;\r
-import org.openecomp.dcae.apod.analytics.model.domain.policy.tca.Threshold;\r
-import org.openecomp.dcae.apod.analytics.model.facade.tca.TCAVESResponse;\r
-import org.slf4j.Logger;\r
-import org.slf4j.LoggerFactory;\r
-\r
-import java.util.Date;\r
-import java.util.List;\r
-\r
-import static org.openecomp.dcae.apod.analytics.common.utils.PersistenceUtils.TABLE_ROW_KEY_COLUMN_NAME;\r
-\r
-/**\r
- * Utility methods to persist TCA Alerts Abatement information\r
- *\r
- * @author Rajiv Singla . Creation Date: 9/11/2017.\r
- */\r
-public abstract class TCAAlertsAbatementPersister {\r
-\r
- private static final Logger LOG = LoggerFactory.getLogger(TCAAlertsAbatementPersister.class);\r
-\r
- private static final Joiner KEY_JOINER = Joiner.on(PersistenceUtils.ROW_KEY_DELIMITER);\r
-\r
- private TCAAlertsAbatementPersister() {\r
- // private constructor\r
- }\r
-\r
- /**\r
- * Creates {@link DatasetProperties} for Alerts Table\r
- *\r
- * @param timeToLiveSeconds alerts table Time to Live\r
- *\r
- * @return Alerts Abatement table properties\r
- */\r
- public static DatasetProperties getDatasetProperties(final int timeToLiveSeconds) {\r
- try {\r
- return ObjectMappedTableProperties.builder()\r
- .setType(TCAAlertsAbatementEntity.class)\r
- .setRowKeyExploreName(TABLE_ROW_KEY_COLUMN_NAME)\r
- .setRowKeyExploreType(Schema.Type.STRING)\r
- .add(IndexedTable.PROPERTY_TTL, timeToLiveSeconds)\r
- .setDescription(CDAPComponentsConstants.TCA_FIXED_ALERTS_ABATEMENT_DESCRIPTION_TABLE)\r
- .build();\r
- } catch (UnsupportedTypeException e) {\r
- final String errorMessage = "Unable to convert TCAAlertsAbatementEntity class to Schema";\r
- throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e);\r
- }\r
- }\r
-\r
-\r
- public static void persist(final EventListener eventListener,\r
- final MetricsPerEventName violatedMetricsPerEventName,\r
- final TCAVESResponse tcavesResponse,\r
- final String abatementTS,\r
- final ObjectMappedTable<TCAAlertsAbatementEntity> tcaAlertsAbatementTable) {\r
- final String abatementTableKey = createKey(eventListener, violatedMetricsPerEventName);\r
-\r
- final long currentTimestamp = new Date().getTime();\r
- final String requestID = tcavesResponse.getRequestID();\r
- final TCAAlertsAbatementEntity tcaAlertsAbatementEntity = new TCAAlertsAbatementEntity(currentTimestamp,\r
- requestID, abatementTS);\r
- tcaAlertsAbatementTable.write(abatementTableKey, tcaAlertsAbatementEntity);\r
-\r
- LOG.debug("Persisted AlertsAbatementEntity: {} with Key: {}", tcaAlertsAbatementEntity, abatementTableKey);\r
-\r
- }\r
-\r
- public static TCAAlertsAbatementEntity lookUpByKey(final EventListener eventListener,\r
- final MetricsPerEventName violatedMetricsPerEventName,\r
- final ObjectMappedTable<TCAAlertsAbatementEntity>\r
- tcaAlertsAbatementTable) {\r
- final String abatementTableKey = createKey(eventListener, violatedMetricsPerEventName);\r
- return tcaAlertsAbatementTable.read(abatementTableKey);\r
- }\r
-\r
-\r
- public static String createKey(final EventListener eventListener,\r
- final MetricsPerEventName violatedMetricsPerEventName) {\r
- // no null check required as all are required fields\r
- final String eventName = violatedMetricsPerEventName.getEventName();\r
- final String sourceName = eventListener.getEvent().getCommonEventHeader().getSourceName();\r
- final String reportingEntityName = eventListener.getEvent().getCommonEventHeader().getReportingEntityName();\r
- // violated threshold will always be present\r
- final Threshold violatedThreshold = violatedMetricsPerEventName.getThresholds().get(0);\r
- final String closedLoopControlName = violatedThreshold.getClosedLoopControlName();\r
- final String fieldPath = violatedThreshold.getFieldPath();\r
-\r
- final List<String> abatementKeyList =\r
- ImmutableList.of(eventName, sourceName, reportingEntityName, closedLoopControlName, fieldPath);\r
-\r
- return KEY_JOINER.join(abatementKeyList);\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.common.persistance.tca;
+
+import co.cask.cdap.api.data.schema.Schema;
+import co.cask.cdap.api.data.schema.UnsupportedTypeException;
+import co.cask.cdap.api.dataset.DatasetProperties;
+import co.cask.cdap.api.dataset.lib.IndexedTable;
+import co.cask.cdap.api.dataset.lib.ObjectMappedTable;
+import co.cask.cdap.api.dataset.lib.ObjectMappedTableProperties;
+import com.google.common.base.Joiner;
+import com.google.common.collect.ImmutableList;
+import org.onap.dcae.apod.analytics.cdap.common.CDAPComponentsConstants;
+import org.onap.dcae.apod.analytics.common.exception.DCAEAnalyticsRuntimeException;
+import org.onap.dcae.apod.analytics.common.utils.PersistenceUtils;
+import org.onap.dcae.apod.analytics.model.domain.cef.EventListener;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.MetricsPerEventName;
+import org.onap.dcae.apod.analytics.model.domain.policy.tca.Threshold;
+import org.onap.dcae.apod.analytics.model.facade.tca.TCAVESResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Date;
+import java.util.List;
+
+import static org.onap.dcae.apod.analytics.common.utils.PersistenceUtils.TABLE_ROW_KEY_COLUMN_NAME;
+
+/**
+ * Utility methods to persist TCA Alerts Abatement information
+ *
+ * @author Rajiv Singla . Creation Date: 9/11/2017.
+ */
+public abstract class TCAAlertsAbatementPersister {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TCAAlertsAbatementPersister.class);
+
+ private static final Joiner KEY_JOINER = Joiner.on(PersistenceUtils.ROW_KEY_DELIMITER);
+
+ private TCAAlertsAbatementPersister() {
+ // private constructor
+ }
+
+ /**
+ * Creates {@link DatasetProperties} for Alerts Table
+ *
+ * @param timeToLiveSeconds alerts table Time to Live
+ *
+ * @return Alerts Abatement table properties
+ */
+ public static DatasetProperties getDatasetProperties(final int timeToLiveSeconds) {
+ try {
+ return ObjectMappedTableProperties.builder()
+ .setType(TCAAlertsAbatementEntity.class)
+ .setRowKeyExploreName(TABLE_ROW_KEY_COLUMN_NAME)
+ .setRowKeyExploreType(Schema.Type.STRING)
+ .add(IndexedTable.PROPERTY_TTL, timeToLiveSeconds)
+ .setDescription(CDAPComponentsConstants.TCA_FIXED_ALERTS_ABATEMENT_DESCRIPTION_TABLE)
+ .build();
+ } catch (UnsupportedTypeException e) {
+ final String errorMessage = "Unable to convert TCAAlertsAbatementEntity class to Schema";
+ throw new DCAEAnalyticsRuntimeException(errorMessage, LOG, e);
+ }
+ }
+
+
+ public static void persist(final EventListener eventListener,
+ final MetricsPerEventName violatedMetricsPerEventName,
+ final TCAVESResponse tcavesResponse,
+ final String abatementTS,
+ final ObjectMappedTable<TCAAlertsAbatementEntity> tcaAlertsAbatementTable) {
+ final String abatementTableKey = createKey(eventListener, violatedMetricsPerEventName);
+
+ final long currentTimestamp = new Date().getTime();
+ final String requestID = tcavesResponse.getRequestID();
+ final TCAAlertsAbatementEntity tcaAlertsAbatementEntity = new TCAAlertsAbatementEntity(currentTimestamp,
+ requestID, abatementTS);
+ tcaAlertsAbatementTable.write(abatementTableKey, tcaAlertsAbatementEntity);
+
+ LOG.debug("Persisted AlertsAbatementEntity: {} with Key: {}", tcaAlertsAbatementEntity, abatementTableKey);
+
+ }
+
+ public static TCAAlertsAbatementEntity lookUpByKey(final EventListener eventListener,
+ final MetricsPerEventName violatedMetricsPerEventName,
+ final ObjectMappedTable<TCAAlertsAbatementEntity>
+ tcaAlertsAbatementTable) {
+ final String abatementTableKey = createKey(eventListener, violatedMetricsPerEventName);
+ return tcaAlertsAbatementTable.read(abatementTableKey);
+ }
+
+
+ public static String createKey(final EventListener eventListener,
+ final MetricsPerEventName violatedMetricsPerEventName) {
+ // no null check required as all are required fields
+ final String eventName = violatedMetricsPerEventName.getEventName();
+ final String sourceName = eventListener.getEvent().getCommonEventHeader().getSourceName();
+ final String reportingEntityName = eventListener.getEvent().getCommonEventHeader().getReportingEntityName();
+ // violated threshold will always be present
+ final Threshold violatedThreshold = violatedMetricsPerEventName.getThresholds().get(0);
+ final String closedLoopControlName = violatedThreshold.getClosedLoopControlName();
+ final String fieldPath = violatedThreshold.getFieldPath();
+
+ final List<String> abatementKeyList =
+ ImmutableList.of(eventName, sourceName, reportingEntityName, closedLoopControlName, fieldPath);
+
+ return KEY_JOINER.join(abatementKeyList);
+ }
+
+}