Example #1
0
// init the exists machine, container, and seq
func (ctx *ClusterContext) initContext() {
	fmt.Printf("Parsing port binding in cluster description.\n")
	ctx.parsePortBindings()

	fmt.Printf("Create a new machine proxy. cluster by:%s, driver:%s, discovery: %s, master: %s, driver options:%s\n", ctx.clusterDesc.ClusterBy, ctx.clusterDesc.Driver, ctx.clusterDesc.Discovery, ctx.clusterDesc.MasterNode, strings.Join(ctx.clusterDesc.DriverOptions, " "))
	machineProxy := dmachine.NewMachineClusterProxy("dockerf machine", ctx.clusterDesc.ClusterBy, ctx.clusterDesc.Driver, ctx.clusterDesc.Discovery, ctx.clusterDesc.MasterNode, ctx.clusterDesc.DriverOptions)
	ctx.mProxy = machineProxy

	fmt.Println("Loading the cluster machine info...")
	mis, err := ctx.mProxy.List()
	if err != nil {
		panic("Init cluster context error, cannot list machine infos:" + err.Error())
	}
	ctx.machineInfos = mis

	fmt.Printf("Starting machine master\n")
	if err := ctx.startMaster(); err != nil {
		panic("Start cluster master failed: " + err.Error())
	}

	tlsConfig, err := machineProxy.Config()
	if err != nil {
		panic(fmt.Sprintf("Failed to load master machine node tls config. err:%s\n", err.Error()))
	}

	containerProxy, err := dcontainer.NewDockerProxy(tlsConfig)
	if err != nil {
		panic("Failed to create docker proxy:%s\n" + err.Error())
	}
	ctx.cProxy = containerProxy

	fmt.Printf("Init the consule cluster.\n")
	if err := ctx.startConsulCluster(); err != nil {
		panic("Start consul cluster failed: " + err.Error())
	}

	fmt.Println("Init the named machine sequence...")
	ctx.initMachineSequence(mis)

	fmt.Printf("Loading all filtered container infos")
	if err := ctx.loadContainers(); err != nil {
		panic("Init cluster context error, cannot list container infos:" + err.Error())
	}

	fmt.Printf("Init container sequences.\n")
	if err := ctx.initContainerSequences(); err != nil {
		panic("Init cluster context error, cannot init container seqs:" + err.Error())
	}

	fmt.Println("cluster context inited successfully")
}
Example #2
0
// init the exists machine, container, and seq
func (ctx *ClusterContext) initContext() {
	// log.Info("Parsing port binding in cluster description.")
	// ctx.parsePortBindings()

	log.Info("Init container description")
	err := ctx.initContainerDescription()
	if err != nil {
		panic("Fail to init container description, err: " + err.Error())
	}

	supportedDrivers := strings.Join(ctx.clusterDesc.Machine.Cloud.SurportedDrivers(), ",")
	log.Infof("Create a new machine proxy. cluster by:%s, supported drivers:%s, discovery: %s, master: %s\n", ctx.clusterDesc.ClusterBy, supportedDrivers, ctx.clusterDesc.Discovery, ctx.clusterDesc.Master)
	machineProxy := dmachine.NewMachineClusterProxy("dockerf machine", ctx.clusterDesc.ClusterBy, ctx.clusterDesc.Discovery, ctx.clusterDesc.Master, ctx.clusterDesc.Machine.Cloud)
	ctx.mProxy = machineProxy

	log.Info("Loading the cluster machine info...")
	mis, err := ctx.mProxy.List()
	if err != nil {
		panic("Init cluster context error, cannot list machine infos:" + err.Error())
	}
	ctx.machineInfos = mis

	log.Info("Init the consule cluster.")
	if err := ctx.startConsulCluster(); err != nil {
		panic("Start consul cluster failed: " + err.Error())
	}

	log.Info("Starting machine master")
	if err := ctx.startMaster(); err != nil {
		panic("Start cluster master failed: " + err.Error())
	}

	tlsConfig, err := machineProxy.Config()
	if err != nil {
		panic(fmt.Sprintf("Failed to load master machine node tls config. err:%s\n", err.Error()))
	}

	containerProxy, err := dcontainer.NewDockerProxy(tlsConfig)
	if err != nil {
		panic("Failed to create docker proxy:%s\n" + err.Error())
	}
	ctx.cProxy = containerProxy

	ctx.containerFilterChain = dcontainerfilter.NewFilterChain(ctx.cProxy)

	log.Info("Init the named machine sequence...")
	ctx.initMachineSequence(mis)

	log.Info("Loading all filtered container infos... ")
	if err := ctx.loadContainers(); err != nil {
		panic("Init cluster context error, cannot list container infos:" + err.Error())
	}

	log.Info("Init container sequences.")
	if err := ctx.initContainerSequences(); err != nil {
		panic("Init cluster context error, cannot init container seqs:" + err.Error())
	}

	log.Infof("ensure machine compacity.")
	if err := ctx.ensureMachineCapacity(); err != nil {
		panic("Ensure machine capacity error:%s" + err.Error())
	}

	log.Info("Init service discovery.")
	if err := ctx.initServiceDiscovery(); err != nil {
		panic("Init service discovery failed:" + err.Error())
	}

	log.Info("cluster context inited successfully")
}