You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/01/27 09:02:31 UTC

[GitHub] [shardingsphere] jingshanglu opened a new pull request #15115: Make It is easy to use with narayana

jingshanglu opened a new pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115


   Fixes #14508 .
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#issuecomment-1024612807


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15115](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (179ab3f) into [master](https://codecov.io/gh/apache/shardingsphere/commit/d8621d6bcd04a73b99cf115aca1f3f84216d18f4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d8621d6) will **decrease** coverage by `0.07%`.
   > The diff coverage is `6.81%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15115/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15115      +/-   ##
   ============================================
   - Coverage     60.19%   60.12%   -0.08%     
     Complexity     1941     1941              
   ============================================
     Files          3189     3190       +1     
     Lines         47645    47731      +86     
     Branches       8099     8110      +11     
   ============================================
   + Hits          28682    28699      +17     
   - Misses        16645    16711      +66     
   - Partials       2318     2321       +3     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../shardingsphere/mode/utils/NarayanaConfigUtil.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL21vZGUvdXRpbHMvTmFyYXlhbmFDb25maWdVdGlsLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...de/manager/memory/MemoryContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtbWVtb3J5LW1vZGUvc2hhcmRpbmdzcGhlcmUtbWVtb3J5LW1vZGUtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvbW9kZS9tYW5hZ2VyL21lbW9yeS9NZW1vcnlDb250ZXh0TWFuYWdlckJ1aWxkZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [.../manager/cluster/ClusterContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtY2x1c3Rlci1tb2RlL3NoYXJkaW5nc3BoZXJlLWNsdXN0ZXItbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvY2x1c3Rlci9DbHVzdGVyQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `72.09% <100.00%> (+1.36%)` | :arrow_up: |
   | [...er/standalone/StandaloneContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtc3RhbmRhbG9uZS1tb2RlL3NoYXJkaW5nc3BoZXJlLXN0YW5kYWxvbmUtbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvc3RhbmRhbG9uZS9TdGFuZGFsb25lQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `90.62% <100.00%> (+0.62%)` | :arrow_up: |
   | [.../coordinator/ClusterContextManagerCoordinator.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtY2x1c3Rlci1tb2RlL3NoYXJkaW5nc3BoZXJlLWNsdXN0ZXItbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvY2x1c3Rlci9jb29yZGluYXRvci9DbHVzdGVyQ29udGV4dE1hbmFnZXJDb29yZGluYXRvci5qYXZh) | `79.10% <0.00%> (+19.40%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [d8621d6...179ab3f](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r802259677



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigFacade.java
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.xa.narayana.util;
+
+import com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore;
+import com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;
+import com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule;
+import com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+import org.apache.shardingsphere.transaction.spi.TransactionConfigFacade;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+public class NarayanaConfigFacade implements TransactionConfigFacade {

Review comment:
       Please add java doc

##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigFacade.java
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.xa.narayana.util;
+
+import com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore;
+import com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;
+import com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule;
+import com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+import org.apache.shardingsphere.transaction.spi.TransactionConfigFacade;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+public class NarayanaConfigFacade implements TransactionConfigFacade {

Review comment:
       Please use final with class if the class not for extension.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jingshanglu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
jingshanglu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r794357094



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +75,102 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml((LinkedHashMap<Object, Object>) result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        System.out.println(path);
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }

Review comment:
       Config of transaction is `org.apache.shardingsphere.transaction.rule.TransactionRule`, all types of transactions share the `props` field.
   ```
   public final class TransactionRule implements GlobalRule {
       
       private final TransactionType defaultType;
       
       private final String providerType;
       
       private final Properties props; 
       
       public TransactionRule(final TransactionRuleConfiguration ruleConfig) {
           defaultType = TransactionType.valueOf(ruleConfig.getDefaultType().toUpperCase());
           providerType = ruleConfig.getProviderType();
           props = ruleConfig.getProps();
       }
       
       @Override
       public String getType() {
           return TransactionRule.class.getSimpleName();
       }
   }
   ```
   `TransactionContextsBuilder` is the general entry for transaction engine initialization. In `TransactionContextsBuilder`, the transaction engine is initialized according to the configuration.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r795010537



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +75,102 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml((LinkedHashMap<Object, Object>) result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        System.out.println(path);
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }

Review comment:
       What I mean is `narayana` should not occur in TransactionContextsBuilder class. The common class should not handle concrete transaction type impl




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#issuecomment-1024612807


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15115](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (42cab77) into [master](https://codecov.io/gh/apache/shardingsphere/commit/d8621d6bcd04a73b99cf115aca1f3f84216d18f4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d8621d6) will **decrease** coverage by `0.07%`.
   > The diff coverage is `7.86%`.
   
   > :exclamation: Current head 42cab77 differs from pull request most recent head 179ab3f. Consider uploading reports for the commit 179ab3f to get more accurate results
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15115/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15115      +/-   ##
   ============================================
   - Coverage     60.19%   60.12%   -0.08%     
     Complexity     1941     1941              
   ============================================
     Files          3189     3190       +1     
     Lines         47645    47732      +87     
     Branches       8099     8110      +11     
   ============================================
   + Hits          28682    28697      +15     
   - Misses        16645    16714      +69     
   - Partials       2318     2321       +3     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [.../shardingsphere/mode/utils/NarayanaConfigUtil.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL21vZGUvdXRpbHMvTmFyYXlhbmFDb25maWdVdGlsLmphdmE=) | `0.00% <0.00%> (ø)` | |
   | [...de/manager/memory/MemoryContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtbWVtb3J5LW1vZGUvc2hhcmRpbmdzcGhlcmUtbWVtb3J5LW1vZGUtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvbW9kZS9tYW5hZ2VyL21lbW9yeS9NZW1vcnlDb250ZXh0TWFuYWdlckJ1aWxkZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ransaction/context/TransactionContextsBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUta2VybmVsL3NoYXJkaW5nc3BoZXJlLXRyYW5zYWN0aW9uL3NoYXJkaW5nc3BoZXJlLXRyYW5zYWN0aW9uLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3RyYW5zYWN0aW9uL2NvbnRleHQvVHJhbnNhY3Rpb25Db250ZXh0c0J1aWxkZXIuamF2YQ==) | `83.33% <100.00%> (+1.51%)` | :arrow_up: |
   | [.../manager/cluster/ClusterContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtY2x1c3Rlci1tb2RlL3NoYXJkaW5nc3BoZXJlLWNsdXN0ZXItbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvY2x1c3Rlci9DbHVzdGVyQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `72.09% <100.00%> (+1.36%)` | :arrow_up: |
   | [...er/standalone/StandaloneContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtc3RhbmRhbG9uZS1tb2RlL3NoYXJkaW5nc3BoZXJlLXN0YW5kYWxvbmUtbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvc3RhbmRhbG9uZS9TdGFuZGFsb25lQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `90.62% <100.00%> (+0.62%)` | :arrow_up: |
   | [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   | [.../coordinator/ClusterContextManagerCoordinator.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtY2x1c3Rlci1tb2RlL3NoYXJkaW5nc3BoZXJlLWNsdXN0ZXItbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvY2x1c3Rlci9jb29yZGluYXRvci9DbHVzdGVyQ29udGV4dE1hbmFnZXJDb29yZGluYXRvci5qYXZh) | `79.10% <0.00%> (+19.40%)` | :arrow_up: |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [d8621d6...179ab3f](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] totalo commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
totalo commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r793419280



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +75,100 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = NarayanaConfigMapToXml((LinkedHashMap<Object, Object>) result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        System.out.println(path);
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }
+
+    private void swapJdbcStore(final TransactionRule transactionRule, Map<Object, Object> config) {
+        Object host = transactionRule.getProps().get("host");
+        Object port = transactionRule.getProps().get("port");
+        Object user = transactionRule.getProps().getProperty("user");
+        Object password = transactionRule.getProps().getProperty("password");
+        Object databaseName = transactionRule.getProps().getProperty("databaseName");
+        if (null != host && null != port && null != user && null != password && null != databaseName) {
+            String jdbcAccess = String.format("com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;ClassName=com.mysql.cj.jdbc.MysqlDataSource;URL=jdbc:mysql://%s:%d/%s;User=%s;Password=%s", host, port, databaseName, user, password);
+            config.put("ObjectStoreEnvironmentBean.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.tablePrefix", "Action");
+            config.put("ObjectStoreEnvironmentBean.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.stateStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.stateStore.tablePrefix", "stateStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.tablePrefix", "Communication");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.dropTable", true);
+        }
+    }
+
+    private Map<Object, Object> generateDefaultNarayanaConfig() {
+        Map<Object, Object> result = new LinkedHashMap<>();
+        result.put("CoordinatorEnvironmentBean.commitOnePhase", "YES");
+        result.put("ObjectStoreEnvironmentBean.transactionSync", "ON");
+        result.put("CoreEnvironmentBean.nodeIdentifier", null == instanceId ? 1 : instanceId);
+        result.put("JTAEnvironmentBean.xaRecoveryNodes", null == instanceId ? 1 : instanceId);
+        List<String> xaResourceOrphanFilterClassNames = new LinkedList<>();
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter");
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter");
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter");
+        result.put("JTAEnvironmentBean.xaResourceOrphanFilterClassNames", xaResourceOrphanFilterClassNames);
+        result.put("CoreEnvironmentBean.socketProcessIdPort", 0);
+        List<String> recoveryModuleClassNames = new LinkedList<>();
+        recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
+        recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
+        result.put("RecoveryEnvironmentBean.recoveryModuleClassNames", recoveryModuleClassNames);
+        result.put("RecoveryEnvironmentBean.expiryScannerClassNames", "com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
+        result.put("RecoveryEnvironmentBean.recoveryPort", 4712);
+        result.put("RecoveryEnvironmentBean.recoveryAddress", null);
+        result.put("RecoveryEnvironmentBean.transactionStatusManagerPort", 0);
+        result.put("RecoveryEnvironmentBean.transactionStatusManagerAddress", null);
+        result.put("RecoveryEnvironmentBean.recoveryListener", "NO");
+        result.put("RecoveryEnvironmentBean.recoveryBackoffPeriod", 1);
+        return result;
+    }
+
+    private String NarayanaConfigMapToXml(LinkedHashMap<Object, Object> sortedMap) {

Review comment:
       Maybe we can consider using freemark?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r802257985



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.spi;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Transaction config factory.
+ */
+public class TransactionConfigFactory {

Review comment:
       Please use final with class if the class not for extension.

##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.spi;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Transaction config factory.
+ */
+public class TransactionConfigFactory {
+
+    private static final Map<String, TransactionConfigFacade> SERVICES = new ConcurrentHashMap<>();
+
+    static {
+        for (TransactionConfigFacade each : ServiceLoader.load(TransactionConfigFacade.class)) {
+            SERVICES.put(each.getTransactionType(), each);
+        }
+    }

Review comment:
       Please reuse `ShardingSphereServiceLoader`

##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.spi;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Transaction config factory.
+ */
+public class TransactionConfigFactory {
+
+    private static final Map<String, TransactionConfigFacade> SERVICES = new ConcurrentHashMap<>();
+
+    static {
+        for (TransactionConfigFacade each : ServiceLoader.load(TransactionConfigFacade.class)) {
+            SERVICES.put(each.getTransactionType(), each);
+        }
+    }
+
+    /**
+     * Get transaction config facade instance.
+     *
+     * @param transactionProviderType transaction provider type
+     * @return transaction config facade
+     */
+    public static TransactionConfigFacade newInstance(final String transactionProviderType) {
+        if (null != transactionProviderType) {
+            return SERVICES.get(transactionProviderType);

Review comment:
       It is better to reuse `TypedSPIRegistry`

##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFactory.java
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.spi;
+
+import java.util.Map;
+import java.util.ServiceLoader;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Transaction config factory.
+ */
+public class TransactionConfigFactory {
+
+    private static final Map<String, TransactionConfigFacade> SERVICES = new ConcurrentHashMap<>();
+
+    static {
+        for (TransactionConfigFacade each : ServiceLoader.load(TransactionConfigFacade.class)) {
+            SERVICES.put(each.getTransactionType(), each);
+        }
+    }
+
+    /**
+     * Get transaction config facade instance.
+     *
+     * @param transactionProviderType transaction provider type
+     * @return transaction config facade
+     */
+    public static TransactionConfigFacade newInstance(final String transactionProviderType) {

Review comment:
       Please use Optional instead of `null`

##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/spi/TransactionConfigFacade.java
##########
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.spi;
+
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+/**
+ * Transaction config facade.
+ */
+public interface TransactionConfigFacade {

Review comment:
       It is better to reuse `TypedSPI`

##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-type/shardingsphere-transaction-xa/shardingsphere-transaction-xa-provider/shardingsphere-transaction-xa-narayana/src/main/java/org/apache/shardingsphere/transaction/xa/narayana/util/NarayanaConfigFacade.java
##########
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.transaction.xa.narayana.util;
+
+import com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore;
+import com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;
+import com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule;
+import com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter;
+import com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+import org.apache.shardingsphere.transaction.spi.TransactionConfigFacade;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+@Slf4j
+public class NarayanaConfigFacade implements TransactionConfigFacade {
+
+    @Override
+    public void generate(final TransactionRule transactionRule, final String instanceId) {
+        if (null == transactionRule) {
+            return;
+        }
+        Map<Object, Object> content;
+        content = generateDefaultNarayanaConfig(instanceId);
+        if (null != transactionRule.getProps()) {
+            swapJdbcStore(transactionRule, content);
+        }
+        String value = narayanaConfigMapToXml(content);
+        String path = ClassLoader.getSystemResource("").getPath();
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }
+
+    @Override
+    public String getTransactionType() {
+        return "Narayana";
+    }
+
+    private static void swapJdbcStore(final TransactionRule transactionRule, final Map<Object, Object> config) {

Review comment:
       Private method should be just next to the method in which it is used




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu merged pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu merged pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r794351754



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +74,99 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {

Review comment:
       The Narayana impl still is `TransactionContextsBuilder` which should move out of common module

##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +74,99 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml(result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }
+
+    private void swapJdbcStore(final TransactionRule transactionRule, final Map<Object, Object> config) {
+        Object host = transactionRule.getProps().get("host");
+        Object port = transactionRule.getProps().get("port");
+        Object user = transactionRule.getProps().getProperty("user");
+        Object password = transactionRule.getProps().getProperty("password");
+        Object databaseName = transactionRule.getProps().getProperty("databaseName");
+        if (null != host && null != port && null != user && null != password && null != databaseName) {
+            String jdbcAccessPatten = "com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;"
+                    + "ClassName=com.mysql.cj.jdbc.MysqlDataSource;URL=jdbc:mysql://%s:%d/%s;User=%s;Password=%s";
+            String jdbcAccess = String.format(jdbcAccessPatten, host, port, databaseName, user, password);
+            config.put("ObjectStoreEnvironmentBean.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.tablePrefix", "Action");
+            config.put("ObjectStoreEnvironmentBean.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.stateStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.stateStore.tablePrefix", "stateStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.tablePrefix", "Communication");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.dropTable", true);
+        }
+    }
+
+    private Map<Object, Object> generateDefaultNarayanaConfig() {
+        Map<Object, Object> result = new LinkedHashMap<>();
+        result.put("CoordinatorEnvironmentBean.commitOnePhase", "YES");
+        result.put("ObjectStoreEnvironmentBean.transactionSync", "ON");
+        result.put("CoreEnvironmentBean.nodeIdentifier", null == instanceId ? 1 : instanceId);
+        result.put("JTAEnvironmentBean.xaRecoveryNodes", null == instanceId ? 1 : instanceId);
+        List<String> xaResourceOrphanFilterClassNames = new LinkedList<>();
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter");
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter");
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter");
+        result.put("JTAEnvironmentBean.xaResourceOrphanFilterClassNames", xaResourceOrphanFilterClassNames);
+        result.put("CoreEnvironmentBean.socketProcessIdPort", 0);
+        List<String> recoveryModuleClassNames = new LinkedList<>();
+        recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
+        recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
+        result.put("RecoveryEnvironmentBean.recoveryModuleClassNames", recoveryModuleClassNames);
+        result.put("RecoveryEnvironmentBean.expiryScannerClassNames", "com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
+        result.put("RecoveryEnvironmentBean.recoveryPort", 4712);
+        result.put("RecoveryEnvironmentBean.recoveryAddress", null);
+        result.put("RecoveryEnvironmentBean.transactionStatusManagerPort", 0);
+        result.put("RecoveryEnvironmentBean.transactionStatusManagerAddress", null);
+        result.put("RecoveryEnvironmentBean.recoveryListener", "NO");
+        result.put("RecoveryEnvironmentBean.recoveryBackoffPeriod", 1);
+        return result;
+    }
+
+    private String narayanaConfigMapToXml(final Map<Object, Object> config) {
+        StringBuilder sb = new StringBuilder("<properties>");
+        for (Object o : config.keySet()) {

Review comment:
       Please rename `o` as `each`

##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +74,99 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml(result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }
+
+    private void swapJdbcStore(final TransactionRule transactionRule, final Map<Object, Object> config) {
+        Object host = transactionRule.getProps().get("host");
+        Object port = transactionRule.getProps().get("port");
+        Object user = transactionRule.getProps().getProperty("user");
+        Object password = transactionRule.getProps().getProperty("password");
+        Object databaseName = transactionRule.getProps().getProperty("databaseName");
+        if (null != host && null != port && null != user && null != password && null != databaseName) {
+            String jdbcAccessPatten = "com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;"
+                    + "ClassName=com.mysql.cj.jdbc.MysqlDataSource;URL=jdbc:mysql://%s:%d/%s;User=%s;Password=%s";
+            String jdbcAccess = String.format(jdbcAccessPatten, host, port, databaseName, user, password);
+            config.put("ObjectStoreEnvironmentBean.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.tablePrefix", "Action");
+            config.put("ObjectStoreEnvironmentBean.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.stateStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.stateStore.tablePrefix", "stateStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.tablePrefix", "Communication");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.dropTable", true);
+        }
+    }
+
+    private Map<Object, Object> generateDefaultNarayanaConfig() {
+        Map<Object, Object> result = new LinkedHashMap<>();
+        result.put("CoordinatorEnvironmentBean.commitOnePhase", "YES");
+        result.put("ObjectStoreEnvironmentBean.transactionSync", "ON");
+        result.put("CoreEnvironmentBean.nodeIdentifier", null == instanceId ? 1 : instanceId);
+        result.put("JTAEnvironmentBean.xaRecoveryNodes", null == instanceId ? 1 : instanceId);
+        List<String> xaResourceOrphanFilterClassNames = new LinkedList<>();
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter");
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter");
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter");
+        result.put("JTAEnvironmentBean.xaResourceOrphanFilterClassNames", xaResourceOrphanFilterClassNames);
+        result.put("CoreEnvironmentBean.socketProcessIdPort", 0);
+        List<String> recoveryModuleClassNames = new LinkedList<>();
+        recoveryModuleClassNames.add("com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule");
+        recoveryModuleClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
+        result.put("RecoveryEnvironmentBean.recoveryModuleClassNames", recoveryModuleClassNames);
+        result.put("RecoveryEnvironmentBean.expiryScannerClassNames", "com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
+        result.put("RecoveryEnvironmentBean.recoveryPort", 4712);
+        result.put("RecoveryEnvironmentBean.recoveryAddress", null);
+        result.put("RecoveryEnvironmentBean.transactionStatusManagerPort", 0);
+        result.put("RecoveryEnvironmentBean.transactionStatusManagerAddress", null);
+        result.put("RecoveryEnvironmentBean.recoveryListener", "NO");
+        result.put("RecoveryEnvironmentBean.recoveryBackoffPeriod", 1);
+        return result;
+    }
+
+    private String narayanaConfigMapToXml(final Map<Object, Object> config) {
+        StringBuilder sb = new StringBuilder("<properties>");

Review comment:
       maybe `result` is better name




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter commented on pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
codecov-commenter commented on pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#issuecomment-1024612807


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15115](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (2e5f4e8) into [master](https://codecov.io/gh/apache/shardingsphere/commit/679e04b0552a4d11fc5596472f1a8dd91b66e634?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (679e04b) will **decrease** coverage by `0.13%`.
   > The diff coverage is `8.33%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15115/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15115      +/-   ##
   ============================================
   - Coverage     59.89%   59.75%   -0.14%     
   - Complexity     1922     1923       +1     
   ============================================
     Files          3165     3172       +7     
     Lines         47327    47580     +253     
     Branches       8051     8093      +42     
   ============================================
   + Hits          28345    28433      +88     
   - Misses        16696    16847     +151     
   - Partials       2286     2300      +14     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...de/manager/memory/MemoryContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtbWVtb3J5LW1vZGUvc2hhcmRpbmdzcGhlcmUtbWVtb3J5LW1vZGUtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvbW9kZS9tYW5hZ2VyL21lbW9yeS9NZW1vcnlDb250ZXh0TWFuYWdlckJ1aWxkZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...ransaction/context/TransactionContextsBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUta2VybmVsL3NoYXJkaW5nc3BoZXJlLXRyYW5zYWN0aW9uL3NoYXJkaW5nc3BoZXJlLXRyYW5zYWN0aW9uLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3RyYW5zYWN0aW9uL2NvbnRleHQvVHJhbnNhY3Rpb25Db250ZXh0c0J1aWxkZXIuamF2YQ==) | `13.48% <3.84%> (-68.34%)` | :arrow_down: |
   | [.../manager/cluster/ClusterContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtY2x1c3Rlci1tb2RlL3NoYXJkaW5nc3BoZXJlLWNsdXN0ZXItbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvY2x1c3Rlci9DbHVzdGVyQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `59.59% <100.00%> (+1.43%)` | :arrow_up: |
   | [...er/standalone/StandaloneContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtc3RhbmRhbG9uZS1tb2RlL3NoYXJkaW5nc3BoZXJlLXN0YW5kYWxvbmUtbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvc3RhbmRhbG9uZS9TdGFuZGFsb25lQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `82.75% <100.00%> (+1.58%)` | :arrow_up: |
   | [...encrypt/rewrite/util/EncryptPropertiesBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcmV3cml0ZS91dGlsL0VuY3J5cHRQcm9wZXJ0aWVzQnVpbGRlci5qYXZh) | `0.00% <0.00%> (-85.72%)` | :arrow_down: |
   | [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   | [...shardingsphere/mode/metadata/MetaDataContexts.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL21vZGUvbWV0YWRhdGEvTWV0YURhdGFDb250ZXh0cy5qYXZh) | `45.45% <0.00%> (-22.97%)` | :arrow_down: |
   | [...route/impl/ReadwriteSplittingDataSourceRouter.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtcmVhZHdyaXRlLXNwbGl0dGluZy9zaGFyZGluZ3NwaGVyZS1yZWFkd3JpdGUtc3BsaXR0aW5nLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3JlYWR3cml0ZXNwbGl0dGluZy9yb3V0ZS9pbXBsL1JlYWR3cml0ZVNwbGl0dGluZ0RhdGFTb3VyY2VSb3V0ZXIuamF2YQ==) | `55.55% <0.00%> (-15.88%)` | :arrow_down: |
   | [...che/shardingsphere/encrypt/rule/EncryptColumn.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcnVsZS9FbmNyeXB0Q29sdW1uLmphdmE=) | `50.00% <0.00%> (-12.50%)` | :arrow_down: |
   | [...pache/shardingsphere/encrypt/rule/EncryptRule.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtZmVhdHVyZXMvc2hhcmRpbmdzcGhlcmUtZW5jcnlwdC9zaGFyZGluZ3NwaGVyZS1lbmNyeXB0LWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL2VuY3J5cHQvcnVsZS9FbmNyeXB0UnVsZS5qYXZh) | `73.17% <0.00%> (-7.08%)` | :arrow_down: |
   | ... and [87 more](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [679e04b...2e5f4e8](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r801219633



##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/utils/NarayanaConfigUtil.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.utils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Narayana config utils.
+ */
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NarayanaConfigUtil {
+
+    /**
+     * generate narayana config file.
+     * @param metaDataContexts metadata contexts.

Review comment:
       Please keep empty line between method JavaDoc and @param

##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/utils/NarayanaConfigUtil.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.utils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Narayana config utils.
+ */
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NarayanaConfigUtil {
+
+    /**
+     * generate narayana config file.
+     * @param metaDataContexts metadata contexts.
+     * @param instanceId instance id.
+     */
+    public static void generateNarayanaConfig(final MetaDataContexts metaDataContexts, final String instanceId) {
+        TransactionRule transactionRule = metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst()
+                .get();
+        if (null == transactionRule) {
+            return;
+        }
+        Map<Object, Object> result;

Review comment:
       Please do not name this variable as `result` if the method return void

##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/utils/NarayanaConfigUtil.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.utils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Narayana config utils.
+ */
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NarayanaConfigUtil {
+
+    /**
+     * generate narayana config file.
+     * @param metaDataContexts metadata contexts.
+     * @param instanceId instance id.

Review comment:
       End of line do not need `.`

##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/utils/NarayanaConfigUtil.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.utils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Narayana config utils.
+ */
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NarayanaConfigUtil {
+
+    /**
+     * generate narayana config file.
+     * @param metaDataContexts metadata contexts.

Review comment:
       1. End of line do not need `.`
   2. meta data are tow words

##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/utils/NarayanaConfigUtil.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.utils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Narayana config utils.
+ */
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NarayanaConfigUtil {
+
+    /**
+     * generate narayana config file.
+     * @param metaDataContexts metadata contexts.
+     * @param instanceId instance id.
+     */
+    public static void generateNarayanaConfig(final MetaDataContexts metaDataContexts, final String instanceId) {
+        TransactionRule transactionRule = metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst()
+                .get();
+        if (null == transactionRule) {
+            return;
+        }
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig(instanceId);
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml(result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }
+
+    private static void swapJdbcStore(final TransactionRule transactionRule, final Map<Object, Object> config) {
+        Object host = transactionRule.getProps().get("host");
+        Object port = transactionRule.getProps().get("port");
+        Object user = transactionRule.getProps().getProperty("user");
+        Object password = transactionRule.getProps().getProperty("password");
+        Object databaseName = transactionRule.getProps().getProperty("databaseName");
+        if (null != host && null != port && null != user && null != password && null != databaseName) {
+            String jdbcAccessPatten = "com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;"
+                    + "ClassName=com.mysql.cj.jdbc.MysqlDataSource;URL=jdbc:mysql://%s:%d/%s;User=%s;Password=%s";
+            String jdbcAccess = String.format(jdbcAccessPatten, host, port, databaseName, user, password);
+            config.put("ObjectStoreEnvironmentBean.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.tablePrefix", "Action");
+            config.put("ObjectStoreEnvironmentBean.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.stateStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.stateStore.tablePrefix", "stateStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.tablePrefix", "Communication");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.dropTable", true);
+        }
+    }
+
+    private static Map<Object, Object> generateDefaultNarayanaConfig(final String instanceId) {
+        Map<Object, Object> result = new LinkedHashMap<>();
+        result.put("CoordinatorEnvironmentBean.commitOnePhase", "YES");
+        result.put("ObjectStoreEnvironmentBean.transactionSync", "ON");
+        result.put("CoreEnvironmentBean.nodeIdentifier", null == instanceId ? 1 : instanceId);
+        result.put("JTAEnvironmentBean.xaRecoveryNodes", null == instanceId ? 1 : instanceId);
+        List<String> xaResourceOrphanFilterClassNames = new LinkedList<>();

Review comment:
       `Collection<String>` is better than `List<String>`

##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/utils/NarayanaConfigUtil.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.utils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Narayana config utils.
+ */
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NarayanaConfigUtil {
+
+    /**
+     * generate narayana config file.
+     * @param metaDataContexts metadata contexts.
+     * @param instanceId instance id.
+     */
+    public static void generateNarayanaConfig(final MetaDataContexts metaDataContexts, final String instanceId) {
+        TransactionRule transactionRule = metaDataContexts.getGlobalRuleMetaData().getRules().stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst()
+                .get();
+        if (null == transactionRule) {
+            return;
+        }
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig(instanceId);
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml(result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }
+
+    private static void swapJdbcStore(final TransactionRule transactionRule, final Map<Object, Object> config) {
+        Object host = transactionRule.getProps().get("host");
+        Object port = transactionRule.getProps().get("port");
+        Object user = transactionRule.getProps().getProperty("user");
+        Object password = transactionRule.getProps().getProperty("password");
+        Object databaseName = transactionRule.getProps().getProperty("databaseName");
+        if (null != host && null != port && null != user && null != password && null != databaseName) {
+            String jdbcAccessPatten = "com.arjuna.ats.internal.arjuna.objectstore.jdbc.accessors.DynamicDataSourceJDBCAccess;"
+                    + "ClassName=com.mysql.cj.jdbc.MysqlDataSource;URL=jdbc:mysql://%s:%d/%s;User=%s;Password=%s";
+            String jdbcAccess = String.format(jdbcAccessPatten, host, port, databaseName, user, password);
+            config.put("ObjectStoreEnvironmentBean.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.tablePrefix", "Action");
+            config.put("ObjectStoreEnvironmentBean.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.stateStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.stateStore.tablePrefix", "stateStore");
+            config.put("ObjectStoreEnvironmentBean.stateStore.dropTable", true);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.objectStoreType", "com.arjuna.ats.internal.arjuna.objectstore.jdbc.JDBCStore");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.jdbcAccess", jdbcAccess);
+            config.put("ObjectStoreEnvironmentBean.communicationStore.tablePrefix", "Communication");
+            config.put("ObjectStoreEnvironmentBean.communicationStore.dropTable", true);
+        }
+    }
+
+    private static Map<Object, Object> generateDefaultNarayanaConfig(final String instanceId) {
+        Map<Object, Object> result = new LinkedHashMap<>();
+        result.put("CoordinatorEnvironmentBean.commitOnePhase", "YES");
+        result.put("ObjectStoreEnvironmentBean.transactionSync", "ON");
+        result.put("CoreEnvironmentBean.nodeIdentifier", null == instanceId ? 1 : instanceId);
+        result.put("JTAEnvironmentBean.xaRecoveryNodes", null == instanceId ? 1 : instanceId);
+        List<String> xaResourceOrphanFilterClassNames = new LinkedList<>();
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter");
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter");
+        xaResourceOrphanFilterClassNames.add("com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter");
+        result.put("JTAEnvironmentBean.xaResourceOrphanFilterClassNames", xaResourceOrphanFilterClassNames);
+        result.put("CoreEnvironmentBean.socketProcessIdPort", 0);
+        List<String> recoveryModuleClassNames = new LinkedList<>();

Review comment:
       `Collection<String>` is better than `List<String>`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] jingshanglu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
jingshanglu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r800033683



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +75,102 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml((LinkedHashMap<Object, Object>) result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        System.out.println(path);
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }

Review comment:
       ok
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r795010537



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +75,102 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml((LinkedHashMap<Object, Object>) result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        System.out.println(path);
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }

Review comment:
       What I mean is `narayana` should not occur in TransactionContextsBuilder class, which is common one, should not handle concrete transaction type impl




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r801219322



##########
File path: shardingsphere-mode/shardingsphere-mode-core/src/main/java/org/apache/shardingsphere/mode/utils/NarayanaConfigUtil.java
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shardingsphere.mode.utils;
+
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.shardingsphere.mode.metadata.MetaDataContexts;
+import org.apache.shardingsphere.transaction.core.TransactionType;
+import org.apache.shardingsphere.transaction.rule.TransactionRule;
+
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Narayana config utils.
+ */
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public final class NarayanaConfigUtil {

Review comment:
       please change NarayanaConfigUtil to SPI impl




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] codecov-commenter edited a comment on pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
codecov-commenter edited a comment on pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#issuecomment-1024612807


   # [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) Report
   > Merging [#15115](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (882263e) into [master](https://codecov.io/gh/apache/shardingsphere/commit/d8621d6bcd04a73b99cf115aca1f3f84216d18f4?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) (d8621d6) will **decrease** coverage by `0.04%`.
   > The diff coverage is `9.90%`.
   
   [![Impacted file tree graph](https://codecov.io/gh/apache/shardingsphere/pull/15115/graphs/tree.svg?width=650&height=150&src=pr&token=ZvlXpWa7so&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   
   ```diff
   @@             Coverage Diff              @@
   ##             master   #15115      +/-   ##
   ============================================
   - Coverage     60.19%   60.15%   -0.05%     
   + Complexity     1941     1938       -3     
   ============================================
     Files          3189     3195       +6     
     Lines         47645    47916     +271     
     Branches       8099     8140      +41     
   ============================================
   + Hits          28682    28825     +143     
   - Misses        16645    16763     +118     
   - Partials       2318     2328      +10     
   ```
   
   
   | [Impacted Files](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | Coverage Δ | |
   |---|---|---|
   | [...here/transaction/spi/TransactionConfigFactory.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUta2VybmVsL3NoYXJkaW5nc3BoZXJlLXRyYW5zYWN0aW9uL3NoYXJkaW5nc3BoZXJlLXRyYW5zYWN0aW9uLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3RyYW5zYWN0aW9uL3NwaS9UcmFuc2FjdGlvbkNvbmZpZ0ZhY3RvcnkuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...saction/xa/narayana/util/NarayanaConfigFacade.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUta2VybmVsL3NoYXJkaW5nc3BoZXJlLXRyYW5zYWN0aW9uL3NoYXJkaW5nc3BoZXJlLXRyYW5zYWN0aW9uLXR5cGUvc2hhcmRpbmdzcGhlcmUtdHJhbnNhY3Rpb24teGEvc2hhcmRpbmdzcGhlcmUtdHJhbnNhY3Rpb24teGEtcHJvdmlkZXIvc2hhcmRpbmdzcGhlcmUtdHJhbnNhY3Rpb24teGEtbmFyYXlhbmEvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3RyYW5zYWN0aW9uL3hhL25hcmF5YW5hL3V0aWwvTmFyYXlhbmFDb25maWdGYWNhZGUuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...de/manager/memory/MemoryContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtbWVtb3J5LW1vZGUvc2hhcmRpbmdzcGhlcmUtbWVtb3J5LW1vZGUtY29yZS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvbW9kZS9tYW5hZ2VyL21lbW9yeS9NZW1vcnlDb250ZXh0TWFuYWdlckJ1aWxkZXIuamF2YQ==) | `0.00% <0.00%> (ø)` | |
   | [...er/standalone/StandaloneContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtc3RhbmRhbG9uZS1tb2RlL3NoYXJkaW5nc3BoZXJlLXN0YW5kYWxvbmUtbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvc3RhbmRhbG9uZS9TdGFuZGFsb25lQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `83.78% <62.50%> (-6.22%)` | :arrow_down: |
   | [.../manager/cluster/ClusterContextManagerBuilder.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtbW9kZS9zaGFyZGluZ3NwaGVyZS1tb2RlLXR5cGUvc2hhcmRpbmdzcGhlcmUtY2x1c3Rlci1tb2RlL3NoYXJkaW5nc3BoZXJlLWNsdXN0ZXItbW9kZS1jb3JlL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9tb2RlL21hbmFnZXIvY2x1c3Rlci9DbHVzdGVyQ29udGV4dE1hbmFnZXJCdWlsZGVyLmphdmE=) | `68.75% <66.66%> (-1.99%)` | :arrow_down: |
   | [...d/text/distsql/ral/common/hint/HintSourceType.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtcHJveHkvc2hhcmRpbmdzcGhlcmUtcHJveHktYmFja2VuZC9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvc2hhcmRpbmdzcGhlcmUvcHJveHkvYmFja2VuZC90ZXh0L2Rpc3RzcWwvcmFsL2NvbW1vbi9oaW50L0hpbnRTb3VyY2VUeXBlLmphdmE=) | `0.00% <0.00%> (-42.86%)` | :arrow_down: |
   | [...ource/props/custom/CustomDataSourceProperties.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9kYXRhc291cmNlL3Byb3BzL2N1c3RvbS9DdXN0b21EYXRhU291cmNlUHJvcGVydGllcy5qYXZh) | `85.00% <0.00%> (-15.00%)` | :arrow_down: |
   | [...datasource/pool/creator/DataSourcePoolCreator.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS9kYXRhc291cmNlL3Bvb2wvY3JlYXRvci9EYXRhU291cmNlUG9vbENyZWF0b3IuamF2YQ==) | `75.00% <0.00%> (-11.37%)` | :arrow_down: |
   | [...ine/representer/ShardingSphereYamlRepresenter.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtaW5mcmEvc2hhcmRpbmdzcGhlcmUtaW5mcmEtY29tbW9uL3NyYy9tYWluL2phdmEvb3JnL2FwYWNoZS9zaGFyZGluZ3NwaGVyZS9pbmZyYS95YW1sL2VuZ2luZS9yZXByZXNlbnRlci9TaGFyZGluZ1NwaGVyZVlhbWxSZXByZXNlbnRlci5qYXZh) | `90.00% <0.00%> (-10.00%)` | :arrow_down: |
   | [...re/spring/boot/datasource/DataSourceMapSetter.java](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation#diff-c2hhcmRpbmdzcGhlcmUtamRiYy9zaGFyZGluZ3NwaGVyZS1qZGJjLXNwcmluZy9zaGFyZGluZ3NwaGVyZS1qZGJjLXNwcmluZy1pbmZyYS9zaGFyZGluZ3NwaGVyZS1qZGJjLXNwcmluZy1ib290LXN0YXJ0ZXItaW5mcmEvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL3NoYXJkaW5nc3BoZXJlL3NwcmluZy9ib290L2RhdGFzb3VyY2UvRGF0YVNvdXJjZU1hcFNldHRlci5qYXZh) | `48.14% <0.00%> (-5.19%)` | :arrow_down: |
   | ... and [51 more](https://codecov.io/gh/apache/shardingsphere/pull/15115/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation) | |
   
   ------
   
   [Continue to review full report at Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation)
   > `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
   > Powered by [Codecov](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Last update [d8621d6...882263e](https://codecov.io/gh/apache/shardingsphere/pull/15115?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=The+Apache+Software+Foundation).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on a change in pull request #15115: Make It is easy to use with narayana

Posted by GitBox <gi...@apache.org>.
terrymanu commented on a change in pull request #15115:
URL: https://github.com/apache/shardingsphere/pull/15115#discussion_r794307018



##########
File path: shardingsphere-kernel/shardingsphere-transaction/shardingsphere-transaction-core/src/main/java/org/apache/shardingsphere/transaction/context/TransactionContextsBuilder.java
##########
@@ -61,4 +75,102 @@ private TransactionRule getTransactionRule() {
         Optional<TransactionRule> transactionRule = globalRules.stream().filter(each -> each instanceof TransactionRule).map(each -> (TransactionRule) each).findFirst();
         return transactionRule.orElseGet(() -> new TransactionRule(new DefaultTransactionRuleConfigurationBuilder().build()));
     }
+    
+    private void generateNarayanaConfig(final TransactionRule transactionRule) {
+        Map<Object, Object> result;
+        if (transactionRule.getDefaultType() == TransactionType.XA && transactionRule.getProviderType().equalsIgnoreCase("Narayana")) {
+            result = generateDefaultNarayanaConfig();
+            if (null != transactionRule.getProps()) {
+                swapJdbcStore(transactionRule, result);
+            }
+        } else {
+            return;
+        }
+        String value = narayanaConfigMapToXml((LinkedHashMap<Object, Object>) result);
+        String path = ClassLoader.getSystemResource("").getPath();
+        System.out.println(path);
+        try (BufferedWriter bufferedWriter = Files.newBufferedWriter(Paths.get(path, "jbossts-properties.xml"))) {
+            bufferedWriter.write(value);
+            bufferedWriter.flush();
+        } catch (final IOException ex) {
+            log.error("generate narayana config file failed.");
+        }
+    }

Review comment:
       This is for common transaction process, could you try to consider about abstract a SPI and move NarayanaConfig into the SPI implementation?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org