#ip #task #rlink #cmdb #appuk #ip-mapping

cmdb-ip-mapping

Get appuk by ip from cmdb in rlink task

10 releases (4 breaking)

0.6.4 Aug 24, 2021
0.6.3 Aug 19, 2021
0.5.0 Jun 17, 2021
0.3.0 May 7, 2021
0.1.1 Apr 14, 2021

#163 in #ip

MIT/Apache

13KB
229 lines

cmdb-ip-mapping

Crates.io Released API docs MIT licensed License

Depend on rlink. Get appuk by ip from cmdb in rlink task.

Example

[dependencies]
cmdb-ip-mapping = "0.1"
        let ip = "10.99.5.49";
        let ip_mapping_url = "http://ipappukmapping.17usoft.com/mapping/all";

        load_ip_mapping_task(ip_mapping_url);

        let option = get_ip_mapping_config(ip);
        assert!(option.is_some());
        assert!(option.unwrap().app_uk.eq("dssteamyyjk.java.ip.appuk.mapping"))

lib.rs:

cmdb-ip-mapping

A library to get appuk by ip from cmdb in rlink task.

Example

Get appUk by ip

use cmdb_ip_mapping::ip_mapping_config::{load_ip_mapping_task, get_ip_mapping_config};

let ip = "test_ip";
let ip_mapping_url = "test_mapping_url";

load_ip_mapping_task(ip_mapping_url);

let vec = get_ip_mapping_config(ip);
let item = vec.unwrap().get(0).unwrap().clone();
assert!(item.group_environment.as_ref().unwrap().eq("qa"))

Consume ip-mapping incremental change

use std::collections::HashMap;
use cmdb_ip_mapping::ip_mapping_connect::IpMappingCoProcessFunction;
use rlink_connector_kafka::{BOOTSTRAP_SERVERS, GROUP_ID, create_input_format, InputFormatBuilder};
use rlink::functions::flat_map::BroadcastFlagMapFunction;
use rlink::core::element::types;

pub const FIELD_TYPE: [u8; 2] = [
    // 0: timestamp
    types::U64,
    // 1: app_id
    types::STRING,
];
pub const FIELD_NAME: [&'static str; 2] = [
    // 0: timestamp
    "timestamp",
    // 1: app_id
    "app_id",
];
pub const FIELD_METADATA: FieldMetadata<53> = FieldMetadata::new(&FIELD_TYPE, &FIELD_NAME);

let ip_mapping_input_format = {
    let mut conf_map = HashMap::new();
    conf_map.insert(BOOTSTRAP_SERVERS.to_string(), ip_mapping_kafka_servers);
    conf_map.insert(GROUP_ID.to_string(), ip_mapping_group_id);
    InputFormatBuilder::new(conf_map, vec![ip_mapping_kafka_topic], None).build()
};

let ip_mapping_stream = env
    .register_source(ip_mapping_input_format, 1)
    .flat_map(BroadcastFlagMapFunction::new());

data_stream
    .connect(
         vec![CoStream::from(ip_mapping_stream)],
         IpMappingCoProcessFunction::new(FnSchema::from(&FIELD_METADATA)),
    )

Dependencies

~40–56MB
~1M SLoC