java

Unusual Java Jenkins Problem (Play Framework)

Posted on Updated on

Sudah beberapa hari ini server Jenkins di kantor selalu komplain ‘build failed’ terus tanpa error yang jelas seperti ini:

------------------------------------------
[...truncated 85 lines...]

[info] Resolving joda-time#joda-time;2.1 ...
[info] Resolving org.joda#joda-convert;1.2 ...
[info] Resolving org.apache.commons#commons-lang3;3.1 ...
[info] Resolving com.ning#async-http-client;1.7.6 ...
[info] Resolving oauth.signpost#signpost-core;1.2.1.2 ...
[info] Resolving oauth.signpost#signpost-commonshttp4;1.2.1.2 ...
[info] Resolving org.apache.httpcomponents#httpcore;4.0.1 ...
[info] Resolving org.apache.httpcomponents#httpclient;4.0.1 ...
[info] Resolving commons-logging#commons-logging;1.1.1 ...
[info] Resolving org.codehaus.jackson#jackson-core-asl;1.9.10 ...
[info] Resolving org.codehaus.jackson#jackson-mapper-asl;1.9.10 ...
[info] Resolving net.sf.ehcache#ehcache-core;2.6.0 ...
[info] Resolving javax.transaction#jta;1.1 ...
[info] Resolving org.scala-lang#scala-reflect;2.10.0 ...
[info] Resolving play#play-java_2.10;2.1.3 ...
[info] Resolving org.hibernate#hibernate-validator;4.3.0.Final ...
[info] Resolving javax.validation#validation-api;1.0.0.GA ...
[info] Resolving org.jboss.logging#jboss-logging;3.1.0.CR2 ...
[info] Resolving org.springframework#spring-core;3.1.2.RELEASE ...
[info] Resolving org.springframework#spring-beans;3.1.2.RELEASE ...
[info] Resolving org.reflections#reflections;0.9.8 ...
[info] Resolving com.google.guava#guava;13.0.1 ...
[info] Resolving com.google.code.findbugs#jsr305;2.0.1 ...
[info] Resolving javax.servlet#javax.servlet-api;3.0.1 ...
[info] Resolving play#play-java-jdbc_2.10;2.1.3 ...
[info] Resolving play#play-jdbc_2.10;2.1.3 ...
[info] Resolving com.jolbox#bonecp;0.7.1.RELEASE ...
[info] Resolving com.h2database#h2;1.3.168 ...
[info] Resolving tyrex#tyrex;1.0.1 ...
[info] Resolving play#play-java-ebean_2.10;2.1.3 ...
[info] Resolving org.hibernate.javax.persistence#hibernate-jpa-2.0-api;1.0.1.Final ...
[info] Resolving mysql#mysql-connector-java;5.1.18 ...
[info] Resolving org.springframework#spring-context;3.2.4.RELEASE ...
[info] Resolving org.springframework#spring-aop;3.2.4.RELEASE ...
[info] Resolving aopalliance#aopalliance;1.0 ...
[info] Resolving org.springframework#spring-beans;3.2.4.RELEASE ...
[info] Resolving org.springframework#spring-core;3.2.4.RELEASE ...
[info] Resolving org.springframework#spring-expression;3.2.4.RELEASE ...
[info] Resolving com.mfizz#mfz-ruby-marshal;1.0.2 ...
[info] Resolving org.mockito#mockito-all;1.8.4 ...
[info] Resolving org.powermock#powermock-module-junit4;1.5.1 ...
[info] Resolving junit#junit;4.11 ...
[info] Resolving org.hamcrest#hamcrest-core;1.3 ...
[info] Resolving org.powermock#powermock-module-junit4-common;1.5.1 ...
[info] Resolving org.powermock#powermock-core;1.5.1 ...
[info] Resolving org.powermock#powermock-reflect;1.5.1 ...
[info] Resolving org.objenesis#objenesis;1.2 ...
[info] Resolving org.javassist#javassist;3.18.0-GA ...
[info] Resolving org.powermock#powermock-api-mockito;1.5.1 ...
[info] Resolving org.mockito#mockito-all;1.9.5 ...
[info] Resolving org.powermock#powermock-api-support;1.5.1 ...
[info] Resolving com.fasterxml.jackson.core#jackson-core;2.2.3 ...
[info] Resolving org.simpleframework#simple-xml;2.7.1 ...
[info] Resolving stax#stax-api;1.0.1 ...
[info] Resolving stax#stax;1.2.0 ...
[info] Resolving xpp3#xpp3;1.1.3.3 ...
[info] Resolving net.greghaines#jesque;1.3.0 ...
[info] Resolving redis.clients#jedis;2.1.0 ...
[info] Resolving commons-pool#commons-pool;1.6 ...
[info] Resolving com.fasterxml.jackson.core#jackson-databind;2.1.2 ...
[info] Resolving com.fasterxml.jackson.core#jackson-annotations;2.1.1 ...
[info] Resolving commons-codec#commons-codec;1.8 ...
[info] Resolving org.avaje.ebeanorm#avaje-ebeanorm;3.2.4 ...
[info] Resolving javax.persistence#persistence-api;1.0 ...
[info] Resolving com.github.mumoshu#play2-memcached_2.10;0.3.0.3 ...
[info] Resolving net.spy#spymemcached;2.9.0 ...
[info] Resolving com.maxmind.geoip#geoip-api;1.2.11 ...
[info] Resolving org.yaml#snakeyaml;1.13 ...
[info] Resolving org.apache.commons#commons-collections4;4.0 ...
[info] Resolving org.fluentlenium#fluentlenium-parent;0.9.1 ...
[info] Resolving com.datastax.cassandra#cassandra-driver-core;2.1.4 ...
[info] Resolving com.google.guava#guava;14.0.1 ...
[info] Resolving com.codahale.metrics#metrics-core;3.0.2 ...
[info] Resolving org.slf4j#slf4j-api;1.7.5 ...
[info] Resolving com.datastax.cassandra#cassandra-driver-mapping;2.1.4 ...
[info] Resolving commons-io#commons-io;2.4 ...
[info] Resolving play#play-test_2.10;2.1.3 ...
[info] Resolving junit#junit-dep;4.10 ...
[info] Resolving org.specs2#specs2_2.10;1.13 ...
[info] Resolving org.specs2#scalaz-core_2.10;7.0.0 ...
[info] Resolving org.specs2#scalaz-concurrent_2.10;7.0.0 ...
[info] Resolving org.specs2#scalaz-effect_2.10;7.0.0 ...
[info] Resolving com.novocode#junit-interface;0.10 ...
[info] Resolving org.scala-tools.testing#test-interface;0.5 ...
[info] Resolving org.fluentlenium#fluentlenium-festassert;0.7.3 ...
[info] Resolving org.fluentlenium#fluentlenium-core;0.7.3 ...
[info] Resolving org.seleniumhq.selenium#selenium-java;2.25.0 ...
[info] Resolving org.seleniumhq.selenium#selenium-android-driver;2.25.0 ...
[info] Resolving org.seleniumhq.selenium#selenium-remote-driver;2.25.0 ...
[info] Resolving cglib#cglib-nodep;2.1_3 ...
[info] Resolving org.json#json;20080701 ...
[info] Resolving org.seleniumhq.selenium#selenium-api;2.25.0 ...
[info] Resolving org.apache.httpcomponents#httpclient;4.1.2 ...
[info] Resolving org.apache.httpcomponents#httpcore;4.1.3 ...
[info] Resolving org.apache.commons#commons-exec;1.1 ...
[info] Resolving net.java.dev.jna#jna;3.4.0 ...
[info] Resolving net.java.dev.jna#platform;3.4.0 ...
[info] Resolving org.seleniumhq.selenium#selenium-chrome-driver;2.25.0 ...
[info] Resolving org.seleniumhq.selenium#selenium-htmlunit-driver;2.25.0 ...
[info] Resolving net.sourceforge.htmlunit#htmlunit;2.9 ...
[info] Resolving xalan#xalan;2.7.1 ...
[info] Resolving xalan#serializer;2.7.1 ...
[info] Resolving xml-apis#xml-apis;1.3.04 ...
[info] Resolving commons-collections#commons-collections;3.2.1 ...
[info] Resolving commons-lang#commons-lang;2.6 ...
[info] Resolving org.apache.httpcomponents#httpmime;4.1.2 ...
[info] Resolving net.sourceforge.htmlunit#htmlunit-core-js;2.9 ...
[info] Resolving xerces#xercesImpl;2.9.1 ...
[info] Resolving net.sourceforge.nekohtml#nekohtml;1.9.15 ...
[info] Resolving net.sourceforge.cssparser#cssparser;0.9.5 ...
[info] Resolving org.w3c.css#sac;1.3 ...
[info] Resolving org.seleniumhq.selenium#selenium-firefox-driver;2.25.0 ...
[info] Resolving org.seleniumhq.selenium#selenium-ie-driver;2.25.0 ...
[info] Resolving org.seleniumhq.selenium#selenium-iphone-driver;2.25.0 ...
[info] Resolving org.seleniumhq.selenium#selenium-safari-driver;2.25.0 ...
[info] Resolving org.webbitserver#webbit;0.4.6 ...
[info] Resolving org.seleniumhq.selenium#selenium-support;2.25.0 ...
[info] Resolving org.easytesting#fest-assert;1.4 ...
[info] Resolving org.easytesting#fest-util;1.1.6 ...

 [0m[ [0minfo [0m]  [0mDone updating. [0m
 [0m[ [0minfo [0m]  [0mCompiling 12 Scala sources and 297 Java sources to <http://**********:8080/job/AdsServing%20Engine/ws/target/scala-2.10/classes... [0m>
 [0m[ [31merror [0m]  [0m<http://**********:8080/job/AdsServing%20Engine/ws/app/models/rtb/twoone/Banner.java>:1: package rtb contains object and package with same name: v21 [0m
 [0m[ [31merror [0m]  [0mone of them needs to be removed from classpath [0m
 [0m[ [31merror [0m]  [0mpackage models.rtb.twoone; [0m
 [0m[ [31merror [0m]  [0m                   ^ [0m
 [0m[ [31merror [0m]  [0mone error found [0m
 [0m[ [31merror [0m]  [0m(compile: [31mcompile [0m) Compilation failed [0m
 [0m[ [31merror [0m]  [0mTotal time: 10 s, completed Feb 3, 2015 2:22:48 PM [0m
Build step 'Execute shell' marked build as failure

Setelah beberapa jam dikutak-katik ternyata solusi-nya cuma hanya perlu re-download dan re-compile play framework nya (kita pake java play framework) :/ Kemungkinan besar ini dikarenakan 1-2minggu yang lalu server jenkins hdd-nya sempat corrupted lalu di repair (dengan software) tapi ada beberapa broken files/directories structure-nya.

Export Data From Cassandra to CSV

Posted on Updated on

Karena kebutuhan untuk mindahin data Cassandra dari cluster lama ke cluster baru maka gue bikin tools untuk ngebantu diri gue sendiri untuk export data cassandra ke CSV.

Updated: The code is pushed to a Github.

Kenapa gue harus bikin tools ini?

Karena Cassandra yg versi gratisan ngga punya tools “bisa jalan” untuk backup data di dalam cassandra.
Well ada sih tools nya beberapa, tapi kalau data lu besar pasti tools tersebut ngadat, makanya kita harus bikin sendiri dengan meraba-raba library connection untuk cassandra dari datastax.

Berhubung skill java gue masih cetek, jadi sorry kalau misalkan agak culun codingan nya. Tapi gue udah test bisa narik tables dengan isi data puluhan GB dan jutaan rows ga ada masalah, so kalau ada yg butuh silahkan di compile aja sendiri pake library java untuk cassandra dari datastax ya.

package lemonade.dumpCassandra;

import java.text.SimpleDateFormat;
import java.util.Iterator;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.ColumnDefinitions.Definition;
import com.datastax.driver.core.DataType;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
import com.datastax.driver.core.SimpleStatement;
import com.datastax.driver.core.Statement;


/**
 * Dump Data from Cassandra to CSV
 * 2015/01/19
 * by sphinxid <firman.gautama@gmail.com>
 *
 */
public class CassExport
{
 public static void main( String[] args )
 {
 String keyspace = "YourKeyspace";
 String table = "TableName";
 String username = "username";
 String password = "password";
 String host = "127.0.0.1";


 Cluster.Builder clusterBuilder = Cluster.builder()
 .addContactPoints(host)
 .withCredentials(username, password);
 Cluster cluster = clusterBuilder.build();
 Session session = cluster.connect(keyspace);

 Statement stmt = new SimpleStatement("SELECT * FROM " + table);
 stmt.setFetchSize(1000);
 ResultSet rs = session.execute(stmt);
 Iterator<Row> iter = rs.iterator();

 while (!rs.isFullyFetched()) {
 rs.fetchMoreResults();
 Row row = iter.next();
 if (row != null)
 {
 StringBuilder line = new StringBuilder();
 for (Definition key : row.getColumnDefinitions().asList())
 {
 String val = myGetValue(key, row);
 line.append("\"");
 line.append(val);
 line.append("\"");
 line.append(",");
 }
 line.deleteCharAt(line.length()-1);
 System.out.println(line.toString());
 }
 }

 session.close();
 cluster.close();

 }

 public static String myGetValue(Definition key, Row row)
 {
 String str = "";

 if (key != null)
 {
 String col = key.getName();

 try
 {
 if (key.getType() == DataType.cdouble())
 {
 str = new Double(row.getDouble(col)).toString();
 }
 else if (key.getType() == DataType.cint())
 {
 str = new Integer(row.getInt(col)).toString();
 }
 else if (key.getType() == DataType.uuid())
 {
 str = row.getUUID(col).toString();
 }
 else if (key.getType() == DataType.cfloat())
 {
 str = new Float(row.getFloat(col)).toString();
 }
 else if (key.getType() == DataType.timestamp())
 {
 str = row.getDate(col).toString();

 SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
 str = fmt.format(row.getDate(col));


 }
 else
 {
 str = row.getString(col);
 }
 } catch (Exception e)
 {
 str = "";
 }
 }

 return str;
 }

}

or this is the pastebin.

#Update

#Benchmark Speed
22gb of data ~ 122mil rows. 
Extracted in 444m38.061s. 
- 1 host cassandra server (4core, 8gb ram, sata hdd).
- avg 4.5k of rows / second.