Porting accounting-insert-storage-se-plugin to newest libraries
parent
f26c7a4765
commit
8923930570
@ -0,0 +1,3 @@
|
||||
/org.eclipse.core.resources.prefs
|
||||
/org.eclipse.jdt.core.prefs
|
||||
/org.eclipse.m2e.core.prefs
|
@ -0,0 +1,13 @@
|
||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
# Changelog for Accounting Insert Storage Smart Executor Plugin
|
||||
|
||||
|
||||
## [v2.0.0-SNAPSHOT]
|
||||
|
||||
- The plugin has been completely rewrote
|
||||
|
||||
## [v1.0.0]
|
||||
|
||||
- First Release
|
||||
|
@ -0,0 +1,71 @@
|
||||
# Accounting Insert Storage Smart Executor Plugin
|
||||
|
||||
Accounting Insert Storage Smart Executor Plugin
|
||||
|
||||
## Built With
|
||||
|
||||
* [OpenJDK](https://openjdk.java.net/) - The JDK used
|
||||
* [Maven](https://maven.apache.org/) - Dependency Management
|
||||
|
||||
## Documentation
|
||||
|
||||
[Accounting Insert Storage Smart Executor Plugin](https://wiki.gcube-system.org/gcube/Accounting)
|
||||
|
||||
## Change log
|
||||
|
||||
See [Releases](https://code-repo.d4science.org/gCubeSystem/accounting-insert-storage-se-plugin/releases).
|
||||
|
||||
## Authors
|
||||
|
||||
* **Luca Frosini** ([ORCID](https://orcid.org/0000-0003-3183-2291)) - [ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
|
||||
|
||||
## How to Cite this Software
|
||||
|
||||
Tell people how to cite this software.
|
||||
* Cite an associated paper?
|
||||
* Use a specific BibTeX entry for the software?
|
||||
|
||||
|
||||
@Manual{,
|
||||
title = {Accounting Insert Storage Smart Executor Plugin},
|
||||
author = {{Frosini, Luca}},
|
||||
organization = {ISTI - CNR},
|
||||
address = {Pisa, Italy},
|
||||
year = 2021,
|
||||
url = {http://www.gcube-system.org/}
|
||||
}
|
||||
|
||||
## License
|
||||
|
||||
This project is licensed under the EUPL V.1.1 License - see the [LICENSE.md](LICENSE.md) file for details.
|
||||
|
||||
|
||||
## About the gCube Framework
|
||||
This software is part of the [gCubeFramework](https://www.gcube-system.org/ "gCubeFramework"): an
|
||||
open-source software toolkit used for building and operating Hybrid Data
|
||||
Infrastructures enabling the dynamic deployment of Virtual Research Environments
|
||||
by favouring the realisation of reuse oriented policies.
|
||||
|
||||
The projects leading to this software have received funding from a series of European Union programmes including:
|
||||
|
||||
- the Sixth Framework Programme for Research and Technological Development
|
||||
- DILIGENT (grant no. 004260).
|
||||
- the Seventh Framework Programme for research, technological development and demonstration
|
||||
- D4Science (grant no. 212488);
|
||||
- D4Science-II (grant no.239019);
|
||||
- ENVRI (grant no. 283465);
|
||||
- iMarine(grant no. 283644);
|
||||
- EUBrazilOpenBio (grant no. 288754).
|
||||
- the H2020 research and innovation programme
|
||||
- SoBigData (grant no. 654024);
|
||||
- PARTHENOS (grant no. 654119);
|
||||
- EGIEngage (grant no. 654142);
|
||||
- ENVRIplus (grant no. 654182);
|
||||
- BlueBRIDGE (grant no. 675680);
|
||||
- PerformFish (grant no. 727610);
|
||||
- AGINFRAplus (grant no. 731001);
|
||||
- DESIRA (grant no. 818194);
|
||||
- ARIADNEplus (grant no. 823914);
|
||||
- RISIS2 (grant no. 824091);
|
||||
|
||||
|
@ -1,80 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.insert.storage.plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.vremanagement.executor.plugin.Plugin;
|
||||
import org.gcube.vremanagement.executor.plugin.PluginDeclaration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class AccountingInsertStoragePluginDeclaration implements PluginDeclaration {
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingInsertStoragePlugin.class);
|
||||
|
||||
/**
|
||||
* Plugin name used by the Executor to retrieve this class
|
||||
*/
|
||||
public static final String NAME = "Accounting-Insert-Storage";
|
||||
|
||||
public static final String DESCRIPTION = "This plugin is used to insert storage status record";
|
||||
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
public void init() {
|
||||
logger.debug(String.format("%s initialized", AccountingInsertStoragePlugin.class.getSimpleName()));
|
||||
}
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
public String getName() {
|
||||
return NAME;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return DESCRIPTION;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return VERSION;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
public Map<String, String> getSupportedCapabilities() {
|
||||
Map<String, String> discoveredCapabilities = new HashMap<String, String>();
|
||||
return discoveredCapabilities;
|
||||
}
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
public Class<? extends Plugin<? extends PluginDeclaration>> getPluginImplementation() {
|
||||
return AccountingInsertStoragePlugin.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AccountingInsertStoragePluginDeclaration [getName()=" + getName()
|
||||
+ ", getDescription()=" + getDescription() + ", getVersion()="
|
||||
+ getVersion() + ", getSupportedCapabilities()="
|
||||
+ getSupportedCapabilities() + ", getPluginImplementation()="
|
||||
+ getPluginImplementation() + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
package org.gcube.accounting.insert.storage.plugin;
|
||||
|
||||
import com.couchbase.client.java.document.json.JsonArray;
|
||||
import com.couchbase.client.java.document.json.JsonObject;
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class Utility {
|
||||
/**
|
||||
* Generate a key for map-reduce
|
||||
* @param key
|
||||
* @return JsonArray
|
||||
*/
|
||||
protected static JsonArray generateKey(String scope,String key){
|
||||
JsonArray generateKey = JsonArray.create();
|
||||
if (scope!=null){
|
||||
generateKey.add(scope);
|
||||
}
|
||||
for (String value: key.split(",")){
|
||||
if (!value.toString().isEmpty())
|
||||
generateKey.add(Integer.parseInt(value));
|
||||
}
|
||||
return generateKey;
|
||||
|
||||
}
|
||||
/**
|
||||
* Verify a record aggregated for insert into bucket
|
||||
* @param item
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean checkType(Object item) {
|
||||
return item == null
|
||||
|| item instanceof String
|
||||
|| item instanceof Integer
|
||||
|| item instanceof Long
|
||||
|| item instanceof Double
|
||||
|| item instanceof Boolean
|
||||
|| item instanceof JsonObject
|
||||
|| item instanceof JsonArray;
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package org.gcube.accounting.insert.storage.utils;
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
|
||||
public class ConfigurationServiceEndpoint {
|
||||
|
||||
//Static Key for Configuration from service end point
|
||||
public static final String URL_PROPERTY_KEY = "URL";
|
||||
public static final String PASSWORD_PROPERTY_KEY = "password";
|
||||
public static final String BUCKET_NAME_PROPERTY_KEY = "bucketName";
|
||||
|
||||
public static final String BUCKET_STORAGE_NAME_PROPERTY_KEY="AggregatedStorageStatusRecord";
|
||||
public static final String BUCKET_STORAGE_TYPE="StorageStatusRecord";
|
||||
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package org.gcube.accounting.insert.storage.utils;
|
||||
public class Constant {
|
||||
|
||||
|
||||
|
||||
//CONSTANT for generate file and backup
|
||||
public static String user=null;
|
||||
public static String NAME_DIR_BACKUP=".aggregatorPlugin";
|
||||
public static String PATH_DIR_BACKUP="backup";
|
||||
public final static String HOME_SYSTEM_PROPERTY = "user.home";
|
||||
public static String PATH_DIR_BACKUP_INSERT="backup/insert";
|
||||
public static String PATH_DIR_BACKUP_DELETE="backup/delete";
|
||||
|
||||
//create a file for delete record before insert a new aggregate
|
||||
public static final String FILE_RECORD_NO_AGGREGATE="no_aggregated";
|
||||
//create a temporany file for insert a new record aggregate
|
||||
public static final String FILE_RECORD_AGGREGATE="aggregated";
|
||||
|
||||
|
||||
|
||||
public static final Integer CONNECTION_TIMEOUT=15;
|
||||
public static final Integer NUM_RETRY=6;
|
||||
public static final Integer CONNECTION_TIMEOUT_BUCKET=15;
|
||||
public static final Integer VIEW_TIMEOUT_BUCKET=120;
|
||||
public static final Integer MAX_REQUEST_LIFE_TIME=120;
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
package org.gcube.accounting.insert.storage.utils;
|
||||
|
||||
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.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.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class ContextUtility {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(ContextUtility.class);
|
||||
|
||||
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(getCurrentContext());
|
||||
}
|
||||
|
||||
public static String getCurrentContext() {
|
||||
try {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
return Constants.authorizationService().get(token).getContext();
|
||||
} catch(Exception e) {
|
||||
String context = ScopeProvider.instance.get();
|
||||
if(context != null) {
|
||||
return context;
|
||||
}
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static ClientInfo getClientInfo() {
|
||||
try {
|
||||
Caller caller = AuthorizationProvider.instance.get();
|
||||
if(caller != null) {
|
||||
return caller.getClient();
|
||||
} else {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
||||
return authorizationEntry.getClientInfo();
|
||||
}
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static final String GET_USERNAME_ERROR = "Unable to retrieve user";
|
||||
|
||||
public static String getUsername() {
|
||||
try {
|
||||
return getClientInfo().getId();
|
||||
} catch(Exception e) {
|
||||
logger.error(GET_USERNAME_ERROR);
|
||||
throw new RuntimeException(GET_USERNAME_ERROR, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isApplication() {
|
||||
try {
|
||||
ClientInfo clientInfo = getClientInfo();
|
||||
return clientInfo.getType() == ClientType.EXTERNALSERVICE;
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,96 +0,0 @@
|
||||
package org.gcube.accounting.insert.storage.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* Retrieves the list user form the base url of the social-networking service in
|
||||
* the scope provided
|
||||
*
|
||||
* @author Alessandro Pieve at ISTI-CNR (alessandro.pieve@isti.cnr.it)
|
||||
*/
|
||||
public class DiscoveryListUser {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(DiscoveryListUser.class);
|
||||
|
||||
private List<String> listUser = null;
|
||||
|
||||
public DiscoveryListUser(String context, String urlService) {
|
||||
|
||||
try {
|
||||
String token = SecurityTokenProvider.instance.get();
|
||||
DiscoveryServiceListUser discoveryList = new DiscoveryServiceListUser(context);
|
||||
if (urlService == null) {
|
||||
urlService = discoveryList.getBasePath() + "=" + token;
|
||||
}
|
||||
log.debug("service DiscoveryServiceListUser:" + urlService);
|
||||
log.debug("scope:{} ,tokend:{}", context, token);
|
||||
String data = getJSON(urlService);
|
||||
log.debug("data read:{}", data);
|
||||
ListUser msg = new Gson().fromJson(data, ListUser.class);
|
||||
// TODO for debug limit a list user:
|
||||
listUser = msg.getResult();
|
||||
} catch (Exception ex) {
|
||||
log.error("DiscoveryListUserException:{}", ex);
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> getListUser() {
|
||||
return listUser;
|
||||
}
|
||||
|
||||
public String getJSON(String url) {
|
||||
HttpURLConnection c = null;
|
||||
try {
|
||||
URL u = new URL(url);
|
||||
c = (HttpURLConnection) u.openConnection();
|
||||
c.setRequestMethod("GET");
|
||||
c.setRequestProperty("Content-length", "0");
|
||||
HttpURLConnection.setFollowRedirects(true);
|
||||
c.setUseCaches(false);
|
||||
c.setAllowUserInteraction(false);
|
||||
c.connect();
|
||||
int status = c.getResponseCode();
|
||||
log.debug("status:{}", status);
|
||||
switch (status) {
|
||||
case 200:
|
||||
case 201:
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(c.getInputStream()));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
br.close();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
} catch (MalformedURLException ex) {
|
||||
log.error("MalformedURLException:{}", ex);
|
||||
|
||||
} catch (IOException ex) {
|
||||
log.error("IOException:{}", ex);
|
||||
} finally {
|
||||
if (c != null) {
|
||||
try {
|
||||
c.disconnect();
|
||||
} catch (Exception ex) {
|
||||
log.error("Exception:{}", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,104 +0,0 @@
|
||||
package org.gcube.accounting.insert.storage.utils;
|
||||
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the base url of the social-networking service in the scope provided
|
||||
* @author Costantino Perciante at ISTI-CNR
|
||||
* (costantino.perciante@isti.cnr.it)
|
||||
*/
|
||||
public class DiscoveryServiceListUser {
|
||||
|
||||
private String basePath = null;
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(DiscoveryServiceListUser.class);
|
||||
private final static String RUNTIME_RESOURCE_NAME = "SocialNetworking";
|
||||
private final static String CATEGORY = "Portal";
|
||||
private final static String NAME_SERVICE = "2/users/get-all-usernames?gcube-token";
|
||||
|
||||
public DiscoveryServiceListUser(String context){
|
||||
|
||||
if(context == null || context.isEmpty())
|
||||
throw new IllegalArgumentException("A valid context is needed to discover the service");
|
||||
|
||||
|
||||
String oldContext = ScopeProvider.instance.get();
|
||||
ScopeProvider.instance.set(context);
|
||||
|
||||
try{
|
||||
|
||||
List<ServiceEndpoint> resources = getConfigurationFromIS();
|
||||
if (resources.size() == 0){
|
||||
logger.error("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Category " + CATEGORY + " in this scope.");
|
||||
throw new Exception("There is no Runtime Resource having name " + RUNTIME_RESOURCE_NAME +" and Category " + CATEGORY + " in this scope.");
|
||||
}
|
||||
else {
|
||||
|
||||
for (ServiceEndpoint res : resources) {
|
||||
|
||||
Iterator<AccessPoint> accessPointIterator = res.profile().accessPoints().iterator();
|
||||
|
||||
while (accessPointIterator.hasNext()) {
|
||||
ServiceEndpoint.AccessPoint accessPoint = (ServiceEndpoint.AccessPoint) accessPointIterator
|
||||
.next();
|
||||
// get base path
|
||||
basePath = accessPoint.address();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}catch(Exception e){
|
||||
|
||||
logger.error("Unable to retrieve such service endpoint information!", e);
|
||||
|
||||
}finally{
|
||||
|
||||
if(oldContext != null && !oldContext.equals(context))
|
||||
ScopeProvider.instance.set(oldContext);
|
||||
|
||||
}
|
||||
|
||||
logger.info("Found base path " + basePath + " for the service");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve endpoints information from IS for DB
|
||||
* @return list of endpoints for ckan database
|
||||
* @throws Exception
|
||||
*/
|
||||
private List<ServiceEndpoint> getConfigurationFromIS() throws Exception{
|
||||
|
||||
SimpleQuery query = queryFor(ServiceEndpoint.class);
|
||||
query.addCondition("$resource/Profile/Name/text() eq '"+ RUNTIME_RESOURCE_NAME +"'");
|
||||
query.addCondition("$resource/Profile/Category/text() eq '"+ CATEGORY +"'");
|
||||
DiscoveryClient<ServiceEndpoint> client = clientFor(ServiceEndpoint.class);
|
||||
List<ServiceEndpoint> toReturn = client.submit(query);
|
||||
return toReturn;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base path of the social networking service
|
||||
* @return the base path
|
||||
*/
|
||||
public String getBasePath() {
|
||||
return basePath+NAME_SERVICE;
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package org.gcube.accounting.insert.storage.utils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
|
||||
import javax.ws.rs.WebApplicationException;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class HTTPUtility {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(HTTPUtility.class);
|
||||
|
||||
public static StringBuilder getStringBuilder(InputStream inputStream) throws IOException {
|
||||
StringBuilder result = new StringBuilder();
|
||||
try(BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
|
||||
String line;
|
||||
while((line = reader.readLine()) != null) {
|
||||
result.append(line);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static String getResultAsString(HttpURLConnection httpURLConnection) throws IOException {
|
||||
int responseCode = httpURLConnection.getResponseCode();
|
||||
if(responseCode >= Status.BAD_REQUEST.getStatusCode()) {
|
||||
Status status = Status.fromStatusCode(responseCode);
|
||||
InputStream inputStream = httpURLConnection.getErrorStream();
|
||||
StringBuilder result = getStringBuilder(inputStream);
|
||||
logger.trace(result.toString());
|
||||
throw new WebApplicationException(result.toString(), status);
|
||||
}
|
||||
InputStream inputStream = httpURLConnection.getInputStream();
|
||||
String ret = getStringBuilder(inputStream).toString();
|
||||
logger.trace("Got Respose is {}", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
package org.gcube.accounting.insert.storage.utils;
|
||||
|
||||
import java.util.List;
|
||||
/**
|
||||
*
|
||||
* @author pieve
|
||||
*
|
||||
*/
|
||||
public class ListUser {
|
||||
/*
|
||||
"success" : false,
|
||||
"message" : "String index out of range: 5",
|
||||
"result" : null
|
||||
*/
|
||||
private Boolean success;
|
||||
private String message;
|
||||
private List<String> result;
|
||||
public Boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
public void setSuccess(Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
public List<String> getResult() {
|
||||
return result;
|
||||
}
|
||||
public void setResult(List<String> result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,94 @@
|
||||
package org.gcube.accounting.insert.storage.utils;
|
||||
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.client;
|
||||
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||
import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Discover the Social Networking Service in the Infrastructure.
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class SocialService {
|
||||
|
||||
private static final String RESOURCE = "jersey-servlet";
|
||||
private static final String SERVICE_NAME = "SocialNetworking";
|
||||
private static final String SERVICE_CLASSE = "Portal";
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(SocialService.class);
|
||||
private String serviceBasePath;
|
||||
|
||||
// Map<String contextFullName, SocialService socialService>
|
||||
private static Map<String,SocialService> socialServicePerContext;
|
||||
|
||||
static {
|
||||
socialServicePerContext = new HashMap<>();
|
||||
}
|
||||
|
||||
public static SocialService getSocialService() throws Exception {
|
||||
String contex = ContextUtility.getCurrentContext();
|
||||
SocialService socialService = socialServicePerContext.get(contex);
|
||||
if(socialService == null) {
|
||||
socialService = new SocialService();
|
||||
socialServicePerContext.put(contex, socialService);
|
||||
}
|
||||
return socialService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Discover the gcore endpoint for the social networking service.
|
||||
* @throws Exception the exception
|
||||
*/
|
||||
private SocialService() throws Exception {
|
||||
getServiceBasePathViaGCoreEndpoint();
|
||||
}
|
||||
|
||||
protected void getServiceBasePathViaGCoreEndpoint() throws Exception {
|
||||
try {
|
||||
SimpleQuery query = queryFor(GCoreEndpoint.class);
|
||||
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'", SERVICE_CLASSE));
|
||||
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
|
||||
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'", SERVICE_NAME));
|
||||
query.setResult(
|
||||
"$resource/Profile/AccessPoint/RunningInstanceInterfaces//Endpoint[@EntryName/string() eq \""
|
||||
+ RESOURCE + "\"]/text()");
|
||||
|
||||
DiscoveryClient<String> client = client();
|
||||
List<String> endpoints = client.submit(query);
|
||||
if(endpoints == null || endpoints.isEmpty()) {
|
||||
throw new Exception("Cannot retrieve the GCoreEndpoint SERVICE_NAME: " + SERVICE_NAME
|
||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + ContextUtility.getCurrentContext());
|
||||
}
|
||||
|
||||
this.serviceBasePath = endpoints.get(0);
|
||||
|
||||
if(serviceBasePath == null)
|
||||
throw new Exception("Endpoint:" + RESOURCE + ", is null for SERVICE_NAME: " + SERVICE_NAME
|
||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + ContextUtility.getCurrentContext());
|
||||
|
||||
serviceBasePath = serviceBasePath.endsWith("/") ? serviceBasePath : serviceBasePath + "/";
|
||||
|
||||
} catch(Exception e) {
|
||||
String error = "An error occurred during GCoreEndpoint discovery, SERVICE_NAME: " + SERVICE_NAME
|
||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + ContextUtility.getCurrentContext() + ".";
|
||||
logger.error(error, e);
|
||||
throw new Exception(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the base path of the service
|
||||
*/
|
||||
public String getServiceBasePath() {
|
||||
return serviceBasePath;
|
||||
}
|
||||
|
||||
}
|
@ -1 +1 @@
|
||||
org.gcube.accounting.insert.storage.plugin.AccountingInsertStoragePluginDeclaration
|
||||
org.gcube.accounting.insert.storage.plugin.AccountingInsertStoragePlugin
|
@ -0,0 +1,103 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.insert.storage.plugin;
|
||||
|
||||
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.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 PARENT_DEFAULT_TEST_SCOPE;
|
||||
public static final String DEFAULT_TEST_SCOPE;
|
||||
public static final String ALTERNATIVE_TEST_SCOPE;
|
||||
|
||||
public static final String DEFAULT_TEST_SCOPE_ANOTHER_USER;
|
||||
|
||||
static {
|
||||
properties = new Properties();
|
||||
InputStream input = ContextTest.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME);
|
||||
|
||||
try {
|
||||
// load the properties file
|
||||
properties.load(input);
|
||||
} catch(IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
// PARENT_DEFAULT_TEST_SCOPE = "/pred4s"
|
||||
// DEFAULT_TEST_SCOPE_NAME = PARENT_DEFAULT_TEST_SCOPE + "/preprod";
|
||||
// ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE_NAME + "/preVRE";
|
||||
|
||||
|
||||
PARENT_DEFAULT_TEST_SCOPE = "/gcube";
|
||||
DEFAULT_TEST_SCOPE = PARENT_DEFAULT_TEST_SCOPE + "/devNext";
|
||||
ALTERNATIVE_TEST_SCOPE = DEFAULT_TEST_SCOPE + "/NextNext";
|
||||
|
||||
DEFAULT_TEST_SCOPE_ANOTHER_USER = "lucio.lelii_" + DEFAULT_TEST_SCOPE;
|
||||
|
||||
try {
|
||||
setContextByName(DEFAULT_TEST_SCOPE);
|
||||
} catch(Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getCurrentScope(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 setContextByName(String fullContextName) throws ObjectNotFound, Exception {
|
||||
String token = ContextTest.properties.getProperty(fullContextName);
|
||||
setContext(token);
|
||||
}
|
||||
|
||||
private 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(getCurrentScope(token));
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
setContextByName(DEFAULT_TEST_SCOPE);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
SecurityTokenProvider.instance.reset();
|
||||
ScopeProvider.instance.reset();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,2 @@
|
||||
*.gcubekey
|
||||
/token.properties
|
@ -0,0 +1,4 @@
|
||||
groupId=org.gcube.accounting
|
||||
artifactId=accounting-insert-storage-se-plugin
|
||||
version=2.0.0-SNAPSHOT
|
||||
description=Accounting Insert Storage Smart Executor Plugin
|
@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE xml>
|
||||
<configuration>
|
||||
|
||||
<appender name="STDOUT"
|
||||
class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{0}: %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.gcube" level="ERROR" />
|
||||
<!-- logger name="org.gcube.documentstore" level="INFO" / -->
|
||||
<!-- logger name="org.gcube.accounting" level="TRACE" / -->
|
||||
<!-- logger name="org.gcube.accounting.datamodel.validations.validators.Harmonizer" level="ERROR" /-->
|
||||
<logger name="org.gcube.accounting.datamodel.aggregation" level="TRACE" />
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="STDOUT" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
@ -0,0 +1,24 @@
|
||||
<assembly
|
||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||
<id>uberjar</id>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<baseDirectory>${file.separator}</baseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>target${file.separator}libs</directory>
|
||||
<outputDirectory>${file.separator}</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<fileMode>755</fileMode>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>target${file.separator}classes</directory>
|
||||
<outputDirectory>${file.separator}</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<fileMode>755</fileMode>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
Loading…
Reference in New Issue