Ejemplo n.º 1
0
Archivo: publish.go Proyecto: 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
}
Ejemplo n.º 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
}
Ejemplo n.º 3
0
// upload the file and get the download url
func (self *FopImgInfo) doTestGetImgUrl() (url string, err error) {
	entry := self.BucketName + ":" + self.Key

	dt := da.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	rsservice, err := rs.New(self.Env.Hosts, self.Env.Ips, dt)
	if err != nil {
		return
	}
	authPolicy := &uptoken.AuthPolicy{
		Scope:    entry,
		Deadline: 3600,
	}
	authPolicy.Deadline += uint32(time.Now().Unix())
	token := uptoken.MakeAuthTokenString(self.Env.AccessKey, self.Env.SecretKey, authPolicy)
	_, code, err := rsservice.Upload(entry, self.SrcImg, "", "", "", token)

	if err != nil || code != 200 {
		return
	}

	getRet, code, err := rsservice.Get(entry, "", "", 3600)
	if err != nil || code != 200 {
		return
	}

	url = getRet.URL
	return
}
Ejemplo n.º 4
0
func Init() (err error) {

	dt := digest.NewTransport(AccessKey, SecretKey, nil)
	Up2cli, err = up2.New(hosts["up"], ips["up"], BlockBits, RPutChunkSize, RPutRetryTimes, dt)
	if err != nil {
		return
	}
	Rscli, err = rs.New(hosts, ips, dt)
	if err != nil {
		return
	}
	return
}
Ejemplo n.º 5
0
Archivo: put.go Proyecto: 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
}
Ejemplo n.º 6
0
func NewService(c *Config) (s *Fileop, err error) {
	if c == nil {
		err = errors.New("No config file")
		return
	}
	// digest transport
	t := digest.NewTransport(c.AccessKey, c.SecretKey, nil)
	if t == nil {
		//	t = http.DefaultTransport
	}
	client := &http.Client{Transport: t}
	s = &Fileop{c, httputil.Client{c, client}}
	return
}
Ejemplo n.º 7
0
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
}
Ejemplo n.º 8
0
// upload the file and get the download url
func (self *FopImgOp) doTestGetImgUrl() (url string, err error) {
	entry := self.BucketName + ":" + self.Key

	dt := da.NewTransport(self.Conf.AccessKey, self.Conf.SecretKey, nil)
	rsservice, err := rs.NewRS(&self.Conf, dt)
	if err != nil {
		return
	}
	authPolicy := &uptoken.AuthPolicy{
		Scope:    entry,
		Deadline: 3600,
	}
	authPolicy.Deadline += uint32(time.Now().Unix())
	token := uptoken.MakeAuthTokenString(self.Conf.AccessKey, self.Conf.SecretKey, authPolicy)
	_, code, err := rsservice.Upload(entry, self.SrcImg, "", "", "", token)

	if err != nil || code != 200 {
		return
	}
	/*f, err := os.Open(self.SrcImg)
	   if err != nil {
	   	return
	   }
	   defer f.Close()
	   fi, err := f.Stat()
	   if err != nil {
	   	return
	   }

	  	_, code, err := rsservice.Put(entry, "", f, fi.Size())
	fmt.Println("rs.Put ", code, err )
	  	if err != nil || code != 200 {
	  		return
	  	}*/

	getRet, code, err := rsservice.Get(entry, "", "", 3600)
	if err != nil || code != 200 {
		return
	}

	url = getRet.URL
	return
}
Ejemplo n.º 9
0
func doTestInit(t *testing.T) {
	var (
		c Config
	)

	// load config
	b, err := ioutil.ReadFile("qbox.conf")
	if err != nil {
		t.Fatal(err)
	}
	if err = json.Unmarshal(b, &c); err != nil {
		t.Fatal(err)
	}

	// create auth transport layer, uptoken and digest
	auth := &uptoken.AuthPolicy{}
	token := uptoken.MakeAuthTokenString(c.AccessKey, c.SecretKey, auth)
	// uptoken transport
	ut := uptoken.NewTransport(token, nil)

	// digest transport
	dt := digest.NewTransport(c.AccessKey, c.SecretKey, nil)

	if eus, err = eu.New(&c, dt); err != nil {
		t.Fatal(err)
	}
	if pubs, err = pub.New(&c, dt); err != nil {
		t.Fatal(err)
	}
	if rss, err = rs.New(&c, dt); err != nil {
		t.Fatal(err)
	}
	if ucs, err = uc.New(&c, dt); err != nil {
		t.Fatal(err)
	}
	if ups, err = up.New(&c, ut); err != nil {
		t.Fatal(err)
	}
	if ims, err = image.New(&c, dt); err != nil {
		t.Fatal(err)
	}
}
Ejemplo n.º 10
0
func (self *UpResuPut) doTestRSGet() (msg string, err error) {
	var ret rss.GetRet

	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	rsservice, err := rss.NewRS(&self.Conf, dt)
	if err != nil {
		return
	}
	begin := time.Now()
	ret, code, err := rsservice.Get(self.EntryURI, "", "", 3600)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLog("UP    "+self.Env.Id+"_"+self.Name+"_doTestRsGet", begin, end, duration)

	if err != nil || code != 200 {
		return
	}
	self.Url = ret.URL
	return
}
Ejemplo n.º 11
0
func (self *Fileop) doTestGetImgDownloadUrl() (url string, err error) {
	var conf service.Config
	// load config
	self.buildConfig(&conf)
	self.Conf = conf
	fmt.Println("conf : ", conf)
	//rnd := rand.New(rand.NewSource(time.Now().UnixNano()))
	//entry := fp.BucketName + ":" + fp.ImageFile + "_" + strconv.FormatInt(rnd.Int63(), 10)
	entry := self.BucketName + ":fixed_entry_not_delete"
	/*policy := &gup.AuthPolicy{
		Scope:    entry,
		Deadline: 3600,
		Customer: "1234",
	}
	policy.Deadline += uint32(time.Now().Unix())*/
	//token := gup.MakeAuthTokenString(fp.AccessKey, fp.SecretKey, policy)

	/*_, code, err := rss.Upload(entry, fp.ImageFile, "", "", "", token)

	if err != nil || code != 200 {
		return
	}*/

	dt := da.NewTransport(self.Conf.AccessKey, self.Conf.SecretKey, nil)
	conn, err := rs.NewRS(&self.Conf, dt)
	if err != nil {
		return
	}

	begin := time.Now()
	getRet, code, err := conn.Get(entry, "", "", 3600)

	if err != nil || code != 200 {
		return
	}
	end := time.Now()
	self.DoLog2("doTestImgUrl", begin, end, end.Sub(begin))

	url = getRet.URL
	return
}
Ejemplo n.º 12
0
func (self *UpResuPut) doTestPut() (msg string, err error) {
	var conf service.Config
	// load config
	self.buildConfig(&conf)
	self.Conf = conf
	DataFile := self.DataFile
	entry := self.Bucket + ":" + self.Key
	self.EntryURI = entry
	dt := digest.NewTransport(conf.AccessKey, conf.SecretKey, nil)
	upservice, _ := up.NewService(&conf, dt, 1, 1)

	f, err := os.Open(DataFile)
	if err != nil {
		return
	}
	defer f.Close()
	fi, err := f.Stat()
	blockCnt := upservice.BlockCount(fi.Size())

	var (
		checksums []string           = make([]string, blockCnt)
		progs     []up.BlockProgress = make([]up.BlockProgress, blockCnt)
		ret       up.PutRet
		code      int
	)
	begin := time.Now()
	code, err = upservice.Put(f, fi.Size(), checksums, progs, func(int, string) {}, func(int, *up.BlockProgress) {})

	if err != nil || code != 200 {
		return
	}
	code, err = upservice.Mkfile(&ret, "/rs-mkfile/", entry, fi.Size(), "", "", checksums)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLog("UP    "+self.Env.Id+"_"+self.Name+"_doTestPut", begin, end, duration)
	if err != nil || code != 200 {
		return
	}
	return
}
Ejemplo n.º 13
0
func (self *UpResuPut) doTestPut() (msg string, err error) {

	DataFile := self.DataFile
	entry := self.Bucket + ":" + self.Key
	self.EntryURI = entry
	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	host := self.Env.Hosts["up"]
	ip := self.Env.Ips["up"]
	upservice, _ := up.NewService(host, ip, self.BlockBits, self.ChunkSize, self.PutRetryTimes, dt, 1, 1)
	log.Info(upservice)

	f, err := os.Open(DataFile)
	if err != nil {
		return
	}
	defer f.Close()
	fi, err := f.Stat()
	blockCnt := upservice.BlockCount(fi.Size())

	var (
		checksums []string           = make([]string, blockCnt)
		progs     []up.BlockProgress = make([]up.BlockProgress, blockCnt)
		ret       up.PutRet
		code      int
	)
	begin := time.Now()
	code, err = upservice.Put(f, fi.Size(), checksums, progs, func(int, string) {}, func(int, *up.BlockProgress) {})

	if err != nil || code != 200 {
		return
	}
	code, err = upservice.Mkfile(&ret, "/rs-mkfile/", entry, fi.Size(), "", "", checksums)
	end := time.Now()
	duration := end.Sub(begin)
	msg = util.GenLogEx("UP    "+self.Env.Id+"_"+self.Name+"_doTestPut", begin, end, duration)
	if err != nil || code != 200 {
		return
	}
	return
}
Ejemplo n.º 14
0
func NewRS(c service.Config) (*rss.RSService, error) {
	dt := digest.NewTransport(c.AccessKey, c.SecretKey, nil)
	return rss.NewRS(&c, dt)
}
Ejemplo n.º 15
0
func (self *UpResuPut) NewRS() (*rs.Service, error) {
	dt := digest.NewTransport(self.Env.AccessKey, self.Env.SecretKey, nil)
	return rs.New(self.Env.Hosts, self.Env.Ips, dt)
}