本文整理汇总了Golang中github.com/square/p2/pkg/manifest.ID函数的典型用法代码示例。如果您正苦于以下问题:Golang ID函数的具体用法?Golang ID怎么用?Golang ID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ID函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: main
func main() {
cmd, consulOpts := flags.ParseWithConsulOptions()
client := kp.NewConsulClient(consulOpts)
logger := logging.NewLogger(logrus.Fields{})
dsstore := dsstore.NewConsul(client, 3, &logger)
applicator := labels.NewConsulApplicator(client, 3)
switch cmd {
case CmdCreate:
minHealth, err := strconv.Atoi(*createMinHealth)
if err != nil {
log.Fatalf("Invalid value for minimum health, expected integer: %v", err)
}
name := ds_fields.ClusterName(*createName)
manifest, err := manifest.FromPath(*createManifest)
if err != nil {
log.Fatalf("%s", err)
}
podID := manifest.ID()
if *createTimeout <= time.Duration(0) {
log.Fatalf("Timeout must be a positive non-zero value, got '%v'", *createTimeout)
}
selectorString := *createSelector
if *createEverywhere {
selectorString = klabels.Everything().String()
} else if selectorString == "" {
selectorString = klabels.Nothing().String()
log.Fatal("Explicit everything selector not allowed, please use the --everwhere flag")
}
selector, err := parseNodeSelectorWithPrompt(klabels.Nothing(), selectorString, applicator)
if err != nil {
log.Fatalf("Error occurred: %v", err)
}
if err = confirmMinheathForSelector(minHealth, selector, applicator); err != nil {
log.Fatalf("Error occurred: %v", err)
}
ds, err := dsstore.Create(manifest, minHealth, name, selector, podID, *createTimeout)
if err != nil {
log.Fatalf("err: %v", err)
}
fmt.Printf("%v has been created in consul", ds.ID)
fmt.Println()
case CmdGet:
id := ds_fields.ID(*getID)
ds, _, err := dsstore.Get(id)
if err != nil {
log.Fatalf("err: %v", err)
}
bytes, err := json.Marshal(ds)
if err != nil {
logger.WithError(err).Fatalln("Unable to marshal daemon set as JSON")
}
fmt.Printf("%s", bytes)
case CmdList:
dsList, err := dsstore.List()
if err != nil {
log.Fatalf("err: %v", err)
}
podID := types.PodID(*listPod)
for _, ds := range dsList {
if *listPod == "" || podID == ds.PodID {
fmt.Printf("%s/%s:%s\n", ds.PodID, ds.Name, ds.ID)
}
}
case CmdEnable:
id := ds_fields.ID(*enableID)
mutator := func(ds ds_fields.DaemonSet) (ds_fields.DaemonSet, error) {
if !ds.Disabled {
return ds, util.Errorf("Daemon set has already been enabled")
}
ds.Disabled = false
return ds, nil
}
_, err := dsstore.MutateDS(id, mutator)
if err != nil {
log.Fatalf("err: %v", err)
}
fmt.Printf("The daemon set '%s' has been successfully enabled in consul", id.String())
fmt.Println()
case CmdDisable:
id := ds_fields.ID(*disableID)
mutator := func(ds ds_fields.DaemonSet) (ds_fields.DaemonSet, error) {
if ds.Disabled {
return ds, util.Errorf("Daemon set has already been disabled")
}
ds.Disabled = true
return ds, nil
//.........这里部分代码省略.........
开发者ID:rudle,项目名称:p2,代码行数:101,代码来源:main.go
示例17: TestPodSetupConfigWritesFiles
func TestPodSetupConfigWritesFiles(t *testing.T) {
manifestStr := `id: thepod
launchables:
my-app:
launchable_type: hoist
launchable_id: web
location: https://localhost:4444/foo/bar/baz_3c021aff048ca8117593f9c71e03b87cf72fd440.tar.gz
cgroup:
cpus: 4
memory: 4G
env:
ENABLED_BLAMS: 5
config:
ENVIRONMENT: staging
`
currUser, err := user.Current()
Assert(t).IsNil(err, "Could not get the current user")
manifestStr += fmt.Sprintf("run_as: %s", currUser.Username)
manifest, err := manifest.FromBytes(bytes.NewBufferString(manifestStr).Bytes())
Assert(t).IsNil(err, "should not have erred reading the manifest")
podTemp, _ := ioutil.TempDir("", "pod")
podFactory := NewFactory(podTemp, "testNode")
pod := podFactory.NewPod(manifest.ID())
launchables := make([]launch.Launchable, 0)
for _, stanza := range manifest.GetLaunchableStanzas() {
launchable, err := pod.getLaunchable(stanza, manifest.RunAsUser(), manifest.GetRestartPolicy())
Assert(t).IsNil(err, "There shouldn't have been an error getting launchable")
launchables = append(launchables, launchable)
}
Assert(t).IsTrue(len(launchables) > 0, "Test setup error: no launchables from launchable stanzas")
err = pod.setupConfig(manifest, launchables)
Assert(t).IsNil(err, "There shouldn't have been an error setting up config")
configFileName, err := manifest.ConfigFileName()
Assert(t).IsNil(err, "Couldn't generate config filename")
configPath := filepath.Join(pod.ConfigDir(), configFileName)
config, err := ioutil.ReadFile(configPath)
Assert(t).IsNil(err, "should not have erred reading the config")
Assert(t).AreEqual("ENVIRONMENT: staging\n", string(config), "the config didn't match")
env, err := ioutil.ReadFile(filepath.Join(pod.EnvDir(), "CONFIG_PATH"))
Assert(t).IsNil(err, "should not have erred reading the env file")
Assert(t).AreEqual(configPath, string(env), "The env path to config didn't match")
platformConfigFileName, err := manifest.PlatformConfigFileName()
Assert(t).IsNil(err, "Couldn't generate platform config filename")
platformConfigPath := filepath.Join(pod.ConfigDir(), platformConfigFileName)
platConfig, err := ioutil.ReadFile(platformConfigPath)
Assert(t).IsNil(err, "should not have erred reading the platform config")
expectedPlatConfig := `web:
cgroup:
cpus: 4
memory: 4294967296
`
Assert(t).AreEqual(expectedPlatConfig, string(platConfig), "the platform config didn't match")
platEnv, err := ioutil.ReadFile(filepath.Join(pod.EnvDir(), "PLATFORM_CONFIG_PATH"))
Assert(t).IsNil(err, "should not have erred reading the platform config env file")
Assert(t).AreEqual(platformConfigPath, string(platEnv), "The env path to platform config didn't match")
for _, launchable := range launchables {
launchableIdEnv, err := ioutil.ReadFile(filepath.Join(launchable.EnvDir(), "LAUNCHABLE_ID"))
Assert(t).IsNil(err, "should not have erred reading the launchable ID env file")
if launchable.ID().String() != string(launchableIdEnv) {
t.Errorf("Launchable Id did not have expected value: wanted '%s' was '%s'", launchable.ID().String(), launchableIdEnv)
}
launchableRootEnv, err := ioutil.ReadFile(filepath.Join(launchable.EnvDir(), "LAUNCHABLE_ROOT"))
Assert(t).IsNil(err, "should not have erred reading the launchable root env file")
Assert(t).AreEqual(launchable.InstallDir(), string(launchableRootEnv), "The launchable root path did not match expected")
enableBlamSetting, err := ioutil.ReadFile(filepath.Join(launchable.EnvDir(), "ENABLED_BLAMS"))
Assert(t).IsNil(err, "should not have erred reading custom env var")
Assert(t).AreEqual("5", string(enableBlamSetting), "The user-supplied custom env var was wrong")
}
}
开发者ID:rudle,项目名称:p2,代码行数:82,代码来源:pod_test.go
注:本文中的github.com/square/p2/pkg/manifest.ID函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论