Search in sources :

Example 1 with ServiceConfiguration

use of net.nemerosa.ontrack.model.structure.ServiceConfiguration in project ontrack by nemerosa.

the class BuildGitCommitLinkMigrationAction method migrateBranchConfigurations.

private void migrateBranchConfigurations(Connection connection) throws SQLException, IOException {
    // For all branches...
    try (PreparedStatement psBranches = connection.prepareStatement("SELECT ID FROM BRANCHES")) {
        try (ResultSet rsBranches = psBranches.executeQuery()) {
            while (rsBranches.next()) {
                int branchId = rsBranches.getInt("ID");
                // For all the Git branch configurations
                try (PreparedStatement psProperty = connection.prepareStatement("SELECT * FROM PROPERTIES WHERE TYPE = ? AND BRANCH = ?", ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE)) {
                    psProperty.setString(1, GitBranchConfigurationPropertyType.class.getName());
                    psProperty.setInt(2, branchId);
                    try (ResultSet rsProperty = psProperty.executeQuery()) {
                        while (rsProperty.next()) {
                            logger.info("Migrating Branch Git configuration: {}", branchId);
                            // Configuration as JSON
                            String json = rsProperty.getString("JSON");
                            // Parses the configuration
                            JsonNode node = objectMapper.readTree(json);
                            // Gets any existing tag pattern
                            String tagPattern = JsonUtils.get(node, "tagPattern", "*");
                            // Creates the commit link
                            ServiceConfiguration buildCommitLink;
                            if ("*".equals(tagPattern)) {
                                buildCommitLink = TagBuildNameGitCommitLink.DEFAULT.toServiceConfiguration();
                            } else {
                                buildCommitLink = new ServiceConfiguration("tagPattern", JsonUtils.object().with("pattern", tagPattern).end());
                            }
                            // Creates the new property
                            GitBranchConfigurationProperty property = new GitBranchConfigurationProperty(JsonUtils.get(node, "branch"), buildCommitLink, JsonUtils.getBoolean(node, "override"), JsonUtils.getInt(node, "buildTagInterval"));
                            // Saves the data back
                            rsProperty.updateString("json", objectMapper.writeValueAsString(property));
                            rsProperty.updateRow();
                        }
                    }
                }
            }
        }
    }
}
Also used : GitBranchConfigurationPropertyType(net.nemerosa.ontrack.extension.git.property.GitBranchConfigurationPropertyType) ServiceConfiguration(net.nemerosa.ontrack.model.structure.ServiceConfiguration) GitBranchConfigurationProperty(net.nemerosa.ontrack.extension.git.property.GitBranchConfigurationProperty) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 2 with ServiceConfiguration

use of net.nemerosa.ontrack.model.structure.ServiceConfiguration in project ontrack by nemerosa.

the class BuildSvnRevisionLinkMigrationAction method migrateSvnBranchConfiguration.

protected void migrateSvnBranchConfiguration(ObjectNode node) {
    // Gets the build path & branch path
    String branchPath = node.get("branchPath").asText();
    String buildPath = node.get("buildPath").asText();
    // Removes the build path property
    node.remove("buildPath");
    // Converts to a service configuration
    ConfiguredBuildSvnRevisionLink<?> configuredBuildSvnRevisionLink = toBuildSvnRevisionLinkConfiguration(buildPath);
    // Gets the configuration representation
    ServiceConfiguration serviceConfiguration = configuredBuildSvnRevisionLink.toServiceConfiguration();
    // As json...
    node.put("buildRevisionLink", (ObjectNode) objectMapper.valueToTree(serviceConfiguration));
    // Logging
    try {
        logger.info("SVN branch config for {} with build expression {} has been converted to {}", branchPath, buildPath, objectMapper.writeValueAsString(serviceConfiguration));
    } catch (IOException ex) {
        throw new JsonClientMappingException(ex);
    }
}
Also used : ServiceConfiguration(net.nemerosa.ontrack.model.structure.ServiceConfiguration) IOException(java.io.IOException) JsonClientMappingException(net.nemerosa.ontrack.client.JsonClientMappingException)

Aggregations

ServiceConfiguration (net.nemerosa.ontrack.model.structure.ServiceConfiguration)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 JsonClientMappingException (net.nemerosa.ontrack.client.JsonClientMappingException)1 GitBranchConfigurationProperty (net.nemerosa.ontrack.extension.git.property.GitBranchConfigurationProperty)1 GitBranchConfigurationPropertyType (net.nemerosa.ontrack.extension.git.property.GitBranchConfigurationPropertyType)1