1 package org.onap.vid.job.command;
3 import com.fasterxml.jackson.databind.ObjectMapper;
4 import com.google.common.collect.ImmutableMap;
5 import org.onap.vid.job.Job.JobStatus;
6 import org.onap.vid.job.JobCommand;
7 import org.onap.vid.job.NextCommand;
8 import org.onap.vid.mso.RestMsoImplementation;
9 import org.onap.vid.mso.RestObject;
10 import org.onap.vid.mso.rest.AsyncRequestStatus;
11 import org.onap.vid.services.AsyncInstantiationBusinessLogic;
12 import org.onap.vid.services.AuditService;
13 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
14 import org.springframework.beans.factory.config.ConfigurableBeanFactory;
15 import org.springframework.context.annotation.Scope;
16 import org.springframework.stereotype.Component;
18 import javax.inject.Inject;
20 import java.util.UUID;
24 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
25 public class InProgressStatusCommand implements JobCommand {
27 private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
29 private static final EELFLoggerDelegate LOGGER = EELFLoggerDelegate.getLogger(InProgressStatusCommand.class);
32 private AsyncInstantiationBusinessLogic asyncInstantiationBL;
35 private RestMsoImplementation restMso;
38 private AuditService auditService;
40 private String requestId;
44 public InProgressStatusCommand() {
47 InProgressStatusCommand(UUID jobUuid, String requestId) {
48 init(jobUuid, requestId);
52 public NextCommand call() {
55 String path = asyncInstantiationBL.getOrchestrationRequestsPath()+"/"+requestId;
56 RestObject<AsyncRequestStatus> msoResponse = restMso.GetForObject("", path, AsyncRequestStatus.class);
58 if (msoResponse.getStatusCode() >= 400 || msoResponse.get() == null) {
59 auditService.setFailedAuditStatusFromMso(jobUuid, requestId, msoResponse.getStatusCode(), msoResponse.getRaw());
60 LOGGER.error(EELFLoggerDelegate.errorLogger,
61 "Failed to get orchestration status for {}. Status code: {}, Body: {}",
62 requestId, msoResponse.getStatusCode(), msoResponse.getRaw());
63 return new NextCommand(JobStatus.IN_PROGRESS, this);
66 jobStatus = asyncInstantiationBL.calcStatus(msoResponse.get());
69 asyncInstantiationBL.auditMsoStatus(jobUuid,msoResponse.get().request);
72 if (jobStatus == JobStatus.FAILED) {
73 asyncInstantiationBL.handleFailedInstantiation(jobUuid);
76 asyncInstantiationBL.updateServiceInfoAndAuditStatus(jobUuid, jobStatus);
78 //in case of JobStatus.PAUSE we leave the job itself as IN_PROGRESS, for keep tracking job progress
79 if (jobStatus == JobStatus.PAUSE) {
80 return new NextCommand(JobStatus.IN_PROGRESS, this);
82 return new NextCommand(jobStatus, this);
83 } catch (javax.ws.rs.ProcessingException e) {
84 // Retry when we can't connect MSO during getStatus
85 LOGGER.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, will retry: {}", requestId, e, e);
86 return new NextCommand(JobStatus.IN_PROGRESS, this);
87 } catch (RuntimeException e) {
88 LOGGER.error(EELFLoggerDelegate.errorLogger, "Cannot get orchestration status for {}, stopping: {}", requestId, e, e);
89 return new NextCommand(JobStatus.STOPPED, this);
94 public InProgressStatusCommand init(UUID jobUuid, Map<String, Object> data) {
95 return init(jobUuid, (String) data.get("requestId"));
98 private InProgressStatusCommand init(UUID jobUuid, String requestId) {
99 this.requestId = requestId;
100 this.jobUuid = jobUuid;
105 public Map<String, Object> getData() {
106 return ImmutableMap.of("requestId", requestId);