summaryrefslogtreecommitdiffstats
path: root/catalog-be/src
diff options
context:
space:
mode:
Diffstat (limited to 'catalog-be/src')
-rw-r--r--catalog-be/src/main/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealth.java62
-rw-r--r--catalog-be/src/test/java/org/openecomp/sdc/be/components/distribution/engine/DistributionEngineClusterHealthTest.java289
2 files changed, 171 insertions, 180 deletions
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 0851f22c0a..9eb0141209 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
@@ -32,6 +32,8 @@ import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.PreDestroy;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
import org.openecomp.sdc.be.config.BeEcompErrorManager;
import org.openecomp.sdc.be.config.ConfigurationManager;
import org.openecomp.sdc.be.config.DistributionEngineConfiguration;
@@ -65,7 +67,7 @@ public class DistributionEngineClusterHealth {
private HealthCheckInfo healthCheckInfo = HealthCheckInfoResult.UNKNOWN.getHealthCheckInfo();
private Map<String, AtomicBoolean> envNamePerStatus = null;
private ScheduledFuture<?> scheduledFuture = null;
-
+
protected void init(final String publicApiKey) {
logger.trace("Enter init method of DistributionEngineClusterHealth");
Long reconnectIntervalConfig = ConfigurationManager.getConfigurationManager().getConfiguration()
@@ -153,40 +155,28 @@ public class DistributionEngineClusterHealth {
}
}
- public enum HealthCheckInfoResult {
- OK(new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.UP, null,
- ClusterStatusDescription.OK.getDescription())), UNAVAILABLE(
- new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null,
- ClusterStatusDescription.UNAVAILABLE.getDescription())), NOT_CONFIGURED(
- new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null,
- ClusterStatusDescription.NOT_CONFIGURED.getDescription())), DISABLED(
- new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null,
- ClusterStatusDescription.DISABLED.getDescription())), UNKNOWN(
- new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.UNKNOWN, null,
- ClusterStatusDescription.UNKNOWN.getDescription()));
- private HealthCheckInfo healthCheckInfo;
-
- HealthCheckInfoResult(HealthCheckInfo healthCheckInfo) {
- this.healthCheckInfo = healthCheckInfo;
- }
-
- public HealthCheckInfo getHealthCheckInfo() {
- return healthCheckInfo;
- }
+ @AllArgsConstructor
+ @Getter
+ private enum HealthCheckInfoResult {
+ // @formatter:off
+ OK (new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.UP, null, ClusterStatusDescription.OK.getDescription())),
+ UNAVAILABLE (new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.UNAVAILABLE.getDescription())),
+ NOT_CONFIGURED (new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.NOT_CONFIGURED.getDescription())),
+ DISABLED (new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.DOWN, null, ClusterStatusDescription.DISABLED.getDescription())),
+ UNKNOWN (new HealthCheckInfo(Constants.HC_COMPONENT_DISTRIBUTION_ENGINE, HealthCheckStatus.UNKNOWN, null, ClusterStatusDescription.UNKNOWN.getDescription()));
+ // @formatter:on
+ private final HealthCheckInfo healthCheckInfo;
}
- public enum ClusterStatusDescription {
- OK("OK"), UNAVAILABLE("U-EB cluster is not available"), NOT_CONFIGURED("U-EB cluster is not configured"), DISABLED(
- "DE is disabled in configuration"), UNKNOWN("U-EB cluster is currently unknown (try again in few minutes)");
- private String desc;
-
- ClusterStatusDescription(String desc) {
- this.desc = desc;
- }
-
- public String getDescription() {
- return desc;
- }
+ @AllArgsConstructor
+ @Getter
+ private enum ClusterStatusDescription {
+ OK("OK"),
+ UNAVAILABLE("U-EB cluster is not available"),
+ NOT_CONFIGURED("U-EB cluster is not configured"),
+ DISABLED("DE is disabled in configuration"),
+ UNKNOWN("U-EB cluster is currently unknown (try again in few minutes)");
+ private final String description;
}
/**
@@ -199,11 +189,12 @@ public class DistributionEngineClusterHealth {
*/
public class HealthCheckScheduledTask implements Runnable {
+ @Getter
List<UebHealthCheckCall> healthCheckCalls = new ArrayList<>();
/**
* executor for the query itself
*/
- ExecutorService healthCheckExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
+ private final ExecutorService healthCheckExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {
@Override
public Thread newThread(Runnable r) {
return new Thread(r, "UEB-Health-Check-Thread");
@@ -298,8 +289,5 @@ public class DistributionEngineClusterHealth {
return result;
}
- public List<UebHealthCheckCall> getHealthCheckCalls() {
- return healthCheckCalls;
- }
}
}
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 5f2b412743..7997814a95 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
@@ -7,9 +7,9 @@
* 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.
@@ -20,150 +20,153 @@
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 java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicBoolean;
import mockit.Deencapsulation;
-import org.junit.Test;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.openecomp.sdc.be.components.BeConfDependentTest;
import org.openecomp.sdc.be.components.distribution.engine.DistributionEngineClusterHealth.HealthCheckScheduledTask;
import org.openecomp.sdc.common.api.HealthCheckInfo;
-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{
-
- private DistributionEngineClusterHealth createTestSubject() {
- return new DistributionEngineClusterHealth();
- }
-
- @Test
- public void testDestroy() throws Exception {
- DistributionEngineClusterHealth testSubject;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "destroy");
- }
-
- @Test
- public void testStartHealthCheckTask() throws Exception {
- DistributionEngineClusterHealth testSubject;
- Map<String, AtomicBoolean> envNamePerStatus = null;
- boolean startTask = false;
-
- // default test
- testSubject = createTestSubject();
- testSubject.startHealthCheckTask(envNamePerStatus, startTask);
- }
-
- @Test
- public void testStartHealthCheckTask_1() {
- final DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
- final Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
- distributionEngineClusterHealth.init("myKey");
- distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
- }
-
- @Test
- public void testHealthCheckScheduledTask() throws Exception {
- DistributionEngineClusterHealth testSubject;
- Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
-
- // default test
- testSubject = createTestSubject();
- HealthCheckScheduledTask healthCheckScheduledTask = testSubject. new HealthCheckScheduledTask(new LinkedList<>());
- LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
- UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
- healthCheckCalls.add(hcc);
- healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
-
- Deencapsulation.invoke(healthCheckScheduledTask, "queryUeb");
- }
-
- @Test
- public void testHealthCheckScheduledTaskRun() throws Exception {
- DistributionEngineClusterHealth testSubject;
- Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
- envNamePerStatus.put("mock", new AtomicBoolean(true));
- // default test
- testSubject = createTestSubject();
- testSubject.startHealthCheckTask(envNamePerStatus, false);
- HealthCheckScheduledTask healthCheckScheduledTask = testSubject. new HealthCheckScheduledTask(new LinkedList<>());
- LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
- UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
- healthCheckCalls.add(hcc);
- healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
-
- Deencapsulation.invoke(healthCheckScheduledTask, "run");
- }
-
- @Test
- public void testHealthCheckScheduledTaskRun_2() throws Exception {
- DistributionEngineClusterHealth testSubject;
- Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
- envNamePerStatus.put("mock", new AtomicBoolean(false));
- // default test
- testSubject = createTestSubject();
- testSubject.startHealthCheckTask(envNamePerStatus, false);
- HealthCheckScheduledTask healthCheckScheduledTask = testSubject. new HealthCheckScheduledTask(new LinkedList<>());
- LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
- UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
- healthCheckCalls.add(hcc);
- healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
-
- Deencapsulation.invoke(healthCheckScheduledTask, "run");
- }
-
- @Test
- public void testLogAlarm() throws Exception {
- DistributionEngineClusterHealth testSubject;
- boolean lastHealthState = false;
-
- // default test
- testSubject = createTestSubject();
- Deencapsulation.invoke(testSubject, "logAlarm", new Object[] { lastHealthState });
- }
-
- @Test
- public void testGetHealthCheckInfo() throws Exception {
- DistributionEngineClusterHealth testSubject;
- HealthCheckInfo result;
-
- // default test
- testSubject = createTestSubject();
- result = testSubject.getHealthCheckInfo();
- }
-
- @Test
- public void testSetHealthCheckUebIsDisabled() throws Exception {
- DistributionEngineClusterHealth testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setHealthCheckUebIsDisabled();
- }
-
- @Test
- public void testSetHealthCheckUebConfigurationError() throws Exception {
- DistributionEngineClusterHealth testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setHealthCheckUebConfigurationError();
- }
-
- @Test
- public void testSetHealthCheckOkAndReportInCaseLastStateIsDown() throws Exception {
- DistributionEngineClusterHealth testSubject;
-
- // default test
- testSubject = createTestSubject();
- testSubject.setHealthCheckOkAndReportInCaseLastStateIsDown();
- }
+class DistributionEngineClusterHealthTest extends BeConfDependentTest {
+
+ private DistributionEngineClusterHealth createTestSubject() {
+ return new DistributionEngineClusterHealth();
+ }
+
+ // TODO - move to BeConfDependentTest after migration to Junit 5
+ @BeforeAll
+ public static void setupBeforeClass() {
+ componentName = "catalog-be";
+ confPath = "src/test/resources/config";
+ setUp();
+ }
+
+ @Test
+ void testDestroy() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ Deencapsulation.invoke(testSubject, "destroy");
+ }
+
+ @Test
+ void testStartHealthCheckTask() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+ Map<String, AtomicBoolean> envNamePerStatus = null;
+ boolean startTask = false;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.startHealthCheckTask(envNamePerStatus, startTask);
+ }
+
+ @Test
+ void testStartHealthCheckTask_1() {
+ final DistributionEngineClusterHealth distributionEngineClusterHealth = new DistributionEngineClusterHealth();
+ final Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
+ distributionEngineClusterHealth.init("myKey");
+ distributionEngineClusterHealth.startHealthCheckTask(envNamePerStatus);
+ }
+
+ @Test
+ void testHealthCheckScheduledTask() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+ Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
+
+ // default test
+ testSubject = createTestSubject();
+ HealthCheckScheduledTask healthCheckScheduledTask = testSubject.new HealthCheckScheduledTask(new LinkedList<>());
+ LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
+ UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
+ healthCheckCalls.add(hcc);
+ healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
+
+ Deencapsulation.invoke(healthCheckScheduledTask, "queryUeb");
+ }
+
+ @Test
+ void testHealthCheckScheduledTaskRun() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+ Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
+ envNamePerStatus.put("mock", new AtomicBoolean(true));
+ // default test
+ testSubject = createTestSubject();
+ testSubject.startHealthCheckTask(envNamePerStatus, false);
+ HealthCheckScheduledTask healthCheckScheduledTask = testSubject.new HealthCheckScheduledTask(new LinkedList<>());
+ LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
+ UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
+ healthCheckCalls.add(hcc);
+ healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
+
+ Deencapsulation.invoke(healthCheckScheduledTask, "run");
+ }
+
+ @Test
+ void testHealthCheckScheduledTaskRun_2() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+ Map<String, AtomicBoolean> envNamePerStatus = new HashMap<>();
+ envNamePerStatus.put("mock", new AtomicBoolean(false));
+ // default test
+ testSubject = createTestSubject();
+ testSubject.startHealthCheckTask(envNamePerStatus, false);
+ HealthCheckScheduledTask healthCheckScheduledTask = testSubject.new HealthCheckScheduledTask(new LinkedList<>());
+ LinkedList<UebHealthCheckCall> healthCheckCalls = new LinkedList<>();
+ UebHealthCheckCall hcc = new UebHealthCheckCall("mock", "mock");
+ healthCheckCalls.add(hcc);
+ healthCheckScheduledTask.healthCheckCalls = healthCheckCalls;
+
+ Deencapsulation.invoke(healthCheckScheduledTask, "run");
+ }
+
+ @Test
+ void testLogAlarm() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+ boolean lastHealthState = false;
+
+ // default test
+ testSubject = createTestSubject();
+ Deencapsulation.invoke(testSubject, "logAlarm", new Object[]{lastHealthState});
+ }
+
+ @Test
+ void testGetHealthCheckInfo() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+ HealthCheckInfo result;
+
+ // default test
+ testSubject = createTestSubject();
+ result = testSubject.getHealthCheckInfo();
+ }
+
+ @Test
+ void testSetHealthCheckUebIsDisabled() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setHealthCheckUebIsDisabled();
+ }
+
+ @Test
+ void testSetHealthCheckUebConfigurationError() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setHealthCheckUebConfigurationError();
+ }
+
+ @Test
+ void testSetHealthCheckOkAndReportInCaseLastStateIsDown() throws Exception {
+ DistributionEngineClusterHealth testSubject;
+
+ // default test
+ testSubject = createTestSubject();
+ testSubject.setHealthCheckOkAndReportInCaseLastStateIsDown();
+ }
}