Merge "Add installation mode to use snapshot image"
[nonrtric/plt/rappmanager.git] / rapp-manager-models / src / main / java / com / oransc / rappmanager / models / statemachine / RappInstanceStateMachine.java
index 4e10ac0..b776df7 100755 (executable)
@@ -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.
@@ -27,9 +28,11 @@ import java.util.UUID;
 import lombok.RequiredArgsConstructor;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.springframework.messaging.support.MessageBuilder;
 import org.springframework.statemachine.StateMachine;
 import org.springframework.statemachine.config.StateMachineFactory;
 import org.springframework.stereotype.Service;
+import reactor.core.publisher.Mono;
 
 @Service
 @RequiredArgsConstructor
@@ -43,13 +46,18 @@ public class RappInstanceStateMachine {
     public void onboardRappInstance(UUID rappInstanceId) {
         StateMachine<RappInstanceState, RappEvent> stateMachine = stateMachineFactory.getStateMachine(rappInstanceId);
         stateMachineMap.put(rappInstanceId, stateMachine);
-        stateMachine.start();
+        stateMachine.startReactively().subscribe();
     }
 
     public void sendRappInstanceEvent(RappInstance rappInstance, RappEvent rappEvent) {
         logger.info("Sending rapp instance event {} for {}", rappEvent.name(), rappInstance.getRappInstanceId());
         logger.debug("State machine map is {}", stateMachineMap);
-        stateMachineMap.get(rappInstance.getRappInstanceId()).sendEvent(rappEvent);
+        stateMachineMap.get(rappInstance.getRappInstanceId()).getExtendedState().getVariables()
+                .put("sme", rappInstance.isSMEEnabled());
+        stateMachineMap.get(rappInstance.getRappInstanceId()).getExtendedState().getVariables()
+                .put("dme", rappInstance.isDMEEnabled());
+        stateMachineMap.get(rappInstance.getRappInstanceId())
+                .sendEvent(Mono.just(MessageBuilder.withPayload(rappEvent).build())).subscribe();
     }
 
     public RappInstanceState getRappInstanceState(UUID rappInstanceId) {
@@ -57,7 +65,7 @@ public class RappInstanceStateMachine {
     }
 
     public void deleteRappInstance(RappInstance rappInstance) {
-        stateMachineMap.get(rappInstance.getRappInstanceId()).stop();
+        stateMachineMap.get(rappInstance.getRappInstanceId()).stopReactively().subscribe();
         stateMachineMap.remove(rappInstance.getRappInstanceId());
     }
 }