Search in sources :

Example 16 with SaturnJobConsoleException

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

the class ContainerController method getRegistryCatalog.

@RequestMapping(value = "/getRegistryCatalog", method = RequestMethod.GET)
public RequestResult getRegistryCatalog(HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        String registryCatalog = containerService.getRegistryCatalog();
        requestResult.setSuccess(true);
        requestResult.setObj(registryCatalog);
    } catch (SaturnJobConsoleException e) {
        requestResult.setSuccess(false);
        requestResult.setMessage(e.getMessage());
    } catch (Throwable t) {
        requestResult.setSuccess(false);
        requestResult.setMessage(t.toString());
    }
    return requestResult;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with SaturnJobConsoleException

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

the class ContainerController method removeContainer.

@RequestMapping(value = "/removeContainer", method = RequestMethod.POST)
public RequestResult removeContainer(String taskId, HttpServletRequest request) {
    RequestResult requestResult = new RequestResult();
    try {
        if (taskId == null) {
            throw new SaturnJobConsoleException("The taskId cannot be null");
        }
        containerService.removeContainer(taskId);
        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;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with SaturnJobConsoleException

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

the class ContainerController method deleteContainerScaleJob.

@RequestMapping(value = "/deleteContainerScaleJob", method = RequestMethod.POST)
public RequestResult deleteContainerScaleJob(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");
        }
        containerService.deleteContainerScaleJob(taskId, jobName);
        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;
}
Also used : RequestResult(com.vip.saturn.job.console.domain.RequestResult) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with SaturnJobConsoleException

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

the class DashboardRefreshController method handleResponse.

private void handleResponse(String url, CloseableHttpResponse httpResponse) throws IOException, SaturnJobConsoleException {
    StatusLine statusLine = httpResponse.getStatusLine();
    Integer statusCode = statusLine != null ? statusLine.getStatusCode() : null;
    LOGGER.info("the statusCode of remote request is:" + statusCode);
    if (statusLine != null && statusCode == HttpStatus.SC_OK) {
        String takeTime = IOUtils.toString(httpResponse.getEntity().getContent(), "UTF-8");
        LOGGER.info("forwardDashboardRefreshToRemote Url " + url + ", spend time:" + takeTime);
        return;
    }
    if (statusCode >= HttpStatus.SC_BAD_REQUEST && statusCode <= HttpStatus.SC_INTERNAL_SERVER_ERROR) {
        String responseBody = EntityUtils.toString(httpResponse.getEntity());
        if (StringUtils.isNotBlank(responseBody)) {
            String errMsg = JSONObject.parseObject(responseBody).getString("message");
            throw new SaturnJobConsoleException(errMsg);
        } else {
            throw new SaturnJobConsoleException("internal server error");
        }
    } else {
        throw new SaturnJobConsoleException("unexpected status returned from Saturn Server.");
    }
}
Also used : StatusLine(org.apache.http.StatusLine) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException)

Example 20 with SaturnJobConsoleException

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

the class DashboardRefreshController method forwardDashboardRefreshToRemote.

private void forwardDashboardRefreshToRemote(String zkClusterKey) throws SaturnJobConsoleException {
    CloseableHttpClient httpClient = null;
    String url = null;
    try {
        String domain = ZkClusterMappingUtils.getConsoleDomainByZkClusterKey(systemConfigService, zkClusterKey);
        if (StringUtils.isBlank(domain)) {
            throw new SaturnJobConsoleException(String.format("The console domain is not found by zkClusterKey(%s)", zkClusterKey));
        }
        url = domain + "/rest/v1/dashboard/refresh?zkClusterKey=" + zkClusterKey;
        httpClient = HttpClientBuilder.create().build();
        HttpPost httpPost = createHttpRequest(url);
        CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
        handleResponse(url, httpResponse);
    } catch (SaturnJobConsoleException se) {
        throw se;
    } catch (Exception e) {
        throw new SaturnJobConsoleException("Fail to execute forwardDashboardRefreshToRemote, Url: " + url, e);
    } finally {
        IOUtils.closeQuietly(httpClient);
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) HttpPost(org.apache.http.client.methods.HttpPost) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) SaturnJobConsoleException(com.vip.saturn.job.console.exception.SaturnJobConsoleException) IOException(java.io.IOException)

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