Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize REST API server Go files #1026

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions src/api/rest/server/mcis/benchmark.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
Copyright 2019 The Cloud-Barista Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Package mcis is to handle REST API for mcis
package mcis

import (
"net/http"

"github.com/cloud-barista/cb-tumblebug/src/core/common"
"github.com/cloud-barista/cb-tumblebug/src/core/mcis"
"github.com/labstack/echo/v4"
)

// RestPostInstallBenchmarkAgentToMcis godoc
// @Summary Install the benchmark agent to specified MCIS
// @Description Install the benchmark agent to specified MCIS
// @Tags [Infra service] MCIS Performance benchmarking (WIP)
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param mcisCmdReq body mcis.McisCmdReq true "MCIS Command Request"
// @Success 200 {object} mcis.RestPostCmdMcisResponseWrapper
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/installBenchmarkAgent/mcis/{mcisId} [post]
func RestPostInstallBenchmarkAgentToMcis(c echo.Context) error {

nsId := c.Param("nsId")
mcisId := c.Param("mcisId")

req := &mcis.McisCmdReq{}
if err := c.Bind(req); err != nil {
return err
}

resultArray, err := mcis.InstallBenchmarkAgentToMcis(nsId, mcisId, req)
if err != nil {
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}

content := RestPostCmdMcisResponseWrapper{}

for _, v := range resultArray {

resultTmp := RestPostCmdMcisResponse{}
resultTmp.McisId = mcisId
resultTmp.VmId = v.VmId
resultTmp.VmIp = v.VmIp
resultTmp.Result = v.Result
content.ResultArray = append(content.ResultArray, resultTmp)

}

common.PrintJsonPretty(content)

return c.JSON(http.StatusOK, content)

}

// Request struct for RestGetAllBenchmark
type RestGetAllBenchmarkRequest struct {
Host string `json:"host"`
}

// RestGetAllBenchmark godoc
// @Summary Run MCIS benchmark for all performance metrics and return results
// @Description Run MCIS benchmark for all performance metrics and return results
// @Tags [Infra service] MCIS Performance benchmarking (WIP)
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param hostIP body RestGetAllBenchmarkRequest true "Host IP address to benchmark"
// @Success 200 {object} mcis.BenchmarkInfoArray
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/benchmarkAll/mcis/{mcisId} [post]
func RestGetAllBenchmark(c echo.Context) error {

nsId := c.Param("nsId")
mcisId := c.Param("mcisId")

req := &RestGetAllBenchmarkRequest{}
if err := c.Bind(req); err != nil {
return err
}

result, err := mcis.RunAllBenchmarks(nsId, mcisId, req.Host)
if err != nil {
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}

common.PrintJsonPretty(*result)
return c.JSON(http.StatusOK, result)
}

type RestGetBenchmarkRequest struct {
Host string `json:"host"`
}

// RestGetBenchmark godoc
// @Summary Run MCIS benchmark for a single performance metric and return results
// @Description Run MCIS benchmark for a single performance metric and return results
// @Tags [Infra service] MCIS Performance benchmarking (WIP)
// @Accept json
// @Produce json
// @Param nsId path string true "Namespace ID" default(ns01)
// @Param mcisId path string true "MCIS ID" default(mcis01)
// @Param hostIP body RestGetBenchmarkRequest true "Host IP address to benchmark"
// @Param action query string true "Benchmark Action to MCIS" Enums(install, init, cpus, cpum, memR, memW, fioR, fioW, dbR, dbW, rtt, mrtt, clean)
// @Success 200 {object} mcis.BenchmarkInfoArray
// @Failure 404 {object} common.SimpleMsg
// @Failure 500 {object} common.SimpleMsg
// @Router /ns/{nsId}/benchmark/mcis/{mcisId} [post]
func RestGetBenchmark(c echo.Context) error {

nsId := c.Param("nsId")
mcisId := c.Param("mcisId")

action := c.QueryParam("action")

req := &RestGetBenchmarkRequest{}
if err := c.Bind(req); err != nil {
return err
}

result, err := mcis.CoreGetBenchmark(nsId, mcisId, action, req.Host)
if err != nil {
mapA := map[string]string{"message": err.Error()}
return c.JSON(http.StatusInternalServerError, &mapA)
}

common.PrintJsonPretty(*result)
return c.JSON(http.StatusOK, result)
}
Loading