Search in sources :

Example 1 with AdminBiz

use of com.xxl.job.core.biz.AdminBiz in project xxl-job by xuxueli.

the class AdminBizTest method registryTest.

/**
 * registry executor
 *
 * @throws Exception
 */
@Test
public void registryTest() throws Exception {
    AdminBiz adminBiz = (AdminBiz) new NetComClientProxy(AdminBiz.class, addressUrl, accessToken).getObject();
    // test executor registry
    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
    ReturnT<String> returnT = adminBiz.registry(registryParam);
    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
}
Also used : AdminBiz(com.xxl.job.core.biz.AdminBiz) NetComClientProxy(com.xxl.job.core.rpc.netcom.NetComClientProxy) RegistryParam(com.xxl.job.core.biz.model.RegistryParam) Test(org.junit.Test)

Example 2 with AdminBiz

use of com.xxl.job.core.biz.AdminBiz in project xxl-job by xuxueli.

the class ExecutorRegistryThread method start.

public void start(final int port, final String ip, final String appName) {
    // valid
    if (appName == null || appName.trim().length() == 0) {
        logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, appName is null.");
        return;
    }
    if (XxlJobExecutor.getAdminBizList() == null) {
        logger.warn(">>>>>>>>>>> xxl-job, executor registry config fail, adminAddresses is null.");
        return;
    }
    // executor address (generate addredd = ip:port)
    final String executorAddress;
    if (ip != null && ip.trim().length() > 0) {
        executorAddress = ip.trim().concat(":").concat(String.valueOf(port));
    } else {
        executorAddress = IpUtil.getIpPort(port);
    }
    registryThread = new Thread(new Runnable() {

        @Override
        public void run() {
            // registry
            while (!toStop) {
                try {
                    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress);
                    for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                        try {
                            ReturnT<String> registryResult = adminBiz.registry(registryParam);
                            if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                                registryResult = ReturnT.SUCCESS;
                                logger.info(">>>>>>>>>>> xxl-job registry success, registryParam:{}, registryResult:{}", new Object[] { registryParam, registryResult });
                                break;
                            } else {
                                logger.info(">>>>>>>>>>> xxl-job registry fail, registryParam:{}, registryResult:{}", new Object[] { registryParam, registryResult });
                            }
                        } catch (Exception e) {
                            logger.info(">>>>>>>>>>> xxl-job registry error, registryParam:{}", registryParam, e);
                        }
                    }
                } catch (Exception e) {
                    logger.error(e.getMessage(), e);
                }
                try {
                    TimeUnit.SECONDS.sleep(RegistryConfig.BEAT_TIMEOUT);
                } catch (InterruptedException e) {
                    logger.error(e.getMessage(), e);
                }
            }
            // registry remove
            try {
                RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), appName, executorAddress);
                for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
                    try {
                        ReturnT<String> registryResult = adminBiz.registryRemove(registryParam);
                        if (registryResult != null && ReturnT.SUCCESS_CODE == registryResult.getCode()) {
                            registryResult = ReturnT.SUCCESS;
                            logger.info(">>>>>>>>>>> xxl-job registry-remove success, registryParam:{}, registryResult:{}", new Object[] { registryParam, registryResult });
                            break;
                        } else {
                            logger.info(">>>>>>>>>>> xxl-job registry-remove fail, registryParam:{}, registryResult:{}", new Object[] { registryParam, registryResult });
                        }
                    } catch (Exception e) {
                        logger.info(">>>>>>>>>>> xxl-job registry-remove error, registryParam:{}", registryParam, e);
                    }
                }
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
            logger.info(">>>>>>>>>>> xxl-job, executor registry thread destory.");
        }
    });
    registryThread.setDaemon(true);
    registryThread.start();
}
Also used : AdminBiz(com.xxl.job.core.biz.AdminBiz) RegistryParam(com.xxl.job.core.biz.model.RegistryParam)

Example 3 with AdminBiz

use of com.xxl.job.core.biz.AdminBiz in project xxl-job by xuxueli.

the class TriggerCallbackThread method doCallback.

/**
 * do callback, will retry if error
 * @param callbackParamList
 */
private void doCallback(List<HandleCallbackParam> callbackParamList) {
    // callback, will retry if error
    for (AdminBiz adminBiz : XxlJobExecutor.getAdminBizList()) {
        try {
            ReturnT<String> callbackResult = adminBiz.callback(callbackParamList);
            if (callbackResult != null && ReturnT.SUCCESS_CODE == callbackResult.getCode()) {
                callbackResult = ReturnT.SUCCESS;
                logger.info(">>>>>>>>>>> xxl-job callback success, callbackParamList:{}, callbackResult:{}", new Object[] { callbackParamList, callbackResult });
                break;
            } else {
                logger.info(">>>>>>>>>>> xxl-job callback fail, callbackParamList:{}, callbackResult:{}", new Object[] { callbackParamList, callbackResult });
            }
        } catch (Exception e) {
            logger.error(">>>>>>>>>>> xxl-job callback error, callbackParamList:{}", callbackParamList, e);
        // getInstance().callBackQueue.addAll(callbackParamList);
        }
    }
}
Also used : AdminBiz(com.xxl.job.core.biz.AdminBiz)

Example 4 with AdminBiz

use of com.xxl.job.core.biz.AdminBiz in project xxl-job by xuxueli.

the class AdminBizTest method registryRemove.

/**
 * registry executor remove
 *
 * @throws Exception
 */
@Test
public void registryRemove() throws Exception {
    AdminBiz adminBiz = (AdminBiz) new NetComClientProxy(AdminBiz.class, addressUrl, accessToken).getObject();
    // test executor registry remove
    RegistryParam registryParam = new RegistryParam(RegistryConfig.RegistType.EXECUTOR.name(), "xxl-job-executor-example", "127.0.0.1:9999");
    ReturnT<String> returnT = adminBiz.registryRemove(registryParam);
    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
}
Also used : AdminBiz(com.xxl.job.core.biz.AdminBiz) NetComClientProxy(com.xxl.job.core.rpc.netcom.NetComClientProxy) RegistryParam(com.xxl.job.core.biz.model.RegistryParam) Test(org.junit.Test)

Example 5 with AdminBiz

use of com.xxl.job.core.biz.AdminBiz in project xxl-job by xuxueli.

the class AdminBizTest method triggerJob.

/**
 * trigger job for once
 *
 * @throws Exception
 */
@Test
public void triggerJob() throws Exception {
    AdminBiz adminBiz = (AdminBiz) new NetComClientProxy(AdminBiz.class, addressUrl, accessToken).getObject();
    int jobId = 1;
    ReturnT<String> returnT = adminBiz.triggerJob(jobId);
    Assert.assertTrue(returnT.getCode() == ReturnT.SUCCESS_CODE);
}
Also used : AdminBiz(com.xxl.job.core.biz.AdminBiz) NetComClientProxy(com.xxl.job.core.rpc.netcom.NetComClientProxy) Test(org.junit.Test)

Aggregations

AdminBiz (com.xxl.job.core.biz.AdminBiz)6 NetComClientProxy (com.xxl.job.core.rpc.netcom.NetComClientProxy)4 RegistryParam (com.xxl.job.core.biz.model.RegistryParam)3 Test (org.junit.Test)3