From cb5018ceb56b983f4c0dca1f0eee9c94c1404b8f Mon Sep 17 00:00:00 2001 From: "victor.gao" Date: Thu, 17 Aug 2017 09:35:20 +0800 Subject: Correct maven pom groupId Correct the mismatch between gerrit project directory and wiki groupid definition. Change-Id: I35035c67dc654e7383c5e9951f1f72986c588d57 Issue-Id:VFC-86 Signed-off-by: victor.gao --- ResmanagementService/deployment/pom.xml | 2 +- ResmanagementService/pom.xml | 2 +- ResmanagementService/service/pom.xml | 2 +- .../org/onap/vfc/nfvo/res/common/ResourceUtil.java | 43 -- .../java/org/onap/vfc/nfvo/res/common/VimUtil.java | 141 ------ .../vfc/nfvo/res/common/constant/Constant.java | 93 ---- .../vfc/nfvo/res/common/constant/HttpConstant.java | 79 ---- .../nfvo/res/common/constant/ParamConstant.java | 370 --------------- .../nfvo/res/common/constant/ResponseConstant.java | 60 --- .../vfc/nfvo/res/common/constant/UrlConstant.java | 258 ----------- .../onap/vfc/nfvo/res/common/util/JsonUtil.java | 290 ------------ .../onap/vfc/nfvo/res/common/util/RestfulUtil.java | 371 --------------- .../onap/vfc/nfvo/res/common/util/StringUtil.java | 215 --------- .../nfvo/res/common/util/request/RequestUtil.java | 129 ------ .../res/common/util/response/ResponseUtil.java | 133 ------ .../res/common/util/response/RoaResponseUtil.java | 113 ----- .../activator/ROAResmgrServicePostProcessor.java | 60 --- .../adapter/impl/ResmgrAdapter2MSBManager.java | 111 ----- .../adapter/impl/ResmgrAdapterMgrService.java | 185 -------- .../adapter/inf/IResmgrAdapter2MSBManager.java | 52 --- .../adapter/inf/IResmgrAdapterMgrService.java | 39 -- .../res/service/base/openstack/impl/HostImpl.java | 80 ---- .../service/base/openstack/impl/LocationImpl.java | 186 -------- .../service/base/openstack/impl/NetworkImpl.java | 101 ----- .../res/service/base/openstack/impl/PortImpl.java | 103 ----- .../res/service/base/openstack/impl/SitesImpl.java | 231 ---------- .../res/service/base/openstack/impl/VimImpl.java | 82 ---- .../nfvo/res/service/base/openstack/inf/Host.java | 66 --- .../base/openstack/inf/InterfaceResManagement.java | 40 -- .../res/service/base/openstack/inf/Location.java | 104 ----- .../res/service/base/openstack/inf/Network.java | 69 --- .../nfvo/res/service/base/openstack/inf/Port.java | 76 ---- .../service/base/openstack/inf/ResManagement.java | 66 --- .../nfvo/res/service/base/openstack/inf/Sites.java | 95 ---- .../nfvo/res/service/base/openstack/inf/Vim.java | 76 ---- .../service/business/impl/HostBusinessImpl.java | 162 ------- .../service/business/impl/LimitsBusinessImpl.java | 93 ---- .../business/impl/LocationBusinessImpl.java | 242 ---------- .../service/business/impl/NetworkBusinessImpl.java | 153 ------- .../service/business/impl/PortBusinessImpl.java | 161 ------- .../service/business/impl/SitesBusinessImpl.java | 200 -------- .../res/service/business/impl/VimBusinessImpl.java | 99 ---- .../res/service/business/inf/HostBusiness.java | 131 ------ .../res/service/business/inf/LimitsBusiness.java | 42 -- .../res/service/business/inf/LocationBusiness.java | 134 ------ .../res/service/business/inf/NetworkBusiness.java | 133 ------ .../res/service/business/inf/PortBusiness.java | 131 ------ .../res/service/business/inf/SitesBusiness.java | 124 ----- .../nfvo/res/service/business/inf/VimBusiness.java | 72 --- .../vfc/nfvo/res/service/dao/impl/AbstractDao.java | 57 --- .../vfc/nfvo/res/service/dao/impl/HostDaoImpl.java | 83 ---- .../nfvo/res/service/dao/impl/LocationDaoImpl.java | 83 ---- .../nfvo/res/service/dao/impl/NetworkDaoImpl.java | 83 ---- .../vfc/nfvo/res/service/dao/impl/PortDaoImpl.java | 83 ---- .../nfvo/res/service/dao/impl/SitesDaoImpl.java | 77 ---- .../vfc/nfvo/res/service/dao/impl/VimDaoImpl.java | 55 --- .../res/service/dao/impl/VirtualLinkDaoImpl.java | 84 ---- .../vfc/nfvo/res/service/dao/impl/VmDaoImpl.java | 108 ----- .../vfc/nfvo/res/service/dao/impl/VnfDaoImpl.java | 84 ---- .../nfvo/res/service/dao/impl/VnfInfoDaoImpl.java | 96 ---- .../res/service/dao/impl/VnfStatusDaoImpl.java | 96 ---- .../onap/vfc/nfvo/res/service/dao/inf/HostDao.java | 114 ----- .../vfc/nfvo/res/service/dao/inf/LocationDao.java | 123 ----- .../vfc/nfvo/res/service/dao/inf/NetworkDao.java | 125 ----- .../onap/vfc/nfvo/res/service/dao/inf/PortDao.java | 114 ----- .../vfc/nfvo/res/service/dao/inf/SitesDao.java | 105 ----- .../onap/vfc/nfvo/res/service/dao/inf/VimDao.java | 68 --- .../nfvo/res/service/dao/inf/VirtualLinkDao.java | 69 --- .../onap/vfc/nfvo/res/service/dao/inf/VmDao.java | 45 -- .../onap/vfc/nfvo/res/service/dao/inf/VnfDao.java | 69 --- .../vfc/nfvo/res/service/dao/inf/VnfInfoDao.java | 43 -- .../vfc/nfvo/res/service/dao/inf/VnfStatusDao.java | 43 -- .../vfc/nfvo/res/service/entity/HostEntity.java | 179 -------- .../nfvo/res/service/entity/LocationEntity.java | 236 ---------- .../vfc/nfvo/res/service/entity/NetworkEntity.java | 271 ----------- .../vfc/nfvo/res/service/entity/PortEntity.java | 179 -------- .../vfc/nfvo/res/service/entity/SitesEntity.java | 309 ------------- .../vfc/nfvo/res/service/entity/VimEntity.java | 106 ----- .../nfvo/res/service/entity/VirtualLinkEntity.java | 285 ------------ .../onap/vfc/nfvo/res/service/entity/VmEntity.java | 96 ---- .../vfc/nfvo/res/service/entity/VnfEntity.java | 337 -------------- .../vfc/nfvo/res/service/entity/VnfInfoEntity.java | 83 ---- .../nfvo/res/service/entity/VnfStatusEntity.java | 213 --------- .../service/group/impl/GrantResServiceImpl.java | 206 --------- .../group/impl/IResourceAddServiceImpl.java | 159 ------- .../group/impl/IResourceDelServiceImpl.java | 75 --- .../group/impl/IResourceUpdateServiceImpl.java | 120 ----- .../service/group/impl/ResOperateServiceImpl.java | 257 ----------- .../service/group/impl/VirtualLinkServiceImpl.java | 123 ----- .../nfvo/res/service/group/impl/VmServiceImpl.java | 177 -------- .../res/service/group/impl/VnfInfoServiceImpl.java | 150 ------ .../res/service/group/impl/VnfServiceImpl.java | 141 ------ .../service/group/impl/VnfStatusServiceImpl.java | 117 ----- .../res/service/group/inf/GrantResService.java | 44 -- .../res/service/group/inf/ResOperateService.java | 82 ---- .../res/service/group/inf/VirtualLinkService.java | 64 --- .../vfc/nfvo/res/service/group/inf/VmService.java | 44 -- .../nfvo/res/service/group/inf/VnfInfoService.java | 42 -- .../vfc/nfvo/res/service/group/inf/VnfService.java | 66 --- .../res/service/group/inf/VnfStatusService.java | 42 -- .../vfc/nfvo/res/service/mapper/HostMapper.java | 114 ----- .../nfvo/res/service/mapper/LocationMapper.java | 123 ----- .../vfc/nfvo/res/service/mapper/NetworkMapper.java | 125 ----- .../vfc/nfvo/res/service/mapper/PortMapper.java | 114 ----- .../vfc/nfvo/res/service/mapper/SitesMapper.java | 111 ----- .../vfc/nfvo/res/service/mapper/VimMapper.java | 68 --- .../nfvo/res/service/mapper/VirtualLinkMapper.java | 39 -- .../onap/vfc/nfvo/res/service/mapper/VmMapper.java | 41 -- .../vfc/nfvo/res/service/mapper/VnfInfoMapper.java | 39 -- .../vfc/nfvo/res/service/mapper/VnfMapper.java | 39 -- .../nfvo/res/service/mapper/VnfStatusMapper.java | 39 -- .../nfvo/res/service/rest/GrantResourseRoa.java | 94 ---- .../onap/vfc/nfvo/res/service/rest/HostRoa.java | 183 -------- .../onap/vfc/nfvo/res/service/rest/LimitsRoa.java | 73 --- .../vfc/nfvo/res/service/rest/LocationRoa.java | 316 ------------- .../onap/vfc/nfvo/res/service/rest/NetworkRoa.java | 189 -------- .../onap/vfc/nfvo/res/service/rest/PortRoa.java | 183 -------- .../vfc/nfvo/res/service/rest/ResOperateRoa.java | 151 ------- .../onap/vfc/nfvo/res/service/rest/SitesRoa.java | 224 --------- .../onap/vfc/nfvo/res/service/rest/SwaggerRoa.java | 49 -- .../vfc/nfvo/res/service/rest/VirtualLinkRoa.java | 129 ------ .../org/onap/vfc/nfvo/res/service/rest/VmRoa.java | 127 ------ .../onap/vfc/nfvo/res/service/rest/VnfInfoRoa.java | 129 ------ .../org/onap/vfc/nfvo/res/service/rest/VnfRoa.java | 128 ------ .../vfc/nfvo/res/service/rest/VnfStatusRoa.java | 129 ------ .../rest/exceptionmapper/ExceptionMessage.java | 64 --- .../exceptionmapper/GenericExceptionMapper.java | 41 -- .../exceptionmapper/ServiceExceptionMapper.java | 45 -- .../nfvo/resmanagement/common/ResourceUtil.java | 43 ++ .../vfc/nfvo/resmanagement/common/VimUtil.java | 141 ++++++ .../resmanagement/common/constant/Constant.java | 93 ++++ .../common/constant/HttpConstant.java | 79 ++++ .../common/constant/ParamConstant.java | 370 +++++++++++++++ .../common/constant/ResponseConstant.java | 60 +++ .../resmanagement/common/constant/UrlConstant.java | 258 +++++++++++ .../nfvo/resmanagement/common/util/JsonUtil.java | 290 ++++++++++++ .../resmanagement/common/util/RestfulUtil.java | 371 +++++++++++++++ .../nfvo/resmanagement/common/util/StringUtil.java | 215 +++++++++ .../common/util/request/RequestUtil.java | 129 ++++++ .../common/util/response/ResponseUtil.java | 133 ++++++ .../common/util/response/RoaResponseUtil.java | 113 +++++ .../activator/ROAResmgrServicePostProcessor.java | 60 +++ .../adapter/impl/ResmgrAdapter2MSBManager.java | 111 +++++ .../adapter/impl/ResmgrAdapterMgrService.java | 185 ++++++++ .../adapter/inf/IResmgrAdapter2MSBManager.java | 52 +++ .../adapter/inf/IResmgrAdapterMgrService.java | 39 ++ .../service/base/openstack/impl/HostImpl.java | 80 ++++ .../service/base/openstack/impl/LocationImpl.java | 186 ++++++++ .../service/base/openstack/impl/NetworkImpl.java | 101 +++++ .../service/base/openstack/impl/PortImpl.java | 103 +++++ .../service/base/openstack/impl/SitesImpl.java | 231 ++++++++++ .../service/base/openstack/impl/VimImpl.java | 82 ++++ .../service/base/openstack/inf/Host.java | 66 +++ .../base/openstack/inf/InterfaceResManagement.java | 40 ++ .../service/base/openstack/inf/Location.java | 104 +++++ .../service/base/openstack/inf/Network.java | 69 +++ .../service/base/openstack/inf/Port.java | 76 ++++ .../service/base/openstack/inf/ResManagement.java | 66 +++ .../service/base/openstack/inf/Sites.java | 95 ++++ .../service/base/openstack/inf/Vim.java | 76 ++++ .../service/business/impl/HostBusinessImpl.java | 162 +++++++ .../service/business/impl/LimitsBusinessImpl.java | 93 ++++ .../business/impl/LocationBusinessImpl.java | 242 ++++++++++ .../service/business/impl/NetworkBusinessImpl.java | 153 +++++++ .../service/business/impl/PortBusinessImpl.java | 161 +++++++ .../service/business/impl/SitesBusinessImpl.java | 200 ++++++++ .../service/business/impl/VimBusinessImpl.java | 99 ++++ .../service/business/inf/HostBusiness.java | 131 ++++++ .../service/business/inf/LimitsBusiness.java | 42 ++ .../service/business/inf/LocationBusiness.java | 134 ++++++ .../service/business/inf/NetworkBusiness.java | 133 ++++++ .../service/business/inf/PortBusiness.java | 131 ++++++ .../service/business/inf/SitesBusiness.java | 124 +++++ .../service/business/inf/VimBusiness.java | 72 +++ .../service/dao/impl/AbstractDao.java | 57 +++ .../service/dao/impl/HostDaoImpl.java | 83 ++++ .../service/dao/impl/LocationDaoImpl.java | 83 ++++ .../service/dao/impl/NetworkDaoImpl.java | 83 ++++ .../service/dao/impl/PortDaoImpl.java | 83 ++++ .../service/dao/impl/SitesDaoImpl.java | 77 ++++ .../resmanagement/service/dao/impl/VimDaoImpl.java | 55 +++ .../service/dao/impl/VirtualLinkDaoImpl.java | 84 ++++ .../resmanagement/service/dao/impl/VmDaoImpl.java | 108 +++++ .../resmanagement/service/dao/impl/VnfDaoImpl.java | 84 ++++ .../service/dao/impl/VnfInfoDaoImpl.java | 96 ++++ .../service/dao/impl/VnfStatusDaoImpl.java | 96 ++++ .../resmanagement/service/dao/inf/HostDao.java | 114 +++++ .../resmanagement/service/dao/inf/LocationDao.java | 123 +++++ .../resmanagement/service/dao/inf/NetworkDao.java | 125 +++++ .../resmanagement/service/dao/inf/PortDao.java | 114 +++++ .../resmanagement/service/dao/inf/SitesDao.java | 105 +++++ .../nfvo/resmanagement/service/dao/inf/VimDao.java | 68 +++ .../service/dao/inf/VirtualLinkDao.java | 69 +++ .../nfvo/resmanagement/service/dao/inf/VmDao.java | 45 ++ .../nfvo/resmanagement/service/dao/inf/VnfDao.java | 69 +++ .../resmanagement/service/dao/inf/VnfInfoDao.java | 43 ++ .../service/dao/inf/VnfStatusDao.java | 43 ++ .../resmanagement/service/entity/HostEntity.java | 179 ++++++++ .../service/entity/LocationEntity.java | 236 ++++++++++ .../service/entity/NetworkEntity.java | 271 +++++++++++ .../resmanagement/service/entity/PortEntity.java | 179 ++++++++ .../resmanagement/service/entity/SitesEntity.java | 309 +++++++++++++ .../resmanagement/service/entity/VimEntity.java | 106 +++++ .../service/entity/VirtualLinkEntity.java | 285 ++++++++++++ .../resmanagement/service/entity/VmEntity.java | 96 ++++ .../resmanagement/service/entity/VnfEntity.java | 337 ++++++++++++++ .../service/entity/VnfInfoEntity.java | 83 ++++ .../service/entity/VnfStatusEntity.java | 213 +++++++++ .../service/group/impl/GrantResServiceImpl.java | 206 +++++++++ .../group/impl/IResourceAddServiceImpl.java | 159 +++++++ .../group/impl/IResourceDelServiceImpl.java | 75 +++ .../group/impl/IResourceUpdateServiceImpl.java | 120 +++++ .../service/group/impl/ResOperateServiceImpl.java | 257 +++++++++++ .../service/group/impl/VirtualLinkServiceImpl.java | 123 +++++ .../service/group/impl/VmServiceImpl.java | 177 ++++++++ .../service/group/impl/VnfInfoServiceImpl.java | 150 ++++++ .../service/group/impl/VnfServiceImpl.java | 141 ++++++ .../service/group/impl/VnfStatusServiceImpl.java | 117 +++++ .../service/group/inf/GrantResService.java | 44 ++ .../service/group/inf/ResOperateService.java | 82 ++++ .../service/group/inf/VirtualLinkService.java | 64 +++ .../resmanagement/service/group/inf/VmService.java | 44 ++ .../service/group/inf/VnfInfoService.java | 42 ++ .../service/group/inf/VnfService.java | 66 +++ .../service/group/inf/VnfStatusService.java | 42 ++ .../resmanagement/service/mapper/HostMapper.java | 114 +++++ .../service/mapper/LocationMapper.java | 123 +++++ .../service/mapper/NetworkMapper.java | 125 +++++ .../resmanagement/service/mapper/PortMapper.java | 114 +++++ .../resmanagement/service/mapper/SitesMapper.java | 111 +++++ .../resmanagement/service/mapper/VimMapper.java | 68 +++ .../service/mapper/VirtualLinkMapper.java | 39 ++ .../resmanagement/service/mapper/VmMapper.java | 41 ++ .../service/mapper/VnfInfoMapper.java | 39 ++ .../resmanagement/service/mapper/VnfMapper.java | 39 ++ .../service/mapper/VnfStatusMapper.java | 39 ++ .../service/rest/GrantResourseRoa.java | 94 ++++ .../nfvo/resmanagement/service/rest/HostRoa.java | 183 ++++++++ .../nfvo/resmanagement/service/rest/LimitsRoa.java | 73 +++ .../resmanagement/service/rest/LocationRoa.java | 316 +++++++++++++ .../resmanagement/service/rest/NetworkRoa.java | 189 ++++++++ .../nfvo/resmanagement/service/rest/PortRoa.java | 183 ++++++++ .../resmanagement/service/rest/ResOperateRoa.java | 151 +++++++ .../nfvo/resmanagement/service/rest/SitesRoa.java | 224 +++++++++ .../resmanagement/service/rest/SwaggerRoa.java | 49 ++ .../resmanagement/service/rest/VirtualLinkRoa.java | 129 ++++++ .../vfc/nfvo/resmanagement/service/rest/VmRoa.java | 127 ++++++ .../resmanagement/service/rest/VnfInfoRoa.java | 129 ++++++ .../nfvo/resmanagement/service/rest/VnfRoa.java | 128 ++++++ .../resmanagement/service/rest/VnfStatusRoa.java | 129 ++++++ .../rest/exceptionmapper/ExceptionMessage.java | 64 +++ .../exceptionmapper/GenericExceptionMapper.java | 41 ++ .../exceptionmapper/ServiceExceptionMapper.java | 45 ++ .../main/resources/mybatis/mysql/HostMapper.xml | 14 +- .../resources/mybatis/mysql/LocationMapper.xml | 12 +- .../main/resources/mybatis/mysql/NetworkMapper.xml | 14 +- .../main/resources/mybatis/mysql/PortMapper.xml | 14 +- .../main/resources/mybatis/mysql/SitesMapper.xml | 14 +- .../src/main/resources/mybatis/mysql/VimMapper.xml | 6 +- .../resources/mybatis/mysql/VirtualLinkMapper.xml | 12 +- .../src/main/resources/mybatis/mysql/VmMapper.xml | 12 +- .../main/resources/mybatis/mysql/VnfInfoMapper.xml | 12 +- .../src/main/resources/mybatis/mysql/VnfMapper.xml | 12 +- .../resources/mybatis/mysql/VnfStatusMapper.xml | 12 +- .../resources/spring/Resmanagement/services.xml | 100 ++-- .../spring/Resmanagement/svc_register.xml | 4 +- .../onap/vfc/nfvo/res/common/ResourceUtilTest.java | 52 --- .../org/onap/vfc/nfvo/res/common/VimUtilTest.java | 49 -- .../vfc/nfvo/res/common/util/JsonUtilTest.java | 436 ------------------ .../vfc/nfvo/res/common/util/RestfulUtilTest.java | 245 ---------- .../vfc/nfvo/res/common/util/StringUtilTest.java | 144 ------ .../res/common/util/request/RequestUtilTest.java | 253 ----------- .../res/common/util/response/ResponseUtilTest.java | 91 ---- .../common/util/response/RoaResponseUtilTest.java | 148 ------ .../adapter/impl/ResmgrAdapter2MSBManagerTest.java | 241 ---------- .../adapter/impl/ResmgrAdapterMgrServiceTest.java | 69 --- .../service/base/openstack/impl/HostImplTest.java | 162 ------- .../base/openstack/impl/LocationImplTest.java | 501 --------------------- .../base/openstack/impl/NetworkImplTest.java | 276 ------------ .../service/base/openstack/impl/PortImplTest.java | 154 ------- .../service/base/openstack/impl/SitesImplTest.java | 149 ------ .../service/base/openstack/impl/VimImplTest.java | 135 ------ .../business/impl/HostBusinessImplTest.java | 88 ---- .../business/impl/LimitsBusinessImplTest.java | 72 --- .../business/impl/LocationBusinessImplTest.java | 220 --------- .../business/impl/SitesBusinessImplTest.java | 409 ----------------- .../service/business/impl/VimBusinessImplTest.java | 178 -------- .../nfvo/res/service/dao/impl/HostDaoImplTest.java | 157 ------- .../res/service/dao/impl/LocationDaoImplTest.java | 88 ---- .../res/service/dao/impl/NetworkDaoImplTest.java | 155 ------- .../nfvo/res/service/dao/impl/PortDaoImplTest.java | 160 ------- .../res/service/dao/impl/SitesDaoImplTest.java | 134 ------ .../nfvo/res/service/dao/impl/VimDaoImplTest.java | 79 ---- .../service/dao/impl/VirtualLinkDaoImplTest.java | 51 --- .../nfvo/res/service/dao/impl/VmDaoImplTest.java | 53 --- .../nfvo/res/service/entity/HostEntityTest.java | 39 -- .../res/service/entity/LocationEntityTest.java | 46 -- .../nfvo/res/service/entity/NetworkEntityTest.java | 50 -- .../nfvo/res/service/entity/PortEntityTest.java | 48 -- .../nfvo/res/service/entity/SitesEntityTest.java | 111 ----- .../vfc/nfvo/res/service/entity/VimEntityTest.java | 43 -- .../res/service/rest/GrantResourseRoaTest.java | 167 ------- .../vfc/nfvo/res/service/rest/HostRoaTest.java | 201 --------- .../vfc/nfvo/res/service/rest/LimitsRoaTest.java | 69 --- .../vfc/nfvo/res/service/rest/LocationRoaTest.java | 390 ---------------- .../vfc/nfvo/res/service/rest/NetworkRoaTest.java | 215 --------- .../vfc/nfvo/res/service/rest/PortRoaTest.java | 215 --------- .../nfvo/res/service/rest/ResOperateRoaTest.java | 198 -------- .../vfc/nfvo/res/service/rest/SitesRoaTest.java | 280 ------------ .../vfc/nfvo/res/service/rest/SwaggerRoaTest.java | 57 --- .../nfvo/res/service/rest/VirtualLinkRoaTest.java | 193 -------- .../onap/vfc/nfvo/res/service/rest/VmRoaTest.java | 194 -------- .../vfc/nfvo/res/service/rest/VnfInfoRoaTest.java | 179 -------- .../onap/vfc/nfvo/res/service/rest/VnfRoaTest.java | 192 -------- .../nfvo/res/service/rest/VnfStatusRoaTest.java | 179 -------- .../rest/exceptionmapper/ExceptionMessageTest.java | 69 --- .../GenericExceptionMapperTest.java | 44 -- .../ServiceExceptionMapperTest.java | 45 -- .../resmanagement/common/ResourceUtilTest.java | 52 +++ .../vfc/nfvo/resmanagement/common/VimUtilTest.java | 49 ++ .../resmanagement/common/util/JsonUtilTest.java | 436 ++++++++++++++++++ .../resmanagement/common/util/RestfulUtilTest.java | 245 ++++++++++ .../resmanagement/common/util/StringUtilTest.java | 144 ++++++ .../common/util/request/RequestUtilTest.java | 253 +++++++++++ .../common/util/response/ResponseUtilTest.java | 91 ++++ .../common/util/response/RoaResponseUtilTest.java | 148 ++++++ .../adapter/impl/ResmgrAdapter2MSBManagerTest.java | 241 ++++++++++ .../adapter/impl/ResmgrAdapterMgrServiceTest.java | 69 +++ .../service/base/openstack/impl/HostImplTest.java | 162 +++++++ .../base/openstack/impl/LocationImplTest.java | 501 +++++++++++++++++++++ .../base/openstack/impl/NetworkImplTest.java | 276 ++++++++++++ .../service/base/openstack/impl/PortImplTest.java | 154 +++++++ .../service/base/openstack/impl/SitesImplTest.java | 149 ++++++ .../service/base/openstack/impl/VimImplTest.java | 135 ++++++ .../business/impl/HostBusinessImplTest.java | 88 ++++ .../business/impl/LimitsBusinessImplTest.java | 72 +++ .../business/impl/LocationBusinessImplTest.java | 220 +++++++++ .../business/impl/SitesBusinessImplTest.java | 409 +++++++++++++++++ .../service/business/impl/VimBusinessImplTest.java | 178 ++++++++ .../service/dao/impl/HostDaoImplTest.java | 157 +++++++ .../service/dao/impl/LocationDaoImplTest.java | 88 ++++ .../service/dao/impl/NetworkDaoImplTest.java | 155 +++++++ .../service/dao/impl/PortDaoImplTest.java | 160 +++++++ .../service/dao/impl/SitesDaoImplTest.java | 134 ++++++ .../service/dao/impl/VimDaoImplTest.java | 79 ++++ .../service/dao/impl/VirtualLinkDaoImplTest.java | 51 +++ .../service/dao/impl/VmDaoImplTest.java | 53 +++ .../service/entity/HostEntityTest.java | 39 ++ .../service/entity/LocationEntityTest.java | 46 ++ .../service/entity/NetworkEntityTest.java | 50 ++ .../service/entity/PortEntityTest.java | 48 ++ .../service/entity/SitesEntityTest.java | 111 +++++ .../service/entity/VimEntityTest.java | 43 ++ .../service/rest/GrantResourseRoaTest.java | 167 +++++++ .../resmanagement/service/rest/HostRoaTest.java | 201 +++++++++ .../resmanagement/service/rest/LimitsRoaTest.java | 69 +++ .../service/rest/LocationRoaTest.java | 390 ++++++++++++++++ .../resmanagement/service/rest/NetworkRoaTest.java | 215 +++++++++ .../resmanagement/service/rest/PortRoaTest.java | 215 +++++++++ .../service/rest/ResOperateRoaTest.java | 198 ++++++++ .../resmanagement/service/rest/SitesRoaTest.java | 280 ++++++++++++ .../resmanagement/service/rest/SwaggerRoaTest.java | 57 +++ .../service/rest/VirtualLinkRoaTest.java | 193 ++++++++ .../nfvo/resmanagement/service/rest/VmRoaTest.java | 194 ++++++++ .../resmanagement/service/rest/VnfInfoRoaTest.java | 179 ++++++++ .../resmanagement/service/rest/VnfRoaTest.java | 192 ++++++++ .../service/rest/VnfStatusRoaTest.java | 179 ++++++++ .../rest/exceptionmapper/ExceptionMessageTest.java | 69 +++ .../GenericExceptionMapperTest.java | 44 ++ .../ServiceExceptionMapperTest.java | 45 ++ pom.xml | 2 +- 371 files changed, 23506 insertions(+), 23506 deletions(-) delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/ResourceUtil.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/VimUtil.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/Constant.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/HttpConstant.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/ParamConstant.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/ResponseConstant.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/UrlConstant.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/JsonUtil.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/RestfulUtil.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/StringUtil.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/request/RequestUtil.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/response/ResponseUtil.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/response/RoaResponseUtil.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/activator/ROAResmgrServicePostProcessor.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapter2MSBManager.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapterMgrService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/inf/IResmgrAdapter2MSBManager.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/inf/IResmgrAdapterMgrService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/HostImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/LocationImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/NetworkImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/PortImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/SitesImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/VimImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Host.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/InterfaceResManagement.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Location.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Network.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Port.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/ResManagement.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Sites.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Vim.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/HostBusinessImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/LimitsBusinessImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/LocationBusinessImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/NetworkBusinessImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/PortBusinessImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/SitesBusinessImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/VimBusinessImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/HostBusiness.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/LimitsBusiness.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/LocationBusiness.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/NetworkBusiness.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/PortBusiness.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/SitesBusiness.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/VimBusiness.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/AbstractDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/HostDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/LocationDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/NetworkDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/PortDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/SitesDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VimDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VirtualLinkDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VmDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfInfoDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfStatusDaoImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/HostDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/LocationDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/NetworkDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/PortDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/SitesDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VimDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VirtualLinkDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VmDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfInfoDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfStatusDao.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/HostEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/LocationEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/NetworkEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/PortEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/SitesEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VimEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VirtualLinkEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VmEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfInfoEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfStatusEntity.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/GrantResServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceAddServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceDelServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceUpdateServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/ResOperateServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VirtualLinkServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VmServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfInfoServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfStatusServiceImpl.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/GrantResService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/ResOperateService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VirtualLinkService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VmService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfInfoService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfStatusService.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/HostMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/LocationMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/NetworkMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/PortMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/SitesMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VimMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VirtualLinkMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VmMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfInfoMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfStatusMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/GrantResourseRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/HostRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/LimitsRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/LocationRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/NetworkRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/PortRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/ResOperateRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/SitesRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/SwaggerRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VirtualLinkRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VmRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfInfoRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfStatusRoa.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ExceptionMessage.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/GenericExceptionMapper.java delete mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ServiceExceptionMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/ResourceUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/HttpConstant.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/ParamConstant.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/ResponseConstant.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/activator/ROAResmgrServicePostProcessor.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManager.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/inf/IResmgrAdapter2MSBManager.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/inf/IResmgrAdapterMgrService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/HostImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/LocationImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/NetworkImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/PortImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/VimImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Host.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/InterfaceResManagement.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Location.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Network.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Port.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/ResManagement.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Sites.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Vim.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/HostBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LimitsBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LocationBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/NetworkBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/PortBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/SitesBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/VimBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/HostBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/LimitsBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/LocationBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/NetworkBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/PortBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/SitesBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/VimBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/AbstractDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/HostDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/LocationDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/NetworkDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/PortDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/SitesDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VimDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VmDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfInfoDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfStatusDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/HostDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/LocationDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/NetworkDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/PortDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/SitesDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VimDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VirtualLinkDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VmDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfInfoDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfStatusDao.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/HostEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/LocationEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NetworkEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/PortEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/SitesEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VimEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VirtualLinkEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfInfoEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfStatusEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceAddServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceDelServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceUpdateServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/ResOperateServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VirtualLinkServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfInfoServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfStatusServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/GrantResService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/ResOperateService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VirtualLinkService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VmService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfInfoService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfStatusService.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/HostMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/LocationMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/NetworkMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/PortMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/SitesMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VimMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VirtualLinkMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VmMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfInfoMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfStatusMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/GrantResourseRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/HostRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/LimitsRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/LocationRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NetworkRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/PortRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/ResOperateRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/SitesRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/SwaggerRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VirtualLinkRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VmRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfInfoRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfStatusRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessage.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapper.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/ResourceUtilTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/VimUtilTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/JsonUtilTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/RestfulUtilTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/StringUtilTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/request/RequestUtilTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/response/ResponseUtilTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/response/RoaResponseUtilTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapterMgrServiceTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/HostImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/LocationImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/NetworkImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/PortImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/SitesImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/VimImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/HostBusinessImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/LimitsBusinessImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/LocationBusinessImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/SitesBusinessImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/VimBusinessImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/HostDaoImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/LocationDaoImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/NetworkDaoImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/PortDaoImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/SitesDaoImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VimDaoImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VirtualLinkDaoImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VmDaoImplTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/HostEntityTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/LocationEntityTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/NetworkEntityTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/PortEntityTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/SitesEntityTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/VimEntityTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/GrantResourseRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/HostRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/LimitsRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/LocationRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/NetworkRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/PortRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/ResOperateRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/SitesRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/SwaggerRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VirtualLinkRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VmRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfInfoRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfStatusRoaTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ExceptionMessageTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/GenericExceptionMapperTest.java delete mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ServiceExceptionMapperTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/ResourceUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/VimUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/HostEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/LocationEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/NetworkEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/PortEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/SitesEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/VimEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/HostRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/LimitsRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/LocationRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/NetworkRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/PortRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/ResOperateRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/SitesRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/SwaggerRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VmRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java create mode 100644 ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java diff --git a/ResmanagementService/deployment/pom.xml b/ResmanagementService/deployment/pom.xml index ed47629..926a7c6 100644 --- a/ResmanagementService/deployment/pom.xml +++ b/ResmanagementService/deployment/pom.xml @@ -17,7 +17,7 @@ 4.0.0 - org.onap.vfc.nfvo.res + org.onap.vfc.nfvo.resmanagement resmanagement-service-root 1.0.0-SNAPSHOT diff --git a/ResmanagementService/pom.xml b/ResmanagementService/pom.xml index 4b3a6c1..7fe4eb1 100644 --- a/ResmanagementService/pom.xml +++ b/ResmanagementService/pom.xml @@ -18,7 +18,7 @@ 4.0.0 resmanagement - org.onap.vfc.nfvo.res + org.onap.vfc.nfvo.resmanagement 1.0.0-SNAPSHOT resmanagement-service-root diff --git a/ResmanagementService/service/pom.xml b/ResmanagementService/service/pom.xml index 5de8505..398a1eb 100644 --- a/ResmanagementService/service/pom.xml +++ b/ResmanagementService/service/pom.xml @@ -17,7 +17,7 @@ 4.0.0 - org.onap.vfc.nfvo.res + org.onap.vfc.nfvo.resmanagement resmanagement-service-root 1.0.0-SNAPSHOT diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/ResourceUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/ResourceUtil.java deleted file mode 100644 index d38459a..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/ResourceUtil.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public class ResourceUtil { - - private ResourceUtil() { - - } - - /** - * It is used to get Message
- * - * @param key - * @return - * @since NFVO 0.5 - */ - public static String getMessage(String key) { - return key; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/VimUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/VimUtil.java deleted file mode 100644 index 6dc3121..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/VimUtil.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common; - -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 30, 2016 - */ -public class VimUtil { - - private static final Logger LOG = LoggerFactory.getLogger(VimUtil.class); - - private VimUtil() { - - } - - /** - * Get VIMs. - * - * @return - */ - public static JSONArray getVims() { - String esrResponse = - RestfulUtil.getResponseContent(UrlConstant.ESR_GET_VIMS_URL, new RestfulParametes(), "get"); - LOG.info("Get vims from ESR! EsrResponse:{}", esrResponse); - if(null == esrResponse) { - LOG.error("ESR return fail."); - return null; - } else { - return JSONArray.fromObject(esrResponse); - } - - } - - /** - * Get vimId by vimName. - * - * @return - */ - public static String getVimIdByName(String name) { - JSONArray vims = getVims(); - for(int i = 0; i < vims.size(); i++) { - JSONObject vim = vims.getJSONObject(i); - LOG.info("vimInfo: " + vim); - String vimName = vim.getString("name"); - String vimId = vim.getString("vimId"); - LOG.info("name:" + name + ", vimName:" + vimName + ", vimId:" + vimId); - if(name.trim().equalsIgnoreCase(vimName)) { - return vimId; - } - } - LOG.error("No vim with this vimName"); - return ""; - - } - - /** - * Get VIM. - * - * @param vimId - * @return - */ - public static JSONObject getVimById(String vimId) { - if(vimId == null || "".equals(vimId.trim())) { - LOG.error("Get vim ERROR, VimId is null. "); - return null; - } - JSONObject esrResponse = RestfulUtil.getResponseObj(String.format(UrlConstant.ESR_GET_VIM_URL, vimId), "get"); - LOG.info("Get vims from ESR! EsrResponse:{}", esrResponse); - if(null == esrResponse) { - LOG.error("ESR return fail."); - return null; - } else { - return esrResponse; - } - } - - /** - * Get tenants. - * - * @param vimId - * @return - */ - public static JSONArray getTenants(String vimId) { - String url = String.format(UrlConstant.GET_TENANT_URL, vimId); - JSONObject resultObj = RestfulUtil.getResponseObj(url, ParamConstant.PARAM_GET); - JSONArray tenants = resultObj.getJSONArray("tenants"); - LOG.info("Get tenants from multivim! tenants:{}", tenants); - return tenants; - } - - /** - *
- * - * @param tenant - * @param vimId - * @return - * @since NFVO 0.5 - */ - public static String getTenantIdByName(String tenant, String vimId) { - JSONArray tenants = VimUtil.getTenants(vimId); - String tenantId = ""; - for(int i = 0; i < tenants.size(); i++) { - JSONObject obj = tenants.getJSONObject(i); - String name = obj.getString("name"); - if(name.equalsIgnoreCase(tenant)) { - tenantId = obj.getString("id"); - } - } - LOG.info("GetTenantIdByName tenantId:{}", tenantId); - return tenantId; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/Constant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/Constant.java deleted file mode 100644 index d26c63e..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/Constant.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.constant; - -/** - * HTTP constants
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public class Constant { - - public static final String RES_MANAGEMENT_DB = "resmanagementdb"; - - /** - * Database Delete/Modify/Add fail. - */ - public static final int ERROR_CODE = -1; - - /** - * Database Delete/Modify/Add success. - */ - public static final int OK_CODE = 1; - - /** - * Lack of resource. - */ - public static final int RES_NOT_ENOUGH_CODE = -2; - - /** - * Module name. - */ - public static final String MODULE_NAME = "Resmanagement"; - - public static final String RESPONSE_CONTENT = "responseContent"; - - public static final String STATUS_CODE = "statusCode"; - - /** - * Format Time - */ - public static final String DATE_FORMATE = "yyyy-MM-dd HH:mm:ss"; - - public static final String DATE_UTC_FORMATE = "yyyy-MM-dd'T'HH:mm:ss'Z'"; - - public static final String UTC_FORMATE = "UTC"; - - public static final String DATE_DAY_FORMATE = "yyyy-MM-dd 00:00:00"; - - /** - * IAM - */ - - public static final String HTTP_CONTENT_TYPE = "Content-Type"; - - public static final String HTTP_CONTENT_TYPE_VALUE = "application/json;charset=UTF-8"; - - public static final String X_TENANT_ID = "X-Tenant-Id"; - - public static final String IAM_TOKEN = "x-auth-token"; - - public static final String IAM_AUTH_TOKEN = "X-Auth-Token"; - - public static final String IAM_USER_ID = "X-User-Id"; - - public static final String IAM_USER_NAME = "X-User-Name"; - - public static final String IAM_DOMAIN_NAME = "X-Domain-Name"; - - public static final String HEADER_SUBJECT_TOKEN = "X-Subject-Token"; - - public static final int REPEAT_REG_TIME = 60 * 1000; - - private Constant() { - // private constants - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/HttpConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/HttpConstant.java deleted file mode 100644 index a81dff5..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/HttpConstant.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.constant; - -/** - * - * Http constant class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class HttpConstant { - - public static final int ERROR_CODE = -1; - - public static final int OK_CODE = 1; - - public static final int HTTP_OK = 200; - - public static final int HTTP_CREATED = 201; - - public static final int HTTP_ACCEPTED = 202; - - public static final int HTTP_NOCONTENT = 204; - - public static final int HTTP_UNAUTHORIZED = 401; - - public static final int HTTP_BAD_REQUEST = 400; - - public static final int HTTP_NOTFOUND_CODE = 404; - - public static final int HTTP_CONFLICT_CODE = 409; - - public static final int HTTP_INVALID_PARAMETERS = 415; - - public static final int HTTP_INNERERROR_CODE = 500; - - public static final int INTERNAL_EXCEPTION_CODE = 600; - - public static final int TOKEN_HEAD_NULL_CODE = 601; - - public static final int TOKEN_USER_NULL_CODE = 602; - - public static final int SERVICE_URL_ERROR_CODE = 603; - - public static final int ACCESS_OBJ_NULL_CODE = 604; - - public static final int CONNECT_NOT_FOUND_CODE = 605; - - public static final int VCENTER_PARA_ERROR_CODE = 606; - - public static final int TYPE_PARA_ERROR_CODE = 607; - - public static final int CONNECT_FAIL_CODE = 608; - - public static final int DIS_CONNECT_FAIL_CODE = 609; - - public static final int HANDSHAKE_FAIL_CODE = 610; - - private HttpConstant() { - //private constructor - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/ParamConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/ParamConstant.java deleted file mode 100644 index 870e4a7..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/ParamConstant.java +++ /dev/null @@ -1,370 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.constant; - -/** - *
- *

- * Contstant for System interactive. - *

- * - * @author - * @version NFVO 0.5 2016-3-17 - */ -public class ParamConstant { - - /** - * param key: vimId. - */ - public static final String PARAM_VIMID = "vimId"; - - /** - * param key: vimName - */ - public static final String PARAM_VIMNAME = "vimName"; - - /** - * param key: tenantId. - */ - public static final String PARAM_TENANTID = "tenantId"; - - public static final String TOTAL_CPU = "totalCPU"; - - public static final String USED_CPU = "usedCPU"; - - public static final String TOTAL_MEMORY = "totalMemory"; - - public static final String USED_MEMORY = "usedMemory"; - - public static final String TOTAL_DISK = "totalDisk"; - - public static final String USED_DISK = "usedDisk"; - - /** - * param key: data. - */ - public static final String PARAM_DATA = "data"; - - /** - * param key: id. - */ - public static final String PARAM_ID = "id"; - - /** - * param key: vimId - */ - public static final String PARAM_IP = "ip"; - - /** - * param key: role. - */ - public static final String PARAM_ROLE = "role"; - - /** - * param key: roleId. - */ - public static final String PARAM_ROLEID = "roleId"; - - /** - * param key: total. - */ - public static final String PARAM_TOTAL = "total"; - - /** - * param key: used. - */ - public static final String PARAM_USED = "used"; - - /** - * param key: vcpus. - */ - public static final String PARAM_VCPUS = "vcpus"; - - /** - * param key: disk. - */ - public static final String PARAM_DISK = "disk"; - - /** - * param key: cpumhz. - */ - public static final String PARAM_CPUMHZ = "cpumhz"; - - /** - * param key: countyr - */ - public static final String PARAM_COUNTRY = "country"; - - /** - * param key: vendorId - */ - public static final String PARAM_VENDORID = "vendorId"; - - /** - * param key: vendorName - */ - public static final String PARAM_VENDORNAME = "vendorName"; - - /** - * param key: memory. - */ - public static final String PARAM_MEMORY = "memory"; - - /** - * param key: name. - */ - public static final String PARAM_NAME = "name"; - - /** - * param key: status. - */ - public static final String PARAM_STATUS = "status"; - - /** - * param key: parent. - */ - public static final String PARAM_PARENT = "parent"; - - /** - * param key: location. - */ - public static final String PARAM_LOCATION = "location"; - - /** - * param key: siteName. - */ - public static final String PARAM_SITENAME = "siteName"; - - /** - * param key: vendor. - */ - public static final String PARAM_VENDOR = "vendor"; - - /** - * param key: vendors. - */ - public static final String PARAM_VENDORS = "vendors"; - - /** - * param key: tenantSites. - */ - public static final String PARAM_TENANTSITES = "tenantSites"; - - /** - * param key: siteId. - */ - public static final String PARAM_SITEID = "siteId"; - - /** - * param key: resArbitration. - */ - public static final String PARAM_RESARBITRATION = "resArbitration"; - - /** - * param key: userRole. - */ - public static final String PARAM_USERROLE = "userRole"; - - /** - * param key: admin. - */ - public static final String PARAM_ADMIN = "admin"; - - /** - * param key: tenant. - */ - public static final String PARAM_TENANT = "tenant"; - - /** - * param key: type. - */ - public static final String PARAM_TYPE = "type"; - - /** - * param key: action. - */ - public static final String PARAM_ACTION = "action"; - - /** - * param key: offline. - */ - public static final String PARAM_OFFLINE = "offline"; - - /** - * param key: online. - */ - public static final String PARAM_ONLINE = "online"; - - /** - * param key: drexecute. - */ - public static final String PARAM_DREXECUTE = "drexecute"; - - /** - * param key: drRollBack. - */ - public static final String PARAM_DRROLLBACK = "drrollback"; - - /** - * param key: scaleOut. - */ - public static final String PARAM_SCALEOUT = "scaleout"; - - /** - * param key: scaleIn. - */ - public static final String PARAM_SCALEIN = "scalein"; - - /** - * param key: network. - */ - public static final String PARAM_NETWORK = "networks"; - - /** - * param key: host. - */ - public static final String PARAM_HOST = "hosts"; - - /** - * param key: network. - */ - public static final String PARAM_PORT = "ports"; - - /** - * param key: providernetworks. - */ - public static final String PARAM_PROVIDERNETWORKS = "providernetworks"; - - /** - * param key: vims. - */ - public static final String PARAM_VIMS = "vims"; - - /** - * param key: vms. - */ - public static final String PARAM_VMS = "vms"; - - /** - * param key: vapps. - */ - public static final String PARAM_VAPPS = "vapps"; - - /** - * param key: vapp. - */ - public static final String PARAM_VAPP = "vapp"; - - /** - * param key: sites. - */ - public static final String PARAM_SITES = "sites"; - - /** - * param key: vduId. - */ - public static final String PARAM_VDUID = "vduId"; - - /** - * param key: vappId. - */ - public static final String PARAM_VAPPID = "vappId"; - - /** - * param key: hostId. - */ - public static final String PARAM_HOSTID = "hostId"; - - /** - * param key: projectId. - */ - public static final String PARAM_PROJECTID = "projectId"; - - /** - * param key: vnfmId. - */ - public static final String PARAM_VNFMID = "vnfmId"; - - /** - * param key: params. - */ - public static final String PARAM_PARAMS = "params"; - - /** - * param key: url. - */ - public static final String PARAM_URL = "url"; - - /** - * param key: post. - */ - public static final String PARAM_POST = "post"; - - /** - * param key: put. - */ - public static final String PARAM_PUT = "put"; - - /** - * param key: del. - */ - public static final String PARAM_DEL = "del"; - - /** - * param key: get. - */ - public static final String PARAM_GET = "get"; - - /** - * param key: retCode. - */ - public static final String PARAM_RETCODE = "retCode"; - - /** - * param key: ADD. - */ - public static final String PARAM_ADD = "add"; - - /** - * param key: active. - */ - public static final String PARAM_ACTIVE = "active"; - - /** - * param key: deleted. - */ - public static final String PARAM_DELETED = "deleted"; - - /** - * param key: deleting. - */ - public static final String PARAM_DELETING = "deleting"; - - /** - * param key: response - */ - public static final String PARAM_RESPONSE = "response"; - - /** - * param key: info - */ - public static final String PARAM_INFO = "info"; - - private ParamConstant() { - // private constructor - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/ResponseConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/ResponseConstant.java deleted file mode 100644 index 5e7126c..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/ResponseConstant.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.constant; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; - -/** - * Response constants.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public class ResponseConstant { - - public static final String ADD_SUCESS_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.add.success"); - - public static final String ADD_FAIL_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.add.error"); - - public static final String DEL_SUCESS_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.del.success"); - - public static final String DEL_FAIL_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.del.error"); - - public static final String MOD_SUCESS_MSG = - ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.update.success"); - - public static final String MOD_FAIL_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.update.error"); - - public static final String QUERY_SUCESS_MSG = - ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.query.success"); - - public static final String QUERY_FAIL_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.query.error"); - - public static final String DELSODORES_FAIL_MSG = "delete sodores error"; - - public static final String DELVNFMINFO_FAIL_MSG = "delete vnfm error"; - - public static final String RES_VERIFY_SUCESS_MSG = "nsdata verify sucessfully"; - - public static final String RES_VERIFY_FAIL_MSG = "res verify failed"; - - private ResponseConstant() { - // private constructor - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/UrlConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/UrlConstant.java deleted file mode 100644 index 572bff3..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/constant/UrlConstant.java +++ /dev/null @@ -1,258 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.constant; - -/** - *
- *

- * Constant for REST URL. - *

- * - * @author - * @version NFVO 0.5 2016-3-17 - */ -public class UrlConstant { - - /** - * networks target. - */ - public static final String LOCATION_TARGET = "location"; - - /** - * MSB register url. - */ - public static final String REST_MSB_REGISTER = "/openoapi/microservices/v1/services"; - - public static final String ESR_GET_VIM_URL = "/openoapi/extsys/v1/vims/%s"; - - public static final String ESR_GET_VIMS_URL = "/openoapi/extsys/v1/vims"; - - /** - * send resource info to monitor url - */ - public static final String SEND_MSG_MONITOR = "/openoapi/umc/v1/resinfo"; - - /** - * networks url. - */ - public static final String LOCATION_URL = "/v1/locations"; - - /** - * port url. - */ - public static final String PORT_URL = "/v1/ports"; - - /** - * host url. - */ - public static final String HOST_URL = "/v1/hosts"; - - /** - * vl url. - */ - public static final String VL_URL = "/v1/vl"; - - /** - * vnf url. - */ - public static final String VNF_URL = "/v1/vnf"; - - /** - * vnfinfo url. - */ - public static final String VNFINFO_URL = "/v1/vnfinfo"; - - /** - * vnfstatus url. - */ - public static final String VNFSTATUS_URL = "/v1/vnfstatus"; - - /** - * grant resource url. - */ - public static final String GRANTRES_URL = "/v1/resource/grant"; - - /** - * vm url. - */ - public static final String VM_URL = "/v1/vm"; - - /** - * sites target. - */ - public static final String SITES_TARGET = "sites"; - - /** - * sites url. - */ - public static final String SITES_URL = "/v1/datacenters"; - - /** - * networks target. - */ - public static final String NETWORKS_TARGET = "networks"; - - /** - * networks url. - */ - public static final String NETWORKS_URL = "/v1/networks"; - - /** - * updateres. - */ - public static final String MODRES_URL = "/updateres"; - - /** - * resoperate target. - */ - public static final String RESOPERATE_TARGET = "resoperate"; - - /** - * APPLICATION_TYPE. - */ - public static final String APPLICATION_TYPE = "application/json"; - - /** - * ADDRES. - */ - public static final String ADDRES_URL = "/resmgr/vims"; - - /** - * updatebytenant. - */ - public static final String UPDATE_BY_TENANT = "updatebytenant"; - - /** - * updatebyvapp. - */ - public static final String UPDATE_BY_VAPP = "updatebyvapp"; - - /** - * getNetworkURL. - */ - public static final String GET_NETWORK_URL = "/openoapi/multivim/v1/%s/%s/networks"; - - /** - * getTenantURL. - */ - public static final String GET_TENANT_URL = "/openoapi/multivim/v1/%s/tenants"; - - /** - * getHostURL. - */ - public static final String GET_HOST_URL = "/openoapi/multivim/v1/%s/%s/hosts"; - - /** - * getHostDetailURL. - */ - public static final String GET_HOSTDETAIL_URL = "/openoapi/multivim/v1/%s/%s/hosts/%s"; - - /** - * getNetworkURL. - */ - public static final String GET_PORT_URL = "/openoapi/multivim/v1/%s/%s/ports"; - - /** - * getLimitsURL. - */ - public static final String GET_LIMITS_URL = "/openoapi/multivim/v1/%s/%s/limits"; - - /** - * template notify M url. - */ - public static final String TEMPLATE_NOTIFY_M_URL = ""; - - /** - * tenantsite allot url. - */ - public static final String TENANTSITE_ALLOT_URL = "/v1/resmanage/tenantsite/allot"; - - /** - * tenantsite allot target. - */ - public static final String TENANTSITE_ALLOT_TARGET = "tenantsite/allot"; - - /** - * tenant url. - */ - public static final String TENANT_URL = "/v1/resmanage/tenant"; - - /** - * tenant target. - */ - public static final String TENANT_TARGET = "tenant"; - - /** - * rollback url. - */ - public static final String ROLLBACK_URL = "/v1/resmanage/rollback"; - - /** - * rollback target. - */ - public static final String ROLLBACK_TARGET = "rollback"; - - /** - * vms target. - */ - public static final String VIM_TARGET = "vim"; - - /** - * vms url. - */ - public static final String VIM_URL = "/v1/resmanage/vim"; - - /** - * https - */ - public static final String GET_HTTPS = "https://"; - - /** - * get token - */ - public static final String GET_IAM_TOKEN = "/v3/auth/tokens"; - - /** - * rest. - */ - public static final String REST = "/rest"; - - /** - * donsdata url. - */ - public static final String INSTALL_URL = "install"; - - /** - * donsdata url. - */ - public static final String UNINSTALL_URL = "uninstall"; - - /** - * respool url. - */ - public static final String RESOPERATE_URL = "/v1/resoperate"; - - /** - * limits url. - */ - public static final String LIMITS_URL = "/v1/limits"; - - private UrlConstant() { - // private constructor - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/JsonUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/JsonUtil.java deleted file mode 100644 index 2b6e905..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/JsonUtil.java +++ /dev/null @@ -1,290 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util; - -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONArray; -import net.sf.json.JSONException; -import net.sf.json.JSONObject; - -/** - * - * Json Utility Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public final class JsonUtil { - - private static final Logger LOG = LoggerFactory.getLogger(StringUtil.class); - - private static final int TYPE_STRING = 0; - - private static final int TYPE_INT = 1; - - private static final int TYPE_JSONA = 2; - - private static final int TYPE_JSONO = 3; - - private static final int TYPE_LONG = 4; - - private JsonUtil() { - } - - /** - * - * Get Json Field String.
- * - * @param jsonObj - * @param fieldName - * @return - * @since NFVO 0.5 - */ - public static String getJsonFieldStr(JSONObject jsonObj, String fieldName) { - return (String)getJsonFieldObject(jsonObj, fieldName, TYPE_STRING); - } - - /** - * - * Get Json Field Integer.
- * - * @param jsonObj - * @param fieldName - * @return - * @since NFVO 0.5 - */ - public static Integer getJsonFieldInt(JSONObject jsonObj, String fieldName) { - return (Integer)getJsonFieldObject(jsonObj, fieldName, TYPE_INT); - } - - /** - * - * Get Json Field array.
- * - * @param jsonObj - * @param fieldName - * @return - * @since NFVO 0.5 - */ - public static JSONArray getJsonFieldArr(JSONObject jsonObj, String fieldName) { - return (JSONArray)getJsonFieldObject(jsonObj, fieldName, TYPE_JSONA); - } - - /** - * - * Get Json Field Json.
- * - * @param jsonObj - * @param fieldName - * @return - * @since NFVO 0.5 - */ - public static JSONObject getJsonFieldJson(JSONObject jsonObj, String fieldName) { - return (JSONObject)getJsonFieldObject(jsonObj, fieldName, TYPE_JSONO); - } - - /** - * - * Get Json Field Long.
- * - * @param jsonObj - * @param fieldName - * @return - * @since NFVO 0.5 - */ - public static Long getJsonFieldLong(JSONObject jsonObj, String fieldName) { - return (Long)getJsonFieldObject(jsonObj, fieldName, TYPE_LONG); - } - - /** - * - * Get Json Field Object.
- * - * @param jsonObj - * @param fieldName - * @param classType - * @return - * @since NFVO 0.5 - */ - private static Object getJsonFieldObject(JSONObject jsonObj, String fieldName, int classType) { - try { - if(null != jsonObj && jsonObj.has(fieldName)) { - Object result = new Object(); - switch(classType) { - case TYPE_STRING: - result = "null".equals(jsonObj.getString(fieldName)) ? "" : jsonObj.getString(fieldName); - break; - case TYPE_INT: - result = jsonObj.getInt(fieldName); - break; - case TYPE_JSONA: - result = jsonObj.getJSONArray(fieldName); - break; - case TYPE_JSONO: - result = jsonObj.getJSONObject(fieldName); - break; - case TYPE_LONG: - result = jsonObj.getLong(fieldName); - break; - default: - result = null; - break; - } - return result; - } - } catch(JSONException e) { - LOG.error("function=getJsonFieldLong, exception: {} ", e); - return null; - } - return null; - } - - /** - * - * Check whether the Json Object is empty.
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static boolean isNullJson(JSONObject jsonObject) { - if(null == jsonObject || jsonObject.isEmpty()) { - return true; - } - return false; - } - - /** - * - * Get String value by Json.
- * - * @param json - * @param key - * @return - * @since NFVO 0.5 - */ - public static String getStrValueByjson(JSONObject json, String key) { - JSONArray names = json.names(); - String result = null; - for(int i = 0; i < names.size(); i++) { - String nodeName = names.getString(i); - if(json.optJSONObject(nodeName) != null) { - result = getStrValueByjson(json.getJSONObject(nodeName), key); - } - if(json.optJSONArray(nodeName) != null) { - result = getStrValueByJArray(json.getJSONArray(nodeName), key); - } - if(nodeName.equals(key)) { - result = json.getString(nodeName); - break; - } - } - return result; - } - - private static String getStrValueByJArray(JSONArray json, String key) { - String result = null; - for(int i = 0; i < json.size(); i++) { - if(json.optJSONObject(i) != null) { - result = getStrValueByjson(json.getJSONObject(i), key); - } - if(json.optJSONArray(i) != null) { - result = getStrValueByJArray(json.getJSONArray(i), key); - } - } - return result; - } - - /** - * - * Get Json Value by Json object.
- * - * @param json - * @param key - * @return - * @since NFVO 0.5 - */ - public static JSONObject getJsonValueByjson(JSONObject json, String key) { - JSONObject resultJson = new JSONObject(); - String result = getStrValueByjson(json, key); - if(null == result) { - return null; - } - resultJson.element(key, result); - return resultJson; - - } - - /** - * - * Get String Value by Json object.
- * - * @param json - * @param parentKey - * @param key - * @return - * @since NFVO 0.5 - */ - public static String getStrValueByJson(JSONObject json, String parentKey, String key) { - if(parentKey.isEmpty()) { - return getStrValueByjson(json, key); - } - JSONObject parentJson = getJsonValueByjson(json, parentKey); - if(isNullJson(parentJson)) { - return null; - } - return getStrValueByjson(parentJson, key); - - } - - /** - * - * Get response Data.
- * - * @param obj - * @return - * @since NFVO 0.5 - */ - public static JSONObject getResponseData(JSONObject obj) { - JSONObject result = new JSONObject(); - - Integer retCode = getJsonFieldInt(obj, ParamConstant.PARAM_RETCODE); - if(null == retCode || retCode == -1) { - return null; - } - - if(obj.optJSONObject(ParamConstant.PARAM_DATA) != null) { - result = obj.getJSONObject(ParamConstant.PARAM_DATA); - } else if(obj.optJSONArray(ParamConstant.PARAM_DATA) != null) { - result = obj.getJSONArray(ParamConstant.PARAM_DATA).getJSONObject(0); - } - if(result.isEmpty()) { - return null; - } - - if(result.containsKey(ParamConstant.PARAM_RETCODE)) { - result = getResponseData(result); - } - return result; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/RestfulUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/RestfulUtil.java deleted file mode 100644 index 5d7d334..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/RestfulUtil.java +++ /dev/null @@ -1,371 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util; - -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.Constant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.Restful; -import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback; -import org.openo.baseservice.roa.util.restclient.RestfulFactory; -import org.openo.baseservice.roa.util.restclient.RestfulOptions; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONArray; -import net.sf.json.JSONException; -import net.sf.json.JSONObject; - -/** - * Restful Utility Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class RestfulUtil { - - public static final String TYPE_GET = "get"; - - public static final String TYPE_PUT = "put"; - - public static final String TYPE_POST = "post"; - - public static final String TYPE_DEL = "delete"; - - public static final String CONTENT_TYPE = "Content-type"; - - public static final String APPLICATION = "application/json"; - - private static final Logger LOGGER = LoggerFactory.getLogger(RestfulUtil.class); - - private static final Restful REST_CLIENT = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); - - private RestfulUtil() { - } - - /** - * Get response object.
- * - * @param url - * @param type - * @return - * @since NFVO 0.5 - */ - public static JSONObject getResponseObj(String url, String type) { - return getResponseObj(url, new RestfulParametes(), type); - } - - /** - * Get response object.
- * - * @param url - * @param parametes - * @param type - * @return - * @since NFVO 0.5 - */ - public static JSONObject getResponseObj(String url, RestfulParametes parametes, String type) { - try { - String content = RestfulUtil.getResponseContent(url, parametes, null, type); - LOGGER.error("function=getResponseObj, content : {}", content); - if(StringUtils.isEmpty(content)) { - return null; - } - return JSONObject.fromObject(content); - } catch(JSONException e) { - LOGGER.error("function=getResponseObj, exception : {}", e); - return null; - } - } - - /** - * Get response content.
- * - * @param url - * @param restParametes - * @param type - * @return - * @since NFVO 0.5 - */ - public static String getResponseContent(String url, RestfulParametes restParametes, String type) { - return getResponseContent(url, restParametes, null, type); - } - - /** - * Get response map.
- * - * @param url - * @param restParametes - * @param opt - * @param type - * @return - * @since NFVO 0.5 - */ - public static Map getResponseMap(String url, RestfulParametes restParametes, RestfulOptions opt, - String type) { - RestfulResponse response = restfulResponse(url, restParametes, opt, type); - return getResponseMap(response); - } - - /** - * Get response content map.
- * - * @param url - * @param type - * @return - * @since NFVO 0.5 - */ - public static Map getResponseContentMap(String url, String type) { - RestfulResponse response = restfulResponse(url, new RestfulParametes(), null, type); - return getResponseMap(response); - } - - private static Map getResponseMap(RestfulResponse response) { - Map resMap = new HashMap<>(10); - if(null != response) { - resMap.put(Constant.RESPONSE_CONTENT, response.getResponseContent()); - resMap.put(Constant.STATUS_CODE, response.getStatus()); - } - return resMap; - } - - /** - * Get response content.
- * - * @param url - * @param restParametes - * @param opt - * @param type - * @return - * @since NFVO 0.5 - */ - public static String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt, - String type) { - String responseContent = null; - RestfulResponse rsp = restfulResponse(url, restParametes, opt, type); - if(rsp != null) { - int httpStatus = rsp.getStatus(); - LOGGER.warn("function=getResponseContent, get response httpStatusCode : {} ", httpStatus); - if(httpStatus < HttpServletResponse.SC_BAD_REQUEST && httpStatus > 0) { - responseContent = rsp.getResponseContent(); - LOGGER.warn("function=getResponseContent, get response data success!responseContent={}", - responseContent); - } - } - return responseContent; - } - - /** - * Get restful response.
- * - * @param url - * @param restParametes - * @param type - * @return - * @since NFVO 0.5 - */ - public static RestfulResponse getRestfulResponse(String url, RestfulParametes restParametes, String type) { - return restfulResponse(url, restParametes, null, type); - } - - private static RestfulResponse restfulResponse(String url, RestfulParametes restParametes, RestfulOptions opt, - String type) { - RestfulResponse rsp = new RestfulResponse(); - try { - - if(REST_CLIENT != null) { - if(TYPE_GET.equals(type)) { - rsp = REST_CLIENT.get(url, restParametes, opt); - } else if(TYPE_POST.equals(type)) { - rsp = REST_CLIENT.post(url, restParametes, opt); - } else if(TYPE_PUT.equals(type)) { - rsp = REST_CLIENT.put(url, restParametes, opt); - } else if(TYPE_DEL.equals(type)) { - rsp = REST_CLIENT.delete(url, restParametes, opt); - } - } - } catch(ServiceException e) { - LOGGER.error("function=restfulResponse, get restful response catch exception {} ", e); - } - LOGGER.warn("function=restfulResponse, response status is {} ", rsp.getStatus()); - return rsp; - } - - /** - * encapsulate the java reflect exception.
- * - * @param methodName, Restful's method. - * @param objects, method param array. - * @return - * @since NFVO 0.5 - */ - public static RestfulResponse getRestRes(String methodName, Object... objects) { - try { - if(objects == null || REST_CLIENT == null) { - return null; - } - - Class[] classes = new Class[objects.length]; - for(int i = 0; i < objects.length; i++) { - classes[i] = objects[i].getClass(); - } - if(methodName.startsWith("async")) { - classes[classes.length - 1] = RestfulAsyncCallback.class; - } - - Class rtType = methodName.startsWith("async") ? void.class : RestfulResponse.class; - MethodType mt = MethodType.methodType(rtType, classes); - Object result = MethodHandles.lookup().findVirtual(REST_CLIENT.getClass(), methodName, mt) - .bindTo(REST_CLIENT).invokeWithArguments(objects); - if(result != null) { - return (RestfulResponse)result; - } - LOGGER.warn("function=getRestRes, msg: invoke Restful async {} method which return type is Void.", - methodName); - return null; - } catch(ReflectiveOperationException e) { - LOGGER.error("function=getRestRes, msg=error occurs, e={}.", e); - } catch(Throwable e) {// NOSONAR - LOGGER.error("function=getRestRes, msg=Throwable, e={}.", e); - try { - throw (ServiceException)new ServiceException().initCause(e.getCause()); - } catch(ServiceException se) { - LOGGER.error("function=getRestRes, msg=ServiceException occurs, e={}.", se); - } - } - return null; - } - - /** - * Get response.
- * - * @param restParametes - * @param url - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - public static JSONArray getResponseRes(RestfulParametes restParametes, String url) throws ServiceException { - String result = getResponseContent(url, restParametes, RestfulUtil.TYPE_GET); - if(null == result || result.isEmpty()) { - LOGGER.error("result from url:" + url + " result:" + result); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result")); - } - - JSONArray rsArray = null; - try { - JSONObject rsJson = JSONObject.fromObject(result); - rsArray = rsJson.getJSONArray(ParamConstant.PARAM_DATA); - } catch(JSONException e) { - LOGGER.error("getResources error:" + e); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result")); - } - return rsArray; - } - - /** - * Get response.
- * - * @param restParametes - * @param url - * @param iResName - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - public static JSONArray getResponseRes(RestfulParametes restParametes, String url, String iResName) - throws ServiceException { - String result = getResponseContent(url, restParametes, RestfulUtil.TYPE_GET); - if(null == result || result.isEmpty()) { - LOGGER.error("result from url:" + url + " result:" + result); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result")); - } - - JSONArray rsArray = null; - try { - JSONObject rsJson = JSONObject.fromObject(result); - rsArray = rsJson.getJSONArray(iResName); - String vimId = rsJson.getString(ParamConstant.PARAM_VIMID); - String vimName = rsJson.getString(ParamConstant.PARAM_VIMNAME); - for(int i = 0; i < rsArray.size(); i++) { - JSONObject jsonObj = rsArray.getJSONObject(i); - jsonObj.put(ParamConstant.PARAM_VIMID, vimId); - jsonObj.put(ParamConstant.PARAM_VIMNAME, vimName); - } - } catch(JSONException e) { - LOGGER.error("getResources error:" + e); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result")); - } - return rsArray; - } - - /** - *
- * - * @param paramsMap - * @param params - * @return - * @since NFVO 0.5 - */ - public static RestfulResponse getRemoteResponse(Map paramsMap, String params) { - String url = paramsMap.get("url"); - String methodType = paramsMap.get("methodType"); - - RestfulResponse rsp = null; - Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); - try { - - RestfulParametes restfulParametes = new RestfulParametes(); - Map headerMap = new HashMap<>(3); - headerMap.put(CONTENT_TYPE, APPLICATION); - restfulParametes.setHeaderMap(headerMap); - restfulParametes.setRawData(params); - - if(rest != null) { - if(TYPE_GET.equalsIgnoreCase(methodType)) { - rsp = rest.get(url, restfulParametes); - } else if(TYPE_POST.equalsIgnoreCase(methodType)) { - rsp = rest.post(url, restfulParametes); - } else if(TYPE_PUT.equalsIgnoreCase(methodType)) { - rsp = rest.put(url, restfulParametes); - } else if(TYPE_DEL.equalsIgnoreCase(methodType)) { - rsp = rest.delete(url, restfulParametes); - } - } - } catch(ServiceException e) { - LOGGER.error("function=getRemoteResponse, get restful response catch exception {}", e); - } - return rsp; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/StringUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/StringUtil.java deleted file mode 100644 index 2d4b1c7..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/StringUtil.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util; - -import java.math.BigDecimal; -import java.text.DecimalFormat; - -import org.apache.commons.lang3.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * String Utility Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public final class StringUtil { - - private static final Logger LOGGER = LoggerFactory.getLogger(StringUtil.class); - - private StringUtil() { - } - - /** - * - * Check whether thestring is valid.
- * - * @param str - * @return - * @since NFVO 0.5 - */ - public static boolean isValidString(String str) { - if(null == str || str.isEmpty()) { - return false; - } - return true; - } - - /** - * - * Check whether the value is larger than zero.
- * - * @param strs - * @return - * @since NFVO 0.5 - */ - public static boolean isAnyLargeThanZero(String... strs) { - for(String str : strs) { - if(!StringUtils.isEmpty(str) && Float.parseFloat(str) > 0) { - LOGGER.info("isAnyLargeThanZero : {} is > 0", str); - return true; - } - } - return false; - } - - /** - * - * Check whether the value is Integer.
- * - * @param strs - * @return - * @since NFVO 0.5 - */ - public static boolean isInteger(String... strs) { - try { - for(String str : strs) { - if(!StringUtils.isEmpty(str)) { - int value = Integer.parseInt(str); - if(value < 0) { - return false; - } - } - } - } catch(NumberFormatException e) { - return false; - } - return true; - } - - /** - * - * Check whether the input is Numeric.
- * - * @param strs - * @return - * @since NFVO 0.5 - */ - public static boolean isNumeric(String... strs) { - try { - for(String str : strs) { - if(!StringUtils.isEmpty(str)) { - float value = Float.parseFloat(str); - if(value < 0) { - return false; - } - } - } - } catch(NumberFormatException e) { - return false; - } - return true; - } - - /** - * - * Compare zero by float.
- * - * @param tatol - * @param used - * @param drTotal - * @return - * @since NFVO 0.5 - */ - public static boolean compareZeroByFloat(String tatol, String used, String drTotal) { - Float ftotal = (float)0; - Float fused = (float)0; - Float fdrTotal = (float)0; - if(!StringUtils.isEmpty(tatol)) { - ftotal = new Float(tatol); - } - if(!StringUtils.isEmpty(used)) { - fused = new Float(used); - } - if(!StringUtils.isEmpty(drTotal)) { - fdrTotal = new Float(drTotal); - } - if(ftotal < fused + fdrTotal) { - return false; - } - - return true; - } - - /** - * - * Compare zero by integer.
- * - * @param tatol - * @param used - * @param drTotal - * @return - * @since NFVO 0.5 - */ - public static boolean compareZeroByInteger(String tatol, String used, String drTotal) { - Integer ftotal = (int)0; - Integer fused = (int)0; - Integer fdrTotal = (int)0; - if(!StringUtils.isEmpty(tatol)) { - ftotal = Integer.valueOf(tatol); - } - if(!StringUtils.isEmpty(used)) { - fused = Integer.valueOf(used); - } - if(!StringUtils.isEmpty(drTotal)) { - fdrTotal = Integer.valueOf(drTotal); - } - if(ftotal < fused + fdrTotal) { - return false; - } - return true; - } - - /** - * - * Number format.
- * - * @param data - * @return - * @since NFVO 0.5 - */ - public static String numFormat(String data) { - if(null != data && !("".equals(data))) { - BigDecimal var = new BigDecimal(data); - DecimalFormat formatWithoutFraction = new DecimalFormat("############"); - DecimalFormat formatWithFraction = new DecimalFormat("############.############"); - if(new BigDecimal(var.intValue()).compareTo(var) == 0) { - return formatWithoutFraction.format(var); - } - return formatWithFraction.format(var); - } - return null; - } - - /** - * - *
- * - * @param inputStr - * @return - * @since NFVO 0.5 - */ - public static boolean checkXss(String inputStr) { - return inputStr.matches("[A-Za-z0-9_.']+"); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/request/RequestUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/request/RequestUtil.java deleted file mode 100644 index bbc28a3..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/request/RequestUtil.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util.request; - -import java.io.IOException; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.io.IOUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONException; -import net.sf.json.JSONObject; - -/** - *
- *

- * Utility used for request - *

- * - * @author - * @version NFVO 0.5 2016-3-17 - */ -public final class RequestUtil { - - private static final Logger LOGGER = LoggerFactory.getLogger(RequestUtil.class); - - /** - * Constructor
- *

- *

- * - * @since NFVO 0.5 - */ - private RequestUtil() { - } - - /** - * Get context string from http context - * - * @param context - * http context - * @return the needed string in http context - */ - public static String getStringRequestBody(HttpServletRequest context) { - try { - InputStream input = context.getInputStream(); - return IOUtils.toString(input); - } catch(IOException e) { - LOGGER.error("function=getStringRequestBody, get httpservletrequest body exception: {}", e); - return null; - } - } - - /** - * Get json parameter from http context - * - * @param context - * http context - * @return JSONObject - */ - public static JSONObject getJsonRequestBody(HttpServletRequest context) { - try { - String bodyStr = getStringRequestBody(context); - return JSONObject.fromObject(bodyStr); - } catch(JSONException e) { - LOGGER.error("function=getJsonRequestBody, maybe request param is not a jsonobject exception: {}", e); - return null; - } - } - - /** - * Get the body of all request in json format
- * - * @param context - * The http context - * @return JSONObject The body of all request in json format - * @since NFVO 0.5 - */ - public static JSONObject getAllJsonRequestBody(HttpServletRequest context) { - JSONObject requestBody = getJsonRequestBody(context); - if(null == requestBody) { - LOGGER.error("get httpservletrequest body exception"); - requestBody = new JSONObject(); - } - LOGGER.warn("function=getAllJsonRequestBody; msg=get request data is:[{}]", requestBody.toString()); - requestBody.put("header", getContextHeader(context)); - return requestBody; - } - - /** - * Get the context header
- * - * @param context - * The http context - * @return Map context header - * @since NFVO 0.5 - */ - @SuppressWarnings("unchecked") - private static Map getContextHeader(HttpServletRequest context) { - Map header = new HashMap(); - Enumeration headerNames = context.getHeaderNames(); - while(headerNames.hasMoreElements()) { - String headerName = headerNames.nextElement(); - String value = context.getHeader(headerName); - header.put(headerName, value); - } - return header; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/response/ResponseUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/response/ResponseUtil.java deleted file mode 100644 index 28ee1b0..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/response/ResponseUtil.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util.response; - -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -import javax.servlet.http.HttpServletRequest; - -import net.sf.json.JSONObject; - -/** - * - * Response utility class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public final class ResponseUtil { - - private ResponseUtil() { - } - - /** - * Roa request common return function, default return code 200
- * - * @param retCode - * The request return code - * @param msg - * The request message - * @return JSONObject The response for http request - * @since NFVO 0.5 - */ - public static JSONObject genHttpResponse(int retCode, String msg) { - return genHttpResponse(null, createCodeMap(-1, retCode), msg, null); - } - - /** - * Roa request common return function, default return code 200
- * - * @param retCode - * The request return code - * @param msg - * The request message - * @param map - * Other request info of this request - * @return JSONObject The response for http request - * @since NFVO 0.5 - */ - public static JSONObject genHttpResponse(int retCode, String msg, Map map) { - return genHttpResponse(null, createCodeMap(-1, retCode), msg, map); - } - - /** - * Roa request common return method
- * - * @param context - * The http request context - * @param httpStatusCode - * The http response code - * @param retCode - * The http request return code - * @param msg - * The message of request - * @return JSONObject The response for http request - * @since NFVO 0.5 - */ - public static JSONObject genHttpResponse(HttpServletRequest context, int httpStatusCode, int retCode, String msg) { - return genHttpResponse(context, createCodeMap(httpStatusCode, retCode), msg, null); - } - - /** - * - * Roa request common return method.
- * - * @param context, The http request context - * @param codeMap - * @param msg, The message of request - * @param map, Other message of request - * @return - * @since NFVO 0.5 - */ - public static JSONObject genHttpResponse(HttpServletRequest context, Map codeMap, String msg, - Map map) { - JSONObject object = new JSONObject(); - - object.put("msg", msg); - if(null != map) { - Iterator> ite = map.entrySet().iterator(); - if(ite.hasNext()) { - Map.Entry entry = ite.next(); - object.put(entry.getKey(), entry.getValue().toString()); - } - } - return object; - } - - /** - * Create code map to maintenance the relationship between return code and - * http status code
- * - * @param httpStatusCode - * The http response code - * @param retCode - * The http request return code - * @return Map - * @since NFVO 0.5 - */ - private static Map createCodeMap(int httpStatusCode, int retCode) { - Map codeMap = new HashMap<>(5); - codeMap.put("httpStatusCode", httpStatusCode); - codeMap.put("retCode", retCode); - return codeMap; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/response/RoaResponseUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/response/RoaResponseUtil.java deleted file mode 100644 index 1043e7a..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/common/util/response/RoaResponseUtil.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util.response; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.ResponseConstant; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- * Utility for generate Roa get/add/update/delete method status - *

- * - * @author - * @version NFVO 0.5 2016-3-17 - */ -public final class RoaResponseUtil { - - private static final Logger LOGGER = LoggerFactory.getLogger(RoaResponseUtil.class); - - private RoaResponseUtil() { - - } - - /** - * Generate get method response
- * - * @param list - * The basic response for get method - * @return JSONObject The response for http request - * @since NFVO 0.5 - */ - public static JSONObject get(List list) { - Map map = new HashMap(10); - map.put(ParamConstant.PARAM_DATA, list); - LOGGER.info("function=get; msg=get map:{}", map.toString()); - return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.QUERY_SUCESS_MSG, map); - } - - /** - * Generate different response by different parameter for add method
- * - * @param result - * The result - * @return JSONObject - * @since NFVO 0.5 - */ - public static JSONObject add(int result) { - LOGGER.info("function=add; msg=add result{}", result); - if(result <= 0) { - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.ADD_FAIL_MSG); - } else { - return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.ADD_SUCESS_MSG); - } - } - - /** - * Generate different response by different parameter for update method
- * - * @param result - * The result - * @return JSONObject The response for http request - * @since NFVO 0.5 - */ - public static JSONObject update(int result) { - LOGGER.info("function=update; msg=update result{}", result); - if(result <= 0) { - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.MOD_FAIL_MSG); - } else { - return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.MOD_SUCESS_MSG); - } - } - - /** - * Generate different response by different parameter for delete method
- * - * @param result - * The result - * @return delete JSONObject of the response for http request - * @since NFVO 0.5 - */ - public static JSONObject delete(int result) { - LOGGER.info("function=delete; msg=delete result{}", result); - if(result <= 0) { - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.DEL_FAIL_MSG); - } else { - return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.DEL_SUCESS_MSG); - } - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/activator/ROAResmgrServicePostProcessor.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/activator/ROAResmgrServicePostProcessor.java deleted file mode 100644 index 6c217c2..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/activator/ROAResmgrServicePostProcessor.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.activator; - -import org.onap.vfc.nfvo.res.service.adapter.inf.IResmgrAdapterMgrService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 22, 2016 - */ -public class ROAResmgrServicePostProcessor implements DestructionAwareBeanPostProcessor { - - private static final Logger LOG = LoggerFactory.getLogger(ROAResmgrServicePostProcessor.class); - - @Override - public Object postProcessAfterInitialization(Object bean, String name) throws BeansException { - if(bean instanceof IResmgrAdapterMgrService) { - LOG.warn("Register to Microservice BUS!"); - IResmgrAdapterMgrService resmgrAdapterSvc = (IResmgrAdapterMgrService)bean; - resmgrAdapterSvc.register(); - } - - return bean; - } - - @Override - public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException { - // TODO Auto-generated method stub - return bean; - } - - @Override - public void postProcessBeforeDestruction(Object bean, String name) throws BeansException { - // TODO Auto-generated method stub - - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapter2MSBManager.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapter2MSBManager.java deleted file mode 100644 index f9ccbed..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapter2MSBManager.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.adapter.impl; - -import java.util.Map; - -import org.onap.vfc.nfvo.res.common.constant.Constant; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.onap.vfc.nfvo.res.service.adapter.inf.IResmgrAdapter2MSBManager; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 22, 2016 - */ -public class ResmgrAdapter2MSBManager implements IResmgrAdapter2MSBManager { - - private static final Logger LOG = LoggerFactory.getLogger(ResmgrAdapter2MSBManager.class); - - @Override - public JSONObject registerResmgr(Map paramsMap, JSONObject driverInfo) { - JSONObject resultObj = new JSONObject(); - - RestfulResponse rsp = RestfulUtil.getRemoteResponse(paramsMap, driverInfo.toString()); - if(null == rsp) { - LOG.error("function=registerResmgr, RestfulResponse is null"); - resultObj.put("reason", "RestfulResponse is null."); - resultObj.put("retCode", Constant.ERROR_CODE); - return resultObj; - } - LOG.warn("function=registerResmgr, status={}, content={}.", rsp.getStatus(), rsp.getResponseContent()); - String resultCreate = rsp.getResponseContent(); - - if(rsp.getStatus() == HttpConstant.HTTP_CREATED) { - LOG.warn("function=registerResmgr, msg= status={}, result={}.", rsp.getStatus(), resultCreate); - resultObj = JSONObject.fromObject(resultCreate); - resultObj.put("retCode", HttpConstant.HTTP_CREATED); - return resultObj; - } else if(rsp.getStatus() == HttpConstant.HTTP_INVALID_PARAMETERS) { - LOG.error("function=registerResmgr, msg=MSB return fail,invalid parameters,status={}, result={}.", - rsp.getStatus(), resultCreate); - resultObj.put("reason", "MSB return fail,invalid parameters."); - } else if(rsp.getStatus() == HttpConstant.HTTP_INNERERROR_CODE) { - LOG.error("function=registerResmgr, msg=MSB return fail,internal system error,status={}, result={}.", - rsp.getStatus(), resultCreate); - resultObj.put("reason", "MSB return fail,internal system error."); - } - resultObj.put("retCode", Constant.ERROR_CODE); - return resultObj; - } - - @Override - public JSONObject unregisterResmgr(Map paramsMap) { - JSONObject resultObj = new JSONObject(); - - RestfulResponse rsp = RestfulUtil.getRemoteResponse(paramsMap, ""); - if(null == rsp) { - LOG.error("function=unregisterResmgr, RestfulResponse is null"); - resultObj.put("reason", "RestfulResponse is null."); - resultObj.put("retCode", Constant.ERROR_CODE); - return resultObj; - } - String resultCreate = rsp.getResponseContent(); - - if(rsp.getStatus() == HttpConstant.HTTP_NOCONTENT) { - LOG.warn("function=unregisterResmgr, msg= status={}, result={}.", rsp.getStatus(), resultCreate); - resultObj = JSONObject.fromObject(resultCreate); - resultObj.put("retCode", HttpConstant.HTTP_NOCONTENT); - return resultObj; - } else if(rsp.getStatus() == HttpConstant.HTTP_NOTFOUND_CODE) { - LOG.error( - "function=unregisterResmgr, msg=MSB return fail,can't find the service instance.status={}, result={}.", - rsp.getStatus(), resultCreate); - resultObj.put("reason", "MSB return fail,can't find the service instance."); - } else if(rsp.getStatus() == HttpConstant.HTTP_INVALID_PARAMETERS) { - LOG.error("function=unregisterResmgr, msg=MSB return fail,invalid parameters,status={}, result={}.", - rsp.getStatus(), resultCreate); - resultObj.put("reason", "MSB return fail,invalid parameters."); - } else if(rsp.getStatus() == HttpConstant.HTTP_INNERERROR_CODE) { - LOG.error("function=unregisterResmgr, msg=MSB return fail,internal system error,status={}, result={}.", - rsp.getStatus(), resultCreate); - resultObj.put("reason", "MSB return fail,internal system error."); - } - resultObj.put("retCode", Constant.ERROR_CODE); - return resultObj; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapterMgrService.java deleted file mode 100644 index 8b1d905..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapterMgrService.java +++ /dev/null @@ -1,185 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.adapter.impl; - -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashMap; -import java.util.Map; -import java.util.concurrent.Executors; - -import org.onap.vfc.nfvo.res.common.constant.Constant; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.service.adapter.inf.IResmgrAdapter2MSBManager; -import org.onap.vfc.nfvo.res.service.adapter.inf.IResmgrAdapterMgrService; -import org.openo.baseservice.util.impl.SystemEnvVariablesFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Service; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 22, 2016 - */ -@Service -public class ResmgrAdapterMgrService implements IResmgrAdapterMgrService { - - private static final Logger LOG = LoggerFactory.getLogger(ResmgrAdapterMgrService.class); - - public static final String RESMGRADAPTERINFO = "resmgradapterinfo.json"; - - @Override - public void register() { - // set BUS URL and mothedtype - Map paramsMap = new HashMap<>(); - paramsMap.put("url", UrlConstant.REST_MSB_REGISTER); - paramsMap.put("methodType", ParamConstant.PARAM_POST); - - // get resmgr info and raise registration - try { - String resmgrInfo = readVimAdapterInfoFromJson(); - if(!"".equals(resmgrInfo)) { - JSONObject adapterObject = JSONObject.fromObject(resmgrInfo); - RegisterResmgrThread resmgrThread = new RegisterResmgrThread(paramsMap, adapterObject); - Executors.newSingleThreadExecutor().submit(resmgrThread); - } else { - LOG.error("Resmgr info is null,please check!"); - } - - } catch(IOException e) { - LOG.error("Failed to read Resmgr info! " + e.getMessage(), e); - } - - } - - /** - * Retrieve VIM driver information. - * - * @return - * @throws IOException - */ - public static String readVimAdapterInfoFromJson() throws IOException { - InputStream ins = null; - BufferedInputStream bins = null; - String fileContent = ""; - - String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator") - + "etc" + System.getProperty("file.separator") + "adapterInfo" + System.getProperty("file.separator") - + RESMGRADAPTERINFO; - - try { - ins = new FileInputStream(fileName); - bins = new BufferedInputStream(ins); - - byte[] contentByte = new byte[ins.available()]; - int num = bins.read(contentByte); - - if(num > 0) { - fileContent = new String(contentByte); - } - } catch(FileNotFoundException e) { - LOG.error(fileName + "is not found!", e); - } finally { - if(ins != null) { - ins.close(); - } - if(bins != null) { - bins.close(); - } - } - - return fileContent; - } - - private static class RegisterResmgrThread implements Runnable { - - // Thread lock Object - private final Object lockObject = new Object(); - - private IResmgrAdapter2MSBManager adapter2MSBMgr = new ResmgrAdapter2MSBManager(); - - // url and mothedtype - private Map paramsMap; - - // driver body - private JSONObject adapterInfo; - - public RegisterResmgrThread(Map paramsMap, JSONObject adapterInfo) { - this.paramsMap = paramsMap; - this.adapterInfo = adapterInfo; - } - - @Override - public void run() { - LOG.info("start register resmgr", RegisterResmgrThread.class); - - if(paramsMap == null || adapterInfo == null) { - LOG.error("parameter is null,please check!", RegisterResmgrThread.class); - return; - } - - // catch Runtime Exception - try { - sendRequest(paramsMap, adapterInfo); - } catch(RuntimeException e) { - LOG.error(e.getMessage(), e); - } - - } - - private void sendRequest(Map paramsMap, JSONObject driverInfo) { - JSONObject resultObj = adapter2MSBMgr.registerResmgr(paramsMap, driverInfo); - - if(Integer.valueOf(resultObj.get("retCode").toString()) == HttpConstant.HTTP_CREATED) { - LOG.info("Resmgr has now Successfully Registered to the Microservice BUS!"); - } else { - LOG.error("Resmgr failed to Register to the Microservice BUS! Reason:" - + resultObj.get("reason").toString() + " retCode:" + resultObj.get("retCode").toString()); - - // if registration fails,wait one minute and try again - try { - synchronized(lockObject) { - lockObject.wait(Constant.REPEAT_REG_TIME); - } - } catch(InterruptedException e) { - LOG.error(e.getMessage(), e); - } - - sendRequest(this.paramsMap, this.adapterInfo); - } - - } - - } - - @Override - public void unregister() { - // unregister - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/inf/IResmgrAdapter2MSBManager.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/inf/IResmgrAdapter2MSBManager.java deleted file mode 100644 index 5981f59..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/inf/IResmgrAdapter2MSBManager.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.adapter.inf; - -import java.util.Map; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 22, 2016 - */ -public interface IResmgrAdapter2MSBManager { - - /** - *
- * - * @param paramsMap - * @param driverInfo - * @return - * @since NFVO 0.5 - */ - JSONObject registerResmgr(Map paramsMap, JSONObject driverInfo); - - /** - *
- * - * @param paramsMap - * @return - * @since NFVO 0.5 - */ - JSONObject unregisterResmgr(Map paramsMap); - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/inf/IResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/inf/IResmgrAdapterMgrService.java deleted file mode 100644 index 3bce8af..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/adapter/inf/IResmgrAdapterMgrService.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.adapter.inf; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 22, 2016 - */ -public interface IResmgrAdapterMgrService { - - /** - * Resmgr register interface. - */ - void register(); - - /** - * Resmgr unregister interface. - */ - void unregister(); - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/HostImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/HostImpl.java deleted file mode 100644 index 1dbaf51..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/HostImpl.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Host; -import org.onap.vfc.nfvo.res.service.business.inf.HostBusiness; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - * - * Host implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class HostImpl implements Host { - - private HostBusiness hostBusiness; - - @Override - public int add(JSONObject jsonObject) throws ServiceException { - return hostBusiness.addHost(HostEntity.toEntity(jsonObject)); - } - - @Override - public int update(JSONObject jsonObject) throws ServiceException { - return hostBusiness.updateHostSelective(HostEntity.toEntity(jsonObject)); - } - - @Override - public int update(HostEntity portEntity) throws ServiceException { - return hostBusiness.updateHostSelective(portEntity); - } - - @Override - public int delete(String id) throws ServiceException { - return hostBusiness.deleteHost(id); - } - - @Override - public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException { - return hostBusiness.updateHostByVimId(HostEntity.toEntity(jsonObject)); - } - - @Override - public int deleteResByVimId(String vimId) throws ServiceException { - return hostBusiness.deleteHostByVimId(vimId); - } - - @Override - public List getList(Map condition) throws ServiceException { - return hostBusiness.getHosts(condition); - } - - public void setHostBusiness(HostBusiness hostBusiness) { - this.hostBusiness = hostBusiness; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/LocationImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/LocationImpl.java deleted file mode 100644 index 422fa06..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/LocationImpl.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Location; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Sites; -import org.onap.vfc.nfvo.res.service.business.inf.LocationBusiness; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - * Location Implementation Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class LocationImpl implements Location { - - private LocationBusiness locationBusiness; - - private Sites sites; - - private static final Logger LOGGER = LoggerFactory.getLogger(LocationImpl.class); - - @Override - public int add(JSONObject jsonObject) throws ServiceException { - return locationBusiness.addLocation(LocationEntity.toEntity(jsonObject)); - } - - @Override - public int update(JSONObject jsonObject) throws ServiceException { - return locationBusiness.updateLocationSelective(LocationEntity.toEntity(jsonObject)); - } - - @Override - public int delete(String location) throws ServiceException { - return locationBusiness.deleteLocation(location); - } - - @Override - public Map get(String id) throws ServiceException { - Map map = new HashMap<>(); - map.put(ParamConstant.PARAM_ID, id); - List sodores = locationBusiness.getLocations(map); - map.clear(); - map.put(ParamConstant.PARAM_DATA, sodores); - return map; - } - - @Override - public List get(Map condition) throws ServiceException { - return locationBusiness.getLocations(condition); - } - - @Override - public List getCountry() throws ServiceException { - return locationBusiness.getCountry(); - } - - @Override - public List getCloudservice() throws ServiceException { - LOGGER.info("get cloud service from external system"); - JSONArray vims = VimUtil.getVims(); - LOGGER.info("vims: " + vims.toString()); - List cloudService = new ArrayList<>(); - for(int i = 0; i < vims.size(); i++) { - String vimName = vims.getJSONObject(i).getString("name"); - cloudService.add(vimName); - } - return cloudService; - } - - @Override - public List getLocationByCountry(Map condition) throws ServiceException { - return locationBusiness.getLocationByCountry(condition); - } - - @Override - public LocationEntity getLocation(Map condition) throws ServiceException { - List locationlist = locationBusiness.getLocations(condition); - if(null == locationlist || locationlist.isEmpty()) { - return null; - } - return locationlist.get(0); - } - - @Override - public List getLocationInfo(List locationInfo) throws ServiceException { - ArrayList newSites = new ArrayList<>(); - Map condition = new HashMap<>(); - for(int i = 0; i < locationInfo.size(); i++) { - LocationEntity locationEntity = locationInfo.get(i); - String latitude = locationEntity.getLatitude(); - String longitude = locationEntity.getLongitude(); - String locatSite = locationEntity.getLocation(); - condition.put(ParamConstant.PARAM_LOCATION, locatSite); - LOGGER.info("LocationRoa::getLocation condition:{}", condition); - List sitesEntity = sites.getList(condition); - LOGGER.info("LocationRoa::getLocation sitesEntity:{}", sitesEntity); - if(null != sitesEntity && !sitesEntity.isEmpty()) { - for(SitesEntity entity : sitesEntity) { - JSONObject site = JSONObject.fromObject(entity.toString()); - JSONObject resTotalJo = site.getJSONObject("total"); - JSONObject resUsedlJo = site.getJSONObject("used"); - JSONObject ressiteJo = computingSite(resTotalJo, resUsedlJo); - site.element("latitude", latitude); - site.element("longitude", longitude); - site.element("siteDetail", ressiteJo); - LOGGER.info("LocationRoa::getLocation latitude:{}, longitude:{}", latitude, longitude); - LOGGER.info("LocationRoa::getLocation site:{}", site); - newSites.add(site); - } - } - } - return newSites; - } - - /** - * Computing site.
- * - * @param total - * @param used - * @return - * @since NFVO 0.5 - */ - public JSONObject computingSite(JSONObject total, JSONObject used) { - String vcpus = JsonUtil.getJsonFieldStr(total, ParamConstant.PARAM_VCPUS); - String memorys = JsonUtil.getJsonFieldStr(total, ParamConstant.PARAM_MEMORY); - String disks = JsonUtil.getJsonFieldStr(total, ParamConstant.PARAM_DISK); - String vcpusused = JsonUtil.getJsonFieldStr(used, ParamConstant.PARAM_VCPUS); - String memoryused = JsonUtil.getJsonFieldStr(used, ParamConstant.PARAM_MEMORY); - String diskused = JsonUtil.getJsonFieldStr(used, ParamConstant.PARAM_DISK); - float cpu = Float.parseFloat(vcpusused) / Float.parseFloat(vcpus); - float memory = Float.parseFloat(memoryused) / Integer.parseInt(memorys); - float disk = Float.parseFloat(diskused) / Float.parseFloat(disks); - JSONObject resTotalJo = new JSONObject(); - resTotalJo.put(ParamConstant.PARAM_VCPUS, String.valueOf(Math.round(cpu * 100)) + "%"); - resTotalJo.put(ParamConstant.PARAM_MEMORY, String.valueOf(Math.round(memory * 100)) + "%"); - resTotalJo.put(ParamConstant.PARAM_DISK, String.valueOf(Math.round(disk * 100)) + "%"); - - return resTotalJo; - } - - public LocationBusiness getLocationBusiness() { - return locationBusiness; - } - - public void setLocationBusiness(LocationBusiness locationBusiness) { - this.locationBusiness = locationBusiness; - } - - public void setSites(Sites sites) { - this.sites = sites; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/NetworkImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/NetworkImpl.java deleted file mode 100644 index 9bfcf74..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/NetworkImpl.java +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Network; -import org.onap.vfc.nfvo.res.service.business.inf.NetworkBusiness; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - * Network implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class NetworkImpl implements Network { - - private static final Logger LOGGER = LoggerFactory.getLogger(NetworkImpl.class); - - private NetworkBusiness networkBusiness; - - @Override - public int add(JSONObject jsonObject) throws ServiceException { - LOGGER.warn("function=addPort; jsonObject={}", jsonObject); - JSONObject networkObj = dataParse(jsonObject); - return networkBusiness.addNetwork(NetworkEntity.toEntity(networkObj)); - } - - private JSONObject dataParse(JSONObject jsonObject) { - JSONObject portObj = new JSONObject(); - portObj.put("id", JsonUtil.getJsonFieldStr(jsonObject, "id")); - portObj.put("name", JsonUtil.getJsonFieldStr(jsonObject, "name")); - portObj.put("status", JsonUtil.getJsonFieldStr(jsonObject, "status")); - portObj.put("tenantId", JsonUtil.getJsonFieldStr(jsonObject, "tenant_id")); - portObj.put("vimId", JsonUtil.getJsonFieldStr(jsonObject, "vimId")); - portObj.put("vimName", JsonUtil.getJsonFieldStr(jsonObject, "vimName")); - portObj.put("physicalNetwork", JsonUtil.getJsonFieldStr(jsonObject, "physicalNetwork")); - portObj.put("networkType", JsonUtil.getJsonFieldStr(jsonObject, "networkType")); - portObj.put("segmentationId", JsonUtil.getJsonFieldStr(jsonObject, "segmentationId")); - return portObj; - } - - @Override - public int add(NetworkEntity entity) throws ServiceException { - return networkBusiness.addNetwork(entity); - } - - @Override - public int update(JSONObject jsonObject) throws ServiceException { - return networkBusiness.updateNetworkSelective(NetworkEntity.toEntity(jsonObject)); - } - - @Override - public int delete(String id) throws ServiceException { - return networkBusiness.deleteNetwork(id); - } - - @Override - public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException { - return networkBusiness.updateNetworkByVimId(NetworkEntity.toEntity(jsonObject)); - } - - @Override - public List getList(Map condition) throws ServiceException { - return networkBusiness.getNetworks(condition); - } - - @Override - public int deleteResByVimId(String vimId) throws ServiceException { - return networkBusiness.deleteNetworkByVimId(vimId); - } - - public void setNetworkBusiness(NetworkBusiness networkBusiness) { - this.networkBusiness = networkBusiness; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/PortImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/PortImpl.java deleted file mode 100644 index 36b6cd1..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/PortImpl.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Port; -import org.onap.vfc.nfvo.res.service.business.inf.PortBusiness; -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - * Port implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class PortImpl implements Port { - - private static final Logger LOGGER = LoggerFactory.getLogger(PortImpl.class); - - private PortBusiness portBusiness; - - @Override - public int add(JSONObject jsonObject) throws ServiceException { - LOGGER.warn("function=addPort; jsonObject={}", jsonObject); - JSONObject portObj = dataParse(jsonObject); - return portBusiness.addPort(PortEntity.toEntity(portObj)); - } - - private JSONObject dataParse(JSONObject jsonObject) { - JSONObject portObj = new JSONObject(); - portObj.put("id", JsonUtil.getJsonFieldStr(jsonObject, "id")); - portObj.put("name", JsonUtil.getJsonFieldStr(jsonObject, "name")); - portObj.put("networkId", JsonUtil.getJsonFieldStr(jsonObject, "networkId")); - portObj.put("status", JsonUtil.getJsonFieldStr(jsonObject, "status")); - portObj.put("tenantId", JsonUtil.getJsonFieldStr(jsonObject, "tenant_id")); - portObj.put("vimId", JsonUtil.getJsonFieldStr(jsonObject, "vimId")); - portObj.put("vimName", JsonUtil.getJsonFieldStr(jsonObject, "vimName")); - return portObj; - } - - @Override - public int add(PortEntity portEntity) throws ServiceException { - return portBusiness.addPort(portEntity); - } - - @Override - public int update(JSONObject jsonObject) throws ServiceException { - return portBusiness.updatePortSelective(PortEntity.toEntity(jsonObject)); - } - - @Override - public int update(PortEntity portEntity) throws ServiceException { - return portBusiness.updatePortSelective(portEntity); - } - - @Override - public int delete(String id) throws ServiceException { - return portBusiness.deletePort(id); - } - - @Override - public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException { - return portBusiness.updatePortByVimId(PortEntity.toEntity(jsonObject)); - } - - @Override - public int deleteResByVimId(String vimId) throws ServiceException { - return portBusiness.deletePortByVimId(vimId); - } - - @Override - public List getList(Map condition) throws ServiceException { - return portBusiness.getPorts(condition); - } - - public void setPortBusiness(PortBusiness portBusiness) { - this.portBusiness = portBusiness; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/SitesImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/SitesImpl.java deleted file mode 100644 index 3238f50..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/SitesImpl.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Sites; -import org.onap.vfc.nfvo.res.service.business.inf.LimitsBusiness; -import org.onap.vfc.nfvo.res.service.business.inf.SitesBusiness; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.onap.vfc.nfvo.res.service.group.inf.ResOperateService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - * DC info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public class SitesImpl implements Sites { - - private static final Logger LOGGER = LoggerFactory.getLogger(SitesImpl.class); - - private SitesBusiness sitesBusiness; - - private LimitsBusiness limitsBusiness; - - private ResOperateService resOperateService; - - @Override - public int add(JSONObject jsonObject) throws ServiceException { - LOGGER.info("Add datacenter jsonObject: {}", jsonObject); - SitesEntity sitesEntity = SitesEntity.toEntity(jsonObject); - sitesEntity.setStatus(ParamConstant.PARAM_ACTIVE); - String vimName = jsonObject.getString(ParamConstant.PARAM_VIMNAME); - String vimId = VimUtil.getVimIdByName(vimName); - sitesEntity.setVimId(vimId); - JSONObject resource = limitsBusiness.getLimits(vimId); - sitesEntity.setVimName(resource.getString(ParamConstant.PARAM_VIMNAME)); - sitesEntity.setTotalCPU(resource.getString(ParamConstant.TOTAL_CPU)); - sitesEntity.setUsedCPU(resource.getString(ParamConstant.USED_CPU)); - sitesEntity.setTotalMemory(resource.getString(ParamConstant.TOTAL_MEMORY)); - sitesEntity.setUsedMemory(resource.getString(ParamConstant.USED_MEMORY)); - sitesEntity.setTotalDisk(resource.getString(ParamConstant.TOTAL_DISK)); - sitesEntity.setUsedDisk(resource.getString(ParamConstant.USED_DISK)); - if(StringUtils.isEmpty(sitesEntity.getId())) { - sitesEntity.setId(UUID.randomUUID().toString()); - jsonObject.put(ParamConstant.PARAM_ID, sitesEntity.getId()); - } - LOGGER.info("Add datacenter sitesEntity: {}", sitesEntity.toString()); - return sitesBusiness.addSite(sitesEntity); - } - - /** - *
- * - * @param json - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public void sendToMonitor(JSONObject jsonObject) throws ServiceException { - LOGGER.info("SitesImpl sendToMonitor jsonObject: {}", jsonObject); - String vimName = jsonObject.getString(ParamConstant.PARAM_VIMNAME); - String vimId = VimUtil.getVimIdByName(vimName); - JSONObject vimInfo = VimUtil.getVimById(vimId); - LOGGER.info("SitesImpl sendToMonitor vimInfo: {}", vimInfo); - String tenant = vimInfo.getString("tenant"); - String tenantId = VimUtil.getTenantIdByName(tenant, vimId); - JSONObject json = new JSONObject(); - json.put("header", null); - LOGGER.info("tenantId:{}, vimId:{}", tenantId, vimId); - resOperateService.addIRes(tenantId, vimId, json); - resOperateService.sendMsgMonitor("create", vimId); - } - - @Override - public int update(SitesEntity sitesEntity) throws ServiceException { - return sitesBusiness.updateSiteSelective(sitesEntity); - } - - @Override - public int update(JSONObject jsonObject) throws ServiceException { - LOGGER.info("grantResource jsonObject: {}", jsonObject); - JSONObject sitesObj = dataParse(jsonObject); - return sitesBusiness.updateSiteSelective(SitesEntity.toEntity(sitesObj)); - } - - private JSONObject dataParse(JSONObject jsonObject) throws ServiceException { - String vimId = jsonObject.getString(ParamConstant.PARAM_VIMID); - Map condition = new HashMap<>(); - condition.put("vimId", vimId); - SitesEntity sitesEntity = get(condition); - if(null == sitesEntity) { - LOGGER.error("Get sites null, vimId={}", vimId); - return null; - } - return computeSiteUsed(jsonObject, sitesEntity); - } - - private JSONObject computeSiteUsed(JSONObject jsonObject, SitesEntity sitesEntity) throws ServiceException { - String action = JsonUtil.getJsonFieldStr(jsonObject, "action"); - String usedCpu = JsonUtil.getJsonFieldStr(jsonObject, ParamConstant.USED_CPU); - String usedMemory = JsonUtil.getJsonFieldStr(jsonObject, ParamConstant.USED_MEMORY); - String usedDisk = JsonUtil.getJsonFieldStr(jsonObject, ParamConstant.USED_DISK); - String oldCpu = sitesEntity.getUsedCPU(); - String oldMemory = sitesEntity.getUsedMemory(); - String oldDisk = sitesEntity.getUsedDisk(); - String newCpu = accumOrFreeRes(usedCpu, oldCpu, action, sitesEntity.getTotalCPU(), "cpu"); - String newMemory = accumOrFreeRes(usedMemory, oldMemory, action, sitesEntity.getTotalMemory(), "memory"); - String newDisk = accumOrFreeRes(usedDisk, oldDisk, action, sitesEntity.getTotalDisk(), "disk"); - - JSONObject resUsed = new JSONObject(); - resUsed.put(ParamConstant.USED_CPU, newCpu); - resUsed.put(ParamConstant.USED_MEMORY, newMemory); - resUsed.put(ParamConstant.USED_DISK, newDisk); - resUsed.put("id", sitesEntity.getId()); - resUsed.put("name", sitesEntity.getName()); - resUsed.put("status", sitesEntity.getStatus()); - resUsed.put("location", sitesEntity.getLocation()); - resUsed.put("country", sitesEntity.getCountry()); - resUsed.put(ParamConstant.PARAM_VIMID, sitesEntity.getVimId()); - resUsed.put(ParamConstant.PARAM_VIMNAME, sitesEntity.getVimName()); - resUsed.put(ParamConstant.TOTAL_CPU, sitesEntity.getTotalCPU()); - resUsed.put(ParamConstant.TOTAL_MEMORY, sitesEntity.getTotalMemory()); - resUsed.put(ParamConstant.TOTAL_DISK, sitesEntity.getTotalDisk()); - return resUsed; - } - - private String accumOrFreeRes(String resUsed, String resOld, String action, String total, String type) - throws ServiceException { - BigDecimal iResUsed = new BigDecimal(resUsed); - BigDecimal iResOld = new BigDecimal(resOld); - BigDecimal itotal = new BigDecimal(total); - if("online".equals(action)) { - if(iResOld.add(iResUsed).compareTo(itotal) > 0) { - throw new ServiceException("Grant resource fail! The " + type + " resource not enough."); - } - return String.valueOf(iResOld.add(iResUsed)); - } else { - if(iResOld.subtract(iResUsed).compareTo(BigDecimal.ZERO) < 0) { - throw new ServiceException("Grant resource fail! The " + type + " resource used below zero."); - } - return String.valueOf(iResOld.subtract(iResUsed)); - } - } - - @Override - public int updateResource(JSONObject jsonObject) throws ServiceException { - return sitesBusiness.updateSiteResource(SitesEntity.toEntity(jsonObject)); - } - - @Override - public int delete(String id) throws ServiceException { - Map map = new HashMap(10); - map.put(ParamConstant.PARAM_ID, id); - List datacenters = getList(map); - SitesEntity site = datacenters.get(0); - LOGGER.info("site: {}", site); - String vimId = site.getVimId(); - LOGGER.info("vimId: {}", vimId); - resOperateService.sendMsgMonitor("delete", vimId); - resOperateService.deleteIRes(vimId); - return sitesBusiness.deleteSite(id); - } - - @Override - public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException { - return sitesBusiness.updateSiteByVimId(SitesEntity.toEntity(jsonObject)); - } - - @Override - public List getList(Map condition) throws ServiceException { - return sitesBusiness.getSites(condition); - } - - @Override - public SitesEntity get(Map condition) throws ServiceException { - List siteList = sitesBusiness.getSites(condition); - if(null == siteList || siteList.isEmpty()) { - return null; - } - return siteList.get(0); - } - - @Override - public int deleteResByVimId(String vimId) throws ServiceException { - return 0; - } - - public void setSitesBusiness(SitesBusiness sitesBusiness) { - this.sitesBusiness = sitesBusiness; - } - - public void setLimitsBusiness(LimitsBusiness limitsBusiness) { - this.limitsBusiness = limitsBusiness; - } - - public void setResOperateService(ResOperateService resOperateService) { - this.resOperateService = resOperateService; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/VimImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/VimImpl.java deleted file mode 100644 index 99c1e96..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/VimImpl.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Vim; -import org.onap.vfc.nfvo.res.service.business.inf.VimBusiness; -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - * Vim info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public class VimImpl implements Vim { - - private VimBusiness vimBusiness; - - @Override - public int add(String id) throws ServiceException { - return vimBusiness.addVim(id); - } - - @Override - public int add(JSONObject jsonObject) throws ServiceException { - return add(jsonObject.getString("id")); - } - - @Override - public int update(JSONObject jsonObject) throws ServiceException { - return 0; - } - - @Override - public int delete(String id) throws ServiceException { - return vimBusiness.deleteVim(id); - } - - @Override - public VimEntity getVim(String id) throws ServiceException { - return vimBusiness.getVim(id); - } - - @Override - public List getList() throws ServiceException { - return vimBusiness.getVims(); - } - - @Override - public List getVimInfo(Map condition) throws ServiceException { - // get vim from vimadapter - return new ArrayList(); - } - - public void setVimBusiness(VimBusiness vimBusiness) { - this.vimBusiness = vimBusiness; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Host.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Host.java deleted file mode 100644 index 068762b..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Host.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public interface Host extends InterfaceResManagement { - - /** - *
- * - * @param jsonObject - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateStatusByVimId(JSONObject jsonObject) throws ServiceException; - - /** - *
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getList(Map condition) throws ServiceException; - - /** - *
- * - * @param resPoolEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int update(HostEntity resPoolEntity) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/InterfaceResManagement.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/InterfaceResManagement.java deleted file mode 100644 index 167c617..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/InterfaceResManagement.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.inf; - -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public interface InterfaceResManagement extends ResManagement { - - /** - *
- * - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deleteResByVimId(String vimId) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Location.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Location.java deleted file mode 100644 index a3a0c15..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Location.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - * Location details class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface Location extends ResManagement { - - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - Map get(String id) throws ServiceException; - - /** - * Get list of locations.
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List get(Map condition) throws ServiceException; - - /** - * Get location details.
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - LocationEntity getLocation(Map condition) throws ServiceException; - - /** - * Get location info.
- * - * @param locationInfo - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getLocationInfo(List locationInfo) throws ServiceException; - - /** - * Get Country.
- * - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getCountry() throws ServiceException; - - /** - * Get location by country.
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getLocationByCountry(Map condition) throws ServiceException; - - /** - * Get cloud services.
- * - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getCloudservice() throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Network.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Network.java deleted file mode 100644 index 398d8a9..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Network.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - * - * Network class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface Network extends InterfaceResManagement { - - /** - * - * Update status by VIM Id.
- * - * @param jsonObject - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateStatusByVimId(JSONObject jsonObject) throws ServiceException; - - /** - * - * Get list of networks.
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getList(Map condition) throws ServiceException; - - /** - *
- * - * @param entity - * @return - * @since NFVO 0.5 - */ - int add(NetworkEntity entity) throws ServiceException; - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Port.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Port.java deleted file mode 100644 index 9fc7f77..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Port.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public interface Port extends InterfaceResManagement { - - /** - *
- * - * @param jsonObject - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateStatusByVimId(JSONObject jsonObject) throws ServiceException; - - /** - *
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getList(Map condition) throws ServiceException; - - /** - *
- * - * @param resPoolEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int update(PortEntity resPoolEntity) throws ServiceException; - - /** - *
- * - * @param portEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int add(PortEntity portEntity) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/ResManagement.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/ResManagement.java deleted file mode 100644 index 225f095..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/ResManagement.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.inf; - -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public interface ResManagement { - - /** - *
- * - * @param jsonObject - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int add(JSONObject jsonObject) throws ServiceException; - - /** - *
- * - * @param jsonObject - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int update(JSONObject jsonObject) throws ServiceException; - - /* - * key : parameter key value : parameter value - */ - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int delete(String id) throws ServiceException; - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Sites.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Sites.java deleted file mode 100644 index c6c622a..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Sites.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public interface Sites extends InterfaceResManagement { - - /** - *
- * - * @param jsonObject - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateStatusByVimId(JSONObject jsonObject) throws ServiceException; - - /** - *
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getList(Map condition) throws ServiceException; - - /** - *
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - SitesEntity get(Map condition) throws ServiceException; - - /** - *
- * - * @param jsonObject - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateResource(JSONObject jsonObject) throws ServiceException; - - /** - *
- * - * @param sitesEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int update(SitesEntity sitesEntity) throws ServiceException; - - /** - *
- * - * @param json - * @throws ServiceException - * @since NFVO 0.5 - */ - void sendToMonitor(JSONObject json) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Vim.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Vim.java deleted file mode 100644 index 4d3e278..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/base/openstack/inf/Vim.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - * Virtualised Infrastructure Manager.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public interface Vim extends ResManagement { - - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - VimEntity getVim(String id) throws ServiceException; - - /** - *
- * - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getList() throws ServiceException; - - /** - * - * Get VIM information.
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getVimInfo(Map condition) throws ServiceException; - - /** - *
- * - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int add(String vimId) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/HostBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/HostBusinessImpl.java deleted file mode 100644 index f7be74f..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/HostBusinessImpl.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.service.business.inf.HostBusiness; -import org.onap.vfc.nfvo.res.service.dao.inf.HostDao; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Host business implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class HostBusinessImpl implements HostBusiness { - - private static final Logger LOGGER = LoggerFactory.getLogger(HostBusinessImpl.class); - - private HostDao hostDao; - - @Override - public HostEntity getHost(String id) { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=getHost; msg=get error, because id is empty."); - return null; - } - return hostDao.getHost(id); - } - - @Override - public List getHosts(Map condition) { - return hostDao.getHosts(condition); - } - - @Override - public int deleteHost(String id) throws ServiceException { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=deleteHost; msg=delete error, because id is empty."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.delete.id.null")); - } - HostEntity rp = hostDao.getHost(id); - if(null == rp) { - return hostDao.deleteHost(id); - } - - return hostDao.deleteHost(id); - } - - @Override - public int addHost(HostEntity hostEntity) throws ServiceException { - if(null == hostEntity) { - LOGGER.error("function=addHost; msg=add error, because hostEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.entity.null")); - } - - if(!checkId(hostEntity.getId())) { - LOGGER.error("function=addHost; msg=add error, because id is already exist."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.id.check")); - } - if(StringUtils.isEmpty(hostEntity.getId())) { - hostEntity.setId(UUID.randomUUID().toString()); - } - return hostDao.addHost(hostEntity); - } - - @Override - public int addHostSelective(HostEntity hostEntity) throws ServiceException { - if(null == hostEntity) { - LOGGER.error("function=addHostSelective; msg=add error, because hostEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.entity.null")); - } - if(!checkId(hostEntity.getId())) { - LOGGER.error("function=addHostSelective; msg=add error, because id is allready exist."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.id.check")); - } - - if(StringUtils.isEmpty(hostEntity.getId())) { - hostEntity.setId(UUID.randomUUID().toString()); - } - return hostDao.addHostSelective(hostEntity); - } - - private boolean checkId(String id) { - HostEntity respool = hostDao.getHost(id); - if(null == respool) { - return true; - } - return false; - } - - @Override - public int updateHostSelective(HostEntity hostEntity) throws ServiceException { - if(!checkId(hostEntity.getId())) { - return hostDao.updateHostSelective(hostEntity); - } else { - return addHostSelective(hostEntity); - } - } - - @Override - public int updateHost(HostEntity hostEntity) throws ServiceException { - if(null == hostEntity) { - LOGGER.error("function=updateHost; msg=update error, because hostEntity is null."); - throw new ServiceException("update error, because hostEntity is null."); - } - - return hostDao.updateHost(hostEntity); - } - - @Override - public int updateHostByVimId(HostEntity hostEntity) throws ServiceException { - if(null == hostEntity) { - LOGGER.error("function=updateHostByVimId; msg=update error, because hostEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.update.entity.null")); - } - return hostDao.updateHostByVimId(hostEntity); - } - - @Override - public int deleteHostByVimId(String vimId) throws ServiceException { - if(StringUtils.isEmpty(vimId)) { - LOGGER.error("function=deleteHostByVimId; msg=delete error, because VimId is empty."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.delete.vimid.check")); - } - return hostDao.deleteHostByVimId(vimId); - } - - public void setHostDao(HostDao hostDao) { - this.hostDao = hostDao; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/LimitsBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/LimitsBusinessImpl.java deleted file mode 100644 index 8a2be18..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/LimitsBusinessImpl.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.onap.vfc.nfvo.res.service.business.inf.LimitsBusiness; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class LimitsBusinessImpl implements LimitsBusiness { - - private static final Logger LOGGER = LoggerFactory.getLogger(LimitsBusinessImpl.class); - - /** - *
- * - * @param vimId - * @param tenantId - * @return - * @since NFVO 0.5 - */ - private JSONObject getResponse(String vimId, String tenantId) { - LOGGER.info("function=getResponse; vimId={}, tenantId={}", vimId, tenantId); - String url = String.format(UrlConstant.GET_LIMITS_URL, vimId, tenantId); - JSONObject result = RestfulUtil.getResponseObj(url, ParamConstant.PARAM_GET); - LOGGER.warn("function=getResponse; result={}", result); - if(null == result) { - JSONObject obj = new JSONObject(); - obj.put("msg", "getLimits fail!"); - return obj; - } - return result; - } - - @Override - public JSONObject getLimits(String vimId) throws ServiceException { - JSONObject vimInfo = VimUtil.getVimById(vimId); - LOGGER.info("GetLimits vimInfo: {}", vimInfo); - String vimName = vimInfo.getString("name"); - String tenant = vimInfo.getString("tenant"); - String tenantId = VimUtil.getTenantIdByName(tenant, vimId); - - JSONObject limits = getResponse(vimId, tenantId); - - String totalCPU = String.valueOf(limits.get("maxTotalCores")); - String totalMemory = String.valueOf(limits.get("maxTotalRAMSize")); - String totalDisk = String.valueOf(limits.get("maxTotalVolumeGigabytes")); - String usedCPU = String.valueOf(limits.get("totalCoresUsed")); - String usedMemory = String.valueOf(limits.get("totalRAMUsed")); - String usedDisk = String.valueOf(limits.get("totalGigabytesUsed")); - - JSONObject result = new JSONObject(); - result.put("vimId", vimId); - result.put("vimName", vimName); - result.put("totalCPU", totalCPU); - result.put("totalMemory", totalMemory); - result.put("totalDisk", totalDisk); - result.put("usedCPU", usedCPU); - result.put("usedMemory", usedMemory); - result.put("usedDisk", usedDisk); - LOGGER.info("getLimits result:{}", result); - return result; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/LocationBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/LocationBusinessImpl.java deleted file mode 100644 index f1da586..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/LocationBusinessImpl.java +++ /dev/null @@ -1,242 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.util.StringUtil; -import org.onap.vfc.nfvo.res.service.business.inf.LocationBusiness; -import org.onap.vfc.nfvo.res.service.dao.inf.LocationDao; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * Location Business implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class LocationBusinessImpl implements LocationBusiness { - - private static final Logger LOGGER = LoggerFactory.getLogger(LocationBusinessImpl.class); - - private LocationDao locationDao; - - /** - * - * Check location.
- * - * @param locationEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - public boolean checkLocation(LocationEntity locationEntity) throws ServiceException { - String location = locationEntity.getLocation(); - Map map = new HashMap<>(); - map.put(ParamConstant.PARAM_LOCATION, location); - List locationList = getLocations(map); - if(locationList == null || locationList.isEmpty()) { - return false; - } - return true; - } - - /** - * - * Check Latitude.;
- * - * @param locationEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - public boolean checkLatitude(LocationEntity locationEntity) throws ServiceException { - String latitu = locationEntity.getLatitude(); - String longitu = locationEntity.getLongitude(); - if("-0".equals(locationEntity.getLatitude())) { - locationEntity.setLatitude("0"); - } - if("-0".equals(locationEntity.getLongitude())) { - locationEntity.setLongitude("0"); - } - float latitude = Float.parseFloat(latitu); - float longitude = Float.parseFloat(longitu); - if((latitude >= -90 && latitude <= 90) && (longitude >= -180 && longitude <= 180)) { - return true; - } - return false; - } - - private boolean checkModified(LocationEntity locationEntity) { - String newCountry = locationEntity.getCountry(); - String newLocation = locationEntity.getLocation(); - String id = locationEntity.getId(); - LocationEntity selectLocation = locationDao.getLocation(id); - if(null == selectLocation) { - return false; - } - String oldCountry = selectLocation.getCountry(); - String oldLocation = selectLocation.getLocation(); - if(newCountry.equals(oldCountry) && newLocation.equals(oldLocation)) { - return true; - } - return false; - } - - @Override - public LocationEntity getLocation(String id) throws ServiceException { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=getLocation; msg=get error, because id is empty."); - return null; - } - return locationDao.getLocation(id); - } - - @Override - public List getCountry() throws ServiceException { - return locationDao.getCountry(); - } - - @Override - public List getLocationByCountry(Map condition) throws ServiceException { - return locationDao.getLocationByCountry(condition); - } - - @Override - public List getLocations(Map condition) throws ServiceException { - return locationDao.getLocations(condition); - } - - @Override - public int deleteLocation(String location) throws ServiceException { - if(StringUtils.isEmpty(location)) { - LOGGER.error("function=deleteLocation; msg=delete error, because location is empty."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.delete.base.entity.check")); - } - return locationDao.deleteLocation(location); - } - - @Override - public int addLocation(LocationEntity locationEntity) throws ServiceException { - if(null == locationEntity) { - LOGGER.error("function=addLocation; msg=add error, because locationEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.entity.null")); - } - if(!StringUtil.checkXss(locationEntity.getCountry()) || !StringUtil.checkXss(locationEntity.getLocation()) - || !StringUtil.checkXss(locationEntity.getLatitude()) - || !StringUtil.checkXss(locationEntity.getLongitude())) { - LOGGER.error("function=addLocation; msg=add Location error, because XSS injection."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.xss.check")); - } - if(checkLocation(locationEntity)) { - LOGGER.error("function=addLocation; msg=add Location error, because location exist."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.entity.check")); - } - if(!checkLatitude(locationEntity)) { - LOGGER.error("function=addLocation; msg=add Location error, because latitude or longitude illegal."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.latitude.check")); - } - if(null == locationEntity.getId() || locationEntity.getId().isEmpty()) { - locationEntity.setId(UUID.randomUUID().toString()); - } - LOGGER.error("function=addLocation; msg=add DO success, : " + locationEntity); - return locationDao.addLocation(locationEntity); - - } - - @Override - public int addLocationSelective(LocationEntity locationEntity) throws ServiceException { - if(null == locationEntity) { - LOGGER.error("function=addLocationSelective; msg=add error, because locationEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.entity.null")); - } - if(!StringUtil.checkXss(locationEntity.getCountry()) || !StringUtil.checkXss(locationEntity.getLocation()) - || !StringUtil.checkXss(locationEntity.getLatitude()) - || !StringUtil.checkXss(locationEntity.getLongitude())) { - LOGGER.error("function=addLocation; msg=add Location error, because XSS injection."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.xss.check")); - } - if(null == locationEntity.getId() || locationEntity.getId().isEmpty()) { - locationEntity.setId(UUID.randomUUID().toString()); - } - return locationDao.addLocationSelective(locationEntity); - } - - @Override - public int updateLocationSelective(LocationEntity locationEntity) throws ServiceException { - if(null == locationEntity) { - LOGGER.error("function=updateLocationSelective; msg=update error, because locationEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.entity.check")); - } - if(!checkLatitude(locationEntity)) { - LOGGER.error("function=updateLocationSelective; msg=update Location error, " - + "because latitude or longitude illegal."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.latitude.check")); - } - if(!checkModified(locationEntity)) { - LOGGER.error("function=updateLocationSelective; msg=update Location error, " - + "because country or location be modified."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.modified.check")); - } - return locationDao.updateLocationSelective(locationEntity); - } - - @Override - public int updateLocation(LocationEntity locationEntity) throws ServiceException { - if(null == locationEntity) { - LOGGER.error("function=updateLocation; msg=update error, because locationEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.entity.null")); - } - if(!checkLatitude(locationEntity)) { - LOGGER.error("function=updateLocation; msg=update Location error, because latitude or longitude illegal."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.latitude.check")); - } - return locationDao.updateLocation(locationEntity); - } - - public LocationDao getLocationDao() { - return locationDao; - } - - public void setLocationDao(LocationDao locationDao) { - this.locationDao = locationDao; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/NetworkBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/NetworkBusinessImpl.java deleted file mode 100644 index e14f9ca..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/NetworkBusinessImpl.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.service.business.inf.NetworkBusiness; -import org.onap.vfc.nfvo.res.service.dao.inf.NetworkDao; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Network business implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class NetworkBusinessImpl implements NetworkBusiness { - - private static final Logger LOGGER = LoggerFactory.getLogger(NetworkBusinessImpl.class); - - private NetworkDao networkDao; - - @Override - public NetworkEntity getNetwork(String id) { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=getNetwork; msg=get error, because id is empty."); - return null; - } - return networkDao.getNetwork(id); - } - - @Override - public List getNetworks(Map condition) { - return networkDao.getNetworks(condition); - } - - @Override - public int deleteNetwork(String id) throws ServiceException { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=deleteNetwork; msg=delete error, because id is empty."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.delete.id.null")); - } - return networkDao.deleteNetwork(id); - } - - @Override - public int addNetwork(NetworkEntity networkEntity) throws ServiceException { - if(null == networkEntity) { - LOGGER.error("function=addNetwork; msg=add error, because networkEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.add.entity.null")); - } - if(!checkId(networkEntity.getId())) { - return networkDao.updateNetworkSelective(networkEntity); - } - if(StringUtils.isEmpty(networkEntity.getId())) { - networkEntity.setId(UUID.randomUUID().toString()); - } - return networkDao.addNetwork(networkEntity); - } - - @Override - public int addNetworkSelective(NetworkEntity networkEntity) throws ServiceException { - if(null == networkEntity) { - LOGGER.error("function=addNetworkSelective; msg=add error, because networkEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.add.entity.null")); - } - if(!checkId(networkEntity.getId())) { - return networkDao.updateNetworkSelective(networkEntity); - } - if(StringUtils.isEmpty(networkEntity.getId())) { - networkEntity.setId(UUID.randomUUID().toString()); - } - return networkDao.addNetworkSelective(networkEntity); - } - - private boolean checkId(String id) { - NetworkEntity network = networkDao.getNetwork(id); - if(null == network) { - return true; - } - return false; - } - - @Override - public int updateNetworkSelective(NetworkEntity networkEntity) throws ServiceException { - if(null == networkEntity) { - LOGGER.error("function=updateNetworkSelective; msg=update error, because networkEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null")); - } - return networkDao.updateNetworkSelective(networkEntity); - } - - @Override - public int updateNetwork(NetworkEntity networkEntity) throws ServiceException { - if(null == networkEntity) { - LOGGER.error("function=updateNetwork; msg=update error, because networkEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null")); - } - return networkDao.updateNetwork(networkEntity); - } - - @Override - public int updateNetworkByVimId(NetworkEntity networkEntity) throws ServiceException { - if(null == networkEntity) { - LOGGER.error("function=updateNetworkByVimId; msg=update error, because networkEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null")); - } - return networkDao.updateNetworkByVimId(networkEntity); - } - - @Override - public int deleteNetworkByVimId(String vimId) throws ServiceException { - if(StringUtils.isEmpty(vimId)) { - LOGGER.error("function=deleteNetworkByVimId; msg=delete error, because VimId is empty."); - throw new ServiceException(ResourceUtil.getMessage("")); - } - return networkDao.deleteNetworkByVimId(vimId); - } - - public void setNetworkDao(NetworkDao networkDao) { - this.networkDao = networkDao; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/PortBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/PortBusinessImpl.java deleted file mode 100644 index 8b11b82..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/PortBusinessImpl.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.service.business.inf.PortBusiness; -import org.onap.vfc.nfvo.res.service.dao.inf.PortDao; -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Port business implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class PortBusinessImpl implements PortBusiness { - - private static final Logger LOGGER = LoggerFactory.getLogger(PortBusinessImpl.class); - - private PortDao portDao; - - @Override - public PortEntity getPort(String id) { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=getPort; msg=get error, because id is empty."); - return null; - } - return portDao.getPort(id); - } - - @Override - public List getPorts(Map condition) { - return portDao.getPorts(condition); - } - - @Override - public int deletePort(String id) throws ServiceException { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=deletePort; msg=delete error, because id is empty."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.delete.id.null")); - } - PortEntity rp = portDao.getPort(id); - if(null == rp) { - return portDao.deletePort(id); - } - - return portDao.deletePort(id); - } - - @Override - public int addPort(PortEntity portEntity) throws ServiceException { - if(null == portEntity) { - LOGGER.error("function=addPort; msg=add error, because portEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.add.entity.null")); - } - - if(!checkId(portEntity.getId())) { - return portDao.updatePortSelective(portEntity); - } - if(StringUtils.isEmpty(portEntity.getId())) { - portEntity.setId(UUID.randomUUID().toString()); - } - return portDao.addPort(portEntity); - } - - @Override - public int addPortSelective(PortEntity portEntity) throws ServiceException { - if(null == portEntity) { - LOGGER.error("function=addPortSelective; msg=add error, because portEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.add.entity.null")); - } - if(!checkId(portEntity.getId())) { - return portDao.updatePortSelective(portEntity); - } - - if(StringUtils.isEmpty(portEntity.getId())) { - portEntity.setId(UUID.randomUUID().toString()); - } - return portDao.addPortSelective(portEntity); - } - - private boolean checkId(String id) { - PortEntity respool = portDao.getPort(id); - if(null == respool) { - return true; - } - return false; - } - - @Override - public int updatePortSelective(PortEntity portEntity) throws ServiceException { - if(null == portEntity) { - LOGGER.error("function=updatePortSelective; msg=update error, because portEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.update.entity.null")); - } - - return portDao.updatePortSelective(portEntity); - } - - @Override - public int updatePort(PortEntity portEntity) throws ServiceException { - if(null == portEntity) { - LOGGER.error("function=updatePort; msg=update error, because portEntity is null."); - throw new ServiceException("update error, because portEntity is null."); - } - - return portDao.updatePort(portEntity); - } - - @Override - public int updatePortByVimId(PortEntity portEntity) throws ServiceException { - if(null == portEntity) { - LOGGER.error("function=updatePortByVimId; msg=update error, because portEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.update.entity.null")); - } - return portDao.updatePortByVimId(portEntity); - } - - @Override - public int deletePortByVimId(String vimId) throws ServiceException { - if(StringUtils.isEmpty(vimId)) { - LOGGER.error("function=deletePortByVimId; msg=delete error, because VimId is empty."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.delete.vimid.check")); - } - return portDao.deletePortByVimId(vimId); - } - - public void setPortDao(PortDao portDao) { - this.portDao = portDao; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/SitesBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/SitesBusinessImpl.java deleted file mode 100644 index 4b724b0..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/SitesBusinessImpl.java +++ /dev/null @@ -1,200 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.service.business.inf.SitesBusiness; -import org.onap.vfc.nfvo.res.service.dao.inf.SitesDao; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Sites info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public class SitesBusinessImpl implements SitesBusiness { - - private static final Logger LOGGER = LoggerFactory.getLogger(SitesBusinessImpl.class); - - private SitesDao sitesDao; - - private static final String TYPE_ADD = "add"; - - private static final String TYPE_UPDATE = "update"; - - private static final String TYPE_DELETE = "delete"; - - @Override - public SitesEntity getSite(String id) throws ServiceException { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=getSite; msg=get error, because id is empty."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.id.null")); - } - return sitesDao.getSite(id); - } - - @Override - public List getSites(Map condition) { - return sitesDao.getSites(condition); - } - - @Override - public int deleteSite(String id) throws ServiceException { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=deleteSite; msg=delete error, because id is empty."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.delete.id.null")); - } - - return sitesDao.deleteSite(id); - } - - @Override - public int addSite(SitesEntity sitesEntity) throws ServiceException { - LOGGER.info("addSite sitesEntity"); - if(null == sitesEntity) { - LOGGER.error("function=addSite; msg=add error, because sitesEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.entity.null")); - } - // if(!StringUtil.checkXss(sitesEntity.getName()) || - // !StringUtil.checkXss(sitesEntity.getCountry()) - // || !StringUtil.checkXss(sitesEntity.getLocation())) { - // LOGGER.error("function=addLocation; msg=add site error, because XSS injection."); - // throw new ServiceException( - // ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.xss.check")); - // } - LOGGER.info("sitesEntity: " + sitesEntity.toString()); - this.checkSite(sitesEntity, TYPE_ADD); - SitesEntity.dataFramat(sitesEntity); - LOGGER.info("Add datacenter data into DB."); - return sitesDao.addSite(sitesEntity); - } - - private void checkSite(SitesEntity sitesEntity, String type) throws ServiceException { - if(TYPE_ADD.equals(type)) { - checkId(sitesEntity.getId()); - checkSiteName(sitesEntity.getName()); - if(!SitesEntity.checkResource(sitesEntity)) { - LOGGER.error("function=checkRespool; msg=site{} resource error", sitesEntity.toString()); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.resource.check")); - } - } - } - - private void checkSiteName(String siteName) throws ServiceException { - Map siteMap = new HashMap<>(10); - siteMap.put(ParamConstant.PARAM_NAME, siteName); - List siteList = sitesDao.getSites(siteMap); - if(null != siteList && !siteList.isEmpty()) { - LOGGER.error("function=checkSiteName; msg=site: {} has already exist.", siteName); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.name.check")); - } - } - - private void checkId(String id) throws ServiceException { - SitesEntity site = sitesDao.getSite(id); - if(null != site) { - LOGGER.error("function=checkId; msg=add error, because id is already exist."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.id.check")); - } - } - - @Override - public int addSiteSelective(SitesEntity sitesEntity) throws ServiceException { - if(null == sitesEntity) { - LOGGER.error("function=addSiteSelective; msg=add error, because sitesEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.entity.null")); - } - this.checkSite(sitesEntity, TYPE_ADD); - - if(StringUtils.isEmpty(sitesEntity.getId())) { - sitesEntity.setId(UUID.randomUUID().toString()); - } - SitesEntity.dataFramat(sitesEntity); - return sitesDao.addSiteSelective(sitesEntity); - } - - @Override - public int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException { - if(null == sitesEntity) { - LOGGER.error("function=updateSiteSelective; msg=update error, because sitesEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.update.entity.null")); - } - - this.checkSite(sitesEntity, TYPE_UPDATE); - SitesEntity.dataFramat(sitesEntity); - return sitesDao.updateSiteSelective(sitesEntity); - } - - @Override - public int updateSite(SitesEntity sitesEntity) throws ServiceException { - if(null == sitesEntity) { - LOGGER.error("function=updateSite; msg=update error, because sitesEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.update.entity.null")); - } - this.checkSite(sitesEntity, TYPE_UPDATE); - SitesEntity.dataFramat(sitesEntity); - return sitesDao.updateSite(sitesEntity); - } - - @Override - public int updateSiteByVimId(SitesEntity sitesEntity) throws ServiceException { - if(null == sitesEntity) { - LOGGER.error("function=updateSiteByVimId; msg=update error, because sitesEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.update.entity.null")); - } - SitesEntity.dataFramat(sitesEntity); - return sitesDao.updateSiteByVimId(sitesEntity); - } - - @Override - public int updateSiteResource(SitesEntity sitesEntity) throws ServiceException { - if(null == sitesEntity) { - LOGGER.error("function=updateSiteResource; msg=update error, because sitesEntity is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.update.entity.null")); - } - SitesEntity.dataFramat(sitesEntity); - return sitesDao.updateSiteSelective(sitesEntity); - } - - public void setSitesDao(SitesDao sitesDao) { - this.sitesDao = sitesDao; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/VimBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/VimBusinessImpl.java deleted file mode 100644 index 48ecd1f..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/impl/VimBusinessImpl.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import java.util.List; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.util.StringUtil; -import org.onap.vfc.nfvo.res.service.business.inf.VimBusiness; -import org.onap.vfc.nfvo.res.service.dao.inf.VimDao; -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Vim info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public class VimBusinessImpl implements VimBusiness { - - private static final Logger LOGGER = LoggerFactory.getLogger(VimBusinessImpl.class); - - private VimDao vimDao; - - @Override - public VimEntity getVim(String id) { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=getVim; msg=get error, because id is empty."); - return null; - } - return vimDao.getVim(id); - } - - @Override - public List getVims() { - return vimDao.getVims(); - } - - @Override - public int deleteVim(String id) throws ServiceException { - if(StringUtils.isEmpty(id)) { - LOGGER.error("function=deleteVim; msg=deleteVim error, because id is empty."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.del.id.check")); - } - return vimDao.deleteVim(id); - } - - @Override - public int addVim(String id) throws ServiceException { - if(!StringUtil.isValidString(id)) { - LOGGER.error("function=addVim; msg=add error, because id is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.add.id.null")); - } - if(!checkId(id)) { - LOGGER.error("function=addVim; msg=add error, because id is already exist."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.add.id.check")); - } - - VimEntity vimEntity = new VimEntity(); - vimEntity.setId(id); - return vimDao.addVim(vimEntity); - } - - private boolean checkId(String id) { - VimEntity vim = vimDao.getVim(id); - if(null == vim) { - return true; - } - return false; - } - - public void setVimDao(VimDao vimDao) { - this.vimDao = vimDao; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/HostBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/HostBusiness.java deleted file mode 100644 index d8a95f3..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/HostBusiness.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - * Host Buisiness Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 31, 2016 - */ -public interface HostBusiness { - - /** - * - * Get host.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - HostEntity getHost(String id); - - /** - * - * Get details of hosts.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getHosts(Map condition); - - /** - * - * Delete host.
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deleteHost(String id) throws ServiceException; - - /** - * - * Delete host by VIM Id.
- * - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deleteHostByVimId(String vimId) throws ServiceException; - - /** - * - * Add host.
- * - * @param hostEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int addHost(HostEntity hostEntity) throws ServiceException; - - /** - * - * Add selective host.
- * - * @param hostEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int addHostSelective(HostEntity hostEntity) throws ServiceException; - - /** - * - * Update selective host.
- * - * @param hostEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateHostSelective(HostEntity hostEntity) throws ServiceException; - - /** - * - * Update host.
- * - * @param hostEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateHost(HostEntity hostEntity) throws ServiceException; - - /** - * - * Update host by VIM Id.
- * - * @param hostEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateHostByVimId(HostEntity hostEntity) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/LimitsBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/LimitsBusiness.java deleted file mode 100644 index 661406a..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/LimitsBusiness.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.inf; - -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface LimitsBusiness { - - /** - *
- * - * @param paramJson - * @return - * @since NFVO 0.5 - */ - JSONObject getLimits(String vimId) throws ServiceException; - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/LocationBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/LocationBusiness.java deleted file mode 100644 index f132a6d..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/LocationBusiness.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - * - * Location Business Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface LocationBusiness { - - /** - * - * Get Location.
- * - * @param location - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - LocationEntity getLocation(String location) throws ServiceException; - - /** - * - * Get Locations.
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getLocations(Map condition) throws ServiceException; - - /** - * - * Delete Location.
- * - * @param location - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deleteLocation(String location) throws ServiceException; - - /** - * - * Add Location.
- * - * @param locationEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int addLocation(LocationEntity locationEntity) throws ServiceException; - - /** - * - * Add Selective Location.
- * - * @param locationEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int addLocationSelective(LocationEntity locationEntity) throws ServiceException; - - /** - * - * Update Selective Location.
- * - * @param locationEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateLocationSelective(LocationEntity locationEntity) throws ServiceException; - - /** - * - * Update Location.
- * - * @param locationEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateLocation(LocationEntity locationEntity) throws ServiceException; - - /** - * - * Get Country.
- * - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getCountry() throws ServiceException; - - /** - * - * Get Location By Country.
- * - * @param condition - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getLocationByCountry(Map condition) throws ServiceException; - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/NetworkBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/NetworkBusiness.java deleted file mode 100644 index f75d2ae..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/NetworkBusiness.java +++ /dev/null @@ -1,133 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - * - * Network Business class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface NetworkBusiness { - - /** - * - * Get network details.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - NetworkEntity getNetwork(String id); - - /** - * - * Get details of available networks.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getNetworks(Map condition); - - /** - * - * Delete Network.
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deleteNetwork(String id) throws ServiceException; - - /** - * - * Delete network by Virtual Infrastructure Manager ID.
- * - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deleteNetworkByVimId(String vimId) throws ServiceException; - - /** - * - * Add Network.
- * - * @param networkEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int addNetwork(NetworkEntity networkEntity) throws ServiceException; - - /** - * - * Add Selective Network.
- * - * @param networkEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int addNetworkSelective(NetworkEntity networkEntity) throws ServiceException; - - /** - * - * Update Selective Network.
- * - * @param networkEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateNetworkSelective(NetworkEntity networkEntity) throws ServiceException; - - /** - * - * Update Network.
- * - * @param networkEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateNetwork(NetworkEntity networkEntity) throws ServiceException; - - /** - * - * Update network by Virtual Infrastructure Manager ID.
- * - * @param networkEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updateNetworkByVimId(NetworkEntity networkEntity) throws ServiceException; - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/PortBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/PortBusiness.java deleted file mode 100644 index 4c19408..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/PortBusiness.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - * Port Buisiness Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 31, 2016 - */ -public interface PortBusiness { - - /** - * - * Get Port.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - PortEntity getPort(String id); - - /** - * - * Get details of ports.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getPorts(Map condition); - - /** - * - * Delete Port.
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deletePort(String id) throws ServiceException; - - /** - * - * Delete port by VIM ID.
- * - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deletePortByVimId(String vimId) throws ServiceException; - - /** - * - * Add port.
- * - * @param portEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int addPort(PortEntity portEntity) throws ServiceException; - - /** - * - * Add selective port.
- * - * @param portEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int addPortSelective(PortEntity portEntity) throws ServiceException; - - /** - * - * Update selective port.
- * - * @param portEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updatePortSelective(PortEntity portEntity) throws ServiceException; - - /** - * - * Update port.
- * - * @param portEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updatePort(PortEntity portEntity) throws ServiceException; - - /** - * - * Update port by VIM Id.
- * - * @param portEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int updatePortByVimId(PortEntity portEntity) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/SitesBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/SitesBusiness.java deleted file mode 100644 index 574e745..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/SitesBusiness.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - * DC info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface SitesBusiness { - - /** - * It is used to get Site info.
- * - * @param id - * @return The get result - * @throws ServiceException When get failed. - * @since NFVO 0.5 - */ - SitesEntity getSite(String id) throws ServiceException; - - /** - * It is used to get Sites info.
- * - * @param condition - * @return The get result - * @since NFVO 0.5 - */ - List getSites(Map condition); - - /** - * It is used to delete Site info.
- * - * @param id - * @return The delete result - * @throws ServiceException When delete failed. - * @since NFVO 0.5 - */ - int deleteSite(String id) throws ServiceException; - - /** - * It is used to add Site info.
- * - * @param sitesEntity - * @return The add result - * @throws ServiceException When add failed. - * @since NFVO 0.5 - */ - int addSite(SitesEntity sitesEntity) throws ServiceException; - - /** - * It is used to add Site info.
- * - * @param sitesEntity - * @return The add result - * @throws ServiceException When add failed. - * @since NFVO 0.5 - */ - int addSiteSelective(SitesEntity sitesEntity) throws ServiceException; - - /** - * It is used to update Site info.
- * - * @param sitesEntity - * @return The update result - * @throws ServiceException When update failed. - * @since NFVO 0.5 - */ - int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException; - - /** - * It is used to create update Site info.
- * - * @param sitesEntity - * @return The update result - * @throws ServiceException When update failed. - * @since NFVO 0.5 - */ - int updateSite(SitesEntity sitesEntity) throws ServiceException; - - /** - * It is used to update Site info.
- * - * @param sitesEntity - * @return The update result - * @throws ServiceException When update failed. - * @since NFVO 0.5 - */ - int updateSiteByVimId(SitesEntity sitesEntity) throws ServiceException; - - /** - * It is used to update Site info.
- * - * @param sitesEntity - * @return The update result - * @throws ServiceException When update failed. - * @since NFVO 0.5 - */ - int updateSiteResource(SitesEntity sitesEntity) throws ServiceException; - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/VimBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/VimBusiness.java deleted file mode 100644 index f29f257..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/business/inf/VimBusiness.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.inf; - -import java.util.List; - -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - * Vim info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface VimBusiness { - - /** - * It is used to get Vim info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - VimEntity getVim(String id); - - /** - * It is used to get Vim info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - List getVims(); - - /** - * It is used to delete Vim info.
- * - * @param id - * @return the delete result - * @throws ServiceException When delete failed. - * @since NFVO 0.5 - */ - int deleteVim(String id) throws ServiceException; - - /** - * It is used to add Vim info.
- * - * @param id - * @return the add result - * @throws ServiceException When add failed. - * @since NFVO 0.5 - */ - int addVim(String id) throws ServiceException; - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/AbstractDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/AbstractDao.java deleted file mode 100644 index b31c5bc..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/AbstractDao.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import org.apache.ibatis.session.SqlSession; - -/** - *
- *

- * Database abstract class to get the MapperManager - *

- * - * @author - * @version NFVO 0.5 2016-3-17 - */ -public class AbstractDao { - - private SqlSession session; - - protected AbstractDao() { - //added this private costructor to fix static errors. - } - - public SqlSession getSession() { - return session; - } - - public void setSession(SqlSession session) { - this.session = session; - } - - /** - * get Mybatis Mapper
- * - * @param type - * The type of Class - * @return Mapper - * @since NFVO 0.5 - */ - public T getMapperManager(Class type) { - return (T)getSession().getMapper(type); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/HostDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/HostDaoImpl.java deleted file mode 100644 index 7dae83c..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/HostDaoImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.inf.HostDao; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.onap.vfc.nfvo.res.service.mapper.HostMapper; - -/** - * - * Host DAO implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class HostDaoImpl extends AbstractDao implements HostDao { - - @Override - public HostEntity getHost(String id) { - return getMapperManager(HostMapper.class).getHost(id); - } - - @Override - public List getHosts(Map condition) { - return getMapperManager(HostMapper.class).getHosts(condition); - } - - @Override - public int deleteHost(String id) { - return getMapperManager(HostMapper.class).deleteHost(id); - } - - @Override - public int deleteHostByVimId(String vimId) { - return getMapperManager(HostMapper.class).deleteHostByVimId(vimId); - } - - @Override - public int addHost(HostEntity hostEntity) { - return getMapperManager(HostMapper.class).addHost(hostEntity); - } - - @Override - public int addHostSelective(HostEntity hostEntity) { - return getMapperManager(HostMapper.class).addHostSelective(hostEntity); - } - - @Override - public int updateHostSelective(HostEntity hostEntity) { - return getMapperManager(HostMapper.class).updateHostSelective(hostEntity); - } - - @Override - public int updateHost(HostEntity hostEntity) { - return getMapperManager(HostMapper.class).updateHost(hostEntity); - } - - @Override - public int updateHostByVimId(HostEntity hostEntity) { - return getMapperManager(HostMapper.class).updateHostByVimId(hostEntity); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/LocationDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/LocationDaoImpl.java deleted file mode 100644 index b6af978..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/LocationDaoImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.inf.LocationDao; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.onap.vfc.nfvo.res.service.mapper.LocationMapper; - -/** - * - * Location DAO implemetation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class LocationDaoImpl extends AbstractDao implements LocationDao { - - @Override - public LocationEntity getLocation(String id) { - return getMapperManager(LocationMapper.class).getLocation(id); - } - - @Override - public List getCountry() { - return getMapperManager(LocationMapper.class).getCountry(); - } - - @Override - public List getLocationByCountry(Map condition) { - return getMapperManager(LocationMapper.class).getLocationByCountry(condition); - } - - @Override - public List getLocations(Map condition) { - return getMapperManager(LocationMapper.class).getLocations(condition); - } - - @Override - public int deleteLocation(String id) { - return getMapperManager(LocationMapper.class).deleteLocation(id); - } - - @Override - public int addLocation(LocationEntity locationEntity) { - return getMapperManager(LocationMapper.class).addLocation(locationEntity); - } - - @Override - public int addLocationSelective(LocationEntity locationEntity) { - return getMapperManager(LocationMapper.class).addLocationSelective(locationEntity); - } - - @Override - public int updateLocationSelective(LocationEntity locationEntity) { - return getMapperManager(LocationMapper.class).updateLocationSelective(locationEntity); - } - - @Override - public int updateLocation(LocationEntity locationEntity) { - return getMapperManager(LocationMapper.class).updateLocation(locationEntity); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/NetworkDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/NetworkDaoImpl.java deleted file mode 100644 index a63e094..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/NetworkDaoImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.inf.NetworkDao; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.mapper.NetworkMapper; - -/** - * - * Network DAO implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class NetworkDaoImpl extends AbstractDao implements NetworkDao { - - @Override - public NetworkEntity getNetwork(String id) { - return getMapperManager(NetworkMapper.class).getNetwork(id); - } - - @Override - public List getNetworks(Map condition) { - return getMapperManager(NetworkMapper.class).getNetworks(condition); - } - - @Override - public int deleteNetwork(String id) { - return getMapperManager(NetworkMapper.class).deleteNetwork(id); - } - - @Override - public int deleteNetworkByVimId(String vimId) { - return getMapperManager(NetworkMapper.class).deleteNetworkByVimId(vimId); - } - - @Override - public int addNetwork(NetworkEntity networkEntity) { - return getMapperManager(NetworkMapper.class).addNetwork(networkEntity); - } - - @Override - public int addNetworkSelective(NetworkEntity networkEntity) { - return getMapperManager(NetworkMapper.class).addNetworkSelective(networkEntity); - } - - @Override - public int updateNetworkSelective(NetworkEntity networkEntity) { - return getMapperManager(NetworkMapper.class).updateNetworkSelective(networkEntity); - } - - @Override - public int updateNetwork(NetworkEntity networkEntity) { - return getMapperManager(NetworkMapper.class).updateNetwork(networkEntity); - } - - @Override - public int updateNetworkByVimId(NetworkEntity networkEntity) { - return getMapperManager(NetworkMapper.class).updateNetworkByVimId(networkEntity); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/PortDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/PortDaoImpl.java deleted file mode 100644 index d4ec76d..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/PortDaoImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.inf.PortDao; -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.onap.vfc.nfvo.res.service.mapper.PortMapper; - -/** - * - * Port DAO implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class PortDaoImpl extends AbstractDao implements PortDao { - - @Override - public PortEntity getPort(String id) { - return getMapperManager(PortMapper.class).getPort(id); - } - - @Override - public List getPorts(Map condition) { - return getMapperManager(PortMapper.class).getPorts(condition); - } - - @Override - public int deletePort(String id) { - return getMapperManager(PortMapper.class).deletePort(id); - } - - @Override - public int deletePortByVimId(String vimId) { - return getMapperManager(PortMapper.class).deletePortByVimId(vimId); - } - - @Override - public int addPort(PortEntity portEntity) { - return getMapperManager(PortMapper.class).addPort(portEntity); - } - - @Override - public int addPortSelective(PortEntity portEntity) { - return getMapperManager(PortMapper.class).addPortSelective(portEntity); - } - - @Override - public int updatePortSelective(PortEntity portEntity) { - return getMapperManager(PortMapper.class).updatePortSelective(portEntity); - } - - @Override - public int updatePort(PortEntity portEntity) { - return getMapperManager(PortMapper.class).updatePort(portEntity); - } - - @Override - public int updatePortByVimId(PortEntity portEntity) { - return getMapperManager(PortMapper.class).updatePortByVimId(portEntity); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/SitesDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/SitesDaoImpl.java deleted file mode 100644 index f35963e..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/SitesDaoImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.inf.SitesDao; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.onap.vfc.nfvo.res.service.mapper.SitesMapper; - -/** - * DC interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public class SitesDaoImpl extends AbstractDao implements SitesDao { - - @Override - public SitesEntity getSite(String id) { - return getMapperManager(SitesMapper.class).getSite(id); - } - - @Override - public List getSites(Map condition) { - return getMapperManager(SitesMapper.class).getSites(condition); - } - - @Override - public int deleteSite(String id) { - return getMapperManager(SitesMapper.class).deleteSite(id); - } - - @Override - public int addSite(SitesEntity sitesEntity) { - return getMapperManager(SitesMapper.class).addSite(sitesEntity); - } - - @Override - public int addSiteSelective(SitesEntity sitesEntity) { - return getMapperManager(SitesMapper.class).addSiteSelective(sitesEntity); - } - - @Override - public int updateSiteSelective(SitesEntity sitesEntity) { - return getMapperManager(SitesMapper.class).updateSiteSelective(sitesEntity); - } - - @Override - public int updateSite(SitesEntity sitesEntity) { - return getMapperManager(SitesMapper.class).updateSite(sitesEntity); - } - - @Override - public int updateSiteByVimId(SitesEntity sitesEntity) { - return getMapperManager(SitesMapper.class).updateSiteByVimId(sitesEntity); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VimDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VimDaoImpl.java deleted file mode 100644 index e8c7374..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VimDaoImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; - -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.inf.VimDao; -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.onap.vfc.nfvo.res.service.mapper.VimMapper; - -/** - * Vim interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 25, 2016 - */ -public class VimDaoImpl extends AbstractDao implements VimDao { - - @Override - public VimEntity getVim(String id) { - return getMapperManager(VimMapper.class).getVim(id); - } - - @Override - public List getVims() { - return getMapperManager(VimMapper.class).getVims(); - } - - @Override - public int deleteVim(String id) { - return getMapperManager(VimMapper.class).deleteVim(id); - } - - @Override - public int addVim(VimEntity vimEntity) { - return getMapperManager(VimMapper.class).addVim(vimEntity); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VirtualLinkDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VirtualLinkDaoImpl.java deleted file mode 100644 index bfe0345..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VirtualLinkDaoImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.inf.VirtualLinkDao; -import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity; -import org.onap.vfc.nfvo.res.service.mapper.VirtualLinkMapper; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public class VirtualLinkDaoImpl extends AbstractDao implements VirtualLinkDao { - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public VirtualLinkEntity getVl(String id) { - return getMapperManager(VirtualLinkMapper.class).selectByPrimaryKey(id); - } - - /** - *
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - @Override - public List getVls(Map condition) { - return getMapperManager(VirtualLinkMapper.class).getVls(condition); - } - - /** - *
- * - * @param virtualLinkEntity - * @return - * @since NFVO 0.5 - */ - @Override - public int addVl(VirtualLinkEntity virtualLinkEntity) { - return getMapperManager(VirtualLinkMapper.class).insert(virtualLinkEntity); - } - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public int deleteVlById(String id) { - return getMapperManager(VirtualLinkMapper.class).deleteByPrimaryKey(id); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VmDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VmDaoImpl.java deleted file mode 100644 index ec174e2..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VmDaoImpl.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.inf.VmDao; -import org.onap.vfc.nfvo.res.service.entity.VmEntity; -import org.onap.vfc.nfvo.res.service.mapper.VmMapper; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public class VmDaoImpl extends AbstractDao implements VmDao { - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public VmEntity getVm(String id) { - return getMapperManager(VmMapper.class).selectByPrimaryKey(id); - } - - /** - *
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - @Override - public List getVms(Map condition) { - return getMapperManager(VmMapper.class).getVms(condition); - } - - /** - *
- * - * @param vmEntity - * @return - * @since NFVO 0.5 - */ - @Override - public int addVm(VmEntity vmEntity) { - return getMapperManager(VmMapper.class).insert(vmEntity); - } - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public int deleteVmById(String id) { - return getMapperManager(VmMapper.class).deleteByPrimaryKey(id); - } - - /** - *
- * - * @param vmEntity - * @return - * @since NFVO 0.5 - */ - @Override - public int updateVm(VmEntity vmEntity) { - return getMapperManager(VmMapper.class).updateByPrimaryKeySelective(vmEntity); - } - - /** - *
- * - * @param vnfInstanceId - * @return - * @since NFVO 0.5 - */ - @Override - public int deleteVmByVnfId(String vnfInstanceId) { - return getMapperManager(VmMapper.class).deleteByVnfId(vnfInstanceId); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfDaoImpl.java deleted file mode 100644 index de1b293..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfDaoImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.inf.VnfDao; -import org.onap.vfc.nfvo.res.service.entity.VnfEntity; -import org.onap.vfc.nfvo.res.service.mapper.VnfMapper; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public class VnfDaoImpl extends AbstractDao implements VnfDao { - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public VnfEntity getVnf(String id) { - return getMapperManager(VnfMapper.class).selectByPrimaryKey(id); - } - - /** - *
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - @Override - public List getVnfs(Map condition) { - return getMapperManager(VnfMapper.class).getVnfs(condition); - } - - /** - *
- * - * @param vnfEntity - * @return - * @since NFVO 0.5 - */ - @Override - public int addVnf(VnfEntity vnfEntity) { - return getMapperManager(VnfMapper.class).insert(vnfEntity); - } - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public int deleteVnfById(String id) { - return getMapperManager(VnfMapper.class).deleteByPrimaryKey(id); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfInfoDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfInfoDaoImpl.java deleted file mode 100644 index a01e01d..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfInfoDaoImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.inf.VnfInfoDao; -import org.onap.vfc.nfvo.res.service.entity.VnfInfoEntity; -import org.onap.vfc.nfvo.res.service.mapper.VnfInfoMapper; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public class VnfInfoDaoImpl extends AbstractDao implements VnfInfoDao { - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public VnfInfoEntity getVnfInfo(String id) { - return getMapperManager(VnfInfoMapper.class).selectByPrimaryKey(id); - } - - /** - *
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - @Override - public List getVnfInfos(Map condition) { - return getMapperManager(VnfInfoMapper.class).getVnfInfos(condition); - } - - /** - *
- * - * @param vmEntity - * @return - * @since NFVO 0.5 - */ - @Override - public int addVnfInfo(VnfInfoEntity vnfInfoEntity) { - return getMapperManager(VnfInfoMapper.class).insert(vnfInfoEntity); - } - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public int deleteVnfInfoById(String id) { - return getMapperManager(VnfInfoMapper.class).deleteByPrimaryKey(id); - } - - /** - *
- * - * @param vnfInfoEntity - * @return - * @since NFVO 0.5 - */ - @Override - public int updateVnfInfo(VnfInfoEntity vnfInfoEntity) { - return getMapperManager(VnfInfoMapper.class).updateByPrimaryKeySelective(vnfInfoEntity); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfStatusDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfStatusDaoImpl.java deleted file mode 100644 index 6570664..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/impl/VnfStatusDaoImpl.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.inf.VnfStatusDao; -import org.onap.vfc.nfvo.res.service.entity.VnfStatusEntity; -import org.onap.vfc.nfvo.res.service.mapper.VnfStatusMapper; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -public class VnfStatusDaoImpl extends AbstractDao implements VnfStatusDao { - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public VnfStatusEntity getVnfStatus(String id) { - return getMapperManager(VnfStatusMapper.class).selectByPrimaryKey(id); - } - - /** - *
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - @Override - public List getVnfStatuss(Map condition) { - return getMapperManager(VnfStatusMapper.class).getVnfStatuss(condition); - } - - /** - *
- * - * @param vnfStatusEntity - * @return - * @since NFVO 0.5 - */ - @Override - public int addVnfStatus(VnfStatusEntity vnfStatusEntity) { - return getMapperManager(VnfStatusMapper.class).insert(vnfStatusEntity); - } - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - @Override - public int deleteVnfStatusById(String id) { - return getMapperManager(VnfStatusMapper.class).deleteByPrimaryKey(id); - } - - /** - *
- * - * @param vnfStatusEntity - * @return - * @since NFVO 0.5 - */ - @Override - public int updateVnfStatus(VnfStatusEntity vnfStatusEntity) { - return getMapperManager(VnfStatusMapper.class).updateByPrimaryKeySelective(vnfStatusEntity); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/HostDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/HostDao.java deleted file mode 100644 index 0f0c825..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/HostDao.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.HostEntity; - -/** - * Host info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface HostDao { - - /** - * It is used to get Host info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - HostEntity getHost(String id); - - /** - * It is used to get Hosts info.
- * - * @param condition - * @return The get result - * @since NFVO 0.5 - */ - List getHosts(Map condition); - - /** - * It is used to delete Hosts info.
- * - * @param id - * @return The delete result - * @since NFVO 0.5 - */ - int deleteHost(String id); - - /** - * It is used to delete Hosts info.
- * - * @param vimId - * @return The delete result - * @since NFVO 0.5 - */ - int deleteHostByVimId(String vimId); - - /** - * It is used to add Hosts info.
- * - * @param hostEntity - * @return The add result - * @since NFVO 0.5 - */ - int addHost(HostEntity hostEntity); - - /** - * It is used to add Hosts info.
- * - * @param hostEntity - * @return The add result - * @since NFVO 0.5 - */ - int addHostSelective(HostEntity hostEntity); - - /** - * It is used to update Hosts info.
- * - * @param hostEntity - * @return The update result - * @since NFVO 0.5 - */ - int updateHostSelective(HostEntity hostEntity); - - /** - * It is used to update Hosts info.
- * - * @param hostEntity - * @return The update result - * @since NFVO 0.5 - */ - int updateHost(HostEntity hostEntity); - - /** - * It is used to update Hosts info.
- * - * @param hostEntity - * @return The update result - * @since NFVO 0.5 - */ - int updateHostByVimId(HostEntity hostEntity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/LocationDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/LocationDao.java deleted file mode 100644 index 4266b6a..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/LocationDao.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; - -/** - * - * Location DAO Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface LocationDao { - - /** - * - * Get Location.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - LocationEntity getLocation(String id); - - /** - * - * Get Locations.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getLocations(Map condition); - - /** - * - * Delete Location.
- * - * @param location - * @return - * @since NFVO 0.5 - */ - int deleteLocation(String location); - - /** - * - * Add Location.
- * - * @param sodoResEntity - * @return - * @since NFVO 0.5 - */ - int addLocation(LocationEntity sodoResEntity); - - /** - * - * Add Selective Location.
- * - * @param sodoResEntity - * @return - * @since NFVO 0.5 - */ - int addLocationSelective(LocationEntity sodoResEntity); - - /** - * - * Update selective location.
- * - * @param sodoResEntity - * @return - * @since NFVO 0.5 - */ - int updateLocationSelective(LocationEntity sodoResEntity); - - /** - * - * Update Location.
- * - * @param sodoResEntity - * @return - * @since NFVO 0.5 - */ - int updateLocation(LocationEntity sodoResEntity); - - /** - * - * Get Country.
- * - * @return - * @since NFVO 0.5 - */ - List getCountry(); - - /** - * - * Get Location by Country.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getLocationByCountry(Map condition); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/NetworkDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/NetworkDao.java deleted file mode 100644 index 1c9b319..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/NetworkDao.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; - -/** - * - * Network DOA Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface NetworkDao { - - /** - * - * Get Network Details.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - NetworkEntity getNetwork(String id); - - /** - * - * Get details of available networks.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getNetworks(Map condition); - - /** - * - * Delete Network.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - int deleteNetwork(String id); - - /** - * - * Delete network by VIM ID.
- * - * @param vimId - * @return - * @since NFVO 0.5 - */ - int deleteNetworkByVimId(String vimId); - - /** - * - * Add Network.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int addNetwork(NetworkEntity networkEntity); - - /** - * - * Add selective network.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int addNetworkSelective(NetworkEntity networkEntity); - - /** - * - * Update selective network.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int updateNetworkSelective(NetworkEntity networkEntity); - - /** - * - * Update network.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int updateNetwork(NetworkEntity networkEntity); - - /** - * - * Update network by VIM ID.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int updateNetworkByVimId(NetworkEntity networkEntity); - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/PortDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/PortDao.java deleted file mode 100644 index 555e507..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/PortDao.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.PortEntity; - -/** - * Port info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface PortDao { - - /** - * It is used to get Port info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - PortEntity getPort(String id); - - /** - * It is used to get Ports info.
- * - * @param condition - * @return The get result - * @since NFVO 0.5 - */ - List getPorts(Map condition); - - /** - * It is used to delete Ports info.
- * - * @param id - * @return The delete result - * @since NFVO 0.5 - */ - int deletePort(String id); - - /** - * It is used to delete Ports info.
- * - * @param vimId - * @return The delete result - * @since NFVO 0.5 - */ - int deletePortByVimId(String vimId); - - /** - * It is used to add Ports info.
- * - * @param portEntity - * @return The add result - * @since NFVO 0.5 - */ - int addPort(PortEntity portEntity); - - /** - * It is used to add Ports info.
- * - * @param portEntity - * @return The add result - * @since NFVO 0.5 - */ - int addPortSelective(PortEntity portEntity); - - /** - * It is used to update Ports info.
- * - * @param portEntity - * @return The update result - * @since NFVO 0.5 - */ - int updatePortSelective(PortEntity portEntity); - - /** - * It is used to update Ports info.
- * - * @param portEntity - * @return The update result - * @since NFVO 0.5 - */ - int updatePort(PortEntity portEntity); - - /** - * It is used to update Ports info.
- * - * @param portEntity - * @return The update result - * @since NFVO 0.5 - */ - int updatePortByVimId(PortEntity portEntity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/SitesDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/SitesDao.java deleted file mode 100644 index c179d40..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/SitesDao.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; - -/** - * Sites info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface SitesDao { - - /** - * It is used to get Sites info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - SitesEntity getSite(String id); - - /** - * It is used to get Sites info.
- * - * @param condition - * @return The get result - * @since NFVO 0.5 - */ - List getSites(Map condition); - - /** - * It is used to get Sites info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - int deleteSite(String id); - - /** - * It is used to delete Sites info.
- * - * @param sitesEntity - * @return The delete result - * @since NFVO 0.5 - */ - int addSite(SitesEntity sitesEntity); - - /** - * It is used to add Sites info.
- * - * @param sitesEntity - * @return The add result - * @since NFVO 0.5 - */ - int addSiteSelective(SitesEntity sitesEntity); - - /** - * It is used to add Sites info.
- * - * @param sitesEntity - * @return The add result - * @since NFVO 0.5 - */ - int updateSiteSelective(SitesEntity sitesEntity); - - /** - * It is used to update Sites info.
- * - * @param sitesEntity - * @return The update result - * @since NFVO 0.5 - */ - int updateSite(SitesEntity sitesEntity); - - /** - * It is used to update Sites info.
- * - * @param sitesEntity - * @return The update result - * @since NFVO 0.5 - */ - int updateSiteByVimId(SitesEntity sitesEntity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VimDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VimDao.java deleted file mode 100644 index 38f1dda..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VimDao.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; - -import org.onap.vfc.nfvo.res.service.entity.VimEntity; - -/** - * Vim info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface VimDao { - - /** - * It is used to get Vim info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - VimEntity getVim(String id); - - /** - * It is used to get Vims info.
- * - * @return The get result - * @since NFVO 0.5 - */ - List getVims(); - - /** - * It is used to delete Vim info.
- * - * @param id - * @return The delete result - * @since NFVO 0.5 - */ - int deleteVim(String id); - - /** - * It is used to add Vim info.
- * - * @param vimEntity - * @return The add result - * @since NFVO 0.5 - */ - int addVim(VimEntity vimEntity); - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VirtualLinkDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VirtualLinkDao.java deleted file mode 100644 index 4b12169..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VirtualLinkDao.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public interface VirtualLinkDao { - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - VirtualLinkEntity getVl(String id); - - /** - *
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getVls(Map condition); - - /** - *
- * - * @param virtualLinkEntity - * @return - * @since NFVO 0.5 - */ - int addVl(VirtualLinkEntity virtualLinkEntity); - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - int deleteVlById(String id); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VmDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VmDao.java deleted file mode 100644 index 3b88b5c..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VmDao.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VmEntity; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public interface VmDao { - - VmEntity getVm(String id); - - List getVms(Map condition); - - int addVm(VmEntity vmEntity); - - int deleteVmById(String id); - - int updateVm(VmEntity vmEntity); - - int deleteVmByVnfId(String vnfInstanceId); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfDao.java deleted file mode 100644 index 03b7ff4..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfDao.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfEntity; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public interface VnfDao { - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - VnfEntity getVnf(String id); - - /** - *
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getVnfs(Map condition); - - /** - *
- * - * @param vnfEntity - * @return - * @since NFVO 0.5 - */ - int addVnf(VnfEntity vnfEntity); - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - int deleteVnfById(String id); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfInfoDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfInfoDao.java deleted file mode 100644 index 6ea65cb..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfInfoDao.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfInfoEntity; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public interface VnfInfoDao { - - VnfInfoEntity getVnfInfo(String id); - - List getVnfInfos(Map condition); - - int addVnfInfo(VnfInfoEntity vnfInfoEntity); - - int deleteVnfInfoById(String id); - - int updateVnfInfo(VnfInfoEntity vnfInfoEntity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfStatusDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfStatusDao.java deleted file mode 100644 index ee6f0f1..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/dao/inf/VnfStatusDao.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfStatusEntity; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -public interface VnfStatusDao { - - VnfStatusEntity getVnfStatus(String id); - - List getVnfStatuss(Map condition); - - int addVnfStatus(VnfStatusEntity vnfStatusEntity); - - int deleteVnfStatusById(String id); - - int updateVnfStatus(VnfStatusEntity vnfStatusEntity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/HostEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/HostEntity.java deleted file mode 100644 index 6c5a20f..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/HostEntity.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * Host entity class.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 31, 2016 - */ -public class HostEntity { - - private String id; - - private String name; - - private String cpu; - - private String memory; - - private String disk; - - private String vimId; - - private String vimName; - - /** - * @return Returns the id. - */ - public String getId() { - return id; - } - - /** - * @param id The id to set. - */ - public void setId(String id) { - this.id = id; - } - - /** - * @return Returns the name. - */ - public String getName() { - return name; - } - - /** - * @param name The name to set. - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return Returns the cpu. - */ - public String getCpu() { - return cpu; - } - - /** - * @param cpu The cpu to set. - */ - public void setCpu(String cpu) { - this.cpu = cpu; - } - - /** - * @return Returns the memory. - */ - public String getMemory() { - return memory; - } - - /** - * @param memory The memory to set. - */ - public void setMemory(String memory) { - this.memory = memory; - } - - /** - * @return Returns the disk. - */ - public String getDisk() { - return disk; - } - - /** - * @param disk The disk to set. - */ - public void setDisk(String disk) { - this.disk = disk; - } - - /** - * @return Returns the vimId. - */ - public String getVimId() { - return vimId; - } - - /** - * @param vimId The vimId to set. - */ - public void setVimId(String vimId) { - this.vimId = vimId; - } - - /** - * @return Returns the vimName. - */ - public String getVimName() { - return vimName; - } - - /** - * @param vimName The vimName to set. - */ - public void setVimName(String vimName) { - this.vimName = vimName; - } - - /** - * - * To entity.
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static HostEntity toEntity(JSONObject jsonObject) { - HostEntity hostEntity = new HostEntity(); - hostEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); - hostEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); - hostEntity.setCpu(JsonUtil.getJsonFieldStr(jsonObject, "cpu")); - hostEntity.setMemory(JsonUtil.getJsonFieldStr(jsonObject, "memory")); - hostEntity.setDisk(JsonUtil.getJsonFieldStr(jsonObject, "disk")); - hostEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); - hostEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); - return hostEntity; - } - - @Override - public String toString() { - JSONObject hostResJson = new JSONObject(); - hostResJson.put("id", StringUtils.trimToEmpty(this.getId())); - hostResJson.put("name", StringUtils.trimToEmpty(this.getName())); - hostResJson.put("cpu", StringUtils.trimToEmpty(this.getCpu())); - hostResJson.put("memory", StringUtils.trimToEmpty(this.getMemory())); - hostResJson.put("disk", StringUtils.trimToEmpty(this.getDisk())); - hostResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); - hostResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); - return hostResJson.toString(); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/LocationEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/LocationEntity.java deleted file mode 100644 index 95d5fad..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/LocationEntity.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * - * Location entity class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class LocationEntity { - - /** - * This field was generated by MyBatis Generator. This field corresponds to - * the database column location.ID - * - * @mbggenerated - */ - private String id; - - /** - * This field was generated by MyBatis Generator. This field corresponds to - * the database column location.COUNTRY - * - * @mbggenerated - */ - private String country; - - /** - * This field was generated by MyBatis Generator. This field corresponds to - * the database column location.LOCATION - * - * @mbggenerated - */ - private String location; - - /** - * This field was generated by MyBatis Generator. This field corresponds to - * the database column location.LATITUDE - * - * @mbggenerated - */ - private String latitude; - - /** - * This field was generated by MyBatis Generator. This field corresponds to - * the database column location.LONGITUDE - * - * @mbggenerated - */ - private String longitude; - - private String description; - - /** - * This method was generated by MyBatis Generator. This method returns the - * value of the database column location.ID - * - * @return the value of location.ID - * @mbggenerated - */ - public String getId() { - return id; - } - - /** - * This method was generated by MyBatis Generator. This method sets the - * value of the database column location.ID - * - * @param id - * the value for location.ID - * @mbggenerated - */ - public void setId(String id) { - this.id = id == null ? null : id.trim(); - } - - /** - * This method was generated by MyBatis Generator. This method returns the - * value of the database column location.COUNTRY - * - * @return the value of location.COUNTRY - * @mbggenerated - */ - public String getCountry() { - return country; - } - - /** - * This method was generated by MyBatis Generator. This method sets the - * value of the database column location.COUNTRY - * - * @param country - * the value for location.COUNTRY - * @mbggenerated - */ - public void setCountry(String country) { - this.country = country == null ? null : country.trim(); - } - - /** - * This method was generated by MyBatis Generator. This method returns the - * value of the database column location.LOCATION - * - * @return the value of location.LOCATION - * @mbggenerated - */ - public String getLocation() { - return location; - } - - /** - * This method was generated by MyBatis Generator. This method sets the - * value of the database column location.LOCATION - * - * @param location - * the value for location.LOCATION - * @mbggenerated - */ - public void setLocation(String location) { - this.location = location == null ? null : location.trim(); - } - - /** - * This method was generated by MyBatis Generator. This method returns the - * value of the database column location.LATITUDE - * - * @return the value of location.LATITUDE - * @mbggenerated - */ - public String getLatitude() { - return latitude; - } - - /** - * This method was generated by MyBatis Generator. This method sets the - * value of the database column location.LATITUDE - * - * @param latitude - * the value for location.LATITUDE - * @mbggenerated - */ - public void setLatitude(String latitude) { - this.latitude = latitude == null ? null : latitude.trim(); - } - - /** - * This method was generated by MyBatis Generator. This method returns the - * value of the database column location.LONGITUDE - * - * @return the value of location.LONGITUDE - * @mbggenerated - */ - public String getLongitude() { - return longitude; - } - - /** - * This method was generated by MyBatis Generator. This method sets the - * value of the database column location.LONGITUDE - * - * @param longitude - * the value for location.LONGITUDE - * @mbggenerated - */ - public void setLongitude(String longitude) { - this.longitude = longitude == null ? null : longitude.trim(); - } - - /** - * @return Returns the description. - */ - public String getDescription() { - return description; - } - - /** - * @param description The description to set. - */ - public void setDescription(String description) { - this.description = description == null ? null : description.trim(); - } - - /** - * - * To Entity.
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static LocationEntity toEntity(JSONObject jsonObject) { - LocationEntity sodoresesEntity = new LocationEntity(); - sodoresesEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); - sodoresesEntity.setCountry(JsonUtil.getJsonFieldStr(jsonObject, "country")); - sodoresesEntity.setLocation(JsonUtil.getJsonFieldStr(jsonObject, "location")); - sodoresesEntity.setLatitude(JsonUtil.getJsonFieldStr(jsonObject, "latitude")); - sodoresesEntity.setLongitude(JsonUtil.getJsonFieldStr(jsonObject, "longitude")); - sodoresesEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description")); - return sodoresesEntity; - } - - @Override - public String toString() { - JSONObject locationJson = new JSONObject(); - locationJson.put("id", StringUtils.trimToEmpty(this.getId())); - locationJson.put("country", StringUtils.trimToEmpty(this.getCountry())); - locationJson.put("location", StringUtils.trimToEmpty(this.getLocation())); - locationJson.put("latitude", StringUtils.trimToEmpty(this.getLatitude())); - locationJson.put("longitude", StringUtils.trimToEmpty(this.getLongitude())); - locationJson.put("description", StringUtils.trimToEmpty(this.getDescription())); - return locationJson.toString(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/NetworkEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/NetworkEntity.java deleted file mode 100644 index 7f1a7e5..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/NetworkEntity.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * - * Network entity class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class NetworkEntity { - - /** - * This field corresponds to the database column network.ID - */ - private String id; - - /** - * This field corresponds to the database column network.NAME - */ - private String name; - - /** - * This field corresponds to the database column network.TENANT_ID - */ - private String tenantId; - - /** - * This field corresponds to the database column network.VIM_ID - */ - private String vimId; - - /** - * This field corresponds to the database column ivm.VIM_NAME - */ - private String vimName; - - /** - * This field corresponds to the database column network.STATUS - */ - private String status; - - /** - * This field corresponds to the database column network.PHYSICAL_NETWORK - */ - - private String physicalNetwork; - - /** - * This field corresponds to the database column network.NETWORK_TYPE - */ - private String networkType; - - /** - * This field corresponds to the database column network.SEGMENTATION_ID - */ - private String segmentationId; - - /** - * return the value of network.ID - */ - public String getId() { - return id; - } - - /** - * This method sets the value of the database column network.ID - * - * @param id - * the value for network.ID - */ - public void setId(String id) { - this.id = id == null ? null : id.trim(); - } - - /** - * return the value of network.NAME - */ - public String getName() { - return name; - } - - /** - * This method sets the value of the database column network.NAME - * - * @param name - * the value for network.NAME - */ - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - /** - * return the value of network.TENANT_ID - */ - public String getTenantId() { - return tenantId; - } - - /** - * This method sets the value of the database column network.TENANT_ID - * - * @param tenantId - * the value for network.TENANT_ID - */ - public void setTenantId(String tenantId) { - this.tenantId = tenantId == null ? null : tenantId.trim(); - } - - /** - * return the value of network.VIM_ID - */ - public String getVimId() { - return vimId; - } - - /** - * This method sets the value of the database column network.VIM_ID - * - * @param networkVimId - * the value for network.VIM_ID - */ - public void setVimId(String networkVimId) { - this.vimId = networkVimId == null ? null : networkVimId.trim(); - } - - /** - * return the value of ivm.VIM_NAME - */ - public String getVimName() { - return vimName; - } - - /** - * This method sets the value of the database column ivm.VIM_NAME - * - * @param networkVimName - * the value for ivm.VIM_NAME - */ - public void setVimName(String networkVimName) { - this.vimName = networkVimName == null ? null : networkVimName.trim(); - } - - /** - * return the value of network.STATUS - */ - public String getStatus() { - return status; - } - - /** - * This method sets the value of the database column network.STATUS - * - * @param networkStatus - * the value for network.STATUS - */ - public void setStatus(String networkStatus) { - this.status = networkStatus == null ? null : networkStatus.trim().toLowerCase(); - } - - /** - * return the value of network.PHYSICAL_NETWORK - */ - public String getPhysicalNetwork() { - return physicalNetwork; - } - - /** - * This method sets the value of the database column - * network.PHYSICAL_NETWORK - * - * @param physicalNetwork - * the value for network.PHYSICAL_NETWORK - */ - public void setPhysicalNetwork(String physicalNetwork) { - this.physicalNetwork = physicalNetwork == null ? null : physicalNetwork.trim(); - } - - /** - * return the value of network.NETWORK_TYPE - */ - public String getNetworkType() { - return networkType; - } - - /** - * This method sets the value of the database column network.NETWORK_TYPE - * - * @param networkType - * the value for network.NETWORK_TYPE - */ - public void setNetworkType(String networkType) { - this.networkType = networkType == null ? null : networkType.trim(); - } - - /** - * return the value of network.SEGMENTATION_ID - */ - public String getSegmentationId() { - return segmentationId; - } - - /** - * This method sets the value of the database column network.SEGMENTATION_ID - * - * @param segmentationId - * the value for network.SEGMENTATION_ID - */ - public void setSegmentationId(String segmentationId) { - this.segmentationId = segmentationId == null ? null : segmentationId.trim(); - } - - /** - * - * To Entity.
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static NetworkEntity toEntity(JSONObject jsonObject) { - NetworkEntity sitesEntity = new NetworkEntity(); - sitesEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); - sitesEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); - sitesEntity.setTenantId(JsonUtil.getJsonFieldStr(jsonObject, "tenantId")); - sitesEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status")); - sitesEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); - sitesEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); - sitesEntity.setPhysicalNetwork(JsonUtil.getJsonFieldStr(jsonObject, "physicalNetwork")); - sitesEntity.setNetworkType(JsonUtil.getJsonFieldStr(jsonObject, "networkType")); - sitesEntity.setSegmentationId(JsonUtil.getJsonFieldStr(jsonObject, "segmentationId")); - return sitesEntity; - } - - @Override - public String toString() { - JSONObject networkJson = new JSONObject(); - networkJson.put("id", StringUtils.trimToEmpty(this.getId())); - networkJson.put("name", StringUtils.trimToEmpty(this.getName())); - networkJson.put("tenant_id", StringUtils.trimToEmpty(this.getTenantId())); - networkJson.put("status", StringUtils.trimToEmpty(this.getStatus())); - networkJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); - networkJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); - networkJson.put("provider:physical_network", StringUtils.trimToEmpty(this.getPhysicalNetwork())); - networkJson.put("provider:network_type", StringUtils.trimToEmpty(this.getNetworkType())); - networkJson.put("provider:segmentation_id", StringUtils.trimToEmpty(this.getSegmentationId())); - return networkJson.toString(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/PortEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/PortEntity.java deleted file mode 100644 index 2249726..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/PortEntity.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * Port Entity Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 31, 2016 - */ -public class PortEntity { - - private String id; - - private String name; - - private String networkId; - - private String status; - - private String tenantId; - - private String vimId; - - private String vimName; - - /** - * @return Returns the id. - */ - public String getId() { - return id; - } - - /** - * @param id The id to set. - */ - public void setId(String id) { - this.id = id == null ? null : id.trim(); - } - - /** - * @return Returns the name. - */ - public String getName() { - return name; - } - - /** - * @param name The name to set. - */ - public void setName(String name) { - this.name = name; - } - - /** - * @return Returns the networkId. - */ - public String getNetworkId() { - return networkId; - } - - /** - * @param networkId The networkId to set. - */ - public void setNetworkId(String networkId) { - this.networkId = networkId; - } - - /** - * @return Returns the status. - */ - public String getStatus() { - return status; - } - - /** - * @param status The status to set. - */ - public void setStatus(String status) { - this.status = status; - } - - /** - * @return Returns the tenantId. - */ - public String getTenantId() { - return tenantId; - } - - /** - * @param tenantId The tenantId to set. - */ - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - - /** - * @return Returns the vimId. - */ - public String getVimId() { - return vimId; - } - - /** - * @param vimId The vimId to set. - */ - public void setVimId(String vimId) { - this.vimId = vimId; - } - - /** - * @return Returns the vimName. - */ - public String getVimName() { - return vimName; - } - - /** - * @param vimName The vimName to set. - */ - public void setVimName(String vimName) { - this.vimName = vimName; - } - - /** - * - * To Entity.
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static PortEntity toEntity(JSONObject jsonObject) { - PortEntity portEntity = new PortEntity(); - portEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); - portEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); - portEntity.setNetworkId(JsonUtil.getJsonFieldStr(jsonObject, "networkId")); - portEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status")); - portEntity.setTenantId(JsonUtil.getJsonFieldStr(jsonObject, "tenantId")); - portEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); - portEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); - return portEntity; - } - - @Override - public String toString() { - JSONObject portResJson = new JSONObject(); - portResJson.put("id", StringUtils.trimToEmpty(this.getId())); - portResJson.put("name", StringUtils.trimToEmpty(this.getName())); - portResJson.put("networkId", StringUtils.trimToEmpty(this.getNetworkId())); - portResJson.put("status", StringUtils.trimToEmpty(this.getStatus())); - portResJson.put("tenantId", StringUtils.trimToEmpty(this.getTenantId())); - portResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); - portResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); - return portResJson.toString(); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/SitesEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/SitesEntity.java deleted file mode 100644 index c2940d6..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/SitesEntity.java +++ /dev/null @@ -1,309 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.common.util.StringUtil; - -import net.sf.json.JSONObject; - -/** - * - * Sites entity class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class SitesEntity { - - private String id; - - private String name; - - private String location; - - private String country; - - private String vimId; - - private String vimName; - - private String status; - - private String totalCPU = "0"; - - private String totalMemory = "0"; - - private String totalDisk = "0"; - - private String usedCPU = "0"; - - private String usedMemory = "0"; - - private String usedDisk = "0"; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id == null ? null : id.trim(); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name == null ? null : name.trim(); - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location == null ? null : location.trim(); - } - - public String getCountry() { - return country; - } - - public void setCountry(String country) { - this.country = country == null ? null : country.trim(); - } - - public String getVimId() { - return vimId; - } - - public void setVimId(String siteVimId) { - this.vimId = siteVimId == null ? null : siteVimId.trim(); - } - - public String getVimName() { - return vimName; - } - - public void setVimName(String siteVimName) { - this.vimName = siteVimName == null ? null : siteVimName.trim(); - } - - public String getStatus() { - return status; - } - - public void setStatus(String siteStatus) { - this.status = siteStatus == null ? null : siteStatus.trim().toLowerCase(); - } - - /** - * @return Returns the totalCPU. - */ - public String getTotalCPU() { - return totalCPU; - } - - /** - * @param totalCPU The totalCPU to set. - */ - public void setTotalCPU(String totalCPU) { - this.totalCPU = totalCPU == null ? null : totalCPU.trim(); - } - - /** - * @return Returns the totalMemory. - */ - public String getTotalMemory() { - return totalMemory; - } - - /** - * @param totalMemory The totalMemory to set. - */ - public void setTotalMemory(String totalMemory) { - this.totalMemory = totalMemory == null ? null : totalMemory.trim(); - } - - /** - * @return Returns the totalDisk. - */ - public String getTotalDisk() { - return totalDisk; - } - - /** - * @param totalDisk The totalDisk to set. - */ - public void setTotalDisk(String totalDisk) { - this.totalDisk = totalDisk == null ? null : totalDisk.trim(); - } - - /** - * @return Returns the usedCPU. - */ - public String getUsedCPU() { - return usedCPU; - } - - /** - * @param usedCPU The usedCPU to set. - */ - public void setUsedCPU(String usedCPU) { - this.usedCPU = usedCPU == null ? null : usedCPU.trim(); - } - - /** - * @return Returns the usedMemory. - */ - public String getUsedMemory() { - return usedMemory; - } - - /** - * @param usedMemory The usedMemory to set. - */ - public void setUsedMemory(String usedMemory) { - this.usedMemory = usedMemory == null ? null : usedMemory.trim(); - } - - /** - * @return Returns the usedDisk. - */ - public String getUsedDisk() { - return usedDisk; - } - - /** - * @param usedDisk The usedDisk to set. - */ - public void setUsedDisk(String usedDisk) { - this.usedDisk = usedDisk == null ? null : usedDisk.trim(); - } - - /** - * - * To Entity.
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static SitesEntity toEntity(JSONObject jsonObject) { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); - sitesEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); - sitesEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status")); - sitesEntity.setLocation(JsonUtil.getJsonFieldStr(jsonObject, "location")); - sitesEntity.setCountry(JsonUtil.getJsonFieldStr(jsonObject, "country")); - sitesEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); - sitesEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); - sitesEntity.setTotalCPU(JsonUtil.getJsonFieldStr(jsonObject, "totalCPU")); - sitesEntity.setTotalMemory(JsonUtil.getJsonFieldStr(jsonObject, "totalMemory")); - sitesEntity.setTotalDisk(JsonUtil.getJsonFieldStr(jsonObject, "totalDisk")); - sitesEntity.setUsedCPU(JsonUtil.getJsonFieldStr(jsonObject, "usedCPU")); - sitesEntity.setUsedMemory(JsonUtil.getJsonFieldStr(jsonObject, "usedMemory")); - sitesEntity.setUsedDisk(JsonUtil.getJsonFieldStr(jsonObject, "usedDisk")); - return sitesEntity; - } - - @Override - public String toString() { - JSONObject siteResJson = new JSONObject(); - siteResJson.put("id", StringUtils.trimToEmpty(this.getId())); - siteResJson.put("name", StringUtils.trimToEmpty(this.getName())); - siteResJson.put("status", StringUtils.trimToEmpty(this.getStatus())); - siteResJson.put("location", StringUtils.trimToEmpty(this.getLocation())); - siteResJson.put("country", StringUtils.trimToEmpty(this.getCountry())); - siteResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); - siteResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); - siteResJson.put("totalCPU", StringUtils.trimToEmpty(this.getTotalCPU())); - siteResJson.put("totalMemory", StringUtils.trimToEmpty(this.getTotalMemory())); - siteResJson.put("totalDisk", StringUtils.trimToEmpty(this.getTotalDisk())); - siteResJson.put("usedCPU", StringUtils.trimToEmpty(this.getUsedCPU())); - siteResJson.put("usedMemory", StringUtils.trimToEmpty(this.getUsedMemory())); - siteResJson.put("usedDisk", StringUtils.trimToEmpty(this.getUsedDisk())); - - return siteResJson.toString(); - } - - /** - * - * Check whther the resource is zero.
- * - * @param siteEntity - * @return - * @since NFVO 0.5 - */ - public static boolean checkResourceIsZero(SitesEntity siteEntity) { - - if(StringUtil.isAnyLargeThanZero(siteEntity.getUsedCPU(), siteEntity.getUsedMemory(), - siteEntity.getUsedDisk())) { - return false; - } - - return true; - } - - /** - * - * Check resource.
- * - * @param siteEntity - * @return - * @since NFVO 0.5 - */ - public static boolean checkResource(SitesEntity siteEntity) { - String cpu = siteEntity.getTotalCPU(); - String memory = siteEntity.getTotalMemory(); - String disk = siteEntity.getTotalDisk(); - String cpuUsed = siteEntity.getUsedCPU(); - String memoryUsed = siteEntity.getUsedMemory(); - String diskUsed = siteEntity.getUsedDisk(); - - if(!StringUtil.isInteger(cpu, cpuUsed)) { - return false; - } - - if(!StringUtil.isNumeric(memory, disk, memoryUsed, diskUsed)) { - return false; - } - return true; - } - - /** - * - * Format data.
- * - * @param siteEntity - * @since NFVO 0.5 - */ - public static void dataFramat(SitesEntity siteEntity) { - siteEntity.setTotalCPU(StringUtil.numFormat(siteEntity.getTotalCPU())); - siteEntity.setTotalMemory(StringUtil.numFormat(siteEntity.getTotalMemory())); - siteEntity.setTotalDisk(StringUtil.numFormat(siteEntity.getTotalDisk())); - siteEntity.setUsedCPU(StringUtil.numFormat(siteEntity.getUsedCPU())); - siteEntity.setUsedMemory(StringUtil.numFormat(siteEntity.getUsedMemory())); - siteEntity.setUsedDisk(StringUtil.numFormat(siteEntity.getUsedDisk())); - - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VimEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VimEntity.java deleted file mode 100644 index b1b52de..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VimEntity.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * - * Virtualised infrastructure manager entity class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class VimEntity { - - /** - * This field corresponds to the database column vim.ID - * - * @mbggenerated - */ - private String id; - - /** - * This field corresponds to the database column vim.ID - * - * @mbggenerated - */ - private String name; - - /** - * This method was generated by MyBatis Generator. This method returns the - * value of the database column vim.ID - * - * @return the value of vim.ID - */ - public String getId() { - return id; - } - - /** - * This method was generated by MyBatis Generator. This method sets the - * value of the database column vim.ID - * - * @param id - * the value for vim.ID - */ - public void setId(String id) { - this.id = id == null ? null : id.trim(); - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - /** - * - * To Entity.
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static VimEntity toEntity(JSONObject jsonObject) { - VimEntity vimEntity = new VimEntity(); - vimEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); - vimEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); - return vimEntity; - } - - /** - * - * To String.
- * - * @return - * @since NFVO 0.5 - */ - public String toString() { - JSONObject resJson = new JSONObject(); - resJson.put("id", StringUtils.trimToEmpty(this.getId())); - resJson.put("name", StringUtils.trimToEmpty(this.getName())); - return resJson.toString(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VirtualLinkEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VirtualLinkEntity.java deleted file mode 100644 index d4408e8..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VirtualLinkEntity.java +++ /dev/null @@ -1,285 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import java.io.Serializable; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * @author l00345485 - * @date 2016-10-27 - */ -public class VirtualLinkEntity implements Serializable { - - /** */ - private String id; - - /** */ - private String name; - - /** */ - private String backendId; - - /** */ - private String isPublic; - - /** */ - private String dcName; - - /** */ - private String vimId; - - /** */ - private String vimName; - - /** */ - private String physicialNet; - - /** */ - private String nsId; - - /** */ - private String nsName; - - /** */ - private String description; - - /** */ - private String networkType; - - /** */ - private String segmentation; - - /** */ - private String mtu; - - /** */ - private String vlanTransparent; - - /** */ - private String routerExternal; - - /** */ - private String resourceProviderType; - - /** */ - private String resourceProviderId; - - private static final long serialVersionUID = 1L; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getBackendId() { - return backendId; - } - - public void setBackendId(String backendId) { - this.backendId = backendId; - } - - public String getIsPublic() { - return isPublic; - } - - public void setIsPublic(String isPublic) { - this.isPublic = isPublic; - } - - public String getDcName() { - return dcName; - } - - public void setDcName(String dcName) { - this.dcName = dcName; - } - - public String getVimId() { - return vimId; - } - - public void setVimId(String vimId) { - this.vimId = vimId; - } - - public String getVimName() { - return vimName; - } - - public void setVimName(String vimName) { - this.vimName = vimName; - } - - public String getPhysicialNet() { - return physicialNet; - } - - public void setPhysicialNet(String physicialNet) { - this.physicialNet = physicialNet; - } - - public String getNsId() { - return nsId; - } - - public void setNsId(String nsId) { - this.nsId = nsId; - } - - public String getNsName() { - return nsName; - } - - public void setNsName(String nsName) { - this.nsName = nsName; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getNetworkType() { - return networkType; - } - - public void setNetworkType(String networkType) { - this.networkType = networkType; - } - - public String getSegmentation() { - return segmentation; - } - - public void setSegmentation(String segmentation) { - this.segmentation = segmentation; - } - - public String getMtu() { - return mtu; - } - - public void setMtu(String mtu) { - this.mtu = mtu; - } - - public String getVlanTransparent() { - return vlanTransparent; - } - - public void setVlanTransparent(String vlanTransparent) { - this.vlanTransparent = vlanTransparent; - } - - public String getRouterExternal() { - return routerExternal; - } - - public void setRouterExternal(String routerExternal) { - this.routerExternal = routerExternal; - } - - public String getResourceProviderType() { - return resourceProviderType; - } - - public void setResourceProviderType(String resourceProviderType) { - this.resourceProviderType = resourceProviderType; - } - - public String getResourceProviderId() { - return resourceProviderId; - } - - public void setResourceProviderId(String resourceProviderId) { - this.resourceProviderId = resourceProviderId; - } - - /** - *
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static VirtualLinkEntity toEntity(JSONObject jsonObject) { - VirtualLinkEntity virtualLinkEntity = new VirtualLinkEntity(); - virtualLinkEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "vlInstanceId")); - virtualLinkEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); - virtualLinkEntity.setBackendId(JsonUtil.getJsonFieldStr(jsonObject, "backendId")); - virtualLinkEntity.setIsPublic(JsonUtil.getJsonFieldStr(jsonObject, "isPublic")); - virtualLinkEntity.setDcName(JsonUtil.getJsonFieldStr(jsonObject, "dcName")); - virtualLinkEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); - virtualLinkEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); - virtualLinkEntity.setPhysicialNet(JsonUtil.getJsonFieldStr(jsonObject, "physicialNet")); - virtualLinkEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId")); - virtualLinkEntity.setNsName(JsonUtil.getJsonFieldStr(jsonObject, "nsName")); - virtualLinkEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description")); - virtualLinkEntity.setNetworkType(JsonUtil.getJsonFieldStr(jsonObject, "networkType")); - virtualLinkEntity.setSegmentation(JsonUtil.getJsonFieldStr(jsonObject, "segmentation")); - virtualLinkEntity.setMtu(JsonUtil.getJsonFieldStr(jsonObject, "mtu")); - virtualLinkEntity.setVlanTransparent(JsonUtil.getJsonFieldStr(jsonObject, "vlanTransparent")); - virtualLinkEntity.setRouterExternal(JsonUtil.getJsonFieldStr(jsonObject, "routerExternal")); - virtualLinkEntity.setResourceProviderId(JsonUtil.getJsonFieldStr(jsonObject, "resourceProviderId")); - virtualLinkEntity.setResourceProviderType(JsonUtil.getJsonFieldStr(jsonObject, "resourceProviderType")); - return virtualLinkEntity; - } - - @Override - public String toString() { - JSONObject virtualLinkResJson = new JSONObject(); - virtualLinkResJson.put("id", StringUtils.trimToEmpty(this.getId())); - virtualLinkResJson.put("name", StringUtils.trimToEmpty(this.getName())); - virtualLinkResJson.put("backendId", StringUtils.trimToEmpty(this.getBackendId())); - virtualLinkResJson.put("isPublic", StringUtils.trimToEmpty(this.getIsPublic())); - virtualLinkResJson.put("dcName", StringUtils.trimToEmpty(this.getDcName())); - virtualLinkResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); - virtualLinkResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); - virtualLinkResJson.put("physicialNet", StringUtils.trimToEmpty(this.getPhysicialNet())); - virtualLinkResJson.put("nsId", StringUtils.trimToEmpty(this.getNsId())); - virtualLinkResJson.put("nsName", StringUtils.trimToEmpty(this.getNsName())); - virtualLinkResJson.put("description", StringUtils.trimToEmpty(this.getDescription())); - virtualLinkResJson.put("networkType", StringUtils.trimToEmpty(this.getNetworkType())); - virtualLinkResJson.put("segmentation", StringUtils.trimToEmpty(this.getSegmentation())); - virtualLinkResJson.put("mtu", StringUtils.trimToEmpty(this.getMtu())); - virtualLinkResJson.put("vlanTransparent", StringUtils.trimToEmpty(this.getVlanTransparent())); - virtualLinkResJson.put("routerExternal", StringUtils.trimToEmpty(this.getRouterExternal())); - virtualLinkResJson.put("resourceProviderId", StringUtils.trimToEmpty(this.getResourceProviderId())); - virtualLinkResJson.put("resourceProviderType", StringUtils.trimToEmpty(this.getResourceProviderType())); - return virtualLinkResJson.toString(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VmEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VmEntity.java deleted file mode 100644 index d46633e..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VmEntity.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import java.io.Serializable; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * @author l00345485 - * @date 2016-10-28 - */ -public class VmEntity implements Serializable { - - /** */ - private String vmId; - - /** */ - private String vmName; - - /** */ - private String vmStatus; - - /** */ - private String vnfInstanceId; - - private static final long serialVersionUID = 1L; - - public String getVmId() { - return vmId; - } - - public void setVmId(String vmId) { - this.vmId = vmId; - } - - public String getVmName() { - return vmName; - } - - public void setVmName(String vmName) { - this.vmName = vmName; - } - - public String getVmStatus() { - return vmStatus; - } - - public void setVmStatus(String vmStatus) { - this.vmStatus = vmStatus; - } - - public String getVnfInstanceId() { - return vnfInstanceId; - } - - public void setVnfInstanceId(String vnfInstanceId) { - this.vnfInstanceId = vnfInstanceId; - } - - public static VmEntity toEntity(JSONObject jsonObject) { - VmEntity vmEntity = new VmEntity(); - vmEntity.setVmId(JsonUtil.getJsonFieldStr(jsonObject, "vmId")); - vmEntity.setVmName(JsonUtil.getJsonFieldStr(jsonObject, "vmName")); - vmEntity.setVmStatus(JsonUtil.getJsonFieldStr(jsonObject, "vmStatus")); - vmEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId")); - return vmEntity; - } - - @Override - public String toString() { - JSONObject vmResJson = new JSONObject(); - vmResJson.put("vmId", StringUtils.trimToEmpty(this.getVmId())); - vmResJson.put("vmName", StringUtils.trimToEmpty(this.getVmName())); - vmResJson.put("vmStatus", StringUtils.trimToEmpty(this.getVmStatus())); - vmResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getVnfInstanceId())); - return vmResJson.toString(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfEntity.java deleted file mode 100644 index 4028c89..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfEntity.java +++ /dev/null @@ -1,337 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import java.io.Serializable; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * @author l00345485 - * @date 2016-10-28 - */ -public class VnfEntity implements Serializable { - - /** */ - private String id; - - /** */ - private String vnfInstanceId; - - /** */ - private String vnfInstanceName; - - /** */ - private String nsId; - - /** */ - private String nsName; - - /** */ - private String vnfmId; - - /** */ - private String vnfmName; - - /** */ - private String vnfPackageName; - - /** */ - private String vnfDescriptorName; - - /** */ - private String vimId; - - /** */ - private String vimName; - - /** */ - private String vimTenant; - - /** */ - private String jobId; - - /** */ - private String vnfStatus; - - /** */ - private String vnfType; - - /** */ - private Integer maxVm; - - /** */ - private Integer maxCpu; - - /** */ - private Integer maxDisk; - - /** */ - private Integer maxRam; - - /** */ - private Integer maxShd; - - /** */ - private Integer maxNet; - - /** */ - private String name; - - private static final long serialVersionUID = 1L; - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getVnfInstanceId() { - return vnfInstanceId; - } - - public void setVnfInstanceId(String vnfInstanceId) { - this.vnfInstanceId = vnfInstanceId; - } - - public String getVnfInstanceName() { - return vnfInstanceName; - } - - public void setVnfInstanceName(String vnfInstanceName) { - this.vnfInstanceName = vnfInstanceName; - } - - public String getNsId() { - return nsId; - } - - public void setNsId(String nsId) { - this.nsId = nsId; - } - - public String getNsName() { - return nsName; - } - - public void setNsName(String nsName) { - this.nsName = nsName; - } - - public String getVnfmId() { - return vnfmId; - } - - public void setVnfmId(String vnfmId) { - this.vnfmId = vnfmId; - } - - public String getVnfmName() { - return vnfmName; - } - - public void setVnfmName(String vnfmName) { - this.vnfmName = vnfmName; - } - - public String getVnfPackageName() { - return vnfPackageName; - } - - public void setVnfPackageName(String vnfPackageName) { - this.vnfPackageName = vnfPackageName; - } - - public String getVnfDescriptorName() { - return vnfDescriptorName; - } - - public void setVnfDescriptorName(String vnfDescriptorName) { - this.vnfDescriptorName = vnfDescriptorName; - } - - public String getVimId() { - return vimId; - } - - public void setVimId(String vimId) { - this.vimId = vimId; - } - - public String getVimName() { - return vimName; - } - - public void setVimName(String vimName) { - this.vimName = vimName; - } - - public String getVimTenant() { - return vimTenant; - } - - public void setVimTenant(String vimTenant) { - this.vimTenant = vimTenant; - } - - public String getJobId() { - return jobId; - } - - public void setJobId(String jobId) { - this.jobId = jobId; - } - - public String getVnfStatus() { - return vnfStatus; - } - - public void setVnfStatus(String vnfStatus) { - this.vnfStatus = vnfStatus; - } - - public String getVnfType() { - return vnfType; - } - - public void setVnfType(String vnfType) { - this.vnfType = vnfType; - } - - public Integer getMaxVm() { - return maxVm; - } - - public void setMaxVm(Integer maxVm) { - this.maxVm = maxVm; - } - - public Integer getMaxCpu() { - return maxCpu; - } - - public void setMaxCpu(Integer maxCpu) { - this.maxCpu = maxCpu; - } - - public Integer getMaxDisk() { - return maxDisk; - } - - public void setMaxDisk(Integer maxDisk) { - this.maxDisk = maxDisk; - } - - public Integer getMaxRam() { - return maxRam; - } - - public void setMaxRam(Integer maxRam) { - this.maxRam = maxRam; - } - - public Integer getMaxShd() { - return maxShd; - } - - public void setMaxShd(Integer maxShd) { - this.maxShd = maxShd; - } - - public Integer getMaxNet() { - return maxNet; - } - - public void setMaxNet(Integer maxNet) { - this.maxNet = maxNet; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - /** - *
- * - * @param jsonObject - * @return - * @since NFVO 0.5 - */ - public static VnfEntity toEntity(JSONObject jsonObject) { - VnfEntity vnfEntity = new VnfEntity(); - vnfEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); - vnfEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); - vnfEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId")); - vnfEntity.setVnfInstanceName(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceName")); - vnfEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId")); - vnfEntity.setNsName(JsonUtil.getJsonFieldStr(jsonObject, "nsName")); - vnfEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfmId")); - vnfEntity.setVnfmName(JsonUtil.getJsonFieldStr(jsonObject, "vnfmName")); - vnfEntity.setVnfPackageName(JsonUtil.getJsonFieldStr(jsonObject, "vnfPackageName")); - vnfEntity.setVnfDescriptorName(JsonUtil.getJsonFieldStr(jsonObject, "vnfDescriptorName")); - vnfEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); - vnfEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); - vnfEntity.setVimTenant(JsonUtil.getJsonFieldStr(jsonObject, "vimTenant")); - vnfEntity.setJobId(JsonUtil.getJsonFieldStr(jsonObject, "jobId")); - vnfEntity.setVnfStatus(JsonUtil.getJsonFieldStr(jsonObject, "vnfStatus")); - vnfEntity.setVnfType(JsonUtil.getJsonFieldStr(jsonObject, "vnfType")); - vnfEntity.setMaxVm(JsonUtil.getJsonFieldInt(jsonObject, "maxVm")); - vnfEntity.setMaxCpu(JsonUtil.getJsonFieldInt(jsonObject, "maxCpu")); - vnfEntity.setMaxDisk(JsonUtil.getJsonFieldInt(jsonObject, "maxDisk")); - vnfEntity.setMaxRam(JsonUtil.getJsonFieldInt(jsonObject, "maxRam")); - vnfEntity.setMaxShd(JsonUtil.getJsonFieldInt(jsonObject, "maxShd")); - vnfEntity.setMaxNet(JsonUtil.getJsonFieldInt(jsonObject, "maxNet")); - return vnfEntity; - } - - @Override - public String toString() { - JSONObject vnfResJson = new JSONObject(); - vnfResJson.put("id", StringUtils.trimToEmpty(this.getId())); - vnfResJson.put("name", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vnfInstanceName", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("nsId", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("nsName", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vnfmId", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vnfmName", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vnfPackageName", StringUtils.trimToEmpty(this.getId())); - vnfResJson.put("vnfDescriptorName", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vimId", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vimName", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vimTenant", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("jobId", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vnfStatus", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("vnfType", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("maxVm", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("maxCpu", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("maxDisk", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("maxRam", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("maxShd", StringUtils.trimToEmpty(this.getName())); - vnfResJson.put("maxNet", StringUtils.trimToEmpty(this.getName())); - return vnfResJson.toString(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfInfoEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfInfoEntity.java deleted file mode 100644 index f993d9c..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfInfoEntity.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import java.io.Serializable; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * @author l00345485 - * @date 2016-10-28 - */ -public class VnfInfoEntity implements Serializable { - - /** */ - private String vnfInstanceId; - - /** */ - private String nsId; - - /** */ - private String vnfmId; - - private static final long serialVersionUID = 1L; - - public String getVnfInstanceId() { - return vnfInstanceId; - } - - public void setVnfInstanceId(String vnfInstanceId) { - this.vnfInstanceId = vnfInstanceId; - } - - public String getNsId() { - return nsId; - } - - public void setNsId(String nsId) { - this.nsId = nsId; - } - - public String getVnfmId() { - return vnfmId; - } - - public void setVnfmId(String vnfmId) { - this.vnfmId = vnfmId; - } - - public static VnfInfoEntity toEntity(JSONObject jsonObject) { - VnfInfoEntity vnfInfoEntity = new VnfInfoEntity(); - vnfInfoEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId")); - vnfInfoEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId")); - vnfInfoEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfmId")); - return vnfInfoEntity; - } - - @Override - public String toString() { - JSONObject vnfInfoResJson = new JSONObject(); - vnfInfoResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getVnfInstanceId())); - vnfInfoResJson.put("nsId", StringUtils.trimToEmpty(this.getNsId())); - vnfInfoResJson.put("vnfmId", StringUtils.trimToEmpty(this.getVnfmId())); - return vnfInfoResJson.toString(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfStatusEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfStatusEntity.java deleted file mode 100644 index 78ad1b8..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/entity/VnfStatusEntity.java +++ /dev/null @@ -1,213 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import java.io.Serializable; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import net.sf.json.JSONObject; - -/** - * @author l00345485 - * @date 2016-10-29 - */ -public class VnfStatusEntity implements Serializable { - - /** */ - private String vnfInstanceId; - - /** */ - private String jobId; - - /** */ - private String nsId; - - /** */ - private String vnfmId; - - /** */ - private String responseDescriptor; - - /** */ - private String status; - - /** */ - private String progress; - - /** */ - private String statusDescription; - - /** */ - private String errorCode; - - /** */ - private String responseId; - - /** */ - private String responseHistoryList; - - /** */ - private String addVm; - - /** */ - private String delVm; - - private static final long serialVersionUID = 1L; - - public String getVnfInstanceId() { - return vnfInstanceId; - } - - public void setVnfInstanceId(String vnfInstanceId) { - this.vnfInstanceId = vnfInstanceId; - } - - public String getJobId() { - return jobId; - } - - public void setJobId(String jobId) { - this.jobId = jobId; - } - - public String getNsId() { - return nsId; - } - - public void setNsId(String nsId) { - this.nsId = nsId; - } - - public String getVnfmId() { - return vnfmId; - } - - public void setVnfmId(String vnfmId) { - this.vnfmId = vnfmId; - } - - public String getResponseDescriptor() { - return responseDescriptor; - } - - public void setResponseDescriptor(String responseDescriptor) { - this.responseDescriptor = responseDescriptor; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getProgress() { - return progress; - } - - public void setProgress(String progress) { - this.progress = progress; - } - - public String getStatusDescription() { - return statusDescription; - } - - public void setStatusDescription(String statusDescription) { - this.statusDescription = statusDescription; - } - - public String getErrorCode() { - return errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getResponseId() { - return responseId; - } - - public void setResponseId(String responseId) { - this.responseId = responseId; - } - - public String getResponseHistoryList() { - return responseHistoryList; - } - - public void setResponseHistoryList(String responseHistoryList) { - this.responseHistoryList = responseHistoryList; - } - - public String getAddVm() { - return addVm; - } - - public void setAddVm(String addVm) { - this.addVm = addVm; - } - - public String getDelVm() { - return delVm; - } - - public void setDelVm(String delVm) { - this.delVm = delVm; - } - - public static VnfStatusEntity toEntity(JSONObject jsonObject) { - VnfStatusEntity vnfStatusEntity = new VnfStatusEntity(); - vnfStatusEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId")); - vnfStatusEntity.setJobId(JsonUtil.getJsonFieldStr(jsonObject, "jobId")); - vnfStatusEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId")); - vnfStatusEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfmId")); - vnfStatusEntity.setResponseDescriptor(JsonUtil.getJsonFieldStr(jsonObject, "responseDescriptor")); - vnfStatusEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status")); - vnfStatusEntity.setProgress(JsonUtil.getJsonFieldStr(jsonObject, "progress")); - vnfStatusEntity.setStatusDescription(JsonUtil.getJsonFieldStr(jsonObject, "statusDescription")); - vnfStatusEntity.setErrorCode(JsonUtil.getJsonFieldStr(jsonObject, "errorCode")); - vnfStatusEntity.setResponseId(JsonUtil.getJsonFieldStr(jsonObject, "responseId")); - vnfStatusEntity.setResponseHistoryList(JsonUtil.getJsonFieldStr(jsonObject, "responseHistoryList")); - vnfStatusEntity.setAddVm(JsonUtil.getJsonFieldStr(jsonObject, "addVm")); - vnfStatusEntity.setDelVm(JsonUtil.getJsonFieldStr(jsonObject, "delVm")); - return vnfStatusEntity; - } - - @Override - public String toString() { - JSONObject vnfStatusResJson = new JSONObject(); - vnfStatusResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getVnfInstanceId())); - vnfStatusResJson.put("jobId", StringUtils.trimToEmpty(this.getJobId())); - vnfStatusResJson.put("nsId", StringUtils.trimToEmpty(this.getNsId())); - vnfStatusResJson.put("vnfmId", StringUtils.trimToEmpty(this.getVnfmId())); - vnfStatusResJson.put("responseDescriptor", StringUtils.trimToEmpty(this.getResponseDescriptor())); - vnfStatusResJson.put("status", StringUtils.trimToEmpty(this.getStatus())); - vnfStatusResJson.put("progress", StringUtils.trimToEmpty(this.getProgress())); - vnfStatusResJson.put("statusDescription", StringUtils.trimToEmpty(this.getStatusDescription())); - vnfStatusResJson.put("errorCode", StringUtils.trimToEmpty(this.getErrorCode())); - vnfStatusResJson.put("responseId", StringUtils.trimToEmpty(this.getResponseId())); - vnfStatusResJson.put("responseHistoryList", StringUtils.trimToEmpty(this.getResponseHistoryList())); - vnfStatusResJson.put("addVm", StringUtils.trimToEmpty(this.getAddVm())); - vnfStatusResJson.put("delVm", StringUtils.trimToEmpty(this.getDelVm())); - return vnfStatusResJson.toString(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/GrantResServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/GrantResServiceImpl.java deleted file mode 100644 index 2eea6d0..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/GrantResServiceImpl.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Sites; -import org.onap.vfc.nfvo.res.service.group.inf.GrantResService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -public class GrantResServiceImpl implements GrantResService { - - private static final Logger LOGGER = LoggerFactory.getLogger(GrantResServiceImpl.class); - - private Sites sites; - - /** - *
- * - * @param object - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public JSONObject grantResource(JSONObject object) throws ServiceException { - LOGGER.info("function=grantResource; object: {}", object.toString()); - JSONObject additionalparam = object.getJSONObject("additionalParam"); - String vimId = additionalparam.getString("vimid"); - JSONObject vimJson = VimUtil.getVimById(vimId); - String tenant = vimJson.getString("tenant"); - JSONObject accessinfo = new JSONObject(); - accessinfo.put("tenant", tenant); - JSONObject vim = new JSONObject(); - vim.put("vimid", vimId); - vim.put("accessinfo", accessinfo); - LOGGER.info("function=grantResource; vim: {}", vim.toString()); - JSONObject result = new JSONObject(); - result.put("vim", vim); - return result; - } - - @Override - public JSONObject grantResourceReal(JSONObject object) throws ServiceException { - LOGGER.info("function=grantResource; object: {}", object.toString()); - String vimId = object.getString("vimId"); - JSONObject vimJson = VimUtil.getVimById(vimId); - JSONObject vim = parseVim(vimJson); - String resType = ""; - JSONArray resArr = new JSONArray(); - if(object.containsKey("addResource")) { - resType = "addResource"; - resArr = parseResource(object, resType); - } else if(object.containsKey("removeResource")) { - resType = "removeResource"; - resArr = parseResource(object, resType); - } - JSONObject resInfo = getResInfo(object, resType); - resInfo.put("vimId", vimId); - sites.update(resInfo); - - JSONObject result = new JSONObject(); - result.put("vim", vim); - result.put("zone", ""); - result.put("zoneGroup", ""); - result.put(resType, resArr); - result.put("tempResource", ""); - result.put("updateResource", ""); - result.put("vimAssets", new JSONObject()); - result.put("additionalParam", ""); - LOGGER.info("function=grantResource; result: {}", result.toString()); - return result; - } - - private JSONObject getResInfo(JSONObject object, String type) { - JSONArray arr = object.getJSONArray(type); - LOGGER.info("function=getResInfo; arr: {}, type: {}", arr, type); - JSONObject resourceObj = new JSONObject(); - if("addResource".equals(type)) { - resourceObj = getGrantResource(arr); - resourceObj.put("action", "online"); - } else if("removeResource".equals(type)) { - resourceObj = getGrantResource(arr); - resourceObj.put("action", "offline"); - } - LOGGER.info("function=getResInfo; resutl: {}", resourceObj.toString()); - return resourceObj; - } - - /** - *
- * - * @param addResource - * @return - * @since NFVO 0.5 - */ - private JSONObject getGrantResource(JSONArray resource) { - int cpuNum = 0; - int memNum = 0; - int diskNum = 0; - for(int i = 0; i < resource.size(); i++) { - JSONObject res = resource.getJSONObject(i); - JSONObject vCpu = res.getJSONObject("resourceTemplate").getJSONObject("virtualComputeDescriptor") - .getJSONObject("virtualCpu"); - int vCpuNum = vCpu.getInt("numVirtualCpu"); - JSONObject vMem = res.getJSONObject("resourceTemplate").getJSONObject("virtualComputeDescriptor") - .getJSONObject("virtualMemory"); - int vMemNum = vMem.getInt("virtualMemSize"); - JSONObject vDisk = res.getJSONObject("resourceTemplate").getJSONObject("virtualStorageDescriptor"); - int vDiskNum = vDisk.getInt("sizeOfStorage"); - cpuNum = cpuNum + vCpuNum; - memNum = memNum + vMemNum; - diskNum = diskNum + vDiskNum; - } - JSONObject obj = new JSONObject(); - obj.put("usedCPU", String.valueOf(cpuNum)); - obj.put("usedMemory", String.valueOf(memNum)); - obj.put("usedDisk", String.valueOf(diskNum)); - return obj; - } - - /** - *
- * - * @param object - * @return - * @since NFVO 0.5 - */ - private JSONArray parseResource(JSONObject object, String key) { - JSONArray newResources = new JSONArray(); - JSONArray oldResource = object.getJSONArray(key); - LOGGER.info("function=parseResource; Resource: {}", oldResource.toString()); - for(int i = 0; i < oldResource.size(); i++) { - JSONObject res = oldResource.getJSONObject(i); - JSONObject obj = new JSONObject(); - obj.put("reservationId", ""); - obj.put("resourceProviderId", ""); - obj.put("zoneId", ""); - obj.put("vimId", object.getString("vimId")); - obj.put("resourceDefinitionId", res.getString("resourceDefinitionId")); - newResources.add(obj); - } - LOGGER.info("function=parseResource; Parse Resource result: {}", newResources.toString()); - return newResources; - } - - /** - *
- * - * @param vimJson - * @return - * @since NFVO 0.5 - */ - private JSONObject parseVim(JSONObject vimJson) { - LOGGER.info("function=grantResource; vimJson: {}", vimJson.toString()); - JSONObject interfaceInfo = new JSONObject(); - interfaceInfo.put("vimType", vimJson.getString("type")); - interfaceInfo.put("apiVersion", "v2"); - interfaceInfo.put("protocolType", "http"); - JSONObject accessInfo = new JSONObject(); - accessInfo.put("tenant", vimJson.getString("tenant")); - accessInfo.put("username", vimJson.getString("userName")); - accessInfo.put("password", vimJson.getString("password")); - JSONObject vim = new JSONObject(); - vim.put("vimInfoId", vimJson.getString("vimId")); - vim.put("vimId", vimJson.getString("vimId")); - vim.put("interfaceInfo", interfaceInfo); - vim.put("accessInfo", accessInfo); - vim.put("interfaceEndpoint", vimJson.getString("url")); - return vim; - } - - /** - * @param sites The sites to set. - */ - public void setSites(Sites sites) { - this.sites = sites; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceAddServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceAddServiceImpl.java deleted file mode 100644 index 6c7bad9..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceAddServiceImpl.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.HashMap; -import java.util.Map; - -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.InterfaceResManagement; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.transaction.annotation.Transactional; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - * iResource add service implementation.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class IResourceAddServiceImpl { - - private static final Logger LOGGER = LoggerFactory.getLogger(IResourceAddServiceImpl.class); - - /** - * Add iResource.
- * - * @param restParametes - * @param iResMap - * @throws ServiceException - * @since NFVO 0.5 - */ - @Transactional(rollbackFor = ServiceException.class) - public void addIRes(RestfulParametes restParametes, Map iResMap) - throws ServiceException { - addIResources(iResMap, createResUrlMap(), restParametes); - } - - private void addIResources(Map iResMap, HashMap urlMap, - RestfulParametes restParametes) throws ServiceException { - for(String iResName : iResMap.keySet()) { - if(ParamConstant.PARAM_HOST.equals(iResName)) { - addHostResource(iResMap, restParametes, String.format(urlMap.get(iResName), - restParametes.get(ParamConstant.PARAM_VIMID), restParametes.get(ParamConstant.PARAM_TENANTID)), - iResName); - } else { - String url = String.format(urlMap.get(iResName), restParametes.get(ParamConstant.PARAM_VIMID), - restParametes.get(ParamConstant.PARAM_TENANTID)); - JSONArray iResArray = RestfulUtil.getResponseRes(new RestfulParametes(), url, iResName); - LOGGER.warn("function=addIResources; iResArray={}", iResArray); - for(Object object : iResArray) { - JSONObject iRes = JSONObject.fromObject(object); - int result = iResMap.get(iResName).add(iRes); - LOGGER.warn("function=addIResources; msg=iRes name is [{}],result is [{}]", iResName, result); - } - } - } - } - - /** - * Add Host Resource.
- * - * @param iResMap - * @param restParametes - * @param url - * @param iResName - * @throws ServiceException - * @since NFVO 0.5 - */ - public static void addHostResource(Map iResMap, RestfulParametes restParametes, - String url, String iResName) throws ServiceException { - JSONArray hostResArray = RestfulUtil.getResponseRes(new RestfulParametes(), url, iResName); - LOGGER.warn("function=addHostResource; hostResArray={}", hostResArray); - for(Object object : hostResArray) { - JSONObject hostRes = JSONObject.fromObject(object); - String hostZone = hostRes.getString("zone"); - if("internal".equals(hostZone)) { - continue; - } - String hostName = hostRes.getString("name"); - String hostUrl = String.format(UrlConstant.GET_HOSTDETAIL_URL, restParametes.get(ParamConstant.PARAM_VIMID), - restParametes.get(ParamConstant.PARAM_TENANTID), hostName); - - String result = RestfulUtil.getResponseContent(hostUrl, new RestfulParametes(), ParamConstant.PARAM_GET); - if(result == null) { - continue; - } - JSONObject hostObj = JSONObject.fromObject(result); - JSONObject host = hostDataParse(hostObj, hostName); - int res = iResMap.get(iResName).add(host); - LOGGER.warn("function=addHostResource; result={}, res={}", result, res); - if(res < 0) { - LOGGER.error("function=addHostResource; add into DB fail!"); - } - - } - } - - /** - *
- * - * @param hostObj - * @param hostName - * @return - * @since NFVO 0.5 - */ - public static JSONObject hostDataParse(JSONObject hostObj, String hostName) { - LOGGER.warn("function=hostDataParse; hostObj={}, hostName={}", hostObj, hostName); - JSONArray hostArray = hostObj.getJSONArray("host"); - for(Object object : hostArray) { - JSONObject hostObject = JSONObject.fromObject(object); - if(hostObject.getString("project").contains("total")) { - String vimId = JsonUtil.getJsonFieldStr(hostObj, "vimId"); - String hostId = vimId + hostName; - JSONObject host = new JSONObject(); - host.put("id", hostId); - host.put("name", hostName); - host.put("cpu", JsonUtil.getJsonFieldStr(hostObject, "cpu")); - host.put("memory", JsonUtil.getJsonFieldStr(hostObject, "memory_mb")); - host.put("disk", JsonUtil.getJsonFieldStr(hostObject, "disk_gb")); - host.put("vimId", JsonUtil.getJsonFieldStr(hostObj, "vimId")); - host.put("vimName", JsonUtil.getJsonFieldStr(hostObj, "vimName")); - return host; - } - } - return new JSONObject(); - } - - private HashMap createResUrlMap() { - HashMap urlMap = new HashMap(10); - urlMap.put(ParamConstant.PARAM_NETWORK, UrlConstant.GET_NETWORK_URL); - urlMap.put(ParamConstant.PARAM_HOST, UrlConstant.GET_HOST_URL); - urlMap.put(ParamConstant.PARAM_PORT, UrlConstant.GET_PORT_URL); - return urlMap; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceDelServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceDelServiceImpl.java deleted file mode 100644 index 8dbcaf0..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceDelServiceImpl.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.HashMap; -import java.util.Map; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.InterfaceResManagement; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Vim; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * - * iResource delete service implementation.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class IResourceDelServiceImpl { - - private static final Logger LOGGER = LoggerFactory.getLogger(IResourceDelServiceImpl.class); - - /** - * - * Delete iResource.
- * - * @param vimId - * @param iResMap - * @param vim - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - public int deleteIRes(String vimId, Map iResMap, Vim vim) throws ServiceException { - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_VIMID, vimId); - - checkIResDelResult(vimId, iResMap); - return vim.delete(vimId); - } - - private void checkIResDelResult(String vimId, Map iResMap) throws ServiceException { - for(String keyName : iResMap.keySet()) { - if(iResMap.get(keyName).deleteResByVimId(vimId) < 0) { - LOGGER.error("function=checkIResDelResult; msg=delete {} failed,", keyName); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.delete.fail") - + keyName); - } - LOGGER.warn("function=checkIResDelResult; msg=delete {} success", keyName); - } - - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceUpdateServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceUpdateServiceImpl.java deleted file mode 100644 index f26fedf..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/IResourceUpdateServiceImpl.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.HashMap; -import java.util.Map; - -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.InterfaceResManagement; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.transaction.annotation.Transactional; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - * iResource update service implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class IResourceUpdateServiceImpl { - - private static final Logger LOGGER = LoggerFactory.getLogger(IResourceUpdateServiceImpl.class); - - /** - * Update iResource.
- * - * @param vimId - * @param restParametes - * @param iResMap - * @param sites - * @throws ServiceException - * @since NFVO 0.5 - */ - @Transactional(rollbackFor = ServiceException.class) - public void updateIRes(String vimId, RestfulParametes restParametes, Map iResMap) - throws ServiceException { - - updateIResByName(iResMap, createResUrlMap(), restParametes, vimId); - } - - private void updateIResByName(Map iResMap, HashMap updateUrlMap, - RestfulParametes restParametes, String vimId) throws ServiceException { - for(String resName : updateUrlMap.keySet()) { - if(ParamConstant.PARAM_HOST.equals(resName)) { - updateHostResource(iResMap, restParametes, String.format(updateUrlMap.get(resName), - restParametes.get(ParamConstant.PARAM_VIMID), restParametes.get(ParamConstant.PARAM_TENANTID)), - resName); - } else if(iResMap.get(resName).deleteResByVimId(vimId) >= 0) { - String url = String.format(updateUrlMap.get(resName), restParametes.get(ParamConstant.PARAM_VIMID), - restParametes.get(ParamConstant.PARAM_TENANTID)); - JSONArray iResArray = RestfulUtil.getResponseRes(new RestfulParametes(), url, resName); - LOGGER.warn("function=addIResources; iResArray={}", iResArray); - for(Object object : iResArray) { - JSONObject iRes = JSONObject.fromObject(object); - int result = iResMap.get(resName).add(iRes); - LOGGER.warn("function=updateIResByName; msg=iRes name is [{}],result is [{}]", resName, result); - - } - } - } - } - - private void updateHostResource(Map iResMap, RestfulParametes restParametes, - String url, String iResName) throws ServiceException { - - JSONArray hostResArray = RestfulUtil.getResponseRes(new RestfulParametes(), url, iResName); - LOGGER.warn("function=updateHostResource; hostResArray={}", hostResArray); - for(Object object : hostResArray) { - JSONObject hostRes = JSONObject.fromObject(object); - String hostZone = hostRes.getString("zone"); - if("internal".equals(hostZone)) { - continue; - } - String hostName = hostRes.getString("name"); - String hostUrl = String.format(UrlConstant.GET_HOSTDETAIL_URL, restParametes.get(ParamConstant.PARAM_VIMID), - restParametes.get(ParamConstant.PARAM_TENANTID), hostName); - - String result = RestfulUtil.getResponseContent(hostUrl, new RestfulParametes(), ParamConstant.PARAM_GET); - JSONObject hostObj = JSONObject.fromObject(result); - JSONObject host = IResourceAddServiceImpl.hostDataParse(hostObj, hostName); - int res = iResMap.get(ParamConstant.PARAM_HOST).update(host); - LOGGER.warn("function=updateHostResource; result={}, res={}", result, res); - if(res < 0) { - LOGGER.error("function=updateHostResource; add into DB fail!"); - } - - } - } - - private HashMap createResUrlMap() { - HashMap updateUrlMap = new HashMap(10); - updateUrlMap.put(ParamConstant.PARAM_NETWORK, UrlConstant.GET_NETWORK_URL); - updateUrlMap.put(ParamConstant.PARAM_HOST, UrlConstant.GET_HOST_URL); - updateUrlMap.put(ParamConstant.PARAM_PORT, UrlConstant.GET_PORT_URL); - return updateUrlMap; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/ResOperateServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/ResOperateServiceImpl.java deleted file mode 100644 index 66686e7..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/ResOperateServiceImpl.java +++ /dev/null @@ -1,257 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.Constant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.onap.vfc.nfvo.res.common.util.StringUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Host; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.InterfaceResManagement; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Network; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Port; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Sites; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Vim; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.onap.vfc.nfvo.res.service.group.inf.ResOperateService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.transaction.annotation.Transactional; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - * Resource operation service implementation class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public class ResOperateServiceImpl implements ResOperateService { - - private static final Logger LOGGER = LoggerFactory.getLogger(ResOperateServiceImpl.class); - - private Sites sites; - - private Network network; - - private Host host; - - private Port port; - - private Vim vim; - - private IResourceAddServiceImpl iResourceAddServiceImpl; - - private IResourceUpdateServiceImpl iResourceUpdateServiceImpl; - - private IResourceDelServiceImpl iResourceDelServiceImpl; - - @Override - @Transactional(rollbackFor = ServiceException.class) - public void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException { - LOGGER.warn("function=addIRes; msg=add IResource by vimId:[{}], tenantId:[{}]", vimId, tenantId); - if(!StringUtil.isValidString(vimId) || !StringUtil.isValidString(tenantId)) { - LOGGER.warn("function=addIRes; msg=vimId[{}] is valid", vimId); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.vimId")); - } - - RestfulParametes restParametes = createRestfulParametes(tenantId, vimId, header); - HashMap iResMap = createMap(); - - if(vim.add(vimId) <= 0) { - LOGGER.error("VimId exists"); - throw new ServiceException("VimId exists"); - } - - iResourceAddServiceImpl.addIRes(restParametes, iResMap); - } - - @Override - @Transactional(rollbackFor = ServiceException.class) - public void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException { - if(!StringUtil.isValidString(vimId)) { - LOGGER.error("function=updateIRes; msg=vimId is not exist"); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.update.res.no.vimId")); - } - - RestfulParametes restParametes = createRestfulParametes(tenantId, vimId, header); - HashMap iResMap = createMap(); - iResourceUpdateServiceImpl.updateIRes(vimId, restParametes, iResMap); - } - - @Override - public void updateAllIRes() throws ServiceException { - LOGGER.warn("function=updateAllIRes; msg=update all IResource"); - List vims = vim.getList(); - if(vims.isEmpty()) { - LOGGER.error("function=updateAllIRes; msg=vimId is not exist"); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.update.res.no.vimId")); - } - for(VimEntity vimEntity : vims) { - String vimId = vimEntity.getId(); - LOGGER.warn("function=updateAllIRes; msg=start update vimId:{}", vimId); - updateIRes(null, vimId, new JSONObject()); - } - } - - @Override - @Transactional(rollbackFor = ServiceException.class) - public int deleteIRes(String vimId) throws ServiceException { - LOGGER.warn("function=deleteAllRes; msg=deleteResPool vimId: {}", vimId); - if(StringUtils.isEmpty(vimId)) { - LOGGER.error("function=deleteAllRes; msg=vimId is null"); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.res.no.vimId")); - } - - return iResourceDelServiceImpl.deleteIRes(vimId, createMap(), vim); - } - - private RestfulParametes createRestfulParametes(String tenantId, String vimId, JSONObject header) { - RestfulParametes restParametes = new RestfulParametes(); - restParametes.put("vimId", vimId); - restParametes.put("tenantId", tenantId); - restParametes.putHttpContextHeader("Content-Type", "application/json"); - JSONObject headers = JsonUtil.getJsonFieldJson(header, "header"); - if(null == headers || !headers.has("x-auth-token")) { - String token = "TestToken"; - LOGGER.warn("function=createRestfulParametes; msg=create token."); - restParametes.putHttpContextHeader(Constant.IAM_AUTH_TOKEN, token); - return restParametes; - } - restParametes.putHttpContextHeader(Constant.IAM_AUTH_TOKEN, - JsonUtil.getJsonFieldStr(headers, Constant.IAM_AUTH_TOKEN)); - return restParametes; - } - - private HashMap createMap() { - HashMap iResMap = new HashMap(10); - iResMap.put(ParamConstant.PARAM_NETWORK, network); - iResMap.put(ParamConstant.PARAM_HOST, host); - iResMap.put(ParamConstant.PARAM_PORT, port); - return iResMap; - } - - public void setSites(Sites sites) { - this.sites = sites; - } - - public void setNetwork(Network network) { - this.network = network; - } - - public void setHost(Host host) { - this.host = host; - } - - public void setPort(Port port) { - this.port = port; - } - - public void setVim(Vim vim) { - this.vim = vim; - } - - /** - * Set iResource Add service implemtation.
- * - * @param iResourceAddServiceImpl - * @since NFVO 0.5 - */ - public void setiResourceAddServiceImpl(IResourceAddServiceImpl iResourceAddServiceImpl) { - this.iResourceAddServiceImpl = iResourceAddServiceImpl; - } - - /** - * Set iResource update service implementation.
- * - * @param iResourceUpdateServiceImpl - * @since NFVO 0.5 - */ - public void setiResourceUpdateServiceImpl(IResourceUpdateServiceImpl iResourceUpdateServiceImpl) { - this.iResourceUpdateServiceImpl = iResourceUpdateServiceImpl; - } - - /** - * Set iresource delete service implementation.
- * - * @param iResourceDelServiceImpl - * @since NFVO 0.5 - */ - public void setiResourceDelServiceImpl(IResourceDelServiceImpl iResourceDelServiceImpl) { - this.iResourceDelServiceImpl = iResourceDelServiceImpl; - } - - /** - *
- * - * @param string - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { - LOGGER.info("Enter sendMsgMonitor!"); - Map map = new HashMap<>(10); - map.put("vimId", vimId); - List hosts = host.getList(map); - for(HostEntity entity : hosts) { - JSONObject msgObj = new JSONObject(); - msgObj.put("operationType", operateType); - msgObj.put("resourceType", "HOST"); - msgObj.put("label", entity.getName()); - if("delete".equals(operateType)) { - JSONArray deleteIds = new JSONArray(); - deleteIds.add(entity.getId()); - msgObj.put("deleteIds", deleteIds); - } else { - JSONArray data = new JSONArray(); - JSONObject obj = JSONObject.fromObject(entity); - obj.put("oid", entity.getId()); - obj.put("moc", "nfv.host.linux"); - data.add(obj); - msgObj.put("data", data); - } - RestfulParametes restfulParametes = new RestfulParametes(); - Map headerMap = new HashMap<>(3); - headerMap.put("Content-Type", "application/json"); - restfulParametes.setHeaderMap(headerMap); - restfulParametes.setRawData(msgObj.toString()); - LOGGER.info("sendMsgMonitor msgObj: {}", msgObj); - String result = RestfulUtil.getResponseContent(UrlConstant.SEND_MSG_MONITOR, restfulParametes, - ParamConstant.PARAM_POST); - LOGGER.warn(result); - } - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VirtualLinkServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VirtualLinkServiceImpl.java deleted file mode 100644 index 287f636..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VirtualLinkServiceImpl.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.service.dao.inf.VirtualLinkDao; -import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VirtualLinkService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 27, 2016 - */ -public class VirtualLinkServiceImpl implements VirtualLinkService { - - private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkServiceImpl.class); - - private VirtualLinkDao virtualLinkDao; - - /** - *
- * - * @param virtualLinkEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException { - if(!checkId(virtualLinkEntity.getId())) { - LOGGER.error("function=addVl; msg=add error, because id is already exist."); - throw new ServiceException(ResourceUtil - .getMessage("org.onap.vfc.nfvo.res.service.group.impl.VirtualLinkServiceImpl.add.id.check")); - } - if(StringUtils.isEmpty(virtualLinkEntity.getId())) { - virtualLinkEntity.setId(UUID.randomUUID().toString()); - } - int result = virtualLinkDao.addVl(virtualLinkEntity); - JSONObject restJson = new JSONObject(); - if(result > 0) { - restJson.put("id", virtualLinkEntity.getId()); - restJson.put("name", virtualLinkEntity.getName()); - } else { - LOGGER.error("function=addVl; msg=add vl into DB error."); - restJson.put("message", "Add Vl into DB error."); - } - return restJson; - - } - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - private boolean checkId(String id) { - VirtualLinkEntity vl = virtualLinkDao.getVl(id); - if(null == vl) { - return true; - } - return false; - } - - /** - *
- * - * @param map - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public List getList(Map map) throws ServiceException { - return virtualLinkDao.getVls(map); - } - - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public int delete(String id) throws ServiceException { - return virtualLinkDao.deleteVlById(id); - } - - public void setVirtualLinkDao(VirtualLinkDao virtualLinkDao) { - this.virtualLinkDao = virtualLinkDao; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VmServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VmServiceImpl.java deleted file mode 100644 index fef97b2..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VmServiceImpl.java +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.onap.vfc.nfvo.res.service.dao.inf.VmDao; -import org.onap.vfc.nfvo.res.service.entity.VmEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VmService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -public class VmServiceImpl implements VmService { - - private static final Logger LOGGER = LoggerFactory.getLogger(VmServiceImpl.class); - - private VmDao vmDao; - - /** - *
- * - * @param vmEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public JSONObject addVm(VmEntity vmEntity) throws ServiceException { - int result; - if(!checkId(vmEntity.getVmId())) { - result = vmDao.updateVm(vmEntity); - sendMsgMonitor("create", vmEntity); - } else { - if(StringUtils.isEmpty(vmEntity.getVmId())) { - vmEntity.setVmId(UUID.randomUUID().toString()); - } - result = vmDao.addVm(vmEntity); - sendMsgMonitor("update", vmEntity); - } - JSONObject restJson = new JSONObject(); - if(result > 0) { - restJson.put("id", vmEntity.getVmId()); - restJson.put("name", vmEntity.getVmName()); - } else { - LOGGER.error("function=addVm; msg=add vm into DB error."); - restJson.put("message", "Add vm into DB error."); - } - return restJson; - } - - /** - *
- * - * @param vmId - * @return - * @since NFVO 0.5 - */ - private boolean checkId(String vmId) { - VmEntity vm = vmDao.getVm(vmId); - if(null == vm) { - return true; - } - return false; - } - - public void sendMsgMonitor(String operateType, VmEntity vmEntity) throws ServiceException { - JSONObject msgObj = new JSONObject(); - msgObj.put("operationType", operateType); - msgObj.put("resourceType", "VDU"); - msgObj.put("label", vmEntity.getVmName()); - if("delete".equals(operateType)) { - JSONArray deleteIds = new JSONArray(); - deleteIds.add(vmEntity.getVmId()); - msgObj.put("deleteIds", deleteIds); - } else { - JSONArray data = new JSONArray(); - JSONObject obj = JSONObject.fromObject(vmEntity); - obj.put("oid", vmEntity.getVmId()); - obj.put("moc", "nfv.vdu.linux"); - data.add(obj); - msgObj.put("data", data); - } - LOGGER.info("sendMsgMonitor msgObj: {}", msgObj); - RestfulParametes restfulParametes = new RestfulParametes(); - Map headerMap = new HashMap<>(3); - headerMap.put("Content-Type", "application/json"); - restfulParametes.setHeaderMap(headerMap); - restfulParametes.setRawData(msgObj.toString()); - String result = RestfulUtil.getResponseContent(UrlConstant.SEND_MSG_MONITOR, restfulParametes, - ParamConstant.PARAM_POST); - LOGGER.warn(result); - - } - - /** - *
- * - * @param map - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public List getList(Map map) throws ServiceException { - return vmDao.getVms(map); - } - - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public int delete(String id) throws ServiceException { - return vmDao.deleteVmById(id); - } - - public void setVmDao(VmDao vmDao) { - this.vmDao = vmDao; - } - - /** - *
- * - * @param vnfInstanceId - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public int deleteByVnfId(String vnfInstanceId) throws ServiceException { - Map map = new HashMap<>(10); - map.put("vnfInstanceId", vnfInstanceId); - List vms = vmDao.getVms(map); - for(int i = 0; i < vms.size(); i++) { - VmEntity vm = vms.get(i); - sendMsgMonitor("delete", vm); - } - return vmDao.deleteVmByVnfId(vnfInstanceId); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfInfoServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfInfoServiceImpl.java deleted file mode 100644 index 7b0e1b8..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfInfoServiceImpl.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.inf.VnfInfoDao; -import org.onap.vfc.nfvo.res.service.entity.VmEntity; -import org.onap.vfc.nfvo.res.service.entity.VnfInfoEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VmService; -import org.onap.vfc.nfvo.res.service.group.inf.VnfInfoService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public class VnfInfoServiceImpl implements VnfInfoService { - - private static final Logger LOGGER = LoggerFactory.getLogger(VnfInfoServiceImpl.class); - - private VnfInfoDao vnfInfoDao; - - private VmService vmService; - - /** - *
- * - * @param object - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public JSONObject addVnfInfo(JSONObject object) throws ServiceException { - LOGGER.info("function=addVnfInfo; object: {}", object); - saveVm(object); - JSONObject vnf = new JSONObject(); - vnf.put("vnfInstanceId", object.get("vnfInstanceId")); - vnf.put("nsId", object.get("nsId")); - vnf.put("vnfmId", object.get("vnfmId")); - VnfInfoEntity vnfInfoEntity = VnfInfoEntity.toEntity(vnf); - int result; - if(!checkId(vnfInfoEntity.getVnfInstanceId())) { - result = vnfInfoDao.updateVnfInfo(vnfInfoEntity); - } else { - result = vnfInfoDao.addVnfInfo(vnfInfoEntity); - } - JSONObject resultObj = new JSONObject(); - if(result > 0) { - resultObj.put("vnfInstanceId", object.get("vnfInstanceId")); - } else { - LOGGER.error("function=addVnfInfo; msg=add vnfInfo into DB error."); - resultObj.put("message", "Add vnfInfo into DB error."); - } - return resultObj; - } - - /** - *
- * - * @param vnfInstanceId - * @return - * @since NFVO 0.5 - */ - private boolean checkId(String vnfInstanceId) { - VnfInfoEntity vnf = vnfInfoDao.getVnfInfo(vnfInstanceId); - if(null == vnf) { - return true; - } - return false; - } - - /** - *
- * - * @param object - * @throws ServiceException - * @since NFVO 0.5 - */ - private void saveVm(JSONObject object) throws ServiceException { - String vnfInstanceId = object.getString("vnfInstanceId"); - JSONArray vms = object.getJSONArray("vms"); - for(int i = 0; i < vms.size(); i++) { - JSONObject vmObj = vms.getJSONObject(i); - vmObj.put("vnfInstanceId", vnfInstanceId); - vmService.addVm(VmEntity.toEntity(vmObj)); - } - - } - - /** - *
- * - * @param map - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public List getList(Map map) throws ServiceException { - return vnfInfoDao.getVnfInfos(map); - } - - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public int delete(String id) throws ServiceException { - vmService.deleteByVnfId(id); - return vnfInfoDao.deleteVnfInfoById(id); - } - - public void setVnfInfoDao(VnfInfoDao vnfInfoDao) { - this.vnfInfoDao = vnfInfoDao; - } - - public void setVmService(VmService vmService) { - this.vmService = vmService; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfServiceImpl.java deleted file mode 100644 index 552d252..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfServiceImpl.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import org.apache.commons.lang3.StringUtils; -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.service.dao.inf.VnfDao; -import org.onap.vfc.nfvo.res.service.entity.VnfEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VnfInfoService; -import org.onap.vfc.nfvo.res.service.group.inf.VnfService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public class VnfServiceImpl implements VnfService { - - private static final Logger LOGGER = LoggerFactory.getLogger(VnfServiceImpl.class); - - private VnfDao vnfDao; - - private VnfInfoService vnfInfoService; - - /** - *
- * - * @param vnfEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException { - if(!checkId(vnfEntity.getId())) { - LOGGER.error("function=addVnf; msg=add error, because id is already exist."); - throw new ServiceException(ResourceUtil - .getMessage("org.onap.vfc.nfvo.res.service.group.impl.VnfServiceImpl.add.id.check")); - } - if(StringUtils.isEmpty(vnfEntity.getId())) { - vnfEntity.setId(UUID.randomUUID().toString()); - } - int result = vnfDao.addVnf(vnfEntity); - JSONObject restJson = new JSONObject(); - if(result > 0) { - restJson.put("id", vnfEntity.getId()); - restJson.put("name", vnfEntity.getName()); - } else { - LOGGER.error("function=addVnf; msg=add vnf into DB error."); - restJson.put("message", "Add vnf into DB error."); - } - return restJson; - } - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - private boolean checkId(String id) { - VnfEntity vnf = vnfDao.getVnf(id); - if(null == vnf) { - return true; - } - return false; - } - - /** - *
- * - * @param map - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public List getList(Map map) throws ServiceException { - return vnfDao.getVnfs(map); - } - - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public int delete(String id) throws ServiceException { - deleteVnfInfo(id); - return vnfDao.deleteVnfById(id); - } - - /** - *
- * - * @param id - * @throws ServiceException - * @since NFVO 0.5 - */ - private void deleteVnfInfo(String vnfInstanceId) throws ServiceException { - vnfInfoService.delete(vnfInstanceId); - } - - public void setVnfDao(VnfDao vnfDao) { - this.vnfDao = vnfDao; - } - - public void setVnfInfoService(VnfInfoService vnfInfoService) { - this.vnfInfoService = vnfInfoService; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfStatusServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfStatusServiceImpl.java deleted file mode 100644 index a846d59..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/impl/VnfStatusServiceImpl.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.impl; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.dao.inf.VnfStatusDao; -import org.onap.vfc.nfvo.res.service.entity.VnfStatusEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VnfStatusService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -public class VnfStatusServiceImpl implements VnfStatusService { - - private static final Logger LOGGER = LoggerFactory.getLogger(VnfStatusServiceImpl.class); - - private VnfStatusDao vnfStatusDao; - - /** - *
- * - * @param object - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public JSONObject addVnfStatus(JSONObject object) throws ServiceException { - LOGGER.info("function=addVnfStatus; object: {}", object); - VnfStatusEntity vnfStatusEntity = VnfStatusEntity.toEntity(object); - int result; - if(!checkId(vnfStatusEntity.getVnfInstanceId())) { - result = vnfStatusDao.updateVnfStatus(vnfStatusEntity); - } else { - result = vnfStatusDao.addVnfStatus(vnfStatusEntity); - } - JSONObject resultObj = new JSONObject(); - if(result > 0) { - resultObj.put("vnfInstanceId", object.get("vnfInstanceId")); - } else { - LOGGER.error("function=addVnfStatus; msg=add vnfStatus into DB error."); - resultObj.put("message", "Add vnfStatus into DB error."); - } - return resultObj; - } - - /** - *
- * - * @param vnfInstanceId - * @return - * @since NFVO 0.5 - */ - private boolean checkId(String vnfInstanceId) { - VnfStatusEntity vnfStatus = vnfStatusDao.getVnfStatus(vnfInstanceId); - if(null == vnfStatus) { - return true; - } - return false; - } - - /** - *
- * - * @param map - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public List getList(Map map) throws ServiceException { - return vnfStatusDao.getVnfStatuss(map); - } - - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @Override - public int delete(String id) throws ServiceException { - return vnfStatusDao.deleteVnfStatusById(id); - } - - public void setVnfStatusDao(VnfStatusDao vnfStatusDao) { - this.vnfStatusDao = vnfStatusDao; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/GrantResService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/GrantResService.java deleted file mode 100644 index 502cba9..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/GrantResService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.inf; - -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -public interface GrantResService { - - /** - *
- * - * @param object - * @return - * @since NFVO 0.5 - */ - JSONObject grantResource(JSONObject object) throws ServiceException; - - JSONObject grantResourceReal(JSONObject object) throws ServiceException; - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/ResOperateService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/ResOperateService.java deleted file mode 100644 index ebd1b7b..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/ResOperateService.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.inf; - -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - * resource operational service class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface ResOperateService { - - /** - * Update iresource.
- * - * @param tenantId - * @param vimId - * @param header - * @throws ServiceException - * @since NFVO 0.5 - */ - void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException; - - /** - * Update all iResource.
- * - * @throws ServiceException - * @since NFVO 0.5 - */ - void updateAllIRes() throws ServiceException; - - /** - * Add iResource.
- * - * @param tenantId - * @param vimId - * @param header - * @throws ServiceException - * @since NFVO 0.5 - */ - void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException; - - /** - * Delete iResource.
- * - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int deleteIRes(String vimId) throws ServiceException; - - /** - *
- * - * @param operateType - * @param vimId - * @throws ServiceException - * @since NFVO 0.5 - */ - void sendMsgMonitor(String operateType, String vimId) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VirtualLinkService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VirtualLinkService.java deleted file mode 100644 index aaca1b9..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VirtualLinkService.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 27, 2016 - */ -public interface VirtualLinkService { - - /** - *
- * - * @param virtualLinkEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException; - - /** - *
- * - * @param map - * @return - * @since NFVO 0.5 - */ - List getList(Map map) throws ServiceException; - - /** - *
- * - * @param id - * @return - * @since NFVO 0.5 - */ - int delete(String id) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VmService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VmService.java deleted file mode 100644 index 98d9565..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VmService.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VmEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -public interface VmService { - - JSONObject addVm(VmEntity vmEntity) throws ServiceException; - - List getList(Map map) throws ServiceException; - - int delete(String id) throws ServiceException; - - int deleteByVnfId(String vnfInstanceId) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfInfoService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfInfoService.java deleted file mode 100644 index 891a8ac..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfInfoService.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfInfoEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public interface VnfInfoService { - - JSONObject addVnfInfo(JSONObject object) throws ServiceException; - - List getList(Map map) throws ServiceException; - - int delete(String id) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfService.java deleted file mode 100644 index ab4c46d..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfService.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -public interface VnfService { - - /** - *
- * - * @param vnfEntity - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException; - - /** - *
- * - * @param map - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - List getList(Map map) throws ServiceException; - - /** - *
- * - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - int delete(String id) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfStatusService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfStatusService.java deleted file mode 100644 index 029dd1a..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/group/inf/VnfStatusService.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.group.inf; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfStatusEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -public interface VnfStatusService { - - JSONObject addVnfStatus(JSONObject object) throws ServiceException; - - List getList(Map map) throws ServiceException; - - int delete(String id) throws ServiceException; -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/HostMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/HostMapper.java deleted file mode 100644 index ab3fdc9..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/HostMapper.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.HostEntity; - -/** - * Host info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface HostMapper { - - /** - * It is used to get Host info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - HostEntity getHost(String id); - - /** - * It is used to get Hosts info.
- * - * @param condition - * @return The get result - * @since NFVO 0.5 - */ - List getHosts(Map condition); - - /** - * It is used to delete Hosts info.
- * - * @param id - * @return The delete result - * @since NFVO 0.5 - */ - int deleteHost(String id); - - /** - * It is used to delete Hosts info.
- * - * @param vimId - * @return The delete result - * @since NFVO 0.5 - */ - int deleteHostByVimId(String vimId); - - /** - * It is used to add Hosts info.
- * - * @param hostEntity - * @return The add result - * @since NFVO 0.5 - */ - int addHost(HostEntity hostEntity); - - /** - * It is used to add Hosts info.
- * - * @param hostEntity - * @return The add result - * @since NFVO 0.5 - */ - int addHostSelective(HostEntity hostEntity); - - /** - * It is used to update Hosts info.
- * - * @param hostEntity - * @return The update result - * @since NFVO 0.5 - */ - int updateHostSelective(HostEntity hostEntity); - - /** - * It is used to update Hosts info.
- * - * @param hostEntity - * @return The update result - * @since NFVO 0.5 - */ - int updateHost(HostEntity hostEntity); - - /** - * It is used to update Hosts info.
- * - * @param hostEntity - * @return The update result - * @since NFVO 0.5 - */ - int updateHostByVimId(HostEntity hostEntity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/LocationMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/LocationMapper.java deleted file mode 100644 index b06fd55..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/LocationMapper.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; - -/** - * - * Location Mapper Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface LocationMapper { - - /** - * - * Get location.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - LocationEntity getLocation(String id); - - /** - * - * Get Country.
- * - * @return - * @since NFVO 0.5 - */ - List getCountry(); - - /** - * - * Get location by country.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getLocationByCountry(Map condition); - - /** - * - * get locations.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getLocations(Map condition); - - /** - * - * Delete location.
- * - * @param location - * @return - * @since NFVO 0.5 - */ - int deleteLocation(String location); - - /** - * - * Add location.
- * - * @param locationEntity - * @return - * @since NFVO 0.5 - */ - int addLocation(LocationEntity locationEntity); - - /** - * - * Add selective location.
- * - * @param locationEntity - * @return - * @since NFVO 0.5 - */ - int addLocationSelective(LocationEntity locationEntity); - - /** - * - * Update selective location.
- * - * @param locationEntity - * @return - * @since NFVO 0.5 - */ - int updateLocationSelective(LocationEntity locationEntity); - - /** - * - * Update location.
- * - * @param locationEntity - * @return - * @since NFVO 0.5 - */ - int updateLocation(LocationEntity locationEntity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/NetworkMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/NetworkMapper.java deleted file mode 100644 index 6b71ca0..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/NetworkMapper.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; - -/** - * - * Network Mapper Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -public interface NetworkMapper { - - /** - * - * Get network details.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - NetworkEntity getNetwork(String id); - - /** - * - * Get details of networks.
- * - * @param condition - * @return - * @since NFVO 0.5 - */ - List getNetworks(Map condition); - - /** - * - * Delete network.
- * - * @param id - * @return - * @since NFVO 0.5 - */ - int deleteNetwork(String id); - - /** - * - * Delete network by VIM ID.
- * - * @param vimId - * @return - * @since NFVO 0.5 - */ - int deleteNetworkByVimId(String vimId); - - /** - * - * Add network.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int addNetwork(NetworkEntity networkEntity); - - /** - * - * Add selective network.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int addNetworkSelective(NetworkEntity networkEntity); - - /** - * - * Update selective network.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int updateNetworkSelective(NetworkEntity networkEntity); - - /** - * - * Update network.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int updateNetwork(NetworkEntity networkEntity); - - /** - * - * Update network by VIM Id.
- * - * @param networkEntity - * @return - * @since NFVO 0.5 - */ - int updateNetworkByVimId(NetworkEntity networkEntity); - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/PortMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/PortMapper.java deleted file mode 100644 index d14b476..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/PortMapper.java +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.PortEntity; - -/** - * Port info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface PortMapper { - - /** - * It is used to get Port info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - PortEntity getPort(String id); - - /** - * It is used to get Ports info.
- * - * @param condition - * @return The get result - * @since NFVO 0.5 - */ - List getPorts(Map condition); - - /** - * It is used to delete Ports info.
- * - * @param id - * @return The delete result - * @since NFVO 0.5 - */ - int deletePort(String id); - - /** - * It is used to delete Ports info.
- * - * @param vimId - * @return The delete result - * @since NFVO 0.5 - */ - int deletePortByVimId(String vimId); - - /** - * It is used to add Ports info.
- * - * @param portEntity - * @return The add result - * @since NFVO 0.5 - */ - int addPort(PortEntity portEntity); - - /** - * It is used to add Ports info.
- * - * @param portEntity - * @return The add result - * @since NFVO 0.5 - */ - int addPortSelective(PortEntity portEntity); - - /** - * It is used to update Ports info.
- * - * @param portEntity - * @return The update result - * @since NFVO 0.5 - */ - int updatePortSelective(PortEntity portEntity); - - /** - * It is used to update Ports info.
- * - * @param portEntity - * @return The update result - * @since NFVO 0.5 - */ - int updatePort(PortEntity portEntity); - - /** - * It is used to update Ports info.
- * - * @param portEntity - * @return The update result - * @since NFVO 0.5 - */ - int updatePortByVimId(PortEntity portEntity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/SitesMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/SitesMapper.java deleted file mode 100644 index 28407c3..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/SitesMapper.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; - -/** - * ResPool info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface SitesMapper { - - /** - * It is used to get Sites info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - SitesEntity getSite(String id); - - /** - * - * It is used to get Sites info.
- * - * @param map - * @return - * @since NFVO 0.5 - */ - List getSites(Map map); - - /** - * It is used to get Sites info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - int deleteSite(String id); - - /** - * - * It is used to delete Site info.
- * - * @param entity - * @return - * @since NFVO 0.5 - */ - int addSite(SitesEntity entity); - - /** - * - * It is used to add Sites info.
- * - * @param entity - * @return - * @since NFVO 0.5 - */ - int addSiteSelective(SitesEntity entity); - - /** - * - * It is used to add Site info.
- * - * @param entity - * @return - * @since NFVO 0.5 - */ - int updateSiteSelective(SitesEntity entity); - - /** - * - * It is used to update Sites info.
- * - * @param entity - * @return - * @since NFVO 0.5 - */ - int updateSite(SitesEntity entity); - - /** - * - * It is used to update Site info.
- * - * @param entity - * @return - * @since NFVO 0.5 - */ - int updateSiteByVimId(SitesEntity entity); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VimMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VimMapper.java deleted file mode 100644 index 6963637..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VimMapper.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; - -import org.onap.vfc.nfvo.res.service.entity.VimEntity; - -/** - * Vim info interface.
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -public interface VimMapper { - - /** - * It is used to get Vim info.
- * - * @param id - * @return The get result - * @since NFVO 0.5 - */ - VimEntity getVim(String id); - - /** - * It is used to get Vims info.
- * - * @return The get result - * @since NFVO 0.5 - */ - List getVims(); - - /** - * It is used to delete Vim info.
- * - * @param id - * @return The delete result - * @since NFVO 0.5 - */ - int deleteVim(String id); - - /** - * It is used to add Vim info.
- * - * @param vimEntity - * @return The add result - * @since NFVO 0.5 - */ - int addVim(VimEntity vimEntity); - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VirtualLinkMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VirtualLinkMapper.java deleted file mode 100644 index 5a1294b..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VirtualLinkMapper.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity; - -public interface VirtualLinkMapper { - - int deleteByPrimaryKey(String id); - - int insert(VirtualLinkEntity record); - - int insertSelective(VirtualLinkEntity record); - - VirtualLinkEntity selectByPrimaryKey(String id); - - List getVls(Map condition); - - int updateByPrimaryKeySelective(VirtualLinkEntity record); - - int updateByPrimaryKey(VirtualLinkEntity record); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VmMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VmMapper.java deleted file mode 100644 index 51fea63..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VmMapper.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VmEntity; - -public interface VmMapper { - - int deleteByPrimaryKey(String vmId); - - int deleteByVnfId(String vnfInstanceId); - - int insert(VmEntity record); - - int insertSelective(VmEntity record); - - VmEntity selectByPrimaryKey(String vmId); - - List getVms(Map condition); - - int updateByPrimaryKeySelective(VmEntity record); - - int updateByPrimaryKey(VmEntity record); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfInfoMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfInfoMapper.java deleted file mode 100644 index c7a51ae..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfInfoMapper.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfInfoEntity; - -public interface VnfInfoMapper { - - int deleteByPrimaryKey(String vnfInstanceId); - - int insert(VnfInfoEntity record); - - int insertSelective(VnfInfoEntity record); - - VnfInfoEntity selectByPrimaryKey(String vnfInstanceId); - - List getVnfInfos(Map condition); - - int updateByPrimaryKeySelective(VnfInfoEntity record); - - int updateByPrimaryKey(VnfInfoEntity record); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfMapper.java deleted file mode 100644 index 39bbeff..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfMapper.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfEntity; - -public interface VnfMapper { - - int deleteByPrimaryKey(String vnfInstanceId); - - int insert(VnfEntity record); - - int insertSelective(VnfEntity record); - - VnfEntity selectByPrimaryKey(String id); - - List getVnfs(Map condition); - - int updateByPrimaryKeySelective(VnfEntity record); - - int updateByPrimaryKey(VnfEntity record); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfStatusMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfStatusMapper.java deleted file mode 100644 index 75dd652..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/mapper/VnfStatusMapper.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.mapper; - -import java.util.List; -import java.util.Map; - -import org.onap.vfc.nfvo.res.service.entity.VnfStatusEntity; - -public interface VnfStatusMapper { - - int deleteByPrimaryKey(String vnfInstanceId); - - int insert(VnfStatusEntity record); - - int insertSelective(VnfStatusEntity record); - - VnfStatusEntity selectByPrimaryKey(String vnfInstanceId); - - List getVnfStatuss(Map condition); - - int updateByPrimaryKeySelective(VnfStatusEntity record); - - int updateByPrimaryKey(VnfStatusEntity record); -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/GrantResourseRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/GrantResourseRoa.java deleted file mode 100644 index 7affca5..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/GrantResourseRoa.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.service.group.inf.GrantResService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -@Path(UrlConstant.GRANTRES_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class GrantResourseRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(GrantResourseRoa.class); - - private GrantResService grantResService; - - @PUT - @Path("/stub") - public JSONObject grantResource(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - if(null == object) { - LOGGER.error("function=grantResource; msg=grantResource error, because body is null."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.grantResource.null")); - } - - LOGGER.info("GrantResourseRoa::grantResource:{}", object.toString()); - try { - return grantResService.grantResource(object); - } catch(ServiceException se) { - LOGGER.error("GrantResourseRoa::grantResource error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - @PUT - public JSONObject grantResourceReal(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - if(null == object) { - LOGGER.error("function=grantResource; msg=grantResource error, because body is null."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.grantResource.null")); - } - - LOGGER.info("GrantResourseRoa::grantResource:{}", object.toString()); - try { - return grantResService.grantResourceReal(object); - } catch(ServiceException se) { - LOGGER.error("GrantResourseRoa::grantResource error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setGrantResService(GrantResService grantResService) { - this.grantResService = grantResService; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/HostRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/HostRoa.java deleted file mode 100644 index b8ab7b7..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/HostRoa.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Host; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - * - * Host ROA Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -@Path(UrlConstant.HOST_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class HostRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(HostRoa.class); - - private Host host; - - /** - * - * Get hosts.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - public JSONObject getHosts(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap<>(10); - List hosts = host.getList(map); - - JSONObject result = new JSONObject(); - result.put("hosts", hosts); - return result; - } - - /** - * - * Get host.
- * - * @param context - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - @Path("/{hostId}") - public JSONObject getHost(@Context HttpServletRequest context, @PathParam("hostId") String id) - throws ServiceException { - LOGGER.info("HostRoa::getHost id:{}", id); - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_ID, id); - List hosts = host.getList(map); - - JSONObject result = new JSONObject(); - result.put("hosts", hosts); - return result; - } - - /** - * - * Add host.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @POST - public JSONObject addHost(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - - LOGGER.info("HostRoa::addHost:{}", object.toString()); - try { - int result = host.add(object); - return RoaResponseUtil.add(result); - } catch(ServiceException se) { - LOGGER.error("HostRoa::addHost error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * - * Delete host.
- * - * @param context - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @DELETE - public JSONObject deleteHost(@Context HttpServletRequest context, @QueryParam(ParamConstant.PARAM_ID) String id) - throws ServiceException { - LOGGER.info("HostRoa::deleteHost id:{}", id); - try { - int result = host.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("HostRoa::deleteHost error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * - * Update host.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @PUT - public JSONObject updateHost(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - - LOGGER.info("HostRoa::updateHost:{}", object.toString()); - try { - int result = host.update(object); - return RoaResponseUtil.update(result); - } catch(ServiceException se) { - LOGGER.error("HostRoa::updateHost error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setHost(Host host) { - this.host = host; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/LimitsRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/LimitsRoa.java deleted file mode 100644 index 849e64d..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/LimitsRoa.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.service.business.inf.LimitsBusiness; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -@Path(UrlConstant.LIMITS_URL) -@Consumes(MediaType.APPLICATION_JSON) -@Produces(MediaType.APPLICATION_JSON) -public class LimitsRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(LimitsRoa.class); - - private LimitsBusiness limitsBusiness; - - /** - *
- * - * @param context - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - public JSONObject getLimits(@Context HttpServletRequest context, - @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException { - LOGGER.warn("function=getLimits, vimId={}", vimId); - return limitsBusiness.getLimits(vimId); - } - - public void setLimitsBusiness(LimitsBusiness limitsBusiness) { - this.limitsBusiness = limitsBusiness; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/LocationRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/LocationRoa.java deleted file mode 100644 index b982b4c..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/LocationRoa.java +++ /dev/null @@ -1,316 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Location; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Sites; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - * Location ROA Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -@Path(UrlConstant.LOCATION_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class LocationRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(LocationRoa.class); - - private Location location; - - private Sites sites; - - /** - * Get Locations Base.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - public JSONObject getLocationsbase(@Context HttpServletRequest context) throws ServiceException { - Map condition = new HashMap<>(); - List locations = location.get(condition); - - JSONObject result = new JSONObject(); - result.put("locations", locations); - return result; - } - - /** - * Get Locations Base.
- * - * @param context - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - @Path("/{locationId}") - public JSONObject getLocationbase(@Context HttpServletRequest context, @PathParam("locationId") String id) - throws ServiceException { - LOGGER.info("LocationRoa::getLocationbase id:{}", id); - Map map = new HashMap<>(); - map.put(ParamConstant.PARAM_ID, id); - List locations = location.get(map); - - JSONObject result = new JSONObject(); - result.put("locations", locations); - return result; - } - - /** - * Get Country.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - @Path("/country") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject getCountry(@Context HttpServletRequest context) throws ServiceException { - return RoaResponseUtil.get(location.getCountry()); - } - - /** - * Get Location by Country.
- * - * @param context - * @param country - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - @Path("/locationbycountry") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject getLocationByCountry(@Context HttpServletRequest context, - @QueryParam(ParamConstant.PARAM_COUNTRY) String country) throws ServiceException { - LOGGER.info("LocationRoa::getLocationByCountry country:{}", country); - Map condition = new HashMap<>(); - condition.put(ParamConstant.PARAM_COUNTRY, country); - return RoaResponseUtil.get(location.getLocationByCountry(condition)); - } - - /** - * Get Cloud Service.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - @Path("/cloudservice") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject getCloudservice(@Context HttpServletRequest context) throws ServiceException { - return RoaResponseUtil.get(location.getCloudservice()); - } - - /** - * Get location details.
- * - * @param context - * @param locations - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - @Path("/site") - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject getLocation(@Context HttpServletRequest context, - @QueryParam(ParamConstant.PARAM_LOCATION) String locations) throws ServiceException { - LOGGER.info("LocationRoa::getLocation locations:{}", locations); - Map condition = new HashMap<>(); - List loca = new ArrayList(); - condition.put(ParamConstant.PARAM_LOCATION, locations); - loca = location.get(condition); - LOGGER.info("LocationRoa::getLocation loca:{}", loca); - return RoaResponseUtil.get(location.getLocationInfo(loca)); - } - - /** - * Add Location.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @POST - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject addLocation(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - - LOGGER.info("LocationRoa::addLocation : " + object.toString()); - try { - int result = location.add(object); - return RoaResponseUtil.add(result); - } catch(ServiceException se) { - LOGGER.error("LocationRoa::addLocation error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * Delete Location Base.
- * - * @param context - * @param locations - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @DELETE - @Path("/{location}") - public JSONObject deleteLocationbase(@Context HttpServletRequest context, - @PathParam(ParamConstant.PARAM_LOCATION) String locations) throws ServiceException { - LOGGER.info("LocationRoa::deleteLocation locations:{}", locations); - Map condition = new HashMap<>(); - condition.put(ParamConstant.PARAM_LOCATION, locations); - try { - int result = location.delete(locations); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("LocationRoa::deleteLocationbase error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * Delete Location.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject deleteLocation(@Context HttpServletRequest context) throws ServiceException { - - JSONObject object = RequestUtil.getJsonRequestBody(context); - String locations = JsonUtil.getJsonFieldStr(object, ParamConstant.PARAM_LOCATION); - String id = JsonUtil.getJsonFieldStr(object, ParamConstant.PARAM_ID); - LOGGER.info("LocationRoa::deleteLocation locations:{}", locations); - - Map condition = new HashMap<>(); - condition.put(ParamConstant.PARAM_LOCATION, locations); - SitesEntity sitesEntity = sites.get(condition); - try { - if(sitesEntity != null) { - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.delete.used.check")); - } - int result = location.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("LocationRoa::deleteLocation error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * Update Location.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @PUT - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject updateLocation(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - String local = JsonUtil.getJsonFieldStr(object, ParamConstant.PARAM_LOCATION); - Map localInfo = new HashMap<>(); - localInfo.put(ParamConstant.PARAM_LOCATION, local); - SitesEntity sitesEntity = sites.get(localInfo); - if(sitesEntity != null) { - LOGGER.error("function=updateLocation; msg=update error, because location is used."); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.used.check")); - } - LOGGER.info("LocationRoa::updateLocation : " + object.toString()); - - try { - int result = location.update(object); - return RoaResponseUtil.update(result); - } catch(ServiceException se) { - LOGGER.error("LocationRoa::update Location error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setLocation(Location location) { - this.location = location; - } - - public void setSites(Sites sites) { - this.sites = sites; - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/NetworkRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/NetworkRoa.java deleted file mode 100644 index 7f9d0f5..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/NetworkRoa.java +++ /dev/null @@ -1,189 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Network; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - * - * Network ROA Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -@Path(UrlConstant.NETWORKS_URL) -@Consumes({MediaType.APPLICATION_JSON}) -@Produces({MediaType.APPLICATION_JSON}) -public class NetworkRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(NetworkRoa.class); - - private Network network; - - /** - * - * Get details of networks.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - public JSONObject getNetworks(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap<>(10); - List networks = network.getList(map); - - JSONObject result = new JSONObject(); - result.put("networks", networks.toString()); - return result; - } - - /** - * - * Get network details.
- * - * @param context - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - @Path("/{networkId}") - public JSONObject getNetwork(@Context HttpServletRequest context, @PathParam("networkId") String id) - throws ServiceException { - LOGGER.info("NetworkRoa::getNetwork id:{}", id); - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_ID, id); - List networks = network.getList(map); - - JSONObject result = new JSONObject(); - result.put("networks", networks.toString()); - return result; - } - - /** - * - * Add network.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @POST - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public JSONObject addNetwork(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - - LOGGER.info("NetworkRoa::addNetwork:{}", object.toString()); - try { - int result = network.add(NetworkEntity.toEntity(object)); - return RoaResponseUtil.add(result); - } catch(ServiceException se) { - LOGGER.error("NetworkRoa::addNetwork error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * - * Delete network.
- * - * @param context - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @DELETE - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public JSONObject deleteNetwork(@Context HttpServletRequest context, @QueryParam(ParamConstant.PARAM_ID) String id) - throws ServiceException { - LOGGER.info("NetworkRoa::deleteNetwork id:{}", id); - try { - int result = network.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("NetworkRoa::deleteNetwork error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * - * Update network.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @PUT - @Consumes({MediaType.APPLICATION_JSON}) - @Produces({MediaType.APPLICATION_JSON}) - public JSONObject updateNetwork(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - - LOGGER.info("NetworkRoa::updateNetwork:{}", object.toString()); - try { - int result = network.update(object); - return RoaResponseUtil.update(result); - } catch(ServiceException se) { - LOGGER.error("NetworkRoa::updateNetwork error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setNetwork(Network network) { - this.network = network; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/PortRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/PortRoa.java deleted file mode 100644 index 952e326..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/PortRoa.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Port; -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - * - * Port ROA Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -@Path(UrlConstant.PORT_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class PortRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(PortRoa.class); - - private Port port; - - /** - * - * Get details of Ports.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - public JSONObject getPorts(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap<>(10); - List ports = port.getList(map); - - JSONObject result = new JSONObject(); - result.put("ports", ports); - return result; - } - - /** - * - * Get port details.
- * - * @param context - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @GET - @Path("/{portId}") - public JSONObject getPort(@Context HttpServletRequest context, @PathParam("portId") String id) - throws ServiceException { - LOGGER.info("PortRoa::getPort id:{}", id); - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_ID, id); - List ports = port.getList(map); - - JSONObject result = new JSONObject(); - result.put("ports", ports); - return result; - } - - /** - * - * Add port.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @POST - public JSONObject addPort(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - - LOGGER.info("PortRoa::addPort:{}", object.toString()); - try { - int result = port.add(PortEntity.toEntity(object)); - return RoaResponseUtil.add(result); - } catch(ServiceException se) { - LOGGER.error("PortRoa::addPort error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * - * Delete port.
- * - * @param context - * @param id - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @DELETE - public JSONObject deletePort(@Context HttpServletRequest context, @QueryParam(ParamConstant.PARAM_ID) String id) - throws ServiceException { - LOGGER.info("PortRoa::deletePort id:{}", id); - try { - int result = port.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("PortRoa::deletePort error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * - * Update port.
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @PUT - public JSONObject updatePort(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - - LOGGER.info("PortRoa::updatePort:{}", object.toString()); - try { - int result = port.update(object); - return RoaResponseUtil.update(result); - } catch(ServiceException se) { - LOGGER.error("PortRoa::updatePort error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setPort(Port port) { - this.port = port; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/ResOperateRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/ResOperateRoa.java deleted file mode 100644 index 111160e..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/ResOperateRoa.java +++ /dev/null @@ -1,151 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.group.inf.ResOperateService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - * Resource Operate ROA Class.
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 10, 2016 - */ -@Path(UrlConstant.RESOPERATE_URL) -@Consumes(MediaType.APPLICATION_JSON) -@Produces(MediaType.APPLICATION_JSON) -public class ResOperateRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(ResOperateRoa.class); - - private ResOperateService resOperateService; - - /** - * Update iResource pool.
- * - * @param context - * @param tenantId - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @PUT - @Path(UrlConstant.MODRES_URL) - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject updateIResPool(@Context HttpServletRequest context, - @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException { - JSONObject json = RequestUtil.getAllJsonRequestBody(context); - LOGGER.warn("ResPoolRoa::modVimId :{}", vimId); - JSONObject vimInfo = VimUtil.getVimById(vimId); - String tenant = vimInfo.getString("tenant"); - String tenantId = VimUtil.getTenantIdByName(tenant, vimId); - try { - resOperateService.updateIRes(tenantId, vimId, json); - resOperateService.sendMsgMonitor("update", vimId); - return RoaResponseUtil.update(HttpConstant.OK_CODE); - } catch(ServiceException se) { - LOGGER.error("ResOperateRoa::updateIResPool error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * Add all resource pool.
- * - * @param context - * @param tenantId - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @POST - @Path(UrlConstant.ADDRES_URL) - @Consumes(UrlConstant.APPLICATION_TYPE) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject addAllResPool(@Context HttpServletRequest context, - @QueryParam(ParamConstant.PARAM_TENANTID) String tenantId, - @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException { - JSONObject json = RequestUtil.getAllJsonRequestBody(context); - LOGGER.warn("ResOperateRoa::vimId :{}", vimId); - - try { - resOperateService.addIRes(tenantId, vimId, json); - resOperateService.sendMsgMonitor("create", vimId); - return RoaResponseUtil.add(HttpConstant.OK_CODE); - } catch(ServiceException se) { - LOGGER.error("ResOperateRoa::addAllResPool error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * Delete iResource.
- * - * @param context - * @param vimId - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @DELETE - @Consumes(MediaType.APPLICATION_JSON) - @Produces(MediaType.APPLICATION_JSON) - public JSONObject deleteIRes(@Context HttpServletRequest context, - @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException { - LOGGER.warn("ResOperateRoa::deleteIResource vimId:{}", vimId); - - try { - resOperateService.sendMsgMonitor("delete", vimId); - int result = resOperateService.deleteIRes(vimId); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("ResOperateRoa::deleteIRes error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setResOperateService(ResOperateService resOperateService) { - this.resOperateService = resOperateService; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/SitesRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/SitesRoa.java deleted file mode 100644 index 6d31aa8..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/SitesRoa.java +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Sites; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - * Sites ROA method
- *

- *

- * - * @author - * @version NFVO 0.5 Aug 24, 2016 - */ -@Path(UrlConstant.SITES_URL) -@Consumes(MediaType.APPLICATION_JSON) -@Produces(MediaType.APPLICATION_JSON) -public class SitesRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(SitesRoa.class); - - private Sites sites; - - /** - * getSites ROA method
- * - * @param context - * @return the get result - * @throws ServiceException When get failed. - * @since NFVO 0.5 - */ - @GET - public JSONObject getSites(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap(10); - List datacenters = sites.getList(map); - - JSONObject result = new JSONObject(); - result.put("datacenters", datacenters); - return result; - } - - /** - * getSite ROA method
- * - * @param context - * @param id - * @return the get result - * @throws ServiceException When get failed. - * @since NFVO 0.5 - */ - @GET - @Path("/{datacenterId}") - public JSONObject getSite(@Context HttpServletRequest context, @PathParam("datacenterId") String id) - throws ServiceException { - LOGGER.warn("SitesRoa::getSitesById id:{}", id); - Map map = new HashMap(10); - map.put(ParamConstant.PARAM_ID, id); - List datacenters = sites.getList(map); - - JSONObject result = new JSONObject(); - result.put("datacenters", datacenters); - return result; - } - - /** - * addSites ROA method
- * - * @param context - * @param id - * @return the add result - * @throws ServiceException When add failed. - * @since NFVO 0.5 - */ - @POST - public JSONObject addSites(@Context HttpServletRequest context) throws ServiceException { - JSONObject json = RequestUtil.getAllJsonRequestBody(context); - - LOGGER.warn("SitesRoa:: start add Sites"); - try { - int result = sites.add(json); - sites.sendToMonitor(json); - return RoaResponseUtil.add(result); - } catch(ServiceException se) { - LOGGER.error("SitesRoa::addSites error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * deleteSites ROA method
- * - * @param context - * @param id - * @return the delete result - * @throws ServiceException When delete failed. - * @since NFVO 0.5 - */ - @DELETE - @Path("/{datacenterId}") - public JSONObject deleteSites(@Context HttpServletRequest context, @PathParam("datacenterId") String id) - throws ServiceException { - LOGGER.warn("SitesRoa::deleteSites siteId:{}", id); - try { - int result = sites.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("SitesRoa::deleteSites error: " + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * updateSites ROA method
- * - * @param context - * @param id - * @return the update result - * @throws ServiceException When update failed. - * @since NFVO 0.5 - */ - @PUT - public JSONObject updateSites(@Context HttpServletRequest context) throws ServiceException { - JSONObject json = RequestUtil.getAllJsonRequestBody(context); - - LOGGER.warn("SitesRoa::start update Sites"); - try { - int result = sites.update(SitesEntity.toEntity(json)); - return RoaResponseUtil.update(result); - } catch(ServiceException se) { - LOGGER.error("SitesRoa::updateSites error:" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - /** - * grant resource method - *
- * - * @param context - * @return - * @throws ServiceException - * @since NFVO 0.5 - */ - @PUT - @Path("/grant") - public JSONObject grantResource(@Context HttpServletRequest context) throws ServiceException { - JSONObject json = RequestUtil.getAllJsonRequestBody(context); - - LOGGER.warn("SitesRoa::grant resource"); - try { - int result = sites.update(json); - return RoaResponseUtil.update(result); - } catch(ServiceException se) { - LOGGER.error("SitesRoa::grant resource:" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - @GET - @Path("/vims") - public String getVims(@Context HttpServletRequest context) throws ServiceException { - LOGGER.info("SitesRoa::get vims"); - JSONArray vims = VimUtil.getVims(); - JSONObject result = new JSONObject(); - result.put("data", vims); - return result.toString(); - } - - @GET - @Path("/vims/{vimId}") - public String getVim(@Context HttpServletRequest context, @PathParam("vimId") String vimId) - throws ServiceException { - LOGGER.info("SitesRoa::get vim by id: {}", vimId); - return VimUtil.getVimById(vimId).toString(); - } - - public void setSites(Sites sites) { - this.sites = sites; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/SwaggerRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/SwaggerRoa.java deleted file mode 100644 index 45ea2c1..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/SwaggerRoa.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.io.IOException; - -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; - -import org.apache.commons.io.IOUtils; - -/** - * Swagger API Doc.
- * - * @author - * @version NFVO 0.5 Oct 24, 2016 - */ -@Path("/v1") -@Produces({MediaType.APPLICATION_JSON}) -public class SwaggerRoa { - /** - * API doc. - * @param filename - * @return - * @throws IOException - */ - @GET - @Path("/swagger.json") - public String apidoc() throws IOException{ - ClassLoader classLoader = getClass().getClassLoader(); - return IOUtils.toString(classLoader.getResourceAsStream("swagger.json")); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VirtualLinkRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VirtualLinkRoa.java deleted file mode 100644 index a30d673..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VirtualLinkRoa.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VirtualLinkService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 27, 2016 - */ -@Path(UrlConstant.VL_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class VirtualLinkRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkRoa.class); - - private VirtualLinkService virtualLink; - - @GET - public JSONObject getVls(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap<>(10); - List vls = virtualLink.getList(map); - LOGGER.info("VirtualLinkRoa::getVls:{}", vls.toString()); - JSONObject result = new JSONObject(); - result.put("vls", vls); - return result; - } - - @GET - @Path("/{vlId}") - public JSONObject getVl(@Context HttpServletRequest context, @PathParam("vlId") String id) throws ServiceException { - LOGGER.info("VirtualLinkRoa::getVl id:{}", id); - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_ID, id); - List vls = virtualLink.getList(map); - LOGGER.info("VirtualLinkRoa::getVl:{}", vls.toString()); - JSONObject result = new JSONObject(); - result.put("vls", vls); - return result; - } - - @POST - public JSONObject addVl(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - if(null == object) { - LOGGER.error("function=addVl; msg=add error, because vl is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.virtualLink.add.null")); - } - - LOGGER.info("VirtualLinkRoa::addVl:{}", object.toString()); - try { - return virtualLink.addVl(VirtualLinkEntity.toEntity(object)); - } catch(ServiceException se) { - LOGGER.error("VirtualLinkRoa::addVl error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - @DELETE - @Path("/{id}") - public JSONObject deleteVl(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) - throws ServiceException { - if(id == null) { - LOGGER.error("function=deleteVl; msg=delete error, because vlId is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.virtualLink.delete.vlId.null")); - } - LOGGER.info("VirtualLinkRoa::deleteVl id:{}", id); - try { - int result = virtualLink.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("VirtualLinkRoa::deleteVl error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setVirtualLink(VirtualLinkService virtualLink) { - this.virtualLink = virtualLink; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VmRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VmRoa.java deleted file mode 100644 index 5b17caa..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VmRoa.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.entity.VmEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VmService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -@Path(UrlConstant.VM_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class VmRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(VmRoa.class); - - private VmService vmService; - - @GET - public JSONObject getVms(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap<>(10); - List vms = vmService.getList(map); - LOGGER.info("VmRoa::getVms:{}", vms.toString()); - JSONObject result = new JSONObject(); - result.put("vms", vms); - return result; - } - - @GET - @Path("/{vmId}") - public JSONObject getVm(@Context HttpServletRequest context, @PathParam("vmId") String id) throws ServiceException { - LOGGER.info("VmRoa::getVm id:{}", id); - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_ID, id); - List vms = vmService.getList(map); - LOGGER.info("VmRoa::getVm:{}", vms.toString()); - JSONObject result = new JSONObject(); - result.put("vms", vms); - return result; - } - - @POST - public JSONObject addVm(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - if(null == object) { - LOGGER.error("function=addVm; msg=add error, because vm is null."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vm.add.null")); - } - - LOGGER.info("VmRoa::addVm:{}", object.toString()); - try { - return vmService.addVm(VmEntity.toEntity(object)); - } catch(ServiceException se) { - LOGGER.error("VmRoa::addVm error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - @DELETE - @Path("/{id}") - public JSONObject deleteVm(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) - throws ServiceException { - if(id == null) { - LOGGER.error("function=deleteVm; msg=delete error, because id is null."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vm.delete.id.null")); - } - LOGGER.info("VmRoa::deleteVm id:{}", id); - try { - int result = vmService.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("VmRoa::deleteVm error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setVmService(VmService vmService) { - this.vmService = vmService; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfInfoRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfInfoRoa.java deleted file mode 100644 index c4f631c..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfInfoRoa.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.entity.VnfInfoEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VnfInfoService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -@Path(UrlConstant.VNFINFO_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class VnfInfoRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(VnfInfoRoa.class); - - private VnfInfoService vnfInfoService; - - @GET - public JSONObject getVnfInfos(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap<>(10); - List vnfInfos = vnfInfoService.getList(map); - LOGGER.info("VnfInfoRoa::getVnfInfos:{}", vnfInfos.toString()); - JSONObject result = new JSONObject(); - result.put("vnfInfos", vnfInfos); - return result; - } - - @GET - @Path("/{id}") - public JSONObject getVnfInfo(@Context HttpServletRequest context, @PathParam("id") String id) - throws ServiceException { - LOGGER.info("VnfInfoRoa::getVnfInfo id:{}", id); - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_ID, id); - List vnfInfos = vnfInfoService.getList(map); - LOGGER.info("VnfInfoRoa::getVnfInfo:{}", vnfInfos.toString()); - JSONObject result = new JSONObject(); - result.put("vnfInfos", vnfInfos); - return result; - } - - @POST - public JSONObject addVnfInfo(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - if(null == object) { - LOGGER.error("function=addVnfInfo; msg=add error, because vnfInfo is null."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfInfo.add.null")); - } - - LOGGER.info("VnfInfoRoa::addVnfInfo:{}", object.toString()); - try { - return vnfInfoService.addVnfInfo(object); - } catch(ServiceException se) { - LOGGER.error("VnfInfoRoa::addVnfInfo error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - @DELETE - @Path("/{id}") - public JSONObject deleteVnfInfo(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) - throws ServiceException { - if(id == null) { - LOGGER.error("function=deleteVnfInfo; msg=delete error, because id is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfInfo.delete.id.null")); - } - LOGGER.info("VnfInfoRoa::deleteVnfInfo id:{}", id); - try { - int result = vnfInfoService.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("VnfInfoRoa::deleteVnfInfo error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setVnfInfoService(VnfInfoService vnfInfoService) { - this.vnfInfoService = vnfInfoService; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfRoa.java deleted file mode 100644 index a60842b..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfRoa.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.entity.VnfEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VnfService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 28, 2016 - */ -@Path(UrlConstant.VNF_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class VnfRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkRoa.class); - - private VnfService vnfService; - - @GET - public JSONObject getVnfs(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap<>(10); - List vnfs = vnfService.getList(map); - LOGGER.info("VnfRoa::getVnfs:{}", vnfs.toString()); - JSONObject result = new JSONObject(); - result.put("vnfs", vnfs); - return result; - } - - @GET - @Path("/{vnfId}") - public JSONObject getVnf(@Context HttpServletRequest context, @PathParam("vnfId") String id) - throws ServiceException { - LOGGER.info("VnfRoa::getVnf id:{}", id); - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_ID, id); - List vnfs = vnfService.getList(map); - LOGGER.info("VnfRoa::getVnf:{}", vnfs.toString()); - JSONObject result = new JSONObject(); - result.put("vnfs", vnfs); - return result; - } - - @POST - public JSONObject addVnf(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - if(null == object) { - LOGGER.error("function=addVnf; msg=add error, because vnf is null."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnf.add.null")); - } - - LOGGER.info("VnfRoa::addVnf:{}", object.toString()); - try { - return vnfService.addVnf(VnfEntity.toEntity(object)); - } catch(ServiceException se) { - LOGGER.error("VnfRoa::addVnf error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - @DELETE - @Path("/{id}") - public JSONObject deleteVnf(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) - throws ServiceException { - if(id == null) { - LOGGER.error("function=deleteVnf; msg=delete error, because id is null."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnf.delete.id.null")); - } - LOGGER.info("VnfRoa::deleteVnf id:{}", id); - try { - int result = vnfService.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("VnfRoa::deleteVnf error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setVnfService(VnfService vnfService) { - this.vnfService = vnfService; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfStatusRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfStatusRoa.java deleted file mode 100644 index d67c11b..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/VnfStatusRoa.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.MediaType; - -import org.onap.vfc.nfvo.res.common.ResourceUtil; -import org.onap.vfc.nfvo.res.common.constant.HttpConstant; -import org.onap.vfc.nfvo.res.common.constant.ParamConstant; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; -import org.onap.vfc.nfvo.res.service.entity.VnfStatusEntity; -import org.onap.vfc.nfvo.res.service.group.inf.VnfStatusService; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Oct 29, 2016 - */ -@Path(UrlConstant.VNFSTATUS_URL) -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -public class VnfStatusRoa { - - private static final Logger LOGGER = LoggerFactory.getLogger(VnfStatusRoa.class); - - private VnfStatusService vnfStatusService; - - @GET - public JSONObject getVnfStatuss(@Context HttpServletRequest context) throws ServiceException { - Map map = new HashMap<>(10); - List vnfStatus = vnfStatusService.getList(map); - LOGGER.info("VnfStatusRoa::getVnfStatuss:{}", vnfStatus.toString()); - JSONObject result = new JSONObject(); - result.put("vnfStatus", vnfStatus); - return result; - } - - @GET - @Path("/{id}") - public JSONObject getVnfStatus(@Context HttpServletRequest context, @PathParam("id") String id) - throws ServiceException { - LOGGER.info("VnfStatusRoa::getVnfStatus id:{}", id); - Map map = new HashMap<>(10); - map.put(ParamConstant.PARAM_ID, id); - List vnfStatus = vnfStatusService.getList(map); - LOGGER.info("VnfStatusRoa::getVnfStatus:{}", vnfStatus.toString()); - JSONObject result = new JSONObject(); - result.put("vnfStatus", vnfStatus); - return result; - } - - @POST - public JSONObject addVnfStatus(@Context HttpServletRequest context) throws ServiceException { - JSONObject object = RequestUtil.getJsonRequestBody(context); - if(null == object) { - LOGGER.error("function=addVnfInfo; msg=add error, because vnfStatus is null."); - throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfStatus.add.null")); - } - - LOGGER.info("VnfStatusRoa::addVnfStatus:{}", object.toString()); - try { - return vnfStatusService.addVnfStatus(object); - } catch(ServiceException se) { - LOGGER.error("VnfStatusRoa::addVnfStatus error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - @DELETE - @Path("/{id}") - public JSONObject deleteVnfStatus(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) - throws ServiceException { - if(id == null) { - LOGGER.error("function=deleteVnfStatus; msg=delete error, because id is null."); - throw new ServiceException( - ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfStatus.delete.id.null")); - } - LOGGER.info("VnfStatusRoa::deleteVnfStatus id:{}", id); - try { - int result = vnfStatusService.delete(id); - return RoaResponseUtil.delete(result); - } catch(ServiceException se) { - LOGGER.error("VnfStatusRoa::deleteVnfStatys error:{}" + se); - return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); - } - } - - public void setVnfStatusService(VnfStatusService vnfStatusService) { - this.vnfStatusService = vnfStatusService; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ExceptionMessage.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ExceptionMessage.java deleted file mode 100644 index 2529c1f..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ExceptionMessage.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest.exceptionmapper; - -import org.apache.http.HttpStatus; - -/** - * Exception response model.
- * - * @author - * @version NFVO 0.5 Sep 27, 2016 - */ -public class ExceptionMessage { - - private String errorCode = "unknown.error"; - - private int httpCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; - - private String message; - - @Override - public String toString() { - return "Error {errorCode=" + this.errorCode + ", httpCode=" + this.httpCode + ", message=" - + this.message + "}"; - } - - public String getErrorCode() { - return this.errorCode; - } - - public void setErrorCode(String errorCode) { - this.errorCode = errorCode; - } - - public String getMessage() { - return this.message; - } - - public void setMessage(String message) { - this.message = message; - } - - public int getHttpCode() { - return this.httpCode; - } - - public void setHttpCode(int httpCode) { - this.httpCode = httpCode; - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/GenericExceptionMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/GenericExceptionMapper.java deleted file mode 100644 index 104c29a..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/GenericExceptionMapper.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest.exceptionmapper; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -/** - * Generic exception response provider.
- * - * - * @author - * @version NFVO 0.5 Sep 27, 2016 - */ -@Provider -public class GenericExceptionMapper implements ExceptionMapper{ - - @Override - public Response toResponse(Exception exception) { - ExceptionMessage message = new ExceptionMessage(); - message.setMessage(exception.getMessage()); - return Response.status(message.getHttpCode()).type( - MediaType.APPLICATION_JSON).entity(message).build(); - } -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ServiceExceptionMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ServiceExceptionMapper.java deleted file mode 100644 index 27d0c9f..0000000 --- a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ServiceExceptionMapper.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest.exceptionmapper; - -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import javax.ws.rs.ext.ExceptionMapper; -import javax.ws.rs.ext.Provider; - -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - * ServiceException response provider.
- * - * @author - * @version NFVO 0.5 Sep 27, 2016 - */ -@Provider -public class ServiceExceptionMapper implements ExceptionMapper{ - - @Override - public Response toResponse(ServiceException exception) { - ExceptionMessage message = new ExceptionMessage(); - message.setErrorCode(exception.getId()); - message.setHttpCode(exception.getHttpCode()); - message.setMessage(exception.getMessage()); - return Response.status(message.getHttpCode()). - type(MediaType.APPLICATION_JSON).entity(message).build(); - } - -} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/ResourceUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/ResourceUtil.java new file mode 100644 index 0000000..4259574 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/ResourceUtil.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public class ResourceUtil { + + private ResourceUtil() { + + } + + /** + * It is used to get Message
+ * + * @param key + * @return + * @since NFVO 0.5 + */ + public static String getMessage(String key) { + return key; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java new file mode 100644 index 0000000..8e66c7f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/VimUtil.java @@ -0,0 +1,141 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common; + +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 30, 2016 + */ +public class VimUtil { + + private static final Logger LOG = LoggerFactory.getLogger(VimUtil.class); + + private VimUtil() { + + } + + /** + * Get VIMs. + * + * @return + */ + public static JSONArray getVims() { + String esrResponse = + RestfulUtil.getResponseContent(UrlConstant.ESR_GET_VIMS_URL, new RestfulParametes(), "get"); + LOG.info("Get vims from ESR! EsrResponse:{}", esrResponse); + if(null == esrResponse) { + LOG.error("ESR return fail."); + return null; + } else { + return JSONArray.fromObject(esrResponse); + } + + } + + /** + * Get vimId by vimName. + * + * @return + */ + public static String getVimIdByName(String name) { + JSONArray vims = getVims(); + for(int i = 0; i < vims.size(); i++) { + JSONObject vim = vims.getJSONObject(i); + LOG.info("vimInfo: " + vim); + String vimName = vim.getString("name"); + String vimId = vim.getString("vimId"); + LOG.info("name:" + name + ", vimName:" + vimName + ", vimId:" + vimId); + if(name.trim().equalsIgnoreCase(vimName)) { + return vimId; + } + } + LOG.error("No vim with this vimName"); + return ""; + + } + + /** + * Get VIM. + * + * @param vimId + * @return + */ + public static JSONObject getVimById(String vimId) { + if(vimId == null || "".equals(vimId.trim())) { + LOG.error("Get vim ERROR, VimId is null. "); + return null; + } + JSONObject esrResponse = RestfulUtil.getResponseObj(String.format(UrlConstant.ESR_GET_VIM_URL, vimId), "get"); + LOG.info("Get vims from ESR! EsrResponse:{}", esrResponse); + if(null == esrResponse) { + LOG.error("ESR return fail."); + return null; + } else { + return esrResponse; + } + } + + /** + * Get tenants. + * + * @param vimId + * @return + */ + public static JSONArray getTenants(String vimId) { + String url = String.format(UrlConstant.GET_TENANT_URL, vimId); + JSONObject resultObj = RestfulUtil.getResponseObj(url, ParamConstant.PARAM_GET); + JSONArray tenants = resultObj.getJSONArray("tenants"); + LOG.info("Get tenants from multivim! tenants:{}", tenants); + return tenants; + } + + /** + *
+ * + * @param tenant + * @param vimId + * @return + * @since NFVO 0.5 + */ + public static String getTenantIdByName(String tenant, String vimId) { + JSONArray tenants = VimUtil.getTenants(vimId); + String tenantId = ""; + for(int i = 0; i < tenants.size(); i++) { + JSONObject obj = tenants.getJSONObject(i); + String name = obj.getString("name"); + if(name.equalsIgnoreCase(tenant)) { + tenantId = obj.getString("id"); + } + } + LOG.info("GetTenantIdByName tenantId:{}", tenantId); + return tenantId; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java new file mode 100644 index 0000000..57bd3cc --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/Constant.java @@ -0,0 +1,93 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.constant; + +/** + * HTTP constants
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public class Constant { + + public static final String RES_MANAGEMENT_DB = "resmanagementdb"; + + /** + * Database Delete/Modify/Add fail. + */ + public static final int ERROR_CODE = -1; + + /** + * Database Delete/Modify/Add success. + */ + public static final int OK_CODE = 1; + + /** + * Lack of resource. + */ + public static final int RES_NOT_ENOUGH_CODE = -2; + + /** + * Module name. + */ + public static final String MODULE_NAME = "Resmanagement"; + + public static final String RESPONSE_CONTENT = "responseContent"; + + public static final String STATUS_CODE = "statusCode"; + + /** + * Format Time + */ + public static final String DATE_FORMATE = "yyyy-MM-dd HH:mm:ss"; + + public static final String DATE_UTC_FORMATE = "yyyy-MM-dd'T'HH:mm:ss'Z'"; + + public static final String UTC_FORMATE = "UTC"; + + public static final String DATE_DAY_FORMATE = "yyyy-MM-dd 00:00:00"; + + /** + * IAM + */ + + public static final String HTTP_CONTENT_TYPE = "Content-Type"; + + public static final String HTTP_CONTENT_TYPE_VALUE = "application/json;charset=UTF-8"; + + public static final String X_TENANT_ID = "X-Tenant-Id"; + + public static final String IAM_TOKEN = "x-auth-token"; + + public static final String IAM_AUTH_TOKEN = "X-Auth-Token"; + + public static final String IAM_USER_ID = "X-User-Id"; + + public static final String IAM_USER_NAME = "X-User-Name"; + + public static final String IAM_DOMAIN_NAME = "X-Domain-Name"; + + public static final String HEADER_SUBJECT_TOKEN = "X-Subject-Token"; + + public static final int REPEAT_REG_TIME = 60 * 1000; + + private Constant() { + // private constants + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/HttpConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/HttpConstant.java new file mode 100644 index 0000000..354f887 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/HttpConstant.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.constant; + +/** + * + * Http constant class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class HttpConstant { + + public static final int ERROR_CODE = -1; + + public static final int OK_CODE = 1; + + public static final int HTTP_OK = 200; + + public static final int HTTP_CREATED = 201; + + public static final int HTTP_ACCEPTED = 202; + + public static final int HTTP_NOCONTENT = 204; + + public static final int HTTP_UNAUTHORIZED = 401; + + public static final int HTTP_BAD_REQUEST = 400; + + public static final int HTTP_NOTFOUND_CODE = 404; + + public static final int HTTP_CONFLICT_CODE = 409; + + public static final int HTTP_INVALID_PARAMETERS = 415; + + public static final int HTTP_INNERERROR_CODE = 500; + + public static final int INTERNAL_EXCEPTION_CODE = 600; + + public static final int TOKEN_HEAD_NULL_CODE = 601; + + public static final int TOKEN_USER_NULL_CODE = 602; + + public static final int SERVICE_URL_ERROR_CODE = 603; + + public static final int ACCESS_OBJ_NULL_CODE = 604; + + public static final int CONNECT_NOT_FOUND_CODE = 605; + + public static final int VCENTER_PARA_ERROR_CODE = 606; + + public static final int TYPE_PARA_ERROR_CODE = 607; + + public static final int CONNECT_FAIL_CODE = 608; + + public static final int DIS_CONNECT_FAIL_CODE = 609; + + public static final int HANDSHAKE_FAIL_CODE = 610; + + private HttpConstant() { + //private constructor + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/ParamConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/ParamConstant.java new file mode 100644 index 0000000..3b958c5 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/ParamConstant.java @@ -0,0 +1,370 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.constant; + +/** + *
+ *

+ * Contstant for System interactive. + *

+ * + * @author + * @version NFVO 0.5 2016-3-17 + */ +public class ParamConstant { + + /** + * param key: vimId. + */ + public static final String PARAM_VIMID = "vimId"; + + /** + * param key: vimName + */ + public static final String PARAM_VIMNAME = "vimName"; + + /** + * param key: tenantId. + */ + public static final String PARAM_TENANTID = "tenantId"; + + public static final String TOTAL_CPU = "totalCPU"; + + public static final String USED_CPU = "usedCPU"; + + public static final String TOTAL_MEMORY = "totalMemory"; + + public static final String USED_MEMORY = "usedMemory"; + + public static final String TOTAL_DISK = "totalDisk"; + + public static final String USED_DISK = "usedDisk"; + + /** + * param key: data. + */ + public static final String PARAM_DATA = "data"; + + /** + * param key: id. + */ + public static final String PARAM_ID = "id"; + + /** + * param key: vimId + */ + public static final String PARAM_IP = "ip"; + + /** + * param key: role. + */ + public static final String PARAM_ROLE = "role"; + + /** + * param key: roleId. + */ + public static final String PARAM_ROLEID = "roleId"; + + /** + * param key: total. + */ + public static final String PARAM_TOTAL = "total"; + + /** + * param key: used. + */ + public static final String PARAM_USED = "used"; + + /** + * param key: vcpus. + */ + public static final String PARAM_VCPUS = "vcpus"; + + /** + * param key: disk. + */ + public static final String PARAM_DISK = "disk"; + + /** + * param key: cpumhz. + */ + public static final String PARAM_CPUMHZ = "cpumhz"; + + /** + * param key: countyr + */ + public static final String PARAM_COUNTRY = "country"; + + /** + * param key: vendorId + */ + public static final String PARAM_VENDORID = "vendorId"; + + /** + * param key: vendorName + */ + public static final String PARAM_VENDORNAME = "vendorName"; + + /** + * param key: memory. + */ + public static final String PARAM_MEMORY = "memory"; + + /** + * param key: name. + */ + public static final String PARAM_NAME = "name"; + + /** + * param key: status. + */ + public static final String PARAM_STATUS = "status"; + + /** + * param key: parent. + */ + public static final String PARAM_PARENT = "parent"; + + /** + * param key: location. + */ + public static final String PARAM_LOCATION = "location"; + + /** + * param key: siteName. + */ + public static final String PARAM_SITENAME = "siteName"; + + /** + * param key: vendor. + */ + public static final String PARAM_VENDOR = "vendor"; + + /** + * param key: vendors. + */ + public static final String PARAM_VENDORS = "vendors"; + + /** + * param key: tenantSites. + */ + public static final String PARAM_TENANTSITES = "tenantSites"; + + /** + * param key: siteId. + */ + public static final String PARAM_SITEID = "siteId"; + + /** + * param key: resArbitration. + */ + public static final String PARAM_RESARBITRATION = "resArbitration"; + + /** + * param key: userRole. + */ + public static final String PARAM_USERROLE = "userRole"; + + /** + * param key: admin. + */ + public static final String PARAM_ADMIN = "admin"; + + /** + * param key: tenant. + */ + public static final String PARAM_TENANT = "tenant"; + + /** + * param key: type. + */ + public static final String PARAM_TYPE = "type"; + + /** + * param key: action. + */ + public static final String PARAM_ACTION = "action"; + + /** + * param key: offline. + */ + public static final String PARAM_OFFLINE = "offline"; + + /** + * param key: online. + */ + public static final String PARAM_ONLINE = "online"; + + /** + * param key: drexecute. + */ + public static final String PARAM_DREXECUTE = "drexecute"; + + /** + * param key: drRollBack. + */ + public static final String PARAM_DRROLLBACK = "drrollback"; + + /** + * param key: scaleOut. + */ + public static final String PARAM_SCALEOUT = "scaleout"; + + /** + * param key: scaleIn. + */ + public static final String PARAM_SCALEIN = "scalein"; + + /** + * param key: network. + */ + public static final String PARAM_NETWORK = "networks"; + + /** + * param key: host. + */ + public static final String PARAM_HOST = "hosts"; + + /** + * param key: network. + */ + public static final String PARAM_PORT = "ports"; + + /** + * param key: providernetworks. + */ + public static final String PARAM_PROVIDERNETWORKS = "providernetworks"; + + /** + * param key: vims. + */ + public static final String PARAM_VIMS = "vims"; + + /** + * param key: vms. + */ + public static final String PARAM_VMS = "vms"; + + /** + * param key: vapps. + */ + public static final String PARAM_VAPPS = "vapps"; + + /** + * param key: vapp. + */ + public static final String PARAM_VAPP = "vapp"; + + /** + * param key: sites. + */ + public static final String PARAM_SITES = "sites"; + + /** + * param key: vduId. + */ + public static final String PARAM_VDUID = "vduId"; + + /** + * param key: vappId. + */ + public static final String PARAM_VAPPID = "vappId"; + + /** + * param key: hostId. + */ + public static final String PARAM_HOSTID = "hostId"; + + /** + * param key: projectId. + */ + public static final String PARAM_PROJECTID = "projectId"; + + /** + * param key: vnfmId. + */ + public static final String PARAM_VNFMID = "vnfmId"; + + /** + * param key: params. + */ + public static final String PARAM_PARAMS = "params"; + + /** + * param key: url. + */ + public static final String PARAM_URL = "url"; + + /** + * param key: post. + */ + public static final String PARAM_POST = "post"; + + /** + * param key: put. + */ + public static final String PARAM_PUT = "put"; + + /** + * param key: del. + */ + public static final String PARAM_DEL = "del"; + + /** + * param key: get. + */ + public static final String PARAM_GET = "get"; + + /** + * param key: retCode. + */ + public static final String PARAM_RETCODE = "retCode"; + + /** + * param key: ADD. + */ + public static final String PARAM_ADD = "add"; + + /** + * param key: active. + */ + public static final String PARAM_ACTIVE = "active"; + + /** + * param key: deleted. + */ + public static final String PARAM_DELETED = "deleted"; + + /** + * param key: deleting. + */ + public static final String PARAM_DELETING = "deleting"; + + /** + * param key: response + */ + public static final String PARAM_RESPONSE = "response"; + + /** + * param key: info + */ + public static final String PARAM_INFO = "info"; + + private ParamConstant() { + // private constructor + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/ResponseConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/ResponseConstant.java new file mode 100644 index 0000000..8222b5f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/ResponseConstant.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.constant; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; + +/** + * Response constants.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public class ResponseConstant { + + public static final String ADD_SUCESS_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.add.success"); + + public static final String ADD_FAIL_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.add.error"); + + public static final String DEL_SUCESS_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.del.success"); + + public static final String DEL_FAIL_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.del.error"); + + public static final String MOD_SUCESS_MSG = + ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.update.success"); + + public static final String MOD_FAIL_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.update.error"); + + public static final String QUERY_SUCESS_MSG = + ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.query.success"); + + public static final String QUERY_FAIL_MSG = ResourceUtil.getMessage("org.openo.nfvo.resmanage.common.query.error"); + + public static final String DELSODORES_FAIL_MSG = "delete sodores error"; + + public static final String DELVNFMINFO_FAIL_MSG = "delete vnfm error"; + + public static final String RES_VERIFY_SUCESS_MSG = "nsdata verify sucessfully"; + + public static final String RES_VERIFY_FAIL_MSG = "res verify failed"; + + private ResponseConstant() { + // private constructor + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java new file mode 100644 index 0000000..1aa50c1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/constant/UrlConstant.java @@ -0,0 +1,258 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.constant; + +/** + *
+ *

+ * Constant for REST URL. + *

+ * + * @author + * @version NFVO 0.5 2016-3-17 + */ +public class UrlConstant { + + /** + * networks target. + */ + public static final String LOCATION_TARGET = "location"; + + /** + * MSB register url. + */ + public static final String REST_MSB_REGISTER = "/openoapi/microservices/v1/services"; + + public static final String ESR_GET_VIM_URL = "/openoapi/extsys/v1/vims/%s"; + + public static final String ESR_GET_VIMS_URL = "/openoapi/extsys/v1/vims"; + + /** + * send resource info to monitor url + */ + public static final String SEND_MSG_MONITOR = "/openoapi/umc/v1/resinfo"; + + /** + * networks url. + */ + public static final String LOCATION_URL = "/v1/locations"; + + /** + * port url. + */ + public static final String PORT_URL = "/v1/ports"; + + /** + * host url. + */ + public static final String HOST_URL = "/v1/hosts"; + + /** + * vl url. + */ + public static final String VL_URL = "/v1/vl"; + + /** + * vnf url. + */ + public static final String VNF_URL = "/v1/vnf"; + + /** + * vnfinfo url. + */ + public static final String VNFINFO_URL = "/v1/vnfinfo"; + + /** + * vnfstatus url. + */ + public static final String VNFSTATUS_URL = "/v1/vnfstatus"; + + /** + * grant resource url. + */ + public static final String GRANTRES_URL = "/v1/resource/grant"; + + /** + * vm url. + */ + public static final String VM_URL = "/v1/vm"; + + /** + * sites target. + */ + public static final String SITES_TARGET = "sites"; + + /** + * sites url. + */ + public static final String SITES_URL = "/v1/datacenters"; + + /** + * networks target. + */ + public static final String NETWORKS_TARGET = "networks"; + + /** + * networks url. + */ + public static final String NETWORKS_URL = "/v1/networks"; + + /** + * updateres. + */ + public static final String MODRES_URL = "/updateres"; + + /** + * resoperate target. + */ + public static final String RESOPERATE_TARGET = "resoperate"; + + /** + * APPLICATION_TYPE. + */ + public static final String APPLICATION_TYPE = "application/json"; + + /** + * ADDRES. + */ + public static final String ADDRES_URL = "/resmgr/vims"; + + /** + * updatebytenant. + */ + public static final String UPDATE_BY_TENANT = "updatebytenant"; + + /** + * updatebyvapp. + */ + public static final String UPDATE_BY_VAPP = "updatebyvapp"; + + /** + * getNetworkURL. + */ + public static final String GET_NETWORK_URL = "/openoapi/multivim/v1/%s/%s/networks"; + + /** + * getTenantURL. + */ + public static final String GET_TENANT_URL = "/openoapi/multivim/v1/%s/tenants"; + + /** + * getHostURL. + */ + public static final String GET_HOST_URL = "/openoapi/multivim/v1/%s/%s/hosts"; + + /** + * getHostDetailURL. + */ + public static final String GET_HOSTDETAIL_URL = "/openoapi/multivim/v1/%s/%s/hosts/%s"; + + /** + * getNetworkURL. + */ + public static final String GET_PORT_URL = "/openoapi/multivim/v1/%s/%s/ports"; + + /** + * getLimitsURL. + */ + public static final String GET_LIMITS_URL = "/openoapi/multivim/v1/%s/%s/limits"; + + /** + * template notify M url. + */ + public static final String TEMPLATE_NOTIFY_M_URL = ""; + + /** + * tenantsite allot url. + */ + public static final String TENANTSITE_ALLOT_URL = "/v1/resmanage/tenantsite/allot"; + + /** + * tenantsite allot target. + */ + public static final String TENANTSITE_ALLOT_TARGET = "tenantsite/allot"; + + /** + * tenant url. + */ + public static final String TENANT_URL = "/v1/resmanage/tenant"; + + /** + * tenant target. + */ + public static final String TENANT_TARGET = "tenant"; + + /** + * rollback url. + */ + public static final String ROLLBACK_URL = "/v1/resmanage/rollback"; + + /** + * rollback target. + */ + public static final String ROLLBACK_TARGET = "rollback"; + + /** + * vms target. + */ + public static final String VIM_TARGET = "vim"; + + /** + * vms url. + */ + public static final String VIM_URL = "/v1/resmanage/vim"; + + /** + * https + */ + public static final String GET_HTTPS = "https://"; + + /** + * get token + */ + public static final String GET_IAM_TOKEN = "/v3/auth/tokens"; + + /** + * rest. + */ + public static final String REST = "/rest"; + + /** + * donsdata url. + */ + public static final String INSTALL_URL = "install"; + + /** + * donsdata url. + */ + public static final String UNINSTALL_URL = "uninstall"; + + /** + * respool url. + */ + public static final String RESOPERATE_URL = "/v1/resoperate"; + + /** + * limits url. + */ + public static final String LIMITS_URL = "/v1/limits"; + + private UrlConstant() { + // private constructor + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java new file mode 100644 index 0000000..faf63f7 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtil.java @@ -0,0 +1,290 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util; + +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; + +/** + * + * Json Utility Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public final class JsonUtil { + + private static final Logger LOG = LoggerFactory.getLogger(StringUtil.class); + + private static final int TYPE_STRING = 0; + + private static final int TYPE_INT = 1; + + private static final int TYPE_JSONA = 2; + + private static final int TYPE_JSONO = 3; + + private static final int TYPE_LONG = 4; + + private JsonUtil() { + } + + /** + * + * Get Json Field String.
+ * + * @param jsonObj + * @param fieldName + * @return + * @since NFVO 0.5 + */ + public static String getJsonFieldStr(JSONObject jsonObj, String fieldName) { + return (String)getJsonFieldObject(jsonObj, fieldName, TYPE_STRING); + } + + /** + * + * Get Json Field Integer.
+ * + * @param jsonObj + * @param fieldName + * @return + * @since NFVO 0.5 + */ + public static Integer getJsonFieldInt(JSONObject jsonObj, String fieldName) { + return (Integer)getJsonFieldObject(jsonObj, fieldName, TYPE_INT); + } + + /** + * + * Get Json Field array.
+ * + * @param jsonObj + * @param fieldName + * @return + * @since NFVO 0.5 + */ + public static JSONArray getJsonFieldArr(JSONObject jsonObj, String fieldName) { + return (JSONArray)getJsonFieldObject(jsonObj, fieldName, TYPE_JSONA); + } + + /** + * + * Get Json Field Json.
+ * + * @param jsonObj + * @param fieldName + * @return + * @since NFVO 0.5 + */ + public static JSONObject getJsonFieldJson(JSONObject jsonObj, String fieldName) { + return (JSONObject)getJsonFieldObject(jsonObj, fieldName, TYPE_JSONO); + } + + /** + * + * Get Json Field Long.
+ * + * @param jsonObj + * @param fieldName + * @return + * @since NFVO 0.5 + */ + public static Long getJsonFieldLong(JSONObject jsonObj, String fieldName) { + return (Long)getJsonFieldObject(jsonObj, fieldName, TYPE_LONG); + } + + /** + * + * Get Json Field Object.
+ * + * @param jsonObj + * @param fieldName + * @param classType + * @return + * @since NFVO 0.5 + */ + private static Object getJsonFieldObject(JSONObject jsonObj, String fieldName, int classType) { + try { + if(null != jsonObj && jsonObj.has(fieldName)) { + Object result = new Object(); + switch(classType) { + case TYPE_STRING: + result = "null".equals(jsonObj.getString(fieldName)) ? "" : jsonObj.getString(fieldName); + break; + case TYPE_INT: + result = jsonObj.getInt(fieldName); + break; + case TYPE_JSONA: + result = jsonObj.getJSONArray(fieldName); + break; + case TYPE_JSONO: + result = jsonObj.getJSONObject(fieldName); + break; + case TYPE_LONG: + result = jsonObj.getLong(fieldName); + break; + default: + result = null; + break; + } + return result; + } + } catch(JSONException e) { + LOG.error("function=getJsonFieldLong, exception: {} ", e); + return null; + } + return null; + } + + /** + * + * Check whether the Json Object is empty.
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static boolean isNullJson(JSONObject jsonObject) { + if(null == jsonObject || jsonObject.isEmpty()) { + return true; + } + return false; + } + + /** + * + * Get String value by Json.
+ * + * @param json + * @param key + * @return + * @since NFVO 0.5 + */ + public static String getStrValueByjson(JSONObject json, String key) { + JSONArray names = json.names(); + String result = null; + for(int i = 0; i < names.size(); i++) { + String nodeName = names.getString(i); + if(json.optJSONObject(nodeName) != null) { + result = getStrValueByjson(json.getJSONObject(nodeName), key); + } + if(json.optJSONArray(nodeName) != null) { + result = getStrValueByJArray(json.getJSONArray(nodeName), key); + } + if(nodeName.equals(key)) { + result = json.getString(nodeName); + break; + } + } + return result; + } + + private static String getStrValueByJArray(JSONArray json, String key) { + String result = null; + for(int i = 0; i < json.size(); i++) { + if(json.optJSONObject(i) != null) { + result = getStrValueByjson(json.getJSONObject(i), key); + } + if(json.optJSONArray(i) != null) { + result = getStrValueByJArray(json.getJSONArray(i), key); + } + } + return result; + } + + /** + * + * Get Json Value by Json object.
+ * + * @param json + * @param key + * @return + * @since NFVO 0.5 + */ + public static JSONObject getJsonValueByjson(JSONObject json, String key) { + JSONObject resultJson = new JSONObject(); + String result = getStrValueByjson(json, key); + if(null == result) { + return null; + } + resultJson.element(key, result); + return resultJson; + + } + + /** + * + * Get String Value by Json object.
+ * + * @param json + * @param parentKey + * @param key + * @return + * @since NFVO 0.5 + */ + public static String getStrValueByJson(JSONObject json, String parentKey, String key) { + if(parentKey.isEmpty()) { + return getStrValueByjson(json, key); + } + JSONObject parentJson = getJsonValueByjson(json, parentKey); + if(isNullJson(parentJson)) { + return null; + } + return getStrValueByjson(parentJson, key); + + } + + /** + * + * Get response Data.
+ * + * @param obj + * @return + * @since NFVO 0.5 + */ + public static JSONObject getResponseData(JSONObject obj) { + JSONObject result = new JSONObject(); + + Integer retCode = getJsonFieldInt(obj, ParamConstant.PARAM_RETCODE); + if(null == retCode || retCode == -1) { + return null; + } + + if(obj.optJSONObject(ParamConstant.PARAM_DATA) != null) { + result = obj.getJSONObject(ParamConstant.PARAM_DATA); + } else if(obj.optJSONArray(ParamConstant.PARAM_DATA) != null) { + result = obj.getJSONArray(ParamConstant.PARAM_DATA).getJSONObject(0); + } + if(result.isEmpty()) { + return null; + } + + if(result.containsKey(ParamConstant.PARAM_RETCODE)) { + result = getResponseData(result); + } + return result; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java new file mode 100644 index 0000000..4036de7 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtil.java @@ -0,0 +1,371 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletResponse; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.Constant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.Restful; +import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback; +import org.openo.baseservice.roa.util.restclient.RestfulFactory; +import org.openo.baseservice.roa.util.restclient.RestfulOptions; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; + +/** + * Restful Utility Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class RestfulUtil { + + public static final String TYPE_GET = "get"; + + public static final String TYPE_PUT = "put"; + + public static final String TYPE_POST = "post"; + + public static final String TYPE_DEL = "delete"; + + public static final String CONTENT_TYPE = "Content-type"; + + public static final String APPLICATION = "application/json"; + + private static final Logger LOGGER = LoggerFactory.getLogger(RestfulUtil.class); + + private static final Restful REST_CLIENT = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); + + private RestfulUtil() { + } + + /** + * Get response object.
+ * + * @param url + * @param type + * @return + * @since NFVO 0.5 + */ + public static JSONObject getResponseObj(String url, String type) { + return getResponseObj(url, new RestfulParametes(), type); + } + + /** + * Get response object.
+ * + * @param url + * @param parametes + * @param type + * @return + * @since NFVO 0.5 + */ + public static JSONObject getResponseObj(String url, RestfulParametes parametes, String type) { + try { + String content = RestfulUtil.getResponseContent(url, parametes, null, type); + LOGGER.error("function=getResponseObj, content : {}", content); + if(StringUtils.isEmpty(content)) { + return null; + } + return JSONObject.fromObject(content); + } catch(JSONException e) { + LOGGER.error("function=getResponseObj, exception : {}", e); + return null; + } + } + + /** + * Get response content.
+ * + * @param url + * @param restParametes + * @param type + * @return + * @since NFVO 0.5 + */ + public static String getResponseContent(String url, RestfulParametes restParametes, String type) { + return getResponseContent(url, restParametes, null, type); + } + + /** + * Get response map.
+ * + * @param url + * @param restParametes + * @param opt + * @param type + * @return + * @since NFVO 0.5 + */ + public static Map getResponseMap(String url, RestfulParametes restParametes, RestfulOptions opt, + String type) { + RestfulResponse response = restfulResponse(url, restParametes, opt, type); + return getResponseMap(response); + } + + /** + * Get response content map.
+ * + * @param url + * @param type + * @return + * @since NFVO 0.5 + */ + public static Map getResponseContentMap(String url, String type) { + RestfulResponse response = restfulResponse(url, new RestfulParametes(), null, type); + return getResponseMap(response); + } + + private static Map getResponseMap(RestfulResponse response) { + Map resMap = new HashMap<>(10); + if(null != response) { + resMap.put(Constant.RESPONSE_CONTENT, response.getResponseContent()); + resMap.put(Constant.STATUS_CODE, response.getStatus()); + } + return resMap; + } + + /** + * Get response content.
+ * + * @param url + * @param restParametes + * @param opt + * @param type + * @return + * @since NFVO 0.5 + */ + public static String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt, + String type) { + String responseContent = null; + RestfulResponse rsp = restfulResponse(url, restParametes, opt, type); + if(rsp != null) { + int httpStatus = rsp.getStatus(); + LOGGER.warn("function=getResponseContent, get response httpStatusCode : {} ", httpStatus); + if(httpStatus < HttpServletResponse.SC_BAD_REQUEST && httpStatus > 0) { + responseContent = rsp.getResponseContent(); + LOGGER.warn("function=getResponseContent, get response data success!responseContent={}", + responseContent); + } + } + return responseContent; + } + + /** + * Get restful response.
+ * + * @param url + * @param restParametes + * @param type + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRestfulResponse(String url, RestfulParametes restParametes, String type) { + return restfulResponse(url, restParametes, null, type); + } + + private static RestfulResponse restfulResponse(String url, RestfulParametes restParametes, RestfulOptions opt, + String type) { + RestfulResponse rsp = new RestfulResponse(); + try { + + if(REST_CLIENT != null) { + if(TYPE_GET.equals(type)) { + rsp = REST_CLIENT.get(url, restParametes, opt); + } else if(TYPE_POST.equals(type)) { + rsp = REST_CLIENT.post(url, restParametes, opt); + } else if(TYPE_PUT.equals(type)) { + rsp = REST_CLIENT.put(url, restParametes, opt); + } else if(TYPE_DEL.equals(type)) { + rsp = REST_CLIENT.delete(url, restParametes, opt); + } + } + } catch(ServiceException e) { + LOGGER.error("function=restfulResponse, get restful response catch exception {} ", e); + } + LOGGER.warn("function=restfulResponse, response status is {} ", rsp.getStatus()); + return rsp; + } + + /** + * encapsulate the java reflect exception.
+ * + * @param methodName, Restful's method. + * @param objects, method param array. + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRestRes(String methodName, Object... objects) { + try { + if(objects == null || REST_CLIENT == null) { + return null; + } + + Class[] classes = new Class[objects.length]; + for(int i = 0; i < objects.length; i++) { + classes[i] = objects[i].getClass(); + } + if(methodName.startsWith("async")) { + classes[classes.length - 1] = RestfulAsyncCallback.class; + } + + Class rtType = methodName.startsWith("async") ? void.class : RestfulResponse.class; + MethodType mt = MethodType.methodType(rtType, classes); + Object result = MethodHandles.lookup().findVirtual(REST_CLIENT.getClass(), methodName, mt) + .bindTo(REST_CLIENT).invokeWithArguments(objects); + if(result != null) { + return (RestfulResponse)result; + } + LOGGER.warn("function=getRestRes, msg: invoke Restful async {} method which return type is Void.", + methodName); + return null; + } catch(ReflectiveOperationException e) { + LOGGER.error("function=getRestRes, msg=error occurs, e={}.", e); + } catch(Throwable e) {// NOSONAR + LOGGER.error("function=getRestRes, msg=Throwable, e={}.", e); + try { + throw (ServiceException)new ServiceException().initCause(e.getCause()); + } catch(ServiceException se) { + LOGGER.error("function=getRestRes, msg=ServiceException occurs, e={}.", se); + } + } + return null; + } + + /** + * Get response.
+ * + * @param restParametes + * @param url + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + public static JSONArray getResponseRes(RestfulParametes restParametes, String url) throws ServiceException { + String result = getResponseContent(url, restParametes, RestfulUtil.TYPE_GET); + if(null == result || result.isEmpty()) { + LOGGER.error("result from url:" + url + " result:" + result); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result")); + } + + JSONArray rsArray = null; + try { + JSONObject rsJson = JSONObject.fromObject(result); + rsArray = rsJson.getJSONArray(ParamConstant.PARAM_DATA); + } catch(JSONException e) { + LOGGER.error("getResources error:" + e); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result")); + } + return rsArray; + } + + /** + * Get response.
+ * + * @param restParametes + * @param url + * @param iResName + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + public static JSONArray getResponseRes(RestfulParametes restParametes, String url, String iResName) + throws ServiceException { + String result = getResponseContent(url, restParametes, RestfulUtil.TYPE_GET); + if(null == result || result.isEmpty()) { + LOGGER.error("result from url:" + url + " result:" + result); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result")); + } + + JSONArray rsArray = null; + try { + JSONObject rsJson = JSONObject.fromObject(result); + rsArray = rsJson.getJSONArray(iResName); + String vimId = rsJson.getString(ParamConstant.PARAM_VIMID); + String vimName = rsJson.getString(ParamConstant.PARAM_VIMNAME); + for(int i = 0; i < rsArray.size(); i++) { + JSONObject jsonObj = rsArray.getJSONObject(i); + jsonObj.put(ParamConstant.PARAM_VIMID, vimId); + jsonObj.put(ParamConstant.PARAM_VIMNAME, vimName); + } + } catch(JSONException e) { + LOGGER.error("getResources error:" + e); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result")); + } + return rsArray; + } + + /** + *
+ * + * @param paramsMap + * @param params + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRemoteResponse(Map paramsMap, String params) { + String url = paramsMap.get("url"); + String methodType = paramsMap.get("methodType"); + + RestfulResponse rsp = null; + Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); + try { + + RestfulParametes restfulParametes = new RestfulParametes(); + Map headerMap = new HashMap<>(3); + headerMap.put(CONTENT_TYPE, APPLICATION); + restfulParametes.setHeaderMap(headerMap); + restfulParametes.setRawData(params); + + if(rest != null) { + if(TYPE_GET.equalsIgnoreCase(methodType)) { + rsp = rest.get(url, restfulParametes); + } else if(TYPE_POST.equalsIgnoreCase(methodType)) { + rsp = rest.post(url, restfulParametes); + } else if(TYPE_PUT.equalsIgnoreCase(methodType)) { + rsp = rest.put(url, restfulParametes); + } else if(TYPE_DEL.equalsIgnoreCase(methodType)) { + rsp = rest.delete(url, restfulParametes); + } + } + } catch(ServiceException e) { + LOGGER.error("function=getRemoteResponse, get restful response catch exception {}", e); + } + return rsp; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java new file mode 100644 index 0000000..a415a71 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtil.java @@ -0,0 +1,215 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util; + +import java.math.BigDecimal; +import java.text.DecimalFormat; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * String Utility Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public final class StringUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(StringUtil.class); + + private StringUtil() { + } + + /** + * + * Check whether thestring is valid.
+ * + * @param str + * @return + * @since NFVO 0.5 + */ + public static boolean isValidString(String str) { + if(null == str || str.isEmpty()) { + return false; + } + return true; + } + + /** + * + * Check whether the value is larger than zero.
+ * + * @param strs + * @return + * @since NFVO 0.5 + */ + public static boolean isAnyLargeThanZero(String... strs) { + for(String str : strs) { + if(!StringUtils.isEmpty(str) && Float.parseFloat(str) > 0) { + LOGGER.info("isAnyLargeThanZero : {} is > 0", str); + return true; + } + } + return false; + } + + /** + * + * Check whether the value is Integer.
+ * + * @param strs + * @return + * @since NFVO 0.5 + */ + public static boolean isInteger(String... strs) { + try { + for(String str : strs) { + if(!StringUtils.isEmpty(str)) { + int value = Integer.parseInt(str); + if(value < 0) { + return false; + } + } + } + } catch(NumberFormatException e) { + return false; + } + return true; + } + + /** + * + * Check whether the input is Numeric.
+ * + * @param strs + * @return + * @since NFVO 0.5 + */ + public static boolean isNumeric(String... strs) { + try { + for(String str : strs) { + if(!StringUtils.isEmpty(str)) { + float value = Float.parseFloat(str); + if(value < 0) { + return false; + } + } + } + } catch(NumberFormatException e) { + return false; + } + return true; + } + + /** + * + * Compare zero by float.
+ * + * @param tatol + * @param used + * @param drTotal + * @return + * @since NFVO 0.5 + */ + public static boolean compareZeroByFloat(String tatol, String used, String drTotal) { + Float ftotal = (float)0; + Float fused = (float)0; + Float fdrTotal = (float)0; + if(!StringUtils.isEmpty(tatol)) { + ftotal = new Float(tatol); + } + if(!StringUtils.isEmpty(used)) { + fused = new Float(used); + } + if(!StringUtils.isEmpty(drTotal)) { + fdrTotal = new Float(drTotal); + } + if(ftotal < fused + fdrTotal) { + return false; + } + + return true; + } + + /** + * + * Compare zero by integer.
+ * + * @param tatol + * @param used + * @param drTotal + * @return + * @since NFVO 0.5 + */ + public static boolean compareZeroByInteger(String tatol, String used, String drTotal) { + Integer ftotal = (int)0; + Integer fused = (int)0; + Integer fdrTotal = (int)0; + if(!StringUtils.isEmpty(tatol)) { + ftotal = Integer.valueOf(tatol); + } + if(!StringUtils.isEmpty(used)) { + fused = Integer.valueOf(used); + } + if(!StringUtils.isEmpty(drTotal)) { + fdrTotal = Integer.valueOf(drTotal); + } + if(ftotal < fused + fdrTotal) { + return false; + } + return true; + } + + /** + * + * Number format.
+ * + * @param data + * @return + * @since NFVO 0.5 + */ + public static String numFormat(String data) { + if(null != data && !("".equals(data))) { + BigDecimal var = new BigDecimal(data); + DecimalFormat formatWithoutFraction = new DecimalFormat("############"); + DecimalFormat formatWithFraction = new DecimalFormat("############.############"); + if(new BigDecimal(var.intValue()).compareTo(var) == 0) { + return formatWithoutFraction.format(var); + } + return formatWithFraction.format(var); + } + return null; + } + + /** + * + *
+ * + * @param inputStr + * @return + * @since NFVO 0.5 + */ + public static boolean checkXss(String inputStr) { + return inputStr.matches("[A-Za-z0-9_.']+"); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java new file mode 100644 index 0000000..8ae59b1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtil.java @@ -0,0 +1,129 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util.request; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONException; +import net.sf.json.JSONObject; + +/** + *
+ *

+ * Utility used for request + *

+ * + * @author + * @version NFVO 0.5 2016-3-17 + */ +public final class RequestUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(RequestUtil.class); + + /** + * Constructor
+ *

+ *

+ * + * @since NFVO 0.5 + */ + private RequestUtil() { + } + + /** + * Get context string from http context + * + * @param context + * http context + * @return the needed string in http context + */ + public static String getStringRequestBody(HttpServletRequest context) { + try { + InputStream input = context.getInputStream(); + return IOUtils.toString(input); + } catch(IOException e) { + LOGGER.error("function=getStringRequestBody, get httpservletrequest body exception: {}", e); + return null; + } + } + + /** + * Get json parameter from http context + * + * @param context + * http context + * @return JSONObject + */ + public static JSONObject getJsonRequestBody(HttpServletRequest context) { + try { + String bodyStr = getStringRequestBody(context); + return JSONObject.fromObject(bodyStr); + } catch(JSONException e) { + LOGGER.error("function=getJsonRequestBody, maybe request param is not a jsonobject exception: {}", e); + return null; + } + } + + /** + * Get the body of all request in json format
+ * + * @param context + * The http context + * @return JSONObject The body of all request in json format + * @since NFVO 0.5 + */ + public static JSONObject getAllJsonRequestBody(HttpServletRequest context) { + JSONObject requestBody = getJsonRequestBody(context); + if(null == requestBody) { + LOGGER.error("get httpservletrequest body exception"); + requestBody = new JSONObject(); + } + LOGGER.warn("function=getAllJsonRequestBody; msg=get request data is:[{}]", requestBody.toString()); + requestBody.put("header", getContextHeader(context)); + return requestBody; + } + + /** + * Get the context header
+ * + * @param context + * The http context + * @return Map context header + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + private static Map getContextHeader(HttpServletRequest context) { + Map header = new HashMap(); + Enumeration headerNames = context.getHeaderNames(); + while(headerNames.hasMoreElements()) { + String headerName = headerNames.nextElement(); + String value = context.getHeader(headerName); + header.put(headerName, value); + } + return header; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java new file mode 100644 index 0000000..6658b29 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtil.java @@ -0,0 +1,133 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util.response; + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; +import java.util.Map.Entry; + +import javax.servlet.http.HttpServletRequest; + +import net.sf.json.JSONObject; + +/** + * + * Response utility class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public final class ResponseUtil { + + private ResponseUtil() { + } + + /** + * Roa request common return function, default return code 200
+ * + * @param retCode + * The request return code + * @param msg + * The request message + * @return JSONObject The response for http request + * @since NFVO 0.5 + */ + public static JSONObject genHttpResponse(int retCode, String msg) { + return genHttpResponse(null, createCodeMap(-1, retCode), msg, null); + } + + /** + * Roa request common return function, default return code 200
+ * + * @param retCode + * The request return code + * @param msg + * The request message + * @param map + * Other request info of this request + * @return JSONObject The response for http request + * @since NFVO 0.5 + */ + public static JSONObject genHttpResponse(int retCode, String msg, Map map) { + return genHttpResponse(null, createCodeMap(-1, retCode), msg, map); + } + + /** + * Roa request common return method
+ * + * @param context + * The http request context + * @param httpStatusCode + * The http response code + * @param retCode + * The http request return code + * @param msg + * The message of request + * @return JSONObject The response for http request + * @since NFVO 0.5 + */ + public static JSONObject genHttpResponse(HttpServletRequest context, int httpStatusCode, int retCode, String msg) { + return genHttpResponse(context, createCodeMap(httpStatusCode, retCode), msg, null); + } + + /** + * + * Roa request common return method.
+ * + * @param context, The http request context + * @param codeMap + * @param msg, The message of request + * @param map, Other message of request + * @return + * @since NFVO 0.5 + */ + public static JSONObject genHttpResponse(HttpServletRequest context, Map codeMap, String msg, + Map map) { + JSONObject object = new JSONObject(); + + object.put("msg", msg); + if(null != map) { + Iterator> ite = map.entrySet().iterator(); + if(ite.hasNext()) { + Map.Entry entry = ite.next(); + object.put(entry.getKey(), entry.getValue().toString()); + } + } + return object; + } + + /** + * Create code map to maintenance the relationship between return code and + * http status code
+ * + * @param httpStatusCode + * The http response code + * @param retCode + * The http request return code + * @return Map + * @since NFVO 0.5 + */ + private static Map createCodeMap(int httpStatusCode, int retCode) { + Map codeMap = new HashMap<>(5); + codeMap.put("httpStatusCode", httpStatusCode); + codeMap.put("retCode", retCode); + return codeMap; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java new file mode 100644 index 0000000..a54891b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtil.java @@ -0,0 +1,113 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util.response; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ResponseConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ * Utility for generate Roa get/add/update/delete method status + *

+ * + * @author + * @version NFVO 0.5 2016-3-17 + */ +public final class RoaResponseUtil { + + private static final Logger LOGGER = LoggerFactory.getLogger(RoaResponseUtil.class); + + private RoaResponseUtil() { + + } + + /** + * Generate get method response
+ * + * @param list + * The basic response for get method + * @return JSONObject The response for http request + * @since NFVO 0.5 + */ + public static JSONObject get(List list) { + Map map = new HashMap(10); + map.put(ParamConstant.PARAM_DATA, list); + LOGGER.info("function=get; msg=get map:{}", map.toString()); + return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.QUERY_SUCESS_MSG, map); + } + + /** + * Generate different response by different parameter for add method
+ * + * @param result + * The result + * @return JSONObject + * @since NFVO 0.5 + */ + public static JSONObject add(int result) { + LOGGER.info("function=add; msg=add result{}", result); + if(result <= 0) { + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.ADD_FAIL_MSG); + } else { + return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.ADD_SUCESS_MSG); + } + } + + /** + * Generate different response by different parameter for update method
+ * + * @param result + * The result + * @return JSONObject The response for http request + * @since NFVO 0.5 + */ + public static JSONObject update(int result) { + LOGGER.info("function=update; msg=update result{}", result); + if(result <= 0) { + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.MOD_FAIL_MSG); + } else { + return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.MOD_SUCESS_MSG); + } + } + + /** + * Generate different response by different parameter for delete method
+ * + * @param result + * The result + * @return delete JSONObject of the response for http request + * @since NFVO 0.5 + */ + public static JSONObject delete(int result) { + LOGGER.info("function=delete; msg=delete result{}", result); + if(result <= 0) { + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, ResponseConstant.DEL_FAIL_MSG); + } else { + return ResponseUtil.genHttpResponse(HttpConstant.OK_CODE, ResponseConstant.DEL_SUCESS_MSG); + } + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/activator/ROAResmgrServicePostProcessor.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/activator/ROAResmgrServicePostProcessor.java new file mode 100644 index 0000000..2525064 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/activator/ROAResmgrServicePostProcessor.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.activator; + +import org.onap.vfc.nfvo.resmanagement.service.adapter.inf.IResmgrAdapterMgrService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 22, 2016 + */ +public class ROAResmgrServicePostProcessor implements DestructionAwareBeanPostProcessor { + + private static final Logger LOG = LoggerFactory.getLogger(ROAResmgrServicePostProcessor.class); + + @Override + public Object postProcessAfterInitialization(Object bean, String name) throws BeansException { + if(bean instanceof IResmgrAdapterMgrService) { + LOG.warn("Register to Microservice BUS!"); + IResmgrAdapterMgrService resmgrAdapterSvc = (IResmgrAdapterMgrService)bean; + resmgrAdapterSvc.register(); + } + + return bean; + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException { + // TODO Auto-generated method stub + return bean; + } + + @Override + public void postProcessBeforeDestruction(Object bean, String name) throws BeansException { + // TODO Auto-generated method stub + + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManager.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManager.java new file mode 100644 index 0000000..4054a62 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManager.java @@ -0,0 +1,111 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.adapter.impl; + +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.common.constant.Constant; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.onap.vfc.nfvo.resmanagement.service.adapter.inf.IResmgrAdapter2MSBManager; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 22, 2016 + */ +public class ResmgrAdapter2MSBManager implements IResmgrAdapter2MSBManager { + + private static final Logger LOG = LoggerFactory.getLogger(ResmgrAdapter2MSBManager.class); + + @Override + public JSONObject registerResmgr(Map paramsMap, JSONObject driverInfo) { + JSONObject resultObj = new JSONObject(); + + RestfulResponse rsp = RestfulUtil.getRemoteResponse(paramsMap, driverInfo.toString()); + if(null == rsp) { + LOG.error("function=registerResmgr, RestfulResponse is null"); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.ERROR_CODE); + return resultObj; + } + LOG.warn("function=registerResmgr, status={}, content={}.", rsp.getStatus(), rsp.getResponseContent()); + String resultCreate = rsp.getResponseContent(); + + if(rsp.getStatus() == HttpConstant.HTTP_CREATED) { + LOG.warn("function=registerResmgr, msg= status={}, result={}.", rsp.getStatus(), resultCreate); + resultObj = JSONObject.fromObject(resultCreate); + resultObj.put("retCode", HttpConstant.HTTP_CREATED); + return resultObj; + } else if(rsp.getStatus() == HttpConstant.HTTP_INVALID_PARAMETERS) { + LOG.error("function=registerResmgr, msg=MSB return fail,invalid parameters,status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "MSB return fail,invalid parameters."); + } else if(rsp.getStatus() == HttpConstant.HTTP_INNERERROR_CODE) { + LOG.error("function=registerResmgr, msg=MSB return fail,internal system error,status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "MSB return fail,internal system error."); + } + resultObj.put("retCode", Constant.ERROR_CODE); + return resultObj; + } + + @Override + public JSONObject unregisterResmgr(Map paramsMap) { + JSONObject resultObj = new JSONObject(); + + RestfulResponse rsp = RestfulUtil.getRemoteResponse(paramsMap, ""); + if(null == rsp) { + LOG.error("function=unregisterResmgr, RestfulResponse is null"); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.ERROR_CODE); + return resultObj; + } + String resultCreate = rsp.getResponseContent(); + + if(rsp.getStatus() == HttpConstant.HTTP_NOCONTENT) { + LOG.warn("function=unregisterResmgr, msg= status={}, result={}.", rsp.getStatus(), resultCreate); + resultObj = JSONObject.fromObject(resultCreate); + resultObj.put("retCode", HttpConstant.HTTP_NOCONTENT); + return resultObj; + } else if(rsp.getStatus() == HttpConstant.HTTP_NOTFOUND_CODE) { + LOG.error( + "function=unregisterResmgr, msg=MSB return fail,can't find the service instance.status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "MSB return fail,can't find the service instance."); + } else if(rsp.getStatus() == HttpConstant.HTTP_INVALID_PARAMETERS) { + LOG.error("function=unregisterResmgr, msg=MSB return fail,invalid parameters,status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "MSB return fail,invalid parameters."); + } else if(rsp.getStatus() == HttpConstant.HTTP_INNERERROR_CODE) { + LOG.error("function=unregisterResmgr, msg=MSB return fail,internal system error,status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "MSB return fail,internal system error."); + } + resultObj.put("retCode", Constant.ERROR_CODE); + return resultObj; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java new file mode 100644 index 0000000..f403aa0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java @@ -0,0 +1,185 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.adapter.impl; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executors; + +import org.onap.vfc.nfvo.resmanagement.common.constant.Constant; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.service.adapter.inf.IResmgrAdapter2MSBManager; +import org.onap.vfc.nfvo.resmanagement.service.adapter.inf.IResmgrAdapterMgrService; +import org.openo.baseservice.util.impl.SystemEnvVariablesFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 22, 2016 + */ +@Service +public class ResmgrAdapterMgrService implements IResmgrAdapterMgrService { + + private static final Logger LOG = LoggerFactory.getLogger(ResmgrAdapterMgrService.class); + + public static final String RESMGRADAPTERINFO = "resmgradapterinfo.json"; + + @Override + public void register() { + // set BUS URL and mothedtype + Map paramsMap = new HashMap<>(); + paramsMap.put("url", UrlConstant.REST_MSB_REGISTER); + paramsMap.put("methodType", ParamConstant.PARAM_POST); + + // get resmgr info and raise registration + try { + String resmgrInfo = readVimAdapterInfoFromJson(); + if(!"".equals(resmgrInfo)) { + JSONObject adapterObject = JSONObject.fromObject(resmgrInfo); + RegisterResmgrThread resmgrThread = new RegisterResmgrThread(paramsMap, adapterObject); + Executors.newSingleThreadExecutor().submit(resmgrThread); + } else { + LOG.error("Resmgr info is null,please check!"); + } + + } catch(IOException e) { + LOG.error("Failed to read Resmgr info! " + e.getMessage(), e); + } + + } + + /** + * Retrieve VIM driver information. + * + * @return + * @throws IOException + */ + public static String readVimAdapterInfoFromJson() throws IOException { + InputStream ins = null; + BufferedInputStream bins = null; + String fileContent = ""; + + String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator") + + "etc" + System.getProperty("file.separator") + "adapterInfo" + System.getProperty("file.separator") + + RESMGRADAPTERINFO; + + try { + ins = new FileInputStream(fileName); + bins = new BufferedInputStream(ins); + + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); + + if(num > 0) { + fileContent = new String(contentByte); + } + } catch(FileNotFoundException e) { + LOG.error(fileName + "is not found!", e); + } finally { + if(ins != null) { + ins.close(); + } + if(bins != null) { + bins.close(); + } + } + + return fileContent; + } + + private static class RegisterResmgrThread implements Runnable { + + // Thread lock Object + private final Object lockObject = new Object(); + + private IResmgrAdapter2MSBManager adapter2MSBMgr = new ResmgrAdapter2MSBManager(); + + // url and mothedtype + private Map paramsMap; + + // driver body + private JSONObject adapterInfo; + + public RegisterResmgrThread(Map paramsMap, JSONObject adapterInfo) { + this.paramsMap = paramsMap; + this.adapterInfo = adapterInfo; + } + + @Override + public void run() { + LOG.info("start register resmgr", RegisterResmgrThread.class); + + if(paramsMap == null || adapterInfo == null) { + LOG.error("parameter is null,please check!", RegisterResmgrThread.class); + return; + } + + // catch Runtime Exception + try { + sendRequest(paramsMap, adapterInfo); + } catch(RuntimeException e) { + LOG.error(e.getMessage(), e); + } + + } + + private void sendRequest(Map paramsMap, JSONObject driverInfo) { + JSONObject resultObj = adapter2MSBMgr.registerResmgr(paramsMap, driverInfo); + + if(Integer.valueOf(resultObj.get("retCode").toString()) == HttpConstant.HTTP_CREATED) { + LOG.info("Resmgr has now Successfully Registered to the Microservice BUS!"); + } else { + LOG.error("Resmgr failed to Register to the Microservice BUS! Reason:" + + resultObj.get("reason").toString() + " retCode:" + resultObj.get("retCode").toString()); + + // if registration fails,wait one minute and try again + try { + synchronized(lockObject) { + lockObject.wait(Constant.REPEAT_REG_TIME); + } + } catch(InterruptedException e) { + LOG.error(e.getMessage(), e); + } + + sendRequest(this.paramsMap, this.adapterInfo); + } + + } + + } + + @Override + public void unregister() { + // unregister + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/inf/IResmgrAdapter2MSBManager.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/inf/IResmgrAdapter2MSBManager.java new file mode 100644 index 0000000..509c9af --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/inf/IResmgrAdapter2MSBManager.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.adapter.inf; + +import java.util.Map; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 22, 2016 + */ +public interface IResmgrAdapter2MSBManager { + + /** + *
+ * + * @param paramsMap + * @param driverInfo + * @return + * @since NFVO 0.5 + */ + JSONObject registerResmgr(Map paramsMap, JSONObject driverInfo); + + /** + *
+ * + * @param paramsMap + * @return + * @since NFVO 0.5 + */ + JSONObject unregisterResmgr(Map paramsMap); + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/inf/IResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/inf/IResmgrAdapterMgrService.java new file mode 100644 index 0000000..4e4d035 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/adapter/inf/IResmgrAdapterMgrService.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.adapter.inf; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 22, 2016 + */ +public interface IResmgrAdapterMgrService { + + /** + * Resmgr register interface. + */ + void register(); + + /** + * Resmgr unregister interface. + */ + void unregister(); + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/HostImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/HostImpl.java new file mode 100644 index 0000000..f3afa9b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/HostImpl.java @@ -0,0 +1,80 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Host; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.HostBusiness; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + * + * Host implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class HostImpl implements Host { + + private HostBusiness hostBusiness; + + @Override + public int add(JSONObject jsonObject) throws ServiceException { + return hostBusiness.addHost(HostEntity.toEntity(jsonObject)); + } + + @Override + public int update(JSONObject jsonObject) throws ServiceException { + return hostBusiness.updateHostSelective(HostEntity.toEntity(jsonObject)); + } + + @Override + public int update(HostEntity portEntity) throws ServiceException { + return hostBusiness.updateHostSelective(portEntity); + } + + @Override + public int delete(String id) throws ServiceException { + return hostBusiness.deleteHost(id); + } + + @Override + public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException { + return hostBusiness.updateHostByVimId(HostEntity.toEntity(jsonObject)); + } + + @Override + public int deleteResByVimId(String vimId) throws ServiceException { + return hostBusiness.deleteHostByVimId(vimId); + } + + @Override + public List getList(Map condition) throws ServiceException { + return hostBusiness.getHosts(condition); + } + + public void setHostBusiness(HostBusiness hostBusiness) { + this.hostBusiness = hostBusiness; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/LocationImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/LocationImpl.java new file mode 100644 index 0000000..a3fffdb --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/LocationImpl.java @@ -0,0 +1,186 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Location; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.LocationBusiness; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * Location Implementation Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class LocationImpl implements Location { + + private LocationBusiness locationBusiness; + + private Sites sites; + + private static final Logger LOGGER = LoggerFactory.getLogger(LocationImpl.class); + + @Override + public int add(JSONObject jsonObject) throws ServiceException { + return locationBusiness.addLocation(LocationEntity.toEntity(jsonObject)); + } + + @Override + public int update(JSONObject jsonObject) throws ServiceException { + return locationBusiness.updateLocationSelective(LocationEntity.toEntity(jsonObject)); + } + + @Override + public int delete(String location) throws ServiceException { + return locationBusiness.deleteLocation(location); + } + + @Override + public Map get(String id) throws ServiceException { + Map map = new HashMap<>(); + map.put(ParamConstant.PARAM_ID, id); + List sodores = locationBusiness.getLocations(map); + map.clear(); + map.put(ParamConstant.PARAM_DATA, sodores); + return map; + } + + @Override + public List get(Map condition) throws ServiceException { + return locationBusiness.getLocations(condition); + } + + @Override + public List getCountry() throws ServiceException { + return locationBusiness.getCountry(); + } + + @Override + public List getCloudservice() throws ServiceException { + LOGGER.info("get cloud service from external system"); + JSONArray vims = VimUtil.getVims(); + LOGGER.info("vims: " + vims.toString()); + List cloudService = new ArrayList<>(); + for(int i = 0; i < vims.size(); i++) { + String vimName = vims.getJSONObject(i).getString("name"); + cloudService.add(vimName); + } + return cloudService; + } + + @Override + public List getLocationByCountry(Map condition) throws ServiceException { + return locationBusiness.getLocationByCountry(condition); + } + + @Override + public LocationEntity getLocation(Map condition) throws ServiceException { + List locationlist = locationBusiness.getLocations(condition); + if(null == locationlist || locationlist.isEmpty()) { + return null; + } + return locationlist.get(0); + } + + @Override + public List getLocationInfo(List locationInfo) throws ServiceException { + ArrayList newSites = new ArrayList<>(); + Map condition = new HashMap<>(); + for(int i = 0; i < locationInfo.size(); i++) { + LocationEntity locationEntity = locationInfo.get(i); + String latitude = locationEntity.getLatitude(); + String longitude = locationEntity.getLongitude(); + String locatSite = locationEntity.getLocation(); + condition.put(ParamConstant.PARAM_LOCATION, locatSite); + LOGGER.info("LocationRoa::getLocation condition:{}", condition); + List sitesEntity = sites.getList(condition); + LOGGER.info("LocationRoa::getLocation sitesEntity:{}", sitesEntity); + if(null != sitesEntity && !sitesEntity.isEmpty()) { + for(SitesEntity entity : sitesEntity) { + JSONObject site = JSONObject.fromObject(entity.toString()); + JSONObject resTotalJo = site.getJSONObject("total"); + JSONObject resUsedlJo = site.getJSONObject("used"); + JSONObject ressiteJo = computingSite(resTotalJo, resUsedlJo); + site.element("latitude", latitude); + site.element("longitude", longitude); + site.element("siteDetail", ressiteJo); + LOGGER.info("LocationRoa::getLocation latitude:{}, longitude:{}", latitude, longitude); + LOGGER.info("LocationRoa::getLocation site:{}", site); + newSites.add(site); + } + } + } + return newSites; + } + + /** + * Computing site.
+ * + * @param total + * @param used + * @return + * @since NFVO 0.5 + */ + public JSONObject computingSite(JSONObject total, JSONObject used) { + String vcpus = JsonUtil.getJsonFieldStr(total, ParamConstant.PARAM_VCPUS); + String memorys = JsonUtil.getJsonFieldStr(total, ParamConstant.PARAM_MEMORY); + String disks = JsonUtil.getJsonFieldStr(total, ParamConstant.PARAM_DISK); + String vcpusused = JsonUtil.getJsonFieldStr(used, ParamConstant.PARAM_VCPUS); + String memoryused = JsonUtil.getJsonFieldStr(used, ParamConstant.PARAM_MEMORY); + String diskused = JsonUtil.getJsonFieldStr(used, ParamConstant.PARAM_DISK); + float cpu = Float.parseFloat(vcpusused) / Float.parseFloat(vcpus); + float memory = Float.parseFloat(memoryused) / Integer.parseInt(memorys); + float disk = Float.parseFloat(diskused) / Float.parseFloat(disks); + JSONObject resTotalJo = new JSONObject(); + resTotalJo.put(ParamConstant.PARAM_VCPUS, String.valueOf(Math.round(cpu * 100)) + "%"); + resTotalJo.put(ParamConstant.PARAM_MEMORY, String.valueOf(Math.round(memory * 100)) + "%"); + resTotalJo.put(ParamConstant.PARAM_DISK, String.valueOf(Math.round(disk * 100)) + "%"); + + return resTotalJo; + } + + public LocationBusiness getLocationBusiness() { + return locationBusiness; + } + + public void setLocationBusiness(LocationBusiness locationBusiness) { + this.locationBusiness = locationBusiness; + } + + public void setSites(Sites sites) { + this.sites = sites; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/NetworkImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/NetworkImpl.java new file mode 100644 index 0000000..8ac3b95 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/NetworkImpl.java @@ -0,0 +1,101 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Network; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.NetworkBusiness; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * Network implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class NetworkImpl implements Network { + + private static final Logger LOGGER = LoggerFactory.getLogger(NetworkImpl.class); + + private NetworkBusiness networkBusiness; + + @Override + public int add(JSONObject jsonObject) throws ServiceException { + LOGGER.warn("function=addPort; jsonObject={}", jsonObject); + JSONObject networkObj = dataParse(jsonObject); + return networkBusiness.addNetwork(NetworkEntity.toEntity(networkObj)); + } + + private JSONObject dataParse(JSONObject jsonObject) { + JSONObject portObj = new JSONObject(); + portObj.put("id", JsonUtil.getJsonFieldStr(jsonObject, "id")); + portObj.put("name", JsonUtil.getJsonFieldStr(jsonObject, "name")); + portObj.put("status", JsonUtil.getJsonFieldStr(jsonObject, "status")); + portObj.put("tenantId", JsonUtil.getJsonFieldStr(jsonObject, "tenant_id")); + portObj.put("vimId", JsonUtil.getJsonFieldStr(jsonObject, "vimId")); + portObj.put("vimName", JsonUtil.getJsonFieldStr(jsonObject, "vimName")); + portObj.put("physicalNetwork", JsonUtil.getJsonFieldStr(jsonObject, "physicalNetwork")); + portObj.put("networkType", JsonUtil.getJsonFieldStr(jsonObject, "networkType")); + portObj.put("segmentationId", JsonUtil.getJsonFieldStr(jsonObject, "segmentationId")); + return portObj; + } + + @Override + public int add(NetworkEntity entity) throws ServiceException { + return networkBusiness.addNetwork(entity); + } + + @Override + public int update(JSONObject jsonObject) throws ServiceException { + return networkBusiness.updateNetworkSelective(NetworkEntity.toEntity(jsonObject)); + } + + @Override + public int delete(String id) throws ServiceException { + return networkBusiness.deleteNetwork(id); + } + + @Override + public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException { + return networkBusiness.updateNetworkByVimId(NetworkEntity.toEntity(jsonObject)); + } + + @Override + public List getList(Map condition) throws ServiceException { + return networkBusiness.getNetworks(condition); + } + + @Override + public int deleteResByVimId(String vimId) throws ServiceException { + return networkBusiness.deleteNetworkByVimId(vimId); + } + + public void setNetworkBusiness(NetworkBusiness networkBusiness) { + this.networkBusiness = networkBusiness; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/PortImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/PortImpl.java new file mode 100644 index 0000000..deec19d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/PortImpl.java @@ -0,0 +1,103 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Port; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.PortBusiness; +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * Port implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class PortImpl implements Port { + + private static final Logger LOGGER = LoggerFactory.getLogger(PortImpl.class); + + private PortBusiness portBusiness; + + @Override + public int add(JSONObject jsonObject) throws ServiceException { + LOGGER.warn("function=addPort; jsonObject={}", jsonObject); + JSONObject portObj = dataParse(jsonObject); + return portBusiness.addPort(PortEntity.toEntity(portObj)); + } + + private JSONObject dataParse(JSONObject jsonObject) { + JSONObject portObj = new JSONObject(); + portObj.put("id", JsonUtil.getJsonFieldStr(jsonObject, "id")); + portObj.put("name", JsonUtil.getJsonFieldStr(jsonObject, "name")); + portObj.put("networkId", JsonUtil.getJsonFieldStr(jsonObject, "networkId")); + portObj.put("status", JsonUtil.getJsonFieldStr(jsonObject, "status")); + portObj.put("tenantId", JsonUtil.getJsonFieldStr(jsonObject, "tenant_id")); + portObj.put("vimId", JsonUtil.getJsonFieldStr(jsonObject, "vimId")); + portObj.put("vimName", JsonUtil.getJsonFieldStr(jsonObject, "vimName")); + return portObj; + } + + @Override + public int add(PortEntity portEntity) throws ServiceException { + return portBusiness.addPort(portEntity); + } + + @Override + public int update(JSONObject jsonObject) throws ServiceException { + return portBusiness.updatePortSelective(PortEntity.toEntity(jsonObject)); + } + + @Override + public int update(PortEntity portEntity) throws ServiceException { + return portBusiness.updatePortSelective(portEntity); + } + + @Override + public int delete(String id) throws ServiceException { + return portBusiness.deletePort(id); + } + + @Override + public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException { + return portBusiness.updatePortByVimId(PortEntity.toEntity(jsonObject)); + } + + @Override + public int deleteResByVimId(String vimId) throws ServiceException { + return portBusiness.deletePortByVimId(vimId); + } + + @Override + public List getList(Map condition) throws ServiceException { + return portBusiness.getPorts(condition); + } + + public void setPortBusiness(PortBusiness portBusiness) { + this.portBusiness = portBusiness; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImpl.java new file mode 100644 index 0000000..939385f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImpl.java @@ -0,0 +1,231 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.LimitsBusiness; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.SitesBusiness; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.ResOperateService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * DC info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public class SitesImpl implements Sites { + + private static final Logger LOGGER = LoggerFactory.getLogger(SitesImpl.class); + + private SitesBusiness sitesBusiness; + + private LimitsBusiness limitsBusiness; + + private ResOperateService resOperateService; + + @Override + public int add(JSONObject jsonObject) throws ServiceException { + LOGGER.info("Add datacenter jsonObject: {}", jsonObject); + SitesEntity sitesEntity = SitesEntity.toEntity(jsonObject); + sitesEntity.setStatus(ParamConstant.PARAM_ACTIVE); + String vimName = jsonObject.getString(ParamConstant.PARAM_VIMNAME); + String vimId = VimUtil.getVimIdByName(vimName); + sitesEntity.setVimId(vimId); + JSONObject resource = limitsBusiness.getLimits(vimId); + sitesEntity.setVimName(resource.getString(ParamConstant.PARAM_VIMNAME)); + sitesEntity.setTotalCPU(resource.getString(ParamConstant.TOTAL_CPU)); + sitesEntity.setUsedCPU(resource.getString(ParamConstant.USED_CPU)); + sitesEntity.setTotalMemory(resource.getString(ParamConstant.TOTAL_MEMORY)); + sitesEntity.setUsedMemory(resource.getString(ParamConstant.USED_MEMORY)); + sitesEntity.setTotalDisk(resource.getString(ParamConstant.TOTAL_DISK)); + sitesEntity.setUsedDisk(resource.getString(ParamConstant.USED_DISK)); + if(StringUtils.isEmpty(sitesEntity.getId())) { + sitesEntity.setId(UUID.randomUUID().toString()); + jsonObject.put(ParamConstant.PARAM_ID, sitesEntity.getId()); + } + LOGGER.info("Add datacenter sitesEntity: {}", sitesEntity.toString()); + return sitesBusiness.addSite(sitesEntity); + } + + /** + *
+ * + * @param json + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public void sendToMonitor(JSONObject jsonObject) throws ServiceException { + LOGGER.info("SitesImpl sendToMonitor jsonObject: {}", jsonObject); + String vimName = jsonObject.getString(ParamConstant.PARAM_VIMNAME); + String vimId = VimUtil.getVimIdByName(vimName); + JSONObject vimInfo = VimUtil.getVimById(vimId); + LOGGER.info("SitesImpl sendToMonitor vimInfo: {}", vimInfo); + String tenant = vimInfo.getString("tenant"); + String tenantId = VimUtil.getTenantIdByName(tenant, vimId); + JSONObject json = new JSONObject(); + json.put("header", null); + LOGGER.info("tenantId:{}, vimId:{}", tenantId, vimId); + resOperateService.addIRes(tenantId, vimId, json); + resOperateService.sendMsgMonitor("create", vimId); + } + + @Override + public int update(SitesEntity sitesEntity) throws ServiceException { + return sitesBusiness.updateSiteSelective(sitesEntity); + } + + @Override + public int update(JSONObject jsonObject) throws ServiceException { + LOGGER.info("grantResource jsonObject: {}", jsonObject); + JSONObject sitesObj = dataParse(jsonObject); + return sitesBusiness.updateSiteSelective(SitesEntity.toEntity(sitesObj)); + } + + private JSONObject dataParse(JSONObject jsonObject) throws ServiceException { + String vimId = jsonObject.getString(ParamConstant.PARAM_VIMID); + Map condition = new HashMap<>(); + condition.put("vimId", vimId); + SitesEntity sitesEntity = get(condition); + if(null == sitesEntity) { + LOGGER.error("Get sites null, vimId={}", vimId); + return null; + } + return computeSiteUsed(jsonObject, sitesEntity); + } + + private JSONObject computeSiteUsed(JSONObject jsonObject, SitesEntity sitesEntity) throws ServiceException { + String action = JsonUtil.getJsonFieldStr(jsonObject, "action"); + String usedCpu = JsonUtil.getJsonFieldStr(jsonObject, ParamConstant.USED_CPU); + String usedMemory = JsonUtil.getJsonFieldStr(jsonObject, ParamConstant.USED_MEMORY); + String usedDisk = JsonUtil.getJsonFieldStr(jsonObject, ParamConstant.USED_DISK); + String oldCpu = sitesEntity.getUsedCPU(); + String oldMemory = sitesEntity.getUsedMemory(); + String oldDisk = sitesEntity.getUsedDisk(); + String newCpu = accumOrFreeRes(usedCpu, oldCpu, action, sitesEntity.getTotalCPU(), "cpu"); + String newMemory = accumOrFreeRes(usedMemory, oldMemory, action, sitesEntity.getTotalMemory(), "memory"); + String newDisk = accumOrFreeRes(usedDisk, oldDisk, action, sitesEntity.getTotalDisk(), "disk"); + + JSONObject resUsed = new JSONObject(); + resUsed.put(ParamConstant.USED_CPU, newCpu); + resUsed.put(ParamConstant.USED_MEMORY, newMemory); + resUsed.put(ParamConstant.USED_DISK, newDisk); + resUsed.put("id", sitesEntity.getId()); + resUsed.put("name", sitesEntity.getName()); + resUsed.put("status", sitesEntity.getStatus()); + resUsed.put("location", sitesEntity.getLocation()); + resUsed.put("country", sitesEntity.getCountry()); + resUsed.put(ParamConstant.PARAM_VIMID, sitesEntity.getVimId()); + resUsed.put(ParamConstant.PARAM_VIMNAME, sitesEntity.getVimName()); + resUsed.put(ParamConstant.TOTAL_CPU, sitesEntity.getTotalCPU()); + resUsed.put(ParamConstant.TOTAL_MEMORY, sitesEntity.getTotalMemory()); + resUsed.put(ParamConstant.TOTAL_DISK, sitesEntity.getTotalDisk()); + return resUsed; + } + + private String accumOrFreeRes(String resUsed, String resOld, String action, String total, String type) + throws ServiceException { + BigDecimal iResUsed = new BigDecimal(resUsed); + BigDecimal iResOld = new BigDecimal(resOld); + BigDecimal itotal = new BigDecimal(total); + if("online".equals(action)) { + if(iResOld.add(iResUsed).compareTo(itotal) > 0) { + throw new ServiceException("Grant resource fail! The " + type + " resource not enough."); + } + return String.valueOf(iResOld.add(iResUsed)); + } else { + if(iResOld.subtract(iResUsed).compareTo(BigDecimal.ZERO) < 0) { + throw new ServiceException("Grant resource fail! The " + type + " resource used below zero."); + } + return String.valueOf(iResOld.subtract(iResUsed)); + } + } + + @Override + public int updateResource(JSONObject jsonObject) throws ServiceException { + return sitesBusiness.updateSiteResource(SitesEntity.toEntity(jsonObject)); + } + + @Override + public int delete(String id) throws ServiceException { + Map map = new HashMap(10); + map.put(ParamConstant.PARAM_ID, id); + List datacenters = getList(map); + SitesEntity site = datacenters.get(0); + LOGGER.info("site: {}", site); + String vimId = site.getVimId(); + LOGGER.info("vimId: {}", vimId); + resOperateService.sendMsgMonitor("delete", vimId); + resOperateService.deleteIRes(vimId); + return sitesBusiness.deleteSite(id); + } + + @Override + public int updateStatusByVimId(JSONObject jsonObject) throws ServiceException { + return sitesBusiness.updateSiteByVimId(SitesEntity.toEntity(jsonObject)); + } + + @Override + public List getList(Map condition) throws ServiceException { + return sitesBusiness.getSites(condition); + } + + @Override + public SitesEntity get(Map condition) throws ServiceException { + List siteList = sitesBusiness.getSites(condition); + if(null == siteList || siteList.isEmpty()) { + return null; + } + return siteList.get(0); + } + + @Override + public int deleteResByVimId(String vimId) throws ServiceException { + return 0; + } + + public void setSitesBusiness(SitesBusiness sitesBusiness) { + this.sitesBusiness = sitesBusiness; + } + + public void setLimitsBusiness(LimitsBusiness limitsBusiness) { + this.limitsBusiness = limitsBusiness; + } + + public void setResOperateService(ResOperateService resOperateService) { + this.resOperateService = resOperateService; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/VimImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/VimImpl.java new file mode 100644 index 0000000..f6cf553 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/VimImpl.java @@ -0,0 +1,82 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Vim; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.VimBusiness; +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + * Vim info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public class VimImpl implements Vim { + + private VimBusiness vimBusiness; + + @Override + public int add(String id) throws ServiceException { + return vimBusiness.addVim(id); + } + + @Override + public int add(JSONObject jsonObject) throws ServiceException { + return add(jsonObject.getString("id")); + } + + @Override + public int update(JSONObject jsonObject) throws ServiceException { + return 0; + } + + @Override + public int delete(String id) throws ServiceException { + return vimBusiness.deleteVim(id); + } + + @Override + public VimEntity getVim(String id) throws ServiceException { + return vimBusiness.getVim(id); + } + + @Override + public List getList() throws ServiceException { + return vimBusiness.getVims(); + } + + @Override + public List getVimInfo(Map condition) throws ServiceException { + // get vim from vimadapter + return new ArrayList(); + } + + public void setVimBusiness(VimBusiness vimBusiness) { + this.vimBusiness = vimBusiness; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Host.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Host.java new file mode 100644 index 0000000..673d274 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Host.java @@ -0,0 +1,66 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public interface Host extends InterfaceResManagement { + + /** + *
+ * + * @param jsonObject + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateStatusByVimId(JSONObject jsonObject) throws ServiceException; + + /** + *
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getList(Map condition) throws ServiceException; + + /** + *
+ * + * @param resPoolEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int update(HostEntity resPoolEntity) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/InterfaceResManagement.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/InterfaceResManagement.java new file mode 100644 index 0000000..b9ec1f6 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/InterfaceResManagement.java @@ -0,0 +1,40 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf; + +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public interface InterfaceResManagement extends ResManagement { + + /** + *
+ * + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deleteResByVimId(String vimId) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Location.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Location.java new file mode 100644 index 0000000..9767e12 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Location.java @@ -0,0 +1,104 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + * Location details class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface Location extends ResManagement { + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + Map get(String id) throws ServiceException; + + /** + * Get list of locations.
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List get(Map condition) throws ServiceException; + + /** + * Get location details.
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + LocationEntity getLocation(Map condition) throws ServiceException; + + /** + * Get location info.
+ * + * @param locationInfo + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getLocationInfo(List locationInfo) throws ServiceException; + + /** + * Get Country.
+ * + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getCountry() throws ServiceException; + + /** + * Get location by country.
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getLocationByCountry(Map condition) throws ServiceException; + + /** + * Get cloud services.
+ * + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getCloudservice() throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Network.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Network.java new file mode 100644 index 0000000..449ebe9 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Network.java @@ -0,0 +1,69 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + * + * Network class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface Network extends InterfaceResManagement { + + /** + * + * Update status by VIM Id.
+ * + * @param jsonObject + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateStatusByVimId(JSONObject jsonObject) throws ServiceException; + + /** + * + * Get list of networks.
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getList(Map condition) throws ServiceException; + + /** + *
+ * + * @param entity + * @return + * @since NFVO 0.5 + */ + int add(NetworkEntity entity) throws ServiceException; + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Port.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Port.java new file mode 100644 index 0000000..9d073f0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Port.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public interface Port extends InterfaceResManagement { + + /** + *
+ * + * @param jsonObject + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateStatusByVimId(JSONObject jsonObject) throws ServiceException; + + /** + *
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getList(Map condition) throws ServiceException; + + /** + *
+ * + * @param resPoolEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int update(PortEntity resPoolEntity) throws ServiceException; + + /** + *
+ * + * @param portEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int add(PortEntity portEntity) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/ResManagement.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/ResManagement.java new file mode 100644 index 0000000..e840827 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/ResManagement.java @@ -0,0 +1,66 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf; + +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public interface ResManagement { + + /** + *
+ * + * @param jsonObject + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int add(JSONObject jsonObject) throws ServiceException; + + /** + *
+ * + * @param jsonObject + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int update(JSONObject jsonObject) throws ServiceException; + + /* + * key : parameter key value : parameter value + */ + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int delete(String id) throws ServiceException; + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Sites.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Sites.java new file mode 100644 index 0000000..7aaba35 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Sites.java @@ -0,0 +1,95 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public interface Sites extends InterfaceResManagement { + + /** + *
+ * + * @param jsonObject + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateStatusByVimId(JSONObject jsonObject) throws ServiceException; + + /** + *
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getList(Map condition) throws ServiceException; + + /** + *
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + SitesEntity get(Map condition) throws ServiceException; + + /** + *
+ * + * @param jsonObject + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateResource(JSONObject jsonObject) throws ServiceException; + + /** + *
+ * + * @param sitesEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int update(SitesEntity sitesEntity) throws ServiceException; + + /** + *
+ * + * @param json + * @throws ServiceException + * @since NFVO 0.5 + */ + void sendToMonitor(JSONObject json) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Vim.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Vim.java new file mode 100644 index 0000000..9378f3f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/inf/Vim.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + * Virtualised Infrastructure Manager.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public interface Vim extends ResManagement { + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + VimEntity getVim(String id) throws ServiceException; + + /** + *
+ * + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getList() throws ServiceException; + + /** + * + * Get VIM information.
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getVimInfo(Map condition) throws ServiceException; + + /** + *
+ * + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int add(String vimId) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/HostBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/HostBusinessImpl.java new file mode 100644 index 0000000..e66c6f5 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/HostBusinessImpl.java @@ -0,0 +1,162 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.HostBusiness; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.HostDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * Host business implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class HostBusinessImpl implements HostBusiness { + + private static final Logger LOGGER = LoggerFactory.getLogger(HostBusinessImpl.class); + + private HostDao hostDao; + + @Override + public HostEntity getHost(String id) { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=getHost; msg=get error, because id is empty."); + return null; + } + return hostDao.getHost(id); + } + + @Override + public List getHosts(Map condition) { + return hostDao.getHosts(condition); + } + + @Override + public int deleteHost(String id) throws ServiceException { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=deleteHost; msg=delete error, because id is empty."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.delete.id.null")); + } + HostEntity rp = hostDao.getHost(id); + if(null == rp) { + return hostDao.deleteHost(id); + } + + return hostDao.deleteHost(id); + } + + @Override + public int addHost(HostEntity hostEntity) throws ServiceException { + if(null == hostEntity) { + LOGGER.error("function=addHost; msg=add error, because hostEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.entity.null")); + } + + if(!checkId(hostEntity.getId())) { + LOGGER.error("function=addHost; msg=add error, because id is already exist."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.id.check")); + } + if(StringUtils.isEmpty(hostEntity.getId())) { + hostEntity.setId(UUID.randomUUID().toString()); + } + return hostDao.addHost(hostEntity); + } + + @Override + public int addHostSelective(HostEntity hostEntity) throws ServiceException { + if(null == hostEntity) { + LOGGER.error("function=addHostSelective; msg=add error, because hostEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.entity.null")); + } + if(!checkId(hostEntity.getId())) { + LOGGER.error("function=addHostSelective; msg=add error, because id is allready exist."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.add.id.check")); + } + + if(StringUtils.isEmpty(hostEntity.getId())) { + hostEntity.setId(UUID.randomUUID().toString()); + } + return hostDao.addHostSelective(hostEntity); + } + + private boolean checkId(String id) { + HostEntity respool = hostDao.getHost(id); + if(null == respool) { + return true; + } + return false; + } + + @Override + public int updateHostSelective(HostEntity hostEntity) throws ServiceException { + if(!checkId(hostEntity.getId())) { + return hostDao.updateHostSelective(hostEntity); + } else { + return addHostSelective(hostEntity); + } + } + + @Override + public int updateHost(HostEntity hostEntity) throws ServiceException { + if(null == hostEntity) { + LOGGER.error("function=updateHost; msg=update error, because hostEntity is null."); + throw new ServiceException("update error, because hostEntity is null."); + } + + return hostDao.updateHost(hostEntity); + } + + @Override + public int updateHostByVimId(HostEntity hostEntity) throws ServiceException { + if(null == hostEntity) { + LOGGER.error("function=updateHostByVimId; msg=update error, because hostEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.update.entity.null")); + } + return hostDao.updateHostByVimId(hostEntity); + } + + @Override + public int deleteHostByVimId(String vimId) throws ServiceException { + if(StringUtils.isEmpty(vimId)) { + LOGGER.error("function=deleteHostByVimId; msg=delete error, because VimId is empty."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.host.delete.vimid.check")); + } + return hostDao.deleteHostByVimId(vimId); + } + + public void setHostDao(HostDao hostDao) { + this.hostDao = hostDao; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LimitsBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LimitsBusinessImpl.java new file mode 100644 index 0000000..668257b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LimitsBusinessImpl.java @@ -0,0 +1,93 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.LimitsBusiness; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class LimitsBusinessImpl implements LimitsBusiness { + + private static final Logger LOGGER = LoggerFactory.getLogger(LimitsBusinessImpl.class); + + /** + *
+ * + * @param vimId + * @param tenantId + * @return + * @since NFVO 0.5 + */ + private JSONObject getResponse(String vimId, String tenantId) { + LOGGER.info("function=getResponse; vimId={}, tenantId={}", vimId, tenantId); + String url = String.format(UrlConstant.GET_LIMITS_URL, vimId, tenantId); + JSONObject result = RestfulUtil.getResponseObj(url, ParamConstant.PARAM_GET); + LOGGER.warn("function=getResponse; result={}", result); + if(null == result) { + JSONObject obj = new JSONObject(); + obj.put("msg", "getLimits fail!"); + return obj; + } + return result; + } + + @Override + public JSONObject getLimits(String vimId) throws ServiceException { + JSONObject vimInfo = VimUtil.getVimById(vimId); + LOGGER.info("GetLimits vimInfo: {}", vimInfo); + String vimName = vimInfo.getString("name"); + String tenant = vimInfo.getString("tenant"); + String tenantId = VimUtil.getTenantIdByName(tenant, vimId); + + JSONObject limits = getResponse(vimId, tenantId); + + String totalCPU = String.valueOf(limits.get("maxTotalCores")); + String totalMemory = String.valueOf(limits.get("maxTotalRAMSize")); + String totalDisk = String.valueOf(limits.get("maxTotalVolumeGigabytes")); + String usedCPU = String.valueOf(limits.get("totalCoresUsed")); + String usedMemory = String.valueOf(limits.get("totalRAMUsed")); + String usedDisk = String.valueOf(limits.get("totalGigabytesUsed")); + + JSONObject result = new JSONObject(); + result.put("vimId", vimId); + result.put("vimName", vimName); + result.put("totalCPU", totalCPU); + result.put("totalMemory", totalMemory); + result.put("totalDisk", totalDisk); + result.put("usedCPU", usedCPU); + result.put("usedMemory", usedMemory); + result.put("usedDisk", usedDisk); + LOGGER.info("getLimits result:{}", result); + return result; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LocationBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LocationBusinessImpl.java new file mode 100644 index 0000000..fcbd3ae --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LocationBusinessImpl.java @@ -0,0 +1,242 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.StringUtil; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.LocationBusiness; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.LocationDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * Location Business implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class LocationBusinessImpl implements LocationBusiness { + + private static final Logger LOGGER = LoggerFactory.getLogger(LocationBusinessImpl.class); + + private LocationDao locationDao; + + /** + * + * Check location.
+ * + * @param locationEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + public boolean checkLocation(LocationEntity locationEntity) throws ServiceException { + String location = locationEntity.getLocation(); + Map map = new HashMap<>(); + map.put(ParamConstant.PARAM_LOCATION, location); + List locationList = getLocations(map); + if(locationList == null || locationList.isEmpty()) { + return false; + } + return true; + } + + /** + * + * Check Latitude.;
+ * + * @param locationEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + public boolean checkLatitude(LocationEntity locationEntity) throws ServiceException { + String latitu = locationEntity.getLatitude(); + String longitu = locationEntity.getLongitude(); + if("-0".equals(locationEntity.getLatitude())) { + locationEntity.setLatitude("0"); + } + if("-0".equals(locationEntity.getLongitude())) { + locationEntity.setLongitude("0"); + } + float latitude = Float.parseFloat(latitu); + float longitude = Float.parseFloat(longitu); + if((latitude >= -90 && latitude <= 90) && (longitude >= -180 && longitude <= 180)) { + return true; + } + return false; + } + + private boolean checkModified(LocationEntity locationEntity) { + String newCountry = locationEntity.getCountry(); + String newLocation = locationEntity.getLocation(); + String id = locationEntity.getId(); + LocationEntity selectLocation = locationDao.getLocation(id); + if(null == selectLocation) { + return false; + } + String oldCountry = selectLocation.getCountry(); + String oldLocation = selectLocation.getLocation(); + if(newCountry.equals(oldCountry) && newLocation.equals(oldLocation)) { + return true; + } + return false; + } + + @Override + public LocationEntity getLocation(String id) throws ServiceException { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=getLocation; msg=get error, because id is empty."); + return null; + } + return locationDao.getLocation(id); + } + + @Override + public List getCountry() throws ServiceException { + return locationDao.getCountry(); + } + + @Override + public List getLocationByCountry(Map condition) throws ServiceException { + return locationDao.getLocationByCountry(condition); + } + + @Override + public List getLocations(Map condition) throws ServiceException { + return locationDao.getLocations(condition); + } + + @Override + public int deleteLocation(String location) throws ServiceException { + if(StringUtils.isEmpty(location)) { + LOGGER.error("function=deleteLocation; msg=delete error, because location is empty."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.delete.base.entity.check")); + } + return locationDao.deleteLocation(location); + } + + @Override + public int addLocation(LocationEntity locationEntity) throws ServiceException { + if(null == locationEntity) { + LOGGER.error("function=addLocation; msg=add error, because locationEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.entity.null")); + } + if(!StringUtil.checkXss(locationEntity.getCountry()) || !StringUtil.checkXss(locationEntity.getLocation()) + || !StringUtil.checkXss(locationEntity.getLatitude()) + || !StringUtil.checkXss(locationEntity.getLongitude())) { + LOGGER.error("function=addLocation; msg=add Location error, because XSS injection."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.xss.check")); + } + if(checkLocation(locationEntity)) { + LOGGER.error("function=addLocation; msg=add Location error, because location exist."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.entity.check")); + } + if(!checkLatitude(locationEntity)) { + LOGGER.error("function=addLocation; msg=add Location error, because latitude or longitude illegal."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.latitude.check")); + } + if(null == locationEntity.getId() || locationEntity.getId().isEmpty()) { + locationEntity.setId(UUID.randomUUID().toString()); + } + LOGGER.error("function=addLocation; msg=add DO success, : " + locationEntity); + return locationDao.addLocation(locationEntity); + + } + + @Override + public int addLocationSelective(LocationEntity locationEntity) throws ServiceException { + if(null == locationEntity) { + LOGGER.error("function=addLocationSelective; msg=add error, because locationEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.entity.null")); + } + if(!StringUtil.checkXss(locationEntity.getCountry()) || !StringUtil.checkXss(locationEntity.getLocation()) + || !StringUtil.checkXss(locationEntity.getLatitude()) + || !StringUtil.checkXss(locationEntity.getLongitude())) { + LOGGER.error("function=addLocation; msg=add Location error, because XSS injection."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.xss.check")); + } + if(null == locationEntity.getId() || locationEntity.getId().isEmpty()) { + locationEntity.setId(UUID.randomUUID().toString()); + } + return locationDao.addLocationSelective(locationEntity); + } + + @Override + public int updateLocationSelective(LocationEntity locationEntity) throws ServiceException { + if(null == locationEntity) { + LOGGER.error("function=updateLocationSelective; msg=update error, because locationEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.entity.check")); + } + if(!checkLatitude(locationEntity)) { + LOGGER.error("function=updateLocationSelective; msg=update Location error, " + + "because latitude or longitude illegal."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.latitude.check")); + } + if(!checkModified(locationEntity)) { + LOGGER.error("function=updateLocationSelective; msg=update Location error, " + + "because country or location be modified."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.modified.check")); + } + return locationDao.updateLocationSelective(locationEntity); + } + + @Override + public int updateLocation(LocationEntity locationEntity) throws ServiceException { + if(null == locationEntity) { + LOGGER.error("function=updateLocation; msg=update error, because locationEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.entity.null")); + } + if(!checkLatitude(locationEntity)) { + LOGGER.error("function=updateLocation; msg=update Location error, because latitude or longitude illegal."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.latitude.check")); + } + return locationDao.updateLocation(locationEntity); + } + + public LocationDao getLocationDao() { + return locationDao; + } + + public void setLocationDao(LocationDao locationDao) { + this.locationDao = locationDao; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/NetworkBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/NetworkBusinessImpl.java new file mode 100644 index 0000000..433af10 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/NetworkBusinessImpl.java @@ -0,0 +1,153 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.NetworkBusiness; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NetworkDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Network business implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class NetworkBusinessImpl implements NetworkBusiness { + + private static final Logger LOGGER = LoggerFactory.getLogger(NetworkBusinessImpl.class); + + private NetworkDao networkDao; + + @Override + public NetworkEntity getNetwork(String id) { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=getNetwork; msg=get error, because id is empty."); + return null; + } + return networkDao.getNetwork(id); + } + + @Override + public List getNetworks(Map condition) { + return networkDao.getNetworks(condition); + } + + @Override + public int deleteNetwork(String id) throws ServiceException { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=deleteNetwork; msg=delete error, because id is empty."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.delete.id.null")); + } + return networkDao.deleteNetwork(id); + } + + @Override + public int addNetwork(NetworkEntity networkEntity) throws ServiceException { + if(null == networkEntity) { + LOGGER.error("function=addNetwork; msg=add error, because networkEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.add.entity.null")); + } + if(!checkId(networkEntity.getId())) { + return networkDao.updateNetworkSelective(networkEntity); + } + if(StringUtils.isEmpty(networkEntity.getId())) { + networkEntity.setId(UUID.randomUUID().toString()); + } + return networkDao.addNetwork(networkEntity); + } + + @Override + public int addNetworkSelective(NetworkEntity networkEntity) throws ServiceException { + if(null == networkEntity) { + LOGGER.error("function=addNetworkSelective; msg=add error, because networkEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.add.entity.null")); + } + if(!checkId(networkEntity.getId())) { + return networkDao.updateNetworkSelective(networkEntity); + } + if(StringUtils.isEmpty(networkEntity.getId())) { + networkEntity.setId(UUID.randomUUID().toString()); + } + return networkDao.addNetworkSelective(networkEntity); + } + + private boolean checkId(String id) { + NetworkEntity network = networkDao.getNetwork(id); + if(null == network) { + return true; + } + return false; + } + + @Override + public int updateNetworkSelective(NetworkEntity networkEntity) throws ServiceException { + if(null == networkEntity) { + LOGGER.error("function=updateNetworkSelective; msg=update error, because networkEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null")); + } + return networkDao.updateNetworkSelective(networkEntity); + } + + @Override + public int updateNetwork(NetworkEntity networkEntity) throws ServiceException { + if(null == networkEntity) { + LOGGER.error("function=updateNetwork; msg=update error, because networkEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null")); + } + return networkDao.updateNetwork(networkEntity); + } + + @Override + public int updateNetworkByVimId(NetworkEntity networkEntity) throws ServiceException { + if(null == networkEntity) { + LOGGER.error("function=updateNetworkByVimId; msg=update error, because networkEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.network.update.entity.null")); + } + return networkDao.updateNetworkByVimId(networkEntity); + } + + @Override + public int deleteNetworkByVimId(String vimId) throws ServiceException { + if(StringUtils.isEmpty(vimId)) { + LOGGER.error("function=deleteNetworkByVimId; msg=delete error, because VimId is empty."); + throw new ServiceException(ResourceUtil.getMessage("")); + } + return networkDao.deleteNetworkByVimId(vimId); + } + + public void setNetworkDao(NetworkDao networkDao) { + this.networkDao = networkDao; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/PortBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/PortBusinessImpl.java new file mode 100644 index 0000000..b2545ac --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/PortBusinessImpl.java @@ -0,0 +1,161 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.PortBusiness; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.PortDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Port business implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class PortBusinessImpl implements PortBusiness { + + private static final Logger LOGGER = LoggerFactory.getLogger(PortBusinessImpl.class); + + private PortDao portDao; + + @Override + public PortEntity getPort(String id) { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=getPort; msg=get error, because id is empty."); + return null; + } + return portDao.getPort(id); + } + + @Override + public List getPorts(Map condition) { + return portDao.getPorts(condition); + } + + @Override + public int deletePort(String id) throws ServiceException { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=deletePort; msg=delete error, because id is empty."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.delete.id.null")); + } + PortEntity rp = portDao.getPort(id); + if(null == rp) { + return portDao.deletePort(id); + } + + return portDao.deletePort(id); + } + + @Override + public int addPort(PortEntity portEntity) throws ServiceException { + if(null == portEntity) { + LOGGER.error("function=addPort; msg=add error, because portEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.add.entity.null")); + } + + if(!checkId(portEntity.getId())) { + return portDao.updatePortSelective(portEntity); + } + if(StringUtils.isEmpty(portEntity.getId())) { + portEntity.setId(UUID.randomUUID().toString()); + } + return portDao.addPort(portEntity); + } + + @Override + public int addPortSelective(PortEntity portEntity) throws ServiceException { + if(null == portEntity) { + LOGGER.error("function=addPortSelective; msg=add error, because portEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.add.entity.null")); + } + if(!checkId(portEntity.getId())) { + return portDao.updatePortSelective(portEntity); + } + + if(StringUtils.isEmpty(portEntity.getId())) { + portEntity.setId(UUID.randomUUID().toString()); + } + return portDao.addPortSelective(portEntity); + } + + private boolean checkId(String id) { + PortEntity respool = portDao.getPort(id); + if(null == respool) { + return true; + } + return false; + } + + @Override + public int updatePortSelective(PortEntity portEntity) throws ServiceException { + if(null == portEntity) { + LOGGER.error("function=updatePortSelective; msg=update error, because portEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.update.entity.null")); + } + + return portDao.updatePortSelective(portEntity); + } + + @Override + public int updatePort(PortEntity portEntity) throws ServiceException { + if(null == portEntity) { + LOGGER.error("function=updatePort; msg=update error, because portEntity is null."); + throw new ServiceException("update error, because portEntity is null."); + } + + return portDao.updatePort(portEntity); + } + + @Override + public int updatePortByVimId(PortEntity portEntity) throws ServiceException { + if(null == portEntity) { + LOGGER.error("function=updatePortByVimId; msg=update error, because portEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.update.entity.null")); + } + return portDao.updatePortByVimId(portEntity); + } + + @Override + public int deletePortByVimId(String vimId) throws ServiceException { + if(StringUtils.isEmpty(vimId)) { + LOGGER.error("function=deletePortByVimId; msg=delete error, because VimId is empty."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.port.delete.vimid.check")); + } + return portDao.deletePortByVimId(vimId); + } + + public void setPortDao(PortDao portDao) { + this.portDao = portDao; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/SitesBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/SitesBusinessImpl.java new file mode 100644 index 0000000..9ffed0a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/SitesBusinessImpl.java @@ -0,0 +1,200 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.SitesBusiness; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.SitesDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Sites info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public class SitesBusinessImpl implements SitesBusiness { + + private static final Logger LOGGER = LoggerFactory.getLogger(SitesBusinessImpl.class); + + private SitesDao sitesDao; + + private static final String TYPE_ADD = "add"; + + private static final String TYPE_UPDATE = "update"; + + private static final String TYPE_DELETE = "delete"; + + @Override + public SitesEntity getSite(String id) throws ServiceException { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=getSite; msg=get error, because id is empty."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.id.null")); + } + return sitesDao.getSite(id); + } + + @Override + public List getSites(Map condition) { + return sitesDao.getSites(condition); + } + + @Override + public int deleteSite(String id) throws ServiceException { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=deleteSite; msg=delete error, because id is empty."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.delete.id.null")); + } + + return sitesDao.deleteSite(id); + } + + @Override + public int addSite(SitesEntity sitesEntity) throws ServiceException { + LOGGER.info("addSite sitesEntity"); + if(null == sitesEntity) { + LOGGER.error("function=addSite; msg=add error, because sitesEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.entity.null")); + } + // if(!StringUtil.checkXss(sitesEntity.getName()) || + // !StringUtil.checkXss(sitesEntity.getCountry()) + // || !StringUtil.checkXss(sitesEntity.getLocation())) { + // LOGGER.error("function=addLocation; msg=add site error, because XSS injection."); + // throw new ServiceException( + // ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.add.xss.check")); + // } + LOGGER.info("sitesEntity: " + sitesEntity.toString()); + this.checkSite(sitesEntity, TYPE_ADD); + SitesEntity.dataFramat(sitesEntity); + LOGGER.info("Add datacenter data into DB."); + return sitesDao.addSite(sitesEntity); + } + + private void checkSite(SitesEntity sitesEntity, String type) throws ServiceException { + if(TYPE_ADD.equals(type)) { + checkId(sitesEntity.getId()); + checkSiteName(sitesEntity.getName()); + if(!SitesEntity.checkResource(sitesEntity)) { + LOGGER.error("function=checkRespool; msg=site{} resource error", sitesEntity.toString()); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.resource.check")); + } + } + } + + private void checkSiteName(String siteName) throws ServiceException { + Map siteMap = new HashMap<>(10); + siteMap.put(ParamConstant.PARAM_NAME, siteName); + List siteList = sitesDao.getSites(siteMap); + if(null != siteList && !siteList.isEmpty()) { + LOGGER.error("function=checkSiteName; msg=site: {} has already exist.", siteName); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.name.check")); + } + } + + private void checkId(String id) throws ServiceException { + SitesEntity site = sitesDao.getSite(id); + if(null != site) { + LOGGER.error("function=checkId; msg=add error, because id is already exist."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.id.check")); + } + } + + @Override + public int addSiteSelective(SitesEntity sitesEntity) throws ServiceException { + if(null == sitesEntity) { + LOGGER.error("function=addSiteSelective; msg=add error, because sitesEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.add.entity.null")); + } + this.checkSite(sitesEntity, TYPE_ADD); + + if(StringUtils.isEmpty(sitesEntity.getId())) { + sitesEntity.setId(UUID.randomUUID().toString()); + } + SitesEntity.dataFramat(sitesEntity); + return sitesDao.addSiteSelective(sitesEntity); + } + + @Override + public int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException { + if(null == sitesEntity) { + LOGGER.error("function=updateSiteSelective; msg=update error, because sitesEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.update.entity.null")); + } + + this.checkSite(sitesEntity, TYPE_UPDATE); + SitesEntity.dataFramat(sitesEntity); + return sitesDao.updateSiteSelective(sitesEntity); + } + + @Override + public int updateSite(SitesEntity sitesEntity) throws ServiceException { + if(null == sitesEntity) { + LOGGER.error("function=updateSite; msg=update error, because sitesEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.update.entity.null")); + } + this.checkSite(sitesEntity, TYPE_UPDATE); + SitesEntity.dataFramat(sitesEntity); + return sitesDao.updateSite(sitesEntity); + } + + @Override + public int updateSiteByVimId(SitesEntity sitesEntity) throws ServiceException { + if(null == sitesEntity) { + LOGGER.error("function=updateSiteByVimId; msg=update error, because sitesEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.update.entity.null")); + } + SitesEntity.dataFramat(sitesEntity); + return sitesDao.updateSiteByVimId(sitesEntity); + } + + @Override + public int updateSiteResource(SitesEntity sitesEntity) throws ServiceException { + if(null == sitesEntity) { + LOGGER.error("function=updateSiteResource; msg=update error, because sitesEntity is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.site.update.entity.null")); + } + SitesEntity.dataFramat(sitesEntity); + return sitesDao.updateSiteSelective(sitesEntity); + } + + public void setSitesDao(SitesDao sitesDao) { + this.sitesDao = sitesDao; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/VimBusinessImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/VimBusinessImpl.java new file mode 100644 index 0000000..5c6dda3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/VimBusinessImpl.java @@ -0,0 +1,99 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.StringUtil; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.VimBusiness; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VimDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Vim info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public class VimBusinessImpl implements VimBusiness { + + private static final Logger LOGGER = LoggerFactory.getLogger(VimBusinessImpl.class); + + private VimDao vimDao; + + @Override + public VimEntity getVim(String id) { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=getVim; msg=get error, because id is empty."); + return null; + } + return vimDao.getVim(id); + } + + @Override + public List getVims() { + return vimDao.getVims(); + } + + @Override + public int deleteVim(String id) throws ServiceException { + if(StringUtils.isEmpty(id)) { + LOGGER.error("function=deleteVim; msg=deleteVim error, because id is empty."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.del.id.check")); + } + return vimDao.deleteVim(id); + } + + @Override + public int addVim(String id) throws ServiceException { + if(!StringUtil.isValidString(id)) { + LOGGER.error("function=addVim; msg=add error, because id is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.add.id.null")); + } + if(!checkId(id)) { + LOGGER.error("function=addVim; msg=add error, because id is already exist."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.vim.add.id.check")); + } + + VimEntity vimEntity = new VimEntity(); + vimEntity.setId(id); + return vimDao.addVim(vimEntity); + } + + private boolean checkId(String id) { + VimEntity vim = vimDao.getVim(id); + if(null == vim) { + return true; + } + return false; + } + + public void setVimDao(VimDao vimDao) { + this.vimDao = vimDao; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/HostBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/HostBusiness.java new file mode 100644 index 0000000..e017709 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/HostBusiness.java @@ -0,0 +1,131 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * Host Buisiness Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 31, 2016 + */ +public interface HostBusiness { + + /** + * + * Get host.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + HostEntity getHost(String id); + + /** + * + * Get details of hosts.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getHosts(Map condition); + + /** + * + * Delete host.
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deleteHost(String id) throws ServiceException; + + /** + * + * Delete host by VIM Id.
+ * + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deleteHostByVimId(String vimId) throws ServiceException; + + /** + * + * Add host.
+ * + * @param hostEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int addHost(HostEntity hostEntity) throws ServiceException; + + /** + * + * Add selective host.
+ * + * @param hostEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int addHostSelective(HostEntity hostEntity) throws ServiceException; + + /** + * + * Update selective host.
+ * + * @param hostEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateHostSelective(HostEntity hostEntity) throws ServiceException; + + /** + * + * Update host.
+ * + * @param hostEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateHost(HostEntity hostEntity) throws ServiceException; + + /** + * + * Update host by VIM Id.
+ * + * @param hostEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateHostByVimId(HostEntity hostEntity) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/LimitsBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/LimitsBusiness.java new file mode 100644 index 0000000..62326ea --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/LimitsBusiness.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.inf; + +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface LimitsBusiness { + + /** + *
+ * + * @param paramJson + * @return + * @since NFVO 0.5 + */ + JSONObject getLimits(String vimId) throws ServiceException; + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/LocationBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/LocationBusiness.java new file mode 100644 index 0000000..6fab40a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/LocationBusiness.java @@ -0,0 +1,134 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * + * Location Business Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface LocationBusiness { + + /** + * + * Get Location.
+ * + * @param location + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + LocationEntity getLocation(String location) throws ServiceException; + + /** + * + * Get Locations.
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getLocations(Map condition) throws ServiceException; + + /** + * + * Delete Location.
+ * + * @param location + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deleteLocation(String location) throws ServiceException; + + /** + * + * Add Location.
+ * + * @param locationEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int addLocation(LocationEntity locationEntity) throws ServiceException; + + /** + * + * Add Selective Location.
+ * + * @param locationEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int addLocationSelective(LocationEntity locationEntity) throws ServiceException; + + /** + * + * Update Selective Location.
+ * + * @param locationEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateLocationSelective(LocationEntity locationEntity) throws ServiceException; + + /** + * + * Update Location.
+ * + * @param locationEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateLocation(LocationEntity locationEntity) throws ServiceException; + + /** + * + * Get Country.
+ * + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getCountry() throws ServiceException; + + /** + * + * Get Location By Country.
+ * + * @param condition + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getLocationByCountry(Map condition) throws ServiceException; + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/NetworkBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/NetworkBusiness.java new file mode 100644 index 0000000..80ff1e3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/NetworkBusiness.java @@ -0,0 +1,133 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * + * Network Business class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface NetworkBusiness { + + /** + * + * Get network details.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + NetworkEntity getNetwork(String id); + + /** + * + * Get details of available networks.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getNetworks(Map condition); + + /** + * + * Delete Network.
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deleteNetwork(String id) throws ServiceException; + + /** + * + * Delete network by Virtual Infrastructure Manager ID.
+ * + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deleteNetworkByVimId(String vimId) throws ServiceException; + + /** + * + * Add Network.
+ * + * @param networkEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int addNetwork(NetworkEntity networkEntity) throws ServiceException; + + /** + * + * Add Selective Network.
+ * + * @param networkEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int addNetworkSelective(NetworkEntity networkEntity) throws ServiceException; + + /** + * + * Update Selective Network.
+ * + * @param networkEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateNetworkSelective(NetworkEntity networkEntity) throws ServiceException; + + /** + * + * Update Network.
+ * + * @param networkEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateNetwork(NetworkEntity networkEntity) throws ServiceException; + + /** + * + * Update network by Virtual Infrastructure Manager ID.
+ * + * @param networkEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updateNetworkByVimId(NetworkEntity networkEntity) throws ServiceException; + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/PortBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/PortBusiness.java new file mode 100644 index 0000000..7e32484 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/PortBusiness.java @@ -0,0 +1,131 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * Port Buisiness Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 31, 2016 + */ +public interface PortBusiness { + + /** + * + * Get Port.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + PortEntity getPort(String id); + + /** + * + * Get details of ports.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getPorts(Map condition); + + /** + * + * Delete Port.
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deletePort(String id) throws ServiceException; + + /** + * + * Delete port by VIM ID.
+ * + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deletePortByVimId(String vimId) throws ServiceException; + + /** + * + * Add port.
+ * + * @param portEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int addPort(PortEntity portEntity) throws ServiceException; + + /** + * + * Add selective port.
+ * + * @param portEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int addPortSelective(PortEntity portEntity) throws ServiceException; + + /** + * + * Update selective port.
+ * + * @param portEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updatePortSelective(PortEntity portEntity) throws ServiceException; + + /** + * + * Update port.
+ * + * @param portEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updatePort(PortEntity portEntity) throws ServiceException; + + /** + * + * Update port by VIM Id.
+ * + * @param portEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int updatePortByVimId(PortEntity portEntity) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/SitesBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/SitesBusiness.java new file mode 100644 index 0000000..f3c09dd --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/SitesBusiness.java @@ -0,0 +1,124 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * DC info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface SitesBusiness { + + /** + * It is used to get Site info.
+ * + * @param id + * @return The get result + * @throws ServiceException When get failed. + * @since NFVO 0.5 + */ + SitesEntity getSite(String id) throws ServiceException; + + /** + * It is used to get Sites info.
+ * + * @param condition + * @return The get result + * @since NFVO 0.5 + */ + List getSites(Map condition); + + /** + * It is used to delete Site info.
+ * + * @param id + * @return The delete result + * @throws ServiceException When delete failed. + * @since NFVO 0.5 + */ + int deleteSite(String id) throws ServiceException; + + /** + * It is used to add Site info.
+ * + * @param sitesEntity + * @return The add result + * @throws ServiceException When add failed. + * @since NFVO 0.5 + */ + int addSite(SitesEntity sitesEntity) throws ServiceException; + + /** + * It is used to add Site info.
+ * + * @param sitesEntity + * @return The add result + * @throws ServiceException When add failed. + * @since NFVO 0.5 + */ + int addSiteSelective(SitesEntity sitesEntity) throws ServiceException; + + /** + * It is used to update Site info.
+ * + * @param sitesEntity + * @return The update result + * @throws ServiceException When update failed. + * @since NFVO 0.5 + */ + int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException; + + /** + * It is used to create update Site info.
+ * + * @param sitesEntity + * @return The update result + * @throws ServiceException When update failed. + * @since NFVO 0.5 + */ + int updateSite(SitesEntity sitesEntity) throws ServiceException; + + /** + * It is used to update Site info.
+ * + * @param sitesEntity + * @return The update result + * @throws ServiceException When update failed. + * @since NFVO 0.5 + */ + int updateSiteByVimId(SitesEntity sitesEntity) throws ServiceException; + + /** + * It is used to update Site info.
+ * + * @param sitesEntity + * @return The update result + * @throws ServiceException When update failed. + * @since NFVO 0.5 + */ + int updateSiteResource(SitesEntity sitesEntity) throws ServiceException; + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/VimBusiness.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/VimBusiness.java new file mode 100644 index 0000000..fc2a857 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/business/inf/VimBusiness.java @@ -0,0 +1,72 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.inf; + +import java.util.List; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * Vim info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface VimBusiness { + + /** + * It is used to get Vim info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + VimEntity getVim(String id); + + /** + * It is used to get Vim info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + List getVims(); + + /** + * It is used to delete Vim info.
+ * + * @param id + * @return the delete result + * @throws ServiceException When delete failed. + * @since NFVO 0.5 + */ + int deleteVim(String id) throws ServiceException; + + /** + * It is used to add Vim info.
+ * + * @param id + * @return the add result + * @throws ServiceException When add failed. + * @since NFVO 0.5 + */ + int addVim(String id) throws ServiceException; + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/AbstractDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/AbstractDao.java new file mode 100644 index 0000000..84171d3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/AbstractDao.java @@ -0,0 +1,57 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import org.apache.ibatis.session.SqlSession; + +/** + *
+ *

+ * Database abstract class to get the MapperManager + *

+ * + * @author + * @version NFVO 0.5 2016-3-17 + */ +public class AbstractDao { + + private SqlSession session; + + protected AbstractDao() { + //added this private costructor to fix static errors. + } + + public SqlSession getSession() { + return session; + } + + public void setSession(SqlSession session) { + this.session = session; + } + + /** + * get Mybatis Mapper
+ * + * @param type + * The type of Class + * @return Mapper + * @since NFVO 0.5 + */ + public T getMapperManager(Class type) { + return (T)getSession().getMapper(type); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/HostDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/HostDaoImpl.java new file mode 100644 index 0000000..e72f426 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/HostDaoImpl.java @@ -0,0 +1,83 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.HostDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.HostMapper; + +/** + * + * Host DAO implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class HostDaoImpl extends AbstractDao implements HostDao { + + @Override + public HostEntity getHost(String id) { + return getMapperManager(HostMapper.class).getHost(id); + } + + @Override + public List getHosts(Map condition) { + return getMapperManager(HostMapper.class).getHosts(condition); + } + + @Override + public int deleteHost(String id) { + return getMapperManager(HostMapper.class).deleteHost(id); + } + + @Override + public int deleteHostByVimId(String vimId) { + return getMapperManager(HostMapper.class).deleteHostByVimId(vimId); + } + + @Override + public int addHost(HostEntity hostEntity) { + return getMapperManager(HostMapper.class).addHost(hostEntity); + } + + @Override + public int addHostSelective(HostEntity hostEntity) { + return getMapperManager(HostMapper.class).addHostSelective(hostEntity); + } + + @Override + public int updateHostSelective(HostEntity hostEntity) { + return getMapperManager(HostMapper.class).updateHostSelective(hostEntity); + } + + @Override + public int updateHost(HostEntity hostEntity) { + return getMapperManager(HostMapper.class).updateHost(hostEntity); + } + + @Override + public int updateHostByVimId(HostEntity hostEntity) { + return getMapperManager(HostMapper.class).updateHostByVimId(hostEntity); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/LocationDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/LocationDaoImpl.java new file mode 100644 index 0000000..7901331 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/LocationDaoImpl.java @@ -0,0 +1,83 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.LocationDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.LocationMapper; + +/** + * + * Location DAO implemetation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class LocationDaoImpl extends AbstractDao implements LocationDao { + + @Override + public LocationEntity getLocation(String id) { + return getMapperManager(LocationMapper.class).getLocation(id); + } + + @Override + public List getCountry() { + return getMapperManager(LocationMapper.class).getCountry(); + } + + @Override + public List getLocationByCountry(Map condition) { + return getMapperManager(LocationMapper.class).getLocationByCountry(condition); + } + + @Override + public List getLocations(Map condition) { + return getMapperManager(LocationMapper.class).getLocations(condition); + } + + @Override + public int deleteLocation(String id) { + return getMapperManager(LocationMapper.class).deleteLocation(id); + } + + @Override + public int addLocation(LocationEntity locationEntity) { + return getMapperManager(LocationMapper.class).addLocation(locationEntity); + } + + @Override + public int addLocationSelective(LocationEntity locationEntity) { + return getMapperManager(LocationMapper.class).addLocationSelective(locationEntity); + } + + @Override + public int updateLocationSelective(LocationEntity locationEntity) { + return getMapperManager(LocationMapper.class).updateLocationSelective(locationEntity); + } + + @Override + public int updateLocation(LocationEntity locationEntity) { + return getMapperManager(LocationMapper.class).updateLocation(locationEntity); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/NetworkDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/NetworkDaoImpl.java new file mode 100644 index 0000000..612aba6 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/NetworkDaoImpl.java @@ -0,0 +1,83 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NetworkDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.NetworkMapper; + +/** + * + * Network DAO implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class NetworkDaoImpl extends AbstractDao implements NetworkDao { + + @Override + public NetworkEntity getNetwork(String id) { + return getMapperManager(NetworkMapper.class).getNetwork(id); + } + + @Override + public List getNetworks(Map condition) { + return getMapperManager(NetworkMapper.class).getNetworks(condition); + } + + @Override + public int deleteNetwork(String id) { + return getMapperManager(NetworkMapper.class).deleteNetwork(id); + } + + @Override + public int deleteNetworkByVimId(String vimId) { + return getMapperManager(NetworkMapper.class).deleteNetworkByVimId(vimId); + } + + @Override + public int addNetwork(NetworkEntity networkEntity) { + return getMapperManager(NetworkMapper.class).addNetwork(networkEntity); + } + + @Override + public int addNetworkSelective(NetworkEntity networkEntity) { + return getMapperManager(NetworkMapper.class).addNetworkSelective(networkEntity); + } + + @Override + public int updateNetworkSelective(NetworkEntity networkEntity) { + return getMapperManager(NetworkMapper.class).updateNetworkSelective(networkEntity); + } + + @Override + public int updateNetwork(NetworkEntity networkEntity) { + return getMapperManager(NetworkMapper.class).updateNetwork(networkEntity); + } + + @Override + public int updateNetworkByVimId(NetworkEntity networkEntity) { + return getMapperManager(NetworkMapper.class).updateNetworkByVimId(networkEntity); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/PortDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/PortDaoImpl.java new file mode 100644 index 0000000..3854152 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/PortDaoImpl.java @@ -0,0 +1,83 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.PortDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.PortMapper; + +/** + * + * Port DAO implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class PortDaoImpl extends AbstractDao implements PortDao { + + @Override + public PortEntity getPort(String id) { + return getMapperManager(PortMapper.class).getPort(id); + } + + @Override + public List getPorts(Map condition) { + return getMapperManager(PortMapper.class).getPorts(condition); + } + + @Override + public int deletePort(String id) { + return getMapperManager(PortMapper.class).deletePort(id); + } + + @Override + public int deletePortByVimId(String vimId) { + return getMapperManager(PortMapper.class).deletePortByVimId(vimId); + } + + @Override + public int addPort(PortEntity portEntity) { + return getMapperManager(PortMapper.class).addPort(portEntity); + } + + @Override + public int addPortSelective(PortEntity portEntity) { + return getMapperManager(PortMapper.class).addPortSelective(portEntity); + } + + @Override + public int updatePortSelective(PortEntity portEntity) { + return getMapperManager(PortMapper.class).updatePortSelective(portEntity); + } + + @Override + public int updatePort(PortEntity portEntity) { + return getMapperManager(PortMapper.class).updatePort(portEntity); + } + + @Override + public int updatePortByVimId(PortEntity portEntity) { + return getMapperManager(PortMapper.class).updatePortByVimId(portEntity); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/SitesDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/SitesDaoImpl.java new file mode 100644 index 0000000..0aec201 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/SitesDaoImpl.java @@ -0,0 +1,77 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.SitesDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.SitesMapper; + +/** + * DC interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public class SitesDaoImpl extends AbstractDao implements SitesDao { + + @Override + public SitesEntity getSite(String id) { + return getMapperManager(SitesMapper.class).getSite(id); + } + + @Override + public List getSites(Map condition) { + return getMapperManager(SitesMapper.class).getSites(condition); + } + + @Override + public int deleteSite(String id) { + return getMapperManager(SitesMapper.class).deleteSite(id); + } + + @Override + public int addSite(SitesEntity sitesEntity) { + return getMapperManager(SitesMapper.class).addSite(sitesEntity); + } + + @Override + public int addSiteSelective(SitesEntity sitesEntity) { + return getMapperManager(SitesMapper.class).addSiteSelective(sitesEntity); + } + + @Override + public int updateSiteSelective(SitesEntity sitesEntity) { + return getMapperManager(SitesMapper.class).updateSiteSelective(sitesEntity); + } + + @Override + public int updateSite(SitesEntity sitesEntity) { + return getMapperManager(SitesMapper.class).updateSite(sitesEntity); + } + + @Override + public int updateSiteByVimId(SitesEntity sitesEntity) { + return getMapperManager(SitesMapper.class).updateSiteByVimId(sitesEntity); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VimDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VimDaoImpl.java new file mode 100644 index 0000000..e450300 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VimDaoImpl.java @@ -0,0 +1,55 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; + +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VimDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VimMapper; + +/** + * Vim interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public class VimDaoImpl extends AbstractDao implements VimDao { + + @Override + public VimEntity getVim(String id) { + return getMapperManager(VimMapper.class).getVim(id); + } + + @Override + public List getVims() { + return getMapperManager(VimMapper.class).getVims(); + } + + @Override + public int deleteVim(String id) { + return getMapperManager(VimMapper.class).deleteVim(id); + } + + @Override + public int addVim(VimEntity vimEntity) { + return getMapperManager(VimMapper.class).addVim(vimEntity); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImpl.java new file mode 100644 index 0000000..e93b9ad --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImpl.java @@ -0,0 +1,84 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VirtualLinkDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VirtualLinkMapper; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public class VirtualLinkDaoImpl extends AbstractDao implements VirtualLinkDao { + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public VirtualLinkEntity getVl(String id) { + return getMapperManager(VirtualLinkMapper.class).selectByPrimaryKey(id); + } + + /** + *
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + @Override + public List getVls(Map condition) { + return getMapperManager(VirtualLinkMapper.class).getVls(condition); + } + + /** + *
+ * + * @param virtualLinkEntity + * @return + * @since NFVO 0.5 + */ + @Override + public int addVl(VirtualLinkEntity virtualLinkEntity) { + return getMapperManager(VirtualLinkMapper.class).insert(virtualLinkEntity); + } + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public int deleteVlById(String id) { + return getMapperManager(VirtualLinkMapper.class).deleteByPrimaryKey(id); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VmDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VmDaoImpl.java new file mode 100644 index 0000000..5e7d34a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VmDaoImpl.java @@ -0,0 +1,108 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VmDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VmMapper; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public class VmDaoImpl extends AbstractDao implements VmDao { + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public VmEntity getVm(String id) { + return getMapperManager(VmMapper.class).selectByPrimaryKey(id); + } + + /** + *
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + @Override + public List getVms(Map condition) { + return getMapperManager(VmMapper.class).getVms(condition); + } + + /** + *
+ * + * @param vmEntity + * @return + * @since NFVO 0.5 + */ + @Override + public int addVm(VmEntity vmEntity) { + return getMapperManager(VmMapper.class).insert(vmEntity); + } + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public int deleteVmById(String id) { + return getMapperManager(VmMapper.class).deleteByPrimaryKey(id); + } + + /** + *
+ * + * @param vmEntity + * @return + * @since NFVO 0.5 + */ + @Override + public int updateVm(VmEntity vmEntity) { + return getMapperManager(VmMapper.class).updateByPrimaryKeySelective(vmEntity); + } + + /** + *
+ * + * @param vnfInstanceId + * @return + * @since NFVO 0.5 + */ + @Override + public int deleteVmByVnfId(String vnfInstanceId) { + return getMapperManager(VmMapper.class).deleteByVnfId(vnfInstanceId); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfDaoImpl.java new file mode 100644 index 0000000..565089a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfDaoImpl.java @@ -0,0 +1,84 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VnfDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VnfMapper; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public class VnfDaoImpl extends AbstractDao implements VnfDao { + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public VnfEntity getVnf(String id) { + return getMapperManager(VnfMapper.class).selectByPrimaryKey(id); + } + + /** + *
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + @Override + public List getVnfs(Map condition) { + return getMapperManager(VnfMapper.class).getVnfs(condition); + } + + /** + *
+ * + * @param vnfEntity + * @return + * @since NFVO 0.5 + */ + @Override + public int addVnf(VnfEntity vnfEntity) { + return getMapperManager(VnfMapper.class).insert(vnfEntity); + } + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public int deleteVnfById(String id) { + return getMapperManager(VnfMapper.class).deleteByPrimaryKey(id); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfInfoDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfInfoDaoImpl.java new file mode 100644 index 0000000..f2369c3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfInfoDaoImpl.java @@ -0,0 +1,96 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VnfInfoDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VnfInfoMapper; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public class VnfInfoDaoImpl extends AbstractDao implements VnfInfoDao { + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public VnfInfoEntity getVnfInfo(String id) { + return getMapperManager(VnfInfoMapper.class).selectByPrimaryKey(id); + } + + /** + *
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + @Override + public List getVnfInfos(Map condition) { + return getMapperManager(VnfInfoMapper.class).getVnfInfos(condition); + } + + /** + *
+ * + * @param vmEntity + * @return + * @since NFVO 0.5 + */ + @Override + public int addVnfInfo(VnfInfoEntity vnfInfoEntity) { + return getMapperManager(VnfInfoMapper.class).insert(vnfInfoEntity); + } + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public int deleteVnfInfoById(String id) { + return getMapperManager(VnfInfoMapper.class).deleteByPrimaryKey(id); + } + + /** + *
+ * + * @param vnfInfoEntity + * @return + * @since NFVO 0.5 + */ + @Override + public int updateVnfInfo(VnfInfoEntity vnfInfoEntity) { + return getMapperManager(VnfInfoMapper.class).updateByPrimaryKeySelective(vnfInfoEntity); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfStatusDaoImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfStatusDaoImpl.java new file mode 100644 index 0000000..4026e9e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VnfStatusDaoImpl.java @@ -0,0 +1,96 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VnfStatusDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VnfStatusMapper; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +public class VnfStatusDaoImpl extends AbstractDao implements VnfStatusDao { + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public VnfStatusEntity getVnfStatus(String id) { + return getMapperManager(VnfStatusMapper.class).selectByPrimaryKey(id); + } + + /** + *
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + @Override + public List getVnfStatuss(Map condition) { + return getMapperManager(VnfStatusMapper.class).getVnfStatuss(condition); + } + + /** + *
+ * + * @param vnfStatusEntity + * @return + * @since NFVO 0.5 + */ + @Override + public int addVnfStatus(VnfStatusEntity vnfStatusEntity) { + return getMapperManager(VnfStatusMapper.class).insert(vnfStatusEntity); + } + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + @Override + public int deleteVnfStatusById(String id) { + return getMapperManager(VnfStatusMapper.class).deleteByPrimaryKey(id); + } + + /** + *
+ * + * @param vnfStatusEntity + * @return + * @since NFVO 0.5 + */ + @Override + public int updateVnfStatus(VnfStatusEntity vnfStatusEntity) { + return getMapperManager(VnfStatusMapper.class).updateByPrimaryKeySelective(vnfStatusEntity); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/HostDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/HostDao.java new file mode 100644 index 0000000..79e32a1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/HostDao.java @@ -0,0 +1,114 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; + +/** + * Host info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface HostDao { + + /** + * It is used to get Host info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + HostEntity getHost(String id); + + /** + * It is used to get Hosts info.
+ * + * @param condition + * @return The get result + * @since NFVO 0.5 + */ + List getHosts(Map condition); + + /** + * It is used to delete Hosts info.
+ * + * @param id + * @return The delete result + * @since NFVO 0.5 + */ + int deleteHost(String id); + + /** + * It is used to delete Hosts info.
+ * + * @param vimId + * @return The delete result + * @since NFVO 0.5 + */ + int deleteHostByVimId(String vimId); + + /** + * It is used to add Hosts info.
+ * + * @param hostEntity + * @return The add result + * @since NFVO 0.5 + */ + int addHost(HostEntity hostEntity); + + /** + * It is used to add Hosts info.
+ * + * @param hostEntity + * @return The add result + * @since NFVO 0.5 + */ + int addHostSelective(HostEntity hostEntity); + + /** + * It is used to update Hosts info.
+ * + * @param hostEntity + * @return The update result + * @since NFVO 0.5 + */ + int updateHostSelective(HostEntity hostEntity); + + /** + * It is used to update Hosts info.
+ * + * @param hostEntity + * @return The update result + * @since NFVO 0.5 + */ + int updateHost(HostEntity hostEntity); + + /** + * It is used to update Hosts info.
+ * + * @param hostEntity + * @return The update result + * @since NFVO 0.5 + */ + int updateHostByVimId(HostEntity hostEntity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/LocationDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/LocationDao.java new file mode 100644 index 0000000..e40cb13 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/LocationDao.java @@ -0,0 +1,123 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; + +/** + * + * Location DAO Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface LocationDao { + + /** + * + * Get Location.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + LocationEntity getLocation(String id); + + /** + * + * Get Locations.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getLocations(Map condition); + + /** + * + * Delete Location.
+ * + * @param location + * @return + * @since NFVO 0.5 + */ + int deleteLocation(String location); + + /** + * + * Add Location.
+ * + * @param sodoResEntity + * @return + * @since NFVO 0.5 + */ + int addLocation(LocationEntity sodoResEntity); + + /** + * + * Add Selective Location.
+ * + * @param sodoResEntity + * @return + * @since NFVO 0.5 + */ + int addLocationSelective(LocationEntity sodoResEntity); + + /** + * + * Update selective location.
+ * + * @param sodoResEntity + * @return + * @since NFVO 0.5 + */ + int updateLocationSelective(LocationEntity sodoResEntity); + + /** + * + * Update Location.
+ * + * @param sodoResEntity + * @return + * @since NFVO 0.5 + */ + int updateLocation(LocationEntity sodoResEntity); + + /** + * + * Get Country.
+ * + * @return + * @since NFVO 0.5 + */ + List getCountry(); + + /** + * + * Get Location by Country.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getLocationByCountry(Map condition); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/NetworkDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/NetworkDao.java new file mode 100644 index 0000000..ed6ce69 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/NetworkDao.java @@ -0,0 +1,125 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; + +/** + * + * Network DOA Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface NetworkDao { + + /** + * + * Get Network Details.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + NetworkEntity getNetwork(String id); + + /** + * + * Get details of available networks.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getNetworks(Map condition); + + /** + * + * Delete Network.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + int deleteNetwork(String id); + + /** + * + * Delete network by VIM ID.
+ * + * @param vimId + * @return + * @since NFVO 0.5 + */ + int deleteNetworkByVimId(String vimId); + + /** + * + * Add Network.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int addNetwork(NetworkEntity networkEntity); + + /** + * + * Add selective network.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int addNetworkSelective(NetworkEntity networkEntity); + + /** + * + * Update selective network.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int updateNetworkSelective(NetworkEntity networkEntity); + + /** + * + * Update network.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int updateNetwork(NetworkEntity networkEntity); + + /** + * + * Update network by VIM ID.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int updateNetworkByVimId(NetworkEntity networkEntity); + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/PortDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/PortDao.java new file mode 100644 index 0000000..3514194 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/PortDao.java @@ -0,0 +1,114 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; + +/** + * Port info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface PortDao { + + /** + * It is used to get Port info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + PortEntity getPort(String id); + + /** + * It is used to get Ports info.
+ * + * @param condition + * @return The get result + * @since NFVO 0.5 + */ + List getPorts(Map condition); + + /** + * It is used to delete Ports info.
+ * + * @param id + * @return The delete result + * @since NFVO 0.5 + */ + int deletePort(String id); + + /** + * It is used to delete Ports info.
+ * + * @param vimId + * @return The delete result + * @since NFVO 0.5 + */ + int deletePortByVimId(String vimId); + + /** + * It is used to add Ports info.
+ * + * @param portEntity + * @return The add result + * @since NFVO 0.5 + */ + int addPort(PortEntity portEntity); + + /** + * It is used to add Ports info.
+ * + * @param portEntity + * @return The add result + * @since NFVO 0.5 + */ + int addPortSelective(PortEntity portEntity); + + /** + * It is used to update Ports info.
+ * + * @param portEntity + * @return The update result + * @since NFVO 0.5 + */ + int updatePortSelective(PortEntity portEntity); + + /** + * It is used to update Ports info.
+ * + * @param portEntity + * @return The update result + * @since NFVO 0.5 + */ + int updatePort(PortEntity portEntity); + + /** + * It is used to update Ports info.
+ * + * @param portEntity + * @return The update result + * @since NFVO 0.5 + */ + int updatePortByVimId(PortEntity portEntity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/SitesDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/SitesDao.java new file mode 100644 index 0000000..b085c8d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/SitesDao.java @@ -0,0 +1,105 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; + +/** + * Sites info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface SitesDao { + + /** + * It is used to get Sites info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + SitesEntity getSite(String id); + + /** + * It is used to get Sites info.
+ * + * @param condition + * @return The get result + * @since NFVO 0.5 + */ + List getSites(Map condition); + + /** + * It is used to get Sites info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + int deleteSite(String id); + + /** + * It is used to delete Sites info.
+ * + * @param sitesEntity + * @return The delete result + * @since NFVO 0.5 + */ + int addSite(SitesEntity sitesEntity); + + /** + * It is used to add Sites info.
+ * + * @param sitesEntity + * @return The add result + * @since NFVO 0.5 + */ + int addSiteSelective(SitesEntity sitesEntity); + + /** + * It is used to add Sites info.
+ * + * @param sitesEntity + * @return The add result + * @since NFVO 0.5 + */ + int updateSiteSelective(SitesEntity sitesEntity); + + /** + * It is used to update Sites info.
+ * + * @param sitesEntity + * @return The update result + * @since NFVO 0.5 + */ + int updateSite(SitesEntity sitesEntity); + + /** + * It is used to update Sites info.
+ * + * @param sitesEntity + * @return The update result + * @since NFVO 0.5 + */ + int updateSiteByVimId(SitesEntity sitesEntity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VimDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VimDao.java new file mode 100644 index 0000000..fd4cd80 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VimDao.java @@ -0,0 +1,68 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; + +/** + * Vim info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface VimDao { + + /** + * It is used to get Vim info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + VimEntity getVim(String id); + + /** + * It is used to get Vims info.
+ * + * @return The get result + * @since NFVO 0.5 + */ + List getVims(); + + /** + * It is used to delete Vim info.
+ * + * @param id + * @return The delete result + * @since NFVO 0.5 + */ + int deleteVim(String id); + + /** + * It is used to add Vim info.
+ * + * @param vimEntity + * @return The add result + * @since NFVO 0.5 + */ + int addVim(VimEntity vimEntity); + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VirtualLinkDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VirtualLinkDao.java new file mode 100644 index 0000000..04c0bc1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VirtualLinkDao.java @@ -0,0 +1,69 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VirtualLinkEntity; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public interface VirtualLinkDao { + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + VirtualLinkEntity getVl(String id); + + /** + *
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getVls(Map condition); + + /** + *
+ * + * @param virtualLinkEntity + * @return + * @since NFVO 0.5 + */ + int addVl(VirtualLinkEntity virtualLinkEntity); + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + int deleteVlById(String id); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VmDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VmDao.java new file mode 100644 index 0000000..5572cee --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VmDao.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public interface VmDao { + + VmEntity getVm(String id); + + List getVms(Map condition); + + int addVm(VmEntity vmEntity); + + int deleteVmById(String id); + + int updateVm(VmEntity vmEntity); + + int deleteVmByVnfId(String vnfInstanceId); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfDao.java new file mode 100644 index 0000000..4a34f22 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfDao.java @@ -0,0 +1,69 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public interface VnfDao { + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + VnfEntity getVnf(String id); + + /** + *
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getVnfs(Map condition); + + /** + *
+ * + * @param vnfEntity + * @return + * @since NFVO 0.5 + */ + int addVnf(VnfEntity vnfEntity); + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + int deleteVnfById(String id); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfInfoDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfInfoDao.java new file mode 100644 index 0000000..e96c636 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfInfoDao.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfInfoEntity; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public interface VnfInfoDao { + + VnfInfoEntity getVnfInfo(String id); + + List getVnfInfos(Map condition); + + int addVnfInfo(VnfInfoEntity vnfInfoEntity); + + int deleteVnfInfoById(String id); + + int updateVnfInfo(VnfInfoEntity vnfInfoEntity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfStatusDao.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfStatusDao.java new file mode 100644 index 0000000..852ea98 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/dao/inf/VnfStatusDao.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfStatusEntity; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +public interface VnfStatusDao { + + VnfStatusEntity getVnfStatus(String id); + + List getVnfStatuss(Map condition); + + int addVnfStatus(VnfStatusEntity vnfStatusEntity); + + int deleteVnfStatusById(String id); + + int updateVnfStatus(VnfStatusEntity vnfStatusEntity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/HostEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/HostEntity.java new file mode 100644 index 0000000..b948fd9 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/HostEntity.java @@ -0,0 +1,179 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * Host entity class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 31, 2016 + */ +public class HostEntity { + + private String id; + + private String name; + + private String cpu; + + private String memory; + + private String disk; + + private String vimId; + + private String vimName; + + /** + * @return Returns the id. + */ + public String getId() { + return id; + } + + /** + * @param id The id to set. + */ + public void setId(String id) { + this.id = id; + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return Returns the cpu. + */ + public String getCpu() { + return cpu; + } + + /** + * @param cpu The cpu to set. + */ + public void setCpu(String cpu) { + this.cpu = cpu; + } + + /** + * @return Returns the memory. + */ + public String getMemory() { + return memory; + } + + /** + * @param memory The memory to set. + */ + public void setMemory(String memory) { + this.memory = memory; + } + + /** + * @return Returns the disk. + */ + public String getDisk() { + return disk; + } + + /** + * @param disk The disk to set. + */ + public void setDisk(String disk) { + this.disk = disk; + } + + /** + * @return Returns the vimId. + */ + public String getVimId() { + return vimId; + } + + /** + * @param vimId The vimId to set. + */ + public void setVimId(String vimId) { + this.vimId = vimId; + } + + /** + * @return Returns the vimName. + */ + public String getVimName() { + return vimName; + } + + /** + * @param vimName The vimName to set. + */ + public void setVimName(String vimName) { + this.vimName = vimName; + } + + /** + * + * To entity.
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static HostEntity toEntity(JSONObject jsonObject) { + HostEntity hostEntity = new HostEntity(); + hostEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); + hostEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); + hostEntity.setCpu(JsonUtil.getJsonFieldStr(jsonObject, "cpu")); + hostEntity.setMemory(JsonUtil.getJsonFieldStr(jsonObject, "memory")); + hostEntity.setDisk(JsonUtil.getJsonFieldStr(jsonObject, "disk")); + hostEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); + hostEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); + return hostEntity; + } + + @Override + public String toString() { + JSONObject hostResJson = new JSONObject(); + hostResJson.put("id", StringUtils.trimToEmpty(this.getId())); + hostResJson.put("name", StringUtils.trimToEmpty(this.getName())); + hostResJson.put("cpu", StringUtils.trimToEmpty(this.getCpu())); + hostResJson.put("memory", StringUtils.trimToEmpty(this.getMemory())); + hostResJson.put("disk", StringUtils.trimToEmpty(this.getDisk())); + hostResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); + hostResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); + return hostResJson.toString(); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/LocationEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/LocationEntity.java new file mode 100644 index 0000000..657c1a0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/LocationEntity.java @@ -0,0 +1,236 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * + * Location entity class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class LocationEntity { + + /** + * This field was generated by MyBatis Generator. This field corresponds to + * the database column location.ID + * + * @mbggenerated + */ + private String id; + + /** + * This field was generated by MyBatis Generator. This field corresponds to + * the database column location.COUNTRY + * + * @mbggenerated + */ + private String country; + + /** + * This field was generated by MyBatis Generator. This field corresponds to + * the database column location.LOCATION + * + * @mbggenerated + */ + private String location; + + /** + * This field was generated by MyBatis Generator. This field corresponds to + * the database column location.LATITUDE + * + * @mbggenerated + */ + private String latitude; + + /** + * This field was generated by MyBatis Generator. This field corresponds to + * the database column location.LONGITUDE + * + * @mbggenerated + */ + private String longitude; + + private String description; + + /** + * This method was generated by MyBatis Generator. This method returns the + * value of the database column location.ID + * + * @return the value of location.ID + * @mbggenerated + */ + public String getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. This method sets the + * value of the database column location.ID + * + * @param id + * the value for location.ID + * @mbggenerated + */ + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + /** + * This method was generated by MyBatis Generator. This method returns the + * value of the database column location.COUNTRY + * + * @return the value of location.COUNTRY + * @mbggenerated + */ + public String getCountry() { + return country; + } + + /** + * This method was generated by MyBatis Generator. This method sets the + * value of the database column location.COUNTRY + * + * @param country + * the value for location.COUNTRY + * @mbggenerated + */ + public void setCountry(String country) { + this.country = country == null ? null : country.trim(); + } + + /** + * This method was generated by MyBatis Generator. This method returns the + * value of the database column location.LOCATION + * + * @return the value of location.LOCATION + * @mbggenerated + */ + public String getLocation() { + return location; + } + + /** + * This method was generated by MyBatis Generator. This method sets the + * value of the database column location.LOCATION + * + * @param location + * the value for location.LOCATION + * @mbggenerated + */ + public void setLocation(String location) { + this.location = location == null ? null : location.trim(); + } + + /** + * This method was generated by MyBatis Generator. This method returns the + * value of the database column location.LATITUDE + * + * @return the value of location.LATITUDE + * @mbggenerated + */ + public String getLatitude() { + return latitude; + } + + /** + * This method was generated by MyBatis Generator. This method sets the + * value of the database column location.LATITUDE + * + * @param latitude + * the value for location.LATITUDE + * @mbggenerated + */ + public void setLatitude(String latitude) { + this.latitude = latitude == null ? null : latitude.trim(); + } + + /** + * This method was generated by MyBatis Generator. This method returns the + * value of the database column location.LONGITUDE + * + * @return the value of location.LONGITUDE + * @mbggenerated + */ + public String getLongitude() { + return longitude; + } + + /** + * This method was generated by MyBatis Generator. This method sets the + * value of the database column location.LONGITUDE + * + * @param longitude + * the value for location.LONGITUDE + * @mbggenerated + */ + public void setLongitude(String longitude) { + this.longitude = longitude == null ? null : longitude.trim(); + } + + /** + * @return Returns the description. + */ + public String getDescription() { + return description; + } + + /** + * @param description The description to set. + */ + public void setDescription(String description) { + this.description = description == null ? null : description.trim(); + } + + /** + * + * To Entity.
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static LocationEntity toEntity(JSONObject jsonObject) { + LocationEntity sodoresesEntity = new LocationEntity(); + sodoresesEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); + sodoresesEntity.setCountry(JsonUtil.getJsonFieldStr(jsonObject, "country")); + sodoresesEntity.setLocation(JsonUtil.getJsonFieldStr(jsonObject, "location")); + sodoresesEntity.setLatitude(JsonUtil.getJsonFieldStr(jsonObject, "latitude")); + sodoresesEntity.setLongitude(JsonUtil.getJsonFieldStr(jsonObject, "longitude")); + sodoresesEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description")); + return sodoresesEntity; + } + + @Override + public String toString() { + JSONObject locationJson = new JSONObject(); + locationJson.put("id", StringUtils.trimToEmpty(this.getId())); + locationJson.put("country", StringUtils.trimToEmpty(this.getCountry())); + locationJson.put("location", StringUtils.trimToEmpty(this.getLocation())); + locationJson.put("latitude", StringUtils.trimToEmpty(this.getLatitude())); + locationJson.put("longitude", StringUtils.trimToEmpty(this.getLongitude())); + locationJson.put("description", StringUtils.trimToEmpty(this.getDescription())); + return locationJson.toString(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NetworkEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NetworkEntity.java new file mode 100644 index 0000000..9d4948e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/NetworkEntity.java @@ -0,0 +1,271 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * + * Network entity class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class NetworkEntity { + + /** + * This field corresponds to the database column network.ID + */ + private String id; + + /** + * This field corresponds to the database column network.NAME + */ + private String name; + + /** + * This field corresponds to the database column network.TENANT_ID + */ + private String tenantId; + + /** + * This field corresponds to the database column network.VIM_ID + */ + private String vimId; + + /** + * This field corresponds to the database column ivm.VIM_NAME + */ + private String vimName; + + /** + * This field corresponds to the database column network.STATUS + */ + private String status; + + /** + * This field corresponds to the database column network.PHYSICAL_NETWORK + */ + + private String physicalNetwork; + + /** + * This field corresponds to the database column network.NETWORK_TYPE + */ + private String networkType; + + /** + * This field corresponds to the database column network.SEGMENTATION_ID + */ + private String segmentationId; + + /** + * return the value of network.ID + */ + public String getId() { + return id; + } + + /** + * This method sets the value of the database column network.ID + * + * @param id + * the value for network.ID + */ + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + /** + * return the value of network.NAME + */ + public String getName() { + return name; + } + + /** + * This method sets the value of the database column network.NAME + * + * @param name + * the value for network.NAME + */ + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + /** + * return the value of network.TENANT_ID + */ + public String getTenantId() { + return tenantId; + } + + /** + * This method sets the value of the database column network.TENANT_ID + * + * @param tenantId + * the value for network.TENANT_ID + */ + public void setTenantId(String tenantId) { + this.tenantId = tenantId == null ? null : tenantId.trim(); + } + + /** + * return the value of network.VIM_ID + */ + public String getVimId() { + return vimId; + } + + /** + * This method sets the value of the database column network.VIM_ID + * + * @param networkVimId + * the value for network.VIM_ID + */ + public void setVimId(String networkVimId) { + this.vimId = networkVimId == null ? null : networkVimId.trim(); + } + + /** + * return the value of ivm.VIM_NAME + */ + public String getVimName() { + return vimName; + } + + /** + * This method sets the value of the database column ivm.VIM_NAME + * + * @param networkVimName + * the value for ivm.VIM_NAME + */ + public void setVimName(String networkVimName) { + this.vimName = networkVimName == null ? null : networkVimName.trim(); + } + + /** + * return the value of network.STATUS + */ + public String getStatus() { + return status; + } + + /** + * This method sets the value of the database column network.STATUS + * + * @param networkStatus + * the value for network.STATUS + */ + public void setStatus(String networkStatus) { + this.status = networkStatus == null ? null : networkStatus.trim().toLowerCase(); + } + + /** + * return the value of network.PHYSICAL_NETWORK + */ + public String getPhysicalNetwork() { + return physicalNetwork; + } + + /** + * This method sets the value of the database column + * network.PHYSICAL_NETWORK + * + * @param physicalNetwork + * the value for network.PHYSICAL_NETWORK + */ + public void setPhysicalNetwork(String physicalNetwork) { + this.physicalNetwork = physicalNetwork == null ? null : physicalNetwork.trim(); + } + + /** + * return the value of network.NETWORK_TYPE + */ + public String getNetworkType() { + return networkType; + } + + /** + * This method sets the value of the database column network.NETWORK_TYPE + * + * @param networkType + * the value for network.NETWORK_TYPE + */ + public void setNetworkType(String networkType) { + this.networkType = networkType == null ? null : networkType.trim(); + } + + /** + * return the value of network.SEGMENTATION_ID + */ + public String getSegmentationId() { + return segmentationId; + } + + /** + * This method sets the value of the database column network.SEGMENTATION_ID + * + * @param segmentationId + * the value for network.SEGMENTATION_ID + */ + public void setSegmentationId(String segmentationId) { + this.segmentationId = segmentationId == null ? null : segmentationId.trim(); + } + + /** + * + * To Entity.
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static NetworkEntity toEntity(JSONObject jsonObject) { + NetworkEntity sitesEntity = new NetworkEntity(); + sitesEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); + sitesEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); + sitesEntity.setTenantId(JsonUtil.getJsonFieldStr(jsonObject, "tenantId")); + sitesEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status")); + sitesEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); + sitesEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); + sitesEntity.setPhysicalNetwork(JsonUtil.getJsonFieldStr(jsonObject, "physicalNetwork")); + sitesEntity.setNetworkType(JsonUtil.getJsonFieldStr(jsonObject, "networkType")); + sitesEntity.setSegmentationId(JsonUtil.getJsonFieldStr(jsonObject, "segmentationId")); + return sitesEntity; + } + + @Override + public String toString() { + JSONObject networkJson = new JSONObject(); + networkJson.put("id", StringUtils.trimToEmpty(this.getId())); + networkJson.put("name", StringUtils.trimToEmpty(this.getName())); + networkJson.put("tenant_id", StringUtils.trimToEmpty(this.getTenantId())); + networkJson.put("status", StringUtils.trimToEmpty(this.getStatus())); + networkJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); + networkJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); + networkJson.put("provider:physical_network", StringUtils.trimToEmpty(this.getPhysicalNetwork())); + networkJson.put("provider:network_type", StringUtils.trimToEmpty(this.getNetworkType())); + networkJson.put("provider:segmentation_id", StringUtils.trimToEmpty(this.getSegmentationId())); + return networkJson.toString(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/PortEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/PortEntity.java new file mode 100644 index 0000000..6aa9c39 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/PortEntity.java @@ -0,0 +1,179 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * Port Entity Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 31, 2016 + */ +public class PortEntity { + + private String id; + + private String name; + + private String networkId; + + private String status; + + private String tenantId; + + private String vimId; + + private String vimName; + + /** + * @return Returns the id. + */ + public String getId() { + return id; + } + + /** + * @param id The id to set. + */ + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + /** + * @return Returns the name. + */ + public String getName() { + return name; + } + + /** + * @param name The name to set. + */ + public void setName(String name) { + this.name = name; + } + + /** + * @return Returns the networkId. + */ + public String getNetworkId() { + return networkId; + } + + /** + * @param networkId The networkId to set. + */ + public void setNetworkId(String networkId) { + this.networkId = networkId; + } + + /** + * @return Returns the status. + */ + public String getStatus() { + return status; + } + + /** + * @param status The status to set. + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * @return Returns the tenantId. + */ + public String getTenantId() { + return tenantId; + } + + /** + * @param tenantId The tenantId to set. + */ + public void setTenantId(String tenantId) { + this.tenantId = tenantId; + } + + /** + * @return Returns the vimId. + */ + public String getVimId() { + return vimId; + } + + /** + * @param vimId The vimId to set. + */ + public void setVimId(String vimId) { + this.vimId = vimId; + } + + /** + * @return Returns the vimName. + */ + public String getVimName() { + return vimName; + } + + /** + * @param vimName The vimName to set. + */ + public void setVimName(String vimName) { + this.vimName = vimName; + } + + /** + * + * To Entity.
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static PortEntity toEntity(JSONObject jsonObject) { + PortEntity portEntity = new PortEntity(); + portEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); + portEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); + portEntity.setNetworkId(JsonUtil.getJsonFieldStr(jsonObject, "networkId")); + portEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status")); + portEntity.setTenantId(JsonUtil.getJsonFieldStr(jsonObject, "tenantId")); + portEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); + portEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); + return portEntity; + } + + @Override + public String toString() { + JSONObject portResJson = new JSONObject(); + portResJson.put("id", StringUtils.trimToEmpty(this.getId())); + portResJson.put("name", StringUtils.trimToEmpty(this.getName())); + portResJson.put("networkId", StringUtils.trimToEmpty(this.getNetworkId())); + portResJson.put("status", StringUtils.trimToEmpty(this.getStatus())); + portResJson.put("tenantId", StringUtils.trimToEmpty(this.getTenantId())); + portResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); + portResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); + return portResJson.toString(); + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/SitesEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/SitesEntity.java new file mode 100644 index 0000000..b0aa27b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/SitesEntity.java @@ -0,0 +1,309 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.StringUtil; + +import net.sf.json.JSONObject; + +/** + * + * Sites entity class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class SitesEntity { + + private String id; + + private String name; + + private String location; + + private String country; + + private String vimId; + + private String vimName; + + private String status; + + private String totalCPU = "0"; + + private String totalMemory = "0"; + + private String totalDisk = "0"; + + private String usedCPU = "0"; + + private String usedMemory = "0"; + + private String usedDisk = "0"; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name == null ? null : name.trim(); + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location == null ? null : location.trim(); + } + + public String getCountry() { + return country; + } + + public void setCountry(String country) { + this.country = country == null ? null : country.trim(); + } + + public String getVimId() { + return vimId; + } + + public void setVimId(String siteVimId) { + this.vimId = siteVimId == null ? null : siteVimId.trim(); + } + + public String getVimName() { + return vimName; + } + + public void setVimName(String siteVimName) { + this.vimName = siteVimName == null ? null : siteVimName.trim(); + } + + public String getStatus() { + return status; + } + + public void setStatus(String siteStatus) { + this.status = siteStatus == null ? null : siteStatus.trim().toLowerCase(); + } + + /** + * @return Returns the totalCPU. + */ + public String getTotalCPU() { + return totalCPU; + } + + /** + * @param totalCPU The totalCPU to set. + */ + public void setTotalCPU(String totalCPU) { + this.totalCPU = totalCPU == null ? null : totalCPU.trim(); + } + + /** + * @return Returns the totalMemory. + */ + public String getTotalMemory() { + return totalMemory; + } + + /** + * @param totalMemory The totalMemory to set. + */ + public void setTotalMemory(String totalMemory) { + this.totalMemory = totalMemory == null ? null : totalMemory.trim(); + } + + /** + * @return Returns the totalDisk. + */ + public String getTotalDisk() { + return totalDisk; + } + + /** + * @param totalDisk The totalDisk to set. + */ + public void setTotalDisk(String totalDisk) { + this.totalDisk = totalDisk == null ? null : totalDisk.trim(); + } + + /** + * @return Returns the usedCPU. + */ + public String getUsedCPU() { + return usedCPU; + } + + /** + * @param usedCPU The usedCPU to set. + */ + public void setUsedCPU(String usedCPU) { + this.usedCPU = usedCPU == null ? null : usedCPU.trim(); + } + + /** + * @return Returns the usedMemory. + */ + public String getUsedMemory() { + return usedMemory; + } + + /** + * @param usedMemory The usedMemory to set. + */ + public void setUsedMemory(String usedMemory) { + this.usedMemory = usedMemory == null ? null : usedMemory.trim(); + } + + /** + * @return Returns the usedDisk. + */ + public String getUsedDisk() { + return usedDisk; + } + + /** + * @param usedDisk The usedDisk to set. + */ + public void setUsedDisk(String usedDisk) { + this.usedDisk = usedDisk == null ? null : usedDisk.trim(); + } + + /** + * + * To Entity.
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static SitesEntity toEntity(JSONObject jsonObject) { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); + sitesEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); + sitesEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status")); + sitesEntity.setLocation(JsonUtil.getJsonFieldStr(jsonObject, "location")); + sitesEntity.setCountry(JsonUtil.getJsonFieldStr(jsonObject, "country")); + sitesEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); + sitesEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); + sitesEntity.setTotalCPU(JsonUtil.getJsonFieldStr(jsonObject, "totalCPU")); + sitesEntity.setTotalMemory(JsonUtil.getJsonFieldStr(jsonObject, "totalMemory")); + sitesEntity.setTotalDisk(JsonUtil.getJsonFieldStr(jsonObject, "totalDisk")); + sitesEntity.setUsedCPU(JsonUtil.getJsonFieldStr(jsonObject, "usedCPU")); + sitesEntity.setUsedMemory(JsonUtil.getJsonFieldStr(jsonObject, "usedMemory")); + sitesEntity.setUsedDisk(JsonUtil.getJsonFieldStr(jsonObject, "usedDisk")); + return sitesEntity; + } + + @Override + public String toString() { + JSONObject siteResJson = new JSONObject(); + siteResJson.put("id", StringUtils.trimToEmpty(this.getId())); + siteResJson.put("name", StringUtils.trimToEmpty(this.getName())); + siteResJson.put("status", StringUtils.trimToEmpty(this.getStatus())); + siteResJson.put("location", StringUtils.trimToEmpty(this.getLocation())); + siteResJson.put("country", StringUtils.trimToEmpty(this.getCountry())); + siteResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); + siteResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); + siteResJson.put("totalCPU", StringUtils.trimToEmpty(this.getTotalCPU())); + siteResJson.put("totalMemory", StringUtils.trimToEmpty(this.getTotalMemory())); + siteResJson.put("totalDisk", StringUtils.trimToEmpty(this.getTotalDisk())); + siteResJson.put("usedCPU", StringUtils.trimToEmpty(this.getUsedCPU())); + siteResJson.put("usedMemory", StringUtils.trimToEmpty(this.getUsedMemory())); + siteResJson.put("usedDisk", StringUtils.trimToEmpty(this.getUsedDisk())); + + return siteResJson.toString(); + } + + /** + * + * Check whther the resource is zero.
+ * + * @param siteEntity + * @return + * @since NFVO 0.5 + */ + public static boolean checkResourceIsZero(SitesEntity siteEntity) { + + if(StringUtil.isAnyLargeThanZero(siteEntity.getUsedCPU(), siteEntity.getUsedMemory(), + siteEntity.getUsedDisk())) { + return false; + } + + return true; + } + + /** + * + * Check resource.
+ * + * @param siteEntity + * @return + * @since NFVO 0.5 + */ + public static boolean checkResource(SitesEntity siteEntity) { + String cpu = siteEntity.getTotalCPU(); + String memory = siteEntity.getTotalMemory(); + String disk = siteEntity.getTotalDisk(); + String cpuUsed = siteEntity.getUsedCPU(); + String memoryUsed = siteEntity.getUsedMemory(); + String diskUsed = siteEntity.getUsedDisk(); + + if(!StringUtil.isInteger(cpu, cpuUsed)) { + return false; + } + + if(!StringUtil.isNumeric(memory, disk, memoryUsed, diskUsed)) { + return false; + } + return true; + } + + /** + * + * Format data.
+ * + * @param siteEntity + * @since NFVO 0.5 + */ + public static void dataFramat(SitesEntity siteEntity) { + siteEntity.setTotalCPU(StringUtil.numFormat(siteEntity.getTotalCPU())); + siteEntity.setTotalMemory(StringUtil.numFormat(siteEntity.getTotalMemory())); + siteEntity.setTotalDisk(StringUtil.numFormat(siteEntity.getTotalDisk())); + siteEntity.setUsedCPU(StringUtil.numFormat(siteEntity.getUsedCPU())); + siteEntity.setUsedMemory(StringUtil.numFormat(siteEntity.getUsedMemory())); + siteEntity.setUsedDisk(StringUtil.numFormat(siteEntity.getUsedDisk())); + + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VimEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VimEntity.java new file mode 100644 index 0000000..fc0c9e9 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VimEntity.java @@ -0,0 +1,106 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * + * Virtualised infrastructure manager entity class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class VimEntity { + + /** + * This field corresponds to the database column vim.ID + * + * @mbggenerated + */ + private String id; + + /** + * This field corresponds to the database column vim.ID + * + * @mbggenerated + */ + private String name; + + /** + * This method was generated by MyBatis Generator. This method returns the + * value of the database column vim.ID + * + * @return the value of vim.ID + */ + public String getId() { + return id; + } + + /** + * This method was generated by MyBatis Generator. This method sets the + * value of the database column vim.ID + * + * @param id + * the value for vim.ID + */ + public void setId(String id) { + this.id = id == null ? null : id.trim(); + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + * + * To Entity.
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static VimEntity toEntity(JSONObject jsonObject) { + VimEntity vimEntity = new VimEntity(); + vimEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); + vimEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); + return vimEntity; + } + + /** + * + * To String.
+ * + * @return + * @since NFVO 0.5 + */ + public String toString() { + JSONObject resJson = new JSONObject(); + resJson.put("id", StringUtils.trimToEmpty(this.getId())); + resJson.put("name", StringUtils.trimToEmpty(this.getName())); + return resJson.toString(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VirtualLinkEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VirtualLinkEntity.java new file mode 100644 index 0000000..228fa5c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VirtualLinkEntity.java @@ -0,0 +1,285 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * @author l00345485 + * @date 2016-10-27 + */ +public class VirtualLinkEntity implements Serializable { + + /** */ + private String id; + + /** */ + private String name; + + /** */ + private String backendId; + + /** */ + private String isPublic; + + /** */ + private String dcName; + + /** */ + private String vimId; + + /** */ + private String vimName; + + /** */ + private String physicialNet; + + /** */ + private String nsId; + + /** */ + private String nsName; + + /** */ + private String description; + + /** */ + private String networkType; + + /** */ + private String segmentation; + + /** */ + private String mtu; + + /** */ + private String vlanTransparent; + + /** */ + private String routerExternal; + + /** */ + private String resourceProviderType; + + /** */ + private String resourceProviderId; + + private static final long serialVersionUID = 1L; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getBackendId() { + return backendId; + } + + public void setBackendId(String backendId) { + this.backendId = backendId; + } + + public String getIsPublic() { + return isPublic; + } + + public void setIsPublic(String isPublic) { + this.isPublic = isPublic; + } + + public String getDcName() { + return dcName; + } + + public void setDcName(String dcName) { + this.dcName = dcName; + } + + public String getVimId() { + return vimId; + } + + public void setVimId(String vimId) { + this.vimId = vimId; + } + + public String getVimName() { + return vimName; + } + + public void setVimName(String vimName) { + this.vimName = vimName; + } + + public String getPhysicialNet() { + return physicialNet; + } + + public void setPhysicialNet(String physicialNet) { + this.physicialNet = physicialNet; + } + + public String getNsId() { + return nsId; + } + + public void setNsId(String nsId) { + this.nsId = nsId; + } + + public String getNsName() { + return nsName; + } + + public void setNsName(String nsName) { + this.nsName = nsName; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getNetworkType() { + return networkType; + } + + public void setNetworkType(String networkType) { + this.networkType = networkType; + } + + public String getSegmentation() { + return segmentation; + } + + public void setSegmentation(String segmentation) { + this.segmentation = segmentation; + } + + public String getMtu() { + return mtu; + } + + public void setMtu(String mtu) { + this.mtu = mtu; + } + + public String getVlanTransparent() { + return vlanTransparent; + } + + public void setVlanTransparent(String vlanTransparent) { + this.vlanTransparent = vlanTransparent; + } + + public String getRouterExternal() { + return routerExternal; + } + + public void setRouterExternal(String routerExternal) { + this.routerExternal = routerExternal; + } + + public String getResourceProviderType() { + return resourceProviderType; + } + + public void setResourceProviderType(String resourceProviderType) { + this.resourceProviderType = resourceProviderType; + } + + public String getResourceProviderId() { + return resourceProviderId; + } + + public void setResourceProviderId(String resourceProviderId) { + this.resourceProviderId = resourceProviderId; + } + + /** + *
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static VirtualLinkEntity toEntity(JSONObject jsonObject) { + VirtualLinkEntity virtualLinkEntity = new VirtualLinkEntity(); + virtualLinkEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "vlInstanceId")); + virtualLinkEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); + virtualLinkEntity.setBackendId(JsonUtil.getJsonFieldStr(jsonObject, "backendId")); + virtualLinkEntity.setIsPublic(JsonUtil.getJsonFieldStr(jsonObject, "isPublic")); + virtualLinkEntity.setDcName(JsonUtil.getJsonFieldStr(jsonObject, "dcName")); + virtualLinkEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); + virtualLinkEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); + virtualLinkEntity.setPhysicialNet(JsonUtil.getJsonFieldStr(jsonObject, "physicialNet")); + virtualLinkEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId")); + virtualLinkEntity.setNsName(JsonUtil.getJsonFieldStr(jsonObject, "nsName")); + virtualLinkEntity.setDescription(JsonUtil.getJsonFieldStr(jsonObject, "description")); + virtualLinkEntity.setNetworkType(JsonUtil.getJsonFieldStr(jsonObject, "networkType")); + virtualLinkEntity.setSegmentation(JsonUtil.getJsonFieldStr(jsonObject, "segmentation")); + virtualLinkEntity.setMtu(JsonUtil.getJsonFieldStr(jsonObject, "mtu")); + virtualLinkEntity.setVlanTransparent(JsonUtil.getJsonFieldStr(jsonObject, "vlanTransparent")); + virtualLinkEntity.setRouterExternal(JsonUtil.getJsonFieldStr(jsonObject, "routerExternal")); + virtualLinkEntity.setResourceProviderId(JsonUtil.getJsonFieldStr(jsonObject, "resourceProviderId")); + virtualLinkEntity.setResourceProviderType(JsonUtil.getJsonFieldStr(jsonObject, "resourceProviderType")); + return virtualLinkEntity; + } + + @Override + public String toString() { + JSONObject virtualLinkResJson = new JSONObject(); + virtualLinkResJson.put("id", StringUtils.trimToEmpty(this.getId())); + virtualLinkResJson.put("name", StringUtils.trimToEmpty(this.getName())); + virtualLinkResJson.put("backendId", StringUtils.trimToEmpty(this.getBackendId())); + virtualLinkResJson.put("isPublic", StringUtils.trimToEmpty(this.getIsPublic())); + virtualLinkResJson.put("dcName", StringUtils.trimToEmpty(this.getDcName())); + virtualLinkResJson.put("vimId", StringUtils.trimToEmpty(this.getVimId())); + virtualLinkResJson.put("vimName", StringUtils.trimToEmpty(this.getVimName())); + virtualLinkResJson.put("physicialNet", StringUtils.trimToEmpty(this.getPhysicialNet())); + virtualLinkResJson.put("nsId", StringUtils.trimToEmpty(this.getNsId())); + virtualLinkResJson.put("nsName", StringUtils.trimToEmpty(this.getNsName())); + virtualLinkResJson.put("description", StringUtils.trimToEmpty(this.getDescription())); + virtualLinkResJson.put("networkType", StringUtils.trimToEmpty(this.getNetworkType())); + virtualLinkResJson.put("segmentation", StringUtils.trimToEmpty(this.getSegmentation())); + virtualLinkResJson.put("mtu", StringUtils.trimToEmpty(this.getMtu())); + virtualLinkResJson.put("vlanTransparent", StringUtils.trimToEmpty(this.getVlanTransparent())); + virtualLinkResJson.put("routerExternal", StringUtils.trimToEmpty(this.getRouterExternal())); + virtualLinkResJson.put("resourceProviderId", StringUtils.trimToEmpty(this.getResourceProviderId())); + virtualLinkResJson.put("resourceProviderType", StringUtils.trimToEmpty(this.getResourceProviderType())); + return virtualLinkResJson.toString(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java new file mode 100644 index 0000000..817ffe2 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VmEntity.java @@ -0,0 +1,96 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * @author l00345485 + * @date 2016-10-28 + */ +public class VmEntity implements Serializable { + + /** */ + private String vmId; + + /** */ + private String vmName; + + /** */ + private String vmStatus; + + /** */ + private String vnfInstanceId; + + private static final long serialVersionUID = 1L; + + public String getVmId() { + return vmId; + } + + public void setVmId(String vmId) { + this.vmId = vmId; + } + + public String getVmName() { + return vmName; + } + + public void setVmName(String vmName) { + this.vmName = vmName; + } + + public String getVmStatus() { + return vmStatus; + } + + public void setVmStatus(String vmStatus) { + this.vmStatus = vmStatus; + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public static VmEntity toEntity(JSONObject jsonObject) { + VmEntity vmEntity = new VmEntity(); + vmEntity.setVmId(JsonUtil.getJsonFieldStr(jsonObject, "vmId")); + vmEntity.setVmName(JsonUtil.getJsonFieldStr(jsonObject, "vmName")); + vmEntity.setVmStatus(JsonUtil.getJsonFieldStr(jsonObject, "vmStatus")); + vmEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId")); + return vmEntity; + } + + @Override + public String toString() { + JSONObject vmResJson = new JSONObject(); + vmResJson.put("vmId", StringUtils.trimToEmpty(this.getVmId())); + vmResJson.put("vmName", StringUtils.trimToEmpty(this.getVmName())); + vmResJson.put("vmStatus", StringUtils.trimToEmpty(this.getVmStatus())); + vmResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getVnfInstanceId())); + return vmResJson.toString(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java new file mode 100644 index 0000000..4de6658 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfEntity.java @@ -0,0 +1,337 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * @author l00345485 + * @date 2016-10-28 + */ +public class VnfEntity implements Serializable { + + /** */ + private String id; + + /** */ + private String vnfInstanceId; + + /** */ + private String vnfInstanceName; + + /** */ + private String nsId; + + /** */ + private String nsName; + + /** */ + private String vnfmId; + + /** */ + private String vnfmName; + + /** */ + private String vnfPackageName; + + /** */ + private String vnfDescriptorName; + + /** */ + private String vimId; + + /** */ + private String vimName; + + /** */ + private String vimTenant; + + /** */ + private String jobId; + + /** */ + private String vnfStatus; + + /** */ + private String vnfType; + + /** */ + private Integer maxVm; + + /** */ + private Integer maxCpu; + + /** */ + private Integer maxDisk; + + /** */ + private Integer maxRam; + + /** */ + private Integer maxShd; + + /** */ + private Integer maxNet; + + /** */ + private String name; + + private static final long serialVersionUID = 1L; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public String getVnfInstanceName() { + return vnfInstanceName; + } + + public void setVnfInstanceName(String vnfInstanceName) { + this.vnfInstanceName = vnfInstanceName; + } + + public String getNsId() { + return nsId; + } + + public void setNsId(String nsId) { + this.nsId = nsId; + } + + public String getNsName() { + return nsName; + } + + public void setNsName(String nsName) { + this.nsName = nsName; + } + + public String getVnfmId() { + return vnfmId; + } + + public void setVnfmId(String vnfmId) { + this.vnfmId = vnfmId; + } + + public String getVnfmName() { + return vnfmName; + } + + public void setVnfmName(String vnfmName) { + this.vnfmName = vnfmName; + } + + public String getVnfPackageName() { + return vnfPackageName; + } + + public void setVnfPackageName(String vnfPackageName) { + this.vnfPackageName = vnfPackageName; + } + + public String getVnfDescriptorName() { + return vnfDescriptorName; + } + + public void setVnfDescriptorName(String vnfDescriptorName) { + this.vnfDescriptorName = vnfDescriptorName; + } + + public String getVimId() { + return vimId; + } + + public void setVimId(String vimId) { + this.vimId = vimId; + } + + public String getVimName() { + return vimName; + } + + public void setVimName(String vimName) { + this.vimName = vimName; + } + + public String getVimTenant() { + return vimTenant; + } + + public void setVimTenant(String vimTenant) { + this.vimTenant = vimTenant; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public String getVnfStatus() { + return vnfStatus; + } + + public void setVnfStatus(String vnfStatus) { + this.vnfStatus = vnfStatus; + } + + public String getVnfType() { + return vnfType; + } + + public void setVnfType(String vnfType) { + this.vnfType = vnfType; + } + + public Integer getMaxVm() { + return maxVm; + } + + public void setMaxVm(Integer maxVm) { + this.maxVm = maxVm; + } + + public Integer getMaxCpu() { + return maxCpu; + } + + public void setMaxCpu(Integer maxCpu) { + this.maxCpu = maxCpu; + } + + public Integer getMaxDisk() { + return maxDisk; + } + + public void setMaxDisk(Integer maxDisk) { + this.maxDisk = maxDisk; + } + + public Integer getMaxRam() { + return maxRam; + } + + public void setMaxRam(Integer maxRam) { + this.maxRam = maxRam; + } + + public Integer getMaxShd() { + return maxShd; + } + + public void setMaxShd(Integer maxShd) { + this.maxShd = maxShd; + } + + public Integer getMaxNet() { + return maxNet; + } + + public void setMaxNet(Integer maxNet) { + this.maxNet = maxNet; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + /** + *
+ * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static VnfEntity toEntity(JSONObject jsonObject) { + VnfEntity vnfEntity = new VnfEntity(); + vnfEntity.setId(JsonUtil.getJsonFieldStr(jsonObject, "id")); + vnfEntity.setName(JsonUtil.getJsonFieldStr(jsonObject, "name")); + vnfEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId")); + vnfEntity.setVnfInstanceName(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceName")); + vnfEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId")); + vnfEntity.setNsName(JsonUtil.getJsonFieldStr(jsonObject, "nsName")); + vnfEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfmId")); + vnfEntity.setVnfmName(JsonUtil.getJsonFieldStr(jsonObject, "vnfmName")); + vnfEntity.setVnfPackageName(JsonUtil.getJsonFieldStr(jsonObject, "vnfPackageName")); + vnfEntity.setVnfDescriptorName(JsonUtil.getJsonFieldStr(jsonObject, "vnfDescriptorName")); + vnfEntity.setVimId(JsonUtil.getJsonFieldStr(jsonObject, "vimId")); + vnfEntity.setVimName(JsonUtil.getJsonFieldStr(jsonObject, "vimName")); + vnfEntity.setVimTenant(JsonUtil.getJsonFieldStr(jsonObject, "vimTenant")); + vnfEntity.setJobId(JsonUtil.getJsonFieldStr(jsonObject, "jobId")); + vnfEntity.setVnfStatus(JsonUtil.getJsonFieldStr(jsonObject, "vnfStatus")); + vnfEntity.setVnfType(JsonUtil.getJsonFieldStr(jsonObject, "vnfType")); + vnfEntity.setMaxVm(JsonUtil.getJsonFieldInt(jsonObject, "maxVm")); + vnfEntity.setMaxCpu(JsonUtil.getJsonFieldInt(jsonObject, "maxCpu")); + vnfEntity.setMaxDisk(JsonUtil.getJsonFieldInt(jsonObject, "maxDisk")); + vnfEntity.setMaxRam(JsonUtil.getJsonFieldInt(jsonObject, "maxRam")); + vnfEntity.setMaxShd(JsonUtil.getJsonFieldInt(jsonObject, "maxShd")); + vnfEntity.setMaxNet(JsonUtil.getJsonFieldInt(jsonObject, "maxNet")); + return vnfEntity; + } + + @Override + public String toString() { + JSONObject vnfResJson = new JSONObject(); + vnfResJson.put("id", StringUtils.trimToEmpty(this.getId())); + vnfResJson.put("name", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vnfInstanceName", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("nsId", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("nsName", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vnfmId", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vnfmName", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vnfPackageName", StringUtils.trimToEmpty(this.getId())); + vnfResJson.put("vnfDescriptorName", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vimId", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vimName", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vimTenant", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("jobId", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vnfStatus", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("vnfType", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("maxVm", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("maxCpu", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("maxDisk", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("maxRam", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("maxShd", StringUtils.trimToEmpty(this.getName())); + vnfResJson.put("maxNet", StringUtils.trimToEmpty(this.getName())); + return vnfResJson.toString(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfInfoEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfInfoEntity.java new file mode 100644 index 0000000..948187f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfInfoEntity.java @@ -0,0 +1,83 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * @author l00345485 + * @date 2016-10-28 + */ +public class VnfInfoEntity implements Serializable { + + /** */ + private String vnfInstanceId; + + /** */ + private String nsId; + + /** */ + private String vnfmId; + + private static final long serialVersionUID = 1L; + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public String getNsId() { + return nsId; + } + + public void setNsId(String nsId) { + this.nsId = nsId; + } + + public String getVnfmId() { + return vnfmId; + } + + public void setVnfmId(String vnfmId) { + this.vnfmId = vnfmId; + } + + public static VnfInfoEntity toEntity(JSONObject jsonObject) { + VnfInfoEntity vnfInfoEntity = new VnfInfoEntity(); + vnfInfoEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId")); + vnfInfoEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId")); + vnfInfoEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfmId")); + return vnfInfoEntity; + } + + @Override + public String toString() { + JSONObject vnfInfoResJson = new JSONObject(); + vnfInfoResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getVnfInstanceId())); + vnfInfoResJson.put("nsId", StringUtils.trimToEmpty(this.getNsId())); + vnfInfoResJson.put("vnfmId", StringUtils.trimToEmpty(this.getVnfmId())); + return vnfInfoResJson.toString(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfStatusEntity.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfStatusEntity.java new file mode 100644 index 0000000..27f008e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/entity/VnfStatusEntity.java @@ -0,0 +1,213 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import net.sf.json.JSONObject; + +/** + * @author l00345485 + * @date 2016-10-29 + */ +public class VnfStatusEntity implements Serializable { + + /** */ + private String vnfInstanceId; + + /** */ + private String jobId; + + /** */ + private String nsId; + + /** */ + private String vnfmId; + + /** */ + private String responseDescriptor; + + /** */ + private String status; + + /** */ + private String progress; + + /** */ + private String statusDescription; + + /** */ + private String errorCode; + + /** */ + private String responseId; + + /** */ + private String responseHistoryList; + + /** */ + private String addVm; + + /** */ + private String delVm; + + private static final long serialVersionUID = 1L; + + public String getVnfInstanceId() { + return vnfInstanceId; + } + + public void setVnfInstanceId(String vnfInstanceId) { + this.vnfInstanceId = vnfInstanceId; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public String getNsId() { + return nsId; + } + + public void setNsId(String nsId) { + this.nsId = nsId; + } + + public String getVnfmId() { + return vnfmId; + } + + public void setVnfmId(String vnfmId) { + this.vnfmId = vnfmId; + } + + public String getResponseDescriptor() { + return responseDescriptor; + } + + public void setResponseDescriptor(String responseDescriptor) { + this.responseDescriptor = responseDescriptor; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getProgress() { + return progress; + } + + public void setProgress(String progress) { + this.progress = progress; + } + + public String getStatusDescription() { + return statusDescription; + } + + public void setStatusDescription(String statusDescription) { + this.statusDescription = statusDescription; + } + + public String getErrorCode() { + return errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getResponseId() { + return responseId; + } + + public void setResponseId(String responseId) { + this.responseId = responseId; + } + + public String getResponseHistoryList() { + return responseHistoryList; + } + + public void setResponseHistoryList(String responseHistoryList) { + this.responseHistoryList = responseHistoryList; + } + + public String getAddVm() { + return addVm; + } + + public void setAddVm(String addVm) { + this.addVm = addVm; + } + + public String getDelVm() { + return delVm; + } + + public void setDelVm(String delVm) { + this.delVm = delVm; + } + + public static VnfStatusEntity toEntity(JSONObject jsonObject) { + VnfStatusEntity vnfStatusEntity = new VnfStatusEntity(); + vnfStatusEntity.setVnfInstanceId(JsonUtil.getJsonFieldStr(jsonObject, "vnfInstanceId")); + vnfStatusEntity.setJobId(JsonUtil.getJsonFieldStr(jsonObject, "jobId")); + vnfStatusEntity.setNsId(JsonUtil.getJsonFieldStr(jsonObject, "nsId")); + vnfStatusEntity.setVnfmId(JsonUtil.getJsonFieldStr(jsonObject, "vnfmId")); + vnfStatusEntity.setResponseDescriptor(JsonUtil.getJsonFieldStr(jsonObject, "responseDescriptor")); + vnfStatusEntity.setStatus(JsonUtil.getJsonFieldStr(jsonObject, "status")); + vnfStatusEntity.setProgress(JsonUtil.getJsonFieldStr(jsonObject, "progress")); + vnfStatusEntity.setStatusDescription(JsonUtil.getJsonFieldStr(jsonObject, "statusDescription")); + vnfStatusEntity.setErrorCode(JsonUtil.getJsonFieldStr(jsonObject, "errorCode")); + vnfStatusEntity.setResponseId(JsonUtil.getJsonFieldStr(jsonObject, "responseId")); + vnfStatusEntity.setResponseHistoryList(JsonUtil.getJsonFieldStr(jsonObject, "responseHistoryList")); + vnfStatusEntity.setAddVm(JsonUtil.getJsonFieldStr(jsonObject, "addVm")); + vnfStatusEntity.setDelVm(JsonUtil.getJsonFieldStr(jsonObject, "delVm")); + return vnfStatusEntity; + } + + @Override + public String toString() { + JSONObject vnfStatusResJson = new JSONObject(); + vnfStatusResJson.put("vnfInstanceId", StringUtils.trimToEmpty(this.getVnfInstanceId())); + vnfStatusResJson.put("jobId", StringUtils.trimToEmpty(this.getJobId())); + vnfStatusResJson.put("nsId", StringUtils.trimToEmpty(this.getNsId())); + vnfStatusResJson.put("vnfmId", StringUtils.trimToEmpty(this.getVnfmId())); + vnfStatusResJson.put("responseDescriptor", StringUtils.trimToEmpty(this.getResponseDescriptor())); + vnfStatusResJson.put("status", StringUtils.trimToEmpty(this.getStatus())); + vnfStatusResJson.put("progress", StringUtils.trimToEmpty(this.getProgress())); + vnfStatusResJson.put("statusDescription", StringUtils.trimToEmpty(this.getStatusDescription())); + vnfStatusResJson.put("errorCode", StringUtils.trimToEmpty(this.getErrorCode())); + vnfStatusResJson.put("responseId", StringUtils.trimToEmpty(this.getResponseId())); + vnfStatusResJson.put("responseHistoryList", StringUtils.trimToEmpty(this.getResponseHistoryList())); + vnfStatusResJson.put("addVm", StringUtils.trimToEmpty(this.getAddVm())); + vnfStatusResJson.put("delVm", StringUtils.trimToEmpty(this.getDelVm())); + return vnfStatusResJson.toString(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImpl.java new file mode 100644 index 0000000..362f80a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/GrantResServiceImpl.java @@ -0,0 +1,206 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.GrantResService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +public class GrantResServiceImpl implements GrantResService { + + private static final Logger LOGGER = LoggerFactory.getLogger(GrantResServiceImpl.class); + + private Sites sites; + + /** + *
+ * + * @param object + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public JSONObject grantResource(JSONObject object) throws ServiceException { + LOGGER.info("function=grantResource; object: {}", object.toString()); + JSONObject additionalparam = object.getJSONObject("additionalParam"); + String vimId = additionalparam.getString("vimid"); + JSONObject vimJson = VimUtil.getVimById(vimId); + String tenant = vimJson.getString("tenant"); + JSONObject accessinfo = new JSONObject(); + accessinfo.put("tenant", tenant); + JSONObject vim = new JSONObject(); + vim.put("vimid", vimId); + vim.put("accessinfo", accessinfo); + LOGGER.info("function=grantResource; vim: {}", vim.toString()); + JSONObject result = new JSONObject(); + result.put("vim", vim); + return result; + } + + @Override + public JSONObject grantResourceReal(JSONObject object) throws ServiceException { + LOGGER.info("function=grantResource; object: {}", object.toString()); + String vimId = object.getString("vimId"); + JSONObject vimJson = VimUtil.getVimById(vimId); + JSONObject vim = parseVim(vimJson); + String resType = ""; + JSONArray resArr = new JSONArray(); + if(object.containsKey("addResource")) { + resType = "addResource"; + resArr = parseResource(object, resType); + } else if(object.containsKey("removeResource")) { + resType = "removeResource"; + resArr = parseResource(object, resType); + } + JSONObject resInfo = getResInfo(object, resType); + resInfo.put("vimId", vimId); + sites.update(resInfo); + + JSONObject result = new JSONObject(); + result.put("vim", vim); + result.put("zone", ""); + result.put("zoneGroup", ""); + result.put(resType, resArr); + result.put("tempResource", ""); + result.put("updateResource", ""); + result.put("vimAssets", new JSONObject()); + result.put("additionalParam", ""); + LOGGER.info("function=grantResource; result: {}", result.toString()); + return result; + } + + private JSONObject getResInfo(JSONObject object, String type) { + JSONArray arr = object.getJSONArray(type); + LOGGER.info("function=getResInfo; arr: {}, type: {}", arr, type); + JSONObject resourceObj = new JSONObject(); + if("addResource".equals(type)) { + resourceObj = getGrantResource(arr); + resourceObj.put("action", "online"); + } else if("removeResource".equals(type)) { + resourceObj = getGrantResource(arr); + resourceObj.put("action", "offline"); + } + LOGGER.info("function=getResInfo; resutl: {}", resourceObj.toString()); + return resourceObj; + } + + /** + *
+ * + * @param addResource + * @return + * @since NFVO 0.5 + */ + private JSONObject getGrantResource(JSONArray resource) { + int cpuNum = 0; + int memNum = 0; + int diskNum = 0; + for(int i = 0; i < resource.size(); i++) { + JSONObject res = resource.getJSONObject(i); + JSONObject vCpu = res.getJSONObject("resourceTemplate").getJSONObject("virtualComputeDescriptor") + .getJSONObject("virtualCpu"); + int vCpuNum = vCpu.getInt("numVirtualCpu"); + JSONObject vMem = res.getJSONObject("resourceTemplate").getJSONObject("virtualComputeDescriptor") + .getJSONObject("virtualMemory"); + int vMemNum = vMem.getInt("virtualMemSize"); + JSONObject vDisk = res.getJSONObject("resourceTemplate").getJSONObject("virtualStorageDescriptor"); + int vDiskNum = vDisk.getInt("sizeOfStorage"); + cpuNum = cpuNum + vCpuNum; + memNum = memNum + vMemNum; + diskNum = diskNum + vDiskNum; + } + JSONObject obj = new JSONObject(); + obj.put("usedCPU", String.valueOf(cpuNum)); + obj.put("usedMemory", String.valueOf(memNum)); + obj.put("usedDisk", String.valueOf(diskNum)); + return obj; + } + + /** + *
+ * + * @param object + * @return + * @since NFVO 0.5 + */ + private JSONArray parseResource(JSONObject object, String key) { + JSONArray newResources = new JSONArray(); + JSONArray oldResource = object.getJSONArray(key); + LOGGER.info("function=parseResource; Resource: {}", oldResource.toString()); + for(int i = 0; i < oldResource.size(); i++) { + JSONObject res = oldResource.getJSONObject(i); + JSONObject obj = new JSONObject(); + obj.put("reservationId", ""); + obj.put("resourceProviderId", ""); + obj.put("zoneId", ""); + obj.put("vimId", object.getString("vimId")); + obj.put("resourceDefinitionId", res.getString("resourceDefinitionId")); + newResources.add(obj); + } + LOGGER.info("function=parseResource; Parse Resource result: {}", newResources.toString()); + return newResources; + } + + /** + *
+ * + * @param vimJson + * @return + * @since NFVO 0.5 + */ + private JSONObject parseVim(JSONObject vimJson) { + LOGGER.info("function=grantResource; vimJson: {}", vimJson.toString()); + JSONObject interfaceInfo = new JSONObject(); + interfaceInfo.put("vimType", vimJson.getString("type")); + interfaceInfo.put("apiVersion", "v2"); + interfaceInfo.put("protocolType", "http"); + JSONObject accessInfo = new JSONObject(); + accessInfo.put("tenant", vimJson.getString("tenant")); + accessInfo.put("username", vimJson.getString("userName")); + accessInfo.put("password", vimJson.getString("password")); + JSONObject vim = new JSONObject(); + vim.put("vimInfoId", vimJson.getString("vimId")); + vim.put("vimId", vimJson.getString("vimId")); + vim.put("interfaceInfo", interfaceInfo); + vim.put("accessInfo", accessInfo); + vim.put("interfaceEndpoint", vimJson.getString("url")); + return vim; + } + + /** + * @param sites The sites to set. + */ + public void setSites(Sites sites) { + this.sites = sites; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceAddServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceAddServiceImpl.java new file mode 100644 index 0000000..1247b0e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceAddServiceImpl.java @@ -0,0 +1,159 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * iResource add service implementation.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class IResourceAddServiceImpl { + + private static final Logger LOGGER = LoggerFactory.getLogger(IResourceAddServiceImpl.class); + + /** + * Add iResource.
+ * + * @param restParametes + * @param iResMap + * @throws ServiceException + * @since NFVO 0.5 + */ + @Transactional(rollbackFor = ServiceException.class) + public void addIRes(RestfulParametes restParametes, Map iResMap) + throws ServiceException { + addIResources(iResMap, createResUrlMap(), restParametes); + } + + private void addIResources(Map iResMap, HashMap urlMap, + RestfulParametes restParametes) throws ServiceException { + for(String iResName : iResMap.keySet()) { + if(ParamConstant.PARAM_HOST.equals(iResName)) { + addHostResource(iResMap, restParametes, String.format(urlMap.get(iResName), + restParametes.get(ParamConstant.PARAM_VIMID), restParametes.get(ParamConstant.PARAM_TENANTID)), + iResName); + } else { + String url = String.format(urlMap.get(iResName), restParametes.get(ParamConstant.PARAM_VIMID), + restParametes.get(ParamConstant.PARAM_TENANTID)); + JSONArray iResArray = RestfulUtil.getResponseRes(new RestfulParametes(), url, iResName); + LOGGER.warn("function=addIResources; iResArray={}", iResArray); + for(Object object : iResArray) { + JSONObject iRes = JSONObject.fromObject(object); + int result = iResMap.get(iResName).add(iRes); + LOGGER.warn("function=addIResources; msg=iRes name is [{}],result is [{}]", iResName, result); + } + } + } + } + + /** + * Add Host Resource.
+ * + * @param iResMap + * @param restParametes + * @param url + * @param iResName + * @throws ServiceException + * @since NFVO 0.5 + */ + public static void addHostResource(Map iResMap, RestfulParametes restParametes, + String url, String iResName) throws ServiceException { + JSONArray hostResArray = RestfulUtil.getResponseRes(new RestfulParametes(), url, iResName); + LOGGER.warn("function=addHostResource; hostResArray={}", hostResArray); + for(Object object : hostResArray) { + JSONObject hostRes = JSONObject.fromObject(object); + String hostZone = hostRes.getString("zone"); + if("internal".equals(hostZone)) { + continue; + } + String hostName = hostRes.getString("name"); + String hostUrl = String.format(UrlConstant.GET_HOSTDETAIL_URL, restParametes.get(ParamConstant.PARAM_VIMID), + restParametes.get(ParamConstant.PARAM_TENANTID), hostName); + + String result = RestfulUtil.getResponseContent(hostUrl, new RestfulParametes(), ParamConstant.PARAM_GET); + if(result == null) { + continue; + } + JSONObject hostObj = JSONObject.fromObject(result); + JSONObject host = hostDataParse(hostObj, hostName); + int res = iResMap.get(iResName).add(host); + LOGGER.warn("function=addHostResource; result={}, res={}", result, res); + if(res < 0) { + LOGGER.error("function=addHostResource; add into DB fail!"); + } + + } + } + + /** + *
+ * + * @param hostObj + * @param hostName + * @return + * @since NFVO 0.5 + */ + public static JSONObject hostDataParse(JSONObject hostObj, String hostName) { + LOGGER.warn("function=hostDataParse; hostObj={}, hostName={}", hostObj, hostName); + JSONArray hostArray = hostObj.getJSONArray("host"); + for(Object object : hostArray) { + JSONObject hostObject = JSONObject.fromObject(object); + if(hostObject.getString("project").contains("total")) { + String vimId = JsonUtil.getJsonFieldStr(hostObj, "vimId"); + String hostId = vimId + hostName; + JSONObject host = new JSONObject(); + host.put("id", hostId); + host.put("name", hostName); + host.put("cpu", JsonUtil.getJsonFieldStr(hostObject, "cpu")); + host.put("memory", JsonUtil.getJsonFieldStr(hostObject, "memory_mb")); + host.put("disk", JsonUtil.getJsonFieldStr(hostObject, "disk_gb")); + host.put("vimId", JsonUtil.getJsonFieldStr(hostObj, "vimId")); + host.put("vimName", JsonUtil.getJsonFieldStr(hostObj, "vimName")); + return host; + } + } + return new JSONObject(); + } + + private HashMap createResUrlMap() { + HashMap urlMap = new HashMap(10); + urlMap.put(ParamConstant.PARAM_NETWORK, UrlConstant.GET_NETWORK_URL); + urlMap.put(ParamConstant.PARAM_HOST, UrlConstant.GET_HOST_URL); + urlMap.put(ParamConstant.PARAM_PORT, UrlConstant.GET_PORT_URL); + return urlMap; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceDelServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceDelServiceImpl.java new file mode 100644 index 0000000..2642ae0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceDelServiceImpl.java @@ -0,0 +1,75 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Vim; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * iResource delete service implementation.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class IResourceDelServiceImpl { + + private static final Logger LOGGER = LoggerFactory.getLogger(IResourceDelServiceImpl.class); + + /** + * + * Delete iResource.
+ * + * @param vimId + * @param iResMap + * @param vim + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + public int deleteIRes(String vimId, Map iResMap, Vim vim) throws ServiceException { + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_VIMID, vimId); + + checkIResDelResult(vimId, iResMap); + return vim.delete(vimId); + } + + private void checkIResDelResult(String vimId, Map iResMap) throws ServiceException { + for(String keyName : iResMap.keySet()) { + if(iResMap.get(keyName).deleteResByVimId(vimId) < 0) { + LOGGER.error("function=checkIResDelResult; msg=delete {} failed,", keyName); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.delete.fail") + + keyName); + } + LOGGER.warn("function=checkIResDelResult; msg=delete {} success", keyName); + } + + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceUpdateServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceUpdateServiceImpl.java new file mode 100644 index 0000000..03cbfc3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/IResourceUpdateServiceImpl.java @@ -0,0 +1,120 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * iResource update service implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class IResourceUpdateServiceImpl { + + private static final Logger LOGGER = LoggerFactory.getLogger(IResourceUpdateServiceImpl.class); + + /** + * Update iResource.
+ * + * @param vimId + * @param restParametes + * @param iResMap + * @param sites + * @throws ServiceException + * @since NFVO 0.5 + */ + @Transactional(rollbackFor = ServiceException.class) + public void updateIRes(String vimId, RestfulParametes restParametes, Map iResMap) + throws ServiceException { + + updateIResByName(iResMap, createResUrlMap(), restParametes, vimId); + } + + private void updateIResByName(Map iResMap, HashMap updateUrlMap, + RestfulParametes restParametes, String vimId) throws ServiceException { + for(String resName : updateUrlMap.keySet()) { + if(ParamConstant.PARAM_HOST.equals(resName)) { + updateHostResource(iResMap, restParametes, String.format(updateUrlMap.get(resName), + restParametes.get(ParamConstant.PARAM_VIMID), restParametes.get(ParamConstant.PARAM_TENANTID)), + resName); + } else if(iResMap.get(resName).deleteResByVimId(vimId) >= 0) { + String url = String.format(updateUrlMap.get(resName), restParametes.get(ParamConstant.PARAM_VIMID), + restParametes.get(ParamConstant.PARAM_TENANTID)); + JSONArray iResArray = RestfulUtil.getResponseRes(new RestfulParametes(), url, resName); + LOGGER.warn("function=addIResources; iResArray={}", iResArray); + for(Object object : iResArray) { + JSONObject iRes = JSONObject.fromObject(object); + int result = iResMap.get(resName).add(iRes); + LOGGER.warn("function=updateIResByName; msg=iRes name is [{}],result is [{}]", resName, result); + + } + } + } + } + + private void updateHostResource(Map iResMap, RestfulParametes restParametes, + String url, String iResName) throws ServiceException { + + JSONArray hostResArray = RestfulUtil.getResponseRes(new RestfulParametes(), url, iResName); + LOGGER.warn("function=updateHostResource; hostResArray={}", hostResArray); + for(Object object : hostResArray) { + JSONObject hostRes = JSONObject.fromObject(object); + String hostZone = hostRes.getString("zone"); + if("internal".equals(hostZone)) { + continue; + } + String hostName = hostRes.getString("name"); + String hostUrl = String.format(UrlConstant.GET_HOSTDETAIL_URL, restParametes.get(ParamConstant.PARAM_VIMID), + restParametes.get(ParamConstant.PARAM_TENANTID), hostName); + + String result = RestfulUtil.getResponseContent(hostUrl, new RestfulParametes(), ParamConstant.PARAM_GET); + JSONObject hostObj = JSONObject.fromObject(result); + JSONObject host = IResourceAddServiceImpl.hostDataParse(hostObj, hostName); + int res = iResMap.get(ParamConstant.PARAM_HOST).update(host); + LOGGER.warn("function=updateHostResource; result={}, res={}", result, res); + if(res < 0) { + LOGGER.error("function=updateHostResource; add into DB fail!"); + } + + } + } + + private HashMap createResUrlMap() { + HashMap updateUrlMap = new HashMap(10); + updateUrlMap.put(ParamConstant.PARAM_NETWORK, UrlConstant.GET_NETWORK_URL); + updateUrlMap.put(ParamConstant.PARAM_HOST, UrlConstant.GET_HOST_URL); + updateUrlMap.put(ParamConstant.PARAM_PORT, UrlConstant.GET_PORT_URL); + return updateUrlMap; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/ResOperateServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/ResOperateServiceImpl.java new file mode 100644 index 0000000..4a8ae39 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/ResOperateServiceImpl.java @@ -0,0 +1,257 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.Constant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.StringUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Host; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Network; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Port; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Vim; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.ResOperateService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.transaction.annotation.Transactional; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * Resource operation service implementation class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class ResOperateServiceImpl implements ResOperateService { + + private static final Logger LOGGER = LoggerFactory.getLogger(ResOperateServiceImpl.class); + + private Sites sites; + + private Network network; + + private Host host; + + private Port port; + + private Vim vim; + + private IResourceAddServiceImpl iResourceAddServiceImpl; + + private IResourceUpdateServiceImpl iResourceUpdateServiceImpl; + + private IResourceDelServiceImpl iResourceDelServiceImpl; + + @Override + @Transactional(rollbackFor = ServiceException.class) + public void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException { + LOGGER.warn("function=addIRes; msg=add IResource by vimId:[{}], tenantId:[{}]", vimId, tenantId); + if(!StringUtil.isValidString(vimId) || !StringUtil.isValidString(tenantId)) { + LOGGER.warn("function=addIRes; msg=vimId[{}] is valid", vimId); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.vimId")); + } + + RestfulParametes restParametes = createRestfulParametes(tenantId, vimId, header); + HashMap iResMap = createMap(); + + if(vim.add(vimId) <= 0) { + LOGGER.error("VimId exists"); + throw new ServiceException("VimId exists"); + } + + iResourceAddServiceImpl.addIRes(restParametes, iResMap); + } + + @Override + @Transactional(rollbackFor = ServiceException.class) + public void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException { + if(!StringUtil.isValidString(vimId)) { + LOGGER.error("function=updateIRes; msg=vimId is not exist"); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.update.res.no.vimId")); + } + + RestfulParametes restParametes = createRestfulParametes(tenantId, vimId, header); + HashMap iResMap = createMap(); + iResourceUpdateServiceImpl.updateIRes(vimId, restParametes, iResMap); + } + + @Override + public void updateAllIRes() throws ServiceException { + LOGGER.warn("function=updateAllIRes; msg=update all IResource"); + List vims = vim.getList(); + if(vims.isEmpty()) { + LOGGER.error("function=updateAllIRes; msg=vimId is not exist"); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.update.res.no.vimId")); + } + for(VimEntity vimEntity : vims) { + String vimId = vimEntity.getId(); + LOGGER.warn("function=updateAllIRes; msg=start update vimId:{}", vimId); + updateIRes(null, vimId, new JSONObject()); + } + } + + @Override + @Transactional(rollbackFor = ServiceException.class) + public int deleteIRes(String vimId) throws ServiceException { + LOGGER.warn("function=deleteAllRes; msg=deleteResPool vimId: {}", vimId); + if(StringUtils.isEmpty(vimId)) { + LOGGER.error("function=deleteAllRes; msg=vimId is null"); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.group.resoperate.res.no.vimId")); + } + + return iResourceDelServiceImpl.deleteIRes(vimId, createMap(), vim); + } + + private RestfulParametes createRestfulParametes(String tenantId, String vimId, JSONObject header) { + RestfulParametes restParametes = new RestfulParametes(); + restParametes.put("vimId", vimId); + restParametes.put("tenantId", tenantId); + restParametes.putHttpContextHeader("Content-Type", "application/json"); + JSONObject headers = JsonUtil.getJsonFieldJson(header, "header"); + if(null == headers || !headers.has("x-auth-token")) { + String token = "TestToken"; + LOGGER.warn("function=createRestfulParametes; msg=create token."); + restParametes.putHttpContextHeader(Constant.IAM_AUTH_TOKEN, token); + return restParametes; + } + restParametes.putHttpContextHeader(Constant.IAM_AUTH_TOKEN, + JsonUtil.getJsonFieldStr(headers, Constant.IAM_AUTH_TOKEN)); + return restParametes; + } + + private HashMap createMap() { + HashMap iResMap = new HashMap(10); + iResMap.put(ParamConstant.PARAM_NETWORK, network); + iResMap.put(ParamConstant.PARAM_HOST, host); + iResMap.put(ParamConstant.PARAM_PORT, port); + return iResMap; + } + + public void setSites(Sites sites) { + this.sites = sites; + } + + public void setNetwork(Network network) { + this.network = network; + } + + public void setHost(Host host) { + this.host = host; + } + + public void setPort(Port port) { + this.port = port; + } + + public void setVim(Vim vim) { + this.vim = vim; + } + + /** + * Set iResource Add service implemtation.
+ * + * @param iResourceAddServiceImpl + * @since NFVO 0.5 + */ + public void setiResourceAddServiceImpl(IResourceAddServiceImpl iResourceAddServiceImpl) { + this.iResourceAddServiceImpl = iResourceAddServiceImpl; + } + + /** + * Set iResource update service implementation.
+ * + * @param iResourceUpdateServiceImpl + * @since NFVO 0.5 + */ + public void setiResourceUpdateServiceImpl(IResourceUpdateServiceImpl iResourceUpdateServiceImpl) { + this.iResourceUpdateServiceImpl = iResourceUpdateServiceImpl; + } + + /** + * Set iresource delete service implementation.
+ * + * @param iResourceDelServiceImpl + * @since NFVO 0.5 + */ + public void setiResourceDelServiceImpl(IResourceDelServiceImpl iResourceDelServiceImpl) { + this.iResourceDelServiceImpl = iResourceDelServiceImpl; + } + + /** + *
+ * + * @param string + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { + LOGGER.info("Enter sendMsgMonitor!"); + Map map = new HashMap<>(10); + map.put("vimId", vimId); + List hosts = host.getList(map); + for(HostEntity entity : hosts) { + JSONObject msgObj = new JSONObject(); + msgObj.put("operationType", operateType); + msgObj.put("resourceType", "HOST"); + msgObj.put("label", entity.getName()); + if("delete".equals(operateType)) { + JSONArray deleteIds = new JSONArray(); + deleteIds.add(entity.getId()); + msgObj.put("deleteIds", deleteIds); + } else { + JSONArray data = new JSONArray(); + JSONObject obj = JSONObject.fromObject(entity); + obj.put("oid", entity.getId()); + obj.put("moc", "nfv.host.linux"); + data.add(obj); + msgObj.put("data", data); + } + RestfulParametes restfulParametes = new RestfulParametes(); + Map headerMap = new HashMap<>(3); + headerMap.put("Content-Type", "application/json"); + restfulParametes.setHeaderMap(headerMap); + restfulParametes.setRawData(msgObj.toString()); + LOGGER.info("sendMsgMonitor msgObj: {}", msgObj); + String result = RestfulUtil.getResponseContent(UrlConstant.SEND_MSG_MONITOR, restfulParametes, + ParamConstant.PARAM_POST); + LOGGER.warn(result); + } + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VirtualLinkServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VirtualLinkServiceImpl.java new file mode 100644 index 0000000..6619bfe --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VirtualLinkServiceImpl.java @@ -0,0 +1,123 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VirtualLinkDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VirtualLinkService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 27, 2016 + */ +public class VirtualLinkServiceImpl implements VirtualLinkService { + + private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkServiceImpl.class); + + private VirtualLinkDao virtualLinkDao; + + /** + *
+ * + * @param virtualLinkEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException { + if(!checkId(virtualLinkEntity.getId())) { + LOGGER.error("function=addVl; msg=add error, because id is already exist."); + throw new ServiceException(ResourceUtil + .getMessage("org.onap.vfc.nfvo.resmanagement.service.group.impl.VirtualLinkServiceImpl.add.id.check")); + } + if(StringUtils.isEmpty(virtualLinkEntity.getId())) { + virtualLinkEntity.setId(UUID.randomUUID().toString()); + } + int result = virtualLinkDao.addVl(virtualLinkEntity); + JSONObject restJson = new JSONObject(); + if(result > 0) { + restJson.put("id", virtualLinkEntity.getId()); + restJson.put("name", virtualLinkEntity.getName()); + } else { + LOGGER.error("function=addVl; msg=add vl into DB error."); + restJson.put("message", "Add Vl into DB error."); + } + return restJson; + + } + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + private boolean checkId(String id) { + VirtualLinkEntity vl = virtualLinkDao.getVl(id); + if(null == vl) { + return true; + } + return false; + } + + /** + *
+ * + * @param map + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public List getList(Map map) throws ServiceException { + return virtualLinkDao.getVls(map); + } + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public int delete(String id) throws ServiceException { + return virtualLinkDao.deleteVlById(id); + } + + public void setVirtualLinkDao(VirtualLinkDao virtualLinkDao) { + this.virtualLinkDao = virtualLinkDao; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java new file mode 100644 index 0000000..df73a15 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VmServiceImpl.java @@ -0,0 +1,177 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VmDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VmService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +public class VmServiceImpl implements VmService { + + private static final Logger LOGGER = LoggerFactory.getLogger(VmServiceImpl.class); + + private VmDao vmDao; + + /** + *
+ * + * @param vmEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public JSONObject addVm(VmEntity vmEntity) throws ServiceException { + int result; + if(!checkId(vmEntity.getVmId())) { + result = vmDao.updateVm(vmEntity); + sendMsgMonitor("create", vmEntity); + } else { + if(StringUtils.isEmpty(vmEntity.getVmId())) { + vmEntity.setVmId(UUID.randomUUID().toString()); + } + result = vmDao.addVm(vmEntity); + sendMsgMonitor("update", vmEntity); + } + JSONObject restJson = new JSONObject(); + if(result > 0) { + restJson.put("id", vmEntity.getVmId()); + restJson.put("name", vmEntity.getVmName()); + } else { + LOGGER.error("function=addVm; msg=add vm into DB error."); + restJson.put("message", "Add vm into DB error."); + } + return restJson; + } + + /** + *
+ * + * @param vmId + * @return + * @since NFVO 0.5 + */ + private boolean checkId(String vmId) { + VmEntity vm = vmDao.getVm(vmId); + if(null == vm) { + return true; + } + return false; + } + + public void sendMsgMonitor(String operateType, VmEntity vmEntity) throws ServiceException { + JSONObject msgObj = new JSONObject(); + msgObj.put("operationType", operateType); + msgObj.put("resourceType", "VDU"); + msgObj.put("label", vmEntity.getVmName()); + if("delete".equals(operateType)) { + JSONArray deleteIds = new JSONArray(); + deleteIds.add(vmEntity.getVmId()); + msgObj.put("deleteIds", deleteIds); + } else { + JSONArray data = new JSONArray(); + JSONObject obj = JSONObject.fromObject(vmEntity); + obj.put("oid", vmEntity.getVmId()); + obj.put("moc", "nfv.vdu.linux"); + data.add(obj); + msgObj.put("data", data); + } + LOGGER.info("sendMsgMonitor msgObj: {}", msgObj); + RestfulParametes restfulParametes = new RestfulParametes(); + Map headerMap = new HashMap<>(3); + headerMap.put("Content-Type", "application/json"); + restfulParametes.setHeaderMap(headerMap); + restfulParametes.setRawData(msgObj.toString()); + String result = RestfulUtil.getResponseContent(UrlConstant.SEND_MSG_MONITOR, restfulParametes, + ParamConstant.PARAM_POST); + LOGGER.warn(result); + + } + + /** + *
+ * + * @param map + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public List getList(Map map) throws ServiceException { + return vmDao.getVms(map); + } + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public int delete(String id) throws ServiceException { + return vmDao.deleteVmById(id); + } + + public void setVmDao(VmDao vmDao) { + this.vmDao = vmDao; + } + + /** + *
+ * + * @param vnfInstanceId + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public int deleteByVnfId(String vnfInstanceId) throws ServiceException { + Map map = new HashMap<>(10); + map.put("vnfInstanceId", vnfInstanceId); + List vms = vmDao.getVms(map); + for(int i = 0; i < vms.size(); i++) { + VmEntity vm = vms.get(i); + sendMsgMonitor("delete", vm); + } + return vmDao.deleteVmByVnfId(vnfInstanceId); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfInfoServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfInfoServiceImpl.java new file mode 100644 index 0000000..bf4ce37 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfInfoServiceImpl.java @@ -0,0 +1,150 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VnfInfoDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VmService; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfInfoService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public class VnfInfoServiceImpl implements VnfInfoService { + + private static final Logger LOGGER = LoggerFactory.getLogger(VnfInfoServiceImpl.class); + + private VnfInfoDao vnfInfoDao; + + private VmService vmService; + + /** + *
+ * + * @param object + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public JSONObject addVnfInfo(JSONObject object) throws ServiceException { + LOGGER.info("function=addVnfInfo; object: {}", object); + saveVm(object); + JSONObject vnf = new JSONObject(); + vnf.put("vnfInstanceId", object.get("vnfInstanceId")); + vnf.put("nsId", object.get("nsId")); + vnf.put("vnfmId", object.get("vnfmId")); + VnfInfoEntity vnfInfoEntity = VnfInfoEntity.toEntity(vnf); + int result; + if(!checkId(vnfInfoEntity.getVnfInstanceId())) { + result = vnfInfoDao.updateVnfInfo(vnfInfoEntity); + } else { + result = vnfInfoDao.addVnfInfo(vnfInfoEntity); + } + JSONObject resultObj = new JSONObject(); + if(result > 0) { + resultObj.put("vnfInstanceId", object.get("vnfInstanceId")); + } else { + LOGGER.error("function=addVnfInfo; msg=add vnfInfo into DB error."); + resultObj.put("message", "Add vnfInfo into DB error."); + } + return resultObj; + } + + /** + *
+ * + * @param vnfInstanceId + * @return + * @since NFVO 0.5 + */ + private boolean checkId(String vnfInstanceId) { + VnfInfoEntity vnf = vnfInfoDao.getVnfInfo(vnfInstanceId); + if(null == vnf) { + return true; + } + return false; + } + + /** + *
+ * + * @param object + * @throws ServiceException + * @since NFVO 0.5 + */ + private void saveVm(JSONObject object) throws ServiceException { + String vnfInstanceId = object.getString("vnfInstanceId"); + JSONArray vms = object.getJSONArray("vms"); + for(int i = 0; i < vms.size(); i++) { + JSONObject vmObj = vms.getJSONObject(i); + vmObj.put("vnfInstanceId", vnfInstanceId); + vmService.addVm(VmEntity.toEntity(vmObj)); + } + + } + + /** + *
+ * + * @param map + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public List getList(Map map) throws ServiceException { + return vnfInfoDao.getVnfInfos(map); + } + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public int delete(String id) throws ServiceException { + vmService.deleteByVnfId(id); + return vnfInfoDao.deleteVnfInfoById(id); + } + + public void setVnfInfoDao(VnfInfoDao vnfInfoDao) { + this.vnfInfoDao = vnfInfoDao; + } + + public void setVmService(VmService vmService) { + this.vmService = vmService; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java new file mode 100644 index 0000000..59059ea --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java @@ -0,0 +1,141 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.lang3.StringUtils; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VnfDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfInfoService; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public class VnfServiceImpl implements VnfService { + + private static final Logger LOGGER = LoggerFactory.getLogger(VnfServiceImpl.class); + + private VnfDao vnfDao; + + private VnfInfoService vnfInfoService; + + /** + *
+ * + * @param vnfEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException { + if(!checkId(vnfEntity.getId())) { + LOGGER.error("function=addVnf; msg=add error, because id is already exist."); + throw new ServiceException(ResourceUtil + .getMessage("org.onap.vfc.nfvo.resmanagement.service.group.impl.VnfServiceImpl.add.id.check")); + } + if(StringUtils.isEmpty(vnfEntity.getId())) { + vnfEntity.setId(UUID.randomUUID().toString()); + } + int result = vnfDao.addVnf(vnfEntity); + JSONObject restJson = new JSONObject(); + if(result > 0) { + restJson.put("id", vnfEntity.getId()); + restJson.put("name", vnfEntity.getName()); + } else { + LOGGER.error("function=addVnf; msg=add vnf into DB error."); + restJson.put("message", "Add vnf into DB error."); + } + return restJson; + } + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + private boolean checkId(String id) { + VnfEntity vnf = vnfDao.getVnf(id); + if(null == vnf) { + return true; + } + return false; + } + + /** + *
+ * + * @param map + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public List getList(Map map) throws ServiceException { + return vnfDao.getVnfs(map); + } + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public int delete(String id) throws ServiceException { + deleteVnfInfo(id); + return vnfDao.deleteVnfById(id); + } + + /** + *
+ * + * @param id + * @throws ServiceException + * @since NFVO 0.5 + */ + private void deleteVnfInfo(String vnfInstanceId) throws ServiceException { + vnfInfoService.delete(vnfInstanceId); + } + + public void setVnfDao(VnfDao vnfDao) { + this.vnfDao = vnfDao; + } + + public void setVnfInfoService(VnfInfoService vnfInfoService) { + this.vnfInfoService = vnfInfoService; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfStatusServiceImpl.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfStatusServiceImpl.java new file mode 100644 index 0000000..49bfda1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/impl/VnfStatusServiceImpl.java @@ -0,0 +1,117 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.impl; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.VnfStatusDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfStatusService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +public class VnfStatusServiceImpl implements VnfStatusService { + + private static final Logger LOGGER = LoggerFactory.getLogger(VnfStatusServiceImpl.class); + + private VnfStatusDao vnfStatusDao; + + /** + *
+ * + * @param object + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public JSONObject addVnfStatus(JSONObject object) throws ServiceException { + LOGGER.info("function=addVnfStatus; object: {}", object); + VnfStatusEntity vnfStatusEntity = VnfStatusEntity.toEntity(object); + int result; + if(!checkId(vnfStatusEntity.getVnfInstanceId())) { + result = vnfStatusDao.updateVnfStatus(vnfStatusEntity); + } else { + result = vnfStatusDao.addVnfStatus(vnfStatusEntity); + } + JSONObject resultObj = new JSONObject(); + if(result > 0) { + resultObj.put("vnfInstanceId", object.get("vnfInstanceId")); + } else { + LOGGER.error("function=addVnfStatus; msg=add vnfStatus into DB error."); + resultObj.put("message", "Add vnfStatus into DB error."); + } + return resultObj; + } + + /** + *
+ * + * @param vnfInstanceId + * @return + * @since NFVO 0.5 + */ + private boolean checkId(String vnfInstanceId) { + VnfStatusEntity vnfStatus = vnfStatusDao.getVnfStatus(vnfInstanceId); + if(null == vnfStatus) { + return true; + } + return false; + } + + /** + *
+ * + * @param map + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public List getList(Map map) throws ServiceException { + return vnfStatusDao.getVnfStatuss(map); + } + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public int delete(String id) throws ServiceException { + return vnfStatusDao.deleteVnfStatusById(id); + } + + public void setVnfStatusDao(VnfStatusDao vnfStatusDao) { + this.vnfStatusDao = vnfStatusDao; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/GrantResService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/GrantResService.java new file mode 100644 index 0000000..ff483e3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/GrantResService.java @@ -0,0 +1,44 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.inf; + +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +public interface GrantResService { + + /** + *
+ * + * @param object + * @return + * @since NFVO 0.5 + */ + JSONObject grantResource(JSONObject object) throws ServiceException; + + JSONObject grantResourceReal(JSONObject object) throws ServiceException; + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/ResOperateService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/ResOperateService.java new file mode 100644 index 0000000..89c2d67 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/ResOperateService.java @@ -0,0 +1,82 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.inf; + +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + * resource operational service class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface ResOperateService { + + /** + * Update iresource.
+ * + * @param tenantId + * @param vimId + * @param header + * @throws ServiceException + * @since NFVO 0.5 + */ + void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException; + + /** + * Update all iResource.
+ * + * @throws ServiceException + * @since NFVO 0.5 + */ + void updateAllIRes() throws ServiceException; + + /** + * Add iResource.
+ * + * @param tenantId + * @param vimId + * @param header + * @throws ServiceException + * @since NFVO 0.5 + */ + void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException; + + /** + * Delete iResource.
+ * + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int deleteIRes(String vimId) throws ServiceException; + + /** + *
+ * + * @param operateType + * @param vimId + * @throws ServiceException + * @since NFVO 0.5 + */ + void sendMsgMonitor(String operateType, String vimId) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VirtualLinkService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VirtualLinkService.java new file mode 100644 index 0000000..a74c08a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VirtualLinkService.java @@ -0,0 +1,64 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 27, 2016 + */ +public interface VirtualLinkService { + + /** + *
+ * + * @param virtualLinkEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException; + + /** + *
+ * + * @param map + * @return + * @since NFVO 0.5 + */ + List getList(Map map) throws ServiceException; + + /** + *
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + int delete(String id) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VmService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VmService.java new file mode 100644 index 0000000..8b5d56f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VmService.java @@ -0,0 +1,44 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +public interface VmService { + + JSONObject addVm(VmEntity vmEntity) throws ServiceException; + + List getList(Map map) throws ServiceException; + + int delete(String id) throws ServiceException; + + int deleteByVnfId(String vnfInstanceId) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfInfoService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfInfoService.java new file mode 100644 index 0000000..da408e1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfInfoService.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public interface VnfInfoService { + + JSONObject addVnfInfo(JSONObject object) throws ServiceException; + + List getList(Map map) throws ServiceException; + + int delete(String id) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfService.java new file mode 100644 index 0000000..196f383 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfService.java @@ -0,0 +1,66 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +public interface VnfService { + + /** + *
+ * + * @param vnfEntity + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException; + + /** + *
+ * + * @param map + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + List getList(Map map) throws ServiceException; + + /** + *
+ * + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + int delete(String id) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfStatusService.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfStatusService.java new file mode 100644 index 0000000..df5e4d9 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/group/inf/VnfStatusService.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +public interface VnfStatusService { + + JSONObject addVnfStatus(JSONObject object) throws ServiceException; + + List getList(Map map) throws ServiceException; + + int delete(String id) throws ServiceException; +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/HostMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/HostMapper.java new file mode 100644 index 0000000..6372c33 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/HostMapper.java @@ -0,0 +1,114 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; + +/** + * Host info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface HostMapper { + + /** + * It is used to get Host info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + HostEntity getHost(String id); + + /** + * It is used to get Hosts info.
+ * + * @param condition + * @return The get result + * @since NFVO 0.5 + */ + List getHosts(Map condition); + + /** + * It is used to delete Hosts info.
+ * + * @param id + * @return The delete result + * @since NFVO 0.5 + */ + int deleteHost(String id); + + /** + * It is used to delete Hosts info.
+ * + * @param vimId + * @return The delete result + * @since NFVO 0.5 + */ + int deleteHostByVimId(String vimId); + + /** + * It is used to add Hosts info.
+ * + * @param hostEntity + * @return The add result + * @since NFVO 0.5 + */ + int addHost(HostEntity hostEntity); + + /** + * It is used to add Hosts info.
+ * + * @param hostEntity + * @return The add result + * @since NFVO 0.5 + */ + int addHostSelective(HostEntity hostEntity); + + /** + * It is used to update Hosts info.
+ * + * @param hostEntity + * @return The update result + * @since NFVO 0.5 + */ + int updateHostSelective(HostEntity hostEntity); + + /** + * It is used to update Hosts info.
+ * + * @param hostEntity + * @return The update result + * @since NFVO 0.5 + */ + int updateHost(HostEntity hostEntity); + + /** + * It is used to update Hosts info.
+ * + * @param hostEntity + * @return The update result + * @since NFVO 0.5 + */ + int updateHostByVimId(HostEntity hostEntity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/LocationMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/LocationMapper.java new file mode 100644 index 0000000..4af0e3d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/LocationMapper.java @@ -0,0 +1,123 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; + +/** + * + * Location Mapper Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface LocationMapper { + + /** + * + * Get location.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + LocationEntity getLocation(String id); + + /** + * + * Get Country.
+ * + * @return + * @since NFVO 0.5 + */ + List getCountry(); + + /** + * + * Get location by country.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getLocationByCountry(Map condition); + + /** + * + * get locations.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getLocations(Map condition); + + /** + * + * Delete location.
+ * + * @param location + * @return + * @since NFVO 0.5 + */ + int deleteLocation(String location); + + /** + * + * Add location.
+ * + * @param locationEntity + * @return + * @since NFVO 0.5 + */ + int addLocation(LocationEntity locationEntity); + + /** + * + * Add selective location.
+ * + * @param locationEntity + * @return + * @since NFVO 0.5 + */ + int addLocationSelective(LocationEntity locationEntity); + + /** + * + * Update selective location.
+ * + * @param locationEntity + * @return + * @since NFVO 0.5 + */ + int updateLocationSelective(LocationEntity locationEntity); + + /** + * + * Update location.
+ * + * @param locationEntity + * @return + * @since NFVO 0.5 + */ + int updateLocation(LocationEntity locationEntity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/NetworkMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/NetworkMapper.java new file mode 100644 index 0000000..c18233d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/NetworkMapper.java @@ -0,0 +1,125 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; + +/** + * + * Network Mapper Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public interface NetworkMapper { + + /** + * + * Get network details.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + NetworkEntity getNetwork(String id); + + /** + * + * Get details of networks.
+ * + * @param condition + * @return + * @since NFVO 0.5 + */ + List getNetworks(Map condition); + + /** + * + * Delete network.
+ * + * @param id + * @return + * @since NFVO 0.5 + */ + int deleteNetwork(String id); + + /** + * + * Delete network by VIM ID.
+ * + * @param vimId + * @return + * @since NFVO 0.5 + */ + int deleteNetworkByVimId(String vimId); + + /** + * + * Add network.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int addNetwork(NetworkEntity networkEntity); + + /** + * + * Add selective network.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int addNetworkSelective(NetworkEntity networkEntity); + + /** + * + * Update selective network.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int updateNetworkSelective(NetworkEntity networkEntity); + + /** + * + * Update network.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int updateNetwork(NetworkEntity networkEntity); + + /** + * + * Update network by VIM Id.
+ * + * @param networkEntity + * @return + * @since NFVO 0.5 + */ + int updateNetworkByVimId(NetworkEntity networkEntity); + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/PortMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/PortMapper.java new file mode 100644 index 0000000..cff6e7f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/PortMapper.java @@ -0,0 +1,114 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; + +/** + * Port info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface PortMapper { + + /** + * It is used to get Port info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + PortEntity getPort(String id); + + /** + * It is used to get Ports info.
+ * + * @param condition + * @return The get result + * @since NFVO 0.5 + */ + List getPorts(Map condition); + + /** + * It is used to delete Ports info.
+ * + * @param id + * @return The delete result + * @since NFVO 0.5 + */ + int deletePort(String id); + + /** + * It is used to delete Ports info.
+ * + * @param vimId + * @return The delete result + * @since NFVO 0.5 + */ + int deletePortByVimId(String vimId); + + /** + * It is used to add Ports info.
+ * + * @param portEntity + * @return The add result + * @since NFVO 0.5 + */ + int addPort(PortEntity portEntity); + + /** + * It is used to add Ports info.
+ * + * @param portEntity + * @return The add result + * @since NFVO 0.5 + */ + int addPortSelective(PortEntity portEntity); + + /** + * It is used to update Ports info.
+ * + * @param portEntity + * @return The update result + * @since NFVO 0.5 + */ + int updatePortSelective(PortEntity portEntity); + + /** + * It is used to update Ports info.
+ * + * @param portEntity + * @return The update result + * @since NFVO 0.5 + */ + int updatePort(PortEntity portEntity); + + /** + * It is used to update Ports info.
+ * + * @param portEntity + * @return The update result + * @since NFVO 0.5 + */ + int updatePortByVimId(PortEntity portEntity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/SitesMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/SitesMapper.java new file mode 100644 index 0000000..e92f753 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/SitesMapper.java @@ -0,0 +1,111 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; + +/** + * ResPool info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface SitesMapper { + + /** + * It is used to get Sites info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + SitesEntity getSite(String id); + + /** + * + * It is used to get Sites info.
+ * + * @param map + * @return + * @since NFVO 0.5 + */ + List getSites(Map map); + + /** + * It is used to get Sites info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + int deleteSite(String id); + + /** + * + * It is used to delete Site info.
+ * + * @param entity + * @return + * @since NFVO 0.5 + */ + int addSite(SitesEntity entity); + + /** + * + * It is used to add Sites info.
+ * + * @param entity + * @return + * @since NFVO 0.5 + */ + int addSiteSelective(SitesEntity entity); + + /** + * + * It is used to add Site info.
+ * + * @param entity + * @return + * @since NFVO 0.5 + */ + int updateSiteSelective(SitesEntity entity); + + /** + * + * It is used to update Sites info.
+ * + * @param entity + * @return + * @since NFVO 0.5 + */ + int updateSite(SitesEntity entity); + + /** + * + * It is used to update Site info.
+ * + * @param entity + * @return + * @since NFVO 0.5 + */ + int updateSiteByVimId(SitesEntity entity); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VimMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VimMapper.java new file mode 100644 index 0000000..05fdfc2 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VimMapper.java @@ -0,0 +1,68 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; + +/** + * Vim info interface.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public interface VimMapper { + + /** + * It is used to get Vim info.
+ * + * @param id + * @return The get result + * @since NFVO 0.5 + */ + VimEntity getVim(String id); + + /** + * It is used to get Vims info.
+ * + * @return The get result + * @since NFVO 0.5 + */ + List getVims(); + + /** + * It is used to delete Vim info.
+ * + * @param id + * @return The delete result + * @since NFVO 0.5 + */ + int deleteVim(String id); + + /** + * It is used to add Vim info.
+ * + * @param vimEntity + * @return The add result + * @since NFVO 0.5 + */ + int addVim(VimEntity vimEntity); + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VirtualLinkMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VirtualLinkMapper.java new file mode 100644 index 0000000..32d4714 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VirtualLinkMapper.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VirtualLinkEntity; + +public interface VirtualLinkMapper { + + int deleteByPrimaryKey(String id); + + int insert(VirtualLinkEntity record); + + int insertSelective(VirtualLinkEntity record); + + VirtualLinkEntity selectByPrimaryKey(String id); + + List getVls(Map condition); + + int updateByPrimaryKeySelective(VirtualLinkEntity record); + + int updateByPrimaryKey(VirtualLinkEntity record); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VmMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VmMapper.java new file mode 100644 index 0000000..c9f7ed4 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VmMapper.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; + +public interface VmMapper { + + int deleteByPrimaryKey(String vmId); + + int deleteByVnfId(String vnfInstanceId); + + int insert(VmEntity record); + + int insertSelective(VmEntity record); + + VmEntity selectByPrimaryKey(String vmId); + + List getVms(Map condition); + + int updateByPrimaryKeySelective(VmEntity record); + + int updateByPrimaryKey(VmEntity record); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfInfoMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfInfoMapper.java new file mode 100644 index 0000000..fd0c0c8 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfInfoMapper.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfInfoEntity; + +public interface VnfInfoMapper { + + int deleteByPrimaryKey(String vnfInstanceId); + + int insert(VnfInfoEntity record); + + int insertSelective(VnfInfoEntity record); + + VnfInfoEntity selectByPrimaryKey(String vnfInstanceId); + + List getVnfInfos(Map condition); + + int updateByPrimaryKeySelective(VnfInfoEntity record); + + int updateByPrimaryKey(VnfInfoEntity record); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfMapper.java new file mode 100644 index 0000000..57afa8f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfMapper.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity; + +public interface VnfMapper { + + int deleteByPrimaryKey(String vnfInstanceId); + + int insert(VnfEntity record); + + int insertSelective(VnfEntity record); + + VnfEntity selectByPrimaryKey(String id); + + List getVnfs(Map condition); + + int updateByPrimaryKeySelective(VnfEntity record); + + int updateByPrimaryKey(VnfEntity record); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfStatusMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfStatusMapper.java new file mode 100644 index 0000000..d9652de --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/mapper/VnfStatusMapper.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfStatusEntity; + +public interface VnfStatusMapper { + + int deleteByPrimaryKey(String vnfInstanceId); + + int insert(VnfStatusEntity record); + + int insertSelective(VnfStatusEntity record); + + VnfStatusEntity selectByPrimaryKey(String vnfInstanceId); + + List getVnfStatuss(Map condition); + + int updateByPrimaryKeySelective(VnfStatusEntity record); + + int updateByPrimaryKey(VnfStatusEntity record); +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/GrantResourseRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/GrantResourseRoa.java new file mode 100644 index 0000000..23190a7 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/GrantResourseRoa.java @@ -0,0 +1,94 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.GrantResService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +@Path(UrlConstant.GRANTRES_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class GrantResourseRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(GrantResourseRoa.class); + + private GrantResService grantResService; + + @PUT + @Path("/stub") + public JSONObject grantResource(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + if(null == object) { + LOGGER.error("function=grantResource; msg=grantResource error, because body is null."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.grantResource.null")); + } + + LOGGER.info("GrantResourseRoa::grantResource:{}", object.toString()); + try { + return grantResService.grantResource(object); + } catch(ServiceException se) { + LOGGER.error("GrantResourseRoa::grantResource error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + @PUT + public JSONObject grantResourceReal(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + if(null == object) { + LOGGER.error("function=grantResource; msg=grantResource error, because body is null."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.grantResource.null")); + } + + LOGGER.info("GrantResourseRoa::grantResource:{}", object.toString()); + try { + return grantResService.grantResourceReal(object); + } catch(ServiceException se) { + LOGGER.error("GrantResourseRoa::grantResource error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setGrantResService(GrantResService grantResService) { + this.grantResService = grantResService; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/HostRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/HostRoa.java new file mode 100644 index 0000000..43f0993 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/HostRoa.java @@ -0,0 +1,183 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Host; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * + * Host ROA Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +@Path(UrlConstant.HOST_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class HostRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(HostRoa.class); + + private Host host; + + /** + * + * Get hosts.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + public JSONObject getHosts(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap<>(10); + List hosts = host.getList(map); + + JSONObject result = new JSONObject(); + result.put("hosts", hosts); + return result; + } + + /** + * + * Get host.
+ * + * @param context + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/{hostId}") + public JSONObject getHost(@Context HttpServletRequest context, @PathParam("hostId") String id) + throws ServiceException { + LOGGER.info("HostRoa::getHost id:{}", id); + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_ID, id); + List hosts = host.getList(map); + + JSONObject result = new JSONObject(); + result.put("hosts", hosts); + return result; + } + + /** + * + * Add host.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + public JSONObject addHost(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + + LOGGER.info("HostRoa::addHost:{}", object.toString()); + try { + int result = host.add(object); + return RoaResponseUtil.add(result); + } catch(ServiceException se) { + LOGGER.error("HostRoa::addHost error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * + * Delete host.
+ * + * @param context + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @DELETE + public JSONObject deleteHost(@Context HttpServletRequest context, @QueryParam(ParamConstant.PARAM_ID) String id) + throws ServiceException { + LOGGER.info("HostRoa::deleteHost id:{}", id); + try { + int result = host.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("HostRoa::deleteHost error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * + * Update host.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @PUT + public JSONObject updateHost(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + + LOGGER.info("HostRoa::updateHost:{}", object.toString()); + try { + int result = host.update(object); + return RoaResponseUtil.update(result); + } catch(ServiceException se) { + LOGGER.error("HostRoa::updateHost error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setHost(Host host) { + this.host = host; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/LimitsRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/LimitsRoa.java new file mode 100644 index 0000000..2b86d3e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/LimitsRoa.java @@ -0,0 +1,73 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.LimitsBusiness; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +@Path(UrlConstant.LIMITS_URL) +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class LimitsRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(LimitsRoa.class); + + private LimitsBusiness limitsBusiness; + + /** + *
+ * + * @param context + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + public JSONObject getLimits(@Context HttpServletRequest context, + @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException { + LOGGER.warn("function=getLimits, vimId={}", vimId); + return limitsBusiness.getLimits(vimId); + } + + public void setLimitsBusiness(LimitsBusiness limitsBusiness) { + this.limitsBusiness = limitsBusiness; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/LocationRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/LocationRoa.java new file mode 100644 index 0000000..b875f53 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/LocationRoa.java @@ -0,0 +1,316 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Location; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * Location ROA Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +@Path(UrlConstant.LOCATION_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class LocationRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(LocationRoa.class); + + private Location location; + + private Sites sites; + + /** + * Get Locations Base.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + public JSONObject getLocationsbase(@Context HttpServletRequest context) throws ServiceException { + Map condition = new HashMap<>(); + List locations = location.get(condition); + + JSONObject result = new JSONObject(); + result.put("locations", locations); + return result; + } + + /** + * Get Locations Base.
+ * + * @param context + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/{locationId}") + public JSONObject getLocationbase(@Context HttpServletRequest context, @PathParam("locationId") String id) + throws ServiceException { + LOGGER.info("LocationRoa::getLocationbase id:{}", id); + Map map = new HashMap<>(); + map.put(ParamConstant.PARAM_ID, id); + List locations = location.get(map); + + JSONObject result = new JSONObject(); + result.put("locations", locations); + return result; + } + + /** + * Get Country.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/country") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject getCountry(@Context HttpServletRequest context) throws ServiceException { + return RoaResponseUtil.get(location.getCountry()); + } + + /** + * Get Location by Country.
+ * + * @param context + * @param country + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/locationbycountry") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject getLocationByCountry(@Context HttpServletRequest context, + @QueryParam(ParamConstant.PARAM_COUNTRY) String country) throws ServiceException { + LOGGER.info("LocationRoa::getLocationByCountry country:{}", country); + Map condition = new HashMap<>(); + condition.put(ParamConstant.PARAM_COUNTRY, country); + return RoaResponseUtil.get(location.getLocationByCountry(condition)); + } + + /** + * Get Cloud Service.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/cloudservice") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject getCloudservice(@Context HttpServletRequest context) throws ServiceException { + return RoaResponseUtil.get(location.getCloudservice()); + } + + /** + * Get location details.
+ * + * @param context + * @param locations + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/site") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject getLocation(@Context HttpServletRequest context, + @QueryParam(ParamConstant.PARAM_LOCATION) String locations) throws ServiceException { + LOGGER.info("LocationRoa::getLocation locations:{}", locations); + Map condition = new HashMap<>(); + List loca = new ArrayList(); + condition.put(ParamConstant.PARAM_LOCATION, locations); + loca = location.get(condition); + LOGGER.info("LocationRoa::getLocation loca:{}", loca); + return RoaResponseUtil.get(location.getLocationInfo(loca)); + } + + /** + * Add Location.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject addLocation(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + + LOGGER.info("LocationRoa::addLocation : " + object.toString()); + try { + int result = location.add(object); + return RoaResponseUtil.add(result); + } catch(ServiceException se) { + LOGGER.error("LocationRoa::addLocation error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * Delete Location Base.
+ * + * @param context + * @param locations + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @DELETE + @Path("/{location}") + public JSONObject deleteLocationbase(@Context HttpServletRequest context, + @PathParam(ParamConstant.PARAM_LOCATION) String locations) throws ServiceException { + LOGGER.info("LocationRoa::deleteLocation locations:{}", locations); + Map condition = new HashMap<>(); + condition.put(ParamConstant.PARAM_LOCATION, locations); + try { + int result = location.delete(locations); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("LocationRoa::deleteLocationbase error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * Delete Location.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @DELETE + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject deleteLocation(@Context HttpServletRequest context) throws ServiceException { + + JSONObject object = RequestUtil.getJsonRequestBody(context); + String locations = JsonUtil.getJsonFieldStr(object, ParamConstant.PARAM_LOCATION); + String id = JsonUtil.getJsonFieldStr(object, ParamConstant.PARAM_ID); + LOGGER.info("LocationRoa::deleteLocation locations:{}", locations); + + Map condition = new HashMap<>(); + condition.put(ParamConstant.PARAM_LOCATION, locations); + SitesEntity sitesEntity = sites.get(condition); + try { + if(sitesEntity != null) { + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.delete.used.check")); + } + int result = location.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("LocationRoa::deleteLocation error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * Update Location.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @PUT + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject updateLocation(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + String local = JsonUtil.getJsonFieldStr(object, ParamConstant.PARAM_LOCATION); + Map localInfo = new HashMap<>(); + localInfo.put(ParamConstant.PARAM_LOCATION, local); + SitesEntity sitesEntity = sites.get(localInfo); + if(sitesEntity != null) { + LOGGER.error("function=updateLocation; msg=update error, because location is used."); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.base.location.update.used.check")); + } + LOGGER.info("LocationRoa::updateLocation : " + object.toString()); + + try { + int result = location.update(object); + return RoaResponseUtil.update(result); + } catch(ServiceException se) { + LOGGER.error("LocationRoa::update Location error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setLocation(Location location) { + this.location = location; + } + + public void setSites(Sites sites) { + this.sites = sites; + } + +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NetworkRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NetworkRoa.java new file mode 100644 index 0000000..22dc8e1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/NetworkRoa.java @@ -0,0 +1,189 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Network; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * + * Network ROA Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +@Path(UrlConstant.NETWORKS_URL) +@Consumes({MediaType.APPLICATION_JSON}) +@Produces({MediaType.APPLICATION_JSON}) +public class NetworkRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(NetworkRoa.class); + + private Network network; + + /** + * + * Get details of networks.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + public JSONObject getNetworks(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap<>(10); + List networks = network.getList(map); + + JSONObject result = new JSONObject(); + result.put("networks", networks.toString()); + return result; + } + + /** + * + * Get network details.
+ * + * @param context + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/{networkId}") + public JSONObject getNetwork(@Context HttpServletRequest context, @PathParam("networkId") String id) + throws ServiceException { + LOGGER.info("NetworkRoa::getNetwork id:{}", id); + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_ID, id); + List networks = network.getList(map); + + JSONObject result = new JSONObject(); + result.put("networks", networks.toString()); + return result; + } + + /** + * + * Add network.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + public JSONObject addNetwork(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + + LOGGER.info("NetworkRoa::addNetwork:{}", object.toString()); + try { + int result = network.add(NetworkEntity.toEntity(object)); + return RoaResponseUtil.add(result); + } catch(ServiceException se) { + LOGGER.error("NetworkRoa::addNetwork error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * + * Delete network.
+ * + * @param context + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @DELETE + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + public JSONObject deleteNetwork(@Context HttpServletRequest context, @QueryParam(ParamConstant.PARAM_ID) String id) + throws ServiceException { + LOGGER.info("NetworkRoa::deleteNetwork id:{}", id); + try { + int result = network.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("NetworkRoa::deleteNetwork error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * + * Update network.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @PUT + @Consumes({MediaType.APPLICATION_JSON}) + @Produces({MediaType.APPLICATION_JSON}) + public JSONObject updateNetwork(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + + LOGGER.info("NetworkRoa::updateNetwork:{}", object.toString()); + try { + int result = network.update(object); + return RoaResponseUtil.update(result); + } catch(ServiceException se) { + LOGGER.error("NetworkRoa::updateNetwork error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setNetwork(Network network) { + this.network = network; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/PortRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/PortRoa.java new file mode 100644 index 0000000..dbe5780 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/PortRoa.java @@ -0,0 +1,183 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Port; +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * + * Port ROA Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +@Path(UrlConstant.PORT_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class PortRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(PortRoa.class); + + private Port port; + + /** + * + * Get details of Ports.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + public JSONObject getPorts(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap<>(10); + List ports = port.getList(map); + + JSONObject result = new JSONObject(); + result.put("ports", ports); + return result; + } + + /** + * + * Get port details.
+ * + * @param context + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/{portId}") + public JSONObject getPort(@Context HttpServletRequest context, @PathParam("portId") String id) + throws ServiceException { + LOGGER.info("PortRoa::getPort id:{}", id); + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_ID, id); + List ports = port.getList(map); + + JSONObject result = new JSONObject(); + result.put("ports", ports); + return result; + } + + /** + * + * Add port.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + public JSONObject addPort(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + + LOGGER.info("PortRoa::addPort:{}", object.toString()); + try { + int result = port.add(PortEntity.toEntity(object)); + return RoaResponseUtil.add(result); + } catch(ServiceException se) { + LOGGER.error("PortRoa::addPort error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * + * Delete port.
+ * + * @param context + * @param id + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @DELETE + public JSONObject deletePort(@Context HttpServletRequest context, @QueryParam(ParamConstant.PARAM_ID) String id) + throws ServiceException { + LOGGER.info("PortRoa::deletePort id:{}", id); + try { + int result = port.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("PortRoa::deletePort error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * + * Update port.
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @PUT + public JSONObject updatePort(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + + LOGGER.info("PortRoa::updatePort:{}", object.toString()); + try { + int result = port.update(object); + return RoaResponseUtil.update(result); + } catch(ServiceException se) { + LOGGER.error("PortRoa::updatePort error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setPort(Port port) { + this.port = port; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/ResOperateRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/ResOperateRoa.java new file mode 100644 index 0000000..4a4a976 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/ResOperateRoa.java @@ -0,0 +1,151 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.ResOperateService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * Resource Operate ROA Class.
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +@Path(UrlConstant.RESOPERATE_URL) +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class ResOperateRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(ResOperateRoa.class); + + private ResOperateService resOperateService; + + /** + * Update iResource pool.
+ * + * @param context + * @param tenantId + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @PUT + @Path(UrlConstant.MODRES_URL) + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject updateIResPool(@Context HttpServletRequest context, + @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException { + JSONObject json = RequestUtil.getAllJsonRequestBody(context); + LOGGER.warn("ResPoolRoa::modVimId :{}", vimId); + JSONObject vimInfo = VimUtil.getVimById(vimId); + String tenant = vimInfo.getString("tenant"); + String tenantId = VimUtil.getTenantIdByName(tenant, vimId); + try { + resOperateService.updateIRes(tenantId, vimId, json); + resOperateService.sendMsgMonitor("update", vimId); + return RoaResponseUtil.update(HttpConstant.OK_CODE); + } catch(ServiceException se) { + LOGGER.error("ResOperateRoa::updateIResPool error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * Add all resource pool.
+ * + * @param context + * @param tenantId + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + @Path(UrlConstant.ADDRES_URL) + @Consumes(UrlConstant.APPLICATION_TYPE) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject addAllResPool(@Context HttpServletRequest context, + @QueryParam(ParamConstant.PARAM_TENANTID) String tenantId, + @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException { + JSONObject json = RequestUtil.getAllJsonRequestBody(context); + LOGGER.warn("ResOperateRoa::vimId :{}", vimId); + + try { + resOperateService.addIRes(tenantId, vimId, json); + resOperateService.sendMsgMonitor("create", vimId); + return RoaResponseUtil.add(HttpConstant.OK_CODE); + } catch(ServiceException se) { + LOGGER.error("ResOperateRoa::addAllResPool error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * Delete iResource.
+ * + * @param context + * @param vimId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @DELETE + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + public JSONObject deleteIRes(@Context HttpServletRequest context, + @QueryParam(ParamConstant.PARAM_VIMID) String vimId) throws ServiceException { + LOGGER.warn("ResOperateRoa::deleteIResource vimId:{}", vimId); + + try { + resOperateService.sendMsgMonitor("delete", vimId); + int result = resOperateService.deleteIRes(vimId); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("ResOperateRoa::deleteIRes error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setResOperateService(ResOperateService resOperateService) { + this.resOperateService = resOperateService; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/SitesRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/SitesRoa.java new file mode 100644 index 0000000..9b7c8e4 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/SitesRoa.java @@ -0,0 +1,224 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * Sites ROA method
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +@Path(UrlConstant.SITES_URL) +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class SitesRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(SitesRoa.class); + + private Sites sites; + + /** + * getSites ROA method
+ * + * @param context + * @return the get result + * @throws ServiceException When get failed. + * @since NFVO 0.5 + */ + @GET + public JSONObject getSites(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap(10); + List datacenters = sites.getList(map); + + JSONObject result = new JSONObject(); + result.put("datacenters", datacenters); + return result; + } + + /** + * getSite ROA method
+ * + * @param context + * @param id + * @return the get result + * @throws ServiceException When get failed. + * @since NFVO 0.5 + */ + @GET + @Path("/{datacenterId}") + public JSONObject getSite(@Context HttpServletRequest context, @PathParam("datacenterId") String id) + throws ServiceException { + LOGGER.warn("SitesRoa::getSitesById id:{}", id); + Map map = new HashMap(10); + map.put(ParamConstant.PARAM_ID, id); + List datacenters = sites.getList(map); + + JSONObject result = new JSONObject(); + result.put("datacenters", datacenters); + return result; + } + + /** + * addSites ROA method
+ * + * @param context + * @param id + * @return the add result + * @throws ServiceException When add failed. + * @since NFVO 0.5 + */ + @POST + public JSONObject addSites(@Context HttpServletRequest context) throws ServiceException { + JSONObject json = RequestUtil.getAllJsonRequestBody(context); + + LOGGER.warn("SitesRoa:: start add Sites"); + try { + int result = sites.add(json); + sites.sendToMonitor(json); + return RoaResponseUtil.add(result); + } catch(ServiceException se) { + LOGGER.error("SitesRoa::addSites error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * deleteSites ROA method
+ * + * @param context + * @param id + * @return the delete result + * @throws ServiceException When delete failed. + * @since NFVO 0.5 + */ + @DELETE + @Path("/{datacenterId}") + public JSONObject deleteSites(@Context HttpServletRequest context, @PathParam("datacenterId") String id) + throws ServiceException { + LOGGER.warn("SitesRoa::deleteSites siteId:{}", id); + try { + int result = sites.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("SitesRoa::deleteSites error: " + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * updateSites ROA method
+ * + * @param context + * @param id + * @return the update result + * @throws ServiceException When update failed. + * @since NFVO 0.5 + */ + @PUT + public JSONObject updateSites(@Context HttpServletRequest context) throws ServiceException { + JSONObject json = RequestUtil.getAllJsonRequestBody(context); + + LOGGER.warn("SitesRoa::start update Sites"); + try { + int result = sites.update(SitesEntity.toEntity(json)); + return RoaResponseUtil.update(result); + } catch(ServiceException se) { + LOGGER.error("SitesRoa::updateSites error:" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + /** + * grant resource method + *
+ * + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @PUT + @Path("/grant") + public JSONObject grantResource(@Context HttpServletRequest context) throws ServiceException { + JSONObject json = RequestUtil.getAllJsonRequestBody(context); + + LOGGER.warn("SitesRoa::grant resource"); + try { + int result = sites.update(json); + return RoaResponseUtil.update(result); + } catch(ServiceException se) { + LOGGER.error("SitesRoa::grant resource:" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + @GET + @Path("/vims") + public String getVims(@Context HttpServletRequest context) throws ServiceException { + LOGGER.info("SitesRoa::get vims"); + JSONArray vims = VimUtil.getVims(); + JSONObject result = new JSONObject(); + result.put("data", vims); + return result.toString(); + } + + @GET + @Path("/vims/{vimId}") + public String getVim(@Context HttpServletRequest context, @PathParam("vimId") String vimId) + throws ServiceException { + LOGGER.info("SitesRoa::get vim by id: {}", vimId); + return VimUtil.getVimById(vimId).toString(); + } + + public void setSites(Sites sites) { + this.sites = sites; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/SwaggerRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/SwaggerRoa.java new file mode 100644 index 0000000..3651102 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/SwaggerRoa.java @@ -0,0 +1,49 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.io.IOException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.apache.commons.io.IOUtils; + +/** + * Swagger API Doc.
+ * + * @author + * @version NFVO 0.5 Oct 24, 2016 + */ +@Path("/v1") +@Produces({MediaType.APPLICATION_JSON}) +public class SwaggerRoa { + /** + * API doc. + * @param filename + * @return + * @throws IOException + */ + @GET + @Path("/swagger.json") + public String apidoc() throws IOException{ + ClassLoader classLoader = getClass().getClassLoader(); + return IOUtils.toString(classLoader.getResourceAsStream("swagger.json")); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VirtualLinkRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VirtualLinkRoa.java new file mode 100644 index 0000000..fd2a325 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VirtualLinkRoa.java @@ -0,0 +1,129 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VirtualLinkService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 27, 2016 + */ +@Path(UrlConstant.VL_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class VirtualLinkRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkRoa.class); + + private VirtualLinkService virtualLink; + + @GET + public JSONObject getVls(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap<>(10); + List vls = virtualLink.getList(map); + LOGGER.info("VirtualLinkRoa::getVls:{}", vls.toString()); + JSONObject result = new JSONObject(); + result.put("vls", vls); + return result; + } + + @GET + @Path("/{vlId}") + public JSONObject getVl(@Context HttpServletRequest context, @PathParam("vlId") String id) throws ServiceException { + LOGGER.info("VirtualLinkRoa::getVl id:{}", id); + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_ID, id); + List vls = virtualLink.getList(map); + LOGGER.info("VirtualLinkRoa::getVl:{}", vls.toString()); + JSONObject result = new JSONObject(); + result.put("vls", vls); + return result; + } + + @POST + public JSONObject addVl(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + if(null == object) { + LOGGER.error("function=addVl; msg=add error, because vl is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.virtualLink.add.null")); + } + + LOGGER.info("VirtualLinkRoa::addVl:{}", object.toString()); + try { + return virtualLink.addVl(VirtualLinkEntity.toEntity(object)); + } catch(ServiceException se) { + LOGGER.error("VirtualLinkRoa::addVl error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + @DELETE + @Path("/{id}") + public JSONObject deleteVl(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) + throws ServiceException { + if(id == null) { + LOGGER.error("function=deleteVl; msg=delete error, because vlId is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.virtualLink.delete.vlId.null")); + } + LOGGER.info("VirtualLinkRoa::deleteVl id:{}", id); + try { + int result = virtualLink.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("VirtualLinkRoa::deleteVl error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setVirtualLink(VirtualLinkService virtualLink) { + this.virtualLink = virtualLink; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VmRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VmRoa.java new file mode 100644 index 0000000..a13d295 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VmRoa.java @@ -0,0 +1,127 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VmService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +@Path(UrlConstant.VM_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class VmRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(VmRoa.class); + + private VmService vmService; + + @GET + public JSONObject getVms(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap<>(10); + List vms = vmService.getList(map); + LOGGER.info("VmRoa::getVms:{}", vms.toString()); + JSONObject result = new JSONObject(); + result.put("vms", vms); + return result; + } + + @GET + @Path("/{vmId}") + public JSONObject getVm(@Context HttpServletRequest context, @PathParam("vmId") String id) throws ServiceException { + LOGGER.info("VmRoa::getVm id:{}", id); + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_ID, id); + List vms = vmService.getList(map); + LOGGER.info("VmRoa::getVm:{}", vms.toString()); + JSONObject result = new JSONObject(); + result.put("vms", vms); + return result; + } + + @POST + public JSONObject addVm(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + if(null == object) { + LOGGER.error("function=addVm; msg=add error, because vm is null."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vm.add.null")); + } + + LOGGER.info("VmRoa::addVm:{}", object.toString()); + try { + return vmService.addVm(VmEntity.toEntity(object)); + } catch(ServiceException se) { + LOGGER.error("VmRoa::addVm error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + @DELETE + @Path("/{id}") + public JSONObject deleteVm(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) + throws ServiceException { + if(id == null) { + LOGGER.error("function=deleteVm; msg=delete error, because id is null."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vm.delete.id.null")); + } + LOGGER.info("VmRoa::deleteVm id:{}", id); + try { + int result = vmService.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("VmRoa::deleteVm error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setVmService(VmService vmService) { + this.vmService = vmService; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfInfoRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfInfoRoa.java new file mode 100644 index 0000000..25351d6 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfInfoRoa.java @@ -0,0 +1,129 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfInfoService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +@Path(UrlConstant.VNFINFO_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class VnfInfoRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(VnfInfoRoa.class); + + private VnfInfoService vnfInfoService; + + @GET + public JSONObject getVnfInfos(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap<>(10); + List vnfInfos = vnfInfoService.getList(map); + LOGGER.info("VnfInfoRoa::getVnfInfos:{}", vnfInfos.toString()); + JSONObject result = new JSONObject(); + result.put("vnfInfos", vnfInfos); + return result; + } + + @GET + @Path("/{id}") + public JSONObject getVnfInfo(@Context HttpServletRequest context, @PathParam("id") String id) + throws ServiceException { + LOGGER.info("VnfInfoRoa::getVnfInfo id:{}", id); + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_ID, id); + List vnfInfos = vnfInfoService.getList(map); + LOGGER.info("VnfInfoRoa::getVnfInfo:{}", vnfInfos.toString()); + JSONObject result = new JSONObject(); + result.put("vnfInfos", vnfInfos); + return result; + } + + @POST + public JSONObject addVnfInfo(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + if(null == object) { + LOGGER.error("function=addVnfInfo; msg=add error, because vnfInfo is null."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfInfo.add.null")); + } + + LOGGER.info("VnfInfoRoa::addVnfInfo:{}", object.toString()); + try { + return vnfInfoService.addVnfInfo(object); + } catch(ServiceException se) { + LOGGER.error("VnfInfoRoa::addVnfInfo error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + @DELETE + @Path("/{id}") + public JSONObject deleteVnfInfo(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) + throws ServiceException { + if(id == null) { + LOGGER.error("function=deleteVnfInfo; msg=delete error, because id is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfInfo.delete.id.null")); + } + LOGGER.info("VnfInfoRoa::deleteVnfInfo id:{}", id); + try { + int result = vnfInfoService.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("VnfInfoRoa::deleteVnfInfo error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setVnfInfoService(VnfInfoService vnfInfoService) { + this.vnfInfoService = vnfInfoService; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java new file mode 100644 index 0000000..96b90d7 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoa.java @@ -0,0 +1,128 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 28, 2016 + */ +@Path(UrlConstant.VNF_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class VnfRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(VirtualLinkRoa.class); + + private VnfService vnfService; + + @GET + public JSONObject getVnfs(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap<>(10); + List vnfs = vnfService.getList(map); + LOGGER.info("VnfRoa::getVnfs:{}", vnfs.toString()); + JSONObject result = new JSONObject(); + result.put("vnfs", vnfs); + return result; + } + + @GET + @Path("/{vnfId}") + public JSONObject getVnf(@Context HttpServletRequest context, @PathParam("vnfId") String id) + throws ServiceException { + LOGGER.info("VnfRoa::getVnf id:{}", id); + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_ID, id); + List vnfs = vnfService.getList(map); + LOGGER.info("VnfRoa::getVnf:{}", vnfs.toString()); + JSONObject result = new JSONObject(); + result.put("vnfs", vnfs); + return result; + } + + @POST + public JSONObject addVnf(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + if(null == object) { + LOGGER.error("function=addVnf; msg=add error, because vnf is null."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnf.add.null")); + } + + LOGGER.info("VnfRoa::addVnf:{}", object.toString()); + try { + return vnfService.addVnf(VnfEntity.toEntity(object)); + } catch(ServiceException se) { + LOGGER.error("VnfRoa::addVnf error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + @DELETE + @Path("/{id}") + public JSONObject deleteVnf(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) + throws ServiceException { + if(id == null) { + LOGGER.error("function=deleteVnf; msg=delete error, because id is null."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnf.delete.id.null")); + } + LOGGER.info("VnfRoa::deleteVnf id:{}", id); + try { + int result = vnfService.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("VnfRoa::deleteVnf error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setVnfService(VnfService vnfService) { + this.vnfService = vnfService; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfStatusRoa.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfStatusRoa.java new file mode 100644 index 0000000..a071199 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfStatusRoa.java @@ -0,0 +1,129 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.HttpConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.ParamConstant; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfStatusService; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 29, 2016 + */ +@Path(UrlConstant.VNFSTATUS_URL) +@Produces(MediaType.APPLICATION_JSON) +@Consumes(MediaType.APPLICATION_JSON) +public class VnfStatusRoa { + + private static final Logger LOGGER = LoggerFactory.getLogger(VnfStatusRoa.class); + + private VnfStatusService vnfStatusService; + + @GET + public JSONObject getVnfStatuss(@Context HttpServletRequest context) throws ServiceException { + Map map = new HashMap<>(10); + List vnfStatus = vnfStatusService.getList(map); + LOGGER.info("VnfStatusRoa::getVnfStatuss:{}", vnfStatus.toString()); + JSONObject result = new JSONObject(); + result.put("vnfStatus", vnfStatus); + return result; + } + + @GET + @Path("/{id}") + public JSONObject getVnfStatus(@Context HttpServletRequest context, @PathParam("id") String id) + throws ServiceException { + LOGGER.info("VnfStatusRoa::getVnfStatus id:{}", id); + Map map = new HashMap<>(10); + map.put(ParamConstant.PARAM_ID, id); + List vnfStatus = vnfStatusService.getList(map); + LOGGER.info("VnfStatusRoa::getVnfStatus:{}", vnfStatus.toString()); + JSONObject result = new JSONObject(); + result.put("vnfStatus", vnfStatus); + return result; + } + + @POST + public JSONObject addVnfStatus(@Context HttpServletRequest context) throws ServiceException { + JSONObject object = RequestUtil.getJsonRequestBody(context); + if(null == object) { + LOGGER.error("function=addVnfInfo; msg=add error, because vnfStatus is null."); + throw new ServiceException(ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfStatus.add.null")); + } + + LOGGER.info("VnfStatusRoa::addVnfStatus:{}", object.toString()); + try { + return vnfStatusService.addVnfStatus(object); + } catch(ServiceException se) { + LOGGER.error("VnfStatusRoa::addVnfStatus error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + @DELETE + @Path("/{id}") + public JSONObject deleteVnfStatus(@Context HttpServletRequest context, @PathParam(ParamConstant.PARAM_ID) String id) + throws ServiceException { + if(id == null) { + LOGGER.error("function=deleteVnfStatus; msg=delete error, because id is null."); + throw new ServiceException( + ResourceUtil.getMessage("org.openo.nfvo.resmanage.service.vnfStatus.delete.id.null")); + } + LOGGER.info("VnfStatusRoa::deleteVnfStatus id:{}", id); + try { + int result = vnfStatusService.delete(id); + return RoaResponseUtil.delete(result); + } catch(ServiceException se) { + LOGGER.error("VnfStatusRoa::deleteVnfStatys error:{}" + se); + return ResponseUtil.genHttpResponse(HttpConstant.ERROR_CODE, se.getMessage()); + } + } + + public void setVnfStatusService(VnfStatusService vnfStatusService) { + this.vnfStatusService = vnfStatusService; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessage.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessage.java new file mode 100644 index 0000000..3ded1e0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessage.java @@ -0,0 +1,64 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper; + +import org.apache.http.HttpStatus; + +/** + * Exception response model.
+ * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +public class ExceptionMessage { + + private String errorCode = "unknown.error"; + + private int httpCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; + + private String message; + + @Override + public String toString() { + return "Error {errorCode=" + this.errorCode + ", httpCode=" + this.httpCode + ", message=" + + this.message + "}"; + } + + public String getErrorCode() { + return this.errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getMessage() { + return this.message; + } + + public void setMessage(String message) { + this.message = message; + } + + public int getHttpCode() { + return this.httpCode; + } + + public void setHttpCode(int httpCode) { + this.httpCode = httpCode; + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapper.java new file mode 100644 index 0000000..4614d87 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapper.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +/** + * Generic exception response provider.
+ * + * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +@Provider +public class GenericExceptionMapper implements ExceptionMapper{ + + @Override + public Response toResponse(Exception exception) { + ExceptionMessage message = new ExceptionMessage(); + message.setMessage(exception.getMessage()); + return Response.status(message.getHttpCode()).type( + MediaType.APPLICATION_JSON).entity(message).build(); + } +} diff --git a/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapper.java b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapper.java new file mode 100644 index 0000000..47d2a0d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * ServiceException response provider.
+ * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +@Provider +public class ServiceExceptionMapper implements ExceptionMapper{ + + @Override + public Response toResponse(ServiceException exception) { + ExceptionMessage message = new ExceptionMessage(); + message.setErrorCode(exception.getId()); + message.setHttpCode(exception.getHttpCode()); + message.setMessage(exception.getMessage()); + return Response.status(message.getHttpCode()). + type(MediaType.APPLICATION_JSON).entity(message).build(); + } + +} diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/HostMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/HostMapper.xml index 7c4c1da..5c242d0 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/HostMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/HostMapper.xml @@ -16,9 +16,9 @@ limitations under the License. --> - + + type="org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity"> @@ -58,7 +58,7 @@ limitations under the License. where VIM_ID = #{vimId,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity"> insert into host (ID, NAME, CPU, MEMORY, DISK, VIM_ID, VIM_NAME) values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{cpu,jdbcType=VARCHAR}, @@ -66,7 +66,7 @@ limitations under the License. , #{vimName,jdbcType=VARCHAR}) + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity"> insert into host @@ -116,7 +116,7 @@ limitations under the License. + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity"> update host @@ -148,7 +148,7 @@ limitations under the License. + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity"> update host set NAME = #{name,jdbcType=VARCHAR}, CPU = #{cpu,jdbcType=VARCHAR}, @@ -159,7 +159,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity"> update host diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/LocationMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/LocationMapper.xml index 22e8885..431c151 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/LocationMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/LocationMapper.xml @@ -16,9 +16,9 @@ limitations under the License. --> - + + type="org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity"> @@ -68,7 +68,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity"> insert into location (ID, COUNTRY, LOCATION, LATITUDE, LONGITUDE, DESCRIPTION) @@ -77,7 +77,7 @@ limitations under the License. #{latitude,jdbcType=VARCHAR}, #{longitude,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}) + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity"> insert into location @@ -122,7 +122,7 @@ limitations under the License. + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity"> update location @@ -145,7 +145,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity"> update location set COUNTRY = #{country,jdbcType=VARCHAR}, diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/NetworkMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/NetworkMapper.xml index dbae050..c07c4c2 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/NetworkMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/NetworkMapper.xml @@ -16,9 +16,9 @@ limitations under the License. --> - + + type="org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity"> @@ -64,7 +64,7 @@ limitations under the License. where VIM_ID = #{vimId,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity"> insert into network (ID, NAME, TENANT_ID, VIM_ID, VIM_NAME, STATUS, PHYSICAL_NETWORK, NETWORK_TYPE, SEGMENTATION_ID @@ -77,7 +77,7 @@ limitations under the License. ) + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity"> insert into network @@ -139,7 +139,7 @@ limitations under the License. + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity"> update network @@ -170,7 +170,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity"> update network set NAME = #{name,jdbcType=VARCHAR}, TENANT_ID = #{tenantId,jdbcType=VARCHAR}, @@ -183,7 +183,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity"> update network diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/PortMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/PortMapper.xml index 5cdb358..ab2eede 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/PortMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/PortMapper.xml @@ -16,9 +16,9 @@ limitations under the License. --> - + + type="org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity"> @@ -55,7 +55,7 @@ limitations under the License. where VIM_ID = #{vimId,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity"> insert into port (ID, NAME, NWTWORK_ID, STATUS, TENANT_ID, VIM_ID, VIM_NAME) values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, @@ -64,7 +64,7 @@ limitations under the License. , #{vimName,jdbcType=VARCHAR}) + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity"> insert into port @@ -114,7 +114,7 @@ limitations under the License. + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity"> update port @@ -139,7 +139,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity"> update port set NAME = #{name,jdbcType=VARCHAR}, NWTWORK_ID = #{networkId,jdbcType=VARCHAR}, @@ -150,7 +150,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity"> update port diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/SitesMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/SitesMapper.xml index 17fad53..aac11c6 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/SitesMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/SitesMapper.xml @@ -16,9 +16,9 @@ limitations under the License. --> - + + type="org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity"> @@ -70,7 +70,7 @@ limitations under the License. #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity"> insert into site (ID, NAME, LOCATION, COUNTRY, VIM_ID, VIM_NAME, STATUS,TOTAL_CPU, TOTAL_MEMORY, TOTAL_DISK, @@ -89,7 +89,7 @@ limitations under the License. #{usedDisk,jdbcType=VARCHAR}) + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity"> insert into site @@ -175,7 +175,7 @@ limitations under the License. + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity"> update site @@ -218,7 +218,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity"> update site set NAME = #{name,jdbcType=VARCHAR}, LOCATION @@ -240,7 +240,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity"> update site diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VimMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VimMapper.xml index 90d09ed..0140306 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/VimMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VimMapper.xml @@ -16,9 +16,9 @@ limitations under the License. --> - + + type="org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity"> @@ -45,7 +45,7 @@ limitations under the License. where ID = #{id,jdbcType=VARCHAR} + parameterType="org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity"> insert into vim (ID) values (#{id,jdbcType=VARCHAR}) diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VirtualLinkMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VirtualLinkMapper.xml index c73dbed..3649d40 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/VirtualLinkMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VirtualLinkMapper.xml @@ -15,8 +15,8 @@ limitations under the License. --> - - + + @@ -61,7 +61,7 @@ delete from vl where id = #{id,jdbcType=VARCHAR} - + insert into vl (id, name, backend_id, is_public, dc_name, vim_id, vim_name, physicial_net, ns_id, @@ -77,7 +77,7 @@ #{routerExternal,jdbcType=VARCHAR}, #{resourceProviderType,jdbcType=VARCHAR}, #{resourceProviderId,jdbcType=VARCHAR} ) - + insert into vl @@ -192,7 +192,7 @@ - + update vl @@ -249,7 +249,7 @@ where id = #{id,jdbcType=VARCHAR} - + update vl set name = #{name,jdbcType=VARCHAR}, backend_id = #{backendId,jdbcType=VARCHAR}, diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VmMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VmMapper.xml index 6c5fd68..825c55f 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/VmMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VmMapper.xml @@ -15,8 +15,8 @@ limitations under the License. --> - - + + @@ -52,13 +52,13 @@ delete from vm where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} - + insert into vm (vm_id, vm_name, vm_status, vnf_instance_id) values (#{vmId,jdbcType=VARCHAR}, #{vmName,jdbcType=VARCHAR}, #{vmStatus,jdbcType=VARCHAR}, #{vnfInstanceId,jdbcType=VARCHAR}) - + insert into vm @@ -89,7 +89,7 @@ - + update vm @@ -104,7 +104,7 @@ where vm_id = #{vmId,jdbcType=VARCHAR} - + update vm set vm_name = #{vmName,jdbcType=VARCHAR}, vm_status = #{vmStatus,jdbcType=VARCHAR}, diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfInfoMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfInfoMapper.xml index e4220fb..da12a0d 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfInfoMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfInfoMapper.xml @@ -15,8 +15,8 @@ limitations under the License. --> - - + + @@ -44,13 +44,13 @@ delete from vnfinfo where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} - + insert into vnfinfo (vnf_instance_id, ns_id, vnfm_id ) values (#{vnfInstanceId,jdbcType=VARCHAR}, #{nsId,jdbcType=VARCHAR}, #{vnfmId,jdbcType=VARCHAR} ) - + insert into vnfinfo @@ -75,7 +75,7 @@ - + update vnfinfo @@ -87,7 +87,7 @@ where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} - + update vnfinfo set ns_id = #{nsId,jdbcType=VARCHAR}, vnfm_id = #{vnfmId,jdbcType=VARCHAR} diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfMapper.xml index bf36b81..7374dd1 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfMapper.xml @@ -15,8 +15,8 @@ limitations under the License. --> - - + + @@ -65,7 +65,7 @@ delete from vnf where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} - + insert into vnf (id, vnf_instance_id, vnf_instance_name, ns_id, ns_name, vnfm_id, vnfm_name, vnf_package_name, vnf_descriptor_name, @@ -83,7 +83,7 @@ #{maxRam,jdbcType=INTEGER}, #{maxShd,jdbcType=INTEGER}, #{maxNet,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}) - + insert into vnf @@ -222,7 +222,7 @@ - + update vnf @@ -291,7 +291,7 @@ where id = #{id,jdbcType=VARCHAR} - + update vnf set vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR}, vnf_instance_name = #{vnfInstanceName,jdbcType=VARCHAR}, diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfStatusMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfStatusMapper.xml index a23a39e..19c4f4a 100644 --- a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfStatusMapper.xml +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfStatusMapper.xml @@ -15,8 +15,8 @@ limitations under the License. --> - - + + @@ -55,7 +55,7 @@ delete from vnfstatus where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} - + insert into vnfstatus (vnf_instance_id, job_id, ns_id, vnfm_id, response_descriptor, status, progress, status_description, error_code, @@ -67,7 +67,7 @@ #{responseId,jdbcType=VARCHAR}, #{responseHistoryList,jdbcType=VARCHAR}, #{addVm,jdbcType=VARCHAR}, #{delVm,jdbcType=VARCHAR}) - + insert into vnfstatus @@ -152,7 +152,7 @@ - + update vnfstatus @@ -194,7 +194,7 @@ where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} - + update vnfstatus set job_id = #{jobId,jdbcType=VARCHAR}, ns_id = #{nsId,jdbcType=VARCHAR}, diff --git a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml index f08019e..7dd42a3 100644 --- a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml +++ b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml @@ -66,217 +66,217 @@ + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.LocationDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.business.impl.LocationBusinessImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.LocationImpl"> - + + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.PortDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.business.impl.PortBusinessImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.PortImpl"> - + + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.HostDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.business.impl.HostBusinessImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.HostImpl"> - + + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.NetworkDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.business.impl.NetworkBusinessImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.NetworkImpl"> - + + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.SitesDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.business.impl.SitesBusinessImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.SitesImpl"> - + + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.VimDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.business.impl.VimBusinessImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.VimImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.business.impl.LimitsBusinessImpl"> - + + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.VirtualLinkDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.group.impl.VirtualLinkServiceImpl"> - + + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.VnfDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.group.impl.VnfServiceImpl"> - + - + - + - + + class="org.onap.vfc.nfvo.resmanagement.service.dao.impl.VnfInfoDaoImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.group.impl.VnfInfoServiceImpl"> - + - + - + - + - + - + + class="org.onap.vfc.nfvo.resmanagement.service.group.impl.ResOperateServiceImpl"> @@ -288,22 +288,22 @@ + class="org.onap.vfc.nfvo.resmanagement.service.group.impl.IResourceUpdateServiceImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.group.impl.IResourceAddServiceImpl"> + class="org.onap.vfc.nfvo.resmanagement.service.group.impl.IResourceDelServiceImpl"> - + - + @@ -324,8 +324,8 @@ - - + + diff --git a/ResmanagementService/service/src/main/resources/spring/Resmanagement/svc_register.xml b/ResmanagementService/service/src/main/resources/spring/Resmanagement/svc_register.xml index 9133d04..e1d7493 100644 --- a/ResmanagementService/service/src/main/resources/spring/Resmanagement/svc_register.xml +++ b/ResmanagementService/service/src/main/resources/spring/Resmanagement/svc_register.xml @@ -37,6 +37,6 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> - - + + \ No newline at end of file diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/ResourceUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/ResourceUtilTest.java deleted file mode 100644 index 26de39a..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/ResourceUtilTest.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.ResourceUtil; - - -public class ResourceUtilTest { - - - @Test - public void testGetMessage() throws NoSuchMethodException, SecurityException { - - - String key = "huawei"; - String result = ResourceUtil.getMessage(key); - String expectedResult = "huawei"; - assertEquals(expectedResult, result); - } - @Test - public void testPrivateConstructor() throws Exception { - Constructor constructor = ResourceUtil.class.getDeclaredConstructor(); - assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); - - constructor.setAccessible(true); - constructor.newInstance(); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/VimUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/VimUtilTest.java deleted file mode 100644 index db2b30d..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/VimUtilTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.common; - -import static org.junit.Assert.*; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.common.constant.UrlConstant; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.openo.baseservice.roa.util.restclient.RestfulOptions; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -public class VimUtilTest { - - - - @Test - public void testPrivateConstructor() throws Exception { - Constructor constructor = VimUtil.class.getDeclaredConstructor(); - assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); - - constructor.setAccessible(true); - constructor.newInstance(); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/JsonUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/JsonUtilTest.java deleted file mode 100644 index 9124fc7..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/JsonUtilTest.java +++ /dev/null @@ -1,436 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -public class JsonUtilTest { - - @Test - public void testGetJsonFieldStr() { - JSONObject jsonObj = new JSONObject(); - String fieldName = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - String result = JsonUtil.getJsonFieldStr(jsonObj, fieldName); - String expectedResult = "1"; - assertEquals(expectedResult, result); - - } - - @Test - public void testGetJsonFieldInt() { - JSONObject jsonObj = new JSONObject(); - String fieldName = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - int result = JsonUtil.getJsonFieldInt(jsonObj, fieldName); - int expectedResult = 1; - assertEquals(expectedResult, result); - - } - - @Test - public void testGetJsonFieldArr() { - JSONObject jsonObj = new JSONObject(); - String fieldName = "a"; - jsonObj.put("a", new JSONArray()); - jsonObj.put("b", "2"); - JSONArray result = JsonUtil.getJsonFieldArr(jsonObj, fieldName); - JSONArray expectedResult = new JSONArray(); - assertEquals(expectedResult, result); - - } - - @Test - public void testGetJsonFieldJson() { - JSONObject jsonObj = new JSONObject(); - String fieldName = "a"; - jsonObj.put("a", new JSONObject()); - jsonObj.put("b", "2"); - JSONObject result = JsonUtil.getJsonFieldJson(jsonObj, fieldName); - JSONObject expectedResult = new JSONObject(); - assertEquals(expectedResult, result); - - } - - @Test - public void testGetJsonFieldLong() { - JSONObject jsonObj = new JSONObject(); - String fieldName = "a"; - jsonObj.put("a", 1); - jsonObj.put("b", 2); - Long result = JsonUtil.getJsonFieldLong(jsonObj, fieldName); - Long expectedResult = new Long(1); - assertEquals(expectedResult, result); - - } - - @Test - public void testGetJsonFieldObjectException() { - JSONObject jsonObj = new JSONObject(); - String fieldName = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - JSONObject result = JsonUtil.getJsonFieldJson(jsonObj, fieldName); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - - } - - @Test - public void testIsNullJson1() { - JSONObject jsonObj = new JSONObject(); - assertTrue(JsonUtil.isNullJson(jsonObj)); - } - - @Test - public void testIsNullJson2() { - assertTrue(JsonUtil.isNullJson(null)); - } - - @Test - public void testIsNullJson3() { - JSONObject jsonObj = new JSONObject(); - jsonObj.put("a", "1"); - assertFalse(JsonUtil.isNullJson(jsonObj)); - } - - @Test - public void testGetStrValueByjsonNULL() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - String result = JsonUtil.getStrValueByjson(jsonObj, key); - String expectedResult = null; - assertEquals(expectedResult, result); - - } - - @Test - public void testGetStrValueByjson() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - new MockUp() { - - @SuppressWarnings("static-access") - @Mock - public JSONObject optJSONObject(String key) { - return new JSONObject().fromObject("{\"a\":\"1\"}"); - } - - @Mock - public JSONObject getJSONObject(String key) { - return new JSONObject(); - } - }; - String result = JsonUtil.getStrValueByjson(jsonObj, key); - String expectedResult = "1"; - assertEquals(expectedResult, result); - - } - - @Test - public void testGetStrValueByjson1() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - new MockUp() { - - @Mock - public JSONObject optJSONObject(String key) { - return null; - } - - @SuppressWarnings("static-access") - @Mock - public JSONArray optJSONArray(String key) { - return new JSONArray().fromObject("[\"a\",\"1\"]"); - } - - @Mock - public JSONArray getJSONArray(String key) { - return new JSONArray(); - } - }; - String result = JsonUtil.getStrValueByjson(jsonObj, key); - String expectedResult = "1"; - assertEquals(expectedResult, result); - - } - - @Test - public void testGetStrValueByjson2() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - String result = JsonUtil.getStrValueByjson(jsonObj, key); - String expectedResult = "1"; - assertEquals(expectedResult, result); - - } - - @Test - public void testGetStrValueByJArray() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - new MockUp() { - - @Mock - public JSONObject optJSONObject(String key) { - return null; - } - - @SuppressWarnings("static-access") - @Mock - public JSONArray optJSONArray(String key) { - return new JSONArray().fromObject("[\"a\",\"1\"]"); - } - - @SuppressWarnings("static-access") - @Mock - public JSONArray getJSONArray(String key) { - return new JSONArray().fromObject("[\"a\",\"1\"]"); - } - - - }; - - String result = JsonUtil.getStrValueByjson(jsonObj, key); - - } - - @Test - public void testGetStrValueByJArray1() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - new MockUp() { - - int count = 1; - - @SuppressWarnings("static-access") - @Mock - public JSONObject optJSONObject(String key) { - if (count == 1) { - count += 1; - return null; - } else - return new JSONObject().fromObject("{\"a\":\"1\"}"); - } - - @SuppressWarnings("static-access") - @Mock - public JSONArray optJSONArray(String key) { - return new JSONArray().fromObject("[\"a\",\"1\"]"); - } - - @SuppressWarnings("static-access") - @Mock - public JSONArray getJSONArray(String key) { - return new JSONArray().fromObject("[\"a\",\"1\"]"); - } - }; - String result = JsonUtil.getStrValueByjson(jsonObj, key); - String expectedResult = "1"; - assertEquals(expectedResult, result); - - } - - @Test - public void testGetJsonValueByjson() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - String result = JsonUtil.getJsonValueByjson(jsonObj, key).toString(); - String expectedResult = "{\"a\":\"1\"}"; - assertEquals(expectedResult, result); - } - - @Test - public void testGetJsonValueByjsonResultIsNull() { - JSONObject jsonObj = new JSONObject(); - String key = "c"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - JSONObject result = JsonUtil.getJsonValueByjson(jsonObj, key); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetStrValueByJsonParentKeyIsNull() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - String parentKey = ""; - String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); - String expectedResult = "1"; - assertEquals(expectedResult, result); - } - - @Test - public void testGetStrValueByJsonParentJsonIsNull() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - String parentKey = "b"; - new MockUp() { - - @Mock - public JSONObject getJsonValueByjson(JSONObject json, String key) { - return new JSONObject(); - } - }; - String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetStrValueByJson() { - JSONObject jsonObj = new JSONObject(); - String key = "a"; - jsonObj.put("a", "1"); - jsonObj.put("b", "2"); - String parentKey = "b"; - String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseDataRetcodeError1() { - new MockUp() { - - @Mock - public Integer getJsonFieldInt(JSONObject jsonObj, String fieldName) { - return null; - } - }; - JSONObject result = JsonUtil.getResponseData(null); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseDataRetcodeError2() { - new MockUp() { - - @Mock - public Integer getJsonFieldInt(JSONObject jsonObj, String fieldName) { - return -1; - } - }; - JSONObject result = JsonUtil.getResponseData(null); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseDataResultIsEmpty() { - JSONObject obj = new JSONObject(); - obj.put("data", "1"); - obj.put("retCode", "1"); - JSONObject result = JsonUtil.getResponseData(obj); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseData() { - JSONObject obj = new JSONObject(); - obj.put("data", new JSONObject()); - obj.put("retCode", "1"); - new MockUp() { - - @SuppressWarnings("static-access") - @Mock - public JSONObject optJSONObject(String key) { - return new JSONObject().fromObject("{\"a\":\"1\"}"); - } - }; - JSONObject result = JsonUtil.getResponseData(obj); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseData1() { - JSONObject obj = new JSONObject(); - obj.put("data", JSONArray.fromObject("[{\"a\":\"1\"},\"1\"]")); - obj.put("retCode", "1"); - new MockUp() { - - @Mock - public JSONObject optJSONObject(String key) { - return null; - } - - @SuppressWarnings("static-access") - @Mock - public JSONArray optJSONArray(String key) { - return new JSONArray().fromObject("[\"a\",\"1\"]"); - } - }; - JSONObject result = JsonUtil.getResponseData(obj); - String expectedResult = "{\"a\":\"1\"}"; - assertEquals(expectedResult, result.toString()); - } - - @Test - public void testGetResponseData2() { - JSONObject obj = new JSONObject(); - JSONObject json = new JSONObject(); - json.put("retCode", "1"); - obj.put("data", json); - obj.put("retCode", "1"); - JSONObject result = JsonUtil.getResponseData(obj); - String expectedResult = null; - assertEquals(expectedResult, result); - } - @Test - public void testPrivateConstructor() throws Exception { - Constructor constructor = JsonUtil.class.getDeclaredConstructor(); - assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); - - constructor.setAccessible(true); - constructor.newInstance(); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/RestfulUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/RestfulUtilTest.java deleted file mode 100644 index 4483316..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/RestfulUtilTest.java +++ /dev/null @@ -1,245 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.constant.Constant; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.RestfulOptions; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONArray; -import net.sf.json.JSONException; -import net.sf.json.JSONObject; - -public class RestfulUtilTest { - - @Test - public void testGetResponseObjWithTwoParams() { - JSONObject result = RestfulUtil.getResponseObj(null, null); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseObjWithThreeParams() { - new MockUp() { - - @Mock - public String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt, - String type) { - return "{\"ResponseContent\":\"123\"}"; - } - }; - JSONObject result = RestfulUtil.getResponseObj(null, null, null); - @SuppressWarnings("static-access") - JSONObject expectedResult = new JSONObject().fromObject("{\"ResponseContent\":\"123\"}"); - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseObjExpections() { - new MockUp() { - - @Mock - public String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt, - String type) { - throw new JSONException(); - } - }; - JSONObject result = RestfulUtil.getResponseObj(null, null, null); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseContent() { - String result = RestfulUtil.getResponseContent(null, null, null); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseMap() { - Map result = RestfulUtil.getResponseMap(null, null, null, null); - Map expectedResult = new HashMap(10); - expectedResult.put(Constant.RESPONSE_CONTENT, null); - expectedResult.put(Constant.STATUS_CODE, -1); - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseContentMap() { - Map result = RestfulUtil.getResponseContentMap(null, null); - Map expectedResult = new HashMap(10); - expectedResult.put(Constant.RESPONSE_CONTENT, null); - expectedResult.put(Constant.STATUS_CODE, -1); - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseContentWithFourParams() { - new MockUp() { - - @Mock - public int getStatus() { - return 200; - } - }; - String result = RestfulUtil.getResponseContent(null, null, null); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetRestfulResponse() { - RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, null); - RestfulResponse expectedResult = new RestfulResponse(); - assertEquals(expectedResult.getStatus(), result.getStatus()); - } - - @Test - public void testRestfulResponse() { - RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "get"); - RestfulResponse expectedResult = new RestfulResponse(); - assertEquals(expectedResult.getStatus(), result.getStatus()); - } - - @Test - public void testRestfulResponse1() { - RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "add"); - RestfulResponse expectedResult = new RestfulResponse(); - assertEquals(expectedResult.getStatus(), result.getStatus()); - } - - @Test - public void testRestfulResponse2() { - RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "put"); - RestfulResponse expectedResult = new RestfulResponse(); - assertEquals(expectedResult.getStatus(), result.getStatus()); - } - - @Test - public void testRestfulResponse3() { - RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "delete"); - RestfulResponse expectedResult = new RestfulResponse(); - assertEquals(expectedResult.getStatus(), result.getStatus()); - } - - @Test - public void testGetRestResObjectsIsNull() { - RestfulResponse result = RestfulUtil.getRestRes(null, null); - RestfulResponse expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetRestResReflectiveOperationException() { - RestfulResponse result = RestfulUtil.getRestRes("123", "get"); - RestfulResponse expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetRestRes() { - RestfulResponse result = RestfulUtil.getRestRes("async123", new RestfulResponse()); - RestfulResponse expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseResResultIsNull() throws ServiceException { - try { - RestfulUtil.getResponseRes(null, null); - } catch (ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testGetResponse() throws ServiceException { - new MockUp() { - - @Mock - public String getResponseContent(String url, RestfulParametes restParametes, String type) { - return "{\"ResponseContent\":\"123\",\"data\":[\"datas\"]}"; - } - }; - JSONArray result = RestfulUtil.getResponseRes(null, null); - JSONArray expectedResult = JSONArray.fromObject("[\"datas\"]"); - assertEquals(expectedResult, result); - } - - @Test - public void testGetResponseExceptions() throws ServiceException { - new MockUp() { - - @Mock - public String getResponseContent(String url, RestfulParametes restParametes, String type) { - return "{\"ResponseContent\":\"123\",}"; - } - }; - try { - RestfulUtil.getResponseRes(null, null); - } catch (ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testGgetResponseRes() throws ServiceException { - new MockUp() { - - @Mock - public String getResponseContent(String url, RestfulParametes restParametes, String type) { - return "{\"ResponseContent\":\"123\",}"; - } - }; - try { - RestfulUtil.getResponseRes(null, null, null); - } catch (ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testGgetResponseResException() throws ServiceException { - new MockUp() { - - @Mock - public String getResponseContent(String url, RestfulParametes restParametes, String type) { - return null; - } - }; - try { - RestfulUtil.getResponseRes(null, null, null); - } catch (ServiceException e) { - assertTrue(true); - } - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/StringUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/StringUtilTest.java deleted file mode 100644 index cc5f42c..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/StringUtilTest.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.StringUtil; - -public class StringUtilTest { - - @Test - public void testisValidString() { - assertTrue(StringUtil.isValidString("abc")); - } - - @Test - public void testisValidString1() { - assertFalse(StringUtil.isValidString(null)); - } - - @Test - public void testisValidString2() { - assertFalse(StringUtil.isValidString("")); - } - - @Test - public void testIsAnyLargeThanZero() { - assertFalse(StringUtil.isAnyLargeThanZero("")); - } - - @Test - public void testIsAnyLargeThanZero1() { - assertTrue(StringUtil.isAnyLargeThanZero("123")); - } - - @Test - public void testIsIntegerExceptions() { - assertFalse(StringUtil.isInteger("asd")); - } - - @Test - public void testIsInteger() { - assertTrue(StringUtil.isInteger("123")); - } - - @Test - public void testIsInteger1() { - assertFalse(StringUtil.isInteger("-1")); - } - - @Test - public void testIsNumericExceptions() { - assertFalse(StringUtil.isNumeric("abc")); - } - - @Test - public void testIsNumeric() { - assertTrue(StringUtil.isNumeric("1.456")); - } - - @Test - public void testIsNumeric1() { - assertFalse(StringUtil.isNumeric("-1.456")); - } - - @Test - public void testCompareZeroByFloat() { - assertTrue(StringUtil.compareZeroByFloat("3.0", "1.0", "2.0")); - } - - @Test - public void testCompareZeroByFloat1() { - assertFalse(StringUtil.compareZeroByFloat("3.0", "1.2", "2.5")); - } - - @Test - public void testCompareZeroByInteger() { - assertTrue(StringUtil.compareZeroByInteger("3", "1", "2")); - } - - @Test - public void testCompareZeroByInteger1() { - assertFalse(StringUtil.compareZeroByInteger("3", "1", "3")); - } - - @Test - public void testNumFormatDataIsNull() { - String result = StringUtil.numFormat(null); - assertEquals(null, result); - } - - @Test - public void testNumFormatDataIsEmpty() { - String result = StringUtil.numFormat(""); - assertEquals(null, result); - } - - @Test - public void testNumFormatInteger() { - String result = StringUtil.numFormat("12"); - String expectedResult = "12"; - assertEquals(expectedResult, result); - } - - @Test - public void testNumFormatFloat() { - String result = StringUtil.numFormat("12.5"); - String expectedResult = "12.5"; - assertEquals(expectedResult, result); - } - - @Test - public void testCheckXss() { - assertTrue(StringUtil.checkXss("123")); - } - @Test - public void testPrivateConstructor() throws Exception { - Constructor constructor = StringUtil.class.getDeclaredConstructor(); - assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); - - constructor.setAccessible(true); - constructor.newInstance(); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/request/RequestUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/request/RequestUtilTest.java deleted file mode 100644 index dafc9e4..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/request/RequestUtilTest.java +++ /dev/null @@ -1,253 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util.request; - -import static org.junit.Assert.*; - -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Constructor; -import java.util.Arrays; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.ServletInputStream; -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.io.IOUtils; -import org.apache.cxf.jaxrs.impl.HttpServletRequestFilter; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; - -import javassist.Modifier; -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; -import net.sf.json.JSONException; -import net.sf.json.JSONObject; - -public class RequestUtilTest { - - @Test - public void testGetStringRequestBody() { - HttpServletRequestFilter context = new MockUp() { - - @Mocked - ServletInputStream input; - - @Mock - public ServletInputStream getInputStream() throws IOException { - return input; - } - }.getMockInstance(); - new MockUp() { - - String data = "{\"NETWORK\":{\"id\": \"123\"}}"; - - @Mock - public String toString(InputStream input) throws IOException { - return data; - } - }; - String result = RequestUtil.getStringRequestBody(context); - String expectedResult = "{\"NETWORK\":{\"id\": \"123\"}}"; - assertEquals(expectedResult, result); - } - - @Test - public void testGetStringRequestBodyException() { - HttpServletRequestFilter context = new MockUp() { - - @Mock - public ServletInputStream getInputStream() throws IOException { - throw new IOException(); - } - }.getMockInstance(); - String result = RequestUtil.getStringRequestBody(context); - String expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetJsonRequestBody() { - HttpServletRequestFilter context = new MockUp() { - - @Mocked - ServletInputStream input; - - @Mock - public ServletInputStream getInputStream() throws IOException { - return input; - } - }.getMockInstance(); - new MockUp() { - - String data = "{\"NETWORK\":{\"id\": \"123\"}}"; - - @Mock - public String toString(InputStream input) throws IOException { - return data; - } - }; - JSONObject result = RequestUtil.getJsonRequestBody(context); - String data1 = "{\"NETWORK\":{\"id\": \"123\"}}"; - JSONObject expectedResult = JSONObject.fromObject(data1); - assertEquals(expectedResult, result); - } - - @Test - public void testGetJsonRequestBody1() { - new MockUp() { - - String data1 = "{\"NETWORK\":{\"id\": \"123\"}}"; - - @Mock - public String getStringRequestBody(HttpServletRequest context) { - return data1; - } - }; - JSONObject result = RequestUtil.getJsonRequestBody(null); - String data1 = "{\"NETWORK\":{\"id\": \"123\"}}"; - JSONObject expectedResult = JSONObject.fromObject(data1); - assertEquals(expectedResult, result); - } - - @Test - public void testGetJsonRequestBodyException() { - HttpServletRequestFilter context = new MockUp() { - - @Mocked - ServletInputStream input; - - @Mock - public ServletInputStream getInputStream() throws JSONException { - throw new JSONException(); - } - }.getMockInstance(); - JSONObject result = RequestUtil.getJsonRequestBody(context); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @SuppressWarnings("rawtypes") - @Test - public void testGetAllJsonRequestBodyRequestBodyIsNull() { - HttpServletRequestFilter context = new MockUp() { - - @Mocked - ServletInputStream input; - - @Mock - public ServletInputStream getInputStream() throws IOException { - return input; - } - - @Mock - public Enumeration getHeaderNames() { - return new Enumeration() { - - List a = Arrays.asList(new String[] { "1", "2" }); - - @Override - public boolean hasMoreElements() { - return false; - } - - @Override - public Object nextElement() { - return null; - } - - }; - } - - }.getMockInstance(); - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - JSONObject result = RequestUtil.getAllJsonRequestBody(context); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("header", new HashMap()); - assertEquals(expectedResult, result); - } - - @SuppressWarnings("rawtypes") - @Test - public void testGetContextHeader() { - HttpServletRequestFilter context = new MockUp() { - - @Mock - public String getHeader(String name) { - return "1"; - } - - @Mock - public Enumeration getHeaderNames() { - return new Enumeration() { - - List a = Arrays.asList(new String[] { "1", "2" }); - - int count = 1; - - @Override - public boolean hasMoreElements() { - if (count == 1) { - count += 1; - return true; - } else - return false; - } - - @Override - public Object nextElement() { - return "1"; - } - - }; - } - - }.getMockInstance(); - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - JSONObject result = RequestUtil.getAllJsonRequestBody(context); - JSONObject expectedResult = new JSONObject(); - Map map = new HashMap(); - map.put("1", "1"); - expectedResult.put("header", map); - assertEquals(expectedResult, result); - } - @Test - public void testPrivateConstructor() throws Exception { - Constructor constructor = RequestUtil.class.getDeclaredConstructor(); - assertTrue("Constructor is private", Modifier.isPrivate(constructor.getModifiers())); - - constructor.setAccessible(true); - constructor.newInstance(); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/response/ResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/response/ResponseUtilTest.java deleted file mode 100644 index 6cef0c3..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/response/ResponseUtilTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util.response; - -import static org.junit.Assert.*; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; - -import net.sf.json.JSONObject; - -public class ResponseUtilTest { - - @Test - public void TestGenHttpResponseWithTwoParam() { - int retCode1 = -1; - String msg1 = "123"; - JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", "123"); - assertEquals(result.toString(), expectedResult.toString()); - ; - } - - @Test - public void TestGenHttpResponseWithThreeParam() { - int retCode1 = -1; - String msg1 = "123"; - JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1, null); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", "123"); - assertEquals(result.toString(), expectedResult.toString()); - ; - } - - @Test - public void TestGenHttpResponseWithFourParam1() { - int httpStatusCode = -1; - int retCode1 = -1; - String msg1 = "123"; - JSONObject result = ResponseUtil.genHttpResponse(null, httpStatusCode, retCode1, msg1); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", "123"); - assertEquals(result.toString(), expectedResult.toString()); - ; - } - - @Test - public void TestGenHttpResponseWithFourParam2() { - Map codeMap = new HashMap(5); - codeMap.put("httpStatusCode", -1); - codeMap.put("retCode", 1); - Map map = new HashMap(5); - map.put("a", -1); - map.put("b", 1); - String msg1 = "123"; - JSONObject result = ResponseUtil.genHttpResponse(null, codeMap, msg1, map); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", "123"); - expectedResult.put("a", "-1"); - assertEquals(result.toString(), expectedResult.toString()); - ; - } - @Test - public void testPrivateConstructor() throws Exception { - Constructor constructor = ResponseUtil.class.getDeclaredConstructor(); - assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); - - constructor.setAccessible(true); - constructor.newInstance(); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/response/RoaResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/response/RoaResponseUtilTest.java deleted file mode 100644 index 9b69944..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/common/util/response/RoaResponseUtilTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.common.util.response; - -import static org.junit.Assert.*; - -import java.lang.reflect.Constructor; -import java.lang.reflect.Modifier; -import java.util.Map; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.response.ResponseUtil; -import org.onap.vfc.nfvo.res.common.util.response.RoaResponseUtil; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -public class RoaResponseUtilTest { - - @Test - public void testGet() { - new MockUp() { - - @Mock - public JSONObject genHttpResponse(int retCode, String msg, Map map) { - return null; - } - }; - JSONObject result = RoaResponseUtil.get(null); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testAdd() { - int a = 0; - new MockUp() { - - @Mock - public JSONObject genHttpResponse(int retCode, String msg) { - return null; - } - }; - JSONObject result = RoaResponseUtil.add(a); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testAdd1() { - int a = 2; - new MockUp() { - - @Mock - public JSONObject genHttpResponse(int retCode, String msg) { - return null; - } - }; - JSONObject result = RoaResponseUtil.add(a); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testUpdate() { - int a = 0; - new MockUp() { - - @Mock - public JSONObject genHttpResponse(int retCode, String msg) { - return null; - } - }; - JSONObject result = RoaResponseUtil.update(a); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testUpdate1() { - int a = 2; - new MockUp() { - - @Mock - public JSONObject genHttpResponse(int retCode, String msg) { - return null; - } - }; - JSONObject result = RoaResponseUtil.update(a); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testDelete() { - int a = -1; - new MockUp() { - - @Mock - public JSONObject genHttpResponse(int retCode, String msg) { - return null; - } - }; - JSONObject result = RoaResponseUtil.delete(a); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testDelete1() { - int a = 0; - new MockUp() { - - @Mock - public JSONObject genHttpResponse(int retCode, String msg) { - return null; - } - }; - JSONObject result = RoaResponseUtil.delete(a); - JSONObject expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testPrivateConstructor() throws Exception { - Constructor constructor = RoaResponseUtil.class.getDeclaredConstructor(); - assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); - - constructor.setAccessible(true); - constructor.newInstance(); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java deleted file mode 100644 index 0855f9b..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.adapter.impl; - -import static org.junit.Assert.assertNotNull; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.RestfulUtil; -import org.onap.vfc.nfvo.res.service.adapter.impl.ResmgrAdapter2MSBManager; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 24, 2016 - */ -public class ResmgrAdapter2MSBManagerTest { - - @Test - public void testRegisterResmgr() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(201); - rsp.setResponseJson("{\"msg\":\"success!\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); - assertNotNull(resultObj); - } - - @Test - public void testRegisterResmgrByInvalid() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(415); - rsp.setResponseJson("{\"msg\":\"invalid parameters\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); - assertNotNull(resultObj); - } - - @Test - public void testRegisterResmgrByInternalError() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(500); - rsp.setResponseJson("{\"msg\":\"internal system error\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); - assertNotNull(resultObj); - } - - @Test - public void testRegisterResmgrByFail() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(404); - rsp.setResponseJson("{\"msg\":\"not found\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); - assertNotNull(resultObj); - } - - @Test - public void testRegisterResmgrByNull() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - return null; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); - assertNotNull(resultObj); - } - - @Test - public void testUnRegisterResmgr() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(204); - rsp.setResponseJson("{\"msg\":\"success!\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); - assertNotNull(resultObj); - } - - @Test - public void testUnRegisterResmgrByNotFound() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(404); - rsp.setResponseJson("{\"msg\":\"not found!\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); - assertNotNull(resultObj); - } - - @Test - public void testUnRegisterResmgrByInvalid() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(415); - rsp.setResponseJson("{\"msg\":\"invalid parameters!\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); - assertNotNull(resultObj); - } - - @Test - public void testUnRegisterResmgrByInternalError() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(500); - rsp.setResponseJson("{\"msg\":\"internal system error!\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); - assertNotNull(resultObj); - } - - @Test - public void testUnRegisterResmgrByFail() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(203); - rsp.setResponseJson("{\"msg\":\"fail!\"}"); - return rsp; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); - assertNotNull(resultObj); - } - - @Test - public void testUnRegisterResmgrByNull() { - new MockUp() { - - @Mock - public RestfulResponse getRemoteResponse(Map paramsMap, String params) { - return null; - } - }; - Map paramsMap = getHashMap(); - ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); - JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); - assertNotNull(resultObj); - } - - private Map getHashMap() { - Map paramsMap = new HashMap<>(); - paramsMap.put("url", "/openoapi/microservices/v1/services"); - paramsMap.put("methodType", "post"); - return paramsMap; - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapterMgrServiceTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapterMgrServiceTest.java deleted file mode 100644 index d045149..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/adapter/impl/ResmgrAdapterMgrServiceTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.adapter.impl; - -import java.io.IOException; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.adapter.impl.ResmgrAdapterMgrService; - -import mockit.Mock; -import mockit.MockUp; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Sep 24, 2016 - */ -public class ResmgrAdapterMgrServiceTest { - - @Test - public void testRegister() { - new MockUp() { - - @Mock - public String readVimAdapterInfoFromJson() throws IOException { - return "{\"serviceName\": \"resmgr\",\"version\": \"v1\",\"url\": \"/openoapi/resmgr/v1\",\"protocol\": \"REST\",\"visualRange\": \"1\",\"nodes\": [{\"ip\": \"127.0.0.1\",\"port\": \"8080\",\"ttl\": 0}]}"; - } - }; - - ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService(); - resmgrService.register(); - } - - @Test - public void testRegisterByIOException() { - new MockUp() { - - @Mock - public String readVimAdapterInfoFromJson() throws IOException { - throw new IOException(); - } - }; - ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService(); - resmgrService.register(); - } - - @Test - public void testRegisterByNoFile() { - ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService(); - resmgrService.register(); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/HostImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/HostImplTest.java deleted file mode 100644 index 827a56d..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/HostImplTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.HostImpl; -import org.onap.vfc.nfvo.res.service.business.impl.HostBusinessImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.HostDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -public class HostImplTest { - - @Test - public void testdeleteHostByVimId() throws ServiceException { - new MockUp() { - - @Mock - public int deleteHostByVimId(String vimId) { - return 1; - } - - }; - HostImpl hostImpl = new HostImpl(); - HostBusinessImpl hostBusiness = new HostBusinessImpl(); - hostBusiness.setHostDao(new HostDaoImpl()); - hostImpl.setHostBusiness(hostBusiness); - - assertTrue(hostImpl.deleteResByVimId("vimId") == 1); - } - @Test - public void testupdateStatusByVimId() throws ServiceException { - HostImpl hostImpl = new HostImpl(); - hostImpl.setHostBusiness(new HostBusinessImpl()); - JSONObject json = new JSONObject(); - json.put("id", "123"); - json.put("vimId", "vim123"); - new MockUp() { - - @Mock - public int updateHostByVimId(HostEntity hostEntity) throws ServiceException { - return 1; - } - }; - int result = hostImpl.updateStatusByVimId(json); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testDelete() throws ServiceException { - HostImpl hostImpl = new HostImpl(); - hostImpl.setHostBusiness(new HostBusinessImpl()); - new MockUp() { - @Mock - public int deleteHost(String id) throws ServiceException { - return 1; - } - }; - - int result = hostImpl.delete("id"); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - - } - - @Test - public void testAdd1() throws ServiceException { - HostImpl hostImpl = new HostImpl(); - hostImpl.setHostBusiness(new HostBusinessImpl()); - JSONObject json = new JSONObject(); - json.put("id", "1"); - new MockUp() { - @Mock - public int addHost(HostEntity hostEntity) throws ServiceException { - return 1; - } - - }; - int result = hostImpl.add(json); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testupdate() throws ServiceException { - HostImpl hostImpl = new HostImpl(); - hostImpl.setHostBusiness(new HostBusinessImpl()); - HostEntity hostEntity = new HostEntity(); - hostEntity.setId("123"); - new MockUp() { - @Mock - public int updateHostSelective(HostEntity hostEntity) throws ServiceException { - return 1; - } - - }; - int result = hostImpl.update(hostEntity); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testUpdateResource() throws ServiceException { - HostImpl hostImpl = new HostImpl(); - hostImpl.setHostBusiness(new HostBusinessImpl()); - JSONObject json = new JSONObject(); - json.put("id", "123"); - json.put("vimId", "vim123"); - new MockUp() { - - @Mock - public int updateHostSelective(HostEntity hostEntity) throws ServiceException { - return 1; - } - }; - int result = hostImpl.update(json); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testGetList() throws ServiceException { - Map condition = new HashMap<>(); - HostImpl hostImpl = new HostImpl(); - hostImpl.setHostBusiness(new HostBusinessImpl()); - new MockUp() { - - @Mock - public List getHosts(Map condition) { - return null; - } - }; - List result = hostImpl.getList(condition); - List exceptedResult = null; - assertEquals(exceptedResult, result); - } - -} \ No newline at end of file diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/LocationImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/LocationImplTest.java deleted file mode 100644 index 4bf8763..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/LocationImplTest.java +++ /dev/null @@ -1,501 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.LocationImpl; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.SitesImpl; -import org.onap.vfc.nfvo.res.service.business.impl.LocationBusinessImpl; -import org.onap.vfc.nfvo.res.service.business.impl.SitesBusinessImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.LocationDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -public class LocationImplTest { - - private LocationImpl locationImpl; - - @Before - public void setUp() throws ServiceException { - locationImpl = new LocationImpl(); - LocationBusinessImpl locationBusinessImpl = new LocationBusinessImpl(); - locationBusinessImpl.setLocationDao(new LocationDaoImpl()); - SitesImpl sitesImpl = new SitesImpl(); - sitesImpl.setSitesBusiness(new SitesBusinessImpl()); - locationImpl.setSites(sitesImpl); - locationImpl.setLocationBusiness(locationBusinessImpl); - - } - - @Test - public void testLocationImpl() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) throws ServiceException { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - - list.add(localEntity); - return null; - } - }; - new MockUp() { - - @Mock - public int addLocation(LocationEntity locationEntity) { - return 1; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "id"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "3"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - assertTrue(locationImpl.add(jsonObject) == 1); - } - - @Test - public void testLocationImplBranch() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) throws ServiceException { - List list = new ArrayList<>(); - - // list.add(localEntity); - return list; - } - }; - new MockUp() { - - @Mock - public int addLocation(LocationEntity locationEntity) { - return 1; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", ""); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "90"); - jsonObject.put("longitude", "180"); - jsonObject.put("description", "description"); - assertTrue(locationImpl.add(jsonObject) == 1); - } - - @Test - public void testLocationImplBranch1() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) throws ServiceException { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - - list.add(localEntity); - return null; - } - }; - new MockUp() { - - @Mock - public int addLocation(LocationEntity locationEntity) { - return 1; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", null); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "3"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - assertTrue(locationImpl.add(jsonObject) == 1); - } - - @Test(expected = ServiceException.class) - public void testLocationImplException() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) throws ServiceException { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - - list.add(localEntity); - return list; - } - }; - - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "2"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "3"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - locationImpl.add(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testLocationImplException1() throws ServiceException { - - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", null); - jsonObject.put("country", ""); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "81"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - locationImpl.add(jsonObject); - - } - - @Test(expected = ServiceException.class) - public void testLocationImplException2() throws ServiceException { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", null); - jsonObject.put("country", "country"); - jsonObject.put("location", ""); - jsonObject.put("latitude", "81"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - locationImpl.add(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testLocationImplException3() throws ServiceException { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", null); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", ""); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - locationImpl.add(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testLocationImplException4() throws ServiceException { - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", null); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "latitude"); - jsonObject.put("longitude", ""); - jsonObject.put("description", "description"); - locationImpl.add(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testLocationImplException5() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) throws ServiceException { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - - list.add(localEntity); - return null; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "id"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "95"); - jsonObject.put("longitude", "185"); - jsonObject.put("description", "description"); - locationImpl.add(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testLocationImplException6() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) throws ServiceException { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - - list.add(localEntity); - return null; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "id"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "80"); - jsonObject.put("longitude", "185"); - jsonObject.put("description", "description"); - locationImpl.add(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testLocationImplException7() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) throws ServiceException { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - - list.add(localEntity); - return null; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "id"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "95"); - jsonObject.put("longitude", "175"); - jsonObject.put("description", "description"); - locationImpl.add(jsonObject); - } - - @Test - public void testUpdate() throws ServiceException { - new MockUp() { - - @Mock - public LocationEntity getLocation(String id) { - LocationEntity localEntity = new LocationEntity(); - localEntity.setCountry("country"); - localEntity.setLocation("location"); - - return localEntity; - } - }; - new MockUp() { - - @Mock - public int updateLocationSelective(LocationEntity locationEntity) { - return 1; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "id"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "14"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - locationImpl.update(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testUpdateException() throws ServiceException { - - new MockUp() { - - @Mock - public int updateLocationSelective(LocationEntity locationEntity) { - return 1; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "id"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "91"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - locationImpl.update(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testUpdateException1() throws ServiceException { - new MockUp() { - - @Mock - public LocationEntity getLocation(String id) { - LocationEntity localEntity = new LocationEntity(); - localEntity.setCountry("countryNew"); - localEntity.setLocation("location"); - - return localEntity; - } - }; - - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "id"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "10"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - locationImpl.update(jsonObject); - } - - @Test(expected = ServiceException.class) - public void testUpdateException2() throws ServiceException { - new MockUp() { - - @Mock - public LocationEntity getLocation(String id) { - LocationEntity localEntity = new LocationEntity(); - localEntity.setCountry("country"); - localEntity.setLocation("locationNew"); - - return localEntity; - } - }; - JSONObject jsonObject = new JSONObject(); - jsonObject.put("id", "id"); - jsonObject.put("country", "country"); - jsonObject.put("location", "location"); - jsonObject.put("latitude", "10"); - jsonObject.put("longitude", "12"); - jsonObject.put("description", "description"); - locationImpl.update(jsonObject); - } - - @Test - public void testDelete() throws ServiceException { - - new MockUp() { - - @Mock - public int deleteLocation(String id) { - return 1; - } - }; - assertTrue(locationImpl.delete("location") == 1); - } - - @Test(expected = ServiceException.class) - public void testDeleteException() throws ServiceException { - - locationImpl.delete(""); - } - - @Test - public void testComputeSite() { - JSONObject total = new JSONObject(); - total.put("vcpus", "12"); - total.put("memory", "23"); - total.put("disk", "23"); - JSONObject used = new JSONObject(); - used.put("vcpus", "12"); - used.put("memory", "23"); - used.put("disk", "23"); - locationImpl.getLocationBusiness(); - - assertTrue(locationImpl.computingSite(total, used) != null); - } - - @Test - public void testGetLocation() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - localEntity.setCountry("country"); - localEntity.setLocation("locationNew"); - list.add(localEntity); - return list; - } - }; - assertTrue(locationImpl.getLocation(new HashMap<>()) != null); - } - - @Test - public void testGetLocationBranch() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - localEntity.setCountry("country"); - localEntity.setLocation("locationNew"); - return list; - } - }; - locationImpl.getLocation(new HashMap<>()); - } - - @Test - public void testGetLocationInfo() throws ServiceException { - new MockUp() { - - @Mock - public List getSites(Map condition) { - List siteList = new ArrayList<>(); - SitesEntity site = new SitesEntity(); - - siteList.add(site); - return siteList; - } - }; - - new MockUp() { - - @Mock - public JSONObject getJSONObject(String key) { - JSONObject total = new JSONObject(); - total.put("vcpus", "12"); - total.put("memory", "23"); - total.put("disk", "23"); - return total; - } - }; - List locationInfo = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - locationInfo.add(localEntity); - locationImpl.getLocationInfo(locationInfo); - } - - @Test - public void testGet() throws ServiceException { - new MockUp() { - - @Mock - public List getLocations(Map condition) throws ServiceException { - List list = new ArrayList<>(); - LocationEntity localEntity = new LocationEntity(); - - list.add(localEntity); - return null; - } - }; - locationImpl.get(new HashMap<>()); - assertTrue(locationImpl.get("id") != null); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/NetworkImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/NetworkImplTest.java deleted file mode 100644 index 478e6ef..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/NetworkImplTest.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.NetworkImpl; -import org.onap.vfc.nfvo.res.service.business.impl.NetworkBusinessImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.NetworkDaoImpl; -import org.onap.vfc.nfvo.res.service.dao.inf.NetworkDao; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -public class NetworkImplTest { - - - @Test - public void testAddBranch() throws ServiceException { - new MockUp() { - - @Mock - public NetworkEntity getNetwork(String id) { - return null; - } - - @Mock - public int addNetwork(NetworkEntity networkEntity) { - return 1; - } - }; - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - JSONObject json = new JSONObject(); - json.put("id", "id"); - json.put("name", "name"); - json.put("status", "status"); - json.put("tenant_id", "tenant_id"); - json.put("vimId", "vimId"); - json.put("vimName", "vimName"); - json.put("provider:physical_network", "provider:physical_network"); - json.put("provider:network_type", "provider:network_type"); - json.put("provider:segmentation_id", "provider:segmentation_id"); - assertTrue(networkImpl.add(json) == 1); - } - - @Test - public void testAddBranch1() throws ServiceException { - new MockUp() { - - @Mock - public NetworkEntity getNetwork(String id) { - return null; - } - - @Mock - public int addNetwork(NetworkEntity networkEntity) { - return 1; - } - }; - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - JSONObject json = new JSONObject(); - json.put("id", ""); - json.put("name", "name"); - json.put("status", "status"); - json.put("tenant_id", "tenant_id"); - json.put("vimId", "vimId"); - json.put("vimName", "vimName"); - json.put("provider:physical_network", "provider:physical_network"); - json.put("provider:network_type", "provider:network_type"); - json.put("provider:segmentation_id", "provider:segmentation_id"); - assertTrue(networkImpl.add(json) == 1); - } - - @Test(expected = ServiceException.class) - public void testAddBranch2() throws ServiceException { - new MockUp() { - @Mock - public NetworkEntity getNetwork(String id) { - return null; - } - - @Mock - public int addNetwork(NetworkEntity networkEntity) { - return 1; - } - }; - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - NetworkEntity entity = null; - networkImpl.add(entity); - - } - - - @Test - public void testDelete() throws ServiceException { - new MockUp() { - - @Mock - public int deleteNetwork(String id) { - return 1; - } - }; - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - assertTrue(networkImpl.delete("id") == 1); - } - - @Test(expected = ServiceException.class) - public void testDelete1() throws ServiceException { - - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - networkImpl.delete(""); - } - - @Test(expected = ServiceException.class) - public void testDeleteVimByIdException() throws ServiceException { - - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - networkImpl.deleteResByVimId(""); - } - - @Test - public void testDeleteVimById() throws ServiceException { - new MockUp() { - - @Mock - public int deleteNetworkByVimId(String vimId) { - return 1; - } - }; - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - assertTrue(networkImpl.deleteResByVimId("vimId") == 1); - } - - - @Test - public void testUpdate() throws ServiceException { - new MockUp() { - - @Mock - public int updateNetworkSelective(NetworkEntity networkEntity) { - return 1; - } - }; - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - - JSONObject json = new JSONObject(); - json.put("id", ""); - json.put("name", "name"); - json.put("status", "status"); - json.put("tenant_id", "tenant_id"); - json.put("vimId", "vimId"); - json.put("vimName", "vimName"); - json.put("provider:physical_network", "provider:physical_network"); - json.put("provider:network_type", "provider:network_type"); - json.put("provider:segmentation_id", "provider:segmentation_id"); - assertTrue(networkImpl.update(json)==1); - } - - - - @Test - public void testUpdateVimById() throws ServiceException { - new MockUp() { - - @Mock - public int updateNetworkByVimId(NetworkEntity NetworkEntity) { - return 1; - } - }; - NetworkImpl networkImpl = new NetworkImpl(); - NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); - NetworkDao networkDao = new NetworkDaoImpl(); - networkBusiness.setNetworkDao(networkDao); - networkImpl.setNetworkBusiness(networkBusiness); - JSONObject json = new JSONObject(); - json.put("id", ""); - json.put("name", "name"); - json.put("status", "status"); - json.put("tenant_id", "tenant_id"); - json.put("vimId", "vimId"); - json.put("vimName", "vimName"); - json.put("provider:physical_network", "provider:physical_network"); - json.put("provider:network_type", "provider:network_type"); - json.put("provider:segmentation_id", "provider:segmentation_id"); - assertTrue(networkImpl.updateStatusByVimId(json)==1); - - } - - @Test - public void testgetList() throws ServiceException { - Map condition = new HashMap<>(); - NetworkImpl networkImpl = new NetworkImpl(); - networkImpl.setNetworkBusiness(new NetworkBusinessImpl()); - new MockUp() { - - @Mock - public List getNetworks(Map condition) { - return null; - } - }; - List result = networkImpl.getList(condition); - List exceptedResult = null; - assertEquals(exceptedResult, result); - } - @Test - public void testadd() throws ServiceException { - NetworkImpl networkImpl = new NetworkImpl(); - networkImpl.setNetworkBusiness(new NetworkBusinessImpl()); - NetworkEntity networkEntity =new NetworkEntity(); - networkEntity.setId("1"); - new MockUp() { - - @Mock - public int addNetwork(NetworkEntity networkEntity ) { - return 1; - } - }; - int result = networkImpl.add(networkEntity); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - } diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/PortImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/PortImplTest.java deleted file mode 100644 index a7ea6c4..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/PortImplTest.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.JsonUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.PortImpl; -import org.onap.vfc.nfvo.res.service.business.impl.PortBusinessImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.PortDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -public class PortImplTest { - - @Test - public void testAddBranch() throws ServiceException { - new MockUp() { - - @Mock - public PortEntity getPort(String id) { - return null; - } - - @Mock - public int addPort(PortEntity portEntity) { - return 1; - } - }; - PortImpl portImpl = new PortImpl(); - PortBusinessImpl portBusiness = new PortBusinessImpl(); - portBusiness.setPortDao(new PortDaoImpl()); - portImpl.setPortBusiness(portBusiness); - JSONObject json = new JSONObject(); - json.put("id", ""); - json.put("name", "name"); - json.put("status", "status"); - json.put("tenant_id", "tenant_id"); - json.put("vimId", "vimId"); - json.put("vimName", "vimName"); - json.put("network_id", "network_id"); - assertTrue(portImpl.add(json) == 1); - } - - @Test(expected = ServiceException.class) - public void testAddBranch1() throws ServiceException { - - PortImpl portImpl = new PortImpl(); - PortBusinessImpl portBusiness = new PortBusinessImpl(); - portBusiness.setPortDao(new PortDaoImpl()); - portImpl.setPortBusiness(portBusiness); - PortEntity portEntity = null; - portImpl.add(portEntity); - } - - @Test(expected = ServiceException.class) - public void testUpdateException() throws ServiceException { - - PortImpl portImpl = new PortImpl(); - PortBusinessImpl portBusiness = new PortBusinessImpl(); - portBusiness.setPortDao(new PortDaoImpl()); - portImpl.setPortBusiness(portBusiness); - PortEntity portEntity = null; - portImpl.update(portEntity); - } - - @Test - public void testUpdate() throws ServiceException { - new MockUp() { - - @Mock - public int updatePortSelective(PortEntity portEntity) { - return 1; - } - - }; - PortImpl portImpl = new PortImpl(); - PortBusinessImpl portBusiness = new PortBusinessImpl(); - portBusiness.setPortDao(new PortDaoImpl()); - portImpl.setPortBusiness(portBusiness); - assertTrue(portImpl.update(new JSONObject()) == 1); - } - - @Test - public void testdelete() throws ServiceException { - new MockUp() { - - @Mock - public int deletePort(String id) { - return 1; - } - - }; - PortImpl portImpl = new PortImpl(); - PortBusinessImpl portBusiness = new PortBusinessImpl(); - portBusiness.setPortDao(new PortDaoImpl()); - portImpl.setPortBusiness(portBusiness); - - } - - @Test - public void testDeleteResByVimId() throws ServiceException { - new MockUp() { - - @Mock - public int deletePortByVimId(String vimId) { - return 1; - } - - }; - PortImpl portImpl = new PortImpl(); - PortBusinessImpl portBusiness = new PortBusinessImpl(); - portBusiness.setPortDao(new PortDaoImpl()); - portImpl.setPortBusiness(portBusiness); - assertTrue(portImpl.deleteResByVimId("vimId") == 1); - } - - @Test(expected = ServiceException.class) - public void testDeleteResByVimIdException() throws ServiceException { - PortImpl portImpl = new PortImpl(); - PortBusinessImpl portBusiness = new PortBusinessImpl(); - portBusiness.setPortDao(new PortDaoImpl()); - portImpl.setPortBusiness(portBusiness); - portImpl.deleteResByVimId(""); - } - - @Test(expected = ServiceException.class) - public void testDelete() throws ServiceException { - PortImpl portImpl = new PortImpl(); - PortBusinessImpl portBusiness = new PortBusinessImpl(); - portBusiness.setPortDao(new PortDaoImpl()); - portImpl.setPortBusiness(portBusiness); - portImpl.delete(""); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/SitesImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/SitesImplTest.java deleted file mode 100644 index ea7aa28..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/SitesImplTest.java +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.SitesImpl; -import org.onap.vfc.nfvo.res.service.business.impl.SitesBusinessImpl; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -public class SitesImplTest { - - - - @Test - public void testUpdate1() throws ServiceException { - SitesImpl sitesImpl = new SitesImpl(); - sitesImpl.setSitesBusiness(new SitesBusinessImpl()); - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setId("123"); - new MockUp() { - - @Mock - public int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException { - return 1; - } - }; - int result = sitesImpl.update(sitesEntity); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testUpdateResource() throws ServiceException { - SitesImpl sitesImpl = new SitesImpl(); - sitesImpl.setSitesBusiness(new SitesBusinessImpl()); - JSONObject json = new JSONObject(); - json.put("id", "123"); - json.put("vimId", "vim123"); - new MockUp() { - - @Mock - public int updateSiteResource(SitesEntity sitesEntity) throws ServiceException { - return 1; - } - }; - int result = sitesImpl.updateResource(json); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testUpdateStatusByVimId() throws ServiceException { - SitesImpl sitesImpl = new SitesImpl(); - sitesImpl.setSitesBusiness(new SitesBusinessImpl()); - JSONObject json = new JSONObject(); - json.put("id", "123"); - json.put("vimId", "vim123"); - new MockUp() { - - @Mock - public int updateSiteByVimId(SitesEntity sitesEntity) throws ServiceException { - return 1; - } - }; - int result = sitesImpl.updateStatusByVimId(json); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testGetList() throws ServiceException { - Map condition = new HashMap<>(); - SitesImpl sitesImpl = new SitesImpl(); - sitesImpl.setSitesBusiness(new SitesBusinessImpl()); - new MockUp() { - - @Mock - public List getSites(Map condition) { - return null; - } - }; - List result = sitesImpl.getList(condition); - List exceptedResult = null; - assertEquals(exceptedResult, result); - } - - @Test - public void testGetNull() throws ServiceException { - Map condition = new HashMap<>(); - SitesImpl sitesImpl = new SitesImpl(); - sitesImpl.setSitesBusiness(new SitesBusinessImpl()); - new MockUp() { - - @Mock - public List getSites(Map condition) { - return null; - } - }; - SitesEntity result = sitesImpl.get(condition); - SitesEntity exceptedResult = null; - assertEquals(exceptedResult, result); - } - - @Test - public void testGet() throws ServiceException { - Map condition = new HashMap<>(); - SitesImpl sitesImpl = new SitesImpl(); - sitesImpl.setSitesBusiness(new SitesBusinessImpl()); - new MockUp() { - - @Mock - public List getSites(Map condition) { - List list = new ArrayList(); - return list; - } - }; - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setId("123"); - sitesImpl.deleteResByVimId("vimId"); - SitesEntity result = sitesImpl.get(condition); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/VimImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/VimImplTest.java deleted file mode 100644 index 9205d30..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/base/openstack/impl/VimImplTest.java +++ /dev/null @@ -1,135 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.base.openstack.impl; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.VimImpl; -import org.onap.vfc.nfvo.res.service.business.impl.VimBusinessImpl; -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -public class VimImplTest { - - @Test - public void testAdd() throws ServiceException { - VimImpl vimImpl = new VimImpl(); - vimImpl.setVimBusiness(new VimBusinessImpl()); - new MockUp() { - - @Mock - public int addVim(String id) throws ServiceException { - return 1; - } - }; - int result = vimImpl.add("id"); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testAdd1() throws ServiceException { - VimImpl vimImpl = new VimImpl(); - vimImpl.setVimBusiness(new VimBusinessImpl()); - JSONObject json = new JSONObject(); - json.put("id", "123"); - new MockUp() { - - @Mock - public int addVim(String id) throws ServiceException { - return 1; - } - }; - int result = vimImpl.add(json); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testUpdate() throws ServiceException { - VimImpl vimImpl = new VimImpl(); - vimImpl.setVimBusiness(new VimBusinessImpl()); - JSONObject json = new JSONObject(); - json.put("id", "123"); - json.put("vimId", "vim123"); - int result = vimImpl.update(json); - int exceptedResult = 0; - assertEquals(exceptedResult, result); - } - - @Test - public void testDelete() throws ServiceException { - VimImpl vimImpl = new VimImpl(); - vimImpl.setVimBusiness(new VimBusinessImpl()); - new MockUp() { - - @Mock - public int deleteVim(String id) throws ServiceException { - return 1; - } - }; - int result = vimImpl.delete("id"); - int exceptedResult = 1; - assertEquals(exceptedResult, result); - } - - @Test - public void testGetVim() throws ServiceException { - VimImpl vimImpl = new VimImpl(); - vimImpl.setVimBusiness(new VimBusinessImpl()); - new MockUp() { - - @Mock - public VimEntity getVim(String id) { - return null; - } - }; - VimEntity result = vimImpl.getVim("id"); - VimEntity exceptedResult = null; - assertEquals(exceptedResult, result); - } - - @Test - public void testGetList() throws ServiceException { - VimImpl vimImpl = new VimImpl(); - vimImpl.setVimBusiness(new VimBusinessImpl()); - new MockUp() { - - @Mock - public List getVims() { - return null; - } - }; - List result = vimImpl.getList(); - List exceptedResult = null; - assertEquals(exceptedResult, result); - } - - @Test - public void testSetVimBusiness() throws ServiceException { - VimImpl vimImpl = new VimImpl(); - vimImpl.setVimBusiness(new VimBusinessImpl()); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/HostBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/HostBusinessImplTest.java deleted file mode 100644 index 4197de9..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/HostBusinessImplTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import static org.junit.Assert.assertTrue; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.business.impl.HostBusinessImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.HostDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; - -public class HostBusinessImplTest { - - @Test - public void testGetHost() { - HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); - assertTrue(hostBussinessImp.getHost("") == null); - } - - @Test - public void testGetHostBranch() { - new MockUp() { - - @Mock - public HostEntity getHost(String id) { - return new HostEntity(); - } - - }; - HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); - hostBussinessImp.setHostDao(new HostDaoImpl()); - assertTrue(hostBussinessImp.getHost("id") != null); - } - - @Test(expected = ServiceException.class) - public void testDelete() throws ServiceException { - HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); - hostBussinessImp.deleteHost(""); - } - - @Test(expected = ServiceException.class) - public void testUpdateHost() throws ServiceException { - HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); - hostBussinessImp.updateHost(null); - } - - @Test(expected = ServiceException.class) - public void testDeleteHostByVimId() throws ServiceException { - HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); - hostBussinessImp.deleteHostByVimId(""); - } - - @Test(expected = ServiceException.class) - public void testUpdateHostByVimId() throws ServiceException { - HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); - hostBussinessImp.updateHostByVimId(null); - } - - @Test(expected = ServiceException.class) - public void testAddHost() throws ServiceException { - HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); - hostBussinessImp.addHost(null); - } - - @Test(expected = ServiceException.class) - public void testAddHostSelective() throws ServiceException { - HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); - hostBussinessImp.addHostSelective(null); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/LimitsBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/LimitsBusinessImplTest.java deleted file mode 100644 index 6c2f849..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/LimitsBusinessImplTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.business.impl.LimitsBusinessImpl; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.openo.baseservice.roa.util.restclient.HttpRest; -import org.openo.baseservice.roa.util.restclient.RestfulOptions; -import org.openo.baseservice.roa.util.restclient.RestfulParametes; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -public class LimitsBusinessImplTest { - - private LimitsBusinessImpl limitsBusinessImpl; - - @Before - public void setUp() throws ServiceException { - limitsBusinessImpl = new LimitsBusinessImpl(); - } - - @Test - public void testGetCpuLimits() throws ServiceException { - new MockUp() { - - @Mock - public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option) - throws ServiceException { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(200); - return rsp; - } - }; - JSONObject paramJson = new JSONObject(); - paramJson.put("vimId", "vimId"); - paramJson.put("tenantId", "tenantId"); - } - - @Test - public void testgetLimits() throws ServiceException { - new MockUp() { - - @Mock - public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option) - throws ServiceException { - RestfulResponse rsp = new RestfulResponse(); - rsp.setStatus(200); - return rsp; - } - - }; - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/LocationBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/LocationBusinessImplTest.java deleted file mode 100644 index 35126cd..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/LocationBusinessImplTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.business.impl.LocationBusinessImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.LocationDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; - -public class LocationBusinessImplTest { - - private LocationBusinessImpl locationBusinessImpl; - - @Before - public void setUp() throws ServiceException { - locationBusinessImpl = new LocationBusinessImpl(); - locationBusinessImpl.setLocationDao(new LocationDaoImpl()); - } - - @Test - public void testGet() throws ServiceException { - new MockUp() { - - @Mock - public LocationEntity getLocation(String id) { - LocationEntity localEntity = new LocationEntity(); - localEntity.setCountry("country"); - localEntity.setLocation("location"); - - return localEntity; - } - }; - assertTrue(locationBusinessImpl.getLocation("id") != null); - } - - @Test - public void testGetBranch() throws ServiceException { - - assertTrue(locationBusinessImpl.getLocation("") == null); - } - - @Test(expected = ServiceException.class) - public void testAddLocationSelectiveExceptio() throws ServiceException { - locationBusinessImpl.addLocationSelective(null); - } - - @Test - public void testAddLocationSelective() throws ServiceException { - new MockUp() { - - @Mock - public int addLocationSelective(LocationEntity locationEntity) { - return 1; - } - }; - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setCountry("country"); - locationEntity.setDescription("description"); - locationEntity.setId("id"); - locationEntity.setLatitude("1"); - locationEntity.setLongitude("12"); - locationEntity.setLocation("location"); - locationBusinessImpl.addLocationSelective(locationEntity); - } - - @Test - public void testAddLocationSelectiveBranch() throws ServiceException { - new MockUp() { - - @Mock - public int addLocationSelective(LocationEntity locationEntity) { - return 1; - } - }; - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setCountry("country"); - locationEntity.setDescription("description"); - locationEntity.setId(""); - locationEntity.setLatitude("1"); - locationEntity.setLongitude("12"); - locationEntity.setLocation("location"); - locationBusinessImpl.addLocationSelective(locationEntity); - } - - @Test - public void testAddLocationSelectiveBranch1() throws ServiceException { - new MockUp() { - - @Mock - public int addLocationSelective(LocationEntity locationEntity) { - return 1; - } - }; - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setCountry("country"); - locationEntity.setDescription("description"); - locationEntity.setId(null); - locationEntity.setLatitude("1"); - locationEntity.setLongitude("12"); - locationEntity.setLocation("location"); - locationBusinessImpl.addLocationSelective(locationEntity); - } - - @Test(expected = ServiceException.class) - public void testAddLocationSelectiveException1() throws ServiceException { - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setCountry(""); - locationEntity.setDescription("description"); - locationEntity.setId("id"); - locationEntity.setLatitude("1"); - locationEntity.setLongitude("12"); - locationEntity.setLocation("location"); - locationBusinessImpl.addLocationSelective(locationEntity); - } - - @Test(expected = ServiceException.class) - public void testAddLocationSelectiveException2() throws ServiceException { - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setCountry("country"); - locationEntity.setDescription("description"); - locationEntity.setId("id"); - locationEntity.setLatitude("1"); - locationEntity.setLongitude("12"); - locationEntity.setLocation(""); - locationBusinessImpl.addLocationSelective(locationEntity); - } - - @Test(expected = ServiceException.class) - public void testAddLocationSelectiveException3() throws ServiceException { - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setCountry("country"); - locationEntity.setDescription("description"); - locationEntity.setId("id"); - locationEntity.setLatitude(""); - locationEntity.setLongitude("12"); - locationEntity.setLocation("location"); - locationBusinessImpl.addLocationSelective(locationEntity); - } - - @Test(expected = ServiceException.class) - public void testAddLocationSelectiveException4() throws ServiceException { - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setCountry("country"); - locationEntity.setDescription("description"); - locationEntity.setId("id"); - locationEntity.setLatitude("1"); - locationEntity.setLongitude(""); - locationEntity.setLocation("location"); - locationBusinessImpl.addLocationSelective(locationEntity); - } - - @Test(expected = ServiceException.class) - public void testUpdateLocationSelective() throws ServiceException { - locationBusinessImpl.updateLocationSelective(null); - } - - @Test(expected = ServiceException.class) - public void testAddLocation() throws ServiceException { - locationBusinessImpl.addLocation(null); - } - - @Test - public void testUpdateLocation() throws ServiceException { - new MockUp() { - - @Mock - public int updateLocation(LocationEntity locationEntity) { - return 1; - } - }; - locationBusinessImpl.getLocationDao(); - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setLatitude("1"); - locationEntity.setLongitude("2"); - locationBusinessImpl.updateLocation(locationEntity); - } - - @Test(expected = ServiceException.class) - public void testUpdateLocationException() throws ServiceException { - new MockUp() { - - @Mock - public int updateLocation(LocationEntity locationEntity) { - return 1; - } - }; - locationBusinessImpl.getLocationDao(); - LocationEntity locationEntity = new LocationEntity(); - locationEntity.setLatitude("100"); - locationEntity.setLongitude("2"); - locationBusinessImpl.updateLocation(locationEntity); - } - - @Test(expected = ServiceException.class) - public void testUpdateLocationException1() throws ServiceException { - locationBusinessImpl.getLocationDao(); - locationBusinessImpl.updateLocation(null); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/SitesBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/SitesBusinessImplTest.java deleted file mode 100644 index ae86558..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/SitesBusinessImplTest.java +++ /dev/null @@ -1,409 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.business.impl.SitesBusinessImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.SitesDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 2016年8月16日 - */ -public class SitesBusinessImplTest { - - private SitesBusinessImpl sitesBusinessImpl; - - @Before - public void setUp() { - sitesBusinessImpl = new SitesBusinessImpl(); - sitesBusinessImpl.setSitesDao(new SitesDaoImpl()); - } - - @Test - public void testGetSitesIdIsNull() throws ServiceException { - try { - sitesBusinessImpl.getSite(null); - } catch(ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testGetSite() throws ServiceException { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setId("123"); - new MockUp() { - - @Mock - public SitesEntity getSite(String id) { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setId("123"); - return sitesEntity; - } - }; - SitesEntity result = sitesBusinessImpl.getSite("id"); - SitesEntity expectedResult = sitesEntity; - assertEquals(expectedResult.toString(), result.toString()); - } - - @Test - public void testGetSites() throws ServiceException { - Map condition = new HashMap(); - SitesBusinessImpl sitesBusinessImpl = new SitesBusinessImpl(); - sitesBusinessImpl.setSitesDao(new SitesDaoImpl()); - new MockUp() { - - @Mock - public List getSites(Map condition) { - return null; - } - }; - List result = sitesBusinessImpl.getSites(condition); - assertNull(result); - } - - @Test - public void testDeleteSiteEmpty() throws ServiceException { - SitesBusinessImpl sitesBusinessImpl = new SitesBusinessImpl(); - sitesBusinessImpl.setSitesDao(new SitesDaoImpl()); - try { - sitesBusinessImpl.deleteSite(""); - } catch(ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testDeleteSite() throws ServiceException { - new MockUp() { - - @Mock - public SitesEntity getSite(String id) { - return null; - } - - @Mock - public int deleteSite(String id) { - return 1; - } - }; - int result = sitesBusinessImpl.deleteSite("007"); - int expectedResult = 1; - assertEquals(expectedResult, result); - } - - @Test - public void testAddSiteSitesEntityIsNull() throws ServiceException { - try { - sitesBusinessImpl.addSite(null); - } catch(ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testCheckSiteExceptions() throws ServiceException { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setCountry("country"); - sitesEntity.setId("id"); - sitesEntity.setLocation("location"); - sitesEntity.setName("name"); - sitesEntity.setStatus("siteStatus"); - sitesEntity.setTotalCPU("12"); - sitesEntity.setTotalDisk("12"); - sitesEntity.setTotalMemory("134"); - sitesEntity.setUsedCPU("12"); - sitesEntity.setUsedDisk("23"); - sitesEntity.setUsedMemory("10"); - sitesEntity.setVimId("siteVimId"); - sitesEntity.setVimName("siteVimName"); - new MockUp() { - - int count1 = 0; - - @Mock - public SitesEntity getSite(String id) { - return null; - } - - @Mock - public List getSites(Map condition) { - if(count1 == 0) { - count1 += 1; - return null; - } - return new ArrayList(); - - } - }; - new MockUp() { - - @Mock - public boolean checkResource(SitesEntity siteEntity) { - return false; - } - }; - try { - sitesBusinessImpl.addSite(sitesEntity); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testCheckSiteExceptions1() throws ServiceException { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setCountry("country"); - sitesEntity.setId("id"); - sitesEntity.setLocation("location"); - sitesEntity.setName("name"); - sitesEntity.setStatus("siteStatus"); - sitesEntity.setTotalCPU("12"); - sitesEntity.setTotalDisk("12"); - sitesEntity.setTotalMemory("134"); - sitesEntity.setUsedCPU("12"); - sitesEntity.setUsedDisk("23"); - sitesEntity.setUsedMemory("10"); - sitesEntity.setVimId("siteVimId"); - sitesEntity.setVimName("siteVimName"); - new MockUp() { - - int count1 = 0; - - @Mock - public SitesEntity getSite(String id) { - return null; - } - - @Mock - public List getSites(Map condition) { - - return null; - - } - }; - new MockUp() { - - @Mock - public boolean checkResource(SitesEntity siteEntity) { - return false; - } - }; - try { - sitesBusinessImpl.addSite(sitesEntity); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testCheckSiteExceptions2() throws ServiceException { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setCountry(""); - sitesEntity.setId("id"); - sitesEntity.setLocation(""); - sitesEntity.setName(""); - sitesEntity.setStatus("siteStatus"); - sitesEntity.setTotalCPU("12"); - sitesEntity.setTotalDisk("12"); - sitesEntity.setTotalMemory("134"); - sitesEntity.setUsedCPU("12"); - sitesEntity.setUsedDisk("23"); - sitesEntity.setUsedMemory("10"); - sitesEntity.setVimId("siteVimId"); - sitesEntity.setVimName("siteVimName"); - new MockUp() { - - int count1 = 0; - - @Mock - public SitesEntity getSite(String id) { - return null; - } - - @Mock - public List getSites(Map condition) { - - return null; - - } - }; - new MockUp() { - - @Mock - public boolean checkResource(SitesEntity siteEntity) { - return false; - } - }; - try { - sitesBusinessImpl.addSite(sitesEntity); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testCheckSiteNameExceptions() throws ServiceException { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setId("123"); - sitesEntity.setCountry("china"); - sitesEntity.setName("openstack"); - sitesEntity.setLocation("xian"); - new MockUp() { - - @Mock - public SitesEntity getSite(String id) { - return null; - } - - @Mock - public List getSites(Map condition) { - List list = new ArrayList(); - list.add(new SitesEntity()); - return list; - - } - }; - try { - sitesBusinessImpl.addSite(sitesEntity); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testCheckIdExceptions() throws ServiceException { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setId("123"); - sitesEntity.setCountry("china"); - sitesEntity.setName("openstack"); - sitesEntity.setLocation("xian"); - new MockUp() { - - @Mock - public SitesEntity getSite(String id) { - return new SitesEntity(); - } - }; - try { - sitesBusinessImpl.addSite(sitesEntity); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testAddSiteSelectiveSitesEntityIsNull() throws ServiceException { - try { - sitesBusinessImpl.addSiteSelective(null); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testUpdateSiteSelectiveSitesEntityIsNull() throws ServiceException { - try { - sitesBusinessImpl.updateSiteSelective(null); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testUpdateSiteSitesEntityIsNull() throws ServiceException { - try { - sitesBusinessImpl.updateSite(null); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testUpdateSiteByVimIdSitesEntityIsNull() throws ServiceException { - try { - sitesBusinessImpl.updateSiteByVimId(null); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testUpdateSiteByVimId() throws ServiceException { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setCountry("china"); - sitesEntity.setName("openstack"); - sitesEntity.setLocation("xian"); - new MockUp() { - - @Mock - public int updateSiteByVimId(SitesEntity sitesEntity) { - return 1; - } - }; - int result = sitesBusinessImpl.updateSiteByVimId(sitesEntity); - int expectedResult = 1; - assertEquals(expectedResult, result); - } - - @Test - public void testUpdateSiteResourceSitesEntityIsNull() throws ServiceException { - try { - sitesBusinessImpl.updateSiteResource(null); - } catch(ServiceException se) { - assertTrue(true); - } - } - - @Test - public void testUpdateSiteResource() throws ServiceException { - SitesEntity sitesEntity = new SitesEntity(); - sitesEntity.setCountry("china"); - sitesEntity.setName("openstack"); - sitesEntity.setLocation("xian"); - new MockUp() { - - @Mock - public int updateSiteSelective(SitesEntity sitesEntity) { - return 1; - } - }; - int result = sitesBusinessImpl.updateSiteResource(sitesEntity); - int expectedResult = 1; - assertEquals(expectedResult, result); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/VimBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/VimBusinessImplTest.java deleted file mode 100644 index 6de3741..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/business/impl/VimBusinessImplTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.business.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.util.List; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.business.impl.VimBusinessImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.VimDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 2016年8月18日 - */ -public class VimBusinessImplTest { - - @Test - public void testGetVimIdIsNull() { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - VimEntity result = vimBusinessImpl.getVim(null); - VimEntity expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testGetVim() { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - VimEntity vimEntity = new VimEntity(); - vimEntity.setId("123"); - new MockUp() { - - @Mock - public VimEntity getVim(String id) { - VimEntity vimEntity = new VimEntity(); - vimEntity.setId("123"); - return vimEntity; - } - }; - VimEntity result = vimBusinessImpl.getVim("id"); - VimEntity expectedResult = vimEntity; - assertEquals(expectedResult.toString(), result.toString()); - } - - @Test - public void testGetVims() throws ServiceException { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - new MockUp() { - - @Mock - public List getVims() { - return null; - } - }; - List result = vimBusinessImpl.getVims(); - List expectedResult = null; - assertEquals(expectedResult, result); - } - - @Test - public void testDeleteVimEmpty() throws ServiceException { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - try { - vimBusinessImpl.deleteVim(""); - } catch (ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testDeleteVim() throws ServiceException { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - new MockUp() { - - @Mock - public int deleteVim(String id) { - return 1; - } - }; - int result = vimBusinessImpl.deleteVim("xian"); - int expectedResult = 1; - assertEquals(expectedResult, result); - } - - @Test - public void testAddVimExceptions() throws ServiceException { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - try { - vimBusinessImpl.addVim(null); - } catch (ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testAddVimExceptions1() throws ServiceException { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - new MockUp() { - - @Mock - public VimEntity getVim(String id) { - return new VimEntity(); - } - }; - try { - vimBusinessImpl.addVim("id"); - } catch (ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testAddVimExceptions2() throws ServiceException { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - VimEntity vimEntity = new VimEntity(); - vimEntity.setId("123"); - try { - vimBusinessImpl.addVim(""); - } catch (ServiceException e) { - assertTrue(true); - } - } - - @Test - public void testAddVim() throws ServiceException { - VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); - vimBusinessImpl.setVimDao(new VimDaoImpl()); - new MockUp() { - - @Mock - public VimEntity getVim(String id) { - return null; - } - - @Mock - public int addVim(VimEntity vimEntity) { - return 1; - } - }; - int result = vimBusinessImpl.addVim("123"); - int expectedResult = 1; - assertEquals(expectedResult, result); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/HostDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/HostDaoImplTest.java deleted file mode 100644 index 3aac705..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/HostDaoImplTest.java +++ /dev/null @@ -1,157 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.service.dao.impl; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.impl.HostDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.mapper.HostMapper; -import org.onap.vfc.nfvo.res.service.mapper.NetworkMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Expectations; -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; - -public class HostDaoImplTest { - @Mocked - HostMapper mapper; - @Test - public void testdeleteHost() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - HostDaoImpl impl = new HostDaoImpl(); - assertEquals(0, impl.deleteHost("123")); - } - - @Test - public void testdeleteHostByVimId() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - HostDaoImpl impl = new HostDaoImpl(); - assertEquals(0, impl.deleteHostByVimId("123")); - } - - @Test - public void testaddHost() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - HostDaoImpl impl = new HostDaoImpl(); - HostEntity hostEntity =new HostEntity(); - hostEntity.setId("1"); - assertEquals(0, impl.addHost(hostEntity)); - - } - - @Test - public void testaddHostSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - HostDaoImpl impl = new HostDaoImpl(); - HostEntity hostEntity =new HostEntity(); - hostEntity.setId("1"); - assertEquals(0, impl.addHostSelective(hostEntity)); - - } - - @Test - public void testupdateHostSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - HostDaoImpl impl = new HostDaoImpl(); - HostEntity hostEntity =new HostEntity(); - hostEntity.setId("1"); - assertEquals(0, impl.updateHostSelective(hostEntity)); - - } - - @Test - public void testupdateHost() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - HostDaoImpl impl = new HostDaoImpl(); - HostEntity hostEntity =new HostEntity(); - hostEntity.setId("1"); - assertEquals(0, impl.updateHost(hostEntity)); - - } - - @Test - public void testupdateHostByVimId() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - HostDaoImpl impl = new HostDaoImpl(); - HostEntity hostEntity =new HostEntity(); - hostEntity.setId("1"); - assertEquals(0, impl.updateHostByVimId(hostEntity)); - - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/LocationDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/LocationDaoImplTest.java deleted file mode 100644 index c131bd1..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/LocationDaoImplTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.impl.LocationDaoImpl; -import org.onap.vfc.nfvo.res.service.dao.impl.NetworkDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.mapper.LocationMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; - -public class LocationDaoImplTest { - LocationMapper mapper; - @Test - public void testaddHost() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - LocationDaoImpl impl = new LocationDaoImpl(); - LocationEntity locationEntity =new LocationEntity(); - locationEntity.setId("locationEntity"); - - - } - - @Test - public void testaddLocationSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - LocationDaoImpl impl = new LocationDaoImpl(); - LocationEntity locationEntity =new LocationEntity(); - locationEntity.setId("1"); - - - } - - @Test - public void testupdateNetwork() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - NetworkDaoImpl impl = new NetworkDaoImpl(); - NetworkEntity networkEntity =new NetworkEntity(); - networkEntity.setId("1"); - - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/NetworkDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/NetworkDaoImplTest.java deleted file mode 100644 index a366b8f..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/NetworkDaoImplTest.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.service.dao.impl; - -import static org.junit.Assert.*; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.impl.NetworkDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.mapper.NetworkMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Expectations; -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; - -public class NetworkDaoImplTest { - @Mocked - NetworkMapper mapper; - @Test - public void testdeleteNetwork() throws ServiceException { - - new Expectations() {{ - mapper.deleteNetwork("123"); - }}; - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - NetworkDaoImpl impl = new NetworkDaoImpl(); - assertEquals(0, impl.deleteNetwork("123")); - - } - @Test - public void testdeleteNetworkByVimId() throws ServiceException { - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - NetworkDaoImpl impl = new NetworkDaoImpl(); - assertEquals(0, impl.deleteNetworkByVimId("123")); - - } - @Test - public void testaddNetwork() throws ServiceException { - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - NetworkDaoImpl impl = new NetworkDaoImpl(); - NetworkEntity networkEntity =new NetworkEntity(); - networkEntity.setId("1"); - assertEquals(0, impl.addNetwork(networkEntity)); - - } - - @Test - public void testaddNetworkSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - NetworkDaoImpl impl = new NetworkDaoImpl(); - NetworkEntity networkEntity =new NetworkEntity(); - networkEntity.setId("1"); - assertEquals(0, impl.addNetworkSelective(networkEntity)); - } - @Test - public void testupdateNetworkSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - NetworkDaoImpl impl = new NetworkDaoImpl(); - NetworkEntity networkEntity =new NetworkEntity(); - networkEntity.setId("1"); - assertEquals(0, impl.updateNetworkSelective(networkEntity)); - } - @Test - public void testupdateNetwork() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - NetworkDaoImpl impl = new NetworkDaoImpl(); - NetworkEntity networkEntity =new NetworkEntity(); - networkEntity.setId("1"); - assertEquals(0, impl.updateNetwork(networkEntity)); - - } - @Test - public void testupdateNetworkByVimId() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - NetworkDaoImpl impl = new NetworkDaoImpl(); - NetworkEntity networkEntity =new NetworkEntity(); - networkEntity.setId("1"); - assertEquals(0, impl.updateNetworkByVimId(networkEntity)); - - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/PortDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/PortDaoImplTest.java deleted file mode 100644 index 1cb4de8..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/PortDaoImplTest.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.service.dao.impl; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.impl.PortDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.onap.vfc.nfvo.res.service.mapper.NetworkMapper; -import org.onap.vfc.nfvo.res.service.mapper.PortMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Expectations; -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; - -public class PortDaoImplTest { - @Mocked - PortMapper mapper; - - - @Test - public void testdeletePort() throws ServiceException { - - new Expectations() {{ - mapper.deletePort("123"); - }}; - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - PortDaoImpl impl = new PortDaoImpl(); - assertEquals(0, impl.deletePort("123")); - - - } - @Test - public void testdeletePortByVimId() throws ServiceException { - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - PortDaoImpl impl = new PortDaoImpl(); - assertEquals(0, impl.deletePortByVimId("123")); - - } - - @Test - public void testaddPort() throws ServiceException { - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - PortDaoImpl impl = new PortDaoImpl(); - PortEntity portEntity =new PortEntity(); - portEntity.setId("1"); - assertEquals(0, impl.addPort(portEntity)); - - } - - @Test - public void testaddPortSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - PortDaoImpl impl = new PortDaoImpl(); - PortEntity portEntity =new PortEntity(); - portEntity.setId("1"); - assertEquals(0, impl.addPortSelective(portEntity)); - - } - - @Test - public void testupdatePortSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - PortDaoImpl impl = new PortDaoImpl(); - PortEntity portEntity =new PortEntity(); - portEntity.setId("1"); - assertEquals(0, impl.updatePortSelective(portEntity)); - } - @Test - public void testupdatePort() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - PortDaoImpl impl = new PortDaoImpl(); - PortEntity portEntity =new PortEntity(); - portEntity.setId("1"); - assertEquals(0, impl.updatePort(portEntity)); - - } - @Test - public void testupdatePortByVimId() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - PortDaoImpl impl = new PortDaoImpl(); - PortEntity portEntity =new PortEntity(); - portEntity.setId("1"); - assertEquals(0, impl.updatePortByVimId(portEntity)); - - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/SitesDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/SitesDaoImplTest.java deleted file mode 100644 index 763ce16..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/SitesDaoImplTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.service.dao.impl; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.impl.SitesDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.onap.vfc.nfvo.res.service.mapper.NetworkMapper; -import org.onap.vfc.nfvo.res.service.mapper.SitesMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Expectations; -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; - -public class SitesDaoImplTest { - @Mocked - SitesMapper mapper; - @Test - public void testdeleteSite() throws ServiceException { - - new Expectations() {{ - mapper.deleteSite("123"); - }}; - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - SitesDaoImpl impl = new SitesDaoImpl(); - assertEquals(0, impl.deleteSite("123")); - } - @Test - public void testaddSite() throws ServiceException { - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - SitesDaoImpl impl = new SitesDaoImpl(); - SitesEntity sitesEntity =new SitesEntity(); - sitesEntity.setId("1"); - assertEquals(0, impl.addSite(sitesEntity)); - } - @Test - public void testaddSiteSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - SitesDaoImpl impl = new SitesDaoImpl(); - SitesEntity sitesEntity =new SitesEntity(); - sitesEntity.setId("1"); - assertEquals(0, impl.addSiteSelective(sitesEntity)); - } - @Test - public void testupdateSiteSelective() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - SitesDaoImpl impl = new SitesDaoImpl(); - SitesEntity sitesEntity =new SitesEntity(); - sitesEntity.setId("1"); - assertEquals(0, impl.updateSiteSelective(sitesEntity)); - } - @Test - public void testupdateNetwork() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - SitesDaoImpl impl = new SitesDaoImpl(); - SitesEntity sitesEntity =new SitesEntity(); - sitesEntity.setId("1"); - assertEquals(0, impl.updateSite(sitesEntity)); - } - @Test - public void testupdateSiteByVimId() throws ServiceException { - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - SitesDaoImpl impl = new SitesDaoImpl(); - SitesEntity sitesEntity =new SitesEntity(); - sitesEntity.setId("1"); - assertEquals(0, impl.updateSiteByVimId(sitesEntity)); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VimDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VimDaoImplTest.java deleted file mode 100644 index 3c393f6..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VimDaoImplTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.dao.impl; - -import static org.junit.Assert.*; - -import java.util.List; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.impl.VimDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.entity.VimEntity; -import org.onap.vfc.nfvo.res.service.mapper.VimMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Expectations; -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; - -public class VimDaoImplTest { - - @Mocked - VimMapper mapper; - - - @Test - public void testdeleteVim() throws ServiceException { - - new Expectations() {{ - mapper.deleteVim("123"); - }}; - - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - VimDaoImpl impl = new VimDaoImpl(); - assertEquals(0, impl.deleteVim("123")); - - - } - - @Test - public void testaddVim() throws ServiceException { - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - VimDaoImpl impl = new VimDaoImpl(); - VimEntity vimEntity =new VimEntity(); - vimEntity.setId("1"); - assertEquals(0, impl.addVim(vimEntity)); - - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VirtualLinkDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VirtualLinkDaoImplTest.java deleted file mode 100644 index 839b4b3..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VirtualLinkDaoImplTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.service.dao.impl; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.impl.VirtualLinkDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity; -import org.onap.vfc.nfvo.res.service.mapper.SitesMapper; -import org.onap.vfc.nfvo.res.service.mapper.VirtualLinkMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; - -public class VirtualLinkDaoImplTest { - @Mocked - VirtualLinkMapper mapper; - @Test - public void testdeleteVlById() throws ServiceException { - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - VirtualLinkDaoImpl impl = new VirtualLinkDaoImpl(); - - assertEquals(0, impl.deleteVlById("1")); - - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VmDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VmDaoImplTest.java deleted file mode 100644 index 5b53db4..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/dao/impl/VmDaoImplTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.service.dao.impl; - -import static org.junit.Assert.*; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.dao.impl.AbstractDao; -import org.onap.vfc.nfvo.res.service.dao.impl.VmDaoImpl; -import org.onap.vfc.nfvo.res.service.entity.VmEntity; -import org.onap.vfc.nfvo.res.service.mapper.SitesMapper; -import org.onap.vfc.nfvo.res.service.mapper.VmMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -import mockit.Mock; -import mockit.MockUp; -import mockit.Mocked; - -public class VmDaoImplTest { - @Mocked - VmMapper mapper; - @Test - public void TestaddVm() throws ServiceException { - new MockUp() { - - @Mock - public T getMapperManager(Class type) { - return (T) mapper; - - } - }; - VmDaoImpl impl = new VmDaoImpl(); - VmEntity vmEntity =new VmEntity(); - vmEntity.setVmId("1"); - //assertEquals(0, impl.addVm(vmEntity)); - - } - - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/HostEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/HostEntityTest.java deleted file mode 100644 index 4a1574b..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/HostEntityTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.onap.vfc.nfvo.res.service.entity; - -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; - -import net.sf.json.JSONObject; - -public class HostEntityTest { - private HostEntity hostEntity; - - @Before - public void setUp() { - hostEntity = new HostEntity(); - } - - @Test - public void testHostEntity() { - assertTrue(hostEntity.toString() != null); - assertTrue(HostEntity.toEntity(new JSONObject()) != null); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/LocationEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/LocationEntityTest.java deleted file mode 100644 index 7e708ed..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/LocationEntityTest.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; - -import net.sf.json.JSONObject; - -public class LocationEntityTest { - - private LocationEntity locationEntity; - - @Before - public void setUp() { - locationEntity = new LocationEntity(); - } - - @Test - public void testLocationEntity() { - locationEntity.setCountry("country"); - locationEntity.setDescription("description"); - locationEntity.setLocation("location"); - locationEntity.setLatitude("latitude"); - locationEntity.setLongitude("longitude"); - assertTrue(locationEntity.toString() != null); - assertTrue(LocationEntity.toEntity(new JSONObject()) != null); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/NetworkEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/NetworkEntityTest.java deleted file mode 100644 index 1bd94c1..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/NetworkEntityTest.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; - -import net.sf.json.JSONObject; - -public class NetworkEntityTest { - - private NetworkEntity networkEntity; - - @Before - public void setUp() { - networkEntity = new NetworkEntity(); - } - - @Test - public void testSetId() { - networkEntity.setId("123"); - networkEntity.setName("name"); - networkEntity.setNetworkType("networkType"); - networkEntity.setPhysicalNetwork("physicalNetwork"); - networkEntity.setSegmentationId("segmentationId"); - networkEntity.setStatus("networkStatus"); - networkEntity.setTenantId("tenantId"); - networkEntity.setVimId("networkVimId"); - networkEntity.setVimName("networkVimName"); - assertTrue(networkEntity.toString() != null); - assertTrue(NetworkEntity.toEntity(new JSONObject()) != null); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/PortEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/PortEntityTest.java deleted file mode 100644 index 0826514..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/PortEntityTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.entity.PortEntity; - -import net.sf.json.JSONObject; - -public class PortEntityTest { - - private PortEntity portEntity; - - @Before - public void setUp() { - portEntity = new PortEntity(); - } - - @Test - public void testPortEntiry() { - portEntity.setId("id:"); - portEntity.setName("name"); - portEntity.setNetworkId("networkId"); - portEntity.setTenantId("tenantId"); - portEntity.setVimId("vimID"); - portEntity.setVimName("vimName"); - assertTrue(portEntity.toString() != null); - assertTrue(PortEntity.toEntity(new JSONObject()) != null); - - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/SitesEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/SitesEntityTest.java deleted file mode 100644 index d20c714..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/SitesEntityTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; - -import net.sf.json.JSONObject; - -public class SitesEntityTest { - - private SitesEntity sitesEntity; - - @Before - public void setUp() { - sitesEntity = new SitesEntity(); - } - - @Test - public void testSitesEntity() { - sitesEntity.setCountry("country"); - sitesEntity.setId("id"); - sitesEntity.setLocation("location"); - sitesEntity.setName("name"); - sitesEntity.setStatus("siteStatus"); - sitesEntity.setTotalCPU("12"); - sitesEntity.setTotalDisk("12"); - sitesEntity.setTotalMemory("134"); - sitesEntity.setUsedCPU("12"); - sitesEntity.setUsedDisk("23"); - sitesEntity.setUsedMemory("10"); - sitesEntity.setVimId("siteVimId"); - sitesEntity.setVimName("siteVimName"); - assertTrue(sitesEntity.toString() != null); - assertTrue(SitesEntity.toEntity(new JSONObject()) != null); - SitesEntity.checkResource(sitesEntity); - SitesEntity.checkResourceIsZero(sitesEntity); - } - - @Test - public void testSitesEntityBranch() { - sitesEntity.setCountry("country"); - sitesEntity.setId("id"); - sitesEntity.setLocation("location"); - sitesEntity.setName("name"); - sitesEntity.setStatus("siteStatus"); - sitesEntity.setTotalCPU(""); - sitesEntity.setTotalDisk(""); - sitesEntity.setTotalMemory(""); - sitesEntity.setUsedCPU(""); - sitesEntity.setUsedDisk(""); - sitesEntity.setUsedMemory(""); - sitesEntity.setVimId("siteVimId"); - sitesEntity.setVimName("siteVimName"); - SitesEntity.checkResource(sitesEntity); - SitesEntity.checkResourceIsZero(sitesEntity); - } - - @Test - public void testSitesEntityBranch1() { - sitesEntity.setCountry("country"); - sitesEntity.setId("id"); - sitesEntity.setLocation("location"); - sitesEntity.setName("name"); - sitesEntity.setStatus("siteStatus"); - sitesEntity.setTotalCPU("s"); - sitesEntity.setTotalDisk(""); - sitesEntity.setTotalMemory("s"); - sitesEntity.setUsedCPU("s"); - sitesEntity.setUsedDisk("s"); - sitesEntity.setUsedMemory("s"); - sitesEntity.setVimId("siteVimId"); - sitesEntity.setVimName("siteVimName"); - SitesEntity.checkResource(sitesEntity); - } - - @Test - public void testSitesEntityBranch2() { - sitesEntity.setCountry("country"); - sitesEntity.setId("id"); - sitesEntity.setLocation("location"); - sitesEntity.setName("name"); - sitesEntity.setStatus("siteStatus"); - sitesEntity.setTotalCPU("23"); - sitesEntity.setTotalDisk(""); - sitesEntity.setTotalMemory("s"); - sitesEntity.setUsedCPU("1"); - sitesEntity.setUsedDisk("s"); - sitesEntity.setUsedMemory("s"); - sitesEntity.setVimId("siteVimId"); - sitesEntity.setVimName("siteVimName"); - SitesEntity.checkResource(sitesEntity); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/VimEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/VimEntityTest.java deleted file mode 100644 index 98e5994..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/entity/VimEntityTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2016 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.entity; - -import static org.junit.Assert.assertTrue; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.entity.VimEntity; - -import net.sf.json.JSONObject; - -public class VimEntityTest { - - private VimEntity vimEntity; - - @Before - public void setUp() { - vimEntity = new VimEntity(); - } - - @Test - public void testSitesEntity() { - vimEntity.setId("id"); - vimEntity.setName("name"); - assertTrue(vimEntity.toString() != null); - assertTrue(VimEntity.toEntity(new JSONObject()) != null); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/GrantResourseRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/GrantResourseRoaTest.java deleted file mode 100644 index 9c5087b..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/GrantResourseRoaTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.group.impl.GrantResServiceImpl; -import org.onap.vfc.nfvo.res.service.group.inf.GrantResService; -import org.onap.vfc.nfvo.res.service.rest.GrantResourseRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Mar 16, 2017 - */ -public class GrantResourseRoaTest { - - private GrantResourseRoa roa; - - private GrantResService grantResService; - - @Before - public void setUp() { - roa = new GrantResourseRoa(); - grantResService = new GrantResServiceImpl(); - roa.setGrantResService(grantResService); - } - - @Test - public void testGrantResource() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject grantResource(JSONObject object) throws ServiceException { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.grantResource(mock); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testGrantResourceByNull() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.grantResource(mock); - assertNotNull(result); - } - - @Test - public void testGrantResourceFail() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject grantResource(JSONObject object) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.grantResource(mock); - assertNotNull(result); - } - - @Test - public void testGrantResourceReal() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject grantResourceReal(JSONObject object) throws ServiceException { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.grantResourceReal(mock); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testGrantResourceRealByNull() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - roa.grantResourceReal(mock); - } - - @Test - public void testGrantResourceRealFail() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject grantResourceReal(JSONObject object) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.grantResourceReal(mock); - assertNotNull(result); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/HostRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/HostRoaTest.java deleted file mode 100644 index ef697ce..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/HostRoaTest.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.HostImpl; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Host; -import org.onap.vfc.nfvo.res.service.entity.HostEntity; -import org.onap.vfc.nfvo.res.service.rest.HostRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class HostRoaTest { - - private HostRoa roa; - - private Host host; - - @Before - public void setUp() { - roa = new HostRoa(); - host = new HostImpl(); - roa.setHost(host); - } - - @Test - public void testGetHosts() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getHosts(mock); - assertNotNull(result); - } - - @Test - public void testGetHost() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getHost(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddHost() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int add(JSONObject jsonObject) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addHost(mock); - assertNotNull(result); - } - - @Test - public void testAddHostByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int add(JSONObject jsonObject) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addHost(mock); - assertNotNull(result); - } - - @Test - public void testDeleteHost() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteHost(mock, "id"); - assertNotNull(result); - } - - @Test - public void testDeleteHostByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteHost(mock, "id"); - assertNotNull(result); - } - - @Test - public void testUpdateHost() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateHost(mock); - assertNotNull(result); - } - - @Test - public void testUpdateHostByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateHost(mock); - assertNotNull(result); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/LimitsRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/LimitsRoaTest.java deleted file mode 100644 index 757856b..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/LimitsRoaTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.business.impl.LimitsBusinessImpl; -import org.onap.vfc.nfvo.res.service.business.inf.LimitsBusiness; -import org.onap.vfc.nfvo.res.service.rest.LimitsRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class LimitsRoaTest { - - private LimitsRoa roa; - - private LimitsBusiness limitsBusiness; - - @Before - public void setUp() { - roa = new LimitsRoa(); - limitsBusiness = new LimitsBusinessImpl(); - roa.setLimitsBusiness(limitsBusiness); - } - - @Test - public void testGetLimitsResource() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getLimits(String vimId) throws ServiceException { - return new JSONObject(); - } - }; - HttpServletRequest context = new MockHttpServletRequest(); - JSONObject result = roa.getLimits(context, "vimId"); - assertNotNull(result); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/LocationRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/LocationRoaTest.java deleted file mode 100644 index fc15bfc..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/LocationRoaTest.java +++ /dev/null @@ -1,390 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.LocationImpl; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.SitesImpl; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Location; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Sites; -import org.onap.vfc.nfvo.res.service.entity.LocationEntity; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.onap.vfc.nfvo.res.service.rest.LocationRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class LocationRoaTest { - - private LocationRoa roa; - - private Location location; - - private Sites sites; - - @Before - public void setUp() { - roa = new LocationRoa(); - location = new LocationImpl(); - sites = new SitesImpl(); - roa.setLocation(location); - roa.setSites(sites); - } - - @Test - public void testGetLocationsbase() throws ServiceException { - new MockUp() { - - @Mock - public List get(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getLocationsbase(mock); - assertNotNull(result); - } - - @Test - public void testGetLocationbase() throws ServiceException { - new MockUp() { - - @Mock - public List get(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getLocationbase(mock, "id"); - assertNotNull(result); - } - - @Test - public void testGetCountry() throws ServiceException { - new MockUp() { - - @Mock - public List getCountry() throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getCountry(mock); - assertNotNull(result); - } - - @Test - public void testGetLocationByCountry() throws ServiceException { - new MockUp() { - - @Mock - public List getLocationByCountry(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getLocationByCountry(mock, "country"); - assertNotNull(result); - } - - @Test - public void testGetLocation() throws ServiceException { - new MockUp() { - - @Mock - public List get(Map condition) throws ServiceException { - return new ArrayList(); - } - - @Mock - public List getLocationInfo(List locationInfo) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getLocation(mock, "locations"); - assertNotNull(result); - } - - @Test - public void testAddLocation() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int add(JSONObject jsonObject) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addLocation(mock); - assertNotNull(result); - } - - @Test - public void testAddLocationByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int add(JSONObject jsonObject) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addLocation(mock); - assertNotNull(result); - } - - @Test - public void testDeleteLocationbase() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String location) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteLocationbase(mock, "locations"); - assertNotNull(result); - } - - @Test - public void testDeleteLocationbaseByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String location) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteLocationbase(mock, "locations"); - assertNotNull(result); - } - - @Test - public void testDeleteLocation() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - JSONObject object = new JSONObject(); - object.put("location", "location"); - object.put("id", "id"); - return object; - } - }; - new MockUp() { - - @Mock - public SitesEntity get(Map condition) throws ServiceException { - return null; - } - }; - new MockUp() { - - @Mock - public int delete(String location) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteLocation(mock); - assertNotNull(result); - } - - @Test - public void testDeleteLocationByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - JSONObject object = new JSONObject(); - object.put("location", "location"); - object.put("id", "id"); - return object; - } - }; - new MockUp() { - - @Mock - public SitesEntity get(Map condition) throws ServiceException { - return null; - } - }; - new MockUp() { - - @Mock - public int delete(String location) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteLocation(mock); - assertNotNull(result); - } - - @Test - public void testDeleteLocationBySitesEntity() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - JSONObject object = new JSONObject(); - object.put("location", "location"); - object.put("id", "id"); - return object; - } - }; - new MockUp() { - - @Mock - public SitesEntity get(Map condition) throws ServiceException { - return new SitesEntity(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteLocation(mock); - assertNotNull(result); - } - - @Test - public void testUpdateLocation() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - JSONObject object = new JSONObject(); - object.put("location", "location"); - return object; - } - }; - new MockUp() { - - @Mock - public SitesEntity get(Map condition) throws ServiceException { - return null; - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateLocation(mock); - assertNotNull(result); - } - - @Test - public void testUpdateLocationByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - JSONObject object = new JSONObject(); - object.put("location", "location"); - return object; - } - }; - new MockUp() { - - @Mock - public SitesEntity get(Map condition) throws ServiceException { - return null; - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateLocation(mock); - assertNotNull(result); - } - - @Test - public void testUpdateLocationBySitesEntity() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - JSONObject object = new JSONObject(); - object.put("location", "location"); - return object; - } - }; - new MockUp() { - - @Mock - public SitesEntity get(Map condition) throws ServiceException { - return new SitesEntity(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateLocation(mock); - assertNotNull(result); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/NetworkRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/NetworkRoaTest.java deleted file mode 100644 index 0aef982..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/NetworkRoaTest.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.NetworkImpl; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Network; -import org.onap.vfc.nfvo.res.service.entity.NetworkEntity; -import org.onap.vfc.nfvo.res.service.rest.NetworkRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class NetworkRoaTest { - - private NetworkRoa roa; - - private Network network; - - @Before - public void setUp() { - roa = new NetworkRoa(); - network = new NetworkImpl(); - roa.setNetwork(network); - } - - @Test - public void testGetNetworks() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getNetworks(mock); - assertNotNull(result); - } - - @Test - public void testGetNetwork() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getNetwork(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddNetwork() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public NetworkEntity toEntity(JSONObject jsonObject) { - return new NetworkEntity(); - } - }; - new MockUp() { - - @Mock - public int add(NetworkEntity entity) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addNetwork(mock); - assertNotNull(result); - } - - @Test - public void testAddNetworkByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public NetworkEntity toEntity(JSONObject jsonObject) { - return new NetworkEntity(); - } - }; - new MockUp() { - - @Mock - public int add(NetworkEntity entity) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addNetwork(mock); - assertNotNull(result); - } - - @Test - public void testDeleteNetwork() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteNetwork(mock, "id"); - assertNotNull(result); - } - - @Test - public void testDeleteNetworkByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteNetwork(mock, "id"); - assertNotNull(result); - } - - @Test - public void testUpdateNetwork() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateNetwork(mock); - assertNotNull(result); - } - - @Test - public void testUpdateNetworkByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateNetwork(mock); - assertNotNull(result); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/PortRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/PortRoaTest.java deleted file mode 100644 index 115a893..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/PortRoaTest.java +++ /dev/null @@ -1,215 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.PortImpl; -import org.onap.vfc.nfvo.res.service.base.openstack.inf.Port; -import org.onap.vfc.nfvo.res.service.entity.PortEntity; -import org.onap.vfc.nfvo.res.service.rest.PortRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class PortRoaTest { - - private PortRoa roa; - - private Port port; - - @Before - public void setUp() { - roa = new PortRoa(); - port = new PortImpl(); - roa.setPort(port); - } - - @Test - public void testGetPorts() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getPorts(mock); - assertNotNull(result); - } - - @Test - public void testGetPort() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getPort(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddPort() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public PortEntity toEntity(JSONObject jsonObject) { - return new PortEntity(); - } - }; - new MockUp() { - - @Mock - public int add(PortEntity portEntity) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addPort(mock); - assertNotNull(result); - } - - @Test - public void testAddPortByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public PortEntity toEntity(JSONObject jsonObject) { - return new PortEntity(); - } - }; - new MockUp() { - - @Mock - public int add(PortEntity portEntity) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addPort(mock); - assertNotNull(result); - } - - @Test - public void testDeletePort() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deletePort(mock, "id"); - assertNotNull(result); - } - - @Test - public void testDeletePortByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deletePort(mock, "id"); - assertNotNull(result); - } - - @Test - public void testUpdatePort() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updatePort(mock); - assertNotNull(result); - } - - @Test - public void testUpdatePortByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updatePort(mock); - assertNotNull(result); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/ResOperateRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/ResOperateRoaTest.java deleted file mode 100644 index 3dffc89..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/ResOperateRoaTest.java +++ /dev/null @@ -1,198 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.group.impl.ResOperateServiceImpl; -import org.onap.vfc.nfvo.res.service.group.inf.ResOperateService; -import org.onap.vfc.nfvo.res.service.rest.ResOperateRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Mar 16, 2017 - */ -public class ResOperateRoaTest { - - private ResOperateRoa roa; - - private ResOperateService resOperateService; - - @Before - public void setUp() { - roa = new ResOperateRoa(); - resOperateService = new ResOperateServiceImpl(); - roa.setResOperateService(resOperateService); - } - - @Test - public void testUpdateIResPool() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject getVimById(String vimId) { - JSONObject vimInfo = new JSONObject(); - vimInfo.put("tenant", "tenant"); - return vimInfo; - } - - @Mock - public String getTenantIdByName(String tenant, String vimId) { - return ""; - } - }; - new MockUp() { - - @Mock - public void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException { - } - - @Mock - public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateIResPool(mock, "vimId"); - assertNotNull(result); - } - - @Test - public void testUpdateIResPoolFail() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject getVimById(String vimId) { - JSONObject vimInfo = new JSONObject(); - vimInfo.put("tenant", "tenant"); - return vimInfo; - } - - @Mock - public String getTenantIdByName(String tenant, String vimId) { - return ""; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.updateIResPool(mock, null); - assertNotNull(result); - } - - @Test - public void testAddAllResPool() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException { - } - - @Mock - public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addAllResPool(mock, "tenantId", "vimId"); - assertNotNull(result); - } - - @Test - public void testAddAllResPoolFail() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addAllResPool(mock, null, null); - assertNotNull(result); - } - - @Test - public void testDeleteIRes() throws ServiceException { - new MockUp() { - - @Mock - public int deleteIRes(String vimId) throws ServiceException { - return 1; - } - - @Mock - public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteIRes(mock, "vimId"); - assertNotNull(result); - } - - @Test - public void testDeleteIResFail() throws ServiceException { - new MockUp() { - - @Mock - public int deleteIRes(String vimId) throws ServiceException { - throw new ServiceException(); - } - - @Mock - public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteIRes(mock, null); - assertNotNull(result); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/SitesRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/SitesRoaTest.java deleted file mode 100644 index 60330c9..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/SitesRoaTest.java +++ /dev/null @@ -1,280 +0,0 @@ -/* - * Copyright 2016-2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.VimUtil; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.base.openstack.impl.SitesImpl; -import org.onap.vfc.nfvo.res.service.entity.SitesEntity; -import org.onap.vfc.nfvo.res.service.rest.SitesRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONArray; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 2016年8月16日 - */ -public class SitesRoaTest { - - private SitesRoa sitesRoa; - - @Before - public void setUp() { - sitesRoa = new SitesRoa(); - sitesRoa.setSites(new SitesImpl()); - } - - @Test - public void testGetSites() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = sitesRoa.getSites(mock); - assertNotNull(result); - } - - @Test - public void testGetSite() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map condition) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = sitesRoa.getSite(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddSites() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getAllJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int add(JSONObject jsonObject) throws ServiceException { - return 1; - } - - @Mock - public void sendToMonitor(JSONObject jsonObject) throws ServiceException { - - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = sitesRoa.addSites(mock); - assertNotNull(result); - } - - @Test - public void testAddSitesExceptions() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getAllJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int add(JSONObject jsonObject) throws ServiceException { - throw new ServiceException(); - } - }; - JSONObject result = sitesRoa.addSites(null); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", ""); - assertEquals(expectedResult.toString(), result.toString()); - } - - @Test - public void testDeleteSites() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - JSONObject result = sitesRoa.deleteSites(null, "123"); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", "org.openo.nfvo.resmanage.common.del.success"); - assertEquals(expectedResult.toString(), result.toString()); - } - - @Test - public void testDeleteSitesExceptions() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - JSONObject result = sitesRoa.deleteSites(null, "123"); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", ""); - assertEquals(expectedResult.toString(), result.toString()); - } - - @Test - public void testUpdateSites() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getAllJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(SitesEntity sitesEntity) throws ServiceException { - return 1; - } - }; - JSONObject result = sitesRoa.updateSites(null); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", "org.openo.nfvo.resmanage.common.update.success"); - assertEquals(expectedResult.toString(), result.toString()); - } - - @Test - public void testUpdateISitesExceptions() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getAllJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(SitesEntity sitesEntity) throws ServiceException { - throw new ServiceException(); - } - }; - JSONObject result = sitesRoa.updateSites(null); - JSONObject expectedResult = new JSONObject(); - expectedResult.put("msg", ""); - assertEquals(expectedResult.toString(), result.toString()); - } - - @Test - public void testGrantResource() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getAllJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = sitesRoa.grantResource(mock); - assertNotNull(result); - } - - @Test - public void testGrantResourceByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getAllJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public int update(JSONObject jsonObject) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = sitesRoa.grantResource(mock); - assertNotNull(result); - } - - @Test - public void testGetVims() throws ServiceException { - new MockUp() { - - @Mock - public JSONArray getVims() { - return new JSONArray(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - String result = sitesRoa.getVims(mock); - assertNotNull(result); - } - - @Test - public void testGetVim() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getVimById(String vimId) { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - String result = sitesRoa.getVim(mock, "id"); - assertNotNull(result); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/SwaggerRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/SwaggerRoaTest.java deleted file mode 100644 index 4e5124b..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/SwaggerRoaTest.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.commons.io.IOUtils; -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.rest.SwaggerRoa; - -import mockit.Mock; -import mockit.MockUp; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class SwaggerRoaTest { - - private SwaggerRoa roa; - - @Test - public void testApidoc() throws IOException { - new MockUp() { - - @Mock - public String toString(InputStream input) { - return ""; - } - }; - roa = new SwaggerRoa(); - String result = roa.apidoc(); - assertNotNull(result); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VirtualLinkRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VirtualLinkRoaTest.java deleted file mode 100644 index ff53d48..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VirtualLinkRoaTest.java +++ /dev/null @@ -1,193 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.entity.VirtualLinkEntity; -import org.onap.vfc.nfvo.res.service.group.impl.VirtualLinkServiceImpl; -import org.onap.vfc.nfvo.res.service.group.inf.VirtualLinkService; -import org.onap.vfc.nfvo.res.service.rest.VirtualLinkRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class VirtualLinkRoaTest { - - private VirtualLinkRoa roa; - - private VirtualLinkService virtualLink; - - @Before - public void setUp() { - roa = new VirtualLinkRoa(); - virtualLink = new VirtualLinkServiceImpl(); - roa.setVirtualLink(virtualLink); - } - - @Test - public void testGetVls() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVls(mock); - assertNotNull(result); - } - - @Test - public void testGetVl() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVl(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddVl() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public VirtualLinkEntity toEntity(JSONObject jsonObject) { - return new VirtualLinkEntity(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVl(mock); - assertNotNull(result); - } - - @Test - public void testAddVlByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public VirtualLinkEntity toEntity(JSONObject jsonObject) { - return new VirtualLinkEntity(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVl(mock); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testAddVlByExceptionByNull() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - roa.addVl(mock); - } - - @Test - public void testDeleteVl() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVl(mock, "id"); - assertNotNull(result); - } - - @Test - public void testDeleteVlByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVl(mock, "id"); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testDeleteVlByNull() throws ServiceException { - HttpServletRequest mock = new MockHttpServletRequest(); - roa.deleteVl(mock, null); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VmRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VmRoaTest.java deleted file mode 100644 index 0d7f52c..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VmRoaTest.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.entity.VmEntity; -import org.onap.vfc.nfvo.res.service.group.impl.VmServiceImpl; -import org.onap.vfc.nfvo.res.service.group.inf.VmService; -import org.onap.vfc.nfvo.res.service.rest.VmRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class VmRoaTest { - - private VmRoa roa; - - private VmService vmService; - - @Before - public void setUp() { - roa = new VmRoa(); - vmService = new VmServiceImpl(); - roa.setVmService(vmService); - } - - @Test - public void testGetVms() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVms(mock); - assertNotNull(result); - } - - @Test - public void testGetVm() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVm(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddVm() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public VmEntity toEntity(JSONObject jsonObject) { - return new VmEntity(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVm(VmEntity vmEntity) throws ServiceException { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVm(mock); - assertNotNull(result); - } - - @Test - public void testAddVmByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public VmEntity toEntity(JSONObject jsonObject) { - return new VmEntity(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVm(VmEntity vmEntity) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVm(mock); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testAddVmByNull() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - roa.addVm(mock); - } - - @Test - public void testDeleteVm() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVm(mock, "id"); - assertNotNull(result); - } - - @Test - public void testDeleteVmByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVm(mock, "id"); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testDeleteVmByNull() throws ServiceException { - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVm(mock, null); - assertNotNull(result); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfInfoRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfInfoRoaTest.java deleted file mode 100644 index 68d00dd..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfInfoRoaTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.entity.VnfInfoEntity; -import org.onap.vfc.nfvo.res.service.group.impl.VnfInfoServiceImpl; -import org.onap.vfc.nfvo.res.service.group.inf.VnfInfoService; -import org.onap.vfc.nfvo.res.service.rest.VnfInfoRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class VnfInfoRoaTest { - - private VnfInfoRoa roa; - - private VnfInfoService vnfInfoService; - - @Before - public void setUp() { - roa = new VnfInfoRoa(); - vnfInfoService = new VnfInfoServiceImpl(); - roa.setVnfInfoService(vnfInfoService); - } - - @Test - public void testGetVnfInfos() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVnfInfos(mock); - assertNotNull(result); - } - - @Test - public void testGetVnfInfo() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVnfInfo(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddVnfInfo() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVnfInfo(JSONObject object) throws ServiceException { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVnfInfo(mock); - assertNotNull(result); - } - - @Test - public void testAddVnfInfoByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVnfInfo(JSONObject object) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVnfInfo(mock); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testAddVnfInfoByNull() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - roa.addVnfInfo(mock); - } - - @Test - public void testDeleteVnfInfo() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVnfInfo(mock, "id"); - assertNotNull(result); - } - - @Test - public void testDeleteVnfInfoByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVnfInfo(mock, "id"); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testDeleteVnfInfoByNull() throws ServiceException { - HttpServletRequest mock = new MockHttpServletRequest(); - roa.deleteVnfInfo(mock, null); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfRoaTest.java deleted file mode 100644 index 112f661..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfRoaTest.java +++ /dev/null @@ -1,192 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.entity.VnfEntity; -import org.onap.vfc.nfvo.res.service.group.impl.VnfServiceImpl; -import org.onap.vfc.nfvo.res.service.group.inf.VnfService; -import org.onap.vfc.nfvo.res.service.rest.VnfRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 10, 2017 - */ -public class VnfRoaTest { - - private VnfRoa roa; - - private VnfService vnfService; - - @Before - public void setUp() { - roa = new VnfRoa(); - vnfService = new VnfServiceImpl(); - roa.setVnfService(vnfService); - } - - @Test - public void testGetVnfs() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVnfs(mock); - assertNotNull(result); - } - - @Test - public void testGetVnf() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVnf(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddVnf() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public VnfEntity toEntity(JSONObject jsonObject) { - return new VnfEntity(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVnf(mock); - assertNotNull(result); - } - - @Test - public void testAddVnfByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public VnfEntity toEntity(JSONObject jsonObject) { - return new VnfEntity(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVnf(mock); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testAddVnfByNull() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - roa.addVnf(mock); - } - - @Test - public void testDeleteVnf() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVnf(mock, "id"); - assertNotNull(result); - } - - @Test - public void testDeleteVnfByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVnf(mock, "id"); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testDeleteVnfByNull() throws ServiceException { - HttpServletRequest mock = new MockHttpServletRequest(); - roa.deleteVnf(mock, null); - } -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfStatusRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfStatusRoaTest.java deleted file mode 100644 index a749290..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/VnfStatusRoaTest.java +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest; - -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; - -import org.junit.Before; -import org.junit.Test; -import org.onap.vfc.nfvo.res.common.util.request.RequestUtil; -import org.onap.vfc.nfvo.res.service.entity.VnfStatusEntity; -import org.onap.vfc.nfvo.res.service.group.impl.VnfStatusServiceImpl; -import org.onap.vfc.nfvo.res.service.group.inf.VnfStatusService; -import org.onap.vfc.nfvo.res.service.rest.VnfStatusRoa; -import org.openo.baseservice.remoteservice.exception.ServiceException; -import org.springframework.mock.web.MockHttpServletRequest; - -import mockit.Mock; -import mockit.MockUp; -import net.sf.json.JSONObject; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 10, 2017 - */ -public class VnfStatusRoaTest { - - private VnfStatusRoa roa; - - private VnfStatusService vnfStatusService; - - @Before - public void setUp() { - roa = new VnfStatusRoa(); - vnfStatusService = new VnfStatusServiceImpl(); - roa.setVnfStatusService(vnfStatusService); - } - - @Test - public void testGetVnfStatuss() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVnfStatuss(mock); - assertNotNull(result); - } - - @Test - public void testGetVnfStatus() throws ServiceException { - new MockUp() { - - @Mock - public List getList(Map map) throws ServiceException { - return new ArrayList(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.getVnfStatus(mock, "id"); - assertNotNull(result); - } - - @Test - public void testAddVnfStatus() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVnfStatus(JSONObject object) throws ServiceException { - return new JSONObject(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVnfStatus(mock); - assertNotNull(result); - } - - @Test - public void testAddVnfStatusByException() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return new JSONObject(); - } - }; - new MockUp() { - - @Mock - public JSONObject addVnfStatus(JSONObject object) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.addVnfStatus(mock); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testAddVnfStatusByNull() throws ServiceException { - new MockUp() { - - @Mock - public JSONObject getJsonRequestBody(HttpServletRequest context) { - return null; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - roa.addVnfStatus(mock); - } - - @Test - public void testDeleteVnfStatus() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - return 1; - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVnfStatus(mock, "id"); - assertNotNull(result); - } - - @Test - public void testDeleteVnfStatusByException() throws ServiceException { - new MockUp() { - - @Mock - public int delete(String id) throws ServiceException { - throw new ServiceException(); - } - }; - HttpServletRequest mock = new MockHttpServletRequest(); - JSONObject result = roa.deleteVnfStatus(mock, "id"); - assertNotNull(result); - } - - @Test(expected = ServiceException.class) - public void testDeleteVnfStatusByNull() throws ServiceException { - HttpServletRequest mock = new MockHttpServletRequest(); - roa.deleteVnfStatus(mock, null); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ExceptionMessageTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ExceptionMessageTest.java deleted file mode 100644 index e118918..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ExceptionMessageTest.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest.exceptionmapper; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.rest.exceptionmapper.ExceptionMessage; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class ExceptionMessageTest { - - @Test - public void testToString() { - ExceptionMessage message = new ExceptionMessage(); - message.setErrorCode("1"); - message.setHttpCode(200); - message.setMessage("Success!"); - String str = message.toString(); - assertNotNull(str); - } - - @Test - public void testGetErrorCode() { - ExceptionMessage message = new ExceptionMessage(); - message.setErrorCode("1"); - String str = message.getErrorCode(); - assertEquals("1", str); - } - - @Test - public void testHttpCode() { - ExceptionMessage message = new ExceptionMessage(); - message.setHttpCode(200); - int str = message.getHttpCode(); - assertEquals(200, str); - } - - @Test - public void testGetMessage() { - ExceptionMessage message = new ExceptionMessage(); - message.setMessage("Success!"); - String str = message.getMessage(); - assertEquals("Success!", str); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/GenericExceptionMapperTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/GenericExceptionMapperTest.java deleted file mode 100644 index 2b150c8..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/GenericExceptionMapperTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest.exceptionmapper; - -import static org.junit.Assert.assertNotNull; - -import javax.ws.rs.core.Response; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.rest.exceptionmapper.GenericExceptionMapper; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class GenericExceptionMapperTest { - - @Test - public void testToResponse() { - GenericExceptionMapper excep = new GenericExceptionMapper(); - Exception exception = new Exception("message"); - Response res = excep.toResponse(exception); - assertNotNull(res); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ServiceExceptionMapperTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ServiceExceptionMapperTest.java deleted file mode 100644 index d5281bf..0000000 --- a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/res/service/rest/exceptionmapper/ServiceExceptionMapperTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2017 Huawei Technologies Co., Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.vfc.nfvo.res.service.rest.exceptionmapper; - -import static org.junit.Assert.assertNotNull; - -import javax.ws.rs.core.Response; - -import org.junit.Test; -import org.onap.vfc.nfvo.res.service.rest.exceptionmapper.ServiceExceptionMapper; -import org.openo.baseservice.remoteservice.exception.ServiceException; - -/** - *
- *

- *

- * - * @author - * @version NFVO 0.5 Feb 9, 2017 - */ -public class ServiceExceptionMapperTest { - - @Test - public void testToResponse() { - ServiceExceptionMapper mapper = new ServiceExceptionMapper(); - ServiceException exception = new ServiceException(); - Response res = mapper.toResponse(exception); - assertNotNull(res); - } - -} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/ResourceUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/ResourceUtilTest.java new file mode 100644 index 0000000..cb2680e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/ResourceUtilTest.java @@ -0,0 +1,52 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.ResourceUtil; + + +public class ResourceUtilTest { + + + @Test + public void testGetMessage() throws NoSuchMethodException, SecurityException { + + + String key = "huawei"; + String result = ResourceUtil.getMessage(key); + String expectedResult = "huawei"; + assertEquals(expectedResult, result); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = ResourceUtil.class.getDeclaredConstructor(); + assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/VimUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/VimUtilTest.java new file mode 100644 index 0000000..6d15bbc --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/VimUtilTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.common; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.common.constant.UrlConstant; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.baseservice.roa.util.restclient.RestfulOptions; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +public class VimUtilTest { + + + + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = VimUtil.class.getDeclaredConstructor(); + assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtilTest.java new file mode 100644 index 0000000..1f7c8a1 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/JsonUtilTest.java @@ -0,0 +1,436 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +public class JsonUtilTest { + + @Test + public void testGetJsonFieldStr() { + JSONObject jsonObj = new JSONObject(); + String fieldName = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + String result = JsonUtil.getJsonFieldStr(jsonObj, fieldName); + String expectedResult = "1"; + assertEquals(expectedResult, result); + + } + + @Test + public void testGetJsonFieldInt() { + JSONObject jsonObj = new JSONObject(); + String fieldName = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + int result = JsonUtil.getJsonFieldInt(jsonObj, fieldName); + int expectedResult = 1; + assertEquals(expectedResult, result); + + } + + @Test + public void testGetJsonFieldArr() { + JSONObject jsonObj = new JSONObject(); + String fieldName = "a"; + jsonObj.put("a", new JSONArray()); + jsonObj.put("b", "2"); + JSONArray result = JsonUtil.getJsonFieldArr(jsonObj, fieldName); + JSONArray expectedResult = new JSONArray(); + assertEquals(expectedResult, result); + + } + + @Test + public void testGetJsonFieldJson() { + JSONObject jsonObj = new JSONObject(); + String fieldName = "a"; + jsonObj.put("a", new JSONObject()); + jsonObj.put("b", "2"); + JSONObject result = JsonUtil.getJsonFieldJson(jsonObj, fieldName); + JSONObject expectedResult = new JSONObject(); + assertEquals(expectedResult, result); + + } + + @Test + public void testGetJsonFieldLong() { + JSONObject jsonObj = new JSONObject(); + String fieldName = "a"; + jsonObj.put("a", 1); + jsonObj.put("b", 2); + Long result = JsonUtil.getJsonFieldLong(jsonObj, fieldName); + Long expectedResult = new Long(1); + assertEquals(expectedResult, result); + + } + + @Test + public void testGetJsonFieldObjectException() { + JSONObject jsonObj = new JSONObject(); + String fieldName = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + JSONObject result = JsonUtil.getJsonFieldJson(jsonObj, fieldName); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + + } + + @Test + public void testIsNullJson1() { + JSONObject jsonObj = new JSONObject(); + assertTrue(JsonUtil.isNullJson(jsonObj)); + } + + @Test + public void testIsNullJson2() { + assertTrue(JsonUtil.isNullJson(null)); + } + + @Test + public void testIsNullJson3() { + JSONObject jsonObj = new JSONObject(); + jsonObj.put("a", "1"); + assertFalse(JsonUtil.isNullJson(jsonObj)); + } + + @Test + public void testGetStrValueByjsonNULL() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + String result = JsonUtil.getStrValueByjson(jsonObj, key); + String expectedResult = null; + assertEquals(expectedResult, result); + + } + + @Test + public void testGetStrValueByjson() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + new MockUp() { + + @SuppressWarnings("static-access") + @Mock + public JSONObject optJSONObject(String key) { + return new JSONObject().fromObject("{\"a\":\"1\"}"); + } + + @Mock + public JSONObject getJSONObject(String key) { + return new JSONObject(); + } + }; + String result = JsonUtil.getStrValueByjson(jsonObj, key); + String expectedResult = "1"; + assertEquals(expectedResult, result); + + } + + @Test + public void testGetStrValueByjson1() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + new MockUp() { + + @Mock + public JSONObject optJSONObject(String key) { + return null; + } + + @SuppressWarnings("static-access") + @Mock + public JSONArray optJSONArray(String key) { + return new JSONArray().fromObject("[\"a\",\"1\"]"); + } + + @Mock + public JSONArray getJSONArray(String key) { + return new JSONArray(); + } + }; + String result = JsonUtil.getStrValueByjson(jsonObj, key); + String expectedResult = "1"; + assertEquals(expectedResult, result); + + } + + @Test + public void testGetStrValueByjson2() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + String result = JsonUtil.getStrValueByjson(jsonObj, key); + String expectedResult = "1"; + assertEquals(expectedResult, result); + + } + + @Test + public void testGetStrValueByJArray() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + new MockUp() { + + @Mock + public JSONObject optJSONObject(String key) { + return null; + } + + @SuppressWarnings("static-access") + @Mock + public JSONArray optJSONArray(String key) { + return new JSONArray().fromObject("[\"a\",\"1\"]"); + } + + @SuppressWarnings("static-access") + @Mock + public JSONArray getJSONArray(String key) { + return new JSONArray().fromObject("[\"a\",\"1\"]"); + } + + + }; + + String result = JsonUtil.getStrValueByjson(jsonObj, key); + + } + + @Test + public void testGetStrValueByJArray1() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + new MockUp() { + + int count = 1; + + @SuppressWarnings("static-access") + @Mock + public JSONObject optJSONObject(String key) { + if (count == 1) { + count += 1; + return null; + } else + return new JSONObject().fromObject("{\"a\":\"1\"}"); + } + + @SuppressWarnings("static-access") + @Mock + public JSONArray optJSONArray(String key) { + return new JSONArray().fromObject("[\"a\",\"1\"]"); + } + + @SuppressWarnings("static-access") + @Mock + public JSONArray getJSONArray(String key) { + return new JSONArray().fromObject("[\"a\",\"1\"]"); + } + }; + String result = JsonUtil.getStrValueByjson(jsonObj, key); + String expectedResult = "1"; + assertEquals(expectedResult, result); + + } + + @Test + public void testGetJsonValueByjson() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + String result = JsonUtil.getJsonValueByjson(jsonObj, key).toString(); + String expectedResult = "{\"a\":\"1\"}"; + assertEquals(expectedResult, result); + } + + @Test + public void testGetJsonValueByjsonResultIsNull() { + JSONObject jsonObj = new JSONObject(); + String key = "c"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + JSONObject result = JsonUtil.getJsonValueByjson(jsonObj, key); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetStrValueByJsonParentKeyIsNull() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + String parentKey = ""; + String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); + String expectedResult = "1"; + assertEquals(expectedResult, result); + } + + @Test + public void testGetStrValueByJsonParentJsonIsNull() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + String parentKey = "b"; + new MockUp() { + + @Mock + public JSONObject getJsonValueByjson(JSONObject json, String key) { + return new JSONObject(); + } + }; + String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetStrValueByJson() { + JSONObject jsonObj = new JSONObject(); + String key = "a"; + jsonObj.put("a", "1"); + jsonObj.put("b", "2"); + String parentKey = "b"; + String result = JsonUtil.getStrValueByJson(jsonObj, parentKey, key); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseDataRetcodeError1() { + new MockUp() { + + @Mock + public Integer getJsonFieldInt(JSONObject jsonObj, String fieldName) { + return null; + } + }; + JSONObject result = JsonUtil.getResponseData(null); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseDataRetcodeError2() { + new MockUp() { + + @Mock + public Integer getJsonFieldInt(JSONObject jsonObj, String fieldName) { + return -1; + } + }; + JSONObject result = JsonUtil.getResponseData(null); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseDataResultIsEmpty() { + JSONObject obj = new JSONObject(); + obj.put("data", "1"); + obj.put("retCode", "1"); + JSONObject result = JsonUtil.getResponseData(obj); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseData() { + JSONObject obj = new JSONObject(); + obj.put("data", new JSONObject()); + obj.put("retCode", "1"); + new MockUp() { + + @SuppressWarnings("static-access") + @Mock + public JSONObject optJSONObject(String key) { + return new JSONObject().fromObject("{\"a\":\"1\"}"); + } + }; + JSONObject result = JsonUtil.getResponseData(obj); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseData1() { + JSONObject obj = new JSONObject(); + obj.put("data", JSONArray.fromObject("[{\"a\":\"1\"},\"1\"]")); + obj.put("retCode", "1"); + new MockUp() { + + @Mock + public JSONObject optJSONObject(String key) { + return null; + } + + @SuppressWarnings("static-access") + @Mock + public JSONArray optJSONArray(String key) { + return new JSONArray().fromObject("[\"a\",\"1\"]"); + } + }; + JSONObject result = JsonUtil.getResponseData(obj); + String expectedResult = "{\"a\":\"1\"}"; + assertEquals(expectedResult, result.toString()); + } + + @Test + public void testGetResponseData2() { + JSONObject obj = new JSONObject(); + JSONObject json = new JSONObject(); + json.put("retCode", "1"); + obj.put("data", json); + obj.put("retCode", "1"); + JSONObject result = JsonUtil.getResponseData(obj); + String expectedResult = null; + assertEquals(expectedResult, result); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = JsonUtil.class.getDeclaredConstructor(); + assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtilTest.java new file mode 100644 index 0000000..8947985 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/RestfulUtilTest.java @@ -0,0 +1,245 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.constant.Constant; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulOptions; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONArray; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; + +public class RestfulUtilTest { + + @Test + public void testGetResponseObjWithTwoParams() { + JSONObject result = RestfulUtil.getResponseObj(null, null); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseObjWithThreeParams() { + new MockUp() { + + @Mock + public String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt, + String type) { + return "{\"ResponseContent\":\"123\"}"; + } + }; + JSONObject result = RestfulUtil.getResponseObj(null, null, null); + @SuppressWarnings("static-access") + JSONObject expectedResult = new JSONObject().fromObject("{\"ResponseContent\":\"123\"}"); + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseObjExpections() { + new MockUp() { + + @Mock + public String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt, + String type) { + throw new JSONException(); + } + }; + JSONObject result = RestfulUtil.getResponseObj(null, null, null); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseContent() { + String result = RestfulUtil.getResponseContent(null, null, null); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseMap() { + Map result = RestfulUtil.getResponseMap(null, null, null, null); + Map expectedResult = new HashMap(10); + expectedResult.put(Constant.RESPONSE_CONTENT, null); + expectedResult.put(Constant.STATUS_CODE, -1); + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseContentMap() { + Map result = RestfulUtil.getResponseContentMap(null, null); + Map expectedResult = new HashMap(10); + expectedResult.put(Constant.RESPONSE_CONTENT, null); + expectedResult.put(Constant.STATUS_CODE, -1); + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseContentWithFourParams() { + new MockUp() { + + @Mock + public int getStatus() { + return 200; + } + }; + String result = RestfulUtil.getResponseContent(null, null, null); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetRestfulResponse() { + RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, null); + RestfulResponse expectedResult = new RestfulResponse(); + assertEquals(expectedResult.getStatus(), result.getStatus()); + } + + @Test + public void testRestfulResponse() { + RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "get"); + RestfulResponse expectedResult = new RestfulResponse(); + assertEquals(expectedResult.getStatus(), result.getStatus()); + } + + @Test + public void testRestfulResponse1() { + RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "add"); + RestfulResponse expectedResult = new RestfulResponse(); + assertEquals(expectedResult.getStatus(), result.getStatus()); + } + + @Test + public void testRestfulResponse2() { + RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "put"); + RestfulResponse expectedResult = new RestfulResponse(); + assertEquals(expectedResult.getStatus(), result.getStatus()); + } + + @Test + public void testRestfulResponse3() { + RestfulResponse result = RestfulUtil.getRestfulResponse(null, null, "delete"); + RestfulResponse expectedResult = new RestfulResponse(); + assertEquals(expectedResult.getStatus(), result.getStatus()); + } + + @Test + public void testGetRestResObjectsIsNull() { + RestfulResponse result = RestfulUtil.getRestRes(null, null); + RestfulResponse expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetRestResReflectiveOperationException() { + RestfulResponse result = RestfulUtil.getRestRes("123", "get"); + RestfulResponse expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetRestRes() { + RestfulResponse result = RestfulUtil.getRestRes("async123", new RestfulResponse()); + RestfulResponse expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseResResultIsNull() throws ServiceException { + try { + RestfulUtil.getResponseRes(null, null); + } catch (ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testGetResponse() throws ServiceException { + new MockUp() { + + @Mock + public String getResponseContent(String url, RestfulParametes restParametes, String type) { + return "{\"ResponseContent\":\"123\",\"data\":[\"datas\"]}"; + } + }; + JSONArray result = RestfulUtil.getResponseRes(null, null); + JSONArray expectedResult = JSONArray.fromObject("[\"datas\"]"); + assertEquals(expectedResult, result); + } + + @Test + public void testGetResponseExceptions() throws ServiceException { + new MockUp() { + + @Mock + public String getResponseContent(String url, RestfulParametes restParametes, String type) { + return "{\"ResponseContent\":\"123\",}"; + } + }; + try { + RestfulUtil.getResponseRes(null, null); + } catch (ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testGgetResponseRes() throws ServiceException { + new MockUp() { + + @Mock + public String getResponseContent(String url, RestfulParametes restParametes, String type) { + return "{\"ResponseContent\":\"123\",}"; + } + }; + try { + RestfulUtil.getResponseRes(null, null, null); + } catch (ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testGgetResponseResException() throws ServiceException { + new MockUp() { + + @Mock + public String getResponseContent(String url, RestfulParametes restParametes, String type) { + return null; + } + }; + try { + RestfulUtil.getResponseRes(null, null, null); + } catch (ServiceException e) { + assertTrue(true); + } + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtilTest.java new file mode 100644 index 0000000..05fb52e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/StringUtilTest.java @@ -0,0 +1,144 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.StringUtil; + +public class StringUtilTest { + + @Test + public void testisValidString() { + assertTrue(StringUtil.isValidString("abc")); + } + + @Test + public void testisValidString1() { + assertFalse(StringUtil.isValidString(null)); + } + + @Test + public void testisValidString2() { + assertFalse(StringUtil.isValidString("")); + } + + @Test + public void testIsAnyLargeThanZero() { + assertFalse(StringUtil.isAnyLargeThanZero("")); + } + + @Test + public void testIsAnyLargeThanZero1() { + assertTrue(StringUtil.isAnyLargeThanZero("123")); + } + + @Test + public void testIsIntegerExceptions() { + assertFalse(StringUtil.isInteger("asd")); + } + + @Test + public void testIsInteger() { + assertTrue(StringUtil.isInteger("123")); + } + + @Test + public void testIsInteger1() { + assertFalse(StringUtil.isInteger("-1")); + } + + @Test + public void testIsNumericExceptions() { + assertFalse(StringUtil.isNumeric("abc")); + } + + @Test + public void testIsNumeric() { + assertTrue(StringUtil.isNumeric("1.456")); + } + + @Test + public void testIsNumeric1() { + assertFalse(StringUtil.isNumeric("-1.456")); + } + + @Test + public void testCompareZeroByFloat() { + assertTrue(StringUtil.compareZeroByFloat("3.0", "1.0", "2.0")); + } + + @Test + public void testCompareZeroByFloat1() { + assertFalse(StringUtil.compareZeroByFloat("3.0", "1.2", "2.5")); + } + + @Test + public void testCompareZeroByInteger() { + assertTrue(StringUtil.compareZeroByInteger("3", "1", "2")); + } + + @Test + public void testCompareZeroByInteger1() { + assertFalse(StringUtil.compareZeroByInteger("3", "1", "3")); + } + + @Test + public void testNumFormatDataIsNull() { + String result = StringUtil.numFormat(null); + assertEquals(null, result); + } + + @Test + public void testNumFormatDataIsEmpty() { + String result = StringUtil.numFormat(""); + assertEquals(null, result); + } + + @Test + public void testNumFormatInteger() { + String result = StringUtil.numFormat("12"); + String expectedResult = "12"; + assertEquals(expectedResult, result); + } + + @Test + public void testNumFormatFloat() { + String result = StringUtil.numFormat("12.5"); + String expectedResult = "12.5"; + assertEquals(expectedResult, result); + } + + @Test + public void testCheckXss() { + assertTrue(StringUtil.checkXss("123")); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = StringUtil.class.getDeclaredConstructor(); + assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtilTest.java new file mode 100644 index 0000000..26feb0e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/request/RequestUtilTest.java @@ -0,0 +1,253 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util.request; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Constructor; +import java.util.Arrays; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.ServletInputStream; +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.io.IOUtils; +import org.apache.cxf.jaxrs.impl.HttpServletRequestFilter; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; + +import javassist.Modifier; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; + +public class RequestUtilTest { + + @Test + public void testGetStringRequestBody() { + HttpServletRequestFilter context = new MockUp() { + + @Mocked + ServletInputStream input; + + @Mock + public ServletInputStream getInputStream() throws IOException { + return input; + } + }.getMockInstance(); + new MockUp() { + + String data = "{\"NETWORK\":{\"id\": \"123\"}}"; + + @Mock + public String toString(InputStream input) throws IOException { + return data; + } + }; + String result = RequestUtil.getStringRequestBody(context); + String expectedResult = "{\"NETWORK\":{\"id\": \"123\"}}"; + assertEquals(expectedResult, result); + } + + @Test + public void testGetStringRequestBodyException() { + HttpServletRequestFilter context = new MockUp() { + + @Mock + public ServletInputStream getInputStream() throws IOException { + throw new IOException(); + } + }.getMockInstance(); + String result = RequestUtil.getStringRequestBody(context); + String expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetJsonRequestBody() { + HttpServletRequestFilter context = new MockUp() { + + @Mocked + ServletInputStream input; + + @Mock + public ServletInputStream getInputStream() throws IOException { + return input; + } + }.getMockInstance(); + new MockUp() { + + String data = "{\"NETWORK\":{\"id\": \"123\"}}"; + + @Mock + public String toString(InputStream input) throws IOException { + return data; + } + }; + JSONObject result = RequestUtil.getJsonRequestBody(context); + String data1 = "{\"NETWORK\":{\"id\": \"123\"}}"; + JSONObject expectedResult = JSONObject.fromObject(data1); + assertEquals(expectedResult, result); + } + + @Test + public void testGetJsonRequestBody1() { + new MockUp() { + + String data1 = "{\"NETWORK\":{\"id\": \"123\"}}"; + + @Mock + public String getStringRequestBody(HttpServletRequest context) { + return data1; + } + }; + JSONObject result = RequestUtil.getJsonRequestBody(null); + String data1 = "{\"NETWORK\":{\"id\": \"123\"}}"; + JSONObject expectedResult = JSONObject.fromObject(data1); + assertEquals(expectedResult, result); + } + + @Test + public void testGetJsonRequestBodyException() { + HttpServletRequestFilter context = new MockUp() { + + @Mocked + ServletInputStream input; + + @Mock + public ServletInputStream getInputStream() throws JSONException { + throw new JSONException(); + } + }.getMockInstance(); + JSONObject result = RequestUtil.getJsonRequestBody(context); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @SuppressWarnings("rawtypes") + @Test + public void testGetAllJsonRequestBodyRequestBodyIsNull() { + HttpServletRequestFilter context = new MockUp() { + + @Mocked + ServletInputStream input; + + @Mock + public ServletInputStream getInputStream() throws IOException { + return input; + } + + @Mock + public Enumeration getHeaderNames() { + return new Enumeration() { + + List a = Arrays.asList(new String[] { "1", "2" }); + + @Override + public boolean hasMoreElements() { + return false; + } + + @Override + public Object nextElement() { + return null; + } + + }; + } + + }.getMockInstance(); + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + JSONObject result = RequestUtil.getAllJsonRequestBody(context); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("header", new HashMap()); + assertEquals(expectedResult, result); + } + + @SuppressWarnings("rawtypes") + @Test + public void testGetContextHeader() { + HttpServletRequestFilter context = new MockUp() { + + @Mock + public String getHeader(String name) { + return "1"; + } + + @Mock + public Enumeration getHeaderNames() { + return new Enumeration() { + + List a = Arrays.asList(new String[] { "1", "2" }); + + int count = 1; + + @Override + public boolean hasMoreElements() { + if (count == 1) { + count += 1; + return true; + } else + return false; + } + + @Override + public Object nextElement() { + return "1"; + } + + }; + } + + }.getMockInstance(); + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + JSONObject result = RequestUtil.getAllJsonRequestBody(context); + JSONObject expectedResult = new JSONObject(); + Map map = new HashMap(); + map.put("1", "1"); + expectedResult.put("header", map); + assertEquals(expectedResult, result); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = RequestUtil.class.getDeclaredConstructor(); + assertTrue("Constructor is private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtilTest.java new file mode 100644 index 0000000..a62e61e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/ResponseUtilTest.java @@ -0,0 +1,91 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util.response; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; + +import net.sf.json.JSONObject; + +public class ResponseUtilTest { + + @Test + public void TestGenHttpResponseWithTwoParam() { + int retCode1 = -1; + String msg1 = "123"; + JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", "123"); + assertEquals(result.toString(), expectedResult.toString()); + ; + } + + @Test + public void TestGenHttpResponseWithThreeParam() { + int retCode1 = -1; + String msg1 = "123"; + JSONObject result = ResponseUtil.genHttpResponse(retCode1, msg1, null); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", "123"); + assertEquals(result.toString(), expectedResult.toString()); + ; + } + + @Test + public void TestGenHttpResponseWithFourParam1() { + int httpStatusCode = -1; + int retCode1 = -1; + String msg1 = "123"; + JSONObject result = ResponseUtil.genHttpResponse(null, httpStatusCode, retCode1, msg1); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", "123"); + assertEquals(result.toString(), expectedResult.toString()); + ; + } + + @Test + public void TestGenHttpResponseWithFourParam2() { + Map codeMap = new HashMap(5); + codeMap.put("httpStatusCode", -1); + codeMap.put("retCode", 1); + Map map = new HashMap(5); + map.put("a", -1); + map.put("b", 1); + String msg1 = "123"; + JSONObject result = ResponseUtil.genHttpResponse(null, codeMap, msg1, map); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", "123"); + expectedResult.put("a", "-1"); + assertEquals(result.toString(), expectedResult.toString()); + ; + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = ResponseUtil.class.getDeclaredConstructor(); + assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java new file mode 100644 index 0000000..d8f8a8e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java @@ -0,0 +1,148 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.common.util.response; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.Map; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.response.RoaResponseUtil; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class RoaResponseUtilTest { + + @Test + public void testGet() { + new MockUp() { + + @Mock + public JSONObject genHttpResponse(int retCode, String msg, Map map) { + return null; + } + }; + JSONObject result = RoaResponseUtil.get(null); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testAdd() { + int a = 0; + new MockUp() { + + @Mock + public JSONObject genHttpResponse(int retCode, String msg) { + return null; + } + }; + JSONObject result = RoaResponseUtil.add(a); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testAdd1() { + int a = 2; + new MockUp() { + + @Mock + public JSONObject genHttpResponse(int retCode, String msg) { + return null; + } + }; + JSONObject result = RoaResponseUtil.add(a); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testUpdate() { + int a = 0; + new MockUp() { + + @Mock + public JSONObject genHttpResponse(int retCode, String msg) { + return null; + } + }; + JSONObject result = RoaResponseUtil.update(a); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testUpdate1() { + int a = 2; + new MockUp() { + + @Mock + public JSONObject genHttpResponse(int retCode, String msg) { + return null; + } + }; + JSONObject result = RoaResponseUtil.update(a); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testDelete() { + int a = -1; + new MockUp() { + + @Mock + public JSONObject genHttpResponse(int retCode, String msg) { + return null; + } + }; + JSONObject result = RoaResponseUtil.delete(a); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testDelete1() { + int a = 0; + new MockUp() { + + @Mock + public JSONObject genHttpResponse(int retCode, String msg) { + return null; + } + }; + JSONObject result = RoaResponseUtil.delete(a); + JSONObject expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = RoaResponseUtil.class.getDeclaredConstructor(); + assertTrue("Constructor is not private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java new file mode 100644 index 0000000..0bcdb81 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java @@ -0,0 +1,241 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.adapter.impl; + +import static org.junit.Assert.assertNotNull; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.RestfulUtil; +import org.onap.vfc.nfvo.resmanagement.service.adapter.impl.ResmgrAdapter2MSBManager; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 24, 2016 + */ +public class ResmgrAdapter2MSBManagerTest { + + @Test + public void testRegisterResmgr() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(201); + rsp.setResponseJson("{\"msg\":\"success!\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); + assertNotNull(resultObj); + } + + @Test + public void testRegisterResmgrByInvalid() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(415); + rsp.setResponseJson("{\"msg\":\"invalid parameters\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); + assertNotNull(resultObj); + } + + @Test + public void testRegisterResmgrByInternalError() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(500); + rsp.setResponseJson("{\"msg\":\"internal system error\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); + assertNotNull(resultObj); + } + + @Test + public void testRegisterResmgrByFail() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(404); + rsp.setResponseJson("{\"msg\":\"not found\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); + assertNotNull(resultObj); + } + + @Test + public void testRegisterResmgrByNull() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + return null; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.registerResmgr(paramsMap, new JSONObject()); + assertNotNull(resultObj); + } + + @Test + public void testUnRegisterResmgr() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(204); + rsp.setResponseJson("{\"msg\":\"success!\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); + assertNotNull(resultObj); + } + + @Test + public void testUnRegisterResmgrByNotFound() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(404); + rsp.setResponseJson("{\"msg\":\"not found!\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); + assertNotNull(resultObj); + } + + @Test + public void testUnRegisterResmgrByInvalid() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(415); + rsp.setResponseJson("{\"msg\":\"invalid parameters!\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); + assertNotNull(resultObj); + } + + @Test + public void testUnRegisterResmgrByInternalError() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(500); + rsp.setResponseJson("{\"msg\":\"internal system error!\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); + assertNotNull(resultObj); + } + + @Test + public void testUnRegisterResmgrByFail() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(203); + rsp.setResponseJson("{\"msg\":\"fail!\"}"); + return rsp; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); + assertNotNull(resultObj); + } + + @Test + public void testUnRegisterResmgrByNull() { + new MockUp() { + + @Mock + public RestfulResponse getRemoteResponse(Map paramsMap, String params) { + return null; + } + }; + Map paramsMap = getHashMap(); + ResmgrAdapter2MSBManager resmgr = new ResmgrAdapter2MSBManager(); + JSONObject resultObj = resmgr.unregisterResmgr(paramsMap); + assertNotNull(resultObj); + } + + private Map getHashMap() { + Map paramsMap = new HashMap<>(); + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + return paramsMap; + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java new file mode 100644 index 0000000..24200e8 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.adapter.impl; + +import java.io.IOException; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.adapter.impl.ResmgrAdapterMgrService; + +import mockit.Mock; +import mockit.MockUp; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 24, 2016 + */ +public class ResmgrAdapterMgrServiceTest { + + @Test + public void testRegister() { + new MockUp() { + + @Mock + public String readVimAdapterInfoFromJson() throws IOException { + return "{\"serviceName\": \"resmgr\",\"version\": \"v1\",\"url\": \"/openoapi/resmgr/v1\",\"protocol\": \"REST\",\"visualRange\": \"1\",\"nodes\": [{\"ip\": \"127.0.0.1\",\"port\": \"8080\",\"ttl\": 0}]}"; + } + }; + + ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService(); + resmgrService.register(); + } + + @Test + public void testRegisterByIOException() { + new MockUp() { + + @Mock + public String readVimAdapterInfoFromJson() throws IOException { + throw new IOException(); + } + }; + ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService(); + resmgrService.register(); + } + + @Test + public void testRegisterByNoFile() { + ResmgrAdapterMgrService resmgrService = new ResmgrAdapterMgrService(); + resmgrService.register(); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java new file mode 100644 index 0000000..8e5dcc4 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java @@ -0,0 +1,162 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.HostImpl; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.HostBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.HostDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class HostImplTest { + + @Test + public void testdeleteHostByVimId() throws ServiceException { + new MockUp() { + + @Mock + public int deleteHostByVimId(String vimId) { + return 1; + } + + }; + HostImpl hostImpl = new HostImpl(); + HostBusinessImpl hostBusiness = new HostBusinessImpl(); + hostBusiness.setHostDao(new HostDaoImpl()); + hostImpl.setHostBusiness(hostBusiness); + + assertTrue(hostImpl.deleteResByVimId("vimId") == 1); + } + @Test + public void testupdateStatusByVimId() throws ServiceException { + HostImpl hostImpl = new HostImpl(); + hostImpl.setHostBusiness(new HostBusinessImpl()); + JSONObject json = new JSONObject(); + json.put("id", "123"); + json.put("vimId", "vim123"); + new MockUp() { + + @Mock + public int updateHostByVimId(HostEntity hostEntity) throws ServiceException { + return 1; + } + }; + int result = hostImpl.updateStatusByVimId(json); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testDelete() throws ServiceException { + HostImpl hostImpl = new HostImpl(); + hostImpl.setHostBusiness(new HostBusinessImpl()); + new MockUp() { + @Mock + public int deleteHost(String id) throws ServiceException { + return 1; + } + }; + + int result = hostImpl.delete("id"); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + + } + + @Test + public void testAdd1() throws ServiceException { + HostImpl hostImpl = new HostImpl(); + hostImpl.setHostBusiness(new HostBusinessImpl()); + JSONObject json = new JSONObject(); + json.put("id", "1"); + new MockUp() { + @Mock + public int addHost(HostEntity hostEntity) throws ServiceException { + return 1; + } + + }; + int result = hostImpl.add(json); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testupdate() throws ServiceException { + HostImpl hostImpl = new HostImpl(); + hostImpl.setHostBusiness(new HostBusinessImpl()); + HostEntity hostEntity = new HostEntity(); + hostEntity.setId("123"); + new MockUp() { + @Mock + public int updateHostSelective(HostEntity hostEntity) throws ServiceException { + return 1; + } + + }; + int result = hostImpl.update(hostEntity); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testUpdateResource() throws ServiceException { + HostImpl hostImpl = new HostImpl(); + hostImpl.setHostBusiness(new HostBusinessImpl()); + JSONObject json = new JSONObject(); + json.put("id", "123"); + json.put("vimId", "vim123"); + new MockUp() { + + @Mock + public int updateHostSelective(HostEntity hostEntity) throws ServiceException { + return 1; + } + }; + int result = hostImpl.update(json); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testGetList() throws ServiceException { + Map condition = new HashMap<>(); + HostImpl hostImpl = new HostImpl(); + hostImpl.setHostBusiness(new HostBusinessImpl()); + new MockUp() { + + @Mock + public List getHosts(Map condition) { + return null; + } + }; + List result = hostImpl.getList(condition); + List exceptedResult = null; + assertEquals(exceptedResult, result); + } + +} \ No newline at end of file diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java new file mode 100644 index 0000000..803d421 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java @@ -0,0 +1,501 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.LocationImpl; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.SitesImpl; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.LocationBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.SitesBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.LocationDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class LocationImplTest { + + private LocationImpl locationImpl; + + @Before + public void setUp() throws ServiceException { + locationImpl = new LocationImpl(); + LocationBusinessImpl locationBusinessImpl = new LocationBusinessImpl(); + locationBusinessImpl.setLocationDao(new LocationDaoImpl()); + SitesImpl sitesImpl = new SitesImpl(); + sitesImpl.setSitesBusiness(new SitesBusinessImpl()); + locationImpl.setSites(sitesImpl); + locationImpl.setLocationBusiness(locationBusinessImpl); + + } + + @Test + public void testLocationImpl() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) throws ServiceException { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + + list.add(localEntity); + return null; + } + }; + new MockUp() { + + @Mock + public int addLocation(LocationEntity locationEntity) { + return 1; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "id"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "3"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + assertTrue(locationImpl.add(jsonObject) == 1); + } + + @Test + public void testLocationImplBranch() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) throws ServiceException { + List list = new ArrayList<>(); + + // list.add(localEntity); + return list; + } + }; + new MockUp() { + + @Mock + public int addLocation(LocationEntity locationEntity) { + return 1; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", ""); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "90"); + jsonObject.put("longitude", "180"); + jsonObject.put("description", "description"); + assertTrue(locationImpl.add(jsonObject) == 1); + } + + @Test + public void testLocationImplBranch1() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) throws ServiceException { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + + list.add(localEntity); + return null; + } + }; + new MockUp() { + + @Mock + public int addLocation(LocationEntity locationEntity) { + return 1; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", null); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "3"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + assertTrue(locationImpl.add(jsonObject) == 1); + } + + @Test(expected = ServiceException.class) + public void testLocationImplException() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) throws ServiceException { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + + list.add(localEntity); + return list; + } + }; + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "2"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "3"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + locationImpl.add(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testLocationImplException1() throws ServiceException { + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", null); + jsonObject.put("country", ""); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "81"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + locationImpl.add(jsonObject); + + } + + @Test(expected = ServiceException.class) + public void testLocationImplException2() throws ServiceException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", null); + jsonObject.put("country", "country"); + jsonObject.put("location", ""); + jsonObject.put("latitude", "81"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + locationImpl.add(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testLocationImplException3() throws ServiceException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", null); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", ""); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + locationImpl.add(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testLocationImplException4() throws ServiceException { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", null); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "latitude"); + jsonObject.put("longitude", ""); + jsonObject.put("description", "description"); + locationImpl.add(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testLocationImplException5() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) throws ServiceException { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + + list.add(localEntity); + return null; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "id"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "95"); + jsonObject.put("longitude", "185"); + jsonObject.put("description", "description"); + locationImpl.add(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testLocationImplException6() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) throws ServiceException { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + + list.add(localEntity); + return null; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "id"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "80"); + jsonObject.put("longitude", "185"); + jsonObject.put("description", "description"); + locationImpl.add(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testLocationImplException7() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) throws ServiceException { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + + list.add(localEntity); + return null; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "id"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "95"); + jsonObject.put("longitude", "175"); + jsonObject.put("description", "description"); + locationImpl.add(jsonObject); + } + + @Test + public void testUpdate() throws ServiceException { + new MockUp() { + + @Mock + public LocationEntity getLocation(String id) { + LocationEntity localEntity = new LocationEntity(); + localEntity.setCountry("country"); + localEntity.setLocation("location"); + + return localEntity; + } + }; + new MockUp() { + + @Mock + public int updateLocationSelective(LocationEntity locationEntity) { + return 1; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "id"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "14"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + locationImpl.update(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testUpdateException() throws ServiceException { + + new MockUp() { + + @Mock + public int updateLocationSelective(LocationEntity locationEntity) { + return 1; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "id"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "91"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + locationImpl.update(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testUpdateException1() throws ServiceException { + new MockUp() { + + @Mock + public LocationEntity getLocation(String id) { + LocationEntity localEntity = new LocationEntity(); + localEntity.setCountry("countryNew"); + localEntity.setLocation("location"); + + return localEntity; + } + }; + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "id"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "10"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + locationImpl.update(jsonObject); + } + + @Test(expected = ServiceException.class) + public void testUpdateException2() throws ServiceException { + new MockUp() { + + @Mock + public LocationEntity getLocation(String id) { + LocationEntity localEntity = new LocationEntity(); + localEntity.setCountry("country"); + localEntity.setLocation("locationNew"); + + return localEntity; + } + }; + JSONObject jsonObject = new JSONObject(); + jsonObject.put("id", "id"); + jsonObject.put("country", "country"); + jsonObject.put("location", "location"); + jsonObject.put("latitude", "10"); + jsonObject.put("longitude", "12"); + jsonObject.put("description", "description"); + locationImpl.update(jsonObject); + } + + @Test + public void testDelete() throws ServiceException { + + new MockUp() { + + @Mock + public int deleteLocation(String id) { + return 1; + } + }; + assertTrue(locationImpl.delete("location") == 1); + } + + @Test(expected = ServiceException.class) + public void testDeleteException() throws ServiceException { + + locationImpl.delete(""); + } + + @Test + public void testComputeSite() { + JSONObject total = new JSONObject(); + total.put("vcpus", "12"); + total.put("memory", "23"); + total.put("disk", "23"); + JSONObject used = new JSONObject(); + used.put("vcpus", "12"); + used.put("memory", "23"); + used.put("disk", "23"); + locationImpl.getLocationBusiness(); + + assertTrue(locationImpl.computingSite(total, used) != null); + } + + @Test + public void testGetLocation() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + localEntity.setCountry("country"); + localEntity.setLocation("locationNew"); + list.add(localEntity); + return list; + } + }; + assertTrue(locationImpl.getLocation(new HashMap<>()) != null); + } + + @Test + public void testGetLocationBranch() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + localEntity.setCountry("country"); + localEntity.setLocation("locationNew"); + return list; + } + }; + locationImpl.getLocation(new HashMap<>()); + } + + @Test + public void testGetLocationInfo() throws ServiceException { + new MockUp() { + + @Mock + public List getSites(Map condition) { + List siteList = new ArrayList<>(); + SitesEntity site = new SitesEntity(); + + siteList.add(site); + return siteList; + } + }; + + new MockUp() { + + @Mock + public JSONObject getJSONObject(String key) { + JSONObject total = new JSONObject(); + total.put("vcpus", "12"); + total.put("memory", "23"); + total.put("disk", "23"); + return total; + } + }; + List locationInfo = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + locationInfo.add(localEntity); + locationImpl.getLocationInfo(locationInfo); + } + + @Test + public void testGet() throws ServiceException { + new MockUp() { + + @Mock + public List getLocations(Map condition) throws ServiceException { + List list = new ArrayList<>(); + LocationEntity localEntity = new LocationEntity(); + + list.add(localEntity); + return null; + } + }; + locationImpl.get(new HashMap<>()); + assertTrue(locationImpl.get("id") != null); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java new file mode 100644 index 0000000..a94e994 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java @@ -0,0 +1,276 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.NetworkImpl; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.NetworkBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.NetworkDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.inf.NetworkDao; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class NetworkImplTest { + + + @Test + public void testAddBranch() throws ServiceException { + new MockUp() { + + @Mock + public NetworkEntity getNetwork(String id) { + return null; + } + + @Mock + public int addNetwork(NetworkEntity networkEntity) { + return 1; + } + }; + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + JSONObject json = new JSONObject(); + json.put("id", "id"); + json.put("name", "name"); + json.put("status", "status"); + json.put("tenant_id", "tenant_id"); + json.put("vimId", "vimId"); + json.put("vimName", "vimName"); + json.put("provider:physical_network", "provider:physical_network"); + json.put("provider:network_type", "provider:network_type"); + json.put("provider:segmentation_id", "provider:segmentation_id"); + assertTrue(networkImpl.add(json) == 1); + } + + @Test + public void testAddBranch1() throws ServiceException { + new MockUp() { + + @Mock + public NetworkEntity getNetwork(String id) { + return null; + } + + @Mock + public int addNetwork(NetworkEntity networkEntity) { + return 1; + } + }; + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + JSONObject json = new JSONObject(); + json.put("id", ""); + json.put("name", "name"); + json.put("status", "status"); + json.put("tenant_id", "tenant_id"); + json.put("vimId", "vimId"); + json.put("vimName", "vimName"); + json.put("provider:physical_network", "provider:physical_network"); + json.put("provider:network_type", "provider:network_type"); + json.put("provider:segmentation_id", "provider:segmentation_id"); + assertTrue(networkImpl.add(json) == 1); + } + + @Test(expected = ServiceException.class) + public void testAddBranch2() throws ServiceException { + new MockUp() { + @Mock + public NetworkEntity getNetwork(String id) { + return null; + } + + @Mock + public int addNetwork(NetworkEntity networkEntity) { + return 1; + } + }; + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + NetworkEntity entity = null; + networkImpl.add(entity); + + } + + + @Test + public void testDelete() throws ServiceException { + new MockUp() { + + @Mock + public int deleteNetwork(String id) { + return 1; + } + }; + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + assertTrue(networkImpl.delete("id") == 1); + } + + @Test(expected = ServiceException.class) + public void testDelete1() throws ServiceException { + + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + networkImpl.delete(""); + } + + @Test(expected = ServiceException.class) + public void testDeleteVimByIdException() throws ServiceException { + + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + networkImpl.deleteResByVimId(""); + } + + @Test + public void testDeleteVimById() throws ServiceException { + new MockUp() { + + @Mock + public int deleteNetworkByVimId(String vimId) { + return 1; + } + }; + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + assertTrue(networkImpl.deleteResByVimId("vimId") == 1); + } + + + @Test + public void testUpdate() throws ServiceException { + new MockUp() { + + @Mock + public int updateNetworkSelective(NetworkEntity networkEntity) { + return 1; + } + }; + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + + JSONObject json = new JSONObject(); + json.put("id", ""); + json.put("name", "name"); + json.put("status", "status"); + json.put("tenant_id", "tenant_id"); + json.put("vimId", "vimId"); + json.put("vimName", "vimName"); + json.put("provider:physical_network", "provider:physical_network"); + json.put("provider:network_type", "provider:network_type"); + json.put("provider:segmentation_id", "provider:segmentation_id"); + assertTrue(networkImpl.update(json)==1); + } + + + + @Test + public void testUpdateVimById() throws ServiceException { + new MockUp() { + + @Mock + public int updateNetworkByVimId(NetworkEntity NetworkEntity) { + return 1; + } + }; + NetworkImpl networkImpl = new NetworkImpl(); + NetworkBusinessImpl networkBusiness = new NetworkBusinessImpl(); + NetworkDao networkDao = new NetworkDaoImpl(); + networkBusiness.setNetworkDao(networkDao); + networkImpl.setNetworkBusiness(networkBusiness); + JSONObject json = new JSONObject(); + json.put("id", ""); + json.put("name", "name"); + json.put("status", "status"); + json.put("tenant_id", "tenant_id"); + json.put("vimId", "vimId"); + json.put("vimName", "vimName"); + json.put("provider:physical_network", "provider:physical_network"); + json.put("provider:network_type", "provider:network_type"); + json.put("provider:segmentation_id", "provider:segmentation_id"); + assertTrue(networkImpl.updateStatusByVimId(json)==1); + + } + + @Test + public void testgetList() throws ServiceException { + Map condition = new HashMap<>(); + NetworkImpl networkImpl = new NetworkImpl(); + networkImpl.setNetworkBusiness(new NetworkBusinessImpl()); + new MockUp() { + + @Mock + public List getNetworks(Map condition) { + return null; + } + }; + List result = networkImpl.getList(condition); + List exceptedResult = null; + assertEquals(exceptedResult, result); + } + @Test + public void testadd() throws ServiceException { + NetworkImpl networkImpl = new NetworkImpl(); + networkImpl.setNetworkBusiness(new NetworkBusinessImpl()); + NetworkEntity networkEntity =new NetworkEntity(); + networkEntity.setId("1"); + new MockUp() { + + @Mock + public int addNetwork(NetworkEntity networkEntity ) { + return 1; + } + }; + int result = networkImpl.add(networkEntity); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + } diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java new file mode 100644 index 0000000..ae482f4 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java @@ -0,0 +1,154 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.JsonUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.PortImpl; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.PortBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.PortDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class PortImplTest { + + @Test + public void testAddBranch() throws ServiceException { + new MockUp() { + + @Mock + public PortEntity getPort(String id) { + return null; + } + + @Mock + public int addPort(PortEntity portEntity) { + return 1; + } + }; + PortImpl portImpl = new PortImpl(); + PortBusinessImpl portBusiness = new PortBusinessImpl(); + portBusiness.setPortDao(new PortDaoImpl()); + portImpl.setPortBusiness(portBusiness); + JSONObject json = new JSONObject(); + json.put("id", ""); + json.put("name", "name"); + json.put("status", "status"); + json.put("tenant_id", "tenant_id"); + json.put("vimId", "vimId"); + json.put("vimName", "vimName"); + json.put("network_id", "network_id"); + assertTrue(portImpl.add(json) == 1); + } + + @Test(expected = ServiceException.class) + public void testAddBranch1() throws ServiceException { + + PortImpl portImpl = new PortImpl(); + PortBusinessImpl portBusiness = new PortBusinessImpl(); + portBusiness.setPortDao(new PortDaoImpl()); + portImpl.setPortBusiness(portBusiness); + PortEntity portEntity = null; + portImpl.add(portEntity); + } + + @Test(expected = ServiceException.class) + public void testUpdateException() throws ServiceException { + + PortImpl portImpl = new PortImpl(); + PortBusinessImpl portBusiness = new PortBusinessImpl(); + portBusiness.setPortDao(new PortDaoImpl()); + portImpl.setPortBusiness(portBusiness); + PortEntity portEntity = null; + portImpl.update(portEntity); + } + + @Test + public void testUpdate() throws ServiceException { + new MockUp() { + + @Mock + public int updatePortSelective(PortEntity portEntity) { + return 1; + } + + }; + PortImpl portImpl = new PortImpl(); + PortBusinessImpl portBusiness = new PortBusinessImpl(); + portBusiness.setPortDao(new PortDaoImpl()); + portImpl.setPortBusiness(portBusiness); + assertTrue(portImpl.update(new JSONObject()) == 1); + } + + @Test + public void testdelete() throws ServiceException { + new MockUp() { + + @Mock + public int deletePort(String id) { + return 1; + } + + }; + PortImpl portImpl = new PortImpl(); + PortBusinessImpl portBusiness = new PortBusinessImpl(); + portBusiness.setPortDao(new PortDaoImpl()); + portImpl.setPortBusiness(portBusiness); + + } + + @Test + public void testDeleteResByVimId() throws ServiceException { + new MockUp() { + + @Mock + public int deletePortByVimId(String vimId) { + return 1; + } + + }; + PortImpl portImpl = new PortImpl(); + PortBusinessImpl portBusiness = new PortBusinessImpl(); + portBusiness.setPortDao(new PortDaoImpl()); + portImpl.setPortBusiness(portBusiness); + assertTrue(portImpl.deleteResByVimId("vimId") == 1); + } + + @Test(expected = ServiceException.class) + public void testDeleteResByVimIdException() throws ServiceException { + PortImpl portImpl = new PortImpl(); + PortBusinessImpl portBusiness = new PortBusinessImpl(); + portBusiness.setPortDao(new PortDaoImpl()); + portImpl.setPortBusiness(portBusiness); + portImpl.deleteResByVimId(""); + } + + @Test(expected = ServiceException.class) + public void testDelete() throws ServiceException { + PortImpl portImpl = new PortImpl(); + PortBusinessImpl portBusiness = new PortBusinessImpl(); + portBusiness.setPortDao(new PortDaoImpl()); + portImpl.setPortBusiness(portBusiness); + portImpl.delete(""); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java new file mode 100644 index 0000000..95bbca7 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java @@ -0,0 +1,149 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.SitesImpl; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.SitesBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class SitesImplTest { + + + + @Test + public void testUpdate1() throws ServiceException { + SitesImpl sitesImpl = new SitesImpl(); + sitesImpl.setSitesBusiness(new SitesBusinessImpl()); + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setId("123"); + new MockUp() { + + @Mock + public int updateSiteSelective(SitesEntity sitesEntity) throws ServiceException { + return 1; + } + }; + int result = sitesImpl.update(sitesEntity); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testUpdateResource() throws ServiceException { + SitesImpl sitesImpl = new SitesImpl(); + sitesImpl.setSitesBusiness(new SitesBusinessImpl()); + JSONObject json = new JSONObject(); + json.put("id", "123"); + json.put("vimId", "vim123"); + new MockUp() { + + @Mock + public int updateSiteResource(SitesEntity sitesEntity) throws ServiceException { + return 1; + } + }; + int result = sitesImpl.updateResource(json); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testUpdateStatusByVimId() throws ServiceException { + SitesImpl sitesImpl = new SitesImpl(); + sitesImpl.setSitesBusiness(new SitesBusinessImpl()); + JSONObject json = new JSONObject(); + json.put("id", "123"); + json.put("vimId", "vim123"); + new MockUp() { + + @Mock + public int updateSiteByVimId(SitesEntity sitesEntity) throws ServiceException { + return 1; + } + }; + int result = sitesImpl.updateStatusByVimId(json); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testGetList() throws ServiceException { + Map condition = new HashMap<>(); + SitesImpl sitesImpl = new SitesImpl(); + sitesImpl.setSitesBusiness(new SitesBusinessImpl()); + new MockUp() { + + @Mock + public List getSites(Map condition) { + return null; + } + }; + List result = sitesImpl.getList(condition); + List exceptedResult = null; + assertEquals(exceptedResult, result); + } + + @Test + public void testGetNull() throws ServiceException { + Map condition = new HashMap<>(); + SitesImpl sitesImpl = new SitesImpl(); + sitesImpl.setSitesBusiness(new SitesBusinessImpl()); + new MockUp() { + + @Mock + public List getSites(Map condition) { + return null; + } + }; + SitesEntity result = sitesImpl.get(condition); + SitesEntity exceptedResult = null; + assertEquals(exceptedResult, result); + } + + @Test + public void testGet() throws ServiceException { + Map condition = new HashMap<>(); + SitesImpl sitesImpl = new SitesImpl(); + sitesImpl.setSitesBusiness(new SitesBusinessImpl()); + new MockUp() { + + @Mock + public List getSites(Map condition) { + List list = new ArrayList(); + return list; + } + }; + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setId("123"); + sitesImpl.deleteResByVimId("vimId"); + SitesEntity result = sitesImpl.get(condition); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java new file mode 100644 index 0000000..28a7344 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java @@ -0,0 +1,135 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.VimImpl; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.VimBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class VimImplTest { + + @Test + public void testAdd() throws ServiceException { + VimImpl vimImpl = new VimImpl(); + vimImpl.setVimBusiness(new VimBusinessImpl()); + new MockUp() { + + @Mock + public int addVim(String id) throws ServiceException { + return 1; + } + }; + int result = vimImpl.add("id"); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testAdd1() throws ServiceException { + VimImpl vimImpl = new VimImpl(); + vimImpl.setVimBusiness(new VimBusinessImpl()); + JSONObject json = new JSONObject(); + json.put("id", "123"); + new MockUp() { + + @Mock + public int addVim(String id) throws ServiceException { + return 1; + } + }; + int result = vimImpl.add(json); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testUpdate() throws ServiceException { + VimImpl vimImpl = new VimImpl(); + vimImpl.setVimBusiness(new VimBusinessImpl()); + JSONObject json = new JSONObject(); + json.put("id", "123"); + json.put("vimId", "vim123"); + int result = vimImpl.update(json); + int exceptedResult = 0; + assertEquals(exceptedResult, result); + } + + @Test + public void testDelete() throws ServiceException { + VimImpl vimImpl = new VimImpl(); + vimImpl.setVimBusiness(new VimBusinessImpl()); + new MockUp() { + + @Mock + public int deleteVim(String id) throws ServiceException { + return 1; + } + }; + int result = vimImpl.delete("id"); + int exceptedResult = 1; + assertEquals(exceptedResult, result); + } + + @Test + public void testGetVim() throws ServiceException { + VimImpl vimImpl = new VimImpl(); + vimImpl.setVimBusiness(new VimBusinessImpl()); + new MockUp() { + + @Mock + public VimEntity getVim(String id) { + return null; + } + }; + VimEntity result = vimImpl.getVim("id"); + VimEntity exceptedResult = null; + assertEquals(exceptedResult, result); + } + + @Test + public void testGetList() throws ServiceException { + VimImpl vimImpl = new VimImpl(); + vimImpl.setVimBusiness(new VimBusinessImpl()); + new MockUp() { + + @Mock + public List getVims() { + return null; + } + }; + List result = vimImpl.getList(); + List exceptedResult = null; + assertEquals(exceptedResult, result); + } + + @Test + public void testSetVimBusiness() throws ServiceException { + VimImpl vimImpl = new VimImpl(); + vimImpl.setVimBusiness(new VimBusinessImpl()); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java new file mode 100644 index 0000000..18ade35 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java @@ -0,0 +1,88 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.HostBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.HostDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; + +public class HostBusinessImplTest { + + @Test + public void testGetHost() { + HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); + assertTrue(hostBussinessImp.getHost("") == null); + } + + @Test + public void testGetHostBranch() { + new MockUp() { + + @Mock + public HostEntity getHost(String id) { + return new HostEntity(); + } + + }; + HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); + hostBussinessImp.setHostDao(new HostDaoImpl()); + assertTrue(hostBussinessImp.getHost("id") != null); + } + + @Test(expected = ServiceException.class) + public void testDelete() throws ServiceException { + HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); + hostBussinessImp.deleteHost(""); + } + + @Test(expected = ServiceException.class) + public void testUpdateHost() throws ServiceException { + HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); + hostBussinessImp.updateHost(null); + } + + @Test(expected = ServiceException.class) + public void testDeleteHostByVimId() throws ServiceException { + HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); + hostBussinessImp.deleteHostByVimId(""); + } + + @Test(expected = ServiceException.class) + public void testUpdateHostByVimId() throws ServiceException { + HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); + hostBussinessImp.updateHostByVimId(null); + } + + @Test(expected = ServiceException.class) + public void testAddHost() throws ServiceException { + HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); + hostBussinessImp.addHost(null); + } + + @Test(expected = ServiceException.class) + public void testAddHostSelective() throws ServiceException { + HostBusinessImpl hostBussinessImp = new HostBusinessImpl(); + hostBussinessImp.addHostSelective(null); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java new file mode 100644 index 0000000..c5c9d78 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java @@ -0,0 +1,72 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.LimitsBusinessImpl; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.HttpRest; +import org.openo.baseservice.roa.util.restclient.RestfulOptions; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class LimitsBusinessImplTest { + + private LimitsBusinessImpl limitsBusinessImpl; + + @Before + public void setUp() throws ServiceException { + limitsBusinessImpl = new LimitsBusinessImpl(); + } + + @Test + public void testGetCpuLimits() throws ServiceException { + new MockUp() { + + @Mock + public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option) + throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(200); + return rsp; + } + }; + JSONObject paramJson = new JSONObject(); + paramJson.put("vimId", "vimId"); + paramJson.put("tenantId", "tenantId"); + } + + @Test + public void testgetLimits() throws ServiceException { + new MockUp() { + + @Mock + public RestfulResponse get(String servicePath, RestfulParametes restParametes, RestfulOptions option) + throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(200); + return rsp; + } + + }; + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java new file mode 100644 index 0000000..70ba66e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java @@ -0,0 +1,220 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.LocationBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.LocationDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; + +public class LocationBusinessImplTest { + + private LocationBusinessImpl locationBusinessImpl; + + @Before + public void setUp() throws ServiceException { + locationBusinessImpl = new LocationBusinessImpl(); + locationBusinessImpl.setLocationDao(new LocationDaoImpl()); + } + + @Test + public void testGet() throws ServiceException { + new MockUp() { + + @Mock + public LocationEntity getLocation(String id) { + LocationEntity localEntity = new LocationEntity(); + localEntity.setCountry("country"); + localEntity.setLocation("location"); + + return localEntity; + } + }; + assertTrue(locationBusinessImpl.getLocation("id") != null); + } + + @Test + public void testGetBranch() throws ServiceException { + + assertTrue(locationBusinessImpl.getLocation("") == null); + } + + @Test(expected = ServiceException.class) + public void testAddLocationSelectiveExceptio() throws ServiceException { + locationBusinessImpl.addLocationSelective(null); + } + + @Test + public void testAddLocationSelective() throws ServiceException { + new MockUp() { + + @Mock + public int addLocationSelective(LocationEntity locationEntity) { + return 1; + } + }; + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setCountry("country"); + locationEntity.setDescription("description"); + locationEntity.setId("id"); + locationEntity.setLatitude("1"); + locationEntity.setLongitude("12"); + locationEntity.setLocation("location"); + locationBusinessImpl.addLocationSelective(locationEntity); + } + + @Test + public void testAddLocationSelectiveBranch() throws ServiceException { + new MockUp() { + + @Mock + public int addLocationSelective(LocationEntity locationEntity) { + return 1; + } + }; + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setCountry("country"); + locationEntity.setDescription("description"); + locationEntity.setId(""); + locationEntity.setLatitude("1"); + locationEntity.setLongitude("12"); + locationEntity.setLocation("location"); + locationBusinessImpl.addLocationSelective(locationEntity); + } + + @Test + public void testAddLocationSelectiveBranch1() throws ServiceException { + new MockUp() { + + @Mock + public int addLocationSelective(LocationEntity locationEntity) { + return 1; + } + }; + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setCountry("country"); + locationEntity.setDescription("description"); + locationEntity.setId(null); + locationEntity.setLatitude("1"); + locationEntity.setLongitude("12"); + locationEntity.setLocation("location"); + locationBusinessImpl.addLocationSelective(locationEntity); + } + + @Test(expected = ServiceException.class) + public void testAddLocationSelectiveException1() throws ServiceException { + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setCountry(""); + locationEntity.setDescription("description"); + locationEntity.setId("id"); + locationEntity.setLatitude("1"); + locationEntity.setLongitude("12"); + locationEntity.setLocation("location"); + locationBusinessImpl.addLocationSelective(locationEntity); + } + + @Test(expected = ServiceException.class) + public void testAddLocationSelectiveException2() throws ServiceException { + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setCountry("country"); + locationEntity.setDescription("description"); + locationEntity.setId("id"); + locationEntity.setLatitude("1"); + locationEntity.setLongitude("12"); + locationEntity.setLocation(""); + locationBusinessImpl.addLocationSelective(locationEntity); + } + + @Test(expected = ServiceException.class) + public void testAddLocationSelectiveException3() throws ServiceException { + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setCountry("country"); + locationEntity.setDescription("description"); + locationEntity.setId("id"); + locationEntity.setLatitude(""); + locationEntity.setLongitude("12"); + locationEntity.setLocation("location"); + locationBusinessImpl.addLocationSelective(locationEntity); + } + + @Test(expected = ServiceException.class) + public void testAddLocationSelectiveException4() throws ServiceException { + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setCountry("country"); + locationEntity.setDescription("description"); + locationEntity.setId("id"); + locationEntity.setLatitude("1"); + locationEntity.setLongitude(""); + locationEntity.setLocation("location"); + locationBusinessImpl.addLocationSelective(locationEntity); + } + + @Test(expected = ServiceException.class) + public void testUpdateLocationSelective() throws ServiceException { + locationBusinessImpl.updateLocationSelective(null); + } + + @Test(expected = ServiceException.class) + public void testAddLocation() throws ServiceException { + locationBusinessImpl.addLocation(null); + } + + @Test + public void testUpdateLocation() throws ServiceException { + new MockUp() { + + @Mock + public int updateLocation(LocationEntity locationEntity) { + return 1; + } + }; + locationBusinessImpl.getLocationDao(); + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setLatitude("1"); + locationEntity.setLongitude("2"); + locationBusinessImpl.updateLocation(locationEntity); + } + + @Test(expected = ServiceException.class) + public void testUpdateLocationException() throws ServiceException { + new MockUp() { + + @Mock + public int updateLocation(LocationEntity locationEntity) { + return 1; + } + }; + locationBusinessImpl.getLocationDao(); + LocationEntity locationEntity = new LocationEntity(); + locationEntity.setLatitude("100"); + locationEntity.setLongitude("2"); + locationBusinessImpl.updateLocation(locationEntity); + } + + @Test(expected = ServiceException.class) + public void testUpdateLocationException1() throws ServiceException { + locationBusinessImpl.getLocationDao(); + locationBusinessImpl.updateLocation(null); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java new file mode 100644 index 0000000..ce33e8f --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java @@ -0,0 +1,409 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.SitesBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.SitesDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 2016年8月16日 + */ +public class SitesBusinessImplTest { + + private SitesBusinessImpl sitesBusinessImpl; + + @Before + public void setUp() { + sitesBusinessImpl = new SitesBusinessImpl(); + sitesBusinessImpl.setSitesDao(new SitesDaoImpl()); + } + + @Test + public void testGetSitesIdIsNull() throws ServiceException { + try { + sitesBusinessImpl.getSite(null); + } catch(ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testGetSite() throws ServiceException { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setId("123"); + new MockUp() { + + @Mock + public SitesEntity getSite(String id) { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setId("123"); + return sitesEntity; + } + }; + SitesEntity result = sitesBusinessImpl.getSite("id"); + SitesEntity expectedResult = sitesEntity; + assertEquals(expectedResult.toString(), result.toString()); + } + + @Test + public void testGetSites() throws ServiceException { + Map condition = new HashMap(); + SitesBusinessImpl sitesBusinessImpl = new SitesBusinessImpl(); + sitesBusinessImpl.setSitesDao(new SitesDaoImpl()); + new MockUp() { + + @Mock + public List getSites(Map condition) { + return null; + } + }; + List result = sitesBusinessImpl.getSites(condition); + assertNull(result); + } + + @Test + public void testDeleteSiteEmpty() throws ServiceException { + SitesBusinessImpl sitesBusinessImpl = new SitesBusinessImpl(); + sitesBusinessImpl.setSitesDao(new SitesDaoImpl()); + try { + sitesBusinessImpl.deleteSite(""); + } catch(ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testDeleteSite() throws ServiceException { + new MockUp() { + + @Mock + public SitesEntity getSite(String id) { + return null; + } + + @Mock + public int deleteSite(String id) { + return 1; + } + }; + int result = sitesBusinessImpl.deleteSite("007"); + int expectedResult = 1; + assertEquals(expectedResult, result); + } + + @Test + public void testAddSiteSitesEntityIsNull() throws ServiceException { + try { + sitesBusinessImpl.addSite(null); + } catch(ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testCheckSiteExceptions() throws ServiceException { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setCountry("country"); + sitesEntity.setId("id"); + sitesEntity.setLocation("location"); + sitesEntity.setName("name"); + sitesEntity.setStatus("siteStatus"); + sitesEntity.setTotalCPU("12"); + sitesEntity.setTotalDisk("12"); + sitesEntity.setTotalMemory("134"); + sitesEntity.setUsedCPU("12"); + sitesEntity.setUsedDisk("23"); + sitesEntity.setUsedMemory("10"); + sitesEntity.setVimId("siteVimId"); + sitesEntity.setVimName("siteVimName"); + new MockUp() { + + int count1 = 0; + + @Mock + public SitesEntity getSite(String id) { + return null; + } + + @Mock + public List getSites(Map condition) { + if(count1 == 0) { + count1 += 1; + return null; + } + return new ArrayList(); + + } + }; + new MockUp() { + + @Mock + public boolean checkResource(SitesEntity siteEntity) { + return false; + } + }; + try { + sitesBusinessImpl.addSite(sitesEntity); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testCheckSiteExceptions1() throws ServiceException { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setCountry("country"); + sitesEntity.setId("id"); + sitesEntity.setLocation("location"); + sitesEntity.setName("name"); + sitesEntity.setStatus("siteStatus"); + sitesEntity.setTotalCPU("12"); + sitesEntity.setTotalDisk("12"); + sitesEntity.setTotalMemory("134"); + sitesEntity.setUsedCPU("12"); + sitesEntity.setUsedDisk("23"); + sitesEntity.setUsedMemory("10"); + sitesEntity.setVimId("siteVimId"); + sitesEntity.setVimName("siteVimName"); + new MockUp() { + + int count1 = 0; + + @Mock + public SitesEntity getSite(String id) { + return null; + } + + @Mock + public List getSites(Map condition) { + + return null; + + } + }; + new MockUp() { + + @Mock + public boolean checkResource(SitesEntity siteEntity) { + return false; + } + }; + try { + sitesBusinessImpl.addSite(sitesEntity); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testCheckSiteExceptions2() throws ServiceException { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setCountry(""); + sitesEntity.setId("id"); + sitesEntity.setLocation(""); + sitesEntity.setName(""); + sitesEntity.setStatus("siteStatus"); + sitesEntity.setTotalCPU("12"); + sitesEntity.setTotalDisk("12"); + sitesEntity.setTotalMemory("134"); + sitesEntity.setUsedCPU("12"); + sitesEntity.setUsedDisk("23"); + sitesEntity.setUsedMemory("10"); + sitesEntity.setVimId("siteVimId"); + sitesEntity.setVimName("siteVimName"); + new MockUp() { + + int count1 = 0; + + @Mock + public SitesEntity getSite(String id) { + return null; + } + + @Mock + public List getSites(Map condition) { + + return null; + + } + }; + new MockUp() { + + @Mock + public boolean checkResource(SitesEntity siteEntity) { + return false; + } + }; + try { + sitesBusinessImpl.addSite(sitesEntity); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testCheckSiteNameExceptions() throws ServiceException { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setId("123"); + sitesEntity.setCountry("china"); + sitesEntity.setName("openstack"); + sitesEntity.setLocation("xian"); + new MockUp() { + + @Mock + public SitesEntity getSite(String id) { + return null; + } + + @Mock + public List getSites(Map condition) { + List list = new ArrayList(); + list.add(new SitesEntity()); + return list; + + } + }; + try { + sitesBusinessImpl.addSite(sitesEntity); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testCheckIdExceptions() throws ServiceException { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setId("123"); + sitesEntity.setCountry("china"); + sitesEntity.setName("openstack"); + sitesEntity.setLocation("xian"); + new MockUp() { + + @Mock + public SitesEntity getSite(String id) { + return new SitesEntity(); + } + }; + try { + sitesBusinessImpl.addSite(sitesEntity); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testAddSiteSelectiveSitesEntityIsNull() throws ServiceException { + try { + sitesBusinessImpl.addSiteSelective(null); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testUpdateSiteSelectiveSitesEntityIsNull() throws ServiceException { + try { + sitesBusinessImpl.updateSiteSelective(null); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testUpdateSiteSitesEntityIsNull() throws ServiceException { + try { + sitesBusinessImpl.updateSite(null); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testUpdateSiteByVimIdSitesEntityIsNull() throws ServiceException { + try { + sitesBusinessImpl.updateSiteByVimId(null); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testUpdateSiteByVimId() throws ServiceException { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setCountry("china"); + sitesEntity.setName("openstack"); + sitesEntity.setLocation("xian"); + new MockUp() { + + @Mock + public int updateSiteByVimId(SitesEntity sitesEntity) { + return 1; + } + }; + int result = sitesBusinessImpl.updateSiteByVimId(sitesEntity); + int expectedResult = 1; + assertEquals(expectedResult, result); + } + + @Test + public void testUpdateSiteResourceSitesEntityIsNull() throws ServiceException { + try { + sitesBusinessImpl.updateSiteResource(null); + } catch(ServiceException se) { + assertTrue(true); + } + } + + @Test + public void testUpdateSiteResource() throws ServiceException { + SitesEntity sitesEntity = new SitesEntity(); + sitesEntity.setCountry("china"); + sitesEntity.setName("openstack"); + sitesEntity.setLocation("xian"); + new MockUp() { + + @Mock + public int updateSiteSelective(SitesEntity sitesEntity) { + return 1; + } + }; + int result = sitesBusinessImpl.updateSiteResource(sitesEntity); + int expectedResult = 1; + assertEquals(expectedResult, result); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java new file mode 100644 index 0000000..c36aaf2 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java @@ -0,0 +1,178 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.business.impl; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.util.List; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.VimBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.VimDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 2016年8月18日 + */ +public class VimBusinessImplTest { + + @Test + public void testGetVimIdIsNull() { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + VimEntity result = vimBusinessImpl.getVim(null); + VimEntity expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testGetVim() { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + VimEntity vimEntity = new VimEntity(); + vimEntity.setId("123"); + new MockUp() { + + @Mock + public VimEntity getVim(String id) { + VimEntity vimEntity = new VimEntity(); + vimEntity.setId("123"); + return vimEntity; + } + }; + VimEntity result = vimBusinessImpl.getVim("id"); + VimEntity expectedResult = vimEntity; + assertEquals(expectedResult.toString(), result.toString()); + } + + @Test + public void testGetVims() throws ServiceException { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + new MockUp() { + + @Mock + public List getVims() { + return null; + } + }; + List result = vimBusinessImpl.getVims(); + List expectedResult = null; + assertEquals(expectedResult, result); + } + + @Test + public void testDeleteVimEmpty() throws ServiceException { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + try { + vimBusinessImpl.deleteVim(""); + } catch (ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testDeleteVim() throws ServiceException { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + new MockUp() { + + @Mock + public int deleteVim(String id) { + return 1; + } + }; + int result = vimBusinessImpl.deleteVim("xian"); + int expectedResult = 1; + assertEquals(expectedResult, result); + } + + @Test + public void testAddVimExceptions() throws ServiceException { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + try { + vimBusinessImpl.addVim(null); + } catch (ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testAddVimExceptions1() throws ServiceException { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + new MockUp() { + + @Mock + public VimEntity getVim(String id) { + return new VimEntity(); + } + }; + try { + vimBusinessImpl.addVim("id"); + } catch (ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testAddVimExceptions2() throws ServiceException { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + VimEntity vimEntity = new VimEntity(); + vimEntity.setId("123"); + try { + vimBusinessImpl.addVim(""); + } catch (ServiceException e) { + assertTrue(true); + } + } + + @Test + public void testAddVim() throws ServiceException { + VimBusinessImpl vimBusinessImpl = new VimBusinessImpl(); + vimBusinessImpl.setVimDao(new VimDaoImpl()); + new MockUp() { + + @Mock + public VimEntity getVim(String id) { + return null; + } + + @Mock + public int addVim(VimEntity vimEntity) { + return 1; + } + }; + int result = vimBusinessImpl.addVim("123"); + int expectedResult = 1; + assertEquals(expectedResult, result); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java new file mode 100644 index 0000000..9ec2c8d --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java @@ -0,0 +1,157 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.HostDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.HostMapper; +import org.onap.vfc.nfvo.resmanagement.service.mapper.NetworkMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Expectations; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; + +public class HostDaoImplTest { + @Mocked + HostMapper mapper; + @Test + public void testdeleteHost() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + HostDaoImpl impl = new HostDaoImpl(); + assertEquals(0, impl.deleteHost("123")); + } + + @Test + public void testdeleteHostByVimId() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + HostDaoImpl impl = new HostDaoImpl(); + assertEquals(0, impl.deleteHostByVimId("123")); + } + + @Test + public void testaddHost() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + HostDaoImpl impl = new HostDaoImpl(); + HostEntity hostEntity =new HostEntity(); + hostEntity.setId("1"); + assertEquals(0, impl.addHost(hostEntity)); + + } + + @Test + public void testaddHostSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + HostDaoImpl impl = new HostDaoImpl(); + HostEntity hostEntity =new HostEntity(); + hostEntity.setId("1"); + assertEquals(0, impl.addHostSelective(hostEntity)); + + } + + @Test + public void testupdateHostSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + HostDaoImpl impl = new HostDaoImpl(); + HostEntity hostEntity =new HostEntity(); + hostEntity.setId("1"); + assertEquals(0, impl.updateHostSelective(hostEntity)); + + } + + @Test + public void testupdateHost() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + HostDaoImpl impl = new HostDaoImpl(); + HostEntity hostEntity =new HostEntity(); + hostEntity.setId("1"); + assertEquals(0, impl.updateHost(hostEntity)); + + } + + @Test + public void testupdateHostByVimId() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + HostDaoImpl impl = new HostDaoImpl(); + HostEntity hostEntity =new HostEntity(); + hostEntity.setId("1"); + assertEquals(0, impl.updateHostByVimId(hostEntity)); + + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java new file mode 100644 index 0000000..908dd5c --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java @@ -0,0 +1,88 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.LocationDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.NetworkDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.LocationMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; + +public class LocationDaoImplTest { + LocationMapper mapper; + @Test + public void testaddHost() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + LocationDaoImpl impl = new LocationDaoImpl(); + LocationEntity locationEntity =new LocationEntity(); + locationEntity.setId("locationEntity"); + + + } + + @Test + public void testaddLocationSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + LocationDaoImpl impl = new LocationDaoImpl(); + LocationEntity locationEntity =new LocationEntity(); + locationEntity.setId("1"); + + + } + + @Test + public void testupdateNetwork() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + NetworkDaoImpl impl = new NetworkDaoImpl(); + NetworkEntity networkEntity =new NetworkEntity(); + networkEntity.setId("1"); + + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java new file mode 100644 index 0000000..88117fa --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java @@ -0,0 +1,155 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.NetworkDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.NetworkMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Expectations; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; + +public class NetworkDaoImplTest { + @Mocked + NetworkMapper mapper; + @Test + public void testdeleteNetwork() throws ServiceException { + + new Expectations() {{ + mapper.deleteNetwork("123"); + }}; + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + NetworkDaoImpl impl = new NetworkDaoImpl(); + assertEquals(0, impl.deleteNetwork("123")); + + } + @Test + public void testdeleteNetworkByVimId() throws ServiceException { + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + NetworkDaoImpl impl = new NetworkDaoImpl(); + assertEquals(0, impl.deleteNetworkByVimId("123")); + + } + @Test + public void testaddNetwork() throws ServiceException { + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + NetworkDaoImpl impl = new NetworkDaoImpl(); + NetworkEntity networkEntity =new NetworkEntity(); + networkEntity.setId("1"); + assertEquals(0, impl.addNetwork(networkEntity)); + + } + + @Test + public void testaddNetworkSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + NetworkDaoImpl impl = new NetworkDaoImpl(); + NetworkEntity networkEntity =new NetworkEntity(); + networkEntity.setId("1"); + assertEquals(0, impl.addNetworkSelective(networkEntity)); + } + @Test + public void testupdateNetworkSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + NetworkDaoImpl impl = new NetworkDaoImpl(); + NetworkEntity networkEntity =new NetworkEntity(); + networkEntity.setId("1"); + assertEquals(0, impl.updateNetworkSelective(networkEntity)); + } + @Test + public void testupdateNetwork() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + NetworkDaoImpl impl = new NetworkDaoImpl(); + NetworkEntity networkEntity =new NetworkEntity(); + networkEntity.setId("1"); + assertEquals(0, impl.updateNetwork(networkEntity)); + + } + @Test + public void testupdateNetworkByVimId() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + NetworkDaoImpl impl = new NetworkDaoImpl(); + NetworkEntity networkEntity =new NetworkEntity(); + networkEntity.setId("1"); + assertEquals(0, impl.updateNetworkByVimId(networkEntity)); + + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java new file mode 100644 index 0000000..efb633c --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java @@ -0,0 +1,160 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.PortDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.NetworkMapper; +import org.onap.vfc.nfvo.resmanagement.service.mapper.PortMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Expectations; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; + +public class PortDaoImplTest { + @Mocked + PortMapper mapper; + + + @Test + public void testdeletePort() throws ServiceException { + + new Expectations() {{ + mapper.deletePort("123"); + }}; + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + PortDaoImpl impl = new PortDaoImpl(); + assertEquals(0, impl.deletePort("123")); + + + } + @Test + public void testdeletePortByVimId() throws ServiceException { + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + PortDaoImpl impl = new PortDaoImpl(); + assertEquals(0, impl.deletePortByVimId("123")); + + } + + @Test + public void testaddPort() throws ServiceException { + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + PortDaoImpl impl = new PortDaoImpl(); + PortEntity portEntity =new PortEntity(); + portEntity.setId("1"); + assertEquals(0, impl.addPort(portEntity)); + + } + + @Test + public void testaddPortSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + PortDaoImpl impl = new PortDaoImpl(); + PortEntity portEntity =new PortEntity(); + portEntity.setId("1"); + assertEquals(0, impl.addPortSelective(portEntity)); + + } + + @Test + public void testupdatePortSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + PortDaoImpl impl = new PortDaoImpl(); + PortEntity portEntity =new PortEntity(); + portEntity.setId("1"); + assertEquals(0, impl.updatePortSelective(portEntity)); + } + @Test + public void testupdatePort() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + PortDaoImpl impl = new PortDaoImpl(); + PortEntity portEntity =new PortEntity(); + portEntity.setId("1"); + assertEquals(0, impl.updatePort(portEntity)); + + } + @Test + public void testupdatePortByVimId() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + PortDaoImpl impl = new PortDaoImpl(); + PortEntity portEntity =new PortEntity(); + portEntity.setId("1"); + assertEquals(0, impl.updatePortByVimId(portEntity)); + + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java new file mode 100644 index 0000000..0944936 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java @@ -0,0 +1,134 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.SitesDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.NetworkMapper; +import org.onap.vfc.nfvo.resmanagement.service.mapper.SitesMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Expectations; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; + +public class SitesDaoImplTest { + @Mocked + SitesMapper mapper; + @Test + public void testdeleteSite() throws ServiceException { + + new Expectations() {{ + mapper.deleteSite("123"); + }}; + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + SitesDaoImpl impl = new SitesDaoImpl(); + assertEquals(0, impl.deleteSite("123")); + } + @Test + public void testaddSite() throws ServiceException { + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + SitesDaoImpl impl = new SitesDaoImpl(); + SitesEntity sitesEntity =new SitesEntity(); + sitesEntity.setId("1"); + assertEquals(0, impl.addSite(sitesEntity)); + } + @Test + public void testaddSiteSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + SitesDaoImpl impl = new SitesDaoImpl(); + SitesEntity sitesEntity =new SitesEntity(); + sitesEntity.setId("1"); + assertEquals(0, impl.addSiteSelective(sitesEntity)); + } + @Test + public void testupdateSiteSelective() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + SitesDaoImpl impl = new SitesDaoImpl(); + SitesEntity sitesEntity =new SitesEntity(); + sitesEntity.setId("1"); + assertEquals(0, impl.updateSiteSelective(sitesEntity)); + } + @Test + public void testupdateNetwork() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + SitesDaoImpl impl = new SitesDaoImpl(); + SitesEntity sitesEntity =new SitesEntity(); + sitesEntity.setId("1"); + assertEquals(0, impl.updateSite(sitesEntity)); + } + @Test + public void testupdateSiteByVimId() throws ServiceException { + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + SitesDaoImpl impl = new SitesDaoImpl(); + SitesEntity sitesEntity =new SitesEntity(); + sitesEntity.setId("1"); + assertEquals(0, impl.updateSiteByVimId(sitesEntity)); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java new file mode 100644 index 0000000..8adf0c8 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java @@ -0,0 +1,79 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.VimDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VimMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Expectations; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; + +public class VimDaoImplTest { + + @Mocked + VimMapper mapper; + + + @Test + public void testdeleteVim() throws ServiceException { + + new Expectations() {{ + mapper.deleteVim("123"); + }}; + + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + VimDaoImpl impl = new VimDaoImpl(); + assertEquals(0, impl.deleteVim("123")); + + + } + + @Test + public void testaddVim() throws ServiceException { + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + VimDaoImpl impl = new VimDaoImpl(); + VimEntity vimEntity =new VimEntity(); + vimEntity.setId("1"); + assertEquals(0, impl.addVim(vimEntity)); + + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java new file mode 100644 index 0000000..fa7fb54 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java @@ -0,0 +1,51 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.VirtualLinkDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.SitesMapper; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VirtualLinkMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; + +public class VirtualLinkDaoImplTest { + @Mocked + VirtualLinkMapper mapper; + @Test + public void testdeleteVlById() throws ServiceException { + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + VirtualLinkDaoImpl impl = new VirtualLinkDaoImpl(); + + assertEquals(0, impl.deleteVlById("1")); + + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java new file mode 100644 index 0000000..07ac61c --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.onap.vfc.nfvo.resmanagement.service.dao.impl.VmDaoImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; +import org.onap.vfc.nfvo.resmanagement.service.mapper.SitesMapper; +import org.onap.vfc.nfvo.resmanagement.service.mapper.VmMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; + +public class VmDaoImplTest { + @Mocked + VmMapper mapper; + @Test + public void TestaddVm() throws ServiceException { + new MockUp() { + + @Mock + public T getMapperManager(Class type) { + return (T) mapper; + + } + }; + VmDaoImpl impl = new VmDaoImpl(); + VmEntity vmEntity =new VmEntity(); + vmEntity.setVmId("1"); + //assertEquals(0, impl.addVm(vmEntity)); + + } + + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/HostEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/HostEntityTest.java new file mode 100644 index 0000000..cbbccff --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/HostEntityTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; + +import net.sf.json.JSONObject; + +public class HostEntityTest { + private HostEntity hostEntity; + + @Before + public void setUp() { + hostEntity = new HostEntity(); + } + + @Test + public void testHostEntity() { + assertTrue(hostEntity.toString() != null); + assertTrue(HostEntity.toEntity(new JSONObject()) != null); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/LocationEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/LocationEntityTest.java new file mode 100644 index 0000000..576101a --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/LocationEntityTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; + +import net.sf.json.JSONObject; + +public class LocationEntityTest { + + private LocationEntity locationEntity; + + @Before + public void setUp() { + locationEntity = new LocationEntity(); + } + + @Test + public void testLocationEntity() { + locationEntity.setCountry("country"); + locationEntity.setDescription("description"); + locationEntity.setLocation("location"); + locationEntity.setLatitude("latitude"); + locationEntity.setLongitude("longitude"); + assertTrue(locationEntity.toString() != null); + assertTrue(LocationEntity.toEntity(new JSONObject()) != null); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/NetworkEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/NetworkEntityTest.java new file mode 100644 index 0000000..4ce309b --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/NetworkEntityTest.java @@ -0,0 +1,50 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; + +import net.sf.json.JSONObject; + +public class NetworkEntityTest { + + private NetworkEntity networkEntity; + + @Before + public void setUp() { + networkEntity = new NetworkEntity(); + } + + @Test + public void testSetId() { + networkEntity.setId("123"); + networkEntity.setName("name"); + networkEntity.setNetworkType("networkType"); + networkEntity.setPhysicalNetwork("physicalNetwork"); + networkEntity.setSegmentationId("segmentationId"); + networkEntity.setStatus("networkStatus"); + networkEntity.setTenantId("tenantId"); + networkEntity.setVimId("networkVimId"); + networkEntity.setVimName("networkVimName"); + assertTrue(networkEntity.toString() != null); + assertTrue(NetworkEntity.toEntity(new JSONObject()) != null); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/PortEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/PortEntityTest.java new file mode 100644 index 0000000..6eef4c9 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/PortEntityTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; + +import net.sf.json.JSONObject; + +public class PortEntityTest { + + private PortEntity portEntity; + + @Before + public void setUp() { + portEntity = new PortEntity(); + } + + @Test + public void testPortEntiry() { + portEntity.setId("id:"); + portEntity.setName("name"); + portEntity.setNetworkId("networkId"); + portEntity.setTenantId("tenantId"); + portEntity.setVimId("vimID"); + portEntity.setVimName("vimName"); + assertTrue(portEntity.toString() != null); + assertTrue(PortEntity.toEntity(new JSONObject()) != null); + + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/SitesEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/SitesEntityTest.java new file mode 100644 index 0000000..6d22897 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/SitesEntityTest.java @@ -0,0 +1,111 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; + +import net.sf.json.JSONObject; + +public class SitesEntityTest { + + private SitesEntity sitesEntity; + + @Before + public void setUp() { + sitesEntity = new SitesEntity(); + } + + @Test + public void testSitesEntity() { + sitesEntity.setCountry("country"); + sitesEntity.setId("id"); + sitesEntity.setLocation("location"); + sitesEntity.setName("name"); + sitesEntity.setStatus("siteStatus"); + sitesEntity.setTotalCPU("12"); + sitesEntity.setTotalDisk("12"); + sitesEntity.setTotalMemory("134"); + sitesEntity.setUsedCPU("12"); + sitesEntity.setUsedDisk("23"); + sitesEntity.setUsedMemory("10"); + sitesEntity.setVimId("siteVimId"); + sitesEntity.setVimName("siteVimName"); + assertTrue(sitesEntity.toString() != null); + assertTrue(SitesEntity.toEntity(new JSONObject()) != null); + SitesEntity.checkResource(sitesEntity); + SitesEntity.checkResourceIsZero(sitesEntity); + } + + @Test + public void testSitesEntityBranch() { + sitesEntity.setCountry("country"); + sitesEntity.setId("id"); + sitesEntity.setLocation("location"); + sitesEntity.setName("name"); + sitesEntity.setStatus("siteStatus"); + sitesEntity.setTotalCPU(""); + sitesEntity.setTotalDisk(""); + sitesEntity.setTotalMemory(""); + sitesEntity.setUsedCPU(""); + sitesEntity.setUsedDisk(""); + sitesEntity.setUsedMemory(""); + sitesEntity.setVimId("siteVimId"); + sitesEntity.setVimName("siteVimName"); + SitesEntity.checkResource(sitesEntity); + SitesEntity.checkResourceIsZero(sitesEntity); + } + + @Test + public void testSitesEntityBranch1() { + sitesEntity.setCountry("country"); + sitesEntity.setId("id"); + sitesEntity.setLocation("location"); + sitesEntity.setName("name"); + sitesEntity.setStatus("siteStatus"); + sitesEntity.setTotalCPU("s"); + sitesEntity.setTotalDisk(""); + sitesEntity.setTotalMemory("s"); + sitesEntity.setUsedCPU("s"); + sitesEntity.setUsedDisk("s"); + sitesEntity.setUsedMemory("s"); + sitesEntity.setVimId("siteVimId"); + sitesEntity.setVimName("siteVimName"); + SitesEntity.checkResource(sitesEntity); + } + + @Test + public void testSitesEntityBranch2() { + sitesEntity.setCountry("country"); + sitesEntity.setId("id"); + sitesEntity.setLocation("location"); + sitesEntity.setName("name"); + sitesEntity.setStatus("siteStatus"); + sitesEntity.setTotalCPU("23"); + sitesEntity.setTotalDisk(""); + sitesEntity.setTotalMemory("s"); + sitesEntity.setUsedCPU("1"); + sitesEntity.setUsedDisk("s"); + sitesEntity.setUsedMemory("s"); + sitesEntity.setVimId("siteVimId"); + sitesEntity.setVimName("siteVimName"); + SitesEntity.checkResource(sitesEntity); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/VimEntityTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/VimEntityTest.java new file mode 100644 index 0000000..e204c0f --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/entity/VimEntityTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2016 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.entity.VimEntity; + +import net.sf.json.JSONObject; + +public class VimEntityTest { + + private VimEntity vimEntity; + + @Before + public void setUp() { + vimEntity = new VimEntity(); + } + + @Test + public void testSitesEntity() { + vimEntity.setId("id"); + vimEntity.setName("name"); + assertTrue(vimEntity.toString() != null); + assertTrue(VimEntity.toEntity(new JSONObject()) != null); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java new file mode 100644 index 0000000..952ca90 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java @@ -0,0 +1,167 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.group.impl.GrantResServiceImpl; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.GrantResService; +import org.onap.vfc.nfvo.resmanagement.service.rest.GrantResourseRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Mar 16, 2017 + */ +public class GrantResourseRoaTest { + + private GrantResourseRoa roa; + + private GrantResService grantResService; + + @Before + public void setUp() { + roa = new GrantResourseRoa(); + grantResService = new GrantResServiceImpl(); + roa.setGrantResService(grantResService); + } + + @Test + public void testGrantResource() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject grantResource(JSONObject object) throws ServiceException { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.grantResource(mock); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testGrantResourceByNull() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.grantResource(mock); + assertNotNull(result); + } + + @Test + public void testGrantResourceFail() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject grantResource(JSONObject object) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.grantResource(mock); + assertNotNull(result); + } + + @Test + public void testGrantResourceReal() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject grantResourceReal(JSONObject object) throws ServiceException { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.grantResourceReal(mock); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testGrantResourceRealByNull() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + roa.grantResourceReal(mock); + } + + @Test + public void testGrantResourceRealFail() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject grantResourceReal(JSONObject object) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.grantResourceReal(mock); + assertNotNull(result); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/HostRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/HostRoaTest.java new file mode 100644 index 0000000..72e79d7 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/HostRoaTest.java @@ -0,0 +1,201 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.HostImpl; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Host; +import org.onap.vfc.nfvo.resmanagement.service.entity.HostEntity; +import org.onap.vfc.nfvo.resmanagement.service.rest.HostRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class HostRoaTest { + + private HostRoa roa; + + private Host host; + + @Before + public void setUp() { + roa = new HostRoa(); + host = new HostImpl(); + roa.setHost(host); + } + + @Test + public void testGetHosts() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getHosts(mock); + assertNotNull(result); + } + + @Test + public void testGetHost() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getHost(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddHost() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int add(JSONObject jsonObject) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addHost(mock); + assertNotNull(result); + } + + @Test + public void testAddHostByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int add(JSONObject jsonObject) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addHost(mock); + assertNotNull(result); + } + + @Test + public void testDeleteHost() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteHost(mock, "id"); + assertNotNull(result); + } + + @Test + public void testDeleteHostByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteHost(mock, "id"); + assertNotNull(result); + } + + @Test + public void testUpdateHost() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateHost(mock); + assertNotNull(result); + } + + @Test + public void testUpdateHostByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateHost(mock); + assertNotNull(result); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/LimitsRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/LimitsRoaTest.java new file mode 100644 index 0000000..391aad3 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/LimitsRoaTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.business.impl.LimitsBusinessImpl; +import org.onap.vfc.nfvo.resmanagement.service.business.inf.LimitsBusiness; +import org.onap.vfc.nfvo.resmanagement.service.rest.LimitsRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class LimitsRoaTest { + + private LimitsRoa roa; + + private LimitsBusiness limitsBusiness; + + @Before + public void setUp() { + roa = new LimitsRoa(); + limitsBusiness = new LimitsBusinessImpl(); + roa.setLimitsBusiness(limitsBusiness); + } + + @Test + public void testGetLimitsResource() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getLimits(String vimId) throws ServiceException { + return new JSONObject(); + } + }; + HttpServletRequest context = new MockHttpServletRequest(); + JSONObject result = roa.getLimits(context, "vimId"); + assertNotNull(result); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/LocationRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/LocationRoaTest.java new file mode 100644 index 0000000..78157f6 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/LocationRoaTest.java @@ -0,0 +1,390 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.LocationImpl; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.SitesImpl; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Location; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.onap.vfc.nfvo.resmanagement.service.entity.LocationEntity; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.onap.vfc.nfvo.resmanagement.service.rest.LocationRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class LocationRoaTest { + + private LocationRoa roa; + + private Location location; + + private Sites sites; + + @Before + public void setUp() { + roa = new LocationRoa(); + location = new LocationImpl(); + sites = new SitesImpl(); + roa.setLocation(location); + roa.setSites(sites); + } + + @Test + public void testGetLocationsbase() throws ServiceException { + new MockUp() { + + @Mock + public List get(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getLocationsbase(mock); + assertNotNull(result); + } + + @Test + public void testGetLocationbase() throws ServiceException { + new MockUp() { + + @Mock + public List get(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getLocationbase(mock, "id"); + assertNotNull(result); + } + + @Test + public void testGetCountry() throws ServiceException { + new MockUp() { + + @Mock + public List getCountry() throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getCountry(mock); + assertNotNull(result); + } + + @Test + public void testGetLocationByCountry() throws ServiceException { + new MockUp() { + + @Mock + public List getLocationByCountry(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getLocationByCountry(mock, "country"); + assertNotNull(result); + } + + @Test + public void testGetLocation() throws ServiceException { + new MockUp() { + + @Mock + public List get(Map condition) throws ServiceException { + return new ArrayList(); + } + + @Mock + public List getLocationInfo(List locationInfo) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getLocation(mock, "locations"); + assertNotNull(result); + } + + @Test + public void testAddLocation() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int add(JSONObject jsonObject) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addLocation(mock); + assertNotNull(result); + } + + @Test + public void testAddLocationByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int add(JSONObject jsonObject) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addLocation(mock); + assertNotNull(result); + } + + @Test + public void testDeleteLocationbase() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String location) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteLocationbase(mock, "locations"); + assertNotNull(result); + } + + @Test + public void testDeleteLocationbaseByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String location) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteLocationbase(mock, "locations"); + assertNotNull(result); + } + + @Test + public void testDeleteLocation() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + JSONObject object = new JSONObject(); + object.put("location", "location"); + object.put("id", "id"); + return object; + } + }; + new MockUp() { + + @Mock + public SitesEntity get(Map condition) throws ServiceException { + return null; + } + }; + new MockUp() { + + @Mock + public int delete(String location) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteLocation(mock); + assertNotNull(result); + } + + @Test + public void testDeleteLocationByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + JSONObject object = new JSONObject(); + object.put("location", "location"); + object.put("id", "id"); + return object; + } + }; + new MockUp() { + + @Mock + public SitesEntity get(Map condition) throws ServiceException { + return null; + } + }; + new MockUp() { + + @Mock + public int delete(String location) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteLocation(mock); + assertNotNull(result); + } + + @Test + public void testDeleteLocationBySitesEntity() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + JSONObject object = new JSONObject(); + object.put("location", "location"); + object.put("id", "id"); + return object; + } + }; + new MockUp() { + + @Mock + public SitesEntity get(Map condition) throws ServiceException { + return new SitesEntity(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteLocation(mock); + assertNotNull(result); + } + + @Test + public void testUpdateLocation() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + JSONObject object = new JSONObject(); + object.put("location", "location"); + return object; + } + }; + new MockUp() { + + @Mock + public SitesEntity get(Map condition) throws ServiceException { + return null; + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateLocation(mock); + assertNotNull(result); + } + + @Test + public void testUpdateLocationByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + JSONObject object = new JSONObject(); + object.put("location", "location"); + return object; + } + }; + new MockUp() { + + @Mock + public SitesEntity get(Map condition) throws ServiceException { + return null; + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateLocation(mock); + assertNotNull(result); + } + + @Test + public void testUpdateLocationBySitesEntity() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + JSONObject object = new JSONObject(); + object.put("location", "location"); + return object; + } + }; + new MockUp() { + + @Mock + public SitesEntity get(Map condition) throws ServiceException { + return new SitesEntity(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateLocation(mock); + assertNotNull(result); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/NetworkRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/NetworkRoaTest.java new file mode 100644 index 0000000..4536b0d --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/NetworkRoaTest.java @@ -0,0 +1,215 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.NetworkImpl; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Network; +import org.onap.vfc.nfvo.resmanagement.service.entity.NetworkEntity; +import org.onap.vfc.nfvo.resmanagement.service.rest.NetworkRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class NetworkRoaTest { + + private NetworkRoa roa; + + private Network network; + + @Before + public void setUp() { + roa = new NetworkRoa(); + network = new NetworkImpl(); + roa.setNetwork(network); + } + + @Test + public void testGetNetworks() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getNetworks(mock); + assertNotNull(result); + } + + @Test + public void testGetNetwork() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getNetwork(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddNetwork() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public NetworkEntity toEntity(JSONObject jsonObject) { + return new NetworkEntity(); + } + }; + new MockUp() { + + @Mock + public int add(NetworkEntity entity) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addNetwork(mock); + assertNotNull(result); + } + + @Test + public void testAddNetworkByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public NetworkEntity toEntity(JSONObject jsonObject) { + return new NetworkEntity(); + } + }; + new MockUp() { + + @Mock + public int add(NetworkEntity entity) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addNetwork(mock); + assertNotNull(result); + } + + @Test + public void testDeleteNetwork() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteNetwork(mock, "id"); + assertNotNull(result); + } + + @Test + public void testDeleteNetworkByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteNetwork(mock, "id"); + assertNotNull(result); + } + + @Test + public void testUpdateNetwork() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateNetwork(mock); + assertNotNull(result); + } + + @Test + public void testUpdateNetworkByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateNetwork(mock); + assertNotNull(result); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/PortRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/PortRoaTest.java new file mode 100644 index 0000000..181e6e5 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/PortRoaTest.java @@ -0,0 +1,215 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.PortImpl; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.inf.Port; +import org.onap.vfc.nfvo.resmanagement.service.entity.PortEntity; +import org.onap.vfc.nfvo.resmanagement.service.rest.PortRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class PortRoaTest { + + private PortRoa roa; + + private Port port; + + @Before + public void setUp() { + roa = new PortRoa(); + port = new PortImpl(); + roa.setPort(port); + } + + @Test + public void testGetPorts() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getPorts(mock); + assertNotNull(result); + } + + @Test + public void testGetPort() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getPort(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddPort() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public PortEntity toEntity(JSONObject jsonObject) { + return new PortEntity(); + } + }; + new MockUp() { + + @Mock + public int add(PortEntity portEntity) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addPort(mock); + assertNotNull(result); + } + + @Test + public void testAddPortByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public PortEntity toEntity(JSONObject jsonObject) { + return new PortEntity(); + } + }; + new MockUp() { + + @Mock + public int add(PortEntity portEntity) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addPort(mock); + assertNotNull(result); + } + + @Test + public void testDeletePort() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deletePort(mock, "id"); + assertNotNull(result); + } + + @Test + public void testDeletePortByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deletePort(mock, "id"); + assertNotNull(result); + } + + @Test + public void testUpdatePort() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updatePort(mock); + assertNotNull(result); + } + + @Test + public void testUpdatePortByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updatePort(mock); + assertNotNull(result); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/ResOperateRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/ResOperateRoaTest.java new file mode 100644 index 0000000..aa87bf5 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/ResOperateRoaTest.java @@ -0,0 +1,198 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.group.impl.ResOperateServiceImpl; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.ResOperateService; +import org.onap.vfc.nfvo.resmanagement.service.rest.ResOperateRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Mar 16, 2017 + */ +public class ResOperateRoaTest { + + private ResOperateRoa roa; + + private ResOperateService resOperateService; + + @Before + public void setUp() { + roa = new ResOperateRoa(); + resOperateService = new ResOperateServiceImpl(); + roa.setResOperateService(resOperateService); + } + + @Test + public void testUpdateIResPool() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject getVimById(String vimId) { + JSONObject vimInfo = new JSONObject(); + vimInfo.put("tenant", "tenant"); + return vimInfo; + } + + @Mock + public String getTenantIdByName(String tenant, String vimId) { + return ""; + } + }; + new MockUp() { + + @Mock + public void updateIRes(String tenantId, String vimId, JSONObject header) throws ServiceException { + } + + @Mock + public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateIResPool(mock, "vimId"); + assertNotNull(result); + } + + @Test + public void testUpdateIResPoolFail() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject getVimById(String vimId) { + JSONObject vimInfo = new JSONObject(); + vimInfo.put("tenant", "tenant"); + return vimInfo; + } + + @Mock + public String getTenantIdByName(String tenant, String vimId) { + return ""; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.updateIResPool(mock, null); + assertNotNull(result); + } + + @Test + public void testAddAllResPool() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public void addIRes(String tenantId, String vimId, JSONObject header) throws ServiceException { + } + + @Mock + public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addAllResPool(mock, "tenantId", "vimId"); + assertNotNull(result); + } + + @Test + public void testAddAllResPoolFail() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addAllResPool(mock, null, null); + assertNotNull(result); + } + + @Test + public void testDeleteIRes() throws ServiceException { + new MockUp() { + + @Mock + public int deleteIRes(String vimId) throws ServiceException { + return 1; + } + + @Mock + public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteIRes(mock, "vimId"); + assertNotNull(result); + } + + @Test + public void testDeleteIResFail() throws ServiceException { + new MockUp() { + + @Mock + public int deleteIRes(String vimId) throws ServiceException { + throw new ServiceException(); + } + + @Mock + public void sendMsgMonitor(String operateType, String vimId) throws ServiceException { + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteIRes(mock, null); + assertNotNull(result); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/SitesRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/SitesRoaTest.java new file mode 100644 index 0000000..1a813c8 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/SitesRoaTest.java @@ -0,0 +1,280 @@ +/* + * Copyright 2016-2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.VimUtil; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.base.openstack.impl.SitesImpl; +import org.onap.vfc.nfvo.resmanagement.service.entity.SitesEntity; +import org.onap.vfc.nfvo.resmanagement.service.rest.SitesRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 2016年8月16日 + */ +public class SitesRoaTest { + + private SitesRoa sitesRoa; + + @Before + public void setUp() { + sitesRoa = new SitesRoa(); + sitesRoa.setSites(new SitesImpl()); + } + + @Test + public void testGetSites() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = sitesRoa.getSites(mock); + assertNotNull(result); + } + + @Test + public void testGetSite() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map condition) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = sitesRoa.getSite(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddSites() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getAllJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int add(JSONObject jsonObject) throws ServiceException { + return 1; + } + + @Mock + public void sendToMonitor(JSONObject jsonObject) throws ServiceException { + + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = sitesRoa.addSites(mock); + assertNotNull(result); + } + + @Test + public void testAddSitesExceptions() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getAllJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int add(JSONObject jsonObject) throws ServiceException { + throw new ServiceException(); + } + }; + JSONObject result = sitesRoa.addSites(null); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", ""); + assertEquals(expectedResult.toString(), result.toString()); + } + + @Test + public void testDeleteSites() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + JSONObject result = sitesRoa.deleteSites(null, "123"); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", "org.openo.nfvo.resmanage.common.del.success"); + assertEquals(expectedResult.toString(), result.toString()); + } + + @Test + public void testDeleteSitesExceptions() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + JSONObject result = sitesRoa.deleteSites(null, "123"); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", ""); + assertEquals(expectedResult.toString(), result.toString()); + } + + @Test + public void testUpdateSites() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getAllJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(SitesEntity sitesEntity) throws ServiceException { + return 1; + } + }; + JSONObject result = sitesRoa.updateSites(null); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", "org.openo.nfvo.resmanage.common.update.success"); + assertEquals(expectedResult.toString(), result.toString()); + } + + @Test + public void testUpdateISitesExceptions() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getAllJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(SitesEntity sitesEntity) throws ServiceException { + throw new ServiceException(); + } + }; + JSONObject result = sitesRoa.updateSites(null); + JSONObject expectedResult = new JSONObject(); + expectedResult.put("msg", ""); + assertEquals(expectedResult.toString(), result.toString()); + } + + @Test + public void testGrantResource() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getAllJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = sitesRoa.grantResource(mock); + assertNotNull(result); + } + + @Test + public void testGrantResourceByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getAllJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public int update(JSONObject jsonObject) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = sitesRoa.grantResource(mock); + assertNotNull(result); + } + + @Test + public void testGetVims() throws ServiceException { + new MockUp() { + + @Mock + public JSONArray getVims() { + return new JSONArray(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + String result = sitesRoa.getVims(mock); + assertNotNull(result); + } + + @Test + public void testGetVim() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getVimById(String vimId) { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + String result = sitesRoa.getVim(mock, "id"); + assertNotNull(result); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/SwaggerRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/SwaggerRoaTest.java new file mode 100644 index 0000000..eccc4d9 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/SwaggerRoaTest.java @@ -0,0 +1,57 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.rest.SwaggerRoa; + +import mockit.Mock; +import mockit.MockUp; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class SwaggerRoaTest { + + private SwaggerRoa roa; + + @Test + public void testApidoc() throws IOException { + new MockUp() { + + @Mock + public String toString(InputStream input) { + return ""; + } + }; + roa = new SwaggerRoa(); + String result = roa.apidoc(); + assertNotNull(result); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java new file mode 100644 index 0000000..5377f60 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java @@ -0,0 +1,193 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.impl.VirtualLinkServiceImpl; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VirtualLinkService; +import org.onap.vfc.nfvo.resmanagement.service.rest.VirtualLinkRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class VirtualLinkRoaTest { + + private VirtualLinkRoa roa; + + private VirtualLinkService virtualLink; + + @Before + public void setUp() { + roa = new VirtualLinkRoa(); + virtualLink = new VirtualLinkServiceImpl(); + roa.setVirtualLink(virtualLink); + } + + @Test + public void testGetVls() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVls(mock); + assertNotNull(result); + } + + @Test + public void testGetVl() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVl(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddVl() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public VirtualLinkEntity toEntity(JSONObject jsonObject) { + return new VirtualLinkEntity(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVl(mock); + assertNotNull(result); + } + + @Test + public void testAddVlByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public VirtualLinkEntity toEntity(JSONObject jsonObject) { + return new VirtualLinkEntity(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVl(VirtualLinkEntity virtualLinkEntity) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVl(mock); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testAddVlByExceptionByNull() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + roa.addVl(mock); + } + + @Test + public void testDeleteVl() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVl(mock, "id"); + assertNotNull(result); + } + + @Test + public void testDeleteVlByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVl(mock, "id"); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testDeleteVlByNull() throws ServiceException { + HttpServletRequest mock = new MockHttpServletRequest(); + roa.deleteVl(mock, null); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VmRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VmRoaTest.java new file mode 100644 index 0000000..f3321fa --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VmRoaTest.java @@ -0,0 +1,194 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VmEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.impl.VmServiceImpl; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VmService; +import org.onap.vfc.nfvo.resmanagement.service.rest.VmRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class VmRoaTest { + + private VmRoa roa; + + private VmService vmService; + + @Before + public void setUp() { + roa = new VmRoa(); + vmService = new VmServiceImpl(); + roa.setVmService(vmService); + } + + @Test + public void testGetVms() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVms(mock); + assertNotNull(result); + } + + @Test + public void testGetVm() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVm(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddVm() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public VmEntity toEntity(JSONObject jsonObject) { + return new VmEntity(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVm(VmEntity vmEntity) throws ServiceException { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVm(mock); + assertNotNull(result); + } + + @Test + public void testAddVmByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public VmEntity toEntity(JSONObject jsonObject) { + return new VmEntity(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVm(VmEntity vmEntity) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVm(mock); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testAddVmByNull() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + roa.addVm(mock); + } + + @Test + public void testDeleteVm() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVm(mock, "id"); + assertNotNull(result); + } + + @Test + public void testDeleteVmByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVm(mock, "id"); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testDeleteVmByNull() throws ServiceException { + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVm(mock, null); + assertNotNull(result); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java new file mode 100644 index 0000000..e6aafa6 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java @@ -0,0 +1,179 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.impl.VnfInfoServiceImpl; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfInfoService; +import org.onap.vfc.nfvo.resmanagement.service.rest.VnfInfoRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class VnfInfoRoaTest { + + private VnfInfoRoa roa; + + private VnfInfoService vnfInfoService; + + @Before + public void setUp() { + roa = new VnfInfoRoa(); + vnfInfoService = new VnfInfoServiceImpl(); + roa.setVnfInfoService(vnfInfoService); + } + + @Test + public void testGetVnfInfos() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVnfInfos(mock); + assertNotNull(result); + } + + @Test + public void testGetVnfInfo() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVnfInfo(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddVnfInfo() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVnfInfo(JSONObject object) throws ServiceException { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVnfInfo(mock); + assertNotNull(result); + } + + @Test + public void testAddVnfInfoByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVnfInfo(JSONObject object) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVnfInfo(mock); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testAddVnfInfoByNull() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + roa.addVnfInfo(mock); + } + + @Test + public void testDeleteVnfInfo() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVnfInfo(mock, "id"); + assertNotNull(result); + } + + @Test + public void testDeleteVnfInfoByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVnfInfo(mock, "id"); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testDeleteVnfInfoByNull() throws ServiceException { + HttpServletRequest mock = new MockHttpServletRequest(); + roa.deleteVnfInfo(mock, null); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoaTest.java new file mode 100644 index 0000000..099bae0 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfRoaTest.java @@ -0,0 +1,192 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.impl.VnfServiceImpl; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfService; +import org.onap.vfc.nfvo.resmanagement.service.rest.VnfRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 10, 2017 + */ +public class VnfRoaTest { + + private VnfRoa roa; + + private VnfService vnfService; + + @Before + public void setUp() { + roa = new VnfRoa(); + vnfService = new VnfServiceImpl(); + roa.setVnfService(vnfService); + } + + @Test + public void testGetVnfs() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVnfs(mock); + assertNotNull(result); + } + + @Test + public void testGetVnf() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVnf(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddVnf() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public VnfEntity toEntity(JSONObject jsonObject) { + return new VnfEntity(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVnf(mock); + assertNotNull(result); + } + + @Test + public void testAddVnfByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public VnfEntity toEntity(JSONObject jsonObject) { + return new VnfEntity(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVnf(VnfEntity vnfEntity) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVnf(mock); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testAddVnfByNull() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + roa.addVnf(mock); + } + + @Test + public void testDeleteVnf() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVnf(mock, "id"); + assertNotNull(result); + } + + @Test + public void testDeleteVnfByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVnf(mock, "id"); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testDeleteVnfByNull() throws ServiceException { + HttpServletRequest mock = new MockHttpServletRequest(); + roa.deleteVnf(mock, null); + } +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java new file mode 100644 index 0000000..61d3e6e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java @@ -0,0 +1,179 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest; + +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; + +import org.junit.Before; +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.common.util.request.RequestUtil; +import org.onap.vfc.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.onap.vfc.nfvo.resmanagement.service.group.impl.VnfStatusServiceImpl; +import org.onap.vfc.nfvo.resmanagement.service.group.inf.VnfStatusService; +import org.onap.vfc.nfvo.resmanagement.service.rest.VnfStatusRoa; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.springframework.mock.web.MockHttpServletRequest; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 10, 2017 + */ +public class VnfStatusRoaTest { + + private VnfStatusRoa roa; + + private VnfStatusService vnfStatusService; + + @Before + public void setUp() { + roa = new VnfStatusRoa(); + vnfStatusService = new VnfStatusServiceImpl(); + roa.setVnfStatusService(vnfStatusService); + } + + @Test + public void testGetVnfStatuss() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVnfStatuss(mock); + assertNotNull(result); + } + + @Test + public void testGetVnfStatus() throws ServiceException { + new MockUp() { + + @Mock + public List getList(Map map) throws ServiceException { + return new ArrayList(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.getVnfStatus(mock, "id"); + assertNotNull(result); + } + + @Test + public void testAddVnfStatus() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVnfStatus(JSONObject object) throws ServiceException { + return new JSONObject(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVnfStatus(mock); + assertNotNull(result); + } + + @Test + public void testAddVnfStatusByException() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return new JSONObject(); + } + }; + new MockUp() { + + @Mock + public JSONObject addVnfStatus(JSONObject object) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.addVnfStatus(mock); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testAddVnfStatusByNull() throws ServiceException { + new MockUp() { + + @Mock + public JSONObject getJsonRequestBody(HttpServletRequest context) { + return null; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + roa.addVnfStatus(mock); + } + + @Test + public void testDeleteVnfStatus() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + return 1; + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVnfStatus(mock, "id"); + assertNotNull(result); + } + + @Test + public void testDeleteVnfStatusByException() throws ServiceException { + new MockUp() { + + @Mock + public int delete(String id) throws ServiceException { + throw new ServiceException(); + } + }; + HttpServletRequest mock = new MockHttpServletRequest(); + JSONObject result = roa.deleteVnfStatus(mock, "id"); + assertNotNull(result); + } + + @Test(expected = ServiceException.class) + public void testDeleteVnfStatusByNull() throws ServiceException { + HttpServletRequest mock = new MockHttpServletRequest(); + roa.deleteVnfStatus(mock, null); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java new file mode 100644 index 0000000..c3a3c33 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java @@ -0,0 +1,69 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper.ExceptionMessage; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class ExceptionMessageTest { + + @Test + public void testToString() { + ExceptionMessage message = new ExceptionMessage(); + message.setErrorCode("1"); + message.setHttpCode(200); + message.setMessage("Success!"); + String str = message.toString(); + assertNotNull(str); + } + + @Test + public void testGetErrorCode() { + ExceptionMessage message = new ExceptionMessage(); + message.setErrorCode("1"); + String str = message.getErrorCode(); + assertEquals("1", str); + } + + @Test + public void testHttpCode() { + ExceptionMessage message = new ExceptionMessage(); + message.setHttpCode(200); + int str = message.getHttpCode(); + assertEquals(200, str); + } + + @Test + public void testGetMessage() { + ExceptionMessage message = new ExceptionMessage(); + message.setMessage("Success!"); + String str = message.getMessage(); + assertEquals("Success!", str); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java new file mode 100644 index 0000000..e6b4916 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java @@ -0,0 +1,44 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper; + +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.Response; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper.GenericExceptionMapper; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class GenericExceptionMapperTest { + + @Test + public void testToResponse() { + GenericExceptionMapper excep = new GenericExceptionMapper(); + Exception exception = new Exception("message"); + Response res = excep.toResponse(exception); + assertNotNull(res); + } + +} diff --git a/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java new file mode 100644 index 0000000..f465772 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/onap/vfc/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java @@ -0,0 +1,45 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper; + +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.Response; + +import org.junit.Test; +import org.onap.vfc.nfvo.resmanagement.service.rest.exceptionmapper.ServiceExceptionMapper; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Feb 9, 2017 + */ +public class ServiceExceptionMapperTest { + + @Test + public void testToResponse() { + ServiceExceptionMapper mapper = new ServiceExceptionMapper(); + ServiceException exception = new ServiceException(); + Response res = mapper.toResponse(exception); + assertNotNull(res); + } + +} diff --git a/pom.xml b/pom.xml index ecb9746..fa4c32b 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 1.0.0-SNAPSHOT 4.0.0 - org.onap.vfc.nfvo.res + org.onap.vfc.nfvo.resmanagement resmanagement 1.0.0-SNAPSHOT pom -- cgit 1.2.3-korg