diff options
Diffstat (limited to 'bpmn')
13 files changed, 243 insertions, 41 deletions
diff --git a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java index 9828d11186..c05557a317 100644 --- a/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java +++ b/bpmn/MSOCommonBPMN/src/main/java/org/onap/so/client/appc/ApplicationControllerAction.java @@ -78,8 +78,24 @@ public class ApplicationControllerAction { appCStatus = healthCheckAction(msoRequestId, vnfId, vnfName, vnfHostIpAddress, controllerType); break; case Snapshot: + if (vmIdList.isEmpty()) { + logger.warn("vmIdList is Empty in AppCClient"); + break; + } String vmIds = JsonUtils.getJsonValue(vmIdList, "vmIds"); + if (vmIds == null) { + logger.warn("vmIds null in AppCClient"); + break; + } + if (vserverIdList.isEmpty()) { + logger.warn("vserverIdList is empty in AppCClient"); + break; + } String vserverIds = JsonUtils.getJsonValue(vserverIdList, "vserverIds"); + if (vserverIds == null) { + logger.warn("vserverIds null in AppCClient"); + break; + } String vmId = ""; String vserverId = ""; ObjectMapper mapper = new ObjectMapper(); diff --git a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java index 32db3a7bf6..48c6995715 100644 --- a/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java +++ b/bpmn/MSOCommonBPMN/src/test/java/org/onap/so/client/appc/ApplicationControllerActionTest.java @@ -481,4 +481,100 @@ public class ApplicationControllerActionTest extends BaseTest { assertEquals(expectedErrorCode, appCAction.getErrorCode()); } + @Test + public void runAppCCommand_Snapshot_vmIdList_Empty_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat("", "identityUrl"); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vmId_null_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + + JSONObject vmIdListJson = new JSONObject(); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat("", payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vserverIdList_Empty_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + ArrayList<String> vmIdList = new ArrayList<String>(); + String vmId = "testlink:testVmId"; + vmIdList.add(vmId); + JSONObject vmIdListJson = new JSONObject(); + vmIdListJson.put("vmIds", vmIdList); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat(vmId, payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } + + @Test + public void runAppCCommand_Snapshot_vserverId_null_Test() + throws ApplicationControllerOrchestratorException, JsonProcessingException { + Action action = Action.Snapshot; + String msoRequestId = "testMsoRequestId"; + String vnfId = "testVnfId"; + Optional<String> payload = Optional.empty(); + HashMap<String, String> payloadInfo = new HashMap<String, String>(); + payloadInfo.put("identityUrl", "testIdentityUrl"); + ArrayList<String> vmIdList = new ArrayList<String>(); + String vmId = "testlink:testVmId1"; + vmIdList.add(vmId); + JSONObject vmIdListJson = new JSONObject(); + vmIdListJson.put("vmIds", vmIdList); + payloadInfo.put("vmIdList", vmIdListJson.toString()); + JSONObject vserverIdListJson = new JSONObject(); + payloadInfo.put("vserverIdList", vserverIdListJson.toString()); + String controllerType = "testControllerType"; + + Status status = new Status(); + Optional<String> otherPayloadVm = PayloadClient.snapshotFormat(vmId, payloadInfo.get("identityUrl")); + doReturn(status).when(client).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + + appCAction.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType); + + verify(client, times(0)).vnfCommand(action, msoRequestId, vnfId, null, otherPayloadVm, controllerType); + } } diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java index 7d5bb0dcf1..21847e1c4e 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/WorkflowException.java @@ -33,7 +33,7 @@ public class WorkflowException implements Serializable { private final int errorCode; private final String errorMessage; private final String workStep; - private TargetEntities extSystemErrorSource; + private transient TargetEntities extSystemErrorSource; /** * Constructor diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceInstance.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceInstance.java index b0b837b3b9..fad6490df2 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceInstance.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/domain/ServiceInstance.java @@ -22,9 +22,7 @@ package org.onap.so.bpmn.core.domain; import java.io.Serializable; import java.util.Map; -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonRootName; /** * This class is used to store instance data of services aka ServiceDecomposition @@ -46,7 +44,7 @@ public class ServiceInstance extends JsonWrapper implements Serializable { private ModelInfo modelInfo; private String environmentContext; private String workloadContext; - private Map serviceParams; + private transient Map serviceParams; private Customer customer = new Customer(); private String e2eVpnKey; diff --git a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/json/JsonUtils.java b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/json/JsonUtils.java index d3d07f9014..3f10df36ab 100644 --- a/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/json/JsonUtils.java +++ b/bpmn/MSOCoreBPMN/src/main/java/org/onap/so/bpmn/core/json/JsonUtils.java @@ -323,7 +323,7 @@ public class JsonUtils { logger.debug("getJsonValue(): the raw value is a String Object={}", rawValue); return (String) rawValue; } else { - logger.debug("getJsonValue(): the raw value is NOT a String Object={}", rawValue.toString()); + logger.debug("getJsonValue(): the raw value is NOT a String Object={}", rawValue); return rawValue.toString(); } } @@ -352,7 +352,7 @@ public class JsonUtils { logger.debug("getJsonNodeValue(): the raw value is a String Object={}", rawValue); return (String) rawValue; } else { - logger.debug("getJsonNodeValue(): the raw value is NOT a String Object={}", rawValue.toString()); + logger.debug("getJsonNodeValue(): the raw value is NOT a String Object={}", rawValue); return rawValue.toString(); } } @@ -380,11 +380,10 @@ public class JsonUtils { return 0; } else { if (rawValue instanceof Integer) { - logger.debug("getJsonIntValue(): the raw value is an Integer Object={}", - ((String) rawValue).toString()); + logger.debug("getJsonIntValue(): the raw value is an Integer Object={}", rawValue); return (Integer) rawValue; } else { - logger.debug("getJsonIntValue(): the raw value is NOT an Integer Object={}", rawValue.toString()); + logger.debug("getJsonIntValue(): the raw value is NOT an Integer Object={}", rawValue); return 0; } } @@ -412,8 +411,7 @@ public class JsonUtils { logger.debug("getJsonBooleanValue(): the raw value is a Boolean Object={}", rawValue); return (Boolean) rawValue; } else { - logger.debug("getJsonBooleanValue(): the raw value is NOT an Boolean Object={}", - rawValue.toString()); + logger.debug("getJsonBooleanValue(): the raw value is NOT an Boolean Object={}", rawValue); return false; } } @@ -455,7 +453,7 @@ public class JsonUtils { return null; } else { if (rawValue instanceof JSONArray) { - logger.debug("getJsonParamValue(): keys={} points to JSONArray: {}", keys, rawValue.toString()); + logger.debug("getJsonParamValue(): keys={} points to JSONArray: {}", keys, rawValue); int arrayLen = ((JSONArray) rawValue).length(); if (index < 0 || arrayLen < index + 1) { logger.debug("getJsonParamValue(): index: {} is out of bounds for array size of {}", index, @@ -464,8 +462,7 @@ public class JsonUtils { } int foundCnt = 0; for (int i = 0; i < arrayLen; i++) { - logger.debug("getJsonParamValue(): index: {}, value: {}", i, - ((JSONArray) rawValue).get(i).toString()); + logger.debug("getJsonParamValue(): index: {}, value: {}", i, ((JSONArray) rawValue).get(i)); if (((JSONArray) rawValue).get(i) instanceof JSONObject) { JSONObject jsonObj = (JSONObject) ((JSONArray) rawValue).get(i); String parmValue = jsonObj.get(name).toString(); @@ -482,16 +479,14 @@ public class JsonUtils { continue; } } else { - logger.debug("getJsonParamValue(): the JSONArray element is NOT a JSONObject={}", - rawValue.toString()); + logger.debug("getJsonParamValue(): the JSONArray element is NOT a JSONObject={}", rawValue); return null; } } logger.debug("getJsonParamValue(): content value NOT found for name: {}", name); return null; } else { - logger.debug("getJsonParamValue(): the raw value is NOT a JSONArray Object={}", - rawValue.toString()); + logger.debug("getJsonParamValue(): the raw value is NOT a JSONArray Object={}", rawValue); return null; } } @@ -1057,13 +1052,13 @@ public class JsonUtils { JsonValidator validator = factory.getValidator(); ProcessingReport report = validator.validate(schema, document); - logger.debug("JSON schema validation report: {}", report.toString()); + logger.debug("JSON schema validation report: {}", report); return report.toString(); } catch (IOException e) { - logger.debug("IOException performing JSON schema validation on document: {}", e.toString()); + logger.debug("IOException performing JSON schema validation on document:", e); throw new ValidationException(e.getMessage()); } catch (ProcessingException e) { - logger.debug("ProcessingException performing JSON schema validation on document: {}", e.toString()); + logger.debug("ProcessingException performing JSON schema validation on document:", e); throw new ValidationException(e.getMessage()); } } diff --git a/bpmn/mso-infrastructure-bpmn/pom.xml b/bpmn/mso-infrastructure-bpmn/pom.xml index ea1a205317..25913eabba 100644 --- a/bpmn/mso-infrastructure-bpmn/pom.xml +++ b/bpmn/mso-infrastructure-bpmn/pom.xml @@ -134,6 +134,24 @@ </executions> </plugin> </plugins> + <resources> + <resource> + <directory>src/main/resources</directory> + <filtering>true</filtering> + <excludes> + <exclude>**/*.p12</exclude> + <exclude>**/*.jks</exclude> + </excludes> + </resource> + <resource> + <directory>src/main/resources</directory> + <filtering>false</filtering> + <includes> + <include>**/*.p12</include> + <include>**/*.jks</include> + </includes> + </resource> + </resources> </build> <dependencyManagement> <dependencies> diff --git a/bpmn/mso-infrastructure-bpmn/src/main/resources/org.onap.so.p12 b/bpmn/mso-infrastructure-bpmn/src/main/resources/org.onap.so.p12 Binary files differnew file mode 100644 index 0000000000..79631bf344 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/resources/org.onap.so.p12 diff --git a/bpmn/mso-infrastructure-bpmn/src/main/resources/org.onap.so.trust.jks b/bpmn/mso-infrastructure-bpmn/src/main/resources/org.onap.so.trust.jks Binary files differnew file mode 100644 index 0000000000..6f8168d896 --- /dev/null +++ b/bpmn/mso-infrastructure-bpmn/src/main/resources/org.onap.so.trust.jks diff --git a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java index fc0f51b032..91cfa93a34 100644 --- a/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java +++ b/bpmn/mso-infrastructure-bpmn/src/test/java/org/onap/so/bpmn/infrastructure/pnf/delegate/CreateAndActivatePnfResourceTest.java @@ -63,8 +63,9 @@ public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest { public void shouldWaitForMessageFromDmaapAndUpdateAaiEntryWhenAaiEntryExists() { // given variables.put(PNF_CORRELATION_ID, PnfManagementTestImpl.ID_WITH_ENTRY); - if (getUpdateResInputObj("OLT") != null) { - variables.put("resourceInput", getUpdateResInputObj("OLT").toString()); + ResourceInput ri = getUpdateResInputObj("OLT"); + if (ri != null) { + variables.put("resourceInput", ri.toString()); } else { variables.put("resourceInput", null); } @@ -86,7 +87,12 @@ public class CreateAndActivatePnfResourceTest extends BaseIntegrationTest { public void shouldCreateAaiEntryWaitForMessageFromDmaapAndUpdateAaiEntryWhenNoAaiEntryExists() { // given variables.put(PNF_CORRELATION_ID, PnfManagementTestImpl.ID_WITHOUT_ENTRY); - variables.put("resourceInput", getUpdateResInputObj("OLT").toString()); + ResourceInput ri = getUpdateResInputObj("OLT"); + if (ri != null) { + variables.put("resourceInput", ri.toString()); + } else { + variables.put("resourceInput", null); + } // when ProcessInstance instance = runtimeService.startProcessInstanceByKey("CreateAndActivatePnfResource", "businessKey", variables); diff --git a/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java b/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java index e4f1998c40..12f30cfa58 100644 --- a/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java +++ b/bpmn/so-bpmn-building-blocks/src/main/java/org/onap/so/bpmn/infrastructure/bpmn/activity/DeployActivitySpecs.java @@ -31,6 +31,8 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.springframework.stereotype.Component; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Component public class DeployActivitySpecs { @@ -38,10 +40,12 @@ public class DeployActivitySpecs { private static final String ACTIVITY_SPEC_URI = "/activityspec-api/v1.0/activity-spec"; private static final String CONTENT_TYPE_JSON = "application/json"; + private static final Logger logger = LoggerFactory.getLogger(DeployActivitySpecs.class); + public static void main(String[] args) throws Exception { if (args == null || args.length == 0) { - System.out.println("Please specify hostname argument"); + logger.info("Please specify hostname argument"); return; } @@ -49,20 +53,23 @@ public class DeployActivitySpecs { File dir = new File(ACTIVITY_FILE_LOCATION); if (!dir.isDirectory()) { - System.out.println("ActivitySpec store is not a directory"); + logger.debug("ActivitySpec store is not a directory"); return; } - for (File f : dir.listFiles()) { - String activitySpecName = f.getName(); - String errorMessage = deployActivitySpec(hostname, activitySpecName); - if (errorMessage == null) { - System.out.println("Deployed Activity Spec: " + activitySpecName); - } else { - System.out.println("Error deploying Activity Spec: " + activitySpecName + " : " + errorMessage); + if (dir.listFiles() != null) { + for (File f : dir.listFiles()) { + String activitySpecName = f.getName(); + String errorMessage = deployActivitySpec(hostname, activitySpecName); + if (errorMessage == null) { + logger.debug("Deployed Activity Spec: " + activitySpecName); + } else { + logger.error("Error deploying Activity Spec: " + activitySpecName + " : " + errorMessage); + } } + } else { + logger.error("Null file list for Activity Specs."); } - return; } protected static String deployActivitySpec(String hostname, String activitySpecName) throws Exception { diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java index 1516f289fe..579e7b72df 100644 --- a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/workflow/service/ServicePluginFactory.java @@ -98,12 +98,17 @@ public class ServicePluginFactory { new String[] {VS_MONITORED, VS_UNMONITORED, TS_MONITORED, TS_UNMONITORED}; static { - try (InputStream is = ClassLoader.class.getResourceAsStream("/application.properties")) { - Properties prop = new Properties(); - prop.load(is); - OOF_DEFAULT_ENDPOINT = prop.getProperty("oof.default.endpoint"); - THIRD_SP_DEFAULT_ENDPOINT = prop.getProperty("third.sp.default.endpoint"); - INVENTORY_OSS_DEFAULT_ENDPOINT = prop.getProperty("inventory.oss.default.endpoint"); + try { + InputStream is = ClassLoader.class.getResourceAsStream("/application.properties"); + if (null != is) { + Properties prop = new Properties(); + prop.load(is); + OOF_DEFAULT_ENDPOINT = prop.getProperty("oof.default.endpoint"); + THIRD_SP_DEFAULT_ENDPOINT = prop.getProperty("third.sp.default.endpoint"); + INVENTORY_OSS_DEFAULT_ENDPOINT = prop.getProperty("inventory.oss.default.endpoint"); + } else { + logger.error("Failed to load property file, Either property file is missing or empty!"); + } } catch (IOException e) { logger.error("Failed to load property file!"); } @@ -434,7 +439,7 @@ public class ServicePluginFactory { } } - logger.error("There is no matching logical link for allowed list :" + allowedList.toString()); + logger.error("There is no matching logical link for allowed list :" + Arrays.toString(allowedList)); return null; } else { logger.info("link customization is not required"); diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java index 638ecefa49..a436f7b5c2 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/activity/ExecuteActivity.java @@ -99,6 +99,7 @@ public class ExecuteActivity implements JavaDelegate { variables.put(G_REQUEST_ID, requestId); variables.put("retryCount", 1); variables.put("aLaCarte", true); + variables.put("suppressRollback", true); execution.getVariables().forEach((key, value) -> { if (value instanceof Serializable) { diff --git a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java index f5bae2c82a..c3c0047fff 100644 --- a/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java +++ b/bpmn/so-bpmn-tasks/src/main/java/org/onap/so/bpmn/infrastructure/adapter/vnfm/tasks/VnfmAdapterCreateVnfTaskConfiguration.java @@ -21,14 +21,32 @@ package org.onap.so.bpmn.infrastructure.adapter.vnfm.tasks; import static org.onap.so.client.RestTemplateConfig.CONFIGURABLE_REST_TEMPLATE; +import java.io.IOException; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import javax.net.ssl.SSLContext; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.ssl.SSLContextBuilder; 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.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; /** @@ -40,13 +58,55 @@ import org.springframework.web.client.RestTemplate; @Configuration public class VnfmAdapterCreateVnfTaskConfiguration { + private static final Logger logger = LoggerFactory.getLogger(VnfmAdapterCreateVnfTaskConfiguration.class); + + @Value("${rest.http.client.configuration.ssl.trustStore:#{null}}") + private Resource trustStore; + + @Value("${rest.http.client.configuration.ssl.trustStorePassword:#{null}}") + private String trustStorePassword; + + @Value("${rest.http.client.configuration.ssl.keyStore:#{null}}") + private Resource keyStoreResource; + + @Value("${rest.http.client.configuration.ssl.keyStorePassword:#{null}}") + private String keyStorePassword; + @Bean public HttpRestServiceProvider databaseHttpRestServiceProvider( @Qualifier(CONFIGURABLE_REST_TEMPLATE) @Autowired final RestTemplate restTemplate, @Autowired final VnfmBasicHttpConfigProvider etsiVnfmAdapter) { + if (trustStore != null) { + setTrustStore(restTemplate); + } return getHttpRestServiceProvider(restTemplate, new BasicHttpHeadersProvider(etsiVnfmAdapter.getAuth())); } + private void setTrustStore(final RestTemplate restTemplate) { + SSLContext sslContext; + try { + if (keyStoreResource != null) { + KeyStore keystore = KeyStore.getInstance("pkcs12"); + keystore.load(keyStoreResource.getInputStream(), keyStorePassword.toCharArray()); + sslContext = + new SSLContextBuilder().loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()) + .loadKeyMaterial(keystore, keyStorePassword.toCharArray()).build(); + } else { + sslContext = new SSLContextBuilder() + .loadTrustMaterial(trustStore.getURL(), trustStorePassword.toCharArray()).build(); + } + logger.info("Setting truststore: {}", trustStore.getURL()); + final SSLConnectionSocketFactory socketFactory = new SSLConnectionSocketFactory(sslContext); + final HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build(); + final HttpComponentsClientHttpRequestFactory factory = + new HttpComponentsClientHttpRequestFactory(httpClient); + restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(factory)); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException | CertificateException + | IOException | UnrecoverableKeyException exception) { + logger.error("Error reading truststore, TLS connection to VNFM will fail.", exception); + } + } + private HttpRestServiceProvider getHttpRestServiceProvider(final RestTemplate restTemplate, final HttpHeadersProvider httpHeadersProvider) { return new HttpRestServiceProviderImpl(restTemplate, httpHeadersProvider); |