/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package tachyon.conf;

import java.io.File;

import org.apache.log4j.Logger;

import tachyon.Constants;

/**
 * Configurations shared by master and workers.
 */
public class CommonConf extends Utils {
  private static final Logger LOG = Logger.getLogger("");

  private static CommonConf COMMON_CONF = null;

  /**
   * This is for unit test only. DO NOT use it for other purpose.
   */
  public static synchronized void clear() {
    COMMON_CONF = null;
  }

  public static synchronized CommonConf get() {
    if (COMMON_CONF == null) {
      COMMON_CONF = new CommonConf();
    }

    return COMMON_CONF;
  }

  public final String TACHYON_HOME;
  public final String UNDERFS_ADDRESS;
  public final String UNDERFS_DATA_FOLDER;
  public final String UNDERFS_WORKERS_FOLDER;

  public final String UNDERFS_HDFS_IMPL;
  public final String WEB_RESOURCES;
  public final boolean USE_ZOOKEEPER;
  public final String ZOOKEEPER_ADDRESS;

  public final String ZOOKEEPER_ELECTION_PATH;

  public final String ZOOKEEPER_LEADER_PATH;

  public final boolean ASYNC_ENABLED;
  
  public final int MAX_COLUMNS;
  
  public final int MAX_TABLE_METADATA_BYTE;

  private CommonConf() {
    if (System.getProperty("tachyon.home") == null) {
      LOG.warn("tachyon.home is not set. Using /mnt/tachyon_default_home as the default value.");
      File file = new File("/mnt/tachyon_default_home");
      if (!file.exists()) {
        file.mkdirs();
      }
    }
    TACHYON_HOME = getProperty("tachyon.home", "/mnt/tachyon_default_home");
    WEB_RESOURCES =
        getProperty("tachyon.web.resources", TACHYON_HOME + "/src/main/webapp");
    UNDERFS_ADDRESS = getProperty("tachyon.underfs.address", TACHYON_HOME + "/underfs");
    UNDERFS_DATA_FOLDER = getProperty("tachyon.data.folder", UNDERFS_ADDRESS + "/tachyon/data");
    UNDERFS_WORKERS_FOLDER =
        getProperty("tachyon.workers.folder", UNDERFS_ADDRESS + "/tachyon/workers");
    UNDERFS_HDFS_IMPL =
        getProperty("tachyon.underfs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");

    USE_ZOOKEEPER = getBooleanProperty("tachyon.usezookeeper", false);
    if (USE_ZOOKEEPER) {
      ZOOKEEPER_ADDRESS = getProperty("tachyon.zookeeper.address");
      ZOOKEEPER_ELECTION_PATH = getProperty("tachyon.zookeeper.election.path", "/election");
      ZOOKEEPER_LEADER_PATH = getProperty("tachyon.zookeeper.leader.path", "/leader");
    } else {
      ZOOKEEPER_ADDRESS = null;
      ZOOKEEPER_ELECTION_PATH = null;
      ZOOKEEPER_LEADER_PATH = null;
    }

    ASYNC_ENABLED = getBooleanProperty("tachyon.async.enabled", false);
    
    MAX_COLUMNS = getIntProperty("tachyon.max.columns", 1000);
    MAX_TABLE_METADATA_BYTE = getIntProperty("tachyon.max.table.metadata.byte", Constants.MB * 5);
  }
}

@@ -1862,18 +1862,16 @@
 NABLED;%0A
-  
 %0A  publi
@@ -1895,18 +1895,16 @@
 OLUMNS;%0A
-  
 %0A  publi
@@ -2399,16 +2399,21 @@
 OME + %22/
+main/
 src/main
@@ -3388,20 +3388,16 @@
 false);%0A
-    
 %0A    MAX

fix webapp location