Skip to content

Commit

Permalink
merge code v1.4.17
Browse files Browse the repository at this point in the history
  • Loading branch information
nkthien committed Nov 4, 2022
1 parent eadc62e commit 5cf98b1
Show file tree
Hide file tree
Showing 89 changed files with 815 additions and 441 deletions.
2 changes: 1 addition & 1 deletion bi-service/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
cd libs/ && ./install.sh && cd ..

mvn clean package && docker build --no-cache -t datainsiderco/bi-service:oss .
mvn clean package && docker build --no-cache -t datainsiderco/bi-service:main .
4 changes: 1 addition & 3 deletions bi-service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3'
services:
bi_service:
image: datainsiderco/bi-service:oss
image: datainsiderco/bi-service:main
container_name: rocket-bi-service
restart: always
environment:
Expand All @@ -14,8 +14,6 @@ services:
CLICKHOUSE_USERNAME: default
CLICKHOUSE_PASSWORD: ""
CLICKHOUSE_CLUSTER_NAME: ""
ports:
- "8080:8080"
volumes:
- ./conf:/app/conf
- ./logs:/app/logs
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion bi-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@
<dependency>
<groupId>datainsider</groupId>
<artifactId>clients</artifactId>
<version>2.2.29</version>
<version>2.2.31</version>
</dependency>

<dependency>
Expand Down
6 changes: 3 additions & 3 deletions bi-service/src/main/scala/co/datainsider/bi/Server.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import co.datainsider.bi.controller.http.filter.{
CORSFilter,
CaseClassExceptionMapping,
CommonExceptionMapping,
JsonParseExceptionMapping,
LicenceFilter
JsonParseExceptionMapping
}
import co.datainsider.bi.controller.thrift.TBIServiceController
import co.datainsider.bi.module.{AccessFilterModule, BIServiceModule, TestModule}
Expand All @@ -24,8 +23,9 @@ import com.twitter.finatra.thrift.ThriftServer
import com.twitter.finatra.thrift.routing.ThriftRouter
import com.twitter.util.Await
import datainsider.client.exception.DbExecuteError
import datainsider.client.filter.{LoggedInUserParser, MustLoggedInFilter}
import datainsider.client.filter.{LicenceFilter, LoggedInUserParser, MustLoggedInFilter}
import datainsider.client.module.{CaasClientModule, MockCaasClientModule, MockSchemaClientModule, SchemaClientModule}
import datainsider.licence.module.LicenceClientModule

/**
* Created by SangDang on 9/8/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import co.datainsider.bi.domain.Directory.{MyData, Shared}
import co.datainsider.bi.domain.Ids.DirectoryId
import co.datainsider.bi.domain.query.event.{ActionType, ResourceType}
import co.datainsider.bi.domain.request._
import co.datainsider.bi.service.{DashboardFieldService, DashboardService, DirectoryService, RecentDirectoryService}
import co.datainsider.share.domain.response.PageResult
import co.datainsider.bi.service.{DashboardFieldService, DashboardService, DirectoryService}
import com.google.inject.Inject
import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.http.Request
import com.twitter.finatra.http.Controller
import com.twitter.util.Future
import datainsider.authorization.filters.{DashboardAccessFilters, WidgetAccessFilters}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ import com.twitter.finatra.http.response.ResponseBuilder
import com.twitter.finatra.jackson.caseclass.exceptions.CaseClassMappingException
import com.twitter.inject.Logging
import datainsider.client.exception.{DIErrorReason, DIException}

import javax.inject.Inject
import scala.util.Try

/**
* @author anhlt
*/
* @author anhlt
*/
@Singleton
class CommonExceptionMapping @Inject() (
response: ResponseBuilder
) extends ExceptionMapper[Throwable]
with Logging {
response: ResponseBuilder
) extends ExceptionMapper[Throwable]
with Logging {
override def toResponse(request: Request, ex: Throwable): Response = {
logError(ex)
val error = ex match {
Expand All @@ -26,7 +29,7 @@ class CommonExceptionMapping @Inject() (
e.getStatus.code,
e.reason,
e.getMessage,
None
Try(e.getCause.getMessage).toOption
)
case _ =>
ApiError(
Expand All @@ -42,11 +45,12 @@ class CommonExceptionMapping @Inject() (
error(s"${ex.getClass.getName}: ${ex.getMessage}", ex)
}
}

@Singleton
class CaseClassExceptionMapping @Inject() (
response: ResponseBuilder
) extends ExceptionMapper[CaseClassMappingException]
with Logging {
response: ResponseBuilder
) extends ExceptionMapper[CaseClassMappingException]
with Logging {
override def toResponse(request: Request, throwable: CaseClassMappingException): Response = {
error("", throwable)
response.badRequest.json(
Expand All @@ -60,9 +64,9 @@ class CaseClassExceptionMapping @Inject() (
}
@Singleton
class JsonParseExceptionMapping @Inject() (
response: ResponseBuilder
) extends ExceptionMapper[JsonParseException]
with Logging {
response: ResponseBuilder
) extends ExceptionMapper[JsonParseException]
with Logging {
override def toResponse(request: Request, ex: JsonParseException): Response = {
error(s"JsonParseExceptionMapping: ${ex.getMessage}", ex)
response.badRequest.json(
Expand All @@ -73,4 +77,4 @@ class JsonParseExceptionMapping @Inject() (
)
)
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package co.datainsider.bi.controller.http.filter

import com.twitter.finagle.http.{Request, Response}
import com.twitter.finagle.{Service, SimpleFilter}
import com.twitter.inject.Logging
import com.twitter.util.Future
import datainsider.client.filter.UserContext.UserContextSyntax
import datainsider.client.util.ZConfig
import datainsider.licence.exception.LicenceExpiredError
import datainsider.licence.service.LicenceClientService

import java.sql.Date
import java.text.SimpleDateFormat
import java.time.Duration
import javax.inject.Inject

class LicenceServerFilter @Inject() (licenceClientService: LicenceClientService)
extends SimpleFilter[Request, Response]
with Logging {
val dateFormat = new SimpleDateFormat("dd MM yyyy HH:mm:ss Z")
override def apply(request: Request, service: Service[Request, Response]): Future[Response] = {
try {
// val licenceKey = request.currentOrganization.get.licenceKey.get
val timeOfMonthMillis: Long = Duration.ofDays(30).toMillis
val timeOfDayMillis: Long = Duration.ofDays(1).toMillis

require(request.currentOrganization.get.licenceKey.isDefined)

for {
licence <- licenceClientService.get(request.currentOrganization.get.licenceKey.get)
response <- service(request)
} yield {
val terminatedTimeMillis = licence.expiredAt + timeOfMonthMillis
val terminatedDate = new Date(terminatedTimeMillis)
if (terminatedTimeMillis < System.currentTimeMillis()) {
throw LicenceExpiredError(s"Your license was terminated ${dateFormat.format(terminatedDate)}")
}

if (licence.expiredAt < System.currentTimeMillis()) {
val withinDays: Long = (terminatedTimeMillis - System.currentTimeMillis()) / timeOfDayMillis
response.headerMap.add(
ZConfig.getString("licence.field_name"),
s"Your license is expired. Please make sure to charge for your license before ${dateFormat
.format(terminatedDate)}/ within ${withinDays} days. Otherwise, your service will be terminated."
)
}
response
}
} catch {
case e: Throwable =>
logger.error(s"LicenceFilter::apply ${e.getMessage}", e)
service(request)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ case class SqlQuery(
TableExpressionUtils.findFromClause(query).map(resp => TableView(resp._1, resp._2))
} catch {
case e: Throwable =>
error(s"find dbName.tblName failed with exception: ${e}")
error(s"allQueryViews::find dbName.tblName failed with exception", e)
Seq.empty
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,26 +184,26 @@ class SqlBuilder(sqlParser: SqlParser) {
*/
private def buildFromClause(): String = {
if (joinFields.nonEmpty) {
var fromClause = getSqlView(joinFields(0).leftViewName) // init
var curView = getSqlView(joinFields(0).leftViewName) // init
val knownViews = mutable.Set[String](joinFields(0).leftViewName)

joinFields.foreach(join => {
var notChanged = true

if (!knownViews.contains(join.leftViewName)) {
fromClause += s"\n ${join.joinType.toString} join ${getSqlView(join.leftViewName)} on ${join.conditionStr}"
curView += s"\n ${join.joinType.toString} join ${getSqlView(join.leftViewName)} on ${join.conditionStr}"
knownViews += join.leftViewName
notChanged = false
} else if (!knownViews.contains(join.rightViewName)) {
fromClause += s"\n ${join.joinType.toString} join ${getSqlView(join.rightViewName)} on ${join.conditionStr}"
curView += s"\n ${join.joinType.toString} join ${getSqlView(join.rightViewName)} on ${join.conditionStr}"
knownViews += join.rightViewName
notChanged = false
}

if (notChanged) throw BadRequestError("invalid join clause")
})

fromClause
curView

} else {
if (fromFields.size > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class ClickhouseEngine @Inject() (@Named("clickhouse") client: JdbcClient) exten
DataTable(colNames, colTypes, rows.toArray)
})
} catch {
case e: SQLException => throw DbExecuteError(e.getMessage)
case e: SQLException => throw DbExecuteError(s"execute sql '$sql' failed with exception: $e")
case e: Throwable => throw InternalError(s"engine.execute failed with exception: $e")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ object ClickhouseParser extends SqlParser {
case None => toValueStr(value, fieldType)
}
} catch {
case e: Throwable => throw UnsupportedError(s"fail to parse $value to sql")
case e: Throwable => throw UnsupportedError(s"fail to parse $value to sql", e)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import com.twitter.finatra.jackson.ScalaObjectMapper
import com.twitter.inject.Logging

case class ApiError(
code: Int,
reason: String,
message: String,
data: Option[Any] = None
)
code: Int,
reason: String,
message: String,
cause: Option[String] = None
)

class CustomResponseWriterImpl @Inject()(
mapper: ScalaObjectMapper
) extends DefaultMessageBodyWriter
with Logging {
class CustomResponseWriterImpl @Inject() (
mapper: ScalaObjectMapper
) extends DefaultMessageBodyWriter
with Logging {
override def write(obj: Any): WriterResponse = {
obj match {
case ex: Throwable =>
Expand All @@ -44,4 +44,4 @@ class CustomResponseWriterImpl @Inject()(
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class QueryServiceImpl @Inject() (
baseQuery,
userProfile.map(_.username),
limit,
request.filterRequests,
if (request.querySetting.isInstanceOf[FilterSetting]) Array.empty else request.filterRequests,
relationshipInfo,
rlsPolicies,
Some(QueryContext(tableExpressions))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object LicenceUtils extends Logging {
val keyFactory = KeyFactory.getInstance("RSA")
keyFactory.generatePublic(keySpec)
} catch {
case e: Throwable => throw new Exception("invalid public key")
case e: Throwable => throw new Exception("invalid public key", e)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class DashboardControllerTest extends FeatureTest with BeforeAndAfterAll {
from = 1,
size = 100
)
println(Serializer.toJson(request))

val response = server.httpPost(
s"$apiPath/list_drill_through",
postBody = Serializer.toJson(request),
Expand Down
2 changes: 1 addition & 1 deletion caas-service/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
cd libs && ./install.sh && cd ../

mvn clean package -DskipTests && docker build --no-cache -t registry.gitlab.com/datainsider/user-profile:oss .
mvn clean package -DskipTests && docker build --no-cache -t datainsiderco/caas-service:main .
1 change: 1 addition & 0 deletions caas-service/conf/development.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ caas {
org_email {
google = "^(.+)@datainsider.co"
}
default_organization_id = 0

}

Expand Down
2 changes: 1 addition & 1 deletion caas-service/conf/local.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ caas {
org_email {
google = "^(.+)@datainsider.co"
}

default_organization_id = 0
}

db {
Expand Down
1 change: 1 addition & 0 deletions caas-service/conf/production.conf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ caas {
org_email {
google = "^(.+)@datainsider.co"
}
default_organization_id = 0

}

Expand Down
2 changes: 1 addition & 1 deletion caas-service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.5'
services:
user-profile:
image: registry.gitlab.com/datainsider/user-profile:local
image: datainsiderco/caas-service:main
container_name: rocket-user-profile
restart: always
environment:
Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion caas-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<dependency>
<groupId>datainsider</groupId>
<artifactId>clients</artifactId>
<version>2.2.29</version>
<version>2.2.31</version>

<exclusions>
<exclusion>
Expand Down
Loading

0 comments on commit 5cf98b1

Please sign in to comment.