Пример #1
0
func main() {
	flag.Parse()
	name := getNameArgument()
	switch *action {
	case "types":
		git := getGitRegistry()
		types, err := git.List()
		if err != nil {
			log.Fatalf("Cannot list %v err")
		}
		log.Printf("Types:")
		for _, t := range types {
			log.Printf("%s:%s", t.Name, t.Version)
			downloadURL, err := git.GetURL(t)
			if err != nil {
				log.Printf("Failed to get download URL for type %s:%s", t.Name, t.Version)
			}
			log.Printf("\tdownload URL: %s", downloadURL)
		}

	case "expand":
		backend := expander.NewExpander(*binary)
		template := loadTemplate(name)
		output, err := backend.ExpandTemplate(template)
		if err != nil {
			log.Fatalf("cannot expand %s: %s\n", name, err)
		}

		fmt.Println(output)
	case "deploy":
		callService("deployments", "POST", name, readTemplate(name))
	case "list":
		callService("deployments", "GET", name, nil)
	case "get":
		path := fmt.Sprintf("deployments/%s", name)
		callService(path, "GET", name, nil)
	case "delete":
		path := fmt.Sprintf("deployments/%s", name)
		callService(path, "DELETE", name, nil)
	case "update":
		path := fmt.Sprintf("deployments/%s", name)
		callService(path, "PUT", name, readTemplate(name))
	case "listtypes":
		callService("types", "GET", name, nil)
	case "listtypeinstances":
		path := fmt.Sprintf("types/%s/instances", url.QueryEscape(name))
		callService(path, "GET", name, nil)
	}
}
Пример #2
0
func main() {
	flag.Parse()
	backend := expander.NewExpander(*expansionBinary)
	wrapper := service.NewService(service.NewExpansionHandler(backend))
	address := fmt.Sprintf(":%d", *port)
	container := restful.DefaultContainer
	server := &http.Server{
		Addr:    address,
		Handler: container,
	}

	wrapper.Register(container)
	log.Printf("Version: %s", version.DeploymentManagerVersion)
	log.Printf("Listening on %s...", address)
	log.Fatal(server.ListenAndServe())
}
Пример #3
0
func TestServiceWrapper(t *testing.T) {
	backend := expander.NewExpander("../expansion/expansion.py")
	wrapper := NewService(NewExpansionHandler(backend))
	container := restful.NewContainer()
	container.ServeMux = http.NewServeMux()
	wrapper.Register(container)
	handlerTester := util.NewHandlerTester(container)
	for _, swtc := range ServiceWrapperTestCases {
		reader := GetTemplateReader(t, swtc.Description, inputFileName)
		w, err := handlerTester(swtc.HTTPMethod, swtc.ServiceURLPath, swtc.ContentType, reader)
		if err != nil {
			t.Errorf("error in test case '%s': %s\n", swtc.Description, err)
		}

		if w.Code != http.StatusOK {
			if w.Code != swtc.StatusCode {
				message := fmt.Sprintf("test returned code:%d, status: %s", w.Code, w.Body.String())
				t.Errorf("error in test case '%s': %s\n", swtc.Description, message)
			}
		} else {
			if swtc.StatusCode != http.StatusOK {
				t.Errorf("expected error did not occur in test case '%s': want: %d have: %d\n",
					swtc.Description, swtc.StatusCode, w.Code)
			}

			body := w.Body.Bytes()
			actualResponse := &expander.ExpansionResponse{}
			if err := json.Unmarshal(body, actualResponse); err != nil {
				t.Errorf("error in test case '%s': %s\n", swtc.Description, err)
			}

			actualResult, err := actualResponse.Unmarshal()
			if err != nil {
				t.Errorf("error in test case '%s': %s\n", swtc.Description, err)
			}

			expectedOutput := GetOutputString(t, swtc.Description)
			expectedResult := expandOutputOrDie(t, expectedOutput, swtc.Description)

			if !reflect.DeepEqual(expectedResult, actualResult) {
				message := fmt.Sprintf("want: %s\nhave: %s\n",
					util.ToYAMLOrError(expectedResult), util.ToYAMLOrError(actualResult))
				t.Errorf("error in test case '%s':\n%s\n", swtc.Description, message)
			}
		}
	}
}
Пример #4
0
func main() {
	flag.Parse()
	args := flag.Args()
	if len(args) < 1 {
		fmt.Fprintln(os.Stderr, "No command supplied")
		usage()
	}

	if *stdin {
		fmt.Printf("reading from stdin is not yet implemented")
		os.Exit(0)
	}

	command := args[0]
	switch command {
	case "templates":
		git := getGitRegistry()
		templates, err := git.List()
		if err != nil {
			log.Fatalf("Cannot list %v", err)
		}

		fmt.Printf("Templates:\n")
		for _, t := range templates {
			fmt.Printf("%s:%s\n", t.Name, t.Version)
			downloadURL, err := git.GetURL(t)
			if err != nil {
				log.Printf("Failed to get download URL for template %s:%s", t.Name, t.Version)
			}

			fmt.Printf("\tdownload URL: %s\n", downloadURL)
		}
	case "describe":
		fmt.Printf("the describe feature is not yet implemented")
	case "expand":
		backend := expander.NewExpander(*binary)
		template := loadTemplate(args)
		output, err := backend.ExpandTemplate(template)
		if err != nil {
			log.Fatalf("cannot expand %s: %s\n", template.Name, err)
		}

		fmt.Println(output)
	case "deploy":
		template := loadTemplate(args)
		action := fmt.Sprintf("deploy configuration named %s", template.Name)
		callService("deployments", "POST", action, marshalTemplate(template))
	case "list":
		callService("deployments", "GET", "list deployments", nil)
	case "get":
		if len(args) < 2 {
			fmt.Fprintln(os.Stderr, "No deployment name supplied")
			usage()
		}

		path := fmt.Sprintf("deployments/%s", args[1])
		action := fmt.Sprintf("get deployment named %s", args[1])
		callService(path, "GET", action, nil)
	case "delete":
		if len(args) < 2 {
			fmt.Fprintln(os.Stderr, "No deployment name supplied")
			usage()
		}

		path := fmt.Sprintf("deployments/%s", args[1])
		action := fmt.Sprintf("delete deployment named %s", args[1])
		callService(path, "DELETE", action, nil)
	case "update":
		template := loadTemplate(args)
		path := fmt.Sprintf("deployments/%s", template.Name)
		action := fmt.Sprintf("delete deployment named %s", template.Name)
		callService(path, "PUT", action, marshalTemplate(template))
	case "deployed-types":
		callService("types", "GET", "list deployed types", nil)
	case "deployed-instances":
		if len(args) < 2 {
			fmt.Fprintln(os.Stderr, "No type name supplied")
			usage()
		}

		path := fmt.Sprintf("types/%s/instances", url.QueryEscape(args[1]))
		action := fmt.Sprintf("list deployed instances of type %s", args[1])
		callService(path, "GET", action, nil)
	default:
		usage()
	}
}