summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichaelMorris <michael.morris@est.tech>2021-09-06 14:28:23 +0100
committerAndr� Schmid <andre.schmid@est.tech>2021-09-09 12:12:29 +0000
commitc03a82e3af8ae60c1200a252aac8dadb1c8da0b8 (patch)
tree26ae3386e358b4865942d550f12357f01b732914
parent0ba5888b69b3ac6b60967ba9b64db96e87dc5c4e (diff)
[SDC-BE] Remove hardcoded MR apiKey
Issue-ID: SDC-3714 Change-Id: Ie154a225bc1c47d6d3b504f915a697047e1b0440 Signed-off-by: MichaelMorris <michael.morris@est.tech>
-rw-r--r--asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineClusterHealthMock.java2
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java12
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java8
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java17
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealthTest.java27
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java9
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/StepsTenantIsolation.java4
7 files changed, 47 insertions, 32 deletions
diff --git a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineClusterHealthMock.java b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineClusterHealthMock.java
index b7273d7a7a..4294ca64d9 100644
--- a/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineClusterHealthMock.java
+++ b/asdctool/src/main/java/org/openecomp/sdc/asdctool/migration/config/mocks/DistributionEngineClusterHealthMock.java
@@ -26,7 +26,7 @@ import org.springframework.stereotype.Component;
public class DistributionEngineClusterHealthMock extends DistributionEngineClusterHealth {
@Override
- protected void init() {
+ protected void init(final String publicApiKey) {
}
@Override
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
index 425b464c4f..41d10737d3 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/CambriaHandler.java
@@ -62,10 +62,6 @@ public class CambriaHandler implements ICambriaHandler {
private static final Logger log = Logger.getLogger(CambriaHandler.class.getName());
private static final String PARTITION_KEY = "asdc" + "aa";
private static final String SEND_NOTIFICATION = "send notification";
- private static final String CONSUMER_ID = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration()
- .getDistributionStatusTopic().getConsumerId();
- private static final boolean USE_HTTPS_WITH_DMAAP = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration()
- .isUseHttpsWithDmaap();
private final Gson gson = new Gson();
/**
@@ -284,7 +280,9 @@ public class CambriaHandler implements ICambriaHandler {
String managerSecretKey) {
AbstractAuthenticatedManagerBuilder<CambriaTopicManager> clientBuilder = createTopicManagerBuilder(hostSet)
.authenticatedBy(managerApiKey, managerSecretKey);
- if (USE_HTTPS_WITH_DMAAP) {
+ final boolean useHttpsWithDmaap = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration()
+ .isUseHttpsWithDmaap();
+ if (useHttpsWithDmaap) {
clientBuilder = clientBuilder.usingHttps();
}
return clientBuilder;
@@ -506,7 +504,9 @@ public class CambriaHandler implements ICambriaHandler {
Either<ApiCredential, CambriaErrorResponse> result;
try {
CambriaIdentityManager createIdentityManager = buildCambriaClient(new IdentityManagerBuilder().usingHosts(hostSet));
- String description = String.format("ASDC Key for %s", CONSUMER_ID);
+ final String consumerId = ConfigurationManager.getConfigurationManager().getDistributionEngineConfiguration()
+ .getDistributionStatusTopic().getConsumerId();
+ String description = String.format("ASDC Key for %s", consumerId);
ApiCredential credential = createIdentityManager.createApiKey("", description);
createIdentityManager.setApiCredentials(credential.getApiKey(), credential.getApiSecret());
result = Either.left(credential);
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java
index b1bf59f3aa..0851f22c0a 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java
@@ -31,7 +31,6 @@ import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
-import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
@@ -66,9 +65,8 @@ public class DistributionEngineClusterHealth {
private HealthCheckInfo healthCheckInfo = HealthCheckInfoResult.UNKNOWN.getHealthCheckInfo();
private Map<String, AtomicBoolean> envNamePerStatus = null;
private ScheduledFuture<?> scheduledFuture = null;
-
- @PostConstruct
- protected void init() {
+
+ protected void init(final String publicApiKey) {
logger.trace("Enter init method of DistributionEngineClusterHealth");
Long reconnectIntervalConfig = ConfigurationManager.getConfigurationManager().getConfiguration()
.getUebHealthCheckReconnectIntervalInSeconds();
@@ -82,7 +80,7 @@ public class DistributionEngineClusterHealth {
DistributionEngineConfiguration distributionEngineConfiguration = ConfigurationManager.getConfigurationManager()
.getDistributionEngineConfiguration();
this.uebServers = distributionEngineConfiguration.getUebServers();
- this.publicApiKey = distributionEngineConfiguration.getUebPublicKey();
+ this.publicApiKey = publicApiKey;
this.healthCheckScheduledTask = new HealthCheckScheduledTask(this.uebServers);
logger.trace("Exit init method of DistributionEngineClusterHealth");
}
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java
index 26992b9c3d..afb311f452 100644
--- a/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java
+++ b/catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngine.java
@@ -168,6 +168,7 @@ public class EnvironmentsEngine implements INotificationHandler {
String envId = opEnvEntry.getEnvironmentId();
DistributionEngineConfiguration distributionEngineConfiguration = ConfigurationManager.getConfigurationManager()
.getDistributionEngineConfiguration();
+ distributionEngineClusterHealth.init(opEnvEntry.getUebApikey());
DistributionEnginePollingTask distributionEnginePollingTask = new DistributionEnginePollingTask(distributionEngineConfiguration,
distributionCompleteReporter, componentUtils, distributionEngineClusterHealth, opEnvEntry);
String envName = configurationManager.getDistributionEngineConfiguration().getEnvironments().get(0);
@@ -430,9 +431,25 @@ public class EnvironmentsEngine implements INotificationHandler {
private Map<String, OperationalEnvironmentEntry> populateEnvironments() {
Map<String, OperationalEnvironmentEntry> envs = getEnvironmentsFromDb();
OperationalEnvironmentEntry confEntry = readEnvFromConfig();
+ readKeyFromDbOrCreate(envs, confEntry);
envs.put(confEntry.getEnvironmentId(), confEntry);
return envs;
}
+
+ private void readKeyFromDbOrCreate(Map<String, OperationalEnvironmentEntry> envs, OperationalEnvironmentEntry confEntry) {
+ if (envs.get(confEntry.getEnvironmentId()) == null){
+ log.debug("Creating UEB API key");
+ Wrapper<Boolean> errorWrapper = new Wrapper<>();
+ createUebKeys(errorWrapper, confEntry);
+ confEntry.setStatus(EnvironmentStatusEnum.COMPLETED);
+ log.debug("Saving UEB API key to DB");
+ operationalEnvironmentDao.save(confEntry);
+ } else {
+ log.debug("Reading UEB API key from DB");
+ confEntry.setUebApikey(envs.get(confEntry.getEnvironmentId()).getUebApikey());
+ confEntry.setUebSecretKey(envs.get(confEntry.getEnvironmentId()).getUebSecretKey());
+ }
+ }
private OperationalEnvironmentEntry readEnvFromConfig() {
OperationalEnvironmentEntry entry = new OperationalEnvironmentEntry();
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealthTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealthTest.java
index 97cb367761..5f2b412743 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealthTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealthTest.java
@@ -20,6 +20,10 @@
package org.openecomp.sdc.be.components.distribution.engine;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import mockit.Deencapsulation;
import org.junit.Test;
import org.openecomp.sdc.be.components.BeConfDependentTest;
@@ -30,6 +34,7 @@ import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean;
+import org.openecomp.sdc.be.resources.data.OperationalEnvironmentEntry;
public class DistributionEngineClusterHealthTest extends BeConfDependentTest{
@@ -38,15 +43,6 @@ public class DistributionEngineClusterHealthTest extends BeConfDependentTest{
}
@Test
- public void testInit() throws Exception {
- DistributionEngineClusterHealth testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "init");
- }
-
- @Test
public void testDestroy() throws Exception {
DistributionEngineClusterHealth testSubject;
@@ -67,14 +63,11 @@ public class DistributionEngineClusterHealthTest extends BeConfDependentTest{
}
@Test
- public void testStartHealthCheckTask_1() throws Exception {
- DistributionEngineClusterHealth testSubject;
- Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
-
- // default test
- testSubject = createTestSubject();
- testSubject.init();
- testSubject.startHealthCheckTask(envNamePerStatus);
+ public void testStartHealthCheckTask_1() {
+ final DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
+ final Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
+ distributionEngineClusterHealth.init("myKey");
+ distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
}
@Test
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java
index 9ac04885b3..109743436f 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/EnvironmentsEngineTest.java
@@ -51,11 +51,12 @@ import java.util.List;
import java.util.Map;
import org.openecomp.sdc.common.impl.ExternalConfiguration;
import org.openecomp.sdc.common.impl.FSConfigurationSource;
-
+import com.att.nsa.apiClient.credentials.ApiCredential;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
import static org.mockito.Mockito.when;
public class EnvironmentsEngineTest {
@@ -70,6 +71,8 @@ public class EnvironmentsEngineTest {
private DistributionEngineConfiguration distributionEngineConfiguration;
@Mock
private AaiRequestHandler aaiRequestHandler;
+ @Mock
+ private CambriaHandler cambriaHandler;
@Before
public void preStart() {
@@ -94,8 +97,10 @@ public class EnvironmentsEngineTest {
when(configurationManager.getConfiguration()).thenReturn(config);
when(config.getDmaapConsumerConfiguration()).thenReturn(dmaapConf);
when(dmaapConf.isActive()).thenReturn(false);
+ ApiCredential apiCredential = new ApiCredential("apiKey", "apiSecret");
+ when(cambriaHandler.createUebKeys(any())).thenReturn(Either.left(apiCredential));
envEngine.init();
-
+
Map<String, OperationalEnvironmentEntry> mapEnvs = envEngine.getEnvironments();
assertEquals("unexpected size of map",3, mapEnvs.size());
}
diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/StepsTenantIsolation.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/StepsTenantIsolation.java
index 2d440aa0f4..77c332a314 100644
--- a/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/StepsTenantIsolation.java
+++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/StepsTenantIsolation.java
@@ -79,6 +79,8 @@ public class StepsTenantIsolation {
private AaiRequestHandler aaiRequestHandler;
@Mock
private CambriaHandler cambriaHandler;
+ @Mock
+ private DistributionEngineClusterHealth distributionEngineClusterHealth;
@InjectMocks
@Spy
private EnvironmentsEngine envEngine;
@@ -298,7 +300,7 @@ public class StepsTenantIsolation {
@SuppressWarnings("unchecked")
@Then("^trying to create Ueb keys (.*)$")
public void trying_to_create_ueb_keys(boolean isActivated) throws Throwable {
- verify(envEngine, Mockito.times(getNumberOfCallsToValidate(isActivated)))
+ verify(envEngine, Mockito.times(getNumberOfCallsToValidate(isActivated) + 1))
.createUebKeys(Mockito.any(Wrapper.class), Mockito.any(OperationalEnvironmentEntry.class));
}