this.deployOrderedState = source.deployOrderedState;
this.lockOrderedState = source.lockOrderedState;
this.startPhase = source.startPhase;
+ this.firstStartPhase = source.firstStartPhase;
}
}
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.common.parameters.annotations.NotNull;
@NotNull
private String compositionId;
- @Column
- @NotNull
- private AutomationCompositionState state;
-
- @Column
- @NotNull
- private AutomationCompositionOrderedState orderedState;
-
@Column
@NotNull
private DeployState deployState;
*/
public JpaAutomationComposition() {
this(UUID.randomUUID().toString(), new PfConceptKey(), UUID.randomUUID().toString(),
- AutomationCompositionState.UNINITIALISED, new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED);
+ new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED);
}
/**
* @param instanceId The UUID of the automation composition instance
* @param key the key
* @param compositionId the TOSCA compositionId of the automation composition definition
- * @param state the state of the automation composition
* @param elements the elements of the automation composition in participants
+ * @param deployState the Deploy State
+ * @param lockState the Lock State
*/
public JpaAutomationComposition(@NonNull final String instanceId, @NonNull final PfConceptKey key,
- @NonNull final String compositionId, @NonNull final AutomationCompositionState state,
+ @NonNull final String compositionId,
@NonNull final List<JpaAutomationCompositionElement> elements,
- @NonNull final DeployState deployState, @NonNull final LockState lockState) {
+ @NonNull final DeployState deployState, @NonNull final LockState lockState) {
this.instanceId = instanceId;
this.name = key.getName();
this.version = key.getVersion();
this.compositionId = compositionId;
- this.state = state;
this.deployState = deployState;
this.lockState = lockState;
this.elements = elements;
this.name = copyConcept.name;
this.version = copyConcept.version;
this.compositionId = copyConcept.compositionId;
- this.state = copyConcept.state;
- this.orderedState = copyConcept.orderedState;
this.deployState = copyConcept.deployState;
this.lockState = copyConcept.lockState;
this.description = copyConcept.description;
automationComposition.setName(name);
automationComposition.setVersion(version);
automationComposition.setCompositionId(UUID.fromString(compositionId));
- automationComposition.setState(state);
- automationComposition.setOrderedState(orderedState != null ? orderedState : state.asOrderedState());
automationComposition.setDeployState(deployState);
automationComposition.setLockState(lockState);
automationComposition.setDescription(description);
this.name = automationComposition.getName();
this.version = automationComposition.getVersion();
this.compositionId = automationComposition.getCompositionId().toString();
- this.state = automationComposition.getState();
- this.orderedState = automationComposition.getOrderedState();
this.deployState = automationComposition.getDeployState();
this.lockState = automationComposition.getLockState();
this.description = automationComposition.getDescription();
return result;
}
- result = ObjectUtils.compare(state, other.state);
- if (result != 0) {
- return result;
- }
-
- result = ObjectUtils.compare(orderedState, other.orderedState);
- if (result != 0) {
- return result;
- }
-
result = ObjectUtils.compare(deployState, other.deployState);
if (result != 0) {
return result;
import lombok.NonNull;
import org.apache.commons.lang3.ObjectUtils;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
import org.onap.policy.clamp.models.acm.concepts.DeployState;
import org.onap.policy.clamp.models.acm.concepts.LockState;
import org.onap.policy.common.parameters.annotations.NotNull;
@NotNull
private String instanceId;
- // @formatter:off
@VerifyKey
@NotNull
@AttributeOverrides({
@NotNull
private String participantId;
- @Column
- @NotNull
- private AutomationCompositionState state;
-
- @Column
- @NotNull
- private AutomationCompositionOrderedState orderedState;
-
@Column
@NotNull
private DeployState deployState;
*/
public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId) {
this(elementId, instanceId, new PfConceptKey(),
- AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, LockState.LOCKED);
+ DeployState.UNDEPLOYED, LockState.LOCKED);
}
/**
* @param elementId The id of the automation composition instance Element
* @param instanceId The id of the automation composition instance
* @param definition the TOSCA definition of the automation composition element
- * @param state the state of the automation composition
+ * @param deployState the Deploy State of the automation composition
+ * @param lockState the Lock State of the automation composition
*/
public JpaAutomationCompositionElement(@NonNull final String elementId, @NonNull final String instanceId,
@NonNull final PfConceptKey definition,
- @NonNull final AutomationCompositionState state,
- @NonNull final DeployState deployState, @NonNull final LockState lockState) {
+ @NonNull final DeployState deployState, @NonNull final LockState lockState) {
this.elementId = elementId;
this.instanceId = instanceId;
this.definition = definition;
- this.state = state;
this.deployState = deployState;
this.lockState = lockState;
}
this.instanceId = copyConcept.instanceId;
this.definition = new PfConceptKey(copyConcept.definition);
this.participantId = copyConcept.participantId;
- this.state = copyConcept.state;
- this.orderedState = copyConcept.orderedState;
this.description = copyConcept.description;
this.properties = (copyConcept.properties != null ? new LinkedHashMap<>(copyConcept.properties) : null);
this.deployState = copyConcept.deployState;
element.setId(UUID.fromString(elementId));
element.setDefinition(new ToscaConceptIdentifier(definition));
element.setParticipantId(UUID.fromString(participantId));
- element.setState(state);
- element.setOrderedState(orderedState != null ? orderedState : state.asOrderedState());
element.setDescription(description);
element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
element.setDeployState(deployState);
public void fromAuthorative(@NonNull final AutomationCompositionElement element) {
this.definition = element.getDefinition().asConceptKey();
this.participantId = element.getParticipantId().toString();
- this.state = element.getState();
- this.orderedState = element.getOrderedState();
this.description = element.getDescription();
- properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
+ this.properties = PfUtils.mapMap(element.getProperties(), UnaryOperator.identity());
this.deployState = element.getDeployState();
this.lockState = element.getLockState();
}
return result;
}
- result = ObjectUtils.compare(state, other.state);
- if (result != 0) {
- return result;
- }
-
- result = ObjectUtils.compare(orderedState, other.orderedState);
- if (result != 0) {
- return result;
- }
-
result = ObjectUtils.compare(deployState, other.deployState);
if (result != 0) {
return result;
*/
public AutomationComposition updateAutomationComposition(
@NonNull final AutomationComposition automationComposition) {
- AcmUtils.setCascadedState(automationComposition, DeployState.UNDEPLOYED, LockState.NONE);
var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition,
JpaAutomationComposition::new, "automation composition"));
example.setVersion(version);
example.setInstanceId(null);
example.setElements(null);
- example.setState(null);
example.setDeployState(null);
example.setLockState(null);
import java.time.Instant;
import java.util.UUID;
import org.junit.jupiter.api.Test;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+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.clamp.models.acm.utils.CommonTestData;
import org.onap.policy.common.utils.coder.CoderException;
orig.setAutomationCompositionId(UUID.randomUUID());
orig.setParticipantId(CommonTestData.getParticipantId());
orig.setMessageId(UUID.randomUUID());
- orig.setOrderedState(AutomationCompositionOrderedState.RUNNING);
- orig.setCurrentState(AutomationCompositionState.PASSIVE);
+ orig.setDeployOrderedState(DeployOrder.DEPLOY);
+ orig.setLockOrderedState(LockOrder.NONE);
orig.setTimestamp(Instant.ofEpochMilli(3000));
assertEquals(removeVariableFields(orig.toString()),
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElementDefinition;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionInfo;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
+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.ParticipantDefinition;
import org.onap.policy.clamp.models.acm.concepts.ParticipantState;
import org.onap.policy.clamp.models.acm.utils.CommonTestData;
private AutomationCompositionInfo getAutomationCompositionInfo(UUID id) {
var acInfo = new AutomationCompositionInfo();
- acInfo.setState(AutomationCompositionState.PASSIVE2RUNNING);
+ acInfo.setDeployState(DeployState.DEPLOYED);
+ acInfo.setLockState(LockState.LOCKED);
acInfo.setAutomationCompositionId(id);
return acInfo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.File;
import java.util.Map;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
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.Participant;
import org.onap.policy.clamp.models.acm.utils.CommonTestData;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfConceptKey;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
}).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement(null, null, null, null, null, null);
+ new JpaAutomationCompositionElement(null, null, null, null, null);
}).hasMessageMatching(NULL_ELEMENT_ID_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationCompositionElement("key", null, null,
- AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, LockState.LOCKED);
+ DeployState.UNDEPLOYED, LockState.LOCKED);
}).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationCompositionElement("key", "key", null,
- AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, LockState.LOCKED);
- }).hasMessageMatching("definition" + NULL_ERROR);
-
- assertThatThrownBy(() -> {
- new JpaAutomationCompositionElement("key", "key", new PfConceptKey(), null,
DeployState.UNDEPLOYED, LockState.LOCKED);
- }).hasMessageMatching("state" + NULL_ERROR);
+ }).hasMessageMatching("definition" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationCompositionElement("key", "key", new PfConceptKey(),
- AutomationCompositionState.UNINITIALISED, null, LockState.LOCKED);
+ null, LockState.LOCKED);
}).hasMessageMatching("deployState" + NULL_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationCompositionElement("key", "key", new PfConceptKey(),
- AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, null);
+ DeployState.UNDEPLOYED, null);
}).hasMessageMatching("lockState" + NULL_ERROR);
assertNotNull(new JpaAutomationCompositionElement());
assertNotNull(new JpaAutomationCompositionElement("key", "key"));
assertNotNull(new JpaAutomationCompositionElement("key", "key",
- new PfConceptKey(), AutomationCompositionState.UNINITIALISED, DeployState.UNDEPLOYED, LockState.LOCKED));
+ new PfConceptKey(), DeployState.UNDEPLOYED, LockState.LOCKED));
}
@Test
assertEquals(testJpaAcElement, testJpaAutomationCompositionElement2);
}
- @Test
- void testJpaAutomationCompositionElementOrderedState() throws CoderException {
- var testAutomationCompositionElement = createAutomationCompositionElementInstance();
- var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
-
- testJpaAutomationCompositionElement.setOrderedState(null);
- assertEquals(testAutomationCompositionElement, testJpaAutomationCompositionElement.toAuthorative());
- testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
-
- var noOrderedStateAce = new StandardCoder().decode(
- new File("src/test/resources/json/AutomationCompositionElementNoOrderedState.json"),
- AutomationCompositionElement.class);
-
- var noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
- assertNull(noOrderedStateJpaAce.getOrderedState());
- noOrderedStateAce.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- noOrderedStateJpaAce = new JpaAutomationCompositionElement(noOrderedStateAce);
- noOrderedStateJpaAce.setInstanceId(testJpaAutomationCompositionElement.getInstanceId());
- noOrderedStateJpaAce.setElementId(testJpaAutomationCompositionElement.getElementId());
- noOrderedStateJpaAce.setParticipantId(testJpaAutomationCompositionElement.getParticipantId());
- assertEquals(testJpaAutomationCompositionElement, noOrderedStateJpaAce);
- }
-
@Test
void testJpaAutomationCompositionElementValidation() {
var testJpaAutomationCompositionElement = createJpaAutomationCompositionElementInstance();
testJpaAutomationCompositionElement.setDescription(null);
assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
- testJpaAutomationCompositionElement.setState(AutomationCompositionState.PASSIVE);
- assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
- testJpaAutomationCompositionElement.setState(AutomationCompositionState.UNINITIALISED);
- assertEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
-
testJpaAutomationCompositionElement.setDeployState(DeployState.DEPLOYED);
assertNotEquals(0, testJpaAutomationCompositionElement.compareTo(otherJpaAutomationCompositionElement));
testJpaAutomationCompositionElement.setDeployState(DeployState.UNDEPLOYED);
ace1.setDefinition(new PfConceptKey("defName", "0.0.1"));
ace1.setDescription("Description");
- ace1.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- ace1.setState(AutomationCompositionState.UNINITIALISED);
ace1.setParticipantId(CommonTestData.getJpaParticipantId());
assertThat(ace1.toString()).contains("AutomationCompositionElement(");
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.UUID;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.models.acm.concepts.AutomationComposition;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionOrderedState;
-import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionState;
-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.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.base.PfConceptKey;
/**
}).hasMessageMatching("authorativeConcept is marked .*ull but is null");
assertThatThrownBy(() -> {
- new JpaAutomationComposition(null, null, null, null, null, null, null);
+ new JpaAutomationComposition(null, null, null, null, null, null);
}).hasMessageMatching(NULL_INSTANCE_ID_ERROR);
assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID, null, null, null, new ArrayList<>(),
+ new JpaAutomationComposition(INSTANCE_ID, null, null, new ArrayList<>(),
DeployState.UNDEPLOYED, LockState.LOCKED);
}).hasMessageMatching("key" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), null,
- AutomationCompositionState.UNINITIALISED, new ArrayList<>(),
- DeployState.UNDEPLOYED, LockState.LOCKED);
+ new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED);
}).hasMessageMatching("compositionId" + NULL_TEXT_ERROR);
- assertThatThrownBy(() -> {
- new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(), null,
- new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED);
- }).hasMessageMatching("state" + NULL_TEXT_ERROR);
-
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(),
- AutomationCompositionState.UNINITIALISED, null, DeployState.UNDEPLOYED, LockState.LOCKED);
+ null, DeployState.UNDEPLOYED, LockState.LOCKED);
}).hasMessageMatching("elements" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(),
- AutomationCompositionState.UNINITIALISED, new ArrayList<>(), null, LockState.LOCKED);
+ new ArrayList<>(), null, LockState.LOCKED);
}).hasMessageMatching("deployState" + NULL_TEXT_ERROR);
assertThatThrownBy(() -> {
new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(),
- AutomationCompositionState.UNINITIALISED, new ArrayList<>(), DeployState.UNDEPLOYED, null);
+ new ArrayList<>(), DeployState.UNDEPLOYED, null);
}).hasMessageMatching("lockState" + NULL_TEXT_ERROR);
assertNotNull(new JpaAutomationComposition());
assertNotNull(new JpaAutomationComposition(INSTANCE_ID, new PfConceptKey(), COMPOSITION_ID.toString(),
- AutomationCompositionState.UNINITIALISED, new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED));
+ new ArrayList<>(), DeployState.UNDEPLOYED, LockState.LOCKED));
}
@Test
assertEquals(testJpaAutomationComposition, testJpaAutomationComposition2);
}
- @Test
- void testJpaAutomationCompositionElementOrderedState() throws CoderException {
- var testAutomationComposition = createAutomationCompositionInstance();
- var testJpaAutomationComposition = createJpaAutomationCompositionInstance();
-
- testJpaAutomationComposition.setOrderedState(null);
- assertEquals(testAutomationComposition, testJpaAutomationComposition.toAuthorative());
- testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
-
- var noOrderedStateAc =
- new StandardCoder().decode(new File("src/test/resources/json/AutomationCompositionNoOrderedState.json"),
- AutomationComposition.class);
-
- noOrderedStateAc.setInstanceId(UUID.fromString(INSTANCE_ID));
- var noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
- assertNull(noOrderedStateJpaAc.getOrderedState());
- noOrderedStateAc.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
- noOrderedStateJpaAc = new JpaAutomationComposition(noOrderedStateAc);
- assertEquals(testJpaAutomationComposition, noOrderedStateJpaAc);
-
- var acWithElements =
- new StandardCoder().decode(new File("src/test/resources/providers/TestAutomationCompositions.json"),
- AutomationCompositions.class).getAutomationCompositionList().get(0);
-
- acWithElements.setInstanceId(UUID.fromString(INSTANCE_ID));
- var jpaAutomationCompositionWithElements = new JpaAutomationComposition(acWithElements);
- assertEquals(4, jpaAutomationCompositionWithElements.getElements().size());
- assertEquals(acWithElements, jpaAutomationCompositionWithElements.toAuthorative());
- }
-
@Test
void testJpaAutomationCompositionValidation() {
var testJpaAutomationComposition = createJpaAutomationCompositionInstance();
testJpaAutomationComposition.setVersion("0.0.1");
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- testJpaAutomationComposition.setState(AutomationCompositionState.PASSIVE);
+ testJpaAutomationComposition.setDeployState(DeployState.DEPLOYED);
assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- testJpaAutomationComposition.setState(AutomationCompositionState.UNINITIALISED);
+ testJpaAutomationComposition.setDeployState(DeployState.UNDEPLOYED);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.PASSIVE);
+ testJpaAutomationComposition.setLockState(LockState.UNLOCKED);
assertNotEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
- testJpaAutomationComposition.setOrderedState(AutomationCompositionOrderedState.UNINITIALISED);
+ testJpaAutomationComposition.setLockState(LockState.NONE);
assertEquals(0, testJpaAutomationComposition.compareTo(otherJpaAutomationComposition));
testJpaAutomationComposition.setDescription("A description");
ac1.setDescription("Description");
ac1.setElements(new ArrayList<>());
ac1.setInstanceId(INSTANCE_ID);
- ac1.setState(AutomationCompositionState.UNINITIALISED);
assertThat(ac1.toString()).contains("AutomationComposition(");
assertNotEquals(0, ac1.hashCode());
import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
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.AutomationCompositionState;
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.messages.rest.instantiation.AcInstanceStateUpdate;
import org.onap.policy.clamp.models.acm.messages.rest.instantiation.InstantiationResponse;
import org.onap.policy.clamp.models.acm.persistence.provider.AcDefinitionProvider;
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
+ if (!DeployState.UNDEPLOYED.equals(acToUpdate.getDeployState())) {
+ throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
+ "Not allow to update for state in " + acToUpdate.getDeployState());
+ }
acToUpdate.setElements(automationComposition.getElements());
acToUpdate.setName(automationComposition.getName());
acToUpdate.setVersion(automationComposition.getVersion());
return result;
}
if (!AcTypeState.PRIMED.equals(acDefinitionOpt.get().getState())) {
- result.addResult(new ObjectValidationResult("ServiceTemplate", "", ValidationStatus.INVALID,
- "Commissioned automation composition definition not primed"));
+ result.addResult(new ObjectValidationResult("ServiceTemplate", acDefinitionOpt.get().getState(),
+ ValidationStatus.INVALID, "Commissioned automation composition definition not primed"));
return result;
}
result.addResult(AcmUtils.validateAutomationComposition(automationComposition,
var automationComposition = automationCompositionProvider.getAutomationComposition(instanceId);
if (!automationComposition.getCompositionId().equals(compositionId)) {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
- "Composition Id " + compositionId + DO_NOT_MATCH + automationComposition.getCompositionId());
+ automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
return automationComposition;
}
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
automationComposition.getCompositionId() + DO_NOT_MATCH + compositionId);
}
- if (!AutomationCompositionState.UNINITIALISED.equals(automationComposition.getState())) {
+ if (!DeployState.UNDEPLOYED.equals(automationComposition.getDeployState())) {
throw new PfModelRuntimeException(Response.Status.BAD_REQUEST,
- "Automation composition state is still " + automationComposition.getState());
+ "Automation composition state is still " + automationComposition.getDeployState());
}
var response = new InstantiationResponse();
automationComposition =
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.UUID;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.onap.policy.clamp.acm.runtime.supervision.SupervisionAcHandler;
import org.onap.policy.clamp.acm.runtime.util.CommonTestData;
import org.onap.policy.clamp.common.acm.exception.AutomationCompositionException;
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.AutomationCompositionState;
+import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+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.messages.rest.instantiation.AcInstanceStateUpdate;
+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.clamp.models.acm.persistence.provider.AcDefinitionProvider;
+import org.onap.policy.clamp.models.acm.persistence.provider.AcInstanceStateResolver;
import org.onap.policy.clamp.models.acm.persistence.provider.AutomationCompositionProvider;
import org.onap.policy.clamp.models.acm.persistence.provider.ProviderUtils;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(wrongCompositionId, instanceId))
.hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
- for (var state : AutomationCompositionState.values()) {
- if (!AutomationCompositionState.UNINITIALISED.equals(state)) {
- assertThatDeleteThrownBy(automationComposition, state);
- }
- }
- automationComposition.setState(AutomationCompositionState.UNINITIALISED);
+ assertThatDeleteThrownBy(automationComposition, DeployState.DEPLOYED, LockState.LOCKED);
+ assertThatDeleteThrownBy(automationComposition, DeployState.DEPLOYING, LockState.NONE);
+ assertThatDeleteThrownBy(automationComposition, DeployState.UNDEPLOYING, LockState.LOCKED);
+
+ automationComposition.setDeployState(DeployState.UNDEPLOYED);
+ automationComposition.setLockState(LockState.NONE);
when(acProvider.deleteAutomationComposition(instanceId)).thenReturn(automationComposition);
instantiationProvider.deleteAutomationComposition(compositionId, instanceId);
}
private void assertThatDeleteThrownBy(AutomationComposition automationComposition,
- AutomationCompositionState state) {
- automationComposition.setState(state);
+ DeployState deployState, LockState lockState) {
+ automationComposition.setDeployState(deployState);
+ automationComposition.setLockState(lockState);
var acProvider = mock(AutomationCompositionProvider.class);
var acDefinitionProvider = mock(AcDefinitionProvider.class);
var compositionId = automationComposition.getCompositionId();
var instanceId = automationComposition.getInstanceId();
assertThatThrownBy(() -> instantiationProvider.deleteAutomationComposition(compositionId, instanceId))
- .hasMessageMatching(String.format(DELETE_BAD_REQUEST, state));
+ .hasMessageMatching(String.format(DELETE_BAD_REQUEST, deployState));
}
@Test
}
@Test
- void testCreateAutomationCompositions_CommissionedAcNotFound() {
+ void testAcDefinitionNotFound() {
var automationComposition = InstantiationUtils
.getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
var acProvider = mock(AutomationCompositionProvider.class);
when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
.thenReturn(automationComposition);
- var acDefinitionProvider = mock(AcDefinitionProvider.class);
var provider = new AutomationCompositionInstantiationProvider(acProvider,
- acDefinitionProvider, null, null);
+ mock(AcDefinitionProvider.class), null, null);
var compositionId = automationComposition.getCompositionId();
assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
assertThatThrownBy(() -> provider.updateAutomationComposition(compositionId, automationComposition))
.hasMessageMatching(AC_DEFINITION_NOT_FOUND);
+ }
+
+ @Test
+ void testCompositionIdDoNotMatch() {
+ var automationComposition = InstantiationUtils
+ .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
+
+ var acProvider = mock(AutomationCompositionProvider.class);
+ when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ var provider = new AutomationCompositionInstantiationProvider(acProvider,
+ mock(AcDefinitionProvider.class), null, null);
+ var compositionId = automationComposition.getCompositionId();
var wrongCompositionId = UUID.randomUUID();
assertThatThrownBy(() -> provider.createAutomationComposition(wrongCompositionId, automationComposition))
.hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
assertThatThrownBy(() -> provider.updateAutomationComposition(wrongCompositionId, automationComposition))
.hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
+
+ assertThatThrownBy(
+ () -> provider.getAutomationComposition(wrongCompositionId, automationComposition.getInstanceId()))
+ .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
+ assertThatThrownBy(() -> provider.compositionInstanceState(wrongCompositionId,
+ automationComposition.getInstanceId(), new AcInstanceStateUpdate()))
+ .hasMessageMatching(compositionId + DO_NOT_MATCH + wrongCompositionId);
+ }
+
+ @Test
+ void testCompositionNotPrimed() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.COMMISSIONED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.findAcDefinition(compositionId)).thenReturn(Optional.of(acDefinition));
+ var acProvider = mock(AutomationCompositionProvider.class);
+ var provider =
+ new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider, null, null);
+
+ var automationComposition =
+ InstantiationUtils.getAutomationCompositionFromResource(AC_INSTANTIATION_CREATE_JSON, "Crud");
+ automationComposition.setCompositionId(compositionId);
+ assertThatThrownBy(() -> provider.createAutomationComposition(compositionId, automationComposition))
+ .hasMessageMatching("\"AutomationComposition\" INVALID, item has status INVALID\n"
+ + " item \"ServiceTemplate\" value \"COMMISSIONED\" INVALID,"
+ + " Commissioned automation composition definition not primed\n");
+ }
+
+ @Test
+ void testUpdateBadRequest() {
+ var automationComposition = InstantiationUtils
+ .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
+
+ var acProvider = mock(AutomationCompositionProvider.class);
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ when(acProvider.getAutomationComposition(automationComposition.getInstanceId()))
+ .thenReturn(automationComposition);
+ var provider = new AutomationCompositionInstantiationProvider(acProvider,
+ mock(AcDefinitionProvider.class), null, null);
+
+ assertThatThrownBy(() -> provider.updateAutomationComposition(automationComposition.getCompositionId(),
+ automationComposition)).hasMessageMatching("Not allow to update for state in DEPLOYED");
+ }
+
+ @Test
+ void testCompositionInstanceState() {
+ var acDefinitionProvider = mock(AcDefinitionProvider.class);
+ var acDefinition = CommonTestData.createAcDefinition(serviceTemplate, AcTypeState.COMMISSIONED);
+ var compositionId = acDefinition.getCompositionId();
+ when(acDefinitionProvider.getAcDefinition(compositionId)).thenReturn(acDefinition);
+
+ var automationComposition = InstantiationUtils
+ .getAutomationCompositionFromResource(AC_INSTANTIATION_AC_DEFINITION_NOT_FOUND_JSON, "AcNotFound");
+ var instanceId = UUID.randomUUID();
+ automationComposition.setCompositionId(compositionId);
+ automationComposition.setInstanceId(instanceId);
+ var acProvider = mock(AutomationCompositionProvider.class);
+ when(acProvider.getAutomationComposition(instanceId))
+ .thenReturn(automationComposition);
+
+ var supervisionAcHandler = mock(SupervisionAcHandler.class);
+ var provider = new AutomationCompositionInstantiationProvider(acProvider, acDefinitionProvider,
+ new AcInstanceStateResolver(), supervisionAcHandler);
+
+ var acInstanceStateUpdate = new AcInstanceStateUpdate();
+ acInstanceStateUpdate.setDeployOrder(DeployOrder.DEPLOY);
+ acInstanceStateUpdate.setLockOrder(LockOrder.NONE);
+ provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate);
+ verify(supervisionAcHandler).deploy(any(AutomationComposition.class),
+ any(AutomationCompositionDefinition.class));
+
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.LOCKED);
+ acInstanceStateUpdate.setDeployOrder(DeployOrder.UNDEPLOY);
+ provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate);
+ verify(supervisionAcHandler).undeploy(any(AutomationComposition.class),
+ any(AutomationCompositionDefinition.class));
+
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.LOCKED);
+ acInstanceStateUpdate.setDeployOrder(DeployOrder.NONE);
+ acInstanceStateUpdate.setLockOrder(LockOrder.UNLOCK);
+ provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate);
+ verify(supervisionAcHandler).unlock(any(AutomationComposition.class),
+ any(AutomationCompositionDefinition.class));
+
+ automationComposition.setDeployState(DeployState.DEPLOYED);
+ automationComposition.setLockState(LockState.UNLOCKED);
+ acInstanceStateUpdate.setDeployOrder(DeployOrder.NONE);
+ acInstanceStateUpdate.setLockOrder(LockOrder.LOCK);
+ provider.compositionInstanceState(compositionId, instanceId, acInstanceStateUpdate);
+ verify(supervisionAcHandler).lock(any(AutomationComposition.class),
+ any(AutomationCompositionDefinition.class));
}
}
+++ /dev/null
-{
- "orderedState": "PASSIVE",
- "automationCompositionIdentifier": {
- "name": "PMSHInstance0",
- "version": "1.0.1"
- }
-}
\ No newline at end of file