예제 #1
0
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
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
}
예제 #3
0
				MetricsConfig: executor.MetricsConfig{
					Guid:  desiredLRP.MetricsGuid,
					Index: int(actualLRP.Index),
				},
				StartTimeout: uint(desiredLRP.StartTimeout),
				Privileged:   desiredLRP.Privileged,
				Setup:        desiredLRP.Setup,
				Action:       desiredLRP.Action,
				Monitor:      desiredLRP.Monitor,
				EgressRules:  desiredLRP.EgressRules,
				Env: append([]executor.EnvironmentVariable{
					{Name: "INSTANCE_GUID", Value: actualLRP.InstanceGuid},
					{Name: "INSTANCE_INDEX", Value: strconv.Itoa(int(actualLRP.Index))},
					{Name: "CF_INSTANCE_GUID", Value: actualLRP.InstanceGuid},
					{Name: "CF_INSTANCE_INDEX", Value: strconv.Itoa(int(actualLRP.Index))},
				}, executor.EnvironmentVariablesFromModel(desiredLRP.EnvironmentVariables)...),
			}))
		})

		Context("when the rootfs is not preloaded", func() {
			BeforeEach(func() {
				desiredLRP.RootFs = "docker://cloudfoundry/test"
			})

			It("uses TotalDiskLimit as the disk scope", func() {
				runReq, err := rep.NewRunRequestFromDesiredLRP(containerGuid, desiredLRP, &actualLRP.ActualLRPKey, &actualLRP.ActualLRPInstanceKey)
				Expect(err).NotTo(HaveOccurred())
				Expect(runReq.DiskScope).To(Equal(executor.TotalDiskLimit))
			})
		})
	})