2424import java .util .Map ;
2525import java .util .Optional ;
2626
27+ import static org .zowe .apiml .util .config .ConfigReader .IS_MODULITH_ENABLED ;
28+
2729//TODO this class doesn't lend itself well to switching of configurations.
2830//attls is integrated in a kludgy way, and deserves a rewrite
2931
3032@ Slf4j
3133public class FullApiMediationLayer {
34+
3235 private RunningService discoveryService ;
3336 private RunningService gatewayService ;
3437 private RunningService apiCatalogService ;
@@ -52,14 +55,19 @@ public class FullApiMediationLayer {
5255 private FullApiMediationLayer () {
5356 env = ConfigReader .environmentConfiguration ().getInstanceEnv ();
5457
58+ if (IS_MODULITH_ENABLED ) {
59+ prepareApiml ();
60+ } else {
61+ prepareGateway ();
62+ prepareDiscovery ();
63+ prepareCaching ();
64+ prepareZaas ();
65+ }
66+
67+ prepareMockServices ();
5568 prepareCatalog ();
5669 prepareDiscoverableClient ();
57- prepareGateway ();
58- prepareMockServices ();
59- prepareDiscovery ();
60- prepareCaching ();
61- prepareZaas ();
62- prepareApiml ();
70+
6371 if (!attlsEnabled ) {
6472 prepareNodeJsSampleApp ();
6573 }
@@ -130,25 +138,28 @@ private void prepareDiscoverableClient() {
130138
131139 public void start () {
132140 try {
133- var discoveryEnv = new HashMap <>(env );
134- discoveryEnv .put ("ZWE_configs_port" , "10011" );
135- discoveryService .startWithScript ("discovery-package/src/main/resources/bin" , discoveryEnv );
136- var gatewayEnv = new HashMap <>(env );
137- gatewayEnv .put ("ZWE_configs_port" , "10010" );
138- gatewayService .startWithScript ("gateway-package/src/main/resources/bin" , gatewayEnv );
139- var catalogEnv = new HashMap <>(env );
140- catalogEnv .put ("ZWE_configs_port" , "10014" );
141- apiCatalogService .startWithScript ("api-catalog-package/src/main/resources/bin" , catalogEnv );
142- var cachingEnv = new HashMap <>(env );
143- cachingEnv .put ("ZWE_configs_port" , "10016" );
144- cachingService .startWithScript ("caching-service-package/src/main/resources/bin" , cachingEnv );
145- var zaasEnv = new HashMap <>(env );
146- zaasEnv .put ("ZWE_configs_port" , "10023" );
147- zaasService .startWithScript ("zaas-package/src/main/resources/bin" , zaasEnv );
148- var apimlModulithEnv = new HashMap <>(env );
149- apimlModulithEnv .put ("ZWE_configs_port" , "10020" );
150- apimlModulithEnv .put ("ZWE_configs_internal_discovery_port" , "10021" );
151- apimlService .startWithScript ("apiml-package/src/main/resources/bin" , apimlModulithEnv );
141+ if (IS_MODULITH_ENABLED ) {
142+ var apimlModulithEnv = new HashMap <>(env );
143+ apimlModulithEnv .put ("ZWE_configs_port" , "10010" );
144+ apimlModulithEnv .put ("ZWE_configs_internal_discovery_port" , "10011" );
145+ apimlService .startWithScript ("apiml-package/src/main/resources/bin" , apimlModulithEnv );
146+ } else {
147+ var discoveryEnv = new HashMap <>(env );
148+ discoveryEnv .put ("ZWE_configs_port" , "10011" );
149+ discoveryService .startWithScript ("discovery-package/src/main/resources/bin" , discoveryEnv );
150+ var gatewayEnv = new HashMap <>(env );
151+ gatewayEnv .put ("ZWE_configs_port" , "10010" );
152+ gatewayService .startWithScript ("gateway-package/src/main/resources/bin" , gatewayEnv );
153+ var catalogEnv = new HashMap <>(env );
154+ catalogEnv .put ("ZWE_configs_port" , "10014" );
155+ apiCatalogService .startWithScript ("api-catalog-package/src/main/resources/bin" , catalogEnv );
156+ var cachingEnv = new HashMap <>(env );
157+ cachingEnv .put ("ZWE_configs_port" , "10016" );
158+ cachingService .startWithScript ("caching-service-package/src/main/resources/bin" , cachingEnv );
159+ var zaasEnv = new HashMap <>(env );
160+ zaasEnv .put ("ZWE_configs_port" , "10023" );
161+ zaasService .startWithScript ("zaas-package/src/main/resources/bin" , zaasEnv );
162+ }
152163
153164 if (!attlsEnabled ) {
154165 nodeJsSampleApp = nodeJsBuilder .start ();
@@ -176,18 +187,22 @@ private String formatEnv() {
176187
177188 public void stop () {
178189 try {
179- discoveryService .stop ();
180- gatewayService .stop ();
181190 mockZosmfService .stop ();
182-
183- apiCatalogService .stop ();
184191 discoverableClientService .stop ();
185192
186- cachingService .stop ();
187- zaasService .stop ();
188193 if (!attlsEnabled && startServices ()) {
189194 nodeJsSampleApp .destroy ();
190195 }
196+
197+ if (IS_MODULITH_ENABLED ) {
198+ apimlService .stop ();
199+ } else {
200+ discoveryService .stop ();
201+ gatewayService .stop ();
202+ apiCatalogService .stop ();
203+ cachingService .stop ();
204+ zaasService .stop ();
205+ }
191206 } catch (Exception e ) {
192207 e .printStackTrace ();
193208 }
0 commit comments