Skip to content

Commit

Permalink
Add min transaction count
Browse files Browse the repository at this point in the history
  • Loading branch information
IsuruMaduranga committed Aug 30, 2023
1 parent 8895c86 commit fc4f2af
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.wso2.carbon.apimgt.gateway.handlers.transaction.config.TransactionCounterConfig;

import java.lang.reflect.Constructor;
import java.util.concurrent.*;
import java.util.concurrent.RejectedExecutionException;

public class TransactionCountHandler extends AbstractExtendedSynapseHandler {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class TransactionCounterConstants {
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";
Expand All @@ -28,6 +29,8 @@ public class TransactionCounterConstants {
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ private APIMConfigFetcher() throws TransactionCounterInitializationException {
temp = Objects.requireNonNull(temp, "Max transaction count cannot be null");
Double MAX_TRANSACTION_COUNT = Double.parseDouble(temp);

Check warning on line 58 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/APIMConfigFetcher.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/config/APIMConfigFetcher.java#L57-L58

Added lines #L57 - L58 were not covered by tests

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,

Check warning on line 60 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/APIMConfigFetcher.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/config/APIMConfigFetcher.java#L60

Added line #L60 was not covered by tests
TransactionCounterConstants.GATEWAY_MIN_TRANSACTION_COUNT);
temp = Objects.requireNonNull(temp, "Min transaction count cannot be null");
Double MIN_TRANSACTION_COUNT = Double.parseDouble(temp);

Check warning on line 63 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/APIMConfigFetcher.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/config/APIMConfigFetcher.java#L62-L63

Added lines #L62 - L63 were not covered by tests

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,

Check warning on line 65 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/APIMConfigFetcher.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/config/APIMConfigFetcher.java#L65

Added line #L65 was not covered by tests
TransactionCounterConstants.GATEWAY_CONSUMER_COMMIT_INTERVAL);
temp = Objects.requireNonNull(temp, "Consumer commit interval cannot be null");
Expand Down Expand Up @@ -93,6 +98,7 @@ private APIMConfigFetcher() throws TransactionCounterInitializationException {
configMap.put(TransactionCounterConstants.PRODUCER_THREAD_POOL_SIZE, PRODUCER_THREAD_POOL_SIZE);
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_RECORD_INTERVAL , TRANSACTION_COUNT_RECORD_INTERVAL);
configMap.put(TransactionCounterConstants.MAX_TRANSACTION_COUNT, MAX_TRANSACTION_COUNT);
configMap.put(TransactionCounterConstants.MIN_TRANSACTION_COUNT, MIN_TRANSACTION_COUNT);
configMap.put(TransactionCounterConstants.CONSUMER_COMMIT_INTERVAL, CONSUMER_COMMIT_INTERVAL);
configMap.put(TransactionCounterConstants.MAX_TRANSACTION_RECORDS_PER_COMMIT, MAX_TRANSACTION_RECORDS_PER_COMMIT);
configMap.put(TransactionCounterConstants.MAX_RETRY_COUNT, MAX_RETRY_COUNT);
Expand All @@ -104,10 +110,8 @@ private APIMConfigFetcher() throws TransactionCounterInitializationException {
// This error won't be thrown here because it is already checked in TransactionCountConfig
} catch (IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
throw new TransactionCounterInitializationException();
} catch (NumberFormatException e) {
} catch (NumberFormatException | NullPointerException e) {
throw new TransactionCounterInitializationException("Error while reading the config values", e);
} catch (NullPointerException e) {
throw new TransactionCounterInitializationException("All configuration values needs to be provided", e);
}
}

Check warning on line 116 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/APIMConfigFetcher.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/config/APIMConfigFetcher.java#L111-L116

Added lines #L111 - L116 were not covered by tests

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public static double getMaxTransactionCount() {
configFetcher.getConfigValue(TransactionCounterConstants.MAX_TRANSACTION_COUNT));

Check warning on line 41 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/TransactionCounterConfig.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/config/TransactionCounterConfig.java#L40-L41

Added lines #L40 - L41 were not covered by tests
}

public static double getMinTransactionCount() {
return Double.parseDouble(
configFetcher.getConfigValue(TransactionCounterConstants.MIN_TRANSACTION_COUNT));

Check warning on line 46 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/TransactionCounterConfig.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/config/TransactionCounterConfig.java#L45-L46

Added lines #L45 - L46 were not covered by tests
}

public static int getTransactionCountRecordInterval() {
return Integer.parseInt(
configFetcher.getConfigValue(TransactionCounterConstants.TRANSACTION_COUNT_RECORD_INTERVAL));

Check warning on line 51 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/TransactionCounterConfig.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/config/TransactionCounterConfig.java#L50-L51

Added lines #L50 - L51 were not covered by tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class TransactionRecordProducer {

private static double MAX_TRANSACTION_COUNT;
private static double MIN_TRANSACTION_COUNT;
private static int TRANSACTION_COUNT_RECORD_INTERVAL;
private static final Log LOG = LogFactory.getLog(TransactionRecordProducer.class);
private static TransactionRecordProducer instance = null;

Check warning on line 22 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/producer/TransactionRecordProducer.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/producer/TransactionRecordProducer.java#L21-L22

Added lines #L21 - L22 were not covered by tests
Expand All @@ -28,6 +29,7 @@ private TransactionRecordProducer(TransactionRecordQueue transactionRecordQueue,

// Obtain config values
MAX_TRANSACTION_COUNT = TransactionCounterConfig.getMaxTransactionCount();
MIN_TRANSACTION_COUNT = TransactionCounterConfig.getMinTransactionCount();
TRANSACTION_COUNT_RECORD_INTERVAL = TransactionCounterConfig.getTransactionCountRecordInterval();

Check warning on line 33 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/producer/TransactionRecordProducer.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/producer/TransactionRecordProducer.java#L31-L33

Added lines #L31 - L33 were not covered by tests

this.transactionRecordQueue = transactionRecordQueue;
Expand Down Expand Up @@ -76,7 +78,7 @@ private void produceRecordScheduled() {
lock.lock();

Check warning on line 78 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/producer/TransactionRecordProducer.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/producer/TransactionRecordProducer.java#L78

Added line #L78 was not covered by tests
try {
int transactionCountValue = transactionCount.get();

Check warning on line 80 in components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/producer/TransactionRecordProducer.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/producer/TransactionRecordProducer.java#L80

Added line #L80 was not covered by tests
if (transactionCountValue != 0) {
if (transactionCountValue >= MIN_TRANSACTION_COUNT) {
TransactionRecord transactionRecord = new TransactionRecord(transactionCountValue);
LOG.info("Transaction count is added to the queue from scheduled producer");
transactionRecordQueue.add(transactionRecord);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,6 @@ protected void activate(ComponentContext componentContext) throws Exception {
bundleContext.registerService(Notifier.class.getName(),new ExternallyDeployedApiNotifier(),null);
bundleContext.registerService(Notifier.class.getName(),new KeyTemplateNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new CorrelationConfigNotifier(), null);
// temp
APIManagerConfigurationServiceImpl configurationService = new APIManagerConfigurationServiceImpl(configuration);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(configurationService);
APIMgtDBUtil.initialize();
Expand Down

0 comments on commit fc4f2af

Please sign in to comment.