Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / command / InstanceGroupCommand.kt
1 package org.onap.vid.job.command
2
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.model.serviceInstantiation.InstanceGroup
8 import org.onap.vid.mso.RestMsoImplementation
9 import org.onap.vid.services.AsyncInstantiationBusinessLogic
10 import org.springframework.beans.factory.annotation.Autowired
11 import org.springframework.beans.factory.config.ConfigurableBeanFactory
12 import org.springframework.context.annotation.Scope
13 import org.springframework.http.HttpMethod
14 import org.springframework.stereotype.Component
15 import java.util.*
16
17 @Component
18 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
19 class InstanceGroupCommand @Autowired constructor(
20         private val asyncInstantiationBL: AsyncInstantiationBusinessLogic,
21         restMso: RestMsoImplementation,
22         msoResultHandlerService: MsoResultHandlerService,
23         inProgressStatusService:InProgressStatusService,
24         watchChildrenJobsBL: WatchChildrenJobsBL
25 ) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService, watchChildrenJobsBL), JobCommand {
26
27     companion object {
28         private val LOGGER = EELFLoggerDelegate.getLogger(InstanceGroupCommand::class.java)
29     }
30
31     override fun createChildren(): Job.JobStatus {
32         return Job.JobStatus.COMPLETED_WITH_NO_ACTION
33     }
34
35     override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
36         val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID)
37         val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO)
38
39         val instantiatePath = asyncInstantiationBL.getInstanceGroupInstantiationPath()
40
41         val requestDetailsWrapper = asyncInstantiationBL.generateInstanceGroupInstantiationRequest(
42                 request as InstanceGroup,
43                 serviceModelInfo, serviceInstanceId,
44                 userId
45         )
46
47         val actionDescription = "create instance group in $serviceInstanceId"
48
49         return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
50     }
51
52     override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
53         val path = asyncInstantiationBL.getInstanceGroupDeletePath(getRequest().instanceId)
54         return MsoRestCallPlan(HttpMethod.DELETE, path, Optional.empty(), Optional.of(userId),
55                 "delete instance group with id ${getRequest().instanceId}")
56
57     }
58
59 }