use of com.vip.saturn.job.console.exception.SaturnJobConsoleException in project Saturn by vipshop.
the class AuthorizationManageServiceImpl method validateUser.
protected void validateUser(UserRole userRole) throws SaturnJobConsoleException {
String userName = userRole.getUserName();
User user = userRepository.selectWithNotFilterDeleted(userName);
if (user == null) {
throw new SaturnJobConsoleException(String.format("用户名(%s)不存在", userName));
}
}
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 + "/v2/apps/" + appId;
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpGet httpGet = new HttpGet(urlStr);
httpGet.setHeader("Authorization", "Basic " + Base64.encodeBase64String((userName + ":" + password).getBytes("UTF-8")));
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) {
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 info.
public static String info(String userName, String password, String appId) throws SaturnJobConsoleException {
String urlStr = SaturnEnvProperties.VIP_SATURN_DCOS_REST_URI + "/v2/apps/" + appId;
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpGet httpGet = new HttpGet(urlStr);
httpGet.setHeader("Authorization", "Basic " + Base64.encodeBase64String((userName + ":" + password).getBytes("UTF-8")));
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 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) {
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 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 + "/v2/apps/" + appId + "?force=true";
CloseableHttpClient httpClient = HttpClients.createDefault();
try {
HttpPut httpPut = new HttpPut(urlStr);
httpPut.setHeader("Authorization", "Basic " + Base64.encodeBase64String((userName + ":" + password).getBytes("UTF-8")));
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) {
} else if (statusCode == 201) {
} 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);
}
}
}
Aggregations