Search in sources :

Example 1 with IClient

use of com.dtstack.taier.pluginapi.client.IClient in project Taier by DTStack.

the class ClientCache method getClient.

/**
 * @param pluginInfo 集群配置信息
 * @return
 */
public IClient getClient(String pluginInfo) throws ClientAccessException {
    String typeName = "";
    try {
        if (StringUtils.isBlank(pluginInfo)) {
            throw new RdosDefineException("plugin info is empty");
        }
        Properties properties = PublicUtil.jsonStrToObjectWithOutNull(pluginInfo, Properties.class);
        typeName = properties.getProperty(ConfigConstant.TYPE_NAME_KEY);
        if (StringUtils.isBlank(typeName)) {
            throw new RdosDefineException("typeName  is empty");
        }
        String md5plugin = MD5Util.getMd5String(pluginInfo);
        String md5sum = null;
        if (!properties.containsKey(MD5_SUM_KEY) || (md5sum = MathUtil.getString(properties.get(MD5_SUM_KEY))) == null) {
            String md5zip = MathUtil.getString(properties.get(MD5_ZIP_KEY));
            if (md5zip == null) {
                md5zip = "";
            }
            md5sum = md5zip + md5plugin;
            properties.setProperty(MD5_SUM_KEY, md5sum);
        }
        Map<String, IClient> clientMap = cache.computeIfAbsent(typeName, k -> Maps.newConcurrentMap());
        IClient client = clientMap.get(md5sum);
        if (client == null) {
            synchronized (clientMap) {
                client = clientMap.get(md5sum);
                if (client == null) {
                    client = ClientFactory.buildPluginClient(pluginInfo, pluginPath);
                    client.init(properties);
                    clientMap.putIfAbsent(md5sum, client);
                }
            }
        }
        return client;
    } catch (Throwable e) {
        LOGGER.error("------- typeName {}  plugin info {} get client error ", typeName, pluginInfo, e);
        throw new ClientAccessException(e);
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IClient(com.dtstack.taier.pluginapi.client.IClient) Properties(java.util.Properties) ClientAccessException(com.dtstack.taier.common.exception.ClientAccessException)

Example 2 with IClient

use of com.dtstack.taier.pluginapi.client.IClient in project Taier by DTStack.

the class ClientOperator method stopJob.

public JobResult stopJob(JobClient jobClient) throws Exception {
    if (jobClient.getEngineTaskId() == null) {
        return JobResult.createSuccessResult(jobClient.getJobId());
    }
    JobIdentifier jobIdentifier = new JobIdentifier(jobClient.getEngineTaskId(), jobClient.getApplicationId(), jobClient.getJobId(), jobClient.getTenantId(), jobClient.getTaskType(), jobClient.getDeployMode(), jobClient.getUserId(), jobClient.getPluginInfo(), jobClient.getComponentVersion());
    jobIdentifier.setForceCancel(jobClient.getForceCancel());
    checkoutOperator(jobClient.getPluginInfo(), jobIdentifier);
    jobIdentifier.setTimeout(getCheckoutTimeout(jobClient));
    IClient client = clientCache.getClient(jobClient.getPluginInfo());
    return client.cancelJob(jobIdentifier);
}
Also used : IClient(com.dtstack.taier.pluginapi.client.IClient) JobIdentifier(com.dtstack.taier.pluginapi.JobIdentifier)

Example 3 with IClient

use of com.dtstack.taier.pluginapi.client.IClient in project Taier by DTStack.

the class ClientOperator method getJobStatus.

public TaskStatus getJobStatus(String pluginInfo, JobIdentifier jobIdentifier) {
    checkoutOperator(pluginInfo, jobIdentifier);
    String jobId = jobIdentifier.getEngineJobId();
    if (Strings.isNullOrEmpty(jobId) && Strings.isNullOrEmpty(jobIdentifier.getApplicationId())) {
        throw new RdosDefineException("can't get job of jobId is empty or null!");
    }
    try {
        IClient client = clientCache.getClient(pluginInfo);
        Object result = client.getJobStatus(jobIdentifier);
        if (result == null) {
            return null;
        }
        return (TaskStatus) result;
    } catch (Exception e) {
        LOGGER.error("getStatus happens error:{}", jobId, e);
        return TaskStatus.NOTFOUND;
    }
}
Also used : RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException) IClient(com.dtstack.taier.pluginapi.client.IClient) JSONObject(com.alibaba.fastjson.JSONObject) TaskStatus(com.dtstack.taier.pluginapi.enums.TaskStatus) ClientAccessException(com.dtstack.taier.common.exception.ClientAccessException) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Example 4 with IClient

use of com.dtstack.taier.pluginapi.client.IClient in project Taier by DTStack.

the class ClientOperator method testConnect.

public ComponentTestResult testConnect(String pluginInfo) {
    JSONObject pluginConfig = JSONObject.parseObject(pluginInfo);
    String typeName = pluginConfig.getString(ConfigConstant.TYPE_NAME_KEY);
    IClient clusterClient = clientCache.getDefaultPlugin(typeName);
    return clusterClient.testConnect(pluginInfo);
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) IClient(com.dtstack.taier.pluginapi.client.IClient)

Example 5 with IClient

use of com.dtstack.taier.pluginapi.client.IClient in project Taier by DTStack.

the class ClientOperator method getEngineLog.

public String getEngineLog(String pluginInfo, JobIdentifier jobIdentifier) {
    checkoutOperator(pluginInfo, jobIdentifier);
    String logInfo;
    try {
        IClient client = clientCache.getClient(pluginInfo);
        logInfo = client.getJobLog(jobIdentifier);
    } catch (Exception e) {
        logInfo = ExceptionUtil.getErrorMessage(e);
    }
    return logInfo;
}
Also used : IClient(com.dtstack.taier.pluginapi.client.IClient) ClientAccessException(com.dtstack.taier.common.exception.ClientAccessException) RdosDefineException(com.dtstack.taier.common.exception.RdosDefineException)

Aggregations

IClient (com.dtstack.taier.pluginapi.client.IClient)7 JSONObject (com.alibaba.fastjson.JSONObject)3 ClientAccessException (com.dtstack.taier.common.exception.ClientAccessException)3 RdosDefineException (com.dtstack.taier.common.exception.RdosDefineException)3 JobIdentifier (com.dtstack.taier.pluginapi.JobIdentifier)2 Properties (java.util.Properties)2 JobClient (com.dtstack.taier.pluginapi.JobClient)1 TaskStatus (com.dtstack.taier.pluginapi.enums.TaskStatus)1 JobResult (com.dtstack.taier.pluginapi.pojo.JobResult)1 ParamAction (com.dtstack.taier.pluginapi.pojo.ParamAction)1 Map (java.util.Map)1