コード例 #1
0
ファイル: sqldb_containers.go プロジェクト: xoebus/checkin
func scanContainer(row scannable) (SavedContainer, error) {
	var (
		resourceID       sql.NullInt64
		checkSourceBlob  []byte
		buildID          sql.NullInt64
		planID           sql.NullString
		stage            string
		buildName        sql.NullString
		resourceName     sql.NullString
		pipelineID       sql.NullInt64
		pipelineName     sql.NullString
		jobName          sql.NullString
		infoType         string
		envVariablesBlob []byte
		attempts         sql.NullString
		ttlInSeconds     *float64
	)
	container := SavedContainer{}

	err := row.Scan(
		&container.WorkerName,
		&resourceID,
		&container.CheckType,
		&checkSourceBlob,
		&buildID,
		&planID,
		&stage,
		&container.Handle,
		&buildName,
		&resourceName,
		&pipelineID,
		&pipelineName,
		&jobName,
		&container.StepName,
		&infoType,
		&container.WorkingDirectory,
		&envVariablesBlob,
		&attempts,
		&container.User,
		&container.TTL,
		&ttlInSeconds,
	)
	if err != nil {
		return SavedContainer{}, err
	}

	if resourceID.Valid {
		container.ResourceID = int(resourceID.Int64)
	}

	if buildID.Valid {
		container.ContainerIdentifier.BuildID = int(buildID.Int64)
	}

	container.PlanID = atc.PlanID(planID.String)

	container.Stage = ContainerStage(stage)

	if buildName.Valid {
		container.BuildName = buildName.String
	}

	if resourceName.Valid {
		container.ResourceName = resourceName.String
	}

	if pipelineID.Valid {
		container.PipelineID = int(pipelineID.Int64)
	}

	if pipelineName.Valid {
		container.PipelineName = pipelineName.String
	}

	if jobName.Valid {
		container.JobName = jobName.String
	}

	container.Type, err = ContainerTypeFromString(infoType)
	if err != nil {
		return SavedContainer{}, err
	}

	err = json.Unmarshal(checkSourceBlob, &container.CheckSource)
	if err != nil {
		return SavedContainer{}, err
	}

	err = json.Unmarshal(envVariablesBlob, &container.EnvironmentVariables)
	if err != nil {
		return SavedContainer{}, err
	}

	if attempts.Valid {
		err = json.Unmarshal([]byte(attempts.String), &container.Attempts)
		if err != nil {
			return SavedContainer{}, err
		}
	}

	//TODO remove this check once all containers have a user
	// specifically waiting upon worker provided resources to
	// use image resources that specifiy a metadata.json with
	// a user
	if container.User == "" {
		container.User = "******"
	}

	if ttlInSeconds != nil {
		container.ExpiresIn = time.Duration(*ttlInSeconds) * time.Second
	}

	return container, nil
}
コード例 #2
0
				identifier = db.VolumeIdentifier{
					ResourceVersion: atc.Version{"ref": "asdf"},
					ResourceHash:    "our-super-sweet-resource-hash",
				}
			})

			It("calls through to the database", func() {
				fakeDB.SaveImageResourceVersionReturns(nil)

				err := inputDelegate.ImageVersionDetermined(identifier)
				Expect(err).ToNot(HaveOccurred())

				Expect(fakeDB.SaveImageResourceVersionCallCount()).To(Equal(1))
				actualBuildID, actualPlanID, actualIdentifier := fakeDB.SaveImageResourceVersionArgsForCall(0)
				Expect(actualBuildID).To(Equal(42))
				Expect(actualPlanID).To(Equal(atc.PlanID("some-origin-id")))
				Expect(actualIdentifier).To(Equal(identifier))
			})

			It("propagates errors", func() {
				distaster := errors.New("sorry mate")
				fakeDB.SaveImageResourceVersionReturns(distaster)

				err := inputDelegate.ImageVersionDetermined(identifier)
				Expect(err).To(Equal(distaster))
			})
		})

		Describe("Stdout", func() {
			var writer io.Writer
コード例 #3
0
func (execution *executionDelegate) ImageVersionDetermined(identifier db.VolumeIdentifier) error {
	return execution.delegate.db.SaveImageResourceVersion(execution.delegate.buildID, atc.PlanID(execution.id), identifier)
}
コード例 #4
0
func (output *outputDelegate) ImageVersionDetermined(identifier db.VolumeIdentifier) error {
	return output.delegate.db.SaveImageResourceVersion(output.delegate.buildID, atc.PlanID(output.id), identifier)
}
コード例 #5
0
ファイル: db_provider_test.go プロジェクト: pcfdev-forks/atc
		})

		Context("when we find no workers", func() {
			It("returns found as false", func() {
				fakeDB.GetWorkerReturns(db.SavedWorker{}, false, nil)

				worker, found, workersErr = provider.GetWorker("no-worker")
				Expect(workersErr).NotTo(HaveOccurred())
				Expect(worker).To(BeNil())
				Expect(found).To(BeFalse())
			})
		})
	})

	Context("when we call to get a container info by identifier", func() {
		It("calls through to the db object", func() {
			provider.FindContainerForIdentifier(Identifier{
				BuildID: 1234,
				PlanID:  atc.PlanID("planid"),
			})

			Expect(fakeDB.FindContainerByIdentifierCallCount()).To(Equal(1))

			Expect(fakeDB.FindContainerByIdentifierArgsForCall(0)).To(Equal(db.ContainerIdentifier{
				BuildID: 1234,
				PlanID:  atc.PlanID("planid"),
			}))
		})
	})
})
コード例 #6
0
)

var _ = Describe("GardenFactory", func() {
	var (
		fakeTracker        *rfakes.FakeTracker
		fakeTrackerFactory *fakes.FakeTrackerFactory
		fakeWorkerClient   *wfakes.FakeClient

		factory Factory

		stdoutBuf *gbytes.Buffer
		stderrBuf *gbytes.Buffer

		identifier = worker.Identifier{
			BuildID: 1234,
			PlanID:  atc.PlanID("some-plan-id"),
		}
		workerMetadata = worker.Metadata{
			PipelineName: "some-pipeline",
			Type:         db.ContainerTypeGet,
			StepName:     "some-step",
		}

		stepMetadata testMetadata = []string{"a=1", "b=2"}

		sourceName SourceName = "some-source-name"
	)

	BeforeEach(func() {
		fakeTracker = new(rfakes.FakeTracker)
		fakeTrackerFactory = new(fakes.FakeTrackerFactory)