From 0071e1369297e57ad8f4706d655cbfb11f27b6b3 Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Fri, 5 Apr 2024 04:28:15 +0000 Subject: [PATCH] revert b74dc5796b2d391b33952ec07f84b9f8b6743fa4 revert Make the executor Callable and retrieve the response --- ...ApplicationManagerProviderServiceImpl.java | 2 ++ .../details/mgt/DeviceInformationManager.java | 1 + .../impl/DeviceInformationManagerImpl.java | 32 +++---------------- .../report/mgt/ReportingPublisherManager.java | 13 +++----- 4 files changed, 12 insertions(+), 36 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java index 368157ca48..7fa3959d26 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/app/mgt/ApplicationManagerProviderServiceImpl.java @@ -290,6 +290,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem ReportingPublisherManager reportingManager = new ReportingPublisherManager(); reportingManager.publishData(deviceDetailsWrapper, DeviceManagementConstants .Report.APP_USAGE_ENDPOINT); + /*HttpReportingUtil.invokeApi(deviceDetailsWrapper.getJSONString(), + reportingHost + DeviceManagementConstants.Report.APP_USAGE_ENDPOINT);*/ } } catch (DeviceManagementDAOException e) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/DeviceInformationManager.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/DeviceInformationManager.java index 911fafdd59..fdf98a86a5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/DeviceInformationManager.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/DeviceInformationManager.java @@ -107,6 +107,7 @@ public interface DeviceInformationManager { * @param deviceType device type of an device * @param payload payload of the event * @param eventType Event type being sent + * @return Http status code if a call is made and if failed to make a call 0 * @throws DeviceDetailsMgtException */ int publishEvents(String deviceId, String deviceType, String payload, String eventType) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index 0facad3b30..e210526a19 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -54,8 +54,6 @@ import java.util.Calendar; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; public class DeviceInformationManagerImpl implements DeviceInformationManager { @@ -88,7 +86,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { DeviceDetailsWrapper deviceDetailsWrapper = new DeviceDetailsWrapper(); deviceDetailsWrapper.setDeviceInfo(deviceInfo); - //Asynchronous call to publish the device information to the reporting service. Hence, response is ignored. publishEvents(device, deviceDetailsWrapper, DeviceManagementConstants.Report.DEVICE_INFO_PARAM); DeviceManagementDAOFactory.beginTransaction(); @@ -206,32 +203,13 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { getDeviceManagementProvider().getDevice(deviceIdentifier, false); DeviceDetailsWrapper deviceDetailsWrapper = new DeviceDetailsWrapper(); deviceDetailsWrapper.setEvents(payload); - Future apiCallback = publishEvents(device, deviceDetailsWrapper, eventType); - if (null != apiCallback) { - while(!apiCallback.isDone()) { - if (log.isDebugEnabled()) { - log.debug("Waiting for the response from the API for the reporting data " + - "publishing for the device " + deviceId + ". Event payload: " + payload); - } - } - return apiCallback.get(); - } - return 0; // If the event publishing is disabled. + publishEvents(device, deviceDetailsWrapper, eventType); + return 201; } catch (DeviceManagementException e) { DeviceManagementDAOFactory.rollbackTransaction(); String msg = "Event publishing error. Could not get device " + deviceId; log.error(msg, e); throw new DeviceDetailsMgtException(msg, e); - } catch (ExecutionException e) { - String message = "Failed while publishing device information data to the reporting service for the device " - + deviceId; - log.error(message, e); - throw new DeviceDetailsMgtException(message, e); - } catch (InterruptedException e) { - String message = "Failed while publishing device information data to the reporting service. Thread " + - "interrupted while waiting for the response from the API for the Device " + deviceId; - log.error(message, e); - throw new DeviceDetailsMgtException(message, e); } } @@ -240,7 +218,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { * @param device Device that is sending event * @param deviceDetailsWrapper Payload to send(example, deviceinfo, applist, raw events) */ - private Future publishEvents(Device device, DeviceDetailsWrapper deviceDetailsWrapper, String + private void publishEvents(Device device, DeviceDetailsWrapper deviceDetailsWrapper, String eventType) { String reportingHost = HttpReportingUtil.getReportingHost(); if (!StringUtils.isBlank(reportingHost) @@ -276,7 +254,8 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { String eventUrl = reportingHost + DeviceManagementConstants.Report .REPORTING_CONTEXT + DeviceManagementConstants.URL_SEPERATOR + eventType; ReportingPublisherManager reportingManager = new ReportingPublisherManager(); - return reportingManager.publishData(deviceDetailsWrapper, eventUrl); + reportingManager.publishData(deviceDetailsWrapper, eventUrl); + //return HttpReportingUtil.invokeApi(deviceDetailsWrapper.getJSONString(), eventUrl); } catch (GroupManagementException e) { log.error("Error occurred while getting group list", e); } catch (UserStoreException e) { @@ -292,7 +271,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { + DeviceManagerUtil.getTenantId()); } } - return null; } @Override diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/report/mgt/ReportingPublisherManager.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/report/mgt/ReportingPublisherManager.java index b6e3bf5ae1..3e72aab7f5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/report/mgt/ReportingPublisherManager.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/report/mgt/ReportingPublisherManager.java @@ -33,10 +33,8 @@ import org.apache.http.protocol.HTTP; import java.io.IOException; import java.net.ConnectException; -import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.util.concurrent.Future; public class ReportingPublisherManager { @@ -53,15 +51,15 @@ public class ReportingPublisherManager { poolingManager.setDefaultMaxPerRoute(10); } - public Future publishData(DeviceDetailsWrapper deviceDetailsWrapper, String eventUrl) { + public void publishData(DeviceDetailsWrapper deviceDetailsWrapper, String eventUrl) { this.payload = deviceDetailsWrapper; this.endpoint = eventUrl; - return executorService.submit(new ReportingPublisher()); + executorService.submit(new ReportingPublisher()); } - private class ReportingPublisher implements Callable { + private class ReportingPublisher implements Runnable { @Override - public Integer call() throws EventPublishingException { + public void run() { try (CloseableHttpClient client = HttpClients.custom().setConnectionManager(poolingManager).build()) { HttpPost apiEndpoint = new HttpPost(endpoint); apiEndpoint.setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); @@ -72,15 +70,12 @@ public class ReportingPublisherManager { if (log.isDebugEnabled()) { log.debug("Published data to the reporting backend: " + endpoint + ", Response code: " + statusCode); } - return statusCode; } catch (ConnectException e) { String message = "Connection refused while publishing reporting data to the API: " + endpoint; log.error(message, e); - throw new EventPublishingException(message, e); } catch (IOException e) { String message = "Error occurred when publishing reporting data to the API: " + endpoint; log.error(message, e); - throw new EventPublishingException(message, e); } } }