Skip to content

Commit

Permalink
main_test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mindhash committed Jan 1, 2018
1 parent 7e0a01e commit c7efd9f
Show file tree
Hide file tree
Showing 76 changed files with 3,131 additions and 506 deletions.
Binary file modified bin/hflow
Binary file not shown.
Binary file modified bin/workhorse
Binary file not shown.
Binary file added pkg/darwin_amd64/hyperview.in/worker.a
Binary file not shown.
35 changes: 15 additions & 20 deletions src/hyperview.in/client/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,8 @@ func (c *ApiClient) InitRepo(repoName string) error {
resp := repo_req.Do()
_, err := resp.Raw()

//fmt.Println("resp: ", string(b))

if err != nil {
return fmt.Errorf("Failed while initializing repo: %s", err)
return fmt.Errorf("Failed while initializing repo: %s", err.Error())
}

base.Log("[InitRepo] Repo created: ", repoName)
Expand Down Expand Up @@ -182,7 +180,7 @@ func (c *ApiClient) CloneRepo(repoName, branchName string) (commitId string, err
}

// push code updates and then call run
func (c *ApiClient) RunTask(repoName string, branchName string, commitId string, cmdStr string) (openCommitId string, task_status string, fnError error) {
func (c *ApiClient) RunTask(repoName string, branchName string, commitId string, cmdStr string) (flow_id string, openCommitId string, task_status string, fnError error) {
var err error
var status_str string
var commit_id string
Expand All @@ -193,8 +191,6 @@ func (c *ApiClient) RunTask(repoName string, branchName string, commitId string,
return commit_id, status_str, err
}

api_req := c.flowIo.Verb("POST")

task_req := flow_pkg.NewFlowLaunchRequest {
Repo: ws.Repo {
Name: repoName,
Expand All @@ -209,6 +205,8 @@ func (c *ApiClient) RunTask(repoName string, branchName string, commitId string,
}

task_req_json, _ := json.Marshal(&task_req)

api_req := c.flowIo.Verb("POST")
_ = api_req.SetBodyReader(ioutil.NopCloser(bytes.NewReader(task_req_json)))

http_resp := api_req.Do()
Expand All @@ -217,10 +215,10 @@ func (c *ApiClient) RunTask(repoName string, branchName string, commitId string,
task_resp := flow_pkg.NewFlowLaunchResponse{}
err = json.Unmarshal(api_resp, &task_resp)
status_str = task_resp.TaskStatusStr
fmt.Println("response: ", status_str, task_resp.Flow)
//fmt.Println("response: ", status_str, task_resp.Flow)
base.Log("[RunTask] Flow Id: ", task_resp.Flow.Id)

return commit_id, status_str, err
return task_resp.Flow.Id, commit_id, status_str, err
}


Expand Down Expand Up @@ -257,7 +255,7 @@ func (c *ApiClient) pushCode(repoName, branchName, commitId, fullFilePath string

wrt_len, err := w.Write(buf[:read_len])

upld_size := upld_size + int64(wrt_len)
upld_size = upld_size + int64(wrt_len)

if err != nil {
return upld_size, err
Expand Down Expand Up @@ -341,12 +339,11 @@ func (c *ApiClient) pushCodeUpdates(repoName, branchName, commitId string) error
}


// Need branch here?
// should compare file sizes and decide to move or not ?
// Push always pushes to the head of commit graph on branch
//
func (c *ApiClient) PushRepo(repoName, branchName, commitId string) (string, error) {
var open_commit_id string
// TODO: check upload size and push only changed
func (c *ApiClient) PushRepo(repoName, branchName, commitId string) (*ws.Commit, error) {
var commit *Commit
var err error

commit_cli, err := rest_client.NewRESTClient(c.ServerAddr, c.config.CommitUriPath, http.DefaultClient)
Expand All @@ -356,28 +353,26 @@ func (c *ApiClient) PushRepo(repoName, branchName, commitId string) (string, err
commit_req.Param("branchName", branchName)
commit_req.Param("commitId", commitId)

base.Debug("[ApiClient.PushRepo] Commit Url: ", commit_req.URL())
commit_resp := commit_req.Do()
commit_data, err := commit_resp.Raw()

// commit ID validated
if err != nil {
base.Log("[ApiClient.PushRepo] Failed to retrieve an open repo commit: ", err)
return open_commit_id, err
return commit, err
}

commit_attrs := &ws.CommitAttrs{}
err = json.Unmarshal(commit_data, &commit_attrs)

open_commit_id = commit_attrs.Commit.Id
commit = commit_attrs.Commit

// got an open commit, now push code
err = c.pushCodeUpdates(repoName, branchName, open_commit_id)
err = c.pushCodeUpdates(repoName, branchName, commit.Id)
if err != nil {
return "", err
}

return open_commit_id, nil
return commit, nil
}


Expand All @@ -396,6 +391,6 @@ func (c *ApiClient) PutObjectWriter(repoName string, branchName string, commitId
return hw, nil
}


// pull task results out folder


4 changes: 2 additions & 2 deletions src/hyperview.in/client/cmd/hflow/branchcmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func BranchCommand() *cobra.Command {
var branch_name string
var err error
branch_cmd := &cobra.Command{
Use: "checkout",
Use: "experiment",
Short: "code checkout experiments ",
Long: `code checkout experiments `,
Run: func(cmd *cobra.Command, args []string) {
Expand All @@ -76,7 +76,7 @@ func BranchCommand() *cobra.Command {

},
}
branch_cmd.Flags().StringVarP(&branch_name, "branch", "b", "", "new branch name")
branch_cmd.Flags().StringVarP(&branch_name, "new-branch", "n", "", "new branch name")

return branch_cmd
}
11 changes: 4 additions & 7 deletions src/hyperview.in/client/cmd/hflow/flowcmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ func FlowCommands() []*cobra.Command {
Long: `start a hyperflow task for a given repo and commit`,
Run: func(cmd *cobra.Command, args []string) {
current_dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))
fmt.Println("task: ", task)


repo_name, _ := config.ReadRepoParams(current_dir, "REPO_NAME")
branch_name, _ := config.ReadRepoParams(current_dir, "BRANCH_NAME")
commit_id, _ := config.ReadRepoParams(current_dir, "COMMIT_ID")

cl, _ := client.NewApiClient(current_dir)
new_commit_id, task_resp, err := cl.RunTask(repo_name, branch_name, commit_id, task)
flow_id, new_commit_id, task_resp, err := cl.RunTask(repo_name, branch_name, commit_id, task)
_ = config.WriteRepoParams(current_dir, "FLOW_ID", flow_id)
_ = config.WriteRepoParams(current_dir, "COMMIT_ID", new_commit_id)

fmt.Println("task run api_response: ", task_resp)
fmt.Println("task run api error (empty if null): ", err)


},
}
flow_cmd.Flags().StringVarP(&task, "task","t", "", "task command")
Expand Down
27 changes: 20 additions & 7 deletions src/hyperview.in/client/cmd/hflow/repocmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"path/filepath"

"github.com/spf13/cobra"

//"hyperview.in/server/base"

client "hyperview.in/client"
"hyperview.in/client/config"
Expand All @@ -21,6 +23,10 @@ func exitWithError(format string, args ...interface{}) {
os.Exit(1)
}

func hasWhiteSpace(s string) bool{
return strings.ContainsAny(s, " ")
}

const (
concurrency = 10
)
Expand All @@ -33,9 +39,9 @@ func RepoCommands() []*cobra.Command {

repo_cmd := &cobra.Command{
Use: "repo",
Short: "List details of current repo",
Short: "Repo command Usage",
//TODO: add command details
Long: `List details of current repo`,
Long: `Repo command Usage`,
Run: func(cmd *cobra.Command, args []string) {
cmd.Usage()
},
Expand All @@ -47,6 +53,14 @@ func RepoCommands() []*cobra.Command {
//TODO: add command details
Long: `Initializes a new repo. Name is mandatory parameter.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
exitWithError("Repo name is mandatory. \nformat: hflow init <<repo_name>>")
}

repo_name = args[0]
if len(args) > 1 || hasWhiteSpace(repo_name) {
exitWithError("Repo name can not have spaces")
}
current_dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))

r, _ := config.ReadRepoParams(current_dir, "REPO_NAME")
Expand All @@ -62,8 +76,7 @@ func RepoCommands() []*cobra.Command {
}

_ = config.WriteRepoParams(current_dir, "REPO_NAME", repo_name)

// TODO: ideally pick branch from the server response
// assumption: repo always starts with a master branch
_ = config.WriteRepoParams(current_dir, "BRANCH_NAME", "master")

},
Expand Down Expand Up @@ -93,8 +106,8 @@ func RepoCommands() []*cobra.Command {
Run: func(cmd *cobra.Command, args []string) {

current_dir, _ := filepath.Abs(filepath.Dir(os.Args[0]))

fmt.Println("directory: ", current_dir)

repo_name, _ = config.ReadRepoParams(current_dir, "REPO_NAME")
branch_name, _ = config.ReadRepoParams(current_dir, "BRANCH_NAME")
curr_commit_id, _ = config.ReadRepoParams(current_dir, "COMMIT_ID")
Expand All @@ -104,12 +117,12 @@ func RepoCommands() []*cobra.Command {
}

c, _ := client.NewApiClient(current_dir)
new_commit, err := c.PushRepo(repo_name, branch_name, curr_commit_id)
commit, err := c.PushRepo(repo_name, branch_name, curr_commit_id)
if err != nil {
exitWithError(err.Error())
}

_ = config.WriteRepoParams(current_dir, "COMMIT_ID", new_commit)
_ = config.WriteRepoParams(current_dir, "COMMIT_ID", commit.Id)
},
}

Expand Down
1 change: 1 addition & 0 deletions src/hyperview.in/client/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func ReadFromFile() (*Config, error) {
fmt.Println("No Config file at :", configPath)
return Default(), nil
}

err = json.Unmarshal(config_encoded, &config)
if err != nil {
return nil, err
Expand Down
6 changes: 5 additions & 1 deletion src/hyperview.in/client/config/repo_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ func WriteRepoParams(working_dir string, key string, value string) error {

func ReadRepoParams(working_dir string, key string) (value string, err error) {
v, _ := GetRepoConfig(working_dir)
//base.Log("repo_id: " , v.Get(key))

if v == nil {
return "", nil
}

vi := v.Get(key)
return vi.(string), nil
}
13 changes: 11 additions & 2 deletions src/hyperview.in/server/base/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import (
"net/http"
)


func Errorf(format string, args ...interface{}) {
fmt.Errorf(format, args)
}

// Custom error when file is not found
type ErrFileNotFound struct {
RepoName string
Expand All @@ -31,16 +36,20 @@ func (err *HTTPError) Error() string {
return fmt.Sprintf("%d %s", err.Status, err.Message)
}


func HTTPErrorf(status int, format string, args ...interface{}) *HTTPError {
return &HTTPError{status, fmt.Sprintf(format, args...)}
}

func ErrorToHTTPStatus(err error) (int, string) {
Debug("[errors.ErrorToHTTPStatus] :", err)

if err == nil {
return 200, "OK"
}
var errString = err.Error()

if errString != "" && errString[0:3] == "400" {
return http.StatusBadRequest, errString[4:]
}

return http.StatusInternalServerError, err.Error()
}
54 changes: 0 additions & 54 deletions src/hyperview.in/server/base/log_level.go

This file was deleted.

Loading

0 comments on commit c7efd9f

Please sign in to comment.