Skip to content

Commit

Permalink
Fix service override. (AcademySoftwareFoundation#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
DiegoTavares authored and carlosfelgarcia committed May 22, 2024
1 parent 8536f4a commit 86d0ba3
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,15 +39,17 @@ public class ManageServiceOverride extends ServiceOverrideInterfaceGrpc.ServiceO
@Override
public void delete(ServiceOverrideDeleteRequest request,
StreamObserver<ServiceOverrideDeleteResponse> 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();
}

@Override
public void update(ServiceOverrideUpdateRequest request,
StreamObserver<ServiceOverrideUpdateResponse> 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();
}
Expand All @@ -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();
Expand All @@ -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();
Expand Down
22 changes: 14 additions & 8 deletions cuegui/cuegui/ServiceDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import cuegui.Constants
import cuegui.TagsWidget
import cuegui.Utils
from opencue.wrappers.service import ServiceOverride


class ServiceForm(QtWidgets.QWidget):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions pycue/opencue/cuebot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions pycue/opencue/wrappers/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 14 additions & 14 deletions pycue/opencue/wrappers/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down

0 comments on commit 86d0ba3

Please sign in to comment.