Search in sources :

Example 1 with Connection

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);
    }
}
Also used : PermissionException(org.ow2.proactive.scheduler.common.exception.PermissionException) InternalSchedulerException(org.ow2.proactive.scheduler.common.exception.InternalSchedulerException) SchedulerException(org.ow2.proactive.scheduler.common.exception.SchedulerException) CredData(org.ow2.proactive.authentication.crypto.CredData) LoginException(javax.security.auth.login.LoginException) NodeException(org.objectweb.proactive.core.node.NodeException) IOException(java.io.IOException) SchedulerRestException(org.ow2.proactive_grid_cloud_portal.scheduler.exception.SchedulerRestException) Credentials(org.ow2.proactive.authentication.crypto.Credentials) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) HttpSession(javax.servlet.http.HttpSession) Session(org.ow2.proactive_grid_cloud_portal.common.Session) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with Connection

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);
    }
}
Also used : Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) LoginException(javax.security.auth.login.LoginException) ActiveObjectCreationException(org.objectweb.proactive.ActiveObjectCreationException) KeyException(java.security.KeyException) NotConfiguredException(org.objectweb.proactive.extensions.dataspaces.exceptions.NotConfiguredException) NodeException(org.objectweb.proactive.core.node.NodeException) ParseException(org.apache.commons.cli.ParseException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) AddingNodesException(org.ow2.proactive.resourcemanager.exception.AddingNodesException) ProActiveRuntimeException(org.objectweb.proactive.core.ProActiveRuntimeException) NotConnectedException(org.ow2.proactive.resourcemanager.exception.NotConnectedException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ProActiveException(org.objectweb.proactive.core.ProActiveException)

Example 3 with Connection

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();
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) ImmutableSet(com.google.common.collect.ImmutableSet) ImmediateService(org.objectweb.proactive.annotation.ImmediateService)

Example 4 with Connection

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));
}
Also used : RequestBuilder(org.atmosphere.wasync.RequestBuilder) RequestBuilder(org.atmosphere.wasync.RequestBuilder) Function(org.atmosphere.wasync.Function) EventSubscription(org.ow2.proactive_grid_cloud_portal.scheduler.dto.eventing.EventSubscription) AsyncHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig) Client(org.atmosphere.wasync.Client) AsyncHttpClient(com.ning.http.client.AsyncHttpClient) AsyncHttpClient(com.ning.http.client.AsyncHttpClient)

Example 5 with Connection

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);
}
Also used : MBeanInfoViewer(org.ow2.proactive.utils.console.MBeanInfoViewer) SchedulerAuthenticationInterface(org.ow2.proactive.scheduler.common.SchedulerAuthenticationInterface)

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