Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #289] Support Register-Model server based on DLedger #288

Merged
merged 10 commits into from
May 29, 2023
Prev Previous commit
Next Next commit
refactor(example): combine modules: command and example
1. combine modules: command and example

Closes #289
  • Loading branch information
TheR1sing3un committed May 25, 2023
commit a075384b851a217897e955514be4c33c07554b13
57 changes: 0 additions & 57 deletions command/pom.xml

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion dledger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dledger-core</artifactId>
<artifactId>dledger</artifactId>

<dependencies>
<dependency>
Expand Down
12 changes: 8 additions & 4 deletions example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dependencies>
<dependency>
<groupId>io.openmessaging.storage</groupId>
<artifactId>dledger-core</artifactId>
<artifactId>dledger-proxy</artifactId>
</dependency>
<dependency>
<groupId>com.beust</groupId>
Expand All @@ -24,6 +24,11 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -33,11 +38,10 @@
<configuration>
<archive>
<manifest>
<mainClass>io.openmessaging.storage.dledger.example.register.BossCommand
</mainClass>
<mainClass>io.openmessaging.storage.dledger.example.CommandCli</mainClass>
</manifest>
</archive>
<finalName>register-dledger</finalName>
<finalName>dledger-example</finalName>
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
<descriptorRefs>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2017-2022 The DLedger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.openmessaging.storage.dledger.example;

import com.beust.jcommander.JCommander;
import io.openmessaging.storage.dledger.example.appender.command.AppendCommand;
import io.openmessaging.storage.dledger.example.appender.command.AppenderCommand;
import io.openmessaging.storage.dledger.example.appender.command.GetCommand;
import io.openmessaging.storage.dledger.example.common.command.BaseCommand;
import io.openmessaging.storage.dledger.example.common.command.LeadershipTransferCommand;
import io.openmessaging.storage.dledger.example.common.command.ReadFileCommand;
import io.openmessaging.storage.dledger.example.register.command.BenchmarkCommand;
import io.openmessaging.storage.dledger.example.register.command.ReadCommand;
import io.openmessaging.storage.dledger.example.register.command.RegisterCommand;
import io.openmessaging.storage.dledger.example.register.command.WriteCommand;
import java.util.HashMap;
import java.util.Map;

public class CommandCli {

private final static Map<String, BaseCommand> COMMANDS = new HashMap<>();

static {
// for common command
COMMANDS.put("leadershipTransfer", new LeadershipTransferCommand());
COMMANDS.put("readFile", new ReadFileCommand());

// for Appender
COMMANDS.put("appender", new AppenderCommand());
COMMANDS.put("append", new AppendCommand());
COMMANDS.put("get", new GetCommand());

// for Register
COMMANDS.put("register", new RegisterCommand());
COMMANDS.put("write", new WriteCommand());
COMMANDS.put("read", new ReadCommand());
COMMANDS.put("benchmark", new BenchmarkCommand());
}



public static void main(String[] args) {
JCommander.Builder builder = JCommander.newBuilder();
COMMANDS.forEach(builder::addCommand);
JCommander jc = builder.build();
jc.parse(args);

if (jc.getParsedCommand() == null) {
jc.usage();
} else {
BaseCommand command = COMMANDS.get(jc.getParsedCommand());
if (null != command) {
command.doCommand();
} else {
jc.usage();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,43 +14,19 @@
* limitations under the License.
*/

package io.openmessaging.storage.dledger.command;
package io.openmessaging.storage.dledger.example.appender;

import com.alibaba.fastjson.JSON;
import com.beust.jcommander.JCommander;
import io.openmessaging.storage.dledger.DLedgerConfig;
import io.openmessaging.storage.dledger.proxy.DLedgerProxy;
import io.openmessaging.storage.dledger.proxy.DLedgerProxyConfig;
import io.openmessaging.storage.dledger.proxy.util.ConfigUtils;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class DLedger {
public class AppenderDLedger {

private static Logger logger = LoggerFactory.getLogger(DLedger.class);

public static void main(String[] args) {
List<DLedgerConfig> dLedgerConfigs = new LinkedList<>();
if (args.length > 0 && ("--config".equals(args[0]) || "-c".equals(args[0]))) {
ConfigCommand configCommand = new ConfigCommand();
JCommander.newBuilder().addObject(configCommand).build().parse(args);
try {
DLedgerProxyConfig dLedgerProxyConfig = ConfigUtils.parseDLedgerProxyConfig(configCommand.getConfigPath());
dLedgerConfigs.addAll(dLedgerProxyConfig.getConfigs());
} catch (Exception e) {
logger.error("Create DLedgerProxyConfig error", e);
System.exit(-1);
}
} else {
DLedgerConfig dLedgerConfig = new DLedgerConfig();
JCommander.newBuilder().addObject(dLedgerConfig).build().parse(args);
dLedgerConfigs.add(dLedgerConfig);
}
bootstrapDLedger(dLedgerConfigs);
}
private static Logger logger = LoggerFactory.getLogger(AppenderDLedger.class);

public static void bootstrapDLedger(List<DLedgerConfig> dLedgerConfigs) {
if (dLedgerConfigs == null || dLedgerConfigs.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,15 +14,18 @@
* limitations under the License.
*/

package io.openmessaging.storage.dledger.command;
package io.openmessaging.storage.dledger.example.appender.command;

import com.alibaba.fastjson.JSON;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.openmessaging.storage.dledger.client.DLedgerClient;
import io.openmessaging.storage.dledger.example.common.command.BaseCommand;
import io.openmessaging.storage.dledger.protocol.AppendEntryResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Parameters(commandDescription = "Append data to AppenderDLedger")
public class AppendCommand extends BaseCommand {

private static Logger logger = LoggerFactory.getLogger(AppendCommand.class);
Expand Down Expand Up @@ -50,3 +53,4 @@ public void doCommand() {
dLedgerClient.shutdown();
}
}

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2017-2022 The DLedger Authors
* Copyright 2017-2022 The DLedger Authors.
*
* Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -14,11 +14,13 @@
* limitations under the License.
*/

package io.openmessaging.storage.dledger.command;
package io.openmessaging.storage.dledger.example.appender.command;

import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import io.openmessaging.storage.dledger.DLedgerConfig;
import io.openmessaging.storage.dledger.example.appender.AppenderDLedger;
import io.openmessaging.storage.dledger.example.common.command.BaseCommand;
import io.openmessaging.storage.dledger.proxy.DLedgerProxyConfig;
import io.openmessaging.storage.dledger.proxy.util.ConfigUtils;
import java.io.File;
Expand All @@ -27,10 +29,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Parameters(commandDescription = "Bootstrap DLedger Server")
public class ServerCommand extends BaseCommand {
@Parameters(commandDescription = "Bootstrap the AppenderDLedger")
public class AppenderCommand extends BaseCommand {

private static Logger logger = LoggerFactory.getLogger(ServerCommand.class);
private static Logger logger = LoggerFactory.getLogger(AppenderCommand.class);

@Parameter(names = {"--group", "-g"}, description = "Group of this server")
private String group = "default";
Expand Down Expand Up @@ -63,7 +65,7 @@ public class ServerCommand extends BaseCommand {
public void doCommand() {
try {
List<DLedgerConfig> dLedgerConfigs = buildDLedgerConfigs();
DLedger.bootstrapDLedger(dLedgerConfigs);
AppenderDLedger.bootstrapDLedger(dLedgerConfigs);
logger.info("Bootstrap DLedger servers success, configs = {}", dLedgerConfigs);
} catch (Exception e) {
logger.error("Bootstrap DLedger servers error", e);
Expand Down
Loading