http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/utils/Util.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/utils/Util.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/utils/Util.java deleted file mode 100644 index c6e5c70..0000000 --- a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/utils/Util.java +++ /dev/null @@ -1,464 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.stratos.throttling.manager.utils; - -import org.apache.stratos.throttling.manager.dataproviders.DataProvider; -import org.apache.stratos.throttling.manager.exception.ThrottlingException; -import org.apache.stratos.throttling.manager.scheduling.ThrottlingJob; -import org.apache.stratos.throttling.manager.services.MultitenancyThrottlingService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.synapse.task.TaskDescription; -import org.apache.synapse.task.TaskScheduler; -import org.apache.synapse.task.TaskSchedulerFactory; -import org.osgi.framework.BundleContext; -import org.wso2.carbon.billing.core.BillingEngine; -import org.wso2.carbon.billing.core.BillingException; -import org.wso2.carbon.billing.core.BillingManager; -import org.wso2.carbon.billing.core.dataobjects.Customer; -import org.wso2.carbon.billing.core.dataobjects.Item; -import org.wso2.carbon.billing.core.dataobjects.Subscription; -import org.wso2.carbon.registry.core.Resource; -import org.wso2.carbon.registry.core.exceptions.RegistryException; -import org.wso2.carbon.registry.core.service.RegistryService; -import org.wso2.carbon.registry.core.session.UserRegistry; -import org.wso2.carbon.registry.core.utils.UUIDGenerator; -import org.wso2.carbon.rule.kernel.config.RuleEngineConfigService; -import org.wso2.carbon.user.core.UserStoreException; -import org.wso2.carbon.user.core.service.RealmService; -import org.wso2.carbon.user.core.tenant.Tenant; -import org.wso2.carbon.user.core.tenant.TenantManager; -import org.wso2.carbon.utils.CarbonUtils; -import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import org.wso2.carbon.billing.mgt.api.MultitenancyBillingInfo; -import org.wso2.carbon.billing.mgt.dataobjects.MultitenancyPackage; -import org.apache.stratos.common.constants.StratosConstants; -import org.apache.stratos.throttling.agent.client.ThrottlingRuleInvoker; -import org.apache.stratos.throttling.manager.conf.ThrottlingConfiguration; -import org.apache.stratos.throttling.manager.tasks.Task; -import org.apache.stratos.usage.api.TenantUsageRetriever; - -import java.io.File; -import java.lang.reflect.Constructor; -import java.text.DateFormatSymbols; -import java.util.Calendar; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Properties; - -/** - * Util methods for throttling manager. - */ -public class Util { - private static final Log log = LogFactory.getLog(Util.class); - private static RegistryService registryService; - private static RealmService realmService; - private static RuleEngineConfigService ruleEngineConfigService; - private static BillingManager billingManager; - private static BundleContext bundleContext; - private static TenantUsageRetriever tenantUsageRetriever; - private static MultitenancyBillingInfo mtBillingInfo; - private static final String THROTTLING_CONFIG = "usage-throttling-agent-config.xml"; - private static final String THROTTLING_TASK_ID = "throttling-task"; - private static ThrottlingConfiguration throttlingConfiguration; - private static final String THROTTLING_RULE_FILE = "throttling-rules.drl"; - - public static synchronized void setRegistryService(RegistryService service) { - if (registryService == null) { - registryService = service; - } - } - - public static RegistryService getRegistryService() { - return registryService; - } - - public static synchronized void setRealmService(RealmService service) { - if (realmService == null) { - realmService = service; - } - } - - public static synchronized void setBundleContext(BundleContext context) { - if (bundleContext == null) { - bundleContext = context; - } - } - - public static void setTenantUsageRetriever(TenantUsageRetriever tenantUsageRetriever) { - Util.tenantUsageRetriever = tenantUsageRetriever; - } - - public static RealmService getRealmService() { - return realmService; - } - - public static UserRegistry getSuperTenantGovernanceSystemRegistry() throws RegistryException { - return registryService.getGovernanceSystemRegistry(); - } - - public static TenantUsageRetriever getTenantUsageRetriever() { - return tenantUsageRetriever; - } - - public static void setRuleEngineConfigService( - RuleEngineConfigService ruleEngineConfigService) { - Util.ruleEngineConfigService = ruleEngineConfigService; - } - - public static RuleEngineConfigService getRuleEngineConfigService() { - return Util.ruleEngineConfigService; - } - - public static BillingManager getBillingManager() { - return billingManager; - } - - public static void setBillingManager(BillingManager billingManager) { - Util.billingManager = billingManager; - } - - /** - * get current billing customer. - * - * @param tenantId, tenant id. - * @return Customer - * @throws RegistryException, if getting the current billing customer failed. - */ - public static Customer getCurrentBillingCustomer(int tenantId) throws RegistryException { - // get the host name of the current domain - if (tenantId == MultitenantConstants.SUPER_TENANT_ID) { - return null; - } - Tenant tenant; - try { - tenant = (Tenant) realmService.getTenantManager().getTenant(tenantId); - } catch (org.wso2.carbon.user.api.UserStoreException e) { - String msg = "Error in getting the realm Information."; - log.error(msg, e); - throw new RegistryException(msg, e); - } - if (tenant == null) { - return null; - } - String customerName = tenant.getDomain(); - BillingEngine billingEngine = - billingManager.getBillingEngine(StratosConstants.MULTITENANCY_VIEWING_TASK_ID); - Customer customer; - try { - if (billingEngine != null) { - List<Customer> customers = billingEngine.getCustomersWithName(customerName); - if (customers == null || customers.size() == 0) { - customer = null; - } else { - customer = customers.get(0); - } - } else { - customer=null; - String msg = "Error in getting billing Engine"; - log.error(msg); - } - } catch (BillingException e) { - String msg = "Error in getting the current customer"; - log.error(msg, e); - throw new RegistryException(msg, e); - } - return customer; - } - - /** - * get current subscription type for the tenant. - * - * @param tenantId, tenant id - * @throws RegistryException, if getting the current subscription type failed. - * @return, Subscripiton - */ - public static Subscription getCurrentSubscription(int tenantId) throws RegistryException { - BillingEngine billingEngine = - billingManager.getBillingEngine(StratosConstants.MULTITENANCY_SCHEDULED_TASK_ID); - - Customer customer = getCurrentBillingCustomer(tenantId); - if (customer == null) { - return null; - } - List<Subscription> subscriptions; - try { - subscriptions = billingEngine.getActiveSubscriptions(customer); - } catch (BillingException e) { - String msg = "Error in getting the current subscription."; - log.error(msg, e); - throw new RegistryException(msg, e); - } - if (subscriptions == null || subscriptions.size() == 0) { - return null; - } - Subscription subscription = subscriptions.get(0); - if (subscription.getActiveUntil().getTime() <= System.currentTimeMillis()) { - return null; - } - int itemId = subscription.getItem().getId(); - // fill with a correct item - Item item; - try { - item = billingEngine.getItem(itemId); - } catch (BillingException e) { - String msg = "Error in getting the item for item id: " + itemId + "."; - log.error(msg, e); - throw new RegistryException(msg, e); - } - subscription.setItem(item); - return subscription; - } - - /** - * get current billing package. - * - * @param tenantId, tenant id. - * @return MultitenancyPackage - * @throws RegistryException, if getting the current billing package failed. - */ - public static MultitenancyPackage getCurrentBillingPackage(int tenantId) - throws RegistryException { - if (mtBillingInfo == null) { - String msg = - "Error in retrieving the current billing package. The package info is null."; - log.error(msg); - throw new RegistryException(msg); - } - List<MultitenancyPackage> multitenancyPackages = mtBillingInfo.getMultitenancyPackages(); - Subscription subscription = getCurrentSubscription(tenantId); - Item currentPackage; - if (subscription == null) { - currentPackage = null; - } else { - currentPackage = subscription.getItem(); - } - MultitenancyPackage currentMultitenancyPackage = null; - for (MultitenancyPackage multitenancyPackage : multitenancyPackages) { - if (multitenancyPackage.getName().toLowerCase().contains("free") && - currentPackage == null) { - currentMultitenancyPackage = multitenancyPackage; - break; - } else if (currentPackage != null && - multitenancyPackage.getName().equals(currentPackage.getName())) { - currentMultitenancyPackage = multitenancyPackage; - break; - } - } - return currentMultitenancyPackage; - } - - /** - * get maximum users allowed for a tenant. - * - * @param tenantId, tenant id - * @throws RegistryException, if getting the maximum number of users failed. - * @return, maximum number of users allowed. - */ - public static int getMaximumUsersAllow(int tenantId) throws RegistryException { - MultitenancyPackage multitenancyPackage = getCurrentBillingPackage(tenantId); - if (multitenancyPackage == null) { - String msg = "The multitenancy package is null."; - log.error(msg); - throw new RegistryException(msg); - } - return multitenancyPackage.getUsersLimit(); - } - - /** - * returns the maximum resource volume in bytes - * - * @param tenantId, tenant id - * @return Resource volume limit. - * @throws RegistryException, if getting the maximum resource limit failed. - */ - public static long getMaximumResourceVolume(int tenantId) throws RegistryException { - MultitenancyPackage multitenancyPackage = getCurrentBillingPackage(tenantId); - if (multitenancyPackage == null) { - String msg = "The multitenancy package is null."; - log.error(msg); - throw new RegistryException(msg); - } - // converting the mb to bytes - return ((long) multitenancyPackage.getResourceVolumeLimit()) * 1024 * 1024; - } - - /** - * get the current month - * - * @param calendar, Calendar - * @return, year-month - */ - public static String getCurrentMonthString(Calendar calendar) { - int currentMonth = calendar.get(Calendar.MONTH); - - String[] monthArr = new DateFormatSymbols().getMonths(); - String month = monthArr[currentMonth]; - return calendar.get(Calendar.YEAR) + "-" + month; - } - - public static void registerTaskOSGIService(Task task) { - if (bundleContext != null) { - bundleContext.registerService(Task.class.getName(), task, null); - } - } - - public static void registerHandlerOSGIService(DataProvider handler) { - if (bundleContext != null) { - bundleContext.registerService(DataProvider.class.getName(), handler, null); - } - } - - public static void setMultitenancyBillingInfo(MultitenancyBillingInfo mtBillingInfo) { - Util.mtBillingInfo = mtBillingInfo; - } - - /** - * Construct the object for the given class - * - * @param className - name of the class - * @return the constructed object. - * @throws org.apache.stratos.throttling.manager.exception.ThrottlingException, if constructing the object failed. - */ - public static Object constructObject(String className) throws ThrottlingException { - Class cl; - Constructor co; - Object obj; - try { - cl = Class.forName(className); - } catch (ClassNotFoundException e) { - String msg = "The class: " + className + " is not in the classpath."; - log.error(msg, e); - throw new ThrottlingException(msg, e); - } - - try { - co = cl.getConstructor(); - } catch (NoSuchMethodException e) { - String msg = "The default constructor for the is not available for " + className + "."; - log.error(msg, e); - throw new ThrottlingException(msg, e); - } - try { - obj = co.newInstance(); - } catch (Exception e) { - String msg = "Error in initializing the object for " + className + "."; - log.error(msg); - throw new ThrottlingException(msg, e); - } - return obj; - } - - public static void registerThrottlingRuleInvoker() { - // construct an instance of throttling service as the rule invoker. - bundleContext.registerService(ThrottlingRuleInvoker.class.getName(), - new MultitenancyThrottlingService(), null); - } - - /** - * Initialize throttling - * - * @throws ThrottlingException, if initializing failed. - */ - public static void initializeThrottling() throws ThrottlingException { - - // load the configuration and initialize the billing engine + do the - // necessary scheduling. - String configFile = CarbonUtils.getCarbonConfigDirPath() + File.separator + - StratosConstants.MULTITENANCY_CONFIG_FOLDER + File.separator + THROTTLING_CONFIG; - // the configuration init will initialize task objects. - throttlingConfiguration = new ThrottlingConfiguration(configFile); - List<Task> throttlingTasks = throttlingConfiguration.getThrottlingTasks(); - - // now initialize the scheduling per each task - for (Task throttlingTask : throttlingTasks) { - initializeScheduling(throttlingTask); - } - } - - private static void initializeScheduling(Task throttlingTask) { - // generate tasks - if (throttlingTask.getTriggerInterval() < 0) { - log.info("Throttling manager Validation info service Disabled"); - } else { - String taskName = UUIDGenerator.generateUUID(); - String groupId = UUIDGenerator.generateUUID(); - - TaskDescription taskDescription = new TaskDescription(); - taskDescription.setName(taskName); - taskDescription.setGroup(groupId); - // we are triggering only at the period - - taskDescription.setInterval(throttlingTask.getTriggerInterval()); - - //Delay first run by given minutes - Calendar startTime = Calendar.getInstance(); - startTime.add(Calendar.MILLISECOND, throttlingTask.getStartDelayInterval()); - taskDescription.setStartTime(startTime.getTime()); - - Map<String, Object> resources = new HashMap<String, Object>(); - resources.put(ThrottlingJob.THROTTLING_TASK_CONTEXT_KEY, throttlingTask); - - TaskScheduler taskScheduler = TaskSchedulerFactory.getTaskScheduler(THROTTLING_TASK_ID); - if (!taskScheduler.isInitialized()) { - Properties properties = new Properties(); - taskScheduler.init(properties); - } - taskScheduler.scheduleTask(taskDescription, resources, ThrottlingJob.class); - } - } - - /** - * get all the tenants - * - * @return Tenant[] - * @throws UserStoreException, if getting the tenants failed. - */ - public static Tenant[] getAllTenants() throws UserStoreException { - TenantManager tenantManager = realmService.getTenantManager(); - try { - return (Tenant[]) tenantManager.getAllTenants(); - } catch (org.wso2.carbon.user.api.UserStoreException e) { - throw new UserStoreException(e); - } - } - - public static List<Task> getTasks() { - return throttlingConfiguration.getThrottlingTasks(); - } - - /** - * Load throttling rules - * - * @throws Exception, if loading the throttling rules failed. - */ - public static void loadThrottlingRules() throws Exception { - UserRegistry systemRegistry = getSuperTenantGovernanceSystemRegistry(); - if (systemRegistry.resourceExists(StratosConstants.THROTTLING_RULES_PATH)) { - return; - } - String throttlingRuleFile = CarbonUtils.getCarbonConfigDirPath() + - File.separator + THROTTLING_RULE_FILE; - byte[] content = CarbonUtils.getBytesFromFile(new File(throttlingRuleFile)); - Resource ruleResource = systemRegistry.newResource(); - ruleResource.setContent(content); - systemRegistry.put(StratosConstants.THROTTLING_RULES_PATH, ruleResource); - } -}
http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/validation/ValidationInfoManager.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/validation/ValidationInfoManager.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/validation/ValidationInfoManager.java deleted file mode 100644 index 850468d..0000000 --- a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/validation/ValidationInfoManager.java +++ /dev/null @@ -1,122 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.stratos.throttling.manager.validation; - -import java.util.Properties; -import java.util.Set; - -import org.apache.stratos.throttling.manager.dataobjects.ThrottlingAccessValidation; -import org.apache.stratos.throttling.manager.exception.ThrottlingException; -import org.apache.stratos.throttling.manager.utils.Util; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.registry.core.Registry; -import org.wso2.carbon.registry.core.RegistryConstants; -import org.wso2.carbon.registry.core.Resource; -import org.wso2.carbon.registry.core.exceptions.RegistryException; -import org.apache.stratos.common.constants.StratosConstants; -import org.apache.stratos.common.util.MeteringAccessValidationUtils; -import org.apache.stratos.throttling.manager.dataobjects.ThrottlingDataContext; - -public class ValidationInfoManager { - private static final Log log = LogFactory.getLog(ValidationInfoManager.class); - - public static void loadValidationDetails(ThrottlingDataContext throttlingDataContext) - throws ThrottlingException { - int tenantId = throttlingDataContext.getTenantId(); - // retrieve validation info for the tenant - String tenantValidationInfoResourcePath = - StratosConstants.TENANT_USER_VALIDATION_STORE_PATH + - RegistryConstants.PATH_SEPARATOR + tenantId; - - ThrottlingAccessValidation accessValidation = throttlingDataContext.getAccessValidation(); - if (accessValidation == null) { - accessValidation = new ThrottlingAccessValidation(); - throttlingDataContext.setAccessValidation(accessValidation); - } - try { - Registry governanceSystemRegistry = Util.getSuperTenantGovernanceSystemRegistry(); - if (governanceSystemRegistry.resourceExists(tenantValidationInfoResourcePath)) { - Resource tenantValidationInfoResource = - governanceSystemRegistry.get(tenantValidationInfoResourcePath); - Properties properties = tenantValidationInfoResource.getProperties(); - Set<String> actions = MeteringAccessValidationUtils.getAvailableActions(properties); - - for (String action : actions) { - String blockActionStr = - tenantValidationInfoResource.getProperty(MeteringAccessValidationUtils - .generateIsBlockedPropertyKey(action)); - - String blockActionMsg = - tenantValidationInfoResource.getProperty(MeteringAccessValidationUtils - .generateErrorMsgPropertyKey(action)); - accessValidation.setTenantBlocked(action, "true".equals(blockActionStr), - blockActionMsg); - - } - } - } catch (RegistryException e) { - String msg = - "Error in getting the tenant validation info. tenant id: " + tenantId + "."; - log.error(msg, e); - throw new ThrottlingException(msg, e); - } - } - - public static void persistValidationDetails(ThrottlingDataContext throttlingDataContext) - throws ThrottlingException { - int tenantId = throttlingDataContext.getTenantId(); - // retrieve validation info for the tenant - String tenantValidationInfoResourcePath = - StratosConstants.TENANT_USER_VALIDATION_STORE_PATH + - RegistryConstants.PATH_SEPARATOR + tenantId; - - ThrottlingAccessValidation accessValidation = throttlingDataContext.getAccessValidation(); - try { - Registry governanceSystemRegistry = Util.getSuperTenantGovernanceSystemRegistry(); - - Resource tenantValidationInfoResource; - if (governanceSystemRegistry.resourceExists(tenantValidationInfoResourcePath)) { - tenantValidationInfoResource = - governanceSystemRegistry.get(tenantValidationInfoResourcePath); - } else { - tenantValidationInfoResource = governanceSystemRegistry.newResource(); - } - - Set<String> actions = accessValidation.getActions(); - for (String action : actions) { - boolean blockAction = accessValidation.isTenantBlocked(action); - String blockActionMsg = accessValidation.getTenantBlockedMsg(action); - - tenantValidationInfoResource.setProperty(MeteringAccessValidationUtils - .generateIsBlockedPropertyKey(action), blockAction ? "true" : "false"); - - tenantValidationInfoResource.setProperty(MeteringAccessValidationUtils - .generateErrorMsgPropertyKey(action), blockActionMsg); - } - governanceSystemRegistry.put(tenantValidationInfoResourcePath, - tenantValidationInfoResource); - } catch (RegistryException e) { - String msg = - "Error in storing the tenant validation info. tenant id: " + tenantId + "."; - log.error(msg, e); - throw new ThrottlingException(msg, e); - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.throttling.manager/src/main/resources/META-INF/component.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.throttling.manager/src/main/resources/META-INF/component.xml b/components/org.apache.stratos.throttling.manager/src/main/resources/META-INF/component.xml deleted file mode 100644 index cd8be13..0000000 --- a/components/org.apache.stratos.throttling.manager/src/main/resources/META-INF/component.xml +++ /dev/null @@ -1,40 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> - -<component xmlns="http://products.wso2.org/carbon"> - <ManagementPermissions> - <ManagementPermission> - <DisplayName>Configure</DisplayName> - <ResourceId>/permission/protected/configure</ResourceId> - </ManagementPermission> - <ManagementPermission> - <DisplayName>Throttling-Rules</DisplayName> - <ResourceId>/permission/protected/configure/throttling-rules</ResourceId> - </ManagementPermission> - <ManagementPermission> - <DisplayName>Manage</DisplayName> - <ResourceId>/permission/protected/manage</ResourceId> - </ManagementPermission> - <ManagementPermission> - <DisplayName>Throttling</DisplayName> - <ResourceId>/permission/protected/manage/throttling</ResourceId> - </ManagementPermission> - </ManagementPermissions> -</component> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.throttling.manager/src/main/resources/META-INF/services.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.throttling.manager/src/main/resources/META-INF/services.xml b/components/org.apache.stratos.throttling.manager/src/main/resources/META-INF/services.xml deleted file mode 100644 index a153ef3..0000000 --- a/components/org.apache.stratos.throttling.manager/src/main/resources/META-INF/services.xml +++ /dev/null @@ -1,59 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<serviceGroup> - - <service name="MultitenancyThrottlingService" scope="transportsession"> - <transports> - <transport>https</transport> - </transports> - <parameter name="ServiceClass" locked="false"> - org.apache.stratos.throttling.manager.services.MultitenancyThrottlingService - </parameter> - <parameter name="adminService" locked="true">true</parameter> - <parameter name="AuthorizationAction" locked="true">/permission/protected/manage/throttling - </parameter> - - <operation name="executeThrottlingRules"> - <parameter name="superTenantService" locked="true">true</parameter> - </operation> - </service> - - <service name="ThrottlingRuleEditorService" scope="transportsession"> - <transports> - <transport>https</transport> - </transports> - <parameter name="ServiceClass" locked="false"> - org.apache.stratos.throttling.manager.services.ThrottlingRuleEditorService - </parameter> - <parameter name="adminService" locked="true">true</parameter> - <parameter name="AuthorizationAction" locked="true">/permission/protected/configure/throttling-rules - </parameter> - - <operation name="retrieveThrottlingRules"> - <parameter name="superTenantService" locked="true">true</parameter> - </operation> - - <operation name="updateThrottlingRules"> - <parameter name="superTenantService" locked="true">true</parameter> - </operation> - </service> - - <parameter name="hiddenService" locked="true">true</parameter> -</serviceGroup> http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/ThrottlingTest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/ThrottlingTest.java b/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/ThrottlingTest.java deleted file mode 100644 index 396fb42..0000000 --- a/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/ThrottlingTest.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbon.throttling.test; - -import org.apache.stratos.throttling.manager.scheduling.ThrottlingJob; -import org.wso2.carbon.registry.core.Resource; -import org.wso2.carbon.user.core.tenant.Tenant; -import org.wso2.carbon.utils.CarbonUtils; -import org.apache.stratos.throttling.manager.tasks.Task; -import org.apache.carbon.throttling.test.utils.BaseTestCase; - -public class ThrottlingTest extends BaseTestCase { - public void testLimitResourceSizeRules() throws Exception { - Tenant tenant = new Tenant(); - tenant.setAdminName("admin"); - tenant.setDomain("abc1.com"); - tenant.setAdminPassword("admin"); - tenant.setEmail("[email protected]"); - tenant.setActive(true); - - int tenantId = realmService.getTenantManager().addTenant(tenant); - realmService.getTenantManager().activateTenant(tenantId); - registry = registryService.getGovernanceUserRegistry("admin", tenantId); - - String configFile = CarbonUtils.getCarbonConfigDirPath() + "/throttling-config1.xml"; - String ruleFile = CarbonUtils.getCarbonConfigDirPath() + "/throttling-rules1.drl"; - // the configuration init will initialize task objects. - //ThrottlingConfiguration ignore = new ThrottlingConfiguration(configFile); - Task task = getThrottlingTask(configFile, ruleFile); - - Resource r1 = registry.newResource(); - r1.setContent("12345678"); // 8 byte is ok - registry.put("/bang", r1); - - new ThrottlingJob().executeTask(task); - - try { - putEmptyResource(); - assertTrue(true); - } catch (Exception e) { - e.printStackTrace(); - assertTrue(false); - } - - r1.setContent("123456789"); // 9 byte is not ok - registry.put("/bang", r1); - - new ThrottlingJob().executeTask(task); - try { - putEmptyResource(); - assertTrue(false); // we expect the exception - } catch (Exception e) { - assertTrue(true); - assertEquals("Your data is big. Bigger than 8", e.getMessage()); - } - - registry.delete("/bang"); - new ThrottlingJob().executeTask(task); - - r1.setContent("1234567891011"); // > 10 byte is not ok - registry.put("/bang", r1); - new ThrottlingJob().executeTask(task); - try { - putEmptyResource(); - assertTrue(true); - } catch (Exception e) { - assertTrue(false); - e.printStackTrace(); - } - registry.delete("/bang"); - new ThrottlingJob().executeTask(task); - - r1.setContent("1234567890123456"); - registry.put("/bang", r1); - new ThrottlingJob().executeTask(task); - try { - putEmptyResource(); - assertTrue(false); // we expect the exception - } catch (Exception e) { - assertTrue(true); - assertEquals("the strange condition for test1 is met", e.getMessage()); - } - registry.delete("/bang"); - new ThrottlingJob().executeTask(task); - - r1.setContent("12345678901234567"); - registry.put("/bang", r1); - new ThrottlingJob().executeTask(task); - try { - putEmptyResource(); - assertTrue(false); // we expect the exception - } catch (Exception e) { - assertTrue(true); - assertEquals("the strange condition for test2 is met", e.getMessage()); - } - } - - public void testBandwidthRules() throws Exception { - - Tenant tenant = new Tenant(); - tenant.setAdminName("admin"); - tenant.setDomain("abc2.com"); - tenant.setAdminPassword("admin"); - tenant.setEmail("[email protected]"); - tenant.setActive(true); - - int tenantId = realmService.getTenantManager().addTenant(tenant); - realmService.getTenantManager().activateTenant(tenantId); - registry = registryService.getGovernanceUserRegistry("admin", tenantId); - - String configFile = CarbonUtils.getCarbonConfigDirPath() + "/throttling-config2.xml"; - String ruleFile = CarbonUtils.getCarbonConfigDirPath() + "/throttling-rules2.drl"; - // the configuration init will initialize task objects. - //ThrottlingConfiguration ignore = new ThrottlingConfiguration(configFile); - Task task = getThrottlingTask(configFile, ruleFile); - - Resource r1 = registry.newResource(); - r1.setContent("12345678"); // 8 byte in - registry.put("/bang", r1); - new ThrottlingJob().executeTask(task); - try { - putEmptyResource(); - assertTrue(true); - } catch (Exception e) { - assertTrue(false); - e.printStackTrace(); - } - - r1.setContent("12345678"); // another 8 byte in - registry.put("/bang", r1); - new ThrottlingJob().executeTask(task); - try { - putEmptyResource(); - assertTrue(false); // we expect the exception - } catch (Exception e) { - assertTrue(true); - assertEquals("Your incoming bw is big. Bigger than 12. your value: 16", e.getMessage()); - } - - // setting another 8 bytes, this should give the early message rather than a new one - - new ThrottlingJob().executeTask(task); - r1.setContent("12345678"); // another 8 byte in - try { - registry.put("/bang", r1); - assertTrue(false); // we expect the exception - } catch (Exception e) { - assertTrue(true); - // and same exception message (no bigger number than 16) - assertEquals("Your incoming bw is big. Bigger than 12. your value: 16", e.getMessage()); - } - } - - public void testDBVolume() throws Exception { - - Tenant tenant = new Tenant(); - tenant.setAdminName("admin"); - tenant.setDomain("abc3.com"); - tenant.setAdminPassword("admin"); - tenant.setEmail("[email protected]"); - tenant.setActive(true); - - int tenantId = realmService.getTenantManager().addTenant(tenant); - realmService.getTenantManager().activateTenant(tenantId); - registry = registryService.getGovernanceUserRegistry("admin", tenantId); - - String configFile = CarbonUtils.getCarbonConfigDirPath() + "/throttling-config3.xml"; - String ruleFile = CarbonUtils.getCarbonConfigDirPath() + "/throttling-rules3.drl"; - // the configuration init will initialize task objects. - //ThrottlingConfiguration ignore = new ThrottlingConfiguration(configFile); - Task task = getThrottlingTask(configFile, ruleFile); - - Resource r1 = registry.newResource(); - r1.setContent("12345678"); // 8 byte in - - registry.put("/bang", r1); - new ThrottlingJob().executeTask(task); - try { - putEmptyResource(); - assertTrue(true); - } catch (Exception e) { - assertTrue(false); - e.printStackTrace(); - } - - r1.setContent("12345678"); // another 8 byte in - registry.put("/bang2", r1); - new ThrottlingJob().executeTask(task); - try { - putEmptyResource(); - assertTrue(false); // we expect the exception - } catch (Exception e) { - assertTrue(true); - assertEquals("Your resource volume is big. Bigger than 12. your value: 16", e.getMessage()); - } - - // setting another 8 bytes, this should give the early message rather than a new one - // if the pre handlers are doing the job. because the value 16 will be increased only - // it goes through the pre dataProviderConfigs - - new ThrottlingJob().executeTask(task); - r1.setContent("12345678"); // another 8 byte in - try { - registry.put("/bang3", r1); - assertTrue(false); // we expect the exception - } catch (Exception e) { - assertTrue(true); - // and same exception message (no bigger number than 16) - assertEquals("Your resource volume is big. Bigger than 12. your value: 16", e.getMessage()); - } - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/utils/BaseTestCase.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/utils/BaseTestCase.java b/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/utils/BaseTestCase.java deleted file mode 100644 index 78746ab..0000000 --- a/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/utils/BaseTestCase.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbon.throttling.test.utils; - -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.util.List; - -import javax.sql.DataSource; - -import junit.framework.TestCase; - -import org.apache.stratos.throttling.manager.conf.ThrottlingConfiguration; -import org.apache.stratos.throttling.manager.tasks.Task; -import org.apache.stratos.throttling.manager.utils.Util; -import org.wso2.carbon.registry.core.Registry; -import org.wso2.carbon.registry.core.Resource; -import org.wso2.carbon.registry.core.config.RegistryContext; -import org.wso2.carbon.registry.core.jdbc.EmbeddedRegistryService; -import org.wso2.carbon.registry.core.jdbc.InMemoryEmbeddedRegistryService; -import org.wso2.carbon.registry.core.session.UserRegistry; -import org.wso2.carbon.user.core.service.RealmService; -import org.wso2.carbon.utils.CarbonUtils; -import org.apache.stratos.common.constants.StratosConstants; -import org.wso2.carbon.registry.core.jdbc.dataaccess.JDBCDataAccessManager; - -public class BaseTestCase extends TestCase { - - protected static RegistryContext ctx; - protected EmbeddedRegistryService registryService; - protected Registry registry; // an admin registry - protected RealmService realmService; - - public void setUp() throws Exception { - if (System.getProperty("carbon.home") == null) { - File file = new File("src/test/resources/carbon-home"); - if (file.exists()) { - System.setProperty("carbon.home", file.getAbsolutePath()); - } - } - - InputStream is; - try { - is = new FileInputStream("src/test/resources/registry.xml"); - } catch (Exception e) { - is = null; - } - /* - * RealmService realmService = new InMemoryRealmService(); - * RegistryContext registryContext = RegistryContext.getBaseInstance(is, - * realmService); registryContext.setSetup(true); - * registryContext.selectDBConfig("h2-db"); - */ - - registryService = new InMemoryEmbeddedRegistryService(is); - Util.setRegistryService(registryService); - org.apache.stratos.usage.util.Util.setRegistryService(registryService); - org.apache.stratos.usage.agent.util.Util.initializeAllListeners(); -// TODO org.apache.stratos.usage.agent.util.Util.setRegistryService(registryService); - - realmService = RegistryContext.getBaseInstance().getRealmService(); - Util.setRealmService(realmService); - DataSource registryDataSource = - ((JDBCDataAccessManager) RegistryContext.getBaseInstance().getDataAccessManager()) - .getDataSource(); - UserRegistry superTenantGovernanceRegistry = registryService.getGovernanceSystemRegistry(); -// TODO Util.setTenantUsageRetriever(new TenantUsageRetriever(registryDataSource, -// superTenantGovernanceRegistry, registryService)); - - /*RuleServerManager ruleServerManager = new RuleServerManager(); - RuleServerConfiguration configuration = - new RuleServerConfiguration(new JSR94BackendRuntimeFactory()); - ruleServerManager.init(configuration); - Util.setRuleEngineConfigService(ruleServerManager); - */ - } - - public Task getThrottlingTask(String configFile, String ruleFile) throws Exception { - saveTrottlingRules(ruleFile); - ThrottlingConfiguration throttlingConfiguration = new ThrottlingConfiguration(configFile); - List<Task> throttlingTasks = throttlingConfiguration.getThrottlingTasks(); - return throttlingTasks.get(0); - } - - public void saveTrottlingRules(String throttlingRuleFile) throws Exception { - UserRegistry systemRegistry = registryService.getGovernanceSystemRegistry(); - - byte[] content = CarbonUtils.getBytesFromFile(new File(throttlingRuleFile)); - Resource ruleResource = systemRegistry.newResource(); - ruleResource.setContent(content); - systemRegistry.put(StratosConstants.THROTTLING_RULES_PATH, ruleResource); - } - - public void putEmptyResource() throws Exception { - Resource r = (Resource) registry.newResource(); - registry.put("/empty", r); - } - -} http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/utils/CustomDataProvider.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/utils/CustomDataProvider.java b/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/utils/CustomDataProvider.java deleted file mode 100644 index b24f03e..0000000 --- a/components/org.apache.stratos.throttling.manager/src/test/java/org/apache/carbon/throttling/test/utils/CustomDataProvider.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.carbon.throttling.test.utils; - -import org.wso2.carbon.billing.mgt.dataobjects.MultitenancyPackage; -import org.apache.stratos.throttling.manager.dataobjects.ThrottlingDataContext; -import org.apache.stratos.throttling.manager.dataobjects.ThrottlingDataEntryConstants; -import org.apache.stratos.throttling.manager.dataproviders.DataProvider; -import org.apache.stratos.throttling.manager.exception.ThrottlingException; - -public class CustomDataProvider extends DataProvider { - public void invoke(ThrottlingDataContext dataContext) throws ThrottlingException { - long dataSize = dataContext.getDataLong(ThrottlingDataEntryConstants.TENANT_CAPACITY); - - if (dataSize % 2 == 0) { - MultitenancyPackage multiPackage = new MultitenancyPackage(); - multiPackage.setName("test1"); - multiPackage.setBandwidthLimit(50); - - dataContext.addDataObject(ThrottlingDataEntryConstants.PACKAGE, multiPackage); - } else { - MultitenancyPackage multiPackage = new MultitenancyPackage(); - multiPackage.setName("test2"); - - dataContext.addDataObject(ThrottlingDataEntryConstants.PACKAGE, multiPackage); - multiPackage.setBandwidthLimit(50); - } - - } -} http://git-wip-us.apache.org/repos/asf/stratos/blob/ee5e9639/components/org.apache.stratos.throttling.manager/src/test/resources/carbon-home/dbscripts/db2.sql ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.throttling.manager/src/test/resources/carbon-home/dbscripts/db2.sql b/components/org.apache.stratos.throttling.manager/src/test/resources/carbon-home/dbscripts/db2.sql deleted file mode 100644 index 6bf1da8..0000000 --- a/components/org.apache.stratos.throttling.manager/src/test/resources/carbon-home/dbscripts/db2.sql +++ /dev/null @@ -1,469 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ - -CREATE TABLE REG_CLUSTER_LOCK ( - REG_LOCK_NAME VARCHAR (20) NOT NULL, - REG_LOCK_STATUS VARCHAR (20), - REG_LOCKED_TIME TIMESTAMP, - REG_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (REG_LOCK_NAME) -); - -CREATE TABLE REG_LOG ( - REG_LOG_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1) , - REG_PATH VARCHAR (2000), - REG_USER_ID VARCHAR (31) NOT NULL, - REG_LOGGED_TIME TIMESTAMP NOT NULL, - REG_ACTION INTEGER NOT NULL, - REG_ACTION_DATA VARCHAR (500), - REG_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (REG_LOG_ID) -); - -CREATE TABLE REG_PATH( - REG_PATH_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_PATH_VALUE VARCHAR(2000) NOT NULL, - REG_PATH_PARENT_ID INTEGER, - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_PATH PRIMARY KEY(REG_PATH_ID) -); --- This index cannot be created due to large length of REG_PATH_VALUE column - sumedha ---CREATE UNIQUE INDEX REG_PATH_IND_BY_PATH_PATH_VALUE ON REG_PATH(REG_PATH_VALUE); - -CREATE TABLE REG_CONTENT ( - REG_CONTENT_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_CONTENT_DATA BLOB(2G), - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_CONTENT PRIMARY KEY(REG_CONTENT_ID) -); - -CREATE TABLE REG_CONTENT_HISTORY ( - REG_CONTENT_ID INTEGER NOT NULL, - REG_CONTENT_DATA BLOB(2G), - REG_DELETED SMALLINT, - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_CONTENT_HISTORY PRIMARY KEY(REG_CONTENT_ID) -); - -CREATE TABLE REG_RESOURCE ( - REG_PATH_ID INTEGER NOT NULL, - REG_NAME VARCHAR(256), - REG_VERSION INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_MEDIA_TYPE VARCHAR(500), - REG_CREATOR VARCHAR(31) NOT NULL, - REG_CREATED_TIME TIMESTAMP NOT NULL, - REG_LAST_UPDATOR VARCHAR(31), - REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL, - REG_DESCRIPTION VARCHAR(1000), - REG_CONTENT_ID INTEGER, - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_RESOURCE PRIMARY KEY(REG_VERSION) - /**CONSTRAINT PK_REG_RESOURCE PRIMARY KEY(PATH_ID,NAME,VERSION)*/ -); - -ALTER TABLE REG_RESOURCE ADD CONSTRAINT REG_RESOURCE_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID) REFERENCES REG_PATH (REG_PATH_ID); -ALTER TABLE REG_RESOURCE ADD CONSTRAINT REG_RESOURCE_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID) REFERENCES REG_CONTENT (REG_CONTENT_ID); -CREATE UNIQUE INDEX REG_RESOURCE_IND_BY_NAME ON REG_RESOURCE(REG_NAME); -CREATE UNIQUE INDEX REG_RESOURCE_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME); - -CREATE TABLE REG_RESOURCE_HISTORY ( - REG_PATH_ID INTEGER NOT NULL, - REG_NAME VARCHAR(256), - REG_VERSION INTEGER NOT NULL, - REG_MEDIA_TYPE VARCHAR(500), - REG_CREATOR VARCHAR(31) NOT NULL, - REG_CREATED_TIME TIMESTAMP NOT NULL, - REG_LAST_UPDATOR VARCHAR(31), - REG_LAST_UPDATED_TIME TIMESTAMP NOT NULL, - REG_DESCRIPTION VARCHAR(1000), - REG_CONTENT_ID INTEGER, - REG_DELETED SMALLINT, - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_RESOURCE_HISTORY PRIMARY KEY(REG_VERSION) -); - -ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT REG_RESOURCE_HIST_FK_BY_PATHID FOREIGN KEY (REG_PATH_ID) REFERENCES REG_PATH (REG_PATH_ID); -ALTER TABLE REG_RESOURCE_HISTORY ADD CONSTRAINT REG_RESOURCE_HIST_FK_BY_CONTENT_ID FOREIGN KEY (REG_CONTENT_ID) REFERENCES REG_CONTENT_HISTORY (REG_CONTENT_ID); -CREATE UNIQUE INDEX REG_RESOURCE_HISTORY_IND_BY_NAME ON REG_RESOURCE_HISTORY(REG_NAME); -CREATE UNIQUE INDEX REG_RESOURCE_HISTORY_IND_BY_PATH_ID_NAME ON REG_RESOURCE(REG_PATH_ID, REG_NAME); - -CREATE TABLE REG_COMMENT ( - REG_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_COMMENT_TEXT VARCHAR(500) NOT NULL, - REG_USER_ID VARCHAR(31) NOT NULL, - REG_COMMENTED_TIME TIMESTAMP NOT NULL, - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_COMMENT PRIMARY KEY(REG_ID) -); - -CREATE TABLE REG_RESOURCE_COMMENT ( - REG_COMMENT_ID INTEGER NOT NULL, - REG_VERSION INTEGER NOT NULL, - REG_PATH_ID INTEGER, - REG_RESOURCE_NAME VARCHAR(256), - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_RESOURCE_COMMENT PRIMARY KEY(REG_VERSION, REG_COMMENT_ID) -); - -ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT REG_RESOURCE_COMMENT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID) REFERENCES REG_PATH (REG_PATH_ID); -ALTER TABLE REG_RESOURCE_COMMENT ADD CONSTRAINT REG_RESOURCE_COMMENT_FK_BY_COMMENT_ID FOREIGN KEY (REG_COMMENT_ID) REFERENCES REG_COMMENT (REG_ID); -CREATE UNIQUE INDEX REG_RESOURCE_COMMENT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_COMMENT(REG_PATH_ID, REG_RESOURCE_NAME); -CREATE UNIQUE INDEX REG_RESOURCE_COMMENT_IND_BY_VERSION ON REG_RESOURCE_COMMENT(REG_VERSION); - -CREATE TABLE REG_RATING ( - REG_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_RATING INTEGER NOT NULL, - REG_USER_ID VARCHAR(31) NOT NULL, - REG_RATED_TIME TIMESTAMP NOT NULL, - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_RATING PRIMARY KEY(REG_ID) -); - -CREATE TABLE REG_RESOURCE_RATING ( - REG_RATING_ID INTEGER NOT NULL, - REG_VERSION INTEGER NOT NULL, - REG_PATH_ID INTEGER, - REG_RESOURCE_NAME VARCHAR(256), - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_RESOURCE_RATING PRIMARY KEY(REG_VERSION, REG_RATING_ID) -); - -ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT REG_RESOURCE_RATING_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID) REFERENCES REG_PATH (REG_PATH_ID); -ALTER TABLE REG_RESOURCE_RATING ADD CONSTRAINT REG_RESOURCE_RATING_FK_BY_RATING_ID FOREIGN KEY (REG_RATING_ID) REFERENCES REG_RATING (REG_ID); -CREATE UNIQUE INDEX REG_RESOURCE_RATING_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_RATING(REG_PATH_ID, REG_RESOURCE_NAME); -CREATE UNIQUE INDEX REG_RESOURCE_RATING_IND_BY_VERSION ON REG_RESOURCE_RATING(REG_VERSION); - - -CREATE TABLE REG_TAG ( - REG_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_TAG_NAME VARCHAR(500) NOT NULL, - REG_USER_ID VARCHAR(31) NOT NULL, - REG_TAGGED_TIME TIMESTAMP NOT NULL, - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_TAG PRIMARY KEY(REG_ID) -); - -CREATE TABLE REG_RESOURCE_TAG ( - REG_TAG_ID INTEGER NOT NULL, - REG_VERSION INTEGER NOT NULL, - REG_PATH_ID INTEGER, - REG_RESOURCE_NAME VARCHAR(256), - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_RESOURCE_TAG PRIMARY KEY(REG_VERSION, REG_TAG_ID) -); - -ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT REG_RESOURCE_TAG_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID) REFERENCES REG_PATH (REG_PATH_ID); -ALTER TABLE REG_RESOURCE_TAG ADD CONSTRAINT REG_RESOURCE_TAG_FK_BY_TAG_ID FOREIGN KEY (REG_TAG_ID) REFERENCES REG_TAG (REG_ID); -CREATE UNIQUE INDEX REG_RESOURCE_TAG_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_TAG(REG_PATH_ID, REG_RESOURCE_NAME); -CREATE UNIQUE INDEX REG_RESOURCE_TAG_IND_BY_VERSION ON REG_RESOURCE_TAG(REG_VERSION); - -CREATE TABLE REG_PROPERTY ( - REG_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_NAME VARCHAR(100) NOT NULL, - REG_VALUE VARCHAR(1000), - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_PROPERTY PRIMARY KEY(REG_ID) -); - -CREATE TABLE REG_RESOURCE_PROPERTY ( - REG_PROPERTY_ID INTEGER NOT NULL, - REG_VERSION INTEGER NOT NULL, - REG_PATH_ID INTEGER, - REG_RESOURCE_NAME VARCHAR(256), - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_RESOURCE_PROPERTY PRIMARY KEY(REG_VERSION, REG_PROPERTY_ID) -); - -ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT REG_RESOURCE_PROPERTY_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID) REFERENCES REG_PATH (REG_PATH_ID); -ALTER TABLE REG_RESOURCE_PROPERTY ADD CONSTRAINT REG_RESOURCE_PROPERTY_FK_BY_TAG_ID FOREIGN KEY (REG_PROPERTY_ID) REFERENCES REG_PROPERTY (REG_ID); -CREATE UNIQUE INDEX REG_RESOURCE_PROPERTY_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_RESOURCE_PROPERTY(REG_PATH_ID, REG_RESOURCE_NAME); -CREATE UNIQUE INDEX REG_RESOURCE_PROPERTY_IND_BY_VERSION ON REG_RESOURCE_PROPERTY(REG_VERSION); - --- CREATE TABLE REG_ASSOCIATIONS ( --- SRC_PATH_ID INTEGER, --- SRC_RESOURCE_NAME VARCHAR(256), --- SRC_VERSION INTEGER, --- TGT_PATH_ID INTEGER, --- TGT_RESOURCE_NAME VARCHAR(256), --- TGT_VERSION INTEGER --- ); --- --- ALTER TABLE REG_ASSOCIATIONS ADD CONSTRAINT REG_ASSOCIATIONS_FK_BY_SRC_PATH_ID FOREIGN KEY (SRC_PATH_ID) REFERENCES REG_PATH (PATH_ID); --- ALTER TABLE REG_ASSOCIATIONS ADD CONSTRAINT REG_ASSOCIATIONS_FK_BY_TGT_PATH_ID FOREIGN KEY (TGT_PATH_ID) REFERENCES REG_PATH (PATH_ID); --- CREATE UNIQUE INDEX REG_ASSOCIATIONS_IND_BY_SRC_VERSION ON REG_ASSOCIATIONS(SRC_VERSION); --- CREATE UNIQUE INDEX REG_ASSOCIATIONS_IND_BY_TGT_VERSION ON REG_ASSOCIATIONS(TGT_VERSION); --- CREATE UNIQUE INDEX REG_ASSOCIATIONS_IND_BY_SRC_RESOURCE_NAME ON REG_ASSOCIATIONS(SRC_RESOURCE_NAME); --- CREATE UNIQUE INDEX REG_ASSOCIATIONS_IND_BY_TGT_RESOURCE_NAME ON REG_ASSOCIATIONS(TGT_RESOURCE_NAME); - - - ---had to reduce REG_SOURCEPATH from 2000 to 1700, REG_TARGETPATH from 2000 to 1700 and REG_ASSOCIATION_TYPE from 2000 to 500 -CREATE TABLE REG_ASSOCIATION ( - REG_ASSOCIATION_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_SOURCEPATH VARCHAR(1700) NOT NULL, - REG_TARGETPATH VARCHAR(1700) NOT NULL, - REG_ASSOCIATION_TYPE VARCHAR(500) NOT NULL, - REG_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (REG_ASSOCIATION_ID) -); - -CREATE TABLE REG_SNAPSHOT ( - REG_SNAPSHOT_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - REG_PATH_ID INTEGER NOT NULL, - REG_RESOURCE_NAME VARCHAR(255), - REG_RESOURCE_VIDS BLOB(2G) NOT NULL, - REG_TENANT_ID INTEGER DEFAULT 0, - CONSTRAINT PK_REG_SNAPSHOT PRIMARY KEY(REG_SNAPSHOT_ID) -); - -CREATE UNIQUE INDEX REG_SNAPSHOT_IND_BY_PATH_ID_AND_RESOURCE_NAME ON REG_SNAPSHOT(REG_PATH_ID, REG_RESOURCE_NAME); - -ALTER TABLE REG_SNAPSHOT ADD CONSTRAINT REG_SNAPSHOT_FK_BY_PATH_ID FOREIGN KEY (REG_PATH_ID) REFERENCES REG_PATH (REG_PATH_ID); - - --- ################################ --- USER MANAGER TABLES --- ################################ - -CREATE TABLE UM_USER ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_USER_NAME VARCHAR(255) NOT NULL, - UM_USER_PASSWORD VARCHAR(255) NOT NULL, - UM_SALT_VALUE VARCHAR(31), - UM_REQUIRE_CHANGE BOOLEAN DEFAULT FALSE, - UM_CHANGED_TIME TIMESTAMP NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (UM_ID), - UNIQUE(UM_USER_NAME) -); - -CREATE TABLE UM_ROLE ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_ROLE_NAME VARCHAR(255) NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (UM_ID), - UNIQUE(UM_ROLE_NAME) -); - -CREATE TABLE UM_ROLE_ATTRIBUTE ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_ATTR_NAME VARCHAR(255) NOT NULL, - UM_ATTR_VALUE VARCHAR(255), - UM_ROLE_ID INTEGER, - UM_TENANT_ID INTEGER DEFAULT 0, - FOREIGN KEY (UM_ROLE_ID) REFERENCES UM_ROLE(UM_ID), - PRIMARY KEY (UM_ID) -); - -CREATE TABLE UM_PERMISSION ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_RESOURCE_ID VARCHAR(255) NOT NULL, - UM_ACTION VARCHAR(255) NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (UM_ID) -); - -CREATE UNIQUE INDEX INDEX_UM_PERMISSION_UM_RESOURCE_ID_UM_ACTION - ON UM_PERMISSION (UM_RESOURCE_ID, UM_ACTION); - -CREATE TABLE UM_ROLE_PERMISSION ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_PERMISSION_ID INTEGER NOT NULL, - UM_ROLE_ID INTEGER NOT NULL, - UM_IS_ALLOWED SMALLINT NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - FOREIGN KEY (UM_PERMISSION_ID) REFERENCES UM_PERMISSION(UM_ID) ON DELETE CASCADE, - FOREIGN KEY (UM_ROLE_ID) REFERENCES UM_ROLE(UM_ID), - PRIMARY KEY (UM_ID) -); --- REMOVED UNIQUE (UM_PERMISSION_ID, UM_ROLE_ID) - - -CREATE TABLE UM_USER_PERMISSION ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_PERMISSION_ID INTEGER NOT NULL, - UM_USER_ID INTEGER NOT NULL, - UM_IS_ALLOWED SMALLINT NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - FOREIGN KEY (UM_PERMISSION_ID) REFERENCES UM_PERMISSION(UM_ID) ON DELETE CASCADE , - FOREIGN KEY (UM_USER_ID) REFERENCES UM_USER(UM_ID), - PRIMARY KEY (UM_ID) -); --- REMOVED UNIQUE (UM_PERMISSION_ID, UM_USER_ID) - -CREATE TABLE UM_USER_ROLE ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_ROLE_ID INTEGER NOT NULL, - UM_USER_ID INTEGER NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - UNIQUE (UM_USER_ID, UM_ROLE_ID), - FOREIGN KEY (UM_ROLE_ID) REFERENCES UM_ROLE(UM_ID), - FOREIGN KEY (UM_USER_ID) REFERENCES UM_USER(UM_ID), - PRIMARY KEY (UM_ID) -); - - -CREATE TABLE UM_USER_DATA ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_USER_ID INTEGER NOT NULL, - UM_EMAIL VARCHAR(255), - UM_FIRST_NAME VARCHAR(150), - UM_LAST_NAME VARCHAR(150), - UM_BIRTH_DATE VARCHAR(100), - UM_FULL_NAME VARCHAR(255), - UM_NAME_PREFIX VARCHAR(30), - UM_GENDER VARCHAR(10), - UM_TIME_ZONE VARCHAR(100), - UM_COMPANY_NAME VARCHAR(255), - UM_JOB_TITLE VARCHAR(150), - UM_PRIMARY_PHONE VARCHAR(100), - UM_HOME_PHONE VARCHAR(100), - UM_WORK_PHONE VARCHAR(100), - UM_MOBILE_PHONE VARCHAR(100), - UM_STREET_ADDRESS VARCHAR(255), - UM_CITY VARCHAR(100), - UM_STATE VARCHAR(100), - UM_COUNTRY VARCHAR(50), - UM_POSTAL_CODE VARCHAR(50), - UM_WEB_PAGE VARCHAR(255), - UM_LANGUAGE VARCHAR(255), - UM_BLOG VARCHAR(255), - UM_PROFILE_ID VARCHAR(50), - UM_TENANT_ID INTEGER DEFAULT 0, - FOREIGN KEY (UM_USER_ID) REFERENCES UM_USER(UM_ID), - PRIMARY KEY (UM_ID) -); - - -CREATE TABLE UM_BIN_DATA ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_USER_ID INTEGER NOT NULL, - UM_CONTENT_NAME VARCHAR(255) NOT NULL, - UM_CONTENT BLOB NOT NULL, - UM_PROFILE_ID VARCHAR(255) NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - FOREIGN KEY (UM_USER_ID) REFERENCES UM_USER(UM_ID), - PRIMARY KEY (UM_ID) -); - - -CREATE TABLE UM_USER_ATTRIBUTE ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_ATTR_NAME VARCHAR(255) NOT NULL, - UM_ATTR_VALUE VARCHAR(1024), - UM_PROFILE_ID VARCHAR(255), - UM_USER_ID INTEGER, - UM_TENANT_ID INTEGER DEFAULT 0, - FOREIGN KEY (UM_USER_ID) REFERENCES UM_USER(UM_ID), - PRIMARY KEY (UM_ID) -); - - - -CREATE TABLE UM_DIALECT( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_DIALECT_URI VARCHAR(255) NOT NULL, - UM_REALM VARCHAR(63) NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - UNIQUE(UM_DIALECT_URI, UM_REALM), - PRIMARY KEY (UM_ID) -); - -CREATE TABLE UM_CLAIM( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_DIALECT_ID INTEGER NOT NULL, - UM_CLAIM_URI VARCHAR(255) NOT NULL, - UM_DISPLAY_TAG VARCHAR(255), - UM_DESCRIPTION VARCHAR(255), - UM_MAPPED_ATTRIBUTE VARCHAR(255), - UM_REG_EX VARCHAR(255), - UM_SUPPORTED SMALLINT, - UM_REQUIRED SMALLINT, - UM_DISPLAY_ORDER INTEGER, - UM_TENANT_ID INTEGER DEFAULT 0, - UNIQUE(UM_DIALECT_ID, UM_CLAIM_URI), - FOREIGN KEY(UM_DIALECT_ID) REFERENCES UM_DIALECT(UM_ID), - PRIMARY KEY (UM_ID) -); - -CREATE TABLE UM_PROFILE_CONFIG( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_DIALECT_ID INTEGER NOT NULL, - UM_PROFILE_NAME VARCHAR(255), - UM_TENANT_ID INTEGER DEFAULT 0, - FOREIGN KEY(UM_DIALECT_ID) REFERENCES UM_DIALECT(UM_ID), - PRIMARY KEY (UM_ID) -); - -CREATE TABLE UM_CLAIM_BEHAVIOR( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_PROFILE_ID INTEGER, - UM_CLAIM_ID INTEGER, - UM_BEHAVIOUR SMALLINT, - UM_TENANT_ID INTEGER DEFAULT 0, - FOREIGN KEY(UM_PROFILE_ID) REFERENCES UM_PROFILE_CONFIG(UM_ID), - FOREIGN KEY(UM_CLAIM_ID) REFERENCES UM_CLAIM(UM_ID), - PRIMARY KEY (UM_ID) -); - -CREATE TABLE HYBRID_ROLE ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_ROLE_ID VARCHAR(255) NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (UM_ID), - UNIQUE(UM_ROLE_ID) -); - -CREATE TABLE HYBRID_USER_ROLE ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_USER_ID VARCHAR(255), - UM_ROLE_ID VARCHAR(255) NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (UM_ID) -); - -CREATE TABLE HYBRID_PERMISSION ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_RESOURCE_ID VARCHAR(255), - UM_ACTION VARCHAR(255) NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (UM_ID) -); - -CREATE TABLE HYBRID_ROLE_PERMISSION ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_PERMISSION_ID INTEGER NOT NULL, - UM_ROLE_ID VARCHAR(255) NOT NULL, - UM_IS_ALLOWED SMALLINT NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - UNIQUE (UM_PERMISSION_ID, UM_ROLE_ID), - FOREIGN KEY (UM_PERMISSION_ID) REFERENCES HYBRID_PERMISSION(UM_ID), - PRIMARY KEY (UM_ID) -); - -CREATE TABLE HYBRID_USER_PERMISSION ( - UM_ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), - UM_PERMISSION_ID INTEGER NOT NULL, - UM_USER_ID VARCHAR(255) NOT NULL, - UM_IS_ALLOWED SMALLINT NOT NULL, - UM_TENANT_ID INTEGER DEFAULT 0, - UNIQUE (UM_PERMISSION_ID, UM_USER_ID), - FOREIGN KEY (UM_PERMISSION_ID) REFERENCES HYBRID_PERMISSION(UM_ID), - PRIMARY KEY (UM_ID) -);
