Search in sources :

Example 11 with SubscriptionDataLoaderImpl

use of org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method initializeLoadingTasks.

public void initializeLoadingTasks() {
    Runnable apiTask = new PopulateTask<>(apiMap, () -> {
        try {
            log.debug("Calling loadAllApis. ");
            List<API> apiList = new SubscriptionDataLoaderImpl().loadAllApis(tenantDomain);
            apiByUUIDMap.clear();
            for (API api : apiList) {
                apiByUUIDMap.put(api.getUuid(), api);
                String key = api.getApiName().concat(":").concat(api.getApiVersion());
                apiNameVersionMap.put(key, api);
            }
            apisInitialized = true;
            return apiList;
        } catch (APIManagementException e) {
            log.error("Exception while loading APIs " + e);
        }
        return null;
    });
    executorService.schedule(apiTask, 0, TimeUnit.SECONDS);
    Runnable subscriptionLoadingTask = new PopulateTask<>(subscriptionMap, () -> {
        try {
            log.debug("Calling loadAllSubscriptions.");
            return new SubscriptionDataLoaderImpl().loadAllSubscriptions(tenantDomain);
        } catch (APIManagementException e) {
            log.error("Exception while loading Subscriptions " + e);
        }
        return null;
    });
    executorService.schedule(subscriptionLoadingTask, 0, TimeUnit.SECONDS);
    Runnable applicationLoadingTask = new PopulateTask<>(applicationMap, () -> {
        try {
            log.debug("Calling loadAllApplications.");
            return new SubscriptionDataLoaderImpl().loadAllApplications(tenantDomain);
        } catch (APIManagementException e) {
            log.error("Exception while loading Applications " + e);
        }
        return null;
    });
    executorService.schedule(applicationLoadingTask, 0, TimeUnit.SECONDS);
    Runnable keyMappingsTask = new PopulateTask<>(applicationKeyMappingMap, () -> {
        try {
            log.debug("Calling loadAllKeyMappings.");
            return new SubscriptionDataLoaderImpl().loadAllKeyMappings(tenantDomain);
        } catch (APIManagementException e) {
            log.error("Exception while loading ApplicationKeyMapping " + e);
        }
        return null;
    });
    executorService.schedule(keyMappingsTask, 0, TimeUnit.SECONDS);
    Runnable apiPolicyLoadingTask = new PopulateTask<>(apiPolicyMap, () -> {
        try {
            log.debug("Calling loadAllSubscriptionPolicies.");
            List<ApiPolicy> apiPolicyList = new SubscriptionDataLoaderImpl().loadAllAPIPolicies(tenantDomain);
            apiPoliciesInitialized = true;
            return apiPolicyList;
        } catch (APIManagementException e) {
            log.error("Exception while loading api Policies " + e);
        }
        return null;
    });
    executorService.schedule(apiPolicyLoadingTask, 0, TimeUnit.SECONDS);
    Runnable subPolicyLoadingTask = new PopulateTask<>(subscriptionPolicyMap, () -> {
        try {
            log.debug("Calling loadAllSubscriptionPolicies.");
            return new SubscriptionDataLoaderImpl().loadAllSubscriptionPolicies(tenantDomain);
        } catch (APIManagementException e) {
            log.error("Exception while loading Subscription Policies " + e);
        }
        return null;
    });
    executorService.schedule(subPolicyLoadingTask, 0, TimeUnit.SECONDS);
    Runnable appPolicyLoadingTask = new PopulateTask<>(appPolicyMap, () -> {
        try {
            log.debug("Calling loadAllAppPolicies.");
            return new SubscriptionDataLoaderImpl().loadAllAppPolicies(tenantDomain);
        } catch (APIManagementException e) {
            log.error("Exception while loading Application Policies " + e);
        }
        return null;
    });
    executorService.schedule(appPolicyLoadingTask, 0, TimeUnit.SECONDS);
    Runnable scopesLoadingTask = new PopulateTask<>(scopesMap, () -> {
        try {
            log.debug("Calling loadAllScopes.");
            List<Scope> scopeList = new SubscriptionDataLoaderImpl().loadAllScopes(tenantDomain);
            scopesInitialized = true;
            return scopeList;
        } catch (APIManagementException e) {
            log.error("Exception while loading Scopes " + e);
        }
        return null;
    });
    executorService.schedule(scopesLoadingTask, 0, TimeUnit.SECONDS);
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Scope(org.wso2.carbon.apimgt.keymgt.model.entity.Scope) ApiPolicy(org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy) API(org.wso2.carbon.apimgt.keymgt.model.entity.API)

Example 12 with SubscriptionDataLoaderImpl

use of org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl in project carbon-apimgt by wso2.

the class SubscriptionDataStoreImpl method addOrUpdateApiPolicy.

@Override
public void addOrUpdateApiPolicy(ApiPolicy apiPolicy) {
    try {
        ApiPolicy policy = new SubscriptionDataLoaderImpl().getAPIPolicy(apiPolicy.getName(), tenantDomain);
        apiPolicyMap.remove(apiPolicy.getCacheKey());
        apiPolicyMap.put(apiPolicy.getCacheKey(), policy);
    } catch (DataLoadingException e) {
        log.error("Exception while loading api policy for " + apiPolicy.getName() + " for domain " + tenantDomain, e);
    }
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) ApiPolicy(org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy)

Aggregations

DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)10 ApiPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy)5 SubscriptionDataLoaderImpl (org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl)5 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)4 ArrayList (java.util.ArrayList)3 SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 API (org.wso2.carbon.apimgt.common.analytics.publishers.dto.API)2 ApplicationPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicy)2 SubscriptionPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy)2 ConditionDTO (org.wso2.carbon.apimgt.api.dto.ConditionDTO)1 ConditionGroupDTO (org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO)1 URITemplate (org.wso2.carbon.apimgt.api.model.URITemplate)1 URLMapping (org.wso2.carbon.apimgt.api.model.subscription.URLMapping)1 DataNotFoundException (org.wso2.carbon.apimgt.common.analytics.exceptions.DataNotFoundException)1 APIPolicyConditionGroup (org.wso2.carbon.apimgt.keymgt.model.entity.APIPolicyConditionGroup)1 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)1 ApplicationKeyMapping (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMapping)1 ApplicationKeyMappingCacheKey (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingCacheKey)1 Condition (org.wso2.carbon.apimgt.keymgt.model.entity.Condition)1