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
This commit is contained in:
Luca Frosini 2016-02-08 16:52:12 +00:00
parent a935fd362f
commit 3cf1364c5b
1 changed files with 30 additions and 40 deletions

View File

@ -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<String> getScopes(ApplicationContext applicationContext){
Collection<String> scopes;
ScopeGroup<String> scopeGroup = applicationContext.profile(GCoreEndpoint.class).scopes();
if(scopeGroup==null || scopeGroup.isEmpty()){
Set<String> applicationScopes = applicationContext.configuration().startScopes();
Set<String> 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<String>(applicationScopes);
}
}else {
scopes = scopeGroup.asCollection();
}
return new ArrayList<String>(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);
}
}