diff options
author | hetengjiao <hetengjiao@chinamobile.com> | 2020-05-13 23:08:47 +0800 |
---|---|---|
committer | hetengjiao <hetengjiao@chinamobile.com> | 2020-05-13 23:09:00 +0800 |
commit | 9eba7e8a6067e792ca0753235fcf1e6d0bd41244 (patch) | |
tree | 701d1aaada2fc7c82b17390116b357f45f7e41b1 /bpmn/so-bpmn-infrastructure-common/src | |
parent | 0746d5df51818753e950bf7a18d1d2d5ba583d0a (diff) |
update nsmf to fix oof and nssmf problem
Issue-ID: SO-2919
Signed-off-by: hetengjiao <hetengjiao@chinamobile.com>
Change-Id: I3dc20b3eeb0ec5f72215dbe81295317446d60524
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src')
4 files changed, 89 insertions, 79 deletions
diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy index 2da5878e36..15a0f34482 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy @@ -349,7 +349,7 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { String orchStatus = execution.getVariable("orchestrationStatus") try { - ServiceInstance si = execution.getVariable("serviceInstanceData") + ServiceInstance si = ServiceInstance si = new ServiceInstance() si.setOrchestrationStatus(orchStatus) AAIResourcesClient client = new AAIResourcesClient() AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, serviceInstanceId) diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSIandNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSIandNSSI.groovy index f58cd9a60d..cc2d865957 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSIandNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoAllocateNSIandNSSI.groovy @@ -1,31 +1,45 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + package org.onap.so.bpmn.infrastructure.scripts -import com.google.common.reflect.TypeToken -import com.google.gson.Gson import org.camunda.bpm.engine.delegate.BpmnError import org.camunda.bpm.engine.delegate.DelegateExecution -import org.onap.aai.domain.yang.AllottedResource import org.onap.aai.domain.yang.Relationship import org.onap.aai.domain.yang.RelationshipList import org.onap.aai.domain.yang.ServiceInstance import org.onap.so.beans.nsmf.SliceTaskParams import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.domain.ServiceProxy import org.onap.so.bpmn.core.json.JsonUtils import org.onap.aaiclient.client.aai.AAIObjectType import org.onap.aaiclient.client.aai.AAIResourcesClient -import org.onap.aaiclient.client.aai.entities.AAIEdgeLabel import org.onap.aaiclient.client.aai.entities.AAIResultWrapper import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory -import org.onap.so.db.request.client.RequestsDbClient -import org.onap.so.db.request.beans.OrchestrationTask import org.slf4j.Logger import org.slf4j.LoggerFactory import javax.ws.rs.NotFoundException -import javax.ws.rs.core.UriBuilder import static org.apache.commons.lang3.StringUtils.isBlank @@ -36,7 +50,8 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() - RequestsDbClient requestsDbClient = new RequestsDbClient() + + private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil) /** * Pre Process the BPMN Flow Request @@ -65,8 +80,9 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi SliceTaskParams sliceParams = execution.getVariable("sliceTaskParams") try { - String modelUuid = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.nstar0_allottedresource0_providing_service_uuid") - String modelInvariantUuid = jsonUtil.getJsonValue(uuiRequest, "service.parameters.requestInputs.nstar0_allottedresource0_providing_service_invariant_uuid") + Map<String, Object> nstSolution = execution.getVariable("nstSolution") as Map + String modelUuid = nstSolution.get("UUID") + String modelInvariantUuid = nstSolution.get("invariantUUID") String serviceModelInfo = """{ "modelInvariantUuid":"${modelInvariantUuid}", "modelUuid":"${modelUuid}", @@ -105,7 +121,7 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi String nsiServiceInstanceID = sliceParams.getSuggestNsiId() AAIResourcesClient resourceClient = new AAIResourcesClient() - AAIResourceUri nsiServiceuri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), nsiServiceInstanceID) + AAIResourceUri nsiServiceuri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), nsiServiceInstanceID) //AAIResourceUri nsiServiceuri = AAIUriFactory.createResourceUri(AAIObjectType.QUERY_ALLOTTED_RESOURCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), nsiServiceInstanceID) try { @@ -156,7 +172,7 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi { try { AAIResourcesClient resourceClient = new AAIResourcesClient() - AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("serviceType"), nssiID) + AAIResourceUri serviceInstanceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), nssiID) AAIResultWrapper wrapper = resourceClient.get(serviceInstanceUri, NotFoundException.class) Optional<org.onap.aai.domain.yang.ServiceInstance> si = wrapper.asBean(org.onap.aai.domain.yang.ServiceInstance.class) org.onap.aai.domain.yang.ServiceInstance nssi = si.get() @@ -179,13 +195,13 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi } void createNSIinAAI(DelegateExecution execution) { - logger.trace("Enter CreateNSIinAAI in DoAllocateNSIandNSSI()") + logger.debug("Enter CreateNSIinAAI in DoAllocateNSIandNSSI()") ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition") org.onap.aai.domain.yang.ServiceInstance nsi = new ServiceInstance(); String sliceInstanceId = UUID.randomUUID().toString() execution.setVariable("sliceInstanceId",sliceInstanceId) nsi.setServiceInstanceId(sliceInstanceId) - String sliceInstanceName = "nsi_"+execution.getVariable("serviceInstanceName") + String sliceInstanceName = "nsi_"+execution.getVariable("sliceServiceInstanceName") nsi.setServiceInstanceName(sliceInstanceName) String serviceType = execution.getVariable("serviceType") nsi.setServiceType(serviceType) @@ -202,11 +218,20 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi //nsi.setEnvironmentContext(snssai) String serviceRole = "nsi" nsi.setServiceRole(serviceRole) + String msg = "" try { AAIResourcesClient client = new AAIResourcesClient() - AAIResourceUri uri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), sliceInstanceId) - client.create(uri, nsi) + AAIResourceUri nsiServiceUri = AAIUriFactory.createResourceUri(AAIObjectType.SERVICE_INSTANCE, execution.getVariable("globalSubscriberId"), execution.getVariable("subscriptionServiceType"), sliceInstanceId) + client.create(nsiServiceUri, nsi) + + Relationship relationship = new Relationship() + logger.info("Creating Allotted resource relationship, nsiServiceUri: " + nsiServiceUri.build().toString()) + relationship.setRelatedLink(nsiServiceUri.build().toString()) + AAIResourceUri allottedResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.ALLOTTED_RESOURCE, + execution.getVariable("globalSubscriberId"),execution.getVariable("subscriptionServiceType"), + execution.getVariable("sliceServiceInstanceId"), execution.getVariable("allottedResourceId")).relationshipAPI() + client.create(allottedResourceUri, relationship) } catch (BpmnError e) { throw e @@ -243,7 +268,7 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi execution.setVariable("maxIndex",maxIndex) execution.setVariable('nsiServiceInstanceId',sliceInstanceId) execution.setVariable("nsiServiceInstanceName",sliceInstanceName) - logger.trace("Exit CreateNSIinAAI in DoAllocateNSIandNSSI()") + logger.debug("Exit CreateNSIinAAI in DoAllocateNSIandNSSI()") } void getOneNsstInfo(DelegateExecution execution){ @@ -271,7 +296,7 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi String domain = jsonUtil.getJsonValue(content, "metadata.domainType") Map<String, Object> nssiMap = execution.getVariable("nssiMap") - String servicename = execution.getVariable("serviceInstanceName") + String servicename = execution.getVariable("sliceServiceInstanceName") String nsiname = "nsi_"+servicename nssiMap.put(domain,"""{ "serviceInstanceId":"", @@ -335,4 +360,4 @@ class DoAllocateNSIandNSSI extends org.onap.so.bpmn.common.scripts.AbstractServi } logger.trace("Exit updateCurrentIndex in DoAllocateNSIandNSSI()") } -} +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy index e6f6af5ab7..4be6ca7e49 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeallocateNSSI.groovy @@ -31,15 +31,14 @@ import org.onap.so.beans.nsmf.NssiDeAllocateRequest import org.onap.so.beans.nsmf.NssiResponse import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil +import org.onap.so.bpmn.common.scripts.NssmfAdapterUtils import org.onap.so.bpmn.common.scripts.RequestDBUtil import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.domain.ServiceArtifact import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.json.JsonUtils import org.onap.so.client.HttpClient -import org.onap.so.client.HttpClientFactory import org.onap.aaiclient.client.aai.AAIObjectType -import org.onap.aaiclient.client.aai.AAIResourcesClient import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory import org.onap.so.db.request.beans.OperationStatus @@ -56,6 +55,8 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor private ExceptionUtil exceptionUtil = new ExceptionUtil() private JsonUtils jsonUtil = new JsonUtils() private RequestDBUtil requestDBUtil = new RequestDBUtil() + private NssmfAdapterUtils nssmfAdapterUtils = new NssmfAdapterUtils(httpClientFactory, jsonUtil) + private static final Logger LOGGER = LoggerFactory.getLogger( DoDeallocateNSSI.class) @Override @@ -103,7 +104,7 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor * get vendor Info * @param execution */ - void processDecomposition(DelegateExecution execution) { + void processDecomposition(DelegateExecution execution) { LOGGER.debug("*****${PREFIX} start processDecomposition *****") try { @@ -150,26 +151,21 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor deAllocateRequest.setEsrInfo(getEsrInfo(currentNSSI)) ObjectMapper mapper = new ObjectMapper() - String json = mapper.writeValueAsString(deAllocateRequest) - - //Prepare auth for NSSMF - Begin - String nssmfRequest = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint", execution) - nssmfRequest = nssmfRequest + String.format("/api/rest/provMns/v1/NSS/SliceProfiles/%s",profileId) - //nssmfRequest = nssmfRequest + String.format(NssmfAdapterUtil.NSSMI_DEALLOCATE_URL,profileId) - //send request to active NSSI TN option - URL url = new URL(nssmfRequest) - LOGGER.info("deallocate nssmfRequest:${nssmfRequest}, reqBody: ${json}") - - HttpClient httpClient = getHttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL) - Response httpResponse = httpClient.post(json) - checkNssmfResponse(httpResponse, execution) - - NssiResponse nssmfResponse = httpResponse.readEntity(NssiResponse.class) - currentNSSI['jobId']= nssmfResponse.getJobId() ?: "" - currentNSSI['jobProgress'] = 0 - execution.setVariable("currentNSSI", currentNSSI) - - LOGGER.debug("*****${PREFIX} Exit sendRequestToNSSMF *****") + String nssmfRequest = mapper.writeValueAsString(deAllocateRequest) + + String urlStr = String.format("/api/rest/provMns/v1/NSS/SliceProfiles/%s",profileId) + + NssiResponse nssmfResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlStr, nssmfRequest, NssiResponse.class) + if (nssmfResponse != null) { + currentNSSI['jobId']= nssmfResponse.getJobId() ?: "" + currentNSSI['jobProgress'] = 0 + execution.setVariable("currentNSSI", currentNSSI) + + LOGGER.debug("*****${PREFIX} Exit sendRequestToNSSMF *****") + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Response from NSSMF.") + } + } /** @@ -189,48 +185,36 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor jobStatusRequest.setEsrInfo(getEsrInfo(currentNSSI)) ObjectMapper mapper = new ObjectMapper() - String json = mapper.writeValueAsString(jobStatusRequest) - - //Prepare auth for NSSMF - Begin - String nssmfRequest = UrnPropertiesReader.getVariable("mso.adapters.nssmf.endpoint", execution) - nssmfRequest = nssmfRequest + String.format("/api/rest/provMns/v1/NSS/jobs/%s",jobId) - //send request to active NSSI TN option - URL url = new URL(nssmfRequest) - LOGGER.info("get deallocate job status, nssmfRequest:${nssmfRequest}, requestBody: ${json}") - - HttpClient httpClient = getHttpClientFactory().newJsonClient(url, ONAPComponents.EXTERNAL) - Response httpResponse = httpClient.post(json) - checkNssmfResponse(httpResponse, execution) - - JobStatusResponse jobStatusResponse = httpResponse.readEntity(JobStatusResponse.class) - def progress = jobStatusResponse?.getResponseDescriptor()?.getProgress() - if(!progress) - { - LOGGER.error("job progress is null or empty!") - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Job progress from NSSMF.") - } - int oldProgress = currentNSSI['jobProgress'] - int currentProgress = progress + String nssmfRequest = mapper.writeValueAsString(jobStatusRequest) - execution.setVariable("isNSSIDeAllocated", (currentProgress == 100)) - execution.setVariable("isNeedUpdateDB", (oldProgress != currentProgress)) - currentNSSI['jobProgress'] = currentProgress + String urlStr = String.format("/api/rest/provMns/v1/NSS/jobs/%s", jobId) - def statusDescription = jobStatusResponse?.getResponseDescriptor()?.getStatusDescription() - currentNSSI['statusDescription'] = statusDescription + JobStatusResponse jobStatusResponse = nssmfAdapterUtils.sendPostRequestNSSMF(execution, urlStr, nssmfRequest, JobStatusResponse.class) - LOGGER.debug("job status result: nsiId = ${nsiId}, nssiId=${nssiId}, oldProgress=${oldProgress}, progress = ${currentProgress}" ) - } + if (jobStatusResponse != null) { + def progress = jobStatusResponse?.getResponseDescriptor()?.getProgress() + if(!progress) + { + LOGGER.error("job progress is null or empty!") + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Job progress from NSSMF.") + } + int oldProgress = currentNSSI['jobProgress'] + int currentProgress = progress + + execution.setVariable("isNSSIDeAllocated", (currentProgress == 100)) + execution.setVariable("isNeedUpdateDB", (oldProgress != currentProgress)) + currentNSSI['jobProgress'] = currentProgress - private void checkNssmfResponse(Response httpResponse, DelegateExecution execution) { - int responseCode = httpResponse.getStatus() - LOGGER.debug("NSSMF response code is: " + responseCode) + def statusDescription = jobStatusResponse?.getResponseDescriptor()?.getStatusDescription() + currentNSSI['statusDescription'] = statusDescription - if ( responseCode < 200 || responseCode > 204 || !httpResponse.hasEntity()) { - exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Response from NSSMF.") + LOGGER.debug("job status result: nsiId = ${nsiId}, nssiId=${nssiId}, oldProgress=${oldProgress}, progress = ${currentProgress}" ) + + } else { + exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "Received a Bad Response from NSSMF.") } - } + } private EsrInfo getEsrInfo(def currentNSSI) { @@ -305,4 +289,4 @@ class DoDeallocateNSSI extends AbstractServiceTaskProcessor } LOGGER.debug("*****${PREFIX} Exist delSliceProfileFromAAI *****") } -} +}
\ No newline at end of file diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/HandleOrchestrationTask.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/HandleOrchestrationTask.groovy index 89490ff620..0f15717b3c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/HandleOrchestrationTask.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/HandleOrchestrationTask.groovy @@ -103,6 +103,7 @@ class HandleOrchestrationTask extends AbstractServiceTaskProcessor { task.setName(taskName) task.setStatus(taskStatus) task.setIsManual(isManual) + task.setCreatedTime(new Date()) task.setParams(paramJson) ObjectMapper objectMapper = new ObjectMapper() payload = objectMapper.writeValueAsString(task) |