summaryrefslogtreecommitdiffstats
path: root/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
diff options
context:
space:
mode:
authorDenes Nemeth <denes.nemeth@nokia.com>2018-03-07 12:54:19 +0100
committerDenes Nemeth <denes.nemeth@nokia.com>2018-03-07 21:56:38 +0100
commit817338bc7da3127ff01e6736d284a081461f484b (patch)
tree071d310a8b2a50ab81e3ea07a33dfc2b760cb04a /nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
parent45f12914d2ba01cd0b7df7069e2879d4d7d275c6 (diff)
Fix sonar issues
Change-Id: If699a0d8ba39238ff8e559567c8c5d44fb1e1d7c Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com> Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java')
-rw-r--r--nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java70
1 files changed, 40 insertions, 30 deletions
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
index 5a21225b..2aba46b3 100644
--- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
+++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/vnfm/JobManager.java
@@ -26,7 +26,6 @@ import com.nokia.cbam.lcm.v32.model.OperationExecution;
import com.nokia.cbam.lcm.v32.model.VnfInfo;
import org.apache.http.HttpStatus;
import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.onap.core.SelfRegistrationManager;
-import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.LifecycleChangeNotificationManager;
import org.onap.vnfmdriver.model.JobDetailInfo;
import org.onap.vnfmdriver.model.JobDetailInfoResponseDescriptor;
import org.onap.vnfmdriver.model.JobResponseInfo;
@@ -39,14 +38,16 @@ import javax.servlet.http.HttpServletResponse;
import java.util.*;
import static com.google.common.base.Splitter.on;
+import static com.google.common.collect.Iterables.find;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.newArrayList;
import static java.util.Optional.empty;
import static java.util.Optional.of;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.SEPARATOR;
-import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.fatalFailure;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions;
import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.CbamRestApiProvider.NOKIA_LCM_API_VERSION;
+import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.notification.LifecycleChangeNotificationManager.NEWEST_OPERATIONS_FIRST;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.util.StringUtils.isEmpty;
@@ -107,11 +108,11 @@ public class JobManager {
synchronized (this) {
if (preparingForShutDown) {
response.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
- fatalFailure(logger, "The service is preparing to shut down");
+ throw buildFatalFailure(logger, "The service is preparing to shut down");
}
if (!selfRegistrationManager.isReady()) {
response.setStatus(HttpStatus.SC_SERVICE_UNAVAILABLE);
- fatalFailure(logger, "The service is not yet ready");
+ throw buildFatalFailure(logger, "The service is not yet ready");
}
}
ongoingJobs.add(jobId);
@@ -190,6 +191,7 @@ public class JobManager {
OperationExecution operation = findOperationByJobId(vnfmId, vnf, jobId);
return getJobDetailInfo(vnfmId, jobId, vnfId, operation);
} catch (NoSuchElementException e) {
+ logger.warn("No operation could be identified for job with {} identifier", jobId, e);
if (ongoingJobs.contains(jobId)) {
return reportOngoing(jobId);
} else {
@@ -204,27 +206,31 @@ public class JobManager {
return reportOngoing(jobId);
case FINISHED:
case OTHER:
- //termination includes VNF deletion in ONAP terminology
- if (operation.getOperationType() == com.nokia.cbam.lcm.v32.model.OperationType.TERMINATE) {
- if (ongoingJobs.contains(jobId)) {
- return reportOngoing(jobId);
- } else {
- //the VNF must be queried again since it could have been deleted since the VNF has been terminated
- if (getVnf(vnfmId, vnfId).isPresent()) {
- return reportFailed(jobId, "unable to delete VNF");
- } else {
- return reportFinished(jobId);
- }
- }
- } else {
- return reportFinished(jobId);
- }
+ return getJobForTerminalOperationState(vnfmId, jobId, vnfId, operation);
case FAILED:
default: //all cases handled
return reportFailed(jobId, operation.getError().getTitle() + ": " + operation.getError().getDetail());
}
}
+ private JobDetailInfo getJobForTerminalOperationState(String vnfmId, String jobId, String vnfId, OperationExecution operation) {
+ //termination includes VNF deletion in ONAP terminology
+ if (operation.getOperationType() == com.nokia.cbam.lcm.v32.model.OperationType.TERMINATE) {
+ if (ongoingJobs.contains(jobId)) {
+ return reportOngoing(jobId);
+ } else {
+ //the VNF must be queried again since it could have been deleted since the VNF has been terminated
+ if (getVnf(vnfmId, vnfId).isPresent()) {
+ return reportFailed(jobId, "unable to delete VNF");
+ } else {
+ return reportFinished(jobId);
+ }
+ }
+ } else {
+ return reportFinished(jobId);
+ }
+ }
+
private JobDetailInfo buildJob(String jobId, JobResponseInfo... history) {
JobDetailInfo job = new JobDetailInfo();
job.setJobId(jobId);
@@ -273,20 +279,24 @@ public class JobManager {
//the operations are sorted so that the newest operations are queried first
//performance optimization that usually the core system is interested in the operations executed last
if (vnf.getOperationExecutions() != null) {
- for (OperationExecution operationExecution : LifecycleChangeNotificationManager.NEWEST_OPERATIONS_FIRST.sortedCopy(vnf.getOperationExecutions())) {
- try {
- Object operationParams = cbamOperationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operationExecution.getId(), NOKIA_LCM_API_VERSION);
- if (extractOnapJobId(operationParams).equals(jobId)) {
- return operationExecution;
- }
- } catch (ApiException e) {
- fatalFailure(logger, "Unable to retrieve operation parameters", e);
- }
- }
+ List<OperationExecution> sortedOperation = NEWEST_OPERATIONS_FIRST.sortedCopy(vnf.getOperationExecutions());
+ return find(sortedOperation, operation -> isCurrentOperationTriggeredByJob(jobId, cbamOperationExecutionApi, operation));
}
throw new NoSuchElementException();
}
+ private boolean isCurrentOperationTriggeredByJob(String jobId, OperationExecutionsApi cbamOperationExecutionApi, OperationExecution operationExecution) {
+ try {
+ Object operationParams = cbamOperationExecutionApi.operationExecutionsOperationExecutionIdOperationParamsGet(operationExecution.getId(), NOKIA_LCM_API_VERSION);
+ if (extractOnapJobId(operationParams).equals(jobId)) {
+ return true;
+ }
+ } catch (ApiException e) {
+ throw buildFatalFailure(logger, "Unable to retrieve operation parameters", e);
+ }
+ return false;
+ }
+
private Optional<VnfInfo> getVnf(String vnfmId, String vnfId) {
try {
//test if the VNF exists (required to be able to distingush between failed request )
@@ -303,7 +313,7 @@ public class JobManager {
return of(cbamLcmApi.vnfsVnfInstanceIdGet(vnfId, NOKIA_LCM_API_VERSION));
}
} catch (ApiException e) {
- throw fatalFailure(logger, "Unable to retrieve VNF", e);
+ throw buildFatalFailure(logger, "Unable to retrieve VNF", e);
}
}
}