...
|
...
|
@@ -7,6 +7,7 @@ import org.apache.hadoop.conf.Configuration; |
|
|
import org.apache.hadoop.fs.Path;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.DisposableBean;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.hadoop.config.common.annotation.EnableAnnotationConfiguration;
|
|
|
import org.springframework.data.hadoop.store.output.TextFileWriter;
|
...
|
...
|
@@ -20,14 +21,17 @@ import java.io.IOException; |
|
|
*/
|
|
|
@Component
|
|
|
@EnableAnnotationConfiguration
|
|
|
public class ClientReportCosn {
|
|
|
public class ClientReportCosn implements DisposableBean {
|
|
|
private static Logger logger = LoggerFactory.getLogger(ClientReportCosn.class);
|
|
|
private static final String COSN_FILE_PREFIX = "app_error_";
|
|
|
private static final String DEFAULT_CONS_PATH = "cosn://applogs/";
|
|
|
// private static final String DEFAULT_CONS_PATH = "/usr/applogs/";
|
|
|
private ConsFileWriter fileWriter = null;
|
|
|
@Autowired
|
|
|
private Configuration configuration;
|
|
|
|
|
|
|
|
|
|
|
|
public void write(ClientReportErrorModel model) {
|
|
|
TextFileWriter writer = getTextFileWriter(model);
|
|
|
if (writer == null) {
|
...
|
...
|
@@ -38,6 +42,13 @@ public class ClientReportCosn { |
|
|
writer.flush();
|
|
|
} catch (IOException ex) {
|
|
|
logger.error("writer to cons failed : {}", ex);
|
|
|
if (writer != null) {
|
|
|
try {
|
|
|
writer.close();
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -54,7 +65,7 @@ public class ClientReportCosn { |
|
|
}
|
|
|
if (fileWriter == null) {
|
|
|
TextFileWriter writer = new TextFileWriter(configuration,
|
|
|
getPath(getFileName(dateId)), null, "|".getBytes());
|
|
|
getPath(getFileName(dateId)), null, "\n".getBytes());
|
|
|
writer.setAppendable(true);
|
|
|
fileWriter = new ConsFileWriter(getFileName(dateId), dateId, writer);
|
|
|
return fileWriter.getWriter();
|
...
|
...
|
@@ -64,7 +75,7 @@ public class ClientReportCosn { |
|
|
} else {
|
|
|
fileWriter.close();
|
|
|
TextFileWriter writer = new TextFileWriter(configuration,
|
|
|
getPath(getFileName(dateId)), null, "|".getBytes());
|
|
|
getPath(getFileName(dateId)), null, "\n".getBytes());
|
|
|
writer.setAppendable(true);
|
|
|
fileWriter.setWriter(writer);
|
|
|
return writer;
|
...
|
...
|
@@ -114,4 +125,11 @@ public class ClientReportCosn { |
|
|
+ model.getExceptionType() + '|'
|
|
|
+ model.getUdid();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void destroy() throws Exception {
|
|
|
if (fileWriter != null) {
|
|
|
fileWriter.close();
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|