Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added status update for to be updated instances #129

Merged
Merged
Show file tree
Hide file tree
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 @@ -30,23 +30,33 @@ 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", "updating service")
yamlHandler.writeObject(
objectToWrite = status,
file = statusYml
)

gitHandler.commitAllChanges(
commitMessage = "Updated Service instance $serviceInstanceId"
)

return status
}

fun deleteServiceInstance(serviceInstance: ServiceInstance) {
Expand Down Expand Up @@ -79,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<ServiceInstanceDatapoints<GaugeMetricModel>> {
val instanceMetricsYmlFiles = serviceInstanceMetricsYmlFiles(serviceInstanceId, MetricType.GAUGE)
val serviceInstanceDatapointsList: MutableList<ServiceInstanceDatapoints<GaugeMetricModel>> = mutableListOf()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Loading