|
| 1 | +#include "node_info.h" |
| 2 | + |
| 3 | +#include "proto/nodeinstance/info/v1/info.pb.h" |
| 4 | + |
| 5 | +#include "schema_wrapper_utils.h" |
| 6 | + |
| 7 | +static int generate_node_info(nodeinstance::info::v1::NodeInfo *info, struct aclk_node_info *data) |
| 8 | +{ |
| 9 | + struct label *label; |
| 10 | + google::protobuf::Map<std::string, std::string> *map; |
| 11 | + |
| 12 | + try |
| 13 | + { |
| 14 | + info->set_name(data->name); |
| 15 | + |
| 16 | + info->set_os(data->os); |
| 17 | + info->set_os_name(data->os_name); |
| 18 | + info->set_os_version(data->os_version); |
| 19 | + |
| 20 | + info->set_kernel_name(data->kernel_name); |
| 21 | + info->set_kernel_version(data->kernel_version); |
| 22 | + |
| 23 | + info->set_architecture(data->architecture); |
| 24 | + |
| 25 | + info->set_cpus(data->cpus); |
| 26 | + |
| 27 | + info->set_cpu_frequency(data->cpu_frequency); |
| 28 | + |
| 29 | + info->set_memory(data->memory); |
| 30 | + |
| 31 | + info->set_disk_space(data->disk_space); |
| 32 | + |
| 33 | + info->set_version(data->version); |
| 34 | + |
| 35 | + info->set_release_channel(data->release_channel); |
| 36 | + |
| 37 | + info->set_timezone(data->timezone); |
| 38 | + |
| 39 | + info->set_virtualization_type(data->virtualization_type); |
| 40 | + |
| 41 | + info->set_container_type(data->container_type); |
| 42 | + |
| 43 | + info->set_custom_info(data->custom_info); |
| 44 | + |
| 45 | + for (size_t i = 0; i < data->service_count; i++) |
| 46 | + info->add_services(data->services[i]); |
| 47 | + |
| 48 | + info->set_machine_guid(data->machine_guid); |
| 49 | + |
| 50 | + map = info->mutable_host_labels(); |
| 51 | + label = data->host_labels_head; |
| 52 | + while (label) { |
| 53 | + map->insert({label->key, label->value}); |
| 54 | + label = label->next; |
| 55 | + } |
| 56 | + } |
| 57 | + catch(...) { |
| 58 | + return 1; |
| 59 | + } |
| 60 | + return 0; |
| 61 | +} |
| 62 | + |
| 63 | +char *generate_update_node_info_message(size_t *len, struct update_node_info *info) |
| 64 | +{ |
| 65 | + nodeinstance::info::v1::UpdateNodeInfo msg; |
| 66 | + |
| 67 | + msg.set_node_id(info->node_id); |
| 68 | + msg.set_claim_id(info->claim_id); |
| 69 | + |
| 70 | + if (generate_node_info(msg.mutable_data(), &info->data)) |
| 71 | + return NULL; |
| 72 | + |
| 73 | + set_google_timestamp_from_timeval(info->updated_at, msg.mutable_updated_at()); |
| 74 | + msg.set_machine_guid(info->machine_guid); |
| 75 | + msg.set_child(info->child); |
| 76 | + |
| 77 | + *len = PROTO_COMPAT_MSG_SIZE(msg); |
| 78 | + char *bin = (char*)malloc(*len); |
| 79 | + if (bin) |
| 80 | + msg.SerializeToArray(bin, *len); |
| 81 | + |
| 82 | + return bin; |
| 83 | +} |
0 commit comments