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=a46c269e0972357c54378520a4bba531bf7bb12d;hp=e1bc784648700ba2c26369614f64e1bd4649eafe;hpb=a071d6befe8d38a5e589dffbbf1dc3904ff3aa79;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 e1bc784..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; @@ -57,12 +59,18 @@ public class RappInstanceStateMachineConfig extends EnumStateMachineConfigurerAd .withExternal() .source(RappInstanceState.DEPLOYING).target(RappInstanceState.UNDEPLOYED).event(RappEvent.SMEDEPLOYFAILED) .and() + .withExternal() + .source(RappInstanceState.DEPLOYING).target(RappInstanceState.UNDEPLOYED).event(RappEvent.DMEDEPLOYFAILED) + .and() .withExternal() .source(RappInstanceState.UNDEPLOYING).target(RappInstanceState.DEPLOYED).event(RappEvent.ACMUNDEPLOYFAILED) .and() .withExternal() .source(RappInstanceState.UNDEPLOYING).target(RappInstanceState.DEPLOYED).event(RappEvent.SMEUNDEPLOYFAILED) .and() + .withExternal() + .source(RappInstanceState.UNDEPLOYING).target(RappInstanceState.DEPLOYED).event(RappEvent.DMEUNDEPLOYFAILED) + .and() .withExternal() .source(RappInstanceState.DEPLOYED).target(RappInstanceState.UNDEPLOYING).event(RappEvent.UNDEPLOYING) .and() @@ -74,12 +82,20 @@ public class RappInstanceStateMachineConfig extends EnumStateMachineConfigurerAd .source(RappInstanceState.DEPLOYING).target(RappInstanceState.DEPLOYED).event(RappEvent.SMEDEPLOYED) .guard(deployedGuard()) .and() + .withExternal() + .source(RappInstanceState.DEPLOYING).target(RappInstanceState.DEPLOYED).event(RappEvent.DMEDEPLOYED) + .guard(deployedGuard()) + .and() .withExternal() .source(RappInstanceState.UNDEPLOYING).target(RappInstanceState.UNDEPLOYED).event(RappEvent.ACMUNDEPLOYED) .guard(undeployedGuard()) .and() .withExternal() .source(RappInstanceState.UNDEPLOYING).target(RappInstanceState.UNDEPLOYED).event(RappEvent.SMEUNDEPLOYED) + .guard(undeployedGuard()) + .and() + .withExternal() + .source(RappInstanceState.UNDEPLOYING).target(RappInstanceState.UNDEPLOYED).event(RappEvent.DMEUNDEPLOYED) .guard(undeployedGuard()); } @@ -89,17 +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; + 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; + return stateContext.getExtendedState().getVariables().get(RappEvent.ACMUNDEPLOYED) != null && smeGuard( + stateContext, RappEvent.SMEUNDEPLOYED) && dmeGuard(stateContext, RappEvent.DMEUNDEPLOYED); }; } }