use of org.thingsboard.server.common.data.plugin.PluginMetaData in project thingsboard by thingsboard.
the class AbstractServiceTest method generatePlugin.
protected PluginMetaData generatePlugin(TenantId tenantId, String token, String clazz, String actions, String configurationDescriptorResource, String dataResource) throws IOException {
if (tenantId == null) {
tenantId = new TenantId(UUIDs.timeBased());
}
if (token == null) {
token = UUID.randomUUID().toString();
}
getOrCreateDescriptor(ComponentScope.TENANT, ComponentType.PLUGIN, clazz, configurationDescriptorResource, actions);
PluginMetaData pluginMetaData = new PluginMetaData();
pluginMetaData.setName("Testing");
pluginMetaData.setClazz(clazz);
pluginMetaData.setTenantId(tenantId);
pluginMetaData.setApiToken(token);
pluginMetaData.setAdditionalInfo(mapper.readTree("{\"test\":\"test\"}"));
try {
pluginMetaData.setConfiguration(readFromResource(dataResource));
} catch (IOException e) {
throw new RuntimeException(e);
}
return pluginMetaData;
}
use of org.thingsboard.server.common.data.plugin.PluginMetaData in project thingsboard by thingsboard.
the class PluginActorMessageProcessor method onUpdate.
@Override
public void onUpdate(ActorContext context) throws Exception {
PluginMetaData oldPluginMd = pluginMd;
pluginMd = systemContext.getPluginService().findPluginById(entityId);
boolean requiresRestart = false;
logger.info("[{}] Plugin configuration was updated from {} to {}.", entityId, oldPluginMd, pluginMd);
if (!oldPluginMd.getClazz().equals(pluginMd.getClazz())) {
logger.info("[{}] Plugin requires restart due to clazz change from {} to {}.", entityId, oldPluginMd.getClazz(), pluginMd.getClazz());
requiresRestart = true;
} else if (!oldPluginMd.getConfiguration().equals(pluginMd.getConfiguration())) {
logger.info("[{}] Plugin requires restart due to configuration change from {} to {}.", entityId, oldPluginMd.getConfiguration(), pluginMd.getConfiguration());
requiresRestart = true;
}
if (requiresRestart) {
this.state = ComponentLifecycleState.SUSPENDED;
if (pluginImpl != null) {
pluginImpl.stop(trustedCtx);
}
start();
}
}
use of org.thingsboard.server.common.data.plugin.PluginMetaData in project thingsboard by thingsboard.
the class BasePluginService method suspendPluginById.
@Override
public void suspendPluginById(PluginId pluginId) {
PluginMetaData plugin = pluginDao.findById(pluginId);
List<RuleMetaData> affectedRules = ruleDao.findRulesByPlugin(plugin.getApiToken()).stream().filter(rule -> rule.getState() == ComponentLifecycleState.ACTIVE).collect(Collectors.toList());
if (affectedRules.isEmpty()) {
updateLifeCycleState(pluginId, ComponentLifecycleState.SUSPENDED);
} else {
throw new DataValidationException("Can't suspend plugin that has active rules!");
}
}
use of org.thingsboard.server.common.data.plugin.PluginMetaData in project thingsboard by thingsboard.
the class CassandraBasePluginDao method findById.
@Override
public PluginMetaData findById(PluginId pluginId) {
log.debug("Search plugin meta-data entity by id [{}]", pluginId);
PluginMetaData pluginMetaData = super.findById(pluginId.getId());
if (log.isTraceEnabled()) {
log.trace("Search result: [{}] for plugin entity [{}]", pluginMetaData != null, pluginMetaData);
} else {
log.debug(SEARCH_RESULT, pluginMetaData != null);
}
return pluginMetaData;
}
use of org.thingsboard.server.common.data.plugin.PluginMetaData in project thingsboard by thingsboard.
the class PluginMetaDataEntity method toData.
@Override
public PluginMetaData toData() {
PluginMetaData data = new PluginMetaData(new PluginId(getId()));
data.setTenantId(new TenantId(fromString(tenantId)));
data.setCreatedTime(UUIDs.unixTimestamp(getId()));
data.setName(name);
data.setClazz(clazz);
data.setPublicAccess(publicAccess);
data.setState(state);
data.setApiToken(apiToken);
data.setConfiguration(configuration);
data.setAdditionalInfo(additionalInfo);
return data;
}
Aggregations