use of com.google.api.codegen.ReleaseLevel in project toolkit by googleapis.
the class GapicMethodConfig method createMethodConfig.
/**
* Creates an instance of GapicMethodConfig based on MethodConfigProto, linking it up with the
* provided method. On errors, null will be returned, and diagnostics are reported to the diag
* collector.
*/
@Nullable
static GapicMethodConfig createMethodConfig(DiagCollector diagCollector, String language, MethodConfigProto methodConfigProto, Method method, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, ImmutableSet<String> retryCodesConfigNames, ImmutableSet<String> retryParamsConfigNames) {
boolean error = false;
ProtoMethodModel methodModel = new ProtoMethodModel(method);
PageStreamingConfig pageStreaming = null;
if (!PageStreamingConfigProto.getDefaultInstance().equals(methodConfigProto.getPageStreaming())) {
pageStreaming = PageStreamingConfig.createPageStreaming(diagCollector, messageConfigs, resourceNameConfigs, methodConfigProto, methodModel);
if (pageStreaming == null) {
error = true;
}
}
GrpcStreamingConfig grpcStreaming = null;
if (isGrpcStreamingMethod(methodModel)) {
if (PageStreamingConfigProto.getDefaultInstance().equals(methodConfigProto.getGrpcStreaming())) {
grpcStreaming = GrpcStreamingConfig.createGrpcStreaming(diagCollector, method);
} else {
grpcStreaming = GrpcStreamingConfig.createGrpcStreaming(diagCollector, methodConfigProto.getGrpcStreaming(), method);
if (grpcStreaming == null) {
error = true;
}
}
}
ImmutableList<FlatteningConfig> flattening = null;
if (!FlatteningConfigProto.getDefaultInstance().equals(methodConfigProto.getFlattening())) {
flattening = createFlattening(diagCollector, messageConfigs, resourceNameConfigs, methodConfigProto, methodModel);
if (flattening == null) {
error = true;
}
}
BatchingConfig batching = null;
if (!BatchingConfigProto.getDefaultInstance().equals(methodConfigProto.getBatching())) {
batching = BatchingConfig.createBatching(diagCollector, methodConfigProto.getBatching(), methodModel);
if (batching == null) {
error = true;
}
}
String retryCodesName = methodConfigProto.getRetryCodesName();
if (!retryCodesName.isEmpty() && !retryCodesConfigNames.contains(retryCodesName)) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Retry codes config used but not defined: '%s' (in method %s)", retryCodesName, methodModel.getFullName()));
error = true;
}
String retryParamsName = methodConfigProto.getRetryParamsName();
if (!retryParamsConfigNames.isEmpty() && !retryParamsConfigNames.contains(retryParamsName)) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Retry parameters config used but not defined: %s (in method %s)", retryParamsName, methodModel.getFullName()));
error = true;
}
Duration timeout = Duration.ofMillis(methodConfigProto.getTimeoutMillis());
if (timeout.toMillis() <= 0) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Default timeout not found or has invalid value (in method %s)", methodModel.getFullName()));
error = true;
}
boolean hasRequestObjectMethod = methodConfigProto.getRequestObjectMethod();
if (hasRequestObjectMethod && method.getRequestStreaming()) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "request_object_method incompatible with streaming method %s", method.getFullName()));
error = true;
}
ImmutableMap<String, String> fieldNamePatterns = ImmutableMap.copyOf(methodConfigProto.getFieldNamePatterns());
ResourceNameTreatment defaultResourceNameTreatment = methodConfigProto.getResourceNameTreatment();
if (defaultResourceNameTreatment == null || defaultResourceNameTreatment.equals(ResourceNameTreatment.UNSET_TREATMENT)) {
defaultResourceNameTreatment = ResourceNameTreatment.NONE;
}
Iterable<FieldConfig> requiredFieldConfigs = createFieldNameConfigs(diagCollector, messageConfigs, defaultResourceNameTreatment, fieldNamePatterns, resourceNameConfigs, getRequiredFields(diagCollector, methodModel, methodConfigProto.getRequiredFieldsList()));
Iterable<FieldConfig> optionalFieldConfigs = createFieldNameConfigs(diagCollector, messageConfigs, defaultResourceNameTreatment, fieldNamePatterns, resourceNameConfigs, getOptionalFields(methodModel, methodConfigProto.getRequiredFieldsList()));
List<String> sampleCodeInitFields = new ArrayList<>();
sampleCodeInitFields.addAll(methodConfigProto.getSampleCodeInitFieldsList());
String rerouteToGrpcInterface = Strings.emptyToNull(methodConfigProto.getRerouteToGrpcInterface());
VisibilityConfig visibility = VisibilityConfig.PUBLIC;
ReleaseLevel releaseLevel = ReleaseLevel.GA;
for (SurfaceTreatmentProto treatment : methodConfigProto.getSurfaceTreatmentsList()) {
if (!treatment.getIncludeLanguagesList().contains(language)) {
continue;
}
if (treatment.getVisibility() != VisibilityProto.UNSET_VISIBILITY) {
visibility = VisibilityConfig.fromProto(treatment.getVisibility());
}
if (treatment.getReleaseLevel() != ReleaseLevel.UNSET_RELEASE_LEVEL) {
releaseLevel = treatment.getReleaseLevel();
}
}
LongRunningConfig longRunningConfig = null;
if (!LongRunningConfigProto.getDefaultInstance().equals(methodConfigProto.getLongRunning())) {
longRunningConfig = LongRunningConfig.createLongRunningConfig(method.getModel(), diagCollector, methodConfigProto.getLongRunning());
if (longRunningConfig == null) {
error = true;
}
}
List<String> headerRequestParams = ImmutableList.copyOf(methodConfigProto.getHeaderRequestParamsList());
if (error) {
return null;
} else {
return new AutoValue_GapicMethodConfig(methodModel, pageStreaming, grpcStreaming, flattening, retryCodesName, retryParamsName, timeout, requiredFieldConfigs, optionalFieldConfigs, defaultResourceNameTreatment, batching, hasRequestObjectMethod, fieldNamePatterns, sampleCodeInitFields, rerouteToGrpcInterface, visibility, releaseLevel, longRunningConfig, headerRequestParams);
}
}
use of com.google.api.codegen.ReleaseLevel in project toolkit by googleapis.
the class DiscoGapicMethodConfig method createDiscoGapicMethodConfig.
/**
* Creates an instance of DiscoGapicMethodConfig based on MethodConfigProto, linking it up with
* the provided method. On errors, null will be returned, and diagnostics are reported to the diag
* collector.
*/
@Nullable
static DiscoGapicMethodConfig createDiscoGapicMethodConfig(DiscoApiModel apiModel, String language, MethodConfigProto methodConfigProto, Method method, ResourceNameMessageConfigs messageConfigs, ImmutableMap<String, ResourceNameConfig> resourceNameConfigs, ImmutableSet<String> retryCodesConfigNames, ImmutableSet<String> retryParamsConfigNames) {
boolean error = false;
DiscoveryMethodModel methodModel = new DiscoveryMethodModel(method, apiModel);
DiagCollector diagCollector = apiModel.getDiagCollector();
PageStreamingConfig pageStreaming = null;
if (!PageStreamingConfigProto.getDefaultInstance().equals(methodConfigProto.getPageStreaming())) {
pageStreaming = PageStreamingConfig.createPageStreaming(apiModel, method);
if (pageStreaming == null) {
error = true;
}
}
ImmutableList<FlatteningConfig> flattening = null;
if (!FlatteningConfigProto.getDefaultInstance().equals(methodConfigProto.getFlattening())) {
flattening = createFlattening(diagCollector, messageConfigs, resourceNameConfigs, methodConfigProto, methodModel);
if (flattening == null) {
error = true;
}
}
BatchingConfig batching = null;
if (!BatchingConfigProto.getDefaultInstance().equals(methodConfigProto.getBatching())) {
batching = BatchingConfig.createBatching(diagCollector, methodConfigProto.getBatching(), methodModel);
if (batching == null) {
error = true;
}
}
String retryCodesName = methodConfigProto.getRetryCodesName();
if (!retryCodesName.isEmpty() && !retryCodesConfigNames.contains(retryCodesName)) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Retry codes config used but not defined: '%s' (in method %s)", retryCodesName, methodModel.getFullName()));
error = true;
}
String retryParamsName = methodConfigProto.getRetryParamsName();
if (!retryParamsConfigNames.isEmpty() && !retryParamsConfigNames.contains(retryParamsName)) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Retry parameters config used but not defined: %s (in method %s)", retryParamsName, methodModel.getFullName()));
error = true;
}
Duration timeout = Duration.ofMillis(methodConfigProto.getTimeoutMillis());
if (timeout.toMillis() <= 0) {
diagCollector.addDiag(Diag.error(SimpleLocation.TOPLEVEL, "Default timeout not found or has invalid value (in method %s)", methodModel.getFullName()));
error = true;
}
boolean hasRequestObjectMethod = methodConfigProto.getRequestObjectMethod();
ImmutableMap<String, String> fieldNamePatterns = ImmutableMap.copyOf(methodConfigProto.getFieldNamePatterns());
ResourceNameTreatment defaultResourceNameTreatment = methodConfigProto.getResourceNameTreatment();
if (defaultResourceNameTreatment == null || defaultResourceNameTreatment.equals(ResourceNameTreatment.UNSET_TREATMENT)) {
defaultResourceNameTreatment = ResourceNameTreatment.NONE;
}
Iterable<FieldConfig> requiredFieldConfigs = createFieldNameConfigs(diagCollector, messageConfigs, defaultResourceNameTreatment, fieldNamePatterns, resourceNameConfigs, getRequiredFields(diagCollector, methodModel, methodConfigProto.getRequiredFieldsList()));
Iterable<FieldConfig> optionalFieldConfigs = createFieldNameConfigs(diagCollector, messageConfigs, defaultResourceNameTreatment, fieldNamePatterns, resourceNameConfigs, getOptionalFields(methodModel, methodConfigProto.getRequiredFieldsList()));
List<String> sampleCodeInitFields = new ArrayList<>();
sampleCodeInitFields.addAll(methodConfigProto.getSampleCodeInitFieldsList());
VisibilityConfig visibility = VisibilityConfig.PUBLIC;
ReleaseLevel releaseLevel = ReleaseLevel.ALPHA;
for (SurfaceTreatmentProto treatment : methodConfigProto.getSurfaceTreatmentsList()) {
if (!treatment.getIncludeLanguagesList().contains(language)) {
continue;
}
if (treatment.getVisibility() != VisibilityProto.UNSET_VISIBILITY) {
visibility = VisibilityConfig.fromProto(treatment.getVisibility());
}
if (treatment.getReleaseLevel() != ReleaseLevel.UNSET_RELEASE_LEVEL) {
releaseLevel = treatment.getReleaseLevel();
}
}
LongRunningConfig longRunningConfig = null;
if (error) {
return null;
} else {
return new AutoValue_DiscoGapicMethodConfig(methodModel, pageStreaming, flattening, retryCodesName, retryParamsName, timeout, requiredFieldConfigs, optionalFieldConfigs, defaultResourceNameTreatment, batching, hasRequestObjectMethod, fieldNamePatterns, sampleCodeInitFields, visibility, releaseLevel, longRunningConfig);
}
}
Aggregations