[INIT+STANDALONE] fresh init of this project from original without specific confidential documents
This commit is contained in:
70
helper_bin/inject_client/src/checker/getLastEntry.go
Executable file
70
helper_bin/inject_client/src/checker/getLastEntry.go
Executable file
@@ -0,0 +1,70 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: getLastEntry.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-15
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package checker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
// GetRandomEntry ...
|
||||
func GetRandomEntry(url string, lastEntry int) string {
|
||||
|
||||
partialURL := url + "/get/System_Name_" + strconv.Itoa(lastEntry)
|
||||
|
||||
resp, err := http.Get(partialURL)
|
||||
if err != nil {
|
||||
log.Printf("\nERROR: Destination URL (%v) does not answer (Error-> %v)",
|
||||
partialURL, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == 200 {
|
||||
body, _ := ioutil.ReadAll(resp.Body)
|
||||
return string(body)
|
||||
}
|
||||
|
||||
return fmt.Sprintf("Error: The status of the received message is unequal 200 (Received: %v)",
|
||||
resp.StatusCode)
|
||||
}
|
||||
61
helper_bin/inject_client/src/checker/urlChecker.go
Executable file
61
helper_bin/inject_client/src/checker/urlChecker.go
Executable file
@@ -0,0 +1,61 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: urlChecker.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-15
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package checker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// IsURLValid ...
|
||||
func IsURLValid(url string) error {
|
||||
|
||||
fullURL := url + "/version"
|
||||
|
||||
resp, err := http.Get(fullURL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Destination URL (%v) does not answer", url)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == http.StatusOK {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("Something seems to be wrong with the server - Abort")
|
||||
}
|
||||
145
helper_bin/inject_client/src/client/client.go
Executable file
145
helper_bin/inject_client/src/client/client.go
Executable file
@@ -0,0 +1,145 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: client.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-15
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Structure: Synchronizer
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// ParaController ...
|
||||
type ParaController struct {
|
||||
Wg sync.WaitGroup
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Structure: InjClient
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// InjClient ...
|
||||
type InjClient struct {
|
||||
clientID int
|
||||
url string
|
||||
}
|
||||
|
||||
//******************** Methods ************************************************
|
||||
|
||||
// generateKeyName ...
|
||||
func (slf *InjClient) generateKeyName() string {
|
||||
return "System_Name_" + strconv.Itoa(slf.clientID)
|
||||
}
|
||||
|
||||
// GenerateRequest ...
|
||||
func (slf *InjClient) generateRequest() *bytes.Reader {
|
||||
|
||||
newName := slf.generateKeyName()
|
||||
|
||||
newNbr := slf.clientID
|
||||
newVers := float64(slf.clientID) + 0.99999999
|
||||
newAct := slf.clientID%2 == 0
|
||||
newNull := "null"
|
||||
|
||||
return bytes.NewReader([]byte(
|
||||
fmt.Sprintf(`{"system_name": "%v","system_number": %v,"system_version": %v,"system_active": %v,"system_null": %v}`,
|
||||
newName, newNbr, newVers, newAct, newNull),
|
||||
))
|
||||
}
|
||||
|
||||
// StartRequest ...
|
||||
func (slf *InjClient) StartRequest(syncer *ParaController) {
|
||||
|
||||
defer func() {
|
||||
err := recover()
|
||||
if err != nil {
|
||||
fmt.Printf("(RECOVER) Worker ID: %v - failed: Reason -> [Program Error: %v]\n",
|
||||
slf.clientID, err)
|
||||
|
||||
syncer.Wg.Add(-1)
|
||||
}
|
||||
}()
|
||||
|
||||
client := &http.Client{Timeout: time.Second * 60}
|
||||
callURL := slf.url + "/add/" + slf.generateKeyName()
|
||||
|
||||
req, _ := http.NewRequest("POST", callURL, slf.generateRequest())
|
||||
req.Header.Set("User-Agent", "Injection-Client-storeserver-1.0.0")
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
|
||||
resp, err := client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("Worker ID: %v - failed: Reason -> [Connection Error -> (%v)]\n",
|
||||
slf.clientID, err)
|
||||
return
|
||||
}
|
||||
if resp.StatusCode != 201 {
|
||||
fmt.Printf("Worker ID: %v - failed: Reason -> [Status != 201 | (Received: %v)]\n",
|
||||
resp.StatusCode, slf.clientID)
|
||||
return
|
||||
}
|
||||
|
||||
resp.Body.Close()
|
||||
syncer.Wg.Add(-1)
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Public Functions
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// NewWorker ...
|
||||
func NewWorker(clientID int, url string) *InjClient {
|
||||
return &InjClient{
|
||||
clientID: clientID,
|
||||
url: url,
|
||||
}
|
||||
}
|
||||
89
helper_bin/inject_client/src/inject_client/main.go
Executable file
89
helper_bin/inject_client/src/inject_client/main.go
Executable file
@@ -0,0 +1,89 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: main.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-15
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"checker"
|
||||
"client"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"time"
|
||||
"utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
const maxParaReqs int = 6000
|
||||
var endNbr int
|
||||
|
||||
cmdArgs := utils.NewCmdController()
|
||||
synchronizer := client.ParaController{}
|
||||
start := time.Now()
|
||||
|
||||
if cmdArgs.GetStart() != 0 {
|
||||
endNbr = cmdArgs.GetStart() + 6000
|
||||
} else {
|
||||
endNbr = maxParaReqs
|
||||
}
|
||||
|
||||
for idx := cmdArgs.GetStart(); idx < endNbr; idx++ {
|
||||
|
||||
synchronizer.Wg.Add(1)
|
||||
go client.NewWorker(idx, cmdArgs.GetTarget()).StartRequest(&synchronizer)
|
||||
}
|
||||
synchronizer.Wg.Wait()
|
||||
|
||||
runtime.GC()
|
||||
|
||||
fmt.Printf("\nToral duration of all (%v) parallel requests -> %v\n",
|
||||
maxParaReqs, time.Since(start))
|
||||
|
||||
fmt.Printf("\nThe default key pattern is \"System_Name_<%v - %v>\"", cmdArgs.GetStart(), endNbr-1)
|
||||
fmt.Printf(`
|
||||
|
||||
EXAMPLE:
|
||||
http://<IP or domain name>:3344/get/System_Name_0
|
||||
`)
|
||||
|
||||
fmt.Printf("Start trying to get the last entry from kvmstoreserver:")
|
||||
|
||||
fmt.Printf("\nRESULT -> %v",
|
||||
checker.GetRandomEntry(cmdArgs.GetTarget(), endNbr-1))
|
||||
|
||||
}
|
||||
98
helper_bin/inject_client/src/utils/cmdParser.go
Executable file
98
helper_bin/inject_client/src/utils/cmdParser.go
Executable file
@@ -0,0 +1,98 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: cmdParser.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-15
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"checker"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Structure: CmdController
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// CmdController ...
|
||||
type CmdController struct {
|
||||
target *string
|
||||
start *int
|
||||
}
|
||||
|
||||
//******************** Methods ************************************************
|
||||
|
||||
// GetTarget ...
|
||||
func (slf *CmdController) GetTarget() string { return *slf.target }
|
||||
|
||||
// GetStart ...
|
||||
func (slf *CmdController) GetStart() int { return *slf.start }
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Public Functions
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// NewCmdController ...
|
||||
func NewCmdController() *CmdController {
|
||||
|
||||
var cmdController CmdController
|
||||
|
||||
cmdController.target = flag.String("target", "",
|
||||
"The URL to the storeserver -> EXAMPLE: http://<IP or domain name>:3344")
|
||||
|
||||
cmdController.start = flag.Int("start", 0,
|
||||
"Please enter the start number. At this point + 6000 will be added")
|
||||
|
||||
if cmdController.target == nil {
|
||||
fmt.Println("Please enter the address of the server -> EXAMPLE: inject_client -target http://<IP or domain name>:3344")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if err := checker.IsURLValid(*cmdController.target); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return &cmdController
|
||||
}
|
||||
121
helper_bin/inject_disk/src/generator/jsonObjGenerator.go
Executable file
121
helper_bin/inject_disk/src/generator/jsonObjGenerator.go
Executable file
@@ -0,0 +1,121 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: jsonObjGenerator.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-14
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package generator
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"keyNameHandling"
|
||||
"log"
|
||||
"strconv"
|
||||
"utils"
|
||||
)
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Declarations
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
const namePattern string = "System_Name_"
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Structure: JObjGenerator
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// JObjGenerator ...
|
||||
type JObjGenerator struct {
|
||||
objNbr int
|
||||
jObj []byte
|
||||
wPath string
|
||||
fullPath string
|
||||
syncer *utils.ParaController
|
||||
}
|
||||
|
||||
//******************** Methods ************************************************
|
||||
|
||||
func (slf *JObjGenerator) generateJObj() {
|
||||
|
||||
keyName := namePattern + strconv.Itoa(slf.objNbr)
|
||||
nodeID, _ := keyNameHandling.NewKeyContext(keyName)
|
||||
|
||||
slf.fullPath = slf.wPath + "/" + strconv.Itoa(nodeID.GetNodeID()) + ".json"
|
||||
|
||||
dataNbr := slf.objNbr
|
||||
dataVers := float64(slf.objNbr) + 0.99999999
|
||||
dataAct := slf.objNbr%2 == 0
|
||||
dataNull := "null"
|
||||
|
||||
slf.jObj = []byte(
|
||||
fmt.Sprintf(`{"node_id":%v,"orig_key_name":"%v","data_container":[{"rev_nbr":0,"meta_header":{"remote_addr":"0.0.0.0:65535","created_at":"1970-01-01T00:00:00.3889558+01:00"},"data":{"system_name": "%v","system_number": %v,"system_version": %v,"system_active": %v,"system_null": %v}}]}`,
|
||||
nodeID.GetNodeID(), nodeID.GetKeyStrName(), nodeID.GetKeyStrName(), dataNbr, dataVers, dataAct, dataNull),
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
// WriteIntoTarget ...
|
||||
func (slf *JObjGenerator) WriteIntoTarget() {
|
||||
|
||||
if err := ioutil.WriteFile(slf.fullPath, slf.jObj, 0660); err != nil {
|
||||
log.Printf("Write for %v failed: Reason -> [%v]", slf.fullPath, err)
|
||||
}
|
||||
|
||||
slf.syncer.Wg.Add(-1)
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Public Functions
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// NewWorker ...
|
||||
func NewWorker(objNbr int, wPath *string, syncer *utils.ParaController) *JObjGenerator {
|
||||
newObj := JObjGenerator{
|
||||
objNbr: objNbr,
|
||||
wPath: *wPath,
|
||||
syncer: syncer,
|
||||
}
|
||||
|
||||
newObj.generateJObj()
|
||||
|
||||
return &newObj
|
||||
}
|
||||
101
helper_bin/inject_disk/src/inject_disk/main.go
Executable file
101
helper_bin/inject_disk/src/inject_disk/main.go
Executable file
@@ -0,0 +1,101 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: main.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-14
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"generator"
|
||||
"time"
|
||||
"utils"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
var (
|
||||
chunkSize int
|
||||
outerLoops int
|
||||
rest int
|
||||
objCounter int
|
||||
)
|
||||
|
||||
chunkSize = 10000
|
||||
|
||||
cmdArgs := utils.NewCmdController()
|
||||
synchronizer := utils.NewParaController()
|
||||
|
||||
if cmdArgs.GetObjects() < chunkSize {
|
||||
chunkSize = cmdArgs.GetObjects()
|
||||
outerLoops = 1
|
||||
rest = 0
|
||||
} else {
|
||||
outerLoops = cmdArgs.GetObjects() / chunkSize
|
||||
rest = cmdArgs.GetObjects() % chunkSize
|
||||
}
|
||||
|
||||
start := time.Now()
|
||||
|
||||
for outerIdx := 0; outerIdx < outerLoops; outerIdx++ {
|
||||
|
||||
for innerIdx := 0; innerIdx < chunkSize; innerIdx++ {
|
||||
synchronizer.Wg.Add(1)
|
||||
generator.NewWorker(objCounter, cmdArgs.GetTargetRef(), synchronizer).
|
||||
WriteIntoTarget()
|
||||
|
||||
objCounter++
|
||||
}
|
||||
|
||||
synchronizer.Wg.Wait()
|
||||
}
|
||||
|
||||
if rest > 0 {
|
||||
for innerIdx := 0; innerIdx < rest; innerIdx++ {
|
||||
synchronizer.Wg.Add(1)
|
||||
generator.NewWorker(objCounter, cmdArgs.GetTargetRef(), synchronizer).
|
||||
WriteIntoTarget()
|
||||
|
||||
objCounter++
|
||||
}
|
||||
|
||||
synchronizer.Wg.Wait()
|
||||
}
|
||||
|
||||
fmt.Printf("%v generic JSON objects were generated in %v and stored in path -> %v\n",
|
||||
objCounter, time.Since(start), *cmdArgs.GetTargetRef())
|
||||
|
||||
}
|
||||
123
helper_bin/inject_disk/src/keyNameHandling/KeyNameToIdConverter.go
Executable file
123
helper_bin/inject_disk/src/keyNameHandling/KeyNameToIdConverter.go
Executable file
@@ -0,0 +1,123 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: KeyNameToIdConverter.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-14
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package keyNameHandling
|
||||
|
||||
// nolint
|
||||
import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Structure: keyContext
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// KeyContext takes the original key and forms or calculates
|
||||
// all necessary parameters. This holds it in, so you can access
|
||||
// it from the outside
|
||||
type keyContext struct {
|
||||
keyNameAsString string
|
||||
keyMd5Hash [16]byte
|
||||
|
||||
// Here is the calculated node ID where the data should be stored
|
||||
dataNodeID int
|
||||
}
|
||||
|
||||
/********************* Methods ************************************************/
|
||||
|
||||
// defDataNodeID ...
|
||||
func (slf *keyContext) defDataNodeID() {
|
||||
|
||||
var uniqueIdentifierStr string
|
||||
|
||||
for idx := 0; idx < 6; idx++ {
|
||||
uniqueIdentifierStr += strconv.Itoa(int(slf.keyMd5Hash[idx]))
|
||||
}
|
||||
|
||||
uniqueIdentifier, _ := strconv.ParseInt(uniqueIdentifierStr, 10, 64)
|
||||
slf.dataNodeID = int(uniqueIdentifier)
|
||||
}
|
||||
|
||||
// nolint
|
||||
// defChkSum calc the checksum from the name (in string form)
|
||||
func (slf *keyContext) defChkSum() {
|
||||
slf.keyMd5Hash = md5.Sum([]byte(slf.keyNameAsString))
|
||||
}
|
||||
|
||||
/********************* Interface: IHandelWithIds ******************************/
|
||||
|
||||
// GetKeyStrName returns the plain text key name from the structure
|
||||
func (slf *keyContext) GetKeyStrName() string { return slf.keyNameAsString }
|
||||
|
||||
// GetNodeId returns the calculated Node ID from the structure
|
||||
func (slf *keyContext) GetNodeID() int { return slf.dataNodeID }
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Public Functions
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// NewKeyContext Returns a reference to the structure, which
|
||||
// contains all information on the following points:
|
||||
//
|
||||
// - Original Key Name as string
|
||||
// - MD5 hash of the key name
|
||||
// - The ID of RootTree
|
||||
// - The ID of the node where to save or read data
|
||||
func NewKeyContext(key string) (IHandelWithIds, error) {
|
||||
|
||||
var kc keyContext
|
||||
|
||||
// A backup to prevent blank input
|
||||
secKey := strings.Trim(key, " ")
|
||||
if len(secKey) == 0 {
|
||||
return &kc, errors.New("Key name is a empty string")
|
||||
}
|
||||
|
||||
kc.keyNameAsString = key
|
||||
kc.defChkSum()
|
||||
kc.defDataNodeID()
|
||||
|
||||
return &kc, nil
|
||||
}
|
||||
52
helper_bin/inject_disk/src/keyNameHandling/interfaces.go
Executable file
52
helper_bin/inject_disk/src/keyNameHandling/interfaces.go
Executable file
@@ -0,0 +1,52 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: interfaces.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-14
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package keyNameHandling
|
||||
|
||||
// IHandelWithIds works as a getter interface. This is
|
||||
// necessary so that the structure keyContext does not
|
||||
// have to be exported. So nobody can manipulate data
|
||||
// into the structure. This interface only realizes read
|
||||
// only capabilities
|
||||
type IHandelWithIds interface {
|
||||
// GetKeyStrName returns the value stored in the structure
|
||||
GetKeyStrName() string
|
||||
|
||||
// GetNodeID returns the value stored in the structure
|
||||
GetNodeID() int
|
||||
}
|
||||
85
helper_bin/inject_disk/src/utils/cmdParser.go
Executable file
85
helper_bin/inject_disk/src/utils/cmdParser.go
Executable file
@@ -0,0 +1,85 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: cmdParser.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-14
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"flag"
|
||||
)
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Structure: CmdController
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// CmdController ...
|
||||
type CmdController struct {
|
||||
target *string
|
||||
objects *int
|
||||
}
|
||||
|
||||
//******************** Methods ************************************************
|
||||
|
||||
// GetTargetRef ...
|
||||
func (slf *CmdController) GetTargetRef() *string { return slf.target }
|
||||
|
||||
// GetObjects ...
|
||||
func (slf *CmdController) GetObjects() int { return *slf.objects }
|
||||
|
||||
//*****************************************************************************
|
||||
//*
|
||||
//* Public Functions
|
||||
//*
|
||||
//*****************************************************************************
|
||||
|
||||
// NewCmdController ...
|
||||
func NewCmdController() *CmdController {
|
||||
|
||||
var cmdController CmdController
|
||||
|
||||
cmdController.target = flag.String("target", "/home/kvmstoreserver/kvmstoreserver/warehouse",
|
||||
"The path to the warehouse folder")
|
||||
|
||||
cmdController.objects = flag.Int("objects", 1,
|
||||
"How many json objects should be generated")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
return &cmdController
|
||||
}
|
||||
53
helper_bin/inject_disk/src/utils/paraController.go
Executable file
53
helper_bin/inject_disk/src/utils/paraController.go
Executable file
@@ -0,0 +1,53 @@
|
||||
/**************************************************************************************
|
||||
*
|
||||
* Project: kvmstoreserver-tools
|
||||
* File name: paraController.go
|
||||
* Version: 1.0.0
|
||||
* Date: 2018-01-14
|
||||
*
|
||||
* Autor: Bogdanovic Theodor
|
||||
* Contact: t.bogdanovic@hotmail.com
|
||||
*
|
||||
* License: GPLv3
|
||||
*
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Copyright 2018 Bogdanovic Theodor
|
||||
*
|
||||
* This file is part of kvmstoreserver-tools.
|
||||
*
|
||||
* kvmstoreserver-tools is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* kvmstoreserver-tools is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with kvmstoreserver-tools. If not, see <http://www.gnu.org/licenses/>.
|
||||
**************************************************************************************/
|
||||
/**************************************************************************************
|
||||
* Further explanations: This source code is under the license specified by the
|
||||
* Autor above. Core components or other packages are still
|
||||
* in source code form, under the license specified by the
|
||||
* respective author.
|
||||
**************************************************************************************/
|
||||
|
||||
package utils
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ParaController ...
|
||||
type ParaController struct {
|
||||
Wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// NewParaController ...
|
||||
func NewParaController() *ParaController {
|
||||
return &ParaController{}
|
||||
}
|
||||
Reference in New Issue
Block a user