if (participantOpt.isPresent()) {
var participant = participantOpt.get();
- if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) {
- participant.setParticipantState(ParticipantState.ON_LINE);
- participantProvider.saveParticipant(participant);
- }
+ checkOnline(participant);
handleRestart(participant.getParticipantId());
} else {
var participant = createParticipant(participantRegisterMsg.getParticipantId(),
var participant = createParticipant(participantStatusMsg.getParticipantId(),
listToMap(participantStatusMsg.getParticipantSupportedElementType()));
participantProvider.saveParticipant(participant);
+ } else {
+ checkOnline(participantOpt.get());
}
if (!participantStatusMsg.getAutomationCompositionInfoList().isEmpty()) {
automationCompositionProvider.upgradeStates(participantStatusMsg.getAutomationCompositionInfoList());
}
}
+ private void checkOnline(Participant participant) {
+ if (ParticipantState.OFF_LINE.equals(participant.getParticipantState())) {
+ participant.setParticipantState(ParticipantState.ON_LINE);
+ participantProvider.saveParticipant(participant);
+ }
+ }
+
private void handleRestart(UUID participantId) {
var compositionIds = participantProvider.getCompositionIds(participantId);
for (var compositionId : compositionIds) {
var participantRegisterMessage = new ParticipantRegister();
participantRegisterMessage.setMessageId(UUID.randomUUID());
participantRegisterMessage.setParticipantId(CommonTestData.getParticipantId());
- var supportedElementType = new ParticipantSupportedElementType();
- supportedElementType.setTypeName("Type");
- supportedElementType.setTypeVersion("1.0.0");
+ var supportedElementType = CommonTestData.createParticipantSupportedElementType();
participantRegisterMessage.setParticipantSupportedElementType(List.of(supportedElementType));
var participantProvider = mock(ParticipantProvider.class);
participantRegisterMessage.setMessageId(UUID.randomUUID());
var participantId = CommonTestData.getParticipantId();
participantRegisterMessage.setParticipantId(participantId);
- var supportedElementType = new ParticipantSupportedElementType();
- supportedElementType.setTypeName("Type");
- supportedElementType.setTypeVersion("1.0.0");
+ var supportedElementType = CommonTestData.createParticipantSupportedElementType();
participantRegisterMessage.setParticipantSupportedElementType(List.of(supportedElementType));
var participant = new Participant();
var participantStatusMessage = new ParticipantStatus();
participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
participantStatusMessage.setState(ParticipantState.ON_LINE);
- var supportedElementType = new ParticipantSupportedElementType();
- supportedElementType.setTypeName("Type");
- supportedElementType.setTypeVersion("1.0.0");
+ var supportedElementType = CommonTestData.createParticipantSupportedElementType();
participantStatusMessage.setParticipantSupportedElementType(List.of(supportedElementType));
participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo()));
verify(automationCompositionProvider).upgradeStates(any());
}
+
+ @Test
+ void testHandleParticipantStatusNotRegisterd() {
+ var participantStatusMessage = new ParticipantStatus();
+ participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantStatusMessage.setState(ParticipantState.ON_LINE);
+ var supportedElementType = CommonTestData.createParticipantSupportedElementType();
+ participantStatusMessage.setParticipantSupportedElementType(List.of(supportedElementType));
+ participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo()));
+
+ var participantProvider = mock(ParticipantProvider.class);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var handler =
+ new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider,
+ mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class));
+ handler.handleParticipantMessage(participantStatusMessage);
+
+ verify(participantProvider).saveParticipant(any());
+ verify(automationCompositionProvider).upgradeStates(any());
+ }
+
+ @Test
+ void testHandleParticipantStatusCheckOnline() {
+ var participantStatusMessage = new ParticipantStatus();
+ participantStatusMessage.setParticipantId(CommonTestData.getParticipantId());
+ participantStatusMessage.setState(ParticipantState.ON_LINE);
+ var supportedElementType = CommonTestData.createParticipantSupportedElementType();
+ participantStatusMessage.setParticipantSupportedElementType(List.of(supportedElementType));
+ participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo()));
+
+ var participantProvider = mock(ParticipantProvider.class);
+ var automationCompositionProvider = mock(AutomationCompositionProvider.class);
+ var handler =
+ new SupervisionParticipantHandler(participantProvider, mock(ParticipantRegisterAckPublisher.class),
+ mock(ParticipantDeregisterAckPublisher.class), automationCompositionProvider,
+ mock(AcDefinitionProvider.class), mock(ParticipantRestartPublisher.class));
+ var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
+ participant.setParticipantState(ParticipantState.OFF_LINE);
+ when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
+ .thenReturn(Optional.of(participant));
+ handler.handleParticipantMessage(participantStatusMessage);
+
+ verify(participantProvider).saveParticipant(any());
+ verify(automationCompositionProvider).upgradeStates(any());
+ }
}
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
+import org.onap.policy.clamp.models.acm.concepts.ParticipantSupportedElementType;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
return participant;
}
+ /**
+ * Create a new ParticipantSupportedElementType.
+ *
+ * @return a new ParticipantSupportedElementType
+ */
+ public static ParticipantSupportedElementType createParticipantSupportedElementType() {
+ var supportedElementType = new ParticipantSupportedElementType();
+ supportedElementType.setTypeName("Type");
+ supportedElementType.setTypeVersion("1.0.0");
+ return supportedElementType;
+ }
+
public static UUID getParticipantId() {
return UUID.fromString("101c62b3-8918-41b9-a747-d21eb79c6c03");
}