Search in sources :

Example 1 with UpgradeThread

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();
}
Also used : HashMap(java.util.HashMap) UpgradeThread(io.nuls.client.rpc.resources.thread.UpgradeThread) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with UpgradeThread

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();
}
Also used : HashMap(java.util.HashMap) UpgradeThread(io.nuls.client.rpc.resources.thread.UpgradeThread) SyncVersionRunner(io.nuls.client.version.SyncVersionRunner) URL(java.net.URL) RpcClientResult(io.nuls.kernel.model.RpcClientResult) Result(io.nuls.kernel.model.Result) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

UpgradeThread (io.nuls.client.rpc.resources.thread.UpgradeThread)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 HashMap (java.util.HashMap)2 SyncVersionRunner (io.nuls.client.version.SyncVersionRunner)1 Result (io.nuls.kernel.model.Result)1 RpcClientResult (io.nuls.kernel.model.RpcClientResult)1 URL (java.net.URL)1