use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.
the class ContainerServiceImpl method removeContainer.
@Override
public void removeContainer(String taskId) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
ContainerToken containerToken = getContainerToken();
String dcosTaskIdNodePath = ContainerNodePath.getDcosTaskIdNodePath(taskId);
if (!curatorFrameworkOp.checkExists(dcosTaskIdNodePath)) {
throw new SaturnJobConsoleException("The taskId already exists");
}
List<ContainerScaleJobVo> containerScaleJobVos = getContainerScaleJobVos(taskId);
List<String> allUnSystemJobs = jobDimensionService.getAllUnSystemJobs(curatorFrameworkOp);
for (String job : allUnSystemJobs) {
String preferListNodePath = JobNodePath.getConfigNodePath(job, "preferList");
if (curatorFrameworkOp.checkExists(preferListNodePath)) {
String preferList = curatorFrameworkOp.getData(preferListNodePath);
if (preferList != null) {
String[] split = preferList.trim().split(",");
for (String tmp : split) {
if (tmp.trim().equals("@" + taskId)) {
throw new SaturnJobConsoleException("Cannot destroy the container, because it's binding a job");
}
}
}
}
}
for (ContainerScaleJobVo containerScaleJobVo : containerScaleJobVos) {
deleteContainerScaleJob(taskId, containerScaleJobVo.getJobName());
}
getContainerRestService().destroy(containerToken, taskId);
curatorFrameworkOp.deleteRecursive(dcosTaskIdNodePath);
}
use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.
the class ContainerServiceImpl method getContainerScaleJobVos.
@Override
public List<ContainerScaleJobVo> getContainerScaleJobVos(String taskId) throws SaturnJobConsoleException {
List<ContainerScaleJobVo> containerScaleJobVos = new ArrayList<>();
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
String dcosTaskScaleJobsNodePath = ContainerNodePath.getDcosTaskScaleJobsNodePath(taskId);
if (curatorFrameworkOp.checkExists(dcosTaskScaleJobsNodePath)) {
List<String> jobs = curatorFrameworkOp.getChildren(dcosTaskScaleJobsNodePath);
if (jobs != null) {
for (String job : jobs) {
ContainerScaleJobVo containerScaleJobVo = getContainerScaleJobVo(taskId, job);
if (containerScaleJobVo != null) {
containerScaleJobVos.add(containerScaleJobVo);
}
}
}
}
Collections.sort(containerScaleJobVos, new Comparator<ContainerScaleJobVo>() {
@Override
public int compare(ContainerScaleJobVo o1, ContainerScaleJobVo o2) {
return o1.getJobName().compareTo(o2.getJobName());
}
});
return containerScaleJobVos;
}
use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.
the class ContainerServiceImpl method getContainerScaleJobVo.
@Override
public ContainerScaleJobVo getContainerScaleJobVo(String taskId, String jobName) throws SaturnJobConsoleException {
ContainerScaleJobVo containerScaleJobVo = null;
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
try {
ContainerScaleJob containerScaleJob = getContainerScaleJob(curatorFrameworkOp, taskId, jobName);
ContainerScaleJobConfig containerScaleJobConfig = containerScaleJob.getContainerScaleJobConfig();
containerScaleJobVo = new ContainerScaleJobVo();
containerScaleJobVo.setJobName(containerScaleJobConfig.getJobName());
containerScaleJobVo.setJobDesc(containerScaleJobConfig.getJobDesc());
if (containerScaleJobConfig.getInstances() != null) {
containerScaleJobVo.setInstances(containerScaleJobConfig.getInstances().toString());
}
if (containerScaleJobConfig.getTimeZone() == null) {
containerScaleJobVo.setTimeZone(SaturnConstants.TIME_ZONE_ID_DEFAULT);
} else {
containerScaleJobVo.setTimeZone(containerScaleJobConfig.getTimeZone());
}
containerScaleJobVo.setCron(containerScaleJobConfig.getCron());
containerScaleJobVo.setEnabled(containerScaleJob.getEnabled().toString());
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
}
return containerScaleJobVo;
}
use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.
the class ContainerController method getContainerScaleJob.
@RequestMapping(value = "/getContainerScaleJobVo", method = RequestMethod.GET)
public RequestResult getContainerScaleJob(String taskId, String jobName, HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
if (taskId == null) {
throw new SaturnJobConsoleException("The taskId cannot be null");
}
if (jobName == null) {
throw new SaturnJobConsoleException("The jobName cannot be null");
}
ContainerScaleJobVo containerScaleJob = containerService.getContainerScaleJobVo(taskId, jobName);
requestResult.setSuccess(true);
requestResult.setObj(containerScaleJob);
} catch (SaturnJobConsoleException e) {
requestResult.setSuccess(false);
requestResult.setMessage(e.getMessage());
} catch (Throwable t) {
requestResult.setSuccess(false);
requestResult.setMessage(t.toString());
}
return requestResult;
}
use of com.vip.saturn.job.console.domain.container.vo.ContainerScaleJobVo in project Saturn by vipshop.
the class MarathonServiceImpl method getContainerScaleJobVo.
@Override
public ContainerScaleJobVo getContainerScaleJobVo(String namespace, String taskId, String jobName) throws SaturnJobConsoleException {
ContainerScaleJobVo containerScaleJobVo = null;
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
try {
ContainerScaleJob containerScaleJob = getContainerScaleJob(curatorFrameworkOp, taskId, jobName);
ContainerScaleJobConfig containerScaleJobConfig = containerScaleJob.getContainerScaleJobConfig();
containerScaleJobVo = new ContainerScaleJobVo();
containerScaleJobVo.setJobName(containerScaleJobConfig.getJobName());
containerScaleJobVo.setJobDesc(containerScaleJobConfig.getJobDesc());
if (containerScaleJobConfig.getInstances() != null) {
containerScaleJobVo.setInstances(containerScaleJobConfig.getInstances().toString());
}
if (containerScaleJobConfig.getTimeZone() == null) {
containerScaleJobVo.setTimeZone(SaturnConstants.TIME_ZONE_ID_DEFAULT);
} else {
containerScaleJobVo.setTimeZone(containerScaleJobConfig.getTimeZone());
}
containerScaleJobVo.setCron(containerScaleJobConfig.getCron());
containerScaleJobVo.setEnabled(containerScaleJob.getEnabled().toString());
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
}
return containerScaleJobVo;
}
Aggregations