示例#1
0
文件: publish.go 项目: shtlee/qa
func (p *Pub) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(p, conf); err != nil {
		return
	}
	if err = config.LoadEx(&p.Env, env); err != nil {
		return
	}
	dt := da.NewTransport(p.Env.AccessKey, p.Env.SecretKey, nil)
	p.rsCli, err = rs.New(p.Env.Hosts, p.Env.Ips, dt)
	if err != nil {
		err = errors.Info(err, "Pub init failed")
		return
	}
	p.pubCli, err = pub.New(p.Env.Hosts["pu"], p.Env.Ips["pu"], dt)
	if err != nil {
		err = errors.Info(err, "Pub init failed")
		return
	}
	p.DataFile = filepath.Join(path, p.DataFile)
	domainRegexp, err := regexp.Compile(p.NormalDomainRegexp)
	if err != nil {
		err = errors.Info(err, "Pub init failed")
		return
	}
	p.isNormalDomain = domainRegexp.Match([]byte(p.Domain))

	return
}
示例#2
0
func (self *UpRPut) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(self, conf); err != nil {
		err = errors.Info(err, "UpResuPut init failed")
		return
	}
	if err = config.LoadEx(&self.Env, env); err != nil {
		err = errors.Info(err, "UpEnv init failed")
		return
	}
	self.DataFile = filepath.Join(path, self.DataFile)
	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	host := self.Env.Hosts["up"]
	ip := self.Env.Ips["up"]

	self.Rscli, err = rs.New(self.Env.Hosts, self.Env.Ips, dt)
	if err != nil {
		err = errors.Info(err, "Rscli init failed")
		return
	}
	self.Up2cli, err = up2.New(host, ip, self.BlockBits, self.ChunkSize, self.PutRetryTimes, dt)
	if err != nil {
		err = errors.Info(err, "Up2cli init failed")
		return
	}
	return
}
示例#3
0
文件: fop_imginfo.go 项目: shtlee/qa
func (self *FopImgInfo) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(self, conf); err != nil {
		return
	}
	if err = config.LoadEx(&self.Env, env); err != nil {
		return
	}
	self.SrcImg = filepath.Join(path, self.SrcImg)
	return
}
示例#4
0
func (self *UpResuPut) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(self, conf); err != nil {
		return err
	}
	if err = config.LoadEx(&self.Env, env); err != nil {
		return err
	}
	self.DataFile = filepath.Join(path, self.DataFile)
	return
}
示例#5
0
文件: put.go 项目: shtlee/qa
func (self *PutFile) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(self, conf); err != nil {
		return err
	}
	if err = config.LoadEx(&self.Env, env); err != nil {
		return err
	}
	dt := da.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	self.Conn, err = rs.New(self.Env.Hosts, self.Env.Ips, dt)
	self.DataFile = filepath.Join(path, self.DataFile)
	return
}
示例#6
0
文件: fop_imgexif.go 项目: shtlee/qa
func (self *FopImgExif) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(self, conf); err != nil {
		return
	}
	if err = config.LoadEx(&self.Env, env); err != nil {
		return
	}
	if err = config.LoadEx(&self.SrcExif, conf); err != nil {
		return
	}
	self.UploadImg = filepath.Join(path, self.UploadImg)
	//self.SrcExif = filepath.Join(path, self.SrcExif)
	return
}
示例#7
0
文件: qboxcases.go 项目: shtlee/qa
func (p *Visitor) VisitFile(file string, fi os.FileInfo) {

	var (
		conf CaseInfo
	)
	log.Info("loading ", file, "...")
	if err := config.LoadEx(&conf, file); err != nil {
		log.Error("load err :", file, err)
		os.Exit(1)
	}
	if conf.Enable == true {
		if _, ok := p.cases[conf.Name]; ok || conf.Name == "" {
			log.Error("name err or duplicate: ", file, conf.Name, conf.Type)
			os.Exit(-1)
		}
		fun, ok := Cases[conf.Type]
		if !ok {
			log.Error("no such type :", conf.Type, conf.Name)
			os.Exit(1)
		}
		caseEntry := fun()
		err := caseEntry.Init(file, p.Env, p.DataPath)
		if err != nil {
			log.Error("init err :", conf.Name, conf.Type, err)
			os.Exit(1)
		}
		p.cases[conf.Name] = caseEntry
		log.Info("loaded", conf.Name, conf.Type)
	}
}
示例#8
0
文件: example.go 项目: shtlee/qa
func (p *Example) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(&p.conf, conf); err != nil {
		return
	}
	return nil
}
示例#9
0
文件: pub_image.go 项目: shtlee/qa
func (p *PubImage) Init(conf, env, path string) (err error) {

	if err = config.LoadEx(p, conf); err != nil {
		err = errors.Info(err, "pub_image load conf failed", conf)
		return
	}
	if err = config.LoadEx(&p.Env, env); err != nil {
		err = errors.Info(err, "pub_image load env failed", env)
		return
	}
	dt := da.NewTransport(p.Env.AccessKey, p.Env.SecretKey, nil)
	p.Pubcli, err = pub.New(p.Env.Hosts["pu"], p.Env.Ips["pu"], dt)
	if err != nil {
		err = errors.Info(err, "pub_image init failed")
		return
	}
	return
}
示例#10
0
文件: qboxcases.go 项目: shtlee/qa
func main() {
	var (
		conf Config
	)
	confDir, _ := cc.GetConfigDir("qbox.me")
	var confName *string = flag.String("f", confDir+"/qboxtest.conf", "the config file")
	flag.Parse()
	log.Info("Use the config file of " + *confName)
	if err := config.LoadEx(&conf, *confName); err != nil {
		log.Error(err)
		return
	}

	runtime.GOMAXPROCS(conf.MaxProcs)

	cases := make(map[string]Interface)
	conf.Include = filepath1.Join(confDir, conf.Include)
	conf.DataPath = filepath1.Join(confDir, conf.DataPath)
	conf.Env = filepath1.Join(confDir, conf.Env)
	filepath.Walk(conf.Include, &Visitor{&conf, cases}, nil)

	check := func() bool {
		msg := fmt.Sprintf("begin check ...\n")
		errCount := 0
		count := 0
		for k, v := range cases {
			count++
			log.Info("begin check", k, "...")
			msg += fmt.Sprintf("[%v/%v]process %v <<<\n", count, len(cases), k)
			info, err := v.Test()
			log.Info("check done :\n", info, k, err)
			msg += info
			msg += "\n"
			if err != nil {
				msg += fmt.Sprintf("!!!!!!!!!!mon case [%v] err!!![%v]\n", k, errors.Detail(err))
				errCount++
			} else {
				msg += fmt.Sprintf("[no err]%v done <<<\n", k)
			}
		}
		msg += fmt.Sprintf("all cases finish[%v/%v] <<<\n", len(cases)-errCount, len(cases))
		fmt.Println("----------------- result ------------------")
		fmt.Println(msg)
		fmt.Println("-------------------------------------------")
		return errCount == 0
	}

	b := check()
	if b {
		os.Exit(0)
	} else {
		os.Exit(1)
	}
}
示例#11
0
func main() {

	flag.Parse()

	if flag.NArg() < 1 {
		help()
		return
	}

	var task Task
	var taskFile = flag.Arg(0)
	err := config.LoadEx(&task, taskFile)
	if err != nil || !task.Isvalid() {
		log.Warn(err, "config.Load failed:", taskFile)
		return
	}

	task.Run()
}
示例#12
0
func main() {

	flag.Parse()

	var conf config
	if err := qconfig.LoadEx(&conf, *confName); err != nil {
		return
	}

	log.SetOutputLevel(conf.DebugLevel)

	logName := logPrefix + strconv.Itoa(conf.LogIndex)
	logFile, err := os.Open(logName)
	if err != nil {
		log.Fatal("open ", logName, " fail: ", err)
	}
	defer func() {
		logFile.Close()
	}()

	defer save(&conf)
	go interruptSave(&conf)
	go successiveSave(&conf)

	var reader *bufio.Reader
	reader, conf.Off = getReader(logFile, conf.Off)

	line := make([]byte, 0, 128)
	now := time.Now()
	last := now
	for {
		now = time.Now()
		sleep(now, last, conf.IntervalNS)
		last = now

		// assume isPrefix nerver be true
		b, _, err := reader.ReadLine()
		line = append(line, b...)

		if err != nil {
			if !conf.Follow {
				break
			}

			newFile := reOpen(logFile, conf.MaxLogSize)
			if newFile == nil {
				continue
			}

			if logFile.Name() != newFile.Name() {
				conf.RW.Lock()
				conf.Off = 0
				conf.LogIndex = getLogIndex(newFile.Name())
				conf.RW.Unlock()
				log.Info("reOpen ", newFile.Name())
			}
			logFile.Close()
			logFile = newFile

			reader, conf.Off = getReader(logFile, conf.Off)

			continue
		}

		atomic.AddInt64(&conf.Off, int64(len(line))+1)

		if uri, ok := parseLine(string(line), conf.Uids, conf.ImageSuffixs); ok {
			preOp(conf.IODomain, string(uri), conf.Params, conf.Save)
		}

		line = line[:0]
	}
}