Decouple config and netconf subsystems.
[controller.git] / opendaylight / netconf / config-netconf-connector / src / main / java / org / opendaylight / controller / netconf / confignetconfconnector / operations / getconfig / GetConfig.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.controller.netconf.confignetconfconnector.operations.getconfig;
10
11 import com.google.common.base.Optional;
12 import org.opendaylight.controller.config.facade.xml.ConfigSubsystemFacade;
13 import org.opendaylight.controller.config.facade.xml.Datastore;
14 import org.opendaylight.controller.config.util.xml.DocumentedException;
15 import org.opendaylight.controller.config.util.xml.XmlElement;
16 import org.opendaylight.controller.netconf.api.xml.XmlNetconfConstants;
17 import org.opendaylight.controller.netconf.confignetconfconnector.operations.AbstractConfigNetconfOperation;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20 import org.w3c.dom.Document;
21 import org.w3c.dom.Element;
22
23 public class GetConfig extends AbstractConfigNetconfOperation {
24
25     public static final String GET_CONFIG = "get-config";
26
27     private final Optional<String> maybeNamespace;
28
29     private static final Logger LOG = LoggerFactory.getLogger(GetConfig.class);
30
31     public GetConfig(final ConfigSubsystemFacade configSubsystemFacade, final Optional<String> maybeNamespace, final String netconfSessionIdForReporting) {
32         super(configSubsystemFacade, netconfSessionIdForReporting);
33         this.maybeNamespace = maybeNamespace;
34     }
35
36     public static Datastore fromXml(XmlElement xml) throws DocumentedException {
37
38         xml.checkName(GET_CONFIG);
39         xml.checkNamespace(XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
40
41         XmlElement sourceElement = xml.getOnlyChildElement(XmlNetconfConstants.SOURCE_KEY,
42                 XmlNetconfConstants.URN_IETF_PARAMS_XML_NS_NETCONF_BASE_1_0);
43         XmlElement sourceNode = sourceElement.getOnlyChildElement();
44         String sourceParsed = sourceNode.getName();
45         LOG.debug("Setting source datastore to '{}'", sourceParsed);
46         Datastore sourceDatastore = Datastore.valueOf(sourceParsed);
47
48         // Filter option: ignore for now, TODO only load modules specified by the filter
49
50         return sourceDatastore;
51
52     }
53
54     @Override
55     protected String getOperationName() {
56         return GET_CONFIG;
57     }
58
59     @Override
60     public Element handleWithNoSubsequentOperations(Document document, XmlElement xml) throws DocumentedException {
61         return getConfigSubsystemFacade().getConfiguration(document, fromXml(xml), maybeNamespace);
62     }
63 }