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(jobUUID: UUID, msoResponse: RestObject<RequestReferencesContainer>): MsoResult {
48 return if (msoResponse.statusCode in 200..399) {
49 val jobStatus = Job.JobStatus.IN_PROGRESS
50 val msoResourceIds = MsoResourceIds(msoResponse.get().requestReferences.requestId, msoResponse.get().requestReferences.instanceId)
51 asyncInstantiationBL.auditVidStatus(jobUUID, jobStatus)
52 setInitialRequestAuditStatusFromMso(jobUUID, msoResourceIds.requestId)
53 asyncInstantiationBL.updateServiceInfo(jobUUID) { x ->
54 x.jobStatus = jobStatus
55 x.serviceInstanceId = msoResourceIds.instanceId
56 x.msoRequestId = UUID.fromString(msoResourceIds.requestId)
58 MsoResult(jobStatus, msoResourceIds)
60 auditService.setFailedAuditStatusFromMso(jobUUID, null, msoResponse.statusCode, msoResponse.raw)
61 handleRootCommandFailed(jobUUID)
65 fun handleResponse(msoResponse: RestObject<RequestReferencesContainer>, actionDescription: String): MsoResult {
66 return if (msoResponse.statusCode in 200..399) {
67 val msoResourceIds = MsoResourceIds(msoResponse.get().requestReferences.requestId, msoResponse.get().requestReferences.instanceId)
68 LOGGER.debug("Successfully sent $actionDescription. Request id: ${msoResourceIds.requestId}")
69 MsoResult(Job.JobStatus.COMPLETED_WITH_NO_ACTION, msoResourceIds)
71 LOGGER.debug("Failed to $actionDescription. Details: ${msoResponse.raw}")
72 MsoResult(Job.JobStatus.FAILED)
77 fun handleRootCommandFailed(jobUUID: UUID): MsoResult {
78 asyncInstantiationBL.handleFailedInstantiation(jobUUID)
79 return MsoResult(Job.JobStatus.FAILED)
82 private fun setInitialRequestAuditStatusFromMso(jobUUID: UUID, requestId: String) {
83 val initialMsoRequestStatus = "REQUESTED"
84 asyncInstantiationBL.auditMsoStatus(jobUUID, initialMsoRequestStatus, requestId, null)