Skip to content

Commit

Permalink
RPCManager, plugin loader refactor (OpenTSDB#870)
Browse files Browse the repository at this point in the history
* Refactored RPCManager, allowed for disabling the built-in UI or API via configuration options

Fix OpenTSDB#830

* Pass mode in for tests

* Added Logging to identify if UI and API are enabled

* Added CLI Options to disable UI or API RPC endpoints

* Missed a few lines with the new option
  • Loading branch information
johann8384 authored Sep 20, 2016
1 parent ad6985e commit 910b433
Show file tree
Hide file tree
Showing 9 changed files with 303 additions and 186 deletions.
4 changes: 3 additions & 1 deletion Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ tsdb_SRC := \
src/query/expression/PostAggregatedDataPoints.java \
src/query/expression/Scale.java \
src/query/expression/SumSeries.java \
src/query/expression/TimeShift.java \
src/query/expression/TimeShift.java \
src/query/expression/TimeSyncedIterator.java \
src/query/expression/UnionIterator.java \
src/query/expression/VariableIterator.java \
Expand Down Expand Up @@ -147,6 +147,7 @@ tsdb_SRC := \
src/tsd/AnnotationRpc.java \
src/tsd/BadRequestException.java \
src/tsd/ConnectionManager.java \
src/tsd/DropCachesRpc.java \
src/tsd/GnuplotException.java \
src/tsd/GraphHandler.java \
src/tsd/HttpJsonSerializer.java \
Expand All @@ -164,6 +165,7 @@ tsdb_SRC := \
src/tsd/RpcHandler.java \
src/tsd/RpcPlugin.java \
src/tsd/RpcManager.java \
src/tsd/RpcUtil.java \
src/tsd/RTPublisher.java \
src/tsd/SearchRpc.java \
src/tsd/StaticFileRpc.java \
Expand Down
8 changes: 8 additions & 0 deletions src/opentsdb.conf
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ tsd.http.cachedir =
# is False
#tsd.core.auto_create_metrics = false

# Whether or not to enable the built-in UI Rpc Plugins, default
# is True
#tsd.core.enable_ui = true

# Whether or not to enable the built-in API Rpc Plugins, default
# is True
#tsd.core.enable_api = true

# --------- STORAGE ----------
# Whether or not to enable data compaction in HBase, default is True
#tsd.storage.enable_compaction = true
Expand Down
4 changes: 4 additions & 0 deletions src/tools/CliOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ static void overloadConfig(final ArgP argp, final Config config) {
// map the overrides
if (entry.getKey().toLowerCase().equals("--auto-metric")) {
config.overrideConfig("tsd.core.auto_create_metrics", "true");
} else if (entry.getKey().toLowerCase().equals("--disable-ui")) {
config.overrideConfig("tsd.core.enable_ui", "false");
} else if (entry.getKey().toLowerCase().equals("--disable-api")) {
config.overrideConfig("tsd.core.enable_api", "false");
} else if (entry.getKey().toLowerCase().equals("--table")) {
config.overrideConfig("tsd.storage.hbase.data_table", entry.getValue());
} else if (entry.getKey().toLowerCase().equals("--uidtable")) {
Expand Down
4 changes: 4 additions & 0 deletions src/tools/TSDMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public static void main(String[] args) throws IOException {
"Use async NIO (default true) or traditional blocking io");
argp.addOption("--read-only", "true|false",
"Set tsd.mode to ro (default false)");
argp.addOption("--disable-ui", "true|false",
"Set tsd.core.enable_ui to false (default true)");
argp.addOption("--disable-api", "true|false",
"Set tsd.core.enable_api to false (default true)");
argp.addOption("--backlog", "NUM",
"Size of connection attempt queue (default: 3072 or kernel"
+ " somaxconn.");
Expand Down
88 changes: 88 additions & 0 deletions src/tsd/DropCachesRpc.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
// This file is part of OpenTSDB.
// Copyright (C) 2013 The OpenTSDB Authors.
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 2.1 of the License, or (at your
// option) any later version. This program is distributed in the hope that it
// will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
// General Public License for more details. You should have received a copy
// of the GNU Lesser General Public License along with this program. If not,
// see <http://www.gnu.org/licenses/>.
package net.opentsdb.tsd;

import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.util.concurrent.Atomics;
import com.stumbleupon.async.Callback;
import com.stumbleupon.async.Deferred;

import org.jboss.netty.channel.Channel;
import org.jboss.netty.handler.codec.http.HttpMethod;
import org.jboss.netty.handler.codec.http.HttpResponseStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.opentsdb.tools.BuildData;
import net.opentsdb.core.Aggregators;
import net.opentsdb.core.TSDB;
import net.opentsdb.query.filter.TagVFilter;
import net.opentsdb.stats.StatsCollector;
import net.opentsdb.utils.Config;
import net.opentsdb.utils.JSON;
import net.opentsdb.utils.PluginLoader;

import java.io.IOException;

/** The "dropcaches" command. */
public final class DropCachesRpc implements TelnetRpc, HttpRpc {
private static final Logger LOG = LoggerFactory.getLogger(DropCachesRpc.class);

public Deferred<Object> execute(final TSDB tsdb, final Channel chan,
final String[] cmd) {
dropCaches(tsdb, chan);
chan.write("Caches dropped.\n");
return Deferred.fromResult(null);
}

public void execute(final TSDB tsdb, final HttpQuery query)
throws IOException {

// only accept GET/DELETE
RpcUtil.allowedMethods(query.method(), HttpMethod.GET.getName(), HttpMethod.DELETE.getName());

dropCaches(tsdb, query.channel());

if (query.apiVersion() > 0) {
final HashMap<String, String> response = new HashMap<String, String>();
response.put("status", "200");
response.put("message", "Caches dropped");
query.sendReply(query.serializer().formatDropCachesV1(response));
} else { // deprecated API
query.sendReply("Caches dropped.\n");
}
}

/** Drops in memory caches. */
private void dropCaches(final TSDB tsdb, final Channel chan) {
LOG.warn(chan + " Dropping all in-memory caches.");
tsdb.dropCaches();
}
}
Loading

0 comments on commit 910b433

Please sign in to comment.