Example #1
0
func (build *execBuild) buildTaskStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
	logger = logger.Session("task")

	var configSource exec.TaskConfigSource
	if plan.Task.Config != nil && plan.Task.ConfigPath != "" {
		configSource = exec.MergedConfigSource{
			A: exec.FileConfigSource{plan.Task.ConfigPath},
			B: exec.StaticConfigSource{*plan.Task.Config},
		}
	} else if plan.Task.Config != nil {
		configSource = exec.StaticConfigSource{*plan.Task.Config}
	} else if plan.Task.ConfigPath != "" {
		configSource = exec.FileConfigSource{plan.Task.ConfigPath}
	} else {
		return exec.Identity{}
	}

	var location event.OriginLocation
	if plan.Location != nil {
		location = event.OriginLocationFrom(*plan.Location)
	}

	pipelineName := plan.Task.Pipeline

	return build.factory.Task(
		logger,
		exec.SourceName(plan.Task.Name),
		build.taskIdentifier(plan.Task.Name, location, pipelineName),
		build.delegate.ExecutionDelegate(logger, *plan.Task, location),
		exec.Privileged(plan.Task.Privileged),
		plan.Task.Tags,
		configSource,
	)
}
Example #2
0
func (build *execBuild) buildTaskStep(logger lager.Logger, plan atc.Plan) exec.StepFactory {
	logger = logger.Session("task")

	var configSource exec.TaskConfigSource
	if plan.Task.ConfigPath != "" && (plan.Task.Config != nil || plan.Task.Params != nil) {
		configSource = exec.MergedConfigSource{
			A: exec.FileConfigSource{plan.Task.ConfigPath},
			B: exec.StaticConfigSource{*plan.Task},
		}
	} else if plan.Task.Config != nil {
		configSource = exec.StaticConfigSource{*plan.Task}
	} else if plan.Task.ConfigPath != "" {
		configSource = exec.FileConfigSource{plan.Task.ConfigPath}
	} else {
		return exec.Identity{}
	}

	configSource = exec.ValidatingConfigSource{configSource}

	workerID, workerMetadata := build.stepIdentifier(
		logger.Session("taskIdentifier"),
		plan.Task.Name,
		plan.ID,
		plan.Task.PipelineID,
		plan.Attempts,
		"task",
	)

	clock := clock.NewClock()

	return build.factory.Task(
		logger,
		exec.SourceName(plan.Task.Name),
		workerID,
		workerMetadata,
		build.delegate.ExecutionDelegate(logger, *plan.Task, event.OriginID(plan.ID)),
		exec.Privileged(plan.Task.Privileged),
		plan.Task.Tags,
		configSource,
		plan.Task.ResourceTypes,
		plan.Task.InputMapping,
		plan.Task.OutputMapping,
		clock,
	)
}
Example #3
0
			Ω(params).Should(Equal(atc.Params{"some": "params"}))
			Ω(version).Should(Equal(atc.Version{"some": "version"}))
		})

		It("constructs tasks correctly", func() {
			Ω(fakeFactory.TaskCallCount()).Should(Equal(1))

			sourceName, workerID, delegate, privileged, tags, configSource := fakeFactory.TaskArgsForCall(0)
			Ω(sourceName).Should(Equal(exec.SourceName("some-task")))
			Ω(workerID).Should(Equal(worker.Identifier{
				BuildID: 42,
				Type:    worker.ContainerTypeTask,
				Name:    "some-task",
			}))
			Ω(delegate).Should(Equal(fakeExecutionDelegate))
			Ω(privileged).Should(Equal(exec.Privileged(false)))
			Ω(tags).Should(BeEmpty())
			Ω(configSource).ShouldNot(BeNil())
		})

		Context("constructing outputs", func() {
			It("constructs the put correctly", func() {
				Ω(fakeFactory.PutCallCount()).Should(Equal(1))

				workerID, delegate, resourceConfig, tags, params := fakeFactory.PutArgsForCall(0)
				Ω(workerID).Should(Equal(worker.Identifier{
					BuildID: 42,
					Type:    worker.ContainerTypePut,
					Name:    "some-put",
				}))
				Ω(delegate).Should(Equal(fakeOutputDelegate))
Example #4
0
					build.Resume(logger)
					Expect(fakeFactory.TaskCallCount()).To(Equal(1))

					logger, sourceName, workerID, delegate, privileged, tags, configSource := fakeFactory.TaskArgsForCall(0)
					Expect(logger).NotTo(BeNil())
					Expect(sourceName).To(Equal(exec.SourceName("some-task")))
					Expect(workerID).To(Equal(worker.Identifier{
						BuildID:      42,
						Type:         db.ContainerTypeTask,
						Name:         "some-task",
						PipelineName: "some-pipeline",
						StepLocation: 123,
					}))

					Expect(privileged).To(Equal(exec.Privileged(false)))
					Expect(tags).To(BeEmpty())
					Expect(configSource).NotTo(BeNil())

					Expect(delegate).To(Equal(fakeExecutionDelegate))
					_, _, location := fakeDelegate.ExecutionDelegateArgsForCall(0)

					Expect(location).NotTo(BeNil())
					Expect(location.ID).To(Equal(uint(123)))
					Expect(location.ParentID).To(Equal(uint(41)))
					Expect(location.ParallelGroup).To(Equal(uint(123498)))
					Expect(location.SerialGroup).To(Equal(uint(69)))
					Expect(location.Hook).To(Equal("look at me I'm a hook"))
				})

				It("releases the tasks correctly", func() {
Example #5
0
func (build *execBuild) buildStepFactory(logger lager.Logger, plan atc.Plan) exec.StepFactory {
	if plan.Aggregate != nil {

		logger = logger.Session("aggregate")

		step := exec.Aggregate{}

		for _, innerPlan := range *plan.Aggregate {
			stepFactory := build.buildStepFactory(logger, innerPlan)

			step = append(step, stepFactory)
		}

		return step
	}

	if plan.Timeout != nil {
		step := build.buildStepFactory(logger, plan.Timeout.Step)
		return exec.Timeout(step, plan.Timeout.Duration)
	}

	if plan.Try != nil {
		step := build.buildStepFactory(logger, plan.Try.Step)
		return exec.Try(step)
	}

	if plan.OnSuccess != nil {
		step := build.buildStepFactory(logger, plan.OnSuccess.Step)
		next := build.buildStepFactory(logger, plan.OnSuccess.Next)
		return exec.OnSuccess(step, next)
	}

	if plan.OnFailure != nil {
		step := build.buildStepFactory(logger, plan.OnFailure.Step)
		next := build.buildStepFactory(logger, plan.OnFailure.Next)
		return exec.OnFailure(step, next)
	}

	if plan.Ensure != nil {
		step := build.buildStepFactory(logger, plan.Ensure.Step)
		next := build.buildStepFactory(logger, plan.Ensure.Next)
		return exec.Ensure(step, next)
	}

	if plan.Compose != nil {
		x := build.buildStepFactory(logger, plan.Compose.A)
		y := build.buildStepFactory(logger, plan.Compose.B)
		return exec.Compose(x, y)
	}

	if plan.Conditional != nil {
		logger = logger.Session("conditional", lager.Data{
			"on": plan.Conditional.Conditions,
		})

		steps := build.buildStepFactory(logger, plan.Conditional.Plan)

		return exec.Conditional{
			Conditions:  plan.Conditional.Conditions,
			StepFactory: steps,
		}
	}

	if plan.Task != nil {
		logger = logger.Session("task")

		var configSource exec.TaskConfigSource
		if plan.Task.Config != nil && plan.Task.ConfigPath != "" {
			configSource = exec.MergedConfigSource{
				A: exec.FileConfigSource{plan.Task.ConfigPath},
				B: exec.StaticConfigSource{*plan.Task.Config},
			}
		} else if plan.Task.Config != nil {
			configSource = exec.StaticConfigSource{*plan.Task.Config}
		} else if plan.Task.ConfigPath != "" {
			configSource = exec.FileConfigSource{plan.Task.ConfigPath}
		} else {
			return exec.Identity{}
		}

		var location event.OriginLocation
		if plan.Location != nil {
			location = event.OriginLocationFrom(*plan.Location)
		}

		return build.factory.Task(
			exec.SourceName(plan.Task.Name),
			build.taskIdentifier(plan.Task.Name, location),
			build.delegate.ExecutionDelegate(logger, *plan.Task, location),
			exec.Privileged(plan.Task.Privileged),
			plan.Task.Tags,
			configSource,
		)
	}

	if plan.Get != nil {
		logger = logger.Session("get", lager.Data{
			"name": plan.Get.Name,
		})

		var location event.OriginLocation
		if plan.Location != nil {
			location = event.OriginLocationFrom(*plan.Location)
		}

		return build.factory.Get(
			exec.SourceName(plan.Get.Name),
			build.getIdentifier(plan.Get.Name, location),
			build.delegate.InputDelegate(logger, *plan.Get, location),
			atc.ResourceConfig{
				Name:   plan.Get.Resource,
				Type:   plan.Get.Type,
				Source: plan.Get.Source,
			},
			plan.Get.Params,
			plan.Get.Tags,
			plan.Get.Version,
		)
	}

	if plan.Put != nil {
		logger = logger.Session("put", lager.Data{
			"name": plan.Put.Name,
		})

		var location event.OriginLocation
		if plan.Location != nil {
			location = event.OriginLocationFrom(*plan.Location)
		}

		return build.factory.Put(
			build.putIdentifier(plan.Put.Name, location),
			build.delegate.OutputDelegate(logger, *plan.Put, location),
			atc.ResourceConfig{
				Name:   plan.Put.Resource,
				Type:   plan.Put.Type,
				Source: plan.Put.Source,
			},
			plan.Put.Tags,
			plan.Put.Params,
		)
	}

	if plan.DependentGet != nil {
		logger = logger.Session("get", lager.Data{
			"name": plan.DependentGet.Name,
		})

		var location event.OriginLocation
		if plan.Location != nil {
			location = event.OriginLocationFrom(*plan.Location)
		}

		getPlan := plan.DependentGet.GetPlan()
		return build.factory.DependentGet(
			exec.SourceName(getPlan.Name),
			build.getIdentifier(getPlan.Name, location),
			build.delegate.InputDelegate(logger, getPlan, location),
			atc.ResourceConfig{
				Name:   getPlan.Resource,
				Type:   getPlan.Type,
				Source: getPlan.Source,
			},
			getPlan.Tags,
			getPlan.Params,
		)
	}

	return exec.Identity{}
}