當前位置: 首頁>>代碼示例>>Golang>>正文


Golang job.ParseJobState函數代碼示例

本文整理匯總了Golang中github.com/coreos/fleet/job.ParseJobState函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseJobState函數的具體用法?Golang ParseJobState怎麽用?Golang ParseJobState使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ParseJobState函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: dirToUnit

// dirToUnit takes a Node containing a Job's constituent objects (in child
// nodes) and returns a *job.Unit, or any error encountered
func (r *EtcdRegistry) dirToUnit(dir *etcd.Node, unitHashLookupFunc func(unit.Hash) *unit.UnitFile) (*job.Unit, error) {
	objKey := path.Join(dir.Key, "object")
	var objNode *etcd.Node
	for _, node := range dir.Nodes {
		node := node
		if node.Key == objKey {
			objNode = node
		}
	}
	if objNode == nil {
		return nil, nil
	}
	u, err := r.getUnitFromObjectNode(objNode, unitHashLookupFunc)
	if err != nil {
		return nil, err
	}
	if u == nil {
		return nil, fmt.Errorf("unable to parse Unit in Registry at key %s", objKey)
	}
	if tgtstate := dirToTargetState(dir); tgtstate != "" {
		ts, err := job.ParseJobState(tgtstate)
		if err != nil {
			return nil, fmt.Errorf("failed to parse Unit(%s) target-state: %v", u.Name, err)
		}
		u.TargetState = ts
	}

	return u, nil
}
開發者ID:jmartin127,項目名稱:heapster,代碼行數:31,代碼來源:job.go

示例2: GetJobTargetState

func (r *EtcdRegistry) GetJobTargetState(jobName string) (*job.JobState, error) {
	key := r.jobTargetStatePath(jobName)
	resp, err := r.etcd.Get(key, false, false)
	if err != nil {
		if err.(*goetcd.EtcdError).ErrorCode != etcd.EcodeNodeExist {
			log.Errorf("Unable to determine target-state of Job(%s): %v", jobName, err)
		}
		return nil, err
	}

	return job.ParseJobState(resp.Node.Value), nil
}
開發者ID:johnmontero,項目名稱:fleet,代碼行數:12,代碼來源:job.go

示例3: filterJobTargetStateChanges

func (es *EventStream) filterJobTargetStateChanges(resp *etcd.Result) *event.Event {
	if resp.Action != "set" {
		return nil
	}

	dir, baseName := path.Split(resp.Node.Key)
	if baseName != "target-state" {
		return nil
	}

	dir = strings.TrimSuffix(dir, "/")
	jobName := path.Base(dir)

	ts := job.ParseJobState(resp.Node.Value)
	if ts == nil {
		return nil
	}

	cs := es.registry.determineJobState(jobName)
	if *cs == *ts {
		return nil
	}

	var cType string
	switch *cs {
	case job.JobStateInactive:
		cType = "CommandLoadJob"
	case job.JobStateLoaded:
		if *ts == job.JobStateInactive {
			cType = "CommandUnloadJob"
		} else if *ts == job.JobStateLaunched {
			cType = "CommandStartJob"
		}
	case job.JobStateLaunched:
		if *ts == job.JobStateLoaded {
			cType = "CommandStopJob"
		} else if *ts == job.JobStateInactive {
			cType = "CommandUnloadJob"
		}
	}

	if cType == "" {
		return nil
	}

	agent, err := es.registry.jobTargetMachine(jobName)
	if err != nil {
		log.Errorf("Failed to look up target of Job(%s): %v", jobName, err)
		return nil
	}

	return &event.Event{cType, jobName, agent}
}
開發者ID:Jitendrakry,項目名稱:fleet,代碼行數:53,代碼來源:job.go

示例4: jobTargetState

func (r *EtcdRegistry) jobTargetState(jobName string) (job.JobState, error) {
	req := etcd.Get{
		Key: r.jobTargetStatePath(jobName),
	}
	resp, err := r.etcd.Do(&req)
	if err != nil {
		if isKeyNotFound(err) {
			err = nil
		}
		return job.JobStateInactive, err
	}

	return job.ParseJobState(resp.Node.Value)
}
開發者ID:JuanCarlosM,項目名稱:fleet,代碼行數:14,代碼來源:job.go

示例5: filterJobTargetStateChanges

func (es *EventStream) filterJobTargetStateChanges(resp *goetcd.Response) *event.Event {
	if resp.Action != "set" {
		return nil
	}

	dir, baseName := path.Split(resp.Node.Key)
	if baseName != "target-state" {
		return nil
	}

	dir = strings.TrimSuffix(dir, "/")
	jobName := path.Base(dir)

	ts := job.ParseJobState(resp.Node.Value)
	if ts == nil {
		return nil
	}

	cs := es.registry.determineJobState(jobName)
	if *cs == *ts {
		return nil
	}

	var cType string
	switch *cs {
	case job.JobStateInactive:
		cType = "CommandLoadJob"
	case job.JobStateLoaded:
		if *ts == job.JobStateInactive {
			cType = "CommandUnloadJob"
		} else if *ts == job.JobStateLaunched {
			cType = "CommandStartJob"
		}
	case job.JobStateLaunched:
		if *ts == job.JobStateLoaded {
			cType = "CommandStopJob"
		} else if *ts == job.JobStateInactive {
			cType = "CommandUnloadJob"
		}
	}

	if cType == "" {
		return nil
	}

	agent, _ := es.registry.GetJobTarget(jobName)
	return &event.Event{cType, jobName, agent}
}
開發者ID:johnmontero,項目名稱:fleet,代碼行數:48,代碼來源:job.go

示例6: CreateUnit

func (rc *RegistryClient) CreateUnit(u *schema.Unit) error {
	rUnit := job.Unit{
		Name:        u.Name,
		Unit:        *schema.MapSchemaUnitOptionsToUnitFile(u.Options),
		TargetState: job.JobStateInactive,
	}

	if len(u.DesiredState) > 0 {
		ts, err := job.ParseJobState(u.DesiredState)
		if err != nil {
			return err
		}

		rUnit.TargetState = ts
	}

	return rc.Registry.CreateUnit(&rUnit)
}
開發者ID:MohamedFAhmed,項目名稱:heapster,代碼行數:18,代碼來源:registry.go

示例7: parseJobDir

func (r *EtcdRegistry) parseJobDir(j *job.Job, dir *etcd.Node) (err error) {
	var heartbeat string
	for _, node := range dir.Nodes {
		switch node.Key {
		case r.jobTargetStatePath(j.Name):
			j.TargetState, err = job.ParseJobState(node.Value)
			if err != nil {
				return
			}
		case r.jobTargetAgentPath(j.Name):
			j.TargetMachineID = node.Value
		case r.jobHeartbeatPath(j.Name):
			heartbeat = node.Value
		}
	}

	j.UnitState = r.getUnitState(j.Name)

	js := determineJobState(j, heartbeat)
	j.State = &js

	return
}
開發者ID:BillTheBest,項目名稱:fleet,代碼行數:23,代碼來源:job.go


注:本文中的github.com/coreos/fleet/job.ParseJobState函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。