-
Notifications
You must be signed in to change notification settings - Fork 627
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp configuration handling mechanism
- Loading branch information
1 parent
f94011f
commit 8895c86
Showing
14 changed files
with
335 additions
and
150 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
47 changes: 47 additions & 0 deletions
47
...java/org/wso2/carbon/apimgt/gateway/handlers/transaction/TransactionCounterConstants.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,47 @@ | ||
package org.wso2.carbon.apimgt.gateway.handlers.transaction; | ||
|
||
public class TransactionCounterConstants { | ||
|
||
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 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_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"; | ||
} |
126 changes: 126 additions & 0 deletions
126
...in/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/APIMConfigFetcher.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,126 @@ | ||
package org.wso2.carbon.apimgt.gateway.handlers.transaction.config; | ||
|
||
import org.wso2.carbon.apimgt.gateway.handlers.transaction.TransactionCounterConstants; | ||
import org.wso2.carbon.apimgt.gateway.handlers.transaction.exception.TransactionCounterInitializationException; | ||
|
||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
import java.util.HashMap; | ||
import java.util.Objects; | ||
|
||
public class APIMConfigFetcher implements ConfigFetcher { | ||
|
||
private static APIMConfigFetcher instance = null; | ||
private static HashMap<String, Object> configMap = new HashMap<>(); | ||
|
||
private APIMConfigFetcher() throws TransactionCounterInitializationException { | ||
try { | ||
Class<?> configClass = Class.forName(TransactionCounterConstants.APIM_CONFIG_CLASS); | ||
|
||
Object serviceReferenceHolder = configClass.getMethod("getInstance").invoke(null); | ||
Object apiManagerConfigurationService = configClass.getMethod("getAPIManagerConfigurationService") | ||
.invoke(serviceReferenceHolder); | ||
Object apiManagerConfiguration = apiManagerConfigurationService.getClass() | ||
.getMethod("getAPIManagerConfiguration").invoke(apiManagerConfigurationService); | ||
Method getFirstProperty = apiManagerConfiguration.getClass().getMethod("getFirstProperty", | ||
String.class); | ||
|
||
// Reading the config values | ||
String temp; | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_SERVER_ID); | ||
String SERVER_ID = Objects.requireNonNull( temp, "Server ID cannot be null"); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_STORE_CLASS); | ||
String TRANSACTION_COUNT_STORE_CLASS = Objects.requireNonNull( | ||
temp, "Transaction count store class cannot be null"); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_QUEUE_SIZE); | ||
temp = Objects.requireNonNull(temp, "Transaction record queue size cannot be null"); | ||
Integer TRANSACTION_RECORD_QUEUE_SIZE = Integer.parseInt(temp); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_PRODUCER_THREAD_POOL_SIZE); | ||
temp = Objects.requireNonNull(temp, "Producer thread pool size cannot be null"); | ||
Integer PRODUCER_THREAD_POOL_SIZE = Integer.parseInt(temp); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_RECORD_INTERVAL); | ||
temp = Objects.requireNonNull(temp, "Transaction count record interval cannot be null"); | ||
Integer TRANSACTION_COUNT_RECORD_INTERVAL = Integer.parseInt(temp); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_MAX_TRANSACTION_COUNT); | ||
temp = Objects.requireNonNull(temp, "Max transaction count cannot be null"); | ||
Double MAX_TRANSACTION_COUNT = Double.parseDouble(temp); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_CONSUMER_COMMIT_INTERVAL); | ||
temp = Objects.requireNonNull(temp, "Consumer commit interval cannot be null"); | ||
Integer CONSUMER_COMMIT_INTERVAL = Integer.parseInt(temp); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_MAX_TRANSACTION_RECORDS_PER_COMMIT); | ||
temp = Objects.requireNonNull(temp, "Max transaction records per commit cannot be null"); | ||
Integer MAX_TRANSACTION_RECORDS_PER_COMMIT = Integer.parseInt(temp); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_MAX_RETRY_COUNT); | ||
temp = Objects.requireNonNull(temp, "Max retry count cannot be null"); | ||
Integer MAX_RETRY_COUNT = Integer.parseInt(temp); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_SERVICE); | ||
String TRANSACTION_COUNT_SERVICE = Objects.requireNonNull(temp, | ||
"Transaction count service cannot be null"); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_SERVICE_USERNAME); | ||
String TRANSACTION_COUNT_SERVICE_USERNAME = Objects.requireNonNull(temp, | ||
"Transaction count service username cannot be null"); | ||
|
||
temp = (String) getFirstProperty.invoke(apiManagerConfiguration, | ||
TransactionCounterConstants.GATEWAY_SERVICE_PASSWORD); | ||
String TRANSACTION_COUNT_SERVICE_PASSWORD = Objects.requireNonNull(temp, | ||
"Transaction count service password cannot be null"); | ||
|
||
configMap.put(TransactionCounterConstants.SERVER_ID, SERVER_ID); | ||
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_STORE_CLASS, TRANSACTION_COUNT_STORE_CLASS); | ||
configMap.put(TransactionCounterConstants.TRANSACTION_RECORD_QUEUE_SIZE, TRANSACTION_RECORD_QUEUE_SIZE); | ||
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.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); | ||
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_SERVICE, TRANSACTION_COUNT_SERVICE); | ||
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_SERVICE_USERNAME, TRANSACTION_COUNT_SERVICE_USERNAME); | ||
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_SERVICE_PASSWORD, TRANSACTION_COUNT_SERVICE_PASSWORD); | ||
|
||
} catch (ClassNotFoundException e) { | ||
// 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) { | ||
throw new TransactionCounterInitializationException("Error while reading the config values", e); | ||
} catch (NullPointerException e) { | ||
throw new TransactionCounterInitializationException("All configuration values needs to be provided", e); | ||
} | ||
} | ||
|
||
public static ConfigFetcher getInstance() throws TransactionCounterInitializationException { | ||
if (instance == null) { | ||
instance = new APIMConfigFetcher(); | ||
} | ||
return instance; | ||
} | ||
|
||
@Override | ||
public String getConfigValue(String key) { | ||
return configMap.get(key).toString(); | ||
} | ||
|
||
} |
6 changes: 6 additions & 0 deletions
6
...c/main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/ConfigFetcher.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,6 @@ | ||
package org.wso2.carbon.apimgt.gateway.handlers.transaction.config; | ||
|
||
public interface ConfigFetcher { | ||
String getConfigValue(String key); | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...main/java/org/wso2/carbon/apimgt/gateway/handlers/transaction/config/MIConfigFetcher.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,27 @@ | ||
package org.wso2.carbon.apimgt.gateway.handlers.transaction.config; | ||
|
||
import org.wso2.carbon.apimgt.gateway.handlers.transaction.exception.TransactionCounterInitializationException; | ||
|
||
import java.util.HashMap; | ||
|
||
public class MIConfigFetcher implements ConfigFetcher { | ||
|
||
private static MIConfigFetcher instance = null; | ||
private static HashMap<String, Object> configMap = new HashMap<>(); | ||
|
||
private MIConfigFetcher() throws TransactionCounterInitializationException { | ||
// To be implemented | ||
} | ||
|
||
public static MIConfigFetcher getInstance() throws TransactionCounterInitializationException{ | ||
if(instance == null) { | ||
instance = new MIConfigFetcher(); | ||
} | ||
return instance; | ||
} | ||
|
||
@Override | ||
public String getConfigValue(String key) { | ||
return null; | ||
} | ||
} |
Oops, something went wrong.