44
55import java .util .Arrays ;
66import in .erail .glue .annotation .StartService ;
7- import in .erail .glue .component .ServiceArray ;
87import io .vertx .core .json .JsonObject ;
8+ import java .util .Optional ;
99import org .apache .logging .log4j .Logger ;
1010
1111public 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