Search in sources :

Example 21 with SubscriptionDataStore

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

the class KeyManagerDataServiceImpl method removeAPIPolicy.

@Override
public void removeAPIPolicy(APIPolicyEvent event) {
    if (log.isDebugEnabled()) {
        log.debug("Remove API Policy in datastore in tenant " + event.getTenantDomain());
    }
    SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(event.getTenantDomain());
    if (store == null) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring the Event due to tenant " + event.getTenantDomain() + " not loaded");
        }
        return;
    }
    store.removeApiPolicy(getAPIPolicyFromAPIPolicyEvent(event));
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 22 with SubscriptionDataStore

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

the class KeyManagerDataServiceImpl method addOrUpdateApplicationKeyMapping.

@Override
public void addOrUpdateApplicationKeyMapping(ApplicationRegistrationEvent event) {
    if (log.isDebugEnabled()) {
        log.debug("Add or Update Application keymapping in datastore in tenant " + event.getTenantDomain());
    }
    SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(event.getTenantDomain());
    if (store == null) {
        if (log.isDebugEnabled()) {
            log.debug("Ignoring the Event due to tenant " + event.getTenantDomain() + " not loaded");
        }
        return;
    }
    store.addOrUpdateApplicationKeyMapping(getApplicationKeyMappingFromApplicationRegistrationEvent(event));
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 23 with SubscriptionDataStore

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

the class SynapseAnalyticsDataProvider method getApi.

@Override
public API getApi() throws DataNotFoundException {
    String apiContext = (String) messageContext.getProperty(RESTConstants.REST_API_CONTEXT);
    String apiVersion = (String) messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
    String tenantDomain = MultitenantUtils.getTenantDomainFromRequestURL(apiContext);
    if (tenantDomain == null) {
        tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
    }
    SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    org.wso2.carbon.apimgt.keymgt.model.entity.API apiObj = store.getApiByContextAndVersion(apiContext, apiVersion);
    API api = new API();
    if (apiObj == null) {
        try {
            apiObj = new SubscriptionDataLoaderImpl().getApi(apiContext, apiVersion);
        } catch (DataLoadingException e) {
            log.error("Error occurred when getting api.", e);
            throw new DataNotFoundException("Error occurred when getting API information", e);
        }
    }
    if (apiObj != null) {
        api.setApiId(apiObj.getUuid());
        api.setApiType(apiObj.getApiType());
        api.setApiName(apiObj.getApiName());
        api.setApiVersion(apiObj.getApiVersion());
        api.setApiCreator(apiObj.getApiProvider());
        api.setApiCreatorTenantDomain(MultitenantUtils.getTenantDomain(api.getApiCreator()));
    }
    return api;
}
Also used : SubscriptionDataLoaderImpl(org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl) DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) DataNotFoundException(org.wso2.carbon.apimgt.common.analytics.exceptions.DataNotFoundException) API(org.wso2.carbon.apimgt.common.analytics.publishers.dto.API) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 24 with SubscriptionDataStore

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

the class InMemoryAPIDeployer method reDeployAPI.

public void reDeployAPI(String apiName, String version, String tenantDomain) throws ArtifactSynchronizerException {
    SubscriptionDataStore tenantSubscriptionStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    Set<String> gatewayLabels = gatewayArtifactSynchronizerProperties.getGatewayLabels();
    if (tenantSubscriptionStore != null) {
        org.wso2.carbon.apimgt.keymgt.model.entity.API retrievedAPI = tenantSubscriptionStore.getApiByNameAndVersion(apiName, version);
        if (retrievedAPI != null) {
            DeployAPIInGatewayEvent deployAPIInGatewayEvent = new DeployAPIInGatewayEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name(), tenantDomain, retrievedAPI.getApiId(), retrievedAPI.getUuid(), gatewayLabels, apiName, version, retrievedAPI.getApiProvider(), retrievedAPI.getApiType(), retrievedAPI.getContext());
            deployAPI(deployAPIInGatewayEvent);
        }
    }
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) DeployAPIInGatewayEvent(org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)

Example 25 with SubscriptionDataStore

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

the class InMemoryAPIDeployer method unDeployAPI.

public void unDeployAPI(String apiName, String version, String tenantDomain) throws ArtifactSynchronizerException {
    SubscriptionDataStore tenantSubscriptionStore = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
    Set<String> gatewayLabels = gatewayArtifactSynchronizerProperties.getGatewayLabels();
    if (tenantSubscriptionStore != null) {
        org.wso2.carbon.apimgt.keymgt.model.entity.API retrievedAPI = tenantSubscriptionStore.getApiByNameAndVersion(apiName, version);
        if (retrievedAPI != null) {
            DeployAPIInGatewayEvent deployAPIInGatewayEvent = new DeployAPIInGatewayEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.REMOVE_API_FROM_GATEWAY.name(), tenantDomain, retrievedAPI.getApiId(), retrievedAPI.getUuid(), gatewayLabels, apiName, version, retrievedAPI.getApiProvider(), retrievedAPI.getApiType(), retrievedAPI.getContext());
            unDeployAPI(deployAPIInGatewayEvent);
        }
    }
}
Also used : SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore) DeployAPIInGatewayEvent(org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)

Aggregations

SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)43 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)14 SubscriptionDataHolder (org.wso2.carbon.apimgt.keymgt.SubscriptionDataHolder)9 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 ArrayList (java.util.ArrayList)7 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)6 Subscription (org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)5 SubscriptionDataLoaderImpl (org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl)5 MessageContext (org.apache.synapse.MessageContext)4 DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)4 ErrorDTO (org.wso2.carbon.apimgt.rest.api.gateway.dto.ErrorDTO)4 ApiPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 URLMapping (org.wso2.carbon.apimgt.api.model.subscription.URLMapping)2 API (org.wso2.carbon.apimgt.common.analytics.publishers.dto.API)2 DeployAPIInGatewayEvent (org.wso2.carbon.apimgt.impl.notifier.events.DeployAPIInGatewayEvent)2 ApplicationPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicy)2 Scope (org.wso2.carbon.apimgt.keymgt.model.entity.Scope)2 SubscriptionPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy)2