From eb6d3d34320cb233ab68ee1e7621a3030b7f63bd Mon Sep 17 00:00:00 2001 From: Priyadharshini Date: Thu, 27 Aug 2020 04:05:09 -0700 Subject: Implement so-oof-adapter to handle OOF Callback - Add NSI/NST selection callback for Networkslicing Issue-ID: SO-3205 Signed-off-by: Priyadharshini Change-Id: Ica88d503495949ecce8b897c3a990fbdaa5d4f0e --- adapters/mso-oof-adapter/.gitignore | 33 ++ adapters/mso-oof-adapter/pom.xml | 120 ++++++ .../so/adapters/oof/MsoOofAdapterApplication.java | 32 ++ .../so/adapters/oof/OofAdapterClientConfig.java | 76 ++++ .../onap/so/adapters/oof/WebSecurityConfig.java | 37 ++ .../onap/so/adapters/oof/constants/Constants.java | 31 ++ .../oof/exceptions/OofAdapterException.java | 39 ++ .../org/onap/so/adapters/oof/model/OofRequest.java | 52 +++ .../so/adapters/oof/rest/OofCallbackHandler.java | 71 ++++ .../org/onap/so/adapters/oof/rest/OofClient.java | 67 +++ .../org/onap/so/adapters/oof/utils/OofUtils.java | 110 +++++ .../adapters/oof/rest/OofCallbackHandlerTest.java | 85 ++++ .../onap/so/adapters/oof/rest/OofClientTest.java | 86 ++++ .../onap/so/adapters/oof/utils/OofUtilsTest.java | 76 ++++ .../testInputs/NsiSelectionOofRequest.json | 84 ++++ .../resources/testInputs/NsiSelectionResponse.json | 20 + adapters/pom.xml | 1 + .../bpmn/common/scripts/DoHandleOofRequest.groovy | 103 +++++ .../onap/so/bpmn/common/scripts/OofUtils.groovy | 36 +- .../oof/adapter/beans/payload/OofRequest.java | 49 +++ .../scripts/CreateSliceService.groovy | 76 ++-- .../scripts/DoCreateSliceServiceOption.groovy | 70 +--- .../main/resources/process/CreateSliceService.bpmn | 454 +++++++++++---------- .../subprocess/DoCreateSliceServiceOption.bpmn | 220 +++++----- .../resources/subprocess/DoHandleOofRequest.bpmn | 122 ++++++ packages/docker/pom.xml | 31 +- 26 files changed, 1752 insertions(+), 429 deletions(-) create mode 100644 adapters/mso-oof-adapter/.gitignore create mode 100644 adapters/mso-oof-adapter/pom.xml create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/constants/Constants.java create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java create mode 100644 adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java create mode 100644 adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java create mode 100644 adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java create mode 100644 adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java create mode 100644 adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionOofRequest.json create mode 100644 adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionResponse.json create mode 100644 bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy create mode 100644 bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/oof/adapter/beans/payload/OofRequest.java create mode 100644 bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoHandleOofRequest.bpmn diff --git a/adapters/mso-oof-adapter/.gitignore b/adapters/mso-oof-adapter/.gitignore new file mode 100644 index 0000000000..549e00a2a9 --- /dev/null +++ b/adapters/mso-oof-adapter/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/adapters/mso-oof-adapter/pom.xml b/adapters/mso-oof-adapter/pom.xml new file mode 100644 index 0000000000..98150d39e0 --- /dev/null +++ b/adapters/mso-oof-adapter/pom.xml @@ -0,0 +1,120 @@ + + + 4.0.0 + + org.onap.so + adapters + 1.7.1-SNAPSHOT + + org.onap.so.adapters + mso-oof-adapter + mso-oof-adapter + mso oof adapter + + + + + org.springframework.boot + spring-boot-dependencies + ${springboot.version} + pom + import + + + + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-webflux + + + + org.apache.cxf + cxf-spring-boot-starter-jaxrs + ${cxf.version} + + + org.apache.cxf + cxf-rt-rs-service-description-swagger + ${cxf.version} + + + org.springframework.boot + spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.junit.jupiter + junit-jupiter-api + test + + + junit + junit + test + + + org.junit.jupiter + junit-jupiter-engine + test + + + org.junit.vintage + junit-vintage-engine + test + + + + ${project.artifactId}-${project.version} + ${project.basedir}/src/test/java + + + org.springframework.boot + spring-boot-maven-plugin + + org.onap.so.adapters.oof.MsoOofAdapterApplication + + + + + repackage + + + + + + org.jacoco + jacoco-maven-plugin + + + + + src/main/resources + true + + **/*.p12 + **/*.jks + + + + src/main/resources + false + + **/*.p12 + **/*.jks + + + + + diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java new file mode 100644 index 0000000000..78fbe6e271 --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/MsoOofAdapterApplication.java @@ -0,0 +1,32 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class MsoOofAdapterApplication { + + public static void main(String[] args) { + SpringApplication.run(MsoOofAdapterApplication.class, args); + } +} diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java new file mode 100644 index 0000000000..5e13c592b7 --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/OofAdapterClientConfig.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof; + +import javax.net.ssl.HostnameVerifier; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSession; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClients; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; +import org.springframework.web.client.RestTemplate; + +@Configuration +public class OofAdapterClientConfig { + + @Bean + public RestTemplate getRestTemplate() { + HttpComponentsClientHttpRequestFactory requestFactory = + new HttpComponentsClientHttpRequestFactory(getHttpsClient()); + requestFactory.setConnectTimeout(60000); + requestFactory.setReadTimeout(60000); + return new RestTemplate(requestFactory); + } + + private HttpClient getHttpsClient() { + TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) {} + + public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) {} + }}; + + // Install the all-trusting trust manager + try { + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + HostnameVerifier hostnameVerifier = new HostnameVerifier() { + @Override + public boolean verify(String hostname, SSLSession session) { + return true; + } + }; + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sc, + new String[] {"TLSv1", "TLSv1.1", "TLSv1.2", "TLSv1.3"}, null, hostnameVerifier); + return HttpClients.custom().setSSLSocketFactory(sslsf).build(); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } +} diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java new file mode 100644 index 0000000000..9a07b0119f --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/WebSecurityConfig.java @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof; + +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; + +@EnableWebSecurity +@Configuration +public class WebSecurityConfig extends WebSecurityConfigurerAdapter { + + @Override + protected void configure(HttpSecurity http) throws Exception { + http.csrf().disable(); + } + +} diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/constants/Constants.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/constants/Constants.java new file mode 100644 index 0000000000..5d91bf38f8 --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/constants/Constants.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.adapters.oof.constants; + +public class Constants { + + public static final String OOF_ENDPOINT = "mso.oof.endpoint"; + public static final String OOF_AUTH = "mso.oof.auth"; + public static final String MSO_KEY = "mso.msoKey"; + public static final String CAMUNDA_URL = "mso.camundaURL"; + public static final String CAMUNDA_AUTH = "mso.camundaAuth"; + public static final String WORKFLOW_MESSAGE_ENPOINT = "mso.workflow.message.endpoint"; + +} diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java new file mode 100644 index 0000000000..ff16d7442c --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/exceptions/OofAdapterException.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.exceptions; + +public class OofAdapterException extends Exception { + + private static final long serialVersionUID = 1L; + + public OofAdapterException(String message) { + super(message); + } + + public OofAdapterException(Throwable e) { + super(e); + } + + public OofAdapterException(String message, Throwable e) { + super(message, e); + } + +} diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java new file mode 100644 index 0000000000..1eb694fd96 --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/model/OofRequest.java @@ -0,0 +1,52 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.adapters.oof.model; + +/** + * POJO representing generic request payload from BPMN processes + */ +public class OofRequest { + + private String apiPath; + + private Object requestDetails; + + public String getApiPath() { + return apiPath; + } + + public void setApiPath(String apiPath) { + this.apiPath = apiPath; + } + + public Object getRequestDetails() { + return requestDetails; + } + + public void setRequestDetails(Object requestDetails) { + this.requestDetails = requestDetails; + } + + @Override + public String toString() { + return "{\"apiPath:\"\"" + apiPath + "\"\", requestDetails:\"\"" + requestDetails + "}"; + } + +} diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java new file mode 100644 index 0000000000..f8da6c6d2e --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/rest/OofCallbackHandler.java @@ -0,0 +1,71 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.rest; + +import org.onap.so.adapters.oof.exceptions.OofAdapterException; +import org.onap.so.adapters.oof.utils.OofUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * A generic call back handler to receive async response from OOF + */ +@RestController +@RequestMapping("/so/adapters/oof/callback/") +public class OofCallbackHandler { + + @Autowired + OofUtils utils; + + @Autowired + RestTemplate restTemplate; + + private static final Logger logger = LoggerFactory.getLogger(OofCallbackHandler.class); + + @PostMapping("/{version:[vV][1]}/{messageEventName}/{correlator}") + public ResponseEntity processCallback(@PathVariable("messageEventName") String messageEventName, + @PathVariable("correlator") String correlator, @RequestBody String oofCallbackRequest) + throws OofAdapterException { + logger.debug("Oof Async response received for event : {} , callback request body : {} ", messageEventName, + oofCallbackRequest); + String camundaMsgUrl = utils.getCamundaMsgUrl(messageEventName, correlator); + HttpEntity request = new HttpEntity(oofCallbackRequest, utils.getCamundaHeaders()); + try { + ResponseEntity response = restTemplate.postForEntity(camundaMsgUrl, request, String.class); + logger.debug("Response from BPMN : {} ", response); + return response; + } catch (Exception e) { + logger.warn("Error injecting message event into BPMN {} {} ", e.getCause(), e.getMessage()); + throw new OofAdapterException(e); + } + + } + +} diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java new file mode 100644 index 0000000000..3a91ec495e --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/rest/OofClient.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.rest; + +import org.onap.so.adapters.oof.exceptions.OofAdapterException; +import org.onap.so.adapters.oof.model.OofRequest; +import org.onap.so.adapters.oof.utils.OofUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpEntity; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.client.RestTemplate; + +/** + * A generic client class to call OOF with request from BPMN + */ +@RestController +@RequestMapping("/so/adapters/oof/") +public class OofClient { + + @Autowired + RestTemplate restTemplate; + + @Autowired + OofUtils utils; + + private static final Logger logger = LoggerFactory.getLogger(OofClient.class); + + @PostMapping("/{version:[vV][1]}") + public ResponseEntity callOof(@RequestBody OofRequest oofRequest) throws OofAdapterException { + try { + logger.debug("Received Request from BPEL {} ", oofRequest); + String oofUrl = utils.getOofurl(oofRequest.getApiPath()); + HttpEntity request = new HttpEntity<>(oofRequest.getRequestDetails(), utils.getOofHttpHeaders()); + ResponseEntity response = restTemplate.postForEntity(oofUrl, request, String.class); + logger.debug("Response from OOF : {} ", response); + return response; + } catch (Exception e) { + logger.warn("Error while calling OOF {} {} ", e.getCause(), e.getMessage()); + throw new OofAdapterException(e); + } + } + +} diff --git a/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java new file mode 100644 index 0000000000..f45baa30fe --- /dev/null +++ b/adapters/mso-oof-adapter/src/main/java/org/onap/so/adapters/oof/utils/OofUtils.java @@ -0,0 +1,110 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.utils; + +import java.security.GeneralSecurityException; +import java.util.ArrayList; +import java.util.List; +import javax.xml.bind.DatatypeConverter; +import org.onap.so.adapters.oof.constants.Constants; +import org.onap.so.utils.CryptoUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; + +@Component +public class OofUtils { + private static Logger logger = LoggerFactory.getLogger(OofUtils.class); + + @Autowired + private Environment env; + + /** + * @param messageEventName + * @param correlator + * @return + */ + public String getCamundaMsgUrl(String messageEventName, String correlator) { + System.out.println(env); + String camundaMsgUrl = new StringBuilder(env.getRequiredProperty(Constants.WORKFLOW_MESSAGE_ENPOINT)) + .append("/").append(messageEventName).append("/").append(correlator).toString(); + return camundaMsgUrl; + } + + /** + * @return + */ + public HttpHeaders getCamundaHeaders() { + HttpHeaders headers = new HttpHeaders(); + List acceptableMediaTypes = new ArrayList<>(); + acceptableMediaTypes.add(MediaType.ALL); + headers.setAccept(acceptableMediaTypes); + headers.setContentType(MediaType.APPLICATION_JSON); + headers.add(HttpHeaders.AUTHORIZATION, addAuthorizationHeader(env.getRequiredProperty(Constants.CAMUNDA_AUTH), + env.getRequiredProperty(Constants.MSO_KEY))); + return headers; + } + + /** + * @param auth + * @param msoKey + * @return + */ + protected String addAuthorizationHeader(String auth, String msoKey) { + String basicAuth = null; + try { + String userCredentials = CryptoUtils.decrypt(auth, msoKey); + if (userCredentials != null) { + basicAuth = "Basic " + DatatypeConverter.printBase64Binary(userCredentials.getBytes()); + } + } catch (GeneralSecurityException e) { + logger.error("Security exception", e); + } + return basicAuth; + } + + /** + * @return + * @throws Exception + */ + public HttpHeaders getOofHttpHeaders() throws Exception { + HttpHeaders headers = new HttpHeaders(); + List acceptableMediaTypes = new ArrayList<>(); + acceptableMediaTypes.add(MediaType.APPLICATION_JSON); + headers.setAccept(acceptableMediaTypes); + headers.setContentType(MediaType.APPLICATION_JSON); + return headers; + } + + /** + * @param apiPath + * @return + */ + public String getOofurl(String apiPath) { + return new StringBuilder(env.getRequiredProperty(Constants.OOF_ENDPOINT)).append(apiPath).toString(); + } + + +} diff --git a/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java new file mode 100644 index 0000000000..3a2f7f5e11 --- /dev/null +++ b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofCallbackHandlerTest.java @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.rest; + +import static org.mockito.Mockito.when; +import java.io.File; +import java.io.IOException; +import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; +import org.onap.so.adapters.oof.utils.OofUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; +import com.fasterxml.jackson.databind.ObjectMapper; + + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class OofCallbackHandlerTest { + + @Autowired + TestRestTemplate restTemplate; + + @MockBean + OofUtils oofutils; + + @MockBean + RestTemplate mockrestTemplate; + + @Before + void prepareMocks() throws Exception { + ResponseEntity responseEntity = new ResponseEntity<>(HttpStatus.OK); + when(oofutils.getCamundaHeaders()).thenReturn(new HttpHeaders()); + when(oofutils.getCamundaMsgUrl(Mockito.anyString(), Mockito.anyString())).thenReturn("oofurl"); + when(mockrestTemplate.postForEntity(Mockito.anyString(), Mockito.any(), Mockito.any())) + .thenReturn(responseEntity); + } + + @Test + void processCallbackTest() throws Exception { + Object request = prepareOofResponse(); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity(request, headers); + ResponseEntity response = restTemplate.postForEntity( + "/so/adapters/oof/callback/v1/NSISelectionResponse/d88da85c-d9e8-4f73-b837-3a72a431622a", entity, + String.class); + Assertions.assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + private Object prepareOofResponse() throws IOException { + File file = new ClassPathResource("testInputs/NsiSelectionResponse.json").getFile(); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(file, Object.class); + } + +} diff --git a/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java new file mode 100644 index 0000000000..ff38a9af63 --- /dev/null +++ b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/rest/OofClientTest.java @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.rest; + +import static org.mockito.Mockito.when; +import java.io.File; +import java.io.IOException; +import org.junit.Before; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.runner.RunWith; +import org.mockito.Mockito; +import org.onap.so.adapters.oof.model.OofRequest; +import org.onap.so.adapters.oof.utils.OofUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.core.io.ClassPathResource; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; +import com.fasterxml.jackson.databind.ObjectMapper; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +class OofClientTest { + + @Autowired + TestRestTemplate restTemplate; + + @MockBean + OofUtils oofutils; + + @MockBean + RestTemplate mockrestTemplate; + + @Before + void prepareMocks() throws Exception { + ResponseEntity responseEntity = new ResponseEntity<>(HttpStatus.OK); + when(oofutils.getOofHttpHeaders()).thenReturn(new HttpHeaders()); + when(oofutils.getOofurl(Mockito.anyString())).thenReturn("oofurl"); + when(mockrestTemplate.postForEntity(Mockito.anyString(), Mockito.any(), Mockito.any())) + .thenReturn(responseEntity); + } + + @Test + void callOofTest() throws Exception { + OofRequest request = prepareOofRequest(); + System.out.println(request); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.APPLICATION_JSON); + HttpEntity entity = new HttpEntity(request, headers); + ResponseEntity response = restTemplate.postForEntity("/so/adapters/oof/v1", entity, String.class); + Assertions.assertEquals(HttpStatus.OK, response.getStatusCode()); + } + + private OofRequest prepareOofRequest() throws IOException { + File file = new ClassPathResource("testInputs/NsiSelectionOofRequest.json").getFile(); + ObjectMapper objectMapper = new ObjectMapper(); + return objectMapper.readValue(file, OofRequest.class); + } + + +} diff --git a/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java new file mode 100644 index 0000000000..e68fa10c3e --- /dev/null +++ b/adapters/mso-oof-adapter/src/test/java/org/onap/so/adapters/oof/utils/OofUtilsTest.java @@ -0,0 +1,76 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.so.adapters.oof.utils; + +import static org.mockito.Mockito.when; +import java.security.GeneralSecurityException; +import javax.xml.bind.DatatypeConverter; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.onap.so.utils.CryptoUtils; +import org.springframework.core.env.Environment; +import org.springframework.http.HttpHeaders; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +class OofUtilsTest { + + @InjectMocks + OofUtils oofUtils; + + @Mock + Environment env; + + @Test + void testGetCamundaMsgUrl() { + when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); + String camundamsgUrl = oofUtils.getCamundaMsgUrl("samplemessage", "sampleCorrelator"); + Assertions.assertNotNull(camundamsgUrl); + } + + + void testGetCamundaHeaders() throws GeneralSecurityException { + when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); + when(CryptoUtils.decrypt(Mockito.anyString(), Mockito.anyString())).thenReturn("decryptedString"); + HttpHeaders headers = oofUtils.getCamundaHeaders(); + Assertions.assertNotNull(headers); + } + + + @Test + void testGetOofHttpHeaders() throws Exception { + when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); + HttpHeaders headers = oofUtils.getOofHttpHeaders(); + Assertions.assertNotNull(headers); + } + + @Test + void testGetOofurl() { + when(env.getRequiredProperty(Mockito.anyString())).thenReturn("dummyString"); + String oofurl = oofUtils.getOofurl("/api/v1/"); + Assertions.assertNotNull(oofurl); + } + +} diff --git a/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionOofRequest.json b/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionOofRequest.json new file mode 100644 index 0000000000..569aae9f38 --- /dev/null +++ b/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionOofRequest.json @@ -0,0 +1,84 @@ +{ + "apiPath":"/api/oof/selection/nsi/v1", + "requestDetails":{ + "serviceProfile":{ + "blob":"content" + }, + "requestInfo":{ + "transactionId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "requestId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "callbackUrl":"myDomain.com/myCallback", + "callbackHeader":{ + "blob":"content" + }, + "sourceId":"d290f1ee-6c54-4b01-90e6-d701748f0851", + "timeout":5, + "numSolutions":1 + }, + "NSTInfo":{ + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa1", + "invariantUUID":"7ua85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-nst" + }, + "NSSTInfo":[ + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa2", + "invariantUUID":"2fa85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-an-nf" + }, + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa3", + "invariantUUID":"4fa85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-cn" + }, + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa4", + "invariantUUID":"5ta85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-tn-fh" + }, + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa5", + "invariantUUID":"6ya85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-tn-mh" + }, + { + "UUID":"3fa85f64-5717-4562-b3fc-2c963f66afa7", + "invariantUUID":"7ua85f64-5717-4562-b3fc-2c963f66afa6", + "name":"embb-tn-bh" + } + ], + "preferReuse":false, + "subnetCapabilities":[ + { + "domainType":"AN-NF", + "capabilityDetails":{ + "blob":"content" + } + }, + { + "domainType":"CN", + "capabilityDetails":{ + "blob":"content" + } + }, + { + "domainType":"TN-FH", + "capabilityDetails":{ + "blob":"content" + } + }, + { + "domainType":"TN-MH", + "capabilityDetails":{ + "blob":"content" + } + }, + { + "domainType":"TN-BH", + "capabilityDetails":{ + "blob":"content" + } + } + ] +} +} \ No newline at end of file diff --git a/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionResponse.json b/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionResponse.json new file mode 100644 index 0000000000..4ddca3eaf9 --- /dev/null +++ b/adapters/mso-oof-adapter/src/test/resources/testInputs/NsiSelectionResponse.json @@ -0,0 +1,20 @@ +{ + "transactionId": "s4r0f1ee-6c54-4b01-90e6-d701748f0851", + "requestId": "r500f1ee-6c54-4b01-90e6-d701748f0851", + "requestStatus": "completed", + "solutions": [ + { + "existingNSI": false, + "newNSISolution": { + "sliceProfiles": [ + { + "domainType":"CN" + } + ], + "matchLevel": { + "blob": "content" + } + } + } + ] +} diff --git a/adapters/pom.xml b/adapters/pom.xml index 3c71b3c031..49f25b8102 100644 --- a/adapters/pom.xml +++ b/adapters/pom.xml @@ -24,6 +24,7 @@ mso-openstack-adapters etsi-sol003-adapter mso-nssmf-adapter + mso-oof-adapter so-appc-orchestrator diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy new file mode 100644 index 0000000000..ebc5f4ac58 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/DoHandleOofRequest.groovy @@ -0,0 +1,103 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License") + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.bpmn.common.scripts + +import javax.ws.rs.core.Response + +import org.apache.commons.lang3.StringUtils +import org.camunda.bpm.engine.delegate.DelegateExecution +import org.onap.logging.filter.base.ONAPComponents +import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.json.JsonUtils +import org.onap.so.client.HttpClient +import org.onap.so.client.HttpClientFactory +import org.onap.so.client.oof.adapter.beans.payload.OofRequest +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import com.fasterxml.jackson.databind.ObjectMapper + + +import static org.onap.so.bpmn.common.scripts.GenericUtils.* + + +class DoHandleOofRequest extends AbstractServiceTaskProcessor { + + ExceptionUtil exceptionUtil = new ExceptionUtil() + JsonUtils jsonUtil = new JsonUtils() + private static final Logger logger = LoggerFactory.getLogger(DoHandleOofRequest.class) + + @Override + public void preProcessRequest(DelegateExecution execution) { + logger.debug("In Preprocess Oof Request Handler") + String apiPath = execution.getVariable("apiPath") + if (isBlank(apiPath)) { + String msg = "Cannot process OOF adapter call : API PATH is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + //msoRequestId is used for correlation + String requestId = execution.getVariable("correlator") + if (isBlank(requestId)) { + String msg = "Cannot process OOF adapter call : correlator is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + String messageType = execution.getVariable("messageType") + if (isBlank(messageType)) { + String msg = "Cannot process OOF adapter call : messageType is null" + exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg) + } + + String timeout = execution.getVariable("timeout") + if (isBlank(timeout)) { + timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution); + if (isBlank(timeout)) { + logger.debug("Setting OOF timeout to default : PT30M") + timeout = "PT30M" + } + } + + Object requestDetails = execution.getVariable("oofRequest") + OofRequest oofRequestPayload = new OofRequest() + oofRequestPayload.setApiPath(apiPath) + oofRequestPayload.setRequestDetails(requestDetails) + ObjectMapper objectMapper = new ObjectMapper() + String requestJson = objectMapper.writeValueAsString(oofRequestPayload) + execution.setVariable("oofRequestPayload", requestJson) + } + + public void callOofAdapter(DelegateExecution execution) { + logger.debug("Start callOofAdapter") + String requestId = execution.getVariable("msoRequestId") + String oofAdapterEndpoint = UrnPropertiesReader.getVariable("mso.adapters.oof.endpoint", execution) + String basicAuthCred = execution.getVariable("BasicAuthHeaderValue") + URL requestUrl = new URL(oofAdapterEndpoint) + String oofRequest = execution.getVariable("oofRequestPayload") + logger.debug("oofRequest : " + oofRequest) + HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.EXTERNAL) + Response httpResponse = httpClient.post(oofRequest) + int responseCode = httpResponse.getStatus() + logger.debug("OOF sync response code is: " + responseCode) + if(responseCode != 200){ + exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.") + } + } + +} diff --git a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy index 69dfacd9bc..2c96e7d3bb 100644 --- a/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy +++ b/bpmn/MSOCommonBPMN/src/main/groovy/org/onap/so/bpmn/common/scripts/OofUtils.groovy @@ -22,42 +22,28 @@ package org.onap.so.bpmn.common.scripts -import com.fasterxml.jackson.databind.ObjectMapper +import static org.onap.so.bpmn.common.scripts.GenericUtils.* + +import javax.ws.rs.core.UriBuilder + import org.camunda.bpm.engine.delegate.DelegateExecution -import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor -import org.onap.so.bpmn.common.scripts.ExceptionUtil import org.onap.so.bpmn.common.util.OofInfraUtils import org.onap.so.bpmn.core.UrnPropertiesReader +import org.onap.so.bpmn.core.domain.AllottedResource import org.onap.so.bpmn.core.domain.HomingSolution import org.onap.so.bpmn.core.domain.ModelInfo import org.onap.so.bpmn.core.domain.Resource -import org.onap.so.bpmn.core.domain.AllottedResource import org.onap.so.bpmn.core.domain.ServiceDecomposition import org.onap.so.bpmn.core.domain.ServiceInstance import org.onap.so.bpmn.core.domain.Subscriber import org.onap.so.bpmn.core.domain.VnfResource import org.onap.so.bpmn.core.json.JsonUtils -import org.onap.so.client.HttpClient -import org.onap.so.client.HttpClientFactory import org.onap.so.db.catalog.beans.CloudSite import org.onap.so.db.catalog.beans.HomingInstance -import org.onap.logging.filter.base.ONAPComponents; -import org.springframework.http.HttpEntity -import org.springframework.http.HttpHeaders -import org.springframework.http.HttpMethod -import org.springframework.http.ResponseEntity -import org.springframework.http.client.BufferingClientHttpRequestFactory -import org.springframework.http.client.HttpComponentsClientHttpRequestFactory -import org.springframework.web.client.RestTemplate -import org.springframework.web.util.UriComponentsBuilder import org.slf4j.Logger import org.slf4j.LoggerFactory -import javax.ws.rs.core.MediaType -import javax.ws.rs.core.Response -import javax.ws.rs.core.UriBuilder - -import static org.onap.so.bpmn.common.scripts.GenericUtils.* +import com.fasterxml.jackson.databind.ObjectMapper class OofUtils { private static final Logger logger = LoggerFactory.getLogger( OofUtils.class); @@ -530,10 +516,11 @@ class OofUtils { return UriBuilder.fromPath("").host(msbHost).port(msbPort).scheme("http").build().toString() } - public String buildSelectNSTRequest(String requestId, Map profileInfo) { + public String buildSelectNSTRequest(String requestId,String messageType, Map profileInfo) { def transactionId = requestId logger.debug( "transactionId is: " + transactionId) - String callbackUrl = "http://0.0.0.0:9000/callback/" + String correlator = requestId + String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator ObjectMapper objectMapper = new ObjectMapper() String json = objectMapper.writeValueAsString(profileInfo) StringBuilder response = new StringBuilder() @@ -554,11 +541,12 @@ class OofUtils { return response.toString() } - public String buildSelectNSIRequest(String requestId, String nstInfo, Map profileInfo){ + public String buildSelectNSIRequest(String requestId, String nstInfo,String messageType, Map profileInfo){ def transactionId = requestId logger.debug( "transactionId is: " + transactionId) - String callbackUrl = "http://0.0.0.0:9000/callback/" + String correlator = requestId + String callbackUrl = UrnPropertiesReader.getVariable("mso.adapters.oof.callback.endpoint") + "/" + messageType + "/" + correlator ObjectMapper objectMapper = new ObjectMapper(); String json = objectMapper.writeValueAsString(profileInfo); StringBuilder response = new StringBuilder(); diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/oof/adapter/beans/payload/OofRequest.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/oof/adapter/beans/payload/OofRequest.java new file mode 100644 index 0000000000..9d81332ed7 --- /dev/null +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/oof/adapter/beans/payload/OofRequest.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - SO + * ================================================================================ + * Copyright (C) 2020 Wipro Limited. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ +package org.onap.so.client.oof.adapter.beans.payload; + +public class OofRequest { + + private String apiPath; + + private Object requestDetails; + + public String getApiPath() { + return apiPath; + } + + public void setApiPath(String apiPath) { + this.apiPath = apiPath; + } + + public Object getRequestDetails() { + return requestDetails; + } + + public void setRequestDetails(Object requestDetails) { + this.requestDetails = requestDetails; + } + + @Override + public String toString() { + return "OofRequest [apiPath=" + apiPath + ", requestDetails=" + requestDetails + "]"; + } + +} diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy index 15a0f34482..389f0a089c 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/CreateSliceService.groovy @@ -178,60 +178,36 @@ public class CreateSliceService extends AbstractServiceTaskProcessor { logger.debug("Finish preProcessRequest") } - public void getNSTSelection(DelegateExecution execution) { - logger.debug("Start getNSTSelection") + public void prepareSelectNSTRequest(DelegateExecution execution) { + logger.debug("Start prepareSelectNSTRequest") String requestId = execution.getVariable("msoRequestId") + String messageType = "NSTSelectionResponse" Map serviceProfile = execution.getVariable("serviceProfile") - String oofUrl = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) - - def authHeader = "" - String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution) - String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution) - - String basicAuthValue = utils.encrypt(basicAuth, msokey) - if (basicAuthValue != null) { - logger.debug( "Obtained BasicAuth username and password for OOF: " + basicAuthValue) - try { - authHeader = utils.getBasicAuth(basicAuthValue, msokey) - execution.setVariable("BasicAuthHeaderValue", authHeader) - } catch (Exception ex) { - logger.debug( "Unable to encode username and password string: " + ex) - exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to " + - "encode username and password string") - } - } else { - logger.debug( "Unable to obtain BasicAuth - BasicAuth value null") - exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " + - "value null") - } - - URL requestUrl = new URL(oofUrl + "/api/oof/v1/selection/nst") - String oofRequest = oofUtils.buildSelectNSTRequest(requestId, serviceProfile) - HttpClient httpClient = new HttpClientFactory().newJsonClient(requestUrl, ONAPComponents.OOF) - httpClient.addAdditionalHeader("Authorization", authHeader) - Response httpResponse = httpClient.post(oofRequest) - - int responseCode = httpResponse.getStatus() - logger.debug("OOF sync response code is: " + responseCode) - - if(responseCode != 200){ - exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.") - } - - Map nstSolution - try { - Map resMap = httpResponse.readEntity(Map.class) - List> nstSolutions = (List>) resMap.get("solutions") - nstSolution = nstSolutions.get(0) - execution.setVariable("nstSolution", nstSolution) - } catch (Exception ex) { - logger.debug( "Failed to get NST solution suggested by OOF.") - exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Failed to get NST solution suggested by OOF.") - } - - logger.debug("Finish getNSTSelection") + execution.setVariable("nstSelectionUrl", "/api/oof/v1/selection/nst") + execution.setVariable("nstSelection_messageType",messageType) + execution.setVariable("nstSelection_correlator",requestId) + String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution); + execution.setVariable("nstSelection_timeout",timeout) + String oofRequest = oofUtils.buildSelectNSTRequest(requestId,messageType, serviceProfile) + execution.setVariable("nstSelection_oofRequest",oofRequest) + logger.debug("Finish prepareSelectNSTRequest") } + + public void processNSTSolutions(DelegateExecution execution) { + Map nstSolution + try { + logger.debug("Start processing NSTSolutions") + Map resMap = objectMapper.readValue(execution.getVariable("nstSelection_oofResponse"),Map.class) + List> nstSolutions = (List>) resMap.get("solutions") + nstSolution = nstSolutions.get(0) + execution.setVariable("nstSolution", nstSolution) + } catch (Exception ex) { + logger.debug( "Failed to get NST solution suggested by OOF.") + exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Failed to get NST solution suggested by OOF.") + } + + } public void prepareDecomposeService(DelegateExecution execution) { logger.debug("Start prepareDecomposeService") diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy index ec9596e7f3..9b78afba03 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy +++ b/bpmn/so-bpmn-infrastructure-common/src/main/groovy/org/onap/so/bpmn/infrastructure/scripts/DoCreateSliceServiceOption.groovy @@ -64,38 +64,16 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ } - void getNSIOptionfromOOF(DelegateExecution execution) { + void prepareSelectNSIRequest(DelegateExecution execution) { String urlString = UrnPropertiesReader.getVariable("mso.oof.endpoint", execution) logger.debug( "get NSI option OOF Url: " + urlString) boolean isNSISuggested = true execution.setVariable("isNSISuggested",isNSISuggested) - - //Prepare auth for OOF - Begin - def authHeader = "" - String basicAuth = UrnPropertiesReader.getVariable("mso.oof.auth", execution) - String msokey = UrnPropertiesReader.getVariable("mso.msoKey", execution) - - String basicAuthValue = utils.encrypt(basicAuth, msokey) - if (basicAuthValue != null) { - logger.debug( "Obtained BasicAuth username and password for OOF: " + basicAuthValue) - try { - authHeader = utils.getBasicAuth(basicAuthValue, msokey) - execution.setVariable("BasicAuthHeaderValue", authHeader) - } catch (Exception ex) { - logger.debug( "Unable to encode username and password string: " + ex) - exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - Unable to " + - "encode username and password string") - } - } else { - logger.debug( "Unable to obtain BasicAuth - BasicAuth value null") - exceptionUtil.buildAndThrowWorkflowException(execution, 401, "Internal Error - BasicAuth " + - "value null") - } - //Prepare auth for OOF - End - String requestId = execution.getVariable("msoRequestId") + String messageType = "NSISelectionResponse" + Map profileInfo = execution.getVariable("serviceProfile") Map nstSolution = execution.getVariable("nstSolution") logger.debug("Get NST selection from OOF: " + nstSolution.toString()) @@ -104,36 +82,21 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ "modelVersionId":"${nstSolution.UUID}", "modelName":"${nstSolution.NSTName}" }""" - - String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo, profileInfo) - logger.debug("Sending request to OOF: " + oofRequest) - - //send request to get NSI option - Begin - URL url = new URL(urlString+"/api/oof/selection/nsi/v1") - HttpClient httpClient = new HttpClientFactory().newJsonClient(url, ONAPComponents.OOF) - httpClient.addAdditionalHeader("Authorization", authHeader) - Response httpResponse = httpClient.post(oofRequest) - - processOOFResponse(httpResponse, execution) - - //解析sliceProfile - logger.debug("start parseServiceProfile") - parseServiceProfile(execution) - logger.debug("end parseServiceProfile") + + execution.setVariable("nsiSelectionUrl", "/api/oof/selection/nsi/v1") + execution.setVariable("nsiSelection_messageType",messageType) + execution.setVariable("nsiSelection_correlator",requestId) + String timeout = UrnPropertiesReader.getVariable("mso.adapters.oof.timeout", execution); + execution.setVariable("nsiSelection_timeout",timeout) + String oofRequest = oofUtils.buildSelectNSIRequest(requestId, nstInfo,messageType, profileInfo) + execution.setVariable("nsiSelection_oofRequest",oofRequest) + logger.debug("Sending request to OOF: " + oofRequest) } - private void processOOFResponse(Response httpResponse, DelegateExecution execution) { + void processOOFResponse(Response httpResponse, DelegateExecution execution) { int responseCode = httpResponse.getStatus() - logger.debug("OOF sync response code is: " + responseCode) - - if (responseCode != 200) { - exceptionUtil.buildAndThrowWorkflowException(execution, responseCode, "Received a Bad Sync Response from OOF.") - logger.debug("Info: No NSI suggested by OOF") - } - SliceTaskParams sliceTaskParams = execution.getVariable("sliceTaskParams") - if (httpResponse.hasEntity()) { - String OOFResponse = httpResponse.readEntity(String.class) + String OOFResponse = execution.getVariable("nsiSelection_oofResponse") logger.debug("NSI OOFResponse is: " + OOFResponse) execution.setVariable("OOFResponse", OOFResponse) //This needs to be changed to derive a value when we add policy to decide the solution options. @@ -154,8 +117,11 @@ class DoCreateSliceServiceOption extends AbstractServiceTaskProcessor{ } execution.setVariable("sliceTaskParams", sliceTaskParams) logger.debug("sliceTaskParams: "+sliceTaskParams.convertToJson()) - } logger.debug("*** Completed options Call to OOF ***") + //解析sliceProfile + logger.debug("start parseServiceProfile") + parseServiceProfile(execution) + logger.debug("end parseServiceProfile") } private boolean hasSharedNSIsolutions( Map solutions){ diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateSliceService.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateSliceService.bpmn index f27794a389..27bd01bda9 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateSliceService.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/process/CreateSliceService.bpmn @@ -1,5 +1,5 @@ - + SequenceFlow_03s744c @@ -34,12 +34,12 @@ css.processUserOptions(execution) def css = new CreateSliceService() css.processDecomposition(execution) - + SequenceFlow_046irye - SequenceFlow_1o23s0i + Flow_1l8mfej import org.onap.so.bpmn.infrastructure.scripts.* def css = new CreateSliceService() -css.getNSTSelection(execution) +css.prepareSelectNSTRequest(execution) @@ -176,7 +176,7 @@ css.prepareUpdateServiceOperationStatus(execution) SequenceFlow_1t19ips - SequenceFlow_1o23s0i + Flow_1u4srgq SequenceFlow_0q7yc2c import org.onap.so.bpmn.infrastructure.scripts.* def dcsi= new CreateSliceService() @@ -446,7 +446,6 @@ css.sendSyncResponse(execution) - SequenceFlow_0n4xku8 @@ -457,12 +456,205 @@ def css = new CreateSliceService() css.updateAAIOrchStatus(execution) + + + + + + + + + + + + Flow_1l8mfej + Flow_0vq2rmw + + + + Flow_0vq2rmw + Flow_1u4srgq + import org.onap.so.bpmn.infrastructure.scripts.* +def css = new CreateSliceService() +css.processNSTSolutions(execution) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -475,9 +667,6 @@ css.updateAAIOrchStatus(execution) - - - @@ -487,12 +676,6 @@ css.updateAAIOrchStatus(execution) - - - - - - @@ -514,9 +697,53 @@ css.updateAAIOrchStatus(execution) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -526,9 +753,6 @@ css.updateAAIOrchStatus(execution) - - - @@ -544,15 +768,6 @@ css.updateAAIOrchStatus(execution) - - - - - - - - - @@ -613,197 +828,18 @@ css.updateAAIOrchStatus(execution) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCreateSliceServiceOption.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCreateSliceServiceOption.bpmn index ad0732df4d..3ed1999d9a 100644 --- a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCreateSliceServiceOption.bpmn +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoCreateSliceServiceOption.bpmn @@ -1,17 +1,17 @@ - + SequenceFlow_1qo2pln - + SequenceFlow_0khtova - SequenceFlow_1utpplq + Flow_15c2jcx import org.onap.so.bpmn.infrastructure.scripts.* def dcso = new DoCreateSliceServiceOption() -dcso.getNSIOptionfromOOF(execution) +dcso.prepareSelectNSIRequest(execution) SequenceFlow_1qo2pln @@ -73,7 +73,6 @@ dcso.prepareNSSTDecompose(execution) SequenceFlow_0a5f5y6 - SequenceFlow_0d774n5 SequenceFlow_0wy6oag @@ -84,7 +83,7 @@ dcso.prepareNSSTDecompose(execution) #{(execution.getVariable("isNSISuggested" ) == true)} - SequenceFlow_1utpplq + Flow_07ustqm SequenceFlow_0piifl1 import org.onap.so.bpmn.infrastructure.scripts.* def dcso = new DoCreateSliceServiceOption() @@ -112,124 +111,159 @@ dcso.prepareNSTDecompose(execution) def dcso = new DoCreateSliceServiceOption() dcso.processDecomposition(execution) + + + + + + + + + + + Flow_15c2jcx + Flow_1mcx2ja + + + Flow_1mcx2ja + Flow_07ustqm + import org.onap.so.bpmn.infrastructure.scripts.* +def dcso = new DoCreateSliceServiceOption() +dcso.processOOFResponse(execution) + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - + + - - - - - - + + + + + + + + + + + - - - - - - - + - + - + - + - - - - - - - - - - - - - - - - - - - - + - - - - - + - - - - - - - - - - - + - - - - - - - - - - - - - - - - - + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file + diff --git a/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoHandleOofRequest.bpmn b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoHandleOofRequest.bpmn new file mode 100644 index 0000000000..7ca1a62312 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-flows/src/main/resources/subprocess/DoHandleOofRequest.bpmn @@ -0,0 +1,122 @@ + + + + + Flow_1jorico + + + + Flow_1fbzzqg + Flow_013jfci + import org.onap.so.bpmn.common.scripts.* +def oofHandler = new DoHandleOofRequest() +oofHandler .callOofAdapter(execution) + + + + + Flow_1jorico + Flow_1fbzzqg + import org.onap.so.bpmn.common.scripts.* +def oofHandler = new DoHandleOofRequest() +oofHandler .preProcessRequest(execution) + + + + + Flow_072knve + + + + Flow_0ykpxpc + + + Flow_072knve + Flow_0ykpxpc + import org.onap.so.bpmn.common.scripts.* +ExceptionUtil ex = new ExceptionUtil() +ex.processJavaException(execution) + + + + + + + + + + + + + + Flow_013jfci + Flow_1nmoiqi + + + + Flow_1nmoiqi + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/packages/docker/pom.xml b/packages/docker/pom.xml index a4a1e378d5..20b61e638a 100644 --- a/packages/docker/pom.xml +++ b/packages/docker/pom.xml @@ -270,6 +270,30 @@ + + ${docker.image.prefix}/so-oof-adapter + + try + docker-files/Dockerfile.so-app + + ${project.version} + ${project.version}-${maven.build.timestamp} + ${project.docker.latesttag.version} + + + + + + + org.onap.so.adapters:mso-oof-adapter + + app.jar + + + + + + ${docker.image.prefix}/so-appc-orchestrator @@ -469,7 +493,7 @@ push - ${docker.image.prefix}/catalog-db-adapter,${docker.image.prefix}/request-db-adapter,${docker.image.prefix}/sdnc-adapter,${docker.image.prefix}/openstack-adapter,${docker.image.prefix}/vfc-adapter,${docker.image.prefix}/sdc-controller,${docker.image.prefix}/bpmn-infra,${docker.image.prefix}/api-handler-infra,${docker.image.prefix}/so-monitoring,${docker.image.prefix}/so-simulator,${docker.image.prefix}/mso-nssmf-adapter,${docker.image.prefix}/mso-cnf-adapter,${docker.image.prefix}/so-etsi-nfvo-ns-lcm + ${docker.image.prefix}/catalog-db-adapter,${docker.image.prefix}/request-db-adapter,${docker.image.prefix}/sdnc-adapter,${docker.image.prefix}/openstack-adapter,${docker.image.prefix}/vfc-adapter,${docker.image.prefix}/sdc-controller,${docker.image.prefix}/bpmn-infra,${docker.image.prefix}/api-handler-infra,${docker.image.prefix}/so-monitoring,${docker.image.prefix}/so-simulator,${docker.image.prefix}/mso-nssmf-adapter,${docker.image.prefix}/so-oof-adapter,${docker.image.prefix}/mso-cnf-adapter,${docker.image.prefix}/so-etsi-nfvo-ns-lcm @@ -527,6 +551,11 @@ mso-nssmf-adapter ${project.version} + + org.onap.so.adapters + mso-oof-adapter + ${project.version} + org.onap.so.adapters so-appc-orchestrator -- cgit 1.2.3-korg