aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2021-03-22 15:33:06 +0000
committerChristophe Closset <christophe.closset@intl.att.com>2021-03-24 06:59:47 +0000
commitd378c37fbd1ecec7b43394926f1ca32a695e07de (patch)
tree5c8a085f8732f980d871d966ac49361644efa698 /openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http
parenta6ae7294ecd336d7e88f915710b08e2658eaee00 (diff)
Reformat openecomp-be
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Issue-ID: SDC-3449 Change-Id: I13e02322f8e00820cc5a1d85752caaeda9bf10d1
Diffstat (limited to 'openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http')
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpConfiguration.java1
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java31
-rw-r--r--openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java27
3 files changed, 14 insertions, 45 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/catalog/notification/http/HttpConfiguration.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpConfiguration.java
index 4403bd840b..e10cd5d8c3 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpConfiguration.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpConfiguration.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdcrests.item.rest.services.catalog.notification.http;
import lombok.AllArgsConstructor;
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java
index c88ac4ecce..1904bb5072 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpNotificationTask.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdcrests.item.rest.services.catalog.notification.http;
import static org.openecomp.sdcrests.item.rest.services.catalog.notification.AsyncNotifier.NextAction.DONE;
@@ -42,8 +41,8 @@ import org.openecomp.sdc.logging.api.LoggerFactory;
import org.openecomp.sdcrests.item.rest.services.catalog.notification.AsyncNotifier;
/**
- * HTTP client for notifying the Catalog of an action on items. The items are referenced by their IDs. The client can
- * run multiple times, in which case only failed IDs will be re-attempted.
+ * HTTP client for notifying the Catalog of an action on items. The items are referenced by their IDs. The client can run multiple times, in which
+ * case only failed IDs will be re-attempted.
*
* @author evitaliy
* @since 21 Nov 2018
@@ -52,10 +51,8 @@ import org.openecomp.sdcrests.item.rest.services.catalog.notification.AsyncNotif
class HttpNotificationTask implements Callable<AsyncNotifier.NextAction> {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpNotificationTask.class);
-
private static final String APPLICATION_JSON = ContentType.APPLICATION_JSON.getMimeType();
private static final String USER_ID_HEADER_PARAM = "USER_ID";
-
private final String endpoint;
private final String userId;
private volatile Collection<String> itemIds;
@@ -68,59 +65,41 @@ class HttpNotificationTask implements Callable<AsyncNotifier.NextAction> {
@Override
public synchronized AsyncNotifier.NextAction call() {
-
try (CloseableHttpClient client = HttpClients.createDefault()) {
-
HttpPost request = createPostRequest(endpoint, itemIds, userId);
-
try (CloseableHttpResponse response = client.execute(request)) {
-
StatusLine status = response.getStatusLine();
-
- LOGGER.debug("Catalog notification on VSP IDs: {}, endpoint: {}, response: {}",
- itemIds, endpoint, status);
-
+ LOGGER.debug("Catalog notification on VSP IDs: {}, endpoint: {}, response: {}", itemIds, endpoint, status);
itemIds = getFailedIds(itemIds, response.getEntity());
-
- if ((status.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR)
- && (itemIds != null) && !itemIds.isEmpty()) {
-
+ if ((status.getStatusCode() == HttpStatus.SC_INTERNAL_SERVER_ERROR) && (itemIds != null) && !itemIds.isEmpty()) {
LOGGER.debug("Catalog notification on VSP IDs {} failed. Endpoint: {}. Retry", itemIds, endpoint);
return RETRY;
}
-
return DONE;
}
-
} catch (Exception e) {
LOGGER.error("Catalog notification on VSP IDs {} failed. Endpoint: {}", itemIds, endpoint, e);
return DONE;
}
}
- private HttpPost createPostRequest(String postUrl, Collection<String> itemIds, String userId)
- throws UnsupportedEncodingException {
-
+ private HttpPost createPostRequest(String postUrl, Collection<String> itemIds, String userId) throws UnsupportedEncodingException {
HttpPost request = new HttpPost(postUrl);
-
request.addHeader(HttpHeaders.ACCEPT, APPLICATION_JSON);
request.addHeader(HttpHeaders.CONTENT_TYPE, APPLICATION_JSON);
request.addHeader(USER_ID_HEADER_PARAM, userId);
-
HttpEntity entity = new StringEntity(JsonUtil.object2Json(itemIds));
request.setEntity(entity);
return request;
}
private Collection<String> getFailedIds(Collection<String> itemIds, HttpEntity responseBody) {
-
try {
NotificationResponse response = JsonUtil.json2Object(responseBody.getContent(), NotificationResponse.class);
return response != null ? response.failedIds : null;
} catch (Exception e) {
LOGGER.error("Error getting failed IDs from response", e);
}
-
return itemIds;
}
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java
index d210dc21af..694aa9241c 100644
--- a/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java
+++ b/openecomp-be/api/openecomp-sdc-rest-webapp/item-rest/item-rest-services/src/main/java/org/openecomp/sdcrests/item/rest/services/catalog/notification/http/HttpTaskProducer.java
@@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
package org.openecomp.sdcrests.item.rest.services.catalog.notification.http;
import java.util.Collection;
@@ -35,11 +34,9 @@ import org.openecomp.sdcrests.item.types.ItemAction;
* @author evitaliy
* @since 21 Nov 2018
*/
-public class HttpTaskProducer
- implements BiFunction<Collection<String>, ItemAction, Callable<AsyncNotifier.NextAction>>, Notifier {
+public class HttpTaskProducer implements BiFunction<Collection<String>, ItemAction, Callable<AsyncNotifier.NextAction>>, Notifier {
private static final Logger LOGGER = LoggerFactory.getLogger(HttpTaskProducer.class);
-
private static final String CATALOG_HTTP_PROTOCOL = "HTTP";
private static final String CATALOG_HTTPS_PROTOCOL = "HTTPS";
private static final Map<ItemAction, String> ACTION_PATHS;
@@ -66,16 +63,13 @@ public class HttpTaskProducer
}
private static String ensureEntryConfigured(String value, String entryName) {
-
if (value == null) {
throw new EntryNotConfiguredException(entryName);
}
-
return value;
}
private static String getPortConfiguration(String protocol, HttpConfiguration config) {
-
if (CATALOG_HTTP_PROTOCOL.equalsIgnoreCase(protocol)) {
return ensureEntryConfigured(config.getCatalogBeHttpPort(), "HTTP port");
} else if (CATALOG_HTTPS_PROTOCOL.equalsIgnoreCase(protocol)) {
@@ -85,6 +79,14 @@ public class HttpTaskProducer
}
}
+ static String getApiPath(ItemAction action) {
+ String path = ACTION_PATHS.get(action);
+ if (path == null) {
+ throw new IllegalArgumentException("Unsupported action: " + action.name());
+ }
+ return path;
+ }
+
@Override
public Callable<AsyncNotifier.NextAction> apply(Collection<String> itemIds, ItemAction action) {
return createNotificationTask(itemIds, action);
@@ -97,20 +99,9 @@ public class HttpTaskProducer
return new HttpNotificationTask(notificationEndpoint, userId, itemIds);
}
- static String getApiPath(ItemAction action) {
-
- String path = ACTION_PATHS.get(action);
- if (path == null) {
- throw new IllegalArgumentException("Unsupported action: " + action.name());
- }
-
- return path;
- }
-
@Override
public void execute(Collection<String> itemIds, ItemAction action) {
HttpNotificationTask task = createNotificationTask(itemIds, action);
task.call();
}
-
}