Search in sources :

Example 1 with UserCredentials

use of org.objectweb.proactive.extensions.dataspaces.api.UserCredentials in project scheduling by ow2-proactive.

the class TaskProActiveDataspaces method initDataSpaces.

private void initDataSpaces() throws Exception {
    long startTime = System.currentTimeMillis();
    // configure node for application
    String appId = taskId.toString();
    // prepare scratch, input, output
    Node node = PAActiveObject.getNode();
    logger.info("Configuring dataspaces for app " + appId + " on " + node.getNodeInformation().getName());
    DataSpacesNodes.configureApplication(node, appId, namingService);
    SCRATCH = PADataSpaces.resolveScratchForAO();
    logger.info("SCRATCH space is " + SCRATCH.getRealURI());
    // Set the scratch folder writable for everyone
    if (!SCRATCH.setWritable(true, false)) {
        logger.warn("Missing permission to change write permissions to " + getScratchFolder());
    }
    InputOutputSpaceConfiguration cacheConfiguration = DataSpaceNodeConfigurationAgent.getCacheSpaceConfiguration();
    if (cacheConfiguration != null) {
        final String cacheName = cacheConfiguration.getName();
        cacheSpaceInstanceInfo = new SpaceInstanceInfo(appId, cacheConfiguration);
        try {
            namingService.register(cacheSpaceInstanceInfo);
        } catch (SpaceAlreadyRegisteredException e) {
            // this is a rare case where the cache space has already been registered for the same task and there was a node failure.
            namingService.unregister(cacheSpaceInstanceInfo.getMountingPoint());
            namingService.register(cacheSpaceInstanceInfo);
        }
        CACHE = initDataSpace(new Callable<DataSpacesFileObject>() {

            @Override
            public DataSpacesFileObject call() throws Exception {
                return PADataSpaces.resolveOutput(cacheName);
            }
        }, "CACHE", false);
    } else {
        logger.error("No Cache space configuration found, cache space is disabled.");
    }
    UserCredentials userCredentials;
    if (decrypter != null) {
        CredData credData = decrypter.decrypt();
        userCredentials = new UserCredentials(credData.getLogin(), credData.getPassword(), credData.getDomain(), credData.getKey());
    } else {
        logger.warn("No decryter found");
        userCredentials = new UserCredentials();
    }
    INPUT = initDataSpace(new Callable<DataSpacesFileObject>() {

        @Override
        public DataSpacesFileObject call() throws Exception {
            return PADataSpaces.resolveDefaultInput();
        }
    }, "INPUT", true);
    OUTPUT = initDataSpace(new Callable<DataSpacesFileObject>() {

        @Override
        public DataSpacesFileObject call() throws Exception {
            return PADataSpaces.resolveDefaultOutput();
        }
    }, "OUTPUT", false);
    GLOBAL = initDataSpace(new Callable<DataSpacesFileObject>() {

        @Override
        public DataSpacesFileObject call() throws Exception {
            return PADataSpaces.resolveOutput(SchedulerConstants.GLOBALSPACE_NAME);
        }
    }, "GLOBAL", false);
    USER = initDataSpace(new Callable<DataSpacesFileObject>() {

        @Override
        public DataSpacesFileObject call() throws Exception {
            return PADataSpaces.resolveOutput(SchedulerConstants.USERSPACE_NAME, userCredentials);
        }
    }, "USER", false);
    logger.info("Time needed to mount data spaces: " + (System.currentTimeMillis() - startTime) + " ms");
}
Also used : InputOutputSpaceConfiguration(org.objectweb.proactive.extensions.dataspaces.core.InputOutputSpaceConfiguration) SpaceInstanceInfo(org.objectweb.proactive.extensions.dataspaces.core.SpaceInstanceInfo) SpaceAlreadyRegisteredException(org.objectweb.proactive.extensions.dataspaces.exceptions.SpaceAlreadyRegisteredException) Node(org.objectweb.proactive.core.node.Node) CredData(org.ow2.proactive.authentication.crypto.CredData) UserCredentials(org.objectweb.proactive.extensions.dataspaces.api.UserCredentials) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) Callable(java.util.concurrent.Callable)

Example 2 with UserCredentials

use of org.objectweb.proactive.extensions.dataspaces.api.UserCredentials in project scheduling by ow2-proactive.

the class SchedulerSpacesSupport method registerUserSpace.

/**
 * This method creates a dedicated USER space for the user which successfully connected
 * This USER space is a subspace of the scheduler default USER space,
 * A sub-folder named with the username is created to contain the USER space
 *
 * @param username the username of an identified user
 * @param credentials credentials of the user
 */
public void registerUserSpace(String username, Credentials credentials) {
    if (this.userGlobalSpaces.get(username) == null && shouldRegisterUserSpace(username)) {
        synchronized (this) {
            DataSpacesFileObject userSpace;
            String userSpaceName = SchedulerConstants.USERSPACE_NAME + "_" + username;
            if (!PASchedulerProperties.DATASPACE_DEFAULTUSER_URL.isSet()) {
                logger.warn("URL of the root USER space is not set, cannot create a USER space for " + username);
                return;
            }
            String localpath = PASchedulerProperties.DATASPACE_DEFAULTUSER_LOCALPATH.getValueAsStringOrNull();
            String hostname = PASchedulerProperties.DATASPACE_DEFAULTUSER_HOSTNAME.getValueAsStringOrNull();
            try {
                UserCredentials userCredentials = getUserCredentials(username, credentials);
                DataSpaceServiceStarter.getDataSpaceServiceStarter().createSpaceWithUserNameSubfolder(username, userCredentials, SchedulerConstants.SCHEDULER_DATASPACE_APPLICATION_ID, userSpaceName, PASchedulerProperties.DATASPACE_DEFAULTUSER_URL.getValueAsString(), localpath, hostname, false, true);
                // immediately retrieve the User Space
                userSpace = PADataSpaces.resolveOutput(userSpaceName, userCredentials);
                logger.info("USER space for user " + username + " is at " + userSpace.getAllRealURIs());
                // register the user GlobalSpace to the frontend state
                this.userGlobalSpaces.put(username, userSpace);
            } catch (Exception e) {
                logger.error("", e);
                return;
            }
        }
    }
}
Also used : DataSpacesFileObject(org.objectweb.proactive.extensions.dataspaces.api.DataSpacesFileObject) UserCredentials(org.objectweb.proactive.extensions.dataspaces.api.UserCredentials) FileSystemException(org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException) KeyException(java.security.KeyException)

Example 3 with UserCredentials

use of org.objectweb.proactive.extensions.dataspaces.api.UserCredentials in project scheduling by ow2-proactive.

the class SchedulerSpacesSupport method getUserCredentials.

private UserCredentials getUserCredentials(String username, Credentials credentials) {
    UserCredentials userCredentials = new UserCredentials();
    if (!PASchedulerProperties.DATASPACE_DEFAULTUSER_IMPERSONATION.getValueAsBoolean() || isInternalUser(username)) {
        return userCredentials;
    }
    try {
        CredData decryptedUserCredentials = credentials.decrypt(corePrivateKey);
        if (PASchedulerProperties.SCHEDULER_AUTH_GLOBAL_DOMAIN.isSet() && decryptedUserCredentials.getDomain() == null) {
            decryptedUserCredentials.setDomain(PASchedulerProperties.SCHEDULER_AUTH_GLOBAL_DOMAIN.getValueAsString());
        }
        userCredentials = new UserCredentials(decryptedUserCredentials.getLogin(), decryptedUserCredentials.getPassword(), decryptedUserCredentials.getDomain(), decryptedUserCredentials.getKey());
    } catch (Exception e) {
        logger.error("Could not decrypt user credentials", e);
    }
    return userCredentials;
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) UserCredentials(org.objectweb.proactive.extensions.dataspaces.api.UserCredentials) FileSystemException(org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException) KeyException(java.security.KeyException)

Example 4 with UserCredentials

use of org.objectweb.proactive.extensions.dataspaces.api.UserCredentials in project scheduling by ow2-proactive.

the class InternalJob method getUserCredentials.

private UserCredentials getUserCredentials() {
    UserCredentials userCredentials = null;
    try {
        CredData decryptedUserCredentials = credentials.decrypt(corePrivateKey);
        if (PASchedulerProperties.SCHEDULER_AUTH_GLOBAL_DOMAIN.isSet() && decryptedUserCredentials.getDomain() == null) {
            decryptedUserCredentials.setDomain(PASchedulerProperties.SCHEDULER_AUTH_GLOBAL_DOMAIN.getValueAsString());
        }
        userCredentials = new UserCredentials(decryptedUserCredentials.getLogin(), decryptedUserCredentials.getPassword(), decryptedUserCredentials.getDomain(), decryptedUserCredentials.getKey());
    } catch (Exception e) {
        LOGGER.error("Could not decrypt user credentials", e);
    }
    return userCredentials;
}
Also used : CredData(org.ow2.proactive.authentication.crypto.CredData) UserCredentials(org.objectweb.proactive.extensions.dataspaces.api.UserCredentials) KeyException(java.security.KeyException) ExecutableCreationException(org.ow2.proactive.scheduler.common.exception.ExecutableCreationException) UnknownTaskException(org.ow2.proactive.scheduler.common.exception.UnknownTaskException) IOException(java.io.IOException)

Example 5 with UserCredentials

use of org.objectweb.proactive.extensions.dataspaces.api.UserCredentials in project scheduling by ow2-proactive.

the class InternalJob method startDataSpaceApplication.

/**
 * Start dataspace configuration and application
 */
public void startDataSpaceApplication(NamingService namingService, List<InternalTask> tasks) {
    if (taskDataSpaceApplications == null) {
        taskDataSpaceApplications = new HashMap<>();
    }
    UserCredentials userCredentials = getUserCredentials();
    for (InternalTask internalTask : tasks) {
        long taskId = internalTask.getId().longValue();
        // if a task restart due to a failure for instance
        if (!taskDataSpaceApplications.containsKey(taskId)) {
            String appId = internalTask.getId().toString();
            TaskDataSpaceApplication taskDataSpaceApplication = new TaskDataSpaceApplication(appId, namingService);
            taskDataSpaceApplications.put(taskId, taskDataSpaceApplication);
            taskDataSpaceApplication.startDataSpaceApplication(getInputSpace(), getOutputSpace(), getGlobalSpace(), getUserSpace(), getOwner(), userCredentials, getId());
        }
    }
}
Also used : InternalTask(org.ow2.proactive.scheduler.task.internal.InternalTask) UserCredentials(org.objectweb.proactive.extensions.dataspaces.api.UserCredentials)

Aggregations

UserCredentials (org.objectweb.proactive.extensions.dataspaces.api.UserCredentials)5 KeyException (java.security.KeyException)3 CredData (org.ow2.proactive.authentication.crypto.CredData)3 FileSystemException (org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 IOException (java.io.IOException)1 Callable (java.util.concurrent.Callable)1 Node (org.objectweb.proactive.core.node.Node)1 DataSpacesFileObject (org.objectweb.proactive.extensions.dataspaces.api.DataSpacesFileObject)1 InputOutputSpaceConfiguration (org.objectweb.proactive.extensions.dataspaces.core.InputOutputSpaceConfiguration)1 SpaceInstanceInfo (org.objectweb.proactive.extensions.dataspaces.core.SpaceInstanceInfo)1 SpaceAlreadyRegisteredException (org.objectweb.proactive.extensions.dataspaces.exceptions.SpaceAlreadyRegisteredException)1 ExecutableCreationException (org.ow2.proactive.scheduler.common.exception.ExecutableCreationException)1 UnknownTaskException (org.ow2.proactive.scheduler.common.exception.UnknownTaskException)1 InternalTask (org.ow2.proactive.scheduler.task.internal.InternalTask)1