Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSB-4637 Narayana-spring-boot components upgrade #96

Merged
merged 4 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public class NarayanaProperties {
/**
* XA recovery nodes.
*/
private List<String> xaRecoveryNodes = List.of("1");
private List<String> xaRecoveryNodes = List.of();

public String getLogDir() {
return this.logDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package me.snowdrop.boot.narayana.core.properties;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.List;

import com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean;
Expand All @@ -34,6 +37,8 @@
*/
public class NarayanaPropertiesInitializer implements InitializingBean {

private static final String HASH_ALGORITHM_FOR_SHORTENING = "SHA-224";

private final NarayanaProperties properties;

public NarayanaPropertiesInitializer(NarayanaProperties narayanaProperties) {
Expand All @@ -59,14 +64,28 @@ public void afterPropertiesSet() {
}

private void setNodeIdentifier(String nodeIdentifier) {
String verifiedNodeIdentifier = nodeIdentifier;
try {
getPopulator(CoreEnvironmentBean.class).setNodeIdentifier(nodeIdentifier);
} catch (CoreEnvironmentBeanException e) {
if (nodeIdentifier != null && nodeIdentifier.getBytes(StandardCharsets.UTF_8).length > 28) {
verifiedNodeIdentifier = shortenNodeIdentifier(nodeIdentifier);
}

getPopulator(CoreEnvironmentBean.class).setNodeIdentifier(verifiedNodeIdentifier);
} catch (CoreEnvironmentBeanException | NoSuchAlgorithmException e) {
throw new IllegalArgumentException(e);
}
}

private String shortenNodeIdentifier(String nodeIdentifier) throws NoSuchAlgorithmException {
final byte[] nodeIdentifierAsBytes = nodeIdentifier.getBytes();
MessageDigest messageDigest224 = MessageDigest.getInstance(HASH_ALGORITHM_FOR_SHORTENING);
return new String(messageDigest224.digest(nodeIdentifierAsBytes), StandardCharsets.UTF_8);
}

private void setXARecoveryNodes(List<String> xaRecoveryNodes) {
if (xaRecoveryNodes.isEmpty()) {
xaRecoveryNodes = List.of(getPopulator(CoreEnvironmentBean.class).getNodeIdentifier());
}
getPopulator(JTAEnvironmentBean.class).setXaRecoveryNodes(xaRecoveryNodes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package me.snowdrop.boot.narayana.core.properties;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -56,6 +55,8 @@ void shouldSetDefaultProperties() {

assertThat(BeanPopulator.getDefaultInstance(CoreEnvironmentBean.class)
.getNodeIdentifier()).isEqualTo("1");
assertThat(BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class)
.getXaRecoveryNodes()).containsOnly("1");
assertThat(BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class)
.getObjectStoreDir()).contains("ObjectStore");
assertThat(BeanPopulator
Expand All @@ -75,7 +76,7 @@ void shouldSetDefaultProperties() {
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getExpiryScanInterval()).isEqualTo(12);

List<String> xaResourceOrphanFilters = Arrays.asList(
List<String> xaResourceOrphanFilters = List.of(
"com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter",
"com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter",
"com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter");
Expand All @@ -95,15 +96,15 @@ void shouldSetDefaultProperties() {
.getCommitMarkableResourceJNDINames())
.isEmpty();

List<String> recoveryModules = Arrays.asList(
List<String> recoveryModules = List.of(
"com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule",
"com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule",
"com.arjuna.ats.internal.txoj.recovery.TORecoveryModule",
"com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getRecoveryModuleClassNames()).isEqualTo(recoveryModules);

List<String> expiryScanners = Arrays.asList(
List<String> expiryScanners = List.of(
"com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getExpiryScannerClassNames()).isEqualTo(expiryScanners);
Expand All @@ -115,22 +116,25 @@ void shouldSetDefaultProperties() {
@Test
void shouldSetModifiedProperties() {
NarayanaProperties narayanaProperties = new NarayanaProperties();
narayanaProperties.setTransactionManagerId("test-id");
narayanaProperties.setTransactionManagerId("test-id-1");
narayanaProperties.setXaRecoveryNodes(List.of("test-id-1", "test-id-2"));
narayanaProperties.setLogDir("test-dir");
narayanaProperties.setDefaultTimeout(1);
narayanaProperties.setPeriodicRecoveryPeriod(2);
narayanaProperties.setRecoveryBackoffPeriod(3);
narayanaProperties.setOnePhaseCommit(false);
narayanaProperties.setXaResourceOrphanFilters(Arrays.asList("test-filter-1", "test-filter-2"));
narayanaProperties.setRecoveryModules(Arrays.asList("test-module-1", "test-module-2"));
narayanaProperties.setExpiryScanners(Arrays.asList("test-scanner-1", "test-scanner-2"));
narayanaProperties.setXaResourceOrphanFilters(List.of("test-filter-1", "test-filter-2"));
narayanaProperties.setRecoveryModules(List.of("test-module-1", "test-module-2"));
narayanaProperties.setExpiryScanners(List.of("test-scanner-1", "test-scanner-2"));

NarayanaPropertiesInitializer narayanaPropertiesInitializer =
new NarayanaPropertiesInitializer(narayanaProperties);
narayanaPropertiesInitializer.afterPropertiesSet();

assertThat(BeanPopulator.getDefaultInstance(CoreEnvironmentBean.class)
.getNodeIdentifier()).isEqualTo("test-id");
.getNodeIdentifier()).isEqualTo("test-id-1");
assertThat(BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class)
.getXaRecoveryNodes()).containsExactly("test-id-1", "test-id-2");
assertThat(BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class)
.getObjectStoreDir()).isEqualTo("test-dir");
assertThat(BeanPopulator
Expand All @@ -149,12 +153,12 @@ void shouldSetModifiedProperties() {
.getRecoveryBackoffPeriod()).isEqualTo(3);
assertThat(BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class)
.getXaResourceOrphanFilterClassNames())
.isEqualTo(Arrays.asList("test-filter-1", "test-filter-2"));
.isEqualTo(List.of("test-filter-1", "test-filter-2"));
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getRecoveryModuleClassNames())
.isEqualTo(Arrays.asList("test-module-1", "test-module-2"));
.isEqualTo(List.of("test-module-1", "test-module-2"));
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getExpiryScannerClassNames())
.isEqualTo(Arrays.asList("test-scanner-1", "test-scanner-2"));
.isEqualTo(List.of("test-scanner-1", "test-scanner-2"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package me.snowdrop.boot.narayana.openshift.recovery;

import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.openshift.client.DefaultOpenShiftClient;
import io.fabric8.kubernetes.client.KubernetesClientBuilder;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
Expand Down Expand Up @@ -45,7 +45,7 @@ public PodStatusManager podStatusManager(StatefulsetRecoveryControllerProperties
@Bean(destroyMethod = "close")
@ConditionalOnMissingBean(KubernetesClient.class)
public KubernetesClient kubernetesClient() {
return new DefaultOpenShiftClient();
return new KubernetesClientBuilder().build();
}

@Bean
Expand Down
18 changes: 9 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,26 +50,26 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<agroal.version>2.2</agroal.version>
<agroal.version>2.3</agroal.version>
<awaitility.version>4.2.0</awaitility.version>
<byteman.version>4.0.21</byteman.version>
<camel.version>4.4.0</camel.version>
<camel-spring-boot.version>4.4.0</camel-spring-boot.version>
<narayana.version>7.0.0.Final</narayana.version>
<openshift-client.version>6.10.0</openshift-client.version>
<narayana.version>7.0.1.Final</narayana.version>
<openshift-client.version>6.13.0</openshift-client.version>
<spring-boot.version>3.2.7</spring-boot.version>

<maven-checkstyle-plugin.version>3.3.0</maven-checkstyle-plugin.version>
<maven-checkstyle-plugin.version>3.3.1</maven-checkstyle-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<maven-deploy-plugin.version>3.1.1</maven-deploy-plugin.version>
<maven-enforcer-plugin.version>3.3.0</maven-enforcer-plugin.version>
<maven-failsafe-plugin.version>3.0.0</maven-failsafe-plugin.version>
<maven-enforcer-plugin.version>3.4.1</maven-enforcer-plugin.version>
<maven-failsafe-plugin.version>3.1.2</maven-failsafe-plugin.version>
<maven-gpg-plugin.version>3.1.0</maven-gpg-plugin.version>
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version>
<maven-javadoc-plugin.version>3.5.0</maven-javadoc-plugin.version>
<maven-javadoc-plugin.version>3.6.3</maven-javadoc-plugin.version>
<maven-release-plugin.version>3.0.1</maven-release-plugin.version>
<maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
<maven-source-plugin.version>3.2.1</maven-source-plugin.version>
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
<maven-source-plugin.version>3.3.0</maven-source-plugin.version>
</properties>

<scm>
Expand Down