use of com.qlangtech.tis.plugin.k8s.K8sImage in project plugins by qlangtech.
the class FlinkK8SClusterManager method listPodAndWatchLog.
@Override
public WatchPodLog listPodAndWatchLog(String podName, ILogListener listener) {
K8sImage k8sImage = this.getK8SImage();
ApiClient apiClient = k8sImage.createApiClient();
return K8SController.listPodAndWatchLog(apiClient, k8sImage, "flink-main-container", new TargetResName(this.clusterId), podName, listener);
}
use of com.qlangtech.tis.plugin.k8s.K8sImage in project plugins by qlangtech.
the class FlinkK8SClusterManager method getRCDeployment.
@Override
public RcDeployment getRCDeployment() {
RcDeployment deployment = new RcDeployment();
K8sImage k8sImage = this.getK8SImage();
ApiClient apiClient = k8sImage.createApiClient();
AppsV1Api appsApi = new AppsV1Api(apiClient);
CoreV1Api coreApi = new CoreV1Api(apiClient);
// String name, String namespace, String pretty, Boolean exact, Boolean export
try {
V1Deployment deploy = appsApi.readNamespacedDeployment(this.clusterId, k8sImage.getNamespace(), "true", null, null);
K8SController.fillSpecInfo(deployment, deploy.getSpec().getReplicas(), deploy.getSpec().getTemplate());
V1DeploymentStatus status = deploy.getStatus();
RcDeployment.ReplicationControllerStatus deploymentStatus = new RcDeployment.ReplicationControllerStatus();
deploymentStatus.setAvailableReplicas(status.getAvailableReplicas());
deploymentStatus.setFullyLabeledReplicas(0);
deploymentStatus.setObservedGeneration(status.getObservedGeneration());
deploymentStatus.setReadyReplicas(status.getReadyReplicas());
deploymentStatus.setReplicas(status.getReplicas());
deployment.setStatus(deploymentStatus);
K8SController.fillCreateTimestamp(deployment, deploy.getMetadata());
K8SController.fillPods(coreApi, k8sImage, deployment, new TargetResName(this.clusterId));
} catch (ApiException e) {
throw K8sExceptionUtils.convert(this.clusterId, e);
}
return deployment;
}
use of com.qlangtech.tis.plugin.k8s.K8sImage in project plugins by qlangtech.
the class K8SDataXJobWorker method remove.
@Override
public void remove() {
K8SController k8SController = getK8SController();
// ApiClient k8SApi = getK8SApi();
k8SController.removeInstance(K8S_DATAX_INSTANCE_NAME);
try {
if (supportHPA()) {
K8sImage k8SImage = this.getK8SImage();
AutoscalingV2beta1Api hpaApi = new AutoscalingV2beta1Api(this.getK8SApi());
// String name,
// String namespace,
// String pretty,
// String dryRun,
// Integer gracePeriodSeconds,
// Boolean orphanDependents,
// String propagationPolicy,
// V1DeleteOptions body
hpaApi.deleteNamespacedHorizontalPodAutoscaler(this.getHpaName(), k8SImage.getNamespace(), K8SController.resultPrettyShow, null, null, null, null, null);
}
} catch (ApiException e) {
// new RuntimeException("code:" + e.getCode() + ",reason:" + e.getResponseBody(), e);
throw K8sExceptionUtils.convert("code:" + e.getCode(), e);
}
this.deleteLaunchToken();
}
use of com.qlangtech.tis.plugin.k8s.K8sImage in project plugins by qlangtech.
the class K8SDataXJobWorker method getHpaStatus.
@Override
public RcHpaStatus getHpaStatus() {
try {
AutoscalingV1Api hpaApi = new AutoscalingV1Api(this.getK8SApi());
K8sImage k8SImage = this.getK8SImage();
// String name, String namespace, String pretty
V1HorizontalPodAutoscaler autoscaler = hpaApi.readNamespacedHorizontalPodAutoscalerStatus(this.getHpaName(), k8SImage.getNamespace(), K8SController.resultPrettyShow);
V1HorizontalPodAutoscalerSpec spec = autoscaler.getSpec();
RcHpaStatus.HpaAutoscalerSpec autoscalerSpec = new RcHpaStatus.HpaAutoscalerSpec();
autoscalerSpec.setMaxReplicas(spec.getMaxReplicas());
autoscalerSpec.setMinReplicas(spec.getMinReplicas());
autoscalerSpec.setTargetCPUUtilizationPercentage(spec.getTargetCPUUtilizationPercentage());
V1HorizontalPodAutoscalerStatus status = autoscaler.getStatus();
RcHpaStatus.HpaAutoscalerStatus autoscalerStatus = new RcHpaStatus.HpaAutoscalerStatus();
autoscalerStatus.setCurrentCPUUtilizationPercentage(status.getCurrentCPUUtilizationPercentage());
autoscalerStatus.setCurrentReplicas(status.getCurrentReplicas());
autoscalerStatus.setDesiredReplicas(status.getDesiredReplicas());
if (status.getLastScaleTime() != null) {
autoscalerStatus.setLastScaleTime(status.getLastScaleTime().getMillis());
}
V1ObjectMeta metadata = autoscaler.getMetadata();
Objects.requireNonNull(metadata, "hpa:" + this.getHpaName() + "relevant metadata can not be null");
Map<String, String> annotations = metadata.getAnnotations();
// [{
// "type": "AbleToScale",
// "status": "True",
// "lastTransitionTime": "2021-06-07T03:52:46Z",
// "reason": "ReadyForNewScale",
// "message": "recommended size matches current size "
// }, {
// "type ": "ScalingActive ",
// "status ": "True ",
// "lastTransitionTime": "2021 - 06 - 08 T00: 08: 17 Z ",
// "reason ": "ValidMetricFound ",
// "message ": "the HPA was able to successfully calculate a replica count from cpu resource utilization(percentage of request)"
// }, {
// "type ": "ScalingLimited ",
// "status ": "True ",
// "lastTransitionTime ": "2021 - 06 - 08 T00: 12: 19 Z ",
// "reason ": "TooFewReplicas ",
// "message ": "The desired replica count is less than the minimum replica count "
// }]
List<RcHpaStatus.HpaConditionEvent> conditions = JSON.parseArray(annotations.get("autoscaling.alpha.kubernetes.io/conditions"), RcHpaStatus.HpaConditionEvent.class);
// JSONObject condition = null;
// for (int i = 0; i < conditions.size(); i++) {
// condition = conditions.getJSONObject(i);
// condition.get
// }
// [{
// "type": "Resource",
// "resource": {
// "name": "cpu",
// "currentAverageUtilization": 0,
// "currentAverageValue": "1m"
// }
// }]
List<RcHpaStatus.HpaMetrics> currentMetrics = JSON.parseArray(annotations.get("autoscaling.alpha.kubernetes.io/current-metrics"), RcHpaStatus.HpaMetrics.class);
RcHpaStatus hpaStatus = new RcHpaStatus(conditions, currentMetrics);
hpaStatus.setAutoscalerStatus(autoscalerStatus);
hpaStatus.setAutoscalerSpec(autoscalerSpec);
return hpaStatus;
} catch (ApiException e) {
// throw new RuntimeException("code:" + e.getCode() + ",reason:" + e.getResponseBody(), e);
throw K8sExceptionUtils.convert(e);
}
}
use of com.qlangtech.tis.plugin.k8s.K8sImage 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);
}
}
Aggregations