diff --git a/Makefile b/Makefile index 19ae1a9..ae02a4a 100644 --- a/Makefile +++ b/Makefile @@ -233,7 +233,7 @@ checkstyle: $(BASE)/vendor: vendor-install -generatemodels: $(CURDIR)/swagger/aif-swagger.yaml ; $(info $(M) generate models …) @ ## Run generate models +generatemodels: $(CURDIR)/swagger/aif-swagger.yaml ; $(info $(M) generate models …) @ ## Generate model if [ ! -d $(BASESRC)/models ]; then \ GOPATH=$(GOPATH) go get -u github.com/go-swagger/go-swagger/cmd/swagger; \ if [ -r ../AdminRestServer/swagger/aif-swagger.yaml ]; then \ @@ -247,5 +247,5 @@ cleanModels: ; $(info $(M) cleaning models…) @ ## Cleanup vendor @rm -rf $(BASESRC)/models @rm -rf $(BASESRC)/client -generate: cleanModels $(BASESRC)/models +generate: cleanModels generatemodels # $(BASESRC)/models diff --git a/README.md b/README.md index 34294e7..ef1743d 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,4 @@ -Adabas RESTful administration client -==================================== +# Adabas RESTful administration client This code contains a sample use case of Adabas RESTful administration. The Swagger definition delivered in the Adabas RESTful administration server can be used to @@ -12,7 +11,7 @@ This example can be generated using GO 1.8 or higher. The result is a command line access to the Adabas RESTful administration. -# Build +## Build The build process needs an installed GO (golang) compiler. The build works on Linux. Any it is possible to build Windows version using the `GOOS=windows` parameter. The build-infrastructure of GO requires web access to download required dependencies. @@ -43,7 +42,7 @@ make GOOS=windows The final platform is independent to the platform Adabas is working. -# Runtime +## Runtime Beside the direct usage of the client you might use the `startAdmin.sh` script for a quick start. In this case it might be necessary to import dependent packages using the `go get ` command. The `startAdmin.sh` script provides all help descriptions entering the `help` command. diff --git a/src/softwareag.com/cmd/client.go b/src/softwareag.com/cmd/client.go index 5390b0c..72b9513 100644 --- a/src/softwareag.com/cmd/client.go +++ b/src/softwareag.com/cmd/client.go @@ -32,16 +32,15 @@ import ( "syscall" "time" - "golang.org/x/crypto/ssh/terminal" - "softwareag.com/client/environment" - - "softwareag.com/cmd/database" - "softwareag.com/cmd/job" - "github.com/go-openapi/runtime" httptransport "github.com/go-openapi/runtime/client" "github.com/go-openapi/strfmt" + "golang.org/x/crypto/ssh/terminal" "softwareag.com/client" + "softwareag.com/client/environment" + "softwareag.com/cmd/database" + "softwareag.com/cmd/filebrowser" + "softwareag.com/cmd/job" ) type display int @@ -81,11 +80,18 @@ const ( checkpoints joblist jobstart + deletejob + deletejobexec + createjob joblog listucb deleteucb addfields status + filelocations + listfiles + downloadfile + uploadfile ) const ( @@ -136,11 +142,18 @@ var displayName = []displayInfo{ displayInfo{id: checkpoints, cmdShort: "checkpoints", cmdDescription: "Display Database checkpoints. Without parameter it shows one day.\n Parameter example with from and to parameter: 2018-05-15_01:00:00,2018-05-20_00:00:00"}, displayInfo{id: joblist, cmdShort: "joblist", cmdDescription: "Job control list"}, displayInfo{id: jobstart, cmdShort: "jobstart", cmdDescription: "Start a specific job"}, + displayInfo{id: deletejob, cmdShort: "deletejob", cmdDescription: "Delete a specific job and the execution log"}, + displayInfo{id: deletejobexec, cmdShort: "deletejobexec", cmdDescription: "Delete the execution log of a job"}, + displayInfo{id: createjob, cmdShort: "createjob", cmdDescription: "Create a new specific job"}, displayInfo{id: joblog, cmdShort: "joblog", cmdDescription: "Job entry log"}, displayInfo{id: listucb, cmdShort: "listucb", cmdDescription: "List Adabas UCB entries"}, displayInfo{id: deleteucb, cmdShort: "deleteucb", cmdDescription: "Delete Adabas UCB entry"}, displayInfo{id: addfields, cmdShort: "addfields", cmdDescription: "Add Adabas fields"}, - displayInfo{id: status, cmdShort: "status", cmdDescription: "Adabas database online state"}} + displayInfo{id: status, cmdShort: "status", cmdDescription: "Adabas database online state"}, + displayInfo{id: filelocations, cmdShort: "filelocations", cmdDescription: "List all available file locations"}, + displayInfo{id: listfiles, cmdShort: "listfiles", cmdDescription: "List file in file location"}, + displayInfo{id: downloadfile, cmdShort: "downloadfile", cmdDescription: "Download file out of file location"}, + displayInfo{id: uploadfile, cmdShort: "uploadfile", cmdDescription: "Upload file to file location"}} func displayValue(name string) display { for i := 0; i < len(displayName); i++ { @@ -171,6 +184,7 @@ func main() { passwd := flag.String("passwd", "", "Password of administration, may be predefined using environment variable ADABAS_ADMIN_PASSWORD") dbid := flag.Int("dbid", 0, "Adabas Database id") fnr := flag.Int("fnr", 0, "Adabas Database file") + sleep := flag.Int("repeat", 0, "Repeat display after given seconds") ignoreTLS := flag.Bool("ignoreTLS", false, "Ignore TLS certificate validation") param := flag.String("param", "", "Method specific parameters") @@ -182,8 +196,9 @@ func main() { if restURL == "" { restURL = os.Getenv(adabasAdminURL) if restURL == "" { + fmt.Println("No host URL provided, use -url parameter or environment setting in " + adabasAdminURL) usage() - return + os.Exit(1) } } @@ -218,7 +233,7 @@ func main() { h, _, errx := net.SplitHostPort(ru) if errx != nil { fmt.Printf("Host url error %s: %v", restURL, errx) - return + os.Exit(2) } cookieURL := &url.URL{Scheme: "http", Host: h, Path: "/adabas"} var cookie *http.Cookie @@ -274,94 +289,123 @@ func main() { // http.SetCookie(clientInstance, &cookie) defer printEnd(time.Now()) - for _, a := range args { - d := displayValue(a) - switch d { - case unknown: - fmt.Printf("Unknown command: %s\n", a) - usage() - aborted = true - return - case env: - database.Environment(clientInstance, auth) - case list: - database.List(clientInstance, auth) - case start: - database.Operation(clientInstance, *dbid, "start", auth) - case shutdown: - database.Operation(clientInstance, *dbid, "shutdown", auth) - case cancel: - database.Operation(clientInstance, *dbid, "cancel", auth) - case abort: - database.Operation(clientInstance, *dbid, "abort", auth) - case info: - database.Operation(clientInstance, *dbid, "", auth) - case userqueue: - database.UserQueue(clientInstance, *dbid, auth) - case cmdqueue: - database.CommandQueue(clientInstance, *dbid, auth) - case holdqueue: - database.HoldQueue(clientInstance, *dbid, auth) - case highwater: - database.Highwater(clientInstance, *dbid, auth) - case commandstats: - database.CommandStats(clientInstance, *dbid, auth) - case bp: - database.BufferpoolStats(clientInstance, *dbid, auth) - case activity: - database.Activity(clientInstance, *dbid, auth) - case threadtable: - database.ThreadTable(clientInstance, *dbid, auth) - case createdatabase: - database.Create(clientInstance, *dbid, input.String(), auth) - case deletedatabase: - database.Delete(clientInstance, *dbid, input.String(), auth) - case renamedatabase: - database.Rename(clientInstance, *dbid, *param, auth) - case parameter: - database.Parameter(clientInstance, *dbid, *param, auth) - case parameterinfo: - database.ParameterInfo(clientInstance, *dbid, auth) - case setparameter: - database.SetParameter(clientInstance, *dbid, *param, auth) - case nucleuslog: - database.NucleusLog(clientInstance, *dbid, auth) - case files: - database.Files(clientInstance, *dbid, auth) - case file: - database.File(clientInstance, *dbid, *fnr, *param, auth) - case deletefile: - database.DeleteFile(clientInstance, *dbid, *fnr, auth) - case information: - database.Information(clientInstance, *dbid, auth) - case fields: - database.Fields(clientInstance, *dbid, *fnr, auth) - case container: - database.Container(clientInstance, *dbid, auth) - case renamefile: - database.RenameFile(clientInstance, *dbid, *fnr, *param, auth) - case createfile: - database.CreateFile(clientInstance, *dbid, *fnr, input, auth) - case checkpoints: - database.Checkpoints(clientInstance, *dbid, *param, auth) - case joblist: - job.List(clientInstance, auth) - case jobstart: - job.Start(clientInstance, *param, auth) - case joblog: - job.Log(clientInstance, *param, auth) - case listucb: - database.Ucb(clientInstance, *dbid, auth) - case deleteucb: - database.DeleteUcb(clientInstance, *dbid, *param, auth) - case addfields: - database.AddFields(clientInstance, *dbid, *fnr, *param, auth) - case status: - database.Status(clientInstance, *dbid, auth) - default: - version(clientInstance) + + for { + var err error + for _, a := range args { + d := displayValue(a) + switch d { + case unknown: + fmt.Printf("Unknown command: %s\n", a) + usage() + aborted = true + os.Exit(4) + case env: + err = database.Environment(clientInstance, auth) + case list: + err = database.List(clientInstance, auth) + case start: + err = database.Operation(clientInstance, *dbid, "start", auth) + case shutdown: + err = database.Operation(clientInstance, *dbid, "shutdown", auth) + case cancel: + err = database.Operation(clientInstance, *dbid, "cancel", auth) + case abort: + err = database.Operation(clientInstance, *dbid, "abort", auth) + case info: + err = database.Operation(clientInstance, *dbid, "", auth) + case userqueue: + err = database.UserQueue(clientInstance, *dbid, auth) + case cmdqueue: + err = database.CommandQueue(clientInstance, *dbid, auth) + case holdqueue: + err = database.HoldQueue(clientInstance, *dbid, auth) + case highwater: + err = database.Highwater(clientInstance, *dbid, auth) + case commandstats: + err = database.CommandStats(clientInstance, *dbid, auth) + case bp: + err = database.BufferpoolStats(clientInstance, *dbid, auth) + case activity: + err = database.Activity(clientInstance, *dbid, auth) + case threadtable: + err = database.ThreadTable(clientInstance, *dbid, auth) + case createdatabase: + err = database.Create(clientInstance, *dbid, input.String(), auth) + case deletedatabase: + err = database.Delete(clientInstance, *dbid, input.String(), auth) + case renamedatabase: + err = database.Rename(clientInstance, *dbid, *param, auth) + case parameter: + err = database.Parameter(clientInstance, *dbid, *param, auth) + case parameterinfo: + err = database.ParameterInfo(clientInstance, *dbid, auth) + case setparameter: + err = database.SetParameter(clientInstance, *dbid, *param, auth) + case nucleuslog: + err = database.NucleusLog(clientInstance, *dbid, auth) + case files: + err = database.Files(clientInstance, *dbid, auth) + case file: + err = database.File(clientInstance, *dbid, *fnr, *param, auth) + case deletefile: + err = database.DeleteFile(clientInstance, *dbid, *fnr, auth) + case information: + err = database.Information(clientInstance, *dbid, auth) + case fields: + err = database.Fields(clientInstance, *dbid, *fnr, auth) + case container: + err = database.Container(clientInstance, *dbid, auth) + case renamefile: + err = database.RenameFile(clientInstance, *dbid, *fnr, *param, auth) + case createfile: + err = database.CreateFile(clientInstance, *dbid, *fnr, input, auth) + case checkpoints: + err = database.Checkpoints(clientInstance, *dbid, *param, auth) + case joblist: + err = job.List(clientInstance, auth) + case jobstart: + err = job.Start(clientInstance, *param, auth) + case deletejob: + err = job.Delete(clientInstance, *param, auth) + case deletejobexec: + err = job.DeleteExecution(clientInstance, *param, auth) + case createjob: + err = job.Create(clientInstance, input.String(), auth) + case joblog: + err = job.Log(clientInstance, *param, auth) + case listucb: + err = database.Ucb(clientInstance, *dbid, auth) + case deleteucb: + err = database.DeleteUcb(clientInstance, *dbid, *param, auth) + case addfields: + err = database.AddFields(clientInstance, *dbid, *fnr, *param, auth) + case status: + err = database.Status(clientInstance, *dbid, auth) + case filelocations: + err = filebrowser.Locations(clientInstance, auth) + case listfiles: + err = filebrowser.List(clientInstance, *param, auth) + case downloadfile: + err = filebrowser.Download(clientInstance, *param, input.String(), auth) + case uploadfile: + err = filebrowser.Upload(clientInstance, *param, input.String(), auth) + default: + err = version(clientInstance) + } + if err != nil { + break + } + } + if err != nil { + os.Exit(10) } + if *sleep == 0 { + break + } else { + time.Sleep(time.Duration(*sleep) * time.Second) + } } } @@ -389,18 +433,19 @@ func printEnd(start time.Time) { } } -func version(clientInstance *client.AdabasAdmin) { +func version(clientInstance *client.AdabasAdmin) error { params := environment.NewGetVersionParams() resp, err := clientInstance.Environment.GetVersion(params) if err != nil { fmt.Println("Error:", err) - return + return err } fmt.Printf("Version %s %s\n", resp.Payload.Version, resp.Payload.Product) fmt.Printf("\nHandlers:\n") for _, h := range resp.Payload.Handler { fmt.Printf(" %s: %s\n", h.Name, h.Version) } + return nil } func adabasEnv(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) { diff --git a/src/softwareag.com/cmd/database/databases.go b/src/softwareag.com/cmd/database/databases.go index 8c7ceb4..fd7bed2 100644 --- a/src/softwareag.com/cmd/database/databases.go +++ b/src/softwareag.com/cmd/database/databases.go @@ -43,7 +43,7 @@ import ( ) // List list databases -func List(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) { +func List(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) error { // resp, err := client.Default.OnlineOffline.GetDatabases(nil, auth) resp, err := clientInstance.OnlineOffline.GetDatabases(nil, auth) if err != nil { @@ -54,7 +54,7 @@ func List(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) default: fmt.Println("Error:", err) } - return + return err } fmt.Printf(" %3s %-16s %8s %s\n", "Dbid", "Name", "Active", "Version") fmt.Println() @@ -62,14 +62,16 @@ func List(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) fmt.Printf(" %03d [%-16s] %8v %s\n", d.Dbid, d.Name, d.Active, d.Version) } fmt.Println() + return nil } // Environment Operation init operations on database -func Environment(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) { +func Environment(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) error { + return nil } // Operation init operations on database -func Operation(clientInstance *client.AdabasAdmin, dbid int, operation string, auth runtime.ClientAuthInfoWriter) { +func Operation(clientInstance *client.AdabasAdmin, dbid int, operation string, auth runtime.ClientAuthInfoWriter) error { if operation != "" { fmt.Printf("\nSend following operation to database %v: %s\n", dbid, operation) } else { @@ -87,7 +89,7 @@ func Operation(clientInstance *client.AdabasAdmin, dbid int, operation string, a default: fmt.Println("Error:", err) } - return + return err } if accepted != nil { fmt.Printf("Database status dbid=%d %s\n", accepted.Payload.Status.Dbid, accepted.Payload.Status.Message) @@ -99,6 +101,7 @@ func Operation(clientInstance *client.AdabasAdmin, dbid int, operation string, a fmt.Printf("Database operation inited successfully\n") } } + return nil } func createDatabaseInstance(dbid int, input string) *models.Database { @@ -137,7 +140,7 @@ func createDatabaseInstance(dbid int, input string) *models.Database { } // Status database online state -func Status(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func Status(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewDatabaseOperationParams() params.DbidOperation = strconv.Itoa(dbid) resp, accepted, err := clientInstance.OnlineOffline.DatabaseOperation(params, auth) @@ -152,7 +155,7 @@ func Status(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAut default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -166,11 +169,11 @@ func Status(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAut p.Printf(" %s\n", accepted.Payload.Status.Message) } p.Println() - + return nil } // Create create database -func Create(clientInstance *client.AdabasAdmin, dbid int, input string, auth runtime.ClientAuthInfoWriter) { +func Create(clientInstance *client.AdabasAdmin, dbid int, input string, auth runtime.ClientAuthInfoWriter) error { params := offline.NewPostAdabasDatabaseParams() params.Database = createDatabaseInstance(dbid, input) params.Database.Dbid = int64(dbid) @@ -183,7 +186,7 @@ func Create(clientInstance *client.AdabasAdmin, dbid int, input string, auth run default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -192,11 +195,11 @@ func Create(clientInstance *client.AdabasAdmin, dbid int, input string, auth run p.Println(" Adabas status of database creation:") p.Println() p.Printf(" %s", resp.Payload.Status.Message) - + return nil } // Delete database -func Delete(clientInstance *client.AdabasAdmin, dbid int, input string, auth runtime.ClientAuthInfoWriter) { +func Delete(clientInstance *client.AdabasAdmin, dbid int, input string, auth runtime.ClientAuthInfoWriter) error { params := offline.NewDeleteAdabasDatabaseParams() params.DbidOperation = float64(dbid) resp, err := clientInstance.Offline.DeleteAdabasDatabase(params, auth) @@ -208,7 +211,7 @@ func Delete(clientInstance *client.AdabasAdmin, dbid int, input string, auth run default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -216,10 +219,11 @@ func Delete(clientInstance *client.AdabasAdmin, dbid int, input string, auth run p.Println() p.Printf(" Adabas status of database delete: %s", resp.Payload.Status.Message) p.Println() + return nil } // Rename database -func Rename(clientInstance *client.AdabasAdmin, dbid int, param string, auth runtime.ClientAuthInfoWriter) { +func Rename(clientInstance *client.AdabasAdmin, dbid int, param string, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewPutDatabaseResourceParams() params.DbidOperation = strconv.Itoa(dbid) params.Name = param @@ -232,7 +236,7 @@ func Rename(clientInstance *client.AdabasAdmin, dbid int, param string, auth run default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -247,11 +251,11 @@ func Rename(clientInstance *client.AdabasAdmin, dbid int, param string, auth run p.Printf(" Adabas status of database delete: %s", acpt.Payload.Status.Message) } p.Println() - + return nil } // NucleusLog show nucleus log -func NucleusLog(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func NucleusLog(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewGetDatabaseNucleusLogParams() params.Dbid = float64(dbid) resp, err := clientInstance.OnlineOffline.GetDatabaseNucleusLog(params, auth) @@ -263,16 +267,19 @@ func NucleusLog(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Clien default: fmt.Println("Error:", err) } - return + return err } fmt.Printf("\nDatabase %03d Nucleus log:\n", dbid) fmt.Println(resp.Payload.Log.Log) + return nil } // Information database information -func Information(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func Information(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewGetDatabaseGcbParams() + rfc3339 := true + params.Rfc3339 = &rfc3339 params.Dbid = float64(dbid) resp, err := clientInstance.OnlineOffline.GetDatabaseGcb(params, auth) if err != nil { @@ -283,7 +290,7 @@ func Information(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Clie default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -294,8 +301,8 @@ func Information(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Clie p.Printf("Name : %s\n", resp.Payload.Gcb.Name) p.Printf("Version : %s\n", resp.Payload.Gcb.StructureLevel) p.Printf("Architecture : %s\n", resp.Payload.Gcb.Architecture) - p.Printf("Created : %s\n", resp.Payload.Gcb.Date) - p.Printf("Last changed : %s\n", resp.Payload.Gcb.TimeStampLog) + p.Printf("Created : %s\n", time.Time(resp.Payload.Gcb.Date).Format("Mon Jan _2 15:04:05 2006")) + p.Printf("Last changed : %s\n", time.Time(resp.Payload.Gcb.TimeStampLog).Format("Mon Jan _2 15:04:05 2006")) p.Printf("PLOG count : %d\n", resp.Payload.Gcb.PLOGCount) p.Printf("Current CLOG : %d\n", resp.Payload.Gcb.CurrentCLOGNumber) p.Printf("Current PLOG : %d\n", resp.Payload.Gcb.CurrentPLOGNumber) @@ -310,7 +317,7 @@ func Information(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Clie p.Printf(" Metadata File : %d\n", resp.Payload.Gcb.ReplicationMetadataFile) p.Printf(" Command File : %d\n", resp.Payload.Gcb.ReplicationCommandFile) p.Printf(" Transition File : %d\n", resp.Payload.Gcb.ReplicationTransitionFile) - p.Printf(" Timestamp Repl : %s\n", resp.Payload.Gcb.TimeStampReplication) + p.Printf(" Timestamp Repl : %s\n", time.Time(resp.Payload.Gcb.TimeStampReplication).Format("Mon Jan _2 15:04:05 2006")) p.Printf("Work\n") for i, e := range resp.Payload.Gcb.WORKExtents { if e.RABNunused != 0 { @@ -326,10 +333,11 @@ func Information(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Clie } p.Printf(" Work part 1 : %d\n", resp.Payload.Gcb.WORKPart1Size) + return nil } // Activity database activity -func Activity(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func Activity(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseActStatsParams() params.Dbid = float64(dbid) resp, err := clientInstance.Online.GetDatabaseActStats(params, auth) @@ -341,7 +349,7 @@ func Activity(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientA default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -362,10 +370,11 @@ func Activity(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientA p.Println(" ------------- ----- ---------- ------- -----") p.Printf(" Buffer Pool %.1f%% WP Space Wait %10d %10d\n", float64(resp.Payload.Statistics.BPHitRate), resp.Payload.Statistics.WPSpaceWaitCurrent, resp.Payload.Statistics.WpSpaceWaitTotal) p.Printf(" Format pool %.1f%%\n", float64(resp.Payload.Statistics.FPHitRate)) + return nil } // ThreadTable display thread table -func ThreadTable(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func ThreadTable(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseThreadTableParams() params.Dbid = float64(dbid) resp, err := clientInstance.Online.GetDatabaseThreadTable(params, auth) @@ -378,7 +387,7 @@ func ThreadTable(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Clie default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -391,22 +400,22 @@ func ThreadTable(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Clie for _, t := range resp.Payload.Threads { p.Printf(" %2d %10d %5d %2s %s\n", t.Thread, t.CommandCount, t.File, t.CommandCode, t.Status) } - + return nil } // Parameter show parameter -func Parameter(clientInstance *client.AdabasAdmin, dbid int, para string, auth runtime.ClientAuthInfoWriter) { +func Parameter(clientInstance *client.AdabasAdmin, dbid int, para string, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewGetDatabaseParameterParams() params.Dbid = float64(dbid) if para == "" { fmt.Println("Please provide parameter static or dynamic to reference corresponding parameter configuration.") - return + return fmt.Errorf("Please provide parameter static or dynamic to reference corresponding parameter configuration") } params.Type = strings.ToLower(para) if params.Type != "static" && params.Type != "dynamic" { fmt.Println("Parameter type must be static or dynamic to reference corresponding parameter configuration.") - return + return fmt.Errorf("Parameter type must be static or dynamic to reference corresponding parameter configuration") } resp, err := clientInstance.OnlineOffline.GetDatabaseParameter(params, auth) @@ -418,7 +427,7 @@ func Parameter(clientInstance *client.AdabasAdmin, dbid int, para string, auth r default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -433,11 +442,11 @@ func Parameter(clientInstance *client.AdabasAdmin, dbid int, para string, auth r v := val.Field(i) fmt.Println(" ", field.Name, "=", v) } - + return nil } // ParameterInfo show parameter info -func ParameterInfo(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func ParameterInfo(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewGetDatabaseParameterInfoParams() params.Dbid = float64(dbid) resp, err := clientInstance.OnlineOffline.GetDatabaseParameterInfo(params, auth) @@ -449,7 +458,7 @@ func ParameterInfo(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Cl default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -498,6 +507,7 @@ func ParameterInfo(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Cl } } p.Println() + return nil } type parameterSet struct { @@ -506,7 +516,7 @@ type parameterSet struct { } // SetParameter set parameter -func SetParameter(clientInstance *client.AdabasAdmin, dbid int, param string, auth runtime.ClientAuthInfoWriter) { +func SetParameter(clientInstance *client.AdabasAdmin, dbid int, param string, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewPutAdabasParameterParams() params.Dbid = float64(dbid) pmap := make(map[string]string) @@ -533,7 +543,7 @@ func SetParameter(clientInstance *client.AdabasAdmin, dbid int, param string, au fmt.Println(v) if len(v) != 2 { fmt.Printf("Parameter %s not valid, need of the type: param1=1,param2=ON,param3=(A,B)", param) - return + return fmt.Errorf("Parameter %s not valid, need of the type: param1=1,param2=ON,param3=(A,B)", param) } if strings.ToLower(v[0]) == "type" { if strings.ToLower(v[1]) == "dynamic" { @@ -567,7 +577,7 @@ func SetParameter(clientInstance *client.AdabasAdmin, dbid int, param string, au i, err := strconv.Atoi(v[1]) if err != nil { fmt.Println("Incorrect value for " + v[0]) - return + return fmt.Errorf("Incorrect value for " + v[0]) } i64 := int64(i) f.Set(reflect.ValueOf(&i64)) @@ -601,12 +611,12 @@ func SetParameter(clientInstance *client.AdabasAdmin, dbid int, param string, au default: fmt.Println("Error:", err) } - return + return err } fmt.Println() fmt.Printf(" Adabas parameter: %s", resp.Payload.Status.Message) fmt.Println() - + return nil } func checkArConflict(value string) string { @@ -755,7 +765,7 @@ func checkLogging(logging string) string { } // Container list database container -func Container(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func Container(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewGetDatabaseContainerParams() params.Dbid = float64(dbid) resp, err := clientInstance.OnlineOffline.GetDatabaseContainer(params, auth) @@ -767,7 +777,7 @@ func Container(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Client default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -785,10 +795,11 @@ func Container(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Client for _, c := range resp.Payload.Container.FreeSpaceTable { p.Printf(" %5s %10d %10d %4d\n", c.Type, c.FirstRABN, c.LastRABN, c.BlockSize) } + return nil } // Checkpoints list checkpoints in an specific range -func Checkpoints(clientInstance *client.AdabasAdmin, dbid int, timeRange string, auth runtime.ClientAuthInfoWriter) { +func Checkpoints(clientInstance *client.AdabasAdmin, dbid int, timeRange string, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseCheckpointsParams() params.Dbid = float64(dbid) if timeRange == "" { @@ -819,22 +830,23 @@ func Checkpoints(clientInstance *client.AdabasAdmin, dbid int, timeRange string, default: fmt.Println("Error:", err) } - return + return err } fmt.Println("\nQuery checkpoint from ", *params.StartTime, " to ", *params.EndTime) for _, c := range resp.Payload.Checkpoints { fmt.Println(c.Name, c.Session, c.Date, c.Details) } + return nil } // DeleteCheckpoints delete checkpoints in an specific range -func DeleteCheckpoints(clientInstance *client.AdabasAdmin, dbid int, timeRange string, auth runtime.ClientAuthInfoWriter) { +func DeleteCheckpoints(clientInstance *client.AdabasAdmin, dbid int, timeRange string, auth runtime.ClientAuthInfoWriter) error { params := online.NewDeleteDatabaseCheckpointsParams() params.Dbid = float64(dbid) if timeRange == "" { fmt.Println("Please provide time range of the checkpoints which should be delete. Example:") fmt.Println(" -param -param '2018-05-15_01:00:00,2018-05-20_00:00:00'") - return + return fmt.Errorf("Checkpoint range parameter missing") } rg := regexp.MustCompile("_") tr := rg.ReplaceAllString(timeRange, " ") @@ -854,18 +866,18 @@ func DeleteCheckpoints(clientInstance *client.AdabasAdmin, dbid int, timeRange s default: fmt.Println("Error:", err) } - return + return err } fmt.Println() fmt.Printf(" Adabas status of delete checkpoint in range of %s to %s: %s", *params.StartTime, *params.EndTime, resp.Payload.Status.Message) fmt.Println() - + return nil } // Ucb list UCBs -func Ucb(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func Ucb(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewGetUCBParams() params.Dbid = float64(dbid) @@ -878,7 +890,7 @@ func Ucb(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthIn default: fmt.Println("Error:", err) } - return + return err } fmt.Println() fmt.Println(" UCB entries:") @@ -888,17 +900,17 @@ func Ucb(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthIn s, _ := json.Marshal(c.UcbFiles) fmt.Printf(" %-20s %-10d %-8s %-8s %s\n", c.Date, c.Sequence, c.ID, c.DBMode, s) } - + return nil } // DeleteUcb delete UCB entry -func DeleteUcb(clientInstance *client.AdabasAdmin, dbid int, param string, auth runtime.ClientAuthInfoWriter) { +func DeleteUcb(clientInstance *client.AdabasAdmin, dbid int, param string, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewDeleteUCBParams() params.Dbid = float64(dbid) ucbid, err := strconv.Atoi(param) if err != nil { fmt.Println("Error UCB id parameter not numeric: ", err) - return + return err } params.Ucbid = int64(ucbid) @@ -912,11 +924,11 @@ func DeleteUcb(clientInstance *client.AdabasAdmin, dbid int, param string, auth default: fmt.Println("Error:", err) } - return + return err } fmt.Println() fmt.Printf(" Adabas status of UCB delete: %s", resp.Payload.Status.Message) fmt.Println() - + return nil } diff --git a/src/softwareag.com/cmd/database/fields.go b/src/softwareag.com/cmd/database/fields.go index 5602dfe..5558ad4 100644 --- a/src/softwareag.com/cmd/database/fields.go +++ b/src/softwareag.com/cmd/database/fields.go @@ -32,8 +32,10 @@ import ( ) // Fields list fields of a Adabas file -func Fields(clientInstance *client.AdabasAdmin, dbid int, fnr int, auth runtime.ClientAuthInfoWriter) { +func Fields(clientInstance *client.AdabasAdmin, dbid int, fnr int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewGetFieldDefinitionTableParams() + rfc3339 := true + params.Rfc3339 = &rfc3339 params.Dbid = float64(dbid) params.File = float64(fnr) resp, err := clientInstance.OnlineOffline.GetFieldDefinitionTable(params, auth) @@ -45,7 +47,7 @@ func Fields(clientInstance *client.AdabasAdmin, dbid int, fnr int, auth runtime. default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -79,10 +81,11 @@ func Fields(clientInstance *client.AdabasAdmin, dbid int, fnr int, auth runtime. printFields(p, f) } } + return nil } // AddFields add Adabas fields -func AddFields(clientInstance *client.AdabasAdmin, dbid int, fnr int, fdt string, auth runtime.ClientAuthInfoWriter) { +func AddFields(clientInstance *client.AdabasAdmin, dbid int, fnr int, fdt string, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewModifyFieldDefinitionTableParams() params.Dbid = float64(dbid) params.File = float64(fnr) @@ -97,11 +100,11 @@ func AddFields(clientInstance *client.AdabasAdmin, dbid int, fnr int, fdt string default: fmt.Println("Error:", err) } - return + return err } fmt.Println("Status: ", resp.Payload.Status.Message) - return + return nil } diff --git a/src/softwareag.com/cmd/database/files.go b/src/softwareag.com/cmd/database/files.go index 20a476b..8a3b6c0 100644 --- a/src/softwareag.com/cmd/database/files.go +++ b/src/softwareag.com/cmd/database/files.go @@ -63,7 +63,7 @@ func (il *InputList) Set(v string) error { } // Files list database files -func Files(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func Files(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewGetDatabaseFilesParams() params.Dbid = float64(dbid) resp, err := clientInstance.OnlineOffline.GetDatabaseFiles(params, auth) @@ -75,7 +75,7 @@ func Files(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuth default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -94,17 +94,18 @@ func Files(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuth } p.Printf(" %03d %-20s %10d %s\n", f.FileNr, f.Name, f.RecordCount, s) } + return nil } // File get file information -func File(clientInstance *client.AdabasAdmin, dbid int, fnr int, para string, auth runtime.ClientAuthInfoWriter) { +func File(clientInstance *client.AdabasAdmin, dbid int, fnr int, para string, auth runtime.ClientAuthInfoWriter) error { if dbid < 1 { fmt.Println("Please add option -dbid Adabas database id") - return + return fmt.Errorf("Please add option -dbid Adabas database id") } if fnr < 1 { fmt.Println("Please add option -fnr Adabas file number") - return + return fmt.Errorf("Please add option -fnr Adabas file number") } if para != "" { params := online.NewPutAdabasFileParameterParams() @@ -121,7 +122,7 @@ func File(clientInstance *client.AdabasAdmin, dbid int, fnr int, para string, au b, err := strconv.ParseBool(p[1]) if err != nil { fmt.Println("PGM refresh parameter invalid: ", p[1]) - return + return err } pgm = b params.Pgmrefresh = &pgm @@ -129,7 +130,7 @@ func File(clientInstance *client.AdabasAdmin, dbid int, fnr int, para string, au b, err := strconv.ParseBool(p[1]) if err != nil { fmt.Println("ISN reusage parameter invalid: ", p[1]) - return + return err } ir = b params.Isnreusage = &ir @@ -137,13 +138,13 @@ func File(clientInstance *client.AdabasAdmin, dbid int, fnr int, para string, au b, err := strconv.ParseBool(p[1]) if err != nil { fmt.Println("Space reusage parameter invalid: ", p[1]) - return + return err } sr = b params.Spacereusage = &sr default: fmt.Println("Unknown parameter:", p[0]) - return + return fmt.Errorf("Unkown Parameter %s", p[0]) } } @@ -158,12 +159,14 @@ func File(clientInstance *client.AdabasAdmin, dbid int, fnr int, para string, au default: fmt.Println("Error:", errp) } - return + return errp } fmt.Println("Status: ", resp.Payload.Status.Message) - return + return nil } params := online_offline.NewGetDatabaseFileParams() + rfc3339 := true + params.Rfc3339 = &rfc3339 params.Dbid = float64(dbid) params.FileOperation = strconv.Itoa(fnr) resp, err := clientInstance.OnlineOffline.GetDatabaseFile(params, auth) @@ -175,7 +178,7 @@ func File(clientInstance *client.AdabasAdmin, dbid int, fnr int, para string, au default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -222,10 +225,11 @@ func File(clientInstance *client.AdabasAdmin, dbid int, fnr int, para string, au p.Printf(" Last RABN : %d\n", e.LastRabn) p.Printf(" Free or Isn : %d\n", e.FreeOrIsn) } + return nil } // RenameFile rename database file -func RenameFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, newName string, auth runtime.ClientAuthInfoWriter) { +func RenameFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, newName string, auth runtime.ClientAuthInfoWriter) error { params := online.NewPutAdabasFileParameterParams() params.Dbid = float64(dbid) params.Name = &newName @@ -239,19 +243,20 @@ func RenameFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, newName s default: fmt.Println("Error:", err) } - return + return err } fmt.Println("Status: ", resp.Payload.Status.Message) + return nil } // RenumberFile renumber database file -func RenumberFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, newNumber string, auth runtime.ClientAuthInfoWriter) { +func RenumberFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, newNumber string, auth runtime.ClientAuthInfoWriter) error { params := online.NewPutAdabasFileParameterParams() params.Dbid = float64(dbid) number, err := strconv.Atoi(newNumber) if err != nil { fmt.Println("Error:", err) - return + return err } flNumber := float64(number) params.Number = &flNumber @@ -265,9 +270,10 @@ func RenumberFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, newNumb default: fmt.Println("Error:", err) } - return + return err } fmt.Println("Status: ", resp.Payload.Status.Message) + return nil } func loadFdt(fdt string) string { @@ -340,16 +346,16 @@ func createFileInstance(dbid int, fnr int, input InputList) *models.FduFdt { } // CreateFile create database file -func CreateFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, input InputList, auth runtime.ClientAuthInfoWriter) { +func CreateFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, input InputList, auth runtime.ClientAuthInfoWriter) error { if len(input) == 0 { fmt.Println("Please add -input parameter for FDU and FDT") - return + return fmt.Errorf("Please add -input parameter for FDU and FDT") } params := online.NewCreateAdabasFileParams() params.Dbid = float64(dbid) params.Fdufdt = createFileInstance(dbid, fnr, input) if params.Fdufdt == nil { - return + return fmt.Errorf("Error parsing file") } resp, err := clientInstance.Online.CreateAdabasFile(params, auth) if err != nil { @@ -360,13 +366,14 @@ func CreateFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, input Inp default: fmt.Println("Error:", err, reflect.TypeOf(err)) } - return + return err } fmt.Println("Status: ", resp.Payload.Status.Message) + return nil } // DeleteFile delete database file -func DeleteFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, auth runtime.ClientAuthInfoWriter) { +func DeleteFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, auth runtime.ClientAuthInfoWriter) error { params := online_offline.NewDeleteFileParams() params.Dbid = float64(dbid) params.FileOperation = float64(fnr) @@ -379,7 +386,7 @@ func DeleteFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, auth runt default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -387,4 +394,5 @@ func DeleteFile(clientInstance *client.AdabasAdmin, dbid int, fnr int, auth runt p.Println() p.Printf(" Adabas status deleting file: %s", resp.Payload.Status.Message) p.Println() + return nil } diff --git a/src/softwareag.com/cmd/database/queues.go b/src/softwareag.com/cmd/database/queues.go index 541f2ab..077748e 100644 --- a/src/softwareag.com/cmd/database/queues.go +++ b/src/softwareag.com/cmd/database/queues.go @@ -28,9 +28,12 @@ import ( ) // UserQueue display all user queue entries -func UserQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func UserQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseUserQueueParams() + rfc3339 := true + params.Rfc3339 = &rfc3339 params.Dbid = float64(dbid) + resp, err := clientInstance.Online.GetDatabaseUserQueue(params, auth) if err != nil { switch err.(type) { @@ -40,7 +43,7 @@ func UserQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Client default: fmt.Println("Error:", err) } - return + return err } userQueue := resp.Payload.UserQueue @@ -52,11 +55,14 @@ func UserQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Client fmt.Printf(" %3d %10d %-8s %-8s %-8s %-8s %-8s %-8s\n", u.UqID, u.UID.ID, u.UID.Node, u.UID.Terminal, u.UID.Timestamp, u.User, u.Flags, u.EtFlags) } + return nil } // CommandQueue display all command queue entries -func CommandQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func CommandQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseCommandQueueParams() + rfc3339 := true + params.Rfc3339 = &rfc3339 params.Dbid = float64(dbid) resp, err := clientInstance.Online.GetDatabaseCommandQueue(params, auth) if err != nil { @@ -67,7 +73,7 @@ func CommandQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Cli default: fmt.Println("Error:", err) } - return + return err } fmt.Println() @@ -77,23 +83,33 @@ func CommandQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Cli for _, c := range resp.Payload.CommandQueue.Commands { fmt.Printf(" %3d %-8s %-8s %-10d %-3s %-8d %-s\n", c.CommID, c.User.Node, c.User.Terminal, c.User.ID, c.CommandCode, c.File, c.Flags) } + return nil } // HoldQueue display all hold queue entries -func HoldQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func HoldQueue(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseHoldQueueParams() + rfc3339 := true + params.Rfc3339 = &rfc3339 params.Dbid = float64(dbid) resp, err := clientInstance.Online.GetDatabaseHoldQueue(params, auth) if err != nil { - fmt.Println("Error:", err) - return + switch err.(type) { + case *online.GetDatabaseHoldQueueBadRequest: + response := err.(*online.GetDatabaseHoldQueueBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err } fmt.Println() fmt.Println(" Hold queue entries:") fmt.Println() fmt.Printf(" Id Node Id Login Id ES Id User Id File ISN Locks Flg\n") - for _, c := range resp.Payload.HoldQueueEntry { - fmt.Printf(" %3d %-8s %-8s %3d %3s %d %s %s\n", c.HqCommid, c.Hid.Node, c.Hid.Terminal, c.Hid.ID, c.User, c.File, c.Locks, c.Flags) + for _, c := range resp.Payload.HoldQueue { + fmt.Printf(" %3d %-8s %-8s %3d %3s %d %s %s\n", c.HqCommid, c.Hid[0].Node, c.Hid[0].Terminal, c.Hid[0].ID, c.User, c.File, c.Locks, c.Flags) } + return nil } diff --git a/src/softwareag.com/cmd/database/stats.go b/src/softwareag.com/cmd/database/stats.go index 074932a..c00e747 100644 --- a/src/softwareag.com/cmd/database/stats.go +++ b/src/softwareag.com/cmd/database/stats.go @@ -30,8 +30,10 @@ import ( ) // Highwater High water statistics -func Highwater(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func Highwater(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseHighWaterParams() + rfc3339 := true + params.Rfc3339 = &rfc3339 params.Dbid = float64(dbid) resp, err := clientInstance.Online.GetDatabaseHighWater(params, auth) if err != nil { @@ -42,7 +44,7 @@ func Highwater(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Client default: fmt.Println("Error:", err) } - return + return err } p := message.NewPrinter(language.English) @@ -100,16 +102,23 @@ func Highwater(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Client p.Printf("%-18s %10d %10d %10d %02d %s\n", "Transaction Commit", resp.Payload.HighWater.TransactionTimeSize, resp.Payload.HighWater.TransactionTimeHighWaterMark.Inuse, resp.Payload.HighWater.TransactionTimeHighWaterMark.High, 0, resp.Payload.HighWater.TransactionTimeHighWaterMark.Time) + return nil } // CommandStats command statistics -func CommandStats(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func CommandStats(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseCommandStatsParams() params.Dbid = float64(dbid) resp, err := clientInstance.Online.GetDatabaseCommandStats(params, auth) if err != nil { - fmt.Println("Error:", err) - return + switch err.(type) { + case *online.GetDatabaseCommandStatsBadRequest: + response := err.(*online.GetDatabaseCommandStatsBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err } fmt.Println() @@ -121,16 +130,23 @@ func CommandStats(clientInstance *client.AdabasAdmin, dbid int, auth runtime.Cli fmt.Printf(" %3s %8d\t\t", c.CommandName, c.CommandCount) } fmt.Println() + return nil } // BufferpoolStats buffer pool statistics -func BufferpoolStats(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) { +func BufferpoolStats(clientInstance *client.AdabasAdmin, dbid int, auth runtime.ClientAuthInfoWriter) error { params := online.NewGetDatabaseBPStatsParams() params.Dbid = float64(dbid) resp, err := clientInstance.Online.GetDatabaseBPStats(params, auth) if err != nil { - fmt.Println("Error:", err) - return + switch err.(type) { + case *online.GetDatabaseBPStatsBadRequest: + response := err.(*online.GetDatabaseBPStatsBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err } p := message.NewPrinter(language.English) @@ -165,4 +181,5 @@ func BufferpoolStats(clientInstance *client.AdabasAdmin, dbid int, auth runtime. //fmt.Printf(" Limit Temp.B.( 50%%): %12d\n", 0) //fmt.Printf(" Modified T.B.( 0%%): %12d\n", 0) fmt.Println() + return nil } diff --git a/src/softwareag.com/cmd/filebrowser/file.go b/src/softwareag.com/cmd/filebrowser/file.go new file mode 100644 index 0000000..0fc5878 --- /dev/null +++ b/src/softwareag.com/cmd/filebrowser/file.go @@ -0,0 +1,141 @@ +/* +* Copyright © 2018 Software AG, Darmstadt, Germany and/or its licensors +* +* SPDX-License-Identifier: Apache-2.0 +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +* + */ + +package filebrowser + +import ( + "fmt" + "os" + "strings" + + "github.com/go-openapi/runtime" + "softwareag.com/client" + "softwareag.com/client/browser" +) + +// Locations list all available file location +func Locations(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) error { + params := browser.NewBrowseListParams() + resp, err := clientInstance.Browser.BrowseList(params, auth) + if err != nil { + switch err.(type) { + case *browser.BrowseListBadRequest: + response := err.(*browser.BrowseListBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err + } + fmt.Println() + fmt.Printf(" Name | Location\n") + fmt.Printf("-----------------------------------|----------------------------------------\n") + for _, d := range resp.Payload.Directories.Directory { + fmt.Printf(" %-33s | %s\n", d.Name, d.Location) + } + return nil +} + +// List list the files of an specific file location +func List(clientInstance *client.AdabasAdmin, param string, auth runtime.ClientAuthInfoWriter) error { + params := browser.NewBrowseParams() + if param == "" { + fmt.Printf("Parameter option missing\n") + return fmt.Errorf("Parameter option missing") + } + p := strings.Split(param, ":") + if len(p) != 2 { + fmt.Printf("Invalid parameter option: %s\n", param) + fmt.Printf("Need to be of format: :\n") + return fmt.Errorf("Need to be of format: :") + } + params.Location = p[0] + params.File = p[1] + resp, err := clientInstance.Browser.Browse(params, auth) + if err != nil { + switch err.(type) { + case *browser.BrowseBadRequest: + response := err.(*browser.BrowseBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err + } + fmt.Println() + fmt.Println("Reference : ", resp.Payload.Reference) + fmt.Println("Location : ", resp.Payload.Location) + for _, f := range resp.Payload.Content { + fmt.Printf(" %-20s %-8d %-10s %-10s %-10s\n", f.Name, f.Size, f.Type, f.Modified, f.Created) + } + fmt.Println() + return nil +} + +// Download download a file +func Download(clientInstance *client.AdabasAdmin, param string, input string, auth runtime.ClientAuthInfoWriter) error { + params := browser.NewDownloadFileParams() + p := strings.Split(param, ":") + params.Location = p[0] + params.File = p[1] + file, err := os.OpenFile(input, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + if err != nil { + return err + } + defer file.Close() + _, err = clientInstance.Browser.DownloadFile(params, auth, file) + if err != nil { + switch err.(type) { + case *browser.DownloadFileBadRequest: + response := err.(*browser.DownloadFileBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err + } + return nil +} + +// Upload upload file +func Upload(clientInstance *client.AdabasAdmin, param string, input string, auth runtime.ClientAuthInfoWriter) error { + params := browser.NewUploadFileParams() + p := strings.Split(param, ":") + params.Location = p[0] + params.File = p[1] + file, ferr := os.OpenFile(input, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) + if ferr != nil { + return ferr + } + params.UploadFile = runtime.NamedReader(input, file) + defer file.Close() + resp, err := clientInstance.Browser.UploadFile(params, auth) + if err != nil { + switch err.(type) { + case *browser.UploadFileBadRequest: + response := err.(*browser.UploadFileBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err + } + fmt.Println("Upload ", resp.Payload.Status.Message) + return nil +} diff --git a/src/softwareag.com/cmd/job/jobs.go b/src/softwareag.com/cmd/job/jobs.go index 1130bfc..4bcecf3 100644 --- a/src/softwareag.com/cmd/job/jobs.go +++ b/src/softwareag.com/cmd/job/jobs.go @@ -20,22 +20,30 @@ package job import ( + "encoding/json" "fmt" + "io/ioutil" "strings" - "softwareag.com/client/scheduler" - "github.com/go-openapi/runtime" "softwareag.com/client" + "softwareag.com/client/scheduler" + "softwareag.com/models" ) // List list the jobs -func List(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) { +func List(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) error { params := scheduler.NewGetJobsParams() resp, err := clientInstance.Scheduler.GetJobs(params, auth) if err != nil { - fmt.Println("Error:", err) - return + switch err.(type) { + case *scheduler.GetJobsNotFound: + response := err.(*scheduler.GetJobsNotFound) + fmt.Println(response.Error()) + default: + fmt.Println("Error:", err) + } + return err } fmt.Println() fmt.Printf("Name User Status Description\n") @@ -47,38 +55,118 @@ func List(clientInstance *client.AdabasAdmin, auth runtime.ClientAuthInfoWriter) } } fmt.Println() + return nil } // Start the job -func Start(clientInstance *client.AdabasAdmin, param string, auth runtime.ClientAuthInfoWriter) { +func Start(clientInstance *client.AdabasAdmin, param string, auth runtime.ClientAuthInfoWriter) error { params := scheduler.NewScheduleJobParams() params.JobName = param resp, err := clientInstance.Scheduler.ScheduleJob(params, auth) if err != nil { - fmt.Println("Error:", err) - return + switch err.(type) { + case *scheduler.ScheduleJobBadRequest: + response := err.(*scheduler.ScheduleJobBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err } - fmt.Println() fmt.Printf("Status message : %s\n", resp.Payload.Status.Message) fmt.Printf("Job Name : %s\n", resp.Payload.Status.Name) fmt.Printf("Execution ID : %d\n", resp.Payload.Status.ExecutionID) fmt.Println() + return nil +} + +// Delete the job +func Delete(clientInstance *client.AdabasAdmin, param string, auth runtime.ClientAuthInfoWriter) error { + params := scheduler.NewDeleteJobParams() + params.JobName = param + resp, err := clientInstance.Scheduler.DeleteJob(params, auth) + if err != nil { + switch err.(type) { + case *scheduler.DeleteJobBadRequest: + response := err.(*scheduler.DeleteJobBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err + } + fmt.Println() + fmt.Printf("Status message : %s\n", resp.Payload.Status.Message) + fmt.Println() + return nil +} + +// DeleteExecution Delete the execution log of a job +func DeleteExecution(clientInstance *client.AdabasAdmin, param string, auth runtime.ClientAuthInfoWriter) error { + params := scheduler.NewDeleteJobResultParams() + p := strings.Split(param, ":") + params.JobName = p[0] + params.JobID = p[1] + resp, err := clientInstance.Scheduler.DeleteJobResult(params, auth) + if err != nil { + switch err.(type) { + case *scheduler.DeleteJobResultBadRequest: + response := err.(*scheduler.DeleteJobResultBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err + } + fmt.Println() + fmt.Printf("Status message : %s\n", resp.Payload.Status.Message) + fmt.Println() + return nil +} + +// Create nre job using job definition file +func Create(clientInstance *client.AdabasAdmin, input string, auth runtime.ClientAuthInfoWriter) error { + params := scheduler.NewPostJobParams() + raw, err := ioutil.ReadFile(input) + if err != nil { + fmt.Println(err.Error()) + return err + } + + job := &models.JobParameter{} + if err := json.Unmarshal(raw, job); err != nil { + return err + } + params.Job = job + resp, err := clientInstance.Scheduler.PostJob(params, auth) + if err != nil { + switch err.(type) { + case *scheduler.PostJobBadRequest: + response := err.(*scheduler.PostJobBadRequest) + fmt.Println(response.Payload.Error.Code, ":", response.Payload.Error.Message) + default: + fmt.Println("Error:", err) + } + return err + } + fmt.Println(resp.Payload.Status.Message) + return nil } // Log output -func Log(clientInstance *client.AdabasAdmin, param string, auth runtime.ClientAuthInfoWriter) { +func Log(clientInstance *client.AdabasAdmin, param string, auth runtime.ClientAuthInfoWriter) error { params := scheduler.NewGetJobResultParams() v := strings.Split(param, ":") params.JobName = v[0] if len(v) != 2 { fmt.Printf("Parameter should be of form: :\n") - return + return fmt.Errorf("Parameter should be of form: :") } params.JobID = v[1] resp, err := clientInstance.Scheduler.GetJobResult(params, auth) if err != nil { fmt.Println("Error:", err) - return + return err } fmt.Println() fmt.Printf("JOB name : %s\n", resp.Payload.JobResult.Name) @@ -87,4 +175,5 @@ func Log(clientInstance *client.AdabasAdmin, param string, auth runtime.ClientAu fmt.Printf("JOB ended : %s\n", resp.Payload.JobResult.Ended) fmt.Printf("Output started -------:\n %s\nOutput ended -------\n", resp.Payload.JobResult.Log) fmt.Println() + return nil } diff --git a/swagger/aif-swagger.yaml b/swagger/aif-swagger.yaml index 75a7b71..d5f76e6 100644 --- a/swagger/aif-swagger.yaml +++ b/swagger/aif-swagger.yaml @@ -1,7 +1,7 @@ swagger: '2.0' info: description: Adabas Administration - version: 6.7.0.0.20092018 + version: 6.7.0.0.06112018 title: Adabas Administration contact: name: Software AG Support @@ -324,6 +324,7 @@ paths: - application/json parameters: - $ref: '#/parameters/dbidParam' + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with database GCB' @@ -414,6 +415,7 @@ paths: - application/json parameters: - $ref: '#/parameters/dbidParam' + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with database user queue entries' @@ -429,7 +431,7 @@ paths: get: tags: - Online - description: Stop the User Queue element + description: Provide User queue details of an specific user queue element operationId: getUserQueueDetail security: - BasicAuth: [] @@ -444,13 +446,14 @@ paths: description: User Queue ID required: true type: number + - $ref: '#/parameters/rfc3339Param' responses: '200': - description: 'Successful response, a User queue is stopped' + description: 'Successful response, a User queue detailed are received' schema: $ref: '#/definitions/UserQueueDetail' '400': - description: Error stopping the database user queue entry + description: Error finding user queue entry schema: $ref: '#/definitions/Error' '401': @@ -496,6 +499,7 @@ paths: - application/json parameters: - $ref: '#/parameters/dbidParam' + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with database command queue entries' @@ -519,6 +523,7 @@ paths: - application/json parameters: - $ref: '#/parameters/dbidParam' + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with database hold queue entries' @@ -834,6 +839,7 @@ paths: - application/json parameters: - $ref: '#/parameters/dbidParam' + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with Adabas High Water Mark statistics' @@ -1038,6 +1044,7 @@ paths: description: Used for operation renumber required: false type: number + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with a FCB representation of the Adabas FCB' @@ -1180,6 +1187,7 @@ paths: refresh renumber required: true type: number + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with a FCB representation of the Adabas FCB' @@ -1259,6 +1267,7 @@ paths: - application/json parameters: - $ref: '#/parameters/dbidParam' + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with a list of UCB entries' @@ -1435,6 +1444,36 @@ paths: description: Authorization error '404': description: Error creating Adabas database + delete: + tags: + - Scheduler + description: Delete a job definition + operationId: deleteJob + security: + - BasicAuth: [] + consumes: + - application/json + produces: + - application/json + parameters: + - name: jobName + in: path + description: Job Name to be requested + required: true + type: string + responses: + '200': + description: 'Successfully delete the job.' + schema: + $ref: '#/definitions/JobStatusResponse' + '400': + description: Environment evaluation error + schema: + $ref: '#/definitions/Error' + '401': + description: Authorization error + '404': + description: Job not available/unknown '/scheduler/job/{jobName}/full': get: tags: @@ -1484,6 +1523,7 @@ paths: description: Job name to be requested required: true type: string + - $ref: '#/parameters/rfc3339Param' responses: '200': description: 'Successful response, with list of known databases.' @@ -1559,7 +1599,7 @@ paths: '200': description: 'Successful response, job result is deleted.' schema: - $ref: '#/definitions/StatusResponse' + $ref: '#/definitions/JobStatusResponse' '400': description: Environment evaluation error schema: @@ -1625,7 +1665,7 @@ paths: get: tags: - Browser - description: Retrieves a list of databases known by Adabas Interface. + description: Download a file out of file location operationId: downloadFile security: - BasicAuth: [] @@ -1680,10 +1720,15 @@ paths: security: - BasicAuth: [] consumes: - - application/octet-stream + - multipart/form-data parameters: - $ref: '#/parameters/locationParam' - $ref: '#/parameters/fileReferenceParam' + - name: uploadFile + in: formData + description: Upload file + required: true + type: file responses: '200': description: 'Successful response, with download binary file.' @@ -1747,6 +1792,12 @@ parameters: description: File number required: true type: number + rfc3339Param: + name: rfc3339 + in: query + description: Return time format in RFC3339 + required: false + type: boolean definitions: Environments: type: object @@ -2053,6 +2104,7 @@ definitions: type: integer Date: type: string + format: date-time Name: type: string Dbid: @@ -2103,8 +2155,10 @@ definitions: type: integer TimeStampReplication: type: string + format: date-time TimeStampLog: type: string + format: date-time WORKExtents: type: object properties: @@ -2162,10 +2216,13 @@ definitions: $ref: '#/definitions/UserQueueEntry' StartSession: type: string + format: date-time StartTransaction: type: string + format: date-time LastActivity: type: string + format: date-time TTLimit: type: integer TNALimit: @@ -2208,6 +2265,7 @@ definitions: type: string Timestamp: type: string + format: date-time CommandQueue: type: object properties: @@ -2246,7 +2304,7 @@ definitions: HoldQueue: type: object properties: - HoldQueueEntry: + HoldQueue: type: array items: $ref: '#/definitions/HoldQueueEntry' @@ -2256,7 +2314,9 @@ definitions: User: type: string Hid: - $ref: '#/definitions/UserInformation' + type: array + items: + $ref: '#/definitions/UserInformation' HqCommid: type: integer File: @@ -2644,6 +2704,7 @@ definitions: $ref: '#/definitions/HighWaterEntries' NucleusStartTime: type: string + format: date-time HighWaterEntries: type: object properties: @@ -2655,6 +2716,7 @@ definitions: x-isnullable: false time: type: string + format: date-time x-isnullable: false required: - inuse @@ -2769,6 +2831,7 @@ definitions: properties: Time: type: string + format: date-time Fields: type: array items: @@ -2877,10 +2940,13 @@ definitions: type: string Utility: type: string - Parameter: + Parameters: type: array items: - type: string + type: object + properties: + Parameter: + type: string Environment: type: array items: @@ -2908,8 +2974,10 @@ definitions: type: string Scheduled: type: string + format: date-time Ended: type: string + format: date-time Status: type: string StartedBy: @@ -2997,11 +3065,13 @@ definitions: Name: type: string Size: - type: string + type: integer Created: type: string + format: data-time Modified: type: string + format: date-time Type: type: string Executions: @@ -3013,8 +3083,10 @@ definitions: type: integer Scheduled: type: string + format: date-time Ended: type: string + format: date-time Log: type: string ExitCode: @@ -3036,6 +3108,7 @@ definitions: properties: Date: type: string + format: date-time Sequence: type: integer Id: diff --git a/templates/create-job-bck.json b/templates/create-job-bck.json new file mode 100644 index 0000000..fbc21a0 --- /dev/null +++ b/templates/create-job-bck.json @@ -0,0 +1 @@ +{"Job":{"User":"RTK","Name":"goadminbackup","Description":"GO Administration test creating job","Utility":"ADABCK","Scripts":"","Parameters":[{"Parameter":"db=24"}, {"Parameter":"dump=*"}],"Environments":[],"CronScheduler":"(null)"}} diff --git a/templates/create-job.json b/templates/create-job.json new file mode 100644 index 0000000..ae4cbce --- /dev/null +++ b/templates/create-job.json @@ -0,0 +1 @@ +{"Job":{"User":"RTK","Name":"goadmintest","Description":"GO Administration test creating job","Utility":"ADAOPR","Scripts":"","Parameters":[{"Parameter":"db=24"}, {"Parameter":"disp=cq"}],"Environments":[],"CronScheduler":"(null)"}}