summaryrefslogtreecommitdiffstats
path: root/client/go/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'client/go/src/cmd')
-rw-r--r--client/go/src/cmd/command_tester.go55
-rw-r--r--client/go/src/cmd/config.go63
-rw-r--r--client/go/src/cmd/deploy.go189
-rw-r--r--client/go/src/cmd/deploy_test.go56
-rw-r--r--client/go/src/cmd/document.go94
-rw-r--r--client/go/src/cmd/document_test.go30
-rw-r--r--client/go/src/cmd/init.go157
-rw-r--r--client/go/src/cmd/init_test.go32
-rw-r--r--client/go/src/cmd/query.go78
-rw-r--r--client/go/src/cmd/query_test.go37
-rw-r--r--client/go/src/cmd/root.go34
-rw-r--r--client/go/src/cmd/status.go59
-rw-r--r--client/go/src/cmd/status_test.go70
-rw-r--r--client/go/src/cmd/target.go60
-rw-r--r--client/go/src/cmd/testdata/A-Head-Full-of-Dreams.json14
-rw-r--r--client/go/src/cmd/testdata/application.zipbin2305 -> 0 bytes
-rw-r--r--client/go/src/cmd/testdata/sample-apps-master.zipbin4253469 -> 0 bytes
-rw-r--r--client/go/src/cmd/testdata/src/main/application/hosts.xml8
-rw-r--r--client/go/src/cmd/testdata/src/main/application/schemas/msmarco.sd299
-rw-r--r--client/go/src/cmd/testdata/src/main/application/services.xml61
20 files changed, 0 insertions, 1396 deletions
diff --git a/client/go/src/cmd/command_tester.go b/client/go/src/cmd/command_tester.go
deleted file mode 100644
index d7899c51436..00000000000
--- a/client/go/src/cmd/command_tester.go
+++ /dev/null
@@ -1,55 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// A helper for testing commands
-// Author: bratseth
-
-package cmd
-
-import (
- "bytes"
- "github.com/vespa-engine/vespa/utils"
- "github.com/stretchr/testify/assert"
- "io/ioutil"
- "net/http"
- "testing"
- "time"
-)
-
-func executeCommand(t *testing.T, client *mockHttpClient, args []string, moreArgs []string) (standardout string) {
- utils.ActiveHttpClient = client
-
- // Reset - persistent flags in Cobra persists over tests
- rootCmd.SetArgs([]string{"status", "-t", ""})
- rootCmd.Execute()
-
- b := bytes.NewBufferString("")
- utils.Out = b
- rootCmd.SetArgs(append(args, moreArgs...))
- rootCmd.Execute()
- out, err := ioutil.ReadAll(b)
- assert.Empty(t, err, "No error")
- return string(out)
-}
-
-type mockHttpClient struct {
- // The HTTP status code that will be returned from the next invocation. Default: 200
- nextStatus int
-
- // The response body code that will be returned from the next invocation. Default: ""
- nextBody string
-
- // A recording of the last HTTP request made through this
- lastRequest *http.Request
-}
-
-func (c *mockHttpClient) Do(request *http.Request, timeout time.Duration) (response *http.Response, error error) {
- if c.nextStatus == 0 {
- c.nextStatus = 200
- }
- c.lastRequest = request
- return &http.Response{
- StatusCode: c.nextStatus,
- Body: ioutil.NopCloser(bytes.NewBufferString(c.nextBody)),
- Header: make(http.Header),
- },
- nil
-}
diff --git a/client/go/src/cmd/config.go b/client/go/src/cmd/config.go
deleted file mode 100644
index 647d13939b1..00000000000
--- a/client/go/src/cmd/config.go
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// vespa config command
-// author: bratseth
-
-package cmd
-
-import (
- "github.com/spf13/cobra"
- "github.com/spf13/viper"
- "github.com/vespa-engine/vespa/utils"
- "os"
- "path/filepath"
-)
-
-func init() {
- rootCmd.AddCommand(configCmd)
-}
-
-var configCmd = &cobra.Command{
- Use: "config",
- Short: "Configure the Vespa command",
- Long: `TODO`,
- Run: func(cmd *cobra.Command, args []string) {
- },
-}
-
-func readConfig() {
- home, err := os.UserHomeDir()
- configName := ".vespa"
- configType := "yaml"
-
- cobra.CheckErr(err)
- viper.AddConfigPath(home)
- viper.SetConfigType(configType)
- viper.SetConfigName(configName)
- viper.AutomaticEnv()
-
- viper.ReadInConfig();
-}
-
-// WIP: Not used yet
-func writeConfig() {
- //viper.BindPFlag("container-target", rootCmd.PersistentFlags().Lookup("container-target"))
- //viper.SetDefault("container-target", "http://127.0.0.1:8080")
-
- home, _ := os.UserHomeDir()
- configName := ".vespa"
- configType := "yaml"
-
- // Viper bug: WriteConfig() will not create the file if missing
- configPath := filepath.Join(home, configName + "." + configType)
- _, statErr := os.Stat(configPath)
- if !os.IsExist(statErr) {
- if _, createErr := os.Create(configPath); createErr != nil {
- utils.Error("Warning: Can not remember flag parameters: " + createErr.Error())
- }
- }
-
- writeErr := viper.WriteConfig()
- if writeErr != nil {
- utils.Error("Could not write config:", writeErr.Error())
- }
-} \ No newline at end of file
diff --git a/client/go/src/cmd/deploy.go b/client/go/src/cmd/deploy.go
deleted file mode 100644
index 9e6940179da..00000000000
--- a/client/go/src/cmd/deploy.go
+++ /dev/null
@@ -1,189 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// vespa deploy command
-// Author: bratseth
-
-package cmd
-
-import (
- "archive/zip"
- "errors"
- "github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/utils"
- "io"
- "io/ioutil"
- "net/http"
- "net/url"
- "os"
- "path/filepath"
- "strings"
- "time"
-)
-
-func init() {
- rootCmd.AddCommand(deployCmd)
- deployCmd.AddCommand(deployPrepareCmd)
- deployCmd.AddCommand(deployActivateCmd)
-}
-
-var deployCmd = &cobra.Command{
- Use: "deploy",
- Short: "Deploys an application package",
- Long: `TODO: Use prepare or deploy activate`,
- Run: func(cmd *cobra.Command, args []string) {
- utils.Error("Use either deploy prepare or deploy activate")
- },
-}
-
-var deployPrepareCmd = &cobra.Command{
- Use: "prepare",
- Short: "Prepares an application for activation",
- Long: `TODO: prepare application-package-dir OR application.zip`,
- Args: func(cmd *cobra.Command, args []string) error {
- if len(args) > 1 {
- return errors.New("Expected an application package as the only argument")
- }
- return nil
- },
- Run: func(cmd *cobra.Command, args []string) {
- if len(args) == 0 {
- deploy(true, "src/main/application")
- } else {
- deploy(true, args[0])
- }
- },
-}
-
-var deployActivateCmd = &cobra.Command{
- Use: "activate",
- Short: "Activates an application package. If no package argument, the previously prepared package is activated.",
- Long: `TODO: activate [application-package-dir OR application.zip]`,
- Args: func(cmd *cobra.Command, args []string) error {
- if len(args) > 1 {
- return errors.New("Expected an application package as the only argument")
- }
- return nil
- },
- Run: func(cmd *cobra.Command, args []string) {
- if len(args) == 0 {
- deploy(false, "")
- } else {
- deploy(false, args[0])
- }
- },
-}
-
-func deploy(prepare bool, application string) {
- // TODO: Support no application (activate)
- // TODO: Support application home as argument instead of src/main and
- // - if target exists, use target/application.zip
- // - else if src/main/application exists, use that
- // - else if current dir has services.xml use that
- if filepath.Ext(application) != ".zip" {
- tempZip, error := ioutil.TempFile("", "application.zip")
- if error != nil {
- utils.Error("Could not create a temporary zip file for the application package")
- utils.Detail(error.Error())
- return
- }
-
- error = zipDir(application, tempZip.Name())
- if (error != nil) {
- utils.Error(error.Error())
- return
- }
- defer os.Remove(tempZip.Name())
- application = tempZip.Name()
- }
-
- zipFileReader, zipFileError := os.Open(application)
- if zipFileError != nil {
- utils.Error("Could not open application package at " + application)
- utils.Detail(zipFileError.Error())
- return
- }
-
- var deployUrl *url.URL
- if prepare {
- deployUrl, _ = url.Parse(getTarget(deployContext).deploy + "/application/v2/tenant/default/prepare")
- } else if application == "" {
- deployUrl, _ = url.Parse(getTarget(deployContext).deploy + "/application/v2/tenant/default/activate")
- } else {
- deployUrl, _ = url.Parse(getTarget(deployContext).deploy + "/application/v2/tenant/default/prepareandactivate")
- }
-
- header := http.Header{}
- header.Add("Content-Type", "application/zip")
- request := &http.Request{
- URL: deployUrl,
- Method: "POST",
- Header: header,
- Body: ioutil.NopCloser(zipFileReader),
- }
- serviceDescription := "Deploy service"
- response := utils.HttpDo(request, time.Minute * 10, serviceDescription)
- defer response.Body.Close()
- if (response == nil) {
- return
- } else if response.StatusCode == 200 {
- utils.Success("Success")
- } else if response.StatusCode % 100 == 4 {
- utils.Error("Invalid application package")
- // TODO: Output error in body
- } else {
- utils.Error("Error from", strings.ToLower(serviceDescription), "at", request.URL.Host)
- utils.Detail("Response status:", response.Status)
- }
-}
-
-func zipDir(dir string, destination string) error {
- if filepath.IsAbs(dir) {
- message := "Path must be relative, but '" + dir + "'"
- return errors.New(message)
- }
- if ! utils.PathExists(dir) {
- message := "'" + dir + "' should be an application package zip or dir, but does not exist"
- return errors.New(message)
- }
- if ! utils.IsDirectory(dir) {
- message := "'" + dir + "' should be an application package dir, but is a (non-zip) file"
- return errors.New(message)
- }
-
- file, err := os.Create(destination)
- if err != nil {
- message := "Could not create a temporary zip file for the application package: " + err.Error()
- return errors.New(message)
- }
- defer file.Close()
-
- w := zip.NewWriter(file)
- defer w.Close()
-
- walker := func(path string, info os.FileInfo, err error) error {
- if err != nil {
- return err
- }
- if info.IsDir() {
- return nil
- }
- file, err := os.Open(path)
- if err != nil {
- return err
- }
- defer file.Close()
-
- zippath := strings.TrimPrefix(path, dir)
- zipfile, err := w.Create(zippath)
- if err != nil {
- return err
- }
-
- _, err = io.Copy(zipfile, file)
- if err != nil {
- return err
- }
- return nil
- }
- return filepath.Walk(dir, walker)
-}
-
diff --git a/client/go/src/cmd/deploy_test.go b/client/go/src/cmd/deploy_test.go
deleted file mode 100644
index 99cfedebc8f..00000000000
--- a/client/go/src/cmd/deploy_test.go
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// deploy command tests
-// Author: bratseth
-
-package cmd
-
-import (
- "github.com/stretchr/testify/assert"
- "testing"
-)
-
-func TestDeployZip(t *testing.T) {
- client := &mockHttpClient{}
- assert.Equal(t,
- "\x1b[32mSuccess\n",
- executeCommand(t, client, []string{"deploy", "activate", "testdata/application.zip"}, []string{}))
- assertDeployRequestMade("http://127.0.0.1:19071", client, t)
-}
-
-func TestDeployZipWithURLTargetArgument(t *testing.T) {
- client := &mockHttpClient{}
- assert.Equal(t,
- "\x1b[32mSuccess\n",
- executeCommand(t, client, []string{"deploy", "activate", "testdata/application.zip", "-t", "http://target:19071"}, []string{}))
- assertDeployRequestMade("http://target:19071", client, t)
-}
-
-func TestDeployZipWitLocalTargetArgument(t *testing.T) {
- client := &mockHttpClient{}
- assert.Equal(t,
- "\x1b[32mSuccess\n",
- executeCommand(t, client, []string{"deploy", "activate", "testdata/application.zip", "-t", "local"}, []string{}))
- assertDeployRequestMade("http://127.0.0.1:19071", client, t)
-}
-
-func TestDeployDirectory(t *testing.T) {
- client := &mockHttpClient{}
- assert.Equal(t,
- "\x1b[32mSuccess\n",
- executeCommand(t, client, []string{"deploy", "activate", "testdata/src/main/application"}, []string{}))
- assertDeployRequestMade("http://127.0.0.1:19071", client, t)
-}
-
-// TODO: Test error replies (5xx and 4xx with error message)
-// TODO: Test prepare and activate prepared
-
-func assertDeployRequestMade(target string, client *mockHttpClient, t *testing.T) {
- assert.Equal(t, target + "/application/v2/tenant/default/prepareandactivate", client.lastRequest.URL.String())
- assert.Equal(t, "application/zip", client.lastRequest.Header.Get("Content-Type"))
- assert.Equal(t, "POST", client.lastRequest.Method)
- var body = client.lastRequest.Body
- assert.NotNil(t, body)
- buf := make([]byte, 7) // Just check the first few bytes
- body.Read(buf)
- assert.Equal(t, "PK\x03\x04\x14\x00\b", string(buf))
-} \ No newline at end of file
diff --git a/client/go/src/cmd/document.go b/client/go/src/cmd/document.go
deleted file mode 100644
index 4e54e3fcb33..00000000000
--- a/client/go/src/cmd/document.go
+++ /dev/null
@@ -1,94 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// vespa document command
-// author: bratseth
-
-package cmd
-
-import (
- "github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/utils"
- "io/ioutil"
- "net/http"
- "net/url"
- "os"
- "strings"
- "time"
-)
-
-func init() {
- rootCmd.AddCommand(documentCmd)
- statusCmd.AddCommand(documentPutCmd)
- statusCmd.AddCommand(documentGetCmd)
-}
-
-var documentCmd = &cobra.Command{
- Use: "document",
- Short: "Issue document operations (put by default)",
- Long: `TODO: Example mynamespace/mydocumenttype/myid document.json`,
- // TODO: Check args
- Run: func(cmd *cobra.Command, args []string) {
- put(args[0], args[1])
- },
-}
-
-var documentPutCmd = &cobra.Command{
- Use: "put mynamespace/mydocumenttype/myid mydocument.json",
- Short: "Puts the document in the given file",
- Long: `TODO`,
- // TODO: This crashes with the above
- // TODO: Extract document id from the content
- // TODO: Check args
- Run: func(cmd *cobra.Command, args []string) {
- put(args[0], args[1])
- },
-}
-
-var documentGetCmd = &cobra.Command{
- Use: "get documentId",
- Short: "Gets a document",
- Long: `TODO`,
- // TODO: Check args
- Run: func(cmd *cobra.Command, args []string) {
- get(args[0])
- },
-}
-
-func get(documentId string) {
- // TODO
-}
-
-func put(documentId string, jsonFile string) {
- url, _ := url.Parse(getTarget(documentContext).document + "/document/v1/" + documentId)
-
- header := http.Header{}
- header.Add("Content-Type", "application/json")
-
- fileReader, fileError := os.Open(jsonFile)
- if fileError != nil {
- utils.Error("Could not open file at " + jsonFile)
- utils.Detail(fileError.Error())
- return
- }
-
- request := &http.Request{
- URL: url,
- Method: "POST",
- Header: header,
- Body: ioutil.NopCloser(fileReader),
- }
- serviceDescription := "Container (document/v1 API)"
- response := utils.HttpDo(request, time.Second * 60, serviceDescription)
- defer response.Body.Close()
- if (response == nil) {
- return
- } else if response.StatusCode == 200 {
- utils.Success("Success") // TODO: Change to something including document id
- } else if response.StatusCode % 100 == 4 {
- utils.Error("Invalid document")
- utils.Detail(response.Status)
- // TODO: Output error in body
- } else {
- utils.Error("Error from", strings.ToLower(serviceDescription), "at", request.URL.Host)
- utils.Detail("Response status:", response.Status)
- }
-} \ No newline at end of file
diff --git a/client/go/src/cmd/document_test.go b/client/go/src/cmd/document_test.go
deleted file mode 100644
index 7e9af0ab921..00000000000
--- a/client/go/src/cmd/document_test.go
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// document command tests
-// Author: bratseth
-
-package cmd
-
-import (
- "github.com/stretchr/testify/assert"
- "github.com/vespa-engine/vespa/utils"
- "io/ioutil"
- "testing"
-)
-
-func TestDocumentPut(t *testing.T) {
- assertDocumentPut("mynamespace/music/docid/1", "testdata/A-Head-Full-of-Dreams.json", t)
-}
-
-func assertDocumentPut(documentId string, jsonFile string, t *testing.T) {
- client := &mockHttpClient{}
- assert.Equal(t,
- "\x1b[32mSuccess\n",
- executeCommand(t, client, []string{"document", documentId, jsonFile}, []string{}))
- target := getTarget(documentContext).document
- assert.Equal(t, target + "/document/v1/" + documentId, client.lastRequest.URL.String())
- assert.Equal(t, "application/json", client.lastRequest.Header.Get("Content-Type"))
- assert.Equal(t, "POST", client.lastRequest.Method)
-
- fileContent, _ := ioutil.ReadFile(jsonFile)
- assert.Equal(t, string(fileContent), utils.ReaderToString(client.lastRequest.Body))
-}
diff --git a/client/go/src/cmd/init.go b/client/go/src/cmd/init.go
deleted file mode 100644
index 7a5a7729246..00000000000
--- a/client/go/src/cmd/init.go
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// vespa init command
-// author: bratseth
-
-package cmd
-
-import (
- "archive/zip"
- "errors"
- "path/filepath"
- "github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/utils"
- "io"
- "io/ioutil"
- "net/http"
- "net/url"
- "os"
- "strings"
- "time"
-)
-
-// Set this to test without downloading this file from github
-var existingSampleAppsZip string
-
-func init() {
- existingSampleAppsZip = ""
- rootCmd.AddCommand(initCmd)
-}
-
-var initCmd = &cobra.Command{
- // TODO: "application" and "list" subcommands?
- Use: "init",
- Short: "Creates the files and directory structure for a new Vespa application",
- Long: `TODO: vespa init applicationName source`,
- Args: func(cmd *cobra.Command, args []string) error {
- if len(args) != 2 {
- return errors.New("vespa init requires a project name and source")
- }
- return nil
- },
- Run: func(cmd *cobra.Command, args []string) {
- initApplication(args[0], args[1])
- },
-}
-
-func initApplication(name string, source string) {
- zipFile := getSampleAppsZip()
- if zipFile == nil {
- return
- }
- if existingSampleAppsZip == "" { // Indicates we created a temp file now
- defer os.Remove(zipFile.Name())
- }
-
- createErr := os.Mkdir(name, 0755)
- if createErr != nil {
- utils.Error("Could not create directory '" + name + "'")
- utils.Detail(createErr.Error())
- return
- }
-
- zipReader, zipOpenError := zip.OpenReader(zipFile.Name())
- if zipOpenError != nil {
- utils.Error("Could not open sample apps zip '" + zipFile.Name() + "'")
- utils.Detail(zipOpenError.Error())
- }
- defer zipReader.Close()
-
- found := false
- for _, f := range zipReader.File {
- zipEntryPrefix := "sample-apps-master/" + source + "/"
- if strings.HasPrefix(f.Name, zipEntryPrefix) {
- found = true
- copyError := copy(f, name, zipEntryPrefix)
- if copyError != nil {
- utils.Error("Could not copy zip entry '" + f.Name + "' to " + name)
- utils.Detail(copyError.Error())
- return
- }
- }
- }
- if !found {
- utils.Error("Could not find source application '" + source + "'")
- } else {
- utils.Success("Created " + name)
- }
-}
-
-func getSampleAppsZip() *os.File {
- if existingSampleAppsZip != "" {
- existing, openExistingError := os.Open(existingSampleAppsZip)
- if openExistingError != nil {
- utils.Error("Could not open existing sample apps zip file '" + existingSampleAppsZip + "'")
- utils.Detail(openExistingError.Error())
- }
- return existing
- }
-
- // TODO: Cache it?
- utils.Detail("Downloading sample apps ...") // TODO: Spawn thread to indicate progress
- zipUrl, _ := url.Parse("https://github.com/vespa-engine/sample-apps/archive/refs/heads/master.zip")
- request := &http.Request{
- URL: zipUrl,
- Method: "GET",
- }
- response := utils.HttpDo(request, time.Minute * 60, "GitHub")
- defer response.Body.Close()
- if response.StatusCode != 200 {
- utils.Error("Could not download sample apps from github")
- utils.Detail(response.Status)
- return nil
- }
-
- destination, tempFileError := ioutil.TempFile("", "prefix")
- if tempFileError != nil {
- utils.Error("Could not create a temp file to hold sample apps")
- utils.Detail(tempFileError.Error())
- }
- // destination, _ := os.Create("./" + name + "/sample-apps.zip")
- // defer destination.Close()
- _, err := io.Copy(destination, response.Body)
- if err != nil {
- utils.Error("Could not download sample apps from GitHub")
- utils.Detail(err.Error())
- return nil
- }
- return destination
-}
-
-func copy(f *zip.File, destinationDir string, zipEntryPrefix string) error {
- destinationPath := filepath.Join(destinationDir, filepath.FromSlash(strings.TrimPrefix(f.Name, zipEntryPrefix)))
- if strings.HasSuffix(f.Name, "/") {
- if f.Name != zipEntryPrefix { // root is already created
- createError := os.Mkdir(destinationPath, 0755)
- if createError != nil {
- return createError
- }
- }
- } else {
- zipEntry, zipEntryOpenError := f.Open()
- if zipEntryOpenError != nil {
- return zipEntryOpenError
- }
- defer zipEntry.Close()
-
- destination, createError := os.Create(destinationPath)
- if createError != nil {
- return createError
- }
-
- _, copyError := io.Copy(destination, zipEntry)
- if copyError != nil {
- return copyError
- }
- }
- return nil
-}
diff --git a/client/go/src/cmd/init_test.go b/client/go/src/cmd/init_test.go
deleted file mode 100644
index f0f832293a7..00000000000
--- a/client/go/src/cmd/init_test.go
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// init command tests
-// Author: bratseth
-
-package cmd
-
-import (
- "github.com/vespa-engine/vespa/utils"
- "github.com/stretchr/testify/assert"
- "os"
- "testing"
- "path/filepath"
-)
-
-func TestInit(t *testing.T) {
- assertCreated("mytestapp", "album-recommendation-selfhosted", t)
-}
-
-func assertCreated(app string, sampleAppName string, t *testing.T) {
- existingSampleAppsZip = "testdata/sample-apps-master.zip"
- standardOut := executeCommand(t, &mockHttpClient{}, []string{"init", app, sampleAppName}, []string{})
- defer os.RemoveAll(app)
- assert.Equal(t, "\x1b[32mCreated " + app + "\n", standardOut)
- assert.True(t, utils.PathExists(filepath.Join(app, "README.md")))
- assert.True(t, utils.PathExists(filepath.Join(app, "src", "main", "application")))
- assert.True(t, utils.IsDirectory(filepath.Join(app, "src", "main", "application")))
-
- servicesStat, _ := os.Stat(filepath.Join(app, "src", "main", "application", "services.xml"))
- var servicesSize int64
- servicesSize = 2474
- assert.Equal(t, servicesSize, servicesStat.Size())
-}
diff --git a/client/go/src/cmd/query.go b/client/go/src/cmd/query.go
deleted file mode 100644
index bf678b19f4d..00000000000
--- a/client/go/src/cmd/query.go
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// vespa query command
-// author: bratseth
-
-package cmd
-
-import (
- "bufio"
- "errors"
- "github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/utils"
- "strings"
- "net/http"
- "net/url"
- "time"
-)
-
-func init() {
- rootCmd.AddCommand(queryCmd)
-}
-
-var queryCmd = &cobra.Command{
- Use: "query",
- Short: "Issue a query to Vespa",
- Long: `TODO, example \"yql=select from sources * where title contains 'foo'\" hits=5`,
- // TODO: Support referencing a query json file
- Args: func(cmd *cobra.Command, args []string) error {
- if len(args) < 1 {
- return errors.New("vespa query requires at least one argument containing the query string")
- }
- return nil
- },
- Run: func(cmd *cobra.Command, args []string) {
- query(args)
- },
-}
-
-func query(arguments []string) {
- url, _ := url.Parse(getTarget(queryContext).query + "/search/")
- urlQuery := url.Query()
- for i := 0; i < len(arguments); i++ {
- key, value := splitArg(arguments[i])
- urlQuery.Set(key, value)
- }
- url.RawQuery = urlQuery.Encode()
-
- response := utils.HttpDo(&http.Request{URL: url,}, time.Second * 10, "Container")
- if (response == nil) {
- return
- }
- defer response.Body.Close()
-
- if (response.StatusCode == 200) {
- // TODO: Pretty-print body
- scanner := bufio.NewScanner(response.Body)
- for ;scanner.Scan(); {
- utils.Print(scanner.Text())
- }
- if err := scanner.Err(); err != nil {
- utils.Error(err.Error())
- }
- } else if response.StatusCode % 100 == 4 {
- utils.Error("Invalid query (status ", response.Status, ")")
- utils.Detail()
- } else {
- utils.Error("Request failed")
- utils.Detail(response.Status)
- }
-}
-
-func splitArg(argument string) (string, string) {
- equalsIndex := strings.Index(argument, "=")
- if equalsIndex < 1 {
- return "yql", argument
- } else {
- return argument[0:equalsIndex], argument[equalsIndex + 1:len(argument)]
- }
-}
diff --git a/client/go/src/cmd/query_test.go b/client/go/src/cmd/query_test.go
deleted file mode 100644
index e062e9c718a..00000000000
--- a/client/go/src/cmd/query_test.go
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// query command tests
-// Author: bratseth
-
-package cmd
-
-import (
- "github.com/stretchr/testify/assert"
- "testing"
-)
-
-func TestQuery(t *testing.T) {
- assertQuery(t,
- "?yql=select+from+sources+%2A+where+title+contains+%27foo%27",
- "select from sources * where title contains 'foo'")
-}
-
-func TestQueryWithMultipleParameters(t *testing.T) {
- assertQuery(t,
- "?hits=5&yql=select+from+sources+%2A+where+title+contains+%27foo%27",
- "select from sources * where title contains 'foo'", "hits=5")
-}
-
-func TestQueryWithExplicitYqlParameter(t *testing.T) {
- assertQuery(t,
- "?yql=select+from+sources+%2A+where+title+contains+%27foo%27",
- "yql=select from sources * where title contains 'foo'")
-}
-
-func assertQuery(t *testing.T, expectedQuery string, query ...string) {
- client := &mockHttpClient{ nextBody: "query result", }
- assert.Equal(t,
- "query result\n",
- executeCommand(t, client, []string{"query"}, query),
- "query output")
- assert.Equal(t, getTarget(queryContext).query + "/search/" + expectedQuery, client.lastRequest.URL.String())
-}
diff --git a/client/go/src/cmd/root.go b/client/go/src/cmd/root.go
deleted file mode 100644
index 8f33cb47c43..00000000000
--- a/client/go/src/cmd/root.go
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// Root Cobra command: vespa
-// author: bratseth
-
-package cmd
-
-import (
- "github.com/spf13/cobra"
-)
-
-var (
- // flags
- // TODO: add timeout flag
- // TODO: add flag to show http request made
- targetArgument string
-
- rootCmd = &cobra.Command{
- Use: "vespa",
- Short: "A command-line tool for working with Vespa instances",
- Long: `TO
-DO`,
- }
-)
-
-func init() {
- cobra.OnInitialize(readConfig)
- rootCmd.PersistentFlags().StringVarP(&targetArgument, "target", "t", "local", "The name or URL of the recipient of this command")
-}
-
-// Execute executes the root command.
-func Execute() error {
- err := rootCmd.Execute()
- return err
-}
diff --git a/client/go/src/cmd/status.go b/client/go/src/cmd/status.go
deleted file mode 100644
index 809b63623ae..00000000000
--- a/client/go/src/cmd/status.go
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// vespa status command
-// author: bratseth
-
-package cmd
-
-import (
- "github.com/spf13/cobra"
- "github.com/vespa-engine/vespa/utils"
-)
-
-func init() {
- rootCmd.AddCommand(statusCmd)
- statusCmd.AddCommand(statusContainerCmd)
- statusCmd.AddCommand(statusConfigServerCmd)
-}
-
-var statusCmd = &cobra.Command{
- Use: "status",
- Short: "Verifies that a vespa target is ready to use (container by default)",
- Long: `TODO`,
- Run: func(cmd *cobra.Command, args []string) {
- status(getTarget(queryContext).query, "Container")
- },
-}
-
-var statusContainerCmd = &cobra.Command{
- Use: "container",
- Short: "Verifies that your Vespa container endpoint is ready [Default]",
- Long: `TODO`,
- Run: func(cmd *cobra.Command, args []string) {
- status(getTarget(queryContext).query, "Container")
- },
-}
-
-var statusConfigServerCmd = &cobra.Command{
- Use: "config-server",
- Short: "Verifies that your Vespa config server endpoint is ready",
- Long: `TODO`,
- Run: func(cmd *cobra.Command, args []string) {
- status(getTarget(deployContext).deploy, "Config server")
- },
-}
-
-func status(target string, description string) {
- path := "/ApplicationStatus"
- response := utils.HttpGet(target, path, description)
- if (response == nil) {
- return
- }
- defer response.Body.Close()
-
- if response.StatusCode != 200 {
- utils.Error(description, "at", target, "is not ready")
- utils.Detail("Response status:", response.Status)
- } else {
- utils.Success(description, "at", target, "is ready")
- }
-}
diff --git a/client/go/src/cmd/status_test.go b/client/go/src/cmd/status_test.go
deleted file mode 100644
index 70fb33c27de..00000000000
--- a/client/go/src/cmd/status_test.go
+++ /dev/null
@@ -1,70 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// status command tests
-// Author: bratseth
-
-package cmd
-
-import (
- "github.com/stretchr/testify/assert"
- "testing"
-)
-
-func TestStatusConfigServerCommand(t *testing.T) {
- assertConfigServerStatus("http://127.0.0.1:19071", []string{}, t)
-}
-
-func TestStatusConfigServerCommandWithURLTarget(t *testing.T) {
- assertConfigServerStatus("http://mydeploytarget", []string{"-t", "http://mydeploytarget"}, t)
-}
-
-func TestStatusConfigServerCommandWithLocalTarget(t *testing.T) {
- assertConfigServerStatus("http://127.0.0.1:19071", []string{"-t", "local"}, t)
-}
-
-func TestStatusContainerCommand(t *testing.T) {
- assertContainerStatus("http://127.0.0.1:8080", []string{}, t)
-}
-
-func TestStatusContainerCommandWithUrlTarget(t *testing.T) {
- assertContainerStatus("http://mycontainertarget", []string{"-t", "http://mycontainertarget"}, t)
-}
-
-func TestStatusContainerCommandWithLocalTarget(t *testing.T) {
- assertContainerStatus("http://127.0.0.1:8080", []string{"-t", "local"}, t)
-}
-
-func TestStatusErrorResponse(t *testing.T) {
- assertContainerError("http://127.0.0.1:8080", []string{}, t)
-}
-
-func assertConfigServerStatus(target string, args []string, t *testing.T) {
- client := &mockHttpClient{}
- assert.Equal(t,
- "\x1b[32mConfig server at " + target + " is ready\n",
- executeCommand(t, client, []string{"status", "config-server"}, args),
- "vespa status config-server")
- assert.Equal(t, target + "/ApplicationStatus", client.lastRequest.URL.String())
-}
-
-func assertContainerStatus(target string, args []string, t *testing.T) {
- client := &mockHttpClient{}
- assert.Equal(t,
- "\x1b[32mContainer at " + target + " is ready\n",
- executeCommand(t, client, []string{"status", "container"}, args),
- "vespa status container")
- assert.Equal(t, target + "/ApplicationStatus", client.lastRequest.URL.String())
-
- assert.Equal(t,
- "\x1b[32mContainer at " + target + " is ready\n",
- executeCommand(t, client, []string{"status"}, args),
- "vespa status (the default)")
- assert.Equal(t, target + "/ApplicationStatus", client.lastRequest.URL.String())
-}
-
-func assertContainerError(target string, args []string, t *testing.T) {
- client := &mockHttpClient{ nextStatus: 500,}
- assert.Equal(t,
- "\x1b[31mContainer at " + target + " is not ready\n\x1b[33mResponse status: \n",
- executeCommand(t, client, []string{"status", "container"}, args),
- "vespa status container")
-} \ No newline at end of file
diff --git a/client/go/src/cmd/target.go b/client/go/src/cmd/target.go
deleted file mode 100644
index 1d56c39540a..00000000000
--- a/client/go/src/cmd/target.go
+++ /dev/null
@@ -1,60 +0,0 @@
-// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-// Models a target for Vespa commands
-// author: bratseth
-
-package cmd
-
-import (
- "github.com/vespa-engine/vespa/utils"
- "strings"
-)
-
-type target struct {
- deploy string
- query string
- document string
-}
-
-type context int32
-const (
- deployContext context = 0
- queryContext context = 1
- documentContext context = 2
-)
-
-func getTarget(targetContext context) *target {
- if strings.HasPrefix(targetArgument, "http") {
- // TODO: Add default ports if missing
- switch targetContext {
- case deployContext:
- return &target{
- deploy: targetArgument,
- }
- case queryContext:
- return &target{
- query: targetArgument,
- }
- case documentContext:
- return &target{
- document: targetArgument,
- }
- }
- }
-
- // Otherwise, target is a name
-
- if targetArgument == "" || targetArgument == "local" {
- return &target{
- deploy: "http://127.0.0.1:19071",
- query: "http://127.0.0.1:8080",
- document: "http://127.0.0.1:8080",
- }
- }
-
- if targetArgument == "cloud" {
- return nil // TODO
- }
-
- utils.Error("Unknown target argument '" + targetArgument + ": Use 'local', 'cloud' or an URL")
- return nil
-} \ No newline at end of file
diff --git a/client/go/src/cmd/testdata/A-Head-Full-of-Dreams.json b/client/go/src/cmd/testdata/A-Head-Full-of-Dreams.json
deleted file mode 100644
index b68872a961e..00000000000
--- a/client/go/src/cmd/testdata/A-Head-Full-of-Dreams.json
+++ /dev/null
@@ -1,14 +0,0 @@
-{
- "fields": {
- "album": "A Head Full of Dreams",
- "artist": "Coldplay",
- "year": 2015,
- "category_scores": {
- "cells": [
- { "address" : { "cat" : "pop" }, "value": 1 },
- { "address" : { "cat" : "rock" }, "value": 0.2 },
- { "address" : { "cat" : "jazz" }, "value": 0 }
- ]
- }
- }
-}
diff --git a/client/go/src/cmd/testdata/application.zip b/client/go/src/cmd/testdata/application.zip
deleted file mode 100644
index b017db6472d..00000000000
--- a/client/go/src/cmd/testdata/application.zip
+++ /dev/null
Binary files differ
diff --git a/client/go/src/cmd/testdata/sample-apps-master.zip b/client/go/src/cmd/testdata/sample-apps-master.zip
deleted file mode 100644
index 6ad49361072..00000000000
--- a/client/go/src/cmd/testdata/sample-apps-master.zip
+++ /dev/null
Binary files differ
diff --git a/client/go/src/cmd/testdata/src/main/application/hosts.xml b/client/go/src/cmd/testdata/src/main/application/hosts.xml
deleted file mode 100644
index 5dd3ed0dded..00000000000
--- a/client/go/src/cmd/testdata/src/main/application/hosts.xml
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="utf-8" ?>
-<!-- Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
-<hosts>
- <host name="localhost">
- <alias>node1</alias>
- </host>
-</hosts>
-
diff --git a/client/go/src/cmd/testdata/src/main/application/schemas/msmarco.sd b/client/go/src/cmd/testdata/src/main/application/schemas/msmarco.sd
deleted file mode 100644
index 183e1a6421f..00000000000
--- a/client/go/src/cmd/testdata/src/main/application/schemas/msmarco.sd
+++ /dev/null
@@ -1,299 +0,0 @@
-# Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
-
-schema msmarco {
- document msmarco {
-
- field id type string {
- indexing: summary | attribute
- }
-
- field title type string {
- indexing: index | summary
- index: enable-bm25
- stemming: best
- }
-
- field url type string {
- indexing: index | summary
- }
-
- field body type string {
- indexing: index | summary
- index: enable-bm25
- summary: dynamic
- stemming: best
- }
-
- field title_word2vec type tensor<float>(x[500]) {
- indexing: attribute
- }
-
- field body_word2vec type tensor<float>(x[500]) {
- indexing: attribute
- }
-
- field title_gse type tensor<float>(x[512]) {
- indexing: attribute
- }
-
- field body_gse type tensor<float>(x[512]) {
- indexing: attribute
- }
-
- field title_bert type tensor<float>(x[768]) {
- indexing: attribute
- }
-
- field body_bert type tensor<float>(x[768]) {
- indexing: attribute
- }
-
- }
-
- document-summary minimal {
- summary id type string {}
- }
-
- fieldset default {
- fields: title, body
- }
-
- rank-profile default {
- first-phase {
- expression: nativeRank(title, body)
- }
- }
-
- rank-profile bm25 inherits default {
- first-phase {
- expression: bm25(title) + bm25(body)
- }
- }
-
- rank-profile word2vec_title_body_all inherits default {
- function dot_product_title() {
- expression: sum(query(tensor)*attribute(title_word2vec))
- }
- function dot_product_body() {
- expression: sum(query(tensor)*attribute(body_word2vec))
- }
- first-phase {
- expression: dot_product_title() + dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile gse_title_body_all inherits default {
- function dot_product_title() {
- expression: sum(query(tensor_gse)*attribute(title_gse))
- }
- function dot_product_body() {
- expression: sum(query(tensor_gse)*attribute(body_gse))
- }
- first-phase {
- expression: dot_product_title() + dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile bert_title_body_all inherits default {
- function dot_product_title() {
- expression: sum(query(tensor_bert)*attribute(title_bert))
- }
- function dot_product_body() {
- expression: sum(query(tensor_bert)*attribute(body_bert))
- }
- first-phase {
- expression: dot_product_title() + dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile bm25_word2vec_title_body_all inherits default {
- function dot_product_title() {
- expression: sum(query(tensor)*attribute(title_word2vec))
- }
- function dot_product_body() {
- expression: sum(query(tensor)*attribute(body_word2vec))
- }
- first-phase {
- expression: bm25(title) + bm25(body) + dot_product_title() + dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- bm25(title)
- bm25(body)
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile bm25_gse_title_body_all inherits default {
- function dot_product_title() {
- expression: sum(query(tensor_gse)*attribute(title_gse))
- }
- function dot_product_body() {
- expression: sum(query(tensor_gse)*attribute(body_gse))
- }
- first-phase {
- expression: bm25(title) + bm25(body) + dot_product_title() + dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- bm25(title)
- bm25(body)
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile bm25_bert_title_body_all inherits default {
- function dot_product_title() {
- expression: sum(query(tensor_bert)*attribute(title_bert))
- }
- function dot_product_body() {
- expression: sum(query(tensor_bert)*attribute(body_bert))
- }
- first-phase {
- expression: bm25(title) + bm25(body) + dot_product_title() + dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- bm25(title)
- bm25(body)
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile listwise_bm25_bert_title_body_all inherits default {
- function dot_product_title() {
- expression: sum(query(tensor_bert)*attribute(title_bert))
- }
- function dot_product_body() {
- expression: sum(query(tensor_bert)*attribute(body_bert))
- }
- first-phase {
- expression: 0.9005951 * bm25(title) + 2.2043643 * bm25(body) + 0.13506432 * dot_product_title() + 0.5840874 * dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- bm25(title)
- bm25(body)
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile listwise_linear_bm25_gse_title_body_and inherits default {
- function dot_product_title() {
- expression: sum(query(tensor_gse)*attribute(title_gse))
- }
- function dot_product_body() {
- expression: sum(query(tensor_gse)*attribute(body_gse))
- }
- first-phase {
- expression: 0.12408562 * bm25(title) + 0.36673144 * bm25(body) + 6.2273498 * dot_product_title() + 5.671119 * dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- bm25(title)
- bm25(body)
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile listwise_linear_bm25_gse_title_body_or inherits default {
- function dot_product_title() {
- expression: sum(query(tensor_gse)*attribute(title_gse))
- }
- function dot_product_body() {
- expression: sum(query(tensor_gse)*attribute(body_gse))
- }
- first-phase {
- expression: 0.7150663 * bm25(title) + 0.9480147 * bm25(body) + 1.560068 * dot_product_title() + 1.5062317 * dot_product_body()
- }
- ignore-default-rank-features
- rank-features {
- bm25(title)
- bm25(body)
- rankingExpression(dot_product_title)
- rankingExpression(dot_product_body)
- }
- }
-
- rank-profile pointwise_linear_bm25 inherits default {
- first-phase {
- expression: 0.22499913 * bm25(title) + 0.07596389 * bm25(body)
- }
- }
-
- rank-profile listwise_linear_bm25 inherits default {
- first-phase {
- expression: 0.13446581 * bm25(title) + 0.5716889 * bm25(body)
- }
- }
-
- rank-profile collect_rank_features_embeddings inherits default {
- function dot_product_title_word2vec() {
- expression: sum(query(tensor)*attribute(title_word2vec))
- }
- function dot_product_body_word2vec() {
- expression: sum(query(tensor)*attribute(body_word2vec))
- }
- function dot_product_title_gse() {
- expression: sum(query(tensor_gse)*attribute(title_gse))
- }
- function dot_product_body_gse() {
- expression: sum(query(tensor_gse)*attribute(body_gse))
- }
- function dot_product_title_bert() {
- expression: sum(query(tensor_bert)*attribute(title_bert))
- }
- function dot_product_body_bert() {
- expression: sum(query(tensor_bert)*attribute(body_bert))
- }
- first-phase {
- expression: random
- }
- ignore-default-rank-features
- rank-features {
- bm25(title)
- bm25(body)
- nativeRank(title)
- nativeRank(body)
- rankingExpression(dot_product_title_word2vec)
- rankingExpression(dot_product_body_word2vec)
- rankingExpression(dot_product_title_gse)
- rankingExpression(dot_product_body_gse)
- rankingExpression(dot_product_title_bert)
- rankingExpression(dot_product_body_bert)
- }
- }
-
- rank-profile collect_rank_features inherits default {
- first-phase {
- expression: random
- }
- ignore-default-rank-features
- rank-features {
- bm25(title)
- bm25(body)
- nativeRank(title)
- nativeRank(body)
- }
- }
-}
diff --git a/client/go/src/cmd/testdata/src/main/application/services.xml b/client/go/src/cmd/testdata/src/main/application/services.xml
deleted file mode 100644
index 766434798f0..00000000000
--- a/client/go/src/cmd/testdata/src/main/application/services.xml
+++ /dev/null
@@ -1,61 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -->
-
-<services version="1.0">
-
- <container id="text_search" version="1.0">
- <document-api/>
- <search>
-
- <!-- Config for bolding in search result snippets -->
- <config name="container.qr-searchers">
- <tag>
- <bold>
- <open>&lt;strong&gt;</open>
- <close>&lt;/strong&gt;</close>
- </bold>
- <separator>...</separator>
- </tag>
- </config>
-
- </search>
- <document-processing/>
-
- <component id="com.yahoo.language.simple.SimpleLinguistics"/>
-
- <handler id="ai.vespa.example.text_search.site.SiteHandler" bundle="text-search">
- <binding>http://*/site/*</binding>
- <binding>http://*/site</binding>
- <config name="ai.vespa.example.text_search.site.site-handler">
- <vespaHostName>localhost</vespaHostName>
- <vespaHostPort>8080</vespaHostPort>
- </config>
- </handler>
-
- <nodes jvmargs="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=*:8998">
- <node hostalias="node1" />
- </nodes>
-
- </container>
-
- <content id="msmarco" version="1.0">
-
- <!-- Config for search result snippets -->
- <config name="vespa.config.search.summary.juniperrc">
- <max_matches>2</max_matches>
- <length>1000</length>
- <surround_max>500</surround_max>
- <min_length>300</min_length>
- </config>
-
- <redundancy>2</redundancy>
- <documents>
- <document type='msmarco' mode="index"/>
- <document-processing cluster="text_search"/>
- </documents>
- <nodes>
- <node distribution-key='0' hostalias='node1'/>
- </nodes>
- </content>
-
-</services>