e81fcd34e33acaeea8233f9deae1231b58574ec5
[vid.git] / vid-app-common / src / main / java / org / onap / vid / job / command / InstanceGroupCommand.kt
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.vid.job.command
22
23 import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate
24 import org.onap.vid.job.Job
25 import org.onap.vid.job.JobAdapter
26 import org.onap.vid.job.JobCommand
27 import org.onap.vid.model.serviceInstantiation.InstanceGroup
28 import org.onap.vid.mso.RestMsoImplementation
29 import org.onap.vid.services.AsyncInstantiationBusinessLogic
30 import org.springframework.beans.factory.annotation.Autowired
31 import org.springframework.beans.factory.config.ConfigurableBeanFactory
32 import org.springframework.context.annotation.Scope
33 import org.springframework.http.HttpMethod
34 import org.springframework.stereotype.Component
35 import java.util.*
36
37 @Component
38 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
39 class InstanceGroupCommand @Autowired constructor(
40         private val asyncInstantiationBL: AsyncInstantiationBusinessLogic,
41         restMso: RestMsoImplementation,
42         msoResultHandlerService: MsoResultHandlerService,
43         inProgressStatusService:InProgressStatusService,
44         watchChildrenJobsBL: WatchChildrenJobsBL
45 ) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService, watchChildrenJobsBL), JobCommand {
46
47     companion object {
48         private val LOGGER = EELFLoggerDelegate.getLogger(InstanceGroupCommand::class.java)
49     }
50
51     override fun createChildren(): Job.JobStatus {
52         return Job.JobStatus.COMPLETED_WITH_NO_ACTION
53     }
54
55     override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
56         val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID)
57         val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO)
58
59         val instantiatePath = asyncInstantiationBL.getInstanceGroupInstantiationPath()
60
61         val requestDetailsWrapper = asyncInstantiationBL.generateInstanceGroupInstantiationRequest(
62                 request as InstanceGroup,
63                 serviceModelInfo, serviceInstanceId,
64                 userId
65         )
66
67         val actionDescription = "create instance group in $serviceInstanceId"
68
69         return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
70     }
71
72     override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
73         val path = asyncInstantiationBL.getInstanceGroupDeletePath(getRequest().instanceId)
74         return MsoRestCallPlan(HttpMethod.DELETE, path, Optional.empty(), Optional.of(userId),
75                 "delete instance group with id ${getRequest().instanceId}")
76
77     }
78
79 }