From 056dcab91efc64b5f9fc39825f9242e7fa0b9d05 Mon Sep 17 00:00:00 2001 From: luxin Date: Mon, 3 Jul 2017 10:19:19 +0800 Subject: Upload nfvo resmanagement code Change-Id: Ibe023d4b09e1105b84eb43153b4d4037cae691db Signed-off-by: luxin --- .../mocoserver/VimDriverSuccessServer.java | 72 ++ .../nfvo/resmanagement/test/ITHostRoaFail.java | 58 ++ .../nfvo/resmanagement/test/ITHostRoaSuccess.java | 51 + .../openo/nfvo/resmanagement/test/ITLimitsRoa.java | 62 ++ .../nfvo/resmanagement/test/ITLocationRoaFail.java | 61 ++ .../resmanagement/test/ITLocationRoaSuccess.java | 54 + .../nfvo/resmanagement/test/ITNetworkRoaFail.java | 61 ++ .../resmanagement/test/ITNetworkRoaSuccess.java | 54 + .../nfvo/resmanagement/test/ITPortRoaFail.java | 58 ++ .../nfvo/resmanagement/test/ITPortRoaSuccess.java | 51 + .../resmanagement/test/ITResOperateRoaFail.java | 50 + .../resmanagement/test/ITResOperateRoaSuccess.java | 66 ++ .../nfvo/resmanagement/test/ITSitesRoaFail.java | 58 ++ .../nfvo/resmanagement/test/ITSitesRoaSuccess.java | 51 + .../nfvo/resmanagement/util/AddSuccessChecker.java | 46 + .../nfvo/resmanagement/util/FailureChecker.java | 44 + .../nfvo/resmanagement/util/GetSuccessChecker.java | 48 + .../openo/nfvo/resmanagement/util/MyChecker.java | 59 ++ .../nfvo/resmanagement/util/MyTestManager.java | 163 +++ .../nfvo/resmanagement/util/SuccessChecker.java | 46 + .../resources/mocoserver/getcpulimits.json | 26 + .../resources/mocoserver/getdisklimits.json | 24 + .../resources/mocoserver/gethost.json | 51 + .../resources/mocoserver/gethosts.json | 26 + .../resources/mocoserver/getnetworks.json | 54 + .../resources/mocoserver/getports.json | 60 ++ .../resources/mocoserver/sendmsgmonitor1.json | 31 + .../resources/mocoserver/sendmsgmonitor2.json | 31 + .../resources/mocoserver/sendmsgmonitor3.json | 23 + .../integration-test/resources/server.properties | 14 + .../testcase/hostroa/createhostsfail1.json | 24 + .../testcase/hostroa/createhostssuccess1.json | 24 + .../testcase/hostroa/deletehostsfail1.json | 15 + .../testcase/hostroa/deletehostssuccess1.json | 15 + .../resources/testcase/hostroa/modhostsfail1.json | 24 + .../testcase/hostroa/modhostssuccess1.json | 24 + .../testcase/hostroa/queryhostsbyidfail1.json | 15 + .../testcase/hostroa/queryhostsbyidsuccess1.json | 23 + .../testcase/limitsroa/querycpulimitssuccess1.json | 23 + .../limitsroa/querydisklimitssuccess1.json | 21 + .../testcase/locationroa/createlocationsfail1.json | 23 + .../locationroa/createlocationssuccess1.json | 23 + .../testcase/locationroa/deletelocationsfail1.json | 15 + .../locationroa/deletelocationssuccess1.json | 15 + .../testcase/locationroa/modlocationsfail1.json | 23 + .../testcase/locationroa/modlocationssuccess1.json | 23 + .../locationroa/querylocationsbyidfail1.json | 15 + .../locationroa/querylocationsbyidsuccess1.json | 22 + .../testcase/networkroa/createnetworksfail1.json | 26 + .../networkroa/createnetworkssuccess1.json | 26 + .../testcase/networkroa/deletenetworksfail1.json | 15 + .../networkroa/deletenetworkssuccess1.json | 15 + .../testcase/networkroa/modnetworksfail1.json | 26 + .../testcase/networkroa/modnetworkssuccess1.json | 26 + .../networkroa/querynetworksbyidfail1.json | 15 + .../networkroa/querynetworksbyidsuccess1.json | 25 + .../testcase/portroa/createportsfail1.json | 24 + .../testcase/portroa/createportssuccess1.json | 24 + .../testcase/portroa/deleteportsfail1.json | 15 + .../testcase/portroa/deleteportssuccess1.json | 15 + .../resources/testcase/portroa/modportsfail1.json | 24 + .../testcase/portroa/modportssuccess1.json | 24 + .../testcase/portroa/queryportsbyidfail1.json | 15 + .../testcase/portroa/queryportsbyidsuccess1.json | 23 + .../testcase/resoperateroa/addresourcefail1.json | 18 + .../resoperateroa/addresourcesuccess1.json | 18 + .../resoperateroa/deleteresourcefail1.json | 15 + .../resoperateroa/deleteresourcesuccess1.json | 15 + .../testcase/resoperateroa/modresourcefail1.json | 17 + .../resoperateroa/modresourcesuccess1.json | 17 + .../testcase/siteroa/createsitesfail1.json | 30 + .../testcase/siteroa/createsitessuccess1.json | 30 + .../testcase/siteroa/deletesitesfail1.json | 15 + .../testcase/siteroa/deletesitessuccess1.json | 15 + .../resources/testcase/siteroa/modsitesfail1.json | 30 + .../testcase/siteroa/modsitessuccess1.json | 30 + .../testcase/siteroa/querysitesbyidfail1.json | 15 + .../testcase/siteroa/querysitesbyidsuccess1.json | 29 + .../src/integration-test/resources/urlconfig.json | 18 + .../nfvo/resmanagement/common/ResourceUtil.java | 43 + .../openo/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 +++ .../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 + .../service/src/main/resources/log4j.properties | 23 + .../main/resources/mybatis/mysql/HostMapper.xml | 189 ++++ .../resources/mybatis/mysql/LocationMapper.xml | 158 +++ .../main/resources/mybatis/mysql/NetworkMapper.xml | 216 ++++ .../main/resources/mybatis/mysql/PortMapper.xml | 180 ++++ .../main/resources/mybatis/mysql/SitesMapper.xml | 286 +++++ .../src/main/resources/mybatis/mysql/VimMapper.xml | 52 + .../resources/mybatis/mysql/VirtualLinkMapper.xml | 273 +++++ .../src/main/resources/mybatis/mysql/VmMapper.xml | 114 ++ .../main/resources/mybatis/mysql/VnfInfoMapper.xml | 96 ++ .../src/main/resources/mybatis/mysql/VnfMapper.xml | 319 ++++++ .../resources/mybatis/mysql/VnfStatusMapper.xml | 213 ++++ .../resources/spring/Resmanagement/services.xml | 331 ++++++ .../spring/Resmanagement/svc_register.xml | 42 + .../service/src/main/resources/swagger.json | 1100 ++++++++++++++++++++ .../service/src/main/webapp/WEB-INF/web.xml | 47 + .../resmanagement/common/ResourceUtilTest.java | 51 + .../nfvo/resmanagement/common/VimUtilTest.java | 48 + .../resmanagement/common/util/JsonUtilTest.java | 435 ++++++++ .../resmanagement/common/util/RestfulUtilTest.java | 244 +++++ .../resmanagement/common/util/StringUtilTest.java | 143 +++ .../common/util/request/RequestUtilTest.java | 252 +++++ .../common/util/response/ResponseUtilTest.java | 90 ++ .../common/util/response/RoaResponseUtilTest.java | 146 +++ .../adapter/impl/ResmgrAdapter2MSBManagerTest.java | 240 +++++ .../adapter/impl/ResmgrAdapterMgrServiceTest.java | 68 ++ .../service/base/openstack/impl/HostImplTest.java | 161 +++ .../base/openstack/impl/LocationImplTest.java | 499 +++++++++ .../base/openstack/impl/NetworkImplTest.java | 275 +++++ .../service/base/openstack/impl/PortImplTest.java | 153 +++ .../service/base/openstack/impl/SitesImplTest.java | 148 +++ .../service/base/openstack/impl/VimImplTest.java | 135 +++ .../business/impl/HostBusinessImplTest.java | 87 ++ .../business/impl/LimitsBusinessImplTest.java | 71 ++ .../business/impl/LocationBusinessImplTest.java | 219 ++++ .../business/impl/SitesBusinessImplTest.java | 408 ++++++++ .../service/business/impl/VimBusinessImplTest.java | 177 ++++ .../service/dao/impl/HostDaoImplTest.java | 155 +++ .../service/dao/impl/LocationDaoImplTest.java | 85 ++ .../service/dao/impl/NetworkDaoImplTest.java | 152 +++ .../service/dao/impl/PortDaoImplTest.java | 158 +++ .../service/dao/impl/SitesDaoImplTest.java | 132 +++ .../service/dao/impl/VimDaoImplTest.java | 77 ++ .../service/dao/impl/VirtualLinkDaoImplTest.java | 49 + .../service/dao/impl/VmDaoImplTest.java | 51 + .../service/entity/HostEntityTest.java | 38 + .../service/entity/LocationEntityTest.java | 45 + .../service/entity/NetworkEntityTest.java | 49 + .../service/entity/PortEntityTest.java | 47 + .../service/entity/SitesEntityTest.java | 110 ++ .../service/entity/VimEntityTest.java | 42 + .../service/rest/GrantResourseRoaTest.java | 166 +++ .../resmanagement/service/rest/HostRoaTest.java | 200 ++++ .../resmanagement/service/rest/LimitsRoaTest.java | 68 ++ .../service/rest/LocationRoaTest.java | 389 +++++++ .../resmanagement/service/rest/NetworkRoaTest.java | 214 ++++ .../resmanagement/service/rest/PortRoaTest.java | 214 ++++ .../service/rest/ResOperateRoaTest.java | 197 ++++ .../resmanagement/service/rest/SitesRoaTest.java | 279 +++++ .../resmanagement/service/rest/SwaggerRoaTest.java | 56 + .../service/rest/VirtualLinkRoaTest.java | 192 ++++ .../nfvo/resmanagement/service/rest/VmRoaTest.java | 193 ++++ .../resmanagement/service/rest/VnfInfoRoaTest.java | 178 ++++ .../resmanagement/service/rest/VnfRoaTest.java | 191 ++++ .../service/rest/VnfStatusRoaTest.java | 178 ++++ .../rest/exceptionmapper/ExceptionMessageTest.java | 68 ++ .../GenericExceptionMapperTest.java | 43 + .../ServiceExceptionMapperTest.java | 44 + 272 files changed, 29529 insertions(+) create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/mocoserver/VimDriverSuccessServer.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITHostRoaFail.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITHostRoaSuccess.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLimitsRoa.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLocationRoaFail.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLocationRoaSuccess.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITNetworkRoaFail.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITNetworkRoaSuccess.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITPortRoaFail.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITPortRoaSuccess.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITResOperateRoaFail.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITResOperateRoaSuccess.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITSitesRoaFail.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITSitesRoaSuccess.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/AddSuccessChecker.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/FailureChecker.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/GetSuccessChecker.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/MyChecker.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/MyTestManager.java create mode 100644 ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/SuccessChecker.java create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/getcpulimits.json create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/getdisklimits.json create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/gethost.json create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/gethosts.json create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/getnetworks.json create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/getports.json create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor2.json create mode 100644 ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor3.json create mode 100644 ResmanagementService/service/src/integration-test/resources/server.properties create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/hostroa/createhostsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/hostroa/createhostssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/hostroa/deletehostsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/hostroa/deletehostssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/hostroa/modhostsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/hostroa/modhostssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/hostroa/queryhostsbyidfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/hostroa/queryhostsbyidsuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/limitsroa/querycpulimitssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/limitsroa/querydisklimitssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/locationroa/createlocationsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/locationroa/createlocationssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/locationroa/deletelocationsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/locationroa/deletelocationssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/locationroa/modlocationsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/locationroa/modlocationssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/locationroa/querylocationsbyidfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/locationroa/querylocationsbyidsuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/networkroa/createnetworksfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/networkroa/createnetworkssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/networkroa/deletenetworksfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/networkroa/deletenetworkssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/networkroa/modnetworksfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/networkroa/modnetworkssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/networkroa/querynetworksbyidfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/networkroa/querynetworksbyidsuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/portroa/createportsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/portroa/createportssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/portroa/deleteportsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/portroa/deleteportssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/portroa/modportsfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/portroa/modportssuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/portroa/queryportsbyidfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/portroa/queryportsbyidsuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/addresourcefail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/addresourcesuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/deleteresourcefail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/deleteresourcesuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/modresourcefail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/modresourcesuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/siteroa/createsitesfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/siteroa/createsitessuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/siteroa/deletesitesfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/siteroa/deletesitessuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/siteroa/modsitesfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/siteroa/modsitessuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/siteroa/querysitesbyidfail1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/testcase/siteroa/querysitesbyidsuccess1.json create mode 100644 ResmanagementService/service/src/integration-test/resources/urlconfig.json create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/ResourceUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/VimUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/Constant.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/HttpConstant.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/ParamConstant.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/ResponseConstant.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/UrlConstant.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/JsonUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/RestfulUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/StringUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtil.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/activator/ROAResmgrServicePostProcessor.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManager.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/adapter/inf/IResmgrAdapter2MSBManager.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/adapter/inf/IResmgrAdapterMgrService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/VimImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Host.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/InterfaceResManagement.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Location.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Network.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Port.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/ResManagement.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Sites.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Vim.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/NetworkBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/PortBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/HostBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/LimitsBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/LocationBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/NetworkBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/PortBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/SitesBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/VimBusiness.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/AbstractDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VnfDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VnfInfoDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VnfStatusDaoImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/HostDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/LocationDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/NetworkDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/PortDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/SitesDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VimDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VirtualLinkDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VmDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VnfDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VnfInfoDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VnfStatusDao.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/HostEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/LocationEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/PortEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/SitesEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VimEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VirtualLinkEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VmEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VnfEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VnfInfoEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VnfStatusEntity.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/GrantResServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/IResourceAddServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/IResourceDelServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/IResourceUpdateServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/ResOperateServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VirtualLinkServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VmServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VnfInfoServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VnfStatusServiceImpl.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/GrantResService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/ResOperateService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VirtualLinkService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VmService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VnfInfoService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VnfService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VnfStatusService.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/HostMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/LocationMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/NetworkMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/PortMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/SitesMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VimMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VirtualLinkMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VmMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VnfInfoMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VnfMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VnfStatusMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/HostRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/LocationRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/PortRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/SitesRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VmRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VnfRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoa.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessage.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapper.java create mode 100644 ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapper.java create mode 100644 ResmanagementService/service/src/main/resources/log4j.properties create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/HostMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/LocationMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/NetworkMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/PortMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/SitesMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/VimMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/VirtualLinkMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/VmMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/VnfInfoMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/VnfMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/mybatis/mysql/VnfStatusMapper.xml create mode 100644 ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml create mode 100644 ResmanagementService/service/src/main/resources/spring/Resmanagement/svc_register.xml create mode 100644 ResmanagementService/service/src/main/resources/swagger.json create mode 100644 ResmanagementService/service/src/main/webapp/WEB-INF/web.xml create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/ResourceUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/VimUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/JsonUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/RestfulUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/StringUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/HostEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/LocationEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/PortEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/SitesEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/VimEntityTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/HostRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LocationRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/PortRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SitesRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VmRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java create mode 100644 ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java (limited to 'ResmanagementService/service/src') diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/mocoserver/VimDriverSuccessServer.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/mocoserver/VimDriverSuccessServer.java new file mode 100644 index 0000000..1d6123f --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/mocoserver/VimDriverSuccessServer.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.openo.nfvo.resmanagement.mocoserver; + +import org.openo.sdno.testframework.moco.MocoHttpServer; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 28, 2016 + */ +public class VimDriverSuccessServer extends MocoHttpServer { + + private static final String GET_CPU_LIMITS = "src/integration-test/resources/mocoserver/getcpulimits.json"; + + private static final String GET_DISK_LIMITS = "src/integration-test/resources/mocoserver/getdisklimits.json"; + + private static final String GET_HOSTS_FILE = "src/integration-test/resources/mocoserver/gethosts.json"; + + private static final String GET_HOST_FILE = "src/integration-test/resources/mocoserver/gethost.json"; + + private static final String GET_NETWORKS_FILE = "src/integration-test/resources/mocoserver/getnetworks.json"; + + private static final String GET_PORTS_FILE = "src/integration-test/resources/mocoserver/getports.json"; + + private static final String SEND_ADD_MONITOR_FILE = + "src/integration-test/resources/mocoserver/sendmsgmonitor1.json"; + + private static final String SEND_MOD_MONITOR_FILE = + "src/integration-test/resources/mocoserver/sendmsgmonitor2.json"; + + private static final String SEND_DEL_MONITOR_FILE = + "src/integration-test/resources/mocoserver/sendmsgmonitor3.json"; + + public VimDriverSuccessServer() { + super(); + } + + public VimDriverSuccessServer(int port) { + super(port); + } + + @Override + public void addRequestResponsePairs() { + this.addRequestResponsePair(GET_CPU_LIMITS); + this.addRequestResponsePair(GET_DISK_LIMITS); + this.addRequestResponsePair(GET_HOSTS_FILE); + this.addRequestResponsePair(GET_HOST_FILE); + this.addRequestResponsePair(GET_NETWORKS_FILE); + this.addRequestResponsePair(GET_PORTS_FILE); + this.addRequestResponsePair(SEND_ADD_MONITOR_FILE); + this.addRequestResponsePair(SEND_MOD_MONITOR_FILE); + this.addRequestResponsePair(SEND_DEL_MONITOR_FILE); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITHostRoaFail.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITHostRoaFail.java new file mode 100644 index 0000000..27e4c59 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITHostRoaFail.java @@ -0,0 +1,58 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 24, 2016 + */ +public class ITHostRoaFail extends MyTestManager { + + private static final String GET_PATH = "src/integration-test/resources/testcase/hostroa/queryhostsbyidfail1.json"; + + private static final String POST_PATH = "src/integration-test/resources/testcase/hostroa/createhostsfail1.json"; + + private static final String PUT_PATH = "src/integration-test/resources/testcase/hostroa/modhostsfail1.json"; + + private static final String DEL_PATH = "src/integration-test/resources/testcase/hostroa/deletehostsfail1.json"; + + private static final String POST_SUCCESS_PATH = + "src/integration-test/resources/testcase/hostroa/createhostssuccess1.json"; + + private static final String DEL_SUCCESS_PATH = + "src/integration-test/resources/testcase/hostroa/deletehostssuccess1.json"; + + @Test + public void testOperateFail() throws ServiceException { + execTestCase(new File(POST_SUCCESS_PATH)); + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + execTestCase(new File(DEL_SUCCESS_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITHostRoaSuccess.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITHostRoaSuccess.java new file mode 100644 index 0000000..72ac04d --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITHostRoaSuccess.java @@ -0,0 +1,51 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 20, 2016 + */ +public class ITHostRoaSuccess extends MyTestManager { + + private static final String GET_PATH = + "src/integration-test/resources/testcase/hostroa/queryhostsbyidsuccess1.json"; + + private static final String POST_PATH = "src/integration-test/resources/testcase/hostroa/createhostssuccess1.json"; + + private static final String PUT_PATH = "src/integration-test/resources/testcase/hostroa/modhostssuccess1.json"; + + private static final String DEL_PATH = "src/integration-test/resources/testcase/hostroa/deletehostssuccess1.json"; + + @Test + public void testOperateSuccess() throws ServiceException { + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLimitsRoa.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLimitsRoa.java new file mode 100644 index 0000000..f9ef461 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLimitsRoa.java @@ -0,0 +1,62 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.mocoserver.VimDriverSuccessServer; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 28, 2016 + */ +public class ITLimitsRoa extends MyTestManager { + + private VimDriverSuccessServer driver = new VimDriverSuccessServer(); + + private static final String GET_CPU_PATH = + "src/integration-test/resources/testcase/limitsroa/querycpulimitssuccess1.json"; + + private static final String GET_DISK_PATH = + "src/integration-test/resources/testcase/limitsroa/querydisklimitssuccess1.json"; + + @Before + public void setup() throws ServiceException, InterruptedException { + driver.start(); + // Thread.sleep(60 * 1000); + } + + @After + public void tearDown() throws ServiceException { + driver.stop(); + } + + @Test + public void testGetLimitsSuccess() throws ServiceException { + execTestCase(new File(GET_CPU_PATH)); + execTestCase(new File(GET_DISK_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLocationRoaFail.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLocationRoaFail.java new file mode 100644 index 0000000..3d8b67d --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLocationRoaFail.java @@ -0,0 +1,61 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +public class ITLocationRoaFail extends MyTestManager { + + private static final String GET_PATH = + "src/integration-test/resources/testcase/locationroa/querylocationsbyidfail1.json"; + + private static final String POST_PATH = + "src/integration-test/resources/testcase/locationroa/createlocationsfail1.json"; + + private static final String PUT_PATH = "src/integration-test/resources/testcase/locationroa/modlocationsfail1.json"; + + private static final String DEL_PATH = + "src/integration-test/resources/testcase/locationroa/deletelocationsfail1.json"; + + private static final String POST_SUCCESS_PATH = + "src/integration-test/resources/testcase/locationroa/createlocationssuccess1.json"; + + private static final String DEL_SUCCESS_PATH = + "src/integration-test/resources/testcase/locationroa/deletelocationssuccess1.json"; + + @Test + public void testOperateSuccess() throws ServiceException { + execTestCase(new File(POST_SUCCESS_PATH)); + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + execTestCase(new File(DEL_SUCCESS_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLocationRoaSuccess.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLocationRoaSuccess.java new file mode 100644 index 0000000..c3641b2 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITLocationRoaSuccess.java @@ -0,0 +1,54 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 26, 2016 + */ +public class ITLocationRoaSuccess extends MyTestManager { + + private static final String GET_PATH = + "src/integration-test/resources/testcase/locationroa/querylocationsbyidsuccess1.json"; + + private static final String POST_PATH = + "src/integration-test/resources/testcase/locationroa/createlocationssuccess1.json"; + + private static final String PUT_PATH = + "src/integration-test/resources/testcase/locationroa/modlocationssuccess1.json"; + + private static final String DEL_PATH = + "src/integration-test/resources/testcase/locationroa/deletelocationssuccess1.json"; + + @Test + public void testOperateSuccess() throws ServiceException { + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITNetworkRoaFail.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITNetworkRoaFail.java new file mode 100644 index 0000000..7b9cb54 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITNetworkRoaFail.java @@ -0,0 +1,61 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +public class ITNetworkRoaFail extends MyTestManager { + + private static final String GET_PATH = + "src/integration-test/resources/testcase/networkroa/querynetworksbyidfail1.json"; + + private static final String POST_PATH = + "src/integration-test/resources/testcase/networkroa/createnetworksfail1.json"; + + private static final String PUT_PATH = "src/integration-test/resources/testcase/networkroa/modnetworksfail1.json"; + + private static final String DEL_PATH = + "src/integration-test/resources/testcase/networkroa/deletenetworksfail1.json"; + + private static final String POST_SUCCESS_PATH = + "src/integration-test/resources/testcase/networkroa/createnetworkssuccess1.json"; + + private static final String DEL_SUCCESS_PATH = + "src/integration-test/resources/testcase/networkroa/deletenetworkssuccess1.json"; + + @Test + public void testOperateSuccess() throws ServiceException { + execTestCase(new File(POST_SUCCESS_PATH)); + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + execTestCase(new File(DEL_SUCCESS_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITNetworkRoaSuccess.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITNetworkRoaSuccess.java new file mode 100644 index 0000000..50f0aeb --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITNetworkRoaSuccess.java @@ -0,0 +1,54 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +public class ITNetworkRoaSuccess extends MyTestManager { + + private static final String GET_PATH = + "src/integration-test/resources/testcase/networkroa/querynetworksbyidsuccess1.json"; + + private static final String POST_PATH = + "src/integration-test/resources/testcase/networkroa/createnetworkssuccess1.json"; + + private static final String PUT_PATH = + "src/integration-test/resources/testcase/networkroa/modnetworkssuccess1.json"; + + private static final String DEL_PATH = + "src/integration-test/resources/testcase/networkroa/deletenetworkssuccess1.json"; + + @Test + public void testOperateSuccess() throws ServiceException { + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITPortRoaFail.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITPortRoaFail.java new file mode 100644 index 0000000..d4b9d34 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITPortRoaFail.java @@ -0,0 +1,58 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 26, 2016 + */ +public class ITPortRoaFail extends MyTestManager { + + private static final String GET_PATH = "src/integration-test/resources/testcase/portroa/queryportsbyidfail1.json"; + + private static final String POST_PATH = "src/integration-test/resources/testcase/portroa/createportsfail1.json"; + + private static final String PUT_PATH = "src/integration-test/resources/testcase/portroa/modportsfail1.json"; + + private static final String DEL_PATH = "src/integration-test/resources/testcase/portroa/deleteportsfail1.json"; + + private static final String POST_SUCCESS_PATH = + "src/integration-test/resources/testcase/portroa/createportssuccess1.json"; + + private static final String DEL_SUCCESS_PATH = + "src/integration-test/resources/testcase/portroa/deleteportssuccess1.json"; + + @Test + public void testOperateFail() throws ServiceException { + execTestCase(new File(POST_SUCCESS_PATH)); + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + execTestCase(new File(DEL_SUCCESS_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITPortRoaSuccess.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITPortRoaSuccess.java new file mode 100644 index 0000000..fadf854 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITPortRoaSuccess.java @@ -0,0 +1,51 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 26, 2016 + */ +public class ITPortRoaSuccess extends MyTestManager { + + private static final String GET_PATH = + "src/integration-test/resources/testcase/portroa/queryportsbyidsuccess1.json"; + + private static final String POST_PATH = "src/integration-test/resources/testcase/portroa/createportssuccess1.json"; + + private static final String PUT_PATH = "src/integration-test/resources/testcase/portroa/modportssuccess1.json"; + + private static final String DEL_PATH = "src/integration-test/resources/testcase/portroa/deleteportssuccess1.json"; + + @Test + public void testOperateSuccess() throws ServiceException { + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITResOperateRoaFail.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITResOperateRoaFail.java new file mode 100644 index 0000000..dcb3dd9 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITResOperateRoaFail.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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 15, 2016 + */ +public class ITResOperateRoaFail extends MyTestManager { + + private static final String POST_PATH = + "src/integration-test/resources/testcase/resoperateroa/addresourcefail1.json"; + + private static final String PUT_PATH = + "src/integration-test/resources/testcase/resoperateroa/modresourcefail1.json"; + + private static final String DEL_PATH = + "src/integration-test/resources/testcase/resoperateroa/deleteresourcefail1.json"; + + @Test + public void testOperateFail() throws ServiceException { + execTestCase(new File(POST_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITResOperateRoaSuccess.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITResOperateRoaSuccess.java new file mode 100644 index 0000000..718d688 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITResOperateRoaSuccess.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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.mocoserver.VimDriverSuccessServer; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Oct 15, 2016 + */ +public class ITResOperateRoaSuccess extends MyTestManager { + + private VimDriverSuccessServer driver = new VimDriverSuccessServer(); + + private static final String POST_PATH = + "src/integration-test/resources/testcase/resoperateroa/addresourcesuccess1.json"; + + private static final String PUT_PATH = + "src/integration-test/resources/testcase/resoperateroa/modresourcesuccess1.json"; + + private static final String DEL_PATH = + "src/integration-test/resources/testcase/resoperateroa/deleteresourcesuccess1.json"; + + @Before + public void setup() throws ServiceException, InterruptedException { + driver.start(); + // Thread.sleep(30 * 1000); + } + + @After + public void tearDown() throws ServiceException { + driver.stop(); + } + + @Test + public void testOperateSuccess() throws ServiceException { + execTestCase(new File(POST_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITSitesRoaFail.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITSitesRoaFail.java new file mode 100644 index 0000000..a96c451 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITSitesRoaFail.java @@ -0,0 +1,58 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +public class ITSitesRoaFail extends MyTestManager { + + private static final String GET_PATH = "src/integration-test/resources/testcase/siteroa/querysitesbyidfail1.json"; + + private static final String POST_PATH = "src/integration-test/resources/testcase/siteroa/createsitesfail1.json"; + + private static final String PUT_PATH = "src/integration-test/resources/testcase/siteroa/modsitesfail1.json"; + + private static final String DEL_PATH = "src/integration-test/resources/testcase/siteroa/deletesitesfail1.json"; + + private static final String POST_SUSCCESS_PATH = + "src/integration-test/resources/testcase/siteroa/createsitessuccess1.json"; + + private static final String DEL_SUCCESS_PATH = + "src/integration-test/resources/testcase/siteroa/deletesitessuccess1.json"; + + @Test + public void testOperateFail() throws ServiceException { + execTestCase(new File(POST_SUSCCESS_PATH)); + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + execTestCase(new File(DEL_SUCCESS_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITSitesRoaSuccess.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITSitesRoaSuccess.java new file mode 100644 index 0000000..b7736c3 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/test/ITSitesRoaSuccess.java @@ -0,0 +1,51 @@ +/* + * 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.openo.nfvo.resmanagement.test; + +import java.io.File; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.util.MyTestManager; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +public class ITSitesRoaSuccess extends MyTestManager { + + private static final String GET_PATH = + "src/integration-test/resources/testcase/siteroa/querysitesbyidsuccess1.json"; + + private static final String POST_PATH = "src/integration-test/resources/testcase/siteroa/createsitessuccess1.json"; + + private static final String PUT_PATH = "src/integration-test/resources/testcase/siteroa/modsitessuccess1.json"; + + private static final String DEL_PATH = "src/integration-test/resources/testcase/siteroa/deletesitessuccess1.json"; + + @Test + public void testOperateSuccess() throws ServiceException { + execTestCase(new File(POST_PATH)); + execTestCase(new File(GET_PATH)); + execTestCase(new File(PUT_PATH)); + execTestCase(new File(DEL_PATH)); + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/AddSuccessChecker.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/AddSuccessChecker.java new file mode 100644 index 0000000..48bc3a2 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/AddSuccessChecker.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.openo.nfvo.resmanagement.util; + +import org.openo.sdno.testframework.checker.IChecker; +import org.openo.sdno.testframework.http.model.HttpResponse; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 21, 2016 + */ +public class AddSuccessChecker implements IChecker { + + String addMsg = "org.openo.nfvo.resmanage.common.update.success"; + + @Override + public boolean check(HttpResponse response) { + String data = response.getData(); + System.out.println(data); + JSONObject dataObj = JSONObject.fromObject(data); + if(response.getStatus() == 200 && addMsg.equals(dataObj.getString("msg"))) { + return true; + } + return false; + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/FailureChecker.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/FailureChecker.java new file mode 100644 index 0000000..dc9f7e8 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/FailureChecker.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 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.openo.nfvo.resmanagement.util; + +import org.openo.sdno.testframework.checker.IChecker; +import org.openo.sdno.testframework.http.model.HttpResponse; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 16, 2016 + */ +public class FailureChecker implements IChecker { + + @Override + public boolean check(HttpResponse response) { + String data = response.getData(); + if(response.getStatus() != 200) { + return true; + } + JSONObject dataObj = JSONObject.fromObject(data); + int retCode = (int)dataObj.get("retCode"); + return retCode == -1; + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/GetSuccessChecker.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/GetSuccessChecker.java new file mode 100644 index 0000000..87e9a51 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/GetSuccessChecker.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.openo.nfvo.resmanagement.util; + +import org.openo.sdno.testframework.checker.IChecker; +import org.openo.sdno.testframework.http.model.HttpResponse; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 21, 2016 + */ +public class GetSuccessChecker implements IChecker { + + String addMsg = "org.openo.nfvo.resmanage.common.add.success"; + + @Override + public boolean check(HttpResponse response) { + System.out.println(response); + String data = response.getData(); + System.out.println(data); + JSONObject dataObj = JSONObject.fromObject(data); + if(response.getStatus() == 200 && !dataObj.isEmpty()) { + System.out.println(dataObj.isEmpty()); + return true; + } + return false; + } +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/MyChecker.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/MyChecker.java new file mode 100644 index 0000000..00fd5b6 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/MyChecker.java @@ -0,0 +1,59 @@ +/* + * 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.openo.nfvo.resmanagement.util; + +import org.openo.sdno.testframework.checker.DefaultChecker; +import org.openo.sdno.testframework.http.model.HttpResponse; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 21, 2016 + */ +public class MyChecker extends DefaultChecker { + + private HttpResponse expectedResponse; + + /** + * Constructor
+ *

+ *

+ * + * @param expectedResponse + * @since NFVO 0.5 + */ + public MyChecker(HttpResponse expectedResponse) { + super(expectedResponse); + this.expectedResponse = expectedResponse; + } + + /** + *
+ * + * @param response + * @return + * @since NFVO 0.5 + */ + @Override + public boolean check(HttpResponse response) { + return expectedResponse.equals(response); + } + +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/MyTestManager.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/MyTestManager.java new file mode 100644 index 0000000..97ebe50 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/MyTestManager.java @@ -0,0 +1,163 @@ +/* + * 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.openo.nfvo.resmanagement.util; + +import java.io.File; +import java.util.Iterator; +import java.util.Map; + +import org.junit.Assert; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.sdno.testframework.checker.DefaultChecker; +import org.openo.sdno.testframework.http.model.HttpModelUtils; +import org.openo.sdno.testframework.http.model.HttpRequest; +import org.openo.sdno.testframework.http.model.HttpResponse; +import org.openo.sdno.testframework.http.model.HttpRquestResponse; +import org.openo.sdno.testframework.restclient.HttpRestClient; +import org.openo.sdno.testframework.testmanager.TestManager; +import org.openo.sdno.testframework.util.file.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Sep 21, 2016 + */ +public class MyTestManager extends TestManager { + + private HttpRestClient restClient; + + public MyTestManager() { + restClient = new HttpRestClient(); + } + + private static final Logger LOGGER = LoggerFactory.getLogger(MyTestManager.class); + + /** + *
+ * + * @param file + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @Override + public HttpResponse execTestCase(File file) throws ServiceException { + String content = FileUtils.readFromJson(file); + HttpRquestResponse httpObject = HttpModelUtils.praseHttpRquestResponse(content); + return send(httpObject.getRequest(), httpObject.getResponse()); + } + + private HttpResponse send(HttpRequest request, HttpResponse response) { + try { + RestfulResponse responseResult = doSend(request); + DefaultChecker checker = new MyChecker(response); + HttpResponse httpResponse = HttpModelUtils.convertResponse(responseResult); + Assert.assertEquals(Boolean.valueOf(checker.check(httpResponse)), Boolean.valueOf(true)); + return httpResponse; + } catch(ServiceException e) { + LOGGER.error("call the restful interface failed.", e); + } + return null; + } + + private RestfulResponse doSend(HttpRequest request) throws ServiceException { + String url = request.getUri(); + String method = request.getMethod(); + String body = request.getData(); + RestfulParametes restfulParametes = new RestfulParametes(); + Map requestHeaders = request.getHeaders(); + if(null != requestHeaders) { + java.util.Map.Entry curEntity; + for(Iterator iterator = requestHeaders.entrySet().iterator(); iterator.hasNext(); restfulParametes + .putHttpContextHeader((String)curEntity.getKey(), (String)curEntity.getValue())) + curEntity = (java.util.Map.Entry)iterator.next(); + + } + Map paramMap = request.getQueries(); + if(null != paramMap) + restfulParametes.setParamMap(paramMap); + if(null != body) + restfulParametes.setRawData(body); + return callRestfulMotheds(url, method, restfulParametes); + } + + private RestfulResponse callRestfulMotheds(String url, String method, RestfulParametes restfulParametes) + throws ServiceException { + String s = method; + byte byte0 = -1; + switch(s.hashCode()) { + case 3446944: + if(s.equals("post")) + byte0 = 0; + break; + + case 102230: + if(s.equals("get")) + byte0 = 1; + break; + + case 111375: + if(s.equals("put")) + byte0 = 2; + break; + + case -1335458389: + if(s.equals("delete")) + byte0 = 3; + break; + + case 3198432: + if(s.equals("head")) + byte0 = 4; + break; + + case 106438728: + if(s.equals("patch")) + byte0 = 5; + break; + } + switch(byte0) { + case 0: // '\0' + return restClient.post(url, restfulParametes); + + case 1: // '\001' + return restClient.get(url, restfulParametes); + + case 2: // '\002' + return restClient.put(url, restfulParametes); + + case 3: // '\003' + return restClient.delete(url, restfulParametes); + + case 4: // '\004' + return restClient.head(url, restfulParametes); + + case 5: // '\005' + return restClient.patch(url, restfulParametes); + } + LOGGER.error("The method is unsupported."); + throw new ServiceException("The method is unsupported."); + } + +} diff --git a/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/SuccessChecker.java b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/SuccessChecker.java new file mode 100644 index 0000000..7817e76 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/java/org/openo/nfvo/resmanagement/util/SuccessChecker.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 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.openo.nfvo.resmanagement.util; + +import org.openo.sdno.testframework.checker.IChecker; +import org.openo.sdno.testframework.http.model.HttpResponse; + +import net.sf.json.JSONObject; + +/** + *
+ *

+ *

+ * + * @author + * @version NFVO 0.5 Aug 16, 2016 + */ +public class SuccessChecker implements IChecker { + + String addMsg = "org.openo.nfvo.resmanage.common.add.success"; + + @Override + public boolean check(HttpResponse response) { + String data = response.getData(); + System.out.println(data); + JSONObject dataObj = JSONObject.fromObject(data); + if(response.getStatus() == 200 && addMsg.equals(dataObj.getString("msg"))) { + return true; + } + return false; + } +} diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/getcpulimits.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/getcpulimits.json new file mode 100644 index 0000000..c2eb426 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/getcpulimits.json @@ -0,0 +1,26 @@ +{ + "request": { + "uri": "/openoapi/vimdriver/v1/limits/1234/cpumemory", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "query": { + "vimId": "123" + } + }, + "response": { + "status": 200, + "json": { + "limits": { + "rate": [], + "absolute": { + "maxTotalVolumes": 1000, + "totalVolumesUsed": 14, + "maxTotalVolumeGigabytes": 42000, + "totalGigabytesUsed":1054 + } + } + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/getdisklimits.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/getdisklimits.json new file mode 100644 index 0000000..a99b0df --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/getdisklimits.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/vimdriver/v1/limits/1234/disk", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "query": { + "vimId": "123" + } + }, + "response": { + "status": 200, + "json": { + "vimId": "123", + "vimName": "vim1", + "limits": { + "volumes": 1000, + "gigabytes": 42000, + "snapshots": 100 + } + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/gethost.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/gethost.json new file mode 100644 index 0000000..427d208 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/gethost.json @@ -0,0 +1,51 @@ +{ + "request": { + "uri": "/openoapi/vimdriver/v1/[a-zA-Z0-9\\-\\_]{1,36}/hosts/[a-zA-Z0-9\\-\\_]{1,36}", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "query": { + "vimId": "123", + "tenantId": "1234" + } + }, + "response": { + "status": 200, + "json": { + "hosts": [{ + "resource": { + "cpu": 1, + "disk_gb": 1028, + "host": "c1a7de0ac9d94e4baceae031d05caae3", + "memory_mb": 8192, + "project": "(total)" + }, + "vimId": "123", + "vimName": "vim" + }, + { + "resource": { + "cpu": 0, + "disk_gb": 0, + "host": "c1a7de0ac9d94e4baceae031d05caae3", + "memory_mb": 512, + "project": "(used_now)" + }, + "vimId": "123", + "vimName": "vim" + }, + { + "resource": { + "cpu": 0, + "disk_gb": 0, + "host": "c1a7de0ac9d94e4baceae031d05caae3", + "memory_mb": 0, + "project": "(used_max)" + }, + "vimId": "123", + "vimName": "vim" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/gethosts.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/gethosts.json new file mode 100644 index 0000000..58d315b --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/gethosts.json @@ -0,0 +1,26 @@ +{ + "request": { + "uri": "/openoapi/vimdriver/v1/[a-zA-Z0-9\\-\\_]{1,36}/hosts", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "query": { + "vimId": "123", + "tenantId": "1234" + } + }, + "response": { + "status": 200, + "json": { + "hosts": [ + { + "host_name": "09c025b0efc64211bd23fc50fa974cdf", + "service": "compute", + "zone": "nova", + "vimId": "123", + "vimName": "vim" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/getnetworks.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/getnetworks.json new file mode 100644 index 0000000..e8afa28 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/getnetworks.json @@ -0,0 +1,54 @@ +{ + "request": { + "uri": "/openoapi/vimdriver/v1/networks", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "query": { + "vimId": "123", + "tenantId": "1234" + } + }, + "response": { + "status": 200, + "json": { + "networks": [{ + "status": "ACTIVE", + "subnets": ["54d6f61d-db07-451c-9ab3-b9609b6b6f0b"], + "name": "private-network", + "provider:physical_network": null, + "admin_state_up": true, + "project_id": "4fd44f30292945e481c7b8a0c8908869", + "tenant_id": "4fd44f30292945e481c7b8a0c8908869", + "qos_policy_id": "6a8454ade84346f59e8d40665f878b2e", + "provider:network_type": "local", + "router:external": true, + "mtu": 0, + "shared": true, + "id": "d32019d3-bc6e-4319-9c1d-6722fc136a22", + "provider:segmentation_id": null, + "vimId": "123", + "vimName": "vim" + }, + { + "status": "ACTIVE", + "subnets": ["08eae331-0402-425a-923c-34f7cfe39c1b"], + "name": "private", + "provider:physical_network": null, + "admin_state_up": true, + "project_id": "26a7980765d0414dbc1fc1f88cdb7e6e", + "tenant_id": "26a7980765d0414dbc1fc1f88cdb7e6e", + "qos_policy_id": "bfdb6c39f71e4d44b1dfbda245c50819", + "provider:network_type": "local", + "router:external": true, + "mtu": 0, + "shared": true, + "id": "db193ab3-96e3-4cb3-8fc5-05f4296d0324", + "provider:segmentation_id": null, + "vimId": "123", + "vimName": "vim" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/getports.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/getports.json new file mode 100644 index 0000000..37902ca --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/getports.json @@ -0,0 +1,60 @@ +{ + "request": { + "uri": "/openoapi/vimdriver/v1/ports", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "query": { + "vimId": "123", + "tenantId": "1234" + } + }, + "response": { + "status": 200, + "json": { + "ports": [{ + "status": "ACTIVE", + "name": "", + "allowed_address_pairs": [], + "admin_state_up": true, + "network_id": "70c1db1f-b701-45bd-96e0-a313ee3430b3", + "project_id": "", + "tenant_id": "", + "extra_dhcp_opts": [], + "device_owner": "network:router_gateway", + "mac_address": "fa:16:3e:58:42:ed", + "fixed_ips": [{ + "subnet_id": "008ba151-0b8c-4a67-98b5-0d2b87666062", + "ip_address": "172.24.4.2" + }], + "id": "d80b1a3b-4fc1-49f3-952e-1e2ab7081d8b", + "security_groups": [], + "device_id": "9ae135f4-b6e0-4dad-9e91-3c223e385824", + "vimId": "123", + "vimName": "vim" + }, + { + "status": "ACTIVE", + "name": "", + "allowed_address_pairs": [], + "admin_state_up": true, + "network_id": "f27aa545-cbdd-4907-b0c6-c9e8b039dcc2", + "project_id": "d397de8a63f341818f198abb0966f6f3", + "tenant_id": "d397de8a63f341818f198abb0966f6f3", + "extra_dhcp_opts": [], + "device_owner": "network:router_interface", + "mac_address": "fa:16:3e:bb:3c:e4", + "fixed_ips": [{ + "subnet_id": "288bf4a1-51ba-43b6-9d0a-520e9005db17", + "ip_address": "10.0.0.1" + }], + "id": "f71a6703-d6de-4be1-a91a-a570ede1d159", + "security_groups": [], + "device_id": "9ae135f4-b6e0-4dad-9e91-3c223e385824", + "vimId": "123", + "vimName": "vim" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor1.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor1.json new file mode 100644 index 0000000..9cbc812 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor1.json @@ -0,0 +1,31 @@ +{ + "request": { + "uri": "/openoapi/umcres/v1/resinfo", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "operationType": "create", + "resourceType": "HOST", + "label": "09c025b0efc64211bd23fc50fa974cdf", + "data": [{ + "cpu": "1", + "disk": "1028", + "id": "12345678", + "memory": "8192", + "name": "09c025b0efc64211bd23fc50fa974cdf", + "vimId": "123", + "vimName": "vim" + }] + } + }, + "response": { + "status": 200, + "json": { + "result": "SUCCESS", + "info": "resource monitor info add ok", + "oid": ["12345678"] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor2.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor2.json new file mode 100644 index 0000000..631cf55 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor2.json @@ -0,0 +1,31 @@ +{ + "request": { + "uri": "/openoapi/umcres/v1/resinfo", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "operationType": "update", + "resourceType": "HOST", + "label": "09c025b0efc64211bd23fc50fa974cdf", + "data": [{ + "cpu": "20", + "disk": "100", + "id": "12345678", + "memory": "8", + "name": "09c025b0efc64211bd23fc50fa974cdf", + "vimId": "123", + "vimName": "456" + }] + } + }, + "response": { + "status": 200, + "json": { + "result":"SUCCESS", + "info":"resource monitor info update ok", + "oid":["12345678"] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor3.json b/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor3.json new file mode 100644 index 0000000..4452178 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/mocoserver/sendmsgmonitor3.json @@ -0,0 +1,23 @@ +{ + "request": { + "uri": "/openoapi/umcres/v1/resinfo", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "operationType": "delete", + "resourceType": "HOST", + "label": "09c025b0efc64211bd23fc50fa974cdf", + "deleteIds": ["12345678"] + } + }, + "response": { + "status": 200, + "json": { + "result":"SUCCESS", + "info":"resource monitor info delete ok", + "oid":["12345678"] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/server.properties b/ResmanagementService/service/src/integration-test/resources/server.properties new file mode 100644 index 0000000..44f3fdf --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/server.properties @@ -0,0 +1,14 @@ + +## Integration Test Server Configuration File + +## Server IpAddress +serverip=127.0.0.1 + +## Server Port +serverport=8080 + +## Http Moco Server Port +mocohttpport=12306 + +## Https Moco Server Port +mocohttpsport=12307 \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/createhostsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/createhostsfail1.json new file mode 100644 index 0000000..2966f48 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/createhostsfail1.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/hosts", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id":"12345678", + "name": "hostName", + "cpu": "20", + "memory": "8", + "disk": "100", + "vimId": "123", + "vimName": "456" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.host.add.id.check" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/createhostssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/createhostssuccess1.json new file mode 100644 index 0000000..4573a0c --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/createhostssuccess1.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/hosts", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id":"12345678", + "name": "hostName", + "cpu": "20", + "memory": "8", + "disk": "100", + "vimId": "123", + "vimName": "456" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.add.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/deletehostsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/deletehostsfail1.json new file mode 100644 index 0000000..5144c9a --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/deletehostsfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/hosts?id=aaaa", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/deletehostssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/deletehostssuccess1.json new file mode 100644 index 0000000..98f3d13 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/deletehostssuccess1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/hosts?id=12345678", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/modhostsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/modhostsfail1.json new file mode 100644 index 0000000..de24b26 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/modhostsfail1.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/hosts", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id":"aaaa", + "name": "newName", + "cpu": "20", + "memory": "8", + "disk": "100", + "vimId": "123", + "vimName": "456" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/modhostssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/modhostssuccess1.json new file mode 100644 index 0000000..3280951 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/modhostssuccess1.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/hosts", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id":"12345678", + "name": "hostName", + "cpu": "20", + "memory": "8", + "disk": "100", + "vimId": "123", + "vimName": "456" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/queryhostsbyidfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/queryhostsbyidfail1.json new file mode 100644 index 0000000..fe528b2 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/queryhostsbyidfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/hosts/aaaa", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "hosts": [] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/queryhostsbyidsuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/queryhostsbyidsuccess1.json new file mode 100644 index 0000000..0cccaa0 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/hostroa/queryhostsbyidsuccess1.json @@ -0,0 +1,23 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/hosts/12345678", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "hosts": [{ + "cpu": "20", + "disk": "100", + "id": "12345678", + "memory": "8", + "name": "hostName", + "vimId": "123", + "vimName": "456" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/limitsroa/querycpulimitssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/limitsroa/querycpulimitssuccess1.json new file mode 100644 index 0000000..8b24164 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/limitsroa/querycpulimitssuccess1.json @@ -0,0 +1,23 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/limits/1234/cpu?vimId=123", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "limits": { + "rate": [], + "absolute": { + "maxTotalVolumes": 1000, + "totalVolumesUsed": 14, + "maxTotalVolumeGigabytes": 42000, + "totalGigabytesUsed":1054 + } + } + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/limitsroa/querydisklimitssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/limitsroa/querydisklimitssuccess1.json new file mode 100644 index 0000000..7da9cdb --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/limitsroa/querydisklimitssuccess1.json @@ -0,0 +1,21 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/limits/1234/disk?vimId=123", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "vimId": "123", + "vimName": "vim1", + "limits": { + "volumes": 1000, + "gigabytes": 42000, + "snapshots": 100 + } + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/createlocationsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/createlocationsfail1.json new file mode 100644 index 0000000..c490bc9 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/createlocationsfail1.json @@ -0,0 +1,23 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/locations", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "country": "china", + "location": "shenzhen", + "latitude": "11", + "longitude": "22.2", + "description": "" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.base.location.add.entity.check" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/createlocationssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/createlocationssuccess1.json new file mode 100644 index 0000000..fb4b97a --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/createlocationssuccess1.json @@ -0,0 +1,23 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/locations", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "country": "china", + "location": "shenzhen", + "latitude": "11", + "longitude": "22.2", + "description": "" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.add.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/deletelocationsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/deletelocationsfail1.json new file mode 100644 index 0000000..136096d --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/deletelocationsfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/locations/aaaa", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/deletelocationssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/deletelocationssuccess1.json new file mode 100644 index 0000000..eaaf8d9 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/deletelocationssuccess1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/locations/12345678", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/modlocationsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/modlocationsfail1.json new file mode 100644 index 0000000..d362898 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/modlocationsfail1.json @@ -0,0 +1,23 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/locations", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "aaaa", + "country": "china", + "location": "shenzhen", + "latitude": "11.1", + "longitude": "22.2", + "description": "" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.base.location.update.modified.check" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/modlocationssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/modlocationssuccess1.json new file mode 100644 index 0000000..3205272 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/modlocationssuccess1.json @@ -0,0 +1,23 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/locations", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "country": "china", + "location": "shenzhen", + "latitude": "11.1", + "longitude": "22.2", + "description": "" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/querylocationsbyidfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/querylocationsbyidfail1.json new file mode 100644 index 0000000..b49a37d --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/querylocationsbyidfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/locations/aaaa", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "locations": [] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/querylocationsbyidsuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/querylocationsbyidsuccess1.json new file mode 100644 index 0000000..387adc9 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/locationroa/querylocationsbyidsuccess1.json @@ -0,0 +1,22 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/locations/12345678", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "locations": [{ + "country": "china", + "description": "", + "id": "12345678", + "latitude": "11", + "location": "shenzhen", + "longitude": "22.2" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/createnetworksfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/createnetworksfail1.json new file mode 100644 index 0000000..014d49f --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/createnetworksfail1.json @@ -0,0 +1,26 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/networks", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "name": "name1", + "tenantId": "111111", + "status": "active", + "vimId": "123", + "vimName": "vimName", + "physicalNetwork": "physnet1", + "networkType": "vlan", + "segmentationId": "26" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.base.network.add.entity.check" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/createnetworkssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/createnetworkssuccess1.json new file mode 100644 index 0000000..b909858 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/createnetworkssuccess1.json @@ -0,0 +1,26 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/networks", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "name": "name1", + "tenantId": "111111", + "status": "active", + "vimId": "123", + "vimName": "vimName", + "physicalNetwork": "physnet1", + "networkType": "vlan", + "segmentationId": "26" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.add.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/deletenetworksfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/deletenetworksfail1.json new file mode 100644 index 0000000..d3a5e5a --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/deletenetworksfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/networks?id=aaaa", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/deletenetworkssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/deletenetworkssuccess1.json new file mode 100644 index 0000000..1e56c4b --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/deletenetworkssuccess1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/networks?id=12345678", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/modnetworksfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/modnetworksfail1.json new file mode 100644 index 0000000..2852a2a --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/modnetworksfail1.json @@ -0,0 +1,26 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/networks", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "aaaa", + "name": "newName1", + "tenantId": "111111", + "status": "active", + "vimId": "123", + "vimName": "vimName", + "physicalNetwork": "physnet1", + "networkType": "vlan", + "segmentationId": "26" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/modnetworkssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/modnetworkssuccess1.json new file mode 100644 index 0000000..fc6aed8 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/modnetworkssuccess1.json @@ -0,0 +1,26 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/networks", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "name": "newName1", + "tenantId": "111111", + "status": "active", + "vimId": "123", + "vimName": "vimName", + "physicalNetwork": "physnet1", + "networkType": "vlan", + "segmentationId": "26" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/querynetworksbyidfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/querynetworksbyidfail1.json new file mode 100644 index 0000000..ae888cf --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/querynetworksbyidfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/networks/aaaa", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "networks": [] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/querynetworksbyidsuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/querynetworksbyidsuccess1.json new file mode 100644 index 0000000..b933eb4 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/networkroa/querynetworksbyidsuccess1.json @@ -0,0 +1,25 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/networks/12345678", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "networks": [{ + "id": "12345678", + "name": "name1", + "tenant_id": "111111", + "status": "active", + "vimId": "123", + "vimName": "vimName", + "provider:physical_network": "physnet1", + "provider:network_type": "vlan", + "provider:segmentation_id": "26" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/portroa/createportsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/createportsfail1.json new file mode 100644 index 0000000..7270bf4 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/createportsfail1.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/ports", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "name": "portName", + "networkId": "1111", + "status": "ACTIVE", + "tenantId": "123456", + "vimId": "11", + "vimName": "22" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.port.add.id.check" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/portroa/createportssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/createportssuccess1.json new file mode 100644 index 0000000..b31d469 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/createportssuccess1.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/ports", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "name": "portName", + "networkId": "1111", + "status": "ACTIVE", + "tenantId": "123456", + "vimId": "11", + "vimName": "22" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.add.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/portroa/deleteportsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/deleteportsfail1.json new file mode 100644 index 0000000..c4e3659 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/deleteportsfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/ports?id=aaaa", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/portroa/deleteportssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/deleteportssuccess1.json new file mode 100644 index 0000000..843593d --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/deleteportssuccess1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/ports?id=12345678", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/portroa/modportsfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/modportsfail1.json new file mode 100644 index 0000000..6c3f521 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/modportsfail1.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/ports", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "aaaa", + "name": "portName", + "networkId": "1111", + "status": "ACTIVE", + "tenantId": "123456", + "vimId": "11", + "vimName": "22" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/portroa/modportssuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/modportssuccess1.json new file mode 100644 index 0000000..583764c --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/modportssuccess1.json @@ -0,0 +1,24 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/ports", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "id": "12345678", + "name": "newName", + "networkId": "1111", + "status": "ACTIVE", + "tenantId": "123456", + "vimId": "11", + "vimName": "22" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/portroa/queryportsbyidfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/queryportsbyidfail1.json new file mode 100644 index 0000000..6a1007f --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/queryportsbyidfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/ports/aaaa", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "ports": [] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/portroa/queryportsbyidsuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/queryportsbyidsuccess1.json new file mode 100644 index 0000000..4fe360f --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/portroa/queryportsbyidsuccess1.json @@ -0,0 +1,23 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/ports/12345678", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "ports": [{ + "id": "12345678", + "name": "portName", + "networkId": "1111", + "status": "ACTIVE", + "tenantId": "123456", + "vimId": "11", + "vimName": "22" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/addresourcefail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/addresourcefail1.json new file mode 100644 index 0000000..a604f52 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/addresourcefail1.json @@ -0,0 +1,18 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/resoperate/resmgr/vims?tenantId=1234", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.vimId" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/addresourcesuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/addresourcesuccess1.json new file mode 100644 index 0000000..b23f38f --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/addresourcesuccess1.json @@ -0,0 +1,18 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/resoperate/resmgr/vims?tenantId=1234&vimId=123", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.add.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/deleteresourcefail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/deleteresourcefail1.json new file mode 100644 index 0000000..d60484c --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/deleteresourcefail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/resoperate", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.group.resoperate.res.no.vimId" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/deleteresourcesuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/deleteresourcesuccess1.json new file mode 100644 index 0000000..4b099ae --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/deleteresourcesuccess1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/resoperate?vimId=123", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/modresourcefail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/modresourcefail1.json new file mode 100644 index 0000000..0a54e89 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/modresourcefail1.json @@ -0,0 +1,17 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/resoperate/updateres?tenantId=1234", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.group.resoperate.add.res.no.result" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/modresourcesuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/modresourcesuccess1.json new file mode 100644 index 0000000..c3196c1 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/resoperateroa/modresourcesuccess1.json @@ -0,0 +1,17 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/resoperate/updateres?tenantId=1234&vimId=123", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/createsitesfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/createsitesfail1.json new file mode 100644 index 0000000..5584c1e --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/createsitesfail1.json @@ -0,0 +1,30 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/datacenters", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "country": "china", + "id": "12345678", + "location": "shanghai", + "name": "shanghai", + "status": "active", + "totalCPU": "100", + "totalDisk": "100", + "totalMemory": "100", + "usedCPU": "10", + "usedDisk": "10", + "usedMemory": "10", + "vimId": "123", + "vimName": "vimName" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.service.base.site.add.id.check" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/createsitessuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/createsitessuccess1.json new file mode 100644 index 0000000..af0d3af --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/createsitessuccess1.json @@ -0,0 +1,30 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/datacenters", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "country": "china", + "id": "12345678", + "location": "shanghai", + "name": "shanghai", + "status": "active", + "totalCPU": "100", + "totalDisk": "100", + "totalMemory": "100", + "usedCPU": "0", + "usedDisk": "0", + "usedMemory": "0", + "vimId": "123", + "vimName": "vimName" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.add.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/deletesitesfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/deletesitesfail1.json new file mode 100644 index 0000000..aacd3fe --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/deletesitesfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/datacenters/aaaa", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/deletesitessuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/deletesitessuccess1.json new file mode 100644 index 0000000..d4b083b --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/deletesitessuccess1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/datacenters/12345678", + "method": "delete", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.del.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/modsitesfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/modsitesfail1.json new file mode 100644 index 0000000..2c1be4e --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/modsitesfail1.json @@ -0,0 +1,30 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/datacenters", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "country": "china", + "id": "aaaa", + "location": "shanghai", + "name": "newName", + "status": "active", + "totalCPU": "100", + "totalDisk": "100", + "totalMemory": "100", + "usedCPU": "0", + "usedDisk": "0", + "usedMemory": "0", + "vimId": "123", + "vimName": "vimName" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.error" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/modsitessuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/modsitessuccess1.json new file mode 100644 index 0000000..da19356 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/modsitessuccess1.json @@ -0,0 +1,30 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/datacenters", + "method": "put", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "country": "china", + "id": "12345678", + "location": "shanghai", + "name": "newName", + "status": "active", + "totalCPU": "100", + "totalDisk": "100", + "totalMemory": "100", + "usedCPU": "0", + "usedDisk": "0", + "usedMemory": "0", + "vimId": "123", + "vimName": "vimName" + } + }, + "response": { + "status": 200, + "json": { + "msg": "org.openo.nfvo.resmanage.common.update.success" + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/querysitesbyidfail1.json b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/querysitesbyidfail1.json new file mode 100644 index 0000000..b12b02c --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/querysitesbyidfail1.json @@ -0,0 +1,15 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/datacenters/aaaa", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "datacenters": [] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/querysitesbyidsuccess1.json b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/querysitesbyidsuccess1.json new file mode 100644 index 0000000..984a7eb --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/testcase/siteroa/querysitesbyidsuccess1.json @@ -0,0 +1,29 @@ +{ + "request": { + "uri": "/openoapi/resmgr/v1/datacenters/12345678", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + } + }, + "response": { + "status": 200, + "json": { + "datacenters": [{ + "country": "china", + "id": "12345678", + "location": "shanghai", + "name": "shanghai", + "status": "active", + "totalCPU": "100", + "totalDisk": "100", + "totalMemory": "100", + "usedCPU": "0", + "usedDisk": "0", + "usedMemory": "0", + "vimId": "123", + "vimName": "vimName" + }] + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/integration-test/resources/urlconfig.json b/ResmanagementService/service/src/integration-test/resources/urlconfig.json new file mode 100644 index 0000000..9d07650 --- /dev/null +++ b/ResmanagementService/service/src/integration-test/resources/urlconfig.json @@ -0,0 +1,18 @@ +[ + { + "url": "/svc/ipsec/v1", + "prefix": "/org.openo.sdno.ipsecservice" + }, + { + "url": "/v2.0/tokens", + "prefix": "" + }, + { + "url": "/v2.0/networks", + "prefix": "" + }, + { + "url": "/rest/v1/resmanage/virtualnetworks", + "prefix": "" + } +] \ No newline at end of file diff --git a/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/ResourceUtil.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/ResourceUtil.java new file mode 100644 index 0000000..572de2b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/common/VimUtil.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/VimUtil.java new file mode 100644 index 0000000..5f2d417 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.common; + +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; +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/openo/nfvo/resmanagement/common/constant/Constant.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/Constant.java new file mode 100644 index 0000000..1e5941d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/common/constant/HttpConstant.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/HttpConstant.java new file mode 100644 index 0000000..f480b70 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/common/constant/ParamConstant.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/ParamConstant.java new file mode 100644 index 0000000..9ba0c4c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/common/constant/ResponseConstant.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/ResponseConstant.java new file mode 100644 index 0000000..a4fe9e0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.common.constant; + +import org.openo.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/openo/nfvo/resmanagement/common/constant/UrlConstant.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/constant/UrlConstant.java new file mode 100644 index 0000000..b9a93a1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/common/util/JsonUtil.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/JsonUtil.java new file mode 100644 index 0000000..5440a7a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.common.util; + +import org.openo.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/openo/nfvo/resmanagement/common/util/RestfulUtil.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/RestfulUtil.java new file mode 100644 index 0000000..e644e27 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.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.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.Constant; +import org.openo.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; + +/** + * 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/openo/nfvo/resmanagement/common/util/StringUtil.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/StringUtil.java new file mode 100644 index 0000000..fd8f09f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/common/util/request/RequestUtil.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtil.java new file mode 100644 index 0000000..5eae4e3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/common/util/response/ResponseUtil.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtil.java new file mode 100644 index 0000000..d6b1415 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/common/util/response/RoaResponseUtil.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtil.java new file mode 100644 index 0000000..dbb034d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.common.util.response; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.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/openo/nfvo/resmanagement/service/activator/ROAResmgrServicePostProcessor.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/activator/ROAResmgrServicePostProcessor.java new file mode 100644 index 0000000..ad66303 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.activator; + +import org.openo.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/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManager.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManager.java new file mode 100644 index 0000000..9e523e3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.adapter.impl; + +import java.util.Map; + +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.resmanagement.common.constant.Constant; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.nfvo.resmanagement.service.adapter.inf.IResmgrAdapter2MSBManager; +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/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrService.java new file mode 100644 index 0000000..ea9a53d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.util.impl.SystemEnvVariablesFactory; +import org.openo.nfvo.resmanagement.common.constant.Constant; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.service.adapter.inf.IResmgrAdapter2MSBManager; +import org.openo.nfvo.resmanagement.service.adapter.inf.IResmgrAdapterMgrService; +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/openo/nfvo/resmanagement/service/adapter/inf/IResmgrAdapter2MSBManager.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/adapter/inf/IResmgrAdapter2MSBManager.java new file mode 100644 index 0000000..df00261 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/adapter/inf/IResmgrAdapterMgrService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/adapter/inf/IResmgrAdapterMgrService.java new file mode 100644 index 0000000..05d4739 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/base/openstack/impl/HostImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImpl.java new file mode 100644 index 0000000..131d7c7 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Host; +import org.openo.nfvo.resmanagement.service.business.inf.HostBusiness; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImpl.java new file mode 100644 index 0000000..346ac84 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.VimUtil; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Location; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.openo.nfvo.resmanagement.service.business.inf.LocationBusiness; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +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/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImpl.java new file mode 100644 index 0000000..b9ec757 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Network; +import org.openo.nfvo.resmanagement.service.business.inf.NetworkBusiness; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +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/openo/nfvo/resmanagement/service/base/openstack/impl/PortImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImpl.java new file mode 100644 index 0000000..3dee172 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Port; +import org.openo.nfvo.resmanagement.service.business.inf.PortBusiness; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; +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/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImpl.java new file mode 100644 index 0000000..6b9345e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.VimUtil; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.openo.nfvo.resmanagement.service.business.inf.LimitsBusiness; +import org.openo.nfvo.resmanagement.service.business.inf.SitesBusiness; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.nfvo.resmanagement.service.group.inf.ResOperateService; +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/openo/nfvo/resmanagement/service/base/openstack/impl/VimImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/VimImpl.java new file mode 100644 index 0000000..d1405a2 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.impl; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Vim; +import org.openo.nfvo.resmanagement.service.business.inf.VimBusiness; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/inf/Host.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Host.java new file mode 100644 index 0000000..44adb19 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/inf/InterfaceResManagement.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/InterfaceResManagement.java new file mode 100644 index 0000000..a89e48e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/base/openstack/inf/Location.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Location.java new file mode 100644 index 0000000..7ee574c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/inf/Network.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Network.java new file mode 100644 index 0000000..bd00e1a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/inf/Port.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Port.java new file mode 100644 index 0000000..3ef79b3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/inf/ResManagement.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/ResManagement.java new file mode 100644 index 0000000..8acbf77 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/base/openstack/inf/Sites.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Sites.java new file mode 100644 index 0000000..ab2e104 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/inf/Vim.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/base/openstack/inf/Vim.java new file mode 100644 index 0000000..f923e0f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; + +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/openo/nfvo/resmanagement/service/business/impl/HostBusinessImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImpl.java new file mode 100644 index 0000000..6da2657 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.service.business.inf.HostBusiness; +import org.openo.nfvo.resmanagement.service.dao.inf.HostDao; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; +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/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImpl.java new file mode 100644 index 0000000..eeb2de0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.business.impl; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.VimUtil; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.nfvo.resmanagement.service.business.inf.LimitsBusiness; +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/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImpl.java new file mode 100644 index 0000000..76ee2a0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.util.StringUtil; +import org.openo.nfvo.resmanagement.service.business.inf.LocationBusiness; +import org.openo.nfvo.resmanagement.service.dao.inf.LocationDao; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; +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/openo/nfvo/resmanagement/service/business/impl/NetworkBusinessImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/NetworkBusinessImpl.java new file mode 100644 index 0000000..811c3e4 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.service.business.inf.NetworkBusiness; +import org.openo.nfvo.resmanagement.service.dao.inf.NetworkDao; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +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/openo/nfvo/resmanagement/service/business/impl/PortBusinessImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/PortBusinessImpl.java new file mode 100644 index 0000000..ce715d9 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.service.business.inf.PortBusiness; +import org.openo.nfvo.resmanagement.service.dao.inf.PortDao; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; +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/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImpl.java new file mode 100644 index 0000000..6ffb3fc --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.service.business.inf.SitesBusiness; +import org.openo.nfvo.resmanagement.service.dao.inf.SitesDao; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +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/openo/nfvo/resmanagement/service/business/impl/VimBusinessImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImpl.java new file mode 100644 index 0000000..6cbcfc4 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.business.impl; + +import java.util.List; + +import org.apache.commons.lang3.StringUtils; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.util.StringUtil; +import org.openo.nfvo.resmanagement.service.business.inf.VimBusiness; +import org.openo.nfvo.resmanagement.service.dao.inf.VimDao; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; +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/openo/nfvo/resmanagement/service/business/inf/HostBusiness.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/HostBusiness.java new file mode 100644 index 0000000..803c96e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; + +/** + * 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/openo/nfvo/resmanagement/service/business/inf/LimitsBusiness.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/LimitsBusiness.java new file mode 100644 index 0000000..b78b6a8 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/business/inf/LocationBusiness.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/LocationBusiness.java new file mode 100644 index 0000000..fd5cef2 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; + +/** + * + * 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/openo/nfvo/resmanagement/service/business/inf/NetworkBusiness.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/NetworkBusiness.java new file mode 100644 index 0000000..be0c9dc --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; + +/** + * + * 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/openo/nfvo/resmanagement/service/business/inf/PortBusiness.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/PortBusiness.java new file mode 100644 index 0000000..b81a3e1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; + +/** + * 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/openo/nfvo/resmanagement/service/business/inf/SitesBusiness.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/SitesBusiness.java new file mode 100644 index 0000000..8d11a39 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.business.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; + +/** + * 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/openo/nfvo/resmanagement/service/business/inf/VimBusiness.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/business/inf/VimBusiness.java new file mode 100644 index 0000000..8806e7a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.business.inf; + +import java.util.List; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; + +/** + * 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/openo/nfvo/resmanagement/service/dao/impl/AbstractDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/AbstractDao.java new file mode 100644 index 0000000..e3a76ca --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/dao/impl/HostDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImpl.java new file mode 100644 index 0000000..1c5c03c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.openo.nfvo.resmanagement.service.dao.inf.HostDao; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImpl.java new file mode 100644 index 0000000..949f19f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.openo.nfvo.resmanagement.service.dao.inf.LocationDao; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImpl.java new file mode 100644 index 0000000..12769a2 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.openo.nfvo.resmanagement.service.dao.inf.NetworkDao; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/PortDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImpl.java new file mode 100644 index 0000000..e113c7a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.openo.nfvo.resmanagement.service.dao.inf.PortDao; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImpl.java new file mode 100644 index 0000000..2d29d7b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.openo.nfvo.resmanagement.service.dao.inf.SitesDao; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/VimDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImpl.java new file mode 100644 index 0000000..e73b251 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; + +import org.openo.nfvo.resmanagement.service.dao.impl.AbstractDao; +import org.openo.nfvo.resmanagement.service.dao.inf.VimDao; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImpl.java new file mode 100644 index 0000000..96ed906 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.inf.VirtualLinkDao; +import org.openo.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/VmDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImpl.java new file mode 100644 index 0000000..ee3806c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.inf.VmDao; +import org.openo.nfvo.resmanagement.service.entity.VmEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/VnfDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VnfDaoImpl.java new file mode 100644 index 0000000..42bb5b5 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.inf.VnfDao; +import org.openo.nfvo.resmanagement.service.entity.VnfEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/VnfInfoDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VnfInfoDaoImpl.java new file mode 100644 index 0000000..6e8d32b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.inf.VnfInfoDao; +import org.openo.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/impl/VnfStatusDaoImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/impl/VnfStatusDaoImpl.java new file mode 100644 index 0000000..ed7db95 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.nfvo.resmanagement.service.dao.inf.VnfStatusDao; +import org.openo.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/HostDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/HostDao.java new file mode 100644 index 0000000..a48c6aa --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/LocationDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/LocationDao.java new file mode 100644 index 0000000..dcf2c9f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/NetworkDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/NetworkDao.java new file mode 100644 index 0000000..0725bd9 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/PortDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/PortDao.java new file mode 100644 index 0000000..f558b5d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/SitesDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/SitesDao.java new file mode 100644 index 0000000..f978c8b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/VimDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VimDao.java new file mode 100644 index 0000000..1b17a46 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/VirtualLinkDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VirtualLinkDao.java new file mode 100644 index 0000000..ead3975 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/VmDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VmDao.java new file mode 100644 index 0000000..6d2b6b6 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/VnfDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VnfDao.java new file mode 100644 index 0000000..7f72ce3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/VnfInfoDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VnfInfoDao.java new file mode 100644 index 0000000..9e2aade --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/dao/inf/VnfStatusDao.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/dao/inf/VnfStatusDao.java new file mode 100644 index 0000000..ef5ba9b --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.dao.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/entity/HostEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/HostEntity.java new file mode 100644 index 0000000..f8166da --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/LocationEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/LocationEntity.java new file mode 100644 index 0000000..eab8ca0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/NetworkEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntity.java new file mode 100644 index 0000000..f65ad37 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/PortEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/PortEntity.java new file mode 100644 index 0000000..4700554 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/SitesEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/SitesEntity.java new file mode 100644 index 0000000..33c1942 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.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/openo/nfvo/resmanagement/service/entity/VimEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VimEntity.java new file mode 100644 index 0000000..9959101 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/VirtualLinkEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VirtualLinkEntity.java new file mode 100644 index 0000000..c9a38d9 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/VmEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VmEntity.java new file mode 100644 index 0000000..e01cabd --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/VnfEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VnfEntity.java new file mode 100644 index 0000000..3a18524 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/VnfInfoEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VnfInfoEntity.java new file mode 100644 index 0000000..023f491 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/entity/VnfStatusEntity.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/entity/VnfStatusEntity.java new file mode 100644 index 0000000..290f264 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.entity; + +import java.io.Serializable; + +import org.apache.commons.lang3.StringUtils; +import org.openo.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/openo/nfvo/resmanagement/service/group/impl/GrantResServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/GrantResServiceImpl.java new file mode 100644 index 0000000..4a8a633 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.impl; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.VimUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.openo.nfvo.resmanagement.service.group.inf.GrantResService; +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/openo/nfvo/resmanagement/service/group/impl/IResourceAddServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/IResourceAddServiceImpl.java new file mode 100644 index 0000000..0699b98 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement; +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/openo/nfvo/resmanagement/service/group/impl/IResourceDelServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/IResourceDelServiceImpl.java new file mode 100644 index 0000000..59cff09 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Vim; +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/openo/nfvo/resmanagement/service/group/impl/IResourceUpdateServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/IResourceUpdateServiceImpl.java new file mode 100644 index 0000000..b789bf9 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.impl; + +import java.util.HashMap; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement; +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/openo/nfvo/resmanagement/service/group/impl/ResOperateServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/ResOperateServiceImpl.java new file mode 100644 index 0000000..788e487 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.Constant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.nfvo.resmanagement.common.util.StringUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Host; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.InterfaceResManagement; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Network; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Port; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Vim; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.nfvo.resmanagement.service.group.inf.ResOperateService; +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/openo/nfvo/resmanagement/service/group/impl/VirtualLinkServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VirtualLinkServiceImpl.java new file mode 100644 index 0000000..5dd726c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.service.dao.inf.VirtualLinkDao; +import org.openo.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VirtualLinkService; +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.openo.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/openo/nfvo/resmanagement/service/group/impl/VmServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VmServiceImpl.java new file mode 100644 index 0000000..51ec0dd --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; +import org.openo.nfvo.resmanagement.service.dao.inf.VmDao; +import org.openo.nfvo.resmanagement.service.entity.VmEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VmService; +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/openo/nfvo/resmanagement/service/group/impl/VnfInfoServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VnfInfoServiceImpl.java new file mode 100644 index 0000000..fb34127 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.dao.inf.VnfInfoDao; +import org.openo.nfvo.resmanagement.service.entity.VmEntity; +import org.openo.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VmService; +import org.openo.nfvo.resmanagement.service.group.inf.VnfInfoService; +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/openo/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VnfServiceImpl.java new file mode 100644 index 0000000..3a1a02e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.service.dao.inf.VnfDao; +import org.openo.nfvo.resmanagement.service.entity.VnfEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VnfInfoService; +import org.openo.nfvo.resmanagement.service.group.inf.VnfService; +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.openo.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/openo/nfvo/resmanagement/service/group/impl/VnfStatusServiceImpl.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/impl/VnfStatusServiceImpl.java new file mode 100644 index 0000000..7e37561 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.impl; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.dao.inf.VnfStatusDao; +import org.openo.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VnfStatusService; +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/openo/nfvo/resmanagement/service/group/inf/GrantResService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/GrantResService.java new file mode 100644 index 0000000..4c52b9c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/group/inf/ResOperateService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/ResOperateService.java new file mode 100644 index 0000000..7e2069f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/group/inf/VirtualLinkService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VirtualLinkService.java new file mode 100644 index 0000000..cd1ea93 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.VirtualLinkEntity; + +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/openo/nfvo/resmanagement/service/group/inf/VmService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VmService.java new file mode 100644 index 0000000..668f9d3 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.VmEntity; + +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/openo/nfvo/resmanagement/service/group/inf/VnfInfoService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VnfInfoService.java new file mode 100644 index 0000000..6e736d6 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.VnfInfoEntity; + +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/openo/nfvo/resmanagement/service/group/inf/VnfService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VnfService.java new file mode 100644 index 0000000..4fbe45e --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.VnfEntity; + +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/openo/nfvo/resmanagement/service/group/inf/VnfStatusService.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/group/inf/VnfStatusService.java new file mode 100644 index 0000000..cdc826c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.group.inf; + +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.VnfStatusEntity; + +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/openo/nfvo/resmanagement/service/mapper/HostMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/HostMapper.java new file mode 100644 index 0000000..643c581 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/LocationMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/LocationMapper.java new file mode 100644 index 0000000..2a2ec5c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/NetworkMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/NetworkMapper.java new file mode 100644 index 0000000..b727f4f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/PortMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/PortMapper.java new file mode 100644 index 0000000..9cae421 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/SitesMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/SitesMapper.java new file mode 100644 index 0000000..e86d5e1 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/VimMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VimMapper.java new file mode 100644 index 0000000..1c4573a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/VirtualLinkMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VirtualLinkMapper.java new file mode 100644 index 0000000..c4cba74 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/VmMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VmMapper.java new file mode 100644 index 0000000..4cb4878 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/VnfInfoMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VnfInfoMapper.java new file mode 100644 index 0000000..45d4f45 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/VnfMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VnfMapper.java new file mode 100644 index 0000000..5d0078f --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/mapper/VnfStatusMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/mapper/VnfStatusMapper.java new file mode 100644 index 0000000..c7e5c7a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.nfvo.resmanagement.service.mapper; + +import java.util.List; +import java.util.Map; + +import org.openo.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/openo/nfvo/resmanagement/service/rest/GrantResourseRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoa.java new file mode 100644 index 0000000..47a9a02 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.service.group.inf.GrantResService; +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/openo/nfvo/resmanagement/service/rest/HostRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/HostRoa.java new file mode 100644 index 0000000..98e7da0 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Host; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; +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/openo/nfvo/resmanagement/service/rest/LimitsRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoa.java new file mode 100644 index 0000000..5275dfe --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.service.business.inf.LimitsBusiness; +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/openo/nfvo/resmanagement/service/rest/LocationRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/LocationRoa.java new file mode 100644 index 0000000..f3bb351 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Location; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +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/openo/nfvo/resmanagement/service/rest/NetworkRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoa.java new file mode 100644 index 0000000..8a3e0bd --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Network; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +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/openo/nfvo/resmanagement/service/rest/PortRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/PortRoa.java new file mode 100644 index 0000000..1d79f93 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Port; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; +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/openo/nfvo/resmanagement/service/rest/ResOperateRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoa.java new file mode 100644 index 0000000..1e68e83 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.VimUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.group.inf.ResOperateService; +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/openo/nfvo/resmanagement/service/rest/SitesRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/SitesRoa.java new file mode 100644 index 0000000..192d33d --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.VimUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +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/openo/nfvo/resmanagement/service/rest/SwaggerRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoa.java new file mode 100644 index 0000000..0e9bf48 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/rest/VirtualLinkRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoa.java new file mode 100644 index 0000000..524a474 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VirtualLinkService; +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/openo/nfvo/resmanagement/service/rest/VmRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VmRoa.java new file mode 100644 index 0000000..cb9d2b6 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.entity.VmEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VmService; +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/openo/nfvo/resmanagement/service/rest/VnfInfoRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoa.java new file mode 100644 index 0000000..b6fd5a5 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VnfInfoService; +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/openo/nfvo/resmanagement/service/rest/VnfRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VnfRoa.java new file mode 100644 index 0000000..4d5fc47 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.entity.VnfEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VnfService; +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/openo/nfvo/resmanagement/service/rest/VnfStatusRoa.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoa.java new file mode 100644 index 0000000..1e7d9f4 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.ResourceUtil; +import org.openo.nfvo.resmanagement.common.constant.HttpConstant; +import org.openo.nfvo.resmanagement.common.constant.ParamConstant; +import org.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.common.util.response.ResponseUtil; +import org.openo.nfvo.resmanagement.common.util.response.RoaResponseUtil; +import org.openo.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.openo.nfvo.resmanagement.service.group.inf.VnfStatusService; +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/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessage.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessage.java new file mode 100644 index 0000000..8f57345 --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapper.java new file mode 100644 index 0000000..d557e0c --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapper.java b/ResmanagementService/service/src/main/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapper.java new file mode 100644 index 0000000..a45852a --- /dev/null +++ b/ResmanagementService/service/src/main/java/org/openo/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.openo.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/log4j.properties b/ResmanagementService/service/src/main/resources/log4j.properties new file mode 100644 index 0000000..d371d16 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/log4j.properties @@ -0,0 +1,23 @@ +############################################################################### +# 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. +############################################################################### +log4j.rootLogger=INFO,root +log4j.appender.root.Append=true +log4j.appender.root.File=${catalina.base}/logs/resmanagement.log +log4j.appender.root.layout.ConversionPattern=%d %-5p [%t][%X{moduleID}][%C %L] %m%n +log4j.appender.root.layout=org.apache.log4j.PatternLayout +log4j.appender.root.MaxBackupIndex=50 +log4j.appender.root.MaxFileSize=20MB +log4j.appender.root=org.apache.log4j.RollingFileAppender \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/HostMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/HostMapper.xml new file mode 100644 index 0000000..850eef4 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/HostMapper.xml @@ -0,0 +1,189 @@ + + + + + + + + + + + + + + + + ID, NAME, CPU, MEMORY, DISK, VIM_ID, VIM_NAME + + + + + delete from host + where ID = #{id,jdbcType=VARCHAR} + + + delete from host + where VIM_ID = #{vimId,jdbcType=VARCHAR} + + + insert into host (ID, NAME, CPU, MEMORY, DISK, VIM_ID, VIM_NAME) + values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, + #{cpu,jdbcType=VARCHAR}, + #{memory,jdbcType=VARCHAR}, #{disk,jdbcType=VARCHAR}, #{vimId,jdbcType=VARCHAR} + , #{vimName,jdbcType=VARCHAR}) + + + insert into host + + + ID, + + + NAME, + + + CPU, + + + MEMORY, + + + DISK, + + + VIM_ID, + + + VIM_NAME, + + + + + #{id,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{cpu,jdbcType=VARCHAR}, + + + #{memory,jdbcType=VARCHAR}, + + + #{disk,jdbcType=VARCHAR}, + + + #{vimId,jdbcType=VARCHAR}, + + + #{vimName,jdbcType=VARCHAR}, + + + + + update host + + + NAME = #{name,jdbcType=VARCHAR}, + + + CPU = #{cpu,jdbcType=VARCHAR}, + + + MEMORY = #{memory,jdbcType=VARCHAR}, + + + DISK = #{disk,jdbcType=VARCHAR}, + + + VIM_ID = #{vimId,jdbcType=VARCHAR}, + + + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + + + + + NAME = #{name,jdbcType=VARCHAR} + + + AND VIM_ID = #{vimId,jdbcType=VARCHAR} + + + + + update host + set NAME = #{name,jdbcType=VARCHAR}, + CPU = #{cpu,jdbcType=VARCHAR}, + MEMORY = #{memory,jdbcType=VARCHAR}, + DISK = #{disk,jdbcType=VARCHAR}, + VIM_ID = #{vimId,jdbcType=VARCHAR}, + VIM_NAME = #{vimName,jdbcType=VARCHAR} + where ID = #{id,jdbcType=VARCHAR} + + + update host + + + ID = #{id,jdbcType=VARCHAR}, + + + NAME = #{name,jdbcType=VARCHAR}, + + + CPU = #{cpu,jdbcType=VARCHAR}, + + + MEMORY = #{memory,jdbcType=VARCHAR}, + + + DISK = #{disk,jdbcType=VARCHAR}, + + + VIM_ID = #{vimId,jdbcType=VARCHAR}, + + + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + + + where VIM_ID = #{vimId,jdbcType=VARCHAR} + + diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/LocationMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/LocationMapper.xml new file mode 100644 index 0000000..b0ecba2 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/LocationMapper.xml @@ -0,0 +1,158 @@ + + + + + + + + + + + + + + + + ID, COUNTRY, LOCATION, LATITUDE, LONGITUDE, DESCRIPTION + + + + + + + delete from location + where ID = #{id,jdbcType=VARCHAR} + + + + insert into location (ID, COUNTRY, LOCATION, + LATITUDE, LONGITUDE, DESCRIPTION) + values (#{id,jdbcType=VARCHAR}, #{country,jdbcType=VARCHAR}, + #{location,jdbcType=VARCHAR}, + #{latitude,jdbcType=VARCHAR}, #{longitude,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}) + + + + insert into location + + + ID, + + + COUNTRY, + + + LOCATION, + + + LATITUDE, + + + LONGITUDE, + + + DESCRIPTION, + + + + + #{id,jdbcType=VARCHAR}, + + + #{country,jdbcType=VARCHAR}, + + + #{location,jdbcType=VARCHAR}, + + + #{latitude,jdbcType=VARCHAR}, + + + #{longitude,jdbcType=VARCHAR}, + + + #{description,jdbcType=VARCHAR}, + + + + + + update location + + + COUNTRY = #{country,jdbcType=VARCHAR}, + + + LOCATION = #{location,jdbcType=VARCHAR}, + + + LATITUDE = #{latitude,jdbcType=VARCHAR}, + + + LONGITUDE = #{longitude,jdbcType=VARCHAR}, + + + DESCRIPTION = #{description,jdbcType=VARCHAR}, + + + where ID = #{id,jdbcType=VARCHAR} + + + + update location + set COUNTRY = #{country,jdbcType=VARCHAR}, + LOCATION = #{location,jdbcType=VARCHAR}, + LATITUDE = #{latitude,jdbcType=VARCHAR}, + LONGITUDE = #{longitude,jdbcType=VARCHAR}, + DESCRIPTION = #{description,jdbcType=VARCHAR} + where ID = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/NetworkMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/NetworkMapper.xml new file mode 100644 index 0000000..65e4d67 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/NetworkMapper.xml @@ -0,0 +1,216 @@ + + + + + + + + + + + + + + + + + + ID, NAME, TENANT_ID, VIM_ID, VIM_NAME, STATUS, + PHYSICAL_NETWORK, NETWORK_TYPE, SEGMENTATION_ID + + + + + delete from network + where ID = #{id,jdbcType=VARCHAR} + + + delete from network + where VIM_ID = #{vimId,jdbcType=VARCHAR} + + + insert into network (ID, NAME, TENANT_ID, + VIM_ID, VIM_NAME, STATUS, + PHYSICAL_NETWORK, NETWORK_TYPE, SEGMENTATION_ID + ) + values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, + #{tenantId,jdbcType=VARCHAR}, + #{vimId,jdbcType=VARCHAR}, #{vimName,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, + #{physicalNetwork,jdbcType=VARCHAR}, #{networkType,jdbcType=VARCHAR}, + #{segmentationId,jdbcType=VARCHAR} + ) + + + insert into network + + + ID, + + + NAME, + + + TENANT_ID, + + + VIM_ID, + + + VIM_NAME, + + + STATUS, + + + PHYSICAL_NETWORK, + + + NETWORK_TYPE, + + + SEGMENTATION_ID, + + + + + #{id,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{tenantId,jdbcType=VARCHAR}, + + + #{vimId,jdbcType=VARCHAR}, + + + #{vimName,jdbcType=VARCHAR}, + + + #{status,jdbcType=VARCHAR}, + + + #{physicalNetwork,jdbcType=VARCHAR}, + + + #{networkType,jdbcType=VARCHAR}, + + + #{segmentationId,jdbcType=VARCHAR}, + + + + + update network + + + NAME = #{name,jdbcType=VARCHAR}, + + + TENANT_ID = #{tenantId,jdbcType=VARCHAR}, + + + VIM_ID = #{vimId,jdbcType=VARCHAR}, + + + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + + + STATUS = #{status,jdbcType=VARCHAR}, + + + PHYSICAL_NETWORK = #{physicalNetwork,jdbcType=VARCHAR}, + + + NETWORK_TYPE = #{networkType,jdbcType=VARCHAR}, + + + SEGMENTATION_ID = #{segmentationId,jdbcType=VARCHAR}, + + + where ID = #{id,jdbcType=VARCHAR} + + + update network + set NAME = #{name,jdbcType=VARCHAR}, + TENANT_ID = #{tenantId,jdbcType=VARCHAR}, + VIM_ID = #{vimId,jdbcType=VARCHAR}, + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + STATUS = #{status,jdbcType=VARCHAR}, + PHYSICAL_NETWORK = #{physicalNetwork,jdbcType=VARCHAR}, + NETWORK_TYPE = #{networkType,jdbcType=VARCHAR}, + SEGMENTATION_ID = #{segmentationId,jdbcType=VARCHAR} + where ID = #{id,jdbcType=VARCHAR} + + + update network + + + ID = #{id,jdbcType=VARCHAR}, + + + NAME = #{name,jdbcType=VARCHAR}, + + + TENANT_ID = #{tenantId,jdbcType=VARCHAR}, + + + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + + + STATUS = #{status,jdbcType=VARCHAR}, + + + PHYSICAL_NETWORK = #{physicalNetwork,jdbcType=VARCHAR}, + + + NETWORK_TYPE = #{networkType,jdbcType=VARCHAR}, + + + SEGMENTATION_ID = #{segmentationId,jdbcType=VARCHAR}, + + + where VIM_ID = #{vimId,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/PortMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/PortMapper.xml new file mode 100644 index 0000000..765dcfe --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/PortMapper.xml @@ -0,0 +1,180 @@ + + + + + + + + + + + + + + + + ID, NAME, NWTWORK_ID, STATUS, TENANT_ID, VIM_ID, VIM_NAME + + + + + delete from port + where ID = #{id,jdbcType=VARCHAR} + + + delete from port + where VIM_ID = #{vimId,jdbcType=VARCHAR} + + + insert into port (ID, NAME, NWTWORK_ID, STATUS, TENANT_ID, VIM_ID, + VIM_NAME) + values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, + #{networkId,jdbcType=VARCHAR}, + #{status,jdbcType=VARCHAR}, #{tenantId,jdbcType=VARCHAR}, #{vimId,jdbcType=VARCHAR} + , #{vimName,jdbcType=VARCHAR}) + + + insert into port + + + ID, + + + NAME, + + + NWTWORK_ID, + + + STATUS, + + + TENANT_ID, + + + VIM_ID, + + + VIM_NAME, + + + + + #{id,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{networkId,jdbcType=VARCHAR}, + + + #{status,jdbcType=VARCHAR}, + + + #{tenantId,jdbcType=VARCHAR}, + + + #{vimId,jdbcType=VARCHAR}, + + + #{vimName,jdbcType=VARCHAR}, + + + + + update port + + + NAME = #{name,jdbcType=VARCHAR}, + + + NWTWORK_ID = #{networkId,jdbcType=VARCHAR}, + + + STATUS = #{status,jdbcType=VARCHAR}, + + + TENANT_ID = #{tenantId,jdbcType=VARCHAR}, + + + VIM_ID = #{vimId,jdbcType=VARCHAR}, + + + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + + + where ID = #{id,jdbcType=VARCHAR} + + + update port + set NAME = #{name,jdbcType=VARCHAR}, + NWTWORK_ID = #{networkId,jdbcType=VARCHAR}, + STATUS = #{status,jdbcType=VARCHAR}, + TENANT_ID = #{tenantId,jdbcType=VARCHAR}, + VIM_ID = #{vimId,jdbcType=VARCHAR}, + VIM_NAME = #{vimName,jdbcType=VARCHAR} + where ID = #{id,jdbcType=VARCHAR} + + + update port + + + ID = #{id,jdbcType=VARCHAR}, + + + NAME = #{name,jdbcType=VARCHAR}, + + + NWTWORK_ID = #{networkId,jdbcType=VARCHAR}, + + + STATUS = #{status,jdbcType=VARCHAR}, + + + TENANT_ID = #{tenantId,jdbcType=VARCHAR}, + + + VIM_ID = #{vimId,jdbcType=VARCHAR}, + + + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + + + where ID = #{id,jdbcType=VARCHAR} + + diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/SitesMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/SitesMapper.xml new file mode 100644 index 0000000..14f7b52 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/SitesMapper.xml @@ -0,0 +1,286 @@ + + + + + + + + + + + + + + + + + + + + + + ID, NAME, LOCATION, COUNTRY, VIM_ID, VIM_NAME, STATUS, + TOTAL_CPU, + TOTAL_MEMORY, TOTAL_DISK, + USED_CPU, USED_MEMORY, USED_DISK + + + + + delete from site + where ID = + #{id,jdbcType=VARCHAR} + + + insert into site (ID, NAME, LOCATION, + COUNTRY, VIM_ID, + VIM_NAME, STATUS,TOTAL_CPU, TOTAL_MEMORY, TOTAL_DISK, + USED_CPU, + USED_MEMORY, USED_DISK) + values (#{id,jdbcType=VARCHAR}, + #{name,jdbcType=VARCHAR}, + #{location,jdbcType=VARCHAR}, + #{country,jdbcType=VARCHAR}, #{vimId,jdbcType=VARCHAR}, + #{vimName,jdbcType=VARCHAR}, + #{status,jdbcType=VARCHAR}, + #{totalCPU,jdbcType=VARCHAR}, #{totalMemory,jdbcType=VARCHAR}, + #{totalDisk,jdbcType=VARCHAR}, + #{usedCPU,jdbcType=VARCHAR}, + #{usedMemory,jdbcType=VARCHAR}, + #{usedDisk,jdbcType=VARCHAR}) + + + insert into site + + + ID, + + + NAME, + + + LOCATION, + + + COUNTRY, + + + VIM_ID, + + + VIM_NAME, + + + STATUS, + + + TOTAL_CPU, + + + TOTAL_MEMORY, + + + TOTAL_DISK, + + + USED_CPU, + + + USED_MEMORY, + + + USED_DISK, + + + + + #{id,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{location,jdbcType=VARCHAR}, + + + #{country,jdbcType=VARCHAR}, + + + #{vimId,jdbcType=VARCHAR}, + + + #{vimName,jdbcType=VARCHAR}, + + + #{status,jdbcType=VARCHAR}, + + + #{totalCPU,jdbcType=VARCHAR}, + + + #{totalMemory,jdbcType=VARCHAR}, + + + #{totalDisk,jdbcType=VARCHAR}, + + + #{usedCPU,jdbcType=VARCHAR}, + + + #{usedMemory,jdbcType=VARCHAR}, + + + #{usedDisk,jdbcType=VARCHAR}, + + + + + update site + + + NAME = #{name,jdbcType=VARCHAR}, + + + LOCATION = #{location,jdbcType=VARCHAR}, + + + COUNTRY = #{country,jdbcType=VARCHAR}, + + + VIM_ID = #{vimId,jdbcType=VARCHAR}, + + + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + + + STATUS = #{status,jdbcType=VARCHAR}, + + + TOTAL_CPU = #{totalCPU,jdbcType=VARCHAR}, + + + TOTAL_MEMORY = #{totalMemory,jdbcType=VARCHAR}, + + + TOTAL_DISK = #{totalDisk,jdbcType=VARCHAR}, + + + USED_CPU = #{usedCPU,jdbcType=VARCHAR}, + + + USED_MEMORY = #{usedMemory,jdbcType=VARCHAR}, + + + USED_DISK = #{usedDisk,jdbcType=VARCHAR}, + + + where ID = #{id,jdbcType=VARCHAR} + + + update site + set NAME = #{name,jdbcType=VARCHAR}, + LOCATION + = #{location,jdbcType=VARCHAR}, + COUNTRY = #{country,jdbcType=VARCHAR}, + VIM_ID = #{vimId,jdbcType=VARCHAR}, + VIM_NAME = + #{vimName,jdbcType=VARCHAR}, + STATUS = #{status,jdbcType=VARCHAR}, + TOTAL_CPU = #{totalCPU,jdbcType=VARCHAR}, + TOTAL_MEMORY = + #{totalMemory,jdbcType=VARCHAR}, + TOTAL_DISK = + #{totalDisk,jdbcType=VARCHAR}, + USED_CPU = #{usedCPU,jdbcType=VARCHAR}, + USED_MEMORY = #{usedMemory,jdbcType=VARCHAR}, + USED_DISK = + #{usedDisk,jdbcType=VARCHAR} + where ID = #{id,jdbcType=VARCHAR} + + + update site + + + ID = #{id,jdbcType=VARCHAR}, + + + NAME = #{name,jdbcType=VARCHAR}, + + + LOCATION = #{location,jdbcType=VARCHAR}, + + + COUNTRY = #{country,jdbcType=VARCHAR}, + + + VIM_NAME = #{vimName,jdbcType=VARCHAR}, + + + STATUS = #{status,jdbcType=VARCHAR}, + + + TOTAL_CPU = #{totalCPU,jdbcType=VARCHAR}, + + + TOTAL_MEMORY = #{totalMemory,jdbcType=VARCHAR}, + + + TOTAL_DISK = #{totalDisk,jdbcType=VARCHAR}, + + + USED_CPU = #{usedCPU,jdbcType=VARCHAR}, + + + USED_MEMORY = #{usedMemory,jdbcType=VARCHAR}, + + + USED_DISK = #{usedDisk,jdbcType=VARCHAR}, + + + where VIM_ID = #{vimId,jdbcType=VARCHAR} + + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VimMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VimMapper.xml new file mode 100644 index 0000000..e6f38ef --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VimMapper.xml @@ -0,0 +1,52 @@ + + + + + + + + + + ID + + + + + delete from vim + where ID = #{id,jdbcType=VARCHAR} + + + insert into vim (ID) + values (#{id,jdbcType=VARCHAR}) + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VirtualLinkMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VirtualLinkMapper.xml new file mode 100644 index 0000000..b4d2394 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VirtualLinkMapper.xml @@ -0,0 +1,273 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + id, name, backend_id, is_public, dc_name, vim_id, vim_name, physicial_net, ns_id, + ns_name, description, network_type, segmentation, mtu, vlan_transparent, router_external, + resource_provider_type, resource_provider_id + + + + + 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, + ns_name, description, network_type, + segmentation, mtu, vlan_transparent, + router_external, resource_provider_type, resource_provider_id + ) + values (#{id,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{backendId,jdbcType=VARCHAR}, + #{isPublic,jdbcType=VARCHAR}, #{dcName,jdbcType=VARCHAR}, #{vimId,jdbcType=VARCHAR}, + #{vimName,jdbcType=VARCHAR}, #{physicialNet,jdbcType=VARCHAR}, #{nsId,jdbcType=VARCHAR}, + #{nsName,jdbcType=VARCHAR}, #{description,jdbcType=VARCHAR}, #{networkType,jdbcType=VARCHAR}, + #{segmentation,jdbcType=VARCHAR}, #{mtu,jdbcType=VARCHAR}, #{vlanTransparent,jdbcType=VARCHAR}, + #{routerExternal,jdbcType=VARCHAR}, #{resourceProviderType,jdbcType=VARCHAR}, #{resourceProviderId,jdbcType=VARCHAR} + ) + + + insert into vl + + + id, + + + name, + + + backend_id, + + + is_public, + + + dc_name, + + + vim_id, + + + vim_name, + + + physicial_net, + + + ns_id, + + + ns_name, + + + description, + + + network_type, + + + segmentation, + + + mtu, + + + vlan_transparent, + + + router_external, + + + resource_provider_type, + + + resource_provider_id, + + + + + #{id,jdbcType=VARCHAR}, + + + #{name,jdbcType=VARCHAR}, + + + #{backendId,jdbcType=VARCHAR}, + + + #{isPublic,jdbcType=VARCHAR}, + + + #{dcName,jdbcType=VARCHAR}, + + + #{vimId,jdbcType=VARCHAR}, + + + #{vimName,jdbcType=VARCHAR}, + + + #{physicialNet,jdbcType=VARCHAR}, + + + #{nsId,jdbcType=VARCHAR}, + + + #{nsName,jdbcType=VARCHAR}, + + + #{description,jdbcType=VARCHAR}, + + + #{networkType,jdbcType=VARCHAR}, + + + #{segmentation,jdbcType=VARCHAR}, + + + #{mtu,jdbcType=VARCHAR}, + + + #{vlanTransparent,jdbcType=VARCHAR}, + + + #{routerExternal,jdbcType=VARCHAR}, + + + #{resourceProviderType,jdbcType=VARCHAR}, + + + #{resourceProviderId,jdbcType=VARCHAR}, + + + + + update vl + + + name = #{name,jdbcType=VARCHAR}, + + + backend_id = #{backendId,jdbcType=VARCHAR}, + + + is_public = #{isPublic,jdbcType=VARCHAR}, + + + dc_name = #{dcName,jdbcType=VARCHAR}, + + + vim_id = #{vimId,jdbcType=VARCHAR}, + + + vim_name = #{vimName,jdbcType=VARCHAR}, + + + physicial_net = #{physicialNet,jdbcType=VARCHAR}, + + + ns_id = #{nsId,jdbcType=VARCHAR}, + + + ns_name = #{nsName,jdbcType=VARCHAR}, + + + description = #{description,jdbcType=VARCHAR}, + + + network_type = #{networkType,jdbcType=VARCHAR}, + + + segmentation = #{segmentation,jdbcType=VARCHAR}, + + + mtu = #{mtu,jdbcType=VARCHAR}, + + + vlan_transparent = #{vlanTransparent,jdbcType=VARCHAR}, + + + router_external = #{routerExternal,jdbcType=VARCHAR}, + + + resource_provider_type = #{resourceProviderType,jdbcType=VARCHAR}, + + + resource_provider_id = #{resourceProviderId,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update vl + set name = #{name,jdbcType=VARCHAR}, + backend_id = #{backendId,jdbcType=VARCHAR}, + is_public = #{isPublic,jdbcType=VARCHAR}, + dc_name = #{dcName,jdbcType=VARCHAR}, + vim_id = #{vimId,jdbcType=VARCHAR}, + vim_name = #{vimName,jdbcType=VARCHAR}, + physicial_net = #{physicialNet,jdbcType=VARCHAR}, + ns_id = #{nsId,jdbcType=VARCHAR}, + ns_name = #{nsName,jdbcType=VARCHAR}, + description = #{description,jdbcType=VARCHAR}, + network_type = #{networkType,jdbcType=VARCHAR}, + segmentation = #{segmentation,jdbcType=VARCHAR}, + mtu = #{mtu,jdbcType=VARCHAR}, + vlan_transparent = #{vlanTransparent,jdbcType=VARCHAR}, + router_external = #{routerExternal,jdbcType=VARCHAR}, + resource_provider_type = #{resourceProviderType,jdbcType=VARCHAR}, + resource_provider_id = #{resourceProviderId,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VmMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VmMapper.xml new file mode 100644 index 0000000..dc2376c --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VmMapper.xml @@ -0,0 +1,114 @@ + + + + + + + + + + + + vm_id, vm_name, vm_status, vnf_instance_id + + + + + delete from vm + where vm_id = #{vmId,jdbcType=VARCHAR} + + + 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 + + + vm_id, + + + vm_name, + + + vm_status, + + + vnf_instance_id, + + + + + #{vmId,jdbcType=VARCHAR}, + + + #{vmName,jdbcType=VARCHAR}, + + + #{vmStatus,jdbcType=VARCHAR}, + + + #{vnfInstanceId,jdbcType=VARCHAR}, + + + + + update vm + + + vm_name = #{vmName,jdbcType=VARCHAR}, + + + vm_status = #{vmStatus,jdbcType=VARCHAR}, + + + vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR}, + + + where vm_id = #{vmId,jdbcType=VARCHAR} + + + update vm + set vm_name = #{vmName,jdbcType=VARCHAR}, + vm_status = #{vmStatus,jdbcType=VARCHAR}, + vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} + where vm_id = #{vmId,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfInfoMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfInfoMapper.xml new file mode 100644 index 0000000..135ccc1 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfInfoMapper.xml @@ -0,0 +1,96 @@ + + + + + + + + + + + vnf_instance_id, ns_id, vnfm_id + + + + + 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 + + + vnf_instance_id, + + + ns_id, + + + vnfm_id, + + + + + #{vnfInstanceId,jdbcType=VARCHAR}, + + + #{nsId,jdbcType=VARCHAR}, + + + #{vnfmId,jdbcType=VARCHAR}, + + + + + update vnfinfo + + + ns_id = #{nsId,jdbcType=VARCHAR}, + + + vnfm_id = #{vnfmId,jdbcType=VARCHAR}, + + + where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} + + + update vnfinfo + set ns_id = #{nsId,jdbcType=VARCHAR}, + vnfm_id = #{vnfmId,jdbcType=VARCHAR} + where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfMapper.xml new file mode 100644 index 0000000..cd187c3 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfMapper.xml @@ -0,0 +1,319 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + id, vnf_instance_id, vnf_instance_name, ns_id, ns_name, vnfm_id, vnfm_name, vnf_package_name, + vnf_descriptor_name, vim_id, vim_name, vim_tenant, job_id, vnf_status, vnf_type, + max_vm, max_cpu, max_disk, max_ram, max_shd, max_net, name + + + + + 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, + vim_id, vim_name, vim_tenant, + job_id, vnf_status, vnf_type, + max_vm, max_cpu, max_disk, + max_ram, max_shd, max_net, + name) + values (#{id,jdbcType=VARCHAR}, #{vnfInstanceId,jdbcType=VARCHAR}, #{vnfInstanceName,jdbcType=VARCHAR}, + #{nsId,jdbcType=VARCHAR}, #{nsName,jdbcType=VARCHAR}, #{vnfmId,jdbcType=VARCHAR}, + #{vnfmName,jdbcType=VARCHAR}, #{vnfPackageName,jdbcType=VARCHAR}, #{vnfDescriptorName,jdbcType=VARCHAR}, + #{vimId,jdbcType=VARCHAR}, #{vimName,jdbcType=VARCHAR}, #{vimTenant,jdbcType=VARCHAR}, + #{jobId,jdbcType=VARCHAR}, #{vnfStatus,jdbcType=VARCHAR}, #{vnfType,jdbcType=VARCHAR}, + #{maxVm,jdbcType=INTEGER}, #{maxCpu,jdbcType=INTEGER}, #{maxDisk,jdbcType=INTEGER}, + #{maxRam,jdbcType=INTEGER}, #{maxShd,jdbcType=INTEGER}, #{maxNet,jdbcType=INTEGER}, + #{name,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, + + + vim_id, + + + vim_name, + + + vim_tenant, + + + job_id, + + + vnf_status, + + + vnf_type, + + + max_vm, + + + max_cpu, + + + max_disk, + + + max_ram, + + + max_shd, + + + max_net, + + + name, + + + + + #{id,jdbcType=VARCHAR}, + + + #{vnfInstanceId,jdbcType=VARCHAR}, + + + #{vnfInstanceName,jdbcType=VARCHAR}, + + + #{nsId,jdbcType=VARCHAR}, + + + #{nsName,jdbcType=VARCHAR}, + + + #{vnfmId,jdbcType=VARCHAR}, + + + #{vnfmName,jdbcType=VARCHAR}, + + + #{vnfPackageName,jdbcType=VARCHAR}, + + + #{vnfDescriptorName,jdbcType=VARCHAR}, + + + #{vimId,jdbcType=VARCHAR}, + + + #{vimName,jdbcType=VARCHAR}, + + + #{vimTenant,jdbcType=VARCHAR}, + + + #{jobId,jdbcType=VARCHAR}, + + + #{vnfStatus,jdbcType=VARCHAR}, + + + #{vnfType,jdbcType=VARCHAR}, + + + #{maxVm,jdbcType=INTEGER}, + + + #{maxCpu,jdbcType=INTEGER}, + + + #{maxDisk,jdbcType=INTEGER}, + + + #{maxRam,jdbcType=INTEGER}, + + + #{maxShd,jdbcType=INTEGER}, + + + #{maxNet,jdbcType=INTEGER}, + + + #{name,jdbcType=VARCHAR}, + + + + + update vnf + + + vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR}, + + + vnf_instance_name = #{vnfInstanceName,jdbcType=VARCHAR}, + + + ns_id = #{nsId,jdbcType=VARCHAR}, + + + ns_name = #{nsName,jdbcType=VARCHAR}, + + + vnfm_id = #{vnfmId,jdbcType=VARCHAR}, + + + vnfm_name = #{vnfmName,jdbcType=VARCHAR}, + + + vnf_package_name = #{vnfPackageName,jdbcType=VARCHAR}, + + + vnf_descriptor_name = #{vnfDescriptorName,jdbcType=VARCHAR}, + + + vim_id = #{vimId,jdbcType=VARCHAR}, + + + vim_name = #{vimName,jdbcType=VARCHAR}, + + + vim_tenant = #{vimTenant,jdbcType=VARCHAR}, + + + job_id = #{jobId,jdbcType=VARCHAR}, + + + vnf_status = #{vnfStatus,jdbcType=VARCHAR}, + + + vnf_type = #{vnfType,jdbcType=VARCHAR}, + + + max_vm = #{maxVm,jdbcType=INTEGER}, + + + max_cpu = #{maxCpu,jdbcType=INTEGER}, + + + max_disk = #{maxDisk,jdbcType=INTEGER}, + + + max_ram = #{maxRam,jdbcType=INTEGER}, + + + max_shd = #{maxShd,jdbcType=INTEGER}, + + + max_net = #{maxNet,jdbcType=INTEGER}, + + + name = #{name,jdbcType=VARCHAR}, + + + where id = #{id,jdbcType=VARCHAR} + + + update vnf + set vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR}, + vnf_instance_name = #{vnfInstanceName,jdbcType=VARCHAR}, + ns_id = #{nsId,jdbcType=VARCHAR}, + ns_name = #{nsName,jdbcType=VARCHAR}, + vnfm_id = #{vnfmId,jdbcType=VARCHAR}, + vnfm_name = #{vnfmName,jdbcType=VARCHAR}, + vnf_package_name = #{vnfPackageName,jdbcType=VARCHAR}, + vnf_descriptor_name = #{vnfDescriptorName,jdbcType=VARCHAR}, + vim_id = #{vimId,jdbcType=VARCHAR}, + vim_name = #{vimName,jdbcType=VARCHAR}, + vim_tenant = #{vimTenant,jdbcType=VARCHAR}, + job_id = #{jobId,jdbcType=VARCHAR}, + vnf_status = #{vnfStatus,jdbcType=VARCHAR}, + vnf_type = #{vnfType,jdbcType=VARCHAR}, + max_vm = #{maxVm,jdbcType=INTEGER}, + max_cpu = #{maxCpu,jdbcType=INTEGER}, + max_disk = #{maxDisk,jdbcType=INTEGER}, + max_ram = #{maxRam,jdbcType=INTEGER}, + max_shd = #{maxShd,jdbcType=INTEGER}, + max_net = #{maxNet,jdbcType=INTEGER}, + name = #{name,jdbcType=VARCHAR} + where id = #{id,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfStatusMapper.xml b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfStatusMapper.xml new file mode 100644 index 0000000..08a5101 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/mybatis/mysql/VnfStatusMapper.xml @@ -0,0 +1,213 @@ + + + + + + + + + + + + + + + + + + + + + vnf_instance_id, job_id, ns_id, vnfm_id, response_descriptor, status, progress, status_description, + error_code, response_id, response_history_list, add_vm, del_vm + + + + + 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, + response_id, response_history_list, add_vm, + del_vm) + values (#{vnfInstanceId,jdbcType=VARCHAR}, #{jobId,jdbcType=VARCHAR}, #{nsId,jdbcType=VARCHAR}, + #{vnfmId,jdbcType=VARCHAR}, #{responseDescriptor,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, + #{progress,jdbcType=VARCHAR}, #{statusDescription,jdbcType=VARCHAR}, #{errorCode,jdbcType=VARCHAR}, + #{responseId,jdbcType=VARCHAR}, #{responseHistoryList,jdbcType=VARCHAR}, #{addVm,jdbcType=VARCHAR}, + #{delVm,jdbcType=VARCHAR}) + + + insert into vnfstatus + + + vnf_instance_id, + + + job_id, + + + ns_id, + + + vnfm_id, + + + response_descriptor, + + + status, + + + progress, + + + status_description, + + + error_code, + + + response_id, + + + response_history_list, + + + add_vm, + + + del_vm, + + + + + #{vnfInstanceId,jdbcType=VARCHAR}, + + + #{jobId,jdbcType=VARCHAR}, + + + #{nsId,jdbcType=VARCHAR}, + + + #{vnfmId,jdbcType=VARCHAR}, + + + #{responseDescriptor,jdbcType=VARCHAR}, + + + #{status,jdbcType=VARCHAR}, + + + #{progress,jdbcType=VARCHAR}, + + + #{statusDescription,jdbcType=VARCHAR}, + + + #{errorCode,jdbcType=VARCHAR}, + + + #{responseId,jdbcType=VARCHAR}, + + + #{responseHistoryList,jdbcType=VARCHAR}, + + + #{addVm,jdbcType=VARCHAR}, + + + #{delVm,jdbcType=VARCHAR}, + + + + + update vnfstatus + + + job_id = #{jobId,jdbcType=VARCHAR}, + + + ns_id = #{nsId,jdbcType=VARCHAR}, + + + vnfm_id = #{vnfmId,jdbcType=VARCHAR}, + + + response_descriptor = #{responseDescriptor,jdbcType=VARCHAR}, + + + status = #{status,jdbcType=VARCHAR}, + + + progress = #{progress,jdbcType=VARCHAR}, + + + status_description = #{statusDescription,jdbcType=VARCHAR}, + + + error_code = #{errorCode,jdbcType=VARCHAR}, + + + response_id = #{responseId,jdbcType=VARCHAR}, + + + response_history_list = #{responseHistoryList,jdbcType=VARCHAR}, + + + add_vm = #{addVm,jdbcType=VARCHAR}, + + + del_vm = #{delVm,jdbcType=VARCHAR}, + + + where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} + + + update vnfstatus + set job_id = #{jobId,jdbcType=VARCHAR}, + ns_id = #{nsId,jdbcType=VARCHAR}, + vnfm_id = #{vnfmId,jdbcType=VARCHAR}, + response_descriptor = #{responseDescriptor,jdbcType=VARCHAR}, + status = #{status,jdbcType=VARCHAR}, + progress = #{progress,jdbcType=VARCHAR}, + status_description = #{statusDescription,jdbcType=VARCHAR}, + error_code = #{errorCode,jdbcType=VARCHAR}, + response_id = #{responseId,jdbcType=VARCHAR}, + response_history_list = #{responseHistoryList,jdbcType=VARCHAR}, + add_vm = #{addVm,jdbcType=VARCHAR}, + del_vm = #{delVm,jdbcType=VARCHAR} + where vnf_instance_id = #{vnfInstanceId,jdbcType=VARCHAR} + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml new file mode 100644 index 0000000..a24efd5 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/spring/Resmanagement/services.xml @@ -0,0 +1,331 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ResmanagementService/service/src/main/resources/spring/Resmanagement/svc_register.xml b/ResmanagementService/service/src/main/resources/spring/Resmanagement/svc_register.xml new file mode 100644 index 0000000..38394ae --- /dev/null +++ b/ResmanagementService/service/src/main/resources/spring/Resmanagement/svc_register.xml @@ -0,0 +1,42 @@ + + + + + + + \ No newline at end of file diff --git a/ResmanagementService/service/src/main/resources/swagger.json b/ResmanagementService/service/src/main/resources/swagger.json new file mode 100644 index 0000000..6273c04 --- /dev/null +++ b/ResmanagementService/service/src/main/resources/swagger.json @@ -0,0 +1,1100 @@ +{ + "swagger": "2.0", + "info": { + "title": "Resource Management API", + "description": "Resource Management API", + "version": "1.0.0" + }, + "tags": [ + { + "name": "Resource Management services" + } + ], + "basePath": "/openoapi/resmgr/v1", + "paths": { + "/limits": { + "get": { + "summary": "Query limits information", + "description": "Query limits information", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vimId", + "in": "query", + "description": "vim Id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "Successfully Query limits information", + "schema": { + "$ref": "#/definitions/QueryLimts" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "Limits Not Found" + }, + "500": { + "description": "Limits failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/resource/grant": { + "put": { + "summary": "Grant VNF Life Cycle Operation", + "description": "Grant Resource", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "open-o", + "description": "OPEN-O Interface.", + "required": true, + "schema": { + "$ref": "#/definitions/GrantResource" + } + } + ], + "responses": { + "200": { + "description": "VNF Resource Response", + "schema": { + "$ref": "#/definitions/GrantResourceResponse" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Resource Not Found" + }, + "500": { + "description": "VNF resource failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/vl": { + "post": { + "summary": "Create virtual link resource", + "description": "virtual link Resource", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "open-o", + "description": "OPEN-O Interface.", + "required": true, + "schema": { + "$ref": "#/definitions/VirtualLink" + } + } + ], + "responses": { + "202": { + "description": "Successfully Created VNF Resource", + "schema": { + "$ref": "#/definitions/VirtualLinkResponse" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Resource Not Found" + }, + "500": { + "description": "VNF resource failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/vl/{id}": { + "delete": { + "summary": "Delete virtual link resource", + "description": "Delete virtual link Resource", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "id", + "in": "path", + "description": "VNF Resource Id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "Successfully Deleted VNF Resource" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Resource Not Found" + }, + "500": { + "description": "VNF resource failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/vnf": { + "post": { + "summary": "Create VNF instance resource", + "description": "Create VNF Resource", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "open-o", + "description": "OPEN-O Interface.", + "required": true, + "schema": { + "$ref": "#/definitions/CreateVNFResource" + } + } + ], + "responses": { + "201": { + "description": "Successfully Created VNF Resource", + "schema": { + "$ref": "#/definitions/CreateVNFResponse" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Resource Not Found" + }, + "500": { + "description": "VNF resource failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/vnfinfo": { + "post": { + "summary": "Write VNF status information", + "description": "VNF Status", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "open-o", + "description": "OPEN-O Interface.", + "required": true, + "schema": { + "$ref": "#/definitions/VNFStatusInfo" + } + } + ], + "responses": { + "201": { + "description": "Successfully write VNF status" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Resource Not Found" + }, + "500": { + "description": "VNF resource failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/vnfdetailinfo": { + "post": { + "summary": "Write VNF detail information", + "description": "VNF detail info", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "in": "body", + "name": "open-o", + "description": "OPEN-O Interface", + "required": true, + "schema": { + "$ref": "#/definitions/VNFDetailInfo" + } + } + ], + "responses": { + "201": { + "description": "Successfully write VNF detail Info" + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Resource Not Found" + }, + "500": { + "description": "VNF resource failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "definitions": { + "QueryLimts": { + "type": "object", + "description": "Query Limits Response.", + "required": [ + "vimId", + "vimName", + "totalCPU", + "totalMemory", + "totalDisk", + "usedCPU", + "usedMemory", + "usedDisk" + ], + "properties": { + "vimId": { + "type": "string", + "description": "Identifier of vimId." + }, + "vimName": { + "type": "string", + "description": "Name." + }, + "totalCPU": { + "type": "string" + }, + "totalMemory": { + "type": "string" + }, + "totalDisk": { + "type": "string" + }, + "usedCPU": { + "type": "string" + }, + "usedMemory": { + "type": "string" + }, + "usedDisk": { + "type": "string" + } + } + }, + "VirtualLinkResponse": { + "type": "object", + "description": "Virtual Link Response.", + "required": [ + "Id", + "Name" + ], + "properties": { + "Id": { + "type": "string", + "description": "Identifier of VL." + }, + "Name": { + "type": "string", + "description": "Name of VL." + } + } + }, + "CreateVNFResponse": { + "type": "object", + "description": "Create VNF Response.", + "required": [ + "Id", + "Name" + ], + "properties": { + "Id": { + "type": "string", + "description": "UUID." + }, + "Name": { + "type": "string", + "description": "Instance Name." + } + } + }, + "VNFDetailInfo": { + "type": "object", + "description": "List of Vm to be added or deleted", + "required": [ + "vnfInstanceId", + "nsId", + "vnfmId", + "Vms" + ], + "properties": { + "vnfInstanceId": { + "type": "string", + "description": "The id of VNF instance" + }, + "nsId": { + "type": "string", + "description": "NS ID" + }, + "vnfmId": { + "type": "string", + "description": "VNFM ID" + }, + "Vms": { + "type": "array", + "items": { + "$ref": "#/definitions/Vm" + } + } + } + }, + "VNFStatusInfo": { + "type": "object", + "description": "Write VNF Status.", + "required": [ + "vnfInstanceId", + "jobId", + "nsId", + "vnfmId", + "responseDescriptor", + "status", + "progress", + "sStatusDescription", + "errorCode", + "responseId", + "responseHistoryList", + "addVm", + "delVm" + ], + "properties": { + "vnfInstanceId": { + "type": "string", + "description": "The Id of VNF Instance." + }, + "jobId": { + "type": "string", + "description": "The ID of workflow." + }, + "nsId": { + "type": "string", + "description": "NS ID." + }, + "vnfmId": { + "type": "string", + "description": "The VNFM ID." + }, + "responseDescriptor": { + "type": "string", + "description": "The name of VNFM." + }, + "status": { + "type": "string", + "description": "Status of VNF - started processing finished error." + }, + "progress": { + "type": "integer", + "description": "progress (1-100)." + }, + "sStatusDescription": { + "type": "string", + "description": "current Progress Description." + }, + "errorCode": { + "type": "integer", + "description": "Error code." + }, + "responseId": { + "type": "integer", + "description": "Message Number." + }, + "responseHistoryList": { + "type": "array", + "items": { + "$ref": "#/definitions/progressInfo" + } + }, + "addVm": { + "type": "array", + "items": { + "$ref": "#/definitions/Vm" + } + }, + "delVm": { + "type": "array", + "items": { + "$ref": "#/definitions/Vm" + } + } + } + }, + "progressInfo": { + "type": "object", + "description": "List of Vm to be added or deleted", + "required": [ + "progress", + "status", + "statusDescription", + "errorCode", + "responseId", + "responseHistoryList" + ], + "properties": { + "progress": { + "type": "integer", + "description": "progress (1 - 100)" + }, + "status": { + "type": "string", + "description": "status" + }, + "statusDescription": { + "type": "string", + "description": "status description" + }, + "errorCode": { + "type": "integer", + "description": "Error Code" + }, + "responseId": { + "type": "integer", + "description": "Id" + }, + "responseHistoryList": { + "type": "array", + "items": { + "$ref": "#/definitions/historyInfo" + } + } + } + }, + "historyInfo": { + "type": "object", + "description": "List of Vm to be added or deleted", + "required": [ + "progress", + "status", + "statusDescription", + "errorCode", + "responseId" + ], + "properties": { + "progress": { + "type": "integer", + "description": "progress (1 - 100)" + }, + "status": { + "type": "string", + "description": "status" + }, + "statusDescription": { + "type": "string", + "description": "status description" + }, + "errorCode": { + "type": "integer", + "description": "Error Code" + }, + "responseId": { + "type": "integer", + "description": "Id" + } + } + }, + "Vm": { + "type": "object", + "description": "List of Vm to be added or deleted", + "required": [ + "vmId", + "vmName", + "vmStatus" + ], + "properties": { + "vmId": { + "type": "string", + "description": "The ID of VM" + }, + "vmName": { + "type": "string", + "description": "The name of VM" + }, + "vmStatus": { + "type": "string", + "description": "The Status of VM" + } + } + }, + "CreateVNFResource": { + "type": "object", + "description": "Create VNF Resource.", + "required": [ + "vnfInstanceId", + "vnfInstanceName", + "nsId", + "nsName", + "vnfmId", + "vnfmName", + "vnfPackageName", + "vnfDescriptorName", + "vimId", + "vimName", + "vimTenant", + "jobId", + "vnfStatus", + "vnfType", + "maxVm", + "maxCpu", + "maxDisk", + "maxRam", + "maxShd", + "maxNet" + ], + "properties": { + "vnfInstanceId": { + "type": "string", + "description": "The Identifier of VNF Instance." + }, + "vnfInstanceName": { + "type": "string", + "description": "The name of VNF." + }, + "nsId": { + "type": "string", + "description": "NS ID." + }, + "nsName": { + "type": "string", + "description": "NS name." + }, + "vnfmId": { + "type": "string", + "description": "The ID of VNFM." + }, + "vnfmName": { + "type": "string", + "description": "The name of VNFM." + }, + "vnfPackageName": { + "type": "string", + "description": "The description of VNF Package." + }, + "vnfDescriptorName": { + "type": "string", + "description": "The Description of VNFD." + }, + "vimId": { + "type": "string", + "description": "Vim ID." + }, + "vimName": { + "type": "string", + "description": "The Name of VIM." + }, + "vimTenant": { + "type": "string", + "description": "The tenant of VIM." + }, + "jobId": { + "type": "string", + "description": "The ID of workflow." + }, + "vnfStatus": { + "type": "string", + "description": "The status of VNF." + }, + "vnfType": { + "type": "string", + "description": "The type of VNF." + }, + "maxVm": { + "type": "integer", + "description": "Max Vm in this VNF." + }, + "maxCpu": { + "type": "integer", + "description": "Max CPU in this VNF." + }, + "maxDisk": { + "type": "integer", + "description": "Max Disk in this VNF." + }, + "maxRam": { + "type": "integer", + "description": "Max Memory in this VNF." + }, + "maxShd": { + "type": "integer", + "description": "Max Share Disk in this VNF." + }, + "maxNet": { + "type": "integer", + "description": "Max logical Network in this VNF." + } + } + }, + "VirtualLink": { + "type": "object", + "description": "Virtual Link Resource.", + "required": [ + "name", + "backendId", + "isPublic", + "dcName", + "vimId", + "vimName", + "physicialNet", + "nsId", + "nsName", + "description", + "networkType", + "segmentation", + "mtu", + "vlanTransparent", + "routerExternal", + "resourceProviderType", + "resourceProviderId" + ], + "properties": { + "name": { + "type": "string", + "description": "Logical Network Name." + }, + "backendId": { + "type": "string", + "description": "The backend id on VIM." + }, + "isPublic": { + "type": "string", + "description": "Sharable - True or False." + }, + "dcName": { + "type": "string", + "description": "The DataCenter name." + }, + "vimId": { + "type": "string", + "description": "vim Id." + }, + "vimName": { + "type": "string", + "description": "The name of VIM." + }, + "physicialNet": { + "type": "string", + "description": "Physicial Network." + }, + "nsId": { + "type": "string", + "description": "NsId." + }, + "nsName": { + "type": "string", + "description": "The name of NS." + }, + "description": { + "type": "string", + "description": "Description." + }, + "networkType": { + "type": "string", + "description": "Network Type - gre/vlan/vxlan." + }, + "segmentation": { + "type": "string", + "description": "Segmentation Id just like vlan id." + }, + "mtu": { + "type": "string", + "description": "MTU value." + }, + "vlanTransparent": { + "type": "string", + "description": "Support vlan transparent- True/False." + }, + "routerExternal": { + "type": "string", + "description": "Support External Router - True / False." + }, + "resourceProviderType": { + "type": "string", + "description": "The location to be deployed in one of the list - VIM/DC/Zone/Host." + }, + "resourceProviderId": { + "type": "string", + "description": "The location ID to be deployed." + } + } + }, + "GrantResourceResponse": { + "type": "object", + "description": "Resource Response.", + "required": [ + "vim", + "zone", + "zoneGroup", + "addResource", + "tempResource", + "removeResource", + "updateResource", + "vimAssets", + "additionalParam" + ], + "properties": { + "vim": { + "$ref": "#/definitions/VimInfo" + }, + "zone": { + "type": "string" + }, + "zoneGroup": { + "type": "string" + }, + "addResource": { + "$ref": "#/definitions/GrantInfo" + }, + "tempResource": { + "$ref": "#/definitions/GrantInfo" + }, + "removeResource": { + "$ref": "#/definitions/GrantInfo" + }, + "updateResource": { + "$ref": "#/definitions/GrantInfo" + }, + "vimAssets": { + "type": "string" + }, + "additionalParam": { + "type": "string" + } + } + }, + "VimInfo": { + "type": "object", + "description": "Information about the VIM that manages this resource.", + "required": [ + "vimInfoId", + "vimId", + "interfaceInfo", + "accessInfo", + "interfaceEndpoint" + ], + "properties": { + "vimInfoId": { + "type": "string", + "description": "The identifier of this VimInfo instance, for the purpose of referencing it from other information elements." + }, + "vimId": { + "type": "string", + "description": "The identifier of the VIM.." + }, + "interfaceInfo": { + "$ref": "#/definitions/interfaceInfo" + }, + "accessInfo": { + "$ref": "#/definitions/accessInfo" + }, + "interfaceEndpoint": { + "type": "string", + "description": "Information about the interface endpoint. An example is a URL." + } + } + }, + "interfaceInfo": { + "type": "object", + "description": "Information about the interface to the VIM, including VIM provider type, API version, and protocol type..", + "required": [ + "vimType", + "apiVersion", + "protocolType" + ], + "properties": { + "vimType": { + "type": "string", + "description": "vim" + }, + "apiVersion": { + "type": "string", + "description": "api version" + }, + "protocolType": { + "type": "string", + "description": "Type of the protocol" + } + } + }, + "accessInfo": { + "type": "object", + "description": "Authentication credentials for accessing the VIM. Examples may include those to support different authentication schemes, e.g., OAuth, Token, etc..", + "required": [ + "tenant", + "username", + "password" + ], + "properties": { + "tenant": { + "type": "string", + "description": "Tenant Name of tenant" + }, + "username": { + "type": "string", + "description": "Username for login" + }, + "password": { + "type": "string", + "description": "Password of login user" + } + } + }, + "GrantInfo": { + "type": "object", + "description": "Grant Information.", + "required": [ + "resourceDefinitionId", + "reservationId", + "vimId", + "resourceProviderId", + "zoneId" + ], + "properties": { + "resourceDefinitionId": { + "type": "string", + "description": "Identifier of the related ResourceDefinition information from Grant Request" + }, + "reservationId": { + "type": "string", + "description": "Reservation Identifier applicable to the VNFC/VL." + }, + "vimId": { + "type": "string", + "description": "Reference to the identifier of the VimInfo information element defining the VIM under whose control this resource to be placed." + }, + "resourceProviderId": { + "type": "string", + "description": "Identifies the entity responsible for the management of the virtualized resource." + }, + "zoneId": { + "type": "string", + "description": "Reference of the identifier of the zoneInfo information element defining the resource zone in which resource to be placed." + } + } + }, + "GrantResource": { + "type": "object", + "description": "Grant Resource Request Body.", + "required": [ + "vnfInstanceId", + "addResource", + "vimId", + "additionalParam" + ], + "properties": { + "vnfInstanceId": { + "type": "string", + "description": "Identifier Instance." + }, + "vimId": { + "type": "string", + "description": "Identifier vim." + }, + "addResource": { + "type": "array", + "items": { + "$ref": "#/definitions/ResourceDefinition" + }, + "description": "Information sufficient to identify the VNF Descriptor which defines the VNF to be created." + }, + "removeResource": { + "type": "array", + "items": { + "$ref": "#/definitions/ResourceDefinition" + } + }, + "additionalParam": { + "type": "object", + "description": "additionalParam.", + "required": [ + "vnfmid" + ], + "properties": { + "vnfmid": { + "type": "string" + }, + "vimid": { + "type": "string" + }, + "tenant": { + "type": "string" + } + } + } + } + }, + "ResourceDefinition": { + "type": "object", + "description": "List of resources to be added / deleted / updated.", + "required": [ + "resourceDefinitionId", + "resourceTemplate", + "type", + "vdu" + ], + "properties": { + "resourceDefinitionId": { + "type": "string", + "description": "Identifier of this ResourceDefinition information element, unique at least within the scope of the Grant request." + }, + "resourceTemplate": { + "$ref": "#/definitions/ResourceTemplate" + }, + "type": { + "default": "compute", + "enum": [ + "compute", + "VL", + "CP", + "Storage" + ], + "description": "Currently only support tosca.nodes.nfv.VDU." + }, + "vdu": { + "type": "string", + "description": "Reference to the related Vdu applicable to this resource in the VNFD." + } + } + }, + "ResourceTemplate": { + "type": "object", + "description": "Resource templates.", + "required": [ + "VirtualComputeDescriptor", + "VirtualStorageDescriptor" + ], + "properties": { + "VirtualComputeDescriptor": { + "$ref": "#/definitions/VirtualComputeDescriptor" + }, + "VirtualStorageDescriptor": { + "$ref": "#/definitions/VirtualStorageDescriptor" + } + } + }, + "VirtualComputeDescriptor": { + "type": "object", + "description": "Reference to a resource template.", + "required": [ + "virtualCpu", + "virtualMemory" + ], + "properties": { + "virtualCpu": { + "type": "integer", + "format": "int32", + "description": "Number of virtual CPUs" + }, + "virtualMemory": { + "type": "integer", + "format": "int32", + "description": "Amount of virtual Memory" + } + } + }, + "VirtualStorageDescriptor": { + "type": "object", + "description": "Reference to a resource template.", + "required": [ + "typeOfStorage", + "sizeOfStorage", + "swImageDescriptor" + ], + "properties": { + "typeOfStorage": { + "type": "string", + "description": "Type of virtualized storage resource" + }, + "sizeOfStorage": { + "type": "integer", + "format": "int32", + "description": "Size of virtualized storage resource" + }, + "swImageDescriptor": { + "type": "string", + "description": "Software image to be loaded on the Virtual Storage" + } + } + }, + "Error": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } +} \ No newline at end of file diff --git a/ResmanagementService/service/src/main/webapp/WEB-INF/web.xml b/ResmanagementService/service/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..5e7e6bd --- /dev/null +++ b/ResmanagementService/service/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,47 @@ + + + + + + org.springframework.web.context.ContextLoaderListener + + + CXFServlet + org.apache.cxf.transport.servlet.CXFServlet + 1 + + + CXFServlet + /openoapi/resmgr/* + + + + contextConfigLocation + WEB-INF/classes/spring/Resmanagement/*.xml + + + + + 10000000 + + + resmanagement-service + + \ No newline at end of file diff --git a/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/ResourceUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/ResourceUtilTest.java new file mode 100644 index 0000000..d162713 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/ResourceUtilTest.java @@ -0,0 +1,51 @@ +/* + * 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.openo.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; + + +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/openo/nfvo/resmanagement/common/VimUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/VimUtilTest.java new file mode 100644 index 0000000..13e12e5 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/VimUtilTest.java @@ -0,0 +1,48 @@ +/* + * 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.openo.nfvo.resmanagement.common; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; +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.openo.nfvo.resmanagement.common.constant.UrlConstant; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; + +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/openo/nfvo/resmanagement/common/util/JsonUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/JsonUtilTest.java new file mode 100644 index 0000000..92b499d --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/JsonUtilTest.java @@ -0,0 +1,435 @@ +/* + * 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.openo.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 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/openo/nfvo/resmanagement/common/util/RestfulUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/RestfulUtilTest.java new file mode 100644 index 0000000..69bfd74 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/RestfulUtilTest.java @@ -0,0 +1,244 @@ +/* + * 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.openo.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.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 org.openo.nfvo.resmanagement.common.constant.Constant; + +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/openo/nfvo/resmanagement/common/util/StringUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/StringUtilTest.java new file mode 100644 index 0000000..9fb9ef1 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/StringUtilTest.java @@ -0,0 +1,143 @@ +/* + * 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.openo.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; + +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/openo/nfvo/resmanagement/common/util/request/RequestUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtilTest.java new file mode 100644 index 0000000..e4d34b8 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/request/RequestUtilTest.java @@ -0,0 +1,252 @@ +/* + * 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.openo.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 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/openo/nfvo/resmanagement/common/util/response/ResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtilTest.java new file mode 100644 index 0000000..b3258f5 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/ResponseUtilTest.java @@ -0,0 +1,90 @@ +/* + * 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.openo.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 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/openo/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java new file mode 100644 index 0000000..1e30587 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/common/util/response/RoaResponseUtilTest.java @@ -0,0 +1,146 @@ +/* + * 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.openo.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 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/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java new file mode 100644 index 0000000..511e509 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapter2MSBManagerTest.java @@ -0,0 +1,240 @@ +/* + * 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.openo.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.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.resmanagement.common.util.RestfulUtil; + +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/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.java new file mode 100644 index 0000000..4ed114d --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/adapter/impl/ResmgrAdapterMgrServiceTest.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.openo.nfvo.resmanagement.service.adapter.impl; + +import java.io.IOException; + +import org.junit.Test; + +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/openo/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java new file mode 100644 index 0000000..446c29f --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/HostImplTest.java @@ -0,0 +1,161 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.business.impl.HostBusinessImpl; +import org.openo.nfvo.resmanagement.service.dao.impl.HostDaoImpl; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java new file mode 100644 index 0000000..74dfe99 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/LocationImplTest.java @@ -0,0 +1,499 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.business.impl.LocationBusinessImpl; +import org.openo.nfvo.resmanagement.service.business.impl.SitesBusinessImpl; +import org.openo.nfvo.resmanagement.service.dao.impl.LocationDaoImpl; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java new file mode 100644 index 0000000..6222005 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/NetworkImplTest.java @@ -0,0 +1,275 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.business.impl.NetworkBusinessImpl; +import org.openo.nfvo.resmanagement.service.dao.impl.NetworkDaoImpl; +import org.openo.nfvo.resmanagement.service.dao.inf.NetworkDao; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java new file mode 100644 index 0000000..3d36011 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/PortImplTest.java @@ -0,0 +1,153 @@ +/* + * 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.openo.nfvo.resmanagement.service.base.openstack.impl; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.JsonUtil; +import org.openo.nfvo.resmanagement.service.business.impl.PortBusinessImpl; +import org.openo.nfvo.resmanagement.service.dao.impl.PortDaoImpl; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.java new file mode 100644 index 0000000..5db06a8 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/SitesImplTest.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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.business.impl.SitesBusinessImpl; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; + +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/openo/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/base/openstack/impl/VimImplTest.java new file mode 100644 index 0000000..b21525c --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/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.openo.nfvo.resmanagement.service.base.openstack.impl; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.base.openstack.impl.VimImpl; +import org.openo.nfvo.resmanagement.service.business.impl.VimBusinessImpl; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; + +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/openo/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java new file mode 100644 index 0000000..1a1d142 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/HostBusinessImplTest.java @@ -0,0 +1,87 @@ +/* + * 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.openo.nfvo.resmanagement.service.business.impl; + +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.dao.impl.HostDaoImpl; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; + +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/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java new file mode 100644 index 0000000..32ec28a --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LimitsBusinessImplTest.java @@ -0,0 +1,71 @@ +/* + * 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.openo.nfvo.resmanagement.service.business.impl; + +import org.junit.Before; +import org.junit.Test; +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/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java new file mode 100644 index 0000000..03f17b3 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/LocationBusinessImplTest.java @@ -0,0 +1,219 @@ +/* + * 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.openo.nfvo.resmanagement.service.business.impl; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.dao.impl.LocationDaoImpl; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; + +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/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java new file mode 100644 index 0000000..94a0dad --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/SitesBusinessImplTest.java @@ -0,0 +1,408 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.dao.impl.SitesDaoImpl; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; + +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/openo/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.java new file mode 100644 index 0000000..1e35569 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/business/impl/VimBusinessImplTest.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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.dao.impl.VimDaoImpl; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; + +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/openo/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.java new file mode 100644 index 0000000..65e7b97 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/HostDaoImplTest.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.openo.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.nfvo.resmanagement.service.mapper.HostMapper; +import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper; + +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/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java new file mode 100644 index 0000000..fa56c24 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/LocationDaoImplTest.java @@ -0,0 +1,85 @@ +/* + * 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.openo.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.nfvo.resmanagement.service.mapper.LocationMapper; + +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/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java new file mode 100644 index 0000000..d0fd3fe --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/NetworkDaoImplTest.java @@ -0,0 +1,152 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper; +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/openo/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java new file mode 100644 index 0000000..4edcdf3 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/PortDaoImplTest.java @@ -0,0 +1,158 @@ +/* + * 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.openo.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; +import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper; +import org.openo.nfvo.resmanagement.service.mapper.PortMapper; + +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/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java new file mode 100644 index 0000000..4deb71e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/SitesDaoImplTest.java @@ -0,0 +1,132 @@ +/* + * 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.openo.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +import org.openo.nfvo.resmanagement.service.mapper.NetworkMapper; +import org.openo.nfvo.resmanagement.service.mapper.SitesMapper; + +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/openo/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java new file mode 100644 index 0000000..736a844 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VimDaoImplTest.java @@ -0,0 +1,77 @@ +/* + * 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.openo.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import java.util.List; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.nfvo.resmanagement.service.entity.VimEntity; +import org.openo.nfvo.resmanagement.service.mapper.VimMapper; + +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/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.java new file mode 100644 index 0000000..c3a3b98 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VirtualLinkDaoImplTest.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.openo.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +import org.openo.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.openo.nfvo.resmanagement.service.mapper.SitesMapper; +import org.openo.nfvo.resmanagement.service.mapper.VirtualLinkMapper; + +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/openo/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.java new file mode 100644 index 0000000..afb9917 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/dao/impl/VmDaoImplTest.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.openo.nfvo.resmanagement.service.dao.impl; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.entity.VmEntity; +import org.openo.nfvo.resmanagement.service.mapper.SitesMapper; +import org.openo.nfvo.resmanagement.service.mapper.VmMapper; + +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/openo/nfvo/resmanagement/service/entity/HostEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/HostEntityTest.java new file mode 100644 index 0000000..119d4f2 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/HostEntityTest.java @@ -0,0 +1,38 @@ +/* + * 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.openo.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +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/openo/nfvo/resmanagement/service/entity/LocationEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/LocationEntityTest.java new file mode 100644 index 0000000..7998905 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/LocationEntityTest.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.openo.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +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/openo/nfvo/resmanagement/service/entity/NetworkEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntityTest.java new file mode 100644 index 0000000..35f1fdc --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/NetworkEntityTest.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.openo.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +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/openo/nfvo/resmanagement/service/entity/PortEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/PortEntityTest.java new file mode 100644 index 0000000..70fa7ad --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/PortEntityTest.java @@ -0,0 +1,47 @@ +/* + * 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.openo.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +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/openo/nfvo/resmanagement/service/entity/SitesEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/SitesEntityTest.java new file mode 100644 index 0000000..44d4dce --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/SitesEntityTest.java @@ -0,0 +1,110 @@ +/* + * 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.openo.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +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/openo/nfvo/resmanagement/service/entity/VimEntityTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/VimEntityTest.java new file mode 100644 index 0000000..a21642d --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/entity/VimEntityTest.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.openo.nfvo.resmanagement.service.entity; + +import static org.junit.Assert.assertTrue; + +import org.junit.Before; +import org.junit.Test; + +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/openo/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java new file mode 100644 index 0000000..1629f8e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/GrantResourseRoaTest.java @@ -0,0 +1,166 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.group.impl.GrantResServiceImpl; +import org.openo.nfvo.resmanagement.service.group.inf.GrantResService; +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/openo/nfvo/resmanagement/service/rest/HostRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/HostRoaTest.java new file mode 100644 index 0000000..bc0b8b7 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/HostRoaTest.java @@ -0,0 +1,200 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.impl.HostImpl; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Host; +import org.openo.nfvo.resmanagement.service.entity.HostEntity; +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/openo/nfvo/resmanagement/service/rest/LimitsRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoaTest.java new file mode 100644 index 0000000..3c028dc --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LimitsRoaTest.java @@ -0,0 +1,68 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.service.business.impl.LimitsBusinessImpl; +import org.openo.nfvo.resmanagement.service.business.inf.LimitsBusiness; +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/openo/nfvo/resmanagement/service/rest/LocationRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LocationRoaTest.java new file mode 100644 index 0000000..2a3c062 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/LocationRoaTest.java @@ -0,0 +1,389 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.impl.LocationImpl; +import org.openo.nfvo.resmanagement.service.base.openstack.impl.SitesImpl; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Location; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Sites; +import org.openo.nfvo.resmanagement.service.entity.LocationEntity; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +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/openo/nfvo/resmanagement/service/rest/NetworkRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoaTest.java new file mode 100644 index 0000000..b838e27 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/NetworkRoaTest.java @@ -0,0 +1,214 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.impl.NetworkImpl; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Network; +import org.openo.nfvo.resmanagement.service.entity.NetworkEntity; +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/openo/nfvo/resmanagement/service/rest/PortRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/PortRoaTest.java new file mode 100644 index 0000000..9e4d127 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/PortRoaTest.java @@ -0,0 +1,214 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.impl.PortImpl; +import org.openo.nfvo.resmanagement.service.base.openstack.inf.Port; +import org.openo.nfvo.resmanagement.service.entity.PortEntity; +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/openo/nfvo/resmanagement/service/rest/ResOperateRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoaTest.java new file mode 100644 index 0000000..eddd61d --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/ResOperateRoaTest.java @@ -0,0 +1,197 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.VimUtil; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.group.impl.ResOperateServiceImpl; +import org.openo.nfvo.resmanagement.service.group.inf.ResOperateService; +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/openo/nfvo/resmanagement/service/rest/SitesRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SitesRoaTest.java new file mode 100644 index 0000000..ad21b19 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SitesRoaTest.java @@ -0,0 +1,279 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.VimUtil; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.base.openstack.impl.SitesImpl; +import org.openo.nfvo.resmanagement.service.entity.SitesEntity; +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/openo/nfvo/resmanagement/service/rest/SwaggerRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoaTest.java new file mode 100644 index 0000000..7cd0b97 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/SwaggerRoaTest.java @@ -0,0 +1,56 @@ +/* + * 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.openo.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 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/openo/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.java new file mode 100644 index 0000000..f8054ae --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VirtualLinkRoaTest.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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.entity.VirtualLinkEntity; +import org.openo.nfvo.resmanagement.service.group.impl.VirtualLinkServiceImpl; +import org.openo.nfvo.resmanagement.service.group.inf.VirtualLinkService; +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/openo/nfvo/resmanagement/service/rest/VmRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VmRoaTest.java new file mode 100644 index 0000000..111a330 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VmRoaTest.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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.entity.VmEntity; +import org.openo.nfvo.resmanagement.service.group.impl.VmServiceImpl; +import org.openo.nfvo.resmanagement.service.group.inf.VmService; +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/openo/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java new file mode 100644 index 0000000..2128d3a --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfInfoRoaTest.java @@ -0,0 +1,178 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.entity.VnfInfoEntity; +import org.openo.nfvo.resmanagement.service.group.impl.VnfInfoServiceImpl; +import org.openo.nfvo.resmanagement.service.group.inf.VnfInfoService; +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/openo/nfvo/resmanagement/service/rest/VnfRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfRoaTest.java new file mode 100644 index 0000000..332cf2d --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfRoaTest.java @@ -0,0 +1,191 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.entity.VnfEntity; +import org.openo.nfvo.resmanagement.service.group.impl.VnfServiceImpl; +import org.openo.nfvo.resmanagement.service.group.inf.VnfService; +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/openo/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java new file mode 100644 index 0000000..1629271 --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/VnfStatusRoaTest.java @@ -0,0 +1,178 @@ +/* + * 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.openo.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.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.resmanagement.common.util.request.RequestUtil; +import org.openo.nfvo.resmanagement.service.entity.VnfStatusEntity; +import org.openo.nfvo.resmanagement.service.group.impl.VnfStatusServiceImpl; +import org.openo.nfvo.resmanagement.service.group.inf.VnfStatusService; +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/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java new file mode 100644 index 0000000..5409ada --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ExceptionMessageTest.java @@ -0,0 +1,68 @@ +/* + * 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.openo.nfvo.resmanagement.service.rest.exceptionmapper; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +/** + *
+ *

+ *

+ * + * @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/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java new file mode 100644 index 0000000..7a90d9e --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/GenericExceptionMapperTest.java @@ -0,0 +1,43 @@ +/* + * 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.openo.nfvo.resmanagement.service.rest.exceptionmapper; + +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.Response; + +import org.junit.Test; + +/** + *
+ *

+ *

+ * + * @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/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.java new file mode 100644 index 0000000..fc4378b --- /dev/null +++ b/ResmanagementService/service/src/test/java/org/openo/nfvo/resmanagement/service/rest/exceptionmapper/ServiceExceptionMapperTest.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.openo.nfvo.resmanagement.service.rest.exceptionmapper; + +import static org.junit.Assert.assertNotNull; + +import javax.ws.rs.core.Response; + +import org.junit.Test; +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); + } + +} -- cgit 1.2.3-korg