Initial QSfera import

This commit is contained in:
Курнат Андрей
2026-06-07 10:20:04 +03:00
commit 2315f25754
16485 changed files with 4826827 additions and 0 deletions
@@ -0,0 +1,18 @@
package command
import (
"github.com/qsfera/server/services/postprocessing/pkg/config"
"github.com/spf13/cobra"
)
// Health is the entrypoint for the health command.
func Health(cfg *config.Config) *cobra.Command {
return &cobra.Command{
Use: "health",
Short: "Check health status",
RunE: func(cmd *cobra.Command, args []string) error {
// Not implemented
return nil
},
}
}
@@ -0,0 +1,88 @@
package command
import (
"context"
"github.com/qsfera/server/pkg/config/configlog"
"github.com/qsfera/server/pkg/generators"
"github.com/qsfera/server/services/postprocessing/pkg/config"
"github.com/qsfera/server/services/postprocessing/pkg/config/parser"
"github.com/opencloud-eu/reva/v2/pkg/events"
"github.com/opencloud-eu/reva/v2/pkg/events/stream"
"github.com/opencloud-eu/reva/v2/pkg/utils"
"github.com/spf13/cobra"
)
// RestartPostprocessing cli command to restart postprocessing
func RestartPostprocessing(cfg *config.Config) *cobra.Command {
restartPostprocessingCmd := &cobra.Command{
Use: "resume",
Aliases: []string{"restart"},
Short: "resume postprocessing for an uploadID",
PreRunE: func(cmd *cobra.Command, args []string) error {
return configlog.ReturnFatal(parser.ParseConfig(cfg))
},
RunE: func(cmd *cobra.Command, args []string) error {
connName := generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus)
stream, err := stream.NatsFromConfig(connName, false, stream.NatsConfig{
Endpoint: cfg.Postprocessing.Events.Endpoint,
Cluster: cfg.Postprocessing.Events.Cluster,
EnableTLS: cfg.Postprocessing.Events.EnableTLS,
TLSInsecure: cfg.Postprocessing.Events.TLSInsecure,
TLSRootCACertificate: cfg.Postprocessing.Events.TLSRootCACertificate,
AuthUsername: cfg.Postprocessing.Events.AuthUsername,
AuthPassword: cfg.Postprocessing.Events.AuthPassword,
})
if err != nil {
return err
}
uid, _ := cmd.Flags().GetString("upload-id")
step := ""
if uid == "" {
step, _ = cmd.Flags().GetString("step")
}
restart, _ := cmd.Flags().GetBool("restart")
var ev events.Unmarshaller
switch {
case restart:
ev = events.RestartPostprocessing{
UploadID: uid,
Timestamp: utils.TSNow(),
}
default:
ev = events.ResumePostprocessing{
UploadID: uid,
Step: events.Postprocessingstep(step),
Timestamp: utils.TSNow(),
}
}
return events.Publish(context.Background(), stream, ev)
},
}
restartPostprocessingCmd.Flags().StringP(
"upload-id",
"u",
"",
"the uploadid to resume. Ignored if unset.",
)
restartPostprocessingCmd.Flags().StringP(
"step",
"s",
"finished",
"resume all uploads in the given postprocessing step. Ignored if upload-id is set.",
)
restartPostprocessingCmd.Flags().BoolP(
"restart",
"r",
false,
"restart postprocessing for the given uploadID. Ignores the step flag.",
)
return restartPostprocessingCmd
}
@@ -0,0 +1,37 @@
package command
import (
"os"
"github.com/qsfera/server/pkg/clihelper"
"github.com/qsfera/server/services/postprocessing/pkg/config"
"github.com/spf13/cobra"
)
// GetCommands provides all commands for this service
func GetCommands(cfg *config.Config) []*cobra.Command {
return []*cobra.Command{
// start this service
Server(cfg),
// interaction with this service
RestartPostprocessing(cfg),
// infos about this service
Health(cfg),
Version(cfg),
}
}
// Execute is the entry point for the postprocessing command.
func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cobra.Command{
Use: "postprocessing",
Short: "starts postprocessing service",
})
app.AddCommand(GetCommands(cfg)...)
app.SetArgs(os.Args[1:])
return app.ExecuteContext(cfg.Context)
}
@@ -0,0 +1,98 @@
package command
import (
"context"
"fmt"
"os"
"os/signal"
"github.com/qsfera/server/pkg/log"
"github.com/qsfera/server/pkg/runner"
"github.com/qsfera/server/pkg/tracing"
"github.com/qsfera/server/services/postprocessing/pkg/config"
"github.com/qsfera/server/services/postprocessing/pkg/config/parser"
"github.com/qsfera/server/services/postprocessing/pkg/server/debug"
"github.com/qsfera/server/services/postprocessing/pkg/service"
"github.com/opencloud-eu/reva/v2/pkg/store"
"github.com/spf13/cobra"
microstore "go-micro.dev/v4/store"
)
// Server is the entrypoint for the server command.
func Server(cfg *config.Config) *cobra.Command {
return &cobra.Command{
Use: "server",
Short: fmt.Sprintf("start %s service without runtime (unsupervised mode)", cfg.Service.Name),
PreRunE: func(cmd *cobra.Command, args []string) error {
err := parser.ParseConfig(cfg)
if err != nil {
fmt.Printf("%v", err)
os.Exit(1)
}
return err
},
RunE: func(cmd *cobra.Command, args []string) error {
logger := log.Configure(cfg.Service.Name, cfg.Commons, cfg.LogLevel)
var cancel context.CancelFunc
if cfg.Context == nil {
cfg.Context, cancel = signal.NotifyContext(context.Background(), runner.StopSignals...)
defer cancel()
}
ctx := cfg.Context
traceProvider, err := tracing.GetTraceProvider(cmd.Context(), cfg.Commons.TracesExporter, cfg.Service.Name)
if err != nil {
return err
}
gr := runner.NewGroup()
{
st := store.Create(
store.Store(cfg.Store.Store),
store.TTL(cfg.Store.TTL),
microstore.Nodes(cfg.Store.Nodes...),
microstore.Database(cfg.Store.Database),
microstore.Table(cfg.Store.Table),
store.Authentication(cfg.Store.AuthUsername, cfg.Store.AuthPassword),
)
svc, err := service.NewPostprocessingService(ctx, logger, st, traceProvider, cfg)
if err != nil {
return err
}
gr.Add(runner.New(cfg.Service.Name+".svc", func() error {
return svc.Run()
}, func() {
svc.Close()
}))
}
{
debugServer, err := debug.Server(
debug.Logger(logger),
debug.Context(ctx),
debug.Config(cfg),
)
if err != nil {
logger.Info().Err(err).Str("transport", "debug").Msg("Failed to initialize server")
return err
}
gr.Add(runner.NewGolangHttpServerRunner("postprocessing_debug", debugServer))
}
grResults := gr.Run(ctx)
// return the first non-nil error found in the results
for _, grResult := range grResults {
if grResult.RunnerError != nil {
return grResult.RunnerError
}
}
return nil
},
}
}
@@ -0,0 +1,18 @@
package command
import (
"github.com/qsfera/server/services/postprocessing/pkg/config"
"github.com/spf13/cobra"
)
// Version prints the service versions of all running instances.
func Version(cfg *config.Config) *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "print the version of this binary and the running extension instances",
RunE: func(cmd *cobra.Command, args []string) error {
// not implemented
return nil
},
}
}