|
|
@ -32,6 +32,7 @@ import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvi
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
|
|
|
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagerStartupListener;
|
|
|
@ -73,23 +74,19 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
throw new DeviceManagementException("No tenant available for tenant domain " + tenantDomain);
|
|
|
|
throw new DeviceManagementException("No tenant available for tenant domain " + tenantDomain);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
synchronized (providers) {
|
|
|
|
synchronized (providers) {
|
|
|
|
try {
|
|
|
|
if (isInitiated) {
|
|
|
|
if (isInitiated) {
|
|
|
|
/* Initializing Device Management Service Provider */
|
|
|
|
/* Initializing Device Management Service Provider */
|
|
|
|
provider.init();
|
|
|
|
provider.init();
|
|
|
|
DeviceManagerUtil.registerDeviceType(deviceType, tenantId, isSharedWithAllTenants);
|
|
|
|
DeviceManagerUtil.registerDeviceType(deviceType, tenantId, isSharedWithAllTenants);
|
|
|
|
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(deviceType,
|
|
|
|
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(deviceType,
|
|
|
|
provider.getDeviceManager().
|
|
|
|
provider.getDeviceManager().
|
|
|
|
requireDeviceAuthorization());
|
|
|
|
requireDeviceAuthorization());
|
|
|
|
registerPushNotificationStrategy(provider);
|
|
|
|
registerPushNotificationStrategy(provider);
|
|
|
|
registerMonitoringTask(provider);
|
|
|
|
registerMonitoringTask(provider);
|
|
|
|
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
|
|
|
|
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
|
|
|
|
DeviceType deviceTypeObj = DeviceManagerUtil.getDeviceType(deviceType, tenantId);
|
|
|
|
registerDeviceStatusMonitoringTask(provider);
|
|
|
|
registerDeviceStatusMonitoringTask(deviceTypeObj, provider);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException("Error occurred while adding device management provider '" +
|
|
|
|
|
|
|
|
deviceType + "'", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isSharedWithAllTenants) {
|
|
|
|
if (isSharedWithAllTenants) {
|
|
|
|
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType);
|
|
|
|
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceType);
|
|
|
@ -118,7 +115,9 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
unregisterPushNotificationStrategy(deviceTypeIdentifier);
|
|
|
|
unregisterPushNotificationStrategy(deviceTypeIdentifier);
|
|
|
|
unregisterMonitoringTask(provider);
|
|
|
|
unregisterMonitoringTask(provider);
|
|
|
|
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
|
|
|
|
if (deviceManagementConfig != null && deviceManagementConfig.getDeviceStatusTaskConfig().isEnabled()) {
|
|
|
|
unregisterDeviceStatusMonitoringTask(provider);
|
|
|
|
DeviceType deviceTypeObj = DeviceManagerUtil.getDeviceType(deviceTypeIdentifier.getDeviceType(),
|
|
|
|
|
|
|
|
deviceTypeIdentifier.getTenantId());
|
|
|
|
|
|
|
|
unregisterDeviceStatusMonitoringTask(deviceTypeObj, provider);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -162,30 +161,30 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
|
|
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
boolean isSharedWithAllTenants = deviceManagementService.getProvisioningConfig().isSharedWithAllTenants();
|
|
|
|
boolean isSharedWithAllTenants = deviceManagementService.getProvisioningConfig().isSharedWithAllTenants();
|
|
|
|
DeviceTypeIdentifier deviceTypeIdentifier;
|
|
|
|
DeviceTypeIdentifier deviceTypeIdentifier;
|
|
|
|
if (isSharedWithAllTenants) {
|
|
|
|
if (isSharedWithAllTenants) {
|
|
|
|
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType());
|
|
|
|
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType());
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType(), tenantId);
|
|
|
|
deviceTypeIdentifier = new DeviceTypeIdentifier(deviceManagementService.getType(), tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pushNoteConfig != null) {
|
|
|
|
if (pushNoteConfig != null) {
|
|
|
|
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
|
|
|
|
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
|
|
|
|
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
|
|
|
|
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
|
|
|
|
if (provider == null) {
|
|
|
|
if (provider == null) {
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
"No registered push notification provider found for the type: '" +
|
|
|
|
"No registered push notification provider found for the type: '" +
|
|
|
|
pushNoteConfig.getType() + "'.");
|
|
|
|
pushNoteConfig.getType() + "'.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
|
|
|
|
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(), notificationStrategy));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
|
|
|
|
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(), notificationStrategy));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
PrivilegedCarbonContext.endTenantFlow();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -231,18 +230,18 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void registerDeviceStatusMonitoringTask(DeviceManagementService deviceManagementService) throws
|
|
|
|
private void registerDeviceStatusMonitoringTask(DeviceType deviceType, DeviceManagementService deviceManagementService) throws
|
|
|
|
DeviceManagementException {
|
|
|
|
DeviceManagementException {
|
|
|
|
DeviceTaskManagerService deviceTaskManagerService = DeviceManagementDataHolder.getInstance().
|
|
|
|
DeviceTaskManagerService deviceTaskManagerService = DeviceManagementDataHolder.getInstance().
|
|
|
|
getDeviceTaskManagerService();
|
|
|
|
getDeviceTaskManagerService();
|
|
|
|
DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig = deviceManagementService.getDeviceStatusTaskPluginConfig();
|
|
|
|
DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig = deviceManagementService.getDeviceStatusTaskPluginConfig();
|
|
|
|
if (deviceStatusTaskPluginConfig != null && deviceStatusTaskPluginConfig.isRequireStatusMonitoring()) {
|
|
|
|
if (deviceStatusTaskPluginConfig != null && deviceStatusTaskPluginConfig.isRequireStatusMonitoring()) {
|
|
|
|
if (deviceTaskManagerService == null) {
|
|
|
|
if (deviceTaskManagerService == null) {
|
|
|
|
DeviceManagementDataHolder.getInstance().addDeviceStatusTaskPluginConfig(deviceManagementService.getType(),
|
|
|
|
DeviceManagementDataHolder.getInstance().addDeviceStatusTaskPluginConfig(deviceType,
|
|
|
|
deviceStatusTaskPluginConfig);
|
|
|
|
deviceStatusTaskPluginConfig);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
new DeviceStatusTaskManagerServiceImpl().startTask(deviceManagementService.getType(), deviceStatusTaskPluginConfig);
|
|
|
|
new DeviceStatusTaskManagerServiceImpl().startTask(deviceType, deviceStatusTaskPluginConfig);
|
|
|
|
} catch (DeviceStatusTaskException e) {
|
|
|
|
} catch (DeviceStatusTaskException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while adding Device Status task service for '" +
|
|
|
|
throw new DeviceManagementException("Error occurred while adding Device Status task service for '" +
|
|
|
|
deviceManagementService.getType() + "'", e);
|
|
|
|
deviceManagementService.getType() + "'", e);
|
|
|
@ -251,21 +250,21 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void unregisterDeviceStatusMonitoringTask(DeviceManagementService deviceManagementService) throws
|
|
|
|
private void unregisterDeviceStatusMonitoringTask(DeviceType deviceType, DeviceManagementService deviceManagementService) throws
|
|
|
|
DeviceManagementException {
|
|
|
|
DeviceManagementException {
|
|
|
|
DeviceStatusTaskManagerService deviceStatusTaskManagerService = DeviceManagementDataHolder.getInstance().
|
|
|
|
DeviceStatusTaskManagerService deviceStatusTaskManagerService = DeviceManagementDataHolder.getInstance().
|
|
|
|
getDeviceStatusTaskManagerService();
|
|
|
|
getDeviceStatusTaskManagerService();
|
|
|
|
DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig = deviceManagementService.getDeviceStatusTaskPluginConfig();
|
|
|
|
DeviceStatusTaskPluginConfig deviceStatusTaskPluginConfig = deviceManagementService.getDeviceStatusTaskPluginConfig();
|
|
|
|
if (deviceStatusTaskPluginConfig != null && deviceStatusTaskPluginConfig.isRequireStatusMonitoring()) {
|
|
|
|
if (deviceStatusTaskPluginConfig != null && deviceStatusTaskPluginConfig.isRequireStatusMonitoring()) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceManagementDataHolder.getInstance().removeDeviceStatusTaskPluginConfig(deviceManagementService.getType());
|
|
|
|
DeviceManagementDataHolder.getInstance().removeDeviceStatusTaskPluginConfig(deviceType);
|
|
|
|
deviceStatusTaskManagerService.stopTask(deviceManagementService.getType(), deviceStatusTaskPluginConfig);
|
|
|
|
deviceStatusTaskManagerService.stopTask(deviceType, deviceStatusTaskPluginConfig);
|
|
|
|
} catch (DeviceStatusTaskException e) {
|
|
|
|
} catch (DeviceStatusTaskException e) {
|
|
|
|
throw new DeviceManagementException("Error occurred while stopping Device Status task service for '" +
|
|
|
|
throw new DeviceManagementException("Error occurred while stopping Device Status task service for '" +
|
|
|
|
deviceManagementService.getType() + "'", e);
|
|
|
|
deviceManagementService.getType() + "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public OperationManager getOperationManager(String deviceType, int tenantId) {
|
|
|
|
public OperationManager getOperationManager(String deviceType, int tenantId) {
|
|
|
|
//Priority need to be given to the tenant before public.
|
|
|
|
//Priority need to be given to the tenant before public.
|
|
|
@ -289,7 +288,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
|
|
|
|
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
|
|
|
|
int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
|
|
|
|
int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
|
|
|
|
DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId,
|
|
|
|
DeviceManagerUtil.registerDeviceType(deviceTypeName, tenantId,
|
|
|
|
provisioningConfig.isSharedWithAllTenants());
|
|
|
|
provisioningConfig.isSharedWithAllTenants());
|
|
|
|
registerPushNotificationStrategy(provider);
|
|
|
|
registerPushNotificationStrategy(provider);
|
|
|
|
registerMonitoringTask(provider);
|
|
|
|
registerMonitoringTask(provider);
|
|
|
|
|
|
|
|
|
|
|
@ -299,13 +298,13 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
//until fix that, use following variable to enable and disable of checking user authorization.
|
|
|
|
//until fix that, use following variable to enable and disable of checking user authorization.
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(provider.getType(),
|
|
|
|
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(provider.getType(),
|
|
|
|
provider.getDeviceManager()
|
|
|
|
provider.getDeviceManager()
|
|
|
|
.requireDeviceAuthorization());
|
|
|
|
.requireDeviceAuthorization());
|
|
|
|
} catch (Throwable e) {
|
|
|
|
} catch (Throwable e) {
|
|
|
|
/* Throwable is caught intentionally as failure of one plugin - due to invalid start up parameters,
|
|
|
|
/* Throwable is caught intentionally as failure of one plugin - due to invalid start up parameters,
|
|
|
|
etc - should not block the initialization of other device management providers */
|
|
|
|
etc - should not block the initialization of other device management providers */
|
|
|
|
log.error("Error occurred while initializing device management provider '" +
|
|
|
|
log.error("Error occurred while initializing device management provider '" +
|
|
|
|
provider.getType() + "'", e);
|
|
|
|
provider.getType() + "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.isInitiated = true;
|
|
|
|
this.isInitiated = true;
|
|
|
|