Introduce FeatureManager to ResourceCommand
[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 org.togglz.core.manager.FeatureManager
17 import java.util.*
18
19 @Component
20 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
21 class VolumeGroupCommand @Autowired constructor(
22         private val asyncInstantiationBL: AsyncInstantiationBusinessLogic,
23         restMso: RestMsoImplementation,
24         private val msoRequestBuilder: MsoRequestBuilder,
25         msoResultHandlerService: MsoResultHandlerService,
26         inProgressStatusService:InProgressStatusService,
27         watchChildrenJobsBL: WatchChildrenJobsBL,
28         jobsBrokerService: JobsBrokerService,
29         jobAdapter: JobAdapter,
30         featureManager: FeatureManager
31 ) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService,
32         watchChildrenJobsBL, jobsBrokerService, jobAdapter, featureManager), JobCommand {
33
34     companion object {
35         private val LOGGER = EELFLoggerDelegate.getLogger(VolumeGroupCommand::class.java)
36     }
37
38     override fun createChildren(): Job.JobStatus {
39         val request: VfModule = getRequest()
40         val dataForChild = buildDataForChild(request, actionPhase)
41
42         childJobs = pushChildrenJobsToBroker(listOf(request), dataForChild, JobType.VfmoduleInstantiation)
43
44         return Job.JobStatus.COMPLETED_WITH_NO_ACTION
45     }
46
47     override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
48         val serviceInstanceId = serviceInstanceIdFromRequest()
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                 serviceModelInfoFromRequest(), 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 }