/*-
* ============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.
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;
.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()
.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());
}
public Guard<RappInstanceState, RappEvent> 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<RappInstanceState, RappEvent> 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<RappInstanceState, RappEvent> 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<RappInstanceState, RappEvent> 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);
};
}
}