You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@stratos.apache.org by la...@apache.org on 2013/07/12 09:53:09 UTC
[16/18] applying 0001-Refactor-throttling-module.patch
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/listeners/WebAppRequestListener.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/listeners/WebAppRequestListener.java b/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/listeners/WebAppRequestListener.java
new file mode 100644
index 0000000..cd7fec9
--- /dev/null
+++ b/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/listeners/WebAppRequestListener.java
@@ -0,0 +1,180 @@
+/*
+ * 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.agent.listeners;
+
+import org.apache.stratos.throttling.agent.cache.ThrottlingActionInfo;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.base.MultitenantConstants;
+import org.wso2.carbon.context.CarbonContext;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.throttling.agent.ThrottlingAgent;
+import org.apache.stratos.throttling.agent.cache.TenantThrottlingInfo;
+import org.wso2.carbon.tomcat.ext.valves.CarbonTomcatValve;
+import org.wso2.carbon.user.api.UserStoreException;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class WebAppRequestListener implements CarbonTomcatValve {
+
+ private static final Log log = LogFactory.getLog(WebAppRequestListener.class);
+
+ private static final Pattern servicesURLPattern = Pattern.compile("\\/services\\/t\\/(.*?)\\/");
+ private static final Pattern webAppsURLPattern = Pattern.compile("\\/t\\/(.*?)\\/webapps\\/");
+
+ private static final String CONTEXT_SERVICES = "services";
+ private static final String CONTEXT_WEBAPPS = "webapps";
+
+ private ThrottlingAgent throttlingAgent;
+
+ public WebAppRequestListener(ThrottlingAgent throttlingAgent) {
+ this.throttlingAgent = throttlingAgent;
+ }
+
+ public void invoke(HttpServletRequest request, HttpServletResponse response) {
+ String requestURI = request.getRequestURI();
+ String tenantDomainName = CarbonContext.getCurrentContext().
+ getTenantDomain();
+ String urlContext = getContext(requestURI);
+ if (tenantDomainName != null && urlContext != null) {
+ try {
+ int tenantId = throttlingAgent.getRealmService().getTenantManager().
+ getTenantId(tenantDomainName);
+ if (tenantId <= 0) {
+ //Allow to proceed
+ } else {
+ if (!throttlingAgent.getRealmService().getTenantManager().getTenant(tenantId).
+ isActive()) {
+ //Check weather activated tenant or not
+ String msg = "You are sending request to a deactivated tenant. for Domain: "
+ + tenantDomainName;
+ log.error(msg);
+ try {
+ response.sendError(403, msg);
+ } catch (IOException e) {
+ String message = "Error in sending throttling rule violation message by an inactive tenant." +
+ " Tenant Domain: " + tenantDomainName;
+ log.error(message, e);
+ }
+ } else {
+ //check weather request come to webapps
+ if (CONTEXT_WEBAPPS.equals(urlContext)) {
+ //if tenant is active we will throttle other parameters such as bandwidth in/out
+ try {
+ TenantThrottlingInfo throttlingInfo =
+ throttlingAgent.getThrottlingInfoCache().
+ getTenantThrottlingInfo(tenantId);
+ if (throttlingInfo != null) {
+ String[] actions =
+ new String[]{StratosConstants.THROTTLING_WEBAPP_IN_BANDWIDTH_ACTION,
+ StratosConstants.THROTTLING_WEBAPP_OUT_BANDWIDTH_ACTION};
+ ThrottlingActionInfo actionInfo;
+
+ actionInfo = throttlingInfo.getThrottlingActionInfo(actions);
+ if (actionInfo != null && actionInfo.isBlocked()) {
+ String blockedMsg = actionInfo.getMessage();
+ String msg = "This action is blocked. Reason: "
+ + blockedMsg;
+ log.error(msg);
+ response.sendError(509, msg);
+ }
+ }
+ } catch (Exception ex) {
+ String msg = "Error in sending throttling rule violation message." +
+ " Tenant Domain: " + tenantDomainName;
+ log.error(msg, ex);
+ return;
+ }
+ } else if (CONTEXT_SERVICES.equals(urlContext)) {
+ try {
+ TenantThrottlingInfo throttlingInfo =
+ throttlingAgent.getThrottlingInfoCache().
+ getTenantThrottlingInfo(tenantId);
+ if (throttlingInfo != null) {
+ String[] actions =
+ new String[]{StratosConstants.THROTTLING_SERVICE_IN_BANDWIDTH_ACTION,
+ StratosConstants.THROTTLING_SERVICE_OUT_BANDWIDTH_ACTION};
+ ThrottlingActionInfo actionInfo;
+
+ actionInfo = throttlingInfo.getThrottlingActionInfo(actions);
+ if (actionInfo != null && actionInfo.isBlocked()) {
+ String blockedMsg = actionInfo.getMessage();
+ String msg = "This action is blocked. Reason: " +
+ blockedMsg;
+ log.error(msg);
+ response.sendError(509, msg);
+ }
+ }
+ } catch (Exception ex) {
+ String msg = "Error in sending throttling rule violation message." +
+ " Tenant Domain: " + tenantDomainName;
+ log.error(msg, ex);
+ }
+ }
+
+ }
+ }
+ } catch (UserStoreException e) {
+ String msg = "Error in getting tenant id to evaluate throttling rule. " +
+ "Tenant Domain: " + tenantDomainName;
+ log.error(msg, e);
+ }
+
+ }
+ }
+
+ /**
+ * Extract tenant domain from request url
+ *
+ * @return tenant domain
+ */
+ public String getTenantName(String requestUrl) {
+ Matcher matcher = servicesURLPattern.matcher(requestUrl);
+ if (matcher.find()) {
+ return matcher.group(1);
+ }
+
+ matcher = webAppsURLPattern.matcher(requestUrl);
+ if (matcher.find()) {
+ return matcher.group(1);
+ }
+
+ return MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
+ }
+
+ /**
+ * Extract context from the request url
+ *
+ * @return context string
+ */
+ public String getContext(String requestUrl) {
+ if (requestUrl.contains("/services") && requestUrl.contains("/t")) {
+ return CONTEXT_SERVICES;
+ }
+
+ if (requestUrl.contains("/t") && requestUrl.contains("/webapps")) {
+ return CONTEXT_WEBAPPS;
+ }
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationException.java b/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationException.java
new file mode 100644
index 0000000..f0f8737
--- /dev/null
+++ b/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationException.java
@@ -0,0 +1,28 @@
+/*
+ * 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.agent.validation;
+
+public class ValidationException extends Exception {
+ public ValidationException(String msg, Exception e) {
+ super(msg, e);
+ }
+ public ValidationException(String msg) {
+ super(msg);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationInfo.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationInfo.java b/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationInfo.java
new file mode 100644
index 0000000..d313e28
--- /dev/null
+++ b/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationInfo.java
@@ -0,0 +1,42 @@
+/*
+ * 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.agent.validation;
+
+public class ValidationInfo {
+ boolean isActionBlocked;
+ String blockedActionMsg;
+
+ public ValidationInfo(){
+ isActionBlocked = false;
+ }
+
+ public boolean isActionBlocked() {
+ return isActionBlocked;
+ }
+ public void setActionBlocked(boolean isBlocked) {
+ this.isActionBlocked = isBlocked;
+ }
+ public String getBlockedActionMsg() {
+ return blockedActionMsg;
+ }
+ public void setBlockedActionMsg(String blockedMsg) {
+ this.blockedActionMsg = blockedMsg;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationInfoRetriever.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationInfoRetriever.java b/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationInfoRetriever.java
new file mode 100644
index 0000000..b65b1c5
--- /dev/null
+++ b/components/org.apache.stratos.throttling.agent/src/main/java/org/apache/stratos/throttling/agent/validation/ValidationInfoRetriever.java
@@ -0,0 +1,112 @@
+/*
+ * 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.agent.validation;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.wso2.carbon.registry.core.RegistryConstants;
+import org.wso2.carbon.registry.core.Resource;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.registry.core.session.UserRegistry;
+import org.apache.stratos.common.constants.StratosConstants;
+import org.apache.stratos.common.util.MeteringAccessValidationUtils;
+
+public class ValidationInfoRetriever {
+ private static final Log log = LogFactory.getLog(ValidationInfoRetriever.class);
+ UserRegistry governanceSystemRegistry;
+
+ public ValidationInfoRetriever(UserRegistry governanceSystemRegistry) {
+ this.governanceSystemRegistry = governanceSystemRegistry;
+ }
+
+ public ValidationInfo getValidationInfo(String action, int tenantId) throws ValidationException {
+ ValidationInfo validationInfo = new ValidationInfo();
+ Resource validationInfoResource = getResource(tenantId);
+ if(validationInfoResource == null){
+ //this means, the user is allowed to proceed
+ return validationInfo;
+ }
+
+ // first get the validation info for all actions
+ checkAction(StratosConstants.THROTTLING_ALL_ACTION, validationInfoResource, validationInfo);
+ if (validationInfo.isActionBlocked()) {
+ return validationInfo;
+ }
+ checkAction(action, validationInfoResource, validationInfo);
+ return validationInfo;
+ }
+
+ public ValidationInfo getValidationInfo(String[] actions, int tenantId) throws ValidationException {
+ ValidationInfo validationInfo = new ValidationInfo();
+ Resource validationInfoResource = getResource(tenantId);
+ if(validationInfoResource == null){
+ //this means, the user is allowed to proceed
+ return validationInfo;
+ }
+
+ // first get the validation info for all actions
+ checkAction(StratosConstants.THROTTLING_ALL_ACTION, validationInfoResource, validationInfo);
+ if (validationInfo.isActionBlocked()) {
+ return validationInfo;
+ }
+
+ for(String action : actions){
+ checkAction(action, validationInfoResource, validationInfo);
+ if (validationInfo.isActionBlocked()) {
+ return validationInfo;
+ }
+ }
+ return validationInfo;
+ }
+
+ private Resource getResource (int tenantId) throws ValidationException{
+ // first retrieve validation info for the tenant
+ String tenantValidationInfoResourcePath =
+ StratosConstants.TENANT_USER_VALIDATION_STORE_PATH +
+ RegistryConstants.PATH_SEPARATOR + tenantId;
+ Resource tenantValidationInfoResource = null;
+ try {
+ if (governanceSystemRegistry.resourceExists(tenantValidationInfoResourcePath)) {
+ tenantValidationInfoResource =
+ governanceSystemRegistry.get(tenantValidationInfoResourcePath);
+ }
+ } catch (RegistryException e) {
+ String msg = "Error in getting the tenant validation info for tenant:" + tenantId;
+ log.error(msg, e);
+ throw new ValidationException(msg, e);
+ }
+ return tenantValidationInfoResource;
+ }
+
+ private void checkAction(String action, Resource tenantValidationInfoResource,
+ ValidationInfo validationInfo){
+ String blockActionStr =
+ tenantValidationInfoResource.getProperty(
+ MeteringAccessValidationUtils.generateIsBlockedPropertyKey(action));
+
+ if ("true".equals(blockActionStr)) {
+ validationInfo.setActionBlocked(true);
+
+ String blockActionMsg =
+ tenantValidationInfoResource.getProperty(
+ MeteringAccessValidationUtils.generateErrorMsgPropertyKey(action));
+ validationInfo.setBlockedActionMsg(blockActionMsg);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.agent/src/main/resources/META-INF/module.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.agent/src/main/resources/META-INF/module.xml b/components/org.apache.stratos.throttling.agent/src/main/resources/META-INF/module.xml
new file mode 100644
index 0000000..dcf21af
--- /dev/null
+++ b/components/org.apache.stratos.throttling.agent/src/main/resources/META-INF/module.xml
@@ -0,0 +1,34 @@
+<!--
+ ~ 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.
+ -->
+<module name="usagethrottling" class="org.apache.stratos.throttling.agent.listeners.ThrottlingModule">
+ <InFlow>
+ <handler name="InFlowUsageThrottlingHandler"
+ class="org.apache.stratos.throttling.agent.listeners.ServiceRequestListener">
+ <order phase="OpPhase" after="AuthorizationHandler"/>
+ </handler>
+ </InFlow>
+
+ <InFaultFlow>
+ <handler name="FaultInFlowUsageThrottlingHandler"
+ class="org.apache.stratos.throttling.agent.listeners.ServiceRequestListener">
+ <order phase="OpPhase" after="AuthorizationHandler"/>
+ </handler>
+ </InFaultFlow>
+ <parameter name="adminModule" locked="true">true</parameter>
+</module>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.agent/src/main/resources/MultitenancyThrottlingService.wsdl
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.agent/src/main/resources/MultitenancyThrottlingService.wsdl b/components/org.apache.stratos.throttling.agent/src/main/resources/MultitenancyThrottlingService.wsdl
new file mode 100644
index 0000000..a652030
--- /dev/null
+++ b/components/org.apache.stratos.throttling.agent/src/main/resources/MultitenancyThrottlingService.wsdl
@@ -0,0 +1,82 @@
+<wsdl:definitions xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:ns1="http://org.apache.axis2/xsd" xmlns:ns="http://services.manager.throttling.carbon.wso2.org" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" targetNamespace="http://services.manager.throttling.carbon.wso2.org">
+ <wsdl:documentation>MultitenancyThrottlingService</wsdl:documentation>
+ <wsdl:types>
+ <xs:schema attributeFormDefault="qualified" elementFormDefault="qualified" targetNamespace="http://services.manager.throttling.carbon.wso2.org">
+ <xs:element name="executeThrottlingRulesException">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="executeThrottlingRulesException" nillable="true" type="ns:Exception" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ <xs:complexType name="Exception">
+ <xs:sequence>
+ <xs:element minOccurs="0" name="Message" nillable="true" type="xs:string" />
+ </xs:sequence>
+ </xs:complexType>
+ <xs:element name="executeThrottlingRules">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element minOccurs="0" name="tenantId" type="xs:int" />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+ </xs:schema>
+ </wsdl:types>
+ <wsdl:message name="executeThrottlingRulesRequest">
+ <wsdl:part name="parameters" element="ns:executeThrottlingRules" />
+ </wsdl:message>
+ <wsdl:message name="executeThrottlingRulesException">
+ <wsdl:part name="parameters" element="ns:executeThrottlingRulesException" />
+ </wsdl:message>
+ <wsdl:portType name="MultitenancyThrottlingServicePortType">
+ <wsdl:operation name="executeThrottlingRules">
+ <wsdl:input message="ns:executeThrottlingRulesRequest" wsaw:Action="urn:executeThrottlingRules" />
+ <wsdl:fault message="ns:executeThrottlingRulesException" name="executeThrottlingRulesException" wsaw:Action="urn:executeThrottlingRulesexecuteThrottlingRulesException" />
+ </wsdl:operation>
+ </wsdl:portType>
+ <wsdl:binding name="MultitenancyThrottlingServiceSoap11Binding" type="ns:MultitenancyThrottlingServicePortType">
+ <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
+ <wsdl:operation name="executeThrottlingRules">
+ <soap:operation soapAction="urn:executeThrottlingRules" style="document" />
+ <wsdl:input>
+ <soap:body use="literal" />
+ </wsdl:input>
+ <wsdl:fault name="executeThrottlingRulesException">
+ <soap:fault use="literal" name="executeThrottlingRulesException" />
+ </wsdl:fault>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:binding name="MultitenancyThrottlingServiceSoap12Binding" type="ns:MultitenancyThrottlingServicePortType">
+ <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" />
+ <wsdl:operation name="executeThrottlingRules">
+ <soap12:operation soapAction="urn:executeThrottlingRules" style="document" />
+ <wsdl:input>
+ <soap12:body use="literal" />
+ </wsdl:input>
+ <wsdl:fault name="executeThrottlingRulesException">
+ <soap12:fault use="literal" name="executeThrottlingRulesException" />
+ </wsdl:fault>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:binding name="MultitenancyThrottlingServiceHttpBinding" type="ns:MultitenancyThrottlingServicePortType">
+ <http:binding verb="POST" />
+ <wsdl:operation name="executeThrottlingRules">
+ <http:operation location="executeThrottlingRules" />
+ <wsdl:input>
+ <mime:content type="text/xml" part="parameters" />
+ </wsdl:input>
+ </wsdl:operation>
+ </wsdl:binding>
+ <wsdl:service name="MultitenancyThrottlingService">
+ <wsdl:port name="MultitenancyThrottlingServiceHttpsSoap11Endpoint" binding="ns:MultitenancyThrottlingServiceSoap11Binding">
+ <soap:address location="https://192.168.1.100:9443/services/MultitenancyThrottlingService.MultitenancyThrottlingServiceHttpsSoap11Endpoint/" />
+ </wsdl:port>
+ <wsdl:port name="MultitenancyThrottlingServiceHttpsSoap12Endpoint" binding="ns:MultitenancyThrottlingServiceSoap12Binding">
+ <soap12:address location="https://192.168.1.100:9443/services/MultitenancyThrottlingService.MultitenancyThrottlingServiceHttpsSoap12Endpoint/" />
+ </wsdl:port>
+ <wsdl:port name="MultitenancyThrottlingServiceHttpsEndpoint" binding="ns:MultitenancyThrottlingServiceHttpBinding">
+ <http:address location="https://192.168.1.100:9443/services/MultitenancyThrottlingService.MultitenancyThrottlingServiceHttpsEndpoint/" />
+ </wsdl:port>
+ </wsdl:service>
+</wsdl:definitions>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/pom.xml
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/pom.xml b/components/org.apache.stratos.throttling.manager/pom.xml
new file mode 100644
index 0000000..0855d5a
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/pom.xml
@@ -0,0 +1,177 @@
+<!--
+ # 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.
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>stratos-components-parent</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>org.apache.stratos.throttling.manager</artifactId>
+ <packaging>bundle</packaging>
+ <name>Apache Stratos - Throttling Manager</name>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-scr-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <excludes>
+ <exclude>**/BaseTestCase.java</exclude>
+ <exclude>**/ThrottlingTest.java</exclude>
+ </excludes>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <extensions>true</extensions>
+ <configuration>
+ <instructions>
+ <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
+ <Bundle-Name>${project.artifactId}</Bundle-Name>
+ <Export-Package>
+ org.apache.stratos.throttling.manager.dataobjects,
+ </Export-Package>
+ <Private-Package>
+ !org.apache.stratos.throttling.manager.dataobjects,
+ org.apache.stratos.throttling.manager.*,
+ </Private-Package>
+ <!--<Require-Bundle>
+ drools;visibility:=reexport
+ </Require-Bundle>-->
+ <Import-Package>
+ org.wso2.carbon.rule.*,
+ org.apache.stratos.common.*,
+ org.apahce.throttling.agent.*,
+ org.wso2.carbon.billing.mgt.*,
+ org.wso2.carbon.registry.core.*;version=1.0.1,
+ org.wso2.carbon.registry.resource.*,
+ org.quartz.*; version=2.1.1,
+ !javax.xml.namespace,
+ javax.xml.namespace; version=0.0.0,
+ javax.servlet;version="${imp.pkg.version.javax.servlet}",
+ javax.servlet.http;version="${imp.pkg.version.javax.servlet}",
+ org.apache.axiom.*; version="${axiom.osgi.version.range}",
+ *;resolution:=optional
+ </Import-Package>
+ <DynamicImport-Package>*</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.axis2.wso2</groupId>
+ <artifactId>axis2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.core</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.utils</artifactId>
+ <version>4.1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.extensions</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.registry.resource</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.common</artifactId>
+ <version>${apache.stratos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.usage</artifactId>
+ <version>${apache.stratos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.billing.mgt</artifactId>
+ <version>2.1.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.rule.kernel</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.rule.common</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.wso2.carbon</groupId>
+ <artifactId>org.wso2.carbon.rule.backend</artifactId>
+ <version>${carbon.platform.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.synapse</groupId>
+ <artifactId>synapse-tasks</artifactId>
+ <version>2.1.1-wso2v4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.synapse</groupId>
+ <artifactId>synapse-commons</artifactId>
+ <version>2.1.1-wso2v4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.throttling.agent</artifactId>
+ <version>${apache.stratos.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.stratos</groupId>
+ <artifactId>org.apache.stratos.usage.agent</artifactId>
+ <version>${apache.stratos.version}</version>
+ </dependency>
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingConfiguration.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingConfiguration.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingConfiguration.java
new file mode 100644
index 0000000..2c43fa4
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingConfiguration.java
@@ -0,0 +1,107 @@
+/*
+ * 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.conf;
+
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.stratos.throttling.manager.exception.ThrottlingException;
+import org.apache.stratos.throttling.manager.tasks.Task;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.common.util.CommonUtil;
+
+public class ThrottlingConfiguration {
+ private static final Log log = LogFactory.getLog(ThrottlingConfiguration.class);
+ private static final String CONFIG_NS = "http://wso2.com/carbon/multitenancy/usage-throttling-agent/config";
+ List<ThrottlingTaskConfiguration> throttlingTaskConfigs;
+ List<Task> tasks;
+
+ public ThrottlingConfiguration(String throttlingConfigFile) throws ThrottlingException {
+ try {
+ OMElement throttlingConfig =
+ CommonUtil.buildOMElement(new FileInputStream(throttlingConfigFile));
+ deserialize(throttlingConfig);
+ } catch (FileNotFoundException e) {
+ String msg = "Unable to find the file: " + throttlingConfigFile + ".";
+ log.error(msg, e);
+ throw new ThrottlingException(msg, e);
+ } catch (Exception e) {
+ String msg = "Error in building the throttling config, config file: " +
+ throttlingConfigFile + ".";
+ log.error(msg, e);
+ throw new ThrottlingException(msg, e);
+ }
+ }
+
+ public void deserialize(OMElement throttlingConfigEle) throws ThrottlingException {
+ OMElement throttlingManagerConfigs=null;
+ Iterator childElements = throttlingConfigEle.getChildElements();
+ while (childElements.hasNext()) {
+ Object configChildElement = childElements.next();
+
+ if (!(configChildElement instanceof OMElement)) {
+ continue;
+ }
+ OMElement configChildOMElement = (OMElement) configChildElement;
+ if (new QName(CONFIG_NS, "ThrottlingManagerTask", "").equals(configChildOMElement.getQName())) {
+ throttlingManagerConfigs=(OMElement)configChildElement;
+ }
+ }
+ // Iterator throttlingConfigChildIt = throttlingConfigEle.getChildElements();
+ Iterator throttlingConfigChildIt = throttlingManagerConfigs.getChildElements();
+ while (throttlingConfigChildIt.hasNext()) {
+ Object throttlingConfigChild = throttlingConfigChildIt.next();
+ if (!(throttlingConfigChild instanceof OMElement)) {
+ continue;
+ }
+ OMElement throttlingConfigChildEle = (OMElement) throttlingConfigChild;
+
+ if (new QName(CONFIG_NS, "tasks", "").equals(throttlingConfigChildEle.getQName())) {
+ throttlingTaskConfigs = new ArrayList<ThrottlingTaskConfiguration>();
+ tasks = new ArrayList<Task>();
+ Iterator tasksConfigChildIt = throttlingConfigChildEle.getChildElements();
+ while (tasksConfigChildIt.hasNext()) {
+ Object taskConfigChild = tasksConfigChildIt.next();
+ if (!(taskConfigChild instanceof OMElement)) {
+ continue;
+ }
+ ThrottlingTaskConfiguration taskConfiguration =
+ new ThrottlingTaskConfiguration((OMElement) taskConfigChild);
+ throttlingTaskConfigs.add(taskConfiguration);
+ tasks.add(taskConfiguration.getTask());
+ }
+ }
+ }
+ }
+
+ public List<ThrottlingTaskConfiguration> getThrottlingTaskConfigs() {
+ return throttlingTaskConfigs;
+ }
+
+ public List<Task> getThrottlingTasks() {
+ return tasks;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingTaskConfiguration.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingTaskConfiguration.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingTaskConfiguration.java
new file mode 100644
index 0000000..553881b
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingTaskConfiguration.java
@@ -0,0 +1,120 @@
+/*
+ * 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.conf;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.throttling.manager.exception.ThrottlingException;
+import org.apache.stratos.throttling.manager.tasks.Task;
+
+import javax.xml.namespace.QName;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class ThrottlingTaskConfiguration {
+ private static final Log log =
+ LogFactory.getLog(ThrottlingTaskConfiguration.class);
+
+ private static final String CONFIG_NS =
+ "http://wso2.com/carbon/multitenancy/usage-throttling-agent/config";
+ private static final String TASK_CONF_PARAMERTERS = "parameters";
+ private static final String TASK_CONF_DATA_PROVIDERS = "dataProviders";
+ private static final String TASK_CONF_PARAM_KEY = "parameter";
+ private static final String TASK_CONF_PARAM_NAME_KEY = "name";
+
+ public static final String INTERVAL_PARAM_KEY = "interval";
+ public static final String DELAY_PARAM_KEY = "delay";
+
+ Task task;
+ List<ThrottlingTaskDataProviderConfiguration> dataProviderConfigs;
+ Map<String, String> taskParameters;
+
+ public ThrottlingTaskConfiguration(OMElement taskConfigEle) throws ThrottlingException {
+ dataProviderConfigs = new ArrayList<ThrottlingTaskDataProviderConfiguration>();
+ serialize(taskConfigEle);
+ }
+
+ private void serialize(OMElement taskConfigEle) throws ThrottlingException {
+ Iterator taskConfigChildIt = taskConfigEle.getChildElements();
+
+ while (taskConfigChildIt.hasNext()) {
+ Object taskConfigChildObj = taskConfigChildIt.next();
+ if (!(taskConfigChildObj instanceof OMElement)) {
+ continue;
+ }
+ OMElement taskConfigChildEle = (OMElement) taskConfigChildObj;
+ if (taskConfigChildEle.getQName().equals(new QName(CONFIG_NS, TASK_CONF_PARAMERTERS))) {
+ Iterator parametersIt = taskConfigChildEle.getChildElements();
+
+ taskParameters = extractTaskParameters(parametersIt);
+ } else if (taskConfigChildEle.getQName().equals(
+ new QName(CONFIG_NS, TASK_CONF_DATA_PROVIDERS))) {
+ Iterator handlerConfigIt = taskConfigChildEle.getChildElements();
+ while (handlerConfigIt.hasNext()) {
+ Object handlerConfigObj = handlerConfigIt.next();
+ if (!(handlerConfigObj instanceof OMElement)) {
+ continue;
+ }
+ OMElement handlerConfigEle = (OMElement) handlerConfigObj;
+ ThrottlingTaskDataProviderConfiguration handlerConfig =
+ new ThrottlingTaskDataProviderConfiguration(handlerConfigEle);
+ dataProviderConfigs.add(handlerConfig);
+ }
+ }
+ }
+
+ // create the task instance
+ task = new Task(taskParameters, dataProviderConfigs);
+
+ }
+
+ private static Map<String, String> extractTaskParameters(
+ Iterator parameterIt) throws ThrottlingException {
+ Map<String, String> parameters = new HashMap<String, String>();
+ while (parameterIt.hasNext()) {
+ Object parameterObj = parameterIt.next();
+ if (!(parameterObj instanceof OMElement)) {
+ continue;
+ }
+ OMElement configChildEle = (OMElement) parameterObj;
+ if (!new QName(CONFIG_NS, TASK_CONF_PARAM_KEY, "")
+ .equals(configChildEle.getQName())) {
+ continue;
+ }
+ String paramName =
+ configChildEle.getAttributeValue(new QName(
+ TASK_CONF_PARAM_NAME_KEY));
+ String paramValue = configChildEle.getText();
+ parameters.put(paramName, paramValue);
+ }
+ return parameters;
+ }
+
+ public List<ThrottlingTaskDataProviderConfiguration> getDataProviderConfigs() {
+ return dataProviderConfigs;
+ }
+
+ public Task getTask() {
+ return task;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingTaskDataProviderConfiguration.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingTaskDataProviderConfiguration.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingTaskDataProviderConfiguration.java
new file mode 100644
index 0000000..5187e2b
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/conf/ThrottlingTaskDataProviderConfiguration.java
@@ -0,0 +1,117 @@
+/*
+ * 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.conf;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.stratos.throttling.manager.dataproviders.DataProvider;
+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 javax.xml.namespace.QName;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+public class ThrottlingTaskDataProviderConfiguration {
+ private static final Log log =
+ LogFactory.getLog(ThrottlingTaskDataProviderConfiguration.class);
+
+ private static final String CONFIG_NS =
+ "http://wso2.com/carbon/multitenancy/throttling/config";
+ private static final String HANDLER_CONF_PARAM_KEY = "parameter";
+ private static final String HANDLER_CLASS_ATTR = "class";
+ private static final String HANDLER_CONF_PARAM_NAME_KEY = "name";
+ private static final String HANDLER_SERVICE_ATTR = "service";
+
+ private String dataProviderServiceName;
+ private Map<String, String> dataProviderParameters;
+ private DataProvider dataProvider;
+ // to keep the task class that are available.
+ private Map<String, DataProvider> dataProviders;
+
+ public ThrottlingTaskDataProviderConfiguration(OMElement handlerConfigEle)
+ throws ThrottlingException {
+ serialize(handlerConfigEle);
+ dataProviders = new HashMap<String, DataProvider>();
+ }
+
+ private void serialize(OMElement handlerConfigEle) throws ThrottlingException {
+ Iterator handlerParameterChildIt = handlerConfigEle.getChildElements();
+ Map<String, String> parameters = extractParameters(handlerParameterChildIt);
+ // get the task class
+ String handlerClassName = handlerConfigEle.getAttributeValue(new QName(HANDLER_CLASS_ATTR));
+
+ if (handlerClassName == null) {
+ dataProviderServiceName =
+ handlerConfigEle.getAttributeValue(new QName(HANDLER_SERVICE_ATTR));
+ dataProviderParameters = parameters;
+ } else {
+ dataProvider = (DataProvider) Util.constructObject(handlerClassName);
+ dataProvider.init(parameters);
+ }
+ }
+
+ private static Map<String, String> extractParameters(Iterator parameterIt)
+ throws ThrottlingException {
+ Map<String, String> parameters = new HashMap<String, String>();
+ while (parameterIt.hasNext()) {
+ Object parameterObj = parameterIt.next();
+ if (!(parameterObj instanceof OMElement)) {
+ continue;
+ }
+ OMElement configChildEle = (OMElement) parameterObj;
+ if (!new QName(CONFIG_NS, HANDLER_CONF_PARAM_KEY, "").equals(configChildEle.getQName())) {
+ continue;
+ }
+ String paramName =
+ configChildEle.getAttributeValue(new QName(HANDLER_CONF_PARAM_NAME_KEY));
+ String paramValue = configChildEle.getText();
+ parameters.put(paramName, paramValue);
+ }
+ return parameters;
+ }
+
+ // get task have to be called to initialize tasks which are registered as
+ // OSGI services
+ public DataProvider getDataProvider() throws ThrottlingException {
+ if (dataProvider == null && dataProviderServiceName != null) {
+ dataProvider = dataProviders.get(dataProviderServiceName);
+ if (dataProvider == null) {
+ String msg =
+ "The scheduler helper service: " +
+ dataProviderServiceName + " is not loaded.";
+ log.error(msg);
+ throw new ThrottlingException(msg);
+ }
+ dataProvider.init(dataProviderParameters);
+ }
+ return dataProvider;
+ }
+
+ public void loadDataProviderService() throws ThrottlingException {
+ if (dataProvider == null && dataProviderServiceName != null) {
+ dataProvider = dataProviders.get(dataProviderServiceName);
+ if (dataProvider != null) {
+ dataProvider.init(dataProviderParameters);
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingAccessValidation.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingAccessValidation.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingAccessValidation.java
new file mode 100644
index 0000000..0721dd4
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingAccessValidation.java
@@ -0,0 +1,73 @@
+/*
+ * 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.dataobjects;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+public class ThrottlingAccessValidation {
+
+ Map<String, Boolean> userBlockedActions = new HashMap<String, Boolean>();
+ Map<String, Boolean> tenantBlockedActions = new HashMap<String, Boolean>();
+ Map<String, String> userBlockedMsgs = new HashMap<String, String>();
+ Map<String, String> tenantBlockedMsgs = new HashMap<String, String>();
+
+ boolean persistValidationInfo = true;
+
+ public boolean isPersistValidationInfo() {
+ return persistValidationInfo;
+ }
+
+ public void setPersistValidationInfo(boolean persistValidationInfo) {
+ this.persistValidationInfo = persistValidationInfo;
+ }
+
+ public boolean isUserBlocked(String action) {
+ Boolean result = userBlockedActions.get(action);
+ return result == null? false: result;
+ }
+
+ public String getUserBlockedMsg(String action) {
+ return userBlockedMsgs.get(action);
+ }
+
+ public void setUserBlocked(String action, boolean block, String msg) {
+ userBlockedActions.put(action, block);
+ userBlockedMsgs.put(action, msg);
+ }
+
+ public boolean isTenantBlocked(String action) {
+ Boolean result = tenantBlockedActions.get(action);
+ return result == null? false: result;
+ }
+
+ public String getTenantBlockedMsg(String action) {
+ return tenantBlockedMsgs.get(action);
+ }
+
+ public void setTenantBlocked(String action, boolean block, String msg) {
+ tenantBlockedActions.put(action, block);
+ tenantBlockedMsgs.put(action, msg);
+ }
+
+ public Set<String> getActions() {
+ return tenantBlockedActions.keySet();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataContext.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataContext.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataContext.java
new file mode 100644
index 0000000..bbe5ac2
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataContext.java
@@ -0,0 +1,148 @@
+/*
+ * 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.dataobjects;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+
+public class ThrottlingDataContext {
+ int tenantId;
+ String userName;
+ Map<String, ThrottlingDataEntry> data;
+ boolean async = false;
+ String taskName = null;
+
+ private ThrottlingAccessValidation accessValidation;
+ boolean processingComplete;
+
+ public ThrottlingDataContext(int tenantId) {
+ this.tenantId = tenantId;
+ this.data = new HashMap<String, ThrottlingDataEntry>();
+ }
+
+ public int getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(int tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+
+ public ThrottlingAccessValidation getAccessValidation() {
+ return accessValidation;
+ }
+
+ public void setAccessValidation(ThrottlingAccessValidation accessValidation) {
+ this.accessValidation = accessValidation;
+ }
+
+ public boolean isProcessingComplete() {
+ return processingComplete;
+ }
+
+ public void setProcessingComplete(boolean processingComplete) {
+ this.processingComplete = processingComplete;
+ }
+
+ public Collection<ThrottlingDataEntry> getData() {
+ return data.values();
+ }
+
+ public void addDataString(String key, String value) {
+ ThrottlingDataEntry dataEntry = new ThrottlingDataEntry(key);
+ dataEntry.setStringValue(value);
+ data.put(key, dataEntry);
+ }
+
+ public void addDataLong(String key, long value) {
+ ThrottlingDataEntry dataEntry = new ThrottlingDataEntry(key);
+ dataEntry.setLongValue(value);
+ data.put(key, dataEntry);
+ }
+
+ public void addDataInt(String key, int value) {
+ ThrottlingDataEntry dataEntry = new ThrottlingDataEntry(key);
+ dataEntry.setIntValue(value);
+ data.put(key, dataEntry);
+ }
+
+ public void addDataObject(String key, Object value) {
+ ThrottlingDataEntry dataEntry = new ThrottlingDataEntry(key);
+ dataEntry.setObjectValue(value);
+ data.put(key, dataEntry);
+ }
+
+ public String getDataString(String key) {
+ ThrottlingDataEntry dataEntry = data.get(key);
+ if (dataEntry == null) {
+ return null;
+ }
+ return dataEntry.getStringValue();
+ }
+
+ public long getDataLong(String key) {
+ ThrottlingDataEntry dataEntry = data.get(key);
+ if (dataEntry == null) {
+ return 0;
+ }
+ return dataEntry.getLongValue();
+ }
+
+ public int getDataInt(String key) {
+ ThrottlingDataEntry dataEntry = data.get(key);
+ if (dataEntry == null) {
+ return 0;
+ }
+ return dataEntry.getIntValue();
+ }
+
+ public Object getDataObject(String key) {
+ ThrottlingDataEntry dataEntry = data.get(key);
+ if (dataEntry == null) {
+ return null;
+ }
+ return dataEntry.getObjectValue();
+ }
+
+ public boolean isAsync() {
+ return async;
+ }
+
+ public void setAsync(boolean async) {
+ this.async = async;
+ }
+
+ public String getTaskName() {
+ return taskName;
+ }
+
+ public void setTaskName(String taskName) {
+ this.taskName = taskName;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataEntry.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataEntry.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataEntry.java
new file mode 100644
index 0000000..9941e76
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataEntry.java
@@ -0,0 +1,87 @@
+/*
+ * 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.dataobjects;
+
+public class ThrottlingDataEntry {
+ String key;
+ String stringValue;
+ int intValue;
+ long longValue;
+ Object objectValue;
+
+ // here we are not using enums, as pojo services may not support that.
+ // 1 - String, 2 - Int, 3 - long, 4 - object
+ int valueType;
+
+ public ThrottlingDataEntry(String key) {
+ this.key = key;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getStringValue() {
+ return stringValue;
+ }
+
+ public void setStringValue(String stringValue) {
+ this.stringValue = stringValue;
+ valueType = 1;
+ }
+
+ public int getIntValue() {
+ return intValue;
+ }
+
+ public void setIntValue(int intValue) {
+ this.intValue = intValue;
+ valueType = 2;
+ }
+
+ public long getLongValue() {
+ return longValue;
+ }
+
+ public void setLongValue(long longValue) {
+ this.longValue = longValue;
+ valueType = 3;
+ }
+
+ public Object getObjectValue() {
+ return objectValue;
+ }
+
+ public void setObjectValue(Object objectValue) {
+ this.objectValue = objectValue;
+ valueType = 4;
+ }
+
+ public int getValueType() {
+ return valueType;
+ }
+
+ public void setValueType(int valueType) {
+ this.valueType = valueType;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataEntryConstants.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataEntryConstants.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataEntryConstants.java
new file mode 100644
index 0000000..2130287
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataobjects/ThrottlingDataEntryConstants.java
@@ -0,0 +1,44 @@
+/*
+ * 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.dataobjects;
+
+public class ThrottlingDataEntryConstants {
+
+ final public static String TENANT_INCOMING_BANDWIDTH = "tenantIncomingBandwidth";
+ final public static String TENANT_OUTGOING_BANDWIDTH = "tenantOutgoingBandwidth";
+
+ final public static String TENANT_CAPACITY = "tenantCapacity";
+ final public static String TENANT_HISTORY_CAPACITY = "tenantHistoryCapacity";
+
+ final public static String USERS_COUNT = "usersCount";
+
+ // some custom objects
+ final public static String CUSTOMER = "customer";
+ final public static String PACKAGE = "package";
+ final public static String USER_MANAGER = "userManager";
+ final public static String REGISTRY_INCOMING_BANDWIDTH = "registryIncomingBandwidth";
+ final public static String REGISTRY_OUTGOING_BANDWIDTH = "registryOutgoingBandwidth";
+ final public static String SERVICE_INCOMING_BANDWIDTH = "serviceIncomingBandwidth";
+ final public static String SERVICE_OUTGOING_BANDWIDTH = "serviceOutgoingBandwidth";
+ final public static String WEBAPP_INCOMING_BANDWIDTH = "webappIncomingBandwidth";
+ final public static String WEBAPP_OUTGOING_BANDWIDTH = "webappOutgoingBandwidth";
+ final public static String SERVICE_REQUEST_COUNT = "serviceRequestCount";
+ final public static String SERVICE_RESPONSE_COUNT = "serviceResponseCount";
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/BillingDataProvider.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/BillingDataProvider.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/BillingDataProvider.java
new file mode 100644
index 0000000..48994bf
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/BillingDataProvider.java
@@ -0,0 +1,55 @@
+/*
+ * 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.dataproviders;
+
+import org.apache.stratos.throttling.manager.dataobjects.ThrottlingDataContext;
+import org.apache.stratos.throttling.manager.dataobjects.ThrottlingDataEntryConstants;
+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.billing.core.dataobjects.Customer;
+import org.wso2.carbon.registry.core.exceptions.RegistryException;
+import org.wso2.carbon.billing.mgt.dataobjects.MultitenancyPackage;
+
+public class BillingDataProvider extends DataProvider {
+ private static Log log = LogFactory.getLog(BillingDataProvider.class);
+
+
+ public void invoke(ThrottlingDataContext dataContext) throws ThrottlingException {
+ int tenantId = dataContext.getTenantId();
+ try {
+ Customer customer = Util.getCurrentBillingCustomer(tenantId);
+ dataContext.addDataObject(ThrottlingDataEntryConstants.CUSTOMER, customer);
+ } catch (RegistryException e) {
+ String msg = "Error in getting the current customer. tenant id: " + tenantId + ".";
+ log.error(msg, e);
+ throw new ThrottlingException(msg, e);
+ }
+ // getting the package
+ try {
+ MultitenancyPackage mtPackage = Util.getCurrentBillingPackage(tenantId);
+ dataContext.addDataObject(ThrottlingDataEntryConstants.PACKAGE, mtPackage);
+ } catch (RegistryException e) {
+ String msg = "Error in getting the multi-tenancy package. tenant id: " + tenantId + ".";
+ log.error(msg, e);
+ throw new ThrottlingException(msg, e);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/DataProvider.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/DataProvider.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/DataProvider.java
new file mode 100644
index 0000000..0df2b12
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/DataProvider.java
@@ -0,0 +1,38 @@
+/*
+ * 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.dataproviders;
+
+import org.apache.stratos.throttling.manager.dataobjects.ThrottlingDataContext;
+import org.apache.stratos.throttling.manager.exception.ThrottlingException;
+
+import java.util.Map;
+
+public abstract class DataProvider {
+ Map<String, String> parameters;
+
+ public void init(Map<String, String> parameters) throws ThrottlingException {
+ this.parameters = parameters;
+ }
+
+ public Map<String, String> getParameters() {
+ return parameters;
+ }
+
+ public abstract void invoke(ThrottlingDataContext dataContext) throws ThrottlingException;
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/UsageDataProvider.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/UsageDataProvider.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/UsageDataProvider.java
new file mode 100644
index 0000000..de8b689
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/dataproviders/UsageDataProvider.java
@@ -0,0 +1,106 @@
+/*
+ * 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.dataproviders;
+
+import java.util.Calendar;
+
+import org.apache.stratos.throttling.manager.dataobjects.ThrottlingDataEntryConstants;
+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.apache.stratos.throttling.manager.dataobjects.ThrottlingDataContext;
+import org.apache.stratos.usage.beans.BandwidthStatistics;
+import org.apache.stratos.usage.beans.RequestStatistics;
+import org.apache.stratos.usage.api.TenantUsageRetriever;
+import org.apache.stratos.usage.beans.TenantUsage;
+
+/**
+ *
+ */
+public class UsageDataProvider extends DataProvider {
+ private static final Log log = LogFactory.getLog(UsageDataProvider.class);
+
+ @Override
+ public void invoke(ThrottlingDataContext dataContext) throws ThrottlingException {
+ int tenantId = dataContext.getTenantId();
+ String userName = dataContext.getUserName();
+ String yearMonth = Util.getCurrentMonthString(Calendar.getInstance());
+ TenantUsageRetriever tenantUsageRetriever = Util.getTenantUsageRetriever();
+
+ try {
+ TenantUsage usage = tenantUsageRetriever.getTenantUsage(tenantId, yearMonth);
+
+ //Bandwidth usages
+ long tenantIncomingBandwidth = usage.getTotalIncomingBandwidth();
+ long tenantOutgoingBandwidth = usage.getTotalOutgoingBandwidth();
+ dataContext.addDataLong(ThrottlingDataEntryConstants.TENANT_INCOMING_BANDWIDTH,
+ tenantIncomingBandwidth);
+ dataContext.addDataLong(ThrottlingDataEntryConstants.TENANT_OUTGOING_BANDWIDTH,
+ tenantOutgoingBandwidth);
+
+ //Registry space capacity
+ long currentTenantCapacity = usage.getRegistryContentCapacity();
+ long historyTenantCapacity = usage.getRegistryContentHistoryCapacity();
+ dataContext.addDataLong(ThrottlingDataEntryConstants.TENANT_CAPACITY,
+ currentTenantCapacity);
+ dataContext.addDataLong(ThrottlingDataEntryConstants.TENANT_HISTORY_CAPACITY,
+ historyTenantCapacity);
+ //Assigning registry bandwidths
+ BandwidthStatistics totalRgistryBW=usage.getTotalRegistryBandwidth();
+ dataContext.addDataLong(ThrottlingDataEntryConstants.REGISTRY_INCOMING_BANDWIDTH,
+ totalRgistryBW.getIncomingBandwidth());
+ dataContext.addDataLong(ThrottlingDataEntryConstants.REGISTRY_OUTGOING_BANDWIDTH,
+ totalRgistryBW.getOutgoingBandwidth());
+
+ //Assigning service bandwidths
+ BandwidthStatistics serviceBWStatistic=usage.getTotalServiceBandwidth();
+ dataContext.addDataLong(ThrottlingDataEntryConstants.SERVICE_INCOMING_BANDWIDTH,
+ serviceBWStatistic.getIncomingBandwidth());
+ dataContext.addDataLong(ThrottlingDataEntryConstants.SERVICE_OUTGOING_BANDWIDTH,
+ serviceBWStatistic.getOutgoingBandwidth());
+
+ //Assigning webapp bandwidths
+ BandwidthStatistics webappBWStatistic = usage.getTotalWebappBandwidth();
+ dataContext.addDataLong(ThrottlingDataEntryConstants.WEBAPP_INCOMING_BANDWIDTH,
+ webappBWStatistic.getIncomingBandwidth());
+ dataContext.addDataLong(ThrottlingDataEntryConstants.WEBAPP_OUTGOING_BANDWIDTH,
+ webappBWStatistic.getOutgoingBandwidth());
+
+ //Assigning service requests and response
+ RequestStatistics requestStat = usage.getTotalRequestStatistics();
+ dataContext.addDataLong(ThrottlingDataEntryConstants.SERVICE_REQUEST_COUNT,
+ requestStat.getRequestCount());
+ dataContext.addDataLong(ThrottlingDataEntryConstants.SERVICE_RESPONSE_COUNT,
+ requestStat.getResponseCount());
+
+ //Get number of users
+ int usersCount = usage.getNumberOfUsers();
+ dataContext.addDataInt(ThrottlingDataEntryConstants.USERS_COUNT, usersCount);
+
+ } catch (Exception e) {
+ String msg = "Error in retrieving Usage information. " + "tenant id: " + tenantId
+ + ", user name: " + userName + ".";
+ log.error(msg, e);
+ throw new ThrottlingException(msg, e);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/exception/ThrottlingException.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/exception/ThrottlingException.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/exception/ThrottlingException.java
new file mode 100644
index 0000000..681a253
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/exception/ThrottlingException.java
@@ -0,0 +1,28 @@
+/*
+ * 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.exception;
+
+public class ThrottlingException extends Exception{
+ public ThrottlingException(String msg, Exception e) {
+ super(msg, e);
+ }
+ public ThrottlingException(String msg) {
+ super(msg);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-stratos/blob/767082e3/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/internal/ThrottlingManagerServiceComponent.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/internal/ThrottlingManagerServiceComponent.java b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/internal/ThrottlingManagerServiceComponent.java
new file mode 100644
index 0000000..231e63b
--- /dev/null
+++ b/components/org.apache.stratos.throttling.manager/src/main/java/org/apache/stratos/throttling/manager/internal/ThrottlingManagerServiceComponent.java
@@ -0,0 +1,129 @@
+/*
+ * 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.internal;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.stratos.throttling.manager.utils.Util;
+import org.osgi.service.component.ComponentContext;
+import org.wso2.carbon.billing.core.BillingManager;
+import org.wso2.carbon.registry.core.service.RegistryService;
+import org.wso2.carbon.rule.kernel.config.RuleEngineConfigService;
+import org.wso2.carbon.user.core.service.RealmService;
+import org.wso2.carbon.billing.mgt.api.MultitenancyBillingInfo;
+import org.apache.stratos.usage.api.TenantUsageRetriever;
+
+/**
+ * @scr.component name="org.wso2.carbon.throttling.manager"
+ * immediate="true"
+ * @scr.reference name="registry.service"
+ * interface="org.wso2.carbon.registry.core.service.RegistryService" cardinality="1..1"
+ * policy="dynamic" bind="setRegistryService" unbind="unsetRegistryService"
+ * @scr.reference name="user.realmservice.default"
+ * interface="org.wso2.carbon.user.core.service.RealmService"
+ * cardinality="1..1" policy="dynamic" bind="setRealmService"
+ * unbind="unsetRealmService"
+ * @scr.reference name="billingManager.service"
+ * interface="org.wso2.carbon.billing.core.BillingManager" cardinality="1..1"
+ * policy="dynamic" bind="setBillingManager" unbind="unsetBillingManager"
+ * @scr.reference name="rule.engine.config.server.component"
+ * interface="org.wso2.carbon.rule.kernel.config.RuleEngineConfigService"
+ * cardinality="1..1"
+ * policy="dynamic" bind="setRuleEngineConfigService"
+ * unbind="unsetRuleEngineConfigService"
+ * @scr.reference name="metering.service"
+ * interface="org.apache.stratos.usage.api.TenantUsageRetriever" cardinality="1..1"
+ * policy="dynamic" bind="setTenantUsageRetriever" unbind="unsetTenantUsageRetriever"
+ * @scr.reference name="org.wso2.carbon.billing.mgt.api.MultitenancyBillingInfo"
+ * interface="org.wso2.carbon.billing.mgt.api.MultitenancyBillingInfo" cardinality="1..1"
+ * policy="dynamic" bind="setMultitenancyBillingInfo" unbind="unsetMultitenancyBillingInfo"
+ */
+public class ThrottlingManagerServiceComponent {
+ private static Log log = LogFactory.getLog(ThrottlingManagerServiceComponent.class);
+
+ protected void activate(ComponentContext context) {
+ try {
+ Util.setBundleContext(context.getBundleContext());
+ Util.loadThrottlingRules();
+ Util.registerThrottlingRuleInvoker();
+ Util.initializeThrottling();
+ log.debug(" Multitenancy Throttling Manager bundle is activated ");
+ } catch (Throwable e) {
+ log.error(" Multitenancy Throttling Manager bundle failed activating ", e);
+ }
+ }
+
+ protected void deactivate(ComponentContext context) {
+ log.debug("******* Multitenancy Throttling Manager bundle is deactivated ******* ");
+ }
+
+ protected void setRegistryService(RegistryService registryService) {
+ Util.setRegistryService(registryService);
+ }
+
+ protected void unsetRegistryService(RegistryService registryService) {
+ Util.setRegistryService(null);
+ }
+
+ protected void setRealmService(RealmService realmService) {
+ Util.setRealmService(realmService);
+ }
+
+ protected void unsetRealmService(RealmService realmService) {
+ Util.setRealmService(null);
+ }
+
+ protected void setBillingManager(BillingManager billingManager) {
+ log.debug("Receiving billingManager service");
+ Util.setBillingManager(billingManager);
+ }
+
+ protected void unsetBillingManager(BillingManager billingManager) {
+ log.debug("Halting billingManager service");
+ Util.setBillingManager(null);
+ }
+
+ protected void setRuleEngineConfigService(RuleEngineConfigService ruleEngineConfigService) {
+ Util.setRuleEngineConfigService(ruleEngineConfigService);
+ }
+
+ protected void unsetRuleEngineConfigService(RuleEngineConfigService ruleEngineConfigService) {
+ // we are not dynamically removing schedule helpers
+ }
+
+ protected void setTenantUsageRetriever(TenantUsageRetriever tenantUsageRetriever) {
+ log.debug("Setting Tenant Usage Retriever service");
+ Util.setTenantUsageRetriever(tenantUsageRetriever);
+ }
+
+ protected void unsetTenantUsageRetriever(TenantUsageRetriever tenantUsageRetriever) {
+ log.debug("Unsetting Tenant Usage Retriever service");
+ Util.setBillingManager(null);
+ }
+
+ protected void setMultitenancyBillingInfo(MultitenancyBillingInfo mtBillingInfo) {
+ log.debug("Setting MT billing info service");
+ Util.setMultitenancyBillingInfo(mtBillingInfo);
+ }
+
+ protected void unsetMultitenancyBillingInfo(MultitenancyBillingInfo mtBillingInfo) {
+ log.debug("Unsetting MT billing info service");
+ Util.setMultitenancyBillingInfo(null);
+ }
+}