Search in sources :

Example 1 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class RMNodeStarter method addNodeToResourceManager.

private void addNodeToResourceManager(String rmURL, Node node, ResourceManager rm) {
    // Add the created node to the Resource Manager with a specified
    // number of attempts and a timeout between each attempt
    boolean isNodeAdded = false;
    int attempts = 0;
    String nodeUrl = node.getNodeInformation().getURL();
    String nodeName = node.getNodeInformation().getName();
    logger.info("Adding node " + nodeName + " to Resource Manager.");
    while ((!isNodeAdded) && (attempts < NB_OF_ADD_NODE_ATTEMPTS)) {
        attempts++;
        try {
            if (this.nodeSourceName != null) {
                isNodeAdded = rm.addNode(nodeUrl, this.nodeSourceName).getBooleanValue();
            } else {
                isNodeAdded = rm.addNode(nodeUrl).getBooleanValue();
            }
        } catch (AddingNodesException addException) {
            addException.printStackTrace();
            System.exit(ExitStatus.RMNODE_ADD_ERROR.exitCode);
        }
        if (isNodeAdded) {
            if (removePrevious) {
                // try to remove previous URL if different...
                String previousURL = this.getAndDeleteNodeURL(nodeName, rank);
                if (previousURL != null && !previousURL.equals(nodeUrl)) {
                    logger.info("Different previous URL registered by this agent has been found. Remove previous registration.");
                    rm.removeNode(previousURL, true);
                }
                // store the node URL
                this.storeNodeURL(nodeName, rank, nodeUrl);
                logger.info("Node " + nodeUrl + " added. URL is stored in " + getNodeURLFilename(nodeName, rank));
            } else {
                logger.info("Node " + nodeUrl + " added.");
            }
        } else {
            // not yet registered
            logger.info("Attempt number " + attempts + " out of " + NB_OF_ADD_NODE_ATTEMPTS + " to add the local node to the Resource Manager at " + rmURL + " has failed.");
            try {
                Thread.sleep(ADD_NODE_ATTEMPTS_DELAY_IN_MS);
            } catch (InterruptedException e) {
                logger.info("Interrupted", e);
            }
        }
    }
    if (!isNodeAdded) {
        // if not registered
        logger.error("The Resource Manager was unable to add the local node " + nodeUrl + " after " + NB_OF_ADD_NODE_ATTEMPTS + " attempts. The application will exit.");
        System.exit(ExitStatus.RMNODE_ADD_ERROR.exitCode);
    }
}
Also used : AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString)

Example 2 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class RMNodeStarter method registerInRM.

/**
 * Tries to join to the Resource Manager with a specified timeout
 * at the given URL, logs with provided credentials and adds the local node to
 * the Resource Manager. Handles all errors/exceptions.
 */
protected ResourceManager registerInRM(final Credentials credentials, final String rmURL, final String nodeName, final Collection<Node> nodes) {
    RMAuthentication auth = joinResourceManager(rmURL);
    final ResourceManager rm = loginToResourceManager(credentials, auth);
    SigarExposer sigarExposer = null;
    if (!disabledMonitoring) {
        // initializing JMX server with Sigar beans
        sigarExposer = new SigarExposer(nodeName);
        final RMAuthentication rmAuth = auth;
        sigarExposer.boot(auth, false, new PermissionChecker() {

            @Override
            public boolean checkPermission(Credentials cred) {
                ResourceManager rm = null;
                try {
                    rm = rmAuth.login(cred);
                    if (NB_OF_ADD_NODE_ATTEMPTS == 0)
                        return true;
                    boolean isAdmin = rm.isNodeAdmin(nodes.iterator().next().getNodeInformation().getURL()).getBooleanValue();
                    if (!isAdmin) {
                        throw new SecurityException("Permission denied");
                    }
                    return true;
                } catch (LoginException e) {
                    throw new SecurityException(e);
                } finally {
                    if (rm != null) {
                        rm.disconnect();
                    }
                }
            }
        });
    } else {
        logger.info("JMX monitoring is disabled.");
    }
    for (final Node node : nodes) {
        nodeSetJmxUrl(sigarExposer, node);
        addNodeToResourceManager(rmURL, node, rm);
    }
    return rm;
}
Also used : SigarExposer(org.ow2.proactive.resourcemanager.node.jmx.SigarExposer) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) PermissionChecker(org.ow2.proactive.jmx.PermissionChecker) Node(org.objectweb.proactive.core.node.Node) LoginException(javax.security.auth.login.LoginException) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 3 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class RMStarter method main.

public static void main(String[] args) {
    configureRMHome();
    configureSecurityManager();
    configureLogging();
    args = JVMPropertiesPreloader.overrideJVMProperties(args);
    initOptions();
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
        if (cmd.hasOption("h")) {
            displayHelp();
        }
        logger.info("Starting the resource manager...");
        RMFactory.setOsJavaProperty();
        boolean localNodes = false;
        if (cmd.hasOption("localNodes")) {
            localNodes = true;
            if (cmd.hasOption("timeout")) {
                String timeout = cmd.getOptionValue("t");
                try {
                    nodeTimeout = Integer.parseInt(timeout);
                } catch (Exception e) {
                    logger.error("Wrong value for timeout option: " + timeout, e);
                }
            }
        }
        // starting clean resource manager
        RMAuthentication auth = RMFactory.startLocal();
        int defaultNodesNumber = PAResourceManagerProperties.RM_NB_LOCAL_NODES.getValueAsInt();
        // -1 means that the number of local nodes depends of the number of cores in the local machine
        if (defaultNodesNumber == -1) {
            defaultNodesNumber = DEFAULT_NODES_NUMBER;
        }
        if (localNodes && defaultNodesNumber > 0) {
            ResourceManager resourceManager = auth.login(Credentials.getCredentials(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
            String nodeSourceName = NodeSource.DEFAULT_LOCAL_NODES_NODE_SOURCE_NAME;
            // first im parameter is default rm url
            byte[] creds = FileToBytesConverter.convertFileToByteArray(new File(PAResourceManagerProperties.getAbsolutePath(PAResourceManagerProperties.RM_CREDS.getValueAsString())));
            resourceManager.createNodeSource(nodeSourceName, LocalInfrastructure.class.getName(), new Object[] { creds, defaultNodesNumber, nodeTimeout, "" }, RestartDownNodesPolicy.class.getName(), null, NodeSource.DEFAULT_LOCAL_NODES_NODE_SOURCE_RECOVERABLE);
            resourceManager.disconnect();
            logger.info("The resource manager with " + defaultNodesNumber + " local nodes created on " + auth.getHostURL());
        } else {
            logger.info("The resource manager created on " + auth.getHostURL());
        }
    } catch (ParseException e1) {
        displayHelp();
    } catch (Exception e) {
        logger.error("", e);
        System.exit(3);
    }
}
Also used : ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) ParseException(org.apache.commons.cli.ParseException) CommandLine(org.apache.commons.cli.CommandLine) RestartDownNodesPolicy(org.ow2.proactive.resourcemanager.nodesource.policy.RestartDownNodesPolicy) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) LocalInfrastructure(org.ow2.proactive.resourcemanager.nodesource.infrastructure.LocalInfrastructure) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 4 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class AuthenticationTest method loginAsAdmin.

private void loginAsAdmin(RMAuthentication auth) throws LoginException, KeyException {
    log("Test 1");
    log("Trying to authorized with correct admin name and password");
    Credentials cred = Credentials.createCredentials(new CredData(TestUsers.DEMO.username, TestUsers.DEMO.password), auth.getPublicKey());
    ResourceManager admin = auth.login(cred);
    admin.disconnect().getBooleanValue();
    log("Passed: successful authentication");
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) Credentials(org.ow2.proactive.authentication.crypto.Credentials)

Example 5 with ResourceManager

use of org.ow2.proactive.resourcemanager.frontend.ResourceManager in project scheduling by ow2-proactive.

the class AddGetReleaseRemoveTest method action.

@Test
public void action() throws Exception {
    final ResourceManager rm = rmHelper.getResourceManager();
    // The username and thr password must be the same a used to connect to the RM
    final String adminLogin = TestUsers.TEST.username;
    final String adminPassword = TestUsers.TEST.password;
    // All accounting values are checked through JMX
    final RMAuthentication auth = rmHelper.getRMAuth();
    final PublicKey pubKey = auth.getPublicKey();
    final Credentials adminCreds = Credentials.createCredentials(new CredData(adminLogin, adminPassword), pubKey);
    final JMXServiceURL jmxRmiServiceURL = new JMXServiceURL(auth.getJMXConnectorURL(JMXTransportProtocol.RMI));
    final HashMap<String, Object> env = new HashMap<>(1);
    env.put(JMXConnector.CREDENTIALS, new Object[] { adminLogin, adminCreds });
    // Connect to the JMX RMI Connector Server
    final ObjectName myAccountMBeanName = new ObjectName(RMJMXBeans.MYACCOUNT_MBEAN_NAME);
    final ObjectName managementMBeanName = new ObjectName(RMJMXBeans.MANAGEMENT_MBEAN_NAME);
    final JMXConnector jmxConnector = JMXConnectorFactory.connect(jmxRmiServiceURL, env);
    final MBeanServerConnection conn = jmxConnector.getMBeanServerConnection();
    // Ensure that no refreshes was done and all account values are correctly initialized
    AttributeList atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
    long usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue();
    long providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue();
    int providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue();
    // ADD, GET, RELEASE, REMOVE
    // 1) ADD
    final long beforeAddTime = System.currentTimeMillis();
    testNode = rmHelper.createNode("test");
    Node node = testNode.getNode();
    final String nodeURL = node.getNodeInformation().getURL();
    rm.addNode(nodeURL).getBooleanValue();
    // We eat the configuring to free event
    rmHelper.waitForNodeEvent(RMEventType.NODE_ADDED, nodeURL);
    rmHelper.waitForNodeEvent(RMEventType.NODE_STATE_CHANGED, nodeURL);
    // 2) GET
    final long beforeGetTime = System.currentTimeMillis();
    node = rm.getAtMostNodes(1, null).get(0);
    // Sleep a certain amount of time that will be the minimum amount of the GET->RELEASE duration
    Thread.sleep(GR_DURATION);
    // 3) RELEASE
    rm.releaseNode(node).getBooleanValue();
    final long getReleaseMaxDuration = System.currentTimeMillis() - beforeGetTime;
    // 4) REMOVE
    rm.removeNode(nodeURL, true).getBooleanValue();
    final long addRemoveMaxDuration = System.currentTimeMillis() - beforeAddTime;
    // Refresh the account manager
    conn.invoke(managementMBeanName, "clearAccoutingCache", null, null);
    // Check account values validity
    atts = conn.getAttributes(myAccountMBeanName, new String[] { "UsedNodeTime", "ProvidedNodeTime", "ProvidedNodesCount" });
    usedNodeTime = (Long) ((Attribute) atts.get(0)).getValue() - usedNodeTime;
    providedNodeTime = (Long) ((Attribute) atts.get(1)).getValue() - providedNodeTime;
    providedNodesCount = (Integer) ((Attribute) atts.get(2)).getValue() - providedNodesCount;
    Assert.assertTrue("Invalid value of the usedNodeTime attribute (usedNodeTime=" + usedNodeTime + ")", (usedNodeTime >= GR_DURATION));
    Assert.assertTrue("Invalid value of the usedNodeTime attribute (getReleaseMaxDuration=" + getReleaseMaxDuration + ")", (usedNodeTime <= getReleaseMaxDuration));
    Assert.assertTrue("Invalid value of the providedNodeTime attribute", (providedNodeTime >= usedNodeTime) && (providedNodeTime <= addRemoveMaxDuration));
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) HashMap(java.util.HashMap) PublicKey(java.security.PublicKey) AttributeList(javax.management.AttributeList) Node(org.objectweb.proactive.core.node.Node) CredData(org.ow2.proactive.authentication.crypto.CredData) ResourceManager(org.ow2.proactive.resourcemanager.frontend.ResourceManager) ObjectName(javax.management.ObjectName) RMAuthentication(org.ow2.proactive.resourcemanager.authentication.RMAuthentication) JMXConnector(javax.management.remote.JMXConnector) Credentials(org.ow2.proactive.authentication.crypto.Credentials) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test) RMFunctionalTest(functionaltests.utils.RMFunctionalTest)

Aggregations

ResourceManager (org.ow2.proactive.resourcemanager.frontend.ResourceManager)45 NodeSet (org.ow2.proactive.utils.NodeSet)26 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)25 Test (org.junit.Test)25 Node (org.objectweb.proactive.core.node.Node)16 File (java.io.File)14 Credentials (org.ow2.proactive.authentication.crypto.Credentials)14 Criteria (org.ow2.proactive.utils.Criteria)13 HashMap (java.util.HashMap)11 CredData (org.ow2.proactive.authentication.crypto.CredData)11 StaticPolicy (org.ow2.proactive.resourcemanager.nodesource.policy.StaticPolicy)11 RMAuthentication (org.ow2.proactive.resourcemanager.authentication.RMAuthentication)10 RMNodeEvent (org.ow2.proactive.resourcemanager.common.event.RMNodeEvent)10 TestNode (functionaltests.utils.TestNode)9 SelectionScript (org.ow2.proactive.scripting.SelectionScript)9 RMMonitorEventReceiver (functionaltests.monitor.RMMonitorEventReceiver)5 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)5 PublicKey (java.security.PublicKey)4