From 3cf1364c5b189eac76492f260e8cbd9e825a9192 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 8 Feb 2016 16:52:12 +0000 Subject: [PATCH] refs #2112: Port SmartExecutor to be compliant with new Authorization https://support.d4science.org/issues/2112 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/vre-management/smart-executor@122934 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../executor/SmartExecutorInitializator.java | 70 ++++++++----------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java index 204f797..81099b3 100644 --- a/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java +++ b/src/main/java/org/gcube/vremanagement/executor/SmartExecutorInitializator.java @@ -1,12 +1,12 @@ -/** - * - */ package org.gcube.vremanagement.executor; import java.io.StringWriter; import java.util.List; import java.util.Map; +import org.gcube.common.authorization.client.Constants; +import org.gcube.common.authorization.library.AuthorizationEntry; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.common.resources.gcore.Resource; import org.gcube.common.resources.gcore.Resources; import org.gcube.common.resources.gcore.ServiceEndpoint; @@ -200,30 +200,6 @@ public class SmartExecutorInitializator implements ApplicationManager { return serviceEndpoint; } - /* - public static List getScopes(ApplicationContext applicationContext){ - Collection scopes; - - ScopeGroup scopeGroup = applicationContext.profile(GCoreEndpoint.class).scopes(); - if(scopeGroup==null || scopeGroup.isEmpty()){ - Set applicationScopes = applicationContext.configuration().startScopes(); - Set containerScopes = applicationContext.container().configuration().startScopes(); - - if(applicationScopes==null || applicationScopes.isEmpty()){ - scopes = containerScopes; - logger.debug("Application Scopes ({}). The Container Scopes ({}) will be used.", applicationScopes, scopes); - } else{ - logger.debug("Container Scopes ({}). Application Scopes ({}) will be used.", containerScopes, applicationScopes); - scopes = new HashSet(applicationScopes); - } - }else { - scopes = scopeGroup.asCollection(); - } - - return new ArrayList(scopes); - } - */ - private void cleanServiceEndpoints(){ try { SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class) @@ -261,10 +237,19 @@ public class SmartExecutorInitializator implements ApplicationManager { */ @Override public void onInit() { + String token = SecurityTokenProvider.instance.get(); + AuthorizationEntry authorizationEntry; + try { + authorizationEntry = Constants.authorizationService().get(token); + } catch (Exception e) { + throw new RuntimeException(e); + } + String scope = authorizationEntry.getContext(); + logger.trace( "\n-------------------------------------------------------\n" - + "Smart Executor is Starting\n" - + "-------------------------------------------------------"); + + "Smart Executor is Starting on scope {}\n" + + "-------------------------------------------------------", scope); ServiceEndpoint serviceEndpoint = createServiceEndpoint(); @@ -273,14 +258,13 @@ public class SmartExecutorInitializator implements ApplicationManager { try { SmartExecutorPersistenceFactory.getPersistenceConnector(); } catch (Exception e) { - String scope = ScopeProvider.instance.get(); logger.error("Unable to isntantiate {} for scope {}", SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e); throw new RuntimeException(e); } - // TODO set task that are still on running state on DB to have a clear - // room + // TODO set task that are still on running state to FAILED state on + // Persistence to clean previous situation of a failure of HostingNode try { publishScopedResource(serviceEndpoint); @@ -297,8 +281,7 @@ public class SmartExecutorInitializator implements ApplicationManager { + "Smart Executor Started Successfully\n" + "-------------------------------------------------------"); - // TODO Launch initializer thread - + // TODO Launch repetitive thread for global task take over } /** @@ -309,16 +292,23 @@ public class SmartExecutorInitializator implements ApplicationManager { */ @Override public void onShutdown(){ + String token = SecurityTokenProvider.instance.get(); + AuthorizationEntry authorizationEntry; + try { + authorizationEntry = Constants.authorizationService().get(token); + } catch (Exception e) { + throw new RuntimeException(e); + } + String scope = authorizationEntry.getContext(); + logger.trace( "\n-------------------------------------------------------\n" - + "Smart Executor is Stopping\n" - + "-------------------------------------------------------"); + + "Smart Executor is Stopping on scope {}\n" + + "-------------------------------------------------------", scope); SmartExecutorScheduler.getInstance().stopAll(); - - String scope = ScopeProvider.instance.get(); cleanServiceEndpoints(); try { SmartExecutorPersistenceFactory.getPersistenceConnector().close(); @@ -329,8 +319,8 @@ public class SmartExecutorInitializator implements ApplicationManager { logger.trace( "\n-------------------------------------------------------\n" - + "Smart Executor Stopped Successfully\n" - + "-------------------------------------------------------"); + + "Smart Executor Stopped Successfully on scope {}\n" + + "-------------------------------------------------------", scope); } }