Skip to content

Commit

Permalink
fix: formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
chillleader committed Jun 6, 2023
1 parent 33d27c8 commit c3a71f1
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@ camunda.operate.client.username=demo
camunda.operate.client.password=demo
camunda.connector.webhook.enabled=true

management.server.port=9080
management.context-path=/actuator
management.endpoints.web.exposure.include=metrics,health,prometheus
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ protected InboundConnectorResult<CorrelatedMessage> triggerMessage(
}
}

protected boolean isActivationConditionMet(InboundConnectorProperties properties, Object context) {
protected boolean isActivationConditionMet(
InboundConnectorProperties properties, Object context) {

String activationCondition = properties.getProperty(ACTIVATION_CONDITION_KEYWORD);
if (activationCondition == null || activationCondition.trim().length() == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class InboundConnectorRuntimeConfiguration {

@Bean
public InboundCorrelationHandler inboundCorrelationHandler(
final ZeebeClient zeebeClient, final FeelEngineWrapper feelEngine,
final ZeebeClient zeebeClient,
final FeelEngineWrapper feelEngine,
final MetricsRecorder metricsRecorder) {
return new MeteredInboundCorrelationHandler(zeebeClient, feelEngine, metricsRecorder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public class ProcessDefinitionImportConfiguration {

@Bean
public ProcessDefinitionImporter processDefinitionImporter(
CamundaOperateClient client, InboundConnectorManager manager,
CamundaOperateClient client,
InboundConnectorManager manager,
MetricsRecorder metricsRecorder) {
return new ProcessDefinitionImporter(client, manager, metricsRecorder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public class ProcessDefinitionImporter {

@Autowired
public ProcessDefinitionImporter(
CamundaOperateClient camundaOperateClient, InboundConnectorManager inboundManager,
CamundaOperateClient camundaOperateClient,
InboundConnectorManager inboundManager,
@Autowired(required = false) MetricsRecorder metricsRecorder) {
this.camundaOperateClient = camundaOperateClient;
this.inboundManager = inboundManager;
Expand Down Expand Up @@ -87,8 +88,7 @@ private void handleImportedDefinitions(List<ProcessDefinition> processDefinition
private void meter(int count) {
if (metricsRecorder != null) {
metricsRecorder.increase(
Inbound.METRIC_NAME_INBOUND_PROCESS_DEFINITIONS_CHECKED,
null, null, count);
Inbound.METRIC_NAME_INBOUND_PROCESS_DEFINITIONS_CHECKED, null, null, count);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ public InboundConnectorManager(
this.webhookConnectorRegistry = webhookConnectorRegistry;
}

/**
* Process a batch of process definitions
*/
/** Process a batch of process definitions */
public void registerProcessDefinitions(List<ProcessDefinition> processDefinitions) {
if (processDefinitions == null || processDefinitions.isEmpty()) {
return;
Expand Down Expand Up @@ -114,9 +112,7 @@ public void registerProcessDefinitions(List<ProcessDefinition> processDefinition
}
}

/**
* Check whether process definition with provided key is already registered
*/
/** Check whether process definition with provided key is already registered */
protected boolean isProcessDefinitionRegistered(long processDefinitionKey) {
return registeredProcessDefinitionKeys.contains(processDefinitionKey);
}
Expand Down Expand Up @@ -155,9 +151,7 @@ private void activateConnector(InboundConnectorProperties newProperties) {
}
inboundContext.reportHealth(Health.up());
metricsRecorder.increase(
Inbound.METRIC_NAME_ACTIVATIONS,
Inbound.ACTION_ACTIVATED,
newProperties.getType());
Inbound.METRIC_NAME_ACTIVATIONS, Inbound.ACTION_ACTIVATED, newProperties.getType());
} catch (Exception e) {
inboundContext.reportHealth(Health.down(e));
// log and continue with other connectors anyway
Expand Down Expand Up @@ -186,9 +180,7 @@ private void addActiveConnector(ActiveInboundConnector connector) {
private void deactivateConnector(InboundConnectorProperties properties) {
findActiveConnector(properties).ifPresent(this::deactivateConnector);
metricsRecorder.increase(
Inbound.METRIC_NAME_ACTIVATIONS,
Inbound.ACTION_DEACTIVATED,
properties.getType());
Inbound.METRIC_NAME_ACTIVATIONS, Inbound.ACTION_DEACTIVATED, properties.getType());
}

private void deactivateConnector(ActiveInboundConnector connector) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.inbound.lifecycle;

import io.camunda.connector.api.inbound.InboundConnectorResult;
Expand All @@ -12,15 +28,15 @@ public class MeteredInboundCorrelationHandler extends InboundCorrelationHandler

private final MetricsRecorder metricsRecorder;

public MeteredInboundCorrelationHandler(ZeebeClient zeebeClient,
FeelEngineWrapper feelEngine, MetricsRecorder metricsRecorder) {
public MeteredInboundCorrelationHandler(
ZeebeClient zeebeClient, FeelEngineWrapper feelEngine, MetricsRecorder metricsRecorder) {
super(zeebeClient, feelEngine);
this.metricsRecorder = metricsRecorder;
}

@Override
protected boolean isActivationConditionMet(InboundConnectorProperties properties,
Object context) {
protected boolean isActivationConditionMet(
InboundConnectorProperties properties, Object context) {
boolean isConditionMet = super.isActivationConditionMet(properties, context);
if (!isConditionMet) {
metricsRecorder.increase(
Expand All @@ -32,27 +48,21 @@ protected boolean isActivationConditionMet(InboundConnectorProperties properties
}

@Override
public InboundConnectorResult<?> correlate(InboundConnectorProperties properties,
Object variables) {
public InboundConnectorResult<?> correlate(
InboundConnectorProperties properties, Object variables) {
metricsRecorder.increase(
Inbound.METRIC_NAME_TRIGGERS,
Inbound.ACTION_TRIGGERED,
properties.getType());
Inbound.METRIC_NAME_TRIGGERS, Inbound.ACTION_TRIGGERED, properties.getType());

try {
var result = super.correlate(properties, variables);
if (result.isActivated()) {
metricsRecorder.increase(
Inbound.METRIC_NAME_TRIGGERS,
Inbound.ACTION_CORRELATED,
properties.getType());
Inbound.METRIC_NAME_TRIGGERS, Inbound.ACTION_CORRELATED, properties.getType());
}
return result;
} catch (Exception e) {
metricsRecorder.increase(
Inbound.METRIC_NAME_TRIGGERS,
Inbound.ACTION_CORRELATION_FAILED,
properties.getType());
Inbound.METRIC_NAME_TRIGGERS, Inbound.ACTION_CORRELATION_FAILED, properties.getType());
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.runtime.metrics;

import io.camunda.zeebe.spring.client.metrics.MetricsRecorder;
Expand All @@ -19,7 +35,8 @@ public static class Outbound {
public static class Inbound {
public static final String METRIC_NAME_ACTIVATIONS = "camunda.connector.inbound.activations";
public static final String METRIC_NAME_TRIGGERS = "camunda.connector.inbound.triggers";
public static final String METRIC_NAME_INBOUND_PROCESS_DEFINITIONS_CHECKED = "camunda.connector.inbound.process-definitions-checked";
public static final String METRIC_NAME_INBOUND_PROCESS_DEFINITIONS_CHECKED =
"camunda.connector.inbound.process-definitions-checked";

public static final String ACTION_ACTIVATED = "activated";
public static final String ACTION_DEACTIVATED = "deactivated";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ public void handle(JobClient client, ActivatedJob job) {
@Override
protected void failJob(JobClient client, ActivatedJob job, Exception exception) {
metricsRecorder.increase(
Outbound.METRIC_NAME_INVOCATIONS,
Outbound.ACTION_FAILED,
connectorConfiguration.getType());
Outbound.METRIC_NAME_INVOCATIONS, Outbound.ACTION_FAILED, connectorConfiguration.getType());
// rethrowing the exception enables retries (handled by JobRunnableFactory)
throw new RuntimeException(exception);
}
Expand All @@ -85,12 +83,12 @@ protected void throwBpmnError(JobClient client, ActivatedJob job, BpmnError valu
Outbound.ACTION_BPMN_ERROR,
connectorConfiguration.getType());
new CommandWrapper(
client
.newThrowErrorCommand(job.getKey())
.errorCode(value.getCode())
.errorMessage(value.getMessage()),
job,
commandExceptionHandlingStrategy)
client
.newThrowErrorCommand(job.getKey())
.errorCode(value.getCode())
.errorMessage(value.getMessage()),
job,
commandExceptionHandlingStrategy)
.executeAsync();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
import io.camunda.connector.runtime.inbound.importer.ProcessDefinitionInspector;
import io.camunda.connector.runtime.inbound.webhook.WebhookConnectorRegistry;
import io.camunda.operate.dto.ProcessDefinition;
import io.camunda.zeebe.spring.client.metrics.DefaultNoopMetricsRecorder;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class InboundConnectorManagerTest {

private InboundConnectorManager manager;
private ProcessDefinitionTestUtil procDefUtil;
private InboundConnectorFactory factory;
Expand All @@ -79,7 +81,12 @@ void resetMocks() {

manager =
new InboundConnectorManager(
factory, correlationHandler, inspector, secretProviderAggregator, webhookRegistry);
factory,
correlationHandler,
inspector,
secretProviderAggregator,
new DefaultNoopMetricsRecorder(),
webhookRegistry);
procDefUtil = new ProcessDefinitionTestUtil(manager, inspector);
}

Expand Down Expand Up @@ -244,7 +251,12 @@ void shouldNotActivateWebhookWhenDisabled() throws Exception {
// emulating camunda.connector.webhook.enabled=false
manager =
new InboundConnectorManager(
factory, correlationHandler, inspector, secretProviderAggregator, null);
factory,
correlationHandler,
inspector,
secretProviderAggregator,
new DefaultNoopMetricsRecorder(),
null);
procDefUtil = new ProcessDefinitionTestUtil(manager, inspector);

when(factory.getInstance("io.camunda:test-webhook:1")).thenReturn(webhookConnectorExecutable);
Expand Down

0 comments on commit c3a71f1

Please sign in to comment.