2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.vid.job.command
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
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 {
54 private val LOGGER = EELFLoggerDelegate.getLogger(InstanceGroupCommand::class.java)
57 override fun createChildren(): Job.JobStatus {
58 val dataForChild = buildDataForChild(getRequest(), actionPhase)
60 childJobs = pushChildrenJobsToBroker(getRequest().vnfGroupMembers.values, dataForChild);
62 return Job.JobStatus.COMPLETED_WITH_NO_ACTION
65 override fun addMyselfToChildrenData(commandParentData: CommandParentData, request: BaseResource) {
66 commandParentData.addInstanceId(CommandParentData.CommandDataKey.VNF_GROUP_INSTANCE_ID, request.instanceId)
69 override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
70 val serviceInstanceId = serviceInstanceIdFromRequest()
72 val instantiatePath = asyncInstantiationBL.getInstanceGroupInstantiationPath()
74 val requestDetailsWrapper = msoRequestBuilder.generateInstanceGroupInstantiationRequest(
75 request as InstanceGroup,
76 serviceModelInfoFromRequest(), serviceInstanceId,
81 val actionDescription = "create instance group in $serviceInstanceId"
83 return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)
86 override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan {
87 val path = asyncInstantiationBL.getInstanceGroupDeletePath(getRequest().instanceId)
88 return MsoRestCallPlan(HttpMethod.DELETE, path, Optional.empty(), Optional.of(userId),
89 "delete instance group with id ${getRequest().instanceId}")
93 override fun getRequest(): InstanceGroup {
94 return sharedData.request as InstanceGroup