moved to jakarta

This commit is contained in:
lucio 2024-03-12 17:28:51 +01:00
parent dd5d5073ed
commit ba36a1da87
12 changed files with 171 additions and 166 deletions

View File

@ -1,5 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
@ -13,14 +23,17 @@
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

51
pom.xml
View File

@ -7,9 +7,12 @@
<version>1.0.1-SNAPSHOT</version>
<name>Legacy is publisher</name>
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</url>
<connection>
scm:git:https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</connection>
<developerConnection>
scm:git:https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</developerConnection>
<url>
https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</url>
</scm>
<properties>
<maven.compiler.source>11</maven.compiler.source>
@ -25,13 +28,35 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId>
<version>3.0.0</version>
<version>3.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.ws</groupId>
<artifactId>jakarta.xml.ws-api</artifactId>
</dependency>
<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
@ -56,22 +81,6 @@
<groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.3</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.3</version>
</dependency>
</dependencies>
</project>

View File

@ -25,8 +25,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SmartgearsProfilePublisher
public class LegacyISPublisher implements Publisher{
public class LegacyISPublisher implements Publisher {
private static Logger logger = LoggerFactory.getLogger(LegacyISPublisher.class);
@ -34,7 +33,6 @@ public class LegacyISPublisher implements Publisher{
private static Map<String, Resource> resourcesCache = new HashMap<String, Resource>();
@Override
public boolean create(ContainerContext container, Set<String> contexts) {
ContainerProfileBuilder cpb = new ContainerProfileBuilder(container);
@ -43,36 +41,30 @@ public class LegacyISPublisher implements Publisher{
synchronized (resourcesCache) {
String id = container.id();
if (!resourcesCache.containsKey(id))
if (!resourcesCache.containsKey(id))
hostingNode = cpb.create();
else {
hostingNode = (HostingNode) resourcesCache.get(id);
cpb.update(hostingNode);
}
for (String context: contexts)
for (String context : contexts)
ResourceMediator.setScope(hostingNode, context);
resourcesCache.put(id, hostingNode);
}
for (String context : filterICContexts(hostingNode.scopes().asCollection())) {
logger.info("publishing container in context {}", context);
AuthorizedTasks.executeSafely(() -> {
try {
registry.getStubs().create(toXml(hostingNode), hostingNode.type().toString());
} catch (Throwable e) {
logger.error("error publishing container in context {}", context, e);
}
for (String context : filterICContexts(hostingNode.scopes().asCollection()))
try {
logger.info("publishing container in context {}", context);
AuthorizedTasks.executeSafely( () -> {
try {
registry.getStubs().create(toXml(hostingNode), hostingNode.type().toString());
}catch (Exception e) {
logger.error("error publishing container", e);
throw new RuntimeException(e);
}
}, new ICSecret(context));
}catch (Throwable e) {
logger.error("error publishing container in context {}", context, e);
}
}, new ICSecret(context));
}
return true;
}
@ -83,34 +75,29 @@ public class LegacyISPublisher implements Publisher{
synchronized (resourcesCache) {
String id = application.id();
if (!resourcesCache.containsKey(id))
if (!resourcesCache.containsKey(id))
endpoint = cpb.create();
else {
endpoint = (GCoreEndpoint) resourcesCache.get(id);
}
for (String context: contexts)
for (String context : contexts)
ResourceMediator.setScope(endpoint, context);
resourcesCache.put(id, endpoint);
}
for (String context : filterICContexts(endpoint.scopes().asCollection()))
try {
logger.info("publishing application in context {}", context);
AuthorizedTasks.executeSafely(() -> {
try {
String resource = toXml(endpoint);
registry.getStubs().create(resource, endpoint.type().toString());
}catch (Exception e) {
logger.error("error publishing application", e);
throw new RuntimeException(e);
}
}, new ICSecret(context));
}catch (Throwable e) {
logger.error("error publishing application profile in context {}", context, e);
}
for (String context : filterICContexts(endpoint.scopes().asCollection())) {
logger.info("publishing application in context {}", context);
AuthorizedTasks.executeSafely(() -> {
try {
String resource = toXml(endpoint);
registry.getStubs().create(resource, endpoint.type().toString());
} catch (Throwable e) {
logger.error("error publishing application in {}", context, e);
}
}, new ICSecret(context));
}
return true;
}
@ -122,14 +109,14 @@ public class LegacyISPublisher implements Publisher{
synchronized (resourcesCache) {
String id = container.id();
if (!resourcesCache.containsKey(id))
if (!resourcesCache.containsKey(id))
hostingNode = cpb.create();
else {
hostingNode = (HostingNode) resourcesCache.get(id);
cpb.update(hostingNode);
}
for (String context: contexts)
for (String context : contexts)
ResourceMediator.removeScope(hostingNode, context);
resourcesCache.put(id, hostingNode);
@ -138,31 +125,31 @@ public class LegacyISPublisher implements Publisher{
for (String context : contexts)
if (isCompatibleScopeForRemove(hostingNode, context))
try {
AuthorizedTasks.executeSafely( () -> {
AuthorizedTasks.executeSafely(() -> {
try {
logger.info("removing container from context {}", context);
registry.getStubs().remove(hostingNode.id(),hostingNode.type().toString());
}catch (Exception e) {
registry.getStubs().remove(hostingNode.id(), hostingNode.type().toString());
} catch (Throwable e) {
throw new RuntimeException(e);
}
}, new ICSecret(context));
}catch (Throwable e) {
} catch (Throwable e) {
logger.error("error removing container in context {}", context, e);
}
for (String context : filterICContexts(hostingNode.scopes().asCollection()))
try {
logger.info("updating container in context {}", context);
AuthorizedTasks.executeSafely( () -> {
AuthorizedTasks.executeSafely(() -> {
try {
registry.getStubs().update(hostingNode.id(), hostingNode.type().toString(),toXml(hostingNode));
}catch (Exception e) {
registry.getStubs().update(hostingNode.id(), hostingNode.type().toString(), toXml(hostingNode));
} catch (Throwable e) {
throw new RuntimeException(e);
}
}, new ICSecret(context));
}catch (Throwable e) {
} catch (Throwable e) {
logger.error("error updating container in context {}", context, e);
}
@ -177,47 +164,47 @@ public class LegacyISPublisher implements Publisher{
synchronized (resourcesCache) {
String id = application.id();
if (!resourcesCache.containsKey(id))
if (!resourcesCache.containsKey(id))
endpoint = cpb.create();
else {
endpoint = (GCoreEndpoint) resourcesCache.get(id);
}
for (String context: contexts)
for (String context : contexts)
ResourceMediator.removeScope(endpoint, context);
resourcesCache.put(id, endpoint);
}
//TODO: Review this
// TODO: Review this
for (String context : contexts)
if (isCompatibleScopeForRemove(endpoint, context))
try {
AuthorizedTasks.executeSafely( () -> {
AuthorizedTasks.executeSafely(() -> {
try {
logger.info("removing container in context {}", context);
registry.getStubs().remove(endpoint.id(),endpoint.type().toString());
}catch (Exception e) {
registry.getStubs().remove(endpoint.id(), endpoint.type().toString());
} catch (Throwable e) {
throw new RuntimeException(e);
}
}, new ICSecret(context));
}catch (Throwable e) {
} catch (Throwable e) {
logger.error("error removing container in context {}", context, e);
}
for (String context : filterICContexts(endpoint.scopes().asCollection()))
try {
AuthorizedTasks.executeSafely(() -> {
AuthorizedTasks.executeSafely(() -> {
try {
logger.info("updating application in context {}", context);
String resource = toXml(endpoint);
registry.getStubs().update(endpoint.id(), endpoint.type().toString(), resource);
}catch (Exception e) {
} catch (Throwable e) {
throw new RuntimeException(e);
}
}, new ICSecret(context));
}catch (Throwable e) {
} catch (Throwable e) {
logger.error("error updating application profile in context {}", context, e);
}
@ -226,27 +213,24 @@ public class LegacyISPublisher implements Publisher{
@Override
public boolean update(ApplicationContext application) {
GCoreEndpoint endpoint;
synchronized (resourcesCache) {
String id = application.id();
endpoint = (GCoreEndpoint) resourcesCache.get(id);
}
for (String context : filterICContexts(endpoint.scopes().asCollection()))
try {
logger.info("updating application in context {}", context);
AuthorizedTasks.executeSafely(() -> {
try {
String resource = toXml(endpoint);
registry.getStubs().update(endpoint.id(), endpoint.type().toString(), resource);
}catch (Exception e) {
throw new RuntimeException(e);
}
}, new ICSecret(context));
}catch (Throwable e) {
logger.error("error updating application profile in context {}", context, e);
}
for (String context : filterICContexts(endpoint.scopes().asCollection())) {
logger.info("updating application in context {}", context);
AuthorizedTasks.executeSafely(() -> {
try {
String resource = toXml(endpoint);
registry.getStubs().update(endpoint.id(), endpoint.type().toString(), resource);
} catch (Throwable e) {
logger.error("error updating application profile in context {}", context, e);
}
}, new ICSecret(context));
}
return true;
}
@ -265,86 +249,85 @@ public class LegacyISPublisher implements Publisher{
resourcesCache.put(id, hostingNode);
}
for (String context : filterICContexts(hostingNode.scopes().asCollection()))
try {
logger.info("updating container in context {}", context);
AuthorizedTasks.executeSafely( () -> {
try {
logger.info("updating container in context {}", context);
registry.getStubs().update(hostingNode.id(), hostingNode.type().toString(),toXml(hostingNode));
}catch (Exception e) {
throw new RuntimeException(e);
}
for (String context : filterICContexts(hostingNode.scopes().asCollection())) {
logger.info("updating container in context {}", context);
AuthorizedTasks.executeSafely(() -> {
try {
logger.info("updating container in context {}", context);
registry.getStubs().update(hostingNode.id(), hostingNode.type().toString(), toXml(hostingNode));
} catch (Throwable e) {
logger.error("error updating container in context {}", context, e);
}
}, new ICSecret(context));
}catch (Throwable e) {
logger.error("error updating container in context {}", context, e);
}
}, new ICSecret(context));
}
return true;
}
private String toXml(Resource resource){
private String toXml(Resource resource) {
StringWriter writer = new StringWriter();
Resources.marshal(resource, writer);
return writer.toString();
}
private Set<String> filterICContexts(Collection<String> contexts){
return contexts.stream().map( (c) ->{
private Set<String> filterICContexts(Collection<String> contexts) {
return contexts.stream().map((c) -> {
ContextBean bean = new ContextBean(c);
return bean.is(Type.VRE)? bean.enclosingScope().toString(): c;
return bean.is(Type.VRE) ? bean.enclosingScope().toString() : c;
}).collect(Collectors.toSet());
}
private <T extends Resource> boolean isCompatibleScopeForRemove(T resource, String scope){
if(resource.scopes().size() == 0)
private <T extends Resource> boolean isCompatibleScopeForRemove(T resource, String scope) {
if (resource.scopes().size() == 0)
return true;
if(new ContextBean(scope).is(Type.VRE))
if (new ContextBean(scope).is(Type.VRE))
return !anotherBrotherVREOrVOOnResource(resource, scope);
else if(new ContextBean(scope).is(Type.VO))
else if (new ContextBean(scope).is(Type.VO))
return !anotherSonVREOnResource(resource, scope);
else
return !anotherInfraScopeOnResource(resource, scope);
}
private <T extends Resource> boolean anotherBrotherVREOrVOOnResource(T resource, String scope){
if(!new ContextBean(scope).is(Type.VRE))
throw new IllegalArgumentException("anotherBrotherVREOrVOOnResource method: the input scope must be a VRE scope");
String enclosedScope=new ContextBean(scope).enclosingScope().toString();
for(String s : resource.scopes()){
if (isChildScope(enclosedScope, s) ||
((enclosedScope != null) && (enclosedScope.toString().equals(s))))
private <T extends Resource> boolean anotherBrotherVREOrVOOnResource(T resource, String scope) {
if (!new ContextBean(scope).is(Type.VRE))
throw new IllegalArgumentException(
"anotherBrotherVREOrVOOnResource method: the input scope must be a VRE scope");
String enclosedScope = new ContextBean(scope).enclosingScope().toString();
for (String s : resource.scopes()) {
if (isChildScope(enclosedScope, s) || ((enclosedScope != null) && (enclosedScope.toString().equals(s))))
return true;
}
return false;
}
private <T extends Resource> boolean anotherSonVREOnResource(T resource, String scope){
if(!new ContextBean(scope).is(Type.VO))
private <T extends Resource> boolean anotherSonVREOnResource(T resource, String scope) {
if (!new ContextBean(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))
for (String s : resource.scopes()) {
if (isChildScope(scope, s))
return true;
}
return false;
}
private boolean isChildScope(String fatherScope, String sonScope) {
ContextBean currentEnclosedScope=new ContextBean(sonScope).enclosingScope();
ContextBean currentEnclosedScope = new ContextBean(sonScope).enclosingScope();
return (currentEnclosedScope != null) && (currentEnclosedScope.toString().equals(fatherScope));
}
private <T extends Resource> boolean anotherInfraScopeOnResource(T resource, String scope){
if(!new ContextBean(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 ContextBean(s).enclosingScope() != null)
s=new ContextBean(s).enclosingScope().toString();
infraScopeFound=s;
if(infraScopeFound.equals(scope))
private <T extends Resource> boolean anotherInfraScopeOnResource(T resource, String scope) {
if (!new ContextBean(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 ContextBean(s).enclosingScope() != null)
s = new ContextBean(s).enclosingScope().toString();
infraScopeFound = s;
if (infraScopeFound.equals(scope))
return true;
}

View File

@ -24,8 +24,6 @@ public class Registry {
private List<URI> endpoints;
private static final Logger log = LoggerFactory.getLogger(Registry.class);
public List<URI> getEndPoints(){
String scope=SecretManagerProvider.get().getContext();
@ -46,24 +44,25 @@ public class Registry {
.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");
throw new IllegalArgumentException("No endpoint for registry found");
}
// able/disable cache
cache.put(scope, endpoints);
}
return endpoints;
}
public RegistryStub getStubs() throws RegistryNotFoundException{
String context=SecretManagerProvider.get().getContext();
URI endpoint=null;
//use another method to cache epr
endpoint = getEndPoints().get(0);
log.debug("get stubs from endpoint: "+ endpoint);
log.debug("get stubs in context {} from endpoint {} ", context, endpoint);
return stubFor(RegistryConstants.registry).at(endpoint);
}
public RegistryStub getStubs(URI endpoint) throws RegistryNotFoundException{
log.debug("get stubs from endpoint: "+ endpoint);
String context=SecretManagerProvider.get().getContext();
log.debug("get stubs in context {} from fixed endpoint {} ", context, endpoint);
return stubFor(RegistryConstants.registry).at(endpoint);
}

View File

@ -5,7 +5,7 @@ import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import javax.servlet.ServletRegistration;
import jakarta.servlet.ServletRegistration;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.smartgears.configuration.ProxyAddress;

View File

@ -1,11 +1,7 @@
package org.gcube.common.core.publisher.is.legacy.stubs;
import static org.gcube.common.core.publisher.is.legacy.stubs.RegistryConstants.*;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import static org.gcube.common.core.publisher.is.legacy.stubs.RegistryConstants.portType;
import static org.gcube.common.core.publisher.is.legacy.stubs.RegistryConstants.target_namespace;
import org.gcube.common.core.publisher.is.legacy.stubs.fault.CreateException;
import org.gcube.common.core.publisher.is.legacy.stubs.fault.InvalidResourceException;
@ -14,6 +10,11 @@ import org.gcube.common.core.publisher.is.legacy.stubs.fault.ResourceDoesNotExis
import org.gcube.common.core.publisher.is.legacy.stubs.fault.ResourceNotAcceptedException;
import org.gcube.common.core.publisher.is.legacy.stubs.fault.UpdateException;
import jakarta.jws.WebMethod;
import jakarta.jws.WebParam;
import jakarta.jws.WebResult;
import jakarta.jws.WebService;
/**
* A local interface to the resource discovery service.
*

View File

@ -1,10 +1,10 @@
package org.gcube.common.core.publisher.is.legacy.stubs.fault;
import javax.xml.ws.WebFault;
import org.gcube.common.core.publisher.is.legacy.stubs.RegistryStub;
import jakarta.xml.ws.WebFault;
/**
* Thrown by {@link RegistryStub#create(String, String)} when something is failed on creation
*/

View File

@ -1,9 +1,9 @@
package org.gcube.common.core.publisher.is.legacy.stubs.fault;
import javax.xml.ws.WebFault;
import org.gcube.common.core.publisher.is.legacy.stubs.RegistryStub;
import jakarta.xml.ws.WebFault;
/**
* Thrown by {@link RegistryStub#create(String, String)} when the resource type is invalid
* service.

View File

@ -1,9 +1,9 @@
package org.gcube.common.core.publisher.is.legacy.stubs.fault;
import javax.xml.ws.WebFault;
import org.gcube.common.core.publisher.is.legacy.stubs.RegistryStub;
import jakarta.xml.ws.WebFault;
/**
* Thrown by {@link RegistryStub#remove(String, String)} when something is failed on remove
*/

View File

@ -1,9 +1,9 @@
package org.gcube.common.core.publisher.is.legacy.stubs.fault;
import javax.xml.ws.WebFault;
import org.gcube.common.core.publisher.is.legacy.stubs.RegistryStub;
import jakarta.xml.ws.WebFault;
/**
* Thrown by {@link RegistryStub#remove(String, String)} when the resource does not exist in the collector
*/

View File

@ -2,10 +2,10 @@ package org.gcube.common.core.publisher.is.legacy.stubs.fault;
import javax.xml.ws.WebFault;
import org.gcube.common.core.publisher.is.legacy.stubs.RegistryStub;
import jakarta.xml.ws.WebFault;
/**
* Thrown by {@link RegistryStub#create(String, String)} when the resource is not accepted cause it doesn't satisfy a requirement
*/

View File

@ -1,10 +1,10 @@
package org.gcube.common.core.publisher.is.legacy.stubs.fault;
import javax.xml.ws.WebFault;
import org.gcube.common.core.publisher.is.legacy.stubs.RegistryStub;
import jakarta.xml.ws.WebFault;
/**
* Thrown by {@link RegistryStub#update(String, String)} when something is failed on update
*/