2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.restconf.handlers;
10 import com.google.common.base.Preconditions;
11 import java.util.Collection;
12 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
13 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
14 import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
15 import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
16 import org.opendaylight.restconf.Draft18.IetfYangLibrary;
17 import org.opendaylight.restconf.Draft18.MonitoringModule;
18 import org.opendaylight.restconf.utils.mapping.RestconfMappingNodeUtil;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 * Implementation of {@link SchemaContextHandler}
31 public class SchemaContextHandler implements SchemaContextListenerHandler {
33 private SchemaContext context;
35 private int moduleSetId;
36 private final TransactionChainHandler transactionChainHandler;
39 * Set module-set-id on initial value - 0
41 * @param transactionChainHandler
43 public SchemaContextHandler(final TransactionChainHandler transactionChainHandler) {
44 this.transactionChainHandler = transactionChainHandler;
49 public void onGlobalContextUpdated(final SchemaContext context) {
50 Preconditions.checkNotNull(context);
52 this.context = context;
54 final Module ietfYangLibraryModule =
55 context.findModuleByNamespaceAndRevision(IetfYangLibrary.URI_MODULE, IetfYangLibrary.DATE);
56 NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode =
57 RestconfMappingNodeUtil.mapModulesByIetfYangLibraryYang(context.getModules(), ietfYangLibraryModule,
58 context, String.valueOf(this.moduleSetId));
61 final Module monitoringModule =
62 this.context.findModuleByNamespaceAndRevision(MonitoringModule.URI_MODULE, MonitoringModule.DATE);
63 normNode = RestconfMappingNodeUtil.mapCapabilites(monitoringModule);
68 public SchemaContext get() {
73 final NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode) {
74 final DOMDataWriteTransaction wTx = this.transactionChainHandler.get().newWriteOnlyTransaction();
75 wTx.put(LogicalDatastoreType.OPERATIONAL,
76 YangInstanceIdentifier.create(NodeIdentifier.create(normNode.getNodeType())), normNode);
78 wTx.submit().checkedGet();
79 } catch (final TransactionCommitFailedException e) {
80 throw new RestconfDocumentedException("Problem occured while putting data to DS.", e);