use of com.google.longrunning.OperationInfo in project toolkit by googleapis.
the class LongRunningConfig method createLongRunningConfig.
/**
* Creates an instance of LongRunningConfig based on protofile annotations. If there is matching
* long running config from GAPIC config, use the GAPIC config's timeout values.
*/
@Nullable
static LongRunningConfig createLongRunningConfig(Method method, DiagCollector diagCollector, @Nonnull LongRunningConfigProto longRunningConfigProto, ProtoParser protoParser) {
int preexistingErrors = diagCollector.getErrorCount();
Model model = method.getModel();
OperationInfo operationTypes = protoParser.getLongRunningOperation(method);
if (operationTypes == null || operationTypes.equals(operationTypes.getDefaultInstanceForType())) {
return null;
}
String responseTypeName = qualifyLroTypeName(operationTypes.getResponseType(), method, protoParser);
String metadataTypeName = qualifyLroTypeName(operationTypes.getMetadataType(), method, protoParser);
TypeRef returnType = model.getSymbolTable().lookupType(responseTypeName);
TypeRef metadataType = model.getSymbolTable().lookupType(metadataTypeName);
if (returnType == null) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Type not found for long running config: '%s'", responseTypeName));
} else if (!returnType.isMessage()) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Type for long running config is not a message: '%s'", responseTypeName));
}
if (metadataType == null) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Metadata type not found for long running config: '%s'", metadataTypeName));
} else if (!metadataType.isMessage()) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Metadata type for long running config is not a message: '%s'", metadataTypeName));
}
if (diagCollector.getErrorCount() - preexistingErrors > 0) {
return null;
}
LongRunningConfig.Builder builder = getGapicConfigLroRetrySettingsOrDefault(diagCollector, longRunningConfigProto);
return builder.setReturnType(ProtoTypeRef.create(returnType)).setMetadataType(ProtoTypeRef.create(metadataType)).build();
}
use of com.google.longrunning.OperationInfo in project toolkit by googleapis.
the class ProtoParserTest method testGetLongRunningOperation.
@Test
public void testGetLongRunningOperation() {
OperationInfo operationTypes = protoParser.getLongRunningOperation(getBigBookMethod);
OperationInfo expected = OperationInfo.newBuilder().setResponseType("google.example.library.v1.Book").setMetadataType("google.example.library.v1.GetBigBookMetadata").build();
assertThat(operationTypes).isEqualTo(expected);
}
Aggregations