From cbe696c5bf1d3aeb986de71d82603eb7c3259083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Le=20Barbier?= Date: Wed, 8 May 2024 11:53:10 +0200 Subject: [PATCH] Demonstrate that infrastructure stack can be created and destroyed --- doc/resource.texinfo | 1 + src/package.lisp | 1 + src/poc.lisp | 9 ++++++--- src/resource.lisp | 6 ++++++ 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/doc/resource.texinfo b/doc/resource.texinfo index 4df1691..f992f43 100644 --- a/doc/resource.texinfo +++ b/doc/resource.texinfo @@ -42,3 +42,4 @@ modifying or examining the underlying resource. @include include/fun-org.melusina.cid-list-resources.texinfo @include include/fun-org.melusina.cid-resource-prerequisites.texinfo +@include include/fun-org.melusina.cid-sort-resources.texinfo diff --git a/src/package.lisp b/src/package.lisp index ab64dfb..061e71e 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -73,6 +73,7 @@ #:examine-differences-between-instance-and-resource #:resource-prerequisites #:resource-serial + #:sort-resources ;; Infrastructure Stacks #:stack-name ;; Simulators and Simulations diff --git a/src/poc.lisp b/src/poc.lisp index e19bb18..7b418ea 100644 --- a/src/poc.lisp +++ b/src/poc.lisp @@ -36,7 +36,10 @@ #:remove-property #:resource-prerequisites #:write-persistent-object - #:read-persistent-object) + #:read-persistent-object + #:sort-resources + #:create-resource + #:delete-resource) (:export #:configure-laboratory #:cloud-vendor @@ -404,7 +407,7 @@ defined, provisioned and modified as a unit.")) (loop :for prerequisite :in (slot-value instance 'resources) :for deep-prerequisites = (resource-prerequisites prerequisite) :append (cons prerequisite deep-prerequisites) :into prerequisites - :finally (return (remove-duplicates prerequisites :test #'eq)))))) + :finally (return (sort-resources (remove-duplicates prerequisites :test #'eq))))))) (support-initialize-tenant-slot-with-designator) (support-initialize-project-slot-with-designator) (finalize-resource-list))) @@ -442,7 +445,7 @@ defined, provisioned and modified as a unit.")) (defmethod create-resource ((instance infrastructure-stack)) (with-slots (resources) instance - (loop :for resource :in resources + (loop :for resource :in (reverse resources) :do (create-resource resource)))) (defmethod delete-resource ((instance infrastructure-stack)) diff --git a/src/resource.lisp b/src/resource.lisp index ad55e05..144ae1e 100644 --- a/src/resource.lisp +++ b/src/resource.lisp @@ -392,6 +392,12 @@ before its prerequisites.")) :append (cons prerequisite deep-prerequisites) :into prerequisites :finally (return (remove-duplicates prerequisites :test #'eq)))) +(defun sort-resources (resources) + "Sort RESOURCES so that any resource in the list appears before its prerequisites." + (flet ((require-p (resource1 resource2) + (member resource2 (resource-prerequisites resource1)))) + (sort resources #'require-p))) + ;;;; ;;;; Resource Lifecycle Methods