X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2FBrokerFacade.xtend;h=eb1f6165ca23c5bb17deac73f575a06bfc57fc57;hp=3c31c5a313ec0b45a9a8390729638331d4a7a7a0;hb=3979e330c9f95a898c54a9234f3a07e3b2ae4349;hpb=d542617f3486541cf9937009fb6aa1e3f2c9f0e2 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 3c31c5a313..eb1f6165ca 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,13 +1,15 @@ package org.opendaylight.controller.sal.restconf.impl +import javax.ws.rs.WebApplicationException +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.* class BrokerFacade implements DataReader { @@ -20,35 +22,47 @@ 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 WebApplicationException(Response.status(Response.Status.SERVICE_UNAVAILABLE) + .entity(RestconfProvider::NOT_INITALIZED_MSG).build()) + } + } + override readConfigurationData(InstanceIdentifier path) { + checkPreconditions return dataService.readConfigurationData(path); } override readOperationalData(InstanceIdentifier path) { + checkPreconditions return dataService.readOperationalData(path); } def RpcResult invokeRpc(QName type, CompositeNode payload) { + checkPreconditions val future = context.rpc(type, payload); return future.get; } def commitConfigurationDataPut(InstanceIdentifier path, CompositeNode payload) { + checkPreconditions val transaction = dataService.beginTransaction; transaction.putConfigurationData(path, payload); return transaction.commit() } def commitOperationalDataPut(InstanceIdentifier path, CompositeNode payload) { + checkPreconditions val transaction = dataService.beginTransaction; transaction.putOperationalData(path, payload); return transaction.commit()