Ejemplo n.º 1
0
// viper read config file, marshal to definition struct,
// load service, validate name and data container
func LoadChainDefinition(chainName string, newCont bool, cNum ...int) (*definitions.Chain, error) {
	if len(cNum) == 0 {
		cNum = append(cNum, 0)
	}

	if cNum[0] == 0 {
		cNum[0] = util.AutoMagic(0, "chain", newCont)
		logger.Debugf("Loading Chain Definition =>\t%s:%d (autoassigned)\n", chainName, cNum[0])
	} else {
		logger.Debugf("Loading Chain Definition =>\t%s:%d\n", chainName, cNum[0])
	}

	chain := definitions.BlankChain()
	chain.Name = chainName
	chain.Operations.ContainerNumber = cNum[0]
	setChainDefaults(chain)

	chainConf, err := loadChainDefinition(chainName)
	if err != nil {
		return nil, err
	}

	// marshal chain and always reset the operational requirements
	// this will make sure to sync with docker so that if changes
	// have occured in the interim they are caught.
	if err = MarshalChainDefinition(chainConf, chain); err != nil {
		return nil, err
	}

	checkChainNames(chain)
	logger.Debugf("Chain Loader. ContNumber =>\t%d\n", chain.Operations.ContainerNumber)
	logger.Debugf("\twith Environment =>\t%v\n", chain.Service.Environment)
	return chain, nil
}
Ejemplo n.º 2
0
// marshal from viper to definitions struct
func MarshalChainDefinition(chainConf *viper.Viper, chain *definitions.Chain) error {
	chnTemp := definitions.BlankChain()
	// logger.Debugf("Loader.Chain: ChainID =>\t\t%v\n", chain.ChainID)
	// logger.Debugf("Loader.Chain. Conf =>\t\t%v\n", chainConf)
	err := chainConf.Marshal(chnTemp)
	if err != nil {
		return fmt.Errorf("The marmots coult not marshal from viper to chain def: %v", err)
	}
	// logger.Debugf("Loader.Chain.Marshal: ChanID =>\t%v\n", chnTemp.ChainID)

	mergeChainAndService(chain, chnTemp.Service)
	chain.ChainID = chnTemp.ChainID

	// toml bools don't really marshal well
	// data_container can be in the chain or
	// in the service layer. this is very
	// opinionated. we know.
	for _, s := range []string{"", "service."} {
		if chainConf.GetBool(s + "data_container") {
			logger.Debugln("Loader.Chain.Marshal: Data Containers Turned On.")
			chain.Service.AutoData = true
		}
	}

	return nil
}
Ejemplo n.º 3
0
// viper read config file, marshal to definition struct,
// load service, validate name and data container
func LoadChainDefinition(chainName string, newCont bool, cNum ...int) (*definitions.Chain, error) {
	if len(cNum) == 0 {
		cNum = append(cNum, 0)
	}

	if cNum[0] == 0 {
		cNum[0] = util.AutoMagic(0, definitions.TypeChain, newCont)
		log.WithField("=>", fmt.Sprintf("%s:%d", chainName, cNum[0])).Debug("Loading chain definition (autoassigned)")
	} else {
		log.WithField("=>", fmt.Sprintf("%s:%d", chainName, cNum[0])).Debug("Loading chain definition")
	}

	chain := definitions.BlankChain()
	chain.Name = chainName
	chain.Operations.ContainerNumber = cNum[0]
	chain.Operations.ContainerType = definitions.TypeChain
	chain.Operations.Labels = util.Labels(chain.Name, chain.Operations)
	if err := setChainDefaults(chain); err != nil {
		return nil, err
	}

	chainConf, err := config.LoadViperConfig(filepath.Join(ChainsPath), chainName, "chain")
	if err != nil {
		return nil, err
	}

	// marshal chain and always reset the operational requirements
	// this will make sure to sync with docker so that if changes
	// have occured in the interim they are caught.
	if err = MarshalChainDefinition(chainConf, chain); err != nil {
		return nil, err
	}

	// Docker 1.6 (which eris doesn't support) had different linking mechanism.
	if ver, _ := util.DockerClientVersion(); ver >= version.DVER_MIN {
		if chain.Dependencies != nil {
			addDependencyVolumesAndLinks(chain.Dependencies, chain.Service, chain.Operations)
		}
	}

	checkChainNames(chain)
	log.WithFields(log.Fields{
		"container number": chain.Operations.ContainerNumber,
		"environment":      chain.Service.Environment,
		"entrypoint":       chain.Service.EntryPoint,
		"cmd":              chain.Service.Command,
	}).Debug("Chain definition loaded")
	return chain, nil
}
Ejemplo n.º 4
0
func MockChainDefinition(chainName, chainID string, newCont bool, cNum ...int) *definitions.Chain {
	chn := definitions.BlankChain()
	chn.Name = chainName
	chn.ChainID = chainID
	chn.Service.AutoData = true

	if len(cNum) == 0 {
		chn.Operations.ContainerNumber = util.AutoMagic(cNum[0], "chain", newCont)
		logger.Debugf("Mocking Chain Definition =>\t%s:%d (autoassigned)\n", chainName, cNum[0])
	} else {
		chn.Operations.ContainerNumber = cNum[0]
		logger.Debugf("Mocking Chain Definition =>\t%s:%d\n", chainName, cNum[0])
	}

	checkChainNames(chn)
	return chn
}
Ejemplo n.º 5
0
// viper read config file, marshal to definition struct,
// load service, validate name and data container
func LoadChainDefinition(chainName string, newCont bool, cNum ...int) (*definitions.Chain, error) {
	if len(cNum) == 0 {
		cNum = append(cNum, 0)
	}

	if cNum[0] == 0 {
		cNum[0] = util.AutoMagic(0, "chain", newCont)
		logger.Debugf("Loading Chain Definition =>\t%s:%d (autoassigned)\n", chainName, cNum[0])
	} else {
		logger.Debugf("Loading Chain Definition =>\t%s:%d\n", chainName, cNum[0])
	}

	chain := definitions.BlankChain()
	chain.Name = chainName
	chain.Operations.ContainerNumber = cNum[0]
	if err := setChainDefaults(chain); err != nil {
		return nil, err
	}

	chainConf, err := config.LoadViperConfig(path.Join(BlockchainsPath), chainName, "chain")
	if err != nil {
		return nil, err
	}

	// marshal chain and always reset the operational requirements
	// this will make sure to sync with docker so that if changes
	// have occured in the interim they are caught.
	if err = MarshalChainDefinition(chainConf, chain); err != nil {
		return nil, err
	}

	// Docker 1.6 (which eris doesn't support) had different linking mechanism.
	if ver, _ := util.DockerClientVersion(); ver >= 1.7 {
		if chain.Dependencies != nil {
			addDependencyVolumesAndLinks(chain.Dependencies, chain.Service, chain.Operations)
		}
	}

	checkChainNames(chain)
	logger.Debugf("Chain Loader. ContNumber =>\t%d\n", chain.Operations.ContainerNumber)
	logger.Debugf("\twith Environment =>\t%v\n", chain.Service.Environment)
	logger.Debugf("\tBooting =>\t\t%v:%v\n", chain.Service.EntryPoint, chain.Service.Command)
	return chain, nil
}
Ejemplo n.º 6
0
func MockChainDefinition(chainName, chainID string, newCont bool, cNum ...int) *definitions.Chain {
	chn := definitions.BlankChain()
	chn.Name = chainName
	chn.ChainID = chainID
	chn.Service.AutoData = true

	if len(cNum) == 0 {
		chn.Operations.ContainerNumber = util.AutoMagic(cNum[0], definitions.TypeChain, newCont)
		log.WithField("=>", fmt.Sprintf("%s:%d", chainName, cNum[0])).Debug("Mocking chain definition (autoassigned)")
	} else {
		chn.Operations.ContainerNumber = cNum[0]
		log.WithField("=>", fmt.Sprintf("%s:%d", chainName, cNum[0])).Debug("Mocking chain definition")
	}

	chn.Operations.ContainerType = definitions.TypeChain
	chn.Operations.Labels = util.Labels(chainName, chn.Operations)

	checkChainNames(chn)
	return chn
}
Ejemplo n.º 7
0
// marshal from viper to definitions struct
func MarshalChainDefinition(chainConf *viper.Viper, chain *definitions.Chain) error {
	log.Debug("Marshalling chain")
	chnTemp := definitions.BlankChain()
	err := chainConf.Unmarshal(chnTemp)
	if err != nil {
		return fmt.Errorf("The marmots coult not marshal from viper to chain def: %v", err)
	}

	util.Merge(chain.Service, chnTemp.Service)
	chain.ChainID = chnTemp.ChainID

	// toml bools don't really marshal well
	// data_container can be in the chain or
	// in the service layer. this is very
	// opinionated. we know.
	for _, s := range []string{"", "service."} {
		if chainConf.GetBool(s + "data_container") {
			chain.Service.AutoData = true
			log.WithField("autodata", chain.Service.AutoData).Debug()
		}
	}

	return nil
}