1048b156
Suraputt Suntimitr
Template
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
|
package th.co.ais.ssbsrfc.message;
import java.util.ArrayList;
import th.co.ais.ssbsrfc.config.Constant;
import th.co.ais.ssbsrfc.config.Invoke;
import th.co.ais.ssbsrfc.config.StateConfig;
import th.co.ais.ssbsrfc.instance.EC02Instance;
import th.co.ais.ssbsrfc.instance.EQXRawInstance;
import th.co.ais.ssbsrfc.instance.Response;
import th.co.ais.ssbsrfc.instance.Stat;
import th.co.ais.ssbsrfc.interfaces.Atomic;
import th.co.ais.ssbsrfc.interfaces.EQXMsg;
import th.co.ais.ssbsrfc.utils.EqxStringUtils;
import th.co.ais.ssbsrfc.utils.Global;
import th.co.ais.ssbsrfc.utils.Log;
import ais.mmt.sand.comlog.DetailsLogPrototype;
import ais.mmt.sand.comlog.bean.DataBean;
import ais.mmt.sand.comlog.bean.DataBean.TYPE;
import ais.mmt.sand.comlog.exception.CommonLogException;
import ec02.af.abstracts.AbstractAF;
import ec02.af.data.EquinoxRawData;
import ec02.af.data.KeyObject;
import ec02.utils.AppLog;
public class EC02Builder {
private EC02Instance ec02Ins = null;
private AbstractAF abstractAF = null;
private EquinoxRawData eqxRawData =null;
private EC02MSGBuilder msgBuilder = null;
public void setEquinoxRawData(AbstractAF abstractAF, EC02Instance ec02Ins){
this.abstractAF = abstractAF;
this.ec02Ins = ec02Ins;
}
public void setEquinoxRawData(EquinoxRawData eqxRawData, AbstractAF abstractAF, EC02Instance ec02Ins){
this.eqxRawData = eqxRawData;
this.abstractAF = abstractAF;
this.ec02Ins = ec02Ins;
}
public ArrayList<EquinoxRawData> getHTTPRequest(ArrayList<EQXRawInstance> eqxRawList){
ArrayList<EquinoxRawData> eqxRawDataList = new ArrayList<EquinoxRawData>();
String timeout = null;
for (int i = 0; i < eqxRawList.size(); i++) {
String type = eqxRawList.get(i).getType();
if (type == null) {
eqxRawList.get(i).setType(EQXMsg.REQUEST);
}
this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i));
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i);
timeout = eqxRawList.get(i).getTimeout();
EquinoxRawData rowData = this.msgBuilder.getHttpMessage();
this.logDetailOutput(rowData, eqxRawList.get(i).getDataOutput(), eqxRawList.get(i).getNodeTo(), eqxRawList.get(i).getCommand());
eqxRawDataList.add(rowData);
}
if (timeout != null) {
this.ec02Ins.setTimeout(timeout);
}
this.ec02Ins.getAFInstance().getListStat().add(new Stat(StateConfig.PROJECT_STAT_NAME + " Send Total Armed Event"));
return eqxRawDataList;
}
public EquinoxRawData getRequest(EQXRawInstance eqxRaw) {
String type = eqxRaw.getType();
if (type == null) {
eqxRaw.setType(EQXMsg.REQUEST);
}
this.msgBuilder = new EC02MSGBuilder(eqxRaw);
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke());
String timeout = eqxRaw.getTimeout();
if (timeout != null) {
this.ec02Ins.setTimeout(timeout);
}
EquinoxRawData rowData = this.msgBuilder.getHttpMessage();
this.logDetailOutput(rowData, eqxRaw.getDataOutput(), eqxRaw.getNodeTo(), eqxRaw.getCommand());
return rowData;
}
public EquinoxRawData getRequestJobTracking(EQXRawInstance eqxRaw) {
String type = eqxRaw.getType();
if (type == null) {
eqxRaw.setType(EQXMsg.REQUEST);
}
this.msgBuilder = new EC02MSGBuilder(eqxRaw);
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke());
String timeout = eqxRaw.getTimeout();
if (timeout != null) {
this.ec02Ins.setTimeout(timeout);
}
// set orig/invoke
String key = eqxRaw.getInvoke();
String orig = "";
String invoke = "";
if (this.eqxRawData != null) {
orig = this.eqxRawData.getRawDataAttribute(EQXMsg.ORIG);
invoke = this.eqxRawData.getInvoke();
} else {
orig = this.ec02Ins.getAFInstance().getOrig();
invoke = this.ec02Ins.getAFInstance().getInvoke();
}
if (!(new Invoke(key).eventType).equals(EQXMsg.UNKNOWN)) {
Response res = new Response (orig, invoke) ;
this.ec02Ins.getAFInstance().setListOrigKey(key, res);
// AppLog.d("## RESPONSE[MG]: " + orig + "/" + invoke);
}
EquinoxRawData rowData = this.msgBuilder.getHttpMessage();
this.logDetailOutput(rowData, eqxRaw.getDataOutput(), eqxRaw.getNodeTo(), eqxRaw.getCommand());
return rowData;
}
public EquinoxRawData getHTTPResponse(EQXRawInstance eqxRaw){
eqxRaw.setType(EQXMsg.RESPONSE);
this.msgBuilder = new EC02MSGBuilder(eqxRaw);
String invoke = (eqxRaw.getInvoke() == null) ? this.ec02Ins.getAFInstance().getInvoke() : eqxRaw.getInvoke();
if (invoke != null && !invoke.equals("")) {
this.msgBuilder.setInvoke(invoke);
}
EquinoxRawData rowData = this.msgBuilder.getHttpMessage();
this.logDetailOutput(rowData, eqxRaw.getDataOutput(), eqxRaw.getNodeTo(), eqxRaw.getCommand());
String subState = (eqxRaw.getSubState() == null) ? "" : eqxRaw.getSubState();
if (!subState.equals("")) {
rowData.getRawDataAttributes().put("subState", subState);
}
String timeout = eqxRaw.getTimeout();
if (timeout != null) {
this.ec02Ins.setTimeout(timeout);
}
return this.msgBuilder.getHttpMessage();
}
/*public ArrayList<EquinoxRawData> getLDAPRequest(ArrayList<EQXRawInstance> eqxRawList){
ArrayList<EquinoxRawData> eqxRawDataList = new ArrayList<EquinoxRawData>();
for (int i = 0; i < eqxRawList.size(); i++) {
eqxRawList.get(i).setType(EQXMsg.REQUEST);
this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i));
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i);
eqxRawDataList.add(this.msgBuilder.getLdapMessage());
}
String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("LDAP-timeout").get(0);
String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf;
this.ec02Ins.setTimeout(timeout);
return eqxRawDataList;
}
public EquinoxRawData getLDAPResponse(EQXRawInstance eqxRaw){
eqxRaw.setType(EQXMsg.RESPONSE);
this.msgBuilder = new EC02MSGBuilder(eqxRaw);
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke());
return this.msgBuilder.getLdapMessage();
}
public ArrayList<EquinoxRawData> getSMPPRequest(ArrayList<EQXRawInstance> eqxRawList){
ArrayList<EquinoxRawData> eqxRawDataList = new ArrayList<EquinoxRawData>();
for (int i = 0; i < eqxRawList.size(); i++) {
eqxRawList.get(i).setType(EQXMsg.REQUEST);
this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i));
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i);
eqxRawDataList.add(this.msgBuilder.getSMPPMessage());
}
String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("SMPP-timeout").get(0);
String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf;
this.ec02Ins.setTimeout(timeout);
return eqxRawDataList;
}
public EquinoxRawData getSMPPResponse(EQXRawInstance eqxRaw){
eqxRaw.setType(EQXMsg.RESPONSE);
this.msgBuilder = new EC02MSGBuilder(eqxRaw);
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke());
return this.msgBuilder.getSMPPMessage();
}*/
public ArrayList<EquinoxRawData> getDiameterRequest(ArrayList<EQXRawInstance> eqxRawList){
ArrayList<EquinoxRawData> eqxRawDataList = new ArrayList<EquinoxRawData>();
for (int i = 0; i < eqxRawList.size(); i++) {
eqxRawList.get(i).setType(EQXMsg.REQUEST);
this.msgBuilder = new EC02MSGBuilder(eqxRawList.get(i));
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke() + i);
eqxRawDataList.add(this.msgBuilder.getDiameterMessage());
}
String timeoutConf = this.abstractAF.getUtils().getHmWarmConfig().get("Diameter-timeout").get(0);
String timeout = (timeoutConf == null) ? this.ec02Ins.getAbstractAF().getUtils().getHmWarmConfig().get("Default-timeout").get(0) : timeoutConf;
this.ec02Ins.setTimeout(timeout);
return eqxRawDataList;
}
public EquinoxRawData getDiameterResponse(EQXRawInstance eqxRaw){
eqxRaw.setType(EQXMsg.RESPONSE);
this.msgBuilder = new EC02MSGBuilder(eqxRaw);
this.msgBuilder.setInvoke(this.ec02Ins.getAFInstance().getInvoke());
return this.msgBuilder.getDiameterMessage();
}
public void getE01Request() {
this.getE01Request(false);
}
public void getE01Request(boolean bool) {
String serviceName = this.ec02Ins.getE01Ins().getServiceName();
if (serviceName == null) {
serviceName = this.abstractAF.getUtils().getHmWarmConfig().get("Resource-Name-E01").get(0).trim();
}
this.abstractAF.getUtils().getGlobalData().configService(serviceName);
KeyObject keyobj = new KeyObject();
keyobj.setObjectType(this.ec02Ins.getE01Ins().getObjType());
ArrayList<String> keyList = this.ec02Ins.getE01Ins().getKey();
// for (int i = 0; i < keyList.size(); i++) {
// AppLog.d("## key " + i + " " + keyList.get(i));
// keyobj.setKey(String.valueOf(i), keyList.get(i));
// }
String[] stringArray = keyList.toArray(new String[keyList.size()]);
for (int i = 0; i < stringArray.length; i++) {
AppLog.d("## key " + i + " " + stringArray[i]);
}
AppLog.d("## keyObj :" + stringArray.length);
if(this.ec02Ins.getE01Ins().getCmd().equals("search")){
// this.abstractAF.getUtils().getGlobalData().search(keyobj, this.ec02Ins.getE01Ins().getId());
this.abstractAF.getUtils().getGlobalData().search(this.ec02Ins.getE01Ins().getObjType(), stringArray, this.ec02Ins.getE01Ins().getId());
}
else if(this.ec02Ins.getE01Ins().getCmd().equals("delete")){
this.abstractAF.getUtils().getGlobalData().delete(keyobj, this.ec02Ins.getE01Ins().getId());
}
else if(this.ec02Ins.getE01Ins().getCmd().equals("add")){
this.abstractAF.getUtils().getGlobalData().add(keyobj, this.ec02Ins.getE01Ins().getData(), this.ec02Ins.getE01Ins().getId());
}
else if(this.ec02Ins.getE01Ins().getCmd().equals("replace")){
this.abstractAF.getUtils().getGlobalData().replace(keyobj, this.ec02Ins.getE01Ins().getData(), this.ec02Ins.getE01Ins().getId());
}
this.abstractAF.getUtils().getGlobalData().setTransactionId(this.ec02Ins.getE01Ins().getInvoke());
// timeout
String timeout = this.ec02Ins.getE01Ins().getTimeout();
if (timeout != null) {
this.ec02Ins.setTimeout(timeout);
}
if (bool) {
String objType = this.ec02Ins.getE01Ins().getObjType();
this.ec02Ins.getAFInstance().getListStat().add(new Stat(this.ec02Ins.getAFInstance().getCurrentState(), Constant.TYPE_SEND, Constant.TYPE_REQUEST, Constant.TYPE_SUCCESS, objType));
} else {
this.ec02Ins.getAFInstance().getListStat().add(new Stat(this.ec02Ins.getAFInstance().getCurrentState(), Constant.TYPE_SEND, Constant.TYPE_REQUEST));
}
}
public void getE01AtomicRequest()
{
String command = this.ec02Ins.getAtomic().getCommand();
String atomicName = this.ec02Ins.getAtomic().getName();
if (command.equals(Atomic.command_get)) {
this.abstractAF.getUtils().getGlobalData().get(atomicName);
} else if(command.equals(Atomic.command_increase)) {
long atomicValue = this.ec02Ins.getAtomic().getValue();
this.abstractAF.getUtils().getGlobalData().increase(atomicName, atomicValue, this.ec02Ins.getAtomic().getMin(), this.ec02Ins.getAtomic().getMax());
} else if(command.equals(Atomic.command_clear)) {
this.abstractAF.getUtils().getGlobalData().clear(atomicName);
}
this.abstractAF.getUtils().getGlobalData().setTransactionId(this.ec02Ins.getE01Ins().getInvoke());
this.ec02Ins.getAFInstance().getListStat().add(new Stat(this.ec02Ins.getAFInstance().getCurrentState(), Constant.TYPE_SEND, Constant.TYPE_REQUEST));
// timeout
String timeout = this.ec02Ins.getE01Ins().getTimeout();
if (timeout != null) {
this.ec02Ins.setTimeout(timeout);
}
}
public EquinoxRawData getUpdateIns(){
this.msgBuilder = new EC02MSGBuilder();
this.ec02Ins.setTimeout(this.abstractAF.getUtils().getHmWarmConfig().get("Update-Instance-timeout").get(0));
return this.msgBuilder.getUpdateIns();
}
private void logDetailOutput(EquinoxRawData equinoxRawData, Object data, String nodeTo, String command)
{
if (Log.debug) {
AppLog.d("## LOGDETAIL_OUTPUT NODETO:" + nodeTo + " command:" + command);
}
// Log Detail Output
if (data != null) {
String currentState = "";
String cmd = (command == null ) ? StateConfig.getCommandFromState(currentState) : command;
if (nodeTo == null && currentState != null) {
String eventType = StateConfig.getEventTypeFromSubState(currentState);
nodeTo = Global.getNodeFromEventType(eventType);
}
String invoke = equinoxRawData.getInvoke();
String type = equinoxRawData.getRawDataAttribute("type");
String rawData = EqxStringUtils.getMessage(equinoxRawData, null, false);
DetailsLogPrototype detLog = this.ec02Ins.getAFInstance().getDetaillog();
DataBean output = new DataBean();
output.setInvoke(invoke);
output.setDirector(nodeTo);
output.setCommandName(cmd);
if(type.equals("response")) {
output.setType(TYPE.RES);
} else {
output.setType(TYPE.REQ);
}
output.setJsonData(MessageParser.toJsonObject(data));
output.setRawData(Global.getDetailLogRawData(rawData));
try {
detLog.addOutput(output);
} catch (CommonLogException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
|