1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package goldengate.ftp.exec.control;
22
23 import goldengate.common.command.ReplyCode;
24 import goldengate.common.command.exception.CommandAbstractException;
25 import goldengate.common.database.DbSession;
26 import goldengate.common.database.data.AbstractDbData.UpdatedInfo;
27 import goldengate.common.database.exception.GoldenGateDatabaseException;
28 import goldengate.common.logging.GgInternalLogger;
29 import goldengate.common.logging.GgInternalLoggerFactory;
30 import goldengate.ftp.core.command.FtpCommandCode;
31 import goldengate.ftp.core.control.BusinessHandler;
32 import goldengate.ftp.core.data.FtpTransfer;
33 import goldengate.ftp.core.exception.FtpNoFileException;
34 import goldengate.ftp.core.session.FtpSession;
35 import goldengate.ftp.exec.config.FileBasedConfiguration;
36 import goldengate.ftp.exec.database.DbConstant;
37 import goldengate.ftp.exec.database.data.DbTransferLog;
38
39
40
41
42
43
44
45 public class GoldenGateActionLogger {
46
47
48
49 private static final GgInternalLogger logger = GgInternalLoggerFactory
50 .getLogger(GoldenGateActionLogger.class);
51
52
53
54
55
56
57
58
59 public static long logCreate(DbSession ftpSession,
60 String message, String file, BusinessHandler handler) {
61 FtpSession session = handler.getFtpSession();
62 String sessionContexte = session.toString();
63 logger.info(message+" "+sessionContexte);
64 if (ftpSession != null) {
65 FtpCommandCode code = session.getCurrentCommand().getCode();
66 if (FtpCommandCode.isStorOrRetrLikeCommand(code)) {
67 boolean isSender =
68 FtpCommandCode.isRetrLikeCommand(code);
69 try {
70
71 DbTransferLog log =
72 new DbTransferLog(ftpSession,
73 session.getAuth().getUser(),
74 session.getAuth().getAccount(),
75 DbConstant.ILLEGALVALUE,
76 isSender, file,
77 code.name(),
78 ReplyCode.REPLY_000_SPECIAL_NOSTATUS, message,
79 UpdatedInfo.TOSUBMIT);
80 logger.debug("Create FS: "+log.toString());
81 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
82 if (isSender) {
83 FileBasedConfiguration.fileBasedConfiguration.monitoring.updateLastOutBand();
84 } else {
85 FileBasedConfiguration.fileBasedConfiguration.monitoring.updateLastInBound();
86 }
87 }
88 return log.getSpecialId();
89 } catch (GoldenGateDatabaseException e1) {
90
91 }
92 }
93 }
94 return DbConstant.ILLEGALVALUE;
95 }
96
97
98
99
100
101
102
103
104
105 public static long logAction(DbSession ftpSession, long specialId,
106 String message, BusinessHandler handler, ReplyCode rcode,
107 UpdatedInfo info) {
108 FtpSession session = handler.getFtpSession();
109 String sessionContexte = session.toString();
110 logger.info(message+" "+sessionContexte);
111 if (ftpSession != null && specialId != DbConstant.ILLEGALVALUE) {
112 FtpCommandCode code = session.getCurrentCommand().getCode();
113 if (FtpCommandCode.isStorOrRetrLikeCommand(code)) {
114 try {
115
116 DbTransferLog log =
117 new DbTransferLog(ftpSession,
118 session.getAuth().getUser(),
119 session.getAuth().getAccount(), specialId);
120 log.changeUpdatedInfo(info);
121 log.setInfotransf(message);
122 log.setReplyCodeExecutionStatus(rcode);
123 log.update();
124 logger.debug("Update FS: "+log.toString());
125 return log.getSpecialId();
126 } catch (GoldenGateDatabaseException e) {
127
128 }
129 } else {
130 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
131 FileBasedConfiguration.fileBasedConfiguration.monitoring.
132 updateCodeNoTransfer(rcode);
133 }
134 }
135 } else {
136 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
137 FileBasedConfiguration.fileBasedConfiguration.monitoring.
138 updateCodeNoTransfer(rcode);
139 }
140 }
141 return specialId;
142 }
143
144
145
146
147
148
149
150
151
152 public static void logErrorAction(DbSession ftpSession, long specialId,
153 FtpTransfer transfer,
154 String message, ReplyCode rcode, BusinessHandler handler) {
155 FtpSession session = handler.getFtpSession();
156 String sessionContexte = session.toString();
157 logger.error(rcode.getCode()+":"+message+" "+sessionContexte);
158 logger.debug("Log",
159 new Exception("Log"));
160 if (ftpSession != null && specialId != DbConstant.ILLEGALVALUE) {
161 FtpCommandCode code = session.getCurrentCommand().getCode();
162 if (FtpCommandCode.isStorOrRetrLikeCommand(code)) {
163 String file = null;
164 if (transfer != null) {
165 try {
166 file = transfer.getFtpFile().getFile();
167 } catch (CommandAbstractException e1) {
168 } catch (FtpNoFileException e1) {
169 }
170 } else {
171 file = null;
172 }
173 UpdatedInfo info = UpdatedInfo.INERROR;
174 try {
175
176 DbTransferLog log =
177 new DbTransferLog(ftpSession,
178 session.getAuth().getUser(),
179 session.getAuth().getAccount(), specialId);
180 log.changeUpdatedInfo(info);
181 log.setInfotransf(message);
182 if (rcode.getCode() < 400) {
183 log.setReplyCodeExecutionStatus(ReplyCode.REPLY_426_CONNECTION_CLOSED_TRANSFER_ABORTED);
184 } else {
185 log.setReplyCodeExecutionStatus(rcode);
186 }
187 if (file != null) {
188 log.setFilename(file);
189 }
190 log.update();
191 if (FileBasedConfiguration.fileBasedConfiguration.ftpMib != null) {
192 FileBasedConfiguration.fileBasedConfiguration.ftpMib.
193 notifyInfoTask(message, log);
194 }
195 logger.debug("Update FS: "+log.toString());
196 } catch (GoldenGateDatabaseException e) {
197
198 }
199 } else {
200 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
201 FileBasedConfiguration.fileBasedConfiguration.monitoring.
202 updateCodeNoTransfer(rcode);
203 }
204 if (rcode != ReplyCode.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN &&
205 rcode != ReplyCode.REPLY_550_REQUESTED_ACTION_NOT_TAKEN) {
206 if (FileBasedConfiguration.fileBasedConfiguration.ftpMib != null) {
207 FileBasedConfiguration.fileBasedConfiguration.ftpMib.
208 notifyWarning(rcode.getMesg(),message);
209 }
210 }
211 }
212 } else {
213 if (FileBasedConfiguration.fileBasedConfiguration.monitoring != null) {
214 FileBasedConfiguration.fileBasedConfiguration.monitoring.
215 updateCodeNoTransfer(rcode);
216 }
217 if (rcode != ReplyCode.REPLY_450_REQUESTED_FILE_ACTION_NOT_TAKEN &&
218 rcode != ReplyCode.REPLY_550_REQUESTED_ACTION_NOT_TAKEN) {
219 if (FileBasedConfiguration.fileBasedConfiguration.ftpMib != null) {
220 FileBasedConfiguration.fileBasedConfiguration.ftpMib.
221 notifyWarning(rcode.getMesg(),message);
222 }
223 }
224 }
225 }
226 }