Commit 82bb206b authored by Szabolcs Gyurko's avatar Szabolcs Gyurko
Browse files

Upgraded to scala 2.12 and fixed the SQLite connection issues

parent 839bbd0e
Pipeline #308 failed with stage
in 10 minutes and 20 seconds
package actors
import java.sql.Timestamp
import javax.inject.{Inject, Singleton}
import akka.actor.UntypedActor
import akka.actor.UntypedAbstractActor
import entities.{ChunkRecord, ChunksTable, JobsTable, QueueTable}
import play.api.Logger
import javax.inject.{Inject, Singleton}
import org.slf4j.LoggerFactory
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import sget2.{Defaults, PersistEvent, SGet2}
import slick.driver.JdbcProfile
import slick.jdbc.JdbcProfile
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
......@@ -19,8 +19,9 @@ import scala.concurrent.duration.Duration
*/
@Singleton
class DataPersister @Inject() (protected val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2)
extends UntypedActor with HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
extends UntypedAbstractActor with HasDatabaseConfigProvider[JdbcProfile] {
import profile.api._
private val Logger = LoggerFactory.getLogger(getClass)
@volatile
private var saveRequested: Boolean = false
......@@ -56,16 +57,15 @@ class DataPersister @Inject() (protected val dbConfigProvider: DatabaseConfigPro
} else {
Logger.trace(s"scheduling a persist in ${Defaults.PERSIST_FREQUENCY - (currentTime - lastSave)}ms")
saveRequested = true
akka.pattern.after(Duration(Defaults.PERSIST_FREQUENCY - (currentTime - lastSave), "ms"), sget2.actorSystem.scheduler)(Future.successful(p)).onSuccess {
case e: PersistEvent
akka.pattern.after(Duration(Defaults.PERSIST_FREQUENCY - (currentTime - lastSave), "ms"), sget2.actorSystem.scheduler)(Future.successful(p)).onComplete { t
t.foreach { e
Logger.trace("persist() by schedule")
this.synchronized {
persist(e)
lastSave = System.currentTimeMillis()
saveRequested = false
}
case _
Logger.trace("God knows what this rubbish is")
}
}
}
}
......
package actors
import akka.actor.UntypedAbstractActor
import javax.inject.{Inject, Singleton}
import akka.actor.UntypedActor
import play.api.Logger
import org.slf4j.LoggerFactory
import sget2.{JobFinishedEvent, SGet2}
/**
* Created by sgyurko on 25/08/2016.
*/
@Singleton
class QueueManager @Inject() (private val sget2: SGet2) extends UntypedActor {
class QueueManager @Inject() (private val sget2: SGet2) extends UntypedAbstractActor {
private val Logger = LoggerFactory.getLogger(getClass)
@scala.throws[Throwable](classOf[Throwable])
override def onReceive(message: Any): Unit = {
......
package controllers
import javax.inject.Inject
import entities.{JobRecord, JobsTable, QueueRecord, QueueTable}
import play.api.Logger
import javax.inject.Inject
import org.slf4j.LoggerFactory
import play.api.data.Form
import play.api.data.Forms._
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.i18n.I18nSupport
import play.api.libs.json.{JsResult, Json}
import play.api.mvc.{Action, Controller, Result}
import play.api.mvc._
import sget2.{Defaults, DownloadJob, DownloadJobStatusCode, SGet2}
import slick.driver.JdbcProfile
import slick.jdbc.JdbcProfile
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
......@@ -21,11 +20,12 @@ import scala.concurrent.Future
*/
final case class AddJobData(url: String, path: String, user: Option[String] = None, pass: Option[String] = None, maxThreads: Option[Int] = Some(4), maxBandwidth: Option[Int] = None)
class AddJob @Inject() (val messagesApi: MessagesApi, protected val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends Controller with I18nSupport with HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
class AddJob @Inject() (val controllerComponents: ControllerComponents, protected val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends BaseController with I18nSupport with HasDatabaseConfigProvider[JdbcProfile] {
import profile.api._
private val jobs = TableQuery[JobsTable]
private val queue = TableQuery[QueueTable]
private val Logger = LoggerFactory.getLogger(getClass)
private val addPostForm = Form(
mapping(
......@@ -39,7 +39,7 @@ class AddJob @Inject() (val messagesApi: MessagesApi, protected val dbConfigProv
)
/* GET for the HTML form */
def index() = Action {
def index() = Action { implicit request
val settings = sget2.settings
var pass: Option[String] = None
......
package controllers
import javax.inject.Inject
import entities.{ChunksTable, JobsTable, QueueTable}
import javax.inject.Inject
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.i18n.I18nSupport
import play.api.libs.json.Json
import play.api.mvc.{Action, Controller}
import play.api.mvc.{BaseController, ControllerComponents}
import sget2.{DownloadObjectMapSettings, SGet2}
import slick.driver.JdbcProfile
import slick.jdbc.JdbcProfile
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
......@@ -20,14 +19,14 @@ final case class JobJson(state: String, currentSpeed: Double, lastCheck: Long, p
bandwidthLimit: Int, startTime: Long, finishTime: Long, size: Long, alive: Boolean, activeThreads: Int,
url: String, path: String, id: Int, downloaded: Long, chunkMatrix: DownloadObjectMapSettings)
class Job @Inject() (val messagesApi: MessagesApi, protected val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends Controller with I18nSupport with HasDatabaseConfigProvider[JdbcProfile]{
import driver.api._
class Job @Inject() (val controllerComponents: ControllerComponents, protected val dbConfigProvider: DatabaseConfigProvider, private val sget2: SGet2) extends BaseController with I18nSupport with HasDatabaseConfigProvider[JdbcProfile]{
import profile.api._
private val jobs = TableQuery[JobsTable]
private val queue = TableQuery[QueueTable]
private val chunks = TableQuery[ChunksTable]
def json(id: Int) = Action {
def json(id: Int) = Action { implicit request
implicit val jobWrites = Json.writes[JobJson]
val jobOption = sget2.downloadQueue.job(id)
if (jobOption.nonEmpty) {
......@@ -41,7 +40,7 @@ class Job @Inject() (val messagesApi: MessagesApi, protected val dbConfigProvide
}
}
def pause(id: Int) = Action {
def pause(id: Int) = Action { implicit request
val jobOption = sget2.downloadQueue.job(id)
if (jobOption.nonEmpty) {
sget2.downloadQueue.stop(id)
......@@ -51,7 +50,7 @@ class Job @Inject() (val messagesApi: MessagesApi, protected val dbConfigProvide
}
}
def start(id: Int) = Action {
def start(id: Int) = Action { implicit request
val jobOption = sget2.downloadQueue.job(id)
if (jobOption.nonEmpty) {
sget2.downloadQueue.start(id)
......
package controllers
import javax.inject.Inject
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller}
import play.api.i18n.I18nSupport
import play.api.mvc.{BaseController, ControllerComponents}
import sget2.SGet2
/**
* Created by sgyurko on 30/08/2016.
*/
class Queue @Inject() (val messagesApi: MessagesApi, val sget2: SGet2) extends Controller with I18nSupport {
class Queue @Inject() (val controllerComponents: ControllerComponents, val sget2: SGet2) extends BaseController with I18nSupport {
def index = Action {
def index = Action { implicit request
Ok(views.html.queue(sget2.downloadQueue.jobList))
}
def js = Action {
def js = Action { implicit request
Ok(views.js.queue()).as("text/javascript")
}
def home = Action {
def home = Action { implicit request
Redirect(routes.Queue.index())
}
}
......@@ -3,11 +3,11 @@ package controllers
import java.util.concurrent.TimeUnit
import io.netty.util.{HashedWheelTimer, Timeout, TimerTask}
import play.api.Logger
import org.slf4j.LoggerFactory
import scala.concurrent.duration.Duration
import scala.concurrent.{ExecutionContext, Future, Promise, TimeoutException}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.Duration
import scala.concurrent.{Future, Promise, TimeoutException}
/**
......@@ -16,6 +16,7 @@ import scala.concurrent.ExecutionContext.Implicits.global
* Mixin trait for additional Future handling
*/
trait SGetAsync {
private val Logger = LoggerFactory.getLogger(getClass)
def withErrorHandling[T](f: Future[T], fallback: T): Future[T] = {
f.recover {
case t
......@@ -32,7 +33,7 @@ trait SGetAsync {
}
}
def withTimeout[T](fut: Future[T], after: Duration)(implicit ec:ExecutionContext): Future[T] = {
def withTimeout[T](fut: Future[T], after: Duration): Future[T] = {
val prom = Promise[T]()
val timer = new HashedWheelTimer(10, TimeUnit.MILLISECONDS)
......
package controllers
import javax.inject.Inject
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.{I18nSupport, MessagesApi}
import play.api.mvc.{Action, Controller}
import play.api.i18n.I18nSupport
import play.api.mvc.{BaseController, ControllerComponents}
import sget2.{Defaults, SGet2}
import scala.concurrent.ExecutionContext.Implicits.global
......@@ -16,7 +15,7 @@ import scala.util.Try
*/
final case class SettingsModel(downloadPath: Option[String],
maxActiveJobs: Option[Int], user: Option[String], pass: Option[String])
class Settings @Inject() (val messagesApi: MessagesApi, private val sget2: SGet2) extends Controller with I18nSupport {
class Settings @Inject() (val controllerComponents: ControllerComponents, private val sget2: SGet2) extends BaseController with I18nSupport {
private val settingsPostForm = Form(
mapping(
"downloadPath" optional(text),
......@@ -26,7 +25,7 @@ class Settings @Inject() (val messagesApi: MessagesApi, private val sget2: SGet2
)(SettingsModel.apply)(SettingsModel.unapply)
)
def index = Action {
def index = Action { implicit request
Ok(views.html.settings(settingsPostForm.fill(getSettings)))
}
......
package entities
import slick.driver.SQLiteDriver.api._
import slick.jdbc.SQLiteProfile.api._
import slick.lifted.Tag
/**
* Created by sgyurko on 26/08/2016.
......
......@@ -3,7 +3,7 @@ package entities
import java.sql.Timestamp
import java.util.Date
import slick.driver.SQLiteDriver.api._
import slick.jdbc.SQLiteProfile.api._
import slick.lifted.Tag
/**
* Created by sgyurko on 26/08/2016.
......
......@@ -3,7 +3,7 @@ package entities
import java.sql.Timestamp
import java.util.Date
import slick.driver.SQLiteDriver.api._
import slick.jdbc.SQLiteProfile.api._
import slick.lifted.Tag
/**
......
package entities
import slick.driver.SQLiteDriver.api._
import slick.jdbc.SQLiteProfile.api._
import slick.lifted.Tag
/**
* Created by sgyurko on 26/08/2016.
......
package sget2
import play.api.Logger
import org.slf4j.LoggerFactory
import scala.io.Codec
......@@ -13,6 +13,7 @@ import scala.io.Codec
abstract class AbstractWorker(protected val downloadJob: DownloadJob, protected val sget2: SGet2) extends Worker {
protected implicit val codec = Codec("ISO-8859-1")
private val threadGroup = new ThreadGroup(downloadJob.id.toString)
private val Logger = LoggerFactory.getLogger(getClass)
/**
* Generic worker logic implementation
......
......@@ -2,7 +2,7 @@ package sget2
import java.io.{InputStream, RandomAccessFile}
import play.api.Logger
import org.slf4j.LoggerFactory
import scala.io.Codec
......@@ -12,6 +12,7 @@ import scala.io.Codec
*/
abstract class AbstractWorkerThread(downloadJob: DownloadJob, slot: (Long, Long))(implicit val codec: Codec) extends Runnable {
protected def downloadBlock(file: RandomAccessFile)
private val Logger = LoggerFactory.getLogger(getClass)
/**
* Implements default download logic, which is seeking in the downloaded artifact and downloading a block.
......
......@@ -3,7 +3,7 @@ package sget2
import java.io.{File, IOException, RandomAccessFile}
import java.net.URL
import play.api.Logger
import org.slf4j.LoggerFactory
import play.api.libs.json.Json
import sget2.DownloadJobStatusCode.DownloadJobStatusCode
......@@ -34,6 +34,7 @@ sealed case class DownloadJobSettings( chunkMatrix: DownloadObjectMapSettings,
*/
class DownloadJob (private var _url: URL, private var _path: String)(implicit private val sget2: SGet2) {
private var targetFileInitialized: Boolean = false
private val Logger = LoggerFactory.getLogger(getClass)
var chunkMatrix: DownloadObjectMap = new DownloadObjectMap
var lastSpeed: (Double, Double) = (0, 0)
var lastCheck: (Long, Long) = (0, 0)
......
package sget2
import entities.{ChunkRecord, ChunksTable, JobsTable, QueueTable}
import play.api.Logger
import org.slf4j.LoggerFactory
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.driver.JdbcProfile
import slick.jdbc.JdbcProfile
import workers.{FtpWorker, HttpWorker}
import scala.collection.mutable.ListBuffer
......@@ -18,7 +18,8 @@ case class DownloadQueueSettings(jobList: List[DownloadJobSettings],
* @author GYURKS
*/
class DownloadQueue (private val sget2: SGet2, protected val dbConfigProvider: DatabaseConfigProvider) extends HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
import profile.api._
private val Logger = LoggerFactory.getLogger(getClass)
val jobList = new ListBuffer[DownloadJob]()
private var _bandwidthLimit: Int = 0
......
......@@ -5,7 +5,7 @@ import javax.inject.{Inject, Singleton}
import akka.actor.{ActorRef, ActorSystem}
import entities.{SettingsRecord, SettingsTable}
import play.api.db.slick.{DatabaseConfigProvider, HasDatabaseConfigProvider}
import slick.driver.JdbcProfile
import slick.jdbc.JdbcProfile
import scala.concurrent.Await
import scala.concurrent.duration.Duration
......@@ -15,7 +15,7 @@ import scala.concurrent.duration.Duration
*/
@Singleton
class SGet2 @Inject() (protected val dbConfigProvider: DatabaseConfigProvider, val actorSystem: ActorSystem) extends HasDatabaseConfigProvider[JdbcProfile] {
import driver.api._
import profile.api._
private val eventBus = new SGet2EventBus
val downloadQueue = new DownloadQueue(this, dbConfigProvider)
......
package sget2
import javax.inject.{Inject, Named, Singleton}
import akka.actor.ActorRef
import play.api.Logger
import javax.inject.{Inject, Named, Singleton}
import org.slf4j.LoggerFactory
import play.api.inject.ApplicationLifecycle
import scala.concurrent.ExecutionContext.Implicits.global
......@@ -16,6 +15,7 @@ import scala.concurrent.Future
class SGet2Startup @Inject() (private val sget2: SGet2, val lifecycle: ApplicationLifecycle,
@Named("DataPersister") private val persister: ActorRef,
@Named("QueueManager") private val queueManager: ActorRef) {
private val Logger = LoggerFactory.getLogger(getClass)
Logger.info("Starting SGet2")
......
@(formData: Form[AddJobData])(implicit messages: Messages)
@(formData: Form[AddJobData])(implicit messages: Messages, request: RequestHeader)
@import views.html.helper.CSRF
<html>
<head>
<title>@{Messages("addjob.title")}</title>
......@@ -10,6 +12,7 @@
<div id="mainContent">
<span class="queueLink"><a href="@routes.Queue.index()">@{Messages("addjob.backToQueue")}</a></span>
<form action="@routes.AddJob.addJobPost()" method="post">
@CSRF.formField
<table class="addJobTable">
<thead class="addJobTableHeader">
<tr>
......
@(settings: Form[SettingsModel])(implicit messages: Messages)
@(settings: Form[SettingsModel])(implicit messages: Messages, request: RequestHeader)
@import views.html.helper.CSRF
<html>
<head>
<title>@{Messages("settings.title")}</title>
......@@ -8,6 +10,7 @@
<div id="mainContent">
<span class="queueLink"><a href="@routes.Queue.index()">@{Messages("settings.backToQueue")}</a></span>
<form action="@routes.Settings.save()" method="post">
@CSRF.formField
<table class="settingsTable">
<thead class="settingsTableHeader">
<th colspan="2" class="settingsHeader">@{Messages("settings.header")}</th>
......
......@@ -4,7 +4,7 @@ import java.io.RandomAccessFile
import java.net.URL
import org.apache.commons.net.ftp.{FTP, FTPClient}
import play.api.Logger
import org.slf4j.LoggerFactory
import sget2.{AbstractWorker, AbstractWorkerThread, DownloadJob, SGet2}
/**
......@@ -13,6 +13,7 @@ import sget2.{AbstractWorker, AbstractWorkerThread, DownloadJob, SGet2}
*/
class FtpWorker (override protected val downloadJob: DownloadJob,
override protected val sget2: SGet2) extends AbstractWorker(downloadJob, sget2) {
private val Logger = LoggerFactory.getLogger(getClass)
/**
* FTP specific file size retrieval using the LIST method.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment