Skip to content

Commit

Permalink
Fix outProperties message in participant simulator
Browse files Browse the repository at this point in the history
Issue-ID: POLICY-5145
Change-Id: I1a597ad17aeda4dcdcd863da97bb61eeb0bdaa09
Signed-off-by: FrancescoFioraEst <[email protected]>
  • Loading branch information
francescofioraest committed Oct 22, 2024
1 parent 20ad241 commit c5b350a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

package org.onap.policy.clamp.acm.participant.sim.main.handler;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -99,6 +100,7 @@ public void migrate(UUID instanceId, AcElementDeploy element, UUID compositionTa
Map<String, Object> properties) {
LOGGER.debug("migrate call instanceId: {}, element: {}, compositionTargetId: {}, properties: {}",
instanceId, element, compositionTargetId, properties);
simulatorService.migrate(instanceId, element.getId(), 0, Map.of());

simulatorService.migrate(instanceId, element.getId(), 0, properties, new HashMap<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public void migrate(CompositionElementDto compositionElement, CompositionElement
simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
} else {
simulatorService.migrate(instanceElement.instanceId(), instanceElement.elementId(),
0, compositionElementTarget.inProperties());
0, compositionElementTarget.inProperties(), instanceElementMigrate.outProperties());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

package org.onap.policy.clamp.acm.participant.sim.main.handler;

import java.util.ArrayList;
import java.util.List;
import lombok.Getter;
import lombok.Setter;
import org.onap.policy.clamp.acm.participant.intermediary.api.CompositionDto;
Expand Down Expand Up @@ -131,13 +129,7 @@ public void migrate(CompositionElementDto compositionElement, CompositionElement
simulatorService.delete(instanceElement.instanceId(), instanceElement.elementId());
} else {
simulatorService.migrate(instanceElementMigrate.instanceId(), instanceElementMigrate.elementId(), stage,
compositionElementTarget.inProperties());
instanceElementMigrate.outProperties().putIfAbsent("stage", new ArrayList<>());
@SuppressWarnings("unchecked")
var stageList = (List<Integer>) instanceElementMigrate.outProperties().get("stage");
stageList.add(stage);
intermediaryApi.sendAcElementInfo(instanceElementMigrate.instanceId(), instanceElementMigrate.elementId(),
null, null, instanceElementMigrate.outProperties());
compositionElementTarget.inProperties(), instanceElementMigrate.outProperties());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package org.onap.policy.clamp.acm.participant.sim.main.handler;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import lombok.Getter;
Expand Down Expand Up @@ -330,7 +331,8 @@ public void deprime(UUID compositionId) {
* @param elementId the elementId
* @param stage the stage
*/
public void migrate(UUID instanceId, UUID elementId, int stage, Map<String, Object> compositionInProperties) {
public void migrate(UUID instanceId, UUID elementId, int stage, Map<String, Object> compositionInProperties,
Map<String, Object> instanceOutProperties) {
if (!execution(getConfig().getMigrateTimerMs(),
"Current Thread migrate is Interrupted during execution {}", elementId)) {
return;
Expand All @@ -344,6 +346,11 @@ public void migrate(UUID instanceId, UUID elementId, int stage, Map<String, Obje
nextStage = Math.min(s, nextStage);
}
}
instanceOutProperties.putIfAbsent("stage", new ArrayList<>());
@SuppressWarnings("unchecked")
var stageList = (List<Integer>) instanceOutProperties.get("stage");
stageList.add(stage);
intermediaryApi.sendAcElementInfo(instanceId, elementId, null, null, instanceOutProperties);
if (nextStage == 1000) {
intermediaryApi.updateAutomationCompositionElementState(
instanceId, elementId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -208,7 +209,7 @@ void testMigrate() {
Map.of(), Map.of());
var instanceElementMigrated = new InstanceElementDto(
INSTANCE_ELEMENT.instanceId(), INSTANCE_ELEMENT.elementId(),
null, Map.of("key", "value"), Map.of());
null, Map.of("key", "value"), new HashMap<>());
acElementHandler
.migrate(COMPOSITION_ELEMENT, compositionElementTarget, INSTANCE_ELEMENT, instanceElementMigrated);
verify(intermediaryApi).updateAutomationCompositionElementState(
Expand Down Expand Up @@ -240,7 +241,8 @@ void testMigrateAdd() {
var compoElTargetAdd = new CompositionElementDto(
UUID.randomUUID(), new ToscaConceptIdentifier(), Map.of(), Map.of(), ElementState.NEW);
var inElMigratedAdd = new InstanceElementDto(
instanceElement.instanceId(), instanceElement.elementId(), null, Map.of(), Map.of(), ElementState.NEW);
instanceElement.instanceId(), instanceElement.elementId(), null,
Map.of(), new HashMap<>(), ElementState.NEW);
acElementHandler
.migrate(compositionElement, compoElTargetAdd, instanceElement, inElMigratedAdd);
verify(intermediaryApi).updateAutomationCompositionElementState(
Expand Down

0 comments on commit c5b350a

Please sign in to comment.