Merge "Build on jenkins nodes with label docker"
[osm/SO.git] / rwlaunchpad / plugins / rwstagingmgr / rift / tasklets / rwstagingmgr / publisher / staging_status.py
1 #
2 # Copyright 2016 RIFT.IO Inc
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # Author(s): Varun Prasad
17 # Creation Date: 09/25/2016
18 #
19
20 import asyncio
21 import uuid
22
23 from gi.repository import (RwDts as rwdts)
24 import rift.mano.dts as mano_dts
25 import rift.tasklets
26
27 from ..protocol import StagingStoreProtocol
28
29 class StagingStorePublisher(mano_dts.DtsHandler, StagingStoreProtocol):
30
31 def __init__(self, log, dts, loop):
32 super().__init__(log, dts, loop)
33 self.delegate = None
34
35 def xpath(self, area_id=None):
36 return ("D,/rw-staging-mgmt:staging-areas/rw-staging-mgmt:staging-area" +
37 ("[area-id='{}']".format(area_id) if area_id else ""))
38
39 @asyncio.coroutine
40 def register(self):
41 # we need a dummy callback for recovery to work
42 @asyncio.coroutine
43 def on_event(dts, g_reg, xact, xact_event, scratch_data):
44 if xact_event == rwdts.MemberEvent.INSTALL:
45 if self.delegate:
46 self.delegate.on_recovery(self.reg.elements)
47
48 return rwdts.MemberRspCode.ACTION_OK
49
50 hdl = rift.tasklets.DTS.RegistrationHandler()
51 handlers = rift.tasklets.Group.Handler(on_event=on_event)
52 with self.dts.group_create(handler=handlers) as group:
53 self.reg = group.register(xpath=self.xpath(),
54 handler=hdl,
55 flags=(rwdts.Flag.PUBLISHER |
56 rwdts.Flag.NO_PREP_READ |
57 rwdts.Flag.CACHE |
58 rwdts.Flag.DATASTORE),)
59
60 assert self.reg is not None
61
62 def on_staging_area_create(self, store):
63 self.reg.update_element(self.xpath(store.area_id), store)
64
65 def on_staging_area_delete(self, store):
66 self.reg.update_element(self.xpath(store.area_id), store)
67
68 def stop(self):
69 self.deregister()
70
71 def deregister(self):
72 """ de-register with dts """
73 if self.reg is not None:
74 self.reg.deregister()
75 self.reg = None