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


Golang manifest.ID函数代码示例

本文整理汇总了Golang中github.com/square/p2/pkg/manifest.ID函数的典型用法代码示例。如果您正苦于以下问题:Golang ID函数的具体用法?Golang ID怎么用?Golang ID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ListPods

func (f *FakePodStore) ListPods(podPrefix kp.PodPrefix, hostname types.NodeName) ([]kp.ManifestResult, time.Duration, error) {
	f.podLock.Lock()
	defer f.podLock.Unlock()
	res := make([]kp.ManifestResult, 0)
	for key, manifest := range f.podResults {
		if key.podPrefix == podPrefix && key.hostname == hostname {
			// TODO(mpuncel) make ManifestResult not contain the path, it's silly to have to do things like this
			path := path.Join(string(podPrefix), hostname.String(), string(manifest.ID()))
			uniqueKey, err := kp.PodUniqueKeyFromConsulPath(path)
			if err != nil {
				return nil, 0, err
			}

			res = append(res, kp.ManifestResult{
				Manifest: manifest,
				PodLocation: types.PodLocation{
					Node:  hostname,
					PodID: manifest.ID(),
				},
				PodUniqueKey: uniqueKey,
			})
		}
	}
	return res, 0, nil
}
开发者ID:petertseng,项目名称:p2,代码行数:25,代码来源:fake_store.go

示例2: AllPods

func (f *FakePodStore) AllPods(podPrefix kp.PodPrefix) ([]kp.ManifestResult, time.Duration, error) {
	f.podLock.Lock()
	defer f.podLock.Unlock()
	res := make([]kp.ManifestResult, 0)
	for key, manifest := range f.podResults {
		if key.podPrefix != podPrefix {
			continue
		}
		path := path.Join(string(podPrefix), key.hostname.String(), string(manifest.ID()))
		uniqueKey, err := kp.PodUniqueKeyFromConsulPath(path)
		if err != nil {
			return nil, 0, err
		}

		res = append(res, kp.ManifestResult{
			Manifest: manifest,
			PodLocation: types.PodLocation{
				Node:  key.hostname,
				PodID: manifest.ID(),
			},
			PodUniqueKey: uniqueKey,
		})
	}
	return res, 0, nil
}
开发者ID:petertseng,项目名称:p2,代码行数:25,代码来源:fake_store.go

示例3: TestShouldRollMidwayDesireLessThanHealthyPartial

func TestShouldRollMidwayDesireLessThanHealthyPartial(t *testing.T) {
	// This test is like the above, but ensures that we are not too conservative.
	// If we have a minimum health of 3, desire 3 on the old side,
	// and have 1 healthy on the new side, we should have room to roll one node.
	checks := map[types.NodeName]health.Result{
		"node1": {Status: health.Passing},
		"node2": {Status: health.Passing},
		"node3": {Status: health.Passing},
		"node4": {Status: health.Passing},
		"node5": {Status: health.Passing},
	}
	upd, _, manifest := updateWithHealth(t, 3, 2, map[types.NodeName]bool{
		// This is something that may happen in a rolling update:
		// old RC only desires three nodes, but still has four of them.
		"node1": true,
		"node2": true,
		"node3": true,
		"node4": true,
	}, map[types.NodeName]bool{
		"node5": true,
	}, checks)
	upd.DesiredReplicas = 5
	upd.MinimumReplicas = 3

	roll, err := upd.uniformShouldRollAfterDelay(t, manifest.ID())
	Assert(t).IsNil(err, "expected no error determining nodes to roll")
	Assert(t).AreEqual(roll, 1, "expected to roll one node")
}
开发者ID:petertseng,项目名称:p2,代码行数:28,代码来源:update_test.go

示例4: TestShouldRollInitialUnknown

func TestShouldRollInitialUnknown(t *testing.T) {
	upd, _, manifest := updateWithHealth(t, 3, 0, nil, nil, nil)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	roll, _ := upd.uniformShouldRollAfterDelay(t, manifest.ID())
	Assert(t).AreEqual(roll, 0, "expected to roll no nodes if health is unknown")
}
开发者ID:petertseng,项目名称:p2,代码行数:8,代码来源:update_test.go

示例5: TestShouldRollInitialMigrationFromZero

func TestShouldRollInitialMigrationFromZero(t *testing.T) {
	upd, _, manifest := updateWithHealth(t, 0, 0, nil, nil, nil)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	remove, add, err := upd.shouldRollAfterDelay(manifest.ID())
	Assert(t).IsNil(err, "expected no error determining nodes to roll")
	Assert(t).AreEqual(remove, 0, "expected to remove no nodes")
	Assert(t).AreEqual(add, 1, "expected to add one node")
}
开发者ID:petertseng,项目名称:p2,代码行数:10,代码来源:update_test.go

示例6: main

func main() {
	kingpin.Version(version.VERSION)
	kingpin.Parse()

	if *nodeName == "" {
		hostname, err := os.Hostname()
		if err != nil {
			log.Fatalf("error getting node name: %v", err)
		}
		*nodeName = hostname
	}

	manifest, err := manifest.FromURI(*manifestURI)
	if err != nil {
		log.Fatalf("%s", err)
	}

	hookFactory := pods.NewHookFactory(filepath.Join(*podRoot, "hooks", *hookType), types.NodeName(*nodeName))

	// /data/pods/hooks/<event>/<id>
	// if the event is the empty string (global hook), then that path segment
	// will be cleaned out
	pod := hookFactory.NewHookPod(manifest.ID())

	// for now use noop verifier in this CLI
	err = pod.Install(manifest, auth.NopVerifier(), artifact.NewRegistry(*registryURI, uri.DefaultFetcher, osversion.DefaultDetector))
	if err != nil {
		log.Fatalf("Could not install manifest %s: %s", manifest.ID(), err)
	}
	// hooks write their current manifest manually since it's normally done at
	// launch time
	_, err = pod.WriteCurrentManifest(manifest)
	if err != nil {
		log.Fatalf("Could not write current manifest for %s: %s", manifest.ID(), err)
	}

	err = hooks.InstallHookScripts(*hookRoot, pod, manifest, logging.DefaultLogger)
	if err != nil {
		log.Fatalf("Could not write hook scripts: %s", err)
	}
}
开发者ID:petertseng,项目名称:p2,代码行数:41,代码来源:main.go

示例7: TestShouldRollMidwayUnknkown

func TestShouldRollMidwayUnknkown(t *testing.T) {
	checks := map[types.NodeName]health.Result{
		"node3": {Status: health.Passing},
	}
	upd, _, manifest := updateWithHealth(t, 2, 1, nil, map[types.NodeName]bool{
		"node3": true,
	}, checks)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	roll, _ := upd.uniformShouldRollAfterDelay(t, manifest.ID())
	Assert(t).AreEqual(roll, 0, "expected to roll no nodes when old nodes all have unknown health")
}
开发者ID:petertseng,项目名称:p2,代码行数:13,代码来源:update_test.go

示例8: TestShouldRollMidwayUnhealthyMigrationFromZero

func TestShouldRollMidwayUnhealthyMigrationFromZero(t *testing.T) {
	checks := map[types.NodeName]health.Result{
		"node3": {Status: health.Critical},
	}
	upd, _, manifest := updateWithHealth(t, 0, 1, nil, map[types.NodeName]bool{
		"node3": true,
	}, checks)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	remove, add, _ := upd.shouldRollAfterDelay(manifest.ID())
	Assert(t).AreEqual(remove, 0, "expected to remove no nodes")
	Assert(t).AreEqual(add, 0, "expected to add no nodes")
}
开发者ID:petertseng,项目名称:p2,代码行数:14,代码来源:update_test.go

示例9: TestRollLoopTypicalCase

func TestRollLoopTypicalCase(t *testing.T) {
	upd, _, manifest := updateWithHealth(t, 3, 0, map[types.NodeName]bool{
		"node1": true,
		"node2": true,
		"node3": true,
	}, nil, nil)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	healths := make(chan map[types.NodeName]health.Result)

	oldRC, oldRCUpdated := watchRCOrFail(t, upd.rcs, upd.OldRC, "old RC")
	newRC, newRCUpdated := watchRCOrFail(t, upd.rcs, upd.NewRC, "new RC")

	rollLoopResult := make(chan bool)

	go func() {
		rollLoopResult <- upd.rollLoop(manifest.ID(), healths, nil, nil)
		close(rollLoopResult)
	}()

	checks := map[types.NodeName]health.Result{
		"node1": {Status: health.Passing},
		"node2": {Status: health.Passing},
		"node3": {Status: health.Passing},
	}

	healths <- checks

	assertRCUpdates(t, oldRC, oldRCUpdated, 2, "old RC")
	assertRCUpdates(t, newRC, newRCUpdated, 1, "new RC")

	transferNode("node1", manifest, upd)
	healths <- checks

	assertRCUpdates(t, oldRC, oldRCUpdated, 1, "old RC")
	assertRCUpdates(t, newRC, newRCUpdated, 2, "new RC")

	transferNode("node2", manifest, upd)
	healths <- checks

	assertRCUpdates(t, oldRC, oldRCUpdated, 0, "old RC")
	assertRCUpdates(t, newRC, newRCUpdated, 3, "new RC")

	transferNode("node3", manifest, upd)
	healths <- checks

	assertRollLoopResult(t, rollLoopResult, true)
}
开发者ID:petertseng,项目名称:p2,代码行数:49,代码来源:update_test.go

示例10: TestShouldRollMidwayHealthyMigrationFromZeroWhenNewSatisfies

func TestShouldRollMidwayHealthyMigrationFromZeroWhenNewSatisfies(t *testing.T) {
	checks := map[types.NodeName]health.Result{
		"node2": {Status: health.Passing},
		"node3": {Status: health.Passing},
	}
	upd, _, manifest := updateWithHealth(t, 0, 2, nil, map[types.NodeName]bool{
		"node2": true,
		"node3": true,
	}, checks)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	remove, add, err := upd.shouldRollAfterDelay(manifest.ID())
	Assert(t).IsNil(err, "expected no error determining nodes to roll")
	Assert(t).AreEqual(remove, 0, "expected to remove no nodes")
	Assert(t).AreEqual(add, 1, "expected to add one node")
}
开发者ID:petertseng,项目名称:p2,代码行数:17,代码来源:update_test.go

示例11: TestShouldRollInitial

func TestShouldRollInitial(t *testing.T) {
	checks := map[types.NodeName]health.Result{
		"node1": {Status: health.Passing},
		"node2": {Status: health.Passing},
		"node3": {Status: health.Passing},
	}
	upd, _, manifest := updateWithHealth(t, 3, 0, map[types.NodeName]bool{
		"node1": true,
		"node2": true,
		"node3": true,
	}, nil, checks)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	roll, err := upd.uniformShouldRollAfterDelay(t, manifest.ID())
	Assert(t).IsNil(err, "expected no error determining nodes to roll")
	Assert(t).AreEqual(roll, 1, "expected to only roll one node")
}
开发者ID:petertseng,项目名称:p2,代码行数:18,代码来源:update_test.go

示例12: TestRollLoopStallsIfUnhealthy

func TestRollLoopStallsIfUnhealthy(t *testing.T) {
	upd, _, manifest := updateWithHealth(t, 3, 0, map[types.NodeName]bool{
		"node1": true,
		"node2": true,
		"node3": true,
	}, nil, nil)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	healths := make(chan map[types.NodeName]health.Result)

	oldRC, oldRCUpdated := watchRCOrFail(t, upd.rcs, upd.OldRC, "old RC")
	newRC, newRCUpdated := watchRCOrFail(t, upd.rcs, upd.NewRC, "new RC")

	rollLoopResult := make(chan bool)
	quitRoll := make(chan struct{})

	go func() {
		rollLoopResult <- upd.rollLoop(manifest.ID(), healths, nil, quitRoll)
		close(rollLoopResult)
	}()

	checks := map[types.NodeName]health.Result{
		"node1": {Status: health.Passing},
		"node2": {Status: health.Passing},
		"node3": {Status: health.Passing},
	}

	healths <- checks

	assertRCUpdates(t, oldRC, oldRCUpdated, 2, "old RC")
	assertRCUpdates(t, newRC, newRCUpdated, 1, "new RC")

	transferNode("node1", manifest, upd)
	checks["node1"] = health.Result{Status: health.Critical}
	go failIfRCDesireChanges(t, oldRC, 2, oldRCUpdated)
	go failIfRCDesireChanges(t, newRC, 1, newRCUpdated)
	for i := 0; i < 5; i++ {
		healths <- checks
	}

	quitRoll <- struct{}{}
	assertRollLoopResult(t, rollLoopResult, false)
}
开发者ID:petertseng,项目名称:p2,代码行数:44,代码来源:update_test.go

示例13: TestRollLoopMigrateFromZero

func TestRollLoopMigrateFromZero(t *testing.T) {
	upd, _, manifest := updateWithHealth(t, 0, 0, nil, nil, nil)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 2

	healths := make(chan map[types.NodeName]health.Result)

	oldRC, oldRCUpdated := watchRCOrFail(t, upd.rcs, upd.OldRC, "old RC")
	newRC, newRCUpdated := watchRCOrFail(t, upd.rcs, upd.NewRC, "new RC")
	go failIfRCDesireChanges(t, oldRC, 0, oldRCUpdated)

	rollLoopResult := make(chan bool)

	go func() {
		rollLoopResult <- upd.rollLoop(manifest.ID(), healths, nil, nil)
		close(rollLoopResult)
	}()

	checks := map[types.NodeName]health.Result{}
	healths <- checks

	assertRCUpdates(t, newRC, newRCUpdated, 1, "new RC")

	checks["node1"] = health.Result{Status: health.Passing}
	transferNode("node1", manifest, upd)
	healths <- checks

	assertRCUpdates(t, newRC, newRCUpdated, 2, "new RC")

	checks["node2"] = health.Result{Status: health.Passing}
	transferNode("node2", manifest, upd)
	healths <- checks

	assertRCUpdates(t, newRC, newRCUpdated, 3, "new RC")

	checks["node3"] = health.Result{Status: health.Passing}
	transferNode("node3", manifest, upd)
	healths <- checks

	assertRollLoopResult(t, rollLoopResult, true)
}
开发者ID:petertseng,项目名称:p2,代码行数:41,代码来源:update_test.go

示例14: TestShouldRollWhenNewSatisfiesButNotAllDesiredHealthy

func TestShouldRollWhenNewSatisfiesButNotAllDesiredHealthy(t *testing.T) {
	// newHealthy < newDesired, and newHealthy >= minHealthy.
	// In this case, we schedule the remaining nodes.
	// We want to ensure that remaining == targetDesired - newDesired
	// instead of targetDesired - newHealthy
	checks := map[types.NodeName]health.Result{
		"node1": {Status: health.Passing},
		"node2": {Status: health.Passing},
		"node3": {Status: health.Critical},
	}
	upd, _, manifest := updateWithHealth(t, 1, 2, map[types.NodeName]bool{
		"node1": true,
	}, map[types.NodeName]bool{
		"node2": true,
		"node3": true,
	}, checks)
	upd.DesiredReplicas = 3
	upd.MinimumReplicas = 1

	roll, err := upd.uniformShouldRollAfterDelay(t, manifest.ID())
	Assert(t).IsNil(err, "expected no error determining nodes to roll")
	Assert(t).AreEqual(roll, 1, "expected to roll one node")
}
开发者ID:petertseng,项目名称:p2,代码行数:23,代码来源:update_test.go

示例15: TestShouldRollMidwayDesireLessThanHealthy

func TestShouldRollMidwayDesireLessThanHealthy(t *testing.T) {
	checks := map[types.NodeName]health.Result{
		"node1": {Status: health.Passing},
		"node2": {Status: health.Passing},
		"node3": {Status: health.Passing},
		"node4": {Status: health.Passing},
		"node5": {Status: health.Passing},
	}
	upd, _, manifest := updateWithHealth(t, 3, 2, map[types.NodeName]bool{
		// This is something that may happen in a rolling update:
		// old RC only desires three nodes, but still has all five.
		"node1": true,
		"node2": true,
		"node3": true,
		"node4": true,
		"node5": true,
	}, map[types.NodeName]bool{}, checks)
	upd.DesiredReplicas = 5
	upd.MinimumReplicas = 3

	roll, _ := upd.uniformShouldRollAfterDelay(t, manifest.ID())
	Assert(t).AreEqual(roll, 0, "expected to roll no nodes")
}
开发者ID:petertseng,项目名称:p2,代码行数:23,代码来源:update_test.go


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