Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
gskrobisz committed Sep 25, 2024
1 parent 82bc8e5 commit be0fe74
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 156 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package pl.touk.nussknacker.engine.api.component

import cats.syntax.functor._
import io.circe.{Decoder, Encoder}
import io.circe.generic.auto._
import io.circe.syntax._
import pl.touk.nussknacker.engine.api.NodeId
import pl.touk.nussknacker.engine.api.component.NodesDeploymentData.NodeDeploymentData

final case class NodesDeploymentData(dataByNodeId: Map[NodeId, NodeDeploymentData])

object NodesDeploymentData {

// Raw deployment parameters (name -> value) that are used as additional node configuration during deployment.
// Each node can be provided with dedicated set of parameters.
// TODO: consider replacing NodeDeploymentData with Json
type NodeDeploymentData = Map[String, String]

val empty: NodesDeploymentData = NodesDeploymentData(Map.empty)

implicit val nodesDeploymentDataEncoder: Encoder[NodesDeploymentData] = Encoder
Expand All @@ -20,25 +23,3 @@ object NodesDeploymentData {
Decoder.decodeMap[NodeId, NodeDeploymentData].map(NodesDeploymentData(_))

}

sealed trait NodeDeploymentData

final case class SqlFilteringExpression(sqlExpression: String) extends NodeDeploymentData

final case class KafkaSourceOffset(offsetResetStrategy: Long) extends NodeDeploymentData

object NodeDeploymentData {

implicit val nodeDeploymentDataEncoder: Encoder[NodeDeploymentData] =
Encoder.instance {
case s: SqlFilteringExpression => s.asJson
case o: KafkaSourceOffset => o.asJson
}

implicit val nodeDeploymentDataDecoder: Decoder[NodeDeploymentData] =
List[Decoder[NodeDeploymentData]](
Decoder[SqlFilteringExpression].widen,
Decoder[KafkaSourceOffset].widen
).reduceLeft(_ or _)

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.touk.nussknacker.engine.api.process

import pl.touk.nussknacker.engine.api.component.Component._
import pl.touk.nussknacker.engine.api.component.{Component, ProcessingMode}
import pl.touk.nussknacker.engine.api.component.{Component, ParameterConfig, ProcessingMode}
import pl.touk.nussknacker.engine.api.context.ContextTransformation
import pl.touk.nussknacker.engine.api.definition.{Parameter, WithExplicitTypesToExtract}
import pl.touk.nussknacker.engine.api.parameter.ParameterName
Expand Down Expand Up @@ -49,8 +49,13 @@ trait TestWithParametersSupport[+T] { self: Source =>
def parametersToTestData(params: Map[ParameterName, AnyRef]): T
}

/**
* Used to define Source parameters for each activity
* e.g.
* {"DEPLOY": { "parametername": ...parameter configuration... }
*/
trait WithActivityParameters { self: Source =>
def activityParametersDefinition: Map[String, List[Parameter]]
def activityParametersDefinition: Map[String, Map[String, ParameterConfig]]
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pl.touk.nussknacker.ui.api

import pl.touk.nussknacker.engine.api.component.NodesDeploymentData
import pl.touk.nussknacker.engine.api.deployment.ProblemDeploymentStatus
import pl.touk.nussknacker.ui.api.description.DeploymentApiEndpoints
import pl.touk.nussknacker.ui.api.description.DeploymentApiEndpoints.Dtos._
Expand Down Expand Up @@ -29,7 +30,9 @@ class DeploymentApiHttpService(
RunDeploymentCommand(
id = deploymentId,
scenarioName = request.scenarioName,
nodesDeploymentData = request.nodesDeploymentData,
nodesDeploymentData = NodesDeploymentData(request.nodesDeploymentData.map { case (n, p) =>
(n, Map("sqlExpression" -> p))
}),
user = loggedUser
),
request.comment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import cats.data.NonEmptyList
import derevo.circe.{decoder, encoder}
import derevo.derive
import pl.touk.nussknacker.engine.api.NodeId
import pl.touk.nussknacker.engine.api.component.{NodeDeploymentData, NodesDeploymentData, SqlFilteringExpression}
import pl.touk.nussknacker.engine.api.context.ProcessCompilationError.{
EmptyProcess,
ExpressionParserCompilationError,
Expand Down Expand Up @@ -48,9 +47,7 @@ class DeploymentApiEndpoints(auth: EndpointInput[AuthCredentials]) extends BaseE
.example(
RunDeploymentRequest(
scenarioName = ProcessName("scenario1"),
NodesDeploymentData(
Map(NodeId("sourceNodeId1") -> SqlFilteringExpression("field1 = 'value'"))
),
nodesDeploymentData = Map(NodeId("sourceNodeId1") -> "field1 = 'value'"),
comment = None
)
)
Expand Down Expand Up @@ -197,7 +194,7 @@ object DeploymentApiEndpoints {
@derive(encoder, decoder, schema)
final case class RunDeploymentRequest(
scenarioName: ProcessName,
nodesDeploymentData: NodesDeploymentData,
nodesDeploymentData: Map[NodeId, String], // nodeId -> single parameter value
comment: Option[ApiCallComment]
)

Expand All @@ -210,13 +207,7 @@ object DeploymentApiEndpoints {
modifiedAt: Instant
)

implicit val nodeDeploymentDataCodec: Schema[NodeDeploymentData] = Schema.derived

implicit val nodesDeploymentDataCodec: Schema[NodesDeploymentData] = Schema
.schemaForMap[NodeId, NodeDeploymentData](_.id)
.map[NodesDeploymentData]((map: Map[NodeId, NodeDeploymentData]) => Some(NodesDeploymentData(map)))(
_.dataByNodeId
)
implicit val nodesDeploymentDataCodec: Schema[Map[NodeId, String]] = Schema.schemaForMap[NodeId, String](_.id)

sealed trait RunDeploymentError

Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
package pl.touk.nussknacker.ui.process.newactivity

import pl.touk.nussknacker.engine.api.definition.StringParameterEditor
import pl.touk.nussknacker.engine.api.NodeId
import pl.touk.nussknacker.engine.api.definition.RawParameterEditor
import pl.touk.nussknacker.engine.api.graph.ScenarioGraph
import pl.touk.nussknacker.engine.api.process.ProcessName
import pl.touk.nussknacker.engine.api.typed.CanBeSubclassDeterminer
import pl.touk.nussknacker.engine.api.typed.typing.Typed
import pl.touk.nussknacker.engine.canonicalgraph.CanonicalProcess
import pl.touk.nussknacker.engine.definition.activity.ActivityInfoProvider
import pl.touk.nussknacker.restmodel.definition.UISourceParameters
import pl.touk.nussknacker.ui.definition.DefinitionsService
import pl.touk.nussknacker.restmodel.definition.UiScenarioPropertyConfig
import pl.touk.nussknacker.ui.process.label.ScenarioLabel
import pl.touk.nussknacker.ui.security.api.LoggedUser
import pl.touk.nussknacker.ui.uiresolving.UIProcessResolver

// TODO: move to ActivityService? execute node compilation only once with ScenarioTestService?
class ActivityInfoService(activityInfoProvider: ActivityInfoProvider, processResolver: UIProcessResolver) {

// TODO: use UiActivityParameterConfig instead of UiScenarioPropertyConfig
def getActivityParameters(
scenarioGraph: ScenarioGraph,
processName: ProcessName,
isFragment: Boolean,
labels: List[ScenarioLabel]
)(
implicit user: LoggedUser
): Map[String, List[UISourceParameters]] = {
): Map[String, Map[NodeId, Map[String, UiScenarioPropertyConfig]]] = {
val canonical = toCanonicalProcess(scenarioGraph, processName, isFragment, labels)
activityInfoProvider
.getActivityParameters(canonical)
.map { case (activityName, nodeParamsMap) =>
activityName -> nodeParamsMap
.map { case (nodeId, params) =>
UISourceParameters(nodeId, params.map(DefinitionsService.createUIParameter))
NodeId(nodeId) -> params.map { case (name, value) =>
name -> UiScenarioPropertyConfig(
value.defaultValue,
value.editor.getOrElse(RawParameterEditor),
value.label,
value.hintText
)
}
}
.map(assignUserFriendlyEditor)
.toList
}
}

Expand All @@ -47,16 +51,4 @@ class ActivityInfoService(activityInfoProvider: ActivityInfoProvider, processRes
processResolver.validateAndResolve(scenarioGraph, processName, isFragment, labels)
}

// copied from ScenarioTestService
private def assignUserFriendlyEditor(uiSourceParameter: UISourceParameters): UISourceParameters = {
val adaptedParameters = uiSourceParameter.parameters.map { uiParameter =>
if (CanBeSubclassDeterminer.canBeSubclassOf(uiParameter.typ, Typed.apply(classOf[String])).isValid) {
uiParameter.copy(editor = StringParameterEditor)
} else {
uiParameter
}
}
uiSourceParameter.copy(parameters = adaptedParameters)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ import pl.touk.nussknacker.ui.processreport.ProcessCounter
import pl.touk.nussknacker.ui.security.api.{LoggedUser, RealLoggedUser}
import pl.touk.nussknacker.ui.util.{MultipartUtils, NuPathMatchers}
import slick.dbio.DBIOAction
import pl.touk.nussknacker.engine.definition.activity.ModelDataActivityInfoProvider
import pl.touk.nussknacker.ui.LoadableConfigBasedNussknackerConfig
import pl.touk.nussknacker.ui.process.newactivity.ActivityInfoService
import pl.touk.nussknacker.ui.process.newactivity.ScenarioActivityService
import java.net.URI
import scala.concurrent.{ExecutionContext, Future}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package pl.touk.nussknacker.ui.api

import io.restassured.RestAssured.`given`
import io.restassured.module.scala.RestAssuredSupport.AddThenToResponse
import org.hamcrest.Matchers.equalTo
import org.hamcrest.Matchers.{emptyOrNullString, equalTo, is, notNullValue}
import org.scalatest.freespec.AnyFreeSpecLike
import pl.touk.nussknacker.engine.build.ScenarioBuilder
import pl.touk.nussknacker.test.base.it.{NuItTest, WithSimplifiedConfigScenarioHelper}
Expand Down Expand Up @@ -38,12 +38,10 @@ class ActivityInfoResourcesSpec
.Then()
.statusCode(200)
.body(
"DEPLOY[0].sourceId",
equalTo("sourceWithParametersId"),
"DEPLOY[0].parameters[0].name",
equalTo("offset"),
"DEPLOY[0].parameters[0].typ.display",
equalTo("Long")
"DEPLOY.sourceWithParametersId.offset",
notNullValue(),
"DEPLOY.sourceWithParametersId.offset.defaultValue",
is(emptyOrNullString())
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class DeploymentApiHttpServiceBusinessSpec
private val correctDeploymentRequest = s"""{
| "scenarioName": "$scenarioName",
| "nodesDeploymentData": {
| "$sourceNodeId": {"sqlExpression":"`date` = '2024-01-01'"}
| "$sourceNodeId": "`date` = '2024-01-01'"
| }
|}""".stripMargin

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DeploymentApiHttpServiceDeploymentCommentSpec
.jsonBody(s"""{
| "scenarioName": "$scenarioName",
| "nodesDeploymentData": {
| "$sourceNodeId": {"sqlExpression":"`date` = '2024-01-01'"}
| "$sourceNodeId": "`date` = '2024-01-01'"
| }
|}""".stripMargin)
.put(s"$nuDesignerHttpAddress/api/deployments/${DeploymentId.generate}")
Expand All @@ -99,7 +99,7 @@ class DeploymentApiHttpServiceDeploymentCommentSpec
.jsonBody(s"""{
| "scenarioName": "$scenarioName",
| "nodesDeploymentData": {
| "$sourceNodeId": {"sqlExpression":"`date` = '2024-01-01'"}
| "$sourceNodeId": "`date` = '2024-01-01'"
| },
| "comment": "deployment comment not matching configured pattern"
|}""".stripMargin)
Expand All @@ -121,7 +121,7 @@ class DeploymentApiHttpServiceDeploymentCommentSpec
.jsonBody(s"""{
| "scenarioName": "$scenarioName",
| "nodesDeploymentData": {
| "$sourceNodeId": {"sqlExpression":"`date` = '2024-01-01'"}
| "$sourceNodeId": "`date` = '2024-01-01'"
| },
| "comment": "comment with $configuredPhrase"
|}""".stripMargin)
Expand Down
33 changes: 5 additions & 28 deletions docs-internal/api/nu-designer-openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -817,8 +817,7 @@ paths:
example:
scenarioName: scenario1
nodesDeploymentData:
sourceNodeId1:
sqlExpression: field1 = 'value'
sourceNodeId1: field1 = 'value'
required: true
responses:
'202':
Expand Down Expand Up @@ -4807,15 +4806,6 @@ components:
JsonParameterEditor:
title: JsonParameterEditor
type: object
KafkaSourceOffset:
title: KafkaSourceOffset
type: object
required:
- offset
properties:
offset:
type: integer
format: int64
LayoutData:
title: LayoutData
type: object
Expand Down Expand Up @@ -4867,11 +4857,11 @@ components:
type: object
additionalProperties:
$ref: '#/components/schemas/Map_TypingResultInJson'
Map_NodeId_NodeDeploymentData:
title: Map_NodeId_NodeDeploymentData
Map_NodeId_String:
title: Map_NodeId_String
type: object
additionalProperties:
$ref: '#/components/schemas/NodeDeploymentData'
type: string
Map_String:
title: Map_String
type: object
Expand Down Expand Up @@ -5299,11 +5289,6 @@ components:
type: string
type:
$ref: '#/components/schemas/NodeTypes12'
NodeDeploymentData:
title: NodeDeploymentData
oneOf:
- $ref: '#/components/schemas/KafkaSourceOffset'
- $ref: '#/components/schemas/SqlFilteringExpression'
NodeTypes:
title: NodeTypes
type: string
Expand Down Expand Up @@ -5734,7 +5719,7 @@ components:
scenarioName:
type: string
nodesDeploymentData:
$ref: '#/components/schemas/Map_NodeId_NodeDeploymentData'
$ref: '#/components/schemas/Map_NodeId_String'
comment:
type:
- string
Expand Down Expand Up @@ -6044,14 +6029,6 @@ components:
SpelTemplateParameterEditor:
title: SpelTemplateParameterEditor
type: object
SqlFilteringExpression:
title: SqlFilteringExpression
type: object
required:
- sqlExpression
properties:
sqlExpression:
type: string
SqlParameterEditor:
title: SqlParameterEditor
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package pl.touk.nussknacker.engine.flink.api.process
import com.github.ghik.silencer.silent
import org.apache.flink.api.common.functions.RuntimeContext
import org.apache.flink.api.common.typeinfo.TypeInformation
import pl.touk.nussknacker.engine.api.component.NodeDeploymentData
import pl.touk.nussknacker.engine.api.component.NodesDeploymentData.NodeDeploymentData
import pl.touk.nussknacker.engine.api.context.ValidationContext
import pl.touk.nussknacker.engine.api.process.ComponentUseCase
import pl.touk.nussknacker.engine.api.runtimecontext.EngineRuntimeContext
Expand Down
Loading

0 comments on commit be0fe74

Please sign in to comment.