Compare commits

...

10 Commits

Author SHA1 Message Date
Lucio Lelii bc84828fc5 fixed exception name 2020-04-08 16:47:56 +02:00
Lucio Lelii ee9e001fcc fixed a bug on Exception catching on Collector stubs 2020-04-08 16:45:56 +02:00
lucio 1626dddc97 catching the REsourceNotFound exceptio 2020-04-08 15:47:47 +02:00
lucio 14b618bf41 added specific exception on CollectorStubs 2020-04-08 15:40:47 +02:00
lucio 61a5cf8700 - Default validator Context control added 2020-04-07 19:16:48 +02:00
lucio a00b163f3f added voRemove method on RegistryPublisher to make only a remove for VO 2020-04-07 10:57:15 +02:00
lucio 1d01f50e29 merge with master 2020-03-18 10:11:21 +01:00
lucio eb40fd0eeb token ora scope made mandatory 2019-11-06 15:31:21 +01:00
lucio 858c935b6c Class impleemnts new Rest IC calls added 2019-10-30 19:09:36 +01:00
lucio e97ec6fbd1 added new IC REST calls 2019-10-24 19:03:32 +02:00
26 changed files with 333 additions and 426 deletions

View File

@ -6,19 +6,16 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> <classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes> <attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes> <attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
@ -28,6 +25,12 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry combineaccessrules="false" kind="src" path="/ic-client"/>
<classpathentry combineaccessrules="false" kind="src" path="/common-scope-maps"/>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target/

View File

@ -1,5 +1,8 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8

View File

@ -21,7 +21,8 @@
<groupId>org.gcube.resources</groupId> <groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId> <artifactId>registry-publisher</artifactId>
<version>1.3.0</version> <version>1.4.0-SNAPSHOT</version>
<dependencies> <dependencies>

View File

@ -19,8 +19,9 @@ public class ResourceMediator {
public static void setScope(Resource resource, String scope){ public static void setScope(Resource resource, String scope){
resource.scopes().add(scope); resource.scopes().add(scope);
} }
public static void removeScope(Resource resource, String scope){ public static void removeScope(Resource resource, String ... scopes){
resource.scopes().remove(scope); for (String scope : scopes)
resource.scopes().remove(scope);
} }
public static Resource cleanAllScopes(Resource resource){ public static Resource cleanAllScopes(Resource resource){

View File

@ -48,6 +48,11 @@ public class AdvancedPublisher extends AdvancedPublisherCommonUtils implements R
@Override @Override
public <T extends Resource> T vosUpdate(T resource) { public <T extends Resource> T vosUpdate(T resource) {
return publisher.vosUpdate(resource); return publisher.vosUpdate(resource);
}
@Override
public <T extends Resource> T vosRemove(T resource, List<String> scopes) {
return publisher.vosRemove(resource, scopes);
} }

View File

@ -48,5 +48,16 @@ public interface RegistryPublisher {
* @return the resource without the current scope if the remove operation has been successfully completed * @return the resource without the current scope if the remove operation has been successfully completed
*/ */
<T extends Resource> T remove(T resource); <T extends Resource> T remove(T resource);
/**
* The resource will be removed from the list of scopes.
* if the scope is the last scope in the resource, the profile will be deleted from IS else:
* if it is a VRE scope then the profile will be updated without the VRE scope;
* if it is a VO scope but there is another VRE scope, belong to the VO, defined in the resource then throw IllegalArgumentException;
* if it is a INFRA scope but there is another VRE or VO scope , belong to the INFRA, defined in the resource then throw IllegalArgumentException.
* @throws IllegalArgumentException if the current scope is not defined in the resource or if there is another VRE scope defined in the resource
* @return the resource without the current scope if the remove operation has been successfully completed
*/
<T extends Resource> T vosRemove(T resource, List<String> scopes);
} }

View File

@ -1,12 +1,12 @@
package org.gcube.informationsystem.publisher; package org.gcube.informationsystem.publisher;
import java.io.StringWriter; import java.io.StringWriter;
import java.util.Date;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import javax.xml.ws.soap.SOAPFaultException; import javax.xml.ws.soap.SOAPFaultException;
@ -24,6 +24,7 @@ import org.gcube.informationsystem.publisher.scope.ValidatorProvider;
import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub;
import org.gcube.informationsystem.publisher.stubs.registry.faults.CreateException; import org.gcube.informationsystem.publisher.stubs.registry.faults.CreateException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.InvalidResourceException; import org.gcube.informationsystem.publisher.stubs.registry.faults.InvalidResourceException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceDoesNotExistException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceNotAcceptedException; import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceNotAcceptedException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.UpdateException; import org.gcube.informationsystem.publisher.stubs.registry.faults.UpdateException;
import org.gcube.informationsystem.publisher.utils.RegistryStubs; import org.gcube.informationsystem.publisher.utils.RegistryStubs;
@ -88,7 +89,6 @@ public class RegistryPublisherImpl implements RegistryPublisher {
log.debug("id generated: "+id); log.debug("id generated: "+id);
ResourceMediator.setId(resource, id); ResourceMediator.setId(resource, id);
} }
HashSet<String> vosScopes = updateResourceScopes(resource);
// add the new scopes // add the new scopes
for(String scope: scopes){ for(String scope: scopes){
log.debug("[VOCREATE] new scope added {}",scope); log.debug("[VOCREATE] new scope added {}",scope);
@ -101,19 +101,20 @@ public class RegistryPublisherImpl implements RegistryPublisher {
log.error("the resource is not valid", e); log.error("the resource is not valid", e);
throw new IllegalArgumentException("the resource is not valid ", e.getCause()); throw new IllegalArgumentException("the resource is not valid ", e.getCause());
} }
HashSet<String> vosScopes = updateResourceScopes(resource);
try{ try{
if(currentScope != null){ if(currentScope != null){
// checking the current scope: if the operation fails in the current VO it will give an exception, if it fails in another VO no exception will be given // checking the current scope: if the operation fails in the current VO it will give an exception, if it fails in another VO no exception will be given
String currentVO = Utils.getCurrentVO(currentScope); String currentVO = Utils.getCurrentVO(currentScope);
if (currentVO != null){ if (currentVO != null){
RegistryStub stub = getRegistryStub(); RegistryStub stub = getRegistryStub();
createResource(resource, currentVO, stub); createResource(resource, currentVO, stub);
vosScopes.remove(currentVO); vosScopes.remove(currentVO);
//in this case it is a root-vo scope so we need to create the resource only at root-vo level //in this case it is a root-vo scope so we need to create the resource only at root-vo level
}else{ }else{
RegistryStub stub = getRegistryStub(); RegistryStub stub = getRegistryStub();
createResource(resource, currentVO, stub); createResource(resource, currentVO, stub);
return resource; return resource;
} }
} }
// update the resource for each VO // update the resource for each VO
@ -232,17 +233,17 @@ public class RegistryPublisherImpl implements RegistryPublisher {
HashSet<String> vosScopes = Utils.getInternalVOScopes(resource); HashSet<String> vosScopes = Utils.getInternalVOScopes(resource);
try{ try{
if(currentScope != null){ if(currentScope != null){
// checking the current scope: if the operation fail in the current VO it will give an exception, if it fails in another VO no exception will be given // checking the current scope: if the operation fail in the current VO it will raise an exception, if it fails in another VO no exception will be raised
String currentVO = Utils.getCurrentVO(currentScope); String currentVO = Utils.getCurrentVO(currentScope);
if (currentVO != null){ if (currentVO != null){
ScopeProvider.instance.set(currentVO); ScopeProvider.instance.set(currentVO);
registryUpdate(resource, 0); registryUpdate(resource, 0);
vosScopes.remove(currentVO); vosScopes.remove(currentVO);
// in this case it is a root-vo scope so we need to update the resource only at root-vo level // in this case it is a root-vo scope
}else{ }else{
ScopeProvider.instance.set(currentScope); ScopeProvider.instance.set(currentScope);
registryUpdate(resource, 0); registryUpdate(resource, 0);
return resource; vosScopes.remove(currentScope);
} }
} }
@ -274,6 +275,66 @@ public class RegistryPublisherImpl implements RegistryPublisher {
return resource; return resource;
} }
/**
* The resource will be removed from all the scopes
* if the scope is the last scope in the resource, the profile will be deleted from IS else
* if it is a VRE scope then the profile will be updated without the VRE scope,
* if it is a VO scope but there is another VRE scope, belong to the VO, defined in the resource then throw IllegalArgumentException
*
* @throws IllegalArgumentException if no service endpoints can be discovered or if there is another VRE scope defined in the resource
*/
public <T extends Resource> T vosRemove(T resource, List<String> scopes){
String currentScope=ScopeProvider.instance.get();
log.info(" remove resource with id : {} from scope: {}",resource.id(),currentScope);
ValidationUtils.valid("resource", resource);// helper that throws an IllegalArgumentException if resource are null
ValidationUtils.valid("scopes", currentScope);// helper that throws an IllegalArgumentException if scopes are null
validateScope(resource);
// the returned voScopes list is not used yet. it should be used if the update/remove operation will be done at VO level
// HashSet<String> vosScopes = updateResourceScopes(resource);
updateResourceScopes(resource);
try {
Resources.validate(resource);
} catch (Exception e) {
log.error("the resource is not valid", e);
throw new IllegalArgumentException("the resource is not valid", e);
}
log.info(" remove {} scope from resource {}",scopes,resource.id());
Set<String> voScopesBeforeRemove =Utils.getInternalVOScopes(resource);
ResourceMediator.removeScope(resource, scopes.toArray(new String[scopes.size()]));
Set<String> voScopesAfterRemove =Utils.getInternalVOScopes(resource);
voScopesBeforeRemove.removeAll(voScopesAfterRemove);
for (String scope: voScopesBeforeRemove)
try {
ScopeProvider.instance.set(scope);
log.info("remove from IS scope {}",currentScope);
registry.getStubs().remove(resource.id(), resource.type().toString());
} catch (ResourceDoesNotExistException e) {
log.warn("resource not found in the current scope, continue");
} catch (Exception e) {
log.error("the resource can't be removed ", e);
throw new IllegalArgumentException("the resource can't be removed from scope "+currentScope, e);
} finally {
ScopeProvider.instance.set(currentScope);
}
// retrieves the scopes on resource and update it
// updateResource(resource, currentScope);
if (!voScopesAfterRemove.isEmpty())
try{
vosUpdate(resource);
}catch(Exception e){
log.error("exception message: "+e.getMessage());
throw new RuntimeException(e.getMessage());
}
return resource;
}
/** /**
* The resource will be removed from current scope * The resource will be removed from current scope
* if the scope is the last scope in the resource, the profile will be deleted from IS else * if the scope is the last scope in the resource, the profile will be deleted from IS else
@ -284,12 +345,12 @@ public class RegistryPublisherImpl implements RegistryPublisher {
*/ */
public <T extends Resource> T remove(T resource){ public <T extends Resource> T remove(T resource){
String currentScope=ScopeProvider.instance.get(); String currentScope=ScopeProvider.instance.get();
log.info(" remove resource with id : "+resource.id()+" from scope: "+currentScope); log.info(" remove resource with id : {} from scope: {}",resource.id(),currentScope);
ValidationUtils.valid("resource", resource);// helper that throws an IllegalArgumentException if resource are null ValidationUtils.valid("resource", resource);// helper that throws an IllegalArgumentException if resource are null
ValidationUtils.valid("scopes", currentScope);// helper that throws an IllegalArgumentException if scopes are null ValidationUtils.valid("scopes", currentScope);// helper that throws an IllegalArgumentException if scopes are null
validateScope(resource); validateScope(resource);
// the returned voScopes list is not used yet. it should be used if the update/remove operation will be done at VO level // the returned voScopes list is not used yet. it should be used if the update/remove operation will be done at VO level
// HashSet<String> vosScopes = updateResourceScopes(resource); // HashSet<String> vosScopes = updateResourceScopes(resource);
updateResourceScopes(resource); updateResourceScopes(resource);
try { try {
Resources.validate(resource); Resources.validate(resource);
@ -297,7 +358,7 @@ public class RegistryPublisherImpl implements RegistryPublisher {
log.error("the resource is not valid", e); log.error("the resource is not valid", e);
throw new IllegalArgumentException("the resource is not valid", e); throw new IllegalArgumentException("the resource is not valid", e);
} }
log.info(" remove "+currentScope+" scope from resource "+resource.id()); log.info(" remove {} scope from resource {}",currentScope,resource.id());
ResourceMediator.removeScope(resource, currentScope); ResourceMediator.removeScope(resource, currentScope);
// retrieves the scopes on resource and update it // retrieves the scopes on resource and update it
// updateResource(resource, currentScope); // updateResource(resource, currentScope);
@ -312,6 +373,7 @@ public class RegistryPublisherImpl implements RegistryPublisher {
} }
private void registryUpdate(Resource resource, int tries){ private void registryUpdate(Resource resource, int tries){
log.trace("try to update resource with id: "+resource.id()+" times "+(tries+1)+" on scope: "+ScopeProvider.instance.get()); log.trace("try to update resource with id: "+resource.id()+" times "+(tries+1)+" on scope: "+ScopeProvider.instance.get());
try{ try{
@ -358,14 +420,14 @@ public class RegistryPublisherImpl implements RegistryPublisher {
*/ */
private <T extends Resource> void updateResourceRemoveOperation(T resource, String currentScope) { private <T extends Resource> void updateResourceRemoveOperation(T resource, String currentScope) {
if(!isRemoveNeeded(resource, currentScope)){ if(!isRemoveNeeded(resource, currentScope)){
// updateResource(resource, currentScope); // updateResource(resource, currentScope);
// v 1.3 (20190902) try to update the resource just at vo level // v 1.3 (20190902) try to update the resource just at vo level
vosUpdate(resource); vosUpdate(resource);
}else{ // remove the profile from IC }else{ // remove the profile from IC
log.info("the resource have only the "+currentScope+" scope defined. Remove the resource "+resource.id()+" from IC"); log.info("the resource have only the {} scope defined. Remove the resource {} from IC", currentScope,resource.id());
// if the resource hasn't any scope, the resource will be removed // if the resource hasn't any scope, the resource will be removed
try { try {
log.debug("remove from IS scope "+currentScope); log.info("remove from IS scope {}",currentScope);
registry.getStubs().remove(resource.id(), resource.type().toString()); registry.getStubs().remove(resource.id(), resource.type().toString());
} catch (Exception e) { } catch (Exception e) {
log.error("the resource can't be removed ", e); log.error("the resource can't be removed ", e);
@ -429,8 +491,7 @@ public class RegistryPublisherImpl implements RegistryPublisher {
ScopeProvider.instance.set(currentScope); ScopeProvider.instance.set(currentScope);
} }
} }
/*
private <T extends Resource> void updateResourceVOLevel(T resource, List <String> voScopes, String currentScope) { private <T extends Resource> void updateResourceVOLevel(T resource, List <String> voScopes, String currentScope) {
int tries=0; int tries=0;
try{ try{
@ -443,14 +504,17 @@ public class RegistryPublisherImpl implements RegistryPublisher {
ScopeProvider.instance.set(currentScope); ScopeProvider.instance.set(currentScope);
} }
} }
*/
private <T extends Resource> HashSet<String> updateResourceScopes(T resource) { private <T extends Resource> HashSet<String> updateResourceScopes(T resource) {
HashSet<String> vosScopes = Utils.getInternalVOScopes(resource); HashSet<String> vosScopes = Utils.getInternalVOScopes(resource);
// if the resource type is a RunningInstance or a HostingNode the check on the most recent resource is bypassed
if((resource.type().toString().equalsIgnoreCase("RunningInstance")) || (resource.type().toString().equalsIgnoreCase("GHN")) || (resource.type().toString().equalsIgnoreCase("GCoreEndpoint")) || (resource.type().toString().equalsIgnoreCase("HostingNode")))
return vosScopes;
//extract the scopes from the more recent resource found at vo level //extract the scopes from the more recent resource found at vo level
List <String> latestScopesFound= Utils.setLatestInternalScopes(resource, vosScopes); List <String> latestScopesFound= Utils.setLatestInternalScopes(resource, vosScopes);
log.debug("latest scope found are "+latestScopesFound); log.debug("latest scope found are "+latestScopesFound);
if((latestScopesFound == null) || (latestScopesFound.isEmpty())){ if((latestScopesFound == null) || (latestScopesFound.isEmpty())){
// if it is a new resource the latestScopesFound should be null, in this case the more recent scopes are the new scopes // if it is a new resource the latestScopesFound should be null, in this case the more recent scopes are the new scopes
latestScopesFound= new ArrayList<String>(vosScopes.size()); latestScopesFound= new ArrayList<String>(vosScopes.size());
for (String scope: vosScopes){ for (String scope: vosScopes){
latestScopesFound.add(scope); latestScopesFound.add(scope);
@ -463,7 +527,7 @@ public class RegistryPublisherImpl implements RegistryPublisher {
log.debug("[VOCREATE] scope added {}",scope); log.debug("[VOCREATE] scope added {}",scope);
ResourceMediator.setScope(resource, scope); ResourceMediator.setScope(resource, scope);
ScopeBean scopeBean = new ScopeBean(scope); ScopeBean scopeBean = new ScopeBean(scope);
// check if the scope was already present inside the resource, if not, it will be added to the voScopes // check if the scope was already present inside the resource, if not, it will be added to the voScopes
if((!scopeBean.is(Type.VRE)) && (!vosScopes.contains(scope))){ if((!scopeBean.is(Type.VRE)) && (!vosScopes.contains(scope))){
vosScopes.add(scope); vosScopes.add(scope);
} }

View File

@ -47,13 +47,7 @@ public class ScopedPublisherImpl implements ScopedPublisher{
@Override @Override
public <T extends Resource> T remove(T resource, List<String> scopes) throws RegistryNotFoundException{ public <T extends Resource> T remove(T resource, List<String> scopes) throws RegistryNotFoundException{
String currentScope=ScopeProvider.instance.get(); return registryPublisher.vosRemove(resource, scopes);
for(String scope : scopes){
ScopeProvider.instance.set(scope);
registryPublisher.remove(resource);
}
ScopeProvider.instance.set(currentScope);
return resource;
} }
} }

View File

@ -3,36 +3,18 @@ package org.gcube.informationsystem.publisher.scope;
import java.util.List; import java.util.List;
import org.gcube.common.resources.gcore.Resource; import org.gcube.common.resources.gcore.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DefaultScopeValidator<R> implements Validator<Resource>{ public class DefaultScopeValidator implements Validator{
private static Logger log = LoggerFactory.getLogger(DefaultScopeValidator.class);
@Override @Override
public <R extends Resource> void validate(R resource) { public void validate(Resource resource) {
// log.info("validate method of "+this.getClass()); if (resource.scopes().isEmpty())
// String currentScope=ScopeProvider.instance.get(); throw new IllegalArgumentException("scopes in the resource are empty");
// ScopeGroup<String> scopes=resource.scopes();
// boolean founded= false;
// for(Iterator<String> it=scopes.iterator(); it.hasNext();){
// String scope=it.next();
// if(scope.equals(currentScope))
// founded=true;
// }
// if(!founded)
// throw new IllegalStateException(" scope "+currentScope+" not present in resource");
} }
@Override @Override
public Class type() { public void checkScopeCompatibility(Resource resource,
return Resource.class;
}
@Override
public <R extends Resource> void checkScopeCompatibility(R resource,
List<String> scopesList) { List<String> scopesList) {
// for(String scope: scopesList){ // for(String scope: scopesList){
// ScopeGroup<String> scopes=resource.scopes(); // ScopeGroup<String> scopes=resource.scopes();

View File

@ -4,11 +4,9 @@ import java.util.List;
import org.gcube.common.resources.gcore.Resource; import org.gcube.common.resources.gcore.Resource;
public interface Validator <R extends Resource>{ public interface Validator {
<R extends Resource> void validate(R resource); void validate(Resource resource);
<R extends Resource> void checkScopeCompatibility(R resource, List<String> scopes); void checkScopeCompatibility(Resource resource, List<String> scopes);
public Class<R> type();
} }

View File

@ -1,29 +1,12 @@
package org.gcube.informationsystem.publisher.scope; package org.gcube.informationsystem.publisher.scope;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.gcube.common.resources.gcore.Resource; import org.gcube.common.resources.gcore.Resource;
public class ValidatorProvider { public class ValidatorProvider {
private static Map<Class, Validator> validatorsMap= new LinkedHashMap<Class, Validator>();
public static Validator getValidator(Resource resource){ public static Validator getValidator(Resource resource){
Validator validator=null; return new DefaultScopeValidator();
if(validatorsMap.isEmpty()){
IValidatorContext context= ScopeValidatorScanner.provider();
List<Validator> validators=context.getValidators();
for(Validator v :validators){
validatorsMap.put(v.type(), v);
}
}
validator=validatorsMap.get(resource.getClass());
if (validator==null)
validator=new DefaultScopeValidator();
return validator;
} }

View File

@ -0,0 +1,121 @@
package org.gcube.informationsystem.publisher.stubs.registry;
import java.io.BufferedOutputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.informationsystem.publisher.stubs.registry.faults.CreateException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.InvalidResourceException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.RemoveException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceDoesNotExistException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceNotAcceptedException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.UpdateException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class CollectorStubs implements RegistryStub {
private static Logger log = LoggerFactory.getLogger(CollectorStubs.class);
public static final String TOKEN_HEADER_ENTRY = "gcube-token";
public static final String SCOPE_HEADER_ENTRY = "gcube-scope";
private String endopoint;
public CollectorStubs(String endopoint) {
super();
this.endopoint = endopoint;
}
@Override
public void create(String profile, String type)
throws InvalidResourceException, ResourceNotAcceptedException, CreateException {
StringBuilder callUrl = new StringBuilder(endopoint).append("/").append(type);
try {
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "text/xml");
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
os.write(profile.getBytes());
}
if (connection.getResponseCode()!=200) throw new CreateException("error creating resource "+connection.getResponseCode());
}catch (Exception e) {
log.error("error on create",e);
throw new CreateException(e.getMessage());
}
}
@Override
public void update(String id, String type, String profile)
throws InvalidResourceException, ResourceNotAcceptedException, UpdateException {
StringBuilder callUrl = new StringBuilder(endopoint).append("/").append(type).append("/").append(id);
try {
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT");
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "text/xml");
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
os.write(profile.getBytes());
}
if (connection.getResponseCode()!=200) throw new UpdateException("error updating resource "+connection.getResponseCode());
}catch (Exception e) {
log.error("error on update",e);
throw new UpdateException(e.getMessage());
}
}
@Override
public void remove(String id, String type) throws ResourceDoesNotExistException, RemoveException {
StringBuilder callUrl = new StringBuilder(endopoint).append("/").append(type).append("/").append(id);
try {
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "DELETE");
connection.setDoInput(true);
if (connection.getResponseCode()!=200){
log.info("response code is not 200");
if (connection.getResponseCode()==404)
throw new ResourceDoesNotExistException("resource with id "+id+" not found");
else throw new RemoveException("generic error removing resource "+id);
}
}catch (ResourceDoesNotExistException | RemoveException e) {
throw e;
}catch (Exception e1) {
throw new RemoveException("connection error removing resource");
}
}
private HttpURLConnection makeRequest(URL url, String method) throws Exception{
HttpURLConnection connection;
if (url.toString().startsWith("https://"))
connection = (HttpsURLConnection)url.openConnection();
else connection = (HttpURLConnection)url.openConnection();
if (ScopeProvider.instance.get()!=null)
connection.setRequestProperty(SCOPE_HEADER_ENTRY,ScopeProvider.instance.get());
else if (SecurityTokenProvider.instance.get()!=null)
connection.setRequestProperty(TOKEN_HEADER_ENTRY,SecurityTokenProvider.instance.get());
else throw new RuntimeException("Collector requires authorization (via token or scope)");
connection.setRequestMethod(method);
return connection;
}
}

View File

@ -2,11 +2,15 @@ package org.gcube.informationsystem.publisher.stubs.registry;
import static org.gcube.informationsystem.publisher.stubs.registry.RegistryConstants.*; import static org.gcube.informationsystem.publisher.stubs.registry.RegistryConstants.*;
import java.io.StringWriter;
import javax.jws.WebMethod; import javax.jws.WebMethod;
import javax.jws.WebParam; import javax.jws.WebParam;
import javax.jws.WebResult; import javax.jws.WebResult;
import javax.jws.WebService; import javax.jws.WebService;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.Resources;
import org.gcube.informationsystem.publisher.stubs.registry.faults.CreateException; import org.gcube.informationsystem.publisher.stubs.registry.faults.CreateException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.InvalidResourceException; import org.gcube.informationsystem.publisher.stubs.registry.faults.InvalidResourceException;
import org.gcube.informationsystem.publisher.stubs.registry.faults.RemoveException; import org.gcube.informationsystem.publisher.stubs.registry.faults.RemoveException;
@ -35,6 +39,7 @@ public interface RegistryStub {
@WebResult() @WebResult()
void create(@WebParam(name="profile") String profile, @WebParam(name="type") String type ) throws InvalidResourceException, void create(@WebParam(name="profile") String profile, @WebParam(name="type") String type ) throws InvalidResourceException,
ResourceNotAcceptedException, CreateException; ResourceNotAcceptedException, CreateException;
/** /**
* *
* @param id the id of the resource to update * @param id the id of the resource to update
@ -48,7 +53,8 @@ public interface RegistryStub {
@WebMethod(operationName="update") @WebMethod(operationName="update")
@WebResult() @WebResult()
void update(@WebParam(name="uniqueID") String id, @WebParam(name="type") String type, @WebParam(name="xmlProfile") String profile ) throws InvalidResourceException, void update(@WebParam(name="uniqueID") String id, @WebParam(name="type") String type, @WebParam(name="xmlProfile") String profile ) throws InvalidResourceException,
ResourceNotAcceptedException, UpdateException; ResourceNotAcceptedException, UpdateException;
/** /**
* *
* @param id the id of the resource to remove * @param id the id of the resource to remove
@ -60,7 +66,6 @@ public interface RegistryStub {
@WebMethod(operationName="remove") @WebMethod(operationName="remove")
@WebResult() @WebResult()
void remove(@WebParam(name="uniqueID") String id, @WebParam(name="type") String type) throws ResourceDoesNotExistException, void remove(@WebParam(name="uniqueID") String id, @WebParam(name="type") String type) throws ResourceDoesNotExistException,
RemoveException; RemoveException;
} }

View File

@ -8,8 +8,10 @@ import java.util.List;
import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.api.ServiceMap;
import org.gcube.informationsystem.publisher.cache.RegistryCache; import org.gcube.informationsystem.publisher.cache.RegistryCache;
import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException;
import org.gcube.informationsystem.publisher.stubs.registry.CollectorStubs;
import org.gcube.informationsystem.publisher.stubs.registry.RegistryConstants; import org.gcube.informationsystem.publisher.stubs.registry.RegistryConstants;
import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub;
import org.gcube.resources.discovery.client.api.DiscoveryClient; import org.gcube.resources.discovery.client.api.DiscoveryClient;
@ -21,16 +23,17 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class RegistryStubs { public class RegistryStubs {
private RegistryCache cache = new RegistryCache(10); private RegistryCache cache = new RegistryCache(10);
private List<URI> endpoints; private List<URI> endpoints;
private static final Logger log = LoggerFactory.getLogger(RegistryStubs.class); private static final Logger log = LoggerFactory.getLogger(RegistryStubs.class);
private static final String XMLSTOREACCESS_SERVICE ="XMLStoreService";
public List<URI> getEndPoints(){ public List<URI> getEndPoints(){
String scope=ScopeProvider.instance.get(); String scope=ScopeProvider.instance.get();
// able/disable cache // able/disable cache
endpoints=(List<URI>)cache.get(scope); endpoints=(List<URI>)cache.get(scope);
if(endpoints==null){ if(endpoints==null){
SimpleQuery query = queryFor(GCoreEndpoint.class); SimpleQuery query = queryFor(GCoreEndpoint.class);
@ -40,32 +43,47 @@ public class RegistryStubs {
public URI parse(String result) throws Exception { public URI parse(String result) throws Exception {
return new URI(result.replaceAll("\n", "")); return new URI(result.replaceAll("\n", ""));
} }
}; };
DiscoveryClient<URI> client = new DelegateClient<URI>(uriParser, new ICClient()); DiscoveryClient<URI> client = new DelegateClient<URI>(uriParser, new ICClient());
query.addCondition("$resource/Profile/ServiceClass/text() eq '"+RegistryConstants.service_class+"'") query.addCondition("$resource/Profile/ServiceClass/text() eq '"+RegistryConstants.service_class+"'")
.addCondition("$resource/Profile/ServiceName/text() eq '"+RegistryConstants.service_name+"'") .addCondition("$resource/Profile/ServiceName/text() eq '"+RegistryConstants.service_name+"'")
.setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq '"+RegistryConstants.service_entrypoint+"']/string()"); .setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq '"+RegistryConstants.service_entrypoint+"']/string()");
endpoints = client.submit(query); endpoints = client.submit(query);
if (endpoints.size()==0){ if (endpoints.size()==0){
throw new IllegalArgumentException("No registry endpoint founded"); throw new IllegalArgumentException("No registry endpoint found");
} }
// able/disable cache // able/disable cache
cache.put(scope, endpoints); cache.put(scope, endpoints);
} }
return endpoints; return endpoints;
} }
public RegistryStub getStubs() throws RegistryNotFoundException{ public RegistryStub getStubs() throws RegistryNotFoundException{
URI endpoint=null; ServiceMap serviceMap = ServiceMap.instance;
//use another method to cache epr if (serviceMap!=null && serviceMap.version().equals("2.0.0")) {
endpoint = getEndPoints().get(0); try {
log.debug("get stubs from endpoint: "+ endpoint); @SuppressWarnings("unchecked")
return stubFor(RegistryConstants.registry).at(endpoint); Class<? extends RegistryStub> localClientclass =(Class<? extends RegistryStub>) Class.forName("org.gcube.informationsystem.collector.client.LocalPublisherClient", true, Thread.currentThread().getContextClassLoader());
log.info("using LocalPublisherClient, information collector specific publisher");
return localClientclass.newInstance();
}catch (Exception e) {
String endpoint = serviceMap.endpoint(XMLSTOREACCESS_SERVICE);
log.info("using REST COLLECTOR");
return new CollectorStubs(endpoint);
}
} else {
//use another method to cache epr
URI endpoint = getEndPoints().get(0);
log.info("getting REGISTRY STUBS stubs from endpoint: {}",endpoint);
return stubFor(RegistryConstants.registry).at(endpoint);
}
} }
public RegistryStub getStubs(URI endpoint) throws RegistryNotFoundException{ public RegistryStub getStubs(URI endpoint) throws RegistryNotFoundException{
log.debug("get stubs from endpoint: "+ endpoint); log.debug("get stubs from endpoint: {}", endpoint);
return stubFor(RegistryConstants.registry).at(endpoint); return stubFor(RegistryConstants.registry).at(endpoint);
} }

View File

@ -42,13 +42,11 @@ public class Utils {
*/ */
public static String getCurrentVO(String currentScope) { public static String getCurrentVO(String currentScope) {
ScopeBean scopeBean = new ScopeBean(currentScope); ScopeBean scopeBean = new ScopeBean(currentScope);
String currentVO=null;
if(scopeBean.is(Type.VRE)) if(scopeBean.is(Type.VRE))
currentVO=scopeBean.enclosingScope().toString(); return scopeBean.enclosingScope().toString();
else if (scopeBean.is(Type.VO)) else if (scopeBean.is(Type.VO))
currentVO= currentScope; return currentScope;
else return null; else return null;
return currentVO;
} }
/** /**
@ -65,6 +63,7 @@ public class Utils {
ScopeBean scopeBean = new ScopeBean(scope); ScopeBean scopeBean = new ScopeBean(scope);
if(scopeBean.is(Type.VRE)) if(scopeBean.is(Type.VRE))
vosScopes.add(scopeBean.enclosingScope().toString()); vosScopes.add(scopeBean.enclosingScope().toString());
else
// if the scope is a root-vo scope, it will be added to the vosScope array // if the scope is a root-vo scope, it will be added to the vosScope array
vosScopes.add(scope); vosScopes.add(scope);
} }
@ -154,6 +153,7 @@ public class Utils {
private static <T extends Resource> List<String> extractInternalScopes(T resource, String latestVO) { private static <T extends Resource> List<String> extractInternalScopes(T resource, String latestVO) {
T extractedResource=null; T extractedResource=null;
log.debug("checking resource "+resource.id()+" type: "+resource.type());
if(resource.type().toString().equalsIgnoreCase("RuntimeResource")){ if(resource.type().toString().equalsIgnoreCase("RuntimeResource")){
extractedResource= (T)getServiceEndpointByID(resource.id(), latestVO); extractedResource= (T)getServiceEndpointByID(resource.id(), latestVO);
}else if(resource.type().toString().equalsIgnoreCase("GenericResource")){ }else if(resource.type().toString().equalsIgnoreCase("GenericResource")){

View File

@ -74,7 +74,7 @@ public class ValidationUtils {
} }
public static <T extends Resource> boolean isCompatibleScopeForRemove(T resource, String scope){ public static <T extends Resource> boolean isCompatibleScopeForRemove(T resource, String scope){
log.info("scope: "+scope+" check if update is needed inr resource: "+resource.id()); log.info("scope: {} check if update is needed inr resource: {}", scope,resource.id());
if(resource.scopes().size() == 0) if(resource.scopes().size() == 0)
return true; return true;
if(new ScopeBean(scope).is(Type.VRE)){ if(new ScopeBean(scope).is(Type.VRE)){
@ -86,11 +86,11 @@ public class ValidationUtils {
}else if(new ScopeBean(scope).is(Type.VO)){ }else if(new ScopeBean(scope).is(Type.VO)){
log.debug(" "+scope+" is a VO scope"); log.debug(" "+scope+" is a VO scope");
if(anotherSonVREOnResource(resource, scope)){ if(anotherSonVREOnResource(resource, scope)){
throw new IllegalArgumentException("the resource "+resource.id()+" have another scope defined in the same VO. The VO is "+scope); return false; //throw new IllegalArgumentException("the resource "+resource.id()+" have another scope defined in the same VO. The VO is "+scope);
}else return true; }else return true;
}else{ // is a INFRA scope }else{ // is a INFRA scope
if(anotherInfraScopeOnResource(resource, scope)){ if(anotherInfraScopeOnResource(resource, scope)){
throw new IllegalArgumentException("the resource "+resource.id()+" have another scope defined in the same INFRA. The INFRA is "+scope); return false; //throw new IllegalArgumentException("the resource "+resource.id()+" have another scope defined in the same INFRA. The INFRA is "+scope);
}else return true; }else return true;
} }
} }

View File

@ -1,68 +0,0 @@
package org.gcube.informationsystem.publisher;
import static org.junit.Assert.*;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
import org.gcube.informationsystem.publisher.scope.IValidatorContext;
import org.gcube.informationsystem.publisher.scope.Validator;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
public class ConfigurationTest {
private ClassLoader loader;
// static final String relativePath="src/test/java/META-INF/services/org.gcube.informationsystem.publisher.scope.IValidatorContext";
@Before
public void init() {
loader = Thread.currentThread().getContextClassLoader();
}
@Test
public void alternativeProvidersCanBeConfigured() {
addJarsToClasspath("customValidator.jar");
List<IValidatorContext> impls=load();
assertEquals(impls.size(), 1);
}
private List<IValidatorContext> load(){
ServiceLoader<IValidatorContext> loader = ServiceLoader.load(IValidatorContext.class);
Iterator<IValidatorContext> iterator = loader.iterator();
List<IValidatorContext> impls = new ArrayList<IValidatorContext>();
while(iterator.hasNext())
impls.add(iterator.next());
System.out.println("size: "+impls.size());
if(impls.size()==1){
IValidatorContext context = impls.get(0);
for( Validator validator : context.getValidators()){
System.out.println("implementation found: "+ validator.type());
}
}
return impls;
}
private void addJarsToClasspath(String ... jars) {
List<URL> jarUrls = new ArrayList<URL>();
for (String jar : jars)
jarUrls.add(loader.getResource(jar));
URLClassLoader urlClassLoader
= new URLClassLoader(jarUrls.toArray(new URL[0]),loader);
Thread.currentThread().setContextClassLoader(urlClassLoader);
}
@After
public void teardown() {
Thread.currentThread().setContextClassLoader(loader);
}
}

View File

@ -1,22 +0,0 @@
package org.gcube.informationsystem.publisher;
import java.util.List;
import static org.junit.Assert.*;
import org.gcube.informationsystem.publisher.scope.IValidatorContext;
import org.gcube.informationsystem.publisher.scope.ScopeValidatorScanner;
import org.gcube.informationsystem.publisher.scope.Validator;
import org.junit.Test;
public class DefaultConfigurationTest {
@Test
public void testDefaultValidator(){
IValidatorContext context=ScopeValidatorScanner.provider();
List<Validator> list= context.getValidators();
assertNotNull(list);
Validator validator =list.get(0);
System.out.println("found validator: "+validator.type());
assertEquals(validator.type().toString().trim(),"class org.gcube.common.resources.gcore.Resource");
}
}

View File

@ -1,46 +0,0 @@
package org.gcube.informationsystem.publisher;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import org.apache.log4j.helpers.Loader;
import org.gcube.informationsystem.publisher.scope.IValidatorContext;
import org.gcube.informationsystem.publisher.scope.ScopeValidatorScanner;
import org.gcube.informationsystem.publisher.scope.Validator;
import org.junit.BeforeClass;
import org.junit.Test;
public class DefaultScopeValidatorTest {
static final String relativePath="/src/test/java/META-INF/services/org.gcube.informationsystem.publisher.scope.IValidatorContext";
// @BeforeClass
public static void deleteServiceInfo(){
URL url=Thread.currentThread().getClass().getResource("/");
if(url != null){
File f =new File(url.getPath());
String rootPath=f.getParentFile().getParentFile().getAbsolutePath();
System.out.println(" "+f.exists()+" path "+rootPath);
File service=new File(rootPath+relativePath);
if(service.exists()){
boolean del=service.delete();
System.out.println("deleted? "+del);
}
}
System.out.println("url founded "+url);
}
// @Test
public void testDefaultValidator(){
IValidatorContext context=ScopeValidatorScanner.provider();
List<Validator> list= context.getValidators();
for(Validator validator : list){
System.out.println("validator founded: "+validator.type());
}
}
}

View File

@ -2,6 +2,8 @@ package org.gcube.informationsystem.publisher;
import static org.gcube.common.resources.gcore.Resources.print; import static org.gcube.common.resources.gcore.Resources.print;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.resources.gcore.GCoreEndpoint; import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.Resource; import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.Resource.Type; import org.gcube.common.resources.gcore.Resource.Type;
@ -14,38 +16,39 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class GCoreEndpointPublisherTests { public class GCoreEndpointPublisherTests {
private static final Logger log = LoggerFactory.getLogger(RegistryPublisherTests.class); private static final Logger log = LoggerFactory.getLogger(RegistryPublisherTests.class);
static GCoreEndpoint running; static GCoreEndpoint running;
static RegistryPublisher rp; static RegistryPublisher rp;
static Resource r; static Resource r;
@BeforeClass @BeforeClass
public static void init(){ public static void init(){
// ScopeProvider.instance.set("/d4science.research-infrastructures.eu/EUBrazilOpenBio"); // ScopeProvider.instance.set("/d4science.research-infrastructures.eu/EUBrazilOpenBio");
ScopeProvider.instance.set("/gcube/devsec"); ScopeProvider.instance.set("/gcube/devNext");
running = Resources.unmarshal(GCoreEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("gCoreEndpoint.xml")); SecurityTokenProvider.instance.set("52b59669-ccde-46d2-a4da-108b9e941f7c-98187548");
rp=RegistryPublisherFactory.create(); rp=RegistryPublisherFactory.create();
} }
@Test @Test
public void printTest(){ public void printTest(){
print(running); //print(running);
//resource-specific tests //resource-specific tests
assertEquals(Type.GCOREENDPOINT,running.type()); assertEquals(Type.GCOREENDPOINT,running.type());
} }
@Test @Test
public void registerCreate(){ public void registerCreate(){
r=rp.create(running);
System.out.println("new resource created: "); for (int i = 0; i<10; i++) {
if(r!=null) running = Resources.unmarshal(GCoreEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("gCoreEndpoint.xml"));
print(r); r=rp.create(running);
assertEquals(running,r); System.out.println("new resource created: "+r.id());
}
} }
@AfterClass /*@AfterClass
public static void forceDeleteResource(){ public static void forceDeleteResource(){
try { try {
Thread.sleep(3000); Thread.sleep(3000);
@ -59,8 +62,8 @@ public class GCoreEndpointPublisherTests {
advancedPublisher.forceRemove(r); advancedPublisher.forceRemove(r);
ScopeProvider.instance.set(currentScope); ScopeProvider.instance.set(currentScope);
} }*/
} }

View File

@ -1,64 +0,0 @@
package org.gcube.informationsystem.publisher;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;
import javax.annotation.Resource;
import org.gcube.informationsystem.publisher.scope.IValidatorContext;
import org.gcube.informationsystem.publisher.scope.ScopeValidatorScanner;
import org.gcube.informationsystem.publisher.scope.Validator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
public class ScopeValidatorTest {
// static IValidatorContext context;
static final String IMPL_CLASS="org.gcube.informationsystem.scope.validator.ValidatorContextImpl";
static final String relativePath="src/test/java/META-INF/services/org.gcube.informationsystem.publisher.scope.IValidatorContext";
// @Rule
// public static TemporaryFolder testFolder = new TemporaryFolder();
public static File service;
// @BeforeClass
public static void writeServiceInfo() throws IOException{
service=new File(relativePath);
FileOutputStream file = new FileOutputStream(service);
PrintStream output = new PrintStream(file);
output.print(IMPL_CLASS);
output.flush();
output.close();
System.out.println("file writed ");
}
// @Test
public void test(){
IValidatorContext context=ScopeValidatorScanner.provider();
List<Validator> list= context.getValidators();
for(Validator validator : list){
System.out.println("validator founded: "+validator.type());
}
}
// @AfterClass
// public static void deleteServiceInfo() throws IOException{
// if(service.exists()){
// boolean del=service.delete();
// System.out.println("deleted? "+del);
//
// }
//
// }
}

View File

@ -1,33 +0,0 @@
package org.gcube.informationsystem.scope.validator;
import java.util.List;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.informationsystem.publisher.scope.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyGenericResourceValidator<R> implements Validator<GenericResource> {
private static Logger log = LoggerFactory.getLogger(MyGenericResourceValidator.class);
@Override
public <R extends Resource> void validate(R resource) {
log.info("validate method of "+this.getClass());
}
@Override
public Class type() {
return GenericResource.class;
}
@Override
public <R extends Resource> void checkScopeCompatibility(R resource,
List<String> scopes) {
// TODO Auto-generated method stub
}
}

View File

@ -1,35 +0,0 @@
package org.gcube.informationsystem.scope.validator;
import java.util.List;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.informationsystem.publisher.scope.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MyServiceEndpointValidator<R> implements Validator<ServiceEndpoint>{
private static Logger log = LoggerFactory.getLogger(MyServiceEndpointValidator.class);
@Override
public <R extends Resource> void validate(R resource) {
log.info("validate method of "+this.getClass());
}
@Override
public Class type() {
return ServiceEndpoint.class;
}
@Override
public <R extends Resource> void checkScopeCompatibility(R resource,
List<String> scopes) {
// TODO Auto-generated method stub
}
}

View File

@ -1,18 +0,0 @@
package org.gcube.informationsystem.scope.validator;
import java.util.Arrays;
import java.util.List;
import org.gcube.informationsystem.publisher.scope.IValidatorContext;
import org.gcube.informationsystem.publisher.scope.Validator;
public class ValidatorContextImpl implements IValidatorContext{
final static List<Validator> validators = Arrays.asList(new MyGenericResourceValidator(), new MyServiceEndpointValidator());
@Override
public List<Validator> getValidators() {
return validators;
}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Resource version="0.4.x"> <Resource version="0.4.x">
<ID>5d244ab0-9d79-11e3-af18-dd5904b11dd6</ID> <ID></ID>
<Type>RunningInstance</Type> <Type>RunningInstance</Type>
<Scopes> <Scopes>
</Scopes> </Scopes>