Skip to content

Commit

Permalink
feat(pkger): extend stacks with update functionality
Browse files Browse the repository at this point in the history
references: #18548
  • Loading branch information
jsteenb2 committed Jun 17, 2020
1 parent 9288dc7 commit 2525a56
Show file tree
Hide file tree
Showing 13 changed files with 921 additions and 194 deletions.
8 changes: 8 additions & 0 deletions cmd/influx/pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,14 @@ func (f *fakePkgSVC) ExportStack(ctx context.Context, orgID, stackID influxdb.ID
panic("not implemented")
}

func (f *fakePkgSVC) ReadStack(ctx context.Context, id influxdb.ID) (pkger.Stack, error) {
panic("not implemented")
}

func (f *fakePkgSVC) UpdateStack(ctx context.Context, upd pkger.StackUpdate) (pkger.Stack, error) {
panic("not implemented")
}

func (f *fakePkgSVC) CreatePkg(ctx context.Context, setters ...pkger.CreatePkgSetFn) (*pkger.Pkg, error) {
if f.createFn != nil {
return f.createFn(ctx, setters...)
Expand Down
73 changes: 70 additions & 3 deletions cmd/influxd/launcher/pkger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ func TestLauncher_Pkger(t *testing.T) {
newStack, err := svc.InitStack(ctx, l.User.ID, stack)
require.NoError(t, err)

assert.NotZero(t, newStack.OrgID)
assert.Equal(t, l.Org.ID, newStack.OrgID)
assert.Equal(t, stack.Name, newStack.Name)
assert.Equal(t, stack.Description, newStack.Description)
assert.Equal(t, stack.URLs, newStack.URLs)
assert.NotNil(t, newStack.Resources)
assert.NotNil(t, newStack.Resources, "failed to match stack resorces")
expectedURLs := stack.URLs
if expectedURLs == nil {
expectedURLs = []string{}
}
assert.Equal(t, expectedURLs, newStack.URLs, "failed to match stack URLs")
assert.NotZero(t, newStack.CRUDLog)

return newStack, func() {
Expand Down Expand Up @@ -371,6 +375,65 @@ func TestLauncher_Pkger(t *testing.T) {
})
})

t.Run("read a stack", func(t *testing.T) {
stacks, err := svc.ListStacks(ctx, l.Org.ID, pkger.ListFilter{})
require.NoError(t, err)
require.Empty(t, stacks)

newStack1, cleanup1 := newStackFn(t, pkger.Stack{
Name: "first stack",
})
defer cleanup1()

newStack2, cleanup2 := newStackFn(t, pkger.Stack{
Name: "second stack",
})
defer cleanup2()

actual, err := svc.ReadStack(ctx, newStack1.ID)
require.NoError(t, err)
assert.Equal(t, newStack1, actual)

actual, err = svc.ReadStack(ctx, newStack2.ID)
require.NoError(t, err)
assert.Equal(t, newStack2, actual)

_, err = svc.ReadStack(ctx, influxdb.ID(9000))
require.Equal(t, influxdb.ENotFound, influxdb.ErrorCode(err))
})

t.Run("updating a stack", func(t *testing.T) {
stack, cleanup := newStackFn(t, pkger.Stack{
OrgID: l.Org.ID,
Name: "first name",
Description: "first desc",
URLs: []string{},
})
defer cleanup()

assertStack := func(t *testing.T, st pkger.Stack) {
t.Helper()
assert.Equal(t, stack.ID, st.ID)
assert.Equal(t, "2nd name", st.Name)
assert.Equal(t, "2nd desc", st.Description)
assert.Equal(t, []string{"http://example.com"}, st.URLs)
assert.True(t, st.UpdatedAt.After(stack.UpdatedAt))
}

updStack, err := svc.UpdateStack(ctx, pkger.StackUpdate{
ID: stack.ID,
Name: strPtr("2nd name"),
Description: strPtr("2nd desc"),
URLs: []string{"http://example.com"},
})
require.NoError(t, err)
assertStack(t, updStack)

readStack, err := svc.ReadStack(ctx, stack.ID)
require.NoError(t, err)
assertStack(t, readStack)
})

t.Run("apply with only a stackID succeeds when stack has URLs", func(t *testing.T) {
svr := httptest.NewServer(nethttp.HandlerFunc(func(w nethttp.ResponseWriter, r *nethttp.Request) {
pkg := newPkg(newBucketObject("bucket-0", "", ""))
Expand Down Expand Up @@ -3664,3 +3727,7 @@ func sortLabels(labels []pkger.SummaryLabel) {
return labels[i].Name < labels[j].Name
})
}

func strPtr(s string) *string {
return &s
}
175 changes: 105 additions & 70 deletions http/swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4725,52 +4725,7 @@ paths:
stacks:
type: array
items:
type: object
properties:
id:
type: string
orgID:
type: string
name:
type: string
description:
type: string
sources:
type: array
items:
type: string
urls:
type: array
items:
type: string
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
resources:
type: object
properties:
apiVersion:
type: string
resourceID:
type: string
kind:
type: string
pkgName:
type: string
associations:
type: array
items:
type: object
properties:
kind:
type: string
pkgName:
type: string
$ref: "#/components/schemas/Stack"
default:
description: Unexpected error
content:
Expand All @@ -4781,9 +4736,9 @@ paths:
operationId: CreateStack
tags:
- InfluxPackages
summary: Create a new Influx package
summary: Create a new stack
requestBody:
description: Influx package to create.
description: Influx stack to create.
required: true
content:
application/json:
Expand All @@ -4806,35 +4761,66 @@ paths:
content:
application/json:
schema:
type: object
properties:
id:
type: string
orgID:
type: string
name:
type: string
description:
type: string
urls:
type: array
items:
type: string
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
$ref: "#/components/schemas/Stack"
default:
description: Unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
/packages/stacks/{stack_id}:
get:
operationId: ReadStack
tags:
- InfluxPackages
summary: Grab a stack by its ID
responses:
"200":
description: Read an influx stack by ID
content:
application/json:
schema:
$ref: "#/components/schemas/Stack"
default:
description: Unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
post:
operationId: UpdateStack
tags:
- InfluxPackages
summary: Update a an Influx Stack
requestBody:
description: Influx stack to update.
required: true
content:
application/json:
schema:
type: object
properties:
name:
type: string
description:
type: string
urls:
type: array
items:
type: string
responses:
"200":
description: Influx stack updated
content:
application/json:
schema:
$ref: "#/components/schemas/Stack"
default:
description: Unexpected error
content:
application/json:
schema:
$ref: "#/components/schemas/Error"
delete:
operationId: DeleteStack
tags:
Expand Down Expand Up @@ -8395,6 +8381,55 @@ components:
type: integer
properties: # field name is properties
$ref: "#/components/schemas/ViewProperties"
Stack:
type: object
properties:
id:
type: string
orgID:
type: string
name:
type: string
description:
type: string
sources:
type: array
items:
type: string
resources:
type: array
items:
type: object
properties:
apiVersion:
type: string
resourceID:
type: string
kind:
type: string
pkgName:
type: string
associations:
type: array
items:
type: object
properties:
kind:
type: string
pkgName:
type: string
urls:
type: array
items:
type: string
createdAt:
type: string
format: date-time
readOnly: true
updatedAt:
type: string
format: date-time
readOnly: true
Runs:
type: object
properties:
Expand Down
Loading

0 comments on commit 2525a56

Please sign in to comment.