com.scalar.dl.client.tool.FunctionsRegistration Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalardl-java-client-sdk Show documentation
Show all versions of scalardl-java-client-sdk Show documentation
A client-side Java library to interact with Scalar DL network.
package com.scalar.dl.client.tool;
import com.moandjiezana.toml.Toml;
import com.scalar.dl.client.config.ClientConfig;
import com.scalar.dl.client.exception.ClientException;
import com.scalar.dl.client.service.ClientService;
import com.scalar.dl.client.service.ClientServiceFactory;
import java.io.File;
import java.util.concurrent.Callable;
import javax.json.JsonValue;
import picocli.CommandLine;
import picocli.CommandLine.Command;
@Command(name = "register-functions", description = "Register specified functions.")
public class FunctionsRegistration implements Callable {
@CommandLine.Option(
names = {"-h", "--help"},
usageHelp = true,
description = "display the help message.")
boolean helpRequested;
@CommandLine.Option(
names = {"--properties", "--config"},
required = true,
paramLabel = "PROPERTIES_FILE",
description = "A configuration file in properties format.")
private String properties;
@CommandLine.Option(
names = {"--functions-file"},
required = true,
paramLabel = "FUNCTION_FILE",
description = "A file including functions to register in TOML format.")
private String functionsFile;
public static void main(String[] args) {
int exitCode =
new CommandLine(new com.scalar.dl.client.tool.FunctionsRegistration()).execute(args);
System.exit(exitCode);
}
@Override
public Integer call() throws Exception {
ClientServiceFactory factory = new ClientServiceFactory(new ClientConfig(new File(properties)));
try (ClientService service = factory.getClientService()) {
new Toml()
.read(new File(functionsFile))
.getTables("functions")
.forEach(
each -> {
service.registerFunction(
each.getString("function-id"),
each.getString("function-binary-name"),
each.getString("function-class-file"));
Common.printOutput(JsonValue.NULL);
});
return 0;
} catch (ClientException e) {
Common.printError(e);
return 1;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy