use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbAlarmNodeTest method initWithClearAlarmScript.
private void initWithClearAlarmScript() {
try {
TbClearAlarmNodeConfiguration config = new TbClearAlarmNodeConfiguration();
config.setAlarmType("SomeType");
config.setAlarmDetailsBuildJs("DETAILS");
ObjectMapper mapper = new ObjectMapper();
TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
when(ctx.createJsScriptEngine("DETAILS")).thenReturn(detailsJs);
when(ctx.getTenantId()).thenReturn(tenantId);
when(ctx.getAlarmService()).thenReturn(alarmService);
when(ctx.getDbCallbackExecutor()).thenReturn(dbExecutor);
node = new TbClearAlarmNode();
node.init(ctx, nodeConfiguration);
} catch (TbNodeException ex) {
throw new IllegalStateException(ex);
}
}
use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbAlarmNodeTest method initWithCreateAlarmScript.
private void initWithCreateAlarmScript() {
try {
TbCreateAlarmNodeConfiguration config = new TbCreateAlarmNodeConfiguration();
config.setPropagate(true);
config.setSeverity(CRITICAL.name());
config.setAlarmType("SomeType");
config.setAlarmDetailsBuildJs("DETAILS");
ObjectMapper mapper = new ObjectMapper();
TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
when(ctx.createJsScriptEngine("DETAILS")).thenReturn(detailsJs);
when(ctx.getTenantId()).thenReturn(tenantId);
when(ctx.getAlarmService()).thenReturn(alarmService);
when(ctx.getDbCallbackExecutor()).thenReturn(dbExecutor);
node = new TbCreateAlarmNode();
node.init(ctx, nodeConfiguration);
} catch (TbNodeException ex) {
throw new IllegalStateException(ex);
}
}
use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbKafkaNode method init.
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbKafkaNodeConfiguration.class);
this.initError = null;
Properties properties = new Properties();
properties.put(ProducerConfig.CLIENT_ID_CONFIG, "producer-tb-kafka-node-" + ctx.getSelfId().getId().toString() + "-" + ctx.getServiceId());
properties.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, config.getBootstrapServers());
properties.put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, config.getValueSerializer());
properties.put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, config.getKeySerializer());
properties.put(ProducerConfig.ACKS_CONFIG, config.getAcks());
properties.put(ProducerConfig.RETRIES_CONFIG, config.getRetries());
properties.put(ProducerConfig.BATCH_SIZE_CONFIG, config.getBatchSize());
properties.put(ProducerConfig.LINGER_MS_CONFIG, config.getLinger());
properties.put(ProducerConfig.BUFFER_MEMORY_CONFIG, config.getBufferMemory());
if (config.getOtherProperties() != null) {
config.getOtherProperties().forEach(properties::put);
}
addMetadataKeyValuesAsKafkaHeaders = BooleanUtils.toBooleanDefaultIfNull(config.isAddMetadataKeyValuesAsKafkaHeaders(), false);
toBytesCharset = config.getKafkaHeadersCharset() != null ? Charset.forName(config.getKafkaHeadersCharset()) : StandardCharsets.UTF_8;
try {
this.producer = new KafkaProducer<>(properties);
Thread ioThread = (Thread) ReflectionUtils.getField(IO_THREAD_FIELD, producer);
ioThread.setUncaughtExceptionHandler((thread, throwable) -> {
if (throwable instanceof ThingsboardKafkaClientError) {
initError = throwable;
destroy();
}
});
} catch (Exception e) {
throw new TbNodeException(e);
}
}
use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbRabbitMqNode method init.
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
this.config = TbNodeUtils.convert(configuration, TbRabbitMqNodeConfiguration.class);
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(this.config.getHost());
factory.setPort(this.config.getPort());
factory.setVirtualHost(this.config.getVirtualHost());
factory.setUsername(this.config.getUsername());
factory.setPassword(this.config.getPassword());
factory.setAutomaticRecoveryEnabled(this.config.isAutomaticRecoveryEnabled());
factory.setConnectionTimeout(this.config.getConnectionTimeout());
factory.setHandshakeTimeout(this.config.getHandshakeTimeout());
this.config.getClientProperties().forEach((k, v) -> factory.getClientProperties().put(k, v));
try {
this.connection = factory.newConnection();
this.channel = this.connection.createChannel();
} catch (Exception e) {
throw new TbNodeException(e);
}
}
use of org.thingsboard.rule.engine.api.TbNodeException in project thingsboard by thingsboard.
the class TbAzureIotHubNode method init.
@Override
public void init(TbContext ctx, TbNodeConfiguration configuration) throws TbNodeException {
try {
this.mqttNodeConfiguration = TbNodeUtils.convert(configuration, TbMqttNodeConfiguration.class);
mqttNodeConfiguration.setPort(8883);
mqttNodeConfiguration.setCleanSession(true);
ClientCredentials credentials = mqttNodeConfiguration.getCredentials();
if (CredentialsType.CERT_PEM == credentials.getType()) {
CertPemCredentials pemCredentials = (CertPemCredentials) credentials;
if (pemCredentials.getCaCert() == null || pemCredentials.getCaCert().isEmpty()) {
pemCredentials.setCaCert(AzureIotHubUtil.getDefaultCaCert());
}
}
this.mqttClient = initClient(ctx);
} catch (Exception e) {
throw new TbNodeException(e);
}
}
Aggregations