|
80 | 80 | import org.wso2.carbon.apimgt.tracing.telemetry.TelemetrySpan;
|
81 | 81 | import org.wso2.carbon.apimgt.tracing.telemetry.TelemetryTracer;
|
82 | 82 | import org.wso2.carbon.apimgt.tracing.telemetry.TelemetryUtil;
|
| 83 | +import org.wso2.carbon.base.ServerConfiguration; |
83 | 84 | import org.wso2.carbon.context.PrivilegedCarbonContext;
|
84 | 85 | import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
|
85 | 86 | import org.wso2.carbon.mediation.registry.RegistryServiceHolder;
|
86 | 87 | import org.wso2.carbon.registry.core.Resource;
|
87 | 88 | import org.wso2.carbon.registry.core.exceptions.RegistryException;
|
88 | 89 | import org.wso2.carbon.registry.core.session.UserRegistry;
|
| 90 | +import org.wso2.carbon.user.api.UserStoreException; |
89 | 91 | import org.wso2.carbon.user.core.UserCoreConstants;
|
| 92 | +import org.wso2.carbon.utils.CarbonUtils; |
90 | 93 | import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
|
91 | 94 | import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
|
92 | 95 |
|
@@ -1716,4 +1719,68 @@ public static boolean isOnDemandLoading() {
|
1716 | 1719 | .getGatewayArtifactSynchronizerProperties();
|
1717 | 1720 | return gatewayArtifactSynchronizerProperties.isOnDemandLoading();
|
1718 | 1721 | }
|
| 1722 | + |
| 1723 | + /** |
| 1724 | + * This method return the carbon.xml config value for tenant eager loading |
| 1725 | + * |
| 1726 | + * @return config string |
| 1727 | + */ |
| 1728 | + public static String getEagerLoadingEnabledTenantsConfig() { |
| 1729 | + ServerConfiguration carbonConfig = CarbonUtils.getServerConfiguration(); |
| 1730 | + return carbonConfig.getFirstProperty(APIConstants.EAGER_LOADING_ENABLED_TENANTS); |
| 1731 | + } |
| 1732 | + |
| 1733 | + /** |
| 1734 | + * This method returns the list of tenants for which eager loading is enabled |
| 1735 | + * |
| 1736 | + * @return List of eager loading enabled tenants |
| 1737 | + */ |
| 1738 | + public static List<String> getTenantsToBeDeployed() throws APIManagementException { |
| 1739 | + List<String> tenantsToBeDeployed = new ArrayList<>(); |
| 1740 | + tenantsToBeDeployed.add(APIConstants.SUPER_TENANT_DOMAIN); |
| 1741 | + |
| 1742 | + //Read eager loading config from carbon server config, and extract include and exclude tenant lists |
| 1743 | + String eagerLoadingConfig = getEagerLoadingEnabledTenantsConfig(); |
| 1744 | + if (StringUtils.isNotEmpty(eagerLoadingConfig)) { |
| 1745 | + boolean includeAllTenants = false; |
| 1746 | + List<String> includeTenantList = new ArrayList<>(); |
| 1747 | + List<String> excludeTenantList = new ArrayList<>(); |
| 1748 | + |
| 1749 | + |
| 1750 | + if (StringUtils.isNotEmpty(eagerLoadingConfig)) { |
| 1751 | + String[] tenants = eagerLoadingConfig.split(","); |
| 1752 | + for (String tenant : tenants) { |
| 1753 | + tenant = tenant.trim(); |
| 1754 | + if (tenant.equals("*")) { |
| 1755 | + includeAllTenants = true; |
| 1756 | + } else if (tenant.contains("!")) { |
| 1757 | + if (tenant.contains("*")) { |
| 1758 | + // "!*" is not a valid config |
| 1759 | + throw new IllegalArgumentException(tenant + " is not a valid tenant domain"); |
| 1760 | + } |
| 1761 | + excludeTenantList.add(tenant.replace("!", "")); |
| 1762 | + } else { |
| 1763 | + includeTenantList.add(tenant); |
| 1764 | + } |
| 1765 | + } |
| 1766 | + } |
| 1767 | + |
| 1768 | + //Fetch all active tenant domains |
| 1769 | + try { |
| 1770 | + Set<String> allTenants = APIUtil.getTenantDomainsByState(APIConstants.TENANT_STATE_ACTIVE); |
| 1771 | + if (includeAllTenants) { |
| 1772 | + tenantsToBeDeployed.addAll(allTenants); |
| 1773 | + // Now that we have included all tenants, let's see whether any tenant have been excluded |
| 1774 | + if (!excludeTenantList.isEmpty()) { |
| 1775 | + tenantsToBeDeployed.removeAll(excludeTenantList); |
| 1776 | + } |
| 1777 | + } else { |
| 1778 | + tenantsToBeDeployed.addAll(includeTenantList); |
| 1779 | + } |
| 1780 | + } catch (UserStoreException e) { |
| 1781 | + throw new APIManagementException("Error while fetching active tenants list.", e); |
| 1782 | + } |
| 1783 | + } |
| 1784 | + return tenantsToBeDeployed; |
| 1785 | + } |
1719 | 1786 | }
|
0 commit comments