当前位置: 首页>>代码示例>>Golang>>正文


Golang go-marathon.NewDefaultConfig函数代码示例

本文整理汇总了Golang中github.com/gambol99/go-marathon.NewDefaultConfig函数的典型用法代码示例。如果您正苦于以下问题:Golang NewDefaultConfig函数的具体用法?Golang NewDefaultConfig怎么用?Golang NewDefaultConfig使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewDefaultConfig函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: initMarathonClient

// getMarathonClient connects to mesos cluster
// returns marathon interface like tasks, applications
// groups, deployment, subscriptions, ...
func initMarathonClient() marathon.Marathon {
	config := marathon.NewDefaultConfig()
	config.URL = conf.New().Endpoint
	client, err := marathon.NewClient(config)
	if err != nil {
		glog.Fatalf("Failed to create a client for marathon, error: %s", err)
	}
	return client
}
开发者ID:anujwalia,项目名称:chimp,代码行数:12,代码来源:marathon.go

示例2: newMarathonClient

func (sc *ServerCommand) newMarathonClient(url string) (marathon.Marathon, error) {
	marathonConfig := marathon.NewDefaultConfig()
	marathonConfig.URL = url
	marathonClient, err := marathon.NewClient(marathonConfig)
	if err != nil {
		return nil, err
	}

	return marathonClient, nil
}
开发者ID:elodina,项目名称:stack-deploy,代码行数:10,代码来源:server.go

示例3: Config

// Config gives new configuration for Marathon client.
func (c *Credential) Config() *marathon.Config {
	cfg := marathon.NewDefaultConfig()

	cfg.URL = c.URL
	cfg.HTTPBasicAuthUser = c.BasicAuthUser
	cfg.HTTPBasicPassword = c.BasicAuthPassword
	cfg.HTTPClient = &http.Client{
		Timeout: c.requestTimeout() * time.Second,
	}

	return &cfg
}
开发者ID:koding,项目名称:koding,代码行数:13,代码来源:schema.go

示例4: main

func main() {
	config := marathon.NewDefaultConfig()
	config.URL = marathonURL
	client, err := marathon.NewClient(config)
	if err != nil {
		log.Fatalf("Make new marathon client error: %v", err)
	}

	app := marathon.Application{}
	app.ID = "queue-test"
	app.Command("sleep 5")
	app.Count(1)
	app.Memory(32)
	fmt.Println("Creating/updating app.")
	// Update application will either create or update the app.
	_, err = client.UpdateApplication(&app, false)
	if err != nil {
		log.Fatalf("Update application error: %v", err)
	}
	// wait until marathon will launch tasks
	err = client.WaitOnApplication(app.ID, 10*time.Second)
	if err != nil {
		log.Fatalln("Application deploy failure, timeout.")
	}
	fmt.Println("Application was deployed.")

	// get marathon queue by chance
	for i := 0; i < 30; i++ {
		// Avoid shadowing err from outer scope.
		var queue *marathon.Queue
		queue, err = client.Queue()
		if err != nil {
			log.Fatalf("Get queue error: %v\n", err)
		}
		if len(queue.Items) > 0 {
			fmt.Println(queue)
			break
		}
		fmt.Printf("Queue is blank now, retry(%d)...\n", 30-i)
		time.Sleep(time.Second)
	}

	// delete marathon queue delay
	err = client.DeleteQueueDelay(app.ID)
	if err != nil {
		log.Fatalf("Delete queue delay error: %v\n", err)
	}
	fmt.Println("Queue delay deleted.")

	return
}
开发者ID:latam-airlines,项目名称:mesos-framework-factory,代码行数:51,代码来源:main.go

示例5: initMarathonClient

// getMarathonClient connects to mesos cluster
// returns marathon interface like tasks, applications
// groups, deployment, subscriptions, ...
func initMarathonClient() marathon.Marathon {
	config := marathon.NewDefaultConfig()
	chimpConfig := conf.New()
	config.URL = chimpConfig.Endpoint
	if chimpConfig.MarathonAuth.Enabled {
		config.HTTPBasicAuthUser = chimpConfig.MarathonAuth.MarathonHttpUser
		config.HTTPBasicPassword = chimpConfig.MarathonAuth.MarathonHttpPassword
	}
	client, err := marathon.NewClient(config)
	if err != nil {
		glog.Fatalf("Failed to create a client for marathon, error: %s", err)
	}
	return client
}
开发者ID:zalando,项目名称:chimp,代码行数:17,代码来源:marathon.go

示例6: New

// New creates a new Adapter.
func New(marathonURL string) (*Adapter, error) {
	config := marathonClient.NewDefaultConfig()
	config.URL = marathonURL
	config.EventsTransport = marathonClient.EventsTransportSSE

	log.WithField("prefix", "marathon").Infof("Connecting to Marathon at %v", marathonURL)
	client, err := marathonClient.NewClient(config)
	if err != nil {
		return nil, err
	}

	return &Adapter{
		client:   client,
		resolver: &defaultAddressResolver{},
	}, nil
}
开发者ID:x-cray,项目名称:marathon-registrator,代码行数:17,代码来源:marathon_adapter.go

示例7: main

func main() {
	flag.Parse()
	config := marathon.NewDefaultConfig()
	config.URL = marathon_url
	config.LogOutput = os.Stdout
	config.EventsPort = marathon_port
	config.EventsInterface = marathon_interface
	glog.Infof("Creating a client Marathon: %s", marathon_url)

	client, err := marathon.NewClient(config)
	Assert(err)

	/* step: lets register for events */
	events := make(marathon.EventsChannel, 5)
	deployments := make(marathon.EventsChannel, 5)
	Assert(client.AddEventsListener(events, marathon.EVENTS_APPLICATIONS))
	Assert(client.AddEventsListener(deployments, marathon.EVENT_DEPLOYMENT_STEP_SUCCESS))

	// lets listen for 10 seconds and then split
	timer := time.After(time.Duration(timeout) * time.Second)
	kill_off := false
	for {
		if kill_off {
			break
		}
		select {
		case <-timer:
			glog.Infof("Exitting the loop")
			kill_off = true
		case event := <-events:
			glog.Infof("Recieved application event: %s", event)
		case event := <-deployments:
			glog.Infof("Recieved deployment event: %v", event)
			var deployment *marathon.EventDeploymentStepSuccess
			deployment = event.Event.(*marathon.EventDeploymentStepSuccess)
			glog.Infof("deployment step:: %v", deployment.CurrentStep)
		}
	}

	glog.Infof("Removing our subscription")
	client.RemoveEventsListener(events)
	client.RemoveEventsListener(deployments)

	Assert(client.UnSubscribe())
}
开发者ID:abraithwaite,项目名称:zoidberg,代码行数:45,代码来源:main.go

示例8: main

func main() {
	flag.Parse()
	config := marathon.NewDefaultConfig()
	config.URL = marathonURL
	client, err := marathon.NewClient(config)
	if err != nil {
		glog.Fatalf("Failed to create a client for marathon, error: %s", err)
	}
	for {
		if application, err := client.Applications(nil); err != nil {
			glog.Errorf("Failed to retrieve a list of applications, error: %s", err)
		} else {
			glog.Infof("Retrieved a list of applications, %v", application)
		}
		glog.Infof("Going to sleep for 20 seconds")
		time.Sleep(5 * time.Second)
	}
}
开发者ID:Raffo,项目名称:go-marathon,代码行数:18,代码来源:main.go

示例9: appList

func appList(cmd *cli.Cmd) {

	cmd.Action = func() {

		output := tm.NewTable(0, 5, 2, ' ', 0)

		config := marathon.NewDefaultConfig()
		config.URL = *marathonHost
		client, err := marathon.NewClient(config)

		if err != nil {
			panic(err)
		}

		applications, err := client.Applications(nil)

		if err != nil {
			panic(err)
		}

		for i, application := range applications.Apps {

			color := chalk.White
			health := ""

			if i != 0 {
				fmt.Fprint(output, "\n")
			}

			if application.HasHealthChecks() {
				if healthy, _ := client.ApplicationOK(application.ID); healthy {
					color = chalk.Green
					health = "Ok"
				} else {
					color = chalk.Red
					health = "Failing"
				}
			}
			fmt.Fprintf(output, "%s%s \t %d/%d/%d \t%s%s", color, application.ID, application.TasksRunning, application.TasksStaged, application.Instances, health, chalk.Reset)
		}
		tm.Print(output)
		tm.Flush()
	}
}
开发者ID:jmprusi,项目名称:mrthn,代码行数:44,代码来源:mrthn.go

示例10: main

func main() {
	flag.Parse()
	config := marathon.NewDefaultConfig()
	config.URL = marathonURL
	config.LogOutput = new(logBridge)
	client, err := marathon.NewClient(config)
	if err != nil {
		glog.Exitln(err)
	}

	applications, err := client.Applications(nil)
	if err != nil {
		glog.Exitln(err)
	}

	for _, a := range applications.Apps {
		glog.Infof("App ID: %v\n", a.ID)
	}
}
开发者ID:latam-airlines,项目名称:mesos-framework-factory,代码行数:19,代码来源:main.go

示例11: Deploy

//Deploy deploys the marathon app
func (dep *MarathonDeployer) Deploy(jsonContent []byte) (*ExpectedDeployment, error) {
	if app, err := parseContent(jsonContent); err == nil {
		config := marathon.NewDefaultConfig()
		config.URL = dep.URL
		config.LogOutput = os.Stdout
		if client, err := marathon.NewClient(config); err == nil {
			if alreadyExists, err := client.HasApplication(app.ID); err == nil && alreadyExists {
				return updateApplication(client, app)
			} else if err == nil && !alreadyExists {
				return createNewApplication(client, app)
			} else {
				return nil, err
			}

		} else {

			glog.Fatalf("Failed to create a client for marathon, error: %s", err)
			return nil, err
		}

	}
	return nil, nil
}
开发者ID:bhameyie,项目名称:dpipeliner,代码行数:24,代码来源:upload.go

示例12: MarathonClient

func MarathonClient(marathonAddress string) (marathon.Marathon, error) {
	conf := marathon.NewDefaultConfig()
	conf.URL = fmt.Sprintf("http://%s", marathonAddress)
	conf.LogOutput = os.Stderr
	return marathon.NewClient(conf)
}
开发者ID:kulikov,项目名称:serve,代码行数:6,代码来源:marathon.go

示例13: main

func main() {
	flag.Parse()
	config := marathon.NewDefaultConfig()
	config.URL = marathon_url
	config.LogOutput = os.Stdout
	client, err := marathon.NewClient(config)
	Assert(err)
	applications, err := client.Applications(nil)
	Assert(err)

	glog.Infof("Found %d application running", len(applications.Apps))
	for _, application := range applications.Apps {
		glog.Infof("Application: %s", application)
		details, err := client.Application(application.ID)
		Assert(err)
		if details.Tasks != nil && len(details.Tasks) > 0 {
			for _, task := range details.Tasks {
				glog.Infof("task: %s", task)
			}
			health, err := client.ApplicationOK(details.ID)
			Assert(err)
			glog.Infof("Application: %s, healthy: %t", details.ID, health)
		}
	}

	APPLICATION_NAME := "/my/product"

	if found, _ := client.HasApplication(APPLICATION_NAME); found {
		deployId, err := client.DeleteApplication(APPLICATION_NAME)
		Assert(err)
		waitOnDeployment(client, deployId)
	}

	glog.Infof("Deploying a new application")
	application := marathon.NewDockerApplication()
	application.Name(APPLICATION_NAME)
	application.CPU(0.1).Memory(64).Storage(0.0).Count(2)
	application.Arg("/usr/sbin/apache2ctl").Arg("-D").Arg("FOREGROUND")
	application.AddEnv("NAME", "frontend_http")
	application.AddEnv("SERVICE_80_NAME", "test_http")
	application.RequirePorts = true
	application.Container.Docker.Container("quay.io/gambol99/apache-php:latest").Expose(80).Expose(443)
	_, err = client.CreateApplication(application)
	Assert(err)

	glog.Infof("Scaling the application to 4 instances")
	deployId, err := client.ScaleApplicationInstances(application.ID, 4, false)
	Assert(err)
	client.WaitOnApplication(application.ID, 30*time.Second)
	glog.Infof("Successfully scaled the application, deployId: %s", deployId.DeploymentID)

	glog.Infof("Deleting the application: %s", APPLICATION_NAME)
	deployId, err = client.DeleteApplication(application.ID)
	Assert(err)
	time.Sleep(time.Duration(10) * time.Second)
	glog.Infof("Successfully deleted the application")

	glog.Infof("Starting the application again")
	_, err = client.CreateApplication(application)
	Assert(err)
	glog.Infof("Created the application: %s", application.ID)

	glog.Infof("Delete all the tasks")
	_, err = client.KillApplicationTasks(application.ID, "", false)
	Assert(err)
}
开发者ID:elliot,项目名称:go-marathon,代码行数:66,代码来源:main.go

示例14: appInfo

func appInfo(cmd *cli.Cmd) {
	cmd.Spec = "NAME"
	var (
		name = cmd.StringArg("NAME", "", "")
	)
	cmd.Action = func() {

		config := marathon.NewDefaultConfig()
		config.URL = *marathonHost
		client, err := marathon.NewClient(config)

		if err != nil {
			fmt.Print("Can't connect to marathon\n")
			os.Exit(1)
		}

		application, err := client.Application(*name)
		if err != nil {
			fmt.Print("Application doesn't exists\n")
			os.Exit(1)
		}
		output := tm.NewTable(0, 2, 1, ' ', 0)
		//output := os.Stdout
		fmt.Fprint(output, "\n")
		fmt.Fprintf(output, "Application Name: \t\"%s\"\n", application.ID)
		fmt.Fprintf(output, "Running/Staged/Failing/Requested: \t%d/%d/%d/%d\n", application.TasksRunning, application.TasksStaged, application.TasksUnhealthy, application.Instances)
		if application.TasksRunning > 0 {
			fmt.Fprint(output, "\nRunning tasks:\n")
			for _, task := range application.Tasks {
				if application.HasHealthChecks() {
					var alive bool
					for _, result := range task.HealthCheckResult {
						alive = result.Alive
					}
					// TODO: Support multiple ports
					if alive {
						fmt.Fprintf(output, "%s  - %s:%d \t Ok%s\n", chalk.Green, task.Host, task.Ports[0], chalk.Reset)
					} else {
						fmt.Fprintf(output, "%s  - %s:%d \t Failing%s\n", chalk.Red, task.Host, task.Ports[0], chalk.Reset)
					}
				} else {
					fmt.Fprintf(output, "  - %s:%d\n", task.Host, task.Ports[0])
				}
			}
		} else {
			fmt.Fprint(output, "  - Exposed ports: \tNo\n")
		}
		fmt.Fprint(output, "\nHealthcheck Information:\n")
		fmt.Fprintf(output, "  - Has Healthcheck? : \t%t\n", application.HasHealthChecks())
		if application.HasHealthChecks() {
			if healthy, _ := client.ApplicationOK(application.ID); healthy {
				fmt.Fprintf(output, "  - Healthcheck Status: \t%sOk%s\n", chalk.Green, chalk.Reset)
			} else {
				fmt.Fprintf(output, "  - Healthcheck Status: \t%sFailing%s\n", chalk.Red, chalk.Reset)
			}
			for i, healthcheck := range application.HealthChecks {
				fmt.Fprintf(output, "\nHealthcheck num: %d\n", i+1)
				fmt.Fprintf(output, "  - Protocol: \t%s\n", healthcheck.Protocol)
				if healthcheck.Protocol == "COMMAND" {
					fmt.Fprintf(output, "  - Command: \t%s\n", healthcheck.Command.Value)
				} else {
					fmt.Fprintf(output, "  - Path: \t%s\n", healthcheck.Path)
				}
				fmt.Fprintf(output, "  - Grace period seconds: \t%ds\n", healthcheck.GracePeriodSeconds)
				fmt.Fprintf(output, "  - Interval: \t%ds\n", healthcheck.IntervalSeconds)
				fmt.Fprintf(output, "  - Timeout: \t%ds\n", healthcheck.TimeoutSeconds)
				fmt.Fprintf(output, "  - Max consecutive failures: \t%d\n", healthcheck.MaxConsecutiveFailures)
			}
		}
		tm.Print(output)
		tm.Flush()
		output = tm.NewTable(0, 2, 1, ' ', 0)
		taskRunningF := float64(application.TasksRunning)

		fmt.Fprint(output, "Per instance limits:\n")
		fmt.Fprintf(output, "  - CPU shares: \t%.1f \t(%.1f)\n", application.CPUs, application.CPUs*taskRunningF)
		fmt.Fprintf(output, "  - Memory: \t%.1f \t(%.1f)\n", application.Mem, application.Mem*taskRunningF)
		fmt.Fprintf(output, "  - Disk: \t%.1f \t(%.1f)\n", application.Disk, application.Disk*taskRunningF)
		fmt.Fprint(output, "\nUpgrade strategy:\n")
		fmt.Fprintf(output, "  - Maximum over capacity: \t%3.f%% \n", application.UpgradeStrategy.MaximumOverCapacity*100)
		fmt.Fprintf(output, "  - Minimum health capacity: \t%3.f%% \n", application.UpgradeStrategy.MinimumHealthCapacity*100)
		fmt.Fprint(output, "\nEnv vars:\n")
		for k := range application.Env {
			fmt.Fprintf(output, "  - %s = \"%s\" \n", k, application.Env[k])
		}
		tm.Print(output)
		tm.Flush()
	}
}
开发者ID:jmprusi,项目名称:mrthn,代码行数:89,代码来源:mrthn.go

示例15: appUpdate

func appUpdate(cmd *cli.Cmd) {
	cmd.Spec = "NAME [--instances=<num> | --cpu=<num> |--mem=<num> | --docker-image=<image>]"
	// healthCheckCMD  = cmd.StringOpt("command-healthcheck", "", "Command to use as healthcheck")
	// healthCheckHTTP = cmd.StringOpt("http-healthcheck", "", "HTTP path to use as healthcheck")
	// healthCheckTCP  = cmd.IntOpt("tcp-healthcheck", -1, "TCP port to use as healthcheck")
	var (
		instances   = cmd.IntOpt("instances", 0, "Number of instances")
		dockerImage = cmd.StringOpt("docker-image", "", "Docker image and version")
		cpu         = cmd.StringOpt("cpu", "", "cpu shares")
		mem         = cmd.StringOpt("mem", "", "memory mb limit")
		name        = cmd.StringArg("NAME", "", "Application name")
	)

	cmd.Action = func() {
		config := marathon.NewDefaultConfig()
		config.URL = *marathonHost
		client, err := marathon.NewClient(config)
		application, err := client.Application(*name)
		application.Version = ""
		output := tm.NewTable(0, 2, 1, ' ', 0)

		// if *healthCheckCMD != "" {
		//
		// }
		//
		// if *healthCheckHTTP != "" {
		//
		// }
		//
		// if *healthCheckTCP != -1 {
		//
		// }

		if *dockerImage != "" {
			fmt.Fprintf(output, "Setting new docker image:\t %s \t-> %s\n", application.Container.Docker.Image, *dockerImage)
			application.Container.Docker.Container(*dockerImage)
		}

		if *cpu != "" {
			cpuFloat, _ := strconv.ParseFloat(*cpu, 64)
			fmt.Fprintf(output, "Setting new cpu limits:\t %.3f \t-> %.3f\n", application.CPUs, cpuFloat)
			application.CPU(cpuFloat)
			if err != nil {
				panic(err)
			}
		}

		if *mem != "" {
			memFloat, _ := strconv.ParseFloat(*mem, 64)
			fmt.Fprintf(output, "Setting new memory limits:\t %.1f \t-> %.1f\n", application.Mem, memFloat)
			application.Memory(memFloat)
			if err != nil {
				panic(err)
			}
		}

		if *instances != 0 {
			fmt.Fprintf(output, "Setting new number of instances:\t %d \t-> %d\n", application.Instances, *instances)
			application.Count(*instances)
		}

		deployment, err := client.UpdateApplication(application)

		if err != nil {
			panic(err)
		}

		tm.Print(output)
		tm.Flush()
		fmt.Fprintf(os.Stdout, "Starting deployment: %s\n", deployment.DeploymentID)
		client.WaitOnApplication(application.ID, 60*time.Second)
		fmt.Println("Application deployed!")
	}
}
开发者ID:jmprusi,项目名称:mrthn,代码行数:74,代码来源:mrthn.go


注:本文中的github.com/gambol99/go-marathon.NewDefaultConfig函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。