use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.
the class SchedulerStateRest method loginWithCredential.
/**
* Login to the scheduler using a multipart form can be used either by
* submitting 2 fields ({@code username} and {@code password}) or by sending
* a credential file with field name {@code credential}.
*
* @return the session id associated to this new connection.
* @throws KeyException
* @throws LoginException
* @throws SchedulerRestException
*/
@Override
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("login")
@Produces("application/json")
public String loginWithCredential(@MultipartForm LoginForm multipart) throws LoginException, KeyException, SchedulerRestException {
try {
Session session;
if (multipart.getCredential() != null) {
Credentials credentials;
try {
session = sessionStore.createUnnamedSession();
credentials = Credentials.getCredentials(multipart.getCredential());
session.connectToScheduler(credentials);
} catch (IOException e) {
throw new LoginException(e.getMessage());
}
} else {
if ((multipart.getUsername() == null) || (multipart.getPassword() == null)) {
throw new LoginException("empty login/password");
}
session = sessionStore.create(multipart.getUsername());
CredData credData = new CredData(CredData.parseLogin(multipart.getUsername()), CredData.parseDomain(multipart.getUsername()), multipart.getPassword(), multipart.getSshKey());
session.connectToScheduler(credData);
}
return session.getSessionId();
} catch (PermissionException e) {
throw new SchedulerRestException(e);
} catch (ActiveObjectCreationException e) {
throw new SchedulerRestException(e);
} catch (SchedulerException e) {
throw new SchedulerRestException(e);
} catch (NodeException e) {
throw new SchedulerRestException(e);
}
}
use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.
the class RMNodeStarter method checkUserSuppliedParameters.
/**
* Checks that user has supplied parameters or override them with java properties values...
*/
protected void checkUserSuppliedParameters() {
// first, the number of add attempts
if (!NB_OF_ADD_NODE_ATTEMPTS_USER_SUPPLIED) {
String tmpNBAddString = System.getProperty(RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS_PROP_NAME);
if (tmpNBAddString != null) {
try {
RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS = Integer.parseInt(tmpNBAddString);
logger.debug("Number of add node attempts not supplied by user, using java property: " + RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS);
} catch (Exception e) {
logger.warn("Cannot use the value supplied by java property " + RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS_PROP_NAME + " : " + tmpNBAddString + ". Using default " + RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS);
}
} else {
logger.debug("Using default value for the number of add node attempts: " + RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS);
}
} else {
logger.debug("Using value supplied by user for the number of add node attempts: " + RMNodeStarter.NB_OF_ADD_NODE_ATTEMPTS);
}
String numberOfReconnection = System.getProperty(RMNodeStarter.NB_OF_RECONNECTION_ATTEMPTS_PROP_NAME);
if (numberOfReconnection != null) {
try {
RMNodeStarter.NB_OF_RECONNECTION_ATTEMPTS = Integer.parseInt(numberOfReconnection);
logger.debug("Number of attempts to reconnect a node to the resource manager when connection is lost: " + RMNodeStarter.NB_OF_RECONNECTION_ATTEMPTS);
} catch (Exception e) {
logger.warn("Cannot use the value supplied by java property " + RMNodeStarter.NB_OF_RECONNECTION_ATTEMPTS_PROP_NAME + " : " + numberOfReconnection + ". Using default " + RMNodeStarter.NB_OF_RECONNECTION_ATTEMPTS);
}
} else {
logger.debug("Using default value for the number of reconnection attempts: " + RMNodeStarter.NB_OF_RECONNECTION_ATTEMPTS);
}
// the delay between two add node attempts
if (!ADD_NODE_ATTEMPTS_DELAY_IN_MS_USER_SUPPLIED) {
String tmpADDNodeDelay = System.getProperty(RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_PROP_NAME);
if (tmpADDNodeDelay != null) {
try {
RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_IN_MS = Integer.parseInt(tmpADDNodeDelay);
logger.debug("Add node attempts delay not supplied by user, using java property: " + RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_IN_MS);
} catch (Exception e) {
logger.warn("Cannot use the value supplied by java property " + RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_PROP_NAME + " : " + tmpADDNodeDelay + ". Using default " + RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_IN_MS);
}
} else {
logger.debug("Using default value for the add node attempts delay: " + RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_IN_MS);
}
} else {
logger.debug("Using value supplied by user for the number the add node attempts delay: " + RMNodeStarter.ADD_NODE_ATTEMPTS_DELAY_IN_MS);
}
// the delay of the node -> rm ping
if (!PING_DELAY_IN_MS_USER_SUPPLIED) {
String tmpPingDelay = System.getProperty(RMNodeStarter.PING_DELAY_PROP_NAME);
if (tmpPingDelay != null) {
try {
RMNodeStarter.PING_DELAY_IN_MS = Integer.parseInt(tmpPingDelay);
logger.debug("RM Ping delay not supplied by user, using java property: " + RMNodeStarter.PING_DELAY_IN_MS);
} catch (Exception e) {
logger.warn("Cannot use the value supplied by java property " + RMNodeStarter.PING_DELAY_PROP_NAME + " : " + tmpPingDelay + ". Using default " + RMNodeStarter.PING_DELAY_IN_MS);
}
} else {
logger.debug("Using default value for the rm ping delay: " + RMNodeStarter.PING_DELAY_IN_MS);
}
} else {
logger.debug("Using value supplied by user for the rm ping delay: " + RMNodeStarter.PING_DELAY_IN_MS);
}
// the "joinRM" timeout
if (!WAIT_ON_JOIN_TIMEOUT_IN_MS_USER_SUPPLIED) {
String tmpWait = System.getProperty(RMNodeStarter.WAIT_ON_JOIN_PROP_NAME);
if (tmpWait != null) {
try {
RMNodeStarter.WAIT_ON_JOIN_TIMEOUT_IN_MS = Integer.parseInt(tmpWait);
logger.debug("Wait on join not supplied by user, using java property: " + RMNodeStarter.WAIT_ON_JOIN_TIMEOUT_IN_MS);
} catch (Exception e) {
logger.warn("Cannot use the value supplied by java property " + RMNodeStarter.WAIT_ON_JOIN_PROP_NAME + " : " + tmpWait + ". Using default " + RMNodeStarter.WAIT_ON_JOIN_TIMEOUT_IN_MS);
}
} else {
logger.debug("Using default value for the wait on join: " + RMNodeStarter.WAIT_ON_JOIN_TIMEOUT_IN_MS);
}
} else {
logger.debug("Using value supplied by user for the wait on join timeout: " + RMNodeStarter.WAIT_ON_JOIN_TIMEOUT_IN_MS);
}
}
use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.
the class RMCore method setNodesAvailable.
/**
* This method is called periodically by ProActive Nodes to inform the
* Resource Manager of a possible reconnection. The method is also used by
* ProActive Nodes to know if they are still known by the Resource Manager.
* For instance a Node which has been removed by a user from the
* Resource Manager is no longer known.
* <p>
* The method is defined as Immediate Service. This way it is executed in
* a dedicated Thread. It is essential in order to allow other methods to
* be executed immediately even if incoming connection to the Nodes is stopped
* or filtered while a timeout occurs when this method tries to send back a reply.
* <p>
* The {@code allNodes} data-structure is written by a single Thread only
* but read by multiple Threads.
* <p>
* Parallel executions of this method must involves different {@code nodeUrl}s.
* <p>
* The underlying calls to {@code setBusyNode} and {@code internalSetFree}
* are writing to the {@code freeNodes} data-structure. It explains why this last
* is synchronized (thread-safe).
*
* @param nodeUrls the URLs of the workers associated to the node that publishes the update.
* @return The set of worker node URLs that are unknown to the Resource Manager
* (i.e. have been removed by a user).
*/
@ImmediateService
@Override
public Set<String> setNodesAvailable(Set<String> nodeUrls) {
waitForRMCoreToBeInitializedIfNeeded();
if (logger.isTraceEnabled()) {
logger.trace("Received availability for the following workers: " + nodeUrls);
}
ImmutableSet.Builder<String> nodeUrlsNotKnownByTheRM = new ImmutableSet.Builder<>();
for (String nodeUrl : nodeUrls) {
RMNode node = this.allNodes.get(nodeUrl);
if (node == null) {
logger.warn("Cannot set node as available, the node is unknown: " + nodeUrl);
if (logger.isDebugEnabled()) {
logger.debug("Known nodes are: " + Arrays.toString(allNodes.keySet().toArray()));
}
nodeUrlsNotKnownByTheRM.add(nodeUrl);
} else if (node.isDown()) {
restoreNodeState(nodeUrl, node);
} else {
if (logger.isDebugEnabled()) {
logger.debug("The node identified by " + nodeUrl + " is known and not DOWN, no action performed");
}
}
}
return nodeUrlsNotKnownByTheRM.build();
}
use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.
the class SchedulerEventReceiver method openAndReceive.
@SuppressWarnings("rawtypes")
private void openAndReceive(final SchedulerEventListener eventListener, boolean myEventsOnly, SchedulerEvent... events) throws IOException {
Client client = ClientFactory.getDefault().newClient();
AsyncHttpClientConfig.Builder builder = new AsyncHttpClientConfig.Builder();
if (insecure) {
builder = builder.setAcceptAnyCertificate(true).setHostnameVerifier(SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
}
AsyncHttpClientConfig httpClientConfig = builder.build();
AsyncHttpClient httpClient = new AsyncHttpClient(httpClientConfig);
socket = client.create(client.newOptionsBuilder().runtime(httpClient).reconnect(false).build());
EventNotificationHandler notificationHandler = new EventNotificationHandler(eventListener);
socket.on(Event.MESSAGE, notificationHandler);
socket.on(Event.CLOSE, new Function() {
public void on(Object t) {
SchedulerEventReceiver.logger.info("#### Websocket connection is closed ####");
if (eventListener instanceof DisconnectionAwareSchedulerEventListener) {
((DisconnectionAwareSchedulerEventListener) eventListener).notifyDisconnection();
}
}
});
// initialize the connection
RequestBuilder requestBuilder = client.newRequestBuilder();
requestBuilder.method(Request.METHOD.GET);
requestBuilder.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
// authentication header
requestBuilder.header("sessionid", sessionId);
requestBuilder.uri(eventingUrl(restServerUrl));
requestBuilder.encoder(new EventSubscriptionEncoder());
requestBuilder.decoder(new EventNotificationDecoder());
requestBuilder.transport(Request.TRANSPORT.WEBSOCKET);
socket.open(requestBuilder.build());
// submit subscription request
EventSubscription eventSubscription = new EventSubscription(myEventsOnly, asStringArray(events));
socket.fire(EventCodecUtil.toJsonString(eventSubscription));
}
use of org.ow2.proactive.authentication.Connection in project scheduling by ow2-proactive.
the class SchedulerProxyUserInterface method init.
/**
* initialize the connection the scheduler.
* Must be called only once
* @param url the scheduler's url
* @param credentials the credential to be passed to the scheduler
* @throws SchedulerException thrown if the scheduler is not available
* @throws LoginException thrown if the credential is invalid
*/
public void init(String url, Credentials credentials) throws SchedulerException, LoginException {
SchedulerAuthenticationInterface auth = SchedulerConnection.join(url);
this.uischeduler = auth.login(credentials);
mbeaninfoviewer = new MBeanInfoViewer(auth, null, credentials);
}
Aggregations