001package org.apache.directory.server.core.api; 002 003 004/* 005 * Licensed to the Apache Software Foundation (ASF) under one 006 * or more contributor license agreements. See the NOTICE file 007 * distributed with this work for additional information 008 * regarding copyright ownership. The ASF licenses this file 009 * to you under the Apache License, Version 2.0 (the 010 * "License"); you may not use this file except in compliance 011 * with the License. You may obtain a copy of the License at 012 * 013 * http://www.apache.org/licenses/LICENSE-2.0 014 * 015 * Unless required by applicable law or agreed to in writing, 016 * software distributed under the License is distributed on an 017 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 018 * KIND, either express or implied. See the License for the 019 * specific language governing permissions and limitations 020 * under the License. 021 * 022 */ 023 024import java.io.File; 025 026 027/** 028 * Convenience class to encapsulate paths to various directories and files within 029 * an instance. 030 * <br> 031 * The default layout is : 032 * <pre> 033 * <instance directory> 034 * | 035 * +-- conf/ 036 * | | 037 * | +-- config.ldif 038 * | | 039 * | +-- wrapper.conf 040 * | | 041 * | +-- log4j.properties 042 * | | 043 * | +-- <keystore file> 044 * | 045 * +-- partitions/ 046 * | | 047 * | +-- system/ 048 * | | | 049 * | | +-- master.db 050 * | | | 051 * | | +-- objectclass.db 052 * | | | 053 * | | +-- objectclass.lg 054 * | | | 055 * | | +-- <index XXX lg and db files> 056 * | | 057 * | +-- schema/ 058 * | | | 059 * | | : 060 * | | 061 * | +-- <partition XXX>/ 062 * | | | 063 * | : : 064 * | 065 * +-- log/ 066 * | | 067 * | [+-- journal.ldif] 068 * | | 069 * | +-- <log file> 070 * | 071 * +-- run/ 072 * | 073 * +-- cache/ 074 * | 075 * +-- syncrepl-data/ 076 * </pre> 077 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 078 */ 079public class InstanceLayout extends AbstractLayout 080{ 081 // Static final fields for system property names 082 private static final String LOG_DIR = "apacheds.log.dir"; 083 private static final String RUN_DIR = "apacheds.run.dir"; 084 085 /** Static directory names */ 086 public static final String LOG_NAME = "log"; 087 public static final String RUN_NAME = "run"; 088 public static final String CONF_NAME = "conf"; 089 public static final String PARTITIONS_NAME = "partitions"; 090 private static final String REPL_NAME = "syncrepl-data"; 091 private static final String CACHE_NAME = "cache"; 092 093 /** Static file names */ 094 private static final String LOG4J_PROPERTIES = "log4j.properties"; 095 private static final String WRAPPER_CONF = "wrapper.conf"; 096 private static final String CONFIG_LDIF = "config.ldif"; 097 private static final String KEYSTORE_FILE = "apacheds.ks"; 098 099 /** The Log directory */ 100 private File logDir; 101 102 /** The Partitions directory */ 103 private File partitionsDir; 104 105 /** The Run directory */ 106 private File runDir; 107 108 /** The Conf directory */ 109 private File confDir; 110 111 /** The replication data directory */ 112 private File replDir; 113 114 /** The cache directory */ 115 private File cacheDir; 116 117 118 /** 119 * Creates a new instance of InstanceLayout. 120 * 121 * @param instanceDirectory the instance directory 122 */ 123 public InstanceLayout( File instanceDirectory ) 124 { 125 super( instanceDirectory ); 126 init(); 127 } 128 129 130 /** 131 * Creates a new instance of InstanceLayout. 132 * 133 * @param instanceDirectoryPath the path to the instance directory 134 */ 135 public InstanceLayout( String instanceDirectoryPath ) 136 { 137 super( instanceDirectoryPath ); 138 init(); 139 } 140 141 142 /** 143 * Initializes the InstanceLayout. 144 */ 145 private void init() 146 { 147 // The required directories 148 File[] requiredDirectories = new File[] 149 { 150 getInstanceDirectory(), 151 getConfDirectory(), 152 getLogDirectory(), 153 getPartitionsDirectory(), 154 getRunDirectory(), 155 getCacheDirectory() 156 }; 157 158 setRequiredDirectories( requiredDirectories ); 159 160 // The required files 161 File[] requiredFiles = new File[] 162 { 163 getWrapperConfigurationFile(), 164 getLogConfigurationFile() /*, 165 getApacheDsConfigurationLdifFile() */// TODO re-activate this when possible. 166 }; 167 168 setRequiredFiles( requiredFiles ); 169 } 170 171 172 /** 173 * Gets the 'conf' directory ('<instance>/conf'). 174 * 175 * @return the 'conf' directory 176 */ 177 public File getConfDirectory() 178 { 179 if ( confDir == null ) 180 { 181 confDir = new File( getInstanceDirectory(), CONF_NAME ); 182 } 183 184 return confDir; 185 } 186 187 188 /** 189 * @param confDir the confDir to set 190 */ 191 public void setConfDir( File confDir ) 192 { 193 this.confDir = confDir; 194 } 195 196 197 /** 198 * Gets the 'cache' directory ('<instance>/cache'). 199 * 200 * @return the 'cache' directory 201 */ 202 public File getCacheDirectory() 203 { 204 if ( cacheDir == null ) 205 { 206 cacheDir = new File( getInstanceDirectory(), CACHE_NAME ); 207 } 208 209 return cacheDir; 210 } 211 212 213 /** 214 * @param cacheDir the confDir to set 215 */ 216 public void setCacheDir( File cacheDir ) 217 { 218 this.cacheDir = cacheDir; 219 } 220 221 222 /** 223 * Gets the 'log' directory ('<instance>/log'). 224 * 225 * @return the 'log' directory 226 */ 227 public File getLogDirectory() 228 { 229 if ( logDir == null ) 230 { 231 String systemLogDir = System.getProperty( LOG_DIR ); 232 233 if ( systemLogDir != null ) 234 { 235 logDir = new File( systemLogDir ); 236 } 237 else 238 { 239 logDir = new File( getInstanceDirectory(), LOG_NAME ); 240 } 241 } 242 243 return logDir; 244 } 245 246 247 /** 248 * @param logDir the logDir to set 249 */ 250 public void setLogDir( File logDir ) 251 { 252 this.logDir = logDir; 253 } 254 255 256 /** 257 * Gets the 'partitions' directory ('<instance>/partitions') 258 * 259 * @return the 'partitions' directory 260 */ 261 public File getPartitionsDirectory() 262 { 263 if ( partitionsDir == null ) 264 { 265 partitionsDir = new File( getInstanceDirectory(), PARTITIONS_NAME ); 266 } 267 268 return partitionsDir; 269 } 270 271 272 /** 273 * @param partitionsDir the partitionsDir to set 274 */ 275 public void setPartitionsDir( File partitionsDir ) 276 { 277 this.partitionsDir = partitionsDir; 278 } 279 280 281 /** 282 * Gets the 'run' directory in the installation directory ('<instance>/run'). 283 * 284 * @return the 'run' directory 285 */ 286 public File getRunDirectory() 287 { 288 if ( runDir == null ) 289 { 290 String systemRunDir = System.getProperty( RUN_DIR ); 291 292 if ( systemRunDir != null ) 293 { 294 runDir = new File( systemRunDir ); 295 } 296 else 297 { 298 runDir = new File( getInstanceDirectory(), RUN_NAME ); 299 } 300 } 301 302 return runDir; 303 } 304 305 306 /** 307 * @param runDir the runDir to set 308 */ 309 public void setRunDir( File runDir ) 310 { 311 this.runDir = runDir; 312 } 313 314 315 /** 316 * Gets the instance directory. 317 * 318 * @return the instance directory 319 */ 320 public File getInstanceDirectory() 321 { 322 return getDirectory(); 323 } 324 325 326 /** 327 * Gets the log configuration file (<em>'<instance>/conf/log4j.properties'</em>). 328 * 329 * @return the log configuration file 330 */ 331 public File getLogConfigurationFile() 332 { 333 return new File( getConfDirectory(), LOG4J_PROPERTIES ); 334 } 335 336 337 /** 338 * Gets the wrapper configuration file (<em>'<instance>/conf/wrapper.conf'</em>). 339 * 340 * @return the wrapper configuration file 341 */ 342 public File getWrapperConfigurationFile() 343 { 344 return new File( getConfDirectory(), WRAPPER_CONF ); 345 } 346 347 348 /** 349 * Gets the apacheds configuration ldif file (<em>'<instance>/conf/config.ldif'</em>). 350 * 351 * @return the apacheds configuration ldif file 352 */ 353 public File getApacheDsConfigurationLdifFile() 354 { 355 return new File( getConfDirectory(), CONFIG_LDIF ); 356 } 357 358 359 /** 360 * Gets the apacheds KeyStore file (<em>'<instance>/conf/apacheds.ks'</em>). 361 * 362 * @return the apacheds KeyWStore file 363 */ 364 public File getKeyStoreFile() 365 { 366 return new File( getConfDirectory(), KEYSTORE_FILE ); 367 } 368 369 370 /** 371 * Gets the 'replication' directory where replication journals are stored 372 * (<em>'<instance>/syncrepl-data'</em>). 373 * 374 * @return the 'replication' directory 375 */ 376 public File getReplDirectory() 377 { 378 if ( replDir == null ) 379 { 380 replDir = new File( getInstanceDirectory(), REPL_NAME ); 381 } 382 383 return replDir; 384 } 385 386 387 /** 388 * Sets the directory where the replication data are stored 389 * 390 * @param replDir the replication journal data directory 391 */ 392 public void setReplDirectory( File replDir ) 393 { 394 this.replDir = replDir; 395 } 396 397 398 /** 399 * @see String#toString() 400 */ 401 public String toString() 402 { 403 return "Instance Layout: \n" 404 + " Instance dir : " + getInstanceDirectory() + "\n" 405 + " Instance conf dir : " + getConfDirectory() + "\n" 406 + " Instance log dir : " + getLogDirectory() + "\n" 407 + " Instance run dir : " + getRunDirectory() + "\n" 408 + " Instance partitions dir : " + getPartitionsDirectory() + "\n" 409 + " Instance replication data dir : " + getReplDirectory() + "\n" 410 + " Instance cache dir : " + getCacheDirectory() + "\n"; 411 } 412}