MCPcopy Create free account
hub / github.com/apache/nifi-minifi-cpp / closeTransaction

Method closeTransaction

extensions/http-curl/sitetosite/HTTPProtocol.cpp:236–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236void HttpSiteToSiteClient::closeTransaction(const utils::Identifier &transactionID) {
237 std::shared_ptr<Transaction> transaction = NULL;
238
239 auto it = this->known_transactions_.find(transactionID);
240
241 if (it == known_transactions_.end()) {
242 return;
243 }
244
245 transaction = it->second;
246 if (transaction->closed_) {
247 return;
248 }
249
250 std::string append_str;
251 logger_->log_trace("Site to Site closing transaction %s", transaction->getUUIDStr());
252
253
254 bool data_received = transaction->getDirection() == RECEIVE && (current_code == CONFIRM_TRANSACTION || current_code == TRANSACTION_FINISHED);
255
256 int code = UNRECOGNIZED_RESPONSE_CODE;
257 // In case transaction was used to actually transmit data (conditions are a bit different for send and receive to detect this),
258 // it has to be confirmed before closing.
259 // In case no data was transmitted, there is nothing to confirm, so the transaction can be cancelled without confirming it.
260 // Confirm means matching CRC checksum of data at both sides.
261 if (transaction->getState() == TRANSACTION_CONFIRMED || data_received) {
262 code = CONFIRM_TRANSACTION;
263 } else if (transaction->current_transfers_ == 0 && !transaction->isDataAvailable()) {
264 code = CANCEL_TRANSACTION;
265 } else {
266 std::string directon = transaction->getDirection() == RECEIVE ? "Receive" : "Send";
267 logger_->log_error("Transaction %s to be closed is in unexpected state. Direction: %s, tranfers: %d, bytes: %llu, state: %d",
268 transactionID.to_string(), directon, transaction->total_transfers_, transaction->_bytes, transaction->getState());
269 }
270
271 std::stringstream uri;
272 std::string dir_str = transaction->getDirection() == SEND ? "input-ports" : "output-ports";
273
274 uri << getBaseURI() << "data-transfer/" << dir_str << "/" << getPortId().to_string() << "/transactions/" << transactionID.to_string() << "?responseCode=" << code;
275
276 if (code == CONFIRM_TRANSACTION && data_received) {
277 uri << "&checksum=" << transaction->getCRC();
278 }
279
280 auto client = create_http_client(uri.str(), "DELETE");
281
282 client->appendHeader(PROTOCOL_VERSION_HEADER, "1");
283
284 client->setConnectionTimeout(std::chrono::milliseconds(5000));
285
286 client->appendHeader("Accept", "application/json");
287
288 client->submit();
289
290 logger_->log_debug("Received %d response code from delete", client->getResponseCode());
291
292 if (client->getResponseCode() == 400) {
293 std::string error(client->getResponseBody().data(), client->getResponseBody().size());

Callers

nothing calls this directly

Calls 15

getPortIdFunction · 0.85
ExceptionClass · 0.85
log_traceMethod · 0.80
getDirectionMethod · 0.80
isDataAvailableMethod · 0.80
log_errorMethod · 0.80
appendHeaderMethod · 0.80
submitMethod · 0.80
log_debugMethod · 0.80
getResponseCodeMethod · 0.80
findMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected