@NonNull
private UUID compositionId;
+ private Boolean restarting;
+
@NonNull
private DeployState deployState = DeployState.UNDEPLOYED;
super(otherAutomationComposition);
this.instanceId = otherAutomationComposition.instanceId;
this.compositionId = otherAutomationComposition.compositionId;
+ this.restarting = otherAutomationComposition.restarting;
this.deployState = otherAutomationComposition.deployState;
this.lockState = otherAutomationComposition.lockState;
this.elements = PfUtils.mapMap(otherAutomationComposition.elements, AutomationCompositionElement::new);
@NonNull
private ToscaServiceTemplate serviceTemplate;
+ private Boolean restarting;
+
@NonNull
private AcTypeState state;
public AutomationCompositionDefinition(final AutomationCompositionDefinition otherAcmDefinition) {
this.compositionId = otherAcmDefinition.compositionId;
this.serviceTemplate = new ToscaServiceTemplate(otherAcmDefinition.serviceTemplate);
+ this.restarting = otherAcmDefinition.restarting;
this.state = otherAcmDefinition.state;
this.elementStateMap = PfUtils.mapMap(otherAcmDefinition.elementStateMap, NodeTemplateState::new);
this.stateChangeResult = otherAcmDefinition.stateChangeResult;
@NonNull
private UUID participantId = UUID.randomUUID();
+ private Boolean restarting;
+
@NonNull
private DeployState deployState = DeployState.UNDEPLOYED;
this.description = otherElement.description;
this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
this.outProperties = PfUtils.mapMap(otherElement.outProperties, UnaryOperator.identity());
+ this.restarting = otherElement.restarting;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
this.operationalState = otherElement.operationalState;
private ToscaConceptIdentifier nodeTemplateId;
+ private Boolean restarting;
+
private AcTypeState state;
private String message;
this.nodeTemplateStateId = copyConstructor.nodeTemplateStateId;
this.participantId = copyConstructor.participantId;
this.nodeTemplateId = new ToscaConceptIdentifier(copyConstructor.nodeTemplateId);
+ this.restarting = copyConstructor.restarting;
this.state = copyConstructor.state;
this.message = copyConstructor.message;
}
@NotNull
private String compositionId;
+ @Column
+ private Boolean restarting;
+
@Column
@NotNull
private DeployState deployState;
this.name = copyConcept.name;
this.version = copyConcept.version;
this.compositionId = copyConcept.compositionId;
+ this.restarting = copyConcept.restarting;
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
this.description = copyConcept.description;
automationComposition.setName(name);
automationComposition.setVersion(version);
automationComposition.setCompositionId(UUID.fromString(compositionId));
+ automationComposition.setRestarting(restarting);
automationComposition.setDeployState(deployState);
automationComposition.setLockState(lockState);
automationComposition.setDescription(description);
this.name = automationComposition.getName();
this.version = automationComposition.getVersion();
this.compositionId = automationComposition.getCompositionId().toString();
+ this.restarting = automationComposition.getRestarting();
this.deployState = automationComposition.getDeployState();
this.lockState = automationComposition.getLockState();
this.description = automationComposition.getDescription();
return result;
}
+ result = ObjectUtils.compare(restarting, other.restarting);
+ if (result != 0) {
+ return result;
+ }
+
result = ObjectUtils.compare(deployState, other.deployState);
if (result != 0) {
return result;
@NotNull
private String version;
+ @Column
+ private Boolean restarting;
+
@Column
@NotNull
private AcTypeState state;
public AutomationCompositionDefinition toAuthorative() {
var acmDefinition = new AutomationCompositionDefinition();
acmDefinition.setCompositionId(UUID.fromString(this.compositionId));
+ acmDefinition.setRestarting(this.restarting);
acmDefinition.setState(this.state);
acmDefinition.setStateChangeResult(this.stateChangeResult);
acmDefinition.setServiceTemplate(this.serviceTemplate.toAuthorative());
@Override
public void fromAuthorative(final AutomationCompositionDefinition copyConcept) {
this.compositionId = copyConcept.getCompositionId().toString();
+ this.restarting = copyConcept.getRestarting();
this.state = copyConcept.getState();
this.stateChangeResult = copyConcept.getStateChangeResult();
this.serviceTemplate = new DocToscaServiceTemplate(copyConcept.getServiceTemplate());
})
private PfConceptKey definition;
+ @Column
@NotNull
private String participantId;
+ @Column
+ private Boolean restarting;
+
@Column
@NotNull
private DeployState deployState;
this.outProperties =
(copyConcept.outProperties != null ? new LinkedHashMap<>(copyConcept.outProperties)
: null);
+ this.restarting = copyConcept.restarting;
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
this.operationalState = copyConcept.operationalState;
element.setDescription(description);
element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
element.setOutProperties(PfUtils.mapMap(outProperties, UnaryOperator.identity()));
+ element.setRestarting(restarting);
element.setDeployState(deployState);
element.setLockState(lockState);
element.setOperationalState(operationalState);
this.description = element.getDescription();
this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
this.outProperties = PfUtils.mapMap(element.getOutProperties(), UnaryOperator.identity());
+ this.restarting = element.getRestarting();
this.deployState = element.getDeployState();
this.lockState = element.getLockState();
this.operationalState = element.getOperationalState();
return result;
}
+ result = ObjectUtils.compare(restarting, other.restarting);
+ if (result != 0) {
+ return result;
+ }
+
result = ObjectUtils.compare(deployState, other.deployState);
if (result != 0) {
return result;
})
private PfConceptKey nodeTemplateId;
+ @Column
+ private Boolean restarting;
+
@Column
@NotNull
private AcTypeState state;
this.participantId = copyConcept.getParticipantId().toString();
}
this.nodeTemplateId = copyConcept.getNodeTemplateId().asConceptKey();
+ this.restarting = copyConcept.getRestarting();
this.state = copyConcept.getState();
this.message = copyConcept.getMessage();
}
nodeTemplateState.setParticipantId(UUID.fromString(this.participantId));
}
nodeTemplateState.setNodeTemplateId(new ToscaConceptIdentifier(this.nodeTemplateId));
+ nodeTemplateState.setRestarting(this.restarting);
nodeTemplateState.setState(this.state);
nodeTemplateState.setMessage(this.message);
return nodeTemplateState;
import java.util.List;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import java.util.UUID;
+import java.util.stream.Collectors;
import javax.ws.rs.core.Response.Status;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.DeployState;
-import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaParticipant;
return ProviderUtils.asEntityList(nodeTemplateStateRepository
.findByParticipantId(participantId.toString()));
}
+
+ /**
+ * Get a list of compositionId associated with a participantId from ac definitions.
+ * @param participantId the participant id associated with the automation composition elements
+ * @return the list of compositionId
+ */
+ public Set<UUID> getCompositionIds(@NonNull final UUID participantId) {
+ return nodeTemplateStateRepository.findByParticipantId(participantId.toString()).stream()
+ .map(nodeTemplateState -> UUID.fromString(nodeTemplateState.getCompositionId()))
+ .collect(Collectors.toSet());
+ }
}
testJpaAcElement.setOperationalState("DEFAULT");
assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setMessage("Message");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setMessage(null);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setRestarting(true);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setRestarting(null);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
testJpaAcElement.setParticipantId(UUID.randomUUID().toString());
assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.models.base.PfConceptKey;
/**
testJpaAutomationComposition.setDescription(null);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setRestarting(true);
+ assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setRestarting(null);
+ assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+
+ testJpaAutomationComposition.setStateChangeResult(StateChangeResult.NO_ERROR);
+ assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+ testJpaAutomationComposition.setStateChangeResult(null);
+ assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
+
assertEquals(testJpaAutomationComposition, new JpaAutomationComposition(testJpaAutomationComposition));
}
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
-import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
-import org.onap.policy.clamp.models.acm.concepts.DeployState;
-import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
import org.onap.policy.clamp.models.acm.concepts.Participant;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
private static final String AUTOMATION_COMPOSITION_JSON =
"src/test/resources/providers/TestAutomationCompositions.json";
- private static final String AUTOMATION_COMPOSITION_JSON_DEREGISTER =
- "src/test/resources/providers/TestAutomationCompositionsDeregister.json";
-
private static final String NODE_TEMPLATE_STATE_JSON = "src/test/resources/providers/NodeTemplateState.json";
private static final String LIST_IS_NULL = ".*. is marked .*ull but is null";
private static final UUID INVALID_ID = UUID.randomUUID();
private AutomationCompositions inputAutomationCompositions;
private List<JpaAutomationComposition> inputAutomationCompositionsJpa;
- private final String originalAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON);
-
- private AutomationCompositions inputAutomationCompositionsDeregister;
- private List<JpaAutomationComposition> inputAutomationCompositionsJpaDeregister;
- private final String deregisterAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON_DEREGISTER);
+ private final String originalAcJson = ResourceUtils.getResourceAsString(AUTOMATION_COMPOSITION_JSON);
private final String nodeTemplateStatesJson = ResourceUtils.getResourceAsString(NODE_TEMPLATE_STATE_JSON);
private List<NodeTemplateState> nodeTemplateStateList = new ArrayList<>();
ProviderUtils.getJpaAndValidateList(inputAutomationCompositions.getAutomationCompositionList(),
JpaAutomationComposition::new, "automation compositions");
- inputAutomationCompositionsDeregister = CODER.decode(deregisterAcJson, AutomationCompositions.class);
- inputAutomationCompositionsJpaDeregister =
- ProviderUtils.getJpaAndValidateList(inputAutomationCompositionsDeregister.getAutomationCompositionList(),
- JpaAutomationComposition::new, "automation compositions");
-
nodeTemplateStateList.add(CODER.decode(nodeTemplateStatesJson, NodeTemplateState.class));
nodeTemplateStateList.get(0).setState(AcTypeState.COMMISSIONED);
jpaNodeTemplateStateList = ProviderUtils.getJpaAndValidateList(nodeTemplateStateList,
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
- assertThatThrownBy(() -> participantProvider.updateParticipant(null))
- .hasMessageMatching(LIST_IS_NULL);
+ assertThatThrownBy(() -> participantProvider.updateParticipant(null)).hasMessageMatching(LIST_IS_NULL);
when(participantRepository.save(any())).thenReturn(jpaParticipantList.get(0));
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
-
assertThat(participantProvider.findParticipant(INVALID_ID)).isEmpty();
when(participantRepository.findAll()).thenReturn(jpaParticipantList);
assertThatThrownBy(() -> participantProvider.getParticipantById(inputParticipants.get(0).getParticipantId()))
.hasMessageMatching("Participant Not Found with ID: " + inputParticipants.get(0).getParticipantId());
- when(participantRepository.findById(any())).thenReturn(
- Optional.ofNullable(jpaParticipantList.get(0)));
+ when(participantRepository.findById(any())).thenReturn(Optional.ofNullable(jpaParticipantList.get(0)));
- var participant = participantProvider.getParticipantById(inputParticipants.get(0)
- .getParticipantId());
+ var participant = participantProvider.getParticipantById(inputParticipants.get(0).getParticipantId());
assertThat(inputParticipants.get(0)).usingRecursiveComparison().isEqualTo(participant);
}
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
- var acElementList = inputAutomationCompositionsJpa
- .stream().map(c -> c.getElements()).collect(Collectors.toList());
-
- when(automationCompositionElementRepository.findByParticipantId(any())).thenReturn(acElementList.get(0));
+ var acElementList = inputAutomationCompositionsJpa.get(0).getElements();
- var listOfAcElements = participantProvider.getAutomationCompositionElements(UUID.randomUUID());
-
- assertThat(acElementList.get(0).equals(listOfAcElements));
+ var participantId = UUID.randomUUID();
+ when(automationCompositionElementRepository.findByParticipantId(participantId.toString()))
+ .thenReturn(acElementList);
+ var listOfAcElements = participantProvider.getAutomationCompositionElements(participantId);
+ assertThat(listOfAcElements).hasSameSizeAs(acElementList);
+ assertEquals(UUID.fromString(acElementList.get(0).getElementId()), listOfAcElements.get(0).getId());
}
@Test
var participantRepository = mock(ParticipantRepository.class);
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
- when(nodeTemplateStateRepository.findByParticipantId(any())).thenReturn(jpaNodeTemplateStateList);
+ var participantId = jpaParticipantList.get(0).getParticipantId();
+ when(nodeTemplateStateRepository.findByParticipantId(participantId)).thenReturn(jpaNodeTemplateStateList);
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
- var listOfNodeTemplateState = participantProvider.getAcNodeTemplateStates(
- UUID.fromString(jpaParticipantList.get(0).getParticipantId()));
-
- assertThat(listOfNodeTemplateState.equals(nodeTemplateStateList));
+ var listOfNodeTemplateState = participantProvider.getAcNodeTemplateStates(UUID.fromString(participantId));
+ assertEquals(listOfNodeTemplateState, nodeTemplateStateList);
}
@Test
}
@Test
- void testResetParticipantAcElementState() {
+ void testGetCompositionIds() {
+ var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
+ var participantId = UUID.randomUUID();
+ when(nodeTemplateStateRepository.findByParticipantId(participantId.toString()))
+ .thenReturn(jpaNodeTemplateStateList);
var participantRepository = mock(ParticipantRepository.class);
var automationCompositionElementRepository = mock(AutomationCompositionElementRepository.class);
- var acElementList = inputAutomationCompositionsJpaDeregister
- .stream().map(c -> c.getElements()).collect(Collectors.toList());
-
- when(automationCompositionElementRepository.findByParticipantId(any())).thenReturn(acElementList.get(0));
-
- var nodeTemplateStateRepository = mock(NodeTemplateStateRepository.class);
var participantProvider = new ParticipantProvider(participantRepository,
automationCompositionElementRepository, nodeTemplateStateRepository);
- acElementList.get(0).stream().forEach(e -> {
- assertThat(e.getDeployState().equals(DeployState.DEPLOYED));
- assertThat(e.getLockState().equals(LockState.LOCKED));
- });
-
- acElementList.get(0).stream().forEach(e -> {
- assertThat(e.getDeployState().equals(DeployState.UNDEPLOYED));
- assertThat(e.getLockState().equals(LockState.NONE));
- });
+ assertThatThrownBy(() -> participantProvider.getCompositionIds(null)).hasMessageMatching(LIST_IS_NULL);
+ var result = participantProvider.getCompositionIds(participantId);
+ assertThat(result).hasSize(1);
}
}