use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class MarathonRestClient method getRegistryRepositoriesTagsList.
public static String getRegistryRepositoriesTagsList(String repository) throws SaturnJobConsoleException {
String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REGISTRY_URI + "/v2/" + repository + "/tags/list";
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpGet httpGet = new HttpGet(urlStr);
CloseableHttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
String entityContent = getEntityContent(entity);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() == 200) {
return entityContent;
} else {
throw new SaturnJobConsoleException(entityContent);
}
} else {
throw new SaturnJobConsoleException("Not data returned, url is " + urlStr);
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
} finally {
try {
httpClient.close();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class MarathonRestClient method destroy.
public static void destroy(String userName, String password, String appId) throws SaturnJobConsoleException {
String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + "/v2/apps/" + appId;
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpDelete httpDelete = new HttpDelete(urlStr);
httpDelete.setHeader("Authorization", "Basic " + Base64.encodeBase64String((userName + ":" + password).getBytes("UTF-8")));
CloseableHttpResponse httpResponse = httpClient.execute(httpDelete);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null) {
int statusCode = statusLine.getStatusCode();
String reasonPhrase = statusLine.getReasonPhrase();
if (statusCode == 200) {
} else {
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
String entityContent = getEntityContent(entity);
throw new SaturnJobConsoleException(entityContent);
} else {
throw new SaturnJobConsoleException("statusCode is " + statusCode + ", reasonPhrase is " + reasonPhrase);
}
}
} else {
throw new SaturnJobConsoleException("Not status returned, url is " + urlStr);
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
} finally {
try {
httpClient.close();
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
}
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class ContainerServiceImpl method saveOrUpdateContainerToken.
@Override
public void saveOrUpdateContainerToken(ContainerToken containerToken) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
String dcosConfigTokenNodePath = ContainerNodePath.getDcosConfigTokenNodePath();
try {
// Update scale job's shardingItemParameters. Disable job, sleep 1s, update shardingItemParameters, sleep
// 1s, enable job
Map<String, List<ContainerScaleJob>> allContainerScaleJobs = new HashMap<>();
List<String> tasks = getTasks(curatorFrameworkOp);
for (String task : tasks) {
List<ContainerScaleJob> containerScaleJobs = getContainerScaleJobs(task);
allContainerScaleJobs.put(task, containerScaleJobs);
}
Iterator<Map.Entry<String, List<ContainerScaleJob>>> iterator = allContainerScaleJobs.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, List<ContainerScaleJob>> next = iterator.next();
List<ContainerScaleJob> containerScaleJobs = next.getValue();
for (ContainerScaleJob containerScaleJob : containerScaleJobs) {
if (containerScaleJob.getEnabled()) {
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(containerScaleJob.getContainerScaleJobConfig().getJobName(), "enabled"), "false");
}
}
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
// NOSONAR
}
Iterator<Map.Entry<String, List<ContainerScaleJob>>> iterator2 = allContainerScaleJobs.entrySet().iterator();
while (iterator2.hasNext()) {
Map.Entry<String, List<ContainerScaleJob>> next = iterator2.next();
String taskId = next.getKey();
List<ContainerScaleJob> containerScaleJobs = next.getValue();
for (ContainerScaleJob containerScaleJob : containerScaleJobs) {
String jobName = containerScaleJob.getContainerScaleJobConfig().getJobName();
Integer instances = containerScaleJob.getContainerScaleJobConfig().getInstances();
String shardingItemParametersNodePath = JobNodePath.getConfigNodePath(jobName, "shardingItemParameters");
String scaleShardingItemParameters = getContainerScaleJobShardingItemParameters(containerToken, taskId, instances);
curatorFrameworkOp.update(shardingItemParametersNodePath, scaleShardingItemParameters);
}
}
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
// NOSONAR
}
Iterator<Map.Entry<String, List<ContainerScaleJob>>> iterator3 = allContainerScaleJobs.entrySet().iterator();
while (iterator3.hasNext()) {
Map.Entry<String, List<ContainerScaleJob>> next = iterator3.next();
List<ContainerScaleJob> containerScaleJobs = next.getValue();
for (ContainerScaleJob containerScaleJob : containerScaleJobs) {
if (containerScaleJob.getEnabled()) {
curatorFrameworkOp.update(JobNodePath.getConfigNodePath(containerScaleJob.getContainerScaleJobConfig().getJobName(), "enabled"), "true");
}
}
}
curatorFrameworkOp.update(dcosConfigTokenNodePath, getContainerRestService().serializeContainerToken(containerToken));
} catch (SaturnJobConsoleException e) {
throw e;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e);
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleException 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.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class ContainerServiceImpl method addContainerScaleJob.
@Override
public void addContainerScaleJob(String taskId, String jobDesc, Integer instances, String timeZone, String cron) throws SaturnJobConsoleException {
CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = curatorRepository.inSessionClient();
String jobName = SaturnConstants.SYSTEM_SCALE_JOB_PREFEX + System.currentTimeMillis();
ContainerToken containerToken = getContainerToken();
JobConfig jobConfig = new JobConfig();
jobConfig.setJobName(jobName);
jobConfig.setDescription(jobDesc);
jobConfig.setTimeZone(timeZone);
jobConfig.setCron(cron);
jobConfig.setJobMode(JobMode.system_scale);
jobConfig.setJobType(JobBriefInfo.JobType.SHELL_JOB.name());
jobConfig.setPreferList("@" + taskId);
jobConfig.setShardingTotalCount(1);
jobConfig.setShardingItemParameters(getContainerScaleJobShardingItemParameters(containerToken, taskId, instances));
jobConfig.setUseDispreferList(false);
jobConfig.setTimeout4AlarmSeconds(30);
jobConfig.setTimeoutSeconds(30);
jobConfig.setJobParameter("");
jobConfig.setQueueName("");
jobConfig.setChannelName("");
jobConfig.setPausePeriodDate("");
jobConfig.setPausePeriodTime("");
RequestResult requestResult = executorService.addJobs(jobConfig);
if (!requestResult.isSuccess()) {
throw new SaturnJobConsoleException(requestResult.getMessage());
}
ContainerScaleJobConfig containerScaleJobConfig = new ContainerScaleJobConfig();
containerScaleJobConfig.setJobName(jobName);
containerScaleJobConfig.setJobDesc(jobDesc);
containerScaleJobConfig.setInstances(instances);
containerScaleJobConfig.setTimeZone(timeZone);
containerScaleJobConfig.setCron(cron);
try {
String containerScaleJobStr = JSON.toJSONString(containerScaleJobConfig);
String dcosTaskScaleJobNodePath = ContainerNodePath.getDcosTaskScaleJobNodePath(taskId, jobName);
curatorFrameworkOp.fillJobNodeIfNotExist(dcosTaskScaleJobNodePath, containerScaleJobStr);
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new SaturnJobConsoleException(e.getMessage(), e);
}
}
Aggregations