Skip to content

Commit 1befe7f

Browse files
authored
Merge pull request #87 from dataiku/fix/dss80-zone-update
Zones update after collection changes + small fixes
2 parents 99f7d79 + 3238f3d commit 1befe7f

File tree

5 files changed

+139
-15
lines changed

5 files changed

+139
-15
lines changed

dataikuapi/dss/dataset.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,26 @@ def move_to_zone(self, zone):
536536
zone = self.project.get_flow().get_zone(zone)
537537
zone.add_item(self)
538538

539+
def share_to_zone(self, zone):
540+
"""
541+
Share this object to a flow zone
542+
543+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to share the object
544+
"""
545+
if isinstance(zone, basestring):
546+
zone = self.project.get_flow().get_zone(zone)
547+
zone.add_shared(self)
548+
549+
def unshare_from_zone(self, zone):
550+
"""
551+
Unshare this object from a flow zone
552+
553+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` from where to unshare the object
554+
"""
555+
if isinstance(zone, basestring):
556+
zone = self.project.get_flow().get_zone(zone)
557+
zone.remove_shared(self)
558+
539559
def get_usages(self):
540560
"""
541561
Get the recipes or analyses referencing this dataset

dataikuapi/dss/flow.py

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .savedmodel import DSSSavedModel
55
from .recipe import DSSRecipe, DSSRecipeDefinitionAndPayload
66
from .future import DSSFuture
7+
from .streaming_endpoint import DSSStreamingEndpoint
78
import logging, json
89

910
class DSSProjectFlow(object):
@@ -145,6 +146,8 @@ def _to_smart_ref(self, obj):
145146
ot = "SAVED_MODEL"
146147
elif isinstance(obj, DSSRecipe):
147148
ot = "RECIPE"
149+
elif isinstance(obj, DSSStreamingEndpoint):
150+
ot = "STREAMING_ENDPOINT"
148151
else:
149152
raise ValueError("Cannot transform to DSS object ref: %s" % obj)
150153

@@ -286,6 +289,10 @@ def id(self):
286289
def name(self):
287290
return self._raw["name"]
288291

292+
@property
293+
def color(self):
294+
return self._raw["color"]
295+
289296
def __repr__(self):
290297
return "<dataikuapi.dss.flow.DSSFlowZone (id=%s, name=%s)>" % (self.id, self.name)
291298

@@ -310,6 +317,8 @@ def _to_native_obj(self, zone_item):
310317
return p.get_saved_model(zone_item["objectId"])
311318
elif zone_item["objectType"] == "RECIPE":
312319
return p.get_recipe(zone_item["objectId"])
320+
elif zone_item["objectType"] == "STREAMING_ENDPOINT":
321+
return p.get_streaming_endpoint(zone_item["objectId"])
313322
else:
314323
raise ValueError("Cannot transform to DSS object: %s" % zone_item)
315324

@@ -323,22 +332,9 @@ def add_item(self, obj):
323332
:param object obj: A :class:`dataikuapi.dss.dataset.DSSDataset`, :class:`dataikuapi.dss.managedfolder.DSSManagedFolder`,
324333
or :class:`dataikuapi.dss.savedmodel.DSSSavedModel` to add to the zone
325334
"""
326-
self.client._perform_empty("POST", "/projects/%s/flow/zones/%s/items" % (self.flow.project.project_key, self.id),
335+
self._raw = self.client._perform_json("POST", "/projects/%s/flow/zones/%s/items" % (self.flow.project.project_key, self.id),
327336
body=self.flow._to_smart_ref(obj))
328337

329-
#. TBD: if we make "add to default" work propertly, then we don't need thjis
330-
#def remove_item(self, obj):
331-
# """
332-
# Removes an item to this zone.#
333-
#
334-
# :param object obj: A :class:`dataikuapi.dss.dataset.DSSDataset`, :class:`dataikuapi.dss.managedfolder.DSSManagedFolder`,
335-
# or :class:`dataikuapi.dss.savedmodel.DSSSavedModel` to add to the zone
336-
# """
337-
# sr = self._to_smart_ref(obj)
338-
#
339-
# self.client._perform_empty("DELETE", "/projects/%s/flow/zones/%s/items/%s/%s" % (self.flow.project.project_key,
340-
# self.id, sr["objectType"], sr["objectId"]))
341-
342338
@property
343339
def items(self):
344340
"""
@@ -356,6 +352,28 @@ def items(self):
356352
"""
357353
return [self._to_native_obj(i) for i in self._raw["items"]]
358354

355+
def add_shared(self, obj):
356+
"""
357+
Share an item to this zone.
358+
359+
The item will not be automatically unshared from its existing zone.
360+
361+
:param object obj: A :class:`dataikuapi.dss.dataset.DSSDataset`, :class:`dataikuapi.dss.managedfolder.DSSManagedFolder`,
362+
or :class:`dataikuapi.dss.savedmodel.DSSSavedModel` to share to the zone
363+
"""
364+
self._raw = self.client._perform_json("POST", "/projects/%s/flow/zones/%s/shared" % (self.flow.project.project_key, self.id),
365+
body=self.flow._to_smart_ref(obj))
366+
367+
def remove_shared(self, obj):
368+
"""
369+
Remove a shared item from this zone.
370+
371+
:param object obj: A :class:`dataikuapi.dss.dataset.DSSDataset`, :class:`dataikuapi.dss.managedfolder.DSSManagedFolder`,
372+
or :class:`dataikuapi.dss.savedmodel.DSSSavedModel` to share to the zone
373+
"""
374+
smartRef = self.flow._to_smart_ref(obj)
375+
self._raw = self.client._perform_json("DELETE", "/projects/%s/flow/zones/%s/shared/%s/%s" % (self.flow.project.project_key, self.id, smartRef['objectType'], smartRef['objectId']))
376+
359377
@property
360378
def shared(self):
361379
"""
@@ -397,6 +415,14 @@ def name(self):
397415
def name(self, new_name):
398416
self._raw["name"] = new_name
399417

418+
@property
419+
def color(self):
420+
return self._raw["color"]
421+
422+
@color.setter
423+
def color(self, new_color):
424+
self._raw["color"] = new_color
425+
400426
def save(self):
401427
"""Saves the settings of the zone"""
402428
self._zone.client._perform_empty("PUT", "/projects/%s/flow/zones/%s" % (self._zone.flow.project.project_key, self._zone.id),

dataikuapi/dss/managedfolder.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ def move_to_zone(self, zone):
177177
zone = self.project.get_flow().get_zone(zone)
178178
zone.add_item(self)
179179

180+
def share_to_zone(self, zone):
181+
"""
182+
Share this object to a flow zone
183+
184+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to share the object
185+
"""
186+
if isinstance(zone, basestring):
187+
zone = self.project.get_flow().get_zone(zone)
188+
zone.add_shared(self)
189+
190+
def unshare_from_zone(self, zone):
191+
"""
192+
Unshare this object from a flow zone
193+
194+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` from where to unshare the object
195+
"""
196+
if isinstance(zone, basestring):
197+
zone = self.project.get_flow().get_zone(zone)
198+
zone.remove_shared(self)
199+
180200
def get_usages(self):
181201
"""
182202
Get the recipes referencing this folder

dataikuapi/dss/savedmodel.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,26 @@ def move_to_zone(self, zone):
145145
zone = self.project.get_flow().get_zone(zone)
146146
zone.add_item(self)
147147

148+
def share_to_zone(self, zone):
149+
"""
150+
Share this object to a flow zone
151+
152+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to share the object
153+
"""
154+
if isinstance(zone, basestring):
155+
zone = self.project.get_flow().get_zone(zone)
156+
zone.add_shared(self)
157+
158+
def unshare_from_zone(self, zone):
159+
"""
160+
Unshare this object from a flow zone
161+
162+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` from where to unshare the object
163+
"""
164+
if isinstance(zone, basestring):
165+
zone = self.project.get_flow().get_zone(zone)
166+
zone.remove_shared(self)
167+
148168
def get_usages(self):
149169
"""
150170
Get the recipes referencing this model

dataikuapi/dss/streaming_endpoint.py

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,47 @@ def set_schema(self, schema):
136136
body=schema)
137137

138138
########################################################
139-
# Usages
139+
# Misc
140140
########################################################
141141

142+
def get_zone(self):
143+
"""
144+
Gets the flow zone of this streaming endpoint
145+
146+
:rtype: :class:`dataikuapi.dss.flow.DSSFlowZone`
147+
"""
148+
return self.project.get_flow().get_zone_of_object(self)
149+
150+
def move_to_zone(self, zone):
151+
"""
152+
Moves this object to a flow zone
153+
154+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to move the object
155+
"""
156+
if isinstance(zone, basestring):
157+
zone = self.project.get_flow().get_zone(zone)
158+
zone.add_item(self)
159+
160+
def share_to_zone(self, zone):
161+
"""
162+
Share this object to a flow zone
163+
164+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` where to share the object
165+
"""
166+
if isinstance(zone, basestring):
167+
zone = self.project.get_flow().get_zone(zone)
168+
zone.add_shared(self)
169+
170+
def unshare_from_zone(self, zone):
171+
"""
172+
Unshare this object from a flow zone
173+
174+
:param object zone: a :class:`dataikuapi.dss.flow.DSSFlowZone` from where to unshare the object
175+
"""
176+
if isinstance(zone, basestring):
177+
zone = self.project.get_flow().get_zone(zone)
178+
zone.remove_shared(self)
179+
142180
def get_usages(self):
143181
"""
144182
Get the recipes or analyses referencing this streaming endpoint

0 commit comments

Comments
 (0)