Merge "Bug 509: Fixed incorrect merging of Data Store Writes / Events"
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / main / java / org / opendaylight / controller / sal / connect / netconf / InventoryUtils.java
1 /*
2  * Copyright (c) 2014 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 package org.opendaylight.controller.sal.connect.netconf;
9
10 import java.net.URI;
11 import java.text.ParseException;
12 import java.text.SimpleDateFormat;
13 import java.util.Date;
14
15 import org.opendaylight.yangtools.yang.common.QName;
16 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 public class InventoryUtils {
21     private static final Logger LOG = LoggerFactory.getLogger(InventoryUtils.class);
22     private static final URI INVENTORY_NAMESPACE = URI.create("urn:opendaylight:inventory");
23     private static final URI NETCONF_INVENTORY_NAMESPACE = URI.create("urn:opendaylight:netconf-node-inventory");
24     private static final Date INVENTORY_REVISION = dateFromString("2013-08-19");
25     private static final Date NETCONF_INVENTORY_REVISION = dateFromString("2014-01-08");
26     public static final QName INVENTORY_NODES = new QName(INVENTORY_NAMESPACE, INVENTORY_REVISION, "nodes");
27     public static final QName INVENTORY_NODE = new QName(INVENTORY_NAMESPACE, INVENTORY_REVISION, "node");
28     public static final QName INVENTORY_ID = new QName(INVENTORY_NAMESPACE, INVENTORY_REVISION, "id");
29     public static final QName INVENTORY_CONNECTED = new QName(NETCONF_INVENTORY_NAMESPACE, NETCONF_INVENTORY_REVISION,
30             "connected");
31     public static final QName NETCONF_INVENTORY_INITIAL_CAPABILITY = new QName(NETCONF_INVENTORY_NAMESPACE,
32             NETCONF_INVENTORY_REVISION, "initial-capability");
33
34     public static final InstanceIdentifier INVENTORY_PATH = InstanceIdentifier.builder().node(INVENTORY_NODES)
35             .toInstance();
36     public static final QName NETCONF_INVENTORY_MOUNT = null;
37
38     private InventoryUtils() {
39         throw new UnsupportedOperationException("Utility class cannot be instantiated");
40     }
41
42     /**
43      * Converts date in string format yyyy-MM-dd to java.util.Date.
44      *
45      * @return java.util.Date conformant to string formatted date yyyy-MM-dd.
46      */
47     private static Date dateFromString(final String date) {
48         // We do not reuse the formatter because it's not thread-safe
49         SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
50         try {
51             return formatter.parse(date);
52         } catch (ParseException e) {
53             LOG.error("Failed to parse date {}", date, e);
54             return null;
55         }
56     }
57 }