From 8ae4003f892a95dd76e9370d430548d57a35f82c Mon Sep 17 00:00:00 2001 From: "Boslet, Cory" Date: Fri, 17 May 2019 10:06:55 -0400 Subject: Audit service enhancements Update number of threads used for openstack audit Refactored post construct audit service and added junits Change-Id: Ic5bd42cda98835305d2e2d5d09a5c039376316a5 Issue-ID: SO-1898 Signed-off-by: Benjamin, Max (mb388a) --- .../onap/so/adapters/audit/AuditStackService.java | 44 ++++++++------ .../src/main/resources/application.yaml | 2 +- .../so/adapters/audit/AuditStackServiceTest.java | 71 ++++++++++++++++++++++ 3 files changed, 99 insertions(+), 18 deletions(-) create mode 100644 adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java (limited to 'adapters/mso-openstack-adapters') diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java index 3508810e04..57d31bf308 100644 --- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java +++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java @@ -50,23 +50,32 @@ public class AuditStackService { private AuditDeleteStackService auditDeleteStack; @PostConstruct - public void auditAddAAIInventory() { - String auth = ""; - try { - auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey")); - } catch (IllegalStateException | GeneralSecurityException e) { - logger.error("Error Decrypting Password", e); + public void auditAddAAIInventory() throws Exception { + for (int i = 0; i < getMaxClients(); i++) { + ExternalTaskClient client = createExternalTaskClient(); + client.subscribe("InventoryAddAudit").lockDuration(60000).handler(auditCreateStack::executeExternalTask) + .open(); } - ClientRequestInterceptor interceptor = - new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth); + } + + @PostConstruct + public void auditDeleteAAIInventory() throws Exception { + for (int i = 0; i < getMaxClients(); i++) { + ExternalTaskClient client = createExternalTaskClient(); + client.subscribe("InventoryDeleteAudit").lockDuration(60000).handler(auditDeleteStack::executeExternalTask) + .open(); + } + } + + protected ExternalTaskClient createExternalTaskClient() throws Exception { + ClientRequestInterceptor interceptor = createClientRequestInterceptor(); ExternalTaskClient client = ExternalTaskClient.create() .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor) - .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build(); - client.subscribe("InventoryAddAudit").lockDuration(60000).handler(auditCreateStack::executeExternalTask).open(); + .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(10000, 2, 120000)).build(); + return client; } - @PostConstruct - public void auditDeleteAAIInventory() { + protected ClientRequestInterceptor createClientRequestInterceptor() { String auth = ""; try { auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey")); @@ -75,11 +84,12 @@ public class AuditStackService { } ClientRequestInterceptor interceptor = new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth); - ExternalTaskClient client = ExternalTaskClient.create() - .baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1).addInterceptor(interceptor) - .asyncResponseTimeout(120000).backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build(); - client.subscribe("InventoryDeleteAudit").lockDuration(60000).handler(auditDeleteStack::executeExternalTask) - .open(); + return interceptor; + } + + protected int getMaxClients() { + return Integer.parseInt(env.getProperty("workflow.topics.maxClients", "10")); } + } diff --git a/adapters/mso-openstack-adapters/src/main/resources/application.yaml b/adapters/mso-openstack-adapters/src/main/resources/application.yaml index 1982961ae7..470bb31b19 100644 --- a/adapters/mso-openstack-adapters/src/main/resources/application.yaml +++ b/adapters/mso-openstack-adapters/src/main/resources/application.yaml @@ -4,7 +4,7 @@ server: port: 8080 tomcat: - max-threads: 50 + max-threads: 75 mso: logPath: ./logs/openstack diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java new file mode 100644 index 0000000000..2eb8d8ef39 --- /dev/null +++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java @@ -0,0 +1,71 @@ +package org.onap.so.adapters.audit; + +import static com.shazam.shazamcrest.MatcherAssert.assertThat; +import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import org.camunda.bpm.client.ExternalTaskClient; +import org.camunda.bpm.client.interceptor.ClientRequestInterceptor; +import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.Spy; +import org.mockito.junit.MockitoJUnitRunner; +import org.onap.so.utils.CryptoUtils; +import org.springframework.core.env.Environment; + +@RunWith(MockitoJUnitRunner.class) +public class AuditStackServiceTest { + + @Spy + @InjectMocks + AuditStackService auditStackService; + + @Mock + Environment mockEnvironment; + + + @Before + public void before() { + Mockito.doReturn("5").when(mockEnvironment).getProperty("workflow.topics.maxClients", "10"); + Mockito.doReturn("6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436") + .when(mockEnvironment).getRequiredProperty("mso.auth"); + Mockito.doReturn("07a7159d3bf51a0e53be7a8f89699be7").when(mockEnvironment).getRequiredProperty("mso.msoKey"); + Mockito.doReturn("something").when(mockEnvironment).getRequiredProperty("mso.config.cadi.aafId"); + Mockito.doReturn("host.com").when(mockEnvironment).getRequiredProperty("mso.workflow.endpoint"); + } + + @Test + public void testGetMaxClients() throws Exception { + int actual = auditStackService.getMaxClients(); + assertEquals(5, actual); + } + + @Test + public void testCreateClientRequestInterceptor() throws Exception { + String auth = CryptoUtils.decrypt( + "6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436", + "07a7159d3bf51a0e53be7a8f89699be7"); + ClientRequestInterceptor expected = new BasicAuthProvider("something", auth); + ClientRequestInterceptor actual = auditStackService.createClientRequestInterceptor(); + assertThat(actual, sameBeanAs(expected)); + + } + + @Test + public void testCreateExternalTaskClient() throws Exception { + String auth = CryptoUtils.decrypt( + "6B466C603A260F3655DBF91E53CE54667041C01406D10E8CAF9CC24D8FA5388D06F90BFE4C852052B436", + "07a7159d3bf51a0e53be7a8f89699be7"); + ClientRequestInterceptor inter = new BasicAuthProvider("something", auth); + Mockito.doReturn(inter).when(auditStackService).createClientRequestInterceptor(); + ExternalTaskClient actual = auditStackService.createExternalTaskClient(); + assertNotNull(actual); + Mockito.verify(auditStackService, Mockito.times(1)).createClientRequestInterceptor(); + + } +} -- cgit 1.2.3-korg