diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml index a4c2ac4585..564673ef8b 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml index d9627dd4c6..1ba9a75dd3 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml index 1023761e3d..56aacfa64d 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/pom.xml b/components/analytics-mgt/grafana-mgt/pom.xml index 5e099a5446..e48aeca1f7 100644 --- a/components/analytics-mgt/grafana-mgt/pom.xml +++ b/components/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/pom.xml b/components/analytics-mgt/pom.xml index 226f71a281..ded09a6876 100644 --- a/components/analytics-mgt/pom.xml +++ b/components/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml index a2e6d02ffd..0918920bdc 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index 3f29d8f5db..a064c551c1 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -21,7 +21,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml index 1db14c86db..9ebf10c38f 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml index 97835e7c80..95be718e7a 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT 4.0.0 diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml index f748dad9a9..6c7db5b264 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 24fa878e3b..81aea0503d 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index daf70f8841..a2c8ece854 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml index ef34a74787..a67eb8592f 100644 --- a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml @@ -20,7 +20,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.api/pom.xml index 5b4ce2177a..4f42850568 100644 --- a/components/application-mgt/io.entgra.application.mgt.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.common/pom.xml b/components/application-mgt/io.entgra.application.mgt.common/pom.xml index 729c04a0ea..2e058b82dd 100644 --- a/components/application-mgt/io.entgra.application.mgt.common/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.common/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.core/pom.xml b/components/application-mgt/io.entgra.application.mgt.core/pom.xml index a888a0bdf4..e93b704269 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.core/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java index 9ad0b9d4c0..bfce4e31fa 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java @@ -94,6 +94,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { || StringUtils.isNotEmpty(filter.getAppReleaseType())) { sql += "LEFT JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "; } + sql += "WHERE AP_APP.TENANT_ID = ? "; if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) { sql += "AND AP_APP.TYPE = ? "; } @@ -128,7 +129,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { sql += filter.getSortBy() +" "; } if (filter.getLimit() != -1) { - sql += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY "; + sql += "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY "; } sql += ") AS app_data ON app_data.ID = AP_APP.ID " + "LEFT JOIN (" @@ -145,6 +146,7 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { Connection conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndex = 1; + stmt.setInt(paramIndex++, tenantId); if (StringUtils.isNotEmpty(filter.getAppType()) && !Constants.ALL.equalsIgnoreCase(filter.getAppType())) { stmt.setString(paramIndex++, filter.getAppType()); } diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml index 8883120c43..adddc4026a 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml index 8d638df716..ff4e816abc 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index 0ead8b8a9b..dfb1d48017 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 9713c4ea12..f70a1fa72c 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml index 7c18184715..a5a16ab3c6 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index 0e9b4a4ed8..fdd5660b81 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -38,7 +38,7 @@ org.wso2.carbon.devicemgt certificate-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 941d82d456..99af2f9561 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml index 50d7f13304..e36b58f55e 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml @@ -23,7 +23,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml index 7584058970..475c8b4e6e 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml index e618a386bd..229e8d6e3e 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml @@ -23,7 +23,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index 899044e147..9a11f603e7 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml index b9534c9c9c..7625a603b3 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml index adcb08c877..ec894c7900 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml index 204498ea3c..2e107b2543 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index ec4d7cb47b..1cde061ac1 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index f80fcbeb1e..3fdd250307 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index fec507492f..d141f2ff6f 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml index 95bb7c668b..2c0ea76ceb 100644 --- a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml +++ b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index b49c7a0299..aca43d379e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index 3b686fe6e3..1abb0dca0c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index ef94adce4a..a55ae5faff 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml @@ -103,6 +103,7 @@ org.wso2.carbon.ndatasource.core, org.wso2.carbon.ntask.core.*, org.wso2.carbon.ntask.common, + io.entgra.task.mgt.common.*, org.apache.commons.collections;version="${commons-collections.version.range}", org.wso2.carbon.email.sender.*, io.swagger.annotations.*;resolution:=optional, @@ -347,6 +348,10 @@ okhttp compile + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.common + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index 585074894d..b293798ba2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -409,7 +409,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { } if (!HttpReportingUtil.isTrackerEnabled()) { if (log.isDebugEnabled()) { - log.info("Traccar is disabled"); + log.debug("Traccar is disabled"); } } } @@ -473,7 +473,7 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { } if (!HttpReportingUtil.isTrackerEnabled()) { if (log.isDebugEnabled()) { - log.info("Traccar is disabled"); + log.debug("Traccar is disabled"); } } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/timeout/task/impl/OperationTimeoutTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/timeout/task/impl/OperationTimeoutTask.java index 2ee7e32032..c1bd71a2a5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/timeout/task/impl/OperationTimeoutTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/timeout/task/impl/OperationTimeoutTask.java @@ -32,31 +32,10 @@ import org.wso2.carbon.device.mgt.core.task.impl.DynamicPartitionedScheduleTask; import java.util.ArrayList; import java.util.List; -import java.util.Map; public class OperationTimeoutTask extends DynamicPartitionedScheduleTask { private static final Log log = LogFactory.getLog(OperationTimeoutTask.class); - private OperationTimeout operationTimeoutConfig; - - @Override - public void setProperties(Map properties) { - super.setProperties(properties); - String operationTimeoutTaskConfigStr = properties - .get(OperationTimeoutTaskManagerServiceImpl.OPERATION_TIMEOUT_TASK_CONFIG); - Gson gson = new Gson(); - operationTimeoutConfig = gson.fromJson(operationTimeoutTaskConfigStr, OperationTimeout.class); - } - - @Override - public String getProperty(String name) { - return super.getProperty(name); - } - - @Override - public void refreshContext() { - super.refreshContext(); - } @Override protected void setup() { @@ -65,12 +44,15 @@ public class OperationTimeoutTask extends DynamicPartitionedScheduleTask { @Override protected void executeDynamicTask() { + String operationTimeoutTaskConfigStr = getProperty( + OperationTimeoutTaskManagerServiceImpl.OPERATION_TIMEOUT_TASK_CONFIG); + Gson gson = new Gson(); + OperationTimeout operationTimeoutConfig = gson.fromJson(operationTimeoutTaskConfigStr, OperationTimeout.class); try { - long timeMillis = System.currentTimeMillis() - operationTimeoutConfig.getTimeout() * 60 * 1000; List deviceTypes = new ArrayList<>(); if (operationTimeoutConfig.getDeviceTypes().size() == 1 && - "ALL".equals(operationTimeoutConfig.getDeviceTypes().get( 0))) { + "ALL".equals(operationTimeoutConfig.getDeviceTypes().get(0))) { try { List deviceTypeList = DeviceManagementDataHolder.getInstance() .getDeviceManagementProvider().getDeviceTypes(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 7bb7e7c627..9b28775687 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -444,7 +444,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv //Exception was not thrown due to being conflicted with non-traccar features } } else { - log.info("Traccar is disabled"); + if (log.isDebugEnabled()) { + log.debug("Traccar is disabled"); + } } //enroll Traccar device @@ -544,7 +546,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv //Exception was not thrown due to being conflicted with non-traccar features } } else { - log.info("Traccar is disabled"); + if (log.isDebugEnabled()) { + log.debug("Traccar is disabled"); + } } //enroll Traccar device return status; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java index 5182fc3651..9d2e1ee7ce 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/status/task/impl/DeviceStatusMonitoringTask.java @@ -37,7 +37,6 @@ import org.wso2.carbon.device.mgt.core.task.impl.DynamicPartitionedScheduleTask; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; -import java.util.Map; /** * This implements the Task service which monitors the device activity periodically & update the device-status if @@ -47,19 +46,8 @@ public class DeviceStatusMonitoringTask extends DynamicPartitionedScheduleTask { private static final Log log = LogFactory.getLog(DeviceStatusMonitoringTask.class); private String deviceType; - private DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig; private int deviceTypeId = -1; - @Override - public void setProperties(Map properties) { - super.setProperties(properties); - deviceType = properties.get(DeviceStatusTaskManagerServiceImpl.DEVICE_TYPE); - deviceTypeId = Integer.parseInt(properties.get(DeviceStatusTaskManagerServiceImpl.DEVICE_TYPE_ID)); - String deviceStatusTaskConfigStr = properties.get(DeviceStatusTaskManagerServiceImpl.DEVICE_STATUS_TASK_CONFIG); - Gson gson = new Gson(); - deviceStatusTaskPluginConfig = gson.fromJson(deviceStatusTaskConfigStr, DeviceStatusTaskPluginConfig.class); - } - @Override protected void setup() { } @@ -92,6 +80,11 @@ public class DeviceStatusMonitoringTask extends DynamicPartitionedScheduleTask { @Override public void executeDynamicTask() { + deviceType = getProperty(DeviceStatusTaskManagerServiceImpl.DEVICE_TYPE); + deviceTypeId = Integer.parseInt(getProperty(DeviceStatusTaskManagerServiceImpl.DEVICE_TYPE_ID)); + String deviceStatusTaskConfigStr = getProperty(DeviceStatusTaskManagerServiceImpl.DEVICE_STATUS_TASK_CONFIG); + Gson gson = new Gson(); + DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig = gson.fromJson(deviceStatusTaskConfigStr, DeviceStatusTaskPluginConfig.class); try { List enrolmentInfoTobeUpdated = new ArrayList<>(); List allDevicesForMonitoring = getAllDevicesForMonitoring(); @@ -102,10 +95,10 @@ public class DeviceStatusMonitoringTask extends DynamicPartitionedScheduleTask { EnrolmentInfo enrolmentInfo = monitoringData.getDevice().getEnrolmentInfo(); EnrolmentInfo.Status status = null; - if (lastUpdatedTime >= this.deviceStatusTaskPluginConfig + if (lastUpdatedTime >= deviceStatusTaskPluginConfig .getIdleTimeToMarkInactive()) { status = EnrolmentInfo.Status.INACTIVE; - } else if (lastUpdatedTime >= this.deviceStatusTaskPluginConfig + } else if (lastUpdatedTime >= deviceStatusTaskPluginConfig .getIdleTimeToMarkUnreachable()) { status = EnrolmentInfo.Status.UNREACHABLE; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index 0c6f77c15d..a13031eabb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -48,7 +48,6 @@ import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; import java.util.List; -import java.util.Map; public class DeviceDetailsRetrieverTask extends DynamicPartitionedScheduleTask { @@ -56,14 +55,9 @@ public class DeviceDetailsRetrieverTask extends DynamicPartitionedScheduleTask { private String deviceType; private DeviceManagementProviderService deviceManagementProviderService; - @Override - public void setProperties(Map map) { - super.setProperties(map); - deviceType = map.get("DEVICE_TYPE"); - } - @Override public void executeDynamicTask() { + deviceType = getProperty("DEVICE_TYPE"); deviceManagementProviderService = DeviceManagementDataHolder.getInstance() .getDeviceManagementProvider(); OperationMonitoringTaskConfig operationMonitoringTaskConfig = deviceManagementProviderService diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DynamicPartitionedScheduleTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DynamicPartitionedScheduleTask.java index 0bbb59d2bd..ad3269be00 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DynamicPartitionedScheduleTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DynamicPartitionedScheduleTask.java @@ -19,10 +19,11 @@ package org.wso2.carbon.device.mgt.core.task.impl; import io.entgra.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException; +import io.entgra.task.mgt.common.constant.TaskMgtConstants; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.device.mgt.common.ServerCtxInfo; import org.wso2.carbon.device.mgt.common.DynamicTaskContext; +import org.wso2.carbon.device.mgt.common.ServerCtxInfo; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; import org.wso2.carbon.ntask.core.Task; @@ -37,11 +38,11 @@ public abstract class DynamicPartitionedScheduleTask implements Task { private Map properties; @Override - public void setProperties(Map properties) { + public final void setProperties(Map properties) { this.properties = properties; } - public String getProperty(String name) { + public final String getProperty(String name) { if (properties == null) { return null; } @@ -62,7 +63,7 @@ public abstract class DynamicPartitionedScheduleTask implements Task { } } } catch (HeartBeatManagementException e) { - log.error("Error Instantiating Variables necessary for Dynamic Task Scheduling. Dynamic Tasks will not function." , e); + log.error("Error Instantiating Variables necessary for Dynamic Task Scheduling. Dynamic Tasks will not function.", e); } setup(); } @@ -70,11 +71,41 @@ public abstract class DynamicPartitionedScheduleTask implements Task { @Override public final void execute() { refreshContext(); - executeDynamicTask(); + if (taskContext != null && taskContext.isPartitioningEnabled()) { + String localHashIndex = getProperty(TaskMgtConstants.Task.LOCAL_HASH_INDEX); + // These tasks are not dynamically scheduled. They are added via a config so scheduled in each node + // during the server startup + if (localHashIndex == null ) { + if (log.isDebugEnabled()) { + log.debug("Executing startup scheduled task (" + getTaskName() + ") with class: " + + this.getClass().getName()); + } + executeDynamicTask(); + return; + } + if (localHashIndex.equals(String.valueOf(taskContext.getServerHashIndex()))) { + if (log.isDebugEnabled()) { + log.debug("Executing dynamically scheduled task (" + getTaskName() + + ") for current server hash index: " + localHashIndex); + } + executeDynamicTask(); + } else { + if (log.isDebugEnabled()) { + log.debug("Ignoring execution of task (" + getTaskName() + + ") not belonging to current serer hash index: " + localHashIndex); + } + } + } else { + executeDynamicTask(); + } + } + + public String getTaskName() { + return getProperty(TaskMgtConstants.Task.LOCAL_TASK_NAME); } - public void refreshContext(){ - if(taskContext != null && taskContext.isPartitioningEnabled()) { + public void refreshContext() { + if (taskContext != null && taskContext.isPartitioningEnabled()) { try { updateContext(); } catch (HeartBeatManagementException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index a1e6a0b4e4..c359b575ef 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml index 9ba77c4ad9..ce0834d4a7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml @@ -23,7 +23,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index 436a192834..d21057f7c5 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml index 5a489fb74e..b77baba84f 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heartbeat-management - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/dto/ElectedCandidate.java b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/dto/ElectedCandidate.java index a3920d362b..99bfa8eba9 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/dto/ElectedCandidate.java +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/src/main/java/io/entgra/server/bootup/heartbeat/beacon/dto/ElectedCandidate.java @@ -19,13 +19,14 @@ package io.entgra.server.bootup.heartbeat.beacon.dto; import java.sql.Timestamp; +import java.util.ArrayList; import java.util.List; public class ElectedCandidate { private String serverUUID; private Timestamp timeOfElection; - private List acknowledgedTaskList = null; + private List acknowledgedTaskList = new ArrayList<>(); public List getAcknowledgedTaskList() { return acknowledgedTaskList; diff --git a/components/heartbeat-management/pom.xml b/components/heartbeat-management/pom.xml index 22913f50e2..8a34ff769a 100644 --- a/components/heartbeat-management/pom.xml +++ b/components/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml index 700239506b..15ce3a51ca 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml index 507cea2e64..7c963d6254 100644 --- a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml index 586de2b47c..b1bdcdf8e3 100644 --- a/components/identity-extensions/pom.xml +++ b/components/identity-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml index 609d10008f..d8c8483db2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml index b02dbd7da2..0dd2f16187 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index bca206470b..d13c9bb1ec 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 96a877190f..6991bb4e5f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index bf5ec91c3d..2f0a6b7bf6 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/task-mgt/pom.xml b/components/task-mgt/pom.xml new file mode 100755 index 0000000000..d9ab379c3b --- /dev/null +++ b/components/task-mgt/pom.xml @@ -0,0 +1,41 @@ + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 5.0.20-SNAPSHOT + ../../pom.xml + + + 4.0.0 + task-mgt + pom + Entgra IoT - Task Management Component + http://entgra.io + + + task-manager + task-watcher + + + \ No newline at end of file diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml new file mode 100755 index 0000000000..ad7c991872 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml @@ -0,0 +1,56 @@ + + + + + task-manager + org.wso2.carbon.devicemgt + 5.0.20-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.task.mgt.common + bundle + Entgra IoT - Task Management Common + Entgra IoT - Task Management Common + https://entgra.io + + + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Task Management Common Bundle + + io.entgra.task.mgt.common.* + + + + + + + \ No newline at end of file diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/bean/DynamicTask.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/bean/DynamicTask.java new file mode 100755 index 0000000000..ece8d4dc26 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/bean/DynamicTask.java @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.bean; + +import java.util.Map; + +public class DynamicTask { + + private int dynamicTaskId; + private String name; + private String cronExpression; + private boolean isEnabled; + private int tenantId; + private String taskClassName; + private Map properties; + + public int getDynamicTaskId() { + return dynamicTaskId; + } + + public void setDynamicTaskId(int dynamicTaskId) { + this.dynamicTaskId = dynamicTaskId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getCronExpression() { + return cronExpression; + } + + public void setCronExpression(String cronExpression) { + this.cronExpression = cronExpression; + } + + public boolean isEnabled() { + return isEnabled; + } + + public void setEnabled(boolean enable) { + isEnabled = enable; + } + + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + public String getTaskClassName() { + return taskClassName; + } + + public void setTaskClassName(String taskClassName) { + this.taskClassName = taskClassName; + } + + public Map getProperties() { + return properties; + } + + public void setProperties(Map properties) { + this.properties = properties; + } + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/constant/TaskMgtConstants.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/constant/TaskMgtConstants.java new file mode 100755 index 0000000000..2ffe960964 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/constant/TaskMgtConstants.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.constant; + +public class TaskMgtConstants { + public static final class DataSourceProperties { + private DataSourceProperties() { + throw new AssertionError(); + } + + public static final String DB_CHECK_QUERY = "SELECT * FROM DM_DEVICE"; + public static final String TASK_CONFIG_XML_NAME = "task-mgt-config.xml"; + } + + public static final class DataBaseTypes { + private DataBaseTypes() { + throw new AssertionError(); + } + + public static final String DB_TYPE_MYSQL = "MySQL"; + public static final String DB_TYPE_ORACLE = "Oracle"; + public static final String DB_TYPE_MSSQL = "Microsoft SQL Server"; + public static final String DB_TYPE_DB2 = "DB2"; + public static final String DB_TYPE_H2 = "H2"; + public static final String DB_TYPE_POSTGRESQL = "PostgreSQL"; + } + + public static final class Task { + + public static final String DYNAMIC_TASK_TYPE = "DYNAMIC_TASK"; + public static final String NAME_SEPARATOR = "_"; + public static final String PROPERTY_KEY_COLUMN_NAME = "PROPERTY_NAME"; + public static final String PROPERTY_VALUE_COLUMN_NAME = "PROPERTY_VALUE"; + public static final String TENANT_ID_PROP = "__TENANT_ID_PROP__"; + public static final String LOCAL_HASH_INDEX = "__LOCAL_HASH_INDEX__"; + public static final String LOCAL_TASK_NAME = "__LOCAL_TASK_NAME__"; + } +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/IllegalTransactionStateException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/IllegalTransactionStateException.java new file mode 100755 index 0000000000..4c4c996c59 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/IllegalTransactionStateException.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.exception; + +public class IllegalTransactionStateException extends RuntimeException { + + private static final long serialVersionUID = -3151279331929070297L; + + public IllegalTransactionStateException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public IllegalTransactionStateException(String message, Throwable cause) { + super(message, cause); + } + + public IllegalTransactionStateException(String msg) { + super(msg); + } + + public IllegalTransactionStateException() { + super(); + } + + public IllegalTransactionStateException(Throwable cause) { + super(cause); + } + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementDAOException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementDAOException.java new file mode 100755 index 0000000000..9b683dba20 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementDAOException.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.exception; + +public class TaskManagementDAOException extends Exception { + + public TaskManagementDAOException(String msg) { + super(msg); + } + + public TaskManagementDAOException(String msg, Exception e) { + super(msg, e); + } + + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementException.java new file mode 100755 index 0000000000..d9705e6438 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementException.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.exception; + +public class TaskManagementException extends Exception { + + public TaskManagementException(String msg) { + super(msg); + } + + public TaskManagementException(String msg, Exception e) { + super(msg, e); + } +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskNotFoundException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskNotFoundException.java new file mode 100755 index 0000000000..2d2f568fe2 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskNotFoundException.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.exception; + +/** + * Represents the exception thrown during validating the request. + */ +public class TaskNotFoundException extends Exception { + + public TaskNotFoundException(String message) { + super(message); + } + + public TaskNotFoundException(String message, Exception ex) { + super(message, ex); + } + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TransactionManagementException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TransactionManagementException.java new file mode 100755 index 0000000000..5e43237e43 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TransactionManagementException.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.exception; + +public class TransactionManagementException extends Exception { + + private static final long serialVersionUID = -3151279321929070297L; + + public TransactionManagementException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public TransactionManagementException(String message, Throwable cause) { + super(message, cause); + } + + public TransactionManagementException(String msg) { + super(msg); + } + + public TransactionManagementException() { + super(); + } + + public TransactionManagementException(Throwable cause) { + super(cause); + } + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/UnsupportedDatabaseEngineException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/UnsupportedDatabaseEngineException.java new file mode 100755 index 0000000000..a29f954e12 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/UnsupportedDatabaseEngineException.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.exception; + +/** + * This runtime exception will be thrown if the server has configured with unsupported DB engine. + */ +public class UnsupportedDatabaseEngineException extends RuntimeException { + + private static final long serialVersionUID = -3151279311929070297L; + + public UnsupportedDatabaseEngineException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public UnsupportedDatabaseEngineException(String message, Throwable cause) { + super(message, cause); + } + + public UnsupportedDatabaseEngineException(String msg) { + super(msg); + } + + public UnsupportedDatabaseEngineException() { + super(); + } + + public UnsupportedDatabaseEngineException(Throwable cause) { + super(cause); + } + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/spi/TaskManagementService.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/spi/TaskManagementService.java new file mode 100755 index 0000000000..fac557e0bd --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/spi/TaskManagementService.java @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.common.spi; + +import io.entgra.task.mgt.common.exception.TaskNotFoundException; +import io.entgra.task.mgt.common.exception.TaskManagementException; +import io.entgra.task.mgt.common.bean.DynamicTask; + +import java.util.List; + +public interface TaskManagementService { + + void init() throws TaskManagementException; + + void createTask(DynamicTask dynamicTask) throws TaskManagementException; + + void updateTask(int dynamicTaskId, DynamicTask dynamicTask) throws TaskManagementException, TaskNotFoundException; + + void toggleTask(int dynamicTaskId, boolean isEnabled) throws TaskManagementException, TaskNotFoundException; + + void deleteTask(int dynamicTaskId) throws TaskManagementException, TaskNotFoundException; + + List getAllDynamicTasks() throws TaskManagementException; + + DynamicTask getDynamicTaskById(int dynamicTaskId) throws TaskManagementException; + + List getActiveDynamicTasks() throws TaskManagementException; +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml new file mode 100755 index 0000000000..f0ffd6c1f5 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml @@ -0,0 +1,141 @@ + + + + + + org.wso2.carbon.devicemgt + task-manager + 5.0.20-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.task.mgt.core + bundle + Entgra IoT - Task manager Core + Entgra IoT - Task manager Core + http://entgra.io + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Task Management Core Bundle + io.entgra.task.mgt.core.internal + + org.osgi.framework.*;version="${imp.package.version.osgi.framework}", + org.osgi.service.*;version="${imp.package.version.osgi.service}", + org.apache.commons.logging, + org.wso2.carbon.ndatasource.core, + org.w3c.dom, + javax.xml.bind.annotation, + javax.xml.bind, + javax.sql, + javax.naming, + io.entgra.task.mgt.common.*, + org.wso2.carbon.utils.*, + org.wso2.carbon.ntask.core.*, + org.wso2.carbon.ntask.common, + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.context, + org.apache.commons.codec.binary;version="${commons-codec.wso2.osgi.version.range}", + org.apache.commons.codec.digest;version="${commons-codec.wso2.osgi.version.range}", + io.entgra.server.bootup.heartbeat.beacon.dto, + io.entgra.server.bootup.heartbeat.beacon.exception, + io.entgra.server.bootup.heartbeat.beacon.service, + + + !io.entgra.task.mgt.core.internal, + io.entgra.task.mgt.core.* + + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + provided + + + org.eclipse.osgi + org.eclipse.osgi.services + provided + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + provided + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.common + provided + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + commons-codec.wso2 + commons-codec + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.devicemgt + io.entgra.server.bootup.heartbeat.beacon + provided + + + + + org.wso2.carbon.commons + org.wso2.carbon.ntask.core + provided + + + + \ No newline at end of file diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskConfigurationManager.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskConfigurationManager.java new file mode 100755 index 0000000000..2779a07ff9 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskConfigurationManager.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.config; + +import io.entgra.task.mgt.common.constant.TaskMgtConstants; +import io.entgra.task.mgt.common.exception.TaskManagementException; +import io.entgra.task.mgt.core.util.TaskManagementUtil; +import org.w3c.dom.Document; +import org.wso2.carbon.utils.CarbonUtils; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.File; + +/** + * Class responsible for the task mgt configuration initialization. + */ +public class TaskConfigurationManager { + + private TaskManagementConfig taskManagementConfig; + private static volatile TaskConfigurationManager taskConfigurationManager; + + private static final String TASK_MGT_CONFIG_PATH = + CarbonUtils.getCarbonConfigDirPath() + File.separator + + TaskMgtConstants.DataSourceProperties.TASK_CONFIG_XML_NAME; + + public static TaskConfigurationManager getInstance() { + if (taskConfigurationManager == null) { + synchronized (TaskConfigurationManager.class) { + if (taskConfigurationManager == null) { + taskConfigurationManager = new TaskConfigurationManager(); + } + } + } + return taskConfigurationManager; + } + + public synchronized void initConfig() throws TaskManagementException { + try { + File taskMgtConfig = new File(TASK_MGT_CONFIG_PATH); + Document doc = TaskManagementUtil.convertToDocument(taskMgtConfig); + + /* Un-marshaling Device Management configuration */ + JAXBContext cdmContext = JAXBContext.newInstance(TaskManagementConfig.class); + Unmarshaller unmarshaller = cdmContext.createUnmarshaller(); + //unmarshaller.setSchema(getSchema()); + this.taskManagementConfig = (TaskManagementConfig) unmarshaller.unmarshal(doc); + } catch (JAXBException e) { + throw new TaskManagementException("Error occurred while initializing Data Source config", e); + } + } + + public TaskManagementConfig getTaskManagementConfig() throws TaskManagementException { + if (taskManagementConfig == null) { + initConfig(); + } + return taskManagementConfig; + } + + public void setTaskManagementConfig(TaskManagementConfig taskManagementConfig) { + this.taskManagementConfig = taskManagementConfig; + } +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfig.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfig.java new file mode 100755 index 0000000000..2b3ae468ac --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfig.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Represents Task Mgt configuration. + */ +@XmlRootElement(name = "TaskMgtConfiguration") +@SuppressWarnings("unused") +public final class TaskManagementConfig { + + private TaskManagementConfigRepository taskMgtConfigRepository; + private boolean isTaskWatcherEnabled; + + @XmlElement(name = "ManagementRepository", required = true) + public TaskManagementConfigRepository getTaskMgtConfigRepository() { + return taskMgtConfigRepository; + } + + public void setTaskMgtConfigRepository(TaskManagementConfigRepository taskMgtConfigRepository) { + this.taskMgtConfigRepository = taskMgtConfigRepository; + } + + @XmlElement(name = "TaskWatcherEnable", required = true) + public boolean isTaskWatcherEnabled() { + return isTaskWatcherEnabled; + } + + public void setTaskWatcherEnabled(boolean enabled) { + this.isTaskWatcherEnabled = enabled; + } +} + diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfigRepository.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfigRepository.java new file mode 100755 index 0000000000..a81617f738 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfigRepository.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.config; + +import io.entgra.task.mgt.core.config.datasource.DataSourceConfig; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Class for holding management repository data. + */ +@XmlRootElement(name = "ManagementRepository") +public class TaskManagementConfigRepository { + + private DataSourceConfig dataSourceConfig; + + @XmlElement(name = "DataSourceConfiguration", required = true) + public DataSourceConfig getDataSourceConfig() { + return dataSourceConfig; + } + + public void setDataSourceConfig(DataSourceConfig dataSourceConfig) { + this.dataSourceConfig = dataSourceConfig; + } + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/DataSourceConfig.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/DataSourceConfig.java new file mode 100755 index 0000000000..b4c4d9fc2d --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/DataSourceConfig.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.config.datasource; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Class for holding data source configuration in task-mgt-config.xml at parsing with JAXB. + */ +@XmlRootElement(name = "DataSourceConfiguration") +public class DataSourceConfig { + + private JNDILookupDefinition jndiLookupDefinition; + + @XmlElement(name = "JndiLookupDefinition", required = true) + public JNDILookupDefinition getJndiLookupDefinition() { + return jndiLookupDefinition; + } + + public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) { + this.jndiLookupDefinition = jndiLookupDefinition; + } + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/JNDILookupDefinition.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/JNDILookupDefinition.java new file mode 100755 index 0000000000..5101af8d49 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/JNDILookupDefinition.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.config.datasource; + +import javax.xml.bind.annotation.*; +import java.util.List; + +/** + * Class for hold JndiLookupDefinition of task-mgt-config.xml at parsing with JAXB. + */ +@XmlRootElement(name = "JndiLookupDefinition") +public class JNDILookupDefinition { + + private String jndiName; + private List jndiProperties; + + @XmlElement(name = "Name", required = false) + public String getJndiName() { + return jndiName; + } + + public void setJndiName(String jndiName) { + this.jndiName = jndiName; + } + + @XmlElementWrapper(name = "Environment", required = false) + @XmlElement(name = "Property", nillable = false) + public List getJndiProperties() { + return jndiProperties; + } + + public void setJndiProperties(List jndiProperties) { + this.jndiProperties = jndiProperties; + } + + @XmlRootElement(name = "Property") + public static class JNDIProperty { + + private String name; + + private String value; + + @XmlAttribute(name = "Name") + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @XmlValue + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + } + +} + diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskDAO.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskDAO.java new file mode 100755 index 0000000000..317870dba1 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskDAO.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.dao; + +import io.entgra.task.mgt.common.bean.DynamicTask; +import io.entgra.task.mgt.common.exception.TaskManagementDAOException; + +import java.util.List; + +/** + * This class represents the key operations associated with dynamic tasks. + */ +public interface DynamicTaskDAO { + + int addTask(DynamicTask dynamicTask) throws TaskManagementDAOException; + + boolean updateDynamicTask(DynamicTask dynamicTask) throws TaskManagementDAOException; + + void deleteDynamicTask(int dynamicTaskId) throws TaskManagementDAOException; + + DynamicTask getDynamicTaskById(int dynamicTaskId) throws TaskManagementDAOException; + + List getAllDynamicTasks() throws TaskManagementDAOException; + + List getActiveDynamicTasks() throws TaskManagementDAOException; + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskPropDAO.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskPropDAO.java new file mode 100755 index 0000000000..b458417298 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskPropDAO.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.dao; + +import io.entgra.task.mgt.common.exception.TaskManagementDAOException; + +import java.util.Map; + +/** + * This class represents the key operations associated with dynamic task properties. + */ +public interface DynamicTaskPropDAO { + + void addTaskProperties(int dynamicTaskId, Map properties) throws TaskManagementDAOException; + + Map getDynamicTaskProps(int dynamicTaskId) throws TaskManagementDAOException; + + void updateDynamicTaskProps(int dynamicTaskId, Map properties) + throws TaskManagementDAOException; +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/common/TaskManagementDAOFactory.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/common/TaskManagementDAOFactory.java new file mode 100755 index 0000000000..c8f8623777 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/common/TaskManagementDAOFactory.java @@ -0,0 +1,206 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.dao.common; + +import io.entgra.task.mgt.common.constant.TaskMgtConstants; +import io.entgra.task.mgt.common.exception.IllegalTransactionStateException; +import io.entgra.task.mgt.common.exception.TransactionManagementException; +import io.entgra.task.mgt.common.exception.UnsupportedDatabaseEngineException; +import io.entgra.task.mgt.core.config.datasource.DataSourceConfig; +import io.entgra.task.mgt.core.config.datasource.JNDILookupDefinition; +import io.entgra.task.mgt.core.dao.DynamicTaskDAO; +import io.entgra.task.mgt.core.dao.DynamicTaskPropDAO; +import io.entgra.task.mgt.core.dao.impl.DynamicTaskDAOImpl; +import io.entgra.task.mgt.core.dao.impl.DynamicTaskPropDAOImpl; +import io.entgra.task.mgt.core.dao.util.TaskManagementDAOUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Hashtable; +import java.util.List; + +public class TaskManagementDAOFactory { + + private static DataSource dataSource; + private static String databaseEngine; + private static final Log log = LogFactory.getLog(TaskManagementDAOFactory.class); + private static ThreadLocal currentConnection = new ThreadLocal<>(); + + + public static DynamicTaskDAO getDynamicTaskDAO() { + if (databaseEngine != null) { + switch (databaseEngine) { + case TaskMgtConstants.DataBaseTypes.DB_TYPE_H2: + case TaskMgtConstants.DataBaseTypes.DB_TYPE_MYSQL: + return new DynamicTaskDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + public static DynamicTaskPropDAO getDynamicTaskPropDAO() { + if (databaseEngine != null) { + switch (databaseEngine) { + case TaskMgtConstants.DataBaseTypes.DB_TYPE_H2: + case TaskMgtConstants.DataBaseTypes.DB_TYPE_MYSQL: + return new DynamicTaskPropDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + public static void init(DataSourceConfig config) { + dataSource = resolveDataSource(config); + try { + databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + } + + public static void init(DataSource dtSource) { + dataSource = dtSource; + try { + databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + } + + public static void beginTransaction() throws TransactionManagementException { + Connection conn = currentConnection.get(); + if (conn != null) { + throw new IllegalTransactionStateException("A transaction is already active within the context of " + + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + + "transaction is already active is a sign of improper transaction handling"); + } + try { + conn = dataSource.getConnection(); + conn.setAutoCommit(false); + currentConnection.set(conn); + } catch (SQLException e) { + throw new TransactionManagementException("Error occurred while retrieving config.datasource connection", e); + } + } + + public static void openConnection() throws SQLException { + Connection conn = currentConnection.get(); + if (conn != null) { + throw new IllegalTransactionStateException("A transaction is already active within the context of " + + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + + "transaction is already active is a sign of improper transaction handling"); + } + conn = dataSource.getConnection(); + currentConnection.set(conn); + } + + public static Connection getConnection() throws SQLException { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + return conn; + } + + public static void commitTransaction() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.commit(); + } catch (SQLException e) { + log.error("Error occurred while committing the transaction", e); + } + } + + public static void rollbackTransaction() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.rollback(); + } catch (SQLException e) { + log.warn("Error occurred while roll-backing the transaction", e); + } + } + + public static void closeConnection() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.close(); + } catch (SQLException e) { + log.warn("Error occurred while close the connection"); + } + currentConnection.remove(); + } + + + /** + * Resolve data source from the data source definition + * + * @param config data source configuration + * @return data source resolved from the data source definition + */ + private static DataSource resolveDataSource(DataSourceConfig config) { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException( + "Device Management Repository data source configuration " + "is null and " + + "thus, is not initialized"); + } + io.entgra.task.mgt.core.config.datasource.JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = TaskManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = TaskManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } +} \ No newline at end of file diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/impl/DynamicTaskDAOImpl.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/impl/DynamicTaskDAOImpl.java new file mode 100755 index 0000000000..80fcb98e15 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/impl/DynamicTaskDAOImpl.java @@ -0,0 +1,176 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.dao.impl; + +import io.entgra.task.mgt.common.bean.DynamicTask; +import io.entgra.task.mgt.common.exception.TaskManagementDAOException; +import io.entgra.task.mgt.core.dao.DynamicTaskDAO; +import io.entgra.task.mgt.core.dao.common.TaskManagementDAOFactory; +import io.entgra.task.mgt.core.dao.util.TaskManagementDAOUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; + +import java.sql.*; +import java.util.List; + + +public class DynamicTaskDAOImpl implements DynamicTaskDAO { + private static final Log log = LogFactory.getLog(DynamicTaskDAOImpl.class); + + @Override + public int addTask(DynamicTask dynamicTask) throws TaskManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + int taskId = -1; + try { + Connection conn = TaskManagementDAOFactory.getConnection(); + String sql = "INSERT INTO DYNAMIC_TASK(CRON, NAME, IS_ENABLED, TASK_CLASS_NAME, TENANT_ID) " + + "VALUES (?, ?, ?, ?, ?)"; + + stmt = conn.prepareStatement(sql, new String[]{"DYNAMIC_TASK_ID"}); + stmt.setString(1, dynamicTask.getCronExpression()); + stmt.setString(2, dynamicTask.getName()); + stmt.setBoolean(3, dynamicTask.isEnabled()); + stmt.setString(4, dynamicTask.getTaskClassName()); + stmt.setInt(5, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + stmt.executeUpdate(); + + rs = stmt.getGeneratedKeys(); + if (rs.next()) { + taskId = rs.getInt(1); + } + return taskId; + } catch (SQLException e) { + String msg = "Error occurred while inserting task '" + dynamicTask.getName() + "'"; + log.error(msg, e); + throw new TaskManagementDAOException(msg, e); + } finally { + TaskManagementDAOUtil.cleanupResources(stmt, null); + } + } + + @Override + public boolean updateDynamicTask(DynamicTask dynamicTask) throws TaskManagementDAOException { + PreparedStatement stmt = null; + int rows; + try { + Connection conn = TaskManagementDAOFactory.getConnection(); + String sql = "UPDATE DYNAMIC_TASK SET CRON = ?,IS_ENABLED = ? WHERE DYNAMIC_TASK_ID = ?"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, dynamicTask.getCronExpression()); + stmt.setBoolean(2, dynamicTask.isEnabled()); + stmt.setInt(3, dynamicTask.getDynamicTaskId()); + rows = stmt.executeUpdate(); + return (rows > 0); + } catch (SQLException e) { + String msg = "Error occurred while updating dynamic task '" + dynamicTask.getDynamicTaskId() + "'"; + log.error(msg, e); + throw new TaskManagementDAOException(msg, e); + } finally { + TaskManagementDAOUtil.cleanupResources(stmt, null); + } + } + + + @Override + public void deleteDynamicTask(int dynamicTaskId) throws TaskManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to delete dynamic task with the id: " + dynamicTaskId); + } + String sql = "DELETE FROM DYNAMIC_TASK WHERE DYNAMIC_TASK_ID = ? AND TENANT_ID = ?"; + try { + Connection conn = TaskManagementDAOFactory.getConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { + stmt.setInt(1, dynamicTaskId); + stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + stmt.executeUpdate(); + } + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to delete a dynamic task which has the id " + + dynamicTaskId; + log.error(msg, e); + throw new TaskManagementDAOException(msg, e); + } + } + + @Override + public DynamicTask getDynamicTaskById(int dynamicTaskId) throws TaskManagementDAOException { + DynamicTask dynamicTask = null; + try { + Connection conn = TaskManagementDAOFactory.getConnection(); + String sql = "SELECT * FROM DYNAMIC_TASK WHERE DYNAMIC_TASK_ID= ? AND TENANT_ID = ?"; + + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, dynamicTaskId); + stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + dynamicTask = TaskManagementDAOUtil.loadDynamicTask(rs); + } + } + } + } catch (SQLException e) { + String msg = "Error occurred while getting dynamic task data for task identifier '" + + dynamicTask + "'"; + log.error(msg, e); + throw new TaskManagementDAOException(msg, e); + } + return dynamicTask; + } + + @Override + public List getAllDynamicTasks() throws TaskManagementDAOException { + List dynamicTasks = null; + try { + Connection conn = TaskManagementDAOFactory.getConnection(); + String sql = "SELECT * FROM DYNAMIC_TASK"; + + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + try (ResultSet rs = stmt.executeQuery()) { + dynamicTasks = TaskManagementDAOUtil.loadDynamicTasks(rs); + } + } + } catch (SQLException e) { + String msg = "Error occurred while getting all dynamic task data "; + log.error(msg, e); + throw new TaskManagementDAOException(msg, e); + } + return dynamicTasks; + } + + @Override + public List getActiveDynamicTasks() throws TaskManagementDAOException { + List dynamicTasks = null; + try { + Connection conn = TaskManagementDAOFactory.getConnection(); + String sql = "SELECT * FROM DYNAMIC_TASK WHERE IS_ENABLED = 'true' "; + + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + try (ResultSet rs = stmt.executeQuery()) { + dynamicTasks = TaskManagementDAOUtil.loadDynamicTasks(rs); + } + } + } catch (SQLException e) { + String msg = "Error occurred while getting all dynamic task data "; + log.error(msg, e); + throw new TaskManagementDAOException(msg, e); + } + return dynamicTasks; + } +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/impl/DynamicTaskPropDAOImpl.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/impl/DynamicTaskPropDAOImpl.java new file mode 100755 index 0000000000..66d6920feb --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/impl/DynamicTaskPropDAOImpl.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.dao.impl; + +import io.entgra.task.mgt.common.constant.TaskMgtConstants; +import io.entgra.task.mgt.common.exception.TaskManagementDAOException; +import io.entgra.task.mgt.core.dao.DynamicTaskPropDAO; +import io.entgra.task.mgt.core.dao.common.TaskManagementDAOFactory; +import io.entgra.task.mgt.core.dao.util.TaskManagementDAOUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; +import java.util.Map; + +public class DynamicTaskPropDAOImpl implements DynamicTaskPropDAO { + + private static final Log log = LogFactory.getLog(DynamicTaskPropDAOImpl.class); + + @Override + public void addTaskProperties(int taskId, Map properties) + throws TaskManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + try { + conn = TaskManagementDAOFactory.getConnection(); + stmt = conn.prepareStatement( + "INSERT INTO DYNAMIC_TASK_PROPERTIES(DYNAMIC_TASK_ID, PROPERTY_NAME, " + + "PROPERTY_VALUE, TENANT_ID) VALUES (?, ?, ?, ?)"); + for (String propertyKey : properties.keySet()) { + stmt.setInt(1, taskId); + stmt.setString(2, propertyKey); + stmt.setString(3, properties.get(propertyKey)); + stmt.setInt(4, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + stmt.addBatch(); + } + stmt.executeBatch(); + } catch (SQLException e) { + String msg = "Error occurred while adding task properties of task '" + taskId + "' to the db."; + log.error(msg, e); + throw new TaskManagementDAOException(msg, e); + } finally { + TaskManagementDAOUtil.cleanupResources(stmt, null); + } + } + + + public Map getDynamicTaskProps(int dynamicTaskId) throws TaskManagementDAOException { + Connection conn = null; + PreparedStatement stmt = null; + ResultSet resultSet = null; + Map properties; + try { + conn = TaskManagementDAOFactory.getConnection(); + stmt = conn.prepareStatement( + "SELECT * FROM DYNAMIC_TASK_PROPERTIES WHERE DYNAMIC_TASK_ID = ?"); + stmt.setInt(1, dynamicTaskId); + resultSet = stmt.executeQuery(); + properties = new HashMap<>(); + while (resultSet.next()) { + properties.put(resultSet.getString(TaskMgtConstants.Task.PROPERTY_KEY_COLUMN_NAME) + , resultSet.getString(TaskMgtConstants.Task.PROPERTY_VALUE_COLUMN_NAME)); + } + } catch (SQLException e) { + String msg = "Error occurred while fetching task properties of : '" + dynamicTaskId + "'"; + log.error(msg, e); + throw new TaskManagementDAOException(msg, e); + } finally { + TaskManagementDAOUtil.cleanupResources(stmt, resultSet); + } + return properties; + } + + @Override + public void updateDynamicTaskProps(int dynamicTaskId, Map properties) + throws TaskManagementDAOException { + if (properties.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("Property map of task id :" + dynamicTaskId + " is empty."); + } + return; + } + Connection conn; + PreparedStatement stmt = null; + try { + conn = TaskManagementDAOFactory.getConnection(); + stmt = conn.prepareStatement("UPDATE DYNAMIC_TASK_PROPERTIES SET PROPERTY_VALUE = ? " + + "WHERE DYNAMIC_TASK_ID = ? AND PROPERTY_NAME = ?"); + + for (Map.Entry entry : properties.entrySet()) { + stmt.setString(1, entry.getValue()); + stmt.setInt(2, dynamicTaskId); + stmt.setString(3, entry.getKey()); + stmt.addBatch(); + } + stmt.executeBatch(); + } catch (SQLException e) { + throw new TaskManagementDAOException + ("Error occurred while updating device properties to database.", e); + } finally { + TaskManagementDAOUtil.cleanupResources(stmt, null); + } + } +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/util/TaskManagementDAOUtil.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/util/TaskManagementDAOUtil.java new file mode 100755 index 0000000000..c9ba9ea07a --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/util/TaskManagementDAOUtil.java @@ -0,0 +1,110 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.dao.util; + +import io.entgra.task.mgt.common.bean.DynamicTask; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import javax.naming.InitialContext; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.List; + +public class TaskManagementDAOUtil { + private static final Log log = LogFactory.getLog(TaskManagementDAOUtil.class); + + public static void cleanupResources(Connection conn, PreparedStatement stmt, ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing result set", e); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing prepared statement", e); + } + } + if (conn != null) { + try { + conn.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing database connection", e); + } + } + } + + public static void cleanupResources(PreparedStatement stmt, ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing result set", e); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing prepared statement", e); + } + } + } + + public static DataSource lookupDataSource(String dataSourceName, + final Hashtable jndiProperties) { + try { + if (jndiProperties == null || jndiProperties.isEmpty()) { + return (DataSource) InitialContext.doLookup(dataSourceName); + } + final InitialContext context = new InitialContext(jndiProperties); + return (DataSource) context.lookup(dataSourceName); + } catch (Exception e) { + throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); + } + } + + public static DynamicTask loadDynamicTask(ResultSet rs) throws SQLException { + DynamicTask dynamicTask = new DynamicTask(); + dynamicTask.setDynamicTaskId(rs.getInt("DYNAMIC_TASK_ID")); + dynamicTask.setName(rs.getString("NAME")); + dynamicTask.setCronExpression(rs.getString("CRON")); + dynamicTask.setTaskClassName(rs.getString("TASK_CLASS_NAME")); + dynamicTask.setEnabled(rs.getBoolean("IS_ENABLED")); + dynamicTask.setTenantId(rs.getInt("TENANT_ID")); + return dynamicTask; + } + + public static List loadDynamicTasks(ResultSet rs) throws SQLException { + List dynamicTasks = new ArrayList<>(); + while (rs.next()) { + dynamicTasks.add(loadDynamicTask(rs)); + } + return dynamicTasks; + } + +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/internal/TaskManagerDataHolder.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/internal/TaskManagerDataHolder.java new file mode 100755 index 0000000000..8de0cbb40f --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/internal/TaskManagerDataHolder.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.internal; + +import io.entgra.server.bootup.heartbeat.beacon.service.HeartBeatManagementService; +import io.entgra.task.mgt.common.spi.TaskManagementService; +import org.wso2.carbon.ntask.core.service.TaskService; + +public class TaskManagerDataHolder { + private TaskManagementService taskManagerService; + private TaskService nTaskService; + + private HeartBeatManagementService heartBeatService; + + private static final TaskManagerDataHolder thisInstance = new TaskManagerDataHolder(); + + private TaskManagerDataHolder() { + } + + public static TaskManagerDataHolder getInstance() { + return thisInstance; + } + + public TaskManagementService getTaskManagementService() { + return taskManagerService; + } + + public void setTaskManagementService(TaskManagementService taskManagerService) { + this.taskManagerService = taskManagerService; + } + + public TaskService getnTaskService() { + return nTaskService; + } + + public void setnTaskService(TaskService nTaskService) { + this.nTaskService = nTaskService; + } + + public HeartBeatManagementService getHeartBeatService() { + return heartBeatService; + } + + public void setHeartBeatService(HeartBeatManagementService heartBeatService) { + this.heartBeatService = heartBeatService; + } +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/internal/TaskManagerServiceComponent.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/internal/TaskManagerServiceComponent.java new file mode 100755 index 0000000000..9021b070ec --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/internal/TaskManagerServiceComponent.java @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.internal; + +import io.entgra.server.bootup.heartbeat.beacon.service.HeartBeatManagementService; +import io.entgra.task.mgt.core.config.TaskManagementConfig; +import io.entgra.task.mgt.core.config.datasource.DataSourceConfig; +import io.entgra.task.mgt.common.spi.TaskManagementService; +import io.entgra.task.mgt.core.config.TaskConfigurationManager; +import io.entgra.task.mgt.core.dao.common.TaskManagementDAOFactory; +import io.entgra.task.mgt.core.service.TaskManagementServiceImpl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.ndatasource.core.DataSourceService; +import org.wso2.carbon.ntask.core.service.TaskService; + +/** + * @scr.component name="io.entgra.task.mgt.service" immediate="true" + * @scr.reference name="datasource.service" + * interface="org.wso2.carbon.ndatasource.core.DataSourceService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDataSourceService" + * unbind="unsetDataSourceService" + * @scr.reference name="app.mgt.ntask.component" + * interface="org.wso2.carbon.ntask.core.service.TaskService" + * cardinality="1..1" + * policy="dynamic" + * bind="setTaskService" + * unbind="unsetTaskService" + * @scr.reference name="entgra.heart.beat.service" + * interface="io.entgra.server.bootup.heartbeat.beacon.service.HeartBeatManagementService" + * cardinality="0..1" + * policy="dynamic" + * bind="setHeartBeatService" + * unbind="unsetHeartBeatService" + */ +public class TaskManagerServiceComponent { + + private static final Log log = LogFactory.getLog(TaskManagerServiceComponent.class); + + protected void activate(ComponentContext ctx) { + + if (log.isDebugEnabled()) { + log.debug("Activating Task Manager Service Component"); + } + try { + TaskManagementConfig taskManagementConfig = TaskConfigurationManager.getInstance() + .getTaskManagementConfig(); + DataSourceConfig dataSourceConfig = taskManagementConfig.getTaskMgtConfigRepository() + .getDataSourceConfig(); + TaskManagementDAOFactory.init(dataSourceConfig); + BundleContext bundleContext = ctx.getBundleContext(); + TaskManagementService taskManagementService = new TaskManagementServiceImpl(); + taskManagementService.init(); + TaskManagerDataHolder.getInstance().setTaskManagementService(taskManagementService); + bundleContext.registerService(TaskManagementService.class.getName() + , taskManagementService, null); + if (log.isDebugEnabled()) { + log.debug("Task Manager Service Component has been successfully activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Task Manager Service Component", e); + } + } + + protected void deactivate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("De-activating Task Manager Service Component"); + } + } + + protected void setDataSourceService(DataSourceService dataSourceService) { + /* This is to avoid Task Manager Service Component getting initialized before the underlying datasources + are registered */ + if (log.isDebugEnabled()) { + log.debug("Data source service set to Task Manager Service Component "); + } + } + + protected void unsetDataSourceService(DataSourceService dataSourceService) { + //do nothing + } + + @SuppressWarnings("unused") + public void setTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Setting the task service to Task Manager Service Component"); + } + TaskManagerDataHolder.getInstance().setnTaskService(taskService); + } + + @SuppressWarnings("unused") + protected void unsetTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Removing the task service from Task Manager Service Component"); + } + TaskManagerDataHolder.getInstance().setnTaskService(null); + } + + @SuppressWarnings("unused") + protected void setHeartBeatService(HeartBeatManagementService heartBeatService) { + if (log.isDebugEnabled()) { + log.debug("Setting heart beat service to Task Manager Service Component"); + } + TaskManagerDataHolder.getInstance().setHeartBeatService(heartBeatService); + } + + @SuppressWarnings("unused") + protected void unsetHeartBeatService(HeartBeatManagementService heartBeatManagementService) { + if (log.isDebugEnabled()) { + log.debug("Removing heart beat service from Task Manager Service Component"); + } + TaskManagerDataHolder.getInstance().setHeartBeatService(null); + } + +} \ No newline at end of file diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/service/TaskManagementServiceImpl.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/service/TaskManagementServiceImpl.java new file mode 100755 index 0000000000..fe3a7cb97e --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/service/TaskManagementServiceImpl.java @@ -0,0 +1,397 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (https://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.task.mgt.core.service; + +import io.entgra.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException; +import io.entgra.task.mgt.common.bean.DynamicTask; +import io.entgra.task.mgt.common.constant.TaskMgtConstants; +import io.entgra.task.mgt.common.exception.TaskManagementDAOException; +import io.entgra.task.mgt.common.exception.TaskManagementException; +import io.entgra.task.mgt.common.exception.TaskNotFoundException; +import io.entgra.task.mgt.common.exception.TransactionManagementException; +import io.entgra.task.mgt.common.spi.TaskManagementService; +import io.entgra.task.mgt.core.dao.DynamicTaskDAO; +import io.entgra.task.mgt.core.dao.DynamicTaskPropDAO; +import io.entgra.task.mgt.core.dao.common.TaskManagementDAOFactory; +import io.entgra.task.mgt.core.internal.TaskManagerDataHolder; +import io.entgra.task.mgt.core.util.TaskManagementUtil; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.ntask.common.TaskException; +import org.wso2.carbon.ntask.core.TaskInfo; +import org.wso2.carbon.ntask.core.TaskManager; +import org.wso2.carbon.ntask.core.service.TaskService; + +import java.util.List; +import java.util.Map; + +public class TaskManagementServiceImpl implements TaskManagementService { + private static final Log log = LogFactory.getLog(TaskManagementServiceImpl.class); + + private final DynamicTaskDAO dynamicTaskDAO; + + private final DynamicTaskPropDAO dynamicTaskPropDAO; + private TaskManager taskManager; + + public TaskManagementServiceImpl() { + this.dynamicTaskDAO = TaskManagementDAOFactory.getDynamicTaskDAO(); + this.dynamicTaskPropDAO = TaskManagementDAOFactory.getDynamicTaskPropDAO(); + } + + @Override + public void init() throws TaskManagementException { + TaskService nTaskService = TaskManagerDataHolder.getInstance().getnTaskService(); + if (nTaskService == null) { + String msg = "Unable to load TaskService, hence unable to schedule the task."; + log.error(msg); + throw new TaskManagementException(msg); + } + if (!nTaskService.getRegisteredTaskTypes().contains(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE)) { + try { + nTaskService.registerTaskType(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE); + this.taskManager = nTaskService.getTaskManager(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE); + } catch (TaskException e) { + String msg = "Error occurred while registering task type [" + + TaskMgtConstants.Task.DYNAMIC_TASK_TYPE + + "], hence unable to schedule the task."; + log.error(msg); + throw new TaskManagementException(msg, e); + } + } + } + + @Override + public void createTask(DynamicTask dynamicTask) throws TaskManagementException { + String taskId; + try { + // add into the dynamic task tables + TaskManagementDAOFactory.beginTransaction(); + int dynamicTaskId = dynamicTaskDAO.addTask(dynamicTask); + + Map taskProperties = dynamicTask.getProperties(); + dynamicTaskPropDAO.addTaskProperties(dynamicTaskId, taskProperties); + + // add into the ntask core + taskId = TaskManagementUtil.generateTaskId(dynamicTaskId); + + try { + int serverHashIdx = TaskManagerDataHolder.getInstance().getHeartBeatService() + .getServerCtxInfo().getLocalServerHashIdx(); + taskProperties.put(TaskMgtConstants.Task.LOCAL_HASH_INDEX, String.valueOf(serverHashIdx)); + taskProperties.put(TaskMgtConstants.Task.LOCAL_TASK_NAME, taskId); + } catch (HeartBeatManagementException e) { + String msg = "Unexpected exception when getting server hash index."; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } + + if (!isTaskExists(taskId)) { + TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo(); + triggerInfo.setCronExpression(dynamicTask.getCronExpression()); + TaskInfo taskInfo = new TaskInfo(taskId, dynamicTask.getTaskClassName(), taskProperties, triggerInfo); + taskManager.registerTask(taskInfo); + taskManager.scheduleTask(taskId); + if (!dynamicTask.isEnabled()) { + taskManager.pauseTask(taskId); + } + } else { + String msg = "Task '" + taskId + "' is already exists in the ntask core " + + "Hence not creating another task for the same name."; + log.error(msg); + } + + TaskManagementDAOFactory.commitTransaction(); + } catch (TaskManagementDAOException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Failed to add dynamic task " + dynamicTask.getName(); + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Failed to start/open transaction to add dynamic task"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TaskException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while scheduling task '" + dynamicTask.getName() + "'"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } finally { + TaskManagementDAOFactory.closeConnection(); + } + } + + @Override + public void updateTask(int dynamicTaskId, DynamicTask dynamicTask) throws TaskManagementException + , TaskNotFoundException { + try { + //Update dynamic task table + TaskManagementDAOFactory.beginTransaction(); + DynamicTask existingTask = dynamicTaskDAO.getDynamicTaskById(dynamicTaskId); + + if (existingTask != null) { + existingTask.setEnabled(dynamicTask.isEnabled()); + existingTask.setCronExpression(dynamicTask.getCronExpression()); + dynamicTaskDAO.updateDynamicTask(existingTask); + if (!dynamicTask.getProperties().isEmpty()) { + dynamicTaskPropDAO.updateDynamicTaskProps(dynamicTaskId, dynamicTask.getProperties()); + } + } else { + String msg = "Task '" + dynamicTaskId + "' is not exists in the dynamic task table."; + log.error(msg); + throw new TaskNotFoundException(msg); + } + + // Update task in the ntask core + String taskId = TaskManagementUtil.generateTaskId(existingTask.getDynamicTaskId()); + if (isTaskExists(taskId)) { + TaskInfo taskInfo = taskManager.getTask(taskId); + if (!dynamicTask.getProperties().isEmpty()) { + taskInfo.setProperties(dynamicTask.getProperties()); + } + TaskInfo.TriggerInfo triggerInfo; + if (taskInfo.getTriggerInfo() == null) { + triggerInfo = new TaskInfo.TriggerInfo(); + } else { + triggerInfo = taskInfo.getTriggerInfo(); + } + triggerInfo.setCronExpression(dynamicTask.getCronExpression()); + taskInfo.setTriggerInfo(triggerInfo); + taskManager.registerTask(taskInfo); + taskManager.rescheduleTask(taskId); + } else { + String msg = "Task '" + taskId + "' is not exists in the n task core " + + "Hence cannot update the task."; + log.error(msg); + } + TaskManagementDAOFactory.commitTransaction(); + } catch (TaskManagementDAOException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Failed to update dynamic task " + dynamicTask.getDynamicTaskId(); + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Failed to start/open transaction to update dynamic task"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TaskException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while updating task '" + dynamicTask.getDynamicTaskId() + "'"; + log.error(msg); + throw new TaskManagementException(msg, e); + } finally { + TaskManagementDAOFactory.closeConnection(); + } + } + + @Override + public void toggleTask(int dynamicTaskId, boolean isEnabled) throws TaskManagementException + , TaskNotFoundException { + + try { + //update dynamic task table + TaskManagementDAOFactory.beginTransaction(); + DynamicTask existingTask = dynamicTaskDAO.getDynamicTaskById(dynamicTaskId); + if (existingTask != null) { + existingTask.setEnabled(isEnabled); + dynamicTaskDAO.updateDynamicTask(existingTask); + } else { + String msg = "Task '" + dynamicTaskId + "' is not exists."; + log.error(msg); + throw new TaskNotFoundException(msg); + } + + // Update task in the ntask core + String taskId = TaskManagementUtil.generateTaskId(existingTask.getDynamicTaskId()); + if (isTaskExists(taskId)) { + if (isEnabled) { + taskManager.resumeTask(taskId); + } else { + taskManager.pauseTask(taskId); + } + } else { + String msg = "Task '" + taskId + "' is not exists in the ntask core " + + "Hence cannot toggle the task in the ntask."; + log.error(msg); + } + TaskManagementDAOFactory.commitTransaction(); + } catch (TaskManagementDAOException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Failed to toggle dynamic task " + dynamicTaskId; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Failed to start/open transaction to toggle dynamic task"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TaskException e) { + String msg = "Error occurred while toggling task '" + dynamicTaskId + "' to '" + isEnabled + "'"; + log.error(msg); + throw new TaskManagementException(msg, e); + } finally { + TaskManagementDAOFactory.closeConnection(); + } + } + + @Override + public void deleteTask(int dynamicTaskId) throws TaskManagementException, TaskNotFoundException { + // delete task from dynamic task table + try { + TaskManagementDAOFactory.beginTransaction(); + DynamicTask existingTask = dynamicTaskDAO.getDynamicTaskById(dynamicTaskId); + if (existingTask != null) { + dynamicTaskDAO.deleteDynamicTask(dynamicTaskId); + } else { + String msg = "Task '" + dynamicTaskId + "' is not exists."; + log.error(msg); + throw new TaskNotFoundException(msg); + } + + String taskId = TaskManagementUtil.generateTaskId(existingTask.getDynamicTaskId()); + if (isTaskExists(taskId)) { + taskManager.deleteTask(taskId); + } else { + String msg = "Task '" + taskId + "' is not exists in the ntask core " + + "Hence cannot delete from the ntask core."; + log.error(msg); + } + TaskManagementDAOFactory.commitTransaction(); + } catch (TaskManagementDAOException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Failed to update dynamic task " + dynamicTaskId; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Failed to start/open transaction to delete dynamic task"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TaskException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while retrieving task manager to delete task '" + dynamicTaskId + "'"; + log.error(msg); + throw new TaskManagementException(msg, e); + } finally { + TaskManagementDAOFactory.closeConnection(); + } + } + + @Override + public List getAllDynamicTasks() throws TaskManagementException { + List dynamicTasks; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of all dynamic tasks"); + } + TaskManagementDAOFactory.beginTransaction(); + dynamicTasks = dynamicTaskDAO.getAllDynamicTasks(); + if (dynamicTasks != null) { + for (DynamicTask dynamicTask : dynamicTasks) { + dynamicTask.setProperties(dynamicTaskPropDAO + .getDynamicTaskProps(dynamicTask.getDynamicTaskId())); + } + } + TaskManagementDAOFactory.commitTransaction(); + } catch (TaskManagementDAOException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while fetching all dynamic tasks"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Failed to start/open transaction to get all dynamic tasks"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } finally { + TaskManagementDAOFactory.closeConnection(); + } + return dynamicTasks; + } + + @Override + public DynamicTask getDynamicTaskById(int dynamicTaskId) throws TaskManagementException { + DynamicTask dynamicTask; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of dynamic task '" + dynamicTaskId + "'"); + } + TaskManagementDAOFactory.beginTransaction(); + dynamicTask = dynamicTaskDAO.getDynamicTaskById(dynamicTaskId); + if (dynamicTask != null) { + dynamicTask.setProperties(dynamicTaskPropDAO.getDynamicTaskProps(dynamicTask.getDynamicTaskId())); + } + TaskManagementDAOFactory.commitTransaction(); + } catch (TaskManagementDAOException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while fetching dynamic task '" + dynamicTaskId + "'"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Failed to start/open transaction to get dynamic task '" + dynamicTaskId + "'"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } finally { + TaskManagementDAOFactory.closeConnection(); + } + return dynamicTask; + } + + @Override + public List getActiveDynamicTasks() throws TaskManagementException { + List dynamicTasks; + try { + if (log.isDebugEnabled()) { + log.debug("Fetching the details of all active dynamic tasks"); + } + TaskManagementDAOFactory.beginTransaction(); + dynamicTasks = dynamicTaskDAO.getActiveDynamicTasks(); + if (dynamicTasks != null) { + for (DynamicTask dynamicTask : dynamicTasks) { + dynamicTask.setProperties(dynamicTaskPropDAO.getDynamicTaskProps(dynamicTask.getDynamicTaskId())); + } + } + TaskManagementDAOFactory.commitTransaction(); + } catch (TaskManagementDAOException e) { + TaskManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while fetching all active dynamic tasks"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Failed to start/open transaction to get all active dynamic tasks"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } finally { + TaskManagementDAOFactory.closeConnection(); + } + return dynamicTasks; + } + + // check whether task exist in the ntask core + private boolean isTaskExists(String taskId) throws TaskManagementException, TaskException { + if (StringUtils.isEmpty(taskId)) { + String msg = "Task ID must not be null or empty."; + log.error(msg); + throw new TaskManagementException(msg); + } + List tasks = taskManager.getAllTasks(); + for (TaskInfo t : tasks) { + if (taskId.equals(t.getName())) { + return true; + } + } + return false; + } +} diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/util/TaskManagementUtil.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/util/TaskManagementUtil.java new file mode 100755 index 0000000000..5308fc29c9 --- /dev/null +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/util/TaskManagementUtil.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.core.util; + +import com.google.gson.Gson; +import io.entgra.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException; +import io.entgra.task.mgt.common.constant.TaskMgtConstants; +import io.entgra.task.mgt.common.exception.TaskManagementException; +import io.entgra.task.mgt.core.internal.TaskManagerDataHolder; +import org.apache.commons.codec.digest.DigestUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; +import java.util.Map; + +/** + * Provides utility methods required by the task management bundle. + */ +public class TaskManagementUtil { + + private static final Log log = LogFactory.getLog(TaskManagementUtil.class); + + public static Document convertToDocument(File file) throws TaskManagementException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + try { + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + return docBuilder.parse(file); + } catch (Exception e) { + throw new TaskManagementException( + "Error occurred while parsing file, while converting " + + "to a org.w3c.dom.Document : " + e.getMessage(), e); + } + } + + public static String generateTaskId(int dynamicTaskId) throws TaskManagementException { + try { + int serverHashIdx = TaskManagerDataHolder.getInstance().getHeartBeatService() + .getServerCtxInfo().getLocalServerHashIdx(); + return generateTaskId(dynamicTaskId, serverHashIdx); + } catch (HeartBeatManagementException e) { + String msg = "Failed to generate task id for a dynamic task " + dynamicTaskId; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } + } + + public static String generateTaskId(int dynamicTaskId, int serverHashIdx) { + return TaskMgtConstants.Task.DYNAMIC_TASK_TYPE + TaskMgtConstants.Task.NAME_SEPARATOR + dynamicTaskId + + TaskMgtConstants.Task.NAME_SEPARATOR + serverHashIdx; + } + + public static String generateTaskPropsMD5(Map taskProperties) { + taskProperties.remove(TaskMgtConstants.Task.TENANT_ID_PROP); + taskProperties.remove(TaskMgtConstants.Task.LOCAL_HASH_INDEX); + taskProperties.remove(TaskMgtConstants.Task.LOCAL_TASK_NAME); + Gson gson = new Gson(); + String json = gson.toJson(taskProperties); + return DigestUtils.md5Hex(json); + } + +} diff --git a/components/task-mgt/task-manager/pom.xml b/components/task-mgt/task-manager/pom.xml new file mode 100755 index 0000000000..a263d338e7 --- /dev/null +++ b/components/task-mgt/task-manager/pom.xml @@ -0,0 +1,41 @@ + + + + + + org.wso2.carbon.devicemgt + task-mgt + 5.0.20-SNAPSHOT + ../pom.xml + + + 4.0.0 + task-manager + Entgra IoT - Task Manager Component + pom + http://entgra.io + + + io.entgra.task.mgt.core + io.entgra.task.mgt.common + + + \ No newline at end of file diff --git a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml new file mode 100755 index 0000000000..d546c28698 --- /dev/null +++ b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml @@ -0,0 +1,140 @@ + + + + + + org.wso2.carbon.devicemgt + task-watcher + 5.0.20-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.task.mgt.watcher + bundle + Entgra IoT - Task Watcher + Entgra IoT - Task Watcher + http://entgra.io + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Task Watcher Bundle + io.entgra.task.mgt.watcher.internal + + io.entgra.server.bootup.heartbeat.beacon.*, + io.entgra.task.mgt.common.*, + io.entgra.task.mgt.core.*, + org.apache.commons.logging, + org.osgi.framework.*;version="${imp.package.version.osgi.framework}", + org.osgi.service.*;version="${imp.package.version.osgi.service}", + org.wso2.carbon.context, + org.wso2.carbon.core, + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.ntask.*, + org.wso2.carbon.user.api, + org.wso2.carbon.user.core.*, + + + io.entgra.task.mgt.watcher.* + + + + + + + + + + org.eclipse.osgi + org.eclipse.osgi + provided + + + org.eclipse.osgi + org.eclipse.osgi.services + provided + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.core + provided + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.wso2.carbon.devicemgt + io.entgra.server.bootup.heartbeat.beacon + provided + + + org.wso2.carbon + org.wso2.carbon.core + provided + + + org.wso2.carbon + org.wso2.carbon.user.core + provided + + + org.wso2.carbon + org.wso2.carbon.user.api + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + + \ No newline at end of file diff --git a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/IoTSStartupHandler.java b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/IoTSStartupHandler.java new file mode 100755 index 0000000000..355fba3825 --- /dev/null +++ b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/IoTSStartupHandler.java @@ -0,0 +1,260 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.watcher; + +import io.entgra.server.bootup.heartbeat.beacon.exception.HeartBeatManagementException; +import io.entgra.task.mgt.common.bean.DynamicTask; +import io.entgra.task.mgt.common.constant.TaskMgtConstants; +import io.entgra.task.mgt.common.exception.TaskManagementException; +import io.entgra.task.mgt.core.util.TaskManagementUtil; +import io.entgra.task.mgt.watcher.internal.TaskWatcherDataHolder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.core.ServerStartupObserver; +import org.wso2.carbon.ntask.common.TaskException; +import org.wso2.carbon.ntask.core.TaskInfo; +import org.wso2.carbon.ntask.core.TaskManager; +import org.wso2.carbon.ntask.core.service.TaskService; +import org.wso2.carbon.user.api.Tenant; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.core.service.RealmService; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Timer; +import java.util.TimerTask; + +public class IoTSStartupHandler implements ServerStartupObserver { + private static final Log log = LogFactory.getLog(IoTSStartupHandler.class); + + @Override + public void completingServerStartup() { + } + + @Override + public void completedServerStartup() { + Timer timer = new Timer(); + timer.schedule(new TimerTask() { + @Override + public void run() { + try { + compareTasks(); + } catch (Exception e) { + log.error("Error occurred when comparing tasks.", e); + } + } + }, 200000, 300000); + } + + private void compareTasks() { + if (log.isDebugEnabled()) { + log.debug("Comparing Tasks from carbon nTask manager and entgra task manager"); + } + TaskService nTaskService = TaskWatcherDataHolder.getInstance().getnTaskService(); + if (nTaskService == null) { + String msg = "Unable to load TaskService from the carbon nTask core"; + log.error(msg); + return; + } + try { + List dynamicTasks = TaskWatcherDataHolder.getInstance().getTaskManagementService() + .getAllDynamicTasks(); + + scheduleMissingTasks(nTaskService, dynamicTasks); + deleteObsoleteTasks(nTaskService, dynamicTasks); + + if (log.isDebugEnabled()) { + log.debug("Task Comparison Completed and all tasks in current node are updated"); + } + } catch (TaskException e) { + String msg = "Error occurred while accessing carbon nTask manager."; + log.error(msg, e); + } catch (TaskManagementException e) { + String msg = "Error occurred while retrieving all active tasks from entgra task manager"; + log.error(msg, e); + } + + } + + private static void scheduleMissingTasks(TaskService nTaskService, List dynamicTasks) + throws TaskException, TaskManagementException { + Map> tenantedDynamicTasks = new HashMap<>(); + List dts; + for (DynamicTask dt : dynamicTasks) { + if (tenantedDynamicTasks.containsKey(dt.getTenantId())) { + dts = tenantedDynamicTasks.get(dt.getTenantId()); + } else { + dts = new ArrayList<>(); + } + dts.add(dt); + tenantedDynamicTasks.put(dt.getTenantId(), dts); + } + TaskManager taskManager; + for (Integer tenantId : tenantedDynamicTasks.keySet()) { + if (tenantId == -1) { + log.warn("Found " + tenantedDynamicTasks.get(tenantId).size() + + " invalid tasks without a valid tenant id."); + continue; + } + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId, true); + if (!nTaskService.getRegisteredTaskTypes().contains(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE)) { + nTaskService.registerTaskType(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE); + } + taskManager = nTaskService.getTaskManager(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE); + List tasks = taskManager.getAllTasks(); + // add or update task into nTask core + for (DynamicTask dt : tenantedDynamicTasks.get(tenantId)) { + String generatedTaskId = TaskManagementUtil.generateTaskId(dt.getDynamicTaskId()); + boolean isExist = false; + for (TaskInfo taskInfo : tasks) { + if (taskInfo.getName().equals(generatedTaskId)) { + isExist = true; + TaskInfo.TriggerInfo triggerInfo = taskInfo.getTriggerInfo(); + String dynamicTaskPropMD5 = TaskManagementUtil.generateTaskPropsMD5(dt.getProperties()); + String existingTaskPropMD5 = TaskManagementUtil.generateTaskPropsMD5(taskInfo.getProperties()); + if (!triggerInfo.getCronExpression().equals(dt.getCronExpression()) + || !dynamicTaskPropMD5.equals(existingTaskPropMD5)) { + triggerInfo.setCronExpression(dt.getCronExpression()); + taskInfo.setTriggerInfo(triggerInfo); + taskInfo.setProperties(populateTaskProperties(tenantId, generatedTaskId, dt.getProperties())); + taskManager.registerTask(taskInfo); + taskManager.rescheduleTask(generatedTaskId); + if (log.isDebugEnabled()) { + log.debug("Task - '" + generatedTaskId + "' updated according to the dynamic task table"); + } + } + if (dt.isEnabled() + && taskManager.getTaskState(generatedTaskId) == TaskManager.TaskState.PAUSED) { + taskManager.resumeTask(generatedTaskId); + if (log.isDebugEnabled()) { + log.debug("Task - '" + generatedTaskId + "' enabled according to the dynamic task table"); + } + } else if (!dt.isEnabled() + && taskManager.getTaskState(generatedTaskId) != TaskManager.TaskState.PAUSED) { + taskManager.pauseTask(generatedTaskId); + if (log.isDebugEnabled()) { + log.debug("Task - '" + generatedTaskId + "' disabled according to the dynamic task table"); + } + } + break; + } + } + if (!isExist) { + TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo(); + triggerInfo.setCronExpression(dt.getCronExpression()); + TaskInfo taskInfo = new TaskInfo(generatedTaskId, dt.getTaskClassName(), + populateTaskProperties(tenantId, generatedTaskId, dt.getProperties()), triggerInfo); + taskManager.registerTask(taskInfo); + taskManager.scheduleTask(generatedTaskId); + if (log.isDebugEnabled()) { + log.debug("New task -'" + generatedTaskId + "' created according to the dynamic task table"); + } + } + } + PrivilegedCarbonContext.endTenantFlow(); + } + } + + private static Map populateTaskProperties(int tenantId, String generatedTaskId, + Map taskProperties) + throws TaskManagementException { + try { + int serverHashIdx = TaskWatcherDataHolder.getInstance().getHeartBeatService() + .getServerCtxInfo().getLocalServerHashIdx(); + taskProperties.put(TaskMgtConstants.Task.LOCAL_HASH_INDEX, String.valueOf(serverHashIdx)); + taskProperties.put(TaskMgtConstants.Task.LOCAL_TASK_NAME, generatedTaskId); + taskProperties.put(TaskMgtConstants.Task.TENANT_ID_PROP, String.valueOf(tenantId)); + return taskProperties; + } catch (HeartBeatManagementException e) { + String msg = "Unexpected exception when getting server hash index."; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } + } + + private static void deleteObsoleteTasks(TaskService nTaskService, List dynamicTasks) + throws TaskManagementException, TaskException { + + List tenants = new ArrayList<>(); + try { + RealmService realmService = TaskWatcherDataHolder.getInstance().getRealmService(); + Tenant[] tenantArray = realmService.getTenantManager().getAllTenants(); + if (tenantArray != null && tenantArray.length != 0) { + tenants.addAll(Arrays.asList(tenantArray)); + } + Tenant superTenant = new Tenant(); + superTenant.setId(-1234); + tenants.add(superTenant); + } catch (UserStoreException e) { + String msg = "Unable to load tenants"; + log.error(msg, e); + return; + } + + TaskManager taskManager; + Set hashIds; + try { + hashIds = TaskWatcherDataHolder.getInstance().getHeartBeatService().getActiveServers().keySet(); + } catch (HeartBeatManagementException e) { + String msg = "Unexpected exception when getting hash indexes of active servers"; + log.error(msg, e); + throw new TaskManagementException(msg, e); + } + + for (Tenant tenant : tenants) { + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenant.getId(), true); + if (!nTaskService.getRegisteredTaskTypes().contains(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE)) { + nTaskService.registerTaskType(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE); + } + taskManager = nTaskService.getTaskManager(TaskMgtConstants.Task.DYNAMIC_TASK_TYPE); + List tasks = taskManager.getAllTasks(); + // Remove deleted items from the nTask core + for (TaskInfo taskInfo : tasks) { + boolean isExist = false; + for (DynamicTask dt : dynamicTasks) { + for (int hid : hashIds) { + if (tenant.getId() == dt.getTenantId() && + taskInfo.getName().equals(TaskManagementUtil.generateTaskId(dt.getDynamicTaskId(), hid))) { + isExist = true; + break; + } + } + if (isExist) { + break; + } + } + if (!isExist) { + taskManager.deleteTask(taskInfo.getName()); + if (log.isDebugEnabled()) { + log.debug("Task '" + taskInfo.getName() + "' deleted according to the dynamic task table"); + } + } + } + PrivilegedCarbonContext.endTenantFlow(); + } + } + +} diff --git a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/internal/TaskWatcherDataHolder.java b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/internal/TaskWatcherDataHolder.java new file mode 100755 index 0000000000..9e2953ae25 --- /dev/null +++ b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/internal/TaskWatcherDataHolder.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.watcher.internal; + +import io.entgra.server.bootup.heartbeat.beacon.service.HeartBeatManagementService; +import io.entgra.task.mgt.common.spi.TaskManagementService; +import org.wso2.carbon.ntask.core.service.TaskService; +import org.wso2.carbon.user.core.service.RealmService; + +public class TaskWatcherDataHolder { + private TaskManagementService taskManagerService; + + private TaskService nTaskService; + + private HeartBeatManagementService heartBeatService; + private RealmService realmService; + + private static final TaskWatcherDataHolder thisInstance = new TaskWatcherDataHolder(); + + private TaskWatcherDataHolder() {} + + public static TaskWatcherDataHolder getInstance() { + return thisInstance; + } + + public TaskManagementService getTaskManagementService() { + return taskManagerService; + } + + public void setTaskManagementService(TaskManagementService taskManagerService) { + this.taskManagerService = taskManagerService; + } + + public TaskService getnTaskService() { + return nTaskService; + } + + public void setnTaskService(TaskService nTaskService) { + this.nTaskService = nTaskService; + } + + public HeartBeatManagementService getHeartBeatService() { + return heartBeatService; + } + + public void setHeartBeatService(HeartBeatManagementService heartBeatService) { + this.heartBeatService = heartBeatService; + } + + public RealmService getRealmService() { + return this.realmService; + } + + public void setRealmService(RealmService realmService) { + this.realmService = realmService; + } + +} diff --git a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/internal/TaskWatcherServiceComponent.java b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/internal/TaskWatcherServiceComponent.java new file mode 100755 index 0000000000..209113df84 --- /dev/null +++ b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/src/main/java/io/entgra/task/mgt/watcher/internal/TaskWatcherServiceComponent.java @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.task.mgt.watcher.internal; + +import io.entgra.server.bootup.heartbeat.beacon.service.HeartBeatManagementService; +import io.entgra.task.mgt.common.spi.TaskManagementService; +import io.entgra.task.mgt.core.config.TaskConfigurationManager; +import io.entgra.task.mgt.core.config.TaskManagementConfig; +import io.entgra.task.mgt.watcher.IoTSStartupHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.core.ServerStartupObserver; +import org.wso2.carbon.ntask.core.service.TaskService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * @scr.component + * name="io.entgra.task.mgt.watcher" immediate="true" + * @scr.reference name="app.mgt.ntask.component" + * interface="org.wso2.carbon.ntask.core.service.TaskService" + * cardinality="1..1" + * policy="dynamic" + * bind="setTaskService" + * unbind="unsetTaskService" + * @scr.reference name="io.entgra.task.mgt.service" + * interface="io.entgra.task.mgt.common.spi.TaskManagementService" + * cardinality="1..1" + * policy="dynamic" + * bind="setTaskMgtService" + * unbind="unsetTaskMgtService" + * @scr.reference name="entgra.heart.beat.service" + * interface="io.entgra.server.bootup.heartbeat.beacon.service.HeartBeatManagementService" + * cardinality="0..1" + * policy="dynamic" + * bind="setHeartBeatService" + * unbind="unsetHeartBeatService" + * @scr.reference name="user.realmservice.default" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + */ +public class TaskWatcherServiceComponent { + + private static final Log log = LogFactory.getLog(TaskWatcherServiceComponent.class); + + protected void activate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("Activating Task Watcher Service Component"); + } + try { + TaskManagementConfig taskManagementConfig = TaskConfigurationManager.getInstance().getTaskManagementConfig(); + if (taskManagementConfig.isTaskWatcherEnabled()) { + BundleContext bundleContext = ctx.getBundleContext(); + bundleContext.registerService(ServerStartupObserver.class.getName(), new IoTSStartupHandler(), null); + } else { + String msg = "Task watcher is not enabled in this environment hence wso2 carbon ntask will not " + + "update according to the task manager "; + log.debug(msg); + } + if (log.isDebugEnabled()) { + log.debug("Task Watcher Service Component has been successfully activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Task Watcher Service Component", e); + } + } + + protected void deactivate(ComponentContext ctx) { + if (log.isDebugEnabled()) { + log.debug("De-activating Task Watcher Service Component"); + } + } + + @SuppressWarnings("unused") + public void setTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Setting the task service to Task Watcher Service Component "); + } + TaskWatcherDataHolder.getInstance().setnTaskService(taskService); + } + + @SuppressWarnings("unused") + protected void unsetTaskService(TaskService taskService) { + if (log.isDebugEnabled()) { + log.debug("Removing the task service from Task Watcher Service Component "); + } + TaskWatcherDataHolder.getInstance().setnTaskService(null); + } + + @SuppressWarnings("unused") + protected void setTaskMgtService(TaskManagementService taskManagementService) { + if (log.isDebugEnabled()) { + log.debug("Setting the task service to Task Watcher Service Component "); + } + TaskWatcherDataHolder.getInstance().setTaskManagementService(taskManagementService); + } + + @SuppressWarnings("unused") + protected void unsetTaskMgtService(TaskManagementService taskManagementService) { + if (log.isDebugEnabled()) { + log.debug("Removing the task service from Task Watcher Service Component "); + } + TaskWatcherDataHolder.getInstance().setTaskManagementService(null); + } + + @SuppressWarnings("unused") + protected void setHeartBeatService(HeartBeatManagementService heartBeatService) { + if (log.isDebugEnabled()) { + log.debug("Setting heart beat service to Task Manager Service Component"); + } + TaskWatcherDataHolder.getInstance().setHeartBeatService(heartBeatService); + } + + @SuppressWarnings("unused") + protected void unsetHeartBeatService(HeartBeatManagementService heartBeatManagementService) { + if (log.isDebugEnabled()) { + log.debug("Removing heart beat service from Task Manager Service Component"); + } + TaskWatcherDataHolder.getInstance().setHeartBeatService(null); + } + + /** + * Sets Realm Service. + * + * @param realmService An instance of RealmService + */ + @SuppressWarnings("unused") + protected void setRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Setting Realm Service"); + } + TaskWatcherDataHolder.getInstance().setRealmService(realmService); + } + + /** + * Unsets Realm Service. + * + * @param realmService An instance of RealmService + */ + @SuppressWarnings("unused") + protected void unsetRealmService(RealmService realmService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting Realm Service"); + } + TaskWatcherDataHolder.getInstance().setRealmService(null); + } + +} diff --git a/components/task-mgt/task-watcher/pom.xml b/components/task-mgt/task-watcher/pom.xml new file mode 100755 index 0000000000..a570d9f279 --- /dev/null +++ b/components/task-mgt/task-watcher/pom.xml @@ -0,0 +1,40 @@ + + + + + + org.wso2.carbon.devicemgt + task-mgt + 5.0.20-SNAPSHOT + ../pom.xml + + + 4.0.0 + task-watcher + Entgra IoT - Task Watcher Component + pom + http://entgra.io + + + io.entgra.task.mgt.watcher + + + \ No newline at end of file diff --git a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml index 00d9b8a2c4..a57921baf3 100644 --- a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml +++ b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/email-sender/pom.xml b/components/transport-mgt/email-sender/pom.xml index e1a7bcc483..8e4d752874 100644 --- a/components/transport-mgt/email-sender/pom.xml +++ b/components/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/pom.xml b/components/transport-mgt/pom.xml index 810bdfb738..9702d7f32c 100644 --- a/components/transport-mgt/pom.xml +++ b/components/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml index ae2099e21c..ae4b3ec78b 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml index e3efb077d6..9f4858d961 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml index 8afeac3dde..b9dc37e51c 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/pom.xml b/components/transport-mgt/sms-handler/pom.xml index 4fa91b3806..1124fd5609 100644 --- a/components/transport-mgt/sms-handler/pom.xml +++ b/components/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml index 25a4af3836..4f4a7e546d 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor io.entgra.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT 4.0.0 diff --git a/components/ui-request-interceptor/pom.xml b/components/ui-request-interceptor/pom.xml index 6cae6f9ff9..e16c2d3f4b 100644 --- a/components/ui-request-interceptor/pom.xml +++ b/components/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index 40949615c2..fdfc56c1dd 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/components/webapp-authenticator-framework/pom.xml b/components/webapp-authenticator-framework/pom.xml index 4dabfd8d69..6945454311 100644 --- a/components/webapp-authenticator-framework/pom.xml +++ b/components/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml index eb5aad0418..e0ce823ef5 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml index d4093bac56..6f52cf112c 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/pom.xml b/features/analytics-mgt/grafana-mgt/pom.xml index d8a88dc195..f9c33243fd 100644 --- a/features/analytics-mgt/grafana-mgt/pom.xml +++ b/features/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/pom.xml b/features/analytics-mgt/pom.xml index ab71844dcb..f6a2860e0b 100644 --- a/features/analytics-mgt/pom.xml +++ b/features/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml index 976aa4ee7e..5e789d64cb 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml index 67e12db3ba..69c6b280e3 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml index af74908a4f..c2ee07f0c9 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index 35b22f42c3..c169946fd3 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml index c2710d96ec..4c1f3edd29 100644 --- a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml index 79523aa6a6..e46d58bb91 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index bb85e18ffa..f9c5861831 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -117,7 +117,8 @@ CREATE TABLE IF NOT EXISTS AP_DEVICE_SUBSCRIPTION( PRIMARY KEY (ID), CONSTRAINT fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1 FOREIGN KEY (AP_APP_RELEASE_ID) - REFERENCES AP_APP_RELEASE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + REFERENCES AP_APP_RELEASE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT uq_AP_DEVICE_SUBSCRIPTION UNIQUE (DM_DEVICE_ID, AP_APP_RELEASE_ID) ); CREATE INDEX fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_DEVICE_SUBSCRIPTION (AP_APP_RELEASE_ID ASC); diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index 754eaca191..9b2e89b3f7 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -1,6 +1,7 @@ -- ----------------------------------------------------- -- Table AP_APP -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP]') AND TYPE IN (N'U')) CREATE TABLE AP_APP( ID INTEGER NOT NULL IDENTITY, NAME VARCHAR(350) NOT NULL, @@ -18,6 +19,7 @@ CREATE TABLE AP_APP( -- ----------------------------------------------------- -- Table AP_APP_RELEASE -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_RELEASE]') AND TYPE IN (N'U')) CREATE TABLE AP_APP_RELEASE( ID INTEGER NOT NULL IDENTITY, DESCRIPTION VARCHAR(max) NOT NULL, @@ -52,6 +54,7 @@ CREATE INDEX fk_AP_APP_RELEASE_AP_APP1_idx ON AP_APP_RELEASE (AP_APP_ID ASC); -- ----------------------------------------------------- -- Table AP_APP_REVIEW -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_REVIEW]') AND TYPE IN (N'U')) CREATE TABLE AP_APP_REVIEW( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -74,6 +77,7 @@ CREATE INDEX fk_AP_APP_COMMENT_AP_APP_RELEASE1_idx ON AP_APP_REVIEW (AP_APP_RELE -- ----------------------------------------------------- -- Table AP_APP_LIFECYCLE_STATE -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_LIFECYCLE_STATE]') AND TYPE IN (N'U')) CREATE TABLE AP_APP_LIFECYCLE_STATE( ID INTEGER NOT NULL IDENTITY, CURRENT_STATE VARCHAR(45) NOT NULL, @@ -93,6 +97,7 @@ CREATE INDEX fk_AP_APP_LIFECYCLE_STATE_AP_APP_RELEASE1_idx ON AP_APP_LIFECYCLE_S -- ----------------------------------------------------- -- Table AP_APP_TAG -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_TAG]') AND TYPE IN (N'U')) CREATE TABLE AP_APP_TAG( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -103,6 +108,7 @@ CREATE TABLE AP_APP_TAG( -- ----------------------------------------------------- -- Table AP_DEVICE_SUBSCRIPTION -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_DEVICE_SUBSCRIPTION]') AND TYPE IN (N'U')) CREATE TABLE AP_DEVICE_SUBSCRIPTION( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -118,13 +124,15 @@ CREATE TABLE AP_DEVICE_SUBSCRIPTION( PRIMARY KEY (ID), CONSTRAINT fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1 FOREIGN KEY (AP_APP_RELEASE_ID) - REFERENCES AP_APP_RELEASE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + REFERENCES AP_APP_RELEASE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT uq_AP_DEVICE_SUBSCRIPTION UNIQUE (DM_DEVICE_ID, AP_APP_RELEASE_ID) ); CREATE INDEX fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_DEVICE_SUBSCRIPTION (AP_APP_RELEASE_ID ASC); -- ----------------------------------------------------- -- Table AP_GROUP_SUBSCRIPTION -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_GROUP_SUBSCRIPTION]') AND TYPE IN (N'U')) CREATE TABLE AP_GROUP_SUBSCRIPTION( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -145,6 +153,7 @@ CREATE INDEX fk_AP_GROUP_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_GROUP_SUBSCRIPTI -- ----------------------------------------------------- -- Table AP_ROLE_SUBSCRIPTION -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_ROLE_SUBSCRIPTION]') AND TYPE IN (N'U')) CREATE TABLE AP_ROLE_SUBSCRIPTION( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -165,6 +174,7 @@ CREATE INDEX fk_AP_ROLE_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_ROLE_SUBSCRIPTION -- ----------------------------------------------------- -- Table AP_UNRESTRICTED_ROLE -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_UNRESTRICTED_ROLE]') AND TYPE IN (N'U')) CREATE TABLE AP_UNRESTRICTED_ROLE( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -180,6 +190,7 @@ CREATE INDEX fk_AP_APP_VISIBILITY_AP_APP1_idx ON AP_UNRESTRICTED_ROLE (AP_APP_ID -- ----------------------------------------------------- -- Table AP_USER_SUBSCRIPTION -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_USER_SUBSCRIPTION]') AND TYPE IN (N'U')) CREATE TABLE AP_USER_SUBSCRIPTION( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -200,6 +211,7 @@ CREATE INDEX fk_AP_USER_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_USER_SUBSCRIPTION -- ----------------------------------------------------- -- Table AP_APP_CATEGORY -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_CATEGORY]') AND TYPE IN (N'U')) CREATE TABLE AP_APP_CATEGORY( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -211,6 +223,7 @@ CREATE TABLE AP_APP_CATEGORY( -- ----------------------------------------------------- -- Table AP_APP_TAG_MAPPING -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_TAG_MAPPING]') AND TYPE IN (N'U')) CREATE TABLE AP_APP_TAG_MAPPING( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -230,6 +243,7 @@ CREATE INDEX fk_AP_APP_TAG_copy1_AP_APP1_idx ON AP_APP_TAG_MAPPING (AP_APP_ID AS -- ----------------------------------------------------- -- Table AP_APP_CATEGORY_MAPPING -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_CATEGORY_MAPPING]') AND TYPE IN (N'U')) CREATE TABLE AP_APP_CATEGORY_MAPPING( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -249,6 +263,7 @@ CREATE INDEX fk_AP_APP_CATEGORY_copy1_AP_APP1_idx ON AP_APP_CATEGORY_MAPPING (AP -- ----------------------------------------------------- -- Table AP_APP_SUB_OP_MAPPING -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_SUB_OP_MAPPING]') AND TYPE IN (N'U')) CREATE TABLE AP_APP_SUB_OP_MAPPING ( ID INTEGER NOT NULL IDENTITY, TENANT_ID INTEGER NOT NULL, @@ -264,6 +279,7 @@ CREATE INDEX fk_AP_APP_SUB_OP_MAPPING_AP_DEVICE_SUBSCRIPTION1_idx ON AP_APP_SUB_ -- ----------------------------------------------------- -- Table AP_SCHEDULED_SUBSCRIPTION -- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_SCHEDULED_SUBSCRIPTION]') AND TYPE IN (N'U')) CREATE TABLE AP_SCHEDULED_SUBSCRIPTION( ID INTEGER NOT NULL IDENTITY, TASK_NAME VARCHAR(100) NOT NULL, @@ -283,7 +299,8 @@ CREATE TABLE AP_SCHEDULED_SUBSCRIPTION( -- ----------------------------------------------------- -- Table AP_IDENTITY_SERVER -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS AP_IDENTITY_SERVER ( +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_IDENTITY_SERVER]') AND TYPE IN (N'U')) +CREATE TABLE AP_IDENTITY_SERVER ( ID INTEGER NOT NULL IDENTITY, NAME VARCHAR(255) NOT NULL, PROVIDER_NAME VARCHAR(255) NOT NULL, @@ -298,8 +315,9 @@ CREATE TABLE IF NOT EXISTS AP_IDENTITY_SERVER ( -- ----------------------------------------------------- -- Table AP_IS_SP_APP_MAPPING --- -----------------------------------------------------; -CREATE TABLE IF NOT EXISTS AP_IS_SP_APP_MAPPING ( +-- ----------------------------------------------------- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_IS_SP_APP_MAPPING]') AND TYPE IN (N'U')) +CREATE TABLE AP_IS_SP_APP_MAPPING ( ID INTEGER NOT NULL IDENTITY, SP_UID VARCHAR(255) NOT NULL, AP_APP_ID INT NOT NULL, @@ -313,7 +331,8 @@ CREATE TABLE IF NOT EXISTS AP_IS_SP_APP_MAPPING ( -- ----------------------------------------------------- -- Table AP_APP_FAVOURITES -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS AP_APP_FAVOURITES( +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[AP_APP_FAVOURITES]') AND TYPE IN (N'U')) +CREATE TABLE AP_APP_FAVOURITES( ID INTEGER NOT NULL IDENTITY, AP_APP_ID INTEGER NOT NULL, USER_NAME VARCHAR(100) NOT NULL, diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 6070139961..54ba58a9fe 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -104,7 +104,8 @@ CREATE TABLE IF NOT EXISTS AP_DEVICE_SUBSCRIPTION( DM_DEVICE_ID INTEGER NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL, PRIMARY KEY (ID), - CONSTRAINT fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1 FOREIGN KEY (AP_APP_RELEASE_ID) REFERENCES AP_APP_RELEASE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + CONSTRAINT fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1 FOREIGN KEY (AP_APP_RELEASE_ID) REFERENCES AP_APP_RELEASE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT uq_AP_DEVICE_SUBSCRIPTION UNIQUE (DM_DEVICE_ID, AP_APP_RELEASE_ID) ); CREATE INDEX fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_DEVICE_SUBSCRIPTION (AP_APP_RELEASE_ID ASC); -- ----------------------------------------------------- diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index 946d720dfd..e8e1dbb225 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -129,7 +129,8 @@ CREATE TABLE IF NOT EXISTS AP_DEVICE_SUBSCRIPTION( PRIMARY KEY (ID), CONSTRAINT fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1 FOREIGN KEY (AP_APP_RELEASE_ID) - REFERENCES AP_APP_RELEASE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + REFERENCES AP_APP_RELEASE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT uq_AP_DEVICE_SUBSCRIPTION UNIQUE (DM_DEVICE_ID, AP_APP_RELEASE_ID) ); CREATE INDEX fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1_idx ON AP_DEVICE_SUBSCRIPTION (AP_APP_RELEASE_ID ASC); diff --git a/features/application-mgt/pom.xml b/features/application-mgt/pom.xml index c50d691b8b..5e855e60c9 100644 --- a/features/application-mgt/pom.xml +++ b/features/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml index d09c299956..7a149fb63d 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml index 0b9c94a5d6..6829f4a0d6 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml index d2099ed0f1..27a40bd0a4 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/pom.xml b/features/certificate-mgt/pom.xml index 57a12c2de7..f86d0bb8ef 100644 --- a/features/certificate-mgt/pom.xml +++ b/features/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml index 1195be8f81..7d18bd12d5 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml index 5b03d5ab3c..1dc330f67f 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml index 432994a184..f178b51f53 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml index 6c1a9076f2..b36bc24864 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml index 0868ada649..822f213a82 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml index c9e3a0c560..e8121a2b25 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml index 2632998706..469735e0c6 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml index 744eb2e76a..91fddccc4e 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml index e63d2d2595..92cc4a384f 100644 --- a/features/device-mgt-extensions/pom.xml +++ b/features/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml index dcec1c1ce2..0c2a6df02f 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml index 7389b0116e..701de1d1b7 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 0e8d1b8466..f383c5d5b9 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -765,3 +765,25 @@ CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING ( TRACCAR_USER_ID INT DEFAULT 0 ); -- END OF DM_EXT_PERMISSION_MAPPING TABLE-- + +-- DYNAMIC TASK TABLES-- +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK ( + DYNAMIC_TASK_ID INTEGER AUTO_INCREMENT NOT NULL, + NAME VARCHAR(300) DEFAULT NULL , + CRON VARCHAR(8000) DEFAULT NULL, + IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (DYNAMIC_TASK_ID) +); + +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( + DYNAMIC_TASK_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), + CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES + DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE +); +-- END OF DYNAMIC TASK TABLE-- \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index a682f457be..1c22ba25fc 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -120,21 +120,6 @@ CREATE TABLE DM_OPERATION ( PRIMARY KEY (ID) ); -IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_STATUS]') AND TYPE IN (N'U')) -CREATE TABLE DM_DEVICE_STATUS ( - ID INTEGER IDENTITY(1,1) NOT NULL, - ENROLMENT_ID INTEGER NOT NULL, - DEVICE_ID INTEGER NOT NULL, - STATUS VARCHAR(50) DEFAULT NULL, - UPDATE_TIME DATETIME2 DEFAULT NULL, - CHANGED_BY VARCHAR(255) NOT NULL, - PRIMARY KEY (ID), - CONSTRAINT FK_DM_DEVICE_STATUS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES - DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT FK_DM_DEVICE_STATUS_ENROLMENT FOREIGN KEY (ENROLMENT_ID) REFERENCES - DM_ENROLMENT (ID) ON DELETE CASCADE ON UPDATE CASCADE -); - IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_ENROLMENT]') AND TYPE IN (N'U')) CREATE TABLE DM_ENROLMENT ( ID INTEGER IDENTITY(1,1) NOT NULL, @@ -151,6 +136,21 @@ CREATE TABLE DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_STATUS]') AND TYPE IN (N'U')) +CREATE TABLE DM_DEVICE_STATUS ( + ID INTEGER IDENTITY(1,1) NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + DEVICE_ID INTEGER NOT NULL, + STATUS VARCHAR(50) DEFAULT NULL, + UPDATE_TIME DATETIME2 DEFAULT NULL, + CHANGED_BY VARCHAR(255) NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_STATUS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT FK_DM_DEVICE_STATUS_ENROLMENT FOREIGN KEY (ENROLMENT_ID) REFERENCES + DM_ENROLMENT (ID) ON DELETE CASCADE ON UPDATE CASCADE +); + IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENROLMENT_FK_DEVICE_ID' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT')) CREATE INDEX IDX_ENROLMENT_FK_DEVICE_ID ON DM_ENROLMENT(DEVICE_ID); IF NOT EXISTS (SELECT * FROM SYS.INDEXES WHERE NAME = 'IDX_ENROLMENT_DEVICE_ID_TENANT_ID' AND OBJECT_ID = OBJECT_ID('DM_ENROLMENT')) @@ -639,10 +639,10 @@ CREATE TABLE DM_OTP_DATA ( USERNAME VARCHAR(500) NOT NULL, EMAIL VARCHAR(100) NOT NULL, EMAIL_TYPE VARCHAR(20) NOT NULL, - META_INFO VARCHAR(20000) NOT NULL, + META_INFO VARCHAR(8000) NOT NULL, CREATED_AT DATETIME2(0) NOT NULL, EXPIRY_TIME INT NOT NULL DEFAULT 3600, - IS_EXPIRED BIT DEFAULT false, + IS_EXPIRED BIT DEFAULT 0, PRIMARY KEY (ID), CONSTRAINT email_type_uk UNIQUE (EMAIL, EMAIL_TYPE) ); @@ -718,8 +718,8 @@ CREATE TABLE DM_GEOFENCE ( ID INT IDENTITY NOT NULL, FENCE_NAME VARCHAR(255) NOT NULL, DESCRIPTION VARCHAR(MAX) DEFAULT NULL, - LATITUDE DECIMAL(3,5) DEFAULT NULL, - LONGITUDE DECIMAL(3,5) DEFAULT NULL, + LATITUDE FLOAT DEFAULT NULL, + LONGITUDE FLOAT DEFAULT NULL, RADIUS DECIMAL(30,4) DEFAULT NULL, GEO_JSON VARCHAR(MAX) DEFAULT NULL, FENCE_SHAPE VARCHAR(100) DEFAULT NULL, @@ -730,3 +730,27 @@ CREATE TABLE DM_GEOFENCE ( ); -- END OF DM_GEOFENCE TABLE-- + +-- DYNAMIC TASK TABLES-- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DYNAMIC_TASK]') AND TYPE IN (N'U')) +CREATE TABLE DYNAMIC_TASK ( + DYNAMIC_TASK_ID INTEGER IDENTITY(1,1) NOT NULL, + NAME VARCHAR(255) DEFAULT NULL , + CRON VARCHAR(8000) DEFAULT NULL, + IS_ENABLED BIT NOT NULL DEFAULT 0, + TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (DYNAMIC_TASK_ID) +); + +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DYNAMIC_TASK_PROPERTIES]') AND TYPE IN (N'U')) +CREATE TABLE DYNAMIC_TASK_PROPERTIES ( + DYNAMIC_TASK_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), + CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES + DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE +); +-- END OF DYNAMIC TASK TABLE-- \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 33ac7964dd..17c7460c97 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -829,3 +829,25 @@ CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING ( TRACCAR_USER_ID INT DEFAULT 0 ); -- END OF DM_EXT_PERMISSION_MAPPING TABLE-- + +-- DYNAMIC TASK TABLES-- +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK ( + DYNAMIC_TASK_ID INTEGER AUTO_INCREMENT NOT NULL, + NAME VARCHAR(300) DEFAULT NULL , + CRON VARCHAR(8000) DEFAULT NULL, + IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (DYNAMIC_TASK_ID) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( + DYNAMIC_TASK_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), + CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES + DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB; +-- END OF DYNAMIC TASK TABLE-- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index bbfe9bbcfb..a5d3725548 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -1096,5 +1096,26 @@ CREATE TABLE DM_GEOFENCE ( TENANT_ID NUMBER(10) DEFAULT 0, CONSTRAINT PK_DM_GEOFENCE PRIMARY KEY (ID) ); - -- END OF DM_GEOFENCE TABLE-- + +-- DYNAMIC TASK TABLES-- +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK ( + DYNAMIC_TASK_ID NUMBER(10) NOT NULL, + NAME VARCHAR2(300) DEFAULT NULL , + CRON VARCHAR2(8000) DEFAULT NULL, + IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TASK_CLASS_NAME VARCHAR2(8000) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + CONSTRAINT PK_DYNAMIC_TASK PRIMARY KEY (DYNAMIC_TASK_ID) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( + DYNAMIC_TASK_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR2(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR2(100) DEFAULT NULL, + TENANT_ID VARCHAR2(100), + CONSTRAINT PK_DYNAMIC_TASK_PROPERTIES PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), + CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES + DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB; +-- END OF DYNAMIC TASK TABLE-- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 67ba8f1b6a..731f086c61 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -750,3 +750,25 @@ CREATE TABLE IF NOT EXISTS DM_GEOFENCE ( ); -- END OF DM_GEOFENCE TABLE-- + +-- DYNAMIC TASK TABLES-- +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK ( + DYNAMIC_TASK_ID INTEGER DEFAULT NEXTVAL ('DYNAMIC_TASK_seq') NOT NULL, + NAME VARCHAR(300) DEFAULT NULL , + CRON VARCHAR(8000) DEFAULT NULL, + IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (DYNAMIC_TASK_ID) +) ENGINE=InnoDB; + +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( + DYNAMIC_TASK_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), + CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES + DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB; +-- END OF DYNAMIC TASK TABLE-- diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml index f7ce8375e5..7ae15434ee 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml @@ -4,7 +4,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml index c8ebd5527f..1f5a22014f 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index 685671a6e8..3d009aa9cb 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index 59a498ce34..43a0145b6e 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml index 1f88d5b765..e5f9d4a316 100644 --- a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml +++ b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heart-beat-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/heartbeat-management/io.entgra.server.heart.beat.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/heart-beat-datasources.xml.j2 b/features/heartbeat-management/io.entgra.server.heart.beat.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/heart-beat-datasources.xml.j2 index 524f28c42a..2360744fe6 100644 --- a/features/heartbeat-management/io.entgra.server.heart.beat.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/heart-beat-datasources.xml.j2 +++ b/features/heartbeat-management/io.entgra.server.heart.beat.feature/src/main/resources/conf_templates/templates/repository/conf/datasources/heart-beat-datasources.xml.j2 @@ -39,10 +39,10 @@ <{{property_name}}>{{property_value}} {% endfor %} {% else %} - jdbc:mysql://localhost:3306/heart_beat - root - root - com.mysql.jdbc.Driver + jdbc:h2:./repository/database/HEART_BEAT_DB;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE + wso2carbon + wso2carbon + org.h2.Driver 50 60000 true diff --git a/features/heartbeat-management/io.entgra.server.heart.beat.feature/src/main/resources/datasources/heart-beat-datasources.xml b/features/heartbeat-management/io.entgra.server.heart.beat.feature/src/main/resources/datasources/heart-beat-datasources.xml index a3c656b757..ebbe5087f2 100644 --- a/features/heartbeat-management/io.entgra.server.heart.beat.feature/src/main/resources/datasources/heart-beat-datasources.xml +++ b/features/heartbeat-management/io.entgra.server.heart.beat.feature/src/main/resources/datasources/heart-beat-datasources.xml @@ -29,10 +29,10 @@ - jdbc:mysql://localhost:3306/heart_beat - root - root - com.mysql.jdbc.Driver + jdbc:h2:./repository/database/HEART_BEAT_DB;AUTO_SERVER=TRUE;DB_CLOSE_ON_EXIT=FALSE + wso2carbon + wso2carbon + org.h2.Driver 50 60000 true diff --git a/features/heartbeat-management/pom.xml b/features/heartbeat-management/pom.xml index d477935ba8..0616963355 100644 --- a/features/heartbeat-management/pom.xml +++ b/features/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml index 5b8d527eb4..9d375e95c4 100644 --- a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml +++ b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt jwt-client-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/jwt-client/pom.xml b/features/jwt-client/pom.xml index b6898a23f3..5eced82de5 100644 --- a/features/jwt-client/pom.xml +++ b/features/jwt-client/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index 00da822151..0a9bff010c 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt policy-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml index c4fc708bf5..833e11aba4 100644 --- a/features/policy-mgt/pom.xml +++ b/features/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/task-mgt/io.entgra.task.mgt.feature/pom.xml b/features/task-mgt/io.entgra.task.mgt.feature/pom.xml new file mode 100755 index 0000000000..c285c53040 --- /dev/null +++ b/features/task-mgt/io.entgra.task.mgt.feature/pom.xml @@ -0,0 +1,112 @@ + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 5.0.20-SNAPSHOT + ../../../pom.xml + + + 4.0.0 + io.entgra.task.mgt.feature + pom + Entgra IoT - Task Manager Feature + http://wso2.org + + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.core + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.common + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.task.mgt + ../../../features/etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + org.eclipse.equinox.p2.type.group:true + + + + + org.wso2.carbon.devicemgt:io.entgra.task.mgt.core:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:io.entgra.task.mgt.common:${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt:io.entgra.task.mgt.watcher:${carbon.device.mgt.version} + + + + + + + + + + \ No newline at end of file diff --git a/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/build.properties b/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/build.properties new file mode 100755 index 0000000000..9c86577d76 --- /dev/null +++ b/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom = true diff --git a/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/conf/task-mgt-config.xml b/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/conf/task-mgt-config.xml new file mode 100755 index 0000000000..13fe285258 --- /dev/null +++ b/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/conf/task-mgt-config.xml @@ -0,0 +1,29 @@ + + + + + + + jdbc/DM_DS + + + + false + + diff --git a/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/conf_templates/templates/repository/conf/task-mgt-config.xml.j2 b/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/conf_templates/templates/repository/conf/task-mgt-config.xml.j2 new file mode 100755 index 0000000000..a6897adf2e --- /dev/null +++ b/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/conf_templates/templates/repository/conf/task-mgt-config.xml.j2 @@ -0,0 +1,37 @@ + + + + + + + {% if task_mgt.datasource.name is defined %} + {{task_mgt.datasource.name}} + {% else %} + jdbc/DM_DS + {% endif %} + + + + {% if task_watcher.conf is defined %} + {{task_watcher.conf.enable}} + {% else %} + false + {% endif %} + + diff --git a/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/p2.inf b/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/p2.inf new file mode 100755 index 0000000000..58012d9c01 --- /dev/null +++ b/features/task-mgt/io.entgra.task.mgt.feature/src/main/resources/p2.inf @@ -0,0 +1,3 @@ +instructions.configure = \ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.task.mgt_${feature.version}/conf/task-mgt-config.xml,target:${installFolder}/../../../repository/conf/task-mgt-config.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/io.entgra.task.mgt_${feature.version}/conf_templates/,target:${installFolder}/../../resources/conf/,overwrite:true);\ \ No newline at end of file diff --git a/features/task-mgt/pom.xml b/features/task-mgt/pom.xml new file mode 100755 index 0000000000..26638a6aa2 --- /dev/null +++ b/features/task-mgt/pom.xml @@ -0,0 +1,42 @@ + + + + + + carbon-devicemgt + org.wso2.carbon.devicemgt + 5.0.20-SNAPSHOT + ../../pom.xml + + + 4.0.0 + task-mgt-feature + pom + Entgra IoT - Task Management Feature + http://entgra.io + + + io.entgra.task.mgt.feature + + + + + \ No newline at end of file diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml index 62f9d46506..c86636d487 100644 --- a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/email-sender/pom.xml b/features/transport-mgt/email-sender/pom.xml index a57c1f50eb..d0cbbef027 100644 --- a/features/transport-mgt/email-sender/pom.xml +++ b/features/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/pom.xml b/features/transport-mgt/pom.xml index fa38682e35..5de9c8c47c 100644 --- a/features/transport-mgt/pom.xml +++ b/features/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml index 86a55ac610..1a8e65ea70 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml index 451992da88..2ba975d2d4 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/pom.xml b/features/transport-mgt/sms-handler/pom.xml index e7013c7d92..629c08ba50 100644 --- a/features/transport-mgt/sms-handler/pom.xml +++ b/features/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml index 169058c88b..0afc3933c9 100644 --- a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml +++ b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor-feature io.entgra.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT 4.0.0 diff --git a/features/ui-request-interceptor/pom.xml b/features/ui-request-interceptor/pom.xml index c5fc298b55..6692653264 100644 --- a/features/ui-request-interceptor/pom.xml +++ b/features/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml index 325623131f..86fd0c7ae2 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework-feature - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../pom.xml diff --git a/features/webapp-authenticator-framework/pom.xml b/features/webapp-authenticator-framework/pom.xml index a8ee0db879..35e608903c 100644 --- a/features/webapp-authenticator-framework/pom.xml +++ b/features/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT ../../pom.xml diff --git a/pom.xml b/pom.xml index 0cc945f483..baed2c7543 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt pom - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT WSO2 Carbon - Device Management - Parent http://wso2.org WSO2 Connected Device Manager Components @@ -46,6 +46,7 @@ components/transport-mgt components/analytics-mgt components/webapp-authenticator-framework + components/task-mgt features/device-mgt features/apimgt-extensions features/application-mgt @@ -58,6 +59,8 @@ features/transport-mgt features/analytics-mgt features/webapp-authenticator-framework + features/task-mgt + @@ -350,6 +353,29 @@ + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.common + ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.core + ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.watcher + ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + io.entgra.task.mgt.feature + zip + ${carbon.device.mgt.version} + + org.wso2.carbon @@ -2033,7 +2059,7 @@ 1.2.11.wso2v10 - 5.0.19-SNAPSHOT + 5.0.20-SNAPSHOT 4.7.35 @@ -2280,4 +2306,4 @@ - + \ No newline at end of file