2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_replica_set_status.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
static v1_replica_set_status_t *v1_replica_set_status_create_internal(
|
2020-03-18 17:24:33 +08:00
|
|
|
int available_replicas,
|
|
|
|
|
list_t *conditions,
|
|
|
|
|
int fully_labeled_replicas,
|
|
|
|
|
long observed_generation,
|
|
|
|
|
int ready_replicas,
|
2025-06-08 08:13:38 +00:00
|
|
|
int replicas,
|
|
|
|
|
int terminating_replicas
|
2020-03-18 17:24:33 +08:00
|
|
|
) {
|
|
|
|
|
v1_replica_set_status_t *v1_replica_set_status_local_var = malloc(sizeof(v1_replica_set_status_t));
|
|
|
|
|
if (!v1_replica_set_status_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_replica_set_status_local_var->available_replicas = available_replicas;
|
|
|
|
|
v1_replica_set_status_local_var->conditions = conditions;
|
|
|
|
|
v1_replica_set_status_local_var->fully_labeled_replicas = fully_labeled_replicas;
|
|
|
|
|
v1_replica_set_status_local_var->observed_generation = observed_generation;
|
|
|
|
|
v1_replica_set_status_local_var->ready_replicas = ready_replicas;
|
|
|
|
|
v1_replica_set_status_local_var->replicas = replicas;
|
2025-06-08 08:13:38 +00:00
|
|
|
v1_replica_set_status_local_var->terminating_replicas = terminating_replicas;
|
2020-03-18 17:24:33 +08:00
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_replica_set_status_local_var->_library_owned = 1;
|
2020-03-18 17:24:33 +08:00
|
|
|
return v1_replica_set_status_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
__attribute__((deprecated)) v1_replica_set_status_t *v1_replica_set_status_create(
|
|
|
|
|
int available_replicas,
|
|
|
|
|
list_t *conditions,
|
|
|
|
|
int fully_labeled_replicas,
|
|
|
|
|
long observed_generation,
|
|
|
|
|
int ready_replicas,
|
2025-06-08 08:13:38 +00:00
|
|
|
int replicas,
|
|
|
|
|
int terminating_replicas
|
2025-02-11 19:36:46 +00:00
|
|
|
) {
|
|
|
|
|
return v1_replica_set_status_create_internal (
|
|
|
|
|
available_replicas,
|
|
|
|
|
conditions,
|
|
|
|
|
fully_labeled_replicas,
|
|
|
|
|
observed_generation,
|
|
|
|
|
ready_replicas,
|
2025-06-08 08:13:38 +00:00
|
|
|
replicas,
|
|
|
|
|
terminating_replicas
|
2025-02-11 19:36:46 +00:00
|
|
|
);
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
void v1_replica_set_status_free(v1_replica_set_status_t *v1_replica_set_status) {
|
|
|
|
|
if(NULL == v1_replica_set_status){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2025-02-11 19:36:46 +00:00
|
|
|
if(v1_replica_set_status->_library_owned != 1){
|
|
|
|
|
fprintf(stderr, "WARNING: %s() does NOT free objects allocated by the user\n", "v1_replica_set_status_free");
|
|
|
|
|
return ;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_replica_set_status->conditions) {
|
|
|
|
|
list_ForEach(listEntry, v1_replica_set_status->conditions) {
|
|
|
|
|
v1_replica_set_condition_free(listEntry->data);
|
|
|
|
|
}
|
2022-03-09 10:56:53 +08:00
|
|
|
list_freeList(v1_replica_set_status->conditions);
|
2021-01-05 15:42:34 +08:00
|
|
|
v1_replica_set_status->conditions = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
}
|
|
|
|
|
free(v1_replica_set_status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_replica_set_status_convertToJSON(v1_replica_set_status_t *v1_replica_set_status) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->available_replicas
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_replica_set_status->available_replicas) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddNumberToObject(item, "availableReplicas", v1_replica_set_status->available_replicas) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->conditions
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_replica_set_status->conditions) {
|
2020-03-18 17:24:33 +08:00
|
|
|
cJSON *conditions = cJSON_AddArrayToObject(item, "conditions");
|
|
|
|
|
if(conditions == NULL) {
|
|
|
|
|
goto fail; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
listEntry_t *conditionsListEntry;
|
|
|
|
|
if (v1_replica_set_status->conditions) {
|
|
|
|
|
list_ForEach(conditionsListEntry, v1_replica_set_status->conditions) {
|
|
|
|
|
cJSON *itemLocal = v1_replica_set_condition_convertToJSON(conditionsListEntry->data);
|
|
|
|
|
if(itemLocal == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToArray(conditions, itemLocal);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->fully_labeled_replicas
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_replica_set_status->fully_labeled_replicas) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddNumberToObject(item, "fullyLabeledReplicas", v1_replica_set_status->fully_labeled_replicas) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->observed_generation
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_replica_set_status->observed_generation) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddNumberToObject(item, "observedGeneration", v1_replica_set_status->observed_generation) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->ready_replicas
|
2022-04-18 09:29:02 +08:00
|
|
|
if(v1_replica_set_status->ready_replicas) {
|
2020-03-18 17:24:33 +08:00
|
|
|
if(cJSON_AddNumberToObject(item, "readyReplicas", v1_replica_set_status->ready_replicas) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
2022-04-18 09:29:02 +08:00
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->replicas
|
|
|
|
|
if (!v1_replica_set_status->replicas) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
if(cJSON_AddNumberToObject(item, "replicas", v1_replica_set_status->replicas) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 08:13:38 +00:00
|
|
|
|
|
|
|
|
// v1_replica_set_status->terminating_replicas
|
|
|
|
|
if(v1_replica_set_status->terminating_replicas) {
|
|
|
|
|
if(cJSON_AddNumberToObject(item, "terminatingReplicas", v1_replica_set_status->terminating_replicas) == NULL) {
|
|
|
|
|
goto fail; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_replica_set_status_t *v1_replica_set_status_parseFromJSON(cJSON *v1_replica_set_statusJSON){
|
|
|
|
|
|
|
|
|
|
v1_replica_set_status_t *v1_replica_set_status_local_var = NULL;
|
|
|
|
|
|
2022-03-29 10:12:05 +08:00
|
|
|
// define the local list for v1_replica_set_status->conditions
|
|
|
|
|
list_t *conditionsList = NULL;
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
// v1_replica_set_status->available_replicas
|
|
|
|
|
cJSON *available_replicas = cJSON_GetObjectItemCaseSensitive(v1_replica_set_statusJSON, "availableReplicas");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(available_replicas)) {
|
|
|
|
|
available_replicas = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (available_replicas) {
|
|
|
|
|
if(!cJSON_IsNumber(available_replicas))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->conditions
|
|
|
|
|
cJSON *conditions = cJSON_GetObjectItemCaseSensitive(v1_replica_set_statusJSON, "conditions");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(conditions)) {
|
|
|
|
|
conditions = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (conditions) {
|
2022-03-29 10:12:05 +08:00
|
|
|
cJSON *conditions_local_nonprimitive = NULL;
|
2020-03-18 17:24:33 +08:00
|
|
|
if(!cJSON_IsArray(conditions)){
|
|
|
|
|
goto end; //nonprimitive container
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 10:56:53 +08:00
|
|
|
conditionsList = list_createList();
|
2020-03-18 17:24:33 +08:00
|
|
|
|
|
|
|
|
cJSON_ArrayForEach(conditions_local_nonprimitive,conditions )
|
|
|
|
|
{
|
|
|
|
|
if(!cJSON_IsObject(conditions_local_nonprimitive)){
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
v1_replica_set_condition_t *conditionsItem = v1_replica_set_condition_parseFromJSON(conditions_local_nonprimitive);
|
|
|
|
|
|
|
|
|
|
list_addElement(conditionsList, conditionsItem);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->fully_labeled_replicas
|
|
|
|
|
cJSON *fully_labeled_replicas = cJSON_GetObjectItemCaseSensitive(v1_replica_set_statusJSON, "fullyLabeledReplicas");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(fully_labeled_replicas)) {
|
|
|
|
|
fully_labeled_replicas = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (fully_labeled_replicas) {
|
|
|
|
|
if(!cJSON_IsNumber(fully_labeled_replicas))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->observed_generation
|
|
|
|
|
cJSON *observed_generation = cJSON_GetObjectItemCaseSensitive(v1_replica_set_statusJSON, "observedGeneration");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(observed_generation)) {
|
|
|
|
|
observed_generation = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (observed_generation) {
|
|
|
|
|
if(!cJSON_IsNumber(observed_generation))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->ready_replicas
|
|
|
|
|
cJSON *ready_replicas = cJSON_GetObjectItemCaseSensitive(v1_replica_set_statusJSON, "readyReplicas");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(ready_replicas)) {
|
|
|
|
|
ready_replicas = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (ready_replicas) {
|
|
|
|
|
if(!cJSON_IsNumber(ready_replicas))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_replica_set_status->replicas
|
|
|
|
|
cJSON *replicas = cJSON_GetObjectItemCaseSensitive(v1_replica_set_statusJSON, "replicas");
|
2025-02-11 19:36:46 +00:00
|
|
|
if (cJSON_IsNull(replicas)) {
|
|
|
|
|
replicas = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
if (!replicas) {
|
|
|
|
|
goto end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!cJSON_IsNumber(replicas))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 08:13:38 +00:00
|
|
|
// v1_replica_set_status->terminating_replicas
|
|
|
|
|
cJSON *terminating_replicas = cJSON_GetObjectItemCaseSensitive(v1_replica_set_statusJSON, "terminatingReplicas");
|
|
|
|
|
if (cJSON_IsNull(terminating_replicas)) {
|
|
|
|
|
terminating_replicas = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (terminating_replicas) {
|
|
|
|
|
if(!cJSON_IsNumber(terminating_replicas))
|
|
|
|
|
{
|
|
|
|
|
goto end; //Numeric
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-18 17:24:33 +08:00
|
|
|
|
2025-02-11 19:36:46 +00:00
|
|
|
v1_replica_set_status_local_var = v1_replica_set_status_create_internal (
|
2020-03-18 17:24:33 +08:00
|
|
|
available_replicas ? available_replicas->valuedouble : 0,
|
|
|
|
|
conditions ? conditionsList : NULL,
|
|
|
|
|
fully_labeled_replicas ? fully_labeled_replicas->valuedouble : 0,
|
|
|
|
|
observed_generation ? observed_generation->valuedouble : 0,
|
|
|
|
|
ready_replicas ? ready_replicas->valuedouble : 0,
|
2025-06-08 08:13:38 +00:00
|
|
|
replicas->valuedouble,
|
|
|
|
|
terminating_replicas ? terminating_replicas->valuedouble : 0
|
2020-03-18 17:24:33 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_replica_set_status_local_var;
|
|
|
|
|
end:
|
2022-03-29 10:12:05 +08:00
|
|
|
if (conditionsList) {
|
|
|
|
|
listEntry_t *listEntry = NULL;
|
|
|
|
|
list_ForEach(listEntry, conditionsList) {
|
|
|
|
|
v1_replica_set_condition_free(listEntry->data);
|
|
|
|
|
listEntry->data = NULL;
|
|
|
|
|
}
|
|
|
|
|
list_freeList(conditionsList);
|
|
|
|
|
conditionsList = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|