From 70a3309f5e3e531981691e08d74cf89fa832c2a4 Mon Sep 17 00:00:00 2001 From: ayalaben Date: Mon, 7 May 2018 14:01:00 +0300 Subject: notify catalog on items action Change-Id: I11aa241c0c74c1a426dc1eee30ec7adb09abdca4 Issue-ID: SDC-1257 Signed-off-by: ayalaben --- .../item/rest/services/CatalogNotifier.java | 45 ++++++++++++---------- 1 file changed, 25 insertions(+), 20 deletions(-) (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest') diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/CatalogNotifier.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/CatalogNotifier.java index 48a4f9c3b6..f19de3d04a 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/CatalogNotifier.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/CatalogNotifier.java @@ -60,6 +60,7 @@ public class CatalogNotifier { private static String notifyCatalogUrl; private static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1); + private static boolean executeNotificationFlag = true; static { @@ -72,38 +73,42 @@ public class CatalogNotifier { try { configurationMap = readFromFile(configurationYamlFile, reader); + Object protocol = configurationMap.get(PROTOCOL_KEY); + Object host = configurationMap.get(HOST_KEY); + Object port = configurationMap.get(PORT_KEY); - } catch (IOException e) { - throw new RuntimeException("Could not read configuration file configuration.yaml"); - } - - Object protocol = configurationMap.get(PROTOCOL_KEY); - Object host = configurationMap.get(HOST_KEY); - Object port = configurationMap.get(PORT_KEY); + if (protocol == null || host == null || port == null) { + LOGGER.error("Could not read configuration file configuration.yaml"); + executeNotificationFlag = false; + } - if (protocol == null || host == null || port == null) { - throw new RuntimeException("Could not read configuration file configuration.yaml"); - } + if (configurationMap.get(URL_KEY) != null) { + String urlFormat = String.valueOf(configurationMap.get(URL_KEY)); + notifyCatalogUrl = + String.format(urlFormat, String.valueOf(protocol), String.valueOf(host), String.valueOf(port)); - if (configurationMap.get(URL_KEY) != null) { - String urlFormat = String.valueOf(configurationMap.get(URL_KEY)); - notifyCatalogUrl = - String.format(urlFormat, String.valueOf(protocol), String.valueOf(host), String.valueOf(port)); + } else { + notifyCatalogUrl = String.format(URL_DEFAULT_FORMAT, String.valueOf(protocol), String.valueOf(host), + String.valueOf(port)); + } - } else { - notifyCatalogUrl = String.format(URL_DEFAULT_FORMAT, String.valueOf(protocol), String.valueOf(host), - String.valueOf(port)); + } catch (Exception e) { + LOGGER.error("Could not read configuration file configuration.yaml"); + executeNotificationFlag = false; } } public void execute(Collection itemIds, ItemAction action, int numOfRetries) { - String userId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId(); + if (executeNotificationFlag) { - Callable callable = createCallable(JsonUtil.object2Json(itemIds), action, numOfRetries, userId); + String userId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId(); - executor.submit(callable); + Callable callable = createCallable(JsonUtil.object2Json(itemIds), action, numOfRetries, userId); + + executor.submit(callable); + } } -- cgit 1.2.3-korg