func (ctx *ClusterContext) initContainerSequences() error { cifs := ctx.containerInfos if len(ctx.filters) > 0 { aCifs, err := ctx.loadAllContainers() if err != nil { return err } cifs = aCifs } cn := dcontainer.ContainerName{} for _, ci := range cifs { cName := ci.Name[0] if cn.Parse(cName) { group := cn.Group seqNum := cn.Seq if gSeq, ok := ctx.cSeqs[group]; ok { gSeq.Max(seqNum) } else { seq := &sequence.Seq{} seq.Max(seqNum) ctx.cSeqs[group] = seq } } else { fmt.Printf("'%s' is not a valid container name.\n", cName) } } fmt.Printf("Named Container info sequences inited:%+v\n", ctx.cSeqs) return nil }
func (ctx *ClusterContext) nextContainerName(group string) string { gSeq := func(g string, ctx *ClusterContext) *sequence.Seq { sequenceLock.Lock() defer sequenceLock.Unlock() gSeq, ok := ctx.cSeqs[group] if ok { return gSeq } gSeq = &sequence.Seq{} gSeq.Max(0) ctx.cSeqs[group] = gSeq return gSeq }(group, ctx) seq := gSeq.Next() cn := dcontainer.ContainerName{ Group: group, Seq: seq, } return cn.GetName() }