9794933cee284c7861d4ae92faf5e1d0f01f1667
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / command / VolumeGroupCommand.kt
1 package org.onap.vid.job.command
2
3 import org.apache.commons.lang3.StringUtils.isNotEmpty
4 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate
5 import org.onap.vid.job.*
6 import org.onap.vid.model.Action
7 import org.onap.vid.model.serviceInstantiation.BaseResource
8 import org.onap.vid.model.serviceInstantiation.VfModule
9 import org.onap.vid.mso.RestMsoImplementation
10 import org.onap.vid.services.AsyncInstantiationBusinessLogic
11 import org.springframework.beans.factory.annotation.Autowired
12 import org.springframework.beans.factory.config.ConfigurableBeanFactory
13 import org.springframework.context.annotation.Scope
14 import org.springframework.http.HttpMethod
15 import org.springframework.stereotype.Component
16 import java.util.*
17
18 @Component
19 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
20 class VolumeGroupCommand @Autowired constructor(
21         private val asyncInstantiationBL: AsyncInstantiationBusinessLogic,
22         restMso: RestMsoImplementation,
23         private val msoRequestBuilder: MsoRequestBuilder,
24         msoResultHandlerService: MsoResultHandlerService,
25         inProgressStatusService:InProgressStatusService,
26         watchChildrenJobsBL: WatchChildrenJobsBL,
27         jobsBrokerService: JobsBrokerService,
28         jobAdapter: JobAdapter
29 ) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService,
30         watchChildrenJobsBL, jobsBrokerService, jobAdapter), JobCommand {
31
32     companion object {
33         private val LOGGER = EELFLoggerDelegate.getLogger(VolumeGroupCommand::class.java)
34     }
35
36     override fun createChildren(): Job.JobStatus {
37         val request: VfModule = getRequest()
38         val dataForChild = buildDataForChild(request, actionPhase)
39
40         childJobs = pushChildrenJobsToBroker(listOf(request), dataForChild, JobType.VfmoduleInstantiation)
41
42         return Job.JobStatus.COMPLETED_WITH_NO_ACTION
43     }
44
45     override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
46         val serviceInstanceId = serviceInstanceIdFromRequest()
47         val vnfInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VNF_INSTANCE_ID)
48         val vnfModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.VNF_MODEL_INFO)
49
50         val instantiatePath = asyncInstantiationBL.getVolumeGroupInstantiationPath(serviceInstanceId,vnfInstanceId)
51
52         val requestDetailsWrapper = msoRequestBuilder.generateVolumeGroupInstantiationRequest(
53                 request as VfModule,
54                 serviceModelInfoFromRequest(), serviceInstanceId,
55                 vnfModelInfo,vnfInstanceId,
56                 userId,
57                 testApi
58         )
59
60         val actionDescription = "create volumeGroup in $vnfInstanceId"
61
62         return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
63     }
64
65     override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
66         TODO("not implemented")
67     }
68
69     override fun isNeedToCreateMyself(): Boolean {
70         return super.isNeedToCreateMyself() && isNotEmpty(getRequest().volumeGroupInstanceName)
71     }
72
73     override fun isNeedToDeleteMyself(): Boolean {
74         return false
75     }
76
77     override fun getRequest(): VfModule {
78         return sharedData.request as VfModule
79     }
80
81     override fun isDescendantHasAction(phase: Action): Boolean {
82         return phase == getRequest().action
83     }
84
85     override fun addMyselfToChildrenData(commandParentData: CommandParentData, request: BaseResource) {
86         commandParentData.addInstanceId(CommandParentData.CommandDataKey.VG_INSTANCE_ID, getActualInstanceId(request));
87     }
88
89     override fun replaceMyself(): Job.JobStatus {
90         return Job.JobStatus.COMPLETED
91     }
92 }