diff options
author | Marcus G K Williams <marcus.williams@intel.com> | 2018-09-20 17:46:07 -0700 |
---|---|---|
committer | Marcus G K Williams <marcus.williams@intel.com> | 2018-09-20 17:47:41 -0700 |
commit | 937b70dab7c0555b03ae5f3beea81da37e9f9dd5 (patch) | |
tree | 68bac0247c1d60fe8328e1cd2c2f07c6dc95c837 /bpmn/MSOCommonBPMN/src/main/groovy/org | |
parent | bddf97be0012847c858ec0122eb53c291de8b45f (diff) |
Update OofHoming w/ directives
Issue-ID: SO-746
Change-Id: I597f7621a32eeb5b8e92cf80700c60bccdc5e560
Signed-off-by: Marcus G K Williams <marcus.williams@intel.com>
Diffstat (limited to 'bpmn/MSOCommonBPMN/src/main/groovy/org')
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy | 62 | ||||
-rw-r--r-- | bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy | 61 |
2 files changed, 81 insertions, 42 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy index 35e68bb79f..70f91671a8 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofHoming.groovy @@ -24,8 +24,7 @@ import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AaiUtil import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.common.scripts.SDNCAdapterUtils -import org.onap.so.bpmn.core.domain.CloudFlavor + import org.onap.so.bpmn.core.domain.InventoryType import org.onap.so.bpmn.core.domain.Resource import org.onap.so.bpmn.core.domain.ResourceType @@ -33,7 +32,8 @@ import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.domain.Subscriber import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.logger.MsoLogger +import org.onap.so.db.catalog.beans.CloudIdentity +import org.onap.so.db.catalog.beans.CloudSite import org.onap.so.rest.APIResponse import org.onap.so.rest.RESTClient import org.onap.so.rest.RESTConfig @@ -52,7 +52,6 @@ import static org.onap.so.bpmn.common.scripts.GenericUtils.* */ class OofHoming extends AbstractServiceTaskProcessor { - private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, OofHoming.class); ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() OofUtils oofUtils = new OofUtils(this) @@ -114,10 +113,7 @@ class OofHoming extends AbstractServiceTaskProcessor { def authHeader = "" String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution) String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution) - - - String basicAuthValue = utils.encrypt(basicAuth, msokey) if (basicAuthValue != null) { utils.log("DEBUG", "Obtained BasicAuth username and password for OOF Adapter: " + basicAuthValue, @@ -156,8 +152,8 @@ class OofHoming extends AbstractServiceTaskProcessor { execution.setVariable("oofRequest", oofRequest) utils.log("DEBUG", "OOF Request is: " + oofRequest, isDebugEnabled) - String endpoint = UrnPropertiesReader.getVariable("mso.oof.service.agnostic.endpoint", execution); - String host = UrnPropertiesReader.getVariable("mso.oof.service.agnostic.host", execution); + String endpoint = UrnPropertiesReader.getVariable("mso.oof.service.agnostic.endpoint", execution) + String host = UrnPropertiesReader.getVariable("mso.oof.service.agnostic.host", execution) String url = host + endpoint utils.log("DEBUG", "Posting to OOF Url: " + url, isDebugEnabled) @@ -240,30 +236,12 @@ class OofHoming extends AbstractServiceTaskProcessor { } resource.getHomingSolution().setInventoryType(InventoryType.valueOf(inventoryType)) - // TODO Deal with Placement Solutions & Assignment Info here JSONArray assignmentArr = placement.getJSONArray("assignmentInfo") - Integer arrayIndex = 0 - Integer flavorsIndex = null - Boolean foundFlavors = false - String flavors = null - Map<String, String> flavorsMap = null - ArrayList<CloudFlavor> flavorsArrayList = new ArrayList<CloudFlavor>() + String oofDirectives = null assignmentArr.each { element -> JSONObject jsonObject = new JSONObject(element.toString()) - if (jsonUtil.getJsonRawValue(jsonObject.toString(), "key") == "flavors") { - flavors = jsonUtil.getJsonRawValue(jsonObject.toString(), "value") - foundFlavors = true - flavorsIndex = arrayIndex - } else { - arrayIndex += 1 - } - } - if (foundFlavors) { - assignmentArr.remove(flavorsIndex) - flavorsMap = jsonUtil.jsonStringToMap(execution, flavors.toString()) - flavorsMap.each { label, flavor -> - CloudFlavor cloudFlavor = new CloudFlavor(label, flavor) - flavorsArrayList.add(cloudFlavor) + if (jsonUtil.getJsonRawValue(jsonObject.toString(), "key") == "oof_directives") { + oofDirectives = jsonUtil.getJsonRawValue(jsonObject.toString(), "value") } } Map<String, String> assignmentMap = jsonUtil.entryArrayToMap(execution, @@ -272,10 +250,26 @@ class OofHoming extends AbstractServiceTaskProcessor { String cloudRegionId = assignmentMap.get("locationId") resource.getHomingSolution().setCloudOwner(cloudOwner) resource.getHomingSolution().setCloudRegionId(cloudRegionId) - if (flavorsArrayList != null && flavorsArrayList.size != 0) { - resource.getHomingSolution().setFlavors(flavorsArrayList) - execution.setVariable(cloudRegionId + "_flavorList", flavorsArrayList) - utils.log("DEBUG", "***** _flavorList is: " + flavorsArrayList.toString() + + + CloudSite cloudSite = new CloudSite(); + cloudSite.setId(cloudRegionId) + cloudSite.setRegionId(cloudRegionId) + String orchestrator = execution.getVariable("orchestrator") + if ((orchestrator != null) || (orchestrator != "")) { + cloudSite.setOrchestrator(orchestrator) + } + + CloudIdentity cloudIdentity = new CloudIdentity(); + cloudIdentity.setId(cloudRegionId); + cloudIdentity.setIdentityUrl("/api/multicloud /v1/" + cloudOwner + "/" + cloudRegionId + "/infra_workload") + cloudSite.setIdentityService(cloudIdentity); + + // Set cloudsite in catalog DB here + oofUtils.createCloudSiteCatalogDb(cloudSite) + + if (oofDirectives != null && oofDirectives != "") { + resource.getHomingSolution().setOofDirectives(oofDirectives) + utils.log("DEBUG", "***** OofDirectives is: " + oofDirectives + " *****", "true") } diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy index 8ce633845b..d95795906f 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy @@ -23,7 +23,7 @@ package org.onap.so.bpmn.common.scripts import org.camunda.bpm.engine.delegate.DelegateExecution import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor import org.onap.so.bpmn.common.scripts.ExceptionUtil -import org.onap.so.bpmn.common.scripts.MsoUtils +import org.onap.so.bpmn.core.UrnPropertiesReader import org.onap.so.bpmn.core.domain.HomingSolution import org.onap.so.bpmn.core.domain.ModelInfo import org.onap.so.bpmn.core.domain.Resource @@ -33,22 +33,32 @@ import org.onap.so.bpmn.core.domain.ServiceInstance import org.onap.so.bpmn.core.domain.Subscriber import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.logger.MsoLogger - -import java.lang.reflect.Array +import org.onap.so.db.catalog.beans.CloudSite +import org.onap.so.rest.APIResponse +import org.onap.so.rest.RESTClient +import org.onap.so.rest.RESTConfig +import org.springframework.http.HttpEntity +import org.springframework.http.HttpHeaders +import org.springframework.http.HttpMethod +import org.springframework.http.ResponseEntity +import org.springframework.http.client.BufferingClientHttpRequestFactory +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory +import org.springframework.web.client.RestTemplate +import org.springframework.web.util.UriComponentsBuilder + +import javax.ws.rs.core.MediaType +import javax.ws.rs.core.Response +import javax.xml.ws.http.HTTPException import static org.onap.so.bpmn.common.scripts.GenericUtils.* class OofUtils { - private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, OofUtils.class); ExceptionUtil exceptionUtil = new ExceptionUtil() JsonUtils jsonUtil = new JsonUtils() private AbstractServiceTaskProcessor utils - public MsoUtils msoUtils = new MsoUtils() - - public OofUtils(AbstractServiceTaskProcessor taskProcessor) { + OofUtils(AbstractServiceTaskProcessor taskProcessor) { this.utils = taskProcessor } @@ -466,4 +476,39 @@ class OofUtils { if (candidatesJson != "") {candidatesJson = candidatesJson.substring(0, candidatesJson.length() - 1)} return candidatesJson } + /** + * This method creates a cloudsite in catalog database. + * + * @param CloudSite cloudSite + * + * @return void + */ + Void createCloudSiteCatalogDb(CloudSite cloudSite, DelegateExecution execution) { + + String endpoint = UrnPropertiesReader.getVariable("mso.catalog.db.spring.endpoint", execution) + String auth = UrnPropertiesReader.getVariable("mso.db.auth", execution) + String uri = "/cloudSite" + + HttpHeaders headers = new HttpHeaders() + + headers.set(HttpHeaders.AUTHORIZATION, auth) + headers.set(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON) + headers.set(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + + UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(endpoint + uri) + HttpEntity<CloudSite> request = new HttpEntity<CloudSite>(cloudSite, headers) + RESTConfig config = new RESTConfig(endpoint + uri) + RESTClient client = new RESTClient(config).addAuthorizationHeader(auth). + addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + APIResponse response = client.httpPost(request.getBody().toString()) + + int responseCode = response.getStatusCode() + logDebug("CatalogDB response code is: " + responseCode, isDebugEnabled) + String syncResponse = response.getResponseBodyAsString() + logDebug("CatalogDB response is: " + syncResponse, isDebugEnabled) + + if(responseCode != 202){ + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from CatalogDB.") + } + } } |