@Override public Model getModel() { return method.getModel(); }
@Override public Model getModel() { return method.getModel(); }
@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; }
static RestMethod createCustomMethod( Method method, HttpAttribute httpConfig, String customNamePrefix) { ImmutableList<PathSegment> path = httpConfig.getFlatPath(); PathSegment lastSegment = path.get(path.size() - 1); // Determine base name. String customName = ""; if (lastSegment instanceof LiteralSegment) { customName = ((LiteralSegment) lastSegment).getLiteral(); path = path.subList(0, path.size() - 1); } else { if (method.getModel().getConfigVersion() > 1) { // From version 2 on, we generate a meaningful name here. customName = method.getSimpleName(); } else if (customNamePrefix.isEmpty()){ // Older versions use the prefix or derive from the http method. customName = httpConfig.getMethodKind().toString().toLowerCase(); } } // Prepend prefix. if (!customNamePrefix.isEmpty() && !customName.toLowerCase().startsWith(customNamePrefix.toLowerCase())) { customName = customNamePrefix + ensureUpperCase(customName); } // Ensure effective start is lower case. customName = ensureLowerCase(customName); String restMethodName = ""; CollectionName collectionName = RestAnalyzer.buildCollectionName(path, method.getModel()); return RestMethod.create( method, RestKind.CUSTOM, collectionName, customName, restMethodName); }
static RestMethod createCustomMethod( Method method, HttpAttribute httpConfig, String customNamePrefix) { ImmutableList<PathSegment> path = httpConfig.getFlatPath(); PathSegment lastSegment = path.get(path.size() - 1); // Determine base name. String customName = ""; if (lastSegment instanceof LiteralSegment) { customName = ((LiteralSegment) lastSegment).getLiteral(); path = path.subList(0, path.size() - 1); } else { if (method.getModel().getConfigVersion() > 1) { // From version 2 on, we generate a meaningful name here. customName = method.getSimpleName(); } else if (customNamePrefix.isEmpty()){ // Older versions use the prefix or derive from the http method. customName = httpConfig.getMethodKind().toString().toLowerCase(); } } // Prepend prefix. if (!customNamePrefix.isEmpty() && !customName.toLowerCase().startsWith(customNamePrefix.toLowerCase())) { customName = customNamePrefix + ensureUpperCase(customName); } // Ensure effective start is lower case. customName = ensureLowerCase(customName); String restMethodName = ""; CollectionName collectionName = RestAnalyzer.buildCollectionName(path, method.getModel()); return RestMethod.create( method, RestKind.CUSTOM, collectionName, customName, restMethodName); }
public static long getTimeoutMillis(ProtoMethodModel method, long defaultTimeout) { Model model = method.getProtoMethod().getModel(); for (BackendRule backendRule : model.getServiceConfig().getBackend().getRulesList()) { if (backendRule.getSelector().equals(method.getFullName())) { return (long) Math.ceil(backendRule.getDeadline() * MILLIS_PER_SECOND); } } return defaultTimeout; }
@BeforeClass public static void startUp() { Mockito.when(simpleMethod.getModel()).thenReturn(model); Mockito.when(lroAnnotatedMethod.getModel()).thenReturn(model); Mockito.when(model.getSymbolTable()).thenReturn(symbolTable); Mockito.when(protoParser.getProtoPackage(ArgumentMatchers.any(Method.class))) .thenReturn(PROTO_PACKAGE_NAME); Mockito.when(protoParser.getLongRunningOperation(lroAnnotatedMethod)) .thenReturn( OperationData.newBuilder() .setMetadataType(ANNOTATIONS_METADATA_TYPE) .setResponseType(ANNOTATIONS_RETURN_TYPE_NAME) .build()); Mockito.when(symbolTable.lookupType(PROTO_PACKAGE_NAME + "." + GAPIC_CONFIG_METADATA_TYPE)) .thenReturn(gapicConfigMetadataType); Mockito.when(symbolTable.lookupType(PROTO_PACKAGE_NAME + "." + GAPIC_CONFIG_RETURN_TYPE_NAME)) .thenReturn(gapicConfigReturnType); Mockito.when(symbolTable.lookupType(PROTO_PACKAGE_NAME + "." + ANNOTATIONS_METADATA_TYPE)) .thenReturn(annotationsMetadataType); Mockito.when(symbolTable.lookupType(PROTO_PACKAGE_NAME + "." + ANNOTATIONS_RETURN_TYPE_NAME)) .thenReturn(annotationsReturnType); }
RestMethod createRestMethod(String collectionNameOverride) { if (pattern.lastSegmentPattern() == SegmentPattern.CUSTOM_VERB || pattern.lastSegmentPattern() == SegmentPattern.CUSTOM_VERB_WITH_COLON) { return RestAnalyzer.createCustomMethod(method, httpConfig, pattern.customPrefix()); } CollectionName collectionName = RestAnalyzer.buildCollectionName(httpConfig.getFlatPath(), method.getModel()); if (!Strings.isNullOrEmpty(collectionNameOverride)) { collectionName = CollectionName.create(collectionNameOverride, collectionName.version()); } String restMethodName = ""; return RestMethod.create( method, pattern.restKind(), collectionName, null, restMethodName); }
RestMethod createRestMethod(String collectionNameOverride) { if (pattern.lastSegmentPattern() == SegmentPattern.CUSTOM_VERB || pattern.lastSegmentPattern() == SegmentPattern.CUSTOM_VERB_WITH_COLON) { return RestAnalyzer.createCustomMethod(method, httpConfig, pattern.customPrefix()); } CollectionName collectionName = RestAnalyzer.buildCollectionName(httpConfig.getFlatPath(), method.getModel()); if (!Strings.isNullOrEmpty(collectionNameOverride)) { collectionName = CollectionName.create(collectionNameOverride, collectionName.version()); } String restMethodName = ""; return RestMethod.create( method, pattern.restKind(), collectionName, null, restMethodName); }
private void merge(Method method) { // TODO(user): Cleanup the use of apiVersion restVersions (VersionAttribute vs // RestVersionsAttribute) in the tools framework. Some references are using the attributes // incorrectly due to the confusion caused by the names. String apiVersion = deriveApiVersion(method); Set<String> restVersions = calculateRestVersions(method); method.putAttribute(VersionAttribute.KEY, VersionAttribute.create(apiVersion)); // UM uses the logical version with a suffix appended, if defined. String versionSuffix = method.getModel().getApiV1VersionSuffix(); method.putAttribute(VersionAttribute.USAGE_MANAGER_KEY, VersionAttribute.create(ApiVersionUtil.appendVersionSuffix(apiVersion, versionSuffix))); // Add the rest versions into RestVersionsAttribute only if parent of the method is included in // the model roots. if (roots.contains(method.getParent())) { if (getModel().hasAttribute(RestVersionsAttribute.KEY)) { getModel().getAttribute(RestVersionsAttribute.KEY).getVersions().addAll(restVersions); } else { getModel().putAttribute(RestVersionsAttribute.KEY, new RestVersionsAttribute(restVersions)); } } }
private void merge(Method method) { // TODO(user): Cleanup the use of apiVersion restVersions (VersionAttribute vs // RestVersionsAttribute) in the tools framework. Some references are using the attributes // incorrectly due to the confusion caused by the names. String apiVersion = deriveApiVersion(method); Set<String> restVersions = calculateRestVersions(method); method.putAttribute(VersionAttribute.KEY, VersionAttribute.create(apiVersion)); // UM uses the logical version with a suffix appended, if defined. String versionSuffix = method.getModel().getApiV1VersionSuffix(); method.putAttribute(VersionAttribute.USAGE_MANAGER_KEY, VersionAttribute.create(ApiVersionUtil.appendVersionSuffix(apiVersion, versionSuffix))); // Add the rest versions into RestVersionsAttribute only if parent of the method is included in // the model roots. if (roots.contains(method.getParent())) { if (getModel().hasAttribute(RestVersionsAttribute.KEY)) { getModel().getAttribute(RestVersionsAttribute.KEY).getVersions().addAll(restVersions); } else { getModel().putAttribute(RestVersionsAttribute.KEY, new RestVersionsAttribute(restVersions)); } } }
asDiagCollector(), method.getLocation(), path, method.getModel().getConfigVersion()) .parse(); if (parsedPath == null) {
asDiagCollector(), method.getLocation(), path, method.getModel().getConfigVersion()) .parse(); if (parsedPath == null) {