Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more granular upload-to-blob functions, refactor u2b code #2498

Merged
merged 30 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
1257313
Add more granular upload-to-blob functions, refactor u2b code
ewertons Jun 30, 2023
c49c3d1
[ACR] Expose upload-to-blob correlation ID and SAS URI in new API fun…
ewertons Jul 8, 2023
c4b3bee
Merge branch 'main' into ewertons/u2b
ewertons Jul 10, 2023
e176cef
Address code review comments (2)
ewertons Jul 11, 2023
161463c
Update unit tests for blob.c
ewertons Jul 12, 2023
136911a
Update iothub_client_ll_u2b_ut
ewertons Jul 12, 2023
969f6b7
Update iothub_client_ll_u2b_ut (continued) and other fixes
ewertons Jul 14, 2023
184ced4
Update iothub_client_ll_u2b_ut (continued 2)
ewertons Jul 15, 2023
824652a
Update iothub_client_ll_u2b_ut (continued 3)
ewertons Jul 16, 2023
3814713
Update iothub_client_ll_u2b_ut (continued 4)
ewertons Jul 17, 2023
96d4669
Merge branch 'main' into ewertons/u2b
ewertons Jul 17, 2023
e2ea53d
Updates to iothub_client_core_ll_ut
ewertons Jul 18, 2023
5c000b0
Updates to iothub_client_core_ll_ut (continued)
ewertons Jul 18, 2023
561dd8a
Additional unit test fixes
ewertons Jul 18, 2023
8cae131
Fix return of blob result in iothubclient_ll_u2b_ut
ewertons Jul 18, 2023
297cfb5
Fix size_t to int conversion in iothub_client_ll_uploadtoblob.c
ewertons Jul 18, 2023
2bce60f
Add fixes for clang build
ewertons Jul 18, 2023
20065e6
More fixes for clang and windows builds
ewertons Jul 19, 2023
8bec9ad
Fix DONT_USE_UPLOADTOBLOB guards in code
ewertons Jul 19, 2023
21eb23e
More build and test fixes
ewertons Jul 19, 2023
391e27a
More build fixes
ewertons Jul 19, 2023
3ef5d88
More test fixes in iothub_client_ll_u2b_ut for OSX pipeline
ewertons Jul 19, 2023
76c3aec
Reduce number of iterations of IoTHub_MQTT_UploadCloseHandle_Before_W…
ewertons Jul 19, 2023
276e03d
Address CR comments from Eric
ewertons Jul 19, 2023
e01a280
Add retry logic to iothub_client_sample_upload_to_blob_custom
ewertons Jul 19, 2023
2129550
Address code review comments (function renaming)
ewertons Jul 20, 2023
6619adc
Merge branch 'main' into ewertons/u2b
ewertons Jul 20, 2023
48e7fce
Verify and log http response status code in u2b functions
ewertons Jul 20, 2023
a31dacb
Update blob_ut
ewertons Jul 20, 2023
2db1cb9
Address final CR comments
ewertons Jul 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 32 additions & 20 deletions iothub_client/inc/internal/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "azure_c_shared_utility/buffer_.h"
#include "azure_c_shared_utility/strings_types.h"
#include "azure_c_shared_utility/httpapiex.h"
#include "azure_c_shared_utility/singlylinkedlist.h"
#include "iothub_client_core_ll.h"
#include "azure_c_shared_utility/shared_util_options.h"

Expand Down Expand Up @@ -46,36 +47,47 @@ extern "C"

MU_DEFINE_ENUM_WITHOUT_INVALID(BLOB_RESULT, BLOB_RESULT_VALUES)

MOCKABLE_FUNCTION(, HTTPAPIEX_HANDLE, Blob_CreateHttpConnection, const char*, blobStorageHostname, const char*, certificates, HTTP_PROXY_OPTIONS*, proxyOptions, const char*, networkInterface, const size_t, timeoutInMilliseconds);

MOCKABLE_FUNCTION(, void, Blob_DestroyHttpConnection, HTTPAPIEX_HANDLE, httpApiExHandle);

MOCKABLE_FUNCTION(, void, Blob_ClearBlockIdList, SINGLYLINKEDLIST_HANDLE, blockIdList);

/**
* @brief Synchronously uploads a byte array to blob storage
*
* @param SASURI The URI to use to upload data
* @param getDataCallbackEx A callback to be invoked to acquire the file chunks to be uploaded, as well as to indicate the status of the upload of the previous block.
* @param context Any data provided by the user to serve as context on getDataCallback.
* @param httpStatus A pointer to an out argument receiving the HTTP status (available only when the return value is BLOB_OK)
* @param httpResponse A BUFFER_HANDLE that receives the HTTP response from the server (available only when the return value is BLOB_OK)
* @param certificates A null terminated string containing CA certificates to be used
* @param proxyOptions A structure that contains optional web proxy information
* @param networkInterface An optional null terminated string containing the network interface
* @param timeoutInMilliseconds The maximum time in ms allowed for a blob transfer. A value of 0 uses the default timeout for the underlying transport.
* @brief Synchronously uploads a byte array as a new block to blob storage (put block operation)
*
* @return A @c BLOB_RESULT. BLOB_OK means the blob has been uploaded successfully. Any other value indicates an error
* @param httpApiExHandle The HTTP connection handle
* @param relativePath The destination path within the storage
* @param blockID The block id (from 00000 to 49999)
* @param blockData The data to upload
* @param blockIDList The list where to store the block IDs
* @param httpStatus A pointer to an out argument receiving the HTTP status (available only when the return value is BLOB_OK)
* @param httpResponse A BUFFER_HANDLE that receives the HTTP response from the server (available only when the return value is BLOB_OK)
*/
MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_UploadMultipleBlocksFromSasUri, const char*, SASURI, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context, unsigned int*, httpStatus, BUFFER_HANDLE, httpResponse, const char*, certificates, HTTP_PROXY_OPTIONS*, proxyOptions, const char*, networkInterface, const size_t, timeoutInMilliseconds)
MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_PutBlock,
HTTPAPIEX_HANDLE, httpApiExHandle,
const char*, relativePath,
unsigned int, blockID,
BUFFER_HANDLE, blockData,
SINGLYLINKEDLIST_HANDLE, blockIDList,
unsigned int*, httpStatus,
BUFFER_HANDLE, httpResponse)

/**
* @brief Synchronously uploads a byte array as a new block to blob storage
* @brief Synchronously sends a put block list request to Azure Storage
*
* @param requestContent The data to upload
* @param blockId The block id (from 00000 to 49999)
* @param xml The XML file containing the blockId list
* @param httpApiExHandle The HTTP connection handle
* @param relativePath The destination path within the storage
* @param httpApiExHandle The connection handle
* @param blockIDList The list containing the block IDs to report
* @param httpStatus A pointer to an out argument receiving the HTTP status (available only when the return value is BLOB_OK)
* @param httpResponse A BUFFER_HANDLE that receives the HTTP response from the server (available only when the return value is BLOB_OK)
*/
//MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_UploadNextBlock, BUFFER_HANDLE, requestContent, unsigned int, blockID, STRING_HANDLE, xml, const char*, relativePath, HTTPAPIEX_HANDLE, httpApiExHandle, unsigned int*, httpStatus, BUFFER_HANDLE, httpResponse)
MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_UploadBlock, HTTPAPIEX_HANDLE, httpApiExHandle, const char*, relativePath, BUFFER_HANDLE, requestContent, unsigned int, blockID, STRING_HANDLE, blockIDList, unsigned int*, httpStatus, BUFFER_HANDLE, httpResponse)
MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_PutBlockList,
HTTPAPIEX_HANDLE, httpApiExHandle,
const char*, relativePath,
SINGLYLINKEDLIST_HANDLE, blockIDList,
unsigned int*, httpStatus,
BUFFER_HANDLE, httpResponse)
#ifdef __cplusplus
}
#endif
Expand Down
20 changes: 18 additions & 2 deletions iothub_client/inc/internal/iothub_client_ll_uploadtoblob.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,26 @@ extern "C"
#define BLOCK_SIZE (100*1024*1024)

typedef struct IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE_DATA* IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE;
typedef struct IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_STRUCT* IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE;

MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, IoTHubClient_LL_UploadToBlob_Create, const IOTHUB_CLIENT_CONFIG*, config, IOTHUB_AUTHORIZATION_HANDLE, auth_handle);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_Impl, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle, const char*, destinationFileName, const unsigned char*, source, size_t, size);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadMultipleBlocksToBlob_Impl, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context);

/*
* @remark This is a function left in this module for legacy compatibility with the exposed public API for
* upload to blob in iothub_(device|module)_client(_ll) that allowed passing a callback for obtaining the
* blob blocks data. Since there was quite a lot of (specific) logic put into this function that it
* better reside in this API module.
*/
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_UploadMultipleBlocks, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContextHandle, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context);


MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_InitializeUpload, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle, const char*, destinationFileName, char**, uploadCorrelationId, char**, azureBlobSasUri);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, IoTHubClient_LL_UploadToBlob_CreateContext, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle, const char*, azureBlobSasUri);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_PutBlock, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContext, uint32_t, blockNumber, const uint8_t*, dataPtr, size_t, dataSize);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_PutBlockList, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContext);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_DestroyContext, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContext);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_NotifyCompletion, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle, const char*, uploadCorrelationId, bool, isSuccess, int, responseCode, const char*, responseMessage);

MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_UploadToBlob_SetOption, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle, const char*, optionName, const void*, value);
MOCKABLE_FUNCTION(, void, IoTHubClient_LL_UploadToBlob_Destroy, IOTHUB_CLIENT_LL_UPLOADTOBLOB_HANDLE, handle);

Expand Down
6 changes: 6 additions & 0 deletions iothub_client/inc/iothub_client_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ extern "C"
#ifndef DONT_USE_UPLOADTOBLOB
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_UploadToBlobAsync, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size, IOTHUB_CLIENT_FILE_UPLOAD_CALLBACK, iotHubClientFileUploadCallback, void*, context);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_UploadMultipleBlocksToBlobAsync, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK, getDataCallback, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_InitializeUpload, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, const char*, destinationFileName, char**, uploadCorrelationId, char**, azureBlobSasUri);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, IoTHubClientCore_CreateUploadContext, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, const char*, azureBlobSasUri);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_AzureStoragePutBlock, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContextHandle, uint32_t, blockNumber, const uint8_t*, dataPtr, size_t, dataSize);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_AzureStoragePutBlockList, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContextHandle);
MOCKABLE_FUNCTION(, void, IoTHubClientCore_DestroyUploadContext, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContextHandle);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_NotifyUploadCompletion, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, const char*, uploadCorrelationId, bool, isSuccess, int, responseCode, const char*, responseMessage);
#endif /* DONT_USE_UPLOADTOBLOB */

MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_SendEventToOutputAsync, IOTHUB_CLIENT_CORE_HANDLE, iotHubClientHandle, IOTHUB_MESSAGE_HANDLE, eventMessageHandle, const char*, outputName, IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK, eventConfirmationCallback, void*, userContextCallback);
Expand Down
8 changes: 8 additions & 0 deletions iothub_client/inc/iothub_client_core_ll.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

Expand All @@ -18,6 +19,7 @@ typedef struct IOTHUB_CLIENT_CORE_LL_HANDLE_DATA_TAG* IOTHUB_CLIENT_CORE_LL_HAND
#include "umock_c/umock_c_prod.h"
#include "iothub_transport_ll.h"
#include "iothub_client_core_common.h"
#include "internal/iothub_client_ll_uploadtoblob.h"

#ifdef __cplusplus
extern "C"
Expand Down Expand Up @@ -52,6 +54,12 @@ extern "C"
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_UploadToBlob, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, const unsigned char*, source, size_t, size);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_UploadMultipleBlocksToBlob, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK, getDataCallback, void*, context);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_UploadMultipleBlocksToBlobEx, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, IOTHUB_CLIENT_FILE_UPLOAD_GET_DATA_CALLBACK_EX, getDataCallbackEx, void*, context);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_InitializeUpload, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, const char*, destinationFileName, char**, uploadCorrelationId, char**, azureBlobSasUri);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, IoTHubClientCore_LL_CreateUploadContext, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, const char*, azureBlobSasUri);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_AzureStoragePutBlock, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContextHandle, uint32_t, blockNumber, const uint8_t*, dataPtr, size_t, dataSize);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_AzureStoragePutBlockList, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContextHandle);
MOCKABLE_FUNCTION(, void, IoTHubClientCore_LL_DestroyUploadContext, IOTHUB_CLIENT_LL_UPLOADTOBLOB_CONTEXT_HANDLE, uploadContextHandle);
MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClientCore_LL_NotifyUploadCompletion, IOTHUB_CLIENT_CORE_LL_HANDLE, iotHubClientHandle, const char*, uploadCorrelationId, bool, isSuccess, int, responseCode, const char*, responseMessage);
#endif /*DONT_USE_UPLOADTOBLOB*/

#ifdef USE_EDGE_MODULES
Expand Down
Loading