Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#38 http client and config #73

Merged
merged 5 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ _productMT
_nestedStructs
myTestCheckpoints

**/main/resources/application.properties
benedeki marked this conversation as resolved.
Show resolved Hide resolved
**/main/resources/application.conf
**/main/resources/application.yaml
**/main/resources/application.yml

*.config
*.keytab
Expand Down
18 changes: 18 additions & 0 deletions agent/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2021 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.

# dispatcher to be used (http or console)
atum.dispatcher.type="http"

# The REST API URI of the atum server
#atum.dispatcher.http.url=
cerveada marked this conversation as resolved.
Show resolved Hide resolved
21 changes: 15 additions & 6 deletions agent/src/main/scala/za/co/absa/atum/agent/AtumAgent.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,27 @@

package za.co.absa.atum.agent

import com.typesafe.config.{Config, ConfigFactory}
import za.co.absa.atum.agent.dispacther.{ConsoleDispatcher, HttpDispatcher}
import za.co.absa.atum.agent.model.MeasureResult

/**
* Place holder for the agent that communicate with the API.
* Place holder for the agent that communicate with the API.
*/
object AtumAgent {

def measurePublish(checkpointKey: String, measure: MeasureResult): Unit =
println(s"Enqueued measurement: $checkpointKey, " + (measure))
val config: Config = ConfigFactory.load()

def publish(checkpointKey: String, context: AtumContext, measureResult: MeasureResult): Unit = println(
Seq(checkpointKey, context, measureResult).mkString(" || ")
)
private val dispatcher = config.getString("atum.dispatcher.type") match {
case "http" => new HttpDispatcher(config.getConfig("atum.dispatcher.http"))
case "console" => new ConsoleDispatcher
case dt => throw new UnsupportedOperationException(s"Unsupported dispatcher type: '$dt''")
}

def measurePublish(checkpointKey: String, measureResult: MeasureResult): Unit =
dispatcher.publish(checkpointKey, measureResult)

def publish(checkpointKey: String, context: AtumContext, measureResult: MeasureResult): Unit =
dispatcher.publish(checkpointKey, context, measureResult)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2021 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.agent.dispacther

import com.typesafe.config.Config
import org.apache.spark.internal.Logging
import za.co.absa.atum.agent.AtumContext
import za.co.absa.atum.agent.model.MeasureResult

/**
* dispatcher useful for development, testing and debugging
*/
class ConsoleDispatcher extends Dispatcher with Logging {

logInfo("using console dispatcher")

override def publish(checkpointKey: String, measureResult: MeasureResult): Unit =
println(s"Publishing $checkpointKey $measureResult")

override def publish(checkpointKey: String, context: AtumContext, measureResult: MeasureResult): Unit =
println(s"Publishing $checkpointKey $context $measureResult")

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2021 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.agent.dispacther
cerveada marked this conversation as resolved.
Show resolved Hide resolved

import za.co.absa.atum.agent.AtumContext
import za.co.absa.atum.agent.model.MeasureResult

trait Dispatcher {
def publish(checkpointKey: String, measureResult: MeasureResult): Unit

def publish(checkpointKey: String, context: AtumContext, measureResult: MeasureResult): Unit
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright 2021 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.agent.dispacther

import com.typesafe.config.Config
import org.apache.spark.internal.Logging
import za.co.absa.atum.agent.model.MeasureResult
import sttp.client3._
import sttp.model.Uri
import za.co.absa.atum.agent.AtumContext

class HttpDispatcher(config: Config) extends Dispatcher with Logging {

private val serverUri = Uri.unsafeParse(config.getString("url"))
private val backend = HttpURLConnectionBackend()

logInfo("using http dispatcher")
logInfo(s"serverUri $serverUri")

override def publish(checkpointKey: String, measureResult: MeasureResult): Unit = {
basicRequest
.body(s"$checkpointKey $measureResult")
.post(serverUri)
.send(backend)
}

override def publish(checkpointKey: String, context: AtumContext, measureResult: MeasureResult): Unit = {
basicRequest
.body(s"$checkpointKey $context $measureResult")
.post(serverUri)
.send(backend)
}
}
14 changes: 14 additions & 0 deletions agent/src/test/resources/application.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2021 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.

atum.dispatcher.type="console"
25 changes: 11 additions & 14 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ object Dependencies {
springBootTest % Test,
springBootWeb,
springBootConfiguration,
springBootTomcat /*% Provided*/,
servletApi /*% Provided*/,
springBootTomcat /*% Provided*/ ,
servletApi /*% Provided*/ ,
springFoxSwagger,
springFoxSwaggerUI,
springFoxBoot,
Expand All @@ -72,22 +72,19 @@ object Dependencies {

def agentDependencies(sparkVersion: String): Seq[ModuleID] = {

val typesafeVersion = "1.4.2"
val typesafeVersion = "1.4.2"
val sparkCommonsVersion = "0.6.0"
val sparkMinorVersion = getVersionUpToMinor(sparkVersion)
val specs2CoreVersion = "4.19.2"
val sparkMinorVersion = getVersionUpToMinor(sparkVersion)
val specs2CoreVersion = "4.19.2"

Seq(
"org.apache.spark" %% "spark-core" % sparkVersion % Provided,
"org.apache.spark" %% "spark-sql" % sparkVersion % Provided,
"com.typesafe" % "config" % typesafeVersion,
"za.co.absa" %% s"spark-commons-spark${sparkMinorVersion}" % sparkCommonsVersion,
"za.co.absa" %% "spark-commons-test" % sparkCommonsVersion % Test,
"org.apache.spark" %% "spark-core" % sparkVersion % Provided,
"org.apache.spark" %% "spark-sql" % sparkVersion % Provided,
"com.typesafe" % "config" % typesafeVersion,
"za.co.absa" %% s"spark-commons-spark${sparkMinorVersion}" % sparkCommonsVersion,
"com.softwaremill.sttp.client3" %% "core" % "3.5.2",
"za.co.absa" %% "spark-commons-test" % sparkCommonsVersion % Test
)

}

}



Loading