Skip to content

Commit 3a40231

Browse files
authored
Add state_reason in Stack object (#4823)
* Add state_reason in Stack object See RFC#0045 (Stack Management) Includes state_reason in Stack Validation Error and Warning --------- Signed-off-by: Rashed Kamal <rashed.kamal@broadcom.com>
1 parent 88aa499 commit 3a40231

File tree

19 files changed

+526
-9
lines changed

19 files changed

+526
-9
lines changed

app/actions/stack_create.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ def create(message)
1313
stack = VCAP::CloudController::Stack.create(
1414
name: message.name,
1515
description: message.description,
16-
state: message.state
16+
state: message.state,
17+
state_reason: message.state_reason
1718
)
1819

1920
MetadataUpdate.update(stack, message)

app/actions/stack_update.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ def initialize(user_audit_info)
1212

1313
def update(stack, message)
1414
stack.db.transaction do
15-
stack.update(state: message.state) if message.requested?(:state)
15+
stack_updates = {}
16+
stack_updates[:state] = message.state if message.requested?(:state)
17+
stack_updates[:state_reason] = message.state_reason if message.state_reason_requested?
18+
stack.update(stack_updates) if stack_updates.any?
19+
1620
MetadataUpdate.update(stack, message)
1721
Repositories::StackEventRepository.new.record_stack_update(stack, @user_audit_info, message.audit_hash)
1822
end

app/messages/stack_create_message.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33

44
module VCAP::CloudController
55
class StackCreateMessage < MetadataBaseMessage
6-
register_allowed_keys %i[name description state]
6+
register_allowed_keys %i[name description state state_reason]
77

88
validates :name, presence: true, length: { maximum: 250 }
99
validates :description, length: { maximum: 250 }
1010
validates :state, inclusion: { in: StackStates::VALID_STATES, message: "must be one of #{StackStates::VALID_STATES.join(', ')}" }, allow_nil: false, if: :state_requested?
11+
validates :state_reason, length: { maximum: 5000 }, allow_nil: true
1112

1213
def state_requested?
1314
requested?(:state)

app/messages/stack_update_message.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33

44
module VCAP::CloudController
55
class StackUpdateMessage < MetadataBaseMessage
6-
register_allowed_keys [:state]
6+
register_allowed_keys %i[state state_reason]
77

88
validates_with NoAdditionalKeysValidator
99
validates :state, inclusion: { in: StackStates::VALID_STATES, message: "must be one of #{StackStates::VALID_STATES.join(', ')}" }, allow_nil: false, if: :state_requested?
10+
validates :state_reason, length: { maximum: 5000 }, allow_nil: true
1011

1112
def state_requested?
1213
requested?(:state)
1314
end
15+
16+
def state_reason_requested?
17+
requested?(:state_reason)
18+
end
1419
end
1520
end

app/presenters/v3/stack_presenter.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def to_hash
1313
name: stack.name,
1414
description: stack.description,
1515
state: stack.state,
16+
state_reason: stack.state_reason,
1617
run_rootfs_image: stack.run_rootfs_image,
1718
build_rootfs_image: stack.build_rootfs_image,
1819
default: stack.default?,
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
Sequel.migration do
2+
up do
3+
alter_table :stacks do
4+
add_column :state_reason, String, null: true, size: 5000 unless @db.schema(:stacks).map(&:first).include?(:state_reason)
5+
end
6+
end
7+
8+
down do
9+
alter_table :stacks do
10+
drop_column :state_reason if @db.schema(:stacks).map(&:first).include?(:state_reason)
11+
end
12+
end
13+
end

docs/v3/source/includes/api_resources/_stacks.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"name": "my-stack",
77
"description": "Here is my stack!",
88
"state": "ACTIVE",
9+
"state_reason": null,
910
"build_rootfs_image": "my-stack",
1011
"run_rootfs_image": "my-stack",
1112
"default": true,
@@ -47,6 +48,7 @@
4748
"run_rootfs_image": "my-stack-1-run",
4849
"description": "This is my first stack!",
4950
"state": "ACTIVE",
51+
"state_reason": null,
5052
"default": true,
5153
"metadata": {
5254
"labels": {},
@@ -67,6 +69,7 @@
6769
"build_rootfs_image": "my-stack-2-build",
6870
"run_rootfs_image": "my-stack-2-run",
6971
"state": "DEPRECATED",
72+
"state_reason": "Stack deprecated and will be removed in future release",
7073
"default": false,
7174
"metadata": {
7275
"labels": {},
@@ -91,6 +94,7 @@
9194
"name": "my-stack",
9295
"description": "Here is my stack!",
9396
"state": "DISABLED",
97+
"state_reason": "Stack disabled and cannot be used for staging new application",
9498
"build_rootfs_image": "my-stack",
9599
"run_rootfs_image": "my-stack",
96100
"default": true,

docs/v3/source/includes/resources/stacks/_create.md.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ curl "https://api.example.org/v3/stacks" \
1313
"name": "my-stack",
1414
"description": "Here is my stack!",
1515
"state": "ACTIVE",
16+
"state_reason": "",
1617
}'
1718
```
1819

@@ -44,6 +45,7 @@ Name | Type | Description | Default
4445
**metadata.labels** | [_label object_](#labels) | Labels applied to the stack
4546
**metadata.annotations** | [_annotation object_](#annotations) | Annotations applied to the stack
4647
**state** | string | The state of the stack; valid states are: `ACTIVE`, `RESTRICTED`, `DEPRECATED`, `DISABLED`
48+
**state_reason** | string | Optional plain text describing the stack state change
4749

4850
#### Permitted roles
4951
|

docs/v3/source/includes/resources/stacks/_object.md.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Name | Type | Description
1515
**name** | _string_ | The name of the stack
1616
**description** | _string_ | The description of the stack
1717
**state** | string | The state of the stack; valid states are: `ACTIVE`, `RESTRICTED`, `DEPRECATED`, `DISABLED`
18+
**state_reason** | string | Optional plain text describing the stack state change
1819
**build_rootfs_image** | _string | The name of the stack image associated with staging/building Apps. If a stack does not have unique images, this will be the same as the stack name.
1920
**run_rootfs_image** | _string | The name of the stack image associated with running Apps + Tasks. If a stack does not have unique images, this will be the same as the stack name.
2021
**default** | _boolean_ | Whether the stack is configured to be the default stack for new applications.

docs/v3/source/includes/resources/stacks/_update.md.erb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ curl "https://api.example.org/v3/stacks/[guid]" \
99
-X PATCH \
1010
-H "Authorization: bearer [token]" \
1111
-H "Content-Type: application/json" \
12-
-d '{ "metadata": { "labels": { "key": "value" }, "annotations": {"note": "detailed information"}},"state":"ACTIVE"}'
12+
-d '{ "metadata": { "labels": { "key": "value" }, "annotations": {"note": "detailed information"}},"state":"ACTIVE", "state_reason": "Optional plain text describing the stack state change" }'
1313

1414
```
1515

@@ -34,6 +34,7 @@ Name | Type | Description
3434
**metadata.labels** | [_label object_](#labels) | Labels applied to the stack
3535
**metadata.annotations** | [_annotation object_](#annotations) | Annotations applied to the stack
3636
**state** | string | The state of the stack; valid states are: `ACTIVE`, `RESTRICTED`, `DEPRECATED`, `DISABLED`
37+
**state_reason** | string | Optional plain text describing the stack state change
3738

3839
#### Permitted roles
3940
|

0 commit comments

Comments
 (0)