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.ServiceInstantiation
30 import org.onap.vid.mso.RestMsoImplementation
31 import org.onap.vid.properties.VidProperties
32 import org.onap.vid.services.AsyncInstantiationBusinessLogic
33 import org.onap.vid.services.AuditService
34 import org.springframework.beans.factory.annotation.Autowired
35 import org.springframework.beans.factory.config.ConfigurableBeanFactory
36 import org.springframework.context.annotation.Scope
37 import org.springframework.http.HttpMethod
38 import org.springframework.stereotype.Component
39 import org.togglz.core.manager.FeatureManager
40 import java.time.ZonedDateTime
41 import java.time.temporal.ChronoUnit
44 const val UNIQUE_INSTANCE_NAME = "optimisticUniqueServiceInstanceName"
46 class ServiceExpiryChecker : ExpiryChecker {
48 override fun isExpired(jobStartTime: ZonedDateTime?): Boolean {
49 val now = ZonedDateTime.now()
50 val maxHoursInProgress = VidProperties.getLongProperty(VidProperties.VID_JOB_MAX_HOURS_IN_PROGRESS)
51 val hoursBetween = ChronoUnit.HOURS.between(jobStartTime, now)
52 return maxHoursInProgress in 1..hoursBetween
57 @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
58 class ALaCarteServiceCommand @Autowired constructor(
59 inProgressStatusService: InProgressStatusService,
60 watchChildrenJobsBL: WatchChildrenJobsBL,
61 private val asyncInstantiationBL: AsyncInstantiationBusinessLogic,
62 jobsBrokerService: JobsBrokerService,
63 private val msoRequestBuilder: MsoRequestBuilder,
64 msoResultHandlerService: MsoResultHandlerService,
65 jobAdapter: JobAdapter,
66 restMso: RestMsoImplementation,
67 auditService: AuditService,
68 featureManager: FeatureManager
69 ) : RootServiceCommand(restMso, inProgressStatusService, msoResultHandlerService,
70 watchChildrenJobsBL, jobsBrokerService, jobAdapter, asyncInstantiationBL, auditService, msoRequestBuilder, featureManager), JobCommand {
73 private val LOGGER = EELFLoggerDelegate.getLogger(ALaCarteServiceCommand::class.java)
76 override fun getRequest(): ServiceInstantiation {
77 return msoResultHandlerService.getRequest(sharedData)
80 override fun createChildren(): Job.JobStatus {
81 val dataForChild = buildDataForChild(getRequest(), actionPhase)
83 childJobs = pushChildrenJobsToBroker(getRequest().children, dataForChild)
85 return Job.JobStatus.COMPLETED_WITH_NO_ACTION
88 override fun addMyselfToChildrenData(commandParentData: CommandParentData, request: BaseResource) {
89 val instanceId = getActualInstanceId(request)
90 commandParentData.addInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID, instanceId)
91 commandParentData.addModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO, request.modelInfo)
94 override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan {
95 val instantiatePath = asyncInstantiationBL.getServiceInstantiationPath(request as ServiceInstantiation)
97 val requestDetailsWrapper = msoRequestBuilder.generateALaCarteServiceInstantiationRequest(
98 request, optimisticUniqueServiceInstanceName, userId)
100 val actionDescription = "create service instance"
102 return MsoRestCallPlan(HttpMethod.POST, instantiatePath, Optional.of(requestDetailsWrapper), Optional.empty(), actionDescription)