2025-02-11 19:36:46 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1beta1_basic_device.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static v1beta1_basic_device_t *v1beta1_basic_device_create_internal(
|
2025-06-08 08:13:38 +00:00
|
|
|
int all_nodes,
|
2025-02-11 19:36:46 +00:00
|
|
|
list_t* attributes,
|
2025-06-08 08:13:38 +00:00
|
|
|
list_t* capacity,
|
|
|
|
|
list_t *consumes_counters,
|
|
|
|
|
char *node_name,
|
|
|
|
|
v1_node_selector_t *node_selector,
|
|
|
|
|
list_t *taints
|
2025-02-11 19:36:46 +00:00
|
|
|
) {
|
|
|
|
|
v1beta1_basic_device_t *v1beta1_basic_device_local_var = malloc(sizeof(v1beta1_basic_device_t));
|
|
|
|
|
if (!v1beta1_basic_device_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
2025-06-08 08:13:38 +00:00
|
|
|
v1beta1_basic_device_local_var->all_nodes = all_nodes;
|
2025-02-11 19:36:46 +00:00
|
|
|
v1beta1_basic_device_local_var->attributes = attributes;
|
|
|
|
|
v1beta1_basic_device_local_var->capacity = capacity;
|
2025-06-08 08:13:38 +00:00
|
|
|
v1beta1_basic_device_local_var->consumes_counters = consumes_counters;
|
|
|
|
|
v1beta1_basic_device_local_var->node_name = node_name;
|
|
|
|
|
v1beta1_basic_device_local_var->node_selector = node_selector;
|
|
|
|
|
v1beta1_basic_device_local_var->taints = taints;
|
2025-02-11 19:36:46 +00:00
|
|
|
|
|
|
|
|
v1beta1_basic_device_local_var->_library_owned = 1;
|
|
|
|
|
return v1beta1_basic_device_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
__attribute__((deprecated)) v1beta1_basic_device_t *v1beta1_basic_device_create(
|
2025-06-08 08:13:38 +00:00
|
|
|
int all_nodes,
|
2025-02-11 19:36:46 +00:00
|
|
|
list_t* attributes,
|
2025-06-08 08:13:38 +00:00
|
|
|
list_t* capacity,
|
|
|
|
|
list_t *consumes_counters,
|
|
|
|
|
char *node_name,
|
|
|
|
|
v1_node_selector_t *node_selector,
|
|
|
|
|
list_t *taints
|
2025-02-11 19:36:46 +00:00
|
|
|
) {
|
|
|
|
|
return v1beta1_basic_device_create_internal (
|
2025-06-08 08:13:38 +00:00
|
|
|
all_nodes,
|
2025-02-11 19:36:46 +00:00
|
|
|
attributes,
|
2025-06-08 08:13:38 +00:00
|
|
|
capacity,
|
|
|
|
|
consumes_counters,
|
|
|
|
|
node_name,
|
|
|
|
|
node_selector,
|
|
|
|
|
taints
|
2025-02-11 19:36:46 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void v1beta1_basic_device_free(v1beta1_basic_device_t *v1beta1_basic_device) {
|
|
|
|
|
if(NULL == v1beta1_basic_device){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
if(v1beta1_basic_device->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1beta1_basic_device_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
listEntry_t *listEntry;
|
|
|
|
|
if (v1beta1_basic_device->attributes) {
|
|
|
|
|
list_ForEach(listEntry, v1beta1_basic_device->attributes) {
|
|
|
|
|
keyValuePair_t *localKeyValue = listEntry->data;
|
|
|
|
|
free (localKeyValue->key);
|
|
|
|
|
free (localKeyValue->value);
|
|
|
|
|
keyValuePair_free(localKeyValue);
|
|
|
|
|
}
|
|
|
|
|
list_freeList(v1beta1_basic_device->attributes);
|
|
|
|
|
v1beta1_basic_device->attributes = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1beta1_basic_device->capacity) {
|
|
|
|
|
list_ForEach(listEntry, v1beta1_basic_device->capacity) {
|
|
|
|
|
keyValuePair_t *localKeyValue = listEntry->data;
|
|
|
|
|
free (localKeyValue->key);
|
|
|
|
|
free (localKeyValue->value);
|
|
|
|
|
keyValuePair_free(localKeyValue);
|
|
|
|
|
}
|
|
|
|
|
list_freeList(v1beta1_basic_device->capacity);
|
|
|
|
|
v1beta1_basic_device->capacity = NULL;
|
|
|
|
|
}
|
2025-06-08 08:13:38 +00:00
|
|
|
if (v1beta1_basic_device->consumes_counters) {
|
|
|
|
|
list_ForEach(listEntry, v1beta1_basic_device->consumes_counters) {
|
|
|
|
|
v1beta1_device_counter_consumption_free(listEntry->data);
|
|
|
|
|
}
|
|
|
|
|
list_freeList(v1beta1_basic_device->consumes_counters);
|
|
|
|
|
v1beta1_basic_device->consumes_counters = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1beta1_basic_device->node_name) {
|
|
|
|
|
free(v1beta1_basic_device->node_name);
|
|
|
|
|
v1beta1_basic_device->node_name = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1beta1_basic_device->node_selector) {
|
|
|
|
|
v1_node_selector_free(v1beta1_basic_device->node_selector);
|
|
|
|
|
v1beta1_basic_device->node_selector = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1beta1_basic_device->taints) {
|
|
|
|
|
list_ForEach(listEntry, v1beta1_basic_device->taints) {
|
|
|
|
|
v1beta1_device_taint_free(listEntry->data);
|
|
|
|
|
}
|
|
|
|
|
list_freeList(v1beta1_basic_device->taints);
|
|
|
|
|
v1beta1_basic_device->taints = NULL;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
free(v1beta1_basic_device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1beta1_basic_device_convertToJSON(v1beta1_basic_device_t *v1beta1_basic_device) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
2025-06-08 08:13:38 +00:00
|
|
|
// v1beta1_basic_device->all_nodes
|
|
|
|
|
if(v1beta1_basic_device->all_nodes) {
|
|
|
|
|
if(cJSON_AddBoolToObject(item, "allNodes", v1beta1_basic_device->all_nodes) == NULL) {
|
|
|
|
|
goto fail; //Bool
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
// v1beta1_basic_device->attributes
|
|
|
|
|
if(v1beta1_basic_device->attributes) {
|
|
|
|
|
cJSON *attributes = cJSON_AddObjectToObject(item, "attributes");
|
|
|
|
|
if(attributes == NULL) {
|
|
|
|
|
goto fail; //primitive map container
|
|
|
|
|
}
|
|
|
|
|
cJSON *localMapObject = attributes;
|
|
|
|
|
listEntry_t *attributesListEntry;
|
|
|
|
|
if (v1beta1_basic_device->attributes) {
|
|
|
|
|
list_ForEach(attributesListEntry, v1beta1_basic_device->attributes) {
|
|
|
|
|
keyValuePair_t *localKeyValue = attributesListEntry->data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->capacity
|
|
|
|
|
if(v1beta1_basic_device->capacity) {
|
|
|
|
|
cJSON *capacity = cJSON_AddObjectToObject(item, "capacity");
|
|
|
|
|
if(capacity == NULL) {
|
|
|
|
|
goto fail; //primitive map container
|
|
|
|
|
}
|
|
|
|
|
cJSON *localMapObject = capacity;
|
|
|
|
|
listEntry_t *capacityListEntry;
|
|
|
|
|
if (v1beta1_basic_device->capacity) {
|
|
|
|
|
list_ForEach(capacityListEntry, v1beta1_basic_device->capacity) {
|
|
|
|
|
keyValuePair_t *localKeyValue = capacityListEntry->data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 08:13:38 +00:00
|
|
|
|
|
|
|
|
// v1beta1_basic_device->consumes_counters
|
|
|
|
|
if(v1beta1_basic_device->consumes_counters) {
|
|
|
|
|
cJSON *consumes_counters = cJSON_AddArrayToObject(item, "consumesCounters");
|
|
|
|
|
if(consumes_counters == NULL) {
|
|
|
|
|
goto fail; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *consumes_countersListEntry;
|
|
|
|
|
if (v1beta1_basic_device->consumes_counters) {
|
|
|
|
|
list_ForEach(consumes_countersListEntry, v1beta1_basic_device->consumes_counters) {
|
|
|
|
|
cJSON *itemLocal = v1beta1_device_counter_consumption_convertToJSON(consumes_countersListEntry->data);
|
|
|
|
|
if(itemLocal == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToArray(consumes_counters, itemLocal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->node_name
|
|
|
|
|
if(v1beta1_basic_device->node_name) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "nodeName", v1beta1_basic_device->node_name) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->node_selector
|
|
|
|
|
if(v1beta1_basic_device->node_selector) {
|
|
|
|
|
cJSON *node_selector_local_JSON = v1_node_selector_convertToJSON(v1beta1_basic_device->node_selector);
|
|
|
|
|
if(node_selector_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "nodeSelector", node_selector_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->taints
|
|
|
|
|
if(v1beta1_basic_device->taints) {
|
|
|
|
|
cJSON *taints = cJSON_AddArrayToObject(item, "taints");
|
|
|
|
|
if(taints == NULL) {
|
|
|
|
|
goto fail; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *taintsListEntry;
|
|
|
|
|
if (v1beta1_basic_device->taints) {
|
|
|
|
|
list_ForEach(taintsListEntry, v1beta1_basic_device->taints) {
|
|
|
|
|
cJSON *itemLocal = v1beta1_device_taint_convertToJSON(taintsListEntry->data);
|
|
|
|
|
if(itemLocal == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToArray(taints, itemLocal);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1beta1_basic_device_t *v1beta1_basic_device_parseFromJSON(cJSON *v1beta1_basic_deviceJSON){
|
|
|
|
|
|
|
|
|
|
v1beta1_basic_device_t *v1beta1_basic_device_local_var = NULL;
|
|
|
|
|
|
|
|
|
|
// define the local map for v1beta1_basic_device->attributes
|
|
|
|
|
list_t *attributesList = NULL;
|
|
|
|
|
|
|
|
|
|
// define the local map for v1beta1_basic_device->capacity
|
|
|
|
|
list_t *capacityList = NULL;
|
|
|
|
|
|
2025-06-08 08:13:38 +00:00
|
|
|
// define the local list for v1beta1_basic_device->consumes_counters
|
|
|
|
|
list_t *consumes_countersList = NULL;
|
|
|
|
|
|
|
|
|
|
// define the local variable for v1beta1_basic_device->node_selector
|
|
|
|
|
v1_node_selector_t *node_selector_local_nonprim = NULL;
|
|
|
|
|
|
|
|
|
|
// define the local list for v1beta1_basic_device->taints
|
|
|
|
|
list_t *taintsList = NULL;
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->all_nodes
|
|
|
|
|
cJSON *all_nodes = cJSON_GetObjectItemCaseSensitive(v1beta1_basic_deviceJSON, "allNodes");
|
|
|
|
|
if (cJSON_IsNull(all_nodes)) {
|
|
|
|
|
all_nodes = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (all_nodes) {
|
|
|
|
|
if(!cJSON_IsBool(all_nodes))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Bool
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
// v1beta1_basic_device->attributes
|
|
|
|
|
cJSON *attributes = cJSON_GetObjectItemCaseSensitive(v1beta1_basic_deviceJSON, "attributes");
|
|
|
|
|
if (cJSON_IsNull(attributes)) {
|
|
|
|
|
attributes = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (attributes) {
|
|
|
|
|
|
|
|
|
|
// The data type of the elements in v1beta1_basic_device->attributes is currently not supported.
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->capacity
|
|
|
|
|
cJSON *capacity = cJSON_GetObjectItemCaseSensitive(v1beta1_basic_deviceJSON, "capacity");
|
|
|
|
|
if (cJSON_IsNull(capacity)) {
|
|
|
|
|
capacity = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (capacity) {
|
|
|
|
|
|
|
|
|
|
// The data type of the elements in v1beta1_basic_device->capacity is currently not supported.
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 08:13:38 +00:00
|
|
|
// v1beta1_basic_device->consumes_counters
|
|
|
|
|
cJSON *consumes_counters = cJSON_GetObjectItemCaseSensitive(v1beta1_basic_deviceJSON, "consumesCounters");
|
|
|
|
|
if (cJSON_IsNull(consumes_counters)) {
|
|
|
|
|
consumes_counters = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (consumes_counters) {
|
|
|
|
|
cJSON *consumes_counters_local_nonprimitive = NULL;
|
|
|
|
|
if(!cJSON_IsArray(consumes_counters)){
|
|
|
|
|
goto end; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
consumes_countersList = list_createList();
|
|
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(consumes_counters_local_nonprimitive,consumes_counters )
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsObject(consumes_counters_local_nonprimitive)){
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
v1beta1_device_counter_consumption_t *consumes_countersItem = v1beta1_device_counter_consumption_parseFromJSON(consumes_counters_local_nonprimitive);
|
|
|
|
|
|
|
|
|
|
list_addElement(consumes_countersList, consumes_countersItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->node_name
|
|
|
|
|
cJSON *node_name = cJSON_GetObjectItemCaseSensitive(v1beta1_basic_deviceJSON, "nodeName");
|
|
|
|
|
if (cJSON_IsNull(node_name)) {
|
|
|
|
|
node_name = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (node_name) {
|
|
|
|
|
if(!cJSON_IsString(node_name) && !cJSON_IsNull(node_name))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->node_selector
|
|
|
|
|
cJSON *node_selector = cJSON_GetObjectItemCaseSensitive(v1beta1_basic_deviceJSON, "nodeSelector");
|
|
|
|
|
if (cJSON_IsNull(node_selector)) {
|
|
|
|
|
node_selector = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (node_selector) {
|
|
|
|
|
node_selector_local_nonprim = v1_node_selector_parseFromJSON(node_selector); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1beta1_basic_device->taints
|
|
|
|
|
cJSON *taints = cJSON_GetObjectItemCaseSensitive(v1beta1_basic_deviceJSON, "taints");
|
|
|
|
|
if (cJSON_IsNull(taints)) {
|
|
|
|
|
taints = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (taints) {
|
|
|
|
|
cJSON *taints_local_nonprimitive = NULL;
|
|
|
|
|
if(!cJSON_IsArray(taints)){
|
|
|
|
|
goto end; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
taintsList = list_createList();
|
|
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(taints_local_nonprimitive,taints )
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsObject(taints_local_nonprimitive)){
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
v1beta1_device_taint_t *taintsItem = v1beta1_device_taint_parseFromJSON(taints_local_nonprimitive);
|
|
|
|
|
|
|
|
|
|
list_addElement(taintsList, taintsItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
|
|
|
|
|
v1beta1_basic_device_local_var = v1beta1_basic_device_create_internal (
|
2025-06-08 08:13:38 +00:00
|
|
|
all_nodes ? all_nodes->valueint : 0,
|
2025-02-11 19:36:46 +00:00
|
|
|
attributes ? attributesList : NULL,
|
2025-06-08 08:13:38 +00:00
|
|
|
capacity ? capacityList : NULL,
|
|
|
|
|
consumes_counters ? consumes_countersList : NULL,
|
|
|
|
|
node_name && !cJSON_IsNull(node_name) ? strdup(node_name->valuestring) : NULL,
|
|
|
|
|
node_selector ? node_selector_local_nonprim : NULL,
|
|
|
|
|
taints ? taintsList : NULL
|
2025-02-11 19:36:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1beta1_basic_device_local_var;
|
|
|
|
|
end:
|
|
|
|
|
|
|
|
|
|
// The data type of the elements in v1beta1_basic_device->attributes is currently not supported.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The data type of the elements in v1beta1_basic_device->capacity is currently not supported.
|
|
|
|
|
|
2025-06-08 08:13:38 +00:00
|
|
|
if (consumes_countersList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, consumes_countersList) {
|
|
|
|
|
v1beta1_device_counter_consumption_free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(consumes_countersList);
|
|
|
|
|
consumes_countersList = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (node_selector_local_nonprim) {
|
|
|
|
|
v1_node_selector_free(node_selector_local_nonprim);
|
|
|
|
|
node_selector_local_nonprim = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (taintsList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, taintsList) {
|
|
|
|
|
v1beta1_device_taint_free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(taintsList);
|
|
|
|
|
taintsList = NULL;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|