Skip to content

Commit

Permalink
Add sync message when OutProperties instance change
Browse files Browse the repository at this point in the history
Add sync message when OutProperties instance change.
Remove update out Properties instance when ac state change happen.

Issue-ID: POLICY-5135
Change-Id: If62521ae3200c8836db92f4825110f14696767df
Signed-off-by: FrancescoFioraEst <[email protected]>
  • Loading branch information
francescofioraest committed Oct 8, 2024
1 parent 9632ec3 commit 20ad241
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -340,9 +340,6 @@ private boolean updateState(AutomationComposition automationComposition,
var element = automationComposition.getElements().get(acElementAck.getKey());
if (element != null) {
element.setMessage(AcmUtils.validatedMessage(acElementAck.getValue().getMessage()));
element.setOutProperties(acElementAck.getValue().getOutProperties());
element.setOperationalState(acElementAck.getValue().getOperationalState());
element.setUseState(acElementAck.getValue().getUseState());
if (stage == null) {
element.setSubState(SubState.NONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantReplica;
Expand Down Expand Up @@ -109,7 +110,8 @@ public void handleParticipantMessage(ParticipantStatus participantStatusMsg) {
participantStatusMsg.getParticipantSupportedElementType(), false);

if (!participantStatusMsg.getAutomationCompositionInfoList().isEmpty()) {
automationCompositionProvider.upgradeStates(participantStatusMsg.getAutomationCompositionInfoList());
updateAcOutProperties(participantStatusMsg.getAutomationCompositionInfoList(),
participantStatusMsg.getCompositionId());
}
if (!participantStatusMsg.getParticipantDefinitionUpdates().isEmpty()
&& participantStatusMsg.getCompositionId() != null) {
Expand Down Expand Up @@ -150,6 +152,16 @@ private ParticipantReplica createReplica(UUID replicaId) {

}

private void updateAcOutProperties(List<AutomationCompositionInfo> automationCompositionInfoList,
UUID compositionId) {
automationCompositionProvider.upgradeStates(automationCompositionInfoList);
var acDefinition = acDefinitionProvider.getAcDefinition(compositionId);
for (var acInfo : automationCompositionInfoList) {
var ac = automationCompositionProvider.getAutomationComposition(acInfo.getAutomationCompositionId());
participantSyncPublisher.sendSync(acDefinition.getServiceTemplate(), ac);
}
}

private void updateAcDefinitionOutProperties(UUID compositionId, UUID replicaId, List<ParticipantDefinition> list) {
var acDefinitionOpt = acDefinitionProvider.findAcDefinition(compositionId);
if (acDefinitionOpt.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,19 @@ void testHandleParticipantSyncRestart() {
void testHandleParticipantStatus() {
var participantStatusMessage = createParticipantStatus();
participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo()));
participantStatusMessage.setCompositionId(UUID.randomUUID());

var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = new AutomationCompositionDefinition();
acDefinition.setCompositionId(participantStatusMessage.getCompositionId());
when(acDefinitionProvider.getAcDefinition(acDefinition.getCompositionId())).thenReturn(acDefinition);

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(ParticipantSyncPublisher.class),
acDefinitionProvider, mock(ParticipantSyncPublisher.class),
mock(AcRuntimeParameterGroup.class));
var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
Expand Down Expand Up @@ -206,6 +212,7 @@ void testAcDefinitionOutProperties() {
Map.of(acElementDefinition.getAcElementDefinitionId().getName(), nodeTemplateState));
var acDefinitionProvider = mock(AcDefinitionProvider.class);
when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition);

var participantProvider = mock(ParticipantProvider.class);
var handler =
Expand All @@ -222,13 +229,19 @@ acDefinitionProvider, mock(ParticipantSyncPublisher.class),
void testHandleParticipantStatusNotRegisterd() {
var participantStatusMessage = createParticipantStatus();
participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo()));
participantStatusMessage.setCompositionId(UUID.randomUUID());

var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = new AutomationCompositionDefinition();
acDefinition.setCompositionId(participantStatusMessage.getCompositionId());
when(acDefinitionProvider.getAcDefinition(acDefinition.getCompositionId())).thenReturn(acDefinition);

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(ParticipantSyncPublisher.class),
acDefinitionProvider, mock(ParticipantSyncPublisher.class),
mock(AcRuntimeParameterGroup.class));
handler.handleParticipantMessage(participantStatusMessage);

Expand All @@ -240,13 +253,19 @@ void testHandleParticipantStatusNotRegisterd() {
void testHandleParticipantStatusCheckOnline() {
var participantStatusMessage = createParticipantStatus();
participantStatusMessage.setAutomationCompositionInfoList(List.of(new AutomationCompositionInfo()));
participantStatusMessage.setCompositionId(UUID.randomUUID());

var acDefinitionProvider = mock(AcDefinitionProvider.class);
var acDefinition = new AutomationCompositionDefinition();
acDefinition.setCompositionId(participantStatusMessage.getCompositionId());
when(acDefinitionProvider.getAcDefinition(acDefinition.getCompositionId())).thenReturn(acDefinition);

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(ParticipantSyncPublisher.class),
acDefinitionProvider, mock(ParticipantSyncPublisher.class),
mock(AcRuntimeParameterGroup.class));
var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
Expand Down

0 comments on commit 20ad241

Please sign in to comment.