2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.vid.job.command
23 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate
24 import org.onap.vid.job.Job
25 import org.onap.vid.job.impl.JobSharedData
26 import org.onap.vid.model.RequestReferencesContainer
27 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation
28 import org.onap.vid.mso.RestObject
29 import org.onap.vid.services.AsyncInstantiationBusinessLogic
30 import org.onap.vid.services.AuditService
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.stereotype.Service
36 class MsoResultHandlerService
37 @Autowired constructor(private val asyncInstantiationBL: AsyncInstantiationBusinessLogic, private val auditService: AuditService) {
40 private val LOGGER = EELFLoggerDelegate.getLogger(MsoResultHandlerService::class.java)
43 fun getRequest(jobSharedData: JobSharedData): ServiceInstantiation {
44 return jobSharedData.request as ServiceInstantiation
47 fun handleRootResponse(sharedData: JobSharedData, msoResponse: RestObject<RequestReferencesContainer>): MsoResult {
48 val jobUUID:UUID = sharedData.jobUuid
49 return if (msoResponse.statusCode in 200..399) {
50 val jobStatus = Job.JobStatus.IN_PROGRESS
51 val msoResourceIds = MsoResourceIds(msoResponse.get().requestReferences.requestId, msoResponse.get().requestReferences.instanceId)
52 auditService.auditVidStatus(jobUUID, jobStatus)
53 setInitialRequestAuditStatusFromMso(jobUUID, msoResourceIds.requestId)
54 asyncInstantiationBL.updateServiceInfo(jobUUID) { x ->
55 x.jobStatus = jobStatus
56 x.serviceInstanceId = msoResourceIds.instanceId
57 x.msoRequestId = UUID.fromString(msoResourceIds.requestId)
59 asyncInstantiationBL.addResourceInfo(sharedData, jobStatus, msoResourceIds.instanceId)
60 MsoResult(Job.JobStatus.COMPLETED_WITH_NO_ACTION, msoResourceIds)
62 auditService.setFailedAuditStatusFromMso(jobUUID, null, msoResponse.statusCode, msoResponse.raw)
63 asyncInstantiationBL.addFailedResourceInfo(sharedData, msoResponse)
64 return MsoResult(Job.JobStatus.FAILED)
68 fun handleResponse(sharedData: JobSharedData, msoResponse: RestObject<RequestReferencesContainer>, actionDescription: String): MsoResult {
69 return if (msoResponse.statusCode in 200..399) {
70 val msoResourceIds = MsoResourceIds(msoResponse.get().requestReferences.requestId, msoResponse.get().requestReferences.instanceId)
71 LOGGER.debug(EELFLoggerDelegate.debugLogger, "Successfully sent $actionDescription. Request id: ${msoResourceIds.requestId}")
72 asyncInstantiationBL.addResourceInfo(sharedData, Job.JobStatus.IN_PROGRESS, msoResourceIds.instanceId)
73 MsoResult(Job.JobStatus.COMPLETED_WITH_NO_ACTION, msoResourceIds)
75 LOGGER.debug(EELFLoggerDelegate.debugLogger, "Failed to $actionDescription. Details: ${msoResponse.raw}")
76 asyncInstantiationBL.addFailedResourceInfo(sharedData, msoResponse)
77 MsoResult(Job.JobStatus.FAILED)
81 private fun setInitialRequestAuditStatusFromMso(jobUUID: UUID, requestId: String) {
82 val initialMsoRequestStatus = "REQUESTED"
83 auditService.auditMsoStatus(jobUUID, initialMsoRequestStatus, requestId, null)