本文整理汇总了Golang中github.com/square/p2/pkg/kp/flags.ParseWithConsulOptions函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseWithConsulOptions函数的具体用法?Golang ParseWithConsulOptions怎么用?Golang ParseWithConsulOptions使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseWithConsulOptions函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
kingpin.Version(version.VERSION)
_, opts := flags.ParseWithConsulOptions()
client := kp.NewConsulClient(opts)
store := kp.NewConsulStore(client)
if *nodeName == "" {
hostname, err := os.Hostname()
if err != nil {
log.Fatalf("Could not get the hostname to do scheduling: %s", err)
}
*nodeName = hostname
}
if len(*manifests) == 0 {
kingpin.Usage()
log.Fatalln("No manifests given")
}
for _, manifestPath := range *manifests {
manifest, err := pods.ManifestFromPath(manifestPath)
if err != nil {
log.Fatalf("Could not read manifest at %s: %s\n", manifestPath, err)
}
path := kp.IntentPath(*nodeName, manifest.ID())
if *hookGlobal {
path = kp.HookPath(manifest.ID())
}
duration, err := store.SetPod(path, manifest)
if err != nil {
log.Fatalf("Could not write manifest %s to intent store: %s\n", manifest.ID(), err)
}
log.Printf("Scheduling %s took %s\n", manifest.ID(), duration)
}
}
开发者ID:tomzhang,项目名称:p2,代码行数:35,代码来源:main.go
示例2: main
func main() {
quitCh := make(chan struct{})
_, consulOpts, labeler := flags.ParseWithConsulOptions()
client := kp.NewConsulClient(consulOpts)
logger := logging.NewLogger(logrus.Fields{})
dsStore := dsstore.NewConsul(client, 3, &logger)
kpStore := kp.NewConsulStore(client)
healthChecker := checker.NewConsulHealthChecker(client)
sessions := make(chan string)
go consulutil.SessionManager(api.SessionEntry{
Name: SessionName(),
LockDelay: 5 * time.Second,
Behavior: api.SessionBehaviorDelete,
TTL: "15s",
}, client, sessions, quitCh, logger)
dsf := ds_farm.NewFarm(kpStore, dsStore, labeler, labels.NewConsulApplicator(client, 0), sessions, logger, nil, &healthChecker, 1*time.Second, *useCachePodMatches)
go func() {
// clear lock immediately on ctrl-C
signals := make(chan os.Signal, 1)
signal.Notify(signals, os.Interrupt)
<-signals
close(quitCh)
}()
dsf.Start(quitCh)
}
开发者ID:petertseng,项目名称:p2,代码行数:30,代码来源:main.go
示例3: main
func main() {
kingpin.Version(version.VERSION)
_, opts := flags.ParseWithConsulOptions()
if *nodeName == "" {
hostname, err := os.Hostname()
if err != nil {
fmt.Fprintf(os.Stderr, "error getting hostname. use --node to specify a node: %v\n", err)
os.Exit(1)
}
*nodeName = hostname
}
rm := NewP2RM(kp.NewConsulClient(opts), *podName, types.NodeName(*nodeName))
podIsManagedByRC, rcID, err := rm.checkForManagingReplicationController()
if err != nil {
os.Exit(2)
}
if !podIsManagedByRC {
err = rm.deletePod()
if err != nil {
os.Exit(2)
}
}
if podIsManagedByRC && !*deallocation {
fmt.Fprintf(
os.Stderr,
"error: %s is managed by replication controller: %s\n"+
"It's possible you meant you deallocate this pod on this node. If so, please confirm your intention with --deallocate\n", *nodeName, rcID)
os.Exit(2)
}
if podIsManagedByRC && *deallocation {
err = rm.decrementDesiredCount(rcID)
if err != nil {
fmt.Fprintf(os.Stderr,
"Encountered error deallocating from the RC %s. You may attempt this command again or use `p2-rctl` to cleanup manually.\n%v",
rcID,
err)
}
}
fmt.Printf("%s: successfully removed %s\n", rm.NodeName, rm.PodName)
}
开发者ID:rudle,项目名称:p2,代码行数:47,代码来源:main.go
示例4: main
func main() {
// Parse custom flags + standard Consul routing options
_, opts, _ := flags.ParseWithConsulOptions()
client := kp.NewConsulClient(opts)
podStore := kp_podstore.NewConsul(client.KV())
podStatusStore := podstatus.NewConsul(statusstore.NewConsul(client), kp.PreparerPodStatusNamespace)
logger := log.New(os.Stderr, "", 0)
port := getPort(logger)
lis, err := net.Listen("tcp", fmt.Sprintf("localhost:%d", port))
if err != nil {
logger.Fatalf("failed to listen: %v", err)
}
s := grpc.NewServer()
podstore_protos.RegisterP2PodStoreServer(s, podstore.NewServer(podStore, podStatusStore))
if err := s.Serve(lis); err != nil {
logger.Fatalf("failed to serve: %v", err)
}
}
开发者ID:petertseng,项目名称:p2,代码行数:22,代码来源:server.go
示例5: main
func main() {
// CLI takes a hostname, a token and recursively deletes all pods
// in the reality tree. This is useful if any pods on a host have
// been manually altered in some way and need to be restored to
// a known state.
kingpin.Version(version.VERSION)
_, opts := flags.ParseWithConsulOptions()
client := kp.NewConsulClient(opts)
store := kp.NewConsulStore(client)
pods, _, err := store.ListPods(kp.REALITY_TREE, types.NodeName(*nodeName))
if err != nil {
log.Fatalf("Could not list pods for node %v: %v", *nodeName, err)
}
for _, pod := range pods {
log.Printf("Deleting %v from reality\n", pod.Manifest.ID())
_, err := store.DeletePod(kp.REALITY_TREE, types.NodeName(*nodeName), pod.Manifest.ID())
if err != nil {
log.Fatalf("Could not remove %v from pod reality tree: %v", err)
}
}
}
开发者ID:drcapulet,项目名称:p2,代码行数:23,代码来源:main.go
注:本文中的github.com/square/p2/pkg/kp/flags.ParseWithConsulOptions函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论