| 3195 | } |
| 3196 | |
| 3197 | static sds clusterManagerNodeGetJSON(clusterManagerNode *node, |
| 3198 | unsigned long error_count) |
| 3199 | { |
| 3200 | sds json = sdsempty(); |
| 3201 | sds replicate = sdsempty(); |
| 3202 | if (node->replicate) |
| 3203 | replicate = sdscatprintf(replicate, "\"%s\"", node->replicate); |
| 3204 | else |
| 3205 | replicate = sdscat(replicate, "null"); |
| 3206 | sds slots = clusterManagerNodeSlotsString(node); |
| 3207 | sds flags = clusterManagerNodeFlagString(node); |
| 3208 | char *p = slots; |
| 3209 | while ((p = strchr(p, '-')) != NULL) |
| 3210 | *(p++) = ','; |
| 3211 | json = sdscatprintf(json, |
| 3212 | " {\n" |
| 3213 | " \"name\": \"%s\",\n" |
| 3214 | " \"host\": \"%s\",\n" |
| 3215 | " \"port\": %d,\n" |
| 3216 | " \"replicate\": %s,\n" |
| 3217 | " \"slots\": [%s],\n" |
| 3218 | " \"slots_count\": %d,\n" |
| 3219 | " \"flags\": \"%s\",\n" |
| 3220 | " \"current_epoch\": %llu", |
| 3221 | node->name, |
| 3222 | node->ip, |
| 3223 | node->port, |
| 3224 | replicate, |
| 3225 | slots, |
| 3226 | node->slots_count, |
| 3227 | flags, |
| 3228 | (unsigned long long)node->current_epoch |
| 3229 | ); |
| 3230 | if (error_count > 0) { |
| 3231 | json = sdscatprintf(json, ",\n \"cluster_errors\": %lu", |
| 3232 | error_count); |
| 3233 | } |
| 3234 | if (node->migrating_count > 0 && node->migrating != NULL) { |
| 3235 | int i = 0; |
| 3236 | sds migrating = sdsempty(); |
| 3237 | for (; i < node->migrating_count; i += 2) { |
| 3238 | sds slot = node->migrating[i]; |
| 3239 | sds dest = node->migrating[i + 1]; |
| 3240 | if (slot && dest) { |
| 3241 | if (sdslen(migrating) > 0) migrating = sdscat(migrating, ","); |
| 3242 | migrating = sdscatfmt(migrating, "\"%S\": \"%S\"", slot, dest); |
| 3243 | } |
| 3244 | } |
| 3245 | if (sdslen(migrating) > 0) |
| 3246 | json = sdscatfmt(json, ",\n \"migrating\": {%S}", migrating); |
| 3247 | sdsfree(migrating); |
| 3248 | } |
| 3249 | if (node->importing_count > 0 && node->importing != NULL) { |
| 3250 | int i = 0; |
| 3251 | sds importing = sdsempty(); |
| 3252 | for (; i < node->importing_count; i += 2) { |
| 3253 | sds slot = node->importing[i]; |
| 3254 | sds from = node->importing[i + 1]; |
no test coverage detected