use of com.ctrip.framework.apollo.common.exception.ServiceException in project apollo by ctripcorp.
the class RetryableRestTemplate method execute.
private <T> T execute(HttpMethod method, Env env, String path, Object request, Class<T> responseType, Object... uriVariables) {
if (path.startsWith("/")) {
path = path.substring(1);
}
String uri = uriTemplateHandler.expand(path, uriVariables).getPath();
Transaction ct = Tracer.newTransaction("AdminAPI", uri);
ct.addData("Env", env);
List<ServiceDTO> services = getAdminServices(env, ct);
HttpHeaders extraHeaders = assembleExtraHeaders(env);
for (ServiceDTO serviceDTO : services) {
try {
T result = doExecute(method, extraHeaders, serviceDTO, path, request, responseType, uriVariables);
ct.setStatus(Transaction.SUCCESS);
ct.complete();
return result;
} catch (Throwable t) {
logger.error("Http request failed, uri: {}, method: {}", uri, method, t);
Tracer.logError(t);
if (canRetry(t, method)) {
Tracer.logEvent(TracerEventType.API_RETRY, uri);
} else {
// biz exception rethrow
ct.setStatus(t);
ct.complete();
throw t;
}
}
}
// all admin server down
ServiceException e = new ServiceException(String.format("Admin servers are unresponsive. meta server address: %s, admin servers: %s", portalMetaDomainService.getDomain(env), services));
ct.setStatus(e);
ct.complete();
throw e;
}
use of com.ctrip.framework.apollo.common.exception.ServiceException in project apollo by ctripcorp.
the class AppService method save.
@Transactional
public App save(App entity) {
if (!isAppIdUnique(entity.getAppId())) {
throw new ServiceException("appId not unique");
}
// protection
entity.setId(0);
App app = appRepository.save(entity);
auditService.audit(App.class.getSimpleName(), app.getId(), Audit.OP.INSERT, app.getDataChangeCreatedBy());
return app;
}
use of com.ctrip.framework.apollo.common.exception.ServiceException in project apollo by ctripcorp.
the class AppNamespaceService method createDefaultAppNamespace.
@Transactional
public void createDefaultAppNamespace(String appId, String createBy) {
if (!isAppNamespaceNameUnique(appId, ConfigConsts.NAMESPACE_APPLICATION)) {
throw new ServiceException("appnamespace not unique");
}
AppNamespace appNs = new AppNamespace();
appNs.setAppId(appId);
appNs.setName(ConfigConsts.NAMESPACE_APPLICATION);
appNs.setComment("default app namespace");
appNs.setFormat(ConfigFileFormat.Properties.getValue());
appNs.setDataChangeCreatedBy(createBy);
appNs.setDataChangeLastModifiedBy(createBy);
appNamespaceRepository.save(appNs);
auditService.audit(AppNamespace.class.getSimpleName(), appNs.getId(), Audit.OP.INSERT, createBy);
}
use of com.ctrip.framework.apollo.common.exception.ServiceException in project apollo by ctripcorp.
the class ConfigsImportService method forceImportNamespaceFromFile.
/**
* force import, new items will overwrite existed items.
*/
public void forceImportNamespaceFromFile(final Env env, final String standardFilename, final InputStream zipInputStream) {
String configText;
try (InputStream in = zipInputStream) {
configText = ConfigToFileUtils.fileToString(in);
} catch (IOException e) {
throw new ServiceException("Read config file errors:{}", e);
}
String operator = userInfoHolder.getUser().getUserId();
this.importNamespaceFromText(env, standardFilename, configText, false, operator);
}
use of com.ctrip.framework.apollo.common.exception.ServiceException in project apollo by ctripcorp.
the class ConfigsExportService method exportApps.
private void exportApps(final Collection<Env> exportEnvs, OutputStream outputStream) {
List<App> hasPermissionApps = findHasPermissionApps();
if (CollectionUtils.isEmpty(hasPermissionApps)) {
return;
}
try (final ZipOutputStream zipOutputStream = new ZipOutputStream(outputStream)) {
// write app info to zip
writeAppInfoToZip(hasPermissionApps, zipOutputStream);
// export app namespace
exportAppNamespaces(zipOutputStream);
// export app's clusters
exportEnvs.parallelStream().forEach(env -> {
try {
this.exportClusters(env, hasPermissionApps, zipOutputStream);
} catch (Exception e) {
logger.error("export cluster error. env = {}", env, e);
}
});
} catch (IOException e) {
logger.error("export config error", e);
throw new ServiceException("export config error", e);
}
}
Aggregations