id
int32 0
167k
| repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
list | docstring
stringlengths 6
2.61k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 85
252
|
---|---|---|---|---|---|---|---|---|---|---|---|
16,200 | projecteru2/core | rpc/rpc.go | ContainerDeployed | func (v *Vibranium) ContainerDeployed(ctx context.Context, opts *pb.ContainerDeployedOptions) (*pb.Empty, error) {
v.taskAdd("ContainerDeployed", false)
defer v.taskDone("ContainerDeployed", false)
return &pb.Empty{}, v.cluster.ContainerDeployed(ctx, opts.Id, opts.Appname, opts.Entrypoint, opts.Nodename, string(opts.Data))
} | go | func (v *Vibranium) ContainerDeployed(ctx context.Context, opts *pb.ContainerDeployedOptions) (*pb.Empty, error) {
v.taskAdd("ContainerDeployed", false)
defer v.taskDone("ContainerDeployed", false)
return &pb.Empty{}, v.cluster.ContainerDeployed(ctx, opts.Id, opts.Appname, opts.Entrypoint, opts.Nodename, string(opts.Data))
} | [
"func",
"(",
"v",
"*",
"Vibranium",
")",
"ContainerDeployed",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"pb",
".",
"ContainerDeployedOptions",
")",
"(",
"*",
"pb",
".",
"Empty",
",",
"error",
")",
"{",
"v",
".",
"taskAdd",
"(",
"\"",
"\"",
",",
"false",
")",
"\n",
"defer",
"v",
".",
"taskDone",
"(",
"\"",
"\"",
",",
"false",
")",
"\n",
"return",
"&",
"pb",
".",
"Empty",
"{",
"}",
",",
"v",
".",
"cluster",
".",
"ContainerDeployed",
"(",
"ctx",
",",
"opts",
".",
"Id",
",",
"opts",
".",
"Appname",
",",
"opts",
".",
"Entrypoint",
",",
"opts",
".",
"Nodename",
",",
"string",
"(",
"opts",
".",
"Data",
")",
")",
"\n",
"}"
] | // ContainerDeployed store deploy status | [
"ContainerDeployed",
"store",
"deploy",
"status"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/rpc/rpc.go#L563-L567 |
16,201 | projecteru2/core | rpc/rpc.go | New | func New(cluster cluster.Cluster, config types.Config, rpcch chan struct{}) *Vibranium {
return &Vibranium{cluster: cluster, config: config, counter: sync.WaitGroup{}, rpcch: rpcch}
} | go | func New(cluster cluster.Cluster, config types.Config, rpcch chan struct{}) *Vibranium {
return &Vibranium{cluster: cluster, config: config, counter: sync.WaitGroup{}, rpcch: rpcch}
} | [
"func",
"New",
"(",
"cluster",
"cluster",
".",
"Cluster",
",",
"config",
"types",
".",
"Config",
",",
"rpcch",
"chan",
"struct",
"{",
"}",
")",
"*",
"Vibranium",
"{",
"return",
"&",
"Vibranium",
"{",
"cluster",
":",
"cluster",
",",
"config",
":",
"config",
",",
"counter",
":",
"sync",
".",
"WaitGroup",
"{",
"}",
",",
"rpcch",
":",
"rpcch",
"}",
"\n",
"}"
] | // New will new a new cluster instance | [
"New",
"will",
"new",
"a",
"new",
"cluster",
"instance"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/rpc/rpc.go#L574-L576 |
16,202 | projecteru2/core | types/container.go | Inspect | func (c *Container) Inspect(ctx context.Context) (*enginetypes.VirtualizationInfo, error) {
if c.Engine == nil {
return nil, ErrNilEngine
}
inspectCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
return c.Engine.VirtualizationInspect(inspectCtx, c.ID)
} | go | func (c *Container) Inspect(ctx context.Context) (*enginetypes.VirtualizationInfo, error) {
if c.Engine == nil {
return nil, ErrNilEngine
}
inspectCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
return c.Engine.VirtualizationInspect(inspectCtx, c.ID)
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"Inspect",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"enginetypes",
".",
"VirtualizationInfo",
",",
"error",
")",
"{",
"if",
"c",
".",
"Engine",
"==",
"nil",
"{",
"return",
"nil",
",",
"ErrNilEngine",
"\n",
"}",
"\n",
"inspectCtx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"5",
"*",
"time",
".",
"Second",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"return",
"c",
".",
"Engine",
".",
"VirtualizationInspect",
"(",
"inspectCtx",
",",
"c",
".",
"ID",
")",
"\n",
"}"
] | // Inspect a container | [
"Inspect",
"a",
"container"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/types/container.go#L30-L37 |
16,203 | projecteru2/core | types/container.go | Start | func (c *Container) Start(ctx context.Context) error {
if c.Engine == nil {
return ErrNilEngine
}
startCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
return c.Engine.VirtualizationStart(startCtx, c.ID)
} | go | func (c *Container) Start(ctx context.Context) error {
if c.Engine == nil {
return ErrNilEngine
}
startCtx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()
return c.Engine.VirtualizationStart(startCtx, c.ID)
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"Start",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"c",
".",
"Engine",
"==",
"nil",
"{",
"return",
"ErrNilEngine",
"\n",
"}",
"\n",
"startCtx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"10",
"*",
"time",
".",
"Second",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"return",
"c",
".",
"Engine",
".",
"VirtualizationStart",
"(",
"startCtx",
",",
"c",
".",
"ID",
")",
"\n",
"}"
] | // Start a container | [
"Start",
"a",
"container"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/types/container.go#L40-L47 |
16,204 | projecteru2/core | types/container.go | Stop | func (c *Container) Stop(ctx context.Context, timeout time.Duration) error {
if c.Engine == nil {
return ErrNilEngine
}
// 这里 block 的问题很严重,按照目前的配置是 5 分钟一级的 block
// 一个简单的处理方法是相信 ctx 不相信 engine 自身的处理
// 另外我怀疑 engine 自己的 timeout 实现是完全的等 timeout 而非结束了就退出
removeCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
return c.Engine.VirtualizationStop(removeCtx, c.ID)
} | go | func (c *Container) Stop(ctx context.Context, timeout time.Duration) error {
if c.Engine == nil {
return ErrNilEngine
}
// 这里 block 的问题很严重,按照目前的配置是 5 分钟一级的 block
// 一个简单的处理方法是相信 ctx 不相信 engine 自身的处理
// 另外我怀疑 engine 自己的 timeout 实现是完全的等 timeout 而非结束了就退出
removeCtx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()
return c.Engine.VirtualizationStop(removeCtx, c.ID)
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"Stop",
"(",
"ctx",
"context",
".",
"Context",
",",
"timeout",
"time",
".",
"Duration",
")",
"error",
"{",
"if",
"c",
".",
"Engine",
"==",
"nil",
"{",
"return",
"ErrNilEngine",
"\n",
"}",
"\n",
"// 这里 block 的问题很严重,按照目前的配置是 5 分钟一级的 block",
"// 一个简单的处理方法是相信 ctx 不相信 engine 自身的处理",
"// 另外我怀疑 engine 自己的 timeout 实现是完全的等 timeout 而非结束了就退出",
"removeCtx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"timeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"return",
"c",
".",
"Engine",
".",
"VirtualizationStop",
"(",
"removeCtx",
",",
"c",
".",
"ID",
")",
"\n",
"}"
] | // Stop a container | [
"Stop",
"a",
"container"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/types/container.go#L50-L60 |
16,205 | projecteru2/core | types/container.go | Remove | func (c *Container) Remove(ctx context.Context) error {
if c.Engine == nil {
return ErrNilEngine
}
return c.Engine.VirtualizationRemove(ctx, c.ID, true, true)
} | go | func (c *Container) Remove(ctx context.Context) error {
if c.Engine == nil {
return ErrNilEngine
}
return c.Engine.VirtualizationRemove(ctx, c.ID, true, true)
} | [
"func",
"(",
"c",
"*",
"Container",
")",
"Remove",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"if",
"c",
".",
"Engine",
"==",
"nil",
"{",
"return",
"ErrNilEngine",
"\n",
"}",
"\n",
"return",
"c",
".",
"Engine",
".",
"VirtualizationRemove",
"(",
"ctx",
",",
"c",
".",
"ID",
",",
"true",
",",
"true",
")",
"\n",
"}"
] | // Remove a container | [
"Remove",
"a",
"container"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/types/container.go#L63-L68 |
16,206 | projecteru2/core | cluster/calcium/status.go | DeployStatusStream | func (c *Calcium) DeployStatusStream(ctx context.Context, appname, entrypoint, nodename string) chan *types.DeployStatus {
return c.store.WatchDeployStatus(ctx, appname, entrypoint, nodename)
} | go | func (c *Calcium) DeployStatusStream(ctx context.Context, appname, entrypoint, nodename string) chan *types.DeployStatus {
return c.store.WatchDeployStatus(ctx, appname, entrypoint, nodename)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"DeployStatusStream",
"(",
"ctx",
"context",
".",
"Context",
",",
"appname",
",",
"entrypoint",
",",
"nodename",
"string",
")",
"chan",
"*",
"types",
".",
"DeployStatus",
"{",
"return",
"c",
".",
"store",
".",
"WatchDeployStatus",
"(",
"ctx",
",",
"appname",
",",
"entrypoint",
",",
"nodename",
")",
"\n",
"}"
] | // DeployStatusStream watch deploy status | [
"DeployStatusStream",
"watch",
"deploy",
"status"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/status.go#L10-L12 |
16,207 | projecteru2/core | metrics/metrics.go | SendNodeInfo | func (m *Metrics) SendNodeInfo(node *types.Node) {
log.Debugf("[Metrics] Update %s memory capacity gauge", node.Name)
nodename := utils.CleanStatsdMetrics(node.Name)
memory := float64(node.MemCap)
if m.MemoryCapacity != nil {
m.MemoryCapacity.WithLabelValues(nodename).Set(memory)
}
for cpuid, value := range node.CPU {
val := float64(value)
key := fmt.Sprintf(cpuMap, nodename, cpuid)
if m.CPUMap != nil {
m.CPUMap.WithLabelValues(nodename, cpuid).Set(val)
}
if m.StatsdAddr == "" {
continue
}
if err := m.gauge(key, val); err != nil {
log.Errorf("[SendNodeInfo] Error occurred while sending data to statsd: %v", err)
}
}
if m.StatsdAddr == "" {
return
}
key := fmt.Sprintf(memStats, nodename)
if err := m.gauge(key, memory); err != nil {
log.Errorf("[SendNodeInfo] Error occurred while sending data to statsd: %v", err)
}
} | go | func (m *Metrics) SendNodeInfo(node *types.Node) {
log.Debugf("[Metrics] Update %s memory capacity gauge", node.Name)
nodename := utils.CleanStatsdMetrics(node.Name)
memory := float64(node.MemCap)
if m.MemoryCapacity != nil {
m.MemoryCapacity.WithLabelValues(nodename).Set(memory)
}
for cpuid, value := range node.CPU {
val := float64(value)
key := fmt.Sprintf(cpuMap, nodename, cpuid)
if m.CPUMap != nil {
m.CPUMap.WithLabelValues(nodename, cpuid).Set(val)
}
if m.StatsdAddr == "" {
continue
}
if err := m.gauge(key, val); err != nil {
log.Errorf("[SendNodeInfo] Error occurred while sending data to statsd: %v", err)
}
}
if m.StatsdAddr == "" {
return
}
key := fmt.Sprintf(memStats, nodename)
if err := m.gauge(key, memory); err != nil {
log.Errorf("[SendNodeInfo] Error occurred while sending data to statsd: %v", err)
}
} | [
"func",
"(",
"m",
"*",
"Metrics",
")",
"SendNodeInfo",
"(",
"node",
"*",
"types",
".",
"Node",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"node",
".",
"Name",
")",
"\n",
"nodename",
":=",
"utils",
".",
"CleanStatsdMetrics",
"(",
"node",
".",
"Name",
")",
"\n",
"memory",
":=",
"float64",
"(",
"node",
".",
"MemCap",
")",
"\n\n",
"if",
"m",
".",
"MemoryCapacity",
"!=",
"nil",
"{",
"m",
".",
"MemoryCapacity",
".",
"WithLabelValues",
"(",
"nodename",
")",
".",
"Set",
"(",
"memory",
")",
"\n",
"}",
"\n\n",
"for",
"cpuid",
",",
"value",
":=",
"range",
"node",
".",
"CPU",
"{",
"val",
":=",
"float64",
"(",
"value",
")",
"\n",
"key",
":=",
"fmt",
".",
"Sprintf",
"(",
"cpuMap",
",",
"nodename",
",",
"cpuid",
")",
"\n",
"if",
"m",
".",
"CPUMap",
"!=",
"nil",
"{",
"m",
".",
"CPUMap",
".",
"WithLabelValues",
"(",
"nodename",
",",
"cpuid",
")",
".",
"Set",
"(",
"val",
")",
"\n",
"}",
"\n",
"if",
"m",
".",
"StatsdAddr",
"==",
"\"",
"\"",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"err",
":=",
"m",
".",
"gauge",
"(",
"key",
",",
"val",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"m",
".",
"StatsdAddr",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"key",
":=",
"fmt",
".",
"Sprintf",
"(",
"memStats",
",",
"nodename",
")",
"\n",
"if",
"err",
":=",
"m",
".",
"gauge",
"(",
"key",
",",
"memory",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // SendNodeInfo update node resource capacity | [
"SendNodeInfo",
"update",
"node",
"resource",
"capacity"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/metrics/metrics.go#L65-L95 |
16,208 | projecteru2/core | metrics/metrics.go | SendDeployCount | func (m *Metrics) SendDeployCount(n int) {
log.Info("[Metrics] Update deploy counter")
if m.DeployCount != nil {
m.DeployCount.WithLabelValues(m.Hostname).Add(float64(n))
}
if m.StatsdAddr == "" {
return
}
key := fmt.Sprintf(deployCount, m.Hostname)
if err := m.count(key, n, 1.0); err != nil {
log.Errorf("[SendDeployCount] Error occurred while counting: %v", err)
}
} | go | func (m *Metrics) SendDeployCount(n int) {
log.Info("[Metrics] Update deploy counter")
if m.DeployCount != nil {
m.DeployCount.WithLabelValues(m.Hostname).Add(float64(n))
}
if m.StatsdAddr == "" {
return
}
key := fmt.Sprintf(deployCount, m.Hostname)
if err := m.count(key, n, 1.0); err != nil {
log.Errorf("[SendDeployCount] Error occurred while counting: %v", err)
}
} | [
"func",
"(",
"m",
"*",
"Metrics",
")",
"SendDeployCount",
"(",
"n",
"int",
")",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"if",
"m",
".",
"DeployCount",
"!=",
"nil",
"{",
"m",
".",
"DeployCount",
".",
"WithLabelValues",
"(",
"m",
".",
"Hostname",
")",
".",
"Add",
"(",
"float64",
"(",
"n",
")",
")",
"\n",
"}",
"\n\n",
"if",
"m",
".",
"StatsdAddr",
"==",
"\"",
"\"",
"{",
"return",
"\n",
"}",
"\n",
"key",
":=",
"fmt",
".",
"Sprintf",
"(",
"deployCount",
",",
"m",
".",
"Hostname",
")",
"\n",
"if",
"err",
":=",
"m",
".",
"count",
"(",
"key",
",",
"n",
",",
"1.0",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] | // SendDeployCount update deploy counter | [
"SendDeployCount",
"update",
"deploy",
"counter"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/metrics/metrics.go#L98-L111 |
16,209 | projecteru2/core | metrics/metrics.go | InitMetrics | func InitMetrics(statsd string) error {
hostname, err := os.Hostname()
if err != nil {
return err
}
Client = Metrics{StatsdAddr: statsd, Hostname: utils.CleanStatsdMetrics(hostname)}
Client.MemoryCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "memory_capacity",
Help: "node available memory.",
}, []string{"nodename"})
Client.DeployCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "core_deploy",
Help: "core deploy counter",
}, []string{"hostname"})
Client.CPUMap = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "cpu_map",
Help: "node available cpu.",
}, []string{"nodename", "cpuid"})
prometheus.MustRegister(Client.DeployCount, Client.MemoryCapacity, Client.CPUMap)
return nil
} | go | func InitMetrics(statsd string) error {
hostname, err := os.Hostname()
if err != nil {
return err
}
Client = Metrics{StatsdAddr: statsd, Hostname: utils.CleanStatsdMetrics(hostname)}
Client.MemoryCapacity = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "memory_capacity",
Help: "node available memory.",
}, []string{"nodename"})
Client.DeployCount = prometheus.NewCounterVec(prometheus.CounterOpts{
Name: "core_deploy",
Help: "core deploy counter",
}, []string{"hostname"})
Client.CPUMap = prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "cpu_map",
Help: "node available cpu.",
}, []string{"nodename", "cpuid"})
prometheus.MustRegister(Client.DeployCount, Client.MemoryCapacity, Client.CPUMap)
return nil
} | [
"func",
"InitMetrics",
"(",
"statsd",
"string",
")",
"error",
"{",
"hostname",
",",
"err",
":=",
"os",
".",
"Hostname",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"Client",
"=",
"Metrics",
"{",
"StatsdAddr",
":",
"statsd",
",",
"Hostname",
":",
"utils",
".",
"CleanStatsdMetrics",
"(",
"hostname",
")",
"}",
"\n\n",
"Client",
".",
"MemoryCapacity",
"=",
"prometheus",
".",
"NewGaugeVec",
"(",
"prometheus",
".",
"GaugeOpts",
"{",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
")",
"\n\n",
"Client",
".",
"DeployCount",
"=",
"prometheus",
".",
"NewCounterVec",
"(",
"prometheus",
".",
"CounterOpts",
"{",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
")",
"\n\n",
"Client",
".",
"CPUMap",
"=",
"prometheus",
".",
"NewGaugeVec",
"(",
"prometheus",
".",
"GaugeOpts",
"{",
"Name",
":",
"\"",
"\"",
",",
"Help",
":",
"\"",
"\"",
",",
"}",
",",
"[",
"]",
"string",
"{",
"\"",
"\"",
",",
"\"",
"\"",
"}",
")",
"\n\n",
"prometheus",
".",
"MustRegister",
"(",
"Client",
".",
"DeployCount",
",",
"Client",
".",
"MemoryCapacity",
",",
"Client",
".",
"CPUMap",
")",
"\n",
"return",
"nil",
"\n",
"}"
] | // InitMetrics new a metrics obj | [
"InitMetrics",
"new",
"a",
"metrics",
"obj"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/metrics/metrics.go#L117-L141 |
16,210 | projecteru2/core | cluster/calcium/meta.go | AddPod | func (c *Calcium) AddPod(ctx context.Context, podname, favor, desc string) (*types.Pod, error) {
return c.store.AddPod(ctx, podname, favor, desc)
} | go | func (c *Calcium) AddPod(ctx context.Context, podname, favor, desc string) (*types.Pod, error) {
return c.store.AddPod(ctx, podname, favor, desc)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"AddPod",
"(",
"ctx",
"context",
".",
"Context",
",",
"podname",
",",
"favor",
",",
"desc",
"string",
")",
"(",
"*",
"types",
".",
"Pod",
",",
"error",
")",
"{",
"return",
"c",
".",
"store",
".",
"AddPod",
"(",
"ctx",
",",
"podname",
",",
"favor",
",",
"desc",
")",
"\n",
"}"
] | // AddPod add pod | [
"AddPod",
"add",
"pod"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L14-L16 |
16,211 | projecteru2/core | cluster/calcium/meta.go | AddNode | func (c *Calcium) AddNode(ctx context.Context, nodename, endpoint, podname, ca, cert, key string, cpu, share int, memory int64, labels map[string]string) (*types.Node, error) {
return c.store.AddNode(ctx, nodename, endpoint, podname, ca, cert, key, cpu, share, memory, labels)
} | go | func (c *Calcium) AddNode(ctx context.Context, nodename, endpoint, podname, ca, cert, key string, cpu, share int, memory int64, labels map[string]string) (*types.Node, error) {
return c.store.AddNode(ctx, nodename, endpoint, podname, ca, cert, key, cpu, share, memory, labels)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"AddNode",
"(",
"ctx",
"context",
".",
"Context",
",",
"nodename",
",",
"endpoint",
",",
"podname",
",",
"ca",
",",
"cert",
",",
"key",
"string",
",",
"cpu",
",",
"share",
"int",
",",
"memory",
"int64",
",",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"*",
"types",
".",
"Node",
",",
"error",
")",
"{",
"return",
"c",
".",
"store",
".",
"AddNode",
"(",
"ctx",
",",
"nodename",
",",
"endpoint",
",",
"podname",
",",
"ca",
",",
"cert",
",",
"key",
",",
"cpu",
",",
"share",
",",
"memory",
",",
"labels",
")",
"\n",
"}"
] | // AddNode add a node in pod | [
"AddNode",
"add",
"a",
"node",
"in",
"pod"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L19-L21 |
16,212 | projecteru2/core | cluster/calcium/meta.go | RemovePod | func (c *Calcium) RemovePod(ctx context.Context, podname string) error {
return c.store.RemovePod(ctx, podname)
} | go | func (c *Calcium) RemovePod(ctx context.Context, podname string) error {
return c.store.RemovePod(ctx, podname)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"RemovePod",
"(",
"ctx",
"context",
".",
"Context",
",",
"podname",
"string",
")",
"error",
"{",
"return",
"c",
".",
"store",
".",
"RemovePod",
"(",
"ctx",
",",
"podname",
")",
"\n",
"}"
] | // RemovePod remove pod | [
"RemovePod",
"remove",
"pod"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L24-L26 |
16,213 | projecteru2/core | cluster/calcium/meta.go | RemoveNode | func (c *Calcium) RemoveNode(ctx context.Context, nodename, podname string) (*types.Pod, error) {
n, err := c.GetNode(ctx, podname, nodename)
if err != nil {
return nil, err
}
c.store.DeleteNode(ctx, n)
return c.store.GetPod(ctx, podname)
} | go | func (c *Calcium) RemoveNode(ctx context.Context, nodename, podname string) (*types.Pod, error) {
n, err := c.GetNode(ctx, podname, nodename)
if err != nil {
return nil, err
}
c.store.DeleteNode(ctx, n)
return c.store.GetPod(ctx, podname)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"RemoveNode",
"(",
"ctx",
"context",
".",
"Context",
",",
"nodename",
",",
"podname",
"string",
")",
"(",
"*",
"types",
".",
"Pod",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"c",
".",
"GetNode",
"(",
"ctx",
",",
"podname",
",",
"nodename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"c",
".",
"store",
".",
"DeleteNode",
"(",
"ctx",
",",
"n",
")",
"\n",
"return",
"c",
".",
"store",
".",
"GetPod",
"(",
"ctx",
",",
"podname",
")",
"\n",
"}"
] | // RemoveNode remove a node | [
"RemoveNode",
"remove",
"a",
"node"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L29-L36 |
16,214 | projecteru2/core | cluster/calcium/meta.go | ListPods | func (c *Calcium) ListPods(ctx context.Context) ([]*types.Pod, error) {
return c.store.GetAllPods(ctx)
} | go | func (c *Calcium) ListPods(ctx context.Context) ([]*types.Pod, error) {
return c.store.GetAllPods(ctx)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"ListPods",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"[",
"]",
"*",
"types",
".",
"Pod",
",",
"error",
")",
"{",
"return",
"c",
".",
"store",
".",
"GetAllPods",
"(",
"ctx",
")",
"\n",
"}"
] | // ListPods show pods | [
"ListPods",
"show",
"pods"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L39-L41 |
16,215 | projecteru2/core | cluster/calcium/meta.go | ListPodNodes | func (c *Calcium) ListPodNodes(ctx context.Context, podname string, all bool) ([]*types.Node, error) {
var nodes []*types.Node
candidates, err := c.store.GetNodesByPod(ctx, podname)
if err != nil {
log.Errorf("[ListPodNodes] Error during ListPodNodes from %s: %v", podname, err)
return nodes, err
}
for _, candidate := range candidates {
if candidate.Available || all {
nodes = append(nodes, candidate)
}
}
return nodes, nil
} | go | func (c *Calcium) ListPodNodes(ctx context.Context, podname string, all bool) ([]*types.Node, error) {
var nodes []*types.Node
candidates, err := c.store.GetNodesByPod(ctx, podname)
if err != nil {
log.Errorf("[ListPodNodes] Error during ListPodNodes from %s: %v", podname, err)
return nodes, err
}
for _, candidate := range candidates {
if candidate.Available || all {
nodes = append(nodes, candidate)
}
}
return nodes, nil
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"ListPodNodes",
"(",
"ctx",
"context",
".",
"Context",
",",
"podname",
"string",
",",
"all",
"bool",
")",
"(",
"[",
"]",
"*",
"types",
".",
"Node",
",",
"error",
")",
"{",
"var",
"nodes",
"[",
"]",
"*",
"types",
".",
"Node",
"\n",
"candidates",
",",
"err",
":=",
"c",
".",
"store",
".",
"GetNodesByPod",
"(",
"ctx",
",",
"podname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"podname",
",",
"err",
")",
"\n",
"return",
"nodes",
",",
"err",
"\n",
"}",
"\n",
"for",
"_",
",",
"candidate",
":=",
"range",
"candidates",
"{",
"if",
"candidate",
".",
"Available",
"||",
"all",
"{",
"nodes",
"=",
"append",
"(",
"nodes",
",",
"candidate",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nodes",
",",
"nil",
"\n",
"}"
] | // ListPodNodes list nodes belong to pod | [
"ListPodNodes",
"list",
"nodes",
"belong",
"to",
"pod"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L44-L57 |
16,216 | projecteru2/core | cluster/calcium/meta.go | GetPod | func (c *Calcium) GetPod(ctx context.Context, podname string) (*types.Pod, error) {
return c.store.GetPod(ctx, podname)
} | go | func (c *Calcium) GetPod(ctx context.Context, podname string) (*types.Pod, error) {
return c.store.GetPod(ctx, podname)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"GetPod",
"(",
"ctx",
"context",
".",
"Context",
",",
"podname",
"string",
")",
"(",
"*",
"types",
".",
"Pod",
",",
"error",
")",
"{",
"return",
"c",
".",
"store",
".",
"GetPod",
"(",
"ctx",
",",
"podname",
")",
"\n",
"}"
] | // GetPod get one pod | [
"GetPod",
"get",
"one",
"pod"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L70-L72 |
16,217 | projecteru2/core | cluster/calcium/meta.go | GetNode | func (c *Calcium) GetNode(ctx context.Context, podname, nodename string) (*types.Node, error) {
return c.store.GetNode(ctx, podname, nodename)
} | go | func (c *Calcium) GetNode(ctx context.Context, podname, nodename string) (*types.Node, error) {
return c.store.GetNode(ctx, podname, nodename)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"GetNode",
"(",
"ctx",
"context",
".",
"Context",
",",
"podname",
",",
"nodename",
"string",
")",
"(",
"*",
"types",
".",
"Node",
",",
"error",
")",
"{",
"return",
"c",
".",
"store",
".",
"GetNode",
"(",
"ctx",
",",
"podname",
",",
"nodename",
")",
"\n",
"}"
] | // GetNode get node | [
"GetNode",
"get",
"node"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L75-L77 |
16,218 | projecteru2/core | cluster/calcium/meta.go | GetContainer | func (c *Calcium) GetContainer(ctx context.Context, ID string) (*types.Container, error) {
return c.store.GetContainer(ctx, ID)
} | go | func (c *Calcium) GetContainer(ctx context.Context, ID string) (*types.Container, error) {
return c.store.GetContainer(ctx, ID)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"GetContainer",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"string",
")",
"(",
"*",
"types",
".",
"Container",
",",
"error",
")",
"{",
"return",
"c",
".",
"store",
".",
"GetContainer",
"(",
"ctx",
",",
"ID",
")",
"\n",
"}"
] | // GetContainer get a container | [
"GetContainer",
"get",
"a",
"container"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L80-L82 |
16,219 | projecteru2/core | cluster/calcium/meta.go | GetContainers | func (c *Calcium) GetContainers(ctx context.Context, IDs []string) ([]*types.Container, error) {
return c.store.GetContainers(ctx, IDs)
} | go | func (c *Calcium) GetContainers(ctx context.Context, IDs []string) ([]*types.Container, error) {
return c.store.GetContainers(ctx, IDs)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"GetContainers",
"(",
"ctx",
"context",
".",
"Context",
",",
"IDs",
"[",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"types",
".",
"Container",
",",
"error",
")",
"{",
"return",
"c",
".",
"store",
".",
"GetContainers",
"(",
"ctx",
",",
"IDs",
")",
"\n",
"}"
] | // GetContainers get containers | [
"GetContainers",
"get",
"containers"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L85-L87 |
16,220 | projecteru2/core | cluster/calcium/meta.go | SetNodeAvailable | func (c *Calcium) SetNodeAvailable(ctx context.Context, podname, nodename string, available bool) (*types.Node, error) {
n, err := c.GetNode(ctx, podname, nodename)
if err != nil {
return nil, err
}
n.Available = available
if err := c.store.UpdateNode(ctx, n); err != nil {
return nil, err
}
return n, nil
} | go | func (c *Calcium) SetNodeAvailable(ctx context.Context, podname, nodename string, available bool) (*types.Node, error) {
n, err := c.GetNode(ctx, podname, nodename)
if err != nil {
return nil, err
}
n.Available = available
if err := c.store.UpdateNode(ctx, n); err != nil {
return nil, err
}
return n, nil
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"SetNodeAvailable",
"(",
"ctx",
"context",
".",
"Context",
",",
"podname",
",",
"nodename",
"string",
",",
"available",
"bool",
")",
"(",
"*",
"types",
".",
"Node",
",",
"error",
")",
"{",
"n",
",",
"err",
":=",
"c",
".",
"GetNode",
"(",
"ctx",
",",
"podname",
",",
"nodename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"n",
".",
"Available",
"=",
"available",
"\n",
"if",
"err",
":=",
"c",
".",
"store",
".",
"UpdateNode",
"(",
"ctx",
",",
"n",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"n",
",",
"nil",
"\n",
"}"
] | // SetNodeAvailable set node available or not | [
"SetNodeAvailable",
"set",
"node",
"available",
"or",
"not"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L90-L100 |
16,221 | projecteru2/core | cluster/calcium/meta.go | ContainerDeployed | func (c *Calcium) ContainerDeployed(ctx context.Context, ID, appname, entrypoint, nodename, data string) error {
return c.store.ContainerDeployed(ctx, ID, appname, entrypoint, nodename, data)
} | go | func (c *Calcium) ContainerDeployed(ctx context.Context, ID, appname, entrypoint, nodename, data string) error {
return c.store.ContainerDeployed(ctx, ID, appname, entrypoint, nodename, data)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"ContainerDeployed",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
",",
"appname",
",",
"entrypoint",
",",
"nodename",
",",
"data",
"string",
")",
"error",
"{",
"return",
"c",
".",
"store",
".",
"ContainerDeployed",
"(",
"ctx",
",",
"ID",
",",
"appname",
",",
"entrypoint",
",",
"nodename",
",",
"data",
")",
"\n",
"}"
] | // ContainerDeployed set container deploy status | [
"ContainerDeployed",
"set",
"container",
"deploy",
"status"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/meta.go#L108-L110 |
16,222 | projecteru2/core | scheduler/complex/potassium.go | New | func New(config types.Config) (*Potassium, error) {
return &Potassium{config.Scheduler.MaxShare, config.Scheduler.ShareBase}, nil
} | go | func New(config types.Config) (*Potassium, error) {
return &Potassium{config.Scheduler.MaxShare, config.Scheduler.ShareBase}, nil
} | [
"func",
"New",
"(",
"config",
"types",
".",
"Config",
")",
"(",
"*",
"Potassium",
",",
"error",
")",
"{",
"return",
"&",
"Potassium",
"{",
"config",
".",
"Scheduler",
".",
"MaxShare",
",",
"config",
".",
"Scheduler",
".",
"ShareBase",
"}",
",",
"nil",
"\n",
"}"
] | // New a potassium | [
"New",
"a",
"potassium"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/scheduler/complex/potassium.go#L17-L19 |
16,223 | projecteru2/core | scheduler/complex/potassium.go | MaxIdleNode | func (m *Potassium) MaxIdleNode(nodes []*types.Node) (*types.Node, error) {
if len(nodes) < 1 {
return nil, types.ErrInsufficientNodes
}
pos := 0
node := nodes[pos]
min := float64(node.CPU.Total())/float64(node.InitCPU.Total()) + float64(node.MemCap)/float64(node.InitMemCap)
for i, node := range nodes {
idle := float64(node.CPU.Total())/float64(node.InitCPU.Total()) + float64(node.MemCap)/float64(node.InitMemCap)
if idle < min {
pos = i
min = idle
}
}
return nodes[pos], nil
} | go | func (m *Potassium) MaxIdleNode(nodes []*types.Node) (*types.Node, error) {
if len(nodes) < 1 {
return nil, types.ErrInsufficientNodes
}
pos := 0
node := nodes[pos]
min := float64(node.CPU.Total())/float64(node.InitCPU.Total()) + float64(node.MemCap)/float64(node.InitMemCap)
for i, node := range nodes {
idle := float64(node.CPU.Total())/float64(node.InitCPU.Total()) + float64(node.MemCap)/float64(node.InitMemCap)
if idle < min {
pos = i
min = idle
}
}
return nodes[pos], nil
} | [
"func",
"(",
"m",
"*",
"Potassium",
")",
"MaxIdleNode",
"(",
"nodes",
"[",
"]",
"*",
"types",
".",
"Node",
")",
"(",
"*",
"types",
".",
"Node",
",",
"error",
")",
"{",
"if",
"len",
"(",
"nodes",
")",
"<",
"1",
"{",
"return",
"nil",
",",
"types",
".",
"ErrInsufficientNodes",
"\n",
"}",
"\n",
"pos",
":=",
"0",
"\n",
"node",
":=",
"nodes",
"[",
"pos",
"]",
"\n",
"min",
":=",
"float64",
"(",
"node",
".",
"CPU",
".",
"Total",
"(",
")",
")",
"/",
"float64",
"(",
"node",
".",
"InitCPU",
".",
"Total",
"(",
")",
")",
"+",
"float64",
"(",
"node",
".",
"MemCap",
")",
"/",
"float64",
"(",
"node",
".",
"InitMemCap",
")",
"\n",
"for",
"i",
",",
"node",
":=",
"range",
"nodes",
"{",
"idle",
":=",
"float64",
"(",
"node",
".",
"CPU",
".",
"Total",
"(",
")",
")",
"/",
"float64",
"(",
"node",
".",
"InitCPU",
".",
"Total",
"(",
")",
")",
"+",
"float64",
"(",
"node",
".",
"MemCap",
")",
"/",
"float64",
"(",
"node",
".",
"InitMemCap",
")",
"\n",
"if",
"idle",
"<",
"min",
"{",
"pos",
"=",
"i",
"\n",
"min",
"=",
"idle",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nodes",
"[",
"pos",
"]",
",",
"nil",
"\n",
"}"
] | // MaxIdleNode use for build | [
"MaxIdleNode",
"use",
"for",
"build"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/scheduler/complex/potassium.go#L22-L37 |
16,224 | projecteru2/core | scheduler/complex/potassium.go | SelectMemoryNodes | func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64, memory int64) ([]types.NodeInfo, int, error) {
log.Debugf("[SelectMemoryNodes] nodesInfo: %v, cpu: %f, memory: %d", nodesInfo, quota, memory)
if memory <= 0 {
return nil, 0, types.ErrNegativeMemory
}
nodesInfoLength := len(nodesInfo)
// 筛选出能满足 CPU 需求的
sort.Slice(nodesInfo, func(i, j int) bool { return len(nodesInfo[i].CPUMap) < len(nodesInfo[j].CPUMap) })
p := sort.Search(nodesInfoLength, func(i int) bool { return float64(len(nodesInfo[i].CPUMap)) >= quota })
// p 最大也就是 nodesInfoLength - 1
if p == nodesInfoLength {
return nil, 0, types.ErrInsufficientCPU
}
nodesInfoLength -= p
nodesInfo = nodesInfo[p:]
// 计算是否有足够的内存满足需求
sort.Slice(nodesInfo, func(i, j int) bool { return nodesInfo[i].MemCap < nodesInfo[j].MemCap })
p = sort.Search(nodesInfoLength, func(i int) bool { return nodesInfo[i].MemCap >= memory })
if p == nodesInfoLength {
return nil, 0, types.ErrInsufficientMEM
}
nodesInfoLength -= p
nodesInfo = nodesInfo[p:]
// 这里 memCap 一定是大于 memory 的所以不用判断 cap 内容
volTotal := 0
for i, nodeInfo := range nodesInfo {
capacity := int(nodeInfo.MemCap / memory)
volTotal += capacity
nodesInfo[i].Capacity = capacity
}
return nodesInfo, volTotal, nil
} | go | func (m *Potassium) SelectMemoryNodes(nodesInfo []types.NodeInfo, quota float64, memory int64) ([]types.NodeInfo, int, error) {
log.Debugf("[SelectMemoryNodes] nodesInfo: %v, cpu: %f, memory: %d", nodesInfo, quota, memory)
if memory <= 0 {
return nil, 0, types.ErrNegativeMemory
}
nodesInfoLength := len(nodesInfo)
// 筛选出能满足 CPU 需求的
sort.Slice(nodesInfo, func(i, j int) bool { return len(nodesInfo[i].CPUMap) < len(nodesInfo[j].CPUMap) })
p := sort.Search(nodesInfoLength, func(i int) bool { return float64(len(nodesInfo[i].CPUMap)) >= quota })
// p 最大也就是 nodesInfoLength - 1
if p == nodesInfoLength {
return nil, 0, types.ErrInsufficientCPU
}
nodesInfoLength -= p
nodesInfo = nodesInfo[p:]
// 计算是否有足够的内存满足需求
sort.Slice(nodesInfo, func(i, j int) bool { return nodesInfo[i].MemCap < nodesInfo[j].MemCap })
p = sort.Search(nodesInfoLength, func(i int) bool { return nodesInfo[i].MemCap >= memory })
if p == nodesInfoLength {
return nil, 0, types.ErrInsufficientMEM
}
nodesInfoLength -= p
nodesInfo = nodesInfo[p:]
// 这里 memCap 一定是大于 memory 的所以不用判断 cap 内容
volTotal := 0
for i, nodeInfo := range nodesInfo {
capacity := int(nodeInfo.MemCap / memory)
volTotal += capacity
nodesInfo[i].Capacity = capacity
}
return nodesInfo, volTotal, nil
} | [
"func",
"(",
"m",
"*",
"Potassium",
")",
"SelectMemoryNodes",
"(",
"nodesInfo",
"[",
"]",
"types",
".",
"NodeInfo",
",",
"quota",
"float64",
",",
"memory",
"int64",
")",
"(",
"[",
"]",
"types",
".",
"NodeInfo",
",",
"int",
",",
"error",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"nodesInfo",
",",
"quota",
",",
"memory",
")",
"\n",
"if",
"memory",
"<=",
"0",
"{",
"return",
"nil",
",",
"0",
",",
"types",
".",
"ErrNegativeMemory",
"\n",
"}",
"\n\n",
"nodesInfoLength",
":=",
"len",
"(",
"nodesInfo",
")",
"\n\n",
"// 筛选出能满足 CPU 需求的",
"sort",
".",
"Slice",
"(",
"nodesInfo",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"len",
"(",
"nodesInfo",
"[",
"i",
"]",
".",
"CPUMap",
")",
"<",
"len",
"(",
"nodesInfo",
"[",
"j",
"]",
".",
"CPUMap",
")",
"}",
")",
"\n",
"p",
":=",
"sort",
".",
"Search",
"(",
"nodesInfoLength",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"float64",
"(",
"len",
"(",
"nodesInfo",
"[",
"i",
"]",
".",
"CPUMap",
")",
")",
">=",
"quota",
"}",
")",
"\n",
"// p 最大也就是 nodesInfoLength - 1",
"if",
"p",
"==",
"nodesInfoLength",
"{",
"return",
"nil",
",",
"0",
",",
"types",
".",
"ErrInsufficientCPU",
"\n",
"}",
"\n",
"nodesInfoLength",
"-=",
"p",
"\n",
"nodesInfo",
"=",
"nodesInfo",
"[",
"p",
":",
"]",
"\n\n",
"// 计算是否有足够的内存满足需求",
"sort",
".",
"Slice",
"(",
"nodesInfo",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"nodesInfo",
"[",
"i",
"]",
".",
"MemCap",
"<",
"nodesInfo",
"[",
"j",
"]",
".",
"MemCap",
"}",
")",
"\n",
"p",
"=",
"sort",
".",
"Search",
"(",
"nodesInfoLength",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"nodesInfo",
"[",
"i",
"]",
".",
"MemCap",
">=",
"memory",
"}",
")",
"\n",
"if",
"p",
"==",
"nodesInfoLength",
"{",
"return",
"nil",
",",
"0",
",",
"types",
".",
"ErrInsufficientMEM",
"\n",
"}",
"\n",
"nodesInfoLength",
"-=",
"p",
"\n",
"nodesInfo",
"=",
"nodesInfo",
"[",
"p",
":",
"]",
"\n\n",
"// 这里 memCap 一定是大于 memory 的所以不用判断 cap 内容",
"volTotal",
":=",
"0",
"\n",
"for",
"i",
",",
"nodeInfo",
":=",
"range",
"nodesInfo",
"{",
"capacity",
":=",
"int",
"(",
"nodeInfo",
".",
"MemCap",
"/",
"memory",
")",
"\n",
"volTotal",
"+=",
"capacity",
"\n",
"nodesInfo",
"[",
"i",
"]",
".",
"Capacity",
"=",
"capacity",
"\n",
"}",
"\n",
"return",
"nodesInfo",
",",
"volTotal",
",",
"nil",
"\n",
"}"
] | // SelectMemoryNodes filter nodes with enough memory | [
"SelectMemoryNodes",
"filter",
"nodes",
"with",
"enough",
"memory"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/scheduler/complex/potassium.go#L40-L75 |
16,225 | projecteru2/core | scheduler/complex/potassium.go | SelectCPUNodes | func (m *Potassium) SelectCPUNodes(nodesInfo []types.NodeInfo, quota float64, memory int64) ([]types.NodeInfo, map[string][]types.CPUMap, int, error) {
log.Debugf("[SelectCPUNodes] nodesInfo: %v, cpu: %f memory: %d", nodesInfo, quota, memory)
if quota <= 0 {
return nil, nil, 0, types.ErrNegativeQuota
}
if len(nodesInfo) == 0 {
return nil, nil, 0, types.ErrZeroNodes
}
return cpuPriorPlan(quota, memory, nodesInfo, m.maxshare, m.sharebase)
} | go | func (m *Potassium) SelectCPUNodes(nodesInfo []types.NodeInfo, quota float64, memory int64) ([]types.NodeInfo, map[string][]types.CPUMap, int, error) {
log.Debugf("[SelectCPUNodes] nodesInfo: %v, cpu: %f memory: %d", nodesInfo, quota, memory)
if quota <= 0 {
return nil, nil, 0, types.ErrNegativeQuota
}
if len(nodesInfo) == 0 {
return nil, nil, 0, types.ErrZeroNodes
}
return cpuPriorPlan(quota, memory, nodesInfo, m.maxshare, m.sharebase)
} | [
"func",
"(",
"m",
"*",
"Potassium",
")",
"SelectCPUNodes",
"(",
"nodesInfo",
"[",
"]",
"types",
".",
"NodeInfo",
",",
"quota",
"float64",
",",
"memory",
"int64",
")",
"(",
"[",
"]",
"types",
".",
"NodeInfo",
",",
"map",
"[",
"string",
"]",
"[",
"]",
"types",
".",
"CPUMap",
",",
"int",
",",
"error",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"nodesInfo",
",",
"quota",
",",
"memory",
")",
"\n",
"if",
"quota",
"<=",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"0",
",",
"types",
".",
"ErrNegativeQuota",
"\n",
"}",
"\n",
"if",
"len",
"(",
"nodesInfo",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"0",
",",
"types",
".",
"ErrZeroNodes",
"\n",
"}",
"\n",
"return",
"cpuPriorPlan",
"(",
"quota",
",",
"memory",
",",
"nodesInfo",
",",
"m",
".",
"maxshare",
",",
"m",
".",
"sharebase",
")",
"\n",
"}"
] | // SelectCPUNodes select nodes with enough cpus | [
"SelectCPUNodes",
"select",
"nodes",
"with",
"enough",
"cpus"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/scheduler/complex/potassium.go#L78-L87 |
16,226 | projecteru2/core | scheduler/complex/average.go | AveragePlan | func AveragePlan(nodesInfo []types.NodeInfo, need, limit int) ([]types.NodeInfo, error) {
nodesInfoLength := len(nodesInfo)
sort.Slice(nodesInfo, func(i, j int) bool { return nodesInfo[i].Capacity < nodesInfo[j].Capacity })
p := sort.Search(nodesInfoLength, func(i int) bool { return nodesInfo[i].Capacity >= need })
if p == nodesInfoLength {
return nil, types.ErrInsufficientCap
}
nodesInfo = nodesInfo[p:]
if limit > 0 {
nodesInfo = nodesInfo[:limit]
}
for i := range nodesInfo {
nodesInfo[i].Deploy = need
nodesInfo[i].Capacity -= need
}
log.Debugf("[AveragePlan] nodesInfo: %v", nodesInfo)
return nodesInfo, nil
} | go | func AveragePlan(nodesInfo []types.NodeInfo, need, limit int) ([]types.NodeInfo, error) {
nodesInfoLength := len(nodesInfo)
sort.Slice(nodesInfo, func(i, j int) bool { return nodesInfo[i].Capacity < nodesInfo[j].Capacity })
p := sort.Search(nodesInfoLength, func(i int) bool { return nodesInfo[i].Capacity >= need })
if p == nodesInfoLength {
return nil, types.ErrInsufficientCap
}
nodesInfo = nodesInfo[p:]
if limit > 0 {
nodesInfo = nodesInfo[:limit]
}
for i := range nodesInfo {
nodesInfo[i].Deploy = need
nodesInfo[i].Capacity -= need
}
log.Debugf("[AveragePlan] nodesInfo: %v", nodesInfo)
return nodesInfo, nil
} | [
"func",
"AveragePlan",
"(",
"nodesInfo",
"[",
"]",
"types",
".",
"NodeInfo",
",",
"need",
",",
"limit",
"int",
")",
"(",
"[",
"]",
"types",
".",
"NodeInfo",
",",
"error",
")",
"{",
"nodesInfoLength",
":=",
"len",
"(",
"nodesInfo",
")",
"\n",
"sort",
".",
"Slice",
"(",
"nodesInfo",
",",
"func",
"(",
"i",
",",
"j",
"int",
")",
"bool",
"{",
"return",
"nodesInfo",
"[",
"i",
"]",
".",
"Capacity",
"<",
"nodesInfo",
"[",
"j",
"]",
".",
"Capacity",
"}",
")",
"\n",
"p",
":=",
"sort",
".",
"Search",
"(",
"nodesInfoLength",
",",
"func",
"(",
"i",
"int",
")",
"bool",
"{",
"return",
"nodesInfo",
"[",
"i",
"]",
".",
"Capacity",
">=",
"need",
"}",
")",
"\n",
"if",
"p",
"==",
"nodesInfoLength",
"{",
"return",
"nil",
",",
"types",
".",
"ErrInsufficientCap",
"\n",
"}",
"\n",
"nodesInfo",
"=",
"nodesInfo",
"[",
"p",
":",
"]",
"\n",
"if",
"limit",
">",
"0",
"{",
"nodesInfo",
"=",
"nodesInfo",
"[",
":",
"limit",
"]",
"\n",
"}",
"\n",
"for",
"i",
":=",
"range",
"nodesInfo",
"{",
"nodesInfo",
"[",
"i",
"]",
".",
"Deploy",
"=",
"need",
"\n",
"nodesInfo",
"[",
"i",
"]",
".",
"Capacity",
"-=",
"need",
"\n",
"}",
"\n\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"nodesInfo",
")",
"\n",
"return",
"nodesInfo",
",",
"nil",
"\n",
"}"
] | // AveragePlan deploy container each node | [
"AveragePlan",
"deploy",
"container",
"each",
"node"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/scheduler/complex/average.go#L11-L29 |
16,227 | projecteru2/core | store/etcdv3/processing.go | SaveProcessing | func (m *Mercury) SaveProcessing(ctx context.Context, opts *types.DeployOptions, nodeInfo types.NodeInfo) error {
processingKey := filepath.Join(containerProcessingPrefix, opts.Name, opts.Entrypoint.Name, nodeInfo.Name, opts.ProcessIdent)
_, err := m.Create(ctx, processingKey, fmt.Sprintf("%d", nodeInfo.Deploy))
return err
} | go | func (m *Mercury) SaveProcessing(ctx context.Context, opts *types.DeployOptions, nodeInfo types.NodeInfo) error {
processingKey := filepath.Join(containerProcessingPrefix, opts.Name, opts.Entrypoint.Name, nodeInfo.Name, opts.ProcessIdent)
_, err := m.Create(ctx, processingKey, fmt.Sprintf("%d", nodeInfo.Deploy))
return err
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"SaveProcessing",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"types",
".",
"DeployOptions",
",",
"nodeInfo",
"types",
".",
"NodeInfo",
")",
"error",
"{",
"processingKey",
":=",
"filepath",
".",
"Join",
"(",
"containerProcessingPrefix",
",",
"opts",
".",
"Name",
",",
"opts",
".",
"Entrypoint",
".",
"Name",
",",
"nodeInfo",
".",
"Name",
",",
"opts",
".",
"ProcessIdent",
")",
"\n",
"_",
",",
"err",
":=",
"m",
".",
"Create",
"(",
"ctx",
",",
"processingKey",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"nodeInfo",
".",
"Deploy",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // SaveProcessing save processing status in etcd | [
"SaveProcessing",
"save",
"processing",
"status",
"in",
"etcd"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/processing.go#L18-L22 |
16,228 | projecteru2/core | store/etcdv3/processing.go | UpdateProcessing | func (m *Mercury) UpdateProcessing(ctx context.Context, opts *types.DeployOptions, nodename string, count int) error {
processingKey := filepath.Join(containerProcessingPrefix, opts.Name, opts.Entrypoint.Name, nodename, opts.ProcessIdent)
_, err := m.Update(ctx, processingKey, fmt.Sprintf("%d", count))
return err
} | go | func (m *Mercury) UpdateProcessing(ctx context.Context, opts *types.DeployOptions, nodename string, count int) error {
processingKey := filepath.Join(containerProcessingPrefix, opts.Name, opts.Entrypoint.Name, nodename, opts.ProcessIdent)
_, err := m.Update(ctx, processingKey, fmt.Sprintf("%d", count))
return err
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"UpdateProcessing",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"types",
".",
"DeployOptions",
",",
"nodename",
"string",
",",
"count",
"int",
")",
"error",
"{",
"processingKey",
":=",
"filepath",
".",
"Join",
"(",
"containerProcessingPrefix",
",",
"opts",
".",
"Name",
",",
"opts",
".",
"Entrypoint",
".",
"Name",
",",
"nodename",
",",
"opts",
".",
"ProcessIdent",
")",
"\n",
"_",
",",
"err",
":=",
"m",
".",
"Update",
"(",
"ctx",
",",
"processingKey",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"count",
")",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // UpdateProcessing update processing status in etcd | [
"UpdateProcessing",
"update",
"processing",
"status",
"in",
"etcd"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/processing.go#L25-L29 |
16,229 | projecteru2/core | store/etcdv3/processing.go | DeleteProcessing | func (m *Mercury) DeleteProcessing(ctx context.Context, opts *types.DeployOptions, nodeInfo types.NodeInfo) error {
processingKey := filepath.Join(containerProcessingPrefix, opts.Name, opts.Entrypoint.Name, nodeInfo.Name, opts.ProcessIdent)
_, err := m.Delete(ctx, processingKey)
return err
} | go | func (m *Mercury) DeleteProcessing(ctx context.Context, opts *types.DeployOptions, nodeInfo types.NodeInfo) error {
processingKey := filepath.Join(containerProcessingPrefix, opts.Name, opts.Entrypoint.Name, nodeInfo.Name, opts.ProcessIdent)
_, err := m.Delete(ctx, processingKey)
return err
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"DeleteProcessing",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"types",
".",
"DeployOptions",
",",
"nodeInfo",
"types",
".",
"NodeInfo",
")",
"error",
"{",
"processingKey",
":=",
"filepath",
".",
"Join",
"(",
"containerProcessingPrefix",
",",
"opts",
".",
"Name",
",",
"opts",
".",
"Entrypoint",
".",
"Name",
",",
"nodeInfo",
".",
"Name",
",",
"opts",
".",
"ProcessIdent",
")",
"\n",
"_",
",",
"err",
":=",
"m",
".",
"Delete",
"(",
"ctx",
",",
"processingKey",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // DeleteProcessing delete processing status in etcd | [
"DeleteProcessing",
"delete",
"processing",
"status",
"in",
"etcd"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/processing.go#L32-L36 |
16,230 | projecteru2/core | engine/docker/build.go | BuildRefs | func (e *Engine) BuildRefs(ctx context.Context, name string, tags []string) []string {
refs := []string{}
for _, tag := range tags {
ref := createImageTag(e.config.Docker, name, tag)
refs = append(refs, ref)
}
// use latest
if len(refs) == 0 {
refs = append(refs, createImageTag(e.config.Docker, name, utils.DefaultVersion))
}
return refs
} | go | func (e *Engine) BuildRefs(ctx context.Context, name string, tags []string) []string {
refs := []string{}
for _, tag := range tags {
ref := createImageTag(e.config.Docker, name, tag)
refs = append(refs, ref)
}
// use latest
if len(refs) == 0 {
refs = append(refs, createImageTag(e.config.Docker, name, utils.DefaultVersion))
}
return refs
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"BuildRefs",
"(",
"ctx",
"context",
".",
"Context",
",",
"name",
"string",
",",
"tags",
"[",
"]",
"string",
")",
"[",
"]",
"string",
"{",
"refs",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"tag",
":=",
"range",
"tags",
"{",
"ref",
":=",
"createImageTag",
"(",
"e",
".",
"config",
".",
"Docker",
",",
"name",
",",
"tag",
")",
"\n",
"refs",
"=",
"append",
"(",
"refs",
",",
"ref",
")",
"\n",
"}",
"\n",
"// use latest",
"if",
"len",
"(",
"refs",
")",
"==",
"0",
"{",
"refs",
"=",
"append",
"(",
"refs",
",",
"createImageTag",
"(",
"e",
".",
"config",
".",
"Docker",
",",
"name",
",",
"utils",
".",
"DefaultVersion",
")",
")",
"\n",
"}",
"\n",
"return",
"refs",
"\n",
"}"
] | // BuildRefs output refs | [
"BuildRefs",
"output",
"refs"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/build.go#L46-L57 |
16,231 | projecteru2/core | cluster/calcium/control.go | ControlContainer | func (c *Calcium) ControlContainer(ctx context.Context, IDs []string, t string) (chan *types.ControlContainerMessage, error) {
ch := make(chan *types.ControlContainerMessage)
go func() {
defer close(ch)
wg := sync.WaitGroup{}
for _, ID := range IDs {
container, err := c.GetContainer(ctx, ID)
if err != nil {
ch <- &types.ControlContainerMessage{
ContainerID: ID,
Error: err,
}
continue
}
wg.Add(1)
go func(container *types.Container) {
defer wg.Done()
var err error
var message []*bytes.Buffer
defer func() {
if err == nil {
log.Infof("[ControlContainer] Control container %s %s", container.ID, t)
log.Infof("[ControlContainer] Output:\n %s", string(types.HookOutput(message)))
}
ch <- &types.ControlContainerMessage{
ContainerID: container.ID,
Error: err,
Hook: message,
}
}()
containerInfo, err := container.Inspect(ctx)
if err != nil {
return
}
switch t {
case cluster.ContainerStop:
message, err = c.doStopContainer(ctx, container, containerInfo, false)
return
case cluster.ContainerStart:
message, err = c.doStartContainer(ctx, container, containerInfo)
return
case cluster.ContainerRestart:
message, err = c.doStopContainer(ctx, container, containerInfo, false)
if err != nil {
return
}
m2, e2 := c.doStartContainer(ctx, container, containerInfo)
message = append(message, m2...)
if e2 != nil {
err = e2
}
return
default:
err = types.ErrUnknownControlType
}
}(container)
}
wg.Wait()
}()
return ch, nil
} | go | func (c *Calcium) ControlContainer(ctx context.Context, IDs []string, t string) (chan *types.ControlContainerMessage, error) {
ch := make(chan *types.ControlContainerMessage)
go func() {
defer close(ch)
wg := sync.WaitGroup{}
for _, ID := range IDs {
container, err := c.GetContainer(ctx, ID)
if err != nil {
ch <- &types.ControlContainerMessage{
ContainerID: ID,
Error: err,
}
continue
}
wg.Add(1)
go func(container *types.Container) {
defer wg.Done()
var err error
var message []*bytes.Buffer
defer func() {
if err == nil {
log.Infof("[ControlContainer] Control container %s %s", container.ID, t)
log.Infof("[ControlContainer] Output:\n %s", string(types.HookOutput(message)))
}
ch <- &types.ControlContainerMessage{
ContainerID: container.ID,
Error: err,
Hook: message,
}
}()
containerInfo, err := container.Inspect(ctx)
if err != nil {
return
}
switch t {
case cluster.ContainerStop:
message, err = c.doStopContainer(ctx, container, containerInfo, false)
return
case cluster.ContainerStart:
message, err = c.doStartContainer(ctx, container, containerInfo)
return
case cluster.ContainerRestart:
message, err = c.doStopContainer(ctx, container, containerInfo, false)
if err != nil {
return
}
m2, e2 := c.doStartContainer(ctx, container, containerInfo)
message = append(message, m2...)
if e2 != nil {
err = e2
}
return
default:
err = types.ErrUnknownControlType
}
}(container)
}
wg.Wait()
}()
return ch, nil
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"ControlContainer",
"(",
"ctx",
"context",
".",
"Context",
",",
"IDs",
"[",
"]",
"string",
",",
"t",
"string",
")",
"(",
"chan",
"*",
"types",
".",
"ControlContainerMessage",
",",
"error",
")",
"{",
"ch",
":=",
"make",
"(",
"chan",
"*",
"types",
".",
"ControlContainerMessage",
")",
"\n\n",
"go",
"func",
"(",
")",
"{",
"defer",
"close",
"(",
"ch",
")",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"for",
"_",
",",
"ID",
":=",
"range",
"IDs",
"{",
"container",
",",
"err",
":=",
"c",
".",
"GetContainer",
"(",
"ctx",
",",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ch",
"<-",
"&",
"types",
".",
"ControlContainerMessage",
"{",
"ContainerID",
":",
"ID",
",",
"Error",
":",
"err",
",",
"}",
"\n",
"continue",
"\n",
"}",
"\n\n",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"container",
"*",
"types",
".",
"Container",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"var",
"err",
"error",
"\n",
"var",
"message",
"[",
"]",
"*",
"bytes",
".",
"Buffer",
"\n",
"defer",
"func",
"(",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"container",
".",
"ID",
",",
"t",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\\n",
"\"",
",",
"string",
"(",
"types",
".",
"HookOutput",
"(",
"message",
")",
")",
")",
"\n",
"}",
"\n",
"ch",
"<-",
"&",
"types",
".",
"ControlContainerMessage",
"{",
"ContainerID",
":",
"container",
".",
"ID",
",",
"Error",
":",
"err",
",",
"Hook",
":",
"message",
",",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"containerInfo",
",",
"err",
":=",
"container",
".",
"Inspect",
"(",
"ctx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"switch",
"t",
"{",
"case",
"cluster",
".",
"ContainerStop",
":",
"message",
",",
"err",
"=",
"c",
".",
"doStopContainer",
"(",
"ctx",
",",
"container",
",",
"containerInfo",
",",
"false",
")",
"\n",
"return",
"\n",
"case",
"cluster",
".",
"ContainerStart",
":",
"message",
",",
"err",
"=",
"c",
".",
"doStartContainer",
"(",
"ctx",
",",
"container",
",",
"containerInfo",
")",
"\n",
"return",
"\n",
"case",
"cluster",
".",
"ContainerRestart",
":",
"message",
",",
"err",
"=",
"c",
".",
"doStopContainer",
"(",
"ctx",
",",
"container",
",",
"containerInfo",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"m2",
",",
"e2",
":=",
"c",
".",
"doStartContainer",
"(",
"ctx",
",",
"container",
",",
"containerInfo",
")",
"\n",
"message",
"=",
"append",
"(",
"message",
",",
"m2",
"...",
")",
"\n",
"if",
"e2",
"!=",
"nil",
"{",
"err",
"=",
"e2",
"\n",
"}",
"\n",
"return",
"\n",
"default",
":",
"err",
"=",
"types",
".",
"ErrUnknownControlType",
"\n",
"}",
"\n",
"}",
"(",
"container",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"ch",
",",
"nil",
"\n",
"}"
] | // ControlContainer control containers status | [
"ControlContainer",
"control",
"containers",
"status"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/control.go#L15-L80 |
16,232 | projecteru2/core | cluster/calcium/image.go | RemoveImage | func (c *Calcium) RemoveImage(ctx context.Context, podname, nodename string, images []string, step int, prune bool) (chan *types.RemoveImageMessage, error) {
ch := make(chan *types.RemoveImageMessage)
if step < 1 {
step = 1
}
var err error
nodes := []*types.Node{}
if nodename != "" {
n, err := c.GetNode(ctx, podname, nodename)
if err != nil {
return ch, err
}
nodes = append(nodes, n)
} else {
nodes, err = c.store.GetNodesByPod(ctx, podname)
if err != nil {
return ch, err
}
}
if len(nodes) == 0 {
return nil, types.ErrPodNoNodes
}
go func() {
defer close(ch)
wg := sync.WaitGroup{}
defer wg.Wait()
for i, node := range nodes {
wg.Add(1)
go func(node *types.Node) {
defer wg.Done()
for _, image := range images {
m := &types.RemoveImageMessage{
Success: false,
Image: image,
Messages: []string{},
}
if removeItems, err := node.Engine.ImageRemove(ctx, image, false, true); err != nil {
m.Messages = append(m.Messages, err.Error())
} else {
m.Success = true
for _, item := range removeItems {
m.Messages = append(m.Messages, fmt.Sprintf("Clean: %s", item))
}
}
ch <- m
}
if prune {
if err := node.Engine.ImagesPrune(ctx); err != nil {
log.Errorf("[RemoveImage] Prune %s pod %s node failed: %v", podname, node.Name, err)
} else {
log.Infof("[RemoveImage] Prune %s pod %s node", podname, node.Name)
}
}
}(node)
if (i+1)%step == 0 {
log.Info("[RemoveImage] Wait for previous cleaner done")
wg.Wait()
}
}
}()
return ch, nil
} | go | func (c *Calcium) RemoveImage(ctx context.Context, podname, nodename string, images []string, step int, prune bool) (chan *types.RemoveImageMessage, error) {
ch := make(chan *types.RemoveImageMessage)
if step < 1 {
step = 1
}
var err error
nodes := []*types.Node{}
if nodename != "" {
n, err := c.GetNode(ctx, podname, nodename)
if err != nil {
return ch, err
}
nodes = append(nodes, n)
} else {
nodes, err = c.store.GetNodesByPod(ctx, podname)
if err != nil {
return ch, err
}
}
if len(nodes) == 0 {
return nil, types.ErrPodNoNodes
}
go func() {
defer close(ch)
wg := sync.WaitGroup{}
defer wg.Wait()
for i, node := range nodes {
wg.Add(1)
go func(node *types.Node) {
defer wg.Done()
for _, image := range images {
m := &types.RemoveImageMessage{
Success: false,
Image: image,
Messages: []string{},
}
if removeItems, err := node.Engine.ImageRemove(ctx, image, false, true); err != nil {
m.Messages = append(m.Messages, err.Error())
} else {
m.Success = true
for _, item := range removeItems {
m.Messages = append(m.Messages, fmt.Sprintf("Clean: %s", item))
}
}
ch <- m
}
if prune {
if err := node.Engine.ImagesPrune(ctx); err != nil {
log.Errorf("[RemoveImage] Prune %s pod %s node failed: %v", podname, node.Name, err)
} else {
log.Infof("[RemoveImage] Prune %s pod %s node", podname, node.Name)
}
}
}(node)
if (i+1)%step == 0 {
log.Info("[RemoveImage] Wait for previous cleaner done")
wg.Wait()
}
}
}()
return ch, nil
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"RemoveImage",
"(",
"ctx",
"context",
".",
"Context",
",",
"podname",
",",
"nodename",
"string",
",",
"images",
"[",
"]",
"string",
",",
"step",
"int",
",",
"prune",
"bool",
")",
"(",
"chan",
"*",
"types",
".",
"RemoveImageMessage",
",",
"error",
")",
"{",
"ch",
":=",
"make",
"(",
"chan",
"*",
"types",
".",
"RemoveImageMessage",
")",
"\n",
"if",
"step",
"<",
"1",
"{",
"step",
"=",
"1",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"nodes",
":=",
"[",
"]",
"*",
"types",
".",
"Node",
"{",
"}",
"\n",
"if",
"nodename",
"!=",
"\"",
"\"",
"{",
"n",
",",
"err",
":=",
"c",
".",
"GetNode",
"(",
"ctx",
",",
"podname",
",",
"nodename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ch",
",",
"err",
"\n",
"}",
"\n",
"nodes",
"=",
"append",
"(",
"nodes",
",",
"n",
")",
"\n",
"}",
"else",
"{",
"nodes",
",",
"err",
"=",
"c",
".",
"store",
".",
"GetNodesByPod",
"(",
"ctx",
",",
"podname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"ch",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"nodes",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"types",
".",
"ErrPodNoNodes",
"\n",
"}",
"\n\n",
"go",
"func",
"(",
")",
"{",
"defer",
"close",
"(",
"ch",
")",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"defer",
"wg",
".",
"Wait",
"(",
")",
"\n",
"for",
"i",
",",
"node",
":=",
"range",
"nodes",
"{",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"node",
"*",
"types",
".",
"Node",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"for",
"_",
",",
"image",
":=",
"range",
"images",
"{",
"m",
":=",
"&",
"types",
".",
"RemoveImageMessage",
"{",
"Success",
":",
"false",
",",
"Image",
":",
"image",
",",
"Messages",
":",
"[",
"]",
"string",
"{",
"}",
",",
"}",
"\n",
"if",
"removeItems",
",",
"err",
":=",
"node",
".",
"Engine",
".",
"ImageRemove",
"(",
"ctx",
",",
"image",
",",
"false",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"m",
".",
"Messages",
"=",
"append",
"(",
"m",
".",
"Messages",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"else",
"{",
"m",
".",
"Success",
"=",
"true",
"\n",
"for",
"_",
",",
"item",
":=",
"range",
"removeItems",
"{",
"m",
".",
"Messages",
"=",
"append",
"(",
"m",
".",
"Messages",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"item",
")",
")",
"\n",
"}",
"\n",
"}",
"\n",
"ch",
"<-",
"m",
"\n",
"}",
"\n",
"if",
"prune",
"{",
"if",
"err",
":=",
"node",
".",
"Engine",
".",
"ImagesPrune",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"podname",
",",
"node",
".",
"Name",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"podname",
",",
"node",
".",
"Name",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
"node",
")",
"\n",
"if",
"(",
"i",
"+",
"1",
")",
"%",
"step",
"==",
"0",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"return",
"ch",
",",
"nil",
"\n",
"}"
] | // RemoveImage remove images | [
"RemoveImage",
"remove",
"images"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/image.go#L13-L78 |
16,233 | projecteru2/core | utils/utils.go | RandomString | func RandomString(n int) string {
r := make([]byte, n)
for i := 0; i < n; i++ {
n, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
// 没那么惨吧
if err != nil {
continue
}
r[i] = letters[n.Int64()]
}
return string(r)
} | go | func RandomString(n int) string {
r := make([]byte, n)
for i := 0; i < n; i++ {
n, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
// 没那么惨吧
if err != nil {
continue
}
r[i] = letters[n.Int64()]
}
return string(r)
} | [
"func",
"RandomString",
"(",
"n",
"int",
")",
"string",
"{",
"r",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"n",
")",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"n",
";",
"i",
"++",
"{",
"n",
",",
"err",
":=",
"rand",
".",
"Int",
"(",
"rand",
".",
"Reader",
",",
"big",
".",
"NewInt",
"(",
"int64",
"(",
"len",
"(",
"letters",
")",
")",
")",
")",
"\n",
"// 没那么惨吧",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"r",
"[",
"i",
"]",
"=",
"letters",
"[",
"n",
".",
"Int64",
"(",
")",
"]",
"\n",
"}",
"\n",
"return",
"string",
"(",
"r",
")",
"\n",
"}"
] | // RandomString random a string | [
"RandomString",
"random",
"a",
"string"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L33-L44 |
16,234 | projecteru2/core | utils/utils.go | Tail | func Tail(path string) string {
parts := strings.Split(path, "/")
return parts[len(parts)-1]
} | go | func Tail(path string) string {
parts := strings.Split(path, "/")
return parts[len(parts)-1]
} | [
"func",
"Tail",
"(",
"path",
"string",
")",
"string",
"{",
"parts",
":=",
"strings",
".",
"Split",
"(",
"path",
",",
"\"",
"\"",
")",
"\n",
"return",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"1",
"]",
"\n",
"}"
] | // Tail return tail thing | [
"Tail",
"return",
"tail",
"thing"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L47-L50 |
16,235 | projecteru2/core | utils/utils.go | GetGitRepoName | func GetGitRepoName(url string) (string, error) {
if !(strings.Contains(url, "git@") || strings.Contains(url, "gitlab@") || strings.Contains(url, "https://")) ||
!strings.HasSuffix(url, ".git") {
return "", fmt.Errorf("Bad git url format %q", url)
}
return strings.TrimSuffix(Tail(url), ".git"), nil
} | go | func GetGitRepoName(url string) (string, error) {
if !(strings.Contains(url, "git@") || strings.Contains(url, "gitlab@") || strings.Contains(url, "https://")) ||
!strings.HasSuffix(url, ".git") {
return "", fmt.Errorf("Bad git url format %q", url)
}
return strings.TrimSuffix(Tail(url), ".git"), nil
} | [
"func",
"GetGitRepoName",
"(",
"url",
"string",
")",
"(",
"string",
",",
"error",
")",
"{",
"if",
"!",
"(",
"strings",
".",
"Contains",
"(",
"url",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"url",
",",
"\"",
"\"",
")",
"||",
"strings",
".",
"Contains",
"(",
"url",
",",
"\"",
"\"",
")",
")",
"||",
"!",
"strings",
".",
"HasSuffix",
"(",
"url",
",",
"\"",
"\"",
")",
"{",
"return",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"url",
")",
"\n",
"}",
"\n\n",
"return",
"strings",
".",
"TrimSuffix",
"(",
"Tail",
"(",
"url",
")",
",",
"\"",
"\"",
")",
",",
"nil",
"\n",
"}"
] | // GetGitRepoName return git repo name | [
"GetGitRepoName",
"return",
"git",
"repo",
"name"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L53-L60 |
16,236 | projecteru2/core | utils/utils.go | GetTag | func GetTag(image string) string {
if !strings.Contains(image, ":") {
return DefaultVersion
}
parts := strings.Split(image, ":")
if len(parts) != 2 {
return WrongVersion
}
return parts[len(parts)-1]
} | go | func GetTag(image string) string {
if !strings.Contains(image, ":") {
return DefaultVersion
}
parts := strings.Split(image, ":")
if len(parts) != 2 {
return WrongVersion
}
return parts[len(parts)-1]
} | [
"func",
"GetTag",
"(",
"image",
"string",
")",
"string",
"{",
"if",
"!",
"strings",
".",
"Contains",
"(",
"image",
",",
"\"",
"\"",
")",
"{",
"return",
"DefaultVersion",
"\n",
"}",
"\n\n",
"parts",
":=",
"strings",
".",
"Split",
"(",
"image",
",",
"\"",
"\"",
")",
"\n",
"if",
"len",
"(",
"parts",
")",
"!=",
"2",
"{",
"return",
"WrongVersion",
"\n",
"}",
"\n\n",
"return",
"parts",
"[",
"len",
"(",
"parts",
")",
"-",
"1",
"]",
"\n",
"}"
] | // GetTag reture image tag | [
"GetTag",
"reture",
"image",
"tag"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L63-L74 |
16,237 | projecteru2/core | utils/utils.go | NormalizeImageName | func NormalizeImageName(image string) string {
if !strings.Contains(image, ":") {
return fmt.Sprintf("%s:latest", image)
}
return image
} | go | func NormalizeImageName(image string) string {
if !strings.Contains(image, ":") {
return fmt.Sprintf("%s:latest", image)
}
return image
} | [
"func",
"NormalizeImageName",
"(",
"image",
"string",
")",
"string",
"{",
"if",
"!",
"strings",
".",
"Contains",
"(",
"image",
",",
"\"",
"\"",
")",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"image",
")",
"\n",
"}",
"\n",
"return",
"image",
"\n",
"}"
] | // NormalizeImageName will normalize image name | [
"NormalizeImageName",
"will",
"normalize",
"image",
"name"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L77-L82 |
16,238 | projecteru2/core | utils/utils.go | MakeCommandLineArgs | func MakeCommandLineArgs(s string) []string {
r := []string{}
for _, part := range safeSplit(s) {
if len(part) == 0 {
continue
}
r = append(r, part)
}
return r
} | go | func MakeCommandLineArgs(s string) []string {
r := []string{}
for _, part := range safeSplit(s) {
if len(part) == 0 {
continue
}
r = append(r, part)
}
return r
} | [
"func",
"MakeCommandLineArgs",
"(",
"s",
"string",
")",
"[",
"]",
"string",
"{",
"r",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"part",
":=",
"range",
"safeSplit",
"(",
"s",
")",
"{",
"if",
"len",
"(",
"part",
")",
"==",
"0",
"{",
"continue",
"\n",
"}",
"\n",
"r",
"=",
"append",
"(",
"r",
",",
"part",
")",
"\n",
"}",
"\n",
"return",
"r",
"\n",
"}"
] | // MakeCommandLineArgs make command line args | [
"MakeCommandLineArgs",
"make",
"command",
"line",
"args"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L85-L94 |
16,239 | projecteru2/core | utils/utils.go | MakeContainerName | func MakeContainerName(appname, entrypoint, ident string) string {
return strings.Join([]string{appname, entrypoint, ident}, "_")
} | go | func MakeContainerName(appname, entrypoint, ident string) string {
return strings.Join([]string{appname, entrypoint, ident}, "_")
} | [
"func",
"MakeContainerName",
"(",
"appname",
",",
"entrypoint",
",",
"ident",
"string",
")",
"string",
"{",
"return",
"strings",
".",
"Join",
"(",
"[",
"]",
"string",
"{",
"appname",
",",
"entrypoint",
",",
"ident",
"}",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // MakeContainerName joins appname, entrypoint, ident using '_' | [
"MakeContainerName",
"joins",
"appname",
"entrypoint",
"ident",
"using",
"_"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L97-L99 |
16,240 | projecteru2/core | utils/utils.go | ParseContainerName | func ParseContainerName(containerName string) (string, string, string, error) {
containerName = strings.TrimLeft(containerName, "/")
splits := strings.Split(containerName, "_")
length := len(splits)
if length >= 3 {
return strings.Join(splits[0:length-2], "_"), splits[length-2], splits[length-1], nil
}
return "", "", "", fmt.Errorf("Bad containerName: %s", containerName)
} | go | func ParseContainerName(containerName string) (string, string, string, error) {
containerName = strings.TrimLeft(containerName, "/")
splits := strings.Split(containerName, "_")
length := len(splits)
if length >= 3 {
return strings.Join(splits[0:length-2], "_"), splits[length-2], splits[length-1], nil
}
return "", "", "", fmt.Errorf("Bad containerName: %s", containerName)
} | [
"func",
"ParseContainerName",
"(",
"containerName",
"string",
")",
"(",
"string",
",",
"string",
",",
"string",
",",
"error",
")",
"{",
"containerName",
"=",
"strings",
".",
"TrimLeft",
"(",
"containerName",
",",
"\"",
"\"",
")",
"\n",
"splits",
":=",
"strings",
".",
"Split",
"(",
"containerName",
",",
"\"",
"\"",
")",
"\n",
"length",
":=",
"len",
"(",
"splits",
")",
"\n",
"if",
"length",
">=",
"3",
"{",
"return",
"strings",
".",
"Join",
"(",
"splits",
"[",
"0",
":",
"length",
"-",
"2",
"]",
",",
"\"",
"\"",
")",
",",
"splits",
"[",
"length",
"-",
"2",
"]",
",",
"splits",
"[",
"length",
"-",
"1",
"]",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"containerName",
")",
"\n",
"}"
] | // ParseContainerName does the opposite thing as MakeContainerName | [
"ParseContainerName",
"does",
"the",
"opposite",
"thing",
"as",
"MakeContainerName"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L102-L110 |
16,241 | projecteru2/core | utils/utils.go | MakePublishInfo | func MakePublishInfo(networks map[string]string, ports []string) map[string][]string {
result := map[string][]string{}
for networkName, ip := range networks {
data := []string{}
for _, port := range ports {
data = append(data, fmt.Sprintf("%s:%s", ip, port))
}
if len(data) > 0 {
result[networkName] = data
}
}
return result
} | go | func MakePublishInfo(networks map[string]string, ports []string) map[string][]string {
result := map[string][]string{}
for networkName, ip := range networks {
data := []string{}
for _, port := range ports {
data = append(data, fmt.Sprintf("%s:%s", ip, port))
}
if len(data) > 0 {
result[networkName] = data
}
}
return result
} | [
"func",
"MakePublishInfo",
"(",
"networks",
"map",
"[",
"string",
"]",
"string",
",",
"ports",
"[",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"result",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"networkName",
",",
"ip",
":=",
"range",
"networks",
"{",
"data",
":=",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"_",
",",
"port",
":=",
"range",
"ports",
"{",
"data",
"=",
"append",
"(",
"data",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ip",
",",
"port",
")",
")",
"\n",
"}",
"\n",
"if",
"len",
"(",
"data",
")",
">",
"0",
"{",
"result",
"[",
"networkName",
"]",
"=",
"data",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // MakePublishInfo generate publish info | [
"MakePublishInfo",
"generate",
"publish",
"info"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L113-L125 |
16,242 | projecteru2/core | utils/utils.go | EncodePublishInfo | func EncodePublishInfo(info map[string][]string) map[string]string {
result := map[string]string{}
for nm, publishs := range info {
if len(publishs) > 0 {
result[nm] = strings.Join(publishs, ",")
}
}
return result
} | go | func EncodePublishInfo(info map[string][]string) map[string]string {
result := map[string]string{}
for nm, publishs := range info {
if len(publishs) > 0 {
result[nm] = strings.Join(publishs, ",")
}
}
return result
} | [
"func",
"EncodePublishInfo",
"(",
"info",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"string",
"{",
"result",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"for",
"nm",
",",
"publishs",
":=",
"range",
"info",
"{",
"if",
"len",
"(",
"publishs",
")",
">",
"0",
"{",
"result",
"[",
"nm",
"]",
"=",
"strings",
".",
"Join",
"(",
"publishs",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // EncodePublishInfo encode publish info | [
"EncodePublishInfo",
"encode",
"publish",
"info"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L128-L136 |
16,243 | projecteru2/core | utils/utils.go | DecodePublishInfo | func DecodePublishInfo(info map[string]string) map[string][]string {
result := map[string][]string{}
for nm, publishs := range info {
if publishs != "" {
result[nm] = strings.Split(publishs, ",")
}
}
return result
} | go | func DecodePublishInfo(info map[string]string) map[string][]string {
result := map[string][]string{}
for nm, publishs := range info {
if publishs != "" {
result[nm] = strings.Split(publishs, ",")
}
}
return result
} | [
"func",
"DecodePublishInfo",
"(",
"info",
"map",
"[",
"string",
"]",
"string",
")",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"result",
":=",
"map",
"[",
"string",
"]",
"[",
"]",
"string",
"{",
"}",
"\n",
"for",
"nm",
",",
"publishs",
":=",
"range",
"info",
"{",
"if",
"publishs",
"!=",
"\"",
"\"",
"{",
"result",
"[",
"nm",
"]",
"=",
"strings",
".",
"Split",
"(",
"publishs",
",",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] | // DecodePublishInfo decode publish info | [
"DecodePublishInfo",
"decode",
"publish",
"info"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L139-L147 |
16,244 | projecteru2/core | utils/utils.go | EncodeMetaInLabel | func EncodeMetaInLabel(meta *types.EruMeta) string {
data, err := json.Marshal(meta)
if err != nil {
log.Errorf("[EncodeMetaInLabel] Encode meta failed %v", err)
return ""
}
return string(data)
} | go | func EncodeMetaInLabel(meta *types.EruMeta) string {
data, err := json.Marshal(meta)
if err != nil {
log.Errorf("[EncodeMetaInLabel] Encode meta failed %v", err)
return ""
}
return string(data)
} | [
"func",
"EncodeMetaInLabel",
"(",
"meta",
"*",
"types",
".",
"EruMeta",
")",
"string",
"{",
"data",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"meta",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"string",
"(",
"data",
")",
"\n",
"}"
] | // EncodeMetaInLabel encode meta to json | [
"EncodeMetaInLabel",
"encode",
"meta",
"to",
"json"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L150-L157 |
16,245 | projecteru2/core | utils/utils.go | DecodeMetaInLabel | func DecodeMetaInLabel(labels map[string]string) *types.EruMeta {
meta := &types.EruMeta{}
metastr, ok := labels[cluster.ERUMeta]
if ok {
if err := json.Unmarshal([]byte(metastr), meta); err != nil {
log.Errorf("[DecodeMetaInLabel] Decode failed %v", err)
}
}
return meta
} | go | func DecodeMetaInLabel(labels map[string]string) *types.EruMeta {
meta := &types.EruMeta{}
metastr, ok := labels[cluster.ERUMeta]
if ok {
if err := json.Unmarshal([]byte(metastr), meta); err != nil {
log.Errorf("[DecodeMetaInLabel] Decode failed %v", err)
}
}
return meta
} | [
"func",
"DecodeMetaInLabel",
"(",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"*",
"types",
".",
"EruMeta",
"{",
"meta",
":=",
"&",
"types",
".",
"EruMeta",
"{",
"}",
"\n",
"metastr",
",",
"ok",
":=",
"labels",
"[",
"cluster",
".",
"ERUMeta",
"]",
"\n",
"if",
"ok",
"{",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"[",
"]",
"byte",
"(",
"metastr",
")",
",",
"meta",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"meta",
"\n",
"}"
] | // DecodeMetaInLabel get meta from label and decode it | [
"DecodeMetaInLabel",
"get",
"meta",
"from",
"label",
"and",
"decode",
"it"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L160-L169 |
16,246 | projecteru2/core | utils/utils.go | ShortID | func ShortID(containerID string) string {
if len(containerID) > shortenLength {
return containerID[:shortenLength]
}
return containerID
} | go | func ShortID(containerID string) string {
if len(containerID) > shortenLength {
return containerID[:shortenLength]
}
return containerID
} | [
"func",
"ShortID",
"(",
"containerID",
"string",
")",
"string",
"{",
"if",
"len",
"(",
"containerID",
")",
">",
"shortenLength",
"{",
"return",
"containerID",
"[",
":",
"shortenLength",
"]",
"\n",
"}",
"\n",
"return",
"containerID",
"\n",
"}"
] | // ShortID short container ID | [
"ShortID",
"short",
"container",
"ID"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L172-L177 |
16,247 | projecteru2/core | utils/utils.go | FilterContainer | func FilterContainer(extend map[string]string, labels map[string]string) bool {
for k, v := range labels {
if n, ok := extend[k]; !ok || n != v {
return false
}
}
return true
} | go | func FilterContainer(extend map[string]string, labels map[string]string) bool {
for k, v := range labels {
if n, ok := extend[k]; !ok || n != v {
return false
}
}
return true
} | [
"func",
"FilterContainer",
"(",
"extend",
"map",
"[",
"string",
"]",
"string",
",",
"labels",
"map",
"[",
"string",
"]",
"string",
")",
"bool",
"{",
"for",
"k",
",",
"v",
":=",
"range",
"labels",
"{",
"if",
"n",
",",
"ok",
":=",
"extend",
"[",
"k",
"]",
";",
"!",
"ok",
"||",
"n",
"!=",
"v",
"{",
"return",
"false",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"true",
"\n",
"}"
] | // FilterContainer filter container by labels | [
"FilterContainer",
"filter",
"container",
"by",
"labels"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L180-L187 |
16,248 | projecteru2/core | utils/utils.go | TempFile | func TempFile(stream io.ReadCloser) (string, error) {
f, err := ioutil.TempFile(os.TempDir(), "")
if err != nil {
return "", err
}
defer f.Close()
defer stream.Close()
_, err = io.Copy(f, stream)
return f.Name(), err
} | go | func TempFile(stream io.ReadCloser) (string, error) {
f, err := ioutil.TempFile(os.TempDir(), "")
if err != nil {
return "", err
}
defer f.Close()
defer stream.Close()
_, err = io.Copy(f, stream)
return f.Name(), err
} | [
"func",
"TempFile",
"(",
"stream",
"io",
".",
"ReadCloser",
")",
"(",
"string",
",",
"error",
")",
"{",
"f",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"os",
".",
"TempDir",
"(",
")",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n",
"defer",
"stream",
".",
"Close",
"(",
")",
"\n\n",
"_",
",",
"err",
"=",
"io",
".",
"Copy",
"(",
"f",
",",
"stream",
")",
"\n",
"return",
"f",
".",
"Name",
"(",
")",
",",
"err",
"\n",
"}"
] | // TempFile store a temp file | [
"TempFile",
"store",
"a",
"temp",
"file"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L195-L205 |
16,249 | projecteru2/core | utils/utils.go | TempTarFile | func TempTarFile(path string, data []byte) (string, error) {
filename := filepath.Base(path)
f, err := ioutil.TempFile(os.TempDir(), filename)
if err != nil {
return "", err
}
name := f.Name()
defer f.Close()
tw := tar.NewWriter(f)
defer tw.Close()
hdr := &tar.Header{
Name: filename,
Mode: 0755,
Size: int64(len(data)),
}
if err := tw.WriteHeader(hdr); err != nil {
return name, err
}
_, err = tw.Write(data)
return name, err
} | go | func TempTarFile(path string, data []byte) (string, error) {
filename := filepath.Base(path)
f, err := ioutil.TempFile(os.TempDir(), filename)
if err != nil {
return "", err
}
name := f.Name()
defer f.Close()
tw := tar.NewWriter(f)
defer tw.Close()
hdr := &tar.Header{
Name: filename,
Mode: 0755,
Size: int64(len(data)),
}
if err := tw.WriteHeader(hdr); err != nil {
return name, err
}
_, err = tw.Write(data)
return name, err
} | [
"func",
"TempTarFile",
"(",
"path",
"string",
",",
"data",
"[",
"]",
"byte",
")",
"(",
"string",
",",
"error",
")",
"{",
"filename",
":=",
"filepath",
".",
"Base",
"(",
"path",
")",
"\n",
"f",
",",
"err",
":=",
"ioutil",
".",
"TempFile",
"(",
"os",
".",
"TempDir",
"(",
")",
",",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"name",
":=",
"f",
".",
"Name",
"(",
")",
"\n",
"defer",
"f",
".",
"Close",
"(",
")",
"\n\n",
"tw",
":=",
"tar",
".",
"NewWriter",
"(",
"f",
")",
"\n",
"defer",
"tw",
".",
"Close",
"(",
")",
"\n",
"hdr",
":=",
"&",
"tar",
".",
"Header",
"{",
"Name",
":",
"filename",
",",
"Mode",
":",
"0755",
",",
"Size",
":",
"int64",
"(",
"len",
"(",
"data",
")",
")",
",",
"}",
"\n",
"if",
"err",
":=",
"tw",
".",
"WriteHeader",
"(",
"hdr",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"name",
",",
"err",
"\n",
"}",
"\n",
"_",
",",
"err",
"=",
"tw",
".",
"Write",
"(",
"data",
")",
"\n",
"return",
"name",
",",
"err",
"\n",
"}"
] | // TempTarFile store and tar bytes to a file | [
"TempTarFile",
"store",
"and",
"tar",
"bytes",
"to",
"a",
"file"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/utils.go#L208-L229 |
16,250 | projecteru2/core | store/etcdv3/helper.go | makeDockerClientWithTLS | func makeDockerClientWithTLS(config types.Config, ca, cert, key *os.File, endpoint, apiversion string) (engine.API, error) {
return docker.MakeRawClientWithTLS(config, ca, cert, key, endpoint, apiversion)
} | go | func makeDockerClientWithTLS(config types.Config, ca, cert, key *os.File, endpoint, apiversion string) (engine.API, error) {
return docker.MakeRawClientWithTLS(config, ca, cert, key, endpoint, apiversion)
} | [
"func",
"makeDockerClientWithTLS",
"(",
"config",
"types",
".",
"Config",
",",
"ca",
",",
"cert",
",",
"key",
"*",
"os",
".",
"File",
",",
"endpoint",
",",
"apiversion",
"string",
")",
"(",
"engine",
".",
"API",
",",
"error",
")",
"{",
"return",
"docker",
".",
"MakeRawClientWithTLS",
"(",
"config",
",",
"ca",
",",
"cert",
",",
"key",
",",
"endpoint",
",",
"apiversion",
")",
"\n",
"}"
] | // use endpoint, cert files path, and api version to create docker client
// we don't check whether this is connectable | [
"use",
"endpoint",
"cert",
"files",
"path",
"and",
"api",
"version",
"to",
"create",
"docker",
"client",
"we",
"don",
"t",
"check",
"whether",
"this",
"is",
"connectable"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/helper.go#L47-L49 |
16,251 | projecteru2/core | client/client.go | NewClient | func NewClient(addr string, authConfig types.AuthConfig) *Client {
conn := connect(addr, authConfig)
return &Client{addr: addr, conn: conn}
} | go | func NewClient(addr string, authConfig types.AuthConfig) *Client {
conn := connect(addr, authConfig)
return &Client{addr: addr, conn: conn}
} | [
"func",
"NewClient",
"(",
"addr",
"string",
",",
"authConfig",
"types",
".",
"AuthConfig",
")",
"*",
"Client",
"{",
"conn",
":=",
"connect",
"(",
"addr",
",",
"authConfig",
")",
"\n",
"return",
"&",
"Client",
"{",
"addr",
":",
"addr",
",",
"conn",
":",
"conn",
"}",
"\n",
"}"
] | // NewClient new a client | [
"NewClient",
"new",
"a",
"client"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/client/client.go#L18-L21 |
16,252 | projecteru2/core | store/etcdv3/embeded/embeded.go | NewCluster | func NewCluster() *clientv3.Client {
t = &testing.T{}
embeddedCluster = integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
return embeddedCluster.RandClient()
} | go | func NewCluster() *clientv3.Client {
t = &testing.T{}
embeddedCluster = integration.NewClusterV3(t, &integration.ClusterConfig{Size: 1})
return embeddedCluster.RandClient()
} | [
"func",
"NewCluster",
"(",
")",
"*",
"clientv3",
".",
"Client",
"{",
"t",
"=",
"&",
"testing",
".",
"T",
"{",
"}",
"\n",
"embeddedCluster",
"=",
"integration",
".",
"NewClusterV3",
"(",
"t",
",",
"&",
"integration",
".",
"ClusterConfig",
"{",
"Size",
":",
"1",
"}",
")",
"\n",
"return",
"embeddedCluster",
".",
"RandClient",
"(",
")",
"\n",
"}"
] | // NewCluster new a embeded cluster | [
"NewCluster",
"new",
"a",
"embeded",
"cluster"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/embeded/embeded.go#L17-L21 |
16,253 | projecteru2/core | utils/config.go | LoadConfig | func LoadConfig(configPath string) (types.Config, error) {
config := types.Config{}
bytes, err := ioutil.ReadFile(configPath)
if err != nil {
return config, err
}
if err := yaml.Unmarshal(bytes, &config); err != nil {
return config, err
}
if config.LockTimeout == 0 {
config.LockTimeout = defaultTTL
}
if config.GlobalTimeout == 0 {
log.Fatal("[Config] Global timeout invaild, exit")
}
config.GlobalTimeout = config.GlobalTimeout * time.Second
if config.Etcd.Prefix == "" {
config.Etcd.Prefix = defaultPrefix
}
if config.Docker.APIVersion == "" {
config.Docker.APIVersion = "1.32"
}
// 默认是 journald
if config.Docker.Log.Type == "" {
config.Docker.Log.Type = "journald"
}
if config.Scheduler.ShareBase == 0 {
config.Scheduler.ShareBase = 100
}
if config.Scheduler.MaxShare == 0 {
config.Scheduler.MaxShare = -1
}
return config, nil
} | go | func LoadConfig(configPath string) (types.Config, error) {
config := types.Config{}
bytes, err := ioutil.ReadFile(configPath)
if err != nil {
return config, err
}
if err := yaml.Unmarshal(bytes, &config); err != nil {
return config, err
}
if config.LockTimeout == 0 {
config.LockTimeout = defaultTTL
}
if config.GlobalTimeout == 0 {
log.Fatal("[Config] Global timeout invaild, exit")
}
config.GlobalTimeout = config.GlobalTimeout * time.Second
if config.Etcd.Prefix == "" {
config.Etcd.Prefix = defaultPrefix
}
if config.Docker.APIVersion == "" {
config.Docker.APIVersion = "1.32"
}
// 默认是 journald
if config.Docker.Log.Type == "" {
config.Docker.Log.Type = "journald"
}
if config.Scheduler.ShareBase == 0 {
config.Scheduler.ShareBase = 100
}
if config.Scheduler.MaxShare == 0 {
config.Scheduler.MaxShare = -1
}
return config, nil
} | [
"func",
"LoadConfig",
"(",
"configPath",
"string",
")",
"(",
"types",
".",
"Config",
",",
"error",
")",
"{",
"config",
":=",
"types",
".",
"Config",
"{",
"}",
"\n\n",
"bytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"configPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"config",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"yaml",
".",
"Unmarshal",
"(",
"bytes",
",",
"&",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"config",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"LockTimeout",
"==",
"0",
"{",
"config",
".",
"LockTimeout",
"=",
"defaultTTL",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"GlobalTimeout",
"==",
"0",
"{",
"log",
".",
"Fatal",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"config",
".",
"GlobalTimeout",
"=",
"config",
".",
"GlobalTimeout",
"*",
"time",
".",
"Second",
"\n\n",
"if",
"config",
".",
"Etcd",
".",
"Prefix",
"==",
"\"",
"\"",
"{",
"config",
".",
"Etcd",
".",
"Prefix",
"=",
"defaultPrefix",
"\n",
"}",
"\n\n",
"if",
"config",
".",
"Docker",
".",
"APIVersion",
"==",
"\"",
"\"",
"{",
"config",
".",
"Docker",
".",
"APIVersion",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"// 默认是 journald",
"if",
"config",
".",
"Docker",
".",
"Log",
".",
"Type",
"==",
"\"",
"\"",
"{",
"config",
".",
"Docker",
".",
"Log",
".",
"Type",
"=",
"\"",
"\"",
"\n",
"}",
"\n",
"if",
"config",
".",
"Scheduler",
".",
"ShareBase",
"==",
"0",
"{",
"config",
".",
"Scheduler",
".",
"ShareBase",
"=",
"100",
"\n",
"}",
"\n",
"if",
"config",
".",
"Scheduler",
".",
"MaxShare",
"==",
"0",
"{",
"config",
".",
"Scheduler",
".",
"MaxShare",
"=",
"-",
"1",
"\n",
"}",
"\n\n",
"return",
"config",
",",
"nil",
"\n",
"}"
] | // LoadConfig load config from yaml | [
"LoadConfig",
"load",
"config",
"from",
"yaml"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/config.go#L19-L59 |
16,254 | projecteru2/core | source/common/common.go | SourceCode | func (g *GitScm) SourceCode(repository, path, revision string, submodule bool) error {
if err := gitcheck(repository, g.Config.PublicKey, g.Config.PrivateKey); err != nil {
return err
}
var repo *git.Repository
var err error
if strings.Contains(repository, "https://") {
repo, err = git.Clone(repository, path, &git.CloneOptions{})
} else {
credentialsCallback := func(url, username string, allowedTypes git.CredType) (git.ErrorCode, *git.Cred) {
ret, cred := git.NewCredSshKey(username, g.Config.PublicKey, g.Config.PrivateKey, "")
return git.ErrorCode(ret), &cred
}
cloneOpts := &git.CloneOptions{
FetchOptions: &git.FetchOptions{
RemoteCallbacks: git.RemoteCallbacks{
CredentialsCallback: credentialsCallback,
CertificateCheckCallback: certificateCheckCallback,
},
},
}
repo, err = git.Clone(repository, path, cloneOpts)
}
if err != nil {
return err
}
defer repo.Free()
if err := repo.CheckoutHead(nil); err != nil {
return err
}
object, err := repo.RevparseSingle(revision)
if err != nil {
return err
}
defer object.Free()
object, err = object.Peel(git.ObjectCommit)
if err != nil {
return err
}
commit, err := object.AsCommit()
if err != nil {
return err
}
defer commit.Free()
tree, err := commit.Tree()
if err != nil {
return err
}
defer tree.Free()
if err := repo.CheckoutTree(tree, &git.CheckoutOpts{Strategy: git.CheckoutSafe}); err != nil {
return err
}
log.Infof("[SourceCode] Fetch repo %s", repository)
log.Infof("[SourceCode] Checkout to commit %v", commit.Id())
// Prepare submodules
if submodule {
repo.Submodules.Foreach(func(sub *git.Submodule, name string) int {
sub.Init(true)
err := sub.Update(true, &git.SubmoduleUpdateOptions{
CheckoutOpts: &git.CheckoutOpts{
Strategy: git.CheckoutForce | git.CheckoutUpdateSubmodules,
},
FetchOptions: &git.FetchOptions{},
})
if err != nil {
log.Errorln(err)
}
return 0
})
}
return nil
} | go | func (g *GitScm) SourceCode(repository, path, revision string, submodule bool) error {
if err := gitcheck(repository, g.Config.PublicKey, g.Config.PrivateKey); err != nil {
return err
}
var repo *git.Repository
var err error
if strings.Contains(repository, "https://") {
repo, err = git.Clone(repository, path, &git.CloneOptions{})
} else {
credentialsCallback := func(url, username string, allowedTypes git.CredType) (git.ErrorCode, *git.Cred) {
ret, cred := git.NewCredSshKey(username, g.Config.PublicKey, g.Config.PrivateKey, "")
return git.ErrorCode(ret), &cred
}
cloneOpts := &git.CloneOptions{
FetchOptions: &git.FetchOptions{
RemoteCallbacks: git.RemoteCallbacks{
CredentialsCallback: credentialsCallback,
CertificateCheckCallback: certificateCheckCallback,
},
},
}
repo, err = git.Clone(repository, path, cloneOpts)
}
if err != nil {
return err
}
defer repo.Free()
if err := repo.CheckoutHead(nil); err != nil {
return err
}
object, err := repo.RevparseSingle(revision)
if err != nil {
return err
}
defer object.Free()
object, err = object.Peel(git.ObjectCommit)
if err != nil {
return err
}
commit, err := object.AsCommit()
if err != nil {
return err
}
defer commit.Free()
tree, err := commit.Tree()
if err != nil {
return err
}
defer tree.Free()
if err := repo.CheckoutTree(tree, &git.CheckoutOpts{Strategy: git.CheckoutSafe}); err != nil {
return err
}
log.Infof("[SourceCode] Fetch repo %s", repository)
log.Infof("[SourceCode] Checkout to commit %v", commit.Id())
// Prepare submodules
if submodule {
repo.Submodules.Foreach(func(sub *git.Submodule, name string) int {
sub.Init(true)
err := sub.Update(true, &git.SubmoduleUpdateOptions{
CheckoutOpts: &git.CheckoutOpts{
Strategy: git.CheckoutForce | git.CheckoutUpdateSubmodules,
},
FetchOptions: &git.FetchOptions{},
})
if err != nil {
log.Errorln(err)
}
return 0
})
}
return nil
} | [
"func",
"(",
"g",
"*",
"GitScm",
")",
"SourceCode",
"(",
"repository",
",",
"path",
",",
"revision",
"string",
",",
"submodule",
"bool",
")",
"error",
"{",
"if",
"err",
":=",
"gitcheck",
"(",
"repository",
",",
"g",
".",
"Config",
".",
"PublicKey",
",",
"g",
".",
"Config",
".",
"PrivateKey",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"var",
"repo",
"*",
"git",
".",
"Repository",
"\n",
"var",
"err",
"error",
"\n",
"if",
"strings",
".",
"Contains",
"(",
"repository",
",",
"\"",
"\"",
")",
"{",
"repo",
",",
"err",
"=",
"git",
".",
"Clone",
"(",
"repository",
",",
"path",
",",
"&",
"git",
".",
"CloneOptions",
"{",
"}",
")",
"\n",
"}",
"else",
"{",
"credentialsCallback",
":=",
"func",
"(",
"url",
",",
"username",
"string",
",",
"allowedTypes",
"git",
".",
"CredType",
")",
"(",
"git",
".",
"ErrorCode",
",",
"*",
"git",
".",
"Cred",
")",
"{",
"ret",
",",
"cred",
":=",
"git",
".",
"NewCredSshKey",
"(",
"username",
",",
"g",
".",
"Config",
".",
"PublicKey",
",",
"g",
".",
"Config",
".",
"PrivateKey",
",",
"\"",
"\"",
")",
"\n",
"return",
"git",
".",
"ErrorCode",
"(",
"ret",
")",
",",
"&",
"cred",
"\n",
"}",
"\n",
"cloneOpts",
":=",
"&",
"git",
".",
"CloneOptions",
"{",
"FetchOptions",
":",
"&",
"git",
".",
"FetchOptions",
"{",
"RemoteCallbacks",
":",
"git",
".",
"RemoteCallbacks",
"{",
"CredentialsCallback",
":",
"credentialsCallback",
",",
"CertificateCheckCallback",
":",
"certificateCheckCallback",
",",
"}",
",",
"}",
",",
"}",
"\n",
"repo",
",",
"err",
"=",
"git",
".",
"Clone",
"(",
"repository",
",",
"path",
",",
"cloneOpts",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"repo",
".",
"Free",
"(",
")",
"\n\n",
"if",
"err",
":=",
"repo",
".",
"CheckoutHead",
"(",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"object",
",",
"err",
":=",
"repo",
".",
"RevparseSingle",
"(",
"revision",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"object",
".",
"Free",
"(",
")",
"\n\n",
"object",
",",
"err",
"=",
"object",
".",
"Peel",
"(",
"git",
".",
"ObjectCommit",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"commit",
",",
"err",
":=",
"object",
".",
"AsCommit",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"commit",
".",
"Free",
"(",
")",
"\n\n",
"tree",
",",
"err",
":=",
"commit",
".",
"Tree",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"tree",
".",
"Free",
"(",
")",
"\n\n",
"if",
"err",
":=",
"repo",
".",
"CheckoutTree",
"(",
"tree",
",",
"&",
"git",
".",
"CheckoutOpts",
"{",
"Strategy",
":",
"git",
".",
"CheckoutSafe",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"repository",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"commit",
".",
"Id",
"(",
")",
")",
"\n\n",
"// Prepare submodules",
"if",
"submodule",
"{",
"repo",
".",
"Submodules",
".",
"Foreach",
"(",
"func",
"(",
"sub",
"*",
"git",
".",
"Submodule",
",",
"name",
"string",
")",
"int",
"{",
"sub",
".",
"Init",
"(",
"true",
")",
"\n",
"err",
":=",
"sub",
".",
"Update",
"(",
"true",
",",
"&",
"git",
".",
"SubmoduleUpdateOptions",
"{",
"CheckoutOpts",
":",
"&",
"git",
".",
"CheckoutOpts",
"{",
"Strategy",
":",
"git",
".",
"CheckoutForce",
"|",
"git",
".",
"CheckoutUpdateSubmodules",
",",
"}",
",",
"FetchOptions",
":",
"&",
"git",
".",
"FetchOptions",
"{",
"}",
",",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorln",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"0",
"\n",
"}",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // SourceCode clone code from repository into path, by revision | [
"SourceCode",
"clone",
"code",
"from",
"repository",
"into",
"path",
"by",
"revision"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/source/common/common.go#L27-L106 |
16,255 | projecteru2/core | source/common/common.go | Artifact | func (g *GitScm) Artifact(artifact, path string) error {
req, err := http.NewRequest(http.MethodGet, artifact, nil)
if err != nil {
return err
}
for k, v := range g.AuthHeaders {
req.Header.Add(k, v)
}
log.Infof("[Artifact] Downloading artifacts from %q", artifact)
resp, err := g.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("Download artifact error %q, code %d", artifact, resp.StatusCode)
}
// extract files from zipfile
return unzipFile(resp.Body, path)
} | go | func (g *GitScm) Artifact(artifact, path string) error {
req, err := http.NewRequest(http.MethodGet, artifact, nil)
if err != nil {
return err
}
for k, v := range g.AuthHeaders {
req.Header.Add(k, v)
}
log.Infof("[Artifact] Downloading artifacts from %q", artifact)
resp, err := g.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return fmt.Errorf("Download artifact error %q, code %d", artifact, resp.StatusCode)
}
// extract files from zipfile
return unzipFile(resp.Body, path)
} | [
"func",
"(",
"g",
"*",
"GitScm",
")",
"Artifact",
"(",
"artifact",
",",
"path",
"string",
")",
"error",
"{",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"http",
".",
"MethodGet",
",",
"artifact",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"for",
"k",
",",
"v",
":=",
"range",
"g",
".",
"AuthHeaders",
"{",
"req",
".",
"Header",
".",
"Add",
"(",
"k",
",",
"v",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"artifact",
")",
"\n",
"resp",
",",
"err",
":=",
"g",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"200",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"artifact",
",",
"resp",
".",
"StatusCode",
")",
"\n",
"}",
"\n\n",
"// extract files from zipfile",
"return",
"unzipFile",
"(",
"resp",
".",
"Body",
",",
"path",
")",
"\n",
"}"
] | // Artifact download the artifact to the path, then unzip it | [
"Artifact",
"download",
"the",
"artifact",
"to",
"the",
"path",
"then",
"unzip",
"it"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/source/common/common.go#L109-L131 |
16,256 | projecteru2/core | cluster/calcium/create.go | CreateContainer | func (c *Calcium) CreateContainer(ctx context.Context, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) {
opts.ProcessIdent = utils.RandomString(16)
pod, err := c.store.GetPod(ctx, opts.Podname)
if err != nil {
log.Errorf("[CreateContainer %s] Error during GetPod for %s: %v", opts.ProcessIdent, opts.Podname, err)
return nil, err
}
log.Infof("[CreateContainer %s] Creating container with options:", opts.ProcessIdent)
litter.Dump(opts)
// 4194304 Byte = 4 MB, 创建容器的内存最低标准
if opts.Memory < minMemory {
return nil, types.NewDetailedErr(types.ErrBadMemory,
fmt.Sprintf("Minimum memory limit allowed is 4MB, got %d", opts.Memory))
}
// Count 要大于0
if opts.Count <= 0 {
return nil, types.NewDetailedErr(types.ErrBadCount, opts.Count)
}
// CPUQuota 也需要大于 0
if opts.CPUQuota <= 0 {
return nil, types.NewDetailedErr(types.ErrBadCPU, opts.CPUQuota)
}
return c.doCreateContainer(ctx, opts, pod)
} | go | func (c *Calcium) CreateContainer(ctx context.Context, opts *types.DeployOptions) (chan *types.CreateContainerMessage, error) {
opts.ProcessIdent = utils.RandomString(16)
pod, err := c.store.GetPod(ctx, opts.Podname)
if err != nil {
log.Errorf("[CreateContainer %s] Error during GetPod for %s: %v", opts.ProcessIdent, opts.Podname, err)
return nil, err
}
log.Infof("[CreateContainer %s] Creating container with options:", opts.ProcessIdent)
litter.Dump(opts)
// 4194304 Byte = 4 MB, 创建容器的内存最低标准
if opts.Memory < minMemory {
return nil, types.NewDetailedErr(types.ErrBadMemory,
fmt.Sprintf("Minimum memory limit allowed is 4MB, got %d", opts.Memory))
}
// Count 要大于0
if opts.Count <= 0 {
return nil, types.NewDetailedErr(types.ErrBadCount, opts.Count)
}
// CPUQuota 也需要大于 0
if opts.CPUQuota <= 0 {
return nil, types.NewDetailedErr(types.ErrBadCPU, opts.CPUQuota)
}
return c.doCreateContainer(ctx, opts, pod)
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"CreateContainer",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"types",
".",
"DeployOptions",
")",
"(",
"chan",
"*",
"types",
".",
"CreateContainerMessage",
",",
"error",
")",
"{",
"opts",
".",
"ProcessIdent",
"=",
"utils",
".",
"RandomString",
"(",
"16",
")",
"\n",
"pod",
",",
"err",
":=",
"c",
".",
"store",
".",
"GetPod",
"(",
"ctx",
",",
"opts",
".",
"Podname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"opts",
".",
"ProcessIdent",
",",
"opts",
".",
"Podname",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"opts",
".",
"ProcessIdent",
")",
"\n",
"litter",
".",
"Dump",
"(",
"opts",
")",
"\n\n",
"// 4194304 Byte = 4 MB, 创建容器的内存最低标准",
"if",
"opts",
".",
"Memory",
"<",
"minMemory",
"{",
"return",
"nil",
",",
"types",
".",
"NewDetailedErr",
"(",
"types",
".",
"ErrBadMemory",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"opts",
".",
"Memory",
")",
")",
"\n",
"}",
"\n",
"// Count 要大于0",
"if",
"opts",
".",
"Count",
"<=",
"0",
"{",
"return",
"nil",
",",
"types",
".",
"NewDetailedErr",
"(",
"types",
".",
"ErrBadCount",
",",
"opts",
".",
"Count",
")",
"\n",
"}",
"\n",
"// CPUQuota 也需要大于 0",
"if",
"opts",
".",
"CPUQuota",
"<=",
"0",
"{",
"return",
"nil",
",",
"types",
".",
"NewDetailedErr",
"(",
"types",
".",
"ErrBadCPU",
",",
"opts",
".",
"CPUQuota",
")",
"\n",
"}",
"\n\n",
"return",
"c",
".",
"doCreateContainer",
"(",
"ctx",
",",
"opts",
",",
"pod",
")",
"\n",
"}"
] | // CreateContainer use options to create containers | [
"CreateContainer",
"use",
"options",
"to",
"create",
"containers"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/create.go#L21-L46 |
16,257 | projecteru2/core | store/etcdv3/mercury.go | New | func New(config types.Config, embededStorage bool) (*Mercury, error) {
var cliv3 *clientv3.Client
var err error
if embededStorage {
cliv3 = embeded.NewCluster()
log.Info("[Mercury] use embeded cluster")
} else if cliv3, err = clientv3.New(clientv3.Config{Endpoints: config.Etcd.Machines}); err != nil {
return nil, err
}
return &Mercury{cliv3: cliv3, config: config}, nil
} | go | func New(config types.Config, embededStorage bool) (*Mercury, error) {
var cliv3 *clientv3.Client
var err error
if embededStorage {
cliv3 = embeded.NewCluster()
log.Info("[Mercury] use embeded cluster")
} else if cliv3, err = clientv3.New(clientv3.Config{Endpoints: config.Etcd.Machines}); err != nil {
return nil, err
}
return &Mercury{cliv3: cliv3, config: config}, nil
} | [
"func",
"New",
"(",
"config",
"types",
".",
"Config",
",",
"embededStorage",
"bool",
")",
"(",
"*",
"Mercury",
",",
"error",
")",
"{",
"var",
"cliv3",
"*",
"clientv3",
".",
"Client",
"\n",
"var",
"err",
"error",
"\n",
"if",
"embededStorage",
"{",
"cliv3",
"=",
"embeded",
".",
"NewCluster",
"(",
")",
"\n",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"}",
"else",
"if",
"cliv3",
",",
"err",
"=",
"clientv3",
".",
"New",
"(",
"clientv3",
".",
"Config",
"{",
"Endpoints",
":",
"config",
".",
"Etcd",
".",
"Machines",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Mercury",
"{",
"cliv3",
":",
"cliv3",
",",
"config",
":",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // New for create a Mercury instance | [
"New",
"for",
"create",
"a",
"Mercury",
"instance"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L48-L58 |
16,258 | projecteru2/core | store/etcdv3/mercury.go | CreateLock | func (m *Mercury) CreateLock(key string, ttl int) (lock.DistributedLock, error) {
lockKey := fmt.Sprintf("%s/%s", m.config.Etcd.LockPrefix, key)
mutex, err := etcdlock.New(m.cliv3, lockKey, ttl)
return mutex, err
} | go | func (m *Mercury) CreateLock(key string, ttl int) (lock.DistributedLock, error) {
lockKey := fmt.Sprintf("%s/%s", m.config.Etcd.LockPrefix, key)
mutex, err := etcdlock.New(m.cliv3, lockKey, ttl)
return mutex, err
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"CreateLock",
"(",
"key",
"string",
",",
"ttl",
"int",
")",
"(",
"lock",
".",
"DistributedLock",
",",
"error",
")",
"{",
"lockKey",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"m",
".",
"config",
".",
"Etcd",
".",
"LockPrefix",
",",
"key",
")",
"\n",
"mutex",
",",
"err",
":=",
"etcdlock",
".",
"New",
"(",
"m",
".",
"cliv3",
",",
"lockKey",
",",
"ttl",
")",
"\n",
"return",
"mutex",
",",
"err",
"\n",
"}"
] | // CreateLock create a lock instance | [
"CreateLock",
"create",
"a",
"lock",
"instance"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L66-L70 |
16,259 | projecteru2/core | store/etcdv3/mercury.go | Get | func (m *Mercury) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) {
return m.cliv3.Get(ctx, m.parseKey(key), opts...)
} | go | func (m *Mercury) Get(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.GetResponse, error) {
return m.cliv3.Get(ctx, m.parseKey(key), opts...)
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"Get",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"(",
"*",
"clientv3",
".",
"GetResponse",
",",
"error",
")",
"{",
"return",
"m",
".",
"cliv3",
".",
"Get",
"(",
"ctx",
",",
"m",
".",
"parseKey",
"(",
"key",
")",
",",
"opts",
"...",
")",
"\n",
"}"
] | // Get get results or noting | [
"Get",
"get",
"results",
"or",
"noting"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L73-L75 |
16,260 | projecteru2/core | store/etcdv3/mercury.go | GetOne | func (m *Mercury) GetOne(ctx context.Context, key string, opts ...clientv3.OpOption) (*mvccpb.KeyValue, error) {
resp, err := m.Get(ctx, key, opts...)
if err != nil {
return nil, err
}
if resp.Count != 1 {
return nil, types.NewDetailedErr(types.ErrBadCount, fmt.Sprintf("key: %s", key))
}
return resp.Kvs[0], nil
} | go | func (m *Mercury) GetOne(ctx context.Context, key string, opts ...clientv3.OpOption) (*mvccpb.KeyValue, error) {
resp, err := m.Get(ctx, key, opts...)
if err != nil {
return nil, err
}
if resp.Count != 1 {
return nil, types.NewDetailedErr(types.ErrBadCount, fmt.Sprintf("key: %s", key))
}
return resp.Kvs[0], nil
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"GetOne",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"(",
"*",
"mvccpb",
".",
"KeyValue",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"m",
".",
"Get",
"(",
"ctx",
",",
"key",
",",
"opts",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"Count",
"!=",
"1",
"{",
"return",
"nil",
",",
"types",
".",
"NewDetailedErr",
"(",
"types",
".",
"ErrBadCount",
",",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"key",
")",
")",
"\n",
"}",
"\n\n",
"return",
"resp",
".",
"Kvs",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // GetOne get one result or noting | [
"GetOne",
"get",
"one",
"result",
"or",
"noting"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L78-L89 |
16,261 | projecteru2/core | store/etcdv3/mercury.go | Delete | func (m *Mercury) Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error) {
return m.cliv3.Delete(ctx, m.parseKey(key), opts...)
} | go | func (m *Mercury) Delete(ctx context.Context, key string, opts ...clientv3.OpOption) (*clientv3.DeleteResponse, error) {
return m.cliv3.Delete(ctx, m.parseKey(key), opts...)
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"Delete",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"(",
"*",
"clientv3",
".",
"DeleteResponse",
",",
"error",
")",
"{",
"return",
"m",
".",
"cliv3",
".",
"Delete",
"(",
"ctx",
",",
"m",
".",
"parseKey",
"(",
"key",
")",
",",
"opts",
"...",
")",
"\n",
"}"
] | // Delete delete key | [
"Delete",
"delete",
"key"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L92-L94 |
16,262 | projecteru2/core | store/etcdv3/mercury.go | BatchDelete | func (m *Mercury) BatchDelete(ctx context.Context, keys []string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
txn := m.cliv3.Txn(ctx)
ops := []clientv3.Op{}
for _, key := range keys {
op := clientv3.OpDelete(m.parseKey(key), opts...)
ops = append(ops, op)
}
return txn.Then(ops...).Commit()
} | go | func (m *Mercury) BatchDelete(ctx context.Context, keys []string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
txn := m.cliv3.Txn(ctx)
ops := []clientv3.Op{}
for _, key := range keys {
op := clientv3.OpDelete(m.parseKey(key), opts...)
ops = append(ops, op)
}
return txn.Then(ops...).Commit()
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"BatchDelete",
"(",
"ctx",
"context",
".",
"Context",
",",
"keys",
"[",
"]",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"(",
"*",
"clientv3",
".",
"TxnResponse",
",",
"error",
")",
"{",
"txn",
":=",
"m",
".",
"cliv3",
".",
"Txn",
"(",
"ctx",
")",
"\n",
"ops",
":=",
"[",
"]",
"clientv3",
".",
"Op",
"{",
"}",
"\n",
"for",
"_",
",",
"key",
":=",
"range",
"keys",
"{",
"op",
":=",
"clientv3",
".",
"OpDelete",
"(",
"m",
".",
"parseKey",
"(",
"key",
")",
",",
"opts",
"...",
")",
"\n",
"ops",
"=",
"append",
"(",
"ops",
",",
"op",
")",
"\n",
"}",
"\n",
"return",
"txn",
".",
"Then",
"(",
"ops",
"...",
")",
".",
"Commit",
"(",
")",
"\n",
"}"
] | // BatchDelete batch delete keys | [
"BatchDelete",
"batch",
"delete",
"keys"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L97-L105 |
16,263 | projecteru2/core | store/etcdv3/mercury.go | Put | func (m *Mercury) Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) {
return m.cliv3.Put(ctx, m.parseKey(key), val, opts...)
} | go | func (m *Mercury) Put(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.PutResponse, error) {
return m.cliv3.Put(ctx, m.parseKey(key), val, opts...)
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"Put",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
",",
"val",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"(",
"*",
"clientv3",
".",
"PutResponse",
",",
"error",
")",
"{",
"return",
"m",
".",
"cliv3",
".",
"Put",
"(",
"ctx",
",",
"m",
".",
"parseKey",
"(",
"key",
")",
",",
"val",
",",
"opts",
"...",
")",
"\n",
"}"
] | // Put save a key value | [
"Put",
"save",
"a",
"key",
"value"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L108-L110 |
16,264 | projecteru2/core | store/etcdv3/mercury.go | Create | func (m *Mercury) Create(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
return m.BatchCreate(ctx, map[string]string{key: val}, opts...)
} | go | func (m *Mercury) Create(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
return m.BatchCreate(ctx, map[string]string{key: val}, opts...)
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"Create",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
",",
"val",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"(",
"*",
"clientv3",
".",
"TxnResponse",
",",
"error",
")",
"{",
"return",
"m",
".",
"BatchCreate",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"string",
"{",
"key",
":",
"val",
"}",
",",
"opts",
"...",
")",
"\n",
"}"
] | // Create create a key if not exists | [
"Create",
"create",
"a",
"key",
"if",
"not",
"exists"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L131-L133 |
16,265 | projecteru2/core | store/etcdv3/mercury.go | BatchCreate | func (m *Mercury) BatchCreate(ctx context.Context, data map[string]string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
limit := map[string]map[int]string{}
for key := range data {
limit[key] = map[int]string{0: "="}
}
resp, err := m.batchPut(ctx, data, limit, opts...)
if err != nil {
return resp, err
}
if !resp.Succeeded {
return resp, types.ErrKeyExists
}
return resp, nil
} | go | func (m *Mercury) BatchCreate(ctx context.Context, data map[string]string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
limit := map[string]map[int]string{}
for key := range data {
limit[key] = map[int]string{0: "="}
}
resp, err := m.batchPut(ctx, data, limit, opts...)
if err != nil {
return resp, err
}
if !resp.Succeeded {
return resp, types.ErrKeyExists
}
return resp, nil
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"BatchCreate",
"(",
"ctx",
"context",
".",
"Context",
",",
"data",
"map",
"[",
"string",
"]",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"(",
"*",
"clientv3",
".",
"TxnResponse",
",",
"error",
")",
"{",
"limit",
":=",
"map",
"[",
"string",
"]",
"map",
"[",
"int",
"]",
"string",
"{",
"}",
"\n",
"for",
"key",
":=",
"range",
"data",
"{",
"limit",
"[",
"key",
"]",
"=",
"map",
"[",
"int",
"]",
"string",
"{",
"0",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"resp",
",",
"err",
":=",
"m",
".",
"batchPut",
"(",
"ctx",
",",
"data",
",",
"limit",
",",
"opts",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n",
"if",
"!",
"resp",
".",
"Succeeded",
"{",
"return",
"resp",
",",
"types",
".",
"ErrKeyExists",
"\n",
"}",
"\n",
"return",
"resp",
",",
"nil",
"\n",
"}"
] | // BatchCreate create key values if not exists | [
"BatchCreate",
"create",
"key",
"values",
"if",
"not",
"exists"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L136-L149 |
16,266 | projecteru2/core | store/etcdv3/mercury.go | Update | func (m *Mercury) Update(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
return m.BatchUpdate(ctx, map[string]string{key: val}, opts...)
} | go | func (m *Mercury) Update(ctx context.Context, key, val string, opts ...clientv3.OpOption) (*clientv3.TxnResponse, error) {
return m.BatchUpdate(ctx, map[string]string{key: val}, opts...)
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"Update",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
",",
"val",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"(",
"*",
"clientv3",
".",
"TxnResponse",
",",
"error",
")",
"{",
"return",
"m",
".",
"BatchUpdate",
"(",
"ctx",
",",
"map",
"[",
"string",
"]",
"string",
"{",
"key",
":",
"val",
"}",
",",
"opts",
"...",
")",
"\n",
"}"
] | // Update update a key if exists | [
"Update",
"update",
"a",
"key",
"if",
"exists"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L152-L154 |
16,267 | projecteru2/core | store/etcdv3/mercury.go | Watch | func (m *Mercury) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan {
key = m.parseKey(key)
return m.cliv3.Watch(ctx, key, opts...)
} | go | func (m *Mercury) Watch(ctx context.Context, key string, opts ...clientv3.OpOption) clientv3.WatchChan {
key = m.parseKey(key)
return m.cliv3.Watch(ctx, key, opts...)
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"Watch",
"(",
"ctx",
"context",
".",
"Context",
",",
"key",
"string",
",",
"opts",
"...",
"clientv3",
".",
"OpOption",
")",
"clientv3",
".",
"WatchChan",
"{",
"key",
"=",
"m",
".",
"parseKey",
"(",
"key",
")",
"\n",
"return",
"m",
".",
"cliv3",
".",
"Watch",
"(",
"ctx",
",",
"key",
",",
"opts",
"...",
")",
"\n",
"}"
] | // Watch wath a key | [
"Watch",
"wath",
"a",
"key"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/mercury.go#L173-L176 |
16,268 | projecteru2/core | cluster/calcium/remove.go | RemoveContainer | func (c *Calcium) RemoveContainer(ctx context.Context, IDs []string, force bool) (chan *types.RemoveContainerMessage, error) {
ch := make(chan *types.RemoveContainerMessage)
go func() {
defer close(ch)
wg := sync.WaitGroup{}
for _, ID := range IDs {
container, containerJSON, containerLock, err := c.doLockAndGetContainer(ctx, ID)
if err != nil {
ch <- &types.RemoveContainerMessage{
ContainerID: ID,
Success: false,
Hook: []*bytes.Buffer{bytes.NewBufferString(err.Error())},
}
continue
}
wg.Add(1)
go func(container *types.Container, containerJSON *enginetypes.VirtualizationInfo, containerLock lock.DistributedLock) {
defer wg.Done()
// force to unlock
defer c.doUnlock(containerLock, container.ID)
output := []*bytes.Buffer{}
success := false
defer func() {
ch <- &types.RemoveContainerMessage{
ContainerID: container.ID,
Success: success,
Hook: output,
}
}()
node, nodeLock, err := c.doLockAndGetNode(ctx, container.Podname, container.Nodename)
if err != nil {
return
}
defer c.doUnlock(nodeLock, node.Name)
output, err = c.doStopAndRemoveContainer(ctx, container, containerJSON, force)
if err != nil {
return
}
log.Infof("[RemoveContainer] Container %s removed", container.ID)
if err = c.store.UpdateNodeResource(ctx, node, container.CPU, container.Quota, container.Memory, store.ActionIncr); err != nil {
log.Errorf("[RemoveContainer] Container %s removed, but update Node resource failed %v", container.ID, err)
return
}
success = true
}(container, containerJSON, containerLock)
}
wg.Wait()
}()
return ch, nil
} | go | func (c *Calcium) RemoveContainer(ctx context.Context, IDs []string, force bool) (chan *types.RemoveContainerMessage, error) {
ch := make(chan *types.RemoveContainerMessage)
go func() {
defer close(ch)
wg := sync.WaitGroup{}
for _, ID := range IDs {
container, containerJSON, containerLock, err := c.doLockAndGetContainer(ctx, ID)
if err != nil {
ch <- &types.RemoveContainerMessage{
ContainerID: ID,
Success: false,
Hook: []*bytes.Buffer{bytes.NewBufferString(err.Error())},
}
continue
}
wg.Add(1)
go func(container *types.Container, containerJSON *enginetypes.VirtualizationInfo, containerLock lock.DistributedLock) {
defer wg.Done()
// force to unlock
defer c.doUnlock(containerLock, container.ID)
output := []*bytes.Buffer{}
success := false
defer func() {
ch <- &types.RemoveContainerMessage{
ContainerID: container.ID,
Success: success,
Hook: output,
}
}()
node, nodeLock, err := c.doLockAndGetNode(ctx, container.Podname, container.Nodename)
if err != nil {
return
}
defer c.doUnlock(nodeLock, node.Name)
output, err = c.doStopAndRemoveContainer(ctx, container, containerJSON, force)
if err != nil {
return
}
log.Infof("[RemoveContainer] Container %s removed", container.ID)
if err = c.store.UpdateNodeResource(ctx, node, container.CPU, container.Quota, container.Memory, store.ActionIncr); err != nil {
log.Errorf("[RemoveContainer] Container %s removed, but update Node resource failed %v", container.ID, err)
return
}
success = true
}(container, containerJSON, containerLock)
}
wg.Wait()
}()
return ch, nil
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"RemoveContainer",
"(",
"ctx",
"context",
".",
"Context",
",",
"IDs",
"[",
"]",
"string",
",",
"force",
"bool",
")",
"(",
"chan",
"*",
"types",
".",
"RemoveContainerMessage",
",",
"error",
")",
"{",
"ch",
":=",
"make",
"(",
"chan",
"*",
"types",
".",
"RemoveContainerMessage",
")",
"\n",
"go",
"func",
"(",
")",
"{",
"defer",
"close",
"(",
"ch",
")",
"\n",
"wg",
":=",
"sync",
".",
"WaitGroup",
"{",
"}",
"\n",
"for",
"_",
",",
"ID",
":=",
"range",
"IDs",
"{",
"container",
",",
"containerJSON",
",",
"containerLock",
",",
"err",
":=",
"c",
".",
"doLockAndGetContainer",
"(",
"ctx",
",",
"ID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"ch",
"<-",
"&",
"types",
".",
"RemoveContainerMessage",
"{",
"ContainerID",
":",
"ID",
",",
"Success",
":",
"false",
",",
"Hook",
":",
"[",
"]",
"*",
"bytes",
".",
"Buffer",
"{",
"bytes",
".",
"NewBufferString",
"(",
"err",
".",
"Error",
"(",
")",
")",
"}",
",",
"}",
"\n",
"continue",
"\n",
"}",
"\n",
"wg",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"func",
"(",
"container",
"*",
"types",
".",
"Container",
",",
"containerJSON",
"*",
"enginetypes",
".",
"VirtualizationInfo",
",",
"containerLock",
"lock",
".",
"DistributedLock",
")",
"{",
"defer",
"wg",
".",
"Done",
"(",
")",
"\n",
"// force to unlock",
"defer",
"c",
".",
"doUnlock",
"(",
"containerLock",
",",
"container",
".",
"ID",
")",
"\n",
"output",
":=",
"[",
"]",
"*",
"bytes",
".",
"Buffer",
"{",
"}",
"\n",
"success",
":=",
"false",
"\n\n",
"defer",
"func",
"(",
")",
"{",
"ch",
"<-",
"&",
"types",
".",
"RemoveContainerMessage",
"{",
"ContainerID",
":",
"container",
".",
"ID",
",",
"Success",
":",
"success",
",",
"Hook",
":",
"output",
",",
"}",
"\n",
"}",
"(",
")",
"\n\n",
"node",
",",
"nodeLock",
",",
"err",
":=",
"c",
".",
"doLockAndGetNode",
"(",
"ctx",
",",
"container",
".",
"Podname",
",",
"container",
".",
"Nodename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"c",
".",
"doUnlock",
"(",
"nodeLock",
",",
"node",
".",
"Name",
")",
"\n\n",
"output",
",",
"err",
"=",
"c",
".",
"doStopAndRemoveContainer",
"(",
"ctx",
",",
"container",
",",
"containerJSON",
",",
"force",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"container",
".",
"ID",
")",
"\n",
"if",
"err",
"=",
"c",
".",
"store",
".",
"UpdateNodeResource",
"(",
"ctx",
",",
"node",
",",
"container",
".",
"CPU",
",",
"container",
".",
"Quota",
",",
"container",
".",
"Memory",
",",
"store",
".",
"ActionIncr",
")",
";",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"container",
".",
"ID",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"success",
"=",
"true",
"\n",
"}",
"(",
"container",
",",
"containerJSON",
",",
"containerLock",
")",
"\n",
"}",
"\n",
"wg",
".",
"Wait",
"(",
")",
"\n",
"}",
"(",
")",
"\n",
"return",
"ch",
",",
"nil",
"\n",
"}"
] | // RemoveContainer remove containers
// returns a channel that contains removing responses | [
"RemoveContainer",
"remove",
"containers",
"returns",
"a",
"channel",
"that",
"contains",
"removing",
"responses"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/remove.go#L18-L72 |
16,269 | projecteru2/core | auth/simple/simple.go | StreamInterceptor | func (b *BasicAuth) StreamInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
ctx := stream.Context()
if err := b.doAuth(ctx); err != nil {
return err
}
return handler(srv, stream)
} | go | func (b *BasicAuth) StreamInterceptor(srv interface{}, stream grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
ctx := stream.Context()
if err := b.doAuth(ctx); err != nil {
return err
}
return handler(srv, stream)
} | [
"func",
"(",
"b",
"*",
"BasicAuth",
")",
"StreamInterceptor",
"(",
"srv",
"interface",
"{",
"}",
",",
"stream",
"grpc",
".",
"ServerStream",
",",
"info",
"*",
"grpc",
".",
"StreamServerInfo",
",",
"handler",
"grpc",
".",
"StreamHandler",
")",
"error",
"{",
"ctx",
":=",
"stream",
".",
"Context",
"(",
")",
"\n",
"if",
"err",
":=",
"b",
".",
"doAuth",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"handler",
"(",
"srv",
",",
"stream",
")",
"\n",
"}"
] | // StreamInterceptor define stream interceptor | [
"StreamInterceptor",
"define",
"stream",
"interceptor"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/auth/simple/simple.go#L23-L29 |
16,270 | projecteru2/core | auth/simple/simple.go | UnaryInterceptor | func (b *BasicAuth) UnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
if err := b.doAuth(ctx); err != nil {
return nil, err
}
return handler(ctx, req)
} | go | func (b *BasicAuth) UnaryInterceptor(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
if err := b.doAuth(ctx); err != nil {
return nil, err
}
return handler(ctx, req)
} | [
"func",
"(",
"b",
"*",
"BasicAuth",
")",
"UnaryInterceptor",
"(",
"ctx",
"context",
".",
"Context",
",",
"req",
"interface",
"{",
"}",
",",
"info",
"*",
"grpc",
".",
"UnaryServerInfo",
",",
"handler",
"grpc",
".",
"UnaryHandler",
")",
"(",
"interface",
"{",
"}",
",",
"error",
")",
"{",
"if",
"err",
":=",
"b",
".",
"doAuth",
"(",
"ctx",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"handler",
"(",
"ctx",
",",
"req",
")",
"\n",
"}"
] | // UnaryInterceptor define unary interceptor | [
"UnaryInterceptor",
"define",
"unary",
"interceptor"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/auth/simple/simple.go#L32-L37 |
16,271 | projecteru2/core | types/errors.go | NewDetailedErr | func NewDetailedErr(err error, details interface{}) error {
return &detailedErr{
details: fmt.Sprintf("%v", details),
err: err,
}
} | go | func NewDetailedErr(err error, details interface{}) error {
return &detailedErr{
details: fmt.Sprintf("%v", details),
err: err,
}
} | [
"func",
"NewDetailedErr",
"(",
"err",
"error",
",",
"details",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"&",
"detailedErr",
"{",
"details",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"details",
")",
",",
"err",
":",
"err",
",",
"}",
"\n",
"}"
] | // NewDetailedErr returns an error with details | [
"NewDetailedErr",
"returns",
"an",
"error",
"with",
"details"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/types/errors.go#L69-L74 |
16,272 | projecteru2/core | types/errors.go | IsDetailedErr | func IsDetailedErr(err error) error {
if e, ok := err.(*detailedErr); ok {
return e.err
}
return err
} | go | func IsDetailedErr(err error) error {
if e, ok := err.(*detailedErr); ok {
return e.err
}
return err
} | [
"func",
"IsDetailedErr",
"(",
"err",
"error",
")",
"error",
"{",
"if",
"e",
",",
"ok",
":=",
"err",
".",
"(",
"*",
"detailedErr",
")",
";",
"ok",
"{",
"return",
"e",
".",
"err",
"\n",
"}",
"\n",
"return",
"err",
"\n",
"}"
] | // IsDetailedErr returns the error's type if the error
// is a detailedErr, otherwise return it back | [
"IsDetailedErr",
"returns",
"the",
"error",
"s",
"type",
"if",
"the",
"error",
"is",
"a",
"detailedErr",
"otherwise",
"return",
"it",
"back"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/types/errors.go#L78-L83 |
16,273 | projecteru2/core | engine/docker/container.go | VirtualizationCopyTo | func (e *Engine) VirtualizationCopyTo(ctx context.Context, ID, path string, content io.Reader, AllowOverwriteDirWithFile, CopyUIDGID bool) error {
return e.client.CopyToContainer(ctx, ID, path, content, dockertypes.CopyToContainerOptions{AllowOverwriteDirWithFile: AllowOverwriteDirWithFile, CopyUIDGID: CopyUIDGID})
} | go | func (e *Engine) VirtualizationCopyTo(ctx context.Context, ID, path string, content io.Reader, AllowOverwriteDirWithFile, CopyUIDGID bool) error {
return e.client.CopyToContainer(ctx, ID, path, content, dockertypes.CopyToContainerOptions{AllowOverwriteDirWithFile: AllowOverwriteDirWithFile, CopyUIDGID: CopyUIDGID})
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationCopyTo",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
",",
"path",
"string",
",",
"content",
"io",
".",
"Reader",
",",
"AllowOverwriteDirWithFile",
",",
"CopyUIDGID",
"bool",
")",
"error",
"{",
"return",
"e",
".",
"client",
".",
"CopyToContainer",
"(",
"ctx",
",",
"ID",
",",
"path",
",",
"content",
",",
"dockertypes",
".",
"CopyToContainerOptions",
"{",
"AllowOverwriteDirWithFile",
":",
"AllowOverwriteDirWithFile",
",",
"CopyUIDGID",
":",
"CopyUIDGID",
"}",
")",
"\n",
"}"
] | // VirtualizationCopyTo copy things to virtualization | [
"VirtualizationCopyTo",
"copy",
"things",
"to",
"virtualization"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L119-L121 |
16,274 | projecteru2/core | engine/docker/container.go | VirtualizationStart | func (e *Engine) VirtualizationStart(ctx context.Context, ID string) error {
return e.client.ContainerStart(ctx, ID, dockertypes.ContainerStartOptions{})
} | go | func (e *Engine) VirtualizationStart(ctx context.Context, ID string) error {
return e.client.ContainerStart(ctx, ID, dockertypes.ContainerStartOptions{})
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationStart",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"string",
")",
"error",
"{",
"return",
"e",
".",
"client",
".",
"ContainerStart",
"(",
"ctx",
",",
"ID",
",",
"dockertypes",
".",
"ContainerStartOptions",
"{",
"}",
")",
"\n",
"}"
] | // VirtualizationStart start virtualization | [
"VirtualizationStart",
"start",
"virtualization"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L124-L126 |
16,275 | projecteru2/core | engine/docker/container.go | VirtualizationStop | func (e *Engine) VirtualizationStop(ctx context.Context, ID string) error {
return e.client.ContainerStop(ctx, ID, nil)
} | go | func (e *Engine) VirtualizationStop(ctx context.Context, ID string) error {
return e.client.ContainerStop(ctx, ID, nil)
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationStop",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"string",
")",
"error",
"{",
"return",
"e",
".",
"client",
".",
"ContainerStop",
"(",
"ctx",
",",
"ID",
",",
"nil",
")",
"\n",
"}"
] | // VirtualizationStop stop virtualization | [
"VirtualizationStop",
"stop",
"virtualization"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L129-L131 |
16,276 | projecteru2/core | engine/docker/container.go | VirtualizationRemove | func (e *Engine) VirtualizationRemove(ctx context.Context, ID string, removeVolumes, force bool) error {
return e.client.ContainerRemove(ctx, ID, dockertypes.ContainerRemoveOptions{RemoveVolumes: removeVolumes, Force: force})
} | go | func (e *Engine) VirtualizationRemove(ctx context.Context, ID string, removeVolumes, force bool) error {
return e.client.ContainerRemove(ctx, ID, dockertypes.ContainerRemoveOptions{RemoveVolumes: removeVolumes, Force: force})
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationRemove",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"string",
",",
"removeVolumes",
",",
"force",
"bool",
")",
"error",
"{",
"return",
"e",
".",
"client",
".",
"ContainerRemove",
"(",
"ctx",
",",
"ID",
",",
"dockertypes",
".",
"ContainerRemoveOptions",
"{",
"RemoveVolumes",
":",
"removeVolumes",
",",
"Force",
":",
"force",
"}",
")",
"\n",
"}"
] | // VirtualizationRemove remove virtualization | [
"VirtualizationRemove",
"remove",
"virtualization"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L134-L136 |
16,277 | projecteru2/core | engine/docker/container.go | VirtualizationInspect | func (e *Engine) VirtualizationInspect(ctx context.Context, ID string) (*enginetypes.VirtualizationInfo, error) {
if e.client == nil {
return nil, coretypes.ErrNilEngine
}
containerJSON, err := e.client.ContainerInspect(ctx, ID)
r := &enginetypes.VirtualizationInfo{}
if err != nil {
return r, err
}
r.ID = containerJSON.ID
r.User = containerJSON.Config.User
r.Image = containerJSON.Config.Image
r.Env = containerJSON.Config.Env
r.Labels = containerJSON.Config.Labels
r.Running = containerJSON.State.Running
r.Networks = map[string]string{}
for networkName, networkSetting := range containerJSON.NetworkSettings.Networks {
ip := networkSetting.IPAddress
if dockercontainer.NetworkMode(networkName).IsHost() {
ip = GetIP(e.client.DaemonHost())
}
r.Networks[networkName] = ip
}
return r, nil
} | go | func (e *Engine) VirtualizationInspect(ctx context.Context, ID string) (*enginetypes.VirtualizationInfo, error) {
if e.client == nil {
return nil, coretypes.ErrNilEngine
}
containerJSON, err := e.client.ContainerInspect(ctx, ID)
r := &enginetypes.VirtualizationInfo{}
if err != nil {
return r, err
}
r.ID = containerJSON.ID
r.User = containerJSON.Config.User
r.Image = containerJSON.Config.Image
r.Env = containerJSON.Config.Env
r.Labels = containerJSON.Config.Labels
r.Running = containerJSON.State.Running
r.Networks = map[string]string{}
for networkName, networkSetting := range containerJSON.NetworkSettings.Networks {
ip := networkSetting.IPAddress
if dockercontainer.NetworkMode(networkName).IsHost() {
ip = GetIP(e.client.DaemonHost())
}
r.Networks[networkName] = ip
}
return r, nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationInspect",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"string",
")",
"(",
"*",
"enginetypes",
".",
"VirtualizationInfo",
",",
"error",
")",
"{",
"if",
"e",
".",
"client",
"==",
"nil",
"{",
"return",
"nil",
",",
"coretypes",
".",
"ErrNilEngine",
"\n",
"}",
"\n\n",
"containerJSON",
",",
"err",
":=",
"e",
".",
"client",
".",
"ContainerInspect",
"(",
"ctx",
",",
"ID",
")",
"\n",
"r",
":=",
"&",
"enginetypes",
".",
"VirtualizationInfo",
"{",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"r",
",",
"err",
"\n",
"}",
"\n",
"r",
".",
"ID",
"=",
"containerJSON",
".",
"ID",
"\n",
"r",
".",
"User",
"=",
"containerJSON",
".",
"Config",
".",
"User",
"\n",
"r",
".",
"Image",
"=",
"containerJSON",
".",
"Config",
".",
"Image",
"\n",
"r",
".",
"Env",
"=",
"containerJSON",
".",
"Config",
".",
"Env",
"\n",
"r",
".",
"Labels",
"=",
"containerJSON",
".",
"Config",
".",
"Labels",
"\n",
"r",
".",
"Running",
"=",
"containerJSON",
".",
"State",
".",
"Running",
"\n",
"r",
".",
"Networks",
"=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"for",
"networkName",
",",
"networkSetting",
":=",
"range",
"containerJSON",
".",
"NetworkSettings",
".",
"Networks",
"{",
"ip",
":=",
"networkSetting",
".",
"IPAddress",
"\n",
"if",
"dockercontainer",
".",
"NetworkMode",
"(",
"networkName",
")",
".",
"IsHost",
"(",
")",
"{",
"ip",
"=",
"GetIP",
"(",
"e",
".",
"client",
".",
"DaemonHost",
"(",
")",
")",
"\n",
"}",
"\n",
"r",
".",
"Networks",
"[",
"networkName",
"]",
"=",
"ip",
"\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] | // VirtualizationInspect get virtualization info | [
"VirtualizationInspect",
"get",
"virtualization",
"info"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L139-L164 |
16,278 | projecteru2/core | engine/docker/container.go | VirtualizationLogs | func (e *Engine) VirtualizationLogs(ctx context.Context, ID string, follow, stdout, stderr bool) (io.Reader, error) {
logsOpts := dockertypes.ContainerLogsOptions{Follow: follow, ShowStdout: stdout, ShowStderr: stderr}
resp, err := e.client.ContainerLogs(ctx, ID, logsOpts)
if err != nil {
return nil, err
}
return mergeStream(ioutil.NopCloser(resp)), nil
} | go | func (e *Engine) VirtualizationLogs(ctx context.Context, ID string, follow, stdout, stderr bool) (io.Reader, error) {
logsOpts := dockertypes.ContainerLogsOptions{Follow: follow, ShowStdout: stdout, ShowStderr: stderr}
resp, err := e.client.ContainerLogs(ctx, ID, logsOpts)
if err != nil {
return nil, err
}
return mergeStream(ioutil.NopCloser(resp)), nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationLogs",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"string",
",",
"follow",
",",
"stdout",
",",
"stderr",
"bool",
")",
"(",
"io",
".",
"Reader",
",",
"error",
")",
"{",
"logsOpts",
":=",
"dockertypes",
".",
"ContainerLogsOptions",
"{",
"Follow",
":",
"follow",
",",
"ShowStdout",
":",
"stdout",
",",
"ShowStderr",
":",
"stderr",
"}",
"\n",
"resp",
",",
"err",
":=",
"e",
".",
"client",
".",
"ContainerLogs",
"(",
"ctx",
",",
"ID",
",",
"logsOpts",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"mergeStream",
"(",
"ioutil",
".",
"NopCloser",
"(",
"resp",
")",
")",
",",
"nil",
"\n",
"}"
] | // VirtualizationLogs show virtualization logs | [
"VirtualizationLogs",
"show",
"virtualization",
"logs"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L167-L174 |
16,279 | projecteru2/core | engine/docker/container.go | VirtualizationAttach | func (e *Engine) VirtualizationAttach(ctx context.Context, ID string, stream, stdin bool) (io.ReadCloser, io.WriteCloser, error) {
resp, err := e.client.ContainerAttach(ctx, ID, dockertypes.ContainerAttachOptions{Stream: stream, Stdin: stdin})
if err != nil {
return nil, nil, err
}
return ioutil.NopCloser(resp.Reader), resp.Conn, nil
} | go | func (e *Engine) VirtualizationAttach(ctx context.Context, ID string, stream, stdin bool) (io.ReadCloser, io.WriteCloser, error) {
resp, err := e.client.ContainerAttach(ctx, ID, dockertypes.ContainerAttachOptions{Stream: stream, Stdin: stdin})
if err != nil {
return nil, nil, err
}
return ioutil.NopCloser(resp.Reader), resp.Conn, nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationAttach",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"string",
",",
"stream",
",",
"stdin",
"bool",
")",
"(",
"io",
".",
"ReadCloser",
",",
"io",
".",
"WriteCloser",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"e",
".",
"client",
".",
"ContainerAttach",
"(",
"ctx",
",",
"ID",
",",
"dockertypes",
".",
"ContainerAttachOptions",
"{",
"Stream",
":",
"stream",
",",
"Stdin",
":",
"stdin",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"NopCloser",
"(",
"resp",
".",
"Reader",
")",
",",
"resp",
".",
"Conn",
",",
"nil",
"\n",
"}"
] | // VirtualizationAttach attach to a virtualization | [
"VirtualizationAttach",
"attach",
"to",
"a",
"virtualization"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L177-L183 |
16,280 | projecteru2/core | engine/docker/container.go | VirtualizationWait | func (e *Engine) VirtualizationWait(ctx context.Context, ID, state string) (*enginetypes.VirtualizationWaitResult, error) {
waitBody, errorCh := e.client.ContainerWait(ctx, ID, dockercontainer.WaitConditionNotRunning)
r := &enginetypes.VirtualizationWaitResult{}
select {
case b := <-waitBody:
if b.Error != nil {
r.Message = b.Error.Message
}
r.Code = b.StatusCode
return r, nil
case err := <-errorCh:
r.Message = err.Error()
r.Code = -1
return r, err
}
} | go | func (e *Engine) VirtualizationWait(ctx context.Context, ID, state string) (*enginetypes.VirtualizationWaitResult, error) {
waitBody, errorCh := e.client.ContainerWait(ctx, ID, dockercontainer.WaitConditionNotRunning)
r := &enginetypes.VirtualizationWaitResult{}
select {
case b := <-waitBody:
if b.Error != nil {
r.Message = b.Error.Message
}
r.Code = b.StatusCode
return r, nil
case err := <-errorCh:
r.Message = err.Error()
r.Code = -1
return r, err
}
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationWait",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
",",
"state",
"string",
")",
"(",
"*",
"enginetypes",
".",
"VirtualizationWaitResult",
",",
"error",
")",
"{",
"waitBody",
",",
"errorCh",
":=",
"e",
".",
"client",
".",
"ContainerWait",
"(",
"ctx",
",",
"ID",
",",
"dockercontainer",
".",
"WaitConditionNotRunning",
")",
"\n",
"r",
":=",
"&",
"enginetypes",
".",
"VirtualizationWaitResult",
"{",
"}",
"\n",
"select",
"{",
"case",
"b",
":=",
"<-",
"waitBody",
":",
"if",
"b",
".",
"Error",
"!=",
"nil",
"{",
"r",
".",
"Message",
"=",
"b",
".",
"Error",
".",
"Message",
"\n",
"}",
"\n",
"r",
".",
"Code",
"=",
"b",
".",
"StatusCode",
"\n",
"return",
"r",
",",
"nil",
"\n",
"case",
"err",
":=",
"<-",
"errorCh",
":",
"r",
".",
"Message",
"=",
"err",
".",
"Error",
"(",
")",
"\n",
"r",
".",
"Code",
"=",
"-",
"1",
"\n",
"return",
"r",
",",
"err",
"\n",
"}",
"\n",
"}"
] | // VirtualizationWait wait virtualization exit | [
"VirtualizationWait",
"wait",
"virtualization",
"exit"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L186-L201 |
16,281 | projecteru2/core | engine/docker/container.go | VirtualizationUpdateResource | func (e *Engine) VirtualizationUpdateResource(ctx context.Context, ID string, opts *enginetypes.VirtualizationResource) error {
newResource := makeResourceSetting(opts.Quota, opts.Memory, opts.CPU, opts.SoftLimit)
updateConfig := dockercontainer.UpdateConfig{Resources: newResource}
_, err := e.client.ContainerUpdate(ctx, ID, updateConfig)
return err
} | go | func (e *Engine) VirtualizationUpdateResource(ctx context.Context, ID string, opts *enginetypes.VirtualizationResource) error {
newResource := makeResourceSetting(opts.Quota, opts.Memory, opts.CPU, opts.SoftLimit)
updateConfig := dockercontainer.UpdateConfig{Resources: newResource}
_, err := e.client.ContainerUpdate(ctx, ID, updateConfig)
return err
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationUpdateResource",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
"string",
",",
"opts",
"*",
"enginetypes",
".",
"VirtualizationResource",
")",
"error",
"{",
"newResource",
":=",
"makeResourceSetting",
"(",
"opts",
".",
"Quota",
",",
"opts",
".",
"Memory",
",",
"opts",
".",
"CPU",
",",
"opts",
".",
"SoftLimit",
")",
"\n",
"updateConfig",
":=",
"dockercontainer",
".",
"UpdateConfig",
"{",
"Resources",
":",
"newResource",
"}",
"\n",
"_",
",",
"err",
":=",
"e",
".",
"client",
".",
"ContainerUpdate",
"(",
"ctx",
",",
"ID",
",",
"updateConfig",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // VirtualizationUpdateResource update virtualization resource | [
"VirtualizationUpdateResource",
"update",
"virtualization",
"resource"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L204-L209 |
16,282 | projecteru2/core | engine/docker/container.go | VirtualizationCopyFrom | func (e *Engine) VirtualizationCopyFrom(ctx context.Context, ID, path string) (io.ReadCloser, string, error) {
resp, stat, err := e.client.CopyFromContainer(ctx, ID, path)
if err != nil {
return nil, "", err
}
return resp, stat.Name, err
} | go | func (e *Engine) VirtualizationCopyFrom(ctx context.Context, ID, path string) (io.ReadCloser, string, error) {
resp, stat, err := e.client.CopyFromContainer(ctx, ID, path)
if err != nil {
return nil, "", err
}
return resp, stat.Name, err
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"VirtualizationCopyFrom",
"(",
"ctx",
"context",
".",
"Context",
",",
"ID",
",",
"path",
"string",
")",
"(",
"io",
".",
"ReadCloser",
",",
"string",
",",
"error",
")",
"{",
"resp",
",",
"stat",
",",
"err",
":=",
"e",
".",
"client",
".",
"CopyFromContainer",
"(",
"ctx",
",",
"ID",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"resp",
",",
"stat",
".",
"Name",
",",
"err",
"\n",
"}"
] | // VirtualizationCopyFrom copy thing from a virtualization | [
"VirtualizationCopyFrom",
"copy",
"thing",
"from",
"a",
"virtualization"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/container.go#L212-L218 |
16,283 | projecteru2/core | auth/auth.go | NewAuth | func NewAuth(auth types.AuthConfig) Auth {
// TODO 这里可以组装其他的方法
return simple.NewBasicAuth(auth.Username, auth.Password)
} | go | func NewAuth(auth types.AuthConfig) Auth {
// TODO 这里可以组装其他的方法
return simple.NewBasicAuth(auth.Username, auth.Password)
} | [
"func",
"NewAuth",
"(",
"auth",
"types",
".",
"AuthConfig",
")",
"Auth",
"{",
"// TODO 这里可以组装其他的方法",
"return",
"simple",
".",
"NewBasicAuth",
"(",
"auth",
".",
"Username",
",",
"auth",
".",
"Password",
")",
"\n",
"}"
] | // NewAuth return auth obj | [
"NewAuth",
"return",
"auth",
"obj"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/auth/auth.go#L18-L21 |
16,284 | projecteru2/core | auth/auth.go | NewCredential | func NewCredential(auth types.AuthConfig) Credential {
// TODO 这里可以组装其他的方法
return simple.NewBasicCredential(auth.Username, auth.Password)
} | go | func NewCredential(auth types.AuthConfig) Credential {
// TODO 这里可以组装其他的方法
return simple.NewBasicCredential(auth.Username, auth.Password)
} | [
"func",
"NewCredential",
"(",
"auth",
"types",
".",
"AuthConfig",
")",
"Credential",
"{",
"// TODO 这里可以组装其他的方法",
"return",
"simple",
".",
"NewBasicCredential",
"(",
"auth",
".",
"Username",
",",
"auth",
".",
"Password",
")",
"\n",
"}"
] | // NewCredential return credential obj | [
"NewCredential",
"return",
"credential",
"obj"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/auth/auth.go#L30-L33 |
16,285 | projecteru2/core | cluster/calcium/resource.go | PodResource | func (c *Calcium) PodResource(ctx context.Context, podname string) (*types.PodResource, error) {
nodes, err := c.ListPodNodes(ctx, podname, true)
if err != nil {
return nil, err
}
r := &types.PodResource{
Name: podname,
CPUPercent: map[string]float64{},
MEMPercent: map[string]float64{},
Diff: map[string]bool{},
Detail: map[string]string{},
}
for _, node := range nodes {
containers, err := c.ListNodeContainers(ctx, node.Name)
if err != nil {
return nil, err
}
cpus := 0.0
memory := int64(0)
cpumap := types.CPUMap{}
for _, container := range containers {
cpus = utils.Round(cpus + container.Quota)
memory += container.Memory
cpumap.Add(container.CPU)
}
r.CPUPercent[node.Name] = cpus / float64(len(node.InitCPU))
r.MEMPercent[node.Name] = float64(memory) / float64(node.InitMemCap)
r.Diff[node.Name] = true
r.Detail[node.Name] = ""
cpumap.Add(node.CPU)
if cpus != node.CPUUsed {
r.Diff[node.Name] = false
r.Detail[node.Name] += fmt.Sprintf("cpus %f now %f ", node.CPUUsed, cpus)
}
for i, v := range cpumap {
if node.InitCPU[i] != v {
r.Diff[node.Name] = false
r.Detail[node.Name] += fmt.Sprintf("cpu %s now %d ", i, v)
}
}
if memory+node.MemCap != node.InitMemCap {
r.Diff[node.Name] = false
r.Detail[node.Name] += fmt.Sprintf("mem now %d ", node.InitMemCap-(memory+node.MemCap))
}
}
return r, nil
} | go | func (c *Calcium) PodResource(ctx context.Context, podname string) (*types.PodResource, error) {
nodes, err := c.ListPodNodes(ctx, podname, true)
if err != nil {
return nil, err
}
r := &types.PodResource{
Name: podname,
CPUPercent: map[string]float64{},
MEMPercent: map[string]float64{},
Diff: map[string]bool{},
Detail: map[string]string{},
}
for _, node := range nodes {
containers, err := c.ListNodeContainers(ctx, node.Name)
if err != nil {
return nil, err
}
cpus := 0.0
memory := int64(0)
cpumap := types.CPUMap{}
for _, container := range containers {
cpus = utils.Round(cpus + container.Quota)
memory += container.Memory
cpumap.Add(container.CPU)
}
r.CPUPercent[node.Name] = cpus / float64(len(node.InitCPU))
r.MEMPercent[node.Name] = float64(memory) / float64(node.InitMemCap)
r.Diff[node.Name] = true
r.Detail[node.Name] = ""
cpumap.Add(node.CPU)
if cpus != node.CPUUsed {
r.Diff[node.Name] = false
r.Detail[node.Name] += fmt.Sprintf("cpus %f now %f ", node.CPUUsed, cpus)
}
for i, v := range cpumap {
if node.InitCPU[i] != v {
r.Diff[node.Name] = false
r.Detail[node.Name] += fmt.Sprintf("cpu %s now %d ", i, v)
}
}
if memory+node.MemCap != node.InitMemCap {
r.Diff[node.Name] = false
r.Detail[node.Name] += fmt.Sprintf("mem now %d ", node.InitMemCap-(memory+node.MemCap))
}
}
return r, nil
} | [
"func",
"(",
"c",
"*",
"Calcium",
")",
"PodResource",
"(",
"ctx",
"context",
".",
"Context",
",",
"podname",
"string",
")",
"(",
"*",
"types",
".",
"PodResource",
",",
"error",
")",
"{",
"nodes",
",",
"err",
":=",
"c",
".",
"ListPodNodes",
"(",
"ctx",
",",
"podname",
",",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"r",
":=",
"&",
"types",
".",
"PodResource",
"{",
"Name",
":",
"podname",
",",
"CPUPercent",
":",
"map",
"[",
"string",
"]",
"float64",
"{",
"}",
",",
"MEMPercent",
":",
"map",
"[",
"string",
"]",
"float64",
"{",
"}",
",",
"Diff",
":",
"map",
"[",
"string",
"]",
"bool",
"{",
"}",
",",
"Detail",
":",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
",",
"}",
"\n",
"for",
"_",
",",
"node",
":=",
"range",
"nodes",
"{",
"containers",
",",
"err",
":=",
"c",
".",
"ListNodeContainers",
"(",
"ctx",
",",
"node",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cpus",
":=",
"0.0",
"\n",
"memory",
":=",
"int64",
"(",
"0",
")",
"\n",
"cpumap",
":=",
"types",
".",
"CPUMap",
"{",
"}",
"\n",
"for",
"_",
",",
"container",
":=",
"range",
"containers",
"{",
"cpus",
"=",
"utils",
".",
"Round",
"(",
"cpus",
"+",
"container",
".",
"Quota",
")",
"\n",
"memory",
"+=",
"container",
".",
"Memory",
"\n",
"cpumap",
".",
"Add",
"(",
"container",
".",
"CPU",
")",
"\n",
"}",
"\n",
"r",
".",
"CPUPercent",
"[",
"node",
".",
"Name",
"]",
"=",
"cpus",
"/",
"float64",
"(",
"len",
"(",
"node",
".",
"InitCPU",
")",
")",
"\n",
"r",
".",
"MEMPercent",
"[",
"node",
".",
"Name",
"]",
"=",
"float64",
"(",
"memory",
")",
"/",
"float64",
"(",
"node",
".",
"InitMemCap",
")",
"\n",
"r",
".",
"Diff",
"[",
"node",
".",
"Name",
"]",
"=",
"true",
"\n",
"r",
".",
"Detail",
"[",
"node",
".",
"Name",
"]",
"=",
"\"",
"\"",
"\n",
"cpumap",
".",
"Add",
"(",
"node",
".",
"CPU",
")",
"\n",
"if",
"cpus",
"!=",
"node",
".",
"CPUUsed",
"{",
"r",
".",
"Diff",
"[",
"node",
".",
"Name",
"]",
"=",
"false",
"\n",
"r",
".",
"Detail",
"[",
"node",
".",
"Name",
"]",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"node",
".",
"CPUUsed",
",",
"cpus",
")",
"\n",
"}",
"\n",
"for",
"i",
",",
"v",
":=",
"range",
"cpumap",
"{",
"if",
"node",
".",
"InitCPU",
"[",
"i",
"]",
"!=",
"v",
"{",
"r",
".",
"Diff",
"[",
"node",
".",
"Name",
"]",
"=",
"false",
"\n",
"r",
".",
"Detail",
"[",
"node",
".",
"Name",
"]",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"i",
",",
"v",
")",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"memory",
"+",
"node",
".",
"MemCap",
"!=",
"node",
".",
"InitMemCap",
"{",
"r",
".",
"Diff",
"[",
"node",
".",
"Name",
"]",
"=",
"false",
"\n",
"r",
".",
"Detail",
"[",
"node",
".",
"Name",
"]",
"+=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"node",
".",
"InitMemCap",
"-",
"(",
"memory",
"+",
"node",
".",
"MemCap",
")",
")",
"\n",
"}",
"\n\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] | // PodResource show pod resource usage | [
"PodResource",
"show",
"pod",
"resource",
"usage"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/cluster/calcium/resource.go#L20-L67 |
16,286 | projecteru2/core | utils/cache.go | Set | func (c *Cache) Set(host string, client engine.API) {
c.Lock()
defer c.Unlock()
c.Clients[host] = client
} | go | func (c *Cache) Set(host string, client engine.API) {
c.Lock()
defer c.Unlock()
c.Clients[host] = client
} | [
"func",
"(",
"c",
"*",
"Cache",
")",
"Set",
"(",
"host",
"string",
",",
"client",
"engine",
".",
"API",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"c",
".",
"Clients",
"[",
"host",
"]",
"=",
"client",
"\n",
"}"
] | // Set connection with host | [
"Set",
"connection",
"with",
"host"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/cache.go#L17-L21 |
16,287 | projecteru2/core | utils/cache.go | Get | func (c *Cache) Get(host string) engine.API {
c.Lock()
defer c.Unlock()
return c.Clients[host]
} | go | func (c *Cache) Get(host string) engine.API {
c.Lock()
defer c.Unlock()
return c.Clients[host]
} | [
"func",
"(",
"c",
"*",
"Cache",
")",
"Get",
"(",
"host",
"string",
")",
"engine",
".",
"API",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"return",
"c",
".",
"Clients",
"[",
"host",
"]",
"\n",
"}"
] | // Get connection by host | [
"Get",
"connection",
"by",
"host"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/cache.go#L24-L28 |
16,288 | projecteru2/core | utils/cache.go | Delete | func (c *Cache) Delete(host string) {
c.Lock()
defer c.Unlock()
delete(c.Clients, host)
} | go | func (c *Cache) Delete(host string) {
c.Lock()
defer c.Unlock()
delete(c.Clients, host)
} | [
"func",
"(",
"c",
"*",
"Cache",
")",
"Delete",
"(",
"host",
"string",
")",
"{",
"c",
".",
"Lock",
"(",
")",
"\n",
"defer",
"c",
".",
"Unlock",
"(",
")",
"\n",
"delete",
"(",
"c",
".",
"Clients",
",",
"host",
")",
"\n",
"}"
] | // Delete connection by host | [
"Delete",
"connection",
"by",
"host"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/utils/cache.go#L31-L35 |
16,289 | projecteru2/core | lock/etcdlock/mutex.go | New | func New(cli *clientv3.Client, key string, ttl int) (*Mutex, error) {
if key == "" {
return nil, types.ErrKeyIsEmpty
}
if !strings.HasPrefix(key, "/") {
key = fmt.Sprintf("/%s", key)
}
session, err := concurrency.NewSession(cli, concurrency.WithTTL(ttl))
if err != nil {
return nil, err
}
mutex := &Mutex{mutex: concurrency.NewMutex(session, key), session: session}
mutex.timeout = time.Duration(ttl) * time.Second
return mutex, nil
} | go | func New(cli *clientv3.Client, key string, ttl int) (*Mutex, error) {
if key == "" {
return nil, types.ErrKeyIsEmpty
}
if !strings.HasPrefix(key, "/") {
key = fmt.Sprintf("/%s", key)
}
session, err := concurrency.NewSession(cli, concurrency.WithTTL(ttl))
if err != nil {
return nil, err
}
mutex := &Mutex{mutex: concurrency.NewMutex(session, key), session: session}
mutex.timeout = time.Duration(ttl) * time.Second
return mutex, nil
} | [
"func",
"New",
"(",
"cli",
"*",
"clientv3",
".",
"Client",
",",
"key",
"string",
",",
"ttl",
"int",
")",
"(",
"*",
"Mutex",
",",
"error",
")",
"{",
"if",
"key",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"types",
".",
"ErrKeyIsEmpty",
"\n",
"}",
"\n\n",
"if",
"!",
"strings",
".",
"HasPrefix",
"(",
"key",
",",
"\"",
"\"",
")",
"{",
"key",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"key",
")",
"\n",
"}",
"\n\n",
"session",
",",
"err",
":=",
"concurrency",
".",
"NewSession",
"(",
"cli",
",",
"concurrency",
".",
"WithTTL",
"(",
"ttl",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"mutex",
":=",
"&",
"Mutex",
"{",
"mutex",
":",
"concurrency",
".",
"NewMutex",
"(",
"session",
",",
"key",
")",
",",
"session",
":",
"session",
"}",
"\n",
"mutex",
".",
"timeout",
"=",
"time",
".",
"Duration",
"(",
"ttl",
")",
"*",
"time",
".",
"Second",
"\n",
"return",
"mutex",
",",
"nil",
"\n",
"}"
] | // New new a lock | [
"New",
"new",
"a",
"lock"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/lock/etcdlock/mutex.go#L22-L39 |
16,290 | projecteru2/core | lock/etcdlock/mutex.go | Lock | func (m *Mutex) Lock(ctx context.Context) error {
lockCtx, cancel := context.WithTimeout(ctx, m.timeout)
defer cancel()
return m.mutex.Lock(lockCtx)
} | go | func (m *Mutex) Lock(ctx context.Context) error {
lockCtx, cancel := context.WithTimeout(ctx, m.timeout)
defer cancel()
return m.mutex.Lock(lockCtx)
} | [
"func",
"(",
"m",
"*",
"Mutex",
")",
"Lock",
"(",
"ctx",
"context",
".",
"Context",
")",
"error",
"{",
"lockCtx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"m",
".",
"timeout",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"return",
"m",
".",
"mutex",
".",
"Lock",
"(",
"lockCtx",
")",
"\n",
"}"
] | // Lock get locked | [
"Lock",
"get",
"locked"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/lock/etcdlock/mutex.go#L42-L46 |
16,291 | projecteru2/core | store/etcdv3/deploy.go | MakeDeployStatus | func (m *Mercury) MakeDeployStatus(ctx context.Context, opts *types.DeployOptions, nodesInfo []types.NodeInfo) ([]types.NodeInfo, error) {
// 手动加 / 防止不精确
key := filepath.Join(containerDeployPrefix, opts.Name, opts.Entrypoint.Name) + "/"
resp, err := m.Get(ctx, key, clientv3.WithPrefix(), clientv3.WithKeysOnly())
if err != nil {
return nil, err
}
if resp.Count != 0 {
nodesInfo, err = m.doGetDeployStatus(ctx, resp, nodesInfo)
if err != nil {
return nil, err
}
} else {
log.Warnf("[MakeDeployStatus] Deploy status not found %s.%s", opts.Name, opts.Entrypoint.Name)
}
return m.doLoadProcessing(ctx, opts, nodesInfo)
} | go | func (m *Mercury) MakeDeployStatus(ctx context.Context, opts *types.DeployOptions, nodesInfo []types.NodeInfo) ([]types.NodeInfo, error) {
// 手动加 / 防止不精确
key := filepath.Join(containerDeployPrefix, opts.Name, opts.Entrypoint.Name) + "/"
resp, err := m.Get(ctx, key, clientv3.WithPrefix(), clientv3.WithKeysOnly())
if err != nil {
return nil, err
}
if resp.Count != 0 {
nodesInfo, err = m.doGetDeployStatus(ctx, resp, nodesInfo)
if err != nil {
return nil, err
}
} else {
log.Warnf("[MakeDeployStatus] Deploy status not found %s.%s", opts.Name, opts.Entrypoint.Name)
}
return m.doLoadProcessing(ctx, opts, nodesInfo)
} | [
"func",
"(",
"m",
"*",
"Mercury",
")",
"MakeDeployStatus",
"(",
"ctx",
"context",
".",
"Context",
",",
"opts",
"*",
"types",
".",
"DeployOptions",
",",
"nodesInfo",
"[",
"]",
"types",
".",
"NodeInfo",
")",
"(",
"[",
"]",
"types",
".",
"NodeInfo",
",",
"error",
")",
"{",
"// 手动加 / 防止不精确",
"key",
":=",
"filepath",
".",
"Join",
"(",
"containerDeployPrefix",
",",
"opts",
".",
"Name",
",",
"opts",
".",
"Entrypoint",
".",
"Name",
")",
"+",
"\"",
"\"",
"\n",
"resp",
",",
"err",
":=",
"m",
".",
"Get",
"(",
"ctx",
",",
"key",
",",
"clientv3",
".",
"WithPrefix",
"(",
")",
",",
"clientv3",
".",
"WithKeysOnly",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"resp",
".",
"Count",
"!=",
"0",
"{",
"nodesInfo",
",",
"err",
"=",
"m",
".",
"doGetDeployStatus",
"(",
"ctx",
",",
"resp",
",",
"nodesInfo",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"else",
"{",
"log",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"opts",
".",
"Name",
",",
"opts",
".",
"Entrypoint",
".",
"Name",
")",
"\n",
"}",
"\n",
"return",
"m",
".",
"doLoadProcessing",
"(",
"ctx",
",",
"opts",
",",
"nodesInfo",
")",
"\n",
"}"
] | // MakeDeployStatus get deploy status from store | [
"MakeDeployStatus",
"get",
"deploy",
"status",
"from",
"store"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/store/etcdv3/deploy.go#L14-L30 |
16,292 | projecteru2/core | engine/docker/exec.go | ExecCreate | func (e *Engine) ExecCreate(ctx context.Context, target string, config *enginetypes.ExecConfig) (string, error) {
execConfig := dockertypes.ExecConfig{
User: config.User,
Cmd: config.Cmd,
Privileged: config.Privileged,
Env: config.Env,
AttachStderr: config.AttachStderr,
AttachStdout: config.AttachStdout,
}
// TODO should timeout
// Fuck docker, ctx will not use inside funcs!!
idResp, err := e.client.ContainerExecCreate(ctx, target, execConfig)
if err != nil {
return "", err
}
return idResp.ID, nil
} | go | func (e *Engine) ExecCreate(ctx context.Context, target string, config *enginetypes.ExecConfig) (string, error) {
execConfig := dockertypes.ExecConfig{
User: config.User,
Cmd: config.Cmd,
Privileged: config.Privileged,
Env: config.Env,
AttachStderr: config.AttachStderr,
AttachStdout: config.AttachStdout,
}
// TODO should timeout
// Fuck docker, ctx will not use inside funcs!!
idResp, err := e.client.ContainerExecCreate(ctx, target, execConfig)
if err != nil {
return "", err
}
return idResp.ID, nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"ExecCreate",
"(",
"ctx",
"context",
".",
"Context",
",",
"target",
"string",
",",
"config",
"*",
"enginetypes",
".",
"ExecConfig",
")",
"(",
"string",
",",
"error",
")",
"{",
"execConfig",
":=",
"dockertypes",
".",
"ExecConfig",
"{",
"User",
":",
"config",
".",
"User",
",",
"Cmd",
":",
"config",
".",
"Cmd",
",",
"Privileged",
":",
"config",
".",
"Privileged",
",",
"Env",
":",
"config",
".",
"Env",
",",
"AttachStderr",
":",
"config",
".",
"AttachStderr",
",",
"AttachStdout",
":",
"config",
".",
"AttachStdout",
",",
"}",
"\n\n",
"// TODO should timeout",
"// Fuck docker, ctx will not use inside funcs!!",
"idResp",
",",
"err",
":=",
"e",
".",
"client",
".",
"ContainerExecCreate",
"(",
"ctx",
",",
"target",
",",
"execConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"return",
"idResp",
".",
"ID",
",",
"nil",
"\n",
"}"
] | // ExecCreate create a exec | [
"ExecCreate",
"create",
"a",
"exec"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/exec.go#L12-L29 |
16,293 | projecteru2/core | engine/docker/exec.go | ExecAttach | func (e *Engine) ExecAttach(ctx context.Context, execID string, detach, tty bool) (io.ReadCloser, error) {
resp, err := e.client.ContainerExecAttach(ctx, execID, dockertypes.ExecStartCheck{})
if err != nil {
return nil, err
}
return FuckDockerStream(resp), nil
} | go | func (e *Engine) ExecAttach(ctx context.Context, execID string, detach, tty bool) (io.ReadCloser, error) {
resp, err := e.client.ContainerExecAttach(ctx, execID, dockertypes.ExecStartCheck{})
if err != nil {
return nil, err
}
return FuckDockerStream(resp), nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"ExecAttach",
"(",
"ctx",
"context",
".",
"Context",
",",
"execID",
"string",
",",
"detach",
",",
"tty",
"bool",
")",
"(",
"io",
".",
"ReadCloser",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"e",
".",
"client",
".",
"ContainerExecAttach",
"(",
"ctx",
",",
"execID",
",",
"dockertypes",
".",
"ExecStartCheck",
"{",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"FuckDockerStream",
"(",
"resp",
")",
",",
"nil",
"\n",
"}"
] | // ExecAttach attach a exec | [
"ExecAttach",
"attach",
"a",
"exec"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/exec.go#L32-L38 |
16,294 | projecteru2/core | engine/docker/exec.go | ExecExitCode | func (e *Engine) ExecExitCode(ctx context.Context, execID string) (int, error) {
r, err := e.client.ContainerExecInspect(ctx, execID)
if err != nil {
return -1, err
}
return r.ExitCode, nil
} | go | func (e *Engine) ExecExitCode(ctx context.Context, execID string) (int, error) {
r, err := e.client.ContainerExecInspect(ctx, execID)
if err != nil {
return -1, err
}
return r.ExitCode, nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"ExecExitCode",
"(",
"ctx",
"context",
".",
"Context",
",",
"execID",
"string",
")",
"(",
"int",
",",
"error",
")",
"{",
"r",
",",
"err",
":=",
"e",
".",
"client",
".",
"ContainerExecInspect",
"(",
"ctx",
",",
"execID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"-",
"1",
",",
"err",
"\n",
"}",
"\n",
"return",
"r",
".",
"ExitCode",
",",
"nil",
"\n",
"}"
] | // ExecExitCode get exec return code | [
"ExecExitCode",
"get",
"exec",
"return",
"code"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/exec.go#L41-L47 |
16,295 | projecteru2/core | source/github/manganese.go | New | func New(config types.Config) *common.GitScm {
gitConfig := config.Git
token := fmt.Sprintf("token %s", gitConfig.Token)
authheaders := map[string]string{}
authheaders["Authorization"] = token
return &common.GitScm{Config: gitConfig, AuthHeaders: authheaders}
} | go | func New(config types.Config) *common.GitScm {
gitConfig := config.Git
token := fmt.Sprintf("token %s", gitConfig.Token)
authheaders := map[string]string{}
authheaders["Authorization"] = token
return &common.GitScm{Config: gitConfig, AuthHeaders: authheaders}
} | [
"func",
"New",
"(",
"config",
"types",
".",
"Config",
")",
"*",
"common",
".",
"GitScm",
"{",
"gitConfig",
":=",
"config",
".",
"Git",
"\n",
"token",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"gitConfig",
".",
"Token",
")",
"\n",
"authheaders",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"authheaders",
"[",
"\"",
"\"",
"]",
"=",
"token",
"\n",
"return",
"&",
"common",
".",
"GitScm",
"{",
"Config",
":",
"gitConfig",
",",
"AuthHeaders",
":",
"authheaders",
"}",
"\n",
"}"
] | // New new a github obj | [
"New",
"new",
"a",
"github",
"obj"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/source/github/manganese.go#L11-L17 |
16,296 | projecteru2/core | engine/docker/docker.go | MakeRawClient | func MakeRawClient(config coretypes.Config, client *http.Client, endpoint, apiversion string) (*Engine, error) {
cli, err := dockerapi.NewClient(endpoint, apiversion, client, nil)
if err != nil {
return nil, err
}
return &Engine{cli, config}, nil
} | go | func MakeRawClient(config coretypes.Config, client *http.Client, endpoint, apiversion string) (*Engine, error) {
cli, err := dockerapi.NewClient(endpoint, apiversion, client, nil)
if err != nil {
return nil, err
}
return &Engine{cli, config}, nil
} | [
"func",
"MakeRawClient",
"(",
"config",
"coretypes",
".",
"Config",
",",
"client",
"*",
"http",
".",
"Client",
",",
"endpoint",
",",
"apiversion",
"string",
")",
"(",
"*",
"Engine",
",",
"error",
")",
"{",
"cli",
",",
"err",
":=",
"dockerapi",
".",
"NewClient",
"(",
"endpoint",
",",
"apiversion",
",",
"client",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"Engine",
"{",
"cli",
",",
"config",
"}",
",",
"nil",
"\n",
"}"
] | // MakeRawClient make raw docker cli | [
"MakeRawClient",
"make",
"raw",
"docker",
"cli"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/docker.go#L30-L36 |
16,297 | projecteru2/core | engine/docker/docker.go | MakeRawClientWithTLS | func MakeRawClientWithTLS(config coretypes.Config, ca, cert, key *os.File, endpoint, apiversion string) (*Engine, error) {
var client *http.Client
options := tlsconfig.Options{
CAFile: ca.Name(),
CertFile: cert.Name(),
KeyFile: key.Name(),
InsecureSkipVerify: true,
}
defer os.Remove(ca.Name())
defer os.Remove(cert.Name())
defer os.Remove(key.Name())
tlsc, err := tlsconfig.Client(options)
if err != nil {
return nil, err
}
client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsc,
},
}
log.Debugf("[MakeRawClientWithTLS] Create new http.Client for %s, %s", endpoint, apiversion)
return MakeRawClient(config, client, endpoint, apiversion)
} | go | func MakeRawClientWithTLS(config coretypes.Config, ca, cert, key *os.File, endpoint, apiversion string) (*Engine, error) {
var client *http.Client
options := tlsconfig.Options{
CAFile: ca.Name(),
CertFile: cert.Name(),
KeyFile: key.Name(),
InsecureSkipVerify: true,
}
defer os.Remove(ca.Name())
defer os.Remove(cert.Name())
defer os.Remove(key.Name())
tlsc, err := tlsconfig.Client(options)
if err != nil {
return nil, err
}
client = &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsc,
},
}
log.Debugf("[MakeRawClientWithTLS] Create new http.Client for %s, %s", endpoint, apiversion)
return MakeRawClient(config, client, endpoint, apiversion)
} | [
"func",
"MakeRawClientWithTLS",
"(",
"config",
"coretypes",
".",
"Config",
",",
"ca",
",",
"cert",
",",
"key",
"*",
"os",
".",
"File",
",",
"endpoint",
",",
"apiversion",
"string",
")",
"(",
"*",
"Engine",
",",
"error",
")",
"{",
"var",
"client",
"*",
"http",
".",
"Client",
"\n",
"options",
":=",
"tlsconfig",
".",
"Options",
"{",
"CAFile",
":",
"ca",
".",
"Name",
"(",
")",
",",
"CertFile",
":",
"cert",
".",
"Name",
"(",
")",
",",
"KeyFile",
":",
"key",
".",
"Name",
"(",
")",
",",
"InsecureSkipVerify",
":",
"true",
",",
"}",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"ca",
".",
"Name",
"(",
")",
")",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"cert",
".",
"Name",
"(",
")",
")",
"\n",
"defer",
"os",
".",
"Remove",
"(",
"key",
".",
"Name",
"(",
")",
")",
"\n",
"tlsc",
",",
"err",
":=",
"tlsconfig",
".",
"Client",
"(",
"options",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"client",
"=",
"&",
"http",
".",
"Client",
"{",
"Transport",
":",
"&",
"http",
".",
"Transport",
"{",
"TLSClientConfig",
":",
"tlsc",
",",
"}",
",",
"}",
"\n",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"endpoint",
",",
"apiversion",
")",
"\n",
"return",
"MakeRawClient",
"(",
"config",
",",
"client",
",",
"endpoint",
",",
"apiversion",
")",
"\n",
"}"
] | // MakeRawClientWithTLS make raw docker cli with TLS | [
"MakeRawClientWithTLS",
"make",
"raw",
"docker",
"cli",
"with",
"TLS"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/docker.go#L39-L61 |
16,298 | projecteru2/core | engine/docker/docker.go | Info | func (e *Engine) Info(ctx context.Context) (*enginetypes.Info, error) {
infoCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
r, err := e.client.Info(infoCtx)
if err != nil {
return nil, err
}
return &enginetypes.Info{ID: r.ID, NCPU: r.NCPU, MemTotal: r.MemTotal}, nil
} | go | func (e *Engine) Info(ctx context.Context) (*enginetypes.Info, error) {
infoCtx, cancel := context.WithTimeout(ctx, 2*time.Second)
defer cancel()
r, err := e.client.Info(infoCtx)
if err != nil {
return nil, err
}
return &enginetypes.Info{ID: r.ID, NCPU: r.NCPU, MemTotal: r.MemTotal}, nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"Info",
"(",
"ctx",
"context",
".",
"Context",
")",
"(",
"*",
"enginetypes",
".",
"Info",
",",
"error",
")",
"{",
"infoCtx",
",",
"cancel",
":=",
"context",
".",
"WithTimeout",
"(",
"ctx",
",",
"2",
"*",
"time",
".",
"Second",
")",
"\n",
"defer",
"cancel",
"(",
")",
"\n",
"r",
",",
"err",
":=",
"e",
".",
"client",
".",
"Info",
"(",
"infoCtx",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"enginetypes",
".",
"Info",
"{",
"ID",
":",
"r",
".",
"ID",
",",
"NCPU",
":",
"r",
".",
"NCPU",
",",
"MemTotal",
":",
"r",
".",
"MemTotal",
"}",
",",
"nil",
"\n",
"}"
] | // Info show node info
// 2 seconds timeout
// used to be 5, but client won't wait that long | [
"Info",
"show",
"node",
"info",
"2",
"seconds",
"timeout",
"used",
"to",
"be",
"5",
"but",
"client",
"won",
"t",
"wait",
"that",
"long"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/docker.go#L66-L74 |
16,299 | projecteru2/core | engine/docker/image.go | ImageList | func (e *Engine) ImageList(ctx context.Context, image string) ([]*enginetypes.Image, error) {
image = normalizeImage(image)
imgListFilter := dockerfilters.NewArgs()
imgListFilter.Add("reference", image) // 相同 repo 的image
images, err := e.client.ImageList(ctx, dockertypes.ImageListOptions{Filters: imgListFilter})
if err != nil {
return nil, err
}
r := []*enginetypes.Image{}
for _, image := range images {
i := &enginetypes.Image{
ID: image.ID,
Tags: image.RepoTags,
}
r = append(r, i)
}
return r, nil
} | go | func (e *Engine) ImageList(ctx context.Context, image string) ([]*enginetypes.Image, error) {
image = normalizeImage(image)
imgListFilter := dockerfilters.NewArgs()
imgListFilter.Add("reference", image) // 相同 repo 的image
images, err := e.client.ImageList(ctx, dockertypes.ImageListOptions{Filters: imgListFilter})
if err != nil {
return nil, err
}
r := []*enginetypes.Image{}
for _, image := range images {
i := &enginetypes.Image{
ID: image.ID,
Tags: image.RepoTags,
}
r = append(r, i)
}
return r, nil
} | [
"func",
"(",
"e",
"*",
"Engine",
")",
"ImageList",
"(",
"ctx",
"context",
".",
"Context",
",",
"image",
"string",
")",
"(",
"[",
"]",
"*",
"enginetypes",
".",
"Image",
",",
"error",
")",
"{",
"image",
"=",
"normalizeImage",
"(",
"image",
")",
"\n",
"imgListFilter",
":=",
"dockerfilters",
".",
"NewArgs",
"(",
")",
"\n",
"imgListFilter",
".",
"Add",
"(",
"\"",
"\"",
",",
"image",
")",
"// 相同 repo 的image",
"\n\n",
"images",
",",
"err",
":=",
"e",
".",
"client",
".",
"ImageList",
"(",
"ctx",
",",
"dockertypes",
".",
"ImageListOptions",
"{",
"Filters",
":",
"imgListFilter",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"r",
":=",
"[",
"]",
"*",
"enginetypes",
".",
"Image",
"{",
"}",
"\n",
"for",
"_",
",",
"image",
":=",
"range",
"images",
"{",
"i",
":=",
"&",
"enginetypes",
".",
"Image",
"{",
"ID",
":",
"image",
".",
"ID",
",",
"Tags",
":",
"image",
".",
"RepoTags",
",",
"}",
"\n",
"r",
"=",
"append",
"(",
"r",
",",
"i",
")",
"\n",
"}",
"\n",
"return",
"r",
",",
"nil",
"\n",
"}"
] | // ImageList list image | [
"ImageList",
"list",
"image"
] | b12208b63ff460ec82327f36d39a2cee786f4dbb | https://github.com/projecteru2/core/blob/b12208b63ff460ec82327f36d39a2cee786f4dbb/engine/docker/image.go#L15-L34 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.