Search in sources :

Example 1 with PluginId

use of org.thingsboard.server.common.data.id.PluginId in project thingsboard by thingsboard.

the class BasicRpcSessionListener method deserialize.

private static ToPluginRpcResponseDeviceMsg deserialize(ServerAddress serverAddress, ClusterAPIProtos.ToPluginRpcResponseRpcMessage msg) {
    ClusterAPIProtos.PluginAddress address = msg.getAddress();
    TenantId pluginTenantId = new TenantId(toUUID(address.getTenantId()));
    PluginId pluginId = new PluginId(toUUID(address.getPluginId()));
    RpcError error = !StringUtils.isEmpty(msg.getError()) ? RpcError.valueOf(msg.getError()) : null;
    FromDeviceRpcResponse response = new FromDeviceRpcResponse(toUUID(msg.getMsgId()), msg.getResponse(), error);
    return new ToPluginRpcResponseDeviceMsg(pluginId, pluginTenantId, response);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) ClusterAPIProtos(org.thingsboard.server.gen.cluster.ClusterAPIProtos) PluginId(org.thingsboard.server.common.data.id.PluginId)

Example 2 with PluginId

use of org.thingsboard.server.common.data.id.PluginId 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 3 with PluginId

use of org.thingsboard.server.common.data.id.PluginId 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)

Example 4 with PluginId

use of org.thingsboard.server.common.data.id.PluginId in project thingsboard by thingsboard.

the class JpaBasePluginDaoTest method createPlugin.

private void createPlugin(UUID tenantId, String namePrefix, int i) {
    PluginMetaData plugin = new PluginMetaData();
    plugin.setId(new PluginId(UUIDs.timeBased()));
    plugin.setTenantId(new TenantId(tenantId));
    plugin.setName(namePrefix + i);
    pluginDao.save(plugin);
}
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)

Example 5 with PluginId

use of org.thingsboard.server.common.data.id.PluginId in project thingsboard by thingsboard.

the class PluginController method activatePluginById.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugin/{pluginId}/activate", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void activatePluginById(@PathVariable(PLUGIN_ID) String strPluginId) throws ThingsboardException {
    checkParameter(PLUGIN_ID, strPluginId);
    try {
        PluginId pluginId = new PluginId(toUUID(strPluginId));
        PluginMetaData plugin = checkPlugin(pluginService.findPluginById(pluginId));
        pluginService.activatePluginById(pluginId);
        actorService.onPluginStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.ACTIVATED);
        logEntityAction(plugin.getId(), plugin, null, ActionType.ACTIVATED, null, strPluginId);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.PLUGIN), null, null, ActionType.ACTIVATED, e, strPluginId);
        throw handleException(e);
    }
}
Also used : PluginMetaData(org.thingsboard.server.common.data.plugin.PluginMetaData) PluginId(org.thingsboard.server.common.data.id.PluginId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

PluginId (org.thingsboard.server.common.data.id.PluginId)11 TenantId (org.thingsboard.server.common.data.id.TenantId)7 PluginMetaData (org.thingsboard.server.common.data.plugin.PluginMetaData)7 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)3 ClusterAPIProtos (org.thingsboard.server.gen.cluster.ClusterAPIProtos)3 ActorRef (akka.actor.ActorRef)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 Collectors (java.util.stream.Collectors)1 Slf4j (lombok.extern.slf4j.Slf4j)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 Service (org.springframework.stereotype.Service)1 DeviceId (org.thingsboard.server.common.data.id.DeviceId)1 RuleId (org.thingsboard.server.common.data.id.RuleId)1 TextPageData (org.thingsboard.server.common.data.page.TextPageData)1