1 package org.onap.vid.job.command
3 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate
4 import org.onap.vid.aai.ExceptionWithRequestInfo
5 import org.onap.vid.changeManagement.RequestDetailsWrapper
6 import org.onap.vid.exceptions.AbortingException
7 import org.onap.vid.exceptions.MaxRetriesException
8 import org.onap.vid.exceptions.TryAgainException
9 import org.onap.vid.job.Job
10 import org.onap.vid.job.JobAdapter
11 import org.onap.vid.job.JobCommand
12 import org.onap.vid.job.JobsBrokerService
13 import org.onap.vid.model.Action
14 import org.onap.vid.model.VidNotions.ModelCategory.*
15 import org.onap.vid.model.serviceInstantiation.ServiceInstantiation
16 import org.onap.vid.mso.RestMsoImplementation
17 import org.onap.vid.services.AsyncInstantiationBusinessLogic
18 import org.onap.vid.services.AuditService
19 import org.springframework.beans.factory.annotation.Autowired
20 import org.springframework.beans.factory.config.ConfigurableBeanFactory
21 import org.springframework.context.annotation.Scope
22 import org.springframework.http.HttpMethod
23 import org.springframework.stereotype.Component
27 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
28 class MacroServiceCommand @Autowired constructor(
29 inProgressStatusService: InProgressStatusService,
30 watchChildrenJobsBL: WatchChildrenJobsBL,
31 private val asyncInstantiationBL: AsyncInstantiationBusinessLogic,
32 jobsBrokerService: JobsBrokerService,
33 private val msoRequestBuilder: MsoRequestBuilder,
34 msoResultHandlerService: MsoResultHandlerService,
35 jobAdapter: JobAdapter,
36 restMso: RestMsoImplementation,
37 auditService: AuditService
38 ) : RootServiceCommand(restMso, inProgressStatusService, msoResultHandlerService,
39 watchChildrenJobsBL, jobsBrokerService, jobAdapter, asyncInstantiationBL, auditService, msoRequestBuilder), JobCommand {
43 private val Logger = EELFLoggerDelegate.getLogger(MacroServiceCommand::class.java)
46 override fun createChildren(): Job.JobStatus {
47 return Job.JobStatus.COMPLETED_WITH_NO_ACTION
50 private val pre1806Models = setOf(Transport, INFRASTRUCTURE_VPN, SERVICE_WITH_COLLECTION_RESOURCE);
52 override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
54 val instantiatePath = asyncInstantiationBL.getServiceInstantiationPath(request as ServiceInstantiation)
56 val requestDetailsWrapper = generateRequest(sharedData.jobUuid, request, optimisticUniqueServiceInstanceName, userId)
58 val actionDescription = "create macro service instance"
60 return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
63 //Aai return bad response while checking names uniqueness
64 catch (exception : ExceptionWithRequestInfo) {
65 Logger.error(EELFLoggerDelegate.errorLogger, "Failed to check name uniqueness in AAI. VID will try again later", exception)
66 throw TryAgainException(exception);
69 //Vid reached to max retries while trying to find unique name in AAI
70 catch (exception : MaxRetriesException) {
71 Logger.error(EELFLoggerDelegate.errorLogger, "Failed to find unused name in AAI", exception)
72 throw AbortingException(exception);
76 private fun generateRequest(jobUuid: UUID?, request: ServiceInstantiation, optimisticUniqueServiceInstanceName: String, userId: String): RequestDetailsWrapper<out Any> {
77 // for transport or for infrastructure VPN - send the pre 1806 request
78 if (shouldUsePre1806Request(request)){
79 return msoRequestBuilder.generateMacroServicePre1806InstantiationRequest(request, userId)
81 return msoRequestBuilder.generateMacroServiceInstantiationRequest(jobUuid, request, optimisticUniqueServiceInstanceName, userId)
84 protected fun shouldUsePre1806Request(request: ServiceInstantiation): Boolean {
85 return (request.vidNotions != null && pre1806Models.contains(request.vidNotions.modelCategory))
89 override fun handleInProgressStatus(jobStatus: Job.JobStatus): Job.JobStatus {
90 asyncInstantiationBL.updateServiceInfoAndAuditStatus(sharedData.jobUuid, jobStatus)
91 return if (jobStatus==Job.JobStatus.PAUSE) Job.JobStatus.IN_PROGRESS else jobStatus
94 override fun isDescendantHasAction(phase: Action): Boolean {