Skip to content

Commit

Permalink
#99 core examples in a subfolder - s3 examples self-standing, too.
Browse files Browse the repository at this point in the history
  • Loading branch information
dk1844 committed Jul 30, 2021
1 parent ece7aaf commit cdce13f
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 17 deletions.
119 changes: 105 additions & 14 deletions examples/s3-sdk-extension-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,89 @@
<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>za.co.absa</groupId>
<artifactId>atum-examples-s3-sdk-extension_2.11</artifactId>
<packaging>jar</packaging>
<version>0.0.1-SNAPSHOT</version>

<parent>
<groupId>za.co.absa</groupId>
<artifactId>atum-parent_2.11</artifactId>
<version>4.0.0-SNAPSHOT</version>
</parent>
<packaging>jar</packaging>

<properties>
<scalastyle.configLocation>${project.basedir}/../../scalastyle-config.xml</scalastyle.configLocation>
<atum.version>4.0.0-SNAPSHOT</atum.version>

<!-- Cross Compilation Properties -->
<default.scala.binary.version>2.11</default.scala.binary.version>
<default.scala.version>${scala_2.11.version}</default.scala.version>

<scala_2.11.version>2.11.12</scala_2.11.version>
<scala_2.12.version>2.12.12</scala_2.12.version>

<!-- Spark versions -->
<spark-24.version>2.4.6</spark-24.version>
<spark-31.version>3.1.2</spark-31.version>

<spark.version>${spark-24.version}</spark.version>

<!-- Controlled by `scala-cross-build` plugin -->
<scala.version>2.11.12</scala.version>
<scala.binary.version>2.11</scala.binary.version>

<!-- Build and plugins properties -->
<scalatest.maven.plugin.version>2.0.2</scalatest.maven.plugin.version>
<maven.shade.plugin.version>2.3</maven.shade.plugin.version>

<scala.maven.plugin.version>3.2.0</scala.maven.plugin.version>
<maven.source.plugin.version>3.0.1</maven.source.plugin.version>

<!-- Frameworks and libraries -->
<commons.version>0.0.27</commons.version>
<scalatest.version>3.2.2</scalatest.version>

</properties>

<dependencies>
<!-- Scala -->
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
<scope>provided</scope>
</dependency>

<!-- Atum -->
<dependency>
<groupId>za.co.absa</groupId>
<artifactId>atum-s3-sdk-extension_${scala.binary.version}</artifactId>
<version>${atum.version}</version>
</dependency>

<!-- spark -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>za.co.absa</groupId>
<artifactId>atum-examples_${scala.binary.version}</artifactId>
<version>${atum.version}</version>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>provided</scope>
</dependency>

<!-- Commons -->
<dependency>
<groupId>za.co.absa.commons</groupId>
<artifactId>commons_${scala.binary.version}</artifactId>
<version>${commons.version}</version>
<scope>provided</scope>
</dependency>

<!-- Scalatest -->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.binary.version}</artifactId>
<version>${scalatest.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

Expand All @@ -54,19 +112,44 @@
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<!-- the Maven Scala plugin -->
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>${scala.maven.plugin.version}</version>
<configuration>
<checkMultipleScalaVersions>false</checkMultipleScalaVersions>
<recompileMode>incremental</recompileMode>
<args>
<arg>-Xfatal-warnings</arg>
<arg>-unchecked</arg>
<arg>-deprecation</arg>
<arg>-feature</arg>
</args>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>${scalatest.maven.version}</version>
<version>${scalatest.maven.plugin.version}</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>

<!-- Uber jar generation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.version}</version>
<version>${maven.shade.plugin.version}</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -76,10 +159,18 @@
</execution>
</executions>
</plugin>

<!-- scala cross build -->
<plugin>
<groupId>org.scalastyle</groupId>
<artifactId>scalastyle-maven-plugin</artifactId>
<groupId>com.github.wajda</groupId>
<artifactId>scala-cross-build-maven-plugin</artifactId>
<version>0.2.1</version>
<configuration>
<defaultScalaBinaryVersion>${default.scala.binary.version}</defaultScalaBinaryVersion>
<defaultScalaVersion>${default.scala.version}</defaultScalaVersion>
</configuration>
</plugin>

</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object SampleSdkS3Measurements1 {
def main(args: Array[String]) {
val sparkBuilder = SparkSession.builder().appName("Sample S3 Measurements 1 Job")
val spark = sparkBuilder
// .master("local")
// .master("local") // use this when running locally
.getOrCreate()

import spark.implicits._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ object SampleSdkS3Measurements2 {
// This example is intended to run AFTER SampleMeasurements1, otherwise it will fail on input file absence

val sparkBuilder = SparkSession.builder().appName("Sample Measurements 2 Job")
//val spark = sparkBuilder.master("local").getOrCreate()
val spark = sparkBuilder.getOrCreate()
val spark = sparkBuilder
// .master("local") // use this when running locally
.getOrCreate()

import spark.implicits._

val hadoopConfiguration = spark.sparkContext.hadoopConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright 2018-2019 ABSA Group Limited
*
* Licensed 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 za.co.absa.atum.utils

import org.scalatest.funsuite.AnyFunSuiteLike
import scala.language.reflectiveCalls

import scala.reflect.ClassTag
import scala.reflect.runtime.universe

trait SparkJobRunnerMethods {
this: AnyFunSuiteLike =>

private def runSparkJob[T](implicit ct: ClassTag[T]): Unit = {
type MainClass = {def main(args: Array[String]): Unit}

val jobClass = ct.runtimeClass
val jobClassSymbol = universe.runtimeMirror(jobClass.getClassLoader).classSymbol(jobClass)
val jobInstance =
if (jobClassSymbol.isModuleClass) {
jobClass.getField("MODULE$").get(jobClass)
} else {
jobClass.getDeclaredConstructor().newInstance()
}

jobInstance.asInstanceOf[MainClass].main(Array.empty)
}

def runSparkJobAsTest[T](implicit ct: ClassTag[T]): Unit = {
val sampleName = ct.runtimeClass.getSimpleName
test(sampleName)(runSparkJob[T](ct))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2018 ABSA Group Limited
*
* Licensed 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 za.co.absa.atum.utils

trait SparkLocalMaster {
System.getProperties.setProperty("spark.master", "local[*]")

// in order to runSampleMeasuremts as tests, otherwise
// java.lang.IllegalArgumentException: System memory 259522560 must be at least 471859200... is thrown
System.getProperties.setProperty("spark.testing.memory", (1024*1024*1024).toString) // 1g
}

0 comments on commit cdce13f

Please sign in to comment.