diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2020-10-20 18:39:21 +0100 |
---|---|---|
committer | waqas.ikram <waqas.ikram@est.tech> | 2020-10-21 15:59:57 +0100 |
commit | eb00f2d1bbc80fb858f15a565a54fa8336c6650d (patch) | |
tree | f6fa694420cd726f887a66c0c6bc1206bec5a730 /so-etsi-nfvo | |
parent | 623dbe5cf31cec13c3c6eec7b74791682eb3b731 (diff) |
Fixing Update status query for NfvoNfInst
Change-Id: Iaa9119532c3005001c5af73f904a9395048ffd11
Issue-ID: SO-2868
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'so-etsi-nfvo')
7 files changed, 79 insertions, 51 deletions
diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/AbstractNetworkServiceTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/AbstractNetworkServiceTask.java index e94b3de81e..a785a5199b 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/AbstractNetworkServiceTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/AbstractNetworkServiceTask.java @@ -19,9 +19,9 @@ */ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.tasks; -import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.JOB_ID_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_INSTANCE_ID_PARAM_NAME; +import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.NS_WORKFLOW_PROCESSING_EXCEPTION_PARAM_NAME; import static org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.CamundaVariableNameConstants.OCC_ID_PARAM_NAME; import java.time.LocalDateTime; import java.util.Optional; @@ -31,7 +31,6 @@ import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJobStatus; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; @@ -109,21 +108,8 @@ public abstract class AbstractNetworkServiceTask { public void updateNsLcmOpOccStatusToCompleted(final DelegateExecution execution) { logger.info("Executing updateNsLcmOpOccStatusToCompleted ..."); - final String occId = (String) execution.getVariable(OCC_ID_PARAM_NAME); - final Optional<NsLcmOpOcc> optional = databaseServiceProvider.getNsLcmOpOcc(occId); - - if (optional.isEmpty()) { - final String message = "Unable to find record for NSLcmOpOcc in database using id: " + occId; - logger.error(message); - abortOperation(execution, message); - } - - final NsLcmOpOcc nsLcmOpOcc = optional.get(); - final OperationStateEnum operationStateCompleted = OperationStateEnum.COMPLETED; - logger.info("Setting operation state to {} for id: {}", operationStateCompleted, occId); - nsLcmOpOcc.setOperationState(operationStateCompleted); - databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); + updateNsLcmOpOccOperationState(execution, OperationStateEnum.COMPLETED); logger.info("Finished executing updateNsLcmOpOccStatusToCompleted ..."); @@ -131,20 +117,8 @@ public abstract class AbstractNetworkServiceTask { public void updateNsLcmOpOccStatusToFailed(final DelegateExecution execution) { logger.info("Executing updateNsLcmOpOccStatusToFailed ..."); - final String occId = (String) execution.getVariable(OCC_ID_PARAM_NAME); - - final Optional<NsLcmOpOcc> optional = databaseServiceProvider.getNsLcmOpOcc(occId); - if (optional.isPresent()) { - final NsLcmOpOcc nsLcmOpOcc = optional.get(); - final OperationStateEnum operationStateFailed = OperationStateEnum.FAILED; - logger.info("Setting operation state to {} for id: {}", operationStateFailed, occId); - nsLcmOpOcc.setOperationState(operationStateFailed); - - databaseServiceProvider.addNSLcmOpOcc(nsLcmOpOcc); - } else { - logger.error("Unable to find record for NSLcmOpOcc in database using id: {}", occId); - } + updateNsLcmOpOccOperationState(execution, OperationStateEnum.FAILED); logger.info("Finished executing updateNsLcmOpOccStatusToFailed ..."); @@ -154,6 +128,19 @@ public abstract class AbstractNetworkServiceTask { abortOperation(execution, message, new InlineResponse400().detail(message)); } + private void updateNsLcmOpOccOperationState(final DelegateExecution execution, + final OperationStateEnum operationState) { + final String occId = (String) execution.getVariable(OCC_ID_PARAM_NAME); + + final boolean isSuccessful = databaseServiceProvider.updateNsLcmOpOccOperationState(occId, operationState); + if (!isSuccessful) { + final String message = + "Unable to update NsLcmOpOcc " + occId + " operationState to" + operationState + " in database"; + logger.error(message); + abortOperation(execution, message); + } + } + protected void abortOperation(final DelegateExecution execution, final String message, final InlineResponse400 problemDetails) { logger.error(message); @@ -175,10 +162,10 @@ public abstract class AbstractNetworkServiceTask { } protected void updateNsInstanceStatus(final DelegateExecution execution, final State nsStatus) { - final NfvoNsInst nfvoNsInst = getNfvoNsInst(execution); + final String nsInstId = (String) execution.getVariable(NS_INSTANCE_ID_PARAM_NAME); + logger.info("Updating NfvoNsInst Status to {} and saving to DB", nsStatus); - nfvoNsInst.setStatus(nsStatus); - databaseServiceProvider.saveNfvoNsInst(nfvoNsInst); + databaseServiceProvider.updateNsInstState(nsInstId, nsStatus); } protected NfvoNsInst getNfvoNsInst(final DelegateExecution execution) { diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java index 600792acc0..0d4cbbe24f 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/CreateInstantiateVnfTask.java @@ -195,7 +195,7 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { } public void updateNfInstanceStatusToFailed(final DelegateExecution execution) { - logger.info("Executing updateNfInstanceStatusToActive"); + logger.info("Executing updateNfInstanceStatusToFailed"); updateNfInstanceStatus(execution, State.FAILED); final CreateInstantiateRequest request = @@ -203,22 +203,19 @@ public class CreateInstantiateVnfTask extends AbstractNetworkServiceTask { addJobStatus(execution, ERROR, "Failed to create and instantiate VNF: " + request.getVnfName() + " will set status to " + State.FAILED); - logger.info("Finished executing updateNfInstanceStatusToInstantiated ..."); + logger.info("Finished executing updateNfInstanceStatusToFailed ..."); } private void updateNfInstanceStatus(final DelegateExecution execution, final State vnfStatus) { final String nfInstId = (String) execution.getVariable(NF_INST_ID_PARAM_NAME); - final Optional<NfvoNfInst> optional = databaseServiceProvider.getNfvoNfInst(nfInstId); - if (optional.isEmpty()) { - final String message = "Unable to find NfvoNfInst record in database using nfInstId: " + nfInstId; + final boolean isSuccessful = databaseServiceProvider.updateNfInstState(nfInstId, vnfStatus); + if (!isSuccessful) { + final String message = + "Unable to update NfvoNfInst " + nfInstId + " status to" + vnfStatus + " in database"; logger.error(message); abortOperation(execution, message); } - - final NfvoNfInst nfvoNfInst = optional.get(); - nfvoNfInst.setStatus(vnfStatus); - databaseServiceProvider.saveNfvoNfInst(nfvoNfInst); } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateVnfTask.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateVnfTask.java index 049a6f38b0..f3e7eea212 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateVnfTask.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-bpmn-flows/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/bpmn/flows/tasks/TerminateVnfTask.java @@ -31,7 +31,6 @@ import org.onap.so.adapters.etsisol003adapter.lcm.v1.model.DeleteVnfResponse; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai.AaiServiceProvider; import org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.vnfm.Sol003AdapterServiceProvider; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.JobStatusEnum; -import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; import org.onap.so.etsi.nfvo.ns.lcm.database.service.DatabaseServiceProvider; import org.slf4j.Logger; @@ -170,16 +169,12 @@ public class TerminateVnfTask extends AbstractNetworkServiceTask { private void updateNfInstanceStatus(final DelegateExecution execution, final State vnfStatus) { final String vnfId = (String) execution.getVariable(TERMINATE_VNF_VNFID_PARAM_NAME); - final Optional<NfvoNfInst> optional = databaseServiceProvider.getNfvoNfInst(vnfId); - if (optional.isEmpty()) { - final String message = "Unable to find NfvoNfInst record in database using vnfId: " + vnfId; + final boolean isSuccessful = databaseServiceProvider.updateNfInstState(vnfId, vnfStatus); + if (!isSuccessful) { + final String message = "Unable to update NfvoNfInst " + vnfId + " status to" + vnfStatus + " in database"; logger.error(message); abortOperation(execution, message); } - - final NfvoNfInst nfvoNfInst = optional.get(); - nfvoNfInst.setStatus(vnfStatus); - databaseServiceProvider.saveNfvoNfInst(nfvoNfInst); } } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NSLcmOpOccRepository.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NSLcmOpOccRepository.java index 696c7be5dd..d52dcd6192 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NSLcmOpOccRepository.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NSLcmOpOccRepository.java @@ -19,9 +19,13 @@ */ package org.onap.so.etsi.nfvo.ns.lcm.database.repository; +import java.util.Optional; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; -import java.util.Optional; +import org.springframework.data.repository.query.Param; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -30,4 +34,9 @@ import java.util.Optional; public interface NSLcmOpOccRepository extends CrudRepository<NsLcmOpOcc, String> { Optional<NsLcmOpOcc> findById(final String id); + + @Modifying(clearAutomatically = true) + @Query("UPDATE NsLcmOpOcc SET operationState = (:operationState) WHERE id = (:id)") + int updateNsLcmOpOccOperationState(@Param("id") final String id, + @Param("operationState") final OperationStateEnum operationState); } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNfInstRepository.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNfInstRepository.java index de14d43de4..5560ea7af3 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNfInstRepository.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNfInstRepository.java @@ -22,7 +22,11 @@ package org.onap.so.etsi.nfvo.ns.lcm.database.repository; import java.util.List; import java.util.Optional; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -35,4 +39,12 @@ public interface NfvoNfInstRepository extends CrudRepository<NfvoNfInst, String> List<NfvoNfInst> findByNsInstNsInstId(final String nsInstId); List<NfvoNfInst> findByNsInstNsInstIdAndName(final String nsInstId, final String name); + + @Modifying(clearAutomatically = true) + @Query("UPDATE NfvoNfInst SET status = (:state) WHERE nfInstId = (:nfInstId)") + int updateNfInstState(@Param("nfInstId") final String nfInstId, @Param("state") final State state); + + @Modifying(clearAutomatically = true) + @Query("DELETE FROM NfvoNfInst WHERE nfInstId = (:nfInstId)") + void deleteNfvoNfInstUsingNfInstId(@Param("nfInstId") final String nfInstId); } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java index beeeacf8cf..2a6abda558 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/repository/NfvoNsInstRepository.java @@ -21,7 +21,11 @@ package org.onap.so.etsi.nfvo.ns.lcm.database.repository; import java.util.Optional; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; +import org.springframework.data.jpa.repository.Modifying; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.query.Param; /** * @author Waqas Ikram (waqas.ikram@est.tech) @@ -35,5 +39,8 @@ public interface NfvoNsInstRepository extends CrudRepository<NfvoNsInst, String> boolean existsNfvoNsInstByName(final String name); + @Modifying(clearAutomatically = true) + @Query("UPDATE NfvoNsInst SET status = (:state) WHERE nsInstId = (:nsInstId)") + int updateNsInstState(@Param("nsInstId") final String nsInstId, @Param("state") final State state); } diff --git a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java index 1487b630c7..58ca76eec9 100644 --- a/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java +++ b/so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/main/java/org/onap/so/etsi/nfvo/ns/lcm/database/service/DatabaseServiceProvider.java @@ -25,6 +25,8 @@ import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoJob; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNfInst; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NfvoNsInst; import org.onap.so.etsi.nfvo.ns.lcm.database.beans.NsLcmOpOcc; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.OperationStateEnum; +import org.onap.so.etsi.nfvo.ns.lcm.database.beans.State; import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NSLcmOpOccRepository; import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoJobRepository; import org.onap.so.etsi.nfvo.ns.lcm.database.repository.NfvoNfInstRepository; @@ -105,6 +107,12 @@ public class DatabaseServiceProvider { return nfvoNsInstRepository.save(nfvoNsInst) != null; } + @Transactional(propagation = Propagation.REQUIRES_NEW) + public boolean updateNsInstState(final String nsInstId, final State state) { + logger.info("Updating NfvoNsInst: {} State to {}", nsInstId, state); + return nfvoNsInstRepository.updateNsInstState(nsInstId, state) > 0; + } + public Optional<NfvoNsInst> getNfvoNsInst(final String nsInstId) { logger.info("Querying database for NfvoNsInst using nsInstId: {}", nsInstId); return nfvoNsInstRepository.findById(nsInstId); @@ -120,6 +128,12 @@ public class DatabaseServiceProvider { return nfvoNfInstRepository.save(nfvoNfInst) != null; } + @Transactional(propagation = Propagation.REQUIRES_NEW) + public boolean updateNfInstState(final String nfInstId, final State state) { + logger.info("Updating NfvoNfInst: {} State to {}", nfInstId, state); + return nfvoNfInstRepository.updateNfInstState(nfInstId, state) > 0; + } + public List<NfvoNfInst> getNfvoNfInstByNsInstId(final String nsInstId) { logger.info("Querying database for NfvoNfInst using nsInstId: {}", nsInstId); return nfvoNfInstRepository.findByNsInstNsInstId(nsInstId); @@ -140,9 +154,10 @@ public class DatabaseServiceProvider { return nfvoNfInstRepository.findByNfInstId(nfInstId).isPresent(); } + @Transactional(propagation = Propagation.REQUIRES_NEW) public void deleteNfvoNfInst(final String nfInstId) { logger.info("Deleting NfvoNfInst with nfInstId: {} from database", nfInstId); - nfvoNfInstRepository.deleteById(nfInstId); + nfvoNfInstRepository.deleteNfvoNfInstUsingNfInstId(nfInstId); } public boolean addNSLcmOpOcc(final NsLcmOpOcc nsLcmOpOcc) { @@ -150,6 +165,12 @@ public class DatabaseServiceProvider { return nsLcmOpOccRepository.save(nsLcmOpOcc) != null; } + @Transactional(propagation = Propagation.REQUIRES_NEW) + public boolean updateNsLcmOpOccOperationState(final String id, final OperationStateEnum operationState) { + logger.info("Updating NsLcmOpOcc: {} operationState to {}", id, operationState); + return nsLcmOpOccRepository.updateNsLcmOpOccOperationState(id, operationState) > 0; + } + public Optional<NsLcmOpOcc> getNsLcmOpOcc(final String id) { logger.info("Querying database for NsLcmOpOcc using id: {}", id); return nsLcmOpOccRepository.findById(id); |