allow upgrader to work with application-profiles when debugging in IDE
@@ -23,6 +23,9 @@ package com.thinkbiganalytics.server.upgrade;
* #L%
*/
+import com.thinkbiganalytics.KyloVersion;
+import com.thinkbiganalytics.KyloVersionUtil;
+
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -30,9 +33,10 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.springframework.core.env.PropertiesPropertySource;
-import com.thinkbiganalytics.KyloVersion;
-import com.thinkbiganalytics.KyloVersionUtil;
+import java.util.Arrays;
+import java.util.Properties;
/**
* Performs all upgrade steps within a metadata transaction.
@@ -53,7 +57,9 @@ public class KyloUpgrader {
try {
KyloUpgradeService upgradeService = upgradeCxt.getBean(KyloUpgradeService.class);
// Keep upgrading until upgrade() returns true, i.e. we are up-to-date;
- while (! upgradeService.upgradeNext());
+ while (!upgradeService.upgradeNext()) {
+ ;
+ }
} finally {
upgradeCxt.close();
}
@@ -81,6 +87,7 @@ public class KyloUpgrader {
}
//Spring is needed to load the Spring Cloud context so we can decrypt the passwords for the database connection
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("kylo-upgrade-check-application-context.xml");
+ loadProfileProperties(ctx);
ctx.refresh();
KyloUpgradeDatabaseVersionChecker upgradeDatabaseVersionChecker = (KyloUpgradeDatabaseVersionChecker) ctx.getBean("kyloUpgradeDatabaseVersionChecker");
KyloVersion kyloVersion = upgradeDatabaseVersionChecker.getDatabaseVersion();
@@ -88,4 +95,18 @@ public class KyloUpgrader {
return kyloVersion;
}
+ private void loadProfileProperties(ClassPathXmlApplicationContext ctx) {
+ Arrays.asList(ctx.getEnvironment().getActiveProfiles()).stream().filter(p -> !"native".equalsIgnoreCase(p)).forEach(p -> {
+ try {
+ Properties properties = new Properties();
+ properties.load(this.getClass().getClassLoader().getResourceAsStream("application-" + p + ".properties"));
+
+ PropertiesPropertySource propertiesPropertySource = new PropertiesPropertySource(p, properties);
+ ctx.getEnvironment().getPropertySources().addLast(propertiesPropertySource);
+ } catch (Exception e) {
+ log.warn("Unable to load properties for profile " + p);
+ }
+ });
+ }
+
}
