package org.opendaylight.controller.sal.restconf.impl
+import javax.ws.rs.core.Response
import org.opendaylight.controller.md.sal.common.api.data.DataReader
-import java.net.URI
-import org.opendaylight.yangtools.yang.data.api.CompositeNode
-import org.opendaylight.controller.sal.core.api.data.DataBrokerService
-import org.opendaylight.controller.sal.core.api.model.SchemaService
-import static com.google.common.base.Preconditions.*;
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.controller.md.sal.common.api.data.DataModificationTransactionFactory
+import org.opendaylight.yangtools.yang.data.api.CompositeNode
+import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier
+import org.slf4j.LoggerFactory
+import org.opendaylight.controller.sal.core.api.mount.MountInstance
-class BrokerFacade implements DataReader<String, CompositeNode> {
+class BrokerFacade implements DataReader<InstanceIdentifier, CompositeNode> {
+
+
+ val static LOG = LoggerFactory.getLogger(BrokerFacade)
+ val static BrokerFacade INSTANCE = new BrokerFacade
@Property
private ConsumerSession context;
-
+
@Property
private DataBrokerService dataService;
- @Property
- private SchemaService schemaService;
-
- @Property
- private extension ControllerContext schemaContext;
+ private new() {
+ if (INSTANCE !== null) {
+ throw new IllegalStateException("Already instantiated");
+ }
+ }
+ def static BrokerFacade getInstance() {
+ return INSTANCE
+ }
- def void init() {
- checkState(dataService !== null)
- checkState(schemaService !== null)
- schemaContext = new ControllerContext();
- schemaContext.schemas = schemaService.globalContext;
+ private def void checkPreconditions() {
+ if (context === null || dataService === null) {
+ throw new ResponseException(Response.Status.SERVICE_UNAVAILABLE, RestconfProvider::NOT_INITALIZED_MSG)
+ }
}
- override readConfigurationData(String path) {
- val processedPath = path.removePrefixes();
- return dataService.readConfigurationData(processedPath.toInstanceIdentifier);
+ override readConfigurationData(InstanceIdentifier path) {
+ checkPreconditions
+ LOG.info("Read Configuration via Restconf: {}", path)
+ return dataService.readConfigurationData(path);
+ }
+
+ def readConfigurationDataBehindMountPoint(MountInstance mountPoint, InstanceIdentifier path) {
+ checkPreconditions
+ LOG.info("Read Configuration via Restconf: {}", path)
+ return mountPoint.readConfigurationData(path);
}
- override readOperationalData(String path) {
- val processedPath = path.removePrefixes();
- return dataService.readOperationalData(processedPath.toInstanceIdentifier);
+ override readOperationalData(InstanceIdentifier path) {
+ checkPreconditions
+ LOG.info("Read Operational via Restconf: {}", path)
+ return dataService.readOperationalData(path);
}
- def RpcResult<CompositeNode> invokeRpc(String type,CompositeNode payload) {
- val future = context.rpc(type.toRpcQName(),payload);
+ def readOperationalDataBehindMountPoint(MountInstance mountPoint, InstanceIdentifier path) {
+ checkPreconditions
+ LOG.info("Read Operational via Restconf: {}", path)
+ return mountPoint.readOperationalData(path);
+ }
+
+ def RpcResult<CompositeNode> 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;
+ LOG.info("Put Configuration via Restconf: {}", path)
+ transaction.putConfigurationData(path, payload);
+ return transaction.commit
+ }
- def commitConfigurationDataUpdate(String path, CompositeNode payload) {
+ def commitConfigurationDataPutBehindMountPoint(MountInstance mountPoint, InstanceIdentifier path, CompositeNode payload) {
+ checkPreconditions
+ val transaction = mountPoint.beginTransaction;
+ LOG.info("Put Configuration via Restconf: {}", path)
+ transaction.putConfigurationData(path, payload);
+ return transaction.commit
+ }
+
+ def commitConfigurationDataPost(InstanceIdentifier path, CompositeNode payload) {
+ checkPreconditions
val transaction = dataService.beginTransaction;
- transaction.putConfigurationData(path.toInstanceIdentifier,payload);
- return transaction.commit()
+ transaction.putConfigurationData(path, payload);
+ if (payload == transaction.createdConfigurationData.get(path)) {
+ LOG.info("Post Configuration via Restconf: {}", path)
+ return transaction.commit
+ }
+ LOG.info("Post Configuration via Restconf was not executed because data already exists: {}", path)
+ return null;
}
- def commitConfigurationDataCreate(String path, CompositeNode payload) {
+ def commitConfigurationDataPostBehindMountPoint(MountInstance mountPoint, InstanceIdentifier path, CompositeNode payload) {
+ checkPreconditions
+ val transaction = mountPoint.beginTransaction;
+ transaction.putConfigurationData(path, payload);
+ if (payload == transaction.createdConfigurationData.get(path)) {
+ LOG.info("Post Configuration via Restconf: {}", path)
+ return transaction.commit
+ }
+ LOG.info("Post Configuration via Restconf was not executed because data already exists: {}", path)
+ return null;
+ }
+
+ def commitConfigurationDataDelete(InstanceIdentifier path) {
+ checkPreconditions
val transaction = dataService.beginTransaction;
- transaction.putConfigurationData(path.toInstanceIdentifier,payload);
- return transaction.commit()
+ LOG.info("Delete Configuration via Restconf: {}", path)
+ transaction.removeConfigurationData(path)
+ return transaction.commit
}
- private def String removePrefixes(String path) {
- return path;
+ def commitConfigurationDataDeleteBehindMountPoint(MountInstance mountPoint, InstanceIdentifier path) {
+ checkPreconditions
+ val transaction = mountPoint.beginTransaction;
+ LOG.info("Delete Configuration via Restconf: {}", path)
+ transaction.removeConfigurationData(path)
+ return transaction.commit
}
+
}