@@ -16,6 +16,7 @@ def initialize(user_audit_info)
1616
1717 def create ( message , lifecycle )
1818 app = nil
19+ warnings = [ ]
1920 AppModel . db . transaction do
2021 app = AppModel . create (
2122 name : message . name ,
@@ -24,6 +25,7 @@ def create(message, lifecycle)
2425 )
2526
2627 lifecycle . create_lifecycle_data_model ( app )
28+ warnings = validate_stack_state ( app , lifecycle )
2729 validate_buildpacks_are_ready ( app )
2830
2931 MetadataUpdate . update ( app , message )
@@ -43,10 +45,14 @@ def create(message, lifecycle)
4345 )
4446 end
4547
48+ app . instance_variable_set ( :@stack_warnings , warnings )
49+
4650 app
4751 rescue Sequel ::ValidationFailed => e
4852 v3_api_error! ( :UniquenessError , e . message ) if e . errors . on ( %i[ space_guid name ] )
4953
54+ raise InvalidApp . new ( e . message )
55+ rescue StackStateValidator ::DisabledStackError , StackStateValidator ::RestrictedStackError => e
5056 raise InvalidApp . new ( e . message )
5157 end
5258
@@ -74,5 +80,17 @@ def validate_buildpacks_are_ready(app)
7480 end
7581 end
7682 end
83+
84+ def validate_stack_state ( app , lifecycle )
85+ return [ ] if lifecycle . type == Lifecycles ::DOCKER
86+
87+ stack_name = app . lifecycle_data . try ( :stack )
88+ return [ ] unless stack_name
89+
90+ stack = Stack . find ( name : stack_name )
91+ return [ ] unless stack
92+
93+ StackStateValidator . validate_for_new_app! ( stack )
94+ end
7795 end
7896end
0 commit comments