Skip to content

Commit

Permalink
HBASE-22326 Fixed Checkstyle errors in hbase-examples
Browse files Browse the repository at this point in the history
  • Loading branch information
HorizonNet committed May 27, 2019
1 parent 21fe1d2 commit 65b8179
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 83 deletions.
7 changes: 7 additions & 0 deletions hbase-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@
<groupId>net.revelc.code</groupId>
<artifactId>warbucks-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<failOnViolation>true</failOnViolation>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hbase.client.example;

import java.io.Closeable;
Expand Down Expand Up @@ -51,7 +50,7 @@ public class RefreshHFilesClient extends Configured implements Tool, Closeable {
/**
* Constructor with Conf object
*
* @param cfg
* @param cfg the {@link Configuration} object to use
*/
public RefreshHFilesClient(Configuration cfg) {
try {
Expand All @@ -75,26 +74,28 @@ public void refreshHFiles(final TableName tableName) throws Throwable {
}

public void refreshHFiles(final Table table) throws Throwable {
final RefreshHFilesProtos.RefreshHFilesRequest request = RefreshHFilesProtos.RefreshHFilesRequest
.getDefaultInstance();
table.coprocessorService(RefreshHFilesProtos.RefreshHFilesService.class, HConstants.EMPTY_START_ROW,
HConstants.EMPTY_END_ROW,
new Batch.Call<RefreshHFilesProtos.RefreshHFilesService,
RefreshHFilesProtos.RefreshHFilesResponse>() {
@Override
public RefreshHFilesProtos.RefreshHFilesResponse call(
RefreshHFilesProtos.RefreshHFilesService refreshHFilesService)
throws IOException {
ServerRpcController controller = new ServerRpcController();
BlockingRpcCallback<RefreshHFilesProtos.RefreshHFilesResponse> rpcCallback =
new BlockingRpcCallback<>();
refreshHFilesService.refreshHFiles(controller, request, rpcCallback);
if (controller.failedOnException()) {
throw controller.getFailedOn();
}
return rpcCallback.get();
}
});
final RefreshHFilesProtos.RefreshHFilesRequest request =
RefreshHFilesProtos.RefreshHFilesRequest.getDefaultInstance();
table.coprocessorService(RefreshHFilesProtos.RefreshHFilesService.class,
HConstants.EMPTY_START_ROW, HConstants.EMPTY_END_ROW,
new Batch.Call<RefreshHFilesProtos.RefreshHFilesService,
RefreshHFilesProtos.RefreshHFilesResponse>() {
@Override
public RefreshHFilesProtos.RefreshHFilesResponse call(
RefreshHFilesProtos.RefreshHFilesService refreshHFilesService)
throws IOException {
ServerRpcController controller = new ServerRpcController();
BlockingRpcCallback<RefreshHFilesProtos.RefreshHFilesResponse> rpcCallback =
new BlockingRpcCallback<>();
refreshHFilesService.refreshHFiles(controller, request, rpcCallback);

if (controller.failedOnException()) {
throw controller.getFailedOn();
}

return rpcCallback.get();
}
});
LOG.debug("Done refreshing HFiles");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@
* return rpcCallback.get();
* }
* };
* Map&lt;byte[], BulkDeleteResponse&gt; result = ht.coprocessorService(BulkDeleteService.class, scan
* .getStartRow(), scan.getStopRow(), callable);
* Map&lt;byte[], BulkDeleteResponse&gt; result = ht.coprocessorService(BulkDeleteService.class,
* scan.getStartRow(), scan.getStopRow(), callable);
* for (BulkDeleteResponse response : result.values()) {
* noOfDeletedRows += response.getRowsDeleted();
* }
Expand Down Expand Up @@ -225,7 +225,8 @@ private Delete createDeleteMutation(List<Cell> deleteRow, DeleteType deleteType,
int noOfVersionsToDelete = 0;
if (timestamp == null) {
for (Cell kv : deleteRow) {
delete.addColumn(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv), kv.getTimestamp());
delete.addColumn(CellUtil.cloneFamily(kv), CellUtil.cloneQualifier(kv),
kv.getTimestamp());
noOfVersionsToDelete++;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hbase.coprocessor.example;

import java.io.IOException;
Expand Down Expand Up @@ -94,7 +93,8 @@ public void postCreateTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
}

@Override
public void preDisableTable(ObserverContext<MasterCoprocessorEnvironment> ctx, TableName tableName) throws IOException {
public void preDisableTable(ObserverContext<MasterCoprocessorEnvironment> ctx,
TableName tableName) throws IOException {
// Increment the Counter for disable table operations
this.disableTableCounter.increment();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hbase.coprocessor.example;

import com.google.protobuf.RpcCallback;
Expand Down Expand Up @@ -57,8 +56,9 @@ public Iterable<Service> getServices() {
}

@Override
public void refreshHFiles(RpcController controller, RefreshHFilesProtos.RefreshHFilesRequest request,
RpcCallback<RefreshHFilesProtos.RefreshHFilesResponse> done) {
public void refreshHFiles(RpcController controller,
RefreshHFilesProtos.RefreshHFilesRequest request,
RpcCallback<RefreshHFilesProtos.RefreshHFilesResponse> done) {
try {
for (Store store : env.getRegion().getStores()) {
LOG.debug("Refreshing HFiles for region: " + store.getRegionInfo().getRegionNameAsString() +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
* Modify ${HADOOP_HOME}/conf/hadoop-env.sh to include the hbase jar, the
* zookeeper jar (can be found in lib/ directory under HBase root, the examples output directory,
* and the hbase conf directory in HADOOP_CLASSPATH, and then run
* <tt><strong>bin/hadoop org.apache.hadoop.hbase.mapreduce.IndexBuilder TABLE_NAME COLUMN_FAMILY ATTR [ATTR ...]</strong></tt>
* <tt><strong>bin/hadoop org.apache.hadoop.hbase.mapreduce.IndexBuilder
* TABLE_NAME COLUMN_FAMILY ATTR [ATTR ...]</strong></tt>
* </p>
*
* <p>
Expand Down Expand Up @@ -117,8 +118,7 @@ protected void setup(Context context) throws IOException,
/**
* Job configuration.
*/
public static Job configureJob(Configuration conf, String [] args)
throws IOException {
public static Job configureJob(Configuration conf, String [] args) throws IOException {
String tableName = args[0];
String columnFamily = args[1];
System.out.println("****" + tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,12 @@ public class SampleUploader extends Configured implements Tool {

private static final String NAME = "SampleUploader";

static class Uploader
extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {

static class Uploader extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {
private long checkpoint = 100;
private long count = 0;

@Override
public void map(LongWritable key, Text line, Context context)
throws IOException {

public void map(LongWritable key, Text line, Context context) throws IOException {
// Input is a CSV file
// Each map() is a single line, where the key is the line number
// Each line is comma-delimited; row,family,qualifier,value
Expand Down Expand Up @@ -117,8 +113,7 @@ public void map(LongWritable key, Text line, Context context)
/**
* Job configuration.
*/
public static Job configureJob(Configuration conf, String [] args)
throws IOException {
public static Job configureJob(Configuration conf, String [] args) throws IOException {
Path inputPath = new Path(args[0]);
String tableName = args[1];
Job job = new Job(conf, NAME + "_" + tableName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,11 @@ private void run() throws Exception {

// Test UTF-8 handling
byte[] invalid = {(byte) 'f', (byte) 'o', (byte) 'o', (byte) '-',
(byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1};
(byte) 0xfc, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1, (byte) 0xa1};
byte[] valid = {(byte) 'f', (byte) 'o', (byte) 'o', (byte) '-',
(byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83,
(byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3,
(byte) 0x83, (byte) 0xAB};
(byte) 0xE7, (byte) 0x94, (byte) 0x9F, (byte) 0xE3, (byte) 0x83,
(byte) 0x93, (byte) 0xE3, (byte) 0x83, (byte) 0xBC, (byte) 0xE3,
(byte) 0x83, (byte) 0xAB};

ArrayList<Mutation> mutations;
// non-utf8 is fine for data
Expand Down Expand Up @@ -421,9 +421,9 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
options.put("debug", "true");

return new AppConfigurationEntry[]{
new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
options)};
new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
options)};
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public class HttpDoAsClient {
static protected String principal = null;

public static void main(String[] args) throws Exception {

if (args.length < 3 || args.length > 4) {

System.out.println("Invalid arguments!");
System.out.println("Usage: HttpDoAsClient host port doAsUserName [security=true]");
System.exit(-1);
Expand Down Expand Up @@ -143,8 +141,6 @@ private void run() throws Exception {
}
}



//
// Create the demo table with two column families, entry: and unused:
//
Expand Down Expand Up @@ -172,7 +168,7 @@ private void run() throws Exception {
Map<ByteBuffer, ColumnDescriptor> columnMap = refresh(client, httpClient)
.getColumnDescriptors(ByteBuffer.wrap(t));
for (ColumnDescriptor col2 : columnMap.values()) {
System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + Integer.toString(col2.maxVersions));
System.out.println(" column: " + utf8(col2.name.array()) + ", maxVer: " + col2.maxVersions);
}

transport.close();
Expand All @@ -181,7 +177,7 @@ private void run() throws Exception {

private Hbase.Client refresh(Hbase.Client client, THttpClient httpClient) {
httpClient.setCustomHeader("doAs", doAsUser);
if(secure) {
if (secure) {
try {
httpClient.setCustomHeader("Authorization", generateTicket());
} catch (GSSException e) {
Expand Down Expand Up @@ -232,7 +228,6 @@ private void printVersions(ByteBuffer row, List<TCell> versions) {

private void printRow(TRowResult rowResult) {
// copy values into a TreeMap to get them in sorted order

TreeMap<String, TCell> sorted = new TreeMap<>();
for (Map.Entry<ByteBuffer, TCell> column : rowResult.columns.entrySet()) {
sorted.put(utf8(column.getKey().array()), column.getValue());
Expand All @@ -249,7 +244,10 @@ private void printRow(TRowResult rowResult) {
}

static Subject getSubject() throws Exception {
if (!secure) return new Subject();
if (!secure) {
return new Subject();
}

/*
* To authenticate the DemoClient, kinit should be invoked ahead.
* Here we try to get the Kerberos credential from the ticket cache.
Expand All @@ -273,9 +271,9 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
options.put("debug", "true");

return new AppConfigurationEntry[]{
new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
options)};
new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
options)};
}
});
context.login();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

@InterfaceAudience.Private
public class DemoClient {

private static String host = "localhost";
private static int port = 9090;
private static boolean secure = false;
Expand All @@ -55,7 +54,8 @@ public class DemoClient {
public static void main(String[] args) throws Exception {
System.out.println("Thrift2 Demo");
System.out.println("Usage: DemoClient [host=localhost] [port=9090] [secure=false]");
System.out.println("This demo assumes you have a table called \"example\" with a column family called \"family1\"");
System.out.println("This demo assumes you have a table called \"example\" with a column " +
"family called \"family1\"");

// use passed in arguments instead of defaults
if (args.length >= 1) {
Expand Down Expand Up @@ -96,7 +96,7 @@ public void run() throws Exception {
if (framed) {
transport = new TFramedTransport(transport);
} else if (secure) {
/**
/*
* The Thrift server the DemoClient is trying to connect to
* must have a matching principal, and support authentication.
*
Expand Down Expand Up @@ -149,7 +149,9 @@ public void run() throws Exception {
}

static Subject getSubject() throws Exception {
if (!secure) return new Subject();
if (!secure) {
return new Subject();
}

/*
* To authenticate the DemoClient, kinit should be invoked ahead.
Expand All @@ -174,9 +176,9 @@ public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
options.put("debug", "true");

return new AppConfigurationEntry[]{
new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
options)};
new AppConfigurationEntry("com.sun.security.auth.module.Krb5LoginModule",
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
options)};
}
});
context.login();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public static void setUp(String regionImpl) {
CONF.set(HConstants.REGION_IMPL, regionImpl);
CONF.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 2);

CONF.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY, RefreshHFilesEndpoint.class.getName());
CONF.setStrings(CoprocessorHost.REGION_COPROCESSOR_CONF_KEY,
RefreshHFilesEndpoint.class.getName());
cluster = HTU.startMiniCluster(NUM_RS);

// Create table
Expand All @@ -80,9 +81,9 @@ protected void addHFilesToRegions() throws IOException {
for (Region region : cluster.getRegions(TABLE_NAME)) {
Path regionDir = new Path(tableDir, region.getRegionInfo().getEncodedName());
Path familyDir = new Path(regionDir, Bytes.toString(FAMILY));
HFileTestUtil
.createHFile(HTU.getConfiguration(), HTU.getTestFileSystem(), new Path(familyDir, HFILE_NAME), FAMILY,
QUALIFIER, Bytes.toBytes("50"), Bytes.toBytes("60"), NUM_ROWS);
HFileTestUtil.createHFile(HTU.getConfiguration(), HTU.getTestFileSystem(),
new Path(familyDir, HFILE_NAME), FAMILY, QUALIFIER, Bytes.toBytes("50"),
Bytes.toBytes("60"), NUM_ROWS);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

@Category(MediumTests.class)
public class TestRefreshHFilesEndpoint extends TestRefreshHFilesBase {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestRefreshHFilesEndpoint.class);
Expand All @@ -69,8 +68,9 @@ private void callRefreshRegionHFilesEndPoint() throws IOException {
RefreshHFilesClient refreshHFilesClient = new RefreshHFilesClient(CONF);
refreshHFilesClient.refreshHFiles(TABLE_NAME);
} catch (RetriesExhaustedException rex) {
if (rex.getCause() instanceof IOException)
if (rex.getCause() instanceof IOException) {
throw new IOException();
}
} catch (Throwable ex) {
LOG.error(ex.toString(), ex);
fail("Couldn't call the RefreshRegionHFilesEndpoint");
Expand All @@ -81,15 +81,15 @@ public static class HRegionForRefreshHFilesEP extends HRegion {
HStoreWithFaultyRefreshHFilesAPI store;

public HRegionForRefreshHFilesEP(final Path tableDir, final WAL wal, final FileSystem fs,
final Configuration confParam, final RegionInfo regionInfo,
final TableDescriptor htd, final RegionServerServices rsServices) {
final Configuration confParam, final RegionInfo regionInfo, final TableDescriptor htd,
final RegionServerServices rsServices) {
super(tableDir, wal, fs, confParam, regionInfo, htd, rsServices);
}

@Override
public List<HStore> getStores() {
List<HStore> list = new ArrayList<>(stores.size());
/**
/*
* This is used to trigger the custom definition (faulty)
* of refresh HFiles API.
*/
Expand Down
Loading

0 comments on commit 65b8179

Please sign in to comment.