Compare commits

...

29 Commits

Author SHA1 Message Date
Luca Frosini 74dae88836 Upgraded gcube-smartgears-bom version 2024-05-08 17:55:10 +02:00
Luca Frosini 93457fe823 Trying different solution 2024-05-07 16:50:51 +02:00
Luca Frosini 81002fccd1 Added log 2024-05-07 16:38:53 +02:00
Luca Frosini 940d0cba9d Downgraded gcube-smartgears-bom 2024-05-07 14:32:02 +02:00
Luca Frosini 85a92bac67 Fixed changelog 2024-05-07 11:58:30 +02:00
Luca Frosini cecc27920c Fixed changelog 2024-05-07 11:56:36 +02:00
Luca Frosini 40166c4116 updated gcube-smartgears-bom version 2024-05-07 11:55:22 +02:00
Luca Frosini 5bad218e6e Resolving bug #24116 2024-05-07 11:45:33 +02:00
Luca Frosini 840bd00275 Resolving bug #27319 2024-05-07 11:45:16 +02:00
luca.frosini e664ac8388 Removed -SNAPSHOT to release the component 2023-09-12 14:47:24 +02:00
luca.frosini 6ce80b4abe Restored guava explicit version 2023-09-08 11:22:57 +02:00
luca.frosini 2a5ef59c53 Commented explicit guava version 2023-09-08 11:10:54 +02:00
luca.frosini af41a518cf Improving service 2023-09-07 16:40:10 +02:00
luca.frosini b3efedeb1f using -SNAPSHOT version of bom 2023-09-06 15:59:19 +02:00
luca.frosini f037dd4761 Fixed code 2023-09-06 15:05:18 +02:00
luca.frosini ae7a628829 Ignored MacOs File 2023-06-21 11:46:17 +02:00
Luca Frosini a7e2fbb312 Restored release version 2022-11-18 15:12:13 +01:00
Luca Frosini d9ee787061 Disabled new IS plugin publishing 2022-11-18 15:09:38 +01:00
Luca Frosini ab225095b0 Fixing plugin PLUGIN_ENDPOINT_FORMAT 2022-11-18 12:50:14 +01:00
Luca Frosini aa8c561a88 Added missing facet to properly publish RunnningPlugin 2022-11-18 12:13:26 +01:00
Luca Frosini ea237b5c29 Fixing startup 2022-11-17 17:28:39 +01:00
Luca Frosini 77943bda32 Enabling new IS plugins publishing 2022-11-02 14:41:55 +01:00
Luca Frosini b8151fe07d Removed -SNAPSHOT to release the component 2022-10-19 12:10:28 +02:00
Luca Frosini 8ff757dbec Commented new IS publisher usage to release the component 2022-09-02 15:29:48 +02:00
Luca Frosini 9ea8a5b917 Added support for authorization-utils 2022-09-01 16:28:25 +02:00
Luca Frosini b41fdf8246 Added class authorship 2022-09-01 16:27:02 +02:00
Luca Frosini 53f675936d Added authorization-utils dependecy 2022-03-08 11:39:57 +01:00
Luca Frosini 4f329913b7 Fixing CHANGELOG 2022-03-08 11:23:26 +01:00
Luca Frosini 9f26bdb42c Porting service to new authorization-utils 2022-03-08 11:21:19 +01:00
29 changed files with 2000 additions and 196 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
target
.classpath
.project
/.DS_Store
/bin/

View File

@ -2,6 +2,24 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
# Changelog for Smart Executor Service
## [v3.2.1-SNAPSHOT]
- Fixed bug on concurrent attempt to enter in a session while trying to schedule a second task #27319
- Fixed bug on concurrent attempt to enter in a session while trying to execute another task #24116
## [v3.2.0]
- Fixed RequestFilter to avoid to remove info to Smartgears
- Migrated code to reorganized E/R format [#24992]
- Force guava version to 23.6-jre to meet requirements of new plugins
## [v3.1.0]
- Ported service to authorization-utils [#22871]
## [v3.0.0]
- Switched smart-executor JSON management to gcube-jackson [#19647]
@ -9,6 +27,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Redesigned HTTP APIs to comply with RESTful architectural style [#12997]
- Added API to retrieve scheduled tasks [#10780]
## [v2.0.0]
- Removed SOAP APIs

1
docs/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/_build/

20
docs/Makefile Normal file
View File

@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

54
docs/conf.py Normal file
View File

@ -0,0 +1,54 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'Smart Executor Service'
copyright = '2012, Luca Frosini (ISTI-CNR)'
author = 'Luca Frosini (ISTI-CNR)'
# The full version, including alpha/beta/rc tags
release = '3.2.0'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = []
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'sphinxdoc'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

103
docs/index.rst Normal file
View File

@ -0,0 +1,103 @@
***********************************************************
Welcome to Smart Executor Service documentation
***********************************************************
Smart Executor is a RESTful application which exposes operations via REST-API.
See the available `REST-API docs <../api-docs/index.html>`_.
Authorization
=============
D4Science adopts state-of-the-art industry standards for authentication and authorization.
Specifically, the implementation fully adopts `OIDC (OpenID Connect) <https://openid.net/connect>`_ for authentication and UMA 2 (User-Managed Authorization) for authorization flows.
`JSON Web Token (JWT) Access token <https://jwt.io/>`_ are used for both authentication and authorization.
Obtain your Bearer token here: https://dev.d4science.org/how-to-access-resources
Service
=======
You can call the methods of the Web Service by writing your own REST client application or using existing REST client plugins.
HTTP Statuses
-------------
Any successful operation returns *200 OK* HTTP status code.
The create operation returns *201 Created*.
Any Background operation returns *202 Accepted*.
Any operation which does not provide any content return *204 No Content*.
The most common error status a client can obtain are:
* **400 Bad Request** used to indicate a clients error `<https://tools.ietf.org/html/rfc7231#section-6.5.1>`_;
* **401 Unauthorized** used to indicate that the client does not provide the authorization token in the HTTP Header or the client has not enough right to perform such request `<https://tools.ietf.org/html/rfc7235#section-3.1>`_;
* **404 Not Found** used to indicate that the requested instance does not exist `<https://tools.ietf.org/html/rfc7231#section-6.5.4>`_;
* **405 Method Not Allowed** the used HTTP method is not supported for the requested URL `<https://tools.ietf.org/html/rfc7231#section-6.5.5>`_.
The response contains the *Allow* HTTP Header indicating the supported HTTP method for such URL `<https://tools.ietf.org/html/rfc7231#section-7.4.1>`_;
* **409 Conflict** the request could not be completed due to a conflict with the current state of the target resource (e.g. the name of the resource already exists) `<https://tools.ietf.org/html/rfc7231#section-6.5.8>`_;
* **500 Internal Server Error** indicate a server failure `<https://tools.ietf.org/html/rfc7231#section-6.6.1>`_.
You can find a complete list of HTTP Status at `<https://httpstatuses.com/>`_
If you get a *500 Internal Server Error*, please report it in the `gCube ticketing system <https://support.d4science.org>`_.
Please use this checklist before reporting an error:
* Replicate the request;
* The failure could be temporal due to network error, server issue and many other temporal issues. For this reason, please retry the request after a certain amount of time before reporting the issue;
* indicate how to replicate the error;
* indicate the time when the error occurred (this simplifies identifying the issue).
HTTP Methods
------------
Smart Executor is a pure RESTful service.
Service Discovery on IS
=======================
The service can be discovered in the gCore IS as gCore Endpoint with the following parameter:
.. code:: xml
<ServiceClass>org.gcube.vremanagement</ServiceClass>
<ServiceName>smart-executor</ServiceName>
The service can be discovered in the Facet Based IS as EService with the following json query:
.. code:: json
{
"@class": "EService",
"consistsOf": [
{
"@class": "IsIdentifiedBy",
"target": {
"@class": "SoftwareFacet",
"group": "org.gcube.vremanagement",
"name": "smart-executor"
}
}
]
}
Service Maven Coordinates
=========================
The maven coordinates of gCat service are:
.. code:: xml
<groupId>org.gcube.vremanagement</groupId>
<artifactId>smart-executor</artifactId>

35
docs/make.bat Normal file
View File

@ -0,0 +1,35 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

View File

@ -5,4 +5,6 @@
<group>${project.groupId}</group>
<version>${project.version}</version>
<description>${project.description}</description>
<exclude>/api-docs.*</exclude>
<exclude>/docs.*</exclude>
</application>

141
pom.xml
View File

@ -11,7 +11,7 @@
<groupId>org.gcube.vremanagement</groupId>
<artifactId>smart-executor</artifactId>
<version>3.0.0</version>
<version>3.2.1-SNAPSHOT</version>
<name>SmartExecutor</name>
<description>Smart Executor Service allows to launch recurrent tasks such as task for infrastructure management, healthy monitoring etc.</description>
<packaging>war</packaging>
@ -20,6 +20,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<webappDirectory>${project.basedir}${file.separator}src${file.separator}main${file.separator}webapp${file.separator}WEB-INF</webappDirectory>
<orientdb.version>3.1.12</orientdb.version>
<enunciate.version>2.14.0</enunciate.version>
</properties>
<scm>
@ -33,7 +34,7 @@
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-smartgears-bom</artifactId>
<version>2.1.0</version>
<version>2.5.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -41,7 +42,11 @@
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-utils</artifactId>
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
@ -100,29 +105,63 @@
<artifactId>smart-executor-client</artifactId>
<version>[3.0.0, 4.0.0-SNAPSHOT)</version>
</dependency>
<!-- Jersey -->
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6-jre</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
</dependency>
<!-- Added to support Java 11 JDK -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
<!-- END Jersey -->
<!-- END Added to support Java 11 JDK -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<!-- Required for Enunciate plugin -->
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-core-annotations</artifactId>
<version>${enunciate.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-rt-util</artifactId>
<version>${enunciate.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- END Required for Enunciate plugin -->
<!-- Tests -->
<dependency>
<groupId>junit</groupId>
@ -137,4 +176,80 @@
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Sphinx plugin' -->
<plugin>
<groupId>kr.motd.maven</groupId>
<artifactId>sphinx-maven-plugin</artifactId>
<version>2.10.0</version>
<configuration>
<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/docs</outputDirectory>
<builder>html</builder>
<configDirectory>${basedir}/docs</configDirectory>
<sourceDirectory>${basedir}/docs</sourceDirectory>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Enunciate Maven plugin -->
<plugin>
<groupId>com.webcohesion.enunciate</groupId>
<artifactId>enunciate-maven-plugin</artifactId>
<version>${enunciate.version}</version>
<executions>
<execution>
<id>assemble</id>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Copy Enunciate Documentation from your-application/api-docs into your war -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-enunciate-docs</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<targetPath>${project.build.directory}/${project.artifactId}-${project.version}/api-docs</targetPath>
<directory>${project.build.directory}/api-docs</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,82 +1,14 @@
package org.gcube.vremanagement.executor;
import java.util.ArrayList;
import java.util.List;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.ClientType;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ContextUtility {
private static Logger logger = LoggerFactory.getLogger(ContextUtility.class);
public static String getCurrentContext() {
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry;
try {
authorizationEntry = Constants.authorizationService().get(token);
} catch(Exception e) {
logger.trace("Context was not retrieved from token. Going to get it from {}",
ScopeProvider.class.getSimpleName());
return ScopeProvider.instance.get();
}
String context = authorizationEntry.getContext();
logger.trace("Context retrieved from token is {}. Context in {} is {}", context,
ScopeProvider.class.getSimpleName(), ScopeProvider.instance.get());
return context;
}
public static String getCurrentContext(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context);
return context;
}
public static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token);
ScopeProvider.instance.set(getCurrentContext(token));
}
public static ClientInfo getClientInfo() {
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry;
try {
authorizationEntry = Constants.authorizationService().get(token);
} catch(Exception e) {
return new ClientInfo() {
/**
* Generated Serial Version UID
*/
private static final long serialVersionUID = 8311873203596762883L;
@Override
public ClientType getType() {
return ClientType.USER;
}
@Override
public List<String> getRoles() {
return new ArrayList<>();
}
@Override
public String getId() {
return "UNKNOWN";
}
};
}
return authorizationEntry.getClientInfo();
return SecretManagerProvider.instance.get().getContext();
}
}

View File

@ -1,9 +1,14 @@
package org.gcube.vremanagement.executor;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.secret.SecretUtility;
import org.gcube.smartgears.ApplicationManager;
import org.gcube.smartgears.ContextProvider;
import org.gcube.smartgears.context.application.ApplicationContext;
@ -15,6 +20,7 @@ import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceConn
import org.gcube.vremanagement.executor.persistence.SmartExecutorPersistenceFactory;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.gcube.vremanagement.executor.rest.RequestFilter;
import org.gcube.vremanagement.executor.scheduledtask.ScheduledTask;
import org.gcube.vremanagement.executor.scheduler.SmartExecutorScheduler;
import org.gcube.vremanagement.executor.scheduler.SmartExecutorSchedulerFactory;
@ -43,6 +49,13 @@ public class SmartExecutorInitializator implements ApplicationManager {
*/
@Override
public void onInit() {
RequestFilter requestFilter = new RequestFilter();
try {
requestFilter.filter(null);
} catch (IOException e) {
throw new RuntimeException(e);
}
String context = ContextUtility.getCurrentContext();
logger.trace(
@ -132,19 +145,27 @@ public class SmartExecutorInitializator implements ApplicationManager {
}
String scheduledTasktoken = scheduledTask.getToken();
try {
ContextUtility.setContext(scheduledTasktoken);
SmartExecutorScheduler smartExecutorScheduler = SmartExecutorSchedulerFactory.getSmartExecutorScheduler();
// A new Scheduled Task will be persisted due to launch. Removing it
smartExecutorPersistenceConnector.removeScheduledTask(scheduledTask);
smartExecutorScheduler.schedule(launchParameter, scheduledTask.getUUID());
} catch (Exception e) {
logger.error("({}) Error while trying to relaunch scheduled task.", context, e);
Secret secret = SecretUtility.getSecretByTokenString(scheduledTasktoken);
SecretManager secretManager = SecretManagerProvider.instance.get();
synchronized (secretManager) {
try {
smartExecutorPersistenceConnector.addScheduledTask(scheduledTask);
} catch (Exception ex) {
logger.error("({}) Unable to add back scheduled task {}", context, taskAsString);
logger.trace("Starting a Secret Manager session (synchronized block)...");
secretManager.startSession(secret);
SmartExecutorScheduler smartExecutorScheduler = SmartExecutorSchedulerFactory.getSmartExecutorScheduler();
// A new Scheduled Task will be persisted due to launch. Removing it
smartExecutorPersistenceConnector.removeScheduledTask(scheduledTask);
smartExecutorScheduler.schedule(launchParameter, scheduledTask.getUUID());
} catch (Exception e) {
logger.error("({}) Error while trying to relaunch scheduled task.", context, e);
try {
smartExecutorPersistenceConnector.addScheduledTask(scheduledTask);
} catch (Exception ex) {
logger.error("({}) Unable to add back scheduled task {}", context, taskAsString);
}
}finally {
secretManager.endSession();
logger.trace("Secret Manager session terminated (synchronized block).");
}
}
@ -165,7 +186,6 @@ public class SmartExecutorInitializator implements ApplicationManager {
+ "Smart Executor Started Successfully on context {}\n"
+ "-------------------------------------------------------", context);
}
/**
@ -176,7 +196,12 @@ public class SmartExecutorInitializator implements ApplicationManager {
*/
@Override
public void onShutdown(){
RequestFilter requestFilter = new RequestFilter();
try {
requestFilter.filter(null);
} catch (IOException e) {
throw new RuntimeException(e);
}
logger.trace(
"\n-------------------------------------------------------\n"

View File

@ -31,6 +31,9 @@ import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class GCoreISPublisher extends ISPublisher {
private static Logger logger = LoggerFactory.getLogger(GCoreISPublisher.class);

View File

@ -7,6 +7,9 @@ import java.util.Map;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.vremanagement.executor.plugin.Plugin;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public abstract class ISPublisher {
protected static List<ISPublisher> isPublishers;
@ -15,7 +18,7 @@ public abstract class ISPublisher {
if(isPublishers==null) {
isPublishers = new ArrayList<>();
isPublishers.add(new GCoreISPublisher(applicationContext));
isPublishers.add(new RestISPublisher(applicationContext));
// isPublishers.add(new RestISPublisher(applicationContext));
}
return isPublishers;
}

View File

@ -1,10 +1,14 @@
package org.gcube.vremanagement.executor.ispublisher;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.informationsystem.model.impl.properties.HeaderImpl;
import org.gcube.informationsystem.base.reference.Direction;
import org.gcube.informationsystem.model.impl.properties.PropagationConstraintImpl;
import org.gcube.informationsystem.model.reference.entities.Facet;
import org.gcube.informationsystem.model.reference.entities.Resource;
@ -14,19 +18,24 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.client.Direction;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClient;
import org.gcube.informationsystem.resourceregistry.client.ResourceRegistryClientFactory;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisher;
import org.gcube.informationsystem.resourceregistry.publisher.ResourceRegistryPublisherFactory;
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.EventFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SimplePropertyFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.SoftwareFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.facets.StateFacetImpl;
import org.gcube.resourcemanagement.model.impl.entities.resources.RunningPluginImpl;
import org.gcube.resourcemanagement.model.impl.relations.consistsof.IsIdentifiedByImpl;
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.ActivatesImpl;
import org.gcube.resourcemanagement.model.impl.relations.isrelatedto.EnablesImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.EventFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SimplePropertyFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.SoftwareFacet;
import org.gcube.resourcemanagement.model.reference.entities.facets.StateFacet;
import org.gcube.resourcemanagement.model.reference.entities.resources.EService;
import org.gcube.resourcemanagement.model.reference.entities.resources.RunningPlugin;
import org.gcube.resourcemanagement.model.reference.entities.resources.Service;
@ -34,12 +43,20 @@ import org.gcube.resourcemanagement.model.reference.entities.resources.Software;
import org.gcube.resourcemanagement.model.reference.relations.consistsof.IsIdentifiedBy;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Activates;
import org.gcube.resourcemanagement.model.reference.relations.isrelatedto.Enables;
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import org.gcube.smartgears.configuration.container.ContainerConfiguration;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.lifecycle.application.ApplicationState;
import org.gcube.vremanagement.executor.ResourceInitializer;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.executor.pluginmanager.PluginManager;
import org.gcube.vremanagement.executor.rest.RestSmartExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class RestISPublisher extends ISPublisher {
private static Logger logger = LoggerFactory.getLogger(RestISPublisher.class);
@ -48,8 +65,6 @@ public class RestISPublisher extends ISPublisher {
protected ResourceRegistryClient resourceRegistryClient;
protected ResourceRegistryPublisher resourceRegistryPublisher;
public RestISPublisher(ApplicationContext applicationContext) {
super(applicationContext);
this.eServiceUUID = UUID.fromString(applicationContext.id());
@ -57,11 +72,85 @@ public class RestISPublisher extends ISPublisher {
this.resourceRegistryPublisher = ResourceRegistryPublisherFactory.create();
}
protected URI getPluginEndpoint(String pluginName, AccessPointFacet smartExecutorAccessPointFacet) throws Exception {
URI smartExecutorEndpoint = getSmartExecutorEndpoint(smartExecutorAccessPointFacet);
String pluginPath = String.format(RestSmartExecutor.PLUGIN_ENDPOINT_FORMAT,pluginName);
URI pluginEndpoint = new URI(smartExecutorEndpoint + pluginPath);
return pluginEndpoint;
}
protected AccessPointFacet getPluginAccessPointFacet(Plugin plugin, AccessPointFacet smartExecutorAccessPointFacet) throws Exception {
AccessPointFacet accessPointFacet = new AccessPointFacetImpl();
URI pluginEndpoint = getPluginEndpoint(plugin.getName(), smartExecutorAccessPointFacet);
accessPointFacet.setEndpoint(pluginEndpoint);
accessPointFacet.setDescription("The " + plugin.getName() + " smart-executor plugin endpoint");
if(smartExecutorAccessPointFacet!=null) {
accessPointFacet.setAuthorization(smartExecutorAccessPointFacet.getAuthorization());
}
accessPointFacet.setEntryName(plugin.getClass().getName());
return accessPointFacet;
}
protected AccessPointFacet getSmartExecutorAccessPointFacet(EService smartExecutorEService) {
AccessPointFacet smartExecutorAccessPointFacet = null;
List<AccessPointFacet> smartExecutorAccessPointFacets = smartExecutorEService.getFacets(AccessPointFacet.class);
for(AccessPointFacet accessPointFacet : smartExecutorAccessPointFacets) {
if(accessPointFacet.getEntryName().compareTo(ResourceInitializer.class.getName())==0) {
smartExecutorAccessPointFacet = accessPointFacet;
break;
}
}
return smartExecutorAccessPointFacet;
}
protected URI getSmartExecutorEndpoint(AccessPointFacet smartExecutorAccessPointFacet) throws URISyntaxException {
URI smartExecutorEndpoint = null;
if(smartExecutorAccessPointFacet != null) {
smartExecutorEndpoint = smartExecutorAccessPointFacet.getEndpoint();
}else {
// fallback
smartExecutorEndpoint = new URI(getBaseAddress());
}
return smartExecutorEndpoint;
}
/**
* Keep this function aligned with resource-registry-handlers/resource-registry-connector
* @return
*/
private String getBaseAddress() {
ApplicationConfiguration configuration = applicationContext.configuration();
ContainerConfiguration container = applicationContext.container().configuration();
String baseAddress;
if (configuration.proxied()) {
String protocol = configuration.proxyAddress().protocol();
String port = configuration.proxyAddress().port() != null ? ":" + configuration.proxyAddress().port() : "";
baseAddress = String.format("%s://%s%s%s", protocol, configuration.proxyAddress().hostname(), port,
applicationContext.application().getContextPath());
} else {
String protocol = container.protocol();
int port = container.port();
baseAddress = String.format("%s://%s:%d%s", protocol, container.hostname(), port,
applicationContext.application().getContextPath());
}
return baseAddress;
}
@SuppressWarnings("unused")
protected RunningPlugin publishRunningPluginWithRelations(Plugin plugin, UUID pluginUUID) throws Exception {
RunningPlugin runningPlugin = new RunningPluginImpl();
runningPlugin.setHeader(new HeaderImpl(pluginUUID));
runningPlugin.setID(pluginUUID);
SoftwareFacet softwareFacet = new SoftwareFacetImpl();
softwareFacet.setGroup(plugin.getGroup());
@ -72,6 +161,7 @@ public class RestISPublisher extends ISPublisher {
IsIdentifiedBy<Resource, Facet> isIdentifiedBy = new IsIdentifiedByImpl<Resource, Facet>(runningPlugin, softwareFacet);
runningPlugin.addFacet(isIdentifiedBy);
Map<String,String> pluginCapabilities = plugin.getSupportedCapabilities();
if(pluginCapabilities!=null) {
for(String capabilityName : pluginCapabilities.keySet()) {
@ -87,6 +177,26 @@ public class RestISPublisher extends ISPublisher {
usesPropagationConstraint.setAddConstraint(AddConstraint.propagate);
usesPropagationConstraint.setRemoveConstraint(RemoveConstraint.cascade);
AccessPointFacet smartExecutorAccessPointFacet = getSmartExecutorAccessPointFacet(smartExecutorEService);
URI smartExecutorEndpoint = getSmartExecutorEndpoint(smartExecutorAccessPointFacet);
AccessPointFacet accessPointFacet = getPluginAccessPointFacet(plugin, smartExecutorAccessPointFacet);
runningPlugin.addFacet(accessPointFacet);
Date date = Calendar.getInstance().getTime();
StateFacet stateFacet = new StateFacetImpl();
stateFacet.setValue(ApplicationState.active.remoteForm().toLowerCase());
stateFacet.setAdditionalProperty("date", date);
runningPlugin.addFacet(stateFacet);
EventFacet eventFacet = new EventFacetImpl();
eventFacet.setDate(date);
eventFacet.setEvent(stateFacet.getValue());
runningPlugin.addFacet(eventFacet);
Activates<EService, RunningPlugin> activates = new ActivatesImpl<EService, RunningPlugin>(smartExecutorEService, runningPlugin, usesPropagationConstraint);
try {
resourceRegistryPublisher.createIsRelatedTo(activates);
@ -129,8 +239,8 @@ public class RestISPublisher extends ISPublisher {
runningPlugin = publishRunningPluginWithRelations(plugin, pluginUUID);
} catch (AvailableInAnotherContextException e) {
runningPlugin = new RunningPluginImpl();
runningPlugin.setHeader(new HeaderImpl(pluginUUID));
resourceRegistryPublisher.addToCurrentContext(runningPlugin);
runningPlugin.setID(pluginUUID);
resourceRegistryPublisher.addToCurrentContext(runningPlugin, false);
} catch (ResourceRegistryException e) {
throw e;
}

View File

@ -14,11 +14,12 @@ import org.gcube.accounting.persistence.AccountingPersistence;
import org.gcube.accounting.persistence.AccountingPersistenceFactory;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.secret.SecretUtility;
import org.gcube.documentstore.exception.InvalidValueException;
import org.gcube.smartgears.ContextProvider;
import org.gcube.vremanagement.executor.ContextUtility;
import org.gcube.vremanagement.executor.exception.AlreadyInFinalStateException;
import org.gcube.vremanagement.executor.exception.InvalidPluginStateEvolutionException;
import org.gcube.vremanagement.executor.plugin.Plugin;
@ -63,11 +64,6 @@ public class RunnablePlugin<T extends Plugin> implements Runnable {
this.iterationNumber = iterationNumber;
this.pluginStateNotifications = pluginStateNotifications;
this.token = token;
try {
SecurityTokenProvider.instance.set(token);
}catch (Exception e) {
throw new RuntimeException(e);
}
try {
setState(PluginState.CREATED);
} catch (AlreadyInFinalStateException | InvalidPluginStateEvolutionException e) {
@ -79,7 +75,7 @@ public class RunnablePlugin<T extends Plugin> implements Runnable {
@Override
public void run(){
public synchronized void run(){
String pluginName = plugin.getName();
logger.info("{} : {} is going to be launched (UUID={}, iterationNumber={}) with the following inputs {}",
@ -89,9 +85,11 @@ public class RunnablePlugin<T extends Plugin> implements Runnable {
JobUsageRecord jobUsageRecord = new JobUsageRecord();
long startTime = actualStateEvolution.getTimestamp();
Secret secret = SecretUtility.getSecretByTokenString(token);
SecretManager secretManager = SecretManagerProvider.instance.get();
try {
ContextUtility.setContext(token);
secretManager.startSession(secret);
setState(PluginState.RUNNING);
@ -101,10 +99,7 @@ public class RunnablePlugin<T extends Plugin> implements Runnable {
Ref hnRef = runOn.getHostingNode();
jobUsageRecord.setHost(hnRef.getAddress());
ClientInfo clientInfo = ContextUtility.getClientInfo();
String consumerId = clientInfo.getId();
jobUsageRecord.setConsumerId(consumerId);
jobUsageRecord.setConsumerId(secretManager.getUser().getUsername());
try {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
@ -156,7 +151,7 @@ public class RunnablePlugin<T extends Plugin> implements Runnable {
} catch (InvalidValueException e) {
logger.error("Unable to account {}", jobUsageRecord, e);
}
secretManager.endSession();
}
}

View File

@ -0,0 +1,60 @@
package org.gcube.vremanagement.executor.rest;
import java.io.IOException;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.ext.Provider;
import org.gcube.common.authorization.library.provider.AccessTokenProvider;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.GCubeSecret;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Provider
@PreMatching
public class RequestFilter implements ContainerRequestFilter, ContainerResponseFilter {
private final static Logger logger = LoggerFactory.getLogger(RequestFilter.class);
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
logger.trace("PreMatching RequestFilter");
SecretManagerProvider.instance.remove();
SecretManager secretManager = new SecretManager();
String token = AccessTokenProvider.instance.get();
if(token!=null) {
Secret secret = new JWTSecret(token);
secretManager.addSecret(secret);
}
token = SecurityTokenProvider.instance.get();
if(token!=null) {
Secret secret = new GCubeSecret(token);
secretManager.addSecret(secret);
}
SecretManagerProvider.instance.set(secretManager);
}
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
throws IOException {
logger.trace("ResponseFilter");
SecretManagerProvider.instance.remove();
}
}

View File

@ -56,6 +56,9 @@ public class RestSmartExecutor {
protected static final String LOCATION_HEADER = "Location";
public static final String PLUGIN_ENDPOINT_FORMAT = RestConstants.PLUGINS_PATH_PART + "/%s/" + RestConstants.EXECUTIONS_PATH_PART;
public static final String PLUGIN_ENDPOINT = "/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART;
@Context
protected UriInfo uriInfo;
@ -89,7 +92,7 @@ public class RestSmartExecutor {
}
@GET
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART)
@Path(PLUGIN_ENDPOINT)
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String getScheduled(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName) throws ExecutorException {
// setCalledMethod(HttpMethod.GET + " /" + RestConstants.PLUGINS_PATH_PART + "/" + pluginName + "/" + RestConstants.EXECUTIONS_PATH_PART);
@ -151,7 +154,7 @@ public class RestSmartExecutor {
}
@POST
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART)
@Path(PLUGIN_ENDPOINT)
@Consumes({MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8})
@Produces(MediaType.TEXT_PLAIN)
public String launch(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName, String launchParameterString)
@ -189,7 +192,7 @@ public class RestSmartExecutor {
}
@GET
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART + "/" + "{" + UUID_PATH_PARAM + "}")
@Path(PLUGIN_ENDPOINT + "/" + "{" + UUID_PATH_PARAM + "}")
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String getLaunchState(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName,
@PathParam(UUID_PATH_PARAM) String executionIdentifier,
@ -227,7 +230,7 @@ public class RestSmartExecutor {
}
@DELETE
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART + "/" + "{" + UUID_PATH_PARAM + "}")
@Path(PLUGIN_ENDPOINT + "/" + "{" + UUID_PATH_PARAM + "}")
public Response delete(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName,
@PathParam(UUID_PATH_PARAM) String executionIdentifier,
@QueryParam(RestConstants.UNSCHEDULE_PARAM) Boolean unschedule) throws ExecutorException {
@ -291,7 +294,7 @@ public class RestSmartExecutor {
}
@PURGE
@Path("/{" + PLUGIN_NAME_PATH_PARAM + "}/" + RestConstants.EXECUTIONS_PATH_PART + "/" + "{" + UUID_PATH_PARAM + "}")
@Path(PLUGIN_ENDPOINT + "/" + "{" + UUID_PATH_PARAM + "}")
public Response purge(@PathParam(PLUGIN_NAME_PATH_PARAM) String pluginName,
@PathParam(UUID_PATH_PARAM) String executionIdentifier) throws ExecutorException {
return delete(pluginName, executionIdentifier, true);

View File

@ -7,14 +7,15 @@ import java.util.UUID;
import org.gcube.com.fasterxml.jackson.annotation.JsonTypeInfo;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.GCoreEndpoint.Profile.Endpoint;
import org.gcube.common.resources.gcore.HostingNode;
import org.gcube.common.resources.gcore.utils.Group;
import org.gcube.smartgears.Constants;
import org.gcube.smartgears.ContextProvider;
import org.gcube.vremanagement.executor.ContextUtility;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.json.ExtendedSEMapper;
import org.gcube.vremanagement.executor.json.SEMapper;
@ -34,16 +35,18 @@ public class ScheduledTask extends org.gcube.vremanagement.executor.plugin.Sched
protected ScheduledTask() {
}
public ScheduledTask(UUID uuid, LaunchParameter launchParameter) {
public ScheduledTask(UUID uuid, LaunchParameter launchParameter) throws Exception {
this(uuid, launchParameter, generateRunOn());
}
public ScheduledTask(UUID uuid, LaunchParameter launchParameter, RunOn runOn) {
public ScheduledTask(UUID uuid, LaunchParameter launchParameter, RunOn runOn) throws Exception {
this.uuid = uuid;
this.launchParameter = launchParameter;
this.token = SecurityTokenProvider.instance.get();
this.context = ContextUtility.getCurrentContext();
this.clientInfo = ContextUtility.getClientInfo();
SecretManager secretManager = SecretManagerProvider.instance.get();
Secret secret = secretManager.getCurrentSecretHolder().getSecrets().first();
this.token = secret.getToken();
this.context = secretManager.getContext();
this.clientInfo = secret.getClientInfo();
this.runOn = runOn;
}

View File

@ -14,8 +14,11 @@ import org.gcube.vremanagement.executor.plugin.PluginStateNotification;
* This class is useless is just used to simulate and indicate the code
* insertion point the possibility to add multiple notification of an event
* in the running plugin evolution.
* Future use of this possibility are possibility to send an email to
* the job owner, notify a registered process. Send a tweet and so on.
* Future use of this are:
* - send an email to the job owner;
* - notify a registered process;
* - send a tweet;
* - etc
* @author Luca Frosini (ISTI - CNR)
*/
@Deprecated

View File

@ -11,7 +11,9 @@ import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.vremanagement.executor.api.types.LaunchParameter;
import org.gcube.vremanagement.executor.api.types.Scheduling;
import org.gcube.vremanagement.executor.exception.ExecutorException;
@ -106,7 +108,9 @@ public class SmartExecutorScheduler {
jobDataMap.put(SmartExecutorTask.UUID, uuid);
jobDataMap.put(SmartExecutorTask.LAUNCH_PARAMETER, parameter);
String token = SecurityTokenProvider.instance.get();
SecretManager secretManager = SecretManagerProvider.instance.get();
Secret secret = secretManager.getCurrentSecretHolder().getSecrets().first();
String token = secret.getToken();
jobDataMap.put(SmartExecutorTask.TOKEN, token);
@SuppressWarnings("rawtypes")

File diff suppressed because it is too large Load Diff

View File

@ -4,6 +4,14 @@
<servlet>
<servlet-name>org.gcube.vremanagement.executor.ResourceInitializer</servlet-name>
</servlet>
<servlet-mapping>
2 <servlet-name>default</servlet-name>
3 <url-pattern>/docs/*</url-pattern>
4 </servlet-mapping>
<servlet-mapping>
2 <servlet-name>default</servlet-name>
3 <url-pattern>/api-docs/*</url-pattern>
4 </servlet-mapping>
<servlet-mapping>
<servlet-name>org.gcube.vremanagement.executor.ResourceInitializer</servlet-name>
<url-pattern>/*</url-pattern>

View File

@ -0,0 +1,25 @@
.d4science_intro {
top: 0;
z-index: 2000;
position: fixed;
display: block ruby;
padding: 10px;
background: white;
width: 100%;
}
.navbar-fixed-top {
top: 100px !important;
}
.sidebar {
top: 160px !important;
}
.navbar {
margin-bottom: 40px !important;
}
.main {
top: 90px;
}

View File

@ -7,33 +7,24 @@ import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.gcube.common.authorization.client.Constants;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.AuthorizationProvider;
import org.gcube.common.authorization.library.provider.ClientInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.secret.SecretUtility;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*
*/
public class ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ContextTest.class);
protected static Properties properties;
protected static final String PROPERTIES_FILENAME = "token.properties";
public static final String ROOT = "/d4science.research-infrastructures.eu";
public static final String DEFAULT_TEST_SCOPE_NAME;
public static final String ROOT;
public static final String VO;
public static final String VRE;
static {
properties = new Properties();
@ -46,57 +37,50 @@ public class ContextTest {
throw new RuntimeException(e);
}
//DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
DEFAULT_TEST_SCOPE_NAME = "/gcube/devNext/NextNext";
ROOT = "/gcube";
// VO = ROOT + "/devsec";
// VRE = VO + "/devVRE";
VO = ROOT + "/devNext";
VRE = VO + "/NextNext";
}
public static String getCurrentContext(){
String token = SecurityTokenProvider.instance.get();
AuthorizationEntry authorizationEntry;
try {
authorizationEntry = Constants.authorizationService().get(token);
} catch (Exception e) {
logger.trace("Context was not retrieved from token. Going to get it from {}", ScopeProvider.class.getSimpleName());
return ScopeProvider.instance.get();
}
String context = authorizationEntry.getContext();
logger.trace("Context retrieved from token is {}. Context in {} is {}",
context, ScopeProvider.class.getSimpleName(), ScopeProvider.instance.get());
return context;
public static void set(Secret secret) throws Exception {
SecretManagerProvider.instance.reset();
SecretManager secretManager = new SecretManager();
SecretManagerProvider.instance.set(secretManager);
secretManager.addSecret(secret);
secretManager.set();
}
public static String getContext(String token) throws ObjectNotFound, Exception {
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
String context = authorizationEntry.getContext();
logger.info("Context of token {} is {}", token, context);
return context;
public static void setContext(String token) throws Exception {
Secret secret = getSecret(token);
set(secret);
}
public static void setContextByName(String fullContextName) throws Exception {
Secret secret = getSecretByContextName(fullContextName);
set(secret);
}
public static void setContextByName(String fullContextName) throws ObjectNotFound, Exception {
private static Secret getSecret(String token) throws Exception {
Secret secret = SecretUtility.getSecretByTokenString(token);
return secret;
}
private static Secret getSecretByContextName(String fullContextName) throws Exception {
String token = ContextTest.properties.getProperty(fullContextName);
setContext(token);
}
public static void setContext(String token) throws ObjectNotFound, Exception {
SecurityTokenProvider.instance.set(token);
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
ClientInfo clientInfo = authorizationEntry.getClientInfo();
logger.debug("User : {} - Type : {}", clientInfo.getId(), clientInfo.getType().name());
String qualifier = authorizationEntry.getQualifier();
Caller caller = new Caller(clientInfo, qualifier);
AuthorizationProvider.instance.set(caller);
ScopeProvider.instance.set(getContext(token));
return getSecret(token);
}
@BeforeClass
public static void beforeClass() throws Exception {
setContextByName(DEFAULT_TEST_SCOPE_NAME);
setContextByName(ROOT);
}
@AfterClass
public static void afterClass() throws Exception {
SecurityTokenProvider.instance.reset();
ScopeProvider.instance.reset();
SecretManagerProvider.instance.reset();
}
}

View File

@ -63,7 +63,7 @@ public class SerializationTest extends ContextTest {
}
@Test
public void testScheduledTask() throws JsonGenerationException, JsonMappingException, IOException {
public void testScheduledTask() throws Exception {
Map<String,Object> inputs = new HashMap<String,Object>();
inputs.put("Hello", "World");
long sleepTime = 10000;

View File

@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.resources.gcore.Resource;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.informationsystem.publisher.RegistryPublisher;
@ -52,7 +53,7 @@ public class SmartExecutorInizializatorTest {
RegistryPublisher registryPublisher = RegistryPublisherFactory.create();
String id = resource.id();
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, ContextTest.getCurrentContext());
logger.debug("Trying to remove {} with ID {} from {}", resource.getClass().getSimpleName(), id, SecretManagerProvider.instance.get().getContext());
registryPublisher.remove(resource);

View File

@ -0,0 +1,101 @@
package org.gcube.vremanagement.executor.ispublisher;
import java.net.URI;
import java.util.UUID;
import javax.servlet.ServletContext;
import org.gcube.common.events.Hub;
import org.gcube.informationsystem.serialization.ElementMapper;
import org.gcube.resourcemanagement.model.impl.entities.facets.AccessPointFacetImpl;
import org.gcube.resourcemanagement.model.reference.entities.facets.AccessPointFacet;
import org.gcube.smartgears.configuration.application.ApplicationConfiguration;
import org.gcube.smartgears.context.Properties;
import org.gcube.smartgears.context.application.ApplicationContext;
import org.gcube.smartgears.context.container.ContainerContext;
import org.gcube.smartgears.lifecycle.application.ApplicationLifecycle;
import org.gcube.smartgears.persistence.Persistence;
import org.gcube.vremanagement.executor.ContextTest;
import org.gcube.vremanagement.executor.plugin.Plugin;
import org.gcube.vremanagement.helloworld.HelloWorldPlugin;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class RestISPublisherTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(RestISPublisherTest.class);
protected ApplicationContext applicationContext;
public RestISPublisherTest() {
applicationContext = new ApplicationContext() {
@Override
public Properties properties() {
return null;
}
@Override
public <T> T profile(Class<T> type) {
return null;
}
@Override
public Persistence persistence() {
return null;
}
@Override
public String name() {
return "mock";
}
@Override
public ApplicationLifecycle lifecycle() {
return null;
}
@Override
public String id() {
return UUID.randomUUID().toString();
}
@Override
public Hub events() {
return null;
}
@Override
public ContainerContext container() {
return null;
}
@Override
public ApplicationConfiguration configuration() {
return null;
}
@Override
public ServletContext application() {
return null;
}
};
}
@Test
public void testPluginEndpoint() throws Exception {
RestISPublisher restISPublisher = new RestISPublisher(applicationContext);
Plugin plugin = new HelloWorldPlugin();
AccessPointFacet smartExecutorAccessPointFacet = new AccessPointFacetImpl();
smartExecutorAccessPointFacet.setEndpoint(new URI("https://smart-executor.d4science.org/smart-executor"));
AccessPointFacet accessPointFacet = restISPublisher.getPluginAccessPointFacet(plugin, smartExecutorAccessPointFacet);
logger.debug("Plugin URI is {}", ElementMapper.marshal(accessPointFacet));
}
}

View File

@ -48,7 +48,8 @@ public class SmartExecutorPersistenceConnectorTest extends ContextTest {
for(int i=0; i<states.length; i++){
long timestamp = new Date().getTime();
PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, 1, timestamp, HelloWorldPlugin.class.newInstance(), states[i], 0);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
PluginStateEvolution pluginStateEvolution = new PluginStateEvolution(uuid, 1, timestamp, helloWorldPlugin, states[i], 0);
persistenceConnector.pluginStateEvolution(pluginStateEvolution, null);
long startTime = Calendar.getInstance().getTimeInMillis();

View File

@ -7,7 +7,9 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.utils.manager.SecretManager;
import org.gcube.common.authorization.utils.manager.SecretManagerProvider;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.vremanagement.executor.ContextTest;
import org.gcube.vremanagement.executor.exception.InputsNullException;
import org.gcube.vremanagement.executor.exception.InvalidInputsException;
@ -29,6 +31,13 @@ public class RunnablePluginTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(SmartExecutorSchedulerTest.class);
private String getToken() {
SecretManager secretManager = SecretManagerProvider.instance.get();
Secret secret = secretManager.getCurrentSecretHolder().getSecrets().first();
String token = secret.getToken();
return token;
}
@Test
public void launchNullInputsTest() throws Exception {
logger.debug("Testing Null inputs");
@ -39,7 +48,7 @@ public class RunnablePluginTest extends ContextTest {
pluginStateNotifications.add(persistenceConnector);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
try {
RunnablePlugin<HelloWorldPlugin> runnablePlugin = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, null, uuid, 1, pluginStateNotifications, SecurityTokenProvider.instance.get());
RunnablePlugin<HelloWorldPlugin> runnablePlugin = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, null, uuid, 1, pluginStateNotifications, getToken());
runnablePlugin.run();
} catch(Exception e){
Assert.assertEquals(InputsNullException.class, e.getCause().getClass());
@ -56,7 +65,7 @@ public class RunnablePluginTest extends ContextTest {
pluginStateNotifications.add(persistenceConnector);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
RunnablePlugin<HelloWorldPlugin> pt = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications,SecurityTokenProvider.instance.get());
RunnablePlugin<HelloWorldPlugin> pt = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications,getToken());
try {
pt.run();
} catch(RuntimeException e) {
@ -78,7 +87,7 @@ public class RunnablePluginTest extends ContextTest {
List<PluginStateNotification> pluginStateNotifications = new ArrayList<PluginStateNotification>();
pluginStateNotifications.add(persistenceConnector);
HelloWorldPlugin helloWorldPlugin = new HelloWorldPlugin();
RunnablePlugin<HelloWorldPlugin> rp = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications,SecurityTokenProvider.instance.get());
RunnablePlugin<HelloWorldPlugin> rp = new RunnablePlugin<HelloWorldPlugin>(helloWorldPlugin, inputs, uuid, 1, pluginStateNotifications,getToken());
long startTime = Calendar.getInstance().getTimeInMillis();
long endTime = startTime;
while(endTime <= (startTime + 1000)){