import static java.util.Objects.isNull;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_OWNER_PARAM_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.CLOUD_REGION_PARAM_KEY;
+import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.RESOURCE_ID_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_ID_PARAM_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.SERVICE_INSTANCE_NAME_PARAM_KEY;
import static org.onap.so.cnfm.lcm.model.utils.AdditionalParamsConstants.TENANT_ID_PARAM_KEY;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
import java.util.Optional;
import org.apache.groovy.util.Maps;
import org.onap.logging.filter.base.ONAPComponents;
import org.onap.so.cnfm.lcm.model.AsInstance;
import org.onap.so.cnfm.lcm.model.CreateAsRequest;
import org.onap.so.cnfm.lcm.model.InstantiateAsRequest;
+import org.onap.so.cnfm.lcm.model.AsInfoModificationRequestDeploymentItems;
import org.onap.so.serviceinstancebeans.CloudConfiguration;
import org.onap.so.serviceinstancebeans.ModelInfo;
import org.onap.so.serviceinstancebeans.RequestDetails;
public class CnfInstantiateTask {
private static final String CREATE_AS_REQUEST_OBJECT = "CreateAsRequestObject";
private static final String INSTANTIATE_AS_REQUEST_OBJECT = "InstantiateAsRequest";
+ private static final String CNFM_REQUEST_STATUS_CHECK_URL = "CnfmStatusCheckUrl";
+ private static final String MONITOR_JOB_NAME = "MonitorJobName";
private static final String AS_INSTANCE_ID = "asInstanceid";
private static final Logger LOGGER = LoggerFactory.getLogger(CnfInstantiateTask.class);
private final ExceptionBuilder exceptionUtil;
final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails();
LOGGER.debug("RequestDetails: {}", requestDetails);
- if (isNull(requestDetails) && isNull(requestDetails.getModelInfo())
- && isNull(requestDetails.getRequestInfo()) && isNull(requestDetails.getCloudConfiguration())
- && isNull(generalBuildingBlock)) {
+ if (isNull(requestDetails) || isNull(requestDetails.getModelInfo())
+ || isNull(requestDetails.getRequestInfo())
+ || isNull(requestDetails.getCloudConfiguration()) && isNull(generalBuildingBlock)) {
LOGGER.error("Missing Mandatory attribute from RequestDetails: {} or GeneralBuildingBlock: {}",
requestDetails, generalBuildingBlock);
exceptionUtil.buildAndThrowWorkflowException(execution, 2000,
final ModelInfo modelInfo = requestDetails.getModelInfo();
final CloudConfiguration cloudConfiguration = requestDetails.getCloudConfiguration();
final ServiceInstance serviceInstance = generalBuildingBlock.getServiceInstance();
+ final String resourceId = executeBuildingBlock.getResourceId();
final CreateAsRequest createAsRequest = new CreateAsRequest().asdId(modelInfo.getModelVersionId())
.asInstanceName(requestDetails.getRequestInfo().getInstanceName())
CLOUD_REGION_PARAM_KEY, cloudConfiguration.getLcpCloudRegionId(), TENANT_ID_PARAM_KEY,
cloudConfiguration.getTenantId(), SERVICE_INSTANCE_ID_PARAM_KEY,
serviceInstance.getServiceInstanceId(), SERVICE_INSTANCE_NAME_PARAM_KEY,
- serviceInstance.getServiceInstanceName()));
+ serviceInstance.getServiceInstanceName(), RESOURCE_ID_KEY, resourceId));
LOGGER.debug("Adding CreateAsRequest to execution {}", createAsRequest);
"Unable to invoke CNFM for CreateAsRequest", ONAPComponents.SO);
}
- final AsInstance asInstance = optional.orElseThrow();
+ final AsInstance asInstance =
+ optional.orElseThrow(() -> new NoSuchElementException("AsInstance object is empty"));
execution.setVariable(AS_INSTANCE_ID, asInstance.getAsInstanceid());
LOGGER.debug("Successfully invoked CNFM response: {}", asInstance);
public void createAsInstanceRequest(final BuildingBlockExecution execution) {
try {
LOGGER.debug("Executing createAsInstanceRequest task ...");
-
+ final ExecuteBuildingBlock executeBuildingBlock =
+ (ExecuteBuildingBlock) execution.getVariable("buildingBlock");
+ final RequestDetails requestDetails = executeBuildingBlock.getRequestDetails();
final InstantiateAsRequest instantiateAsRequest = new InstantiateAsRequest();
-
+ if (requestDetails != null && requestDetails.getRequestParameters() != null) {
+ List<Map<String, Object>> userParams = requestDetails.getRequestParameters().getUserParams();
+ if (userParams != null && !userParams.isEmpty()) {
+ List<Object> deploymentItems = new ArrayList<>();
+ List<AsInfoModificationRequestDeploymentItems> deploymentItemsReq = new ArrayList<>();
+ for (Map<String, Object> userParam : userParams) {
+ if (userParam.containsKey("deploymentItems")) {
+ deploymentItems = (ArrayList<Object>) userParam.get("deploymentItems");
+ break;
+ }
+ }
+ for (Object deploymentItem : deploymentItems) {
+ Map<String, Object> deploymentItemMap = (Map<String, Object>) deploymentItem;
+ AsInfoModificationRequestDeploymentItems item = new AsInfoModificationRequestDeploymentItems();
+ item.setDeploymentItemsId(deploymentItemMap.get("deploymentItemsId").toString());
+ item.setLifecycleParameterKeyValues(deploymentItemMap.get("lifecycleParameterKeyValues"));
+ deploymentItemsReq.add(item);
+ }
+ instantiateAsRequest.setDeploymentItems(deploymentItemsReq);
+ }
+ }
LOGGER.debug("Adding InstantiateAsRequest to execution {}", instantiateAsRequest);
execution.setVariable(INSTANTIATE_AS_REQUEST_OBJECT, instantiateAsRequest);
try {
final InstantiateAsRequest instantiateAsRequest = execution.getVariable(INSTANTIATE_AS_REQUEST_OBJECT);
final String asInstanceId = execution.getVariable(AS_INSTANCE_ID);
- cnfmHttpServiceProvider.invokeInstantiateAsRequest(instantiateAsRequest, asInstanceId);
+ Optional<URI> cnfStatusCheckURL =
+ cnfmHttpServiceProvider.invokeInstantiateAsRequest(instantiateAsRequest, asInstanceId);
+ execution.setVariable(CNFM_REQUEST_STATUS_CHECK_URL, cnfStatusCheckURL.orElseThrow());
+ execution.setVariable(MONITOR_JOB_NAME, "Instantiate");
LOGGER.debug("Successfully invoked CNFM instantiate AS request: {}", asInstanceId);
-
} catch (final Exception exception) {
LOGGER.error("Unable to invoke CNFM InstantiateAsRequest", exception);
exceptionUtil.buildAndThrowWorkflowException(execution, 2005, exception);