import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
/**
- * Wrapping providers from restconf draft02 and draft11.
+ * Wrapping providers from restconf draft02 and draft15.
*
*/
public class RestconfWrapperProviders implements AutoCloseable, RestConnector {
// DRAFT02
private final RestconfProviderImpl providerDraft02;
- // DRAFT11
- private final RestConnectorProvider providerDraft11;
+ // DRAFT15
+ private final RestConnectorProvider providerDraft15;
/**
* Init both providers:
* <ul>
* <li>draft02 - {@link RestconfProviderImpl}
- * <li>draft11 - {@link RestConnectorProvider}
+ * <li>draft15 - {@link RestConnectorProvider}
* </ul>
*
* @param port
this.providerDraft02 = new RestconfProviderImpl();
this.providerDraft02.setWebsocketPort(port);
- // Init draft11 provider
- this.providerDraft11 = new RestConnectorProvider();
+ this.providerDraft15 = new RestConnectorProvider();
}
/**
* Register both providers, which will use the SAL layer:
* <ul>
* <li>draft02 - {@link RestconfProviderImpl}
- * <li>draft11 - {@link RestConnectorProvider}
+ * <li>draft15 - {@link RestConnectorProvider}
* </ul>
*
* @param broker
// Register draft02 provider
broker.registerProvider(this.providerDraft02);
- // Register draft11 provider
- broker.registerProvider(this.providerDraft11);
+ // Register draft15 provider
+ broker.registerProvider(this.providerDraft15);
}
/**
@Override
public void close() throws Exception {
this.providerDraft02.close();
- this.providerDraft11.close();
+ this.providerDraft15.close();
}
}
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
@Provider
-@Produces({ SchemaRetrievalService.YANG_MEDIA_TYPE, Draft11.MediaTypes.YANG })
+@Produces({ SchemaRetrievalService.YANG_MEDIA_TYPE, Draft15.MediaTypes.YANG })
public class SchemaExportContentYangBodyWriter implements MessageBodyWriter<SchemaExportContext> {
@Override
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import javax.xml.stream.XMLStreamException;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
@Provider
-@Produces({ SchemaRetrievalService.YIN_MEDIA_TYPE, Draft11.MediaTypes.YIN + RestconfConstants.XML })
+@Produces({ SchemaRetrievalService.YIN_MEDIA_TYPE, Draft15.MediaTypes.YIN + RestconfConstants.XML })
public class SchemaExportContentYinBodyWriter implements MessageBodyWriter<SchemaExportContext> {
@Override
*/
package org.opendaylight.netconf.sal.rest.api;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.yangtools.yang.common.QName;
/**
* @deprecated Do not use old implementation of restconf draft. It will be
- * replaced by {@link Draft11}.
+ * replaced by {@link Draft15}.
*
*/
@Deprecated
import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
-import org.opendaylight.restconf.utils.patch.Draft11AbstractIdentifierAwareJaxRsProvider;
+import org.opendaylight.restconf.utils.patch.Draft15AbstractIdentifierAwareJaxRsProvider;
/**
* @deprecated This class will be replaced by
- * {@link Draft11AbstractIdentifierAwareJaxRsProvider}
+ * {@link Draft15AbstractIdentifierAwareJaxRsProvider}
*/
@Deprecated
public class AbstractIdentifierAwareJaxRsProvider {
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.slf4j.LoggerFactory;
@Provider
-@Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft11.MediaTypes.DATA + RestconfConstants.JSON,
- Draft02.MediaTypes.OPERATION + RestconfService.JSON, Draft11.MediaTypes.OPERATION + RestconfConstants.JSON,
- MediaType.APPLICATION_JSON })
+@Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft02.MediaTypes.OPERATION + RestconfService.JSON,
+ Draft15.MediaTypes.DATA + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
private final static Logger LOG = LoggerFactory.getLogger(JsonNormalizedNodeBodyReader.class);
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.utils.patch.Draft11JsonToPATCHBodyReader;
+import org.opendaylight.restconf.utils.patch.Draft15JsonToPATCHBodyReader;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.slf4j.LoggerFactory;
/**
- * @deprecated This class will be replaced by {@link Draft11JsonToPATCHBodyReader}
+ * @deprecated This class will be replaced by {@link Draft15JsonToPATCHBodyReader}
*/
@Deprecated
@Provider
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
@Provider
@Produces({ Draft02.MediaTypes.API + RestconfService.JSON, Draft02.MediaTypes.DATA + RestconfService.JSON,
- Draft02.MediaTypes.OPERATION + RestconfService.JSON,
- Draft11.MediaTypes.API + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.JSON,
- Draft11.MediaTypes.OPERATION + RestconfConstants.JSON, MediaType.APPLICATION_JSON })
+ Draft02.MediaTypes.OPERATION + RestconfService.JSON, Draft15.MediaTypes.DATA + RestconfConstants.JSON,
+ MediaType.APPLICATION_JSON })
public class NormalizedNodeJsonBodyWriter implements MessageBodyWriter<NormalizedNodeContext> {
private static final int DEFAULT_INDENT_SPACES_NUM = 2;
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.utils.RestconfConstants;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
@Provider
@Produces({ Draft02.MediaTypes.API + RestconfService.XML, Draft02.MediaTypes.DATA + RestconfService.XML,
- Draft02.MediaTypes.OPERATION + RestconfService.XML,
- Draft11.MediaTypes.API + RestconfConstants.XML, Draft11.MediaTypes.DATA + RestconfConstants.XML,
- Draft11.MediaTypes.OPERATION + RestconfConstants.XML, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ Draft02.MediaTypes.OPERATION + RestconfService.XML, Draft15.MediaTypes.DATA, MediaType.APPLICATION_XML,
+ MediaType.TEXT_XML })
public class NormalizedNodeXmlBodyWriter implements MessageBodyWriter<NormalizedNodeContext> {
private static final XMLOutputFactory XML_FACTORY;
import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext;
import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusEntity;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.yangtools.yang.data.codec.gson.JsonWriterFactory;
@Provider
@Produces({Draft02.MediaTypes.PATCH_STATUS + RestconfService.JSON,
- Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.JSON})
+ Draft15.MediaTypes.PATCH_STATUS + RestconfConstants.JSON})
public class PATCHJsonBodyWriter implements MessageBodyWriter<PATCHStatusContext> {
@Override
import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext;
import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusEntity;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
@Provider
@Produces({Draft02.MediaTypes.PATCH_STATUS + RestconfService.XML,
- Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.XML})
+ Draft15.MediaTypes.PATCH_STATUS + RestconfConstants.XML})
public class PATCHXmlBodyWriter implements MessageBodyWriter<PATCHStatusContext> {
private static final XMLOutputFactory XML_FACTORY;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.utils.RestconfConstants;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlUtils;
import org.w3c.dom.Element;
@Provider
-@Consumes({ Draft02.MediaTypes.DATA + RestconfService.XML, Draft11.MediaTypes.DATA + RestconfConstants.XML,
- Draft02.MediaTypes.OPERATION + RestconfService.XML, Draft11.MediaTypes.OPERATION + RestconfConstants.XML,
- MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+@Consumes({ Draft02.MediaTypes.DATA + RestconfService.XML, Draft02.MediaTypes.OPERATION + RestconfService.XML,
+ Draft15.MediaTypes.DATA, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
private final static Logger LOG = LoggerFactory.getLogger(XmlNormalizedNodeBodyReader.class);
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.utils.patch.Draft11XmlToPATCHBodyReader;
+import org.opendaylight.restconf.utils.patch.Draft15XmlToPATCHBodyReader;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.w3c.dom.NodeList;
/**
- * @deprecated This class will be replaced by {@link Draft11XmlToPATCHBodyReader}
+ * @deprecated This class will be replaced by {@link Draft15XmlToPATCHBodyReader}
*/
@Deprecated
@Provider
* </ul>
* </ul>
*
- * We used old revision {@link Draft11.RestconfModule#REVISION} of restconf yang
+ * We used old revision {@link Draft15.RestconfModule#REVISION} of restconf yang
* because the latest restconf draft has to be supported by Yang 1.1 and we are
* not. Then, this is only partial implementation of the latest restconf draft.
*/
-public final class Draft11 {
+public final class Draft15 {
- private Draft11() {
+ private Draft15() {
throw new UnsupportedOperationException("Util class");
}
throw new UnsupportedOperationException("Util class");
}
- public static final String API = "application/yang.api";
- public static final String DATASTORE = "application/yang.datastore";
- public static final String DATA = "application/yang.data";
- public static final String OPERATION = "application/yang.operation";
+ public static final String DATA = "application/yang-data";
public static final String PATCH = "application/yang.patch";
public static final String PATCH_STATUS = "application/yang.patch-status";
- public static final String ERRORS = "application/yang.errors";
public static final String YIN = "application/yin";
public static final String YANG = "application/yang";
}
public static final String ERROR_LIST_SCHEMA_NODE = "error";
- public static final QName IETF_RESTCONF_QNAME = QName.create(Draft11.RestconfModule.NAMESPACE, Draft11.RestconfModule.REVISION,
- Draft11.RestconfModule.NAME);
+ public static final QName IETF_RESTCONF_QNAME = QName.create(Draft15.RestconfModule.NAMESPACE, Draft15.RestconfModule.REVISION,
+ Draft15.RestconfModule.NAME);
public static final QName ERRORS_CONTAINER_QNAME = QName.create(IETF_RESTCONF_QNAME, ERRORS_CONTAINER_SCHEMA_NODE);
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.opendaylight.restconf;
import com.google.common.base.Preconditions;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.controller.sal.core.api.Broker.ProviderSession;
import org.opendaylight.controller.sal.core.api.Provider;
import org.opendaylight.controller.sal.core.api.model.SchemaService;
import org.opendaylight.netconf.sal.rest.api.RestConnector;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.restconf.common.wrapper.services.Draft11ServicesWrapperImpl;
+import org.opendaylight.restconf.common.wrapper.services.Draft15ServicesWrapperImpl;
import org.opendaylight.restconf.handlers.DOMDataBrokerHandler;
import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.handlers.RpcServiceHandler;
import org.slf4j.LoggerFactory;
/**
- * Provider for restconf draft11.
+ * Provider for restconf draft15.
*
*/
public class RestConnectorProvider implements Provider, RestConnector, AutoCloseable {
private static final Logger LOG = LoggerFactory.getLogger(RestConnectorProvider.class);
- private final TransactionChainListener transactionListener = new TransactionChainListener() {
+ public static final TransactionChainListener transactionListener = new TransactionChainListener() {
@Override
public void onTransactionChainFailed(final TransactionChain<?, ?> chain,
final AsyncTransaction<?, ?> transaction, final Throwable cause) {
LOG.warn("TransactionChain({}) {} FAILED!", chain, transaction.getIdentifier(), cause);
- chain.close();
resetTransactionChainForAdapaters(chain);
throw new RestconfDocumentedException("TransactionChain(" + chain + ") not committed correctly", cause);
}
};
private ListenerRegistration<SchemaContextListener> listenerRegistration;
- private DOMDataBroker dataBroker;
- private DOMTransactionChain transactionChain;
+ private static TransactionChainHandler transactionChainHandler;
+ private static DOMDataBroker dataBroker;
@Override
public void onSessionInitiated(final ProviderSession session) {
final SchemaService schemaService = Preconditions.checkNotNull(session.getService(SchemaService.class));
- final Draft11ServicesWrapperImpl wrapperServices = Draft11ServicesWrapperImpl.getInstance();
+ final Draft15ServicesWrapperImpl wrapperServices = Draft15ServicesWrapperImpl.getInstance();
final SchemaContextHandler schemaCtxHandler = new SchemaContextHandler();
this.listenerRegistration = schemaService.registerSchemaContextListener(schemaCtxHandler);
final DOMMountPointServiceHandler domMountPointServiceHandler = new DOMMountPointServiceHandler(
session.getService(DOMMountPointService.class));
- this.dataBroker = session.getService(DOMDataBroker.class);
- final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(this.dataBroker);
+ RestConnectorProvider.dataBroker = session.getService(DOMDataBroker.class);
+ final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(RestConnectorProvider.dataBroker);
- this.transactionChain = this.dataBroker.createTransactionChain(this.transactionListener);
- final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(this.transactionChain);
+ RestConnectorProvider.transactionChainHandler = new TransactionChainHandler(RestConnectorProvider.dataBroker
+ .createTransactionChain(RestConnectorProvider.transactionListener));
final DOMRpcService rpcService = session.getService(DOMRpcService.class);
final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
- wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler, transactionChainHandler,
- brokerHandler, rpcServiceHandler);
+ wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler,
+ RestConnectorProvider.transactionChainHandler, brokerHandler, rpcServiceHandler);
}
/**
- * After {@link TransactionChain} failed, this is creating new transaction
- * with listener.
+ * After {@link TransactionChain} failed, this updates {@link TransactionChainHandler} with new transaction chain.
*
* @param chain
* - old {@link TransactionChain}
*/
- private void resetTransactionChainForAdapaters(final TransactionChain<?, ?> chain) {
- LOG.trace("Resetting TransactionChain({}) to {}", chain, this.transactionChain);
- this.transactionChain = Preconditions.checkNotNull(this.dataBroker)
- .createTransactionChain(this.transactionListener);
+ public static void resetTransactionChainForAdapaters(final TransactionChain<?, ?> chain) {
+ LOG.trace("Resetting TransactionChain({})", chain);
+ chain.close();
+ RestConnectorProvider.transactionChainHandler.update(
+ Preconditions.checkNotNull(RestConnectorProvider.dataBroker).createTransactionChain(
+ RestConnectorProvider.transactionListener)
+ );
}
@Override
@Override
public void close() throws Exception {
+ // close registration
if (this.listenerRegistration != null) {
this.listenerRegistration.close();
}
- if (this.transactionChain != null) {
- this.transactionChain.close();
+
+ // close transaction chain
+ if (RestConnectorProvider.transactionChainHandler != null) {
+ RestConnectorProvider.transactionChainHandler.get().close();
}
}
}
import org.opendaylight.netconf.sal.rest.impl.PATCHXmlBodyWriter;
import org.opendaylight.netconf.sal.rest.impl.RestconfDocumentedExceptionMapper;
import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
-import org.opendaylight.restconf.common.wrapper.services.Draft11ServicesWrapperImpl;
-import org.opendaylight.restconf.utils.patch.Draft11JsonToPATCHBodyReader;
-import org.opendaylight.restconf.utils.patch.Draft11XmlToPATCHBodyReader;
+import org.opendaylight.restconf.common.wrapper.services.Draft15ServicesWrapperImpl;
+import org.opendaylight.restconf.utils.patch.Draft15JsonToPATCHBodyReader;
+import org.opendaylight.restconf.utils.patch.Draft15XmlToPATCHBodyReader;
public class RestconfApplication extends Application {
return ImmutableSet.<Class<?>> builder().add(NormalizedNodeJsonBodyWriter.class)
.add(NormalizedNodeXmlBodyWriter.class).add(JsonNormalizedNodeBodyReader.class)
.add(XmlNormalizedNodeBodyReader.class).add(SchemaExportContentYinBodyWriter.class)
- .add(Draft11JsonToPATCHBodyReader.class).add(Draft11XmlToPATCHBodyReader.class)
+ .add(Draft15JsonToPATCHBodyReader.class).add(Draft15XmlToPATCHBodyReader.class)
.add(PATCHJsonBodyWriter.class).add(PATCHXmlBodyWriter.class)
.add(SchemaExportContentYangBodyWriter.class).add(RestconfDocumentedExceptionMapper.class)
.build();
@Override
public Set<Object> getSingletons() {
final Set<Object> singletons = new HashSet<>();
- singletons.add(Draft11ServicesWrapperImpl.getInstance());
+ singletons.add(Draft15ServicesWrapperImpl.getInstance());
return singletons;
}
}
import java.util.Date;
import java.util.Set;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
* Get {@link Module} by ietf-restconf qname from
- * {@link Draft11.RestconfModule}
+ * {@link Draft15.RestconfModule}
*
* @return {@link Module}
*/
public Module getRestconfModule() {
- return this.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME.getNamespace(),
- Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision());
+ return this.findModuleByNamespaceAndRevision(Draft15.RestconfModule.IETF_RESTCONF_QNAME.getNamespace(),
+ Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision());
}
/**
import org.opendaylight.restconf.handlers.RpcServiceHandler;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.rest.services.api.Draft11BaseServicesWrapper;
+import org.opendaylight.restconf.rest.services.api.Draft15BaseServicesWrapper;
import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
import org.opendaylight.restconf.rest.services.api.RestconfOperationsService;
import org.opendaylight.restconf.rest.services.api.RestconfSchemaService;
import org.opendaylight.restconf.rest.services.impl.RestconfOperationsServiceImpl;
import org.opendaylight.restconf.rest.services.impl.RestconfSchemaServiceImpl;
import org.opendaylight.restconf.rest.services.impl.RestconfStreamsServiceImpl;
-import org.opendaylight.restconf.restful.services.api.Draft11TransactionServicesWrapper;
+import org.opendaylight.restconf.restful.services.api.Draft15TransactionServicesWrapper;
import org.opendaylight.restconf.restful.services.api.RestconfDataService;
import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService;
import org.opendaylight.restconf.restful.services.api.RestconfStreamsSubscriptionService;
/**
* Wrapper for services:
* <ul>
- * <li>{@link Draft11BaseServicesWrapper}
- * <li>{@link Draft11TransactionServicesWrapper}
+ * <li>{@link Draft15BaseServicesWrapper}
+ * <li>{@link Draft15TransactionServicesWrapper}
* </ul>
*
*/
@Path("/")
-public class Draft11ServicesWrapperImpl implements Draft11BaseServicesWrapper, Draft11TransactionServicesWrapper {
+public class Draft15ServicesWrapperImpl implements Draft15BaseServicesWrapper, Draft15TransactionServicesWrapper {
private RestconfDataService delegRestconfDataService;
private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
private RestconfStreamsService delegRestStrsService;
private RestconfSchemaService delegRestSchService;
- private Draft11ServicesWrapperImpl() {
+ private Draft15ServicesWrapperImpl() {
}
private static class InstanceHolder {
- public static final Draft11ServicesWrapperImpl INSTANCE = new Draft11ServicesWrapperImpl();
+ public static final Draft15ServicesWrapperImpl INSTANCE = new Draft15ServicesWrapperImpl();
}
- public static Draft11ServicesWrapperImpl getInstance() {
+ public static Draft15ServicesWrapperImpl getInstance() {
return InstanceHolder.INSTANCE;
}
}
@Override
- public NormalizedNodeContext readData(final String identifier, final UriInfo uriInfo) {
+ public Response readData(final String identifier, final UriInfo uriInfo) {
return this.delegRestconfDataService.readData(identifier, uriInfo);
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.restconf.handlers;
-import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+package org.opendaylight.restconf.handlers;
/**
* Handler for handling object prepared by provider for Restconf services
/**
* Get prepared object
*
- * @return {@link DOMTransactionChain}
+ * @return T
*/
T get();
+
+ /**
+ * Update object
+ *
+ * @param object
+ * - new object to update old object
+ */
+ default void update(T object) {}
}
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.opendaylight.restconf.handlers;
import com.google.common.base.Preconditions;
*/
public class TransactionChainHandler implements Handler<DOMTransactionChain> {
- private final DOMTransactionChain transactionChain;
+ private DOMTransactionChain transactionChain;
/**
* Prepare transaction chain service for Restconf services
this.transactionChain = transactionChain;
}
+ @Override
+ public void update(final DOMTransactionChain transactionChain) {
+ Preconditions.checkNotNull(transactionChain);
+ this.transactionChain = transactionChain;
+ }
+
@Override
public DOMTransactionChain get() {
return this.transactionChain;
* </ul>
*
*/
-public interface Draft11BaseServicesWrapper
+public interface Draft15BaseServicesWrapper
extends RestconfModulesService, RestconfOperationsService, RestconfStreamsService, RestconfSchemaService {
}
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
/**
* @return {@link NormalizedNodeContext}
*/
@GET
- @Path("data/ietf-yang-library:modules")
- @Produces({ Draft11.MediaTypes.API + RestconfConstants.JSON, Draft11.MediaTypes.API + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Path("data/ietf-yang-library:modules-state")
+ @Produces({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public NormalizedNodeContext getModules(@Context UriInfo uriInfo);
/**
* @return {@link NormalizedNodeContext}
*/
@GET
- @Path("data/ietf-yang-library:modules/{identifier:.+}")
- @Produces({ Draft11.MediaTypes.API + RestconfConstants.JSON, Draft11.MediaTypes.API + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Path("data/ietf-yang-library:modules-state/{identifier:.+}")
+ @Produces({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public NormalizedNodeContext getModules(@PathParam("identifier") String identifier, @Context UriInfo uriInfo);
/**
* @return {@link NormalizedNodeContext}
*/
@GET
- @Path("data/ietf-yang-library:modules/module/{identifier:.+}")
- @Produces({ Draft11.MediaTypes.API + RestconfConstants.JSON, Draft11.MediaTypes.API + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Path("data/ietf-yang-library:modules-state/module/{identifier:.+}")
+ @Produces({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public NormalizedNodeContext getModule(@PathParam("identifier") String identifier, @Context UriInfo uriInfo);
}
\ No newline at end of file
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
/**
*/
@GET
@Path("/operations")
- @Produces({ Draft11.MediaTypes.API + RestconfConstants.JSON, Draft11.MediaTypes.API + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Produces({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public NormalizedNodeContext getOperations(@Context UriInfo uriInfo);
/**
*/
@GET
@Path("/operations/{identifier:.+}")
- @Produces({ Draft11.MediaTypes.API + RestconfConstants.JSON, Draft11.MediaTypes.API + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Produces({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public NormalizedNodeContext getOperations(@PathParam("identifier") String identifier, @Context UriInfo uriInfo);
}
\ No newline at end of file
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
/**
* @return {@link SchemaExportContext}
*/
@GET
- @Produces({ Draft11.MediaTypes.YANG, Draft11.MediaTypes.YIN + RestconfConstants.XML })
+ @Produces({ Draft15.MediaTypes.YANG, Draft15.MediaTypes.YIN + RestconfConstants.XML })
@Path("data/ietf-yang-library:modules/module/{identifier:.+}/schema")
SchemaExportContext getSchema(@PathParam("identifier") String identifier);
}
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
/**
*/
@GET
@Path("data/ietf-restconf-monitoring:restconf-state/streams")
- @Produces({ Draft11.MediaTypes.API + RestconfConstants.JSON, Draft11.MediaTypes.API + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Produces({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
public NormalizedNodeContext getAvailableStreams(@Context UriInfo uriInfo);
}
\ No newline at end of file
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.common.references.SchemaContextRef;
import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
final MapNode moduleMap = RestconfMappingNodeUtil
.restconfMappingNode(schemaContextRef.getRestconfModule(), modules);
final DataSchemaNode moduleSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
- schemaContextRef.getRestconfModule(), Draft11.RestconfModule.MODULE_LIST_SCHEMA_NODE);
+ schemaContextRef.getRestconfModule(), Draft15.RestconfModule.MODULE_LIST_SCHEMA_NODE);
Preconditions.checkState(moduleSchemaNode instanceof ListSchemaNode);
if (mountPoint == null) {
return new NormalizedNodeContext(
final MapNode mapNodes = RestconfMappingNodeUtil.restconfMappingNode(restconfModule, modules);
final DataSchemaNode schemaNode = RestconfSchemaUtil.getRestconfSchemaNode(restconfModule,
- Draft11.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
+ Draft15.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
Preconditions.checkState(schemaNode instanceof ContainerSchemaNode);
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> modulContainerSchemaNodeBuilder = Builders
.containerBuilder((ContainerSchemaNode) schemaNode);
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.streams.listeners.Notificator;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.common.references.SchemaContextRef;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
final Set<String> availableStreams = Notificator.getStreamNames();
final DataSchemaNode streamListSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
- schemaContextRef.getRestconfModule(), Draft11.MonitoringModule.STREAM_LIST_SCHEMA_NODE);
+ schemaContextRef.getRestconfModule(), Draft15.MonitoringModule.STREAM_LIST_SCHEMA_NODE);
Preconditions.checkState(streamListSchemaNode instanceof ListSchemaNode);
final CollectionNodeBuilder<MapEntryNode, MapNode> listStreamBuilder = Builders
.mapBuilder((ListSchemaNode) streamListSchemaNode);
}
final DataSchemaNode streamContSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(
- schemaContextRef.getRestconfModule(), Draft11.MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE);
+ schemaContextRef.getRestconfModule(), Draft15.MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE);
Preconditions.checkState(streamContSchemaNode instanceof ContainerSchemaNode);
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> streamsContainerBuilder = Builders
.containerBuilder((ContainerSchemaNode) streamContSchemaNode);
* </ul>
*
*/
-public interface Draft11TransactionServicesWrapper
+public interface Draft15TransactionServicesWrapper
extends RestconfDataService, RestconfInvokeOperationsService, RestconfStreamsSubscriptionService {
}
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
/**
*/
@GET
@Path("/data/{identifier:.+}")
- @Produces({ Draft11.MediaTypes.DATA + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
- NormalizedNodeContext readData(@Encoded @PathParam("identifier") String identifier,
+ @Produces({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ Response readData(@Encoded @PathParam("identifier") String identifier,
@Context UriInfo uriInfo);
/**
*/
@PUT
@Path("/data/{identifier:.+}")
- @Consumes({ Draft11.MediaTypes.DATA + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Consumes({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
Response putData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload);
/**
*/
@POST
@Path("/data/{identifier:.+}")
- @Consumes({ Draft11.MediaTypes.DATA + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Consumes({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
Response postData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload,
@Context UriInfo uriInfo);
*/
@POST
@Path("/data")
- @Consumes({ Draft11.MediaTypes.DATA + RestconfConstants.JSON, Draft11.MediaTypes.DATA + RestconfConstants.XML,
- MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Consumes({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
Response postData(NormalizedNodeContext payload, @Context UriInfo uriInfo);
/**
*/
@PATCH
@Path("/data/{identifier:.+}")
- @Consumes({ Draft11.MediaTypes.PATCH + RestconfConstants.JSON, Draft11.MediaTypes.PATCH + RestconfConstants.XML })
- @Produces({ Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.JSON,
- Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.XML })
+ @Consumes({ Draft15.MediaTypes.PATCH + RestconfConstants.JSON, Draft15.MediaTypes.PATCH + RestconfConstants.XML })
+ @Produces({ Draft15.MediaTypes.PATCH_STATUS + RestconfConstants.JSON,
+ Draft15.MediaTypes.PATCH_STATUS + RestconfConstants.XML })
PATCHStatusContext patchData(@Encoded @PathParam("identifier") String identifier, PATCHContext context,
@Context UriInfo uriInfo);
*/
@PATCH
@Path("/data")
- @Consumes({ Draft11.MediaTypes.PATCH + RestconfConstants.JSON, Draft11.MediaTypes.PATCH + RestconfConstants.XML })
- @Produces({ Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.JSON,
- Draft11.MediaTypes.PATCH_STATUS + RestconfConstants.XML })
+ @Consumes({ Draft15.MediaTypes.PATCH + RestconfConstants.JSON, Draft15.MediaTypes.PATCH + RestconfConstants.XML })
+ @Produces({ Draft15.MediaTypes.PATCH_STATUS + RestconfConstants.JSON,
+ Draft15.MediaTypes.PATCH_STATUS + RestconfConstants.XML })
PATCHStatusContext patchData(PATCHContext context, @Context UriInfo uriInfo);
}
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
/**
*/
@POST
@Path("/operations/{identifier:.+}")
- @Produces({ Draft11.MediaTypes.OPERATION + RestconfConstants.JSON,
- Draft11.MediaTypes.OPERATION + RestconfConstants.XML, Draft11.MediaTypes.DATA + RestconfConstants.JSON,
- Draft11.MediaTypes.DATA + RestconfConstants.XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
- MediaType.TEXT_XML })
- @Consumes({ Draft11.MediaTypes.OPERATION + RestconfConstants.JSON,
- Draft11.MediaTypes.OPERATION + RestconfConstants.XML, Draft11.MediaTypes.DATA + RestconfConstants.JSON,
- Draft11.MediaTypes.DATA + RestconfConstants.XML, MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML,
- MediaType.TEXT_XML })
+ @Produces({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
+ @Consumes({ Draft15.MediaTypes.DATA + RestconfConstants.JSON, Draft15.MediaTypes.DATA, MediaType.APPLICATION_JSON,
+ MediaType.APPLICATION_XML, MediaType.TEXT_XML })
NormalizedNodeContext invokeRpc(@Encoded @PathParam("identifier") String identifier,
NormalizedNodeContext payload, @Context UriInfo uriInfo);
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
import org.opendaylight.netconf.sal.restconf.impl.PATCHStatusContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
+import org.opendaylight.restconf.RestConnectorProvider;
import org.opendaylight.restconf.common.references.SchemaContextRef;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.handlers.TransactionChainHandler;
}
@Override
- public NormalizedNodeContext readData(final String identifier, final UriInfo uriInfo) {
+ public Response readData(final String identifier, final UriInfo uriInfo) {
Preconditions.checkNotNull(identifier);
final SchemaContextRef schemaContextRef = new SchemaContextRef(this.schemaContextHandler.get());
- final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier, schemaContextRef.get());
+ final InstanceIdentifierContext<?> instanceIdentifier = ParserIdentifier.toInstanceIdentifier(identifier,
+ schemaContextRef.get());
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
final String value = uriInfo.getQueryParameters().getFirst(RestconfDataServiceConstant.CONTENT);
- DOMDataReadWriteTransaction transaction = null;
+ DOMTransactionChain transaction = null;
if (mountPoint == null) {
- transaction = this.transactionChainHandler.get().newReadWriteTransaction();
+ transaction = this.transactionChainHandler.get();
} else {
transaction = transactionOfMountPoint(mountPoint);
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(instanceIdentifier, mountPoint,
transaction);
final NormalizedNode<?, ?> node = ReadDataTransactionUtil.readData(value, transactionNode);
-
- return new NormalizedNodeContext(instanceIdentifier, node);
+ final SimpleDateFormat dateFormatGmt = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss");
+ dateFormatGmt.setTimeZone(TimeZone.getTimeZone("GMT"));
+ final String etag = '"' + node.getNodeType().getModule().getFormattedRevision()
+ + node.getNodeType().getLocalName() + '"';
+ Response resp = null;
+ if ((value == null) || value.contains(RestconfDataServiceConstant.ReadData.CONFIG)) {
+ resp = Response.status(200).entity(new NormalizedNodeContext(instanceIdentifier, node)).header("ETag", etag)
+ .header("Last-Modified", dateFormatGmt.toString()).build();
+ } else {
+ resp = Response.status(200).entity(new NormalizedNodeContext(instanceIdentifier, node)).build();
+ }
+ return resp;
}
@Override
PutDataTransactionUtil.validateListKeysEqualityInPayloadAndUri(payload);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- DOMDataReadWriteTransaction transaction = null;
+ DOMTransactionChain transaction = null;
SchemaContextRef ref = null;
if (mountPoint == null) {
- transaction = this.transactionChainHandler.get().newReadWriteTransaction();
+ transaction = this.transactionChainHandler.get();
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
transaction = transactionOfMountPoint(mountPoint);
Preconditions.checkNotNull(payload);
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- DOMDataReadWriteTransaction transaction = null;
+ DOMTransactionChain transaction = null;
SchemaContextRef ref = null;
if (mountPoint == null) {
- transaction = this.transactionChainHandler.get().newReadWriteTransaction();
+ transaction = this.transactionChainHandler.get();
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
transaction = transactionOfMountPoint(mountPoint);
schemaContextRef.get());
final DOMMountPoint mountPoint = instanceIdentifier.getMountPoint();
- final DOMDataReadWriteTransaction transaction;
+ final DOMTransactionChain transaction;
if (mountPoint == null) {
- transaction = this.transactionChainHandler.get().newReadWriteTransaction();
+ transaction = this.transactionChainHandler.get();
} else {
transaction = transactionOfMountPoint(mountPoint);
}
Preconditions.checkNotNull(context);
final DOMMountPoint mountPoint = context.getInstanceIdentifierContext().getMountPoint();
- final DOMDataReadWriteTransaction transaction;
+ final DOMTransactionChain transaction;
final SchemaContextRef ref;
if (mountPoint == null) {
- transaction = this.transactionChainHandler.get().newReadWriteTransaction();
+ transaction = this.transactionChainHandler.get();
ref = new SchemaContextRef(this.schemaContextHandler.get());
} else {
transaction = transactionOfMountPoint(mountPoint);
* @param mountPoint
* @return {@link DOMDataReadWriteTransaction}
*/
- private static DOMDataReadWriteTransaction transactionOfMountPoint(final DOMMountPoint mountPoint) {
+ private static DOMTransactionChain transactionOfMountPoint(final DOMMountPoint mountPoint) {
final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
if (domDataBrokerService.isPresent()) {
- return domDataBrokerService.get().newReadWriteTransaction();
+ return domDataBrokerService.get().createTransactionChain(RestConnectorProvider.transactionListener);
} else {
final String errMsg = "DOM data broker service isn't available for mount point "
+ mountPoint.getIdentifier();
package org.opendaylight.restconf.restful.transaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
/**
private final InstanceIdentifierContext<?> instanceIdentifier;
private final DOMMountPoint mountPoint;
private LogicalDatastoreType configuration = null;
- private final DOMDataReadWriteTransaction transaction;
+ private final DOMTransactionChain transactionChain;
/**
* Set base type of variables, which ones we need for transaction.
* - {@link InstanceIdentifierContext} of data for transaction
* @param mountPoint
* - mount point if is present
- * @param transaction
- * - {@link DOMDataReadWriteTransaction} transaction for
- * operations
+ * @param transactionChain
+ * - transaction chain for creating specific type of transaction
+ * in specific operation
*/
public TransactionVarsWrapper(final InstanceIdentifierContext<?> instanceIdentifier, final DOMMountPoint mountPoint,
- final DOMDataReadWriteTransaction transaction) {
+ final DOMTransactionChain transactionChain) {
this.instanceIdentifier = instanceIdentifier;
this.mountPoint = mountPoint;
- this.transaction = transaction;
+ this.transactionChain = transactionChain;
}
/**
}
/**
- * Get specific type of transaction
+ * Get transaction chain for creating specific transaction for specific
+ * operation
*
- * @return specific type transaction
+ * @return transaction chain
*/
- public DOMDataReadWriteTransaction getTransaction() {
- return this.transaction;
+ public DOMTransactionChain getTransactionChain() {
+ return this.transactionChain;
}
}
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
*/
public static Response deleteData(final TransactionVarsWrapper transactionNode) {
final CheckedFuture<Void, TransactionCommitFailedException> future = submitData(
- transactionNode.getTransaction(), transactionNode.getInstanceIdentifier().getInstanceIdentifier());
+ transactionNode.getTransactionChain(), transactionNode.getTransactionChain().newReadWriteTransaction(),
+ transactionNode.getInstanceIdentifier().getInstanceIdentifier());
final ResponseFactory response = new ResponseFactory();
FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE, response);
return response.build();
/**
* Delete data via transaction. Return error if data to delete does not exist.
*
+ * @param transactionChain
+ * - transaction chain
* @param readWriteTx
* - read and write transaction
* @param path
* @return {@link CheckedFuture}
*/
private static CheckedFuture<Void, TransactionCommitFailedException> submitData(
- final DOMDataReadWriteTransaction readWriteTx, final YangInstanceIdentifier path) {
- TransactionUtil.checkItemExists(readWriteTx, LogicalDatastoreType.CONFIGURATION, path,
+ final DOMTransactionChain transactionChain, final DOMDataReadWriteTransaction readWriteTx,
+ final YangInstanceIdentifier path) {
+ TransactionUtil.checkItemExists(transactionChain, readWriteTx, LogicalDatastoreType.CONFIGURATION, path,
RestconfDataServiceConstant.DeleteData.DELETE_TX_TYPE);
readWriteTx.delete(LogicalDatastoreType.CONFIGURATION, path);
return readWriteTx.submit();
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.restconf.RestConnectorProvider;
import org.opendaylight.restconf.common.references.SchemaContextRef;
import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper;
import org.opendaylight.restconf.restful.utils.RestconfDataServiceConstant.PatchData;
final SchemaContextRef schemaContextRef) {
final List<PATCHStatusEntity> editCollection = new ArrayList<>();
int errorCounter = 0;
+ final DOMDataReadWriteTransaction tx = transactionNode.getTransactionChain().newReadWriteTransaction();
for (final PATCHEntity patchEntity : context.getData()) {
final PATCHEditOperation operation = PATCHEditOperation.valueOf(patchEntity.getOperation().toUpperCase());
if (errorCounter == 0) {
try {
createDataWithinTransaction(LogicalDatastoreType.CONFIGURATION,
- patchEntity.getTargetNode(), patchEntity.getNode(),
- transactionNode.getTransaction(), schemaContextRef);
+ patchEntity.getTargetNode(), patchEntity.getNode(), tx, schemaContextRef);
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
case DELETE:
if (errorCounter == 0) {
try {
- deleteDataWithinTransaction(LogicalDatastoreType.CONFIGURATION,
- patchEntity.getTargetNode(), transactionNode.getTransaction());
+ deleteDataWithinTransaction(LogicalDatastoreType.CONFIGURATION, patchEntity.getTargetNode(),
+ tx);
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
if (errorCounter == 0) {
try {
mergeDataWithinTransaction(LogicalDatastoreType.CONFIGURATION,
- patchEntity.getTargetNode(), patchEntity.getNode(), transactionNode.getTransaction(),
- schemaContextRef);
+ patchEntity.getTargetNode(), patchEntity.getNode(), tx, schemaContextRef);
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
if (errorCounter == 0) {
try {
replaceDataWithinTransaction(LogicalDatastoreType.CONFIGURATION,
- patchEntity.getTargetNode(), patchEntity.getNode(), schemaContextRef,
- transactionNode.getTransaction());
+ patchEntity.getTargetNode(), patchEntity.getNode(), schemaContextRef, tx);
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
case REMOVE:
if (errorCounter == 0) {
try {
- removeDataWithinTransaction(LogicalDatastoreType.CONFIGURATION,
- patchEntity.getTargetNode(), transactionNode.getTransaction());
+ removeDataWithinTransaction(LogicalDatastoreType.CONFIGURATION, patchEntity.getTargetNode(),
+ tx);
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(), true, null));
} catch (final RestconfDocumentedException e) {
editCollection.add(new PATCHStatusEntity(patchEntity.getEditId(),
// if no errors then submit transaction, otherwise cancel
if (errorCounter == 0) {
final ResponseFactory response = new ResponseFactory();
- final CheckedFuture<Void, TransactionCommitFailedException> future = transactionNode
- .getTransaction().submit();
+ final CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
try {
FutureCallbackTx.addCallback(future, PatchData.PATCH_TX_TYPE, response);
return new PATCHStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), true, null);
} else {
- transactionNode.getTransaction().cancel();
+ tx.cancel();
+ RestConnectorProvider.resetTransactionChainForAdapaters(transactionNode.getTransactionChain());
return new PATCHStatusContext(context.getPatchId(), ImmutableList.copyOf(editCollection), false, null);
}
}
final YangInstanceIdentifier path,
final DOMDataReadWriteTransaction readWriteTransaction) {
LOG.trace("Delete {} within Restconf PATCH: {}", dataStore.name(), path);
- TransactionUtil.checkItemExists(readWriteTransaction, dataStore, path, PatchData.PATCH_TX_TYPE);
+ checkItemExistsWithinTransaction(readWriteTransaction, dataStore, path);
readWriteTransaction.delete(dataStore, path);
}
final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
if (errorIfExists) {
- TransactionUtil.checkItemDoesNotExists(
- rWTransaction, dataStore, childPath, PatchData.PATCH_TX_TYPE);
+ checkItemDoesNotExistsWithinTransaction(rWTransaction, dataStore, childPath);
}
rWTransaction.put(dataStore, childPath, child);
}
} else {
if (errorIfExists) {
- TransactionUtil.checkItemDoesNotExists(
- rWTransaction, dataStore, path, PatchData.PATCH_TX_TYPE);
+ checkItemDoesNotExistsWithinTransaction(rWTransaction, dataStore, path);
}
TransactionUtil.ensureParentsByMerge(path, schemaContext, rWTransaction);
rWTransaction.put(dataStore, path, payload);
}
}
+
+ /**
+ * Check if items already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
+ * data does NOT already exists.
+ * @param rWTransaction Transaction
+ * @param store Datastore
+ * @param path Path to be checked
+ */
+ public static void checkItemExistsWithinTransaction(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType store, final YangInstanceIdentifier path) {
+ final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
+ final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
+
+ FutureCallbackTx.addCallback(future, PatchData.PATCH_TX_TYPE, response);
+
+ if (!response.result) {
+ final String errMsg = "Operation via Restconf was not executed because data does not exist";
+ LOG.trace("{}:{}", errMsg, path);
+ throw new RestconfDocumentedException(
+ "Data does not exist", ErrorType.PROTOCOL, ErrorTag.DATA_MISSING, path);
+ }
+ }
+
+ /**
+ * Check if items do NOT already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
+ * data already exists.
+ * @param rWTransaction Transaction
+ * @param store Datastore
+ * @param path Path to be checked
+ */
+ public static void checkItemDoesNotExistsWithinTransaction(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType store, final YangInstanceIdentifier path) {
+ final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
+ final FutureDataFactory<Boolean> response = new FutureDataFactory<>();
+
+ FutureCallbackTx.addCallback(future, PatchData.PATCH_TX_TYPE, response);
+
+ if (response.result) {
+ final String errMsg = "Operation via Restconf was not executed because data already exists";
+ LOG.trace("{}:{}", errMsg, path);
+ throw new RestconfDocumentedException(
+ "Data already exists", ErrorType.PROTOCOL, ErrorTag.DATA_EXISTS, path);
+ }
+ }
}
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.restconf.common.references.SchemaContextRef;
import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper;
private static CheckedFuture<Void, TransactionCommitFailedException> submitData(final YangInstanceIdentifier path,
final NormalizedNode<?, ?> data, final TransactionVarsWrapper transactionNode,
final SchemaContext schemaContext) {
- final DOMDataReadWriteTransaction transaction = transactionNode.getTransaction();
+ final DOMTransactionChain transactionChain = transactionNode.getTransactionChain();
+ final DOMDataReadWriteTransaction transaction = transactionChain.newReadWriteTransaction();
final NormalizedNode<?, ?> node = ImmutableNodes.fromInstanceId(schemaContext, path);
transaction.put(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.create(node.getIdentifier()), node);
TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
if (data instanceof MapNode) {
for (final MapEntryNode child : ((MapNode) data).getValue()) {
- putChild(child, transaction, path);
+ putChild(child, transactionChain, transaction, path);
}
} else if (data instanceof AugmentationNode) {
for (final DataContainerChild<? extends PathArgument, ?> child : ((AugmentationNode) data).getValue()) {
- putChild(child, transaction, path);
+ putChild(child, transactionChain, transaction, path);
}
} else if (data instanceof ChoiceNode) {
for (final DataContainerChild<? extends PathArgument, ?> child : ((ChoiceNode) data).getValue()) {
- putChild(child, transaction, path);
+ putChild(child, transactionChain, transaction, path);
}
} else if (data instanceof LeafSetNode<?>) {
for (final LeafSetEntryNode<?> child : ((LeafSetNode<?>) data).getValue()) {
- putChild(child, transaction, path);
+ putChild(child, transactionChain, transaction, path);
}
} else if (data instanceof ContainerNode) {
for (final DataContainerChild<? extends PathArgument, ?> child : ((ContainerNode) data).getValue()) {
- putChild(child, transaction, path);
+ putChild(child, transactionChain, transaction, path);
}
}
+
return transaction.submit();
}
*
* @param child
* - data
+ * @param transactionChain
+ * - transaction chain
* @param readWriteTx
* - transaction
* @param path
* - path to data
*/
- private static void putChild(final NormalizedNode<?, ?> child, final DOMDataReadWriteTransaction readWriteTx,
- final YangInstanceIdentifier path) {
+ private static void putChild(final NormalizedNode<?, ?> child, final DOMTransactionChain transactionChain,
+ final DOMDataReadWriteTransaction readWriteTx, final YangInstanceIdentifier path) {
final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
- TransactionUtil.checkItemDoesNotExists(readWriteTx, LogicalDatastoreType.CONFIGURATION, childPath,
+ TransactionUtil.checkItemDoesNotExists(
+ transactionChain, readWriteTx, LogicalDatastoreType.CONFIGURATION, childPath,
RestconfDataServiceConstant.PostData.POST_TX_TYPE);
readWriteTx.put(LogicalDatastoreType.CONFIGURATION, childPath, child);
}
final ResponseFactory responseFactory = new ResponseFactory(
ReadDataTransactionUtil.readData(RestconfDataServiceConstant.ReadData.CONFIG, transactionNode));
final CheckedFuture<Void, TransactionCommitFailedException> submitData = submitData(path, schemaCtxRef.get(),
- transactionNode.getTransaction(), payload.getData());
+ transactionNode.getTransactionChain().newWriteOnlyTransaction(), payload.getData());
FutureCallbackTx.addCallback(submitData, RestconfDataServiceConstant.PutData.PUT_TX_TYPE, responseFactory);
return responseFactory.build();
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
+import java.util.Collection;
import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
private static NormalizedNode<?, ?> readDataViaTransaction(final TransactionVarsWrapper transactionNode) {
if (transactionNode.getLogicalDatastoreType() != null) {
final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> listenableFuture = transactionNode
- .getTransaction().read(transactionNode.getLogicalDatastoreType(),
+ .getTransactionChain().newReadOnlyTransaction().read(transactionNode.getLogicalDatastoreType(),
transactionNode.getInstanceIdentifier().getInstanceIdentifier());
final NormalizedNodeFactory dataFactory = new NormalizedNodeFactory();
FutureCallbackTx.addCallback(listenableFuture, RestconfDataServiceConstant.ReadData.READ_TYPE_TX,
final NormalizedNode<?, ?> configDataNode = readDataViaTransaction(transactionNode);
// if no data exists
- if (stateDataNode == null && configDataNode == null) {
+ if ((stateDataNode == null) && (configDataNode == null)) {
throw new RestconfDocumentedException(
"Request could not be completed because the relevant data model content does not exist",
ErrorType.PROTOCOL,
*/
private static NormalizedNode<?, ?> prepareData(final NormalizedNode<?, ?> configDataNode,
final NormalizedNode<?, ?> stateDataNode) {
- final MapNode immutableStateData = ImmutableNodes.mapNodeBuilder(stateDataNode.getNodeType())
+
+ if (configDataNode instanceof MapNode) { // part for lists mapping
+ final MapNode immutableStateData = ImmutableNodes.mapNodeBuilder(stateDataNode.getNodeType())
.addChild((MapEntryNode) stateDataNode).build();
- final MapNode immutableConfigData = ImmutableNodes.mapNodeBuilder(configDataNode.getNodeType())
+ final MapNode immutableConfigData = ImmutableNodes.mapNodeBuilder(configDataNode.getNodeType())
.addChild((MapEntryNode) configDataNode).build();
-
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = ImmutableNodes
+ final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder = ImmutableNodes
.mapEntryBuilder();
- mapEntryBuilder.withNodeIdentifier((NodeIdentifierWithPredicates) configDataNode.getIdentifier());
+ mapEntryBuilder.withNodeIdentifier((NodeIdentifierWithPredicates) configDataNode.getIdentifier());
- // MAP CONFIG DATA
- mapDataNode(immutableConfigData, mapEntryBuilder);
- // MAP STATE DATA
- mapDataNode(immutableStateData, mapEntryBuilder);
+ // MAP CONFIG DATA
+ mapDataNode(immutableConfigData, mapEntryBuilder);
+ // MAP STATE DATA
+ mapDataNode(immutableStateData, mapEntryBuilder);
+ return ImmutableNodes.mapNodeBuilder(configDataNode.getNodeType()).addChild(mapEntryBuilder.build()).build();
+ } else if (configDataNode instanceof ContainerNode) { // part for
+ // containers
+ // mapping
+ final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder = Builders
+ .containerBuilder((ContainerNode) configDataNode);
+ // MAP CONFIG DATA
+ mapCont(containerBuilder, ((ContainerNode) configDataNode).getValue());
+ // MAP STATE DATA
+ mapCont(containerBuilder, ((ContainerNode) stateDataNode).getValue());
- return ImmutableNodes.mapNodeBuilder(configDataNode.getNodeType()).addChild(mapEntryBuilder.build()).build();
+ return containerBuilder.build();
+ } else {
+ throw new RestconfDocumentedException("Bad type of node.");
+ }
+ }
+
+ /**
+ * Map data to builder
+ *
+ * @param containerBuilder
+ * - builder for mapping data
+ * @param childs
+ * - childs of data (container)
+ */
+ private static void mapCont(final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder,
+ final Collection<DataContainerChild<? extends PathArgument, ?>> childs) {
+ for (final DataContainerChild<? extends PathArgument, ?> child : childs) {
+ containerBuilder.addChild(child);
+ }
}
/**
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
+
package org.opendaylight.restconf.restful.utils;
import com.google.common.base.Preconditions;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.restconf.RestConnectorProvider;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
/**
* Check if items already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
* data does NOT already exists.
+ * @param transactionChain Transaction chain
* @param rWTransaction Transaction
* @param store Datastore
* @param path Path to be checked
* @param operationType Type of operation (READ, POST, PUT, DELETE...)
*/
- public static void checkItemExists(final DOMDataReadWriteTransaction rWTransaction,
+ public static void checkItemExists(final DOMTransactionChain transactionChain,
+ final DOMDataReadWriteTransaction rWTransaction,
final LogicalDatastoreType store, final YangInstanceIdentifier path,
final String operationType) {
final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
FutureCallbackTx.addCallback(future, operationType, response);
if (!response.result) {
+ // close transaction and reset transaction chain
+ rWTransaction.cancel();
+ RestConnectorProvider.resetTransactionChainForAdapaters(transactionChain);
+
+ // throw error
final String errMsg = "Operation via Restconf was not executed because data does not exist";
LOG.trace("{}:{}", errMsg, path);
throw new RestconfDocumentedException(
/**
* Check if items do NOT already exists at specified {@code path}. Throws {@link RestconfDocumentedException} if
* data already exists.
+ * @param transactionChain Transaction chain
* @param rWTransaction Transaction
* @param store Datastore
* @param path Path to be checked
* @param operationType Type of operation (READ, POST, PUT, DELETE...)
*/
- public static void checkItemDoesNotExists(final DOMDataReadWriteTransaction rWTransaction,
+ public static void checkItemDoesNotExists(final DOMTransactionChain transactionChain,
+ final DOMDataReadWriteTransaction rWTransaction,
final LogicalDatastoreType store, final YangInstanceIdentifier path,
final String operationType) {
final CheckedFuture<Boolean, ReadFailedException> future = rWTransaction.exists(store, path);
FutureCallbackTx.addCallback(future, operationType, response);
if (response.result) {
+ // close transaction and reset transaction chain
+ rWTransaction.cancel();
+ RestConnectorProvider.resetTransactionChainForAdapaters(transactionChain);
+
+ // throw error
final String errMsg = "Operation via Restconf was not executed because data already exists";
LOG.trace("{}:{}", errMsg, path);
throw new RestconfDocumentedException(
import com.google.common.base.Preconditions;
import java.util.Collection;
import java.util.Set;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.restconf.utils.schema.context.RestconfSchemaUtil;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
*/
public static MapNode restconfMappingNode(final Module restconfModule, final Set<Module> modules) {
final DataSchemaNode modulListSchemaNode = RestconfSchemaUtil.getRestconfSchemaNode(restconfModule,
- Draft11.RestconfModule.MODULE_LIST_SCHEMA_NODE);
+ Draft15.RestconfModule.MODULE_LIST_SCHEMA_NODE);
Preconditions.checkState(modulListSchemaNode instanceof ListSchemaNode);
final CollectionNodeBuilder<MapEntryNode, MapNode> listModuleBuilder = Builders
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.restconf.utils.parser.ParserIdentifier;
-public class Draft11AbstractIdentifierAwareJaxRsProvider {
+public class Draft15AbstractIdentifierAwareJaxRsProvider {
private static final String POST = "POST";
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.slf4j.LoggerFactory;
@Provider
-@Consumes({Draft11.MediaTypes.PATCH + RestconfConstants.JSON})
-public class Draft11JsonToPATCHBodyReader extends Draft11AbstractIdentifierAwareJaxRsProvider
+@Consumes({Draft15.MediaTypes.PATCH + RestconfConstants.JSON})
+public class Draft15JsonToPATCHBodyReader extends Draft15AbstractIdentifierAwareJaxRsProvider
implements MessageBodyReader<PATCHContext> {
- private final static Logger LOG = LoggerFactory.getLogger(Draft11JsonToPATCHBodyReader.class);
+ private final static Logger LOG = LoggerFactory.getLogger(Draft15JsonToPATCHBodyReader.class);
private String patchId;
@Override
private List<PATCHEntity> read(final JsonReader in, final InstanceIdentifierContext path) throws IOException {
final List<PATCHEntity> resultCollection = new ArrayList<>();
- final Draft11StringModuleInstanceIdentifierCodec codec = new Draft11StringModuleInstanceIdentifierCodec(
+ final Draft15StringModuleInstanceIdentifierCodec codec = new Draft15StringModuleInstanceIdentifierCodec(
path.getSchemaContext());
- final Draft11JsonToPATCHBodyReader.PatchEdit edit = new Draft11JsonToPATCHBodyReader.PatchEdit();
+ final Draft15JsonToPATCHBodyReader.PatchEdit edit = new Draft15JsonToPATCHBodyReader.PatchEdit();
while (in.hasNext()) {
switch (in.peek()) {
*/
private void parseByName(@Nonnull final String name, @Nonnull final PatchEdit edit,
@Nonnull final JsonReader in, @Nonnull final InstanceIdentifierContext path,
- @Nonnull final Draft11StringModuleInstanceIdentifierCodec codec,
+ @Nonnull final Draft15StringModuleInstanceIdentifierCodec codec,
@Nonnull final List<PATCHEntity> resultCollection) throws IOException {
switch (name) {
case "edit" :
*/
private void readEditDefinition(@Nonnull final PatchEdit edit, @Nonnull final JsonReader in,
@Nonnull final InstanceIdentifierContext path,
- @Nonnull final Draft11StringModuleInstanceIdentifierCodec codec) throws IOException {
+ @Nonnull final Draft15StringModuleInstanceIdentifierCodec codec) throws IOException {
final StringBuffer value = new StringBuffer();
in.beginObject();
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-final class Draft11StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
+final class Draft15StringModuleInstanceIdentifierCodec extends AbstractModuleStringInstanceIdentifierCodec {
private final DataSchemaContextTree dataContextTree;
private final SchemaContext context;
private final String defaultPrefix;
- Draft11StringModuleInstanceIdentifierCodec(SchemaContext context) {
+ Draft15StringModuleInstanceIdentifierCodec(SchemaContext context) {
this.context = Preconditions.checkNotNull(context);
this.dataContextTree = DataSchemaContextTree.from(context);
this.defaultPrefix = "";
}
- Draft11StringModuleInstanceIdentifierCodec(SchemaContext context, @Nonnull String defaultPrefix) {
+ Draft15StringModuleInstanceIdentifierCodec(SchemaContext context, @Nonnull String defaultPrefix) {
this.context = Preconditions.checkNotNull(context);
this.dataContextTree = DataSchemaContextTree.from(context);
this.defaultPrefix = defaultPrefix;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.w3c.dom.NodeList;
@Provider
-@Consumes({Draft11.MediaTypes.PATCH + RestconfConstants.XML})
-public class Draft11XmlToPATCHBodyReader extends Draft11AbstractIdentifierAwareJaxRsProvider implements
+@Consumes({Draft15.MediaTypes.PATCH + RestconfConstants.XML})
+public class Draft15XmlToPATCHBodyReader extends Draft15AbstractIdentifierAwareJaxRsProvider implements
MessageBodyReader<PATCHContext> {
- private final static Logger LOG = LoggerFactory.getLogger(Draft11XmlToPATCHBodyReader.class);
+ private final static Logger LOG = LoggerFactory.getLogger(Draft15XmlToPATCHBodyReader.class);
private static final DocumentBuilderFactory BUILDERFACTORY;
static {
URI.create(namespace)).iterator().next();
// initialize codec + set default prefix derived from module name
- final Draft11StringModuleInstanceIdentifierCodec codec = new Draft11StringModuleInstanceIdentifierCodec(
+ final Draft15StringModuleInstanceIdentifierCodec codec = new Draft15StringModuleInstanceIdentifierCodec(
pathContext.getSchemaContext(), module.getName());
// find complete path to target and target schema node
/**
* Prepare non-conditional XPath suitable for deserialization
- * with {@link Draft11StringModuleInstanceIdentifierCodec}
+ * with {@link Draft15StringModuleInstanceIdentifierCodec}
* @param schemaNode Top schema node
* @param target Edit operation target
* @param value Element with value
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
final Set<GroupingDefinition> groupings = restconfModule.getGroupings();
final GroupingDefinition restGroup = findSchemaNodeInCollection(groupings,
- Draft11.RestconfModule.RESTCONF_GROUPING_SCHEMA_NODE);
+ Draft15.RestconfModule.RESTCONF_GROUPING_SCHEMA_NODE);
final Collection<DataSchemaNode> childNodes = restGroup.getChildNodes();
final DataSchemaNode restCont = childNodes.iterator().next();
private static DataSchemaNode findSchemaNode(final DataSchemaNode restCont, final String schemaNodeName) {
switch (schemaNodeName) {
//MODULES
- case Draft11.RestconfModule.MODULE_LIST_SCHEMA_NODE:
+ case Draft15.RestconfModule.MODULE_LIST_SCHEMA_NODE:
final DataSchemaNode moduleListSchNode = findSchemaNodeInCollection(
((DataNodeContainer) findSchemaNode(restCont,
- Draft11.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE)).getChildNodes(),
- Draft11.RestconfModule.MODULE_LIST_SCHEMA_NODE);
+ Draft15.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE)).getChildNodes(),
+ Draft15.RestconfModule.MODULE_LIST_SCHEMA_NODE);
Preconditions.checkNotNull(moduleListSchNode);
return moduleListSchNode;
- case Draft11.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE:
+ case Draft15.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE:
final DataSchemaNode modulesContSchNode = findSchemaNodeInCollection(((DataNodeContainer) restCont).getChildNodes(),
- Draft11.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
+ Draft15.RestconfModule.MODULES_CONTAINER_SCHEMA_NODE);
Preconditions.checkNotNull(modulesContSchNode);
return modulesContSchNode;
//STREAMS
- case Draft11.MonitoringModule.STREAM_LIST_SCHEMA_NODE:
+ case Draft15.MonitoringModule.STREAM_LIST_SCHEMA_NODE:
final DataSchemaNode streamListSchNode = findSchemaNodeInCollection(
((DataNodeContainer) findSchemaNode(restCont,
- Draft11.MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE)).getChildNodes(),
- Draft11.MonitoringModule.STREAM_LIST_SCHEMA_NODE);
+ Draft15.MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE)).getChildNodes(),
+ Draft15.MonitoringModule.STREAM_LIST_SCHEMA_NODE);
Preconditions.checkNotNull(streamListSchNode);
return streamListSchNode;
- case Draft11.MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE:
+ case Draft15.MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE:
final DataSchemaNode streamsContSchNode = findSchemaNodeInCollection(
((DataNodeContainer) restCont).getChildNodes(),
- Draft11.MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE);
+ Draft15.MonitoringModule.STREAMS_CONTAINER_SCHEMA_NODE);
Preconditions.checkNotNull(streamsContSchNode);
return streamsContSchNode;
default:
<servlet-mapping>
<servlet-name>Restconf</servlet-name>
- <url-pattern>/11/*</url-pattern>
+ <url-pattern>/15/*</url-pattern>
</servlet-mapping>
<filter>
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
-import org.opendaylight.restconf.utils.patch.Draft11AbstractIdentifierAwareJaxRsProvider;
+import org.opendaylight.restconf.utils.patch.Draft15AbstractIdentifierAwareJaxRsProvider;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public abstract class Draft11AbstractBodyReaderTest {
public Draft11AbstractBodyReaderTest() throws NoSuchFieldException,
SecurityException {
- uriField = Draft11AbstractIdentifierAwareJaxRsProvider.class
+ uriField = Draft15AbstractIdentifierAwareJaxRsProvider.class
.getDeclaredField("uriInfo");
uriField.setAccessible(true);
- requestField = Draft11AbstractIdentifierAwareJaxRsProvider.class
+ requestField = Draft15AbstractIdentifierAwareJaxRsProvider.class
.getDeclaredField("request");
requestField.setAccessible(true);
mediaType = getMediaType();
return TestRestconfUtils.loadSchemaContext(yangPath, schemaContext);
}
- protected static <T extends Draft11AbstractIdentifierAwareJaxRsProvider> void mockBodyReader(
+ protected static <T extends Draft15AbstractIdentifierAwareJaxRsProvider> void mockBodyReader(
final String identifier, final T normalizedNodeProvider,
final boolean isPost) throws NoSuchFieldException,
SecurityException, IllegalArgumentException, IllegalAccessException {
import org.junit.Test;
import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.restconf.utils.patch.Draft11JsonToPATCHBodyReader;
+import org.opendaylight.restconf.utils.patch.Draft15JsonToPATCHBodyReader;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class TestDraft11JsonPATCHBodyReader extends Draft11AbstractBodyReaderTest {
- private final Draft11JsonToPATCHBodyReader jsonPATCHBodyReader;
+ private final Draft15JsonToPATCHBodyReader jsonPATCHBodyReader;
private static SchemaContext schemaContext;
public TestDraft11JsonPATCHBodyReader() throws NoSuchFieldException, SecurityException {
super();
- jsonPATCHBodyReader = new Draft11JsonToPATCHBodyReader();
+ jsonPATCHBodyReader = new Draft15JsonToPATCHBodyReader();
}
@Override
import org.junit.Test;
import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.restconf.utils.patch.Draft11XmlToPATCHBodyReader;
+import org.opendaylight.restconf.utils.patch.Draft15XmlToPATCHBodyReader;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public class TestDraft11XmlPATCHBodyReader extends Draft11AbstractBodyReaderTest {
- private final Draft11XmlToPATCHBodyReader xmlPATCHBodyReader;
+ private final Draft15XmlToPATCHBodyReader xmlPATCHBodyReader;
private static SchemaContext schemaContext;
public TestDraft11XmlPATCHBodyReader() throws NoSuchFieldException, SecurityException {
super();
- xmlPATCHBodyReader = new Draft11XmlToPATCHBodyReader();
+ xmlPATCHBodyReader = new Draft15XmlToPATCHBodyReader();
}
@Override
// verify interaction
verify(this.mockRegistration, times(1)).close();
+ verify(mockTransactionChain, times(1)).close();
}
}
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft11.RestconfModule;
+import org.opendaylight.restconf.Draft15.RestconfModule;
import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfModulesService;
import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.utils.RestconfConstants;
when(schemaContext.findModuleByNamespaceAndRevision(any(URI.class), any(Date.class))).thenAnswer(invocation -> {
final Object[] args = invocation.getArguments();
- if (args[0] == Draft11.RestconfModule.IETF_RESTCONF_QNAME.getNamespace()
- && args[1] == Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()) {
+ if (args[0] == Draft15.RestconfModule.IETF_RESTCONF_QNAME.getNamespace()
+ && args[1] == Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision()) {
return parseCustomRestconfSource(restconfModuleName).findModuleByName(
restconfModuleName, (Date) args[1]);
} else {
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
import org.opendaylight.netconf.sal.streams.listeners.Notificator;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeConstants;
public void getAvailableStreamsTest() throws Exception {
// prepare conditions - get correct Restconf module
when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
- when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
- .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
+ when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft15.RestconfModule.IETF_RESTCONF_QNAME
+ .getNamespace(), Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("ietf-restconf"));
// make test
public void getAvailableStreamsMissingRestconfModuleNegativeTest() {
// prepare conditions - get null Restconf module
when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
- when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
- .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision())).thenReturn(null);
+ when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft15.RestconfModule.IETF_RESTCONF_QNAME
+ .getNamespace(), Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision())).thenReturn(null);
// make test
this.thrown.expect(NullPointerException.class);
public void getAvailableStreamsMissingListStreamNegativeTest() {
// prepare conditions - get Restconf module with missing list stream
when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
- when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
- .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
+ when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft15.RestconfModule.IETF_RESTCONF_QNAME
+ .getNamespace(), Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-missing-list-stream"));
// make test and verify
public void getAvailableStreamsMissingContainerStreamsNegativeTest() {
// prepare conditions - get Restconf module with missing container streams
when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
- when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
- .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
+ when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft15.RestconfModule.IETF_RESTCONF_QNAME
+ .getNamespace(), Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-missing-container-streams"));
// make test and verify
public void getAvailableStreamsIllegalListStreamNegativeTest() {
// prepare conditions - get Restconf module with illegal list stream
when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
- when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
- .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
+ when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft15.RestconfModule.IETF_RESTCONF_QNAME
+ .getNamespace(), Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-illegal-list-stream"));
// make test
public void getAvailableStreamsIllegalContainerStreamsNegativeTest() {
// prepare conditions - get Restconf module with illegal container streams
when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
- when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
- .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
+ when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft15.RestconfModule.IETF_RESTCONF_QNAME
+ .getNamespace(), Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-illegal-container-streams"));
// make test
public void getAvailableStreamsIllegalLeafDescriptionNegativeTest() {
// prepare conditions - get Restconf module with illegal leaf description in list stream
when(this.contextHandler.get()).thenReturn(this.mockSchemaContext);
- when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft11.RestconfModule.IETF_RESTCONF_QNAME
- .getNamespace(), Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
+ when(this.mockSchemaContext.findModuleByNamespaceAndRevision(Draft15.RestconfModule.IETF_RESTCONF_QNAME
+ .getNamespace(), Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision()))
.thenReturn(getTestingRestconfModule("restconf-module-with-illegal-leaf-description"));
// make test
* @return Restconf module
*/
private Module getTestingRestconfModule(final String s) {
- return this.schemaContext.findModuleByName(s, Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision());
+ return this.schemaContext.findModuleByName(s, Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision());
}
/**
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
import com.google.common.util.concurrent.Futures;
+import java.lang.reflect.Field;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
+import org.junit.AfterClass;
import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
+import org.opendaylight.restconf.RestConnectorProvider;
+import org.opendaylight.restconf.handlers.TransactionChainHandler;
import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
public class DeleteDataTransactionUtilTest {
- @Mock DOMDataReadWriteTransaction transaction;
- @Mock InstanceIdentifierContext<?> context;
+ @Mock
+ private DOMTransactionChain transactionChain;
+ @Mock
+ private InstanceIdentifierContext<?> context;
+ @Mock
+ private DOMDataReadWriteTransaction readWrite;
+
+ // Fields used when delete operation fails to reset transaction chain
+ private static Field handler;
+ private static Field broker;
+
+ @BeforeClass
+ public static void setup() throws Exception {
+ DeleteDataTransactionUtilTest.handler = RestConnectorProvider.class.getDeclaredField("transactionChainHandler");
+ DeleteDataTransactionUtilTest.broker = RestConnectorProvider.class.getDeclaredField("dataBroker");
+
+ DeleteDataTransactionUtilTest.handler.setAccessible(true);
+ DeleteDataTransactionUtilTest.handler.set(RestConnectorProvider.class, mock(TransactionChainHandler.class));
+
+ DeleteDataTransactionUtilTest.broker.setAccessible(true);
+ DeleteDataTransactionUtilTest.broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
+ }
+
+ @AfterClass
+ public static void clean() throws Exception {
+ DeleteDataTransactionUtilTest.handler.set(RestConnectorProvider.class, null);
+ DeleteDataTransactionUtilTest.handler.setAccessible(false);
+
+ DeleteDataTransactionUtilTest.broker.set(RestConnectorProvider.class, null);
+ DeleteDataTransactionUtilTest.broker.setAccessible(false);
+ }
@Before
public void init() throws Exception {
MockitoAnnotations.initMocks(this);
- Mockito.when(this.transaction.submit()).thenReturn(Futures.immediateCheckedFuture(null));
- Mockito.when(context.getInstanceIdentifier()).thenReturn(YangInstanceIdentifier.EMPTY);
+ Mockito.when(this.transactionChain.newReadWriteTransaction()).thenReturn(this.readWrite);
+ Mockito.when(this.readWrite.submit()).thenReturn(Futures.immediateCheckedFuture(null));
+ Mockito.when(this.context.getInstanceIdentifier()).thenReturn(YangInstanceIdentifier.EMPTY);
}
/**
@Test
public void deleteData() throws Exception {
// assert that data to delete exists
- Mockito.when(this.transaction.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY))
+ Mockito.when(this.transactionChain.newReadWriteTransaction().exists(LogicalDatastoreType.CONFIGURATION,
+ YangInstanceIdentifier.EMPTY))
.thenReturn(Futures.immediateCheckedFuture(Boolean.TRUE));
// test
final Response response = DeleteDataTransactionUtil.deleteData(
- new TransactionVarsWrapper(this.context, null, this.transaction));
+ new TransactionVarsWrapper(this.context, null, this.transactionChain));
// assert success
assertEquals("Not expected response received", Status.OK.getStatusCode(), response.getStatus());
@Test
public void deleteDataNegativeTest() throws Exception {
// assert that data to delete does NOT exist
- Mockito.when(this.transaction.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY))
+ Mockito.when(this.transactionChain.newReadWriteTransaction().exists(LogicalDatastoreType.CONFIGURATION,
+ YangInstanceIdentifier.EMPTY))
.thenReturn(Futures.immediateCheckedFuture(Boolean.FALSE));
// test and assert error
try {
- DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null, this.transaction));
+ DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null, this.transactionChain));
fail("Delete operation should fail due to missing data");
} catch (final RestconfDocumentedException e) {
assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
-import org.opendaylight.restconf.Draft11;
-import org.opendaylight.restconf.Draft11.MonitoringModule;
-import org.opendaylight.restconf.Draft11.RestconfModule;
+import org.opendaylight.restconf.Draft15;
+import org.opendaylight.restconf.Draft15.MonitoringModule;
+import org.opendaylight.restconf.Draft15.RestconfModule;
import org.opendaylight.restconf.utils.schema.context.RestconfSchemaUtil;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
*/
private Module getTestingRestconfModule(final String s) {
return RestconfMappingNodeUtilTest.schemaContext.findModuleByName(
- s, Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision());
+ s, Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision());
}
/**
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import static org.opendaylight.restconf.Draft11.MonitoringModule;
-import static org.opendaylight.restconf.Draft11.RestconfModule;
+import static org.opendaylight.restconf.Draft15.MonitoringModule;
+import static org.opendaylight.restconf.Draft15.RestconfModule;
import com.google.common.collect.Sets;
import java.util.NoSuchElementException;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
-import org.opendaylight.restconf.Draft11;
+import org.opendaylight.restconf.Draft15;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
* @return Restconf module
*/
private Module getTestingRestconfModule(final String s) {
- return schemaContext.findModuleByName(s, Draft11.RestconfModule.IETF_RESTCONF_QNAME.getRevision());
+ return schemaContext.findModuleByName(s, Draft15.RestconfModule.IETF_RESTCONF_QNAME.getRevision());
}
}