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">
<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-1.8">
<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>

View File

@ -1,8 +1,8 @@
eclipse.preferences.version=1
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.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=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.reportPreviewFeatures=ignore
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.
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]
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">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -10,12 +11,14 @@
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears-app</artifactId>
<version>2.1.0</version>
<version>2.1.1-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>
</properties>
<scm>
@ -56,7 +59,7 @@
<dependency>
<groupId>org.gcube.core</groupId>
<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>
</dependency>
@ -77,7 +80,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<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.smartgears.ApplicationManager;
import org.gcube.smartgears.Constants;
import org.gcube.smartgears.ManagerPair;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -30,28 +31,28 @@ public class OnlineObserver implements AppManagerObserver{
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 Collection<String> startingTokens;
private Set<Class<? extends ApplicationManager>> managersClasses;
public OnlineObserver(OnlineProvider provider) {
this.provider = provider;
}
public void register() {
for (String startingToken : startingTokens )
this.onRegistration(startingToken);
}
@Observes(value=Constants.token_registered, kind=Kind.safe)
public synchronized void onRegistration(final String securityToken){
log.info("token registered called with token {}", securityToken);
List<Future<ApplicationManager>> futureList = new ArrayList<Future<ApplicationManager>>();
List<ManagerPair> futureList = new ArrayList<ManagerPair>();
try {
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));
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()))
provider.getAppmanagerMap().get(appManager.getCanonicalName()).put(context, appManagerFuture);
else {
@ -86,12 +87,14 @@ public class OnlineObserver implements AppManagerObserver{
try {
final String context = authorizationService().get(securityToken).getContext();
for (Future<ApplicationManager> appManager: instanciatedManagerPerScope.get(context)){
service.execute(new ShutDownAppManager(securityToken, context, appManager));
provider.getAppmanagerMap().get(appManager).remove(context);
}
if(instanciatedManagerPerScope.get(context) != null ) {
for (ManagerPair manager: instanciatedManagerPerScope.get(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();
} catch (ObjectNotFound 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()){
try {
String context = authorizationService().get(token).getContext();
for (Future<ApplicationManager> appManagerEntry: instanciatedManagerPerScope.get(context)){
try{
log.info("stoppping {} in context {} ",appContext.name(), context);
if(instanciatedManagerPerScope.get(context) != null ) {
for (ManagerPair manager: instanciatedManagerPerScope.get(context)){
try{
log.info("stoppping {} in context {} ",appContext.name(), context);
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(context);
try {
appManagerEntry.get().onShutdown();
log.info("manager {} correctly suhtdown on context {}",appContext.name(), context);
} catch (Exception e){
log.warn("problem calling onShutdown for context {}", context, e);
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(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) {
@ -201,7 +206,7 @@ public class OnlineObserver implements AppManagerObserver{
@Override
public void setStartingTokens(Collection<String> startingTokens) {
this.startingTokens = startingTokens;
}
@Override
@ -209,5 +214,5 @@ public class OnlineObserver implements AppManagerObserver{
this.managersClasses = managersClasses;
}
}