예제 #1
0
// @Title get
// @Description get all services
// @Success 200 {string} []Service
// @Failure 404 error reason
// @router / [get]
func (c *ListController) Get() {
	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	namespace := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/services/" + namespace

	serviceSlice := make([]Service, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &serviceSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = serviceSlice
		c.ServeJSON()
	}
}
예제 #2
0
// @Title get
// @Description get the autoscaler
// @Param kind path string true "The type of target autoscaler configured for"
// @Param name path string true "The name of target autoscaler configured for"
// @Success 200 {object} guirestapi.deploy.autoscaler.ReplicationControllerAutoScaler
// @Failure 404 error reason
// @router /:kind/:name [get]
func (c *EditController) Get() {
	kind := c.GetString(":kind")
	name := c.GetString(":name")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	namespace, _ := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/autoscalers/" + namespace + "/" + kind + "/" + name

	replicationControllerAutoScaler := ReplicationControllerAutoScaler{}

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &replicationControllerAutoScaler, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = replicationControllerAutoScaler
		c.ServeJSON()
	}
}
예제 #3
0
// @Title get
// @Description get the cluster application template
// @Param name path string true "The name of cluster application template"
// @Success 200 {object} guirestapi.repository.thirdparty.Cluster
// @Failure 404 error reason
// @router /launchinformation/:name [get]
func (c *LaunchController) Get() {
	name := c.GetString("name")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/clusterapplications/" + name
	cluster := Cluster{}

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &cluster, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		c.Data["json"] = cluster
		c.ServeJSON()
	}
}
예제 #4
0
func (c *EditController) Get() {
	c.TplName = "system/host/credential/edit.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	ip := c.GetString("ip")

	if ip == "" {
		c.Data["actionButtonValue"] = "Create"
		c.Data["pageHeader"] = "Create Host Credential"
		c.Data["createOrUpdate"] = "create"
		c.Data["fieldDisabledChecked"] = ""

		c.Data["sshPort"] = 22
	} else {
		cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
		cloudoneHost := beego.AppConfig.String("cloudoneHost")
		cloudonePort := beego.AppConfig.String("cloudonePort")

		url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
			"/api/v1/hosts/credentials/" + ip

		credential := Credential{}

		tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

		_, err := restclient.RequestGetWithStructure(url, &credential, tokenHeaderMap)

		if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
			return
		}

		if err != nil {
			// Error
			guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
			guimessage.OutputMessage(c.Data)
			return
		}

		c.Data["actionButtonValue"] = "Update"
		c.Data["pageHeader"] = "Update Host Credential"
		c.Data["createOrUpdate"] = "update"

		c.Data["ip"] = credential.IP
		c.Data["sshPort"] = credential.SSH.Port
		c.Data["sshUser"] = credential.SSH.User
		c.Data["sshPassword"] = credential.SSH.Password
		if credential.Disabled {
			c.Data["fieldDisabledChecked"] = "checked"
		} else {
			c.Data["fieldDisabledChecked"] = ""
		}

		c.Data["ipFieldReadOnly"] = "readonly"
	}

	guimessage.OutputMessage(c.Data)
}
예제 #5
0
func (c *ListController) Get() {
	c.TplName = "repository/thirdparty/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiRepositoryThirdPartyEdit", user, "GET", "/gui/repository/thirdparty/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiRepositoryThirdPartyLaunch := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/thirdparty/launch")
	hasGuiRepositoryThirdPartyEdit := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/thirdparty/edit")
	hasGuiRepositoryThirdPartyDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/thirdparty/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/clusterapplications/"

	thirdPartyApplicationSlice := make([]ThirdPartyApplication, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &thirdPartyApplicationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(thirdPartyApplicationSlice); i++ {
			if hasGuiRepositoryThirdPartyLaunch {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyLaunch = "<div class='btn-group'>"
			} else {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyLaunch = "<div hidden>"
			}
			if hasGuiRepositoryThirdPartyEdit {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyEdit = "<div class='btn-group'>"
			} else {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyEdit = "<div hidden>"
			}
			if hasGuiRepositoryThirdPartyDelete {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyDelete = "<div class='btn-group'>"
			} else {
				thirdPartyApplicationSlice[i].HiddenTagGuiRepositoryThirdPartyDelete = "<div hidden>"
			}
		}

		sort.Sort(ByThirdPartyApplication(thirdPartyApplicationSlice))
		c.Data["thirdPartyApplicationSlice"] = thirdPartyApplicationSlice
	}

	guimessage.OutputMessage(c.Data)
}
예제 #6
0
func (c *ListController) Get() {
	c.TplName = "deploy/deploybluegreen/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	// Tag won't work in loop so need to be placed in data
	hasGuiDeployDeployBlueGreenSelect := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploybluegreen/select")
	hasGuiDeployDeployBlueGreenDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/deploy/deploybluegreen/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploybluegreens/"

	deployBlueGreenSlice := make([]DeployBlueGreen, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &deployBlueGreenSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(deployBlueGreenSlice); i++ {
			if deployBlueGreenSlice[i].NodePort == 0 {
				deployBlueGreenSlice[i].NodePortDisplay = "Auto-generated"
			} else {
				deployBlueGreenSlice[i].NodePortDisplay = strconv.Itoa(deployBlueGreenSlice[i].NodePort)
			}

			if hasGuiDeployDeployBlueGreenSelect {
				deployBlueGreenSlice[i].HiddenTagGuiDeployDeployBlueGreenSelect = "<div class='btn-group'>"
			} else {
				deployBlueGreenSlice[i].HiddenTagGuiDeployDeployBlueGreenSelect = "<div hidden>"
			}
			if hasGuiDeployDeployBlueGreenDelete {
				deployBlueGreenSlice[i].HiddenTagGuiDeployDeployBlueGreenDelete = "<div class='btn-group'>"
			} else {
				deployBlueGreenSlice[i].HiddenTagGuiDeployDeployBlueGreenDelete = "<div hidden>"
			}
		}

		sort.Sort(ByDeployBlueGreen(deployBlueGreenSlice))
		c.Data["deployBlueGreenSlice"] = deployBlueGreenSlice
	}

	guimessage.OutputMessage(c.Data)
}
예제 #7
0
func (c *ListController) Get() {
	c.TplName = "filesystem/glusterfs/volume/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiFileSystemGlusterfsClusterList", user, "GET", "/gui/filesystem/glusterfs/cluster/list")
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuifFileSystemGlusterfsVolumeCreate", user, "GET", "/gui/filesystem/glusterfs/volume/create")
	// Tag won't work in loop so need to be placed in data
	hasHiddenTagGuiFileSystemGlusterfsVolumeReset := user.HasPermission(identity.GetConponentName(), "GET", "/gui/filesystem/glusterfs/volume/reset")
	hasHiddenTagGuiFileSystemGlusterfsVolumeDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/filesystem/glusterfs/volume/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	clusterName := c.GetString("clusterName")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/glusterfs/clusters/" + clusterName + "/volumes/"

	glusterfsVolumeSlice := make([]GlusterfsVolume, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &glusterfsVolumeSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(glusterfsVolumeSlice); i++ {
			glusterfsVolumeSlice[i].ClusterName = clusterName

			if hasHiddenTagGuiFileSystemGlusterfsVolumeReset {
				glusterfsVolumeSlice[i].HiddenTagGuiFileSystemGlusterfsVolumeReset = "<div class='btn-group'>"
			} else {
				glusterfsVolumeSlice[i].HiddenTagGuiFileSystemGlusterfsVolumeReset = "<div hidden>"
			}
			if hasHiddenTagGuiFileSystemGlusterfsVolumeDelete {
				glusterfsVolumeSlice[i].HiddenTagGuiFileSystemGlusterfsVolumeDelete = "<div class='btn-group'>"
			} else {
				glusterfsVolumeSlice[i].HiddenTagGuiFileSystemGlusterfsVolumeDelete = "<div hidden>"
			}
		}

		c.Data["glusterfsVolumeSlice"] = glusterfsVolumeSlice
		c.Data["clusterName"] = clusterName
	}

	guimessage.OutputMessage(c.Data)
}
예제 #8
0
func (c *ListController) Get() {
	c.TplName = "system/privateregistry/image/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	serverName := c.GetString("serverName")
	repositoryName := c.GetString("repositoryName")

	c.Data["serverName"] = serverName

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiSystemPrivateRegistryRepositoryList", user, "GET", "/gui/system/privateregistry/repository/list")
	// Tag won't work in loop so need to be placed in data
	hasGuiSystemPrivateRegistryImageDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/privateregistry/image/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/privateregistries/servers/" + serverName + "/repositories/" + repositoryName + "/tags/"

	tagSlice := make([]string, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &tagSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		imageSlice := make([]Image, 0)
		for _, tag := range tagSlice {
			imageSlice = append(imageSlice, Image{tag, serverName, repositoryName, ""})
		}

		for i := 0; i < len(imageSlice); i++ {
			if hasGuiSystemPrivateRegistryImageDelete {
				imageSlice[i].HiddenTagGuiSystemPrivateRegistryImageDelete = "<div class='btn-group'>"
			} else {
				imageSlice[i].HiddenTagGuiSystemPrivateRegistryImageDelete = "<div hidden>"
			}
		}

		sort.Sort(ByImage(imageSlice))
		c.Data["imageSlice"] = imageSlice
	}

	guimessage.OutputMessage(c.Data)
}
예제 #9
0
func (c *ListController) Get() {
	c.TplName = "system/rbac/role/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// System RBAC tab menu
	user, _ := c.GetSession("user").(*rbac.User)
	c.Data["systemRBACTabMenu"] = identity.GetSystemRBACTabMenu(user, "role")
	// Authorization for Button
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiSystemRBACRoleEdit", user, "GET", "/gui/system/rbac/role/edit")
	// Tag won't work in loop so need to be placed in data
	hasGuiSystemRBACRoleEdit := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/rbac/role/edit")
	hasGuiSystemRBACRoleDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/system/rbac/role/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/authorizations/roles"

	simplifiedRoleSlice := make([]SimplifiedRole, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &simplifiedRoleSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for i := 0; i < len(simplifiedRoleSlice); i++ {
			if hasGuiSystemRBACRoleEdit {
				simplifiedRoleSlice[i].HiddenTagGuiSystemRBACRoleEdit = "<div class='btn-group'>"
			} else {
				simplifiedRoleSlice[i].HiddenTagGuiSystemRBACRoleEdit = "<div hidden>"
			}
			if hasGuiSystemRBACRoleDelete {
				simplifiedRoleSlice[i].HiddenTagGuiSystemRBACRoleDelete = "<div class='btn-group'>"
			} else {
				simplifiedRoleSlice[i].HiddenTagGuiSystemRBACRoleDelete = "<div hidden>"
			}
		}

		sort.Sort(BySimplifiedRole(simplifiedRoleSlice))
		c.Data["simplifiedRoleSlice"] = simplifiedRoleSlice
	}

	guimessage.OutputMessage(c.Data)
}
예제 #10
0
func (c *IndexController) Get() {
	c.TplName = "monitor/container/index.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	cloudoneGUIProtocol := beego.AppConfig.String("cloudoneGUIProtocol")
	cloudoneGUIHost, cloudoneGUIPort := dashboard.GetServerHostAndPortFromUserRequest(c.Ctx.Input)

	namespaces, _ := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/replicationcontrollers/" + namespaces

	jsonMapSlice := make([]interface{}, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &jsonMapSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		replicationControllerNameSlice := make([]string, 0)
		replicationControllerNameSlice = append(replicationControllerNameSlice, allKeyword)

		for _, jsonMap := range jsonMapSlice {
			name, _ := jsonMap.(map[string]interface{})["Name"].(string)
			if name != "" {
				replicationControllerNameSlice = append(replicationControllerNameSlice, name)
			}
		}

		c.Data["cloudoneGUIProtocol"] = cloudoneGUIProtocol
		c.Data["cloudoneGUIHost"] = cloudoneGUIHost
		c.Data["cloudoneGUIPort"] = cloudoneGUIPort
		c.Data["replicationControllerNameSlice"] = replicationControllerNameSlice
	}

	guimessage.OutputMessage(c.Data)
}
예제 #11
0
func (c *EditController) Get() {
	c.TplName = "system/privateregistry/server/edit.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	serverName := c.GetString("serverName")

	if serverName == "" {
		c.Data["actionButtonValue"] = "Create"
		c.Data["pageHeader"] = "Create Server Configuration"
		c.Data["createOrUpdate"] = "create"
	} else {
		cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
		cloudoneHost := beego.AppConfig.String("cloudoneHost")
		cloudonePort := beego.AppConfig.String("cloudonePort")

		url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
			"/api/v1/privateregistries/servers/" + serverName

		privateRegistry := PrivateRegistry{}

		tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

		_, err := restclient.RequestGetWithStructure(url, &privateRegistry, tokenHeaderMap)

		if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
			return
		}

		if err != nil {
			// Error
			guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
			guimessage.OutputMessage(c.Data)
			return
		}

		c.Data["actionButtonValue"] = "Update"
		c.Data["pageHeader"] = "Update Server Configuration"
		c.Data["createOrUpdate"] = "update"

		c.Data["name"] = privateRegistry.Name
		c.Data["host"] = privateRegistry.Host
		c.Data["port"] = privateRegistry.Port

		c.Data["nameFieldReadOnly"] = "readonly"
	}

	guimessage.OutputMessage(c.Data)
}
예제 #12
0
// @Title get
// @Description get related information
// @Success 200 {string} {}
// @Failure 404 error reason
// @router /selectinformation [get]
func (c *IndexController) Get() {
	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")
	cloudoneGUIProtocol := beego.AppConfig.String("cloudoneGUIProtocol")
	cloudoneGUIHost, cloudoneGUIPort := dashboard.GetServerHostAndPortFromUserRequest(c.Ctx.Input)

	namespaces, _ := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/replicationcontrollers/" + namespaces

	jsonMapSlice := make([]interface{}, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &jsonMapSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		replicationControllerNameSlice := make([]string, 0)
		replicationControllerNameSlice = append(replicationControllerNameSlice, allKeyword)

		for _, jsonMap := range jsonMapSlice {
			name, _ := jsonMap.(map[string]interface{})["Name"].(string)
			if name != "" {
				replicationControllerNameSlice = append(replicationControllerNameSlice, name)
			}
		}

		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["cloudoneGUIProtocol"] = cloudoneGUIProtocol
		c.Data["json"].(map[string]interface{})["cloudoneGUIHost"] = cloudoneGUIHost
		c.Data["json"].(map[string]interface{})["cloudoneGUIPort"] = cloudoneGUIPort
		c.Data["json"].(map[string]interface{})["replicationControllerNameSlice"] = replicationControllerNameSlice
		c.ServeJSON()
	}
}
예제 #13
0
func (c *SelectController) Get() {
	c.TplName = "deploy/clone/select.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)

	currentNamespace, _ := c.GetSession("namespace").(string)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/namespaces/"

	nameSlice := make([]string, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &nameSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		guimessage.OutputMessage(c.Data)
		return
	}

	namespaceSlice := make([]string, 0)
	for _, name := range nameSlice {
		if user.HasResource(identity.GetConponentName(), "/namespaces/"+name) {
			namespaceSlice = append(namespaceSlice, name)
		}
	}

	c.Data["currentNamespace"] = currentNamespace
	c.Data["namespaceSlice"] = namespaceSlice

	guimessage.OutputMessage(c.Data)

}
예제 #14
0
파일: node.go 프로젝트: cloudawan/cloudone
func GetAllNodeIP(kubeApiServerEndPoint string, kubeApiServerToken string) (returnedIpSlice []string, returnedError error) {
	defer func() {
		if err := recover(); err != nil {
			log.Error("GetAllNodeIP Error: %s", err)
			log.Error(logger.GetStackTrace(4096, false))
			returnedIpSlice = nil
			returnedError = err.(error)
		}
	}()

	jsonMap := make(map[string]interface{})

	headerMap := make(map[string]string)
	headerMap["Authorization"] = kubeApiServerToken

	url := kubeApiServerEndPoint + "/api/v1/nodes/"
	_, err := restclient.RequestGetWithStructure(url, &jsonMap, headerMap)
	if err != nil {
		log.Error(err)
		return nil, err
	}

	ipSlice := make([]string, 0)

	itemSlice, _ := jsonMap["items"].([]interface{})
	for _, item := range itemSlice {
		itemJsonMap, _ := item.(map[string]interface{})
		statusJsonMap, _ := itemJsonMap["status"].(map[string]interface{})
		addressesJsonSlice, _ := statusJsonMap["addresses"].([]interface{})
		address := ""
		for _, value := range addressesJsonSlice {
			addressJsonMap, _ := value.(map[string]interface{})
			addressType, _ := addressJsonMap["type"].(string)
			addressAddress, _ := addressJsonMap["address"].(string)
			if addressType == "InternalIP" {
				address = addressAddress
				break
			}
		}

		if len(address) > 0 {
			ipSlice = append(ipSlice, address)
		}
	}

	return ipSlice, nil
}
예제 #15
0
func (c *CreateController) Get() {
	c.TplName = "filesystem/glusterfs/volume/create.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	clusterName := c.GetString("clusterName")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/glusterfs/clusters/" + clusterName

	glusterfsCluster := cluster.GlusterfsCluster{}

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &glusterfsCluster, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		hostList := ""
		length := len(glusterfsCluster.HostSlice)
		for index, host := range glusterfsCluster.HostSlice {
			if index == length-1 {
				hostList += host
			} else {
				hostList += host + ","
			}
		}

		c.Data["hostSlice"] = glusterfsCluster.HostSlice
		c.Data["clusterName"] = clusterName
		c.Data["hostList"] = hostList
	}

	guimessage.OutputMessage(c.Data)
}
예제 #16
0
// @Title get
// @Description get the related selection in order to create a new deployment
// @Param name path string true "The name of image record"
// @Param oldVersion query string true "The current version to be replaced"
// @Success 200 {string} {}
// @Failure 404 error reason
// @router /updateinformation/:name [get]
func (c *UpdateController) Get() {
	name := c.GetString(":name")
	oldVersion := c.GetString("oldVersion")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/imagerecords/" + name

	imageRecordSlice := make([]ImageRecord, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &imageRecordSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		versionEnvironmentMap := make(map[string]map[string]string)
		versionSlice := make([]string, 0)
		for _, imageRecord := range imageRecordSlice {
			if imageRecord.Version != oldVersion {
				versionSlice = append(versionSlice, imageRecord.Version)
				versionEnvironmentMap[imageRecord.Version] = imageRecord.Environment
			}
		}

		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["name"] = name
		c.Data["json"].(map[string]interface{})["versionSlice"] = versionSlice
		c.Data["json"].(map[string]interface{})["versionEnvironmentMap"] = versionEnvironmentMap
		c.ServeJSON()
	}
}
예제 #17
0
func (c *CreateController) Get() {
	c.TplName = "repository/imageinformation/create.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/privateregistries/servers/"

	privateRegistrySlice := make([]PrivateRegistry, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &privateRegistrySlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		guimessage.RedirectMessage(c)
		c.Ctx.Redirect(302, "/gui/repository/imageinformation/list")
		return
	}

	if len(privateRegistrySlice) == 0 {
		guimessage.AddWarning("At least one private registry is required. Please configure it in system.")
		guimessage.RedirectMessage(c)
		c.Ctx.Redirect(302, "/gui/repository/imageinformation/list")
		return
	}

	c.Data["privateRegistrySlice"] = privateRegistrySlice

	guimessage.OutputMessage(c.Data)
}
func getCache(token string) (*rbac.User, error) {
	// Get from cache first
	user := rbac.GetCache(token)
	if user == nil {
		// Not exist. Ask the authorization server.
		cloudoneProtocol, ok := configuration.LocalConfiguration.GetString("cloudoneProtocol")
		if ok == false {
			log.Error("Unable to get configuration cloudoneProtocol")
			return nil, errors.New("Unable to get configuration cloudoneProtocol")
		}

		cloudoneHost, ok := configuration.LocalConfiguration.GetString("cloudoneHost")
		if ok == false {
			log.Error("Unable to get configuration cloudoneHost")
			return nil, errors.New("Unable to get configuration cloudoneHost")
		}

		cloudonePort, ok := configuration.LocalConfiguration.GetInt("cloudonePort")
		if ok == false {
			log.Error("Unable to get configuration cloudonePort")
			return nil, errors.New("Unable to get configuration cloudonePort")
		}

		url := cloudoneProtocol + "://" + cloudoneHost + ":" + strconv.Itoa(cloudonePort) +
			"/api/v1/authorizations/tokens/" + token + "/components/" + componentName
		user := &rbac.User{}
		_, err := restclient.RequestGetWithStructure(url, &user, nil)
		if err != nil {
			log.Debug(err)
			return nil, err
		} else {
			// Set Cache
			rbac.SetCache(token, user, cacheTTL)
			log.Info("Cache user %s", user.Name)

			return user, nil
		}
	} else {
		return user, nil
	}
}
예제 #19
0
// @Title get
// @Description get all deployments
// @Success 200 {string} []DeployInformation
// @Failure 404 error reason
// @router / [get]
func (c *ListController) Get() {
	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	namespace, _ := c.GetSession("namespace").(string)

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploys/" + namespace

	deployInformationSlice := make([]DeployInformation, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &deployInformationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	} else {
		// Only show those belonging to this namespace
		filteredDeployInformationSlice := make([]DeployInformation, 0)
		for _, deployInformation := range deployInformationSlice {
			filteredDeployInformationSlice = append(filteredDeployInformationSlice, deployInformation)
		}

		c.Data["json"] = filteredDeployInformationSlice
		c.ServeJSON()
	}
}
예제 #20
0
func (c *LogController) Get() {
	c.TplName = "repository/imagerecord/log.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	imageInformation := c.GetString("imageInformation")
	version := c.GetString("version")

	cloudoneAnalysisProtocol := beego.AppConfig.String("cloudoneAnalysisProtocol")
	cloudoneAnalysisHost := beego.AppConfig.String("cloudoneAnalysisHost")
	cloudoneAnalysisPort := beego.AppConfig.String("cloudoneAnalysisPort")

	url := cloudoneAnalysisProtocol + "://" + cloudoneAnalysisHost + ":" + cloudoneAnalysisPort +
		"/api/v1/buildlogs/" + imageInformation + "/" + version

	buildLog := build.BuildLog{}

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &buildLog, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		c.Data["log"] = buildLog.Content
	}

	c.Data["imageInformation"] = imageInformation

	guimessage.OutputMessage(c.Data)
}
예제 #21
0
func (c *ListController) Get() {
	c.TplName = "repository/imagerecord/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	identity.SetPrivilegeHiddenTag(c.Data, "hiddenTagGuiRepositoryImageInformationList", user, "GET", "/gui/repository/imageinformation/list")
	// Tag won't work in loop so need to be placed in data
	hasGuiRepositoryImageRecordLog := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/imagerecord/log")
	hasGuiRepositoryImageRecordDelete := user.HasPermission(identity.GetConponentName(), "GET", "/gui/repository/imagerecord/delete")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	name := c.GetString("name")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/imagerecords/" + name

	imageRecordSlice := make([]ImageRecord, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	returnedJsonMap, err := restclient.RequestGetWithStructure(url, &imageRecordSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		errorJsonMap, _ := returnedJsonMap.(map[string]interface{})
		errorMessage, _ := errorJsonMap["ErrorMessage"].(string)
		if strings.HasPrefix(errorMessage, "100: Key not found") {

		} else {
			// Error
			guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		}
	}

	for i := 0; i < len(imageRecordSlice); i++ {
		if imageRecordSlice[i].Failure {
			imageRecordSlice[i].FieldFailureStyleColor = "red"
		}
		if hasGuiRepositoryImageRecordLog {
			imageRecordSlice[i].HiddenTagGuiRepositoryImageRecordLog = "<div class='btn-group'>"
		} else {
			imageRecordSlice[i].HiddenTagGuiRepositoryImageRecordLog = "<div hidden>"
		}
		if hasGuiRepositoryImageRecordDelete {
			imageRecordSlice[i].HiddenTagGuiRepositoryImageRecordDelete = "<div class='btn-group'>"
		} else {
			imageRecordSlice[i].HiddenTagGuiRepositoryImageRecordDelete = "<div hidden>"
		}
	}

	sort.Sort(ByImageRecord(imageRecordSlice))
	c.Data["imageRecordSlice"] = imageRecordSlice

	guimessage.OutputMessage(c.Data)
}
예제 #22
0
func (c *DataController) Get() {
	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/deploybluegreens/"

	deployBlueGreenSlice := make([]DeployBlueGreen, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &deployBlueGreenSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.ServeJSON()
		return
	}

	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/deploys/"

	deployInformationSlice := make([]DeployInformation, 0)

	_, err = restclient.RequestGetWithStructure(url, &deployInformationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.ServeJSON()
		return
	}

	deployInformationMap := make(map[string]DeployInformation)
	for _, deployInformation := range deployInformationSlice {
		deployInformationMap[deployInformation.ImageInformationName+"-"+deployInformation.Namespace] = deployInformation
	}

	// Json
	c.Data["json"] = make(map[string]interface{})
	c.Data["json"].(map[string]interface{})["bluegreenView"] = make([]interface{}, 0)
	c.Data["json"].(map[string]interface{})["errorMap"] = make(map[string]interface{})

	bluegreenJsonMap := make(map[string]interface{})
	bluegreenJsonMap["name"] = "B/G View"
	bluegreenJsonMap["children"] = make([]interface{}, 0)
	c.Data["json"].(map[string]interface{})["bluegreenView"] = append(c.Data["json"].(map[string]interface{})["bluegreenView"].([]interface{}), bluegreenJsonMap)

	leafAmount := 0
	for _, deployBlueGreen := range deployBlueGreenSlice {
		url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
			"/api/v1/deploybluegreens/deployable/" + deployBlueGreen.ImageInformation

		namespaceSlice := make([]string, 0)

		_, err := restclient.RequestGetWithStructure(url, &namespaceSlice, tokenHeaderMap)

		if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
			return
		}

		if err != nil {
			c.Data["json"].(map[string]interface{})["error"] = "Get deployable namespace data error"
			c.Data["json"].(map[string]interface{})["errorMap"].(map[string]interface{})[deployBlueGreen.ImageInformation] = err.Error()
		} else {
			blueGreenJsonMap := make(map[string]interface{})
			blueGreenJsonMap["name"] = deployBlueGreen.ImageInformation
			blueGreenJsonMap["color"] = dashboard.TextColorBlueGreen
			blueGreenJsonMap["children"] = make([]interface{}, 0)
			for _, namespace := range namespaceSlice {
				deployInformation := deployInformationMap[deployBlueGreen.ImageInformation+"-"+namespace]
				if deployInformation.CurrentVersion == "" {
					c.Data["json"].(map[string]interface{})["error"] = "Get deployInformation data error"
					errorMessage, _ := c.Data["json"].(map[string]interface{})["errorMap"].(map[string]interface{})[deployBlueGreen.ImageInformation].(string)
					c.Data["json"].(map[string]interface{})["errorMap"].(map[string]interface{})[deployBlueGreen.ImageInformation] = errorMessage + " Get deployInformation data from namespace " + namespace + " error"
				} else {
					namespaceJsonMap := make(map[string]interface{})
					namespaceJsonMap["name"] = namespace
					namespaceJsonMap["color"] = dashboard.TextColorNamespace
					namespaceJsonMap["children"] = make([]interface{}, 0)
					deployInformationJsonMap := make(map[string]interface{})
					deployInformationJsonMap["name"] = deployInformation.CurrentVersion + " " + deployInformation.CurrentVersionDescription
					deployInformationJsonMap["color"] = dashboard.TextColorDeployInformation
					if namespace == deployBlueGreen.Namespace {
						deployInformationJsonMap["children"] = make([]interface{}, 0)
						nodePortJsonMap := make(map[string]interface{})
						nodePortJsonMap["name"] = "bg_" + deployBlueGreen.ImageInformation + " " + strconv.Itoa(deployBlueGreen.NodePort)
						nodePortJsonMap["color"] = dashboard.TextColorPort
						deployInformationJsonMap["children"] = append(deployInformationJsonMap["children"].([]interface{}), nodePortJsonMap)
					}
					namespaceJsonMap["children"] = append(namespaceJsonMap["children"].([]interface{}), deployInformationJsonMap)
					blueGreenJsonMap["children"] = append(blueGreenJsonMap["children"].([]interface{}), namespaceJsonMap)
				}
				leafAmount++
			}
			bluegreenJsonMap["children"] = append(bluegreenJsonMap["children"].([]interface{}), blueGreenJsonMap)
		}
	}
	c.Data["json"].(map[string]interface{})["leafAmount"] = leafAmount

	dashboard.RecursiveSortTheDataInGraphJsonMap(c.Data["json"].(map[string]interface{}))

	c.ServeJSON()
}
예제 #23
0
func (c *EditController) Get() {
	c.TplName = "deploy/autoscaler/edit.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	kind := c.GetString("kind")
	name := c.GetString("name")

	c.Data["cpuHidden"] = "hidden"
	c.Data["memoryHidden"] = "hidden"

	if kind == "" || name == "" {
		c.Data["actionButtonValue"] = "Create"
		c.Data["pageHeader"] = "Create Autoscaler"
		c.Data["kind"] = ""
		c.Data["name"] = ""
		c.Data["readonly"] = ""
		c.Data["maximumReplica"] = 1
		c.Data["minimumReplica"] = 1
	} else {
		namespace, _ := c.GetSession("namespace").(string)

		cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
		cloudoneHost := beego.AppConfig.String("cloudoneHost")
		cloudonePort := beego.AppConfig.String("cloudonePort")

		url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
			"/api/v1/autoscalers/" + namespace + "/" + kind + "/" + name

		replicationControllerAutoScaler := ReplicationControllerAutoScaler{}

		tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

		_, err := restclient.RequestGetWithStructure(url, &replicationControllerAutoScaler, tokenHeaderMap)

		if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
			return
		}

		if err != nil {
			// Error
			guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		} else {
			c.Data["maximumReplica"] = replicationControllerAutoScaler.MaximumReplica
			c.Data["minimumReplica"] = replicationControllerAutoScaler.MinimumReplica

			for _, indicator := range replicationControllerAutoScaler.IndicatorSlice {
				switch indicator.Type {
				case "cpu":
					c.Data["cpuChecked"] = "checked"
					delete(c.Data, "cpuHidden")

					if indicator.AboveAllOrOne {
						c.Data["cpuAboveAllOrOneChecked"] = "checked"
					}

					c.Data["cpuAbovePercentageOfData"] = int(indicator.AbovePercentageOfData * 100)
					c.Data["cpuAboveThreshold"] = indicator.AboveThreshold / 1000000

					if indicator.BelowAllOrOne {
						c.Data["cpuBelowAllOrOneChecked"] = "checked"
					}

					c.Data["cpuBelowPercentageOfData"] = int(indicator.BelowPercentageOfData * 100)
					c.Data["cpuBelowThreshold"] = indicator.BelowThreshold / 1000000
				case "memory":
					c.Data["memoryChecked"] = "checked"
					delete(c.Data, "memoryHidden")

					if indicator.AboveAllOrOne {
						c.Data["memoryAboveAllOrOneChecked"] = "checked"
					}

					c.Data["memoryAbovePercentageOfData"] = int(indicator.AbovePercentageOfData * 100)
					c.Data["memoryAboveThreshold"] = indicator.AboveThreshold / (1024 * 1024)

					if indicator.BelowAllOrOne {
						c.Data["memoryBelowAllOrOneChecked"] = "checked"
					}

					c.Data["memoryBelowPercentageOfData"] = int(indicator.BelowPercentageOfData * 100)
					c.Data["memoryBelowThreshold"] = indicator.BelowThreshold / (1024 * 1024)
				}
			}
			coolDownDurationInSecond := int(replicationControllerAutoScaler.CoolDownDuration / time.Second)
			c.Data["coolDownDuration"] = coolDownDurationInSecond
			c.Data["readonly"] = "readonly"

			switch kind {
			case "application":
				c.Data["kindApplicationSelected"] = "selected"
			case "selector":
				c.Data["kindSelectorSelected"] = "selected"
			case "replicationController":
				c.Data["kindReplicationControllerSelected"] = "selected"
			}
		}

		c.Data["kind"] = kind
		c.Data["name"] = name
		c.Data["actionButtonValue"] = "Update"
		c.Data["pageHeader"] = "Update Autoscaler"
	}

	guimessage.OutputMessage(c.Data)
}
예제 #24
0
func (c *EditController) Get() {
	c.TplName = "filesystem/glusterfs/cluster/edit.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	clusterName := c.GetString("clusterName")

	if clusterName == "" {
		c.Data["actionButtonValue"] = "Create"
		c.Data["pageHeader"] = "Create Cluster Configuration"
		c.Data["createOrUpdate"] = "create"

		c.Data["sshDialTimeoutInMilliSecond"] = 1000
		c.Data["sshSessionTimeoutInMilliSecond"] = 10000
		c.Data["sshPort"] = 22
	} else {
		cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
		cloudoneHost := beego.AppConfig.String("cloudoneHost")
		cloudonePort := beego.AppConfig.String("cloudonePort")

		url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
			"/api/v1/glusterfs/clusters/" + clusterName

		glusterfsCluster := GlusterfsCluster{}

		tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

		_, err := restclient.RequestGetWithStructure(url, &glusterfsCluster, tokenHeaderMap)

		if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
			return
		}

		if err != nil {
			// Error
			guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
			guimessage.OutputMessage(c.Data)
			return
		}

		hostList := ""
		length := len(glusterfsCluster.HostSlice)
		for index, host := range glusterfsCluster.HostSlice {
			if index == length-1 {
				hostList += host
			} else {
				hostList += host + ","
			}
		}

		c.Data["actionButtonValue"] = "Update"
		c.Data["pageHeader"] = "Update Cluster Configuration"
		c.Data["createOrUpdate"] = "update"

		c.Data["name"] = glusterfsCluster.Name
		c.Data["hostList"] = hostList
		c.Data["path"] = glusterfsCluster.Path
		c.Data["sshDialTimeoutInMilliSecond"] = int64(glusterfsCluster.SSHDialTimeout / time.Millisecond)
		c.Data["sshSessionTimeoutInMilliSecond"] = int64(glusterfsCluster.SSHSessionTimeout / time.Millisecond)
		c.Data["sshPort"] = glusterfsCluster.SSHPort
		c.Data["sshUser"] = glusterfsCluster.SSHUser
		c.Data["sshPassword"] = glusterfsCluster.SSHPassword

		c.Data["nameFieldReadOnly"] = "readonly"
	}

	guimessage.OutputMessage(c.Data)
}
예제 #25
0
func (c *SelectController) Get() {
	c.TplName = "deploy/deploybluegreen/select.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")

	imageInformation := c.GetString("imageInformation")
	source := c.GetString("source")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploybluegreens/" + imageInformation

	deployBlueGreen := DeployBlueGreen{}

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	statusCode, _, _, err := restclient.RequestWithStructure("GET", url, nil, &deployBlueGreen, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if source == "repository" {
		c.Data["buttonUrlCancel"] = "/gui/repository/imageinformation/list"
	} else {
		c.Data["buttonUrlCancel"] = "/gui/deploy/deploybluegreen/list"
	}

	if err != nil {
		// Other errors
		guimessage.AddDanger("Fail to get deployable namespace")

		// Redirect to list
		if source == "repository" {
			c.Ctx.Redirect(302, "/gui/repository/imageinformation/list")
		} else {
			c.Ctx.Redirect(302, "/gui/deploy/deploybluegreen/list")
		}

		guimessage.RedirectMessage(c)

		return

	} else if statusCode == 404 {
		// Not existing, create
		c.Data["actionButtonValue"] = "Create"
		c.Data["pageHeader"] = "Create Blue Green Deployment"
		c.Data["imageInformation"] = imageInformation
	} else {
		// Update
		c.Data["actionButtonValue"] = "Update"
		c.Data["pageHeader"] = "Update Blue Green Deployment"
		c.Data["imageInformation"] = imageInformation

		autoGeneratedNodePort := false
		if deployBlueGreen.NodePort == 0 {
			autoGeneratedNodePort = true
		}

		c.Data["currentNamespace"] = deployBlueGreen.Namespace
		c.Data["description"] = deployBlueGreen.Description

		if autoGeneratedNodePort {
			c.Data["nodePort"] = ""
			c.Data["checkTagAutoGeneratedNodePort"] = "checked"
			c.Data["hiddenTagNodePort"] = "hidden"
		} else {
			c.Data["nodePort"] = deployBlueGreen.NodePort
			c.Data["checkTagAutoGeneratedNodePort"] = ""
			c.Data["hiddenTagNodePort"] = ""
		}
	}

	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploybluegreens/deployable/" + imageInformation

	namespaceSlice := make([]string, 0)

	tokenHeaderMap, _ = c.GetSession("tokenHeaderMap").(map[string]string)

	_, err = restclient.RequestGetWithStructure(url, &namespaceSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		guimessage.AddDanger("Fail to get deployable namespace")

		// Redirect to list
		if source == "repository" {
			c.Ctx.Redirect(302, "/gui/repository/imageinformation/list")
		} else {
			c.Ctx.Redirect(302, "/gui/deploy/deploybluegreen/list")
		}

		guimessage.RedirectMessage(c)

		return
	}

	if len(namespaceSlice) == 0 {
		guimessage.AddDanger("No deployed application is detected so there is no namespace to select for blue green deployment")

		// Redirect to list
		if source == "repository" {
			c.Ctx.Redirect(302, "/gui/repository/imageinformation/list")
		} else {
			c.Ctx.Redirect(302, "/gui/deploy/deploybluegreen/list")
		}

		guimessage.RedirectMessage(c)
	} else {
		c.Data["namespaceSlice"] = namespaceSlice

		guimessage.OutputMessage(c.Data)
	}
}
예제 #26
0
func (c *DeleteController) Get() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	name := c.GetString("name")

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	// Delete deploy
	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deploys/" + name

	deployInformationSlice := make([]deploy.DeployInformation, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &deployInformationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for _, deployInformation := range deployInformationSlice {
			url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
				"/api/v1/deploys/" + name + "/" + deployInformation.ImageInformationName

			_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

			if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
				return
			}

			if err != nil {
				guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
			}
		}
	}

	// Delete third party service
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/deployclusterapplications/" + name

	deployClusterApplicationSlice := make([]deployclusterapplication.DeployClusterApplication, 0)
	_, err = restclient.RequestGetWithStructure(url, &deployClusterApplicationSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for _, deployClusterApplication := range deployClusterApplicationSlice {
			url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
				"/api/v1/deployclusterapplications/" + name + "/" + deployClusterApplication.Name

			_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

			if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
				return
			}

			if err != nil {
				guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
			}
		}
	}

	// Delete namespace
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/namespaces/" + name

	_, err = restclient.RequestDelete(url, nil, tokenHeaderMap, true)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		guimessage.AddSuccess("Namespace " + name + " is deleted")

		selectedNamespace := c.GetSession("namespace")
		if selectedNamespace.(string) == name {
			c.SetSession("namespace", "default")
		}
	}

	// Delete autoscaler
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/autoscalers/"

	replicationControllerAutoScalerSlice := make([]autoscaler.ReplicationControllerAutoScaler, 0)
	_, err = restclient.RequestGetWithStructure(url, &replicationControllerAutoScalerSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for _, replicationControllerAutoScaler := range replicationControllerAutoScalerSlice {
			if replicationControllerAutoScaler.Namespace == name {
				url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
					"/api/v1/autoscalers/" + name + "/" + replicationControllerAutoScaler.Kind + "/" + replicationControllerAutoScaler.Name

				_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

				if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
					return
				}

				if err != nil {
					guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
				}
			}
		}
	}

	// Delete notifier
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/notifiers/"

	replicationControllerNotifierSlice := make([]notifier.ReplicationControllerNotifier, 0)
	_, err = restclient.RequestGetWithStructure(url, &replicationControllerNotifierSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		for _, replicationControllerNotifier := range replicationControllerNotifierSlice {
			if replicationControllerNotifier.Namespace == name {
				url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
					"/api/v1/notifiers/" + name + "/" + replicationControllerNotifier.Kind + "/" + replicationControllerNotifier.Name

				_, err := restclient.RequestDelete(url, nil, tokenHeaderMap, true)

				if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
					return
				}

				if err != nil {
					guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
				}
			}
		}
	}

	// Since the name deletion is asynchronized, wait for some time
	time.Sleep(time.Millisecond * 500)

	// Redirect to list
	c.Ctx.Redirect(302, "/gui/system/namespace/list")

	guimessage.RedirectMessage(c)
}
예제 #27
0
// @Title get
// @Description get all events and related parameters
// @Success 200 {string} {}
// @Failure 404 error reason
// @router / [get]
func (c *ListController) GetAll() {
	cloudoneAnalysisProtocol := beego.AppConfig.String("cloudoneAnalysisProtocol")
	cloudoneAnalysisHost := beego.AppConfig.String("cloudoneAnalysisHost")
	cloudoneAnalysisPort := beego.AppConfig.String("cloudoneAnalysisPort")

	acknowledge := c.GetString("acknowledge")
	if acknowledge == "" {
		acknowledge = "false"
	}

	offset, _ := c.GetInt("offset")

	url := cloudoneAnalysisProtocol + "://" + cloudoneAnalysisHost + ":" + cloudoneAnalysisPort +
		"/api/v1/historicalevents?acknowledge=" + acknowledge + "&size=" + strconv.Itoa(amountPerPage) + "&offset=" + strconv.Itoa(offset)

	jsonMapSlice := make([]map[string]interface{}, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &jsonMapSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		c.Data["json"] = make(map[string]interface{})
		c.Data["json"].(map[string]interface{})["error"] = err.Error()
		c.Ctx.Output.Status = 404
		c.ServeJSON()
		return
	}

	kubernetesEventSlice := make([]KubernetesEvent, 0)
	for _, jsonMap := range jsonMapSlice {
		sourceJsonMap, _ := jsonMap["_source"].(map[string]interface{})

		namespace, _ := sourceJsonMap["metadata"].(map[string]interface{})["namespace"].(string)
		name, _ := sourceJsonMap["involvedObject"].(map[string]interface{})["name"].(string)
		kind, _ := sourceJsonMap["involvedObject"].(map[string]interface{})["kind"].(string)
		source, _ := sourceJsonMap["source"].(map[string]interface{})
		id, _ := jsonMap["_id"].(string)
		firstTimestamp, _ := sourceJsonMap["firstTimestamp"].(string)
		lastTimestamp, _ := sourceJsonMap["lastTimestamp"].(string)
		count, _ := sourceJsonMap["count"].(float64)
		message, _ := sourceJsonMap["message"].(string)
		reason, _ := sourceJsonMap["reason"].(string)
		acknowledge, _ := sourceJsonMap["searchMetaData"].(map[string]interface{})["acknowledge"].(bool)

		firstTime, err := time.Parse(time.RFC3339, firstTimestamp)
		if err == nil {
			firstTime = firstTime.Local()
		}
		lastTime, err := time.Parse(time.RFC3339, lastTimestamp)
		if err == nil {
			lastTime = lastTime.Local()
		}

		kubernetesEvent := KubernetesEvent{
			namespace,
			name,
			kind,
			source,
			id,
			firstTime,
			lastTime,
			int(count),
			message,
			reason,
			acknowledge,
		}

		kubernetesEventSlice = append(kubernetesEventSlice, kubernetesEvent)
	}

	previousOffset := offset - amountPerPage
	if previousOffset < 0 {
		previousOffset = 0
	}
	nextOffset := offset + amountPerPage

	previousFrom := previousOffset
	if previousFrom < 0 {
		previousFrom = 0
	}

	previousFrom += 1
	previousTo := previousOffset + amountPerPage

	nextFrom := nextOffset + 1
	nextTo := nextOffset + amountPerPage

	c.Data["json"] = make(map[string]interface{})
	c.Data["json"].(map[string]interface{})["offset"] = offset
	c.Data["json"].(map[string]interface{})["amountPerPage"] = amountPerPage
	c.Data["json"].(map[string]interface{})["previousFrom"] = previousFrom
	c.Data["json"].(map[string]interface{})["previousTo"] = previousTo
	c.Data["json"].(map[string]interface{})["nextFrom"] = nextFrom
	c.Data["json"].(map[string]interface{})["nextTo"] = nextTo
	c.Data["json"].(map[string]interface{})["previousOffset"] = previousOffset
	c.Data["json"].(map[string]interface{})["nextOffset"] = nextOffset

	c.Data["json"].(map[string]interface{})["kubernetesEventSlice"] = kubernetesEventSlice
	c.ServeJSON()
}
예제 #28
0
func (c *LoginController) Post() {
	guimessage := guimessagedisplay.GetGUIMessage(c)

	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	username := c.GetString("username")
	password := c.GetString("password")
	timeZoneOffset, err := c.GetInt("timeZoneOffset")
	if err != nil {
		guimessage.AddDanger("Fail to get browser time zone offset. Use UTC instead")
	} else {
		hourOffset := float64(timeZoneOffset) / 60.0
		// Since it is time offset, it needs to multiple -1 to get the UTC format
		sign := "-"
		if hourOffset < 0 {
			sign = "+"
		}
		guimessage.AddSuccess("Browser time zone is UTC " + sign + strconv.FormatFloat(math.Abs(hourOffset), 'f', -1, 64) + "")
		c.SetSession("timeZoneOffset", timeZoneOffset)
	}

	// User
	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/authorizations/tokens/"
	userData := UserData{username, password}
	tokenData := TokenData{}
	_, err = restclient.RequestPostWithStructure(url, userData, &tokenData, nil)

	if err != nil {
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		guimessage.RedirectMessage(c)
		c.Ctx.Redirect(302, "/gui/login/")
		return
	}

	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort +
		"/api/v1/authorizations/tokens/" + tokenData.Token + "/components/" + componentName
	user := &rbac.User{}
	_, err = restclient.RequestGetWithStructure(url, &user, nil)
	if err != nil {
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		guimessage.RedirectMessage(c)
		c.Ctx.Redirect(302, "/gui/login/")
		return
	}

	// Set session
	// User is used by this component to authorize
	c.SetSession("user", user)
	c.SetSession("username", user.Name)
	// Token is used to submit to other componentes to authorize
	headerMap := make(map[string]string)
	headerMap["token"] = tokenData.Token
	c.SetSession("tokenHeaderMap", headerMap)
	// Layout menu is used to display common layout menu
	layoutMenu := GetLayoutMenu(user)
	c.SetSession("layoutMenu", layoutMenu)

	// Namespace
	namespace := beego.AppConfig.String("namespace")
	// Get first namespace
	for _, resource := range user.ResourceSlice {
		if resource.Component == componentName || resource.Component == "*" {
			if strings.HasPrefix(resource.Path, "/namespaces/") {
				splitSlice := strings.Split(resource.Path, "/")
				name := splitSlice[2]
				if name != "" && name != "*" {
					namespace = name
					break
				}
			}
		}
	}
	metaDataMap := user.MetaDataMap
	if metaDataMap == nil {
		metaDataMap = make(map[string]string)
	}
	// If loginNamespace is set, use it
	loginNamespace := metaDataMap["loginNamespace"]
	if len(loginNamespace) > 0 {
		namespace = loginNamespace
	}

	// Check if the namespace existing
	url = cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/namespaces/"

	nameSlice := make([]string, 0)

	_, err = restclient.RequestGetWithStructure(url, &nameSlice, headerMap)

	if IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
		guimessage.RedirectMessage(c)
		c.Ctx.Redirect(302, "/gui/login/")
		return
	}

	namespaceExist := false
	for _, name := range nameSlice {
		if name == namespace {
			namespaceExist = true
		}
	}

	if namespaceExist == false {
		guimessage.AddDanger("Namespace " + namespace + " set for user doesn't exist")
		guimessage.RedirectMessage(c)
		c.Ctx.Redirect(302, "/gui/login/")
		return
	}

	// Set namespace
	c.SetSession("namespace", namespace)

	// Send audit log since this page will pass filter
	go func() {
		sendAuditLog(c.Ctx, user.Name, false)
	}()

	guimessage.AddSuccess("User " + username + " login")

	c.Ctx.Redirect(302, "/gui/dashboard/topology/")

	guimessage.RedirectMessage(c)
}
예제 #29
0
// @Title get
// @Description get node data
// @Success 200 {string} {}
// @Failure 404 error reason
// @router / [get]
func (c *DataController) Get() {
	cloudoneProtocol := beego.AppConfig.String("cloudoneProtocol")
	cloudoneHost := beego.AppConfig.String("cloudoneHost")
	cloudonePort := beego.AppConfig.String("cloudonePort")

	url := cloudoneProtocol + "://" + cloudoneHost + ":" + cloudonePort + "/api/v1/nodemetrics"

	nodeMetricSlice := make([]NodeMetric, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &nodeMetricSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		errorJsonMap := make(map[string]interface{})
		errorJsonMap["error"] = err.Error()
		c.Data["json"] = errorJsonMap
		c.ServeJSON()
		return
	}

	nodeAmount := 0
	for _, nodeMetric := range nodeMetricSlice {
		if nodeMetric.Valid {
			nodeAmount++
		}
	}

	// CPU usage total
	cpuUsageTotalJsonMap := make(map[string]interface{})
	cpuUsageTotalDifferenceAmountMaximum := 0
	// Memory usage
	memoryUsageJsonMap := make(map[string]interface{})
	memoryUsageAmountMaximum := 0
	// Disk I/O byte
	diskIOServiceBytesStatsJsonMap := make(map[string]interface{})
	diskIOServiceBytesStatsDifferenceAmountMaximum := 0
	// Disk I/O count
	diskIOServicedStatsJsonMap := make(map[string]interface{})
	diskIOServicedStatsDifferenceAmountMaximum := 0
	// Network RX Byte
	networkRXBytesJsonMap := make(map[string]interface{})
	networkRXBytesDifferenceAmountMaximum := 0
	// Network TX Byte
	networkTXBytesJsonMap := make(map[string]interface{})
	networkTXBytesDifferenceAmountMaximum := 0
	// Network RX Packets
	networkRXPacketsJsonMap := make(map[string]interface{})
	networkRXPacketsDifferenceAmountMaximum := 0
	// Network TX Packets
	networkTXPacketsJsonMap := make(map[string]interface{})
	networkTXPacketsDifferenceAmountMaximum := 0

	if nodeAmount > 0 {
		// CPU usage total
		cpuUsageTotalJsonMap["series"] = make([]interface{}, 0)
		// Memory usage
		memoryUsageJsonMap["series"] = make([]interface{}, 0)
		// Disk I/O byte
		diskIOServiceBytesStatsJsonMap["series"] = make([]interface{}, 0)
		// Disk I/O count
		diskIOServicedStatsJsonMap["series"] = make([]interface{}, 0)
		// Network RX Byte
		networkRXBytesJsonMap["series"] = make([]interface{}, 0)
		// Network TX Byte
		networkTXBytesJsonMap["series"] = make([]interface{}, 0)
		// Network RX Packets
		networkRXPacketsJsonMap["series"] = make([]interface{}, 0)
		// Network TX Packets
		networkTXPacketsJsonMap["series"] = make([]interface{}, 0)

		for _, nodeMetric := range nodeMetricSlice {
			if nodeMetric.Valid {
				// CPU usage total
				cpuUsageTotalDifferenceAmount := len(nodeMetric.CpuUsageTotalSlice) - 1
				if cpuUsageTotalDifferenceAmount > cpuUsageTotalDifferenceAmountMaximum {
					cpuUsageTotalDifferenceAmountMaximum = cpuUsageTotalDifferenceAmount
				}
				cpuUsageTotalJsonMapSeries := make(map[string]interface{})
				cpuUsageTotalJsonMapSeries["name"] = nodeMetric.KubeletHost
				cpuUsageTotalJsonMapSeries["data"] = make([]int, cpuUsageTotalDifferenceAmount)
				for j := 0; j < cpuUsageTotalDifferenceAmount; j++ {
					cpuUsageTotalJsonMapSeries["data"].([]int)[j] = int(nodeMetric.CpuUsageTotalSlice[j+1]-nodeMetric.CpuUsageTotalSlice[j]) / 1000000
				}
				cpuUsageTotalJsonMap["series"] = append(cpuUsageTotalJsonMap["series"].([]interface{}), cpuUsageTotalJsonMapSeries)
				// Memory usage
				memoryUsageAmount := len(nodeMetric.MemoryUsageSlice)
				if memoryUsageAmount > memoryUsageAmountMaximum {
					memoryUsageAmountMaximum = memoryUsageAmount
				}
				memoryUsageJsonMapSeries := make(map[string]interface{})
				memoryUsageJsonMapSeries["name"] = nodeMetric.KubeletHost
				memoryUsageJsonMapSeries["data"] = make([]int, memoryUsageAmount)
				for j := 0; j < memoryUsageAmount; j++ {
					memoryUsageJsonMapSeries["data"].([]int)[j] = int(nodeMetric.MemoryUsageSlice[j]) / (1024 * 1024)
				}
				memoryUsageJsonMap["series"] = append(memoryUsageJsonMap["series"].([]interface{}), memoryUsageJsonMapSeries)
				// Disk I/O byte
				diskIOServiceBytesStatsDifferenceAmount := len(nodeMetric.DiskIOServiceBytesStatsTotalSlice) - 1
				if diskIOServiceBytesStatsDifferenceAmount > diskIOServiceBytesStatsDifferenceAmountMaximum {
					diskIOServiceBytesStatsDifferenceAmountMaximum = diskIOServiceBytesStatsDifferenceAmount
				}
				diskIOServiceBytesStatsJsonMapSeries := make(map[string]interface{})
				diskIOServiceBytesStatsJsonMapSeries["name"] = nodeMetric.KubeletHost
				diskIOServiceBytesStatsJsonMapSeries["data"] = make([]int, diskIOServiceBytesStatsDifferenceAmount)
				for j := 0; j < diskIOServiceBytesStatsDifferenceAmount; j++ {
					diskIOServiceBytesStatsJsonMapSeries["data"].([]int)[j] = int(nodeMetric.DiskIOServiceBytesStatsTotalSlice[j+1] - nodeMetric.DiskIOServiceBytesStatsTotalSlice[j])
				}
				diskIOServiceBytesStatsJsonMap["series"] = append(diskIOServiceBytesStatsJsonMap["series"].([]interface{}), diskIOServiceBytesStatsJsonMapSeries)
				// Disk I/O count
				diskIOServicedStatsDifferenceAmount := len(nodeMetric.DiskIOServicedStatsTotalSlice) - 1
				if diskIOServicedStatsDifferenceAmount > diskIOServicedStatsDifferenceAmountMaximum {
					diskIOServicedStatsDifferenceAmountMaximum = diskIOServicedStatsDifferenceAmount
				}
				diskIOServicedStatsJsonMapSeries := make(map[string]interface{})
				diskIOServicedStatsJsonMapSeries["name"] = nodeMetric.KubeletHost
				diskIOServicedStatsJsonMapSeries["data"] = make([]int, diskIOServicedStatsDifferenceAmount)
				for j := 0; j < diskIOServicedStatsDifferenceAmount; j++ {
					diskIOServicedStatsJsonMapSeries["data"].([]int)[j] = int(nodeMetric.DiskIOServicedStatsTotalSlice[j+1] - nodeMetric.DiskIOServicedStatsTotalSlice[j])
				}
				diskIOServicedStatsJsonMap["series"] = append(diskIOServicedStatsJsonMap["series"].([]interface{}), diskIOServicedStatsJsonMapSeries)
				// Network RX Byte
				networkRXBytesDifferenceAmount := len(nodeMetric.NetworkRXBytesSlice) - 1
				if networkRXBytesDifferenceAmount > networkRXBytesDifferenceAmountMaximum {
					networkRXBytesDifferenceAmountMaximum = networkRXBytesDifferenceAmount
				}
				networkRXBytesJsonMapSeries := make(map[string]interface{})
				networkRXBytesJsonMapSeries["name"] = nodeMetric.KubeletHost
				networkRXBytesJsonMapSeries["data"] = make([]int, networkRXBytesDifferenceAmount)
				for j := 0; j < networkRXBytesDifferenceAmount; j++ {
					networkRXBytesJsonMapSeries["data"].([]int)[j] = int(nodeMetric.NetworkRXBytesSlice[j+1] - nodeMetric.NetworkRXBytesSlice[j])
				}
				networkRXBytesJsonMap["series"] = append(networkRXBytesJsonMap["series"].([]interface{}), networkRXBytesJsonMapSeries)
				// Network TX Byte
				networkTXBytesDifferenceAmount := len(nodeMetric.NetworkTXBytesSlice) - 1
				if networkTXBytesDifferenceAmount > networkTXBytesDifferenceAmountMaximum {
					networkTXBytesDifferenceAmountMaximum = networkTXBytesDifferenceAmount
				}
				networkTXBytesJsonMapSeries := make(map[string]interface{})
				networkTXBytesJsonMapSeries["name"] = nodeMetric.KubeletHost
				networkTXBytesJsonMapSeries["data"] = make([]int, networkTXBytesDifferenceAmount)
				for j := 0; j < networkTXBytesDifferenceAmount; j++ {
					networkTXBytesJsonMapSeries["data"].([]int)[j] = int(nodeMetric.NetworkTXBytesSlice[j+1] - nodeMetric.NetworkTXBytesSlice[j])
				}
				networkTXBytesJsonMap["series"] = append(networkTXBytesJsonMap["series"].([]interface{}), networkTXBytesJsonMapSeries)
				// Network RX Packet
				networkRXPacketsDifferenceAmount := len(nodeMetric.NetworkRXPacketsSlice) - 1
				if networkRXPacketsDifferenceAmount > networkRXPacketsDifferenceAmountMaximum {
					networkRXPacketsDifferenceAmountMaximum = networkRXPacketsDifferenceAmount
				}
				networkRXPacketsJsonMapSeries := make(map[string]interface{})
				networkRXPacketsJsonMapSeries["name"] = nodeMetric.KubeletHost
				networkRXPacketsJsonMapSeries["data"] = make([]int, networkRXPacketsDifferenceAmount)
				for j := 0; j < networkRXPacketsDifferenceAmount; j++ {
					networkRXPacketsJsonMapSeries["data"].([]int)[j] = int(nodeMetric.NetworkRXPacketsSlice[j+1] - nodeMetric.NetworkRXPacketsSlice[j])
				}
				networkRXPacketsJsonMap["series"] = append(networkRXPacketsJsonMap["series"].([]interface{}), networkRXPacketsJsonMapSeries)
				// Network TX Packet
				networkTXPacketsDifferenceAmount := len(nodeMetric.NetworkTXPacketsSlice) - 1
				if networkTXPacketsDifferenceAmount > networkTXPacketsDifferenceAmountMaximum {
					networkTXPacketsDifferenceAmountMaximum = networkTXPacketsDifferenceAmount
				}
				networkTXPacketsJsonMapSeries := make(map[string]interface{})
				networkTXPacketsJsonMapSeries["name"] = nodeMetric.KubeletHost
				networkTXPacketsJsonMapSeries["data"] = make([]int, networkTXPacketsDifferenceAmount)
				for j := 0; j < networkTXPacketsDifferenceAmount; j++ {
					networkTXPacketsJsonMapSeries["data"].([]int)[j] = int(nodeMetric.NetworkTXPacketsSlice[j+1] - nodeMetric.NetworkTXPacketsSlice[j])
				}
				networkTXPacketsJsonMap["series"] = append(networkTXPacketsJsonMap["series"].([]interface{}), networkTXPacketsJsonMapSeries)
			}
		}

		// CPU usage total
		cpuUsageTotalJsonMap["labels"] = make([]int, cpuUsageTotalDifferenceAmountMaximum)
		for i := 0; i < cpuUsageTotalDifferenceAmountMaximum; i++ {
			cpuUsageTotalJsonMap["labels"].([]int)[i] = -1*cpuUsageTotalDifferenceAmountMaximum + i + 1
		}
		// Memory usage
		memoryUsageJsonMap["labels"] = make([]int, memoryUsageAmountMaximum)
		for i := 0; i < memoryUsageAmountMaximum; i++ {
			memoryUsageJsonMap["labels"].([]int)[i] = -1*memoryUsageAmountMaximum + i + 1
		}
		// Disk I/O byte
		diskIOServiceBytesStatsJsonMap["labels"] = make([]int, diskIOServiceBytesStatsDifferenceAmountMaximum)
		for i := 0; i < diskIOServiceBytesStatsDifferenceAmountMaximum; i++ {
			diskIOServiceBytesStatsJsonMap["labels"].([]int)[i] = -1*diskIOServiceBytesStatsDifferenceAmountMaximum + i + 1
		}
		// Disk I/O count
		diskIOServicedStatsJsonMap["labels"] = make([]int, diskIOServicedStatsDifferenceAmountMaximum)
		for i := 0; i < diskIOServicedStatsDifferenceAmountMaximum; i++ {
			diskIOServicedStatsJsonMap["labels"].([]int)[i] = -1*diskIOServicedStatsDifferenceAmountMaximum + i + 1
		}
		// Network RX Byte
		networkRXBytesJsonMap["labels"] = make([]int, networkRXBytesDifferenceAmountMaximum)
		for i := 0; i < networkRXBytesDifferenceAmountMaximum; i++ {
			networkRXBytesJsonMap["labels"].([]int)[i] = -1*networkRXBytesDifferenceAmountMaximum + i + 1
		}
		// Network TX Byte
		networkTXBytesJsonMap["labels"] = make([]int, networkTXBytesDifferenceAmountMaximum)
		for i := 0; i < networkTXBytesDifferenceAmountMaximum; i++ {
			networkTXBytesJsonMap["labels"].([]int)[i] = -1*networkTXBytesDifferenceAmountMaximum + i + 1
		}
		// Network RX Packet
		networkRXPacketsJsonMap["labels"] = make([]int, networkRXPacketsDifferenceAmountMaximum)
		for i := 0; i < networkRXPacketsDifferenceAmountMaximum; i++ {
			networkRXPacketsJsonMap["labels"].([]int)[i] = -1*networkRXPacketsDifferenceAmountMaximum + i + 1
		}
		// Network RX Packet
		networkTXPacketsJsonMap["labels"] = make([]int, networkTXPacketsDifferenceAmountMaximum)
		for i := 0; i < networkTXPacketsDifferenceAmountMaximum; i++ {
			networkTXPacketsJsonMap["labels"].([]int)[i] = -1*networkTXPacketsDifferenceAmountMaximum + i + 1
		}
	}

	// Convert
	current := time.Now()
	// CPU usage total
	convertedCpuUsageTotalJsonMap := make(map[string]interface{})
	convertedCpuUsageTotalJsonMap["metadata"] = make(map[string]interface{})
	convertedCpuUsageTotalJsonMap["metadata"].(map[string]interface{})["title"] = "CPU (ms/1s)"
	convertedCpuUsageTotalJsonMap["metadata"].(map[string]interface{})["lineName"] = make([]string, 0)
	convertedCpuUsageTotalJsonMap["data"] = make([]map[string]interface{}, cpuUsageTotalDifferenceAmountMaximum)
	for i := 0; i < cpuUsageTotalDifferenceAmountMaximum; i++ {
		convertedCpuUsageTotalJsonMap["data"].([]map[string]interface{})[i] = make(map[string]interface{})
		convertedCpuUsageTotalJsonMap["data"].([]map[string]interface{})[i]["y"] = make([]int, 0)
		convertedCpuUsageTotalJsonMap["data"].([]map[string]interface{})[i]["x"] = current.Add(
			time.Duration(time.Second * time.Duration(-1*(cpuUsageTotalDifferenceAmountMaximum-i)))).Format("2006-01-02 15:04:05")
	}
	for _, line := range cpuUsageTotalJsonMap["series"].([]interface{}) {
		convertedCpuUsageTotalJsonMap["metadata"].(map[string]interface{})["lineName"] = append(
			convertedCpuUsageTotalJsonMap["metadata"].(map[string]interface{})["lineName"].([]string),
			line.(map[string]interface{})["name"].(string))
		for i := 0; i < len(line.(map[string]interface{})["data"].([]int)); i++ {
			convertedCpuUsageTotalJsonMap["data"].([]map[string]interface{})[i]["y"] = append(
				convertedCpuUsageTotalJsonMap["data"].([]map[string]interface{})[i]["y"].([]int),
				line.(map[string]interface{})["data"].([]int)[i])
		}
	}
	// Memory usage
	convertedMemoryUsageJsonMap := make(map[string]interface{})
	convertedMemoryUsageJsonMap["metadata"] = make(map[string]interface{})
	convertedMemoryUsageJsonMap["metadata"].(map[string]interface{})["title"] = "Memory(MB)"
	convertedMemoryUsageJsonMap["metadata"].(map[string]interface{})["lineName"] = make([]string, 0)
	convertedMemoryUsageJsonMap["data"] = make([]map[string]interface{}, memoryUsageAmountMaximum)
	for i := 0; i < memoryUsageAmountMaximum; i++ {
		convertedMemoryUsageJsonMap["data"].([]map[string]interface{})[i] = make(map[string]interface{})
		convertedMemoryUsageJsonMap["data"].([]map[string]interface{})[i]["y"] = make([]int, 0)
		convertedMemoryUsageJsonMap["data"].([]map[string]interface{})[i]["x"] = current.Add(
			time.Duration(time.Second * time.Duration(-1*(memoryUsageAmountMaximum-i)))).Format("2006-01-02 15:04:05")
	}
	for _, line := range memoryUsageJsonMap["series"].([]interface{}) {
		convertedMemoryUsageJsonMap["metadata"].(map[string]interface{})["lineName"] = append(
			convertedMemoryUsageJsonMap["metadata"].(map[string]interface{})["lineName"].([]string),
			line.(map[string]interface{})["name"].(string))
		for i := 0; i < len(line.(map[string]interface{})["data"].([]int)); i++ {
			convertedMemoryUsageJsonMap["data"].([]map[string]interface{})[i]["y"] = append(
				convertedMemoryUsageJsonMap["data"].([]map[string]interface{})[i]["y"].([]int),
				line.(map[string]interface{})["data"].([]int)[i])
		}
	}
	// Disk I/O byte
	convertedDiskIOServiceBytesStatsJsonMap := make(map[string]interface{})
	convertedDiskIOServiceBytesStatsJsonMap["metadata"] = make(map[string]interface{})
	convertedDiskIOServiceBytesStatsJsonMap["metadata"].(map[string]interface{})["title"] = "Disk I/O (Byte/s)"
	convertedDiskIOServiceBytesStatsJsonMap["metadata"].(map[string]interface{})["lineName"] = make([]string, 0)
	convertedDiskIOServiceBytesStatsJsonMap["data"] = make([]map[string]interface{}, diskIOServiceBytesStatsDifferenceAmountMaximum)
	for i := 0; i < diskIOServiceBytesStatsDifferenceAmountMaximum; i++ {
		convertedDiskIOServiceBytesStatsJsonMap["data"].([]map[string]interface{})[i] = make(map[string]interface{})
		convertedDiskIOServiceBytesStatsJsonMap["data"].([]map[string]interface{})[i]["y"] = make([]int, 0)
		convertedDiskIOServiceBytesStatsJsonMap["data"].([]map[string]interface{})[i]["x"] = current.Add(
			time.Duration(time.Second * time.Duration(-1*(diskIOServiceBytesStatsDifferenceAmountMaximum-i)))).Format("2006-01-02 15:04:05")
	}
	for _, line := range diskIOServiceBytesStatsJsonMap["series"].([]interface{}) {
		convertedDiskIOServiceBytesStatsJsonMap["metadata"].(map[string]interface{})["lineName"] = append(
			convertedDiskIOServiceBytesStatsJsonMap["metadata"].(map[string]interface{})["lineName"].([]string),
			line.(map[string]interface{})["name"].(string))
		for i := 0; i < len(line.(map[string]interface{})["data"].([]int)); i++ {
			convertedDiskIOServiceBytesStatsJsonMap["data"].([]map[string]interface{})[i]["y"] = append(
				convertedDiskIOServiceBytesStatsJsonMap["data"].([]map[string]interface{})[i]["y"].([]int),
				line.(map[string]interface{})["data"].([]int)[i])
		}
	}
	// Disk I/O count
	convertedDiskIOServicedStatsJsonMap := make(map[string]interface{})
	convertedDiskIOServicedStatsJsonMap["metadata"] = make(map[string]interface{})
	convertedDiskIOServicedStatsJsonMap["metadata"].(map[string]interface{})["title"] = "Disk I/O (count/s)"
	convertedDiskIOServicedStatsJsonMap["metadata"].(map[string]interface{})["lineName"] = make([]string, 0)
	convertedDiskIOServicedStatsJsonMap["data"] = make([]map[string]interface{}, diskIOServicedStatsDifferenceAmountMaximum)
	for i := 0; i < diskIOServicedStatsDifferenceAmountMaximum; i++ {
		convertedDiskIOServicedStatsJsonMap["data"].([]map[string]interface{})[i] = make(map[string]interface{})
		convertedDiskIOServicedStatsJsonMap["data"].([]map[string]interface{})[i]["y"] = make([]int, 0)
		convertedDiskIOServicedStatsJsonMap["data"].([]map[string]interface{})[i]["x"] = current.Add(
			time.Duration(time.Second * time.Duration(-1*(diskIOServicedStatsDifferenceAmountMaximum-i)))).Format("2006-01-02 15:04:05")
	}
	for _, line := range diskIOServicedStatsJsonMap["series"].([]interface{}) {
		convertedDiskIOServicedStatsJsonMap["metadata"].(map[string]interface{})["lineName"] = append(
			convertedDiskIOServicedStatsJsonMap["metadata"].(map[string]interface{})["lineName"].([]string),
			line.(map[string]interface{})["name"].(string))
		for i := 0; i < len(line.(map[string]interface{})["data"].([]int)); i++ {
			convertedDiskIOServicedStatsJsonMap["data"].([]map[string]interface{})[i]["y"] = append(
				convertedDiskIOServicedStatsJsonMap["data"].([]map[string]interface{})[i]["y"].([]int),
				line.(map[string]interface{})["data"].([]int)[i])
		}
	}
	// Network RX Byte
	convertedNetworkRXBytesJsonMap := make(map[string]interface{})
	convertedNetworkRXBytesJsonMap["metadata"] = make(map[string]interface{})
	convertedNetworkRXBytesJsonMap["metadata"].(map[string]interface{})["title"] = "Network RX (Bytes/s)"
	convertedNetworkRXBytesJsonMap["metadata"].(map[string]interface{})["lineName"] = make([]string, 0)
	convertedNetworkRXBytesJsonMap["data"] = make([]map[string]interface{}, networkRXBytesDifferenceAmountMaximum)
	for i := 0; i < networkRXBytesDifferenceAmountMaximum; i++ {
		convertedNetworkRXBytesJsonMap["data"].([]map[string]interface{})[i] = make(map[string]interface{})
		convertedNetworkRXBytesJsonMap["data"].([]map[string]interface{})[i]["y"] = make([]int, 0)
		convertedNetworkRXBytesJsonMap["data"].([]map[string]interface{})[i]["x"] = current.Add(
			time.Duration(time.Second * time.Duration(-1*(networkRXBytesDifferenceAmountMaximum-i)))).Format("2006-01-02 15:04:05")
	}
	for _, line := range networkRXBytesJsonMap["series"].([]interface{}) {
		convertedNetworkRXBytesJsonMap["metadata"].(map[string]interface{})["lineName"] = append(
			convertedNetworkRXBytesJsonMap["metadata"].(map[string]interface{})["lineName"].([]string),
			line.(map[string]interface{})["name"].(string))
		for i := 0; i < len(line.(map[string]interface{})["data"].([]int)); i++ {
			convertedNetworkRXBytesJsonMap["data"].([]map[string]interface{})[i]["y"] = append(
				convertedNetworkRXBytesJsonMap["data"].([]map[string]interface{})[i]["y"].([]int),
				line.(map[string]interface{})["data"].([]int)[i])
		}
	}
	// Network TX Byte
	convertedNetworkTXBytesJsonMap := make(map[string]interface{})
	convertedNetworkTXBytesJsonMap["metadata"] = make(map[string]interface{})
	convertedNetworkTXBytesJsonMap["metadata"].(map[string]interface{})["title"] = "Network TX (Bytes/s)"
	convertedNetworkTXBytesJsonMap["metadata"].(map[string]interface{})["lineName"] = make([]string, 0)
	convertedNetworkTXBytesJsonMap["data"] = make([]map[string]interface{}, networkTXBytesDifferenceAmountMaximum)
	for i := 0; i < networkTXBytesDifferenceAmountMaximum; i++ {
		convertedNetworkTXBytesJsonMap["data"].([]map[string]interface{})[i] = make(map[string]interface{})
		convertedNetworkTXBytesJsonMap["data"].([]map[string]interface{})[i]["y"] = make([]int, 0)
		convertedNetworkTXBytesJsonMap["data"].([]map[string]interface{})[i]["x"] = current.Add(
			time.Duration(time.Second * time.Duration(-1*(networkTXBytesDifferenceAmountMaximum-i)))).Format("2006-01-02 15:04:05")
	}
	for _, line := range networkTXBytesJsonMap["series"].([]interface{}) {
		convertedNetworkTXBytesJsonMap["metadata"].(map[string]interface{})["lineName"] = append(
			convertedNetworkTXBytesJsonMap["metadata"].(map[string]interface{})["lineName"].([]string),
			line.(map[string]interface{})["name"].(string))
		for i := 0; i < len(line.(map[string]interface{})["data"].([]int)); i++ {
			convertedNetworkTXBytesJsonMap["data"].([]map[string]interface{})[i]["y"] = append(
				convertedNetworkTXBytesJsonMap["data"].([]map[string]interface{})[i]["y"].([]int),
				line.(map[string]interface{})["data"].([]int)[i])
		}
	}
	// Network RX Packet
	convertedNetworkRXPacketsJsonMap := make(map[string]interface{})
	convertedNetworkRXPacketsJsonMap["metadata"] = make(map[string]interface{})
	convertedNetworkRXPacketsJsonMap["metadata"].(map[string]interface{})["title"] = "Network RX (packet/s)"
	convertedNetworkRXPacketsJsonMap["metadata"].(map[string]interface{})["lineName"] = make([]string, 0)
	convertedNetworkRXPacketsJsonMap["data"] = make([]map[string]interface{}, networkRXPacketsDifferenceAmountMaximum)
	for i := 0; i < networkRXPacketsDifferenceAmountMaximum; i++ {
		convertedNetworkRXPacketsJsonMap["data"].([]map[string]interface{})[i] = make(map[string]interface{})
		convertedNetworkRXPacketsJsonMap["data"].([]map[string]interface{})[i]["y"] = make([]int, 0)
		convertedNetworkRXPacketsJsonMap["data"].([]map[string]interface{})[i]["x"] = current.Add(
			time.Duration(time.Second * time.Duration(-1*(networkRXPacketsDifferenceAmountMaximum-i)))).Format("2006-01-02 15:04:05")
	}
	for _, line := range networkRXPacketsJsonMap["series"].([]interface{}) {
		convertedNetworkRXPacketsJsonMap["metadata"].(map[string]interface{})["lineName"] = append(
			convertedNetworkRXPacketsJsonMap["metadata"].(map[string]interface{})["lineName"].([]string),
			line.(map[string]interface{})["name"].(string))
		for i := 0; i < len(line.(map[string]interface{})["data"].([]int)); i++ {
			convertedNetworkRXPacketsJsonMap["data"].([]map[string]interface{})[i]["y"] = append(
				convertedNetworkRXPacketsJsonMap["data"].([]map[string]interface{})[i]["y"].([]int),
				line.(map[string]interface{})["data"].([]int)[i])
		}
	}
	// Network TX Packet
	convertedNetworkTXPacketsJsonMap := make(map[string]interface{})
	convertedNetworkTXPacketsJsonMap["metadata"] = make(map[string]interface{})
	convertedNetworkTXPacketsJsonMap["metadata"].(map[string]interface{})["title"] = "Network TX (packet/s)"
	convertedNetworkTXPacketsJsonMap["metadata"].(map[string]interface{})["lineName"] = make([]string, 0)
	convertedNetworkTXPacketsJsonMap["data"] = make([]map[string]interface{}, networkTXPacketsDifferenceAmountMaximum)
	for i := 0; i < networkTXPacketsDifferenceAmountMaximum; i++ {
		convertedNetworkTXPacketsJsonMap["data"].([]map[string]interface{})[i] = make(map[string]interface{})
		convertedNetworkTXPacketsJsonMap["data"].([]map[string]interface{})[i]["y"] = make([]int, 0)
		convertedNetworkTXPacketsJsonMap["data"].([]map[string]interface{})[i]["x"] = current.Add(
			time.Duration(time.Second * time.Duration(-1*(networkTXPacketsDifferenceAmountMaximum-i)))).Format("2006-01-02 15:04:05")
	}
	for _, line := range networkTXPacketsJsonMap["series"].([]interface{}) {
		convertedNetworkTXPacketsJsonMap["metadata"].(map[string]interface{})["lineName"] = append(
			convertedNetworkTXPacketsJsonMap["metadata"].(map[string]interface{})["lineName"].([]string),
			line.(map[string]interface{})["name"].(string))
		for i := 0; i < len(line.(map[string]interface{})["data"].([]int)); i++ {
			convertedNetworkTXPacketsJsonMap["data"].([]map[string]interface{})[i]["y"] = append(
				convertedNetworkTXPacketsJsonMap["data"].([]map[string]interface{})[i]["y"].([]int),
				line.(map[string]interface{})["data"].([]int)[i])
		}
	}

	chartJsonMap := make(map[string]interface{})
	// Memory usage
	chartJsonMap["cpuUsageTotal"] = convertedCpuUsageTotalJsonMap
	// Memory usage
	chartJsonMap["memoryUsage"] = convertedMemoryUsageJsonMap
	// Disk I/O byte
	chartJsonMap["diskIOServiceBytesStats"] = convertedDiskIOServiceBytesStatsJsonMap
	// Disk I/O count
	chartJsonMap["diskIOServicedStats"] = convertedDiskIOServicedStatsJsonMap
	// Network RX Byte
	chartJsonMap["networkRXBytes"] = convertedNetworkRXBytesJsonMap
	// Network TX Byte
	chartJsonMap["networkTXBytes"] = convertedNetworkTXBytesJsonMap
	// Network RX Packet
	chartJsonMap["networkRXPackets"] = convertedNetworkRXPacketsJsonMap
	// Network TX Packet
	chartJsonMap["networkTXPackets"] = convertedNetworkTXPacketsJsonMap

	c.Data["json"] = chartJsonMap

	c.ServeJSON()
}
예제 #30
0
func (c *ListController) Get() {
	c.TplName = "event/kubernetes/list.html"
	guimessage := guimessagedisplay.GetGUIMessage(c)

	// Authorization for web page display
	c.Data["layoutMenu"] = c.GetSession("layoutMenu")
	// Authorization for Button
	user, _ := c.GetSession("user").(*rbac.User)
	// Tag won't work in loop so need to be placed in data
	hasGuiEventKubernetesAcknowledge := user.HasPermission(identity.GetConponentName(), "GET", "/gui/event/kubernetes/acknowledge")

	cloudoneAnalysisProtocol := beego.AppConfig.String("cloudoneAnalysisProtocol")
	cloudoneAnalysisHost := beego.AppConfig.String("cloudoneAnalysisHost")
	cloudoneAnalysisPort := beego.AppConfig.String("cloudoneAnalysisPort")

	acknowledge := c.GetString("acknowledge")
	if acknowledge == "" {
		acknowledge = "false"
	}

	offset, _ := c.GetInt("offset")

	url := cloudoneAnalysisProtocol + "://" + cloudoneAnalysisHost + ":" + cloudoneAnalysisPort +
		"/api/v1/historicalevents?acknowledge=" + acknowledge + "&size=" + strconv.Itoa(amountPerPage) + "&offset=" + strconv.Itoa(offset)

	jsonMapSlice := make([]map[string]interface{}, 0)

	tokenHeaderMap, _ := c.GetSession("tokenHeaderMap").(map[string]string)

	_, err := restclient.RequestGetWithStructure(url, &jsonMapSlice, tokenHeaderMap)

	if identity.IsTokenInvalidAndRedirect(c, c.Ctx, err) {
		return
	}

	if err != nil {
		// Error
		guimessage.AddDanger(guimessagedisplay.GetErrorMessage(err))
	} else {
		var action string
		var button string
		if acknowledge == "true" {
			action = "false"
			button = "Unacknowledge"
		} else {
			action = "true"
			button = "Acknowledge"
		}

		kubernetesEventSlice := make([]KubernetesEvent, 0)
		for _, jsonMap := range jsonMapSlice {
			sourceJsonMap, _ := jsonMap["_source"].(map[string]interface{})

			namespace, _ := sourceJsonMap["metadata"].(map[string]interface{})["namespace"].(string)
			name, _ := sourceJsonMap["involvedObject"].(map[string]interface{})["name"].(string)
			kind, _ := sourceJsonMap["involvedObject"].(map[string]interface{})["kind"].(string)
			source, _ := sourceJsonMap["source"].(map[string]interface{})
			id, _ := jsonMap["_id"].(string)
			firstTimestamp, _ := sourceJsonMap["firstTimestamp"].(string)
			lastTimestamp, _ := sourceJsonMap["lastTimestamp"].(string)
			count, _ := sourceJsonMap["count"].(float64)
			message, _ := sourceJsonMap["message"].(string)
			reason, _ := sourceJsonMap["reason"].(string)
			acknowledge, _ := sourceJsonMap["searchMetaData"].(map[string]interface{})["acknowledge"].(bool)

			firstTime, err := time.Parse(time.RFC3339, firstTimestamp)
			if err == nil {
				firstTime = firstTime.Local()
			}
			lastTime, err := time.Parse(time.RFC3339, lastTimestamp)
			if err == nil {
				lastTime = lastTime.Local()
			}

			kubernetesEvent := KubernetesEvent{
				namespace,
				name,
				kind,
				source,
				id,
				firstTime,
				lastTime,
				int(count),
				message,
				reason,
				acknowledge,
				action,
				button,
				"",
			}

			kubernetesEventSlice = append(kubernetesEventSlice, kubernetesEvent)
		}

		previousOffset := offset - amountPerPage
		if previousOffset < 0 {
			previousOffset = 0
		}
		nextOffset := offset + amountPerPage

		previousFrom := previousOffset
		if previousFrom < 0 {
			previousFrom = 0
		}
		previousFrom += 1
		previousTo := previousOffset + amountPerPage
		c.Data["previousLabel"] = strconv.Itoa(previousFrom) + "~" + strconv.Itoa(previousTo)
		if offset == 0 {
			c.Data["previousButtonHidden"] = "hidden"
		} else {
			c.Data["previousButtonHidden"] = ""
		}

		nextFrom := nextOffset + 1
		nextTo := nextOffset + amountPerPage
		c.Data["nextLabel"] = strconv.Itoa(nextFrom) + "~" + strconv.Itoa(nextTo)

		if acknowledge == "true" {
			c.Data["acknowledgeActive"] = "active"
			c.Data["paginationUrlPrevious"] = "/gui/event/kubernetes/list?acknowledge=true&offset=" + strconv.Itoa(previousOffset)
			c.Data["paginationUrlNext"] = "/gui/event/kubernetes/list?acknowledge=true&offset=" + strconv.Itoa(nextOffset)
		} else {
			c.Data["unacknowledgeActive"] = "active"
			c.Data["paginationUrlPrevious"] = "/gui/event/kubernetes/list?acknowledge=false&offset=" + strconv.Itoa(previousOffset)
			c.Data["paginationUrlNext"] = "/gui/event/kubernetes/list?acknowledge=false&offset=" + strconv.Itoa(nextOffset)
		}

		for i := 0; i < len(kubernetesEventSlice); i++ {
			if hasGuiEventKubernetesAcknowledge {
				kubernetesEventSlice[i].HiddenTagGuiEventKubernetesAcknowledge = "<div class='btn-group'>"
			} else {
				kubernetesEventSlice[i].HiddenTagGuiEventKubernetesAcknowledge = "<div hidden>"
			}
		}

		c.Data["kubernetesEventSlice"] = kubernetesEventSlice
	}

	guimessage.OutputMessage(c.Data)
}