diff options
author | Einat Vinouze <einat.vinouze@intl.att.com> | 2019-08-27 16:01:01 +0300 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2019-09-09 07:01:36 +0000 |
commit | e1f7974f0badbd4440d5b7ea5f1b1cb2d4973818 (patch) | |
tree | 46be9cdc44cbb475527bc3c43df23d16f7579d29 /vid-app-common/src/main/java/org/onap/vid/job | |
parent | e25b88b5a7a0f3bf63ca7160a441b53145484bcc (diff) |
Adding feature: Replace vfmodule
Issue-ID: VID-603
Change-Id: I59068a0979d6fb733e4243c8f78921f396dc9d17
Signed-off-by: Einat Vinouze <einat.vinouze@intl.att.com>
Signed-off-by: Amichai Hemli <amichai.hemli@intl.att.com>
Signed-off-by: Ittay Stern <ittay.stern@att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/job')
3 files changed, 182 insertions, 14 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java index 0fe7255c4..2b6b57ade 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/CommandUtils.java @@ -21,8 +21,10 @@ package org.onap.vid.job.command; import org.apache.commons.lang3.StringUtils; +import org.onap.vid.aai.model.ModelVer; import org.onap.vid.asdc.AsdcCatalogException; import org.onap.vid.model.ServiceModel; +import org.onap.vid.services.AaiService; import org.onap.vid.services.VidService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -31,18 +33,16 @@ import org.springframework.stereotype.Component; public class CommandUtils { private final VidService vidService; + private final AaiService aaiService; @Autowired - public CommandUtils(VidService vidService) { + public CommandUtils(VidService vidService, AaiService aaiService) { this.vidService = vidService; + this.aaiService = aaiService; } public boolean isVfModuleBaseModule(String serviceModelUuid, String vfModuleModelUUID) throws AsdcCatalogException{ - ServiceModel serviceModel = vidService.getService(serviceModelUuid); - - if (serviceModel==null) { - throw new AsdcCatalogException("Failed to retrieve model with uuid "+serviceModelUuid +" from SDC"); - } + ServiceModel serviceModel = getServiceModel(serviceModelUuid); if (serviceModel.getVfModules() == null) { throw createAsdcCatalogVfModuleModelUUIDNotFoundException(serviceModelUuid, vfModuleModelUUID); @@ -58,6 +58,23 @@ public class CommandUtils { .getBaseModule(); } + public ServiceModel getServiceModel(String serviceModelUuid) throws AsdcCatalogException{ + ServiceModel serviceModel = vidService.getService(serviceModelUuid); + + if (serviceModel==null) { + throw new AsdcCatalogException("Failed to retrieve model with uuid "+serviceModelUuid +" from SDC"); + } + + return serviceModel; + } + + public String getNewestModelUuid(String serviceModelInvariantId) + { + ModelVer serviceModelLatestVersion = aaiService.getNewestModelVersionByInvariantId(serviceModelInvariantId); + + return serviceModelLatestVersion.getModelVersionId(); + } + private AsdcCatalogException createAsdcCatalogVfModuleModelUUIDNotFoundException(String serviceModelUuid, String vfModuleModelUUID) { return new AsdcCatalogException("Failed to find vfModuleModelUUID: " + vfModuleModelUUID + "in model with uuid: " + serviceModelUuid); diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt index 0e9ab7b7a..2c50e03cd 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/ResourceCommand.kt @@ -222,11 +222,16 @@ abstract class ResourceCommand( else -> InternalState.IN_PROGRESS } + InternalState.REPLACE_MYSELF -> when (jobStatus) { + JobStatus.IN_PROGRESS -> InternalState.REPLACE_MYSELF + else -> InternalState.IN_PROGRESS + } + InternalState.IN_PROGRESS -> { when { jobStatus != JobStatus.COMPLETED -> InternalState.IN_PROGRESS isDescendantHasAction(Action.Create) -> InternalState.CREATING_CHILDREN - isDescendantHasAction(Action.Replace) -> InternalState.CREATING_CHILDREN + isDescendantHasAction(Action.Upgrade) -> InternalState.CREATING_CHILDREN else -> InternalState.TERMINAL } } @@ -284,7 +289,7 @@ abstract class ResourceCommand( isNeedToResumeMySelf() -> InternalState.RESUME_MYSELF isNeedToReplaceMySelf() -> InternalState.REPLACE_MYSELF isDescendantHasAction(phase) -> InternalState.CREATING_CHILDREN - isDescendantHasAction(Action.Replace) -> InternalState.CREATING_CHILDREN + isDescendantHasAction(Action.Upgrade) -> InternalState.CREATING_CHILDREN else -> InternalState.TERMINAL } else -> throw IllegalStateException("state $internalState is not supported yet") diff --git a/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt b/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt index af52fa049..276b00e6f 100644 --- a/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt +++ b/vid-app-common/src/main/java/org/onap/vid/job/command/VfmoduleCommand.kt @@ -5,9 +5,10 @@ import org.onap.vid.job.Job import org.onap.vid.job.JobAdapter import org.onap.vid.job.JobCommand import org.onap.vid.job.JobsBrokerService -import org.onap.vid.model.Action +import org.onap.vid.model.* import org.onap.vid.model.serviceInstantiation.VfModule import org.onap.vid.mso.RestMsoImplementation +import org.onap.vid.mso.model.ModelInfo import org.onap.vid.services.AsyncInstantiationBusinessLogic import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.config.ConfigurableBeanFactory @@ -16,6 +17,8 @@ import org.springframework.http.HttpMethod import org.springframework.stereotype.Component import java.util.* +typealias ToscaVfm = org.onap.vid.model.VfModule + @Component @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE) class VfmoduleCommand @Autowired constructor( @@ -45,7 +48,7 @@ class VfmoduleCommand @Autowired constructor( val vnfInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VNF_INSTANCE_ID) val vgInstaceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VG_INSTANCE_ID) - val instantiatePath = asyncInstantiationBL.getVfmoduleInstantiationPath(serviceInstanceId, vnfInstanceId) + val instantiatePath = asyncInstantiationBL.getVfmoduleInstantiationPath(serviceInstanceId, vnfInstanceId) val requestDetailsWrapper = msoRequestBuilder.generateVfModuleInstantiationRequest( request as VfModule, @@ -75,14 +78,16 @@ class VfmoduleCommand @Autowired constructor( return false } - private fun planReplaceMyselfRestCall(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan { + private fun planReplaceMyselfRestCall3(commandParentData: CommandParentData, request: JobAdapter.AsyncJobRequest, userId: String, testApi: String?): MsoRestCallPlan { val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID) val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO) val vnfModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.VNF_MODEL_INFO) val vnfInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VNF_INSTANCE_ID) val replacePath = asyncInstantiationBL.getVfModuleReplacePath(serviceInstanceId, vnfInstanceId, getRequest().instanceId) - val requestDetailsWrapper = msoRequestBuilder.generateVfModuleInstantiationRequest( + amendModelInfoWithNewestModel(serviceModelInfo, vnfModelInfo, (request as VfModule).modelInfo) + + val requestDetailsWrapper = msoRequestBuilder.generateVfModuleInstantiationRequest( request as VfModule, serviceModelInfo, serviceInstanceId,vnfModelInfo, vnfInstanceId,null,userId, testApi) val actionDescription = "replace vfmodule ${request.instanceId}" @@ -90,9 +95,142 @@ class VfmoduleCommand @Autowired constructor( return MsoRestCallPlan(HttpMethod.POST, replacePath, Optional.of(requestDetailsWrapper), Optional.of(userId), actionDescription) } + private fun planReplaceMyselfRestCall(commandParentData: CommandParentData): MsoRestCallPlan { + + val newestModel = fetchNewestServiceModel() + + val serviceInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.SERVICE_INSTANCE_ID) + val vnfInstanceId = commandParentData.getInstanceId(CommandParentData.CommandDataKey.VNF_INSTANCE_ID) + + val (serviceModelInfo, vnfModelInfo, vfmModelInfo) = newestSelector(newestModel, commandParentData); + + val originalRequestWithNewestVfmModelInfo = getRequest().cloneWith(vfmModelInfo) + + val requestDetailsWrapper = msoRequestBuilder.generateVfModuleInstantiationRequest( + originalRequestWithNewestVfmModelInfo, serviceModelInfo, serviceInstanceId, + vnfModelInfo, vnfInstanceId, null, sharedData.userId, sharedData.testApi) + + + val replacePath = asyncInstantiationBL.getVfModuleReplacePath(serviceInstanceId, vnfInstanceId, getRequest().instanceId) + + return MsoRestCallPlan(HttpMethod.POST, replacePath, Optional.of(requestDetailsWrapper), Optional.of(sharedData.userId), + "replace vfmodule ${getRequest().instanceId}") + } + + data class ModelsInfoTriplet(val serviceModelInfo: ModelInfo, val vnfModelInfo: ModelInfo, val vfmModelInfo: ModelInfo) + + private fun newestSelector(newestModel: ServiceModel, commandParentData: CommandParentData): ModelsInfoTriplet { + val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO) + val vfmModelInfo = getRequest().modelInfo + val vnfModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.VNF_MODEL_INFO) + + val newestServiceModelInfo = newestServiceModelInfo(newestModel) + val newestVfmModelInfo = newestVfmModelInfo(newestModel) + val newestVnfModelInfo = newestVnfModelInfo(newestModel, commandParentData) + + return if (newestServiceModelInfo == null || newestVfmModelInfo == null || newestVnfModelInfo == null) { + ModelsInfoTriplet(serviceModelInfo, vnfModelInfo, vfmModelInfo) + } else { + ModelsInfoTriplet(newestServiceModelInfo, newestVnfModelInfo, newestVfmModelInfo) + } + } + + private fun newestServiceModelInfo(newestModel: ServiceModel) = toModelInfo(newestModel.service) + + private fun newestVfmModelInfo(newestModel: ServiceModel): ModelInfo? { + val vfmModelInfo = getRequest().modelInfo + val newestVfm = selectVfm(newestModel, vfmModelInfo) + return toModelInfo(newestVfm) + } + + private fun newestVnfModelInfo(newestModel: ServiceModel, commandParentData: CommandParentData): ModelInfo? { + val vnfModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.VNF_MODEL_INFO) + val newestVnf = selectVnf(newestModel, vnfModelInfo) + return toModelInfo(newestVnf) + } + + private fun selectVfm(newestModel: ServiceModel, modelInfo: ModelInfo) = newestModel.vfModules[modelInfo.modelCustomizationId] + + private fun selectVnf(newestModel: ServiceModel, modelInfo: ModelInfo) = newestModel.vnfs[modelInfo.modelCustomizationId] + + private fun toModelInfo(toBeConverted: VNF?): ModelInfo? = toBeConverted?.let { toModelInfo(it, "vnf") } + + private fun toModelInfo(toBeConverted: ToscaVfm?): ModelInfo? = toBeConverted?.let { toModelInfo(it, "vfModule") } + + private fun toModelInfo(toBeConverted: MinimalNode, modelType: String): ModelInfo { + val targetModelInfo = ModelInfo() + + targetModelInfo.modelType = modelType + targetModelInfo.modelName = toBeConverted.name + targetModelInfo.modelNameVersionId = null + targetModelInfo.modelVersion = toBeConverted.version + targetModelInfo.modelVersionId = toBeConverted.uuid + targetModelInfo.modelInvariantId = toBeConverted.invariantUuid + + targetModelInfo.modelCustomizationId = when (toBeConverted) { + is VNF -> toBeConverted.customizationUuid + is ToscaVfm -> toBeConverted.customizationUuid + else -> throw IllegalArgumentException() + } + + targetModelInfo.modelCustomizationName = when (toBeConverted) { + is VNF -> toBeConverted.modelCustomizationName + is ToscaVfm -> toBeConverted.modelCustomizationName + else -> throw IllegalArgumentException() + } + + return targetModelInfo + } + + private fun toModelInfo(toBeConverted: Service?): ModelInfo? { + + if (toBeConverted == null) + return null + + val targetModelInfo = ModelInfo() + + targetModelInfo.modelVersionId = toBeConverted.uuid + targetModelInfo.modelInvariantId = toBeConverted.invariantUuid + targetModelInfo.modelVersion = toBeConverted.version + //targetModelInfo.modelCustomizationId = toBeConverted.customizationUuid + //targetModelInfo.modelCustomizationName = toBeConverted.modelCustomizationName + targetModelInfo.modelType = "service" + targetModelInfo.modelName = toBeConverted.name + + return targetModelInfo + } + + private fun amendModelInfoWithNewestModel(serviceModelInfo: ModelInfo, vnfModelInfo: ModelInfo, vfmModelInfo: ModelInfo) { + val newestModel = fetchNewestServiceModel() + val newestService = newestModel.service + + val newestVfm = newestModel.vfModules[vfmModelInfo.modelCustomizationId] + val newestVnf = newestModel.vnfs[vnfModelInfo.modelCustomizationId] + + if (!(newestService == null || newestVnf == null || newestVfm == null)) { + + serviceModelInfo.modelName = newestService.name + serviceModelInfo.modelVersionId = newestService.uuid + serviceModelInfo.modelVersion = newestService.version + + vnfModelInfo.modelName = newestVnf.name + vnfModelInfo.modelVersionId = newestVnf.uuid + vnfModelInfo.modelVersion = newestVnf.version + vnfModelInfo.modelCustomizationId = newestVnf.customizationUuid + vnfModelInfo.modelCustomizationName = newestVnf.modelCustomizationName + + vfmModelInfo.modelName = newestVfm.name + vfmModelInfo.modelVersionId = newestVfm.uuid + vfmModelInfo.modelVersion = newestVfm.version + vfmModelInfo.modelCustomizationId = newestVfm.customizationUuid + vfmModelInfo.modelCustomizationName = newestVfm.modelCustomizationName + } + } + + override fun replaceMyself(): Job.JobStatus { try { - val replaceMyselfCommand = planReplaceMyselfRestCall(commandParentData, sharedData.request, sharedData.userId, sharedData.testApi ) + val replaceMyselfCommand = planReplaceMyselfRestCall(commandParentData) return executeAndHandleMsoInstanceRequest(replaceMyselfCommand) } catch (exception: Exception) { LOGGER.error("Failed to replace instanceId ${getRequest().instanceId} ", exception) @@ -101,6 +239,14 @@ class VfmoduleCommand @Autowired constructor( } override fun isNeedToReplaceMySelf(): Boolean { - return getActionType() == Action.Replace + return getActionType() == Action.Upgrade + } + + private fun fetchNewestServiceModel(): ServiceModel { + val serviceModelInfo = commandParentData.getModelInfo(CommandParentData.CommandDataKey.SERVICE_MODEL_INFO) + var modelNewestUuid = commandUtils.getNewestModelUuid(serviceModelInfo.modelInvariantId); + var serviceNewestModel = commandUtils.getServiceModel(modelNewestUuid); + + return serviceNewestModel; } } |