Example #1
0
func appGet(c echo.Context) error {

	ty := c.QueryParam("type")
	var returnValue proto.Message
	var err error
	var Region = c.QueryParam("region")

	if ty == "value" { // 获取单个应用信息
		args := new(types.GetParams)
		app := new(types.App)
		returnValue = app
		args.Region = Region
		args.Id = c.QueryParam("id")
		err = appHandler.Get(args, app)
	} else { // 获取应用列表
		args := new(types.ListParams)
		applist := new(types.AppList)
		returnValue = applist
		args.Region = Region
		args.Offset = 0  // 列表偏移量
		args.Length = 10 // 列表长度
		err = appHandler.List(args, applist)
	}

	// 获取数据失败
	if err != nil {
		return SendData(c, http.StatusNotFound, returnValue)
	}

	return SendData(c, http.StatusOK, returnValue)
}
Example #2
0
func podGet(c echo.Context) error {

	var arg = new(types.GetParams)
	arg.Region = c.QueryParam("region")
	arg.ParentId = c.QueryParam("appid")
	arg.Id = c.QueryParam("id")
	var pod = new(types.Pod)

	err := podHandler.Get(arg, pod)
	if err != nil {
		return SendData(c, http.StatusNotFound, pod)
	}
	return SendData(c, http.StatusOK, pod)
}
Example #3
0
func TestAppTempGet(t *testing.T) {
	Init()
	arg := new(types.GetParams)
	arg.Id = "redis"
	arg.Region = ""
	app := new(types.App)

	appTempHandler := AppTempHandler{}

	err := appTempHandler.Get(arg, app)
	if err != nil {
		t.Error("AppHandler get err:", err)
	}
}
Example #4
0
func appTempGet(c echo.Context) error {

	args := new(types.GetParams)
	app := new(types.App)

	args.Region = c.QueryParam("region")

	if args.Region == "" {
		args.Region = types.DefaultRegion
	}

	args.Id = c.QueryParam("id")
	err := appTempHandler.Get(args, app)
	// 获取数据失败
	if err != nil {
		return c.String(http.StatusNotFound, "")
	}
	return SendData(c, http.StatusOK, app)
}
Example #5
0
func main() {
	cli, err := protorpc.Dial("tcp", "127.0.0.1:1235")

	if err != nil {
		fmt.Println(err)
	}

	defer cli.Close()

	args := &types.Pod{}
	args.Name = "woyun2"
	args.ParentId = "default"
	args.Containers = []*types.Container{
		&types.Container{
			Name:  "redis",
			Image: "hub.asyou.me/gitlab/redis",
			Port: []*types.ContainerPort{
				&types.ContainerPort{
					Name:          "redis",
					ContainerPort: 6379,
				},
			},
		},
	}
	reply := new(types.Event)

	err = cli.Call("Pod.Post", args, reply)
	if err != nil {
		fmt.Println("Pod.Post: expected no error but got string %q", err.Error())
	} else {
		fmt.Println("Pod.Post: PASS")
	}

	err = cli.Call("Pod.Get", args, args)
	if err != nil {
		fmt.Println("Pod.Get: expected no error but got string %q", err.Error())
	} else {
		fmt.Println("Pod.Get: PASS")
		fmt.Println(args)
	}

	/*args.ParentId = "default"
	err = cli.Call("Pod.Put", args, reply)
	if err != nil {
		fmt.Println("Pod.Put error : ", err.Error())
	} else {
		fmt.Println("Pod.Put: PASS")
	}*/

	list_args := &types.ListParams{}
	list_args.ParentId = "default"
	list_reply := &types.PodList{}
	err = cli.Call("Pod.List", list_args, list_reply)
	if err != nil {
		fmt.Println("Pod.List: expected no error but got string %q", err.Error())
	} else {
		fmt.Println("Pod.List: PASS")
		fmt.Println(list_reply)
	}

	args2 := &types.DeleteParams{}
	args2.Id = "woyun2"
	args2.ParentId = "default"
	reply2 := new(types.Event)

	err = cli.Call("Pod.Delete", args2, reply2)
	if err != nil {
		fmt.Println("Pod.Delete: error %q", err.Error())
	} else {
		fmt.Println("Pod.Delete: PASS")
	}

	args3 := new(types.GetParams)
	args3.Id = "222"
	reply3 := new(types.App)
	err = cli.Call("AppTemp.Get", args3, reply3)
	if err != nil {
		fmt.Println("AppTemp.Get: error %q", err.Error())
	} else {
		fmt.Println("AppTemp.Get: PASS")
		fmt.Println(reply3)
	}

	time.Sleep(5 * time.Second)
}