Apply checkstyle fixes to eagle-storage-base module
authoryonzhang <yonzhang@ebay.com>
Tue, 3 Apr 2018 23:13:52 +0000 (16:13 -0700)
committeryonzhang <yonzhang@ebay.com>
Tue, 3 Apr 2018 23:13:52 +0000 (16:13 -0700)
Author: coheigea
Reviewer: yonzhang

Closes #988

18 files changed:
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/DataStorage.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/DataStorageManager.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/exception/IllegalDataStorageException.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/exception/IllegalDataStorageTypeException.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/operation/CompiledQuery.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/operation/CreateStatement.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/operation/DeleteStatement.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/operation/QueryStatement.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/operation/RawQuery.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/operation/RowkeyQueryStatement.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/operation/UpdateStatement.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/result/Result.java
eagle-core/eagle-query/eagle-storage-base/src/main/java/org/apache/eagle/storage/spi/DataStorageServiceLoader.java
eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/TestUri.java
eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCompiledQuery.java
eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestCreateStatement.java
eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/operation/TestUpdateStatement.java
eagle-core/eagle-query/eagle-storage-base/src/test/java/org/apache/eagle/storage/spi/TestDataStorageServiceProvider.java

index 4347401..314d29a 100644 (file)
@@ -70,18 +70,18 @@ public interface DataStorage<I> {
     <E extends TaggedLogAPIEntity> ModifyResult<I> delete(List<E> entities, EntityDefinition entityDefinition) throws IOException;
 
     /**
-     * Execute delete operation by entity ids
+     * Execute delete operation
      *
      * @throws IOException
      */
-    ModifyResult<I> deleteByID(List<I> ids, EntityDefinition entityDefinition) throws IOException;
+    ModifyResult<I> delete(CompiledQuery query, EntityDefinition entityDefinition) throws IOException;
 
     /**
-     * Execute delete operation
+     * Execute delete operation by entity ids
      *
      * @throws IOException
      */
-    ModifyResult<I> delete(CompiledQuery query, EntityDefinition entityDefinition) throws IOException;
+    ModifyResult<I> deleteByID(List<I> ids, EntityDefinition entityDefinition) throws IOException;
 
     /**
      * Execute query to return a list of results, may not always tagged entities
index a47af9f..8ea1630 100644 (file)
@@ -31,10 +31,12 @@ import java.util.Properties;
  * @since 3/20/15
  */
 public class DataStorageManager {
-    public final static String EAGLE_STORAGE_TYPE = "eagle.service.storage-type";
-    public final static String DEFAULT_DATA_STORAGE_TYPE = "hbase";
+    public static final String EAGLE_STORAGE_TYPE = "eagle.service.storage-type";
+    public static final String DEFAULT_DATA_STORAGE_TYPE = "hbase";
 
-    private final static Logger LOG = LoggerFactory.getLogger(DataStorageManager.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DataStorageManager.class);
+
+    private static DataStorage singletonStorageInstance;
 
     /**
      * Get data storage without cache
@@ -58,39 +60,6 @@ public class DataStorageManager {
         return dataStorage;
     }
 
-    private static DataStorage singletonStorageInstance;
-
-    /**
-     * get storage class by type configured as eagle.storage.type from eagle configuration: config.properties
-     *
-     * @return DataStorage instance
-     * @throws IllegalDataStorageTypeException
-     */
-    public synchronized static DataStorage getDataStorageByEagleConfig(boolean cache) throws IllegalDataStorageTypeException {
-        String storageType = EagleConfigFactory.load().getStorageType();
-
-        if (!cache) {
-            return newDataStorage(storageType);
-        }
-
-        if (singletonStorageInstance == null) {
-            if (storageType == null) {
-                LOG.error(EAGLE_STORAGE_TYPE + " is null, trying default data storage: " + DEFAULT_DATA_STORAGE_TYPE);
-                storageType = DEFAULT_DATA_STORAGE_TYPE;
-            }
-            singletonStorageInstance = newDataStorage(storageType);
-        }
-        return singletonStorageInstance;
-    }
-
-    /**
-     * @return DataStorage instance by singleton pattern
-     * @throws IllegalDataStorageTypeException
-     */
-    public synchronized static DataStorage getDataStorageByEagleConfig() throws IllegalDataStorageTypeException {
-        return getDataStorageByEagleConfig(true);
-    }
-
     /**
      * Get data storage by configuration
      *
@@ -121,4 +90,36 @@ public class DataStorageManager {
         }
         return newDataStorage(storageType);
     }
+
+    /**
+     * get storage class by type configured as eagle.storage.type from eagle configuration: config.properties
+     *
+     * @return DataStorage instance
+     * @throws IllegalDataStorageTypeException
+     */
+    public static synchronized DataStorage getDataStorageByEagleConfig(boolean cache) throws IllegalDataStorageTypeException {
+        String storageType = EagleConfigFactory.load().getStorageType();
+
+        if (!cache) {
+            return newDataStorage(storageType);
+        }
+
+        if (singletonStorageInstance == null) {
+            if (storageType == null) {
+                LOG.error(EAGLE_STORAGE_TYPE + " is null, trying default data storage: " + DEFAULT_DATA_STORAGE_TYPE);
+                storageType = DEFAULT_DATA_STORAGE_TYPE;
+            }
+            singletonStorageInstance = newDataStorage(storageType);
+        }
+        return singletonStorageInstance;
+    }
+
+    /**
+     * @return DataStorage instance by singleton pattern
+     * @throws IllegalDataStorageTypeException
+     */
+    public static synchronized DataStorage getDataStorageByEagleConfig() throws IllegalDataStorageTypeException {
+        return getDataStorageByEagleConfig(true);
+    }
+
 }
\ No newline at end of file
index ddd520d..8d2c804 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.eagle.storage.exception;
 /**
  * @since 3/20/15
  */
-public class IllegalDataStorageException extends Exception{
+public class IllegalDataStorageException extends Exception {
     public IllegalDataStorageException() {
         super();
     }
index e0b99d9..3ef7758 100644 (file)
@@ -19,7 +19,7 @@ package org.apache.eagle.storage.exception;
 /**
  * @since 3/20/15
  */
-public class IllegalDataStorageTypeException extends Exception{
+public class IllegalDataStorageTypeException extends Exception {
     public IllegalDataStorageTypeException() {
         super();
     }
index 9ec5751..5c23016 100644 (file)
@@ -40,8 +40,21 @@ import java.util.Set;
  * @since 3/23/15
  */
 public class CompiledQuery {
-    private final static Logger LOG = LoggerFactory.getLogger(CompiledQuery.class);
+    private static final Logger LOG = LoggerFactory.getLogger(CompiledQuery.class);
     private boolean timeSeries;
+    private String serviceName;
+    private SearchCondition searchCondition;
+    private final RawQuery rawQuery;
+    private boolean hasAgg;
+    private List<AggregateFunctionType> aggregateFunctionTypes;
+    private List<SortOption> sortOptions;
+    private List<AggregateFunctionType> sortFunctions;
+    private List<String> sortFields;
+    private List<String> groupByFields;
+
+    private long startTime;
+    private long endTime;
+    private List<String> aggregateFields;
 
     public boolean isHasAgg() {
         return hasAgg;
@@ -84,7 +97,6 @@ public class CompiledQuery {
     }
 
     public static Logger getLog() {
-
         return LOG;
     }
 
@@ -108,18 +120,6 @@ public class CompiledQuery {
         return rawQuery;
     }
 
-    private String serviceName;
-    private SearchCondition searchCondition;
-    private final RawQuery rawQuery;
-    private boolean hasAgg;
-    private List<AggregateFunctionType> aggregateFunctionTypes;
-    private List<SortOption> sortOptions;
-    private List<AggregateFunctionType> sortFunctions;
-    private List<String> sortFields;
-    private List<String> groupByFields;
-
-    private long startTime;
-
     public long getEndTime() {
         return endTime;
     }
@@ -136,8 +136,6 @@ public class CompiledQuery {
         this.startTime = startTime;
     }
 
-    private long endTime;
-
     public List<String> getAggregateFields() {
         return aggregateFields;
     }
@@ -146,8 +144,6 @@ public class CompiledQuery {
         this.aggregateFields = aggregateFields;
     }
 
-    private List<String> aggregateFields;
-
     public CompiledQuery(RawQuery rawQueryCondition) throws QueryCompileException {
         this.rawQuery = rawQueryCondition;
         try {
@@ -165,19 +161,22 @@ public class CompiledQuery {
         this.groupByFields = groupByFields;
     }
 
-    private void validateQueryParameters(String startRowkey, int pageSize){
-        if(pageSize < 0){
-            throw new IllegalArgumentException("Positive pageSize value should be always provided. The list query format is:\n" + "eagle-service/rest/list?query=<querystring>&pageSize=10&startRowkey=xyz&startTime=xxx&endTime=xxx");
+    private void validateQueryParameters(String startRowkey, int pageSize) {
+        if (pageSize < 0) {
+            throw new IllegalArgumentException("Positive pageSize value should be always provided. The list query format is:\n"
+                + "eagle-service/rest/list?query=<querystring>&pageSize=10&startRowkey=xyz&startTime=xxx&endTime=xxx");
         }
 
-        if(startRowkey != null && startRowkey.equals("null")){
+        if (startRowkey != null && startRowkey.equals("null")) {
             LOG.warn("startRowkey being null string is not same to startRowkey == null");
         }
         return;
     }
 
-    private void checkNotNull(Object obj,String name){
-        if(obj == null) throw new IllegalArgumentException(name+" should not be null");
+    private void checkNotNull(Object obj, String name) {
+        if (obj == null) {
+            throw new IllegalArgumentException(name + " should not be null");
+        }
     }
 
     protected void compile() throws Exception {
@@ -192,7 +191,7 @@ public class CompiledQuery {
         this.searchCondition.setOutputAlias(compiler.getOutputAlias());
         this.searchCondition.setFilter(compiler.filter());
         this.searchCondition.setQueryExpression(compiler.getQueryExpression());
-        if(compiler.sortOptions() == null && this.rawQuery.getTop() > 0) {
+        if (compiler.sortOptions() == null && this.rawQuery.getTop() > 0) {
             LOG.warn("Parameter \"top\" is only used for sort query! Ignore top parameter this time since it's not a sort query");
         }
 
@@ -212,12 +211,12 @@ public class CompiledQuery {
 
         // 3. Set time range if it's timeseries service
         EntityDefinition ed = EntityDefinitionManager.getEntityByServiceName(serviceName);
-        if(ed.isTimeSeries()){
+        if (ed.isTimeSeries()) {
             // TODO check Time exists for timeseries or topology data
             long endTimeMillis = System.currentTimeMillis();
             long startTimeMills = endTimeMillis - 30 * DateTimeUtil.ONEDAY;
 
-            if(this.rawQuery.getStartTime() != null && this.rawQuery.getEndTime() != null) {
+            if (this.rawQuery.getStartTime() != null && this.rawQuery.getEndTime() != null) {
                 endTimeMillis = DateTimeUtil.parseTimeStrToMilliseconds(rawQuery.getEndTime());
                 startTimeMills = DateTimeUtil.parseTimeStrToMilliseconds(rawQuery.getStartTime());
             } else {
@@ -227,7 +226,7 @@ public class CompiledQuery {
             this.searchCondition.setEndTime(endTimeMillis);
             this.setStartTime(startTimeMills);
             this.setEndTime(endTimeMillis);
-        }else{
+        } else {
             this.searchCondition.setStartTime(0);
             this.searchCondition.setEndTime(1);
             this.setStartTime(0);
@@ -244,21 +243,29 @@ public class CompiledQuery {
         List<String> outputFields = compiler.outputFields();
         List<String> groupbyFields = compiler.groupbyFields();
         List<String> aggregateFields = compiler.aggregateFields();
-        Set<String> filterFields = compiler.getFilterFields();
 
         // Start to generate output fields list {
         searchCondition.setOutputAll(compiler.isOutputAll());
-        if(outputFields == null) outputFields = new ArrayList<String>();
-        if(compiler.hasAgg()){
-            if(groupbyFields != null) outputFields.addAll(groupbyFields);
-            if(aggregateFields != null) outputFields.addAll(aggregateFields);
-            if(GenericMetricEntity.GENERIC_METRIC_SERVICE.equals(serviceName) && !outputFields.contains(GenericMetricEntity.VALUE_FIELD)){
+        if (outputFields == null) {
+            outputFields = new ArrayList<String>();
+        }
+        if (compiler.hasAgg()) {
+            if (groupbyFields != null) {
+                outputFields.addAll(groupbyFields);
+            }
+            if (aggregateFields != null) {
+                outputFields.addAll(aggregateFields);
+            }
+            if (GenericMetricEntity.GENERIC_METRIC_SERVICE.equals(serviceName) && !outputFields.contains(GenericMetricEntity.VALUE_FIELD)) {
                 outputFields.add(GenericMetricEntity.VALUE_FIELD);
             }
         }
-        if(filterFields!=null) outputFields.addAll(filterFields);
+        Set<String> filterFields = compiler.getFilterFields();
+        if (filterFields != null) {
+            outputFields.addAll(filterFields);
+        }
         searchCondition.setOutputFields(outputFields);
-        if(LOG.isDebugEnabled()) {
+        if (LOG.isDebugEnabled()) {
             if (compiler.isOutputAll()) {
                 LOG.debug("Output fields: all");
             } else {
@@ -275,7 +282,7 @@ public class CompiledQuery {
         this.timeSeries = timeSeries;
     }
 
-    public long getIntervalMin(){
+    public long getIntervalMin() {
         return this.getRawQuery().getIntervalmin();
     }
 }
\ No newline at end of file
index 80256e1..13fcc60 100644 (file)
@@ -32,7 +32,7 @@ public class CreateStatement implements Statement<ModifyResult<String>> {
     private final List<? extends TaggedLogAPIEntity> entities;
     private final EntityDefinition entityDefinition;
 
-    public CreateStatement(List<? extends TaggedLogAPIEntity> entities,String serviceName){
+    public CreateStatement(List<? extends TaggedLogAPIEntity> entities,String serviceName) {
         this.entities = entities;
 
         try {
@@ -44,14 +44,14 @@ public class CreateStatement implements Statement<ModifyResult<String>> {
         }
     }
 
-    public CreateStatement(List<? extends TaggedLogAPIEntity> entities,EntityDefinition entityDefinition){
+    public CreateStatement(List<? extends TaggedLogAPIEntity> entities,EntityDefinition entityDefinition) {
         this.entities = entities;
         this.entityDefinition = entityDefinition;
     }
 
-    private void checkNotNull(Object obj,String fieldName){
-        if(obj == null){
-            throw new IllegalArgumentException(fieldName+" is null");
+    private void checkNotNull(Object obj, String fieldName) {
+        if (obj == null) {
+            throw new IllegalArgumentException(fieldName + " is null");
         }
     }
 
index 37f5397..d4733e4 100644 (file)
@@ -36,7 +36,7 @@ public class DeleteStatement implements Statement<ModifyResult<String>> {
 
     private EntityDefinition entityDefinition;
 
-    public DeleteStatement(String serviceName){
+    public DeleteStatement(String serviceName) {
         try {
             this.entityDefinition = EntityDefinitionManager.getEntityByServiceName(serviceName);
         } catch (InstantiationException e) {
@@ -46,7 +46,7 @@ public class DeleteStatement implements Statement<ModifyResult<String>> {
         }
     }
 
-    public DeleteStatement(Class<? extends TaggedLogAPIEntity> entityClass){
+    public DeleteStatement(Class<? extends TaggedLogAPIEntity> entityClass) {
         try {
             this.entityDefinition = EntityDefinitionManager.getEntityDefinitionByEntityClass(entityClass);
         } catch (InstantiationException e) {
@@ -56,41 +56,41 @@ public class DeleteStatement implements Statement<ModifyResult<String>> {
         }
     }
 
-    public DeleteStatement(RawQuery query){
+    public DeleteStatement(RawQuery query) {
         this.query = query;
     }
 
-    public void setIds(List ids){
+    public void setIds(List ids) {
         this.ids = ids;
     }
 
-    public void setEntities(List<? extends TaggedLogAPIEntity> entities){
+    public void setEntities(List<? extends TaggedLogAPIEntity> entities) {
         this.entities = entities;
     }
 
-//    public void setQuery(RawQuery query){
-//        this.query = query;
-//    }
+    //    public void setQuery(RawQuery query) {
+    //        this.query = query;
+    //    }
 
     @SuppressWarnings("unchecked")
     @Override
-    public ModifyResult<String> execute(DataStorage storage) throws IOException{
+    public ModifyResult<String> execute(DataStorage storage) throws IOException {
         ModifyResult result;
         try {
-            if(this.ids !=null){
+            if (this.ids != null) {
                 result = storage.deleteByID(this.ids,this.entityDefinition);
-            }else if(this.entities != null){
-                result =storage.delete(this.entities, this.entityDefinition);
-            }else if(this.query != null){
+            } else if (this.entities != null) {
+                result = storage.delete(this.entities, this.entityDefinition);
+            } else if (this.query != null) {
                 CompiledQuery compiledQuery = storage.compile(this.query);
                 this.entityDefinition = EntityDefinitionManager.getEntityByServiceName(compiledQuery.getServiceName());
                 result = storage.delete(compiledQuery,this.entityDefinition);
-            }else{
+            } else {
                 throw new IllegalStateException("bad delete statement, not given enough parameters");
             }
         } catch (QueryCompileException e) {
             throw new IOException(e);
-        }catch (Exception ex){
+        } catch (Exception ex) {
             throw new IOException(ex);
         }
         return result;
index ca40961..44f6fe0 100644 (file)
@@ -27,10 +27,10 @@ import java.io.IOException;
 /**
  * @since 3/18/15
  */
-public class QueryStatement implements Statement<QueryResult<?>>{
+public class QueryStatement implements Statement<QueryResult<?>> {
     private final RawQuery query;
 
-    public QueryStatement(RawQuery queryCondition){
+    public QueryStatement(RawQuery queryCondition) {
         this.query = queryCondition;
     }
 
index 9741638..c457d5d 100755 (executable)
@@ -142,17 +142,21 @@ public class RawQuery {
         this.metricName = metricName;
     }
 
-    public static Builder build(){
+    public static Builder build() {
         return new Builder();
     }
-    public static class Builder{
+
+    public static class Builder {
         private final RawQuery rawQuery;
-        public Builder(){
-            this.rawQuery= new RawQuery();
+
+        public Builder() {
+            this.rawQuery = new RawQuery();
         }
-        public RawQuery done(){
+
+        public RawQuery done() {
             return this.rawQuery;
         }
+
         public Builder query(String query) {
             this.rawQuery.setQuery(query);
             return this;
@@ -214,7 +218,9 @@ public class RawQuery {
         }
 
         public Builder verbose(Boolean verbose) {
-            if(verbose == null) verbose = true;
+            if (verbose == null) {
+                verbose = true;
+            }
             this.rawQuery.setVerbose(verbose);
             return this;
         }
index 017224c..68456f2 100644 (file)
@@ -28,7 +28,7 @@ import java.util.List;
 /**
  * @since 6/29/15
  */
-public class RowkeyQueryStatement implements Statement<QueryResult<?>>{
+public class RowkeyQueryStatement implements Statement<QueryResult<?>> {
     private final List<String> rowkeys;
     private final EntityDefinition entityDefinition;
 
index 1c59e0b..7dc683e 100644 (file)
@@ -33,7 +33,7 @@ public class UpdateStatement implements Statement<ModifyResult<String>> {
 
     private final EntityDefinition entityDefinition;
 
-    public UpdateStatement(List<? extends TaggedLogAPIEntity> entities,String serviceName){
+    public UpdateStatement(List<? extends TaggedLogAPIEntity> entities,String serviceName) {
         this.entities = entities;
         try {
             this.entityDefinition = EntityDefinitionManager.getEntityByServiceName(serviceName);
@@ -44,7 +44,7 @@ public class UpdateStatement implements Statement<ModifyResult<String>> {
         }
     }
 
-    public UpdateStatement(List<? extends TaggedLogAPIEntity> entities,EntityDefinition entityDefinition){
+    public UpdateStatement(List<? extends TaggedLogAPIEntity> entities,EntityDefinition entityDefinition) {
         this.entities = entities;
         this.entityDefinition = entityDefinition;
     }
index 492be08..ee5afde 100644 (file)
@@ -20,6 +20,10 @@ package org.apache.eagle.storage.result;
  * @since 3/18/15
  */
 public class Result {
+    private boolean success;
+
+    private int size;
+
     public boolean isSuccess() {
         return success;
     }
@@ -27,9 +31,6 @@ public class Result {
     public void setSuccess(boolean success) {
         this.success = success;
     }
-    private boolean success;
-
-    private int size;
 
     public void setSize(int size) {
         this.size = size;
index 2d747ab..c95fe3e 100644 (file)
@@ -26,7 +26,7 @@ import java.util.*;
  * @since 3/20/15
  */
 public class DataStorageServiceLoader {
-    private final Logger LOG = LoggerFactory.getLogger(DataStorageServiceLoader.class);
+    private static final Logger LOG = LoggerFactory.getLogger(DataStorageServiceLoader.class);
     private final ServiceLoader<DataStorageServiceProvider> serviceLoader;
     private final Map<String, DataStorageServiceProvider> storageServiceProviders;
 
index 0976bbb..cea7a77 100644 (file)
@@ -26,7 +26,7 @@ import java.net.URI;
  */
 public class TestUri {
     @Test
-    public void testUri(){
+    public void testUri() {
         String url = "eagle:hbase://zk1:2181,zk2:2181/hbase?connectionTimeout=12";
         String cleanURI = url.substring(6);
 
index a59a5d8..4673244 100644 (file)
@@ -36,7 +36,7 @@ public class TestCompiledQuery {
 
     static EntityDefinition entityDefinition = null;
 
-    final String queryStr = "TestTimeSeriesAPIEntity[@cluster=\"c4ut\"]{*}";
+    final String queryStr = "TestTimeSeriesAPIEntity[@cluster =\"c4ut\"]{*}";
     final int pageSize = 1000;
     final long baseTimestamp = createTimeStamp(2017, 0, 11, 0, 0, 0);
     final String startTime = DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp);
index 60a0839..a08bb8b 100644 (file)
@@ -20,8 +20,6 @@ import org.apache.eagle.log.entity.meta.EntityDefinitionManager;
 import org.apache.eagle.log.entity.test.TestTimeSeriesAPIEntity;
 import org.apache.eagle.storage.DataStorage;
 import org.junit.Test;
-import org.mockito.Mock;
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
index 0920c10..274a2cd 100644 (file)
@@ -23,7 +23,7 @@ import org.junit.Test;
  * @since 3/20/15
  */
 public class TestDataStorageServiceProvider implements DataStorageServiceProvider {
-    private final static String TEST = "test";
+    private static final String TEST = "test";
 
     @Override
     public String getType() {