Introduce FeatureManager to ResourceCommand
[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.job.JobsBrokerService
28 import org.onap.vid.model.serviceInstantiation.BaseResource
29 import org.onap.vid.model.serviceInstantiation.InstanceGroup
30 import org.onap.vid.mso.RestMsoImplementation
31 import org.onap.vid.services.AsyncInstantiationBusinessLogic
32 import org.springframework.beans.factory.annotation.Autowired
33 import org.springframework.beans.factory.config.ConfigurableBeanFactory
34 import org.springframework.context.annotation.Scope
35 import org.springframework.http.HttpMethod
36 import org.springframework.stereotype.Component
37 import org.togglz.core.manager.FeatureManager
38 import java.util.*
39
40 @Component
41 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
42 class InstanceGroupCommand @Autowired constructor(
43         private val asyncInstantiationBL: AsyncInstantiationBusinessLogic,
44         restMso: RestMsoImplementation,
45         private val msoRequestBuilder: MsoRequestBuilder,
46         msoResultHandlerService: MsoResultHandlerService,
47         inProgressStatusService:InProgressStatusService,
48         watchChildrenJobsBL: WatchChildrenJobsBL,
49         jobsBrokerService: JobsBrokerService,
50         jobAdapter: JobAdapter,
51         featureManager: FeatureManager
52 ) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService,
53         watchChildrenJobsBL, jobsBrokerService, jobAdapter, featureManager), JobCommand {
54
55     companion object {
56         private val LOGGER = EELFLoggerDelegate.getLogger(InstanceGroupCommand::class.java)
57     }
58
59     override fun createChildren(): Job.JobStatus {
60         val dataForChild = buildDataForChild(getRequest(), actionPhase)
61
62         childJobs = pushChildrenJobsToBroker(getRequest().vnfGroupMembers.values, dataForChild);
63
64         return Job.JobStatus.COMPLETED_WITH_NO_ACTION
65     }
66
67     override fun addMyselfToChildrenData(commandParentData: CommandParentData, request: BaseResource) {
68         commandParentData.addInstanceId(CommandParentData.CommandDataKey.VNF_GROUP_INSTANCE_ID, request.instanceId)
69     }
70
71     override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
72         val serviceInstanceId = serviceInstanceIdFromRequest()
73
74         val instantiatePath = asyncInstantiationBL.getInstanceGroupInstantiationPath()
75
76         val requestDetailsWrapper = msoRequestBuilder.generateInstanceGroupInstantiationRequest(
77                 request as InstanceGroup,
78                 serviceModelInfoFromRequest(), serviceInstanceId,
79                 userId,
80                 testApi
81         )
82
83         val actionDescription = "create instance group in $serviceInstanceId"
84
85         return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
86     }
87
88     override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
89         val path = asyncInstantiationBL.getInstanceGroupDeletePath(getRequest().instanceId)
90         return MsoRestCallPlan(HttpMethod.DELETE, path, Optional.empty(), Optional.of(userId),
91                 "delete instance group with id ${getRequest().instanceId}")
92
93     }
94
95     override fun getRequest(): InstanceGroup {
96         return sharedData.request as InstanceGroup
97     }
98 }