1 package org.onap.vid.job.command
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
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 {
33 private val LOGGER = EELFLoggerDelegate.getLogger(VolumeGroupCommand::class.java)
36 override fun createChildren(): Job.JobStatus {
37 val request: VfModule = getRequest()
38 val dataForChild = buildDataForChild(request, actionPhase)
40 childJobs = pushChildrenJobsToBroker(listOf(request), dataForChild, JobType.VfmoduleInstantiation)
42 return Job.JobStatus.COMPLETED_WITH_NO_ACTION
45 override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
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)
52 val instantiatePath = asyncInstantiationBL.getVolumeGroupInstantiationPath(serviceInstanceId,vnfInstanceId)
54 val requestDetailsWrapper = msoRequestBuilder.generateVolumeGroupInstantiationRequest(
56 serviceModelInfo, serviceInstanceId,
57 vnfModelInfo,vnfInstanceId,
62 val actionDescription = "create volumeGroup in $vnfInstanceId"
64 return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
67 override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
68 TODO("not implemented")
71 override fun isNeedToCreateMyself(): Boolean {
72 return super.isNeedToCreateMyself() && isNotEmpty(getRequest().volumeGroupInstanceName)
75 override fun isNeedToDeleteMyself(): Boolean {
79 override fun getRequest(): VfModule {
80 return sharedData.request as VfModule
83 override fun isDescendantHasAction(phase: Action): Boolean {
84 return phase == getRequest().action
87 override fun addMyselfToChildrenData(commandParentData: CommandParentData, request: BaseResource) {
88 commandParentData.addInstanceId(CommandParentData.CommandDataKey.VG_INSTANCE_ID, getActualInstanceId(request));
91 override fun replaceMyself(): Job.JobStatus {
92 return Job.JobStatus.COMPLETED