Add support for ABATED alerts within CDAP TCA
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-common / src / main / java / org / openecomp / dcae / apod / analytics / cdap / common / persistance / tca / TCAAlertsAbatementEntity.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *   You may obtain a copy of the License at
10  *
11  *          http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *  ============================LICENSE_END===========================================
19  */
20
21 package org.openecomp.dcae.apod.analytics.cdap.common.persistance.tca;
22
23 import com.google.common.base.Objects;
24 import org.apache.hadoop.io.Writable;
25 import org.apache.hadoop.io.WritableUtils;
26
27 import java.io.DataInput;
28 import java.io.DataOutput;
29 import java.io.IOException;
30 import java.io.Serializable;
31
32 /**
33  * TCA Alerts Abatement Entity is used to persist information to determine if abatement event need to sent to downstream
34  * systems
35  *
36  *  @author rs153v (Rajiv Singla) . Creation Date: 9/11/2017.
37  */
38 public class TCAAlertsAbatementEntity implements Writable, Serializable {
39
40     private static final long serialVersionUID = 1L;
41
42     private long creationTS;
43     private String requestId;
44     // Kept as string to avoid null checks
45     private String abatementSentTS;
46
47     /**
48      * No Arg constructor required for Jackson Json Serialization / Deserialization
49      */
50     public TCAAlertsAbatementEntity() {
51         // required no arg constructor
52     }
53
54     /**
55      * Creates TCA Alerts Abatement Entity to persist information to determine if abatement alerts need to be posted
56      *
57      * @param creationTS record creation time
58      * @param requestId request ID of generated alert
59      * @param abatementSentTS time when abatement was sent out for that alert if any
60      */
61     public TCAAlertsAbatementEntity(long creationTS, String requestId, String abatementSentTS) {
62         this.creationTS = creationTS;
63         this.requestId = requestId;
64         this.abatementSentTS = abatementSentTS;
65     }
66
67     /**
68      * Timestamp when record was created
69      *
70      * @return timestamp when record was created
71      */
72     public long getCreationTS() {
73         return creationTS;
74     }
75
76     /**
77      * Set value for timestamp when record was created
78      *
79      * @param creationTS new value for timestamp when record was created
80      */
81     public void setCreationTS(long creationTS) {
82         this.creationTS = creationTS;
83     }
84
85     /**
86      * Request Id of ONSET alert which was sent
87      *
88      * @return request Id of ONSET alert which was sent
89      */
90     public String getRequestId() {
91         return requestId;
92     }
93
94     /**
95      * Set Request Id of ONSET alert
96      *
97      * @param requestId set new value for ONSET alert request id
98      */
99     public void setRequestId(String requestId) {
100         this.requestId = requestId;
101     }
102
103
104     /**
105      * Get abatement Sent Timestamp
106      *
107      * @return get abatement alert sent timestamp
108      */
109     public String getAbatementSentTS() {
110         return abatementSentTS;
111     }
112
113     /**
114      * Set timestamp when abatement alert is sent
115      *
116      * @param abatementSentTS sent new value for timestamp when abatement alert is sent
117      */
118     public void setAbatementSentTS(String abatementSentTS) {
119         this.abatementSentTS = abatementSentTS;
120     }
121
122     /**
123      * Write entity to Table
124      *
125      * @param dataOutput data output
126      * @throws IOException io exception
127      */
128     @Override
129     public void write(DataOutput dataOutput) throws IOException {
130         WritableUtils.writeVLong(dataOutput, creationTS);
131         WritableUtils.writeString(dataOutput, requestId);
132         WritableUtils.writeString(dataOutput, abatementSentTS);
133     }
134
135     /**
136      * Read entity from table
137      *
138      * @param dataInput data input
139      * @throws IOException io exception
140      */
141     @Override
142     public void readFields(DataInput dataInput) throws IOException {
143         creationTS = WritableUtils.readVLong(dataInput);
144         requestId = WritableUtils.readString(dataInput);
145         abatementSentTS = WritableUtils.readString(dataInput);
146     }
147
148
149     @Override
150     public String toString() {
151         return Objects.toStringHelper(this)
152                 .add("creationTS", creationTS)
153                 .add("requestId", requestId)
154                 .add("abatementSentTS", abatementSentTS)
155                 .toString();
156     }
157 }