Add Config argument to Create of DyradJobManager 71/162371/1
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Wed, 29 Nov 2017 15:32:38 +0000 (16:32 +0100)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 30 Nov 2017 13:25:57 +0000 (14:25 +0100)
Change-Id: Ibc8d13e7131a2690d0874d281011f440b179c57c
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
dryadjobmanager.go
manager/dryad_job.go
manager/dryad_job_manager.go
manager/dryad_job_manager_test.go
manager/dryad_job_runner.go
manager/dryad_job_runner_test.go

index 1a1b79a..5ede866 100644 (file)
@@ -62,9 +62,12 @@ type DryadJobFilter struct {
 // DryadJobManager organizes running Jobs on allocated Dryad.
 type DryadJobManager interface {
        // Create starts execution of Job definition on allocated Dryad.
+       // Job's config is passed in order to avoid need to fetch it from Job Manager.
+       //
+       // JobID is used only to reference currently executing Jobs.
        //
        // Slow read from a channel may miss some events.
-       Create(JobID, Dryad, chan<- DryadJobStatusChange) error
+       Create(JobID, Dryad, Config, chan<- DryadJobStatusChange) error
 
        // Cancel stops DryadJob associated with Job.
        //
index 21cc5d1..59b0607 100644 (file)
@@ -54,12 +54,12 @@ func newDryadJobWithCancel(job JobID, changes chan<- DryadJobStatusChange,
 
 // newDryadJob creates an instance of dryadJob and starts a goroutine
 // executing phases of given job implemented by provider of DryadJobRunner interface.
-func newDryadJob(job JobID, rusalka Dryad, changes chan<- DryadJobStatusChange) *dryadJob {
+func newDryadJob(job JobID, rusalka Dryad, conf Config, changes chan<- DryadJobStatusChange) *dryadJob {
        session := dryad.NewSessionProvider(rusalka)
        device := dryad.NewDeviceCommunicationProvider(session)
 
        ctx, cancel := context.WithCancel(context.Background())
-       runner := newDryadJobRunner(ctx, session, device)
+       runner := newDryadJobRunner(ctx, session, device, conf)
 
        dJob := newDryadJobWithCancel(job, changes, runner, cancel)
 
index 3e0dcdb..530261a 100644 (file)
@@ -40,7 +40,7 @@ func NewDryadJobManager() DryadJobManager {
 }
 
 // Create is part of DryadJobManager interface.
-func (d *DryadJobs) Create(job JobID, rusalka Dryad, changes chan<- DryadJobStatusChange) error {
+func (d *DryadJobs) Create(job JobID, rusalka Dryad, conf Config, changes chan<- DryadJobStatusChange) error {
        _, ok := d.jobs[job]
        if ok {
                return ErrDuplicated
@@ -48,7 +48,7 @@ func (d *DryadJobs) Create(job JobID, rusalka Dryad, changes chan<- DryadJobStat
        d.jobsMutex.Lock()
        defer d.jobsMutex.Unlock()
        // FIXME(amistewicz): dryadJobs should not be stored indefinitely.
-       d.jobs[job] = newDryadJob(job, rusalka, changes)
+       d.jobs[job] = newDryadJob(job, rusalka, conf, changes)
        return nil
 }
 
index a543289..795c99c 100644 (file)
@@ -35,7 +35,7 @@ var _ = Describe("DryadJobManager", func() {
        })
 
        create := func() {
-               err := djm.Create(jobID, Dryad{}, nil)
+               err := djm.Create(jobID, Dryad{}, Config{}, nil)
                Expect(err).ToNot(HaveOccurred())
        }
 
@@ -51,7 +51,7 @@ var _ = Describe("DryadJobManager", func() {
        It("should fail to duplicate jobs", func() {
                create()
 
-               err := djm.Create(jobID, Dryad{}, nil)
+               err := djm.Create(jobID, Dryad{}, Config{}, nil)
                Expect(err).To(Equal(ErrDuplicated))
        })
 
index 5b279c2..94e2770 100644 (file)
@@ -21,6 +21,7 @@ package manager
 import (
        "context"
 
+       "git.tizen.org/tools/weles"
        "git.tizen.org/tools/weles/manager/dryad"
 )
 
@@ -30,15 +31,18 @@ type dryadJobRunner struct {
        ctx     context.Context
        rusalka dryad.SessionProvider
        device  dryad.DeviceCommunicationProvider
+       conf    weles.Config
 }
 
 // newDryadJobRunner prepares a new instance of dryadJobRunner
 // and returns DryadJobRunner interface to it.
-func newDryadJobRunner(ctx context.Context, rusalka dryad.SessionProvider, device dryad.DeviceCommunicationProvider) DryadJobRunner {
+func newDryadJobRunner(ctx context.Context, rusalka dryad.SessionProvider,
+       device dryad.DeviceCommunicationProvider, conf weles.Config) DryadJobRunner {
        return &dryadJobRunner{
                ctx:     ctx,
                rusalka: rusalka,
                device:  device,
+               conf:    conf,
        }
 }
 
index e91ae57..8e4a810 100644 (file)
@@ -20,6 +20,8 @@ import (
        "context"
        "errors"
 
+       "git.tizen.org/tools/weles"
+
        "github.com/golang/mock/gomock"
        . "github.com/onsi/ginkgo"
        . "github.com/onsi/gomega"
@@ -37,7 +39,7 @@ var _ = Describe("DryadJobRunner", func() {
                ctrl = gomock.NewController(GinkgoT())
                mockSession = NewMockSessionProvider(ctrl)
                mockDevice = NewMockDeviceCommunicationProvider(ctrl)
-               djr = newDryadJobRunner(context.Background(), mockSession, mockDevice)
+               djr = newDryadJobRunner(context.Background(), mockSession, mockDevice, weles.Config{})
        })
 
        AfterEach(func() {