<commit_before>/*
 * ################################################################
 *
 * ProActive Parallel Suite(TM): The Java(TM) library for
 *    Parallel, Distributed, Multi-Core Computing for
 *    Enterprise Grids & Clouds
 *
 * Copyright (C) 1997-2011 INRIA/University of
 *                 Nice-Sophia Antipolis/ActiveEon
 * Contact: <EMAIL> or <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; version 3 of
 * the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * If needed, contact us to obtain a release under GPL Version 2 or 3
 * or a different license than the AGPL.
 *
 *  Initial developer(s):               The ActiveEon Team
 *                        http://www.activeeon.com/
 *  Contributor(s):
 *
 * ################################################################
 * $$ACTIVEEON_INITIAL_DEV$$
 */
package org.ow2.proactive.resourcemanager.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.Parser;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.objectweb.proactive.core.ProActiveException;
import org.objectweb.proactive.core.config.xml.ProActiveConfigurationParser;
import org.objectweb.proactive.core.node.Node;
import org.objectweb.proactive.core.node.NodeFactory;
import org.objectweb.proactive.core.util.log.ProActiveLogger;
import org.ow2.proactive.authentication.crypto.Credentials;
import org.ow2.proactive.resourcemanager.authentication.RMAuthentication;
import org.ow2.proactive.resourcemanager.common.RMConstants;
import org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties;
import org.ow2.proactive.resourcemanager.exception.AddingNodesException;
import org.ow2.proactive.resourcemanager.frontend.RMConnection;
import org.ow2.proactive.resourcemanager.frontend.ResourceManager;
import org.ow2.proactive.utils.console.JVMPropertiesPreloader;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;


/**
 * This class is responsible for creating a local node. You can define different settings to
 * register the node to an apropriate Resource Manager, ping it...
 *
 * @author ProActive team
 */
public class RMNodeStarter {

    protected Credentials credentials = null;
    protected String rmURL = null;
    protected String nodeName = RMNodeStarter.PAAGENT_DEFAULT_NODE_NAME;
    protected String nodeSourceName = null;

    /** Class' logger */
    protected static final Logger logger = ProActiveLogger.getLogger(RMLoggers.RMNODE);

    /** The default name of the node */
    protected static final String PAAGENT_DEFAULT_NODE_NAME = "PA-AGENT_NODE";

    /** Prefix for temp files that store nodes URL */
    protected static final String URL_TMPFILE_PREFIX = "PA-AGENT_URL";

    /** Name of the java property to set the rank */
    protected final static String RANK_PROP_NAME = "proactive.agent.rank";

    /**
     * The starter will try to connect to the Resource Manager before killing
     * itself that means that it will try to connect during
     * WAIT_ON_JOIN_TIMEOUT_IN_MS milliseconds
     */
    protected static int WAIT_ON_JOIN_TIMEOUT_IN_MS = 60000;
    /** to inform that the user supplied a value from the command line for the join rm timeout */
    protected static boolean WAIT_ON_JOIN_TIMEOUT_IN_MS_USER_SUPPLIED = false;
    /** Name of the java property to set the timeout value used to join the resource manager */
    protected final static String WAIT_ON_JOIN_PROP_NAME = "proactive.node.joinrm.timeout";

    /**
     * The ping delay used in RMPinger that pings the RM and exists if the
     * Resource Manager is down
     */
    protected static long PING_DELAY_IN_MS = 30000;
    /** to inform that the user supplied a value from the command line for the ping */
    protected static boolean PING_DELAY_IN_MS_USER_SUPPLIED = false;
    /** Name of the java property to set the node -> rm ping frequency value */
    protected final static String PING_DELAY_PROP_NAME = "proactive.node.ping.delay";

    /** The number of attempts to add the local node to the RM before quitting */
    protected static int NB_OF_ADD_NODE_ATTEMPTS = 10;
    /** to inform that the user supplied a value from the command line for the number of "add" attempts */
    protected static boolean NB_OF_ADD_NODE_ATTEMPTS_USER_SUPPLIED = false;
    /** Name of the java property to set the number of attempts performed to add a node to the resource manager */
    protected final static String NB_OF_ADD_NODE_ATTEMPTS_PROP_NAME = "proactive.node.add.attempts";

    /** The delay, in millis, between two attempts to add a node */
    protected static int ADD_NODE_ATTEMPTS_DELAY_IN_MS = 5000;
    /** to inform that the user supplied a value from the command line for the delay between two add attempts*/
    protected static boolean ADD_NODE_ATTEMPTS_DELAY_IN_MS_USER_SUPPLIED = false;
    /** Name of the java property to set the delay between two attempts performed to add a node to the resource manager */
    protected final static String ADD_NODE_ATTEMPTS_DELAY_PROP_NAME = "proactive.node.add.delay";
    /** Name of the java property to set the node source name */
    protected final static String NODESOURCE_PROP_NAME = "proactive.agent.nodesource";
<commit_msg>SCHEDULING-1224 Corrected name of the property<commit_after>/*
 * ################################################################
 *
 * ProActive Parallel Suite(TM): The Java(TM) library for
 *    Parallel, Distributed, Multi-Core Computing for
 *    Enterprise Grids & Clouds
 *
 * Copyright (C) 1997-2011 INRIA/University of
 *                 Nice-Sophia Antipolis/ActiveEon
 * Contact: <EMAIL> or <EMAIL>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Affero General Public License
 * as published by the Free Software Foundation; version 3 of
 * the License.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
 * USA
 *
 * If needed, contact us to obtain a release under GPL Version 2 or 3
 * or a different license than the AGPL.
 *
 *  Initial developer(s):               The ActiveEon Team
 *                        http://www.activeeon.com/
 *  Contributor(s):
 *
 * ################################################################
 * $$ACTIVEEON_INITIAL_DEV$$
 */
package org.ow2.proactive.resourcemanager.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyException;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.GnuParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import org.apache.commons.cli.Parser;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.objectweb.proactive.core.ProActiveException;
import org.objectweb.proactive.core.config.xml.ProActiveConfigurationParser;
import org.objectweb.proactive.core.node.Node;
import org.objectweb.proactive.core.node.NodeFactory;
import org.objectweb.proactive.core.util.log.ProActiveLogger;
import org.ow2.proactive.authentication.crypto.Credentials;
import org.ow2.proactive.resourcemanager.authentication.RMAuthentication;
import org.ow2.proactive.resourcemanager.common.RMConstants;
import org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties;
import org.ow2.proactive.resourcemanager.exception.AddingNodesException;
import org.ow2.proactive.resourcemanager.frontend.RMConnection;
import org.ow2.proactive.resourcemanager.frontend.ResourceManager;
import org.ow2.proactive.utils.console.JVMPropertiesPreloader;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;


/**
 * This class is responsible for creating a local node. You can define different settings to
 * register the node to an apropriate Resource Manager, ping it...
 *
 * @author ProActive team
 */
public class RMNodeStarter {

    protected Credentials credentials = null;
    protected String rmURL = null;
    protected String nodeName = RMNodeStarter.PAAGENT_DEFAULT_NODE_NAME;
    protected String nodeSourceName = null;

    /** Class' logger */
    protected static final Logger logger = ProActiveLogger.getLogger(RMLoggers.RMNODE);

    /** The default name of the node */
    protected static final String PAAGENT_DEFAULT_NODE_NAME = "PA-AGENT_NODE";

    /** Prefix for temp files that store nodes URL */
    protected static final String URL_TMPFILE_PREFIX = "PA-AGENT_URL";

    /** Name of the java property to set the rank */
    protected final static String RANK_PROP_NAME = "proactive.agent.rank";

    /**
     * The starter will try to connect to the Resource Manager before killing
     * itself that means that it will try to connect during
     * WAIT_ON_JOIN_TIMEOUT_IN_MS milliseconds
     */
    protected static int WAIT_ON_JOIN_TIMEOUT_IN_MS = 60000;
    /** to inform that the user supplied a value from the command line for the join rm timeout */
    protected static boolean WAIT_ON_JOIN_TIMEOUT_IN_MS_USER_SUPPLIED = false;
    /** Name of the java property to set the timeout value used to join the resource manager */
    protected final static String WAIT_ON_JOIN_PROP_NAME = "proactive.node.joinrm.timeout";

    /**
     * The ping delay used in RMPinger that pings the RM and exists if the
     * Resource Manager is down
     */
    protected static long PING_DELAY_IN_MS = 30000;
    /** to inform that the user supplied a value from the command line for the ping */
    protected static boolean PING_DELAY_IN_MS_USER_SUPPLIED = false;
    /** Name of the java property to set the node -> rm ping frequency value */
    protected final static String PING_DELAY_PROP_NAME = "proactive.node.ping.delay";

    /** The number of attempts to add the local node to the RM before quitting */
    protected static int NB_OF_ADD_NODE_ATTEMPTS = 10;
    /** to inform that the user supplied a value from the command line for the number of "add" attempts */
    protected static boolean NB_OF_ADD_NODE_ATTEMPTS_USER_SUPPLIED = false;
    /** Name of the java property to set the number of attempts performed to add a node to the resource manager */
    protected final static String NB_OF_ADD_NODE_ATTEMPTS_PROP_NAME = "proactive.node.add.attempts";

    /** The delay, in millis, between two attempts to add a node */
    protected static int ADD_NODE_ATTEMPTS_DELAY_IN_MS = 5000;
    /** to inform that the user supplied a value from the command line for the delay between two add attempts*/
    protected static boolean ADD_NODE_ATTEMPTS_DELAY_IN_MS_USER_SUPPLIED = false;
    /** Name of the java property to set the delay between two attempts performed to add a node to the resource manager */
    protected final static String ADD_NODE_ATTEMPTS_DELAY_PROP_NAME = "proactive.node.add.delay";
    /** Name of the java property to set the node source name */
    protected final static String NODESOURCE_PROP_NAME = "proactive.node.nodesource";

{'fraction_non_alphanumeric': 0.09282990083905415, 'fraction_numerical': 0.008695652173913044, 'mean_word_length': 4.151669941060904, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4827545', 'n_tokens_mistral': 3754, 'n_tokens_neox': 3614, 'n_words': 1267}