aboutsummaryrefslogtreecommitdiffstats
path: root/models/src/main/java/org/onap
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2023-12-14 17:33:57 +0000
committerFrancesco Fiora <francesco.fiora@est.tech>2024-03-08 16:14:43 +0000
commitb75038fab6ae0816413ed9f925639f3befe4fddb (patch)
treeb6867f9a3be4f7aacaa2eaa2a7d1440097ac87e7 /models/src/main/java/org/onap
parent33751b41710ad0b31ee3b4aa8346591d5ecb36ad (diff)
Update compositions and instances monitoring
Improved performance scanning only compositions and instances that are in transition. Issue-ID: POLICY-4906 Change-Id: I7a849e921f1d97509f67ff624c715c893a1432ab Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'models/src/main/java/org/onap')
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java50
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AutomationCompositionProvider.java18
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java11
-rw-r--r--models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java13
4 files changed, 78 insertions, 14 deletions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
index a9b9a0cfd..9eb5e7a32 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/provider/AcDefinitionProvider.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -28,10 +28,14 @@ import java.util.UUID;
import lombok.RequiredArgsConstructor;
import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.concepts.NodeTemplateState;
+import org.onap.policy.clamp.models.acm.concepts.StateChangeResult;
import org.onap.policy.clamp.models.acm.document.base.ToscaServiceTemplateValidation;
import org.onap.policy.clamp.models.acm.document.concepts.DocToscaServiceTemplate;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
+import org.onap.policy.clamp.models.acm.persistence.concepts.JpaNodeTemplateState;
import org.onap.policy.clamp.models.acm.persistence.repository.AutomationCompositionDefinitionRepository;
+import org.onap.policy.clamp.models.acm.persistence.repository.NodeTemplateStateRepository;
import org.onap.policy.clamp.models.acm.utils.AcmUtils;
import org.onap.policy.common.parameters.BeanValidationResult;
import org.onap.policy.models.base.PfModelRuntimeException;
@@ -47,6 +51,7 @@ import org.springframework.transaction.annotation.Transactional;
public class AcDefinitionProvider {
private final AutomationCompositionDefinitionRepository acmDefinitionRepository;
+ private final NodeTemplateStateRepository nodeTemplateStateRepository;
/**
* Create Automation Composition Definition.
@@ -125,6 +130,43 @@ public class AcDefinitionProvider {
}
/**
+ * Update Ac Definition AcTypeState, StateChangeResult and restarting.
+ *
+ * @param compositionId The UUID of the automation composition definition to update
+ * @param state the AcTypeState
+ * @param stateChangeResult the StateChangeResult
+ * @param restarting restarting process
+ */
+ public void updateAcDefinitionState(UUID compositionId, AcTypeState state, StateChangeResult stateChangeResult,
+ Boolean restarting) {
+ var jpaUpdate = acmDefinitionRepository.findById(compositionId.toString());
+ if (jpaUpdate.isEmpty()) {
+ String errorMessage = "update of Automation Composition Definition \"" + compositionId
+ + "\" failed, Automation Composition Definition does not exist";
+ throw new PfModelRuntimeException(Response.Status.NOT_FOUND, errorMessage);
+ }
+ var acDefinition = jpaUpdate.get();
+ acDefinition.setState(state);
+ acDefinition.setStateChangeResult(stateChangeResult);
+ acDefinition.setRestarting(restarting);
+ acmDefinitionRepository.save(acDefinition);
+ acmDefinitionRepository.flush();
+ }
+
+ /**
+ * Update Ac DefinitionElement.
+ *
+ * @param nodeTemplateState the NodeTemplateState
+ * @param compositionId The UUID of the automation composition definition
+ */
+ public void updateAcDefinitionElement(NodeTemplateState nodeTemplateState, UUID compositionId) {
+ var jpaNodeTemplateState = new JpaNodeTemplateState(
+ nodeTemplateState.getNodeTemplateStateId().toString(), compositionId.toString());
+ jpaNodeTemplateState.fromAuthorative(nodeTemplateState);
+ nodeTemplateStateRepository.save(jpaNodeTemplateState);
+ }
+
+ /**
* Delete Automation Composition Definition.
*
* @param compositionId The UUID of the automation composition definition to delete
@@ -173,13 +215,13 @@ public class AcDefinitionProvider {
}
/**
- * Get Automation Composition Definitions.
+ * Get Automation Composition Definitions in transition.
*
* @return the Automation Composition Definitions found
*/
@Transactional(readOnly = true)
- public List<AutomationCompositionDefinition> getAllAcDefinitions() {
- var jpaList = acmDefinitionRepository.findAll();
+ public List<AutomationCompositionDefinition> getAllAcDefinitionsInTransition() {
+ var jpaList = acmDefinitionRepository.findByStateIn(List.of(AcTypeState.PRIMING, AcTypeState.DEPRIMING));
return ProviderUtils.asEntityList(jpaList);
}
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 1ffcc1b6e..8be12960b 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
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2023 Nordix Foundation.
+ * Copyright (C) 2021-2024 Nordix Foundation.
* ================================================================================
* Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
@@ -127,7 +127,7 @@ public class AutomationCompositionProvider {
@NonNull final AutomationComposition automationComposition) {
var result = automationCompositionRepository.save(ProviderUtils.getJpaAndValidate(automationComposition,
JpaAutomationComposition::new, "automation composition"));
-
+ automationCompositionRepository.flush();
// Return the saved automation composition
return result.toAuthorative();
}
@@ -145,6 +145,20 @@ public class AutomationCompositionProvider {
}
/**
+ * Get all automation compositions in transition..
+ *
+ * @return all automation compositions found
+ */
+ @Transactional(readOnly = true)
+ public List<AutomationComposition> getAcInstancesInTransition() {
+ var jpaList = automationCompositionRepository.findByDeployStateIn(List.of(DeployState.DEPLOYING,
+ DeployState.UNDEPLOYING, DeployState.DELETING, DeployState.UPDATING, DeployState.MIGRATING));
+ jpaList.addAll(automationCompositionRepository.findByLockStateIn(
+ List.of(LockState.LOCKING, LockState.UNLOCKING)));
+ return ProviderUtils.asEntityList(jpaList);
+ }
+
+ /**
* Get automation compositions.
*
* @param name the name of the automation composition to get, null to get all automation compositions
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java
index df4d7dffa..86de60bf2 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionDefinitionRepository.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation.
+ * Copyright (C) 2022,2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,13 +20,16 @@
package org.onap.policy.clamp.models.acm.persistence.repository;
+import java.util.Collection;
+import java.util.List;
+import org.onap.policy.clamp.models.acm.concepts.AcTypeState;
import org.onap.policy.clamp.models.acm.persistence.concepts.JpaAutomationCompositionDefinition;
import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
@Repository
public interface AutomationCompositionDefinitionRepository
- extends JpaRepository<JpaAutomationCompositionDefinition, String>,
- QueryByExampleExecutor<JpaAutomationCompositionDefinition> {
+ extends JpaRepository<JpaAutomationCompositionDefinition, String> {
+
+ List<JpaAutomationCompositionDefinition> findByStateIn(Collection<AcTypeState> states);
}
diff --git a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
index bb8b3e6d9..d61dfb41b 100644
--- a/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
+++ b/models/src/main/java/org/onap/policy/clamp/models/acm/persistence/repository/AutomationCompositionRepository.java
@@ -1,6 +1,6 @@
/*-
* ============LICENSE_START=======================================================
- * Copyright (C) 2021-2022 Nordix Foundation.
+ * Copyright (C) 2021-2022,2024 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,15 +20,20 @@
package org.onap.policy.clamp.models.acm.persistence.repository;
+import java.util.Collection;
import java.util.List;
+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.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
import org.springframework.stereotype.Repository;
@Repository
-public interface AutomationCompositionRepository
- extends JpaRepository<JpaAutomationComposition, String>, QueryByExampleExecutor<JpaAutomationComposition> {
+public interface AutomationCompositionRepository extends JpaRepository<JpaAutomationComposition, String> {
List<JpaAutomationComposition> findByCompositionId(String compositionId);
+
+ List<JpaAutomationComposition> findByDeployStateIn(Collection<DeployState> deployStates);
+
+ List<JpaAutomationComposition> findByLockStateIn(Collection<LockState> lockStates);
}