-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from dilannm/master
add all features from mig india
- Loading branch information
Showing
421 changed files
with
222,400 additions
and
1,444 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>org.wso2telco.analytics.sparkUdf</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.jdt.core.javabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
<buildCommand> | ||
<name>org.eclipse.m2e.core.maven2Builder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
<nature>org.eclipse.m2e.core.maven2Nature</nature> | ||
</natures> | ||
</projectDescription> |
3 changes: 3 additions & 0 deletions
3
components/org.wso2telco.analytics.sparkUdf/.settings/org.eclipse.core.resources.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
eclipse.preferences.version=1 | ||
encoding//src/main/java=UTF-8 | ||
encoding//src/test/java=UTF-8 |
5 changes: 5 additions & 0 deletions
5
components/org.wso2telco.analytics.sparkUdf/.settings/org.eclipse.jdt.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 | ||
org.eclipse.jdt.core.compiler.compliance=1.7 | ||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning | ||
org.eclipse.jdt.core.compiler.source=1.7 |
4 changes: 4 additions & 0 deletions
4
components/org.wso2telco.analytics.sparkUdf/.settings/org.eclipse.m2e.core.prefs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<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> | ||
|
||
|
||
<parent> | ||
<groupId>org.wso2telco.analytics</groupId> | ||
<artifactId>org.wso2telco.analytics.ids</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<relativePath>../../pom.xml</relativePath> | ||
</parent> | ||
|
||
|
||
<artifactId>org.wso2telco.analytics.sparkUdf</artifactId> | ||
<packaging>bundle</packaging> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.felix</groupId> | ||
<artifactId>maven-scr-plugin</artifactId> | ||
<version>1.8.0</version> | ||
<executions> | ||
<execution> | ||
<id>generate-scr-descriptor</id> | ||
<goals> | ||
<goal>scr</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
</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> | ||
<Import-Package> | ||
org.wso2.carbon.analytics.spark.core.*, | ||
*;resolution:=optional | ||
</Import-Package> | ||
<DynamicImport-Package>*</DynamicImport-Package> | ||
</instructions> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
|
||
</build> | ||
|
||
|
||
|
||
|
||
</project> |
134 changes: 134 additions & 0 deletions
134
...2telco.analytics.sparkUdf/src/main/java/org/wso2telco/analytics/sparkUdf/DateTimeUDF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* | ||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. | ||
* | ||
* WSO2 Inc. 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.wso2telco.analytics.sparkUdf; | ||
|
||
import java.text.DateFormat; | ||
import java.text.ParseException; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
public class DateTimeUDF { | ||
|
||
|
||
/** | ||
* Returns the string daterime for the long to which the timestamp belongs to. | ||
* Ex: for a long timstamp value for 3/4/2016 12:33:22 it would return the string 2016-04-03 12:33:22 am | ||
* @param timestamp timestamp in milliseconds. | ||
* @return string value of the date. | ||
* @throws ParseException | ||
*/ | ||
public String getFormattedTimeString(Long timestamp) throws ParseException { | ||
if(timestamp!=null){ | ||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aa"); | ||
return dateFormat.format(new Date(timestamp)); | ||
}else{ | ||
return null; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Returns the string date for the month to which the timestamp belongs to. | ||
* Ex: for a long timstamp value for 3/4/2016 12:33:22 it would return the string 2016-4 | ||
* @param timestamp timestamp in milliseconds. | ||
* @return string value of the date. | ||
* @throws ParseException | ||
*/ | ||
public String getMonthString(Long timestamp) throws ParseException { | ||
if(timestamp!=null){ | ||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM"); | ||
return dateFormat.format(new Date(timestamp)); | ||
}else{ | ||
return null; | ||
} | ||
} | ||
|
||
|
||
/** | ||
* Returns the long value for the date to which the timestamp belongs to. | ||
* Ex: for a long timstamp value for 3/4/2016 12:33:22 it would return the long timstamp value for the date | ||
* 3/4/2016 00:00:00. | ||
* | ||
* @param timestamp timestamp in milliseconds. | ||
* @return long timestamp value for the date it belongs to. | ||
* @throws ParseException | ||
*/ | ||
public Long getDateTimestamp(Long timestamp) throws ParseException { | ||
if(timestamp!=null){ | ||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
String dateString = dateFormat.format(new Date(timestamp)); | ||
Date processedDate = dateFormat.parse(dateString); | ||
return processedDate.getTime(); | ||
}else{ | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the long value for the Month to which the timestamp belongs to. | ||
* Ex: for a long timstamp value for 3/4/2016 12:33:22 it would return the long timstamp value for the date | ||
* 3/1/2016 00:00:00. | ||
* | ||
* @param timestamp timestamp in milliseconds. | ||
* @return long timestamp value for the date it belongs to. | ||
* @throws ParseException | ||
*/ | ||
public Long getMonthTimestamp(Long timestamp) throws ParseException { | ||
if(timestamp!=null){ | ||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM"); | ||
String dateString = dateFormat.format(new Date(timestamp)); | ||
Date processedDate = dateFormat.parse(dateString); | ||
return processedDate.getTime(); | ||
}else{ | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the string date for the day to which the timestamp belongs to. | ||
* Ex: for a long timstamp value for 3/4/2016 12:33:22 it would return the string 2016-4-3 | ||
* @param timestamp timestamp in milliseconds. | ||
* @return string value of the date. | ||
* @throws ParseException | ||
*/ | ||
public String getDateString(Long timestamp) throws ParseException { | ||
if(timestamp!=null){ | ||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
return dateFormat.format(new Date(timestamp)); | ||
}else{ | ||
return null; | ||
} | ||
} | ||
|
||
/** | ||
* Returns the long timestamp for the given date | ||
* @param dateString date of the format yyyy-mm-dd | ||
* @return timestamp in milliseconds | ||
* @throws ParseException | ||
*/ | ||
public Long getTimestampForDate(String dateString) throws ParseException { | ||
if(dateString!=null){ | ||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); | ||
Date processedDate = dateFormat.parse(dateString); | ||
return processedDate.getTime(); | ||
}else{ | ||
return null; | ||
} | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
....wso2telco.analytics.sparkUdf/src/main/java/org/wso2telco/analytics/sparkUdf/IPRange.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package org.wso2telco.analytics.sparkUdf; | ||
|
||
import java.net.InetAddress; | ||
import java.net.UnknownHostException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class IPRange { | ||
|
||
public Boolean checkIpRange(String min, String max, String xForward){ | ||
Boolean status=false; | ||
if(min !=null && max !=null && xForward !=null){ | ||
List<String> ipList = Arrays.asList(xForward.split(",")); | ||
for(String ip : ipList){ | ||
try { | ||
if(InetAddress.getByName(min)!=null && InetAddress.getByName(max)!=null){ | ||
long ipLo = ipToLong(InetAddress.getByName(min)); | ||
long ipHi = ipToLong(InetAddress.getByName(max)); | ||
if(InetAddress.getByName(ip.trim())!=null){ | ||
long ipToTest = ipToLong(InetAddress.getByName(ip.trim())); | ||
if (ipToTest >= ipLo && ipToTest <= ipHi){ | ||
status=true; | ||
} | ||
} | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
} | ||
return status; | ||
} | ||
|
||
public static long ipToLong(InetAddress ip) throws Exception{ | ||
byte[] octets = ip.getAddress(); | ||
long result = 0; | ||
for (byte octet : octets) { | ||
result <<= 8; | ||
result |= octet & 0xff; | ||
} | ||
return result; | ||
} | ||
} |
Oops, something went wrong.