aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/main/java/org
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-04-05 16:32:38 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2023-04-11 10:06:21 +0100
commit9f1fdf9f419c1724a9cf75a20fdd24df191766bd (patch)
tree16db3d01d45ae45a4fc776d9d23596ec2c6bcc58 /models/src/main/java/org
parent2ca7552978f5389ef5ed2e5d4be3cb43e446f7c6 (diff)
Add UseState and OperationalState support in ACM
Issue-ID: POLICY-4639 Change-Id: Iac5249c054bf41d830463826a8f61f477c48235b Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java/org')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java4
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java58
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java6
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java22
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java26
6 files changed, 122 insertions, 0 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
index 8f8a54f39..611336058 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AcElementDeployAck.java
@@ -37,6 +37,10 @@ public class AcElementDeployAck {
// State of the AutomationCompositionElement
private LockState lockState;
+ private String operationalState;
+
+ private String useState;
+
// Result: Success/Fail.
private Boolean result;
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
index 018031624..edc9e1c5f 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElement.java
@@ -54,6 +54,10 @@ public class AutomationCompositionElement {
@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,
@@ -73,5 +77,7 @@ public class AutomationCompositionElement {
this.properties = PfUtils.mapMap(otherElement.properties, UnaryOperator.identity());
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
+ this.operationalState = otherElement.operationalState;
+ this.useState = otherElement.useState;
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java
new file mode 100644
index 000000000..1eb4bf8cb
--- /dev/null
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionElementInfo.java
@@ -0,0 +1,58 @@
+/*-
+ * ============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;
+ }
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java
index 17875c429..64cfa8034 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/concepts/AutomationCompositionInfo.java
@@ -20,10 +20,13 @@
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.
@@ -39,6 +42,8 @@ public class AutomationCompositionInfo {
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.
*
@@ -48,5 +53,6 @@ public class AutomationCompositionInfo {
this.automationCompositionId = otherElement.automationCompositionId;
this.deployState = otherElement.deployState;
this.lockState = otherElement.lockState;
+ this.elements = PfUtils.mapList(otherElement.elements, AutomationCompositionElementInfo::new);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
index 4c3a6a3be..4ba336edf 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/concepts/JpaAutomationCompositionElement.java
@@ -93,6 +93,12 @@ public class JpaAutomationCompositionElement extends Validated
private LockState lockState;
@Column
+ private String operationalState;
+
+ @Column
+ private String useState;
+
+ @Column
private String description;
@Lob
@@ -152,6 +158,8 @@ public class JpaAutomationCompositionElement extends Validated
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;
}
/**
@@ -174,6 +182,8 @@ public class JpaAutomationCompositionElement extends Validated
element.setProperties(PfUtils.mapMap(properties, UnaryOperator.identity()));
element.setDeployState(deployState);
element.setLockState(lockState);
+ element.setOperationalState(operationalState);
+ element.setUseState(useState);
return element;
}
@@ -186,6 +196,8 @@ public class JpaAutomationCompositionElement extends Validated
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
@@ -227,6 +239,16 @@ public class JpaAutomationCompositionElement extends Validated
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);
}
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
index 058feae76..959fd7637 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java
@@ -22,6 +22,7 @@
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;
@@ -30,9 +31,12 @@ import javax.ws.rs.core.Response.Status;
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;
@@ -50,6 +54,7 @@ import org.springframework.transaction.annotation.Transactional;
public class AutomationCompositionProvider {
private final AutomationCompositionRepository automationCompositionRepository;
+ private final AutomationCompositionElementRepository acElementRepository;
/**
* Get automation composition.
@@ -182,4 +187,25 @@ public class AutomationCompositionProvider {
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);
+ }
}