Search in sources :

Example 1 with PluginMetaData

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;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) IOException(java.io.IOException)

Example 2 with 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();
    }
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData)

Example 3 with PluginMetaData

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!");
    }
}
Also used : ComponentType(org.thingsboard.server.common.data.plugin.ComponentType) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Autowired(org.springframework.beans.factory.annotation.Autowired) TextPageData(org.thingsboard.server.common.data.page.TextPageData) StringUtils(org.apache.commons.lang3.StringUtils) TenantId(org.thingsboard.server.common.data.id.TenantId) DataValidator(org.thingsboard.server.dao.service.DataValidator) ArrayList(java.util.ArrayList) Validator.validateId(org.thingsboard.server.dao.service.Validator.validateId) ComponentLifecycleState(org.thingsboard.server.common.data.plugin.ComponentLifecycleState) PluginId(org.thingsboard.server.common.data.id.PluginId) Service(org.springframework.stereotype.Service) ComponentDescriptorService(org.thingsboard.server.dao.component.ComponentDescriptorService) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) Validator(org.thingsboard.server.dao.service.Validator) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) DatabaseException(org.thingsboard.server.dao.exception.DatabaseException) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) RuleDao(org.thingsboard.server.dao.rule.RuleDao) Slf4j(lombok.extern.slf4j.Slf4j) AbstractEntityService(org.thingsboard.server.dao.entity.AbstractEntityService) List(java.util.List) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) PaginatedRemover(org.thingsboard.server.dao.service.PaginatedRemover) ComponentDescriptor(org.thingsboard.server.common.data.plugin.ComponentDescriptor) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ModelConstants(org.thingsboard.server.dao.model.ModelConstants) DataValidationException(org.thingsboard.server.dao.exception.DataValidationException) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData)

Example 4 with PluginMetaData

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;
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData)

Example 5 with 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;
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) PluginId(org.thingsboard.server.common.data.id.PluginId)

Aggregations

PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)50 Test (org.junit.Test)24 TenantId (org.thingsboard.server.common.data.id.TenantId)17 AbstractServiceTest (org.thingsboard.server.dao.service.AbstractServiceTest)14 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)13 RuleMetaData (org.thingsboard.server.common.data.rule.RuleMetaData)13 PluginId (org.thingsboard.server.common.data.id.PluginId)8 TelemetryStoragePlugin (org.thingsboard.server.extensions.core.plugin.telemetry.TelemetryStoragePlugin)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)5 ArrayList (java.util.ArrayList)4 TextPageData (org.thingsboard.server.common.data.page.TextPageData)4 List (java.util.List)3 UUID (java.util.UUID)3 Before (org.junit.Before)3 Tenant (org.thingsboard.server.common.data.Tenant)3 ComponentDescriptor (org.thingsboard.server.common.data.plugin.ComponentDescriptor)3 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 DatabaseSetup (com.github.springtestdbunit.annotation.DatabaseSetup)2