use of io.github.tesla.ops.common.TeslaException in project tesla by linking12.
the class FilterRouteController method save.
@Log("保存路由")
@RequiresPermissions("filter:route:add")
@PostMapping("/save")
@ResponseBody()
public CommonResponse save(RouteVo zuulVo, @RequestParam(name = "zipFile", required = false) MultipartFile zipFile) {
try {
// grpc路由
if (zipFile != null) {
InputStream directoryZipStream = zipFile.getInputStream();
CommonResponse response = judgeFileType(directoryZipStream, "zip");
if (response != null) {
return response;
} else {
String serviceFileName = zuulVo.getServiceFileName();
byte[] protoContext = protobufService.compileDirectoryProto(zipFile, serviceFileName);
FilterRouteDto zuulDto = zuulVo.buildRouteDto();
zuulDto.setProtoContext(protoContext);
routeService.save(zuulDto);
}
} else {
FilterRouteDto zuulDto = zuulVo.buildRouteDto();
routeService.save(zuulDto);
}
} catch (IOException e) {
throw new TeslaException("保存路由失败", e);
}
return CommonResponse.ok();
}
use of io.github.tesla.ops.common.TeslaException in project tesla by linking12.
the class FilterRouteController method update.
@Log("更新路由")
@RequiresPermissions("filter:route:edit")
@PostMapping("/update")
@ResponseBody()
public CommonResponse update(RouteVo zuulVo, @RequestParam(name = "zipFile", required = false) MultipartFile zipFile) {
try {
// grpc路由
if (zipFile != null) {
InputStream directoryZipStream = zipFile.getInputStream();
CommonResponse response = judgeFileType(directoryZipStream, "zip");
if (response != null) {
return response;
} else {
String serviceFileName = zuulVo.getServiceFileName();
byte[] protoContext = protobufService.compileDirectoryProto(zipFile, serviceFileName);
FilterRouteDto zuulDto = zuulVo.buildRouteDto();
zuulDto.setProtoContext(protoContext);
routeService.update(zuulDto);
}
} else {
FilterRouteDto zuulDto = zuulVo.buildRouteDto();
routeService.update(zuulDto);
}
} catch (IOException e) {
throw new TeslaException("保存路由失败", e);
}
return CommonResponse.ok();
}
use of io.github.tesla.ops.common.TeslaException in project tesla by linking12.
the class ProtobufServiceImpl method runProtoc.
private byte[] runProtoc(String includePath, String protoFilePath) {
try {
Path descriptorPath = Files.createTempFile("descriptor", ".pb.bin");
ImmutableList.Builder<String> builder = ImmutableList.<String>builder();
if (includePath != null) {
builder.add("-I" + includePath);
}
builder.add("--descriptor_set_out=" + descriptorPath.toAbsolutePath().toString());
ImmutableList<String> protocArgs = builder.add(protoFilePath).build();
int status = Protoc.runProtoc(protocArgs.toArray(new String[0]));
if (status != 0) {
throw new IllegalArgumentException(String.format("Got exit code [%d] from protoc with args [%s]", status, protocArgs));
}
return Files.readAllBytes(descriptorPath);
} catch (IOException | InterruptedException e) {
throw new TeslaException(e.getMessage(), e);
}
}
use of io.github.tesla.ops.common.TeslaException in project tesla by linking12.
the class ProtobufServiceImpl method compileDirectoryProto.
@Override
public byte[] compileDirectoryProto(MultipartFile directoryZipStream, String serviceFileName) {
String fileDirectory = null;
try {
fileDirectory = this.uploadZipFile(directoryZipStream, serviceFileName);
ProtoFileServiceFilter filter = new ProtoFileServiceFilter(serviceFileName);
Files.walkFileTree(Paths.get(fileDirectory), filter);
String protoFilePath = filter.getProtoFilePath();
return this.runProtoc(fileDirectory, protoFilePath);
} catch (IOException e) {
throw new TeslaException(e.getMessage(), e);
} finally {
if (fileDirectory != null) {
FileUtils.deleteQuietly(new File(fileDirectory));
}
}
}
Aggregations