2020-03-18 17:24:33 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include "v1_daemon_set_update_strategy.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_daemon_set_update_strategy_t *v1_daemon_set_update_strategy_create(
|
|
|
|
|
v1_rolling_update_daemon_set_t *rolling_update,
|
|
|
|
|
char *type
|
|
|
|
|
) {
|
|
|
|
|
v1_daemon_set_update_strategy_t *v1_daemon_set_update_strategy_local_var = malloc(sizeof(v1_daemon_set_update_strategy_t));
|
|
|
|
|
if (!v1_daemon_set_update_strategy_local_var) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
v1_daemon_set_update_strategy_local_var->rolling_update = rolling_update;
|
|
|
|
|
v1_daemon_set_update_strategy_local_var->type = type;
|
|
|
|
|
|
|
|
|
|
return v1_daemon_set_update_strategy_local_var;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void v1_daemon_set_update_strategy_free(v1_daemon_set_update_strategy_t *v1_daemon_set_update_strategy) {
|
|
|
|
|
if(NULL == v1_daemon_set_update_strategy){
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
listEntry_t *listEntry;
|
2021-01-05 15:42:34 +08:00
|
|
|
if (v1_daemon_set_update_strategy->rolling_update) {
|
|
|
|
|
v1_rolling_update_daemon_set_free(v1_daemon_set_update_strategy->rolling_update);
|
|
|
|
|
v1_daemon_set_update_strategy->rolling_update = NULL;
|
|
|
|
|
}
|
|
|
|
|
if (v1_daemon_set_update_strategy->type) {
|
|
|
|
|
free(v1_daemon_set_update_strategy->type);
|
|
|
|
|
v1_daemon_set_update_strategy->type = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
free(v1_daemon_set_update_strategy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cJSON *v1_daemon_set_update_strategy_convertToJSON(v1_daemon_set_update_strategy_t *v1_daemon_set_update_strategy) {
|
|
|
|
|
cJSON *item = cJSON_CreateObject();
|
|
|
|
|
|
|
|
|
|
// v1_daemon_set_update_strategy->rolling_update
|
|
|
|
|
if(v1_daemon_set_update_strategy->rolling_update) {
|
|
|
|
|
cJSON *rolling_update_local_JSON = v1_rolling_update_daemon_set_convertToJSON(v1_daemon_set_update_strategy->rolling_update);
|
|
|
|
|
if(rolling_update_local_JSON == NULL) {
|
|
|
|
|
goto fail; //model
|
|
|
|
|
}
|
|
|
|
|
cJSON_AddItemToObject(item, "rollingUpdate", rolling_update_local_JSON);
|
|
|
|
|
if(item->child == NULL) {
|
|
|
|
|
goto fail;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// v1_daemon_set_update_strategy->type
|
|
|
|
|
if(v1_daemon_set_update_strategy->type) {
|
|
|
|
|
if(cJSON_AddStringToObject(item, "type", v1_daemon_set_update_strategy->type) == NULL) {
|
|
|
|
|
goto fail; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return item;
|
|
|
|
|
fail:
|
|
|
|
|
if (item) {
|
|
|
|
|
cJSON_Delete(item);
|
|
|
|
|
}
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
v1_daemon_set_update_strategy_t *v1_daemon_set_update_strategy_parseFromJSON(cJSON *v1_daemon_set_update_strategyJSON){
|
|
|
|
|
|
|
|
|
|
v1_daemon_set_update_strategy_t *v1_daemon_set_update_strategy_local_var = NULL;
|
|
|
|
|
|
|
|
|
|
// v1_daemon_set_update_strategy->rolling_update
|
|
|
|
|
cJSON *rolling_update = cJSON_GetObjectItemCaseSensitive(v1_daemon_set_update_strategyJSON, "rollingUpdate");
|
|
|
|
|
v1_rolling_update_daemon_set_t *rolling_update_local_nonprim = NULL;
|
|
|
|
|
if (rolling_update) {
|
|
|
|
|
rolling_update_local_nonprim = v1_rolling_update_daemon_set_parseFromJSON(rolling_update); //nonprimitive
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v1_daemon_set_update_strategy->type
|
|
|
|
|
cJSON *type = cJSON_GetObjectItemCaseSensitive(v1_daemon_set_update_strategyJSON, "type");
|
|
|
|
|
if (type) {
|
|
|
|
|
if(!cJSON_IsString(type))
|
|
|
|
|
{
|
|
|
|
|
goto end; //String
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
v1_daemon_set_update_strategy_local_var = v1_daemon_set_update_strategy_create (
|
|
|
|
|
rolling_update ? rolling_update_local_nonprim : NULL,
|
|
|
|
|
type ? strdup(type->valuestring) : NULL
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return v1_daemon_set_update_strategy_local_var;
|
|
|
|
|
end:
|
2021-01-11 12:15:24 +08:00
|
|
|
if (rolling_update_local_nonprim) {
|
|
|
|
|
v1_rolling_update_daemon_set_free(rolling_update_local_nonprim);
|
|
|
|
|
rolling_update_local_nonprim = NULL;
|
|
|
|
|
}
|
2020-03-18 17:24:33 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
}
|