2 # Copyright 2016 RIFT.IO Inc
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
16 # Author(s): Varun Prasad
17 # Creation Date: 09/25/2016
23 from gi
.repository
import (RwDts
as rwdts
)
24 import rift
.mano
.dts
as mano_dts
27 from ..protocol
import StagingStoreProtocol
29 class StagingStorePublisher(mano_dts
.DtsHandler
, StagingStoreProtocol
):
31 def __init__(self
, log
, dts
, loop
):
32 super().__init
__(log
, dts
, loop
)
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 ""))
41 # we need a dummy callback for recovery to work
43 def on_event(dts
, g_reg
, xact
, xact_event
, scratch_data
):
44 if xact_event
== rwdts
.MemberEvent
.INSTALL
:
46 self
.delegate
.on_recovery(self
.reg
.elements
)
48 return rwdts
.MemberRspCode
.ACTION_OK
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(),
55 flags
=(rwdts
.Flag
.PUBLISHER |
56 rwdts
.Flag
.NO_PREP_READ |
58 rwdts
.Flag
.DATASTORE
),)
60 assert self
.reg
is not None
62 def on_staging_area_create(self
, store
):
63 self
.reg
.update_element(self
.xpath(store
.area_id
), store
)
65 def on_staging_area_delete(self
, store
):
66 self
.reg
.update_element(self
.xpath(store
.area_id
), store
)
72 """ de-register with dts """
73 if self
.reg
is not None: