Search in sources :

Example 1 with ContextConfiguration

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;
}
Also used : Path(java.nio.file.Path) Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) CobiGenRuntimeException(com.devonfw.cobigen.api.exception.CobiGenRuntimeException) BackupFailedException(com.devonfw.cobigen.impl.exceptions.BackupFailedException) ArrayList(java.util.ArrayList) ContextConfiguration(com.devonfw.cobigen.impl.config.ContextConfiguration)

Example 2 with ContextConfiguration

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;
}
Also used : MapperFacade(ma.glasnost.orika.MapperFacade) NotYetSupportedException(com.devonfw.cobigen.api.exception.NotYetSupportedException) BigDecimal(java.math.BigDecimal) MapperFactory(ma.glasnost.orika.MapperFactory) DefaultMapperFactory(ma.glasnost.orika.impl.DefaultMapperFactory) ContextConfiguration(com.devonfw.cobigen.impl.config.ContextConfiguration)

Example 3 with ContextConfiguration

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;
}
Also used : Path(java.nio.file.Path) TemplateConfigurationUpgrader(com.devonfw.cobigen.impl.config.upgrade.TemplateConfigurationUpgrader) Trigger(com.devonfw.cobigen.impl.config.entity.Trigger) ContextConfiguration(com.devonfw.cobigen.impl.config.ContextConfiguration) TemplatesConfigurationVersion(com.devonfw.cobigen.impl.config.constant.TemplatesConfigurationVersion) File(java.io.File)

Aggregations

ContextConfiguration (com.devonfw.cobigen.impl.config.ContextConfiguration)3 Trigger (com.devonfw.cobigen.impl.config.entity.Trigger)2 Path (java.nio.file.Path)2 CobiGenRuntimeException (com.devonfw.cobigen.api.exception.CobiGenRuntimeException)1 NotYetSupportedException (com.devonfw.cobigen.api.exception.NotYetSupportedException)1 TemplatesConfigurationVersion (com.devonfw.cobigen.impl.config.constant.TemplatesConfigurationVersion)1 TemplateConfigurationUpgrader (com.devonfw.cobigen.impl.config.upgrade.TemplateConfigurationUpgrader)1 BackupFailedException (com.devonfw.cobigen.impl.exceptions.BackupFailedException)1 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 MapperFacade (ma.glasnost.orika.MapperFacade)1 MapperFactory (ma.glasnost.orika.MapperFactory)1 DefaultMapperFactory (ma.glasnost.orika.impl.DefaultMapperFactory)1