Skip to content

Commit

Permalink
adding wso2de/-product-apim code base to wso2/product-apim
Browse files Browse the repository at this point in the history
  • Loading branch information
rswijesena committed Jan 26, 2015
1 parent 93ae1ee commit 6897f0f
Show file tree
Hide file tree
Showing 957 changed files with 168,611 additions and 0 deletions.
35 changes: 35 additions & 0 deletions config/BAM/bamClient/build.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<project name="BAMClient" default="clean" basedir=".">

<property name="client.class.dir" value="target/client/classes"/>

<target name="clean">
<delete dir="target"/>
</target>

<target name="init" depends="clean">
<mkdir dir="${client.class.dir}"/>
<mkdir dir="org.wso2.carbon.bam.client/lib" />
<path id="javac.bam.client.classpath">
<pathelement path="${client.class.dir}"/>
<fileset dir="./../repository/components/plugins"/>
<fileset dir="./../lib"/>
<fileset dir="./org.wso2.carbon.bam.client/lib"/>
</path>
</target>

<target name="compile_client" depends="init" description="Compile all Java">
<javac srcdir="org.wso2.carbon.bam.client/src" destdir="${client.class.dir}">
<classpath refid="javac.bam.client.classpath"/>
</javac>
</target>

<target name="initialize_column_family_datastore" depends="compile_client">
<java classname="org.wso2.carbon.bam.client.Client"
classpathref="javac.bam.client.classpath" fork="true">
<sysproperty key="bamUrl" value="https://localhost:9444/services/"/>
<sysproperty key="carbon.home" value="./.."/>
<sysproperty key="configFilePath" value="./org.wso2.carbon.bam.client/src/main/resources/"/>
</java>
</target>

</project>
50 changes: 50 additions & 0 deletions config/BAM/bamClient/org.wso2.carbon.bam.client/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.wso2.carbon.bam.client</groupId>
<artifactId>sample</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<name>sample</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.bam.analyzer.stub</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.bam.core.stub</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.bam.agent</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.bam2.service</artifactId>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.authenticator.stub</artifactId>
<version>4.0.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package org.wso2.carbon.bam.client;


import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.context.ServiceContext;
import org.apache.axis2.transport.http.HTTPConstants;
import org.wso2.carbon.analytics.hive.stub.HiveScriptStoreServiceHiveScriptStoreException;
import org.wso2.carbon.analytics.hive.stub.HiveScriptStoreServiceStub;
import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub;
import org.wso2.carbon.authenticator.stub.LoginAuthenticationExceptionException;
import org.wso2.carbon.utils.FileUtil;

import java.io.IOException;

public class Client {

private static String HIVE_SCRIPT_STORE_SERVICE = "HiveScriptStoreService";

private static HiveScriptStoreServiceStub hiveScriptStoreServiceStub;


public static void main(String[] args)
throws IOException,
LoginAuthenticationExceptionException {

String trustStore = System.getProperty("carbon.home") + "/repository/resources/security";
System.setProperty("javax.net.ssl.trustStore", trustStore + "/client-truststore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");


String authenticationServiceURL = getProperty("bamUrl") + "AuthenticationAdmin";
AuthenticationAdminStub authenticationAdminStub = new AuthenticationAdminStub(authenticationServiceURL);
ServiceClient client = authenticationAdminStub._getServiceClient();
Options options = client.getOptions();
options.setManageSession(true);

authenticationAdminStub.login("admin", "admin", "localhost");

ServiceContext serviceContext = authenticationAdminStub.
_getServiceClient().getLastOperationContext().getServiceContext();
String sessionCookie = (String) serviceContext.getProperty(HTTPConstants.COOKIE_STRING);

String hiveScriptStoreServiceURL = getProperty("bamUrl") + HIVE_SCRIPT_STORE_SERVICE;
hiveScriptStoreServiceStub = new HiveScriptStoreServiceStub(hiveScriptStoreServiceURL);

ServiceClient hiveScriptStoreServiceStubClient = hiveScriptStoreServiceStub._getServiceClient();
Options hiveScriptStoreServiceStubOption = hiveScriptStoreServiceStubClient.getOptions();
hiveScriptStoreServiceStubOption.setManageSession(true);
hiveScriptStoreServiceStubOption.setProperty(org.apache.axis2.transport.http.HTTPConstants.COOKIE_STRING, sessionCookie);

String apiVersionUsageSummaryContent = FileUtil.readFileToString(System.getProperty("configFilePath") +
"APIVersionUsageSummaryScript.hiveql");
String apiVersionKeyUsageSummaryContent = FileUtil.readFileToString( System.getProperty("configFilePath") +
"APIVersionKeyUsageSummaryScript.hiveql");
String apiVersionKeyLastAccessSummaryContent = FileUtil.readFileToString( System.getProperty("configFilePath") +
"APIVersionKeyLastAccessSummaryScript.hiveql");
String apiVersionServiceTimeSummaryContent = FileUtil.readFileToString( System.getProperty("configFilePath") +
"APIVersionServiceTimeSummaryScript.hiveql");
String keyUsageSummaryContent = FileUtil.readFileToString( System.getProperty("configFilePath") +
"KeyUsageSummaryScript.hiveql");



try {

hiveScriptStoreServiceStub.saveHiveScript("APIVersionUsageSummaryScript",apiVersionUsageSummaryContent,"1 * * * * ? *");
hiveScriptStoreServiceStub.saveHiveScript("APIVersionKeyUsageSummaryScript",apiVersionKeyUsageSummaryContent,"1 * * * * ? *");
hiveScriptStoreServiceStub.saveHiveScript("APIVersionKeyLastAccessSummaryScript",apiVersionKeyLastAccessSummaryContent,"1 * * * * ? *");
hiveScriptStoreServiceStub.saveHiveScript("APIVersionServiceTimeSummaryScript",apiVersionServiceTimeSummaryContent,"1 * * * * ? *");
hiveScriptStoreServiceStub.saveHiveScript("KeyUsageSummaryScript",keyUsageSummaryContent,"1 * * * * ? *");
System.out.println("BAM configured successfully for collecting API stats");
return;

} catch (HiveScriptStoreServiceHiveScriptStoreException e) {
e.printStackTrace();
}


}

private static String getProperty(String bamUrl) {
String defaultVal = "https://localhost:9443/services/";
String result = System.getProperty(bamUrl);
if (result == null || result.length() == 0) {
result = defaultVal;
}
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
CREATE EXTERNAL TABLE IF NOT EXISTS APIVersionKeyLastAccess (key STRING,
api_version
STRING,consumerKey STRING,userId STRING,
context STRING,requestTime STRING) STORED BY
'org.apache.hadoop.hive.cassandra.CassandraStorageHandler' WITH SERDEPROPERTIES ( "cassandra.host" =
"127.0.0.1",
"cassandra.port" = "9161","cassandra.ks.name" = "EVENT_KS",
"cassandra.ks.username"
= "admin","cassandra.ks.password" = "admin",
"cassandra.cf.name" =
"org_wso2_apimgt_statistics_request",
"cassandra.columns.mapping" =
":key,payload_api_version,
payload_consumerKey,payload_userId,payload_context,
payload_requestTime"
);
CREATE EXTERNAL TABLE IF NOT EXISTS APIVersionKeyLastAccessSummary (api_version STRING,
consumerKey STRING,userId STRING,context STRING,
requestTime DOUBLE) STORED BY
'org.wso2.carbon.hadoop.hive.jdbc.storage.JDBCStorageHandler' TBLPROPERTIES ( 'wso2.carbon.datasource.name'='WSO2AM_STATS_DB',
'hive.jdbc.update.on.duplicate' = 'true',
'hive.jdbc.table.create.query' = 'CREATE TABLE APIVersionKeyLastAccessSummary (api_version
VARCHAR(100),
consumerKey VARCHAR(100),userId VARCHAR(100),
context VARCHAR(100),requestTime
DOUBLE)' );
insert overwrite table APIVersionKeyLastAccessSummary select api_version,
consumerKey,userId,context,max(cast(requestTime as DOUBLE)) from APIVersionKeyLastAccess group
by api_version,
consumerKey,userId,context;


Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE EXTERNAL TABLE IF NOT EXISTS KeyUsage (key STRING,
context STRING,consumerKey
STRING,userId STRING,
version STRING,request STRING) STORED BY
'org.apache.hadoop.hive.cassandra.CassandraStorageHandler' WITH SERDEPROPERTIES ( "cassandra.host" =
"127.0.0.1",
"cassandra.port" = "9161","cassandra.ks.name" = "EVENT_KS",
"cassandra.ks.username"
= "admin","cassandra.ks.password" = "admin",
"cassandra.cf.name" =
"org_wso2_apimgt_statistics_request",
"cassandra.columns.mapping" =
":key,payload_context,
payload_consumerKey,payload_userId,payload_version,
payload_request" );
CREATE EXTERNAL TABLE IF NOT EXISTS KeyUsageSummary (context STRING,
consumerKey STRING,userId
STRING,version STRING,
request INT) STORED BY
'org.wso2.carbon.hadoop.hive.jdbc.storage.JDBCStorageHandler' TBLPROPERTIES ( 'wso2.carbon.datasource.name'='WSO2AM_STATS_DB',
'hive.jdbc.update.on.duplicate' = 'true',
'hive.jdbc.table.create.query' = 'CREATE TABLE KeyUsageSummary (context
VARCHAR(100),
consumerKey VARCHAR(100),userId VARCHAR(100),
version VARCHAR(100),request INT)' );
insert overwrite table KeyUsageSummary select context,
consumerKey,userId,version,sum(cast(request as INT)) from KeyUsage group by context,
consumerKey,userId,version;


Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
CREATE EXTERNAL TABLE IF NOT EXISTS APIVersionServiceTime (key STRING,
api_version
STRING,context STRING,serviceTime STRING,
response STRING) STORED BY
'org.apache.hadoop.hive.cassandra.CassandraStorageHandler' WITH SERDEPROPERTIES ( "cassandra.host" =
"127.0.0.1",
"cassandra.port" = "9161","cassandra.ks.name" = "EVENT_KS",
"cassandra.ks.username"
= "admin","cassandra.ks.password" = "admin",
"cassandra.cf.name" =
"org_wso2_apimgt_statistics_response",
"cassandra.columns.mapping" =
":key,payload_api_version,
payload_context,payload_serviceTime,payload_response" );
CREATE EXTERNAL TABLE IF NOT EXISTS APIVersionServiceTimeSummary (api_version STRING,
context
STRING,serviceTime INT,response INT) STORED BY
'org.wso2.carbon.hadoop.hive.jdbc.storage.JDBCStorageHandler' TBLPROPERTIES ( 'wso2.carbon.datasource.name'='WSO2AM_STATS_DB',
'hive.jdbc.update.on.duplicate' = 'true',
'hive.jdbc.table.create.query' = 'CREATE TABLE APIVersionServiceTimeSummary (api_version
VARCHAR(100),
context VARCHAR(100),serviceTime INT,response INT)' );
insert overwrite table APIVersionServiceTimeSummary select api_version,
context,avg(cast(serviceTime as INT)),sum(cast(response as INT)) from APIVersionServiceTime
group by api_version,
context;


Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CREATE EXTERNAL TABLE IF NOT EXISTS APIVersionUsage (key STRING,
api STRING,version
STRING,context STRING,
request STRING) STORED BY
'org.apache.hadoop.hive.cassandra.CassandraStorageHandler' WITH SERDEPROPERTIES ( "cassandra.host" =
"127.0.0.1",
"cassandra.port" = "9161","cassandra.ks.name" = "EVENT_KS",
"cassandra.ks.username"
= "admin","cassandra.ks.password" = "admin",
"cassandra.cf.name" =
"org_wso2_apimgt_statistics_request",
"cassandra.columns.mapping" =
":key,payload_api,
payload_version,payload_context,payload_request" );
CREATE EXTERNAL TABLE IF NOT EXISTS APIVersionUsageSummary (api STRING,
version STRING,context
STRING,request INT) STORED BY 'org.wso2.carbon.hadoop.hive.jdbc.storage.JDBCStorageHandler' TBLPROPERTIES
('wso2.carbon.datasource.name'='WSO2AM_STATS_DB',
'hive.jdbc.update.on.duplicate' = 'true',
'hive.jdbc.table.create.query' = 'CREATE TABLE APIVersionUsageSummary (api
VARCHAR(100),
version VARCHAR(100),context VARCHAR(100),
request INT)' );
insert overwrite table APIVersionUsageSummary select api,
version,context,sum(cast(request as
INT)) from APIVersionUsage group by api,
version,context;


Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
CREATE EXTERNAL TABLE IF NOT EXISTS APIVersionKeyUsage (key STRING,
api STRING,version
STRING,consumerKey STRING,
userId STRING,request STRING) STORED BY
'org.apache.hadoop.hive.cassandra.CassandraStorageHandler' WITH SERDEPROPERTIES ( "cassandra.host" =
"127.0.0.1",
"cassandra.port" = "9161","cassandra.ks.name" = "EVENT_KS",
"cassandra.ks.username"
= "admin","cassandra.ks.password" = "admin",
"cassandra.cf.name" =
"org_wso2_apimgt_statistics_request",
"cassandra.columns.mapping" =
":key,payload_api,
payload_version,payload_consumerKey,payload_userId,
payload_request" );
CREATE EXTERNAL TABLE IF NOT EXISTS APIVersionKeyUsageSummary (api STRING,
version
STRING,consumerKey STRING,userId STRING,
request DOUBLE) STORED BY
'org.wso2.carbon.hadoop.hive.jdbc.storage.JDBCStorageHandler' TBLPROPERTIES ( 'wso2.carbon.datasource.name'='WSO2AM_STATS_DB',
'hive.jdbc.update.on.duplicate' = 'true',
'hive.jdbc.table.create.query' = 'CREATE TABLE APIVersionKeyUsageSummary (api
VARCHAR(100),
version VARCHAR(100),consumerKey VARCHAR(100),
userId VARCHAR(100),request DOUBLE)' );
insert overwrite table APIVersionKeyUsageSummary select api,
version,consumerKey,userId,sum(cast(request as DOUBLE)) from APIVersionKeyUsage group by api,
version,consumerKey,userId;


Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<APIManager>
<Database>
<URL>jdbc:h2:target/repository/database/WSO2AM_DB</URL>
<Username>wso2carbon</Username>
<Password>wso2carbon</Password>
<Driver>org.h2.Driver</Driver>
<maxActive>50</maxActive>
<maxWait>60000</maxWait>
<minIdle>5</minIdle>
</Database>
<APIUsageTracking>
<Enabled>false</Enabled>
<ThriftPort>7612</ThriftPort>
<BAMServerURL>https://localhost:9444/</BAMServerURL>
<BAMUsername>admin</BAMUsername>
<BAMPassword>admin</BAMPassword>
<BAMTrustStore>repository/resources/security/client-truststore.jks</BAMTrustStore>
<BAMTrustStorePassword>wso2carbon</BAMTrustStorePassword>
</APIUsageTracking>
<APIKeyManager>
<ServerURL>https://localhost:9443/services/</ServerURL>
<Username>admin</Username>
<Password>admin</Password>
</APIKeyManager>
<APIGateway>
<ServerURL>https://localhost:9443/services/</ServerURL>
<Username>admin</Username>
<Password>admin</Password>
</APIGateway>
</APIManager>
Loading

0 comments on commit 6897f0f

Please sign in to comment.