001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2006-2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.loggers; 028 029 import java.util.ArrayList; 030 031 import org.opends.server.api.DirectoryThread; 032 import org.opends.server.config.ConfigEntry; 033 034 import static org.opends.server.loggers.debug.DebugLogger.*; 035 import org.opends.server.loggers.debug.DebugTracer; 036 import org.opends.server.types.DebugLogLevel; 037 038 /** 039 * This thread is spawned off at the time of file rotation to 040 * execute specific actions such as compression, encryption, 041 * and signing of the log files. 042 */ 043 public class RotationActionThread extends DirectoryThread 044 { 045 /** 046 * The tracer object for the debug logger. 047 */ 048 private static final DebugTracer TRACER = getTracer(); 049 050 051 private ArrayList<ActionType> actions; 052 private String filename; 053 private ConfigEntry configEntry; 054 055 /** 056 * Create the logger thread along with the specified file name, 057 * and the rotation actions. 058 * 059 * @param filename The name of the file to be rotated. 060 * @param actions The set of actions that should be performed when the 061 * file is rotated. 062 * @param configEntry The entry that contains the rotation configuration. 063 */ 064 public RotationActionThread(String filename, 065 ArrayList<ActionType> actions, 066 ConfigEntry configEntry) 067 { 068 super("Logger Rotation Action Thread"); 069 070 this.filename = filename; 071 this.actions = actions; 072 this.configEntry = configEntry; 073 } 074 075 /** 076 * The run method of the thread. 077 */ 078 public void run() 079 { 080 try 081 { 082 for(ActionType at : actions) 083 { 084 PostRotationAction action = null; 085 switch(at) 086 { 087 case GZIP_COMPRESS: 088 String gzipFile = filename + ".gz"; 089 action = new GZIPAction(filename, gzipFile, true); 090 break; 091 case ZIP_COMPRESS: 092 String zipFile = filename + ".zip"; 093 action = new ZIPAction(filename, zipFile, true); 094 break; 095 case SIGN: 096 //String alias = RotationConfigUtil.getCertificateAlias(configEntry); 097 //action = new SignatureAction(filename, alias); 098 break; 099 case ENCRYPT: 100 String encFile = filename + ".enc"; 101 //String certAlias = 102 // RotationConfigUtil.getCertificateAlias(configEntry); 103 // FIXME - make the encryption algorithm configurable. 104 //action = new EncryptAction(filename, encFile, false, certAlias, 105 // "RSA"); 106 break; 107 default: 108 System.err.println("Invalid post rollover action:" + at); 109 break; 110 } 111 if(action != null) 112 { 113 boolean val = action.execute(); 114 if(val == false) 115 { 116 System.err.println("Post rotation action failed."); 117 } 118 } 119 } 120 } catch(Exception e) 121 { 122 if (debugEnabled()) 123 { 124 TRACER.debugCaught(DebugLogLevel.ERROR, e); 125 } 126 } 127 } 128 129 } 130