Skip to content

Commit 5de42da

Browse files
committed
Merge pull request #74 from natashadsilva/bluemix
improvements to samples
2 parents b93e22f + f7f61d3 commit 5de42da

File tree

5 files changed

+82
-29
lines changed

5 files changed

+82
-29
lines changed

build.xml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

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

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

7070
</target>
7171

7272
<target name="samples" depends="toolkit">
7373
<subant target="indextoolkit" genericantfile="${basedir}/build.xml">
74-
<dirset dir="samples" includes="*"/>
75-
<dirset dir="extraSamples" includes="*"/>
74+
<dirset dir="samples" includes="HBaseBluemixSample*"/>
7675
</subant>
7776
</target>
7877
<target name="cleansamples">
7978
<subant target="cleantoolkit" genericantfile="${basedir}/build.xml">
80-
<dirset dir="samples" includes="*"/>
79+
<dirset dir="samples" includes="HBaseBluemixSample"/>
8180
</subant>
8281
</target>
8382

@@ -120,15 +119,16 @@
120119

121120
<!-- Targets to build releases -->
122121
<target name="release" depends="clean,all,spldoc">
122+
<echo message="toolkit to build {toolkit}"/>
123123
<mkdir dir="${tmp}" />
124-
<property name="releasefilename" value="${tmp}/streamsx.hbase.toolkits-${tkinfo.info:identity.info:version}-${DSTAMP}-${TSTAMP}.tgz"/>
124+
<property name="releasefilename" value="${tmp}/streamsx.hbase.bluemix.toolkits-${tkinfo.info:identity.info:version}-${DSTAMP}-${TSTAMP}.tgz"/>
125125
<tar compression="gzip" longfile="gnu"
126126
destfile="${releasefilename}"
127127
basedir="${basedir}"
128-
includes="${tkinfo.info:identity.info:name}/** samples/**"
129-
excludes="**/.gitignore **/.settings/** **/.settings **/.project **/.classpath **/tmp_downloaded/*"
128+
includes="${tkinfo.info:identity.info:name}/** samples/HBaseBluemixSample/**"
129+
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/*"
130130
/>
131131
<checksum file="${releasefilename}"/>
132132
<checksum algorithm="sha1" file="${releasefilename}"/>
133133
</target>
134-
</project>
134+
</project>

com.ibm.streamsx.hbase.bluemix/com.ibm.streamsx.hbase.bluemix/Stargate.spl renamed to com.ibm.streamsx.hbase.bluemix/com.ibm.streamsx.hbase.bluemix/HBaseBluemixFunctions.spl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ namespace com.ibm.streamsx.hbase.bluemix;
66
use com.ibm.streamsx.inet.http::*;
77
use com.ibm.streamsx.bytes.conversion::*;
88

9-
type RowType = rstring row, list<tuple<rstring column, rstring value, int64 time>> cells;
9+
10+
/**
11+
* Represents a row in an HBase table.
12+
*/
13+
type RowType = rstring rowKey, list<CellType> cells;
14+
15+
/**
16+
Represents a cell within a row in an HBase table.
17+
*/
18+
type CellType = tuple<rstring column, rstring value, int64 time>;
19+
1020

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

2030
public rstring hbaseDeleteTable(rstring baseUrl, rstring username, rstring password, rstring tableName) {
@@ -124,7 +134,7 @@ public RowType hbaseGet(rstring baseUrl, rstring username, rstring password, rs
124134
if (isTraceable(Trace.trace)) {
125135
appTrc(Trace.trace,"row key is "+rowid);
126136
}
127-
mutable list<tuple<rstring column, rstring value, int64 time>> cellList = [];
137+
mutable list<CellType> cellList = [];
128138
mutable int32 nextCell = findFirst(resultJson,"{",rowidEnd);
129139
while (nextCell != -1) {
130140
int32 columnStart = findFirst(resultJson,"column\":",nextCell) + 9;
@@ -148,5 +158,6 @@ public RowType hbaseGet(rstring baseUrl, rstring username, rstring password, rs
148158
if (isTraceable(Trace.trace)) {
149159
appTrc(Trace.error,"Cell list:"+(rstring)cellList);
150160
}
151-
return {row = rowid,cells=cellList};
152-
}
161+
return {rowKey= rowid,cells=cellList};
162+
}
163+

samples/HBaseBluemixSample/HBaseDeleteTable.spl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ composite HBaseDeleteTable {
1313

1414
() as Tester = Custom() {
1515
logic onProcess: {
16-
hbaseDeleteTable($baseUrl,$username,$password,"person");
16+
rstring error_msg = hbaseDeleteTable($baseUrl,$username,$password,"person");
17+
if (length(error_msg) == 0) {
18+
printStringLn("HBase table deleted successfully.");
19+
} else {
20+
printStringLn("HBase table deletion error: " + error_msg);
21+
}
1722
}
1823
}
1924

samples/HBaseBluemixSample/HBaseGet.spl

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
*/
44
use com.ibm.streamsx.hbase.bluemix::*;
55

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

812

913
composite HBaseGet {
@@ -16,15 +20,22 @@ composite HBaseGet {
1620

1721
stream<RowType row> ReadHBase = Custom() {
1822
logic onProcess: {
19-
RowType row = hbaseGet($baseUrl,$username,$password,"person","1");
20-
submit ({row = row},ReadHBase);
23+
mutable int32 count = 1;
24+
while (count <= 5) { //Retrieve the 5 rows added by the HBaseMakeTableAndPut sample.
25+
RowType row = hbaseGet($baseUrl,$username,$password,"person", (rstring)count);
26+
submit ({row = row},ReadHBase);
27+
count++;
28+
}
2129
}
2230
}
2331

2432
() as Writer = Custom(ReadHBase) {
2533
logic
2634
onTuple ReadHBase: {
27-
printStringLn((rstring)row);
35+
RowType returned_row = ReadHBase.row;
36+
for (CellType cell in returned_row.cells) {
37+
printStringLn("Row " + returned_row.rowKey+ ", Column: " + cell.column + " Value: " + cell.value + " Time:" + (rstring)cell.time);
38+
}
2839
}
2940
}
3041

samples/HBaseBluemixSample/HBaseMakeTableAndPut.spl

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,45 +2,71 @@
22
* All Rights Reserved
33
*/
44
use com.ibm.streamsx.hbase.bluemix::*;
5-
5+
/***
6+
* Create a table in HBase and add some data to it using the
7+
* hbaseMakeTable and hbasePut functions.
8+
* See the HBaseGet sample to see how to retrieve data from HBase.
9+
*/
610
composite HBaseMakeTableAndPut {
711
param
812
expression<rstring> $password:getSubmissionTimeValue("password");
913
expression<rstring> $username:getSubmissionTimeValue("username");
1014
expression<rstring> $baseUrl:getSubmissionTimeValue("url");
1115

1216
type
13-
AppTuple = uint64 rowKey;
17+
AppTuple = uint64 rowKey, rstring name;
1418

1519

1620
graph
1721

1822

1923
() as CreateTable = Custom() {
20-
logic onProcess: {
24+
logic
25+
onProcess: {
26+
2127
hbaseMakeTable($baseUrl,$username,$password,"person",["personal","professional"]);
22-
}
23-
}
28+
}
29+
}
2430

2531
stream <AppTuple> AppTuple_beat = Beacon () {
2632

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

3138
param
32-
iterations: 10u;
39+
iterations: 5u;
3340
initDelay: 10.0;
3441

3542
output
36-
AppTuple_beat : rowKey = ++tupleCount;
43+
AppTuple_beat :name= people[IterationCount()], rowKey = ++tupleCount;
3744
}
3845

3946

4047
() as InsertData = Custom(AppTuple_beat) {
41-
logic onTuple AppTuple_beat: {
42-
hbasePut($baseUrl,$username,$password,"person",(rstring)rowKey,"personal","fname","Tasos");
43-
}
48+
logic state :{
49+
mutable int32 count = 0;
50+
}
51+
onTuple AppTuple_beat: {
52+
53+
rstring error_msg = hbasePut($baseUrl,$username,$password,"person",(rstring)rowKey,"personal","fname", name );
54+
55+
//error handling/checking
56+
if (length(error_msg) == 0) {
57+
//hbasePut returns an empty message if the put was successful
58+
count++;
59+
} else {
60+
printStringLn("Error returned from hbasePut: " + error_msg);
61+
}
62+
}
63+
64+
onPunct AppTuple_beat: {
65+
if (currentPunct() == Sys.FinalMarker) {
66+
//only print when the application is finished
67+
printStringLn("hbasePut test successfully put " + (rstring)count + " entries.");
68+
}
69+
}
4470
}
4571

4672

0 commit comments

Comments
 (0)