// 処理のメインルーチン func realMain(args *arguments) int { if args.v { // バージョン情報表示 showVersion() return rc_OK } if args.help { // Usage表示 showUsage() return rc_OK } // 設定ファイル名の取得 if len(args.config) == 0 { args.config = defaultConfig } if err := config.Load(args.config); err != nil { // 設定ファイル読み込み。 console.DisplayError("CTU006E", args.config) return rc_PARMERR } if len(args.from) == 0 && len(args.to) == 0 { // From-to指定無しの場合は、現在のCPU日付のみを対象とする now := utctime.Now() if args.isUTC { args.from = now.Format(utctime.Date8Num) args.to = args.from } else { args.from = now.FormatLocaltime(utctime.Date8Num) args.to = args.from } } from, to, err := parseFromTo(args.from, args.to, args.isUTC) if err != nil { console.DisplayError("CTU003E", err) showUsage() return rc_PARMERR } status, err := getStatusType(args.status) // status取得 if err != nil { console.DisplayError("CTU003E", fmt.Sprintf("Invalid status option. [%v]", args.status)) showUsage() return rc_PARMERR } gen := getSeparatorType(args.format) // 出力形態 if gen == nil { console.DisplayError("CTU003E", fmt.Sprintf("Invalid [format] format.[%v]", args.format)) showUsage() return rc_PARMERR } param := NewShowParam(args.nid, args.jobnet, from, to, status, gen) rc, err := param.Run(config.DB.DBFile, args.isUTC) if err != nil { console.DisplayError("CTU004E", err) return rc_ERROR } else if rc == 0 { // 出力件数が0 return rc_NOTHING } return rc_OK }
func realMain() int { args := fetchArgs() if args == nil { showUsage() return 1 } configPath := filepath.Join(util.GetRootPath(), "bin", "master.ini") if err := config.Load(configPath); err != nil { msg := fmt.Sprintf("master.ini not found or cannot read it.") fmt.Println(network.RealtimeErrorResult(msg)) return 1 } networkDir := config.Dir.JobnetDir if err := network.LoadJobex(args.realtimeName, networkDir); err != nil { msg := fmt.Sprintf("Jobex csv load error: %s", err) fmt.Println(network.RealtimeErrorResult(msg)) return 1 } res, err := http.Get(args.jsonURL) if err != nil { msg := fmt.Sprintf("HTTP request error: %s", err) fmt.Println(network.RealtimeErrorResult(msg)) return 1 } defer res.Body.Close() if res.StatusCode != http.StatusOK { msg := fmt.Sprintf("HTTP response error. Status code[%d]", res.StatusCode) fmt.Println(network.RealtimeErrorResult(msg)) return 1 } nwk, err := network.Parse(res.Body) if err != nil { msg := fmt.Sprintf("Parse error: %s", err) fmt.Println(network.RealtimeErrorResult(msg)) return 1 } cmd := network.NewCommand(args.realtimeName) if err := nwk.Export(cmd.GetNetworkName(), networkDir); err != nil { msg := fmt.Sprintf("Network temporary file create error: %s", err) fmt.Println(network.RealtimeErrorResult(msg)) return 1 } defer nwk.Clean(cmd.GetNetworkName(), networkDir) id, err := cmd.Run() if err != nil { fmt.Println(network.MasterErrorResult(err.Error(), cmd.GetPID())) return 1 } result := network.SuccessResult(cmd.GetPID(), id, cmd.GetNetworkName()) fmt.Println(result) cmd.Release() return 0 }
func realMain(args *arguments) int { if args.versionFlag == flag_ON { showVersion() return rc_OK } if args.networkName == "" && args.rerunInstance == 0 { showUsage() return rc_ERROR } if args.networkName != "" && args.rerunInstance != 0 { console.Display("CTM019E", "Cannot use both -n and -r option.") return rc_ERROR } if args.configPath == "" { args.configPath = defaultConfig } message.MasterVersion = Version if err := config.Load(args.configPath); err != nil { console.Display("CTM004E", args.configPath) return rc_ERROR } if err := config.DetectError(); err != nil { console.Display("CTM005E", err) return rc_ERROR } if err := log.Init(config.Dir.LogDir, "master", "", config.Log.OutputLevel, config.Log.MaxSizeKB, config.Log.MaxGeneration, config.Log.TimeoutSec); err != nil { console.Display("CTM021E", err) return rc_ERROR } defer log.Term() console.Display("CTM001I", os.Getpid(), Version) // master終了時のコンソール出力 var rc int defer func() { console.Display("CTM002I", rc) }() if args.rerunInstance != 0 { nwkResult, err := getNetworkResult(args.rerunInstance) if err != nil { console.Display("CTM019E", err) return rc_ERROR } if nwkResult.Status == db.NORMAL || nwkResult.Status == db.WARN { console.Display("CTM029I", args.rerunInstance) return rc_OK } args.networkName = nwkResult.JobnetWork args.startFlag = flag_ON } nwk := jobnet.LoadNetwork(args.networkName) if nwk == nil { rc = rc_ERROR return rc } defer nwk.Terminate() err := nwk.DetectFlowError() if err != nil { console.Display("CTM011E", nwk.MasterPath, err) rc = rc_ERROR return rc } if args.startFlag == flag_OFF { console.Display("CTM020I", nwk.MasterPath) rc = rc_OK return rc } err = nwk.LoadJobEx() if err != nil { console.Display("CTM004E", nwk.JobExPath) log.Error(err) rc = rc_ERROR return rc } if args.rerunInstance == 0 { err = nwk.Run() } else { nwk.ID = args.rerunInstance err = nwk.Rerun() } if err != nil { console.Display("CTM013I", nwk.Name, nwk.ID, "ABNORMAL") // ジョブ自体の異常終了では、エラーメッセージが空で返るので、出力しない if len(err.Error()) != 0 { log.Error(err) } rc = rc_ERROR return rc } console.Display("CTM013I", nwk.Name, nwk.ID, "NORMAL") rc = rc_OK return rc }