X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=rapp-manager-models%2Fsrc%2Fmain%2Fjava%2Fcom%2Foransc%2Frappmanager%2Fmodels%2Fstatemachine%2FRappInstanceStateMachineConfig.java;h=d9dbd3aec36fa249f1aa04a41e697ab0e0985dd9;hb=fc63eb0da4e4426fbfbecdd4f95bec68ca3ceded;hp=34c9a92b282c4dbc084186901a8d7364ee46736b;hpb=77a08f7b9a97e0c6fcce5729cdcc3c18ea90c002;p=nonrtric%2Fplt%2Frappmanager.git diff --git a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfig.java b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfig.java index 34c9a92..d9dbd3a 100755 --- a/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfig.java +++ b/rapp-manager-models/src/main/java/com/oransc/rappmanager/models/statemachine/RappInstanceStateMachineConfig.java @@ -1,6 +1,7 @@ /*- * ============LICENSE_START====================================================================== * Copyright (C) 2023 Nordix Foundation. All rights reserved. + * Copyright (C) 2024 OpenInfra Foundation Europe. All rights reserved. * =============================================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +24,7 @@ import com.oransc.rappmanager.models.rappinstance.RappInstanceState; import java.util.EnumSet; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.statemachine.StateContext; import org.springframework.statemachine.config.EnableStateMachineFactory; import org.springframework.statemachine.config.EnumStateMachineConfigurerAdapter; import org.springframework.statemachine.config.builders.StateMachineConfigurationConfigurer; @@ -103,19 +105,33 @@ public class RappInstanceStateMachineConfig extends EnumStateMachineConfigurerAd public Guard deployedGuard() { return stateContext -> { stateContext.getExtendedState().getVariables().put(stateContext.getEvent(), true); - return stateContext.getExtendedState().getVariables().get(RappEvent.ACMDEPLOYED) != null - && stateContext.getExtendedState().getVariables().get(RappEvent.SMEDEPLOYED) != null - && stateContext.getExtendedState().getVariables().get(RappEvent.DMEDEPLOYED) != null; + return stateContext.getExtendedState().getVariables().get(RappEvent.ACMDEPLOYED) != null && smeGuard( + stateContext, RappEvent.SMEDEPLOYED) && dmeGuard(stateContext, RappEvent.DMEDEPLOYED); }; } + boolean smeGuard(StateContext stateContext, RappEvent rappEvent) { + Boolean smeEnabled = (Boolean) stateContext.getExtendedState().getVariables().get("sme"); + if (smeEnabled != null && smeEnabled.equals(Boolean.TRUE)) { + return stateContext.getExtendedState().getVariables().get(rappEvent) != null; + } + return true; + } + + boolean dmeGuard(StateContext stateContext, RappEvent rappEvent) { + Boolean dmeEnabled = (Boolean) stateContext.getExtendedState().getVariables().get("dme"); + if (dmeEnabled != null && dmeEnabled.equals(Boolean.TRUE)) { + return stateContext.getExtendedState().getVariables().get(rappEvent) != null; + } + return true; + } + @Bean public Guard undeployedGuard() { return stateContext -> { stateContext.getExtendedState().getVariables().put(stateContext.getEvent(), true); - return stateContext.getExtendedState().getVariables().get(RappEvent.ACMUNDEPLOYED) != null - && stateContext.getExtendedState().getVariables().get(RappEvent.SMEUNDEPLOYED) != null - && stateContext.getExtendedState().getVariables().get(RappEvent.DMEUNDEPLOYED) != null; + return stateContext.getExtendedState().getVariables().get(RappEvent.ACMUNDEPLOYED) != null && smeGuard( + stateContext, RappEvent.SMEUNDEPLOYED) && dmeGuard(stateContext, RappEvent.DMEUNDEPLOYED); }; } }