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;
}
}
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;
}
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");
}
}
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());
}
}
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;
}
Aggregations