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"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <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"> <classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
@ -13,14 +23,17 @@
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </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> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>

51
pom.xml
View File

@ -7,9 +7,12 @@
<version>1.0.1-SNAPSHOT</version> <version>1.0.1-SNAPSHOT</version>
<name>Legacy is publisher</name> <name>Legacy is publisher</name>
<scm> <scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</connection> <connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</developerConnection> scm:git:https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</connection>
<url>https://code-repo.d4science.org/gCubeSystem/legacy-is-publisher-connector</url> <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> </scm>
<properties> <properties>
<maven.compiler.source>11</maven.compiler.source> <maven.compiler.source>11</maven.compiler.source>
@ -25,13 +28,35 @@
<dependency> <dependency>
<groupId>org.gcube.distribution</groupId> <groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId> <artifactId>gcube-smartgears-bom</artifactId>
<version>3.0.0</version> <version>3.0.1-SNAPSHOT</version>
<type>pom</type> <type>pom</type>
<scope>import</scope> <scope>import</scope>
</dependency> </dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>
<dependencies> <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> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -56,22 +81,6 @@
<groupId>org.gcube.resources</groupId> <groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId> <artifactId>common-gcore-resources</artifactId>
</dependency> </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> </dependencies>
</project> </project>

View File

@ -27,14 +27,12 @@ import org.slf4j.LoggerFactory;
@SmartgearsProfilePublisher @SmartgearsProfilePublisher
public class LegacyISPublisher implements Publisher { public class LegacyISPublisher implements Publisher {
private static Logger logger = LoggerFactory.getLogger(LegacyISPublisher.class); private static Logger logger = LoggerFactory.getLogger(LegacyISPublisher.class);
private Registry registry = new Registry(); private Registry registry = new Registry();
private static Map<String, Resource> resourcesCache = new HashMap<String, Resource>(); private static Map<String, Resource> resourcesCache = new HashMap<String, Resource>();
@Override @Override
public boolean create(ContainerContext container, Set<String> contexts) { public boolean create(ContainerContext container, Set<String> contexts) {
ContainerProfileBuilder cpb = new ContainerProfileBuilder(container); ContainerProfileBuilder cpb = new ContainerProfileBuilder(container);
@ -56,23 +54,17 @@ public class LegacyISPublisher implements Publisher{
resourcesCache.put(id, hostingNode); resourcesCache.put(id, hostingNode);
} }
for (String context : filterICContexts(hostingNode.scopes().asCollection())) {
for (String context : filterICContexts(hostingNode.scopes().asCollection()))
try {
logger.info("publishing container in context {}", context); logger.info("publishing container in context {}", context);
AuthorizedTasks.executeSafely(() -> { AuthorizedTasks.executeSafely(() -> {
try { try {
registry.getStubs().create(toXml(hostingNode), hostingNode.type().toString()); 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) { } catch (Throwable e) {
logger.error("error publishing container in context {}", context, e); logger.error("error publishing container in context {}", context, e);
} }
}, new ICSecret(context));
}
return true; return true;
} }
@ -95,22 +87,17 @@ public class LegacyISPublisher implements Publisher{
resourcesCache.put(id, endpoint); resourcesCache.put(id, endpoint);
} }
for (String context : filterICContexts(endpoint.scopes().asCollection())) for (String context : filterICContexts(endpoint.scopes().asCollection())) {
try {
logger.info("publishing application in context {}", context); logger.info("publishing application in context {}", context);
AuthorizedTasks.executeSafely(() -> { AuthorizedTasks.executeSafely(() -> {
try { try {
String resource = toXml(endpoint); String resource = toXml(endpoint);
registry.getStubs().create(resource, endpoint.type().toString()); registry.getStubs().create(resource, endpoint.type().toString());
}catch (Exception e) { } catch (Throwable e) {
logger.error("error publishing application", e); logger.error("error publishing application in {}", context, e);
throw new RuntimeException(e);
} }
}, new ICSecret(context)); }, new ICSecret(context));
}catch (Throwable e) {
logger.error("error publishing application profile in context {}", context, e);
} }
return true; return true;
} }
@ -142,7 +129,7 @@ public class LegacyISPublisher implements Publisher{
try { try {
logger.info("removing container from context {}", context); logger.info("removing container from context {}", context);
registry.getStubs().remove(hostingNode.id(), hostingNode.type().toString()); registry.getStubs().remove(hostingNode.id(), hostingNode.type().toString());
}catch (Exception e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -157,7 +144,7 @@ public class LegacyISPublisher implements Publisher{
AuthorizedTasks.executeSafely(() -> { AuthorizedTasks.executeSafely(() -> {
try { try {
registry.getStubs().update(hostingNode.id(), hostingNode.type().toString(), toXml(hostingNode)); registry.getStubs().update(hostingNode.id(), hostingNode.type().toString(), toXml(hostingNode));
}catch (Exception e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -197,7 +184,7 @@ public class LegacyISPublisher implements Publisher{
try { try {
logger.info("removing container in context {}", context); logger.info("removing container in context {}", context);
registry.getStubs().remove(endpoint.id(), endpoint.type().toString()); registry.getStubs().remove(endpoint.id(), endpoint.type().toString());
}catch (Exception e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@ -213,7 +200,7 @@ public class LegacyISPublisher implements Publisher{
logger.info("updating application in context {}", context); logger.info("updating application in context {}", context);
String resource = toXml(endpoint); String resource = toXml(endpoint);
registry.getStubs().update(endpoint.id(), endpoint.type().toString(), resource); registry.getStubs().update(endpoint.id(), endpoint.type().toString(), resource);
}catch (Exception e) { } catch (Throwable e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
}, new ICSecret(context)); }, new ICSecret(context));
@ -233,20 +220,17 @@ public class LegacyISPublisher implements Publisher{
endpoint = (GCoreEndpoint) resourcesCache.get(id); endpoint = (GCoreEndpoint) resourcesCache.get(id);
} }
for (String context : filterICContexts(endpoint.scopes().asCollection())) for (String context : filterICContexts(endpoint.scopes().asCollection())) {
try {
logger.info("updating application in context {}", context); logger.info("updating application in context {}", context);
AuthorizedTasks.executeSafely(() -> { AuthorizedTasks.executeSafely(() -> {
try { try {
String resource = toXml(endpoint); String resource = toXml(endpoint);
registry.getStubs().update(endpoint.id(), endpoint.type().toString(), resource); registry.getStubs().update(endpoint.id(), endpoint.type().toString(), resource);
}catch (Exception e) {
throw new RuntimeException(e);
}
}, new ICSecret(context));
} catch (Throwable e) { } catch (Throwable e) {
logger.error("error updating application profile in context {}", context, e); logger.error("error updating application profile in context {}", context, e);
} }
}, new ICSecret(context));
}
return true; return true;
} }
@ -265,20 +249,17 @@ public class LegacyISPublisher implements Publisher{
resourcesCache.put(id, hostingNode); resourcesCache.put(id, hostingNode);
} }
for (String context : filterICContexts(hostingNode.scopes().asCollection())) for (String context : filterICContexts(hostingNode.scopes().asCollection())) {
try {
logger.info("updating container in context {}", context); logger.info("updating container in context {}", context);
AuthorizedTasks.executeSafely(() -> { AuthorizedTasks.executeSafely(() -> {
try { try {
logger.info("updating container in context {}", context); logger.info("updating container in context {}", context);
registry.getStubs().update(hostingNode.id(), hostingNode.type().toString(), toXml(hostingNode)); registry.getStubs().update(hostingNode.id(), hostingNode.type().toString(), toXml(hostingNode));
}catch (Exception e) { } catch (Throwable e) {
throw new RuntimeException(e); logger.error("error updating container in context {}", context, e);
} }
}, new ICSecret(context)); }, new ICSecret(context));
}catch (Throwable e) {
logger.error("error updating container in context {}", context, e);
} }
return true; return true;
} }
@ -310,11 +291,11 @@ public class LegacyISPublisher implements Publisher{
private <T extends Resource> boolean anotherBrotherVREOrVOOnResource(T resource, String scope) { private <T extends Resource> boolean anotherBrotherVREOrVOOnResource(T resource, String scope) {
if (!new ContextBean(scope).is(Type.VRE)) if (!new ContextBean(scope).is(Type.VRE))
throw new IllegalArgumentException("anotherBrotherVREOrVOOnResource method: the input scope must be a VRE scope"); throw new IllegalArgumentException(
"anotherBrotherVREOrVOOnResource method: the input scope must be a VRE scope");
String enclosedScope = new ContextBean(scope).enclosingScope().toString(); String enclosedScope = new ContextBean(scope).enclosingScope().toString();
for (String s : resource.scopes()) { for (String s : resource.scopes()) {
if (isChildScope(enclosedScope, s) || if (isChildScope(enclosedScope, s) || ((enclosedScope != null) && (enclosedScope.toString().equals(s))))
((enclosedScope != null) && (enclosedScope.toString().equals(s))))
return true; return true;
} }
return false; return false;
@ -330,6 +311,7 @@ public class LegacyISPublisher implements Publisher{
} }
return false; return false;
} }
private boolean isChildScope(String fatherScope, String sonScope) { 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)); return (currentEnclosedScope != null) && (currentEnclosedScope.toString().equals(fatherScope));
@ -338,7 +320,8 @@ public class LegacyISPublisher implements Publisher{
private <T extends Resource> boolean anotherInfraScopeOnResource(T resource, String scope) { private <T extends Resource> boolean anotherInfraScopeOnResource(T resource, String scope) {
if (!new ContextBean(scope).is(Type.INFRASTRUCTURE)) if (!new ContextBean(scope).is(Type.INFRASTRUCTURE))
throw new IllegalArgumentException("anotherInfraScopeOnResource method: the input scope must be a INFRASTRUCTURE scope"); throw new IllegalArgumentException(
"anotherInfraScopeOnResource method: the input scope must be a INFRASTRUCTURE scope");
String infraScopeFound = null; String infraScopeFound = null;
for (String s : resource.scopes()) { for (String s : resource.scopes()) {
while (new ContextBean(s).enclosingScope() != null) while (new ContextBean(s).enclosingScope() != null)

View File

@ -24,8 +24,6 @@ public class Registry {
private List<URI> endpoints; private List<URI> endpoints;
private static final Logger log = LoggerFactory.getLogger(Registry.class); private static final Logger log = LoggerFactory.getLogger(Registry.class);
public List<URI> getEndPoints(){ public List<URI> getEndPoints(){
String scope=SecretManagerProvider.get().getContext(); 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()"); .setResult("$resource/Profile/AccessPoint/RunningInstanceInterfaces/Endpoint[string(@EntryName) eq '"+RegistryConstants.service_entrypoint+"']/string()");
endpoints = client.submit(query); endpoints = client.submit(query);
if (endpoints.size()==0){ if (endpoints.size()==0){
throw new IllegalArgumentException("No registry endpoint founded"); throw new IllegalArgumentException("No endpoint for registry found");
} }
// able/disable cache
cache.put(scope, endpoints); cache.put(scope, endpoints);
} }
return endpoints; return endpoints;
} }
public RegistryStub getStubs() throws RegistryNotFoundException{ public RegistryStub getStubs() throws RegistryNotFoundException{
String context=SecretManagerProvider.get().getContext();
URI endpoint=null; URI endpoint=null;
//use another method to cache epr //use another method to cache epr
endpoint = getEndPoints().get(0); 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); return stubFor(RegistryConstants.registry).at(endpoint);
} }
public RegistryStub getStubs(URI endpoint) throws RegistryNotFoundException{ public RegistryStub getStubs(URI endpoint) throws RegistryNotFoundException{
log.debug("get stubs from endpoint: "+ endpoint); String context=SecretManagerProvider.get().getContext();
log.debug("get stubs in context {} from fixed endpoint {} ", context, endpoint);
return stubFor(RegistryConstants.registry).at(endpoint); return stubFor(RegistryConstants.registry).at(endpoint);
} }

View File

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

View File

@ -1,11 +1,7 @@
package org.gcube.common.core.publisher.is.legacy.stubs; package org.gcube.common.core.publisher.is.legacy.stubs;
import static org.gcube.common.core.publisher.is.legacy.stubs.RegistryConstants.*; 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 javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import org.gcube.common.core.publisher.is.legacy.stubs.fault.CreateException; import org.gcube.common.core.publisher.is.legacy.stubs.fault.CreateException;
import org.gcube.common.core.publisher.is.legacy.stubs.fault.InvalidResourceException; 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.ResourceNotAcceptedException;
import org.gcube.common.core.publisher.is.legacy.stubs.fault.UpdateException; 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. * A local interface to the resource discovery service.
* *

View File

@ -1,10 +1,10 @@
package org.gcube.common.core.publisher.is.legacy.stubs.fault; 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 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 * 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; 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 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 * Thrown by {@link RegistryStub#create(String, String)} when the resource type is invalid
* service. * service.

View File

@ -1,9 +1,9 @@
package org.gcube.common.core.publisher.is.legacy.stubs.fault; 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 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 * 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; 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 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 * 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 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 * 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; 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 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 * Thrown by {@link RegistryStub#update(String, String)} when something is failed on update
*/ */