This is an automated email from the ASF dual-hosted git repository.

rohit pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/cloudstack-csbench.git

commit f05db353f4f7274f2a4c609afc53bb1d8e76e469
Author: Harikrishna Patnala <[email protected]>
AuthorDate: Fri Jul 21 15:12:06 2023 +0530

    set defaults
---
 apirunner/apirunner.go | 39 +++++++--------------------------------
 config/config          |  8 ++++----
 config/configreader.go | 23 +++++++++++++++++++----
 listCommands.txt       |  2 +-
 4 files changed, 31 insertions(+), 41 deletions(-)

diff --git a/apirunner/apirunner.go b/apirunner/apirunner.go
index a645dad..d8ed5cd 100644
--- a/apirunner/apirunner.go
+++ b/apirunner/apirunner.go
@@ -191,10 +191,13 @@ func saveData(apiURL string, count float64, minTime 
float64, maxTime float64, av
        writer := csv.NewWriter(file)
        defer writer.Flush()
 
-        reader := bufio.NewReader(file)
+        filereader, err := os.Open(file.Name())
+        defer filereader.Close()
+        reader := bufio.NewReader(filereader)
         firstLine, err := reader.ReadString('\n')
-        fmt.Printf("HARI %s", firstLine)
-        if !strings.Contains(firstLine, "Count") {
+        containsCount := strings.Contains(strings.ToLower(firstLine), "count")
+
+        if !containsCount {
             header := []string{"Count", "MinTime", "MaxTime", "AvgTime", 
"Page", "PageSize", "keyword", "User", "DBprofile"}
             err = writer.Write(header)
             if err != nil {
@@ -203,7 +206,6 @@ func saveData(apiURL string, count float64, minTime 
float64, maxTime float64, av
             }
         }
 
-
        record := []string{}
        if page != 0 {
             record = []string{
@@ -241,34 +243,7 @@ func saveData(apiURL string, count float64, minTime 
float64, maxTime float64, av
        logger.Log(message)
 }
 
-func executeAPI() (apiURL string, params url.Values) (float64, float64, bool) {
-       concurrentOptions := 5 // Change this value to the desired number of 
concurrent options.
-
-       var wg sync.WaitGroup
-       requestsChan := make(chan int, concurrentOptions)
-
-       // Start the goroutines to make concurrent API requests.
-       for i := 0; i < concurrentOptions; i++ {
-               wg.Add(1)
-               go func() {
-                       defer wg.Done()
-                       for range requestsChan {
-                elapsedTime, apicount, _ := executeAPI(apiURL, params)
-            }
-               }()
-       }
-
-       // Send the API requests to the channel.
-       for i := 0; i < 10; i++ { // Replace '10' with the total number of API 
requests you want to make.
-               requestsChan <- i
-       }
-
-       close(requestsChan)
-       wg.Wait()
-
-}
-
-func executeAPIconcurrent(apiURL string, params url.Values) (float64, float64, 
bool) {
+func executeAPI(apiURL string, params url.Values) (float64, float64, bool) {
     // Send the API request and calculate the time
     apiURL = fmt.Sprintf("%s?%s", apiURL, params.Encode())
     logger.Log(fmt.Sprintf("Running the API %s", apiURL))
diff --git a/config/config b/config/config
index 6b4627e..1aa3fe1 100644
--- a/config/config
+++ b/config/config
@@ -11,15 +11,15 @@ signatureversion = 3
 timeout = 3600
 
 [user]
-apikey = 
wLvaRCjiMCEKzo8OnF9uH6ieCGZKG_6gfkVK1Qkx5yi5pde5jlUPXku66A2d2ehIowlIanTfGVwQSxMRryN3nA
-secretkey = 
-9e4AGjrCtDThzSFVJKC3E2hPAnD9YV_bintfOvxnzPzMAuDkRB7CslOEYYkrWVqFeCTslLmxp--Bcg39br8ow
+apikey = 
+secretkey = 
 expires = 600
 signatureversion = 3
 timeout = 3600
 
 [domainadmin]
-apikey = 
wLvaRCjiMCEKzo8OnF9uH6ieCGZKG_6gfkVK1Qkx5yi5pde5jlUPXku66A2d2ehIowlIanTfGVwQSxMRryN3nA
-secretkey = 
-9e4AGjrCtDThzSFVJKC3E2hPAnD9YV_bintfOvxnzPzMAuDkRB7CslOEYYkrWVqFeCTslLmxp--Bcg39br8ow
+apikey = 
+secretkey = 
 expires = 600
 signatureversion = 3
 timeout = 3600
diff --git a/config/configreader.go b/config/configreader.go
index 3509967..1daee3e 100644
--- a/config/configreader.go
+++ b/config/configreader.go
@@ -12,12 +12,12 @@ type Profile struct {
     Name             string
     ApiKey           string
     SecretKey        string
-    Expires          int
-    SignatureVersion int
-    Timeout          int
+    Expires          int        `default:"600"`
+    SignatureVersion int        `default:"3"`
+    Timeout          int        `default:"3600"`
 }
 
-var URL = ""
+var URL = "http://localhost:8080/client/api/";
 var Iterations = 1
 var Page = 0
 var PageSize = 0
@@ -124,7 +124,22 @@ func ReadProfiles(filePath string) (map[int]*Profile, 
error) {
        }
        Host = parsedURL.Hostname()
 
+    validateConfig(profiles)
 
     return profiles, nil
 }
 
+func validateConfig(profiles map[int]*Profile) (bool) {
+
+    result := true
+       for i, profile := range profiles {
+               if profile.ApiKey == "" || profile.SecretKey == "" {
+                   message := "Please check ApiKey, SecretKey of the profile. 
They should not be empty"
+                   fmt.Printf("Skipping profile [%s] : %s\n", profile.Name, 
message)
+                   delete(profiles, i)
+            result = false
+        }
+       }
+
+       return result
+}
diff --git a/listCommands.txt b/listCommands.txt
index ffe9c53..418a0b9 100644
--- a/listCommands.txt
+++ b/listCommands.txt
@@ -1,4 +1,4 @@
-listDomains keyword=test
+listDomains
 listAccounts
 listVirtualMachines
 listVolumes

Reply via email to