From 2854651c23702c857ce006ee8eac5126774f66f7 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Wed, 3 Apr 2024 12:37:42 +0530 Subject: [PATCH 1/4] Improvements for the reporting data publishing (cherry picked from commit 6c1286ebad915273a860ac5e61685abce82bffdf) --- ...ApplicationManagerProviderServiceImpl.java | 8 +- .../impl/DeviceInformationManagerImpl.java | 14 ++-- .../report/mgt/ReportingPublisherManager.java | 82 +++++++++++++++++++ .../mgt/core/util/HttpReportingUtil.java | 19 +---- 4 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 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 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 fec70931a4..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 @@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.device.mgt.core.app.mgt; import com.google.gson.Gson; +import io.entgra.device.mgt.core.device.mgt.core.report.mgt.ReportingPublisherManager; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -286,8 +287,11 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem deviceDetailsWrapper.setTenantId(tenantId); deviceDetailsWrapper.setDevice(device); deviceDetailsWrapper.setApplications(newApplications); - HttpReportingUtil.invokeApi(deviceDetailsWrapper.getJSONString(), - reportingHost + DeviceManagementConstants.Report.APP_USAGE_ENDPOINT); + 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/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 d3681a43c4..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 @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.impl; +import io.entgra.device.mgt.core.device.mgt.core.report.mgt.ReportingPublisherManager; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -29,7 +30,6 @@ import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceDetailsW import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceInfo; import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceLocation; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.EventPublishingException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; @@ -203,7 +203,8 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { getDeviceManagementProvider().getDevice(deviceIdentifier, false); DeviceDetailsWrapper deviceDetailsWrapper = new DeviceDetailsWrapper(); deviceDetailsWrapper.setEvents(payload); - return publishEvents(device, deviceDetailsWrapper, eventType); + publishEvents(device, deviceDetailsWrapper, eventType); + return 201; } catch (DeviceManagementException e) { DeviceManagementDAOFactory.rollbackTransaction(); String msg = "Event publishing error. Could not get device " + deviceId; @@ -217,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 int publishEvents(Device device, DeviceDetailsWrapper deviceDetailsWrapper, String + private void publishEvents(Device device, DeviceDetailsWrapper deviceDetailsWrapper, String eventType) { String reportingHost = HttpReportingUtil.getReportingHost(); if (!StringUtils.isBlank(reportingHost) @@ -252,9 +253,9 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { String eventUrl = reportingHost + DeviceManagementConstants.Report .REPORTING_CONTEXT + DeviceManagementConstants.URL_SEPERATOR + eventType; - return HttpReportingUtil.invokeApi(deviceDetailsWrapper.getJSONString(), eventUrl); - } catch (EventPublishingException e) { - log.error("Error occurred while sending events", e); + ReportingPublisherManager reportingManager = new ReportingPublisherManager(); + 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) { @@ -270,7 +271,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { + DeviceManagerUtil.getTenantId()); } } - return 0; } @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 new file mode 100644 index 0000000000..3e72aab7f5 --- /dev/null +++ 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 @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.device.mgt.core.report.mgt; + +import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceDetailsWrapper; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.EventPublishingException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpResponse; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; +import org.apache.http.protocol.HTTP; + +import java.io.IOException; +import java.net.ConnectException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +public class ReportingPublisherManager { + + private static final Log log = LogFactory.getLog(ReportingPublisherManager.class); + private final static ExecutorService executorService; + private DeviceDetailsWrapper payload; + private String endpoint; + private static final PoolingHttpClientConnectionManager poolingManager; + + static { + executorService = Executors.newFixedThreadPool(10); //todo make this configurable + poolingManager = new PoolingHttpClientConnectionManager(); + poolingManager.setMaxTotal(10); //todo make this configurable + poolingManager.setDefaultMaxPerRoute(10); + } + + public void publishData(DeviceDetailsWrapper deviceDetailsWrapper, String eventUrl) { + this.payload = deviceDetailsWrapper; + this.endpoint = eventUrl; + executorService.submit(new ReportingPublisher()); + } + + private class ReportingPublisher implements Runnable { + @Override + 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()); + StringEntity requestEntity = new StringEntity(payload.getJSONString(), ContentType.APPLICATION_JSON); + apiEndpoint.setEntity(requestEntity); + HttpResponse response = client.execute(apiEndpoint); + int statusCode = response.getStatusLine().getStatusCode(); + if (log.isDebugEnabled()) { + log.debug("Published data to the reporting backend: " + endpoint + ", Response code: " + statusCode); + } + } catch (ConnectException e) { + String message = "Connection refused while publishing reporting data to the API: " + endpoint; + log.error(message, e); + } catch (IOException e) { + String message = "Error occurred when publishing reporting data to the API: " + endpoint; + log.error(message, 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/util/HttpReportingUtil.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/util/HttpReportingUtil.java index 288d0c0fc5..ad7a7bf67d 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/util/HttpReportingUtil.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/util/HttpReportingUtil.java @@ -27,6 +27,7 @@ import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; import org.apache.http.protocol.HTTP; import org.json.JSONObject; import io.entgra.device.mgt.core.device.mgt.common.exceptions.EventPublishingException; @@ -49,24 +50,6 @@ public class HttpReportingUtil { return System.getProperty(DeviceManagementConstants.Report.REPORTING_EVENT_HOST); } - public static int invokeApi(String payload, String endpoint) throws EventPublishingException { - try (CloseableHttpClient client = HttpClients.createDefault()) { - HttpPost apiEndpoint = new HttpPost(endpoint); - apiEndpoint.setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); - StringEntity requestEntity = new StringEntity( - payload, ContentType.APPLICATION_JSON); - apiEndpoint.setEntity(requestEntity); - HttpResponse response = client.execute(apiEndpoint); - return response.getStatusLine().getStatusCode(); - } catch (ConnectException e) { - log.error("Connection refused to API endpoint: " + endpoint, e); - return HttpStatus.SC_SERVICE_UNAVAILABLE; - } catch (IOException e) { - throw new EventPublishingException("Error occurred when " + - "invoking API. API endpoint: " + endpoint, e); - } - } - public static boolean isPublishingEnabledForTenant() { Object configuration = DeviceManagerUtil.getConfiguration(IS_EVENT_PUBLISHING_ENABLED); -- 2.36.3 From d97f45940726e9c4107a07a56573a8c79fe8325c Mon Sep 17 00:00:00 2001 From: Pahansith Date: Fri, 5 Apr 2024 09:56:04 +0530 Subject: [PATCH 2/4] Make the executor Callable and retrieve the response (cherry picked from commit b74dc5796b2d391b33952ec07f84b9f8b6743fa4) --- ...ApplicationManagerProviderServiceImpl.java | 2 -- .../details/mgt/DeviceInformationManager.java | 1 - .../impl/DeviceInformationManagerImpl.java | 32 ++++++++++++++++--- .../report/mgt/ReportingPublisherManager.java | 13 +++++--- 4 files changed, 36 insertions(+), 12 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 7fa3959d26..368157ca48 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,8 +290,6 @@ 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 fdf98a86a5..911fafdd59 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,7 +107,6 @@ 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 e210526a19..0facad3b30 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,6 +54,8 @@ 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 { @@ -86,6 +88,7 @@ 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(); @@ -203,13 +206,32 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { getDeviceManagementProvider().getDevice(deviceIdentifier, false); DeviceDetailsWrapper deviceDetailsWrapper = new DeviceDetailsWrapper(); deviceDetailsWrapper.setEvents(payload); - publishEvents(device, deviceDetailsWrapper, eventType); - return 201; + 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. } 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); } } @@ -218,7 +240,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { * @param device Device that is sending event * @param deviceDetailsWrapper Payload to send(example, deviceinfo, applist, raw events) */ - private void publishEvents(Device device, DeviceDetailsWrapper deviceDetailsWrapper, String + private Future publishEvents(Device device, DeviceDetailsWrapper deviceDetailsWrapper, String eventType) { String reportingHost = HttpReportingUtil.getReportingHost(); if (!StringUtils.isBlank(reportingHost) @@ -254,8 +276,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { String eventUrl = reportingHost + DeviceManagementConstants.Report .REPORTING_CONTEXT + DeviceManagementConstants.URL_SEPERATOR + eventType; ReportingPublisherManager reportingManager = new ReportingPublisherManager(); - reportingManager.publishData(deviceDetailsWrapper, eventUrl); - //return HttpReportingUtil.invokeApi(deviceDetailsWrapper.getJSONString(), eventUrl); + return reportingManager.publishData(deviceDetailsWrapper, eventUrl); } catch (GroupManagementException e) { log.error("Error occurred while getting group list", e); } catch (UserStoreException e) { @@ -271,6 +292,7 @@ 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 3e72aab7f5..b6e3bf5ae1 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,8 +33,10 @@ 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 { @@ -51,15 +53,15 @@ public class ReportingPublisherManager { poolingManager.setDefaultMaxPerRoute(10); } - public void publishData(DeviceDetailsWrapper deviceDetailsWrapper, String eventUrl) { + public Future publishData(DeviceDetailsWrapper deviceDetailsWrapper, String eventUrl) { this.payload = deviceDetailsWrapper; this.endpoint = eventUrl; - executorService.submit(new ReportingPublisher()); + return executorService.submit(new ReportingPublisher()); } - private class ReportingPublisher implements Runnable { + private class ReportingPublisher implements Callable { @Override - public void run() { + public Integer call() throws EventPublishingException { try (CloseableHttpClient client = HttpClients.custom().setConnectionManager(poolingManager).build()) { HttpPost apiEndpoint = new HttpPost(endpoint); apiEndpoint.setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()); @@ -70,12 +72,15 @@ 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); } } } -- 2.36.3 From d57be2c00c950f4b7a97062ac7ae256f43a0e88e Mon Sep 17 00:00:00 2001 From: Pahansith Date: Fri, 5 Apr 2024 10:19:26 +0530 Subject: [PATCH 3/4] Change debug enabled check for performance optimization --- .../device/details/mgt/impl/DeviceInformationManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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..9846b85419 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 @@ -208,8 +208,9 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { deviceDetailsWrapper.setEvents(payload); Future apiCallback = publishEvents(device, deviceDetailsWrapper, eventType); if (null != apiCallback) { + boolean isDebugEnabled = log.isDebugEnabled(); while(!apiCallback.isDone()) { - if (log.isDebugEnabled()) { + if (isDebugEnabled) { log.debug("Waiting for the response from the API for the reporting data " + "publishing for the device " + deviceId + ". Event payload: " + payload); } -- 2.36.3 From 7686716cc10a6a63290ad586bc39502d127df9fb Mon Sep 17 00:00:00 2001 From: Pahansith Date: Fri, 5 Apr 2024 10:28:08 +0530 Subject: [PATCH 4/4] Add missing method doc comment --- .../mgt/core/device/details/mgt/DeviceInformationManager.java | 1 + .../device/details/mgt/impl/DeviceInformationManagerImpl.java | 1 + 2 files changed, 2 insertions(+) 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 9846b85419..f298db68d4 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 @@ -224,6 +224,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { log.error(msg, e); throw new DeviceDetailsMgtException(msg, e); } catch (ExecutionException e) { + //Exceptions thrown in ReportingPublisherManager will be wrapped under this exception String message = "Failed while publishing device information data to the reporting service for the device " + deviceId; log.error(message, e); -- 2.36.3