summaryrefslogtreecommitdiffstats
path: root/adapters/mso-openstack-adapters/src
diff options
context:
space:
mode:
authorSteve Smokowski <ss835w@att.com>2019-09-10 11:58:11 +0000
committerGerrit Code Review <gerrit@onap.org>2019-09-10 11:58:11 +0000
commit8d19ead3b24e7ee654bb467565ad7e6b94ddc671 (patch)
tree7659987fa1e4d3a3696a33999f13ef25e8bf62e2 /adapters/mso-openstack-adapters/src
parentd6d0a05998f981bfc48f71c713f5b1f9797bf56e (diff)
parentff4b57e3632507a7a8e4b740722663f02caacc2a (diff)
Merge "Created external task utils in a common location"
Diffstat (limited to 'adapters/mso-openstack-adapters/src')
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java24
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java4
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditStackService.java49
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryService.java24
-rw-r--r--adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java28
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java41
-rw-r--r--adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java91
7 files changed, 24 insertions, 237 deletions
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java
index 8edce124ec..493ac4a54f 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AbstractAuditService.java
@@ -22,19 +22,17 @@
package org.onap.so.adapters.audit;
import java.util.Optional;
-import org.camunda.bpm.client.task.ExternalTask;
-import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.objects.audit.AAIObjectAudit;
import org.onap.so.objects.audit.AAIObjectAuditList;
+import org.onap.so.utils.ExternalTaskUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
-public abstract class AbstractAuditService {
+public abstract class AbstractAuditService extends ExternalTaskUtils {
private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
@@ -82,22 +80,4 @@ public abstract class AbstractAuditService {
}
}
- protected String[] getRetrySequence() {
- return env.getProperty("mso.workflow.topics.retrySequence", String[].class);
- }
-
- protected void setupMDC(ExternalTask externalTask) {
- logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
- String msoRequestId = externalTask.getVariable("mso-request-id");
- if (msoRequestId != null && !msoRequestId.isEmpty()) {
- MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
- }
- MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName());
- }
-
- protected long calculateRetryDelay(int currentRetries) {
- int retrySequence = getRetrySequence().length - currentRetries;
- long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier", "6000"));
- return Integer.parseInt(getRetrySequence()[retrySequence]) * retryMultiplier;
- }
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java
index 1e5b6de857..d03c86ac30 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/audit/AuditCreateStackService.java
@@ -34,7 +34,6 @@ import org.onap.so.objects.audit.AAIObjectAuditList;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
@@ -45,9 +44,6 @@ public class AuditCreateStackService extends AbstractAuditService {
@Autowired
public HeatStackAudit heatStackAudit;
- @Autowired
- public Environment environment;
-
protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
setupMDC(externalTask);
AuditInventory auditInventory = externalTask.getVariable("auditInventory");
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 6a42456715..fb7e925d88 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
@@ -20,13 +20,9 @@
package org.onap.so.adapters.audit;
-import java.security.GeneralSecurityException;
import javax.annotation.PostConstruct;
import org.camunda.bpm.client.ExternalTaskClient;
-import org.camunda.bpm.client.backoff.ExponentialBackoffStrategy;
-import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
-import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
-import org.onap.so.utils.CryptoUtils;
+import org.onap.so.utils.ExternalTaskServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -56,10 +52,13 @@ public class AuditStackService {
@Autowired
private AuditQueryStackService auditQueryStack;
+ @Autowired
+ private ExternalTaskServiceUtils externalTaskServiceUtils;
+
@PostConstruct
- public void auditAddAAIInventory() {
- for (int i = 0; i < getMaxClients(); i++) {
- ExternalTaskClient client = createExternalTaskClient();
+ public void auditAddAAIInventory() throws Exception {
+ for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
+ ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
client.subscribe("InventoryAddAudit")
.lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
.handler(auditCreateStack::executeExternalTask).open();
@@ -67,9 +66,9 @@ public class AuditStackService {
}
@PostConstruct
- public void auditDeleteAAIInventory() {
- for (int i = 0; i < getMaxClients(); i++) {
- ExternalTaskClient client = createExternalTaskClient();
+ public void auditDeleteAAIInventory() throws Exception {
+ for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
+ ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
client.subscribe("InventoryDeleteAudit")
.lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
.handler(auditDeleteStack::executeExternalTask).open();
@@ -77,35 +76,13 @@ public class AuditStackService {
}
@PostConstruct
- public void auditQueryInventory() {
- for (int i = 0; i < getMaxClients(); i++) {
- ExternalTaskClient client = createExternalTaskClient();
+ public void auditQueryInventory() throws Exception {
+ for (int i = 0; i < externalTaskServiceUtils.getMaxClients(); i++) {
+ ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
client.subscribe("InventoryQueryAudit")
.lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", DEFAULT_AUDIT_LOCK_TIME)))
.handler(auditQueryStack::executeExternalTask).open();
}
}
- protected ExternalTaskClient createExternalTaskClient() {
- ClientRequestInterceptor interceptor = createClientRequestInterceptor();
- return ExternalTaskClient.create().baseUrl(env.getRequiredProperty("mso.workflow.endpoint")).maxTasks(1)
- .addInterceptor(interceptor).asyncResponseTimeout(120000)
- .backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0)).build();
- }
-
- protected ClientRequestInterceptor createClientRequestInterceptor() {
- String auth = "";
- try {
- auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
- } catch (IllegalStateException | GeneralSecurityException e) {
- logger.error("Error Decrypting Password", e);
- }
- return new BasicAuthProvider(env.getRequiredProperty("mso.config.cadi.aafId"), auth);
- }
-
- protected int getMaxClients() {
- return Integer.parseInt(env.getProperty("workflow.topics.maxClients", DEFAULT_MAX_CLIENTS_FOR_TOPIC));
- }
-
-
}
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryService.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryService.java
index 49a9e7e171..c1cc7428ee 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryService.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryService.java
@@ -20,13 +20,9 @@
package org.onap.so.adapters.inventory.create;
-import java.security.GeneralSecurityException;
import javax.annotation.PostConstruct;
import org.camunda.bpm.client.ExternalTaskClient;
-import org.camunda.bpm.client.backoff.ExponentialBackoffStrategy;
-import org.camunda.bpm.client.interceptor.ClientRequestInterceptor;
-import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;
-import org.onap.so.utils.CryptoUtils;
+import org.onap.so.utils.ExternalTaskServiceUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -46,19 +42,13 @@ public class CreateInventoryService {
@Autowired
private CreateInventoryTask createInventory;
+ @Autowired
+ private ExternalTaskServiceUtils externalTaskServiceUtils;
+
@PostConstruct
- public void auditAAIInventory() {
- String auth = "";
- try {
- auth = CryptoUtils.decrypt(env.getRequiredProperty("mso.auth"), env.getRequiredProperty("mso.msoKey"));
- } catch (IllegalStateException | GeneralSecurityException e) {
- logger.error("Error Decrypting Password", e);
- }
- 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();
+ public void auditAAIInventory() throws Exception {
+
+ ExternalTaskClient client = externalTaskServiceUtils.createExternalTaskClient();
client.subscribe("InventoryCreate")
.lockDuration(Long.parseLong(env.getProperty("mso.audit.lock-time", "60000")))
.handler(createInventory::executeExternalTask).open();
diff --git a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java
index a6c61704ad..29d0ef633f 100644
--- a/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java
+++ b/adapters/mso-openstack-adapters/src/main/java/org/onap/so/adapters/inventory/create/CreateInventoryTask.java
@@ -27,15 +27,14 @@ import org.camunda.bpm.client.task.ExternalTaskService;
import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.so.client.graphinventory.GraphInventoryCommonObjectMapperProvider;
import org.onap.so.objects.audit.AAIObjectAuditList;
+import org.onap.so.utils.ExternalTaskUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
-public class CreateInventoryTask {
+public class CreateInventoryTask extends ExternalTaskUtils {
private static final String UNABLE_TO_WRITE_ALL_INVENTORY_TO_A_AI = "Unable to write all inventory to A&AI";
@@ -46,9 +45,6 @@ public class CreateInventoryTask {
@Autowired
CreateAAIInventory createInventory;
- @Autowired
- public Environment env;
-
protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
setupMDC(externalTask);
boolean success = true;
@@ -107,25 +103,5 @@ public class CreateInventoryTask {
}
}
- private void setupMDC(ExternalTask externalTask) {
- try {
- logger.info(ONAPLogConstants.Markers.ENTRY, "Entering");
- MDC.put(ONAPLogConstants.MDCs.SERVICE_NAME, externalTask.getTopicName());
- String msoRequestId = externalTask.getVariable("mso-request-id");
- if (msoRequestId != null && !msoRequestId.isEmpty())
- MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, msoRequestId);
- } catch (Exception e) {
- logger.error("Error in setting up MDC", e);
- }
- }
-
- protected long calculateRetryDelay(int currentRetries) {
- int retrySequence = getRetrySequence().length - currentRetries;
- long retryMultiplier = Long.parseLong(env.getProperty("mso.workflow.topics.retryMultiplier", "6000"));
- return Integer.parseInt(getRetrySequence()[retrySequence]) * retryMultiplier;
- }
- public String[] getRetrySequence() {
- return env.getProperty("mso.workflow.topics.retrySequence", String[].class);
- }
}
diff --git a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
index 3432e4a8b6..2109fb289f 100644
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
+++ b/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceDataTest.java
@@ -170,47 +170,6 @@ public class AuditStackServiceDataTest extends AuditCreateStackService {
}
@Test
- public void retry_sequence_calculation_Test() {
- long firstRetry = auditStackService.calculateRetryDelay(8);
- assertEquals(6000L, firstRetry);
- long secondRetry = auditStackService.calculateRetryDelay(7);
- assertEquals(6000L, secondRetry);
- long thirdRetry = auditStackService.calculateRetryDelay(6);
- assertEquals(12000L, thirdRetry);
- long fourthRetry = auditStackService.calculateRetryDelay(5);
- assertEquals(18000L, fourthRetry);
- long fifthRetry = auditStackService.calculateRetryDelay(4);
- assertEquals(30000L, fifthRetry);
- long sixRetry = auditStackService.calculateRetryDelay(3);
- assertEquals(48000L, sixRetry);
- long seventhRetry = auditStackService.calculateRetryDelay(2);
- assertEquals(78000L, seventhRetry);
- long eigthRetry = auditStackService.calculateRetryDelay(1);
- assertEquals(120000L, eigthRetry);
- }
-
- @Test
- public void retry_sequence_Test() {
- long firstRetry = auditStackService.calculateRetryDelay(8);
- assertEquals(6000L, firstRetry);
- long secondRetry = auditStackService.calculateRetryDelay(7);
- assertEquals(6000L, secondRetry);
- long thirdRetry = auditStackService.calculateRetryDelay(6);
- assertEquals(12000L, thirdRetry);
- long fourthRetry = auditStackService.calculateRetryDelay(5);
- assertEquals(18000L, fourthRetry);
- long fifthRetry = auditStackService.calculateRetryDelay(4);
- assertEquals(30000L, fifthRetry);
- long sixRetry = auditStackService.calculateRetryDelay(3);
- assertEquals(48000L, sixRetry);
- long seventhRetry = auditStackService.calculateRetryDelay(2);
- assertEquals(78000L, seventhRetry);
- long eigthRetry = auditStackService.calculateRetryDelay(1);
- assertEquals(120000L, eigthRetry);
- }
-
-
- @Test
public void determineAuditResult_Test() throws Exception {
boolean actual = auditStackService.didCreateAuditFail(auditListOptSuccess);
assertEquals(false, actual);
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
deleted file mode 100644
index c9aef950f7..0000000000
--- a/adapters/mso-openstack-adapters/src/test/java/org/onap/so/adapters/audit/AuditStackServiceTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP - SO
- * ================================================================================
- * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.so.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();
-
- }
-}