Search in sources :

Example 76 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class MarathonRestClient method getRegistryCatalog.

public static String getRegistryCatalog() throws SaturnJobConsoleException {
    String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REGISTRY_URI + "/v2/_catalog";
    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) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    } finally {
        try {
            httpClient.close();
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpEntity(org.apache.http.HttpEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException)

Example 77 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class MarathonRestClient method scale.

public static void scale(String userName, String password, String appId, Integer instances) throws SaturnJobConsoleException {
    JSONObject params = new JSONObject();
    params.put("instances", instances);
    String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + API_VERSION_DES + appId + "?force=true";
    CloseableHttpClient httpClient = HttpClients.createDefault();
    try {
        HttpPut httpPut = new HttpPut(urlStr);
        httpPut.setHeader(AUTHORIZATION_DES, BASIC_DES + Base64.encodeBase64String((userName + ":" + password).getBytes(UTF8_DES)));
        httpPut.setHeader("Content-type", "application/json; charset=utf-8");
        httpPut.setEntity(new StringEntity(params.toJSONString()));
        CloseableHttpResponse httpResponse = httpClient.execute(httpPut);
        StatusLine statusLine = httpResponse.getStatusLine();
        if (statusLine != null) {
            int statusCode = statusLine.getStatusCode();
            String reasonPhrase = statusLine.getReasonPhrase();
            if ((statusCode != 200) && (statusCode != 201)) {
                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) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    } finally {
        try {
            httpClient.close();
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) StringEntity(org.apache.http.entity.StringEntity) JSONObject(com.alibaba.fastjson.JSONObject) HttpEntity(org.apache.http.HttpEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException)

Example 78 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class MarathonRestClient method getContainerStatus.

public static ContainerStatus getContainerStatus(String userName, String password, String appId) throws SaturnJobConsoleException {
    String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + API_VERSION_DES + appId;
    CloseableHttpClient httpClient = HttpClients.createDefault();
    try {
        HttpGet httpGet = new HttpGet(urlStr);
        httpGet.setHeader(AUTHORIZATION_DES, BASIC_DES + Base64.encodeBase64String((userName + ":" + password).getBytes(UTF8_DES)));
        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) {
                WrapperApp app = JSON.parseObject(entityContent, WrapperApp.class);
                ContainerStatus containerStatus = new ContainerStatus();
                containerStatus.setHealthyCount(app.getApp().getTasksHealthy());
                containerStatus.setUnhealthyCount(app.getApp().getTasksUnhealthy());
                containerStatus.setRunningCount(app.getApp().getTasksRunning());
                containerStatus.setStagedCount(app.getApp().getTasksStaged());
                containerStatus.setTotalCount(app.getApp().getInstances());
                return containerStatus;
            } else {
                throw new SaturnJobConsoleException(entityContent);
            }
        } else {
            throw new SaturnJobConsoleException("Not data returned, url is " + urlStr);
        }
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new SaturnJobConsoleException(e);
    } finally {
        try {
            httpClient.close();
        } catch (IOException e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : StatusLine(org.apache.http.StatusLine) CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) ContainerStatus(com.vip.saturn.job.console.domain.container.ContainerStatus) WrapperApp(com.vip.saturn.job.console.service.impl.marathon.entity.WrapperApp) HttpEntity(org.apache.http.HttpEntity) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException)

Example 79 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobServiceImpl method disableJob.

@Transactional(rollbackFor = Exception.class)
@Override
public void disableJob(String namespace, String jobName, String updatedBy) throws SaturnJobConsoleException {
    JobConfig4DB jobConfig = currentJobConfigService.findConfigByNamespaceAndJobName(namespace, jobName);
    if (jobConfig == null) {
        throw new SaturnJobConsoleException(ERROR_CODE_NOT_EXISTED, "不能禁用该作业(" + jobName + "),因为该作业不存在");
    }
    if (!jobConfig.getEnabled()) {
        throw new SaturnJobConsoleException(ERROR_CODE_BAD_REQUEST, "该作业(" + jobName + ")已经处于禁用状态");
    }
    jobConfig.setEnabled(Boolean.FALSE);
    jobConfig.setLastUpdateTime(new Date());
    jobConfig.setLastUpdateBy(updatedBy);
    currentJobConfigService.updateByPrimaryKey(jobConfig);
    CuratorRepository.CuratorFrameworkOp curatorFrameworkOp = registryCenterService.getCuratorFrameworkOp(namespace);
    curatorFrameworkOp.update(JobNodePath.getConfigNodePath(jobName, CONFIG_ITEM_ENABLED), false);
}
Also used : CuratorRepository(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) CuratorFrameworkOp(com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp) JobConfig4DB(com.vip.saturn.job.console.mybatis.entity.JobConfig4DB) Transactional(org.springframework.transaction.annotation.Transactional)

Example 80 with SaturnJobConsoleException

use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.

the class JobServiceImpl method validateGroupsFieldOfJobConfig.

private void validateGroupsFieldOfJobConfig(JobConfig jobConfig) throws SaturnJobConsoleException {
    String groups = jobConfig.getGroups();
    if (groups == null) {
        return;
    }
    if (groups.length() > 255) {
        throw new SaturnJobConsoleException("分组过长,不能超过255个字符");
    }
    Pattern pattern = Pattern.compile("[`!@#$%^!@#¥%……&*()|{}【】‘;:”“’。,、? ]");
    for (String group : groups.split(",")) {
        validateGroupName(group, pattern);
    }
}
Also used : Pattern(java.util.regex.Pattern) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Aggregations

SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)190 SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)56 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)56 CuratorRepository (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository)39 RequestResult (com.vip.saturn.job.console.domain.RequestResult)31 ParseException (java.text.ParseException)28 ResponseEntity (org.springframework.http.ResponseEntity)26 Transactional (org.springframework.transaction.annotation.Transactional)23 JobConfig4DB (com.vip.saturn.job.console.mybatis.entity.JobConfig4DB)22 CuratorFrameworkOp (com.vip.saturn.job.console.repository.zookeeper.CuratorRepository.CuratorFrameworkOp)22 IOException (java.io.IOException)19 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)19 StatusLine (org.apache.http.StatusLine)18 HttpEntity (org.apache.http.HttpEntity)16 Audit (com.vip.saturn.job.console.aop.annotation.Audit)13 JobConfig (com.vip.saturn.job.console.domain.JobConfig)11 HttpHeaders (org.springframework.http.HttpHeaders)11 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)9 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)8 ArrayList (java.util.ArrayList)8