GroupNode findOrCreateSystemNode(MonitorEngine engine) {
   ManagedNode infNode = nodeService.findByPath(ManagedNode.INFRASTRUCTURE_PATH);
   // 兼容手工创建时,引擎资源节点存在对应管理节点的情况
   // 创建 引擎系统 群组,其中存放监控服务器,监控引擎,相关redis/mysql/nginx等自带应用
   GroupNode engineSystemGroupNode;
   try {
     engineSystemGroupNode = (GroupNode) nodeService.findByPath(engine.getSystemPath());
   } catch (IllegalArgumentException e) {
     // Not found exception
     engineSystemGroupNode = new GroupNode();
     engineSystemGroupNode.cascadeCreating();
     engineSystemGroupNode.setPath(engine.getSystemPath());
     if (engine.isDefault()) {
       engineSystemGroupNode.setLabel("缺省监控系统");
     } else {
       engineSystemGroupNode.setLabel(engine.getLabel() + "系统");
     }
     engineSystemGroupNode.setIcon("monitor_system");
     engineSystemGroupNode.setComment("Auto created system group node for " + engine.getLabel());
     try {
       nodeService.create(infNode, engineSystemGroupNode);
     } catch (NodeException ex) {
       throw new ApplicationContextException("Can't auto create engine group node", ex);
     }
   }
   return engineSystemGroupNode;
 }
Пример #2
0
 @Override
 public MonitorEngine register(MonitorEngine engine) throws ResourceException {
   // 先执行自动批准动作
   performApproval(engine);
   // 如果是从监控服务器下载下来的引擎,关联了相应的engine id,则直接更新
   if (StringUtils.isNotBlank(engine.getEngineId())) {
     MonitorEngine legacy = findByEngineId(engine.getEngineId());
     // id/name/label 保留数据库中的值
     engine.setId(legacy.getId());
     engine.setName(legacy.getName());
     engine.setLabel(legacy.getLabel());
     // properties 合并
     if (legacy.getProperties() != null) {
       if (engine.getProperties() == null) {
         engine.setProperties(legacy.getProperties());
       } else {
         engine.getProperties().putAll(legacy.getProperties());
       }
     }
     return update(legacy, engine);
   } else if (isDefault(engine)) { // 还有一种常见情况,就是缺省引擎(与监控服务器安装在同一个地址),而后没有配置engineId
     MonitorEngine defaultEngine = getRepository().findDefaultEngine();
     engine.setEngineId(defaultEngine.getEngineId());
     return update(defaultEngine, engine);
   } else {
     // 否则创建一个新的实例
     return create(engine);
   }
 }
 void createEngineNode(MonitorEngine engine, GroupNode engineSystemGroupNode) {
   // 在引擎系统中,添加引擎自身这个节点
   String enginePath = engine.getSystemPath() + "/engine";
   ResourceNode engineNode;
   try {
     nodeService.findByPath(enginePath);
   } catch (Exception e) {
     engineNode = new ResourceNode();
     // 说明该节点是在创建引擎后被级联自动创建的
     engineNode.cascadeCreating();
     engineNode.setResource(engine);
     engineNode.setPath(enginePath);
     engineNode.setLabel(engine.getLabel());
     engineNode.setIcon("monitor_engine");
     engineNode.setState(State.Running);
     engineNode.setComment("Auto created engine node for " + engine.getLabel());
     try {
       nodeService.create(engineSystemGroupNode, engineNode);
     } catch (NodeException ex) {
       throw new ApplicationContextException("Can't auto create engine node", ex);
     }
   }
 }