From 0d3cc6900af64dab98f63aa8dd64deb88644df50 Mon Sep 17 00:00:00 2001 From: Diego Tavares Date: Tue, 5 Mar 2024 09:35:34 -0800 Subject: [PATCH] Fix service override. (#866) --- .../spcue/servant/ManageServiceOverride.java | 13 +++++---- cuegui/cuegui/ServiceDialog.py | 22 +++++++++------ pycue/opencue/cuebot.py | 1 + pycue/opencue/wrappers/service.py | 23 +++++++++++++++ pycue/opencue/wrappers/show.py | 28 +++++++++---------- 5 files changed, 60 insertions(+), 27 deletions(-) diff --git a/cuebot/src/main/java/com/imageworks/spcue/servant/ManageServiceOverride.java b/cuebot/src/main/java/com/imageworks/spcue/servant/ManageServiceOverride.java index 16afb3bf2..6d2db02fe 100644 --- a/cuebot/src/main/java/com/imageworks/spcue/servant/ManageServiceOverride.java +++ b/cuebot/src/main/java/com/imageworks/spcue/servant/ManageServiceOverride.java @@ -23,7 +23,7 @@ import io.grpc.stub.StreamObserver; -import com.imageworks.spcue.ServiceEntity; +import com.imageworks.spcue.ServiceOverrideEntity; import com.imageworks.spcue.grpc.service.Service; import com.imageworks.spcue.grpc.service.ServiceOverrideDeleteRequest; import com.imageworks.spcue.grpc.service.ServiceOverrideDeleteResponse; @@ -39,7 +39,8 @@ public class ManageServiceOverride extends ServiceOverrideInterfaceGrpc.ServiceO @Override public void delete(ServiceOverrideDeleteRequest request, StreamObserver responseObserver) { - serviceManager.deleteService(toServiceEntity(request.getService())); + // Passing null on showId as the interface doesn't require a showId in this situation + serviceManager.deleteService(toServiceOverrideEntity(request.getService(), null)); responseObserver.onNext(ServiceOverrideDeleteResponse.newBuilder().build()); responseObserver.onCompleted(); } @@ -47,7 +48,8 @@ public void delete(ServiceOverrideDeleteRequest request, @Override public void update(ServiceOverrideUpdateRequest request, StreamObserver responseObserver) { - serviceManager.updateService(toServiceEntity(request.getService())); + // Passing null on showId as the interface doesn't require a showId in this situation + serviceManager.updateService(toServiceOverrideEntity(request.getService(), null)); responseObserver.onNext(ServiceOverrideUpdateResponse.newBuilder().build()); responseObserver.onCompleted(); } @@ -60,8 +62,8 @@ public void setServiceManager(ServiceManager serviceManager) { this.serviceManager = serviceManager; } - private ServiceEntity toServiceEntity(Service service) { - ServiceEntity entity = new ServiceEntity(); + private ServiceOverrideEntity toServiceOverrideEntity(Service service, String showId){ + ServiceOverrideEntity entity = new ServiceOverrideEntity(); entity.id = service.getId(); entity.name = service.getName(); entity.minCores = service.getMinCores(); @@ -72,6 +74,7 @@ private ServiceEntity toServiceEntity(Service service) { entity.minGpuMemory = service.getMinGpuMemory(); entity.tags = new LinkedHashSet<>(service.getTagsList()); entity.threadable = service.getThreadable(); + entity.showId = showId; entity.timeout = service.getTimeout(); entity.timeout_llu = service.getTimeoutLlu(); entity.minMemoryIncrease = service.getMinMemoryIncrease(); diff --git a/cuegui/cuegui/ServiceDialog.py b/cuegui/cuegui/ServiceDialog.py index c54ca4a88..1fac432af 100644 --- a/cuegui/cuegui/ServiceDialog.py +++ b/cuegui/cuegui/ServiceDialog.py @@ -31,6 +31,7 @@ import cuegui.Constants import cuegui.TagsWidget import cuegui.Utils +from opencue.wrappers.service import ServiceOverride class ServiceForm(QtWidgets.QWidget): @@ -124,13 +125,13 @@ def setService(self, service): """ self.__service = service self.__buttons.setDisabled(False) - self.name.setText(service.data.name) - self.threadable.setChecked(service.data.threadable) - self.min_cores.setValue(service.data.min_cores) - self.max_cores.setValue(service.data.max_cores) - self.min_memory.setValue(service.data.min_memory // 1024) + self.name.setText(service.name()) + self.threadable.setChecked(service.threadable()) + self.min_cores.setValue(service.minCores()) + self.max_cores.setValue(service.maxCores()) self.min_gpu_memory.setValue(service.data.min_gpu_memory // 1024) - self._tags_w.set_tags(service.data.tags) + self.min_memory.setValue(service.minMemory() // 1024) + self._tags_w.set_tags(service.tags()) self.timeout.setValue(service.data.timeout) self.timeout_llu.setValue(service.data.timeout_llu) self.min_memory_increase.setValue(service.data.min_memory_increase // 1024) @@ -263,11 +264,16 @@ def saved(self, service): if self.__new_service: if self.__show: - self.__show.createServiceOverride(service.data) + serviceOverride = self.__show.createServiceOverride(service.data) else: opencue.api.createService(service.data) else: - service.update() + if self.__show: + serviceOverride = ServiceOverride(service) + serviceOverride.id = service.id() + serviceOverride.update() + else: + service.update() self.refresh() self.__new_service = False diff --git a/pycue/opencue/cuebot.py b/pycue/opencue/cuebot.py index b007f0efd..764d5428e 100644 --- a/pycue/opencue/cuebot.py +++ b/pycue/opencue/cuebot.py @@ -136,6 +136,7 @@ class Cuebot(object): 'proc': host_pb2_grpc.ProcInterfaceStub, 'renderPartition': renderPartition_pb2_grpc.RenderPartitionInterfaceStub, 'service': service_pb2_grpc.ServiceInterfaceStub, + 'serviceOverride': service_pb2_grpc.ServiceOverrideInterfaceStub, 'show': show_pb2_grpc.ShowInterfaceStub, 'subscription': subscription_pb2_grpc.SubscriptionInterfaceStub, 'task': task_pb2_grpc.TaskInterfaceStub diff --git a/pycue/opencue/wrappers/service.py b/pycue/opencue/wrappers/service.py index b3f6563d2..92cafe7fc 100644 --- a/pycue/opencue/wrappers/service.py +++ b/pycue/opencue/wrappers/service.py @@ -259,3 +259,26 @@ def setMinMemoryIncrease(self, min_memory_increase): self.data.min_memory_increase = min_memory_increase else: raise ValueError("Minimum memory increase must be > 0") + +class ServiceOverride(object): + def __init__(self, serviceOverride=None): + if serviceOverride: + self.id = serviceOverride.id + self.data = serviceOverride.data or service_pb2.Service().data + else: + defaultServiceOverride = service_pb2.ServiceOverride() + self.id = defaultServiceOverride.id + self.data = defaultServiceOverride.data + + self.stub = Cuebot.getStub("serviceOverride") + + def delete(self): + self.stub.Delete( + service_pb2.ServiceOverrideDeleteRequest(service=self.data), + timeout=Cuebot.Timeout) + + def update(self): + """Commit a ServiceOverride change to the database""" + self.stub.Update( + service_pb2.ServiceOverrideUpdateRequest(service=self.data), + timeout=Cuebot.Timeout) diff --git a/pycue/opencue/wrappers/show.py b/pycue/opencue/wrappers/show.py index 5dad1a000..c7594aaa3 100644 --- a/pycue/opencue/wrappers/show.py +++ b/pycue/opencue/wrappers/show.py @@ -19,6 +19,7 @@ import opencue.wrappers.filter import opencue.wrappers.group import opencue.wrappers.subscription +from opencue.wrappers.service import ServiceOverride class Show(object): @@ -66,30 +67,29 @@ def delete(self): def createServiceOverride(self, data): """Creates a Service Override at the show level. - - :type data: service_pb2.Service - :param data: service data, typically from opencue.wrappers.service.Service.data + :type data: opencue.wrapper.service.Service + :param data: Service.data object """ # min_memory_increase has to be greater than 0. if data.min_memory_increase <= 0: raise ValueError("Minimum memory increase must be > 0") - - self.stub.CreateServiceOverride( - show_pb2.ShowCreateServiceOverrideRequest(show=self.data, service=data), - timeout=Cuebot.Timeout) + + self.stub.CreateServiceOverride(show_pb2.ShowCreateServiceOverrideRequest( + show=self.data, service=data), + timeout=Cuebot.Timeout) def getServiceOverride(self, serviceName): - """Returns a service override for a show. + """ + Returns a service override for a show - :type serviceName: str :param serviceName: name of the service for the show - :rtype: service_pb2.ServiceOverride :return: service override object """ - return self.stub.GetServiceOverride( - show_pb2.ShowGetServiceOverrideRequest(show=self.data, name=serviceName), - timeout=Cuebot.Timeout).service_override + serviceOverride = self.stub.GetServiceOverride(show_pb2.ShowGetServiceOverrideRequest( + show=self.data, name=serviceName), + timeout=Cuebot.Timeout).service_override + return ServiceOverride(serviceOverride) def getServiceOverrides(self): """Returns a list of service overrides on the show. @@ -100,7 +100,7 @@ def getServiceOverrides(self): serviceOverrideSeq = self.stub.GetServiceOverrides( show_pb2.ShowGetServiceOverridesRequest(show=self.data), timeout=Cuebot.Timeout).service_overrides - return serviceOverrideSeq.service_overrides + return [ServiceOverride(override) for override in serviceOverrideSeq.service_overrides] def getSubscriptions(self): """Returns a list of all subscriptions the show has.