summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-05-16 08:54:54 +0200
committerFiete Ostkamp <Fiete.Ostkamp@telekom.de>2024-05-16 08:59:11 +0200
commitc4208db72297836601e1e4a579b60f96960bbdf3 (patch)
treeade19694865508d2089e3d0bdee85ae9953867a4 /src
parenta61b2948f9cbe25d0ec6cd957671d51d83c62a1a (diff)
Stop sdc-distribution-client upon service shutdown
- restore old behaviour by calling distributionClient.stop() - downgrade sdc-distribution-client version to 2.0.0 Issue-ID: AAI-3848 Change-Id: Id252f4d8e387a916dcbdebd5110b46432858ee6b Signed-off-by: Fiete Ostkamp <Fiete.Ostkamp@telekom.de>
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java24
-rw-r--r--src/test/java/org/onap/aai/modelloader/config/DistributionClientStartupConfigTest.java62
2 files changed, 79 insertions, 7 deletions
diff --git a/src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java b/src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java
index cd9d919..937c62d 100644
--- a/src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java
+++ b/src/main/java/org/onap/aai/modelloader/config/DistributionClientStartupConfig.java
@@ -23,6 +23,8 @@ import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
+import javax.annotation.PreDestroy;
+
import org.onap.aai.cl.api.Logger;
import org.onap.aai.cl.eelf.LoggerFactory;
import org.onap.aai.modelloader.notification.EventCallback;
@@ -42,13 +44,13 @@ public class DistributionClientStartupConfig {
private static final Logger logger = LoggerFactory.getInstance().getLogger(DistributionClientStartupConfig.class);
- private final IDistributionClient client;
+ private final IDistributionClient distributionClient;
private final ModelLoaderConfig config;
private final EventCallback eventCallback;
- public DistributionClientStartupConfig(IDistributionClient client, ModelLoaderConfig config,
+ public DistributionClientStartupConfig(IDistributionClient distributionClient, ModelLoaderConfig config,
EventCallback eventCallback) {
- this.client = client;
+ this.distributionClient = distributionClient;
this.config = config;
this.eventCallback = eventCallback;
}
@@ -58,12 +60,12 @@ public class DistributionClientStartupConfig {
// Initialize distribution client
logger.debug(ModelLoaderMsgs.INITIALIZING, "Initializing distribution client...");
IDistributionClientResult initResult = null;
- initResult = client.init(config, eventCallback);
+ initResult = distributionClient.init(config, eventCallback);
if (initResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
// Start distribution client
logger.debug(ModelLoaderMsgs.INITIALIZING, "Starting distribution client...");
- IDistributionClientResult startResult = client.start();
+ IDistributionClientResult startResult = distributionClient.start();
if (startResult.getDistributionActionResult() == DistributionActionResultEnum.SUCCESS) {
logger.info(ModelLoaderMsgs.INITIALIZING, "Connection to SDC established");
} else {
@@ -72,7 +74,7 @@ public class DistributionClientStartupConfig {
// Kick off a timer to retry the SDC connection
Timer timer = new Timer();
- TimerTask task = new SdcConnectionJob(client, config, eventCallback, timer);
+ TimerTask task = new SdcConnectionJob(distributionClient, config, eventCallback, timer);
timer.schedule(task, new Date(), 60000);
}
} else {
@@ -81,8 +83,16 @@ public class DistributionClientStartupConfig {
// Kick off a timer to retry the SDC connection
Timer timer = new Timer();
- TimerTask task = new SdcConnectionJob(client, config, eventCallback, timer);
+ TimerTask task = new SdcConnectionJob(distributionClient, config, eventCallback, timer);
timer.schedule(task, new Date(), 60000);
}
}
+
+ @PreDestroy
+ public void destroy() {
+ logger.info(ModelLoaderMsgs.STOPPING_CLIENT);
+ if (distributionClient != null) {
+ distributionClient.stop();
+ }
+ }
}
diff --git a/src/test/java/org/onap/aai/modelloader/config/DistributionClientStartupConfigTest.java b/src/test/java/org/onap/aai/modelloader/config/DistributionClientStartupConfigTest.java
new file mode 100644
index 0000000..4dbdddb
--- /dev/null
+++ b/src/test/java/org/onap/aai/modelloader/config/DistributionClientStartupConfigTest.java
@@ -0,0 +1,62 @@
+/**
+ * ============LICENSE_START=======================================================
+ * org.onap.aai
+ * ================================================================================
+ * Copyright © 2024 Deutsche Telekom AG 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.aai.modelloader.config;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.onap.aai.modelloader.notification.EventCallback;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class DistributionClientStartupConfigTest {
+
+ @Mock IDistributionClient distributionClient;
+ @Mock ModelLoaderConfig config;
+ @Mock EventCallback eventCallback;
+ @InjectMocks DistributionClientStartupConfig startupConfig;
+
+ @Test
+ public void thatClientIsInitialized() {
+ IDistributionClientResult initResult = mock(IDistributionClientResult.class);
+ when(distributionClient.init(any(), any())).thenReturn(initResult);
+ when(distributionClient.start()).thenReturn(initResult);
+ when(initResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS);
+ startupConfig.initSdcClient();
+ verify(distributionClient, times(1)).init(any(), any());
+ verify(distributionClient, times(1)).start();
+ }
+
+ @Test
+ public void thatClientIsStoppedOnPreDestroy() {
+ startupConfig.destroy();
+ verify(distributionClient, times(1)).stop();
+ }
+
+}