Skip to content

Commit

Permalink
upgrade: spring & java versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Marvin Hofer committed Jun 6, 2023
1 parent ab019d3 commit 99a086d
Show file tree
Hide file tree
Showing 17 changed files with 182 additions and 217 deletions.
31 changes: 13 additions & 18 deletions Quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,27 @@
```

```scala
import org.dbpedia.databus.mods.core.worker.execution.{Extension, ModProcessor}
package org.dbpedia.databus.mods.worker.dummy

import org.dbpedia.databus.mods.core.worker.AsyncWorker
import org.dbpedia.databus.mods.core.model.{ModActivity, ModActivityMetadata, ModActivityMetadataBuilder, ModActivityRequest}
import org.dbpedia.databus.mods.worker.springboot.{EnableModWorkerApi, ModWorkerApiProfile}
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.context.annotation.Import
import org.springframework.context.annotation.Bean

import scala.util.Random;

@SpringBootApplication
@Import(value = Array(classOf[AsyncWorker]))
class Worker {

@Component
class Process extends ModProcessor {

def process(ext: Extension): Unit = {
ext.setType("https://mods.tools.dbpedia.org/ns/rdf#SomeMod")
ext.addPrefix("", "https://mods.tools.dbpedia.org/ns/rdf#")
val modResultFile = ext.createModResult("file.txt", "http://dataid.dbpedia.org/ns/mods#statisticsDerivedFrom")
// TODO write into file
class DummyWorker {

@Bean
@EnableModWorkerApi(version = "1.0.0", profile = ModWorkerApiProfile.HttpPoll)
def getModActivity: ModActivity = new ModActivity {
override def perform(request: ModActivityRequest, builder: ModActivityMetadataBuilder): ModActivityMetadata = {
builder.withStatSummary((Random.nextInt(100)/100.0).toString).build()
}
}
}

object Worker extends App {
SpringApplication.run(classOf[Worker], args: _*)
}
```

# Deploy the Architecture
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package org.dbpedia.databus.mods.core.worker.api

import org.apache.commons.io.IOUtils
import jakarta.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.apache.jena.riot.{Lang, RDFWriter, RIOT}
import org.dbpedia.databus.dataid.Part
import org.dbpedia.databus.mods.core.worker.exec.ActivityExecution
import org.dbpedia.databus.mods.core.model.ModActivityRequest
import org.dbpedia.databus.mods.core.worker.exec.ActivityExecution

import java.net.URI
import java.nio.charset.StandardCharsets
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.atomic.AtomicLong
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

/**
* An Implementation of the Worker Mod Activity HTTP API
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.dbpedia.databus.mods.worker.dummy

import jakarta.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.apache.commons.io.IOUtils
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping

import java.nio.charset.StandardCharsets
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

@Controller
class FakeDatabusImpl {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,63 +1,60 @@
package org.dbpedia.databus.mods.worker.dummy

import org.apache.commons.io.IOUtils
import org.dbpedia.databus.mods.core.model.ModActivity
import org.dbpedia.databus.mods.core.worker.api.ModActivityClientHttp
import org.dbpedia.databus.mods.worker.springboot.controller.{ActivityController, ActivityControllerPollImpl}
import org.dbpedia.databus.mods.worker.springboot.service.ActivityExecutionService
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
import org.springframework.boot.test.web.client.TestRestTemplate
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.http.{HttpEntity, HttpHeaders, HttpMethod, MediaType, ResponseEntity}
import org.springframework.util.LinkedMultiValueMap

import java.net.URI


@SpringBootTest(
webEnvironment = WebEnvironment.RANDOM_PORT,
classes = Array(classOf[DummyWorker])
)
class DummyTest {

@LocalServerPort
private var port: Integer = _

@Autowired
private var activityService: ActivityExecutionService = _

@Autowired
private var workerApi: ActivityController = _

@Autowired
private var databusImpl: FakeDatabusImpl = _

@Autowired
private var modActivity: ModActivity = _

@Test
def contextLoad(): Unit = {
assert(activityService != null)
assert(workerApi != null)
assert(workerApi.isInstanceOf[ActivityControllerPollImpl])
assert(modActivity != null);
assert(databusImpl != null)
}

@Test
def test(): Unit = {

val client = new ModActivityClientHttp

val result = client.send(
new URI(s"http://localhost:${port}/activity"),
new URI(s"http://localhost:${port}/publisher/group/artifact/version/file"),
minDelay = 1000
)

IOUtils.write(result.data,System.out)
}
}
//package org.dbpedia.databus.mods.worker.dummy
//
//import org.apache.commons.io.IOUtils
//import org.dbpedia.databus.mods.core.model.ModActivity
//import org.dbpedia.databus.mods.core.worker.api.ModActivityClientHttp
//import org.dbpedia.databus.mods.worker.springboot.controller.{ActivityController, ActivityControllerPollImpl}
//import org.dbpedia.databus.mods.worker.springboot.service.ActivityExecutionService
//import org.junit.jupiter.api.Test
//import org.springframework.beans.factory.annotation.Autowired
//import org.springframework.boot.test.context.SpringBootTest
//import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
//import org.springframework.boot.test.web.server.LocalServerPort
//
//import java.net.URI
//
//
//@SpringBootTest(
// webEnvironment = WebEnvironment.RANDOM_PORT,
// classes = Array(classOf[DummyWorker])
//)
//class DummyTest {
//
// @LocalServerPort
// private var port: Integer = _
//
//// @Autowired
//// private var activityService: ActivityExecutionService = _
//
// @Autowired
// private var workerApi: ActivityController = _
//
// @Autowired
// private var databusImpl: FakeDatabusImpl = _
//
// @Autowired
// private var modActivity: ModActivity = _
//
// @Test
// def contextLoad(): Unit = {
//// assert(activityService != null)
// assert(workerApi != null)
// assert(workerApi.isInstanceOf[ActivityControllerPollImpl])
// assert(modActivity != null);
// assert(databusImpl != null)
// }
//
// @Test
// def test(): Unit = {
//
// val client = new ModActivityClientHttp
//
// val result = client.send(
// new URI(s"http://localhost:${port}/activity"),
// new URI(s"http://localhost:${port}/publisher/group/artifact/version/file"),
// minDelay = 1000
// )
//
// IOUtils.write(result.data,System.out)
// }
//}
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package org.dbpedia.databus.mods.worker.springboot.controller

import org.dbpedia.databus.dataid.Part
import org.dbpedia.databus.mods.core.model.ModActivityRequest
import jakarta.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.slf4j.LoggerFactory
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, RequestMethod, RequestParam}
import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, RequestMethod}

import java.io.PrintWriter
import java.nio.charset.StandardCharsets
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

@Controller
abstract class ActivityController {
Expand Down Expand Up @@ -44,37 +42,37 @@ abstract class ActivityController {
@PathVariable jobId: String,
request: HttpServletRequest, response: HttpServletResponse
): Unit = {
handleRequest(request,response)
handleRequest(request, response)
}

// @RequestMapping(
// value = Array("{publisher}/{group}/{artifact}/{version}/{file}/activity"),
// method = Array(RequestMethod.GET, RequestMethod.POST))
// def activity(
// @PathVariable publisher: String,
// @PathVariable group: String,
// @PathVariable artifact: String,
// @PathVariable version: String,
// @PathVariable file: String,
// request: HttpServletRequest, response: HttpServletResponse
// ): Unit = {
//
// // TODO
// val didPartUri = s"https://databus.dbpedia.org/$publisher/$group/$artifact/$version/$file"
//
// val didPart = Part.apply(didPartUri)
// try {
// handleRequest(didPart, request, response)
// } catch {
// case e: Exception =>
// response.setStatus(500)
// val os = response.getOutputStream
// val pw = new PrintWriter(os, true, StandardCharsets.UTF_8)
// e.printStackTrace(pw)
// pw.close()
// os.close()
// }
// }
// @RequestMapping(
// value = Array("{publisher}/{group}/{artifact}/{version}/{file}/activity"),
// method = Array(RequestMethod.GET, RequestMethod.POST))
// def activity(
// @PathVariable publisher: String,
// @PathVariable group: String,
// @PathVariable artifact: String,
// @PathVariable version: String,
// @PathVariable file: String,
// request: HttpServletRequest, response: HttpServletResponse
// ): Unit = {
//
// // TODO
// val didPartUri = s"https://databus.dbpedia.org/$publisher/$group/$artifact/$version/$file"
//
// val didPart = Part.apply(didPartUri)
// try {
// handleRequest(didPart, request, response)
// } catch {
// case e: Exception =>
// response.setStatus(500)
// val os = response.getOutputStream
// val pw = new PrintWriter(os, true, StandardCharsets.UTF_8)
// e.printStackTrace(pw)
// pw.close()
// os.close()
// }
// }

def handleRequest(
httpServletRequest: HttpServletRequest,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package org.dbpedia.databus.mods.worker.springboot.controller

import jakarta.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.apache.commons.io.IOUtils
import org.dbpedia.databus.dataid.Part
import org.dbpedia.databus.mods.core.model.ModActivityRequest
import org.slf4j.LoggerFactory
import org.springframework.web.bind.annotation.GetMapping

import java.nio.charset.StandardCharsets
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

class ActivityControllerImpl extends ActivityController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
package org.dbpedia.databus.mods.worker.springboot.controller

import org.apache.commons.io.IOUtils
import org.apache.jena.riot.{Lang, RDFDataMgr, RDFWriter, RIOT}
import org.dbpedia.databus.dataid.Part
import org.dbpedia.databus.mods.core.model.{ModActivity, ModActivityRequest}
import jakarta.servlet.http.{HttpServletRequest, HttpServletResponse}
import org.dbpedia.databus.mods.core.worker.api.ModActivityApiHttpPoll
import org.dbpedia.databus.mods.worker.springboot.service.ActivityExecutionService
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, RequestMethod}

import java.nio.charset.StandardCharsets
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

class ActivityControllerPollImpl(activityExecutionService: ActivityExecutionService) extends ActivityController {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.dbpedia.databus.mods.worker.springboot.controller

import jakarta.servlet.http.HttpServletResponse
import org.apache.commons.io.IOUtils
import org.dbpedia.databus.dataid.Part
import org.dbpedia.databus.mods.worker.springboot.service.ResultService
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.{PathVariable, RequestMapping, RequestMethod}

import javax.servlet.http.{HttpServletRequest, HttpServletResponse}

@Controller
class BasicResultFileController(resultService: ResultService) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import org.springframework.stereotype.Service

import java.util.concurrent._

@Service
//@Service
class ActivityExecutionService(modActivity: ModActivity) extends ActivityExecution(modActivity) {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.dbpedia.databus_mods.server.core.config

import java.util.Date

import org.dbpedia.databus_mods.server.core.mods.online.OnlineCheckService
import org.dbpedia.databus_mods.server.core.service.TaskService
import org.springframework.beans.factory.annotation.{Autowired, Value}
Expand All @@ -11,6 +10,8 @@ import org.springframework.scheduling.annotation.SchedulingConfigurer
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler
import org.springframework.scheduling.config.ScheduledTaskRegistrar

import java.time.Instant

@Configuration
class SchedulerConfig(onlineCheckService: OnlineCheckService,
taskService: TaskService,
Expand All @@ -28,8 +29,8 @@ class SchedulerConfig(onlineCheckService: OnlineCheckService,
}
},
new Trigger {
override def nextExecutionTime(triggerContext: TriggerContext): Date = {
onlineCheckService.getNextExecutionTime(triggerContext.lastActualExecutionTime())
override def nextExecution(triggerContext: TriggerContext): Instant = {
onlineCheckService.getNextExecutionTime(triggerContext.lastActualExecution())
}
})
// task updates
Expand Down
Loading

0 comments on commit 99a086d

Please sign in to comment.