nacos -cmdb 服务

LD is tigger forever,CG are not brothers forever, throw the pot and shine forever.
Modesty is not false, solid is not naive, treacherous but not deceitful, stay with good people, and stay away from poor people.
talk is cheap, show others the code,Keep progress,make a better result.
Survive during the day and develop at night。

目录

在这里插入图片描述

概 述

nacos -cmdb 服务

操作控制器:

@RestController
@RequestMapping(UtilsAndCommons.NACOS_CMDB_CONTEXT + "/ops")
public class OperationController {
    
    @Autowired
    private CmdbProvider cmdbProvider;
    
    /**
     * query label.
     *
     * @param request http request
     * @return query result
     * @throws Exception exception
     */
    @RequestMapping(value = "/label", method = RequestMethod.GET)
    public String queryLabel(HttpServletRequest request) throws Exception {
        String entry = WebUtils.required(request, "entry");
        String label = WebUtils.required(request, "label");
        return cmdbProvider.queryLabel(entry, "ip", label);
    }
}
这个注入一个CmdbProvider Service:

那么CmdbProvider 是如何的?
CmdbProvider 提供了cmdb标签任务,dump 任务cmdb事件任务:
包含了加载初始化,查询实体,查询标签,根据标签查询实体,移除实体,更新实体等。

其中最重要的是:注入了:

 
    @Value("${nacos.cmdb.dumpTaskInterval:3600}")
    private int dumpTaskInterval;
    
    @Value("${nacos.cmdb.eventTaskInterval:10}")
    private int eventTaskInterval;
    
    @Value("${nacos.cmdb.labelTaskInterval:300}")
    private int labelTaskInterval;
    
    @Value("${nacos.cmdb.loadDataAtStart:false}")
    private boolean loadDataAtStart;

都是一些属性数值。
取出对应的配置文件的数值:

server.port=8848
server.servlet.context-path=/nacos
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.loadDataAtStart=true

目前提供了Reader 和Writer方法:

 */
public interface CmdbReader {
    
    /**
     * Get entity.
     *
     * @param entityName name of entity
     * @param entityType type of entity
     * @return entity
     */
    Entity queryEntity(String entityName, String entityType);
    
    /**
     * Get label of entity.
     *
     * @param entityName name of entity
     * @param entityType type of entity
     * @param labelName  label name
     * @return label value
     */
    String queryLabel(String entityName, String entityType, String labelName);
    
    /**
     * Get entities of selected label.
     *
     * @param labelName  name of label
     * @param labelValue value of label
     * @return list of entity
     */
    List<Entity> queryEntitiesByLabel(String labelName, String labelValue);
}

最后交由CmdbExecutor 来执行。
执行者执行:
private static final ScheduledExecutorService GLOBAL_EXECUTOR = ExecutorFactory.Managed
.newScheduledExecutorService(ClassUtils.getCanonicalName(CmdbApp.class), EnvUtil.getAvailableProcessors(),
new NameThreadFactory(“com.alibaba.nacos.cmdb.global.executor”));

public static void scheduleCmdbTask(Runnable runnable, long delay, TimeUnit unit) {
    GLOBAL_EXECUTOR.schedule(runnable, delay, unit);
}

主要流程步骤如下:
1.initCmdsService:
2.加载数据,首先判断switches 是否启动,初始化label 标签,使用cmdbService获取Label
3.初始化实体集合,和实体映射数据。
4.调用Spring post方法,开始线程初始化,首先判断cmdb服务是否为空,
不为空,获取实体事件队列。

依次判断事件类型:如果是实体移除的方法:
如果是实体移除的方法调用移除实体的方法,如果是实体的更新方法:
调用实体的更新的方法:

总结:

相关工具如下:

分析:

小结:

主要讲述了nacos -cmdb 服务相关的分析,请大家指正~

参考资料和推荐阅读

1.链接: link

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

执于代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值