Skip to content

Commit

Permalink
Merge pull request #45 from hildrum/master
Browse files Browse the repository at this point in the history
No comments, so I'm pulling this in.
  • Loading branch information
hildrum committed May 30, 2014
2 parents 78ee593 + 42b8f2e commit c044200
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
import org.apache.hadoop.hbase.client.HConnectionManager;
import org.apache.hadoop.hbase.client.HConnection;
import org.apache.hadoop.hbase.client.HTableInterface;
import org.apache.hadoop.fs.Path;
import java.io.File;
import java.net.URI;

/**
* Class for shared code between operators.
Expand All @@ -47,8 +50,10 @@ public abstract class HBASEOperator extends AbstractOperator {
protected Charset charset = RSTRING_CHAR_SET;
private String tableName = null;
protected byte tableNameBytes[] = null;
private String hbaseSite =null;
protected HConnection connection =null;
private Configuration conf;
static final String HBASE_SITE_PARAM_NAME="hbaseSite";
static final String TABLE_PARAM_NAME = "tableName";
static final String ROW_PARAM_NAME = "rowAttrName";
static final String STATIC_COLF_NAME = "staticColumnFamily";
Expand All @@ -57,6 +62,10 @@ public abstract class HBASEOperator extends AbstractOperator {
static final String VALID_TYPE_STRING="rstring, ustring, blob, or int64";
static final int BYTES_IN_LONG = Long.SIZE/Byte.SIZE;

@Parameter(name=HBASE_SITE_PARAM_NAME, optional=true,description="The hbase-site.xml file. This is an optional parameter; if not set, the operator will look in opt/downloaded and HBASE_HOME/conf for hbase-site.xml. It may be absolute or relative; if relative, it's relative to the data directory of the operator.")
public void setHbaseSite(String name) {
hbaseSite = name;
}

@Parameter(name=CHARSET_PARAM_NAME, optional=true,description="Character set to be used for converting byte[] to Strings and Strings to byte[]. Defaults to UTF-8")
public void getCharset(String _name) {
Expand Down Expand Up @@ -186,7 +195,22 @@ public synchronized void initialize(OperatorContext context)
Logger.getLogger(this.getClass()).trace("Operator " + context.getName() + " initializing in PE: " + context.getPE().getPEId() + " in Job: " + context.getPE().getJobId() );

conf = new Configuration();
conf.addResource("hbase-site.xml");
if (hbaseSite == null) {
conf.addResource("hbase-site.xml");
}
else {
// We need to pass the conf a Path. Seems the safest way to do that is to create a path from a URI.
// We want to handle both relative and absolute paths, adn I don't want to futz around prepending
// file:/// to a string.
// First get a URI for the data directory.
URI dataDir = context.getPE().getDataDirectory().toURI();
// now, resolve the hbase site against the data directory.
URI hbaseSiteURI = dataDir.resolve(hbaseSite);
// make a path out of it.
Path hbaseSitePath = new Path(hbaseSiteURI);
// add the resource. finally.
conf.addResource(hbaseSitePath);
}
connection = HConnectionManager.createConnection(conf);
tableNameBytes = tableName.getBytes(charset);
// Just check to see if the table exists. Might as well fail on initialize instead of process.
Expand Down
11 changes: 11 additions & 0 deletions samples/ConfigTests/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
##License

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this except in compliance with the License.

You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.
29 changes: 29 additions & 0 deletions samples/ConfigTests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (C) 2014, International Business Machines Corporation
# All Rights Reserved

# NOTE: To compile, you must have HBASE_HOME and HBASE_HOME set in your
# environment.

.PHONY: all clean

# Fill in STREAMS_HBASE_TOOLKIT location here.
STREAMS_HBASE_TOOLKIT ?= ../../com.ibm.streamsx.hbase

SPLC_FLAGS = -a
SPLC = $(STREAMS_INSTALL)/bin/sc

SPL_CMD_ARGS ?= -t $(STREAMS_HBASE_TOOLKIT)
SPL_MAIN_COMPOSITE = com.ibm.streamsx.hbase.sample::ConfigTest

all: standalone

standalone:
$(SPLC) $(SPLC_FLAGS) -T -M $(SPL_MAIN_COMPOSITE) $(SPL_CMD_ARGS)

distributed:
$(SPLC) $(SPLC_FLAGS) -M $(SPL_MAIN_COMPOSITE) $(SPL_CMD_ARGS)

clean:
$(SPLC) $(SPLC_FLAGS) -C -M $(SPL_MAIN_COMPOSITE)
rm data/*.out

43 changes: 43 additions & 0 deletions samples/ConfigTests/com.ibm.streamsx.hbase.sample/ConfigTest.spl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* Copyright (C) 2013-2014, International Business Machines Corporation */
/* All Rights Reserved */

namespace com.ibm.streamsx.hbase.sample ;

use com.ibm.streamsx.hbase::HBASEPut ;

/** Demonstrate the use of configuration options.
* To use, you must set hbaseSite when you run the standalone or submit the job.
* Invoke the standalone with output/bin/standalone hbaseSite=/path/to/hbase-site.xml
* Submit the job with -P hbaseSite=/path/to/hbase-site.xml
* The path may be relative or absolute; if relative, it's relative to teh data
* directory.
*/

composite ConfigTest
{
// You must supply this to run the composite.
param expression<rstring> $hbaseSite: getSubmissionTimeValue("hbaseSite");
graph
stream<rstring character, rstring colF, rstring colQ, rstring value> full = Beacon() {
param
iterations: 1;
output full:
character = "Bill",
colF="appearance",
colQ="numlegs",
value="4";
}

() as allSink = HBASEPut(full)
{
param
tableName : "streamsSample_lotr" ;
rowAttrName : "character" ;
columnFamilyAttrName : "colF" ;
columnQualifierAttrName : "colQ" ;
valueAttrName : "value" ;
hbaseSite: $hbaseSite;
}

}

27 changes: 27 additions & 0 deletions tests/ConfigTest.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Tests the GetSample and Scan sample
#

CLEAR_TABLE
tableName=streamsSample_lotr
firstColumnFamily=appearance
secondColumnFamily=location

COMMAND
command=echo $HBASE_HOME/conf/hbase-site.xml
resultKey=absPath

MAKE_AND_RUN
dir=../samples/ConfigTests
param1=hbaseSite
value1_key=absPath

COMMAND
command=cp $HBASE_HOME/conf/hbase-site.xml ../samples/ConfigTests/data

MAKE_AND_RUN
dir=../samples/ConfigTests
param1=hbaseSite
value1=hbase-site.xml


# leave empty line.

0 comments on commit c044200

Please sign in to comment.