commit 9b645a137e3073c7d03382443d262b22962329d1 Author: roberto.cirillo Date: Wed Sep 4 12:58:06 2019 +0000 initial import v 1.3.0-SNAPSHOT git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/branches/information-system/registry-publisher/1.3@181494 82a268e6-3cf1-43bd-a215-b396298e98cf diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..0c7f994 --- /dev/null +++ b/.classpath @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..ef8a0d7 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + registry-publisher + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs new file mode 100644 index 0000000..b0f23d6 --- /dev/null +++ b/.settings/org.eclipse.core.resources.prefs @@ -0,0 +1,7 @@ +#Mon Dec 03 11:56:31 CET 2012 +eclipse.preferences.version=1 +encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 +encoding//src/test/java=UTF-8 +encoding//src/test/resources=UTF-8 +encoding/=UTF-8 diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..ec4300d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..6b4bdbf --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,5 @@ +#Mon Dec 03 11:51:29 CET 2012 +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/distro/CHANGELOG b/distro/CHANGELOG new file mode 100644 index 0000000..bc7a68f --- /dev/null +++ b/distro/CHANGELOG @@ -0,0 +1,7 @@ +v 1.2.5 (10-09-2014) + * update test class code, update removeById method +v 1.2.4 (30-06-2014) + * added method removeByID in AdvancedPublisher class +v 1.2.3 (03-04-2014) + * added filtering on scope promotion for some kind of resources: genericResource, GcoreEndpoint and Software + * update remove operation \ No newline at end of file diff --git a/distro/LICENSE b/distro/LICENSE new file mode 100644 index 0000000..7bca8c8 --- /dev/null +++ b/distro/LICENSE @@ -0,0 +1,2 @@ +${gcube.license} + diff --git a/distro/README b/distro/README new file mode 100644 index 0000000..d7fc1a1 --- /dev/null +++ b/distro/README @@ -0,0 +1,67 @@ +The gCube System - ${name} +-------------------------------------------------- + +${description} + + +${gcube.description} + +${gcube.funding} + + +Version +-------------------------------------------------- + +${version} (${buildDate}) + +Please see the file named "changelog.xml" in this directory for the release notes. + + +Authors +-------------------------------------------------- + +* Fabio Simeoni (fabio.simeoni-AT-fao.org), FAO of the UN, Italy +* Lucio Lelii (lucio.lelii-AT-isti.cnr.it), CNR, Italy +* Roberto Cirillo (roberto.cirillo-AT-isti.cnr.it), ISTI-CNR. + + +Maintainers +----------- + +* Roberto Cirillo (roberto.cirillo-AT-isti.cnr.it), ISTI-CNR. + + +Download information +-------------------------------------------------- + +Source code is available from SVN: + ${scm.url} + +Binaries can be downloaded from the gCube website: + ${gcube.website} + + +Installation +-------------------------------------------------- + +Installation documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + + +Documentation +-------------------------------------------------- + +Documentation is available on-line in the gCube Wiki: + ${gcube.wikiRoot} + +Support +-------------------------------------------------- + +Bugs and support requests can be reported in the gCube issue tracking tool: + ${gcube.issueTracking} + + +Licensing +-------------------------------------------------- + +This software is licensed under the terms you may find in the file named "LICENSE" in this directory. diff --git a/distro/changelog.xml b/distro/changelog.xml new file mode 100644 index 0000000..6d1154b --- /dev/null +++ b/distro/changelog.xml @@ -0,0 +1,33 @@ + + + VO create modified to perform resource registration only once per VO scope + + + added update and create only on VOs + + + removed scope promotion on PublisherImpl + + + remove log4j.properties file from src/main/resources folder + + + add dependency range for ic-client on pom + + + added method removeByID in AdvancedPublisher class + + + added filtering on scope promotion for some kind of resources: genericResource, GcoreEndpoint and Software + update remove operation + + + bug fixing + + + Second Release + + + First Release + + \ No newline at end of file diff --git a/distro/descriptor.xml b/distro/descriptor.xml new file mode 100644 index 0000000..dd16f0c --- /dev/null +++ b/distro/descriptor.xml @@ -0,0 +1,31 @@ + + servicearchive + + tar.gz + + / + + + ${distroDirectory} + / + true + + README + LICENSE + changelog.xml + profile.xml + + 755 + true + + + + + target/${build.finalName}.jar + /${artifactId} + + + diff --git a/distro/profile.xml b/distro/profile.xml new file mode 100644 index 0000000..f6970f3 --- /dev/null +++ b/distro/profile.xml @@ -0,0 +1,26 @@ + + + + Service + + ${description} + InformationSystem + ${artifactId} + 1.0.0 + + + ${artifactId} + ${version} + + ${groupId} + ${artifactId} + ${version} + + + ${build.finalName}.jar + + + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..23ed6a8 --- /dev/null +++ b/pom.xml @@ -0,0 +1,118 @@ + + 4.0.0 + + org.gcube.tools + maven-parent + 1.0.0 + + + + distro + + + + scm:svn:http://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/${project.artifactId} + scm:svn:https://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/${project.artifactId} + http://svn.d4science.research-infrastructures.eu/gcube/trunk/information-system/${project.artifactId} + + + org.gcube.resources + registry-publisher + 1.2.9-SNAPSHOT + + + + + org.gcube.resources + common-gcore-resources + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + + + + org.gcube.core + common-gcore-stubs + [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + + + + org.slf4j + slf4j-api + 1.6.4 + + + + org.gcube.resources.discovery + ic-client + [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) + + + + + org.slf4j + slf4j-log4j12 + 1.6.4 + test + + + junit + junit + 4.11 + test + + + + + + + + org.apache.maven.plugins + maven-resources-plugin + 2.5 + + + copy-profile + install + + copy-resources + + + target + + + ${distroDirectory} + true + + profile.xml + + + + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + ${distroDirectory}/descriptor.xml + + + + + servicearchive + install + + single + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/common/resources/gcore/ResourceMediator.java b/src/main/java/org/gcube/common/resources/gcore/ResourceMediator.java new file mode 100644 index 0000000..d9a61c0 --- /dev/null +++ b/src/main/java/org/gcube/common/resources/gcore/ResourceMediator.java @@ -0,0 +1,23 @@ +package org.gcube.common.resources.gcore; + + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ResourceMediator { + + private static final Logger log = LoggerFactory.getLogger(ResourceMediator.class); + + public static void setId(Resource resource, String id) { + resource.setId(id); + log.debug(id+"new id resource: "+resource.id()); + } + + public static void setScope(Resource resource, String scope){ + resource.scopes().add(scope); + } + public static void removeScope(Resource resource, String scope){ + resource.scopes().remove(scope); + } + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/AdvancedPublisher.java b/src/main/java/org/gcube/informationsystem/publisher/AdvancedPublisher.java new file mode 100644 index 0000000..0cb4040 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/AdvancedPublisher.java @@ -0,0 +1,54 @@ +package org.gcube.informationsystem.publisher; + +import java.util.List; + +import org.gcube.common.resources.gcore.Resource; +import org.gcube.informationsystem.publisher.utils.RegistryStubs; +/** + * Wrapper class of RegistryPublisherImpl class that implements the RegistryPublisher interface + * + * @author rcirillo + * + */ +public class AdvancedPublisher extends AdvancedPublisherCommonUtils implements RegistryPublisher { + + private RegistryPublisher publisher; + private RegistryStubs registry; + + public AdvancedPublisher(){ + publisher=new RegistryPublisherImpl(); + registry=new RegistryStubs(); + } + + public AdvancedPublisher(RegistryPublisher publisher){ + this.publisher=publisher; + registry=new RegistryStubs(); + } + + @Override + public T create(T resource) { + return publisher.create(resource); + } + + @Override + public T update(T resource) { + return publisher.update(resource); + } + + @Override + public T remove(T resource) { + return publisher.remove(resource); + } + + @Override + public T vosCreate(T resource, List scopes) { + return publisher.vosCreate(resource, scopes); + } + + @Override + public T vosUpdate(T resource) { + return publisher.vosUpdate(resource); + } + + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/AdvancedPublisherCommonUtils.java b/src/main/java/org/gcube/informationsystem/publisher/AdvancedPublisherCommonUtils.java new file mode 100644 index 0000000..1d1ce04 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/AdvancedPublisherCommonUtils.java @@ -0,0 +1,140 @@ +package org.gcube.informationsystem.publisher; + +import java.net.URI; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; + +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.ResourceMediator; +import org.gcube.common.resources.gcore.ScopeGroup; +//import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.scope.impl.ScopeBean.Type; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; +import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; +import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceDoesNotExistException; +import org.gcube.informationsystem.publisher.utils.RegistryStubs; +import org.gcube.informationsystem.publisher.utils.ValidationUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class AdvancedPublisherCommonUtils { + + protected RegistryStubs registry; + private static final Logger log = LoggerFactory.getLogger(AdvancedPublisher.class); + + /** + * Remove the input resource: + * if is a VRE scope: delete profile from IS + * if is a VO scope: delete profile from IS + * if is a INFRA scope: delete profile in the infra and for every VO under the infrastructures + * @throws IllegalArgumentException if there are problems to contact the Registry service + */ + public T forceRemove(T resource){ + RegistryStub stub=null; + registry=new RegistryStubs(); + String currentScope=ScopeProvider.instance.get(); + if(new ScopeBean(currentScope).is(Type.VRE) || new ScopeBean(currentScope).is(Type.VO)){ + ScopeGroup scopes=resource.scopes(); + List scopesToRemove=new LinkedList(); + for(Iterator it=scopes.iterator(); it.hasNext();){ + String scope=it.next(); + log.debug(" check scope: "+scope); + // if the scope is present in the resource then The resource will be removed from VO + if(scope.equals(currentScope)){ + ScopeProvider.instance.set(scope); + try{ + stub=registry.getStubs(); + }catch(RegistryNotFoundException e){ + throw new IllegalArgumentException(e.getCause()); + } + log.debug("remove scope "+scope); + try{ + stub.remove(resource.id(), resource.type().toString()); + }catch(ResourceDoesNotExistException e){ + // if the scope is a VRE scope probably the resource has already been deleted from VO scope + // it must be removed from the resource + } + scopesToRemove.add(scope); + } + } + for(String scope : scopesToRemove){ + ResourceMediator.removeScope(resource, scope); + } + + }else{ // it is a INFRA scope, the resource will be removed from all the VO scopes under this infra + ScopeGroup scopes=resource.scopes(); + List scopesToRemove=new LinkedList(); + for(Iterator it=scopes.iterator(); it.hasNext();){ + String scope=it.next(); + log.debug(" check scope: "+scope); + String voScope=null; + if(new ScopeBean(scope).is(Type.VRE)){ + voScope=new ScopeBean(scope).enclosingScope().toString(); + } + // if the scope is present in the resource then The resource will be removed from VO + if((scope.equals(currentScope)) || (ValidationUtils.isChildScope(currentScope, scope)) || ( (voScope != null) && (ValidationUtils.isChildScope(currentScope, voScope)) )){ + ScopeProvider.instance.set(scope); + try{ + stub=registry.getStubs(); + }catch(RegistryNotFoundException e){ + throw new IllegalArgumentException(e.getCause()); + } + log.debug("remove scope "+scope); + try{ + stub.remove(resource.id(), resource.type().toString()); + }catch(ResourceDoesNotExistException e){ + // if the scope is a VRE scope probably the resource has already been deleted from VO scope + // it must be removed from the resource + } + scopesToRemove.add(scope); + } + } + for(String scope : scopesToRemove){ + ResourceMediator.removeScope(resource, scope); + } + + } + ScopeProvider.instance.set(currentScope); + return resource; + } + + public void removeById(String id, org.gcube.common.resources.gcore.Resource.Type type){ + RegistryStub stub=null; + registry=new RegistryStubs(); + String currentScope=ScopeProvider.instance.get(); + try{ + stub=registry.getStubs(); + }catch(RegistryNotFoundException e){ + throw new IllegalArgumentException(e.getCause()); + } + log.debug("remove "+id+" from scope "+currentScope); + try{ + stub.remove(id, type.toString()); + }catch(ResourceDoesNotExistException e){ + // if the scope is a VRE scope probably the resource has already been deleted from VO scope + // it must be removed from the resource + } + } + + public void removeById(String id, org.gcube.common.resources.gcore.Resource.Type type, URI endpoint){ + RegistryStub stub=null; + registry=new RegistryStubs(); + String currentScope=ScopeProvider.instance.get(); + try{ + stub=registry.getStubs(endpoint); + }catch(RegistryNotFoundException e){ + throw new IllegalArgumentException(e.getCause()); + } + log.debug("remove "+id+" from scope "+currentScope); + try{ + stub.remove(id, type.toString()); + }catch(ResourceDoesNotExistException e){ + // if the scope is a VRE scope probably the resource has already been deleted from VO scope + // it must be removed from the resource + } + } + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/AdvancedScopedPublisher.java b/src/main/java/org/gcube/informationsystem/publisher/AdvancedScopedPublisher.java new file mode 100644 index 0000000..f602178 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/AdvancedScopedPublisher.java @@ -0,0 +1,53 @@ +package org.gcube.informationsystem.publisher; + +import java.util.List; + +import org.gcube.common.resources.gcore.Resource; +import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; + + +/** + * Wrapper class of ScopedPublisherImpl class that implements the ScopedPublisher interface + * + * @author rcirillo + * + */ + +public class AdvancedScopedPublisher extends AdvancedPublisherCommonUtils implements ScopedPublisher { + + private ScopedPublisher publisher; + + public AdvancedScopedPublisher(){ + publisher=new ScopedPublisherImpl(); + } + + public AdvancedScopedPublisher(ScopedPublisher publisher){ + this.publisher=publisher; + } + + @Override + public T create(T resource, List scopes) + throws RegistryNotFoundException { + return publisher.create(resource, scopes); + } + + @Override + public T update(T resource) + throws RegistryNotFoundException { + return publisher.update(resource); + } + + @Override + public T remove(T resource, List scopes) + throws RegistryNotFoundException { + return publisher.remove(resource, scopes); + } + +// @Override +// public void remove(String id, Type type, List scopes) +// throws RegistryNotFoundException { +// publisher.remove(id, type, scopes); +// +// } + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisher.java b/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisher.java new file mode 100644 index 0000000..7ab6175 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisher.java @@ -0,0 +1,52 @@ +package org.gcube.informationsystem.publisher; + +import java.util.List; + +import org.gcube.common.resources.gcore.Resource; + +public interface RegistryPublisher { + + /** + * The resource is created in the current scope and it is updated in the other scopes that are presents in the resource. + * If is a VRE scope then in the resource will be added also the VO and INFRA scopes if they are not already presents in the resource + * If is a VO scope then in the resource will be added also the INFRA scope if it is not already present in the resource + * @throws IllegalStateException if the current scope is incompatible with the scope defined in the resource or if the scope is already defined in the resource + * @throws IllegalArgumentException if there are problems to contact the Registry service or the resource is not a valid resource + */ + T create(T resource); + + /** + * The resource is created in all VOs scopes that are presents in the resource. + * @throws IllegalStateException if scopes is null + * @throws IllegalArgumentException if there are problems to contact the Registry service or the resource is not a valid resource + */ + < T extends Resource> T vosCreate(T resource, List scopes); + + /** + * The resource will be updated on all the scopes that are defined in the resource. + * If an updating operation fail. It will be repeated with best-effort delivery approach + * @throws IllegalStateException if the current scope is not defined in the resource. + * @throws IllegalArgumentException if there are problems with the registry service or the resource is not a valid resource + */ + T update(T resource); + + /** + * The resource will be updated on all the VO scopes that are defined in the resource. + * If an updating operation fail. It will be repeated with best-effort delivery approach + * @throws IllegalStateException if the current scope is not defined in the resource. + * @throws IllegalArgumentException if there are problems with the registry service or the resource is not a valid resource + */ + T vosUpdate(T resource); + + /** + * 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 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 remove(T resource); + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisherFactory.java b/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisherFactory.java new file mode 100644 index 0000000..5da0c8c --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisherFactory.java @@ -0,0 +1,20 @@ +package org.gcube.informationsystem.publisher; + +public class RegistryPublisherFactory { + + private static RegistryPublisher singleton = new RegistryPublisherImpl(); + + public static RegistryPublisher create(){ + return singleton; + } + + + public static void setPublisher(RegistryPublisher registryPublisher){ + singleton = registryPublisher; + } + + public static ScopedPublisher scopedPublisher(){ + return new ScopedPublisherImpl(singleton); + } + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisherImpl.java b/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisherImpl.java new file mode 100644 index 0000000..fe00f3e --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/RegistryPublisherImpl.java @@ -0,0 +1,407 @@ +package org.gcube.informationsystem.publisher; + +import java.io.StringWriter; +import java.util.Arrays; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.UUID; + +import javax.xml.ws.soap.SOAPFaultException; + +import org.gcube.common.clients.stubs.jaxws.JAXWSUtils; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.ResourceMediator; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.resources.gcore.ScopeGroup; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.common.scope.impl.ScopeBean.Type; +import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; +import org.gcube.informationsystem.publisher.scope.ValidatorProvider; +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.InvalidResourceException; +import org.gcube.informationsystem.publisher.stubs.registry.faults.ResourceNotAcceptedException; +import org.gcube.informationsystem.publisher.stubs.registry.faults.UpdateException; +import org.gcube.informationsystem.publisher.utils.RegistryStubs; +import org.gcube.informationsystem.publisher.utils.ValidationUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class RegistryPublisherImpl implements RegistryPublisher { + + private static final Logger log = LoggerFactory.getLogger(RegistryPublisher.class); + private static final int REGISTRY_THRESHOLD = 5; + private RegistryStubs registry; + /** + * Used in create operation. If is not null the update on this scope will never be done + */ + private String scopeCreated; + + protected RegistryPublisherImpl(){ + registry=new RegistryStubs(); + }; + + /** + * The resource is created in the current scope and it is updated in the other scopes that are presents in the resource. + * If is a VRE scope then in the resource will be added also the VO and INFRA scope if they are not present + * If is a VO scope then in the resource will be added also the INFRA scope if it is not present + * @throws RegistryNotFoundException if no service endpoints can be discovered + * @throws InvalidResourceExceptionwhen the resource type is invalid service. + * @throws ResourceNotAcceptedException when the resource is not accepted cause it doesn't satisfy a requirement + * @throws CreateException when something is failed on creation + */ + + public < T extends Resource> T create(T resource){ + String scope=ScopeProvider.instance.get(); + T res = internalCreate(resource, scope); + scopeCreated=scope; + res=update(res); + return res; + } + + public < T extends Resource> T vosCreate(T resource, List scopes){ + T res = internalVosCreate(resource, scopes); + return res; + } + + private < T extends Resource> T internalVosCreate(T resource, List scopes){ + String currentScope=ScopeProvider.instance.get(); + ValidationUtils.valid("resource", resource);// helper that throws an IllegalArgumentException if resource are null + ValidationUtils.valid("scopes", scopes);// helper that throws an IllegalArgumentException if scopes are null + if ((resource.id()== null) || (resource.id().isEmpty())){ + // set id + String id=UUID.randomUUID().toString(); + log.debug("id generated: "+id); + ResourceMediator.setId(resource, id); + } + + HashSet vosScopes = new HashSet(); + for(String scope: scopes){ + ScopeBean scopeBean = new ScopeBean(scope); + if(scopeBean.is(Type.VRE)) + vosScopes.add(scopeBean.enclosingScope().toString()); + else vosScopes.add(scope); + log.debug("[VOCREATE] scope found {}",scope); + ResourceMediator.setScope(resource, scope); + } + + try { + Resources.validate(resource); + } catch (Exception e) { + log.error("the resource is not valid", e); + throw new IllegalArgumentException("the resource is not valid ", e.getCause()); + } + + try{ + for (String voScope: vosScopes){ + // if update is calling on create operation and the scope is not equal to create operation scope or if is a simple update operation, try to update it + log.trace("[VOCREATE] resource "+resource.id()+" update in scope {} with scopes {} ",voScope, resource.scopes().asCollection()); + ScopeProvider.instance.set(voScope); + //retrieve registry stub + RegistryStub stub = getRegistryStub(); + createResource(resource, voScope, stub); + } + }finally{ + ScopeProvider.instance.set(currentScope); + } + log.trace("[VOCREATE] resource created with scopes {}",resource.scopes().asCollection()); + return resource; + } + + private < T extends Resource> T internalCreate(T resource, String scope){ + log.trace("registry-publisher: create method"); + + ValidationUtils.valid("resource", resource);// helper that throws an IllegalArgumentException if resource are null + ValidationUtils.valid("scopes", scope);// helper that throws an IllegalArgumentException if scopes are null + if(ValidationUtils.isPresent(resource, scope)) + throw new IllegalStateException("The scope "+scope+" is already present in the resource. The create operation can't be performed "); + log.debug("resource id found: "+resource.id()); + if ((resource.id()== null) || (resource.id().isEmpty())){ + // set id + String id=UUID.randomUUID().toString(); + log.debug("id generated: "+id); + ResourceMediator.setId(resource, id); + } + // set scope on resource + log.debug("scope set in resource: {} ",scope); + ResourceMediator.setScope(resource, scope); + // check if the scope is compatible with the scopes defined in the resources + ValidatorProvider.getValidator(resource).checkScopeCompatibility(resource, Arrays.asList(scope)); + // add enclosing scopes to the resource with filtering on GenericResource, RunningIstance, and Service resources + String type=resource.type().toString(); + + /* + if((!type.equalsIgnoreCase("GenericResource")) && (!(type.equalsIgnoreCase("RunningInstance"))) && (!(type.equalsIgnoreCase("Service")))){ + ValidationUtils.addEnclosingScopesOnResource(resource, scope); + }else{ + log.debug(" Resource type: "+type+": for this type of resource there isn't scope promotion"); + }*/ + try { + Resources.validate(resource); + } catch (Exception e) { + log.error("the resource is not valid", e); + throw new IllegalArgumentException("the resource is not valid ", e.getCause()); + } + //retrieve registry stub + RegistryStub stub = getRegistryStub(); + createResource(resource, scope, stub); + log.trace("resource created in scope {} with scopes {}",scope, resource.scopes().asCollection()); + return resource; + } + + + + /** + * The resource will be updated on all the scopes that are defined in the resource. + * If an updating operation fail. It will be repeated with best-effort delivery approach + * @throws RegistryNotFoundException if no service endpoints can be discovered + * @throws InvalidResourceException when the resource type is invalid service. + * @throws ResourceNotAcceptedException when the resource is not accepted cause it doesn't satisfy a requirement + * @throws CreateException when something is failed on creation + */ + public T update(T resource){ + log.trace("[UPDATE] update resource with id : "+resource.id()); + String currentScope=ScopeProvider.instance.get(); + ValidationUtils.valid("resource", resource);// helper that throws an IllegalArgumentException if resource are null + validateScope(resource); // is empty + try { + Resources.validate(resource); + } catch (Exception e) { + log.error("the resource is not valid", e); + throw new IllegalArgumentException("the resource is not valid", e); + } + // retrieves the scopes on resource + ScopeGroup scopes=resource.scopes(); + int tries=0; + try{ + for(String scope: scopes){ + log.debug("[UPDATE] check update operation on scope "+scope); + // if update is calling on create operation and the scope is not equal to create operation scope or if is a simple update operation, try to update it + if((scopeCreated == null) || ((scopeCreated!=null) && (!scopeCreated.equals(scope)))){ + log.trace("[UPDATE] resource update in scope {} with scopes {} ",scope, resource.scopes().asCollection()); + ScopeProvider.instance.set(scope); + registryUpdate(resource, tries); + tries=0; + }else{ + log.trace("skip updating on scope "+scopeCreated); + } + + } + }finally{ + scopeCreated=null; + // reset the scope + ScopeProvider.instance.set(currentScope); + } + return resource; + } + + @Override + public T vosUpdate(T resource) { + log.trace("[VOUPDATE] update resource with id : "+resource.id()); + String currentScope=ScopeProvider.instance.get(); + ValidationUtils.valid("resource", resource);// helper that throws an IllegalArgumentException if resource are null + validateScope(resource); // is empty + try { + Resources.validate(resource); + } catch (Exception e) { + log.error("the resource is not valid", e); + throw new IllegalArgumentException("the resource is not valid", e); + } + + HashSet vosScopes = new HashSet(); + int tries=0; + for(String scope: resource.scopes().asCollection()){ + ScopeBean scopeBean = new ScopeBean(scope); + if(scopeBean.is(Type.VRE)) + vosScopes.add(scopeBean.enclosingScope().toString()); + else vosScopes.add(scope); + log.debug("[VOUPDATE] scope found {}",scope); + } + + log.debug("[VOUPDATE] scopes in resources {}",resource.scopes().asCollection()); + + try{ + for (String voScope: vosScopes){ + log.debug("[VOUPDATE] check update operation on scope {} ",voScope); + // if update is calling on create operation and the scope is not equal to create operation scope or if is a simple update operation, try to update it + if((scopeCreated == null) || ((scopeCreated!=null) && (!scopeCreated.equals(voScope)))){ + log.trace("[VOUPDATE] resource "+resource.id()+" update in scope {} with scopes {} ",voScope, resource.scopes().asCollection()); + ScopeProvider.instance.set(voScope); + registryUpdate(resource, tries); + tries=0; + }else{ + log.trace("[VOUPDATE] skip updating on scope {}",scopeCreated); + } + + } + }finally{ + scopeCreated=null; + ScopeProvider.instance.set(currentScope); + } + return resource; + } + + /** + * 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 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 remove(T resource){ + String currentScope=ScopeProvider.instance.get(); + log.info(" remove resource with id : "+resource.id()+" from scope: "+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); + 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 "+currentScope+" scope from resource "+resource.id()); + ResourceMediator.removeScope(resource, currentScope); + // retrieves the scopes on resource and update it + // updateResource(resource, currentScope); + try{ + updateResourceRemoveOperation(resource, currentScope); + }catch(Exception e){ + ResourceMediator.setScope(resource, currentScope); + log.error("exception message: "+e.getMessage()); + throw new RuntimeException(e.getMessage()); + } + return resource; + } + + + 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()); + try{ + registry.getStubs().update(resource.id(),resource.type().toString(), toXml(resource) ); + }catch(RegistryNotFoundException e){ + throw new IllegalArgumentException(e.getCause()); + }catch(InvalidResourceException e){ + throw new IllegalArgumentException(e.getCause()); + }catch(ResourceNotAcceptedException e){ + throw new IllegalArgumentException(e.getCause()); + }catch(UpdateException e){ + throw new IllegalArgumentException(e.getCause()); + }catch(SOAPFaultException e) { + log.warn("Failed update resource on "+registry.getEndPoints().get(0)+" times: "+(tries+1)); + if(tries< REGISTRY_THRESHOLD){ + tries++; + try { + Thread.sleep(3000); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + registryUpdate(resource, tries); + } + throw new IllegalArgumentException(JAXWSUtils.remoteCause(e)); + } + } + + + private String toXml(Resource resource){ + StringWriter writer = new StringWriter(); + Resources.marshal(resource, writer); + return writer.toString(); + } + + private void validateScope(Resource resource){ + ValidatorProvider.getValidator(resource).validate(resource); + } + + /** + * If is the last scope on Resource, the resource will be removed else the resource will be updated + * @param resource + * @param currentScope + */ + private void updateResourceRemoveOperation(T resource, String currentScope) { + if(!isRemoveNeeded(resource, currentScope)){ + updateResource(resource, currentScope); + }else{ // remove the profile from IC + log.info("the resource have only the "+currentScope+" scope defined. Remove the resource "+resource.id()+" from IC"); + // if the resource not have any scope, the resource will be removed + try { + log.debug("remove from IS scope "+currentScope); + registry.getStubs().remove(resource.id(), resource.type().toString()); + } 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); + } + // ScopeBean currentScopeBean=new ScopeBean(currentScope); + // if(currentScopeBean.is(Type.VRE)){ + // log.debug("remove from resource scope "+currentScopeBean.enclosingScope().toString()); + // ResourceMediator.removeScope(resource, currentScopeBean.enclosingScope().toString()); + // log.debug("remove from resource scope "+currentScope); + // ResourceMediator.removeScope(resource, currentScope); + // }else if(currentScopeBean.is(Type.VO)){ + // log.debug("remove from resource scope "+currentScope); + // ResourceMediator.removeScope(resource, currentScope); + // } + updateResource(resource, currentScope); + } + } + + + private boolean isRemoveNeeded(T resource, String scope){ + if(ValidationUtils.isCompatibleScopeForRemove(resource, scope)){ + return true; + }else{ + return false; + } + } + + private void createResource(T resource, String scope, RegistryStub stub) { + try{ + log.info("create resource with id "+resource.id()+" in scope: "+scope); + String type=null; + type=resource.type().toString(); + log.info("resource type is: "+type); + if(resource.type().equals("ServiceEndpoint")) + type="RuntimeResource"; + stub.create(toXml(resource), type); + }catch(InvalidResourceException e){ + throw new IllegalArgumentException(e.getCause()); + }catch(ResourceNotAcceptedException e){ + throw new IllegalArgumentException(e.getCause()); + }catch(CreateException e){ + throw new IllegalArgumentException(e.getCause()); + }catch(SOAPFaultException e) { + throw new IllegalArgumentException(JAXWSUtils.remoteCause(e)); + } + log.info("created resource "+resource.id()+" on scope "+scope); + } + + private RegistryStub getRegistryStub() { + RegistryStub stub=null; + try{ + stub=registry.getStubs(); + }catch(RegistryNotFoundException e){ + throw new IllegalArgumentException(e.getCause()); + } + return stub; + } + + private void updateResource(T resource, String currentScope) { + ScopeGroup scopes=resource.scopes(); + int tries=0; + for(Iterator it=scopes.iterator();it.hasNext();){ + String scope=(String)it.next(); + ScopeProvider.instance.set(scope); + registryUpdate(resource, tries); + + } + // reset the scope + ScopeProvider.instance.set(currentScope); + } + + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/ScopedPublisher.java b/src/main/java/org/gcube/informationsystem/publisher/ScopedPublisher.java new file mode 100644 index 0000000..bf2d529 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/ScopedPublisher.java @@ -0,0 +1,31 @@ +package org.gcube.informationsystem.publisher; + +import java.util.List; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; + +public interface ScopedPublisher { + + /** + * The resource is created in all the scopes in the list and the resource is updated in all the other scopes that are presents in the resource + * @throws IllegalStateException if the current scope is incompatible with the scope defined in the resource + * @throws IllegalArgumentException if there are problems to contact the Registry service or the resource is not a valid resource + */ + public T create(T resource, List scopes) throws RegistryNotFoundException; + + /** + * The resource will be updated on all scopes that are defined in the resource. + * If an updating operation fail. It will be repeated with best-effort strategy. + * @throws IllegalStateException if the current scope is not defined in the resource. + * @throws IllegalArgumentException if there are problems with the registry service or the resource is not a valid resource + */ + public T update(T resource) throws RegistryNotFoundException; + + /** + * Remove a resource from all the scopes in the input list, if and only if all the scopes are defined in the resource + * @throws IllegalArgumentException if one or more scopes in the list are not defined in the resource + * @return the resource without the current scope if the remove operation is succesfully + */ + public T remove(T resource, List scopes) throws RegistryNotFoundException; + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/ScopedPublisherImpl.java b/src/main/java/org/gcube/informationsystem/publisher/ScopedPublisherImpl.java new file mode 100644 index 0000000..94113bf --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/ScopedPublisherImpl.java @@ -0,0 +1,59 @@ +package org.gcube.informationsystem.publisher; + +import java.util.List; + +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + + +public class ScopedPublisherImpl implements ScopedPublisher{ + private RegistryPublisher registryPublisher; + private static final Logger log = LoggerFactory.getLogger(ScopedPublisherImpl.class); + + + protected ScopedPublisherImpl(){ + registryPublisher=new RegistryPublisherImpl(); + } + + protected ScopedPublisherImpl(RegistryPublisher rp){ + registryPublisher=rp; + } + + @Override + public T create(T resource, List scopes) throws RegistryNotFoundException{ + return registryPublisher.vosCreate(resource, scopes); + } + + @Override + public T update(T resource) throws RegistryNotFoundException{ + log.info("[UPDATE] call to registryPublisher upadate method on resource "+resource.id()+" in scope {} with scopes {} ", ScopeProvider.instance.get(), resource.scopes().asCollection()); + return registryPublisher.vosUpdate(resource); + } + + +// public void remove(String id, Type type, List scopes) throws RegistryNotFoundException { +// String currentScope=ScopeProvider.instance.get(); +// for(String scope : scopes){ +// ScopeProvider.instance.set(scope); +// log.info("call to registryPublisher remove method with scope "+scope); +// registryPublisher.remove(id, type); +// } +// ScopeProvider.instance.set(currentScope); +// } + + @Override + public T remove(T resource, List scopes) throws RegistryNotFoundException{ + String currentScope=ScopeProvider.instance.get(); + for(String scope : scopes){ + ScopeProvider.instance.set(scope); + registryPublisher.remove(resource); + } + ScopeProvider.instance.set(currentScope); + return resource; + } + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/cache/RegistryCache.java b/src/main/java/org/gcube/informationsystem/publisher/cache/RegistryCache.java new file mode 100644 index 0000000..fcd8283 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/cache/RegistryCache.java @@ -0,0 +1,39 @@ +package org.gcube.informationsystem.publisher.cache; + +import java.net.URI; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class RegistryCache extends LinkedHashMap>{ + + private final int capacity; + private long accessCount = 0; + private long hitCount = 0; + + public RegistryCache(int capacity){ + super(capacity + 1, 1.1f, true); + this.capacity = capacity; + } + + public List get(String key){ + accessCount++; + if (containsKey(key)){ + hitCount++; + } + List value = super.get(key); + return value; + } + + protected boolean removeEldestEntry(Map.Entry eldest){ + return size() > capacity; + } + + public long getAccessCount(){ + return accessCount; + } + + public long getHitCount(){ + return hitCount; + } +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/exception/RegistryNotFoundException.java b/src/main/java/org/gcube/informationsystem/publisher/exception/RegistryNotFoundException.java new file mode 100644 index 0000000..7966edc --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/exception/RegistryNotFoundException.java @@ -0,0 +1,29 @@ +package org.gcube.informationsystem.publisher.exception; + +public class RegistryNotFoundException extends Exception { + + /** + * + */ + private static final long serialVersionUID = -8265959805049300612L; + + public RegistryNotFoundException() { + super(); + } + + public RegistryNotFoundException(String arg0, Throwable arg1) { + super(arg0, arg1); + } + + public RegistryNotFoundException(String arg0) { + super(arg0); + } + + public RegistryNotFoundException(Throwable arg0) { + super(arg0); + } + + + + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/scope/DefaultScopeValidator.java b/src/main/java/org/gcube/informationsystem/publisher/scope/DefaultScopeValidator.java new file mode 100644 index 0000000..52eaef1 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/scope/DefaultScopeValidator.java @@ -0,0 +1,48 @@ +package org.gcube.informationsystem.publisher.scope; + +import java.util.List; + +import org.gcube.common.resources.gcore.Resource; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DefaultScopeValidator implements Validator{ + + private static Logger log = LoggerFactory.getLogger(DefaultScopeValidator.class); + + @Override + public void validate(R resource) { +// log.info("validate method of "+this.getClass()); +// String currentScope=ScopeProvider.instance.get(); +// ScopeGroup scopes=resource.scopes(); +// boolean founded= false; +// for(Iterator 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 + public Class type() { + return Resource.class; + } + + @Override + public void checkScopeCompatibility(R resource, + List scopesList) { +// for(String scope: scopesList){ +// ScopeGroup scopes=resource.scopes(); +// for(Iterator it=scopes.iterator(); it.hasNext();){ +// String scopeItem=it.next(); +// if((!scopeItem.contains(scope)) && (!scope.contains(scopeItem))) +// throw new IllegalStateException("The scope "+scope+" is not compatible with scope: "+scopeItem+" that is present in the resource"+ resource.id()); +// } +// } + } + + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/scope/DefaultValidatorContext.java b/src/main/java/org/gcube/informationsystem/publisher/scope/DefaultValidatorContext.java new file mode 100644 index 0000000..9fa3280 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/scope/DefaultValidatorContext.java @@ -0,0 +1,18 @@ +package org.gcube.informationsystem.publisher.scope; + +import java.util.Arrays; +import java.util.List; + +import org.gcube.common.resources.gcore.Resource; + + +public class DefaultValidatorContext implements IValidatorContext{ + + final static List validators = Arrays.asList((Validator)new DefaultScopeValidator()); + + @Override + public List getValidators() { + return validators; + } + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/scope/IValidatorContext.java b/src/main/java/org/gcube/informationsystem/publisher/scope/IValidatorContext.java new file mode 100644 index 0000000..0ff0a8a --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/scope/IValidatorContext.java @@ -0,0 +1,9 @@ +package org.gcube.informationsystem.publisher.scope; + +import java.util.List; + +public interface IValidatorContext { + + List getValidators(); + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/scope/ScopeValidatorScanner.java b/src/main/java/org/gcube/informationsystem/publisher/scope/ScopeValidatorScanner.java new file mode 100644 index 0000000..d9cf387 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/scope/ScopeValidatorScanner.java @@ -0,0 +1,52 @@ +package org.gcube.informationsystem.publisher.scope; + +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ScopeValidatorScanner { + + private static Logger log = LoggerFactory.getLogger(ScopeValidatorScanner.class); + private static ClassLoader loader; + + public static IValidatorContext provider() { + + loader = Thread.currentThread().getContextClassLoader(); +// addJarsToClasspath("customValidator.jar","scope-validator.jar"); + try { + IValidatorContext impl = null; + ServiceLoader loader = ServiceLoader.load(IValidatorContext.class); + Iterator iterator = loader.iterator(); + List impls = new ArrayList(); + while(iterator.hasNext()) + impls.add(iterator.next()); + if (impls.size()==0) { + impl = new DefaultValidatorContext(); + } + else if (impls.size()>1) + throw new Exception("mis-configured environment: detected multiple default validator "+impls); + else + impl=impls.get(0); + log.info("using scope validator "+impl); + return impl; + } catch (Exception e) { + throw new RuntimeException("could not configure scope validator", e); + } + } + + private static void addJarsToClasspath(String ... jars) { + + List jarUrls = new ArrayList(); + for (String jar : jars) + jarUrls.add(loader.getResource(jar)); + URLClassLoader urlClassLoader + = new URLClassLoader(jarUrls.toArray(new URL[0]),loader); + Thread.currentThread().setContextClassLoader(urlClassLoader); + } + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/scope/Validator.java b/src/main/java/org/gcube/informationsystem/publisher/scope/Validator.java new file mode 100644 index 0000000..0797eb7 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/scope/Validator.java @@ -0,0 +1,14 @@ +package org.gcube.informationsystem.publisher.scope; + +import java.util.List; + +import org.gcube.common.resources.gcore.Resource; + +public interface Validator { + + void validate(R resource); + void checkScopeCompatibility(R resource, List scopes); + + public Class type(); + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/scope/ValidatorProvider.java b/src/main/java/org/gcube/informationsystem/publisher/scope/ValidatorProvider.java new file mode 100644 index 0000000..d8f9b84 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/scope/ValidatorProvider.java @@ -0,0 +1,30 @@ +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; + +public class ValidatorProvider { + + private static Map validatorsMap= new LinkedHashMap(); + + + public static Validator getValidator(Resource resource){ + Validator validator=null; + if(validatorsMap.isEmpty()){ + IValidatorContext context= ScopeValidatorScanner.provider(); + List 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; + } + + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/CollectorConstants.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/CollectorConstants.java new file mode 100644 index 0000000..2760d1f --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/CollectorConstants.java @@ -0,0 +1,33 @@ +package org.gcube.informationsystem.publisher.stubs.collector; + +import static org.gcube.common.clients.stubs.jaxws.GCoreServiceBuilder.*; + +import javax.xml.namespace.QName; + +import org.gcube.common.clients.stubs.jaxws.GCoreService; + +/** + * Stub-related constants. + * + * @author Fabio Simeoni + * + */ +public class CollectorConstants { + + //public constants + public static final String namespace = "http://gcube-system.org/namespaces/informationsystem/collector/XQueryAccess/service"; + public static final String localname = "XQueryAccessService"; + public static final QName name = new QName(namespace,localname); + + public static String service_class="InformationSystem"; + public static String service_name="IS-Collector"; + + //package-private constants for JAXWS interface annotations + static final String target_namespace = "http://gcube-system.org/namespaces/informationsystem/collector/XQueryAccess"; + static final String portType = "XQueryAccessPortType"; + static final String port = "XQueryAccessPortTypePort"; + + public final static GCoreService collector = service().withName(name). + coordinates(service_class, service_name). + andInterface(CollectorStub.class); +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/CollectorStub.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/CollectorStub.java new file mode 100644 index 0000000..3b6c32b --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/CollectorStub.java @@ -0,0 +1,29 @@ +package org.gcube.informationsystem.publisher.stubs.collector; + +import static org.gcube.informationsystem.publisher.stubs.collector.CollectorConstants.*; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; +import javax.xml.ws.soap.SOAPFaultException; + +/** + * A local interface to the resource discovery service. + * + * + */ +@WebService(name=portType,targetNamespace=target_namespace) +public interface CollectorStub { + + /** + * Executes a {@link QueryStub}. + * @param query the query + * @return the query results + * @throws MalformedQueryException if the query is malformed + * @throws SOAPFaultException if the query cannot be executed + */ + @WebMethod(operationName="XQueryExecute") + @WebResult(name="Dataset") + String execute(@WebParam(name="XQueryExpression") String query) throws MalformedQueryException; +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/MalformedQueryException.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/MalformedQueryException.java new file mode 100644 index 0000000..eb6a07c --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/collector/MalformedQueryException.java @@ -0,0 +1,26 @@ +package org.gcube.informationsystem.publisher.stubs.collector; + +import javax.xml.ws.WebFault; + +/** + * Thrown by {@link CollectorStub#execute(String)} when the query cannot be submitted to the Information Collector + * service. + */ +@WebFault(name = "XQueryFaultType") +public class MalformedQueryException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates an instance with a given message and an {@link AxisFaultInfo} payload + * @param message the message + * @param info the payload + */ + public MalformedQueryException(String message) { + super(message); + } +} + diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryConstants.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryConstants.java new file mode 100644 index 0000000..626a9fb --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryConstants.java @@ -0,0 +1,34 @@ +package org.gcube.informationsystem.publisher.stubs.registry; + +import static org.gcube.common.clients.stubs.jaxws.GCoreServiceBuilder.*; + +import javax.xml.namespace.QName; + +import org.gcube.common.clients.stubs.jaxws.GCoreService; + +/** + * Stub-related constants. + * + * @author Fabio Simeoni + * + */ +public class RegistryConstants { + + //public constants + public static final String namespace = "http://gcube-system.org/namespaces/informationsystem/registry/resourceregistration/service"; + public static final String localname = "ResourceRegistrationService"; + public static final QName name = new QName(namespace,localname); + + public static String service_class="InformationSystem"; + public static String service_name="IS-Registry"; + public static String service_entrypoint="gcube/informationsystem/registry/ResourceRegistration"; + + //package-private constants for JAXWS interface annotations + static final String target_namespace = "http://gcube-system.org/namespaces/informationsystem/registry/resourceregistration"; + static final String portType = "ResourceRegistrationPortType"; + static final String port = "ResourceRegistrationPortTypePort"; + + public final static GCoreService registry = service().withName(name). + coordinates(service_class, service_name). + andInterface(RegistryStub.class); +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryStub.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryStub.java new file mode 100644 index 0000000..eb12315 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/RegistryStub.java @@ -0,0 +1,66 @@ +package org.gcube.informationsystem.publisher.stubs.registry; + +import static org.gcube.informationsystem.publisher.stubs.registry.RegistryConstants.*; + +import javax.jws.WebMethod; +import javax.jws.WebParam; +import javax.jws.WebResult; +import javax.jws.WebService; + +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; + +/** + * A local interface to the resource discovery service. + * + * + */ +@WebService(name=portType,targetNamespace=target_namespace) +public interface RegistryStub { + + /** + * + * @param profile the profile in xml + * @param type the type of the resource to store + * + * @throws InvalidResourceException if the profile is not valid + * @throws ResourceNotAcceptedException if some filter is applied registry side + * @throws CreateException if something goes wrong on creation + */ + @WebMethod(operationName="create") + @WebResult() + void create(@WebParam(name="profile") String profile, @WebParam(name="type") String type ) throws InvalidResourceException, + ResourceNotAcceptedException, CreateException; + /** + * + * @param id the id of the resource to update + * @param type the type of the resource to update + * @param profile the profile in xml + * + * @throws InvalidResourceException if the profile is not valid + * @throws ResourceNotAcceptedException if some filter is applied registry side + * @throws UpdateException if something goes wrong on update + */ + @WebMethod(operationName="update") + @WebResult() + void update(@WebParam(name="uniqueID") String id, @WebParam(name="type") String type, @WebParam(name="xmlProfile") String profile ) throws InvalidResourceException, + ResourceNotAcceptedException, UpdateException; + /** + * + * @param id the id of the resource to remove + * @param type the type of the resource to remove + * + * @throws ResourceDoesNotExistException if the resource is not stored on the Collector + * @throws RemoveException if something goes wrong during deletion + */ + @WebMethod(operationName="remove") + @WebResult() + void remove(@WebParam(name="uniqueID") String id, @WebParam(name="type") String type) throws ResourceDoesNotExistException, + RemoveException; + + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/CreateException.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/CreateException.java new file mode 100644 index 0000000..32d59da --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/CreateException.java @@ -0,0 +1,27 @@ +package org.gcube.informationsystem.publisher.stubs.registry.faults; + + +import javax.xml.ws.WebFault; + +import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; + +/** + * Thrown by {@link RegistryStub#create(String, String)} when something is failed on creation + */ +@WebFault(name = "CreateFault") +public class CreateException extends PublisherException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates an instance with a given message and an {@link AxisFaultInfo} payload + * @param message the message + * @param info the payload + */ + public CreateException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/InvalidResourceException.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/InvalidResourceException.java new file mode 100644 index 0000000..4a897ef --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/InvalidResourceException.java @@ -0,0 +1,32 @@ +package org.gcube.informationsystem.publisher.stubs.registry.faults; + +import javax.xml.ws.WebFault; + +import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; + +/** + * Thrown by {@link RegistryStub#create(String, String)} when the resource type is invalid + * service. + */ +@WebFault(name = "InvalidResourceFault") +public class InvalidResourceException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates an instance with a given message and an {@link AxisFaultInfo} payload + * @param message the message + * @param info the payload + */ + public InvalidResourceException(String message) { + super(message); + } + + public InvalidResourceException(Exception e1) { + super(e1); + } +} + diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/PublisherException.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/PublisherException.java new file mode 100644 index 0000000..be2681d --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/PublisherException.java @@ -0,0 +1,32 @@ +package org.gcube.informationsystem.publisher.stubs.registry.faults; + +public abstract class PublisherException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public PublisherException() { + super(); + // TODO Auto-generated constructor stub + } + + public PublisherException(String arg0, Throwable arg1) { + super(arg0, arg1); + // TODO Auto-generated constructor stub + } + + public PublisherException(String arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + public PublisherException(Throwable arg0) { + super(arg0); + // TODO Auto-generated constructor stub + } + + + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/RemoveException.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/RemoveException.java new file mode 100644 index 0000000..711f976 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/RemoveException.java @@ -0,0 +1,26 @@ +package org.gcube.informationsystem.publisher.stubs.registry.faults; + +import javax.xml.ws.WebFault; + +import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; + +/** + * Thrown by {@link RegistryStub#remove(String, String)} when something is failed on remove + */ +@WebFault(name = "RemoveFault") +public class RemoveException extends PublisherException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates an instance with a given message and an {@link AxisFaultInfo} payload + * @param message the message + * @param info the payload + */ + public RemoveException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/ResourceDoesNotExistException.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/ResourceDoesNotExistException.java new file mode 100644 index 0000000..939848f --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/ResourceDoesNotExistException.java @@ -0,0 +1,26 @@ +package org.gcube.informationsystem.publisher.stubs.registry.faults; + +import javax.xml.ws.WebFault; + +import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; + +/** + * Thrown by {@link RegistryStub#remove(String, String)} when the resource does not exist in the collector + */ +@WebFault(name = "ResourceDoesNotExistFault") +public class ResourceDoesNotExistException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates an instance with a given message and an {@link AxisFaultInfo} payload + * @param message the message + * @param info the payload + */ + public ResourceDoesNotExistException(String message) { + super(message); + } +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/ResourceNotAcceptedException.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/ResourceNotAcceptedException.java new file mode 100644 index 0000000..d9e449c --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/ResourceNotAcceptedException.java @@ -0,0 +1,28 @@ +package org.gcube.informationsystem.publisher.stubs.registry.faults; + + + +import javax.xml.ws.WebFault; + +import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; + +/** + * Thrown by {@link RegistryStub#create(String, String)} when the resource is not accepted cause it doesn't satisfy a requirement + */ +@WebFault(name = "ResourceNotAcceptedFault") +public class ResourceNotAcceptedException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates an instance with a given message and an {@link AxisFaultInfo} payload + * @param message the message + * @param info the payload + */ + public ResourceNotAcceptedException(String message) { + super(message); + } +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/UpdateException.java b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/UpdateException.java new file mode 100644 index 0000000..0f8b3c3 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/stubs/registry/faults/UpdateException.java @@ -0,0 +1,27 @@ +package org.gcube.informationsystem.publisher.stubs.registry.faults; + + +import javax.xml.ws.WebFault; + +import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; + +/** + * Thrown by {@link RegistryStub#update(String, String)} when something is failed on update + */ +@WebFault(name = "UpdateFault") +public class UpdateException extends PublisherException { + + /** + * + */ + private static final long serialVersionUID = 1L; + + /** + * Creates an instance with a given message and an {@link AxisFaultInfo} payload + * @param message the message + * @param info the payload + */ + public UpdateException(String message) { + super(message); + } +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/utils/RegistryStubs.java b/src/main/java/org/gcube/informationsystem/publisher/utils/RegistryStubs.java new file mode 100644 index 0000000..952a9b1 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/utils/RegistryStubs.java @@ -0,0 +1,72 @@ +package org.gcube.informationsystem.publisher.utils; + +import static org.gcube.common.clients.stubs.jaxws.StubFactory.stubFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; + +import java.net.URI; +import java.util.List; + +import org.gcube.common.resources.gcore.GCoreEndpoint; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.publisher.cache.RegistryCache; +import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; +import org.gcube.informationsystem.publisher.stubs.registry.RegistryConstants; +import org.gcube.informationsystem.publisher.stubs.registry.RegistryStub; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.api.ResultParser; +import org.gcube.resources.discovery.client.impl.DelegateClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.gcube.resources.discovery.icclient.ICClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RegistryStubs { + + private RegistryCache cache = new RegistryCache(10); + private List endpoints; + private static final Logger log = LoggerFactory.getLogger(RegistryStubs.class); + + + + public List getEndPoints(){ + String scope=ScopeProvider.instance.get(); +// able/disable cache + endpoints=(List)cache.get(scope); + if(endpoints==null){ + SimpleQuery query = queryFor(GCoreEndpoint.class); + ResultParser uriParser =new ResultParser() { + + @Override + public URI parse(String result) throws Exception { + return new URI(result.replaceAll("\n", "")); + } + + }; + DiscoveryClient client = new DelegateClient(uriParser, new ICClient()); + query.addCondition("$resource/Profile/ServiceClass/text() eq '"+RegistryConstants.service_class+"'") + .addCondition("$resource/Profile/ServiceName/text() eq '"+RegistryConstants.service_name+"'") + .setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq '"+RegistryConstants.service_entrypoint+"']/string()"); + endpoints = client.submit(query); + if (endpoints.size()==0){ + throw new IllegalArgumentException("No registry endpoint founded"); + } +// able/disable cache + cache.put(scope, endpoints); + } + return endpoints; + } + + public RegistryStub getStubs() throws RegistryNotFoundException{ + URI endpoint=null; + //use another method to cache epr + endpoint = getEndPoints().get(0); + log.debug("get stubs from endpoint: "+ endpoint); + return stubFor(RegistryConstants.registry).at(endpoint); + } + + public RegistryStub getStubs(URI endpoint) throws RegistryNotFoundException{ + log.debug("get stubs from endpoint: "+ endpoint); + return stubFor(RegistryConstants.registry).at(endpoint); + } + +} diff --git a/src/main/java/org/gcube/informationsystem/publisher/utils/ValidationUtils.java b/src/main/java/org/gcube/informationsystem/publisher/utils/ValidationUtils.java new file mode 100644 index 0000000..c079ba2 --- /dev/null +++ b/src/main/java/org/gcube/informationsystem/publisher/utils/ValidationUtils.java @@ -0,0 +1,141 @@ +package org.gcube.informationsystem.publisher.utils; + +import java.util.Iterator; + +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.ResourceMediator; +import org.gcube.common.resources.gcore.ScopeGroup; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.common.scope.impl.ScopeBean.Type; +import org.gcube.informationsystem.publisher.RegistryPublisher; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class ValidationUtils { + + private static final Logger log = LoggerFactory.getLogger(ValidationUtils.class); + + public static void valid(String name, Object object){ + if (object==null) + throw new IllegalArgumentException(name+" is null"); + } + + public static < R extends Resource > boolean isPresent(R resource, String currentScope){ + ScopeGroup scopes=resource.scopes(); + boolean founded= false; + for(Iterator it=scopes.iterator(); it.hasNext();){ + String scope=it.next(); + if(scope.equals(currentScope)) + founded=true; + } + if(founded) + throw new IllegalArgumentException(" scope "+currentScope+" is already present in resource"); + return false; + } + + + /** + * If scope is a VRE scope and the VO and INFRA scopes are not present in the resource, this method add these scopes to the resource + * @param resource the resource + * @param scope a scope + */ + public static void addEnclosingScopesOnResource(T resource, String scope){ + if(new ScopeBean(scope).is(Type.VRE)){ + String voScope=new ScopeBean(scope).enclosingScope().toString(); + String infraScope=new ScopeBean(voScope).enclosingScope().toString(); +// The scope collection is a set, I can add scope without checking + log.debug("adding "+voScope+" to the resource "+resource.id()); + ResourceMediator.setScope(resource, voScope); + log.debug("adding "+infraScope+" to the resource "+resource.id()); + ResourceMediator.setScope(resource, infraScope); + }else if(new ScopeBean(scope).is(Type.VO)){ + String infraScope=new ScopeBean(scope).enclosingScope().toString(); + log.debug("adding "+infraScope+" to the resource "+resource.id()); +// The scope collection is a set, I can add scope without checking + ResourceMediator.setScope(resource, infraScope); + } + } + + public static boolean isCompatibleScopeForRemove(T resource, String scope){ + log.info("scope: "+scope+" check if update is needed inr resource: "+resource.id()); + if(resource.scopes().size() == 0) + return true; + if(new ScopeBean(scope).is(Type.VRE)){ + log.debug(" "+scope+" is a VRE scope"); + if(anotherBrotherVREOrVOOnResource(resource, scope)){ + log.debug("found another VRE or VO scope on the resource: "); + return false; + }else return true; + }else if(new ScopeBean(scope).is(Type.VO)){ + log.debug(" "+scope+" is a VO scope"); + if(anotherSonVREOnResource(resource, 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{ // is a INFRA scope + if(anotherInfraScopeOnResource(resource, 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; + } + } + + public static boolean anotherBrotherVREOrVOOnResource(T resource, String scope){ + if(!new ScopeBean(scope).is(Type.VRE)) + throw new IllegalArgumentException("anotherBrotherVREOrVOOnResource method: the input scope must be a VRE scope"); + String enclosedScope=new ScopeBean(scope).enclosingScope().toString(); + log.debug("VO scope "+enclosedScope); + for(String s : resource.scopes()){ + log.debug(" check scope "+s); + if(isChildScope(enclosedScope, s)){ + log.debug("the scope "+s+" is another VRE scope defined in the resource. Not Remove needed "); + return true; + }else if((enclosedScope != null) && (enclosedScope.toString().equals(s))){ + log.debug("the scope "+s+" is the father VO scope defined in the resource. Not Remove needed "); + return true; + } + } + log.debug("other brother VRE scope or VO scope not found on the resource "); + return false; + } + + public static boolean anotherSonVREOnResource(T resource, String scope){ + if(!new ScopeBean(scope).is(Type.VO)) + throw new IllegalArgumentException("anotherSonVREOnResource method: the input scope must be a VO scope"); + for(String s : resource.scopes()){ + if(isChildScope(scope, s)){ + log.debug("the scope "+s+" is another VO scope defined in the resource "); + return true; + } + } + return false; + } + + public static boolean isChildScope(String fatherScope, String sonScope) { + ScopeBean currentEnclosedScope=new ScopeBean(sonScope).enclosingScope(); + if((currentEnclosedScope != null) && (currentEnclosedScope.toString().equals(fatherScope))){ + log.debug("check scope"+fatherScope+": found another son VRE scope "+sonScope); + return true; + }else return false; + } + + public static boolean anotherInfraScopeOnResource(T resource, String scope){ + if(!new ScopeBean(scope).is(Type.INFRASTRUCTURE)) + throw new IllegalArgumentException("anotherInfraScopeOnResource method: the input scope must be a INFRASTRUCTURE scope"); + String infraScopeFound=null; + for(String s : resource.scopes()){ + while(new ScopeBean(s).enclosingScope() != null){ + s=new ScopeBean(s).enclosingScope().toString(); + + } + infraScopeFound=s; + if(infraScopeFound.equals(scope)){ + log.debug("check scope"+scope+": found another scope on infra "+s); + return true; + } + } + return false; + } + + + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/BodyWithNSTests.java b/src/test/java/org/gcube/informationsystem/publisher/BodyWithNSTests.java new file mode 100644 index 0000000..79ff35b --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/BodyWithNSTests.java @@ -0,0 +1,41 @@ +package org.gcube.informationsystem.publisher; + +import static org.junit.Assert.*; + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.Date; + +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.scope.api.ScopeProvider; +import org.junit.Test; + +public class BodyWithNSTests { + +// @Test + public void buildMassiAndvalentinaGeneric() throws Exception { + + GenericResource generic = new GenericResource(); + generic.newProfile().name("test Nov 6 Rob").type("test").description("this is a test " + new Date()); + + String text = "nn va"; + + generic.profile().newBody(text); + + StringWriter writer = new StringWriter(); + Resources.marshal(generic,writer); + + GenericResource parsed = Resources.unmarshal(GenericResource.class,new StringReader(writer.toString())); + + Resources.print(parsed); + + Resources.validate(parsed); + ScopeProvider.instance.set("/gcube/devsec"); + RegistryPublisher rp=RegistryPublisherFactory.create(); + rp.create(generic); + + } + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/ConfigurationTest.java b/src/test/java/org/gcube/informationsystem/publisher/ConfigurationTest.java new file mode 100644 index 0000000..3fc8ae9 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/ConfigurationTest.java @@ -0,0 +1,68 @@ +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 impls=load(); + assertEquals(impls.size(), 1); + } + + private List load(){ + ServiceLoader loader = ServiceLoader.load(IValidatorContext.class); + Iterator iterator = loader.iterator(); + List impls = new ArrayList(); + 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 jarUrls = new ArrayList(); + 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); + } +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/DefaultConfigurationTest.java b/src/test/java/org/gcube/informationsystem/publisher/DefaultConfigurationTest.java new file mode 100644 index 0000000..ac3a6c4 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/DefaultConfigurationTest.java @@ -0,0 +1,22 @@ +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 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"); + } + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/DefaultScopeValidatorTest.java b/src/test/java/org/gcube/informationsystem/publisher/DefaultScopeValidatorTest.java new file mode 100644 index 0000000..aea19f2 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/DefaultScopeValidatorTest.java @@ -0,0 +1,46 @@ +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 list= context.getValidators(); + for(Validator validator : list){ + System.out.println("validator founded: "+validator.type()); + } + } + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/GCoreEndpointPublisherTests.java b/src/test/java/org/gcube/informationsystem/publisher/GCoreEndpointPublisherTests.java new file mode 100644 index 0000000..b92479e --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/GCoreEndpointPublisherTests.java @@ -0,0 +1,66 @@ +package org.gcube.informationsystem.publisher; + +import static org.gcube.common.resources.gcore.Resources.print; +import static org.junit.Assert.*; +import org.gcube.common.resources.gcore.GCoreEndpoint; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.scope.api.ScopeProvider; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class GCoreEndpointPublisherTests { + + private static final Logger log = LoggerFactory.getLogger(RegistryPublisherTests.class); + static GCoreEndpoint running; + static RegistryPublisher rp; + static Resource r; + + @BeforeClass + public static void init(){ +// ScopeProvider.instance.set("/d4science.research-infrastructures.eu/EUBrazilOpenBio"); + ScopeProvider.instance.set("/gcube/devsec"); + running = Resources.unmarshal(GCoreEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("gCoreEndpoint.xml")); + rp=RegistryPublisherFactory.create(); + } + + @Test + public void printTest(){ + print(running); + //resource-specific tests + assertEquals(Type.GCOREENDPOINT,running.type()); + } + + @Test + public void registerCreate(){ + r=rp.create(running); + System.out.println("new resource created: "); + if(r!=null) + print(r); + assertEquals(running,r); + } + + + @AfterClass + public static void forceDeleteResource(){ + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String currentScope=ScopeProvider.instance.get(); + log.info("force remove resource "+r.id()+" to scope "+currentScope); + AdvancedPublisher advancedPublisher=new AdvancedPublisher(rp); + advancedPublisher.forceRemove(r); + ScopeProvider.instance.set(currentScope); + + + } + +} + diff --git a/src/test/java/org/gcube/informationsystem/publisher/PublisherTest.java b/src/test/java/org/gcube/informationsystem/publisher/PublisherTest.java new file mode 100644 index 0000000..8686ad0 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/PublisherTest.java @@ -0,0 +1,30 @@ +package org.gcube.informationsystem.publisher; + +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.scope.api.ScopeProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class PublisherTest { + + static Logger log = LoggerFactory.getLogger(PublisherTest.class); + + /** + * @param args + * @throws Exception + */ + public static void main(String[] args) throws Exception { +// ScopeProvider.instance.set("/gcube/devsec/devVre"); +// log.trace("starting client"); +// RegistryPublisher registryPublisher = RegistryPublisherFactory.create(); +// AdvancedPublisher publisher=new AdvancedPublisher(registryPublisher); +// publisher.removeFromAllScopes("testError", Type.GENERIC); + } + + + public static T unmarshal(Class clazz, String sample) throws Exception { + return Resources.unmarshal(clazz,PublisherTest.class.getClassLoader().getResourceAsStream(sample)); + } + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/RegistryPublisherTests.java b/src/test/java/org/gcube/informationsystem/publisher/RegistryPublisherTests.java new file mode 100644 index 0000000..dbd10b7 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/RegistryPublisherTests.java @@ -0,0 +1,114 @@ +package org.gcube.informationsystem.publisher; + +import static org.gcube.common.resources.gcore.Resources.print; +import static org.junit.Assert.*; +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RegistryPublisherTests { + + private static final Logger log = LoggerFactory.getLogger(RegistryPublisherTests.class); + static GenericResource generic; +// static GCoreEndpoint running; +// static ServiceEndpoint runtime; +// static Software service; + static RegistryPublisher rp; + static Resource r; + + @BeforeClass + public static void init(){ + ScopeProvider.instance.set("/gcube/devNext"); +// ScopeProvider.instance.set("/gcube/devsec"); + generic = Resources.unmarshal(GenericResource.class, PublisherTest.class.getClassLoader().getResourceAsStream("generic.xml")); +// runtime = Resources.unmarshal(ServiceEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("broker.xml")); +// service = Resources.unmarshal(Software.class, PublisherTest.class.getClassLoader().getResourceAsStream("service.xml")); +// running = Resources.unmarshal(GCoreEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("gCoreEndpoint.xml")); + rp=RegistryPublisherFactory.create(); + } + + @Test + public void printTest(){ + //print it + print(generic); +// print(runtime); +// print(service); +// print(running); + //resource-specific tests + assertEquals(Type.GENERIC,generic.type()); +// assertEquals(Type.ENDPOINT,runtime.type()); +// assertEquals(Type.SOFTWARE ,service.type()); +// assertEquals(Type.GCOREENDPOINT,running.type()); + } + + @Test + public void registerCreate(){ + r=rp.create(generic); +// r=rp.create(runtime); +// r=rp.create(service); +// r=rp.create(running); + System.out.println("new resource created: "); + if(r!=null) + print(r); +// try { +// Thread.sleep(15000); +// } catch (InterruptedException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// String currentScope=ScopeProvider.instance.get(); +// ScopeGroup scopes=r.scopes(); +// for(Iterator it=scopes.iterator(); it.hasNext();){ +// String scope=it.next(); +// log.info("set scope "+scope); +// ScopeProvider.instance.set(scope); +// SimpleQuery query = queryFor(GenericResource.class); +// query.addCondition("$resource/Profile/SecondaryType/text() eq 'PublisherBotoxTest' and $resource/Profile/Name eq 'TestNewPublisher' "); +// DiscoveryClient client = clientFor(GenericResource.class); +// List resources = client.submit(query); +// if(resources.size() > 0){ +// System.out.println("resource found in scope "+scope); +// GenericResource resource=resources.get(0); +// log.info("r founded "+resource.id()+" "+resource.toString()); +// log.info("original resource: "+r.id()+" "+r.toString()); +// assertEquals(resource.scopes(), r.scopes()); +// log.info("assert ok in scope "+scope); +// } +// } +// ScopeProvider.instance.set(currentScope); + + } + + + @Test + public void removeResource(){ + rp.remove(generic); + } + + @AfterClass + public static void forceDeleteResource(){ + String currentScope=ScopeProvider.instance.get(); + log.info("force remove resource "+r.id()+" to scope "+currentScope); + AdvancedPublisher advancedPublisher=new AdvancedPublisher(rp); + advancedPublisher.forceRemove(r); + String enclosedScope=new ScopeBean(currentScope).enclosingScope().toString(); + while( enclosedScope != null){ + ScopeProvider.instance.set(enclosedScope); + advancedPublisher.forceRemove(r); + if(new ScopeBean(enclosedScope).enclosingScope() != null) + enclosedScope=new ScopeBean(enclosedScope).enclosingScope().toString(); + } + ScopeProvider.instance.set(currentScope); + + + } + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/RegistryRemoveTests.java b/src/test/java/org/gcube/informationsystem/publisher/RegistryRemoveTests.java new file mode 100644 index 0000000..a676d17 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/RegistryRemoveTests.java @@ -0,0 +1,108 @@ +package org.gcube.informationsystem.publisher; + +import static org.gcube.common.resources.gcore.Resources.print; +import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; +import static org.junit.Assert.assertEquals; + +import java.util.Iterator; +import java.util.List; + +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.resources.gcore.ScopeGroup; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RegistryRemoveTests { + + static GenericResource generic; + static RegistryPublisher rp; + static Resource r; + private static final Logger log = LoggerFactory.getLogger(RegistryUpdateTests.class); + + @BeforeClass + public static void init(){ + ScopeProvider.instance.set("/gcube/devNext"); + generic = Resources.unmarshal(GenericResource.class, PublisherTest.class.getClassLoader().getResourceAsStream("generic.xml")); + rp=RegistryPublisherFactory.create(); + } + + @Test + public void printTest(){ + //print it + print(generic); + //resource-specific tests + assertEquals(Type.GENERIC,generic.type()); + r=rp.create(generic); + try { + Thread.sleep(15000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + @Test + public void removeFromCurrentScope(){ + r=rp.remove(generic); + try { + Thread.sleep(15000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String currentScope=ScopeProvider.instance.get(); + ScopeGroup scopes=r.scopes(); + for(Iterator it=scopes.iterator(); it.hasNext();){ + String scope=it.next(); + log.info("set scope "+scope); + ScopeProvider.instance.set(scope); + SimpleQuery query = queryFor(GenericResource.class); + query.addCondition("$resource/Profile/SecondaryType/text() eq 'PublisherBotoxTest' and $resource/Profile/Name eq 'TestNewPublisher5' "); + DiscoveryClient client = clientFor(GenericResource.class); + List resources = client.submit(query); + if(resources.size() > 0){ + System.out.println("resource found in scope "+scope+ " size "+resources.size()); + GenericResource resource=resources.get(0); + log.info("r founded "+resource.id()+" "+resource.toString()); + log.info("original resource: "+r.id()+" "+r.toString()); + assertEquals(resource.scopes(), r.scopes()); + log.info("assert ok in scope "+scope); + } + } + ScopeProvider.instance.set(currentScope); + } + + @AfterClass + public static void removeResource(){ + String currentScope=ScopeProvider.instance.get(); + log.info("force remove resource "+r.id()+" to scope "+currentScope); + AdvancedPublisher advancedPublisher=new AdvancedPublisher(rp); + advancedPublisher.forceRemove(r); + ScopeBean scopeBean=new ScopeBean(currentScope).enclosingScope(); + if(scopeBean!=null){ + String enclosedScope=scopeBean.toString(); + while( enclosedScope != null){ + ScopeProvider.instance.set(enclosedScope); + advancedPublisher.forceRemove(r); + scopeBean=new ScopeBean(enclosedScope).enclosingScope(); + if(scopeBean!=null){ + enclosedScope=scopeBean.toString(); + }else enclosedScope=null; + } + } + ScopeProvider.instance.set(currentScope); + + + } +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/RegistryUpdateTests.java b/src/test/java/org/gcube/informationsystem/publisher/RegistryUpdateTests.java new file mode 100644 index 0000000..101a703 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/RegistryUpdateTests.java @@ -0,0 +1,115 @@ +package org.gcube.informationsystem.publisher; + +import static org.gcube.common.resources.gcore.Resources.print; +import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; +import static org.junit.Assert.*; + +import java.util.Iterator; +import java.util.List; +import java.util.UUID; + +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.ResourceMediator; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.resources.gcore.ScopeGroup; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.scope.impl.ScopeBean; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RegistryUpdateTests { + + static GenericResource generic; + static RegistryPublisher rp; + static GenericResource r; + private static final Logger log = LoggerFactory.getLogger(RegistryUpdateTests.class); + + @BeforeClass + public static void init(){ + ScopeProvider.instance.set("/gcube/devsec/devVRE"); + generic = Resources.unmarshal(GenericResource.class, PublisherTest.class.getClassLoader().getResourceAsStream("generic.xml")); + rp=RegistryPublisherFactory.create(); + } + + @Test + public void printTest(){ + //print it + print(generic); + //resource-specific tests + assertEquals(Type.GENERIC,generic.type()); + } + + @Test + public void registerUpdate(){ + rp.create(generic); + try { + Thread.sleep(15000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("old description "+generic.profile().description()); + String newDescription="testUpdateDescription"; + generic.profile().description(newDescription); + System.out.println("new description "+generic.profile().description()); + r=rp.update(generic); + try { + Thread.sleep(15000); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + String currentScope=ScopeProvider.instance.get(); + ScopeGroup scopes=r.scopes(); + for(Iterator it=scopes.iterator(); it.hasNext();){ + String scope=it.next(); + log.info("set scope "+scope); + ScopeProvider.instance.set(scope); + SimpleQuery query = queryFor(GenericResource.class); + query.addCondition("$resource/Profile/SecondaryType/text() eq 'PublisherBotoxTest' and $resource/Profile/Name eq 'TestNewPublisher' "); + DiscoveryClient client = clientFor(GenericResource.class); + List resources = client.submit(query); + if(resources.size() > 0){ + System.out.println("resource found in scope "+scope+ " size "+resources.size()); + GenericResource resource=resources.get(0); + log.info("r founded "+resource.id()+" "+resource.toString()); + log.info("original resource: "+r.id()+" "+r.toString()); + assertEquals(resource.scopes(), r.scopes()); + assertEquals(resource.profile().description(), r.profile().description()); + log.info("assert ok in scope "+scope); + } + } + ScopeProvider.instance.set(currentScope); + } + + @Test + public void removeResource(){ + String currentScope=ScopeProvider.instance.get(); + log.info("force remove resource "+r.id()+" to scope "+currentScope); + AdvancedPublisher advancedPublisher=new AdvancedPublisher(rp); + advancedPublisher.forceRemove(r); + ScopeBean scopeBean=new ScopeBean(currentScope).enclosingScope(); + if(scopeBean!=null){ + String enclosedScope=scopeBean.toString(); + while( enclosedScope != null){ + ScopeProvider.instance.set(enclosedScope); + advancedPublisher.forceRemove(r); + scopeBean=new ScopeBean(enclosedScope).enclosingScope(); + if(scopeBean!=null){ + enclosedScope=scopeBean.toString(); + }else enclosedScope=null; + } + } + ScopeProvider.instance.set(currentScope); + + } + + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/RemoveByIdTests.java b/src/test/java/org/gcube/informationsystem/publisher/RemoveByIdTests.java new file mode 100644 index 0000000..80e4210 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/RemoveByIdTests.java @@ -0,0 +1,53 @@ +package org.gcube.informationsystem.publisher; + + +import java.net.URI; +import java.net.URISyntaxException; +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.publisher.AdvancedPublisher; +import org.gcube.informationsystem.publisher.RegistryPublisher; +import org.gcube.informationsystem.publisher.RegistryPublisherFactory; +import org.junit.BeforeClass; +import org.junit.Test; + + +public class RemoveByIdTests { + + static GenericResource generic; + static AdvancedPublisher arp; + static RegistryPublisher rp; + static Resource r; + private static String scope="/gcube/devNext"; + private String id="c66bb9b0-e571-11e2-9f13-fcb948ca7a75";//aedc90ed-6df2-437c-ac0f-ffecbafda893 + private Type type=Type.ENDPOINT; + private String endpointString="http://node20.d.d4science.research-infrastructures.eu:8080/wsrf/services/gcube/informationsystem/registry/ResourceRegistration"; + + @BeforeClass + public static void init(){ + ScopeProvider.instance.set(scope); + rp=RegistryPublisherFactory.create(); + arp=new AdvancedPublisher(rp); + } + + + @Test + public void removeFromCurrentScope(){ + arp.removeById(id, type); + } + +// @Test + public void removeFromCurrentScopeWithEndpoint(){ + URI endpoint=null; + try { + endpoint=new URI(endpointString); + } catch (URISyntaxException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + arp.removeById(id, type, endpoint); + } + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/ScopeValidatorTest.java b/src/test/java/org/gcube/informationsystem/publisher/ScopeValidatorTest.java new file mode 100644 index 0000000..083d40b --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/ScopeValidatorTest.java @@ -0,0 +1,64 @@ +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 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); +// +// } +// +// } + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/ScopedPublisherTests.java b/src/test/java/org/gcube/informationsystem/publisher/ScopedPublisherTests.java new file mode 100644 index 0000000..143d0e4 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/ScopedPublisherTests.java @@ -0,0 +1,98 @@ +package org.gcube.informationsystem.publisher; + +import static org.gcube.common.resources.gcore.Resources.print; +import static org.gcube.resources.discovery.icclient.ICFactory.clientFor; +import static org.gcube.resources.discovery.icclient.ICFactory.queryFor; +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.gcube.common.resources.gcore.GenericResource; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.resources.gcore.ScopeGroup; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.informationsystem.publisher.exception.RegistryNotFoundException; +import org.gcube.resources.discovery.client.api.DiscoveryClient; +import org.gcube.resources.discovery.client.queries.api.SimpleQuery; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ScopedPublisherTests { + + static GenericResource generic; + static ScopedPublisher sp; + static List scopes; + private static final Logger log = LoggerFactory.getLogger(RegistryPublisherTests.class); + static Resource r; + + @BeforeClass + public static void init(){ +// ScopeProvider.instance.set("/gcube/devsec"); + generic = Resources.unmarshal(GenericResource.class, PublisherTest.class.getClassLoader().getResourceAsStream("generic.xml")); + sp=RegistryPublisherFactory.scopedPublisher(); + scopes=new ArrayList(); + scopes.add("/gcube/devNext"); + scopes.add("/gcube/devsec/devVRE"); + } + + + @Test + public void printTest(){ + //print it + print(generic); + //resource-specific tests + assertEquals(Type.GENERIC,generic.type()); + + } + + @Test + public void scopedPublisherCreate(){ + try { + r=sp.create(generic, scopes); + } catch (RegistryNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + System.out.println("new resource created: "); + String currentScope=ScopeProvider.instance.get(); + ScopeGroup scopes=r.scopes(); + for(Iterator it=scopes.iterator(); it.hasNext();){ + String scope=it.next(); + if(currentScope==null){ + currentScope=scope; + } + log.info("set scope "+scope); + ScopeProvider.instance.set(scope); + SimpleQuery query = queryFor(GenericResource.class); + query.addCondition("$resource/Profile/SecondaryType/text() eq 'PublisherBotoxTest' and $resource/Profile/Name eq 'TestNewPublisher' "); + DiscoveryClient client = clientFor(GenericResource.class); + List resources = client.submit(query); + if(resources.size() > 0){ + System.out.println("resource found in scope "+scope+" resource found "+resources.size()); + GenericResource resource=resources.get(0); + log.info("r founded "+resource.id()+" "+resource.toString()); + log.info("original resource: "+r.id()+" "+r.toString()); + assertEquals(resource, r); + log.info("assert ok in scope "+scope); + } + } + ScopeProvider.instance.set(currentScope); + } + + + @Test + public void removeResource(){ + log.info("remove resource "+r.id()+" from all scopes "); + AdvancedScopedPublisher advancedPublisher=new AdvancedScopedPublisher(sp); + advancedPublisher.forceRemove(r); + + } + + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/ServiceEndpointPublisherTests.java b/src/test/java/org/gcube/informationsystem/publisher/ServiceEndpointPublisherTests.java new file mode 100644 index 0000000..30f192f --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/ServiceEndpointPublisherTests.java @@ -0,0 +1,59 @@ +package org.gcube.informationsystem.publisher; + +import static org.gcube.common.resources.gcore.Resources.print; +import static org.junit.Assert.*; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.ServiceEndpoint; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.scope.api.ScopeProvider; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class ServiceEndpointPublisherTests { + + private static final Logger log = LoggerFactory.getLogger(RegistryPublisherTests.class); + static ServiceEndpoint runtime; + static RegistryPublisher rp; + static Resource r; + + @BeforeClass + public static void init(){ +// ScopeProvider.instance.set("/d4science.research-infrastructures.eu/EUBrazilOpenBio"); + ScopeProvider.instance.set("/gcube/devsec"); + runtime = Resources.unmarshal(ServiceEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("broker.xml")); + rp=RegistryPublisherFactory.create(); + } + + @Test + public void printTest(){ + print(runtime); + //resource-specific tests + assertEquals(Type.ENDPOINT,runtime.type()); + } + + @Test + public void registerCreate(){ + r=rp.create(runtime); + System.out.println("new resource created: "); + if(r!=null) + print(r); + assertEquals(runtime,r); + } + + + @AfterClass + public static void forceDeleteResource(){ + String currentScope=ScopeProvider.instance.get(); + log.info("force remove resource "+r.id()+" to scope "+currentScope); + AdvancedPublisher advancedPublisher=new AdvancedPublisher(rp); + advancedPublisher.forceRemove(r); + ScopeProvider.instance.set(currentScope); + + + } + +} diff --git a/src/test/java/org/gcube/informationsystem/publisher/SoftwarePublisherTests.java b/src/test/java/org/gcube/informationsystem/publisher/SoftwarePublisherTests.java new file mode 100644 index 0000000..fb40e1e --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/publisher/SoftwarePublisherTests.java @@ -0,0 +1,59 @@ +package org.gcube.informationsystem.publisher; + +import static org.gcube.common.resources.gcore.Resources.print; +import static org.junit.Assert.*; +import org.gcube.common.resources.gcore.Resource; +import org.gcube.common.resources.gcore.Software; +import org.gcube.common.resources.gcore.Resource.Type; +import org.gcube.common.resources.gcore.Resources; +import org.gcube.common.scope.api.ScopeProvider; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SoftwarePublisherTests { + + private static final Logger log = LoggerFactory.getLogger(RegistryPublisherTests.class); + static Software service; + static RegistryPublisher rp; + static Resource r; + + @BeforeClass + public static void init(){ +// ScopeProvider.instance.set("/d4science.research-infrastructures.eu/EUBrazilOpenBio"); + ScopeProvider.instance.set("/gcube/devsec"); + service = Resources.unmarshal(Software.class, PublisherTest.class.getClassLoader().getResourceAsStream("service.xml")); + rp=RegistryPublisherFactory.create(); + } + + @Test + public void printTest(){ + print(service); + //resource-specific tests + assertEquals(Type.SOFTWARE ,service.type()); + } + + @Test + public void registerCreate(){ + r=rp.create(service); + System.out.println("new resource created: "); + if(r!=null) + print(r); + assertEquals(service,r); + } + + @AfterClass + public static void forceDeleteResource(){ + String currentScope=ScopeProvider.instance.get(); + log.info("force remove resource "+r.id()+" to scope "+currentScope); + AdvancedPublisher advancedPublisher=new AdvancedPublisher(rp); + advancedPublisher.forceRemove(r); + ScopeProvider.instance.set(currentScope); + + + } + +} + diff --git a/src/test/java/org/gcube/informationsystem/scope/validator/MyGenericResourceValidator.java b/src/test/java/org/gcube/informationsystem/scope/validator/MyGenericResourceValidator.java new file mode 100644 index 0000000..0b06776 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/scope/validator/MyGenericResourceValidator.java @@ -0,0 +1,33 @@ +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 implements Validator { + + private static Logger log = LoggerFactory.getLogger(MyGenericResourceValidator.class); + + @Override + public void validate(R resource) { + log.info("validate method of "+this.getClass()); + } + + @Override + public Class type() { + return GenericResource.class; + } + + @Override + public void checkScopeCompatibility(R resource, + List scopes) { + // TODO Auto-generated method stub + + } + + +} diff --git a/src/test/java/org/gcube/informationsystem/scope/validator/MyServiceEndpointValidator.java b/src/test/java/org/gcube/informationsystem/scope/validator/MyServiceEndpointValidator.java new file mode 100644 index 0000000..e327e73 --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/scope/validator/MyServiceEndpointValidator.java @@ -0,0 +1,35 @@ +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 implements Validator{ + + private static Logger log = LoggerFactory.getLogger(MyServiceEndpointValidator.class); + + @Override + public void validate(R resource) { + log.info("validate method of "+this.getClass()); + + } + + @Override + public Class type() { + return ServiceEndpoint.class; + } + + @Override + public void checkScopeCompatibility(R resource, + List scopes) { + // TODO Auto-generated method stub + + } + + + +} diff --git a/src/test/java/org/gcube/informationsystem/scope/validator/ValidatorContextImpl.java b/src/test/java/org/gcube/informationsystem/scope/validator/ValidatorContextImpl.java new file mode 100644 index 0000000..fb5f5bd --- /dev/null +++ b/src/test/java/org/gcube/informationsystem/scope/validator/ValidatorContextImpl.java @@ -0,0 +1,18 @@ +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 validators = Arrays.asList(new MyGenericResourceValidator(), new MyServiceEndpointValidator()); + + @Override + public List getValidators() { + return validators; + } + +} diff --git a/src/test/resources/ObisRR.xml b/src/test/resources/ObisRR.xml new file mode 100644 index 0000000..6d592b7 --- /dev/null +++ b/src/test/resources/ObisRR.xml @@ -0,0 +1,49 @@ + + e6705ad0-fa8a-11e2-92fd-b6f8c481951b + RuntimeResource + + /d4science.research-infrastructures.eu + /d4science.research-infrastructures.eu/gCubeApps + + + Database + Obis2Repository + Obis2Repository + + postgres + 8 + 4 + 0 + 0 + + + obis2.i-marine.research-infrastructures.eu + + READY + + + jdbc connection url + + jdbc:postgresql://obis2.i-marine.research-infrastructures.eu:5432/obis + + + postgres + Db/lnp5cAPwrAfjqorqctA== + + + + dialect + org.hibernate.dialect.PostgreSQLDialect + + + dbname + obis + + + driver + org.postgresql.Driver + + + + + \ No newline at end of file diff --git a/src/test/resources/StatisticalRR.xml b/src/test/resources/StatisticalRR.xml new file mode 100644 index 0000000..5b592d3 --- /dev/null +++ b/src/test/resources/StatisticalRR.xml @@ -0,0 +1,44 @@ + + + RuntimeResource + + /d4science.research-infrastructures.eu + + + Database + StatisticalManagerDataBase + DB for Statistical Manager Service + + postgres + 8 + 4 + 0 + 0 + + + db1.p.d4science.research-infrastructures.eu + + READY + + + jdbc conection url + + jdbc:postgresql://db1.p.d4science.research-infrastructures.eu/testdb + + + utente + UwNMZOK7FlIjGPR+NZCV6w== + + + + Hibernate connection url + + jdbc:postgresql://db1.p.d4science.research-infrastructures.eu/dataSpace + + + utente + UwNMZOK7FlIjGPR+NZCV6w== + + + + \ No newline at end of file diff --git a/src/test/resources/broker.xml b/src/test/resources/broker.xml new file mode 100644 index 0000000..38fe8fd --- /dev/null +++ b/src/test/resources/broker.xml @@ -0,0 +1,34 @@ + + + + RuntimeResource + + + + Service + MessageBrokerTestPublisher + + + ActiveMQ + 5 + 6 + 0 + 0 + + + message-broker.d4science.research-infrastructures.eu + + READY + + + openwire interface + + tcp://message-broker.d4science.research-infrastructures.eu:6166 + + + + 6vW1u92cpdgHzYAgIurn9w== + + + + \ No newline at end of file diff --git a/src/test/resources/cotrixbug.xml b/src/test/resources/cotrixbug.xml new file mode 100644 index 0000000..613ced2 --- /dev/null +++ b/src/test/resources/cotrixbug.xml @@ -0,0 +1,55 @@ + + + dec27470-447e-11e2-a749-e3b17e68146a + + GenericResource + + + + /gcube + + + + + + ApplicationProfile + + Cotrix + + Cotrix application + + + + org.cotrix.web + + http://ftp.d4science.org/apps/profiles/cotrix.png + + + + /gcube/devsec/devVRE + + /group/devvre/cotrix + + + + + + /gcube/devsec + + /group/devsec/cotrix + + + + + + /gcube/devsec/devNext + + /group/devnext/cotrix + + + + + + + + diff --git a/src/test/resources/customValidator.jar b/src/test/resources/customValidator.jar new file mode 100644 index 0000000..edb7589 Binary files /dev/null and b/src/test/resources/customValidator.jar differ diff --git a/src/test/resources/devsec.servicemap b/src/test/resources/devsec.servicemap new file mode 100644 index 0000000..0bc5d13 --- /dev/null +++ b/src/test/resources/devsec.servicemap @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/src/test/resources/endpoint.xml b/src/test/resources/endpoint.xml new file mode 100644 index 0000000..ad2b04f --- /dev/null +++ b/src/test/resources/endpoint.xml @@ -0,0 +1,42 @@ + + 03489ee0-240a-11e2-b212-c52eb951fce1 + RuntimeResource + + + + + Test + TestRR + RR TEST + + apache + 2 + 0 + 0 + 0 + + + svn.research-infrastructures.eu/public/d4science/gcube/trunk + + + + + + URL + + http://svn.research-infrastructures.eu/public/d4science/gcube/trunk + + + + + 6vW1u92cpdgHzYAgIurn9w== + + + + folder + ./ + + + + + \ No newline at end of file diff --git a/src/test/resources/gCoreEndpoint.xml b/src/test/resources/gCoreEndpoint.xml new file mode 100644 index 0000000..ca88ff4 --- /dev/null +++ b/src/test/resources/gCoreEndpoint.xml @@ -0,0 +1,24 @@ + + +5d244ab0-9d79-11e3-af18-dd5904b11dd6 + RunningInstance + + + + Test + 3.1.0 + + + ResultSetService + Search + + + ready + + + + http://nodetest.isti.cnr.it:8080/wsrf/services/gcube/common/test/test + + + + \ No newline at end of file diff --git a/src/test/resources/generic.xml b/src/test/resources/generic.xml new file mode 100644 index 0000000..bc48efc --- /dev/null +++ b/src/test/resources/generic.xml @@ -0,0 +1,22 @@ + + + 321e10bb-a906-4d82-89ba-197ccdd75d3f + + + + + + GenericResource + + PublisherBotoxTest + Test + Test + + + 2014-09-05T14:33:33.116+02:00 + true + + test + + + \ No newline at end of file diff --git a/src/test/resources/generic2.xml b/src/test/resources/generic2.xml new file mode 100644 index 0000000..842f0e4 --- /dev/null +++ b/src/test/resources/generic2.xml @@ -0,0 +1,21 @@ + + + t78909d3-4bef-4b3a-b3a1-7eb39fd86a27 + + + + + GenericResource + + PublisherBotoxTest + TestNewPublisher + TestNewPublisher + + + 2013-08-28T14:33:33.116+02:00 + true + + test + + + \ No newline at end of file diff --git a/src/test/resources/ghn.xml b/src/test/resources/ghn.xml new file mode 100644 index 0000000..a3ee71a --- /dev/null +++ b/src/test/resources/ghn.xml @@ -0,0 +1,981 @@ + + bb6e2d69-cccc-42ef-9985-fae2cba85753 + GHN + + + /gcube/devsec/devVRE + + + gcube + + rcirillo-test.ghn.it:8080 + 2013-12-03T11:08:16+01:00 + certified + Dynamic + + + + + + + + + + + + + + + + + + + TERM + + xterm + + + + + + M3_HOME + + /usr/local/apache-maven/apache-maven-3.0.4 + + + + + + XDG_SESSION_PATH + + /org/freedesktop/DisplayManager/Session0 + + + + + + GNOME_KEYRING_CONTROL + + /tmp/keyring-UxzBZa + + + + + + JAVA_HOME + + /usr/local/java/sun-jdk-6-linux-x86-1.6.0.16 + + + + + + SHLVL + + 1 + + + + + + LESSCLOSE + + /usr/bin/lesspipe %s %s + + + + + + XFILESEARCHPATH + + /usr/dt/app-defaults/%L/Dt + + + + + + SESSION_MANAGER + + local/rcirillo-cnr.isti.cnr.it:@/tmp/.ICE-unix/1769,unix/rcirillo-cnr.isti.cnr.it:/tmp/.ICE-unix/1769 + + + + + + COLORTERM + + gnome-terminal + + + + + + GNOME_DESKTOP_SESSION_ID + + this-is-deprecated + + + + + + M3 + + /usr/local/apache-maven/apache-maven-3.0.4/bin + + + + + + GDMSESSION + + ubuntu + + + + + + XDG_SESSION_COOKIE + + d42b5ce427dfcf7226bbc48200000009-1381330528.868244-973891316 + + + + + + COMPIZ_CONFIG_PROFILE + + ubuntu + + + + + + XDG_DATA_DIRS + + /usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/ + + + + + + MANDATORY_PATH + + /usr/share/gconf/ubuntu.mandatory.path + + + + + + PWD + + /home/rcirillo/tomcat7/apache-tomcat-7.0.42 + + + + + + WINDOWID + + 62914566 + + + + + + LOGNAME + + rcirillo + + + + + + GPG_AGENT_INFO + + /tmp/keyring-UxzBZa/gpg:0:1 + + + + + + _ + + /bin/sh + + + + + + NLSPATH + + /usr/dt/lib/nls/msg/%L/%N.cat + + + + + + LD_LIBRARY_PATH + + /usr/local/java/jdk1.6.0.16/jre/lib/i386/server:/usr/local/java/jdk1.6.0.16/jre/lib/i386:/usr/local/java/jdk1.6.0.16/jre/../lib/i386 + + + + + + OLDPWD + + /home/rcirillo + + + + + + SHELL + + /bin/bash + + + + + + DBUS_SESSION_BUS_ADDRESS + + unix:abstract=/tmp/dbus-Cn8BAkdY1z,guid=38ad666c775b2a4d58adfa8700000061 + + + + + + GNOME_KEYRING_PID + + 1758 + + + + + + XDG_CONFIG_DIRS + + /etc/xdg/xdg-ubuntu:/etc/xdg + + + + + + XDG_CURRENT_DESKTOP + + Unity + + + + + + DESKTOP_SESSION + + ubuntu + + + + + + JRE_HOME + + /usr/local/java/jdk1.6.0.16/jre + + + + + + DISPLAY + + :0 + + + + + + UBUNTU_MENUPROXY + + libappmenu.so + + + + + + USER + + rcirillo + + + + + + HOME + + /home/rcirillo + + + + + + GHN_HOME + + /home/rcirillo/ghn + + + + + + GLOBUS_LOCATION + + /home/rcirillo/gCore + + + + + + XAUTHORITY + + /home/rcirillo/.Xauthority + + + + + + LESSOPEN + + | /usr/bin/lesspipe %s + + + + + + DEFAULTS_PATH + + /usr/share/gconf/ubuntu.default.path + + + + + + XDG_SEAT_PATH + + /org/freedesktop/DisplayManager/Seat0 + + + + + + LANG + + en_US.UTF-8 + + + + + + Java + + 1.6.0_16 + + + + + + SmartGears + + 1.0.0-SNAPSHOT + + + + + + ghn-update-interval-in-secs + + 60 + + + + + + CATALINA_HOME + + /home/rcirillo/tomcat7/apache-tomcat-7.0.42/ + + + + + + WINDOWID + + 63229945 + + + + + + OLDPWD + + /home/rcirillo/tomcat7/apache-tomcat-7.0.39 + + + + + + PWD + + /home/rcirillo/tomcat7/apache-tomcat-7.0.39 + + + + + + OLDPWD + + /home/rcirillo/tomcat7/apache-tomcat-7.0.42 + + + + + + OLDPWD + + /home/rcirillo/tomcat7/apache-tomcat-7.0.39/webapps + + + + + + SmartGears + + 1.0.1-SNAPSHOT + + + + + + SESSION_MANAGER + + local/rcirillo-cnr.isti.cnr.it:@/tmp/.ICE-unix/1689,unix/rcirillo-cnr.isti.cnr.it:/tmp/.ICE-unix/1689 + + + + + + XDG_SESSION_COOKIE + + d42b5ce427dfcf7226bbc48200000009-1384861380.927751-1601996142 + + + + + + GDM_LANG + + en_US + + + + + + XAUTHORITY + + /var/run/gdm/auth-for-rcirillo-OhHcgc/database + + + + + + WINDOWPATH + + 7 + + + + + + USERNAME + + rcirillo + + + + + + GNOME_KEYRING_CONTROL + + /tmp/keyring-qdWlJd + + + + + + WINDOWID + + 52544429 + + + + + + GPG_AGENT_INFO + + /tmp/keyring-qdWlJd/gpg:0:1 + + + + + + DBUS_SESSION_BUS_ADDRESS + + unix:abstract=/tmp/dbus-vEOiFR7tGG,guid=5e7a147626aec6489b9f3d3e00000021 + + + + + + GNOME_KEYRING_PID + + 1672 + + + + + + LANGUAGE + + en_US:en + + + + + + WINDOWID + + 52428806 + + + + + + OLDPWD + + /home/rcirillo/tomcat7 + + + + + + TERM + + xterm + + + + + + M3_HOME + + /usr/local/apache-maven/apache-maven-3.0.4 + + + + + + JAVA_HOME + + /usr/local/java/sun-jdk-6-linux-x86-1.6.0.16 + + + + + + LESSCLOSE + + /usr/bin/lesspipe %s %s + + + + + + SESSION_MANAGER + + local/rcirillo-cnr.isti.cnr.it:@/tmp/.ICE-unix/1689,unix/rcirillo-cnr.isti.cnr.it:/tmp/.ICE-unix/1689 + + + + + + GNOME_DESKTOP_SESSION_ID + + this-is-deprecated + + + + + + M3 + + /usr/local/apache-maven/apache-maven-3.0.4/bin + + + + + + COMPIZ_CONFIG_PROFILE + + ubuntu + + + + + + XDG_SESSION_COOKIE + + d42b5ce427dfcf7226bbc48200000009-1384861380.927751-1601996142 + + + + + + GDMSESSION + + ubuntu + + + + + + MANDATORY_PATH + + /usr/share/gconf/ubuntu.mandatory.path + + + + + + PWD + + /home/rcirillo/tomcat7/apache-tomcat-7.0.39 + + + + + + NLSPATH + + /usr/dt/lib/nls/msg/%L/%N.cat + + + + + + XDG_CURRENT_DESKTOP + + Unity + + + + + + XDG_CONFIG_DIRS + + /etc/xdg/xdg-ubuntu:/etc/xdg + + + + + + GLOBUS_LOCATION + + /home/rcirillo/gCore + + + + + + GHN_HOME + + /home/rcirillo/ghn + + + + + + GDM_LANG + + en_US + + + + + + XAUTHORITY + + /var/run/gdm/auth-for-rcirillo-OhHcgc/database + + + + + + WINDOWPATH + + 7 + + + + + + USERNAME + + rcirillo + + + + + + GNOME_KEYRING_CONTROL + + /tmp/keyring-qdWlJd + + + + + + SHLVL + + 1 + + + + + + XFILESEARCHPATH + + /usr/dt/app-defaults/%L/Dt + + + + + + COLORTERM + + gnome-terminal + + + + + + XDG_DATA_DIRS + + /usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/ + + + + + + LOGNAME + + rcirillo + + + + + + WINDOWID + + 52428806 + + + + + + GPG_AGENT_INFO + + /tmp/keyring-qdWlJd/gpg:0:1 + + + + + + _ + + /bin/sh + + + + + + LD_LIBRARY_PATH + + /usr/local/java/jdk1.6.0.16/jre/lib/i386/server:/usr/local/java/jdk1.6.0.16/jre/lib/i386:/usr/local/java/jdk1.6.0.16/jre/../lib/i386 + + + + + + OLDPWD + + /home/rcirillo/tomcat7/apache-tomcat-7.0.39/webapps + + + + + + DBUS_SESSION_BUS_ADDRESS + + unix:abstract=/tmp/dbus-vEOiFR7tGG,guid=5e7a147626aec6489b9f3d3e00000021 + + + + + + SHELL + + /bin/bash + + + + + + GNOME_KEYRING_PID + + 1672 + + + + + + LANGUAGE + + en_US:en + + + + + + JRE_HOME + + /usr/local/java/jdk1.6.0.16/jre + + + + + + DESKTOP_SESSION + + ubuntu + + + + + + DISPLAY + + :0 + + + + + + USER + + rcirillo + + + + + + UBUNTU_MENUPROXY + + libappmenu.so + + + + + + HOME + + /home/rcirillo + + + + + + LESSOPEN + + | /usr/bin/lesspipe %s + + + + + + DEFAULTS_PATH + + /usr/share/gconf/ubuntu.default.path + + + + + + LANG + + en_US.UTF-8 + + + + + + Java + + 1.6.0_16 + + + + + + SmartGears + + 1.0.1-SNAPSHOT + + + + + + ghn-update-interval-in-secs + + 60 + + + + + + + + 13 days + + + + + + 2013-12-03T10:06:19+01:00 + + + + + + rome + + it + + 41.9000 + + 12.5000 + + rcirillo-test.ghn.cnr.it + + + + + + \ No newline at end of file diff --git a/src/test/resources/log4j.properties b/src/test/resources/log4j.properties new file mode 100644 index 0000000..852274e --- /dev/null +++ b/src/test/resources/log4j.properties @@ -0,0 +1,19 @@ +# Set root category priority to WARN and its only appender to A1. +log4j.rootCategory=ERROR, A1 + +log4j.rootLogger=TRACE + +log4j.appender.A1=org.apache.log4j.ConsoleAppender + + +# A1 uses PatternLayout. +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=[PUBLISHER] %d{HH:mm:ss,SSS} %-5p %c{2} [%t,%M:%L] %m%n + + +# Display any warnings generated by our code +log4j.category.org.gcube.informationsystem.publisher=TRACE,A1 +log4j.additivity.org.gcube.informationsystem.publisher=false + + + diff --git a/src/test/resources/scope-validator.jar b/src/test/resources/scope-validator.jar new file mode 100644 index 0000000..fddcf9e Binary files /dev/null and b/src/test/resources/scope-validator.jar differ diff --git a/src/test/resources/service.xml b/src/test/resources/service.xml new file mode 100644 index 0000000..a904173 --- /dev/null +++ b/src/test/resources/service.xml @@ -0,0 +1,31 @@ + + 3aa0e790-b609-11e1-959a-8f8c3e6664f5 + Service + + + + + + + Test Profile: registry publisher test + Test + NameTest + 1.0.0 + + + NameTest + 1.0.0 + + org.gcube.test + test-test-test + 1.0.0 + + + library + + test-test-test-1.0.0.jar + + + + + \ No newline at end of file