Fills the configuration file (and creates it if doesn't exists) with
the default configuration values.

@throws java.io.IOException
961964
private void createDefaultConfigurationFile() throws IOException
    {
        
        File configFile = new File(configFilePath);
        
        if (configFile.exists()) {
            //seems a problem with access rights, report error
            throw new IOException();
        }
        else {
            //create the default file
            
            //create config dir if not exists yet
            File parentDir = configFile.getParentFile();
            if (!parentDir.exists())
                parentDir.mkdirs();
            
            //create config file
            configFile.createNewFile();
            
            Properties config = new Properties();
            
            fillDefaultProperties(config);
            
            OutputStream fileOutput = new FileOutputStream(configFile);
            config.store(fileOutput, automaticFileMsg);
        }
        
    }
90417
public static synchronized void init(Configuration conf) {
    if (!initDone) {
      DefaultConfiguration.conf = conf;
      DefaultConfiguration.initDone = true;
    }
  }
1272331
private void _fill () throws IOException
  {
    int nDstOfs = 0;
    if (m_nMarkedChar > UNMARKED)
    {
      // Marked
      final int nDelta = m_nNextCharIndex - m_nMarkedChar;
      if (nDelta >= m_nReadAheadLimit)
      {
        // Gone past read-ahead limit: Invalidate mark
        m_nMarkedChar = INVALIDATED;
        m_nReadAheadLimit = 0;
      }
      else
      {
        if (m_nReadAheadLimit <= m_aBuf.length)
        {
          // Shuffle in the current buffer
          System.arraycopy (m_aBuf, m_nMarkedChar, m_aBuf, 0, nDelta);
          m_nMarkedChar = 0;
          nDstOfs = nDelta;
        }
        else
        {
          // Reallocate buffer to accommodate read-ahead limit
          final char [] aNewBuf = new char [m_nReadAheadLimit];
          System.arraycopy (m_aBuf, m_nMarkedChar, aNewBuf, 0, nDelta);
          m_aBuf = aNewBuf;
          m_nMarkedChar = 0;
          nDstOfs = nDelta;
        }
        m_nNextCharIndex = nDelta;
        m_nChars = nDelta;
      }
    }

    int nBytesRead;
    do
    {
      nBytesRead = m_aReader.read (m_aBuf, nDstOfs, m_aBuf.length - nDstOfs);
    } while (nBytesRead == 0);
    if (nBytesRead > 0)
    {
      m_nChars = nDstOfs + nBytesRead;
      m_nNextCharIndex = nDstOfs;
    }
  }
712152
public void load(String config)
        throws IOException
    {
        _config=config;
        if(log.isDebugEnabled())log.debug("Load "+this+" from "+config);
        Properties properties = new Properties();
        Resource resource=Resource.newResource(config);
        properties.load(resource.getInputStream());

        Iterator iter = properties.entrySet().iterator();
        while(iter.hasNext())
        {
            Map.Entry entry = (Map.Entry)iter.next();

            String username=entry.getKey().toString().trim();
            String credentials=entry.getValue().toString().trim();
            String roles=null;
            int c=credentials.indexOf(',');
            if (c>0)
            {
                roles=credentials.substring(c+1).trim();
                credentials=credentials.substring(0,c).trim();
            }

            if (username!=null && username.length()>0 &&
                credentials!=null && credentials.length()>0)
            {
                put(username,credentials);
                if(roles!=null && roles.length()>0)
                {
                    StringTokenizer tok = new StringTokenizer(roles,", ");
                    while (tok.hasMoreTokens())
                        addUserToRole(username,tok.nextToken());
                }
            }
        }
    }
483570
private void createIzouPropertiesFile() {
        String propertiesPath = getMain().getFileSystemManager().getPropertiesLocation() + File.separator
                + IZOU_PROPERTIES_FILE_NAME;

        propertiesFile = new File(propertiesPath);
        if (!propertiesFile.exists()) try (PrintWriter writer = new PrintWriter(propertiesFile.getAbsolutePath(), "UTF-8")) {
            propertiesFile.createNewFile();

            writer.println("# --------------------");
            writer.println("# Izou Properties File");
            writer.println("# --------------------");
            writer.println("#");
            writer.println("# This file has some general configuration options that have to be configured before");
            writer.println("# Izou can run successfully.");
        } catch (IOException e) {
            error("Error while trying to create the new Properties file", e);
        }
    }
986950
private void init() throws ConfigFileIOException {
        this.props = new Properties();
        log.info("Reading config file: {}", this.configFile);
        boolean ok = true;
        try {
            // El fichero esta en el CLASSPATH
            this.props.load(SystemConfig.class.getResourceAsStream(this.configFile));
        } catch (Exception e) {
            log.warn("File not found in the Classpath");
            try {
                this.props.load(new FileInputStream(this.configFile));
            } catch (IOException ioe) {
                log.error("Can't open file: {}", ioe.getLocalizedMessage());
                ok = false;
                ioe.printStackTrace();
                throw new ConfigFileIOException(ioe.getLocalizedMessage());
            }
        }
        if (ok) {
            log.info("Configuration loaded successfully");
            if (log.isDebugEnabled()) {
                log.debug(this.toString());
            }
        }
    }
1019539
public void initialize(URI name, Configuration conf) throws IOException {
    fs.initialize(name, conf);
  }
1214233
protected synchronized void initialize(JobConf conf) throws IOException {
    maxRefillQueueSize =
        conf.getInt(MAX_REFILL_QUEUE_SIZE, DEFAULT_MAX_REFILL_QUEUE_SIZE);
    if (maxRefillQueueSize <= 0) {
      throw new RuntimeException("Illegal value for " +
          MAX_REFILL_QUEUE_SIZE + " " + maxRefillQueueSize);
    }
    this.originalConf = conf;
    // use configured nameserver & interface to get local hostname
    this.fConf = new JobConf(conf);
    localFs = FileSystem.getLocal(fConf);
    if (fConf.get("slave.host.name") != null) {
      this.localHostname = fConf.get("slave.host.name");
    }
    if (localHostname == null) {
      this.localHostname =
      DNS.getDefaultHost
      (fConf.get("mapred.tasktracker.dns.interface","default"),
       fConf.get("mapred.tasktracker.dns.nameserver","default"));
    }
  
    try {
      java.net.InetAddress inetAddress = java.net.InetAddress.getByName(this.localHostname);
      if (inetAddress != null) {
        this.localHostAddress = inetAddress.getHostAddress();
      }
      else {
        LOG.info("Unable to get IPaddress for " + this.localHostname);
      }
    } catch (UnknownHostException e) {
      LOG.info("Unable to get IPaddress for " + this.localHostname);
    }

    Class<? extends ResourceCalculatorPlugin> clazz =
        fConf.getClass(MAPRED_TASKTRACKER_MEMORY_CALCULATOR_PLUGIN_PROPERTY,
            null, ResourceCalculatorPlugin.class);
    resourceCalculatorPlugin =
      (ResourceCalculatorPlugin) ResourceCalculatorPlugin
            .getResourceCalculatorPlugin(clazz, fConf);
    LOG.info("Using ResourceCalculatorPlugin : " + resourceCalculatorPlugin);
    int numCpuOnTT = resourceCalculatorPlugin.getNumProcessors();
    maxMapSlots = getMaxSlots(fConf, numCpuOnTT, TaskType.MAP);
    maxReduceSlots = getMaxSlots(fConf, numCpuOnTT, TaskType.REDUCE);
    actualMaxMapSlots =
      getMaxActualSlots(fConf, numCpuOnTT, TaskType.MAP);
    actualMaxReduceSlots =
      getMaxActualSlots(fConf, numCpuOnTT, TaskType.REDUCE);
    LOG.info("Num cpus = " + numCpuOnTT +
             ", max map slots = " + maxMapSlots +
             ", max reduce slots = " + maxReduceSlots +
             ", actual max map slots = " + actualMaxMapSlots +
             ", actual max reduce slots = " + actualMaxReduceSlots);

    // Check local disk, start async disk service, and clean up all
    // local directories.
    checkLocalDirs(getLocalDirsFromConf(this.fConf));
    asyncDiskService = new MRAsyncDiskService(FileSystem.getLocal(fConf),
        getLocalDirsFromConf(fConf), fConf);
    asyncDiskService.cleanupAllVolumes();
    DistributedCache.purgeCache(fConf, asyncDiskService);
    versionBeanName = VersionInfo.registerJMX("TaskTracker");

    // Clear out state tables
    this.tasks.clear();
    this.runningTasks = new LinkedHashMap<TaskAttemptID, TaskInProgress>();
    this.runningJobs = new TreeMap<JobID, RunningJob>();
    this.mapTotal = 0;
    this.reduceTotal = 0;
    this.acceptNewTasks = true;
    this.status = null;

    this.minSpaceStart = this.fConf.getLong("mapred.local.dir.minspacestart", 0L);
    this.minSpaceKill = this.fConf.getLong("mapred.local.dir.minspacekill", 0L);
    //tweak the probe sample size (make it a function of numCopiers)
    probe_sample_size = this.fConf.getInt("mapred.tasktracker.events.batchsize", 500);

    // Set up TaskTracker instrumentation
    this.myInstrumentation = createInstrumentation(this, fConf);

    // bind address
    String address =
      NetUtils.getServerAddress(fConf,
                                "mapred.task.tracker.report.bindAddress",
                                "mapred.task.tracker.report.port",
                                "mapred.task.tracker.report.address");
    InetSocketAddress socAddr = NetUtils.createSocketAddr(address);
    String bindAddress = socAddr.getHostName();
    int tmpPort = socAddr.getPort();

    this.jvmManager = new JvmManager(this);

    // Set service-level authorization security policy
    if (this.fConf.getBoolean(
          ServiceAuthorizationManager.SERVICE_AUTHORIZATION_CONFIG, false)) {
      PolicyProvider policyProvider =
        (PolicyProvider)(ReflectionUtils.newInstance(
            this.fConf.getClass(PolicyProvider.POLICY_PROVIDER_CONFIG,
                MapReducePolicyProvider.class, PolicyProvider.class),
            this.fConf));
      SecurityUtil.setPolicy(new ConfiguredPolicy(this.fConf, policyProvider));
    }

    // RPC initialization
    int max = actualMaxMapSlots > actualMaxReduceSlots ?
                       actualMaxMapSlots : actualMaxReduceSlots;
    //set the num handlers to max*2 since canCommit may wait for the duration
    //of a heartbeat RPC
    int numHandlers = 2 * max;
    LOG.info("Starting RPC server with " + numHandlers + " handlers");
    this.taskReportServer =
      RPC.getServer(this, bindAddress, tmpPort, numHandlers, false, this.fConf);
    this.taskReportServer.start();

    // get the assigned address
    this.taskReportAddress = taskReportServer.getListenerAddress();
    this.fConf.set("mapred.task.tracker.report.address",
        taskReportAddress.getHostName() + ":" + taskReportAddress.getPort());
    LOG.info("TaskTracker up at: " + this.taskReportAddress);

    this.taskTrackerName = "tracker_" + localHostname + ":" + taskReportAddress;
    LOG.info("Starting tracker " + taskTrackerName);

    this.justInited = true;
    this.running = true;

    taskMemoryControlGroupEnabled = fConf.getBoolean(
        MAPRED_TASKTRACKER_CGROUP_MEM_ENABLE_PROPERTY,
        DEFAULT_MAPRED_TASKTRACKER_CGROUP_MEM_ENABLE_PROPERTY);
    if(taskMemoryControlGroupEnabled) {
      ttMemCgroup = new TaskTrackerMemoryControlGroup(fConf);
    }
    
    taskCPUControlGroupEnabled = fConf.getBoolean(
            MAPRED_TASKTRACKER_CGROUP_CPU_ENABLE_PROPERTY,
            DEFAULT_MAPRED_TASKTRACKER_CGROUP_CPU_ENABLE_PROPERTY);
    if(taskCPUControlGroupEnabled)
      ttCPUCgroup = new TaskTrackerCPUControlGroup(fConf, actualMaxMapSlots + actualMaxReduceSlots);
    
    initializeMemoryManagement();
    cgroupMemoryWatcher = new CGroupMemoryWatcher(this);
    cgroupMemoryWatcher.start();

    setTaskLogsMonitor(new TaskLogsMonitor(getMapUserLogRetainSize(),
        getReduceUserLogRetainSize()));
    getTaskLogsMonitor().start();

    this.indexCache = new IndexCache(this.fConf);

    pulseChecker = PulseChecker.create(this, "TaskTracker");

    heartbeatMonitor = new HeartbeatMonitor(this.fConf);
    mapLauncher =
      new TaskLauncher(TaskType.MAP, maxMapSlots, actualMaxMapSlots);
    reduceLauncher =
      new TaskLauncher(TaskType.REDUCE, maxReduceSlots, actualMaxReduceSlots);
    mapLauncher.start();
    reduceLauncher.start();
    Class<? extends TaskController> taskControllerClass
                          = fConf.getClass("mapred.task.tracker.task-controller",
                                            DefaultTaskController.class,
                                            TaskController.class);
    taskController = (TaskController)ReflectionUtils.newInstance(
                                                      taskControllerClass, fConf);

    //setup and create jobcache directory with appropriate permissions
    taskController.setup();

    //Start up node health checker service.
    if (shouldStartHealthMonitor(this.fConf)) {
      startHealthMonitor(this.fConf);
    }

    oobHeartbeatOnTaskCompletion =
      fConf.getBoolean(TT_OUTOFBAND_HEARBEAT, false);
    fastFetch = fConf.getBoolean(TT_FAST_FETCH, false);

    // Setup the launcher if in simulation mode
    simulatedTaskMode = fConf.getBoolean(TT_SIMULATED_TASKS, false);
    LOG.info("simulatedTaskMode = " + simulatedTaskMode);
    long simulatedTaskRunningTime =
        fConf.getLong(TT_SIMULATED_TASK_RUNNING_TIME, 20000);
    if (simulatedTaskMode) {
      simulatedTaskRunner =
        new SimulatedTaskRunner(simulatedTaskRunningTime, this);
      simulatedTaskRunner.start();
    }
    // Setup task completion event store
    useTaskCompletionEventsStore = fConf.getBoolean(
        MAPRED_TASKTRACKER_TCE_STORE_PROPERTY, false);
    profileAllTasks = fConf.getBoolean(TT_PROFILE_ALL_TASKS, false);
  }
1092930
private final static void loadConfig() {
		try {
			conf = Configurations.loadConfig(configFilePath);
		} catch (ConfigurationException e) {
			terminate();
			throw new InitializationException(INIT_FAILED, e);
		}
	}
921613
public Configuration create() {
        Configuration configuration;
        try {
            InputStream stream = null;
            try {
                // Search the user configuration
                stream = Utils.openResourceStream(DEFAULT_USER_CONFIGURATION_FILE);

                // If user configuration not found then use default
                if (stream == null) {
                    stream = Utils.openResourceStream(DEFAULT_CONFIGURATION_FILE);
                }

                if (stream != null) {
                    configuration = create(stream);
                } else {
                    throw new TextProcessorFactoryException("Can't find or open default configuration resource.");
                }
            } finally {
                if (stream != null) {
                    stream.close();
                }
            }

            Properties properties = new Properties();

            // Load properties from .property file
            InputStream propertiesStream = null;
            try {
                propertiesStream = Utils.openResourceStream(DEFAULT_PROPERTIES_FILE);
                if (propertiesStream != null) {
                    properties.load(propertiesStream);
                }
            } finally {
                if (propertiesStream != null) {
                    propertiesStream.close();
                }
            }

            // Load properties from xml file
            InputStream xmlPropertiesStream = null;
            try {
                xmlPropertiesStream = Utils.openResourceStream(DEFAULT_PROPERTIES_XML_FILE);
                if (xmlPropertiesStream != null) {
                    properties.loadFromXML(xmlPropertiesStream);
                }
            } finally {
                if (xmlPropertiesStream != null) {
                    xmlPropertiesStream.close();
                }
            }

            if (!properties.isEmpty()) {
                Map<String, CharSequence> params = new HashMap<String, CharSequence>();
                params.putAll(configuration.getParams());
                for (Map.Entry<Object, Object> entry : properties.entrySet()) {
                    Object key = entry.getKey();
                    if (key != null) {
                        params.put(key.toString(), entry.getValue().toString());
                    }
                }
                configuration.setParams(params);
            }
        } catch (IOException e) {
            throw new TextProcessorFactoryException(e);
        }

        return configuration;
    }
325098
@Override
	public void init(File jsonFile) throws IndexerException {
		try {
			config = new JsonSimpleConfig(jsonFile);
			init();
		} catch (IOException ioe) {
			throw new IndexerException(ioe);
		}
	}
742904
protected void loadConfigs() {
        configs = new Properties();
        // If run as a jar, find in file system classpath first, if not found, then get resource in jar.
        if (ClassPathUtil.testRunMainInJar()) {
            String[] classPathsInFileSystem = ClassPathUtil.getAllClassPathNotInJar();
            String workDir = System.getProperty("user.dir");
            String mainJarRelativePath = ClassPathUtil.getClassPathsInSystemProperty()[0];
            File mainJar = new File(workDir, mainJarRelativePath);
            File mainJarDir = mainJar.getParentFile();
            for (String classPath : classPathsInFileSystem) {
                File classPathFile = new File(classPath);
                File configFile;
                if (classPathFile.isAbsolute()) {
                    configFile = new File(classPathFile, propertiesAbsoluteClassPath);
                } else {
                    configFile = new File(new File(mainJarDir, classPath), propertiesAbsoluteClassPath);
                }
                if (configFile.exists() && configFile.isFile()) {
                    InputStream is = null;
                    try {
                        is = new FileInputStream(configFile);
                        loadConfigsFromStream(is);
                    } catch (FileNotFoundException e) {
                        LOGGER.warn("Load config file " + configFile.getPath() + " error!", e);
                    }
                    return;
                }
            }
        }
        if (propertiesFilePath == null) {
            if (propertiesAbsoluteClassPath == null) {
                return;
            }
            InputStream is = OneProperties.class.getResourceAsStream(propertiesAbsoluteClassPath);
            loadConfigsFromStream(is);
        } else {
            configs = PropertiesIO.load(propertiesFilePath);
        }
    }
444754
public static synchronized void init ()
    {
        // only initialize ourselves once
        if (_keys != null) {
            return;
        } else {
            _keys = new ArrayList<Class<?>>();
            _values = new ArrayList<String>();
        }

        // first try loading the properties file without a leading slash
        ClassLoader cld = ExceptionMap.class.getClassLoader();
        InputStream config = ConfigUtil.getStream(PROPS_NAME, cld);
        if (config == null) {
            log.warning("Unable to load " + PROPS_NAME + " from CLASSPATH.");

        } else {
            // otherwise process ye old config file.
            try {
                // we'll do some serious jiggery pokery to leverage the parsing
                // implementation provided by java.util.Properties. god bless
                // method overloading
                final ArrayList<String> classes = new ArrayList<String>();
                Properties loader = new Properties() {
                    @Override public Object put (Object key, Object value) {
                        classes.add((String)key);
                        _values.add((String)value);
                        return key;
                    }
                };
                loader.load(config);

                // now cruise through and resolve the exceptions named as
                // keys and throw out any that don't appear to exist
                for (int i = 0; i < classes.size(); i++) {
                    String exclass = classes.get(i);
                    try {
                        Class<?> cl = Class.forName(exclass);
                        // replace the string with the class object
                        _keys.add(cl);

                    } catch (Throwable t) {
                        log.warning("Unable to resolve exception class.", "class", exclass,
                                    "error", t);
                        _values.remove(i);
                        i--; // back on up a notch
                    }
                }

            } catch (IOException ioe) {
                log.warning("Error reading exception mapping file: " + ioe);
            }
        }
    }
206533
protected void configure(String[] args) throws IOException {
    for (String arg : args) {
      if (arg.startsWith("--input=")) {
        FileRef ref = createInput();
        ref.setPath(arg.substring(arg.indexOf('=') + 1));
      } else if (arg.startsWith("--output=")) {
        FileRef ref = createOutput();
        ref.setPath(arg.substring(arg.indexOf('=') + 1));
      } else if (arg.startsWith("--libdefined=")) {
        FunctionNamePredicate libdefined = new FunctionNamePredicate();
        libdefined.setPattern(arg.substring(arg.indexOf('=') + 1));
        addConfiguredLibdefined(libdefined);
      } else {
        throw new IllegalArgumentException(arg);
      }
    }
  }
425879
public void initialize() throws IOException {
    // Create a pipe such that its one end is connected to the input stream used by
    // the uploader and the other end is the write channel used by the caller.
    PipedInputStream pipeSource = new PipedInputStream(pipeBufferSize);
    OutputStream pipeSink = new PipedOutputStream(pipeSource);
    pipeSinkChannel = Channels.newChannel(pipeSink);

    // Connect pipe-source to the stream used by uploader.
    InputStreamContent objectContentStream = new InputStreamContent(contentType, pipeSource);
    // Indicate that we do not know length of file in advance.
    objectContentStream.setLength(-1);
    objectContentStream.setCloseInputStream(false);

    T request = createRequest(objectContentStream);
    request.setDisableGZipContent(true);

    // Change chunk size from default value (10MB) to one that yields higher performance.
    clientRequestHelper.setChunkSize(request, uploadChunkSize);

    // Given that the two ends of the pipe must operate asynchronous relative
    // to each other, we need to start the upload operation on a separate thread.
    uploadOperation = threadPool.submit(new UploadOperation(request, pipeSource));

    isInitialized = true;
  }
347344
private void fill() throws IOException {
    int i = in.read(buf, 0, buf.length);
    if (i > 0) {
      pos = 0;
      count = i;
    }
  }
1118731
void backupConfiguration() throws IOException {

        final String configuration = Constants.CONFIGURATION;

        final File a = new File(installedImage.getAppClientDir(), configuration);
        final File d = new File(installedImage.getDomainDir(), configuration);
        final File s = new File(installedImage.getStandaloneDir(), configuration);

        if (a.exists()) {
            final File ab = new File(configBackup, Constants.APP_CLIENT);
            backupDirectory(a, ab);
        }
        if (d.exists()) {
            final File db = new File(configBackup, Constants.DOMAIN);
            backupDirectory(d, db);
        }
        if (s.exists()) {
            final File sb = new File(configBackup, Constants.STANDALONE);
            backupDirectory(s, sb);
        }

    }