com.scalar.dl.client.tool.ContractRegistration 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.
/*
* This file is part of the Scalar DL client SDK.
* Copyright (c) 2019 Scalar, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
*
* You can be released from the requirements of the license by purchasing
* a commercial license. For more information, please contact Scalar, Inc.
*/
package com.scalar.dl.client.tool;
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.io.StringReader;
import java.util.Optional;
import java.util.concurrent.Callable;
import javax.json.Json;
import javax.json.JsonValue;
import picocli.CommandLine;
import picocli.CommandLine.Command;
@Command(name = "register-contract", description = "Register a specified contract.")
public class ContractRegistration implements Callable {
@CommandLine.Option(
names = {"--properties", "--config"},
required = true,
paramLabel = "PROPERTIES_FILE",
description = "A configuration file in properties format.")
private String properties;
@CommandLine.Option(
names = {"--contract-id"},
required = true,
paramLabel = "CONTRACT_ID",
description = "An ID of a contract to register.")
private String contractId;
@CommandLine.Option(
names = {"--contract-binary-name"},
required = true,
paramLabel = "CONTRACT_BINARY_NAME",
description = "A binary name of a contract to register.")
private String contractBinaryName;
@CommandLine.Option(
names = {"--contract-class-file"},
required = true,
paramLabel = "CONTRACT_CLASS_FILE",
description = "A contract class file to register.")
private String contractClassFile;
@CommandLine.Option(
names = {"--contract-properties"},
required = false,
paramLabel = "CONTRACT_PROPERTIES",
description = "A contract properties in serialized JSON format.")
private String contractProperties;
@CommandLine.Option(
names = {"-h", "--help"},
usageHelp = true,
description = "display the help message.")
boolean helpRequested;
public static void main(String[] args) {
int exitCode = new CommandLine(new ContractRegistration()).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()) {
service.registerContract(
contractId,
contractBinaryName,
contractClassFile,
Optional.ofNullable(contractProperties)
.map(p -> Json.createReader(new StringReader(p)).readObject()));
Common.printOutput(JsonValue.NULL);
return 0;
} catch (ClientException e) {
Common.printError(e);
return 1;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy