first release
git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-insert-rstudio-se-plugin@147148 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
commit
50d40af0ad
|
@ -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-rstudio-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
|
Binary file not shown.
|
@ -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-rstudio-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,164 @@
|
|||
<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-rstudio-se-plugin</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<name>Accounting Insert RStudio</name>
|
||||
<description>Accounting Insert RStudio</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>
|
||||
|
||||
|
||||
<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>
|
||||
<groupId>org.gcube.data.publishing</groupId>
|
||||
<artifactId>document-store-lib</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.gcube.accounting</groupId>
|
||||
<artifactId>accounting-lib</artifactId>
|
||||
<scope>provided</scope>
|
||||
</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>
|
||||
<dependency>
|
||||
<groupId>org.gcube.core</groupId>
|
||||
<artifactId>common-encryption</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.gcube.vremanagement</groupId>
|
||||
<artifactId>smart-executor-client</artifactId>
|
||||
<version>1.3.0-4.1.0-132087</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.rstudio.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.rstudio.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,210 @@
|
|||
package org.gcube.accounting.insert.rstudio.plugin;
|
||||
|
||||
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.gcube.accounting.insert.rstudio.persistence.AggregatorPersistenceBackendQueryConfiguration;
|
||||
import org.gcube.accounting.insert.rstudio.utils.ConfigurationServiceEndpoint;
|
||||
import org.gcube.accounting.insert.rstudio.utils.Constant;
|
||||
import org.gcube.common.scope.api.ScopeProvider;
|
||||
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 AccountingInsertRstudioPlugin extends Plugin<AccountingInsertRstudioPluginDeclaration> {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingInsertRstudioPlugin.class);
|
||||
|
||||
|
||||
|
||||
public AccountingInsertRstudioPlugin(AccountingInsertRstudioPluginDeclaration 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("AccountingInsertRstudioPlugin 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("AccountingInsertRstudioPlugin launch",e.getLocalizedMessage());
|
||||
throw e;
|
||||
}
|
||||
|
||||
logger.debug("AccountingInsertRstudioPlugin open cluster:{}",context);
|
||||
Cluster cluster = CouchbaseCluster.create(ENV, url);
|
||||
Bucket accountingBucket = cluster.openBucket(bucket,password);
|
||||
|
||||
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="";
|
||||
|
||||
String uri="RStudio";
|
||||
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");
|
||||
|
||||
String pathFile=null;
|
||||
if (inputs.containsKey("pathFile"))
|
||||
pathFile=(String) inputs.get("pathFile");
|
||||
|
||||
if (pathFile==null){
|
||||
throw new IllegalArgumentException(
|
||||
"Path File is null!!");
|
||||
}
|
||||
|
||||
JsonDocument document=null;
|
||||
JsonObject content=null;
|
||||
|
||||
BufferedReader reader = new BufferedReader(new FileReader(pathFile));
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
line=line.trim();
|
||||
logger.debug("AccountingInsertRstudioPlugin line :{}",line);
|
||||
|
||||
String[] infoUser=line.split("\\s+");
|
||||
String user=infoUser[1];
|
||||
Long dataVolume= Long.parseLong(infoUser[0]);
|
||||
if (inputs.containsKey("unitVolume")){
|
||||
|
||||
switch ((String) inputs.get("unitVolume")) {
|
||||
case "Kilobyte":
|
||||
dataVolume=kilToByte(dataVolume);
|
||||
break;
|
||||
case "Megabyte":
|
||||
dataVolume=megaToByte(dataVolume);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
try{
|
||||
String docId=UUID.randomUUID().toString();
|
||||
logger.debug("AccountingInsertRstudioPlugin User:{} dataVolume:{} KB",user,bytesToKil(dataVolume));
|
||||
logger.debug("AccountingInsertRstudioPlugin User:{} dataVolume:{} bytes",user,dataVolume);
|
||||
dataServiceId=InetAddress.getLocalHost().getHostName();
|
||||
Long dataCount=0l;
|
||||
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", user);
|
||||
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");
|
||||
}
|
||||
|
||||
}
|
||||
logger.trace("AccountingInsertRstudioPlugin close");
|
||||
reader.close();
|
||||
cluster.disconnect();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
protected void onStop() throws Exception {
|
||||
logger.trace("{} onStop() function", this.getClass().getSimpleName());
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
|
||||
private static long bytesToMeg(long bytes) {
|
||||
return bytes / Constant.MEGABYTE;
|
||||
}
|
||||
|
||||
private static long bytesToKil(long bytes) {
|
||||
return bytes / Constant.KILOBYTE ;
|
||||
}
|
||||
|
||||
private static long kilToByte(long kilobytes) {
|
||||
return kilobytes * Constant.KILOBYTE;
|
||||
}
|
||||
|
||||
private Long megaToByte(Long megaToByte) {
|
||||
return megaToByte * Constant.MEGABYTE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
*
|
||||
*/
|
||||
package org.gcube.accounting.insert.rstudio.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 AccountingInsertRstudioPluginDeclaration implements PluginDeclaration {
|
||||
/**
|
||||
* Logger
|
||||
*/
|
||||
private static Logger logger = LoggerFactory.getLogger(AccountingInsertRstudioPlugin.class);
|
||||
|
||||
/**
|
||||
* Plugin name used by the Executor to retrieve this class
|
||||
*/
|
||||
public static final String NAME = "Accounting-Insert-RStudio";
|
||||
|
||||
public static final String DESCRIPTION = "This plugin is used to insert RStudio storage record";
|
||||
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
/**{@inheritDoc}*/
|
||||
@Override
|
||||
public void init() {
|
||||
logger.debug(String.format("%s initialized", AccountingInsertRstudioPlugin.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 AccountingInsertRstudioPlugin.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AccountingInsertRstudioPluginDeclaration [getName()=" + getName()
|
||||
+ ", getDescription()=" + getDescription() + ", getVersion()="
|
||||
+ getVersion() + ", getSupportedCapabilities()="
|
||||
+ getSupportedCapabilities() + ", getPluginImplementation()="
|
||||
+ getPluginImplementation() + "]";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package org.gcube.accounting.insert.rstudio.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,17 @@
|
|||
package org.gcube.accounting.insert.rstudio.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,16 @@
|
|||
package org.gcube.accounting.insert.rstudio.utils;
|
||||
public class Constant {
|
||||
|
||||
//CONSTANT for connection Db
|
||||
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;
|
||||
|
||||
|
||||
|
||||
public static final long GIGABYTE = 1024L * 1024L * 1024L;
|
||||
public static final long MEGABYTE = 1024L * 1024L;
|
||||
public static final long KILOBYTE = 1024L;
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
org.gcube.accounting.insert.rstudio.plugin.AccountingInsertRstudioPluginDeclaration
|
|
@ -0,0 +1,62 @@
|
|||
package org.gcube.accounting.insert.rstudio.plugin;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.accounting.insert.rstudio.plugin.AccountingInsertRstudioPlugin;
|
||||
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","content-management");
|
||||
inputs.put("dataServiceName","storage-manager");
|
||||
inputs.put("dataServiceId","identifier");
|
||||
inputs.put("uri","Rstudio");
|
||||
inputs.put("dataType","STORAGE");
|
||||
inputs.put("unitVolume","Kilobyte");
|
||||
inputs.put("pathFile","/home/pieve/home_disk_space");
|
||||
|
||||
|
||||
|
||||
AccountingInsertRstudioPlugin plugin = new AccountingInsertRstudioPlugin(null);
|
||||
plugin.launch(inputs);
|
||||
logger.debug("-------------- launch test finished");
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void after(){
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue