diff options
author | Seshu-Kumar-M <seshu.kumar.m@huawei.com> | 2017-10-11 20:39:35 +0800 |
---|---|---|
committer | Seshu Kumar M <seshu.kumar.m@huawei.com> | 2017-10-11 13:27:17 +0000 |
commit | f86960874497f005079c9e595b5e9e2eb0a815d1 (patch) | |
tree | 59edf77900890ad64aaf9327d5191857c3766f20 /adapters/mso-vfc-adapter/src/main/java/org | |
parent | ad6fc43208ddfacea150d51e4ec2b28d48fe5f0d (diff) |
Imp Modules refactored for the readthedocs
Signed-off-by: Seshu-Kumar-M <seshu.kumar.m@huawei.com>
IssueId: SO-209
Change-Id: Ie1b553863f824497fbe7381f66bc1581310702af
Diffstat (limited to 'adapters/mso-vfc-adapter/src/main/java/org')
7 files changed, 814 insertions, 806 deletions
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiUtil.java index 29f27d05e9..719385f97f 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiUtil.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/AaiUtil.java @@ -22,25 +22,24 @@ package org.openecomp.mso.adapters.vfc; import org.openecomp.mso.adapters.vfc.model.RestfulResponse; /** - * Implement class of operating aai database table - * <br> + * Implement class of operating aai database table <br> * <p> * </p> * * @author - * @version ONAP Amsterdam Release 2017-08-28 + * @version ONAP Amsterdam Release 2017-08-28 */ public class AaiUtil { - public static RestfulResponse addRelation(String globalSubsriberId, String serviceType, String serviceInstanceId, String resourceInstanceId) - { - //sent rest to aai to add relation for service and ns. - return null; - } - - public static RestfulResponse removeRelation(String globalSubsriberId, String serviceType, String serviceInstanceId ,String resourceInstanceId) - { - //sent rest to aai to remove relation between service an ns. - return null; - } + public static RestfulResponse addRelation(String globalSubsriberId, String serviceType, + String serviceInstanceId, String resourceInstanceId) { + // sent rest to aai to add relation for service and ns. + return null; + } + + public static RestfulResponse removeRelation(String globalSubsriberId, String serviceType, + String serviceInstanceId, String resourceInstanceId) { + // sent rest to aai to remove relation between service an ns. + return null; + } } diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java index 52286fd3ac..6c2ab4d081 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java @@ -41,8 +41,7 @@ import org.openecomp.mso.adapters.vfc.util.ValidateUtil; import org.openecomp.mso.logger.MsoLogger; /** - * The rest class for VF-c Adapter - * <br> + * The rest class for VF-c Adapter <br> * <p> * </p> * @@ -52,162 +51,161 @@ import org.openecomp.mso.logger.MsoLogger; @Path("/vfcadapter/v1") public class VfcAdapterRest { - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); - private final VfcManager driverMgr = new VfcManager(); + private final VfcManager driverMgr = new VfcManager(); - public VfcAdapterRest() { + public VfcAdapterRest() { - } + } - /** - * Create a NS - * <br> - * - * @param servletReq the http request - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/ns") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response createNfvoNs(HttpServletRequest servletReq) { - // Step 1: get parameters from request for current node - try { - String body = RestfulUtil.getRequestBody(servletReq); - ValidateUtil.assertObjectNotNull(body); - LOGGER.debug("body from request is {}" + body); - NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class); - RestfulResponse rsp = driverMgr.createNs(nsInput); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } + /** + * Create a NS <br> + * + * @param servletReq the http request + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/ns") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response createNfvoNs(HttpServletRequest servletReq) { + // Step 1: get parameters from request for current node + try { + String body = RestfulUtil.getRequestBody(servletReq); + ValidateUtil.assertObjectNotNull(body); + LOGGER.debug("body from request is {}" + body); + NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class); + RestfulResponse rsp = driverMgr.createNs(nsInput); + return buildResponse(rsp); + } catch (ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); } + } - /** - * Delete NS instance<br> - * - * @param servletReq http request - * @return response - * @since ONAP Amsterdam Release - */ - @DELETE - @Path("/ns/{nsInstanceId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response deleteNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) { - try { - // Step 1: get parameters from request for current node - String body = RestfulUtil.getRequestBody(servletReq); - ValidateUtil.assertObjectNotNull(body); - LOGGER.debug("body from request is {}" + body); - NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class); - RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } + /** + * Delete NS instance<br> + * + * @param servletReq http request + * @return response + * @since ONAP Amsterdam Release + */ + @DELETE + @Path("/ns/{nsInstanceId}") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response deleteNfvoNs(HttpServletRequest servletReq, + @PathParam("nsInstanceId") String nsInstanceId) { + try { + // Step 1: get parameters from request for current node + String body = RestfulUtil.getRequestBody(servletReq); + ValidateUtil.assertObjectNotNull(body); + LOGGER.debug("body from request is {}" + body); + NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class); + RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId); + return buildResponse(rsp); + } catch (ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); } + } - /** - * Query Operation job status - * <br> - * - * @param servletReq The Http Request - * @param jobId The job id - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/jobs/{jobId}") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response queryNfvoJobStatus(HttpServletRequest servletReq, @PathParam("jobId") String jobId) { - try { - ValidateUtil.assertObjectNotNull(jobId); - String body = RestfulUtil.getRequestBody(servletReq); - ValidateUtil.assertObjectNotNull(body); - LOGGER.debug("body from request is {}" + body); - NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class); + /** + * Query Operation job status <br> + * + * @param servletReq The Http Request + * @param jobId The job id + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/jobs/{jobId}") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response queryNfvoJobStatus(HttpServletRequest servletReq, + @PathParam("jobId") String jobId) { + try { + ValidateUtil.assertObjectNotNull(jobId); + String body = RestfulUtil.getRequestBody(servletReq); + ValidateUtil.assertObjectNotNull(body); + LOGGER.debug("body from request is {}" + body); + NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class); - RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } + RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId); + return buildResponse(rsp); + } catch (ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); } + } - /** - * Instantiate NS instance - * <br> - * - * @param servletReq The http request - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/ns/{nsInstanceId}/instantiate") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response instantiateNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) { - String body = RestfulUtil.getRequestBody(servletReq); - try { - ValidateUtil.assertObjectNotNull(body); - LOGGER.debug("body from request is {}" + body); - NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class); - RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } + /** + * Instantiate NS instance <br> + * + * @param servletReq The http request + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/ns/{nsInstanceId}/instantiate") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response instantiateNfvoNs(HttpServletRequest servletReq, + @PathParam("nsInstanceId") String nsInstanceId) { + String body = RestfulUtil.getRequestBody(servletReq); + try { + ValidateUtil.assertObjectNotNull(body); + LOGGER.debug("body from request is {}" + body); + NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class); + RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput); + return buildResponse(rsp); + } catch (ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); } + } - /** - * Terminate NS instance - * <br> - * - * @param servletReq The http request - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - @POST - @Path("/ns/{nsInstanceId}/terminate") - @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) - public Response terminateNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) { - try { - ValidateUtil.assertObjectNotNull(nsInstanceId); - String body = RestfulUtil.getRequestBody(servletReq); - ValidateUtil.assertObjectNotNull(body); - LOGGER.debug("body from request is {}" + body); - NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class); - RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId); - return buildResponse(rsp); - } catch(ApplicationException e) { - LOGGER.debug("ApplicationException: ", e); - return e.buildErrorResponse(); - } + /** + * Terminate NS instance <br> + * + * @param servletReq The http request + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + @POST + @Path("/ns/{nsInstanceId}/terminate") + @Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON}) + public Response terminateNfvoNs(HttpServletRequest servletReq, + @PathParam("nsInstanceId") String nsInstanceId) { + try { + ValidateUtil.assertObjectNotNull(nsInstanceId); + String body = RestfulUtil.getRequestBody(servletReq); + ValidateUtil.assertObjectNotNull(body); + LOGGER.debug("body from request is {}" + body); + NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class); + RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId); + return buildResponse(rsp); + } catch (ApplicationException e) { + LOGGER.debug("ApplicationException: ", e); + return e.buildErrorResponse(); } + } - /** - * build response from restful response - * <br> - * - * @param rsp general response object - * @return - * @since ONAP Amsterdam Release - */ - private Response buildResponse(RestfulResponse rsp) { - ResponseBuilder rspBuilder = Response.status(rsp.getStatus()); - rspBuilder.entity(rsp.getResponseContent()); - return rspBuilder.build(); - } + /** + * build response from restful response <br> + * + * @param rsp general response object + * @return + * @since ONAP Amsterdam Release + */ + private Response buildResponse(RestfulResponse rsp) { + ResponseBuilder rspBuilder = Response.status(rsp.getStatus()); + rspBuilder.entity(rsp.getResponseContent()); + return rspBuilder.build(); + } } diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java index 8c503aa43e..78ec50f9f0 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java @@ -46,8 +46,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * VF-C Manager - * <br> + * VF-C Manager <br> * <p> * </p> * @@ -56,355 +55,364 @@ import org.slf4j.LoggerFactory; */ public class VfcManager { - private static final Logger LOGGER = LoggerFactory.getLogger(VfcManager.class); - - /** - * nfvo url map - */ - private static Map<String, String> nfvoUrlMap; - - static { - nfvoUrlMap = new HashMap<>(); - nfvoUrlMap.put(Step.CREATE, CommonConstant.NFVO_CREATE_URL); - nfvoUrlMap.put(Step.INSTANTIATE, CommonConstant.NFVO_INSTANTIATE_URL); - nfvoUrlMap.put(Step.TERMINATE, CommonConstant.NFVO_TERMINATE_URL); - nfvoUrlMap.put(Step.DELETE, CommonConstant.NFVO_DELETE_URL); - nfvoUrlMap.put(Step.QUERY, CommonConstant.NFVO_QUERY_URL); + private static final Logger LOGGER = LoggerFactory.getLogger(VfcManager.class); + + /** + * nfvo url map + */ + private static Map<String, String> nfvoUrlMap; + + static { + nfvoUrlMap = new HashMap<>(); + nfvoUrlMap.put(Step.CREATE, CommonConstant.NFVO_CREATE_URL); + nfvoUrlMap.put(Step.INSTANTIATE, CommonConstant.NFVO_INSTANTIATE_URL); + nfvoUrlMap.put(Step.TERMINATE, CommonConstant.NFVO_TERMINATE_URL); + nfvoUrlMap.put(Step.DELETE, CommonConstant.NFVO_DELETE_URL); + nfvoUrlMap.put(Step.QUERY, CommonConstant.NFVO_QUERY_URL); + } + + public VfcManager() { + + } + + /** + * create network service <br> + * + * @param segInput input parameters for current node from http request + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse createNs(NSResourceInputParameter segInput) throws ApplicationException { + + // Step1: get service template by node type + String nsdId = segInput.getNsOperationKey().getNodeTemplateUUID(); + // nsdId for NFVO is "id" in the response, while for SDNO is "servcice template id" + LOGGER.info("serviceTemplateId is {}, id is {}", nsdId); + + LOGGER.info("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 + NsCreateReq oRequest = new NsCreateReq(); + oRequest.setNsdId(nsdId); + oRequest.setNsName(segInput.getNsServiceName()); + oRequest.setDescription(segInput.getNsServiceDescription()); + String createReq = JsonUtil.marshal(oRequest); + + // Step4: Call NFVO or SDNO lcm to create ns + RestfulResponse createRsp = RestfulUtil.send(url, methodType, createReq); + ValidateUtil.assertObjectNotNull(createRsp); + LOGGER.info("create ns response status is : {}", createRsp.getStatus()); + LOGGER.info("create ns response content is : {}", createRsp.getResponseContent()); + @SuppressWarnings("unchecked") + Map<String, String> rsp = JsonUtil.unMarshal(createRsp.getResponseContent(), Map.class); + String nsInstanceId = rsp.get(CommonConstant.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); } - - public VfcManager() { - + LOGGER.info("create ns -> end"); + LOGGER.info("save segment and operaton info -> begin"); + // Step 5: add relation between service and NS + AaiUtil.addRelation(segInput.getNsOperationKey().getGlobalSubscriberId(), + segInput.getNsOperationKey().getServiceType(), segInput.getNsOperationKey().getServiceId(), + nsInstanceId); + + // Step 6: save resource operation information + ResourceOperationStatus nsOperInfo = (RequestsDatabase.getInstance()) + .getResourceOperationStatus(segInput.getNsOperationKey().getServiceId(), + segInput.getNsOperationKey().getOperationId(), + segInput.getNsOperationKey().getNodeTemplateUUID()); + nsOperInfo.setStatus(RequestsDbConstant.Status.PROCESSING); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + + if (!HttpCode.isSucess(createRsp.getStatus())) { + LOGGER.error("update segment operation status : fail to create ns"); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setErrorCode(String.valueOf(createRsp.getStatus())); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_CREATE_NS); } - - /** - * create network service - * <br> - * - * @param segInput input parameters for current node from http request - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse createNs(NSResourceInputParameter segInput) throws ApplicationException { - - // Step1: get service template by node type - String nsdId = segInput.getNsOperationKey().getNodeTemplateUUID(); - // nsdId for NFVO is "id" in the response, while for SDNO is "servcice template id" - LOGGER.info("serviceTemplateId is {}, id is {}", nsdId); - - LOGGER.info("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 - NsCreateReq oRequest = new NsCreateReq(); - oRequest.setNsdId(nsdId); - oRequest.setNsName(segInput.getNsServiceName()); - oRequest.setDescription(segInput.getNsServiceDescription()); - String createReq = JsonUtil.marshal(oRequest); - - // Step4: Call NFVO or SDNO lcm to create ns - RestfulResponse createRsp = RestfulUtil.send(url, methodType, createReq); - ValidateUtil.assertObjectNotNull(createRsp); - LOGGER.info("create ns response status is : {}", createRsp.getStatus()); - LOGGER.info("create ns response content is : {}", createRsp.getResponseContent()); - @SuppressWarnings("unchecked") - Map<String, String> rsp = JsonUtil.unMarshal(createRsp.getResponseContent(), Map.class); - String nsInstanceId = rsp.get(CommonConstant.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); - } - LOGGER.info("create ns -> end"); - LOGGER.info("save segment and operaton info -> begin"); - // Step 5: add relation between service and NS - AaiUtil.addRelation(segInput.getNsOperationKey().getGlobalSubscriberId(), - segInput.getNsOperationKey().getServiceType(), segInput.getNsOperationKey().getServiceId(), - nsInstanceId); - - // Step 6: save resource operation information - ResourceOperationStatus nsOperInfo = (RequestsDatabase.getInstance()).getResourceOperationStatus( - segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(), - segInput.getNsOperationKey().getNodeTemplateUUID()); - nsOperInfo.setStatus(RequestsDbConstant.Status.PROCESSING); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - - if(!HttpCode.isSucess(createRsp.getStatus())) { - LOGGER.error("update segment operation status : fail to create ns"); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setErrorCode(String.valueOf(createRsp.getStatus())); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_CREATE_NS); - } - LOGGER.info("save segment and operation info -> end"); - return createRsp; + LOGGER.info("save segment and operation info -> end"); + return createRsp; + } + + /** + * delete network service <br> + * + * @param nsOperationKey The operation key of the NS resource + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse deleteNs(NsOperationKey nsOperationKey, String nsInstanceId) + throws ApplicationException { + LOGGER.info("delete ns -> begin"); + // Step1: prepare url and methodType + String url = getUrl(nsInstanceId, CommonConstant.Step.DELETE); + String methodType = CommonConstant.MethodType.DELETE; + + // Step2: prepare restful parameters and options + RestfulResponse deleteRsp = RestfulUtil.send(url, methodType, ""); + ValidateUtil.assertObjectNotNull(deleteRsp); + LOGGER.info("delete ns response status is : {}", deleteRsp.getStatus()); + LOGGER.info("delete ns response content is : {}", deleteRsp.getResponseContent()); + LOGGER.info("delete ns -> end"); + ResourceOperationStatus nsOperInfo = + (RequestsDatabase.getInstance()).getResourceOperationStatus(nsOperationKey.getServiceId(), + nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); + if (!HttpCode.isSucess(deleteRsp.getStatus())) { + LOGGER.error("fail to delete ns"); + + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setErrorCode(String.valueOf(deleteRsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_DELETE_NS); } - /** - * delete network service - * <br> - * - * @param nsOperationKey The operation key of the NS resource - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse deleteNs(NsOperationKey nsOperationKey, String nsInstanceId) throws ApplicationException { - LOGGER.info("delete ns -> begin"); - // Step1: prepare url and methodType - String url = getUrl(nsInstanceId, CommonConstant.Step.DELETE); - String methodType = CommonConstant.MethodType.DELETE; - - // Step2: prepare restful parameters and options - RestfulResponse deleteRsp = RestfulUtil.send(url, methodType, ""); - ValidateUtil.assertObjectNotNull(deleteRsp); - LOGGER.info("delete ns response status is : {}", deleteRsp.getStatus()); - LOGGER.info("delete ns response content is : {}", deleteRsp.getResponseContent()); - LOGGER.info("delete ns -> end"); - ResourceOperationStatus nsOperInfo = (RequestsDatabase.getInstance()).getResourceOperationStatus( - nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); - if(!HttpCode.isSucess(deleteRsp.getStatus())) { - LOGGER.error("fail to delete ns"); - - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setErrorCode(String.valueOf(deleteRsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_DELETE_NS); - } - - // Step3: remove relation info between service and ns - AaiUtil.removeRelation(nsOperationKey.getGlobalSubscriberId(), nsOperationKey.getServiceType(), - nsOperationKey.getServiceId(), nsInstanceId); - LOGGER.info("delete segment information -> end"); - - // Step4: update service segment operation status - nsOperInfo.setStatus(RequestsDbConstant.Status.FINISHED); - nsOperInfo.setErrorCode(String.valueOf(deleteRsp.getStatus())); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - LOGGER.info("update segment operaton status for delete -> end"); - - return deleteRsp; - + // Step3: remove relation info between service and ns + AaiUtil.removeRelation(nsOperationKey.getGlobalSubscriberId(), nsOperationKey.getServiceType(), + nsOperationKey.getServiceId(), nsInstanceId); + LOGGER.info("delete segment information -> end"); + + // Step4: update service segment operation status + nsOperInfo.setStatus(RequestsDbConstant.Status.FINISHED); + nsOperInfo.setErrorCode(String.valueOf(deleteRsp.getStatus())); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + LOGGER.info("update segment operaton status for delete -> end"); + + return deleteRsp; + + } + + /** + * instantiate network service <br> + * + * @param nsInstanceId The NS instance id + * @param segInput input parameters for current node from http request + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse instantiateNs(String nsInstanceId, NSResourceInputParameter segInput) + throws ApplicationException { + // Call the NFVO or SDNO service to instantiate service + LOGGER.info("instantiate ns -> begin"); + + // Step1: Prepare restful parameters and options + NsInstantiateReq oRequest = new NsInstantiateReq(); + oRequest.setNsInstanceId(nsInstanceId); + NsParameters nsParameters = segInput.getNsParameters(); + oRequest.setLocationConstraints(nsParameters.getLocationConstraints()); + oRequest.setAdditionalParamForNs(nsParameters.getAdditionalParamForNs()); + String instReq = JsonUtil.marshal(oRequest); + // Step2: prepare url and + String url = getUrl(nsInstanceId, CommonConstant.Step.INSTANTIATE); + String methodType = CommonConstant.MethodType.POST; + + RestfulResponse instRsp = RestfulUtil.send(url, methodType, instReq); + ValidateUtil.assertObjectNotNull(instRsp); + LOGGER.info("instantiate ns response status is : {}", instRsp.getStatus()); + LOGGER.info("instantiate ns response content is : {}", instRsp.getResponseContent()); + ValidateUtil.assertObjectNotNull(instRsp.getResponseContent()); + @SuppressWarnings("unchecked") + Map<String, String> rsp = JsonUtil.unMarshal(instRsp.getResponseContent(), Map.class); + String jobId = rsp.get(CommonConstant.JOB_ID); + ResourceOperationStatus nsOperInfo = (RequestsDatabase.getInstance()) + .getResourceOperationStatus(segInput.getNsOperationKey().getServiceId(), + segInput.getNsOperationKey().getOperationId(), + segInput.getNsOperationKey().getNodeTemplateUUID()); + if (ValidateUtil.isStrEmpty(jobId)) { + LOGGER.error("Invalid jobId from instantiate operation"); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setErrorCode(String.valueOf(instRsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION); } - - /** - * instantiate network service - * <br> - * - * @param nsInstanceId The NS instance id - * @param segInput input parameters for current node from http request - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse instantiateNs(String nsInstanceId, NSResourceInputParameter segInput) - throws ApplicationException { - // Call the NFVO or SDNO service to instantiate service - LOGGER.info("instantiate ns -> begin"); - - // Step1: Prepare restful parameters and options - NsInstantiateReq oRequest = new NsInstantiateReq(); - oRequest.setNsInstanceId(nsInstanceId); - NsParameters nsParameters = segInput.getNsParameters(); - oRequest.setLocationConstraints(nsParameters.getLocationConstraints()); - oRequest.setAdditionalParamForNs(nsParameters.getAdditionalParamForNs()); - String instReq = JsonUtil.marshal(oRequest); - // Step2: prepare url and - String url = getUrl(nsInstanceId, CommonConstant.Step.INSTANTIATE); - String methodType = CommonConstant.MethodType.POST; - - RestfulResponse instRsp = RestfulUtil.send(url, methodType, instReq); - ValidateUtil.assertObjectNotNull(instRsp); - LOGGER.info("instantiate ns response status is : {}", instRsp.getStatus()); - LOGGER.info("instantiate ns response content is : {}", instRsp.getResponseContent()); - ValidateUtil.assertObjectNotNull(instRsp.getResponseContent()); - @SuppressWarnings("unchecked") - Map<String, String> rsp = JsonUtil.unMarshal(instRsp.getResponseContent(), Map.class); - String jobId = rsp.get(CommonConstant.JOB_ID); - ResourceOperationStatus nsOperInfo = (RequestsDatabase.getInstance()).getResourceOperationStatus( - segInput.getNsOperationKey().getServiceId(), segInput.getNsOperationKey().getOperationId(), - segInput.getNsOperationKey().getNodeTemplateUUID()); - if(ValidateUtil.isStrEmpty(jobId)) { - LOGGER.error("Invalid jobId from instantiate operation"); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setErrorCode(String.valueOf(instRsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION); - } - LOGGER.info("instantiate ns -> end"); - - if(!HttpCode.isSucess(instRsp.getStatus())) { - LOGGER.error("update segment operation status : fail to instantiate ns"); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setErrorCode(String.valueOf(instRsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_INSTANTIATE_NS); - } - - // Step 3: update segment operation job id - LOGGER.info("update resource operation status job id -> begin"); - nsOperInfo.setJobId(jobId); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - LOGGER.info("update segment operation job id -> end"); - - return instRsp; + LOGGER.info("instantiate ns -> end"); + + if (!HttpCode.isSucess(instRsp.getStatus())) { + LOGGER.error("update segment operation status : fail to instantiate ns"); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setErrorCode(String.valueOf(instRsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.INSTANTIATE_NS_FAILED); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_INSTANTIATE_NS); } - /** - * terminate network service - * <br> - * - * @param nsOperationKey The operation key for NS resource - * @param nsInstanceId The NS instance id - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse terminateNs(NsOperationKey nsOperationKey, String nsInstanceId) throws ApplicationException { - // Step1: save segment operation info for delete process - LOGGER.info("save segment operation for delete process"); - ResourceOperationStatus nsOperInfo = (RequestsDatabase.getInstance()).getResourceOperationStatus( - nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); - nsOperInfo.setStatus(RequestsDbConstant.Status.PROCESSING); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - - LOGGER.info("terminate ns -> begin"); - // Step2: prepare url and method type - String url = getUrl(nsInstanceId, CommonConstant.Step.TERMINATE); - String methodType = CommonConstant.MethodType.POST; - - // Step3: prepare restful parameters and options - Map<String, String> reqBody = new HashMap<>(); - reqBody.put("nsInstanceId", nsInstanceId); - reqBody.put("terminationType", "graceful"); - reqBody.put("gracefulTerminationTimeout", "60"); - - // Step4: Call the NFVO or SDNO service to terminate service - RestfulResponse terminateRsp = RestfulUtil.send(url, methodType, JsonUtil.marshal(reqBody)); - ValidateUtil.assertObjectNotNull(terminateRsp); - LOGGER.info("terminate ns response status is : {}", terminateRsp.getStatus()); - LOGGER.info("terminate ns response content is : {}", terminateRsp.getResponseContent()); - @SuppressWarnings("unchecked") - Map<String, String> rsp = JsonUtil.unMarshal(terminateRsp.getResponseContent(), Map.class); - String jobId = rsp.get(CommonConstant.JOB_ID); - if(ValidateUtil.isStrEmpty(jobId)) { - LOGGER.error("Invalid jobId from terminate operation"); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setErrorCode(String.valueOf(terminateRsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, - DriverExceptionID.INVALID_RESPONSE_FROM_TERMINATE_OPERATION); - } - LOGGER.info("terminate ns -> end"); - - // Step 3: update segment operation - if(!HttpCode.isSucess(terminateRsp.getStatus())) { - LOGGER.error("fail to instantiate ns"); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setErrorCode(String.valueOf(terminateRsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_TERMINATE_NS); - } - LOGGER.info("update segment job id -> begin"); - nsOperInfo.setJobId(jobId); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - LOGGER.info("update segment job id -> end"); - - return terminateRsp; + // Step 3: update segment operation job id + LOGGER.info("update resource operation status job id -> begin"); + nsOperInfo.setJobId(jobId); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + LOGGER.info("update segment operation job id -> end"); + + return instRsp; + } + + /** + * terminate network service <br> + * + * @param nsOperationKey The operation key for NS resource + * @param nsInstanceId The NS instance id + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse terminateNs(NsOperationKey nsOperationKey, String nsInstanceId) + throws ApplicationException { + // Step1: save segment operation info for delete process + LOGGER.info("save segment operation for delete process"); + ResourceOperationStatus nsOperInfo = + (RequestsDatabase.getInstance()).getResourceOperationStatus(nsOperationKey.getServiceId(), + nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); + nsOperInfo.setStatus(RequestsDbConstant.Status.PROCESSING); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + + LOGGER.info("terminate ns -> begin"); + // Step2: prepare url and method type + String url = getUrl(nsInstanceId, CommonConstant.Step.TERMINATE); + String methodType = CommonConstant.MethodType.POST; + + // Step3: prepare restful parameters and options + Map<String, String> reqBody = new HashMap<>(); + reqBody.put("nsInstanceId", nsInstanceId); + reqBody.put("terminationType", "graceful"); + reqBody.put("gracefulTerminationTimeout", "60"); + + // Step4: Call the NFVO or SDNO service to terminate service + RestfulResponse terminateRsp = RestfulUtil.send(url, methodType, JsonUtil.marshal(reqBody)); + ValidateUtil.assertObjectNotNull(terminateRsp); + LOGGER.info("terminate ns response status is : {}", terminateRsp.getStatus()); + LOGGER.info("terminate ns response content is : {}", terminateRsp.getResponseContent()); + @SuppressWarnings("unchecked") + Map<String, String> rsp = JsonUtil.unMarshal(terminateRsp.getResponseContent(), Map.class); + String jobId = rsp.get(CommonConstant.JOB_ID); + if (ValidateUtil.isStrEmpty(jobId)) { + LOGGER.error("Invalid jobId from terminate operation"); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setErrorCode(String.valueOf(terminateRsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.INVALID_RESPONSE_FROM_TERMINATE_OPERATION); } - - /** - * get ns progress by job Id - * <br> - * - * @param nsOperationKey The OperationKey for NS resource - * @param jobId the job id - * @return - * @since ONAP Amsterdam Release - */ - public RestfulResponse getNsProgress(NsOperationKey nsOperationKey, String jobId) throws ApplicationException { - - ValidateUtil.assertObjectNotNull(jobId); - // Step 1: query the current resource operation status - ResourceOperationStatus nsOperInfo = (RequestsDatabase.getInstance()).getResourceOperationStatus( - nsOperationKey.getServiceId(), nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); - - // Step 2: start query - LOGGER.info("query ns status -> begin"); - String url = getUrl(jobId, CommonConstant.Step.QUERY); - String methodType = CommonConstant.MethodType.GET; - // prepare restful parameters and options - RestfulResponse rsp = RestfulUtil.send(url, methodType, ""); - ValidateUtil.assertObjectNotNull(rsp); - LOGGER.info("query ns progress response status is : {}", rsp.getStatus()); - LOGGER.info("query ns progress response content is : {}", rsp.getResponseContent()); - // Step 3:check the response staus - if(!HttpCode.isSucess(rsp.getStatus())) { - LOGGER.info("fail to query job status"); - nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus())); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.FAIL_TO_QUERY_JOB_STATUS); - } - // Step 4: Process Network Service Instantiate Response - NsProgressStatus nsProgress = JsonUtil.unMarshal(rsp.getResponseContent(), NsProgressStatus.class); - ResponseDescriptor rspDesc = nsProgress.getResponseDescriptor(); - // Step 5: update segment operation progress - - nsOperInfo.setProgress(rspDesc.getProgress()); - nsOperInfo.setStatusDescription(rspDesc.getStatusDescription()); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - - // Step 6: update segment operation status - if(RequestsDbConstant.Progress.ONE_HUNDRED.equals(rspDesc.getProgress()) - && RequestsDbConstant.Status.FINISHED.equals(rspDesc.getStatus())) { - LOGGER.info("job result is succeeded, operType is {}", nsOperInfo.getOperType()); - nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); - - if(RequestsDbConstant.OperationType.CREATE.equals(nsOperInfo.getOperType())) { - nsOperInfo.setStatus(RequestsDbConstant.Status.FINISHED); - } - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - } else if(RequestsDbConstant.Status.ERROR.equals(rspDesc.getStatus())) { - LOGGER.error("job result is failed, operType is {}", nsOperInfo.getOperType()); - nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus())); - nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); - nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); - (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); - throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, DriverExceptionID.JOB_STATUS_ERROR); - } else { - LOGGER.error("unexcepted response status"); - } - LOGGER.info("query ns status -> end"); - - return rsp; + LOGGER.info("terminate ns -> end"); + + // Step 3: update segment operation + if (!HttpCode.isSucess(terminateRsp.getStatus())) { + LOGGER.error("fail to instantiate ns"); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setErrorCode(String.valueOf(terminateRsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.TERMINATE_NS_FAILED); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_TERMINATE_NS); } - - /** - * get url for the operation - * <br> - * - * @param variable variable should be put in the url - * @param step step of the operation (terminate,query,delete) - * @return - * @since ONAP Amsterdam Release - */ - private String getUrl(String variable, String step) { - - String url; - String originalUrl; - originalUrl = (String)nfvoUrlMap.get(step); - url = String.format(originalUrl, variable); - return url; - + LOGGER.info("update segment job id -> begin"); + nsOperInfo.setJobId(jobId); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + LOGGER.info("update segment job id -> end"); + + return terminateRsp; + } + + /** + * get ns progress by job Id <br> + * + * @param nsOperationKey The OperationKey for NS resource + * @param jobId the job id + * @return + * @since ONAP Amsterdam Release + */ + public RestfulResponse getNsProgress(NsOperationKey nsOperationKey, String jobId) + throws ApplicationException { + + ValidateUtil.assertObjectNotNull(jobId); + // Step 1: query the current resource operation status + ResourceOperationStatus nsOperInfo = + (RequestsDatabase.getInstance()).getResourceOperationStatus(nsOperationKey.getServiceId(), + nsOperationKey.getOperationId(), nsOperationKey.getNodeTemplateUUID()); + + // Step 2: start query + LOGGER.info("query ns status -> begin"); + String url = getUrl(jobId, CommonConstant.Step.QUERY); + String methodType = CommonConstant.MethodType.GET; + // prepare restful parameters and options + RestfulResponse rsp = RestfulUtil.send(url, methodType, ""); + ValidateUtil.assertObjectNotNull(rsp); + LOGGER.info("query ns progress response status is : {}", rsp.getStatus()); + LOGGER.info("query ns progress response content is : {}", rsp.getResponseContent()); + // Step 3:check the response staus + if (!HttpCode.isSucess(rsp.getStatus())) { + LOGGER.info("fail to query job status"); + nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus())); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.FAIL_TO_QUERY_JOB_STATUS); + } + // Step 4: Process Network Service Instantiate Response + NsProgressStatus nsProgress = + JsonUtil.unMarshal(rsp.getResponseContent(), NsProgressStatus.class); + ResponseDescriptor rspDesc = nsProgress.getResponseDescriptor(); + // Step 5: update segment operation progress + + nsOperInfo.setProgress(rspDesc.getProgress()); + nsOperInfo.setStatusDescription(rspDesc.getStatusDescription()); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + + // Step 6: update segment operation status + if (RequestsDbConstant.Progress.ONE_HUNDRED.equals(rspDesc.getProgress()) + && RequestsDbConstant.Status.FINISHED.equals(rspDesc.getStatus())) { + LOGGER.info("job result is succeeded, operType is {}", nsOperInfo.getOperType()); + nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); + + if (RequestsDbConstant.OperationType.CREATE.equals(nsOperInfo.getOperType())) { + nsOperInfo.setStatus(RequestsDbConstant.Status.FINISHED); + } + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + } else if (RequestsDbConstant.Status.ERROR.equals(rspDesc.getStatus())) { + LOGGER.error("job result is failed, operType is {}", nsOperInfo.getOperType()); + nsOperInfo.setErrorCode(String.valueOf(rsp.getStatus())); + nsOperInfo.setStatusDescription(CommonConstant.StatusDesc.QUERY_JOB_STATUS_FAILED); + nsOperInfo.setStatus(RequestsDbConstant.Status.ERROR); + (RequestsDatabase.getInstance()).updateResOperStatus(nsOperInfo); + throw new ApplicationException(HttpCode.INTERNAL_SERVER_ERROR, + DriverExceptionID.JOB_STATUS_ERROR); + } else { + LOGGER.error("unexcepted response status"); } + LOGGER.info("query ns status -> end"); + + return rsp; + } + + /** + * get url for the operation <br> + * + * @param variable variable should be put in the url + * @param step step of the operation (terminate,query,delete) + * @return + * @since ONAP Amsterdam Release + */ + private String getUrl(String variable, String step) { + + String url; + String originalUrl; + originalUrl = (String) nfvoUrlMap.get(step); + url = String.format(originalUrl, variable); + return url; + + } } diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/DriverExceptionID.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/DriverExceptionID.java index a160b82e8a..afaa9019ad 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/DriverExceptionID.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/constant/DriverExceptionID.java @@ -31,27 +31,29 @@ package org.openecomp.mso.adapters.vfc.constant; */ public class DriverExceptionID { - public static final String INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION = - "Invalid response from instantiate operation"; + public static final String INVALID_RESPONSE_FROM_INSTANTIATE_OPERATION = + "Invalid response from instantiate operation"; - public static final String INVALID_RESPONSEE_FROM_CREATE_OPERATION = "Invalid response from create operation"; + public static final String INVALID_RESPONSEE_FROM_CREATE_OPERATION = + "Invalid response from create operation"; - public static final String FAIL_TO_INSTANTIATE_NS = "Fail to instantiate ns"; + public static final String FAIL_TO_INSTANTIATE_NS = "Fail to instantiate ns"; - public static final String FAIL_TO_CREATE_NS = "Fail to create ns"; + public static final String FAIL_TO_CREATE_NS = "Fail to create ns"; - public static final String INVALID_RESPONSE_FROM_TERMINATE_OPERATION = "Invalid response from terminate operation"; + public static final String INVALID_RESPONSE_FROM_TERMINATE_OPERATION = + "Invalid response from terminate operation"; - public static final String FAIL_TO_DELETE_NS = "Fail to delete ns"; + public static final String FAIL_TO_DELETE_NS = "Fail to delete ns"; - public static final String FAIL_TO_TERMINATE_NS = "Fail to terminate ns"; + public static final String FAIL_TO_TERMINATE_NS = "Fail to terminate ns"; - public static final String JOB_STATUS_ERROR = "Job status error"; + public static final String JOB_STATUS_ERROR = "Job status error"; - public static final String FAIL_TO_QUERY_JOB_STATUS = "Fail to query job status"; + public static final String FAIL_TO_QUERY_JOB_STATUS = "Fail to query job status"; - private DriverExceptionID() { + private DriverExceptionID() { - } + } } diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java index a9546d5c4c..69ad951aa5 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java @@ -40,93 +40,93 @@ import org.openecomp.mso.logger.MsoLogger; */ public class JsonUtil { - /** - * Log service - */ - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); + /** + * Log service + */ + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); - /** - * Mapper. - */ - private static final ObjectMapper MAPPER = new ObjectMapper(); + /** + * Mapper. + */ + private static final ObjectMapper MAPPER = new ObjectMapper(); - static { - MAPPER.setDeserializationConfig(MAPPER.getDeserializationConfig() - .without(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES)); - MAPPER.setSerializationInclusion(Inclusion.NON_NULL); - } + static { + MAPPER.setDeserializationConfig(MAPPER.getDeserializationConfig().without( + org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES)); + MAPPER.setSerializationInclusion(Inclusion.NON_NULL); + } - /** - * Constructor<br/> - * <p> - * </p> - * - * @since ONAP Amsterdam Release 2017-9-6 - */ - private JsonUtil() { + /** + * Constructor<br/> + * <p> + * </p> + * + * @since ONAP Amsterdam Release 2017-9-6 + */ + private JsonUtil() { - } + } - /** - * Parse the string in form of json.<br/> - * - * @param jsonstr json string. - * @param type that convert json string to - * @return model object - * @since ONAP Amsterdam Release 2017-9-6 - */ - public static <T> T unMarshal(String jsonstr, Class<T> type) throws ApplicationException { - try { - return MAPPER.readValue(jsonstr, type); - } catch(IOException e) { - LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError, - "fail to unMarshal json", e); - throw new ApplicationException(HttpCode.BAD_REQUEST, "fail to unMarshal json"); - } + /** + * Parse the string in form of json.<br/> + * + * @param jsonstr json string. + * @param type that convert json string to + * @return model object + * @since ONAP Amsterdam Release 2017-9-6 + */ + public static <T> T unMarshal(String jsonstr, Class<T> type) throws ApplicationException { + try { + return MAPPER.readValue(jsonstr, type); + } catch (IOException e) { + LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError, + "fail to unMarshal json", e); + throw new ApplicationException(HttpCode.BAD_REQUEST, "fail to unMarshal json"); } + } - /** - * Parse the string in form of json.<br/> - * - * @param jsonstr json string. - * @param type that convert json string to - * @return model object - * @since ONAP Amsterdam Release 2017-9-6 - */ - public static <T> T unMarshal(String jsonstr, TypeReference<T> type) throws ApplicationException { - try { - return MAPPER.readValue(jsonstr, type); - } catch(IOException e) { - LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError, - "fail to unMarshal json", e); - throw new ApplicationException(HttpCode.BAD_REQUEST, "fail to unMarshal json"); - } + /** + * Parse the string in form of json.<br/> + * + * @param jsonstr json string. + * @param type that convert json string to + * @return model object + * @since ONAP Amsterdam Release 2017-9-6 + */ + public static <T> T unMarshal(String jsonstr, TypeReference<T> type) throws ApplicationException { + try { + return MAPPER.readValue(jsonstr, type); + } catch (IOException e) { + LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError, + "fail to unMarshal json", e); + throw new ApplicationException(HttpCode.BAD_REQUEST, "fail to unMarshal json"); } + } - /** - * Convert object to json string.<br/> - * - * @param srcObj data object - * @return json string - * @since ONAP Amsterdam Release 2017-9-6 - */ - public static String marshal(Object srcObj) throws ApplicationException { - try { - return MAPPER.writeValueAsString(srcObj); - } catch(IOException e) { - LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError, - "fail to marshal json", e); - throw new ApplicationException(HttpCode.BAD_REQUEST, "srcObj marshal failed!"); - } + /** + * Convert object to json string.<br/> + * + * @param srcObj data object + * @return json string + * @since ONAP Amsterdam Release 2017-9-6 + */ + public static String marshal(Object srcObj) throws ApplicationException { + try { + return MAPPER.writeValueAsString(srcObj); + } catch (IOException e) { + LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError, + "fail to marshal json", e); + throw new ApplicationException(HttpCode.BAD_REQUEST, "srcObj marshal failed!"); } + } - /** - * Get mapper.<br/> - * - * @return mapper - * @since ONAP Amsterdam Release 2017-9-6 - */ - public static ObjectMapper getMapper() { - return MAPPER; - } + /** + * Get mapper.<br/> + * + * @return mapper + * @since ONAP Amsterdam Release 2017-9-6 + */ + public static ObjectMapper getMapper() { + return MAPPER; + } } diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java index 8e5f0b4274..85065c0953 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/RestfulUtil.java @@ -58,179 +58,179 @@ import org.openecomp.mso.logger.MsoLogger; */ public class RestfulUtil { - /** - * Log service - */ - private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); - - private static final MsoAlarmLogger ALARMLOGGER = new MsoAlarmLogger(); - - private static final int DEFAULT_TIME_OUT = 60; - - private RestfulUtil() { - - } - - public static RestfulResponse send(String url, String methodType, String content) { - LOGGER.info(MessageEnum.RA_NS_EXC, url, "VFC", ""); - LOGGER.debug("VFC Request Body:\n" + content); - - HttpRequestBase method = null; - HttpResponse httpResponse = null; - + /** + * Log service + */ + private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA); + + private static final MsoAlarmLogger ALARMLOGGER = new MsoAlarmLogger(); + + private static final int DEFAULT_TIME_OUT = 60; + + private RestfulUtil() { + + } + + public static RestfulResponse send(String url, String methodType, String content) { + LOGGER.info(MessageEnum.RA_NS_EXC, url, "VFC", ""); + LOGGER.debug("VFC Request Body:\n" + content); + + HttpRequestBase method = null; + HttpResponse httpResponse = null; + + try { + int timeout = DEFAULT_TIME_OUT; + + RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout) + .setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).build(); + + HttpClient client = HttpClientBuilder.create().build(); + + if ("POST".equals(methodType)) { + HttpPost httpPost = new HttpPost(url); + httpPost.setConfig(requestConfig); + httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON)); + method = httpPost; + } else if ("PUT".equals(methodType)) { + HttpPut httpPut = new HttpPut(url); + httpPut.setConfig(requestConfig); + httpPut.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON)); + method = httpPut; + } else if ("GET".equals(methodType)) { + HttpGet httpGet = new HttpGet(url); + httpGet.setConfig(requestConfig); + method = httpGet; + } else if ("DELETE".equals(methodType)) { + HttpDelete httpDelete = new HttpDelete(url); + httpDelete.setConfig(requestConfig); + method = httpDelete; + } + + // now VFC have no auth + // String userCredentials = + // SDNCAdapterProperties.getEncryptedProperty(Constants.SDNC_AUTH_PROP, + // Constants.DEFAULT_SDNC_AUTH, Constants.ENCRYPTION_KEY); + // String authorization = "Basic " + + // DatatypeConverter.printBase64Binary(userCredentials.getBytes()); + // method.setHeader("Authorization", authorization); + + httpResponse = client.execute(method); + + String responseContent = null; + if (httpResponse.getEntity() != null) { + responseContent = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); + } + + int statusCode = httpResponse.getStatusLine().getStatusCode(); + String statusMessage = httpResponse.getStatusLine().getReasonPhrase(); + + LOGGER.debug("VFC Response: " + statusCode + " " + statusMessage + + (responseContent == null ? "" : System.lineSeparator() + responseContent)); + + if (httpResponse.getStatusLine().getStatusCode() >= 300) { + String errMsg = "VFC returned " + statusCode + " " + statusMessage; + logError(errMsg); + return createResponse(statusCode, errMsg); + } + + httpResponse = null; + + if (null != method) { + method.reset(); + } else { + LOGGER.debug("method is NULL:"); + } + + method = null; + + LOGGER.info(MessageEnum.RA_RESPONSE_FROM_SDNC, responseContent, "SDNC", ""); + return createResponse(statusCode, responseContent); + + } catch (SocketTimeoutException e) { + String errMsg = "Request to SDNC timed out"; + logError(errMsg, e); + return createResponse(HttpURLConnection.HTTP_CLIENT_TIMEOUT, errMsg); + + } catch (ConnectTimeoutException e) { + String errMsg = "Request to SDNC timed out"; + logError(errMsg, e); + return createResponse(HttpURLConnection.HTTP_CLIENT_TIMEOUT, errMsg); + + } catch (Exception e) { + String errMsg = "Error processing request to SDNC"; + logError(errMsg, e); + return createResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, errMsg); + + } finally { + if (httpResponse != null) { try { - int timeout = DEFAULT_TIME_OUT; - - RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout) - .setConnectionRequestTimeout(timeout).build(); - - HttpClient client = HttpClientBuilder.create().build(); - - if("POST".equals(methodType)) { - HttpPost httpPost = new HttpPost(url); - httpPost.setConfig(requestConfig); - httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON)); - method = httpPost; - } else if("PUT".equals(methodType)) { - HttpPut httpPut = new HttpPut(url); - httpPut.setConfig(requestConfig); - httpPut.setEntity(new StringEntity(content, ContentType.APPLICATION_JSON)); - method = httpPut; - } else if("GET".equals(methodType)) { - HttpGet httpGet = new HttpGet(url); - httpGet.setConfig(requestConfig); - method = httpGet; - } else if("DELETE".equals(methodType)) { - HttpDelete httpDelete = new HttpDelete(url); - httpDelete.setConfig(requestConfig); - method = httpDelete; - } - - // now VFC have no auth - // String userCredentials = - // SDNCAdapterProperties.getEncryptedProperty(Constants.SDNC_AUTH_PROP, - // Constants.DEFAULT_SDNC_AUTH, Constants.ENCRYPTION_KEY); - // String authorization = "Basic " + - // DatatypeConverter.printBase64Binary(userCredentials.getBytes()); - // method.setHeader("Authorization", authorization); - - httpResponse = client.execute(method); - - String responseContent = null; - if(httpResponse.getEntity() != null) { - responseContent = EntityUtils.toString(httpResponse.getEntity(), "UTF-8"); - } - - int statusCode = httpResponse.getStatusLine().getStatusCode(); - String statusMessage = httpResponse.getStatusLine().getReasonPhrase(); - - LOGGER.debug("VFC Response: " + statusCode + " " + statusMessage - + (responseContent == null ? "" : System.lineSeparator() + responseContent)); - - if(httpResponse.getStatusLine().getStatusCode() >= 300) { - String errMsg = "VFC returned " + statusCode + " " + statusMessage; - logError(errMsg); - return createResponse(statusCode, errMsg); - } - - httpResponse = null; - - if(null != method) { - method.reset(); - } - else { - LOGGER.debug("method is NULL:"); - } - - method = null; - - LOGGER.info(MessageEnum.RA_RESPONSE_FROM_SDNC, responseContent, "SDNC", ""); - return createResponse(statusCode, responseContent); - - } catch(SocketTimeoutException e) { - String errMsg = "Request to SDNC timed out"; - logError(errMsg, e); - return createResponse(HttpURLConnection.HTTP_CLIENT_TIMEOUT, errMsg); - - } catch(ConnectTimeoutException e) { - String errMsg = "Request to SDNC timed out"; - logError(errMsg, e); - return createResponse(HttpURLConnection.HTTP_CLIENT_TIMEOUT, errMsg); - - } catch(Exception e) { - String errMsg = "Error processing request to SDNC"; - logError(errMsg, e); - return createResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, errMsg); - - } finally { - if(httpResponse != null) { - try { - EntityUtils.consume(httpResponse.getEntity()); - } catch(Exception e) { - LOGGER.debug("Exception :",e); - } - } - - if(method != null) { - try { - method.reset(); - } catch(Exception e) { - LOGGER.debug("Exception :",e); - } - } + EntityUtils.consume(httpResponse.getEntity()); + } catch (Exception e) { + LOGGER.debug("Exception :", e); } - } + } - private static void logError(String errMsg, Throwable t) { - LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, errMsg, t); - ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, errMsg); - } - - private static void logError(String errMsg) { - LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, errMsg); - ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, errMsg); - } - - private static RestfulResponse createResponse(int statusCode, String content) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(statusCode); - rsp.setResponseContent(content); - return rsp; + if (method != null) { + try { + method.reset(); + } catch (Exception e) { + LOGGER.debug("Exception :", e); + } + } } - - /** - * @param request - * @return - */ - public static String getRequestBody(HttpServletRequest request) { - String body = null; - StringBuilder stringBuilder = new StringBuilder(); - BufferedReader bufferedReader = null; + } + + private static void logError(String errMsg, Throwable t) { + LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, errMsg, + t); + ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, errMsg); + } + + private static void logError(String errMsg) { + LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, errMsg); + ALARMLOGGER.sendAlarm("MsoInternalError", MsoAlarmLogger.CRITICAL, errMsg); + } + + private static RestfulResponse createResponse(int statusCode, String content) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(statusCode); + rsp.setResponseContent(content); + return rsp; + } + + /** + * @param request + * @return + */ + public static String getRequestBody(HttpServletRequest request) { + String body = null; + StringBuilder stringBuilder = new StringBuilder(); + BufferedReader bufferedReader = null; + try { + InputStream inputStream = request.getInputStream(); + if (inputStream != null) { + bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); + char[] charBuffer = new char[128]; + int bytesRead = -1; + while ((bytesRead = bufferedReader.read(charBuffer)) > 0) + stringBuilder.append(charBuffer, 0, bytesRead); + } + } catch (IOException ex) { + LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, + "read inputStream buffer catch exception:", ex); + } finally { + if (bufferedReader != null) { try { - InputStream inputStream = request.getInputStream(); - if(inputStream != null) { - bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); - char[] charBuffer = new char[128]; - int bytesRead = -1; - while((bytesRead = bufferedReader.read(charBuffer)) > 0) - stringBuilder.append(charBuffer, 0, bytesRead); - } - } catch(IOException ex) { - LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, - "read inputStream buffer catch exception:", ex); - } finally { - if(bufferedReader != null) { - try { - bufferedReader.close(); - } catch(IOException ex) { - LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, - "close buffer catch exception:", ex); - } - } + bufferedReader.close(); + } catch (IOException ex) { + LOGGER.error(MessageEnum.RA_NS_EXC, "VFC", "", MsoLogger.ErrorCode.AvailabilityError, + "close buffer catch exception:", ex); } - - body = stringBuilder.toString(); - return body; + } } + body = stringBuilder.toString(); + return body; + } + } diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java index a6fa2d29e2..26f8d6e53b 100644 --- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java +++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java @@ -27,60 +27,61 @@ import org.slf4j.LoggerFactory; public class ValidateUtil {
- /**
- * Log server.
- */
- private static final Logger LOGGER = LoggerFactory.getLogger(ValidateUtil.class);
+ /**
+ * Log server.
+ */
+ private static final Logger LOGGER = LoggerFactory.getLogger(ValidateUtil.class);
- /**
- * Constructor<br/>
- * <p>
- * </p>
- *
- * @since ONAP Amsterdam Release 2017-9-6
- */
- private ValidateUtil() {
+ /**
+ * Constructor<br/>
+ * <p>
+ * </p>
+ *
+ * @since ONAP Amsterdam Release 2017-9-6
+ */
+ private ValidateUtil() {
- }
-
- /**
- * Assert String parameter.<br/>
- *
- * @param paramValue parameter data
- * @param name of parameter
- * @since ONAP Amsterdam Release 2017-9-6
- */
- public static void assertStringNotNull(String paramValue, String paramName) throws ApplicationException {
- if(null != paramValue && !paramValue.isEmpty()) {
- return;
- }
+ }
- LOGGER.error(paramName + ": Parameter is null or empty.");
- throw new ApplicationException(HttpCode.BAD_REQUEST, paramName + ": Invalid parameter.");
+ /**
+ * Assert String parameter.<br/>
+ *
+ * @param paramValue parameter data
+ * @param name of parameter
+ * @since ONAP Amsterdam Release 2017-9-6
+ */
+ public static void assertStringNotNull(String paramValue, String paramName)
+ throws ApplicationException {
+ if (null != paramValue && !paramValue.isEmpty()) {
+ return;
}
- /**
- * Assert object is null.<br/>
- *
- * @param object data object
- * @since ONAP Amsterdam Release 2017-9-6
- */
- public static void assertObjectNotNull(Object object) throws ApplicationException {
- if(null == object) {
- LOGGER.error("Object is null.");
- throw new ApplicationException(HttpCode.BAD_REQUEST, "Object is null.");
- }
+ LOGGER.error(paramName + ": Parameter is null or empty.");
+ throw new ApplicationException(HttpCode.BAD_REQUEST, paramName + ": Invalid parameter.");
+ }
+ /**
+ * Assert object is null.<br/>
+ *
+ * @param object data object
+ * @since ONAP Amsterdam Release 2017-9-6
+ */
+ public static void assertObjectNotNull(Object object) throws ApplicationException {
+ if (null == object) {
+ LOGGER.error("Object is null.");
+ throw new ApplicationException(HttpCode.BAD_REQUEST, "Object is null.");
}
- /**
- * <br>
- *
- * @param str
- * @return
- * @since ONAP Amsterdam Release
- */
- public static boolean isStrEmpty(String str) {
- return null == str || str.isEmpty();
- }
+ }
+
+ /**
+ * <br>
+ *
+ * @param str
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ public static boolean isStrEmpty(String str) {
+ return null == str || str.isEmpty();
+ }
}
|