Implant vid-app-common org.onap.vid.job (main and test)
[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
47         val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID)
48         val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO)
49         val vnfInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VNF_INSTANCE_ID)
50         val vnfModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.VNF_MODEL_INFO)
51
52         val instantiatePath = asyncInstantiationBL.getVolumeGroupInstantiationPath(serviceInstanceId,vnfInstanceId)
53
54         val requestDetailsWrapper = msoRequestBuilder.generateVolumeGroupInstantiationRequest(
55                 request as VfModule,
56                 serviceModelInfo, serviceInstanceId,
57                 vnfModelInfo,vnfInstanceId,
58                 userId,
59                 testApi
60         )
61
62         val actionDescription = "create volumeGroup in $vnfInstanceId"
63
64         return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
65     }
66
67     override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
68         TODO("not implemented")
69     }
70
71     override fun isNeedToCreateMyself(): Boolean {
72         return super.isNeedToCreateMyself() && isNotEmpty(getRequest().volumeGroupInstanceName)
73     }
74
75     override fun isNeedToDeleteMyself(): Boolean {
76         return false
77     }
78
79     override fun getRequest(): VfModule {
80         return sharedData.request as VfModule
81     }
82
83     override fun isDescendantHasAction(phase: Action): Boolean {
84         return phase == getRequest().action
85     }
86
87     override fun addMyselfToChildrenData(commandParentData: CommandParentData, request: BaseResource) {
88         commandParentData.addInstanceId(CommandParentData.CommandDataKey.VG_INSTANCE_ID, getActualInstanceId(request));
89     }
90
91     override fun replaceMyself(): Job.JobStatus {
92         return Job.JobStatus.COMPLETED
93     }
94 }