use of io.nuls.client.rpc.resources.thread.UpgradeThread in project nuls by nuls-io.
the class ClientResource method stopUpdate.
@POST
@Path("/upgrade/stop")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "停止升级")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = Boolean.class) })
public RpcClientResult stopUpdate() {
UpgradeThread thread = UpgradeThread.getInstance();
if (!thread.isUpgrading()) {
return Result.getFailed(KernelErrorCode.NOT_UPGRADING).toRpcClientResult();
}
if (thread.getProcess().getPercentage() == 100) {
return Result.getFailed(KernelErrorCode.UPGRADING).toRpcClientResult();
}
boolean result = thread.stop();
if (result) {
Map<String, Boolean> map = new HashMap<>();
map.put("value", true);
return Result.getSuccess().setData(map).toRpcClientResult();
}
return Result.getFailed(KernelErrorCode.FAILED).toRpcClientResult();
}
use of io.nuls.client.rpc.resources.thread.UpgradeThread in project nuls by nuls-io.
the class ClientResource method startUpdate.
@POST
@Path("/upgrade/{version}")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "升级")
@ApiResponses(value = { @ApiResponse(code = 200, message = "success", response = Boolean.class) })
public RpcClientResult startUpdate(@PathParam("version") String version) {
AssertUtil.canNotEmpty(version);
SyncVersionRunner syncor = SyncVersionRunner.getInstance();
String newestVersion = syncor.getNewestVersion();
if (!VersionUtils.higherThan(newestVersion, NulsConfig.VERSION)) {
Result result = Result.getFailed(KernelErrorCode.NONEWVER);
return result.toRpcClientResult();
}
if (!version.equals(newestVersion)) {
Result result = Result.getFailed(KernelErrorCode.VERSION_NOT_NEWEST);
return result.toRpcClientResult();
}
URL url = ClientResource.class.getClassLoader().getResource("libs");
if (null == url) {
return Result.getFailed(KernelErrorCode.DATA_NOT_FOUND).toRpcClientResult();
}
UpgradeThread thread = UpgradeThread.getInstance();
if (thread.isUpgrading()) {
return Result.getFailed(KernelErrorCode.UPGRADING).toRpcClientResult();
}
boolean result = thread.start();
if (result) {
TaskManager.createAndRunThread((short) 1, "upgrade", thread);
Map<String, Boolean> map = new HashMap<>();
map.put("value", true);
return Result.getSuccess().setData(map).toRpcClientResult();
}
return Result.getFailed(KernelErrorCode.FAILED).toRpcClientResult();
}
Aggregations