From bea1b76992588995c737d2ebcf1952c3833b704e Mon Sep 17 00:00:00 2001 From: Sebastian Petzold Date: Sun, 24 Mar 2024 12:24:39 +0100 Subject: [PATCH 1/2] Added status update for to be updated instances --- .../dockerosb/persistence/ServiceInstanceRepository.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt b/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt index f2142f3..38d8b46 100644 --- a/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt +++ b/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt @@ -44,6 +44,14 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va objectToWrite = serviceInstance, file = instanceYml ) + + val statusYml = serviceInstanceStatusYmlFile(serviceInstanceId) + val status = Status("in progress", "service update") + yamlHandler.writeObject( + objectToWrite = status, + file = statusYml + ) + gitHandler.commitAllChanges( commitMessage = "Updated Service instance $serviceInstanceId" ) From 65e072b020ca7590009d31cf30284c3a8d82f9e8 Mon Sep 17 00:00:00 2001 From: Johannes Rudolph Date: Fri, 21 Jun 2024 17:32:03 +0200 Subject: [PATCH 2/2] test: add test case for setting instance status in progress after update --- .../persistence/ServiceInstanceRepository.kt | 9 ++++--- .../service/GenericServiceInstanceService.kt | 4 +-- .../scenario/UpdateServiceInstanceScenario.kt | 25 ++++++++++++++++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt b/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt index 38d8b46..89a603b 100644 --- a/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt +++ b/src/main/kotlin/io/meshcloud/dockerosb/persistence/ServiceInstanceRepository.kt @@ -30,23 +30,23 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va } // TODO Check if an update request is allowed. See https://github.com/meshcloud/unipipe-service-broker/pull/35/files#r651527916 + // Right now we don't apply any validation and trust the marketplace to know what it's doing. // // There are several actions that can be [triggered via an update request](https://github.com/openservicebrokerapi/servicebroker/blob/master/spec.md#updating-a-service-instance): //- updating the plan a service instance is using, if `plan_updateable` is true //- updating the context object of a service instance, if `allow_context_updates` is true //- applying a maintenance update, if the service broker previously provided `maintenance_info` to the platform. - fun updateServiceInstance(serviceInstance: ServiceInstance) { + fun updateServiceInstance(serviceInstance: ServiceInstance): Status { val serviceInstanceId = serviceInstance.serviceInstanceId val instanceYml = serviceInstanceYmlFile(serviceInstanceId) - yamlHandler.writeObject( objectToWrite = serviceInstance, file = instanceYml ) val statusYml = serviceInstanceStatusYmlFile(serviceInstanceId) - val status = Status("in progress", "service update") + val status = Status("in progress", "updating service") yamlHandler.writeObject( objectToWrite = status, file = statusYml @@ -55,6 +55,8 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va gitHandler.commitAllChanges( commitMessage = "Updated Service instance $serviceInstanceId" ) + + return status } fun deleteServiceInstance(serviceInstance: ServiceInstance) { @@ -87,7 +89,6 @@ class ServiceInstanceRepository(private val yamlHandler: YamlHandler, private va return yamlHandler.readObject(instanceYml, ServiceInstance::class.java) } - fun tryGetServiceInstanceGaugeMetrics(serviceInstanceId: String, from: Instant, to: Instant): List> { val instanceMetricsYmlFiles = serviceInstanceMetricsYmlFiles(serviceInstanceId, MetricType.GAUGE) val serviceInstanceDatapointsList: MutableList> = mutableListOf() diff --git a/src/main/kotlin/io/meshcloud/dockerosb/service/GenericServiceInstanceService.kt b/src/main/kotlin/io/meshcloud/dockerosb/service/GenericServiceInstanceService.kt index 3d2fb6f..2ef73a5 100644 --- a/src/main/kotlin/io/meshcloud/dockerosb/service/GenericServiceInstanceService.kt +++ b/src/main/kotlin/io/meshcloud/dockerosb/service/GenericServiceInstanceService.kt @@ -47,12 +47,12 @@ class GenericServiceInstanceService( ?: throw ServiceInstanceDoesNotExistException(request.serviceInstanceId) val updatedInstance = existingInstance.update(request) - repository.updateServiceInstance(updatedInstance) + val status = repository.updateServiceInstance(updatedInstance) return Mono.just( UpdateServiceInstanceResponse.builder() .async(true) - .operation("updating service") + .operation(status.description) .build() ) } diff --git a/src/test/kotlin/io/meshcloud/dockerosb/scenario/UpdateServiceInstanceScenario.kt b/src/test/kotlin/io/meshcloud/dockerosb/scenario/UpdateServiceInstanceScenario.kt index d9fe71b..7ed1920 100644 --- a/src/test/kotlin/io/meshcloud/dockerosb/scenario/UpdateServiceInstanceScenario.kt +++ b/src/test/kotlin/io/meshcloud/dockerosb/scenario/UpdateServiceInstanceScenario.kt @@ -35,7 +35,30 @@ class UpdateServiceInstanceScenario : DockerOsbApplicationTests() { val instance = repository.tryGetServiceInstance(instanceId) instance!!.planId } - + assertEquals(createdPlanId, updatedPlanId) } + + @Test + fun `update request sets status to in progress`() { + val instanceId = "e4bd6a78-7e05-4d5a-97b8-f8c5d1c710db" + val createRequest = fixture.builder.createServiceInstanceRequest(instanceId) + serviceInstanceService.createServiceInstance(createRequest) + + val updateRequest = fixture.builder.updateServiceInstanceRequest(instanceId) { + parameters("foo", "bar") + } + + val response = serviceInstanceService.updateServiceInstance(updateRequest) + + response.subscribe { + assertEquals("updating service", it.operation) + } + + useServiceInstanceRepository { repository -> + val instance = repository.getServiceInstanceStatus(instanceId) + assertEquals("in progress", instance.status) + assertEquals("updating service", instance.description) + } + } } \ No newline at end of file