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:
parent
a935fd362f
commit
3cf1364c5b
|
@ -1,12 +1,12 @@
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package org.gcube.vremanagement.executor;
|
package org.gcube.vremanagement.executor;
|
||||||
|
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
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.Resource;
|
||||||
import org.gcube.common.resources.gcore.Resources;
|
import org.gcube.common.resources.gcore.Resources;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
|
@ -200,30 +200,6 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
return serviceEndpoint;
|
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(){
|
private void cleanServiceEndpoints(){
|
||||||
try {
|
try {
|
||||||
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class)
|
SimpleQuery query = ICFactory.queryFor(ServiceEndpoint.class)
|
||||||
|
@ -261,10 +237,19 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onInit() {
|
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(
|
logger.trace(
|
||||||
"\n-------------------------------------------------------\n"
|
"\n-------------------------------------------------------\n"
|
||||||
+ "Smart Executor is Starting\n"
|
+ "Smart Executor is Starting on scope {}\n"
|
||||||
+ "-------------------------------------------------------");
|
+ "-------------------------------------------------------", scope);
|
||||||
|
|
||||||
ServiceEndpoint serviceEndpoint = createServiceEndpoint();
|
ServiceEndpoint serviceEndpoint = createServiceEndpoint();
|
||||||
|
|
||||||
|
@ -273,14 +258,13 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
try {
|
try {
|
||||||
SmartExecutorPersistenceFactory.getPersistenceConnector();
|
SmartExecutorPersistenceFactory.getPersistenceConnector();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String scope = ScopeProvider.instance.get();
|
|
||||||
logger.error("Unable to isntantiate {} for scope {}",
|
logger.error("Unable to isntantiate {} for scope {}",
|
||||||
SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e);
|
SmartExecutorPersistenceConnector.class.getSimpleName(), scope, e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO set task that are still on running state on DB to have a clear
|
// TODO set task that are still on running state to FAILED state on
|
||||||
// room
|
// Persistence to clean previous situation of a failure of HostingNode
|
||||||
|
|
||||||
try {
|
try {
|
||||||
publishScopedResource(serviceEndpoint);
|
publishScopedResource(serviceEndpoint);
|
||||||
|
@ -297,8 +281,7 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
+ "Smart Executor Started Successfully\n"
|
+ "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
|
@Override
|
||||||
public void onShutdown(){
|
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(
|
logger.trace(
|
||||||
"\n-------------------------------------------------------\n"
|
"\n-------------------------------------------------------\n"
|
||||||
+ "Smart Executor is Stopping\n"
|
+ "Smart Executor is Stopping on scope {}\n"
|
||||||
+ "-------------------------------------------------------");
|
+ "-------------------------------------------------------", scope);
|
||||||
|
|
||||||
SmartExecutorScheduler.getInstance().stopAll();
|
SmartExecutorScheduler.getInstance().stopAll();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
String scope = ScopeProvider.instance.get();
|
|
||||||
cleanServiceEndpoints();
|
cleanServiceEndpoints();
|
||||||
try {
|
try {
|
||||||
SmartExecutorPersistenceFactory.getPersistenceConnector().close();
|
SmartExecutorPersistenceFactory.getPersistenceConnector().close();
|
||||||
|
@ -329,8 +319,8 @@ public class SmartExecutorInitializator implements ApplicationManager {
|
||||||
|
|
||||||
logger.trace(
|
logger.trace(
|
||||||
"\n-------------------------------------------------------\n"
|
"\n-------------------------------------------------------\n"
|
||||||
+ "Smart Executor Stopped Successfully\n"
|
+ "Smart Executor Stopped Successfully on scope {}\n"
|
||||||
+ "-------------------------------------------------------");
|
+ "-------------------------------------------------------", scope);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue