solved a bug on remove context

This commit is contained in:
Lucio Lelii 2022-12-06 12:26:18 +01:00
parent 1714f81a4f
commit 2139e64024
6 changed files with 77 additions and 41 deletions

View File

@ -16,10 +16,9 @@
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>

View File

@ -1,8 +1,8 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@ -12,4 +12,4 @@ org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=11

View File

@ -3,6 +3,10 @@
All notable changes to this project will be documented in this file. 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). This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [v2.1.1-SNAPSHOT] - [2022-12-06]
solved a bug on removeContext
## [v2.1.0] - [2022-02-04] ## [v2.1.0] - [2022-02-04]
added OfflineObserver for test purpose added OfflineObserver for test purpose

12
pom.xml
View File

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<parent> <parent>
@ -10,12 +11,14 @@
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId> <artifactId>common-smartgears-app</artifactId>
<version>2.1.0</version> <version>2.1.1-SNAPSHOT</version>
<name>Smartgears Application</name> <name>Smartgears Application</name>
<properties> <properties>
<distroDirectory>distro</distroDirectory> <distroDirectory>distro</distroDirectory>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties> </properties>
<scm> <scm>
@ -56,7 +59,7 @@
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-smartgears</artifactId> <artifactId>common-smartgears</artifactId>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> <version>[3.0.0-SNAPSHOT,4.0.0-SNAPSHOT)</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
@ -77,7 +80,6 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId> <artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions> <executions>
<execution> <execution>
<id>copy-profile</id> <id>copy-profile</id>

View File

@ -0,0 +1,26 @@
package org.gcube.smartgears;
import java.util.concurrent.Future;
public class ManagerPair {
private Class<? extends ApplicationManager> clazz;
private Future<ApplicationManager> future;
public ManagerPair(Class<? extends ApplicationManager> clazz, Future<ApplicationManager> future) {
super();
this.clazz = clazz;
this.future = future;
}
public Class<? extends ApplicationManager> getImplementationClass() {
return clazz;
}
public Future<ApplicationManager> getFuture() {
return future;
}
}

View File

@ -20,6 +20,7 @@ import org.gcube.common.events.Observes.Kind;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.smartgears.ApplicationManager; import org.gcube.smartgears.ApplicationManager;
import org.gcube.smartgears.Constants; import org.gcube.smartgears.Constants;
import org.gcube.smartgears.ManagerPair;
import org.gcube.smartgears.context.application.ApplicationContext; import org.gcube.smartgears.context.application.ApplicationContext;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -30,28 +31,28 @@ public class OnlineObserver implements AppManagerObserver{
private static ExecutorService service = Executors.newCachedThreadPool(); private static ExecutorService service = Executors.newCachedThreadPool();
private Map<String, List<Future<ApplicationManager>>> instanciatedManagerPerScope = new HashMap<String, List<Future<ApplicationManager>>>(); private Map<String, List<ManagerPair>> instanciatedManagerPerScope = new HashMap<String, List<ManagerPair>>();
private OnlineProvider provider; private OnlineProvider provider;
private Collection<String> startingTokens; private Collection<String> startingTokens;
private Set<Class<? extends ApplicationManager>> managersClasses; private Set<Class<? extends ApplicationManager>> managersClasses;
public OnlineObserver(OnlineProvider provider) { public OnlineObserver(OnlineProvider provider) {
this.provider = provider; this.provider = provider;
} }
public void register() { public void register() {
for (String startingToken : startingTokens ) for (String startingToken : startingTokens )
this.onRegistration(startingToken); this.onRegistration(startingToken);
} }
@Observes(value=Constants.token_registered, kind=Kind.safe) @Observes(value=Constants.token_registered, kind=Kind.safe)
public synchronized void onRegistration(final String securityToken){ public synchronized void onRegistration(final String securityToken){
log.info("token registered called with token {}", securityToken); log.info("token registered called with token {}", securityToken);
List<Future<ApplicationManager>> futureList = new ArrayList<Future<ApplicationManager>>(); List<ManagerPair> futureList = new ArrayList<ManagerPair>();
try { try {
final String context = authorizationService().get(securityToken).getContext(); final String context = authorizationService().get(securityToken).getContext();
@ -60,7 +61,7 @@ public class OnlineObserver implements AppManagerObserver{
Future<ApplicationManager> appManagerFuture = service.submit(new InitAppManager(securityToken, context, appManager)); Future<ApplicationManager> appManagerFuture = service.submit(new InitAppManager(securityToken, context, appManager));
log.info("intializing app in context {} with token {} ",context, securityToken); log.info("intializing app in context {} with token {} ",context, securityToken);
futureList.add(appManagerFuture); futureList.add(new ManagerPair(appManager, appManagerFuture));
if (provider.getAppmanagerMap().containsKey(appManager.getCanonicalName())) if (provider.getAppmanagerMap().containsKey(appManager.getCanonicalName()))
provider.getAppmanagerMap().get(appManager.getCanonicalName()).put(context, appManagerFuture); provider.getAppmanagerMap().get(appManager.getCanonicalName()).put(context, appManagerFuture);
else { else {
@ -86,12 +87,14 @@ public class OnlineObserver implements AppManagerObserver{
try { try {
final String context = authorizationService().get(securityToken).getContext(); final String context = authorizationService().get(securityToken).getContext();
for (Future<ApplicationManager> appManager: instanciatedManagerPerScope.get(context)){ if(instanciatedManagerPerScope.get(context) != null ) {
service.execute(new ShutDownAppManager(securityToken, context, appManager)); for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
provider.getAppmanagerMap().get(appManager).remove(context); service.execute(new ShutDownAppManager(securityToken, context, manager.getFuture()));
} provider.getAppmanagerMap().get(manager.getImplementationClass().getCanonicalName()).remove(context);
}
instanciatedManagerPerScope.remove(context);
}
instanciatedManagerPerScope.remove(context);
SecurityTokenProvider.instance.reset(); SecurityTokenProvider.instance.reset();
} catch (ObjectNotFound e1) { } catch (ObjectNotFound e1) {
log.error("it should never happen (token has just been created)",e1); log.error("it should never happen (token has just been created)",e1);
@ -107,24 +110,26 @@ public class OnlineObserver implements AppManagerObserver{
for (String token :appContext.configuration().startTokens()){ for (String token :appContext.configuration().startTokens()){
try { try {
String context = authorizationService().get(token).getContext(); String context = authorizationService().get(token).getContext();
for (Future<ApplicationManager> appManagerEntry: instanciatedManagerPerScope.get(context)){ if(instanciatedManagerPerScope.get(context) != null ) {
try{ for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
log.info("stoppping {} in context {} ",appContext.name(), context); try{
log.info("stoppping {} in context {} ",appContext.name(), context);
SecurityTokenProvider.instance.set(token); SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(context); ScopeProvider.instance.set(context);
try { try {
appManagerEntry.get().onShutdown(); manager.getFuture().get().onShutdown();
log.info("manager {} correctly suhtdown on context {}",appContext.name(), context); log.info("manager {} correctly suhtdown on context {}",appContext.name(), context);
} catch (Exception e){ } catch (Exception e){
log.warn("problem calling onShutdown for context {}", context, 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(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) { } catch (ObjectNotFound e1) {
@ -201,7 +206,7 @@ public class OnlineObserver implements AppManagerObserver{
@Override @Override
public void setStartingTokens(Collection<String> startingTokens) { public void setStartingTokens(Collection<String> startingTokens) {
this.startingTokens = startingTokens; this.startingTokens = startingTokens;
} }
@Override @Override
@ -209,5 +214,5 @@ public class OnlineObserver implements AppManagerObserver{
this.managersClasses = managersClasses; this.managersClasses = managersClasses;
} }
} }