// State of the AutomationCompositionElement
private LockState lockState;
+ private String operationalState;
+
+ private String useState;
+
// Result: Success/Fail.
private Boolean result;
@NonNull
private LockState lockState = LockState.LOCKED;
+ private String operationalState;
+
+ private String useState;
+
private String description;
// A map indexed by the property name. Each map entry is the serialized value of the property,
this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
+ this.operationalState = otherElement.operationalState;
+ this.useState = otherElement.useState;
}
}
--- /dev/null
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2023 Nordix Foundation.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.models.acm.concepts;
+
+import java.util.UUID;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+import lombok.ToString;
+
+/**
+ * Class to represent a automation composition element info instance.
+ */
+@NoArgsConstructor
+@Data
+@ToString
+public class AutomationCompositionElementInfo {
+
+ private UUID automationCompositionElementId;
+
+ private DeployState deployState = DeployState.UNDEPLOYED;
+
+ private LockState lockState = LockState.LOCKED;
+
+ private String operationalState;
+
+ private String useState;
+
+ /**
+ * Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
+ *
+ * @param otherElement the other element to copy from
+ */
+ public AutomationCompositionElementInfo(AutomationCompositionElementInfo otherElement) {
+ this.automationCompositionElementId = otherElement.automationCompositionElementId;
+ this.deployState = otherElement.deployState;
+ this.lockState = otherElement.lockState;
+ this.operationalState = otherElement.operationalState;
+ this.useState = otherElement.useState;
+ }
+}
package org.onap.policy.clamp.models.acm.concepts;
+import java.util.ArrayList;
+import java.util.List;
import java.util.UUID;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;
+import org.onap.policy.models.base.PfUtils;
/**
* Class to represent a automation composition info instance.
private LockState lockState = LockState.LOCKED;
+ private List<AutomationCompositionElementInfo> elements = new ArrayList<>();
+
/**
* Copy constructor, does a deep copy but as all fields here are immutable, it's just a regular copy.
*
this.automationCompositionId = otherElement.automationCompositionId;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
+ this.elements = PfUtils.mapList(otherElement.elements, AutomationCompositionElementInfo::new);
}
}
@NotNull
private LockState lockState;
+ @Column
+ private String operationalState;
+
+ @Column
+ private String useState;
+
@Column
private String description;
this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
+ this.operationalState = copyConcept.operationalState;
+ this.useState = copyConcept.useState;
}
/**
element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
element.setDeployState(deployState);
element.setLockState(lockState);
+ element.setOperationalState(operationalState);
+ element.setUseState(useState);
return element;
}
this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
this.deployState = element.getDeployState();
this.lockState = element.getLockState();
+ this.operationalState = element.getOperationalState();
+ this.useState = element.getUseState();
}
@Override
return result;
}
+ result = ObjectUtils.compare(useState, other.useState);
+ if (result != 0) {
+ return result;
+ }
+
+ result = ObjectUtils.compare(operationalState, other.operationalState);
+ if (result != 0) {
+ return result;
+ }
+
return ObjectUtils.compare(description, other.description);
}
}
package org.onap.policy.clamp.models.acm.persistence.provider;
+import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
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.persistence.concepts.JpaAutomationComposition;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionElement;
+import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.models.base.PfModelRuntimeException;
public class AutomationCompositionProvider {
private final AutomationCompositionRepository automationCompositionRepository;
+ private final AutomationCompositionElementRepository acElementRepository;
/**
* Get automation composition.
return jpaDeleteAutomationComposition.get().toAuthorative();
}
+
+ /**
+ * Upgrade States.
+ *
+ * @param automationCompositionInfoList list of AutomationCompositionInfo
+ */
+ public void upgradeStates(@NonNull final List<AutomationCompositionInfo> automationCompositionInfoList) {
+ if (automationCompositionInfoList.isEmpty()) {
+ return;
+ }
+ List<JpaAutomationCompositionElement> jpaList = new ArrayList<>();
+ for (var acInstance : automationCompositionInfoList) {
+ for (var element : acInstance.getElements()) {
+ var jpa = acElementRepository.getReferenceById(element.getAutomationCompositionElementId().toString());
+ jpa.setUseState(element.getUseState());
+ jpa.setOperationalState(element.getOperationalState());
+ jpaList.add(jpa);
+ }
+ }
+ acElementRepository.saveAll(jpaList);
+ }
}
// verify with all values
orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(CommonTestData.getParticipantId());
- var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED,
+ var acElementResult = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "",
true, "AutomationCompositionElement result");
final var automationCompositionResultMap = Map.of(UUID.randomUUID(), acElementResult);
orig.setAutomationCompositionResultMap(automationCompositionResultMap);
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
// verify with all values
var automationCompositionId = UUID.randomUUID();
+ var acElementId = UUID.randomUUID();
orig.setAutomationCompositionId(automationCompositionId);
var participantId = CommonTestData.getParticipantId();
orig.setParticipantId(participantId);
orig.setState(ParticipantState.ON_LINE);
orig.setTimestamp(Instant.ofEpochMilli(3000));
- var acInfo = getAutomationCompositionInfo(automationCompositionId);
+ var acInfo = getAutomationCompositionInfo(automationCompositionId, acElementId);
orig.setAutomationCompositionInfoList(List.of(acInfo));
var participantDefinitionUpdate = new ParticipantDefinition();
assertSerializable(orig, ParticipantStatus.class);
}
- private AutomationCompositionInfo getAutomationCompositionInfo(UUID id) {
+ private AutomationCompositionInfo getAutomationCompositionInfo(UUID id, UUID acElementId) {
var acInfo = new AutomationCompositionInfo();
acInfo.setDeployState(DeployState.DEPLOYED);
acInfo.setLockState(LockState.LOCKED);
acInfo.setAutomationCompositionId(id);
+ var acInfoElement = new AutomationCompositionElementInfo();
+ acInfoElement.setAutomationCompositionElementId(acElementId);
+ acInfoElement.setDeployState(DeployState.DEPLOYED);
+ acInfoElement.setLockState(LockState.LOCKED);
+ acInfoElement.setOperationalState("DEFAULT");
+ acInfoElement.setUseState("IDLE");
+ acInfo.getElements().add(acInfoElement);
return acInfo;
}
assertEquals(ELEMENT_ID, testJpaAcElement.getElementId());
- var testJpaAutomationCompositionElement2 = new JpaAutomationCompositionElement(testJpaAcElement);
- assertEquals(testJpaAcElement, testJpaAutomationCompositionElement2);
+ var testJpaAcElement2 = new JpaAutomationCompositionElement(testJpaAcElement);
+ assertEquals(testJpaAcElement, testJpaAcElement2);
+
+ testJpaAcElement2 = new JpaAutomationCompositionElement(testJpaAcElement.toAuthorative());
+ testJpaAcElement2.setElementId(ELEMENT_ID);
+ testJpaAcElement2.setInstanceId(INSTANCE_ID);
+ assertEquals(testJpaAcElement, testJpaAcElement2);
}
@Test
@Test
void testJpaAutomationCompositionElementCompareTo() {
- var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
+ var testJpaAcElement = createJpaAutomationCompositionElementInstance();
- var otherJpaAutomationCompositionElement =
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- assertEquals(-1, testJpaAutomationCompositionElement.compareTo(null));
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(testJpaAutomationCompositionElement));
+ var otherJpaAcElement =
+ new JpaAutomationCompositionElement(testJpaAcElement);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ assertEquals(-1, testJpaAcElement.compareTo(null));
+ assertEquals(0, testJpaAcElement.compareTo(testJpaAcElement));
assertNotEquals(0,
- testJpaAutomationCompositionElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
-
- testJpaAutomationCompositionElement.setElementId("BadValue");
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setElementId(ELEMENT_ID);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setInstanceId("BadValue");
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setInstanceId(INSTANCE_ID);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setDefinition(new PfConceptKey("aceDef", "0.0.1"));
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setDescription("Description");
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setDescription(null);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setDeployState(DeployState.DEPLOYED);
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setDeployState(DeployState.UNDEPLOYED);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setLockState(LockState.UNLOCKED);
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setLockState(LockState.LOCKED);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setParticipantId(UUID.randomUUID().toString());
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- assertEquals(testJpaAutomationCompositionElement,
- new JpaAutomationCompositionElement(testJpaAutomationCompositionElement));
+ testJpaAcElement.compareTo(new DummyJpaAutomationCompositionElementChild()));
+
+ testJpaAcElement.setElementId("BadValue");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setElementId(ELEMENT_ID);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setInstanceId("BadValue");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setInstanceId(INSTANCE_ID);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setDefinition(new PfConceptKey("BadValue", "0.0.1"));
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setDefinition(new PfConceptKey("aceDef", "0.0.1"));
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setDescription("Description");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setDescription(null);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setDeployState(DeployState.DEPLOYED);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setDeployState(DeployState.UNDEPLOYED);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setLockState(LockState.UNLOCKED);
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setLockState(LockState.LOCKED);
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setUseState("BadValue");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setUseState("IDLE");
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setOperationalState("BadValue");
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+ testJpaAcElement.setOperationalState("DEFAULT");
+ assertEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ testJpaAcElement.setParticipantId(UUID.randomUUID().toString());
+ assertNotEquals(0, testJpaAcElement.compareTo(otherJpaAcElement));
+
+ assertEquals(testJpaAcElement, new JpaAutomationCompositionElement(testJpaAcElement));
}
@Test
automationCompositionElement.setDefinition(new ToscaConceptIdentifier("aceDef", "0.0.1"));
automationCompositionElement.setParticipantId(CommonTestData.getParticipantId());
automationCompositionElement.setProperties(Map.of("key", "{}"));
+ automationCompositionElement.setUseState("IDLE");
+ automationCompositionElement.setOperationalState("DEFAULT");
return automationCompositionElement;
}
import org.mockito.Mockito;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationComposition;
+import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionElementRepository;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionRepository;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
@Test
void testAutomationCompositionCreate() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
when(automationCompositionRepository.save(any(JpaAutomationComposition.class)))
.thenReturn(inputAutomationCompositionsJpa.get(0));
@Test
void testAutomationCompositionUpdate() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
assertThatThrownBy(() -> automationCompositionProvider.updateAutomationComposition(null))
.hasMessageMatching(OBJECT_IS_NULL);
@Test
void testGetAutomationCompositions() throws Exception {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
var acList = automationCompositionProvider.getAutomationCompositions(UUID.randomUUID(),
@Test
void testGetAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
assertThatThrownBy(
@Test
void testFindAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
var acOpt = automationCompositionProvider.findAutomationComposition(automationComposition.getInstanceId());
@Test
void testGetAcInstancesByCompositionId() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
var automationComposition = inputAutomationCompositions.getAutomationCompositionList().get(0);
when(automationCompositionRepository.findByCompositionId(automationComposition.getCompositionId().toString()))
@Test
void testDeleteAutomationComposition() {
var automationCompositionRepository = mock(AutomationCompositionRepository.class);
- var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository);
+ var automationCompositionProvider = new AutomationCompositionProvider(automationCompositionRepository,
+ mock(AutomationCompositionElementRepository.class));
assertThatThrownBy(() -> automationCompositionProvider.deleteAutomationComposition(UUID.randomUUID()))
.hasMessageMatching(".*.failed, automation composition does not exist");
return policyList;
}
+
+ @Override
+ public String getUseState(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ return "IDLE";
+ }
+
+ @Override
+ public String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ return "ENABLED";
+ }
}
package org.onap.policy.clamp.acm.participant.policy.main.handler;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
assertThatThrownBy(() -> handler.deploy(AC_ID, element, Map.of()))
.hasMessageMatching("Deploy of Policy failed.");
}
+
+ @Test
+ void testGetOperationalState() throws PfModelException {
+ var api = mock(PolicyApiHttpClient.class);
+ var pap = mock(PolicyPapHttpClient.class);
+ var handler = new AutomationCompositionElementHandler(api, pap);
+
+ assertEquals("ENABLED", handler.getOperationalState(UUID.randomUUID(), UUID.randomUUID()));
+ }
+
+ @Test
+ void testGetUseState() throws PfModelException {
+ var api = mock(PolicyApiHttpClient.class);
+ var pap = mock(PolicyPapHttpClient.class);
+ var handler = new AutomationCompositionElementHandler(api, pap);
+
+ assertEquals("IDLE", handler.getUseState(UUID.randomUUID(), UUID.randomUUID()));
+ }
}
*/
public void deploy(UUID automationCompositionId, AcElementDeploy element, Map<String, Object> properties)
throws PfModelException;
+
+ public default void lock(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Lock Operation
+ }
+
+ public default void unlock(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Unlock Operation
+ }
+
+ public default String getUseState(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Use State
+ return "";
+ }
+
+ public default String getOperationalState(UUID automationCompositionId, UUID automationCompositionElementId)
+ throws PfModelException {
+ // default Operational State
+ return "";
+ }
}
if (element != null) {
element.setDeployState(deployState);
element.setLockState(lockState);
+ element.setUseState(getUseState(automationCompositionId, id));
+ element.setOperationalState(getOperationalState(automationCompositionId, id));
}
var checkOpt = automationComposition.getElements().values().stream()
.filter(acElement -> !deployState.equals(acElement.getDeployState())).findAny();
automationCompositionStateChangeAck.setAutomationCompositionId(automationCompositionId);
acElement.setDeployState(deployState);
acElement.setLockState(lockState);
+ acElement.setUseState(getUseState(automationCompositionId, id));
+ acElement.setOperationalState(getOperationalState(automationCompositionId, id));
automationCompositionStateChangeAck.getAutomationCompositionResultMap().put(acElement.getId(),
- new AcElementDeployAck(deployState, lockState, true,
+ new AcElementDeployAck(deployState, lockState,
+ acElement.getOperationalState(), acElement.getUseState(), true,
"Automation composition element {} state changed to {}\", id, newState)"));
LOGGER.debug("Automation composition element {} state changed to {}", id, deployState);
automationCompositionStateChangeAck
if (acElementNodeTemplate != null) {
int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
if (startPhaseMsg.equals(startPhase)) {
- updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
- LockState.LOCKED);
+ for (var acElementListener : listeners) {
+ try {
+ acElementListener.lock(instanceId, acElement.getId());
+ updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
+ LockState.LOCKED);
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element lock failed {}", instanceId);
+ }
+ }
}
}
}
if (acElementNodeTemplate != null) {
int startPhase = ParticipantUtils.findStartPhase(acElementNodeTemplate.getProperties());
if (startPhaseMsg.equals(startPhase)) {
- updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
- LockState.UNLOCKED);
+ for (var acElementListener : listeners) {
+ try {
+ acElementListener.unlock(instanceId, acElement.getId());
+ updateAutomationCompositionElementState(instanceId, acElement.getId(), DeployState.DEPLOYED,
+ LockState.UNLOCKED);
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element unlock failed {}", instanceId);
+ }
+ }
}
}
}
try {
acElementListener.undeploy(instanceId, acElement.getId());
} catch (PfModelException e) {
- LOGGER.debug("Automation composition element update failed {}", instanceId);
+ LOGGER.error("Automation composition element update failed {}", instanceId);
}
}
}
}
}
+
+ /**
+ * Get UseState.
+ *
+ * @param instanceId the instance Id
+ * @param acElementId the Automation Composition Element Id
+ * @return the UseState of the Automation Composition Element
+ */
+ public String getUseState(UUID instanceId, UUID acElementId) {
+ for (var acElementListener : listeners) {
+ try {
+ return acElementListener.getUseState(instanceId, acElementId);
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element get Use State failed {}", acElementId);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get OperationalState.
+ *
+ * @param instanceId the instance Id
+ * @param acElementId the Automation Composition Element Id
+ * @return the OperationalState of the Automation Composition Element
+ */
+ public String getOperationalState(UUID instanceId, UUID acElementId) {
+ for (var acElementListener : listeners) {
+ try {
+ return acElementListener.getOperationalState(instanceId, acElementId);
+ } catch (PfModelException e) {
+ LOGGER.error("Automation composition element get Use State failed {}", acElementId);
+ }
+ }
+ return null;
+ }
}
import org.onap.policy.clamp.acm.participant.intermediary.parameters.ParticipantParameters;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementInfo;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
import org.onap.policy.clamp.models.acm.concepts.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
acInfo.setAutomationCompositionId(entry.getKey());
acInfo.setDeployState(entry.getValue().getDeployState());
acInfo.setLockState(entry.getValue().getLockState());
+ for (var element : entry.getValue().getElements().values()) {
+ var elementInfo = new AutomationCompositionElementInfo();
+ elementInfo.setAutomationCompositionElementId(element.getId());
+ elementInfo.setDeployState(element.getDeployState());
+ elementInfo.setLockState(element.getLockState());
+ elementInfo.setOperationalState(
+ automationCompositionHandler.getOperationalState(entry.getKey(), element.getId()));
+ elementInfo.setUseState(automationCompositionHandler.getUseState(entry.getKey(), element.getId()));
+ acInfo.getElements().add(elementInfo);
+ }
automationCompositionInfoList.add(acInfo);
}
return automationCompositionInfoList;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyMap;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.util.List;
import java.util.UUID;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.AutomationCompositionStateChange;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.DeployOrder;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.LockOrder;
+import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
import org.springframework.test.context.junit.jupiter.SpringExtension;
private final CommonTestData commonTestData = new CommonTestData();
+ private static final String STATE_VALUE = "STATE_VALUE";
+
@Test
void automationCompositionHandlerTest() {
var ach = commonTestData.getMockAutomationCompositionHandler();
}
@Test
- void handleAutomationCompositionDeployTest() {
+ void handleAutomationCompositionDeployTest() throws PfModelException {
var acd = new AutomationCompositionElementDefinition();
var definition = CommonTestData.getDefinition();
acd.setAcElementDefinitionId(definition);
+ acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
var updateMsg = new AutomationCompositionDeploy();
updateMsg.setAutomationCompositionId(UUID.randomUUID());
var uuid = UUID.randomUUID();
updateMsg.setStartPhase(0);
var acElementDefinitions = List.of(acd);
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ var listener = mock(AutomationCompositionElementListener.class);
+ ach.registerAutomationCompositionElementListener(listener);
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(0)).deploy(any(), any(), anyMap());
updateMsg.setFirstStartPhase(false);
updateMsg.setStartPhase(1);
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(0)).deploy(any(), any(), anyMap());
ach.getAutomationCompositionMap().clear();
updateMsg.setFirstStartPhase(true);
updateMsg.setStartPhase(0);
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(0)).deploy(any(), any(), anyMap());
updateMsg.setAutomationCompositionId(UUID.randomUUID());
updateMsg.setParticipantUpdatesList(List.of(mock(ParticipantDeploy.class)));
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions));
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(0)).deploy(any(), any(), anyMap());
updateMsg.setStartPhase(1);
var participantDeploy = new ParticipantDeploy();
participantDeploy.setAcElementList(List.of(element));
updateMsg.setParticipantUpdatesList(List.of(participantDeploy));
- var acd2 = new AutomationCompositionElementDefinition();
- acd2.setAcElementDefinitionId(definition);
- acd2.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
- assertDoesNotThrow(() -> ach.handleAutomationCompositionDeploy(updateMsg, List.of(acd2)));
-
+ updateMsg.setStartPhase(0);
+ ach.handleAutomationCompositionDeploy(updateMsg, acElementDefinitions);
+ verify(listener, times(1)).deploy(any(), any(), anyMap());
}
@Test
- void acUndeployTest() {
+ void acUndeployTest() throws PfModelException {
var uuid = UUID.randomUUID();
var partecipantId = CommonTestData.getParticipantId();
var definition = CommonTestData.getDefinition();
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
stateChangeUndeploy
.setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
- ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of());
+ var listener = mock(AutomationCompositionElementListener.class);
+ ach.registerAutomationCompositionElementListener(listener);
+
+ var acd = new AutomationCompositionElementDefinition();
+ acd.setAcElementDefinitionId(definition);
+ acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+ ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of(acd));
+ verify(listener, times(1)).undeploy(any(), any());
+
stateChangeUndeploy.setAutomationCompositionId(UUID.randomUUID());
stateChangeUndeploy.setParticipantId(CommonTestData.getRndParticipantId());
assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUndeploy, List.of()));
}
@Test
- void automationCompositionStateUnlock() {
+ void automationCompositionStateLock() throws PfModelException {
+ var uuid = UUID.randomUUID();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
+
+ var stateChangeLock =
+ commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.LOCK);
+
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var listener = mock(AutomationCompositionElementListener.class);
+ ach.registerAutomationCompositionElementListener(listener);
+ stateChangeLock
+ .setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
+ var acd = new AutomationCompositionElementDefinition();
+ acd.setAcElementDefinitionId(definition);
+ acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+ ach.handleAutomationCompositionStateChange(stateChangeLock, List.of(acd));
+ stateChangeLock.setAutomationCompositionId(UUID.randomUUID());
+ stateChangeLock.setParticipantId(CommonTestData.getRndParticipantId());
+ ach.handleAutomationCompositionStateChange(stateChangeLock, List.of());
+ verify(listener, times(1)).lock(any(), any());
+ }
+
+ @Test
+ void automationCompositionStateUnlock() throws PfModelException {
var uuid = UUID.randomUUID();
var partecipantId = CommonTestData.getParticipantId();
var definition = CommonTestData.getDefinition();
commonTestData.getStateChange(partecipantId, uuid, DeployOrder.NONE, LockOrder.UNLOCK);
var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var listener = mock(AutomationCompositionElementListener.class);
+ ach.registerAutomationCompositionElementListener(listener);
stateChangeUnlock
.setAutomationCompositionId(ach.getAutomationCompositionMap().entrySet().iterator().next().getKey());
- ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
+ var acd = new AutomationCompositionElementDefinition();
+ acd.setAcElementDefinitionId(definition);
+ acd.setAutomationCompositionElementToscaNodeTemplate(mock(ToscaNodeTemplate.class));
+ ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of(acd));
stateChangeUnlock.setAutomationCompositionId(UUID.randomUUID());
stateChangeUnlock.setParticipantId(CommonTestData.getRndParticipantId());
- assertDoesNotThrow(() -> ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of()));
+ ach.handleAutomationCompositionStateChange(stateChangeUnlock, List.of());
+ verify(listener, times(1)).unlock(any(), any());
+ }
+
+ @Test
+ void testGetUseState() throws PfModelException {
+ var uuid = UUID.randomUUID();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var listener = mock(AutomationCompositionElementListener.class);
+ when(listener.getUseState(uuid, uuid)).thenReturn(STATE_VALUE);
+ ach.registerAutomationCompositionElementListener(listener);
+ assertEquals(STATE_VALUE, ach.getUseState(uuid, uuid));
+ }
+
+ @Test
+ void testGetOperationalState() throws PfModelException {
+ var uuid = UUID.randomUUID();
+ var partecipantId = CommonTestData.getParticipantId();
+ var definition = CommonTestData.getDefinition();
+ var ach = commonTestData.setTestAutomationCompositionHandler(definition, uuid, partecipantId);
+ var listener = mock(AutomationCompositionElementListener.class);
+ when(listener.getOperationalState(uuid, uuid)).thenReturn(STATE_VALUE);
+ ach.registerAutomationCompositionElementListener(listener);
+ assertEquals(STATE_VALUE, ach.getOperationalState(uuid, uuid));
}
}
}
public static ToscaConceptIdentifier getDefinition() {
- return new ToscaConceptIdentifier("org.onap.PM_CDS_Blueprint", "1.0.1");
+ return new ToscaConceptIdentifier("org.onap.domain.pmsh.PMSH_DCAEMicroservice", "1.2.3");
}
/**
public AutomationCompositionStateChange getStateChange(UUID participantId, UUID uuid,
DeployOrder deployOrder, LockOrder lockOrder) {
var stateChange = new AutomationCompositionStateChange();
+ stateChange.setStartPhase(0);
stateChange.setAutomationCompositionId(UUID.randomUUID());
stateChange.setParticipantId(participantId);
stateChange.setMessageId(uuid);
if (element != null) {
element.setDeployState(acElementAck.getValue().getDeployState());
element.setLockState(acElementAck.getValue().getLockState());
+ if (DeployState.DEPLOYED.equals(element.getDeployState())) {
+ element.setOperationalState(acElementAck.getValue().getOperationalState());
+ element.setUseState(acElementAck.getValue().getUseState());
+ } else {
+ element.setOperationalState(null);
+ element.setUseState(null);
+ }
updated = true;
}
}
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantMessage;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private final ParticipantProvider participantProvider;
private final ParticipantRegisterAckPublisher participantRegisterAckPublisher;
private final ParticipantDeregisterAckPublisher participantDeregisterAckPublisher;
+ private final AutomationCompositionProvider automationCompositionProvider;
/**
* Handle a ParticipantRegister message from a participant.
LOGGER.debug("Participant Status received {}", participantStatusMsg);
saveParticipantStatus(participantStatusMsg,
listToMap(participantStatusMsg.getParticipantSupportedElementType()));
+ if (!participantStatusMsg.getAutomationCompositionInfoList().isEmpty()) {
+ automationCompositionProvider.upgradeStates(participantStatusMsg.getAutomationCompositionInfoList());
+ }
}
private void saveParticipantStatus(ParticipantMessage participantMessage,
var automationCompositionAckMessage =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_STATECHANGE_ACK);
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, true, "");
+ var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.UNLOCKED, "", "", true, "");
automationCompositionAckMessage.getAutomationCompositionResultMap().put(elementEntry.getKey(),
acElementDeployAck);
}
var automationCompositionAckMessage =
new AutomationCompositionDeployAck(ParticipantMessageType.AUTOMATION_COMPOSITION_DEPLOY_ACK);
for (var elementEntry : automationComposition.getElements().entrySet()) {
- var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, true, "");
+ var acElementDeployAck = new AcElementDeployAck(DeployState.DEPLOYED, LockState.LOCKED, "", "", true, "");
automationCompositionAckMessage
.setAutomationCompositionResultMap(Map.of(elementEntry.getKey(), acElementDeployAck));
}
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantDeregister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantRegister;
import org.onap.policy.clamp.models.acm.messages.dmaap.participant.ParticipantStatus;
+import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ParticipantProvider;
class SupervisionParticipantHandlerTest {
participantDeregisterMessage.setParticipantId(CommonTestData.getParticipantId());
var participantDeregisterAckPublisher = mock(ParticipantDeregisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider,
- mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher);
+ mock(ParticipantRegisterAckPublisher.class), participantDeregisterAckPublisher,
+ mock(AutomationCompositionProvider.class));
handler.handleParticipantMessage(participantDeregisterMessage);
var participantProvider = mock(ParticipantProvider.class);
var participantRegisterAckPublisher = mock(ParticipantRegisterAckPublisher.class);
var handler = new SupervisionParticipantHandler(participantProvider, participantRegisterAckPublisher,
- mock(ParticipantDeregisterAckPublisher.class));
+ mock(ParticipantDeregisterAckPublisher.class),
+ mock(AutomationCompositionProvider.class));
handler.handleParticipantMessage(participantRegisterMessage);
verify(participantProvider).saveParticipant(any());
var participantProvider = mock(ParticipantProvider.class);
var handler = new SupervisionParticipantHandler(participantProvider,
- mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class));
+ mock(ParticipantRegisterAckPublisher.class), mock(ParticipantDeregisterAckPublisher.class),
+ mock(AutomationCompositionProvider.class));
var participant = CommonTestData.createParticipant(CommonTestData.getParticipantId());
when(participantProvider.findParticipant(CommonTestData.getParticipantId()))
.thenReturn(Optional.of(participant));