use of io.cdap.cdap.logging.clean.LogCleaner in project cdap by caskdata.
the class CDAPLogAppender method start.
@Override
public void start() {
// These should all passed. The settings are from the cdap-log-pipeline.xml and the context must be AppenderContext
Preconditions.checkState(dirPermissions != null, "Property dirPermissions cannot be null");
Preconditions.checkState(filePermissions != null, "Property filePermissions cannot be null");
Preconditions.checkState(syncIntervalBytes > 0, "Property syncIntervalBytes must be > 0.");
Preconditions.checkState(maxFileLifetimeMs > 0, "Property maxFileLifetimeMs must be > 0");
Preconditions.checkState(maxFileSizeInBytes > 0, "Property maxFileSizeInBytes must be > 0");
Preconditions.checkState(fileRetentionDurationDays > 0, "Property fileRetentionDurationDays must be > 0");
Preconditions.checkState(logCleanupIntervalMins > 0, "Property logCleanupIntervalMins must be > 0");
Preconditions.checkState(fileCleanupBatchSize > 0, "Property fileCleanupBatchSize must be > 0");
if (context instanceof AppenderContext) {
AppenderContext context = (AppenderContext) this.context;
logFileManager = new LogFileManager(dirPermissions, filePermissions, maxFileLifetimeMs, maxFileSizeInBytes, syncIntervalBytes, new FileMetaDataWriter(context.getTransactionRunner()), context.getLocationFactory());
if (context.getInstanceId() == 0) {
scheduledExecutorService = Executors.newSingleThreadScheduledExecutor(Threads.createDaemonThreadFactory("log-clean-up"));
FileMetadataCleaner fileMetadataCleaner = new FileMetadataCleaner(context.getTransactionRunner());
LogCleaner logCleaner = new LogCleaner(fileMetadataCleaner, context.getLocationFactory(), TimeUnit.DAYS.toMillis(fileRetentionDurationDays), fileCleanupBatchSize);
scheduledExecutorService.scheduleAtFixedRate(logCleaner, 10, logCleanupIntervalMins, TimeUnit.MINUTES);
}
} else if (!Boolean.TRUE.equals(context.getObject(Constants.Logging.PIPELINE_VALIDATION))) {
throw new IllegalStateException("Expected logger context instance of " + AppenderContext.class.getName() + " but get " + context.getClass().getName());
}
super.start();
}
Aggregations