+/*-\r
+ * ============LICENSE_START=======================================================\r
+ * ONAP - SO\r
+ * ================================================================================\r
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
+ * ================================================================================\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ============LICENSE_END=========================================================\r
+ */\r
+\r
package org.openecomp.mso.bpmn.common.scripts\r
\r
-import org.camunda.bpm.engine.runtime.Execution\r
+import org.camunda.bpm.engine.delegate.DelegateExecution\r
+import org.json.JSONArray\r
import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil\r
import org.openecomp.mso.bpmn.common.scripts.MsoUtils\r
*\r
* @author cb645j\r
*/\r
- public String buildRequest(Execution execution, String requestId, ServiceDecomposition decomposition, Subscriber subscriber, String homingParams){\r
+ public String buildRequest(DelegateExecution execution, String requestId, ServiceDecomposition decomposition, Subscriber subscriber, String homingParams){\r
def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
utils.log("DEBUG", "Started Building Sniro Request", isDebugEnabled)\r
def callbackUrl = utils.createWorkflowMessageAdapterCallbackURL(execution, "SNIROResponse", requestId)\r
orderInfo = StringUtils.normalizeSpace(orderInfo)\r
}\r
\r
+ //Determine RequestType\r
+ //TODO Figure out better way to determine this\r
+ String requestType = "initial"\r
+ List<Resource> resources = decomposition.getServiceResources()\r
+ for(Resource r:resources){\r
+ HomingSolution currentSolution = r.getCurrentHomingSolution()\r
+ if(currentSolution != null){\r
+ requestType = "speed changed"\r
+ }\r
+ }\r
+\r
+ int timeoutSeconds = 1800\r
+ String timeout = execution.getVariable("timeout")\r
+ if(isNotBlank(timeout)){\r
+ String subT = timeout.substring(2, timeout.length() - 1)\r
+ int timeoutInt = Integer.parseInt(subT)\r
+ timeoutSeconds = timeoutInt * 60\r
+ }\r
+\r
//Demands\r
String placementDemands = ""\r
StringBuilder sb = new StringBuilder()\r
utils.log("DEBUG", "Allotted Resources List is empty - will try to get service VNFs instead.", isDebugEnabled)\r
resourceList = decomposition.getServiceVnfs()\r
}\r
- \r
+\r
if(resourceList.isEmpty() || resourceList == null){\r
utils.log("DEBUG", "Resources List is Empty", isDebugEnabled)\r
}else{\r
def resouceModelType = resourceModelInfo.getModelType()\r
def tenantId = "" //Optional\r
def tenantName = "" //Optional\r
- \r
+\r
+\r
+ String existingPlacement = ""\r
+ HomingSolution currentPlacement = resource.getCurrentHomingSolution()\r
+ if(currentPlacement != null){\r
+ String homedServiceInstanceId = currentPlacement.getServiceInstanceId()\r
+ existingPlacement =\r
+ ""","existingPlacement": {\r
+ "serviceInstanceId": "${homedServiceInstanceId}"\r
+ }"""\r
+ }\r
+\r
+\r
String demand =\r
"""{\r
"resourceInstanceType": "${resourceInstanceType}",\r
},\r
"tenantId": "${tenantId}",\r
"tenantName": "${tenantName}"\r
+ ${existingPlacement}\r
},"""\r
- \r
+\r
placementDemands = sb.append(demand)\r
}\r
placementDemands = placementDemands.substring(0, placementDemands.length() - 1);\r
sb = new StringBuilder()\r
if(vnfResourceList.isEmpty() || vnfResourceList == null){\r
utils.log("DEBUG", "Vnf Resources List is Empty", isDebugEnabled)\r
- }else{ \r
+ }else{\r
for(VnfResource vnfResource:vnfResourceList){\r
ModelInfo vnfResourceModelInfo = vnfResource.getModelInfo()\r
ResourceInstance vnfResourceInstance = vnfResource.getResourceInstance()\r
def resouceModelVersion = vnfResourceModelInfo.getModelVersion()\r
def resouceModelVersionId = vnfResourceModelInfo.getModelUuid()\r
def resouceModelType = vnfResourceModelInfo.getModelType()\r
- \r
+\r
+ String curentLicenseJson = ""\r
+ HomingSolution currentSol = vnfResource.getCurrentHomingSolution()\r
+ if(currentSol != null){\r
+ JSONArray entitlementPoolList = currentSol.getLicense().getEntitlementPoolListAsString()\r
+ JSONArray licenseKeyGroupList = currentSol.getLicense().getLicenseKeyGroupListAsString()\r
+ curentLicenseJson =\r
+ """ ,"existingLicense": [\r
+ {\r
+ "entitlementPoolUUID":\r
+ ${entitlementPoolList},\r
+ "licenseKeyGroupUUID":\r
+ ${licenseKeyGroupList}\r
+\r
+ }\r
+ ]"""\r
+ }\r
+\r
String demand =\r
"""{\r
"resourceInstanceType": "${resourceInstanceType}",\r
"modelVersionId": "${resouceModelVersionId}",\r
"modelType": "${resouceModelType}"\r
}\r
+ ${curentLicenseJson}\r
},"""\r
- \r
+\r
licenseDemands = sb.append(demand)\r
}\r
licenseDemands = licenseDemands.substring(0, licenseDemands.length() - 1);\r
}\r
- \r
+\r
String request =\r
"""{\r
"requestInfo": {\r
"requestId": "${requestId}",\r
"callbackUrl": "${callbackUrl}",\r
"sourceId": "mso",\r
+ "requestType": "${requestType}",\r
"optimizer": [\r
"placement",\r
"license"\r
],\r
"numSolutions": 1,\r
- "timeout": 600\r
+ "timeout": ${timeoutSeconds}\r
},\r
"placementInfo": {\r
"serviceModelInfo": {\r
*\r
* @author cb645j\r
*/\r
- public void validateCallbackResponse(Execution execution, String response){\r
+ public void validateCallbackResponse(DelegateExecution execution, String response){\r
def isDebugEnabled = execution.getVariable("isDebugLogEnabled")\r
String placements = ""\r
if(isBlank(response)){\r
exceptionUtil.buildAndThrowWorkflowException(execution, 5000, "Sniro Async Callback Response is Empty")\r
}else{\r
- if(JsonUtils.jsonElementExist(response, "solutionInfo.placement")){\r
- placements = jsonUtil.getJsonValue(response, "solutionInfo.placement")\r
+ if(JsonUtils.jsonElementExist(response, "solutionInfo.placementInfo")){\r
+ placements = jsonUtil.getJsonValue(response, "solutionInfo.placementInfo")\r
if(isBlank(placements) || placements.equalsIgnoreCase("[]")){\r
String statusMessage = jsonUtil.getJsonValue(response, "statusMessage")\r
if(isBlank(statusMessage)){\r