Module: Gapic::Model::Service
- Defined in:
- lib/gapic/model/service/nonstandard_lro_provider.rb
Overview
Service-level models
Defined Under Namespace
Classes: NoNonstandardLro, NonstandardLroProvider
Class Method Summary collapse
-
.parse_nonstandard_lro(service) ⇒ NonstandardLroProvider?
Parses the service proto information to determine, whether it is a provider for nonstandard long-running operations polling.
Class Method Details
.parse_nonstandard_lro(service) ⇒ NonstandardLroProvider?
Parses the service proto information to determine, whether it is a provider for nonstandard long-running operations polling
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/gapic/model/service/nonstandard_lro_provider.rb', line 152 def parse_nonstandard_lro service polling_method = find_polling_method service return unless polling_method # There should not be any methods that have the `operation_service` annotation # in the LRO provider service. # In theory there is nothing wrong with one LRO polling service using another # LRO polling service, in practice there is potential for service intialization cycles # Until we have a real usecase it's safer to assume an error in proto. nonstandard_lro_candidates = service.methods.find_all do |m| !m.operation_service.nil? && !m.operation_service.empty? end if nonstandard_lro_candidates.length.positive? ops_service_method = nonstandard_lro_candidates[0] error_text = "A service `#{service.name}` has a method annotated " \ "with `polling_method` (`#{polling_method.name}`), and also a method annotated " \ "with `operation_service` (`#{ops_service_method.name}`). " \ "This means a grpc service tries to be a client " \ "and a provider of the nonstandard LRO at the same time. " \ "This is not supported." raise ModelError, error_text end lro_object_full_name = polling_method.output.full_name status_field = find_status_field service, polling_method operation_status_field = status_field.name operation_name_field = name_of_operation_field polling_method, ::Google::Cloud::OperationResponseMapping::NAME operation_err_code_field = name_of_operation_field polling_method, ::Google::Cloud::OperationResponseMapping::ERROR_CODE operation_err_msg_field = name_of_operation_field polling_method, ::Google::Cloud::OperationResponseMapping::ERROR_MESSAGE # optionally, there might be fields in the polling method's input object # that should be filled with information from the LRO object ops_response_fields = polling_method.input.fields.find_all do |f| !f.operation_response_field.nil? && !f.operation_response_field.empty? end operation_response_fields = ops_response_fields.to_h do |field| [field.name, field.operation_response_field] end NonstandardLroProvider.new service.full_name, polling_method.name, lro_object_full_name, operation_status_field, operation_name_field, operation_err_code_field, operation_err_msg_field, operation_response_fields end |