From 2363c37d07e37317252e843c28f410519f83588d Mon Sep 17 00:00:00 2001 From: Sambasiva K Date: Thu, 27 Feb 2020 16:42:36 +0530 Subject: Modification of VFC adapter code to make it SOL005 compliant Change-Id: Ife06298197bed8c1e3766083c7bec39132610f84 Issue-ID: SO-1579 Signed-Off-by: Sambasiva K --- .../adapters/requestsdb/MsoRequestsDbAdapter.java | 15 +++++++++ .../requestsdb/MsoRequestsDbAdapterImpl.java | 39 ++++++++++++++++++++++ .../V6.1.1__Add_Instance_NFVO_Mapping_Table.sql | 12 +++++++ .../requestsdb/adapters/MSORequestDBImplTest.java | 28 ++++++++++++++++ 4 files changed, 94 insertions(+) create mode 100644 adapters/mso-requests-db-adapter/src/main/resources/db/migration/V6.1.1__Add_Instance_NFVO_Mapping_Table.sql (limited to 'adapters/mso-requests-db-adapter/src') diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapter.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapter.java index 110fc6c03e..84ff054a7c 100644 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapter.java +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapter.java @@ -26,6 +26,7 @@ import javax.jws.WebService; import javax.xml.bind.annotation.XmlElement; import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException; import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.InstanceNfvoMapping; import org.onap.so.db.request.beans.ResourceOperationStatus; /** @@ -54,6 +55,20 @@ public interface MsoRequestsDbAdapter { @WebParam(name = "vfModuleName") @XmlElement(required = false) String vfModuleName) throws MsoRequestsDbException; + @WebMethod + public void setInstanceNfvoMappingRepository( + @WebParam(name = "instanceId") @XmlElement(required = true) String instanceId, + @WebParam(name = "nfvoName") @XmlElement(required = true) String nfvoName, + @WebParam(name = "endpoint") @XmlElement(required = true) String endpoint, + @WebParam(name = "username") @XmlElement(required = true) String username, + @WebParam(name = "password") @XmlElement(required = true) String password, + @WebParam(name = "apiRoot") @XmlElement(required = false) String apiRoot) throws MsoRequestsDbException; + + @WebMethod + public InstanceNfvoMapping getInstanceNfvoMapping( + @WebParam(name = "instanceId") @XmlElement(required = true) String instanceId) + throws MsoRequestsDbException; + @WebMethod public InfraActiveRequests getInfraRequest( @WebParam(name = "requestId") @XmlElement(required = true) String requestId) throws MsoRequestsDbException; diff --git a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java index 085a255948..052a53bb1f 100644 --- a/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java +++ b/adapters/mso-requests-db-adapter/src/main/java/org/onap/so/adapters/requestsdb/MsoRequestsDbAdapterImpl.java @@ -31,12 +31,14 @@ import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.db.request.beans.ResourceOperationStatus; +import org.onap.so.db.request.beans.InstanceNfvoMapping; import org.onap.so.db.request.beans.ResourceOperationStatusId; import org.onap.so.db.request.beans.SiteStatus; import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; import org.onap.so.db.request.data.repository.OperationStatusRepository; import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository; import org.onap.so.db.request.data.repository.SiteStatusRepository; +import org.onap.so.db.request.data.repository.InstanceNfvoMappingRepository; import org.onap.so.logger.ErrorCode; import org.onap.so.requestsdb.RequestsDbConstant; import org.slf4j.Logger; @@ -58,6 +60,9 @@ public class MsoRequestsDbAdapterImpl implements MsoRequestsDbAdapter { @Autowired private InfraActiveRequestsRepository infraActive; + @Autowired + private InstanceNfvoMappingRepository instanceNfvoMappingRepository; + @Autowired private SiteStatusRepository siteRepo; @@ -67,6 +72,40 @@ public class MsoRequestsDbAdapterImpl implements MsoRequestsDbAdapter { @Autowired private ResourceOperationStatusRepository resourceOperationStatusRepository; + @Transactional + @Override + public void setInstanceNfvoMappingRepository(String instanceId, String nfvoName, String endpoint, String username, + String password, String apiRoot) { + InstanceNfvoMapping instanceNfvoMapping = new InstanceNfvoMapping(); + if (apiRoot != null) { + instanceNfvoMapping.setApiRoot(apiRoot); + } + if (endpoint != null) { + instanceNfvoMapping.setEndpoint(endpoint); + } + if (instanceId != null) { + instanceNfvoMapping.setInstanceId(instanceId); + } + if (nfvoName != null) { + instanceNfvoMapping.setNfvoName(nfvoName); + } + if (username != null) { + instanceNfvoMapping.setUsername(username); + } + if (password != null) { + instanceNfvoMapping.setPassword(password); + } + + instanceNfvoMappingRepository.save(instanceNfvoMapping); + } + + @Transactional + @Override + public InstanceNfvoMapping getInstanceNfvoMapping(String instanceId) { + InstanceNfvoMapping instanceNfvoMapping = instanceNfvoMappingRepository.findOneByInstanceId(instanceId); + return instanceNfvoMapping; + } + @Transactional @Override public void updateInfraRequest(String requestId, String lastModifiedBy, String statusMessage, String responseBody, diff --git a/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V6.1.1__Add_Instance_NFVO_Mapping_Table.sql b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V6.1.1__Add_Instance_NFVO_Mapping_Table.sql new file mode 100644 index 0000000000..165a9b33f8 --- /dev/null +++ b/adapters/mso-requests-db-adapter/src/main/resources/db/migration/V6.1.1__Add_Instance_NFVO_Mapping_Table.sql @@ -0,0 +1,12 @@ +use requestdb; + +CREATE TABLE `instance_nfvo_mapping` ( + `INSTANCE_ID` varchar(256) NOT NULL, + `NFVO_NAME` varchar(256) DEFAULT NULL, + `ENDPOINT` varchar(256) DEFAULT NULL, + `USERNAME` varchar(256) DEFAULT NULL, + `PASSWORD` varchar(256) DEFAULT NULL, + `API_ROOT` varchar(256) DEFAULT NULL, + `JOB_ID` varchar(256) DEFAULT NULL, + PRIMARY KEY (`INSTANCE_ID`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1; \ No newline at end of file diff --git a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java index fef9dbc22c..9ded5b4b79 100644 --- a/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java +++ b/adapters/mso-requests-db-adapter/src/test/java/org/onap/so/adapters/requestsdb/adapters/MSORequestDBImplTest.java @@ -39,8 +39,10 @@ import org.onap.so.adapters.requestsdb.exceptions.MsoRequestsDbException; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.db.request.beans.OperationStatus; import org.onap.so.db.request.beans.ResourceOperationStatus; +import org.onap.so.db.request.beans.InstanceNfvoMapping; import org.onap.so.db.request.data.repository.OperationStatusRepository; import org.onap.so.db.request.data.repository.ResourceOperationStatusRepository; +import org.onap.so.db.request.data.repository.InstanceNfvoMappingRepository; import org.onap.so.requestsdb.RequestsDbConstant; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.server.LocalServerPort; @@ -58,6 +60,9 @@ public class MSORequestDBImplTest extends RequestsAdapterBase { @Autowired private ResourceOperationStatusRepository resourceOperationStatusRepo; + @Autowired + private InstanceNfvoMappingRepository instanceNfvoMappingRepository; + @Rule public ExpectedException thrown = ExpectedException.none(); @@ -256,6 +261,29 @@ public class MSORequestDBImplTest extends RequestsAdapterBase { assertEquals(siteDisabled, false); } + @Test + public void setInstanceNfvoMappingRepository() throws MsoRequestsDbException { + InstanceNfvoMapping instanceNfvoMapping = new InstanceNfvoMapping(); + String instanceId = "9b9f02c0-298b-458a-bc9c-be3692e4f354"; + String nfvoName = "testNFVO"; + String endpoint = "http://127.0.0.1:80/"; + String username = "admin"; + String password = "admin"; + String apiRoot = "v1"; + + instanceNfvoMapping.setApiRoot(apiRoot); + instanceNfvoMapping.setEndpoint(endpoint); + instanceNfvoMapping.setInstanceId(instanceId); + instanceNfvoMapping.setNfvoName(nfvoName); + instanceNfvoMapping.setUsername(username); + instanceNfvoMapping.setPassword(password); + + dbAdapter.setInstanceNfvoMappingRepository(instanceId, nfvoName, endpoint, username, password, apiRoot); + InstanceNfvoMapping dbInstNfvoMap = dbAdapter.getInstanceNfvoMapping(instanceId); + assertThat(dbInstNfvoMap, sameBeanAs(instanceNfvoMapping)); + } + + @Test public void updateServiceOperation() throws MsoRequestsDbException { String serviceId = "serviceid"; -- cgit 1.2.3-korg