summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src
diff options
context:
space:
mode:
authorayalaben <ayala.benzvi@amdocs.com>2018-05-27 13:54:38 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-05-29 06:31:15 +0000
commit34771f3e531e26d179e5ba77b987befe4035b38e (patch)
treec66f86f80c5c044363f151b46d2bcac66e268dad /openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src
parentb145c0825c0bd163a0a2643aeee4c8b283e35ada (diff)
Catalog notification port
Change-Id: I714ac047c98551ddf29ca509811265bfd7c66f24 Issue-ID: SDC-1257 Signed-off-by: ayalaben <ayala.benzvi@amdocs.com>
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/CatalogNotifier.java55
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java9
2 files changed, 38 insertions, 26 deletions
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 f19de3d04a..4f2b7aed63 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
@@ -30,6 +30,7 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
@@ -44,15 +45,18 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdc.logging.api.LoggingContext;
import org.openecomp.sdcrests.item.types.ItemAction;
-public class CatalogNotifier {
+ class CatalogNotifier {
private static final Logger LOGGER = LoggerFactory.getLogger(CatalogNotifier.class);
private static final String USER_ID_HEADER_PARAM = "USER_ID";
private static final String CONFIG_FILE = "configuration.yaml";
private static final String PROTOCOL_KEY = "beProtocol";
+ private static final String HTTP_PROTOCOL = "http|HTTP";
+ private static final String HTTPS_PROTOCOL = "https|HTTPS";
private static final String HOST_KEY = "beFqdn";
- private static final String PORT_KEY = "beHttpPort";
+ private static final String HTTP_PORT_KEY = "beHttpPort";
+ private static final String HTTPS_PORT_KEY = "beSslPort";
private static final String URL_KEY = "onboardCatalogNotificationUrl";
private static final String URL_DEFAULT_FORMAT = "%s://%s:%s/sdc2/rest/v1/catalog/notif/vsp/";
@@ -60,7 +64,6 @@ public class CatalogNotifier {
private static String notifyCatalogUrl;
private static ScheduledExecutorService executor = Executors.newScheduledThreadPool(1);
- private static boolean executeNotificationFlag = true;
static {
@@ -75,11 +78,17 @@ public class CatalogNotifier {
configurationMap = readFromFile(configurationYamlFile, reader);
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) {
+ throw new ExceptionInInitializerError("Could not read configuration file configuration.yaml.");
+ }
+
+ Object port = null;
+ if (String.valueOf(protocol).matches(HTTP_PROTOCOL)) {
+ port = configurationMap.get(HTTP_PORT_KEY);
+ }
+ if (String.valueOf(protocol).matches(HTTPS_PROTOCOL)) {
+ port = configurationMap.get(HTTPS_PORT_KEY);
}
if (configurationMap.get(URL_KEY) != null) {
@@ -93,22 +102,20 @@ public class CatalogNotifier {
}
} catch (Exception e) {
- LOGGER.error("Could not read configuration file configuration.yaml");
- executeNotificationFlag = false;
+ throw new ExceptionInInitializerError(
+ "Could not read configuration file configuration.yaml. Error: " + e.getMessage());
+
}
}
public void execute(Collection<String> itemIds, ItemAction action, int numOfRetries) {
- if (executeNotificationFlag) {
-
- String userId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId();
+ String userId = SessionContextProviderFactory.getInstance().createInterface().get().getUser().getUserId();
- Callable callable = createCallable(JsonUtil.object2Json(itemIds), action, numOfRetries, userId);
+ Callable callable = createCallable(JsonUtil.object2Json(itemIds), action, numOfRetries, userId);
- executor.submit(callable);
- }
+ executor.submit(callable);
}
@@ -121,22 +128,22 @@ public class CatalogNotifier {
private Void handleHttpRequest(String url, String itemIds, ItemAction action, String userId,
int numOfRetries) {
- try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
+ try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
HttpPost request = createPostRequest(url, itemIds, userId);
HttpResponse response = httpclient.execute(request);
- LOGGER.error(
- String.format("Catalog notification on vspId - %s action - %s. Response: %s", itemIds,
- action.name(), response.getStatusLine()));
+ LOGGER.debug(String.format("Catalog notification on vspId - %s action - %s. Response: %s", itemIds,
+ action.name(), response.getStatusLine()));
- if (numOfRetries > 1 && response.getStatusLine().getStatusCode() == 500) {
+ if (numOfRetries > 1 && response.getStatusLine().getStatusCode() == Response.Status.INTERNAL_SERVER_ERROR
+ .getStatusCode()) {
Callable callable =
createCallable(getFailedIds(itemIds, response.getEntity()), action, --numOfRetries, userId);
- executor.schedule(callable, 5 , TimeUnit.SECONDS);
+ executor.schedule(callable, 5, TimeUnit.SECONDS);
}
} catch (Exception e) {
- LOGGER.error(String.format("Catalog notification on vspId - %s action - %s FAILED. Error: %S",
- itemIds.toString(), action.name(), e.getMessage()));
+ LOGGER.error(String.format("Catalog notification on vspId - %s action - %s FAILED. Error: %S", itemIds,
+ action.name(), e.getMessage()));
}
return null;
}
@@ -173,7 +180,7 @@ public class CatalogNotifier {
} else if (action == ItemAction.RESTORE) {
actionStr = "restored";
}
- LOGGER.error("Catalog notification on URL - " + notifyCatalogUrl + actionStr);
+ LOGGER.debug("Catalog notification URL - " + notifyCatalogUrl + actionStr);
return notifyCatalogUrl + actionStr;
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java
index 359662ad33..afdac0ad61 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/ItemsImpl.java
@@ -86,7 +86,7 @@ public class ItemsImpl implements Items {
private NotificationPropagationManager notifier =
NotificationPropagationManagerFactory.getInstance().createInterface();
- private CatalogNotifier catalogNotifier = new CatalogNotifier();
+
private Map<ItemAction, ActionSideAffects> actionSideAffectsMap = new EnumMap<>(ItemAction.class);
@@ -120,7 +120,12 @@ public class ItemsImpl implements Items {
}
actionSideAffectsMap.get(request.getAction()).execute(item, user);
- catalogNotifier.execute(Collections.singleton(itemId),request.getAction(),2);
+ try {
+ CatalogNotifier catalogNotifier = new CatalogNotifier();
+ catalogNotifier.execute(Collections.singleton(itemId), request.getAction(), 2);
+ } catch (Exception e){
+ LOGGER.error("Failed to send catalog notification on item " + itemId + " Error: " + e.getMessage());
+ }
return Response.ok().build();
}