1) Add tool to convert properties from the old settings to the new ones.

This commit is contained in:
cheddar 2013-09-12 17:59:23 -05:00
parent 044e43d231
commit e0738b3b22
9 changed files with 522 additions and 1 deletions

View File

@ -19,6 +19,7 @@
package io.druid.server.initialization; package io.druid.server.initialization;
import com.google.common.base.Charsets;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.io.Closeables; import com.google.common.io.Closeables;
import com.google.inject.Binder; import com.google.inject.Binder;
@ -31,6 +32,7 @@ import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties; import java.util.Properties;
/** /**
@ -67,7 +69,7 @@ public class PropertiesModule implements Module
if (stream != null) { if (stream != null) {
log.info("Loading properties from %s", propertiesFile); log.info("Loading properties from %s", propertiesFile);
try { try {
fileProps.load(stream); fileProps.load(new InputStreamReader(stream, Charsets.UTF_8));
} }
catch (IOException e) { catch (IOException e) {
throw Throwables.propagate(e); throw Throwables.propagate(e);

View File

@ -26,6 +26,7 @@ import com.google.inject.Module;
import io.airlift.command.Cli; import io.airlift.command.Cli;
import io.airlift.command.Help; import io.airlift.command.Help;
import io.airlift.command.ParseException; import io.airlift.command.ParseException;
import io.druid.cli.convert.ConvertProperties;
import io.druid.guice.DruidGuiceExtensions; import io.druid.guice.DruidGuiceExtensions;
import io.druid.guice.DruidSecondaryModule; import io.druid.guice.DruidSecondaryModule;
import io.druid.guice.JsonConfigProvider; import io.druid.guice.JsonConfigProvider;
@ -63,6 +64,11 @@ public class Main
.withDefaultCommand(Help.class) .withDefaultCommand(Help.class)
.withCommands(CliRealtimeExample.class); .withCommands(CliRealtimeExample.class);
builder.withGroup("tools")
.withDescription("Various tools for working with Druid")
.withDefaultCommand(Help.class)
.withCommands(ConvertProperties.class);
builder.withGroup("internal") builder.withGroup("internal")
.withDescription("Processes that Druid runs \"internally\", you should rarely use these directly") .withDescription("Processes that Druid runs \"internally\", you should rarely use these directly")
.withDefaultCommand(Help.class) .withDefaultCommand(Help.class)

View File

@ -0,0 +1,48 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.cli.convert;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Properties;
/**
*/
public class ChatHandlerConverter implements PropertyConverter
{
private static final String PROPERTY = "druid.indexer.chathandler.publishDiscovery";
@Override
public boolean canHandle(String property)
{
return PROPERTY.equals(property);
}
@Override
public Map<String, String> convert(Properties properties)
{
if (Boolean.parseBoolean(properties.getProperty(PROPERTY))) {
return ImmutableMap.of("druid.indexer.task.chathandler.type", "curator");
}
return ImmutableMap.of();
}
}

View File

@ -0,0 +1,163 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.cli.convert;
import com.google.common.base.Charsets;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.metamx.common.logger.Logger;
import io.airlift.command.Command;
import io.airlift.command.Option;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.List;
import java.util.Map;
import java.util.Properties;
/**
*/
@Command(
name = "convertProps",
description = "Converts runtime.properties files from version 0.5 to 0.6"
)
public class ConvertProperties implements Runnable
{
private static final Logger log = new Logger(ConvertProperties.class);
private static final List<PropertyConverter> converters = Lists.newArrayList(
new DatabasePropertiesConverter(),
new Rename("druid.database.rules.defaultDatasource", "druid.manager.rules.defaultTier"),
new Rename("druid.zk.paths.discoveryPath", "druid.discovery.curator.path"),
new Rename("druid.http.numThreads", "druid.server.http.numThreads"),
new Rename("druid.http.maxIdleTimeMillis", "druid.server.http.maxIdleTime"),
new Rename("druid.database.connectURI", "druid.db.connector.connectURI"),
new Rename("druid.database.user", "druid.db.connector.user"),
new Rename("druid.database.password", "druid.db.connector.password"),
new Rename("com.metamx.emitter", "druid.emitter"),
new Rename("com.metamx.emitter.logging.level", "druid.emitter.logging.logLevel"),
new IndexCacheConverter(),
new Rename("druid.paths.segmentInfoCache", "druid.segmentCache.infoPath"),
new Rename("com.metamx.aws.accessKey", "druid.s3.accessKey"),
new Rename("com.metamx.aws.secretKey", "druid.s3.secretKey"),
new PrefixRename("druid.bard.cache", "druid.broker.cache"),
new Rename("druid.client.http.connections", "druid.broker.http.numConnections"),
new Rename("com.metamx.query.groupBy.maxResults", "druid.query.groupBy.maxResults"),
new Rename("com.metamx.query.search.maxSearchLimit", "druid.query.search.maxSearchLimit"),
new Rename("druid.indexer.storage", "druid.indexer.storage.type"),
new Rename("druid.indexer.threads", "druid.indexer.runner.forks"),
new Rename("druid.indexer.taskDir", "druid.indexer.runner.taskDir"),
new Rename("druid.indexer.fork.java", "druid.indexer.runner.javaCommand"),
new Rename("druid.indexer.fork.opts", "druid.indexer.runner.javaOpts"),
new Rename("druid.indexer.fork.classpath", "druid.indexer.runner.classpath"),
new Rename("druid.indexer.fork.main", "druid.indexer.runner.mainClass"),
new Rename("druid.indexer.fork.hostpattern", "druid.indexer.runner.hostPattern"),
new Rename("druid.indexer.fork.startport", "druid.indexer.runner.startPort"),
new Rename("druid.indexer.properties.prefixes", "druid.indexer.runner.allowedPrefixes"),
new Rename("druid.indexer.taskAssignmentTimeoutDuration", "druid.indexer.runner.taskAssignmentTimeout"),
new Rename("druid.indexer.worker.version", "druid.indexer.runner.workerVersion"),
new Rename("druid.zk.maxNumBytes", "druid.indexer.runner.maxZnodeBytes"),
new Rename("druid.indexer.provisionResources.duration", "druid.indexer.autoscale.provisionPeriod"),
new Rename("druid.indexer.terminateResources.duration", "druid.indexer.autoscale.terminatePeriod"),
new Rename("druid.indexer.terminateResources.originDateTime", "druid.indexer.autoscale.originTime"),
new Rename("druid.indexer.autoscaling.strategy", "druid.indexer.autoscale.strategy"),
new Rename("druid.indexer.maxWorkerIdleTimeMillisBeforeDeletion", "druid.indexer.autoscale.workerIdleTimeout"),
new Rename("druid.indexer.maxScalingDuration", "druid.indexer.autoscale.scalingTimeout"),
new Rename("druid.indexer.numEventsToTrack", "druid.indexer.autoscale.numEventsToTrack"),
new Rename("druid.indexer.maxPendingTaskDuration", "druid.indexer.autoscale.pendingTaskTimeout"),
new Rename("druid.indexer.worker.version", "druid.indexer.autoscale.workerVersion"),
new Rename("druid.indexer.worker.port", "druid.indexer.autoscale.workerPort"),
new Rename("druid.worker.masterService", "druid.worker.overlordService"),
new ChatHandlerConverter(),
new Rename("druid.indexer.baseDir", "druid.indexer.task.baseDir"),
new Rename("druid.indexer.taskDir", "druid.indexer.task.taskDir"),
new Rename("druid.indexer.hadoopWorkingPath", "druid.indexer.task.hadoopWorkingPath"),
new Rename("druid.indexer.rowFlushBoundary", "druid.indexer.task.rowFlushBoundary"),
new Rename("druid.worker.taskActionClient.retry.minWaitMillis", "druid.worker.taskActionClient.retry.minWait"),
new Rename("druid.worker.taskActionClient.retry.maxWaitMillis", "druid.worker.taskActionClient.retry.maxWait"),
new Rename("druid.master.merger.service", "druid.selectors.indexing.serviceName")
);
@Option(name = "-f", title = "file", description = "The properties file to convert", required = true)
public String filename;
@Option(name = "-o", title = "outFile", description = "The file to write updated properties to.", required = true)
public String outFilename;
@Override
public void run()
{
File file = new File(filename);
if (!file.exists()) {
System.out.printf("File[%s] does not exist.%n", file);
}
File outFile = new File(outFilename);
if (!outFile.getParentFile().exists()) {
outFile.getParentFile().mkdirs();
}
Properties fromFile = new Properties();
try (Reader in = new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))
{
fromFile.load(in);
}
catch (IOException e) {
throw Throwables.propagate(e);
}
Properties updatedProps = new Properties();
int count = 0;
for (String property : fromFile.stringPropertyNames()) {
boolean handled = false;
for (PropertyConverter converter : converters) {
if (converter.canHandle(property)) {
for (Map.Entry<String, String> entry : converter.convert(fromFile).entrySet()) {
++count;
updatedProps.setProperty(entry.getKey(), entry.getValue());
}
handled = true;
}
}
if (!handled) {
updatedProps.put(property, fromFile.getProperty(property));
}
}
try (Writer out = new OutputStreamWriter(new FileOutputStream(outFile), Charsets.UTF_8))
{
updatedProps.store(out, null);
}
catch (IOException e) {
throw Throwables.propagate(e);
}
log.info("Completed! Converted[%,d] properties.", count);
}
}

View File

@ -0,0 +1,96 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.cli.convert;
import com.google.api.client.util.Maps;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
/**
*/
public class DatabasePropertiesConverter implements PropertyConverter
{
private final List<String> tableProperties = Lists.newArrayList(
"druid.database.segmentTable",
"druid.database.configTable",
"druid.database.ruleTable",
"druid.database.taskLockTable",
"druid.database.taskLogTable",
"druid.database.taskTable"
);
private AtomicBoolean ran = new AtomicBoolean(false);
@Override
public boolean canHandle(String property)
{
return tableProperties.contains(property) && !ran.get();
}
@Override
public Map<String, String> convert(Properties properties)
{
if (!ran.getAndSet(true)) {
String tablePrefix = properties.getProperty("druid.database.segmentTable");
if (tablePrefix == null) {
tablePrefix = "druid";
}
else {
tablePrefix = tablePrefix.split("_")[0];
}
Map<String, String> retVal = Maps.newLinkedHashMap();
retVal.put("druid.db.tables.base", tablePrefix);
addIfNotDefault(properties, tablePrefix, retVal, "druid.database.segmentTable", "segments");
addIfNotDefault(properties, tablePrefix, retVal, "druid.database.configTable", "config");
addIfNotDefault(properties, tablePrefix, retVal, "druid.database.ruleTable", "rules");
addIfNotDefault(properties, tablePrefix, retVal, "druid.database.taskTable", "tasks");
addIfNotDefault(properties, tablePrefix, retVal, "druid.database.taskLockTable", "taskLock");
addIfNotDefault(properties, tablePrefix, retVal, "druid.database.taskLogTable", "taskLog");
return retVal;
}
return ImmutableMap.of();
}
private void addIfNotDefault(
Properties properties,
String tablePrefix,
Map<String, String> retVal,
String property,
String tablename
)
{
final String value = properties.getProperty(property);
if (value != null) {
if (!value.equals(String.format("%s_%s", tablePrefix, tablename))) {
retVal.put(String.format("druid.db.tables.%s", tablename), value);
}
}
}
}

View File

@ -0,0 +1,52 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.cli.convert;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Properties;
/**
*/
public class IndexCacheConverter implements PropertyConverter
{
private static final String PROPERTY = "druid.paths.indexCache";
@Override
public boolean canHandle(String property)
{
return PROPERTY.equals(property);
}
@Override
public Map<String, String> convert(Properties properties)
{
final String value = properties.getProperty(PROPERTY);
return ImmutableMap.of(
"druid.segmentCache.locations",
String.format(
"[{\"path\": \"%s\", \"maxSize\": %s}]", value, properties.getProperty("druid.server.maxSize")
)
);
}
}

View File

@ -0,0 +1,69 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.cli.convert;
import com.google.api.client.util.Maps;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicBoolean;
/**
*/
public class PrefixRename implements PropertyConverter
{
private final String prefix;
private final String outputPrefix;
private final AtomicBoolean ran = new AtomicBoolean(false);
public PrefixRename(
String prefix,
String outputPrefix
)
{
this.prefix = prefix;
this.outputPrefix = outputPrefix;
}
@Override
public boolean canHandle(String property)
{
return property.startsWith(prefix) && !ran.get();
}
@Override
public Map<String, String> convert(Properties properties)
{
if (!ran.getAndSet(true)) {
Map<String, String> retVal = Maps.newLinkedHashMap();
for (String property : properties.stringPropertyNames()) {
if (property.startsWith(prefix)) {
retVal.put(property.replace(prefix, outputPrefix), properties.getProperty(property));
}
}
return retVal;
}
return ImmutableMap.of();
}
}

View File

@ -0,0 +1,31 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.cli.convert;
import java.util.Map;
import java.util.Properties;
/**
*/
public interface PropertyConverter
{
public boolean canHandle(String property);
public Map<String, String> convert(Properties properties);
}

View File

@ -0,0 +1,54 @@
/*
* Druid - a distributed column store.
* Copyright (C) 2012, 2013 Metamarkets Group Inc.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package io.druid.cli.convert;
import com.google.common.collect.ImmutableMap;
import java.util.Map;
import java.util.Properties;
/**
*/
public class Rename implements PropertyConverter
{
private final String property;
private final String newProperty;
public Rename(
String property,
String newProperty
)
{
this.property = property;
this.newProperty = newProperty;
}
@Override
public boolean canHandle(String property)
{
return this.property.equals(property);
}
@Override
public Map<String, String> convert(Properties properties)
{
return ImmutableMap.of(newProperty, properties.getProperty(property));
}
}