STAR-322: Checking if response changed before updating cluster

This commit is contained in:
Daniel Schiavini 2018-12-07 13:19:45 +01:00
parent 2b8358fda8
commit 5b963de2ea
13 changed files with 58 additions and 30 deletions

View file

@ -0,0 +1,17 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from datetime import datetime, timezone
from ...Models import BaseModel
class BaseCloudModel(BaseModel):
def __eq__(self, other):
return type(self) == type(other) and self.__dict__ == other.__dict__
def __ne__(self, other):
return type(self) != type(other) or self.__dict__ != other.__dict__
@staticmethod
def parseDate(date_str: str) -> datetime:
return datetime.strptime(date_str, "%Y-%m-%dT%H:%M:%S.%fZ").replace(tzinfo=timezone.utc)

View file

@ -1,10 +1,10 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
## Class representing a cloud connected cluster.
class CloudCluster(BaseModel):
class CloudCluster(BaseCloudModel):
def __init__(self, **kwargs):
self.cluster_id = None # type: str
self.host_guid = None # type: str

View file

@ -6,14 +6,14 @@ from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
from plugins.UM3NetworkPrinting.src.Cloud.CloudOutputController import CloudOutputController
from .CloudClusterPrinterConfiguration import CloudClusterPrinterConfiguration
from .CloudClusterPrintJobConstraint import CloudClusterPrintJobConstraint
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
## Class representing a print job
from plugins.UM3NetworkPrinting.src.UM3PrintJobOutputModel import UM3PrintJobOutputModel
class CloudClusterPrintJob(BaseModel):
class CloudClusterPrintJob(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.assigned_to = None # type: str
self.configuration = [] # type: List[CloudClusterPrinterConfiguration]

View file

@ -1,10 +1,10 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
## Class representing a cloud cluster print job constraint
class CloudClusterPrintJobConstraint(BaseModel):
class CloudClusterPrintJobConstraint(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.require_printer_name = None # type: str
super().__init__(**kwargs)

View file

@ -6,11 +6,11 @@ from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
from cura.PrinterOutput.PrinterOutputController import PrinterOutputController
from cura.PrinterOutput.PrinterOutputModel import PrinterOutputModel
from .CloudClusterPrinterConfiguration import CloudClusterPrinterConfiguration
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
## Class representing a cluster printer
class CloudClusterPrinter(BaseModel):
class CloudClusterPrinter(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.configuration = [] # type: List[CloudClusterPrinterConfiguration]
self.enabled = None # type: str

View file

@ -6,11 +6,11 @@ from cura.PrinterOutput.ConfigurationModel import ConfigurationModel
from cura.PrinterOutput.ExtruderConfigurationModel import ExtruderConfigurationModel
from cura.PrinterOutput.ExtruderOutputModel import ExtruderOutputModel
from .CloudClusterPrinterConfigurationMaterial import CloudClusterPrinterConfigurationMaterial
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
## Class representing a cloud cluster printer configuration
class CloudClusterPrinterConfiguration(BaseModel):
class CloudClusterPrinterConfiguration(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.extruder_index = None # type: int
self.material = None # type: CloudClusterPrinterConfigurationMaterial

View file

@ -1,11 +1,11 @@
from UM.Logger import Logger
from cura.CuraApplication import CuraApplication
from cura.PrinterOutput.MaterialOutputModel import MaterialOutputModel
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
## Class representing a cloud cluster printer configuration
class CloudClusterPrinterConfigurationMaterial(BaseModel):
class CloudClusterPrinterConfigurationMaterial(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.guid = None # type: str
self.brand = None # type: str

View file

@ -1,15 +1,17 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from datetime import datetime
from typing import List
from .CloudClusterPrinter import CloudClusterPrinter
from .CloudClusterPrintJob import CloudClusterPrintJob
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
# Model that represents the status of the cluster for the cloud
class CloudClusterStatus(BaseModel):
class CloudClusterStatus(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.generated_time = None # type: datetime
# a list of the printers
self.printers = [] # type: List[CloudClusterPrinter]
# a list of the print jobs
@ -20,3 +22,7 @@ class CloudClusterStatus(BaseModel):
# converting any dictionaries into models
self.printers = [CloudClusterPrinter(**p) if isinstance(p, dict) else p for p in self.printers]
self.print_jobs = [CloudClusterPrintJob(**j) if isinstance(j, dict) else j for j in self.print_jobs]
# converting generated time into datetime
if isinstance(self.generated_time, str):
self.generated_time = self.parseDate(self.generated_time)

View file

@ -2,11 +2,11 @@
# Cura is released under the terms of the LGPLv3 or higher.
from typing import Dict
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
## Class representing errors generated by the cloud servers, according to the json-api standard.
class CloudErrorObject(BaseModel):
class CloudErrorObject(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.id = None # type: str
self.code = None # type: str

View file

@ -1,10 +1,10 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
# Model that represents the response received from the cloud after requesting to upload a print job
class CloudJobResponse(BaseModel):
class CloudJobResponse(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.download_url = None # type: str
self.job_id = None # type: str

View file

@ -1,10 +1,10 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
# Model that represents the request to upload a print job to the cloud
class CloudJobUploadRequest(BaseModel):
class CloudJobUploadRequest(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.file_size = None # type: int
self.job_name = None # type: str

View file

@ -1,10 +1,10 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from ...Models import BaseModel
from .BaseCloudModel import BaseCloudModel
# Model that represents the responses received from the cloud after requesting a job to be printed.
class CloudPrintResponse(BaseModel):
class CloudPrintResponse(BaseCloudModel):
def __init__(self, **kwargs) -> None:
self.cluster_job_id = None # type: str
self.job_id = None # type: str