Unverified Commit 3f89eab2 authored by Fabien Viale's avatar Fabien Viale Committed by GitHub
Browse files

Merge pull request #16 from ow2-proactive/master

syncrhonize fork
parents 8e2ac8d0 b114cd29
......@@ -47,13 +47,11 @@ import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileType;
import org.apache.log4j.Logger;
import org.ow2.proactive.scheduler.common.SchedulerConstants;
import org.ow2.proactive.scheduler.common.SchedulerSpaceInterface;
import org.ow2.proactive.scheduler.common.exception.NotConnectedException;
import org.ow2.proactive.scheduler.common.exception.PermissionException;
import org.ow2.proactive_grid_cloud_portal.common.Session;
import org.ow2.proactive_grid_cloud_portal.common.SessionStore;
import org.ow2.proactive_grid_cloud_portal.common.SharedSessionStore;
import org.ow2.proactive_grid_cloud_portal.dataspace.dto.ListFile;
import org.ow2.proactive_grid_cloud_portal.dataspace.util.VFSZipper;
import org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestException;
import org.ow2.proactive_grid_cloud_portal.scheduler.exception.PermissionRestException;
......@@ -372,27 +370,7 @@ public class RestDataspaceImpl implements RestDataspace {
}
}
public boolean checkFileExistsInGlobalSpace(Session session, String pathname)
throws NotConnectedException, PermissionException {
try {
return fileSystem(session).resolveFileInGlobalspace(pathname).exists();
} catch (FileSystemException e) {
logger.debug(String.format("Can't parse the file name [%s] in the global space.", pathname), e);
return false;
}
}
public boolean checkFileExistsInUserSpace(Session session, String pathname)
throws NotConnectedException, PermissionException {
try {
return fileSystem(session).resolveFileInUserspace(pathname).exists();
} catch (FileSystemException e) {
logger.debug(String.format("Can't parse the file name [%s] in the user space.", pathname), e);
return false;
}
}
private FileSystem fileSystem(Session session)
public FileSystem fileSystem(Session session)
throws FileSystemException, NotConnectedException, PermissionException {
FileSystem fs = session.fileSystem();
if (fs == null) {
......
......@@ -25,6 +25,10 @@
*/
package org.ow2.proactive_grid_cloud_portal.dataspace;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
import org.apache.log4j.Logger;
import org.ow2.proactive.scheduler.common.SchedulerConstants;
import org.ow2.proactive.scheduler.common.SchedulerSpaceInterface;
import org.ow2.proactive.scheduler.common.exception.NotConnectedException;
import org.ow2.proactive.scheduler.common.exception.PermissionException;
......@@ -34,6 +38,8 @@ import org.ow2.proactive_grid_cloud_portal.scheduler.exception.NotConnectedRestE
public class SchedulerDataspaceImpl implements SchedulerSpaceInterface {
private static final Logger logger = Logger.getLogger(SchedulerDataspaceImpl.class);
private static RestDataspaceImpl dataspaceRestApi = new RestDataspaceImpl();
private Session session;
......@@ -42,11 +48,37 @@ public class SchedulerDataspaceImpl implements SchedulerSpaceInterface {
session = dataspaceRestApi.checkSessionValidity(sessionId);
}
public boolean checkFileExistsInGlobalSpace(String pathname) throws NotConnectedException, PermissionException {
return dataspaceRestApi.checkFileExistsInGlobalSpace(session, pathname);
@Override
public boolean isFolder(String dataspace, String pathname) throws NotConnectedException, PermissionException {
try {
return resolveFile(dataspace, pathname).isFolder();
} catch (FileSystemException e) {
logger.debug(String.format("Can't parse the file [%s] in the dataspace [%s].", pathname, dataspace), e);
return false;
}
}
@Override
public boolean checkFileExists(String dataspace, String pathname)
throws NotConnectedException, PermissionException {
try {
return resolveFile(dataspace, pathname).exists();
} catch (FileSystemException e) {
logger.debug(String.format("Can't parse the file [%s] in the dataspace [%s].", pathname, dataspace), e);
return false;
}
}
public boolean checkFileExistsInUserSpace(String pathname) throws NotConnectedException, PermissionException {
return dataspaceRestApi.checkFileExistsInUserSpace(session, pathname);
private FileObject resolveFile(String dataspace, String pathname)
throws NotConnectedException, FileSystemException, PermissionException {
switch (dataspace) {
case SchedulerConstants.GLOBALSPACE_NAME:
return dataspaceRestApi.fileSystem(session).resolveFileInGlobalspace(pathname);
case SchedulerConstants.USERSPACE_NAME:
return dataspaceRestApi.fileSystem(session).resolveFileInUserspace(pathname);
default:
throw new IllegalArgumentException("Invalid dataspace name: " + dataspace);
}
}
}
......@@ -32,22 +32,22 @@ import org.ow2.proactive.scheduler.common.exception.PermissionException;
public interface SchedulerSpaceInterface {
/**
* Check if the GLOBAL DataSpace contains the specified file
*
* Check if a file in the specified DataSpace is a folder
* @param dataspace the target DataSpace name. It has two possible values, 'USERSPACE' or 'GLOBALSPACE'.
* @param pathname the file path to check
* @return whether the specified file exists in the GLOBAL DataSpace
* @throws NotConnectedException if you are not authenticated.
* @throws PermissionException if you can't access to the global data space.
* @return whether the specified file is a folder
* @throws NotConnectedException if you are not authenticated
* @throws PermissionException if you can't access to the global data space
*/
boolean checkFileExistsInGlobalSpace(String pathname) throws NotConnectedException, PermissionException;
boolean isFolder(String dataspace, String pathname) throws NotConnectedException, PermissionException;
/**
* Check if the USER DataSpace contains the specified file
*
* Check if a file exists in the specified location in the DataSpace
* @param dataspace the target DataSpace name. It has two possible values, 'USERSPACE' or 'GLOBALSPACE'.
* @param pathname the file path to check
* @return whether the specified file exists in the USER DataSpace
* @throws NotConnectedException if you are not authenticated.
* @throws PermissionException if you can't access to the user data space.
* @return whether the specified file exists in the GLOBAL DataSpace
* @throws NotConnectedException if you are not authenticated
* @throws PermissionException if you can't access to the global data space
*/
boolean checkFileExistsInUserSpace(String pathname) throws NotConnectedException, PermissionException;
boolean checkFileExists(String dataspace, String pathname) throws NotConnectedException, PermissionException;
}
......@@ -25,28 +25,26 @@
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import java.net.URI;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.URIConverter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.IdentityConverter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.GlobalFileValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator;
public class GlobalFileParserValidator extends BaseParserValidator<URI> {
public class GlobalFileParserValidator extends BaseParserValidator<String> {
public GlobalFileParserValidator(String model) throws ModelSyntaxException {
super(model, ModelType.GLOBAL_FILE);
}
@Override
protected Converter<URI> createConverter(String model) throws ModelSyntaxException {
return new URIConverter();
protected Converter<String> createConverter(String model) throws ModelSyntaxException {
return new IdentityConverter();
}
@Override
protected Validator<URI> createValidator(String model, Converter<URI> converter) {
protected Validator<String> createValidator(String model, Converter<String> converter) {
return new GlobalFileValidator();
}
}
......@@ -25,28 +25,26 @@
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.factory;
import java.net.URI;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.Converter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.URIConverter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.converter.IdentityConverter;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ModelSyntaxException;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.UserFileValidator;
import org.ow2.proactive.scheduler.common.job.factories.spi.model.validator.Validator;
public class UserFileParserValidator extends BaseParserValidator<URI> {
public class UserFileParserValidator extends BaseParserValidator<String> {
public UserFileParserValidator(String model) throws ModelSyntaxException {
super(model, ModelType.USER_FILE);
}
@Override
protected Converter<URI> createConverter(String model) throws ModelSyntaxException {
return new URIConverter();
protected Converter<String> createConverter(String model) throws ModelSyntaxException {
return new IdentityConverter();
}
@Override
protected Validator<URI> createValidator(String model, Converter<URI> converter) {
protected Validator<String> createValidator(String model, Converter<String> converter) {
return new UserFileValidator();
}
}
......@@ -25,7 +25,7 @@
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.validator;
import java.net.URI;
import static org.ow2.proactive.scheduler.common.SchedulerConstants.GLOBALSPACE_NAME;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
......@@ -35,11 +35,11 @@ import org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidator
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException;
public class GlobalFileValidator implements Validator<URI> {
public class GlobalFileValidator implements Validator<String> {
private static final Logger logger = Logger.getLogger(GlobalFileValidator.class);
@Override
public URI validate(URI parameterValue, ModelValidatorContext context) throws ValidationException {
public String validate(String parameterValue, ModelValidatorContext context) throws ValidationException {
if (context == null || context.getSpace() == null) {
// Sometimes the workflow is parsed and checked without scheduler instance (e.g., submitted from catalog).
// In this case, we don't have the access of the scheduler global dataspace, so the validity check is passed.
......@@ -49,14 +49,18 @@ public class GlobalFileValidator implements Validator<URI> {
}
// if parameterValue is not a file existing in data space, we throw ValidationException
if (StringUtils.isBlank(parameterValue.toString())) {
if (StringUtils.isBlank(parameterValue)) {
throw new ValidationException("Please provide a valid file path in the global space as the variable value.");
}
try {
if (!context.getSpace().checkFileExistsInGlobalSpace(parameterValue.toString())) {
if (!context.getSpace().checkFileExists(GLOBALSPACE_NAME, parameterValue)) {
throw new ValidationException(String.format("Could not find the file path [%s] in the global data space. Please add the file into the global data space or change the variable value to a valid path.",
parameterValue));
}
if (context.getSpace().isFolder(GLOBALSPACE_NAME, parameterValue)) {
throw new ValidationException(String.format("The file path [%s] in the global data space is a folder instead of a regular file. Please change the variable value to a valid path of a regular file.",
parameterValue));
}
} catch (NotConnectedException | PermissionException e) {
throw new ValidationException("Could not read global data space files from the scheduler, make sure you are connected and you have permission rights to read global data space files.",
e);
......
......@@ -25,7 +25,7 @@
*/
package org.ow2.proactive.scheduler.common.job.factories.spi.model.validator;
import java.net.URI;
import static org.ow2.proactive.scheduler.common.SchedulerConstants.USERSPACE_NAME;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
......@@ -35,11 +35,11 @@ import org.ow2.proactive.scheduler.common.job.factories.spi.model.ModelValidator
import org.ow2.proactive.scheduler.common.job.factories.spi.model.exceptions.ValidationException;
public class UserFileValidator implements Validator<URI> {
public class UserFileValidator implements Validator<String> {
private static final Logger logger = Logger.getLogger(UserFileValidator.class);
@Override
public URI validate(URI parameterValue, ModelValidatorContext context) throws ValidationException {
public String validate(String parameterValue, ModelValidatorContext context) throws ValidationException {
if (context == null || context.getSpace() == null) {
// Sometimes the workflow is parsed and checked without scheduler instance (e.g., submitted from catalog).
// In this case, we don't have the access of the scheduler user dataspace, so the validity check is passed.
......@@ -49,14 +49,18 @@ public class UserFileValidator implements Validator<URI> {
}
// if parameterValue is not a file existing in data space, we throw ValidationException
if (StringUtils.isBlank(parameterValue.toString())) {
if (StringUtils.isBlank(parameterValue)) {
throw new ValidationException("Please provide a valid file path in the user space as the variable value.");
}
try {
if (!context.getSpace().checkFileExistsInUserSpace(parameterValue.toString())) {
if (!context.getSpace().checkFileExists(USERSPACE_NAME, parameterValue)) {
throw new ValidationException(String.format("Could not find the file path [%s] in the user data space. Please add the file into the user data space or change the variable value to a valid path.",
parameterValue));
}
if (context.getSpace().isFolder(USERSPACE_NAME, parameterValue)) {
throw new ValidationException(String.format("The file path [%s] in the user data space is a folder instead of a regular file. Please change the variable value to a valid path of a regular file.",
parameterValue));
}
} catch (NotConnectedException | PermissionException e) {
throw new ValidationException("Could not read user data space files from the scheduler, make sure you are connected and you have permission rights to read user data space files.",
e);
......
......@@ -86,6 +86,8 @@ import org.objectweb.proactive.core.ProActiveException;
import org.objectweb.proactive.core.UniqueID;
import org.objectweb.proactive.core.body.request.Request;
import org.objectweb.proactive.extensions.annotation.ActiveObject;
import org.objectweb.proactive.extensions.dataspaces.api.DataSpacesFileObject;
import org.objectweb.proactive.extensions.dataspaces.exceptions.FileSystemException;
import org.objectweb.proactive.utils.NamedThreadFactory;
import org.ow2.proactive.authentication.UserData;
import org.ow2.proactive.authentication.crypto.Credentials;
......@@ -1681,17 +1683,31 @@ public class SchedulerFrontend implements InitActive, Scheduler, RunActive, Sche
@Override
@ImmediateService
public boolean checkFileExistsInGlobalSpace(String pathname) throws NotConnectedException, PermissionException {
frontendState.checkPermission("checkFileExistsInGlobalSpace",
"You don't have permissions to check the file existence in the GLOBAL Space");
return this.spacesSupport.checkFileExistsInGlobalSpace(pathname);
public boolean isFolder(String dataspace, String pathname) throws NotConnectedException, PermissionException {
try {
UserIdentificationImpl userId = frontendState.checkPermission("isFolder",
"You don't have permissions to check the file type in the DataSpace");
DataSpacesFileObject file = this.spacesSupport.resolveFile(dataspace, userId.getUsername(), pathname);
return file.isFolder();
} catch (FileSystemException e) {
logger.debug(String.format("Can't parse the directory [%s] in the user space.", pathname), e);
return false;
}
}
@Override
@ImmediateService
public boolean checkFileExistsInUserSpace(String pathname) throws NotConnectedException, PermissionException {
UserIdentificationImpl userId = frontendState.checkPermission("checkFileExistsInUserSpace",
"You don't have permissions to check the file existence in the USER Space");
return this.spacesSupport.checkFileExistsInUserSpace(userId.getUsername(), pathname);
public boolean checkFileExists(String dataspace, String pathname)
throws NotConnectedException, PermissionException {
try {
UserIdentificationImpl userId = frontendState.checkPermission("checkFileExists",
"You don't have permissions to check the file existence in the DataSpace");
DataSpacesFileObject file = this.spacesSupport.resolveFile(dataspace, userId.getUsername(), pathname);
return file.exists();
} catch (FileSystemException e) {
logger.debug(String.format("Can't parse the directory [%s] in the user space.", pathname), e);
return false;
}
}
}
......@@ -143,32 +143,22 @@ public class SchedulerSpacesSupport {
}
/**
* Check whether a file path exist in global space
*
* @param pathname the file path to check
* @return whether the file exist in global space
* Get the file object of a file path in the specified dataspace
* @param dataspace the target DataSpace name. It has two possible values, 'USERSPACE' or 'GLOBALSPACE'.
* @param username the user's name, it can be null when the dataspace is 'GLOBALSPACE'.
* @param pathname the relative file path under the specified dataspace
* @return the file object
* @throws FileSystemException On error parsing the file path.
*/
public boolean checkFileExistsInGlobalSpace(String pathname) {
try {
return this.globalSpace.resolveFile(pathname).exists();
} catch (FileSystemException e) {
logger.debug(String.format("Can't parse the file name [%s] in the global space.", pathname), e);
return false;
}
}
/**
* Check whether a file path exist in user space
* @param username the user's name
* @param pathname the file path to check
* @return whether the file exist in user space
*/
public boolean checkFileExistsInUserSpace(String username, String pathname) {
try {
return this.getUserSpace(username).resolveFile(pathname).exists();
} catch (FileSystemException e) {
logger.debug(String.format("Can't parse file name [%s] in user [%s] dataspace.", pathname, username), e);
return false;
public DataSpacesFileObject resolveFile(String dataspace, String username, String pathname)
throws FileSystemException {
switch (dataspace) {
case SchedulerConstants.GLOBALSPACE_NAME:
return this.getGlobalSpace().resolveFile(pathname);
case SchedulerConstants.USERSPACE_NAME:
return this.getUserSpace(username).resolveFile(pathname);
default:
throw new IllegalArgumentException("Invalid dataspace name: " + dataspace);
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment