Skip to content

Commit

Permalink
Updated build to 1.2.1-1
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhks committed Mar 31, 2018
2 parents dd7284d + dba2242 commit 0439a29
Show file tree
Hide file tree
Showing 107 changed files with 4,946 additions and 1,148 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ before_script:
- export CLASSPATH=tools/tablesaw-1.2.6.jar

script:
- java make clean test-all
- java make ivy-retrieve;java make clean test-all

before_install:
- sudo rm -rf /var/lib/cassandra/*
- wget http://www.us.apache.org/dist/cassandra/3.0.15/apache-cassandra-3.0.15-bin.tar.gz && tar -xvzf apache-cassandra-3.0.15-bin.tar.gz && sudo sh apache-cassandra-3.0.15/bin/cassandra
- wget http://www.us.apache.org/dist/cassandra/3.11.1/apache-cassandra-3.11.1-bin.tar.gz && tar -xvzf apache-cassandra-3.11.1-bin.tar.gz && sudo sh apache-cassandra-3.11.1/bin/cassandra -R
2 changes: 1 addition & 1 deletion build.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ saw.setProperty(Tablesaw.PROP_MULTI_THREAD_OUTPUT, Tablesaw.PROP_VALUE_ON)

programName = "kairosdb"
//Do not use '-' in version string, it breaks rpm uninstall.
version = "1.2.0"
version = "1.2.1"
release = saw.getProperty("KAIROS_RELEASE_NUMBER", "1") //package release number
summary = "KairosDB"
description = """\
Expand Down
2 changes: 1 addition & 1 deletion ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<dependency org="org.hamcrest" name="hamcrest-library" rev="1.3"
conf="test->default"/>
<!--<dependency org="org.mockito" name="mockito-all" rev="1.9.5" />-->
<dependency org="org.mockito" name="mockito-core" rev="1.10.19" conf="test->default"/>
<dependency org="org.mockito" name="mockito-core" rev="2.13.0" conf="test->default"/>
<!--<dependency org="io.netty" name="netty" rev="3.5.11.Final" />-->
<dependency org="io.netty" name="netty" rev="3.10.6.Final" />
<!--<dependency org="org.powermock" name="powermock-api-mockito" rev="1.4.12" />
Expand Down
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This file is read only. Generated by the Tablesaw Ivy plugin.
<modelVersion>4.0.0</modelVersion>
<groupId>org.kairosdb</groupId>
<artifactId>kairosdb</artifactId>
<version>1.2.0-0.3beta</version>
<version>1.2.1-0.1beta</version>
<packaging>jar</packaging>
<name>kairosdb</name>
<description>KairosDB is a time series database that stores numeric values along
Expand Down Expand Up @@ -65,7 +65,7 @@ This file is read only. Generated by the Tablesaw Ivy plugin.
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>1.10.19</version>
<version>2.13.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -76,22 +76,22 @@ This file is read only. Generated by the Tablesaw Ivy plugin.
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>3.0</version>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-multibindings</artifactId>
<version>3.0</version>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-assistedinject</artifactId>
<version>3.0</version>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>3.0</version>
<version>4.1.0</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
Expand Down
2 changes: 1 addition & 1 deletion src/docs/kairosdevelopment/Plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ property Kairos will use a new ClassLoader to load your jar and dependencies.
Lets say you have a plugin called foo. You install a properties file that contains
::
kairosdb.service.foo=com.foo.MyPluginModule
kairosdb.service_folder=lib/foo
kairosdb.service_folder.foo=lib/foo

You can then place your jar and dependencies in the folder
::
Expand Down
5 changes: 4 additions & 1 deletion src/docs/restapi/ListMetricNames.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
List Metric Names
=================

Returns a list of all metric names.
Returns a list of all metric names. If you specify the prefix parameter, only
names that start with prefix are returned.

------
Method
Expand All @@ -15,6 +16,8 @@ Request

http://[host]:[port]/api/v1/metricnames

http://[host]:[port]/api/v1/metricnames?prefix=[prefix]

----
Body
----
Expand Down
31 changes: 31 additions & 0 deletions src/main/conf/tables.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,32 @@
<col name="type" type="string"/>
</table>

<table name="service_modification">
<property key="hsqldb_tableType" value="CACHED"/>
<col name="service" type="string" primary_key="true"/>
<col name="service_key" type="string" primary_key="true"/>
<col name="modification_time" type="timestamp"/>
</table>

<table name="service_index">
<property key="hsqldb_tableType" value="CACHED"/>
<col name="service" type="string" primary_key="true"/>
<col name="service_key" type="string" primary_key="true"/>
<col name="key" type="string" primary_key="true"/>
<col name="value" type="string"/>
<col name="modification_time" type="timestamp" auto_set="mts"/>

<table_query name="service_keys" result_type="multi">
<input>
<param name="service" type="string" test="foo"/>
</input>
<sql>
from service_index this
where
this."service" = ?
order by this."key" asc
</sql>
</table_query>

<table_query name="keys" result_type="multi">
<input>
Expand Down Expand Up @@ -68,6 +88,17 @@
</sql>
</table_query>

<table_query name="modification_time" result_type="single">
<input>
</input>
<return>
</return>
<sql>
select "modification_time" from service_index
</sql>
</table_query>


<table_query name="service_keys" result_type="multi">
<input>
<param name="service" type="string" test="foo"/>
Expand Down
19 changes: 17 additions & 2 deletions src/main/java/org/kairosdb/core/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.kairosdb.core;

import com.google.common.net.InetAddresses;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.TypeLiteral;
Expand Down Expand Up @@ -86,20 +87,22 @@
import javax.inject.Singleton;
import java.util.MissingResourceException;
import java.util.Properties;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

import static org.kairosdb.core.queue.QueueProcessor.QUEUE_PROCESSOR;
import static org.kairosdb.core.queue.QueueProcessor.QUEUE_PROCESSOR_CLASS;


public class CoreModule extends AbstractModule
{
public static final String QUEUE_PATH = "kairosdb.queue_processor.queue_path";
public static final String PAGE_SIZE = "kairosdb.queue_processor.page_size";

public static final String DATAPOINTS_FACTORY_LONG = "kairosdb.datapoints.factory.long";
public static final String DATAPOINTS_FACTORY_DOUBLE = "kairosdb.datapoints.factory.double";

private Properties m_props;
private final FilterEventBus m_eventBus;

Expand Down Expand Up @@ -228,6 +231,8 @@ public void afterInjection(I i)

bind(IngestExecutorService.class);

bind(HostManager.class).in(Singleton.class);

String hostIp = m_props.getProperty("kairosdb.host_ip");
bindConstant().annotatedWith(Names.named("HOST_IP")).to(hostIp != null ? hostIp: InetAddresses.toAddrString(Util.findPublicIp()));

Expand All @@ -245,6 +250,16 @@ public BigArray getBigArray(@Named(QUEUE_PATH) String queuePath,
@Provides @Named(QUEUE_PROCESSOR) @Singleton
public ExecutorService getQueueExecutor()
{
return Executors.newSingleThreadExecutor();
return Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("QueueProcessor-%s").build());
}

@Provides
@Singleton
@Named(HostManager.HOST_MANAGER_SERVICE_EXECUTOR)
public ScheduledExecutorService getExecutorService()
{
return Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder().setNameFormat("HostManagerService-%s").build());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import javax.inject.Inject;
import java.io.DataInput;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
Expand Down
123 changes: 123 additions & 0 deletions src/main/java/org/kairosdb/core/HostManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package org.kairosdb.core;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableMap;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import org.kairosdb.core.datastore.ServiceKeyStore;
import org.kairosdb.core.datastore.ServiceKeyValue;
import org.kairosdb.core.exception.DatastoreException;
import org.kairosdb.core.exception.KairosDBException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ScheduledExecutorService;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.kairosdb.util.Preconditions.checkNotNullOrEmpty;

public class HostManager implements KairosDBService
{
private static final Logger logger = LoggerFactory.getLogger(HostManager.class);

private static final String SERVICE = "_Hosts";
private static final String SERVICE_KEY = "Active";
private static final String DELAY = "kairosdb.host_service_manager.check_delay_time_millseconds";
private static final String INACTIVE_TIME = "kairosdb.host_service_manager.inactive_time_seconds";
public static final String HOST_MANAGER_SERVICE_EXECUTOR = "HostManagerServiceExecutor";

private final ServiceKeyStore keyStore;
private final String hostname;
private final long inactiveTimeSeconds;
private final String guid;
private ScheduledExecutorService executorService;

private volatile Map<String, ServiceKeyValue> activeHosts = new HashMap<>();

@Inject
public HostManager(ServiceKeyStore keyStore,
@Named(HOST_MANAGER_SERVICE_EXECUTOR) ScheduledExecutorService executorService,
@Named(DELAY) long delay, @Named("HOSTNAME") String hostName, @Named(INACTIVE_TIME) long inactiveTime,
@Named(Main.KAIROSDB_SERVER_GUID) String guid)
{
this.keyStore = checkNotNull(keyStore, "keyStore cannot be null");
this.executorService = checkNotNull(executorService, "executorService cannot be null");
this.hostname = checkNotNullOrEmpty(hostName, "hostname cannot be null or empty");
this.inactiveTimeSeconds = inactiveTime;
this.guid = checkNotNullOrEmpty(guid, "guid cannot be null or empty");

executorService.scheduleWithFixedDelay(new CheckChanges(), 0, delay, java.util.concurrent.TimeUnit.MILLISECONDS);
}

private class CheckChanges implements Runnable
{
@Override
public void run()
{
checkHostChanges();
}
}

@VisibleForTesting
void checkHostChanges()
{
try {
// Add this host to the table if it doesn't exist or update its timestamp
keyStore.setValue(SERVICE, SERVICE_KEY, guid, hostname);

Map<String, ServiceKeyValue> hosts = getHostsFromKeyStore();

// Remove inactive nodes from the table
long now = System.currentTimeMillis();
for (String guid : hosts.keySet()) {
ServiceKeyValue host = hosts.get(guid);
if ((host.getLastModified().getTime() + (1000 * inactiveTimeSeconds)) < now) {
keyStore.deleteKey(SERVICE, SERVICE_KEY, guid);
}
}

// update cache
activeHosts = getHostsFromKeyStore();
}
catch (Throwable e) {
logger.error("Could not access keystore " + SERVICE + ":" + SERVICE_KEY);
}
}

private Map<String, ServiceKeyValue> getHostsFromKeyStore()
throws DatastoreException
{
Map<String, ServiceKeyValue> hosts = new HashMap<>();
Iterable<String> guids = keyStore.listKeys(SERVICE, SERVICE_KEY);
for (String guid : guids) {
ServiceKeyValue value = keyStore.getValue(SERVICE, SERVICE_KEY, guid);
if (value != null) {
hosts.put(guid, value);
}
}
return hosts;
}

/**
* Returns a map of kairos hosts. The key is a guid nd the value is the hostname. There should always be at least one in the map (the current kairos node).
* @return list of kairos hosts.
*/
public Map<String, ServiceKeyValue> getActiveKairosHosts()
{
return ImmutableMap.copyOf(activeHosts);
}

@Override
public void start()
throws KairosDBException
{
}

@Override
public void stop()
{
executorService.shutdown();
}
}
Loading

0 comments on commit 0439a29

Please sign in to comment.