Skip to content

Commit d16e860

Browse files
authored
Merge pull request #43 from vinscom/remove-servicearray
Removed service array
2 parents b4f3aa1 + 929d992 commit d16e860

File tree

3 files changed

+123
-117
lines changed

3 files changed

+123
-117
lines changed

src/main/java/in/erail/route/OpenAPI3RouteBuilder.java

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import in.erail.common.FrameworkConstants;
1616
import in.erail.glue.annotation.StartService;
17-
import in.erail.glue.component.ServiceArray;
1817
import io.netty.handler.codec.http.HttpHeaderNames;
1918
import io.netty.handler.codec.http.HttpResponseStatus;
2019
import io.vertx.core.eventbus.DeliveryOptions;
@@ -26,7 +25,9 @@
2625
import io.vertx.reactivex.ext.web.RoutingContext;
2726
import io.vertx.reactivex.ext.web.api.contract.openapi3.OpenAPI3RouterFactory;
2827
import in.erail.service.RESTService;
28+
import java.util.Arrays;
2929
import java.util.HashMap;
30+
import java.util.Optional;
3031

3132
/**
3233
*
@@ -36,7 +37,7 @@ public class OpenAPI3RouteBuilder extends AbstractRouterBuilderImpl {
3637

3738
private static final String AUTHORIZATION_PREFIX = "realm";
3839
private static final String FAIL_SUFFIX = ".fail";
39-
private ServiceArray mServices;
40+
private RESTService[] mServices;
4041
private File mOpenAPI3File;
4142
private DeliveryOptions mDeliveryOptions;
4243
private boolean mSecurityEnable = true;
@@ -51,22 +52,20 @@ public void setOpenAPI3File(File pOpenAPI3File) {
5152
this.mOpenAPI3File = pOpenAPI3File;
5253
}
5354

54-
public ServiceArray getServices() {
55+
public RESTService[] getServices() {
5556
return mServices;
5657
}
5758

58-
public void setServices(ServiceArray pServices) {
59+
public void setServices(RESTService[] pServices) {
5960
this.mServices = pServices;
6061
}
6162

6263
@StartService
6364
public void start() {
6465

65-
getServices()
66-
.getServices()
67-
.stream()
68-
.forEach((api) -> {
69-
RESTService service = (RESTService) api;
66+
Arrays
67+
.stream(getServices())
68+
.forEach((service) -> {
7069
getMetrics()
7170
.put(service.getServiceUniqueId(),
7271
getMetricRegistry().timer("api.framework.service." + service.getServiceUniqueId()));
@@ -193,35 +192,38 @@ public Router getRouter(Router pRouter) {
193192
.rxCreateRouterFactoryFromFile(getVertx(), getOpenAPI3File().getAbsolutePath())
194193
.blockingGet();
195194

196-
getServices()
197-
.getServices()
198-
.forEach((api) -> {
199-
RESTService service = (RESTService) api;
200-
201-
apiFactory.addHandlerByOperationId(service.getOperationId(), (routingContext) -> {
202-
203-
routingContext.put(FrameworkConstants.RoutingContext.Attribute.BODY_AS_JSON, service.isBodyAsJson());
204-
205-
if (isSecurityEnable()) {
206-
207-
if (routingContext.user() == null) {
208-
routingContext.fail(401);
209-
return;
210-
}
211-
212-
routingContext.user().isAuthorized(AUTHORIZATION_PREFIX + ":" + service.getOperationId(), (event) -> {
213-
boolean authSuccess = event.succeeded() ? event.result() : false;
214-
if (authSuccess) {
215-
process(routingContext, service.getServiceUniqueId());
216-
} else {
217-
routingContext.fail(401);
218-
}
219-
});
220-
} else {
221-
getLog().warn("Security disabled for " + service.getServiceUniqueId());
222-
process(routingContext, service.getServiceUniqueId());
223-
}
224-
});
195+
Optional
196+
.ofNullable(getServices())
197+
.ifPresent(t -> {
198+
Arrays
199+
.asList(t)
200+
.stream()
201+
.forEach((service) -> {
202+
apiFactory.addHandlerByOperationId(service.getOperationId(), (routingContext) -> {
203+
204+
routingContext.put(FrameworkConstants.RoutingContext.Attribute.BODY_AS_JSON, service.isBodyAsJson());
205+
206+
if (isSecurityEnable()) {
207+
208+
if (routingContext.user() == null) {
209+
routingContext.fail(401);
210+
return;
211+
}
212+
213+
routingContext.user().isAuthorized(AUTHORIZATION_PREFIX + ":" + service.getOperationId(), (event) -> {
214+
boolean authSuccess = event.succeeded() ? event.result() : false;
215+
if (authSuccess) {
216+
process(routingContext, service.getServiceUniqueId());
217+
} else {
218+
routingContext.fail(401);
219+
}
220+
});
221+
} else {
222+
getLog().warn("Security disabled for " + service.getServiceUniqueId());
223+
process(routingContext, service.getServiceUniqueId());
224+
}
225+
});
226+
});
225227
});
226228

227229
return apiFactory.getRouter();

src/main/java/io/vertx/core/VerticalDeployer.java

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
import java.util.Arrays;
66
import in.erail.glue.annotation.StartService;
7-
import in.erail.glue.component.ServiceArray;
87
import io.vertx.core.json.JsonObject;
8+
import java.util.Optional;
99
import org.apache.logging.log4j.Logger;
1010

1111
public class VerticalDeployer {
1212

1313
private String[] mVerticalNames;
14-
private ServiceArray mVerticalInstances;
14+
private Verticle[] mVerticalInstances;
1515
private DeploymentOptions mDeploymentOptions;
1616
private Vertx mVertx;
1717
private Logger mLog;
@@ -21,51 +21,59 @@ public class VerticalDeployer {
2121
public void start() {
2222

2323
//Deploy using name
24-
Arrays
25-
.stream(getVerticalNames())
26-
.forEach((path) -> {
27-
JsonObject deployMsg = new JsonObject();
28-
deployMsg.put("name", path);
29-
getVertx()
30-
.getDelegate()
31-
.deployVerticle(path, getDeploymentOptions(), (result) -> {
32-
if (result.succeeded()) {
33-
String deploymentId = result.result();
34-
deployMsg.put("deploymentId", deploymentId);
35-
deployMsg.put("success", true);
36-
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
37-
getLog().info(() -> "Deployed:" + path + ":" + deploymentId);
38-
} else {
39-
deployMsg.put("success", false);
40-
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
41-
getLog().error("Vertical Deployment failed", result.cause());
42-
}
24+
Optional
25+
.ofNullable(getVerticalNames())
26+
.ifPresent(t -> {
27+
Arrays
28+
.stream(getVerticalNames())
29+
.forEach((path) -> {
30+
JsonObject deployMsg = new JsonObject();
31+
deployMsg.put("name", path);
32+
getVertx()
33+
.getDelegate()
34+
.deployVerticle(path, getDeploymentOptions(), (result) -> {
35+
if (result.succeeded()) {
36+
String deploymentId = result.result();
37+
deployMsg.put("deploymentId", deploymentId);
38+
deployMsg.put("success", true);
39+
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
40+
getLog().info(() -> "Deployed:" + path + ":" + deploymentId);
41+
} else {
42+
deployMsg.put("success", false);
43+
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
44+
getLog().error("Vertical Deployment failed", result.cause());
45+
}
46+
});
4347
});
4448
});
4549

4650
//Deploy using Java class instance
47-
getVerticalInstances()
48-
.getServices()
49-
.stream()
50-
.forEach((vertical) -> {
51-
52-
JsonObject deployMsg = new JsonObject();
53-
deployMsg.put("name", vertical.getClass().getCanonicalName());
54-
getVertx()
55-
.getDelegate()
56-
.deployVerticle((Verticle) vertical, getDeploymentOptions(), (result) -> {
57-
if (result.succeeded()) {
58-
String deploymentId = result.result();
59-
deployMsg.put("deploymentId", deploymentId);
60-
deployMsg.put("success", true);
61-
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
62-
getLog().info(() -> "Deployed:" + vertical.getClass().getCanonicalName() + ":" + deploymentId);
63-
} else {
64-
deployMsg.put("success", false);
65-
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
66-
getLog().error("Vertical Deployment failed", result.cause());
67-
}
51+
Optional
52+
.ofNullable(getVerticalInstances())
53+
.ifPresent(t -> {
54+
Arrays
55+
.stream(t)
56+
.forEach((vertical) -> {
57+
58+
JsonObject deployMsg = new JsonObject();
59+
deployMsg.put("name", vertical.getClass().getCanonicalName());
60+
getVertx()
61+
.getDelegate()
62+
.deployVerticle(vertical, getDeploymentOptions(), (result) -> {
63+
if (result.succeeded()) {
64+
String deploymentId = result.result();
65+
deployMsg.put("deploymentId", deploymentId);
66+
deployMsg.put("success", true);
67+
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
68+
getLog().info(() -> "Deployed:" + vertical.getClass().getCanonicalName() + ":" + deploymentId);
69+
} else {
70+
deployMsg.put("success", false);
71+
getVertx().eventBus().publish(getDeployStatusTopicName(), deployMsg);
72+
getLog().error("Vertical Deployment failed", result.cause());
73+
}
74+
});
6875
});
76+
6977
});
7078

7179
}
@@ -110,11 +118,11 @@ public void setDeployStatusTopicName(String pDeployStatusTopicName) {
110118
this.mDeployStatusTopicName = pDeployStatusTopicName;
111119
}
112120

113-
public ServiceArray getVerticalInstances() {
121+
public Verticle[] getVerticalInstances() {
114122
return mVerticalInstances;
115123
}
116124

117-
public void setVerticalInstances(ServiceArray pVerticalInstances) {
125+
public void setVerticalInstances(Verticle[] pVerticalInstances) {
118126
this.mVerticalInstances = pVerticalInstances;
119127
}
120128

0 commit comments

Comments
 (0)