コード例 #1
0
ファイル: conversion_helpers.go プロジェクト: jianhuiz/rep
func NewRunRequestFromTask(task *models.Task) (executor.RunRequest, error) {
	diskScope, err := diskScopeForRootFS(task.RootFs)
	if err != nil {
		return executor.RunRequest{}, err
	}

	tags := executor.Tags{
		ResultFileTag: task.ResultFile,
	}
	runInfo := executor.RunInfo{
		DiskScope:  diskScope,
		CPUWeight:  uint(task.CpuWeight),
		Privileged: task.Privileged,

		LogConfig: executor.LogConfig{
			Guid:       task.LogGuid,
			SourceName: task.LogSource,
		},
		MetricsConfig: executor.MetricsConfig{
			Guid: task.MetricsGuid,
		},
		Action:      task.Action,
		Env:         executor.EnvironmentVariablesFromModel(task.EnvironmentVariables),
		EgressRules: task.EgressRules,
	}
	return executor.NewRunRequest(task.TaskGuid, &runInfo, tags), nil
}
コード例 #2
0
ファイル: depot_test.go プロジェクト: snowsnail/executor
func newRunRequest(guid string) *executor.RunRequest {
	runInfo := executor.RunInfo{
	// TODO: Fill in required fields.
	}
	r := executor.NewRunRequest(guid, &runInfo, nil)
	return &r
}
コード例 #3
0
func (expectation transitionExpectation) driveFromState(allocationStore *allocationstore.AllocationStore, container executor.Container) {
	allocationRequest := executor.NewAllocationRequest(container.Guid, &container.Resource, container.Tags)
	runReq := executor.NewRunRequest(container.Guid, &container.RunInfo, container.Tags)

	switch expectation.from {
	case "non-existent":

	case "reserved":
		_, err := allocationStore.Allocate(logger, &allocationRequest)
		Expect(err).NotTo(HaveOccurred())

	case "initializing":
		_, err := allocationStore.Allocate(logger, &allocationRequest)
		Expect(err).NotTo(HaveOccurred())

		err = allocationStore.Initialize(logger, &runReq)
		Expect(err).NotTo(HaveOccurred())

	case "failed":
		_, err := allocationStore.Allocate(logger, &allocationRequest)
		Expect(err).NotTo(HaveOccurred())

		err = allocationStore.Initialize(logger, &runReq)
		Expect(err).NotTo(HaveOccurred())

		_, err = allocationStore.Fail(logger, container.Guid, "failure-reason")
		Expect(err).NotTo(HaveOccurred())

	default:
		Fail("unknown 'from' state: " + expectation.from)
	}
}
コード例 #4
0
ファイル: conversion_helpers.go プロジェクト: jiangytcn/rep
func NewRunRequestFromDesiredLRP(
	containerGuid string,
	desiredLRP *models.DesiredLRP,
	lrpKey *models.ActualLRPKey,
	lrpInstanceKey *models.ActualLRPInstanceKey,
) (executor.RunRequest, error) {
	diskScope, err := diskScopeForRootFS(desiredLRP.RootFs)
	if err != nil {
		return executor.RunRequest{}, err
	}

	runInfo := executor.RunInfo{
		CPUWeight: uint(desiredLRP.CpuWeight),
		DiskScope: diskScope,
		Ports:     ConvertPortMappings(desiredLRP.Ports),
		LogConfig: executor.LogConfig{
			Guid:       desiredLRP.LogGuid,
			Index:      int(lrpKey.Index),
			SourceName: desiredLRP.LogSource,
		},

		MetricsConfig: executor.MetricsConfig{
			Guid:  desiredLRP.MetricsGuid,
			Index: int(lrpKey.Index),
		},
		StartTimeout:       uint(desiredLRP.StartTimeout),
		Privileged:         desiredLRP.Privileged,
		CachedDependencies: ConvertCachedDependencies(desiredLRP.CachedDependencies),
		Setup:              desiredLRP.Setup,
		Action:             desiredLRP.Action,
		Monitor:            desiredLRP.Monitor,
		EgressRules:        desiredLRP.EgressRules,
		Env: append([]executor.EnvironmentVariable{
			{Name: "INSTANCE_GUID", Value: lrpInstanceKey.InstanceGuid},
			{Name: "INSTANCE_INDEX", Value: strconv.Itoa(int(lrpKey.Index))},
			{Name: "CF_INSTANCE_GUID", Value: lrpInstanceKey.InstanceGuid},
			{Name: "CF_INSTANCE_INDEX", Value: strconv.Itoa(int(lrpKey.Index))},
		}, executor.EnvironmentVariablesFromModel(desiredLRP.EnvironmentVariables)...),
	}
	tags := executor.Tags{}
	return executor.NewRunRequest(containerGuid, &runInfo, tags), nil
}
コード例 #5
0
func (expectation transitionExpectation) transitionToState(allocationStore *allocationstore.AllocationStore, container executor.Container) error {
	switch expectation.to {
	case "reserve":
		allocationRequest := executor.NewAllocationRequest(container.Guid, &container.Resource, container.Tags)
		_, err := allocationStore.Allocate(logger, &allocationRequest)
		return err

	case "initialize":
		runReq := executor.NewRunRequest(container.Guid, &container.RunInfo, container.Tags)
		return allocationStore.Initialize(logger, &runReq)

	case "fail":
		_, err := allocationStore.Fail(logger, container.Guid, "failure-reason")
		return err

	default:
		Fail("unknown 'to' state: " + expectation.to)
		return nil
	}
}
コード例 #6
0
	})

	Describe("Initialize", func() {
		var req executor.AllocationRequest

		BeforeEach(func() {
			resource := executor.NewResource(512, 512, "")
			req = executor.NewAllocationRequest("banana", &resource, nil)

			_, err := allocationStore.Allocate(logger, &req)
			Expect(err).NotTo(HaveOccurred())
		})

		Context("when the guid is available", func() {
			It("it is marked as INITIALIZING", func() {
				runReq := executor.NewRunRequest(req.Guid, &executor.RunInfo{}, executor.Tags{})
				err := allocationStore.Initialize(logger, &runReq)
				Expect(err).NotTo(HaveOccurred())

				allocation, err := allocationStore.Lookup(req.Guid)
				Expect(err).NotTo(HaveOccurred())

				Expect(allocation.Guid).To(Equal(req.Guid))
				Expect(allocation.State).To(Equal(executor.StateInitializing))
			})
		})

		Context("when the guid is not available", func() {
			It("errors", func() {
				runReq := executor.NewRunRequest("doesnt-exist", &executor.RunInfo{}, executor.Tags{})
				err := allocationStore.Initialize(logger, &runReq)
コード例 #7
0
	var logger *lagertest.TestLogger
	var expectedGuid = "some-instance-guid"
	const sessionPrefix = "test"

	BeforeEach(func() {
		executorClient = new(fakes.FakeClient)
		containerDelegate = internal.NewContainerDelegate(executorClient)
		logger = lagertest.NewTestLogger(sessionPrefix)
	})

	Describe("RunContainer", func() {
		var result bool
		var runRequest executor.RunRequest

		BeforeEach(func() {
			runRequest = executor.NewRunRequest(expectedGuid, &executor.RunInfo{}, executor.Tags{})
		})

		JustBeforeEach(func() {
			result = containerDelegate.RunContainer(logger, &runRequest)
		})

		It("runs the container", func() {
			Expect(executorClient.RunContainerCallCount()).To(Equal(1))
			_, runReq := executorClient.RunContainerArgsForCall(0)
			Expect(*runReq).To(Equal(runRequest))
		})

		Context("when running succeeds", func() {
			It("returns true", func() {
				Expect(result).To(BeTrue())