worker: Define new jobs to handle copying and resharing of images
The copy job copies from one region to another. It does not preserve the sharing on the ami and it's snapshot, that needs to be queued separately.
This commit is contained in:
parent
5e9ecd3ae4
commit
099b34b301
5 changed files with 405 additions and 42 deletions
|
|
@ -256,6 +256,33 @@ type ContainerResolveJobResult struct {
|
|||
JobResult
|
||||
}
|
||||
|
||||
type AWSEC2ShareJob struct {
|
||||
Ami string `json:"ami"`
|
||||
Region string `json:"region"`
|
||||
ShareWithAccounts []string `json:"shareWithAccounts"`
|
||||
}
|
||||
|
||||
type AWSEC2ShareJobResult struct {
|
||||
JobResult
|
||||
|
||||
Ami string `json:"ami"`
|
||||
Region string `json:"region"`
|
||||
}
|
||||
|
||||
type AWSEC2CopyJob struct {
|
||||
Ami string `json:"ami"`
|
||||
SourceRegion string `json:"source_region"`
|
||||
TargetRegion string `json:"target_region"`
|
||||
TargetName string `json:"target_name"`
|
||||
}
|
||||
|
||||
type AWSEC2CopyJobResult struct {
|
||||
JobResult
|
||||
|
||||
Ami string `json:"ami"`
|
||||
Region string `json:"region"`
|
||||
}
|
||||
|
||||
//
|
||||
// JSON-serializable types for the client
|
||||
//
|
||||
|
|
|
|||
|
|
@ -35,6 +35,8 @@ const (
|
|||
JobTypeDepsolve string = "depsolve"
|
||||
JobTypeManifestIDOnly string = "manifest-id-only"
|
||||
JobTypeContainerResolve string = "container-resolve"
|
||||
JobTypeAWSEC2Copy string = "aws-ec2-copy"
|
||||
JobTypeAWSEC2Share string = "aws-ec2-share"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
|
|
@ -157,6 +159,14 @@ func (s *Server) EnqueueContainerResolveJob(job *ContainerResolveJob, channel st
|
|||
return s.enqueue(JobTypeContainerResolve, job, nil, channel)
|
||||
}
|
||||
|
||||
func (s *Server) EnqueueAWSEC2CopyJob(job *AWSEC2CopyJob, parent uuid.UUID, channel string) (uuid.UUID, error) {
|
||||
return s.enqueue(JobTypeAWSEC2Copy, job, []uuid.UUID{parent}, channel)
|
||||
}
|
||||
|
||||
func (s *Server) EnqueueAWSEC2ShareJob(job *AWSEC2ShareJob, parent uuid.UUID, channel string) (uuid.UUID, error) {
|
||||
return s.enqueue(JobTypeAWSEC2Share, job, []uuid.UUID{parent}, channel)
|
||||
}
|
||||
|
||||
func (s *Server) enqueue(jobType string, job interface{}, dependencies []uuid.UUID, channel string) (uuid.UUID, error) {
|
||||
prometheus.EnqueueJobMetrics(strings.Split(jobType, ":")[0], channel)
|
||||
return s.jobs.Enqueue(jobType, job, dependencies, channel)
|
||||
|
|
@ -359,6 +369,32 @@ func (s *Server) ContainerResolveJobInfo(id uuid.UUID, result *ContainerResolveJ
|
|||
return jobInfo, nil
|
||||
}
|
||||
|
||||
func (s *Server) AWSEC2CopyJobInfo(id uuid.UUID, result *AWSEC2CopyJobResult) (*JobInfo, error) {
|
||||
jobInfo, err := s.jobInfo(id, result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if jobInfo.JobType != JobTypeAWSEC2Copy {
|
||||
return nil, fmt.Errorf("expected %q, found %q job instead", JobTypeAWSEC2Copy, jobInfo.JobType)
|
||||
}
|
||||
|
||||
return jobInfo, nil
|
||||
}
|
||||
|
||||
func (s *Server) AWSEC2ShareJobInfo(id uuid.UUID, result *AWSEC2ShareJobResult) (*JobInfo, error) {
|
||||
jobInfo, err := s.jobInfo(id, result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if jobInfo.JobType != JobTypeAWSEC2Share {
|
||||
return nil, fmt.Errorf("expected %q, found %q job instead", JobTypeAWSEC2Share, jobInfo.JobType)
|
||||
}
|
||||
|
||||
return jobInfo, nil
|
||||
}
|
||||
|
||||
func (s *Server) jobInfo(id uuid.UUID, result interface{}) (*JobInfo, error) {
|
||||
jobType, channel, rawResult, queued, started, finished, canceled, deps, err := s.jobs.JobStatus(id)
|
||||
if err != nil {
|
||||
|
|
@ -624,6 +660,20 @@ func (s *Server) FinishJob(token uuid.UUID, result json.RawMessage) error {
|
|||
return err
|
||||
}
|
||||
jobResult = &kojiFinalizeJR.JobResult
|
||||
case JobTypeAWSEC2Copy:
|
||||
var awsEC2CopyJR AWSEC2CopyJobResult
|
||||
jobInfo, err = s.AWSEC2CopyJobInfo(jobId, &awsEC2CopyJR)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jobResult = &awsEC2CopyJR.JobResult
|
||||
case JobTypeAWSEC2Share:
|
||||
var awsEC2ShareJR AWSEC2ShareJobResult
|
||||
jobInfo, err = s.AWSEC2ShareJobInfo(jobId, &awsEC2ShareJR)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
jobResult = &awsEC2ShareJR.JobResult
|
||||
|
||||
case JobTypeContainerResolve:
|
||||
var containerResolveJR ContainerResolveJobResult
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue