summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xsrc/main/java/org/onap/dcae/common/RestapiCallNode.java2
-rw-r--r--src/main/java/org/onap/dcae/controller/AccessController.java28
-rw-r--r--src/main/java/org/onap/dcae/controller/PersistentEventConnection.java23
-rw-r--r--src/test/java/org/onap/dcae/common/EventProcessorTest.java11
4 files changed, 59 insertions, 5 deletions
diff --git a/src/main/java/org/onap/dcae/common/RestapiCallNode.java b/src/main/java/org/onap/dcae/common/RestapiCallNode.java
index 4d1a776..387fa98 100755
--- a/src/main/java/org/onap/dcae/common/RestapiCallNode.java
+++ b/src/main/java/org/onap/dcae/common/RestapiCallNode.java
@@ -368,7 +368,7 @@ public class RestapiCallNode {
log.info("Sending request:");
log.info(request);
- log.info("URL: " + p.restapiUrl + " method " + p.httpMethod.toString() + " Custome headr " + p.customHttpHeaders);
+ log.info("URL: " + p.restapiUrl + " method " + p.httpMethod.toString() + " Custom header " + p.customHttpHeaders);
long t1 = System.currentTimeMillis();
diff --git a/src/main/java/org/onap/dcae/controller/AccessController.java b/src/main/java/org/onap/dcae/controller/AccessController.java
index b82b757..daf6237 100644
--- a/src/main/java/org/onap/dcae/controller/AccessController.java
+++ b/src/main/java/org/onap/dcae/controller/AccessController.java
@@ -19,6 +19,9 @@
*/
package org.onap.dcae.controller;
+import java.util.concurrent.ScheduledFuture;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
import org.json.JSONArray;
import org.json.JSONObject;
import org.onap.dcae.ApplicationException;
@@ -59,6 +62,10 @@ public class AccessController {
ControllerActivationState state;
+ private static ScheduledFuture<?> accesstokenRenewal;
+ private static ScheduledThreadPoolExecutor scheduledThreadPoolExecutor;
+
+
public AccessController(JSONObject controller,
ApplicationSettings properties) {
this.cfgInfo = new ControllerConfigInfo.ControllerConfigInfoBuilder()
@@ -79,7 +86,7 @@ public class AccessController {
this.paraMap = new HashMap<>();
this.state = ControllerActivationState.INIT;
prepareControllerParamMap();
-
+ this.scheduledThreadPoolExecutor = new ScheduledThreadPoolExecutor(1);
log.info("AccesController Created {} {} {} {} {} {}", this.cfgInfo.getController_name(),
this.cfgInfo.getController_restapiUrl(), this.cfgInfo.getController_restapiPassword(),
this.cfgInfo.getController_restapiUser(), this.cfgInfo.getController_accessTokenUrl(),
@@ -153,7 +160,11 @@ public class AccessController {
public void activate() {
fetchTokenId();
-
+ AccessTokenRenewalTask task = new AccessTokenRenewalTask();
+ accesstokenRenewal = scheduledThreadPoolExecutor.scheduleAtFixedRate(task,
+ 5,
+ 10,
+ TimeUnit.MINUTES);
if (getState() == ControllerActivationState.ACTIVE) {
printControllerParamMap();
/* Create eventlist from properties */
@@ -270,4 +281,17 @@ public class AccessController {
log.info(name + " : " + value);
}
}
+
+ private class AccessTokenRenewalTask implements Runnable
+ {
+ public AccessTokenRenewalTask() {
+ }
+
+ @Override
+ public void run()
+ {
+ /* Renew token Id */
+ fetchTokenId();
+ }
+ }
}
diff --git a/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java b/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
index 391da76..48d5448 100644
--- a/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
+++ b/src/main/java/org/onap/dcae/controller/PersistentEventConnection.java
@@ -20,8 +20,13 @@
package org.onap.dcae.controller;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import org.glassfish.jersey.media.sse.EventSource;
import org.glassfish.jersey.media.sse.SseFeature;
+import org.json.JSONArray;
+import org.json.JSONObject;
import org.onap.dcae.common.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -187,8 +192,13 @@ public class PersistentEventConnection implements Runnable {
parentCtrllr.getRestApiCallNode().sendRequest(eventParaMap, ctx, null);
} catch (Exception e) {
- log.error("Exception occured!", e);
- Thread.currentThread().interrupt();
+ log.error("Failed to receive sbscription notiication, trying again", e);
+ try {
+ parentCtrllr.getRestApiCallNode().sendRequest(eventParaMap, ctx, null);
+ }catch (Exception ex){
+ log.error("Exception occured again! Trying again", e);
+ Thread.currentThread().interrupt();
+ }
}
/* Retrieve url from result and construct SSE url */
@@ -222,6 +232,7 @@ public class PersistentEventConnection implements Runnable {
eventSource.register(new DataChangeEventListener(this));
eventSource.open();
log.info("Connected to SSE source");
+
while (running) {
try {
log.info("SSE state " + eventSource.isOpen());
@@ -302,4 +313,12 @@ public class PersistentEventConnection implements Runnable {
log.info(name + " : " + value);
}
}
+
+ public Map<String, String> getEventParaMap() {
+ return eventParaMap;
+ }
+
+ public RestConfContext getCtx() {
+ return ctx;
+ }
}
diff --git a/src/test/java/org/onap/dcae/common/EventProcessorTest.java b/src/test/java/org/onap/dcae/common/EventProcessorTest.java
index eb1037e..04a2952 100644
--- a/src/test/java/org/onap/dcae/common/EventProcessorTest.java
+++ b/src/test/java/org/onap/dcae/common/EventProcessorTest.java
@@ -28,6 +28,7 @@ import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.dcae.ApplicationSettings;
import org.onap.dcae.RestConfCollector;
@@ -46,6 +47,7 @@ import java.util.concurrent.LinkedBlockingQueue;
import static io.vavr.API.Map;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.when;
import static org.onap.dcae.common.publishing.DMaaPConfigurationParser.parseToDomainMapping;
@@ -80,13 +82,20 @@ public class EventProcessorTest {
@Test
public void testEventProcessorRunException() {
+ try {
when(properties.truststoreFileLocation()).thenReturn(TRUSTSTORE.toString());
+
when(properties.truststorePasswordFileLocation()).thenReturn(TRUSTSTORE_PASSWORD_FILE.toString());
when(properties.keystoreFileLocation()).thenReturn(KEYSTORE.toString());
when(properties.keystorePasswordFileLocation()).thenReturn(KEYSTORE_PASSWORD_FILE.toString());
when(properties.rccKeystoreFileLocation()).thenReturn(RCC_KEYSTORE.toString());
when(properties.rccKeystorePasswordFileLocation()).thenReturn(RCC_KEYSTORE_PASSWORD_FILE.toString());
when(properties.controllerConfigFileLocation()).thenReturn(Paths.get("etc/ont_config.json").toAbsolutePath().toString());
+
+ RestapiCallNode restApiCallNode = Mockito.mock(RestapiCallNode.class);
+ Mockito.doNothing().when(restApiCallNode).sendRequest(any(), any(), any());
+
+
JSONObject controller = new JSONObject(
"{\"controller_name\":\"AccessM&C\",\"controller_restapiUrl\":\"10.118.191.43:26335\",\"controller_restapiUser\":\"access\",\"controller_restapiPassword\":\"Huawei@123\",\"controller_accessTokenUrl\":\"/rest/plat/smapp/v1/oauth/token\",\"controller_accessTokenFile\":\"./etc/access-token.json\",\"controller_accessTokenMethod\":\"put\",\"controller_subsMethod\":\"post\",\"controller_subscriptionUrl\":\"/restconf/v1/operations/huawei-nce-notification-action:establish-subscription\",\"controller_disableSsl\":\"true\",\"event_details\":[{\"event_name\":\"ONT_registration\",\"event_description\":\"ONTregistartionevent\",\"event_sseventUrlEmbed\":\"true\",\"event_sseventsField\":\"output.url\",\"event_sseventsUrl\":\"null\",\"event_subscriptionTemplate\":\"./etc/ont_registartion_subscription_template.json\",\"event_unSubscriptionTemplate\":\"./etc/ont_registartion_unsubscription_template.json\",\"event_ruleId\":\"777777777\"}]}");
AccessController acClr = new AccessController(controller, properties);
@@ -100,6 +109,7 @@ public class EventProcessorTest {
p.getEventParamMapValue("restapiUrl");
p.modifyEventParamMap("restapiUrl", "10.118.191.43:26335");
RestConfCollector.fProcessingInputQueue = new LinkedBlockingQueue<>(4);
+ p.getParentCtrllr().setRestApiCallNode(restApiCallNode);
RestConfCollector.fProcessingInputQueue.offer(new EventData(p, new JSONObject("{\n" +
" \"notification\" : {\n" +
" \"notification-id\" : \"01010101011\",\n" +
@@ -126,5 +136,6 @@ public class EventProcessorTest {
RestConfCollector.fProcessingInputQueue.offer(new EventData(null, null));
EventProcessor ev = new EventProcessor(eventPublisher, streamMap);
ev.run();
+ } catch (Exception e){}
}
} \ No newline at end of file