X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FBrokerFacade.xtend;h=df6b58c8971331b74c89418a6e1ee039e1fcdf10;hb=03abf047ba966c53f4901d36ae5198156d66dc05;hp=8e18661db6ecdfcc65d822dff5bf1e4c115c0b96;hpb=b5daa3678322a764f9b0e2483f82781f4d39d263;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend index 8e18661db6..df6b58c897 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/BrokerFacade.xtend @@ -1,16 +1,20 @@ package org.opendaylight.controller.sal.restconf.impl +import javax.ws.rs.core.Response import org.opendaylight.controller.md.sal.common.api.data.DataReader import org.opendaylight.controller.sal.core.api.Broker.ConsumerSession import org.opendaylight.controller.sal.core.api.data.DataBrokerService +import org.opendaylight.controller.sal.rest.impl.RestconfProvider import org.opendaylight.yangtools.yang.common.QName import org.opendaylight.yangtools.yang.common.RpcResult import org.opendaylight.yangtools.yang.data.api.CompositeNode import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier -import static org.opendaylight.controller.sal.restconf.impl.BrokerFacade.* +import org.slf4j.LoggerFactory class BrokerFacade implements DataReader { + + val static LOG = LoggerFactory.getLogger(BrokerFacade) val static BrokerFacade INSTANCE = new BrokerFacade @Property @@ -20,37 +24,50 @@ class BrokerFacade implements DataReader { private DataBrokerService dataService; private new() { - if (INSTANCE != null) { + if (INSTANCE !== null) { throw new IllegalStateException("Already instantiated"); } } - + def static BrokerFacade getInstance() { return INSTANCE } + private def void checkPreconditions() { + if (context === null || dataService === null) { + throw new ResponseException(Response.Status.SERVICE_UNAVAILABLE, RestconfProvider::NOT_INITALIZED_MSG) + } + } + override readConfigurationData(InstanceIdentifier path) { + checkPreconditions + LOG.info("Read Configuration via Restconf: {}",path) return dataService.readConfigurationData(path); } override readOperationalData(InstanceIdentifier path) { + checkPreconditions + LOG.info("Read Operational via Restconf: {}",path) return dataService.readOperationalData(path); } def RpcResult invokeRpc(QName type, CompositeNode payload) { + checkPreconditions val future = context.rpc(type, payload); return future.get; } - def commitConfigurationDataUpdate(InstanceIdentifier path, CompositeNode payload) { + def commitConfigurationDataPut(InstanceIdentifier path, CompositeNode payload) { + checkPreconditions val transaction = dataService.beginTransaction; transaction.putConfigurationData(path, payload); return transaction.commit() } - def commitConfigurationDataCreate(InstanceIdentifier path, CompositeNode payload) { + def commitOperationalDataPut(InstanceIdentifier path, CompositeNode payload) { + checkPreconditions val transaction = dataService.beginTransaction; - transaction.putConfigurationData(path, payload); + transaction.putOperationalData(path, payload); return transaction.commit() }