Skip to content

Commit

Permalink
fixes #710 update rest and hybrid generator (#711)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu authored Dec 7, 2024
1 parent d1fa198 commit 6e54f04
Show file tree
Hide file tree
Showing 23 changed files with 149 additions and 399 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,33 +84,22 @@ public void generate(String targetPath, Object model, JsonNode config) throws IO
transfer(targetPath, "", ".project", templates.hybrid.project.template());
}

// config
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "service.yml", templates.hybrid.serviceYml.template(config));

transfer(targetPath, ("src.main.resources.config").replace(".", separator), "server.yml", templates.hybrid.serverYml.template(serviceId, enableHttp, httpPort, enableHttps, httpsPort, enableHttp2, enableRegistry, version));
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "server.yml", templates.hybrid.serverYml.template(serviceId, enableHttp, "49587", enableHttps, "49588", enableHttp2, enableRegistry, version));

if(kafkaProducer) {
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "kafka-producer.yml", templates.hybrid.kafkaProducerYml.template(kafkaTopic));
}
if(kafkaConsumer) {
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "kafka-streams.yml", templates.hybrid.kafkaStreamsYml.template(artifactId));
}

// transfer(targetPath, ("src.main.resources.config").replace(".", separator), "secret.yml", templates.hybrid.secretYml.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "security.yml", templates.hybrid.securityYml.template());

transfer(targetPath, ("src.main.resources.config").replace(".", separator), "primary.crt", templates.hybrid.primaryCrt.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "secondary.crt", templates.hybrid.secondaryCrt.template());

// logging
transfer(targetPath, ("src.main.resources").replace(".", separator), "logback.xml", templates.hybrid.logback.template());
transfer(targetPath, ("src.test.resources").replace(".", separator), "logback-test.xml", templates.hybrid.logback.template());

// added with #471
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "app-status.yml", templates.hybrid.appStatusYml.template());
// values.yml file, transfer to suppress the warning message during start startup and encourage usage.
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "values.yml", templates.hybrid.values.template());
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "values.yml", templates.hybrid.values.template(config, handlerPackage, jsonPath, serviceId, enableHttp, httpPort, enableHttps, httpsPort, enableHttp2, enableRegistry, version));
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "values.yml", templates.hybrid.values.template(config, handlerPackage, jsonPath, serviceId, enableHttp, "49587", enableHttps, "49588", enableHttp2, enableRegistry, version));

// transfer binary files without touching them.
try (InputStream is = HybridServerGenerator.class.getResourceAsStream("/binaries/server.keystore")) {
Expand Down Expand Up @@ -138,9 +127,6 @@ public void generate(String targetPath, Object model, JsonNode config) throws IO
transfer(targetPath, ("src.main.resources.config").replace(".", separator), "handler.yml",
templates.hybrid.handlerYml.template(serviceId, handlerPackage, jsonPath, prometheusMetrics));

transfer(targetPath, ("src.main.resources.config").replace(".", separator), "rpc-router.yml",
templates.hybrid.rpcRouterYml.template(handlerPackage, jsonPath));

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import static java.io.File.separator;

Expand Down Expand Up @@ -81,12 +82,6 @@ public void generate(String targetPath, Object model, JsonNode config) throws IO
transfer(targetPath, "", ".project", templates.hybrid.project.template());
}

// config
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "service.yml", templates.hybrid.serviceYml.template(config));

transfer(targetPath, ("src.test.resources.config").replace(".", separator), "server.yml", templates.hybrid.serverYml.template(serviceId, enableHttp, "49587", enableHttps, "49588", enableHttp2, enableRegistry, version));
//transfer(targetPath, ("src.test.resources.config").replace(".", separator), "secret.yml", templates.hybrid.secretYml.template());
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "security.yml", templates.hybrid.securityYml.template());
if(kafkaProducer) {
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "kafka-producer.yml", templates.hybrid.kafkaProducerYml.template(kafkaTopic));
}
Expand All @@ -103,10 +98,10 @@ public void generate(String targetPath, Object model, JsonNode config) throws IO
// added with #471
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "app-status.yml", templates.hybrid.appStatusYml.template());
// values.yml file, transfer to suppress the warning message during start startup and encourage usage.
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "values.yml", templates.hybrid.values.template());
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "values.yml", templates.hybrid.values.template(config, handlerPackage, jsonPath, serviceId, enableHttp, "49587", enableHttps, "49588", enableHttp2, enableRegistry, version));

// handler
Map<String, Object> services = new HashMap<String, Object>();
Map<String, Object> services = new TreeMap<String, Object>();
JsonNode anyModel = (JsonNode)model;
String host = anyModel.get("host").textValue();
String service = anyModel.get("service").textValue();
Expand All @@ -121,7 +116,7 @@ public void generate(String targetPath, Object model, JsonNode config) throws IO
}
transfer(targetPath, ("src.main.java." + handlerPackage).replace(".", separator), item.get("handler").textValue() + ".java", templates.hybrid.handler.template(handlerPackage, host, service, item, example));
String sId = host + "/" + service + "/" + item.get("name").textValue() + "/" + item.get("version").textValue();
Map<String, Object> map = new HashMap<>();
Map<String, Object> map = new TreeMap<>();
map.put("schema", item.get("schema"));
JsonNode anyScope = item.get("scope");
String scope = anyScope != null ? anyScope.textValue().trim() : null;
Expand Down Expand Up @@ -164,9 +159,6 @@ public void generate(String targetPath, Object model, JsonNode config) throws IO
transfer(targetPath, ("src.test.resources.config").replace(".", separator), "handler.yml",
templates.hybrid.handlerYml.template(serviceId, handlerPackage, jsonPath, prometheusMetrics));

transfer(targetPath, ("src.test.resources.config").replace(".", separator), "rpc-router.yml",
templates.hybrid.rpcRouterYml.template(handlerPackage, jsonPath));

// write the generated schema into the config folder for schema validation.
try (InputStream is = new ByteArrayInputStream(Generator.jsonMapper.writerWithDefaultPrettyPrinter().writeValueAsBytes(services))) {
Generator.copyFile(is, Paths.get(targetPath, ("src.main.resources").replace(".", separator), "schema.json"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package @handlerPackage;

import com.networknt.utility.NioUtils;
import com.networknt.rpc.Handler;
import com.networknt.rpc.HybridHandler;
import com.networknt.rpc.router.ServiceHandler;
import java.nio.ByteBuffer;
import io.undertow.server.HttpServerExchange;
Expand All @@ -13,7 +13,7 @@ For more information on how to write business handlers, please check the link be
https://doc.networknt.com/development/business-handler/hybrid/
*/
@@ServiceHandler(id="@host/@service/@item.get("name").textValue()/@item.get("version").textValue()")
public class @item.get("handler").textValue() implements Handler {
public class @item.get("handler").textValue() implements HybridHandler {
@@Override
public ByteBuffer handle(HttpServerExchange exchange, Object input) {
return NioUtils.toByteBuffer("@example");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,22 @@ handlers:
# Light-framework cross-cutting concerns implemented in the microservice
- com.networknt.exception.ExceptionHandler@@exception
@if(prometheusMetrics){ - com.networknt.metrics.prometheus.PrometheusHandler@@prometheus} else { - com.networknt.metrics.MetricsHandler@@metrics}
# - com.networknt.traceability.TraceabilityHandler@@traceability
# - com.networknt.correlation.CorrelationHandler@@correlation
- com.networknt.jaeger.tracing.JaegerHandler@@jaeger
- com.networknt.correlation.CorrelationHandler@@correlation
- com.networknt.cors.CorsHttpHandler@@cors
- com.networknt.body.BodyHandler@@body
# - com.networknt.audit.AuditHandler@@audit
# DumpHandler is to dump detail request/response info to log, useful for troubleshooting but not suggested to use in production due to it may lower the performance
# - com.networknt.dump.DumpHandler@@dump
# - com.networknt.sanitizer.SanitizerHandler@@sanitizer
- com.networknt.rpc.router.JsonHandler@@json
- com.networknt.rpc.router.SchemaHandler@@schema
- com.networknt.rpc.security.HybridJwtVerifyHandler@@security

# Customer business domain specific cross-cutting concerns handlers
# - com.example.validator.CustomizedValidator@@custvalidator
# Framework endpoint handlers
- com.networknt.health.HealthGetHandler@@health
- com.networknt.info.ServerInfoGetHandler@@info
- com.networknt.openapi.JwtVerifyHandler@@security
- com.networknt.logging.handler.LoggerGetHandler@@getLogger
- com.networknt.logging.handler.LoggerPostHandler@@postLogger
- com.networknt.logging.handler.LoggerGetLogContentsHandler@@getLogContents
Expand All @@ -74,10 +75,10 @@ chains:
default:
- exception
@if(prometheusMetrics){ - prometheus} else { - metrics}
- traceability
- correlation
# - dump
- cors
- schema
- security
- json

paths:
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6e54f04

Please sign in to comment.