|
@@ -7,6 +7,7 @@ import org.apache.hadoop.conf.Configuration; |
|
@@ -7,6 +7,7 @@ import org.apache.hadoop.conf.Configuration; |
7
|
import org.apache.hadoop.fs.Path;
|
7
|
import org.apache.hadoop.fs.Path;
|
8
|
import org.slf4j.Logger;
|
8
|
import org.slf4j.Logger;
|
9
|
import org.slf4j.LoggerFactory;
|
9
|
import org.slf4j.LoggerFactory;
|
|
|
10
|
+import org.springframework.beans.factory.DisposableBean;
|
10
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.beans.factory.annotation.Autowired;
|
11
|
import org.springframework.data.hadoop.config.common.annotation.EnableAnnotationConfiguration;
|
12
|
import org.springframework.data.hadoop.config.common.annotation.EnableAnnotationConfiguration;
|
12
|
import org.springframework.data.hadoop.store.output.TextFileWriter;
|
13
|
import org.springframework.data.hadoop.store.output.TextFileWriter;
|
|
@@ -20,14 +21,17 @@ import java.io.IOException; |
|
@@ -20,14 +21,17 @@ import java.io.IOException; |
20
|
*/
|
21
|
*/
|
21
|
@Component
|
22
|
@Component
|
22
|
@EnableAnnotationConfiguration
|
23
|
@EnableAnnotationConfiguration
|
23
|
-public class ClientReportCosn {
|
24
|
+public class ClientReportCosn implements DisposableBean {
|
24
|
private static Logger logger = LoggerFactory.getLogger(ClientReportCosn.class);
|
25
|
private static Logger logger = LoggerFactory.getLogger(ClientReportCosn.class);
|
25
|
private static final String COSN_FILE_PREFIX = "app_error_";
|
26
|
private static final String COSN_FILE_PREFIX = "app_error_";
|
26
|
private static final String DEFAULT_CONS_PATH = "cosn://applogs/";
|
27
|
private static final String DEFAULT_CONS_PATH = "cosn://applogs/";
|
|
|
28
|
+// private static final String DEFAULT_CONS_PATH = "/usr/applogs/";
|
27
|
private ConsFileWriter fileWriter = null;
|
29
|
private ConsFileWriter fileWriter = null;
|
28
|
@Autowired
|
30
|
@Autowired
|
29
|
private Configuration configuration;
|
31
|
private Configuration configuration;
|
30
|
|
32
|
|
|
|
33
|
+
|
|
|
34
|
+
|
31
|
public void write(ClientReportErrorModel model) {
|
35
|
public void write(ClientReportErrorModel model) {
|
32
|
TextFileWriter writer = getTextFileWriter(model);
|
36
|
TextFileWriter writer = getTextFileWriter(model);
|
33
|
if (writer == null) {
|
37
|
if (writer == null) {
|
|
@@ -38,6 +42,13 @@ public class ClientReportCosn { |
|
@@ -38,6 +42,13 @@ public class ClientReportCosn { |
38
|
writer.flush();
|
42
|
writer.flush();
|
39
|
} catch (IOException ex) {
|
43
|
} catch (IOException ex) {
|
40
|
logger.error("writer to cons failed : {}", ex);
|
44
|
logger.error("writer to cons failed : {}", ex);
|
|
|
45
|
+ if (writer != null) {
|
|
|
46
|
+ try {
|
|
|
47
|
+ writer.close();
|
|
|
48
|
+ } catch (IOException e) {
|
|
|
49
|
+
|
|
|
50
|
+ }
|
|
|
51
|
+ }
|
41
|
}
|
52
|
}
|
42
|
}
|
53
|
}
|
43
|
|
54
|
|
|
@@ -54,7 +65,7 @@ public class ClientReportCosn { |
|
@@ -54,7 +65,7 @@ public class ClientReportCosn { |
54
|
}
|
65
|
}
|
55
|
if (fileWriter == null) {
|
66
|
if (fileWriter == null) {
|
56
|
TextFileWriter writer = new TextFileWriter(configuration,
|
67
|
TextFileWriter writer = new TextFileWriter(configuration,
|
57
|
- getPath(getFileName(dateId)), null, "|".getBytes());
|
68
|
+ getPath(getFileName(dateId)), null, "\n".getBytes());
|
58
|
writer.setAppendable(true);
|
69
|
writer.setAppendable(true);
|
59
|
fileWriter = new ConsFileWriter(getFileName(dateId), dateId, writer);
|
70
|
fileWriter = new ConsFileWriter(getFileName(dateId), dateId, writer);
|
60
|
return fileWriter.getWriter();
|
71
|
return fileWriter.getWriter();
|
|
@@ -64,7 +75,7 @@ public class ClientReportCosn { |
|
@@ -64,7 +75,7 @@ public class ClientReportCosn { |
64
|
} else {
|
75
|
} else {
|
65
|
fileWriter.close();
|
76
|
fileWriter.close();
|
66
|
TextFileWriter writer = new TextFileWriter(configuration,
|
77
|
TextFileWriter writer = new TextFileWriter(configuration,
|
67
|
- getPath(getFileName(dateId)), null, "|".getBytes());
|
78
|
+ getPath(getFileName(dateId)), null, "\n".getBytes());
|
68
|
writer.setAppendable(true);
|
79
|
writer.setAppendable(true);
|
69
|
fileWriter.setWriter(writer);
|
80
|
fileWriter.setWriter(writer);
|
70
|
return writer;
|
81
|
return writer;
|
|
@@ -114,4 +125,11 @@ public class ClientReportCosn { |
|
@@ -114,4 +125,11 @@ public class ClientReportCosn { |
114
|
+ model.getExceptionType() + '|'
|
125
|
+ model.getExceptionType() + '|'
|
115
|
+ model.getUdid();
|
126
|
+ model.getUdid();
|
116
|
}
|
127
|
}
|
|
|
128
|
+
|
|
|
129
|
+ @Override
|
|
|
130
|
+ public void destroy() throws Exception {
|
|
|
131
|
+ if (fileWriter != null) {
|
|
|
132
|
+ fileWriter.close();
|
|
|
133
|
+ }
|
|
|
134
|
+ }
|
117
|
} |
135
|
} |