Compare commits
11 Commits
master
...
feature/22
Author | SHA1 | Date |
---|---|---|
lucio | 6b056664a9 | |
lucio | 7738b1ea1f | |
lucio | 73cba3adc7 | |
Lucio Lelii | d04d5dafbf | |
Lucio Lelii | c80f8896a1 | |
Lucio Lelii | c20234af24 | |
Lucio Lelii | bdbbd55d8c | |
Lucio Lelii | b65fe507af | |
Lucio Lelii | e076dc39de | |
Lucio Lelii | 9f90b83724 | |
Lucio Lelii | 558e8af575 |
21
.classpath
21
.classpath
|
@ -1,5 +1,16 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<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="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
|
@ -13,15 +24,5 @@
|
|||
<attribute name="test" 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="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="output" path="target/classes"/>
|
||||
</classpath>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
/target/
|
|
@ -10,6 +10,6 @@ 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
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
|
||||
|
||||
<wb-module deploy-name="common-smartgears-app">
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/resources"/>
|
||||
|
||||
<wb-resource deploy-path="/" source-path="/src/main/java"/>
|
||||
|
||||
</wb-module>
|
||||
|
||||
</project-modules>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<faceted-project>
|
||||
<installed facet="jst.utility" version="1.0"/>
|
||||
<installed facet="java" version="1.8"/>
|
||||
<installed facet="java" version="11"/>
|
||||
</faceted-project>
|
||||
|
|
|
@ -3,9 +3,9 @@
|
|||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [v2.1.1] - [2022-12-06]
|
||||
## [v3.0.0-SNAPSHOT] - [2022-05-13]
|
||||
|
||||
solved a bug on removeContext
|
||||
porting to new IAM
|
||||
|
||||
## [v2.1.0] - [2022-02-04]
|
||||
|
||||
|
|
29
pom.xml
29
pom.xml
|
@ -11,14 +11,15 @@
|
|||
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears-app</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<name>Smartgears Application</name>
|
||||
|
||||
|
||||
<properties>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
|
@ -27,6 +28,18 @@
|
|||
<url>https://code-repo.d4science.org/gCubeSystem/common-smartgears-app</url>
|
||||
</scm>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>gcube-smartgears-bom</artifactId>
|
||||
<version>3.0.0-SNAPSHOT</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
|
@ -39,7 +52,6 @@
|
|||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.10</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
|
||||
|
@ -59,10 +71,14 @@
|
|||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-smartgears</artifactId>
|
||||
<version>[3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
|
@ -80,6 +96,7 @@
|
|||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>2.5</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-profile</id>
|
||||
|
|
|
@ -32,16 +32,19 @@ public abstract class ApplicationManagerProvider {
|
|||
|
||||
protected static synchronized void init(ApplicationContext appcontext) {
|
||||
if (!initialized) {
|
||||
if (appcontext.container().configuration().mode()== Mode.offline)
|
||||
if (appcontext.container().configuration().mode()== Mode.offline)
|
||||
instance = new OfflineProvider();
|
||||
|
||||
else
|
||||
instance = new OnlineProvider();
|
||||
initialized =true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static synchronized ApplicationManager get(final Class<? extends ApplicationManager> applicationManagerClass){
|
||||
if (!initialized) throw new RuntimeException("ApplicationManagerProvider not yet initialized");
|
||||
logger.debug("retrieveing application manager of {} ",applicationManagerClass.getCanonicalName());
|
||||
Object obj = instance.getApplicationManagerObject(applicationManagerClass);
|
||||
return applicationManagerClass.cast(obj);
|
||||
}
|
||||
|
@ -56,16 +59,17 @@ public abstract class ApplicationManagerProvider {
|
|||
logger.trace("getting object {} from cache ",_class.getCanonicalName());
|
||||
return obj;
|
||||
} else {
|
||||
obj = _class.newInstance();
|
||||
obj = _class.getDeclaredConstructor().newInstance();
|
||||
classProxyObjetMap.put(_class.getCanonicalName(), obj);
|
||||
}
|
||||
|
||||
|
||||
logger.debug("proxy created for {} ",applicationManagerClass.getCanonicalName());
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("error creating proxy ", e);
|
||||
}
|
||||
|
||||
((ProxyObject)obj).setHandler(getMethdoHandler(applicationManagerClass));
|
||||
((ProxyObject)obj).setHandler(this.getMethodHandler(applicationManagerClass));
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -108,7 +112,7 @@ public abstract class ApplicationManagerProvider {
|
|||
}
|
||||
|
||||
protected abstract Future<ApplicationManager> retrieveFuture(Class<? extends ApplicationManager> applicationManagerClass);
|
||||
protected abstract MethodHandler getMethdoHandler(Class<? extends ApplicationManager> applicationManagerClass);
|
||||
protected abstract MethodHandler getMethodHandler(Class<? extends ApplicationManager> applicationManagerClass);
|
||||
protected abstract AppManagerObserver getObserver();
|
||||
|
||||
}
|
||||
|
|
|
@ -4,12 +4,10 @@ import java.net.URL;
|
|||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
import javax.servlet.annotation.WebListener;
|
||||
|
||||
import org.gcube.smartgears.Constants;
|
||||
import org.gcube.smartgears.annotations.ManagedBy;
|
||||
import org.gcube.smartgears.application.manager.AppManagerObserver;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
|
@ -61,15 +59,14 @@ public class ContextListener implements ServletContextListener {
|
|||
Set<Class<? extends ApplicationManager>> managers = new HashSet<Class<? extends ApplicationManager>>();
|
||||
for (Class<?> initializer: toInitialize ){
|
||||
ManagedBy manageBy = initializer.getAnnotation(ManagedBy.class);
|
||||
log.info("ApplicationManager added {} @ {}", manageBy.value().getSimpleName(), context.name());
|
||||
log.info("ApplicationManager added {} to {} @ {}", manageBy.value().getSimpleName(), initializer.getSimpleName(), context.name());
|
||||
managers.add(manageBy.value());
|
||||
}
|
||||
if (managers.size()>0){
|
||||
observer = ApplicationManagerProvider.instance.getObserver();
|
||||
observer.setStartingTokens(context.configuration().startTokens());
|
||||
observer.setAuthorizationProvider(context.container().authorizationProvider());
|
||||
observer.setApplicationManagerClasses(managers);
|
||||
observer.register();
|
||||
|
||||
context.events().subscribe(observer);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,8 @@ import org.gcube.smartgears.context.Properties;
|
|||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.smartgears.context.container.ContainerContext;
|
||||
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
|
||||
import org.gcube.smartgears.persistence.Persistence;
|
||||
import org.gcube.smartgears.persistence.PersistenceWriter;
|
||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||
|
||||
/**
|
||||
* Embedded in an application, makes available its context as a gCube resource.
|
||||
|
@ -56,12 +57,7 @@ public class ContextProvider {
|
|||
public ApplicationConfiguration configuration() {
|
||||
return delegate.configuration();
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T profile(Class<T> type) {
|
||||
return delegate.profile(type);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ApplicationLifecycle lifecycle() {
|
||||
return delegate.lifecycle();
|
||||
|
@ -71,12 +67,7 @@ public class ContextProvider {
|
|||
public Hub events() {
|
||||
return delegate.events();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Persistence persistence() {
|
||||
return delegate.persistence();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ServletContext application() {
|
||||
return delegate.application();
|
||||
|
@ -96,6 +87,16 @@ public class ContextProvider {
|
|||
public String id() {
|
||||
return delegate.id();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PersistenceWriter persistence() {
|
||||
return delegate.persistence();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AuthorizationProvider authorizationProvider() {
|
||||
return delegate.authorizationProvider();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,4 +23,4 @@ public class ManagerPair {
|
|||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -1,10 +1,10 @@
|
|||
package org.gcube.smartgears.application.manager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.smartgears.ApplicationManager;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||
|
||||
public interface AppManagerObserver {
|
||||
|
||||
|
@ -16,7 +16,7 @@ public interface AppManagerObserver {
|
|||
|
||||
void unregister();
|
||||
|
||||
void setStartingTokens(Collection<String> startingTokens);
|
||||
public void setAuthorizationProvider(AuthorizationProvider authProvider);
|
||||
|
||||
void setApplicationManagerClasses(Set<Class<? extends ApplicationManager>> managersClasses);
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.gcube.smartgears.application.manager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
@ -13,6 +12,7 @@ import org.gcube.common.events.Observes.Kind;
|
|||
import org.gcube.smartgears.ApplicationManager;
|
||||
import org.gcube.smartgears.Constants;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -79,7 +79,7 @@ public class OfflineObserver implements AppManagerObserver {
|
|||
|
||||
@Override
|
||||
public ApplicationManager call() throws Exception {
|
||||
ApplicationManager manager = managerClass.newInstance();
|
||||
ApplicationManager manager = managerClass.getDeclaredConstructor().newInstance();
|
||||
try {
|
||||
log.info("calling on onInit of {}",manager.getClass().getCanonicalName());
|
||||
manager.onInit();
|
||||
|
@ -109,13 +109,15 @@ public class OfflineObserver implements AppManagerObserver {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStartingTokens(Collection<String> startingTokens) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void setApplicationManagerClasses(Set<Class<? extends ApplicationManager>> managerClasses) {
|
||||
this.managerClasses = managerClasses;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAuthorizationProvider(AuthorizationProvider authProvider) {
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ public class OfflineProvider extends ApplicationManagerProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected MethodHandler getMethdoHandler(Class<? extends ApplicationManager> applicationManagerClass) {
|
||||
protected MethodHandler getMethodHandler(Class<? extends ApplicationManager> applicationManagerClass) {
|
||||
MethodHandler handler = new MethodHandler() {
|
||||
@Override
|
||||
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package org.gcube.smartgears.application.manager;
|
||||
|
||||
import static org.gcube.common.authorization.client.Constants.authorizationService;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -13,15 +10,15 @@ import java.util.concurrent.ExecutorService;
|
|||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.events.Observes;
|
||||
import org.gcube.common.events.Observes.Kind;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.smartgears.ApplicationManager;
|
||||
import org.gcube.smartgears.Constants;
|
||||
import org.gcube.smartgears.ManagerPair;
|
||||
import org.gcube.smartgears.context.application.ApplicationContext;
|
||||
import org.gcube.smartgears.security.AuthorizationProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -35,7 +32,7 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
|
||||
private OnlineProvider provider;
|
||||
|
||||
private Collection<String> startingTokens;
|
||||
private AuthorizationProvider authProvider;
|
||||
|
||||
private Set<Class<? extends ApplicationManager>> managersClasses;
|
||||
|
||||
|
@ -45,21 +42,25 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
}
|
||||
|
||||
public void register() {
|
||||
for (String startingToken : startingTokens )
|
||||
this.onRegistration(startingToken);
|
||||
for (String context : authProvider.getContexts()) {
|
||||
this.onRegistration(context);
|
||||
}
|
||||
}
|
||||
|
||||
@Observes(value=Constants.token_registered, kind=Kind.safe)
|
||||
public synchronized void onRegistration(final String securityToken){
|
||||
log.info("token registered called with token {}", securityToken);
|
||||
public synchronized void onRegistration(String context){
|
||||
log.info("registration called in context {}", context);
|
||||
List<ManagerPair> futureList = new ArrayList<ManagerPair>();
|
||||
|
||||
try {
|
||||
final String context = authorizationService().get(securityToken).getContext();
|
||||
|
||||
Secret secret = authProvider.getSecretForContext(context);
|
||||
|
||||
for (Class<? extends ApplicationManager> appManager: managersClasses){
|
||||
Future<ApplicationManager> appManagerFuture = service.submit(new InitAppManager(securityToken, context, appManager));
|
||||
log.info("intializing app in context {} with token {} ",context, securityToken);
|
||||
|
||||
|
||||
Future<ApplicationManager> appManagerFuture = service.submit(new InitAppManager(secret, appManager));
|
||||
log.info("intializing app using manager {} in context {}",appManager.getClass().getCanonicalName(),context);
|
||||
|
||||
futureList.add(new ManagerPair(appManager, appManagerFuture));
|
||||
if (provider.getAppmanagerMap().containsKey(appManager.getCanonicalName()))
|
||||
|
@ -72,33 +73,28 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
}
|
||||
if (!futureList.isEmpty())
|
||||
instanciatedManagerPerScope.put(context, futureList);
|
||||
} catch (ObjectNotFound e1) {
|
||||
log.error("it should never happen (token has just been created)",e1);
|
||||
throw new RuntimeException("it should never happen (token has just been created",e1);
|
||||
} catch (Exception e1) {
|
||||
log.error("something failed getting token",e1);
|
||||
throw new RuntimeException("something failed getting token",e1);
|
||||
log.error("something failed getting authorization",e1);
|
||||
throw new RuntimeException("something failed getting authorization",e1);
|
||||
}
|
||||
}
|
||||
|
||||
@Observes(value=Constants.token_removed, kind=Kind.critical)
|
||||
public synchronized void onRemove(final String securityToken){
|
||||
public synchronized void onRemove(String context){
|
||||
|
||||
try {
|
||||
final String context = authorizationService().get(securityToken).getContext();
|
||||
|
||||
Secret secret = authProvider.getSecretForContext(context);
|
||||
|
||||
if(instanciatedManagerPerScope.get(context) != null ) {
|
||||
for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
|
||||
service.execute(new ShutDownAppManager(securityToken, context, manager.getFuture()));
|
||||
service.execute(new ShutDownAppManager(secret, manager.getFuture()));
|
||||
provider.getAppmanagerMap().get(manager.getImplementationClass().getCanonicalName()).remove(context);
|
||||
}
|
||||
instanciatedManagerPerScope.remove(context);
|
||||
}
|
||||
|
||||
SecurityTokenProvider.instance.reset();
|
||||
} catch (ObjectNotFound e1) {
|
||||
log.error("it should never happen (token has just been created)",e1);
|
||||
throw new RuntimeException("it should never happen (token has just been created",e1);
|
||||
|
||||
instanciatedManagerPerScope.remove(context);
|
||||
} catch (Exception e1) {
|
||||
log.error("something failed getting token",e1);
|
||||
throw new RuntimeException("something failed getting token",e1);
|
||||
|
@ -107,37 +103,9 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
|
||||
public synchronized void onStop(ApplicationContext appContext){
|
||||
|
||||
for (String token :appContext.configuration().startTokens()){
|
||||
try {
|
||||
String context = authorizationService().get(token).getContext();
|
||||
if(instanciatedManagerPerScope.get(context) != null ) {
|
||||
for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
|
||||
try{
|
||||
log.info("stoppping {} in context {} ",appContext.name(), context);
|
||||
for (String context :appContext.authorizationProvider().getContexts())
|
||||
this.onRemove(context);
|
||||
|
||||
SecurityTokenProvider.instance.set(token);
|
||||
ScopeProvider.instance.set(context);
|
||||
try {
|
||||
manager.getFuture().get().onShutdown();
|
||||
log.info("manager {} correctly suhtdown on context {}",appContext.name(), context);
|
||||
} catch (Exception e){
|
||||
log.warn("problem calling onShutdown for context {}", context, e);
|
||||
}
|
||||
}catch(Exception e){
|
||||
log.error("error retrieving token on shutdown on context {}", context,e);
|
||||
throw new RuntimeException("error retrieving token on shutdown",e);
|
||||
}finally{
|
||||
ScopeProvider.instance.reset();
|
||||
SecurityTokenProvider.instance.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ObjectNotFound e1) {
|
||||
log.error("token not found : {}",token,e1);
|
||||
} catch (Exception e1) {
|
||||
log.error("something failed getting token {}",token,e1);
|
||||
}
|
||||
}
|
||||
unregister();
|
||||
}
|
||||
|
||||
|
@ -148,28 +116,27 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
public class InitAppManager implements Callable<ApplicationManager>{
|
||||
|
||||
private Class<? extends ApplicationManager> managerClass;
|
||||
private String securityToken;
|
||||
private String context;
|
||||
private Secret secret;
|
||||
|
||||
public InitAppManager(String securityToken, String context, Class<? extends ApplicationManager> managerClass){
|
||||
public InitAppManager(Secret secret, Class<? extends ApplicationManager> managerClass){
|
||||
this.managerClass = managerClass;
|
||||
this.securityToken = securityToken;
|
||||
this.context = context;
|
||||
this.secret = secret;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationManager call() throws Exception {
|
||||
SecurityTokenProvider.instance.set(securityToken);
|
||||
ScopeProvider.instance.set(context);
|
||||
ApplicationManager manager = managerClass.newInstance();
|
||||
log.info("on init called");
|
||||
SecretManagerProvider.instance.set(secret);
|
||||
ApplicationManager manager = null;
|
||||
try {
|
||||
log.info("calling on onInit of {} on token {}",manager.getClass().getCanonicalName(), securityToken);
|
||||
manager = managerClass.getDeclaredConstructor().newInstance();
|
||||
log.info("calling on onInit on manager {} with secret {}",manager.getClass().getCanonicalName(),secret);
|
||||
manager.onInit();
|
||||
} catch (Exception e) {
|
||||
log.warn("error on onInit of {} on token {}",manager.getClass().getCanonicalName(), securityToken, e);
|
||||
log.warn("error on onInit of {} on context {}",manager.getClass().getCanonicalName(), secret.getContext(), e);
|
||||
} finally{
|
||||
ScopeProvider.instance.reset();
|
||||
SecurityTokenProvider.instance.reset();
|
||||
SecretManagerProvider.instance.reset();
|
||||
}
|
||||
return manager;
|
||||
}
|
||||
|
@ -178,34 +145,30 @@ public class OnlineObserver implements AppManagerObserver{
|
|||
public class ShutDownAppManager implements Runnable{
|
||||
|
||||
private Future<ApplicationManager> appManager;
|
||||
private String securityToken;
|
||||
private String context;
|
||||
private Secret secret;
|
||||
|
||||
public ShutDownAppManager(String securityToken, String context, Future<ApplicationManager> appManager){
|
||||
public ShutDownAppManager(Secret secret, Future<ApplicationManager> appManager){
|
||||
this.appManager = appManager;
|
||||
this.securityToken = securityToken;
|
||||
this.context = context;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
SecurityTokenProvider.instance.set(securityToken);
|
||||
ScopeProvider.instance.set(context);
|
||||
SecretManagerProvider.instance.set(secret);
|
||||
try {
|
||||
log.info("calling on ShutDown of {} on token {}",appManager.getClass().getCanonicalName(), securityToken);
|
||||
log.info("calling on ShutDown of {} on context {}",appManager.getClass().getCanonicalName(), secret.getContext());
|
||||
appManager.get().onShutdown();
|
||||
} catch (Exception e) {
|
||||
log.warn("error on onShutdown of {} on token {}",appManager.getClass().getCanonicalName(), securityToken, e);
|
||||
log.warn("error on onShutdown of {} on context {}",appManager.getClass().getCanonicalName(), secret.getContext(), e);
|
||||
} finally{
|
||||
ScopeProvider.instance.reset();
|
||||
SecurityTokenProvider.instance.reset();
|
||||
SecretManagerProvider.instance.reset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStartingTokens(Collection<String> startingTokens) {
|
||||
this.startingTokens = startingTokens;
|
||||
public void setAuthorizationProvider(AuthorizationProvider authProvider) {
|
||||
this.authProvider = authProvider;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,8 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.common.security.providers.SecretManagerProvider;
|
||||
import org.gcube.common.security.secrets.Secret;
|
||||
import org.gcube.smartgears.ApplicationManager;
|
||||
import org.gcube.smartgears.ApplicationManagerProvider;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -25,15 +26,18 @@ public class OnlineProvider extends ApplicationManagerProvider {
|
|||
|
||||
@Override
|
||||
protected Future<ApplicationManager> retrieveFuture(Class<? extends ApplicationManager> applicationManagerClass) {
|
||||
return appManagerMap.get(applicationManagerClass.getCanonicalName()).get(ScopeProvider.instance.get());
|
||||
Secret secret = SecretManagerProvider.instance.get();
|
||||
String context = secret.getContext();
|
||||
logger.debug("retrieving appManager {} in context {}",applicationManagerClass.getCanonicalName(), context);
|
||||
return appManagerMap.get(applicationManagerClass.getCanonicalName()).get(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MethodHandler getMethdoHandler(Class<? extends ApplicationManager> applicationManagerClass) {
|
||||
protected MethodHandler getMethodHandler(Class<? extends ApplicationManager> applicationManagerClass) {
|
||||
MethodHandler handler = new MethodHandler() {
|
||||
@Override
|
||||
public Object invoke(Object self, Method thisMethod, Method proceed, Object[] args) throws Throwable {
|
||||
if (ScopeProvider.instance.get()==null) throw new RuntimeException("error invoking application manager method, scope is not set in this thread");
|
||||
if (SecretManagerProvider.instance.get()==null) throw new Exception("error invoking application manager method, secret is not set in this thread");
|
||||
logger.debug("applicationManagerClass is {}",applicationManagerClass.getCanonicalName());
|
||||
Future<ApplicationManager> appManagerFuture = retrieveFuture(applicationManagerClass);
|
||||
logger.debug("appmanager future is null? {}", appManagerFuture==null);
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
package org.gcube.smartgears.stateful;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ResourceBinder {
|
||||
|
||||
@Test
|
||||
public void bind() throws Exception{
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue