Changeset ebe87df


Ignore:
Timestamp:
Aug 30, 2017 4:06:10 PM (4 weeks ago)
Author:
www-data <www-data@…>
Branches:
master
Children:
f49f6e2
Parents:
cb9b92a
git-author:
Bang Pham Huu <b.phamhuu@…> (08/29/17 11:31:26)
git-committer:
www-data <www-data@…> (08/30/17 16:06:10)
Message:

ticket:502 - Fix logging in the Spring framework and faulty Bean injection in petascope

Summary:
There is a hidden problem from Spring Framework which it will stop Tomcat
then petascope also cannot start. The problem is shown when adding the log4j for Spring Framework when it starts and is fixed. It was about the ambiguity of injection Bean to a java class, but Spring cannot show the error in log
as Spring Framework starts before petascope.properties is loaded.

Test Plan: Tested by copying war, jar to a VM and it could run.

Reviewers: dmisev

Differential Revision: http://codereview.rasdaman.org/D457

Files:
1 added
1 deleted
6 edited

Legend:

Unmodified
Added
Removed
  • .gitignore

    r45b3145 rebe87df  
    109109applications/petascope/src/main/resources/application.properties
    110110application.properties
     111applications/petascope/petascope_core/src/main/resources/log4j.properties
    111112bin/update_db.sh
    112113migrate_petascopedb.sh
  • applications/petascope/CMakeLists.txt

    r7d15c94 rebe87df  
    4747set(APPLICATION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/petascope_main/src/main/resources/application.properties")
    4848
     49# Log4j for Spring framework and used only when it starts (not for petascope applications)
     50set(LOG4J_SPRING_FILE_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/petascope_core/src/main/resources/log4j.properties.in")
     51set(LOG4J_SPRING_FILE "${CMAKE_CURRENT_SOURCE_DIR}/petascope_core/src/main/resources/log4j.properties")
     52
    4953# Only has 1 petascope.properties for all databases in application (petascope_main)
    5054set(SETTINGS_FILE_TEMPLATE "${CMAKE_CURRENT_SOURCE_DIR}/petascope_main/src/main/resources/petascope.properties.in")
     
    8084# Do the same for the petascope_migration pom.xml
    8185configure_file("${CMAKE_CURRENT_SOURCE_DIR}/petascope_migration/pom.xml.in" "${CMAKE_CURRENT_SOURCE_DIR}/petascope_migration/pom.xml" @ONLY)
     86
     87# Do the same for log4j.properties.in
     88configure_file("${LOG4J_SPRING_FILE_TEMPLATE}" "${LOG4J_SPRING_FILE}" @ONLY)
    8289
    8390# Do the same for petascope.properties.in
  • applications/petascope/Makefile.am

    r901a413 rebe87df  
    7474WCS_CLIENT_DEST = $(WEB)/$(STATIC_WEB_FOLDER)/wcs-client/
    7575
     76LOG4J_SPRING_SETTINGS_FILE = petascope_core/src/main/resources/log4j.properties.in
     77LOG4J_SPRING_SETTINGS_FILE_EDIT = petascope_core/src/main/resources/log4j.properties
     78
    7679SETTINGS_FILE = petascope_main/src/main/resources/petascope.properties.in
    7780SETTINGS_FILE_EDIT = petascope_main/src/main/resources/petascope.properties
     
    130133        $(SED) -i "s|@GDAL_JAVA_DIR@|$(GDAL_JAVA_DIR)|g" $(SRC_RES)/application.properties
    131134        $(SED) -i "s|@CONF_DIR@|$(sysconfdir)|g" $(SRC_RES)/application.properties
     135        cp $(LOG4J_SPRING_SETTINGS_FILE) $(LOG4J_SPRING_SETTINGS_FILE_EDIT)
     136        $(SED) -i "s|@LOG_DIR@|$(logdir)|g" $(LOG4J_SPRING_SETTINGS_FILE_EDIT)         
    132137        cp migrate_petascopedb.sh.in migrate_petascopedb.sh     
    133138        $(SED) -i "s|@LOG_DIR@|$(logdir)|g" migrate_petascopedb.sh     
  • applications/petascope/petascope_core/src/main/java/org/rasdaman/InitAllConfigurationsApplicationService.java

    r1ede013 rebe87df  
    6262     * @throws java.io.IOException
    6363     */
    64     public static void addLibraryPath(String libraryName, String pathToAdd) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, IOException {
    65         final String tmpTargetNativeDefaultFolderPath = "/tmp/rasdaman/" + libraryName;
     64    public static void addLibraryPath(String libraryName, String pathToAdd) throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException, IOException, InterruptedException {
     65        final String tmpTargetNativeDefaultFolderPath = "/tmp/rasdaman/" + libraryName;         
     66   
     67        // Remove this temp directory for the gdal library as it already loaded in JVM
     68        FileUtils.deleteDirectory(new File(tmpTargetNativeDefaultFolderPath));
     69       
    6670        String timeStamp = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
    6771       
     
    8387
    8488        int i = 0;
     89        boolean pathExist = false;
    8590        // check if the path to add is already present
    8691        for (String path : paths) {
    8792            String pathFolder = StringUtils.substringBeforeLast(path, "/");
    88             if (pathFolder.equals(tmpTargetNativeDefaultFolderPath)) {
    89                 // Remove the previous rasdaman/gdal_native folder first
    90                 FileUtils.deleteDirectory(new File(path));
     93            if (pathFolder.equals(tmpTargetNativeDefaultFolderPath)) {               
    9194                // Override the old path of rasdaman/gdal_native with the new one
    9295                paths[i] = tmpTargetNativeFolderPath;
    9396                usrPathsField.set(null, paths);
    94                 return;
     97                pathExist = true;
     98                break;
    9599            }
    96100            i++;
    97101        }
    98102
    99         //add the new path
    100         final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);       
    101         newPaths[newPaths.length - 1] = tmpTargetNativeFolderPath;
    102         usrPathsField.set(null, newPaths);
     103        if (pathExist == false) {
     104            //add the new path
     105            final String[] newPaths = Arrays.copyOf(paths, paths.length + 1);       
     106            newPaths[newPaths.length - 1] = tmpTargetNativeFolderPath;
     107            usrPathsField.set(null, newPaths);
     108        }
     109       
     110        // As the war file can be run from terminal which has different user name (e.g: rasdaman not tomcat)
     111        // So must set it to 777 permission then the folder can be deleted from both external tomcat or embedded tomcat.
     112        Runtime rt = Runtime.getRuntime();
     113        rt.exec("chmod -R 777 " + tmpTargetNativeDefaultFolderPath);
    103114    }
    104115}
  • applications/petascope/petascope_main/src/main/java/org/rasdaman/ApplicationMain.java

    re87a9d5 rebe87df  
    6969
    7070    private static final Logger log = LoggerFactory.getLogger(ApplicationMain.class);
    71 
    72     @Autowired
    73     AbstractHandler abstractHandler;
    74 
     71   
    7572    /**
    7673     * NOTE: This one is use to load Petascope properties from external file
     
    8077     * @throws java.sql.SQLException
    8178     * @throws java.lang.ClassNotFoundException
     79     * @throws petascope.exceptions.PetascopeException
     80     * @throws java.lang.InterruptedException
    8281     * @PropertySource in class level will not work as it requires a constant
    8382     * path to petascope.properties.
     
    8887     */
    8988    @Bean
    90     public PropertySourcesPlaceholderConfigurer placeholderConfigurer() throws FileNotFoundException, IOException, SQLException, ClassNotFoundException, PetascopeException, InterruptedException {
     89    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() throws FileNotFoundException, IOException, SQLException, ClassNotFoundException, PetascopeException, InterruptedException {
    9190        String resourceName = APPLICATION_PROPERTIES_FILE; // could also be a constant
    9291        Properties properties = new Properties();
    93         InputStream resourceStream = this.getClass().getResourceAsStream("/" + resourceName);
     92        InputStream resourceStream = ApplicationMain.class.getClassLoader().getResourceAsStream("/" + resourceName);
    9493        properties.load(resourceStream);
    9594
     
    124123     * OGC WCS XML Schema
    125124     */
    126     private void initConfigurations(Properties properties) throws SQLException, ClassNotFoundException, PetascopeException, IOException, InterruptedException {               
     125    private static void initConfigurations(Properties properties) throws SQLException, ClassNotFoundException, PetascopeException, IOException, InterruptedException {               
    127126        String GDAL_JAVA_DIR = properties.getProperty(KEY_GDAL_JAVA_DIR);
    128127        String CONF_DIR = properties.getProperty(KEY_PETASCOPE_CONF_DIR);
  • applications/petascope/petascope_migration/src/main/java/org/rasdaman/InitializeApplication.java

    r303022f rebe87df  
    6969     */
    7070    @Bean
    71     public PropertySourcesPlaceholderConfigurer placeholderConfigurer() throws FileNotFoundException, IOException, SQLException, ClassNotFoundException, PetascopeException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
     71    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() throws FileNotFoundException, IOException, SQLException, ClassNotFoundException, PetascopeException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, InterruptedException {
    7272        String resourceName = APPLICATION_PROPERTIES_FILE; // could also be a constant
    7373        Properties properties = new Properties();
    74         InputStream resourceStream = this.getClass().getResourceAsStream("/" + resourceName);
     74        InputStream resourceStream = InitializeApplication.class.getResourceAsStream("/" + resourceName);
    7575        properties.load(resourceStream);
    7676
     
    9696     * OGC WCS XML Schema
    9797     */
    98     private void initConfigurations(Properties properties) throws SQLException, ClassNotFoundException, PetascopeException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, IOException {
     98    private static void initConfigurations(Properties properties) throws SQLException, ClassNotFoundException, PetascopeException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException, IOException, InterruptedException {
    9999        String GDAL_JAVA_DIR = properties.getProperty(KEY_GDAL_JAVA_DIR);
    100100        String CONF_DIR = properties.getProperty(KEY_PETASCOPE_CONF_DIR);
Note: See TracChangeset for help on using the changeset viewer.