Fix getJob status bug 64/113164/3
authorwaqas.ikram <waqas.ikram@est.tech>
Thu, 24 Sep 2020 11:47:22 +0000 (12:47 +0100)
committerwaqas.ikram <waqas.ikram@est.tech>
Fri, 25 Sep 2020 13:02:10 +0000 (14:02 +0100)
Change-Id: I1a3bab4de5c6cfaa5b7874bccff79fbf72f8dc03
Issue-ID: SO-3268
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
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/extclients/aai/AaiServiceProviderImpl.java
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/service/JobExecutorService.java
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/NfvoJobRepository.java
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/RefreshableRepository.java [new file with mode: 0644]
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/RefreshableRepositoryImpl.java [new file with mode: 0644]
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
so-etsi-nfvo/so-etsi-nfvo-ns-lcm/so-etsi-nfvo-ns-lcm-database-service/src/test/java/org/onap/so/etsi/nfvo/ns/lcm/database/DatabaseServiceProviderTest.java

index 78cdc79..0da53a0 100644 (file)
@@ -22,6 +22,7 @@ package org.onap.so.etsi.nfvo.ns.lcm.bpmn.flows.extclients.aai;
 import java.util.Optional;
 import org.onap.aai.domain.yang.GenericVnf;
 import org.onap.aai.domain.yang.ServiceInstance;
+import org.onap.aaiclient.client.aai.AAIObjectType;
 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
@@ -88,7 +89,8 @@ public class AaiServiceProviderImpl implements AaiServiceProvider {
     @Override
     public void deleteGenericVnf(final String vnfId) {
         logger.info("Deleting GenericVnf with id: {} from AAI.", vnfId);
-        final AAIResourceUri aaiResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.GENERIC_VNF, vnfId);
+        final AAIResourceUri aaiResourceUri =
+                AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(vnfId));
         aaiClientProvider.getAaiClient().delete(aaiResourceUri);
     }
 }
index f240fa3..31e3011 100644 (file)
@@ -289,7 +289,7 @@ public class JobExecutorService {
             JobStatusEnum currentJobStatus = null;
             while (timeOutTime > System.currentTimeMillis()) {
 
-                final Optional<NfvoJob> optional = databaseServiceProvider.getJob(jobId);
+                final Optional<NfvoJob> optional = databaseServiceProvider.getRefreshedJob(jobId);
 
                 if (optional.isEmpty()) {
                     logger.error("Unable to find Job using jobId: {}", jobId);
@@ -299,7 +299,7 @@ public class JobExecutorService {
                 final NfvoJob nfvoJob = optional.get();
                 currentJobStatus = nfvoJob.getStatus();
                 logger.debug("Received job status response: \n {}", nfvoJob);
-                if (jobFinishedStates.contains(nfvoJob.getStatus())) {
+                if (jobFinishedStates.contains(currentJobStatus)) {
                     logger.info("Job finished \n {}", currentJobStatus);
                     return ImmutablePair.of(nfvoJob.getProcessInstanceId(), currentJobStatus);
                 }
index 844f608..2d6d033 100644 (file)
@@ -27,7 +27,7 @@ import org.springframework.data.repository.CrudRepository;
  * @author Waqas Ikram (waqas.ikram@est.tech)
  *
  */
-public interface NfvoJobRepository extends CrudRepository<NfvoJob, String> {
+public interface NfvoJobRepository extends CrudRepository<NfvoJob, String>, RefreshableRepository<NfvoJob> {
 
     Optional<NfvoJob> findByResourceId(final String resourceId);
 
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/RefreshableRepository.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/RefreshableRepository.java
new file mode 100644 (file)
index 0000000..efa7130
--- /dev/null
@@ -0,0 +1,30 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2020 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.so.etsi.nfvo.ns.lcm.database.repository;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+public interface RefreshableRepository<T> {
+
+    void refreshEntity(T entity);
+
+}
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/RefreshableRepositoryImpl.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/RefreshableRepositoryImpl.java
new file mode 100644 (file)
index 0000000..abd095f
--- /dev/null
@@ -0,0 +1,42 @@
+/*-
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2020 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.so.etsi.nfvo.ns.lcm.database.repository;
+
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import org.springframework.stereotype.Repository;
+
+/**
+ * @author Waqas Ikram (waqas.ikram@est.tech)
+ *
+ */
+@Repository
+public class RefreshableRepositoryImpl<T> implements RefreshableRepository<T> {
+
+    @PersistenceContext
+    private EntityManager entityManager;
+
+    @Override
+    public void refreshEntity(final T entity) {
+        entityManager.refresh(entity);
+
+    }
+
+}
index 762408a..1aaddeb 100644 (file)
@@ -33,6 +33,9 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Isolation;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
 
 /**
  * @author Waqas Ikram (waqas.ikram@est.tech)
@@ -71,6 +74,16 @@ public class DatabaseServiceProvider {
         return nfvoJobRepository.findById(jobId);
     }
 
+    @Transactional(propagation = Propagation.REQUIRES_NEW, isolation = Isolation.REPEATABLE_READ, readOnly = true)
+    public Optional<NfvoJob> getRefreshedJob(final String jobId) {
+        logger.info("Querying database for NfvoJob using jobId: {}", jobId);
+        final Optional<NfvoJob> optional = getJob(jobId);
+        if (optional.isPresent()) {
+            nfvoJobRepository.refreshEntity(optional.get());
+        }
+        return optional;
+    }
+
     public Optional<NfvoJob> getJobByResourceId(final String resourceId) {
         logger.info("Querying database for NfvoJob using resourceId: {}", resourceId);
         return nfvoJobRepository.findByResourceId(resourceId);
index 42579fd..8108749 100644 (file)
@@ -65,8 +65,12 @@ public class DatabaseServiceProviderTest {
                 .resourceName(DUMMY_NAME).startTime(CURRENT_DATE_TIME).status(JobStatusEnum.STARTED);
         databaseServiceProvider.addJob(expected);
 
-        final Optional<NfvoJob> actual = databaseServiceProvider.getJob(expected.getJobId());
+        Optional<NfvoJob> actual = databaseServiceProvider.getJob(expected.getJobId());
         assertEquals(expected, actual.get());
+
+        actual = databaseServiceProvider.getRefreshedJob(expected.getJobId());
+        assertEquals(expected, actual.get());
+
     }
 
     @Test