use of com.vip.saturn.job.console.domain.RequestResult in project Saturn by vipshop.
the class ContainerController method addContainer.
@RequestMapping(value = "/addContainer", method = RequestMethod.POST)
@ResponseBody
public RequestResult addContainer(AddContainerModel addContainerModel, HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
if (addContainerModel.getContainerToken() == null) {
throw new SaturnJobConsoleException("Please input container token");
}
containerService.checkContainerTokenNotNull(addContainerModel.getContainerToken());
containerService.saveOrUpdateContainerTokenIfNecessary(addContainerModel.getContainerToken());
ContainerConfig containerConfig = new ContainerConfig();
containerConfig.setTaskId(addContainerModel.getTaskId());
containerConfig.setCmd(addContainerModel.getCmd());
containerConfig.setCpus(addContainerModel.getCpus());
containerConfig.setMem(addContainerModel.getMem());
containerConfig.setInstances(addContainerModel.getInstances());
containerConfig.setConstraints(addContainerModel.getConstraints());
containerConfig.setEnv(addContainerModel.getEnv());
containerConfig.setPrivileged(addContainerModel.getPrivileged() == null ? false : addContainerModel.getPrivileged());
containerConfig.setForcePullImage(addContainerModel.getForcePullImage() == null ? true : addContainerModel.getForcePullImage());
containerConfig.setParameters(addContainerModel.getParameters());
containerConfig.setVolumes(addContainerModel.getVolumes());
containerConfig.setImage(addContainerModel.getImage());
containerConfig.setCreateTime(System.currentTimeMillis());
String imageNew = "";
String vipSaturnDcosRegistryUri = SaturnEnvProperties.VIP_SATURN_DCOS_REGISTRY_URI;
if (vipSaturnDcosRegistryUri == null || vipSaturnDcosRegistryUri.trim().length() == 0) {
String errorMsg = "VIP_SATURN_DCOS_REGISTRY_URI is not configured";
requestResult.setSuccess(false);
requestResult.setMessage(errorMsg);
return requestResult;
} else {
if (vipSaturnDcosRegistryUri.startsWith("http://")) {
String tmp = vipSaturnDcosRegistryUri.substring("http://".length());
while (tmp.endsWith("/")) {
tmp = tmp.substring(0, tmp.length() - 1);
}
imageNew = tmp + "/" + addContainerModel.getImage();
} else if (vipSaturnDcosRegistryUri.startsWith("https://")) {
String tmp = vipSaturnDcosRegistryUri.substring("https://".length());
while (tmp.endsWith("/")) {
tmp = tmp.substring(0, tmp.length() - 1);
}
imageNew = tmp + "/" + addContainerModel.getImage();
}
}
containerConfig.setImage(imageNew);
if (containerConfig.getEnv() == null) {
containerConfig.setEnv(new HashMap<String, String>());
}
if (!containerConfig.getEnv().containsKey(SaturnEnvProperties.NAME_VIP_SATURN_ZK_CONNECTION)) {
containerConfig.getEnv().put(SaturnEnvProperties.NAME_VIP_SATURN_ZK_CONNECTION, getCurrentZkAddr(request.getSession()));
}
containerService.addContainer(containerConfig);
requestResult.setSuccess(true);
} 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.RequestResult in project Saturn by vipshop.
the class ContainerController method saveOrUpdateContainerToken.
@RequestMapping(value = "saveOrUpdateContainerToken", method = RequestMethod.POST)
public RequestResult saveOrUpdateContainerToken(ContainerToken containerToken, HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
if (containerToken == null) {
throw new SaturnJobConsoleException("Please input container token");
}
containerService.checkContainerTokenNotNull(containerToken);
containerService.saveOrUpdateContainerToken(containerToken);
requestResult.setSuccess(true);
} 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.RequestResult in project Saturn by vipshop.
the class ContainerController method getContainerDetail.
@RequestMapping(value = "/getContainerDetail", method = RequestMethod.GET)
public RequestResult getContainerDetail(String taskId, HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
if (taskId == null) {
throw new SaturnJobConsoleException("The taskId cannot be null");
}
String containerDetail = containerService.getContainerDetail(taskId);
requestResult.setSuccess(true);
requestResult.setObj(containerDetail);
} 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.RequestResult 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.RequestResult in project Saturn by vipshop.
the class ContainerController method enableContainerScaleJob.
@RequestMapping(value = "/enableContainerScaleJob", method = RequestMethod.POST)
public RequestResult enableContainerScaleJob(String jobName, Boolean enable, HttpServletRequest request) {
RequestResult requestResult = new RequestResult();
try {
if (jobName == null) {
throw new SaturnJobConsoleException("The jobName cannot be null");
}
if (enable == null) {
throw new SaturnJobConsoleException("The enable cannot be null");
}
containerService.enableContainerScaleJob(jobName, enable);
requestResult.setSuccess(true);
} catch (SaturnJobConsoleException e) {
requestResult.setSuccess(false);
requestResult.setMessage(e.getMessage());
} catch (Throwable t) {
requestResult.setSuccess(false);
requestResult.setMessage(t.toString());
}
return requestResult;
}
Aggregations