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=616a88111ea9603f0d6f93c7462e6dab39644fcf;hp=07cd4a846b211d68a1643081da667768a81e3a93;hpb=25563418e1867be44ab8d829db30360df60ee1c9;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 07cd4a846b..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,44 +1,74 @@ 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 org.slf4j.LoggerFactory class BrokerFacade implements DataReader { + + val static LOG = LoggerFactory.getLogger(BrokerFacade) + val static BrokerFacade INSTANCE = new BrokerFacade + @Property private ConsumerSession context; @Property private DataBrokerService dataService; + + private new() { + 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() } - + }