From 69455a268648881f4b5a0c4547d769c2e6ecc2c1 Mon Sep 17 00:00:00 2001 From: "Benjamin, Max (mb388a)" Date: Tue, 4 Sep 2018 11:21:02 -0400 Subject: added generic fabric support to SO Fix Autoincrement of ID field in table Fix accidental removal of method Update usage of requestdb client removed unused imports in common tasks and test Fix broken branch, have unit tests pass references the Epic branch Fix broken branch from compiling committing classpath for vfc adapter cause its not going away added in the fail case for when there are no profiles removed second set of adapters in application test yml removed double adapters in request db application test added jpa repo dependency to the so bpmn folder pom add creation timestamp column to the table added in null checks for Config returned from policy switched to string in requestprocess with jenerate switched to string in requestprocess with jenerate updated aai version in common pom to 605 from 591 renamed the db scripts for flyway sync to register added endpoint to application test yml for failing test ... Change-Id: I800f837ea75d7cdff740dc3a387e4d7654cfd085 Issue-ID: SO-972 Signed-off-by: Benjamin, Max (mb388a) --- .../mso-requests-db/hibernate.properties | 2 - .../mso-requests-db/hibernate.reveng.xml | 11 - mso-api-handlers/mso-requests-db/pom.xml | 9 +- .../mso-requests-db/src/hibernate.reveng.xml | 30 -- .../onap/so/db/request/beans/InfraRequests.java | 2 +- .../so/db/request/beans/RequestProcessingData.java | 167 ++++++++++ .../so/db/request/client/RequestsDbClient.java | 366 +++++++++++++++++++++ .../RequestProcessingDataRepository.java | 37 +++ .../org/onap/so/requestsdb/RequestsDBHelper.java | 4 +- .../onap/so/requestsdb/TimestampXMLAdapter.java | 42 +++ .../so/requestsdb/adapter/TimestampXMLAdapter.java | 42 --- .../so/requestsdb/client/RequestsDbClient.java | 272 --------------- .../src/test/java/org/onap/so/BaseTest.java | 34 ++ .../src/test/java/org/onap/so/TestApplication.java | 2 +- .../src/test/resources/afterMigrate.sql | 35 ++ .../src/test/resources/application-test.yaml | 1 + .../mso-requests-db/src/test/resources/schema.sql | 4 +- 17 files changed, 693 insertions(+), 367 deletions(-) delete mode 100644 mso-api-handlers/mso-requests-db/hibernate.properties delete mode 100644 mso-api-handlers/mso-requests-db/hibernate.reveng.xml delete mode 100644 mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml create mode 100644 mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java create mode 100644 mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java create mode 100644 mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java create mode 100644 mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/TimestampXMLAdapter.java delete mode 100644 mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/adapter/TimestampXMLAdapter.java delete mode 100644 mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/client/RequestsDbClient.java create mode 100644 mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/BaseTest.java create mode 100644 mso-api-handlers/mso-requests-db/src/test/resources/afterMigrate.sql (limited to 'mso-api-handlers/mso-requests-db') diff --git a/mso-api-handlers/mso-requests-db/hibernate.properties b/mso-api-handlers/mso-requests-db/hibernate.properties deleted file mode 100644 index cf56960f4b..0000000000 --- a/mso-api-handlers/mso-requests-db/hibernate.properties +++ /dev/null @@ -1,2 +0,0 @@ -hibernate.show_sql=true -hibernate.format_sql=true diff --git a/mso-api-handlers/mso-requests-db/hibernate.reveng.xml b/mso-api-handlers/mso-requests-db/hibernate.reveng.xml deleted file mode 100644 index cb1e8c6669..0000000000 --- a/mso-api-handlers/mso-requests-db/hibernate.reveng.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/pom.xml b/mso-api-handlers/mso-requests-db/pom.xml index 006058e98d..a3b0ec1258 100644 --- a/mso-api-handlers/mso-requests-db/pom.xml +++ b/mso-api-handlers/mso-requests-db/pom.xml @@ -74,6 +74,7 @@ org.springframework.boot spring-boot-starter-data-rest + true jar @@ -90,10 +91,10 @@ jar - beans - - **/beans/** - + client + + **/repository/** + diff --git a/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml b/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml deleted file mode 100644 index d62640525b..0000000000 --- a/mso-api-handlers/mso-requests-db/src/hibernate.reveng.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java index 0833064f8a..4a46a0d00d 100644 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/InfraRequests.java @@ -35,7 +35,7 @@ import javax.persistence.TemporalType; import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter; import org.apache.commons.lang3.builder.ToStringBuilder; -import org.onap.so.requestsdb.adapter.TimestampXMLAdapter; +import org.onap.so.requestsdb.TimestampXMLAdapter; import uk.co.blackpepper.bowman.annotation.ResourceId; diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java new file mode 100644 index 0000000000..34832b9917 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/beans/RequestProcessingData.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 Huawei Technologies Co., Ltd. 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.db.request.beans; + +import java.io.Serializable; +import java.util.Date; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.GenerationType; +import javax.persistence.Id; +import javax.persistence.PrePersist; +import javax.persistence.Table; +import javax.persistence.Temporal; +import javax.persistence.TemporalType; + +import org.apache.commons.lang3.builder.HashCodeBuilder; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.ToStringBuilder; + +import com.openpojo.business.annotation.BusinessKey; + +/** + * persist the request identifiers created when MSO POSTs a request to PINC + *
+ *

+ *

+ * + * @author + * @version + */ + +@Entity +@Table(name = "request_processing_data") +public class RequestProcessingData implements Serializable{ + + /** + * + */ + private static final long serialVersionUID = -3497593687393936143L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "ID") + private Integer id; + + @BusinessKey + @Column(name = "SO_REQUEST_ID", length=50, unique=true) + private String soRequestId; + + @BusinessKey + @Column(name = "GROUPING_ID", length=100, unique=true) + private String groupingId; + + @BusinessKey + @Column(name = "NAME", length=200) + private String name; + + @Column(name = "VALUE", columnDefinition = "LONGTEXT") + private String value; + + @BusinessKey + @Column(name = "TAG", length=200) + private String tag; + + @Column(name = "CREATE_TIME", insertable = false, updatable = false) + @Temporal(TemporalType.TIMESTAMP) + private Date created = null; + + @Override + public boolean equals(final Object other) { + if (!(other instanceof RequestProcessingData)) { + return false; + } + RequestProcessingData castOther = (RequestProcessingData) other; + return new EqualsBuilder().append(soRequestId, castOther.soRequestId).append(groupingId, castOther.groupingId) + .append(name, castOther.name).append(tag, castOther.tag).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(soRequestId).append(groupingId).append(name).append(tag).toHashCode(); + } + + @Override + public String toString() { + return new ToStringBuilder(this).append("id", id).append("soRequestId", soRequestId) + .append("groupingId", groupingId).append("name", name).append("value", value).append("tag", tag) + .toString(); + } + + @PrePersist + protected void createdAt() { + this.created = new Date(); + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getSoRequestId() { + return soRequestId; + } + + public void setSoRequestId(String soRequestId) { + this.soRequestId = soRequestId; + } + + public String getGroupingId() { + return groupingId; + } + + public void setGroupingId(String groupingId) { + this.groupingId = groupingId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public Date getCreated() { + return created; + } +} \ No newline at end of file diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java new file mode 100644 index 0000000000..54fec3ad4d --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/client/RequestsDbClient.java @@ -0,0 +1,366 @@ +/*- + * ============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.db.request.client; + +import java.io.IOException; +import java.net.URI; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import javax.annotation.PostConstruct; +import javax.ws.rs.core.UriBuilder; + +import org.apache.http.HttpStatus; +import org.onap.so.db.request.beans.ArchivedInfraRequests; +import org.onap.so.db.request.beans.InfraActiveRequests; +import org.onap.so.db.request.beans.OperationStatus; +import org.onap.so.db.request.beans.OperationalEnvDistributionStatus; +import org.onap.so.db.request.beans.OperationalEnvServiceModelStatus; +import org.onap.so.db.request.beans.RequestProcessingData; +import org.onap.so.db.request.beans.ResourceOperationStatus; +import org.onap.so.db.request.beans.SiteStatus; +import org.onap.so.db.request.beans.WatchdogComponentDistributionStatus; +import org.onap.so.db.request.beans.WatchdogDistributionStatus; +import org.onap.so.db.request.beans.WatchdogServiceModVerIdLookup; +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.context.annotation.Primary; +import org.springframework.core.ParameterizedTypeReference; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpRequest; +import org.springframework.http.client.ClientHttpRequestExecution; +import org.springframework.http.client.ClientHttpRequestInterceptor; +import org.springframework.http.client.ClientHttpResponse; +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 uk.co.blackpepper.bowman.RestTemplateConfigurer; + +@Component("RequestsDbClient") +@Primary +public class RequestsDbClient { + + private static final String SERVICE_ID = "SERVICE_ID"; + private static final String OPERATION_ID = "OPERATION_ID"; + private static final String SO_REQUEST_ID = "SO_REQUEST_ID"; + private static final String GROUPING_ID = "GROUPING_ID"; + private static final String REQUEST_ID = "REQUEST_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 NAME = "NAME"; + private static final String VALUE = "VALUE"; + private static final String TAG = "TAG"; + + private Client infraActiveRequestClient; + private Client operationStatusClient; + private Client requestProcessingDataClient; + private final Client distributionStatusClient; + private final Client serviceModelStatusClient; + + @Value("${mso.adapters.requestDb.endpoint}") + protected 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 operationalEnvDistributionStatusURI = "/operationalEnvDistributionStatus/"; + + private String findOneByServiceIdAndOperationIdURI = "/findOneByServiceIdAndOperationId"; + + private String findOneByOperationalEnvIdAndServiceModelVersionIdURI = "/findOneByOperationalEnvIdAndServiceModelVersionId"; + + private String findAllByOperationalEnvIdAndRequestIdURI = "/findAllByOperationalEnvIdAndRequestId"; + + private String cloudOrchestrationFiltersFromInfraActive = "/infraActiveRequests/getCloudOrchestrationFiltersFromInfraActive"; + + private String requestProcessingDataURI = "/requestProcessingData"; + + private String findOneBySoRequestIdAndGroupingIdAndNameAndTagURI = "/requestProcessingData/search/findOneBySoRequestIdAndGroupingIdAndNameAndTag/"; + + private String findBySoRequestIdOrderByGroupingIdDesc = "/requestProcessingData/search/findBySoRequestIdOrderByGroupingIdDesc/"; + + protected HttpHeaders headers; + + protected ClientFactory clientFactory; + + @Autowired + protected 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; + requestProcessingDataURI = endpoint + requestProcessingDataURI; + 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(new RestTemplateConfigurer() { + + public void configure(RestTemplate restTemplate) { + + restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() { + + public ClientHttpResponse intercept(HttpRequest request, byte[] body, + ClientHttpRequestExecution execution) throws IOException { + + request.getHeaders().add("Authorization", msoAdaptersAuth); + return execution.execute(request, body); + } + }); + } + }).build().buildClientFactory(); + infraActiveRequestClient = clientFactory.create(InfraActiveRequests.class); + operationStatusClient = clientFactory.create(OperationStatus.class); + requestProcessingDataClient = clientFactory.create(RequestProcessingData.class); + distributionStatusClient = clientFactory.create(OperationalEnvDistributionStatus.class); + serviceModelStatusClient = clientFactory.create(OperationalEnvServiceModelStatus.class); + } + + public List getCloudOrchestrationFiltersFromInfraActive(Map orchestrationMap){ + URI uri = getUri(cloudOrchestrationFiltersFromInfraActive); + HttpEntity entity = new HttpEntity<>(orchestrationMap, headers); + try{ + return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference>() {}).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 getOrchestrationFiltersFromInfraActive(Map> orchestrationMap) { + URI uri = getUri(getOrchestrationFilterURI); + HttpEntity>> entity = new HttpEntity<>(orchestrationMap, headers); + return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference>() {}).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 instanceIdMap, String instanceName, String requestScope) { + URI uri = getUri(checkInstanceNameDuplicate); + HttpEntity 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 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 getMultipleOperationalEnvServiceModelStatus(URI uri){ + Iterable iterable = serviceModelStatusClient.getAll(uri); + List serviceModelStatuses = new ArrayList<>(); + Iterator statusIterator = iterable.iterator(); + statusIterator.forEachRemaining(serviceModelStatuses::add); + return serviceModelStatuses; + } + + public void save(InfraActiveRequests infraActiveRequests) { + URI uri = getUri(infraActiveRequestURI); + HttpEntity entity = new HttpEntity<>(infraActiveRequests, headers); + restTemplate.postForLocation(uri, entity); + } + + public void save(T object){ + URI uri = getUri(endpoint+classURLMapper.getURI(object.getClass())); + HttpEntity entity = new HttpEntity<>(object, headers); + restTemplate.postForLocation(uri, entity); + } + + private OperationalEnvDistributionStatus getSingleOperationalEnvDistributionStatus(URI uri){ + return distributionStatusClient.get(uri); + } + + protected InfraActiveRequests getSingleInfraActiveRequests(URI uri) { + return infraActiveRequestClient.get(uri); + } + + public void updateInfraActiveRequests(InfraActiveRequests request) { + infraActiveRequestClient.put(request); + } + + protected URI getUri(String uri) { + return URI.create(uri); + } + + + + public OperationStatus getSingleOperationStatus(URI uri){ + return operationStatusClient.get(uri); + } + + public void saveRequestProcessingData(RequestProcessingData requestProcessingData) { + URI uri = getUri(endpoint + requestProcessingDataURI); + HttpEntity entity = new HttpEntity<>(requestProcessingData, headers); + restTemplate.postForLocation(uri, entity); + } + + public RequestProcessingData getRequestProcessingDataBySoRequestIdAndGroupingIdAndNameAndTag(String soRequestId, + String groupingId, String name, String tag) { + return this.getSingleRequestProcessingData(UriBuilder.fromUri(endpoint + findOneBySoRequestIdAndGroupingIdAndNameAndTagURI) + .queryParam(SO_REQUEST_ID,soRequestId) + .queryParam(GROUPING_ID,groupingId) + .queryParam(NAME,name) + .queryParam(TAG,tag) + .build()); + } + public List getRequestProcessingDataBySoRequestId(String soRequestId) { + return this.getRequestProcessingData(UriBuilder.fromUri(endpoint + findBySoRequestIdOrderByGroupingIdDesc) + .queryParam(SO_REQUEST_ID,soRequestId) + .build()); + } + + public RequestProcessingData getSingleRequestProcessingData(URI uri){ + return requestProcessingDataClient.get(uri); + } + + private List getRequestProcessingData(URI uri) { + Iterable requestProcessingDataIterator = requestProcessingDataClient.getAll(uri); + List requestProcessingDataList = new ArrayList<>(); + Iterator it = requestProcessingDataIterator.iterator(); + it.forEachRemaining(requestProcessingDataList::add); + return requestProcessingDataList; + } + + public List getAllRequestProcessingData() { + + return (List) this.getAllRequestProcessingData(UriBuilder.fromUri(endpoint + "/requestProcessingData").build()); + } + + private Iterable getAllRequestProcessingData(URI uri) { + return requestProcessingDataClient.getAll(uri); + } + + @Bean + public RestTemplate restTemplate() { + return new RestTemplate( new HttpComponentsClientHttpRequestFactory()); + } + + @Component + static class ClassURLMapper { + private static final Map 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/"); + } + + String getURI(Class className) { + Class actualClass = classURLMap.keySet() + .stream() + .filter(requestdbClass -> requestdbClass.isAssignableFrom(className)) + .findFirst() + .get(); + return classURLMap.get(actualClass); + } + } + + //USED FOR TEST ONLY + public void setPortToEndpoint(String port) { + endpoint = endpoint + port; + } + + //USED FOR TEST ONLY + public void removePortFromEndpoint() { + endpoint = endpoint.substring(0, endpoint.lastIndexOf(':') + 1); + } +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java new file mode 100644 index 0000000000..f80be0525c --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/db/request/data/repository/RequestProcessingDataRepository.java @@ -0,0 +1,37 @@ +/*- + * ============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.db.request.data.repository; + +import java.util.List; + +import org.onap.so.db.request.beans.RequestProcessingData; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.repository.query.Param; +import org.springframework.data.rest.core.annotation.RepositoryRestResource; + +@RepositoryRestResource(collectionResourceRel = "requestProcessingData", path = "requestProcessingData") +public interface RequestProcessingDataRepository extends JpaRepository { + RequestProcessingData findOneBySoRequestIdAndGroupingIdAndNameAndTag( + @Param("SO_REQUEST_ID") String soRequestId, @Param("GROUPING_ID") String groupingId, + @Param("NAME") String name, @Param("TAG") String tag); + + List findBySoRequestIdOrderByGroupingIdDesc(@Param("SO_REQUEST_ID") String soRequestId); +} 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 562e54ca6e..ea3ef30827 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 @@ -24,8 +24,9 @@ import java.sql.Timestamp; import org.onap.so.db.request.beans.InfraActiveRequests; import org.onap.so.logger.MsoLogger; -import org.onap.so.requestsdb.client.RequestsDbClient; +import org.onap.so.db.request.client.RequestsDbClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.stereotype.Component; @Component @@ -37,6 +38,7 @@ public class RequestsDBHelper { private String methodName = ""; private String classMethodMessage = ""; @Autowired + @Qualifier("RequestsDbClient") private RequestsDbClient requestsDbClient; /** * This util method is to update the InfraRequest table to Complete diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/TimestampXMLAdapter.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/TimestampXMLAdapter.java new file mode 100644 index 0000000000..3a326598a7 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/TimestampXMLAdapter.java @@ -0,0 +1,42 @@ +/*- + * ============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; + + +import java.sql.Timestamp; + +import javax.xml.bind.annotation.adapters.XmlAdapter; + +public class TimestampXMLAdapter extends XmlAdapter { + + @Override + public Long marshal (Timestamp v) throws Exception { + return v.getTime (); + } + + @Override + public Timestamp unmarshal (Long v) throws Exception { + if (v == null) { + return new Timestamp(0); + } + return new Timestamp (v); + } +} diff --git a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/adapter/TimestampXMLAdapter.java b/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/adapter/TimestampXMLAdapter.java deleted file mode 100644 index 1cde1aac51..0000000000 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/adapter/TimestampXMLAdapter.java +++ /dev/null @@ -1,42 +0,0 @@ -/*- - * ============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.adapter; - - -import java.sql.Timestamp; - -import javax.xml.bind.annotation.adapters.XmlAdapter; - -public class TimestampXMLAdapter extends XmlAdapter { - - @Override - public Long marshal (Timestamp v) throws Exception { - return v.getTime (); - } - - @Override - public Timestamp unmarshal (Long v) throws Exception { - if (v == null) { - return new Timestamp(0); - } - return new Timestamp (v); - } -} 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 deleted file mode 100644 index 8e291aa15b..0000000000 --- a/mso-api-handlers/mso-requests-db/src/main/java/org/onap/so/requestsdb/client/RequestsDbClient.java +++ /dev/null @@ -1,272 +0,0 @@ -/*- - * ============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 infraActiveRequestClient; - private final Client operationStatusClient; - private final Client distributionStatusClient; - private final Client 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 getCloudOrchestrationFiltersFromInfraActive(Map orchestrationMap){ - URI uri = getUri(cloudOrchestrationFiltersFromInfraActive); - HttpEntity entity = new HttpEntity<>(orchestrationMap, headers); - try{ - return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference>() {}).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 getOrchestrationFiltersFromInfraActive(Map> orchestrationMap) { - URI uri = getUri(getOrchestrationFilterURI); - HttpEntity>> entity = new HttpEntity<>(orchestrationMap, headers); - return restTemplate.exchange(uri, HttpMethod.POST, entity, new ParameterizedTypeReference>() {}).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 instanceIdMap, String instanceName, String requestScope) { - URI uri = getUri(checkInstanceNameDuplicate); - HttpEntity 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 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 getMultipleOperationalEnvServiceModelStatus(URI uri){ - Iterable iterable = serviceModelStatusClient.getAll(uri); - List serviceModelStatuses = new ArrayList<>(); - Iterator statusIterator = iterable.iterator(); - statusIterator.forEachRemaining(serviceModelStatuses::add); - return serviceModelStatuses; - } - - public void save(InfraActiveRequests infraActiveRequests) { - URI uri = getUri(infraActiveRequestURI); - HttpEntity entity = new HttpEntity<>(infraActiveRequests, headers); - restTemplate.postForLocation(uri, entity); - } - - public void save(T object){ - URI uri = getUri(endpoint+classURLMapper.getURI(object.getClass())); - HttpEntity 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 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/"); - } - - String getURI(Class 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/java/org/onap/so/BaseTest.java b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/BaseTest.java new file mode 100644 index 0000000000..5a8df1d556 --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/BaseTest.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2017 - 2018 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; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = TestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@ActiveProfiles("test") +public abstract class BaseTest { + +} diff --git a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/TestApplication.java b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/TestApplication.java index ec2c41bf8c..00d212a23e 100644 --- a/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/TestApplication.java +++ b/mso-api-handlers/mso-requests-db/src/test/java/org/onap/so/TestApplication.java @@ -24,7 +24,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Profile; -@SpringBootApplication(scanBasePackages = { "org.onap" }) +@SpringBootApplication(scanBasePackages = { "org.onap.so.db" }) @Profile("test") public class TestApplication { public static void main(String... args) { diff --git a/mso-api-handlers/mso-requests-db/src/test/resources/afterMigrate.sql b/mso-api-handlers/mso-requests-db/src/test/resources/afterMigrate.sql new file mode 100644 index 0000000000..897dd3faca --- /dev/null +++ b/mso-api-handlers/mso-requests-db/src/test/resources/afterMigrate.sql @@ -0,0 +1,35 @@ +use requestdb; + +insert into operation_status(service_id, operation_id, service_name, user_id, result, operation_content, progress, reason, operate_at, finished_at) values +('serviceid', 'operationid', 'servicename', 'userid', 'result', 'operationcontent', 'progress', 'reason', '2016-11-24 13:19:10', '2016-11-24 13:19:10'); + + +insert into infra_active_requests(request_id, client_request_id, action, request_status, status_message, progress, start_time, end_time, source, vnf_id, vnf_name, vnf_type, service_type, aic_node_clli, tenant_id, prov_status, vnf_params, vnf_outputs, request_body, response_body, last_modified_by, modify_time, request_type, volume_group_id, volume_group_name, vf_module_id, vf_module_name, vf_module_model_name, aai_service_id, aic_cloud_region, callback_url, correlator, network_id, network_name, network_type, request_scope, request_action, service_instance_id, service_instance_name, requestor_id, configuration_id, configuration_name, operational_env_id, operational_env_name) values +('00032ab7-3fb3-42e5-965d-8ea592502017', '00032ab7-3fb3-42e5-965d-8ea592502016', 'deleteInstance', 'COMPLETE', 'Vf Module has been deleted successfully.', '100', '2016-12-22 18:59:54', '2016-12-22 19:00:28', 'VID', 'b92f60c8-8de3-46c1-8dc1-e4390ac2b005', null, null, null, null, '6accefef3cb442ff9e644d589fb04107', null, null, null, '{"requestDetails":{"modelInfo":{"modelType":"vfModule","modelName":"vSAMP10aDEV::base::module-0"},"requestInfo":{"source":"VID"},"cloudConfiguration":{"tenantId":"6accefef3cb442ff9e644d589fb04107","lcpCloudRegionId":"mtn6"}}}', null, 'BPMN', '2016-12-22 19:00:28', null, null, null, 'c7d527b1-7a91-49fd-b97d-1c8c0f4a7992', null, 'vSAMP10aDEV::base::module-0', null, 'mtn6', null, null, null, null, null, 'vfModule', 'deleteInstance', 'e3b5744d-2ad1-4cdd-8390-c999a38829bc', null, null, null, null, null, null), +('00093944-bf16-4373-ab9a-3adfe730ff2d', null, 'createInstance', 'FAILED', 'Error: Locked instance - This service (MSODEV_1707_SI_vSAMP10a_011-4) already has a request being worked with a status of IN_PROGRESS (RequestId - 278e83b1-4f9f-450e-9e7d-3700a6ed22f4). The existing request must finish or be cleaned up before proceeding.', '100', '2017-07-11 18:33:26', '2017-07-11 18:33:26', 'VID', null, null, null, null, null, '19123c2924c648eb8e42a3c1f14b7682', null, null, null, '{"requestDetails":{"modelInfo":{"modelInvariantId":"9647dfc4-2083-11e7-93ae-92361f002671","modelType":"service","modelName":"MSOTADevInfra_vSAMP10a_Service","modelVersion":"1.0","modelVersionId":"5df8b6de-2083-11e7-93ae-92361f002671"},"requestInfo":{"source":"VID","instanceName":"MSODEV_1707_SI_vSAMP10a_011-4","suppressRollback":false,"requestorId":"xxxxxx"},"subscriberInfo":{"globalSubscriberId":"MSO_1610_dev","subscriberName":"MSO_1610_dev"},"cloudConfiguration":{"tenantId":"19123c2924c648eb8e42a3c1f14b7682","lcpCloudRegionId":"mtn6"},"requestParameters":{"subscriptionServiceType":"MSO-dev-service-type","userParams":[{"name":"someUserParam","value":"someValue"}],"aLaCarte":true,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true,"alaCarteSet":true,"alaCarte":true}}}', null, 'APIH', '2016-12-22 19:00:28', null, null, null, null, null, null, null, 'mtn6', null, null, null, null, null, 'service', 'createInstance', null, 'MSODEV_1707_SI_vSAMP10a_011-4', 'xxxxxx', null, null, null, null), +('001619d2-a297-4a4b-a9f5-e2823c88458f', '001619d2-a297-4a4b-a9f5-e2823c88458f', 'CREATE_VF_MODULE', 'COMPLETE', 'COMPLETED', '100', '2016-07-01 14:11:42', '2017-05-02 16:03:34', 'PORTAL', null, 'test-vscp', 'elena_test21', null, null, '381b9ff6c75e4625b7a4182f90fc68d3', null, null, null, '\n\n \n 001619d2-a297-4a4b-a9f5-e2823c88458f\n CREATE_VF_MODULE\n PORTAL\n \n \n test-vscp\n moduleName\n elena_test21\n moduleModelName\n 1.0\n a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb\n mtn9\n 381b9ff6c75e4625b7a4182f90fc68d3\n \n \n false\n \n \n\n', 'NONE', 'RDBTEST', '2016-07-01 14:11:42', 'VNF', null, null, null, 'MODULENAME1', 'moduleModelName', 'a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb', 'mtn9', null, null, null, null, null, 'vfModule', 'createInstance', null, null, null, null, null, null, null), +('00164b9e-784d-48a8-8973-bbad6ef818ed', null, 'createInstance', 'COMPLETE', 'Service Instance was created successfully.', '100', '2017-09-28 12:45:51', '2017-09-28 12:45:53', 'VID', null, null, null, null, null, '19123c2924c648eb8e42a3c1f14b7682', null, null, null, '{"requestDetails":{"requestDetails":{"modelInfo":{"modelCustomizationName":null,"modelInvariantId":"52b49b5d-3086-4ffd-b5e6-1b1e5e7e062f","modelType":"service","modelNameVersionId":null,"modelName":"MSO Test Network","modelVersion":"1.0","modelCustomizationUuid":null,"modelVersionId":"aed5a5b7-20d3-44f7-90a3-ddbd16f14d1e","modelCustomizationId":null,"modelUuid":null,"modelInvariantUuid":null,"modelInstanceName":null},"requestInfo":{"billingAccountNumber":null,"callbackUrl":null,"correlator":null,"orderNumber":null,"productFamilyId":null,"orderVersion":null,"source":"VID","instanceName":"DEV-MTN6-3100-0927-1","suppressRollback":false,"requestorId":"xxxxxx"},"relatedInstanceList":null,"subscriberInfo":{"globalSubscriberId":"MSO_1610_dev","subscriberName":"MSO_1610_dev"},"cloudConfiguration":{"aicNodeClli":null,"tenantId":"19123c2924c648eb8e42a3c1f14b7682","lcpCloudRegionId":"mtn6"},"requestParameters":{"subscriptionServiceType":"MSO-dev-service-type","userParams":[{"name":"someUserParam","value":"someValue"}],"aLaCarte":true,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true,"alaCarte":true},"project":null,"owningEntity":null,"platform":null,"lineOfBusiness":null}}}', null, 'CreateGenericALaCarteServiceInstance', '2017-09-28 12:45:52', null, null, null, null, null, null, null, 'mtn6', null, null, null, null, null, 'service', 'createInstance', 'b2f59173-b7e5-4e0f-8440-232fd601b865', 'DEV-MTN6-3100-0927-1', 'xxxxxx', null, null, null, null), +('00173cc9-5ce2-4673-a810-f87fefb2829e', null, 'createInstance', 'FAILED', 'Error parsing request. No valid instanceName is specified', '100', '2017-04-14 21:08:46', '2017-04-14 21:08:46', 'VID', null, null, null, null, null, 'a259ae7b7c3f493cb3d91f95a7c18149', null, null, null, '{"requestDetails":{"modelInfo":{"modelInvariantId":"ff6163d4-7214-459e-9f76-507b4eb00f51","modelType":"service","modelName":"ConstraintsSrvcVID","modelVersion":"2.0","modelVersionId":"722d256c-a374-4fba-a14f-a59b76bb7656"},"requestInfo":{"productFamilyId":"LRSI-OSPF","source":"VID","requestorId":"xxxxxx"},"subscriberInfo":{"globalSubscriberId":"a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"},"cloudConfiguration":{"tenantId":"a259ae7b7c3f493cb3d91f95a7c18149","lcpCloudRegionId":"mtn16"},"requestParameters":{"subscriptionServiceType":"Mobility","userParams":[{"name":"neutronport6_name","value":"8"},{"name":"neutronnet5_network_name","value":"8"},{"name":"contrailv2vlansubinterface3_name","value":"false"}]}}}', null, 'APIH', '2016-12-22 19:00:28', null, null, null, null, null, null, null, 'mtn16', null, null, null, null, null, 'service', 'createInstance', null, null, null, null, null, null, null), +('0017f68c-eb2d-45bb-b7c7-ec31b37dc349', null, 'activateInstance', 'UNLOCKED', null, '20', '2017-09-26 16:09:29', '2017-09-28 12:45:53', 'VID', null, null, null, null, null, null, null, null, null, '{"requestDetails":{"modelInfo":{"modelCustomizationName":null,"modelInvariantId":"1587cf0e-f12f-478d-8530-5c55ac578c39","modelType":"configuration","modelNameVersionId":null,"modelName":null,"modelVersion":null,"modelCustomizationUuid":null,"modelVersionId":"36a3a8ea-49a6-4ac8-b06c-89a545444455","modelCustomizationId":"68dc9a92-214c-11e7-93ae-92361f002671","modelUuid":null,"modelInvariantUuid":null,"modelInstanceName":null},"requestInfo":{"billingAccountNumber":null,"callbackUrl":null,"correlator":null,"orderNumber":null,"productFamilyId":null,"orderVersion":null,"source":"VID","instanceName":null,"suppressRollback":false,"requestorId":"xxxxxx"},"relatedInstanceList":[{"relatedInstance":{"instanceName":null,"instanceId":"9e15a443-af65-4f05-9000-47ae495e937d","modelInfo":{"modelCustomizationName":null,"modelInvariantId":"de19ae10-9a25-11e7-abc4-cec278b6b50a","modelType":"service","modelNameVersionId":null,"modelName":"MSOTADevInfra_Configuration_Service","modelVersion":"1.0","modelCustomizationUuid":null,"modelVersionId":"ee938612-9a25-11e7-abc4-cec278b6b50a","modelCustomizationId":null,"modelUuid":null,"modelInvariantUuid":null,"modelInstanceName":null},"instanceDirection":null}}],"subscriberInfo":null,"cloudConfiguration":{"aicNodeClli":null,"tenantId":null,"lcpCloudRegionId":"mtn6"},"requestParameters":{"subscriptionServiceType":null,"userParams":[],"aLaCarte":false,"autoBuildVfModules":false,"cascadeDelete":false,"usePreload":true,"alaCarte":false},"project":null,"owningEntity":null,"platform":null,"lineOfBusiness":null}}', null, 'APIH', '2017-09-26 16:09:29', null, null, null, null, null, null, null, 'mtn6', null, null, null, null, null, 'configuration', 'activateInstance', '9e15a443-af65-4f05-9000-47ae495e937d', null, 'xxxxxx', '26ef7f15-57bb-48df-8170-e59edc26234c', null, null, null); + +insert into watchdog_distributionid_status(distribution_id, distribution_id_status, create_time, modify_time) values +('1533c4bd-a3e3-493f-a16d-28c20614415e', '', '2017-11-30 15:48:09', '2017-11-30 15:48:09'), +('55429711-809b-4a3b-9ee5-5120d46d9de0', '', '2017-11-30 16:35:36', '2017-11-30 16:35:36'), +('67f0b2d1-9013-4b2b-9914-bbe2288284fb', '', '2017-11-30 15:54:39', '2017-11-30 15:54:39'); + +insert into watchdog_per_component_distribution_status(distribution_id, component_name, component_distribution_status, create_time, modify_time) values +('1533c4bd-a3e3-493f-a16d-28c20614415e', 'MSO', 'COMPONENT_DONE_OK', '2017-11-30 15:48:09', '2017-11-30 15:48:09'), +('55429711-809b-4a3b-9ee5-5120d46d9de0', 'MSO', 'COMPONENT_DONE_ERROR', '2017-11-30 16:35:36', '2017-11-30 16:35:36'), +('67f0b2d1-9013-4b2b-9914-bbe2288284fb', 'MSO', 'COMPONENT_DONE_OK', '2017-11-30 15:54:39', '2017-11-30 15:54:39'); + +insert into watchdog_service_mod_ver_id_lookup(distribution_id, service_model_version_id, create_time, modify_time) values +('1533c4bd-a3e3-493f-a16d-28c20614415e', '7e813ab5-88d3-4fcb-86c0-498c5d7eef9a', '2017-11-30 15:48:08', '2017-11-30 15:48:08'), +('55429711-809b-4a3b-9ee5-5120d46d9de0', 'cc031e75-4442-4d1a-b774-8a2b434e0a50', '2017-11-30 16:35:36', '2017-11-30 16:35:36'), +('67f0b2d1-9013-4b2b-9914-bbe2288284fb', 'eade1e9d-c1ec-4ef3-bc31-60570fba1573', '2017-11-30 15:54:39', '2017-11-30 15:54:39'); + + +insert into site_status(site_name, status, creation_timestamp) values +('testsite', 0, '2017-11-30 15:48:09'); + +INSERT INTO requestdb.request_processing_data (ID, SO_REQUEST_ID, GROUPING_ID, NAME, VALUE, TAG) VALUES +(1, 'fbb8df64-9be5-11e8-98d0-529269fb1459', '12b84dc6-9be6-11e8-98d0-529269fb1459', 'test-name', 'test-value', 'test-tag'); \ No newline at end of file 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 62ae4794f5..c4dd60356b 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 @@ -12,6 +12,7 @@ mso: endpoint: http://localhost:8081 site-name: localDevEnv logPath: logs + # H2 spring: datasource: diff --git a/mso-api-handlers/mso-requests-db/src/test/resources/schema.sql b/mso-api-handlers/mso-requests-db/src/test/resources/schema.sql index a01153a43c..ab554d440b 100644 --- a/mso-api-handlers/mso-requests-db/src/test/resources/schema.sql +++ b/mso-api-handlers/mso-requests-db/src/test/resources/schema.sql @@ -207,6 +207,4 @@ ALTER TABLE PUBLIC.SITE_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_C PRIMARY KEY(SI ALTER TABLE PUBLIC.WATCHDOG_DISTRIBUTIONID_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_7 PRIMARY KEY(DISTRIBUTION_ID); ALTER TABLE PUBLIC.WATCHDOG_PER_COMPONENT_DISTRIBUTION_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_D PRIMARY KEY(DISTRIBUTION_ID, COMPONENT_NAME); ALTER TABLE PUBLIC.WATCHDOG_SERVICE_MOD_VER_ID_LOOKUP ADD CONSTRAINT PUBLIC.CONSTRAINT_6 PRIMARY KEY(DISTRIBUTION_ID, SERVICE_MODEL_VERSION_ID); -ALTER TABLE PUBLIC.WATCHDOG_PER_COMPONENT_DISTRIBUTION_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_DE FOREIGN KEY(DISTRIBUTION_ID) REFERENCES PUBLIC.WATCHDOG_DISTRIBUTIONID_STATUS(DISTRIBUTION_ID) NOCHECK; - - +ALTER TABLE PUBLIC.WATCHDOG_PER_COMPONENT_DISTRIBUTION_STATUS ADD CONSTRAINT PUBLIC.CONSTRAINT_DE FOREIGN KEY(DISTRIBUTION_ID) REFERENCES PUBLIC.WATCHDOG_DISTRIBUTIONID_STATUS(DISTRIBUTION_ID) NOCHECK; \ No newline at end of file -- cgit 1.2.3-korg