Search in sources :

Example 1 with EnvVarsBuilder

use of com.qlangtech.tis.plugin.k8s.EnvVarsBuilder in project plugins by qlangtech.

the class K8SDataXJobWorker method launchService.

@Override
public void launchService() {
    if (inService()) {
        throw new IllegalStateException("k8s instance of:" + KEY_FIELD_NAME + " is running can not relaunch");
    }
    try {
        // 启动服务
        // ExponentialBackoffRetry retryPolicy = new ExponentialBackoffRetry(1000, 3);
        // CuratorFrameworkFactory.Builder curatorBuilder = CuratorFrameworkFactory.builder();
        // curatorBuilder.retryPolicy(retryPolicy);
        // this.client = curatorBuilder.connectString(this.zkAddress).build();
        K8sImage k8sImage = this.getK8SImage();
        // this.k8sClient = k8SImage.createApiClient();
        ReplicasSpec replicasSpec = this.getReplicasSpec();
        Objects.requireNonNull(replicasSpec, "replicasSpec can not be null");
        EnvVarsBuilder varsBuilder = new EnvVarsBuilder("tis-datax-executor") {

            @Override
            public String getAppOptions() {
                // return "-D" + DataxUtils.DATAX_QUEUE_ZK_PATH + "=" + getZkQueuePath() + " -D" + DataxUtils.DATAX_ZK_ADDRESS + "=" + getZookeeperAddress();
                return getZookeeperAddress() + " " + getZkQueuePath();
            }

            @Override
            public String getExtraSysProps() {
                return "-D" + CuratorDataXTaskMessage.SYSTEM_KEY_LOGBACK_PATH_KEY + "=" + CuratorDataXTaskMessage.SYSTEM_KEY_LOGBACK_PATH_VALUE;
            }

            @Override
            protected String processHost(String address) {
                return processDefaultHost(address);
            }
        };
        // K8sImage config, CoreV1Api api, String name, ReplicasSpec incrSpec, List< V1EnvVar > envs
        // CoreV1Api k8sV1Api = new CoreV1Api(k8sClient);
        // K8sImage k8sImage = this.getK8SImage();
        this.getK8SController().createReplicationController(K8S_DATAX_INSTANCE_NAME, replicasSpec, varsBuilder.build());
        if (supportHPA()) {
            HorizontalpodAutoscaler hap = this.getHpa();
            createHorizontalpodAutoscaler(k8sImage, hap);
        }
        writeLaunchToken();
    } catch (ApiException e) {
        logger.error(e.getResponseBody(), e);
        throw K8sExceptionUtils.convert(e);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : EnvVarsBuilder(com.qlangtech.tis.plugin.k8s.EnvVarsBuilder) HorizontalpodAutoscaler(com.qlangtech.tis.config.k8s.HorizontalpodAutoscaler) ReplicasSpec(com.qlangtech.tis.config.k8s.ReplicasSpec) ApiException(io.kubernetes.client.openapi.ApiException) K8sImage(com.qlangtech.tis.plugin.k8s.K8sImage) ApiException(io.kubernetes.client.openapi.ApiException)

Aggregations

HorizontalpodAutoscaler (com.qlangtech.tis.config.k8s.HorizontalpodAutoscaler)1 ReplicasSpec (com.qlangtech.tis.config.k8s.ReplicasSpec)1 EnvVarsBuilder (com.qlangtech.tis.plugin.k8s.EnvVarsBuilder)1 K8sImage (com.qlangtech.tis.plugin.k8s.K8sImage)1 ApiException (io.kubernetes.client.openapi.ApiException)1