Search in sources :

Example 21 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class RMStateCaching method getRMInitialState.

/**
 * @return cached RM State as returned by {@link RMProxyUserInterface#getRMInitialState(long)}
 */
public static RMStateDelta getRMInitialState(long counter) {
    try {
        long startTime = System.currentTimeMillis();
        final RMStateDelta state = PAFuture.getFutureValue(rm.getRMInitialState(counter));
        long time = System.currentTimeMillis() - startTime;
        logger.debug(String.format("Updated RM initial state in %d ms", time));
        return state;
    } catch (Exception e) {
        logger.error("Exception occurrend while updating RM state cache, connection reset", e);
        throw e;
    }
}
Also used : RMStateDelta(org.ow2.proactive.resourcemanager.common.event.dto.RMStateDelta)

Example 22 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class RMNodeStarter method allNodesAreAvailable.

private boolean allNodesAreAvailable(Map<String, Node> nodes, ResourceManager rm) {
    if (rm == null) {
        throw new NotConnectedException("No connection to RM");
    }
    Set<String> unknownNodeUrls = PAFuture.getFutureValue(rm.setNodesAvailable(ImmutableSet.copyOf(nodes.keySet())), nodeAvailabilityReportTimeoutDelay);
    for (String unknownNodeUrl : unknownNodeUrls) {
        killWorkerNodeIfRemovedByUser(nodes, unknownNodeUrl);
    }
    int nodeCount = nodes.size();
    if (logger.isDebugEnabled()) {
        logger.debug("Node count is equal to " + nodeCount);
    }
    return nodeCount > 0;
}
Also used : NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString)

Example 23 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class RMFactory method startLocal.

/**
 * Creates and starts a Resource manager on the local host using the given initializer to configure it.
 * Only one RM can be started by JVM.
 *
 * @param initializer Use to configure the Resource Manager before starting it.
 * 		This parameter can be null, if so the Resource Manager will try to start on the JVM properties and
 * 		the "pa.rm.home" property MUST be set to the root of the RM directory.
 * @return a RM authentication that allow you to administer the RM or get its connection URL.
 *
 * @throws NodeException If the RM's node can't be created
 * @throws ActiveObjectCreationException If RMCore cannot be created
 * @throws AlreadyBoundException if a node with the same RMNode's name is already exist.
 * @throws IOException If node and RMCore fails.
 * @throws RMException if the connection to the authentication interface fails.
 */
public static RMAuthentication startLocal(RMInitializer initializer) throws Exception {
    if (rmcore == null) {
        if (initializer != null) {
            // configure application
            configure(initializer);
        }
        configureLog4j();
        Node nodeRM = NodeFactory.createLocalNode(PAResourceManagerProperties.RM_NODE_NAME.getValueAsString(), false, null, null);
        String RMCoreName = RMConstants.NAME_ACTIVE_OBJECT_RMCORE;
        rmcore = (RMCore) // the class to deploy
        PAActiveObject.newActive(// the class to deploy
        RMCore.class.getName(), new Object[] { RMCoreName, nodeRM }, nodeRM);
        logger.debug("New RM core started locally");
        return RMConnection.waitAndJoin(null);
    } else {
        throw new RMException("RM Core already running locally");
    }
}
Also used : RMCore(org.ow2.proactive.resourcemanager.core.RMCore) Node(org.objectweb.proactive.core.node.Node) RMException(org.ow2.proactive.resourcemanager.exception.RMException)

Example 24 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class RMCore method disconnect.

/**
 * Disconnects the client and releases all nodes held by him
 */
public void disconnect(UniqueID clientId) {
    Client client = RMCore.clients.remove(clientId);
    if (client != null) {
        List<RMNode> nodesToRelease = new LinkedList<>();
        // expensive but relatively rare operation
        for (RMNode rmnode : new ArrayList<>(allNodes.values())) {
            // the same connection
            if (client.equals(rmnode.getOwner()) && clientId.equals(rmnode.getOwner().getId())) {
                if (rmnode.isToRemove()) {
                    removeNodeFromCoreAndSource(rmnode, client);
                } else if (rmnode.isBusy()) {
                    nodesToRelease.add(rmnode);
                }
            }
        }
        // Force the nodes cleaning here to avoid the situation
        // when the disconnected client still uses nodes.
        // In the future we may clean nodes for any release request
        nodesCleaner.cleanAndRelease(nodesToRelease);
        // update the connection info in the DB
        if (client.getHistory() != null) {
            UserHistory userHistory = client.getHistory();
            userHistory.setEndTime(System.currentTimeMillis());
            dbManager.updateUserHistory(userHistory);
        }
        logger.info(client + " disconnected from " + client.getId().shortString());
    } else {
        logger.warn("Trying to disconnect unknown client with id " + clientId.shortString());
    }
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) UserHistory(org.ow2.proactive.resourcemanager.core.history.UserHistory) ArrayList(java.util.ArrayList) Client(org.ow2.proactive.resourcemanager.authentication.Client) LinkedList(java.util.LinkedList)

Example 25 with Connection

use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.

the class LDAPLoginModule method getLDAPUserDN.

/**
 * Connects anonymously to the LDAP server <code>url</code> and retrieve
 * DN of the user <code>username</code>
 *
 * <p>
 * @exception NamingException
 *                if a naming exception is encountered.
 * <p>
 *
 * @return the String containing the UID of the user or null if the user is
 *         not found.
 */
private String getLDAPUserDN(String username) throws NamingException {
    String userDN = null;
    DirContext ctx = null;
    try {
        // Create the initial directory context
        ctx = this.connectAndGetContext();
        SearchControls sControl = new SearchControls();
        sControl.setSearchScope(SearchControls.SUBTREE_SCOPE);
        String filter = String.format(ldapProperties.getProperty(LDAPProperties.LDAP_USER_FILTER), username);
        // looking for the user dn (distinguish name)
        NamingEnumeration<SearchResult> answer = ctx.search(USERS_DN, filter, sControl);
        if (answer.hasMoreElements()) {
            SearchResult result = (SearchResult) answer.next();
            userDN = result.getNameInNamespace();
            if (logger.isDebugEnabled()) {
                logger.debug("User " + username + " has LDAP entry " + userDN);
            }
            subject.getPrincipals().add(new UserNamePrincipal(username));
            // looking for the user groups
            String groupFilter = String.format(ldapProperties.getProperty(LDAPProperties.LDAP_GROUP_FILTER), userDN);
            NamingEnumeration<SearchResult> groupResults = ctx.search(GROUPS_DN, groupFilter, sControl);
            while (groupResults.hasMoreElements()) {
                SearchResult res = (SearchResult) groupResults.next();
                Attribute attr = res.getAttributes().get(ldapProperties.getProperty(LDAPProperties.LDAP_GROUPNAME_ATTR));
                if (attr != null) {
                    String groupName = attr.get().toString();
                    subject.getPrincipals().add(new GroupNamePrincipal(groupName));
                    if (logger.isDebugEnabled()) {
                        logger.debug("User " + username + " is a member of group " + groupName);
                    }
                }
            }
        } else {
            if (logger.isDebugEnabled()) {
                logger.debug("User DN not found");
            }
        }
    } catch (NamingException e) {
        logger.error("Problem with the search in mode: " + AUTHENTICATION_METHOD + e);
        throw e;
    } finally {
        try {
            if (ctx != null) {
                ctx.close();
            }
        } catch (NamingException e) {
            logger.error("", e);
            logger.error("Problem closing LDAP connection: " + e.getMessage());
        }
    }
    return userDN;
}
Also used : UserNamePrincipal(org.ow2.proactive.authentication.principals.UserNamePrincipal) Attribute(javax.naming.directory.Attribute) SearchControls(javax.naming.directory.SearchControls) SearchResult(javax.naming.directory.SearchResult) NamingException(javax.naming.NamingException) DirContext(javax.naming.directory.DirContext) InitialDirContext(javax.naming.directory.InitialDirContext) GroupNamePrincipal(org.ow2.proactive.authentication.principals.GroupNamePrincipal)

Aggregations

SchedulerAuthenticationInterface (org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)9 KeyException (java.security.KeyException)6 LoginException (javax.security.auth.login.LoginException)6 Test (org.junit.Test)6 CredData (org.ow2.proactive.authentication.crypto.CredData)5 Credentials (org.ow2.proactive.authentication.crypto.Credentials)5 IOException (java.io.IOException)4 HashMap (java.util.HashMap)4 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)4 InternalSchedulerException (org.ow2.proactive.scheduler.common.exception.InternalSchedulerException)4 SchedulerException (org.ow2.proactive.scheduler.common.exception.SchedulerException)4 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)3 PublicKey (java.security.PublicKey)3 JMXConnector (javax.management.remote.JMXConnector)3 JMXServiceURL (javax.management.remote.JMXServiceURL)3 RMException (org.ow2.proactive.resourcemanager.exception.RMException)3 JobId (org.ow2.proactive.scheduler.common.job.JobId)3 RMFunctionalTest (functionaltests.utils.RMFunctionalTest)2 File (java.io.File)2 MBeanServerConnection (javax.management.MBeanServerConnection)2