当前位置: 首页>>代码示例>>Golang>>正文


Golang liboct.GetDefaultDB函数代码示例

本文整理汇总了Golang中github.com/huawei-openlab/oct-engine/liboct.GetDefaultDB函数的典型用法代码示例。如果您正苦于以下问题:Golang GetDefaultDB函数的具体用法?Golang GetDefaultDB怎么用?Golang GetDefaultDB使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetDefaultDB函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ListCases

func ListCases(w http.ResponseWriter, r *http.Request) {
	//Need better explaination of 'status', currently, only hasReport/isUpdated
	db := liboct.GetDefaultDB()
	var query liboct.DBQuery
	page_string := r.URL.Query().Get("Page")
	page, err := strconv.Atoi(page_string)
	if err == nil {
		query.Page = page
	}
	pageSizeString := r.URL.Query().Get("PageSize")
	pageSize, err := strconv.Atoi(pageSizeString)
	if err != nil {
		query.PageSize = pageSize
	}

	status := r.URL.Query().Get("Status")
	if len(status) > 0 {
		query.Params = make(map[string]string)
		query.Params["Status"] = status
	}
	ids := db.Lookup(liboct.DBCase, query)

	var caseList []liboct.TestCase
	for index := 0; index < len(ids); index++ {
		if val, err := db.Get(liboct.DBCase, ids[index]); err == nil {
			tc, _ := liboct.CaseFromString(val.String())
			caseList = append(caseList, tc)
		}
	}

	liboct.RenderOK(w, fmt.Sprintf("%d cases founded", len(caseList)), caseList)
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:32,代码来源:case.go

示例2: ReceiveTask

func ReceiveTask(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	realURL, params := liboct.ReceiveFile(w, r, OCTDCacheDir)

	logrus.Debugf("ReceiveTask %v", realURL)

	if id, ok := params["id"]; ok {
		if strings.HasSuffix(realURL, ".tar.gz") {
			liboct.UntarFile(realURL, strings.TrimSuffix(realURL, ".tar.gz"))
		}
		var task liboct.TestTask
		task.ID = id
		task.BundleURL = realURL
		if name, ok := params["name"]; ok {
			task.Name = name
		} else {
			task.Name = id
			logrus.Warnf("Cannot find the name of the task.")
		}
		db.Update(liboct.DBTask, id, task)

		liboct.RenderOK(w, "", nil)
	} else {
		liboct.RenderErrorf(w, fmt.Sprintf("Cannot find the task id: %d", id))
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:26,代码来源:main.go

示例3: init

func init() {
	cmf, err := os.Open("casemanager.conf")
	if err != nil {
		logrus.Fatal(err)
		return
	}
	defer cmf.Close()

	if err = json.NewDecoder(cmf).Decode(&pubConfig); err != nil {
		logrus.Fatal(err)
		return
	}

	if pubConfig.Debug {
		logrus.SetLevel(logrus.DebugLevel)
	} else {
		logrus.SetLevel(logrus.WarnLevel)
	}

	db := liboct.GetDefaultDB()
	db.RegistCollect(liboct.DBCase)
	db.RegistCollect(liboct.DBRepo)
	db.RegistCollect(liboct.DBTask)

	repos := pubConfig.Repos
	for index := 0; index < len(repos); index++ {
		if err := repos[index].IsValid(); err != nil {
			logrus.Warnf("The repo ", repos[index], " is invalid. ", err.Error())
			continue
		}
		if id, err := db.Add(liboct.DBRepo, repos[index]); err == nil {
			RefreshRepo(id)
		}
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:35,代码来源:main.go

示例4: GetTaskReport

// redirect to local to test
func GetTaskReport(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	id := r.URL.Query().Get(":TaskID")
	taskInterface, err := db.Get(liboct.DBTask, id)
	if err != nil {
		liboct.RenderError(w, err)
		return
	}

	task, _ := liboct.TaskFromString(taskInterface.String())
	// Here the task.PostURL is: http://ip:port/task/id
	getURL := fmt.Sprintf("%s/report", task.PostURL)
	logrus.Debugf("Get url ", getURL)
	resp, err := http.Get(getURL)
	if err != nil {
		liboct.RenderError(w, err)
		return
	}
	defer resp.Body.Close()
	resp_body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		liboct.RenderError(w, err)
		return
	}

	w.Write([]byte(resp_body))
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:28,代码来源:task.go

示例5: GetTaskReport

func GetTaskReport(w http.ResponseWriter, r *http.Request) {
	filename := r.URL.Query().Get("File")
	id := r.URL.Query().Get(":ID")

	db := liboct.GetDefaultDB()
	taskInterface, err := db.Get(liboct.DBTask, id)
	if err != nil {
		logrus.Warnf("Cannot find the test job %v", id)
		w.WriteHeader(http.StatusNotFound)
		w.Write([]byte("Cannot find the test job " + id))
		return
	}

	task, _ := liboct.TaskFromString(taskInterface.String())
	workingDir := strings.TrimSuffix(task.BundleURL, ".tar.gz")
	//The real working dir is under 'source'
	realURL := path.Join(workingDir, "source", filename)
	file, err := os.Open(realURL)
	defer file.Close()
	if err != nil {
		logrus.Warnf("Cannot open the file %v", filename)
		w.WriteHeader(http.StatusNotFound)
		w.Write([]byte("Cannot open the file: " + realURL))
		return
	}

	buf := bytes.NewBufferString("")
	buf.ReadFrom(file)

	w.Write([]byte(buf.String()))
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:31,代码来源:main.go

示例6: ReceiveTaskCommand

func ReceiveTaskCommand(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	id := r.URL.Query().Get(":ID")
	sInterface, err := db.Get(liboct.DBScheduler, id)
	if err != nil {
		liboct.RenderError(w, err)
		return
	}
	s, _ := liboct.SchedulerFromString(sInterface.String())

	result, _ := ioutil.ReadAll(r.Body)
	logrus.Debugf("Receive task Command %s", string(result))
	r.Body.Close()
	/* Donnot use this now FIXME
	var cmd liboct.TestActionCommand
	json.Unmarshal([]byte(result), &cmd)
	*/
	action, err := liboct.TestActionFromString(string(result))
	if err != nil {
		liboct.RenderError(w, err)
		return
	}

	err = s.Command(action)
	db.Update(liboct.DBScheduler, id, s)
	if err != nil {
		liboct.RenderError(w, err)
	} else {
		liboct.RenderOK(w, "", nil)
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:31,代码来源:main.go

示例7: AddRepo

func AddRepo(w http.ResponseWriter, r *http.Request) {
	action := r.URL.Query().Get("Action")
	db := liboct.GetDefaultDB()
	//Add and refresh
	if action == "Add" {
		var repo liboct.TestCaseRepo
		result, _ := ioutil.ReadAll(r.Body)
		r.Body.Close()
		err := json.Unmarshal([]byte(result), &repo)
		if err != nil {
			liboct.RenderError(w, err)
		} else {
			if err := repo.IsValid(); err == nil {
				if id, e := db.Add(liboct.DBRepo, repo); e != nil {
					liboct.RenderError(w, err)
				} else {
					RefreshRepo(id)
					liboct.RenderOK(w, "", nil)
				}
			} else {
				liboct.RenderError(w, err)
			}
		}
	} else if action == "Refresh" {
		ids := db.Lookup(liboct.DBRepo, liboct.DBQuery{})
		for index := 0; index < len(ids); index++ {
			RefreshRepo(ids[index])
		}
		liboct.RenderOK(w, "", nil)
	} else {
		liboct.RenderErrorf(w, "The action in AddRepo is limited to Add/Refresh")
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:33,代码来源:case.go

示例8: ModifyRepo

func ModifyRepo(w http.ResponseWriter, r *http.Request) {
	repoID := r.URL.Query().Get(":ID")
	action := r.URL.Query().Get("Action")
	db := liboct.GetDefaultDB()
	val, err := db.Get(liboct.DBRepo, repoID)
	if err != nil {
		liboct.RenderError(w, err)
		return
	}
	if action == "Modify" {
		var newRepo liboct.TestCaseRepo
		result, _ := ioutil.ReadAll(r.Body)
		r.Body.Close()
		err := json.Unmarshal([]byte(result), &newRepo)
		if err != nil {
			liboct.RenderError(w, err)
		} else {
			oldRepo, _ := liboct.RepoFromString(val.String())
			oldRepo.Modify(newRepo)
			db.Update(liboct.DBRepo, repoID, oldRepo)
			RefreshRepo(repoID)
			liboct.RenderOK(w, "", nil)
		}
	} else if action == "Refresh" {
		RefreshRepo(repoID)
		liboct.RenderOK(w, "", nil)
	} else {
		liboct.RenderErrorf(w, "The action in ModifyRepo is limited to Add/Refresh")
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:30,代码来源:case.go

示例9: RefreshRepos

func RefreshRepos(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	ids := db.Lookup(liboct.DBRepo, liboct.DBQuery{})
	for index := 0; index < len(ids); index++ {
		RefreshRepo(ids[index])
	}
	liboct.RenderOK(w, "", nil)
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:8,代码来源:case.go

示例10: GetRepo

func GetRepo(w http.ResponseWriter, r *http.Request) {
	id := r.URL.Query().Get(":ID")
	db := liboct.GetDefaultDB()
	if repo, err := db.Get(liboct.DBRepo, id); err != nil {
		liboct.RenderError(w, err)
	} else {
		liboct.RenderOK(w, "", repo)
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:9,代码来源:case.go

示例11: GetTaskStatus

func GetTaskStatus(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	id := r.URL.Query().Get(":TaskID")
	if taskInterface, err := db.Get(liboct.DBTask, id); err != nil {
		liboct.RenderError(w, err)
	} else {
		liboct.RenderOK(w, "", taskInterface)
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:9,代码来源:task.go

示例12: CleanRepo

func CleanRepo(repo liboct.TestCaseRepo) {
	var query liboct.DBQuery
	db := liboct.GetDefaultDB()
	query.Params = make(map[string]string)
	query.Params["RepoID"] = repo.GetID()
	ids := db.Lookup(liboct.DBRepo, query)
	for index := 0; index < len(ids); index++ {
		db.Remove(liboct.DBCase, ids[index])
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:10,代码来源:case.go

示例13: DeleteResource

func DeleteResource(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	id := r.URL.Query().Get("ID")
	lock.Lock()
	if err := db.Remove(liboct.DBResource, id); err != nil {
		liboct.RenderError(w, err)
	} else {
		liboct.RenderOK(w, "Success in remove the resource", nil)
	}
	lock.Unlock()
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:11,代码来源:resource.go

示例14: GetCaseReport

func GetCaseReport(w http.ResponseWriter, r *http.Request) {
	db := liboct.GetDefaultDB()
	id := r.URL.Query().Get(":ID")
	if val, err := db.Get(liboct.DBCase, id); err != nil {
		liboct.RenderError(w, err)
	} else {
		tc, _ := liboct.CaseFromString(val.String())
		content := tc.GetReportContent()
		if len(content) > 0 {
			liboct.RenderOK(w, "", content)
		} else {
			liboct.RenderErrorf(w, "Case report is empty.")
		}
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:15,代码来源:case.go

示例15: RefreshRepo

//This refresh the 'cache' maintained in casemanager
func RefreshRepo(id string) {
	db := liboct.GetDefaultDB()
	val, err := db.Get(liboct.DBRepo, id)
	if err != nil {
		return
	}
	repo, _ := liboct.RepoFromString(val.String())
	if repo.Refresh() {
		CleanRepo(repo)
		cases := repo.GetCases()
		for index := 0; index < len(cases); index++ {
			fmt.Println("case loaded ", cases[index])
			db.Add(liboct.DBCase, cases[index])
		}
	}
}
开发者ID:pombredanne,项目名称:oct-engine,代码行数:17,代码来源:case.go


注:本文中的github.com/huawei-openlab/oct-engine/liboct.GetDefaultDB函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。