diff options
author | Ittay Stern <ittay.stern@att.com> | 2018-12-31 17:21:27 +0200 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-01-09 20:19:55 +0200 |
commit | 6ad41e3ccd398a2721f41ad61c80b7bb03f7d127 (patch) | |
tree | 3bd672dff83e3218232cd8665680416b7fc26a5d /vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt | |
parent | 5ec29ff5e3864f1ba6ecac71f8bffbefa400cf27 (diff) |
Merge from ECOMP's repository
Main Features
--------------
- Async-Instantiation jobs mechanism major update; still WIP (package
`org.onap.vid.job`)
- New features in View/Edit: Activate fabric configuration; show
related networks; soft delete
- Support AAI service-tree traversal (`AAIServiceTree`)
- In-memory cache for SDC models and certain A&AI queries
(`CacheProviderWithLoadingCache`)
- Upgrade TOSCA Parser and add parsing options; fix malformed TOSCA
models
- Resolve Cloud-Owner values for MSO
- Pass X-ONAP headers to MSO
Infrastructure
--------------
- Remove codehaus' jackson mapper; use soley fasterxml 2.9.7
- Surefire invokes both TestNG and JUnit tests
- Support Kotlin source files
- AaiController2 which handles errors in a "Spring manner"
- Inline generated-sources and remove jsonschema2pojo
Quality
--------
- Cumulative bug fixes (A&AI API, UI timeouts, and many more)
- Many Sonar issues cleaned-up
- Some unused classes removed
- Minor changes in vid-automation project, allowing some API
verification to run
Hard Merges
------------
- HTTP Clients (MSO, A&AI, WebConfig, OutgoingRequestHeadersTest)
- Moved `package org.onap.vid.controllers` to `controller`, without
plural -- just to keep semantic sync with ECOMP.
Reference commit in ECOMP: 3d1141625
Issue-ID: VID-378
Change-Id: I9c8d1e74caa41815891d441fc0760bb5f29c5788
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt')
-rw-r--r-- | vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt new file mode 100644 index 000000000..f88e9d65e --- /dev/null +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ALaCarteServiceCommand.kt @@ -0,0 +1,122 @@ +package org.onap.vid.job.command + +import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate +import org.onap.vid.changeManagement.RequestDetailsWrapper +import org.onap.vid.job.* +import org.onap.vid.model.Action +import org.onap.vid.model.serviceInstantiation.ServiceInstantiation +import org.onap.vid.mso.RestMsoImplementation +import org.onap.vid.mso.model.ServiceDeletionRequestDetails +import org.onap.vid.properties.VidProperties +import org.onap.vid.services.AsyncInstantiationBusinessLogic +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.beans.factory.config.ConfigurableBeanFactory +import org.springframework.context.annotation.Scope +import org.springframework.http.HttpMethod +import org.springframework.stereotype.Component +import java.time.ZonedDateTime +import java.time.temporal.ChronoUnit +import java.util.* + +class ServiceExpiryChecker : ExpiryChecker { + + override fun isExpired(jobStartTime: ZonedDateTime?): Boolean { + val now = ZonedDateTime.now() + val maxHoursInProgress = VidProperties.getLongProperty(VidProperties.VID_JOB_MAX_HOURS_IN_PROGRESS) + val hoursBetween = ChronoUnit.HOURS.between(jobStartTime, now) + return maxHoursInProgress in 1..hoursBetween + } +} + + +@Component +@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) +class ALaCarteServiceCommand @Autowired constructor( + inProgressStatusService: InProgressStatusService, + watchChildrenJobsBL: WatchChildrenJobsBL, + private val asyncInstantiationBL: AsyncInstantiationBusinessLogic, + private val jobsBrokerService: JobsBrokerService, + msoResultHandlerService: MsoResultHandlerService, + private val jobAdapter: JobAdapter, + restMso: RestMsoImplementation +) : ResourceCommand(restMso, inProgressStatusService, msoResultHandlerService, watchChildrenJobsBL), JobCommand { + + override fun getExpiryChecker(): ExpiryChecker { + return ServiceExpiryChecker(); + } + + companion object { + private val LOGGER = EELFLoggerDelegate.getLogger(ALaCarteServiceCommand::class.java) + } + + override fun getRequest(): ServiceInstantiation { + return msoResultHandlerService.getRequest(sharedData) + } + + override fun createChildren(): Job.JobStatus { + val dataForChild = buildDataForChild(getRequest())//.plus(ACTION_PHASE to actionPhase) + + val childJobType = when (actionPhase) { + Action.Create -> JobType.InstanceGroupInstantiation + Action.Delete -> JobType.InstanceGroup + else -> return Job.JobStatus.COMPLETED + } + + childJobs = getRequest().vnfGroups + .map { jobAdapter.createChildJob(childJobType, Job.JobStatus.CREATING, it.value, sharedData, dataForChild) } + .map { jobsBrokerService.add(it) } + .map { it.toString() } + + return Job.JobStatus.COMPLETED_WITH_NO_ACTION + } + + private fun buildDataForChild(request: ServiceInstantiation): Map<String, Any> { + val commandParentData = CommandParentData() + commandParentData.addInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID, request.instanceId) + commandParentData.addModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO, request.modelInfo) + return commandParentData.parentData + } + + override fun planCreateMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan { + TODO("not implemented") + } + + override fun planDeleteMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String): MsoRestCallPlan { + val requestDetailsWrapper = generateServiceDeletionRequest() + val path = asyncInstantiationBL.getServiceDeletionPath(getRequest().instanceId) + return MsoRestCallPlan(HttpMethod.DELETE, path, Optional.of(requestDetailsWrapper), Optional.empty(), + "delete instance with id ${getRequest().instanceId}") + + } + + override fun handleInProgressStatus(jobStatus: Job.JobStatus): Job.JobStatus { + if (jobStatus==Job.JobStatus.FAILED) { + asyncInstantiationBL.handleFailedInstantiation(sharedData.jobUuid) + return jobStatus + } + + asyncInstantiationBL.updateServiceInfoAndAuditStatus(sharedData.jobUuid, jobStatus) + return if (jobStatus == Job.JobStatus.PAUSE) Job.JobStatus.IN_PROGRESS else jobStatus + } + + + private fun generateServiceDeletionRequest(): RequestDetailsWrapper<ServiceDeletionRequestDetails> { + return asyncInstantiationBL.generateALaCarteServiceDeletionRequest( + sharedData.jobUuid, getRequest(), sharedData.userId + ) + } + + override fun getExternalInProgressStatus() = Job.JobStatus.IN_PROGRESS + + override fun isServiceCommand(): Boolean = true + + override fun onFinal(jobStatus: Job.JobStatus) { + asyncInstantiationBL.updateServiceInfoAndAuditStatus(sharedData.jobUuid, jobStatus) + } + + override fun onInitial(phase: Action) { + if (phase== Action.Delete) { + asyncInstantiationBL.updateServiceInfoAndAuditStatus(sharedData.jobUuid, Job.JobStatus.IN_PROGRESS) + } + } +} |