Skip to content

Commit

Permalink
Configuration file processor
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafacs committed Apr 26, 2021
1 parent 4c1449d commit a28b104
Show file tree
Hide file tree
Showing 15 changed files with 499 additions and 31 deletions.
@@ -1,8 +1,21 @@
package io.quarkus.temporal.client.deployment;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.temporal.runtime.TemporalAbstractConfiguration;
import io.quarkus.temporal.runtime.TemporalRecorder;
import io.quarkus.temporal.runtime.config.WorkflowConfigurations;
import javax.enterprise.context.ApplicationScoped;

/**
* @Author Mostafa Albana
*/
class TemporalClientProcessor {

private static final String FEATURE = "temporal-client";
Expand All @@ -11,4 +24,45 @@ class TemporalClientProcessor {
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
void initBeans(BuildProducer<AdditionalBeanBuildItem> additionalBeans) {
additionalBeans.produce(AdditionalBeanBuildItem.builder().addBeanClass(TemporalAbstractConfiguration.class).build());
}

@BuildStep
AdditionalApplicationArchiveMarkerBuildItem required() {
return new AdditionalApplicationArchiveMarkerBuildItem("workflow.yml");
}
@BuildStep
@Record(ExecutionTime.STATIC_INIT)
void buildConfigs(TemporalRecorder recorder,
BuildProducer<SyntheticBeanBuildItem> syntheticBeanBuildItemBuildProducer) throws Exception{

SyntheticBeanBuildItem syntheticBeanBuildItem = SyntheticBeanBuildItem.configure(WorkflowConfigurations.class)
.scope(ApplicationScoped.class)
.runtimeValue(recorder.createWorkflowConfigs())
.done();
syntheticBeanBuildItemBuildProducer.produce(syntheticBeanBuildItem);

}

// buildWorkflowFactories(BeanContainerBuildItem beanContainerBuildItem,
// CombinedIndexBuildItem combinedIndex
// ) {
// WorkflowClient workflowClient = beanContainerBuildItem.getValue().instance(WorkflowClient.class);
// //Work = recorder.
//// for (AnnotationInstance ai : combinedIndex.getIndex()
//// .getAnnotations(DotName.createSimple(ActivityInterface.class.getName()))) {
//// AnnotationValue flowId = ai.value("value");
//// if (flowId != null && flowId.asString() != null) {
////
//// AnnotationValue activityName = ai.value();
//// recorder.registerFlowReference(ai.target().asClass().name().toString(),
//// definingDocumentId == null ? "" : definingDocumentId.asString(),
//// flowId.asString());
//// }
//// }
// }

}
@@ -1,22 +1,34 @@
package io.quarkus.temporal.client.test;

import io.temporal.client.WorkflowClient;
import io.temporal.client.WorkflowClientOptions;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import io.quarkus.test.QuarkusDevModeTest;

import javax.inject.Inject;
import java.util.function.Supplier;

public class TemporalClientDevModeTest {

@Inject
WorkflowClient workflowClient;

// Start hot reload (DevMode) test with your extension loaded
@RegisterExtension
static final QuarkusDevModeTest devModeTest = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.add(new StringAsset("quarkus.temporal.service.url=localhost:7233"), "application.properties"));

@Test
public void writeYourOwnDevModeTest() {
//WorkflowClientOptions options = workflowClient.getOptions();
//Assertions.assertNotNull(workflowClient);
// Write your dev mode tests here - see the testing extension guide https://quarkus.io/guides/writing-extensions#testing-hot-reload for more information
Assertions.assertTrue(true, "Add dev mode assertions to " + getClass().getName());
}
Expand Down
@@ -1,6 +1,7 @@
package io.quarkus.temporal.client.test;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -13,7 +14,11 @@ public class TemporalClientTest {
// Start unit test with your extension loaded
@RegisterExtension
static final QuarkusUnitTest unitTest = new QuarkusUnitTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
.setArchiveProducer(() ->
ShrinkWrap.create(JavaArchive.class)
//.addClass(DevModeResource.class)
.add(new StringAsset("quarkus.temporal.service.url=localhost:7233"), "application.properties")
);

@Test
public void writeYourOwnUnitTest() {
Expand Down
Expand Up @@ -19,14 +19,25 @@
import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.inject.Inject;
import io.temporal.client.WorkflowClient;
import io.quarkus.temporal.runtime.config.WorkflowConfigurations;


@Path("/temporal-client")
@ApplicationScoped
public class TemporalClientResource {
// add some rest methods here

@Inject
WorkflowClient workflowClient;

@Inject
WorkflowConfigurations workflowConfigurations;

@GET
public String hello() {
return "Hello temporal-client";

return "workfow = "+workflowClient.toString() +" - config"+workflowConfigurations.toString();
}
}
2 changes: 2 additions & 0 deletions integration-tests/src/main/resources/application.properties
@@ -0,0 +1,2 @@

quarkus.temporal.service.url=sw-staging.sellware.net:7233
2 changes: 2 additions & 0 deletions integration-tests/src/main/resources/workflow.yml
@@ -0,0 +1,2 @@
Test:
executionTimeout: 60
@@ -1,7 +1,7 @@
package io.quarkus.temporal.client.it;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeTemporalClientResourceIT extends TemporalClientResourceTest {
}
//package io.quarkus.temporal.client.it;
//
//import io.quarkus.test.junit.NativeImageTest;
//
//@NativeImageTest
//public class NativeTemporalClientResourceIT extends TemporalClientResourceTest {
//}
@@ -1,21 +1,21 @@
package io.quarkus.temporal.client.it;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class TemporalClientResourceTest {

@Test
public void testHelloEndpoint() {
given()
.when().get("/temporal-client")
.then()
.statusCode(200)
.body(is("Hello temporal-client"));
}
}
//package io.quarkus.temporal.client.it;
//
//import static io.restassured.RestAssured.given;
//import static org.hamcrest.Matchers.is;
//
//import org.junit.jupiter.api.Test;
//
//import io.quarkus.test.junit.QuarkusTest;
//
//@QuarkusTest
//public class TemporalClientResourceTest {
//
// @Test
// public void testHelloEndpoint() {
// given()
// .when().get("/temporal-client")
// .then()
// .statusCode(200)
// .body(is("Hello temporal-client"));
// }
//}
6 changes: 6 additions & 0 deletions runtime/pom.xml
Expand Up @@ -21,6 +21,12 @@
<version>${temporal.version}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-yaml</artifactId>
<version>2.11.3</version>
</dependency>

</dependencies>
<build>
<plugins>
Expand Down
@@ -0,0 +1,21 @@
package io.quarkus.temporal.runtime;

import io.temporal.client.WorkflowClient;
import io.temporal.serviceclient.WorkflowServiceStubs;
import io.temporal.serviceclient.WorkflowServiceStubsOptions;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;

public class TemporalAbstractConfiguration {

@Produces
@ApplicationScoped
public WorkflowClient workflowClient(TemporalServerBuildTimeConfig temporalServerBuildTimeConfig) {
WorkflowServiceStubsOptions options = WorkflowServiceStubsOptions.newBuilder()
.setTarget(temporalServerBuildTimeConfig.serviceUrl)
.build();

WorkflowServiceStubs service = WorkflowServiceStubs.newInstance(options);
return WorkflowClient.newInstance(service);
}
}
@@ -0,0 +1,18 @@
package io.quarkus.temporal.runtime;

import io.temporal.activity.ActivityInterface;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@ActivityInterface
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface TemporalActivity {

String name();

Class workflow();
}
@@ -0,0 +1,41 @@
package io.quarkus.temporal.runtime;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.temporal.runtime.config.WorkflowConfig;
import io.quarkus.temporal.runtime.config.WorkflowConfigurations;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Map;


@Recorder
public class TemporalRecorder {

private static final String WORKFLOWS_FILE_CONFIG = "/Users/mac/quarkus-temporal-extension/integration-tests/src/main/resources/workflow.yml";

Logger logger = LoggerFactory.getLogger(this.getClass());
WorkflowConfigurations workflowConfigurations = null;

public RuntimeValue<WorkflowConfigurations> createWorkflowConfigs() {

ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
Map<String, WorkflowConfig> configs = null;
try {
InputStream is = new FileInputStream(WORKFLOWS_FILE_CONFIG);//getClass().getResourceAsStream(WORKFLOWS_FILE_CONFIG);
configs = mapper.readValue(is, new TypeReference<Map<String, WorkflowConfig>>() {});
return new RuntimeValue<>(new WorkflowConfigurations(configs));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}

}
@@ -0,0 +1,16 @@
package io.quarkus.temporal.runtime;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(name = "temporal", phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
public class TemporalServerBuildTimeConfig {

/**
* Temporal service url
*/
@ConfigItem(name="service.url")
public String serviceUrl;
}

0 comments on commit a28b104

Please sign in to comment.