git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-insert-storage-se-plugin@142393 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
commit
f9f5f572f4
|
@ -0,0 +1,36 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="target/classes" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
|
||||
<attributes>
|
||||
<attribute name="optional" value="true"/>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="output" path="target/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,23 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>accounting-insert-storage-se-plugin</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.m2e.core.maven2Builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,6 @@
|
|||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/main/resources=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
encoding//src/test/resources=UTF-8
|
||||
encoding/<project>=UTF-8
|
|
@ -0,0 +1,5 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.7
|
|
@ -0,0 +1,4 @@
|
|||
activeProfiles=
|
||||
eclipse.preferences.version=1
|
||||
resolveWorkspaceProjects=true
|
||||
version=1
|
|
@ -0,0 +1,4 @@
|
|||
gCube System - License
|
||||
------------------------------------------------------------
|
||||
|
||||
${gcube.license}
|
|
@ -0,0 +1,65 @@
|
|||
The gCube System - ${name}
|
||||
--------------------------------------------------
|
||||
|
||||
${description}
|
||||
|
||||
|
||||
${gcube.description}
|
||||
|
||||
${gcube.funding}
|
||||
|
||||
|
||||
Version
|
||||
--------------------------------------------------
|
||||
|
||||
${version} (${buildDate})
|
||||
|
||||
Please see the file named "changelog.xml" in this directory for the release notes.
|
||||
|
||||
|
||||
Authors
|
||||
--------------------------------------------------
|
||||
|
||||
* Alessandro Pieve (alessandro.pieve-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
|
||||
|
||||
Maintainers
|
||||
-----------
|
||||
|
||||
* Alessandro Pieve (alessandro.pieve-AT-isti.cnr.it), Istituto di Scienza e Tecnologie dell'Informazione "A. Faedo" - CNR, Pisa (Italy).
|
||||
|
||||
|
||||
Download information
|
||||
--------------------------------------------------
|
||||
|
||||
Source code is available from SVN:
|
||||
${scm.url}
|
||||
|
||||
Binaries can be downloaded from the gCube website:
|
||||
${gcube.website}
|
||||
|
||||
|
||||
Installation
|
||||
--------------------------------------------------
|
||||
|
||||
Installation documentation is available on-line in the gCube Wiki:
|
||||
${gcube.wikiRoot}/SmartExecutor
|
||||
|
||||
|
||||
Documentation
|
||||
--------------------------------------------------
|
||||
|
||||
Documentation is available on-line in the gCube Wiki:
|
||||
${gcube.wikiRoot}/SmartExecutor
|
||||
|
||||
|
||||
Support
|
||||
--------------------------------------------------
|
||||
|
||||
Bugs and support requests can be reported in the gCube issue tracking tool:
|
||||
${gcube.issueTracking}
|
||||
|
||||
|
||||
Licensing
|
||||
--------------------------------------------------
|
||||
|
||||
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.
|
|
@ -0,0 +1,5 @@
|
|||
<ReleaseNotes>
|
||||
<Changeset component="org.gcube.accounting.accounting-insert-storage-se-plugin.1.0.0" date="${buildDate}">
|
||||
<Change>First Release</Change>
|
||||
</Changeset>
|
||||
</ReleaseNotes>
|
|
@ -0,0 +1,31 @@
|
|||
<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>servicearchive</id>
|
||||
<formats>
|
||||
<format>tar.gz</format>
|
||||
</formats>
|
||||
<baseDirectory>/</baseDirectory>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${distroDirectory}</directory>
|
||||
<outputDirectory>/</outputDirectory>
|
||||
<useDefaultExcludes>true</useDefaultExcludes>
|
||||
<includes>
|
||||
<include>README</include>
|
||||
<include>LICENSE</include>
|
||||
<include>changelog.xml</include>
|
||||
<include>profile.xml</include>
|
||||
</includes>
|
||||
<fileMode>755</fileMode>
|
||||
<filtered>true</filtered>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
<source>target/${build.finalName}.jar</source>
|
||||
<outputDirectory>/${artifactId}</outputDirectory>
|
||||
</file>
|
||||
</files>
|
||||
</assembly>
|
|
@ -0,0 +1,27 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Resource>
|
||||
<ID />
|
||||
<Type>Plugin</Type>
|
||||
<Profile>
|
||||
<Description>{description}</Description>
|
||||
<Class>${serviceClass}</Class>
|
||||
<Name>${artifactId}</Name>
|
||||
<Version>1.0.0</Version>
|
||||
<Packages>
|
||||
<Software>
|
||||
<Description>{description}</Description>
|
||||
<Name>${artifactId}</Name>
|
||||
<Version>${version}</Version>
|
||||
<MavenCoordinates>
|
||||
<groupId>${groupId}</groupId>
|
||||
<artifactId>${artifactId}</artifactId>
|
||||
<version>${version}</version>
|
||||
</MavenCoordinates>
|
||||
<Type>Plugin</Type>
|
||||
<Files>
|
||||
<File>${build.finalName}.jar</File>
|
||||
</Files>
|
||||
</Software>
|
||||
</Packages>
|
||||
</Profile>
|
||||
</Resource>
|
|
@ -0,0 +1,180 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.gcube.tools</groupId>
|
||||
<artifactId>maven-parent</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-insert-storage</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>Accounting Insert Storage</name>
|
||||
<description>Accounting Insert Storage</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<distroDirectory>distro</distroDirectory>
|
||||
<serviceClass>Accounting</serviceClass>
|
||||
</properties>
|
||||
|
||||
<scm>
|
||||
<connection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId}</connection>
|
||||
<developerConnection>scm:https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId}</developerConnection>
|
||||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId}</url>
|
||||
</scm>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.distribution</groupId>
|
||||
<artifactId>maven-smartgears-bom</artifactId>
|
||||
<version>LATEST</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.gcube.vremanagement</groupId>
|
||||
<artifactId>smart-executor-api</artifactId>
|
||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-scope</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Home Library -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library-jcr</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>home-library</artifactId>
|
||||
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- END Home Library -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>common-authorization</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.common</groupId>
|
||||
<artifactId>authorization-client</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- CouchBase libraries -->
|
||||
<dependency>
|
||||
<groupId>com.couchbase.client</groupId>
|
||||
<artifactId>java-client</artifactId>
|
||||
<version>2.2.3</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.couchbase.client</groupId>
|
||||
<artifactId>core-io</artifactId>
|
||||
<version>[1.2.3,2.0.0)</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<!-- END CouchBase libraries -->
|
||||
<!-- Document Store and accounting lib -->
|
||||
<dependency>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib-couchbase</artifactId>
|
||||
<version>[1.0.1-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<artifactId>document-store-lib</artifactId>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-lib</artifactId>
|
||||
<version>[2.2.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>2.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-wrapper</artifactId>
|
||||
<version>[2.0.2-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.contentmanagement</groupId>
|
||||
<artifactId>storage-manager-core</artifactId>
|
||||
<version>[2.2.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.0.13</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<configuration>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
|
@ -0,0 +1,17 @@
|
|||
package org.gcube.accounting.insert.storage.persistence;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public interface AggregatorPersistenceBackendQuery {
|
||||
|
||||
public static final int KEY_VALUES_LIMIT = 25;
|
||||
|
||||
public void prepareConnection(
|
||||
AggregatorPersistenceBackendQueryConfiguration configuration)
|
||||
throws Exception;
|
||||
|
||||
}
|
|
@ -0,0 +1,30 @@
|
|||
package org.gcube.accounting.insert.storage.persistence;
|
||||
|
||||
|
||||
import org.gcube.accounting.persistence.AccountingPersistenceConfiguration;
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class AggregatorPersistenceBackendQueryConfiguration extends AccountingPersistenceConfiguration {
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
*/
|
||||
public AggregatorPersistenceBackendQueryConfiguration(){
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class1 The class of the persistence to instantiate
|
||||
* @throws Exception if fails
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
public AggregatorPersistenceBackendQueryConfiguration(Class<?> persistence) throws Exception{
|
||||
super((Class) persistence);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,178 @@
|
|||
package org.gcube.accounting.insert.storage.plugin;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.accounting.insert.storage.persistence.AggregatorPersistenceBackendQueryConfiguration;
|
||||
import org.gcube.accounting.insert.storage.utils.ConfigurationServiceEndpoint;
|
||||
import org.gcube.accounting.insert.storage.utils.Constant;
|
||||
import org.gcube.accounting.insert.storage.utils.DiscoveryListUser;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.gcube.contentmanagement.blobstorage.service.IClient;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.AccessType;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.MemoryType;
|
||||
import org.gcube.contentmanager.storageclient.wrapper.StorageClient;
|
||||
import org.gcube.documentstore.persistence.PersistenceCouchBase;
|
||||
import org.gcube.vremanagement.executor.plugin.Plugin;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.couchbase.client.java.Bucket;
|
||||
import com.couchbase.client.java.Cluster;
|
||||
import com.couchbase.client.java.CouchbaseCluster;
|
||||
import com.couchbase.client.java.document.JsonDocument;
|
||||
import com.couchbase.client.java.document.json.JsonObject;
|
||||
import com.couchbase.client.java.env.CouchbaseEnvironment;
|
||||
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Alessandro Pieve (ISTI - CNR)
|
||||
*
|
||||
*/
|
||||
public class AccountingInsertStoragePlugin extends Plugin<AccountingInsertStoragePluginDeclaration> {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingInsertStoragePlugin.class);
|
||||
|
||||
public AccountingInsertStoragePlugin(AccountingInsertStoragePluginDeclaration pluginDeclaration) {
|
||||
super(pluginDeclaration);
|
||||
}
|
||||
|
||||
/* The environment configuration */
|
||||
protected static final CouchbaseEnvironment ENV =
|
||||
DefaultCouchbaseEnvironment.builder()
|
||||
.connectTimeout(Constant.CONNECTION_TIMEOUT * 1000)
|
||||
.maxRequestLifetime(Constant.MAX_REQUEST_LIFE_TIME * 1000)
|
||||
.queryTimeout(Constant.CONNECTION_TIMEOUT * 1000) //15 Seconds in milliseconds
|
||||
.viewTimeout(Constant.VIEW_TIMEOUT_BUCKET * 1000)//120 Seconds in milliseconds
|
||||
.keepAliveInterval(3600 * 1000) // 3600 Seconds in milliseconds
|
||||
.kvTimeout(5000) //in ms
|
||||
.build();
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
public void launch(Map<String, Object> inputs) throws Exception {
|
||||
|
||||
String context=ScopeProvider.instance.get();
|
||||
logger.debug("launch on context:{}",context);
|
||||
String url=null;
|
||||
String password =null;
|
||||
String bucket=null;
|
||||
AggregatorPersistenceBackendQueryConfiguration configuration;
|
||||
try{
|
||||
configuration = new AggregatorPersistenceBackendQueryConfiguration(PersistenceCouchBase.class);
|
||||
url = configuration.getProperty(ConfigurationServiceEndpoint.URL_PROPERTY_KEY);
|
||||
password = configuration.getProperty(ConfigurationServiceEndpoint.PASSWORD_PROPERTY_KEY);
|
||||
bucket=configuration.getProperty(ConfigurationServiceEndpoint.BUCKET_STORAGE_NAME_PROPERTY_KEY);
|
||||
|
||||
}
|
||||
catch (Exception e) {
|
||||
logger.error("launch",e.getLocalizedMessage());
|
||||
throw e;
|
||||
}
|
||||
Cluster cluster = CouchbaseCluster.create(ENV, url);
|
||||
Bucket accountingBucket = cluster.openBucket(bucket,password);
|
||||
|
||||
String urlService=null;
|
||||
if (inputs.containsKey("urlService"))
|
||||
urlService=(String) inputs.get("urlService");
|
||||
|
||||
String dataServiceClass="content-management";
|
||||
if (inputs.containsKey("dataServiceClass"))
|
||||
dataServiceClass=(String) inputs.get("dataServiceClass");
|
||||
|
||||
String dataServiceName="storage-manager";
|
||||
if (inputs.containsKey("dataServiceName"))
|
||||
dataServiceName=(String) inputs.get("dataServiceName");
|
||||
|
||||
String dataServiceId="identifier";
|
||||
if (inputs.containsKey("dataServiceId"))
|
||||
dataServiceId=(String) inputs.get("dataServiceId");
|
||||
|
||||
String uri="MongoDb";
|
||||
if (inputs.containsKey("uri"))
|
||||
uri=(String) inputs.get("uri");
|
||||
|
||||
String dataType="STORAGE";
|
||||
if (inputs.containsKey("dataType"))
|
||||
dataType=(String) inputs.get("dataType");
|
||||
|
||||
Integer timeWait=1000;
|
||||
if (inputs.containsKey("timeWait"))
|
||||
timeWait=(Integer) inputs.get("timeWait");
|
||||
|
||||
DiscoveryListUser discoveryListUser= new DiscoveryListUser(context,urlService);
|
||||
//list user
|
||||
JsonDocument document=null;
|
||||
JsonObject content=null;
|
||||
for (String consumerId:discoveryListUser.getListUser()){
|
||||
//for each user call homelibrary and insert
|
||||
IClient client=new StorageClient("", "", consumerId, AccessType.PUBLIC, MemoryType.PERSISTENT).getClient();
|
||||
try{
|
||||
String docId=UUID.randomUUID().toString();
|
||||
|
||||
Long dataVolume= Long.parseLong(client.getTotalUserVolume());
|
||||
Long dataCount=Long.parseLong(client.getUserTotalItems());
|
||||
Long timeStamp= System.currentTimeMillis();
|
||||
|
||||
content = JsonObject.empty().put("scope", context);
|
||||
content.put("operationCount", 1);
|
||||
content.put("dataCount", dataCount);
|
||||
content.put("endTime", timeStamp);
|
||||
content.put("consumerId", consumerId);
|
||||
content.put("startTime", timeStamp);
|
||||
content.put("id", docId);
|
||||
content.put("dataVolume", dataVolume);
|
||||
content.put("dataType", dataType);
|
||||
content.put("operationResult", "SUCCESS");
|
||||
content.put("dataServiceClass", dataServiceClass);
|
||||
content.put("dataServiceName", dataServiceName);
|
||||
content.put("dataServiceId", dataServiceId);
|
||||
content.put("aggregated", true);
|
||||
content.put("providerId", uri);
|
||||
content.put("creationTime", timeStamp);
|
||||
content.put("recordType", "StorageStatusRecord");
|
||||
document = JsonDocument.create("docId", content);
|
||||
|
||||
JsonDocument doc = JsonDocument.create(docId, content);
|
||||
|
||||
JsonDocument response = accountingBucket.upsert(doc);
|
||||
logger.debug("upsert doc:{}",doc.toString());
|
||||
Thread.sleep(timeWait);
|
||||
|
||||
|
||||
}
|
||||
catch(Exception e){
|
||||
logger.error("doc:{} not insert ({}), problem with exist bucket",document.id(),document.toString(),e);
|
||||
logger.error("force insert into list for insert");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
cluster.disconnect();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
protected void onStop() throws Exception {
|
||||
logger.trace("{} onStop() function", this.getClass().getSimpleName());
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
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() + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
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
|
||||
*/
|
||||
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
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
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";
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
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,106 @@
|
|||
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.ArrayList;
|
||||
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 ;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base path of the social networking service
|
||||
* @return
|
||||
*/
|
||||
public List<String> getListUser() {
|
||||
return listUser;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param url
|
||||
* @return String response content
|
||||
*/
|
||||
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");
|
||||
c.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;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,104 @@
|
|||
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
|
||||
*/
|
||||
public String getBasePath() {
|
||||
return basePath+NAME_SERVICE;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
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 @@
|
|||
org.gcube.accounting.insert.storage.plugin.AccountingInsertStoragePluginDeclaration
|
|
@ -0,0 +1,58 @@
|
|||
package org.gcube.accounting.insert.storage.plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.insert.storage.plugin.AccountingInsertStoragePlugin;
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
public class Tests {
|
||||
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
private static Logger logger = LoggerFactory.getLogger(Tests.class);
|
||||
|
||||
@Before
|
||||
public void beforeTest(){
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLaunch() throws Exception {
|
||||
|
||||
//SecurityTokenProvider.instance.set("36501a0d-a205-4bf1-87ad-4c7185faa0d6-98187548");
|
||||
SecurityTokenProvider.instance.set("3acdde42-6883-4564-b3ba-69f6486f6fe0-98187548");
|
||||
//FOR DEBUG
|
||||
String scopeDebug="/gcube";
|
||||
ScopeProvider.instance.set(scopeDebug);
|
||||
// END FOR DEBUG
|
||||
|
||||
Map<String, Object> inputs = new HashMap<String, Object>();
|
||||
//type aggregation
|
||||
|
||||
/*optional*/
|
||||
//inputs.put("urlService","http://socialnetworking-d-d4s.d4science.org/social-networking-library-ws/rest/");
|
||||
inputs.put("dataServiceClass","contenta-management");
|
||||
inputs.put("dataServiceName","storagea-manager");
|
||||
inputs.put("dataServiceId","identifiera");
|
||||
inputs.put("uri","MongoDba");
|
||||
inputs.put("dataType","STORAGEa");
|
||||
|
||||
|
||||
AccountingInsertStoragePlugin plugin = new AccountingInsertStoragePlugin(null);
|
||||
plugin.launch(inputs);
|
||||
logger.debug("-------------- launch test finished");
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void after(){
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue