diff --git a/.classpath b/.classpath index 2fcc910..6077578 100644 --- a/.classpath +++ b/.classpath @@ -25,6 +25,12 @@ + + + + + + diff --git a/.project b/.project index 4aa5433..ac328d6 100644 --- a/.project +++ b/.project @@ -15,6 +15,11 @@ + + org.eclipse.wst.validation.validationbuilder + + + org.eclipse.m2e.core.maven2Builder @@ -22,8 +27,11 @@ + org.eclipse.jem.workbench.JavaEMFNature + org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.jdt.core.javanature org.eclipse.m2e.core.maven2Nature org.eclipse.wst.common.project.facet.core.nature + org.eclipse.wst.jsdt.core.jsNature diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index cdfe4f1..29abf99 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,5 +1,6 @@ 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 index 2af1e7b..29fe717 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,11 @@ eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 org.eclipse.jdt.core.compiler.compliance=11 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore +org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.source=11 diff --git a/Dockerfile b/Dockerfile index 99c0481..a2b7de3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM d4science/smartgears-distribution:4.0.0-SNAPSHOT-java11-tomcat9 +FROM smartgears-distribution:4.0.0-SNAPSHOT-java11-tomcat9 COPY ./docker/logback.xml /etc/ COPY ./docker/container.ini /etc/ diff --git a/docker/container.ini b/docker/container.ini index 3834ff0..24dacaf 100644 --- a/docker/container.ini +++ b/docker/container.ini @@ -1,5 +1,5 @@ [node] -mode = offline +mode = online hostname = myhostname.isti.cnr.it protocol= http port = 8080 diff --git a/docker/logback.xml b/docker/logback.xml index dc0b16e..b919bc4 100644 --- a/docker/logback.xml +++ b/docker/logback.xml @@ -9,8 +9,9 @@ + - + diff --git a/src/main/java/manager/HelloWorldManager.java b/src/main/java/manager/HelloWorldManager.java index 9671e65..79b7b8d 100644 --- a/src/main/java/manager/HelloWorldManager.java +++ b/src/main/java/manager/HelloWorldManager.java @@ -3,15 +3,18 @@ package manager; import org.gcube.common.security.providers.SecretManagerProvider; import org.gcube.common.security.secrets.Secret; import org.gcube.smartgears.ApplicationManager; +import org.gcube.smartgears.ContextProvider; +import org.gcube.smartgears.configuration.Mode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * - * This class is use to Manage the application initialization and shutdown per context; - * The init and shutdown methods are called one per context in which the app is running - * respectively at init and a shutdown time. - * It is connected to the app declaring it via the @ManagedBy annotation. (@see HelloWorld class) + * This class is use to Manage the application initialization and shutdown per + * context; The init and shutdown methods are called one per context in which + * the app is running respectively at init and a shutdown time. It is connected + * to the app declaring it via the @ManagedBy annotation. (@see HelloWorld + * class) * * * @author lucio @@ -19,19 +22,27 @@ import org.slf4j.LoggerFactory; */ public class HelloWorldManager implements ApplicationManager { - Logger logger = LoggerFactory.getLogger(HelloWorldManager.class); - + Logger logger = LoggerFactory.getLogger(HelloWorldManager.class); + @Override public void onInit() { - Secret secret = SecretManagerProvider.get(); - logger.debug("init called in context {}", secret.getContext()); - + if (ContextProvider.get().container().configuration().mode() == Mode.offline) { + logger.debug("init called in offline mode"); + } else { + Secret secret = SecretManagerProvider.get(); + logger.debug("init called in context {}", secret.getContext()); + } + } @Override public void onShutdown() { - Secret secret = SecretManagerProvider.get(); - logger.debug("shutDown called in context {}", secret.getContext()); + if (ContextProvider.get().container().configuration().mode() == Mode.offline) { + logger.debug("shutDown called in offline mode"); + } else { + Secret secret = SecretManagerProvider.get(); + logger.debug("shutDown called in context {}", secret.getContext()); + } } } diff --git a/src/main/java/org/gcube/service/helloworld/services/HelloService.java b/src/main/java/org/gcube/service/helloworld/services/HelloService.java index 36ec1f5..48d6ad1 100644 --- a/src/main/java/org/gcube/service/helloworld/services/HelloService.java +++ b/src/main/java/org/gcube/service/helloworld/services/HelloService.java @@ -7,6 +7,7 @@ import javax.ws.rs.core.MediaType; import org.gcube.common.security.providers.SecretManagerProvider; import org.gcube.common.security.secrets.Secret; +import org.gcube.smartgears.ContextProvider; import org.gcube.smartgears.annotations.ManagedBy; import org.gcube.smartgears.utils.InnerMethodName; import org.slf4j.Logger; @@ -14,7 +15,6 @@ import org.slf4j.LoggerFactory; import manager.HelloWorldManager; - @ManagedBy(HelloWorldManager.class) @Path("hello") public class HelloService { @@ -28,8 +28,10 @@ public class HelloService { Secret secret = SecretManagerProvider.get(); String userId = secret.getOwner().getId(); String context = secret.getContext(); + + String infrastructureName = ContextProvider.get().container().configuration().infrastructure(); logger.info("caller id is {}",userId); - return String.format("Hello %s in context %s", userId,context); + return String.format("Hello %s in context %s in infastructure {}", userId,context, infrastructureName); } }