Search in sources :

Example 6 with PluginId

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

the class PluginController method deletePlugin.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugin/{pluginId}", method = RequestMethod.DELETE)
@ResponseStatus(value = HttpStatus.OK)
public void deletePlugin(@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.deletePluginById(pluginId);
        actorService.onPluginStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.DELETED);
        logEntityAction(pluginId, plugin, null, ActionType.DELETED, null, strPluginId);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.PLUGIN), null, null, ActionType.DELETED, 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)

Example 7 with PluginId

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

the class PluginController method suspendPluginById.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/plugin/{pluginId}/suspend", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void suspendPluginById(@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.suspendPluginById(pluginId);
        actorService.onPluginStateChange(plugin.getTenantId(), plugin.getId(), ComponentLifecycleEvent.SUSPENDED);
        logEntityAction(plugin.getId(), plugin, null, ActionType.SUSPENDED, null, strPluginId);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.PLUGIN), null, null, ActionType.SUSPENDED, 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)

Example 8 with PluginId

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

the class TenantActor method onComponentLifecycleMsg.

private void onComponentLifecycleMsg(ComponentLifecycleMsg msg) {
    Optional<PluginId> pluginId = msg.getPluginId();
    Optional<RuleId> ruleId = msg.getRuleId();
    if (pluginId.isPresent()) {
        ActorRef pluginActor = pluginManager.getOrCreatePluginActor(this.context(), pluginId.get());
        pluginActor.tell(msg, ActorRef.noSender());
    } else if (ruleId.isPresent()) {
        ActorRef target;
        Optional<ActorRef> ref = ruleManager.update(this.context(), ruleId.get(), msg.getEvent());
        if (ref.isPresent()) {
            target = ref.get();
        } else {
            logger.debug("Failed to find actor for rule: [{}]", ruleId);
            return;
        }
        target.tell(msg, ActorRef.noSender());
    } else {
        logger.debug("[{}] Invalid component lifecycle msg.", tenantId);
    }
}
Also used : Optional(java.util.Optional) ActorRef(akka.actor.ActorRef) RuleId(org.thingsboard.server.common.data.id.RuleId) PluginId(org.thingsboard.server.common.data.id.PluginId)

Example 9 with PluginId

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

the class BasicRpcSessionListener method convert.

private static PluginRpcMsg convert(ServerAddress serverAddress, ClusterAPIProtos.ToPluginRpcMessage msg) {
    ClusterAPIProtos.PluginAddress address = msg.getAddress();
    TenantId tenantId = new TenantId(toUUID(address.getTenantId()));
    PluginId pluginId = new PluginId(toUUID(address.getPluginId()));
    RpcMsg rpcMsg = new RpcMsg(serverAddress, msg.getClazz(), msg.getData().toByteArray());
    return new PluginRpcMsg(tenantId, pluginId, rpcMsg);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) ClusterAPIProtos(org.thingsboard.server.gen.cluster.ClusterAPIProtos) PluginRpcMsg(org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg) PluginRpcMsg(org.thingsboard.server.extensions.api.plugins.rpc.PluginRpcMsg) RpcMsg(org.thingsboard.server.extensions.api.plugins.rpc.RpcMsg) PluginId(org.thingsboard.server.common.data.id.PluginId)

Example 10 with PluginId

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

the class BasicRpcSessionListener method deserialize.

private static ToDeviceRpcRequestPluginMsg deserialize(ServerAddress serverAddress, ClusterAPIProtos.ToDeviceRpcRequestRpcMessage msg) {
    ClusterAPIProtos.PluginAddress address = msg.getAddress();
    TenantId pluginTenantId = new TenantId(toUUID(address.getTenantId()));
    PluginId pluginId = new PluginId(toUUID(address.getPluginId()));
    TenantId deviceTenantId = new TenantId(toUUID(msg.getDeviceTenantId()));
    DeviceId deviceId = new DeviceId(toUUID(msg.getDeviceId()));
    ToDeviceRpcRequestBody requestBody = new ToDeviceRpcRequestBody(msg.getMethod(), msg.getParams());
    ToDeviceRpcRequest request = new ToDeviceRpcRequest(toUUID(msg.getMsgId()), null, deviceTenantId, deviceId, msg.getOneway(), msg.getExpTime(), requestBody);
    return new ToDeviceRpcRequestPluginMsg(serverAddress, pluginId, pluginTenantId, request);
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) ClusterAPIProtos(org.thingsboard.server.gen.cluster.ClusterAPIProtos) DeviceId(org.thingsboard.server.common.data.id.DeviceId) PluginId(org.thingsboard.server.common.data.id.PluginId)

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