Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
thknieling committed Dec 6, 2018
2 parents c741965 + d0f1bbc commit d52aa4d
Show file tree
Hide file tree
Showing 13 changed files with 632 additions and 227 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.

Expand Down Expand Up @@ -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 <package>` command. The `startAdmin.sh` script provides all help descriptions entering the `help` command.

Expand Down
239 changes: 142 additions & 97 deletions src/softwareag.com/cmd/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -81,11 +80,18 @@ const (
checkpoints
joblist
jobstart
deletejob
deletejobexec
createjob
joblog
listucb
deleteucb
addfields
status
filelocations
listfiles
downloadfile
uploadfile
)

const (
Expand Down Expand Up @@ -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++ {
Expand Down Expand Up @@ -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")

Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit d52aa4d

Please sign in to comment.