Unlocking
This commit is contained in:
parent
dd61ba2d37
commit
1d425405a9
|
@ -8,6 +8,7 @@ import org.gcube.application.geoportal.client.utils.Serialization;
|
|||
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.document.access.Access;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
|
||||
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
|
||||
|
@ -231,10 +232,54 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T forceUnlock(String id) throws RemoteException {
|
||||
try {
|
||||
log.warn("Force Unlock of {} [useCaseDescriptor {} , class {}]",
|
||||
id, profileID,getManagedClass());
|
||||
Call<WebTarget, T> call = endpoint -> {
|
||||
return ResponseCommons.check(endpoint.path(profileID).path(InterfaceConstants.Methods.FORCE_UNLOCK).path(id).
|
||||
request(MediaType.APPLICATION_JSON).
|
||||
put(Entity.json("")),getManagedClass());
|
||||
};
|
||||
T toReturn=delegate.make(call);
|
||||
log.info("Unlocked ID {} useCaseDescriptor {}", id, profileID);
|
||||
return toReturn;
|
||||
}catch(RemoteException e){
|
||||
log.error("Unexpected error ",e);
|
||||
throw e;
|
||||
}catch(Exception e){
|
||||
log.error("Unexpected error ",e);
|
||||
throw new RemoteException("Unexpected Error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T setAccessPolicy(String id, Access toSet) throws RemoteException {
|
||||
try {
|
||||
log.info("Setting Access of {} [useCaseDescriptor {} , class {}] as {}",
|
||||
id, profileID,getManagedClass(),toSet);
|
||||
Call<WebTarget, T> call = endpoint -> {
|
||||
return ResponseCommons.check(endpoint.path(profileID).path(InterfaceConstants.Methods.SET_PROJECT_ACCESS_POLICY).path(id).
|
||||
request(MediaType.APPLICATION_JSON).
|
||||
put(Entity.json(toSet)),getManagedClass());
|
||||
};
|
||||
T toReturn=delegate.make(call);
|
||||
log.debug("Updated Access of ID {} useCaseDescriptor {}", id, profileID);
|
||||
return toReturn;
|
||||
}catch(RemoteException e){
|
||||
log.error("Unexpected error ",e);
|
||||
throw e;
|
||||
}catch(Exception e){
|
||||
log.error("Unexpected error ",e);
|
||||
throw new RemoteException("Unexpected Error", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T updateDocument(String id, Document updatedDocument) throws RemoteException {
|
||||
try {
|
||||
log.debug("Updateing {} [useCaseDescriptor {} , class {}] with ",
|
||||
log.debug("Updateing {} [useCaseDescriptor {} , class {}] with ",
|
||||
id, profileID,getManagedClass(),updatedDocument);
|
||||
Call<WebTarget, T> call = endpoint -> {
|
||||
return ResponseCommons.check(endpoint.path(profileID).path(id).
|
||||
|
@ -242,7 +287,7 @@ public class DefaultDocumentsClient<T extends Project> implements Projects<T> {
|
|||
put(Entity.entity(updatedDocument, MediaType.APPLICATION_JSON)),getManagedClass());
|
||||
};
|
||||
T toReturn=delegate.make(call);
|
||||
log.info("Updated ID {} useCaseDescriptor {} ", id, profileID);
|
||||
log.info("Updated ID {} useCaseDescriptor {}", id, profileID);
|
||||
return toReturn;
|
||||
}catch(RemoteException e){
|
||||
log.error("Unexpected error ",e);
|
||||
|
|
|
@ -4,6 +4,7 @@ import org.bson.Document;
|
|||
import org.gcube.application.geoportal.common.faults.InvalidRequestException;
|
||||
import org.gcube.application.geoportal.common.model.document.Project;
|
||||
import org.gcube.application.geoportal.common.model.configuration.Configuration;
|
||||
import org.gcube.application.geoportal.common.model.document.access.Access;
|
||||
import org.gcube.application.geoportal.common.model.rest.QueryRequest;
|
||||
import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
|
||||
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
|
||||
|
@ -39,4 +40,7 @@ public interface Projects<P extends Project> {
|
|||
public P registerFileSet(String id, RegisterFileSetRequest req) throws RemoteException, InvalidRequestException;
|
||||
//FileSets
|
||||
public P deleteFileSet(String id, String path, Boolean force) throws RemoteException;
|
||||
|
||||
public P forceUnlock(String id) throws RemoteException;
|
||||
public P setAccessPolicy(String id, Access toSet) throws RemoteException;
|
||||
}
|
||||
|
|
|
@ -683,10 +683,10 @@ public class ProfiledMongoManager extends MongoManager implements MongoManagerI<
|
|||
// expected exception
|
||||
toUnlock = getByID(id);
|
||||
}finally {
|
||||
if(toUnlock!=null) unlock(toUnlock);
|
||||
if(toUnlock!=null)
|
||||
return unlock(toUnlock);
|
||||
else throw new WebApplicationException("Unable to get Project "+id, Response.Status.EXPECTATION_FAILED);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -87,7 +87,7 @@ public class UserUtils {
|
|||
user.setRoles(roles);
|
||||
}catch(Exception e){
|
||||
log.warn("Unable to determine user id, using FAKE",e);
|
||||
user.setUsername("FAKE");
|
||||
user.setUsername("fabio.sinibaldi");
|
||||
user.setRoles(new HashSet<>());
|
||||
user.getRoles().addAll(DEFAULT_ROLES);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import javax.ws.rs.client.Entity;
|
|||
import javax.ws.rs.client.WebTarget;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
|
@ -105,6 +106,19 @@ public class DummyProjectTest extends AbstractProfiledDocumentsTests{
|
|||
return doc;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnlock() throws Exception {
|
||||
assumeTrue(GCubeTest.isTestInfrastructureEnabled());
|
||||
// Not automatic, needs generation of locked project
|
||||
assumeTrue(false);
|
||||
String id = "627e87bb02ad3d1a2e0e9e18";
|
||||
String ucd = "profiledConcessioni";
|
||||
Project p =check(target(InterfaceConstants.Methods.PROJECTS).path(ucd).path(InterfaceConstants.Methods.FORCE_UNLOCK).path(id).request(MediaType.APPLICATION_JSON).
|
||||
put(Entity.entity("", MediaType.APPLICATION_JSON)), Project.class);
|
||||
assertNull(p.getLock());
|
||||
}
|
||||
|
||||
|
||||
// @Test
|
||||
// public void testSDI() throws Exception {
|
||||
// // Create new
|
||||
|
|
|
@ -11,9 +11,7 @@ import org.gcube.application.geoportal.common.rest.Projects;
|
|||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import static org.gcube.application.geoportal.client.plugins.GeoportalAbstractPlugin.projects;
|
||||
|
@ -38,14 +36,16 @@ public class ClearProjects {
|
|||
|
||||
AtomicLong count=new AtomicLong(0);
|
||||
AtomicLong nullCount=new AtomicLong(0);
|
||||
AtomicLong errCount=new AtomicLong(0);
|
||||
|
||||
ConcurrentSkipListSet<String> errors = new ConcurrentSkipListSet<>();
|
||||
|
||||
AtomicLong found=new AtomicLong(0);
|
||||
|
||||
Iterator<Project> it=null;
|
||||
it=client.query(new QueryRequest());
|
||||
// it=manager.search("{\"nome\" : {$regex : \"Mock .*\"}, \"creationTime\" :{$gt : \"2021-10-18T13:58:53.326\"}}");
|
||||
|
||||
ExecutorService service = Executors.newFixedThreadPool(3);
|
||||
ExecutorService service = Executors.newFixedThreadPool(1);
|
||||
|
||||
|
||||
it.forEachRemaining((Project c)->{
|
||||
|
@ -60,6 +60,11 @@ public class ClearProjects {
|
|||
System.out.println("ID IS NULL " + c);
|
||||
nullCount.incrementAndGet();
|
||||
}
|
||||
if(c.getLock()!=null){
|
||||
System.out.println("Unlocking "+currentId);
|
||||
client.forceUnlock(currentId);
|
||||
}
|
||||
|
||||
else
|
||||
if(toSkipIds.contains(currentId))
|
||||
System.out.println("Skipping "+currentId);
|
||||
|
@ -69,7 +74,7 @@ public class ClearProjects {
|
|||
}
|
||||
}catch(Throwable throwable){
|
||||
System.err.println(throwable);
|
||||
errCount.incrementAndGet();
|
||||
errors.add(c.getId());
|
||||
try {Thread.sleep(1000);} catch (InterruptedException i) {}
|
||||
}finally {
|
||||
count.incrementAndGet();
|
||||
|
@ -83,8 +88,10 @@ public class ClearProjects {
|
|||
if(found.get()==count.get()) service.shutdown();
|
||||
}
|
||||
|
||||
System.out.println("Done "+count.get()+" [null : "+nullCount.get()+", err : "+errCount.get()+"]");
|
||||
System.out.println("Done "+count.get()+" [null : "+nullCount.get()+", err : "+errors.size()+"]");
|
||||
|
||||
System.out.println("Errors : ");
|
||||
errors.forEach(s -> System.out.println(s));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue