Skip to content

Commit

Permalink
Merge pull request #36 from Cray-HPE/virtual-node-support
Browse files Browse the repository at this point in the history
Added support for the VirtualNode type
  • Loading branch information
shunr-hpe authored Sep 26, 2023
2 parents cce8c58 + e1f04ce commit 09f12a0
Show file tree
Hide file tree
Showing 41 changed files with 2,715 additions and 2,736 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.19.1
1.20.0
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.20.0] - 2023-09-08

### Added

- Added support for the VirtualNode type

## [1.19.1] - 2023-01-11

### Changed
Expand Down
126 changes: 62 additions & 64 deletions cmd/hbtd/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// (C) Copyright [2020-2021] Hewlett Packard Enterprise Development LP
// (C) Copyright [2020-2021,2023] Hewlett Packard Enterprise Development LP
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -30,10 +30,10 @@ import (
)

type Route struct {
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
Name string
Method string
Pattern string
HandlerFunc http.HandlerFunc
}

type Routes []Route
Expand All @@ -51,71 +51,69 @@ const (
URL_HEALTH = URL_ROOT + "/health"
)


// Generate the API routes
func newRouter(routes []Route) *mux.Router {
router := mux.NewRouter().StrictSlash(true)
for _, route := range routes {
var handler http.Handler
handler = route.HandlerFunc
router.
Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(handler)
}
return router
router := mux.NewRouter().StrictSlash(true)
for _, route := range routes {
var handler http.Handler
handler = route.HandlerFunc
router.
Methods(route.Method).
Path(route.Pattern).
Name(route.Name).
Handler(handler)
}
return router
}

// Create the API route descriptors.

func generateRoutes() Routes {
return Routes{
Route{"hbRcv",
strings.ToUpper("Post"),
URL_HEARTBEAT,
hbRcv,
},
Route{"hbRcvXName",
strings.ToUpper("Post"),
URL_HEARTBEAT + "/{xname}",
hbRcvXName,
},
Route{"params_get",
strings.ToUpper("Get"),
URL_PARAMS,
paramsIO,
},
Route{"params_patch",
strings.ToUpper("Patch"),
URL_PARAMS,
paramsIO,
},
Route{"doHealth",
strings.ToUpper("Get"),
URL_HEALTH,
doHealth,
},
Route{"doLiveness",
strings.ToUpper("Get"),
URL_LIVENESS,
doLiveness,
},
Route{"doReadiness",
strings.ToUpper("Get"),
URL_READINESS,
doReadiness,
},
Route{"hbStates",
strings.ToUpper("Post"),
URL_HB_STATES,
hbStates,
},
Route{"hbStateSingle",
strings.ToUpper("Get"),
URL_HB_STATE + "/{xname}",
hbStateSingle,
},
return Routes{
Route{"hbRcv",
strings.ToUpper("Post"),
URL_HEARTBEAT,
hbRcv,
},
Route{"hbRcvXName",
strings.ToUpper("Post"),
URL_HEARTBEAT + "/{xname}",
hbRcvXName,
},
Route{"params_get",
strings.ToUpper("Get"),
URL_PARAMS,
paramsIO,
},
Route{"params_patch",
strings.ToUpper("Patch"),
URL_PARAMS,
paramsIO,
},
Route{"doHealth",
strings.ToUpper("Get"),
URL_HEALTH,
doHealth,
},
Route{"doLiveness",
strings.ToUpper("Get"),
URL_LIVENESS,
doLiveness,
},
Route{"doReadiness",
strings.ToUpper("Get"),
URL_READINESS,
doReadiness,
},
Route{"hbStates",
strings.ToUpper("Post"),
URL_HB_STATES,
hbStates,
},
Route{"hbStateSingle",
strings.ToUpper("Get"),
URL_HB_STATE + "/{xname}",
hbStateSingle,
},
}
}

4 changes: 2 additions & 2 deletions cmd/hbtd/hbtd.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// (C) Copyright [2018-2021] Hewlett Packard Enterprise Development LP
// (C) Copyright [2018-2021,2023] Hewlett Packard Enterprise Development LP
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -52,7 +52,7 @@ import (
"syscall"
"time"

"github.com/Cray-HPE/hms-base"
"github.com/Cray-HPE/hms-base/v2"
"github.com/Cray-HPE/hms-hmetcd"
"github.com/Cray-HPE/hms-msgbus"
)
Expand Down
47 changes: 22 additions & 25 deletions cmd/hbtd/health.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// MIT License
//
// (C) Copyright [2020-2021] Hewlett Packard Enterprise Development LP
//
//
// (C) Copyright [2020-2021,2023] Hewlett Packard Enterprise Development LP
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Expand All @@ -20,8 +20,6 @@
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.



package main

import (
Expand All @@ -31,7 +29,7 @@ import (
"net/http"
"time"

"github.com/Cray-HPE/hms-base"
"github.com/Cray-HPE/hms-base/v2"
)

// HealthResponse - used to report service health stats
Expand All @@ -44,13 +42,12 @@ type HealthResponse struct {
var hsmReady = false
var stopCheckHSM = false


// Periodically check on the availability of HSM.

func checkHSM() {
var offBase int64

if (app_params.nosm.int_param != 0) {
if app_params.nosm.int_param != 0 {
return
}

Expand All @@ -59,33 +56,33 @@ func checkHSM() {
offBase = time.Now().Unix()

for {
if (stopCheckHSM) {
if stopCheckHSM {
return
}
lrdy := false
req,err := http.NewRequest("GET",url,nil)
if (err != nil) {
hbtdPrintf("ERROR: HSM check, can't create request: %v",err)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
hbtdPrintf("ERROR: HSM check, can't create request: %v", err)
} else {
base.SetHTTPUserAgent(req,serviceName)
rsp,rerr := htrans.client.Do(req)
if (rerr == nil) {
if (rsp.Body != nil) {
base.SetHTTPUserAgent(req, serviceName)
rsp, rerr := htrans.client.Do(req)
if rerr == nil {
if rsp.Body != nil {
rsp.Body.Close()
}
if (rsp.StatusCode == http.StatusOK) {
if rsp.StatusCode == http.StatusOK {
lrdy = true
}
}
}

hsmReady = lrdy
if (!lrdy) {
if !lrdy {
tdiff := time.Now().Unix() - offBase
hbtdPrintf("HSM is not responsive (%d seconds).",tdiff)
hbtdPrintf("HSM is not responsive (%d seconds).", tdiff)
} else {
offBase = time.Now().Unix()
if (!pstat) {
if !pstat {
offBase = time.Now().Unix()
hbtdPrintf("HSM is responsive.")
}
Expand All @@ -96,17 +93,17 @@ func checkHSM() {
}

//Wait until HSM is ready. NOTE: this may be temporary. There needs to
//be improvements on how to handle HSM coming and going. Once that is
//be improvements on how to handle HSM coming and going. Once that is
//done this may be able to be removed.

func waitForHSM() {
if (app_params.nosm.int_param != 0) {
if app_params.nosm.int_param != 0 {
return
}

hbtdPrintf("Waiting for HSM to be responsive...")
for {
if (hsmReady) {
if hsmReady {
return
}

Expand Down
11 changes: 5 additions & 6 deletions cmd/hbtd/health_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// MIT License
//
// (C) Copyright [2020-2021] Hewlett Packard Enterprise Development LP
// (C) Copyright [2020-2021,2023] Hewlett Packard Enterprise Development LP
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
Expand All @@ -20,14 +20,13 @@
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.


package main

import (
"fmt"
"crypto/tls"
"bytes"
"crypto/tls"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -212,7 +211,7 @@ func TestHealth(t *testing.T) {
if err != nil {
t.Fatalf("ERROR unmarshalling GET response body:%s", err.Error())
}
kp = fmt.Sprintf("Initialization key present: %s",HBTD_HEALTH_OK)
kp = fmt.Sprintf("Initialization key present: %s", HBTD_HEALTH_OK)
if stats.KvStoreStatus != kp {
t.Fatal("Expected KV Store initialized")
}
Expand All @@ -236,7 +235,7 @@ func TestHSMReadies(t *testing.T) {
t.Logf("**** Testing HSM readiness ****")
go checkHSM()
time.Sleep(10 * time.Second)
if (hsmReady == true) {
if hsmReady == true {
t.Errorf("HSM shows ready, should not be.")
}
stopCheckHSM = true
Expand Down
Loading

0 comments on commit 09f12a0

Please sign in to comment.