|
|
@ -22,11 +22,13 @@ import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceManagementServiceHolder;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceStatusTaskPluginConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
|
|
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
|
|
@ -35,9 +37,7 @@ import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeDefinitionProvider;
|
|
|
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
|
|
|
import org.wso2.carbon.device.mgt.common.type.mgt.DeviceTypeMetaDefinition;
|
|
|
|
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.DeviceManagementServiceHolder;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
|
|
|
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
|
|
|
|
|
|
|
|
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;
|
|
|
@ -51,12 +51,9 @@ import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException;
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.task.DeviceTaskManagerService;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
|
|
|
|
public class DeviceManagementPluginRepository implements DeviceManagerStartupListener {
|
|
|
|
|
|
|
|
|
|
|
@ -158,9 +155,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
OperationManager operationManager = operationManagerRepository.getOperationManager(
|
|
|
|
OperationManager operationManager = operationManagerRepository.getOperationManager(
|
|
|
|
deviceTypeIdentifier);
|
|
|
|
deviceTypeIdentifier);
|
|
|
|
if (operationManager != null) {
|
|
|
|
if (operationManager != null) {
|
|
|
|
Collection<NotificationStrategy> notificationStrategies = operationManager.getNotificationStrategyMap()
|
|
|
|
NotificationStrategy notificationStrategy = operationManager.getNotificationStrategy();
|
|
|
|
.values();
|
|
|
|
if (notificationStrategy != null) {
|
|
|
|
for (NotificationStrategy notificationStrategy : notificationStrategies) {
|
|
|
|
|
|
|
|
notificationStrategy.undeploy();
|
|
|
|
notificationStrategy.undeploy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operationManagerRepository.removeOperationManager(deviceTypeIdentifier);
|
|
|
|
operationManagerRepository.removeOperationManager(deviceTypeIdentifier);
|
|
|
@ -208,7 +204,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
long updatedTimestamp = provider.getTimestamp();
|
|
|
|
long updatedTimestamp = provider.getTimestamp();
|
|
|
|
if (System.currentTimeMillis() - updatedTimestamp > DEFAULT_UPDATE_TIMESTAMP) {
|
|
|
|
if (System.currentTimeMillis() - updatedTimestamp > DEFAULT_UPDATE_TIMESTAMP) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
DeviceType deviceType = DeviceManagerUtil.getDeviceType(type, tenantId);
|
|
|
|
DeviceType deviceType = DeviceManagerUtil.getDeviceType(type,tenantId);
|
|
|
|
DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition();
|
|
|
|
DeviceTypeMetaDefinition deviceTypeMetaDefinition = deviceType.getDeviceTypeMetaDefinition();
|
|
|
|
if (deviceTypeMetaDefinition != null) {
|
|
|
|
if (deviceTypeMetaDefinition != null) {
|
|
|
|
Gson gson = new Gson();
|
|
|
|
Gson gson = new Gson();
|
|
|
@ -217,9 +213,8 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
provider.getDeviceManagementService()).getDeviceTypeMetaDefinition();
|
|
|
|
provider.getDeviceManagementService()).getDeviceTypeMetaDefinition();
|
|
|
|
String cachedDefinition = gson.toJson(deviceTypeMetaDefinition);
|
|
|
|
String cachedDefinition = gson.toJson(deviceTypeMetaDefinition);
|
|
|
|
if (!cachedDefinition.equals(dbStoredDefinition)) {
|
|
|
|
if (!cachedDefinition.equals(dbStoredDefinition)) {
|
|
|
|
DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder
|
|
|
|
DeviceManagementService deviceTypeManagerService = DeviceManagementDataHolder.getInstance()
|
|
|
|
.getInstance().getDeviceTypeGeneratorService()
|
|
|
|
.getDeviceTypeGeneratorService().populateDeviceManagementService(type, deviceTypeMetaDefinition);
|
|
|
|
.populateDeviceManagementService(type, deviceTypeMetaDefinition);
|
|
|
|
|
|
|
|
if (deviceTypeManagerService == null) {
|
|
|
|
if (deviceTypeManagerService == null) {
|
|
|
|
log.error("Failing to retrieve the device type service for " + type);
|
|
|
|
log.error("Failing to retrieve the device type service for " + type);
|
|
|
|
return null;
|
|
|
|
return null;
|
|
|
@ -253,7 +248,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
|
|
|
|
|
|
|
|
private void registerPushNotificationStrategy(DeviceManagementService deviceManagementService)
|
|
|
|
private void registerPushNotificationStrategy(DeviceManagementService deviceManagementService)
|
|
|
|
throws DeviceManagementException {
|
|
|
|
throws DeviceManagementException {
|
|
|
|
List<PushNotificationConfig> pushNoteConfigs = deviceManagementService.getPushNotificationConfigs();
|
|
|
|
PushNotificationConfig pushNoteConfig = deviceManagementService.getPushNotificationConfig();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
|
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
|
|
|
deviceManagementService.getProvisioningConfig().getProviderTenantDomain(), true);
|
|
|
@ -267,40 +262,17 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
|
|
|
|
deviceTypeIdentifier = new DeviceTypeServiceIdentifier(deviceManagementService.getType(), tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (pushNoteConfigs != null) {
|
|
|
|
if (pushNoteConfig != null) {
|
|
|
|
Map<String, NotificationStrategy> notificationStrategyMap = new ConcurrentHashMap<>();
|
|
|
|
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
|
|
|
|
NotificationStrategy defaultNotificationStrategy = null;
|
|
|
|
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
|
|
|
|
for (PushNotificationConfig pushNoteConfig : pushNoteConfigs) {
|
|
|
|
if (provider == null) {
|
|
|
|
PushNotificationProvider provider = DeviceManagementDataHolder.getInstance()
|
|
|
|
|
|
|
|
.getPushNotificationProviderRepository().getProvider(pushNoteConfig.getType());
|
|
|
|
|
|
|
|
if (provider == null) {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"No registered push notification provider found for the type: '" +
|
|
|
|
|
|
|
|
pushNoteConfig.getType() + "'.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
|
|
|
|
|
|
|
|
if (pushNoteConfig.isDefault()) {
|
|
|
|
|
|
|
|
if (defaultNotificationStrategy == null) {
|
|
|
|
|
|
|
|
defaultNotificationStrategy = notificationStrategy;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
|
|
|
|
"Multiple push notification strategies are set as default. Only one strategy can " +
|
|
|
|
|
|
|
|
"be set as default for the device type: '" + deviceTypeIdentifier
|
|
|
|
|
|
|
|
.getDeviceType() + "'.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
notificationStrategyMap.put(pushNoteConfig.getType(), notificationStrategy);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (defaultNotificationStrategy != null) {
|
|
|
|
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(),
|
|
|
|
|
|
|
|
defaultNotificationStrategy, notificationStrategyMap));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
"No registered default push notification provider found for the device type: '" + deviceTypeIdentifier
|
|
|
|
"No registered push notification provider found for the type: '" +
|
|
|
|
.getDeviceType() + "'.");
|
|
|
|
pushNoteConfig.getType() + "'.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NotificationStrategy notificationStrategy = provider.getNotificationStrategy(pushNoteConfig);
|
|
|
|
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType(), notificationStrategy));
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
operationManagerRepository.addOperationManager(deviceTypeIdentifier,
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType()));
|
|
|
|
new OperationManagerImpl(deviceTypeIdentifier.getDeviceType()));
|
|
|
@ -405,7 +377,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
|
|
|
|
String deviceTypeName;
|
|
|
|
String deviceTypeName;
|
|
|
|
synchronized (providers) {
|
|
|
|
synchronized (providers) {
|
|
|
|
for (DeviceManagementServiceHolder deviceManagementServiceHolder : providers.values()) {
|
|
|
|
for (DeviceManagementServiceHolder deviceManagementServiceHolder : providers.values()) {
|
|
|
|
DeviceManagementService provider = deviceManagementServiceHolder.getDeviceManagementService();
|
|
|
|
DeviceManagementService provider= deviceManagementServiceHolder.getDeviceManagementService();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
provider.init();
|
|
|
|
provider.init();
|
|
|
|
deviceTypeName = provider.getType();
|
|
|
|
deviceTypeName = provider.getType();
|
|
|
|