use of com.google.cloud.discotoproto3converter.proto3.GrpcMethod in project disco-to-proto3-converter by googleapis.
the class ServiceConfigWriter method writeToFile.
@Override
public void writeToFile(PrintWriter writer, ProtoFile protoFile, boolean outputComments) throws IOException {
ServiceConfig serviceConfig = new ServiceConfig();
String protoPkg = protoFile.getMetadata().getProtoPkg();
RetryPolicy idempotentRetryPolicy = new RetryPolicy("0.100s", "60s", 1.3D, Arrays.asList("DEADLINE_EXCEEDED", "UNAVAILABLE"));
MethodConfig idempotentMethodConfig = new MethodConfig("600s", idempotentRetryPolicy);
MethodConfig nonidempotentMethodConfig = new MethodConfig("600s", null);
for (GrpcService service : protoFile.getServices().values()) {
for (GrpcMethod method : service.getMethods()) {
Optional<Option> opt = method.getOptions().stream().filter(o -> o.getName().equals("google.api.http")).findFirst();
Name name = new Name(protoPkg + "." + service.getName(), method.getName());
if (opt.isPresent() && opt.get().getProperties().containsKey("get")) {
idempotentMethodConfig.getName().add(name);
} else {
nonidempotentMethodConfig.getName().add(name);
}
}
}
serviceConfig.getMethodConfig().add(idempotentMethodConfig);
serviceConfig.getMethodConfig().add(nonidempotentMethodConfig);
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(serviceConfig);
writer.println(json);
}
use of com.google.cloud.discotoproto3converter.proto3.GrpcMethod in project disco-to-proto3-converter by googleapis.
the class GapicYamlWriter method writeToFile.
@Override
public void writeToFile(PrintWriter writer, ProtoFile protoFile, boolean outputComments) {
writeLicenseAndWarning(writer, protoFile.getMetadata());
writer.println("type: com.google.api.codegen.ConfigProto");
writer.println("config_schema_version: 2.0.0");
writer.println("language_settings:");
// Consider adding other languages as well, if ever needed
writer.println(" java:");
writer.println(" package_name: com." + protoFile.getMetadata().getProtoPkg());
writer.println("interfaces:");
for (GrpcService service : protoFile.getServices().values()) {
boolean firstMethod = true;
for (GrpcMethod method : service.getMethods()) {
Optional<Option> opt = method.getOptions().stream().filter(o -> o.getName().equals("google.cloud.operation_service")).findFirst();
if (!opt.isPresent()) {
continue;
}
if (firstMethod) {
writer.println("- name: " + protoFile.getMetadata().getProtoPkg() + "." + service.getName());
writer.println(" methods:");
firstMethod = false;
}
writer.println(" - name: " + method.getName());
// Consider making these configurable
writer.println(" long_running:");
writer.println(" initial_poll_delay_millis: 500");
writer.println(" poll_delay_multiplier: 1.5");
writer.println(" max_poll_delay_millis: 20000");
writer.println(" total_poll_timeout_millis: 600000");
}
}
}
Aggregations