use of com.qlangtech.tis.coredefine.module.action.impl.RcDeployment 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.coredefine.module.action.impl.RcDeployment in project plugins by qlangtech.
the class K8SController method getRCDeployment.
// private List<V1EnvVar> addEnvVars(String indexName, long timestamp) {
// List<V1EnvVar> envVars = Lists.newArrayList();
// V1EnvVar var = new V1EnvVar();
// var.setName("JVM_PROPERTY");
// var.setValue("-Ddata.dir=/opt/data -D" + Config.KEY_JAVA_RUNTIME_PROP_ENV_PROPS + "=true");
// envVars.add(var);
//
// RunEnvironment runtime = RunEnvironment.getSysRuntime();
// var = new V1EnvVar();
// var.setName("JAVA_RUNTIME");
// var.setValue(runtime.getKeyName());
// envVars.add(var);
// var = new V1EnvVar();
// var.setName("APP_OPTIONS");
// var.setValue(indexName + " " + timestamp);
// envVars.add(var);
//
// var = new V1EnvVar();
// var.setName("APP_NAME");
// var.setValue("tis-incr");
// envVars.add(var);
//
// var = new V1EnvVar();
// var.setName(Config.KEY_RUNTIME);
// var.setValue(runtime.getKeyName());
// envVars.add(var);
//
// var = new V1EnvVar();
// var.setName(Config.KEY_ZK_HOST);
// var.setValue(Config.getZKHost());
// envVars.add(var);
//
// var = new V1EnvVar();
// var.setName(Config.KEY_ASSEMBLE_HOST);
// var.setValue(Config.getAssembleHost());
// envVars.add(var);
//
// var = new V1EnvVar();
// var.setName(Config.KEY_TIS_HOST);
// var.setValue(Config.getTisHost());
// envVars.add(var);
//
// return envVars;
//
// }
// /**
// * 取得RC实体对象,有即证明已经完成发布流程
// *
// * @return
// */
// @Override
// public RcDeployment getRCDeployment(String collection) {
// return getRcDeployment(api, this.config, collection);
// }
@Override
public RcDeployment getRCDeployment(TargetResName tisInstanceName) {
Objects.requireNonNull(api, "param api can not be null");
Objects.requireNonNull(config, "param config can not be null");
RcDeployment rcDeployment = null;
try {
V1ReplicationController rc = api.readNamespacedReplicationController(tisInstanceName.getK8SResName(), config.getNamespace(), resultPrettyShow, null, null);
if (rc == null) {
return null;
}
rcDeployment = new RcDeployment();
fillSpecInfo(rcDeployment, rc.getSpec().getReplicas(), rc.getSpec().getTemplate());
V1ReplicationControllerStatus status = rc.getStatus();
RcDeployment.ReplicationControllerStatus rControlStatus = new RcDeployment.ReplicationControllerStatus();
rControlStatus.setAvailableReplicas(status.getAvailableReplicas());
rControlStatus.setFullyLabeledReplicas(status.getFullyLabeledReplicas());
rControlStatus.setObservedGeneration(status.getObservedGeneration());
rControlStatus.setReadyReplicas(status.getReadyReplicas());
rControlStatus.setReplicas(status.getReplicas());
rcDeployment.setStatus(rControlStatus);
fillCreateTimestamp(rcDeployment, rc.getMetadata());
fillPods(this.api, this.config, rcDeployment, tisInstanceName);
} catch (ApiException e) {
if (e.getCode() == 404) {
logger.warn("can not get collection rc deployment:" + tisInstanceName.getK8SResName());
return null;
} else {
// new RuntimeException("code:" + e.getCode() + "\n" + e.getResponseBody(), e);
throw K8sExceptionUtils.convert("code:" + e.getCode(), e);
}
}
return rcDeployment;
}
use of com.qlangtech.tis.coredefine.module.action.impl.RcDeployment in project plugins by qlangtech.
the class TestDefaultIncrK8sConfig method testCreateIncrDeployment.
public void testCreateIncrDeployment() throws Exception {
IRCController incr = incrFactory.getIncrSync();
assertNotNull(incr);
assertFalse(s4totalpay + " shall have not deploy incr instance in k8s", incr.getRCDeployment(new TargetResName(s4totalpay)) != null);
RcDeployment incrSpec = new RcDeployment();
incrSpec.setCpuLimit(Specification.parse("1"));
incrSpec.setCpuRequest(Specification.parse("500m"));
incrSpec.setMemoryLimit(Specification.parse("1G"));
incrSpec.setMemoryRequest(Specification.parse("500M"));
incrSpec.setReplicaCount(1);
long timestamp = 20190820171040l;
try {
incr.deploy(new TargetResName(s4totalpay), incrSpec, timestamp);
} catch (Exception e) {
throw e;
}
}
use of com.qlangtech.tis.coredefine.module.action.impl.RcDeployment in project tis by qlangtech.
the class CoreAction method getIndexIncrStatus.
public static IndexIncrStatus getIndexIncrStatus(BasicModule module, boolean getRcConfigInCache) throws Exception {
IndexIncrStatus incrStatus = doGetDataXReaderWriterDesc(module.getCollectionName());
// 是否可以取缓存中的deployment信息,在刚删除pod重启之后需要取全新的deployment信息不能缓存
IPluginStore<IncrStreamFactory> store = getIncrStreamFactoryStore(module);
if (store.getPlugin() == null) {
incrStatus.setK8sPluginInitialized(false);
return incrStatus;
}
incrStatus.setK8sPluginInitialized(true);
IndexStreamCodeGenerator indexStreamCodeGenerator = getIndexStreamCodeGenerator(module);
StreamCodeContext streamCodeContext = new StreamCodeContext(module.getCollectionName(), indexStreamCodeGenerator.incrScriptTimestamp);
incrStatus.setIncrScriptCreated(streamCodeContext.isIncrScriptDirCreated());
TISK8sDelegate k8s = TISK8sDelegate.getK8SDelegate(module.getCollectionName());
IDeploymentDetail rcConfig = k8s.getRcConfig(getRcConfigInCache);
incrStatus.setK8sReplicationControllerCreated(rcConfig != null);
if (rcConfig != null) {
rcConfig.accept(new IDeploymentDetail.IDeploymentDetailVisitor() {
@Override
public void visit(RcDeployment rcDeployment) {
incrStatus.setRcDeployment(rcDeployment);
}
@Override
public void visit(FlinkJobDeploymentDetails details) {
incrStatus.setFlinkJobDetail(details);
}
});
// JobType.RemoteCallResult<IndexJobRunningStatus> callResult
// = JobType.QueryIndexJobRunningStatus.assembIncrControlWithResult(
// getAssembleNodeAddress(module.getSolrZkClient()),
// module.getCollectionName(), Collections.emptyList(), IndexJobRunningStatus.class);
// if (callResult.success) {
incrStatus.setIncrProcess(null);
// }
}
return incrStatus;
}
Aggregations