// ĠCopyright Ġ 2 0 1 9 ĠAmazon . com , ĠInc . Ġor Ġits Ġaffiliates . ĠAll ĠRights ĠReserved . Ċ // ĠSPDX - License - Identifier : ĠApache - 2 . 0 Ċ Ċ package Ġsoftware . aws . tool k its . jetbrains . services . cloudformation Ċ Ċ import Ġcom . intellij . ide . util . tree View . Abstract TreeNode Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġicons . Aws Icons Ċ import Ġsoftware . amazon . aw ssdk . services . cloudformation . Cloud Formation Client Ċ import Ġsoftware . amazon . aw ssdk . services . cloudformation . model . Resource Status Ċ import Ġsoftware . amazon . aw ssdk . services . cloudformation . model . Stack Status Ċ import Ġsoftware . amazon . aw ssdk . services . lambda . Lambda Client Ċ import Ġsoftware . aws . tool k its . jetbrains . core . Aws Client Manager Ċ import Ġsoftware . aws . tool k its . jetbrains . core . Delete Resource Action Ċ import Ġsoftware . aws . tool k its . jetbrains . core . aws Client Ċ import Ġsoftware . aws . tool k its . jetbrains . core . explorer . Aws Explorer Empty Node Ċ import Ġsoftware . aws . tool k its . jetbrains . core . explorer . Aws Explorer Error Node Ċ import Ġsoftware . aws . tool k its . jetbrains . core . explorer . Aws Explorer Node Ċ import Ġsoftware . aws . tool k its . jetbrains . core . explorer . Aws Explorer Resource Node Ċ import Ġsoftware . aws . tool k its . jetbrains . core . explorer . Aws Explorer Service Root Node Ċ import Ġsoftware . aws . tool k its . jetbrains . core . explorer . Aws Node Always Expand able Ċ import Ġsoftware . aws . tool k its . jetbrains . core . explorer . Aws Node Child Cache Ċ import Ġsoftware . aws . tool k its . jetbrains . core . explorer . Aws Truncated Result Node Ċ import Ġsoftware . aws . tool k its . jetbrains . core . stack . open Stack Ċ import Ġsoftware . aws . tool k its . jetbrains . services . lambda . Lambda Function Node Ċ import Ġsoftware . aws . tool k its . jetbrains . services . lambda . to Data Class Ċ import Ġsoftware . aws . tool k its . jetbrains . utils . to Human Readable Ċ import Ġsoftware . aws . tool k its . resources . message Ċ import Ġjavax . swing . tree . Default Mutable TreeNode Ċ import Ġjavax . swing . tree . Default Tree Model Ċ Ċ class ĠCloudFormation Service Node ( project : ĠProject ) Ġ: ĠAws Explorer Service Root Node ( project , Ġmessage (" explorer . node . cloudformation ")) Ġ{ ĊĠĠĠ Ġoverride Ġfun ĠserviceName () Ġ= ĠCloudFormation Client . SERVICE _ NAME ĊĊĠĠĠ Ġprivate Ġval Ġclient : ĠCloudFormation Client Ġ= ĠAws Client Manager . getInstance ( project ). getClient () ĊĊĠĠĠ Ġoverride Ġfun Ġload Resources ( pagination Token : ĠString ?): ĠCollection < Aws Explorer Node <* >> Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġclient . describe Stack s Ġ{ Ġrequest Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpagination Token ?. let Ġ{ Ġrequest . nextToken ( it ) Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġval Ġnodes Ġ= Ġresponse . stacks (). filter NotNull (). as Sequence () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . stack Status () Ġ! in ĠDE LET ING _ STACK _ STAT ES Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. sorted With ( compare By ( String . CASE _ INS ENS ITIVE _ ORDER ) Ġ{ Ġit . stack Name () Ġ}) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġit Ġ-> ĠCloudFormation Stack Node ( node Project , Ġit . stack Name (), Ġit . stack Status ()) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. toList () ĊĊĠĠĠĠĠĠĠ Ġreturn Ġnodes Ġ+ Ġpagination Node If Required ( response . nextToken ()) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġpagination Node If Required ( nextToken : ĠString ?) Ġ= Ġwhen Ġ{ ĊĠĠĠĠĠĠĠ Ġnext Token Ġ!= Ġnull Ġ-> ĠlistOf ( Aws Truncated Result Node ( this , Ġnext Token )) ĊĠĠĠĠĠĠĠ Ġelse Ġ-> Ġempty List () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠDE LET ING _ STACK _ STAT ES Ġ= Ġset Of ( Stack Status . DELETE _ COMPLETE ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠCloudFormation Stack Node ( project : ĠProject , Ġval Ġstack Name : ĠString , Ġprivate Ġval Ġstack Status : ĠStack Status ) Ġ: ĊĠĠĠ ĠAws Explorer Resource Node < String >( project , ĠCloudFormation Client . SERVICE _ NAME , Ġstack Name , ĠAws Icons . Resources . CLO U DF ORM ATION _ STACK ), ĊĠĠĠ ĠAws Node Always Expand able , ĊĠĠĠ ĠAws Node Child Cache Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġresource Type () Ġ= Ġ" stack " ĊĊĠĠĠ Ġprivate Ġval Ġc fn Client : ĠCloudFormation Client Ġ= Ġproject . aws Client () ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠCloudFormation ĠStack ĠNodes Ġdo Ġnot Ġimmediately Ġquery Ġfor Ġstack Ġresources . ĊĠĠĠĠ Ġ* ĠWe Ġwait Ġuntil Ġnode Ġwill Ġbe Ġexpanded Ġbefore Ġquerying , Ġreducing Ġrisk Ġof Ġtriggering ĠT PS Ġlimits . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġprivate Ġval Ġno Resources Children : ĠCollection < Abstract TreeNode < Any >> Ġ= ĠlistOf ( Aws Explorer Empty Node ( project , Ġmessage (" explorer . stack . no . serverless . resources ")) ). filter Is Instance < Abstract TreeNode < Any >>() ĊĠĠĠ Ġprivate Ġvar Ġcached Children : ĠCollection < Abstract TreeNode < Any >> Ġ= Ġempty List () ĊĊĠĠĠ Ġprivate Ġvar Ġis Child Cache In InitialState : ĠBoolean Ġ= Ġtrue ĊĊĠĠĠ Ġoverride Ġfun Ġis Always Leaf () Ġ= Ġfalse ĊĊĠĠĠ Ġoverride Ġfun Ġis Initial Child State () Ġ= Ġis Child Cache In InitialState ĊĊĠĠĠ Ġ/** ĊĠĠĠĠ Ġ* ĠChildren Ġare Ġcached Ġby Ġdefault Ġto Ġprevent Ġdescribe Stack Resources Ġfrom Ġbeing Ġcalled Ġeach Ġtime Ġa Ġstack Ġnode Ġis Ġexpanded . ĊĠĠĠĠ Ġ*/ ĊĠĠĠ Ġ@ Suppress (" UN CHECK ED _ CAST ") ĊĠĠĠ Ġoverride Ġfun Ġget Children (): ĠCollection < Abstract TreeNode < Any >> Ġ= Ġget Children ( false ) ĊĊĠĠĠ Ġoverride Ġfun Ġget Children ( refresh : ĠBoolean ): ĠCollection < Abstract TreeNode < Any >> Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( refresh ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Cached Children () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġreturn Ġcached Children ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon DoubleClick ( model : ĠDefault Tree Model , Ġselected Element : ĠDefault Mutable TreeNode ) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on DoubleClick ( model , Ġselected Element ) ĊĠĠĠĠĠĠĠ Ġopen Stack ( node Project , Ġstack Name ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġupdate Cached Children () Ġ{ ĊĠĠĠĠĠĠĠ Ġcached Children Ġ= Ġif Ġ( stack Status Ġin ĠFAILED _ STACK _ STAT ES Ġ|| Ġstack Status Ġin ĠIN _ PROGRESS _ STACK _ STAT ES ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġempty List () ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġloaded Ġ= Ġload Server less Stack Resources () ĊĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( loaded . isEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġno Resources Children ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġloaded . filter Is Instance < Abstract TreeNode < Any >>() ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġis Child Cache In InitialState Ġ= Ġfalse ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġload Server less Stack Resources (): ĠList < Aws Explorer Node <* >> Ġ= Ġtry Ġ{ ĊĠĠĠĠĠĠĠ Ġc fn Client ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. describe Stack Resources Ġ{ Ġit . stack Name ( stack Name ) Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. stack Resources () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. filter Ġ{ Ġit . resourceType () Ġ== ĠL AMBDA _ FUNCTION _ TYPE Ġ&& Ġit . resource Status () Ġin ĠCOMP LETE _ RESOURCE _ STAT ES Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. map Ġ{ Ġresource Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠTODO : ĠEnable Ġusing Ġcache , Ġand Ġa Ġregistry Ġfor Ġthese Ġmappings Ġof ĠC FN Ġ-> Ġreal Ġresource ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġclient Ġ= Ġproject !!. aws Client < Lambda Client >( credential Provider , Ġregion ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġresponse Ġ= Ġclient . get Function Ġ{ Ġit . function Name ( resource . physical ResourceId ()) Ġ} ĊĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLambda Function Node ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnode Project , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġclient , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġresponse . configuration (). to Data Class ( credential Provider . id , Ġregion ), ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtrue ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. toList () ĊĠĠĠ Ġ} Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠĠĠ ĠlistOf ( Aws Explorer Error Node ( project !! , Ġe )) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġstatus Text (): ĠString ? Ġ= Ġstack Status . toString (). to Human Readable () ĊĊĠĠĠ Ġprivate Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġval ĠCOMP LETE _ RESOURCE _ STAT ES Ġ= Ġset Of ( Resource Status . CREATE _ COMPLETE , ĠResource Status . UPDATE _ COMPLETE ) ĊĠĠĠĠĠĠĠ Ġval ĠFAILED _ STACK _ STAT ES Ġ= Ġset Of ( Stack Status . CREATE _ FAILED , ĠStack Status . DELETE _ FAILED , ĠStack Status . ROLL BACK _ FAILED ) ĊĠĠĠĠĠĠĠ Ġval ĠIN _ PROGRESS _ STACK _ STAT ES Ġ= Ġset Of ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStack Status . CREATE _ IN _ PROGRESS , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStack Status . DELETE _ IN _ PROGRESS , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStack Status . ROLL BACK _ IN _ PROGRESS , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStack Status . UPDATE _ IN _ PROGRESS , ĊĠĠĠĠĠĠĠĠĠĠĠ ĠStack Status . UPDATE _ ROLL BACK _ IN _ PROGRESS ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} Ċ } Ċ Ċ class ĠDelete Cloud Formation Stack Action Ġ: ĠDelete Resource Action < Cloud Formation Stack Node >( message (" cloudformation . stack . delete . action ")) Ġ{ ĊĠĠĠ Ġoverride Ġfun Ġperform Delete ( selected : ĠCloudFormation Stack Node ) Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclient : ĠCloudFormation Client Ġ= ĠAws Client Manager . getInstance ( selected . node Project ). getClient () ĊĠĠĠĠĠĠĠ Ġclient . delete Stack Ġ{ Ġit . stack Name ( selected . stack Name ) Ġ} ĊĠĠĠĠĠĠĠ Ġclient . waitFor Stack Deletion Complete ( selected . stack Name ) ĊĠĠĠ Ġ} Ċ }