Skip to content

Commit

Permalink
MID-8842 ninja - improving upgrade constants
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Jul 26, 2023
1 parent 7bf7ca8 commit b982107
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,17 @@

public class UpgradeConstants {

public static final String SUPPORTED_VERSION_LTS = "4.4.5";

public static final String SUPPORTED_VERSION_FEATURE = "4.7.1";

// todo, master doesn't have a version to upgrade to..., support branches do have this one
/**
* This is the version we are upgrading from.
* It's current version.
*/
public static final String SUPPORTED_VERSION = "4.8";

/**
* This is the version we are upgrading to.
* For "master" branch it is null - there's nothing newer than master - nothing to upgrade to.
*/
public static final String SUPPORTED_VERSION_TARGET = null;

public static final String[] SUPPORTED_VERSIONS = { SUPPORTED_VERSION_LTS, SUPPORTED_VERSION_FEATURE };

public static final String UPGRADE_TEMP_DIRECTORY = ".upgrade";

public static final String LABEL_SCHEMA_CHANGE_NUMBER = "schemaChangeNumber";

public static final String LABEL_SCHEMA_AUDIT_CHANGE_NUMBER = "schemaAuditChangeNumber";

public static final String SUPPORTED_SCHEMA_CHANGE_NUMBER = Integer.toString(15);

public static final String SUPPORTED_SCHEMA_AUDIT_CHANGE_NUMBER = Integer.toString(4);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.evolveum.midpoint.ninja.util.ConsoleFormat;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.repo.api.RepositoryService;
import com.evolveum.midpoint.repo.sqale.SqaleUtils;
import com.evolveum.midpoint.schema.LabeledString;
import com.evolveum.midpoint.schema.RepositoryDiag;
import com.evolveum.midpoint.schema.SearchResultList;
Expand Down Expand Up @@ -52,16 +53,16 @@ private boolean checkDatabaseSchemaVersion(RepositoryService repository) {
RepositoryDiag diag = repository.getRepositoryDiag();

boolean result = validateChangeNumber(
diag.getAdditionalDetails(), UpgradeConstants.LABEL_SCHEMA_CHANGE_NUMBER,
UpgradeConstants.SUPPORTED_SCHEMA_CHANGE_NUMBER);
diag.getAdditionalDetails(), SqaleUtils.SCHEMA_CHANGE_NUMBER,
SqaleUtils.SCHEMA_CHANGE_NUMBER);
if (!result) {
return false;
}

// todo this will not work if audit was not configured or is in different database!
return validateChangeNumber(
diag.getAdditionalDetails(), UpgradeConstants.LABEL_SCHEMA_AUDIT_CHANGE_NUMBER,
UpgradeConstants.SUPPORTED_SCHEMA_AUDIT_CHANGE_NUMBER);
diag.getAdditionalDetails(), SqaleUtils.SCHEMA_AUDIT_CHANGE_NUMBER,
SqaleUtils.SCHEMA_AUDIT_CHANGE_NUMBER);
}

private boolean validateChangeNumber(List<LabeledString> list, String label, String expected) {
Expand Down Expand Up @@ -117,11 +118,10 @@ private boolean checkNodesVersion(RepositoryService repository) throws SchemaExc
"Node versions in cluster: ", Arrays.toString(versions.toArray())));

String version = versions.iterator().next();
boolean match = Arrays.asList(UpgradeConstants.SUPPORTED_VERSIONS).contains(version);
if (!match) {
if (!Objects.equals(version, UpgradeConstants.SUPPORTED_VERSION)) {
log.error(ConsoleFormat.formatErrorMessageWithParameter(
"There are midPoint nodes with versions that doesn't match supported version for upgrade (" +
Arrays.toString(UpgradeConstants.SUPPORTED_VERSIONS) + ")", Arrays.toString(versions.toArray())));
UpgradeConstants.SUPPORTED_VERSION + ")", Arrays.toString(versions.toArray())));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

import com.evolveum.midpoint.ninja.action.upgrade.UpgradeConstants;
import com.evolveum.midpoint.repo.sqale.SqaleUtils;

@ContextConfiguration(locations = "classpath:ctx-ninja-test.xml")
@DirtiesContext
Expand Down Expand Up @@ -48,8 +48,8 @@ public void test200TestWrongSchemaVersion() throws Exception {

try (Connection connection = repositoryDataSource.getConnection()) {
JdbcTemplate template = new JdbcTemplate(new SingleConnectionDataSource(connection, true));
template.update("update m_global_metadata set value=? where name = ?", "123456", UpgradeConstants.LABEL_SCHEMA_CHANGE_NUMBER);
template.execute("commit");
template.update("UPDATE m_global_metadata SET value=? WHERE name = ?", "123456", SqaleUtils.SCHEMA_CHANGE_NUMBER);
template.execute("COMMIT");
}

when();
Expand Down

0 comments on commit b982107

Please sign in to comment.