mirror of
https://github.com/NationalSecurityAgency/timely.git
synced 2026-11-10 03:41:25 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f86b20c02 | ||
|
|
a3620a3f24 | ||
|
|
9c99e74958 | ||
|
|
91ec36e819 | ||
|
|
9ad1b18b74 | ||
|
|
82c45d4dd4 |
No files matched your search
+1
-1
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>timely-analytics</artifactId>
|
||||
<!--
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>timely-balancer</artifactId>
|
||||
<dependencies>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package timely.balancer;
|
||||
|
||||
import static org.apache.accumulo.core.conf.ConfigurationTypeHelper.getTimeInMillis;
|
||||
import static timely.Server.SERVICE_DISCOVERY_PATH;
|
||||
import static timely.store.cache.DataStoreCache.NON_CACHED_METRICS;
|
||||
import static timely.store.cache.DataStoreCache.NON_CACHED_METRICS_LOCK_PATH;
|
||||
@@ -57,7 +58,6 @@ import io.netty.handler.stream.ChunkedWriteHandler;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import io.netty.util.NettyRuntime;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
import org.apache.accumulo.core.conf.AccumuloConfiguration;
|
||||
import org.apache.curator.RetryPolicy;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
@@ -378,8 +378,7 @@ public class Balancer {
|
||||
|
||||
// start curator framework
|
||||
RetryPolicy retryPolicy = new RetryForever(1000);
|
||||
int timeout = Long.valueOf(AccumuloConfiguration.getTimeInMillis(balancerConfig.getZooKeeper().getTimeout()))
|
||||
.intValue();
|
||||
int timeout = Long.valueOf(getTimeInMillis(balancerConfig.getZooKeeper().getTimeout())).intValue();
|
||||
curatorFramework = CuratorFrameworkFactory.newClient(balancerConfig.getZooKeeper().getServers(), timeout, 10000,
|
||||
retryPolicy);
|
||||
curatorFramework.start();
|
||||
|
||||
@@ -31,8 +31,8 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
import com.csvreader.CsvReader;
|
||||
import com.csvreader.CsvWriter;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.SerializationUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.recipes.atomic.DistributedAtomicLong;
|
||||
import org.apache.curator.framework.recipes.atomic.DistributedAtomicValue;
|
||||
|
||||
+2
-2
@@ -4,13 +4,13 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>timely-client</artifactId>
|
||||
<properties>
|
||||
<!-- PEP 440 compliant version gets substituted into src/main/python/template/setup.py -->
|
||||
<!-- use .dev0 instead of -SNAPSHOT -->
|
||||
<python.client.version>1.3.6</python.client.version>
|
||||
<python.client.version>2.0.0</python.client.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -6,7 +6,9 @@ import java.lang.reflect.Modifier;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* A simple interface that objects can implement to return the object size.
|
||||
@@ -46,7 +48,7 @@ public interface ObjectSizeOf {
|
||||
|
||||
public static class Sizer {
|
||||
|
||||
private static final Logger log = Logger.getLogger(Sizer.class.getCanonicalName());
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Sizer.class);
|
||||
public static final short OBJECT_OVERHEAD = 8;
|
||||
public static final short ARRAY_OVERHEAD = 12;
|
||||
public static final short REFERENCE = 4;
|
||||
@@ -150,7 +152,7 @@ public interface ObjectSizeOf {
|
||||
}
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
log.warning("Unable to determine object size for " + o);
|
||||
LOG.warn("Unable to determine object size for " + o, t);
|
||||
}
|
||||
if (debug) {
|
||||
System.out.println(o.getClass().getCanonicalName() + "=" + size);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>collectd-nsq-plugin</artifactId>
|
||||
<dependencies>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>collectd-plugin-parent</artifactId>
|
||||
<dependencies>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>collectd-timely-plugin</artifactId>
|
||||
<dependencies>
|
||||
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>timely-common</artifactId>
|
||||
<dependencies>
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ `uname` == "Darwin" ]]; then
|
||||
THIS_SCRIPT=`python -c 'import os,sys; print os.path.realpath(sys.argv[1])' $0`
|
||||
TCNATIVE_SUFFIX="jnilib"
|
||||
else
|
||||
THIS_SCRIPT=`readlink -f $0`
|
||||
TCNATIVE_SUFFIX="so"
|
||||
fi
|
||||
|
||||
THIS_DIR="${THIS_SCRIPT%/*}"
|
||||
NATIVE_DIR="${THIS_DIR}/META-INF/native"
|
||||
BASE_DIR=${THIS_DIR}/..
|
||||
TMP_DIR="${BASE_DIR}/tmp"
|
||||
CONF_DIR="${BASE_DIR}/conf"
|
||||
LIB_DIR="${BASE_DIR}/lib"
|
||||
NUM_SERVER_THREADS=4
|
||||
|
||||
if [[ -e ${TMP_DIR} ]]; then
|
||||
rm -rf ${TMP_DIR}
|
||||
fi
|
||||
mkdir ${TMP_DIR}
|
||||
|
||||
if [[ -e ${NATIVE_DIR} ]]; then
|
||||
rm -rf ${NATIVE_DIR}
|
||||
fi
|
||||
mkdir -p ${NATIVE_DIR}
|
||||
|
||||
pushd ${BASE_DIR}/bin
|
||||
$JAVA_HOME/bin/jar xf ${LIB_DIR}/netty-tcnative-boringssl-static*.jar META-INF/native/libnetty_tcnative_linux_x86_64.${TCNATIVE_SUFFIX}
|
||||
$JAVA_HOME/bin/jar xf ${LIB_DIR}/netty-all*.jar META-INF/native/libnetty_transport_native_epoll_x86_64.${TCNATIVE_SUFFIX}
|
||||
popd
|
||||
|
||||
export CLASSPATH="${CONF_DIR}:${LIB_DIR}/*:${HADOOP_CONF_DIR}"
|
||||
JVM_ARGS="-Xmx1G -Xms1G -Dio.netty.eventLoopThreads=${NUM_SERVER_THREADS} Dlog4j.configurationFile=${CONF_DIR}/log4j2-spring.xml"
|
||||
JVM_ARGS="${JVM_ARGS} -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector"
|
||||
JVM_ARGS="${JVM_ARGS} -Djava.library.path=${NATIVE_DIR}"
|
||||
|
||||
#JVM_ARGS="${JVM_ARGS} -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005"
|
||||
|
||||
echo "$JAVA_HOME/bin/java ${JVM_ARGS} timely.grafana.auth.GrafanaAuth --spring.config.name=grafana-auth"
|
||||
$JAVA_HOME/bin/java ${JVM_ARGS} timely.grafana.auth.GrafanaAuth --spring.config.name=grafana-auth
|
||||
@@ -1,55 +0,0 @@
|
||||
grafana-auth:
|
||||
grafana:
|
||||
host: localhost
|
||||
port: 3001
|
||||
security:
|
||||
session-max-age: 86400
|
||||
cache-expiration-minutes: 60
|
||||
cache-refresh-minutes: 5
|
||||
allow-anonymous-http-access: true
|
||||
allow-anonymous-ws-access: true
|
||||
serverSsl:
|
||||
certificate-file:
|
||||
key-file:
|
||||
#key-password:
|
||||
use-generated-keypair: true
|
||||
trust-store-file:
|
||||
use-openssl: true
|
||||
#use-ciphers:
|
||||
clientSsl:
|
||||
keyFile:
|
||||
keyType: pkcs12
|
||||
#keyPassword:
|
||||
trustStoreFile:
|
||||
trustStoreType: jks
|
||||
#trustStorePassword:
|
||||
http:
|
||||
host: localhost
|
||||
ip: 127.0.0.1
|
||||
port: 3000
|
||||
redirect-path: /secure-me
|
||||
strict-transport-max-age: 608400
|
||||
cors:
|
||||
allow-any-origin: false
|
||||
allow-null-origin: false
|
||||
allow-credentials: true
|
||||
allowed-origins:
|
||||
allowed-methods: DELETE,GET,HEAD,OPTIONS,PUT,POST
|
||||
allowed-headers: content-type
|
||||
httpClientPool:
|
||||
minIdlePerKey: 0
|
||||
maxIdlePerKey: 40
|
||||
maxTotalPerKey: 40
|
||||
maxTotal: -1
|
||||
lifo: true
|
||||
fairness: false
|
||||
maxWaitMillis: -1
|
||||
minEvictableIdleTimeMillis: 1800000
|
||||
evictorShutdownTimeoutMillis: 10000
|
||||
softMinEvictableIdleTimeMillis: -1
|
||||
numTestsPerEvictionRun: 3
|
||||
timeBetweenEvictionRunsMillis: -1
|
||||
blockWhenExhausted: true
|
||||
jmxEnabled: true
|
||||
testOnBorrow: false
|
||||
testOnReturn: false
|
||||
@@ -1,13 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="warn" monitorInterval="60">
|
||||
<Appenders>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="error" includeLocation="false">
|
||||
<AppenderRef ref="Console" level="error" />
|
||||
</Root>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Configuration status="warn" monitorInterval="60">
|
||||
<Properties>
|
||||
<Property name="PID">????</Property>
|
||||
<Property name="LOG_PATTERN">%clr{%d{yyyy-MM-dd HH:mm:ss.SSS}}{faint} %clr{%5p} %clr{${sys:PID}}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n%wEx</Property>
|
||||
</Properties>
|
||||
<Appenders>
|
||||
<RollingRandomAccessFile name="Rolling" fileName="/srv/logs/timely/grafana-auth.log"
|
||||
filePattern="/srv/logs/timely/$${date:yyyy-MM}/grafana-auth-%d{MM-dd-yyyy}-%i.log.gz">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
<Policies>
|
||||
<SizeBasedTriggeringPolicy size="1024 MB" />
|
||||
</Policies>
|
||||
<DefaultRolloverStrategy max="10" />
|
||||
</RollingRandomAccessFile>
|
||||
<Console name="Console" target="SYSTEM_OUT">
|
||||
<PatternLayout pattern="${LOG_PATTERN}"/>
|
||||
</Console>
|
||||
</Appenders>
|
||||
<Loggers>
|
||||
<Root level="trace" includeLocation="false">
|
||||
<AppenderRef ref="Console" level="warn" />
|
||||
<AppenderRef ref="Rolling" level="trace" />
|
||||
</Root>
|
||||
<Logger name="timely" additivity="false">
|
||||
<AppenderRef ref="Console" level="debug" />
|
||||
</Logger>
|
||||
</Loggers>
|
||||
</Configuration>
|
||||
@@ -1,71 +0,0 @@
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/security"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xmlns:util="http://www.springframework.org/schema/util"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/security
|
||||
http://www.springframework.org/schema/security/spring-security.xsd
|
||||
http://www.springframework.org/schema/util
|
||||
http://www.springframework.org/schema/util/spring-util.xsd">
|
||||
|
||||
<beans:bean id="x509PrincipalExtractor" class="org.springframework.security.web.authentication.preauth.x509.SubjectDnX509PrincipalExtractor">
|
||||
<beans:property name="subjectDnRegex" value="CN=(.*?)(?:,|$)"/>
|
||||
</beans:bean>
|
||||
|
||||
<beans:bean id="timelyUserDetailsService" class="timely.auth.UserDetailsService">
|
||||
<beans:property name="users">
|
||||
<util:list>
|
||||
<beans:bean class="timely.auth.TimelyUser">
|
||||
<beans:constructor-arg name="subjectDn">
|
||||
<beans:value>CN=example.com</beans:value>
|
||||
</beans:constructor-arg>
|
||||
<beans:constructor-arg name="auths">
|
||||
<util:list>
|
||||
<beans:value>D</beans:value>
|
||||
<beans:value>E</beans:value>
|
||||
<beans:value>F</beans:value>
|
||||
</util:list>
|
||||
</beans:constructor-arg>
|
||||
<beans:constructor-arg name="roles">
|
||||
<util:list>
|
||||
<beans:value>G</beans:value>
|
||||
<beans:value>H</beans:value>
|
||||
<beans:value>I</beans:value>
|
||||
</util:list>
|
||||
</beans:constructor-arg>
|
||||
</beans:bean>
|
||||
</util:list>
|
||||
</beans:property>
|
||||
</beans:bean>
|
||||
|
||||
<beans:bean id="x509AuthorizationProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
|
||||
<beans:property name="preAuthenticatedUserDetailsService" ref="timelyUserDetailsService" />
|
||||
</beans:bean>
|
||||
|
||||
<user-service id="usernamePasswordService">
|
||||
<user name="test" password="test1" authorities="A,B,C" />
|
||||
</user-service>
|
||||
|
||||
<beans:bean id="noOpPasswordEncoder" class="org.springframework.security.crypto.password.NoOpPasswordEncoder"/>
|
||||
|
||||
<beans:bean id="UserNamePasswordAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider">
|
||||
<beans:property name="userDetailsService" ref="usernamePasswordService"/>
|
||||
<beans:property name="passwordEncoder" ref="noOpPasswordEncoder"/>
|
||||
</beans:bean>
|
||||
|
||||
<authentication-manager alias="authenticationManager">
|
||||
<!-- X509 PreAuthenticated authorization provider -->
|
||||
<authentication-provider ref="x509AuthorizationProvider"/>
|
||||
<!-- Basic authorization provider, validates provided username and password -->
|
||||
<authentication-provider ref="UserNamePasswordAuthenticationProvider" />
|
||||
</authentication-manager>
|
||||
|
||||
<util:list id="requiredRoles" value-type="java.lang.String">
|
||||
<beans:value></beans:value>
|
||||
</util:list>
|
||||
|
||||
<util:list id="requiredAuths" value-type="java.lang.String">
|
||||
<beans:value></beans:value>
|
||||
</util:list>
|
||||
</beans:beans>
|
||||
@@ -1,295 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
</parent>
|
||||
<artifactId>grafana-auth</artifactId>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jdk8</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ben-manes.caffeine</groupId>
|
||||
<artifactId>caffeine</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.flatbuffers</groupId>
|
||||
<artifactId>flatbuffers-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.lukehutch</groupId>
|
||||
<artifactId>fast-classpath-scanner</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.sourceforge.javacsv</groupId>
|
||||
<artifactId>javacsv</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.accumulo</groupId>
|
||||
<artifactId>accumulo-core</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.accumulo</groupId>
|
||||
<artifactId>accumulo-minicluster</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-collections4</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-framework</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-recipes</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-x-discovery</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.hadoop</groupId>
|
||||
<artifactId>hadoop-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.hadoop</groupId>
|
||||
<artifactId>hadoop-common</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>jdk.tools</groupId>
|
||||
<artifactId>jdk.tools</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.hadoop</groupId>
|
||||
<artifactId>hadoop-minicluster</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-websocket</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-log4j2</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-config</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.security</groupId>
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely-balancer</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely-common</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely-server</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lmax</groupId>
|
||||
<artifactId>disruptor</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-tcnative-boringssl-static</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-slf4j-impl</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.javassist</groupId>
|
||||
<artifactId>javassist</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-test-autoconfigure</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>assemble</id>
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
<phase>package</phase>
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<descriptor>src/main/dist/assembly.xml</descriptor>
|
||||
</descriptors>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-dependency-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
<phase>prepare-package</phase>
|
||||
<configuration>
|
||||
<excludeArtifactIds>junit</excludeArtifactIds>
|
||||
<outputDirectory>${project.build.directory}/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>unpack-native</id>
|
||||
<goals>
|
||||
<goal>unpack</goal>
|
||||
</goals>
|
||||
<phase>process-test-classes</phase>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-tcnative-boringssl-static</artifactId>
|
||||
<version>${version.netty-tcnative}</version>
|
||||
<type>jar</type>
|
||||
<overWrite>false</overWrite>
|
||||
<outputDirectory>${project.build.directory}/native</outputDirectory>
|
||||
<includes>**/*.so</includes>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>build-helper-maven-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>add-source</id>
|
||||
<goals>
|
||||
<goal>add-source</goal>
|
||||
</goals>
|
||||
<phase>generate-sources</phase>
|
||||
<configuration>
|
||||
<sources>
|
||||
<source>src/main/generated-java</source>
|
||||
</sources>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<extensions>
|
||||
<!-- Use os-maven-plugin to initialize the "os.detected" properties -->
|
||||
<extension>
|
||||
<groupId>kr.motd.maven</groupId>
|
||||
<artifactId>os-maven-plugin</artifactId>
|
||||
</extension>
|
||||
</extensions>
|
||||
</build>
|
||||
</project>
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">
|
||||
<id>dist</id>
|
||||
<formats>
|
||||
<format>tar.gz</format>
|
||||
</formats>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>README*</include>
|
||||
<include>LICENSE*</include>
|
||||
<include>NOTICE*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.build.directory}</directory>
|
||||
<outputDirectory>lib</outputDirectory>
|
||||
<includes>
|
||||
<include>timely*.jar</include>
|
||||
<include>grafana*.jar</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.build.directory}/lib</directory>
|
||||
<outputDirectory>lib</outputDirectory>
|
||||
<includes>
|
||||
<include>*.jar</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/bin</directory>
|
||||
<outputDirectory>bin</outputDirectory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/conf</directory>
|
||||
<outputDirectory>conf</outputDirectory>
|
||||
<includes>
|
||||
<include>*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<fileSet>
|
||||
<directory>${project.basedir}/src/main/resources/webapp</directory>
|
||||
<outputDirectory>bin/webapp</outputDirectory>
|
||||
<includes>
|
||||
<include>*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
||||
@@ -1,322 +0,0 @@
|
||||
package timely.grafana.auth;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.buffer.PooledByteBufAllocator;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelFuture;
|
||||
import io.netty.channel.ChannelHandler;
|
||||
import io.netty.channel.ChannelInitializer;
|
||||
import io.netty.channel.ChannelOption;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.epoll.EpollEventLoopGroup;
|
||||
import io.netty.channel.epoll.EpollServerSocketChannel;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.ServerSocketChannel;
|
||||
import io.netty.channel.socket.SocketChannel;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
import io.netty.handler.codec.http.HttpContentCompressor;
|
||||
import io.netty.handler.codec.http.HttpContentDecompressor;
|
||||
import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||
import io.netty.handler.codec.http.HttpRequestDecoder;
|
||||
import io.netty.handler.codec.http.HttpResponseEncoder;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import io.netty.handler.ssl.ClientAuth;
|
||||
import io.netty.handler.ssl.OpenSslServerContext;
|
||||
import io.netty.handler.ssl.OpenSslServerSessionContext;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.SslProvider;
|
||||
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
||||
import io.netty.handler.stream.ChunkedWriteHandler;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.balancer.configuration.ClientSsl;
|
||||
import timely.balancer.connection.http.HttpClientPool;
|
||||
import timely.client.http.HttpClient;
|
||||
import timely.configuration.ServerSsl;
|
||||
import timely.grafana.auth.configuration.GrafanaAuthConfiguration;
|
||||
import timely.grafana.auth.configuration.SpringBootstrap;
|
||||
import timely.grafana.auth.netty.http.GrafanaRelayHandler;
|
||||
import timely.grafana.auth.netty.http.GrafanaRequestDecoder;
|
||||
import timely.netty.http.HttpStaticFileServerHandler;
|
||||
import timely.netty.http.NonSslRedirectHandler;
|
||||
import timely.netty.http.TimelyExceptionHandler;
|
||||
import timely.netty.http.auth.X509LoginRequestHandler;
|
||||
|
||||
public class GrafanaAuth {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GrafanaAuth.class);
|
||||
private static final int EPOLL_MIN_MAJOR_VERSION = 2;
|
||||
private static final int EPOLL_MIN_MINOR_VERSION = 6;
|
||||
private static final int EPOLL_MIN_PATCH_VERSION = 32;
|
||||
private static final String OS_NAME = "os.name";
|
||||
private static final String OS_VERSION = "os.version";
|
||||
protected static final CountDownLatch LATCH = new CountDownLatch(1);
|
||||
static ConfigurableApplicationContext applicationContext;
|
||||
|
||||
private final GrafanaAuthConfiguration grafanaAuthConfig;
|
||||
private EventLoopGroup httpWorkerGroup = null;
|
||||
private EventLoopGroup httpBossGroup = null;
|
||||
protected Channel httpChannelHandle = null;
|
||||
protected volatile boolean shutdown = false;
|
||||
|
||||
public GrafanaAuth(GrafanaAuthConfiguration grafanaAuthConfig) throws Exception {
|
||||
this.grafanaAuthConfig = grafanaAuthConfig;
|
||||
}
|
||||
|
||||
protected static ConfigurableApplicationContext initializeContext(String[] args) {
|
||||
SpringApplicationBuilder builder = new SpringApplicationBuilder(SpringBootstrap.class);
|
||||
builder.web(WebApplicationType.NONE);
|
||||
builder.registerShutdownHook(false);
|
||||
return builder.run(args);
|
||||
}
|
||||
|
||||
private void shutdownHook() {
|
||||
|
||||
final Runnable shutdownRunner = () -> {
|
||||
if (!shutdown) {
|
||||
shutdown();
|
||||
}
|
||||
};
|
||||
final Thread hook = new Thread(shutdownRunner, "shutdown-hook-thread");
|
||||
Runtime.getRuntime().addShutdownHook(hook);
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
List<ChannelFuture> channelFutures = new ArrayList<>();
|
||||
|
||||
if (httpChannelHandle != null) {
|
||||
LOG.info("Closing httpChannelHandle");
|
||||
channelFutures.add(httpChannelHandle.close());
|
||||
}
|
||||
|
||||
// wait for the channels to shutdown
|
||||
channelFutures.forEach(f -> {
|
||||
try {
|
||||
f.get();
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Channel:" + f.channel().config() + " -> " + e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
|
||||
int quietPeriod = grafanaAuthConfig.getShutdownQuietPeriod();
|
||||
List<Future<?>> groupFutures = new ArrayList<>();
|
||||
|
||||
if (httpBossGroup != null) {
|
||||
LOG.info("Shutting down httpBossGroup");
|
||||
groupFutures.add(httpBossGroup.shutdownGracefully(quietPeriod, 10, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
if (httpWorkerGroup != null) {
|
||||
LOG.info("Shutting down httpWorkerGroup");
|
||||
groupFutures.add(httpWorkerGroup.shutdownGracefully(quietPeriod, 10, TimeUnit.SECONDS));
|
||||
}
|
||||
|
||||
groupFutures.parallelStream().forEach(f -> {
|
||||
try {
|
||||
f.get();
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Group:" + f.toString() + " -> " + e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
|
||||
if (applicationContext != null) {
|
||||
LOG.info("Closing applicationContext");
|
||||
applicationContext.close();
|
||||
}
|
||||
|
||||
this.shutdown = true;
|
||||
LOG.info("Server shut down.");
|
||||
}
|
||||
|
||||
private static boolean useEpoll() {
|
||||
|
||||
// Should we just return true if this is Linux and if we get an error
|
||||
// during Epoll
|
||||
// setup handle it there?
|
||||
final String os = SystemPropertyUtil.get(OS_NAME).toLowerCase().trim();
|
||||
final String[] version = SystemPropertyUtil.get(OS_VERSION).toLowerCase().trim().split("\\.");
|
||||
if (os.startsWith("linux") && version.length >= 3) {
|
||||
final int major = Integer.parseInt(version[0]);
|
||||
if (major > EPOLL_MIN_MAJOR_VERSION) {
|
||||
return true;
|
||||
} else if (major == EPOLL_MIN_MAJOR_VERSION) {
|
||||
final int minor = Integer.parseInt(version[1]);
|
||||
if (minor > EPOLL_MIN_MINOR_VERSION) {
|
||||
return true;
|
||||
} else if (minor == EPOLL_MIN_MINOR_VERSION) {
|
||||
final int patch = Integer.parseInt(version[2].substring(0, 2));
|
||||
return patch >= EPOLL_MIN_PATCH_VERSION;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected SslContext createSSLContext(GrafanaAuthConfiguration config) throws Exception {
|
||||
|
||||
ServerSsl sslCfg = config.getSecurity().getServerSsl();
|
||||
Boolean generate = sslCfg.isUseGeneratedKeypair();
|
||||
SslContextBuilder ssl;
|
||||
if (generate) {
|
||||
LOG.warn("Using generated self signed server certificate");
|
||||
Date begin = new Date();
|
||||
Date end = new Date(begin.getTime() + 86400000);
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate("localhost", begin, end);
|
||||
ssl = SslContextBuilder.forServer(ssc.certificate(), ssc.privateKey());
|
||||
} else {
|
||||
String cert = sslCfg.getCertificateFile();
|
||||
String key = sslCfg.getKeyFile();
|
||||
String keyPass = sslCfg.getKeyPassword();
|
||||
if (null == cert || null == key) {
|
||||
throw new IllegalArgumentException("Check your SSL properties, something is wrong.");
|
||||
}
|
||||
ssl = SslContextBuilder.forServer(new File(cert), new File(key), keyPass);
|
||||
}
|
||||
|
||||
ssl.ciphers(sslCfg.getUseCiphers());
|
||||
|
||||
// Can't set to REQUIRE because the CORS pre-flight requests will fail.
|
||||
ssl.clientAuth(ClientAuth.OPTIONAL);
|
||||
|
||||
Boolean useOpenSSL = sslCfg.isUseOpenssl();
|
||||
if (useOpenSSL) {
|
||||
ssl.sslProvider(SslProvider.OPENSSL);
|
||||
} else {
|
||||
ssl.sslProvider(SslProvider.JDK);
|
||||
}
|
||||
String trustStore = sslCfg.getTrustStoreFile();
|
||||
if (null != trustStore) {
|
||||
if (!trustStore.isEmpty()) {
|
||||
ssl.trustManager(new File(trustStore));
|
||||
}
|
||||
}
|
||||
return ssl.build();
|
||||
}
|
||||
|
||||
protected SSLContext createSSLClientContext(GrafanaAuthConfiguration config) throws Exception {
|
||||
|
||||
ClientSsl ssl = config.getSecurity().getClientSsl();
|
||||
return HttpClient.getSSLContext(ssl.getTrustStoreFile(), ssl.getTrustStoreType(), ssl.getTrustStorePassword(),
|
||||
ssl.getKeyFile(), ssl.getKeyType(), ssl.getKeyPassword());
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
|
||||
AuthCache.configure(grafanaAuthConfig.getSecurity());
|
||||
final boolean useEpoll = useEpoll();
|
||||
Class<? extends ServerSocketChannel> channelClass;
|
||||
if (useEpoll) {
|
||||
httpWorkerGroup = new EpollEventLoopGroup();
|
||||
httpBossGroup = new EpollEventLoopGroup();
|
||||
channelClass = EpollServerSocketChannel.class;
|
||||
} else {
|
||||
httpWorkerGroup = new NioEventLoopGroup();
|
||||
httpBossGroup = new NioEventLoopGroup();
|
||||
channelClass = NioServerSocketChannel.class;
|
||||
}
|
||||
LOG.info("Using channel class {}", channelClass.getSimpleName());
|
||||
|
||||
final int httpPort = grafanaAuthConfig.getHttp().getPort();
|
||||
final String httpIp = grafanaAuthConfig.getHttp().getIp();
|
||||
SslContext sslCtx = createSSLContext(grafanaAuthConfig);
|
||||
if (sslCtx instanceof OpenSslServerContext) {
|
||||
OpenSslServerContext openssl = (OpenSslServerContext) sslCtx;
|
||||
String application = "GrafanaAuth_" + httpPort;
|
||||
OpenSslServerSessionContext opensslCtx = openssl.sessionContext();
|
||||
opensslCtx.setSessionCacheEnabled(true);
|
||||
opensslCtx.setSessionCacheSize(128);
|
||||
opensslCtx.setSessionIdContext(application.getBytes(StandardCharsets.UTF_8));
|
||||
opensslCtx.setSessionTimeout(grafanaAuthConfig.getSecurity().getSessionMaxAge());
|
||||
}
|
||||
SSLContext clientSSLContext = createSSLClientContext(grafanaAuthConfig);
|
||||
final ServerBootstrap httpServer = new ServerBootstrap();
|
||||
httpServer.group(httpBossGroup, httpWorkerGroup);
|
||||
httpServer.channel(channelClass);
|
||||
httpServer.handler(new LoggingHandler());
|
||||
HttpClientPool httpClientPool = new HttpClientPool(grafanaAuthConfig.getSecurity(), grafanaAuthConfig.getHttp(),
|
||||
clientSSLContext);
|
||||
httpServer.childHandler(setupHttpChannel(grafanaAuthConfig, sslCtx, httpClientPool));
|
||||
httpServer.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
||||
httpServer.option(ChannelOption.SO_BACKLOG, 128);
|
||||
httpServer.option(ChannelOption.SO_KEEPALIVE, true);
|
||||
httpChannelHandle = httpServer.bind(httpIp, httpPort).sync().channel();
|
||||
final String httpAddress = ((InetSocketAddress) httpChannelHandle.localAddress()).getAddress().getHostAddress();
|
||||
|
||||
shutdownHook();
|
||||
LOG.info("Server started. Listening on {}:{} for HTTP traffic", httpAddress, httpPort);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
GrafanaAuth.applicationContext = GrafanaAuth.initializeContext(args);
|
||||
GrafanaAuthConfiguration grafanaAuthConf = GrafanaAuth.applicationContext
|
||||
.getBean(GrafanaAuthConfiguration.class);
|
||||
|
||||
GrafanaAuth grafanaAuth = new GrafanaAuth(grafanaAuthConf);
|
||||
try {
|
||||
grafanaAuth.run();
|
||||
LATCH.await();
|
||||
} catch (final InterruptedException e) {
|
||||
LOG.info("Server shutting down.");
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error running server.", e);
|
||||
} finally {
|
||||
try {
|
||||
grafanaAuth.shutdown();
|
||||
} catch (Exception e) {
|
||||
System.exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected ChannelHandler setupHttpChannel(GrafanaAuthConfiguration config, SslContext sslCtx,
|
||||
HttpClientPool httpClientPool) {
|
||||
|
||||
return new ChannelInitializer<SocketChannel>() {
|
||||
|
||||
@Override
|
||||
protected void initChannel(SocketChannel ch) throws Exception {
|
||||
|
||||
ch.pipeline().addLast("ssl", new NonSslRedirectHandler(config.getHttp(), sslCtx));
|
||||
ch.pipeline().addLast("encoder", new HttpResponseEncoder());
|
||||
ch.pipeline().addLast("decoder", new HttpRequestDecoder());
|
||||
ch.pipeline().addLast("compressor", new HttpContentCompressor());
|
||||
ch.pipeline().addLast("decompressor", new HttpContentDecompressor());
|
||||
// high maximum contentLength so that grafana snapshots can be delivered
|
||||
// might not be necessary if inbound chunking (while proxying) is handled
|
||||
ch.pipeline().addLast("aggregator", new HttpObjectAggregator(2097152));
|
||||
ch.pipeline().addLast("chunker", new ChunkedWriteHandler());
|
||||
ch.pipeline().addLast("grafanaDecoder",
|
||||
new GrafanaRequestDecoder(config.getSecurity(), config.getHttp()));
|
||||
ch.pipeline().addLast("fileServer", new HttpStaticFileServerHandler());
|
||||
ch.pipeline().addLast("login", new X509LoginRequestHandler(config.getSecurity(), config.getHttp()));
|
||||
ch.pipeline().addLast("httpRelay", new GrafanaRelayHandler(config, httpClientPool));
|
||||
ch.pipeline().addLast("error", new TimelyExceptionHandler()
|
||||
.setIgnoreSslHandshakeErrors(config.getSecurity().getServerSsl().isUseGeneratedKeypair()));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package timely.grafana.auth.configuration;
|
||||
|
||||
public class Grafana {
|
||||
|
||||
private String host = "localhost";
|
||||
private Integer port = 3000;
|
||||
private String protocol = "http";
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setPort(Integer port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
public Integer getPort() {
|
||||
return port;
|
||||
}
|
||||
|
||||
public void setProtocol(String protocol) {
|
||||
this.protocol = protocol;
|
||||
}
|
||||
|
||||
public String getProtocol() {
|
||||
return protocol;
|
||||
}
|
||||
}
|
||||
-54
@@ -1,54 +0,0 @@
|
||||
package timely.grafana.auth.configuration;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.boot.context.properties.NestedConfigurationProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import timely.balancer.configuration.BalancerHttp;
|
||||
import timely.balancer.configuration.BalancerSecurity;
|
||||
|
||||
@Validated
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "grafana-auth")
|
||||
public class GrafanaAuthConfiguration {
|
||||
|
||||
@Valid
|
||||
@NestedConfigurationProperty
|
||||
private BalancerHttp http = new BalancerHttp();
|
||||
|
||||
@Valid
|
||||
@NestedConfigurationProperty
|
||||
private BalancerSecurity security = new BalancerSecurity();
|
||||
|
||||
@Valid
|
||||
@NestedConfigurationProperty
|
||||
private Grafana grafana = new Grafana();
|
||||
|
||||
private Integer shutdownQuietPeriod = 5;
|
||||
|
||||
public BalancerSecurity getSecurity() {
|
||||
return security;
|
||||
}
|
||||
|
||||
public BalancerHttp getHttp() {
|
||||
return http;
|
||||
}
|
||||
|
||||
public Grafana getGrafana() {
|
||||
return grafana;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time to wait (in seconds) for connections to finish and to make sure no new
|
||||
* connections happen before shutting down Netty event loop groups.
|
||||
*/
|
||||
public int getShutdownQuietPeriod() {
|
||||
return this.shutdownQuietPeriod;
|
||||
}
|
||||
|
||||
public void setShutdownQuietPeriod(Integer quietPeriod) {
|
||||
this.shutdownQuietPeriod = quietPeriod;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package timely.grafana.auth.configuration;
|
||||
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication(scanBasePackageClasses = { SpringBootstrap.class })
|
||||
public class SpringBootstrap {
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
package timely.grafana.auth.netty.http;
|
||||
|
||||
import static io.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import io.netty.handler.codec.http.DefaultFullHttpResponse;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.FullHttpResponse;
|
||||
import io.netty.handler.codec.http.HttpMethod;
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import io.netty.handler.codec.http.HttpVersion;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpDelete;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpHead;
|
||||
import org.apache.http.client.methods.HttpOptions;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.client.methods.HttpPut;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.message.BasicHeader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StreamUtils;
|
||||
import timely.api.request.timeseries.HttpRequest;
|
||||
import timely.api.response.TimelyException;
|
||||
import timely.auth.TimelyPrincipal;
|
||||
import timely.auth.TimelyUser;
|
||||
import timely.auth.util.DnUtils;
|
||||
import timely.auth.util.HttpHeaderUtils;
|
||||
import timely.balancer.connection.TimelyBalancedHost;
|
||||
import timely.balancer.connection.http.HttpClientPool;
|
||||
import timely.grafana.auth.configuration.GrafanaAuthConfiguration;
|
||||
import timely.grafana.request.GrafanaRequest;
|
||||
import timely.netty.http.TimelyHttpHandler;
|
||||
import timely.netty.http.auth.TimelyAuthenticationToken;
|
||||
|
||||
public class GrafanaRelayHandler extends SimpleChannelInboundHandler<HttpRequest> implements TimelyHttpHandler {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GrafanaRelayHandler.class);
|
||||
private final HttpClientPool httpClientPool;
|
||||
private GrafanaAuthConfiguration config;
|
||||
|
||||
public GrafanaRelayHandler(GrafanaAuthConfiguration config, HttpClientPool httpClientPool) {
|
||||
this.config = config;
|
||||
this.httpClientPool = httpClientPool;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void channelRead0(ChannelHandlerContext ctx, HttpRequest msg) throws Exception {
|
||||
|
||||
CloseableHttpClient client = null;
|
||||
CloseableHttpResponse relayedResponse = null;
|
||||
FullHttpRequest request = null;
|
||||
GrafanaRequest grafanaRequest;
|
||||
TimelyBalancedHost k = null;
|
||||
String relayURI = null;
|
||||
try {
|
||||
try {
|
||||
request = msg.getHttpRequest();
|
||||
String originalURI = request.uri();
|
||||
originalURI = encodeURI(originalURI);
|
||||
|
||||
if (msg instanceof GrafanaRequest) {
|
||||
grafanaRequest = (GrafanaRequest) msg;
|
||||
} else {
|
||||
throw new UnsupportedOperationException("Request not supported");
|
||||
}
|
||||
TimelyAuthenticationToken token = grafanaRequest.getToken();
|
||||
if (token == null) {
|
||||
throw new IllegalStateException("No token on grafana request");
|
||||
}
|
||||
|
||||
String protocol = config.getGrafana().getProtocol();
|
||||
String host = config.getGrafana().getHost();
|
||||
Integer port = config.getGrafana().getPort();
|
||||
k = TimelyBalancedHost.of(host, -1, port, -1, -1, null);
|
||||
client = httpClientPool.borrowObject(k);
|
||||
Multimap<String, String> headers = HttpHeaderUtils.toMultimap(request.headers());
|
||||
|
||||
// If incoming user sets these headers, do not relay them
|
||||
headers.removeAll("x-webauth-user");
|
||||
headers.removeAll("x-webauth-name");
|
||||
TimelyPrincipal principal = token.getTimelyPrincipal();
|
||||
TimelyUser user = principal.getPrimaryUser();
|
||||
String subjectDn = user.getDn().subjectDN();
|
||||
String userName = DnUtils.getCommonName(subjectDn);
|
||||
String loginName = DnUtils.getShortName(subjectDn);
|
||||
headers.put("x-webauth-user", loginName);
|
||||
headers.put("x-webauth-name", userName);
|
||||
List<Header> relayedHeaderList = new ArrayList<>();
|
||||
for (Map.Entry<String, String> h : headers.entries()) {
|
||||
if (!h.getKey().equals(CONTENT_LENGTH.toString())) {
|
||||
relayedHeaderList.add(new BasicHeader(h.getKey(), h.getValue()));
|
||||
}
|
||||
}
|
||||
Header[] headerArray = new Header[relayedHeaderList.size()];
|
||||
relayedHeaderList.toArray(headerArray);
|
||||
relayURI = protocol + "://" + host + ":" + port + originalURI;
|
||||
if (request.method().equals(HttpMethod.HEAD)) {
|
||||
HttpHead relayedRequest = new HttpHead(relayURI);
|
||||
if (headerArray.length > 0) {
|
||||
relayedRequest.setHeaders(headerArray);
|
||||
}
|
||||
relayedResponse = client.execute(relayedRequest);
|
||||
} else if (request.method().equals(HttpMethod.GET)) {
|
||||
HttpGet relayedRequest = new HttpGet(relayURI);
|
||||
if (headerArray.length > 0) {
|
||||
relayedRequest.setHeaders(headerArray);
|
||||
}
|
||||
relayedResponse = client.execute(relayedRequest);
|
||||
} else if (request.method().equals(HttpMethod.POST)) {
|
||||
HttpPost relayedRequest = new HttpPost(relayURI);
|
||||
String content = request.content().toString(StandardCharsets.UTF_8);
|
||||
StringEntity entity = new StringEntity(content);
|
||||
relayedRequest.setEntity(entity);
|
||||
if (headerArray.length > 0) {
|
||||
relayedRequest.setHeaders(headerArray);
|
||||
}
|
||||
relayedResponse = client.execute(relayedRequest);
|
||||
} else if (request.method().equals(HttpMethod.PUT)) {
|
||||
HttpPut relayedRequest = new HttpPut(relayURI);
|
||||
String content = request.content().toString(StandardCharsets.UTF_8);
|
||||
StringEntity entity = new StringEntity(content);
|
||||
relayedRequest.setEntity(entity);
|
||||
if (headerArray.length > 0) {
|
||||
relayedRequest.setHeaders(headerArray);
|
||||
}
|
||||
relayedResponse = client.execute(relayedRequest);
|
||||
} else if (request.method().equals(HttpMethod.DELETE)) {
|
||||
HttpDelete relayedRequest = new HttpDelete(relayURI);
|
||||
if (headerArray.length > 0) {
|
||||
relayedRequest.setHeaders(headerArray);
|
||||
}
|
||||
relayedResponse = client.execute(relayedRequest);
|
||||
} else if (request.method().equals(HttpMethod.OPTIONS)) {
|
||||
HttpOptions relayedRequest = new HttpOptions(relayURI);
|
||||
if (headerArray.length > 0) {
|
||||
relayedRequest.setHeaders(headerArray);
|
||||
}
|
||||
relayedResponse = client.execute(relayedRequest);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
String message = e.getMessage();
|
||||
if (message == null) {
|
||||
LOG.error("", e);
|
||||
} else {
|
||||
LOG.error(message, e);
|
||||
}
|
||||
this.sendHttpError(ctx, new TimelyException(HttpResponseStatus.INTERNAL_SERVER_ERROR.code(),
|
||||
e.getMessage(), e.getLocalizedMessage(), e));
|
||||
return;
|
||||
} finally {
|
||||
if (request != null) {
|
||||
ReferenceCountUtil.release(request);
|
||||
}
|
||||
}
|
||||
|
||||
FullHttpResponse response = null;
|
||||
if (relayedResponse == null) {
|
||||
this.sendHttpError(ctx, new TimelyException(HttpResponseStatus.METHOD_NOT_ALLOWED.code(),
|
||||
"Method not allowed", "Method not allowed"));
|
||||
} else {
|
||||
LOG.debug("RequestURL:{} ResponseCode:{}", relayURI, relayedResponse.getStatusLine().getStatusCode());
|
||||
HttpEntity httpEntity = relayedResponse.getEntity();
|
||||
if (httpEntity == null) {
|
||||
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpResponseStatus.valueOf(relayedResponse.getStatusLine().getStatusCode()));
|
||||
} else {
|
||||
ByteArrayOutputStream baos = new MyByteArrayOutputStream();
|
||||
StreamUtils.copy(httpEntity.getContent(), baos);
|
||||
response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,
|
||||
HttpResponseStatus.valueOf(relayedResponse.getStatusLine().getStatusCode()),
|
||||
Unpooled.copiedBuffer(baos.toByteArray()));
|
||||
response.headers().set(CONTENT_LENGTH, response.content().readableBytes());
|
||||
}
|
||||
for (Header h : relayedResponse.getAllHeaders()) {
|
||||
response.headers().add(h.getName(), h.getValue());
|
||||
}
|
||||
sendResponse(ctx, response);
|
||||
}
|
||||
} finally {
|
||||
if (relayedResponse != null) {
|
||||
relayedResponse.close();
|
||||
}
|
||||
if (client != null && k != null) {
|
||||
httpClientPool.returnObject(k, client);
|
||||
} else {
|
||||
LOG.error("NOT RETURNING CONNECTION! " + msg.getHttpRequest().uri());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static public class MyByteArrayOutputStream extends ByteArrayOutputStream {
|
||||
|
||||
public MyByteArrayOutputStream() {
|
||||
}
|
||||
|
||||
public MyByteArrayOutputStream(int size) {
|
||||
super(size);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public byte[] getBuf() {
|
||||
return buf;
|
||||
}
|
||||
}
|
||||
|
||||
static public String encodeURI(String s) {
|
||||
try {
|
||||
s = s.replaceAll("\\{", URLEncoder.encode("{", "UTF-8"));
|
||||
s = s.replaceAll("\\}", URLEncoder.encode("}", "UTF-8"));
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
return s;
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
package timely.grafana.auth.netty.http;
|
||||
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Multimap;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.handler.codec.MessageToMessageDecoder;
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.QueryStringDecoder;
|
||||
import io.netty.handler.codec.http.cookie.ServerCookieDecoder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.api.request.AuthenticatedRequest;
|
||||
import timely.api.request.timeseries.HttpRequest;
|
||||
import timely.api.response.StrictTransportResponse;
|
||||
import timely.api.response.TimelyException;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.auth.AuthenticationService;
|
||||
import timely.auth.SubjectIssuerDNPair;
|
||||
import timely.auth.TimelyPrincipal;
|
||||
import timely.auth.util.HttpHeaderUtils;
|
||||
import timely.configuration.Http;
|
||||
import timely.configuration.Security;
|
||||
import timely.grafana.request.GrafanaRequest;
|
||||
import timely.netty.Constants;
|
||||
import timely.netty.http.TimelyHttpHandler;
|
||||
import timely.netty.http.auth.TimelyAuthenticationToken;
|
||||
|
||||
public class GrafanaRequestDecoder extends MessageToMessageDecoder<FullHttpRequest> implements TimelyHttpHandler {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(GrafanaRequestDecoder.class);
|
||||
private static final String LOG_RECEIVED_REQUEST = "Received HTTP request {}";
|
||||
private static final String LOG_PARSED_REQUEST = "Parsed request {}";
|
||||
|
||||
private final Security security;
|
||||
private final String nonSecureRedirectAddress;
|
||||
|
||||
public GrafanaRequestDecoder(Security security, Http http) {
|
||||
|
||||
this.security = security;
|
||||
this.nonSecureRedirectAddress = http.getRedirectPath();
|
||||
}
|
||||
|
||||
public static String getSessionId(FullHttpRequest msg) {
|
||||
Multimap<String, String> headers = HttpHeaderUtils.toMultimap(msg.headers());
|
||||
Collection<String> cookies = headers.get(HttpHeaderNames.COOKIE.toString());
|
||||
final StringBuilder buf = new StringBuilder();
|
||||
cookies.forEach(h -> {
|
||||
ServerCookieDecoder.STRICT.decode(h).forEach(c -> {
|
||||
if (c.name().equals(Constants.COOKIE_NAME)) {
|
||||
if (buf.length() == 0) {
|
||||
buf.append(c.value());
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
if (buf.length() == 0) {
|
||||
return null;
|
||||
} else {
|
||||
return buf.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decode(ChannelHandlerContext ctx, FullHttpRequest msg, List<Object> out) throws Exception {
|
||||
|
||||
LOG.trace(LOG_RECEIVED_REQUEST, msg);
|
||||
|
||||
final String uri = msg.uri();
|
||||
final QueryStringDecoder decoder = new QueryStringDecoder(uri);
|
||||
if (decoder.path().equals(nonSecureRedirectAddress)) {
|
||||
out.add(new StrictTransportResponse());
|
||||
return;
|
||||
}
|
||||
|
||||
final String sessionId = getSessionId(msg);
|
||||
LOG.trace("SessionID: " + sessionId);
|
||||
|
||||
HttpRequest request;
|
||||
try {
|
||||
request = new GrafanaRequest();
|
||||
Multimap<String, String> headers = HttpHeaderUtils.toMultimap(msg.headers());
|
||||
((AuthenticatedRequest) request).addHeaders(headers);
|
||||
X509Certificate clientCert = AuthenticationService.getClientCertificate(ctx);
|
||||
TimelyAuthenticationToken token;
|
||||
if (StringUtils.isNotBlank(sessionId)) {
|
||||
TimelyPrincipal principal;
|
||||
((AuthenticatedRequest) request).setSessionId(sessionId);
|
||||
if (AuthCache.containsKey(sessionId)) {
|
||||
principal = AuthCache.get(sessionId);
|
||||
} else {
|
||||
principal = TimelyPrincipal.anonymousPrincipal();
|
||||
}
|
||||
SubjectIssuerDNPair dn = principal.getPrimaryUser().getDn();
|
||||
token = AuthenticationService.getAuthenticationToken(null, dn.subjectDN(), dn.issuerDN());
|
||||
} else if (clientCert != null) {
|
||||
token = AuthenticationService.getAuthenticationToken(clientCert, headers);
|
||||
} else {
|
||||
SubjectIssuerDNPair dn = TimelyPrincipal.anonymousPrincipal().getPrimaryUser().getDn();
|
||||
token = AuthenticationService.getAuthenticationToken(null, dn.subjectDN(), dn.issuerDN());
|
||||
}
|
||||
((AuthenticatedRequest) request).setToken(token);
|
||||
request.setHttpRequest(msg.copy());
|
||||
LOG.trace(LOG_PARSED_REQUEST, request);
|
||||
request.validate();
|
||||
out.add(request);
|
||||
} catch (UnsupportedOperationException | NullPointerException e) {
|
||||
// Return the original http request to route to the static file
|
||||
// server
|
||||
msg.retain();
|
||||
out.add(msg);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
try {
|
||||
AuthenticationService.enforceAccess((AuthenticatedRequest) request);
|
||||
} catch (TimelyException e) {
|
||||
if (!security.isAllowAnonymousHttpAccess()) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
out.clear();
|
||||
throw e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
package timely.grafana.request;
|
||||
|
||||
import io.netty.handler.codec.http.FullHttpRequest;
|
||||
import io.netty.handler.codec.http.QueryStringDecoder;
|
||||
import timely.api.annotation.Http;
|
||||
import timely.api.request.AuthenticatedRequest;
|
||||
import timely.api.request.HttpGetRequest;
|
||||
import timely.api.request.HttpPostRequest;
|
||||
|
||||
@Http(path = "/")
|
||||
public class GrafanaRequest extends AuthenticatedRequest implements HttpGetRequest, HttpPostRequest {
|
||||
|
||||
private FullHttpRequest httpRequest = null;
|
||||
|
||||
@Override
|
||||
public HttpGetRequest parseQueryParameters(QueryStringDecoder decoder) throws Exception {
|
||||
return new GrafanaRequest();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HttpPostRequest parseBody(String content) throws Exception {
|
||||
return new GrafanaRequest();
|
||||
}
|
||||
|
||||
public void setHttpRequest(FullHttpRequest httpRequest) {
|
||||
this.httpRequest = httpRequest;
|
||||
}
|
||||
|
||||
public FullHttpRequest getHttpRequest() {
|
||||
return httpRequest;
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<FindBugsFilter>
|
||||
<Match>
|
||||
<Class name="timely.grafana.auth.netty.http.GrafanaRelayHandler$MyByteArrayOutputStream" />
|
||||
<Method name="getBuf" />
|
||||
<Bug pattern="EI_EXPOSE_REP" />
|
||||
</Match>
|
||||
<Match>
|
||||
<!-- this is bad practice, but changing it would change behavior; probably needs more triage -->
|
||||
<Class name="timely.grafana.auth.netty.http.GrafanaRequestDecoder" />
|
||||
<Method name="decode" />
|
||||
<Bug pattern="DCN_NULLPOINTER_EXCEPTION" />
|
||||
</Match>
|
||||
<Match>
|
||||
<!-- these are probably avoidable, but needs further triage to fix -->
|
||||
<Bug pattern="EI_EXPOSE_REP" />
|
||||
</Match>
|
||||
<Match>
|
||||
<!-- these are probably avoidable, but needs further triage to fix -->
|
||||
<Bug pattern="EI_EXPOSE_REP2" />
|
||||
</Match>
|
||||
</FindBugsFilter>
|
||||
+1
-1
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>timely-app</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
Vendored
+2
-2
@@ -28,8 +28,8 @@
|
||||
}
|
||||
],
|
||||
"screenshots": [],
|
||||
"version": "1.3.6",
|
||||
"updated": "2023-10-13"
|
||||
"version": "2.0.0",
|
||||
"updated": "2024-01-17"
|
||||
},
|
||||
"dependencies": {
|
||||
"classnames": "2.2.6",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "timely-datasource",
|
||||
"version": "1.3.6",
|
||||
"version": "2.0.0",
|
||||
"description": "Timely",
|
||||
"backend": true,
|
||||
"alerting": true,
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Timely</name>
|
||||
<description>A secure and scalable time series database based on Apache Accumulo</description>
|
||||
@@ -20,7 +20,6 @@
|
||||
<module>grafana</module>
|
||||
<module>analytics</module>
|
||||
<module>balancer</module>
|
||||
<module>grafana-auth</module>
|
||||
</modules>
|
||||
<scm>
|
||||
<connection>scm:git:https://github.com/NationalSecurityAgency/timely.git</connection>
|
||||
@@ -34,21 +33,25 @@
|
||||
<properties>
|
||||
<assembly.tarLongFileMode>posix</assembly.tarLongFileMode>
|
||||
<collectd-api-jar>/usr/share/collectd/java/collectd-api.jar</collectd-api-jar>
|
||||
<maven.compiler.source>1.8</maven.compiler.source>
|
||||
<maven.compiler.target>1.8</maven.compiler.target>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<!-- Configure the os-maven-plugin extension to expand the classifier on -->
|
||||
<!-- Fedora-"like" systems. -->
|
||||
<os.detection.classifierWithLikes>fedora</os.detection.classifierWithLikes>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<version.accumulo>1.10.3</version.accumulo>
|
||||
<version.accumulo>2.1.2</version.accumulo>
|
||||
<version.buildnumber-maven>1.4</version.buildnumber-maven>
|
||||
<version.caffeine>2.6.2</version.caffeine>
|
||||
<version.caffeine>3.1.6</version.caffeine>
|
||||
<version.collectd>5.7.1</version.collectd>
|
||||
<version.commons-collections4>4.3</version.commons-collections4>
|
||||
<version.commons-lang3>3.8.1</version.commons-lang3>
|
||||
<version.commons-lang3>3.13.0</version.commons-lang3>
|
||||
<version.commons-logging>1.1.1</version.commons-logging>
|
||||
<version.commons-pool2>2.6.1</version.commons-pool2>
|
||||
<version.commons-text>1.10.0</version.commons-text>
|
||||
<version.compression.gorilla>2.1.1</version.compression.gorilla>
|
||||
<version.curator>4.1.0</version.curator>
|
||||
<version.datawave-in-memory-accumulo>2.1.1</version.datawave-in-memory-accumulo>
|
||||
<version.disruptor>3.4.2</version.disruptor>
|
||||
<version.easymock>4.0.2</version.easymock>
|
||||
<version.eclipse-lifecycle>1.0.0</version.eclipse-lifecycle>
|
||||
@@ -59,7 +62,7 @@
|
||||
<version.hadoop>3.3.3</version.hadoop>
|
||||
<version.httpcomponents>4.5.13</version.httpcomponents>
|
||||
<version.impsort>1.9.0</version.impsort>
|
||||
<version.jackson>2.12.7</version.jackson>
|
||||
<version.jackson>2.13.3</version.jackson>
|
||||
<version.jackson.databind>2.12.7.1</version.jackson.databind>
|
||||
<version.jacoco>0.8.4</version.jacoco>
|
||||
<version.jakarta.websocket-api>1.1.1</version.jakarta.websocket-api>
|
||||
@@ -69,7 +72,7 @@
|
||||
<version.jjwt>0.11.2</version.jjwt>
|
||||
<version.jsoup>1.15.3</version.jsoup>
|
||||
<version.junit>4.13.1</version.junit>
|
||||
<version.log4j>2.20.0</version.log4j>
|
||||
<version.log4j2>2.20.0</version.log4j2>
|
||||
<version.maven-assembly>3.1.1</version.maven-assembly>
|
||||
<version.maven-build-helper>3.0.0</version.maven-build-helper>
|
||||
<version.maven-compiler>3.8.1</version.maven-compiler>
|
||||
@@ -79,21 +82,29 @@
|
||||
<version.maven-rpm>2.2.0</version.maven-rpm>
|
||||
<version.maven-shade>3.2.1</version.maven-shade>
|
||||
<version.maven-surefire>3.0.0-M3</version.maven-surefire>
|
||||
<version.netty>4.1.42.Final</version.netty>
|
||||
<version.netty-tcnative>2.0.25.Final</version.netty-tcnative>
|
||||
<version.micrometer>1.11.1</version.micrometer>
|
||||
<version.netty>4.1.45.Final</version.netty>
|
||||
<version.netty-tcnative>2.0.29.Final</version.netty-tcnative>
|
||||
<version.os-maven>1.5.0.Final</version.os-maven>
|
||||
<version.powermock>1.6.4</version.powermock>
|
||||
<version.slf4j>1.7.26</version.slf4j>
|
||||
<version.spotbugs-maven>4.5.0.0</version.spotbugs-maven>
|
||||
<version.spotbugs-maven>4.7.3.5</version.spotbugs-maven>
|
||||
<version.spring-boot>2.1.3.RELEASE</version.spring-boot>
|
||||
<version.tyrus>1.15</version.tyrus>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-bom</artifactId>
|
||||
<version>${version.netty}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-bom</artifactId>
|
||||
<version>${version.log4j}</version>
|
||||
<version>${version.log4j2}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
@@ -118,7 +129,17 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${version.jackson.databind}</version>
|
||||
<version>${version.jackson}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-xml</artifactId>
|
||||
<version>${version.jackson}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.dataformat</groupId>
|
||||
<artifactId>jackson-dataformat-yaml</artifactId>
|
||||
<version>${version.jackson}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
@@ -150,10 +171,26 @@
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>1.9.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>${version.commons-logging}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>fi.iki.yak</groupId>
|
||||
<artifactId>compression-gorilla</artifactId>
|
||||
<version>2.1.1</version>
|
||||
<version>${version.compression.gorilla}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gov.nsa.datawave.contrib</groupId>
|
||||
<artifactId>datawave-in-memory-accumulo</artifactId>
|
||||
<version>${version.datawave-in-memory-accumulo}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.accumulo</groupId>
|
||||
<artifactId>*</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.lukehutch</groupId>
|
||||
@@ -164,12 +201,23 @@
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-impl</artifactId>
|
||||
<version>${version.jjwt}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
<version>${version.jjwt}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
<version>${version.micrometer}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
@@ -180,6 +228,11 @@
|
||||
<artifactId>netty-tcnative-boringssl-static</artifactId>
|
||||
<version>${version.netty-tcnative}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.projectreactor.netty</groupId>
|
||||
<artifactId>reactor-netty</artifactId>
|
||||
<version>${version.reactor-netty}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>jakarta.websocket</groupId>
|
||||
<artifactId>jakarta.websocket-api</artifactId>
|
||||
@@ -199,6 +252,10 @@
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -210,6 +267,10 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -227,6 +288,11 @@
|
||||
<artifactId>commons-pool2</artifactId>
|
||||
<version>${version.commons-pool2}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-text</artifactId>
|
||||
<version>${version.commons-text}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.curator</groupId>
|
||||
<artifactId>curator-client</artifactId>
|
||||
@@ -283,6 +349,10 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty-util</artifactId>
|
||||
@@ -298,6 +368,10 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
@@ -329,6 +403,10 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.mortbay.jetty</groupId>
|
||||
<artifactId>jetty</artifactId>
|
||||
@@ -344,6 +422,12 @@
|
||||
<artifactId>httpclient</artifactId>
|
||||
<version>${version.httpcomponents}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- This bridge allows log4j2 to work with code that is still using the log4j 1.2 classes/api -->
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-1.2-api</artifactId>
|
||||
<version>${version.log4j2}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.glassfish.tyrus</groupId>
|
||||
<artifactId>tyrus-client</artifactId>
|
||||
@@ -364,6 +448,11 @@
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
<version>${version.slf4j}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-log4j12</artifactId>
|
||||
<version>${version.slf4j}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>collectd-plugin-parent</artifactId>
|
||||
@@ -497,7 +586,7 @@
|
||||
<include>**/*.java</include>
|
||||
</includes>
|
||||
<groups>timely.test.IntegrationTest</groups>
|
||||
<redirectTestOutputToFile>true</redirectTestOutputToFile>
|
||||
<redirectTestOutputToFile>false</redirectTestOutputToFile>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
@@ -525,6 +614,11 @@
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-resources-plugin</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
|
||||
+9
-1
@@ -4,7 +4,7 @@
|
||||
<parent>
|
||||
<groupId>timely</groupId>
|
||||
<artifactId>timely</artifactId>
|
||||
<version>1.3.6</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
<artifactId>timely-server</artifactId>
|
||||
<dependencies>
|
||||
@@ -44,6 +44,10 @@
|
||||
<groupId>fi.iki.yak</groupId>
|
||||
<artifactId>compression-gorilla</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>gov.nsa.datawave.contrib</groupId>
|
||||
<artifactId>datawave-in-memory-accumulo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.lukehutch</groupId>
|
||||
<artifactId>fast-classpath-scanner</artifactId>
|
||||
@@ -56,6 +60,10 @@
|
||||
<groupId>io.jsonwebtoken</groupId>
|
||||
<artifactId>jjwt-jackson</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.micrometer</groupId>
|
||||
<artifactId>micrometer-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package timely;
|
||||
|
||||
import static org.apache.accumulo.core.conf.ConfigurationTypeHelper.getTimeInMillis;
|
||||
import static timely.store.cache.DataStoreCache.NON_CACHED_METRICS;
|
||||
import static timely.store.cache.DataStoreCache.NON_CACHED_METRICS_LOCK_PATH;
|
||||
|
||||
@@ -11,6 +12,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -60,7 +62,8 @@ import io.netty.handler.stream.ChunkedWriteHandler;
|
||||
import io.netty.handler.timeout.IdleStateHandler;
|
||||
import io.netty.util.NettyRuntime;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
import org.apache.accumulo.core.conf.AccumuloConfiguration;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.conf.ClientProperty;
|
||||
import org.apache.curator.RetryPolicy;
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.framework.CuratorFrameworkFactory;
|
||||
@@ -81,6 +84,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.auth.JWTTokenHandler;
|
||||
import timely.auth.VisibilityCache;
|
||||
import timely.configuration.Accumulo;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.configuration.Cors;
|
||||
import timely.configuration.ServerSsl;
|
||||
@@ -141,6 +145,7 @@ public class Server {
|
||||
static ConfigurableApplicationContext applicationContext;
|
||||
|
||||
private final Configuration config;
|
||||
private AccumuloClient accumuloClient;
|
||||
private EventLoopGroup tcpWorkerGroup = null;
|
||||
private EventLoopGroup tcpBossGroup = null;
|
||||
private EventLoopGroup httpWorkerGroup = null;
|
||||
@@ -303,9 +308,11 @@ public class Server {
|
||||
// wait for the channels to shutdown
|
||||
channelFutures.forEach(f -> {
|
||||
try {
|
||||
f.get();
|
||||
if (!f.isDone()) {
|
||||
f.get();
|
||||
}
|
||||
} catch (final Exception e) {
|
||||
LOG.error("Channel:" + f.channel().config() + " -> " + e.getMessage(), e);
|
||||
LOG.error("Channel:" + f.channel().config() + " -> " + e.getMessage());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -413,17 +420,40 @@ public class Server {
|
||||
LOG.info("Server shut down.");
|
||||
}
|
||||
|
||||
public Server(Configuration conf, int eventLoopThreads) throws Exception {
|
||||
public Server(Configuration conf, AccumuloClient accumuloClient, int eventLoopThreads) {
|
||||
|
||||
DEFAULT_EVENT_LOOP_THREADS = eventLoopThreads;
|
||||
this.config = conf;
|
||||
if (accumuloClient == null) {
|
||||
this.accumuloClient = createAccumuloClient((conf));
|
||||
} else {
|
||||
this.accumuloClient = accumuloClient;
|
||||
}
|
||||
}
|
||||
|
||||
public Server(Configuration conf) throws Exception {
|
||||
public Server(Configuration conf, AccumuloClient accumuloClient) {
|
||||
this(conf, accumuloClient, Math.max(1,
|
||||
SystemPropertyUtil.getInt("io.netty.eventLoopThreads", NettyRuntime.availableProcessors() * 2)));
|
||||
}
|
||||
|
||||
DEFAULT_EVENT_LOOP_THREADS = Math.max(1,
|
||||
SystemPropertyUtil.getInt("io.netty.eventLoopThreads", NettyRuntime.availableProcessors() * 2));
|
||||
this.config = conf;
|
||||
public Server(Configuration conf) {
|
||||
this(conf, null);
|
||||
}
|
||||
|
||||
private AccumuloClient createAccumuloClient(Configuration conf) {
|
||||
Properties properties = new Properties();
|
||||
Accumulo accumuloConf = conf.getAccumulo();
|
||||
properties.put(ClientProperty.INSTANCE_NAME.getKey(), accumuloConf.getInstanceName());
|
||||
properties.put(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), accumuloConf.getZookeepers());
|
||||
properties.put(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getKey(), accumuloConf.getZookeeperTimeout());
|
||||
properties.put(ClientProperty.AUTH_PRINCIPAL.getKey(), accumuloConf.getUsername());
|
||||
properties.put(ClientProperty.AUTH_TOKEN.getKey(), accumuloConf.getPassword());
|
||||
properties.put(ClientProperty.AUTH_TYPE.getKey(), "password");
|
||||
return org.apache.accumulo.core.client.Accumulo.newClient().from(properties).build();
|
||||
}
|
||||
|
||||
public void setAccumuloClient(AccumuloClient accumuloClient) {
|
||||
this.accumuloClient = accumuloClient;
|
||||
}
|
||||
|
||||
private void ensureZkPaths(CuratorFramework curatorFramework, String[] paths) {
|
||||
@@ -465,8 +495,7 @@ public class Server {
|
||||
public void run() throws Exception {
|
||||
|
||||
RetryPolicy retryPolicy = new RetryForever(1000);
|
||||
int timeout = Long.valueOf(AccumuloConfiguration.getTimeInMillis(config.getAccumulo().getZookeeperTimeout()))
|
||||
.intValue();
|
||||
int timeout = Long.valueOf(getTimeInMillis(config.getAccumulo().getZookeeperTimeout())).intValue();
|
||||
curatorFramework = CuratorFrameworkFactory.newClient(config.getAccumulo().getZookeepers(), timeout, 10000,
|
||||
retryPolicy);
|
||||
curatorFramework.start();
|
||||
@@ -474,7 +503,7 @@ public class Server {
|
||||
|
||||
int nettyThreads = Math.max(1,
|
||||
SystemPropertyUtil.getInt("io.netty.eventLoopThreads", Runtime.getRuntime().availableProcessors() * 2));
|
||||
dataStore = DataStoreFactory.create(config, nettyThreads);
|
||||
dataStore = DataStoreFactory.create(config, accumuloClient, nettyThreads);
|
||||
if (config.getCache().isEnabled()) {
|
||||
dataStoreCache = new DataStoreCache(curatorFramework, config);
|
||||
dataStoreCache.setInternalMetrics(dataStore.getInternalMetrics());
|
||||
@@ -484,7 +513,7 @@ public class Server {
|
||||
MetaCacheFactory.getCache(config);
|
||||
AuthCache.configure(config.getSecurity());
|
||||
VisibilityCache.init(config);
|
||||
JWTTokenHandler.init(config.getSecurity(), config.getAccumulo());
|
||||
JWTTokenHandler.init(config.getSecurity(), accumuloClient);
|
||||
final boolean useEpoll = useEpoll();
|
||||
Class<? extends ServerSocketChannel> channelClass;
|
||||
Class<? extends Channel> datagramChannelClass;
|
||||
@@ -520,7 +549,6 @@ public class Server {
|
||||
tcpServer.childHandler(setupTcpChannel());
|
||||
tcpServer.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
||||
tcpServer.option(ChannelOption.SO_BACKLOG, 128);
|
||||
tcpServer.option(ChannelOption.SO_KEEPALIVE, true);
|
||||
final int tcpPort = config.getServer().getTcpPort();
|
||||
final String tcpIp = config.getServer().getIp();
|
||||
tcpChannelHandle = tcpServer.bind(tcpIp, tcpPort).sync().channel();
|
||||
@@ -545,7 +573,6 @@ public class Server {
|
||||
httpServer.childHandler(setupHttpChannel(config, sslCtx));
|
||||
httpServer.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
||||
httpServer.option(ChannelOption.SO_BACKLOG, 128);
|
||||
httpServer.option(ChannelOption.SO_KEEPALIVE, true);
|
||||
httpChannelHandle = httpServer.bind(httpIp, httpPort).sync().channel();
|
||||
final String httpAddress = ((InetSocketAddress) httpChannelHandle.localAddress()).getAddress().getHostAddress();
|
||||
|
||||
@@ -558,9 +585,7 @@ public class Server {
|
||||
wsServer.childHandler(setupWSChannel(sslCtx, config));
|
||||
wsServer.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
|
||||
wsServer.option(ChannelOption.SO_BACKLOG, 128);
|
||||
wsServer.option(ChannelOption.SO_KEEPALIVE, true);
|
||||
/* Not sure if next two lines are necessary */
|
||||
wsServer.option(ChannelOption.SO_SNDBUF, 1048576);
|
||||
/* Not sure if next line is necessary */
|
||||
wsServer.option(ChannelOption.WRITE_BUFFER_WATER_MARK, new WriteBufferWaterMark(620145, 838860));
|
||||
wsChannelHandle = wsServer.bind(wsIp, wsPort).sync().channel();
|
||||
final String wsAddress = ((InetSocketAddress) wsChannelHandle.localAddress()).getAddress().getHostAddress();
|
||||
@@ -591,7 +616,7 @@ public class Server {
|
||||
Boolean generate = sslCfg.isUseGeneratedKeypair();
|
||||
SslContextBuilder ssl;
|
||||
if (generate) {
|
||||
LOG.warn("Using generated self signed server certificate");
|
||||
LOG.info("Using generated self signed server certificate");
|
||||
Date begin = new Date();
|
||||
Date end = new Date(begin.getTime() + TimeUnit.DAYS.toMillis(7));
|
||||
SelfSignedCertificate ssc = new SelfSignedCertificate("localhost", begin, end);
|
||||
|
||||
@@ -3,10 +3,11 @@ package timely;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.AccumuloException;
|
||||
import org.apache.accumulo.core.client.AccumuloSecurityException;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.admin.SecurityOperations;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.apache.accumulo.minicluster.MemoryUnit;
|
||||
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
|
||||
@@ -73,9 +74,8 @@ public class StandaloneServer extends Server {
|
||||
System.err.println("Error starting MiniAccumuloCluster: " + e.getMessage());
|
||||
System.exit(1);
|
||||
}
|
||||
try {
|
||||
Connector conn = mac.getConnector("root", "secret");
|
||||
SecurityOperations sops = conn.securityOperations();
|
||||
try (AccumuloClient accumuloClient = mac.createAccumuloClient("root", new PasswordToken("secret"))) {
|
||||
SecurityOperations sops = accumuloClient.securityOperations();
|
||||
Authorizations rootAuths = new Authorizations("A", "B", "C", "D", "E", "F", "G", "H", "I");
|
||||
sops.changeUserAuthorizations("root", rootAuths);
|
||||
} catch (AccumuloException | AccumuloSecurityException e) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.apache.accumulo.core.iterators.IteratorEnvironment;
|
||||
import org.apache.accumulo.core.iterators.OptionDescriber;
|
||||
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
|
||||
import org.apache.accumulo.core.iterators.WrappingIterator;
|
||||
import org.apache.accumulo.core.iterators.system.VisibilityFilter;
|
||||
import org.apache.accumulo.core.iteratorsImpl.system.VisibilityFilter;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
|
||||
@@ -13,17 +13,12 @@ import java.util.stream.Collectors;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.datatype.guava.GuavaModule;
|
||||
import io.jsonwebtoken.*;
|
||||
import org.apache.accumulo.core.client.ClientConfiguration;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.Instance;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.ResourceUtils;
|
||||
import timely.configuration.Accumulo;
|
||||
import timely.configuration.Security;
|
||||
|
||||
/**
|
||||
@@ -37,7 +32,7 @@ public class JWTTokenHandler {
|
||||
private static ObjectMapper objectMapper;
|
||||
private static Collection<String> accumuloAuths = new TreeSet<>();
|
||||
|
||||
public static void init(Security security, Accumulo accumulo) {
|
||||
public static void init(Security security, AccumuloClient accumuloClient) {
|
||||
if (StringUtils.isNotBlank(security.getJwtCheckKeyStore())) {
|
||||
try {
|
||||
String type = security.getJwtCheckKeyType();
|
||||
@@ -61,18 +56,11 @@ public class JWTTokenHandler {
|
||||
}
|
||||
JWTTokenHandler.objectMapper = new ObjectMapper();
|
||||
JWTTokenHandler.objectMapper.registerModule(new GuavaModule());
|
||||
if (accumulo != null) {
|
||||
|
||||
if (accumuloClient != null) {
|
||||
try {
|
||||
final Map<String, String> properties = new HashMap<>();
|
||||
properties.put("instance.name", accumulo.getInstanceName());
|
||||
properties.put("instance.zookeeper.host", accumulo.getZookeepers());
|
||||
properties.put("instance.zookeeper.timeout", accumulo.getZookeeperTimeout());
|
||||
final ClientConfiguration aconf = ClientConfiguration.fromMap(properties);
|
||||
final Instance instance = new ZooKeeperInstance(aconf);
|
||||
Connector connector = instance.getConnector(accumulo.getUsername(),
|
||||
new PasswordToken(accumulo.getPassword()));
|
||||
Authorizations currentAccumuloAuths = connector.securityOperations()
|
||||
.getUserAuthorizations(connector.whoami());
|
||||
Authorizations currentAccumuloAuths = accumuloClient.securityOperations()
|
||||
.getUserAuthorizations(accumuloClient.whoami());
|
||||
currentAccumuloAuths.iterator()
|
||||
.forEachRemaining(a -> accumuloAuths.add(new String(a, Charset.forName("UTF-8"))));
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -9,11 +9,11 @@ import com.google.common.collect.Lists;
|
||||
import org.apache.accumulo.core.client.IteratorSetting;
|
||||
import org.apache.accumulo.core.client.IteratorSetting.Column;
|
||||
import org.apache.accumulo.core.client.ScannerBase;
|
||||
import org.apache.accumulo.core.client.impl.ScannerOptions;
|
||||
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
|
||||
import org.apache.accumulo.core.clientImpl.ScannerOptions;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.data.thrift.IterInfo;
|
||||
import org.apache.accumulo.core.dataImpl.thrift.IterInfo;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.apache.hadoop.io.Text;
|
||||
|
||||
@@ -28,6 +28,7 @@ public class ScannerBaseDelegate implements ScannerBase {
|
||||
private static final String SYSTEM_ITERATOR_NAME_PREFIX = "sys_";
|
||||
|
||||
protected final ScannerBase delegate;
|
||||
protected ConsistencyLevel consistencyLevel = ConsistencyLevel.IMMEDIATE;
|
||||
|
||||
public ScannerBaseDelegate(ScannerBase delegate) {
|
||||
this.delegate = delegate;
|
||||
@@ -221,6 +222,16 @@ public class ScannerBaseDelegate implements ScannerBase {
|
||||
return delegate.getClassLoaderContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConsistencyLevel getConsistencyLevel() {
|
||||
return consistencyLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConsistencyLevel(ConsistencyLevel consistencyLevel) {
|
||||
this.consistencyLevel = consistencyLevel;
|
||||
}
|
||||
|
||||
public void setContext(String context) {
|
||||
delegate.setClassLoaderContext(context);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.BatchDeleter;
|
||||
import org.apache.accumulo.core.client.BatchScanner;
|
||||
import org.apache.accumulo.core.client.BatchWriterConfig;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.IteratorSetting;
|
||||
import org.apache.accumulo.core.client.Scanner;
|
||||
import org.apache.accumulo.core.client.ScannerBase;
|
||||
@@ -23,29 +23,29 @@ public class ScannerHelper {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(ScannerHelper.class);
|
||||
|
||||
public static Scanner createScanner(Connector connector, String tableName,
|
||||
public static Scanner createScanner(AccumuloClient accumuloClient, String tableName,
|
||||
Collection<Authorizations> authorizations) throws TableNotFoundException {
|
||||
if (authorizations == null || authorizations.isEmpty())
|
||||
throw new IllegalArgumentException("Authorizations must not be empty.");
|
||||
|
||||
Iterator<Authorizations> iter = AuthorizationsMinimizer.minimize(authorizations).iterator();
|
||||
Scanner scanner = connector.createScanner(tableName, iter.next());
|
||||
Scanner scanner = accumuloClient.createScanner(tableName, iter.next());
|
||||
addVisibilityFilters(iter, scanner);
|
||||
return scanner;
|
||||
}
|
||||
|
||||
public static BatchScanner createBatchScanner(Connector connector, String tableName,
|
||||
public static BatchScanner createBatchScanner(AccumuloClient accumuloClient, String tableName,
|
||||
Collection<Authorizations> authorizations, int numQueryThreads) throws TableNotFoundException {
|
||||
if (authorizations == null || authorizations.isEmpty())
|
||||
throw new IllegalArgumentException("Authorizations must not be empty.");
|
||||
|
||||
Iterator<Authorizations> iter = AuthorizationsMinimizer.minimize(authorizations).iterator();
|
||||
BatchScanner batchScanner = connector.createBatchScanner(tableName, iter.next(), numQueryThreads);
|
||||
BatchScanner batchScanner = accumuloClient.createBatchScanner(tableName, iter.next(), numQueryThreads);
|
||||
addVisibilityFilters(iter, batchScanner);
|
||||
return batchScanner;
|
||||
}
|
||||
|
||||
public static BatchDeleter createBatchDeleter(Connector connector, String tableName,
|
||||
public static BatchDeleter createBatchDeleter(AccumuloClient accumuloClient, String tableName,
|
||||
Collection<Authorizations> authorizations, int numQueryThreads, long maxMemory, long maxLatency,
|
||||
int maxWriteThreads) throws TableNotFoundException {
|
||||
if (authorizations == null || authorizations.isEmpty())
|
||||
@@ -54,7 +54,7 @@ public class ScannerHelper {
|
||||
Iterator<Authorizations> iter = AuthorizationsMinimizer.minimize(authorizations).iterator();
|
||||
BatchWriterConfig bwCfg = new BatchWriterConfig().setMaxLatency(maxLatency, TimeUnit.MILLISECONDS)
|
||||
.setMaxMemory(maxMemory).setMaxWriteThreads(maxWriteThreads);
|
||||
BatchDeleter batchDeleter = connector.createBatchDeleter(tableName, iter.next(), numQueryThreads, bwCfg);
|
||||
BatchDeleter batchDeleter = accumuloClient.createBatchDeleter(tableName, iter.next(), numQueryThreads, bwCfg);
|
||||
addVisibilityFilters(iter, batchDeleter);
|
||||
return batchDeleter;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package timely.configuration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
@@ -18,7 +19,7 @@ public class Configuration {
|
||||
|
||||
private String metricsTable = "timely.metrics";
|
||||
private String metaTable = "timely.meta";
|
||||
private HashMap<String, Integer> metricAgeOffDays = new HashMap<>();
|
||||
private Map<String, Integer> metricAgeOffDays = new HashMap<>();
|
||||
private List<String> metricsReportIgnoredTags = new ArrayList<>();
|
||||
private String instance = null;
|
||||
private String defaultVisibility = null;
|
||||
@@ -82,11 +83,11 @@ public class Configuration {
|
||||
this.defaultVisibility = defaultVisibility;
|
||||
}
|
||||
|
||||
public HashMap<String, Integer> getMetricAgeOffDays() {
|
||||
public Map<String, Integer> getMetricAgeOffDays() {
|
||||
return metricAgeOffDays;
|
||||
}
|
||||
|
||||
public void setMetricAgeOffDays(HashMap<String, Integer> metricAgeOffDays) {
|
||||
public void setMetricAgeOffDays(Map<String, Integer> metricAgeOffDays) {
|
||||
this.metricAgeOffDays = metricAgeOffDays;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TcpDecoder extends ByteToMessageDecoder {
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
|
||||
ByteBuf buf = in.readBytes(in.readableBytes());
|
||||
String input = "";
|
||||
String input = null;
|
||||
try {
|
||||
if (buf == Unpooled.EMPTY_BUFFER) {
|
||||
return;
|
||||
|
||||
@@ -22,11 +22,11 @@ public class UdpDecoder extends ByteToMessageDecoder {
|
||||
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
|
||||
|
||||
ByteBuf buf = in.readBytes(in.readableBytes());
|
||||
String input = null;
|
||||
try {
|
||||
if (buf == Unpooled.EMPTY_BUFFER) {
|
||||
return;
|
||||
}
|
||||
final String input;
|
||||
if (buf.hasArray()) {
|
||||
input = new String(buf.array(), UTF_8);
|
||||
} else {
|
||||
@@ -58,6 +58,8 @@ public class UdpDecoder extends ByteToMessageDecoder {
|
||||
tcp.parse(input);
|
||||
out.add(tcp);
|
||||
LOG.trace("Converted {} to {}", input, tcp);
|
||||
} catch (Exception e) {
|
||||
LOG.error("{} parsing line:[{}]", e.getMessage(), input);
|
||||
} finally {
|
||||
buf.release();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package timely.sample.iterators;
|
||||
|
||||
import static org.apache.accumulo.core.conf.AccumuloConfiguration.getTimeInMillis;
|
||||
import static org.apache.accumulo.core.conf.ConfigurationTypeHelper.getTimeInMillis;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -80,7 +80,7 @@ public class DownsampleIterator extends WrappingIterator {
|
||||
@Override
|
||||
public boolean hasTop() {
|
||||
|
||||
if (super.hasTop()) {
|
||||
if (last == null && super.hasTop()) {
|
||||
while (super.hasTop()) {
|
||||
Key topKey = super.getTopKey();
|
||||
Value topValue = super.getTopValue();
|
||||
@@ -89,12 +89,12 @@ public class DownsampleIterator extends WrappingIterator {
|
||||
long timestamp = metric.getValue().getTimestamp();
|
||||
if (memoryEstimator.shouldReturnBasedOnMemoryUsage(timestamp, value)) {
|
||||
LOG.trace("returning current values - memory usage > " + memoryEstimator.maxDownsampleMemory
|
||||
+ " for metric=" + metric.toString());
|
||||
+ " for metric=" + metric);
|
||||
break;
|
||||
}
|
||||
last = topKey;
|
||||
|
||||
Set<Tag> tags = new HashSet<Tag>(metric.getTags());
|
||||
Set<Tag> tags = new HashSet<>(metric.getTags());
|
||||
Downsample sample = value.get(tags);
|
||||
if (sample == null) {
|
||||
try {
|
||||
@@ -113,10 +113,8 @@ public class DownsampleIterator extends WrappingIterator {
|
||||
throw new RuntimeException("Downstream next() failed", e);
|
||||
}
|
||||
}
|
||||
return last != null;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return last != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package timely.store;
|
||||
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import timely.api.response.TimelyException;
|
||||
import timely.configuration.Configuration;
|
||||
|
||||
public class DataStoreFactory {
|
||||
|
||||
public static DataStore create(Configuration conf, int numWriteThreads) throws TimelyException {
|
||||
public static DataStore create(Configuration conf, AccumuloClient accumuloClient, int numWriteThreads)
|
||||
throws TimelyException {
|
||||
|
||||
return new DataStoreImpl(conf, numWriteThreads);
|
||||
return new DataStoreImpl(conf, accumuloClient, numWriteThreads);
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
package timely.store;
|
||||
|
||||
import static org.apache.accumulo.core.conf.AccumuloConfiguration.getMemoryInBytes;
|
||||
import static org.apache.accumulo.core.conf.AccumuloConfiguration.getTimeInMillis;
|
||||
import static org.apache.accumulo.core.conf.ConfigurationTypeHelper.getMemoryAsBytes;
|
||||
import static org.apache.accumulo.core.conf.ConfigurationTypeHelper.getTimeInMillis;
|
||||
import static timely.adapter.accumulo.MetricAdapter.VISIBILITY_TAG;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -33,12 +33,10 @@ import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.netty.handler.codec.http.HttpResponseStatus;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.BatchScanner;
|
||||
import org.apache.accumulo.core.client.BatchWriter;
|
||||
import org.apache.accumulo.core.client.BatchWriterConfig;
|
||||
import org.apache.accumulo.core.client.ClientConfiguration;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.Instance;
|
||||
import org.apache.accumulo.core.client.IteratorSetting;
|
||||
import org.apache.accumulo.core.client.MutationsRejectedException;
|
||||
import org.apache.accumulo.core.client.NamespaceExistsException;
|
||||
@@ -46,8 +44,6 @@ import org.apache.accumulo.core.client.Scanner;
|
||||
import org.apache.accumulo.core.client.ScannerBase;
|
||||
import org.apache.accumulo.core.client.TableExistsException;
|
||||
import org.apache.accumulo.core.client.TableNotFoundException;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
import org.apache.accumulo.core.data.PartialKey;
|
||||
@@ -120,14 +116,14 @@ public class DataStoreImpl implements DataStore {
|
||||
|
||||
}
|
||||
|
||||
private final Connector connector;
|
||||
private MetaCache metaCache = null;
|
||||
private final AccumuloClient accumuloClient;
|
||||
private final MetaCache metaCache;
|
||||
private final AtomicLong lastCountTime = new AtomicLong(System.currentTimeMillis());
|
||||
private final AtomicReference<SortedMap<MetricTagK, Integer>> metaCounts = new AtomicReference<>(new TreeMap<>());
|
||||
private final String metricsTable;
|
||||
private final String metaTable;
|
||||
private final InternalMetrics internalMetrics;
|
||||
private ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
|
||||
private final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1);
|
||||
private final int scannerThreads;
|
||||
private final long maxDownsampleMemory;
|
||||
private final BatchWriterConfig bwConfig;
|
||||
@@ -140,21 +136,15 @@ public class DataStoreImpl implements DataStore {
|
||||
private DataStoreCache cache = null;
|
||||
private final String defaultVisibility;
|
||||
|
||||
public DataStoreImpl(Configuration conf, int numWriteThreads) throws TimelyException {
|
||||
public DataStoreImpl(Configuration conf, AccumuloClient accumuloClient, int numWriteThreads)
|
||||
throws TimelyException {
|
||||
|
||||
try {
|
||||
final Map<String, String> properties = new HashMap<>();
|
||||
this.accumuloClient = accumuloClient;
|
||||
Accumulo accumuloConf = conf.getAccumulo();
|
||||
properties.put("instance.name", accumuloConf.getInstanceName());
|
||||
properties.put("instance.zookeeper.host", accumuloConf.getZookeepers());
|
||||
properties.put("instance.zookeeper.timeout", accumuloConf.getZookeeperTimeout());
|
||||
final ClientConfiguration aconf = ClientConfiguration.fromMap(properties);
|
||||
final Instance instance = new ZooKeeperInstance(aconf);
|
||||
connector = instance.getConnector(accumuloConf.getUsername(),
|
||||
new PasswordToken(accumuloConf.getPassword()));
|
||||
bwConfig = new BatchWriterConfig();
|
||||
bwConfig.setMaxLatency(getTimeInMillis(accumuloConf.getWrite().getLatency()), TimeUnit.MILLISECONDS);
|
||||
bwConfig.setMaxMemory(getMemoryInBytes(accumuloConf.getWrite().getBufferSize()) / numWriteThreads);
|
||||
bwConfig.setMaxMemory(getMemoryAsBytes(accumuloConf.getWrite().getBufferSize()) / numWriteThreads);
|
||||
bwConfig.setMaxWriteThreads(accumuloConf.getWrite().getThreads());
|
||||
scannerThreads = accumuloConf.getScan().getThreads();
|
||||
maxDownsampleMemory = accumuloConf.getScan().getMaxDownsampleMemory();
|
||||
@@ -165,19 +155,19 @@ public class DataStoreImpl implements DataStore {
|
||||
try {
|
||||
// validate visibility
|
||||
vis = new ColumnVisibility(defaultVisibility);
|
||||
LOG.info("Using defaultVisibility: {}", vis.toString());
|
||||
LOG.info("Using defaultVisibility: {}", vis);
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error("Error validating defaultVisibility " + defaultVisibility + " " + e.getMessage(), e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
try {
|
||||
String whoami = connector.whoami();
|
||||
Authorizations auths = connector.securityOperations().getUserAuthorizations(whoami);
|
||||
String whoami = accumuloClient.whoami();
|
||||
Authorizations auths = accumuloClient.securityOperations().getUserAuthorizations(whoami);
|
||||
VisibilityEvaluator eval = new VisibilityEvaluator(auths);
|
||||
if (!eval.evaluate(vis)) {
|
||||
throw new IllegalArgumentException("Accumulo user " + whoami + " with authorization "
|
||||
+ auths.toString() + " can not see data with defaultVisibility " + vis.toString());
|
||||
throw new IllegalArgumentException("Accumulo user " + whoami + " with authorization " + auths
|
||||
+ " can not see data with defaultVisibility " + vis);
|
||||
}
|
||||
} catch (RuntimeException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
@@ -189,10 +179,10 @@ public class DataStoreImpl implements DataStore {
|
||||
if (metricsTable.contains(".")) {
|
||||
final String[] parts = metricsTable.split("\\.", 2);
|
||||
final String namespace = parts[0];
|
||||
if (!connector.namespaceOperations().exists(namespace)) {
|
||||
if (!accumuloClient.namespaceOperations().exists(namespace)) {
|
||||
try {
|
||||
LOG.info("Creating namespace " + namespace);
|
||||
connector.namespaceOperations().create(namespace);
|
||||
accumuloClient.namespaceOperations().create(namespace);
|
||||
} catch (final NamespaceExistsException ex) {
|
||||
// don't care
|
||||
}
|
||||
@@ -201,11 +191,11 @@ public class DataStoreImpl implements DataStore {
|
||||
ageOffSettings = getAgeOff(conf);
|
||||
defaultAgeOffMilliSec = this.getAgeOffForMetric(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY);
|
||||
|
||||
final Map<String, String> tableIdMap = connector.tableOperations().tableIdMap();
|
||||
final Map<String, String> tableIdMap = accumuloClient.tableOperations().tableIdMap();
|
||||
if (!tableIdMap.containsKey(metricsTable)) {
|
||||
try {
|
||||
LOG.info("Creating table " + metricsTable);
|
||||
connector.tableOperations().create(metricsTable);
|
||||
accumuloClient.tableOperations().create(metricsTable);
|
||||
} catch (final TableExistsException ex) {
|
||||
// don't care
|
||||
}
|
||||
@@ -215,7 +205,7 @@ public class DataStoreImpl implements DataStore {
|
||||
if (!tableIdMap.containsKey(metaTable)) {
|
||||
try {
|
||||
LOG.info("Creating table " + metaTable);
|
||||
connector.tableOperations().create(metaTable);
|
||||
accumuloClient.tableOperations().create(metaTable);
|
||||
} catch (final TableExistsException ex) {
|
||||
// don't care
|
||||
}
|
||||
@@ -237,36 +227,28 @@ public class DataStoreImpl implements DataStore {
|
||||
public void applyAgeOffSettings() {
|
||||
|
||||
// remove iterator and related settings (ageoffs) to ensure current values used
|
||||
if (iteratorOperation((c, t) -> {
|
||||
this.removeAgeOffIterators(c, t);
|
||||
}, connector, metricsTable, 5)) {
|
||||
if (iteratorOperation(this::removeAgeOffIterators, accumuloClient, metricsTable, 5)) {
|
||||
LOG.info("Remove ageoff for " + metricsTable + " completed");
|
||||
} else {
|
||||
LOG.error("Remove ageoff for " + metricsTable + " failed");
|
||||
}
|
||||
|
||||
// add iterator and related settings (ageoffs) to ensure current values used
|
||||
if (iteratorOperation((c, t) -> {
|
||||
this.applyMetricAgeOffIterator(c, t);
|
||||
}, connector, metricsTable, 5)) {
|
||||
if (iteratorOperation(this::applyMetricAgeOffIterator, accumuloClient, metricsTable, 5)) {
|
||||
LOG.info("Apply ageoff for " + metricsTable + " completed");
|
||||
} else {
|
||||
LOG.error("Apply ageoff for " + metricsTable + " failed");
|
||||
}
|
||||
|
||||
// remove iterator and related settings (ageoffs) to ensure current values used
|
||||
if (iteratorOperation((c, t) -> {
|
||||
this.removeAgeOffIterators(c, t);
|
||||
}, connector, metaTable, 5)) {
|
||||
if (iteratorOperation(this::removeAgeOffIterators, accumuloClient, metaTable, 5)) {
|
||||
LOG.info("Remove ageoff for " + metaTable + " completed");
|
||||
} else {
|
||||
LOG.error("Remove ageoff for " + metaTable + " failed");
|
||||
}
|
||||
|
||||
// add iterator and related settings (ageoffs) to ensure current values used
|
||||
if (iteratorOperation((c, t) -> {
|
||||
this.applyMetaAgeOffIterator(c, t);
|
||||
}, connector, metaTable, 5)) {
|
||||
if (iteratorOperation(this::applyMetaAgeOffIterator, accumuloClient, metaTable, 5)) {
|
||||
LOG.info("Apply ageoff for " + metaTable + " completed");
|
||||
} else {
|
||||
LOG.error("Apply ageoff for " + metaTable + " failed");
|
||||
@@ -292,15 +274,16 @@ public class DataStoreImpl implements DataStore {
|
||||
|
||||
public interface RetryableIteratorOperation {
|
||||
|
||||
void execute(Connector con, String tableName) throws Exception;
|
||||
void execute(AccumuloClient accumuloClient, String tableName) throws Exception;
|
||||
}
|
||||
|
||||
private boolean iteratorOperation(RetryableIteratorOperation op, Connector connector, String table, int retries) {
|
||||
private boolean iteratorOperation(RetryableIteratorOperation op, AccumuloClient accumuloClient, String table,
|
||||
int retries) {
|
||||
boolean success = false;
|
||||
int attempt = 1;
|
||||
while (!success && attempt++ <= retries) {
|
||||
try {
|
||||
op.execute(connector, table);
|
||||
op.execute(accumuloClient, table);
|
||||
success = true;
|
||||
} catch (Exception e) {
|
||||
Throwable cause = e.getCause();
|
||||
@@ -319,25 +302,25 @@ public class DataStoreImpl implements DataStore {
|
||||
return success;
|
||||
}
|
||||
|
||||
private void removeAgeOffIterators(Connector connector, String tableName) throws Exception {
|
||||
Map<String, EnumSet<IteratorScope>> iters = connector.tableOperations().listIterators(tableName);
|
||||
private void removeAgeOffIterators(AccumuloClient accumuloClient, String tableName) throws Exception {
|
||||
Map<String, EnumSet<IteratorScope>> iters = accumuloClient.tableOperations().listIterators(tableName);
|
||||
for (String name : iters.keySet()) {
|
||||
if (name.startsWith("ageoff")) {
|
||||
connector.tableOperations().removeIterator(tableName, name, AGEOFF_SCOPES);
|
||||
accumuloClient.tableOperations().removeIterator(tableName, name, AGEOFF_SCOPES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void applyMetricAgeOffIterator(Connector connector, String tableName) throws Exception {
|
||||
private void applyMetricAgeOffIterator(AccumuloClient accumuloClient, String tableName) throws Exception {
|
||||
IteratorSetting ageOffIteratorSettings = new IteratorSetting(100, "ageoffmetrics", MetricAgeOffIterator.class,
|
||||
this.ageOffSettings);
|
||||
connector.tableOperations().attachIterator(tableName, ageOffIteratorSettings, AGEOFF_SCOPES);
|
||||
accumuloClient.tableOperations().attachIterator(tableName, ageOffIteratorSettings, AGEOFF_SCOPES);
|
||||
}
|
||||
|
||||
private void applyMetaAgeOffIterator(Connector connector, String tableName) throws Exception {
|
||||
private void applyMetaAgeOffIterator(AccumuloClient accumuloClient, String tableName) throws Exception {
|
||||
IteratorSetting ageOffIteratorSettings = new IteratorSetting(100, "ageoffmeta", MetaAgeOffIterator.class,
|
||||
this.ageOffSettings);
|
||||
connector.tableOperations().attachIterator(tableName, ageOffIteratorSettings, AGEOFF_SCOPES);
|
||||
accumuloClient.tableOperations().attachIterator(tableName, ageOffIteratorSettings, AGEOFF_SCOPES);
|
||||
}
|
||||
|
||||
private Map<String, String> getAgeOff(Configuration conf) {
|
||||
@@ -375,7 +358,7 @@ public class DataStoreImpl implements DataStore {
|
||||
|
||||
if (null == metaWriter.get()) {
|
||||
try {
|
||||
BatchWriter w = connector.createBatchWriter(metaTable, bwConfig);
|
||||
BatchWriter w = accumuloClient.createBatchWriter(metaTable, bwConfig);
|
||||
metaWriter.set(w);
|
||||
writers.add(w);
|
||||
} catch (TableNotFoundException e) {
|
||||
@@ -385,7 +368,7 @@ public class DataStoreImpl implements DataStore {
|
||||
}
|
||||
if (null == batchWriter.get()) {
|
||||
try {
|
||||
BatchWriter w = connector.createBatchWriter(metricsTable, bwConfig);
|
||||
BatchWriter w = accumuloClient.createBatchWriter(metricsTable, bwConfig);
|
||||
batchWriter.set(w);
|
||||
writers.add(w);
|
||||
} catch (TableNotFoundException e) {
|
||||
@@ -400,18 +383,14 @@ public class DataStoreImpl implements DataStore {
|
||||
toCache.add(new Meta(metric.getName(), tag.getKey(), tag.getValue()));
|
||||
}
|
||||
if (!toCache.isEmpty()) {
|
||||
final Set<Mutation> muts = new TreeSet<>(new Comparator<Mutation>() {
|
||||
|
||||
@Override
|
||||
public int compare(Mutation o1, Mutation o2) {
|
||||
if (o1.equals(o2)) {
|
||||
return 0;
|
||||
final Set<Mutation> muts = new TreeSet<>((o1, o2) -> {
|
||||
if (o1.equals(o2)) {
|
||||
return 0;
|
||||
} else {
|
||||
if (o1.hashCode() < o2.hashCode()) {
|
||||
return -1;
|
||||
} else {
|
||||
if (o1.hashCode() < o2.hashCode()) {
|
||||
return -1;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -432,7 +411,7 @@ public class DataStoreImpl implements DataStore {
|
||||
} catch (MutationsRejectedException e1) {
|
||||
LOG.error("Error closing meta writer", e1);
|
||||
}
|
||||
final BatchWriter w = connector.createBatchWriter(metaTable, bwConfig);
|
||||
final BatchWriter w = accumuloClient.createBatchWriter(metaTable, bwConfig);
|
||||
metaWriter.set(w);
|
||||
writers.add(w);
|
||||
} catch (TableNotFoundException e1) {
|
||||
@@ -455,7 +434,7 @@ public class DataStoreImpl implements DataStore {
|
||||
} catch (MutationsRejectedException e1) {
|
||||
LOG.error("Error closing metric writer", e1);
|
||||
}
|
||||
final BatchWriter w = connector.createBatchWriter(metricsTable, bwConfig);
|
||||
final BatchWriter w = accumuloClient.createBatchWriter(metricsTable, bwConfig);
|
||||
batchWriter.set(w);
|
||||
writers.add(w);
|
||||
} catch (TableNotFoundException e1) {
|
||||
@@ -485,48 +464,53 @@ public class DataStoreImpl implements DataStore {
|
||||
SuggestResponse result = new SuggestResponse();
|
||||
try {
|
||||
Optional<String> metricOpt = request.getMetric();
|
||||
if (request.getType().equals("metrics")) {
|
||||
Set<String> metrics = new TreeSet<>();
|
||||
String query = metricOpt.isPresent() ? metricOpt.get() : null;
|
||||
for (Meta m : metaCache) {
|
||||
if (query == null || m.getMetric().contains(query)) {
|
||||
metrics.add(m.getMetric());
|
||||
if (request.getMax() >= 0 && metrics.size() >= request.getMax()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
result.setSuggestions(new ArrayList<>(metrics));
|
||||
} else if (request.getType().equals("tagk")) {
|
||||
Set<String> tagKeys = new TreeSet<>();
|
||||
if (metricOpt.isPresent()) {
|
||||
String metric = metricOpt.get();
|
||||
switch (request.getType()) {
|
||||
case "metrics":
|
||||
Set<String> metrics = new TreeSet<>();
|
||||
String query = metricOpt.orElse(null);
|
||||
for (Meta m : metaCache) {
|
||||
if (m.getMetric().equals(metric)) {
|
||||
tagKeys.add(m.getTagKey());
|
||||
if (request.getMax() >= 0 && tagKeys.size() >= request.getMax()) {
|
||||
if (query == null || m.getMetric().contains(query)) {
|
||||
metrics.add(m.getMetric());
|
||||
if (request.getMax() >= 0 && metrics.size() >= request.getMax()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.setSuggestions(new ArrayList<>(tagKeys));
|
||||
} else if (request.getType().equals("tagv")) {
|
||||
Set<String> tagValues = new TreeSet<>();
|
||||
Optional<String> tagKeyOpt = request.getTag();
|
||||
if (metricOpt.isPresent() && tagKeyOpt.isPresent()) {
|
||||
String metric = metricOpt.get();
|
||||
String tagKey = tagKeyOpt.get();
|
||||
for (Meta m : metaCache) {
|
||||
if (m.getMetric().equals(metric) && m.getTagKey().equals(tagKey)) {
|
||||
tagValues.add(m.getTagValue());
|
||||
if (request.getMax() >= 0 && tagValues.size() >= request.getMax()) {
|
||||
break;
|
||||
result.setSuggestions(new ArrayList<>(metrics));
|
||||
break;
|
||||
case "tagk":
|
||||
Set<String> tagKeys = new TreeSet<>();
|
||||
if (metricOpt.isPresent()) {
|
||||
String metric = metricOpt.get();
|
||||
for (Meta m : metaCache) {
|
||||
if (m.getMetric().equals(metric)) {
|
||||
tagKeys.add(m.getTagKey());
|
||||
if (request.getMax() >= 0 && tagKeys.size() >= request.getMax()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.setSuggestions(new ArrayList<>(tagValues));
|
||||
result.setSuggestions(new ArrayList<>(tagKeys));
|
||||
break;
|
||||
case "tagv":
|
||||
Set<String> tagValues = new TreeSet<>();
|
||||
Optional<String> tagKeyOpt = request.getTag();
|
||||
if (metricOpt.isPresent() && tagKeyOpt.isPresent()) {
|
||||
String metric = metricOpt.get();
|
||||
String tagKey = tagKeyOpt.get();
|
||||
for (Meta m : metaCache) {
|
||||
if (m.getMetric().equals(metric) && m.getTagKey().equals(tagKey)) {
|
||||
tagValues.add(m.getTagValue());
|
||||
if (request.getMax() >= 0 && tagValues.size() >= request.getMax()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result.setSuggestions(new ArrayList<>(tagValues));
|
||||
break;
|
||||
default:
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Error during suggest: " + ex.getMessage(), ex);
|
||||
@@ -549,12 +533,9 @@ public class DataStoreImpl implements DataStore {
|
||||
result.setTags(tags);
|
||||
result.setLimit(msg.getLimit());
|
||||
Map<String, Pattern> tagPatterns = new HashMap<>();
|
||||
tags.forEach((k, v) -> {
|
||||
tagPatterns.put(k, Pattern.compile(v));
|
||||
});
|
||||
tags.forEach((k, v) -> tagPatterns.put(k, Pattern.compile(v)));
|
||||
try {
|
||||
final Scanner scanner = connector.createScanner(metaTable, Authorizations.EMPTY);
|
||||
try {
|
||||
try (Scanner scanner = accumuloClient.createScanner(metaTable, Authorizations.EMPTY)) {
|
||||
List<Result> resultField = new ArrayList<>();
|
||||
Key start = new Key(Meta.VALUE_PREFIX + msg.getQuery());
|
||||
Key end = start.followingKey(PartialKey.ROW);
|
||||
@@ -576,10 +557,6 @@ public class DataStoreImpl implements DataStore {
|
||||
result.setResults(resultField);
|
||||
result.setTotalResults(total);
|
||||
result.setTime((int) (System.currentTimeMillis() - startMillis));
|
||||
} finally {
|
||||
if (scanner != null) {
|
||||
scanner.close();
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
LOG.error("Error during lookup: " + ex.getMessage(), ex);
|
||||
@@ -629,12 +606,9 @@ public class DataStoreImpl implements DataStore {
|
||||
z += c.size();
|
||||
}
|
||||
long totalRequestedTime = requestedEndTs - requestedStartTs;
|
||||
long percentServedFromCache = 0;
|
||||
long percentServedFromCache;
|
||||
if (!cachedMetrics.isEmpty() && oldestCacheTimestamp != Long.MAX_VALUE) {
|
||||
if (requestedStartTs < oldestCacheTimestamp && requestedEndTs < oldestCacheTimestamp) {
|
||||
percentServedFromCache = 0;
|
||||
} else if (requestedStartTs >= oldestCacheTimestamp
|
||||
&& requestedEndTs >= oldestCacheTimestamp) {
|
||||
if (requestedStartTs >= oldestCacheTimestamp) {
|
||||
percentServedFromCache = 100;
|
||||
} else {
|
||||
long timeAnsweredFromCache = requestedEndTs - oldestCacheTimestamp;
|
||||
@@ -647,7 +621,7 @@ public class DataStoreImpl implements DataStore {
|
||||
LOG.debug(
|
||||
"Cache query for [{}] time:{} duration (min):{} metrics:{} results:{} percentFromCache:{}",
|
||||
msg.getUserName(), (System.currentTimeMillis() - now),
|
||||
((requestedEndTs - requestedStartTs) / (1000 * 60)), metricList.toString(), z,
|
||||
((requestedEndTs - requestedStartTs) / (1000 * 60)), metricList, z,
|
||||
percentServedFromCache);
|
||||
allSeries.putAll(cachedMetrics);
|
||||
}
|
||||
@@ -678,7 +652,7 @@ public class DataStoreImpl implements DataStore {
|
||||
BatchScanner scanner = null;
|
||||
try {
|
||||
Collection<Authorizations> authorizations = getSessionAuthorizations(msg);
|
||||
scanner = ScannerHelper.createBatchScanner(connector, metricsTable, authorizations,
|
||||
scanner = ScannerHelper.createBatchScanner(accumuloClient, metricsTable, authorizations,
|
||||
scannerThreads);
|
||||
List<String> tagOrder = prioritizeTags(query.getMetric(), query.getTags());
|
||||
Map<String, String> orderedTags = orderTags(tagOrder, query.getTags());
|
||||
@@ -686,7 +660,7 @@ public class DataStoreImpl implements DataStore {
|
||||
List<Range> ranges = getQueryRanges(metric, startOfFirstPeriod, endOfLastPeriod,
|
||||
colFamValues);
|
||||
scanner.setRanges(ranges);
|
||||
setQueryColumns(scanner, metric, orderedTags, colFamValues);
|
||||
setQueryColumns(scanner, orderedTags, colFamValues);
|
||||
|
||||
if (query.isRate()) {
|
||||
LOG.trace("Adding rate iterator");
|
||||
@@ -730,7 +704,7 @@ public class DataStoreImpl implements DataStore {
|
||||
for (Entry<Set<Tag>, Aggregation> entry : samples.entrySet()) {
|
||||
Set<Tag> key = new HashSet<>();
|
||||
for (Tag tag : entry.getKey()) {
|
||||
if (query.getTags().keySet().contains(tag.getKey())) {
|
||||
if (query.getTags().containsKey(tag.getKey())) {
|
||||
key.add(tag);
|
||||
}
|
||||
}
|
||||
@@ -756,8 +730,8 @@ public class DataStoreImpl implements DataStore {
|
||||
}
|
||||
}
|
||||
LOG.debug("Query for [{}] time:{} duration:{} metrics:{} results:{}", msg.getUserName(),
|
||||
(System.currentTimeMillis() - now), ((requestedEndTs - requestedStartTs) / (1000 * 60)),
|
||||
metricList.toString(), numResults);
|
||||
(System.currentTimeMillis() - now), ((requestedEndTs - requestedStartTs) / (1000 * 60)), metricList,
|
||||
numResults);
|
||||
internalMetrics.addQueryResponse(result.size(), (System.currentTimeMillis() - now));
|
||||
return result;
|
||||
} catch (ClassNotFoundException | IOException | TableNotFoundException ex) {
|
||||
@@ -771,9 +745,9 @@ public class DataStoreImpl implements DataStore {
|
||||
Map<String, String> order = new LinkedHashMap<>(tags.size());
|
||||
tagOrder.forEach(t -> order.put(t, tags.get(t)));
|
||||
if (tagOrder.size() > tags.size()) {
|
||||
tags.entrySet().forEach(k -> {
|
||||
if (!tagOrder.contains(k.getKey())) {
|
||||
order.put(k.getKey(), k.getValue());
|
||||
tags.forEach((key, value) -> {
|
||||
if (!tagOrder.contains(key)) {
|
||||
order.put(key, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -816,14 +790,7 @@ public class DataStoreImpl implements DataStore {
|
||||
}
|
||||
}
|
||||
List<String> result = new ArrayList<>(tags.keySet());
|
||||
Collections.sort(result, new Comparator<String>() {
|
||||
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
// greater count lowers priority
|
||||
return priority.get(o1).intValue() - priority.get(o2).intValue();
|
||||
}
|
||||
});
|
||||
result.sort(Comparator.comparingInt(priority::get));
|
||||
LOG.trace("Tag priority {}", result);
|
||||
return result;
|
||||
}
|
||||
@@ -856,7 +823,7 @@ public class DataStoreImpl implements DataStore {
|
||||
try {
|
||||
Map<String, String> tags = (requestedTags == null) ? new LinkedHashMap<>() : requestedTags;
|
||||
LOG.trace("Looking for requested tags: {}", tags);
|
||||
meta = connector.createScanner(metaTable, Authorizations.EMPTY);
|
||||
meta = accumuloClient.createScanner(metaTable, Authorizations.EMPTY);
|
||||
Text start = new Text(Meta.VALUE_PREFIX + metric);
|
||||
Text end = new Text(Meta.VALUE_PREFIX + metric + "\\x0000");
|
||||
end.append(new byte[] { (byte) 0xff }, 0, 1);
|
||||
@@ -899,10 +866,7 @@ public class DataStoreImpl implements DataStore {
|
||||
tagValue = metaEntry.getKey().getColumnQualifier();
|
||||
LOG.trace("Found tag entry {}={}", tagName, tagValue);
|
||||
|
||||
if (ONLY_RETURN_FIRST_TAG && !tagName.equals(firstTag)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return !ONLY_RETURN_FIRST_TAG || tagName.equals(firstTag);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -925,7 +889,7 @@ public class DataStoreImpl implements DataStore {
|
||||
}
|
||||
}
|
||||
|
||||
private void setQueryColumns(ScannerBase scanner, String metric, Map<String, String> tags, Set<Tag> colFamValues)
|
||||
private void setQueryColumns(ScannerBase scanner, Map<String, String> tags, Set<Tag> colFamValues)
|
||||
throws TimelyException {
|
||||
|
||||
if (colFamValues.size() == 0) {
|
||||
@@ -945,7 +909,7 @@ public class DataStoreImpl implements DataStore {
|
||||
if (tagIter.hasNext()) {
|
||||
tagIter.next();
|
||||
}
|
||||
Entry<String, String> tag = null;
|
||||
Entry<String, String> tag;
|
||||
while (tagIter.hasNext()) {
|
||||
tag = tagIter.next();
|
||||
LOG.trace("Adding regex filter for tag {}", tag);
|
||||
@@ -1022,14 +986,13 @@ public class DataStoreImpl implements DataStore {
|
||||
: beginRangeRounded;
|
||||
for (Tag t : colFamValues) {
|
||||
final byte[] start_row = MetricAdapter.encodeRowKey(metric, beginRangeRounded);
|
||||
Key startKey = new Key(new Text(start_row),
|
||||
new Text(t.join().getBytes(Charset.forName("UTF-8"))),
|
||||
Key startKey = new Key(new Text(start_row), new Text(t.join().getBytes(StandardCharsets.UTF_8)),
|
||||
new Text(MetricAdapter.encodeColQual(beginRangeTimestamp, "")), new Text(new byte[0]),
|
||||
beginRangeTimestamp);
|
||||
LOG.trace("Start key for metric {} and time {} is {}", metric, beginRangeTimestamp,
|
||||
startKey.toStringNoTime());
|
||||
final byte[] end_row = MetricAdapter.encodeRowKey(metric, beginRangeRounded);
|
||||
Key endKey = new Key(new Text(end_row), new Text(t.join().getBytes(Charset.forName("UTF-8"))),
|
||||
Key endKey = new Key(new Text(end_row), new Text(t.join().getBytes(StandardCharsets.UTF_8)),
|
||||
new Text(MetricAdapter.encodeColQual(endRangeTimestamp, "")), new Text(new byte[0]),
|
||||
endRangeTimestamp);
|
||||
LOG.trace("End key for metric {} and time {} is {}", metric, beginRangeTimestamp,
|
||||
@@ -1075,14 +1038,14 @@ public class DataStoreImpl implements DataStore {
|
||||
}
|
||||
Collection<Authorizations> auths = getSessionAuthorizations(request);
|
||||
LOG.debug("Creating metric scanner for [{}] with auths: {}", request.getUserName(), auths);
|
||||
Scanner s = ScannerHelper.createScanner(connector, this.metricsTable, auths);
|
||||
Scanner s = ScannerHelper.createScanner(accumuloClient, this.metricsTable, auths);
|
||||
if (tags == null) {
|
||||
tags = new LinkedHashMap<>();
|
||||
}
|
||||
List<String> tagOrder = prioritizeTags(metric, tags);
|
||||
Map<String, String> orderedTags = orderTags(tagOrder, tags);
|
||||
Set<Tag> colFamValues = getColumnFamilies(metric, orderedTags);
|
||||
setQueryColumns(s, metric, orderedTags, colFamValues);
|
||||
setQueryColumns(s, orderedTags, colFamValues);
|
||||
s.setBatchSize(scannerBatchSize);
|
||||
s.setReadaheadThreshold(scannerReadAhead);
|
||||
return s;
|
||||
@@ -1112,5 +1075,8 @@ public class DataStoreImpl implements DataStore {
|
||||
LOG.warn("Error shutting down batchwriter: ", ex.getMessage());
|
||||
}
|
||||
});
|
||||
if (accumuloClient != null) {
|
||||
accumuloClient.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.concurrent.Executors;
|
||||
@@ -12,15 +13,9 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.github.benmanes.caffeine.cache.Cache;
|
||||
import com.github.benmanes.caffeine.cache.Caffeine;
|
||||
import org.apache.accumulo.core.client.AccumuloException;
|
||||
import org.apache.accumulo.core.client.AccumuloSecurityException;
|
||||
import org.apache.accumulo.core.client.ClientConfiguration;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.Instance;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.Scanner;
|
||||
import org.apache.accumulo.core.client.TableNotFoundException;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.conf.ClientProperty;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
@@ -53,20 +48,22 @@ public class MetaCacheImpl implements MetaCache {
|
||||
|
||||
private void refreshCache(long expirationMinutes) {
|
||||
long oldestTimestamp = System.currentTimeMillis() - (expirationMinutes * 60 * 1000);
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
Accumulo accumuloConf = configuration.getAccumulo();
|
||||
properties.put("instance.name", accumuloConf.getInstanceName());
|
||||
properties.put("instance.zookeeper.host", accumuloConf.getZookeepers());
|
||||
final ClientConfiguration aConf = ClientConfiguration.fromMap(properties);
|
||||
String metaTable = configuration.getMetaTable();
|
||||
Map<String, Map<String, Long>> metricMap = new HashMap<>();
|
||||
Scanner scanner = null;
|
||||
try {
|
||||
Map<Meta, Object> newCache = new HashMap<>();
|
||||
final Instance instance = new ZooKeeperInstance(aConf);
|
||||
Connector connector = instance.getConnector(accumuloConf.getUsername(),
|
||||
new PasswordToken(accumuloConf.getPassword()));
|
||||
scanner = connector.createScanner(metaTable, Authorizations.EMPTY);
|
||||
final Properties properties = new Properties();
|
||||
Accumulo accumuloConf = configuration.getAccumulo();
|
||||
properties.put(ClientProperty.INSTANCE_NAME.getKey(), accumuloConf.getInstanceName());
|
||||
properties.put(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), accumuloConf.getZookeepers());
|
||||
properties.put(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getKey(), accumuloConf.getZookeeperTimeout());
|
||||
properties.put(ClientProperty.AUTH_PRINCIPAL.getKey(), accumuloConf.getUsername());
|
||||
properties.put(ClientProperty.AUTH_TOKEN.getKey(), accumuloConf.getPassword());
|
||||
properties.put(ClientProperty.AUTH_TYPE.getKey(), "password");
|
||||
AccumuloClient accumuloClient = org.apache.accumulo.core.client.Accumulo.newClient().from(properties)
|
||||
.build();
|
||||
scanner = accumuloClient.createScanner(metaTable, Authorizations.EMPTY);
|
||||
LOG.debug("Begin scanning " + metaTable);
|
||||
Key metricPrefixBeginKey = new Key(Meta.METRIC_PREFIX);
|
||||
int firstChar = Meta.METRIC_PREFIX.charAt(0);
|
||||
@@ -112,7 +109,7 @@ public class MetaCacheImpl implements MetaCache {
|
||||
cache.putAll(newCache);
|
||||
}
|
||||
LOG.debug("Finished scanning " + metaTable);
|
||||
} catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
} finally {
|
||||
if (scanner != null) {
|
||||
|
||||
@@ -207,18 +207,14 @@ public class DataStoreCache {
|
||||
testIPRWLock(curatorFramework, nonCachedMetricsIPRWLock, NON_CACHED_METRICS_LOCK_PATH);
|
||||
nonCachedMetricsIP = new DistributedAtomicValue(curatorFramework, NON_CACHED_METRICS, new RetryForever(1000));
|
||||
try {
|
||||
nonCachedMetricsIP.initialize(SerializationUtils.serialize(new TreeSet<>()));
|
||||
nonCachedMetricsIP.forceSet(SerializationUtils.serialize(new TreeSet<>()));
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
TreeCacheListener nonCachedMetricsListener = new TreeCacheListener() {
|
||||
|
||||
@Override
|
||||
public void childEvent(CuratorFramework curatorFramework, TreeCacheEvent event) throws Exception {
|
||||
if (event.getType().equals(TreeCacheEvent.Type.NODE_UPDATED)) {
|
||||
LOG.info("Handling nonCachedMetricsIP event {}", event.getType().toString());
|
||||
readNonCachedMetricsIP();
|
||||
}
|
||||
TreeCacheListener nonCachedMetricsListener = (cf, event) -> {
|
||||
if (event.getType().equals(TreeCacheEvent.Type.NODE_UPDATED)) {
|
||||
LOG.info("Handling nonCachedMetricsIP event {}", event.getType().toString());
|
||||
readNonCachedMetricsIP();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,9 +5,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.accumulo.core.security.ColumnVisibility;
|
||||
import org.apache.commons.lang.builder.CompareToBuilder;
|
||||
import org.apache.commons.lang.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang.builder.HashCodeBuilder;
|
||||
import org.apache.commons.lang3.builder.CompareToBuilder;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
import timely.model.Tag;
|
||||
|
||||
public class TaggedMetric implements Comparable<TaggedMetric> {
|
||||
|
||||
@@ -15,7 +15,7 @@ public class VisibilityFilter {
|
||||
protected LRUMap cache;
|
||||
|
||||
private static final Logger log = LoggerFactory
|
||||
.getLogger(org.apache.accumulo.core.iterators.system.VisibilityFilter.class);
|
||||
.getLogger(org.apache.accumulo.core.iteratorsImpl.system.VisibilityFilter.class);
|
||||
|
||||
public VisibilityFilter(Authorizations authorizations) {
|
||||
this.ve = new VisibilityEvaluator(authorizations);
|
||||
|
||||
@@ -7,13 +7,13 @@ import java.util.OptionalLong;
|
||||
|
||||
import org.apache.accumulo.core.conf.Property;
|
||||
import org.apache.accumulo.core.data.TabletId;
|
||||
import org.apache.accumulo.server.fs.FileRef;
|
||||
import org.apache.accumulo.core.metadata.StoredTabletFile;
|
||||
import org.apache.accumulo.tserver.compaction.CompactionPlan;
|
||||
import org.apache.accumulo.tserver.compaction.CompactionStrategy;
|
||||
import org.apache.accumulo.tserver.compaction.MajorCompactionRequest;
|
||||
import org.apache.commons.collections4.trie.PatriciaTrie;
|
||||
import org.apache.commons.configuration.Configuration;
|
||||
import org.apache.commons.configuration.MapConfiguration;
|
||||
import org.apache.commons.configuration2.Configuration;
|
||||
import org.apache.commons.configuration2.MapConfiguration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.store.MetricAgeOffIterator;
|
||||
@@ -108,8 +108,8 @@ public class MetricCompactionStrategy extends CompactionStrategy {
|
||||
CompactionPlan plan = null;
|
||||
if (shouldCompact(request)) {
|
||||
plan = new CompactionPlan();
|
||||
for (FileRef ref : request.getFiles().keySet()) {
|
||||
plan.inputFiles.add(ref);
|
||||
for (StoredTabletFile f : request.getFiles().keySet()) {
|
||||
plan.inputFiles.add(f);
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled()) {
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.StringJoiner;
|
||||
import org.apache.accumulo.core.client.lexicoder.Lexicoder;
|
||||
import org.apache.accumulo.core.client.lexicoder.LongLexicoder;
|
||||
import org.apache.accumulo.core.client.lexicoder.StringLexicoder;
|
||||
import org.apache.accumulo.core.client.lexicoder.impl.ByteUtils;
|
||||
import org.apache.accumulo.core.clientImpl.lexicoder.ByteUtils;
|
||||
import org.apache.accumulo.core.data.TabletId;
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
@@ -139,10 +139,11 @@ public class TieredCompactionStrategy extends CompactionStrategy {
|
||||
String tableContext = tableProperties.get(Property.TABLE_CLASSPATH.getKey());
|
||||
Class<? extends CompactionStrategy> clazz;
|
||||
if (null != tableContext && !tableContext.equals("")) {
|
||||
clazz = AccumuloVFSClassLoader.getContextManager().loadClass(tableContext, clazzName,
|
||||
CompactionStrategy.class);
|
||||
clazz = AccumuloVFSClassLoader.getContextClassLoader(tableContext).loadClass(clazzName)
|
||||
.asSubclass(CompactionStrategy.class);
|
||||
} else {
|
||||
clazz = AccumuloVFSClassLoader.loadClass(clazzName, CompactionStrategy.class);
|
||||
clazz = AccumuloVFSClassLoader.getClassLoader().loadClass(clazzName)
|
||||
.asSubclass(CompactionStrategy.class);
|
||||
}
|
||||
strategy = clazz.newInstance();
|
||||
strategy.init(options());
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package timely.store.compaction.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.accumulo.core.client.ClientConfiguration;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.Instance;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.conf.ClientProperty;
|
||||
import org.springframework.boot.Banner;
|
||||
import org.springframework.boot.WebApplicationType;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
@@ -22,19 +19,22 @@ public class TabletMetadataConsole {
|
||||
try (ConfigurableApplicationContext ctx = new SpringApplicationBuilder(SpringBootstrap.class)
|
||||
.bannerMode(Banner.Mode.OFF).web(WebApplicationType.NONE).run(args)) {
|
||||
Configuration conf = ctx.getBean(Configuration.class);
|
||||
HashMap<String, String> apacheConf = new HashMap<>();
|
||||
|
||||
final Properties properties = new Properties();
|
||||
Accumulo accumuloConf = conf.getAccumulo();
|
||||
apacheConf.put("instance.name", accumuloConf.getInstanceName());
|
||||
apacheConf.put("instance.zookeeper.host", accumuloConf.getZookeepers());
|
||||
ClientConfiguration aconf = ClientConfiguration.fromMap(apacheConf);
|
||||
Instance instance = new ZooKeeperInstance(aconf);
|
||||
Connector con = instance.getConnector(accumuloConf.getUsername(),
|
||||
new PasswordToken(accumuloConf.getPassword()));
|
||||
properties.put(ClientProperty.INSTANCE_NAME.getKey(), accumuloConf.getInstanceName());
|
||||
properties.put(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), accumuloConf.getZookeepers());
|
||||
properties.put(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getKey(), accumuloConf.getZookeeperTimeout());
|
||||
properties.put(ClientProperty.AUTH_PRINCIPAL.getKey(), accumuloConf.getUsername());
|
||||
properties.put(ClientProperty.AUTH_TOKEN.getKey(), accumuloConf.getPassword());
|
||||
properties.put(ClientProperty.AUTH_TYPE.getKey(), "password");
|
||||
try (AccumuloClient accumuloClient = org.apache.accumulo.core.client.Accumulo.newClient().from(properties)
|
||||
.build()) {
|
||||
TabletMetadataQuery query = new TabletMetadataQuery(accumuloClient, conf.getMetricsTable());
|
||||
TabletMetadataView view = query.run();
|
||||
|
||||
TabletMetadataQuery query = new TabletMetadataQuery(con, conf.getMetricsTable());
|
||||
TabletMetadataView view = query.run();
|
||||
|
||||
System.out.println(view.toText(TimeUnit.DAYS));
|
||||
System.out.println(view.toText(TimeUnit.DAYS));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,9 @@ package timely.store.compaction.util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.AccumuloException;
|
||||
import org.apache.accumulo.core.client.AccumuloSecurityException;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.Scanner;
|
||||
import org.apache.accumulo.core.client.TableNotFoundException;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
@@ -14,25 +14,24 @@ import org.apache.accumulo.core.metadata.MetadataTable;
|
||||
|
||||
public class TabletMetadataQuery {
|
||||
|
||||
private final Connector connector;
|
||||
private final AccumuloClient accumuloClient;
|
||||
private final String tableName;
|
||||
|
||||
public TabletMetadataQuery(Connector connector, String tableName) {
|
||||
this.connector = connector;
|
||||
public TabletMetadataQuery(AccumuloClient accumuloClient, String tableName) {
|
||||
this.accumuloClient = accumuloClient;
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
public TabletMetadataView run() throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
|
||||
TabletMetadataView view = new TabletMetadataView();
|
||||
Map<String, String> tableMap = connector.tableOperations().tableIdMap();
|
||||
Map<String, String> tableMap = accumuloClient.tableOperations().tableIdMap();
|
||||
String tableId = tableMap.get(tableName);
|
||||
if (null == tableId) {
|
||||
throw new IllegalStateException("Unable to find " + MetadataTable.NAME);
|
||||
}
|
||||
|
||||
try (Scanner s = connector.createScanner(MetadataTable.NAME,
|
||||
connector.securityOperations().getUserAuthorizations(connector.whoami()))) {
|
||||
// s.setRange(new Range(tableId, true, tableId, true));
|
||||
try (Scanner s = accumuloClient.createScanner(MetadataTable.NAME,
|
||||
accumuloClient.securityOperations().getUserAuthorizations(accumuloClient.whoami()))) {
|
||||
s.setRange(Range.prefix(tableId));
|
||||
for (Map.Entry<Key, Value> e : s) {
|
||||
view.addEntry(e);
|
||||
|
||||
@@ -6,7 +6,6 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.data.impl.KeyExtent;
|
||||
import org.apache.accumulo.core.metadata.schema.MetadataSchema;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.math3.stat.descriptive.StatisticalSummary;
|
||||
@@ -29,14 +28,14 @@ public class TabletMetadataView {
|
||||
}
|
||||
|
||||
public void addEntry(Map.Entry<Key, Value> entry) {
|
||||
KeyExtent ke = new KeyExtent(entry.getKey().getRow(), (Text) null);
|
||||
if (ke.getEndRow() == null) {
|
||||
Text endRow = MetadataSchema.TabletsSection.decodeRow(entry.getKey().getRow()).getSecond();
|
||||
if (endRow == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Text cf = entry.getKey().getColumnFamily();
|
||||
Text cq = entry.getKey().getColumnQualifier();
|
||||
MetadataAccumulator.Entry candidate = accumulator.checkEntryState(ke.getEndRow());
|
||||
MetadataAccumulator.Entry candidate = accumulator.checkEntryState(endRow);
|
||||
|
||||
if (cf.equals(MetadataSchema.TabletsSection.DataFileColumnFamily.NAME)) {
|
||||
String val = entry.getValue().toString();
|
||||
@@ -55,8 +54,8 @@ public class TabletMetadataView {
|
||||
}
|
||||
} else if (cf.equals(MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.getColumnFamily())
|
||||
&& cq.equals(MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN.getColumnQualifier())) {
|
||||
ke = new KeyExtent(entry.getKey().getRow(), entry.getValue());
|
||||
candidate.setTablePrev(ke.getPrevEndRow());
|
||||
Text prevEndRow = MetadataSchema.TabletsSection.TabletColumnFamily.decodePrevEndRow(entry.getValue());
|
||||
candidate.setTablePrev(prevEndRow);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -220,13 +220,11 @@ public class MetricScanner extends Thread implements UncaughtExceptionHandler {
|
||||
} else if (rangeItr.hasNext()) {
|
||||
// set next range on the scanner
|
||||
Range r = rangeItr.next();
|
||||
this.scanner.close();
|
||||
this.scanner.setRange(r);
|
||||
this.iter = scanner.iterator();
|
||||
} else if (this.endTime == 0) {
|
||||
flush();
|
||||
long endTimeStamp = (System.currentTimeMillis() - (lag * 1000));
|
||||
this.scanner.close();
|
||||
if (null == m) {
|
||||
LOG.debug("[{}] No results found, waiting {}ms to retry with new end time {}. [{}]",
|
||||
subscriptionId, delay, endTimeStamp);
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
package timely.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.accumulo.core.client.ClientConfiguration;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.Instance;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.Scanner;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.conf.ClientProperty;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
@@ -30,23 +26,23 @@ public class GetMetricTableSplitPoints {
|
||||
.bannerMode(Mode.OFF).web(WebApplicationType.NONE).run(args)) {
|
||||
Configuration conf = ctx.getBean(Configuration.class);
|
||||
|
||||
final Map<String, String> properties = new HashMap<>();
|
||||
final Properties properties = new Properties();
|
||||
Accumulo accumuloConf = conf.getAccumulo();
|
||||
properties.put("instance.name", accumuloConf.getInstanceName());
|
||||
properties.put("instance.zookeeper.host", accumuloConf.getZookeepers());
|
||||
final ClientConfiguration aconf = ClientConfiguration.fromMap(properties);
|
||||
final Instance instance = new ZooKeeperInstance(aconf);
|
||||
Connector con = instance.getConnector(accumuloConf.getUsername(),
|
||||
new PasswordToken(accumuloConf.getPassword()));
|
||||
Scanner s = con.createScanner(conf.getMetaTable(),
|
||||
con.securityOperations().getUserAuthorizations(con.whoami()));
|
||||
try {
|
||||
properties.put(ClientProperty.INSTANCE_NAME.getKey(), accumuloConf.getInstanceName());
|
||||
properties.put(ClientProperty.INSTANCE_ZOOKEEPERS.getKey(), accumuloConf.getZookeepers());
|
||||
properties.put(ClientProperty.INSTANCE_ZOOKEEPERS_TIMEOUT.getKey(), accumuloConf.getZookeeperTimeout());
|
||||
properties.put(ClientProperty.AUTH_PRINCIPAL.getKey(), accumuloConf.getUsername());
|
||||
properties.put(ClientProperty.AUTH_TOKEN.getKey(), accumuloConf.getPassword());
|
||||
properties.put(ClientProperty.AUTH_TYPE.getKey(), "password");
|
||||
try (AccumuloClient accumuloClient = org.apache.accumulo.core.client.Accumulo.newClient().from(properties)
|
||||
.build();
|
||||
Scanner s = accumuloClient.createScanner(conf.getMetaTable(),
|
||||
accumuloClient.securityOperations().getUserAuthorizations(accumuloClient.whoami()))) {
|
||||
|
||||
s.setRange(new Range(Meta.METRIC_PREFIX, true, Meta.TAG_PREFIX, false));
|
||||
for (Entry<Key, Value> e : s) {
|
||||
System.out.println(e.getKey().getRow().toString().substring(Meta.METRIC_PREFIX.length()));
|
||||
}
|
||||
} finally {
|
||||
s.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||
import io.netty.handler.codec.http.HttpRequestDecoder;
|
||||
import io.netty.handler.logging.LoggingHandler;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.netty.http.NonSslRedirectHandler;
|
||||
import timely.netty.tcp.MetricsBufferDecoder;
|
||||
@@ -25,8 +26,8 @@ public class TestServer extends Server {
|
||||
private final TestCaptureRequestHandler httpRequests = new TestCaptureRequestHandler();
|
||||
private final TestCaptureRequestHandler udpRequests = new TestCaptureRequestHandler();
|
||||
|
||||
public TestServer(Configuration conf) throws Exception {
|
||||
super(conf, 1);
|
||||
public TestServer(Configuration conf, AccumuloClient accumuloClient) {
|
||||
super(conf, accumuloClient, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
package timely.api.response.timeseries;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import timely.api.request.timeseries.SearchLookupRequest;
|
||||
import timely.api.response.timeseries.SearchLookupResponse.Result;
|
||||
import timely.model.Tag;
|
||||
import timely.util.JsonUtil;
|
||||
|
||||
public class SearchLookupResponseTest {
|
||||
@@ -42,14 +44,11 @@ public class SearchLookupResponseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMetricRequest() {
|
||||
try {
|
||||
String r = "{\"operation\":\"lookup\", \"metric\":\"testmetric\", \"tags\":[{\"host\":\".*\"}]}";
|
||||
SearchLookupRequest req = JsonUtil.getObjectMapper().readValue(r, SearchLookupRequest.class);
|
||||
System.out.println(req);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public void testMetricRequest() throws Exception {
|
||||
String r = "{\"operation\":\"lookup\", \"metric\":\"testmetric\", \"tags\":[{\"host\":\".*\"}]}";
|
||||
SearchLookupRequest req = JsonUtil.getObjectMapper().readValue(r, SearchLookupRequest.class);
|
||||
Assert.assertEquals("testmetric", req.getQuery());
|
||||
Assert.assertEquals(Collections.singletonList(new Tag("host", ".*")), req.getTags());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,12 +10,10 @@ import java.util.Map.Entry;
|
||||
import org.apache.accumulo.core.client.IteratorSetting;
|
||||
import org.apache.accumulo.core.data.*;
|
||||
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
|
||||
import org.apache.accumulo.core.iterators.SortedMapIterator;
|
||||
import org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import timely.adapter.accumulo.MetricAdapter;
|
||||
import timely.auth.VisibilityCache;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.model.Metric;
|
||||
import timely.model.Tag;
|
||||
import timely.sample.Aggregation;
|
||||
@@ -28,11 +26,6 @@ public class AggregationIteratorTest {
|
||||
final private SortedMap<Key, Value> testData1 = new TreeMap<>();
|
||||
final private SortedMap<Key, Value> testData2 = new TreeMap<>();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
VisibilityCache.init(new Configuration());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void createTestData() throws Exception {
|
||||
createTestData1();
|
||||
@@ -149,5 +142,4 @@ public class AggregationIteratorTest {
|
||||
Map<Set<Tag>, Aggregation> samples = AggregationIterator.decodeValue(iter.getTopValue());
|
||||
return samples;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,12 +14,10 @@ import org.apache.accumulo.core.data.Mutation;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
|
||||
import org.apache.accumulo.core.iterators.SortedMapIterator;
|
||||
import org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import timely.adapter.accumulo.MetricAdapter;
|
||||
import timely.auth.VisibilityCache;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.model.Metric;
|
||||
import timely.model.ObjectSizeOf;
|
||||
import timely.model.Tag;
|
||||
@@ -32,11 +30,6 @@ public class DownsampleIteratorTest {
|
||||
final private SortedMap<Key, Value> testData1 = new TreeMap<>();
|
||||
final private SortedMap<Key, Value> testData2 = new TreeMap<>();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
VisibilityCache.init(new Configuration());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void createTestData() {
|
||||
createTestData1();
|
||||
@@ -52,7 +45,6 @@ public class DownsampleIteratorTest {
|
||||
for (ColumnUpdate cu : mutation.getUpdates()) {
|
||||
Key key = new Key(mutation.getRow(), cu.getColumnFamily(), cu.getColumnQualifier(),
|
||||
cu.getColumnVisibility(), cu.getTimestamp());
|
||||
System.out.println(key.toString());
|
||||
testData1.put(key, new Value(cu.getValue()));
|
||||
}
|
||||
}
|
||||
@@ -260,7 +252,7 @@ public class DownsampleIteratorTest {
|
||||
iter.seek(new Range(), Collections.emptyList(), true);
|
||||
boolean hasTop = iter.hasTop();
|
||||
assertTrue(hasTop);
|
||||
Key key = null;
|
||||
Key key;
|
||||
Map<Set<Tag>, Downsample> samples = new HashMap<>();
|
||||
do {
|
||||
Map<Set<Tag>, Downsample> currentSamples = DownsampleIterator.decodeValue(iter.getTopValue());
|
||||
@@ -277,7 +269,7 @@ public class DownsampleIteratorTest {
|
||||
}
|
||||
}
|
||||
key = iter.getTopKey();
|
||||
System.out.println(key.toString());
|
||||
iter.next();
|
||||
} while (iter.hasTop());
|
||||
|
||||
assertEquals(testData.lastKey(), key);
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
|
||||
import org.apache.accumulo.core.iterators.SortedMapIterator;
|
||||
import org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import timely.adapter.accumulo.MetaAdapter;
|
||||
|
||||
@@ -11,7 +11,7 @@ import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
|
||||
import org.apache.accumulo.core.iterators.SortedMapIterator;
|
||||
import org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import timely.adapter.accumulo.MetricAdapter;
|
||||
|
||||
+11
-26
@@ -1,5 +1,7 @@
|
||||
package timely.store.cache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -20,37 +22,24 @@ public class TestGorillaStore {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOne() {
|
||||
public void testGorillaStore() {
|
||||
|
||||
GorillaStore gStore = new GorillaStore("", Long.MAX_VALUE);
|
||||
|
||||
Double[] valueArray = new Double[] { 1.123, 2.314, 3.856, 4.7678, 5.8966, 6.0976, 1.2345, 2.3456, 3.4567 };
|
||||
List<Double> values = new ArrayList<>(Arrays.asList(valueArray));
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
gStore.addValue(now += 100, 1.123);
|
||||
gStore.addValue(now += 100, 2.314);
|
||||
gStore.addValue(now += 100, 3.856);
|
||||
gStore.addValue(now += 100, 4.7678);
|
||||
gStore.addValue(now += 100, 5.8966);
|
||||
gStore.addValue(now += 100, 6.0976);
|
||||
gStore.addValue(now += 100, 1.2345);
|
||||
for (Double d : values) {
|
||||
gStore.addValue(now += 100, d);
|
||||
}
|
||||
|
||||
List<WrappedGorillaDecompressor> decompressorList = gStore.getDecompressors(0, Long.MAX_VALUE);
|
||||
Pair pair;
|
||||
int x = 0;
|
||||
for (WrappedGorillaDecompressor w : decompressorList) {
|
||||
while ((pair = w.readPair()) != null) {
|
||||
System.out.println(pair.getTimestamp() + " --> " + pair.getDoubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println("---------------");
|
||||
|
||||
gStore.addValue(now += 100, 2.3456);
|
||||
gStore.addValue(now += 100, 3.4567);
|
||||
|
||||
decompressorList = gStore.getDecompressors(0, Long.MAX_VALUE);
|
||||
pair = null;
|
||||
for (WrappedGorillaDecompressor w : decompressorList) {
|
||||
while ((pair = w.readPair()) != null) {
|
||||
System.out.println(pair.getTimestamp() + " --> " + pair.getDoubleValue());
|
||||
Assert.assertEquals(values.get(x++).doubleValue(), pair.getDoubleValue(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,7 +57,6 @@ public class TestGorillaStore {
|
||||
|
||||
for (int x = 1; x <= 100; x++) {
|
||||
|
||||
System.out.println("adding value x:" + x);
|
||||
gStore.addValue(timestamp, 2.0);
|
||||
timestamp = timestamp + 1000;
|
||||
|
||||
@@ -79,7 +67,6 @@ public class TestGorillaStore {
|
||||
continue;
|
||||
}
|
||||
|
||||
System.out.println("fetching values x:" + x);
|
||||
long totalObservations = 0;
|
||||
|
||||
List<WrappedGorillaDecompressor> decompressorList = gStore.getDecompressors(start, timestamp);
|
||||
@@ -88,9 +75,7 @@ public class TestGorillaStore {
|
||||
totalObservations++;
|
||||
}
|
||||
}
|
||||
|
||||
Assert.assertEquals("Unexpected number of total observations", x, totalObservations);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import timely.api.response.TimelyException;
|
||||
import timely.api.response.timeseries.QueryResponse;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.model.Metric;
|
||||
import timely.model.ObjectSizeOf;
|
||||
import timely.model.Tag;
|
||||
import timely.model.Value;
|
||||
|
||||
@@ -56,7 +55,6 @@ public class TestMemoryDataStore {
|
||||
}
|
||||
mmStore.flushCaches(-1);
|
||||
return mmStore;
|
||||
|
||||
}
|
||||
|
||||
private DataStoreCache getMetricMemoryStore2(long baseTimestamp) throws TimelyException {
|
||||
@@ -69,26 +67,20 @@ public class TestMemoryDataStore {
|
||||
tags.put("rack", "r01n01");
|
||||
tags.put("instance", "sample");
|
||||
|
||||
boolean debug = false;
|
||||
System.out.println("bytesUsed=" + ObjectSizeOf.Sizer.getObjectSize(mmStore, true, debug));
|
||||
|
||||
Random r = new Random();
|
||||
long timestamp = baseTimestamp;
|
||||
for (int x = 0; x <= 60 * 24; x++) {
|
||||
mmStore.store(createMetric("metric.number.1", tags, r.nextInt(1000), timestamp + (x * 1000)));
|
||||
if (x == 0) {
|
||||
System.out.println("bytesUsed=" + ObjectSizeOf.Sizer.getObjectSize(mmStore, true, debug));
|
||||
}
|
||||
}
|
||||
System.out.println("bytesUsed=" + ObjectSizeOf.Sizer.getObjectSize(mmStore, true, debug));
|
||||
mmStore.flushCaches(-1);
|
||||
return mmStore;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOne() throws TimelyException {
|
||||
public void testFiveSecondDownsample() throws TimelyException {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
// 5 second boundary so that we know how many downsamples to expect
|
||||
long now = (System.currentTimeMillis() / 5000) * 5000;
|
||||
DataStoreCache mmStore = getMetricMemoryStore1(now);
|
||||
|
||||
QueryRequest query = new QueryRequest();
|
||||
@@ -101,20 +93,21 @@ public class TestMemoryDataStore {
|
||||
subQuery.addTag("host", ".*");
|
||||
query.setQueries(Collections.singleton(subQuery));
|
||||
|
||||
try {
|
||||
List<QueryResponse> responseList = mmStore.query(query);
|
||||
for (QueryResponse response : responseList) {
|
||||
System.out.println(response.toString());
|
||||
}
|
||||
} catch (TimelyException e) {
|
||||
e.printStackTrace();
|
||||
List<QueryResponse> responseList = mmStore.query(query);
|
||||
Assert.assertEquals(3, responseList.size());
|
||||
int downsamples = 0;
|
||||
for (QueryResponse r : responseList) {
|
||||
Assert.assertEquals("mymetric", r.getMetric());
|
||||
downsamples += r.getDps().size();
|
||||
}
|
||||
Assert.assertEquals(8, downsamples);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStorage() throws TimelyException {
|
||||
public void testFiveMinuteDownsample() throws TimelyException {
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
// 5 minute boundary so that we know how many downsamples to expect
|
||||
long now = (System.currentTimeMillis() / 300000) * 300000;
|
||||
DataStoreCache mmStore = getMetricMemoryStore2(now);
|
||||
|
||||
QueryRequest query = new QueryRequest();
|
||||
@@ -127,16 +120,20 @@ public class TestMemoryDataStore {
|
||||
subQuery.addTag("host", ".*");
|
||||
query.setQueries(Collections.singleton(subQuery));
|
||||
|
||||
try {
|
||||
List<QueryResponse> responseList = mmStore.query(query);
|
||||
for (QueryResponse response : responseList) {
|
||||
System.out.println(response.toString());
|
||||
}
|
||||
} catch (TimelyException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
List<QueryResponse> responseList = mmStore.query(query);
|
||||
Assert.assertEquals(1, responseList.size());
|
||||
QueryResponse r = responseList.get(0);
|
||||
Assert.assertEquals("metric.number.1", r.getMetric());
|
||||
Assert.assertEquals(5, r.getDps().size());
|
||||
}
|
||||
|
||||
/*
|
||||
* timely.api.response.timeseries.QueryResponse@4263b080[metric=metric.number.1,
|
||||
* tags={host=r01n01},aggregatedTags=[],dps={1700008200000=484.239837398374,
|
||||
* 1700008500000=469.02666666666664, 1700008800000=499.17,
|
||||
* 1700009100000=504.14666666666665, 1700009400000=469.8576271186441}]
|
||||
*/
|
||||
|
||||
private Metric createMetric(String metric, Map<String, String> tags, double value, long timestamp) {
|
||||
Metric m = new Metric();
|
||||
m.setName(metric);
|
||||
|
||||
@@ -18,9 +18,13 @@ import org.apache.hadoop.fs.Path;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class TestWrappedGorillaCompressor {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TestWrappedGorillaCompressor.class);
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws IOException, ClassNotFoundException {
|
||||
|
||||
@@ -82,13 +86,13 @@ public class TestWrappedGorillaCompressor {
|
||||
|
||||
GorillaDecompressor d = new GorillaDecompressor(new LongArrayInput(c.getCompressorOutput()));
|
||||
LinkedList<Pair> q = new LinkedList<>();
|
||||
Pair p = null;
|
||||
Pair p;
|
||||
while ((p = d.readPair()) != null) {
|
||||
q.add(p);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println(e.getMessage());
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,9 +106,9 @@ public class MetricCompactionStrategyTest {
|
||||
assertNotNull(plan);
|
||||
|
||||
assertEquals(3, plan.inputFiles.size());
|
||||
assertEquals(f1, plan.inputFiles.get(0).path().toString());
|
||||
assertEquals(f2, plan.inputFiles.get(1).path().toString());
|
||||
assertEquals(f3, plan.inputFiles.get(2).path().toString());
|
||||
assertEquals(f1, plan.inputFiles.get(0).getPathStr());
|
||||
assertEquals(f2, plan.inputFiles.get(1).getPathStr());
|
||||
assertEquals(f3, plan.inputFiles.get(2).getPathStr());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.accumulo.server.fs.FileRef;
|
||||
import org.apache.accumulo.core.metadata.StoredTabletFile;
|
||||
import org.apache.accumulo.tserver.compaction.CompactionPlan;
|
||||
import org.apache.accumulo.tserver.compaction.CompactionStrategy;
|
||||
import org.apache.accumulo.tserver.compaction.DefaultCompactionStrategy;
|
||||
@@ -124,7 +124,7 @@ public class TieredCompactionStrategyTest {
|
||||
@Test
|
||||
public void getCompactionPlanSkipsAndStopsAtTier() throws IOException {
|
||||
CompactionPlan p1 = new CompactionPlan();
|
||||
p1.inputFiles.add(new FileRef("hdfs://hdfs-name/accumulo/tables/2/default_tablet/C0000ao8.rf"));
|
||||
p1.inputFiles.add(new StoredTabletFile("hdfs://hdfs-name/accumulo/tables/2/default_tablet/C0000ao8.rf"));
|
||||
|
||||
CompactionStrategy c1 = EasyMock.createMock("c1", CompactionStrategy.class);
|
||||
CompactionStrategy c2 = EasyMock.createMock("c2", CompactionStrategy.class);
|
||||
@@ -149,7 +149,7 @@ public class TieredCompactionStrategyTest {
|
||||
@Test
|
||||
public void getCompactionPlanSkipsWhenEmptyInputAndStopsAtTier() throws IOException {
|
||||
CompactionPlan p1 = new CompactionPlan();
|
||||
p1.inputFiles.add(new FileRef("hdfs://hdfs-name/accumulo/tables/2/default_tablet/C0000ao8.rf"));
|
||||
p1.inputFiles.add(new StoredTabletFile("hdfs://hdfs-name/accumulo/tables/2/default_tablet/C0000ao8.rf"));
|
||||
|
||||
CompactionStrategy c1 = EasyMock.createMock("c1", CompactionStrategy.class);
|
||||
CompactionStrategy c2 = EasyMock.createMock("c2", CompactionStrategy.class);
|
||||
|
||||
@@ -6,15 +6,15 @@ import java.util.Collection;
|
||||
|
||||
import org.apache.accumulo.core.client.sample.SamplerConfiguration;
|
||||
import org.apache.accumulo.core.conf.AccumuloConfiguration;
|
||||
import org.apache.accumulo.core.conf.DefaultConfiguration;
|
||||
import org.apache.accumulo.core.data.ByteSequence;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.IteratorEnvironment;
|
||||
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
|
||||
import org.apache.accumulo.core.iterators.SortedKeyValueIterator;
|
||||
import org.apache.accumulo.core.iterators.system.MapFileIterator;
|
||||
import org.apache.accumulo.core.iteratorsImpl.system.MapFileIterator;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.apache.accumulo.core.util.CachedConfiguration;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.fs.FileSystem;
|
||||
|
||||
@@ -29,14 +29,14 @@ public class IteratorTestBase {
|
||||
}
|
||||
|
||||
public DefaultIteratorEnvironment() {
|
||||
this.conf = AccumuloConfiguration.getDefaultConfiguration();
|
||||
this.conf = DefaultConfiguration.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SortedKeyValueIterator<Key, Value> reserveMapFileReader(String mapFileName) throws IOException {
|
||||
Configuration conf = CachedConfiguration.getInstance();
|
||||
Configuration conf = new Configuration();
|
||||
FileSystem fs = FileSystem.get(conf);
|
||||
return new MapFileIterator(this.conf, fs, mapFileName, conf);
|
||||
return new MapFileIterator(fs, mapFileName, conf);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,7 +14,7 @@ import org.apache.accumulo.core.client.IteratorSetting;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.SortedMapIterator;
|
||||
import org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import timely.adapter.accumulo.MetricAdapter;
|
||||
@@ -24,7 +24,7 @@ import timely.model.Tag;
|
||||
|
||||
public class RateIteratorTest extends IteratorTestBase {
|
||||
|
||||
private TreeMap<Key, Value> table = new TreeMap<Key, Value>();
|
||||
private TreeMap<Key, Value> table = new TreeMap<>();
|
||||
private static final List<Tag> tags = new ArrayList<>();
|
||||
static {
|
||||
tags.add(new Tag("rack", "r1"));
|
||||
|
||||
@@ -12,7 +12,7 @@ import org.apache.accumulo.core.client.IteratorSetting;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Range;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.SortedMapIterator;
|
||||
import org.apache.accumulo.core.iteratorsImpl.system.SortedMapIterator;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
@@ -25,7 +25,7 @@ public class TimeSeriesGroupingIteratorTest extends IteratorTestBase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TimeSeriesGroupingIteratorTest.class);
|
||||
|
||||
private TreeMap<Key, Value> table = new TreeMap<Key, Value>();
|
||||
private TreeMap<Key, Value> table = new TreeMap<>();
|
||||
private static final List<Tag> tags = new ArrayList<>();
|
||||
static {
|
||||
tags.add(new Tag("rack", "r1"));
|
||||
@@ -34,7 +34,7 @@ public class TimeSeriesGroupingIteratorTest extends IteratorTestBase {
|
||||
@Before
|
||||
public void setup() {
|
||||
table.clear();
|
||||
long ts = System.currentTimeMillis();
|
||||
long ts = ((System.currentTimeMillis() / 1000) * 1000);
|
||||
for (int i = 0; i < 100; i++) {
|
||||
ts += 1000;
|
||||
Metric m = new Metric("sys.cpu.user", ts, i * 1.0D, tags);
|
||||
@@ -80,7 +80,7 @@ public class TimeSeriesGroupingIteratorTest extends IteratorTestBase {
|
||||
@Test
|
||||
public void testMultipleTimeSeriesMovingAverage() throws Exception {
|
||||
table.clear();
|
||||
long ts = System.currentTimeMillis();
|
||||
long ts = ((System.currentTimeMillis() / 1000) * 1000);
|
||||
List<Tag> tags1 = new ArrayList<>();
|
||||
tags1.add(new Tag("host", "r01n01"));
|
||||
List<Tag> tags2 = new ArrayList<>();
|
||||
@@ -122,7 +122,7 @@ public class TimeSeriesGroupingIteratorTest extends IteratorTestBase {
|
||||
@Test
|
||||
public void testTimeSeriesDropOff() throws Exception {
|
||||
table.clear();
|
||||
long ts = System.currentTimeMillis();
|
||||
long ts = ((System.currentTimeMillis() / 1000) * 1000);
|
||||
List<Tag> tags1 = new ArrayList<>();
|
||||
tags1.add(new Tag("host", "r01n01"));
|
||||
List<Tag> tags2 = new ArrayList<>();
|
||||
@@ -156,11 +156,9 @@ public class TimeSeriesGroupingIteratorTest extends IteratorTestBase {
|
||||
// this section changed when the key structure changed so that identical
|
||||
// colFam values sorted consecutively within an given time period
|
||||
for (int i = 4; i < 100; i++) {
|
||||
System.out.println(i);
|
||||
checkNextResult(iter, new double[] { i - 4, i - 3, i - 2, i - 1, i });
|
||||
}
|
||||
for (int i = 4; i < 50; i++) {
|
||||
System.out.println(i);
|
||||
checkNextResult(iter, new double[] { (i - 4) * 2, (i - 3) * 2, (i - 2) * 2, (i - 1) * 2, i * 2 });
|
||||
}
|
||||
assertFalse(iter.hasTop());
|
||||
@@ -169,7 +167,7 @@ public class TimeSeriesGroupingIteratorTest extends IteratorTestBase {
|
||||
@Test
|
||||
public void testAdditionalTimeSeries() throws Exception {
|
||||
table.clear();
|
||||
long ts = System.currentTimeMillis();
|
||||
long ts = ((System.currentTimeMillis() / 1000) * 1000);
|
||||
List<Tag> tags1 = new ArrayList<>();
|
||||
tags1.add(new Tag("host", "r01n01"));
|
||||
List<Tag> tags2 = new ArrayList<>();
|
||||
@@ -215,7 +213,7 @@ public class TimeSeriesGroupingIteratorTest extends IteratorTestBase {
|
||||
@Test
|
||||
public void testManySparseTimeSeries() throws Exception {
|
||||
table.clear();
|
||||
long ts = System.currentTimeMillis();
|
||||
long ts = ((System.currentTimeMillis() / 1000) * 1000);
|
||||
List<Tag> tags1 = new ArrayList<>();
|
||||
tags1.add(new Tag("host", "r01n01"));
|
||||
List<Tag> tags2 = new ArrayList<>();
|
||||
@@ -278,7 +276,6 @@ public class TimeSeriesGroupingIteratorTest extends IteratorTestBase {
|
||||
shiftAndAdd(first, 1);
|
||||
}
|
||||
for (int i = 4; i < 100; i++) {
|
||||
System.out.println(i);
|
||||
checkNextResult(iter, second);
|
||||
shiftAndAdd(second, 2);
|
||||
}
|
||||
|
||||
@@ -10,16 +10,19 @@ import org.apache.accumulo.core.client.lexicoder.Lexicoder;
|
||||
import org.apache.accumulo.core.client.lexicoder.PairLexicoder;
|
||||
import org.apache.accumulo.core.client.lexicoder.StringLexicoder;
|
||||
import org.apache.accumulo.core.conf.AccumuloConfiguration;
|
||||
import org.apache.accumulo.core.conf.DefaultConfiguration;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.TableId;
|
||||
import org.apache.accumulo.core.data.TabletId;
|
||||
import org.apache.accumulo.core.data.impl.KeyExtent;
|
||||
import org.apache.accumulo.core.data.impl.TabletIdImpl;
|
||||
import org.apache.accumulo.core.dataImpl.KeyExtent;
|
||||
import org.apache.accumulo.core.dataImpl.TabletIdImpl;
|
||||
import org.apache.accumulo.core.metadata.StoredTabletFile;
|
||||
import org.apache.accumulo.core.metadata.schema.DataFileValue;
|
||||
import org.apache.accumulo.core.util.ComparablePair;
|
||||
import org.apache.accumulo.server.fs.FileRef;
|
||||
import org.apache.accumulo.server.fs.VolumeManager;
|
||||
import org.apache.accumulo.server.ServerContext;
|
||||
import org.apache.accumulo.tserver.compaction.MajorCompactionReason;
|
||||
import org.apache.accumulo.tserver.compaction.MajorCompactionRequest;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.easymock.EasyMock;
|
||||
import timely.adapter.accumulo.MetricAdapter;
|
||||
|
||||
@@ -30,7 +33,7 @@ public class CompactionRequestBuilder {
|
||||
private static final PairLexicoder<String, String> badPairEncoder = new PairLexicoder<>(stringEncoder,
|
||||
stringEncoder);
|
||||
|
||||
private final Map<FileRef, DataFileValue> refs = new LinkedHashMap<>();
|
||||
private final Map<StoredTabletFile, DataFileValue> refs = new LinkedHashMap<>();
|
||||
private final Map<String, String> tableProperties;
|
||||
private final long timeMillis;
|
||||
private Key endKeyMetric;
|
||||
@@ -74,7 +77,7 @@ public class CompactionRequestBuilder {
|
||||
}
|
||||
|
||||
public CompactionRequestBuilder file(String path, long size, long entries) {
|
||||
refs.put(new FileRef(path), new DataFileValue(size, entries));
|
||||
refs.put(new StoredTabletFile(path), new DataFileValue(size, entries));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -84,25 +87,24 @@ public class CompactionRequestBuilder {
|
||||
}
|
||||
|
||||
public MajorCompactionRequest build() {
|
||||
String tableName = "1";
|
||||
KeyExtent ke = new KeyExtent();
|
||||
ke.setTableId(tableName);
|
||||
|
||||
TableId tableId = TableId.of("1");
|
||||
Text endRow = null;
|
||||
if (null != endKeyMetric) {
|
||||
ke.setEndRow(endKeyMetric.getRow());
|
||||
endRow = endKeyMetric.getRow();
|
||||
}
|
||||
|
||||
Text prevEndRow = null;
|
||||
if (null != prevKeyMetric) {
|
||||
ke.setPrevEndRow(prevKeyMetric.getRow());
|
||||
prevEndRow = prevKeyMetric.getRow();
|
||||
}
|
||||
|
||||
KeyExtent ke = new KeyExtent(tableId, endRow, prevEndRow);
|
||||
TabletId tid = new TabletIdImpl(ke);
|
||||
|
||||
// @formatter:off
|
||||
MajorCompactionRequest req = EasyMock.partialMockBuilder(MajorCompactionRequest.class)
|
||||
.withConstructor(KeyExtent.class, MajorCompactionReason.class, VolumeManager.class,
|
||||
AccumuloConfiguration.class)
|
||||
.withArgs(ke, MajorCompactionReason.NORMAL, null, AccumuloConfiguration.getDefaultConfiguration())
|
||||
.withConstructor(KeyExtent.class, MajorCompactionReason.class,
|
||||
AccumuloConfiguration.class, ServerContext.class)
|
||||
.withArgs(ke, MajorCompactionReason.NORMAL, DefaultConfiguration.getInstance(), null)
|
||||
.addMockedMethod("getTabletId")
|
||||
.addMockedMethod("getTableProperties")
|
||||
.createMock();
|
||||
|
||||
@@ -4,11 +4,11 @@ import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.AccumuloException;
|
||||
import org.apache.accumulo.core.client.AccumuloSecurityException;
|
||||
import org.apache.accumulo.core.client.BatchWriter;
|
||||
import org.apache.accumulo.core.client.BatchWriterConfig;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.TableNotFoundException;
|
||||
import org.apache.accumulo.core.data.Mutation;
|
||||
import timely.adapter.accumulo.MetricAdapter;
|
||||
@@ -17,12 +17,12 @@ import timely.model.Metric;
|
||||
public class TestMetricWriter {
|
||||
|
||||
private static final int DEFAULT_BATCHES = 10000;
|
||||
private final Connector connector;
|
||||
private final AccumuloClient accumuloClient;
|
||||
private final TestMetrics metrics;
|
||||
private final String tableName;
|
||||
|
||||
public TestMetricWriter(String tableName, Connector connector, TestMetrics metrics) {
|
||||
this.connector = connector;
|
||||
public TestMetricWriter(String tableName, AccumuloClient accumuloClient, TestMetrics metrics) {
|
||||
this.accumuloClient = accumuloClient;
|
||||
this.metrics = metrics;
|
||||
this.tableName = tableName;
|
||||
}
|
||||
@@ -49,10 +49,10 @@ public class TestMetricWriter {
|
||||
|
||||
try {
|
||||
BatchWriterConfig cfg = new BatchWriterConfig().setMaxWriteThreads(4);
|
||||
try (BatchWriter writer = connector.createBatchWriter(tableName, cfg)) {
|
||||
try (BatchWriter writer = accumuloClient.createBatchWriter(tableName, cfg)) {
|
||||
writer.addMutations(mutations);
|
||||
}
|
||||
connector.tableOperations().flush(tableName, null, null, true);
|
||||
accumuloClient.tableOperations().flush(tableName, null, null, true);
|
||||
} catch (AccumuloException | AccumuloSecurityException | TableNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.TableId;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.data.impl.KeyExtent;
|
||||
import org.apache.accumulo.core.metadata.schema.MetadataSchema;
|
||||
import org.apache.accumulo.core.util.ColumnFQ;
|
||||
import org.apache.hadoop.io.Text;
|
||||
@@ -31,7 +31,8 @@ public class TestTabletMetadata {
|
||||
|
||||
public TestTabletMetadata prev(Text row, Text prevRow) {
|
||||
ColumnFQ cfq = MetadataSchema.TabletsSection.TabletColumnFamily.PREV_ROW_COLUMN;
|
||||
addEntry(row, cfq.getColumnFamily(), cfq.getColumnQualifier(), KeyExtent.encodePrevEndRow(prevRow));
|
||||
addEntry(row, cfq.getColumnFamily(), cfq.getColumnQualifier(),
|
||||
MetadataSchema.TabletsSection.TabletColumnFamily.encodePrevEndRow(prevRow));
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ public class TestTabletMetadata {
|
||||
}
|
||||
|
||||
private void addEntry(Text row, Text cf, Text cq, Value value) {
|
||||
Text rowEntry = KeyExtent.getMetadataEntry(tableId, row);
|
||||
Text rowEntry = MetadataSchema.TabletsSection.encodeRow(TableId.of(tableId), row);
|
||||
Value val = new Value(value);
|
||||
Key k = new Key(rowEntry, cf, cq);
|
||||
entries.add(Maps.immutableEntry(k, val));
|
||||
|
||||
@@ -3,19 +3,19 @@ package timely.test.integration;
|
||||
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import timely.Server;
|
||||
import timely.api.request.timeseries.QueryRequest;
|
||||
import timely.api.request.timeseries.QueryRequest.SubQuery;
|
||||
import timely.api.response.timeseries.QueryResponse;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.store.MetricAgeOffIterator;
|
||||
import timely.store.cache.DataStoreCache;
|
||||
import timely.test.IntegrationTest;
|
||||
@@ -25,18 +25,27 @@ public class DataStoreIT extends OneWaySSLBase {
|
||||
|
||||
private static final long ONE_DAY = TimeUnit.DAYS.toMillis(1);
|
||||
private static final long ONE_HOUR = TimeUnit.HOURS.toMillis(1);
|
||||
private static final long TEST_TIME = System.currentTimeMillis() - ONE_DAY;
|
||||
private static final Long TEST_TIME = ((System.currentTimeMillis() / 1000) * 1000) - ONE_DAY;
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultAgeOffWithoutCache() throws Exception {
|
||||
conf.getCache().setEnabled(false);
|
||||
testDefaultAgeOff(conf);
|
||||
conf.setMetricAgeOffDays(Collections.singletonMap(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY, 1));
|
||||
startServer();
|
||||
testDefaultAgeOff();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultAgeOffWithCache() throws Exception {
|
||||
conf.getCache().setEnabled(true);
|
||||
testDefaultAgeOff(conf);
|
||||
conf.setMetricAgeOffDays(Collections.singletonMap(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY, 1));
|
||||
startServer();
|
||||
testDefaultAgeOff();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,66 +59,59 @@ public class DataStoreIT extends OneWaySSLBase {
|
||||
HashMap<String, Integer> ageOffHours = new HashMap<>();
|
||||
ageOffHours.put(DataStoreCache.DEFAULT_AGEOFF_KEY, 23);
|
||||
conf.getCache().setMetricAgeOffHours(ageOffHours);
|
||||
testDefaultAgeOff(conf);
|
||||
conf.setMetricAgeOffDays(Collections.singletonMap(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY, 1));
|
||||
startServer();
|
||||
testDefaultAgeOff();
|
||||
}
|
||||
|
||||
public void testDefaultAgeOff(Configuration conf) throws Exception {
|
||||
HashMap<String, Integer> ageOffSettings = new HashMap<>();
|
||||
ageOffSettings.put(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY, 1);
|
||||
conf.setMetricAgeOffDays(ageOffSettings);
|
||||
public void testDefaultAgeOff() throws Exception {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + ONE_HOUR) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + (ONE_HOUR * 2)) + " 2.0 tag1=value1 tag3=value3");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(4, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + (24 * ONE_HOUR));
|
||||
SubQuery subQuery = new SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.addTag("tag1", ".*");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
List<QueryResponse> response = query("https://127.0.0.1:54322/api/query", request);
|
||||
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + ONE_HOUR) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + (ONE_HOUR * 2)) + " 2.0 tag1=value1 tag3=value3");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(4, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + (24 * ONE_HOUR));
|
||||
SubQuery subQuery = new SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.addTag("tag1", ".*");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
List<QueryResponse> response = query("https://127.0.0.1:54322/api/query", request);
|
||||
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(1, tags.size());
|
||||
assertEquals("value1", tags.get("tag1"));
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(2, dps.size());
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(1, tags.size());
|
||||
assertEquals("value1", tags.get("tag1"));
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(2, dps.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAgeOffWithoutCache() throws Exception {
|
||||
conf.getCache().setEnabled(false);
|
||||
testMultipleAgeOff(conf);
|
||||
conf.setMetricAgeOffDays(Collections.singletonMap(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY, 1));
|
||||
startServer();
|
||||
testDefaultAgeOff();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAgeOffWithCache() throws Exception {
|
||||
conf.getCache().setEnabled(true);
|
||||
testMultipleAgeOff(conf);
|
||||
}
|
||||
|
||||
public void testMultipleAgeOff(Configuration conf) throws Exception {
|
||||
HashMap<String, Integer> ageOffSettings = new HashMap<>();
|
||||
ageOffSettings.put(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY, 1);
|
||||
ageOffSettings.put("sys.cpu.user", 1);
|
||||
conf.setMetricAgeOffDays(ageOffSettings);
|
||||
startServer();
|
||||
testMultipleAgeOff();
|
||||
}
|
||||
|
||||
public void testMultipleAgeOff() throws Exception {
|
||||
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
// @formatter:off
|
||||
/*
|
||||
* TEST_TIME = System.currentTimeMillis() - ONE_DAY
|
||||
* TEST_TIME = ((System.currentTimeMillis() / 1000) * 1000) - ONE_DAY
|
||||
* Age off for all metrics is one day = 24 hours
|
||||
*
|
||||
* lines 1, 2, 3 will age off immediately as they are >= 2 days old
|
||||
@@ -119,46 +121,41 @@ public class DataStoreIT extends OneWaySSLBase {
|
||||
*
|
||||
*/
|
||||
// @formatter:on
|
||||
try {
|
||||
put("sys.cpu.idle " + (TEST_TIME - ONE_DAY - (2 * ONE_HOUR)) + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME - ONE_DAY - ONE_HOUR) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME - ONE_DAY) + " 2.0 tag1=value1 tag3=value3",
|
||||
"sys.cpu.idle " + (TEST_TIME + (ONE_DAY * 2)) + " 2.0 tag1=value1 tag3=value3",
|
||||
"sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + ONE_HOUR) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + (ONE_HOUR * 2)) + " 2.0 tag1=value1 tag3=value3");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(4, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME - ONE_DAY - (2 * ONE_HOUR));
|
||||
request.setEnd(TEST_TIME + (24 * ONE_HOUR));
|
||||
SubQuery subQuery = new SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.addTag("tag1", ".*");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
List<QueryResponse> response = query("https://127.0.0.1:54322/api/query", request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(1, tags.size());
|
||||
assertEquals("value1", tags.get("tag1"));
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(2, dps.size());
|
||||
put("sys.cpu.idle " + (TEST_TIME - ONE_DAY - (2 * ONE_HOUR)) + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME - ONE_DAY - ONE_HOUR) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME - ONE_DAY) + " 2.0 tag1=value1 tag3=value3",
|
||||
"sys.cpu.idle " + (TEST_TIME + (ONE_DAY * 2)) + " 2.0 tag1=value1 tag3=value3",
|
||||
"sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + ONE_HOUR) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + (ONE_HOUR * 2)) + " 2.0 tag1=value1 tag3=value3");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(4, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME - ONE_DAY - (2 * ONE_HOUR));
|
||||
request.setEnd(TEST_TIME + (24 * ONE_HOUR));
|
||||
SubQuery subQuery = new SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.addTag("tag1", ".*");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
List<QueryResponse> response = query("https://127.0.0.1:54322/api/query", request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(1, tags.size());
|
||||
assertEquals("value1", tags.get("tag1"));
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(2, dps.size());
|
||||
|
||||
QueryRequest request2 = new QueryRequest();
|
||||
request2.setStart(TEST_TIME - ONE_DAY - (2 * ONE_HOUR));
|
||||
request2.setEnd(TEST_TIME + (24 * ONE_HOUR));
|
||||
SubQuery subQuery2 = new SubQuery();
|
||||
subQuery2.setMetric("sys.cpu.idle");
|
||||
subQuery2.addTag("tag1", ".*");
|
||||
subQuery2.setDownsample(Optional.of("1s-max"));
|
||||
request2.addQuery(subQuery2);
|
||||
List<QueryResponse> response2 = query("https://127.0.0.1:54322/api/query", request2);
|
||||
assertEquals(0, response2.size());
|
||||
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
QueryRequest request2 = new QueryRequest();
|
||||
request2.setStart(TEST_TIME - ONE_DAY - (2 * ONE_HOUR));
|
||||
request2.setEnd(TEST_TIME + (24 * ONE_HOUR));
|
||||
SubQuery subQuery2 = new SubQuery();
|
||||
subQuery2.setMetric("sys.cpu.idle");
|
||||
subQuery2.addTag("tag1", ".*");
|
||||
subQuery2.setDownsample(Optional.of("1s-max"));
|
||||
request2.addQuery(subQuery2);
|
||||
List<QueryResponse> response2 = query("https://127.0.0.1:54322/api/query", request2);
|
||||
assertEquals(0, response2.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
package timely.test.integration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
|
||||
import datawave.accumulo.inmemory.InMemoryAccumuloClient;
|
||||
import datawave.accumulo.inmemory.InMemoryInstance;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.AccumuloSecurityException;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.apache.zookeeper.server.ServerConfig;
|
||||
import org.apache.zookeeper.server.ZooKeeperServerMain;
|
||||
import org.apache.zookeeper.server.quorum.QuorumPeerConfig;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.Server;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.store.MetricAgeOffIterator;
|
||||
import timely.test.TestConfiguration;
|
||||
|
||||
/**
|
||||
* Base class for integration tests using in-memory-accumulo.
|
||||
*/
|
||||
public class InMemoryITBase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(InMemoryITBase.class);
|
||||
|
||||
protected static final String ROOT_USER = "root";
|
||||
protected static final String ROOT_PASSWORD = "secret";
|
||||
protected Configuration conf = null;
|
||||
protected AccumuloClient accumuloClient;
|
||||
protected Server s;
|
||||
private ZooKeeperServerMain zookeeper;
|
||||
private Future zooFuture;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupInMemoryAccumulo() throws Exception {
|
||||
|
||||
InMemoryInstance instance = new InMemoryInstance();
|
||||
try {
|
||||
AccumuloClient accumuloClient = new InMemoryAccumuloClient(ROOT_USER, instance);
|
||||
accumuloClient.securityOperations().changeUserAuthorizations(accumuloClient.whoami(),
|
||||
new Authorizations("PUBLIC", "A", "B", "C"));
|
||||
} catch (AccumuloSecurityException e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void startupInMemoryBase() throws Exception {
|
||||
AuthCache.clear();
|
||||
clearTablesResetConf();
|
||||
InMemoryInstance instance = new InMemoryInstance();
|
||||
accumuloClient = new InMemoryAccumuloClient(ROOT_USER, instance);
|
||||
|
||||
File tempDir;
|
||||
try {
|
||||
tempDir = Files.createTempDirectory("zookeeper_temp").toFile();
|
||||
tempDir.deleteOnExit();
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to create temp directory for mini accumulo cluster");
|
||||
}
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put("dataDir", tempDir.getAbsolutePath() + "/data");
|
||||
properties.put("clientPort", "2181");
|
||||
properties.put("skipACL", "true");
|
||||
properties.put("leaderServes", "yes");
|
||||
properties.put("4lw.commands.whitelist", "*");
|
||||
QuorumPeerConfig quorumPeerConfig = new QuorumPeerConfig();
|
||||
quorumPeerConfig.parseProperties(properties);
|
||||
|
||||
zookeeper = new ZooKeeperServerMain();
|
||||
final ServerConfig config = new ServerConfig();
|
||||
config.readFrom(quorumPeerConfig);
|
||||
zooFuture = Executors.newSingleThreadExecutor().submit(() -> {
|
||||
try {
|
||||
zookeeper.runFromConfig(config);
|
||||
} catch (Exception e) {
|
||||
LOG.error(e.getMessage(), e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void stopServer() {
|
||||
if (s != null) {
|
||||
s.setAccumuloClient(null);
|
||||
s.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdownInMemoryBase() {
|
||||
if (zookeeper != null) {
|
||||
zookeeper.close();
|
||||
}
|
||||
|
||||
if (zooFuture != null) {
|
||||
zooFuture.cancel(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearTablesResetConf() throws Exception {
|
||||
InMemoryInstance instance = new InMemoryInstance();
|
||||
AccumuloClient accumuloClient = new InMemoryAccumuloClient(ROOT_USER, instance);
|
||||
accumuloClient.tableOperations().list().forEach(t -> {
|
||||
if (t.startsWith("timely")) {
|
||||
try {
|
||||
accumuloClient.tableOperations().delete(t);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
// Reset configuration
|
||||
conf = TestConfiguration.createMinimalConfigurationForTest();
|
||||
conf.getAccumulo().setInstanceName(instance.getInstanceName());
|
||||
conf.getAccumulo().setZookeepers(instance.getZooKeepers());
|
||||
conf.getSecurity().getServerSsl().setUseOpenssl(false);
|
||||
conf.getSecurity().getServerSsl().setUseGeneratedKeypair(true);
|
||||
conf.getWebsocket().setFlushIntervalSeconds(TestConfiguration.WAIT_SECONDS);
|
||||
HashMap<String, Integer> ageOffSettings = new HashMap<>();
|
||||
ageOffSettings.put(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY, 7);
|
||||
conf.setMetricAgeOffDays(ageOffSettings);
|
||||
// }
|
||||
}
|
||||
|
||||
protected void deleteAccumuloEntries() throws Exception {
|
||||
InMemoryInstance instance = new InMemoryInstance();
|
||||
AccumuloClient accumuloClient = new InMemoryAccumuloClient(ROOT_USER, instance);
|
||||
accumuloClient.tableOperations().list().forEach(t -> {
|
||||
if (t.startsWith("timely")) {
|
||||
try {
|
||||
accumuloClient.tableOperations().deleteRows(t, new Text("#"), new Text("~"));
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void startServer() {
|
||||
try {
|
||||
s = new Server(conf, accumuloClient);
|
||||
s.run();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,13 +5,16 @@ import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
|
||||
import org.apache.accumulo.minicluster.MiniAccumuloConfig;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.Server;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.store.MetricAgeOffIterator;
|
||||
@@ -38,8 +41,10 @@ public class MacITBase {
|
||||
tempDir.deleteOnExit();
|
||||
}
|
||||
|
||||
protected static MiniAccumuloCluster mac = null;
|
||||
private static MiniAccumuloCluster mac = null;
|
||||
protected static Configuration conf = null;
|
||||
protected AccumuloClient accumuloClient;
|
||||
protected Server s;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupMiniAccumulo() throws Exception {
|
||||
@@ -47,31 +52,30 @@ public class MacITBase {
|
||||
final MiniAccumuloConfig macConfig = new MiniAccumuloConfig(tempDir, MAC_ROOT_PASSWORD);
|
||||
mac = new MiniAccumuloCluster(macConfig);
|
||||
mac.start();
|
||||
conf = TestConfiguration.createMinimalConfigurationForTest();
|
||||
conf.getAccumulo().setInstanceName(mac.getInstanceName());
|
||||
conf.getAccumulo().setZookeepers(mac.getZooKeepers());
|
||||
conf.getSecurity().getServerSsl().setUseOpenssl(false);
|
||||
conf.getSecurity().getServerSsl().setUseGeneratedKeypair(true);
|
||||
conf.getWebsocket().setFlushIntervalSeconds(TestConfiguration.WAIT_SECONDS);
|
||||
HashMap<String, Integer> ageOffSettings = new HashMap<>();
|
||||
ageOffSettings.put(MetricAgeOffIterator.DEFAULT_AGEOFF_KEY, 7);
|
||||
conf.setMetricAgeOffDays(ageOffSettings);
|
||||
} else {
|
||||
LOG.info("Mini Accumulo already running.");
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void clearTablesResetConf() throws Exception {
|
||||
Connector con = mac.getConnector(MAC_ROOT_USER, MAC_ROOT_PASSWORD);
|
||||
con.tableOperations().list().forEach(t -> {
|
||||
if (t.startsWith("timely")) {
|
||||
try {
|
||||
con.tableOperations().delete(t);
|
||||
} catch (Exception e) {
|
||||
public void setupMacITBase() {
|
||||
AuthCache.clear();
|
||||
clearTablesResetConf();
|
||||
accumuloClient = mac.createAccumuloClient(MAC_ROOT_USER, new PasswordToken(MAC_ROOT_PASSWORD));
|
||||
}
|
||||
|
||||
private void clearTablesResetConf() {
|
||||
try (AccumuloClient accumuloClient = mac.createAccumuloClient(MAC_ROOT_USER,
|
||||
new PasswordToken(MAC_ROOT_PASSWORD))) {
|
||||
accumuloClient.tableOperations().list().forEach(t -> {
|
||||
if (t.startsWith("timely")) {
|
||||
try {
|
||||
accumuloClient.tableOperations().delete(t);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
// Reset configuration
|
||||
conf = TestConfiguration.createMinimalConfigurationForTest();
|
||||
conf.getAccumulo().setInstanceName(mac.getInstanceName());
|
||||
@@ -84,8 +88,26 @@ public class MacITBase {
|
||||
conf.setMetricAgeOffDays(ageOffSettings);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void initializeAuthCache() {
|
||||
AuthCache.clear();
|
||||
protected void startServer() throws Exception {
|
||||
s = new Server(conf, accumuloClient);
|
||||
s.run();
|
||||
}
|
||||
|
||||
protected void stopServer() {
|
||||
if (s != null) {
|
||||
s.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
if (accumuloClient != null) {
|
||||
accumuloClient.close();
|
||||
accumuloClient = null;
|
||||
}
|
||||
|
||||
if (s != null) {
|
||||
s.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.AccumuloClient;
|
||||
import org.apache.accumulo.core.client.IteratorSetting;
|
||||
import org.apache.accumulo.core.conf.Property;
|
||||
import org.apache.accumulo.core.iterators.IteratorUtil;
|
||||
@@ -22,13 +22,12 @@ import org.apache.accumulo.tserver.compaction.CompactionStrategy;
|
||||
import org.apache.accumulo.tserver.compaction.DefaultCompactionStrategy;
|
||||
import org.apache.hadoop.io.Text;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.store.MetricAgeOffIterator;
|
||||
import timely.store.compaction.MetricCompactionStrategy;
|
||||
import timely.store.compaction.TabletRowAdapter;
|
||||
@@ -49,53 +48,45 @@ public class MetricCompactionIT extends MacITBase {
|
||||
private static final EnumSet<IteratorUtil.IteratorScope> AGEOFF_SCOPES = EnumSet
|
||||
.allOf(IteratorUtil.IteratorScope.class);
|
||||
|
||||
private Connector connector;
|
||||
private MetricConfigurationAdapter adapter;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupClass() throws Exception {
|
||||
Connector connector = mac.getConnector(MAC_ROOT_USER, MAC_ROOT_PASSWORD);
|
||||
connector.instanceOperations().setProperty(Property.TSERV_MAJC_DELAY.getKey(), "3s");
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
connector = mac.getConnector(MAC_ROOT_USER, MAC_ROOT_PASSWORD);
|
||||
accumuloClient.instanceOperations().setProperty(Property.TSERV_MAJC_DELAY.getKey(), "3s");
|
||||
String metricsTable = conf.getMetricsTable();
|
||||
if (!metricsTable.contains(".")) {
|
||||
throw new IllegalArgumentException("Expected to find namespace in table name");
|
||||
}
|
||||
String[] parts = metricsTable.split("\\.", 2);
|
||||
String namespace = parts[0];
|
||||
if (!connector.namespaceOperations().exists(namespace)) {
|
||||
connector.namespaceOperations().create(namespace);
|
||||
if (!accumuloClient.namespaceOperations().exists(namespace)) {
|
||||
accumuloClient.namespaceOperations().create(namespace);
|
||||
}
|
||||
connector.tableOperations().create(metricsTable);
|
||||
adapter = new MetricConfigurationAdapter(connector, conf.getMetricsTable());
|
||||
connector.tableOperations().setProperty(conf.getMetricsTable(), Property.TABLE_SPLIT_THRESHOLD.getKey(), "50K");
|
||||
accumuloClient.tableOperations().create(metricsTable);
|
||||
adapter = new MetricConfigurationAdapter(accumuloClient, conf.getMetricsTable());
|
||||
accumuloClient.tableOperations().setProperty(conf.getMetricsTable(), Property.TABLE_SPLIT_THRESHOLD.getKey(),
|
||||
"50K");
|
||||
adapter.resetState();
|
||||
startServer();
|
||||
}
|
||||
|
||||
@After
|
||||
public void teardown() throws Exception {
|
||||
accumuloClient.instanceOperations().setProperty(Property.TSERV_MAJC_DELAY.getKey(), "30s");
|
||||
adapter.resetState();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void teardownClass() throws Exception {
|
||||
Connector connector = mac.getConnector(MAC_ROOT_USER, MAC_ROOT_PASSWORD);
|
||||
connector.instanceOperations().setProperty(Property.TSERV_MAJC_DELAY.getKey(), "30s");
|
||||
AuthCache.resetConfiguration();
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void tableMetadataEnumeratesTablets() throws Exception {
|
||||
String metricsTable = conf.getMetricsTable();
|
||||
|
||||
TestMetricWriter writer = new TestMetricWriter(metricsTable, connector, new TestMetrics());
|
||||
TestMetricWriter writer = new TestMetricWriter(metricsTable, accumuloClient, new TestMetrics());
|
||||
writer.ingestRandomDuration(60, TimeUnit.SECONDS, System.currentTimeMillis(), 250);
|
||||
|
||||
Collection<Text> splits = connector.tableOperations().listSplits(conf.getMetricsTable());
|
||||
TabletMetadataQuery query = new TabletMetadataQuery(connector, metricsTable);
|
||||
Collection<Text> splits = accumuloClient.tableOperations().listSplits(conf.getMetricsTable());
|
||||
TabletMetadataQuery query = new TabletMetadataQuery(accumuloClient, metricsTable);
|
||||
TabletMetadataView view = query.run();
|
||||
|
||||
// @formatter:off
|
||||
@@ -138,12 +129,13 @@ public class MetricCompactionIT extends MacITBase {
|
||||
String metricsTable = conf.getMetricsTable();
|
||||
|
||||
// check to make sure the table has only one iterator
|
||||
Map<String, EnumSet<IteratorUtil.IteratorScope>> itrs = connector.tableOperations().listIterators(metricsTable);
|
||||
assertEquals(1, itrs.size());
|
||||
Map<String, EnumSet<IteratorUtil.IteratorScope>> itrs = accumuloClient.tableOperations()
|
||||
.listIterators(metricsTable);
|
||||
assertEquals(2, itrs.size());
|
||||
assertTrue(itrs.containsKey("vers"));
|
||||
|
||||
long timestampMax = System.currentTimeMillis();
|
||||
TestMetricWriter writer = new TestMetricWriter(conf.getMetricsTable(), connector, new TestMetrics());
|
||||
TestMetricWriter writer = new TestMetricWriter(conf.getMetricsTable(), accumuloClient, new TestMetrics());
|
||||
long timestampMin = writer.ingestRandomDuration(30, TimeUnit.SECONDS, timestampMax, 250);
|
||||
|
||||
// invoke compact operation to flush everything through
|
||||
@@ -157,7 +149,7 @@ public class MetricCompactionIT extends MacITBase {
|
||||
|
||||
// run check to verify there are pre-existing splits for a prefix
|
||||
// @formatter:off
|
||||
TabletMetadataQuery query = new TabletMetadataQuery(connector, metricsTable);
|
||||
TabletMetadataQuery query = new TabletMetadataQuery(accumuloClient, metricsTable);
|
||||
TabletSummary summary1 = query.run()
|
||||
.computeSummary()
|
||||
.build();
|
||||
@@ -206,14 +198,14 @@ public class MetricCompactionIT extends MacITBase {
|
||||
|
||||
private static class MetricConfigurationAdapter {
|
||||
|
||||
private final Connector connector;
|
||||
private final AccumuloClient accumuloClient;
|
||||
private final String tableName;
|
||||
|
||||
private static String[] CLEAR_PROPERTY_KEYS = {
|
||||
Property.TABLE_COMPACTION_STRATEGY_PREFIX.getKey() + MetricCompactionStrategy.MIN_AGEOFF_KEY };
|
||||
|
||||
public MetricConfigurationAdapter(Connector connector, String tableName) {
|
||||
this.connector = connector;
|
||||
public MetricConfigurationAdapter(AccumuloClient accumuloClient, String tableName) {
|
||||
this.accumuloClient = accumuloClient;
|
||||
this.tableName = tableName;
|
||||
}
|
||||
|
||||
@@ -223,31 +215,32 @@ public class MetricCompactionIT extends MacITBase {
|
||||
ageOffs.put("ageoff.default", Long.toString(ageOff));
|
||||
IteratorSetting ageOffIteratorSettings = new IteratorSetting(100, AGE_OFF_ITERATOR_NAME,
|
||||
MetricAgeOffIterator.class, ageOffs);
|
||||
connector.tableOperations().attachIterator(tableName, ageOffIteratorSettings, AGEOFF_SCOPES);
|
||||
connector.tableOperations().setProperty(tableName, Property.TABLE_COMPACTION_STRATEGY.getKey(),
|
||||
accumuloClient.tableOperations().removeIterator(tableName, AGE_OFF_ITERATOR_NAME, AGEOFF_SCOPES);
|
||||
accumuloClient.tableOperations().attachIterator(tableName, ageOffIteratorSettings, AGEOFF_SCOPES);
|
||||
accumuloClient.tableOperations().setProperty(tableName, Property.TABLE_COMPACTION_STRATEGY.getKey(),
|
||||
clazz.getName());
|
||||
}
|
||||
|
||||
public void runCompaction() throws Exception {
|
||||
connector.tableOperations().compact(tableName, null, null, true, true);
|
||||
accumuloClient.tableOperations().compact(tableName, null, null, true, true);
|
||||
}
|
||||
|
||||
public void resetState() throws Exception {
|
||||
Map<String, EnumSet<IteratorUtil.IteratorScope>> iters = connector.tableOperations()
|
||||
Map<String, EnumSet<IteratorUtil.IteratorScope>> iters = accumuloClient.tableOperations()
|
||||
.listIterators(tableName);
|
||||
for (String name : iters.keySet()) {
|
||||
if (name.startsWith("ageoff")) {
|
||||
connector.tableOperations().removeIterator(tableName, name, AGEOFF_SCOPES);
|
||||
accumuloClient.tableOperations().removeIterator(tableName, name, AGEOFF_SCOPES);
|
||||
}
|
||||
}
|
||||
|
||||
// reset compaction strategy to default
|
||||
connector.tableOperations().setProperty(tableName, Property.TABLE_COMPACTION_STRATEGY.getKey(),
|
||||
accumuloClient.tableOperations().setProperty(tableName, Property.TABLE_COMPACTION_STRATEGY.getKey(),
|
||||
DefaultCompactionStrategy.class.getName());
|
||||
|
||||
// reset any properties
|
||||
for (String s : CLEAR_PROPERTY_KEYS) {
|
||||
connector.tableOperations().removeProperty(tableName, s);
|
||||
accumuloClient.tableOperations().removeProperty(tableName, s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,10 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import timely.Server;
|
||||
import timely.api.request.timeseries.QueryRequest;
|
||||
import timely.api.request.timeseries.QueryRequest.SubQuery;
|
||||
import timely.api.response.timeseries.QueryResponse;
|
||||
@@ -25,34 +26,38 @@ import timely.test.TestConfiguration;
|
||||
@Category(IntegrationTest.class)
|
||||
public class OneWaySSLAnonAccessIT extends OneWaySSLBase {
|
||||
|
||||
private static final Long TEST_TIME = System.currentTimeMillis();
|
||||
private static final Long TEST_TIME = (System.currentTimeMillis() / 1000) * 1000;
|
||||
|
||||
@Before
|
||||
public void startup() {
|
||||
startServer();
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithVisibility() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 1000) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 2000) + " 2.0 tag1=value1 tag3=value3 viz=secret");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + 6000);
|
||||
SubQuery subQuery = new SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
List<QueryResponse> response = query("https://127.0.0.1:54322/api/query", request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(0, tags.size());
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(2, dps.size());
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 1000) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 2000) + " 2.0 tag1=value1 tag3=value3 viz=secret");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + 6000);
|
||||
SubQuery subQuery = new SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
List<QueryResponse> response = query("https://127.0.0.1:54322/api/query", request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(0, tags.size());
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(2, dps.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -26,6 +26,16 @@ public class OneWaySSLBase extends QueryBase {
|
||||
|
||||
protected static File clientTrustStoreFile = null;
|
||||
|
||||
@Before
|
||||
public void setupOneWaySSLBase() throws Exception {
|
||||
setupSSL(conf);
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdownOneWaySSLBase() {
|
||||
AuthCache.resetConfiguration();
|
||||
}
|
||||
|
||||
protected SSLSocketFactory getSSLSocketFactory() throws Exception {
|
||||
SslContextBuilder builder = SslContextBuilder.forClient();
|
||||
builder.applicationProtocolConfig(ApplicationProtocolConfig.DISABLED);
|
||||
@@ -49,11 +59,6 @@ public class OneWaySSLBase extends QueryBase {
|
||||
config.getSecurity().setAllowAnonymousHttpAccess(true);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void configureSSL() throws Exception {
|
||||
setupSSL(conf);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(String username, String password, URL url) throws Exception {
|
||||
// No username/password needed for anonymous access
|
||||
@@ -67,10 +72,4 @@ public class OneWaySSLBase extends QueryBase {
|
||||
con.setHostnameVerifier((host, session) -> true);
|
||||
return con;
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
AuthCache.resetConfiguration();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,14 +16,12 @@ import javax.net.ssl.HttpsURLConnection;
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.cookie.ClientCookieDecoder;
|
||||
import io.netty.handler.codec.http.cookie.Cookie;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import timely.Server;
|
||||
import timely.api.request.auth.BasicAuthLoginRequest;
|
||||
import timely.api.request.timeseries.QueryRequest;
|
||||
import timely.api.response.timeseries.QueryResponse;
|
||||
@@ -41,7 +39,17 @@ import timely.util.JsonUtil;
|
||||
@Category(IntegrationTest.class)
|
||||
public class OneWaySSLBasicAuthAccessIT extends OneWaySSLBase {
|
||||
|
||||
private static final Long TEST_TIME = System.currentTimeMillis();
|
||||
private static final Long TEST_TIME = (System.currentTimeMillis() / 1000) * 1000;
|
||||
|
||||
@Before
|
||||
public void startup() {
|
||||
startServer();
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
stopServer();
|
||||
}
|
||||
|
||||
protected HttpsURLConnection getUrlConnection(URL url) throws Exception {
|
||||
// Username and password are set in src/test/resources/security.xml
|
||||
@@ -81,8 +89,8 @@ public class OneWaySSLBasicAuthAccessIT extends OneWaySSLBase {
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
AuthCache.clear();
|
||||
Connector con = mac.getConnector("root", "secret");
|
||||
con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root",
|
||||
new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
}
|
||||
|
||||
@After
|
||||
@@ -92,57 +100,39 @@ public class OneWaySSLBasicAuthAccessIT extends OneWaySSLBase {
|
||||
|
||||
@Test
|
||||
public void testBasicAuthLogin() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query(metrics);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query(metrics);
|
||||
}
|
||||
|
||||
@Test(expected = UnauthorizedUserException.class)
|
||||
public void testBasicAuthLoginFailure() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query("test", "test2", metrics);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query("test", "test2", metrics);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithVisibility() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 1000) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 2000) + " 2.0 tag1=value1 tag3=value3 viz=A",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 2.0 tag1=value1 tag3=value3 viz=D",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 2.0 tag1=value1 tag3=value3 viz=G");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + 6000);
|
||||
QueryRequest.SubQuery subQuery = new QueryRequest.SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
String metrics = "https://127.0.0.1:54322/api/query";
|
||||
List<QueryResponse> response = query("test", "test1", metrics, request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(0, tags.size());
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
// test user only has authorities A,B,C. So it does not see D and G.
|
||||
assertEquals(3, dps.size());
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 1000) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 2000) + " 2.0 tag1=value1 tag3=value3 viz=A",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 2.0 tag1=value1 tag3=value3 viz=D",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 2.0 tag1=value1 tag3=value3 viz=G");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + 6000);
|
||||
QueryRequest.SubQuery subQuery = new QueryRequest.SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
String metrics = "https://127.0.0.1:54322/api/query";
|
||||
List<QueryResponse> response = query("test", "test1", metrics, request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(0, tags.size());
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
// test user only has authorities A,B,C. So it does not see D and G.
|
||||
assertEquals(3, dps.size());
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ import timely.api.request.timeseries.QueryRequest;
|
||||
import timely.api.response.timeseries.QueryResponse;
|
||||
import timely.util.JsonUtil;
|
||||
|
||||
public abstract class QueryBase extends MacITBase {
|
||||
public abstract class QueryBase extends InMemoryITBase {
|
||||
|
||||
public static class NotSuccessfulException extends Exception {
|
||||
|
||||
@@ -82,7 +82,7 @@ public abstract class QueryBase extends MacITBase {
|
||||
assertEquals(expectedResponseCode, responseCode);
|
||||
if (200 == responseCode) {
|
||||
String result = IOUtils.toString(con.getInputStream(), UTF_8);
|
||||
LOG.info("Result is {}", result);
|
||||
LOG.debug("Result is {}", result);
|
||||
return result;
|
||||
} else {
|
||||
throw new NotSuccessfulException();
|
||||
@@ -109,7 +109,7 @@ public abstract class QueryBase extends MacITBase {
|
||||
Assert.assertEquals(expectedResponseCode, responseCode);
|
||||
if (200 == responseCode) {
|
||||
String result = IOUtils.toString(con.getInputStream(), UTF_8);
|
||||
LOG.info("Result is {}", result);
|
||||
LOG.debug("Result is {}", result);
|
||||
JavaType type = JsonUtil.getObjectMapper().getTypeFactory().constructCollectionType(List.class,
|
||||
QueryResponse.class);
|
||||
return JsonUtil.getObjectMapper().readValue(result, type);
|
||||
@@ -138,7 +138,7 @@ public abstract class QueryBase extends MacITBase {
|
||||
Assert.assertEquals(expectedResponseCode, responseCode);
|
||||
if (200 == responseCode) {
|
||||
String result = IOUtils.toString(con.getInputStream(), UTF_8);
|
||||
LOG.info("Result is {}", result);
|
||||
LOG.debug("Result is {}", result);
|
||||
JavaType type = JsonUtil.getObjectMapper().getTypeFactory().constructCollectionType(List.class,
|
||||
QueryResponse.class);
|
||||
return JsonUtil.getObjectMapper().readValue(result, type);
|
||||
|
||||
@@ -2,23 +2,19 @@ package timely.test.integration;
|
||||
|
||||
import org.junit.*;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import timely.Server;
|
||||
import timely.test.IntegrationTest;
|
||||
|
||||
@Category(IntegrationTest.class)
|
||||
public class StaticFileServerIT extends OneWaySSLBase {
|
||||
|
||||
private static Server s = null;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
s = new Server(conf);
|
||||
s.run();
|
||||
public void startup() {
|
||||
startServer();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
s.shutdown();
|
||||
public void shutdown() {
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test(expected = NotSuccessfulException.class)
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
package timely.test.integration;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.cookie.ClientCookieDecoder;
|
||||
import io.netty.handler.codec.http.cookie.Cookie;
|
||||
import io.netty.handler.ssl.ApplicationProtocolConfig;
|
||||
import io.netty.handler.ssl.JdkSslContext;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.SslProvider;
|
||||
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.netty.Constants;
|
||||
|
||||
/**
|
||||
* Base test class for SSL with anonymous access
|
||||
*/
|
||||
public class TwoWaySSLBase extends QueryBase {
|
||||
|
||||
private static File clientTrustStoreFile;
|
||||
private static SelfSignedCertificate serverCert;
|
||||
|
||||
static {
|
||||
try {
|
||||
serverCert = new SelfSignedCertificate();
|
||||
clientTrustStoreFile = serverCert.certificate().getAbsoluteFile();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void startupTwoWaySSLBase() throws Exception {
|
||||
setupSSL(conf);
|
||||
}
|
||||
|
||||
public SelfSignedCertificate getServerCert() {
|
||||
return serverCert;
|
||||
}
|
||||
|
||||
protected File getClientTrustStoreFile() {
|
||||
return clientTrustStoreFile;
|
||||
}
|
||||
|
||||
protected SSLSocketFactory getSSLSocketFactory() throws Exception {
|
||||
SelfSignedCertificate serverCert = getServerCert();
|
||||
File clientTrustStoreFile = getClientTrustStoreFile();
|
||||
SslContextBuilder builder = SslContextBuilder.forClient();
|
||||
builder.applicationProtocolConfig(ApplicationProtocolConfig.DISABLED);
|
||||
// Use server cert / key on client side.
|
||||
builder.keyManager(serverCert.key(), (String) null, serverCert.cert());
|
||||
builder.sslProvider(SslProvider.JDK);
|
||||
builder.trustManager(clientTrustStoreFile); // Trust the server cert
|
||||
SslContext ctx = builder.build();
|
||||
Assert.assertTrue(ctx.isClient());
|
||||
Assert.assertTrue(ctx instanceof JdkSslContext);
|
||||
JdkSslContext jdk = (JdkSslContext) ctx;
|
||||
SSLContext jdkSslContext = jdk.context();
|
||||
return jdkSslContext.getSocketFactory();
|
||||
}
|
||||
|
||||
protected void setupSSL(Configuration config) {
|
||||
SelfSignedCertificate serverCert = getServerCert();
|
||||
config.getSecurity().getServerSsl().setCertificateFile(serverCert.certificate().getAbsolutePath());
|
||||
config.getSecurity().getServerSsl().setKeyFile(serverCert.privateKey().getAbsolutePath());
|
||||
// Needed for 2way SSL
|
||||
config.getSecurity().getServerSsl().setTrustStoreFile(serverCert.certificate().getAbsolutePath());
|
||||
config.getSecurity().getServerSsl().setUseOpenssl(false);
|
||||
config.getSecurity().getServerSsl().setUseGeneratedKeypair(false);
|
||||
config.getSecurity().setAllowAnonymousHttpAccess(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(URL url) throws Exception {
|
||||
// Username and password not used in 2way SSL case
|
||||
return getUrlConnection(null, null, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(String username, String password, URL url) throws Exception {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(getSSLSocketFactory());
|
||||
URL loginURL = new URL(url.getProtocol() + "://" + url.getHost() + ":" + url.getPort() + "/login");
|
||||
HttpsURLConnection con = (HttpsURLConnection) loginURL.openConnection();
|
||||
con.setHostnameVerifier((arg0, arg1) -> true);
|
||||
con.setRequestMethod("GET");
|
||||
con.setDoOutput(true);
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
con.connect();
|
||||
int responseCode = con.getResponseCode();
|
||||
if (401 == responseCode) {
|
||||
throw new UnauthorizedUserException();
|
||||
}
|
||||
Assert.assertEquals(200, responseCode);
|
||||
List<String> cookies = con.getHeaderFields().get(HttpHeaderNames.SET_COOKIE.toString());
|
||||
Assert.assertEquals(1, cookies.size());
|
||||
Cookie sessionCookie = ClientCookieDecoder.STRICT.decode(cookies.get(0));
|
||||
Assert.assertEquals(Constants.COOKIE_NAME, sessionCookie.name());
|
||||
con = (HttpsURLConnection) url.openConnection();
|
||||
con.setRequestProperty(HttpHeaderNames.COOKIE.toString(), sessionCookie.name() + "=" + sessionCookie.value());
|
||||
con.setHostnameVerifier((arg0, arg1) -> true);
|
||||
return con;
|
||||
}
|
||||
}
|
||||
@@ -1,175 +1,58 @@
|
||||
package timely.test.integration;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.cookie.ClientCookieDecoder;
|
||||
import io.netty.handler.codec.http.cookie.Cookie;
|
||||
import io.netty.handler.ssl.ApplicationProtocolConfig;
|
||||
import io.netty.handler.ssl.JdkSslContext;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.SslProvider;
|
||||
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
|
||||
import org.apache.accumulo.minicluster.MiniAccumuloConfig;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import timely.Server;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.netty.Constants;
|
||||
import timely.test.TestConfiguration;
|
||||
|
||||
public class TwoWaySSLFailureIT extends QueryBase {
|
||||
public class TwoWaySSLFailureIT extends TwoWaySSLBase {
|
||||
|
||||
@ClassRule
|
||||
public static final TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
private static MiniAccumuloCluster mac = null;
|
||||
private static Configuration conf = null;
|
||||
|
||||
private static SelfSignedCertificate serverCert = null;
|
||||
private static File clientTrustStoreFile = null;
|
||||
private static File clientTrustStoreFile;
|
||||
private static SelfSignedCertificate serverCert;
|
||||
|
||||
static {
|
||||
try {
|
||||
// This fqdn does not match what is in security.xml
|
||||
serverCert = new SelfSignedCertificate("CN=bad.example.com");
|
||||
clientTrustStoreFile = serverCert.certificate().getAbsoluteFile();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error creating self signed certificate", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected SSLSocketFactory getSSLSocketFactory() throws Exception {
|
||||
SslContextBuilder builder = SslContextBuilder.forClient();
|
||||
builder.applicationProtocolConfig(ApplicationProtocolConfig.DISABLED);
|
||||
// Use server cert / key on client side
|
||||
builder.keyManager(serverCert.key(), (String) null, serverCert.cert());
|
||||
builder.sslProvider(SslProvider.JDK);
|
||||
builder.trustManager(clientTrustStoreFile); // Trust the server cert
|
||||
SslContext ctx = builder.build();
|
||||
Assert.assertTrue(ctx.isClient());
|
||||
Assert.assertTrue(ctx instanceof JdkSslContext);
|
||||
JdkSslContext jdk = (JdkSslContext) ctx;
|
||||
SSLContext jdkSslContext = jdk.context();
|
||||
return jdkSslContext.getSocketFactory();
|
||||
public SelfSignedCertificate getServerCert() {
|
||||
return serverCert;
|
||||
}
|
||||
|
||||
protected static void setupSSL(Configuration config) throws Exception {
|
||||
config.getSecurity().getServerSsl().setCertificateFile(serverCert.certificate().getAbsolutePath());
|
||||
config.getSecurity().getServerSsl().setKeyFile(serverCert.privateKey().getAbsolutePath());
|
||||
// Needed for 2way SSL
|
||||
config.getSecurity().getServerSsl().setTrustStoreFile(serverCert.certificate().getAbsolutePath());
|
||||
config.getSecurity().getServerSsl().setUseOpenssl(false);
|
||||
config.getSecurity().getServerSsl().setUseGeneratedKeypair(false);
|
||||
config.getSecurity().setAllowAnonymousHttpAccess(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(URL url) throws Exception {
|
||||
// Username and password not used in 2way SSL case
|
||||
return getUrlConnection(null, null, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(String username, String password, URL url) throws Exception {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(getSSLSocketFactory());
|
||||
URL loginURL = new URL(url.getProtocol() + "://" + url.getHost() + ":" + url.getPort() + "/login");
|
||||
HttpsURLConnection con = (HttpsURLConnection) loginURL.openConnection();
|
||||
con.setHostnameVerifier(new HostnameVerifier() {
|
||||
|
||||
@Override
|
||||
public boolean verify(String arg0, SSLSession arg1) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
con.setRequestMethod("GET");
|
||||
con.setDoOutput(true);
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
con.connect();
|
||||
int responseCode = con.getResponseCode();
|
||||
if (401 == responseCode) {
|
||||
throw new UnauthorizedUserException();
|
||||
}
|
||||
Assert.assertEquals(200, responseCode);
|
||||
List<String> cookies = con.getHeaderFields().get(HttpHeaderNames.SET_COOKIE.toString());
|
||||
Assert.assertEquals(1, cookies.size());
|
||||
Cookie sessionCookie = ClientCookieDecoder.STRICT.decode(cookies.get(0));
|
||||
Assert.assertEquals(Constants.COOKIE_NAME, sessionCookie.name());
|
||||
con = (HttpsURLConnection) url.openConnection();
|
||||
con.setRequestProperty(HttpHeaderNames.COOKIE.toString(), sessionCookie.name() + "=" + sessionCookie.value());
|
||||
con.setHostnameVerifier(new HostnameVerifier() {
|
||||
|
||||
@Override
|
||||
public boolean verify(String arg0, SSLSession arg1) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return con;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
temp.create();
|
||||
final MiniAccumuloConfig macConfig = new MiniAccumuloConfig(temp.newFolder("mac"), "secret");
|
||||
mac = new MiniAccumuloCluster(macConfig);
|
||||
mac.start();
|
||||
conf = TestConfiguration.createMinimalConfigurationForTest();
|
||||
conf.getAccumulo().setInstanceName(mac.getInstanceName());
|
||||
conf.getAccumulo().setZookeepers(mac.getZooKeepers());
|
||||
setupSSL(conf);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
mac.stop();
|
||||
protected File getClientTrustStoreFile() {
|
||||
return clientTrustStoreFile;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Connector con = mac.getConnector("root", "secret");
|
||||
con.tableOperations().list().forEach(t -> {
|
||||
accumuloClient.tableOperations().list().forEach(t -> {
|
||||
if (t.startsWith("timely")) {
|
||||
try {
|
||||
con.tableOperations().delete(t);
|
||||
accumuloClient.tableOperations().delete(t);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
startServer();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
AuthCache.resetConfiguration();
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test(expected = UnauthorizedUserException.class)
|
||||
public void testBasicAuthLoginFailure() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query(metrics);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query(metrics);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,45 +3,20 @@ package timely.test.integration;
|
||||
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.cookie.ClientCookieDecoder;
|
||||
import io.netty.handler.codec.http.cookie.Cookie;
|
||||
import io.netty.handler.ssl.ApplicationProtocolConfig;
|
||||
import io.netty.handler.ssl.JdkSslContext;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.SslProvider;
|
||||
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.apache.accumulo.minicluster.MiniAccumuloCluster;
|
||||
import org.apache.accumulo.minicluster.MiniAccumuloConfig;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import timely.Server;
|
||||
import timely.api.request.timeseries.QueryRequest;
|
||||
import timely.api.response.timeseries.QueryResponse;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.netty.Constants;
|
||||
import timely.test.IntegrationTest;
|
||||
import timely.test.TestConfiguration;
|
||||
|
||||
@@ -51,108 +26,18 @@ import timely.test.TestConfiguration;
|
||||
*
|
||||
*/
|
||||
@Category(IntegrationTest.class)
|
||||
public class TwoWaySSLIT extends QueryBase {
|
||||
public class TwoWaySSLIT extends TwoWaySSLBase {
|
||||
|
||||
private static final Long TEST_TIME = System.currentTimeMillis();
|
||||
|
||||
@ClassRule
|
||||
public static final TemporaryFolder temp = new TemporaryFolder();
|
||||
|
||||
private static MiniAccumuloCluster mac = null;
|
||||
private static Configuration conf = null;
|
||||
|
||||
protected static SelfSignedCertificate serverCert = null;
|
||||
protected static File clientTrustStoreFile = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
serverCert = new SelfSignedCertificate();
|
||||
clientTrustStoreFile = serverCert.certificate().getAbsoluteFile();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error creating self signed certificate", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected SSLSocketFactory getSSLSocketFactory() throws Exception {
|
||||
SslContextBuilder builder = SslContextBuilder.forClient();
|
||||
builder.applicationProtocolConfig(ApplicationProtocolConfig.DISABLED);
|
||||
// Use server cert / key on client side.
|
||||
builder.keyManager(serverCert.key(), (String) null, serverCert.cert());
|
||||
builder.sslProvider(SslProvider.JDK);
|
||||
builder.trustManager(clientTrustStoreFile); // Trust the server cert
|
||||
SslContext ctx = builder.build();
|
||||
Assert.assertTrue(ctx.isClient());
|
||||
Assert.assertTrue(ctx instanceof JdkSslContext);
|
||||
JdkSslContext jdk = (JdkSslContext) ctx;
|
||||
SSLContext jdkSslContext = jdk.context();
|
||||
return jdkSslContext.getSocketFactory();
|
||||
}
|
||||
|
||||
protected static void setupSSL(Configuration config) throws Exception {
|
||||
config.getSecurity().getServerSsl().setCertificateFile(serverCert.certificate().getAbsolutePath());
|
||||
config.getSecurity().getServerSsl().setKeyFile(serverCert.privateKey().getAbsolutePath());
|
||||
// Needed for 2way SSL
|
||||
config.getSecurity().getServerSsl().setTrustStoreFile(serverCert.certificate().getAbsolutePath());
|
||||
config.getSecurity().getServerSsl().setUseOpenssl(false);
|
||||
config.getSecurity().getServerSsl().setUseGeneratedKeypair(false);
|
||||
config.getSecurity().setAllowAnonymousHttpAccess(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(URL url) throws Exception {
|
||||
// Username and password not used in 2way SSL case
|
||||
return getUrlConnection(null, null, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(String username, String password, URL url) throws Exception {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(getSSLSocketFactory());
|
||||
URL loginURL = new URL(url.getProtocol() + "://" + url.getHost() + ":" + url.getPort() + "/login");
|
||||
HttpsURLConnection con = (HttpsURLConnection) loginURL.openConnection();
|
||||
con.setHostnameVerifier((host, session) -> true);
|
||||
con.setRequestMethod("GET");
|
||||
con.setDoOutput(true);
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
con.connect();
|
||||
int responseCode = con.getResponseCode();
|
||||
if (401 == responseCode) {
|
||||
throw new UnauthorizedUserException();
|
||||
}
|
||||
Assert.assertEquals(200, responseCode);
|
||||
List<String> cookies = con.getHeaderFields().get(HttpHeaderNames.SET_COOKIE.toString());
|
||||
Assert.assertEquals(1, cookies.size());
|
||||
Cookie sessionCookie = ClientCookieDecoder.STRICT.decode(cookies.get(0));
|
||||
Assert.assertEquals(Constants.COOKIE_NAME, sessionCookie.name());
|
||||
con = (HttpsURLConnection) url.openConnection();
|
||||
con.setRequestProperty(HttpHeaderNames.COOKIE.toString(), sessionCookie.name() + "=" + sessionCookie.value());
|
||||
con.setHostnameVerifier((host, session) -> true);
|
||||
return con;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClass() throws Exception {
|
||||
final MiniAccumuloConfig macConfig = new MiniAccumuloConfig(temp.newFolder("mac"), "secret");
|
||||
mac = new MiniAccumuloCluster(macConfig);
|
||||
mac.start();
|
||||
conf = TestConfiguration.createMinimalConfigurationForTest();
|
||||
conf.getAccumulo().setInstanceName(mac.getInstanceName());
|
||||
conf.getAccumulo().setZookeepers(mac.getZooKeepers());
|
||||
setupSSL(conf);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClass() throws Exception {
|
||||
mac.stop();
|
||||
}
|
||||
private static final Long TEST_TIME = (System.currentTimeMillis() / 1000) * 1000;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Connector con = mac.getConnector("root", "secret");
|
||||
con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
con.tableOperations().list().forEach(t -> {
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root",
|
||||
new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
accumuloClient.tableOperations().list().forEach(t -> {
|
||||
if (t.startsWith("timely")) {
|
||||
try {
|
||||
con.tableOperations().delete(t);
|
||||
accumuloClient.tableOperations().delete(t);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
@@ -166,58 +51,52 @@ public class TwoWaySSLIT extends QueryBase {
|
||||
|
||||
@Test
|
||||
public void testBasicAuthLogin() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query(metrics);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
startServer();
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query(metrics);
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithVisibilityWithoutCache() throws Exception {
|
||||
conf.getCache().setEnabled(false);
|
||||
startServer();
|
||||
testQueryWithVisibility(conf);
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithVisibilityWithCache() throws Exception {
|
||||
conf.getCache().setEnabled(true);
|
||||
startServer();
|
||||
testQueryWithVisibility(conf);
|
||||
stopServer();
|
||||
}
|
||||
|
||||
public void testQueryWithVisibility(Configuration conf) throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
// @formatter:off
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 1000) + " 2.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 2000) + " 3.0 tag1=value1 tag3=value3 viz=A",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 4.0 tag1=value1 tag3=value3 viz=D",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 5.0 tag1=value1 tag3=value3 viz=G");
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + 6000);
|
||||
QueryRequest.SubQuery subQuery = new QueryRequest.SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
// @formatter:on
|
||||
// @formatter:off
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 1000) + " 2.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 2000) + " 3.0 tag1=value1 tag3=value3 viz=A",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 4.0 tag1=value1 tag3=value3 viz=D",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 5.0 tag1=value1 tag3=value3 viz=G");
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + 6000);
|
||||
QueryRequest.SubQuery subQuery = new QueryRequest.SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
// @formatter:on
|
||||
|
||||
String metrics = "https://127.0.0.1:54322/api/query";
|
||||
List<QueryResponse> response = query(metrics, request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(0, tags.size());
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(3, dps.size());
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
String metrics = "https://127.0.0.1:54322/api/query";
|
||||
List<QueryResponse> response = query(metrics, request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(0, tags.size());
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(3, dps.size());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,41 +3,19 @@ package timely.test.integration;
|
||||
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.SSLSession;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import io.netty.handler.codec.http.cookie.ClientCookieDecoder;
|
||||
import io.netty.handler.codec.http.cookie.Cookie;
|
||||
import io.netty.handler.ssl.ApplicationProtocolConfig;
|
||||
import io.netty.handler.ssl.JdkSslContext;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.SslProvider;
|
||||
import io.netty.handler.ssl.util.SelfSignedCertificate;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import timely.Server;
|
||||
import timely.api.request.timeseries.QueryRequest;
|
||||
import timely.api.response.timeseries.QueryResponse;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.configuration.Configuration;
|
||||
import timely.netty.Constants;
|
||||
import timely.test.IntegrationTest;
|
||||
import timely.test.TestConfiguration;
|
||||
|
||||
@@ -48,146 +26,51 @@ import timely.test.TestConfiguration;
|
||||
*
|
||||
*/
|
||||
@Category(IntegrationTest.class)
|
||||
public class TwoWaySSLOpenSSLIT extends QueryBase {
|
||||
public class TwoWaySSLOpenSSLIT extends TwoWaySSLBase {
|
||||
|
||||
private static final Long TEST_TIME = System.currentTimeMillis();
|
||||
|
||||
protected static SelfSignedCertificate serverCert = null;
|
||||
protected static File clientTrustStoreFile = null;
|
||||
|
||||
static {
|
||||
try {
|
||||
serverCert = new SelfSignedCertificate();
|
||||
clientTrustStoreFile = serverCert.certificate().getAbsoluteFile();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Error creating self signed certificate", e);
|
||||
}
|
||||
}
|
||||
|
||||
protected SSLSocketFactory getSSLSocketFactory() throws Exception {
|
||||
SslContextBuilder builder = SslContextBuilder.forClient();
|
||||
builder.applicationProtocolConfig(ApplicationProtocolConfig.DISABLED);
|
||||
// Use server cert / key on client side.
|
||||
builder.keyManager(serverCert.key(), (String) null, serverCert.cert());
|
||||
builder.sslProvider(SslProvider.JDK);
|
||||
builder.trustManager(clientTrustStoreFile); // Trust the server cert
|
||||
SslContext ctx = builder.build();
|
||||
Assert.assertTrue(ctx.isClient());
|
||||
Assert.assertTrue(ctx instanceof JdkSslContext);
|
||||
JdkSslContext jdk = (JdkSslContext) ctx;
|
||||
SSLContext jdkSslContext = jdk.context();
|
||||
return jdkSslContext.getSocketFactory();
|
||||
}
|
||||
|
||||
protected static void setupSSL(Configuration config) throws Exception {
|
||||
config.getSecurity().getServerSsl().setCertificateFile(serverCert.certificate().getAbsolutePath());
|
||||
config.getSecurity().getServerSsl().setKeyFile(serverCert.privateKey().getAbsolutePath());
|
||||
// Needed for 2way SSL
|
||||
config.getSecurity().getServerSsl().setTrustStoreFile(serverCert.certificate().getAbsolutePath());
|
||||
config.getSecurity().getServerSsl().setUseOpenssl(false);
|
||||
config.getSecurity().getServerSsl().setUseGeneratedKeypair(false);
|
||||
config.getSecurity().setAllowAnonymousHttpAccess(false);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void configureSSL() throws Exception {
|
||||
setupSSL(conf);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(URL url) throws Exception {
|
||||
// Username and password not used in 2way SSL case
|
||||
return getUrlConnection(null, null, url);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HttpsURLConnection getUrlConnection(String username, String password, URL url) throws Exception {
|
||||
HttpsURLConnection.setDefaultSSLSocketFactory(getSSLSocketFactory());
|
||||
URL loginURL = new URL(url.getProtocol() + "://" + url.getHost() + ":" + url.getPort() + "/login");
|
||||
HttpsURLConnection con = (HttpsURLConnection) loginURL.openConnection();
|
||||
con.setHostnameVerifier(new HostnameVerifier() {
|
||||
|
||||
@Override
|
||||
public boolean verify(String arg0, SSLSession arg1) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
con.setRequestMethod("GET");
|
||||
con.setDoOutput(true);
|
||||
con.setRequestProperty("Content-Type", "application/json");
|
||||
con.connect();
|
||||
int responseCode = con.getResponseCode();
|
||||
if (401 == responseCode) {
|
||||
throw new UnauthorizedUserException();
|
||||
}
|
||||
Assert.assertEquals(200, responseCode);
|
||||
List<String> cookies = con.getHeaderFields().get(HttpHeaderNames.SET_COOKIE.toString());
|
||||
Assert.assertEquals(1, cookies.size());
|
||||
Cookie sessionCookie = ClientCookieDecoder.STRICT.decode(cookies.get(0));
|
||||
Assert.assertEquals(Constants.COOKIE_NAME, sessionCookie.name());
|
||||
con = (HttpsURLConnection) url.openConnection();
|
||||
con.setRequestProperty(HttpHeaderNames.COOKIE.toString(), sessionCookie.name() + "=" + sessionCookie.value());
|
||||
con.setHostnameVerifier(new HostnameVerifier() {
|
||||
|
||||
@Override
|
||||
public boolean verify(String arg0, SSLSession arg1) {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return con;
|
||||
}
|
||||
private static final Long TEST_TIME = (System.currentTimeMillis() / 1000) * 1000;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Connector con = mac.getConnector("root", "secret");
|
||||
con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root",
|
||||
new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
startServer();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
AuthCache.resetConfiguration();
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicAuthLogin() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query(metrics);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
String metrics = "https://localhost:54322/api/metrics";
|
||||
query(metrics);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testQueryWithVisibility() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 1000) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 2000) + " 2.0 tag1=value1 tag3=value3 viz=A",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 2.0 tag1=value1 tag3=value3 viz=D",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 2.0 tag1=value1 tag3=value3 viz=G");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + 6000);
|
||||
QueryRequest.SubQuery subQuery = new QueryRequest.SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
String metrics = "https://127.0.0.1:54322/api/query";
|
||||
List<QueryResponse> response = query(metrics, request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(0, tags.size());
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(3, dps.size());
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 1000) + " 3.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.user " + (TEST_TIME + 2000) + " 2.0 tag1=value1 tag3=value3 viz=A",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 2.0 tag1=value1 tag3=value3 viz=D",
|
||||
"sys.cpu.user " + (TEST_TIME + 3000) + " 2.0 tag1=value1 tag3=value3 viz=G");
|
||||
// Latency in TestConfiguration is 2s, wait for it
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
QueryRequest request = new QueryRequest();
|
||||
request.setStart(TEST_TIME);
|
||||
request.setEnd(TEST_TIME + 6000);
|
||||
QueryRequest.SubQuery subQuery = new QueryRequest.SubQuery();
|
||||
subQuery.setMetric("sys.cpu.user");
|
||||
subQuery.setDownsample(Optional.of("1s-max"));
|
||||
request.addQuery(subQuery);
|
||||
String metrics = "https://127.0.0.1:54322/api/query";
|
||||
List<QueryResponse> response = query(metrics, request);
|
||||
assertEquals(1, response.size());
|
||||
Map<String, String> tags = response.get(0).getTags();
|
||||
assertEquals(0, tags.size());
|
||||
Map<String, Object> dps = response.get(0).getDps();
|
||||
assertEquals(3, dps.size());
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package timely.test.integration.client;
|
||||
|
||||
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static timely.test.TestConfiguration.WAIT_SECONDS;
|
||||
@@ -12,9 +11,6 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
|
||||
@@ -25,7 +21,6 @@ import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.Server;
|
||||
import timely.TestServer;
|
||||
import timely.api.request.MetricRequest;
|
||||
import timely.auth.AuthCache;
|
||||
@@ -39,7 +34,7 @@ import timely.test.integration.OneWaySSLBase;
|
||||
public class TcpClientIT extends OneWaySSLBase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TcpClientIT.class);
|
||||
private static final Long TEST_TIME = System.currentTimeMillis();
|
||||
private static final Long TEST_TIME = (System.currentTimeMillis() / 1000) * 1000;
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
@@ -48,7 +43,7 @@ public class TcpClientIT extends OneWaySSLBase {
|
||||
|
||||
@Test
|
||||
public void testPut() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (TcpClient client = new TcpClient("127.0.0.1", 54321)) {
|
||||
client.open();
|
||||
@@ -79,7 +74,7 @@ public class TcpClientIT extends OneWaySSLBase {
|
||||
@Test
|
||||
public void testPutMultiple() throws Exception {
|
||||
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (TcpClient client = new TcpClient("127.0.0.1", 54321)) {
|
||||
client.open();
|
||||
@@ -123,7 +118,7 @@ public class TcpClientIT extends OneWaySSLBase {
|
||||
|
||||
@Test
|
||||
public void testPutInvalidTimestamp() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (TcpClient client = new TcpClient("127.0.0.1", 54321)) {
|
||||
client.open();
|
||||
@@ -138,90 +133,85 @@ public class TcpClientIT extends OneWaySSLBase {
|
||||
|
||||
@Test
|
||||
public void testPersistence() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
startServer();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME + 1) + " 1.0 tag3=value3 tag4=value4",
|
||||
"sys.cpu.idle " + (TEST_TIME + 2) + " 1.0 tag3=value3 tag4=value4");
|
||||
sleepUninterruptibly(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
assertTrue(accumuloClient.namespaceOperations().exists("timely"));
|
||||
assertTrue(accumuloClient.tableOperations().exists("timely.metrics"));
|
||||
assertTrue(accumuloClient.tableOperations().exists("timely.meta"));
|
||||
int count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta entry: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(10, count);
|
||||
// count w/out versioning iterator to make sure that the optimization
|
||||
// for writing is working
|
||||
accumuloClient.tableOperations().removeIterator("timely.meta", "vers", EnumSet.of(IteratorScope.scan));
|
||||
// wait for zookeeper propagation
|
||||
sleepUninterruptibly(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta no vers iter: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(15, count);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
stopServer();
|
||||
}
|
||||
final ZooKeeperInstance inst = new ZooKeeperInstance(mac.getClientConfig());
|
||||
final Connector connector = inst.getConnector("root", new PasswordToken("secret".getBytes(UTF_8)));
|
||||
assertTrue(connector.namespaceOperations().exists("timely"));
|
||||
assertTrue(connector.tableOperations().exists("timely.metrics"));
|
||||
assertTrue(connector.tableOperations().exists("timely.meta"));
|
||||
int count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta entry: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(10, count);
|
||||
// count w/out versioning iterator to make sure that the optimization
|
||||
// for writing is working
|
||||
connector.tableOperations().removeIterator("timely.meta", "vers", EnumSet.of(IteratorScope.scan));
|
||||
// wait for zookeeper propagation
|
||||
sleepUninterruptibly(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta no vers iter: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(15, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistenceWithVisibility() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
startServer();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME + 1) + " 1.0 tag3=value3 tag4=value4 viz=(a|b)",
|
||||
"sys.cpu.idle " + (TEST_TIME + 2) + " 1.0 tag3=value3 tag4=value4 viz=(c&b)");
|
||||
sleepUninterruptibly(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
final ZooKeeperInstance inst = new ZooKeeperInstance(mac.getClientConfig());
|
||||
final Connector connector = inst.getConnector("root", new PasswordToken("secret".getBytes(UTF_8)));
|
||||
connector.securityOperations().changeUserAuthorizations("root", new Authorizations("a", "b", "c"));
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root", new Authorizations("a", "b", "c"));
|
||||
|
||||
int count = 0;
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
int count = 0;
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics",
|
||||
Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(2, count);
|
||||
count = 0;
|
||||
Authorizations auth1 = new Authorizations("a");
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", auth1)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(4, count);
|
||||
count = 0;
|
||||
Authorizations auth2 = new Authorizations("b", "c");
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", auth2)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
} finally {
|
||||
stopServer();
|
||||
}
|
||||
assertEquals(2, count);
|
||||
count = 0;
|
||||
Authorizations auth1 = new Authorizations("a");
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", auth1)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(4, count);
|
||||
count = 0;
|
||||
Authorizations auth2 = new Authorizations("b", "c");
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", auth2)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
}
|
||||
|
||||
protected void put(String... lines) throws Exception {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package timely.test.integration.client;
|
||||
|
||||
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -11,9 +10,6 @@ import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
|
||||
@@ -25,7 +21,6 @@ import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.Server;
|
||||
import timely.TestServer;
|
||||
import timely.api.request.MetricRequest;
|
||||
import timely.auth.AuthCache;
|
||||
@@ -34,21 +29,20 @@ import timely.model.Metric;
|
||||
import timely.model.Tag;
|
||||
import timely.test.IntegrationTest;
|
||||
import timely.test.TestConfiguration;
|
||||
import timely.test.integration.MacITBase;
|
||||
import timely.test.integration.InMemoryITBase;
|
||||
|
||||
@Category(IntegrationTest.class)
|
||||
public class UdpClientIT extends MacITBase {
|
||||
public class UdpClientIT extends InMemoryITBase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(UdpClientIT.class);
|
||||
private static final Long TEST_TIME = System.currentTimeMillis();
|
||||
private static final Long TEST_TIME = (System.currentTimeMillis() / 1000) * 1000;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Connector con = mac.getConnector("root", "secret");
|
||||
con.tableOperations().list().forEach(t -> {
|
||||
accumuloClient.tableOperations().list().forEach(t -> {
|
||||
if (t.startsWith("timely")) {
|
||||
try {
|
||||
con.tableOperations().delete(t);
|
||||
accumuloClient.tableOperations().delete(t);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
@@ -62,7 +56,7 @@ public class UdpClientIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPut() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (UdpClient client = new UdpClient("127.0.0.1", 54325)) {
|
||||
client.open();
|
||||
@@ -92,7 +86,7 @@ public class UdpClientIT extends MacITBase {
|
||||
@Test
|
||||
public void testPutMultiple() throws Exception {
|
||||
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (UdpClient client = new UdpClient("127.0.0.1", 54325)) {
|
||||
client.open();
|
||||
@@ -134,7 +128,7 @@ public class UdpClientIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPutInvalidTimestamp() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (UdpClient client = new UdpClient("127.0.0.1", 54325)) {
|
||||
client.open();
|
||||
@@ -148,90 +142,79 @@ public class UdpClientIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPersistence() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
startServer();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME + 1) + " 1.0 tag3=value3 tag4=value4",
|
||||
"sys.cpu.idle " + (TEST_TIME + 2) + " 1.0 tag3=value3 tag4=value4");
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
assertTrue(accumuloClient.namespaceOperations().exists("timely"));
|
||||
assertTrue(accumuloClient.tableOperations().exists("timely.metrics"));
|
||||
assertTrue(accumuloClient.tableOperations().exists("timely.meta"));
|
||||
int count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
count++;
|
||||
}
|
||||
assertEquals(10, count);
|
||||
// count w/out versioning iterator to make sure that the optimization
|
||||
// for writing is working
|
||||
accumuloClient.tableOperations().removeIterator("timely.meta", "vers", EnumSet.of(IteratorScope.scan));
|
||||
// wait for zookeeper propagation
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
count++;
|
||||
}
|
||||
assertEquals(15, count);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
stopServer();
|
||||
}
|
||||
final ZooKeeperInstance inst = new ZooKeeperInstance(mac.getClientConfig());
|
||||
final Connector connector = inst.getConnector("root", new PasswordToken("secret".getBytes(UTF_8)));
|
||||
assertTrue(connector.namespaceOperations().exists("timely"));
|
||||
assertTrue(connector.tableOperations().exists("timely.metrics"));
|
||||
assertTrue(connector.tableOperations().exists("timely.meta"));
|
||||
int count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta entry: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(10, count);
|
||||
// count w/out versioning iterator to make sure that the optimization
|
||||
// for writing is working
|
||||
connector.tableOperations().removeIterator("timely.meta", "vers", EnumSet.of(IteratorScope.scan));
|
||||
// wait for zookeeper propagation
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta no vers iter: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(15, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistenceWithVisibility() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
startServer();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME + 1) + " 1.0 tag3=value3 tag4=value4 viz=(a|b)",
|
||||
"sys.cpu.idle " + (TEST_TIME + 2) + " 1.0 tag3=value3 tag4=value4 viz=(c&b)");
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
final ZooKeeperInstance inst = new ZooKeeperInstance(mac.getClientConfig());
|
||||
final Connector connector = inst.getConnector("root", new PasswordToken("secret".getBytes(UTF_8)));
|
||||
connector.securityOperations().changeUserAuthorizations("root", new Authorizations("a", "b", "c"));
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root", new Authorizations("a", "b", "c"));
|
||||
|
||||
int count = 0;
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
int count = 0;
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics",
|
||||
Authorizations.EMPTY)) {
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(2, count);
|
||||
count = 0;
|
||||
Authorizations auth1 = new Authorizations("a");
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", auth1)) {
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(4, count);
|
||||
count = 0;
|
||||
Authorizations auth2 = new Authorizations("b", "c");
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", auth2)) {
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
} finally {
|
||||
stopServer();
|
||||
}
|
||||
assertEquals(2, count);
|
||||
count = 0;
|
||||
Authorizations auth1 = new Authorizations("a");
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", auth1)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(4, count);
|
||||
count = 0;
|
||||
Authorizations auth2 = new Authorizations("b", "c");
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", auth2)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
}
|
||||
|
||||
private void put(String... lines) throws Exception {
|
||||
|
||||
@@ -17,7 +17,6 @@ import io.netty.handler.ssl.JdkSslContext;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.SslProvider;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.apache.http.client.HttpResponseException;
|
||||
import org.junit.After;
|
||||
@@ -27,7 +26,6 @@ import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.Server;
|
||||
import timely.api.response.MetricResponses;
|
||||
import timely.auth.AuthCache;
|
||||
import timely.client.websocket.ClientHandler;
|
||||
@@ -41,10 +39,9 @@ import timely.test.integration.OneWaySSLBase;
|
||||
public class WebSocketClientIT extends OneWaySSLBase {
|
||||
|
||||
private final static Logger LOG = LoggerFactory.getLogger(WebSocketClientIT.class);
|
||||
private static final Long TEST_TIME = System.currentTimeMillis() - (240 * 1000);
|
||||
private static final Long TEST_TIME = ((System.currentTimeMillis() / 1000) * 1000) - (240 * 1000);
|
||||
|
||||
private static SSLContext sslCtx = null;
|
||||
private Server s = null;
|
||||
|
||||
private void setupSslCtx() throws Exception {
|
||||
Assert.assertNotNull(clientTrustStoreFile);
|
||||
@@ -61,18 +58,16 @@ public class WebSocketClientIT extends OneWaySSLBase {
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Connector con = mac.getConnector("root", "secret");
|
||||
con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
s = new Server(conf);
|
||||
s.run();
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root",
|
||||
new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
setupSslCtx();
|
||||
startServer();
|
||||
}
|
||||
|
||||
@Override
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
s.shutdown();
|
||||
AuthCache.resetConfiguration();
|
||||
stopServer();
|
||||
}
|
||||
|
||||
public void testWorkflow(WebSocketSubscriptionClient client) throws Exception {
|
||||
@@ -143,12 +138,8 @@ public class WebSocketClientIT extends OneWaySSLBase {
|
||||
public void testClientAnonymousAccess() throws Exception {
|
||||
WebSocketSubscriptionClient client = new WebSocketSubscriptionClient(sslCtx, "localhost", 54322, 54323, false,
|
||||
false, null, null, false, 65536);
|
||||
try {
|
||||
conf.getSecurity().setAllowAnonymousWsAccess(true);
|
||||
testWorkflow(client);
|
||||
} finally {
|
||||
conf.getSecurity().setAllowAnonymousWsAccess(false);
|
||||
}
|
||||
conf.getSecurity().setAllowAnonymousWsAccess(true);
|
||||
testWorkflow(client);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+7
-9
@@ -8,9 +8,10 @@ import java.net.URL;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import io.netty.handler.codec.http.HttpHeaderNames;
|
||||
import org.junit.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import timely.Server;
|
||||
import timely.netty.http.StrictTransportHandler;
|
||||
import timely.test.IntegrationTest;
|
||||
import timely.test.integration.OneWaySSLBase;
|
||||
@@ -18,17 +19,14 @@ import timely.test.integration.OneWaySSLBase;
|
||||
@Category(IntegrationTest.class)
|
||||
public class HTTPStrictTransportSecurityIT extends OneWaySSLBase {
|
||||
|
||||
private static Server s = null;
|
||||
|
||||
@Before
|
||||
public void before() throws Exception {
|
||||
s = new Server(conf);
|
||||
s.run();
|
||||
public void startup() {
|
||||
startServer();
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() throws Exception {
|
||||
s.shutdown();
|
||||
public void shutdown() {
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,7 +1,6 @@
|
||||
package timely.test.integration.tcp;
|
||||
|
||||
import static com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static timely.test.TestConfiguration.WAIT_SECONDS;
|
||||
@@ -18,18 +17,16 @@ import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.junit.*;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.Server;
|
||||
import timely.TestServer;
|
||||
import timely.api.request.MetricRequest;
|
||||
import timely.api.request.VersionRequest;
|
||||
@@ -37,16 +34,16 @@ import timely.auth.AuthCache;
|
||||
import timely.model.Metric;
|
||||
import timely.model.Tag;
|
||||
import timely.test.IntegrationTest;
|
||||
import timely.test.integration.MacITBase;
|
||||
import timely.test.integration.InMemoryITBase;
|
||||
|
||||
/**
|
||||
* Integration tests for the operations available over the TCP transport
|
||||
*/
|
||||
@Category(IntegrationTest.class)
|
||||
public class TimelyTcpIT extends MacITBase {
|
||||
public class TimelyTcpIT extends InMemoryITBase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TimelyTcpIT.class);
|
||||
private static final Long TEST_TIME = System.currentTimeMillis();
|
||||
private static final Long TEST_TIME = (System.currentTimeMillis() / 1000) * 1000;
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
@@ -55,7 +52,7 @@ public class TimelyTcpIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testVersion() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (Socket sock = new Socket("127.0.0.1", 54321);
|
||||
PrintWriter writer = new PrintWriter(sock.getOutputStream(), true);) {
|
||||
@@ -75,7 +72,7 @@ public class TimelyTcpIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPut() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (Socket sock = new Socket("127.0.0.1", 54321);
|
||||
PrintWriter writer = new PrintWriter(sock.getOutputStream(), true);) {
|
||||
@@ -106,7 +103,7 @@ public class TimelyTcpIT extends MacITBase {
|
||||
@Test
|
||||
public void testPutMultiple() throws Exception {
|
||||
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (Socket sock = new Socket("127.0.0.1", 54321);
|
||||
PrintWriter writer = new PrintWriter(sock.getOutputStream(), true)) {
|
||||
@@ -189,7 +186,7 @@ public class TimelyTcpIT extends MacITBase {
|
||||
binary.get(data, 0, binary.remaining());
|
||||
LOG.debug("Sending {} bytes", data.length);
|
||||
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (Socket sock = new Socket("127.0.0.1", 54321);) {
|
||||
sock.getOutputStream().write(data);
|
||||
@@ -232,7 +229,7 @@ public class TimelyTcpIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPutInvalidTimestamp() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
try (Socket sock = new Socket("127.0.0.1", 54321);
|
||||
PrintWriter writer = new PrintWriter(sock.getOutputStream(), true);
|
||||
@@ -248,90 +245,85 @@ public class TimelyTcpIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPersistence() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
startServer();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME + 1) + " 1.0 tag3=value3 tag4=value4",
|
||||
"sys.cpu.idle " + (TEST_TIME + 2) + " 1.0 tag3=value3 tag4=value4");
|
||||
sleepUninterruptibly(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
assertTrue(accumuloClient.namespaceOperations().exists("timely"));
|
||||
assertTrue(accumuloClient.tableOperations().exists("timely.metrics"));
|
||||
assertTrue(accumuloClient.tableOperations().exists("timely.meta"));
|
||||
int count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta entry: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(10, count);
|
||||
// count w/out versioning iterator to make sure that the optimization
|
||||
// for writing is working
|
||||
accumuloClient.tableOperations().removeIterator("timely.meta", "vers", EnumSet.of(IteratorScope.scan));
|
||||
// wait for zookeeper propagation
|
||||
sleepUninterruptibly(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta no vers iter: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(15, count);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
stopServer();
|
||||
}
|
||||
final ZooKeeperInstance inst = new ZooKeeperInstance(mac.getClientConfig());
|
||||
final Connector connector = inst.getConnector("root", new PasswordToken("secret".getBytes(UTF_8)));
|
||||
assertTrue(connector.namespaceOperations().exists("timely"));
|
||||
assertTrue(connector.tableOperations().exists("timely.metrics"));
|
||||
assertTrue(connector.tableOperations().exists("timely.meta"));
|
||||
int count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta entry: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(10, count);
|
||||
// count w/out versioning iterator to make sure that the optimization
|
||||
// for writing is working
|
||||
connector.tableOperations().removeIterator("timely.meta", "vers", EnumSet.of(IteratorScope.scan));
|
||||
// wait for zookeeper propagation
|
||||
sleepUninterruptibly(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta no vers iter: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(15, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistenceWithVisibility() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
startServer();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME + 1) + " 1.0 tag3=value3 tag4=value4 viz=(a|b)",
|
||||
"sys.cpu.idle " + (TEST_TIME + 2) + " 1.0 tag3=value3 tag4=value4 viz=(c&b)");
|
||||
sleepUninterruptibly(WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
final ZooKeeperInstance inst = new ZooKeeperInstance(mac.getClientConfig());
|
||||
final Connector connector = inst.getConnector("root", new PasswordToken("secret".getBytes(UTF_8)));
|
||||
connector.securityOperations().changeUserAuthorizations("root", new Authorizations("a", "b", "c"));
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root", new Authorizations("a", "b", "c"));
|
||||
|
||||
int count = 0;
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
int count = 0;
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics",
|
||||
Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(2, count);
|
||||
count = 0;
|
||||
Authorizations auth1 = new Authorizations("a");
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", auth1)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(4, count);
|
||||
count = 0;
|
||||
Authorizations auth2 = new Authorizations("b", "c");
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", auth2)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
} finally {
|
||||
stopServer();
|
||||
}
|
||||
assertEquals(2, count);
|
||||
count = 0;
|
||||
Authorizations auth1 = new Authorizations("a");
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", auth1)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(4, count);
|
||||
count = 0;
|
||||
Authorizations auth2 = new Authorizations("b", "c");
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", auth2)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
}
|
||||
|
||||
private void put(String... lines) throws Exception {
|
||||
|
||||
@@ -16,9 +16,6 @@ import java.util.Map.Entry;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.flatbuffers.FlatBufferBuilder;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.client.ZooKeeperInstance;
|
||||
import org.apache.accumulo.core.client.security.tokens.PasswordToken;
|
||||
import org.apache.accumulo.core.data.Key;
|
||||
import org.apache.accumulo.core.data.Value;
|
||||
import org.apache.accumulo.core.iterators.IteratorUtil.IteratorScope;
|
||||
@@ -30,7 +27,6 @@ import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import timely.Server;
|
||||
import timely.TestServer;
|
||||
import timely.api.request.MetricRequest;
|
||||
import timely.auth.AuthCache;
|
||||
@@ -38,24 +34,23 @@ import timely.model.Metric;
|
||||
import timely.model.Tag;
|
||||
import timely.test.IntegrationTest;
|
||||
import timely.test.TestConfiguration;
|
||||
import timely.test.integration.MacITBase;
|
||||
import timely.test.integration.InMemoryITBase;
|
||||
|
||||
/**
|
||||
* Integration tests for the operations available over the UDP transport
|
||||
*/
|
||||
@Category(IntegrationTest.class)
|
||||
public class TimelyUdpIT extends MacITBase {
|
||||
public class TimelyUdpIT extends InMemoryITBase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TimelyUdpIT.class);
|
||||
private static final Long TEST_TIME = System.currentTimeMillis();
|
||||
private static final Long TEST_TIME = (System.currentTimeMillis() / 1000) * 1000;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
Connector con = mac.getConnector("root", "secret");
|
||||
con.tableOperations().list().forEach(t -> {
|
||||
accumuloClient.tableOperations().list().forEach(t -> {
|
||||
if (t.startsWith("timely")) {
|
||||
try {
|
||||
con.tableOperations().delete(t);
|
||||
accumuloClient.tableOperations().delete(t);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
@@ -69,7 +64,7 @@ public class TimelyUdpIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPut() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 54325);
|
||||
DatagramPacket packet = new DatagramPacket("".getBytes(UTF_8), 0, 0, address.getAddress(), 54325);
|
||||
@@ -100,8 +95,7 @@ public class TimelyUdpIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPutMultiple() throws Exception {
|
||||
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 54325);
|
||||
DatagramPacket packet = new DatagramPacket("".getBytes(UTF_8), 0, 0, address.getAddress(), 54325);
|
||||
@@ -184,7 +178,7 @@ public class TimelyUdpIT extends MacITBase {
|
||||
binary.get(data, 0, binary.remaining());
|
||||
LOG.debug("Sending {} bytes", data.length);
|
||||
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 54325);
|
||||
DatagramPacket packet = new DatagramPacket("".getBytes(UTF_8), 0, 0, address.getAddress(), 54325);
|
||||
@@ -228,7 +222,7 @@ public class TimelyUdpIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPutInvalidTimestamp() throws Exception {
|
||||
final TestServer m = new TestServer(conf);
|
||||
final TestServer m = new TestServer(conf, accumuloClient);
|
||||
m.run();
|
||||
InetSocketAddress address = new InetSocketAddress("127.0.0.1", 54325);
|
||||
DatagramPacket packet = new DatagramPacket("".getBytes(UTF_8), 0, 0, address.getAddress(), 54325);
|
||||
@@ -244,90 +238,85 @@ public class TimelyUdpIT extends MacITBase {
|
||||
|
||||
@Test
|
||||
public void testPersistence() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
startServer();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME + 1) + " 1.0 tag3=value3 tag4=value4",
|
||||
"sys.cpu.idle " + (TEST_TIME + 2) + " 1.0 tag3=value3 tag4=value4");
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
assertTrue(accumuloClient.namespaceOperations().exists("timely"));
|
||||
assertTrue(accumuloClient.tableOperations().exists("timely.metrics"));
|
||||
assertTrue(accumuloClient.tableOperations().exists("timely.meta"));
|
||||
int count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta entry: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(10, count);
|
||||
// count w/out versioning iterator to make sure that the optimization
|
||||
// for writing is working
|
||||
accumuloClient.tableOperations().removeIterator("timely.meta", "vers", EnumSet.of(IteratorScope.scan));
|
||||
// wait for zookeeper propagation
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : accumuloClient.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta no vers iter: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(15, count);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
stopServer();
|
||||
}
|
||||
final ZooKeeperInstance inst = new ZooKeeperInstance(mac.getClientConfig());
|
||||
final Connector connector = inst.getConnector("root", new PasswordToken("secret".getBytes(UTF_8)));
|
||||
assertTrue(connector.namespaceOperations().exists("timely"));
|
||||
assertTrue(connector.tableOperations().exists("timely.metrics"));
|
||||
assertTrue(connector.tableOperations().exists("timely.meta"));
|
||||
int count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta entry: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(10, count);
|
||||
// count w/out versioning iterator to make sure that the optimization
|
||||
// for writing is working
|
||||
connector.tableOperations().removeIterator("timely.meta", "vers", EnumSet.of(IteratorScope.scan));
|
||||
// wait for zookeeper propagation
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
count = 0;
|
||||
for (final Entry<Key, Value> entry : connector.createScanner("timely.meta", Authorizations.EMPTY)) {
|
||||
LOG.info("Meta no vers iter: " + entry);
|
||||
count++;
|
||||
}
|
||||
assertEquals(15, count);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPersistenceWithVisibility() throws Exception {
|
||||
final Server s = new Server(conf);
|
||||
s.run();
|
||||
startServer();
|
||||
try {
|
||||
put("sys.cpu.user " + TEST_TIME + " 1.0 tag1=value1 tag2=value2",
|
||||
"sys.cpu.idle " + (TEST_TIME + 1) + " 1.0 tag3=value3 tag4=value4 viz=(a|b)",
|
||||
"sys.cpu.idle " + (TEST_TIME + 2) + " 1.0 tag3=value3 tag4=value4 viz=(c&b)");
|
||||
sleepUninterruptibly(TestConfiguration.WAIT_SECONDS, TimeUnit.SECONDS);
|
||||
} finally {
|
||||
s.shutdown();
|
||||
}
|
||||
final ZooKeeperInstance inst = new ZooKeeperInstance(mac.getClientConfig());
|
||||
final Connector connector = inst.getConnector("root", new PasswordToken("secret".getBytes(UTF_8)));
|
||||
connector.securityOperations().changeUserAuthorizations("root", new Authorizations("a", "b", "c"));
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root", new Authorizations("a", "b", "c"));
|
||||
|
||||
int count = 0;
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
int count = 0;
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics",
|
||||
Authorizations.EMPTY)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(2, count);
|
||||
count = 0;
|
||||
Authorizations auth1 = new Authorizations("a");
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", auth1)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(4, count);
|
||||
count = 0;
|
||||
Authorizations auth2 = new Authorizations("b", "c");
|
||||
for (final Map.Entry<Key, Value> entry : accumuloClient.createScanner("timely.metrics", auth2)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
} finally {
|
||||
stopServer();
|
||||
}
|
||||
assertEquals(2, count);
|
||||
count = 0;
|
||||
Authorizations auth1 = new Authorizations("a");
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", auth1)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(4, count);
|
||||
count = 0;
|
||||
Authorizations auth2 = new Authorizations("b", "c");
|
||||
for (final Map.Entry<Key, Value> entry : connector.createScanner("timely.metrics", auth2)) {
|
||||
LOG.info("Entry: " + entry);
|
||||
final double value = ByteBuffer.wrap(entry.getValue().get()).getDouble();
|
||||
assertEquals(1.0, value, 1e-9);
|
||||
count++;
|
||||
}
|
||||
assertEquals(6, count);
|
||||
}
|
||||
|
||||
private void put(String... lines) throws Exception {
|
||||
|
||||
@@ -40,9 +40,8 @@ import io.netty.handler.codec.http.websocketx.WebSocketVersion;
|
||||
import io.netty.handler.ssl.SslContext;
|
||||
import io.netty.handler.ssl.SslContextBuilder;
|
||||
import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
|
||||
import org.apache.accumulo.core.client.Connector;
|
||||
import org.apache.accumulo.core.security.Authorizations;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -50,7 +49,6 @@ import org.junit.experimental.categories.Category;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
import timely.Server;
|
||||
import timely.api.request.VersionRequest;
|
||||
import timely.api.request.subscription.AddSubscription;
|
||||
import timely.api.request.subscription.CloseSubscription;
|
||||
@@ -80,7 +78,7 @@ import timely.util.JsonUtil;
|
||||
public class WebSocketIT extends OneWaySSLBase {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(WebSocketIT.class);
|
||||
private static final Long TEST_TIME = System.currentTimeMillis() - (240 * 1000);
|
||||
private static final Long TEST_TIME = ((System.currentTimeMillis() / 1000) * 1000) - (240 * 1000);
|
||||
private static final int WS_PORT = 54323;
|
||||
private static final URI LOCATION;
|
||||
static {
|
||||
@@ -174,27 +172,19 @@ public class WebSocketIT extends OneWaySSLBase {
|
||||
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void after() {
|
||||
AuthCache.resetConfiguration();
|
||||
}
|
||||
|
||||
private EventLoopGroup group = null;
|
||||
private Channel ch = null;
|
||||
private ClientHandler handler = null;
|
||||
private Server s = null;
|
||||
private String sessionId = null;
|
||||
private UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken("test", "test1");
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
s = new Server(conf);
|
||||
s.run();
|
||||
|
||||
Connector con = mac.getConnector("root", "secret");
|
||||
con.securityOperations().changeUserAuthorizations("root", new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
accumuloClient.securityOperations().changeUserAuthorizations("root",
|
||||
new Authorizations("A", "B", "C", "D", "E", "F"));
|
||||
|
||||
this.sessionId = UUID.randomUUID().toString();
|
||||
startServer();
|
||||
AuthCache.put(sessionId, TimelyPrincipal.anonymousPrincipal());
|
||||
group = new NioEventLoopGroup();
|
||||
SslContext ssl = SslContextBuilder.forClient().trustManager(InsecureTrustManagerFactory.INSTANCE).build();
|
||||
@@ -225,6 +215,11 @@ public class WebSocketIT extends OneWaySSLBase {
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void shutdown() {
|
||||
stopServer();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClientDisappears() throws Exception {
|
||||
try {
|
||||
@@ -271,7 +266,6 @@ public class WebSocketIT extends OneWaySSLBase {
|
||||
}
|
||||
} finally {
|
||||
ch.close().sync();
|
||||
s.shutdown();
|
||||
group.shutdownGracefully();
|
||||
}
|
||||
}
|
||||
@@ -344,15 +338,6 @@ public class WebSocketIT extends OneWaySSLBase {
|
||||
second = Metric.newBuilder().name("sys.cpu.user").value(TEST_TIME + 500, 7.0D).tag(new Tag("rack", "r2"))
|
||||
.tag(new Tag("tag3", "value3")).build();
|
||||
|
||||
int x = 1;
|
||||
for (String r : response) {
|
||||
responses = JsonUtil.getObjectMapper().readValue(r, MetricResponses.class);
|
||||
for (MetricResponse r1 : responses.getResponses()) {
|
||||
System.out.println(x + " -- " + r1.toString());
|
||||
}
|
||||
x++;
|
||||
}
|
||||
|
||||
Assert.assertEquals(1, response.size());
|
||||
responses = JsonUtil.getObjectMapper().readValue(response.get(0), MetricResponses.class);
|
||||
Assert.assertEquals(2, responses.size());
|
||||
@@ -776,7 +761,6 @@ public class WebSocketIT extends OneWaySSLBase {
|
||||
response = handler.getResponses();
|
||||
}
|
||||
assertEquals(1, response.size());
|
||||
System.out.println(response.get(0));
|
||||
SuggestResponse r = JsonUtil.getObjectMapper().readValue(response.get(0), SuggestResponse.class);
|
||||
assertEquals(1, r.getSuggestions().size());
|
||||
assertEquals("sys.cpu.user", r.getSuggestions().get(0));
|
||||
|
||||
Reference in new issue
Block a user