示例#1
0
func stripIDs(plan atc.Plan) (atc.Plan, []string) {
	var ids []string

	var subIDs []string

	plan.ID = "<stripped>"

	if plan.Aggregate != nil {
		for i, p := range *plan.Aggregate {
			(*plan.Aggregate)[i], subIDs = stripIDs(p)
			ids = append(ids, subIDs...)
		}
	}

	if plan.Do != nil {
		for i, p := range *plan.Do {
			(*plan.Do)[i], subIDs = stripIDs(p)
			ids = append(ids, subIDs...)
		}
	}

	if plan.OnSuccess != nil {
		plan.OnSuccess.Step, subIDs = stripIDs(plan.OnSuccess.Step)
		ids = append(ids, subIDs...)

		plan.OnSuccess.Next, subIDs = stripIDs(plan.OnSuccess.Next)
		ids = append(ids, subIDs...)
	}

	if plan.OnFailure != nil {
		plan.OnFailure.Step, subIDs = stripIDs(plan.OnFailure.Step)
		ids = append(ids, subIDs...)

		plan.OnFailure.Next, subIDs = stripIDs(plan.OnFailure.Next)
		ids = append(ids, subIDs...)
	}

	if plan.Ensure != nil {
		plan.Ensure.Step, subIDs = stripIDs(plan.Ensure.Step)
		ids = append(ids, subIDs...)

		plan.Ensure.Next, subIDs = stripIDs(plan.Ensure.Next)
		ids = append(ids, subIDs...)
	}

	if plan.Timeout != nil {
		plan.Timeout.Step, subIDs = stripIDs(plan.Timeout.Step)
		ids = append(ids, subIDs...)
	}

	if plan.Try != nil {
		plan.Try.Step, subIDs = stripIDs(plan.Try.Step)
		ids = append(ids, subIDs...)
	}

	return plan, ids
}
示例#2
0
func makeConditionalOnSuccess(plan atc.Plan) atc.Plan {
	if plan.Conditional != nil {
		return plan
	} else if plan.Aggregate != nil {
		conditionaled := atc.AggregatePlan{}
		for _, plan := range *plan.Aggregate {
			conditionaled = append(conditionaled, makeConditionalOnSuccess(plan))
		}

		plan.Aggregate = &conditionaled
	} else {
		plan = atc.Plan{
			Conditional: &atc.ConditionalPlan{
				Conditions: atc.Conditions{atc.ConditionSuccess},
				Plan:       plan,
			},
		}
	}

	return plan
}
示例#3
0
		plan := atc.Plan{
			ID: "0",
			Aggregate: &atc.AggregatePlan{
				atc.Plan{
					ID: "1",
					Aggregate: &atc.AggregatePlan{
						atc.Plan{
							ID: "2",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
					},
				},

				atc.Plan{
					ID: "3",
					Get: &atc.GetPlan{
						Type:     "type",
						Name:     "name",
						Resource: "resource",
						Pipeline: "pipeline",
						Source:   atc.Source{"some": "source"},
						Params:   atc.Params{"some": "params"},
						Version:  atc.Version{"some": "version"},
						Tags:     atc.Tags{"tags"},
					},
				},

				atc.Plan{
					ID: "4",
					Put: &atc.PutPlan{
						Type:     "type",
						Name:     "name",
						Resource: "resource",
						Pipeline: "pipeline",
						Source:   atc.Source{"some": "source"},
						Params:   atc.Params{"some": "params"},
						Tags:     atc.Tags{"tags"},
					},
				},

				atc.Plan{
					ID: "5",
					Task: &atc.TaskPlan{
						Name:       "name",
						Privileged: true,
						Tags:       atc.Tags{"tags"},
						ConfigPath: "some/config/path.yml",
						Config: &atc.TaskConfig{
							Params: map[string]string{"some": "secret"},
						},
						Pipeline: "pipeline",
					},
				},

				atc.Plan{
					ID: "6",
					Ensure: &atc.EnsurePlan{
						Step: atc.Plan{
							ID: "7",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
						Next: atc.Plan{
							ID: "8",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
					},
				},

				atc.Plan{
					ID: "9",
					OnSuccess: &atc.OnSuccessPlan{
						Step: atc.Plan{
							ID: "10",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
						Next: atc.Plan{
							ID: "11",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
					},
				},

				atc.Plan{
					ID: "12",
					OnFailure: &atc.OnFailurePlan{
						Step: atc.Plan{
							ID: "13",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
						Next: atc.Plan{
							ID: "14",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
					},
				},

				atc.Plan{
					ID: "15",
					Try: &atc.TryPlan{
						Step: atc.Plan{
							ID: "16",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
					},
				},

				atc.Plan{
					ID: "17",
					DependentGet: &atc.DependentGetPlan{
						Type:     "type",
						Name:     "name",
						Resource: "resource",
						Pipeline: "pipeline",
						Source:   atc.Source{"some": "source"},
						Params:   atc.Params{"some": "params"},
						Tags:     atc.Tags{"tags"},
					},
				},

				atc.Plan{
					ID: "18",
					Timeout: &atc.TimeoutPlan{
						Step: atc.Plan{
							ID: "19",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
						Duration: "lol",
					},
				},

				atc.Plan{
					ID: "20",
					Do: &atc.DoPlan{
						atc.Plan{
							ID: "21",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
					},
				},

				atc.Plan{
					ID: "22",
					Retry: &atc.RetryPlan{
						atc.Plan{
							ID: "23",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
						atc.Plan{
							ID: "24",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
						atc.Plan{
							ID: "25",
							Task: &atc.TaskPlan{
								Name:       "name",
								ConfigPath: "some/config/path.yml",
								Config: &atc.TaskConfig{
									Params: map[string]string{"some": "secret"},
								},
							},
						},
					},
				},
			},
		}
示例#4
0
func (factory *BuildFactory) constructPlanFromConfig(
	planConfig atc.PlanConfig,
	resources atc.ResourceConfigs,
	inputs []db.BuildInput,
	hasHooks bool,
) atc.Plan {
	var plan atc.Plan

	switch {
	case planConfig.Do != nil:
		if hasHooks {
			plan = factory.constructPlanHookBasedPlan(
				*planConfig.Do,
				resources,
				inputs,
			)
		} else {
			plan = factory.constructPlanSequenceBasedPlan(
				*planConfig.Do,
				resources,
				inputs,
			)
		}
		if plan.Location == nil {
			plan.Location = planConfig.Location
		}

	case planConfig.Put != "":
		logicalName := planConfig.Put

		resourceName := planConfig.Resource
		if resourceName == "" {
			resourceName = logicalName
		}

		resource, _ := resources.Lookup(resourceName)

		putPlan := &atc.PutPlan{
			Type:     resource.Type,
			Name:     logicalName,
			Pipeline: factory.PipelineName,
			Resource: resourceName,
			Source:   resource.Source,
			Params:   planConfig.Params,
			Tags:     planConfig.Tags,
		}

		dependentGetPlan := &atc.DependentGetPlan{
			Type:     resource.Type,
			Name:     logicalName,
			Pipeline: factory.PipelineName,
			Resource: resourceName,
			Params:   planConfig.GetParams,
			Tags:     planConfig.Tags,
			Source:   resource.Source,
		}

		stepLocation := &atc.Location{}
		nextLocation := &atc.Location{}

		if planConfig.Location != nil {
			stepLocation.ID = planConfig.Location.ID
			stepLocation.Hook = planConfig.Location.Hook

			if planConfig.Location.ParallelGroup != 0 {
				stepLocation.ParallelGroup = planConfig.Location.ParallelGroup
			} else {
				stepLocation.ParentID = planConfig.Location.ParentID
			}

			nextLocation.ID = stepLocation.ID + 1
			nextLocation.ParentID = stepLocation.ID
		}

		plan = atc.Plan{
			// Location: planConfig.Location,
			OnSuccess: &atc.OnSuccessPlan{
				Step: atc.Plan{
					Location: stepLocation,
					Put:      putPlan,
				},
				Next: atc.Plan{
					Location:     nextLocation,
					DependentGet: dependentGetPlan,
				},
			},
		}

	case planConfig.Get != "":
		resourceName := planConfig.Resource
		if resourceName == "" {
			resourceName = planConfig.Get
		}

		resource, _ := resources.Lookup(resourceName)

		name := planConfig.Get
		var version db.Version
		for _, input := range inputs {
			if input.Name == name {
				version = input.Version
				break
			}
		}

		plan = atc.Plan{
			Location: planConfig.Location,
			Get: &atc.GetPlan{
				Type:     resource.Type,
				Name:     name,
				Pipeline: factory.PipelineName,
				Resource: resourceName,
				Source:   resource.Source,
				Params:   planConfig.Params,
				Version:  atc.Version(version),
				Tags:     planConfig.Tags,
			},
		}

	case planConfig.Task != "":
		plan = atc.Plan{
			Location: planConfig.Location,
			Task: &atc.TaskPlan{
				Name:       planConfig.Task,
				Privileged: planConfig.Privileged,
				Config:     planConfig.TaskConfig,
				ConfigPath: planConfig.TaskConfigPath,
				Tags:       planConfig.Tags,
			},
		}

	case planConfig.Try != nil:
		nextStep := factory.constructPlanFromConfig(
			*planConfig.Try,
			resources,
			inputs,
			hasHooks)

		plan = atc.Plan{
			Location: planConfig.Location,
			Try: &atc.TryPlan{
				Step: nextStep,
			},
		}

	case planConfig.Aggregate != nil:
		aggregate := atc.AggregatePlan{}

		for _, planConfig := range *planConfig.Aggregate {
			nextStep := factory.constructPlanFromConfig(
				planConfig,
				resources,
				inputs,
				hasHooks)

			aggregate = append(aggregate, nextStep)
		}

		plan = atc.Plan{
			Location:  planConfig.Location,
			Aggregate: &aggregate,
		}
	}

	if planConfig.Conditions != nil {
		plan = atc.Plan{
			Conditional: &atc.ConditionalPlan{
				Conditions: *planConfig.Conditions,
				Plan:       plan,
			},
		}
	}

	if planConfig.Timeout != "" {
		plan = atc.Plan{
			Timeout: &atc.TimeoutPlan{
				Duration: planConfig.Timeout,
				Step:     plan,
			},
		}
	}

	constructionParams := factory.ensureIfPresent(factory.successIfPresent(factory.failureIfPresent(
		constructionParams{
			plan:       plan,
			planConfig: planConfig,
			resources:  resources,
			inputs:     inputs,
			hasHooks:   hasHooks,
		})),
	)

	return constructionParams.plan
}
示例#5
0
					build, err = execEngine.CreateBuild(logger, buildModel, plan)
					Expect(err).NotTo(HaveOccurred())

					build.Resume(logger)
					Expect(outputStep.ReleaseCallCount()).To(Equal(1))
					Expect(dependentStep.ReleaseCallCount()).To(Equal(1))
				})
			})
		})
	})

	Describe("PublicPlan", func() {
		var build engine.Build
		var logger lager.Logger

		var plan atc.Plan

		var publicPlan atc.PublicBuildPlan
		var planFound bool
		var publicPlanErr error

		BeforeEach(func() {
			logger = lagertest.NewTestLogger("test")

			planFactory := atc.NewPlanFactory(123)

			plan = planFactory.NewPlan(atc.OnSuccessPlan{
				Step: planFactory.NewPlan(atc.PutPlan{
					Name:     "some-put",
					Resource: "some-output-resource",
					Tags:     []string{"some", "putget", "tags"},