This commit is contained in:
mr
2024-11-08 13:59:22 +01:00
parent 685badc59a
commit 1ca77b6611
69 changed files with 1601 additions and 1337 deletions

View File

@@ -10,7 +10,7 @@ Map<Type, SerializerDeserializer> refs = <Type, SerializerDeserializer> {
Search: Search(),
Workspace: Workspace(),
DataItem: DataItem(),
DataCenterItem: DataCenterItem(),
ComputeItem: ComputeItem(),
StorageItem: StorageItem(),
ProcessingItem: ProcessingItem(),
Workflow: Workflow(),
@@ -18,7 +18,8 @@ Map<Type, SerializerDeserializer> refs = <Type, SerializerDeserializer> {
WorkflowExecutions: WorkflowExecutions(),
LogsResult: LogsResult(),
Check: Check(),
SharedWorkspace: SharedWorkspace(),
CollaborativeArea: CollaborativeArea(),
SimpleData: SimpleData(),
};
class APIResponse<T extends SerializerDeserializer> {
@@ -40,7 +41,11 @@ class APIResponse<T extends SerializerDeserializer> {
APIResponse<T> deserialize(dynamic j) {
dynamic data;
try { data = j["data"];
try {
if (j["data"] == null) { data = j; }
else {
data = j["data"];
}
} catch (e) { data = j; }
try {
return APIResponse<T>(
@@ -52,6 +57,15 @@ class APIResponse<T extends SerializerDeserializer> {
}
}
class SimpleData extends SerializerDeserializer<SimpleData> {
SimpleData({ this.value });
dynamic value;
@override deserialize(dynamic json) {
return SimpleData(value: json);
}
@override Map<String, dynamic> serialize() => { };
}
class RawData extends SerializerDeserializer<RawData> {
RawData({ this.values = const []});
List<dynamic> values = [];

View File

@@ -6,31 +6,31 @@ import 'package:oc_front/models/abstract.dart';
const List<ProcessingItem> _emptyComputing = [];
const List<DataItem> _emptyData = [];
const List<DataCenterItem> _emptyDataCenter = [];
const List<ComputeItem> _emptyCompute = [];
const List<StorageItem> _emptyStorage = [];
class Search extends SerializerDeserializer<Search> {
Search({
this.computing = _emptyComputing,
this.datacenter = _emptyDataCenter,
this.compute = _emptyCompute,
this.data = _emptyData,
this.storage = _emptyStorage,
});
List<ProcessingItem> computing;
List<DataCenterItem> datacenter;
List<ComputeItem> compute;
List<DataItem> data;
List<StorageItem> storage;
@override deserialize(dynamic json) {
json = json as Map<String, dynamic>;
return Search(
computing: json.containsKey("processing") ? fromListJson(json["processing"], ProcessingItem()) : [],
datacenter: json.containsKey("datacenter") ? fromListJson(json["datacenter"], DataCenterItem()) : [],
compute: json.containsKey("compute") ? fromListJson(json["compute"], ComputeItem()) : [],
data: json.containsKey("data") ? fromListJson(json["data"], DataItem()) : [],
storage: json.containsKey("storage") ? fromListJson(json["storage"], StorageItem()) : [],
);
}
@override Map<String, dynamic> serialize() => {
"processing": toListJson<ProcessingItem>(computing),
"datacenter": toListJson<DataCenterItem>(datacenter),
"compute": toListJson<ComputeItem>(compute),
"data": toListJson<DataItem>(data),
"storage": toListJson<StorageItem>(storage),
};
@@ -41,14 +41,14 @@ class Resource implements SerializerDeserializer<Resource> {
List<DataItem> datas = [];
List<ProcessingItem> processings = [];
List<StorageItem> storages = [];
List<DataCenterItem> datacenters = [];
List<ComputeItem> computes = [];
List<WorkflowItem> workflows = [];
Resource({
this.datas = const [],
this.processings = const [],
this.storages = const [],
this.datacenters = const [],
this.computes = const [],
this.workflows = const [],
});
@@ -56,7 +56,7 @@ class Resource implements SerializerDeserializer<Resource> {
try { json = json as Map<String, dynamic>;
} catch (e) { return Resource(); }
return Resource(
datacenters: json.containsKey("datacenter_resource") ? fromListJson(json["datacenter_resource"], DataCenterItem()) : [],
computes: json.containsKey("compute_resource") ? fromListJson(json["compute_resource"], ComputeItem()) : [],
datas: json.containsKey("data_resource") ? fromListJson(json["data_resource"], DataItem()) : [],
processings: json.containsKey("processing_resource") ? fromListJson(json["processing_resource"], ProcessingItem()) : [],
storages: json.containsKey("storage_resource") ? fromListJson(json["storage_resource"], StorageItem()) : [],
@@ -66,7 +66,7 @@ class Resource implements SerializerDeserializer<Resource> {
@override Map<String, dynamic> serialize() {
return {
"datacenter_resource": toListJson<DataCenterItem>(datacenters),
"compute_resource": toListJson<ComputeItem>(computes),
"data_resource": toListJson<DataItem>(datas),
"processing_resource": toListJson<ProcessingItem>(processings),
"storage_resource": toListJson<StorageItem>(storages),
@@ -198,7 +198,7 @@ class ResourceModel extends SerializerDeserializer<ResourceModel> {
Type? getTopicType(String topic) {
if (topic == "processing") { return ProcessingItem; }
else if (topic == "data") { return DataItem; }
else if (topic == "datacenter") { return DataCenterItem; }
else if (topic == "compute") { return ComputeItem; }
else if (topic == "storage") { return StorageItem; }
else if (topic == "workflow") { return WorkflowItem; }
else { return null; }
@@ -208,7 +208,7 @@ String getTopic(Type type) {
if (type == AbstractItem) { return "resource"; }
if (type == ProcessingItem) { return "processing"; }
if (type == DataItem) { return "data"; }
if (type == DataCenterItem) { return "datacenter"; }
if (type == ComputeItem) { return "compute"; }
if (type == StorageItem) { return "storage"; }
if (type == WorkflowItem) { return "workflow"; }
return "";
@@ -216,7 +216,7 @@ String getTopic(Type type) {
bool isComputing(String topic) => topic == "processing";
bool isData(String topic) => topic == "data";
bool isDataCenter(String topic) => topic == "datacenter";
bool isCompute(String topic) => topic == "compute";
bool isStorage(String topic) => topic == "storage";
bool isWorkflow(String topic) => topic == "workflow";
@@ -710,8 +710,8 @@ class DataItem extends SerializerDeserializer<DataItem> implements AbstractItem<
};
}
class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements AbstractItem<DataCenterItem> {
DataCenterItem({
class ComputeItem extends SerializerDeserializer<ComputeItem> implements AbstractItem<ComputeItem> {
ComputeItem({
this.id,
this.name,
this.logo,
@@ -728,6 +728,11 @@ class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements A
this.cpus = const [],
this.gpus = const [],
this.ram,
this.technology,
this.access,
this.architecture,
this.localisation,
this.isService = false,
});
@override String? id;
@override String? name;
@@ -735,7 +740,7 @@ class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements A
@override String? source;
@override String? ownerLogo;
@override String? owner;
@override String topic = "datacenter";
@override String topic = "compute";
@override double? price;
@override String? licence;
@override List<dynamic> inputs;
@@ -743,9 +748,14 @@ class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements A
@override String? description;
@override String? shortDescription;
@override ResourceModel? model;
bool isService = false;
String? architecture;
int? access;
String? localisation;
// Special Attributes
List<CPU> cpus = [];
List<GPU> gpus = [];
int? technology;
RAM? ram;
@override String getID() {
return id ?? "";
@@ -763,20 +773,42 @@ class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements A
double? getHeight() {
return height;
}
String getTechnology() {
if (technology == 0) { return "docker"; }
if (technology == 1) { return "kubernetes"; }
if (technology == 2) { return "slurm"; }
if (technology == 3) { return "hardware"; }
if (technology == 4) { return "condor"; }
return "";
}
String getAccess() {
if (access == 0) { return "ssh"; }
if (access == 1) { return "ssh kube api"; }
if (access == 2) { return "ssh slurm"; }
if (access == 3) { return "ssh docker"; }
if (access == 4) { return "opencloud"; }
if (access == 5) { return "vpn"; }
return "";
}
@override deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return DataCenterItem(); }
var w = DataCenterItem(
} catch (e) { return ComputeItem(); }
var w = ComputeItem(
isService: json.containsKey("is_service") ? json["is_service"] : false,
id: json.containsKey("id") ? json["id"] : null,
name: json.containsKey("name") ? json["name"] : null,
logo: json.containsKey("logo") ? json["logo"] : null,
technology: json.containsKey("technology") ? json["technology"] : null,
owner: json.containsKey("owner") ? json["owner"] : null,
ownerLogo: json.containsKey("owner_logo") ? json["owner_logo"] : null,
price: json.containsKey("price") ? json["price"]?.toDouble() : null,
licence: json.containsKey("licence") ? json["licence"] : null,
description: json.containsKey("description") ? json["description"] : null,
shortDescription: json.containsKey("short_description") ? json["short_description"] : null,
access: json.containsKey("access") ? json["access"] : null,
architecture: json.containsKey("architecture") ? json["architecture"] : null,
localisation: json.containsKey("localisation") ? json["localisation"] : null,
inputs: json["inputs"] ?? [],
outputs: json["outputs"] ?? [],
source: json.containsKey("source") ? json["source"] : null,
@@ -785,6 +817,7 @@ class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements A
gpus: json.containsKey("gpus") ? fromListJson(json["gpus"], GPU()) : [],
ram: json.containsKey("ram") ? RAM().deserialize(json["ram"]) : null,
);
print(w.technology);
if (w.logo != null) {
//
var image = Image.network(w.logo!);
@@ -829,12 +862,17 @@ class DataCenterItem extends SerializerDeserializer<DataCenterItem> implements A
"owner": owner,
"owner_logo": ownerLogo,
"price": price,
"is_service": isService,
"licence": licence,
"access": access,
"architecture": architecture,
"localisation": localisation,
"description": description,
"short_description": shortDescription,
"inputs": inputs,
"outputs": outputs,
"source": source,
"technology": technology,
"resource_model": model?.serialize(),
"cpus": toListJson<CPU>(cpus),
"gpus": toListJson<GPU>(gpus),

View File

@@ -3,7 +3,7 @@ import 'package:oc_front/models/response.dart';
import 'package:oc_front/models/workflow.dart';
import 'package:oc_front/models/workspace.dart';
class SharedWorkspace extends SerializerDeserializer<SharedWorkspace> {
class CollaborativeArea extends SerializerDeserializer<CollaborativeArea> {
String? id;
String? name;
String? description;
@@ -15,7 +15,7 @@ class SharedWorkspace extends SerializerDeserializer<SharedWorkspace> {
List<Peer> peers = [];
List<Rule> rules = [];
SharedWorkspace(
CollaborativeArea(
{this.id,
this.name,
this.description,
@@ -30,8 +30,8 @@ class SharedWorkspace extends SerializerDeserializer<SharedWorkspace> {
@override
deserialize(dynamic json) {
try { json = json as Map<String, dynamic>;
} catch (e) { return SharedWorkspace(); }
return SharedWorkspace(
} catch (e) { return CollaborativeArea(); }
return CollaborativeArea(
id: json.containsKey("id") ? json["id"] : null,
name: json.containsKey("name") ? json["name"] : null,
description: json.containsKey("description") ? json["description"] : null,

View File

@@ -103,7 +103,7 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
String? id;
String? name;
List<dynamic> data;
List<dynamic> datacenter;
List<dynamic> compute;
List<dynamic> storage;
List<dynamic> processing;
List<dynamic> workflows;
@@ -116,7 +116,7 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
this.id,
this.name = "",
this.data = const [],
this.datacenter = const [],
this.compute = const [],
this.storage = const [],
this.processing = const [],
this.workflows = const [],
@@ -138,7 +138,7 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
name: json.containsKey("name") ? json["name"] : "",
workflows: json.containsKey("workflows") ? json["workflows"] : [],
processing: json.containsKey("processings") ? json["processings"] : [],
datacenter: json.containsKey("datacenters") ? json["datacenters"] : [],
compute: json.containsKey("computes") ? json["computes"] : [],
data: json.containsKey("datas") ? json["datas"] : [],
scheduleActive: json.containsKey("schedule_active") ? json["schedule_active"] : false,
storage: json.containsKey("storages") ? json["storages"] : [],
@@ -152,7 +152,7 @@ class Workflow extends SerializerDeserializer<Workflow> implements ShallowData
"id": id,
"name": name,
"datas": data,
"datacenters" : datacenter,
"computes" : compute,
"storages": storage,
"processings": processing,
"workflows": workflows,
@@ -497,7 +497,7 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
DataItem? data;
ProcessingItem? processing;
StorageItem? storage;
DataCenterItem? datacenter;
ComputeItem? compute;
WorkflowItem? workflow;
GraphItem({
@@ -508,7 +508,7 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
this.data,
this.processing,
this.storage,
this.datacenter,
this.compute,
this.workflow,
});
@@ -516,7 +516,7 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
if (data != null) { return data!; }
if (processing != null) { return processing!; }
if (storage != null) { return storage!; }
if (datacenter != null) { return datacenter!; }
if (compute != null) { return compute!; }
if (workflow != null) { return workflow!; }
return null;
}
@@ -542,21 +542,21 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
processing!.expose.removeWhere((element) => element.port == null || element.port == 0 || (element.PAT == 0 && element.path == ""));
}
} else if (abs.topic == "datacenter") {
datacenter = DataCenterItem().deserialize(abs.serialize());
} else if (abs.topic == "compute") {
compute = ComputeItem().deserialize(abs.serialize());
} else if (abs.topic == "storage") {
storage = StorageItem().deserialize(abs.serialize());
} else if (abs.topic == "workflow") {
workflow = WorkflowItem().deserialize(abs.serialize());
} else {
datacenter = null;
compute = null;
data = null;
processing = null;
storage = null;
workflow = null;
}
} else {
datacenter = null;
compute = null;
data = null;
processing = null;
storage = null;
@@ -566,7 +566,7 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
Map<String, dynamic> toDashboard() {
Map<String, dynamic> element = {};
for(var el in [data, processing, storage, datacenter, workflow]) {
for(var el in [data, processing, storage, compute, workflow]) {
if (el != null && el.getID() != "") {
element = el.serialize();
break;
@@ -593,7 +593,7 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
data: json.containsKey("data") ? DataItem().deserialize(json["data"]) : null,
processing: json.containsKey("processing") ? ProcessingItem().deserialize(json["processing"]) : null,
storage: json.containsKey("storage") ? StorageItem().deserialize(json["storage"]) : null,
datacenter: json.containsKey("datacenter") ? DataCenterItem().deserialize(json["datacenter"]) : null,
compute: json.containsKey("compute") ? ComputeItem().deserialize(json["compute"]) : null,
workflow: json.containsKey("workflow") ? WorkflowItem().deserialize(json["workflow"]) : null,
);
}
@@ -605,7 +605,7 @@ class GraphItem extends SerializerDeserializer<GraphItem> {
"data": data?.serialize(),
"processing": processing?.serialize(),
"storage": storage?.serialize(),
"datacenter": datacenter?.serialize(),
"compute": compute?.serialize(),
"workflow": workflow?.serialize(),
"position": position?.serialize(),
};

View File

@@ -8,7 +8,7 @@ class Workspace extends SerializerDeserializer<Workspace> implements ShallowData
String? name;
bool? active;
List<DataItem> datas;
List<DataCenterItem> datacenters;
List<ComputeItem> computes;
List<StorageItem> storages;
List<ProcessingItem> processings;
List<WorkflowItem> workflows;
@@ -20,7 +20,7 @@ class Workspace extends SerializerDeserializer<Workspace> implements ShallowData
this.active = false,
this.workflows = const [],
this.datas = const [],
this.datacenters = const [],
this.computes = const [],
this.storages = const [],
this.processings = const [],
this.shared,
@@ -39,7 +39,7 @@ class Workspace extends SerializerDeserializer<Workspace> implements ShallowData
active: json.containsKey("active") ? json["active"] : false,
processings: json.containsKey("processing_resources") ? fromListJson(json["processing_resources"], ProcessingItem()) : [],
storages: json.containsKey("storage_resources") ? fromListJson(json["storage_resources"], StorageItem()) : [],
datacenters: json.containsKey("datacenter_resources") ? fromListJson(json["datacenter_resources"], DataCenterItem()) : [],
computes: json.containsKey("compute_resources") ? fromListJson(json["compute_resources"], ComputeItem()) : [],
datas: json.containsKey("data_resources") ? fromListJson(json["data_resources"], DataItem()) : [],
workflows: json.containsKey("workflow_resources") ? fromListJson(json["workflow_resources"], WorkflowItem()) : []
);
@@ -49,7 +49,7 @@ class Workspace extends SerializerDeserializer<Workspace> implements ShallowData
"name": name,
"processings": processings.map((e) => e.id).toList(),
"storages": storages.map((e) => e.id).toList(),
"datacenters": datacenters.map((e) => e.id).toList(),
"computes": computes.map((e) => e.id).toList(),
"datas": datas.map((e) => e.id).toList(),
"workflows": workflows.map((e) => e.id).toList(),
};