├── 3rdparty.md ├── LICENSE ├── README.md ├── pom.xml ├── pulsarquery-admin ├── pom.xml └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── ebay │ │ │ └── pulsar │ │ │ └── analytics │ │ │ ├── security │ │ │ └── spring │ │ │ │ ├── GlobalSecuritySetting.java │ │ │ │ ├── PermissionControlCache.java │ │ │ │ ├── PlainTextBasicAuthenticationEntryPoint.java │ │ │ │ ├── PulsarSession.java │ │ │ │ └── PulsarUserDetailService.java │ │ │ └── service │ │ │ ├── DashboardService.java │ │ │ ├── DataSourceService.java │ │ │ ├── GroupService.java │ │ │ ├── PermissionConst.java │ │ │ ├── SysPermission.java │ │ │ ├── UserPermissionControl.java │ │ │ └── UserService.java │ └── resources │ │ └── mysql.sql │ └── test │ ├── java │ └── com │ │ └── ebay │ │ └── pulsar │ │ └── analytics │ │ ├── service │ │ ├── DashboardServiceTest.java │ │ ├── DatasourceServiceTest.java │ │ ├── GroupServiceTest.java │ │ ├── PermissionConstTest.java │ │ ├── ReflectFieldUtil.java │ │ ├── UserPermissionControlTest.java │ │ └── UserServiceTest.java │ │ └── spring │ │ └── security │ │ └── GlobalSecuritySettingTest.java │ └── resources │ └── spring │ ├── authentication-security.xml │ └── pulsar-datasource.xml ├── pulsarquery-cache ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── ebay │ │ └── pulsar │ │ └── analytics │ │ └── cache │ │ ├── ByteCountingLRUMap.java │ │ ├── BytesBoundedLinkedQueue.java │ │ ├── Cache.java │ │ ├── CacheConfig.java │ │ ├── CacheProvider.java │ │ ├── CacheStats.java │ │ ├── LZ4Transcoder.java │ │ ├── MapCache.java │ │ ├── MemcachedCache.java │ │ ├── MemcachedCacheConfig.java │ │ └── MemcachedOperationQueueFactory.java │ └── test │ └── java │ └── com │ └── ebay │ └── pulsar │ └── analytics │ ├── cacheprovider │ └── CacheProviderTest.java │ ├── mapcache │ └── MapCacheTest.java │ └── memcachedcache │ ├── BytesBoundedLinkedQueueTest.java │ ├── MemcachedCacheTest.java │ └── ReflectFieldUtil.java ├── pulsarquery-core ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── ebay │ │ └── pulsar │ │ └── analytics │ │ ├── auth │ │ ├── AuthModels.java │ │ ├── Authentication.java │ │ ├── Authorization.java │ │ ├── UserInfo.java │ │ ├── exceptions │ │ │ └── InvalidSessionException.java │ │ └── impl │ │ │ └── AuthenticationImpl.java │ │ ├── config │ │ ├── Configuration.java │ │ └── ConfigurationFactory.java │ │ ├── constants │ │ ├── Constants.java │ │ └── ConstantsUtils.java │ │ ├── dao │ │ ├── DBFactory.java │ │ ├── DBService.java │ │ ├── RDBMS.java │ │ ├── mapper │ │ │ ├── BaseDBMapper.java │ │ │ ├── DBDashboardMapper.java │ │ │ ├── DBDataSourceMapper.java │ │ │ ├── DBGroupMapper.java │ │ │ ├── DBRightGroupMapper.java │ │ │ ├── DBTableMapper.java │ │ │ ├── DBUserGroupMapper.java │ │ │ └── DBUserMapper.java │ │ ├── model │ │ │ ├── DBDashboard.java │ │ │ ├── DBDataSource.java │ │ │ ├── DBGroup.java │ │ │ ├── DBRightGroup.java │ │ │ ├── DBTable.java │ │ │ ├── DBUser.java │ │ │ └── DBUserGroup.java │ │ └── service │ │ │ ├── BaseDBService.java │ │ │ ├── DBDashboardService.java │ │ │ ├── DBDataSourceService.java │ │ │ ├── DBGroupService.java │ │ │ ├── DBRightGroupService.java │ │ │ ├── DBTableService.java │ │ │ ├── DBUserGroupService.java │ │ │ ├── DBUserService.java │ │ │ └── DirectSQLAccessService.java │ │ ├── datasource │ │ ├── AbstractDataSourceProviderFactory.java │ │ ├── DBConnector.java │ │ ├── DataSourceConfiguration.java │ │ ├── DataSourceMetaRepo.java │ │ ├── DataSourceProvider.java │ │ ├── DataSourceProviderFactory.java │ │ ├── DataSourceRoutingStrategy.java │ │ ├── DataSourceTypeEnum.java │ │ ├── DataSourceTypeRegistry.java │ │ ├── PulsarTable.java │ │ ├── PulsarTableDimension.java │ │ ├── ShutDown.java │ │ ├── Starter.java │ │ ├── Table.java │ │ ├── TableDimension.java │ │ └── loader │ │ │ ├── DataSourceConfigurationLoader.java │ │ │ ├── DynamicDataSourceConfigurationLoader.java │ │ │ ├── DynamicDataSourceConfigurationManager.java │ │ │ ├── PeriodicalConfigurationLoader.java │ │ │ └── StaticDataSourceConfigurationLoader.java │ │ ├── exception │ │ ├── DataSourceConfigurationException.java │ │ ├── DataSourceException.java │ │ ├── ExceptionErrorCode.java │ │ ├── InvalidQueryParameterException.java │ │ └── SqlTranslationException.java │ │ ├── filters │ │ └── ApiOriginFilter.java │ │ ├── query │ │ ├── AbstractSQLQueryProcessor.java │ │ ├── RestQueryProcessor.java │ │ ├── SQLQueryContext.java │ │ ├── SQLQueryProcessor.java │ │ ├── client │ │ │ └── ClientQueryConfig.java │ │ ├── request │ │ │ ├── BaseRequest.java │ │ │ ├── BaseSQLRequest.java │ │ │ ├── CoreRequest.java │ │ │ ├── DateRange.java │ │ │ ├── GeneralSQLRequest.java │ │ │ ├── PulsarDateTimeFormatter.java │ │ │ ├── RealtimeRequest.java │ │ │ └── SQLRequest.java │ │ ├── response │ │ │ ├── ErrorResponse.java │ │ │ ├── QueryResponse.java │ │ │ ├── TraceAbleResponse.java │ │ │ └── TraceQuery.java │ │ ├── result │ │ │ ├── ChainedRevisor.java │ │ │ ├── ColumnNameRevisor.java │ │ │ ├── ColumnValueCollector.java │ │ │ ├── HllMetricRevisor.java │ │ │ ├── ResultEnricher.java │ │ │ ├── ResultNode.java │ │ │ └── ResultRevisor.java │ │ ├── sql │ │ │ ├── FilterHavingParser.java │ │ │ ├── SQLTranslator.java │ │ │ └── SimpleTableNameParser.java │ │ └── validator │ │ │ ├── QueryValidator.java │ │ │ └── SQLQueryValidator.java │ │ └── util │ │ ├── JsonUtil.java │ │ ├── PulsarQueryScheduler.java │ │ ├── Serializer.java │ │ └── Slugify.java │ └── test │ └── java │ └── com │ └── ebay │ └── pulsar │ └── analytics │ ├── auth │ └── AuthModelsTest.java │ ├── datasource │ ├── DataSourceConfigurationTest.java │ ├── DataSourceMetaRepoTest.java │ ├── PulsarTableTest.java │ └── TableTest.java │ ├── metricstore │ └── db │ │ ├── AbstracDataSourceProviderFactoryTest.java │ │ ├── BaseDBServiceTest.java │ │ ├── DBModelTest.java │ │ ├── RDMBSTest.java │ │ └── ReflectFieldUtil.java │ ├── query │ ├── AbstractSQLQueryProcessTest.java │ ├── FilterHavingParserTest.java │ ├── QueryTest.java │ ├── SQLTranslatorTest.java │ ├── response │ │ └── TraceAbleResponseTest.java │ ├── result │ │ ├── ChainedRevisorTest.java │ │ ├── ColumnNameRevisorTest.java │ │ └── HllMetricRevisorTest.java │ └── validator │ │ └── SQLQueryValidatorTest.java │ └── util │ ├── JsonUtilTest.java │ ├── SerializerTest.java │ └── SlugifyTest.java ├── pulsarquery-druid ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── ebay │ │ └── pulsar │ │ └── analytics │ │ ├── datasource │ │ ├── ClientHelper.java │ │ ├── DruidDataSourceProviderFactory.java │ │ ├── DruidRestDBConnector.java │ │ └── DruidRestTableMeta.java │ │ └── metricstore │ │ └── druid │ │ ├── aggregator │ │ ├── BaseAggregator.java │ │ ├── CardinalityAggregator.java │ │ ├── CountAggregator.java │ │ ├── DoubleSumAggregator.java │ │ ├── FilteredAggregator.java │ │ ├── HyperUniqueAggregator.java │ │ ├── LongSumAggregator.java │ │ ├── MaxAggregator.java │ │ └── MinAggregator.java │ │ ├── constants │ │ └── Constants.java │ │ ├── filter │ │ ├── AndFilter.java │ │ ├── BaseFilter.java │ │ ├── FilterCacheHelper.java │ │ ├── NotFilter.java │ │ ├── OrFilter.java │ │ ├── RegexFilter.java │ │ └── SelectorFilter.java │ │ ├── granularity │ │ ├── BaseGranularity.java │ │ ├── DruidGranularityParser.java │ │ ├── DurationGranularity.java │ │ ├── InvalidGranularity.java │ │ ├── PeriodGranularity.java │ │ └── SimpleGranularity.java │ │ ├── having │ │ ├── AndHaving.java │ │ ├── BaseHaving.java │ │ ├── EqualToHaving.java │ │ ├── GreaterThanHaving.java │ │ ├── HavingCacheHelper.java │ │ ├── LessThanHaving.java │ │ ├── NotHaving.java │ │ └── OrHaving.java │ │ ├── limitspec │ │ ├── DefaultLimitSpec.java │ │ └── OrderByColumnSpec.java │ │ ├── metric │ │ ├── AlphaNumericMetric.java │ │ ├── BaseMetric.java │ │ ├── InvertedMetric.java │ │ ├── LexicographicMetric.java │ │ └── NumericMetric.java │ │ ├── postaggregator │ │ ├── ArithmeticPostAggregator.java │ │ ├── BasePostAggregator.java │ │ ├── ConstantPostAggregator.java │ │ ├── FieldAccessorPostAggregator.java │ │ ├── HyperUniqueCardinalityPostAggregator.java │ │ └── PostAggregatorCacheHelper.java │ │ └── query │ │ ├── DruidQueryParameter.java │ │ ├── DruidQueryProcessor.java │ │ ├── model │ │ ├── BaseQuery.java │ │ ├── DruidSpecs.java │ │ ├── GroupByQuery.java │ │ ├── QueryCacheHelper.java │ │ ├── TimeSeriesQuery.java │ │ └── TopNQuery.java │ │ ├── sql │ │ ├── AbstractDruidSqlTranslator.java │ │ ├── DruidAggregatorTranslator.java │ │ ├── DruidFilterTranslator.java │ │ ├── DruidHavingTranslator.java │ │ ├── DruidOrderByTranslator.java │ │ ├── DruidPostAggregatorTranslator.java │ │ ├── DruidSQLTranslator.java │ │ └── HllConstants.java │ │ └── validator │ │ ├── DruidGranularityValidator.java │ │ └── GranularityAndTimeRange.java │ └── test │ ├── java │ └── com │ │ └── ebay │ │ └── pulsar │ │ └── analytics │ │ ├── ReflectFieldUtil.java │ │ └── metricstore │ │ ├── datasource │ │ └── DataSourceTest.java │ │ ├── druid │ │ ├── aggregator │ │ │ └── AggregatorTest.java │ │ ├── filter │ │ │ └── FilterTest.java │ │ ├── having │ │ │ └── HavingTest.java │ │ ├── metric │ │ │ └── MetricTest.java │ │ ├── postaggregator │ │ │ └── PostAggregatorTest.java │ │ └── query │ │ │ └── QueryTest.java │ │ ├── granularity │ │ └── GranularityTest.java │ │ ├── limitspec │ │ └── LimitSpecTest.java │ │ ├── query │ │ ├── DruidQueryParameterTest.java │ │ ├── DruidQueryProcessorBugFix.java │ │ └── DruidQueryProcessorTest.java │ │ └── validator │ │ └── ValidatorsTest.java │ └── resources │ ├── datasources │ └── druid.properties │ ├── querys.txt │ ├── raws.txt │ └── results.txt ├── pulsarquery-pulsar ├── pom.xml └── src │ ├── main │ └── java │ │ └── com │ │ └── ebay │ │ └── pulsar │ │ └── analytics │ │ ├── datasource │ │ ├── PulsarDataBaseConnector.java │ │ ├── PulsarDataSourceConfiguration.java │ │ ├── PulsarDataSourceProviderFactory.java │ │ ├── PulsarDataSourceRoutingStrategy.java │ │ ├── PulsarDataSourceRule.java │ │ ├── PulsarRestMetricMeta.java │ │ ├── PulsarRestMetricRegistry.java │ │ └── loader │ │ │ └── PulsarDataSourceConfigurationLoader.java │ │ └── holap │ │ └── query │ │ ├── DruidFilterParser.java │ │ ├── DruidHavingParser.java │ │ ├── RestQueryProcessorImpl.java │ │ ├── model │ │ └── QueryMetricProps.java │ │ └── validator │ │ └── PulsarRestValidator.java │ └── test │ ├── java │ └── com │ │ └── ebay │ │ └── pulsar │ │ └── analytics │ │ ├── datasource │ │ ├── PulsarDataBaseConnectorTest.java │ │ ├── PulsarDataSourceRoutingStrategyTest.java │ │ ├── PulsarDataSourceRuleTest.java │ │ └── ReflectFieldUtil.java │ │ └── holap │ │ └── query │ │ ├── DruidFilterParserTest.java │ │ ├── DruidHavingParserTest.java │ │ ├── RestQueryProcessorImplTest.java │ │ └── validator │ │ └── PulsarRestValidatorTest.java │ └── resources │ └── datasourceconfig.xml └── pulsarquery-service ├── pom.xml └── src └── main ├── java └── com │ └── ebay │ └── pulsar │ └── analytics │ ├── Dashboard.java │ └── resources │ ├── CachingResource.java │ ├── PermissionControlResource.java │ ├── PulsarQueryResource.java │ ├── exception │ └── InvalidAPIParameterException.java │ └── init │ └── PulsarQueryBootstrap.java ├── resources ├── context.xml ├── datasources │ └── druid.properties ├── env.xml ├── logback.xml ├── pulsar-config.properties ├── pulsar-datasource.xml ├── query-config.xml └── simple │ ├── authentication-security.xml │ ├── pulsarholp-config.xml │ └── restmetric-config.xml └── webapp └── WEB-INF ├── deployServlet-servlet.xml └── web.xml /3rdparty.md: -------------------------------------------------------------------------------- 1 | # External dependencies 2 | 3 | ## Apache License 4 | 5 | [License link](http://www.apache.org/licenses/LICENSE-2.0) 6 | 7 | 1. foundationdb sql parser 8 | 2. Stream - https://github.com/addthis/stream-lib 9 | 3. Resteasy - http://resteasy.jboss.org/ 10 | 4. Joda time - http://www.joda.org/joda-time/ 11 | 5. Spring - https://spring.io/ 12 | 6. Logback - http://logback.qos.ch/ 13 | 7. Jackson - https://github.com/FasterXML 14 | 8. lz4 - https://github.com/jpountz/lz4-java 15 | 9. guava - https://github.com/google/guava 16 | 10. apache common - https://github.com/apache 17 | 11. ehcache - https://github.com/ehcache 18 | 12. powermock - https://github.com/jayway/powermock 19 | 13. jetty - https://github.com/eclipse/jetty.project 20 | 21 | 22 | ## MIT License 23 | 24 | 1. Mockito - https://github.com/mockito/mockito 25 | 2. slf4j - https://github.com/qos-ch/slf4j 26 | 27 | ## Eclipse Public License - v 1.0 28 | 1. JUnit - https://github.com/junit-team/junit 29 | 30 | 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Pulsar Reporting API 2 | =================== 3 | 4 | Pulsar Reporting API provides an abstract data access layer on top of metric stores. Supports both SQL and structured JSON queries. 5 | 6 | See [**wiki**](../../wiki) for more detail. 7 | -------------------------------------------------------------------------------- /pulsarquery-admin/src/main/java/com/ebay/pulsar/analytics/security/spring/GlobalSecuritySetting.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.security.spring; 7 | 8 | import org.springframework.beans.factory.InitializingBean; 9 | import org.springframework.beans.factory.annotation.Autowired; 10 | import org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor; 11 | 12 | import com.google.common.base.Preconditions; 13 | 14 | /** 15 | * @author qxing 16 | * 17 | * Modify MethodSecurityInterceptor property alwaysReauthenticate 18 | * set it to true. 19 | **/ 20 | public class GlobalSecuritySetting implements InitializingBean { 21 | @Autowired 22 | MethodSecurityInterceptor interceptor; 23 | 24 | @Override 25 | public void afterPropertiesSet() throws Exception { 26 | Preconditions.checkNotNull(interceptor); 27 | if (!interceptor.isAlwaysReauthenticate()) { 28 | interceptor.setAlwaysReauthenticate(true); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /pulsarquery-admin/src/main/java/com/ebay/pulsar/analytics/security/spring/PlainTextBasicAuthenticationEntryPoint.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.security.spring; 7 | 8 | import java.io.IOException; 9 | import java.io.PrintWriter; 10 | 11 | import javax.servlet.ServletException; 12 | import javax.servlet.http.HttpServletRequest; 13 | import javax.servlet.http.HttpServletResponse; 14 | 15 | import org.springframework.security.core.AuthenticationException; 16 | import org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint; 17 | 18 | /** 19 | * 20 | *@author qxing 21 | * 22 | **/ 23 | public class PlainTextBasicAuthenticationEntryPoint extends 24 | BasicAuthenticationEntryPoint { 25 | @Override 26 | public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { 27 | response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\""); 28 | response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 29 | PrintWriter writer = response.getWriter(); 30 | writer.println("HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage()); 31 | 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /pulsarquery-admin/src/main/java/com/ebay/pulsar/analytics/security/spring/PulsarSession.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.security.spring; 7 | 8 | import java.util.Set; 9 | 10 | import org.springframework.security.core.authority.SimpleGrantedAuthority; 11 | 12 | import com.ebay.pulsar.analytics.dao.model.DBUser; 13 | 14 | /** 15 | * 16 | *@author qxing 17 | * 18 | **/ 19 | public class PulsarSession { 20 | DBUser user; 21 | Set authorities; 22 | public PulsarSession(DBUser user,Set authorities){ 23 | this.user=user; 24 | this.authorities=authorities; 25 | } 26 | public DBUser getUser() { 27 | return user; 28 | } 29 | public Set getAuthorities() { 30 | return authorities; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /pulsarquery-admin/src/main/java/com/ebay/pulsar/analytics/service/PermissionConst.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.service; 7 | 8 | import com.google.common.collect.ImmutableSet; 9 | 10 | /** 11 | * 12 | *@author qxing 13 | * 14 | **/ 15 | public class PermissionConst { 16 | //thirdpartyauthentication 17 | public static final String THIRD_PARTY_AUTHENTICATION_PASSWORD="d98f3a9f13cf4b0485b89c6462242a31"; 18 | public static final String PUBLICGROUP="public"; 19 | public static final String ADMINGROUP="admin"; 20 | public static final String MANAGE_RIGHT_TEMPLATE="%s_MANAGE"; 21 | public static final String VIEW_RIGHT_TEMPLATE="%s_VIEW"; 22 | public static final String DATA_TABLE_RIGHT_TEMPLATE="%s_%s"; 23 | public static final String RESOURCE_NAME_TEMPLATGE="%s_%d"; 24 | public static final int RIGHT_TYPE_SYS=0; 25 | public static final int RIGHT_TYPE_DATA=1; 26 | public static final int RIGHT_TYPE_DASHBOARD=2; 27 | public static final int RIGHT_TYPE_MENU=3; 28 | public static final int RIGHT_TYPE_GROUP=4; 29 | public static final ImmutableSet reservedGroup=ImmutableSet.of(ADMINGROUP); 30 | 31 | public static final ImmutableSet sysRights=ImmutableSet.of( 32 | SysPermission.ADD_DASHBOARD.toString(), 33 | SysPermission.ADD_DATASOURCE.toString(), 34 | SysPermission.ADD_GROUP.toString(), 35 | SysPermission.SYS_MANAGE_DASHBOARD.toString(), 36 | SysPermission.SYS_MANAGE_DATASOURCE.toString(), 37 | SysPermission.SYS_MANAGE_GROUP.toString(), 38 | SysPermission.SYS_VIEW_DASHBOARD.toString(), 39 | SysPermission.SYS_VIEW_DATASOURCE.toString(), 40 | SysPermission.SYS_VIEW_GROUP.toString()); 41 | 42 | public static boolean isReservedGroup(String groupName){ 43 | return reservedGroup.contains(groupName); 44 | } 45 | public static boolean isSysPermission(String rightName){ 46 | return sysRights.contains(rightName); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pulsarquery-admin/src/main/java/com/ebay/pulsar/analytics/service/SysPermission.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.service; 7 | /** 8 | *@author qxing 9 | * 10 | *SYS_ADMIN will have all the permissions. 11 | * 12 | * 13 | **/ 14 | public enum SysPermission { 15 | /** 16 | * Datasource permissions, 17 | * 18 | * Default the creator will have all the permissions for operation of this data source. 19 | * DELETE_DATASOURCE,UPDATE_DATASOURCE, 20 | * 21 | */ 22 | ADD_DATASOURCE,//default the create will have all the permission for the adding datasource. 23 | ADD_GROUP, 24 | ADD_DASHBOARD, 25 | ADD_MENU, 26 | SYS_MANAGE_DATASOURCE, 27 | SYS_VIEW_DATASOURCE, 28 | SYS_MANAGE_DASHBOARD, 29 | SYS_VIEW_DASHBOARD, 30 | SYS_MANAGE_GROUP, 31 | SYS_VIEW_GROUP 32 | 33 | } 34 | -------------------------------------------------------------------------------- /pulsarquery-admin/src/test/java/com/ebay/pulsar/analytics/service/PermissionConstTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.service; 7 | 8 | import org.junit.Assert; 9 | import org.junit.Test; 10 | 11 | public class PermissionConstTest { 12 | 13 | @Test 14 | public void testUtils() throws Exception{ 15 | //Mock to improver ut coverage 16 | Assert.assertEquals("public", PermissionConst.PUBLICGROUP); 17 | Assert.assertEquals("%s_MANAGE", PermissionConst.MANAGE_RIGHT_TEMPLATE); 18 | Assert.assertEquals("%s_VIEW", PermissionConst.VIEW_RIGHT_TEMPLATE); 19 | Assert.assertEquals("%s_%s", PermissionConst.DATA_TABLE_RIGHT_TEMPLATE); 20 | Assert.assertEquals("%s_%d", PermissionConst.RESOURCE_NAME_TEMPLATGE); 21 | Assert.assertEquals(0, PermissionConst.RIGHT_TYPE_SYS); 22 | Assert.assertEquals(1, PermissionConst.RIGHT_TYPE_DATA); 23 | Assert.assertEquals(2, PermissionConst.RIGHT_TYPE_DASHBOARD); 24 | Assert.assertEquals(3, PermissionConst.RIGHT_TYPE_MENU); 25 | Assert.assertEquals(4, PermissionConst.RIGHT_TYPE_GROUP); 26 | } 27 | 28 | 29 | } 30 | -------------------------------------------------------------------------------- /pulsarquery-admin/src/test/resources/spring/authentication-security.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /pulsarquery-cache/src/main/java/com/ebay/pulsar/analytics/cache/Cache.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.cache; 7 | 8 | import java.nio.ByteBuffer; 9 | import java.util.Arrays; 10 | import java.util.Map; 11 | 12 | import com.google.common.base.Charsets; 13 | import com.google.common.base.Preconditions; 14 | import com.google.common.primitives.Ints; 15 | 16 | public interface Cache { 17 | byte[] get(NamedKey key); 18 | 19 | void put(NamedKey key, byte[] value, int expiration); 20 | 21 | Map getBulk(Iterable keys); 22 | 23 | void close(String namespace); 24 | 25 | CacheStats getStats(); 26 | 27 | boolean isLocal(); 28 | 29 | public class NamedKey { 30 | final public String namespace; 31 | final public byte[] key; 32 | 33 | public NamedKey(String namespace, byte[] key) { 34 | Preconditions.checkArgument(namespace != null, "namespace must not be null"); 35 | Preconditions.checkArgument(key != null, "key must not be null"); 36 | this.namespace = namespace; 37 | this.key = key; 38 | } 39 | 40 | public byte[] toByteArray() { 41 | final byte[] nsBytes = this.namespace.getBytes(Charsets.UTF_8); 42 | return ByteBuffer.allocate(Ints.BYTES + nsBytes.length + this.key.length).putInt(nsBytes.length) 43 | .put(nsBytes).put(this.key).array(); 44 | } 45 | 46 | @Override 47 | public boolean equals(Object o) { 48 | if (this == o) { 49 | return true; 50 | } 51 | if (o == null || getClass() != o.getClass()) { 52 | return false; 53 | } 54 | 55 | NamedKey namedKey = (NamedKey) o; 56 | 57 | if (!namespace.equals(namedKey.namespace)) { 58 | return false; 59 | } 60 | if (!Arrays.equals(key, namedKey.key)) { 61 | return false; 62 | } 63 | return true; 64 | } 65 | 66 | @Override 67 | public int hashCode() { 68 | return 31 * namespace.hashCode() + Arrays.hashCode(key); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /pulsarquery-cache/src/main/java/com/ebay/pulsar/analytics/cache/CacheConfig.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.cache; 8 | 9 | import java.util.ArrayList; 10 | import java.util.List; 11 | import java.util.Map; 12 | 13 | import com.google.common.base.Splitter; 14 | 15 | public class CacheConfig { 16 | private boolean useCache; 17 | private boolean populateCache; 18 | private List unCacheable; 19 | private Map expirations; 20 | 21 | public void setUseCache(boolean useCache) { 22 | this.useCache = useCache; 23 | } 24 | 25 | public void setPopulateCache(boolean populateCache) { 26 | this.populateCache = populateCache; 27 | } 28 | 29 | public void setUnCacheable(String unCacheable) { 30 | if(unCacheable == null) 31 | this.unCacheable = new ArrayList(); 32 | else 33 | this.unCacheable = Splitter.on(",").omitEmptyStrings().splitToList(unCacheable); 34 | } 35 | 36 | public boolean isPopulateCache() { 37 | return populateCache; 38 | } 39 | 40 | public boolean isUseCache() { 41 | return useCache; 42 | } 43 | 44 | public boolean isQueryCacheable(String queryTypeName) { 45 | if(unCacheable!=null) 46 | return !unCacheable.contains(queryTypeName); 47 | else 48 | throw new NullPointerException("unCacheable is null"); 49 | } 50 | 51 | public int getExpiration(String type) { 52 | if(expirations!=null) 53 | return expirations.get(type); 54 | else 55 | throw new NullPointerException("expirations is null"); 56 | } 57 | 58 | public Map getExpirations() { 59 | return expirations; 60 | } 61 | 62 | public void setExpirations(Map expirations) { 63 | this.expirations = expirations; 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /pulsarquery-cache/src/main/java/com/ebay/pulsar/analytics/cache/CacheProvider.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.cache; 8 | 9 | public class CacheProvider { 10 | // cache type, memcached or others 11 | private String type; 12 | 13 | private CacheConfig cacheConfig; 14 | 15 | private MemcachedCacheConfig memConfig; 16 | 17 | public String getType() { 18 | return type; 19 | } 20 | 21 | public void setType(String type) { 22 | this.type = type; 23 | } 24 | 25 | public CacheConfig getCacheConfig() { 26 | return cacheConfig; 27 | } 28 | 29 | public void setCacheConfig(CacheConfig cacheConfig) { 30 | this.cacheConfig = cacheConfig; 31 | } 32 | 33 | public MemcachedCacheConfig getMemConfig() { 34 | return memConfig; 35 | } 36 | 37 | public void setMemConfig(MemcachedCacheConfig memConfig) { 38 | this.memConfig = memConfig; 39 | } 40 | 41 | public Cache get() { 42 | if (type.equals("memcached")) { 43 | return MemcachedCache.create(memConfig); 44 | } else { 45 | return null; // other cache types 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pulsarquery-cache/src/main/java/com/ebay/pulsar/analytics/cache/CacheStats.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.cache; 8 | 9 | public class CacheStats { 10 | private final long numHits; 11 | private final long numMisses; 12 | private final long getBytes; 13 | private final long getTime; 14 | private final long numPut; 15 | private final long putBytes; 16 | private final long numEvictions; 17 | private final long numTimeouts; 18 | private final long numErrors; 19 | 20 | public CacheStats(long getBytes, long getTime, long numPut, long putBytes, long numHits, long numMisses, 21 | long numEvictions, long numTimeouts, long numErrors) { 22 | this.getBytes = getBytes; 23 | this.getTime = getTime; 24 | this.numPut = numPut; 25 | this.putBytes = putBytes; 26 | this.numHits = numHits; 27 | this.numMisses = numMisses; 28 | this.numEvictions = numEvictions; 29 | this.numTimeouts = numTimeouts; 30 | this.numErrors = numErrors; 31 | } 32 | 33 | public long getNumHits() { 34 | return numHits; 35 | } 36 | 37 | public long getNumMisses() { 38 | return numMisses; 39 | } 40 | 41 | public long getNumGet() { 42 | return numHits + numMisses; 43 | } 44 | 45 | public long getNumGetBytes() { 46 | return getBytes; 47 | } 48 | 49 | public long getNumPutBytes() { 50 | return putBytes; 51 | } 52 | 53 | public long getNumPut() { 54 | return numPut; 55 | } 56 | 57 | public long getNumEvictions() { 58 | return numEvictions; 59 | } 60 | 61 | public long getNumTimeouts() { 62 | return numTimeouts; 63 | } 64 | 65 | public long getNumErrors() { 66 | return numErrors; 67 | } 68 | 69 | public long numLookups() { 70 | return numHits + numMisses; 71 | } 72 | 73 | public double hitRate() { 74 | long lookups = numLookups(); 75 | return lookups == 0 ? 0 : numHits / (double) lookups; 76 | } 77 | 78 | public long avgGetBytes() { 79 | return getBytes == 0 ? 0 : getBytes / numLookups(); 80 | } 81 | 82 | public long getAvgGetTime() { 83 | return getTime / numLookups(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /pulsarquery-cache/src/main/java/com/ebay/pulsar/analytics/cache/LZ4Transcoder.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.cache; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import net.jpountz.lz4.LZ4Compressor; 12 | import net.jpountz.lz4.LZ4FastDecompressor; 13 | import net.jpountz.lz4.LZ4Factory; 14 | import net.spy.memcached.transcoders.SerializingTranscoder; 15 | 16 | import com.google.common.primitives.Ints; 17 | 18 | public class LZ4Transcoder extends SerializingTranscoder { 19 | private final LZ4Factory lz4Factory; 20 | 21 | public LZ4Transcoder() { 22 | super(); 23 | lz4Factory = LZ4Factory.fastestJavaInstance(); 24 | } 25 | 26 | public LZ4Transcoder(int max) { 27 | super(max); 28 | lz4Factory = LZ4Factory.fastestJavaInstance(); 29 | } 30 | 31 | @Override 32 | protected byte[] compress(byte[] in) { 33 | if (in == null) { 34 | throw new NullPointerException("Can't compress null"); 35 | } 36 | 37 | LZ4Compressor compressor = lz4Factory.fastCompressor(); 38 | 39 | byte[] out = new byte[compressor.maxCompressedLength(in.length)]; 40 | int compressedLength = compressor.compress(in, 0, in.length, out, 0); 41 | 42 | getLogger().debug("Compressed %d bytes to %d", in.length, compressedLength); 43 | 44 | return ByteBuffer.allocate(Ints.BYTES + compressedLength).putInt(in.length).put(out, 0, compressedLength).array(); 45 | } 46 | 47 | @Override 48 | protected byte[] decompress(byte[] in) { 49 | byte[] out = null; 50 | if (in != null) { 51 | LZ4FastDecompressor decompressor = lz4Factory.fastDecompressor(); 52 | 53 | int size = ByteBuffer.wrap(in).getInt(); 54 | out = new byte[size]; 55 | decompressor.decompress(in, Ints.BYTES, out, 0, out.length); 56 | } 57 | return out == null ? null : out; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pulsarquery-cache/src/main/java/com/ebay/pulsar/analytics/cache/MemcachedOperationQueueFactory.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.cache; 8 | 9 | import java.util.concurrent.BlockingQueue; 10 | 11 | import net.spy.memcached.ops.Operation; 12 | import net.spy.memcached.ops.OperationQueueFactory; 13 | 14 | public class MemcachedOperationQueueFactory implements OperationQueueFactory { 15 | public final long maxQueueSize; 16 | 17 | public MemcachedOperationQueueFactory(long maxQueueSize) { 18 | this.maxQueueSize = maxQueueSize; 19 | } 20 | 21 | @Override 22 | public BlockingQueue create() { 23 | return new BytesBoundedLinkedQueue(maxQueueSize) { 24 | @Override 25 | public long getBytesSize(Operation operation) { 26 | return operation.getBuffer().remaining(); 27 | } 28 | }; 29 | } 30 | } -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/auth/AuthModels.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.auth; 7 | 8 | import com.ebay.pulsar.analytics.config.ConfigurationFactory; 9 | import com.google.common.base.Throwables; 10 | 11 | /** 12 | *@author qxing 13 | * 14 | **/ 15 | public class AuthModels { 16 | public static final String AUTHENTICATION_ENABLE_KEY="pulsar.analytics.authentication.enable"; 17 | public static final String AUTHORIZATION_ENABLE_KEY="pulsar.analytics.authorization.enable"; 18 | 19 | public static final String AUTHENTICATION_IMPLEMENTATION_KEY="pulsar.analytics.authentication.impl"; 20 | public static final String AUTHORIZATION_IMPLEMENTATION_KEY="pulsar.analytics.authorization.impl"; 21 | public static Authentication authentication(){ 22 | return AuthenticationHolder.auth; 23 | } 24 | public static Authorization authorization(){ 25 | return AuthorizationHolder.auth; 26 | } 27 | 28 | private static T instance(String clazz, Class parent){ 29 | try{ 30 | Class clz=Class.forName(clazz); 31 | if(parent.isAssignableFrom(clz)){ 32 | Object obj=clz.newInstance(); 33 | T ret=parent.cast(obj); 34 | return ret; 35 | } 36 | throw new RuntimeException("class["+clazz+"] is not assignable to ["+parent.getName()+"]."); 37 | }catch(Exception e){ 38 | Throwables.propagate(e); 39 | } 40 | return null; 41 | } 42 | 43 | private static class AuthenticationHolder{ 44 | private static volatile Authentication auth; 45 | static{ 46 | auth=instance(ConfigurationFactory.instance().getString(AUTHENTICATION_IMPLEMENTATION_KEY), 47 | Authentication.class); 48 | } 49 | } 50 | private static class AuthorizationHolder{ 51 | private static volatile Authorization auth; 52 | static{ 53 | auth=instance(ConfigurationFactory.instance().getString(AUTHORIZATION_IMPLEMENTATION_KEY), 54 | Authorization.class); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/auth/Authentication.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.auth; 7 | 8 | /** 9 | * Implement this to enable login. 10 | * 11 | * after authenticate user with password and optional ext, if pass, return an UserInfo to client 12 | * which contains essential information for UI part. e.g. user name, token, etc. 13 | * 14 | *@author qxing 15 | * 16 | **/ 17 | public interface Authentication { 18 | /** 19 | * Implement login logical with provided userName, password and an optional ext could be anything. 20 | * 21 | * return UserInfo contains login success or not, and some server generated data as well as other user informations. 22 | * 23 | * No exception throws for login failed. 24 | * 25 | * @param userName 26 | * @param password 27 | * @param ext 28 | * @return 29 | */ 30 | public UserInfo login(String userName, String password) throws Exception; 31 | /** 32 | * check user session. 33 | * 34 | * return true if session is valid and not expired. 35 | * throw SessionExpiredException for session expired. 36 | * throw InvalidSessionException for invalid session. 37 | * 38 | * @param userName 39 | * @return 40 | */ 41 | public boolean checkSession(String userName); 42 | /** 43 | * check whether the authentication model is enabled. 44 | * @return true is enabled and false is not. 45 | */ 46 | public boolean authenticationEnabled(); 47 | } 48 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/auth/Authorization.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.auth; 7 | /** 8 | *@author qxing 9 | * 10 | **/ 11 | public interface Authorization { 12 | 13 | public boolean canAccessData(String user,final String dataSource,final String table); 14 | /** 15 | * check whether the user has some permission 16 | * 17 | * throw NoPermissionException if user don't have this permission. 18 | * 19 | * @param user 20 | * @param permission 21 | * @return true if user has this permission. 22 | */ 23 | public boolean hasPermission(String user, final String permission); 24 | /** 25 | * check whether authorization model enabled. 26 | * 27 | * @return true if enabled. false is not. 28 | */ 29 | public boolean authorizationEnabled(); 30 | } 31 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/auth/exceptions/InvalidSessionException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.auth.exceptions; 7 | /** 8 | *@author qxing 9 | * 10 | **/ 11 | public class InvalidSessionException extends RuntimeException { 12 | /** 13 | * 14 | */ 15 | private static final long serialVersionUID = -759779116336619499L; 16 | public InvalidSessionException(String msg){ 17 | super(msg); 18 | } 19 | public InvalidSessionException(String msg,Throwable t){ 20 | super(msg,t); 21 | } 22 | public InvalidSessionException(Throwable t){ 23 | super(t); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/config/Configuration.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.config; 7 | 8 | 9 | /** 10 | *@author qxing 11 | * 12 | **/ 13 | public interface Configuration { 14 | public String getString(String key); 15 | } 16 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/config/ConfigurationFactory.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.config; 7 | 8 | import com.ebay.pulsar.analytics.auth.AuthModels; 9 | 10 | /** 11 | *@author qxing 12 | * 13 | **/ 14 | public class ConfigurationFactory { 15 | public static Configuration instance(){ 16 | return ConfigurationHolder.conf; 17 | } 18 | /** 19 | * Please implementation this method to load all the configurations. 20 | * 21 | * @return 22 | */ 23 | 24 | private static Configuration loadConfig(){ 25 | return new Configuration(){ 26 | 27 | @Override 28 | public String getString(String key) { 29 | if(AuthModels.AUTHENTICATION_IMPLEMENTATION_KEY.equals(key)){ 30 | return "com.ebay.pulsar.analytics.auth.impl.AuthenticationImpl"; 31 | }else if(AuthModels.AUTHORIZATION_IMPLEMENTATION_KEY.equals(key)){ 32 | return "com.ebay.pulsar.analytics.auth.impl.AuthorizationImpl"; 33 | }else if(AuthModels.AUTHENTICATION_ENABLE_KEY.equals(key)){ 34 | return "true"; 35 | }else if(AuthModels.AUTHORIZATION_ENABLE_KEY.equals(key)){ 36 | return "true"; 37 | }else{ 38 | return ""; 39 | } 40 | } 41 | 42 | }; 43 | } 44 | 45 | private static class ConfigurationHolder{ 46 | private static Configuration conf; 47 | static{ 48 | conf=loadConfig(); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/constants/Constants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.constants; 7 | 8 | 9 | /** 10 | * 11 | * @author rtao 12 | * 13 | */ 14 | public class Constants { 15 | public enum RequestNameSpace { 16 | core, 17 | realtime, 18 | sql, 19 | today, 20 | yesterday; 21 | } 22 | 23 | public enum Granularity { 24 | all, 25 | second, 26 | minute, 27 | five_minute, 28 | fifteen_minute, 29 | thirty_minute, 30 | hour, 31 | day, 32 | week, 33 | month 34 | } 35 | 36 | public enum AggregateFunction { 37 | count, 38 | countall, // This is for count(*) 39 | sum, 40 | min, 41 | max; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/DBService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * Database Operation. 13 | * 14 | *@author qxing 15 | * 16 | **/ 17 | public interface DBService { 18 | 19 | public T getById(long id); 20 | public List getAll(); 21 | public List get(T condition); 22 | public int updateById(T update); 23 | public long inser(T insert); 24 | public int deleteById(long id); 25 | public int deleteBatch(T condition); 26 | public int execute(String sql,Map param); 27 | } 28 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/mapper/DBDashboardMapper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.mapper; 7 | 8 | import com.ebay.pulsar.analytics.dao.model.DBDashboard; 9 | 10 | public class DBDashboardMapper extends BaseDBMapper { 11 | 12 | } 13 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/mapper/DBDataSourceMapper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.mapper; 7 | 8 | import com.ebay.pulsar.analytics.dao.model.DBDataSource; 9 | 10 | 11 | public class DBDataSourceMapper extends BaseDBMapper { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/mapper/DBGroupMapper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.mapper; 7 | 8 | import com.ebay.pulsar.analytics.dao.model.DBGroup; 9 | 10 | /** 11 | *@author qxing 12 | * 13 | **/ 14 | public class DBGroupMapper extends BaseDBMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/mapper/DBRightGroupMapper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.mapper; 7 | 8 | import com.ebay.pulsar.analytics.dao.model.DBRightGroup; 9 | 10 | /** 11 | *@author qxing 12 | * 13 | **/ 14 | public class DBRightGroupMapper extends BaseDBMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/mapper/DBTableMapper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.mapper; 7 | 8 | import com.ebay.pulsar.analytics.dao.model.DBTable; 9 | 10 | /** 11 | *@author qxing 12 | * 13 | **/ 14 | public class DBTableMapper extends BaseDBMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/mapper/DBUserGroupMapper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.mapper; 7 | 8 | import com.ebay.pulsar.analytics.dao.model.DBUserGroup; 9 | 10 | /** 11 | *@author qxing 12 | * 13 | **/ 14 | public class DBUserGroupMapper extends BaseDBMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/mapper/DBUserMapper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.mapper; 7 | 8 | import com.ebay.pulsar.analytics.dao.model.DBUser; 9 | 10 | /** 11 | *@author qxing 12 | * 13 | **/ 14 | public class DBUserMapper extends BaseDBMapper { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/service/DBDashboardService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.service; 7 | 8 | import org.springframework.jdbc.core.RowMapper; 9 | 10 | import com.ebay.pulsar.analytics.dao.mapper.DBDashboardMapper; 11 | import com.ebay.pulsar.analytics.dao.model.DBDashboard; 12 | 13 | 14 | public class DBDashboardService extends BaseDBService { 15 | 16 | @Override 17 | public String getTableName() { 18 | return getTablePrefix()+"DBDashboard"; 19 | } 20 | 21 | @Override 22 | public RowMapper mapper() { 23 | return new DBDashboardMapper(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/service/DBDataSourceService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.service; 7 | 8 | import org.springframework.jdbc.core.RowMapper; 9 | 10 | import com.ebay.pulsar.analytics.dao.mapper.DBDataSourceMapper; 11 | import com.ebay.pulsar.analytics.dao.model.DBDataSource; 12 | import com.ebay.pulsar.analytics.dao.service.BaseDBService; 13 | 14 | 15 | 16 | public class DBDataSourceService extends BaseDBService { 17 | 18 | @Override 19 | public String getTableName() { 20 | return getTablePrefix()+"DBDatasource"; 21 | } 22 | 23 | @Override 24 | public RowMapper mapper() { 25 | return new DBDataSourceMapper(); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/service/DBGroupService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.service; 7 | 8 | import org.springframework.jdbc.core.RowMapper; 9 | 10 | import com.ebay.pulsar.analytics.dao.mapper.DBGroupMapper; 11 | import com.ebay.pulsar.analytics.dao.model.DBGroup; 12 | 13 | 14 | 15 | public class DBGroupService extends BaseDBService { 16 | @Override 17 | public String getTableName() { 18 | //return Configs.getString("pulsareye.monitor.db.table.checker","PULSAREYE_CHECKER"); 19 | return getTablePrefix()+"DBGroup"; 20 | } 21 | 22 | @Override 23 | public RowMapper mapper() { 24 | return new DBGroupMapper(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/service/DBRightGroupService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.service; 7 | 8 | import org.springframework.jdbc.core.RowMapper; 9 | 10 | import com.ebay.pulsar.analytics.dao.mapper.DBRightGroupMapper; 11 | import com.ebay.pulsar.analytics.dao.model.DBRightGroup; 12 | import com.google.common.collect.ImmutableMap; 13 | 14 | 15 | 16 | public class DBRightGroupService extends BaseDBService { 17 | @Override 18 | public String getTableName() { 19 | //return Configs.getString("pulsareye.monitor.db.table.checker","PULSAREYE_CHECKER"); 20 | return getTablePrefix()+"DBRightGroup"; 21 | } 22 | 23 | @Override 24 | public RowMapper mapper() { 25 | return new DBRightGroupMapper(); 26 | } 27 | public int deleteRightsFromGroupByPrefix(String rightNamePrefix){ 28 | String prefix=rightNamePrefix.endsWith("%")?rightNamePrefix:rightNamePrefix+"%"; 29 | return execute("delete from "+QUTOA+getTableName()+QUTOA+ " where rightName like :rightName" 30 | ,ImmutableMap.of("rightName",prefix)); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/service/DBTableService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.service; 7 | 8 | import org.springframework.jdbc.core.RowMapper; 9 | 10 | import com.ebay.pulsar.analytics.dao.mapper.DBTableMapper; 11 | import com.ebay.pulsar.analytics.dao.model.DBTable; 12 | 13 | 14 | 15 | public class DBTableService extends BaseDBService { 16 | @Override 17 | public String getTableName() { 18 | //return Configs.getString("pulsareye.monitor.db.table.checker","PULSAREYE_CHECKER"); 19 | return getTablePrefix()+"DBTables"; 20 | } 21 | 22 | @Override 23 | public RowMapper mapper() { 24 | return new DBTableMapper(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/service/DBUserGroupService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.service; 7 | 8 | import org.springframework.jdbc.core.RowMapper; 9 | 10 | import com.ebay.pulsar.analytics.dao.mapper.DBUserGroupMapper; 11 | import com.ebay.pulsar.analytics.dao.model.DBUserGroup; 12 | 13 | 14 | 15 | public class DBUserGroupService extends BaseDBService { 16 | @Override 17 | public String getTableName() { 18 | //return Configs.getString("pulsareye.monitor.db.table.checker","PULSAREYE_CHECKER"); 19 | return getTablePrefix()+"DBUserGroup"; 20 | } 21 | 22 | @Override 23 | public RowMapper mapper() { 24 | return new DBUserGroupMapper(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/dao/service/DBUserService.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.dao.service; 7 | 8 | import org.springframework.jdbc.core.RowMapper; 9 | 10 | import com.ebay.pulsar.analytics.dao.mapper.DBUserMapper; 11 | import com.ebay.pulsar.analytics.dao.model.DBUser; 12 | 13 | 14 | 15 | public class DBUserService extends BaseDBService { 16 | @Override 17 | public String getTableName() { 18 | //return Configs.getString("pulsareye.monitor.db.table.checker","PULSAREYE_CHECKER"); 19 | return getTablePrefix()+"DBUser"; 20 | } 21 | 22 | @Override 23 | public RowMapper mapper() { 24 | return new DBUserMapper(); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/DBConnector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource; 7 | 8 | import java.util.Set; 9 | 10 | /** 11 | * 12 | * @author mingmwang 13 | * 14 | */ 15 | public interface DBConnector extends Starter, ShutDown { 16 | public Object query(Object query); 17 | public Set getAllTables(); 18 | public Table getTableMeta(String tableName); 19 | } 20 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/DataSourceProviderFactory.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource; 7 | 8 | import com.ebay.pulsar.analytics.query.SQLQueryProcessor; 9 | 10 | /** 11 | * 12 | * @author mingmwang 13 | * 14 | */ 15 | public interface DataSourceProviderFactory { 16 | public boolean validate(DataSourceConfiguration configuration); 17 | public DataSourceProvider create(DataSourceConfiguration configuration); 18 | public SQLQueryProcessor queryProcessor(); 19 | } 20 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/DataSourceRoutingStrategy.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource; 7 | 8 | /** 9 | * 10 | * @author mingmwang 11 | * 12 | */ 13 | import com.ebay.pulsar.analytics.query.request.DateRange; 14 | 15 | public interface DataSourceRoutingStrategy { 16 | public String getDataSourceName(String tableName, DateRange range, String molapName, String rtolapName); 17 | } 18 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/DataSourceTypeEnum.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource; 7 | 8 | /** 9 | * 10 | * @author mingmwang 11 | * 12 | */ 13 | public enum DataSourceTypeEnum { 14 | PULSAR("pulsar"), DRUID("druid"); 15 | 16 | private final String type; 17 | 18 | private DataSourceTypeEnum(String type) { 19 | this.type = type; 20 | } 21 | 22 | public String getType() { 23 | return type; 24 | } 25 | 26 | public static DataSourceTypeEnum fromType(String typeStr) { 27 | if (typeStr != null) { 28 | for (DataSourceTypeEnum typeEnum : DataSourceTypeEnum.values()) { 29 | if (typeEnum.getType().equalsIgnoreCase(typeStr)) { 30 | return typeEnum; 31 | } 32 | } 33 | } 34 | return null; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/DataSourceTypeRegistry.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource; 7 | 8 | import java.lang.reflect.Method; 9 | import java.util.EnumMap; 10 | import java.util.Set; 11 | 12 | import com.google.common.base.Function; 13 | import com.google.common.collect.FluentIterable; 14 | import com.google.common.collect.Maps; 15 | 16 | /** 17 | * 18 | * @author mingmwang 19 | * 20 | */ 21 | public class DataSourceTypeRegistry { 22 | private static EnumMap> factryRegistry = Maps.newEnumMap(DataSourceTypeEnum.class); 23 | 24 | public static void registerDataSourceType(DataSourceTypeEnum dataSourceType, Class clazz){ 25 | factryRegistry.put(dataSourceType, clazz); 26 | } 27 | 28 | public static DataSourceProviderFactory getDataSourceFactory(DataSourceTypeEnum dataSourceType){ 29 | Class clazz = factryRegistry.get(dataSourceType); 30 | if(clazz == null) 31 | return null; 32 | try { 33 | Method getInstance = clazz.getMethod("getInstance", new Class[0]); 34 | return (DataSourceProviderFactory)getInstance.invoke(null, new Object[0]); 35 | } catch (Exception e) { 36 | return null; 37 | } 38 | } 39 | 40 | public static Set getAllSupportedDataSourceTypes(){ 41 | return FluentIterable.from(factryRegistry.keySet()) 42 | .transform(new Function() { 43 | @Override 44 | public String apply(DataSourceTypeEnum input) { 45 | if(input!=null) 46 | return input.getType(); 47 | return null; 48 | } 49 | }).toSet(); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/ShutDown.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource; 7 | 8 | /** 9 | * 10 | * @author mingmwang 11 | * 12 | */ 13 | public interface ShutDown { 14 | public void close(); 15 | } 16 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/Starter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource; 7 | 8 | /** 9 | * 10 | * @author mingmwang 11 | * 12 | */ 13 | public interface Starter { 14 | public void start(); 15 | } 16 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/loader/DataSourceConfigurationLoader.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource.loader; 7 | 8 | /** 9 | * 10 | * @author mingmwang 11 | * 12 | */ 13 | public interface DataSourceConfigurationLoader { 14 | public static final String DATASOURCE_TYPE = "datasourcetype"; 15 | public static final String ENDPOINTS = "endpoints"; 16 | public static final String DATASOURCE_NAME = "datasourcename"; 17 | public static final String PULSAR_DATASOURCE = "pulsarholap"; 18 | 19 | public void load(); 20 | } 21 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/loader/DynamicDataSourceConfigurationLoader.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource.loader; 7 | 8 | import java.util.List; 9 | 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | import com.ebay.pulsar.analytics.dao.model.DBDataSource; 14 | import com.ebay.pulsar.analytics.dao.service.DBDataSourceService; 15 | import com.ebay.pulsar.analytics.datasource.DataSourceConfiguration; 16 | import com.ebay.pulsar.analytics.datasource.DataSourceMetaRepo; 17 | 18 | /** 19 | * Load all the DB configurations from datasources 20 | * 21 | * @author mingmwang 22 | * 23 | */ 24 | public class DynamicDataSourceConfigurationLoader implements DataSourceConfigurationLoader { 25 | private static final Logger logger = LoggerFactory.getLogger(DynamicDataSourceConfigurationLoader.class); 26 | private DBDataSourceService datasourceService = new DBDataSourceService(); 27 | 28 | @Override 29 | public void load() { 30 | List list = datasourceService.getAll(); 31 | for(DBDataSource dataSource : list){ 32 | String dataSourceName = dataSource.getName(); 33 | 34 | DataSourceConfiguration configFromRepo = DataSourceMetaRepo.getInstance().getDbConf(dataSourceName); 35 | if(configFromRepo == null){ 36 | logger.info("Add dynamic metricstore:" + dataSourceName); 37 | DynamicDataSourceConfigurationManager.activateDataSource(dataSource); 38 | }else{ 39 | if(configFromRepo.isRealOnly()){ 40 | logger.error("Unable to update readonly metricstore:" + dataSourceName); 41 | continue; 42 | }else{ 43 | long refreshTime = DynamicDataSourceConfigurationManager.getDBRefreshTime(dataSource); 44 | if(configFromRepo.getRefreshTime() < refreshTime){ 45 | logger.info("Refresh dynamic metricstore:" + dataSourceName); 46 | DynamicDataSourceConfigurationManager.disableDataSource(dataSource); 47 | DynamicDataSourceConfigurationManager.activateDataSource(dataSource); 48 | } 49 | } 50 | } 51 | } 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/datasource/loader/PeriodicalConfigurationLoader.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.datasource.loader; 7 | 8 | import java.util.concurrent.ScheduledExecutorService; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | import com.ebay.pulsar.analytics.util.PulsarQueryScheduler; 12 | 13 | /** 14 | * 15 | * @author mingmwang 16 | * 17 | */ 18 | public class PeriodicalConfigurationLoader implements DataSourceConfigurationLoader { 19 | 20 | private static final Long ONE_MINUTE = 60 * 1000L; 21 | 22 | public PeriodicalConfigurationLoader(final DataSourceConfigurationLoader loader) { 23 | ScheduledExecutorService scheduler = PulsarQueryScheduler.getScheduler(); 24 | scheduler.scheduleWithFixedDelay(new Runnable() { 25 | @Override 26 | public void run() { 27 | try{ 28 | loader.load(); 29 | }catch(Exception t){ 30 | } 31 | } 32 | }, 0, ONE_MINUTE, TimeUnit.MILLISECONDS); 33 | } 34 | 35 | @Override 36 | public void load() { 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/exception/DataSourceConfigurationException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.exception; 7 | 8 | public class DataSourceConfigurationException extends RuntimeException { 9 | private static final long serialVersionUID = -3775554654653365202L; 10 | 11 | public DataSourceConfigurationException(String msg){ 12 | super(msg); 13 | } 14 | public DataSourceConfigurationException(String msg,Throwable t){ 15 | super(msg,t); 16 | } 17 | public DataSourceConfigurationException(Throwable t){ 18 | super(t); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/exception/DataSourceException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.exception; 7 | 8 | 9 | public class DataSourceException extends RuntimeException { 10 | private static final long serialVersionUID = 3550626010738416585L; 11 | 12 | public DataSourceException(String msg){ 13 | super(msg); 14 | } 15 | public DataSourceException(String msg,Throwable t){ 16 | super(msg,t); 17 | } 18 | public DataSourceException(Throwable t){ 19 | super(t); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/exception/ExceptionErrorCode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.exception; 7 | 8 | 9 | import com.google.common.base.Joiner; 10 | 11 | public enum ExceptionErrorCode { 12 | DATASOURCE_ERROR(11001, "DataSource Error. "), 13 | INVALID_DATASOURCE(11002, "Invalid query datasource:"), 14 | INVALID_ENDPOINTS(11003, "Invalid Endpoints in XML config for metric: "), 15 | 16 | INVALID_GRANULARITY(12001, "Invalid granularity: "), 17 | INVALID_GRANULARITY_INTERVAL(12002, "Invalid granularity minute with Intervals > 1 day. "), 18 | INVALID_QUERYTIME(12003, "Invalid time range (start/end):"), 19 | INVALID_CUSTOM_TIME(12004, "Invalid Custom Time: "), 20 | 21 | MISSING_SQL(13001, "Missing sql."), 22 | SQL_PARSING_ERROR(13002, "SQL parsing error: "), 23 | INVALID_AGGREGATE(13011, "Invalid aggregate: "), 24 | INVALID_SORT_PARAM(13021, "Invalid sort parameter (must be metric/aggregate): "), 25 | INVALID_FILTER(13031, "Invalid filter: "), 26 | MISSING_METRIC(13041, "Missing metrics. "), 27 | INVALID_METRIC(13042, "Invalid metrics: "), 28 | MULTI_METRICS_ERROR(13043, "Multi-metrics not supported. "), 29 | INVALID_HAVING_CLAUSE(13051, "Invalid having clause: "), 30 | INVALID_DIMENSION(13061, "Invalid dimension: "), 31 | INVALID_MAXRESULT(13071, "Invalid maxResults parameter: "), 32 | INVALID_DURATION(13081, "Invalid duration (must be between 1 to 1800 seconds): "), 33 | 34 | ; 35 | 36 | private final int code; 37 | private final String message; 38 | private final String errorMessage; 39 | 40 | private ExceptionErrorCode(int code, String message){ 41 | this.code = code; 42 | this.message = message; 43 | StringBuilder sb = new StringBuilder(); 44 | Joiner.on(":").appendTo(sb, code, message); 45 | errorMessage = sb.toString(); 46 | } 47 | 48 | public String getErrorMessage(){ 49 | return errorMessage; 50 | } 51 | 52 | public int getCode(){ 53 | return code; 54 | } 55 | 56 | public String getMessage(){ 57 | return message; 58 | } 59 | } 60 | 61 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/exception/InvalidQueryParameterException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.exception; 7 | 8 | public class InvalidQueryParameterException extends RuntimeException{ 9 | private static final long serialVersionUID = -6207679970021851625L; 10 | 11 | public InvalidQueryParameterException(String msg){ 12 | super(msg); 13 | } 14 | public InvalidQueryParameterException(String msg,Throwable t){ 15 | super(msg,t); 16 | } 17 | public InvalidQueryParameterException(Throwable t){ 18 | super(t); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/exception/SqlTranslationException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.exception; 7 | 8 | 9 | public class SqlTranslationException extends RuntimeException{ 10 | private static final long serialVersionUID = 4476978734547934067L; 11 | 12 | public SqlTranslationException(String msg){ 13 | super(msg); 14 | } 15 | public SqlTranslationException(String msg,Throwable t){ 16 | super(msg,t); 17 | } 18 | public SqlTranslationException(Throwable t){ 19 | super(t); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/filters/ApiOriginFilter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.filters; 7 | 8 | import java.io.IOException; 9 | 10 | import javax.servlet.FilterChain; 11 | import javax.servlet.FilterConfig; 12 | import javax.servlet.ServletException; 13 | import javax.servlet.ServletRequest; 14 | import javax.servlet.ServletResponse; 15 | import javax.servlet.http.HttpServletRequest; 16 | import javax.servlet.http.HttpServletResponse; 17 | 18 | 19 | /** 20 | * 21 | * @author rtao 22 | * 23 | */ 24 | public class ApiOriginFilter implements javax.servlet.Filter { 25 | @Override 26 | public void doFilter(ServletRequest request, ServletResponse response, 27 | FilterChain chain) throws IOException, ServletException { 28 | HttpServletResponse res = (HttpServletResponse) response; 29 | HttpServletRequest req = (HttpServletRequest) request; 30 | String originHeader = req.getHeader("Origin"); 31 | res.addHeader("Access-Control-Allow-Origin", originHeader); 32 | res.setHeader("Access-Control-Allow-Credentials", "true"); 33 | res.addHeader("Access-Control-Allow-Headers", 34 | "Content-Type,Authorization"); 35 | res.addHeader("Access-Control-Allow-Methods", 36 | "GET, POST, DELETE, PUT,OPTION,OPTIONS"); 37 | 38 | if (req.getMethod().equals("OPTION") 39 | || req.getMethod().equals("OPTIONS")) { 40 | 41 | res.setHeader("Access-Control-Allow-Origin", originHeader); 42 | res.addHeader("Access-Control-Allow-Methods", 43 | "DELETE, GET, OPTIONS, POST, PUT, UPDATE"); 44 | res.addHeader( 45 | "Access-Control-Allow-Headers", 46 | "Authorization, withCredentials,Content-Type, Timeout, X-File-Size, X-Requested-With"); 47 | res.addHeader("Access-Control-Expose-Headers", 48 | "DAV, content-length, Allow"); 49 | res.addHeader("Access-Control-Max-Age", "86400"); 50 | } 51 | chain.doFilter(request, response); 52 | } 53 | 54 | @Override 55 | public void destroy() { 56 | } 57 | 58 | @Override 59 | public void init(FilterConfig filterConfig) throws ServletException { 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/RestQueryProcessor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query; 7 | 8 | import java.io.IOException; 9 | import java.text.ParseException; 10 | 11 | import com.ebay.pulsar.analytics.query.request.BaseRequest; 12 | import com.ebay.pulsar.analytics.query.response.TraceAbleResponse; 13 | import com.fasterxml.jackson.core.JsonParseException; 14 | import com.fasterxml.jackson.databind.JsonMappingException; 15 | 16 | /** 17 | * Rest and SQL query processor 18 | * 19 | * @author mingmwang 20 | * 21 | */ 22 | public interface RestQueryProcessor extends SQLQueryProcessor { 23 | TraceAbleResponse executeRestQuery(BaseRequest req) throws JsonParseException, JsonMappingException, IOException, ParseException; 24 | } 25 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/SQLQueryContext.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query; 7 | 8 | import java.util.List; 9 | 10 | import com.ebay.pulsar.analytics.constants.Constants.RequestNameSpace; 11 | import com.ebay.pulsar.analytics.query.request.DateRange; 12 | 13 | /** 14 | * 15 | * @author mingmwang 16 | * 17 | */ 18 | public class SQLQueryContext { 19 | private DateRange intervals; 20 | private String sqlQuery; 21 | private String granularity; 22 | private RequestNameSpace ns; 23 | 24 | private List tableNames; 25 | private List dbNameSpaces; 26 | 27 | public RequestNameSpace getNs() { 28 | return ns; 29 | } 30 | 31 | public void setNs(RequestNameSpace ns) { 32 | this.ns = ns; 33 | } 34 | 35 | public DateRange getIntervals() { 36 | return intervals; 37 | } 38 | 39 | public void setIntervals(DateRange intervals) { 40 | this.intervals = intervals; 41 | } 42 | 43 | public String getSqlQuery() { 44 | return sqlQuery; 45 | } 46 | 47 | public void setSqlQuery(String sqlQuery) { 48 | this.sqlQuery = sqlQuery; 49 | } 50 | 51 | public String getGranularity() { 52 | return granularity; 53 | } 54 | 55 | public void setGranularity(String granularity) { 56 | this.granularity = granularity; 57 | } 58 | 59 | public List getTableNames() { 60 | return tableNames; 61 | } 62 | 63 | public void setTableNames(List tableNames) { 64 | this.tableNames = tableNames; 65 | } 66 | 67 | public List getDbNameSpaces() { 68 | return dbNameSpaces; 69 | } 70 | 71 | public void setDbNameSpaces(List dbNameSpaces) { 72 | this.dbNameSpaces = dbNameSpaces; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/SQLQueryProcessor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query; 7 | 8 | import java.io.IOException; 9 | import java.text.ParseException; 10 | 11 | import com.ebay.pulsar.analytics.query.request.BaseSQLRequest; 12 | import com.ebay.pulsar.analytics.query.response.TraceAbleResponse; 13 | import com.fasterxml.jackson.core.JsonParseException; 14 | import com.fasterxml.jackson.databind.JsonMappingException; 15 | /** 16 | * Implement this to do the real query in each dataSource. 17 | * 18 | * @author mingmwang 19 | * 20 | **/ 21 | public interface SQLQueryProcessor { 22 | public TraceAbleResponse executeQuery(BaseSQLRequest req, String dataSourceName) throws JsonParseException, JsonMappingException, IOException, ParseException; 23 | } 24 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/client/ClientQueryConfig.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.client; 7 | 8 | /** 9 | * 10 | * @author mingmwang 11 | * 12 | */ 13 | public class ClientQueryConfig { 14 | 15 | private int connectTimeout = 10000; 16 | private int readTimeout = 30000; 17 | private int threadPoolsize = 10; 18 | 19 | // Limit factor is to get more response results to do post-processing 20 | private float limitFactor; 21 | 22 | public int getConnectTimeout() { 23 | return connectTimeout; 24 | } 25 | 26 | public void setConnectTimeout(int connectTimeout) { 27 | this.connectTimeout = connectTimeout; 28 | } 29 | 30 | public int getReadTimeout() { 31 | return readTimeout; 32 | } 33 | 34 | public void setReadTimeout(int readTimeout) { 35 | this.readTimeout = readTimeout; 36 | } 37 | 38 | public int getThreadPoolsize() { 39 | return threadPoolsize; 40 | } 41 | 42 | public void setThreadPoolsize(int threadPoolsize) { 43 | this.threadPoolsize = threadPoolsize; 44 | } 45 | 46 | public float getLimitFactor() { 47 | return limitFactor; 48 | } 49 | 50 | public void setLimitFactor(float limitFactor) { 51 | this.limitFactor = limitFactor; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/request/BaseRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.request; 7 | 8 | import java.util.List; 9 | 10 | import com.ebay.pulsar.analytics.constants.Constants.RequestNameSpace; 11 | 12 | /** 13 | * 14 | * @author rtao 15 | * 16 | */ 17 | public abstract class BaseRequest { 18 | private List metrics; 19 | private List dimensions; 20 | private String filter; 21 | private String granularity; 22 | private Integer maxResults; 23 | private String sort; 24 | private String having; 25 | private RequestNameSpace namespace; 26 | 27 | public List getMetrics() { 28 | return metrics; 29 | } 30 | public void setMetrics(List metrics) { 31 | this.metrics = metrics; 32 | } 33 | public List getDimensions() { 34 | return dimensions; 35 | } 36 | public void setDimensions(List dimensions) { 37 | this.dimensions = dimensions; 38 | } 39 | public String getFilter() { 40 | return filter; 41 | } 42 | public void setFilter(String filter) { 43 | this.filter = filter; 44 | } 45 | public String getHaving() { 46 | return having; 47 | } 48 | public void setHaving(String having) { 49 | this.having = having; 50 | } 51 | public String getGranularity() { 52 | return granularity; 53 | } 54 | public void setGranularity(String granularity) { 55 | this.granularity = granularity; 56 | } 57 | public Integer getMaxResults() { 58 | return maxResults; 59 | } 60 | public void setMaxResults(Integer maxResults) { 61 | this.maxResults = maxResults; 62 | } 63 | public String getSort() { 64 | return sort; 65 | } 66 | public void setSort(String sort) { 67 | this.sort = sort; 68 | } 69 | public RequestNameSpace getNamespace() { 70 | return namespace; 71 | } 72 | public void setNamespace(RequestNameSpace namespace) { 73 | this.namespace = namespace; 74 | } 75 | 76 | public abstract DateRange getQueryDateRange(); 77 | } 78 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/request/BaseSQLRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.request; 7 | 8 | import com.ebay.pulsar.analytics.constants.Constants.RequestNameSpace; 9 | 10 | /** 11 | * 12 | * @author rtao 13 | * 14 | */ 15 | public abstract class BaseSQLRequest { 16 | private String sql; 17 | private String granularity; 18 | private RequestNameSpace namespace; 19 | 20 | public String getSql() { 21 | return sql; 22 | } 23 | public void setSql(String sql) { 24 | this.sql = sql; 25 | } 26 | 27 | public String getGranularity() { 28 | return granularity; 29 | } 30 | public void setGranularity(String granularity) { 31 | this.granularity = granularity; 32 | } 33 | 34 | public RequestNameSpace getNamespace() { 35 | return namespace; 36 | } 37 | public void setNamespace(RequestNameSpace namespace) { 38 | this.namespace = namespace; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/request/DateRange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.request; 7 | 8 | import org.joda.time.DateTime; 9 | 10 | /** 11 | * 12 | * @author rtao 13 | * 14 | */ 15 | public class DateRange { 16 | private DateTime start; 17 | private DateTime end; 18 | 19 | public DateRange(DateTime start, DateTime end) { 20 | this.start = start; 21 | this.end = end; 22 | } 23 | 24 | public DateTime getStart() { 25 | return start; 26 | } 27 | public void setStart(DateTime start) { 28 | this.start = start; 29 | } 30 | public DateTime getEnd() { 31 | return end; 32 | } 33 | public void setEnd(DateTime end) { 34 | this.end = end; 35 | } 36 | 37 | @Override 38 | public int hashCode() { 39 | final int prime = 31; 40 | int result = 1; 41 | result = prime * result + ((end == null) ? 0 : end.hashCode()); 42 | result = prime * result + ((start == null) ? 0 : start.hashCode()); 43 | return result; 44 | } 45 | 46 | @Override 47 | public boolean equals(Object obj) { 48 | if (this == obj) 49 | return true; 50 | if (obj == null) 51 | return false; 52 | if (getClass() != obj.getClass()) 53 | return false; 54 | DateRange other = (DateRange) obj; 55 | if (end == null) { 56 | if (other.end != null) 57 | return false; 58 | } else if (!end.equals(other.end)) 59 | return false; 60 | if (start == null) { 61 | if (other.start != null) 62 | return false; 63 | } else if (!start.equals(other.start)) 64 | return false; 65 | return true; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/request/GeneralSQLRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.request; 7 | 8 | /** 9 | * 10 | * @author rtao 11 | * 12 | */ 13 | public class GeneralSQLRequest extends BaseSQLRequest{ 14 | 15 | } 16 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/request/RealtimeRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.request; 7 | 8 | import org.joda.time.DateTime; 9 | 10 | 11 | /** 12 | * 13 | * @author rtao 14 | * 15 | */ 16 | public class RealtimeRequest extends BaseRequest { 17 | private Integer duration; 18 | 19 | public Integer getDuration() { 20 | return duration; 21 | } 22 | 23 | public void setDuration(Integer duration) { 24 | this.duration = duration; 25 | } 26 | 27 | @Override 28 | public DateRange getQueryDateRange() { 29 | DateTime start = null; 30 | DateTime end = null; 31 | DateTime now = new DateTime(PulsarDateTimeFormatter.MST_TIMEZONE); 32 | 33 | // normalize to 0, 10, 20, 30, 40, 50 of each minute 34 | end = new DateTime((now.getMillis() /10000)*10000); 35 | Integer duration = getDuration(); 36 | if (duration == null) { 37 | duration = 5 * 60; // default to last 5 minutes 38 | } 39 | start = new DateTime(end.getMillis() - duration * 1000); 40 | 41 | DateRange dateRange = new DateRange(start, end); 42 | return dateRange; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/request/SQLRequest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.request; 7 | 8 | 9 | /** 10 | * 11 | * @author rtao 12 | * 13 | */ 14 | public class SQLRequest extends BaseSQLRequest { 15 | private String startTime; 16 | private String endTime; 17 | private String customTime; 18 | private String intervals; 19 | 20 | public String getIntervals() { 21 | return intervals; 22 | } 23 | public void setIntervals(String intervals) { 24 | this.intervals = intervals; 25 | } 26 | public String getStartTime() { 27 | return startTime; 28 | } 29 | public void setStartTime(String startTime) { 30 | this.startTime = startTime; 31 | } 32 | public String getEndTime() { 33 | return endTime; 34 | } 35 | public void setEndTime(String endTime) { 36 | this.endTime = endTime; 37 | } 38 | public String getCustomTime() { 39 | return customTime; 40 | } 41 | public void setCustomTime(String customTime) { 42 | this.customTime = customTime; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/response/ErrorResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.response; 7 | 8 | /** 9 | * 10 | * @author rtao 11 | * 12 | */ 13 | public class ErrorResponse { 14 | 15 | public String url; 16 | public String exception; 17 | 18 | /** 19 | * @param exception 20 | */ 21 | public ErrorResponse(String url, Exception exception) { 22 | this.url = url; 23 | this.exception = exception.getLocalizedMessage(); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/response/QueryResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.response; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | /** 12 | * 13 | * @author rtao 14 | * 15 | */ 16 | public class QueryResponse { 17 | private List> queryResult; 18 | 19 | public List> getQueryResult() { 20 | return queryResult; 21 | } 22 | public void setQueryResult(List> queryResult) { 23 | this.queryResult = queryResult; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/response/TraceAbleResponse.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.response; 7 | 8 | 9 | /** 10 | * 11 | * @author rtao 12 | * 13 | */ 14 | public class TraceAbleResponse extends QueryResponse { 15 | private TraceQuery query; 16 | private long requestProcessTime; 17 | 18 | public long getRequestProcessTime() { 19 | return requestProcessTime; 20 | } 21 | 22 | public void setRequestProcessTime(long requestProcessTime) { 23 | this.requestProcessTime = requestProcessTime; 24 | } 25 | 26 | public TraceQuery getQuery() { 27 | return query; 28 | } 29 | 30 | public void setQuery(TraceQuery query) { 31 | this.query = query; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/result/ChainedRevisor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | import java.util.List; 9 | 10 | import com.google.common.collect.Lists; 11 | 12 | 13 | /** 14 | * 15 | * @author mingmwang 16 | * 17 | */ 18 | public class ChainedRevisor implements ResultRevisor { 19 | 20 | List revisorList; 21 | 22 | public ChainedRevisor(ResultRevisor ...revisor) { 23 | this.revisorList = Lists.newArrayList(revisor); 24 | } 25 | 26 | public ChainedRevisor(List revisorList) { 27 | this.revisorList = revisorList; 28 | } 29 | @Override 30 | public void revise(ResultNode node) { 31 | for(ResultRevisor revisor : revisorList){ 32 | revisor.revise(node); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/result/ColumnNameRevisor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | import java.util.List; 9 | import java.util.Map; 10 | 11 | 12 | /** 13 | * 14 | * @author mingmwang 15 | * 16 | */ 17 | public class ColumnNameRevisor implements ResultRevisor { 18 | private List dimensions; 19 | private Map nameAliasMap; 20 | 21 | public ColumnNameRevisor(List dimensions, 22 | Map nameAliasMap) { 23 | this.dimensions = dimensions; 24 | this.nameAliasMap = nameAliasMap; 25 | } 26 | 27 | @Override 28 | public void revise(ResultNode node) { 29 | if(dimensions!=null && dimensions.contains(node.getName())){ 30 | String newColumnName = replaceColumnToUserRequest(node.getName(), nameAliasMap); 31 | node.setName(newColumnName); 32 | } 33 | } 34 | 35 | private String replaceColumnToUserRequest(String columnName, Map nameAliasMap) { 36 | if(nameAliasMap != null && nameAliasMap.get(columnName) != null){ 37 | return nameAliasMap.get(columnName); 38 | } 39 | return columnName; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/result/ColumnValueCollector.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | import java.util.Collection; 9 | 10 | import com.google.common.collect.Sets; 11 | 12 | /** 13 | * 14 | * @author mingmwang 15 | * 16 | * @param 17 | */ 18 | public class ColumnValueCollector implements ResultRevisor { 19 | private String columnName; 20 | private Collection valueCollection; 21 | 22 | public ColumnValueCollector(String columnName) { 23 | this(columnName, Sets.newHashSet()); 24 | } 25 | 26 | public ColumnValueCollector(String columnName, Collection valueCollection) { 27 | super(); 28 | this.columnName = columnName; 29 | this.valueCollection = valueCollection; 30 | } 31 | 32 | 33 | @SuppressWarnings("unchecked") 34 | @Override 35 | public void revise(ResultNode node) { 36 | if(columnName.equals(node.getName())){ 37 | valueCollection.add((V)node.getValue()); 38 | } 39 | } 40 | 41 | public Collection getValueCollection() { 42 | return valueCollection; 43 | } 44 | 45 | public String getColumnName() { 46 | return columnName; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/result/HllMetricRevisor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | import java.util.Set; 9 | 10 | /** 11 | * 12 | * @author mingmwang 13 | * 14 | */ 15 | public class HllMetricRevisor implements ResultRevisor { 16 | public Set hllSet; 17 | 18 | public HllMetricRevisor(Set hllSet) { 19 | this.hllSet = hllSet; 20 | } 21 | 22 | @Override 23 | public void revise(ResultNode node) { 24 | if (hllSet != null && hllSet.contains(node.getName())) { 25 | Long hllLongValue = ((Number) node.getValue()).longValue(); 26 | node.setValue(hllLongValue); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/result/ResultEnricher.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | import java.util.Map; 9 | 10 | /** 11 | * 12 | * @author mingmwang 13 | * 14 | */ 15 | public interface ResultEnricher { 16 | public Map enrich(Iterable idList); 17 | } 18 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/result/ResultNode.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | /** 9 | * 10 | * @author mingmwang 11 | * 12 | */ 13 | public class ResultNode{ 14 | private String name; 15 | private Object value; 16 | 17 | public ResultNode(String name, Object value) { 18 | this.name = name; 19 | this.value = value; 20 | } 21 | 22 | public String getName() { 23 | return name; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public Object getValue() { 31 | return value; 32 | } 33 | 34 | public void setValue(Object value) { 35 | this.value = value; 36 | } 37 | 38 | public void revise(ResultRevisor revisor) { 39 | revisor.revise(this); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/result/ResultRevisor.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | /** 9 | * Implement this interface to do alias transformation for query result. 10 | * 11 | * @author mingmwang 12 | * 13 | */ 14 | public interface ResultRevisor { 15 | public void revise(ResultNode node); 16 | } 17 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/sql/SimpleTableNameParser.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.sql; 7 | 8 | import java.util.regex.Matcher; 9 | import java.util.regex.Pattern; 10 | 11 | import com.google.common.base.Strings; 12 | 13 | /** 14 | * FundationDb didn't support "." "." structure in the SQL Grammer, so use regex to parse table name from SQL. 15 | * Only support one table name now. 16 | * @param sql 17 | * @return tableName 18 | * 19 | * @author mingmwang 20 | */ 21 | public class SimpleTableNameParser { 22 | 23 | private static String SQL_PATTERN_STR = "select (.*) from\\s+([^ ,]+)(?:\\s*,\\s*([^ ,]+))*\\s+"; 24 | private static Pattern SQL_PATTERN = Pattern.compile(SQL_PATTERN_STR, Pattern.CASE_INSENSITIVE); 25 | 26 | public static String getTableName(String sql){ 27 | if(Strings.isNullOrEmpty(sql)){ 28 | return null; 29 | } 30 | Matcher matcher = SQL_PATTERN.matcher(sql); 31 | if(matcher.find()){ 32 | return matcher.group(2); 33 | }else{ 34 | return null; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/query/validator/QueryValidator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.validator; 7 | 8 | /** 9 | * Validate the query parameters. 10 | * 11 | * @author mingmwang 12 | * 13 | */ 14 | public interface QueryValidator { 15 | void validate(T part); 16 | } 17 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/util/PulsarQueryScheduler.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.util; 7 | 8 | import java.util.concurrent.Executors; 9 | import java.util.concurrent.ScheduledExecutorService; 10 | 11 | import com.google.common.util.concurrent.ThreadFactoryBuilder; 12 | 13 | /** 14 | * 15 | * @author mingmwang 16 | * 17 | */ 18 | public class PulsarQueryScheduler { 19 | private static ScheduledExecutorService scheduler = Executors 20 | .newScheduledThreadPool(1, new ThreadFactoryBuilder().setNameFormat("PulsarQueryScheduler").build()); 21 | 22 | public static ScheduledExecutorService getScheduler() { 23 | return scheduler; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/util/Serializer.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.util; 7 | 8 | import java.io.IOException; 9 | 10 | import com.fasterxml.jackson.core.JsonParseException; 11 | import com.fasterxml.jackson.core.JsonProcessingException; 12 | import com.fasterxml.jackson.databind.JsonMappingException; 13 | 14 | /** 15 | * 16 | * @author rtao 17 | * 18 | * @param 19 | */ 20 | public class Serializer { 21 | private final Class type; 22 | 23 | public Serializer(Class type) { 24 | this.type = type; 25 | } 26 | 27 | public T deserialize(byte[] value) throws JsonParseException, JsonMappingException, IOException { 28 | if (null == value) { 29 | return null; 30 | } 31 | 32 | return JsonUtil.readValue(value, type); 33 | } 34 | 35 | public byte[] serialize(T obj) throws JsonProcessingException { 36 | if (null == obj) { 37 | return null; 38 | } 39 | 40 | return JsonUtil.writeValueAsBytes(obj); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /pulsarquery-core/src/main/java/com/ebay/pulsar/analytics/util/Slugify.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.util; 7 | 8 | import java.text.Normalizer; 9 | import java.util.Map; 10 | import java.util.Map.Entry; 11 | 12 | /** 13 | * @author xinxu1 14 | * 15 | **/ 16 | public class Slugify { 17 | 18 | private Map customReplacements; 19 | private boolean lowerCase; 20 | 21 | public Slugify() { 22 | this(true); 23 | } 24 | 25 | public Slugify(final boolean lowerCase) { 26 | setLowerCase(lowerCase); 27 | } 28 | 29 | public String slugify(String input) { 30 | if (input == null) { 31 | return ""; 32 | } 33 | 34 | input = input.trim(); 35 | 36 | Map customReplacements = getCustomReplacements(); 37 | if (customReplacements != null) { 38 | for (Entry entry : customReplacements.entrySet()) { 39 | input = input.replace(entry.getKey(), entry.getValue()); 40 | } 41 | } 42 | 43 | input = Normalizer.normalize(input, Normalizer.Form.NFD) 44 | .replaceAll("[^0-9a-zA-Z\\s]+", "") 45 | .replaceAll(" +", "_"); 46 | 47 | if (getLowerCase()) { 48 | input = input.toLowerCase(); 49 | } 50 | 51 | return input; 52 | } 53 | 54 | public Map getCustomReplacements() { 55 | return customReplacements; 56 | } 57 | 58 | public void setCustomReplacements(Map customReplacements) { 59 | this.customReplacements = customReplacements; 60 | } 61 | 62 | public boolean getLowerCase() { 63 | return lowerCase; 64 | } 65 | 66 | public void setLowerCase(boolean lowerCase) { 67 | this.lowerCase = lowerCase; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/auth/AuthModelsTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.auth; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | import org.junit.Test; 14 | 15 | import com.ebay.pulsar.analytics.auth.impl.AuthenticationImpl; 16 | 17 | public class AuthModelsTest { 18 | @Test 19 | public void testUserInfo(){ 20 | UserInfo userinfo=new UserInfo(); 21 | userinfo.setEnableAuthentication(true); 22 | userinfo.setEnableAuthorization(true); 23 | userinfo.setEnabled(true); 24 | AuthenticationImpl model=new AuthenticationImpl(); 25 | model.authenticationEnabled(); 26 | model.checkSession("test"); 27 | AuthModels.authentication(); 28 | Map ext=new HashMap(); 29 | ext.put("test","test"); 30 | userinfo.setExt(ext); 31 | userinfo.setLoginSuccess(true); 32 | userinfo.setToken("test"); 33 | userinfo.setUserName("test"); 34 | assertTrue(userinfo.getExt().equals(ext)); 35 | assertTrue(userinfo.getToken().equals("test")); 36 | assertTrue(userinfo.getUserName().equals("test")); 37 | assertTrue(userinfo.isEnableAuthentication()); 38 | assertTrue(userinfo.isEnableAuthorization()); 39 | assertTrue(userinfo.isLoginSuccess()); 40 | assertTrue(userinfo.isEnabled()); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/metricstore/db/AbstracDataSourceProviderFactoryTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.metricstore.db; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | import org.junit.Test; 11 | import org.mockito.Matchers; 12 | import org.mockito.Mockito; 13 | import org.mockito.internal.stubbing.answers.CallsRealMethods; 14 | 15 | import com.ebay.pulsar.analytics.datasource.AbstractDataSourceProviderFactory; 16 | import com.ebay.pulsar.analytics.datasource.DBConnector; 17 | import com.ebay.pulsar.analytics.datasource.DataSourceConfiguration; 18 | import com.ebay.pulsar.analytics.datasource.DataSourceTypeEnum; 19 | import com.ebay.pulsar.analytics.datasource.Table; 20 | import com.google.common.collect.Lists; 21 | import com.google.common.collect.Sets; 22 | 23 | public class AbstracDataSourceProviderFactoryTest { 24 | @Test 25 | public void testFactory() { 26 | 27 | DBConnector collector=Mockito.mock( 28 | DBConnector.class); 29 | Table table=new Table(); 30 | table.setTableName("tst"); 31 | Mockito.when(collector.getAllTables()).thenReturn(Sets.newHashSet("tst")); 32 | Mockito.when(collector.getTableMeta("tst")).thenReturn(table); 33 | AbstractDataSourceProviderFactory factory = Mockito.mock(AbstractDataSourceProviderFactory.class, 34 | new CallsRealMethods()); 35 | Mockito.doReturn(collector) 36 | .when(factory) 37 | .getDBCollector(Matchers.any(DataSourceConfiguration.class)); 38 | DataSourceConfiguration configuration = new DataSourceConfiguration( 39 | DataSourceTypeEnum.DRUID, "testdb"); 40 | configuration.setEndPoint(Lists.newArrayList("http://test")); assertEquals(Lists.newArrayList(table),factory.create(configuration).getTables()); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/query/AbstractSQLQueryProcessTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | import java.io.IOException; 11 | import java.text.ParseException; 12 | 13 | import org.junit.Test; 14 | import org.mockito.Mockito; 15 | 16 | import com.ebay.pulsar.analytics.constants.Constants; 17 | import com.ebay.pulsar.analytics.query.request.SQLRequest; 18 | import com.ebay.pulsar.analytics.query.response.TraceAbleResponse; 19 | import com.ebay.pulsar.analytics.query.sql.SQLTranslator; 20 | import com.fasterxml.jackson.core.JsonParseException; 21 | import com.fasterxml.jackson.databind.JsonMappingException; 22 | 23 | public class AbstractSQLQueryProcessTest extends AbstractSQLQueryProcessor{ 24 | @Test 25 | public void testProcess(){ 26 | SQLRequest sqlRequest = new SQLRequest(); 27 | 28 | sqlRequest.setEndTime("2015-09-9 23:59:59"); 29 | sqlRequest.setGranularity("day"); 30 | sqlRequest.setIntervals("2015-08-20 00:00:00/2015-08-26 23:59:59"); 31 | sqlRequest.setNamespace(Constants.RequestNameSpace.sql); 32 | sqlRequest 33 | .setSql("select count(clickcount_ag) as \"clickcount_ag\", testDim from tabletest group by testDim limit 100"); 34 | sqlRequest.setStartTime("2015-09-15 23:59:59"); 35 | 36 | assertEquals(sqlRequest.getGranularity(),prepareQuery(sqlRequest,"druid").getGranularity()); 37 | } 38 | 39 | @Override 40 | public SQLTranslator getSqlTranslator() { 41 | SQLTranslator sqlTranslator = Mockito.mock(SQLTranslator.class, 42 | Mockito.CALLS_REAL_METHODS); 43 | return sqlTranslator; 44 | } 45 | 46 | @Override 47 | public TraceAbleResponse doSQLQuery(SQLQueryContext queryContext) 48 | throws JsonParseException, JsonMappingException, IOException, 49 | ParseException { 50 | return null; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/query/result/ChainedRevisorTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | import static org.junit.Assert.assertTrue; 9 | 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | import org.junit.Test; 16 | 17 | public class ChainedRevisorTest { 18 | @Test 19 | public void testChainedRevisor(){ 20 | ResultNode node = new ResultNode("testDim", "testDim"); 21 | node.setName("testDim"); 22 | node.setValue("testDim"); 23 | List dimensions = new ArrayList(); 24 | Map nameAliasMap = new HashMap(); 25 | dimensions.add("testDim"); 26 | nameAliasMap.put("testDim", "dimension"); 27 | ColumnNameRevisor cr = new ColumnNameRevisor(dimensions, nameAliasMap); 28 | cr.revise(node); 29 | List revisorList =new ArrayList(); 30 | revisorList.add(cr); 31 | ChainedRevisor revisor=new ChainedRevisor(revisorList); 32 | ChainedRevisor revisor2=new ChainedRevisor(cr); 33 | revisor.revise(node); 34 | revisor2.revise(node); 35 | assertTrue("dimension".equals(node.getName())); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/query/result/ColumnNameRevisorTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | import java.util.ArrayList; 11 | import java.util.HashMap; 12 | import java.util.List; 13 | import java.util.Map; 14 | 15 | import org.junit.Test; 16 | 17 | public class ColumnNameRevisorTest { 18 | @SuppressWarnings({ "rawtypes", "unchecked" }) 19 | @Test 20 | public void testColumn() { 21 | ResultNode node = new ResultNode("testDim", "testDim"); 22 | node.setName("testDim"); 23 | node.setValue("testDim"); 24 | assertTrue("testDim".equals(node.getName())); 25 | assertTrue("testDim".equals(node.getValue())); 26 | 27 | List dimensions = new ArrayList(); 28 | Map nameAliasMap = new HashMap(); 29 | dimensions.add("testDim"); 30 | nameAliasMap.put("testDim", "dimension"); 31 | ColumnNameRevisor cr = new ColumnNameRevisor(dimensions, nameAliasMap); 32 | cr.revise(node); 33 | assertTrue("dimension".equals(node.getName())); 34 | 35 | ColumnValueCollector cc = new ColumnValueCollector("dimension"); 36 | List valueList = new ArrayList(); 37 | ColumnValueCollector cc2 = new ColumnValueCollector("dimension", 38 | valueList); 39 | assertTrue(valueList.equals(cc2.getValueCollection())); 40 | valueList.add("testDim"); 41 | cc.revise(node); 42 | cc2.revise(node); 43 | assertTrue(valueList.equals(cc2.getValueCollection())); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/query/result/HllMetricRevisorTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.query.result; 7 | 8 | import static org.junit.Assert.assertTrue; 9 | 10 | import java.util.HashSet; 11 | import java.util.Set; 12 | 13 | import org.junit.Test; 14 | 15 | public class HllMetricRevisorTest { 16 | @Test 17 | public void testHllMetricRevisor(){ 18 | ResultNode node = new ResultNode("testDim", "testDim"); 19 | node.setName("testDim"); 20 | node.setValue(10); 21 | Set hllSet=new HashSet(); 22 | hllSet.add("testDim"); 23 | HllMetricRevisor revisor=new HllMetricRevisor(hllSet); 24 | revisor.revise(node); 25 | assertTrue(10L==(Long)node.getValue()); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/util/JsonUtilTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.util; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | import org.junit.Test; 14 | 15 | import com.fasterxml.jackson.core.JsonProcessingException; 16 | 17 | public class JsonUtilTest { 18 | 19 | @Test 20 | public void test() throws JsonProcessingException { 21 | Map map=new HashMap(); 22 | map.put("testKay", "testValue"); 23 | 24 | //JsonUtil.readValue(src, valueType); 25 | assertEquals("{\"testKay\":\"testValue\"}",JsonUtil.writeValueAsString(map)); 26 | assertEquals("{\r\n \"testKay\" : \"testValue\"\r\n}",JsonUtil.writeValueAsIndentString(map)); 27 | assertEquals("{\"testKay\":\"testValue\"}".getBytes().length,JsonUtil.writeValueAsBytes(map).length); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/util/SerializerTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.util; 7 | 8 | import static org.junit.Assert.assertTrue; 9 | 10 | import java.io.IOException; 11 | 12 | import org.junit.Test; 13 | 14 | import com.ebay.pulsar.analytics.dao.model.DBDataSource; 15 | 16 | public class SerializerTest { 17 | @SuppressWarnings({ "unchecked", "rawtypes" }) 18 | @Test 19 | public void testSerializer() throws IOException{ 20 | Serializer serializer=new Serializer(DBDataSource.class); 21 | DBDataSource datasource=new DBDataSource(); 22 | datasource.setName("test"); 23 | assertTrue(serializer.deserialize(serializer.serialize(datasource)).equals(datasource)); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /pulsarquery-core/src/test/java/com/ebay/pulsar/analytics/util/SlugifyTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | package com.ebay.pulsar.analytics.util; 7 | 8 | import static org.junit.Assert.*; 9 | 10 | import java.util.HashMap; 11 | import java.util.Map; 12 | 13 | import org.junit.Test; 14 | 15 | public class SlugifyTest { 16 | private Slugify slg = new Slugify(); 17 | 18 | @Test 19 | public void testSlugify() { 20 | slg.setLowerCase(false); 21 | assertEquals("Hello_World", slg.slugify("Hello World")); 22 | assertEquals("HelloWorld", slg.slugify("HelloWorld")); 23 | slg.setLowerCase(true); 24 | assertEquals("hello_world", slg.slugify("Hello World")); 25 | Map customReplacements = new HashMap(); 26 | customReplacements.put("Hello","x"); 27 | slg.setCustomReplacements(customReplacements); 28 | assertEquals("x_world", slg.slugify("Hello World") ); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/datasource/DruidDataSourceProviderFactory.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource; 8 | 9 | import com.ebay.pulsar.analytics.metricstore.druid.query.DruidQueryProcessor; 10 | import com.ebay.pulsar.analytics.query.SQLQueryProcessor; 11 | 12 | 13 | /** 14 | * 15 | * @author mingmwang 16 | * 17 | */ 18 | public class DruidDataSourceProviderFactory extends AbstractDataSourceProviderFactory { 19 | private final static DruidDataSourceProviderFactory instance = new DruidDataSourceProviderFactory(); 20 | public static DruidDataSourceProviderFactory getInstance(){ 21 | return instance; 22 | } 23 | 24 | private SQLQueryProcessor processor = new DruidQueryProcessor(); 25 | 26 | 27 | public SQLQueryProcessor getProcessor() { 28 | return processor; 29 | } 30 | 31 | public void setProcessor(SQLQueryProcessor processor) { 32 | this.processor = processor; 33 | } 34 | 35 | private DruidDataSourceProviderFactory(){ 36 | DataSourceTypeRegistry.registerDataSourceType(DataSourceTypeEnum.DRUID, DruidDataSourceProviderFactory.class); 37 | } 38 | 39 | @Override 40 | public DBConnector getDBCollector(DataSourceConfiguration configuration) { 41 | return new DruidRestDBConnector(configuration); 42 | } 43 | 44 | @Override 45 | public SQLQueryProcessor queryProcessor() { 46 | return processor; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/datasource/DruidRestTableMeta.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource; 8 | 9 | 10 | import java.util.Set; 11 | 12 | /** 13 | * 14 | * @author mingmwang 15 | * 16 | */ 17 | public class DruidRestTableMeta { 18 | private Set dimensions; 19 | private Set metrics; 20 | 21 | public Set getDimensions() { 22 | return dimensions; 23 | } 24 | public void setDimensions(Set dimensions) { 25 | this.dimensions = dimensions; 26 | } 27 | public Set getMetrics() { 28 | return metrics; 29 | } 30 | public void setMetrics(Set metrics) { 31 | this.metrics = metrics; 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | final int prime = 31; 37 | int result = 1; 38 | result = prime * result 39 | + ((dimensions == null) ? 0 : dimensions.hashCode()); 40 | result = prime * result + ((metrics == null) ? 0 : metrics.hashCode()); 41 | return result; 42 | } 43 | @Override 44 | public boolean equals(Object obj) { 45 | if (this == obj) 46 | return true; 47 | if (obj == null) 48 | return false; 49 | if (getClass() != obj.getClass()) 50 | return false; 51 | DruidRestTableMeta other = (DruidRestTableMeta) obj; 52 | if (dimensions == null) { 53 | if (other.dimensions != null) 54 | return false; 55 | } else if (!dimensions.equals(other.dimensions)) 56 | return false; 57 | if (metrics == null) { 58 | if (other.metrics != null) 59 | return false; 60 | } else if (!metrics.equals(other.metrics)) 61 | return false; 62 | return true; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/aggregator/BaseAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.aggregator; 8 | 9 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.AggregatorType; 10 | 11 | /** 12 | * 13 | * @author rtao 14 | * 15 | */ 16 | public abstract class BaseAggregator { 17 | private AggregatorType type; 18 | private String name; 19 | 20 | public BaseAggregator(AggregatorType type, String name) { 21 | this.type = type; 22 | this.name = name; 23 | } 24 | 25 | public AggregatorType getType() { 26 | return type; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public abstract byte[] cacheKey(); 34 | 35 | @Override 36 | public int hashCode() { 37 | final int prime = 31; 38 | int result = 1; 39 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 40 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (obj == null) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | BaseAggregator other = (BaseAggregator) obj; 53 | if (name == null) { 54 | if (other.name != null) 55 | return false; 56 | } else if (!name.equals(other.name)) 57 | return false; 58 | if (type != other.type) 59 | return false; 60 | return true; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/aggregator/CountAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.aggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.AggregatorType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class CountAggregator extends BaseAggregator { 19 | private static final byte CACHE_TYPE_ID = 0x0; 20 | 21 | public CountAggregator(String name) { 22 | super(AggregatorType.count, name); 23 | } 24 | 25 | @Override 26 | public byte[] cacheKey() { 27 | byte[] nameBytes = super.getName().getBytes(); 28 | return ByteBuffer.allocate(1 + nameBytes.length).put(CACHE_TYPE_ID).put(nameBytes).array(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/aggregator/DoubleSumAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.aggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.AggregatorType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class DoubleSumAggregator extends BaseAggregator { 19 | private String fieldName; 20 | 21 | private static final byte CACHE_TYPE_ID = 0x2; 22 | 23 | public DoubleSumAggregator(String name, String fieldName) { 24 | super(AggregatorType.doubleSum, name); 25 | this.fieldName = fieldName; 26 | } 27 | 28 | public String getFieldName() { 29 | return fieldName; 30 | } 31 | 32 | @Override 33 | public byte[] cacheKey() { 34 | byte[] nameBytes = super.getName().getBytes(); 35 | byte[] fieldNameBytes = fieldName.getBytes(); 36 | 37 | return ByteBuffer.allocate(1 + nameBytes.length + fieldNameBytes.length).put(CACHE_TYPE_ID) 38 | .put(nameBytes).put(fieldNameBytes).array(); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | final int prime = 31; 44 | int result = super.hashCode(); 45 | result = prime * result 46 | + ((fieldName == null) ? 0 : fieldName.hashCode()); 47 | return result; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object obj) { 52 | if (this == obj) 53 | return true; 54 | if (!super.equals(obj)) 55 | return false; 56 | if (getClass() != obj.getClass()) 57 | return false; 58 | DoubleSumAggregator other = (DoubleSumAggregator) obj; 59 | if (fieldName == null) { 60 | if (other.fieldName != null) 61 | return false; 62 | } else if (!fieldName.equals(other.fieldName)) 63 | return false; 64 | return true; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/aggregator/HyperUniqueAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.aggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.AggregatorType; 11 | 12 | /** 13 | * 14 | * @author rtao 15 | * 16 | */ 17 | public class HyperUniqueAggregator extends BaseAggregator { 18 | private String fieldName; 19 | 20 | private static final byte CACHE_TYPE_ID = 0x5; 21 | 22 | public HyperUniqueAggregator(String name, String fieldName) { 23 | super(AggregatorType.hyperUnique, name); 24 | this.fieldName = fieldName; 25 | } 26 | 27 | public String getFieldName() { 28 | return fieldName; 29 | } 30 | 31 | @Override 32 | public byte[] cacheKey() { 33 | byte[] nameBytes = super.getName().getBytes(); 34 | byte[] fieldNameBytes = fieldName.getBytes(); 35 | 36 | return ByteBuffer.allocate(1 + nameBytes.length + fieldNameBytes.length).put(CACHE_TYPE_ID) 37 | .put(nameBytes).put(fieldNameBytes).array(); 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | final int prime = 31; 43 | int result = super.hashCode(); 44 | result = prime * result 45 | + ((fieldName == null) ? 0 : fieldName.hashCode()); 46 | return result; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object obj) { 51 | if (this == obj) 52 | return true; 53 | if (!super.equals(obj)) 54 | return false; 55 | if (getClass() != obj.getClass()) 56 | return false; 57 | HyperUniqueAggregator other = (HyperUniqueAggregator) obj; 58 | if (fieldName == null) { 59 | if (other.fieldName != null) 60 | return false; 61 | } else if (!fieldName.equals(other.fieldName)) 62 | return false; 63 | return true; 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/aggregator/LongSumAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.aggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.AggregatorType; 11 | 12 | /** 13 | * 14 | * @author rtao 15 | * 16 | */ 17 | public class LongSumAggregator extends BaseAggregator { 18 | private String fieldName; 19 | 20 | private static final byte CACHE_TYPE_ID = 0x1; 21 | 22 | public LongSumAggregator(String name, String fieldName) { 23 | super(AggregatorType.longSum, name); 24 | this.fieldName = fieldName; 25 | } 26 | 27 | public String getFieldName() { 28 | return fieldName; 29 | } 30 | 31 | @Override 32 | public byte[] cacheKey() { 33 | byte[] nameBytes = super.getName().getBytes(); 34 | byte[] fieldNameBytes = fieldName.getBytes(); 35 | 36 | return ByteBuffer.allocate(1 + nameBytes.length + fieldNameBytes.length).put(CACHE_TYPE_ID) 37 | .put(nameBytes).put(fieldNameBytes).array(); 38 | } 39 | 40 | @Override 41 | public int hashCode() { 42 | final int prime = 31; 43 | int result = super.hashCode(); 44 | result = prime * result 45 | + ((fieldName == null) ? 0 : fieldName.hashCode()); 46 | return result; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object obj) { 51 | if (this == obj) 52 | return true; 53 | if (!super.equals(obj)) 54 | return false; 55 | if (getClass() != obj.getClass()) 56 | return false; 57 | LongSumAggregator other = (LongSumAggregator) obj; 58 | if (fieldName == null) { 59 | if (other.fieldName != null) 60 | return false; 61 | } else if (!fieldName.equals(other.fieldName)) 62 | return false; 63 | return true; 64 | } 65 | 66 | 67 | } 68 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/aggregator/MaxAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.aggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.AggregatorType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class MaxAggregator extends BaseAggregator { 19 | private String fieldName; 20 | 21 | private static final byte CACHE_TYPE_ID = 0x3; 22 | 23 | public MaxAggregator(String name, String fieldName) { 24 | super(AggregatorType.max, name); 25 | this.fieldName = fieldName; 26 | } 27 | 28 | public String getFieldName() { 29 | return fieldName; 30 | } 31 | 32 | @Override 33 | public byte[] cacheKey() { 34 | byte[] nameBytes = super.getName().getBytes(); 35 | byte[] fieldNameBytes = fieldName.getBytes(); 36 | 37 | return ByteBuffer.allocate(1 + nameBytes.length + fieldNameBytes.length).put(CACHE_TYPE_ID) 38 | .put(nameBytes).put(fieldNameBytes).array(); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | final int prime = 31; 44 | int result = super.hashCode(); 45 | result = prime * result 46 | + ((fieldName == null) ? 0 : fieldName.hashCode()); 47 | return result; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object obj) { 52 | if (this == obj) 53 | return true; 54 | if (!super.equals(obj)) 55 | return false; 56 | if (getClass() != obj.getClass()) 57 | return false; 58 | MaxAggregator other = (MaxAggregator) obj; 59 | if (fieldName == null) { 60 | if (other.fieldName != null) 61 | return false; 62 | } else if (!fieldName.equals(other.fieldName)) 63 | return false; 64 | return true; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/aggregator/MinAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.aggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.AggregatorType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class MinAggregator extends BaseAggregator { 19 | private String fieldName; 20 | 21 | private static final byte CACHE_TYPE_ID = 0x4; 22 | 23 | public MinAggregator(String name, String fieldName) { 24 | super(AggregatorType.min, name); 25 | this.fieldName = fieldName; 26 | } 27 | 28 | public String getFieldName() { 29 | return fieldName; 30 | } 31 | 32 | @Override 33 | public byte[] cacheKey() { 34 | byte[] nameBytes = super.getName().getBytes(); 35 | byte[] fieldNameBytes = fieldName.getBytes(); 36 | 37 | return ByteBuffer.allocate(1 + nameBytes.length + fieldNameBytes.length).put(CACHE_TYPE_ID) 38 | .put(nameBytes).put(fieldNameBytes).array(); 39 | } 40 | 41 | @Override 42 | public int hashCode() { 43 | final int prime = 31; 44 | int result = super.hashCode(); 45 | result = prime * result 46 | + ((fieldName == null) ? 0 : fieldName.hashCode()); 47 | return result; 48 | } 49 | 50 | @Override 51 | public boolean equals(Object obj) { 52 | if (this == obj) 53 | return true; 54 | if (!super.equals(obj)) 55 | return false; 56 | if (getClass() != obj.getClass()) 57 | return false; 58 | MinAggregator other = (MinAggregator) obj; 59 | if (fieldName == null) { 60 | if (other.fieldName != null) 61 | return false; 62 | } else if (!fieldName.equals(other.fieldName)) 63 | return false; 64 | return true; 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/constants/Constants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.constants; 8 | 9 | /** 10 | * 11 | * @author rtao 12 | * 13 | */ 14 | public final class Constants { 15 | public enum QueryType { 16 | timeseries, 17 | topN, 18 | groupBy, 19 | search; 20 | } 21 | 22 | public enum AggregatorType { 23 | count, 24 | longSum, 25 | doubleSum, 26 | min, 27 | max, 28 | cardinality, 29 | hyperUnique, 30 | filtered; 31 | } 32 | 33 | public enum PostAggregatorType { 34 | arithmetic, 35 | fieldAccess, 36 | constant, 37 | hyperUniqueCardinality 38 | } 39 | 40 | public enum FilterType { 41 | selector, 42 | regex, 43 | and, 44 | or, 45 | not 46 | } 47 | 48 | public enum MetricType { 49 | numeric, 50 | lexicographic, 51 | alphaNumeric, 52 | inverted 53 | } 54 | 55 | public enum SortDirection { 56 | ascending, 57 | descending 58 | } 59 | 60 | public enum HavingType { 61 | equalTo, 62 | greaterThan, 63 | lessThan, 64 | and, 65 | or, 66 | not 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/filter/AndFilter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.filter; 8 | 9 | import java.util.List; 10 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.FilterType; 11 | 12 | /** 13 | * 14 | * @author rtao 15 | * 16 | */ 17 | public class AndFilter extends BaseFilter { 18 | private List fields; 19 | 20 | public AndFilter(List fields) { 21 | super(FilterType.and); 22 | this.fields = fields; 23 | } 24 | 25 | public List getFields() { 26 | return fields; 27 | } 28 | 29 | @Override 30 | public byte[] cacheKey() { 31 | return FilterCacheHelper.computeCacheKey(FilterCacheHelper.AND_CACHE_ID, fields); 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | final int prime = 31; 37 | int result = super.hashCode(); 38 | result = prime * result + ((fields == null) ? 0 : fields.hashCode()); 39 | return result; 40 | } 41 | 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) 45 | return true; 46 | if (!super.equals(obj)) 47 | return false; 48 | if (getClass() != obj.getClass()) 49 | return false; 50 | AndFilter other = (AndFilter) obj; 51 | if (fields == null) { 52 | if (other.fields != null) 53 | return false; 54 | } else if (!fields.equals(other.fields)) 55 | return false; 56 | return true; 57 | } 58 | 59 | 60 | } 61 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/filter/BaseFilter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.filter; 8 | 9 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.FilterType; 10 | 11 | /** 12 | * 13 | * @author rtao 14 | * 15 | */ 16 | public abstract class BaseFilter { 17 | private FilterType type; 18 | 19 | public BaseFilter(FilterType type) { 20 | this.type = type; 21 | } 22 | 23 | public FilterType getType() { 24 | return type; 25 | } 26 | 27 | public abstract byte[] cacheKey(); 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | BaseFilter other = (BaseFilter) obj; 46 | if (type != other.type) 47 | return false; 48 | return true; 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/filter/FilterCacheHelper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.filter; 8 | 9 | import java.nio.ByteBuffer; 10 | import java.util.List; 11 | 12 | /** 13 | * 14 | * @author rtao 15 | * 16 | */ 17 | public class FilterCacheHelper { 18 | static final byte NOOP_CACHE_ID = -0x4; 19 | static final byte SELECTOR_CACHE_ID = 0x0; 20 | static final byte AND_CACHE_ID = 0x1; 21 | static final byte OR_CACHE_ID = 0x2; 22 | static final byte NOT_CACHE_ID = 0x3; 23 | static final byte EXTRACTION_CACHE_ID = 0x4; 24 | static final byte REGEX_CACHE_ID = 0x5; 25 | static final byte SEARCH_QUERY_TYPE_ID = 0x6; 26 | static final byte JAVASCRIPT_CACHE_ID = 0x7; 27 | static final byte SPATIAL_CACHE_ID = 0x8; 28 | 29 | static byte[] computeCacheKey(byte cacheIdKey, List filters) { 30 | if (filters.size() == 1) { 31 | return filters.get(0).cacheKey(); 32 | } 33 | 34 | byte[][] cacheKeys = new byte[filters.size()][]; 35 | int totalSize = 0; 36 | int index = 0; 37 | for (BaseFilter field : filters) { 38 | cacheKeys[index] = field.cacheKey(); 39 | totalSize += cacheKeys[index].length; 40 | ++index; 41 | } 42 | 43 | ByteBuffer retVal = ByteBuffer.allocate(1 + totalSize); 44 | retVal.put(cacheIdKey); 45 | for (byte[] cacheKey : cacheKeys) { 46 | retVal.put(cacheKey); 47 | } 48 | return retVal.array(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/filter/NotFilter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.filter; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.FilterType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class NotFilter extends BaseFilter { 19 | private BaseFilter field; 20 | 21 | public NotFilter(BaseFilter field) { 22 | super(FilterType.not); 23 | this.field = field; 24 | } 25 | 26 | public BaseFilter getField() { 27 | return field; 28 | } 29 | 30 | @Override 31 | public byte[] cacheKey() { 32 | byte[] subKey = field.cacheKey(); 33 | return ByteBuffer.allocate(1 + subKey.length).put(FilterCacheHelper.NOT_CACHE_ID).put(subKey).array(); 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | final int prime = 31; 39 | int result = super.hashCode(); 40 | result = prime * result + ((field == null) ? 0 : field.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (!super.equals(obj)) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | NotFilter other = (NotFilter) obj; 53 | if (field == null) { 54 | if (other.field != null) 55 | return false; 56 | } else if (!field.equals(other.field)) 57 | return false; 58 | return true; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/filter/OrFilter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.filter; 8 | 9 | import java.util.List; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.FilterType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class OrFilter extends BaseFilter { 19 | private List fields; 20 | 21 | public OrFilter(List fields) { 22 | super(FilterType.or); 23 | this.fields = fields; 24 | } 25 | 26 | public List getFields() { 27 | return fields; 28 | } 29 | 30 | @Override 31 | public byte[] cacheKey() { 32 | return FilterCacheHelper.computeCacheKey(FilterCacheHelper.OR_CACHE_ID, fields); 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | final int prime = 31; 38 | int result = super.hashCode(); 39 | result = prime * result + ((fields == null) ? 0 : fields.hashCode()); 40 | return result; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object obj) { 45 | if (this == obj) 46 | return true; 47 | if (!super.equals(obj)) 48 | return false; 49 | if (getClass() != obj.getClass()) 50 | return false; 51 | OrFilter other = (OrFilter) obj; 52 | if (fields == null) { 53 | if (other.fields != null) 54 | return false; 55 | } else if (!fields.equals(other.fields)) 56 | return false; 57 | return true; 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/filter/SelectorFilter.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.filter; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.FilterType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class SelectorFilter extends BaseFilter { 19 | private String dimension; 20 | private String value; 21 | 22 | public SelectorFilter(String dimension, String value) { 23 | super(FilterType.selector); 24 | this.dimension = dimension; 25 | this.value = value; 26 | } 27 | 28 | public String getDimension() { 29 | return dimension; 30 | } 31 | 32 | public String getValue() { 33 | return value; 34 | } 35 | 36 | @Override 37 | public byte[] cacheKey() { 38 | byte[] dimensionBytes = dimension.getBytes(); 39 | byte[] valueBytes = value == null ? new byte[] {} : value.getBytes(); 40 | return ByteBuffer.allocate(1 + dimensionBytes.length + valueBytes.length).put(FilterCacheHelper.SELECTOR_CACHE_ID).put(dimensionBytes).put(valueBytes).array(); 41 | } 42 | 43 | @Override 44 | public int hashCode() { 45 | final int prime = 31; 46 | int result = super.hashCode(); 47 | result = prime * result 48 | + ((dimension == null) ? 0 : dimension.hashCode()); 49 | result = prime * result + ((value == null) ? 0 : value.hashCode()); 50 | return result; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object obj) { 55 | if (this == obj) 56 | return true; 57 | if (!super.equals(obj)) 58 | return false; 59 | if (getClass() != obj.getClass()) 60 | return false; 61 | SelectorFilter other = (SelectorFilter) obj; 62 | if (dimension == null) { 63 | if (other.dimension != null) 64 | return false; 65 | } else if (!dimension.equals(other.dimension)) 66 | return false; 67 | if (value == null) { 68 | if (other.value != null) 69 | return false; 70 | } else if (!value.equals(other.value)) 71 | return false; 72 | return true; 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/granularity/BaseGranularity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.granularity; 8 | 9 | /** 10 | * 11 | * @author mingmwang 12 | * 13 | */ 14 | public abstract class BaseGranularity { 15 | public static final BaseGranularity ALL = new SimpleGranularity("all"); 16 | public abstract byte[] cacheKey(); 17 | } 18 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/granularity/DruidGranularityParser.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.granularity; 8 | 9 | import com.ebay.pulsar.analytics.constants.Constants.Granularity; 10 | import com.ebay.pulsar.analytics.constants.ConstantsUtils; 11 | import com.ebay.pulsar.analytics.query.request.PulsarDateTimeFormatter; 12 | 13 | /** 14 | * 15 | * @author mingmwang 16 | * 17 | */ 18 | public class DruidGranularityParser { 19 | private static final String DEFAULT_ORIGIN1 = "1970-01-04T00:00:00-07:00"; 20 | private static final String DEFAULT_ORIGIN2 = "1970-01-01T00:00:00-07:00"; 21 | 22 | public static BaseGranularity parse(String granularityStr) { 23 | if(granularityStr == null || granularityStr.equalsIgnoreCase("all")) { 24 | return BaseGranularity.ALL; 25 | } 26 | String origin = DEFAULT_ORIGIN1; 27 | String duration = null; 28 | Granularity granluarityEnum = ConstantsUtils.getGranularity(granularityStr); 29 | if (granluarityEnum != null) { 30 | duration = ConstantsUtils.getGranularityDuration(granluarityEnum); 31 | if(granluarityEnum == Granularity.month){ 32 | origin = DEFAULT_ORIGIN2; 33 | } 34 | } else { 35 | try { 36 | PulsarDateTimeFormatter.ISO_PERIOD_FORMATTER.parsePeriod(granularityStr); 37 | } catch (Exception ex) { 38 | return new InvalidGranularity(granularityStr); 39 | } 40 | // passed the newDuration() function, that means it's a valid iso8601 string 41 | duration = granularityStr; 42 | } 43 | return new PeriodGranularity(duration, "MST", origin); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/granularity/InvalidGranularity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.granularity; 8 | 9 | /** 10 | * 11 | * @author mingmwang 12 | * 13 | */ 14 | public class InvalidGranularity extends SimpleGranularity { 15 | public InvalidGranularity(String key) { 16 | super(key); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/granularity/SimpleGranularity.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.granularity; 8 | 9 | import com.fasterxml.jackson.annotation.JsonValue; 10 | 11 | /** 12 | * 13 | * @author mingmwang 14 | * 15 | */ 16 | public class SimpleGranularity extends BaseGranularity { 17 | private final String key; 18 | public SimpleGranularity(String key){ 19 | this.key = key; 20 | } 21 | 22 | @Override 23 | public byte[] cacheKey() { 24 | return key.getBytes(); 25 | } 26 | 27 | @JsonValue 28 | public String getKey() { 29 | return key; 30 | } 31 | 32 | @Override 33 | public int hashCode() { 34 | final int prime = 31; 35 | int result = 1; 36 | result = prime * result + ((key == null) ? 0 : key.hashCode()); 37 | return result; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object obj) { 42 | if (this == obj) 43 | return true; 44 | if (obj == null) 45 | return false; 46 | if (getClass() != obj.getClass()) 47 | return false; 48 | SimpleGranularity other = (SimpleGranularity) obj; 49 | if (key == null) { 50 | if (other.key != null) 51 | return false; 52 | } else if (!key.equals(other.key)) 53 | return false; 54 | return true; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/having/AndHaving.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.having; 8 | 9 | import java.util.List; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.HavingType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class AndHaving extends BaseHaving { 19 | private List havingSpecs; 20 | 21 | public AndHaving(List havingSpecs) { 22 | super(HavingType.and); 23 | this.havingSpecs = havingSpecs; 24 | } 25 | 26 | public List getHavingSpecs() { 27 | return havingSpecs; 28 | } 29 | 30 | @Override 31 | public byte[] cacheKey() { 32 | return HavingCacheHelper.computeCacheKey(HavingCacheHelper.AND_CACHE_ID, havingSpecs); 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | final int prime = 31; 38 | int result = super.hashCode(); 39 | result = prime * result 40 | + ((havingSpecs == null) ? 0 : havingSpecs.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (!super.equals(obj)) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | AndHaving other = (AndHaving) obj; 53 | if (havingSpecs == null) { 54 | if (other.havingSpecs != null) 55 | return false; 56 | } else if (!havingSpecs.equals(other.havingSpecs)) 57 | return false; 58 | return true; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/having/BaseHaving.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.having; 8 | 9 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.HavingType; 10 | 11 | /** 12 | * 13 | * @author rtao 14 | * 15 | */ 16 | public abstract class BaseHaving { 17 | private HavingType type; 18 | 19 | public BaseHaving(HavingType type) { 20 | this.type = type; 21 | } 22 | 23 | public HavingType getType() { 24 | return type; 25 | } 26 | 27 | public abstract byte[] cacheKey(); 28 | 29 | @Override 30 | public int hashCode() { 31 | final int prime = 31; 32 | int result = 1; 33 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 34 | return result; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) { 39 | if (this == obj) 40 | return true; 41 | if (obj == null) 42 | return false; 43 | if (getClass() != obj.getClass()) 44 | return false; 45 | BaseHaving other = (BaseHaving) obj; 46 | if (type != other.type) 47 | return false; 48 | return true; 49 | } 50 | 51 | 52 | } 53 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/having/HavingCacheHelper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.having; 8 | 9 | import java.nio.ByteBuffer; 10 | import java.util.List; 11 | 12 | /** 13 | * 14 | * @author rtao 15 | * 16 | */ 17 | public class HavingCacheHelper { 18 | static final byte NOOP_CACHE_ID = -0x4; 19 | static final byte EQUAL_TO_CACHE_ID = 0x0; 20 | static final byte GREATER_THAN_CACHE_ID = 0x1; 21 | static final byte LESS_THAN_CACHE_ID = 0x2; 22 | static final byte AND_CACHE_ID = 0x3; 23 | static final byte OR_CACHE_ID = 0x4; 24 | static final byte NOT_CACHE_ID = 0x5; 25 | 26 | static byte[] computeCacheKey(byte cacheIdKey, List havingSpecs) { 27 | if (havingSpecs.size() == 1) { 28 | return havingSpecs.get(0).cacheKey(); 29 | } 30 | 31 | byte[][] cacheKeys = new byte[havingSpecs.size()][]; 32 | int totalSize = 0; 33 | int index = 0; 34 | for (BaseHaving field : havingSpecs) { 35 | cacheKeys[index] = field.cacheKey(); 36 | totalSize += cacheKeys[index].length; 37 | ++index; 38 | } 39 | 40 | ByteBuffer retVal = ByteBuffer.allocate(1 + totalSize); 41 | retVal.put(cacheIdKey); 42 | for (byte[] cacheKey : cacheKeys) { 43 | retVal.put(cacheKey); 44 | } 45 | return retVal.array(); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/having/NotHaving.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.having; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.HavingType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class NotHaving extends BaseHaving { 19 | private BaseHaving havingSpec; 20 | 21 | public NotHaving(BaseHaving havingSpec) { 22 | super(HavingType.not); 23 | this.havingSpec = havingSpec; 24 | } 25 | 26 | public BaseHaving getHavingSpec() { 27 | return havingSpec; 28 | } 29 | 30 | @Override 31 | public byte[] cacheKey() { 32 | byte[] subKey = havingSpec.cacheKey(); 33 | return ByteBuffer.allocate(1 + subKey.length).put(HavingCacheHelper.NOT_CACHE_ID).put(subKey).array(); 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | final int prime = 31; 39 | int result = super.hashCode(); 40 | result = prime * result 41 | + ((havingSpec == null) ? 0 : havingSpec.hashCode()); 42 | return result; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object obj) { 47 | if (this == obj) 48 | return true; 49 | if (!super.equals(obj)) 50 | return false; 51 | if (getClass() != obj.getClass()) 52 | return false; 53 | NotHaving other = (NotHaving) obj; 54 | if (havingSpec == null) { 55 | if (other.havingSpec != null) 56 | return false; 57 | } else if (!havingSpec.equals(other.havingSpec)) 58 | return false; 59 | return true; 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/having/OrHaving.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.having; 8 | 9 | import java.util.List; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.HavingType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class OrHaving extends BaseHaving { 19 | private List havingSpecs; 20 | 21 | public OrHaving(List havingSpecs) { 22 | super(HavingType.or); 23 | this.havingSpecs = havingSpecs; 24 | } 25 | 26 | public List getHavingSpecs() { 27 | return havingSpecs; 28 | } 29 | 30 | @Override 31 | public byte[] cacheKey() { 32 | return HavingCacheHelper.computeCacheKey(HavingCacheHelper.OR_CACHE_ID, havingSpecs); 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | final int prime = 31; 38 | int result = super.hashCode(); 39 | result = prime * result 40 | + ((havingSpecs == null) ? 0 : havingSpecs.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (!super.equals(obj)) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | OrHaving other = (OrHaving) obj; 53 | if (havingSpecs == null) { 54 | if (other.havingSpecs != null) 55 | return false; 56 | } else if (!havingSpecs.equals(other.havingSpecs)) 57 | return false; 58 | return true; 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/limitspec/OrderByColumnSpec.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.limitspec; 8 | 9 | /** 10 | * 11 | * @author rtao 12 | * 13 | */ 14 | import java.nio.ByteBuffer; 15 | 16 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.SortDirection; 17 | 18 | public class OrderByColumnSpec { 19 | private String dimension; 20 | private SortDirection direction; 21 | 22 | public OrderByColumnSpec(String dimension, SortDirection direction) { 23 | this.dimension = dimension; 24 | this.direction = direction; 25 | } 26 | 27 | public String getDimension() { 28 | return dimension; 29 | } 30 | 31 | public SortDirection getDirection() { 32 | return direction; 33 | } 34 | 35 | public byte[] cacheKey() { 36 | final byte[] dimensionBytes = dimension.getBytes(); 37 | final byte[] directionBytes = direction.name().getBytes(); 38 | 39 | return ByteBuffer.allocate(dimensionBytes.length + directionBytes.length).put(dimensionBytes).put(directionBytes).array(); 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | final int prime = 31; 45 | int result = 1; 46 | result = prime * result 47 | + ((dimension == null) ? 0 : dimension.hashCode()); 48 | result = prime * result 49 | + ((direction == null) ? 0 : direction.hashCode()); 50 | return result; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object obj) { 55 | if (this == obj) 56 | return true; 57 | if (obj == null) 58 | return false; 59 | if (getClass() != obj.getClass()) 60 | return false; 61 | OrderByColumnSpec other = (OrderByColumnSpec) obj; 62 | if (dimension == null) { 63 | if (other.dimension != null) 64 | return false; 65 | } else if (!dimension.equals(other.dimension)) 66 | return false; 67 | if (direction != other.direction) 68 | return false; 69 | return true; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/metric/AlphaNumericMetric.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.metric; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.MetricType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class AlphaNumericMetric extends BaseMetric { 19 | private String previousStop; 20 | 21 | private static final byte CACHE_TYPE_ID = 0x5; 22 | 23 | public AlphaNumericMetric(String previousStop) { 24 | super(MetricType.alphaNumeric); 25 | this.previousStop = previousStop; 26 | } 27 | 28 | public String getPreviousStop() { 29 | return previousStop; 30 | } 31 | 32 | @Override 33 | public byte[] cacheKey() { 34 | final byte[] cacheKey = previousStop.getBytes(); 35 | return ByteBuffer.allocate(1 + cacheKey.length).put(CACHE_TYPE_ID).put(cacheKey).array(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/metric/BaseMetric.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.metric; 8 | 9 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.MetricType; 10 | 11 | /** 12 | * 13 | * @author rtao 14 | * 15 | */ 16 | public abstract class BaseMetric { 17 | private MetricType type; 18 | 19 | public BaseMetric(MetricType type) { 20 | this.type = type; 21 | } 22 | 23 | public MetricType getType() { 24 | return type; 25 | } 26 | 27 | public abstract byte[] cacheKey(); 28 | } 29 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/metric/InvertedMetric.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.metric; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.MetricType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class InvertedMetric extends BaseMetric { 19 | private BaseMetric metric; 20 | 21 | private static final byte CACHE_TYPE_ID = 0x3; 22 | 23 | public InvertedMetric(BaseMetric metric) { 24 | super(MetricType.inverted); 25 | this.metric = metric; 26 | } 27 | 28 | public BaseMetric getMetric() { 29 | return metric; 30 | } 31 | 32 | @Override 33 | public byte[] cacheKey() { 34 | final byte[] cacheKey = metric.cacheKey(); 35 | return ByteBuffer.allocate(1 + cacheKey.length).put(CACHE_TYPE_ID).put(cacheKey).array(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/metric/LexicographicMetric.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.metric; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.MetricType; 12 | import com.google.common.base.Charsets; 13 | 14 | /** 15 | * 16 | * @author rtao 17 | * 18 | */ 19 | public class LexicographicMetric extends BaseMetric { 20 | private String previousStop; 21 | 22 | private static final byte CACHE_TYPE_ID = 0x1; 23 | 24 | public LexicographicMetric(String previousStop) { 25 | super(MetricType.lexicographic); 26 | this.previousStop = previousStop; 27 | } 28 | 29 | public String getPreviousStop() { 30 | return previousStop; 31 | } 32 | 33 | @Override 34 | public byte[] cacheKey() { 35 | byte[] previousStopBytes = previousStop == null ? new byte[] {} : previousStop.getBytes(Charsets.UTF_8); 36 | return ByteBuffer.allocate(1 + previousStopBytes.length).put(CACHE_TYPE_ID).put(previousStopBytes).array(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/metric/NumericMetric.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.metric; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.MetricType; 12 | import com.google.common.base.Charsets; 13 | 14 | /** 15 | * 16 | * @author rtao 17 | * 18 | */ 19 | public class NumericMetric extends BaseMetric { 20 | private String metric; 21 | 22 | private static final byte CACHE_TYPE_ID = 0x0; 23 | 24 | public NumericMetric(String metric) { 25 | super(MetricType.numeric); 26 | this.metric = metric; 27 | } 28 | 29 | public String getMetric() { 30 | return metric; 31 | } 32 | 33 | @Override 34 | public byte[] cacheKey() { 35 | byte[] metricBytes = metric.getBytes(Charsets.UTF_8); 36 | return ByteBuffer.allocate(1 + metricBytes.length).put(CACHE_TYPE_ID).put(metricBytes).array(); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/postaggregator/BasePostAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.postaggregator; 8 | 9 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.PostAggregatorType; 10 | 11 | /** 12 | * 13 | * @author rtao 14 | * 15 | */ 16 | public abstract class BasePostAggregator { 17 | private PostAggregatorType type; 18 | private String name; 19 | 20 | public BasePostAggregator(PostAggregatorType type, String name) { 21 | this.type = type; 22 | this.name = name; 23 | } 24 | 25 | public PostAggregatorType getType() { 26 | return type; 27 | } 28 | 29 | public String getName() { 30 | return name; 31 | } 32 | 33 | public abstract byte[] cacheKey(); 34 | 35 | @Override 36 | public int hashCode() { 37 | final int prime = 31; 38 | int result = 1; 39 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 40 | result = prime * result + ((type == null) ? 0 : type.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) 47 | return true; 48 | if (obj == null) 49 | return false; 50 | if (getClass() != obj.getClass()) 51 | return false; 52 | BasePostAggregator other = (BasePostAggregator) obj; 53 | if (name == null) { 54 | if (other.name != null) 55 | return false; 56 | } else if (!name.equals(other.name)) 57 | return false; 58 | if (type != other.type) 59 | return false; 60 | return true; 61 | } 62 | 63 | 64 | } 65 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/postaggregator/FieldAccessorPostAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.postaggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.PostAggregatorType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class FieldAccessorPostAggregator extends BasePostAggregator { 19 | private String fieldName; 20 | 21 | public FieldAccessorPostAggregator(String name, String fieldName) { 22 | super(PostAggregatorType.fieldAccess, name); 23 | this.fieldName = fieldName; 24 | } 25 | 26 | public String getFieldName() { 27 | return fieldName; 28 | } 29 | 30 | @Override 31 | public byte[] cacheKey() { 32 | byte[] fieldNameBytes = fieldName.getBytes(); 33 | return ByteBuffer.allocate(1 + fieldNameBytes.length).put(PostAggregatorCacheHelper.FIELD_ACCESSOR_CACHE_ID).put(fieldNameBytes).array(); 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | final int prime = 31; 39 | int result = super.hashCode(); 40 | result = prime * result 41 | + ((fieldName == null) ? 0 : fieldName.hashCode()); 42 | return result; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object obj) { 47 | if (this == obj) 48 | return true; 49 | if (!super.equals(obj)) 50 | return false; 51 | if (getClass() != obj.getClass()) 52 | return false; 53 | FieldAccessorPostAggregator other = (FieldAccessorPostAggregator) obj; 54 | if (fieldName == null) { 55 | if (other.fieldName != null) 56 | return false; 57 | } else if (!fieldName.equals(other.fieldName)) 58 | return false; 59 | return true; 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/postaggregator/HyperUniqueCardinalityPostAggregator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.postaggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | 11 | import com.ebay.pulsar.analytics.metricstore.druid.constants.Constants.PostAggregatorType; 12 | 13 | /** 14 | * 15 | * @author rtao 16 | * 17 | */ 18 | public class HyperUniqueCardinalityPostAggregator extends BasePostAggregator { 19 | private String fieldName; 20 | 21 | public HyperUniqueCardinalityPostAggregator(String name, String fieldName) { 22 | super(PostAggregatorType.hyperUniqueCardinality, name); 23 | this.fieldName = fieldName; 24 | } 25 | 26 | public String getFieldName() { 27 | return fieldName; 28 | } 29 | 30 | @Override 31 | public byte[] cacheKey() { 32 | byte[] fieldNameBytes = fieldName.getBytes(); 33 | return ByteBuffer.allocate(1 + fieldNameBytes.length).put(PostAggregatorCacheHelper.HYPERUNIQUECARDINALITY_CACHE_ID).put(fieldNameBytes).array(); 34 | } 35 | 36 | @Override 37 | public int hashCode() { 38 | final int prime = 31; 39 | int result = super.hashCode(); 40 | result = prime * result 41 | + ((fieldName == null) ? 0 : fieldName.hashCode()); 42 | return result; 43 | } 44 | 45 | @Override 46 | public boolean equals(Object obj) { 47 | if (this == obj) 48 | return true; 49 | if (!super.equals(obj)) 50 | return false; 51 | if (getClass() != obj.getClass()) 52 | return false; 53 | HyperUniqueCardinalityPostAggregator other = (HyperUniqueCardinalityPostAggregator) obj; 54 | if (fieldName == null) { 55 | if (other.fieldName != null) 56 | return false; 57 | } else if (!fieldName.equals(other.fieldName)) 58 | return false; 59 | return true; 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/postaggregator/PostAggregatorCacheHelper.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.postaggregator; 8 | 9 | import java.nio.ByteBuffer; 10 | import java.util.List; 11 | 12 | /** 13 | * 14 | * @author rtao 15 | * 16 | */ 17 | public class PostAggregatorCacheHelper { 18 | static final byte NOOP_CACHE_ID = -0x4; 19 | static final byte ARITHMETIC_CACHE_ID = 0x0; 20 | static final byte FIELD_ACCESSOR_CACHE_ID = 0x1; 21 | static final byte CONSTANT_CACHE_ID = 0x2; 22 | static final byte HYPERUNIQUECARDINALITY_CACHE_ID = 0x4; 23 | 24 | static byte[] computeCacheKey(List fields) { 25 | if (fields.size() == 1) { 26 | return fields.get(0).cacheKey(); 27 | } 28 | 29 | byte[][] cacheKeys = new byte[fields.size()][]; 30 | int totalSize = 0; 31 | int index = 0; 32 | for (BasePostAggregator field : fields) { 33 | cacheKeys[index] = field.cacheKey(); 34 | totalSize += cacheKeys[index].length; 35 | ++index; 36 | } 37 | 38 | ByteBuffer retVal = ByteBuffer.allocate(totalSize); 39 | for (byte[] cacheKey : cacheKeys) { 40 | retVal.put(cacheKey); 41 | } 42 | return retVal.array(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/query/sql/AbstractDruidSqlTranslator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.query.sql; 8 | 9 | import java.util.Map; 10 | 11 | import com.ebay.pulsar.analytics.datasource.PulsarTableDimension; 12 | import com.ebay.pulsar.analytics.datasource.Table; 13 | import com.ebay.pulsar.analytics.datasource.TableDimension; 14 | import com.ebay.pulsar.analytics.query.sql.SQLTranslator; 15 | import com.foundationdb.sql.parser.ColumnReference; 16 | import com.foundationdb.sql.parser.QueryTreeNode; 17 | 18 | /** 19 | * 20 | * @author mingmwang 21 | * 22 | */ 23 | public abstract class AbstractDruidSqlTranslator extends SQLTranslator { 24 | @Override 25 | public String checkNameChange (ColumnReference column, Table tableColumnsMeta, Map nodesMapIn) { 26 | String colNameDruid = null; 27 | TableDimension tableDimension = tableColumnsMeta.getColumnMeta(column.getColumnName()); 28 | if (tableDimension != null && (tableDimension instanceof PulsarTableDimension)) { 29 | colNameDruid = ((PulsarTableDimension) tableDimension).getRTOLAPColumnName(); 30 | if(colNameDruid != null) 31 | return colNameDruid; 32 | } 33 | return column.getColumnName(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/query/sql/HllConstants.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.query.sql; 8 | 9 | /** 10 | * 11 | * @author mingmwang 12 | * 13 | */ 14 | public class HllConstants { 15 | public static final String HLLPREFIX = "hllhaving_"; 16 | } 17 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/query/validator/DruidGranularityValidator.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.query.validator; 8 | 9 | import org.joda.time.DateTime; 10 | 11 | import com.ebay.pulsar.analytics.exception.ExceptionErrorCode; 12 | import com.ebay.pulsar.analytics.exception.InvalidQueryParameterException; 13 | import com.ebay.pulsar.analytics.metricstore.druid.granularity.BaseGranularity; 14 | import com.ebay.pulsar.analytics.metricstore.druid.granularity.InvalidGranularity; 15 | import com.ebay.pulsar.analytics.metricstore.druid.granularity.PeriodGranularity; 16 | import com.ebay.pulsar.analytics.query.request.DateRange; 17 | import com.ebay.pulsar.analytics.query.validator.QueryValidator; 18 | 19 | /** 20 | * 21 | * @author mingmwang 22 | * 23 | */ 24 | public class DruidGranularityValidator implements QueryValidator { 25 | private static long ONEDAY_MILLIS = 86400000; 26 | 27 | @Override 28 | public void validate(GranularityAndTimeRange req) { 29 | BaseGranularity granularity = req.getGranularity(); 30 | if (granularity instanceof InvalidGranularity) { 31 | throw new InvalidQueryParameterException( 32 | ExceptionErrorCode.INVALID_GRANULARITY.getErrorMessage() + ((InvalidGranularity)granularity).getKey()); 33 | } 34 | else if(granularity instanceof PeriodGranularity){ 35 | DateRange intervals = req.getIntervals(); 36 | if ("PT1M".equals(((PeriodGranularity)granularity).getPeriod())) { 37 | DateTime start = intervals.getStart(); 38 | DateTime end = intervals.getEnd(); 39 | long intervalTime = end.getMillis() - start.getMillis(); 40 | if (intervalTime > ONEDAY_MILLIS) { 41 | throw new InvalidQueryParameterException(ExceptionErrorCode.INVALID_GRANULARITY_INTERVAL.getErrorMessage()); 42 | } 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/main/java/com/ebay/pulsar/analytics/metricstore/druid/query/validator/GranularityAndTimeRange.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.metricstore.druid.query.validator; 8 | 9 | import com.ebay.pulsar.analytics.metricstore.druid.granularity.BaseGranularity; 10 | import com.ebay.pulsar.analytics.query.request.DateRange; 11 | 12 | /** 13 | * 14 | * @author mingmwang 15 | * 16 | */ 17 | public class GranularityAndTimeRange { 18 | private BaseGranularity granularity; 19 | private DateRange intervals; 20 | 21 | public GranularityAndTimeRange(BaseGranularity granularity, DateRange intervals){ 22 | this.granularity = granularity; 23 | this.intervals = intervals; 24 | } 25 | public BaseGranularity getGranularity() { 26 | return granularity; 27 | } 28 | 29 | public DateRange getIntervals() { 30 | return intervals; 31 | } 32 | @Override 33 | public int hashCode() { 34 | final int prime = 31; 35 | int result = 1; 36 | result = prime * result 37 | + ((granularity == null) ? 0 : granularity.hashCode()); 38 | result = prime * result 39 | + ((intervals == null) ? 0 : intervals.hashCode()); 40 | return result; 41 | } 42 | @Override 43 | public boolean equals(Object obj) { 44 | if (this == obj) 45 | return true; 46 | if (obj == null) 47 | return false; 48 | if (getClass() != obj.getClass()) 49 | return false; 50 | GranularityAndTimeRange other = (GranularityAndTimeRange) obj; 51 | if (granularity == null) { 52 | if (other.granularity != null) 53 | return false; 54 | } else if (!granularity.equals(other.granularity)) 55 | return false; 56 | if (intervals == null) { 57 | if (other.intervals != null) 58 | return false; 59 | } else if (!intervals.equals(other.intervals)) 60 | return false; 61 | return true; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /pulsarquery-druid/src/test/resources/datasources/druid.properties: -------------------------------------------------------------------------------- 1 | datasourcetype=druid 2 | datasourcename=trackingdruid 3 | endpoints=http://test -------------------------------------------------------------------------------- /pulsarquery-pulsar/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 4.0.0 10 | 11 | com.ebay.pulsar 12 | data-analytics-api 13 | 0.2.0 14 | .. 15 | 16 | Pulsar Query 17 | 18 | pulsarquery-pulsar 19 | pulsarquery-pulsar 20 | jar 21 | 22 | 23 | 24 | com.ebay.pulsar 25 | pulsarquery-core 26 | ${project.version} 27 | 28 | 29 | com.ebay.pulsar 30 | pulsarquery-druid 31 | ${project.version} 32 | 33 | 34 | com.ebay.pulsar 35 | pulsarquery-cache 36 | ${project.version} 37 | 38 | 39 | 40 | junit 41 | junit 42 | test 43 | 44 | 45 | org.mockito 46 | mockito-core 47 | test 48 | 49 | 50 | org.powermock 51 | powermock-api-mockito 52 | test 53 | 54 | 55 | mockito-all 56 | org.mockito 57 | 58 | 59 | 60 | 61 | org.powermock 62 | powermock-module-junit4 63 | test 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/main/java/com/ebay/pulsar/analytics/datasource/PulsarDataSourceProviderFactory.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource; 8 | 9 | import com.ebay.pulsar.analytics.exception.DataSourceConfigurationException; 10 | import com.ebay.pulsar.analytics.query.RestQueryProcessor; 11 | import com.ebay.pulsar.analytics.query.SQLQueryProcessor; 12 | 13 | /** 14 | * 15 | * @author mingmwang 16 | * 17 | */ 18 | public class PulsarDataSourceProviderFactory extends AbstractDataSourceProviderFactory { 19 | 20 | private static PulsarDataSourceProviderFactory instance = new PulsarDataSourceProviderFactory(); 21 | public static PulsarDataSourceProviderFactory getInstance(){ 22 | return instance; 23 | } 24 | 25 | private RestQueryProcessor restProcessor; 26 | 27 | private PulsarDataSourceProviderFactory(){ 28 | DataSourceTypeRegistry.registerDataSourceType(DataSourceTypeEnum.PULSAR, PulsarDataSourceProviderFactory.class); 29 | } 30 | 31 | @Override 32 | public DataSourceProvider create(DataSourceConfiguration configuration) { 33 | DataSourceProvider db = super.create(configuration); 34 | return db; 35 | } 36 | 37 | @Override 38 | public DBConnector getDBCollector(DataSourceConfiguration configuration) { 39 | if(!(configuration instanceof PulsarDataSourceConfiguration)){ 40 | throw new DataSourceConfigurationException("Error configuration!"); 41 | } 42 | PulsarDataSourceConfiguration pulsarDataBaseConf = (PulsarDataSourceConfiguration)configuration; 43 | return new PulsarDataBaseConnector(pulsarDataBaseConf); 44 | } 45 | 46 | @Override 47 | public SQLQueryProcessor queryProcessor() { 48 | return restProcessor; 49 | } 50 | 51 | public RestQueryProcessor getRestProcessor() { 52 | return restProcessor; 53 | } 54 | 55 | public void setRestProcessor(RestQueryProcessor restProcessor) { 56 | this.restProcessor = restProcessor; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/main/java/com/ebay/pulsar/analytics/datasource/PulsarDataSourceRoutingStrategy.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource; 8 | 9 | import java.util.Map; 10 | 11 | import org.joda.time.DateTime; 12 | import org.joda.time.Period; 13 | 14 | import com.ebay.pulsar.analytics.query.request.DateRange; 15 | import com.ebay.pulsar.analytics.query.request.PulsarDateTimeFormatter; 16 | import com.google.common.base.Strings; 17 | 18 | /** 19 | * 20 | * @author mingmwang 21 | * 22 | */ 23 | public class PulsarDataSourceRoutingStrategy implements DataSourceRoutingStrategy { 24 | 25 | private Map configuration; 26 | 27 | public Map getConfiguration() { 28 | return configuration; 29 | } 30 | 31 | public void setConfiguration(Map configuration) { 32 | this.configuration = configuration; 33 | } 34 | 35 | @Override 36 | public String getDataSourceName(String tableName, DateRange range, String molapName, String rtolapName) { 37 | PulsarDataSourceRule rule = configuration.get(tableName); 38 | if(!Strings.isNullOrEmpty(molapName) && rule != null){ 39 | Period period = PulsarDateTimeFormatter.ISO_PERIOD_FORMATTER.parsePeriod(rule.getPeriod()); 40 | DateTime start = range.getStart(); 41 | DateTime now = new DateTime(PulsarDateTimeFormatter.MST_TIMEZONE); 42 | DateTime closeDate = now.minus(period); 43 | //MOLAP 44 | if(start.isBefore(closeDate)){ 45 | return molapName; 46 | }else{ 47 | return rtolapName; 48 | } 49 | } 50 | else 51 | return rtolapName; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/main/java/com/ebay/pulsar/analytics/datasource/PulsarDataSourceRule.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource; 8 | 9 | /** 10 | * 11 | * @author mingmwang 12 | * 13 | */ 14 | public class PulsarDataSourceRule { 15 | private String datasourceType; 16 | private String period; 17 | 18 | public PulsarDataSourceRule(String datasourceType, String period) { 19 | this.datasourceType = datasourceType; 20 | this.period = period; 21 | } 22 | 23 | public String getPeriod() { 24 | return period; 25 | } 26 | 27 | public void setPeriod(String period) { 28 | this.period = period; 29 | } 30 | 31 | public String getDatasourceType() { 32 | return datasourceType; 33 | } 34 | 35 | public void setDatasourceType(String datasourceType) { 36 | this.datasourceType = datasourceType; 37 | } 38 | 39 | @Override 40 | public int hashCode() { 41 | final int prime = 31; 42 | int result = 1; 43 | result = prime * result + ((period == null) ? 0 : period.hashCode()); 44 | result = prime * result 45 | + ((datasourceType == null) ? 0 : datasourceType.hashCode()); 46 | return result; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object obj) { 51 | if (this == obj) 52 | return true; 53 | if (obj == null) 54 | return false; 55 | if (getClass() != obj.getClass()) 56 | return false; 57 | PulsarDataSourceRule other = (PulsarDataSourceRule) obj; 58 | if (period == null) { 59 | if (other.period != null) 60 | return false; 61 | } else if (!period.equals(other.period)) 62 | return false; 63 | if (datasourceType == null) { 64 | if (other.datasourceType != null) 65 | return false; 66 | } else if (!datasourceType.equals(other.datasourceType)) 67 | return false; 68 | return true; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/main/java/com/ebay/pulsar/analytics/datasource/PulsarRestMetricRegistry.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource; 8 | 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | import com.google.common.collect.Maps; 13 | 14 | /** 15 | * 16 | * @author mingmwang 17 | * 18 | */ 19 | public class PulsarRestMetricRegistry { 20 | private List metricsList; 21 | private Map metricsMap = Maps.newHashMap(); 22 | 23 | public List getMetricsList() { 24 | return metricsList; 25 | } 26 | public void setMetricsList(List metricsList) { 27 | this.metricsList = metricsList; 28 | } 29 | 30 | public PulsarRestMetricRegistry (List metricsList) { 31 | this.metricsList = metricsList; 32 | for (PulsarRestMetricMeta metricMeta : metricsList) { 33 | String metricName = metricMeta.getMetricName(); 34 | metricsMap.put(metricName, metricMeta); 35 | 36 | List kylinAggregates = metricMeta.getKylinAggregators(); 37 | if (kylinAggregates == null) { 38 | continue; 39 | } 40 | Map aliasAggregateMap = Maps.newHashMap(); 41 | for (String aggregate : kylinAggregates) { 42 | int idx = aggregate.lastIndexOf(' '); 43 | if (idx > 0) { 44 | String alias = aggregate.substring(idx+1); 45 | String aggrSql = aggregate.substring(0, idx); 46 | aliasAggregateMap.put(alias.toLowerCase(), aggrSql); 47 | } 48 | } 49 | metricMeta.setKylinAliasAggregatorMap(aliasAggregateMap); 50 | } 51 | } 52 | 53 | public PulsarRestMetricMeta getMetricsMetaFromName (String metricName) { 54 | return metricsMap.get(metricName); 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/main/java/com/ebay/pulsar/analytics/datasource/loader/PulsarDataSourceConfigurationLoader.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource.loader; 8 | 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import com.ebay.pulsar.analytics.datasource.DataSourceMetaRepo; 13 | import com.ebay.pulsar.analytics.datasource.PulsarDataSourceConfiguration; 14 | 15 | /** 16 | * 17 | * @author mingmwang 18 | * 19 | */ 20 | public class PulsarDataSourceConfigurationLoader implements DataSourceConfigurationLoader { 21 | private static final Logger logger = LoggerFactory.getLogger(PulsarDataSourceConfigurationLoader.class); 22 | 23 | private PulsarDataSourceConfiguration configuration; 24 | 25 | public PulsarDataSourceConfigurationLoader(PulsarDataSourceConfiguration configuration){ 26 | this.configuration = configuration; 27 | } 28 | 29 | @Override 30 | public void load() { 31 | logger.info("Add static metricstore configuration:" + PULSAR_DATASOURCE); 32 | DataSourceMetaRepo.getInstance().addDbConf(PULSAR_DATASOURCE, configuration); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/main/java/com/ebay/pulsar/analytics/holap/query/DruidFilterParser.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.holap.query; 8 | 9 | import java.util.List; 10 | 11 | import com.ebay.pulsar.analytics.datasource.Table; 12 | import com.ebay.pulsar.analytics.exception.SqlTranslationException; 13 | import com.ebay.pulsar.analytics.metricstore.druid.filter.BaseFilter; 14 | import com.ebay.pulsar.analytics.metricstore.druid.query.sql.DruidFilterTranslator; 15 | import com.ebay.pulsar.analytics.query.sql.FilterHavingParser; 16 | import com.foundationdb.sql.parser.ValueNode; 17 | 18 | //////////////////////////////////////////////////////////// 19 | // The DruidFilterParser can be used as the following: 20 | // 21 | // DruidFilterParser parser = new DruidFilterParser(); 22 | // BaseFilter userFilter = parser.parseWhere(req.getFilter(), tableMeta); 23 | //////////////////////////////////////////////////////////// 24 | 25 | public class DruidFilterParser extends FilterHavingParser{ 26 | private DruidFilterTranslator filterTranslator = new DruidFilterTranslator(); 27 | 28 | public BaseFilter parseWhere(String whereClause, Table tableMeta) throws SqlTranslationException { 29 | // Construct SQL Statement "SELECT * FROM TBL WHERE " 30 | StringBuilder strBuilder = new StringBuilder (SELECT_FROM_WHERE); 31 | strBuilder.append(whereClause); 32 | 33 | BaseFilter filter = null; 34 | QueryWhereHaving queryDesc = parse(strBuilder.toString(), tableMeta); 35 | List vNodes = queryDesc.getWhereClauses(); 36 | if (vNodes != null && !vNodes.isEmpty()) { 37 | // Should only have 1 node 38 | ValueNode vNode = vNodes.get(0); 39 | filter = filterTranslator.valueNodeToFilter(vNode, tableMeta); 40 | } 41 | return filter; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/main/java/com/ebay/pulsar/analytics/holap/query/model/QueryMetricProps.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.holap.query.model; 8 | 9 | import com.ebay.pulsar.analytics.datasource.PulsarRestMetricMeta; 10 | import com.ebay.pulsar.analytics.query.request.DateRange; 11 | 12 | /** 13 | * 14 | * @author mingmwang 15 | * 16 | */ 17 | public class QueryMetricProps { 18 | private PulsarRestMetricMeta metricMeta; 19 | private String metric; 20 | private DateRange intervals; 21 | 22 | public QueryMetricProps (PulsarRestMetricMeta metricMeta, DateRange intervals) { 23 | this.metricMeta = metricMeta; 24 | this.metric = metricMeta.getMetricName(); 25 | this.intervals = intervals; 26 | } 27 | 28 | public PulsarRestMetricMeta getMetricMeta () { 29 | return this.metricMeta; 30 | } 31 | 32 | public String getMetric () { 33 | return this.metric; 34 | } 35 | 36 | public DateRange getIntevals () { 37 | return this.intervals; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/test/java/com/ebay/pulsar/analytics/datasource/PulsarDataSourceRoutingStrategyTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | import java.util.HashMap; 12 | import java.util.Map; 13 | 14 | import org.joda.time.DateTime; 15 | import org.junit.Test; 16 | 17 | import com.ebay.pulsar.analytics.query.request.DateRange; 18 | 19 | public class PulsarDataSourceRoutingStrategyTest { 20 | @Test 21 | public void testDataSourceRouting(){ 22 | PulsarDataSourceRoutingStrategy strategy=new PulsarDataSourceRoutingStrategy(); 23 | PulsarDataSourceRule rule = new PulsarDataSourceRule("druid", "P3M"); 24 | rule.setDatasourceType("druid"); 25 | rule.setPeriod("P3M"); 26 | Map configuration=new HashMap(); 27 | configuration.put("event", rule); 28 | strategy.setConfiguration(configuration); 29 | assertEquals(configuration,strategy.getConfiguration()); 30 | DateTime startTime=DateTime.parse("2015-09-15T23:59:59"); 31 | DateTime endTime=DateTime.parse("2015-09-15T23:59:59"); 32 | DateRange dataRange = new DateRange(startTime, endTime); 33 | assertEquals(strategy.getDataSourceName("event", dataRange, "tracking", "trackingdruid"),"trackingdruid"); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /pulsarquery-pulsar/src/test/java/com/ebay/pulsar/analytics/datasource/PulsarDataSourceRuleTest.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.datasource; 8 | 9 | import static org.junit.Assert.*; 10 | 11 | import org.junit.Test; 12 | 13 | public class PulsarDataSourceRuleTest { 14 | @Test 15 | public void testPulsarDataSourceRule() { 16 | PulsarDataSourceRule rule = new PulsarDataSourceRule("druid", "day"); 17 | rule.setDatasourceType("druid"); 18 | rule.setPeriod("day"); 19 | PulsarDataSourceRule rule1 = new PulsarDataSourceRule("druid", "day"); 20 | rule1.setDatasourceType("druid"); 21 | rule1.setPeriod("day"); 22 | assertEquals("druid",rule.getDatasourceType()); 23 | assertEquals("day",rule.getPeriod()); 24 | assertEquals(rule.hashCode(),rule1.hashCode()); 25 | PulsarDataSourceRule rule2 = new PulsarDataSourceRule(null, "day"); 26 | rule2.setPeriod("day"); 27 | PulsarDataSourceRule rule3 = new PulsarDataSourceRule("druid", null); 28 | rule3.setDatasourceType("druid"); 29 | PulsarDataSourceRule rule4 = new PulsarDataSourceRule("druid", "day"); 30 | rule4.setDatasourceType("druid"); 31 | rule4.setPeriod("week"); 32 | PulsarDataSourceRule rule5 = new PulsarDataSourceRule("druid", "day"); 33 | rule5.setDatasourceType("druid1"); 34 | rule5.setPeriod("day"); 35 | assertFalse(rule2.equals(rule)); 36 | assertFalse(rule3.equals(rule)); 37 | assertFalse(rule4.equals(rule)); 38 | assertFalse(rule5.equals(rule)); 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/java/com/ebay/pulsar/analytics/resources/exception/InvalidAPIParameterException.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.resources.exception; 8 | 9 | 10 | public class InvalidAPIParameterException extends RuntimeException{ 11 | /** 12 | * 13 | */ 14 | private static final long serialVersionUID = 6486713606693730634L; 15 | public InvalidAPIParameterException(String msg){ 16 | super(msg); 17 | } 18 | public InvalidAPIParameterException(String msg,Throwable t){ 19 | super(msg,t); 20 | } 21 | public InvalidAPIParameterException(Throwable t){ 22 | super(t); 23 | } 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/java/com/ebay/pulsar/analytics/resources/init/PulsarQueryBootstrap.java: -------------------------------------------------------------------------------- 1 | /******************************************************************************* 2 | * Copyright © 2012-2015 eBay Software Foundation 3 | * This program is dual licensed under the MIT and Apache 2.0 licenses. 4 | * Please see LICENSE for more information. 5 | *******************************************************************************/ 6 | 7 | package com.ebay.pulsar.analytics.resources.init; 8 | 9 | import java.util.List; 10 | 11 | import com.ebay.pulsar.analytics.datasource.DataSourceMetaRepo; 12 | import com.ebay.pulsar.analytics.datasource.PulsarDataSourceConfiguration; 13 | import com.ebay.pulsar.analytics.datasource.loader.DataSourceConfigurationLoader; 14 | import com.ebay.pulsar.analytics.datasource.loader.DynamicDataSourceConfigurationLoader; 15 | import com.ebay.pulsar.analytics.datasource.loader.PeriodicalConfigurationLoader; 16 | import com.ebay.pulsar.analytics.datasource.loader.PulsarDataSourceConfigurationLoader; 17 | import com.ebay.pulsar.analytics.datasource.loader.StaticDataSourceConfigurationLoader; 18 | 19 | /** 20 | * 21 | * Bootstrap all the configurations of the processors and DB resources. 22 | * 23 | * @author mingmwang 24 | */ 25 | public class PulsarQueryBootstrap { 26 | 27 | public PulsarQueryBootstrap(List preLoadClazz, PulsarDataSourceConfiguration pulsarConfiguration) throws ClassNotFoundException { 28 | for(String clazz : preLoadClazz) 29 | Class.forName(clazz); 30 | initDBConfiguration(pulsarConfiguration); 31 | } 32 | 33 | private void initDBConfiguration(PulsarDataSourceConfiguration pulsarConfiguration) { 34 | try{ 35 | DataSourceConfigurationLoader staticLoader = new StaticDataSourceConfigurationLoader(); 36 | staticLoader.load(); 37 | }catch(Throwable ex){ 38 | } 39 | 40 | try{ 41 | DataSourceConfigurationLoader pulsarLoader = new PulsarDataSourceConfigurationLoader(pulsarConfiguration); 42 | pulsarLoader.load(); 43 | }catch(Throwable ex){ 44 | } 45 | 46 | try{ 47 | DataSourceConfigurationLoader periodLoader = new PeriodicalConfigurationLoader(new DynamicDataSourceConfigurationLoader()); 48 | periodLoader.load(); 49 | }catch(Throwable ex){ 50 | } 51 | 52 | //early init all metadata 53 | DataSourceMetaRepo.getInstance().getAllDBMeta(); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/resources/context.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 30 | 31 | 32 | 33 | 34 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/resources/datasources/druid.properties: -------------------------------------------------------------------------------- 1 | datasourcetype=druid 2 | datasourcename=trackingdruid 3 | endpoints=http://pulsarioDruid:8082/druid/v2 4 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/resources/env.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 30 | 31 | 33 | 34 | 35 | file:///${user.home}/pulsar-config.properties 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | UTF-8 13 | 14 | ${default_pattern} 15 | 16 | 17 | 18 | 19 | UTF-8 20 | ${catalina.home}/logs/pulsar-query.log 21 | 22 | ${catalina.home}/logs/pulsar-query.log.%d{yyyy-MM-dd} 23 | 15 24 | 25 | 26 | ${default_pattern} 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/resources/pulsar-config.properties: -------------------------------------------------------------------------------- 1 | pulsarquery.db.driver=com.mysql.jdbc.Driver 2 | pulsarquery.db.url=jdbc:mysql://pulsarioDruid:3306/pulsarreport 3 | pulsarquery.db.user=root 4 | pulsarquery.db.password= 5 | pulsarquery.db.table.name.prefix=PULSAR_ 6 | pulsarquery.cache.use.cache=true 7 | pulsarquery.cache.populate.cache=true 8 | pulsarquery.cache.uncache=search 9 | pulsarquery.cache.expiration.core=2592000 10 | pulsarquery.cache.expiration.realtime=10 11 | pulsarquery.cache.expiration.sql=86400 12 | pulsarquery.cache.expiration.today=900 13 | pulsarquery.cache.expiration.yesterday=86400 14 | pulsarquery.memcached.hosts=pulsarioMemcached:11211 15 | pulsarquery.memcached.op.timeout=2000 16 | pulsarquery.memcached.op.max.object.size=52428800 17 | pulsarquery.memcached.op.read.buffer.size=16384 18 | pulsarquery.memcached.max.operation.queue.size=0 19 | pulsarquery.memcached.key.prefix=druid-api 20 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/resources/simple/authentication-security.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 16 | 17 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /pulsarquery-service/src/main/webapp/WEB-INF/deployServlet-servlet.xml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 20 | 21 | 22 | 23 | GET 24 | POST 25 | 26 | 27 | 28 | 29 | 31 | 32 | /WEB-INF/jsp/ 33 | 34 | 35 | .jsp 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | --------------------------------------------------------------------------------