diff options
author | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-08-24 09:23:29 -0400 |
---|---|---|
committer | Benjamin, Max (mb388a) <mb388a@us.att.com> | 2018-08-24 09:23:40 -0400 |
commit | 22c813992a18915f8874976d371ffb55d63930bf (patch) | |
tree | eb0c01a1f54208c6537848f14bcf71a0363f2053 /mso-api-handlers/mso-requests-db/src | |
parent | 969cde43a1c52fc5a0131cd94713a3c4ba3d1564 (diff) |
request db access converted to rest
[MSO-5031]_updated_JUnits_to_assert_request_body_for_requestDb_client
Marking JPARepositories as Remote Rest repositories for
TenantIsolationRunnable class | Minor refactoring
Add request DB Config to ATT specific ASDC controller test yaml
Adding requestDB Endpoint to yaml so as to pass the tests of asdc
controller
Adding requestDB Endpoint to yaml so as to pass the tests
Adding requestDB Endpoint to yaml so as to pass the tests
Handling the build failure due to mock mismatch
Handling the build failure due to conflicting beans and additional
minor refactoring
Handling the build failure due to conflicting beans
Adding RequestDB endpoint to yaml files for running tests
Removing non-entity classes from ClassURLMapper class
Marking JPARepositories as Remote Rest repositories for
TenantIsolationRunnable class | Fixing minor Bug
Marking JPARepositories as Remote Rest repositories for
TenantIsolationRunnable class | Fixing junits
Marking JPARepositories as Remote Rest repositories for
TenantIsolationRunnable class | Fixing
getMultipleOperationalEnvServiceModelStatus
Marking JPARepositories as Remote Rest repositories for
TenantIsolationRunnable class | Fixing Junits
Marking JPARepositories as Remote Rest repositories for RequestsDBHelper
Marking JPARepositories as Remote Rest repositories for
TenantIsolationRunnable class | Moving RequestsDbClient to requestdb
package
Marking JPARepositories as Remote Rest repositories for
TenantIsolationRunnable class | Fixing Junits
Marking JPARepositories as Remote Rest repositories for
TenantIsolationRunnable class | Initial Checkin
Change-Id: I4053919e98afb8db962511be0a3318b1bf8af88a
Issue-ID: SO-903
Signed-off-by: Benjamin, Max (mb388a) <mb388a@us.att.com>
Diffstat (limited to 'mso-api-handlers/mso-requests-db/src')
12 files changed, 303 insertions, 37 deletions
diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ArchivedInfraRequestsRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ArchivedInfraRequestsRepository.java index f3e92ed16a..603f9bb494 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ArchivedInfraRequestsRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ArchivedInfraRequestsRepository.java @@ -22,9 +22,10 @@ package org.onap.so.db.request.data.repository; import org.onap.so.db.request.beans.ArchivedInfraRequests; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -@Repository +@RepositoryRestResource(collectionResourceRel = "archivedInfraRequests", path = "archivedInfraRequests") public interface ArchivedInfraRequestsRepository extends JpaRepository<ArchivedInfraRequests, String> { } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java index 22a1604bdd..16e10e3d5b 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationStatusRepository.java @@ -26,7 +26,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.query.Param; import org.springframework.data.rest.core.annotation.RepositoryRestResource; -@RepositoryRestResource(collectionResourceRel = "operationStatusRepository", path = "operationStatusRepository") +@RepositoryRestResource(collectionResourceRel = "operationStatus", path = "operationStatus") public interface OperationStatusRepository extends JpaRepository<OperationStatus, OperationStatusId> { OperationStatus findOneByServiceIdAndOperationId(@Param("SERVICE_ID") String serviceId, @Param("OPERATION_ID") String operationId); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvDistributionStatusRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvDistributionStatusRepository.java index 799e5ad147..e89755d565 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvDistributionStatusRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvDistributionStatusRepository.java @@ -25,10 +25,10 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.transaction.annotation.Transactional; -@Repository +@RepositoryRestResource(collectionResourceRel = "operationalEnvDistributionStatus", path = "operationalEnvDistributionStatus") public interface OperationalEnvDistributionStatusRepository extends JpaRepository<OperationalEnvDistributionStatus, String> { @Modifying diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java index ee2baedf61..bcad9ce6d5 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/OperationalEnvServiceModelStatusRepository.java @@ -28,32 +28,16 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; -import org.springframework.stereotype.Repository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.transaction.annotation.Transactional; -@Repository +@RepositoryRestResource(collectionResourceRel = "operationalEnvServiceModelStatus", path = "operationalEnvServiceModelStatus") public interface OperationalEnvServiceModelStatusRepository extends JpaRepository<OperationalEnvServiceModelStatus, OperationalEnvServiceModelStatusId>{ public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndRequestId(String operationalEnvId, String requestId); - public List<OperationalEnvServiceModelStatus> findAllByOperationalEnvIdAndRequestId(String operationalEnvId, String requestId); - public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionId(String operationalEnvId, String serviceModelVersionId); + public List<OperationalEnvServiceModelStatus> findAllByOperationalEnvIdAndRequestId(@Param("OPERATIONAL_ENV_ID") String operationalEnvId, + @Param("REQUEST_ID") String requestId); + public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionId(@Param("OPERATIONAL_ENV_ID") String operationalEnvId, + @Param("SERVICE_MODEL_VERSION_ID") String serviceModelVersionId); - @Modifying - @Transactional - @Query("update OperationalEnvServiceModelStatus set serviceModelVersionDistrStatus = :asdcStatus, retryCount = :retryCount where " - + "operationalEnvId = :operationalEnvId and serviceModelVersionId = :serviceModelVersionId") - public int setServiceModelVersionDistrStatusAndRetryCountFor(@Param("asdcStatus") String serviceModelVersionDistrStatus, - @Param("retryCount") int retryCount, - @Param("operationalEnvId") String operationalEnvId, - @Param("serviceModelVersionId") String serviceModelVersionId); - - @Modifying - @Transactional - @Query("update OperationalEnvServiceModelStatus set serviceModelVersionDistrStatus = :asdcStatus, retryCount = :retryCount where " - + "operationalEnvId = :operationalEnvId and serviceModelVersionId = :serviceModelVersionId and requestId = :requestId") - public int setServiceModelVersionDistrStatusAndRetryCountFor(@Param("asdcStatus") String serviceModelVersionDistrStatus, - @Param("retryCount") int retryCount, - @Param("operationalEnvId") String operationalEnvId, - @Param("serviceModelVersionId") String serviceModelVersionId, - @Param("requestId") String requestId); } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ResourceOperationStatusRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ResourceOperationStatusRepository.java index 2d77f7589e..b93bf7840b 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ResourceOperationStatusRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/ResourceOperationStatusRepository.java @@ -25,9 +25,10 @@ import java.util.List; import org.onap.so.db.request.beans.ResourceOperationStatus; import org.onap.so.db.request.beans.ResourceOperationStatusId; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -@Repository +@RepositoryRestResource(collectionResourceRel = "resourceOperationStatus", path = "resourceOperationStatus") public interface ResourceOperationStatusRepository extends JpaRepository<ResourceOperationStatus, ResourceOperationStatusId> { List<ResourceOperationStatus> findByServiceIdAndOperationId(String serviceId, String operationId); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/SiteStatusRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/SiteStatusRepository.java index 11923512a5..179d40ad23 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/SiteStatusRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/SiteStatusRepository.java @@ -22,9 +22,10 @@ package org.onap.so.db.request.data.repository; import org.onap.so.db.request.beans.SiteStatus; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -@Repository +@RepositoryRestResource(collectionResourceRel = "siteStatus", path = "siteStatus") public interface SiteStatusRepository extends JpaRepository<SiteStatus, String> { SiteStatus findOneBySiteName(String siteName); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogComponentDistributionStatusRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogComponentDistributionStatusRepository.java index 8310d79a5b..138ec0fb4d 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogComponentDistributionStatusRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogComponentDistributionStatusRepository.java @@ -25,9 +25,10 @@ import java.util.List; import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; import org.onap.so.db.request.beans.WatchdogComponentDistributionStatusId; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -@Repository +@RepositoryRestResource(collectionResourceRel = "watchdogComponentDistributionStatus", path = "watchdogComponentDistributionStatus") public interface WatchdogComponentDistributionStatusRepository extends JpaRepository<WatchdogComponentDistributionStatus, WatchdogComponentDistributionStatusId> { public List<WatchdogComponentDistributionStatus> findByDistributionId(String distributionId); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogDistributionStatusRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogDistributionStatusRepository.java index 6e37181380..fde8485e6d 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogDistributionStatusRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogDistributionStatusRepository.java @@ -22,9 +22,10 @@ package org.onap.so.db.request.data.repository; import org.onap.so.db.request.beans.WatchdogDistributionStatus; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -@Repository +@RepositoryRestResource(collectionResourceRel = "watchdogDistributionStatus", path = "watchdogDistributionStatus") public interface WatchdogDistributionStatusRepository extends JpaRepository<WatchdogDistributionStatus, String> { } diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogServiceModVerIdLookupRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogServiceModVerIdLookupRepository.java index b83481b88b..b9585d495e 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogServiceModVerIdLookupRepository.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/WatchdogServiceModVerIdLookupRepository.java @@ -23,9 +23,10 @@ package org.onap.so.db.request.data.repository; import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookupId; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; import org.springframework.stereotype.Repository; -@Repository +@RepositoryRestResource(collectionResourceRel = "watchdogServiceModVerIdLookup", path = "watchdogServiceModVerIdLookup") public interface WatchdogServiceModVerIdLookupRepository extends JpaRepository<WatchdogServiceModVerIdLookup, WatchdogServiceModVerIdLookupId> { public WatchdogServiceModVerIdLookup findOneByDistributionId(String distributionId); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/RequestsDBHelper.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/RequestsDBHelper.java index 6eb00ea1e9..562e54ca6e 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/RequestsDBHelper.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/RequestsDBHelper.java @@ -23,8 +23,8 @@ package org.onap.so.requestsdb; import java.sql.Timestamp; import org.onap.so.db.request.beans.InfraActiveRequests; -import org.onap.so.db.request.data.repository.InfraActiveRequestsRepository; import org.onap.so.logger.MsoLogger; +import org.onap.so.requestsdb.client.RequestsDbClient; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -37,7 +37,7 @@ public class RequestsDBHelper { private String methodName = ""; private String classMethodMessage = ""; @Autowired - private InfraActiveRequestsRepository infraActiveRequestsRepository; + private RequestsDbClient requestsDbClient; /** * This util method is to update the InfraRequest table to Complete * @param msg - string, unique message for each caller @@ -51,7 +51,7 @@ public class RequestsDBHelper { classMethodMessage = className + " " + methodName; msoLogger.debug("Begin of " + classMethodMessage); - InfraActiveRequests request = infraActiveRequestsRepository.findOneByRequestId(requestId); + InfraActiveRequests request = requestsDbClient.getInfraActiveRequestbyRequestId(requestId); request.setRequestStatus("COMPLETE"); request.setStatusMessage("SUCCESSFUL, operationalEnvironmentId - " + operationalEnvironmentId + "; Success Message: " + msg); @@ -66,7 +66,7 @@ public class RequestsDBHelper { } Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); request.setEndTime(endTimeStamp); - infraActiveRequestsRepository.save(request); + requestsDbClient.save(request); msoLogger.debug("End of " + classMethodMessage); @@ -85,7 +85,7 @@ public class RequestsDBHelper { classMethodMessage = className + " " + methodName; msoLogger.debug("Begin of " + classMethodMessage); - InfraActiveRequests request = infraActiveRequestsRepository.findOneByRequestId(requestId); + InfraActiveRequests request = requestsDbClient.getInfraActiveRequestbyRequestId(requestId); request.setRequestStatus("FAILED"); request.setStatusMessage("FAILURE, operationalEnvironmentId - " + operationalEnvironmentId + "; Error message: " + msg); request.setProgress(100L); @@ -99,7 +99,7 @@ public class RequestsDBHelper { } Timestamp endTimeStamp = new Timestamp(System.currentTimeMillis()); request.setEndTime(endTimeStamp); - infraActiveRequestsRepository.save(request); + requestsDbClient.save(request); msoLogger.debug("End of " + classMethodMessage); diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/client/RequestsDbClient.java new file mode 100644 index 0000000000..8e291aa15b --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/client/RequestsDbClient.java @@ -0,0 +1,272 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.requestsdb.client; + +import org.apache.http.HttpStatus; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; +import org.onap.so.db.request.beans.OperationStatus; +import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; +import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; +import org.onap.so.db.request.beans.ArchivedInfraRequests; +import org.onap.so.db.request.beans.ResourceOperationStatus; +import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; +import org.onap.so.db.request.beans.WatchdogDistributionStatus; +import org.onap.so.db.request.beans.SiteStatus; +import org.onap.so.db.request.data.controller.InstanceNameDuplicateCheckRequest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.RestTemplate; +import uk.co.blackpepper.bowman.Client; +import uk.co.blackpepper.bowman.ClientFactory; +import uk.co.blackpepper.bowman.Configuration; + +import javax.annotation.PostConstruct; +import javax.ws.rs.core.UriBuilder; +import java.net.URI; +import java.util.List; +import java.util.Map; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; + +@Component +public class RequestsDbClient { + + private static final String SERVICE_ID = "SERVICE_ID"; + private static final String OPERATION_ID = "OPERATION_ID"; + private static final String OPERATIONAL_ENVIRONMENT_ID = "OPERATIONAL_ENVIRONMENT_ID"; + private static final String SERVICE_MODEL_VERSION_ID = "SERVICE_MODEL_VERSION_ID"; + private static final String REQUEST_ID = "REQUEST_ID"; + + private final Client<InfraActiveRequests> infraActiveRequestClient; + private final Client<OperationStatus> operationStatusClient; + private final Client<OperationalEnvDistributionStatus> distributionStatusClient; + private final Client<OperationalEnvServiceModelStatus> serviceModelStatusClient; + + @Value("${mso.adapters.requestDb.endpoint}") + private String endpoint; + + @Value("${mso.adapters.requestDb.auth}") + private String msoAdaptersAuth; + + private String getOrchestrationFilterURI = "/infraActiveRequests/getOrchestrationFiltersFromInfraActive/"; + private static final String OPERATION_STATUS_SEARCH = "/operationStatus/search"; + private static final String OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH = "/operationalEnvServiceModelStatus/search"; + + private String checkVnfIdStatus = "/infraActiveRequests/checkVnfIdStatus/"; + + private String infraActiveRequestURI = "/infraActiveRequests/"; + + private String checkInstanceNameDuplicate = "/infraActiveRequests/checkInstanceNameDuplicate"; + + private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId"; + + private String operationalEnvDistributionStatusURI = "/operationalEnvDistributionStatus/"; + + private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive"; + + private String findOneByOperationalEnvIdAndServiceModelVersionIdURI = "/findOneByOperationalEnvIdAndServiceModelVersionId"; + + private String findAllByOperationalEnvIdAndRequestIdURI = "/findAllByOperationalEnvIdAndRequestId"; + + private HttpHeaders headers; + + @Autowired + private RestTemplate restTemplate; + @Autowired + ClassURLMapper classURLMapper; + + + @PostConstruct + public void init() { + getOrchestrationFilterURI = endpoint + getOrchestrationFilterURI; + infraActiveRequestURI = endpoint + infraActiveRequestURI; + checkVnfIdStatus = endpoint + checkVnfIdStatus; + checkInstanceNameDuplicate = endpoint + checkInstanceNameDuplicate; + cloudOrchestrationFiltersFromInfraActive = endpoint + cloudOrchestrationFiltersFromInfraActive; + findOneByServiceIdAndOperationIdURI = endpoint + OPERATION_STATUS_SEARCH + findOneByServiceIdAndOperationIdURI; + operationalEnvDistributionStatusURI = endpoint + operationalEnvDistributionStatusURI; + findOneByOperationalEnvIdAndServiceModelVersionIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findOneByOperationalEnvIdAndServiceModelVersionIdURI; + findAllByOperationalEnvIdAndRequestIdURI = endpoint + OPERATIONAL_ENV_SERVICE_MODEL_STATUS_SEARCH + findAllByOperationalEnvIdAndRequestIdURI; + headers = new HttpHeaders(); + headers.set("Authorization", msoAdaptersAuth); + } + + public RequestsDbClient() { + ClientFactory clientFactory = Configuration.builder().setRestTemplateConfigurer(restTemplate -> restTemplate.getInterceptors().add((request, body, execution) -> { + request.getHeaders().add("Authorization", msoAdaptersAuth); + return execution.execute(request, body); + })).build().buildClientFactory(); + infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class); + operationStatusClient = clientFactory.create(OperationStatus.class); + distributionStatusClient = clientFactory.create(OperationalEnvDistributionStatus.class); + serviceModelStatusClient = clientFactory.create(OperationalEnvServiceModelStatus.class); + } + public List<InfraActiveRequests> getCloudOrchestrationFiltersFromInfraActive(Map<String, String> orchestrationMap){ + URI uri = getUri(cloudOrchestrationFiltersFromInfraActive); + HttpEntity<Map> entity = new HttpEntity<>(orchestrationMap, headers); + try{ + return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody(); + }catch(HttpClientErrorException e){ + if(HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()){ + return null; + } + throw e; + } + } + public InfraActiveRequests getInfraActiveRequestbyRequestId(String requestId) { + return this.getSingleInfraActiveRequests(this.getUri(endpoint + "/infraActiveRequests/" + requestId)); + } + + public List<InfraActiveRequests> getOrchestrationFiltersFromInfraActive(Map<String, List<String>> orchestrationMap) { + URI uri = getUri(getOrchestrationFilterURI); + HttpEntity<Map<String, List<String>>> entity = new HttpEntity<>(orchestrationMap, headers); + return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference<List<InfraActiveRequests>>() {}).getBody(); + } + + public InfraActiveRequests checkVnfIdStatus(String operationalEnvironmentId) { + URI uri = getUri(checkVnfIdStatus + operationalEnvironmentId); + return restTemplate.exchange(uri, HttpMethod.GET, HttpEntity.EMPTY, InfraActiveRequests.class).getBody(); + } + public InfraActiveRequests checkInstanceNameDuplicate(HashMap<String, String> instanceIdMap, String instanceName, String requestScope) { + URI uri = getUri(checkInstanceNameDuplicate); + HttpEntity<InstanceNameDuplicateCheckRequest> entity = new HttpEntity<>(new InstanceNameDuplicateCheckRequest(instanceIdMap, instanceName, requestScope), headers); + try{ + return restTemplate.exchange(uri, HttpMethod.POST, entity, InfraActiveRequests.class).getBody(); + }catch(HttpClientErrorException e){ + if(HttpStatus.SC_NOT_FOUND == e.getStatusCode().value()){ + return null; + } + throw e; + } + + } + + public OperationStatus getOneByServiceIdAndOperationId(String serviceId, String operationId){ + return this.getSingleOperationStatus(UriBuilder.fromUri(findOneByServiceIdAndOperationIdURI) + .queryParam(SERVICE_ID,serviceId) + .queryParam(OPERATION_ID,operationId) + .build()); + } + + public OperationalEnvServiceModelStatus findOneByOperationalEnvIdAndServiceModelVersionId(String operationalEnvironmentId, String serviceModelVersionId) { + return this.getSingleOperationalEnvServiceModelStatus(UriBuilder.fromUri(findOneByOperationalEnvIdAndServiceModelVersionIdURI) + .queryParam(OPERATIONAL_ENVIRONMENT_ID,operationalEnvironmentId) + .queryParam(SERVICE_MODEL_VERSION_ID,serviceModelVersionId) + .build()); + } + + public List<OperationalEnvServiceModelStatus> getAllByOperationalEnvIdAndRequestId(String operationalEnvironmentId, String requestId){ + return this.getMultipleOperationalEnvServiceModelStatus(UriBuilder.fromUri(findAllByOperationalEnvIdAndRequestIdURI) + .queryParam(OPERATIONAL_ENVIRONMENT_ID,operationalEnvironmentId) + .queryParam(REQUEST_ID,requestId) + .build()); + } + + public OperationalEnvDistributionStatus getDistributionStatusById(String distributionId){ + return this.getSingleOperationalEnvDistributionStatus(UriBuilder.fromUri(operationalEnvDistributionStatusURI+distributionId).build()); + } + + private OperationalEnvServiceModelStatus getSingleOperationalEnvServiceModelStatus(URI uri){ + return serviceModelStatusClient.get(uri); + } + + private List<OperationalEnvServiceModelStatus> getMultipleOperationalEnvServiceModelStatus(URI uri){ + Iterable <OperationalEnvServiceModelStatus> iterable = serviceModelStatusClient.getAll(uri); + List<OperationalEnvServiceModelStatus> serviceModelStatuses = new ArrayList<>(); + Iterator<OperationalEnvServiceModelStatus> statusIterator = iterable.iterator(); + statusIterator.forEachRemaining(serviceModelStatuses::add); + return serviceModelStatuses; + } + + public void save(InfraActiveRequests infraActiveRequests) { + URI uri = getUri(infraActiveRequestURI); + HttpEntity<InfraActiveRequests> entity = new HttpEntity<>(infraActiveRequests, headers); + restTemplate.postForLocation(uri, entity); + } + + public <T> void save(T object){ + URI uri = getUri(endpoint+classURLMapper.getURI(object.getClass())); + HttpEntity<T> entity = new HttpEntity<>(object, headers); + restTemplate.postForLocation(uri, entity); + } + + private OperationalEnvDistributionStatus getSingleOperationalEnvDistributionStatus(URI uri){ + return distributionStatusClient.get(uri); + } + + private InfraActiveRequests getSingleInfraActiveRequests(URI uri) { + return infraActiveRequestClient.get(uri); + } + + public void updateInfraActiveRequests(InfraActiveRequests request) { + infraActiveRequestClient.put(request); + } + + private OperationStatus getSingleOperationStatus(URI uri){ + return operationStatusClient.get(uri); + } + + private URI getUri(String uri) { + return URI.create(uri); + } + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate( new HttpComponentsClientHttpRequestFactory()); + } + + @Component + static class ClassURLMapper { + private static final Map <Class,String> classURLMap = new HashMap<>(); + + ClassURLMapper() { + classURLMap.put(ArchivedInfraRequests.class,"/archivedInfraRequests/"); + classURLMap.put(InfraActiveRequests.class,"/infraActiveRequests/"); + classURLMap.put(OperationalEnvDistributionStatus.class,"/operationalEnvDistributionStatus/"); + classURLMap.put(OperationalEnvServiceModelStatus.class,"/operationalEnvServiceModelStatus/"); + classURLMap.put(OperationStatus.class,"/operationStatus/"); + classURLMap.put(ResourceOperationStatus.class,"/resourceOperationStatus/"); + classURLMap.put(SiteStatus.class,"/siteStatus/"); + classURLMap.put(WatchdogComponentDistributionStatus.class,"/watchdogComponentDistributionStatus/"); + classURLMap.put(WatchdogDistributionStatus.class,"/watchdogDistributionStatus/"); + classURLMap.put(WatchdogServiceModVerIdLookup.class,"/watchdogServiceModVerIdLookup/"); + } + + <T> String getURI(Class<T> className) { + Class actualClass = classURLMap.keySet() + .stream() + .filter(requestdbClass -> requestdbClass.isAssignableFrom(className)) + .findFirst() + .get(); + return classURLMap.get(actualClass); + } + } +} diff --git a/mso-api-handlers/mso-requests-db/src/test/resources/application-test.yaml b/mso-api-handlers/mso-requests-db/src/test/resources/application-test.yaml index c8e90c3d8b..62ae4794f5 100644 --- a/mso-api-handlers/mso-requests-db/src/test/resources/application-test.yaml +++ b/mso-api-handlers/mso-requests-db/src/test/resources/application-test.yaml @@ -6,6 +6,10 @@ server: max-threads: 50 ssl-enable: false mso: + adapters: + requestDb: + auth: Basic YnBlbDptc28tZGItMTUwNyE= + endpoint: http://localhost:8081 site-name: localDevEnv logPath: logs # H2 |