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
24 import org.togglz.core.manager.FeatureManager
28 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
29 class MacroServiceCommand @Autowired constructor(
30 inProgressStatusService: InProgressStatusService,
31 watchChildrenJobsBL: WatchChildrenJobsBL,
32 private val asyncInstantiationBL: AsyncInstantiationBusinessLogic,
33 jobsBrokerService: JobsBrokerService,
34 private val msoRequestBuilder: MsoRequestBuilder,
35 msoResultHandlerService: MsoResultHandlerService,
36 jobAdapter: JobAdapter,
37 restMso: RestMsoImplementation,
38 auditService: AuditService,
39 featureManager: FeatureManager
40 ) : RootServiceCommand(restMso, inProgressStatusService, msoResultHandlerService,
41 watchChildrenJobsBL, jobsBrokerService, jobAdapter, asyncInstantiationBL, auditService, msoRequestBuilder, featureManager), JobCommand {
45 private val Logger = EELFLoggerDelegate.getLogger(MacroServiceCommand::class.java)
48 override fun createChildren(): Job.JobStatus {
49 return Job.JobStatus.COMPLETED_WITH_NO_ACTION
52 private val pre1806Models = setOf(Transport, INFRASTRUCTURE_VPN, SERVICE_WITH_COLLECTION_RESOURCE);
54 override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
56 val instantiatePath = asyncInstantiationBL.getServiceInstantiationPath(request as ServiceInstantiation)
58 val requestDetailsWrapper = generateRequest(sharedData.jobUuid, request, optimisticUniqueServiceInstanceName, userId)
60 val actionDescription = "create macro service instance"
62 return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
65 //Aai return bad response while checking names uniqueness
66 catch (exception : ExceptionWithRequestInfo) {
67 Logger.error("Failed to check name uniqueness in AAI. VID will try again later", exception)
68 throw TryAgainException(exception);
71 //Vid reached to max retries while trying to find unique name in AAI
72 catch (exception : MaxRetriesException) {
73 Logger.error("Failed to find unused name in AAI", exception)
74 throw AbortingException(exception);
78 private fun generateRequest(jobUuid: UUID?, request: ServiceInstantiation, optimisticUniqueServiceInstanceName: String, userId: String): RequestDetailsWrapper<out Any> {
79 // for transport or for infrastructure VPN - send the pre 1806 request
80 if (shouldUsePre1806Request(request)){
81 return msoRequestBuilder.generateMacroServicePre1806InstantiationRequest(request, userId)
83 return msoRequestBuilder.generateMacroServiceInstantiationRequest(jobUuid, request, optimisticUniqueServiceInstanceName, userId)
86 protected fun shouldUsePre1806Request(request: ServiceInstantiation): Boolean {
87 return (request.vidNotions != null && pre1806Models.contains(request.vidNotions.modelCategory))
91 override fun handleInProgressStatus(jobStatus: Job.JobStatus): Job.JobStatus {
92 asyncInstantiationBL.updateServiceInfoAndAuditStatus(sharedData.jobUuid, jobStatus)
93 return if (jobStatus==Job.JobStatus.PAUSE) Job.JobStatus.IN_PROGRESS else jobStatus
96 override fun isDescendantHasAction(phase: Action): Boolean {