use of org.ow2.proactive.scheduler.common.exception.PermissionException in project scheduling by ow2-proactive.
the class DataSpaceClient method delete.
@Override
public boolean delete(IRemoteSource source) throws NotConnectedException, PermissionException {
if (log.isDebugEnabled()) {
log.debug("Trying to delete " + source);
}
StringBuffer uriTmpl = (new StringBuffer()).append(restDataspaceUrl).append(source.getDataspace().value());
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).build();
ResteasyWebTarget target = client.target(uriTmpl.toString()).path(source.getPath());
List<String> includes = source.getIncludes();
if (includes != null && !includes.isEmpty()) {
target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
}
List<String> excludes = source.getExcludes();
if (excludes != null && !excludes.isEmpty()) {
target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
}
Response response = null;
try {
response = target.request().header("sessionid", sessionId).delete();
boolean noContent = false;
if (response.getStatus() != HttpURLConnection.HTTP_NO_CONTENT) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedException("User not authenticated or session timeout.");
} else {
throw new RuntimeException("Cannot delete file(s). Status :" + response.getStatusInfo() + " Entity : " + response.getEntity());
}
} else {
noContent = true;
log.debug("No action performed for deletion since source " + source + " was not found remotely");
}
if (!noContent && log.isDebugEnabled()) {
log.debug("Removal of " + source + " performed with success");
}
return true;
} finally {
if (response != null) {
response.close();
}
}
}
use of org.ow2.proactive.scheduler.common.exception.PermissionException in project scheduling by ow2-proactive.
the class DataSpaceClient method download.
@Override
public boolean download(IRemoteSource source, ILocalDestination destination) throws NotConnectedException, PermissionException {
if (log.isDebugEnabled()) {
log.debug("Downloading from " + source + " to " + destination);
}
StringBuffer uriTmpl = (new StringBuffer()).append(restDataspaceUrl).append(source.getDataspace().value());
ResteasyClient client = new ResteasyClientBuilder().httpEngine(httpEngine).build();
ResteasyWebTarget target = client.target(uriTmpl.toString()).path(source.getPath());
List<String> includes = source.getIncludes();
if (includes != null && !includes.isEmpty()) {
target = target.queryParam("includes", includes.toArray(new Object[includes.size()]));
}
List<String> excludes = source.getExcludes();
if (excludes != null && !excludes.isEmpty()) {
target = target.queryParam("excludes", excludes.toArray(new Object[excludes.size()]));
}
Response response = null;
try {
response = target.request().header("sessionid", sessionId).acceptEncoding("*", "gzip", "zip").get();
if (response.getStatus() != HttpURLConnection.HTTP_OK) {
if (response.getStatus() == HttpURLConnection.HTTP_UNAUTHORIZED) {
throw new NotConnectedException("User not authenticated or session timeout.");
} else {
throw new RuntimeException(String.format("Cannot retrieve the file. Status code: %s", response.getStatus()));
}
}
if (response.hasEntity()) {
InputStream is = response.readEntity(InputStream.class);
destination.readFrom(is, response.getHeaderString(HttpHeaders.CONTENT_ENCODING));
} else {
throw new RuntimeException(String.format("%s in %s is empty.", source.getDataspace(), source.getPath()));
}
if (log.isDebugEnabled()) {
log.debug("Download from " + source + " to " + destination + " performed with success");
}
return true;
} catch (IOException ioe) {
throw Throwables.propagate(ioe);
} finally {
if (response != null) {
response.close();
}
}
}
use of org.ow2.proactive.scheduler.common.exception.PermissionException in project scheduling by ow2-proactive.
the class AuthenticationTest method loginAsUser.
private void loginAsUser(SchedulerAuthenticationInterface auth, PublicKey pubKey) throws KeyException, LoginException, AlreadyConnectedException, NotConnectedException, PermissionException {
log("Test 2");
log("Trying to authorized as a user with correct user name and password");
Credentials cred = Credentials.createCredentials(new CredData(TestUsers.USER.username, TestUsers.USER.password), pubKey);
Scheduler user = auth.login(cred);
String userName = user.getCurrentUser();
Assert.assertEquals(TestUsers.USER.username, userName);
UserData userData = user.getCurrentUserData();
Assert.assertNotNull(userData);
Assert.assertNotNull(userData.getUserName());
Assert.assertNotNull(userData.getGroups());
Assert.assertTrue(userData.getGroups().contains("user"));
user.disconnect();
log("Passed: successful authentication");
}
use of org.ow2.proactive.scheduler.common.exception.PermissionException in project scheduling by ow2-proactive.
the class SchedulerFrontendState method checkLinkResourceManager.
synchronized void checkLinkResourceManager() throws NotConnectedException, PermissionException {
UniqueID id = checkAccess();
UserIdentificationImpl ident = identifications.get(id).getUser();
// renew session for this user
renewUserSession(id, ident);
try {
ident.checkPermission(new ConnectToResourceManagerPermission(), ident.getUsername() + " does not have permissions to change RM in the scheduler");
} catch (PermissionException ex) {
logger.info(ex.getMessage());
throw ex;
}
}
use of org.ow2.proactive.scheduler.common.exception.PermissionException in project scheduling by ow2-proactive.
the class RunningTaskRecoveryWithDownNodeTest method checkJobResult.
private void checkJobResult(JobId jobid, Scheduler scheduler) throws NotConnectedException, PermissionException, UnknownJobException {
JobResult jobResult = scheduler.getJobResult(jobid);
Assert.assertFalse(jobResult.hadException());
}
Aggregations