class VfcManagerSol005 {

    public RestfulResponse createNs(NSResourceInputParameter segInput) throws ApplicationException {

        Map<String, String> nfvoDetails;
        // Step1: get service template by node type
        String nsdId = segInput.getNsServiceModelUUID();
        // nsdId for NFVO is "id" in the response, while for SDNO is "servcice template id"
        LOGGER.info("serviceTemplateId is {}, id is {}", nsdId, nsdId);


        LOGGER.info("SOL005 create ns -> begin");
        // Step2: Prepare url and method type
        String url = getUrl(null, CommonConstant.Step.CREATE);
        String methodType = CommonConstant.MethodType.POST;

        // Step3: Prepare restful parameters and options
        CreateNsRequest createNsRequest = new CreateNsRequest();
        createNsRequest.setNsDescription(segInput.getNsServiceDescription());
        createNsRequest.setNsdId(segInput.getNsServiceModelUUID());
        createNsRequest.setNsName(segInput.getNsServiceName());

        String createReq = JsonUtil.marshal(createNsRequest);
        RestfulResponse aaiRestfulResponse = null;
        NsParameters nsParameters = segInput.getNsParameters();
        if (nsParameters.getAdditionalParamForNs().containsKey("orchestrator")) {
            if (nsParameters.getAdditionalParamForNs().get("orchestrator") != null) {
                String nfvo = nsParameters.getAdditionalParamForNs().get("nfvo").toString();
                aaiRestfulResponse = restfulUtil.getNfvoFromAAI(nfvo);
                nfvoDetails = JsonUtil.unMarshal(aaiRestfulResponse.getResponseContent(), Map.class);
                url = nfvoDetails.get("url") + nfvoDetails.get("api-root") + url;

            }
        } else {
            LOGGER.error("Nfvo not present in AAI");
            throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_CREATE_NS);
        }


        // Prepare request header for createNs request.
        Map<String, String> requestHeader = new HashMap<>();
        requestHeader.put("GLOBALCUSTOMERID", segInput.getNsOperationKey().getGlobalSubscriberId());
        requestHeader.put("SERVICETYPE", segInput.getNsOperationKey().getServiceType());

        // Step4: Call NFVO or SDNO lcm to create ns
        LOGGER.info("Request Payload for CreateNs: " + createReq);

        RestfulResponse createRsp = restfulUtil.send(url, methodType, createReq, requestHeader);
        ValidateUtil.assertObjectNotNull(createRsp);
        LOGGER.info("create ns response status is : {}", createRsp.getStatus());
        LOGGER.info("create ns response content is : {}", createRsp.getResponseContent());

        // Step 5: save resource operation information
        ResourceOperationStatus status = new ResourceOperationStatus(segInput.getNsOperationKey().getServiceId(),
                segInput.getNsOperationKey().getOperationId(), segInput.getNsOperationKey().getNodeTemplateUUID());
        status.setStatus(RequestsDbConstant.Status.PROCESSING);
        status = resourceOperationStatusRepository.save(status);
        if (!HttpCode.isSucess(createRsp.getStatus())) {
            LOGGER.error("update segment operation status : fail to create ns");
            status.setProgress("40");
            status.setStatusDescription("NS not created");
            status.setStatus(RequestsDbConstant.Status.ERROR);
            status.setErrorCode(String.valueOf(createRsp.getStatus()));
            resourceOperationStatusRepository.save(status);
            throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_CREATE_NS);
        }
        // TODO: Capture all the content of the response. Currently fetching ID value alone.
        // Should be converted into the NsInstance.class
        @SuppressWarnings("unchecked")
        Map<String, String> rsp = JsonUtil.unMarshal(createRsp.getResponseContent(), Map.class);
        String nsInstanceId = rsp.get(CommonConstant.SOL005_NS_INSTANCE_ID);
        if (ValidateUtil.isStrEmpty(nsInstanceId)) {
            LOGGER.error("Invalid instanceId from create operation");
            throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR,
                    DriverExceptionID.INVALID_RESPONSEE_FROM_CREATE_OPERATION);
        }

        nfvoDetails = JsonUtil.unMarshal(aaiRestfulResponse.getResponseContent(), Map.class);
        instanceNfvoMapping.setInstanceId(nsInstanceId);
        instanceNfvoMapping.setPassword(nfvoDetails.get("password"));
        instanceNfvoMapping.setUsername(nfvoDetails.get("userName"));
        instanceNfvoMapping.setNfvoName(nfvoDetails.get("nfvoId"));
        instanceNfvoMapping.setEndpoint(nfvoDetails.get("url"));
        instanceNfvoMapping.setApiRoot(nfvoDetails.get("api-root"));
        instanceNfvoMappingRepository.save(instanceNfvoMapping);
        LOGGER.info("create ns -> end");
        LOGGER.info("save segment and operaton info -> begin");
        // Step 6: add relation between service and NS
        AaiUtil.addRelation(segInput.getNsOperationKey().getGlobalSubscriberId(),
                segInput.getNsOperationKey().getServiceType(), segInput.getNsOperationKey().getServiceId(),
                nsInstanceId);
        LOGGER.info("save segment and operation info -> end");
        return createRsp;
    }

    public  VfcManagerSol005();

}