1 package org.onap.vid.job.command
3 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate
4 import org.onap.vid.job.Job
5 import org.onap.vid.job.JobAdapter
6 import org.onap.vid.job.JobCommand
7 import org.onap.vid.job.JobsBrokerService
8 import org.onap.vid.model.Action
9 import org.onap.vid.model.serviceInstantiation.VfModule
10 import org.onap.vid.mso.RestMsoImplementation
11 import org.onap.vid.services.AsyncInstantiationBusinessLogic
12 import org.springframework.beans.factory.annotation.Autowired
13 import org.springframework.beans.factory.config.ConfigurableBeanFactory
14 import org.springframework.context.annotation.Scope
15 import org.springframework.http.HttpMethod
16 import org.springframework.stereotype.Component
20 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
21 class VfmoduleCommand @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 ) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService,
31 watchChildrenJobsBL, jobsBrokerService, jobAdapter), JobCommand {
34 private val LOGGER = EELFLoggerDelegate.getLogger(VfmoduleCommand::class.java)
37 override fun createChildren(): Job.JobStatus {
38 return Job.JobStatus.COMPLETED_WITH_NO_ACTION
41 override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
42 val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID)
43 val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO)
44 val vnfModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.VNF_MODEL_INFO)
45 val vnfInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VNF_INSTANCE_ID)
46 val vgInstaceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VG_INSTANCE_ID)
48 val instantiatePath = asyncInstantiationBL.getVfmoduleInstantiationPath(serviceInstanceId, vnfInstanceId)
50 val requestDetailsWrapper = msoRequestBuilder.generateVfModuleInstantiationRequest(
52 serviceModelInfo, serviceInstanceId, vnfModelInfo, vnfInstanceId, vgInstaceId, userId, testApi)
54 val actionDescription = "create vfmodule in $vnfInstanceId"
56 return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
60 override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
61 val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID)
62 val vnfInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VNF_INSTANCE_ID)
64 val path = asyncInstantiationBL.getVfModuleDeletePath(serviceInstanceId, vnfInstanceId, getRequest().instanceId)
65 val requestDetailsWrapper = msoRequestBuilder.generateDeleteVfModuleRequest(getRequest(), userId)
66 return MsoRestCallPlan(HttpMethod.DELETE, path, Optional.of(requestDetailsWrapper), Optional.of(userId),
67 "delete vfmodule ${getRequest().instanceId} from service instance $serviceInstanceId and vnf $vnfInstanceId")
70 override fun getRequest(): VfModule {
71 return sharedData.request as VfModule
74 override fun isDescendantHasAction(phase: Action): Boolean {
78 private fun planReplaceMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
79 val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID)
80 val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO)
81 val vnfModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.VNF_MODEL_INFO)
82 val vnfInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VNF_INSTANCE_ID)
83 val replacePath = asyncInstantiationBL.getVfModuleReplacePath(serviceInstanceId, vnfInstanceId, getRequest().instanceId)
85 val requestDetailsWrapper = msoRequestBuilder.generateVfModuleInstantiationRequest(
86 request as VfModule, serviceModelInfo, serviceInstanceId,vnfModelInfo, vnfInstanceId,null,userId, testApi)
88 val actionDescription = "replace vfmodule ${request.instanceId}"
90 return MsoRestCallPlan(HttpMethod.POST, replacePath, Optional.of(requestDetailsWrapper), Optional.of(userId), actionDescription)
93 override fun replaceMyself(): Job.JobStatus {
95 val replaceMyselfCommand = planReplaceMyselfRestCall(commandParentData, sharedData.request, sharedData.userId, sharedData.testApi )
96 return executeAndHandleMsoInstanceRequest(replaceMyselfCommand)
97 } catch (exception: Exception) {
98 LOGGER.error("Failed to replace instanceId ${getRequest().instanceId} ", exception)
99 return Job.JobStatus.FAILED
103 override fun isNeedToReplaceMySelf(): Boolean {
104 return getActionType() == Action.Replace