[server] Add support for dummy mode

This commit is contained in:
Ciprian Dorin Craciun 2019-08-12 13:37:46 +03:00
parent 94ccc6d89c
commit 1cc9d9bacb
3 changed files with 71 additions and 24 deletions

View file

@ -506,6 +506,8 @@
exec -- env -i "$( type -P -- curl )" \ exec -- env -i "$( type -P -- curl )" \
--silent \ --silent \
--compressed \ --compressed \
--output /dev/stdout \
--dump-header /dev/stdout \
"${@}" \ "${@}" \
-- "http://127.9.185.194:8080/${_path}" \ -- "http://127.9.185.194:8080/${_path}" \
# #

View file

@ -39,6 +39,7 @@ type server struct {
cachedDataMeta map[string][]byte cachedDataMeta map[string][]byte
cachedDataContent map[string][]byte cachedDataContent map[string][]byte
debug bool debug bool
dummy bool
} }
@ -364,6 +365,17 @@ func (_server *server) ServeError (_context *fasthttp.RequestCtx, _status uint,
} }
func (_server *server) ServeDummy (_context *fasthttp.RequestCtx) () {
_server.ServeStatic (_context, http.StatusOK, DummyData, DummyContentType, DummyContentEncoding, false)
}
func ServeDummyRaw (_context *fasthttp.RequestCtx) () {
_context.Response.SetBodyRaw (DummyData)
_context.Response.SetStatusCode (200)
}
func main () () { func main () () {
@ -375,7 +387,7 @@ func main_0 () (error) {
var _bind string var _bind string
var _archive string var _archivePath string
var _archiveInmem bool var _archiveInmem bool
var _archiveMmap bool var _archiveMmap bool
var _archivePreload bool var _archivePreload bool
@ -386,6 +398,7 @@ func main_0 () (error) {
var _threads uint var _threads uint
var _slave uint var _slave uint
var _debug bool var _debug bool
var _dummy bool
var _isFirst bool var _isFirst bool
var _profileCpu string var _profileCpu string
@ -429,6 +442,7 @@ func main_0 () (error) {
--profile-mem <path> --profile-mem <path>
--debug --debug
--dummy
** for details see: ** for details see:
https://github.com/volution/kawipiko#kawipiko-server https://github.com/volution/kawipiko#kawipiko-server
@ -437,7 +451,7 @@ func main_0 () (error) {
} }
_bind_0 := _flags.String ("bind", "", "") _bind_0 := _flags.String ("bind", "", "")
_archive_0 := _flags.String ("archive", "", "") _archivePath_0 := _flags.String ("archive", "", "")
_archiveInmem_0 := _flags.Bool ("archive-inmem", false, "") _archiveInmem_0 := _flags.Bool ("archive-inmem", false, "")
_archiveMmap_0 := _flags.Bool ("archive-mmap", false, "") _archiveMmap_0 := _flags.Bool ("archive-mmap", false, "")
_archivePreload_0 := _flags.Bool ("archive-preload", false, "") _archivePreload_0 := _flags.Bool ("archive-preload", false, "")
@ -451,11 +465,12 @@ func main_0 () (error) {
_profileCpu_0 := _flags.String ("profile-cpu", "", "") _profileCpu_0 := _flags.String ("profile-cpu", "", "")
_profileMem_0 := _flags.String ("profile-mem", "", "") _profileMem_0 := _flags.String ("profile-mem", "", "")
_debug_0 := _flags.Bool ("debug", false, "") _debug_0 := _flags.Bool ("debug", false, "")
_dummy_0 := _flags.Bool ("dummy", false, "")
FlagsParse (_flags, 0, 0) FlagsParse (_flags, 0, 0)
_bind = *_bind_0 _bind = *_bind_0
_archive = *_archive_0 _archivePath = *_archivePath_0
_archiveInmem = *_archiveInmem_0 _archiveInmem = *_archiveInmem_0
_archiveMmap = *_archiveMmap_0 _archiveMmap = *_archiveMmap_0
_archivePreload = *_archivePreload_0 _archivePreload = *_archivePreload_0
@ -467,6 +482,7 @@ func main_0 () (error) {
_threads = *_threads_0 _threads = *_threads_0
_slave = *_slave_0 _slave = *_slave_0
_debug = *_debug_0 _debug = *_debug_0
_dummy = *_dummy_0
_profileCpu = *_profileCpu_0 _profileCpu = *_profileCpu_0
_profileMem = *_profileMem_0 _profileMem = *_profileMem_0
@ -474,10 +490,11 @@ func main_0 () (error) {
if _bind == "" { if _bind == "" {
AbortError (nil, "[6edd9512] expected bind address argument!") AbortError (nil, "[6edd9512] expected bind address argument!")
} }
if _archive == "" {
if !_dummy {
if _archivePath == "" {
AbortError (nil, "[eefe1a38] expected archive file argument!") AbortError (nil, "[eefe1a38] expected archive file argument!")
} }
if _archiveInmem && _archiveMmap { if _archiveInmem && _archiveMmap {
AbortError (nil, "[a2101041] archive 'memory-loaded' and 'memory-mapped' are mutually exclusive!") AbortError (nil, "[a2101041] archive 'memory-loaded' and 'memory-mapped' are mutually exclusive!")
} }
@ -485,6 +502,17 @@ func main_0 () (error) {
log.Printf ("[ww] [3e8a40e4] archive 'memory-loaded' implies preloading!\n") log.Printf ("[ww] [3e8a40e4] archive 'memory-loaded' implies preloading!\n")
_archivePreload = false _archivePreload = false
} }
} else {
log.Printf ("[ww] [8e014192] running in dummy mode; all archive related arguments are ignored!\n")
_archivePath = ""
_archiveInmem = false
_archiveMmap = false
_archivePreload = false
_indexAll = false
_indexPaths = false
_indexDataMeta = false
_indexDataContent = false
}
if (_processes > 1) && ((_profileCpu != "") || (_profileMem != "")) { if (_processes > 1) && ((_profileCpu != "") || (_profileMem != "")) {
AbortError (nil, "[cd18d250] multi-process and profiling are mutually exclusive!") AbortError (nil, "[cd18d250] multi-process and profiling are mutually exclusive!")
@ -526,8 +554,10 @@ func main_0 () (error) {
_processArguments := make ([]string, 0, len (os.Args)) _processArguments := make ([]string, 0, len (os.Args))
_processArguments = append (_processArguments, _processArguments = append (_processArguments,
"--bind", _bind, "--bind", _bind,
"--archive", _archive,
) )
if _archivePath != "" {
_processArguments = append (_processArguments, "--archive", _archivePath)
}
if _archiveInmem { if _archiveInmem {
_processArguments = append (_processArguments, "--archive-inmem") _processArguments = append (_processArguments, "--archive-inmem")
} }
@ -540,6 +570,9 @@ func main_0 () (error) {
if _debug { if _debug {
_processArguments = append (_processArguments, "--debug") _processArguments = append (_processArguments, "--debug")
} }
if _dummy {
_processArguments = append (_processArguments, "--dummy")
}
_processArguments = append (_processArguments, "--threads", fmt.Sprintf ("%d", _threads)) _processArguments = append (_processArguments, "--threads", fmt.Sprintf ("%d", _threads))
_processAttributes := & os.ProcAttr { _processAttributes := & os.ProcAttr {
@ -619,13 +652,14 @@ func main_0 () (error) {
var _cdbReader *cdb.CDB var _cdbReader *cdb.CDB
{ if _archivePath != "" {
if _debug || _isFirst { if _debug || _isFirst {
log.Printf ("[ii] [3b788396] opening archive file `%s`...\n", _archive) log.Printf ("[ii] [3b788396] opening archive file `%s`...\n", _archivePath)
} }
var _cdbFile *os.File var _cdbFile *os.File
if _cdbFile_0, _error := os.Open (_archive); _error == nil { if _cdbFile_0, _error := os.Open (_archivePath); _error == nil {
_cdbFile = _cdbFile_0 _cdbFile = _cdbFile_0
} else { } else {
AbortError (_error, "[9e0b5ed3] failed opening archive file!") AbortError (_error, "[9e0b5ed3] failed opening archive file!")
@ -733,7 +767,6 @@ func main_0 () (error) {
} }
} }
}
if _schemaVersion, _error := _cdbReader.GetWithCdbHash ([]byte (NamespaceSchemaVersion)); _error == nil { if _schemaVersion, _error := _cdbReader.GetWithCdbHash ([]byte (NamespaceSchemaVersion)); _error == nil {
if _schemaVersion == nil { if _schemaVersion == nil {
@ -744,6 +777,8 @@ func main_0 () (error) {
} else { } else {
AbortError (_error, "[87cae197] failed opening archive!") AbortError (_error, "[87cae197] failed opening archive!")
} }
}
var _cachedFileFingerprints map[string][]byte var _cachedFileFingerprints map[string][]byte
if _indexPaths { if _indexPaths {
@ -857,6 +892,7 @@ func main_0 () (error) {
cachedDataMeta : _cachedDataMeta, cachedDataMeta : _cachedDataMeta,
cachedDataContent : _cachedDataContent, cachedDataContent : _cachedDataContent,
debug : _debug, debug : _debug,
dummy : _dummy,
} }
@ -921,6 +957,11 @@ func main_0 () (error) {
} }
if _dummy {
// _httpServer.Handler = _server.ServeDummy
_httpServer.Handler = ServeDummyRaw
}
_server.httpServer = _httpServer _server.httpServer = _httpServer

View file

@ -15,6 +15,10 @@ var HeartbeatContentEncoding = "identity"
var HeartbeatDataOk = []byte ("OK\n") var HeartbeatDataOk = []byte ("OK\n")
var HeartbeatDataNok = []byte ("NOK\n") var HeartbeatDataNok = []byte ("NOK\n")
var DummyContentType = MimeTypeText
var DummyContentEncoding = "identity"
var DummyData = []byte ("hello world!\n")
var FaviconContentType = "image/vnd.microsoft.icon" var FaviconContentType = "image/vnd.microsoft.icon"
var FaviconContentEncoding = "identity" var FaviconContentEncoding = "identity"