Skip to content

Commit

Permalink
Merge pull request #8 from mindsphere/dev
Browse files Browse the repository at this point in the history
mcl_deployment component added. fixed sonar issues.
  • Loading branch information
mclib-dev authored Mar 26, 2021
2 parents a1885de + 0903b12 commit fce6a7a
Show file tree
Hide file tree
Showing 116 changed files with 10,257 additions and 546 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# [4.3.0] (2021-03-27)

## Features

* MCL Deployment component is introduced for agents to access Deployment Workflow API of MindSphere.

# [4.2.4] (2020-11-28)

## Features
Expand Down
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ OPTION(MCL_CONNECTIVITY "Option to compile connectivity extension." ON)
# Option to compile data lake extension.
OPTION(MCL_DATA_LAKE "Option to compile data lake extension." ON)

# Option to compile deployment extension.
OPTION(MCL_DEPLOYMENT "Option to compile deployment extension." ON)

# Option to set if MCL build as static or dynamic.
OPTION(MCL_STATICLIB "Option to build static or dynamic." OFF)

Expand All @@ -120,3 +123,7 @@ ENDIF()
IF(MCL_DATA_LAKE)
ADD_SUBDIRECTORY(mcl_data_lake)
ENDIF()

IF(MCL_DEPLOYMENT)
ADD_SUBDIRECTORY(mcl_deployment)
ENDIF()
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ Agents will be able to upload unstructured data to MindSphere Data Lake with **D
which is also an extension to **Core** component and it is independent of the **Connectivity** component.
Including **mcl_data_lake.h** in agent source code will enable all data lake component functionality together with core component functionality.

Agents will be able to get and update any workflows assigned to them with **Deployment** component of MCL, an extension to **Core** component.
Including **mcl_deployment.h** in agent source code will enable all deployment component functionality together with core component functionality.

MCL build process will generate separate output binaries for each component.
Agents willing to exploit only the core functionality can do so by building and including only the core component.
Agents willing to exploit any extension component functionality can do so by building and including that extension component together with
Expand Down Expand Up @@ -294,7 +297,8 @@ $ cmake -DCMAKE_PREFIX_PATH="<OpenSSL_Install_Directory>;<libcurl_Install_Direct
$ cmake --build . --clean-first --target install
```

Now, there must be folders named **mcl_core** and **mcl_connectivity** containing MCL headers in **\<MCL_Install_Directory\>/include** and shared objects named **libmcl_core.so** and **libmcl_connectivity.so** in **\<MCL_Install_Directory\>/lib**.
Now, there must be folders named **mcl_core**, **mcl_connectivity**, **mcl_data_lake** and **mcl_deployment** containing MCL headers in **\<MCL_Install_Directory\>/include**
and shared objects named **libmcl_core.so**, **libmcl_connectivity.so**, **libmcl_data_lake.so** and **libmcl_deployment.so** in **\<MCL_Install_Directory\>/lib**.

#### MCL Build Options
You can build MCL with different configurations with the options listed in the table below:
Expand All @@ -306,6 +310,7 @@ MCL_DOC | OFF | If set to ON, MCL reference documentation is also built.
MCL_TEST | OFF | If set to ON and if ruby is found in path MCL is built with tests.
MCL_CONNECTIVITY | ON | If set to ON, MCL Connectivity component will also be built.
MCL_DATA_LAKE | ON | If set to ON, MCL Data Lake component will also be built.
MCL_DEPLOYMENT | ON | If set to ON, MCL Deployment component will also be built.
MCL_CRYPTO | "openssl" | See "Replacing MCL Modules" section.
MCL_HTTP_CLIENT | "curl" | See "Replacing MCL Modules" section.
MCL_FILE_UTIL | "standard" | See "Replacing MCL Modules" section.
Expand Down Expand Up @@ -396,8 +401,6 @@ data point mapping details.
Agents have the option to exchange each data item a a single or they have the option to exchange multiple data items
independent of their types together in a store (**mcl_store_t). See **mcl_store.h** for details.

Most of the functions in MCL return a status code (E_MCL_CORE_RETURN_CODE, E_MCL_CONNECTIVITY_RETURN_CODE) defined in **mcl_core_common.h** and **mcl_connectivity_common.h**.

## Examples
You can find agent application examples using MCL in **/examples** folder of each component of MCL distribution.

Expand Down Expand Up @@ -435,5 +438,9 @@ Check <MCL_Source_Directory>/mcl_connectivity/examples/event_upload.c file for t
This example agent uploads an object to MindSphere Data Lake.
Check <MCL_Source_Directory>/mcl_data_lake/examples/data_lake_upload.c file for the implementation.

### Example : Deployment Workflow
This example agent gets and updates deployment workflow assigned to it.
Check <MCL_Source_Directory>/mcl_deployment/examples/manage_deployment.c file for the implementation.

## Licensing
Please see the files called LICENSE.md and ReadMe_OSS.htm.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ extern "C"
typedef enum E_MCL_CONNECTIVITY_RETURN_CODE
{
MCL_FILE_CANNOT_BE_OPENED = MCL_CORE_RETURN_CODE_END, //!< File can not be opened.
MCL_TOO_MANY_REQUESTS, //!< If the response of server is HTTP 429.
MCL_ITEM_EXCEEDS_MAX_HTTP_REQUEST_SIZE, //!< Item exceeds max http payload request.
MCL_STORE_IS_EMPTY, //!< The store trying to be exchanged has no data inside.
MCL_CONNECTIVITY_RETURN_CODE_END //!< End of return codes.
Expand Down
1 change: 0 additions & 1 deletion mcl_connectivity/src/connectivity_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
const char *mcl_connectivity_return_code_strings[MCL_CONNECTIVITY_RETURN_CODE_END - MCL_CORE_RETURN_CODE_END] =
{
"MCL_FILE_CANNOT_BE_OPENED",
"MCL_TOO_MANY_REQUESTS",
"MCL_ITEM_EXCEEDS_MAX_HTTP_REQUEST_SIZE",
"MCL_STORE_IS_EMPTY"
};
9 changes: 6 additions & 3 deletions mcl_connectivity/src/connectivity_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ mcl_error_t mcl_connectivity_configuration_initialize(mcl_connectivity_configura
return code;
}

mcl_error_t mcl_connectivity_configuration_set_parameter(mcl_connectivity_configuration_t *configuration, E_MCL_CONNECTIVITY_CONFIGURATION_PARAMETER parameter, const void *value)
mcl_error_t mcl_connectivity_configuration_set_parameter(mcl_connectivity_configuration_t *configuration,
E_MCL_CONNECTIVITY_CONFIGURATION_PARAMETER parameter, const void *value)
{
mcl_error_t code = MCL_OK;

MCL_DEBUG_ENTRY("mcl_connectivity_configuration_t *configuration = <%p>, E_MCL_CONNECTIVITY_CONFIGURATION_PARAMETER parameter = <%d>, const void *value = <%p>", configuration, parameter, value);
MCL_DEBUG_ENTRY("mcl_connectivity_configuration_t *configuration = <%p>, E_MCL_CONNECTIVITY_CONFIGURATION_PARAMETER parameter = <%d>, "\
"const void *value = <%p>", configuration, parameter, value);

MCL_ASSERT_NOT_NULL(configuration, code);
MCL_ASSERT_NOT_NULL(value, code);
Expand All @@ -64,7 +66,8 @@ mcl_error_t mcl_connectivity_configuration_set_parameter(mcl_connectivity_config

case MCL_CONNECTIVITY_CONFIGURATION_PARAMETER_MAX_HTTP_PAYLOAD_SIZE:

if ((MCL_CONNECTIVITY_MIN_HTTP_PAYLOAD_SIZE <= *((const mcl_size_t *) value)) && (MCL_CONNECTIVITY_MAX_HTTP_PAYLOAD_SIZE >= *((const mcl_size_t *) value)))
if ((MCL_CONNECTIVITY_MIN_HTTP_PAYLOAD_SIZE <= *((const mcl_size_t *) value)) &&
(MCL_CONNECTIVITY_MAX_HTTP_PAYLOAD_SIZE >= *((const mcl_size_t *) value)))
{
configuration->max_http_payload_size = *((const mcl_size_t *) value);
}
Expand Down
112 changes: 27 additions & 85 deletions mcl_connectivity/src/connectivity_processor.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,6 @@ static mcl_error_t _generate_correlation_id_string(char *correlation_id);
// Function used to evaluate the response to the exchange request.
static mcl_error_t _evaluate_response_for_exchange(mcl_http_response_t *response, const char *correlation_id);

// Function used to map status code of the response to MCL return code.
static mcl_error_t _evaluate_response_codes(mcl_http_response_t *response);

// Function used to add file tuple with callback.
static mcl_size_t _file_payload_callback(char *buffer, mcl_size_t size, mcl_size_t count, void *user_context);

Expand Down Expand Up @@ -355,7 +352,7 @@ mcl_error_t connectivity_processor_create_mapping(connectivity_processor_t *conn
MCL_ERROR("HTTP Response:\n%.*s", http_response->payload_size, http_response->payload);
}

code = _evaluate_response_codes(http_response);
code = mcl_http_response_get_status(http_response);

if (MCL_OK == code)
{
Expand All @@ -382,7 +379,8 @@ mcl_error_t connectivity_processor_get_data_source_configuration(connectivity_pr
char *url;
*configuration = MCL_NULL;

MCL_DEBUG_ENTRY("connectivity_processor_t *connectivity_processor = <%p>, data_source_configuration_t **configuration = <%p>", connectivity_processor, configuration);
MCL_DEBUG_ENTRY("connectivity_processor_t *connectivity_processor = <%p>, data_source_configuration_t **configuration = <%p>",
connectivity_processor, configuration);

// Calculate url length.
agent_id_length = mcl_string_util_strlen(connectivity_processor->agent_id);
Expand Down Expand Up @@ -461,7 +459,7 @@ mcl_error_t connectivity_processor_get_data_source_configuration(connectivity_pr
}
else
{
code = _evaluate_response_codes(http_response);
code = mcl_http_response_get_status(http_response);
}
}

Expand All @@ -475,7 +473,8 @@ static mcl_error_t _scan_store_after_exchange(store_t *store, mcl_bool_t *store_
{
mcl_error_t code = exchange_response;

MCL_DEBUG_ENTRY("store_t *store = <%p>, mcl_bool_t *store_fully_processed = <%p>, mcl_error_t exchange_response = <%d>", store, store_fully_processed, exchange_response);
MCL_DEBUG_ENTRY("store_t *store = <%p>, mcl_bool_t *store_fully_processed = <%p>, mcl_error_t exchange_response = <%d>",
store, store_fully_processed, exchange_response);

if (MCL_OK == code)
{
Expand All @@ -501,7 +500,8 @@ static mcl_error_t _add_http_headers_for_exchange(connectivity_processor_t *proc
{
mcl_error_t code;

MCL_DEBUG_ENTRY("connectivity_processor_t *processor = <%p>, mcl_http_request_t *request = <%p>, const char *boundary = <%p>", processor, request, boundary);
MCL_DEBUG_ENTRY("connectivity_processor_t *processor = <%p>, mcl_http_request_t *request = <%p>, const char *boundary = <%p>",
processor, request, boundary);

// Add boundary.
code = _add_multipart_mixed_content_type_header(request, boundary);
Expand All @@ -523,12 +523,13 @@ static mcl_error_t _add_http_headers_for_exchange(connectivity_processor_t *proc
static mcl_error_t _add_multipart_mixed_content_type_header(mcl_http_request_t *request, const char *boundary)
{
mcl_error_t code;
mcl_size_t header_value_length;
char *header_value;
mcl_size_t header_value_length;
mcl_size_t constant_part_length = 24;

MCL_DEBUG_ENTRY("mcl_http_request_t *request = <%p>, const char *boundary = <%p>", request, boundary);

header_value_length = mcl_string_util_strlen(content_type_values[CONTENT_TYPE_MULTIPART_MIXED]) + mcl_string_util_strlen(boundary) + 24;
header_value_length = mcl_string_util_strlen(content_type_values[CONTENT_TYPE_MULTIPART_MIXED]) + mcl_string_util_strlen(boundary) + constant_part_length;

header_value = MCL_MALLOC(header_value_length + 1);

Expand All @@ -540,7 +541,8 @@ static mcl_error_t _add_multipart_mixed_content_type_header(mcl_http_request_t *
else
{
// Compose header value.
code = mcl_string_util_snprintf(header_value, header_value_length + 1, "%s;boundary=%s;charset=utf-8", content_type_values[CONTENT_TYPE_MULTIPART_MIXED], boundary);
code = mcl_string_util_snprintf(header_value, header_value_length + 1, "%s;boundary=%s;charset=utf-8",
content_type_values[CONTENT_TYPE_MULTIPART_MIXED], boundary);

// Add header to http request.
if (MCL_OK == code)
Expand Down Expand Up @@ -597,73 +599,7 @@ static mcl_error_t _evaluate_response_for_exchange(mcl_http_response_t *response
MCL_ERROR("HTTP Response:\n%.*s", response->payload_size, response->payload);
}

code = _evaluate_response_codes(response);
}

MCL_DEBUG_LEAVE("retVal = <%d>", code);
return code;
}

static mcl_error_t _evaluate_response_codes(mcl_http_response_t *response)
{
mcl_error_t code;

MCL_DEBUG_ENTRY("mcl_http_response_t *response = <%p>", response);

switch (response->status_code)
{
case MCL_HTTP_STATUS_CODE_SUCCESS:
code = MCL_OK;
break;

case MCL_HTTP_STATUS_CODE_CREATED:
code = MCL_CREATED;
break;

case MCL_HTTP_STATUS_CODE_PARTIAL_CONTENT:
code = MCL_PARTIAL_CONTENT;
break;

case MCL_HTTP_STATUS_CODE_BAD_REQUEST:
code = MCL_BAD_REQUEST;
break;

case MCL_HTTP_STATUS_CODE_UNAUTHORIZED:
code = MCL_UNAUTHORIZED;
break;

case MCL_HTTP_STATUS_CODE_FORBIDDEN:
code = MCL_FORBIDDEN;
break;

case MCL_HTTP_STATUS_CODE_NOT_FOUND:
code = MCL_NOT_FOUND;
break;

case MCL_HTTP_STATUS_CODE_INTERNAL_SERVER_ERR:
code = MCL_SERVER_FAIL;
break;

case MCL_HTTP_STATUS_CODE_CONFLICT:
code = MCL_CONFLICT;
break;

case MCL_HTTP_STATUS_CODE_PRECONDITION_FAILED:
code = MCL_PRECONDITION_FAIL;
break;

case MCL_HTTP_STATUS_CODE_PAYLOAD_TOO_LARGE:
code = MCL_REQUEST_PAYLOAD_TOO_LARGE;
break;

case MCL_HTTP_RESULT_CODE_TOO_MANY_REQUESTS:
code = MCL_TOO_MANY_REQUESTS;
break;

default:
code = MCL_UNEXPECTED_RESULT_CODE;
MCL_INFO("Server responded with unexpected HTTP status code %d.", response->status_code);
break;
code = mcl_http_response_get_status(response);
}

MCL_DEBUG_LEAVE("retVal = <%d>", code);
Expand All @@ -674,7 +610,7 @@ static mcl_error_t _generate_correlation_id_string(char *correlation_id)
{
mcl_error_t code;
mcl_int16_t index;
unsigned char *id = (unsigned char*)correlation_id;
unsigned char *id = (unsigned char*) correlation_id;

MCL_DEBUG_ENTRY("char *correlation_id = <%p>", correlation_id);

Expand Down Expand Up @@ -728,7 +664,8 @@ static mcl_error_t _add_item_to_buffer(char *buffer, mcl_size_t *buffer_size, mc
{
mcl_error_t code;

MCL_DEBUG_ENTRY("char *buffer = <%p>, mcl_size_t *buffer_size = <%p>, mcl_item_t *item = <%p>, const char *boundary = <%p>", buffer, buffer_size, item, boundary);
MCL_DEBUG_ENTRY("char *buffer = <%p>, mcl_size_t *buffer_size = <%p>, mcl_item_t *item = <%p>, const char *boundary = <%p>",
buffer, buffer_size, item, boundary);

switch (item->type)
{
Expand All @@ -740,7 +677,8 @@ static mcl_error_t _add_item_to_buffer(char *buffer, mcl_size_t *buffer_size, mc

case MCL_ITEM_TYPE_FILE:
mcl_file_util_rewind(((file_t *) item)->payload->file_descriptor);
code = multipart_add_tuple_with_callback(buffer, buffer_size, item, boundary, content_type_values[CONTENT_TYPE_APPLICATION_OCTET_STREAM], _file_payload_callback, item);
code = multipart_add_tuple_with_callback(buffer, buffer_size, item, boundary,
content_type_values[CONTENT_TYPE_APPLICATION_OCTET_STREAM], _file_payload_callback, item);
break;

case MCL_ITEM_TYPE_CUSTOM_DATA:
Expand Down Expand Up @@ -886,7 +824,8 @@ static mcl_error_t _prepare_body_for_store(store_t *store, mcl_size_t max_http_p
mcl_size_t remaining_size;
mcl_error_t code;

MCL_DEBUG_ENTRY("store_t *store = <%p>, mcl_size_t max_http_payload_size = <%lu>, char *boundary = <%p>, mcl_uint8_t **body = <%p>, mcl_size_t *body_size = <%p>", store, max_http_payload_size, boundary, body, body_size);
MCL_DEBUG_ENTRY("store_t *store = <%p>, mcl_size_t max_http_payload_size = <%lu>, char *boundary = <%p>, mcl_uint8_t **body = <%p>, "\
"mcl_size_t *body_size = <%p>", store, max_http_payload_size, boundary, body, body_size);

*body_size = 0;
remaining_size = _select_store_items_to_exchange(store, max_http_payload_size);
Expand Down Expand Up @@ -941,7 +880,8 @@ static mcl_error_t _prepare_body(mcl_item_t *item, mcl_size_t max_http_payload_s
{
mcl_error_t code = MCL_OK;

MCL_DEBUG_ENTRY("mcl_item_t *item = <%p>, mcl_size_t max_http_payload_size = <%lu>, char *boundary = <%p>, mcl_uint8_t **body = <%p>, mcl_size_t *body_size = <%lu>", item, max_http_payload_size, boundary, body, body_size);
MCL_DEBUG_ENTRY("mcl_item_t *item = <%p>, mcl_size_t max_http_payload_size = <%lu>, char *boundary = <%p>, mcl_uint8_t **body = <%p>, "\
"mcl_size_t *body_size = <%lu>", item, max_http_payload_size, boundary, body, body_size);

if (MCL_ITEM_TYPE_STORE == item->type)
{
Expand Down Expand Up @@ -1059,14 +999,16 @@ static mcl_error_t _add_custom_data_to_buffer(char *buffer, mcl_size_t *buffer_s
mcl_error_t code;
custom_data_callback_user_context user_context;

MCL_DEBUG_ENTRY("char *buffer = <%p>, mcl_size_t *buffer_size = <%p>, custom_data_t *custom_data = <%p>, const char *boundary = <%p>", buffer, buffer_size, custom_data, boundary);
MCL_DEBUG_ENTRY("char *buffer = <%p>, mcl_size_t *buffer_size = <%p>, custom_data_t *custom_data = <%p>, const char *boundary = <%p>",
buffer, buffer_size, custom_data, boundary);

// Set user context.
user_context.custom_data = custom_data;
user_context.offset = 0;

// Add custom data to http_request.
code = multipart_add_tuple_with_callback(buffer, buffer_size, custom_data, boundary, custom_data->payload->content_type, _custom_data_payload_callback, &user_context);
code = multipart_add_tuple_with_callback(buffer, buffer_size, custom_data, boundary,
custom_data->payload->content_type, _custom_data_payload_callback, &user_context);

MCL_DEBUG_LEAVE("retVal = <%d>", code);
return code;
Expand Down
3 changes: 2 additions & 1 deletion mcl_connectivity/src/connectivity_processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ MCL_LOCAL mcl_error_t connectivity_processor_create_mapping(connectivity_process
* <li>#MCL_FAIL in case of an internal error in MCL.</li>
* </ul>
*/
MCL_LOCAL mcl_error_t connectivity_processor_get_data_source_configuration(connectivity_processor_t *connectivity_processor, data_source_configuration_t **configuration);
MCL_LOCAL mcl_error_t connectivity_processor_get_data_source_configuration(connectivity_processor_t *connectivity_processor,
data_source_configuration_t **configuration);

/**
* This function destroys connectivity processor data structure.
Expand Down
6 changes: 4 additions & 2 deletions mcl_connectivity/src/custom_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ mcl_error_t mcl_custom_data_set_parameter(mcl_custom_data_t *custom_data, E_MCL_
{
mcl_error_t code = MCL_OK;

MCL_DEBUG_ENTRY("mcl_custom_data_t *custom_data = <%p>, E_MCL_CUSTOM_DATA_PARAMETER parameter = <%d>, const void *value = <%p>", custom_data, parameter, value);
MCL_DEBUG_ENTRY("mcl_custom_data_t *custom_data = <%p>, E_MCL_CUSTOM_DATA_PARAMETER parameter = <%d>, const void *value = <%p>",
custom_data, parameter, value);

// Null check.
MCL_ASSERT_NOT_NULL(custom_data, code);
Expand Down Expand Up @@ -108,7 +109,8 @@ mcl_error_t custom_data_validate(custom_data_t *custom_data)
MCL_DEBUG_ENTRY("custom_data_t *custom_data = <%p>", custom_data);

// Checks whether all mandatory parameters of a custom data are set or not.
if ((MCL_NULL == payload->buffer) || (MCL_NULL == payload->content_type) || (MCL_NULL == payload->type) || (MCL_NULL == payload->version) || (0 == payload->size))
if ((MCL_NULL == payload->buffer) || (MCL_NULL == payload->content_type) ||
(MCL_NULL == payload->type) || (MCL_NULL == payload->version) || (0 == payload->size))
{
code = MCL_INVALID_PARAMETER;
}
Expand Down
3 changes: 2 additions & 1 deletion mcl_connectivity/src/data_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ mcl_error_t mcl_data_source_set_parameter(mcl_data_source_t *data_source, E_MCL_
{
mcl_error_t code;

MCL_DEBUG_ENTRY("mcl_data_source_t *data_source = <%p>, E_MCL_DATA_SOURCE_PARAMETER parameter = <%d>, const void *value = <%p>", data_source, parameter, value);
MCL_DEBUG_ENTRY("mcl_data_source_t *data_source = <%p>, E_MCL_DATA_SOURCE_PARAMETER parameter = <%d>, const void *value = <%p>",
data_source, parameter, value);

// Null check.
MCL_ASSERT_NOT_NULL(data_source, code);
Expand Down
Loading

0 comments on commit fce6a7a

Please sign in to comment.