Search in sources :

Example 6 with CronPattern

use of cn.hutool.cron.pattern.CronPattern in project hutool by dromara.

the class TaskTableTest method toStringTest.

@Test
@Ignore
public void toStringTest() {
    final TaskTable taskTable = new TaskTable();
    taskTable.add(IdUtil.fastUUID(), new CronPattern("*/10 * * * * *"), () -> Console.log("Task 1"));
    taskTable.add(IdUtil.fastUUID(), new CronPattern("*/20 * * * * *"), () -> Console.log("Task 2"));
    taskTable.add(IdUtil.fastUUID(), new CronPattern("*/30 * * * * *"), () -> Console.log("Task 3"));
    Console.log(taskTable);
}
Also used : CronPattern(cn.hutool.cron.pattern.CronPattern) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 7 with CronPattern

use of cn.hutool.cron.pattern.CronPattern in project Jpom by dromara.

the class ScriptController method save.

@RequestMapping(value = "save.json", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
public String save(NodeScriptModel nodeScriptModel, String type) {
    Assert.notNull(nodeScriptModel, "没有数据");
    Assert.hasText(nodeScriptModel.getContext(), "内容为空");
    // 
    String autoExecCron = nodeScriptModel.getAutoExecCron();
    if (StrUtil.isNotEmpty(autoExecCron)) {
        try {
            new CronPattern(autoExecCron);
        } catch (Exception e) {
            throw new IllegalArgumentException("定时执行表达式格式不正确");
        }
    }
    nodeScriptModel.setWorkspaceId(getWorkspaceId());
    // 
    nodeScriptModel.setContext(HtmlUtil.unescape(nodeScriptModel.getContext()));
    NodeScriptModel eModel = nodeScriptServer.getItem(nodeScriptModel.getId());
    boolean needCreate = false;
    if ("add".equalsIgnoreCase(type)) {
        Assert.isNull(eModel, "id已经存在啦");
        nodeScriptModel.setId(IdUtil.fastSimpleUUID());
        File file = nodeScriptModel.getFile(true);
        if (file.exists() || file.isDirectory()) {
            return JsonMessage.getString(405, "当地id路径文件已经存在来,请修改");
        }
        nodeScriptServer.addItem(nodeScriptModel);
        return JsonMessage.getString(200, "添加成功");
    } else if ("sync".equalsIgnoreCase(type)) {
        if (eModel == null) {
            eModel = new NodeScriptModel();
            eModel.setId(nodeScriptModel.getId());
            needCreate = true;
        }
        eModel.setScriptType("server-sync");
    }
    Assert.notNull(eModel, "对应数据不存在");
    eModel.setName(nodeScriptModel.getName());
    eModel.setAutoExecCron(autoExecCron);
    eModel.setDescription(nodeScriptModel.getDescription());
    eModel.setContext(nodeScriptModel.getContext());
    eModel.setDefArgs(nodeScriptModel.getDefArgs());
    if (needCreate) {
        nodeScriptServer.addItem(eModel);
    } else {
        nodeScriptServer.updateItem(eModel);
    }
    return JsonMessage.getString(200, "修改成功");
}
Also used : NodeScriptModel(io.jpom.model.data.NodeScriptModel) CronPattern(cn.hutool.cron.pattern.CronPattern) File(java.io.File) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with CronPattern

use of cn.hutool.cron.pattern.CronPattern in project Jpom by dromara.

the class CommandInfoController method edit.

/**
 * 新建/编辑命令
 *
 * @param data 命令信息
 * @return result
 *
 * @api {POST} node/ssh_command/edit 新建/编辑命令
 * @apiGroup node/ssh_command
 * @apiUse defResultJson
 * @apiBody {String} name           命令名称
 * @apiBody {String} command        命令内容
 * @apiBody {String} [desc]         命令描述
 * @apiBody {String} defParams      默认参数
 * @apiBody {String} autoExecCron   定时构建表达式
 * @apiBody {String} id             命令主键 ID
 * @apiBody {String} [sshIds]       SSH 节点
 */
@RequestMapping(value = "edit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String edit(@RequestBody JSONObject data) {
    String name = data.getString("name");
    String command = data.getString("command");
    String desc = data.getString("desc");
    String defParams = data.getString("defParams");
    Assert.hasText(name, "请输入命令名称");
    Assert.hasText(command, "请输入命令内容");
    String autoExecCron = data.getString("autoExecCron");
    String id = data.getString("id");
    // 
    CommandModel commandModel = new CommandModel();
    commandModel.setName(name);
    commandModel.setCommand(command);
    commandModel.setDesc(desc);
    commandModel.setSshIds(data.getString("sshIds"));
    if (StrUtil.isNotEmpty(autoExecCron)) {
        try {
            new CronPattern(autoExecCron);
        } catch (Exception e) {
            throw new IllegalArgumentException("定时构建表达式格式不正确");
        }
    }
    commandModel.setAutoExecCron(autoExecCron);
    // 
    if (StrUtil.isNotEmpty(defParams)) {
        List<CommandModel.CommandParam> params = CommandModel.params(defParams);
        if (params == null) {
            commandModel.setDefParams(StrUtil.EMPTY);
        } else {
            commandModel.setDefParams(JSONObject.toJSONString(params));
        }
    } else {
        commandModel.setDefParams(StrUtil.EMPTY);
    }
    if (StrUtil.isEmpty(id)) {
        commandService.insert(commandModel);
    } else {
        commandModel.setId(id);
        commandService.updateById(commandModel, getRequest());
    }
    return JsonMessage.getString(200, "操作成功");
}
Also used : CommandModel(io.jpom.model.data.CommandModel) CronPattern(cn.hutool.cron.pattern.CronPattern) IOException(java.io.IOException) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CronPattern (cn.hutool.cron.pattern.CronPattern)8 Test (org.junit.Test)5 IOException (java.io.IOException)2 Ignore (org.junit.Ignore)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CommandModel (io.jpom.model.data.CommandModel)1 NodeScriptModel (io.jpom.model.data.NodeScriptModel)1 UserModel (io.jpom.model.data.UserModel)1 ClassFeature (io.jpom.permission.ClassFeature)1 Feature (io.jpom.permission.Feature)1 MethodFeature (io.jpom.permission.MethodFeature)1 File (java.io.File)1