Skip to content

Commit

Permalink
Merge pull request #74 from natashadsilva/bluemix
Browse files Browse the repository at this point in the history
improvements to samples
  • Loading branch information
natashadsilva committed Dec 9, 2015
2 parents b93e22f + f7f61d3 commit 5de42da
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 29 deletions.
18 changes: 9 additions & 9 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- toolkit was tested with HBase 0.94.3 and Hadoop 1.1.1 -->
<property name="streams.install" value="${env.STREAMS_INSTALL}" />
<property name="toolkit" location="com.ibm.streamsx.hbase"/>
<property name="toolkit" location="com.ibm.streamsx.hbase.bluemix"/>
<property name="tmp" location="tmp" />

<target name="all" depends="toolkit,samples"/>
Expand Down Expand Up @@ -64,20 +64,19 @@
</antcall>
<touch file="${tkinfo.info:identity.info:name}/toolkit.xml"/>
<subant target="spldoctoolkit" genericantfile="${basedir}/build.xml">
<dirset dir="samples" includes="*"/>
<dirset dir="samples" includes="HBaseBluemixSample"/>
</subant>

</target>

<target name="samples" depends="toolkit">
<subant target="indextoolkit" genericantfile="${basedir}/build.xml">
<dirset dir="samples" includes="*"/>
<dirset dir="extraSamples" includes="*"/>
<dirset dir="samples" includes="HBaseBluemixSample*"/>
</subant>
</target>
<target name="cleansamples">
<subant target="cleantoolkit" genericantfile="${basedir}/build.xml">
<dirset dir="samples" includes="*"/>
<dirset dir="samples" includes="HBaseBluemixSample"/>
</subant>
</target>

Expand Down Expand Up @@ -120,15 +119,16 @@

<!-- Targets to build releases -->
<target name="release" depends="clean,all,spldoc">
<echo message="toolkit to build {toolkit}"/>
<mkdir dir="${tmp}" />
<property name="releasefilename" value="${tmp}/streamsx.hbase.toolkits-${tkinfo.info:identity.info:version}-${DSTAMP}-${TSTAMP}.tgz"/>
<property name="releasefilename" value="${tmp}/streamsx.hbase.bluemix.toolkits-${tkinfo.info:identity.info:version}-${DSTAMP}-${TSTAMP}.tgz"/>
<tar compression="gzip" longfile="gnu"
destfile="${releasefilename}"
basedir="${basedir}"
includes="${tkinfo.info:identity.info:name}/** samples/**"
excludes="**/.gitignore **/.settings/** **/.settings **/.project **/.classpath **/tmp_downloaded/*"
includes="${tkinfo.info:identity.info:name}/** samples/HBaseBluemixSample/**"
excludes="**/.gitignore samples/HBaseBluemixSample/toolkit.xml samples/HBaseBluemixSample/output/** samples/HBaseBluemixSample/.toolkitList ${tkinfo.info:identity.info:name}/.settings com.ibm.streams.hbase.bluemix/.project ${tkinfo.info:identity.info:name}/.classpath **/tmp_downloaded/*"
/>
<checksum file="${releasefilename}"/>
<checksum algorithm="sha1" file="${releasefilename}"/>
</target>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,25 @@ namespace com.ibm.streamsx.hbase.bluemix;
use com.ibm.streamsx.inet.http::*;
use com.ibm.streamsx.bytes.conversion::*;

type RowType = rstring row, list<tuple<rstring column, rstring value, int64 time>> cells;

/**
* Represents a row in an HBase table.
*/
type RowType = rstring rowKey, list<CellType> cells;

/**
Represents a cell within a row in an HBase table.
*/
type CellType = tuple<rstring column, rstring value, int64 time>;


/**
* Delete an HBase table.
* @param baseUrl URL used to access HBase, should be http://.../hbase
* @param username Username if access is via the Knox gateway. May be empty.
* @param password Password for the Knox gateway. Maybe be empty.
* @param tableName Name of the table to create.
* @return the result of the HttpDelete request. May contain an exception in the case of an error.
* @return the result of the HttpDelete request. May contain an exception in the case of an error and will be empty otherwise.
*/

public rstring hbaseDeleteTable(rstring baseUrl, rstring username, rstring password, rstring tableName) {
Expand Down Expand Up @@ -124,7 +134,7 @@ public RowType hbaseGet(rstring baseUrl, rstring username, rstring password, rs
if (isTraceable(Trace.trace)) {
appTrc(Trace.trace,"row key is "+rowid);
}
mutable list<tuple<rstring column, rstring value, int64 time>> cellList = [];
mutable list<CellType> cellList = [];
mutable int32 nextCell = findFirst(resultJson,"{",rowidEnd);
while (nextCell != -1) {
int32 columnStart = findFirst(resultJson,"column\":",nextCell) + 9;
Expand All @@ -148,5 +158,6 @@ public RowType hbaseGet(rstring baseUrl, rstring username, rstring password, rs
if (isTraceable(Trace.trace)) {
appTrc(Trace.error,"Cell list:"+(rstring)cellList);
}
return {row = rowid,cells=cellList};
}
return {rowKey= rowid,cells=cellList};
}

7 changes: 6 additions & 1 deletion samples/HBaseBluemixSample/HBaseDeleteTable.spl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ composite HBaseDeleteTable {

() as Tester = Custom() {
logic onProcess: {
hbaseDeleteTable($baseUrl,$username,$password,"person");
rstring error_msg = hbaseDeleteTable($baseUrl,$username,$password,"person");
if (length(error_msg) == 0) {
printStringLn("HBase table deleted successfully.");
} else {
printStringLn("HBase table deletion error: " + error_msg);
}
}
}

Expand Down
19 changes: 15 additions & 4 deletions samples/HBaseBluemixSample/HBaseGet.spl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
*/
use com.ibm.streamsx.hbase.bluemix::*;


/**
* This sample demonstrates how to get cells from a row in HBase using the hbaseGet function.
* It is assumed that the HBaseMakeTableAndPut sample has been run first to insert rows into a table.
*
*/


composite HBaseGet {
Expand All @@ -16,15 +20,22 @@ composite HBaseGet {

stream<RowType row> ReadHBase = Custom() {
logic onProcess: {
RowType row = hbaseGet($baseUrl,$username,$password,"person","1");
submit ({row = row},ReadHBase);
mutable int32 count = 1;
while (count <= 5) { //Retrieve the 5 rows added by the HBaseMakeTableAndPut sample.
RowType row = hbaseGet($baseUrl,$username,$password,"person", (rstring)count);
submit ({row = row},ReadHBase);
count++;
}
}
}

() as Writer = Custom(ReadHBase) {
logic
onTuple ReadHBase: {
printStringLn((rstring)row);
RowType returned_row = ReadHBase.row;
for (CellType cell in returned_row.cells) {
printStringLn("Row " + returned_row.rowKey+ ", Column: " + cell.column + " Value: " + cell.value + " Time:" + (rstring)cell.time);
}
}
}

Expand Down
46 changes: 36 additions & 10 deletions samples/HBaseBluemixSample/HBaseMakeTableAndPut.spl
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,71 @@
* All Rights Reserved
*/
use com.ibm.streamsx.hbase.bluemix::*;

/***
* Create a table in HBase and add some data to it using the
* hbaseMakeTable and hbasePut functions.
* See the HBaseGet sample to see how to retrieve data from HBase.
*/
composite HBaseMakeTableAndPut {
param
expression<rstring> $password:getSubmissionTimeValue("password");
expression<rstring> $username:getSubmissionTimeValue("username");
expression<rstring> $baseUrl:getSubmissionTimeValue("url");

type
AppTuple = uint64 rowKey;
AppTuple = uint64 rowKey, rstring name;


graph


() as CreateTable = Custom() {
logic onProcess: {
logic
onProcess: {

hbaseMakeTable($baseUrl,$username,$password,"person",["personal","professional"]);
}
}
}
}

stream <AppTuple> AppTuple_beat = Beacon () {

logic state: {
mutable uint64 tupleCount = 0u;
list<rstring> people = ["Tasos", "Mark", "Robin", "Kelly", "Grace"];
}

param
iterations: 10u;
iterations: 5u;
initDelay: 10.0;

output
AppTuple_beat : rowKey = ++tupleCount;
AppTuple_beat :name= people[IterationCount()], rowKey = ++tupleCount;
}


() as InsertData = Custom(AppTuple_beat) {
logic onTuple AppTuple_beat: {
hbasePut($baseUrl,$username,$password,"person",(rstring)rowKey,"personal","fname","Tasos");
}
logic state :{
mutable int32 count = 0;
}
onTuple AppTuple_beat: {

rstring error_msg = hbasePut($baseUrl,$username,$password,"person",(rstring)rowKey,"personal","fname", name );

//error handling/checking
if (length(error_msg) == 0) {
//hbasePut returns an empty message if the put was successful
count++;
} else {
printStringLn("Error returned from hbasePut: " + error_msg);
}
}

onPunct AppTuple_beat: {
if (currentPunct() == Sys.FinalMarker) {
//only print when the application is finished
printStringLn("hbasePut test successfully put " + (rstring)count + " entries.");
}
}
}


Expand Down

0 comments on commit 5de42da

Please sign in to comment.