2016-05-18 12:17:40 +02:00
|
|
|
package replication
|
2016-04-20 08:24:17 +02:00
|
|
|
|
2016-05-10 13:38:50 +02:00
|
|
|
/*
|
2016-04-20 08:24:17 +02:00
|
|
|
import (
|
|
|
|
"encoding/json"
|
2016-05-03 09:51:52 +02:00
|
|
|
//"github.com/vmware/harbor/dao"
|
2016-04-20 08:24:17 +02:00
|
|
|
"github.com/vmware/harbor/job"
|
|
|
|
"github.com/vmware/harbor/models"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
jobType = "transfer_img_out"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Runner struct {
|
|
|
|
job.JobSM
|
|
|
|
Logger job.Logger
|
|
|
|
parm ImgOutParm
|
|
|
|
}
|
|
|
|
|
|
|
|
type ImgPuller struct {
|
|
|
|
job.DummyHandler
|
|
|
|
img string
|
|
|
|
logger job.Logger
|
|
|
|
}
|
|
|
|
|
2016-05-03 09:51:52 +02:00
|
|
|
func (ip ImgPuller) Enter() (string, error) {
|
|
|
|
ip.logger.Infof("I'm pretending to pull img:%s, then sleep 30s", ip.img)
|
|
|
|
time.Sleep(30 * time.Second)
|
2016-04-20 08:24:17 +02:00
|
|
|
ip.logger.Infof("wake up from sleep....")
|
2016-05-03 09:51:52 +02:00
|
|
|
return "push-img", nil
|
2016-04-20 08:24:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type ImgPusher struct {
|
|
|
|
job.DummyHandler
|
|
|
|
targetURL string
|
|
|
|
logger job.Logger
|
|
|
|
}
|
|
|
|
|
2016-05-03 09:51:52 +02:00
|
|
|
func (ip ImgPusher) Enter() (string, error) {
|
|
|
|
ip.logger.Infof("I'm pretending to push img to:%s, then sleep 30s", ip.targetURL)
|
|
|
|
time.Sleep(30 * time.Second)
|
2016-04-20 08:24:17 +02:00
|
|
|
ip.logger.Infof("wake up from sleep....")
|
2016-05-03 09:51:52 +02:00
|
|
|
return job.JobContinue, nil
|
2016-04-20 08:24:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
job.Register(jobType, Runner{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r Runner) Run(je models.JobEntry) error {
|
|
|
|
err := r.init(je)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-05-03 09:51:52 +02:00
|
|
|
r.Start(job.JobRunning)
|
2016-04-20 08:24:17 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *Runner) init(je models.JobEntry) error {
|
|
|
|
r.JobID = je.ID
|
|
|
|
r.InitJobSM()
|
|
|
|
err := json.Unmarshal([]byte(je.ParmsStr), &r.parm)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
r.Logger = job.Logger{je.ID}
|
2016-05-03 09:51:52 +02:00
|
|
|
r.AddTransition(job.JobRunning, "pull-img", ImgPuller{DummyHandler: job.DummyHandler{JobID: r.JobID}, img: r.parm.Image, logger: r.Logger})
|
2016-04-20 08:24:17 +02:00
|
|
|
//only handle on target for now
|
|
|
|
url := r.parm.Targets[0].URL
|
|
|
|
r.AddTransition("pull-img", "push-img", ImgPusher{DummyHandler: job.DummyHandler{JobID: r.JobID}, targetURL: url, logger: r.Logger})
|
2016-05-03 09:51:52 +02:00
|
|
|
r.AddTransition("push-img", job.JobFinished, job.StatusUpdater{job.DummyHandler{JobID: r.JobID}, job.JobFinished})
|
2016-04-20 08:24:17 +02:00
|
|
|
return nil
|
|
|
|
}
|
2016-05-10 13:38:50 +02:00
|
|
|
*/
|