Merge pull request #222 from openziti/fix-session-create-response

Fix session create response. fail faster on rotating hs tests
This commit is contained in:
Paul Lorenz
2020-06-22 11:53:49 -04:00
committed by GitHub
10 changed files with 49 additions and 249 deletions
@@ -30,7 +30,7 @@ import (
const EntityNameSession = "sessions"
var SessionLinkFactory = NewBasicLinkFactory(EntityNameApiSession)
var SessionLinkFactory = NewBasicLinkFactory(EntityNameSession)
func MapCreateSessionToModel(apiSessionId string, session *rest_model.SessionCreate) *model.Session {
ret := &model.Session{
@@ -34,18 +34,13 @@ func (nsr *SessionRequestResponder) RespondWithCreatedId(id string, link rest_mo
nsr.RespondWithError(err)
return
}
edgeRouters, _ := getSessionEdgeRouters(nsr.ae, modelSession)
restModel, err := MapSessionToRestModel(nsr.ae, modelSession)
if err != nil {
nsr.RespondWithError(err)
return
}
newSessionEnvelope := &rest_model.SessionCreateEnvelope{
Data: &rest_model.SessionCreateLocation{
CreateLocation: rest_model.CreateLocation{
Links: rest_model.Links{
"self": link,
},
ID: id,
},
Token: modelSession.Token,
EdgeRouters: edgeRouters,
},
Data: restModel,
Meta: &rest_model.Meta{},
}
+3 -3
View File
@@ -33,9 +33,9 @@ require (
github.com/michaelquigley/pfxlog v0.0.0-20190813191113-2be43bd0dccc
github.com/miekg/dns v1.1.29
github.com/mitchellh/mapstructure v1.3.2
github.com/openziti/fabric v0.11.49
github.com/openziti/foundation v0.11.8
github.com/openziti/sdk-golang v0.13.11
github.com/openziti/fabric v0.11.50
github.com/openziti/foundation v0.11.9
github.com/openziti/sdk-golang v0.13.12
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.6.0
github.com/spf13/cobra v0.0.7
+6 -6
View File
@@ -287,12 +287,12 @@ github.com/onsi/ginkgo v1.7.0 h1:WSHQ+IS43OoUrWtD1/bbclrwK8TTH5hzp+umCiuxHgs=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/gomega v1.4.3 h1:RE1xgDvH7imwFD45h+u2SgIfERHlS2yNG4DObb5BSKU=
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
github.com/openziti/fabric v0.11.49 h1:xsR/Llz+sTYxZh3OuFRulUJoIQsINAmsqFHJoebq6t4=
github.com/openziti/fabric v0.11.49/go.mod h1:GNOqnzKXDpffv100R92uWv4v65aotI4AWkXGWK3N62c=
github.com/openziti/foundation v0.11.8 h1:fcJzxdtU1URLwPB6DHRLlod+by4TMXYmMPWxOKu2vEw=
github.com/openziti/foundation v0.11.8/go.mod h1:Qdd7eCuTrpRwEeDbvYy89sFbEY4+J7OuX8UygxNBsvY=
github.com/openziti/sdk-golang v0.13.11 h1:VlaW8H2dOeq4LwZtc5VFObjcI9YJW+rNNVA43LYKAec=
github.com/openziti/sdk-golang v0.13.11/go.mod h1:CQFpRGd/+x/i5uHdnXaY7V1Eusb6siCmZcF7vVhUXKo=
github.com/openziti/fabric v0.11.50 h1:9/qTkRzmlKV4uxbuZ5f2oaQbU23KuTmHZLLwnEms7to=
github.com/openziti/fabric v0.11.50/go.mod h1:tVOEFvCM470TVHZxLzthpDa0mvj5rapg5HzbERB5n60=
github.com/openziti/foundation v0.11.9 h1:tPXs7gYFGyGznySUtKY4TvBe8grbv8WYH4KA1g0M4SU=
github.com/openziti/foundation v0.11.9/go.mod h1:Qdd7eCuTrpRwEeDbvYy89sFbEY4+J7OuX8UygxNBsvY=
github.com/openziti/sdk-golang v0.13.12 h1:y2eeh3LEmyvIY2s0ZxHsThoyvtKHbns5ofLqvtw8RQ0=
github.com/openziti/sdk-golang v0.13.12/go.mod h1:9nBR/FCfLEDh3MQWx+RblGsEUMEYD0jbIdu2ckGNXlU=
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6 h1:lNCW6THrCKBiJBpz8kbVGjC7MgdCGKwuvBgc7LoD6sw=
github.com/orcaman/concurrent-map v0.0.0-20190826125027-8c72a8bb44f6/go.mod h1:Lu3tH6HLW3feq74c2GC+jIMS/K2CFcDWnWD9XkenwhI=
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
+1 -1
View File
@@ -41,7 +41,7 @@ import (
type SessionCreateEnvelope struct {
// data
Data *SessionCreateLocation `json:"data,omitempty"`
Data *SessionDetail `json:"data,omitempty"`
// meta
Meta *Meta `json:"meta,omitempty"`
-166
View File
@@ -1,166 +0,0 @@
// Code generated by go-swagger; DO NOT EDIT.
//
// Copyright NetFoundry, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// __ __ _
// \ \ / / (_)
// \ \ /\ / /_ _ _ __ _ __ _ _ __ __ _
// \ \/ \/ / _` | '__| '_ \| | '_ \ / _` |
// \ /\ / (_| | | | | | | | | | | (_| | : This file is generated, do not edit it.
// \/ \/ \__,_|_| |_| |_|_|_| |_|\__, |
// __/ |
// |___/
package rest_model
// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command
import (
"strconv"
"github.com/go-openapi/errors"
"github.com/go-openapi/strfmt"
"github.com/go-openapi/swag"
)
// SessionCreateLocation session create location
//
// swagger:model sessionCreateLocation
type SessionCreateLocation struct {
CreateLocation
// edge routers
EdgeRouters []*SessionEdgeRouter `json:"edgeRouters"`
// token
Token string `json:"token,omitempty"`
}
// UnmarshalJSON unmarshals this object from a JSON structure
func (m *SessionCreateLocation) UnmarshalJSON(raw []byte) error {
// AO0
var aO0 CreateLocation
if err := swag.ReadJSON(raw, &aO0); err != nil {
return err
}
m.CreateLocation = aO0
// AO1
var dataAO1 struct {
EdgeRouters []*SessionEdgeRouter `json:"edgeRouters"`
Token string `json:"token,omitempty"`
}
if err := swag.ReadJSON(raw, &dataAO1); err != nil {
return err
}
m.EdgeRouters = dataAO1.EdgeRouters
m.Token = dataAO1.Token
return nil
}
// MarshalJSON marshals this object to a JSON structure
func (m SessionCreateLocation) MarshalJSON() ([]byte, error) {
_parts := make([][]byte, 0, 2)
aO0, err := swag.WriteJSON(m.CreateLocation)
if err != nil {
return nil, err
}
_parts = append(_parts, aO0)
var dataAO1 struct {
EdgeRouters []*SessionEdgeRouter `json:"edgeRouters"`
Token string `json:"token,omitempty"`
}
dataAO1.EdgeRouters = m.EdgeRouters
dataAO1.Token = m.Token
jsonDataAO1, errAO1 := swag.WriteJSON(dataAO1)
if errAO1 != nil {
return nil, errAO1
}
_parts = append(_parts, jsonDataAO1)
return swag.ConcatJSON(_parts...), nil
}
// Validate validates this session create location
func (m *SessionCreateLocation) Validate(formats strfmt.Registry) error {
var res []error
// validation for a type composition with CreateLocation
if err := m.CreateLocation.Validate(formats); err != nil {
res = append(res, err)
}
if err := m.validateEdgeRouters(formats); err != nil {
res = append(res, err)
}
if len(res) > 0 {
return errors.CompositeValidationError(res...)
}
return nil
}
func (m *SessionCreateLocation) validateEdgeRouters(formats strfmt.Registry) error {
if swag.IsZero(m.EdgeRouters) { // not required
return nil
}
for i := 0; i < len(m.EdgeRouters); i++ {
if swag.IsZero(m.EdgeRouters[i]) { // not required
continue
}
if m.EdgeRouters[i] != nil {
if err := m.EdgeRouters[i].Validate(formats); err != nil {
if ve, ok := err.(*errors.Validation); ok {
return ve.ValidateName("edgeRouters" + "." + strconv.Itoa(i))
}
return err
}
}
}
return nil
}
// MarshalBinary interface implementation
func (m *SessionCreateLocation) MarshalBinary() ([]byte, error) {
if m == nil {
return nil, nil
}
return swag.WriteJSON(m)
}
// UnmarshalBinary interface implementation
func (m *SessionCreateLocation) UnmarshalBinary(b []byte) error {
var res SessionCreateLocation
if err := swag.ReadJSON(b, &res); err != nil {
return err
}
*m = res
return nil
}
+2 -46
View File
@@ -7301,35 +7301,13 @@ func init() {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/sessionCreateLocation"
"$ref": "#/definitions/sessionDetail"
},
"meta": {
"$ref": "#/definitions/meta"
}
}
},
"sessionCreateLocation": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/createLocation"
},
{
"type": "object",
"properties": {
"edgeRouters": {
"type": "array",
"items": {
"$ref": "#/definitions/sessionEdgeRouter"
}
},
"token": {
"type": "string"
}
}
}
]
},
"sessionDetail": {
"type": "object",
"allOf": [
@@ -22944,35 +22922,13 @@ func init() {
"type": "object",
"properties": {
"data": {
"$ref": "#/definitions/sessionCreateLocation"
"$ref": "#/definitions/sessionDetail"
},
"meta": {
"$ref": "#/definitions/meta"
}
}
},
"sessionCreateLocation": {
"type": "object",
"allOf": [
{
"$ref": "#/definitions/createLocation"
},
{
"type": "object",
"properties": {
"edgeRouters": {
"type": "array",
"items": {
"$ref": "#/definitions/sessionEdgeRouter"
}
},
"token": {
"type": "string"
}
}
}
]
},
"sessionDetail": {
"type": "object",
"allOf": [
+1 -13
View File
@@ -4897,7 +4897,7 @@ definitions:
meta:
$ref: '#/definitions/meta'
data:
$ref: '#/definitions/sessionCreateLocation'
$ref: '#/definitions/sessionDetail'
enrollmentCertsEnvelope:
type: object
properties:
@@ -4905,18 +4905,6 @@ definitions:
$ref: '#/definitions/meta'
data:
$ref: '#/definitions/enrollmentCerts'
sessionCreateLocation:
type: object
allOf:
- $ref: '#/definitions/createLocation'
- type: object
properties:
token:
type: string
edgeRouters:
type: array
items:
$ref: '#/definitions/sessionEdgeRouter'
version:
type: object
properties:
+19
View File
@@ -37,6 +37,7 @@ import (
"github.com/openziti/fabric/router/xgress"
"github.com/openziti/foundation/identity/certtools"
"github.com/openziti/foundation/util/concurrenz"
"github.com/openziti/foundation/util/debugz"
nfpem "github.com/openziti/foundation/util/pem"
sdkconfig "github.com/openziti/sdk-golang/ziti/config"
"github.com/openziti/sdk-golang/ziti/edge"
@@ -84,6 +85,24 @@ func init() {
transport.AddAddressParser(quic.AddressParser{})
transport.AddAddressParser(tls.AddressParser{})
transport.AddAddressParser(tcp.AddressParser{})
go debugStuckTests()
}
func debugStuckTests() {
iterations := 1
lastStack := ""
for iterations < 21 {
time.Sleep(time.Minute)
stack := debugz.GenerateStack()
fmt.Printf("minute %v\n", iterations)
if stack == lastStack {
fmt.Println("Stack unchanged")
} else {
fmt.Println(stack)
}
lastStack = stack
}
}
type TestContext struct {
+10 -2
View File
@@ -122,7 +122,11 @@ func testClientFirstWithStrategy(ctx *TestContext, strategy string) {
logger := pfxlog.Logger()
for i := 0; i < 250; i++ {
<-dials
select {
case <-time.After(time.Second * 10):
// let it fall through and try to dial
case <-dials:
}
count := atomic.AddInt32(&dialCount, -1)
logger.Debugf("consumed dial capacity. Available: %v", count)
@@ -236,7 +240,11 @@ func testServerFirstWithStrategy(ctx *TestContext, strategy string) {
clientContext := ziti.NewContextWithConfig(clientConfig)
for i := 0; i < 250; i++ {
<-dials
select {
case <-time.After(time.Second * 10):
// let it fall through and try to dial
case <-dials:
}
conn := ctx.WrapConn(clientContext.Dial(service.Name))
name := conn.ReadString(1024, time.Second)
conn.WriteString("hello, "+name, time.Second)