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