public void checkInstanceProcessState()

in manager/dm-agent/src/main/java/org/apache/doris/manager/agent/service/heartbeat/DorisInstanceOperator.java [202:304]


    public void checkInstanceProcessState(String moduleName, String installDir, int httpPort)
            throws InstanceNotInstallException, InstanceNotRunningException, InstanceServiceException {

        if (moduleName.equals(ServerAndAgentConstant.BROKER_NAME)) {
            moduleName = getBrokerInstallationPath(installDir);
        }

        // install dir check
        log.info("to check module {} instance process state in {}", moduleName, installDir);
        File moduleRoot = Paths.get(installDir, moduleName).toFile();
        if (!moduleRoot.exists()) {
            log.error("instance {} not installed, can not find root path: {}", moduleName, moduleRoot);
            throw new InstanceNotInstallException(moduleName, installDir);
        }

        // process state check
        // dont consider multiple be is deployed at one a machine node
        try {
            int insPid = processIsRunning(moduleName, installDir);
            if (insPid < 0) {
                log.error("instance {} is not running", moduleName);
                throw new InstanceNotRunningException(moduleName, moduleRoot.getAbsolutePath());
            }
        } catch (Exception e) {
            log.error("check instance {} process state error: {}", moduleName, e.getMessage());
            throw new InstanceNotRunningException(moduleName, moduleRoot.getAbsolutePath());
        }

        if (httpPort <= 0) {
            log.warn("invalid http port {}, skip http service check", httpPort);
            return;
        }

        // fe/be http service check
        String statusURL;
        if (moduleName.equals(ServerAndAgentConstant.FE_NAME)) {
            statusURL = "http://localhost:" + httpPort + "/api/bootstrap";
        } else if (moduleName.equals(ServerAndAgentConstant.BE_NAME)) {
            statusURL = "http://localhost:" + httpPort + "/api/health";
        } else {
            // can not check other module by http
            log.error("unknown module name {}", moduleName);
            return;
        }

        /*
         * Before Palo 3.10, the FE api/bootstrap API return like this:
         * {
         *    "replayedJournalId": 0,
         *    "queryPort": 0,
         *    "rpcPort": 0,
         *    "status": "OK",
         *    "msg": "Success"
         * }
         *
         * From 3.10, the FE api/bootstrap API return like this:
         * {
         *  "msg": "success",
         *  "code": 0,
         *  "data": {"replayedJournalId": 0, "queryPort": 0, "rpcPort": 0},
         *  "count": 0
         * }
         *
         * FE api/health return like this
         * {
         * "msg": "success",
         * "code": 0,
         * "data": {"online_backend_num": 2, "total_backend_num": 2},
         * "count": 0
         * }
         *
         * BE api/health return lik this
         * {"status": "OK","msg": "To Be Added"}
         *
         */

        String stateRes;
        try {
            stateRes = Request.sendGetRequest(statusURL, new HashMap<>());
        } catch (URISyntaxException e) {
            log.error("{} syntax error {}", statusURL, e.getMessage());
            return;
        } catch (IOException e) {
            throw new InstanceServiceException(moduleName);
        }
        log.info("http health return: {}", stateRes);
        // or status == ok
        JSONObject stateJson =  JSONObject.parseObject(stateRes);
        String status = stateJson.getString("status");
        if (status != null && status.equals("OK")) {
            log.info("module {} instance service is normal, return status OK", moduleName);
            return;
        }

        // or code == 0
        Integer code = stateJson.getInteger("code");
        if (code != null && code == 0) {
            log.info("modele {} instance service is normal return code 0", moduleName);
            return;
        }

        throw new InstanceServiceException(moduleName);
    }