diff options
31 files changed, 498 insertions, 441 deletions
diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java index 6c1c81c6ef..195ada37f7 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceInfo.java @@ -24,8 +24,11 @@ import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.beans.ServiceInfo; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.util.CollectionUtils; import javax.xml.bind.annotation.XmlRootElement; +import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; @XmlRootElement(name = "serviceInfo") @@ -45,8 +48,10 @@ public class QueryServiceInfo extends CatalogQuery { this.serviceInfo = new ServiceInfo(); } - public QueryServiceInfo(ServiceInfo serviceInfo) { - this.serviceInfo = serviceInfo; + public QueryServiceInfo(List<ServiceInfo> serviceInfos) { + if (!CollectionUtils.isEmpty(serviceInfos)) { + this.serviceInfo = serviceInfos.get(0); + } } public ServiceInfo getServiceInfo() { diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java index d5aa472c8d..305d52a997 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/catalogrest/QueryServiceMacroHolder.java @@ -94,7 +94,7 @@ public class QueryServiceMacroHolder extends CatalogQuery { subitem = new QueryAllottedResourceCustomization(service.getAllottedCustomizations()).JSON2(true, true); valueMap.put("_SERVICEALLOTTEDRESOURCES_", subitem.replaceAll(LINE_BEGINNING, "\t")); - subitem = new QueryServiceInfo(serviceMacroHolder.getServiceInfo()).JSON2(true, true); + subitem = new QueryServiceInfo(service.getServiceInfos()).JSON2(true, true); valueMap.put("_SERVICEINFO_", subitem.replaceAll(LINE_BEGINNING, "\t")); subitem = new QueryServiceProxyCustomization(service.getServiceProxyCustomizations()).JSON2(true, true); diff --git a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java index fca1d3a45e..98abf15645 100644 --- a/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java +++ b/adapters/mso-catalog-db-adapter/src/main/java/org/onap/so/adapters/catalogdb/rest/CatalogDbAdapterRest.java @@ -102,9 +102,6 @@ public class CatalogDbAdapterRest { @Autowired private InstanceGroupRepository instanceGroupRepository; - @Autowired - private ServiceInfoRepository serviceInfoRepository; - private static final String NO_MATCHING_PARAMETERS = "no matching parameters"; public Response respond(String version, int respStatus, boolean isArray, CatalogQuery qryResp) { @@ -307,8 +304,6 @@ public class CatalogDbAdapterRest { respStatus = HttpStatus.SC_NOT_FOUND; qryResp = new QueryServiceMacroHolder(); } else { - ServiceInfo serviceInfo = serviceInfoRepository.findByService(ret.getService()); - ret.setServiceInfo(serviceInfo); qryResp = new QueryServiceMacroHolder(ret); logger.debug("serviceMacroHolder qryResp= {}", qryResp); } diff --git a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V7.5__AddServiceArtifact.sql b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V7.5__AddServiceArtifact.sql index d32c4666c5..6ef8446a9f 100644 --- a/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V7.5__AddServiceArtifact.sql +++ b/adapters/mso-catalog-db-adapter/src/main/resources/db/migration/V7.5__AddServiceArtifact.sql @@ -4,7 +4,9 @@ CREATE TABLE IF NOT EXISTS `service_info` ( `ID` int (11) AUTO_INCREMENT, `SERVICE_INPUT` varchar (5000), `SERVICE_PROPERTIES` varchar (5000), - PRIMARY KEY (`ID`) + `SERVICE_MODEL_UUID` varchar (200) NOT NULL, + PRIMARY KEY (`ID`), + CONSTRAINT `fk_service_info_service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `service_artifact`( @@ -18,13 +20,5 @@ CREATE TABLE IF NOT EXISTS `service_artifact`( `CREATION_TIMESTAMP` DATETIME DEFAULT CURRENT_TIMESTAMP, `SERVICE_MODEL_UUID` varchar (200) NOT NULL, PRIMARY KEY (`ARTIFACT_UUID`), - CONSTRAINT `fk_service_artifact_service_info1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE + CONSTRAINT `fk_service_artifact_service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=latin1; - -CREATE TABLE IF NOT EXISTS `service_to_service_info` ( - `SERVICE_MODEL_UUID` varchar (200) NOT NULL, - `SERVICE_INFO_ID` INT (11) NOT NULL, - PRIMARY KEY (`SERVICE_MODEL_UUID`,`SERVICE_INFO_ID`), - CONSTRAINT `fk_service_to_service_info__service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_service_to_service_info__service_info1` FOREIGN KEY (`SERVICE_INFO_ID`) REFERENCES `service_info` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE -)
\ No newline at end of file diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCConnector.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCConnector.java index 431e9db87b..ea24a0ce3e 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCConnector.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCConnector.java @@ -11,9 +11,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -27,6 +27,8 @@ package org.onap.so.adapters.sdnc.sdncrest; import java.io.StringReader; import java.net.HttpURLConnection; import java.net.SocketTimeoutException; +import java.util.Arrays; +import java.util.List; import javax.xml.XMLConstants; import javax.xml.bind.DatatypeConverter; import javax.xml.parsers.DocumentBuilderFactory; @@ -71,7 +73,6 @@ import org.springframework.core.env.Environment; public abstract class SDNCConnector { private static final Logger logger = LoggerFactory.getLogger(SDNCConnector.class); - private static final String MSO_INTERNAL_ERROR = "MsoInternalError"; private static final String XPATH_EXCEPTION = "XPath Exception"; @Autowired private Environment env; @@ -84,32 +85,10 @@ public abstract class SDNCConnector { HttpResponse httpResponse = null; try { - int timeout = Integer.parseInt(rt.getTimeout()); - - RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout) - .setConnectionRequestTimeout(timeout).build(); HttpClient client = HttpClientBuilder.create().build(); - if ("POST".equals(rt.getReqMethod())) { - HttpPost httpPost = new HttpPost(rt.getSdncUrl()); - httpPost.setConfig(requestConfig); - httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_XML)); - method = httpPost; - } else if ("PUT".equals(rt.getReqMethod())) { - HttpPut httpPut = new HttpPut(rt.getSdncUrl()); - httpPut.setConfig(requestConfig); - httpPut.setEntity(new StringEntity(content, ContentType.APPLICATION_XML)); - method = httpPut; - } else if ("GET".equals(rt.getReqMethod())) { - HttpGet httpGet = new HttpGet(rt.getSdncUrl()); - httpGet.setConfig(requestConfig); - method = httpGet; - } else if ("DELETE".equals(rt.getReqMethod())) { - HttpDelete httpDelete = new HttpDelete(rt.getSdncUrl()); - httpDelete.setConfig(requestConfig); - method = httpDelete; - } + method = getHttpRequestMethod(content, rt); String userCredentials = CryptoUtils.decrypt(env.getProperty(Constants.SDNC_AUTH_PROP), @@ -122,8 +101,6 @@ public abstract class SDNCConnector { logger.debug("method is NULL:"); } - - httpResponse = client.execute(method); String responseContent = null; @@ -141,7 +118,7 @@ public abstract class SDNCConnector { String errMsg = "SDNC returned " + statusCode + " " + statusMessage; String errors = analyzeErrors(responseContent); - if (errors != null) { + if (errors != null && !errors.isEmpty()) { errMsg += " " + errors; } @@ -192,6 +169,36 @@ public abstract class SDNCConnector { } } + private HttpRequestBase getHttpRequestMethod(String content, TypedRequestTunables rt) { + + int timeout = Integer.parseInt(rt.getTimeout()); + HttpRequestBase method = null; + + RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout).setConnectTimeout(timeout) + .setConnectionRequestTimeout(timeout).build(); + + if ("POST".equals(rt.getReqMethod())) { + HttpPost httpPost = new HttpPost(rt.getSdncUrl()); + httpPost.setConfig(requestConfig); + httpPost.setEntity(new StringEntity(content, ContentType.APPLICATION_XML)); + method = httpPost; + } else if ("PUT".equals(rt.getReqMethod())) { + HttpPut httpPut = new HttpPut(rt.getSdncUrl()); + httpPut.setConfig(requestConfig); + httpPut.setEntity(new StringEntity(content, ContentType.APPLICATION_XML)); + method = httpPut; + } else if ("GET".equals(rt.getReqMethod())) { + HttpGet httpGet = new HttpGet(rt.getSdncUrl()); + httpGet.setConfig(requestConfig); + method = httpGet; + } else if ("DELETE".equals(rt.getReqMethod())) { + HttpDelete httpDelete = new HttpDelete(rt.getSdncUrl()); + httpDelete.setConfig(requestConfig); + method = httpDelete; + } + return method; + } + protected void logError(String errMsg) { logger.error(LoggingAnchor.FOUR, MessageEnum.RA_EXCEPTION_COMMUNICATE_SDNC.toString(), "SDNC", ErrorCode.AvailabilityError.getValue(), errMsg); @@ -205,7 +212,7 @@ public abstract class SDNCConnector { /** * Generates a response object from content received from SDNC. The response object may be a success response object * or an error response object. This method must be overridden by the subclass to return the correct object type. - * + * * @param statusCode the response status code from SDNC (e.g. 200) * @param statusMessage the response status message from SDNC (e.g. "OK") * @param responseContent the body of the response from SDNC (possibly null) @@ -218,7 +225,7 @@ public abstract class SDNCConnector { /** * Generates an error response object. This method must be overridden by the subclass to return the correct object * type. - * + * * @param statusCode the response status code (from SDNC, or internally generated) * @param errMsg the error message (normally a verbose explanation of the error) * @param rt request tunables @@ -229,17 +236,17 @@ public abstract class SDNCConnector { /** * Called by the send() method to analyze errors that may be encoded in the content of non-2XX responses. By * default, this method tries to parse the content as a restconf error. - * + * * <pre> * xmlns = "urn:ietf:params:xml:ns:yang:ietf-restconf" * </pre> - * + * * If an error (or errors) can be obtained from the content, then the result is a string in this format: - * + * * <pre> * [error-type:TYPE, error-tag:TAG, error-message:MESSAGE] ... * </pre> - * + * * If no error could be obtained from the content, then the result is null. * <p> * The subclass can override this method to provide another implementation. @@ -262,7 +269,7 @@ public abstract class SDNCConnector { // </error> // </errors> - StringBuilder output = null; + String output = null; try { XPathFactory xpathFactory = XPathFactory.newInstance(); @@ -274,55 +281,47 @@ public abstract class SDNCConnector { InputSource source = new InputSource(new StringReader(content)); Document doc = documentBuilderFactory.newDocumentBuilder().parse(source); NodeList errors = (NodeList) xpath.evaluate("errors/error", doc, XPathConstants.NODESET); + StringBuilder errorDetails = getErrorDetails(xpath, errors); + if (errorDetails != null) { + output = errorDetails.toString(); + } + } catch (Exception e) { + logger.error(LoggingAnchor.FOUR, MessageEnum.RA_ANALYZE_ERROR_EXC.toString(), "SDNC", + ErrorCode.DataError.getValue(), "Exception while analyzing errors", e); + } - for (int i = 0; i < errors.getLength(); i++) { - Element error = (Element) errors.item(i); + return output; + } - String info = ""; + private StringBuilder getErrorDetails(XPath xpath, NodeList errors) { - try { - String errorType = xpath.evaluate("error-type", error); - info += "error-type:" + errorType; - } catch (XPathExpressionException e) { - logger.error(LoggingAnchor.SIX, MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-type", - error.toString(), "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); - } + StringBuilder output = null; - try { - String errorTag = xpath.evaluate("error-tag", error); - if (!info.isEmpty()) { - info += ", "; - } - info += "error-tag:" + errorTag; - } catch (XPathExpressionException e) { - logger.error(LoggingAnchor.SIX, MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-tag", - error.toString(), "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); - } + for (int i = 0; i < errors.getLength(); i++) { + Element error = (Element) errors.item(i); + + StringBuilder info = new StringBuilder(); + List<String> errorAttributesList = Arrays.asList("error-type", "error-tag", "error-message"); + + for (String errorAttrib : errorAttributesList) { try { - String errorMessage = xpath.evaluate("error-message", error); - if (!info.isEmpty()) { - info += ", "; - } - info += "error-message:" + errorMessage; - } catch (Exception e) { - logger.error(LoggingAnchor.SIX, MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), "error-message", + String errorAttribValue = xpath.evaluate(errorAttrib, error); + info.append(errorAttrib).append(":").append(errorAttribValue); + } catch (XPathExpressionException e) { + logger.error(LoggingAnchor.SIX, MessageEnum.RA_EVALUATE_XPATH_ERROR.toString(), errorAttrib, error.toString(), "SDNC", ErrorCode.DataError.getValue(), XPATH_EXCEPTION, e); } + } - if (!info.isEmpty()) { - if (output == null) { - output = new StringBuilder("[" + info + "]"); - } else { - output.append(" [").append(info).append("]"); - } + if (!info.toString().isEmpty()) { + if (output == null) { + output = new StringBuilder("[" + info + "]"); + } else { + output.append(" [").append(info).append("]"); } } - } catch (Exception e) { - logger.error(LoggingAnchor.FOUR, MessageEnum.RA_ANALYZE_ERROR_EXC.toString(), "SDNC", - ErrorCode.DataError.getValue(), "Exception while analyzing errors", e); } - - return output.toString(); + return output; } } diff --git a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java index 6f76ea1eab..9dd95c6713 100644 --- a/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java +++ b/adapters/mso-sdnc-adapter/src/main/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnector.java @@ -11,9 +11,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -59,9 +59,6 @@ public class SDNCServiceRequestConnector extends SDNCConnector { TypedRequestTunables rt) { try { return parseResponseContent(responseContent); - } catch (ParseException e) { - logger.error("Error occured:", e); - return createErrorResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage(), rt); } catch (Exception e) { logger.error("Error occured:", e); return createErrorResponse(HttpURLConnection.HTTP_INTERNAL_ERROR, e.getMessage(), rt); @@ -79,10 +76,10 @@ public class SDNCServiceRequestConnector extends SDNCConnector { * response code contained in the content. For 2XX response codes, an SDNCServiceResponse is returned. Otherwise, an * SDNCServiceError is returned. If the content cannot be parsed, or if the content does not contain all required * elements, a parse exception is thrown. This method performs no logging or alarming. - * + * * @throws ParseException on error */ - public static SDNCResponseCommon parseResponseContent(String responseContent) + public SDNCResponseCommon parseResponseContent(String responseContent) throws ParseException, ParserConfigurationException, SAXException, IOException { // Note: this document builder is not namespace-aware, so namespaces are ignored. @@ -119,16 +116,24 @@ public class SDNCServiceRequestConnector extends SDNCConnector { List<Element> responseParameters = new ArrayList<>(); for (Element child : SDNCAdapterUtils.childElements(configurationResponseCommon)) { - if ("response-code".equals(child.getNodeName())) { - responseCode = child.getTextContent(); - } else if ("response-message".equals(child.getNodeName())) { - responseMessage = child.getTextContent(); - } else if ("svc-request-id".equals(child.getNodeName())) { - svcRequestId = child.getTextContent(); - } else if ("ack-final-indicator".equals(child.getNodeName())) { - ackFinalIndicator = child.getTextContent(); - } else if ("response-parameters".equals(child.getNodeName())) { - responseParameters.add(child); + + switch (child.getNodeName()) { + case "response-code": + responseCode = child.getTextContent(); + break; + case "response-message": + responseMessage = child.getTextContent(); + break; + case "svc-request-id": + svcRequestId = child.getTextContent(); + break; + case "ack-final-indicator": + ackFinalIndicator = child.getTextContent(); + break; + case "response-parameters": + responseParameters.add(child); + break; + default: } } @@ -167,8 +172,15 @@ public class SDNCServiceRequestConnector extends SDNCConnector { return new SDNCServiceError(svcRequestId, responseCode, responseMessage, ackFinalIndicator); } - // Create a success response object. + return createSDNCServiceResponse(responseCode, responseMessage, svcRequestId, ackFinalIndicator, + responseParameters); + + } + + private SDNCServiceResponse createSDNCServiceResponse(String responseCode, String responseMessage, + String svcRequestId, String ackFinalIndicator, List<Element> responseParameters) throws ParseException { + // Create a success response object. SDNCServiceResponse response = new SDNCServiceResponse(svcRequestId, responseCode, responseMessage, ackFinalIndicator); @@ -201,8 +213,6 @@ public class SDNCServiceRequestConnector extends SDNCConnector { response.addParam(tagName, tagValue); } - return response; - } } diff --git a/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnectorTest.java b/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnectorTest.java index 9911cae677..9adc6c52f5 100644 --- a/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnectorTest.java +++ b/adapters/mso-sdnc-adapter/src/test/java/org/onap/so/adapters/sdnc/sdncrest/SDNCServiceRequestConnectorTest.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -31,7 +31,8 @@ public class SDNCServiceRequestConnectorTest { public void parseResponseContentTest() throws Exception { String content = FileUtil.readResourceFile("SdncServiceResponse.xml"); - SDNCResponseCommon responseCommon = SDNCServiceRequestConnector.parseResponseContent(content); + SDNCServiceRequestConnector sdncServiceRequestConnector = new SDNCServiceRequestConnector(); + SDNCResponseCommon responseCommon = sdncServiceRequestConnector.parseResponseContent(content); assertNotNull(responseCommon); } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java index 6840dd388b..860dfbbe9c 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderConfiguration.java @@ -20,16 +20,41 @@ package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.CertificateException; +import java.util.concurrent.TimeUnit; +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.config.Registry; +import org.apache.http.config.RegistryBuilder; +import org.apache.http.conn.socket.ConnectionSocketFactory; +import org.apache.http.conn.socket.PlainConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.ssl.SSLContextBuilder; +import org.onap.logging.filter.spring.SpringClientPayloadFilter; import org.onap.so.adapters.vnfmadapter.extclients.AbstractServiceProviderConfiguration; import org.onap.so.configuration.rest.BasicHttpHeadersProvider; -import org.onap.so.configuration.rest.HttpHeadersProvider; +import org.onap.so.configuration.rest.HttpClientConnectionConfiguration; +import org.onap.so.logging.jaxrs.filter.SOSpringClientFilter; import org.onap.so.rest.service.HttpRestServiceProvider; import org.onap.so.rest.service.HttpRestServiceProviderImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.io.Resource; +import org.springframework.http.client.BufferingClientHttpRequestFactory; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.web.client.RestTemplate; /** @@ -41,16 +66,105 @@ import org.springframework.web.client.RestTemplate; @Configuration public class EtsiCatalogServiceProviderConfiguration extends AbstractServiceProviderConfiguration { - @Bean(name = "etsiCatalogServiceProvider") - public HttpRestServiceProvider httpRestServiceProvider( - @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate) { - return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider()); + public static final String ETSI_CATALOG_REST_TEMPLATE_BEAN = "etsiCatalogRestTemplate"; + + public static final String ETSI_CATALOG_SERVICE_PROVIDER_BEAN = "etsiCatalogServiceProvider"; + + private final static Logger LOGGER = LoggerFactory.getLogger(EtsiCatalogServiceProviderConfiguration.class); + + private final HttpClientConnectionConfiguration clientConnectionConfiguration; + + @Value("${etsi-catalog-manager.http.client.ssl.trust-store:#{null}}") + private Resource trustStore; + @Value("${etsi-catalog-manager.http.client.ssl.trust-store-password:#{null}}") + private String trustStorePassword; + + @Autowired + public EtsiCatalogServiceProviderConfiguration( + final HttpClientConnectionConfiguration clientConnectionConfiguration) { + this.clientConnectionConfiguration = clientConnectionConfiguration; + } + + @Bean + @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) + public RestTemplate etsiCatalogRestTemplate() { + final RestTemplate restTemplate = new RestTemplate(); + restTemplate.getInterceptors().add(new SOSpringClientFilter()); + restTemplate.getInterceptors().add((new SpringClientPayloadFilter())); + return restTemplate; } - private HttpRestServiceProvider getHttpRestServiceProvider(final RestTemplate restTemplate, - final HttpHeadersProvider httpHeadersProvider) { + @Bean + @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) + public HttpRestServiceProvider etsiCatalogHttpRestServiceProvider( + @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) final RestTemplate restTemplate) { setGsonMessageConverter(restTemplate); - return new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider); + + final HttpClientBuilder httpClientBuilder = getHttpClientBuilder(); + if (trustStore != null) { + try { + LOGGER.debug("Setting up HttpComponentsClientHttpRequestFactory with SSL Context"); + LOGGER.debug("Setting client trust-store: {}", trustStore.getURL()); + LOGGER.debug("Creating SSLConnectionSocketFactory with AllowAllHostsVerifier ... "); + final SSLContext sslContext = new SSLContextBuilder() + .loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()).build(); + final SSLConnectionSocketFactory sslConnectionSocketFactory = + new SSLConnectionSocketFactory(sslContext, AllowAllHostsVerifier.INSTANCE); + httpClientBuilder.setSSLSocketFactory(sslConnectionSocketFactory); + final Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder + .<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.INSTANCE) + .register("https", sslConnectionSocketFactory).build(); + + httpClientBuilder.setConnectionManager(getConnectionManager(socketFactoryRegistry)); + } catch (final KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException + | IOException exception) { + LOGGER.error("Error reading truststore, TLS connection will fail.", exception); + } + + } else { + LOGGER.debug("Setting connection manager without SSL ConnectionSocketFactory ..."); + httpClientBuilder.setConnectionManager(getConnectionManager()); + } + + final HttpComponentsClientHttpRequestFactory factory = + new HttpComponentsClientHttpRequestFactory(httpClientBuilder.build()); + restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory)); + + return new HttpRestServiceProviderImpl(restTemplate, new BasicHttpHeadersProvider().getHttpHeaders()); + } + + private PoolingHttpClientConnectionManager getConnectionManager( + final Registry<ConnectionSocketFactory> socketFactoryRegistry) { + return new PoolingHttpClientConnectionManager(socketFactoryRegistry, null, null, null, + clientConnectionConfiguration.getTimeToLiveInMins(), TimeUnit.MINUTES); + } + + private PoolingHttpClientConnectionManager getConnectionManager() { + return new PoolingHttpClientConnectionManager(clientConnectionConfiguration.getTimeToLiveInMins(), + TimeUnit.MINUTES); + } + + private HttpClientBuilder getHttpClientBuilder() { + return HttpClientBuilder.create().setMaxConnPerRoute(clientConnectionConfiguration.getMaxConnectionsPerRoute()) + .setMaxConnTotal(clientConnectionConfiguration.getMaxConnections()) + .setDefaultRequestConfig(getRequestConfig()); + } + + private RequestConfig getRequestConfig() { + return RequestConfig.custom().setSocketTimeout(clientConnectionConfiguration.getSocketTimeOutInMiliSeconds()) + .setConnectTimeout(clientConnectionConfiguration.getConnectionTimeOutInMilliSeconds()).build(); + } + + private static final class AllowAllHostsVerifier implements HostnameVerifier { + + private static final AllowAllHostsVerifier INSTANCE = new AllowAllHostsVerifier(); + + @Override + public boolean verify(final String hostname, final SSLSession session) { + LOGGER.debug("Skipping hostname verification ..."); + return true; + } + } } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java index 30d084629c..cae413ce10 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/etsicatalog/EtsiCatalogServiceProviderImpl.java @@ -20,6 +20,7 @@ package org.onap.so.adapters.vnfmadapter.extclients.etsicatalog; +import static org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_SERVICE_PROVIDER_BEAN; import java.util.Optional; import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.NsdmSubscription; import org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.model.PkgmSubscription; @@ -53,14 +54,14 @@ import org.springframework.stereotype.Service; public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvider { private static final Logger logger = LoggerFactory.getLogger(EtsiCatalogServiceProviderImpl.class); - @Qualifier("etsiCatalogServiceProvider") private final HttpRestServiceProvider httpServiceProvider; private final EtsiCatalogUrlProvider etsiCatalogUrlProvider; private final ConversionService conversionService; @Autowired public EtsiCatalogServiceProviderImpl(final EtsiCatalogUrlProvider etsiCatalogUrlProvider, - final HttpRestServiceProvider httpServiceProvider, final ConversionService conversionService) { + @Qualifier(ETSI_CATALOG_SERVICE_PROVIDER_BEAN) final HttpRestServiceProvider httpServiceProvider, + final ConversionService conversionService) { this.etsiCatalogUrlProvider = etsiCatalogUrlProvider; this.httpServiceProvider = httpServiceProvider; this.conversionService = conversionService; @@ -118,8 +119,10 @@ public class EtsiCatalogServiceProviderImpl implements EtsiCatalogServiceProvide if (inlineResponse2001 != null) { responses[index] = inlineResponse2001; } + } else { + logger.error("Unable to find Converter for response class: {}", + vnfPackages[index].getClass()); } - logger.error("Unable to find Converter for response class: {}", vnfPackages[index].getClass()); } return Optional.of(responses); } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java new file mode 100644 index 0000000000..9ed17e4379 --- /dev/null +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/extclients/vnfm/VnfmHttpServiceProviderConfiguration.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Ericsson. 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.adapters.vnfmadapter.extclients.vnfm; + +import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import org.onap.so.adapters.vnfmadapter.extclients.AbstractServiceProviderConfiguration; +import org.onap.so.configuration.rest.BasicHttpHeadersProvider; +import org.onap.so.rest.service.HttpRestServiceProvider; +import org.onap.so.rest.service.HttpRestServiceProviderImpl; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.client.RestTemplate; + +/** + * @author Waqas Ikram (waqas.ikram@est.tech) + * + */ +@Configuration +public class VnfmHttpServiceProviderConfiguration extends AbstractServiceProviderConfiguration { + public static final String VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN = "vnfmAdapterHttpServiceProvider"; + + @Bean + @Qualifier(VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN) + public HttpRestServiceProvider vnfmAdapterHttpRestServiceProvider( + @Autowired @Qualifier(CONFIGURABLE_REST_TEMPLATE) RestTemplate restTemplate) { + setGsonMessageConverter(restTemplate); + return new HttpRestServiceProviderImpl(restTemplate, new BasicHttpHeadersProvider().getHttpHeaders()); + } + +} diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/AbstractNotificationServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/AbstractNotificationServiceProvider.java index 86ca59cffe..d6b7ae7201 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/AbstractNotificationServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/AbstractNotificationServiceProvider.java @@ -19,16 +19,13 @@ */ package org.onap.so.adapters.vnfmadapter.packagemanagement.subscriptionmanagement; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import static org.onap.so.adapters.vnfmadapter.extclients.vnfm.VnfmHttpServiceProviderConfiguration.VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN; import java.nio.charset.StandardCharsets; import org.apache.commons.codec.binary.Base64; import org.onap.so.configuration.rest.BasicHttpHeadersProvider; -import org.onap.so.configuration.rest.HttpHeadersProvider; import org.onap.so.rest.service.HttpRestServiceProvider; -import org.onap.so.rest.service.HttpRestServiceProviderImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.web.client.RestTemplate; /** * A base class that can be extended by classes for providing notification services. Provides common methods that will @@ -40,12 +37,10 @@ import org.springframework.web.client.RestTemplate; public abstract class AbstractNotificationServiceProvider { @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) - private RestTemplate restTemplate; + @Qualifier(VNFM_ADAPTER_HTTP_SERVICE_PROVIDER_BEAN) + private HttpRestServiceProvider httpRestServiceProvider; - protected HttpRestServiceProvider getHttpRestServiceProvider(final HttpHeadersProvider httpHeadersProvider) { - final HttpRestServiceProvider httpRestServiceProvider = - new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider); + protected HttpRestServiceProvider getHttpRestServiceProvider() { return httpRestServiceProvider; } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/BasicAuthNotificationServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/BasicAuthNotificationServiceProvider.java index 6f9d94e9de..cf0cdb085a 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/BasicAuthNotificationServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/BasicAuthNotificationServiceProvider.java @@ -47,10 +47,10 @@ public class BasicAuthNotificationServiceProvider extends AbstractNotificationSe final HttpHeadersProvider httpHeadersProvider = getBasicHttpHeadersProviderWithBasicAuth(subscriptionsAuthentication.getParamsBasic().getUserName(), subscriptionsAuthentication.getParamsBasic().getPassword()); - final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(httpHeadersProvider); + final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(); - final ResponseEntity<Void> responseEntity = - httpRestServiceProvider.postHttpRequest(notification, callbackUri, Void.class); + final ResponseEntity<Void> responseEntity = httpRestServiceProvider.postHttpRequest(notification, callbackUri, + httpHeadersProvider.getHttpHeaders(), Void.class); if (responseEntity.getStatusCode().is2xxSuccessful()) { logger.info("Notification sent successfully."); return true; diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java index 496fb083cf..c065203cd8 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/main/java/org/onap/so/adapters/vnfmadapter/packagemanagement/subscriptionmanagement/OAuthNotificationServiceProvider.java @@ -48,13 +48,14 @@ public class OAuthNotificationServiceProvider extends AbstractNotificationServic final String token = getAccessToken(subscriptionsAuthentication); if (token == null) { + logger.error("Failed to get access token"); return false; } final HttpHeadersProvider httpHeadersProvider = getHttpHeadersProvider(token); - final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(httpHeadersProvider); - final ResponseEntity<Void> responseEntity = - httpRestServiceProvider.postHttpRequest(notification, callbackUri, Void.class); + final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(); + final ResponseEntity<Void> responseEntity = httpRestServiceProvider.postHttpRequest(notification, callbackUri, + httpHeadersProvider.getHttpHeaders(), Void.class); if (responseEntity.getStatusCode().is2xxSuccessful()) { logger.info("Notification sent successfully."); return true; @@ -83,9 +84,9 @@ public class OAuthNotificationServiceProvider extends AbstractNotificationServic subscriptionsAuthentication.getParamsOauth2ClientCredentials().getClientId(), subscriptionsAuthentication.getParamsOauth2ClientCredentials().getClientPassword()); - final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(httpHeadersProvider); - final ResponseEntity<OAuthTokenResponse> responseEntity = - httpRestServiceProvider.postHttpRequest(null, tokenEndpoint, OAuthTokenResponse.class); + final HttpRestServiceProvider httpRestServiceProvider = getHttpRestServiceProvider(); + final ResponseEntity<OAuthTokenResponse> responseEntity = httpRestServiceProvider.postHttpRequest(null, + tokenEndpoint, httpHeadersProvider.getHttpHeaders(), OAuthTokenResponse.class); if (responseEntity.getStatusCode().is2xxSuccessful()) { if (responseEntity.getBody() != null) { logger.info("Returning Access Token."); diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java index 322251e753..29afa8c549 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/EtsiSubscriptionNotificationControllerTest.java @@ -278,7 +278,7 @@ public class EtsiSubscriptionNotificationControllerTest { mockRestServer.expect(requestTo(CALLBACK_URI)).andExpect(method(HttpMethod.POST)) .andExpect(jsonPath("$.id").value(NOTIFICATION_ID)) .andExpect(jsonPath("$.notificationType").value( - VnfPackageChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION.toString())) + VnfPackageChangeNotification.NotificationTypeEnum.VNFPACKAGECHANGENOTIFICATION.getValue())) .andExpect(jsonPath("$.subscriptionId").value(SUBSCRIPTION_ID)) .andExpect(jsonPath("$.timeStamp").value(TIMESTAMP.toString())) .andExpect(jsonPath("$.vnfPkgId").value(VNFPKG_ID.toString())) diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java index c5194cf27e..31e612a812 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementControllerTest.java @@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import static org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_REST_TEMPLATE_BEAN; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; @@ -74,11 +74,11 @@ public class Sol003PackageManagementControllerTest { private int port; @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) - private RestTemplate testRestTemplate; + @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) + private RestTemplate restTemplate; @Autowired - private TestRestTemplate restTemplate; + private TestRestTemplate testRestTemplate; private static final String VNF_PACKAGE_ID = "myVnfPackageId"; private static final String ARTIFACT_PATH = "myArtifactPath"; @@ -104,8 +104,7 @@ public class Sol003PackageManagementControllerTest { @Before public void setUp() { - final MockRestServiceServer.MockRestServiceServerBuilder builder = - MockRestServiceServer.bindTo(testRestTemplate); + final MockRestServiceServer.MockRestServiceServerBuilder builder = MockRestServiceServer.bindTo(restTemplate); builder.ignoreExpectOrder(true); mockRestServer = builder.build(); basicHttpHeadersProvider = new BasicHttpHeadersProvider(); @@ -123,7 +122,7 @@ public class Sol003PackageManagementControllerTest { + VNF_PACKAGE_ID + "/package_content"; final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); final ResponseEntity<byte[]> responseEntity = - restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class); + testRestTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class); assertEquals(byte[].class, responseEntity.getBody().getClass()); assertArrayEquals(responseEntity.getBody(), responseArray); @@ -164,7 +163,7 @@ public class Sol003PackageManagementControllerTest { final ResponseEntity<ProblemDetails> responseEntity = - restTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class); + testRestTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class); assertTrue(responseEntity.getBody() instanceof ProblemDetails); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); @@ -226,7 +225,7 @@ public class Sol003PackageManagementControllerTest { + VNF_PACKAGE_ID + "/artifacts/" + ARTIFACT_PATH; final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); final ResponseEntity<byte[]> responseEntity = - restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class); + testRestTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class); assertEquals(byte[].class, responseEntity.getBody().getClass()); assertArrayEquals(responseEntity.getBody(), responseArray); @@ -267,7 +266,7 @@ public class Sol003PackageManagementControllerTest { final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); final ResponseEntity<ProblemDetails> responseEntity = - restTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class); + testRestTemplate.exchange(testURL, HttpMethod.GET, request, ProblemDetails.class); assertNotNull(responseEntity.getBody()); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, responseEntity.getStatusCode()); @@ -331,7 +330,7 @@ public class Sol003PackageManagementControllerTest { final String testURL = localhostUrl + port + VNFPKGM_BASE_URL; final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); - final ResponseEntity<InlineResponse2001[]> responseEntity = restTemplate.withBasicAuth("test", "test") + final ResponseEntity<InlineResponse2001[]> responseEntity = testRestTemplate.withBasicAuth("test", "test") .exchange(testURL, HttpMethod.GET, request, InlineResponse2001[].class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); @@ -412,7 +411,7 @@ public class Sol003PackageManagementControllerTest { final String testURL = localhostUrl + port + VNFPKGM_BASE_URL + "/" + VNF_PACKAGE_ID; final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); - final ResponseEntity<InlineResponse2001> responseEntity = restTemplate.withBasicAuth("test", "test") + final ResponseEntity<InlineResponse2001> responseEntity = testRestTemplate.withBasicAuth("test", "test") .exchange(testURL, HttpMethod.GET, request, InlineResponse2001.class); assertEquals(HttpStatus.OK, responseEntity.getStatusCode()); @@ -484,7 +483,8 @@ public class Sol003PackageManagementControllerTest { + VNF_PACKAGE_ID + "\" \n" + "endpoint.", problemDetails.getDetail()); } - // The below test method is here to improve code coverage and provide a foundation for writing future tests + // The below test method is here to improve code coverage and provide a foundation for writing + // future tests @Test public void testGetPackageVnfd_ValidArray_Success() { final byte[] responseArray = buildByteArrayWithRandomData(10); @@ -497,7 +497,7 @@ public class Sol003PackageManagementControllerTest { "http://localhost:" + port + PACKAGE_MANAGEMENT_BASE_URL + "/vnf_packages/" + VNF_PACKAGE_ID + "/vnfd"; final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); final ResponseEntity<byte[]> responseEntity = - restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class); + testRestTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, byte[].class); assertEquals(byte[].class, responseEntity.getBody().getClass()); assertArrayEquals(responseEntity.getBody(), responseArray); @@ -592,7 +592,7 @@ public class Sol003PackageManagementControllerTest { private ResponseEntity<ProblemDetails> sendHttpRequest(final String url) { final String testURL = localhostUrl + port + VNFPKGM_BASE_URL + "/" + url; final HttpEntity<?> request = new HttpEntity<>(basicHttpHeadersProvider.getHttpHeaders()); - return restTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, + return testRestTemplate.withBasicAuth("test", "test").exchange(testURL, HttpMethod.GET, request, ProblemDetails.class); } @@ -652,4 +652,5 @@ public class Sol003PackageManagementControllerTest { final VNFPKGMLinkSerializer vnfpkgmLinkSerializer = new VNFPKGMLinkSerializer().self(uriLink); return vnfpkgmLinkSerializer; } + } diff --git a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java index a2828b1f9f..c269af8e68 100644 --- a/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java +++ b/adapters/mso-vnfm-adapter/mso-vnfm-etsi-adapter/src/test/java/org/onap/so/adapters/vnfmadapter/rest/Sol003PackageManagementSubscriptionControllerTest.java @@ -28,7 +28,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.onap.so.adapters.vnfmadapter.Constants.PACKAGE_MANAGEMENT_BASE_URL; -import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import static org.onap.so.adapters.vnfmadapter.extclients.etsicatalog.EtsiCatalogServiceProviderConfiguration.ETSI_CATALOG_REST_TEMPLATE_BEAN; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; @@ -102,7 +102,7 @@ public class Sol003PackageManagementSubscriptionControllerTest { private static final String LOCALHOST_URL = "http://localhost:"; @Autowired - @Qualifier(CONFIGURABLE_REST_TEMPLATE) + @Qualifier(ETSI_CATALOG_REST_TEMPLATE_BEAN) private RestTemplate restTemplate; private MockRestServiceServer mockRestServiceServer; @Autowired diff --git a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java index 423c1a7ed6..4bc3f884f8 100644 --- a/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java +++ b/asdc-controller/src/main/java/org/onap/so/asdc/installer/heat/ToscaResourceInstaller.java @@ -216,9 +216,6 @@ public class ToscaResourceInstaller { protected PnfCustomizationRepository pnfCustomizationRepository; @Autowired - protected ServiceInfoRepository serviceInfoRepository; - - @Autowired protected WorkflowResource workflowResource; @Autowired @@ -393,7 +390,7 @@ public class ToscaResourceInstaller { createToscaCsar(toscaResourceStruct); createService(toscaResourceStruct, vfResourceStruct); Service service = toscaResourceStruct.getCatalogService(); - ServiceInfo serviceInfo = createServiceInfo(toscaResourceStruct, service); + createServiceInfo(toscaResourceStruct, service); List<IEntityDetails> vfEntityList = getEntityDetails(toscaResourceStruct, EntityQuery.newBuilder(SdcTypes.VF), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false); @@ -423,9 +420,8 @@ public class ToscaResourceInstaller { processServiceProxyAndConfiguration(toscaResourceStruct, service); logger.info("Saving Service: {} ", service.getModelName()); - ServiceInfo serviceResult = serviceInfoRepository.save(serviceInfo); - Service resultService = serviceResult.getService(); - correlateConfigCustomResources(resultService); + service = serviceRepo.save(service); + correlateConfigCustomResources(service); workflowResource.processWorkflows(vfResourceStructure); @@ -2902,9 +2898,9 @@ public class ToscaResourceInstaller { createToscaCsar(toscaResourceStruct); createService(toscaResourceStruct, vfResourceStruct); Service service = toscaResourceStruct.getCatalogService(); - ServiceInfo serviceInfo = createServiceInfo(toscaResourceStruct, service); + createServiceInfo(toscaResourceStruct, service); createServiceArtifact(service, vfResourceStruct, artifactContent); - serviceInfoRepository.save(serviceInfo); + serviceRepo.save(service); } private void createServiceArtifact(Service service, VfResourceStructure vfResourceStruct, String artifactContent) { @@ -2927,16 +2923,19 @@ public class ToscaResourceInstaller { service.setServiceArtifactList(serviceArtifactList); } - private ServiceInfo createServiceInfo(ToscaResourceStructure toscaResourceStruct, Service service) { + private void createServiceInfo(ToscaResourceStructure toscaResourceStruct, Service service) { + List<ServiceInfo> serviceInfos = new ArrayList<>(); + ServiceInfo serviceInfo = new ServiceInfo(); String serviceInput = getServiceInput(toscaResourceStruct); serviceInfo.setServiceInput(serviceInput); String serviceProperties = getServiceProperties(toscaResourceStruct); serviceInfo.setServiceProperties(serviceProperties); - serviceInfo.setService(service); - return serviceInfo; + serviceInfos.add(serviceInfo); + + service.setServiceInfos(serviceInfos); } private String getServiceProperties(ToscaResourceStructure toscaResourceStruct) { diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java index b8a2d01b49..e4882119ab 100644 --- a/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java +++ b/asdc-controller/src/test/java/org/onap/so/asdc/installer/heat/ToscaResourceInstallerTest.java @@ -343,7 +343,6 @@ public class ToscaResourceInstallerTest extends BaseTest { doReturn(resourceCustomizationUUID).when(metadata).getValue("vfModuleModelCustomizationUUID"); ServiceRepository serviceRepo = spy(ServiceRepository.class); - ServiceInfoRepository serviceInfoRepo = spy(ServiceInfoRepository.class); VnfResourceRepository vnfRepo = spy(VnfResourceRepository.class); doReturn(null).when(vnfRepo).findResourceByModelUUID(uuid); @@ -354,7 +353,6 @@ public class ToscaResourceInstallerTest extends BaseTest { WorkflowResource workflowResource = spy(WorkflowResource.class); ReflectionTestUtils.setField(toscaInstaller, "serviceRepo", serviceRepo); - ReflectionTestUtils.setField(toscaInstaller, "serviceInfoRepository", serviceInfoRepo); ReflectionTestUtils.setField(toscaInstaller, "vnfRepo", vnfRepo); ReflectionTestUtils.setField(toscaInstaller, "vfModuleRepo", vfModuleRepo); ReflectionTestUtils.setField(toscaInstaller, "instanceGroupRepo", instanceGroupRepo); @@ -425,10 +423,7 @@ public class ToscaResourceInstallerTest extends BaseTest { assertNotNull(service); service.setModelVersion("1.0"); - ServiceInfo serviceInfo = new ServiceInfo(); - serviceInfo.setService(service); doReturn(service).when(serviceRepo).save(service); - doReturn(serviceInfo).when(serviceInfoRepo).save(any(ServiceInfo.class)); WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository = spy(WatchdogComponentDistributionStatusRepository.class); diff --git a/asdc-controller/src/test/resources/schema.sql b/asdc-controller/src/test/resources/schema.sql index d051d1a56c..7ed1e99385 100644 --- a/asdc-controller/src/test/resources/schema.sql +++ b/asdc-controller/src/test/resources/schema.sql @@ -1382,7 +1382,9 @@ CREATE TABLE IF NOT EXISTS `service_info` ( `ID` int (11) AUTO_INCREMENT, `SERVICE_INPUT` varchar (5000), `SERVICE_PROPERTIES` varchar (5000), - PRIMARY KEY (`ID`) + `SERVICE_MODEL_UUID` varchar (200) NOT NULL, + PRIMARY KEY (`ID`), + CONSTRAINT `fk_service_info_service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE IF NOT EXISTS `service_artifact`( @@ -1399,14 +1401,6 @@ CREATE TABLE IF NOT EXISTS `service_artifact`( CONSTRAINT `fk_service_artifact_service_info1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE )ENGINE=InnoDB DEFAULT CHARSET=latin1; -CREATE TABLE IF NOT EXISTS `service_to_service_info` ( - `SERVICE_MODEL_UUID` varchar (200) NOT NULL, - `SERVICE_INFO_ID` INT (11) NOT NULL, - PRIMARY KEY (`SERVICE_MODEL_UUID`,`SERVICE_INFO_ID`), - CONSTRAINT `fk_service_to_service_info__service1` FOREIGN KEY (`SERVICE_MODEL_UUID`) REFERENCES `service` (`MODEL_UUID`) ON DELETE CASCADE ON UPDATE CASCADE, - CONSTRAINT `fk_service_to_service_info__service_info1` FOREIGN KEY (`SERVICE_INFO_ID`) REFERENCES `service_info` (`ID`) ON DELETE CASCADE ON UPDATE CASCADE -)ENGINE=InnoDB DEFAULT CHARSET=latin1; - --------START Request DB SCHEMA -------- CREATE DATABASE requestdb; USE requestdb; diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java index 3632d187c9..70c78472ba 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceDecomposition.java @@ -23,10 +23,6 @@ package org.onap.so.bpmn.core.domain; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRootName; @@ -35,6 +31,10 @@ import org.onap.so.bpmn.core.json.DecomposeJsonUtil; import org.onap.so.bpmn.core.json.JsonDecomposingException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; @@ -71,6 +71,10 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { private List<AllottedResource> allottedResources; @JsonProperty("configResource") private List<ConfigResource> configResources; + @JsonProperty("serviceInfo") + private ServiceInfo serviceInfo; + @JsonProperty("serviceProxy") + private List<ServiceProxy> serviceProxy; public ServiceDecomposition() { super(); @@ -85,6 +89,8 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { this.serviceRole = serviceDecomposition.getServiceRole(); this.serviceType = serviceDecomposition.getServiceType(); this.configResources = serviceDecomposition.getConfigResources(); + this.serviceProxy = serviceDecomposition.getServiceProxy(); + this.serviceInfo = serviceDecomposition.getServiceInfo(); } /** @@ -109,11 +115,13 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { this.project = serviceDecomposition.getProject(); this.owningEntity = serviceDecomposition.getOwningEntity(); + this.serviceProxy = serviceDecomposition.getServiceProxy(); + this.serviceInfo = serviceDecomposition.getServiceInfo(); } /** * Constructor taking a Service Decomposition JSON serialization - * + * * @param catalogRestOutput * @param serviceInstanceId */ @@ -128,7 +136,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { * Return just the service model portion of the Service Decomposition as a Java object. The service model object * should support retrieval as JSON string that is formatted correctly for sending serviceModelInfo to Building * Blocks. - * + * * @return */ public ModelInfo getModelInfo() { @@ -235,6 +243,22 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { this.sdncVersion = sdncVersion; } + public ServiceInfo getServiceInfo() { + return serviceInfo; + } + + public void setServiceInfo(ServiceInfo serviceInfo) { + this.serviceInfo = serviceInfo; + } + + public List<ServiceProxy> getServiceProxy() { + return serviceProxy; + } + + public void setServiceProxy(List<ServiceProxy> serviceProxy) { + this.serviceProxy = serviceProxy; + } + // ***** // ***** @@ -243,7 +267,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * This method returns one combined list of Resources of All Types - * + * * @return */ @JsonIgnore @@ -275,7 +299,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Returns a JSON list of all Network Resource structures (i.e. the serialized NetworkDecomposition objects). - * + * * @return */ @JsonIgnore @@ -285,7 +309,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Returns a JSON list of all VnfResource structures (i.e. the serialized VnfResource objects). - * + * * @return */ @JsonIgnore @@ -295,7 +319,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Returns a JSON list of all Allotted Resource structures (i.e. the serialized AllottedResource objects). - * + * * @return */ @JsonIgnore @@ -305,7 +329,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Returns a JSON list of all Config Resource structures (i.e. the serialized ConfigResource objects). - * + * * @return */ @JsonIgnore @@ -328,7 +352,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { // Methods to add Resource to the list /** * Add VNF resource to the list - * + * * @param vnfResource */ public void addVnfResource(Resource vnfResource) { @@ -340,7 +364,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Add Network resource to the list - * + * * @param networkResource */ public void addNetworkResource(Resource networkResource) { @@ -352,7 +376,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Add Allotted resource to the list - * + * * @param allottedResource */ public void addAllottedResource(Resource allottedResource) { @@ -364,7 +388,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Add Config resource to the list - * + * * @param allottedResource */ public void addConfigResource(Resource configResource) { @@ -378,7 +402,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { * Add resource to the list Given a ResourceDecomposition (subclass) object, add it to the Service Decomposition (in * the appropriate category, e.g. as a VNF, Network, or Allotted Resource). As dependencies are not currently * supported, add it to the end of any ordered lists. - * + * * @param resource */ public void addResource(Resource resource) { @@ -403,7 +427,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Add resource to the list - * + * * @param jsonResource */ public void addVnfResource(String jsonResource) throws JsonDecomposingException { @@ -414,7 +438,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Add resource to the list - * + * * @param jsonResource */ public void addNetworkResource(String jsonResource) throws JsonDecomposingException { @@ -425,7 +449,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Add resource to the list - * + * * @param Resource */ public void addAllottedResource(String jsonResource) throws JsonDecomposingException { @@ -436,7 +460,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Add resource to the list - * + * * @param Resource */ public void addConfigResource(String jsonResource) throws JsonDecomposingException { @@ -449,7 +473,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { * Given a ResourceDecomposition (subclass) object, locate it in the Service Decomposition by its unique ID, and * replace the current version with the new one. This method should support concurrency control via an * auto-incrementing field in the ResourceDecomposition class. - * + * * @param newResource * @return TRUE if replacement was a success */ @@ -474,7 +498,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Given a ResourceDecomposition as a JSON string, locate it in the Service Decomposition by its unique ID, and * replace the current version with the new one. - * + * * @param jsonString * @return */ @@ -485,7 +509,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Given a resource object ID, locate it in the Service Decomposition by its unique ID, and delete it. - * + * * @param resource * @return TRUE if delete was a success */ @@ -503,7 +527,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Generic method to get List of Resource objects based on input resource's resourceType - * + * * @param resource * @return List matching the resourceType of resource */ @@ -530,7 +554,7 @@ public class ServiceDecomposition extends JsonWrapper implements Serializable { /** * Generic method to set List of ResourceDecomposition objects - * + * * @param resources * @return */ diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy index 8b9726c2b7..7d1bc4c779 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSDNCNetworkResource.groovy @@ -127,11 +127,7 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { String key = iterator.next() HashMap<String, String> hashMap = new HashMap() hashMap.put("name", key) - if(jsonObject.get(key)==null){ - hashMap.put("value", "") - }else{ - hashMap.put("value", jsonObject.get(key)) - } + hashMap.put("value", jsonObject.get(key)) paramList.add(hashMap) } Map<String, List<Map<String, Object>>> paramMap = new HashMap() @@ -260,6 +256,17 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { break + case ~/[\w\s\W]*UNI[\w\s\W]*/ : + def resourceInput = resourceInputObj.getResourceParameters() + String incomingRequest = resourceInputObj.getRequestsInputs() + String serviceParameters = JsonUtils.getJsonValue(incomingRequest, "service.parameters") + String requestInputs = JsonUtils.getJsonValue(serviceParameters, "requestInputs") + JSONObject inputParameters = new JSONObject(requestInputs) + String uResourceInput = jsonUtil.addJsonValue(resourceInput, "requestInputs.service-name", inputParameters.get("name")) + resourceInputObj.setResourceParameters(uResourceInput) + execution.setVariable(Prefix + "resourceInput", resourceInputObj.toString()) + break + case ~/[\w\s\W]*sdwanvpnattachment[\w\s\W]*/ : case ~/[\w\s\W]*sotnvpnattachment[\w\s\W]*/ : case ~/[\w\s\W]*SOTN-Attachment[\w\s\W]*/ : @@ -363,7 +370,7 @@ public class CreateSDNCNetworkResource extends AbstractServiceTaskProcessor { <sdncadapter:MsoAction>opticalservice</sdncadapter:MsoAction> </sdncadapter:RequestHeader> <sdncadapterworkflow:SDNCRequestData> - <request-id>${msoUtils.xmlEscape(hdrRequestId)}</request-id> + <request-id>${msoUtils.xmlEscape(serviceInstanceId)}</request-id> <global-customer-id>${msoUtils.xmlEscape(globalCustomerId)}</global-customer-id> <service-type>${msoUtils.xmlEscape(serviceType)}</service-type> <notification-url>sdncCallback</notification-url> diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy index 61b1250522..cdc242dbd8 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DeleteSDNCNetworkResource.groovy @@ -221,6 +221,30 @@ public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor { switch (modelType) { case "VNF": + if(modelName.contains("UNI") && "MDONS_OTN".equals(serviceType)){ + String serviceInstanceName = resourceInputObj.getResourceInstanceName() + sdncTopologyDeleteRequest = """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1" + xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1" + xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"> + <sdncadapter:RequestHeader> + <sdncadapter:RequestId>${MsoUtils.xmlEscape(hdrRequestId)}</sdncadapter:RequestId> + <sdncadapter:SvcInstanceId>${MsoUtils.xmlEscape(serviceInstanceId)}</sdncadapter:SvcInstanceId> + <sdncadapter:SvcAction>${MsoUtils.xmlEscape(sdnc_svcAction)}</sdncadapter:SvcAction> + <sdncadapter:SvcOperation>optical-service-delete</sdncadapter:SvcOperation> + <sdncadapter:CallbackUrl>sdncCallback</sdncadapter:CallbackUrl> + <sdncadapter:MsoAction>opticalservice</sdncadapter:MsoAction> + </sdncadapter:RequestHeader> + <sdncadapterworkflow:SDNCRequestData> + <request-id>${msoUtils.xmlEscape(serviceInstanceId)}</request-id> + <payload> + <param> + <name>service-name</name> + <value>${msoUtils.xmlEscape(serviceInstanceName)}</value> + </param> + </payload> + </sdncadapterworkflow:SDNCRequestData> + </aetgt:SDNCAdapterWorkflowRequest>""".trim() + } else{ sdncTopologyDeleteRequest = """<aetgt:SDNCAdapterWorkflowRequest xmlns:aetgt="http://org.onap/so/workflow/schema/v1" xmlns:sdncadapter="http://org.onap.so/workflow/sdnc/adapter/schema/v1" xmlns:sdncadapterworkflow="http://org.onap/so/workflow/schema/v1"> @@ -275,6 +299,7 @@ public class DeleteSDNCNetworkResource extends AbstractServiceTaskProcessor { </vnf-request-input> </sdncadapterworkflow:SDNCRequestData> </aetgt:SDNCAdapterWorkflowRequest>""".trim() + } break case "GROUP" : //When a new resource creation request reaches SO, the parent resources information needs to be provided diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy index a24bc4411e..35af3d34d6 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoDeleteE2EServiceInstance.groovy @@ -450,6 +450,16 @@ public class DoDeleteE2EServiceInstance extends AbstractServiceTaskProcessor { execution.setVariable("serviceModelInfo", serviceDecomposition.getModelInfo()) List<Resource> deleteResourceList = serviceDecomposition.getServiceResources() + if (serviceDecomposition.getServiceType().equals("MDONS_OTN")){ + for (Resource resource : deleteResourceList) { + String serviceName = execution.getVariable("serviceInstanceName") + String serviceInstanceId = execution.getVariable("serviceInstanceId") + resource.setResourceId(serviceInstanceId) + resource.setResourceInstanceName(serviceName) + def delMap = new ImmutablePair(resource, null) + deleteRealResourceList.add(delMap) + } + } else{ String serviceRelationShip = execution.getVariable("serviceRelationShip") def jsonSlurper = new JsonSlurper() def jsonOutput = new JsonOutput() @@ -492,6 +502,7 @@ public class DoDeleteE2EServiceInstance extends AbstractServiceTaskProcessor { } } } + } // only delete real existing resources execution.setVariable("deleteResourceList", deleteRealResourceList) diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteE2EServiceInstance.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteE2EServiceInstance.bpmn index 1149cc9ea9..85fe3b4b29 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteE2EServiceInstance.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoDeleteE2EServiceInstance.bpmn @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.1.0"> +<bpmn:definitions xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:camunda="http://camunda.org/schema/1.0/bpmn" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="Definitions_1" targetNamespace="http://bpmn.io/schema/bpmn" exporter="Camunda Modeler" exporterVersion="3.4.1"> <bpmn:process id="DoDeleteE2EServiceInstance" name="All Resources Deleted" isExecutable="true"> <bpmn:startEvent id="StartEvent_0212h2r" name="Start Flow"> <bpmn:outgoing>SequenceFlow_0vz7cd9</bpmn:outgoing> @@ -131,6 +131,7 @@ dcsi.postDecomposeService(execution)</bpmn:script> <camunda:in source="operationType" target="operationType" /> <camunda:in source="operationId" target="operationId" /> <camunda:in source="serviceDecomposition" target="serviceDecomposition" /> + <camunda:in source="serviceInstanceName" target="serviceInstanceName" /> </bpmn:extensionElements> <bpmn:incoming>SequenceFlow_1j08ko3</bpmn:incoming> <bpmn:outgoing>SequenceFlow_1cevtpy</bpmn:outgoing> diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java index 7e5cf19b21..b6ab9d0ce6 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/aai/tasks/AAIUpdateTasks.java @@ -188,6 +188,15 @@ public class AAIUpdateTasks { } /** + * BPMN access method to update status of VfModule to Active in AAI + */ + public void updateOrchestrationStatusActivateVfModule(BuildingBlockExecution execution) { + execution.setVariable("aaiActivateVfModuleRollback", false); + updateOrchestrationStatusForVfModule(execution, OrchestrationStatus.ACTIVE); + execution.setVariable("aaiActivateVfModuleRollback", true); + } + + /** * BPMN access method to update aaiDeactivateVfModuleRollback to true for deactivating the VfModule */ public void updateOrchestrationStatusDeactivateVfModule(BuildingBlockExecution execution) { @@ -205,9 +214,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of L3Network to Assigned in AAI - * - * @param execution - * @throws BBObjectNotFoundException */ public void updateOrchestrationStatusAssignedNetwork(BuildingBlockExecution execution) { updateNetwork(execution, OrchestrationStatus.ASSIGNED); @@ -215,9 +221,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of L3Network to Active in AAI - * - * @param execution - * @throws BBObjectNotFoundException */ public void updateOrchestrationStatusActiveNetwork(BuildingBlockExecution execution) { updateNetwork(execution, OrchestrationStatus.ACTIVE); @@ -225,9 +228,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of L3Network to Created in AAI - * - * @param execution - * @throws BBObjectNotFoundException */ public void updateOrchestrationStatusCreatedNetwork(BuildingBlockExecution execution) { updateNetwork(execution, OrchestrationStatus.CREATED); @@ -262,9 +262,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of L3Network Collection to Active in AAI - * - * @param execution - * @throws BBObjectNotFoundException */ public void updateOrchestrationStatusActiveNetworkCollection(BuildingBlockExecution execution) { execution.setVariable("aaiNetworkCollectionActivateRollback", false); @@ -285,27 +282,7 @@ public class AAIUpdateTasks { } /** - * BPMN access method to update status of VfModule to Active in AAI - * - * @param execution - */ - public void updateOrchestrationStatusActivateVfModule(BuildingBlockExecution execution) { - execution.setVariable("aaiActivateVfModuleRollback", false); - try { - VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, OrchestrationStatus.ACTIVE); - execution.setVariable("aaiActivateVfModuleRollback", true); - } catch (Exception ex) { - logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusActivateVfModule", ex); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } - } - - /** * BPMN access method to update HeatStackId of VfModule in AAI - * - * @param execution */ public void updateHeatStackIdVfModule(BuildingBlockExecution execution) { try { @@ -325,9 +302,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update L3Network after it was created in cloud - * - * @param execution - * @throws Exception */ public void updateNetworkCreated(BuildingBlockExecution execution) throws Exception { execution.setVariable("aaiNetworkActivateRollback", false); @@ -369,9 +343,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update L3Network after it was updated in cloud - * - * @param execution - * @throws Exception */ public void updateNetworkUpdated(BuildingBlockExecution execution) throws Exception { L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID); @@ -399,8 +370,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update L3Network Object - * - * @param execution */ public void updateObjectNetwork(BuildingBlockExecution execution) { try { @@ -414,8 +383,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update ServiceInstance - * - * @param execution */ public void updateServiceInstance(BuildingBlockExecution execution) { try { @@ -430,8 +397,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update Vnf Object - * - * @param execution */ public void updateObjectVnf(BuildingBlockExecution execution) { try { @@ -445,8 +410,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of VfModuleRollback as true - * - * @param execution */ public void updateOrchestrationStatusDeleteVfModule(BuildingBlockExecution execution) { execution.setVariable("aaiDeleteVfModuleRollback", false); @@ -454,9 +417,6 @@ public class AAIUpdateTasks { VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); vfModule.setHeatStackId(""); GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - - VfModule copiedVfModule = vfModule.shallowCopyId(); - copiedVfModule.setHeatStackId(""); aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, OrchestrationStatus.ASSIGNED); execution.setVariable("aaiDeleteVfModuleRollback", true); } catch (Exception ex) { @@ -467,8 +427,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update Model of VfModule - * - * @param execution */ public void updateModelVfModule(BuildingBlockExecution execution) { try { @@ -483,8 +441,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of FabricConfiguration to Assigned in AAI - * - * @param execution */ public void updateOrchestrationStatusAssignFabricConfiguration(BuildingBlockExecution execution) { try { @@ -499,8 +455,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of FabricConfiguration to Active in AAI - * - * @param execution */ public void updateOrchestrationStatusActivateFabricConfiguration(BuildingBlockExecution execution) { try { @@ -515,8 +469,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of FabricConfiguration to deactive in AAI - * - * @param execution */ public void updateOrchestrationStatusDeactivateFabricConfiguration(BuildingBlockExecution execution) { try { @@ -532,8 +484,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update Ipv4OamAddress of Vnf - * - * @param execution */ public void updateIpv4OamAddressVnf(BuildingBlockExecution execution) { try { @@ -555,8 +505,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update ManagementV6Address of Vnf - * - * @param execution */ public void updateManagementV6AddressVnf(BuildingBlockExecution execution) { try { @@ -578,8 +526,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update ContrailServiceInstanceFqdn of VfModule - * - * @param execution */ public void updateContrailServiceInstanceFqdnVfModule(BuildingBlockExecution execution) { try { @@ -598,8 +544,6 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of Vnf to ConfigAssigned in AAI - * - * @param execution */ public void updateOrchestrationStatusConfigAssignedVnf(BuildingBlockExecution execution) { try { @@ -613,79 +557,16 @@ public class AAIUpdateTasks { /** * BPMN access method to update status of Vnf to Configure in AAI - * - * @param execution */ public void updateOrchestrationStatusConfigDeployConfigureVnf(BuildingBlockExecution execution) { - try { - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - aaiVnfResources.updateOrchestrationStatusVnf(vnf, OrchestrationStatus.CONFIGURE); - - } catch (Exception ex) { - logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusConfigDeployConfigureVnf", ex); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } + updateOrchestrationStatusForVnf(execution, OrchestrationStatus.CONFIGURE); } /** * BPMN access method to update status of Vnf to configured in AAI - * - * @param execution */ public void updateOrchestrationStatusConfigDeployConfiguredVnf(BuildingBlockExecution execution) { - try { - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - aaiVnfResources.updateOrchestrationStatusVnf(vnf, OrchestrationStatus.CONFIGURED); - } catch (Exception ex) { - logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusConfigDeployConfiguredVnf", ex); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } - } - - /** - * BPMN access method to update status of VNF/VF-Module based on SO scope and action. - * - * @param execution - BuildingBlockExecution - * @param scope - SO scope (vnf/vfModule) - * @param action - action (configAssign/configDeploy/configUndeploy etc..) - */ - public void updateOrchestrationStatusForCds(BuildingBlockExecution execution, String scope, String action) { - try { - GenericVnf vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID); - OrchestrationStatus status = getOrchestrationStatus(action); - switch (scope) { - case "vnf": - aaiVnfResources.updateOrchestrationStatusVnf(vnf, status); - break; - case "vfModule": - VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID); - aaiVfModuleResources.updateOrchestrationStatusVfModule(vfModule, vnf, status); - break; - default: - throw new IllegalArgumentException( - "Invalid scope to update orchestration status for CDS : " + action); - } - } catch (Exception ex) { - logger.error("Exception occurred in AAIUpdateTasks updateOrchestrationStatusForCds", ex); - exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); - } - } - - private OrchestrationStatus getOrchestrationStatus(String action) { - /** - * At this state, OrcherstationStatus enum associated with configAssign and configDeploy. I am not sure which is - * the correct approach. 1. Are we going to map each specific action to OrchestrationStauts ? 2. We will have - * only one generic status for all actions ? - */ - - switch (action) { - case "configAssign": - return OrchestrationStatus.ASSIGNED; - case "configDeploy": - return OrchestrationStatus.CONFIGURED; - default: - throw new IllegalArgumentException("Invalid action to set Orchestration status: " + action); - } + updateOrchestrationStatusForVnf(execution, OrchestrationStatus.CONFIGURED); } private void updateOrchestrationStatusForService(BuildingBlockExecution execution, OrchestrationStatus status) { @@ -751,5 +632,4 @@ public class AAIUpdateTasks { exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex); } } - } diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java index f8a4d910f4..eead1761ea 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/workflow/tasks/WorkflowAction.java @@ -169,12 +169,7 @@ public class WorkflowAction { } public void selectExecutionList(DelegateExecution execution) throws Exception { - final String requestAction = (String) execution.getVariable(BBConstants.G_ACTION); - final String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID); - final String bpmnRequest = (String) execution.getVariable(BBConstants.G_BPMN_REQUEST); - final boolean aLaCarte = (boolean) execution.getVariable(BBConstants.G_ALACARTE); final String apiVersion = (String) execution.getVariable(BBConstants.G_APIVERSION); - String uri = (String) execution.getVariable(BBConstants.G_URI); final String vnfType = (String) execution.getVariable(VNF_TYPE); String serviceInstanceId = (String) execution.getVariable("serviceInstanceId"); final String createInstanceAction = "createInstance"; @@ -183,40 +178,34 @@ public class WorkflowAction { List<OrchestrationFlow> orchFlows = (List<OrchestrationFlow>) execution.getVariable(BBConstants.G_ORCHESTRATION_FLOW); - List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>(); WorkflowResourceIds workflowResourceIds = populateResourceIdsFromApiHandler(execution); List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>(); List<Resource> resourceList = new ArrayList<>(); execution.setVariable("sentSyncResponse", false); execution.setVariable("homing", false); execution.setVariable("calledHoming", false); + execution.setVariable(BBConstants.G_ISTOPLEVELFLOW, true); try { - ObjectMapper mapper = new ObjectMapper(); - execution.setVariable(BBConstants.G_ISTOPLEVELFLOW, true); - ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class); + final String bpmnRequest = (String) execution.getVariable(BBConstants.G_BPMN_REQUEST); + ServiceInstancesRequest sIRequest = + new ObjectMapper().readValue(bpmnRequest, ServiceInstancesRequest.class); RequestDetails requestDetails = sIRequest.getRequestDetails(); - boolean suppressRollback = false; - try { - suppressRollback = requestDetails.getRequestInfo().getSuppressRollback(); - } catch (Exception ex) { - logger.warn("Exception in getSuppressRollback", ex); - suppressRollback = false; - } - execution.setVariable("suppressRollback", suppressRollback); - boolean isResume = false; - if (isUriResume(uri)) { - isResume = true; - if (!aLaCarte) { - logger.debug("replacing URI {}", uri); - uri = bbInputSetupUtils.loadOriginalInfraActiveRequestById(requestId).getRequestUrl(); - logger.debug("for RESUME with original value {}", uri); - } + execution.setVariable("suppressRollback", requestDetails.getRequestInfo().getSuppressRollback()); + String uri = (String) execution.getVariable(BBConstants.G_URI); + final String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID); + final boolean aLaCarte = (boolean) execution.getVariable(BBConstants.G_ALACARTE); + boolean isResume = isUriResume(uri); + if (!aLaCarte && isResume) { + logger.debug("replacing URI {}", uri); + uri = bbInputSetupUtils.loadOriginalInfraActiveRequestById(requestId).getRequestUrl(); + logger.debug("for RESUME with original value {}", uri); } Resource resource = extractResourceIdAndTypeFromUri(uri); WorkflowType resourceType = resource.getResourceType(); execution.setVariable("resourceName", resourceType.toString()); String resourceId = ""; + final String requestAction = (String) execution.getVariable(BBConstants.G_ACTION); if (resource.isGenerated() && requestAction.equalsIgnoreCase(createInstanceAction) && sIRequest.getRequestDetails().getRequestInfo().getInstanceName() != null) { resourceId = validateResourceIdInAAI(resource.getResourceId(), resourceType, @@ -230,7 +219,7 @@ public class WorkflowAction { } execution.setVariable("resourceId", resourceId); execution.setVariable("resourceType", resourceType); - + List<ExecuteBuildingBlock> flowsToExecute = new ArrayList<>(); if (isRequestMacroServiceResume(aLaCarte, resourceType, requestAction, serviceInstanceId)) { flowsToExecute = bbInputSetupUtils.loadOriginalFlowExecutionPath(requestId); if (flowsToExecute == null) { diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/Service.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/Service.java index 0d7a6dbd1f..3f3742f699 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/Service.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/Service.java @@ -139,6 +139,9 @@ public class Service implements Serializable { @OneToMany(cascade = CascadeType.ALL, mappedBy = "service") private List<ServiceArtifact> serviceArtifactList; + @OneToMany(cascade = CascadeType.ALL, mappedBy = "service") + private List<ServiceInfo> serviceInfos; + @Column(name = "NAMING_POLICY") private String namingPolicy; @@ -385,6 +388,17 @@ public class Service implements Serializable { this.serviceArtifactList = serviceArtifactList; } + public List<ServiceInfo> getServiceInfos() { + if (serviceInfos == null) { + serviceInfos = new ArrayList<>(); + } + return serviceInfos; + } + + public void setServiceInfos(List<ServiceInfo> serviceInfos) { + this.serviceInfos = serviceInfos; + } + public String getWorkloadContext() { return this.workloadContext; } diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/ServiceInfo.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/ServiceInfo.java index f9c95767f6..d11a112c80 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/ServiceInfo.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/beans/ServiceInfo.java @@ -45,9 +45,8 @@ public class ServiceInfo implements Serializable { @Column(name = "SERVICE_PROPERTIES") private String serviceProperties; - @OneToOne(cascade = CascadeType.ALL) - @JoinTable(name = "service_to_service_info", joinColumns = @JoinColumn(name = "SERVICE_INFO_ID"), - inverseJoinColumns = @JoinColumn(name = "SERVICE_MODEL_UUID")) + @ManyToOne(cascade = CascadeType.ALL) + @JoinColumn(name = "SERVICE_MODEL_UUID") private Service service; public Integer getId() { diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceInfoRepository.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceInfoRepository.java deleted file mode 100644 index e3a4ca264e..0000000000 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/data/repository/ServiceInfoRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (c) 2019, CMCC Technologies Co., Ltd. - * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT 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.catalog.data.repository; - -import org.onap.so.db.catalog.beans.Service; -import org.onap.so.db.catalog.beans.ServiceInfo; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.rest.core.annotation.RepositoryRestResource; - -@RepositoryRestResource(collectionResourceRel = "serviceInfo", path = "serviceInfo") -public interface ServiceInfoRepository extends JpaRepository<ServiceInfo, Integer> { - - ServiceInfo findByService(Service service); - -} diff --git a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/rest/beans/ServiceMacroHolder.java b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/rest/beans/ServiceMacroHolder.java index ec4e922c8f..65cbb5253e 100644 --- a/mso-catalog-db/src/main/java/org/onap/so/db/catalog/rest/beans/ServiceMacroHolder.java +++ b/mso-catalog-db/src/main/java/org/onap/so/db/catalog/rest/beans/ServiceMacroHolder.java @@ -39,7 +39,6 @@ public class ServiceMacroHolder implements Serializable { private ArrayList<AllottedResourceCustomization> allottedResourceCustomizations; private ArrayList<VnfResourceCustomization> vnfResourceCustomizations; private ArrayList<ServiceProxyResourceCustomization> serviceProxyResourceCustomizations; - private ServiceInfo serviceInfo; public ServiceMacroHolder() { @@ -50,7 +49,6 @@ public class ServiceMacroHolder implements Serializable { this.allottedResourceCustomizations = new ArrayList<>(); this.vnfResourceCustomizations = new ArrayList<>(); this.serviceProxyResourceCustomizations = new ArrayList<>(); - this.serviceInfo = null; } public ServiceMacroHolder(Service service) { @@ -66,14 +64,6 @@ public class ServiceMacroHolder implements Serializable { this.service = service; } - public ServiceInfo getServiceInfo() { - return serviceInfo; - } - - public void setServiceInfo(ServiceInfo serviceInfo) { - this.serviceInfo = serviceInfo; - } - public void setVnfResources(ArrayList<VnfResource> vnfResources) { this.vnfResources = vnfResources; } @@ -165,11 +155,6 @@ public class ServiceMacroHolder implements Serializable { } else { sb.append("service: null"); } - if (this.serviceInfo != null) { - sb.append("serviceInfo: " + this.serviceInfo.toString()); - } else { - sb.append("serviceInfo: null"); - } if (this.vnfResourceCustomizations != null && this.vnfResourceCustomizations.size() > 0) { int i = 0; sb.append("VnfResources: "); diff --git a/packages/docker/pom.xml b/packages/docker/pom.xml index b231dedf91..3a9ec375da 100644 --- a/packages/docker/pom.xml +++ b/packages/docker/pom.xml @@ -42,20 +42,20 @@ </goals> <configuration> <source> - println 'Project version: ' + project.properties['so.project.version']; - def versionArray; - if ( project.properties['so.project.version'] != null ) { - versionArray = project.properties['so.project.version'].split('-'); - } + println 'Project version: ' + project.properties['so.project.version']; + def versionArray; + if ( project.properties['so.project.version'] != null ) { + versionArray = project.properties['so.project.version'].split('-'); + } - if ( project.properties['so.project.version'].endsWith("-SNAPSHOT") ) { - project.properties['project.docker.latesttag.version']=versionArray[0] + "-SNAPSHOT-latest"; - } else { - project.properties['project.docker.latesttag.version']=versionArray[0] + "-STAGING-latest"; - } + if ( project.properties['so.project.version'].endsWith("-SNAPSHOT") ) { + project.properties['project.docker.latesttag.version']=versionArray[0] + "-SNAPSHOT-latest"; + } else { + project.properties['project.docker.latesttag.version']=versionArray[0] + "-STAGING-latest"; + } - println 'New tag for docker: ' + project.properties['project.docker.latesttag.version']; - </source> + println 'New tag for docker: ' + project.properties['project.docker.latesttag.version']; + </source> </configuration> </execution> </executions> |