diff options
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid')
3 files changed, 36 insertions, 24 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java index cee5af69..6685a63d 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/InProgressStatusCommand.java @@ -23,6 +23,7 @@ package org.onap.vid.job.command; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import io.joshworks.restclient.http.HttpResponse; +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.onap.vid.job.Job.JobStatus; import org.onap.vid.job.JobCommand; import org.onap.vid.job.NextCommand; @@ -30,13 +31,13 @@ import org.onap.vid.mso.MsoInterface; import org.onap.vid.mso.rest.AsyncRequestStatus; import org.onap.vid.services.AsyncInstantiationBusinessLogic; import org.onap.vid.services.AuditService; -import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate; import org.springframework.beans.factory.config.ConfigurableBeanFactory; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Component; import javax.inject.Inject; import java.util.Map; +import java.util.Objects; import java.util.UUID; @@ -68,33 +69,38 @@ public class InProgressStatusCommand implements JobCommand { init(jobUuid, requestId); } + InProgressStatusCommand(AsyncInstantiationBusinessLogic asyncInstantiationBusinessLogic, MsoInterface msoInterface, AuditService auditService, UUID jobUuid, String requestId) { + this(jobUuid, requestId); + this.asyncInstantiationBL = asyncInstantiationBusinessLogic; + this.restMso = msoInterface; + this.auditService = auditService; + } + @Override public NextCommand call() { try { - String path = asyncInstantiationBL.getOrchestrationRequestsPath()+"/"+requestId; + String path = asyncInstantiationBL.getOrchestrationRequestsPath() + "/" + requestId; HttpResponse<AsyncRequestStatus> msoResponse = restMso.get(path, AsyncRequestStatus.class); JobStatus jobStatus; if (msoResponse.getStatus() >= 400 || msoResponse.getBody() == null) { - auditService.setFailedAuditStatusFromMso(jobUuid, requestId, msoResponse.getStatus(), msoResponse.getBody().toString()); + auditService.setFailedAuditStatusFromMso(jobUuid, requestId, msoResponse.getStatus(), Objects.toString(msoResponse.getBody())); LOGGER.error(EELFLoggerDelegate.errorLogger, "Failed to get orchestration status for {}. Status code: {}, Body: {}", - requestId, msoResponse.getStatus(), msoResponse.getRawBody().toString()); + requestId, msoResponse.getStatus(), Objects.toString(msoResponse.getRawBody())); return new NextCommand(JobStatus.IN_PROGRESS, this); - } - else { + } else { jobStatus = asyncInstantiationBL.calcStatus(msoResponse.getBody()); } - asyncInstantiationBL.auditMsoStatus(jobUuid,msoResponse.getBody().request); + asyncInstantiationBL.auditMsoStatus(jobUuid, msoResponse.getBody().request); if (jobStatus == JobStatus.FAILED) { asyncInstantiationBL.handleFailedInstantiation(jobUuid); - } - else { + } else { asyncInstantiationBL.updateServiceInfoAndAuditStatus(jobUuid, jobStatus); } //in case of JobStatus.PAUSE we leave the job itself as IN_PROGRESS, for keep tracking job progress @@ -128,5 +134,4 @@ public class InProgressStatusCommand implements JobCommand { return ImmutableMap.of("requestId", requestId); } - } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java index 9d22b8bf..958fc115 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ServiceInstantiationCommand.java @@ -42,6 +42,7 @@ import org.springframework.stereotype.Component; import javax.inject.Inject; import java.util.Map; +import java.util.Objects; import java.util.UUID; @@ -73,6 +74,14 @@ public class ServiceInstantiationCommand implements JobCommand { init(uuid, serviceInstantiationRequest, userId); } + ServiceInstantiationCommand(AsyncInstantiationBusinessLogic asyncInstantiationBL, AuditService auditService, MsoInterface msoInterface, + UUID uuid, ServiceInstantiation serviceInstantiation, String userId) { + this(uuid, serviceInstantiation, userId); + this.asyncInstantiationBL = asyncInstantiationBL; + this.auditService = auditService; + this.restMso = msoInterface; + } + @Override public NextCommand call() { RequestDetailsWrapper<ServiceInstantiationRequestDetails> requestDetailsWrapper ; @@ -81,7 +90,6 @@ public class ServiceInstantiationCommand implements JobCommand { uuid, serviceInstantiationRequest, userId ); } - //Aai return bad response while checking names uniqueness catch (InvalidAAIResponseException exception) { LOGGER.error("Failed to check name uniqueness in AAI. VID will try again later", exception); @@ -116,7 +124,7 @@ public class ServiceInstantiationCommand implements JobCommand { return new NextCommand(jobStatus, new InProgressStatusCommand(uuid, requestId)); } else { auditService.setFailedAuditStatusFromMso(uuid,null, msoResponse.getStatus(), - msoResponse.getBody().toString()); + Objects.toString(msoResponse.getBody())); return handleCommandFailed(); } diff --git a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java index 77e1dd2c..59f12f4c 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/impl/JobAdapterImpl.java @@ -33,14 +33,10 @@ public class JobAdapterImpl implements JobAdapter { } @Override - public Job createJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, Integer indexInBulk){ - JobDaoImpl job = new JobDaoImpl(); - job.setStatus(Job.JobStatus.PENDING); - job.setTypeAndData(jobType, ImmutableMap.of( + public Job createJob(JobType jobType, AsyncJobRequest request, UUID templateId, String userId, Integer indexInBulk) { + JobDaoImpl job = createJob(jobType, templateId, indexInBulk, ImmutableMap.of( "request", request, "userId", userId)); - job.setTemplateId(templateId); - job.setIndexInBulk(indexInBulk); job.setUserId(userId); return job; } @@ -59,14 +55,17 @@ public class JobAdapterImpl implements JobAdapter { List<Job> jobList = new ArrayList<>(count + 1); UUID templateId = UUID.randomUUID(); for (int i = 0; i < count; i++) { - Job child = new JobDaoImpl(); - child.setTypeAndData(jobType, bulkRequest); - child.setStatus(Job.JobStatus.PENDING); - child.setTemplateId(templateId); - child.setIndexInBulk(i); - jobList.add(child); + jobList.add(createJob(jobType, templateId, i, bulkRequest)); } return jobList; } + private JobDaoImpl createJob(JobType jobType, UUID templateId, Integer indexInBulk, Map<String, Object> data) { + JobDaoImpl job = new JobDaoImpl(); + job.setStatus(Job.JobStatus.PENDING); + job.setTypeAndData(jobType, data); + job.setTemplateId(templateId); + job.setIndexInBulk(indexInBulk); + return job; + } } |