Skip to content

Commit

Permalink
Merge pull request #380 from ARGOeu/devel
Browse files Browse the repository at this point in the history
Prepare to release v1.9.1
  • Loading branch information
kkoumantaros authored Jul 8, 2020
2 parents 8e7ad09 + 43d3eec commit 26b92a1
Show file tree
Hide file tree
Showing 33 changed files with 10,924 additions and 73 deletions.
13 changes: 13 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,24 @@ pipeline {
}
}
post{
always {
cleanWs()
}
success {
script{
if ( env.BRANCH_NAME == 'devel' ) {
build job: '/ARGO-utils/argo-swagger-docs', propagate: false
}
if ( env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'devel' ) {
slackSend( message: ":rocket: New version for <$BUILD_URL|$PROJECT_DIR>:$BRANCH_NAME Job: $JOB_NAME !")
}
}
}
failure {
script{
if ( env.BRANCH_NAME == 'master' || env.BRANCH_NAME == 'devel' ) {
slackSend( message: ":rain_cloud: Build Failed for <$BUILD_URL|$PROJECT_DIR>:$BRANCH_NAME Job: $JOB_NAME")
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@ The ARGO Web API provides the Serving Layer of ARGO. It is comprised of a high p

godoc -http=:6060



## Postman tests
Once you finished with the installation you can run the postman tests that are located in the ./postman directory.

### Run with Postman Client
If you have a postman client you can import the files to your collections and environment variables respectively.

### Run from command line
if you prefer to use the command line you may follow the steps showed bellow

Declare the variables bellow
- `COMMIT` should be the commit of the artifact that is deployed
- `TOKEN` is an access token that is set in the service

$ cd postman && npm install newman
$ ./node_modules/newman/bin/newman.js run ./argo-web-api_tests.json -k -e ./postman/env.json --env-var last_commit=$COMMIT api_key=$TOKEN

## Credits

The ARGO Messaging Service is developed by [GRNET](http://www.grnet.gr)
Expand Down
236 changes: 236 additions & 0 deletions app/results/Controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
package results

import (
"encoding/base64"
"fmt"
"net/http"
"strconv"

"github.com/ARGOeu/argo-web-api/app/reports"
"github.com/ARGOeu/argo-web-api/respond"
Expand All @@ -35,6 +37,154 @@ import (
"gopkg.in/mgo.v2/bson"
)

// FlatListEndpointResults is responsible for handling request to flat list all available endpoint results
func FlatListEndpointResults(r *http.Request, cfg config.Config) (int, http.Header, []byte, error) {
//STANDARD DECLARATIONS START
code := http.StatusOK
h := http.Header{}
output := []byte("")
err := error(nil)
charset := "utf-8"
//STANDARD DECLARATIONS END

// Set Content-Type response Header value
contentType := r.Header.Get("Accept")
h.Set("Content-Type", fmt.Sprintf("%s; charset=%s", contentType, charset))

// Parse the request into the input
urlValues := r.URL.Query()
vars := mux.Vars(r)
supergroup := urlValues.Get("supergroup")
service := urlValues.Get("service")

skip := 0
tkStr := urlValues.Get("nextPageToken")
if tkStr != "" {
tk, err := base64.StdEncoding.DecodeString(tkStr)
if err != nil {
code = http.StatusInternalServerError
return code, h, output, err
}
skip, err = strconv.Atoi(string(tk))
if err != nil {
code = http.StatusInternalServerError
return code, h, output, err
}
}

limit := -1
limStr := urlValues.Get("pageSize")
if limStr != "" {
limit, err = strconv.Atoi(limStr)
if err != nil {
code = http.StatusInternalServerError
return code, h, output, err
}
}

// Grab Tenant DB configuration from context
tenantDbConfig := context.Get(r, "tenant_conf").(config.MongoConfig)

session, err := mongo.OpenSession(tenantDbConfig)
defer mongo.CloseSession(session)
if err != nil {
code = http.StatusInternalServerError
return code, h, output, err
}

report := reports.MongoInterface{}
err = mongo.FindOne(session, tenantDbConfig.Db, "reports", bson.M{"info.name": vars["report_name"]}, &report)

if err != nil {
code = http.StatusNotFound
message := "The report with the name " + vars["report_name"] + " does not exist"
output, err := createErrorMessage(message, code, contentType) //Render the response into XML or JSON
return code, h, output, err
}

input := endpointResultQuery{
basicQuery: basicQuery{
Name: vars["endpoint_name"],

Granularity: urlValues.Get("granularity"),
Format: contentType,
StartTime: urlValues.Get("start_time"),
EndTime: urlValues.Get("end_time"),
Report: report,
Vars: vars,
},
EndpointGroup: supergroup,
Service: service,
}

tenantDB := session.DB(tenantDbConfig.Db)
errs := input.Validate(tenantDB)
if len(errs) > 0 {
out := respond.BadRequestSimple
out.Errors = errs
output = out.MarshalTo(contentType)
code = 400
return code, h, output, err
}

results := []EndpointInterface{}

// Construct the query to mongodb based on the input
filter := bson.M{
"date": bson.M{"$gte": input.StartTimeInt, "$lte": input.EndTimeInt},
"report": report.ID,
}

if input.Name != "" {
filter["name"] = input.Name
}

if input.Service != "" {
filter["service"] = input.Service
}

if input.EndpointGroup != "" {
filter["supergroup"] = input.EndpointGroup
}

// Select the granularity of the search daily/monthly
if input.Granularity == "daily" {
customForm[0] = "20060102"
customForm[1] = "2006-01-02"
query := FlatDailyEndpoint(filter, limit, skip)
err = mongo.Pipe(session, tenantDbConfig.Db, "endpoint_ar", query, &results)
} else if input.Granularity == "monthly" {
customForm[0] = "200601"
customForm[1] = "2006-01"
query := FlatMonthlyEndpoint(filter, limit, skip)
err = mongo.Pipe(session, tenantDbConfig.Db, "endpoint_ar", query, &results)

}

// mongo.Find(session, tenantDbConfig.Db, "endpoint_group_ar", bson.M{}, "_id", &results)
if err != nil {
code = http.StatusInternalServerError
return code, h, output, err
}

if len(results) == 0 {
code = http.StatusNotFound
message := "No results found for given query"
output, err = createErrorMessage(message, code, contentType)
return code, h, output, err
}

output, err = createFlatEndpointResultView(results, report, input.Format, limit, skip)

if err != nil {
code = http.StatusInternalServerError
return code, h, output, err
}

return code, h, output, err

}

// ListEndpointResults is responsible for handling request to list service flavor results
func ListEndpointResults(r *http.Request, cfg config.Config) (int, http.Header, []byte, error) {
//STANDARD DECLARATIONS START
Expand Down Expand Up @@ -168,12 +318,47 @@ func ListEndpointResults(r *http.Request, cfg config.Config) (int, http.Header,

}

// FlatDailyEndpoint query to aggregate daily endpoint a/r results from mongoDB
func FlatDailyEndpoint(filter bson.M, limit int, skip int) []bson.M {

query := []bson.M{
{"$match": filter},
{"$project": bson.M{
"_id": 1,
"date": bson.D{{"$substr", list{"$date", 0, 8}}},
"name": 1,
"availability": 1,
"reliability": 1,
"unknown": 1,
"up": 1,
"down": 1,
"supergroup": 1,
"service": 1,
"info": 1,
"report": 1}},
{"$sort": bson.D{
{"name", 1},
{"service", 1},
{"supergroup", 1},
{"date", 1},
}}}

if limit > 0 {
query = append(query, bson.M{"$skip": skip})
query = append(query, bson.M{"$limit": limit + 1})

}

return query
}

// DailyEndpoint query to aggregate daily endpoint a/r results from mongoDB
func DailyEndpoint(filter bson.M) []bson.M {
query := []bson.M{
{"$match": filter},
{"$group": bson.M{
"_id": bson.M{
"id": "$_id",
"date": bson.D{{"$substr", list{"$date", 0, 8}}},
"name": "$name",
"supergroup": "$supergroup",
Expand All @@ -188,6 +373,7 @@ func DailyEndpoint(filter bson.M) []bson.M {
}},

{"$project": bson.M{
"_id": "$_id.id",
"date": "$_id.date",
"name": "$_id.name",
"availability": "$_id.availability",
Expand All @@ -208,6 +394,56 @@ func DailyEndpoint(filter bson.M) []bson.M {
return query
}

// FlatMonthlyEndpoint query to aggregate monthly a/r results from mongoDB
func FlatMonthlyEndpoint(filter bson.M, limit int, skip int) []bson.M {
query := []bson.M{
{"$match": filter},
{"$group": bson.M{
"_id": bson.M{
"date": bson.D{{"$substr", list{"$date", 0, 6}}},
"name": "$name",
"supergroup": "$supergroup",
"service": "$service",
"report": "$report"},
"avgup": bson.M{"$avg": "$up"},
"avgunknown": bson.M{"$avg": "$unknown"},
"avgdown": bson.M{"$avg": "$down"},
"info": bson.M{"$first": "$info"}}},
{"$project": bson.M{
"date": "$_id.date",
"name": "$_id.name",
"supergroup": "$_id.supergroup",
"service": "$_id.service",
"report": "$_id.report",
"info": "$info",
"unknown": "$avgunknown",
"up": "$avgup",
"down": "$avgdown",
"availability": bson.M{
"$multiply": list{
bson.M{"$divide": list{
"$avgup", bson.M{"$subtract": list{1.00000001, "$avgunknown"}}}},
100}},
"reliability": bson.M{
"$multiply": list{
bson.M{"$divide": list{
"$avgup", bson.M{"$subtract": list{bson.M{"$subtract": list{1.00000001, "$avgunknown"}}, "$avgdown"}}}},
100}}}},
{"$sort": bson.D{
{"name", 1},
{"service", 1},
{"supergroup", 1},
{"date", 1}}}}

if limit > 0 {
query = append(query, bson.M{"$skip": skip})
query = append(query, bson.M{"$limit": limit + 1})

}

return query
}

// MonthlyEndpoint query to aggregate monthly a/r results from mongoDB
func MonthlyEndpoint(filter bson.M) []bson.M {
query := []bson.M{
Expand Down
9 changes: 9 additions & 0 deletions app/results/Model.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ type ServiceEndpointGroup struct {
type Endpoint struct {
XMLName xml.Name `xml:"group" json:"-"`
Name string `xml:"name,attr" json:"name"`
Service string `xml:"service,attr,omitempty" json:"service,omitempty"`
SuperGroup string `xml:"supergroup,attr,omitempty" json:"supergroup,omitempty"`
Type string `xml:"type,attr" json:"type"`
Info map[string]string `xml:"-" json:"info,omitempty"`
Availability []interface{} `json:"results"`
Expand Down Expand Up @@ -201,6 +203,13 @@ type SuperGroup struct {
Results []interface{} `json:"results,omitempty"`
}

type pageRoot struct {
XMLName xml.Name `xml:"root" json:"-"`
Result []interface{} `json:"results"`
PageToken string `json:"nextPageToken,omitempty"`
PageSize int `json:"pageSize,omitempty"`
}

type root struct {
XMLName xml.Name `xml:"root" json:"-"`
Result []interface{} `json:"results"`
Expand Down
Loading

0 comments on commit 26b92a1

Please sign in to comment.