forked from apache/incubator-seata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Saga implementation base on state machine (apache#1608)
- Loading branch information
Showing
217 changed files
with
18,345 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
...rotobuf/src/main/java/io/seata/codec/protobuf/convertor/GlobalReportRequestConvertor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed 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 io.seata.codec.protobuf.convertor; | ||
|
||
import io.seata.codec.protobuf.generated.AbstractGlobalEndRequestProto; | ||
import io.seata.codec.protobuf.generated.AbstractMessageProto; | ||
import io.seata.codec.protobuf.generated.AbstractTransactionRequestProto; | ||
import io.seata.codec.protobuf.generated.GlobalReportRequestProto; | ||
import io.seata.codec.protobuf.generated.GlobalStatusProto; | ||
import io.seata.codec.protobuf.generated.MessageTypeProto; | ||
import io.seata.core.model.GlobalStatus; | ||
import io.seata.core.protocol.transaction.GlobalReportRequest; | ||
|
||
/** | ||
* @author lorne.cl | ||
*/ | ||
public class GlobalReportRequestConvertor implements PbConvertor<GlobalReportRequest, GlobalReportRequestProto> { | ||
@Override | ||
public GlobalReportRequestProto convert2Proto(GlobalReportRequest globalReportRequest) { | ||
final short typeCode = globalReportRequest.getTypeCode(); | ||
|
||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( | ||
MessageTypeProto.forNumber(typeCode)).build(); | ||
|
||
final AbstractTransactionRequestProto abstractTransactionRequestProto = AbstractTransactionRequestProto | ||
.newBuilder().setAbstractMessage( | ||
abstractMessage).build(); | ||
|
||
final String extraData = globalReportRequest.getExtraData(); | ||
AbstractGlobalEndRequestProto abstractGlobalEndRequestProto = AbstractGlobalEndRequestProto.newBuilder() | ||
.setAbstractTransactionRequest(abstractTransactionRequestProto) | ||
.setXid(globalReportRequest.getXid()) | ||
.setExtraData(extraData == null ? "" : extraData) | ||
.build(); | ||
|
||
GlobalReportRequestProto result = GlobalReportRequestProto.newBuilder().setAbstractGlobalEndRequest( | ||
abstractGlobalEndRequestProto) | ||
.setGlobalStatus(GlobalStatusProto.valueOf(globalReportRequest.getGlobalStatus().name())) | ||
.build(); | ||
|
||
return result; | ||
} | ||
|
||
@Override | ||
public GlobalReportRequest convert2Model(GlobalReportRequestProto globalReportRequestProto) { | ||
GlobalReportRequest globalReportRequest = new GlobalReportRequest(); | ||
globalReportRequest.setExtraData(globalReportRequestProto.getAbstractGlobalEndRequest().getExtraData()); | ||
globalReportRequest.setXid(globalReportRequestProto.getAbstractGlobalEndRequest().getXid()); | ||
globalReportRequest.setGlobalStatus(GlobalStatus.valueOf(globalReportRequestProto.getGlobalStatus().name())); | ||
return globalReportRequest; | ||
} | ||
} |
84 changes: 84 additions & 0 deletions
84
...otobuf/src/main/java/io/seata/codec/protobuf/convertor/GlobalReportResponseConvertor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright 1999-2019 Seata.io Group. | ||
* | ||
* Licensed 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 io.seata.codec.protobuf.convertor; | ||
|
||
import io.seata.codec.protobuf.generated.AbstractGlobalEndResponseProto; | ||
import io.seata.codec.protobuf.generated.AbstractMessageProto; | ||
import io.seata.codec.protobuf.generated.AbstractResultMessageProto; | ||
import io.seata.codec.protobuf.generated.AbstractTransactionResponseProto; | ||
import io.seata.codec.protobuf.generated.GlobalReportResponseProto; | ||
import io.seata.codec.protobuf.generated.GlobalStatusProto; | ||
import io.seata.codec.protobuf.generated.MessageTypeProto; | ||
import io.seata.codec.protobuf.generated.ResultCodeProto; | ||
import io.seata.codec.protobuf.generated.TransactionExceptionCodeProto; | ||
import io.seata.core.exception.TransactionExceptionCode; | ||
import io.seata.core.model.GlobalStatus; | ||
import io.seata.core.protocol.ResultCode; | ||
import io.seata.core.protocol.transaction.GlobalReportResponse; | ||
|
||
/** | ||
* @author lorne.cl | ||
*/ | ||
public class GlobalReportResponseConvertor implements PbConvertor<GlobalReportResponse, GlobalReportResponseProto> { | ||
@Override | ||
public GlobalReportResponseProto convert2Proto(GlobalReportResponse globalStatusResponse) { | ||
final short typeCode = globalStatusResponse.getTypeCode(); | ||
|
||
final AbstractMessageProto abstractMessage = AbstractMessageProto.newBuilder().setMessageType( | ||
MessageTypeProto.forNumber(typeCode)).build(); | ||
|
||
final String msg = globalStatusResponse.getMsg(); | ||
final AbstractResultMessageProto abstractResultMessageProto = AbstractResultMessageProto.newBuilder().setMsg( | ||
msg == null ? "" : msg) | ||
.setResultCode(ResultCodeProto.valueOf(globalStatusResponse.getResultCode().name())).setAbstractMessage( | ||
abstractMessage).build(); | ||
|
||
AbstractTransactionResponseProto abstractTransactionResponseProto = AbstractTransactionResponseProto | ||
.newBuilder().setAbstractResultMessage(abstractResultMessageProto) | ||
.setTransactionExceptionCode( | ||
TransactionExceptionCodeProto.valueOf(globalStatusResponse.getTransactionExceptionCode().name())) | ||
.build(); | ||
|
||
AbstractGlobalEndResponseProto abstractGlobalEndResponseProto = AbstractGlobalEndResponseProto.newBuilder() | ||
.setAbstractTransactionResponse(abstractTransactionResponseProto) | ||
.setGlobalStatus(GlobalStatusProto.valueOf(globalStatusResponse.getGlobalStatus().name())) | ||
.build(); | ||
|
||
GlobalReportResponseProto result = GlobalReportResponseProto.newBuilder().setAbstractGlobalEndResponse( | ||
abstractGlobalEndResponseProto).build(); | ||
return result; | ||
} | ||
|
||
@Override | ||
public GlobalReportResponse convert2Model(GlobalReportResponseProto globalStatusResponseProto) { | ||
GlobalReportResponse branchRegisterResponse = new GlobalReportResponse(); | ||
final AbstractGlobalEndResponseProto abstractGlobalEndResponse = globalStatusResponseProto | ||
.getAbstractGlobalEndResponse(); | ||
AbstractTransactionResponseProto abstractResultMessage = abstractGlobalEndResponse | ||
.getAbstractTransactionResponse(); | ||
branchRegisterResponse.setMsg( | ||
abstractResultMessage.getAbstractResultMessage().getMsg()); | ||
branchRegisterResponse.setResultCode( | ||
ResultCode.valueOf(abstractResultMessage.getAbstractResultMessage().getResultCode().name())); | ||
branchRegisterResponse.setTransactionExceptionCode(TransactionExceptionCode.valueOf( | ||
abstractResultMessage.getTransactionExceptionCode().name())); | ||
branchRegisterResponse.setGlobalStatus( | ||
GlobalStatus.valueOf(abstractGlobalEndResponse.getGlobalStatus().name())); | ||
|
||
return branchRegisterResponse; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,4 +13,5 @@ enum BranchTypeProto { | |
|
||
TCC = 1; | ||
|
||
SAGA = 2; | ||
} |
15 changes: 15 additions & 0 deletions
15
...tobuf/src/main/resources/protobuf/io/seata/protocol/transcation/globalReportRequest.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
|
||
package io.seata.protocol.protobuf; | ||
|
||
import "abstractGlobalEndRequest.proto"; | ||
import "globalStatus.proto"; | ||
|
||
option java_multiple_files = true; | ||
option java_outer_classname = "GlobalReportRequest"; | ||
option java_package = "io.seata.codec.protobuf.generated"; | ||
|
||
message GlobalReportRequestProto { | ||
AbstractGlobalEndRequestProto abstractGlobalEndRequest = 1; | ||
GlobalStatusProto globalStatus = 2; | ||
} |
13 changes: 13 additions & 0 deletions
13
...obuf/src/main/resources/protobuf/io/seata/protocol/transcation/globalReportResponse.proto
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
syntax = "proto3"; | ||
|
||
package io.seata.protocol.protobuf; | ||
|
||
import "abstractGlobalEndResponse.proto"; | ||
|
||
option java_multiple_files = true; | ||
option java_outer_classname = "GlobalReportResponse"; | ||
option java_package = "io.seata.codec.protobuf.generated"; | ||
|
||
message GlobalReportResponseProto { | ||
AbstractGlobalEndResponseProto abstractGlobalEndResponse = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.