public void createDefaultDashboardTemplate()

in ozhera-monitor/ozhera-monitor-service/src/main/java/org/apache/ozhera/monitor/service/impl/HeraDashboardServiceImpl.java [209:285]


    public void createDefaultDashboardTemplate() {
        //Only the first initialization is created using freeMarker. First check if the templates already exist in the database.
        // If so, do not create them again
        DashboardConstant.GRAFANA_SRE_TEMPLATES.forEach(name -> {
            GrafanaTemplate grafanaTemplate = grafanaTemplateDao.fetchOneByName(name);
            if (grafanaTemplate == null) {
                //If it has not been created, it is created from the ftl file
                try {
                    insertDashboardTemplate(name);
                } catch (IOException e) {
                    log.error("HeraDashboardService.createDefaultDashboardTemplate error :{}", e.getMessage());
                }
            } else {
                // If it already exists, delete it from db first, then fetch the latest one from the template and create a new one
                int resCount = grafanaTemplateDao.deleteHard(grafanaTemplate.getId());
                if (resCount >= 1) {
                    try {
                        insertDashboardTemplate(name);
                    } catch (IOException e) {
                        log.error("HeraDashboardService.createDefaultDashboardTemplate Multiple create error :{}",
                                e.getMessage());
                    }
                }
            }
        });
        
        //create java biz template
        GrafanaTemplate grafanaTemplate = grafanaTemplateDao.fetchOneByName("hera-java模板");
        if (grafanaTemplate == null) {
            try {
                String content = FreeMarkerUtil.getTemplateStr(HERA_GRAFANA_TEMPLATE,
                        DashboardConstant.JAEGER_QUERY_File_NAME);
                GrafanaTemplate template = new GrafanaTemplate();
                template.setName("hera-java模板");
                template.setCreateTime(new Date());
                template.setUpdateTime(new Date());
                template.setLanguage(0);
                template.setPlatform(0);
                template.setAppType(0);
                template.setTemplate(content);
                template.setDeleted(false);
                template.setPanelIdList(DashboardConstant.DEFAULT_PANEL_ID_LIST);
                int insertRes = grafanaTemplateDao.insert(template);
                log.info("HeraDashboardService.createDefaultDashboardTemplate name:{},insertRes:{}", "hera-java模板",
                        insertRes);
            } catch (IOException e) {
                log.error("HeraDashboardService.createDefaultDashboardTemplate java template error :{}",
                        e.getMessage());
            }
        }
        
        //create golang biz template
        GrafanaTemplate grafanaGoTemplate = grafanaTemplateDao.fetchOneByName("hera-golang模板");
        if (grafanaGoTemplate == null) {
            try {
                String content = FreeMarkerUtil.getTemplateStr(HERA_GRAFANA_TEMPLATE,
                        DashboardConstant.GOLANG_File_NAME);
                GrafanaTemplate template = new GrafanaTemplate();
                template.setName("hera-golang模板");
                template.setCreateTime(new Date());
                template.setUpdateTime(new Date());
                template.setLanguage(1);
                template.setPlatform(0);
                template.setAppType(0);
                template.setTemplate(content);
                template.setDeleted(false);
                template.setPanelIdList(DashboardConstant.DEFAULT_GOLANG_ID_LIST);
                int insertRes = grafanaTemplateDao.insert(template);
                log.info("HeraDashboardService.createDefaultDashboardTemplate name:{},insertRes:{}", "hera-golang模板",
                        insertRes);
            } catch (IOException e) {
                log.error("HeraDashboardService.createDefaultDashboardTemplate golang template error :{}",
                        e.getMessage());
            }
        }
        
    }