Search in sources :

Example 1 with OperationInfo

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();
}
Also used : OperationInfo(com.google.longrunning.OperationInfo) TypeRef(com.google.api.tools.framework.model.TypeRef) Model(com.google.api.tools.framework.model.Model) Nullable(javax.annotation.Nullable)

Example 2 with OperationInfo

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);
}
Also used : OperationInfo(com.google.longrunning.OperationInfo) GapicCodeGeneratorAnnotationsTest(com.google.api.codegen.protoannotations.GapicCodeGeneratorAnnotationsTest) Test(org.junit.Test)

Aggregations

OperationInfo (com.google.longrunning.OperationInfo)2 GapicCodeGeneratorAnnotationsTest (com.google.api.codegen.protoannotations.GapicCodeGeneratorAnnotationsTest)1 Model (com.google.api.tools.framework.model.Model)1 TypeRef (com.google.api.tools.framework.model.TypeRef)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1