Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

fix: update deployment persistence #201

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -252,77 +252,88 @@ public Uni<Response> deleteDeployment(@PathParam("uuid") UUID deploymentId) {
@Path("{uuid}")
public Uni<DeploymentEntity> updateDeployment(
@PathParam("uuid") UUID deploymentUuid, DeploymentSpec spec) {
Uni<DeploymentEntity> deploymentUni = getDeploymentUni(deploymentUuid);
Uni<List<ConfigEntity>> configList =
ConfigUtilities.getMappedConfigs(spec.configSelector(), dsf);
return configList
.onItem()
.transform(configs -> ConfigUtilities.applyConfigsToDeployment(spec, configs))
.onItem()
.transformToUni(
combinedSpec ->
Uni.combine()
.all()
.unis(Uni.createFrom().item(combinedSpec), getPipeline(combinedSpec))
.asTuple())
.onItem()
.transformToUni(
specAndPipeline ->
Uni.combine()
.all()
.unis(
Uni.createFrom().item(specAndPipeline.getItem2()),
getStream(
specAndPipeline.getItem1(),
StaticConfig.STREAM_IN_CONFIG,
specAndPipeline.getItem2(),
StaticConfig.STREAM_IN),
getStream(
specAndPipeline.getItem1(),
StaticConfig.STREAM_OUT_CONFIG,
specAndPipeline.getItem2(),
StaticConfig.STREAM_OUT),
deploymentUni,
configList,
Uni.createFrom().item(specAndPipeline.getItem1()))
.asTuple())
.onItem()
.transform(
tuple ->
updateDeployment(
tuple.getItem1(),
tuple.getItem3(),
tuple.getItem2(),
tuple.getItem6(),
tuple.getItem4(),
tuple.getItem5()))
.onFailure()
.transform(
ex ->
new UpdateDeploymentException(StaticConfig.LoggerMessages.DEPLOYMENT_NOT_UPDATED));
}

private Uni<PipelineEntity> getPipeline(DeploymentSpec deploymentSpec) {
return dsf.withTransaction(
(session, transaction) ->
((session, transaction) ->
session
.find(PipelineEntity.class, getPipelineUUIDFromMap(deploymentSpec.deployment()))
.find(DeploymentEntity.class, deploymentUuid)
.onItem()
.ifNull()
.failWith(
new CreateDeploymentException(StaticConfig.LoggerMessages.PIPELINE_NOT_FOUND)));
new CreateDeploymentException(StaticConfig.LoggerMessages.DEPLOYMENT_NOT_FOUND))
.onItem()
.transformToUni(
entity ->
Uni.combine()
.all()
.unis(
ConfigUtilities.getMappedConfigs(spec.configSelector(), dsf),
Uni.createFrom().item(entity))
.asTuple())
.onItem()
.transformToUni(
tuple -> {
DeploymentSpec combinedSpec =
ConfigUtilities.applyConfigsToDeployment(spec, tuple.getItem1());
return Uni.combine()
.all()
.unis(
Uni.createFrom().item(combinedSpec),
getPipeline(combinedSpec),
Uni.createFrom().item(tuple.getItem1()),
Uni.createFrom().item(tuple.getItem2()))
.asTuple();
})
.onItem()
.transformToUni(
tuple ->
Uni.combine()
.all()
.unis(
Uni.createFrom().item(tuple.getItem2()),
getStream(
tuple.getItem1(),
StaticConfig.STREAM_IN_CONFIG,
tuple.getItem2(),
StaticConfig.STREAM_IN),
getStream(
tuple.getItem1(),
StaticConfig.STREAM_OUT_CONFIG,
tuple.getItem2(),
StaticConfig.STREAM_OUT),
Uni.createFrom().item(tuple.getItem4()),
Uni.createFrom().item(tuple.getItem3()),
Uni.createFrom().item(tuple.getItem1()))
.asTuple())
.onItem()
.transform(
tuple -> {
updateDeployment(
tuple.getItem1(),
tuple.getItem3(),
tuple.getItem2(),
tuple.getItem6(),
tuple.getItem4(),
tuple.getItem5());
return session.merge(tuple.getItem4());
})
.flatMap(deploymentEntity -> deploymentEntity)
.onFailure()
.transform(
ex ->
new UpdateDeploymentException(
StaticConfig.LoggerMessages.DEPLOYMENT_NOT_UPDATED))));
}

private Uni<DeploymentEntity> getDeploymentUni(UUID deploymentUuid) {
private Uni<PipelineEntity> getPipeline(DeploymentSpec deploymentSpec) {
return dsf.withTransaction(
(session, transaction) ->
session
.find(DeploymentEntity.class, deploymentUuid)
.find(PipelineEntity.class, getPipelineUUIDFromMap(deploymentSpec.deployment()))
.onItem()
.ifNull()
.failWith(
new CreateDeploymentException(
StaticConfig.LoggerMessages.DEPLOYMENT_NOT_FOUND)));
new CreateDeploymentException(StaticConfig.LoggerMessages.PIPELINE_NOT_FOUND)));
}

private Uni<StreamEntity> getStream(
Expand Down