use of com.devonfw.cobigen.impl.config.ContextConfiguration in project cobigen by devonfw.
the class HealthCheckImpl method upgradeAllConfigurations.
@Override
public HealthCheckReport upgradeAllConfigurations(Path contextConfigurationPath, BackupPolicy backupPolicy) {
try {
upgradeContextConfiguration(contextConfigurationPath, backupPolicy);
} catch (BackupFailedException e) {
upgradeContextConfiguration(contextConfigurationPath, BackupPolicy.NO_BACKUP);
}
ContextConfiguration contextConfiguration = new ContextConfiguration(contextConfigurationPath);
List<String> expectedTemplatesConfigurations = new ArrayList<>();
Set<String> hasConfiguration = Sets.newHashSet();
Map<String, Path> upgradeableConfigurations = this.healthCheckReport.getUpgradeableConfigurations();
for (Trigger t : contextConfiguration.getTriggers()) {
expectedTemplatesConfigurations.add(t.getTemplateFolder());
hasConfiguration.add(t.getTemplateFolder());
}
this.healthCheckReport.setHasConfiguration(hasConfiguration);
upgradeableConfigurations.put("TempOne", contextConfigurationPath.resolve("TempOne"));
this.healthCheckReport.setUpgradeableConfigurations(upgradeableConfigurations);
if (expectedTemplatesConfigurations.containsAll(this.healthCheckReport.getHasConfiguration())) {
for (final String key : expectedTemplatesConfigurations) {
if (this.healthCheckReport.getUpgradeableConfigurations().containsKey(key)) {
upgradeTemplatesConfiguration(this.healthCheckReport.getUpgradeableConfigurations().get(key), backupPolicy);
}
}
} else {
LOG.error("Expected template configuration does not equal the actual template configuration");
throw new CobiGenRuntimeException("Update of the templates configuration was not successful, please retry");
}
return this.healthCheckReport;
}
use of com.devonfw.cobigen.impl.config.ContextConfiguration in project cobigen by devonfw.
the class ContextConfigurationUpgrader method performNextUpgradeStep.
@Override
protected ConfigurationUpgradeResult performNextUpgradeStep(ContextConfigurationVersion source, Object previousConfigurationRootNode) throws Exception {
ConfigurationUpgradeResult result = new ConfigurationUpgradeResult();
MapperFactory mapperFactory;
MapperFacade mapper;
com.devonfw.cobigen.impl.config.entity.io.v2_2.ContextConfiguration upgradedConfig;
switch(source) {
case v2_0:
case v2_1:
mapperFactory = new DefaultMapperFactory.Builder().useAutoMapping(true).mapNulls(true).build();
mapperFactory.classMap(com.devonfw.cobigen.impl.config.entity.io.v2_0.ContextConfiguration.class, com.devonfw.cobigen.impl.config.entity.io.v2_2.ContextConfiguration.class).field("triggers.trigger", "trigger").byDefault().register();
mapperFactory.classMap(com.devonfw.cobigen.impl.config.entity.io.v2_0.ContainerMatcher.class, com.devonfw.cobigen.impl.config.entity.io.v2_2.ContainerMatcher.class).field("retrieveObjectsRecursively:{isRetrieveObjectsRecursively|setRetrieveObjectsRecursively(new Boolean(%s))|type=java.lang.Boolean}", "retrieveObjectsRecursively:{isRetrieveObjectsRecursively|setRetrieveObjectsRecursively(new Boolean(%s))|type=java.lang.Boolean}").byDefault().register();
mapper = mapperFactory.getMapperFacade();
upgradedConfig = mapper.map(previousConfigurationRootNode, com.devonfw.cobigen.impl.config.entity.io.v2_2.ContextConfiguration.class);
upgradedConfig.setVersion(new BigDecimal("2.2"));
result.setResultConfigurationJaxbRootNode(upgradedConfig);
break;
default:
throw new NotYetSupportedException("An upgrade of the context configuration from a version previous to v2.0 is not yet supported.");
}
return result;
}
use of com.devonfw.cobigen.impl.config.ContextConfiguration in project cobigen by devonfw.
the class HealthCheckImpl method perform.
@Override
public HealthCheckReport perform(Path configurationPath) {
// 1. Get configuration resources
// determine expected template configurations to be defined
ContextConfiguration contextConfiguration = new ContextConfiguration(configurationPath);
List<String> expectedTemplatesConfigurations = Lists.newArrayList();
Set<String> hasConfiguration = Sets.newHashSet();
Set<String> isAccessible = Sets.newHashSet();
Map<String, Path> upgradeableConfigurations = Maps.newHashMap();
Set<String> upToDateConfigurations = Sets.newHashSet();
Path pathForCobigenTemplates = null;
for (Trigger t : contextConfiguration.getTriggers()) {
expectedTemplatesConfigurations.add(t.getTemplateFolder());
}
// 2. Determine current state
TemplateConfigurationUpgrader templateConfigurationUpgrader = new TemplateConfigurationUpgrader();
pathForCobigenTemplates = configurationPath.resolve("src" + File.separator + "main" + File.separator + "templates");
for (String expectedTemplateFolder : expectedTemplatesConfigurations) {
if (Files.exists(pathForCobigenTemplates)) {
String configPath = (configurationPath + File.separator + "src" + File.separator + "main" + File.separator + "templates").toString();
hasConfiguration.add(configPath);
isAccessible.add(configPath);
Path expectedTemplateFolderForResolvedVer = pathForCobigenTemplates.resolve(expectedTemplateFolder.replace("/", File.separator).toString());
TemplatesConfigurationVersion resolvedVersion = templateConfigurationUpgrader.resolveLatestCompatibleSchemaVersion(expectedTemplateFolderForResolvedVer);
if (resolvedVersion != null) {
if (resolvedVersion != TemplatesConfigurationVersion.getLatest()) {
upgradeableConfigurations.put(expectedTemplateFolder, pathForCobigenTemplates);
} else {
upToDateConfigurations.add(expectedTemplateFolder);
}
}
} else {
Path templateFolder = configurationPath.resolve(expectedTemplateFolder);
Path templatesConfigurationPath = templateFolder.resolve(ConfigurationConstants.TEMPLATES_CONFIG_FILENAME);
File templatesConfigurationFile = templatesConfigurationPath.toFile();
if (templatesConfigurationFile.exists()) {
hasConfiguration.add(expectedTemplateFolder);
if (templatesConfigurationFile.canWrite()) {
isAccessible.add(expectedTemplateFolder);
TemplatesConfigurationVersion resolvedVersion = templateConfigurationUpgrader.resolveLatestCompatibleSchemaVersion(templateFolder);
if (resolvedVersion != null) {
if (resolvedVersion != TemplatesConfigurationVersion.getLatest()) {
upgradeableConfigurations.put(expectedTemplateFolder, templateFolder);
} else {
upToDateConfigurations.add(expectedTemplateFolder);
}
}
}
}
}
}
this.healthCheckReport.setExpectedTemplatesConfigurations(expectedTemplatesConfigurations);
this.healthCheckReport.setHasConfiguration(hasConfiguration);
this.healthCheckReport.setIsAccessible(isAccessible);
this.healthCheckReport.setUpgradeableConfigurations(upgradeableConfigurations);
this.healthCheckReport.setUpToDateConfigurations(upToDateConfigurations);
return this.healthCheckReport;
}
Aggregations