jsinovassin commented on code in PR #432:
URL: https://github.com/apache/unomi/pull/432#discussion_r888779181


##########
lifecycle-watcher/src/main/java/org/apache/unomi/lifecycle/BundleWatcherImpl.java:
##########
@@ -223,50 +266,93 @@ private void displayLogsForInactiveServices() {
         });
     }
 
+    private void fillFeaturesToInstall() {
+        String installGraphQLFeature = 
bundleContext.getProperty("org.apache.unomi.graphql.feature.activated");
+        boolean graphQLToInstall = 
StringUtils.isNotBlank(installGraphQLFeature) && 
installGraphQLFeature.equals("true");
+        if (graphQLToInstall) {
+            featuresToInstall.add(CDP_GRAPHQL_FEATURE);
+            
requiredBundlesFromFeatures.put("org.apache.unomi.cdp-graphql-api-impl", false);
+            
requiredBundlesFromFeatures.put("org.apache.unomi.graphql-playground", false);
+        }
+    }
+
+    public boolean shouldInstallAdditionalFeatures() {
+        return !featuresToInstall.isEmpty();
+    }
+
+    private void installFeatures() {
+        List<String> installedFeatures = new ArrayList<>();
+        featuresToInstall.forEach(value -> {
+            try {
+                long featureStartupTime = System.currentTimeMillis();
+                if 
(!featuresService.isInstalled(featuresService.getFeature(value))) {
+                    System.out.println("Installing feature " + value);
+                    featuresService.installFeature(value, 
EnumSet.of(FeaturesService.Option.NoAutoRefreshManagedBundles,
+                            
FeaturesService.Option.NoAutoRefreshUnmanagedBundles, 
FeaturesService.Option.NoAutoRefreshBundles));
+                    logger.info("Feature {} successfully installed in {} ms", 
value, System.currentTimeMillis() - featureStartupTime);
+                }
+                installedFeatures.add(value);
+            } catch (Exception e) {
+                logger.error("Error when installing {} feature", value, e);
+            }
+        });
+        installedFeatures.forEach(value -> featuresToInstall.remove(value));
+    }
+
+    private void startScheduler() {
+        if (scheduledFuture == null || scheduledFuture.isCancelled()) {
+            TimerTask task = new TimerTask() {
+                @Override
+                public void run() {
+                    displayLogsForInactiveBundles(requiredBundles);
+                    displayLogsForInactiveBundles(requiredBundlesFromFeatures);
+                    displayLogsForInactiveServices();
+                    checkStartupComplete();
+                }
+            };
+            scheduledFuture = scheduler
+                    .scheduleWithFixedDelay(task, 
checkStartupStateRefreshInterval, checkStartupStateRefreshInterval, 
TimeUnit.SECONDS);
+        }
+    }
+
     private void checkStartupComplete() {
         if (!isStartupComplete()) {
-            if (scheduledFuture == null || scheduledFuture.isCancelled()) {
-                TimerTask task = new TimerTask() {
-                    @Override
-                    public void run() {
-                        displayLogsForInactiveBundles();
-                        displayLogsForInactiveServices();
-                        checkStartupComplete();
-                    }
-                };
-                scheduledFuture = scheduler
-                        .scheduleWithFixedDelay(task, 
checkStartupStateRefreshInterval, checkStartupStateRefreshInterval, 
TimeUnit.SECONDS);
-            }
+            startScheduler();
             return;
         }
         if (scheduledFuture != null) {
             scheduledFuture.cancel(true);
             scheduledFuture = null;
         }
+        if (shouldInstallAdditionalFeatures() && !installingFeatureStarted) {
+            installingFeatureStarted = true;
+            installFeatures();
+            checkStartupComplete();
+            return;
+        }
+        if (!allAdditionalBundleStarted()) {
+            startScheduler();
+            return;
+        }

Review Comment:
   The problem is that I need to wait that Unomi is fully started, otherwise I 
have a strange behaviour where I try to install features during the starting. 
Installing the bundles of a feature during this time, stop the execution and 
Unomi never start.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to