• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-server / 1622978334

13 Jan 2025 03:51PM UTC coverage: 72.802% (-3.8%) from 76.608%
1622978334

Pull #300

gitlab-ci

alfrunes
fix: Deployment device count should not exceed max devices

Added a condition to skip deployments when the device count reaches max
devices.

Changelog: Title
Ticket: MEN-7847
Signed-off-by: Alf-Rune Siqveland <alf.rune@northern.tech>
Pull Request #300: fix: Deployment device count should not exceed max devices

4251 of 6164 branches covered (68.96%)

Branch coverage included in aggregate %.

0 of 18 new or added lines in 1 file covered. (0.0%)

2544 existing lines in 83 files now uncovered.

42741 of 58384 relevant lines covered (73.21%)

21.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

76.92
/backend/services/deviceconnect/server/server.go
1
// Copyright 2023 Northern.tech AS
2
//
3
//    Licensed under the Apache License, Version 2.0 (the "License");
4
//    you may not use this file except in compliance with the License.
5
//    You may obtain a copy of the License at
6
//
7
//        http://www.apache.org/licenses/LICENSE-2.0
8
//
9
//    Unless required by applicable law or agreed to in writing, software
10
//    distributed under the License is distributed on an "AS IS" BASIS,
11
//    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
//    See the License for the specific language governing permissions and
13
//    limitations under the License.
14

15
package server
16

17
import (
18
        "context"
19
        "net/http"
20
        "os"
21
        "os/signal"
22
        "time"
23

24
        "golang.org/x/sys/unix"
25

26
        "github.com/mendersoftware/mender-server/pkg/config"
27
        "github.com/mendersoftware/mender-server/pkg/log"
28

29
        api "github.com/mendersoftware/mender-server/services/deviceconnect/api/http"
30
        "github.com/mendersoftware/mender-server/services/deviceconnect/app"
31
        "github.com/mendersoftware/mender-server/services/deviceconnect/client/nats"
32
        "github.com/mendersoftware/mender-server/services/deviceconnect/client/workflows"
33
        dconfig "github.com/mendersoftware/mender-server/services/deviceconnect/config"
34
        "github.com/mendersoftware/mender-server/services/deviceconnect/store"
35
)
36

37
// InitAndRun initializes the server and runs it
38
func InitAndRun(conf config.Reader, dataStore store.DataStore) error {
2✔
39
        ctx := context.Background()
2✔
40

2✔
41
        log.Setup(conf.GetBool(dconfig.SettingDebugLog))
2✔
42
        l := log.FromContext(ctx)
2✔
43

2✔
44
        allowedOrigin := conf.GetStringSlice(dconfig.SettingWSAllowedOrigins)
2✔
45
        if allowedOrigin != nil {
4✔
46
                api.SetAcceptedOrigins(allowedOrigin)
2✔
47
        }
2✔
48

49
        natsClient, err := nats.NewClientWithDefaults(
2✔
50
                config.Config.GetString(dconfig.SettingNatsURI),
2✔
51
        )
2✔
52
        if err != nil {
2✔
53
                return err
×
54
        }
×
55
        wflows := workflows.NewClient(
2✔
56
                config.Config.GetString(dconfig.SettingWorkflowsURL),
2✔
57
        )
2✔
58
        deviceConnectApp := app.New(
2✔
59
                dataStore, wflows, app.Config{
2✔
60
                        HaveAuditLogs: conf.GetBool(dconfig.SettingEnableAuditLogs),
2✔
61
                },
2✔
62
        )
2✔
63

2✔
64
        gracefulShutdownTimeout := conf.GetDuration(dconfig.SettingGracefulShutdownTimeout)
2✔
65
        router, err := api.NewRouter(deviceConnectApp, natsClient, &api.RouterConfig{
2✔
66
                GracefulShutdownTimeout: gracefulShutdownTimeout,
2✔
67
        })
2✔
68
        if err != nil {
2✔
69
                l.Fatal(err)
×
70
        }
×
71

72
        var listen = conf.GetString(dconfig.SettingListen)
2✔
73
        srv := &http.Server{
2✔
74
                Addr:    listen,
2✔
75
                Handler: router,
2✔
76
        }
2✔
77

2✔
78
        go func() {
4✔
79
                if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed {
2✔
80
                        l.Fatalf("listen: %s\n", err)
×
81
                }
×
82
        }()
83

84
        quit := make(chan os.Signal, 1)
2✔
85
        signal.Notify(quit, unix.SIGINT, unix.SIGTERM, unix.SIGUSR1)
2✔
86
        recvSignal := <-quit
2✔
87

2✔
88
        l.Info("server shutdown")
2✔
89

2✔
90
        if recvSignal == unix.SIGUSR1 {
2✔
91
                l.Info("received SIGUSR1, graceful shutdown")
×
92
                srv.RegisterOnShutdown(func() {
×
93
                        deviceConnectApp.Shutdown(gracefulShutdownTimeout)
×
94
                })
×
95
        }
96

97
        ctxWithTimeout, cancel := context.WithTimeout(ctx, 5*time.Second)
2✔
98
        defer cancel()
2✔
99
        if err := srv.Shutdown(ctxWithTimeout); err != nil {
2✔
100
                l.Fatal("error when shutting down the server ", err)
×
101
        }
×
102
        l.Info("server exited")
2✔
103

2✔
104
        if recvSignal == unix.SIGUSR1 {
2✔
UNCOV
105
                deviceConnectApp.ShutdownDone()
×
106
                l.Info("graceful shutdown completed")
×
107
        }
×
108

109
        return nil
2✔
110
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc