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",
"(",
"\"",
"... | // 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",
":",
"conf... | // 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"... | // 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",
".",
"WithT... | // 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 的问题很... | // 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... | // 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",
".",
"Watc... | // 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",
... | // 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",
".",
... | // 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",
":",... | // 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",
"... | // 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",
",",
"... | // 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",
"(",
"c... | // 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",
"[",
"]",
"*",
"typ... | // 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",
... | // 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"... | // 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",
",",
... | // 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",
".",
"GetContain... | // 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",
":=",... | // 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",
".",
"ContainerDeploy... | // 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",
... | // 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"... | // 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",
")",
"{",
"lo... | // 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",
"]",
"[",
"]",
... | // 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",
... | // 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",
... | // 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",
".",
... | // 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",... | // 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",
"_",
",",
"... | // 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",
":=",
... | // 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",
".",
... | // 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",
"(",
"r... | // 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",
",",
"\"",
"\"",
")",
"||",
"s... | // 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",
",",
"\... | // 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",
... | // 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",
"... | // 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",
":=",
"str... | // 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... | // 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",
... | // 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",
":=... | // 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",
... | // 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",
... | // 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",... | // 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",
... | // 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",... | // 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",
"docke... | // 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",
":",... | // 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",
"... | // 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",
... | // 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",
","... | // 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",
"!=... | // 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",
".",
"Process... | // 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",
"{",
"cliv... | // 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",
".",
... | // 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",
".",
"... | // 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",
":=... | // 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",
".... | // 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... | // 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",
... | // 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"... | // 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",... | // 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"... | // 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",
")",
... | // 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",
":=",
... | // 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",
"{",... | // 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",
"... | // 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",
",",
"}",... | // 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",
"{",
"ret... | // 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",
".",
"ContainerSta... | // 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",
","... | // 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",
"{",
"ret... | // 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",
":=",
"doc... | // 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",
")",
"{",
"... | // 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",
":=",
... | // 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",
"(",
... | // 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",
":=",
... | // 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"... | // 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",
"]",
"=",
"clie... | // 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",
"}"... | // 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"... | // 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",
",",
... | // 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",
".",
... | // 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",
".",
... | // 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",
",",
... | // 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",
"authheader... | // 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",
".",
"Ne... | // 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",
"*",
... | // 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"... | // 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",
... | // 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.