当前位置: 首页>>代码示例>>Golang>>正文


Golang Container.State方法代码示例

本文整理汇总了Golang中github.com/cloudfoundry-incubator/executor.Container.State方法的典型用法代码示例。如果您正苦于以下问题:Golang Container.State方法的具体用法?Golang Container.State怎么用?Golang Container.State使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/cloudfoundry-incubator/executor.Container的用法示例。


在下文中一共展示了Container.State方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Create

func (store *GardenStore) Create(logger lager.Logger, container executor.Container) (executor.Container, error) {
	if container.State != executor.StateInitializing {
		return executor.Container{}, executor.ErrInvalidTransition
	}
	container.State = executor.StateCreated

	logStreamer := log_streamer.New(
		container.LogConfig.Guid,
		container.LogConfig.SourceName,
		container.LogConfig.Index,
	)

	fmt.Fprintf(logStreamer.Stdout(), "Creating container\n")

	container, err := store.exchanger.CreateInGarden(logger, store.gardenClient, container)
	if err != nil {
		fmt.Fprintf(logStreamer.Stderr(), "Failed to create container\n")
		return executor.Container{}, err
	}

	fmt.Fprintf(logStreamer.Stdout(), "Successfully created container\n")

	return container, nil
}
开发者ID:snowsnail,项目名称:executor,代码行数:24,代码来源:garden_store.go

示例2:

		Context("when given an LRP container", func() {
			var container executor.Container

			BeforeEach(func() {
				container = newLRPContainer(expectedLrpKey, expectedInstanceKey, expectedNetInfo)
			})

			JustBeforeEach(func() {
				processor.Process(logger, container)
			})

			Context("and the container is INVALID", func() {
				BeforeEach(func() {
					expectedSessionName = sessionPrefix + "process-invalid-container"
					container.State = executor.StateInvalid
				})

				It("logs an error", func() {
					Expect(logger).To(Say(expectedSessionName))
				})
			})

			Context("and the container is RESERVED", func() {
				BeforeEach(func() {
					bbsClient.DesiredLRPByProcessGuidReturns(desiredLRP, nil)
					expectedSessionName = sessionPrefix + "process-reserved-container"
					container.State = executor.StateReserved
				})

				It("claims the actualLRP in the bbs", func() {
开发者ID:jianhuiz,项目名称:rep,代码行数:30,代码来源:ordinary_lrp_processor_test.go

示例3: garden2executor

func garden2executor(handle string, info garden.ContainerInfo) (executor.Container, error) {
	executorContainer := executor.Container{
		Guid:       handle,
		Tags:       executor.Tags{},
		ExternalIP: info.ExternalIP,
	}

	executorContainer.Ports = make([]executor.PortMapping, len(info.MappedPorts))

	for key, value := range info.Properties {
		switch key {
		case ContainerStateProperty:
			state := executor.State(value)

			if state == executor.StateReserved ||
				state == executor.StateInitializing ||
				state == executor.StateCreated ||
				state == executor.StateRunning ||
				state == executor.StateCompleted {
				executorContainer.State = state
			} else {
				return executor.Container{}, InvalidStateError{value}
			}
		case ContainerAllocatedAtProperty:
			_, err := fmt.Sscanf(value, "%d", &executorContainer.AllocatedAt)
			if err != nil {
				return executor.Container{}, MalformedPropertyError{
					Property: ContainerAllocatedAtProperty,
					Value:    value,
				}
			}
		case ContainerRootfsProperty:
			executorContainer.RootFSPath = value
		case ContainerLogProperty:
			err := json.Unmarshal([]byte(value), &executorContainer.LogConfig)
			if err != nil {
				return executor.Container{}, InvalidJSONError{
					Property:     key,
					Value:        value,
					UnmarshalErr: err,
				}
			}
		case ContainerMetricsConfigProperty:
			err := json.Unmarshal([]byte(value), &executorContainer.MetricsConfig)
			if err != nil {
				return executor.Container{}, InvalidJSONError{
					Property:     key,
					Value:        value,
					UnmarshalErr: err,
				}
			}
		case ContainerResultProperty:
			err := json.Unmarshal([]byte(value), &executorContainer.RunResult)
			if err != nil {
				return executor.Container{}, InvalidJSONError{
					Property:     key,
					Value:        value,
					UnmarshalErr: err,
				}
			}
		case ContainerMemoryMBProperty:
			memoryMB, err := strconv.Atoi(value)
			if err != nil {
				return executor.Container{}, MalformedPropertyError{
					Property: key,
					Value:    value,
				}
			}

			executorContainer.MemoryMB = memoryMB
		case ContainerDiskMBProperty:
			diskMB, err := strconv.Atoi(value)
			if err != nil {
				return executor.Container{}, MalformedPropertyError{
					Property: key,
					Value:    value,
				}
			}

			executorContainer.DiskMB = diskMB
		case ContainerCPUWeightProperty:
			cpuWeight, err := strconv.Atoi(value)
			if err != nil {
				return executor.Container{}, MalformedPropertyError{
					Property: key,
					Value:    value,
				}
			}

			executorContainer.CPUWeight = uint(cpuWeight)
		case ContainerStartTimeoutProperty:
			startTimeout, err := strconv.Atoi(value)
			if err != nil {
				return executor.Container{}, MalformedPropertyError{
					Property: key,
					Value:    value,
				}
			}

			executorContainer.StartTimeout = uint(startTimeout)
//.........这里部分代码省略.........
开发者ID:snowsnail,项目名称:executor,代码行数:101,代码来源:exchanger.go


注:本文中的github.com/cloudfoundry-incubator/executor.Container.State方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。