Skip to content

Commit

Permalink
Show registered workflows and Activities (#953)
Browse files Browse the repository at this point in the history
* Show registered workflow

Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* Add `NewWorkflowOption` to config version, time, input, etc when start a new workflow (#945)

* add NewWorkflowOption

Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>

* fix style

Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>

* add unit test

Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>

* add more unit tests for improving coverage

Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>

---------

Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* Update CLI link in example readme's (#951)

* Updated pre-requisite link to Dapr CLI

Signed-off-by: Michaël Hompus <michael@hompus.nl>

* Update JDK list to match all other examples

Signed-off-by: Michaël Hompus <michael@hompus.nl>

---------

Signed-off-by: Michaël Hompus <michael@hompus.nl>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* remove static

Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* Add determinstic UUID generation (#947)

* add determinstic UUID generation

Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>

* add unit test to improve coverage

Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>

* update grpc version to 1.59.0 to be compatible updated durabletask-java

Signed-off-by: kaibocai <kaibocai@microsoft.com>

---------

Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>
Signed-off-by: kaibocai <kaibocai@microsoft.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* fix flaky integration test ActorExceptionIT (#954)

Signed-off-by: MregXN <mregxn@gmail.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* fix flaky it ActorReminderRecovery (#958)

Signed-off-by: MregXN <mregxn@gmail.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* fix flaky integration test MethodInvokeIT (#959)

* fix flaky it MethodInvokeIT

Signed-off-by: MregXN <mregxn@gmail.com>

* add debug print

Signed-off-by: MregXN <mregxn@gmail.com>

* add debug print

Signed-off-by: MregXN <mregxn@gmail.com>

* add more waiting time

Signed-off-by: MregXN <mregxn@gmail.com>

* wait before invoke

Signed-off-by: MregXN <mregxn@gmail.com>

* wait for health before invoke

Signed-off-by: MregXN <mregxn@gmail.com>

---------

Signed-off-by: MregXN <mregxn@gmail.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* Fix errors

Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>

* make thead safe

* Fix code and test.

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

---------

Signed-off-by: addjuarez <6789375+addjuarez@users.noreply.github.com>
Signed-off-by: kaibocai <89094811+kaibocai@users.noreply.github.com>
Signed-off-by: Michaël Hompus <michael@hompus.nl>
Signed-off-by: kaibocai <kaibocai@microsoft.com>
Signed-off-by: MregXN <mregxn@gmail.com>
Signed-off-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Co-authored-by: kaibocai <89094811+kaibocai@users.noreply.github.com>
Co-authored-by: Michaël Hompus <michael@hompus.nl>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: MregXN <46479059+MregXN@users.noreply.github.com>
Co-authored-by: Dapr Bot <56698301+dapr-bot@users.noreply.github.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Co-authored-by: Artur Souza <asouza.pro@gmail.com>
  • Loading branch information
8 people authored Feb 16, 2024
1 parent a0ae3c3 commit 4458f4f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 38 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 The Dapr Authors
* Copyright 2024 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
Expand All @@ -18,11 +18,11 @@
import io.dapr.workflows.Workflow;
import io.dapr.workflows.internal.ApiTokenClientInterceptor;
import io.grpc.ClientInterceptor;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

public class WorkflowRuntimeBuilder {
private static volatile WorkflowRuntime instance;
Expand All @@ -31,14 +31,20 @@ public class WorkflowRuntimeBuilder {
private Set<String> workflows = new HashSet<String>();
private Set<String> activities = new HashSet<String>();
private static ClientInterceptor WORKFLOW_INTERCEPTOR = new ApiTokenClientInterceptor();
private final Set<String> activitySet = Collections.synchronizedSet(new HashSet<>());
private final Set<String> workflowSet = Collections.synchronizedSet(new HashSet<>());

/**
* Constructs the WorkflowRuntimeBuilder.
*/
public WorkflowRuntimeBuilder() {
this(LoggerFactory.getLogger(WorkflowRuntimeBuilder.class));
}

WorkflowRuntimeBuilder(Logger logger) {
this.builder = new DurableTaskGrpcWorkerBuilder().grpcChannel(
NetworkUtils.buildGrpcManagedChannel(WORKFLOW_INTERCEPTOR));
this.logger = Logger.getLogger(WorkflowRuntimeBuilder.class.getName());
NetworkUtils.buildGrpcManagedChannel(WORKFLOW_INTERCEPTOR));
this.logger = logger;
}

/**
Expand All @@ -54,7 +60,9 @@ public WorkflowRuntime build() {
}
}
}
this.logger.log(Level.INFO, "Successfully built dapr workflow runtime");
this.logger.info("List of registered workflows: " + this.workflowSet);
this.logger.info("List of registered activites: " + this.activitySet);
this.logger.info("Successfully built dapr workflow runtime");
return instance;
}

Expand All @@ -69,7 +77,8 @@ public <T extends Workflow> WorkflowRuntimeBuilder registerWorkflow(Class<T> cla
this.builder = this.builder.addOrchestration(
new OrchestratorWrapper<>(clazz)
);
this.logger.log(Level.INFO, "Registered Workflow: " + clazz.getSimpleName());
this.workflowSet.add(clazz.getCanonicalName());
this.logger.info("Registered Workflow: " + clazz.getSimpleName());
this.workflows.add(clazz.getSimpleName());
return this;
}
Expand All @@ -84,7 +93,8 @@ public <T extends WorkflowActivity> void registerActivity(Class<T> clazz) {
this.builder = this.builder.addActivity(
new ActivityWrapper<>(clazz)
);
this.logger.log(Level.INFO, "Registered Activity: " + clazz.getSimpleName());
this.activitySet.add(clazz.getCanonicalName());
this.logger.info("Registered Activity: " + clazz.getSimpleName());
this.activities.add(clazz.getSimpleName());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
/*
* Copyright 2024 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* 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.dapr.workflows.runtime;


import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.slf4j.Logger;

import static org.junit.Assert.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.logging.Logger;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

public class WorkflowRuntimeBuilderTest {
public static class TestWorkflow extends Workflow {
Expand Down Expand Up @@ -51,36 +61,19 @@ public void loggingOutputTest() {
ByteArrayOutputStream outStreamCapture = new ByteArrayOutputStream();
System.setOut(new PrintStream(outStreamCapture));

LogCaptureHandler testLoggerHandler = new LogCaptureHandler();
Logger testLogger = Logger.getLogger(WorkflowRuntimeBuilder.class.getName());
Logger testLogger = Mockito.mock(Logger.class);

testLogger.addHandler(testLoggerHandler);

// indexOf will return -1 if the string is not found.
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerWorkflow(TestWorkflow.class));
assertNotEquals(-1, testLoggerHandler.capturedLog.indexOf("Registered Workflow: TestWorkflow"));
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder().registerActivity(TestActivity.class));
assertNotEquals(-1, testLoggerHandler.capturedLog.indexOf("Registered Activity: TestActivity"));
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder(testLogger).registerWorkflow(TestWorkflow.class));
assertDoesNotThrow(() -> new WorkflowRuntimeBuilder(testLogger).registerActivity(TestActivity.class));

WorkflowRuntimeBuilder wfRuntime = new WorkflowRuntimeBuilder();

wfRuntime.build();
}

private static class LogCaptureHandler extends Handler {
private StringBuilder capturedLog = new StringBuilder();

@Override
public void publish(LogRecord record) {
capturedLog.append(record.getMessage()).append(System.lineSeparator());
}

@Override
public void flush(){
}

@Override
public void close() throws SecurityException {
}
Mockito.verify(testLogger, Mockito.times(1))
.info(Mockito.eq("Registered Workflow: TestWorkflow"));
Mockito.verify(testLogger, Mockito.times(1))
.info(Mockito.eq("Registered Activity: TestActivity"));
}

}

0 comments on commit 4458f4f

Please sign in to comment.