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.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
import org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode;
import org.slf4j.LoggerFactory;
@Provider
-@Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft02.MediaTypes.OPERATION + RestconfService.JSON,
+@Consumes({ Draft02.MediaTypes.DATA + RestconfService.JSON, Draft11.MediaTypes.DATA + RestconfConstants.JSON,
+ Draft02.MediaTypes.OPERATION + RestconfService.JSON, Draft11.MediaTypes.OPERATION + RestconfConstants.JSON,
MediaType.APPLICATION_JSON })
public class JsonNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
}
}
- private static void propagateExceptionAs(Exception e) throws RestconfDocumentedException {
+ private static void propagateExceptionAs(final Exception e) throws RestconfDocumentedException {
if(e instanceof RestconfDocumentedException) {
throw (RestconfDocumentedException)e;
}
final List<YangInstanceIdentifier.PathArgument> iiToDataList = new ArrayList<>();
InstanceIdentifierContext<? extends SchemaNode> newIIContext;
- while (result instanceof AugmentationNode || result instanceof ChoiceNode) {
+ while ((result instanceof AugmentationNode) || (result instanceof ChoiceNode)) {
final Object childNode = ((DataContainerNode) result).getValue().iterator().next();
if (isPost) {
iiToDataList.add(result.getIdentifier());
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.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, Draft02.MediaTypes.OPERATION + RestconfService.XML,
+@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 })
public class XmlNormalizedNodeBodyReader extends AbstractIdentifierAwareJaxRsProvider implements MessageBodyReader<NormalizedNodeContext> {
}
private static AugmentationSchema findCorrespondingAugment(final DataSchemaNode parent, final DataSchemaNode child) {
- if (parent instanceof AugmentationTarget && !(parent instanceof ChoiceSchemaNode)) {
+ if ((parent instanceof AugmentationTarget) && !(parent instanceof ChoiceSchemaNode)) {
for (final AugmentationSchema augmentation : ((AugmentationTarget) parent).getAvailableAugmentations()) {
final DataSchemaNode childInAugmentation = augmentation.getDataChildByName(child.getQName());
if (childInAugmentation != null) {
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
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.handlers.DOMDataBrokerHandler;
import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+import org.opendaylight.restconf.handlers.RpcServiceHandler;
import org.opendaylight.restconf.handlers.SchemaContextHandler;
import org.opendaylight.restconf.handlers.TransactionChainHandler;
-import org.opendaylight.restconf.rest.services.impl.Draft11ServicesWrapperImpl;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.model.api.SchemaContextListener;
import org.slf4j.Logger;
session.getService(DOMMountPointService.class));
this.dataBroker = session.getService(DOMDataBroker.class);
+ final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(this.dataBroker);
+
this.transactionChain = this.dataBroker.createTransactionChain(this.transactionListener);
final TransactionChainHandler transactionChainHandler = new TransactionChainHandler(this.transactionChain);
- final DOMDataBrokerHandler brokerHandler = new DOMDataBrokerHandler(this.dataBroker);
+ final DOMRpcService rpcService = session.getService(DOMRpcService.class);
+ final RpcServiceHandler rpcServiceHandler = new RpcServiceHandler(rpcService);
- wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler);
+ wrapperServices.setHandlers(schemaCtxHandler, domMountPointServiceHandler, transactionChainHandler,
+ brokerHandler, rpcServiceHandler);
}
/**
import javax.ws.rs.core.Application;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYangBodyWriter;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContentYinBodyWriter;
+import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeXmlBodyWriter;
-import org.opendaylight.restconf.rest.services.impl.Draft11ServicesWrapperImpl;
+import org.opendaylight.netconf.sal.rest.impl.XmlNormalizedNodeBodyReader;
+import org.opendaylight.restconf.common.wrapper.services.Draft11ServicesWrapperImpl;
public class RestconfApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
return ImmutableSet.<Class<?>> builder().add(NormalizedNodeJsonBodyWriter.class)
- .add(NormalizedNodeXmlBodyWriter.class).add(SchemaExportContentYinBodyWriter.class)
+ .add(NormalizedNodeXmlBodyWriter.class).add(JsonNormalizedNodeBodyReader.class)
+ .add(XmlNormalizedNodeBodyReader.class).add(SchemaExportContentYinBodyWriter.class)
.add(SchemaExportContentYangBodyWriter.class)
.build();
}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.common.wrapper.services;
+
+import javax.ws.rs.Path;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
+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.handlers.DOMDataBrokerHandler;
+import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
+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.RestconfModulesService;
+import org.opendaylight.restconf.rest.services.api.RestconfOperationsService;
+import org.opendaylight.restconf.rest.services.api.RestconfSchemaService;
+import org.opendaylight.restconf.rest.services.api.RestconfStreamsService;
+import org.opendaylight.restconf.rest.services.impl.RestconfModulesServiceImpl;
+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.RestconfDataService;
+import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService;
+import org.opendaylight.restconf.restful.services.api.RestconfStreamsSubscriptionService;
+import org.opendaylight.restconf.restful.services.impl.RestconfDataServiceImpl;
+import org.opendaylight.restconf.restful.services.impl.RestconfInvokeOperationsServiceImpl;
+import org.opendaylight.restconf.restful.services.impl.RestconfStreamsSubscriptionServiceImpl;
+
+/**
+ * Wrapper for services:
+ * <ul>
+ * <li>{@link Draft11BaseServicesWrapper}
+ * <li>{@link Draft11TransactionServicesWrapper}
+ * </ul>
+ *
+ */
+@Path("/")
+public class Draft11ServicesWrapperImpl implements Draft11BaseServicesWrapper, Draft11TransactionServicesWrapper {
+
+ private RestconfDataService delegRestconfDataService;
+ private RestconfInvokeOperationsService delegRestconfInvokeOpsService;
+ private RestconfStreamsSubscriptionService delegRestconfSubscrService;
+ private RestconfModulesService delegRestModService;
+ private RestconfOperationsService delegRestOpsService;
+ private RestconfStreamsService delegRestStrsService;
+ private RestconfSchemaService delegRestSchService;
+
+ private Draft11ServicesWrapperImpl() {
+ }
+
+ private static class InstanceHolder {
+ public static final Draft11ServicesWrapperImpl INSTANCE = new Draft11ServicesWrapperImpl();
+ }
+
+ public static Draft11ServicesWrapperImpl getInstance() {
+ return InstanceHolder.INSTANCE;
+ }
+
+ @Override
+ public NormalizedNodeContext getModules(final UriInfo uriInfo) {
+ return this.delegRestModService.getModules(uriInfo);
+ }
+
+ @Override
+ public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
+ return this.delegRestModService.getModules(identifier, uriInfo);
+ }
+
+ @Override
+ public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
+ return this.delegRestModService.getModule(identifier, uriInfo);
+ }
+
+ @Override
+ public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
+ return this.delegRestOpsService.getOperations(uriInfo);
+ }
+
+ @Override
+ public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
+ return this.delegRestOpsService.getOperations(identifier, uriInfo);
+ }
+
+ @Override
+ public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
+ return this.delegRestStrsService.getAvailableStreams(uriInfo);
+ }
+
+ @Override
+ public SchemaExportContext getSchema(final String mountAndModuleId) {
+ return this.delegRestSchService.getSchema(mountAndModuleId);
+ }
+
+ @Override
+ public NormalizedNodeContext readData(final String identifier, final UriInfo uriInfo) {
+ return this.delegRestconfDataService.readData(identifier, uriInfo);
+ }
+
+ @Override
+ public Response putData(final String identifier, final NormalizedNodeContext payload) {
+ return this.delegRestconfDataService.putData(identifier, payload);
+ }
+
+ @Override
+ public Response postData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
+ return this.delegRestconfDataService.postData(identifier, payload, uriInfo);
+ }
+
+ @Override
+ public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
+ return this.delegRestconfDataService.postData(payload, uriInfo);
+ }
+
+ @Override
+ public Response deleteData(final String identifier) {
+ return this.delegRestconfDataService.deleteData(identifier);
+ }
+
+ @Override
+ public PATCHStatusContext patchData(final String identifier, final PATCHContext context, final UriInfo uriInfo) {
+ return this.delegRestconfDataService.patchData(identifier, context, uriInfo);
+ }
+
+ @Override
+ public PATCHStatusContext patchData(final PATCHContext context, final UriInfo uriInfo) {
+ return this.delegRestconfDataService.patchData(context, uriInfo);
+ }
+
+ @Override
+ public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload,
+ final UriInfo uriInfo) {
+ return this.delegRestconfInvokeOpsService.invokeRpc(identifier, payload, uriInfo);
+ }
+
+ @Override
+ public Response subscribeToStream(final String identifier, final UriInfo uriInfo) {
+ return this.delegRestconfSubscrService.subscribeToStream(identifier, uriInfo);
+ }
+
+ public void setHandlers(final SchemaContextHandler schemaCtxHandler,
+ final DOMMountPointServiceHandler domMountPointServiceHandler,
+ final TransactionChainHandler transactionChainHandler, final DOMDataBrokerHandler domDataBrokerHandler,
+ final RpcServiceHandler rpcServiceHandler) {
+ this.delegRestModService = new RestconfModulesServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+ this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+ this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
+ this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaCtxHandler);
+ this.delegRestconfDataService = new RestconfDataServiceImpl(schemaCtxHandler, transactionChainHandler);
+ this.delegRestconfInvokeOpsService = new RestconfInvokeOperationsServiceImpl(rpcServiceHandler,
+ schemaCtxHandler);
+ this.delegRestconfSubscrService = new RestconfStreamsSubscriptionServiceImpl(domDataBrokerHandler);
+ }
+}
*/
package org.opendaylight.restconf.parser.builder;
-import static org.opendaylight.restconf.utils.parser.builder.ParserBuilderConstants.Serializer;
import com.google.common.base.Preconditions;
import java.net.URI;
import java.util.Map.Entry;
import org.opendaylight.restconf.utils.RestconfConstants;
import org.opendaylight.restconf.utils.parser.builder.ParserBuilderConstants;
+import org.opendaylight.restconf.utils.parser.builder.ParserBuilderConstants.Serializer;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
+import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
// condition is satisfied also for the first path argument
if (!arg.getNodeType().getModule().equals(parentModule)) {
path.append(RestconfConstants.SLASH
- + prefixForNamespace(arg.getNodeType())
+ + prefixForNamespace(arg.getNodeType(), schemaContext)
+ ParserBuilderConstants.Deserializer.COLON);
} else {
path.append(RestconfConstants.SLASH);
* - {@link QName}
* @return {@link String}
*/
- private static String prefixForNamespace(final QName qname) {
+ private static String prefixForNamespace(final QName qname, final SchemaContext schemaContext) {
final URI namespace = qname.getNamespace();
Preconditions.checkArgument(namespace != null, "Failed to map QName {}", qname);
- final String prefix = namespace.toString();
- return prefix.replace(ParserBuilderConstants.Deserializer.COLON, ParserBuilderConstants.Deserializer.HYPHEN);
+ final Module module = schemaContext.findModuleByNamespaceAndRevision(namespace, qname.getRevision());
+ return module.getName();
}
private static final class MainVarsWrapper {
*/
package org.opendaylight.restconf.rest.services.api;
-import javax.ws.rs.Path;
-
/**
- * Wrapper for all services:
+ * Wrapper for all base services:
* <ul>
* <li>{@link RestconfModulesService}
* <li>{@link RestconfOperationsService}
* </ul>
*
*/
-@Path("/")
-public interface Draft11ServicesWrapper
+public interface Draft11BaseServicesWrapper
extends RestconfModulesService, RestconfOperationsService, RestconfStreamsService, RestconfSchemaService {
}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * 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.rest.services.impl;
-
-import javax.ws.rs.core.UriInfo;
-import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
-import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
-import org.opendaylight.restconf.handlers.DOMMountPointServiceHandler;
-import org.opendaylight.restconf.handlers.SchemaContextHandler;
-import org.opendaylight.restconf.rest.services.api.Draft11ServicesWrapper;
-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.api.RestconfStreamsService;
-
-/**
- * Implementation of {@link Draft11ServicesWrapper}
- *
- */
-public class Draft11ServicesWrapperImpl implements Draft11ServicesWrapper {
-
- private RestconfModulesService delegRestModService;
- private RestconfOperationsService delegRestOpsService;
- private RestconfStreamsService delegRestStrsService;
- private RestconfSchemaService delegRestSchService;
-
- private Draft11ServicesWrapperImpl() {
- }
-
- @Override
- public NormalizedNodeContext getModules(final UriInfo uriInfo) {
- return this.delegRestModService.getModules(uriInfo);
- }
-
- @Override
- public NormalizedNodeContext getModules(final String identifier, final UriInfo uriInfo) {
- return this.delegRestModService.getModules(identifier, uriInfo);
- }
-
- @Override
- public NormalizedNodeContext getModule(final String identifier, final UriInfo uriInfo) {
- return this.delegRestModService.getModule(identifier, uriInfo);
- }
-
- @Override
- public NormalizedNodeContext getOperations(final UriInfo uriInfo) {
- return this.delegRestOpsService.getOperations(uriInfo);
- }
-
- @Override
- public NormalizedNodeContext getOperations(final String identifier, final UriInfo uriInfo) {
- return this.delegRestOpsService.getOperations(identifier, uriInfo);
- }
-
- @Override
- public NormalizedNodeContext getAvailableStreams(final UriInfo uriInfo) {
- return this.delegRestStrsService.getAvailableStreams(uriInfo);
- }
-
- @Override
- public SchemaExportContext getSchema(final String mountAndModuleId) {
- return this.delegRestSchService.getSchema(mountAndModuleId);
- }
-
- public static Draft11ServicesWrapperImpl getInstance() {
- return InstanceHolder.INSTANCE;
- }
-
- private static class InstanceHolder {
- public static final Draft11ServicesWrapperImpl INSTANCE = new Draft11ServicesWrapperImpl();
- }
-
- public void setHandlers(final SchemaContextHandler schemaCtxHandler,
- final DOMMountPointServiceHandler domMountPointServiceHandler) {
- this.delegRestModService = new RestconfModulesServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
- this.delegRestOpsService = new RestconfOperationsServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
- this.delegRestSchService = new RestconfSchemaServiceImpl(schemaCtxHandler, domMountPointServiceHandler);
- this.delegRestStrsService = new RestconfStreamsServiceImpl(schemaCtxHandler);
- }
-
-}
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * 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.services.api;
+
+/**
+ * Wrapper for all transaction services:
+ * <ul>
+ * <li>{@link RestconfDataService}
+ * <li>{@link RestconfInvokeOperationsService}
+ * <li>{@link RestconfStreamsSubscriptionService}
+ * </ul>
+ *
+ */
+public interface Draft11TransactionServicesWrapper
+ extends RestconfDataService, RestconfInvokeOperationsService, RestconfStreamsSubscriptionService {
+
+}
private final static Logger LOG = LoggerFactory.getLogger(RestconfDataServiceImpl.class);
- private SchemaContextHandler schemaContextHandler;
- private TransactionChainHandler transactionChainHandler;
+ private final SchemaContextHandler schemaContextHandler;
+ private final TransactionChainHandler transactionChainHandler;
+
+ public RestconfDataServiceImpl(final SchemaContextHandler schemaContextHandler,
+ final TransactionChainHandler transactionChainHandler) {
+ this.schemaContextHandler = schemaContextHandler;
+ this.transactionChainHandler = transactionChainHandler;
+ }
@Override
public NormalizedNodeContext readData(final String identifier, final UriInfo uriInfo) {
*/
public class RestconfInvokeOperationsServiceImpl implements RestconfInvokeOperationsService {
- private RpcServiceHandler rpcServiceHandler;
- private SchemaContextHandler schemaContextHandler;
+ private final RpcServiceHandler rpcServiceHandler;
+ private final SchemaContextHandler schemaContextHandler;
+
+ public RestconfInvokeOperationsServiceImpl(final RpcServiceHandler rpcServiceHandler,
+ final SchemaContextHandler schemaContextHandler) {
+ this.rpcServiceHandler = rpcServiceHandler;
+ this.schemaContextHandler = schemaContextHandler;
+ }
@Override
public NormalizedNodeContext invokeRpc(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
private static final Logger LOG = LoggerFactory.getLogger(RestconfStreamsSubscriptionServiceImpl.class);
- private DOMDataBrokerHandler domDataBrokerHandler;
+ private final DOMDataBrokerHandler domDataBrokerHandler;
+
+ public RestconfStreamsSubscriptionServiceImpl(final DOMDataBrokerHandler domDataBrokerHandler) {
+ this.domDataBrokerHandler = domDataBrokerHandler;
+ }
@Override
public Response subscribeToStream(final String identifier, final UriInfo uriInfo) {
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import java.util.concurrent.CountDownLatch;
import javax.annotation.Nullable;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.slf4j.Logger;
*/
static <T, X extends Exception> void addCallback(final CheckedFuture<T, X> listenableFuture, final String txType,
final FutureDataFactory<T> dataFactory) {
+ final CountDownLatch responseWaiter = new CountDownLatch(1);
Futures.addCallback(listenableFuture, new FutureCallback<T>() {
@Override
public void onFailure(final Throwable t) {
handlingLoggerAndValues(t, txType, null, null);
+ responseWaiter.countDown();
}
@Override
public void onSuccess(final T result) {
handlingLoggerAndValues(null, txType, result, dataFactory);
+ responseWaiter.countDown();
}
});
+ try {
+ responseWaiter.await();
+ } catch (final InterruptedException e) {
+ final String msg = "Problem while waiting for response";
+ LOG.warn(msg);
+ throw new RestconfDocumentedException(msg, e);
+ }
}
/**
protected static <T> void handlingLoggerAndValues(@Nullable final Throwable t, final String txType,
final T result, final FutureDataFactory<T> dataFactory) {
if (t != null) {
- LOG.info("Transaction({}) FAILED!", txType, t);
+ LOG.warn("Transaction({}) FAILED!", txType, t);
throw new RestconfDocumentedException(" Transaction(" + txType + ") not committed correctly", t);
} else {
LOG.trace("Transaction({}) SUCCESSFUL!", txType);