@Test public void testCreateLROWithGapicConfigOnly() { DiagCollector diagCollector = new BoundedDiagCollector(); // simpleMethod has no LRO proto annotations. // lroConfigProtoWithPollSettings contains LRO settings. LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( simpleMethod, diagCollector, lroConfigProtoWithPollSettings, protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNotNull(); ProtoTypeRef metadataTypeModel = (ProtoTypeRef) longRunningConfig.getMetadataType(); assertThat(metadataTypeModel.getProtoType()).isEqualTo(gapicConfigMetadataType); ProtoTypeRef returnTypeModel = (ProtoTypeRef) longRunningConfig.getReturnType(); assertThat(returnTypeModel.getProtoType()).isEqualTo(gapicConfigReturnType); // These are the values specified by lroConfigProtoWithPollSettings. assertThat(longRunningConfig.getInitialPollDelay().toMillis()) .isEqualTo(TEST_INITIAL_POLL_DELAY); assertThat(longRunningConfig.getMaxPollDelay().toMillis()).isEqualTo(TEST_MAX_POLL_DELAY); assertThat(longRunningConfig.getPollDelayMultiplier()).isEqualTo(TEST_POLL_DELAY_MULTIPLIER); assertThat(longRunningConfig.getTotalPollTimeout().toMillis()) .isEqualTo(TEST_TOTAL_POLL_TIMEOUT); assertThat(longRunningConfig.implementsCancel()).isEqualTo(TEST_IMPLEMENTS_CANCEL); assertThat(longRunningConfig.implementsDelete()).isEqualTo(TEST_IMPLEMENTS_DELETE); }
@Nullable static LongRunningConfig createLongRunningConfig( Method method, DiagCollector diagCollector, LongRunningConfigProto longRunningConfigProto, ProtoParser protoParser) { LongRunningConfig longRunningConfig = createLongRunningConfigFromProtoFile( method, diagCollector, longRunningConfigProto, protoParser); if (longRunningConfig != null) { return longRunningConfig; } if (!LongRunningConfigProto.getDefaultInstance().equals(longRunningConfigProto)) { return LongRunningConfig.createLongRunningConfigFromGapicConfig( method.getModel(), diagCollector, longRunningConfigProto); } return null; }
@Override public String getAndSaveOperationResponseTypeName( MethodModel method, ImportTypeTable typeTable, MethodConfig methodConfig) { String responseTypeName = typeTable.getFullNameFor(methodConfig.getLongRunningConfig().getReturnType()); String metaTypeName = typeTable.getFullNameFor(methodConfig.getLongRunningConfig().getMetadataType()); return typeTable.getAndSaveNicknameForContainer( "Google.LongRunning.Operation", responseTypeName, metaTypeName); }
LongRunningOperationDetailView generateDetailView(MethodContext context) { MethodConfig methodConfig = context.getMethodConfig(); LongRunningConfig lroConfig = methodConfig.getLongRunningConfig(); SurfaceNamer namer = context.getNamer(); String clientReturnTypeName = namer.getAndSaveOperationResponseTypeName( context.getMethodModel(), context.getTypeTable(), methodConfig); String operationPayloadTypeName = namer.getLongRunningOperationTypeName(context.getTypeTable(), lroConfig.getReturnType()); String metadataTypeName = namer.getLongRunningOperationTypeName(context.getTypeTable(), lroConfig.getMetadataType()); return LongRunningOperationDetailView.newBuilder() .methodName(namer.getApiMethodName(context.getMethodModel(), VisibilityConfig.PUBLIC)) .constructorName(namer.getTypeConstructor(clientReturnTypeName)) .clientReturnTypeName(clientReturnTypeName) .operationPayloadTypeName(operationPayloadTypeName) .isEmptyOperation(lroConfig.getReturnType().isEmptyType()) .isEmptyMetadata(lroConfig.getMetadataType().isEmptyType()) .metadataTypeName(metadataTypeName) .implementsDelete(lroConfig.implementsDelete()) .implementsCancel(lroConfig.implementsCancel()) .initialPollDelay(lroConfig.getInitialPollDelay().toMillis()) .pollDelayMultiplier(lroConfig.getPollDelayMultiplier()) .maxPollDelay(lroConfig.getMaxPollDelay().toMillis()) .totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()) .build(); } }
private List<LongRunningOperationDetailView> createLongRunningDescriptors( GapicInterfaceContext context) { List<LongRunningOperationDetailView> result = new ArrayList<>(); for (MethodModel method : context.getLongRunningMethods()) { GapicMethodContext methodContext = context.asDynamicMethodContext(method); LongRunningConfig lroConfig = methodContext.getMethodConfig().getLongRunningConfig(); TypeModel returnType = lroConfig.getReturnType(); TypeModel metadataType = lroConfig.getMetadataType(); result.add( LongRunningOperationDetailView.newBuilder() .methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)) .constructorName("") .clientReturnTypeName("") .operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)) .isEmptyOperation(lroConfig.getReturnType().isEmptyType()) .isEmptyMetadata(lroConfig.getMetadataType().isEmptyType()) .metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)) .implementsCancel(true) .implementsDelete(true) .initialPollDelay(lroConfig.getInitialPollDelay().toMillis()) .pollDelayMultiplier(lroConfig.getPollDelayMultiplier()) .maxPollDelay(lroConfig.getMaxPollDelay().toMillis()) .totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()) .build()); } return result; }
private InitCodeContext createResponseInitCodeContext( MethodContext context, SymbolTable symbolTable) { TypeModel outputType = context.getMethodModel().getOutputType(); if (context.getMethodConfig().isLongRunningOperation()) { outputType = context.getMethodConfig().getLongRunningConfig().getReturnType(); } return InitCodeContext.newBuilder() .initObjectType(outputType) .symbolTable(symbolTable) .suggestedName(Name.from("expected_response")) .initFieldConfigStrings(ImmutableList.of()) .initValueConfigMap(ImmutableMap.of()) .initFields(responseInitFields(outputType.getFields())) .fieldConfigMap(context.getProductConfig().getDefaultResourceNameFieldConfigMap()) .valueGenerator(valueGenerator) .additionalInitCodeNodes(createMockResponseAdditionalSubTrees(context)) .build(); }
@Test public void testCreateLROWithNonLROMethod() { DiagCollector diagCollector = new BoundedDiagCollector(); LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( simpleMethod, diagCollector, LongRunningConfigProto.getDefaultInstance(), protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNull(); } }
qualifyLroTypeName(operationTypes.getResponseType(), method, protoParser); String metadataTypeName = qualifyLroTypeName(operationTypes.getMetadataType(), method, protoParser); return LongRunningConfig.createLongRunningConfigFromGapicConfig( method.getModel(), diagCollector, longRunningConfigProto);
private List<LongRunningOperationDetailView> createLongRunningDescriptors( GapicInterfaceContext context) { List<LongRunningOperationDetailView> result = new ArrayList<>(); for (MethodModel method : context.getLongRunningMethods()) { GapicMethodContext methodContext = context.asDynamicMethodContext(method); LongRunningConfig lroConfig = methodContext.getMethodConfig().getLongRunningConfig(); TypeModel returnType = lroConfig.getReturnType(); TypeModel metadataType = lroConfig.getMetadataType(); result.add( LongRunningOperationDetailView.newBuilder() .methodName(context.getNamer().getApiMethodName(method, VisibilityConfig.PUBLIC)) .transportMethodName(context.getNamer().getGrpcMethodName(method)) .constructorName("") .clientReturnTypeName("") .operationPayloadTypeName(context.getImportTypeTable().getFullNameFor(returnType)) .isEmptyOperation(lroConfig.getReturnType().isEmptyType()) .isEmptyMetadata(lroConfig.getMetadataType().isEmptyType()) .metadataTypeName(context.getImportTypeTable().getFullNameFor(metadataType)) .implementsCancel(true) .implementsDelete(true) .initialPollDelay(lroConfig.getInitialPollDelay().toMillis()) .pollDelayMultiplier(lroConfig.getPollDelayMultiplier()) .maxPollDelay(lroConfig.getMaxPollDelay().toMillis()) .totalPollTimeout(lroConfig.getTotalPollTimeout().toMillis()) .build()); } return result; }
@Override public String getAndSaveOperationResponseTypeName( MethodModel method, ImportTypeTable typeTable, MethodConfig methodConfig) { String responseTypeName = typeTable.getFullNameFor(methodConfig.getLongRunningConfig().getReturnType()); String metadataTypeName = typeTable.getFullNameFor(methodConfig.getLongRunningConfig().getMetadataType()); return typeTable.getAndSaveNicknameForContainer( "com.google.api.gax.grpc.OperationFuture", responseTypeName, metadataTypeName); }
public StaticLangApiMethodView generateOperationCallableMethod(MethodContext context) { MethodModel method = context.getMethodModel(); SurfaceNamer namer = context.getNamer(); StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder(); setCommonFields(context, methodViewBuilder); methodViewBuilder.name(namer.getOperationCallableMethodName(method)); methodViewBuilder.exampleName(context.getNamer().getOperationCallableMethodExampleName(method)); setCallableMethodFields( context, namer.getOperationCallableName(method), methodViewBuilder, Arrays.asList(CallingForm.LongRunningCallable)); TypeModel returnType = context.getMethodConfig().getLongRunningConfig().getReturnType(); methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType)); methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context)); return methodViewBuilder.type(ClientMethodType.OperationCallableMethod).build(); }
LongRunningConfig.createLongRunningConfig( method, diagCollector, methodConfigProto.getLongRunning(), protoParser); if (diagCollector.getErrorCount() > 0) {
public List<GrpcElementDocView> generateElementDocs( GapicProductConfig productConfig, ModelTypeTable typeTable, SurfaceNamer namer, ProtoContainerElement containerElement) { ImmutableList.Builder<GrpcElementDocView> children = ImmutableList.builder(); Set<String> lroTypes = productConfig .getInterfaceConfigMap() .values() .stream() .flatMap(i -> i.getMethodConfigs().stream()) .map(MethodConfig::getLongRunningConfig) .filter(Objects::nonNull) .flatMap(lro -> Stream.of(lro.getReturnType(), lro.getMetadataType())) .map(t -> ((ProtoTypeRef) t).getProtoType()) .map(TypeRef::getMessageType) .map(MessageType::getFullName) .collect(ImmutableSet.toImmutableSet()); Collection<MessageType> messages = containerElement .getMessages() .stream() .filter(m -> m.isReachable() || lroTypes.contains(m.getFullName())) .collect(ImmutableList.toImmutableList()); children.addAll(generateMessageDocs(productConfig, typeTable, namer, messages)); children.addAll(generateEnumDocs(typeTable, namer, containerElement.getEnums())); return children.build(); }
TypeModel returnType = context.getMethodConfig().getLongRunningConfig().getReturnType(); methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType)); methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context));
@Test public void testCreateLROWithAnnotationsOverridingGapicConfig() { DiagCollector diagCollector = new BoundedDiagCollector(); // lroAnnotatedMethod contains different settings than that in lroConfigProtoWithPollSettings. LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( lroAnnotatedMethod, diagCollector, lroConfigProtoWithPollSettings, protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNotNull(); // Assert that proto annotations settings take precendence over gapic config. ProtoTypeRef metadataTypeModel = (ProtoTypeRef) longRunningConfig.getMetadataType(); assertThat(metadataTypeModel.getProtoType()).isEqualTo(annotationsMetadataType); ProtoTypeRef returnTypeModel = (ProtoTypeRef) longRunningConfig.getReturnType(); assertThat(returnTypeModel.getProtoType()).isEqualTo(annotationsReturnType); assertThat(longRunningConfig.getInitialPollDelay().toMillis()) .isEqualTo(LongRunningConfig.LRO_INITIAL_POLL_DELAY_MILLIS); assertThat(longRunningConfig.getMaxPollDelay().toMillis()) .isEqualTo(LongRunningConfig.LRO_MAX_POLL_DELAY_MILLIS); assertThat(longRunningConfig.getPollDelayMultiplier()) .isEqualTo(LongRunningConfig.LRO_POLL_DELAY_MULTIPLIER); assertThat(longRunningConfig.getTotalPollTimeout().toMillis()) .isEqualTo(LongRunningConfig.LRO_TOTAL_POLL_TIMEOUT_MILLS); assertThat(longRunningConfig.implementsCancel()) .isEqualTo(LongRunningConfig.LRO_IMPLEMENTS_CANCEL); assertThat(longRunningConfig.implementsDelete()) .isEqualTo(LongRunningConfig.LRO_IMPLEMENTS_DELETE); }
private void addMethodImports(GapicMethodContext context) { ModelTypeTable typeTable = context.getTypeTable(); GapicMethodConfig methodConfig = context.getMethodConfig(); if (methodConfig.isLongRunningOperation()) { typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType()); typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getMetadataType()); } typeTable.getAndSaveNicknameFor(context.getMethod().getInputType()); addFieldsImports(typeTable, methodConfig.getRequiredFields()); addFieldsImports(typeTable, methodConfig.getOptionalFields()); }
public StaticLangApiMethodView generateOperationRequestObjectMethod( MethodContext context, List<ParamWithSimpleDoc> additionalParams) { MethodModel method = context.getMethodModel(); SurfaceNamer namer = context.getNamer(); StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder(); setCommonFields(context, methodViewBuilder); methodViewBuilder.name( namer.getApiMethodName(method, context.getMethodConfig().getVisibility())); methodViewBuilder.exampleName( namer.getApiMethodExampleName(context.getInterfaceConfig(), method)); setRequestObjectMethodFields( context, namer.getCallableMethodName(method), Synchronicity.Sync, additionalParams, methodViewBuilder, Arrays.asList(CallingForm.LongRunningRequest)); methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context)); TypeModel returnType = context.getMethodConfig().getLongRunningConfig().getReturnType(); methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType)); return methodViewBuilder.type(ClientMethodType.OperationRequestObjectMethod).build(); }
@Test public void testCreateLROWithoutGapicConfig() { DiagCollector diagCollector = new BoundedDiagCollector(); LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( lroAnnotatedMethod, diagCollector, LongRunningConfigProto.getDefaultInstance(), protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNotNull(); ProtoTypeRef metadataTypeModel = (ProtoTypeRef) longRunningConfig.getMetadataType(); assertThat(metadataTypeModel.getProtoType()).isEqualTo(annotationsMetadataType); ProtoTypeRef returnTypeModel = (ProtoTypeRef) longRunningConfig.getReturnType(); assertThat(returnTypeModel.getProtoType()).isEqualTo(annotationsReturnType); assertThat(longRunningConfig.getInitialPollDelay().toMillis()) .isEqualTo(LongRunningConfig.LRO_INITIAL_POLL_DELAY_MILLIS); assertThat(longRunningConfig.getMaxPollDelay().toMillis()) .isEqualTo(LongRunningConfig.LRO_MAX_POLL_DELAY_MILLIS); assertThat(longRunningConfig.getPollDelayMultiplier()) .isEqualTo(LongRunningConfig.LRO_POLL_DELAY_MULTIPLIER); assertThat(longRunningConfig.getTotalPollTimeout().toMillis()) .isEqualTo(LongRunningConfig.LRO_TOTAL_POLL_TIMEOUT_MILLS); assertThat(longRunningConfig.implementsCancel()) .isEqualTo(LongRunningConfig.LRO_IMPLEMENTS_CANCEL); assertThat(longRunningConfig.implementsDelete()) .isEqualTo(LongRunningConfig.LRO_IMPLEMENTS_DELETE); }
private void addMethodImports(GapicMethodContext context) { ModelTypeTable typeTable = context.getTypeTable(); GapicMethodConfig methodConfig = context.getMethodConfig(); if (methodConfig.isLongRunningOperation()) { typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getReturnType()); typeTable.getAndSaveNicknameFor(methodConfig.getLongRunningConfig().getMetadataType()); } typeTable.getAndSaveNicknameFor(context.getMethod().getInputType()); addFieldsImports(typeTable, methodConfig.getRequiredFields()); addFieldsImports(typeTable, methodConfig.getOptionalFields()); }
public StaticLangApiMethodView generateOperationFlattenedMethod( MethodContext context, List<ParamWithSimpleDoc> additionalParams) { MethodModel method = context.getMethodModel(); SurfaceNamer namer = context.getNamer(); StaticLangApiMethodView.Builder methodViewBuilder = StaticLangApiMethodView.newBuilder(); setCommonFields(context, methodViewBuilder); methodViewBuilder.name( namer.getApiMethodName(method, context.getMethodConfig().getVisibility())); methodViewBuilder.exampleName( namer.getApiMethodExampleName(context.getInterfaceConfig(), method)); methodViewBuilder.callableName(namer.getCallableName(method)); setFlattenedMethodFields( context, additionalParams, Synchronicity.Sync, methodViewBuilder, Arrays.asList(CallingForm.LongRunningFlattened)); methodViewBuilder.operationMethod(lroTransformer.generateDetailView(context)); TypeModel returnType = context.getMethodConfig().getLongRunningConfig().getReturnType(); methodViewBuilder.responseTypeName(context.getTypeTable().getAndSaveNicknameFor(returnType)); return methodViewBuilder.type(ClientMethodType.OperationFlattenedMethod).build(); }