├── 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 extends DataSourceProviderFactory> clazz){
25 | factryRegistry.put(dataSourceType, clazz);
26 | }
27 |
28 | public static DataSourceProviderFactory getDataSourceFactory(DataSourceTypeEnum dataSourceType){
29 | Class extends DataSourceProviderFactory> 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