class VfcManagerSol005 {

    public RestfulResponse instantiateNs(String nsInstanceId, NSResourceInputParameter segInput)
            throws ApplicationException {
        // Call the NFVO or SDNO service to instantiate service
        LOGGER.info("SOL005 instantiate ns -> begin");

        // Step1: Prepare restful parameters and options
        InstantiateNsRequest instantiateNsRequest = new InstantiateNsRequest();

        NsInstantiateReq oRequest = new NsInstantiateReq();
        oRequest.setNsInstanceId(nsInstanceId);
        NsParameters nsParameters = segInput.getNsParameters();

        ArrayList<VnfLocationConstraint> vnfLocationConstraints = new ArrayList<VnfLocationConstraint>();
        for (LocationConstraint locationConstraint : nsParameters.getLocationConstraints()) {
            VnfLocationConstraint vnfLocationConstraint = new VnfLocationConstraint();
            vnfLocationConstraint.setVnfProfileId(locationConstraint.getVnfProfileId());
            vnfLocationConstraint.setLocationConstraints(null);
            vnfLocationConstraints.add(vnfLocationConstraint);

        }
        instantiateNsRequest.setAditionalParamsForNs(nsParameters.getAdditionalParamForNs());
        // Setting FlavourID which is a mandatory paramater to default
        // as UUI is not sending this parameter to so
        instantiateNsRequest.setNsFlavourId("default");
        String instReq = JsonUtil.marshal(instantiateNsRequest);
        LOGGER.info("Request Payload for InstantiateNs: " + instReq);
        // Step2: prepare url and
        String url = getUrl(nsInstanceId, CommonConstant.Step.INSTANTIATE);
        String methodType = CommonConstant.MethodType.POST;
        instanceNfvoMapping = instanceNfvoMappingRepository.findOneByInstanceId(nsInstanceId);

        if (instanceNfvoMapping != null) {

            url = instanceNfvoMapping.getEndpoint() + instanceNfvoMapping.getApiRoot() + url;

        } else {
            throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_INSTANTIATE_NS);

        }
        // Step3: prepare restful parameters and options
        Map<String, String> reqBody = new HashMap<>();
        reqBody.put("terminationTime", LocalDateTime.now().toString());
        RestfulResponse instRsp = restfulUtil.send(url, methodType, instReq);
        ResourceOperationStatus status = new ResourceOperationStatus(segInput.getNsOperationKey().getServiceId(),
                segInput.getNsOperationKey().getOperationId(), segInput.getNsOperationKey().getNodeTemplateUUID());
        ValidateUtil.assertObjectNotNull(instRsp);
        if (!HttpCode.isSucess(instRsp.getStatus())) {
            LOGGER.error("update segment operation status : fail to instantiate ns");
            status.setStatus(RequestsDbConstant.Status.ERROR);
            status.setErrorCode(String.valueOf(instRsp.getStatus()));
            status.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED);
            resourceOperationStatusRepository.save(status);
            throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_INSTANTIATE_NS);
        }
        LOGGER.info("instantiate ns response status is : {}", instRsp.getStatus());
        LOGGER.info("response payload is {}", instRsp.getResponseContent());
        String jobId = null;
        if (instRsp.getStatus() == 202) {
            String jobUri = instRsp.getRespHeaderStr(CommonConstant.JOB_URI);
            LOGGER.info("JOB URI" + jobUri);
            jobId = jobUri.split("/")[4];
            if (ValidateUtil.isStrEmpty(jobId)) {
                LOGGER.error("Invalid jobId from instantiate operation");
                status.setStatus(RequestsDbConstant.Status.ERROR);
                status.setErrorCode(String.valueOf(instRsp.getStatus()));
                status.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED);
                resourceOperationStatusRepository.save(status);
                throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR,
                        DriverExceptionID.INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION);
            }

        } else if (instRsp.getStatus() > 400 && instRsp.getStatus() < 600) {
            LOGGER.error("ERROR while executing instantiateNs request");
            ProblemDetails problemDetails = JsonUtil.unMarshal(instRsp.getResponseContent(), ProblemDetails.class);
            status.setStatus(RequestsDbConstant.Status.ERROR);
            status.setErrorCode(String.valueOf(instRsp.getStatus()));
            status.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED + problemDetails.getDetail());
            resourceOperationStatusRepository.save(status);
            if (instRsp.getStatus() == 406) {
                throw new ApplicationException(HttpCode.NOT_ACCEPTABLE, DriverExceptionID.FAIL_TO_INSTANTIATE_NS);
            } else if (instRsp.getStatus() == 400) {
                throw new ApplicationException(HttpCode.BAD_REQUEST, DriverExceptionID.FAIL_TO_INSTANTIATE_NS);
            } else if (instRsp.getStatus() == 404) {
                throw new ApplicationException(HttpCode.NOT_FOUND, DriverExceptionID.FAIL_TO_INSTANTIATE_NS);
            } else if (instRsp.getStatus() == 409) {
                LOGGER.error("The operation cannot be executed currently,\n"
                        + "due to a conflict with the state of the resource");
                throw new ApplicationException(HttpCode.RESPOND_CONFLICT, DriverExceptionID.FAIL_TO_INSTANTIATE_NS);
            } else if (instRsp.getStatus() == 500) {
                throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR,
                        DriverExceptionID.FAIL_TO_INSTANTIATE_NS);
            } else {
                throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR,
                        DriverExceptionID.FAIL_TO_INSTANTIATE_NS);
            }

        }
        LOGGER.info("Job id is " + jobId);
        LOGGER.info("Nfvo Details" + instanceNfvoMapping.toString());
        LOGGER.info("instantiate ns -> end");
        // Step 3: update segment operation job id
        LOGGER.info("update resource operation status job id -> begin");
        status.setJobId(jobId);
        status.setProgress("100");
        status.setStatusDescription("NS initiation completed.");
        resourceOperationStatusRepository.save(status);
        instanceNfvoMapping.setJobId(jobId);
        instanceNfvoMappingRepository.save(instanceNfvoMapping);
        LOGGER.info("update segment operation job id -> end" + instanceNfvoMapping.toString());
        return instRsp;
    }

    public  VfcManagerSol005();

}