commit 175bde198cc26932b8ad3928b7fc6a3f9ccafb23 Author: Luca Frosini Date: Mon Aug 28 13:13:29 2017 +0000 Branching in my private branch git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/private/luca.frosini/GenerateMapReduceCouchbase@152519 82a268e6-3cf1-43bd-a215-b396298e98cf diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..e43402f --- /dev/null +++ b/.classpath @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..cb4f56a --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + GenerateMapReduceCouchbase + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..6249222 --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,12 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs new file mode 100644 index 0000000..f897a7f --- /dev/null +++ b/.settings/org.eclipse.m2e.core.prefs @@ -0,0 +1,4 @@ +activeProfiles= +eclipse.preferences.version=1 +resolveWorkspaceProjects=true +version=1 diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..2fcda67 --- /dev/null +++ b/pom.xml @@ -0,0 +1,38 @@ + + 4.0.0 + org.gcube.influxdb + db-ttest + 0.0.1-SNAPSHOT + influxdbTest + + + + couchbase + Couchbase Maven Repository + default + http://files.couchbase.com/maven2/ + + false + + + + + + org.influxdb + influxdb-java + 2.2 + + + com.google.code.gson + gson + 2.3.1 + + + com.couchbase.client + java-client + 2.0.3 + + + + \ No newline at end of file diff --git a/src/main/java/org/gcube/dbtest/dbtest.java b/src/main/java/org/gcube/dbtest/dbtest.java new file mode 100644 index 0000000..c325cb3 --- /dev/null +++ b/src/main/java/org/gcube/dbtest/dbtest.java @@ -0,0 +1,81 @@ +package org.gcube.dbtest; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.couchbase.client.java.Bucket; +import com.couchbase.client.java.Cluster; +import com.couchbase.client.java.CouchbaseCluster; +import com.couchbase.client.java.bucket.BucketManager; +import com.couchbase.client.java.env.CouchbaseEnvironment; +import com.couchbase.client.java.env.DefaultCouchbaseEnvironment; +import com.couchbase.client.java.view.DefaultView; +import com.couchbase.client.java.view.DesignDocument; + +public class dbtest { + + protected static final String DEFAULT_DB = "accounting"; + + protected static final String DEFAULT_DB_SERVICE = "accounting_service"; + protected static final String DEFAULT_DB_STORAGE = "accounting_storage"; + + protected static final String MAP_REDUCE_PATH_IMPORT = "/home/pieve/Documents/AccountingAnalyticsListMapReduceCouchbase/couchbase/2.0.0/_design/ServiceUsageRecord"; + + protected static final String URL="http://couchbase01-d-d4s.d4science.org"; + protected static final String PASSWORD="accounting"; + + /* The environment configuration */ + protected static final CouchbaseEnvironment ENV = DefaultCouchbaseEnvironment + .builder().queryEnabled(true).build(); + public static void main(String[] args) throws Exception{ + createMapReduceCouchBase(); + } + + + private static void createMapReduceCouchBase() throws Exception{ + + Cluster cluster = CouchbaseCluster.create(ENV, URL); + Bucket bucket = cluster.openBucket(DEFAULT_DB_SERVICE,PASSWORD); + BucketManager bucketManager = bucket.bucketManager(); + File file = new File(MAP_REDUCE_PATH_IMPORT); + + File[] filesInDir = file.listFiles(); + Arrays.sort(filesInDir); + Map mappe = new HashMap(); + + for(File fs : filesInDir) + { + String nameMapReduce=fs.getName(); + String nameViewCustom=fs.getName().split("__")[0]; + if (!fs.getName().equals("Invalid")){ + + String stringMap= new String (Files.readAllBytes(Paths.get(fs.toString()+"/map.js"))); + String stringReduce= new String (Files.readAllBytes(Paths.get(fs.toString()+"/reduce.js"))); + + if (!mappe.containsKey(nameViewCustom)) + mappe.put(nameViewCustom, new ArrayList()); + System.out.println("add view:"+nameViewCustom+" and map:"+nameMapReduce); + mappe.get(nameViewCustom).add(DefaultView.create(nameMapReduce,stringMap,stringReduce)); + } + } + + for(Map.Entry entry : mappe.entrySet()) { + + String key = entry.getKey(); + System.out.println("key"+key); + DesignDocument designDoc = DesignDocument.create(key,entry.getValue()); + bucketManager.insertDesignDocument(designDoc); + + + } + + cluster.disconnect(); + } + +}