-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: new ksql-restore-command-topic to restore backups
- Loading branch information
Showing
9 changed files
with
897 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
# (Copyright) [2020] Confluent, Inc. | ||
|
||
base_dir=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd ) | ||
|
||
: "${KSQL_CONFIG_DIR:="$base_dir/config"}" | ||
|
||
# logj4 settings | ||
if [ -z "$KSQL_LOG4J_OPTS" ]; then | ||
# Test for files from dev -> packages so this will work as expected in dev if you have packages | ||
# installed | ||
if [ -e "$base_dir/config/log4j.properties" ]; then # Dev environment | ||
KSQL_CONFIG_DIR="$base_dir/config" | ||
elif [ -e "$base_dir/etc/ksqldb/log4j.properties" ]; then # Simple zip file layout | ||
KSQL_CONFIG_DIR="$base_dir/etc/ksqldb" | ||
elif [ -e "/etc/ksqldb/log4j.properties" ]; then # Normal install layout | ||
KSQL_CONFIG_DIR="/etc/ksqldb" | ||
fi | ||
fi | ||
|
||
: "${KSQL_LOG4J_OPTS:=""}" | ||
|
||
# Use file logging by default | ||
if [ -z "$KSQL_LOG4J_OPTS" ]; then | ||
export KSQL_LOG4J_OPTS="-Dlog4j.configuration=file:$KSQL_CONFIG_DIR/log4j-file.properties" | ||
fi | ||
|
||
exec "$base_dir"/bin/ksql-run-class io.confluent.ksql.rest.server.restore.KsqlRestoreCommandTopic "$@" |
64 changes: 64 additions & 0 deletions
64
ksqldb-rest-app/src/main/java/io/confluent/ksql/rest/server/BackupInputFile.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright 2020 Confluent Inc. | ||
* | ||
* Licensed under the Confluent Community License (the "License"); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* http://www.confluent.io/confluent-community-license | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package io.confluent.ksql.rest.server; | ||
|
||
import io.confluent.ksql.util.Pair; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public class BackupInputFile { | ||
protected static final String KEY_VALUE_SEPARATOR_STR = ":"; | ||
protected static final String NEW_LINE_SEPARATOR_STR = "\n"; | ||
|
||
static final byte[] KEY_VALUE_SEPARATOR_BYTES = | ||
KEY_VALUE_SEPARATOR_STR.getBytes(StandardCharsets.UTF_8); | ||
static final byte[] NEW_LINE_SEPARATOR_BYTES = | ||
NEW_LINE_SEPARATOR_STR.getBytes(StandardCharsets.UTF_8); | ||
|
||
private final File file; | ||
|
||
public BackupInputFile(final File file) { | ||
this.file = Objects.requireNonNull(file, "file"); | ||
} | ||
|
||
public File getFile() { | ||
return file; | ||
} | ||
|
||
public String getPath() { | ||
return file.getAbsolutePath(); | ||
} | ||
|
||
public List<Pair<byte[], byte[]>> readRecords() throws IOException { | ||
final List<Pair<byte[], byte[]>> commands = new ArrayList<>(); | ||
for (final String line : Files.readAllLines(getFile().toPath(), StandardCharsets.UTF_8)) { | ||
final String commandId = line.substring(0, line.indexOf(KEY_VALUE_SEPARATOR_STR)); | ||
final String command = line.substring(line.indexOf(KEY_VALUE_SEPARATOR_STR) + 1); | ||
|
||
commands.add(new Pair<>( | ||
commandId.getBytes(StandardCharsets.UTF_8), | ||
command.getBytes(StandardCharsets.UTF_8) | ||
)); | ||
} | ||
|
||
return commands; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.