| 1 | #include "node_info.h" |
| 2 | |
| 3 | #include "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 | google::protobuf::Map<std::string, std::string> *map; |
| 10 | |
| 11 | if (data->name) |
| 12 | info->set_name(data->name); |
| 13 | |
| 14 | if (data->os) |
| 15 | info->set_os(data->os); |
| 16 | if (data->os_name) |
| 17 | info->set_os_name(data->os_name); |
| 18 | if (data->os_version) |
| 19 | info->set_os_version(data->os_version); |
| 20 | |
| 21 | if (data->kernel_name) |
| 22 | info->set_kernel_name(data->kernel_name); |
| 23 | if (data->kernel_version) |
| 24 | info->set_kernel_version(data->kernel_version); |
| 25 | |
| 26 | if (data->architecture) |
| 27 | info->set_architecture(data->architecture); |
| 28 | |
| 29 | info->set_cpus(data->cpus); |
| 30 | |
| 31 | if (data->cpu_frequency) |
| 32 | info->set_cpu_frequency(data->cpu_frequency); |
| 33 | |
| 34 | if (data->memory) |
| 35 | info->set_memory(data->memory); |
| 36 | |
| 37 | if (data->disk_space) |
| 38 | info->set_disk_space(data->disk_space); |
| 39 | |
| 40 | if (data->version) |
| 41 | info->set_version(data->version); |
| 42 | |
| 43 | if (data->release_channel) |
| 44 | info->set_release_channel(data->release_channel); |
| 45 | |
| 46 | if (data->timezone) |
| 47 | info->set_timezone(data->timezone); |
| 48 | |
| 49 | if (data->virtualization_type) |
| 50 | info->set_virtualization_type(data->virtualization_type); |
| 51 | |
| 52 | if (data->container_type) |
| 53 | info->set_container_type(data->container_type); |
| 54 | |
| 55 | if (data->custom_info) |
| 56 | info->set_custom_info(data->custom_info); |
| 57 | |
| 58 | if (data->machine_guid) |
| 59 | info->set_machine_guid(data->machine_guid); |
| 60 | |
| 61 | nodeinstance::info::v1::MachineLearningInfo *ml_info = info->mutable_ml_info(); |
| 62 | ml_info->set_ml_capable(data->ml_info.ml_capable); |
| 63 | ml_info->set_ml_enabled(data->ml_info.ml_enabled); |
| 64 | |
| 65 | map = info->mutable_host_labels(); |
| 66 | rrdlabels_walkthrough_read(data->host_labels_ptr, label_add_to_map_callback, map); |
| 67 | return 0; |
| 68 | } |
| 69 | |
| 70 | char *generate_update_node_info_message(size_t *len, struct update_node_info *info) |
| 71 | { |
| 72 | nodeinstance::info::v1::UpdateNodeInfo msg; |
| 73 | |
| 74 | msg.set_node_id(info->node_id); |
| 75 | msg.set_claim_id(info->claim_id); |
| 76 | |
| 77 | if (generate_node_info(msg.mutable_data(), &info->data)) |
| 78 | return NULL; |
| 79 | |
| 80 | set_google_timestamp_from_timeval(info->updated_at, msg.mutable_updated_at()); |
| 81 | msg.set_machine_guid(info->machine_guid); |
| 82 | msg.set_child(info->child); |
| 83 | |
| 84 | nodeinstance::info::v1::MachineLearningInfo *ml_info = msg.mutable_ml_info(); |
| 85 | ml_info->set_ml_capable(info->ml_info.ml_capable); |
| 86 | ml_info->set_ml_enabled(info->ml_info.ml_enabled); |
| 87 | |
| 88 | struct capability *capa; |
| 89 | if (info->node_capabilities) { |
| 90 | capa = info->node_capabilities; |
| 91 | while (capa->name) { |
| 92 | aclk_lib::v1::Capability *proto_capa = msg.mutable_node_info()->add_capabilities(); |
| 93 | capability_set(proto_capa, capa); |
| 94 | capa++; |
| 95 | } |
| 96 | } |
| 97 | if (info->node_instance_capabilities) { |
| 98 | capa = info->node_instance_capabilities; |
| 99 | while (capa->name) { |
| 100 | aclk_lib::v1::Capability *proto_capa = msg.mutable_node_instance_info()->add_capabilities(); |
| 101 | capability_set(proto_capa, capa); |
| 102 | capa++; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | *len = PROTO_COMPAT_MSG_SIZE(msg); |
| 107 | char *bin = (char*)mallocz(*len); |
| 108 | if (bin) |
| 109 | msg.SerializeToArray(bin, *len); |
| 110 | |
| 111 | return bin; |
| 112 | } |
| 113 | |
| 114 | char *generate_update_node_collectors_message(size_t *len, struct update_node_collectors *upd_node_collectors) |
| 115 | { |
| 116 | nodeinstance::info::v1::UpdateNodeCollectors msg; |
| 117 | |
| 118 | msg.set_node_id(upd_node_collectors->node_id); |
| 119 | msg.set_claim_id(upd_node_collectors->claim_id); |
| 120 | |
| 121 | void *colls; |
| 122 | dfe_start_read(upd_node_collectors->node_collectors, colls) { |
| 123 | struct collector_info *c =(struct collector_info *)colls; |
| 124 | nodeinstance::info::v1::CollectorInfo *col = msg.add_collectors(); |
| 125 | col->set_plugin(c->plugin); |
| 126 | col->set_module(c->module); |
| 127 | } |
| 128 | dfe_done(colls); |
| 129 | |
| 130 | *len = PROTO_COMPAT_MSG_SIZE(msg); |
| 131 | char *bin = (char*)mallocz(*len); |
| 132 | if (bin) |
| 133 | msg.SerializeToArray(bin, *len); |
| 134 | |
| 135 | return bin; |
| 136 | } |