Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Feature] Transaction counting for synapse gateway #12085

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bd36dcf
Add initial working implementation for transaction counting
IsuruMaduranga Jul 17, 2023
25a276f
Fix concurrency logic in transaction counting
IsuruMaduranga Jul 17, 2023
5ec30cc
Redefine TransactionCountStore interface
IsuruMaduranga Jul 17, 2023
311a455
Add retry mechanism for committing transaction count
IsuruMaduranga Jul 17, 2023
360a09d
Add scheduled transaction count committing
IsuruMaduranga Jul 17, 2023
9f1ac35
Code refactor
IsuruMaduranga Jul 17, 2023
bd6ecb4
Extend TransactionCountHandler from AbstractExtendedSynapseHandler
IsuruMaduranga Jul 17, 2023
801b881
Bug fix in TransactionCountHandler
IsuruMaduranga Jul 17, 2023
56140ea
Code refactoring in TransactionCountHandler
IsuruMaduranga Jul 19, 2023
1d16d38
Refactor transactional counting to a producer consumer pattern
IsuruMaduranga Jul 26, 2023
f0a7893
Make transaction counter configurable
IsuruMaduranga Jul 28, 2023
a502e1f
Add serverID and host to Transaction record
IsuruMaduranga Jul 28, 2023
5aa79c9
Implement TransactionRecordStoreImpl with retries
IsuruMaduranga Jul 29, 2023
9425fd1
Refactor transaction record committing
IsuruMaduranga Aug 8, 2023
986a6b4
Update transaction record timestamp
IsuruMaduranga Aug 8, 2023
ff77f4b
Add basic auth to TransactionRecordStore
IsuruMaduranga Aug 9, 2023
b4fbd7e
Make transaction record consumer single threaded
IsuruMaduranga Aug 11, 2023
2992f39
Make params configurable
IsuruMaduranga Aug 25, 2023
f94011f
Refactor code
IsuruMaduranga Aug 25, 2023
8895c86
Revamp configuration handling mechanism
IsuruMaduranga Aug 30, 2023
fc4f2af
Add min transaction count
IsuruMaduranga Aug 30, 2023
33770d1
Major code refactoring
IsuruMaduranga Aug 31, 2023
27447aa
Major code refactoring
IsuruMaduranga Aug 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package org.wso2.carbon.apimgt.gateway.handlers.transaction;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.AbstractExtendedSynapseHandler;
import org.apache.synapse.MessageContext;
import org.wso2.carbon.apimgt.gateway.handlers.transaction.consumer.TransactionRecordConsumer;
import org.wso2.carbon.apimgt.gateway.handlers.transaction.exception.TransactionCounterConfigurationException;
import org.wso2.carbon.apimgt.gateway.handlers.transaction.producer.TransactionRecordProducer;
import org.wso2.carbon.apimgt.gateway.handlers.transaction.queue.TransactionRecordQueue;
import org.wso2.carbon.apimgt.gateway.handlers.transaction.record.TransactionRecord;
import org.wso2.carbon.apimgt.gateway.handlers.transaction.store.TransactionRecordStore;
import org.wso2.carbon.apimgt.gateway.handlers.transaction.config.TransactionCounterConfig;

import java.lang.reflect.Constructor;

/**
* This class is the starting point of the transaction counter. This class is responsible for initializing all the
* components of the transaction counter and starting them. This class extends the Synapse handler interface and is
* responsible for intercepting the Synapse message flow and passing the message context to the transaction counting
* logic. This is registered in handlers.xml in case of APIM and service bus initializer in case of MI/ESB.
* @author - Isuru Wijesiri
* @version - 1.0.0
*/
public class TransactionCountHandler extends AbstractExtendedSynapseHandler {
private static final Log LOG = LogFactory.getLog(TransactionCountHandler.class);

Check warning on line 26 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L26

Added line #L26 was not covered by tests
private TransactionRecordQueue transactionRecordQueue;
private TransactionRecordProducer transactionRecordProducer;
private TransactionRecordConsumer transactionRecordConsumer;
private TransactionRecordStore transactionCountStore;
private static boolean enabled = false;

Check warning on line 31 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L31

Added line #L31 was not covered by tests

public TransactionCountHandler() {

Check warning on line 33 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L33

Added line #L33 was not covered by tests

// Initialize the config mechanism
try {
TransactionCounterConfig.init();
} catch (TransactionCounterConfigurationException e) {
LOG.error("Error while initializing Transaction Counter. Transaction counter will be disabled", e);
return;
}

Check warning on line 41 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L37-L41

Added lines #L37 - L41 were not covered by tests

try {
Class<?> clazz = Class.forName(
TransactionCounterConfig.getTransactionCountStoreClass()

Check warning on line 45 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L44-L45

Added lines #L44 - L45 were not covered by tests
);
Constructor<?> constructor = clazz.getConstructor();
this.transactionCountStore = (TransactionRecordStore) constructor.newInstance();
} catch (Exception e) {
LOG.error("Error while initializing Transaction Counter. Transaction counter will be disabled", e);
return;
}

Check warning on line 52 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L47-L52

Added lines #L47 - L52 were not covered by tests

this.transactionRecordProducer = TransactionRecordProducer.getInstance();
this.transactionRecordConsumer = TransactionRecordConsumer.getInstance();
this.transactionRecordQueue = TransactionRecordQueue.getInstance();

Check warning on line 56 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L54-L56

Added lines #L54 - L56 were not covered by tests

TransactionRecord.init(
TransactionCounterConfig.getServerID(),
TransactionCounterConfig.getServerType().toString()

Check warning on line 60 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L58-L60

Added lines #L58 - L60 were not covered by tests
);

this.transactionRecordQueue.init(
TransactionCounterConfig.getTransactionRecordQueueSize()

Check warning on line 64 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L63-L64

Added lines #L63 - L64 were not covered by tests
);

this.transactionRecordProducer.init(

Check warning on line 67 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L67

Added line #L67 was not covered by tests
transactionRecordQueue,
TransactionCounterConfig.getProducerThreadPoolSize(),
TransactionCounterConfig.getMaxTransactionCount(),
TransactionCounterConfig.getMinTransactionCount(),
TransactionCounterConfig.getTransactionCountRecordInterval());

Check warning on line 72 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L69-L72

Added lines #L69 - L72 were not covered by tests

this.transactionCountStore.init(
TransactionCounterConfig.getTransactionCountService(),
TransactionCounterConfig.getTransactionCountServiceUsername(),
TransactionCounterConfig.getTransactionCountServicePassword()

Check warning on line 77 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L74-L77

Added lines #L74 - L77 were not covered by tests
);

this.transactionRecordConsumer.init(

Check warning on line 80 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L80

Added line #L80 was not covered by tests
transactionCountStore,
transactionRecordQueue,
TransactionCounterConfig.getConsumerCommitInterval(),
TransactionCounterConfig.getMaxRetryCount(),
TransactionCounterConfig.getMaxTransactionRecordsPerCommit());

Check warning on line 85 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L83-L85

Added lines #L83 - L85 were not covered by tests

enabled = true;
}

Check warning on line 88 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L87-L88

Added lines #L87 - L88 were not covered by tests

@Override
public boolean handleRequestInFlow(MessageContext messageContext) {
if(!enabled) {
return true;

Check warning on line 93 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L93

Added line #L93 was not covered by tests
}
int tCount = TransactionCountingLogic.handleRequestInFlow(messageContext);

Check warning on line 95 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L95

Added line #L95 was not covered by tests
if(tCount > 0) {
this.transactionRecordProducer.addTransaction(tCount);

Check warning on line 97 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L97

Added line #L97 was not covered by tests
}
return true;

Check warning on line 99 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L99

Added line #L99 was not covered by tests
}

@Override
public boolean handleRequestOutFlow(MessageContext messageContext) {
if(!enabled) {
return true;

Check warning on line 105 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L105

Added line #L105 was not covered by tests
}
int tCount = TransactionCountingLogic.handleRequestOutFlow(messageContext);

Check warning on line 107 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L107

Added line #L107 was not covered by tests
if(tCount > 0) {
this.transactionRecordProducer.addTransaction(tCount);

Check warning on line 109 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L109

Added line #L109 was not covered by tests
}
return true;

Check warning on line 111 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L111

Added line #L111 was not covered by tests
}

@Override
public boolean handleResponseInFlow(MessageContext messageContext) {
if(!enabled) {
return true;

Check warning on line 117 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L117

Added line #L117 was not covered by tests
}
int tCount = TransactionCountingLogic.handleResponseInFlow(messageContext);

Check warning on line 119 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L119

Added line #L119 was not covered by tests
if(tCount > 0) {
this.transactionRecordProducer.addTransaction(tCount);

Check warning on line 121 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L121

Added line #L121 was not covered by tests
}
return true;

Check warning on line 123 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L123

Added line #L123 was not covered by tests
}

@Override
public boolean handleResponseOutFlow(MessageContext messageContext) {
if(!enabled) {
return true;

Check warning on line 129 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L129

Added line #L129 was not covered by tests
}
int tCount = TransactionCountingLogic.handleResponseOutFlow(messageContext);

Check warning on line 131 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L131

Added line #L131 was not covered by tests
if(tCount > 0) {
this.transactionRecordProducer.addTransaction(tCount);

Check warning on line 133 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L133

Added line #L133 was not covered by tests
}
return true;

Check warning on line 135 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L135

Added line #L135 was not covered by tests
}

@Override
public boolean handleServerInit() {
// Nothing to implement
return true;

Check warning on line 141 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L141

Added line #L141 was not covered by tests
}

@Override
public boolean handleServerShutDown() {
// Clen up resources
transactionRecordProducer.shutdown();
transactionRecordConsumer.shutdown();
transactionRecordQueue.clenUp();
transactionCountStore.clenUp();
return true;

Check warning on line 151 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L147-L151

Added lines #L147 - L151 were not covered by tests
}

@Override
public boolean handleArtifactDeployment(String s, String s1, String s2) {
// Nothing to implement
return true;

Check warning on line 157 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L157

Added line #L157 was not covered by tests
}

@Override
public boolean handleArtifactUnDeployment(String s, String s1, String s2) {
// Nothing to implement
return true;

Check warning on line 163 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L163

Added line #L163 was not covered by tests
}

@Override
public boolean handleError(MessageContext messageContext) {
// Nothing to implement
return true;

Check warning on line 169 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountHandler.java#L169

Added line #L169 was not covered by tests
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.wso2.carbon.apimgt.gateway.handlers.transaction;

public class TransactionCounterConstants {

Check warning on line 3 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCounterConstants.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCounterConstants.java#L3

Added line #L3 was not covered by tests

public static enum ServerType {
GATEWAY, MI

Check warning on line 6 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCounterConstants.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCounterConstants.java#L5-L6

Added lines #L5 - L6 were not covered by tests
}

public static final String IS_THERE_ASSOCIATED_INCOMING_REQUEST = "is_there_incoming_request";
public static final String TRANSPORT_WS = "ws";
public static final String TRANSPORT_WSS = "wss";

public static final String SERVER_ID = "serverId";
public static final String TRANSACTION_COUNT_STORE_CLASS = "transactionCountStoreClass";
public static final String TRANSACTION_RECORD_QUEUE_SIZE = "transactionRecordQueueSize";
public static final String PRODUCER_THREAD_POOL_SIZE = "producerThreadPoolSize";
public static final String TRANSACTION_COUNT_RECORD_INTERVAL = "transactionCountRecordInterval";
public static final String MAX_TRANSACTION_COUNT = "maxTransactionCount";
public static final String MIN_TRANSACTION_COUNT = "minTransactionCount";
public static final String CONSUMER_COMMIT_INTERVAL = "consumerCommitInterval";
public static final String MAX_TRANSACTION_RECORDS_PER_COMMIT = "maxTransactionRecordsPerCommit";
public static final String MAX_RETRY_COUNT = "maxRetryCount";
public static final String TRANSACTION_COUNT_SERVICE = "transactionCountService";
public static final String TRANSACTION_COUNT_SERVICE_USERNAME = "transactionCountServiceUsername";
public static final String TRANSACTION_COUNT_SERVICE_PASSWORD = "transactionCountServicePassword";

// APIM Gateway related constants
public static final String APIM_CONFIG_CLASS = "org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder";
public static final String GATEWAY_CONFIG_ROOT = "APIGateway.TransactionCounter";
public static final String GATEWAY_PRODUCER_THREAD_POOL_SIZE = GATEWAY_CONFIG_ROOT +
".ProducerThreadPoolSize";
public static final String GATEWAY_QUEUE_SIZE = GATEWAY_CONFIG_ROOT + ".QueueSize";
public static final String GATEWAY_STORE_CLASS = GATEWAY_CONFIG_ROOT + ".StoreClass";
public static final String GATEWAY_MAX_TRANSACTION_COUNT = GATEWAY_CONFIG_ROOT +
".MaxTransactionCount";
public static final String GATEWAY_MIN_TRANSACTION_COUNT = GATEWAY_CONFIG_ROOT +
".MinTransactionCount";
public static final String GATEWAY_RECORD_INTERVAL = GATEWAY_CONFIG_ROOT
+ ".ProducerScheduledInterval";
public static final String GATEWAY_MAX_RETRY_COUNT = GATEWAY_CONFIG_ROOT + ".MaxRetryCount";
public static final String GATEWAY_MAX_TRANSACTION_RECORDS_PER_COMMIT = GATEWAY_CONFIG_ROOT
+ ".MaxBatchSize";
public static final String GATEWAY_CONSUMER_COMMIT_INTERVAL = GATEWAY_CONFIG_ROOT
+ ".PublisherScheduledInterval";
public static final String GATEWAY_SERVER_ID = GATEWAY_CONFIG_ROOT + ".ServerID";
public static final String GATEWAY_SERVICE = GATEWAY_CONFIG_ROOT + ".ServiceURL";
public static final String GATEWAY_SERVICE_USERNAME = GATEWAY_CONFIG_ROOT
+ ".ServiceUsername";
public static final String GATEWAY_SERVICE_PASSWORD = GATEWAY_CONFIG_ROOT
+ ".ServicePassword";

// MI related constants
public static final String MI_CONFIG_CLASS = "org.wso2.config.mapper.ConfigParser";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.wso2.carbon.apimgt.gateway.handlers.transaction;

import org.apache.synapse.MessageContext;
import org.apache.synapse.core.axis2.Axis2MessageContext;


/**
* This class contains the logic for counting transactions.
* In case of changing the logic, this class should be modified, replaced or extended.
* @author - Isuru Wijesiri
* @version - 1.0.0
*/
public class TransactionCountingLogic {

Check warning on line 13 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L13

Added line #L13 was not covered by tests

public static int handleRequestInFlow(MessageContext messageContext) {
org.apache.axis2.context.MessageContext axis2MessageContext =
((Axis2MessageContext) messageContext).getAxis2MessageContext();

Check warning on line 17 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L16-L17

Added lines #L16 - L17 were not covered by tests

// Setting this property to identify request-response pairs
messageContext.setProperty(TransactionCounterConstants.IS_THERE_ASSOCIATED_INCOMING_REQUEST, true);

Check warning on line 20 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L20

Added line #L20 was not covered by tests

// Counting message received via an open WebSocket
String transport = axis2MessageContext.getIncomingTransportName();

Check warning on line 23 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L23

Added line #L23 was not covered by tests
if (transport.equals(TransactionCounterConstants.TRANSPORT_WS) ||
transport.equals(TransactionCounterConstants.TRANSPORT_WSS)){
return 1;

Check warning on line 26 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L26

Added line #L26 was not covered by tests
}
return 0;

Check warning on line 28 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L28

Added line #L28 was not covered by tests
}

public static int handleRequestOutFlow(MessageContext messageContext) {
Object isThereAnAssociatedIncomingRequest = messageContext.getProperty(

Check warning on line 32 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L32

Added line #L32 was not covered by tests
TransactionCounterConstants.IS_THERE_ASSOCIATED_INCOMING_REQUEST);

// Counting outgoing messages that are not related to any request-response pair
if (isThereAnAssociatedIncomingRequest == null) {
return 1;

Check warning on line 37 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L37

Added line #L37 was not covered by tests
}
return 0;

Check warning on line 39 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L39

Added line #L39 was not covered by tests
}

public static int handleResponseInFlow(MessageContext messageContext) {
return 0;

Check warning on line 43 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L43

Added line #L43 was not covered by tests
}

public static int handleResponseOutFlow(MessageContext messageContext) {
Object isThereAnAssociatedIncomingRequest = messageContext.getProperty(

Check warning on line 47 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L47

Added line #L47 was not covered by tests
TransactionCounterConstants.IS_THERE_ASSOCIATED_INCOMING_REQUEST);

// Counting request-response pairs
if (isThereAnAssociatedIncomingRequest instanceof Boolean) {
return 1;

Check warning on line 52 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L52

Added line #L52 was not covered by tests
}
return 0;

Check warning on line 54 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java

View check run for this annotation

Codecov / codecov/patch

components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCountingLogic.java#L54

Added line #L54 was not covered by tests
}
}
Loading
Loading