diff options
author | Timoney, Daniel (dt5972) <dtimoney@att.com> | 2017-02-15 10:37:53 -0500 |
---|---|---|
committer | Timoney, Daniel (dt5972) <dtimoney@att.com> | 2017-02-15 10:40:37 -0500 |
commit | 324ee36fe31763e507b422ab0a88e4230045e205 (patch) | |
tree | d0b04520f6657601c918ce63fd27575977624187 /dgbuilder/tools | |
parent | f0c97e8db427481e28c0a16b789bc73801b35e47 (diff) |
Initial commit for OpenECOMP SDN-C OA&M
Change-Id: I7ab579fd0d206bf356f36d52dcdf4f71f1fa2680
Signed-off-by: Timoney, Daniel (dt5972) <dtimoney@att.com>
Former-commit-id: 2a9f0edd09581f907e62ec4689b5ac94dd5382ba
Diffstat (limited to 'dgbuilder/tools')
28 files changed, 2877 insertions, 0 deletions
diff --git a/dgbuilder/tools/FormatXml.java b/dgbuilder/tools/FormatXml.java new file mode 100644 index 00000000..7c6915f7 --- /dev/null +++ b/dgbuilder/tools/FormatXml.java @@ -0,0 +1,49 @@ +import javax.xml.transform.*; +import javax.xml.transform.stream.*; +import java.io.*; +import java.util.*; +import java.nio.file.Paths; +import java.nio.file.Files; +import java.nio.charset.StandardCharsets; +import java.nio.charset.Charset; +public class FormatXml{ +public static String formatXml(String input, int indent) { + try { + Source xmlInput = new StreamSource(new StringReader(input)); + StringWriter stringWriter = new StringWriter(); + StreamResult xmlOutput = new StreamResult(stringWriter); + TransformerFactory transformerFactory = TransformerFactory.newInstance(); + transformerFactory.setAttribute("indent-number", indent); + Transformer transformer = transformerFactory.newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.transform(xmlInput, xmlOutput); + return xmlOutput.getWriter().toString(); + } catch (Exception e) { + throw new RuntimeException(e); // simple exception handling, please review it + } +} + +public static String prettyFormat(String input) { + return formatXml(input, 2); +} + +public static String readFile(String path, Charset encoding) + throws IOException +{ + byte[] encoded = Files.readAllBytes(Paths.get(path)); + return new String(encoded, encoding); +} + +public static void main(String[] args){ +try{ + if (args != null && args.length != 1){ + System.out.println("Usage:java FormatXml xmlStr"); + System.exit(-1); + } + String xmlStr = readFile(args[0], StandardCharsets.UTF_8); + System.out.println(prettyFormat(xmlStr)); +}catch(Exception e){ + e.printStackTrace(); +} +} +} diff --git a/dgbuilder/tools/PrintYangToProp.java b/dgbuilder/tools/PrintYangToProp.java new file mode 100644 index 00000000..93aaac79 --- /dev/null +++ b/dgbuilder/tools/PrintYangToProp.java @@ -0,0 +1,1424 @@ + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.PrintStream; +import java.io.FileDescriptor; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.util.LinkedList; +import java.util.List; +import java.util.Properties; +import java.util.Arrays; +import java.util.ArrayList; +import java.io.*; +import javax.json.*; +import org.opendaylight.yangtools.yang.binding.Identifier; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddress; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv4Address; +import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Ipv6Address; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.CaseFormat; + +public class PrintYangToProp { + + private static final Logger LOG = LoggerFactory.getLogger(PrintYangToProp.class); + public static final String PROPERTIES_FILE="/opt/bvc/controller/configuration/flowred.properties"; + private static Properties properties; + + static { + + // Trick class loader into loading builders. Some of + // these will be needed later by Reflection classes, but need + // to explicitly "new" them here to get class loader to load them. +/* + ServiceInformationBuilder b2 = new ServiceInformationBuilder(); + ServiceDataBuilder b3 = new ServiceDataBuilder(); + SdncRequestHeaderBuilder b4 = new SdncRequestHeaderBuilder(); + RequestInformationBuilder b6 = new RequestInformationBuilder(); + + FlowredGroupInformationDataBuilder b29 = new FlowredGroupInformationDataBuilder(); + FlowredInformationDataBuilder b48 = new FlowredInformationDataBuilder(); + + OperStatusBuilder b41 = new OperStatusBuilder(); +*/ + + + } + + public static void loadProperties() { + /* + + File file = new File(PROPERTIES_FILE); + properties = new Properties(); + InputStream input = null; + if (file.isFile() && file.canRead()) { + try { + input = new FileInputStream(file); + properties.load(input); + LOG.info("Loaded properties from " + PROPERTIES_FILE ); + } catch (Exception e) { + LOG.error("Failed to load properties " + PROPERTIES_FILE +"\n",e); + } finally { + if (input != null) { + try { + input.close(); + } catch (IOException e) { + LOG.error("Failed to close properties file " + PROPERTIES_FILE +"\n",e); + } + } + } + } + */ + } + + public static Properties toProperties(Properties props, Object fromObj) { + Class fromClass = null; + + if (fromObj != null) + { + fromClass = fromObj.getClass(); + } + return (toProperties(props, "", fromObj, fromClass)); + } + + public static Properties toProperties(Properties props, String pfx, Object fromObj) + { + Class fromClass = null; + + if (fromObj != null) + { + fromClass = fromObj.getClass(); + } + + return(toProperties(props, pfx, fromObj, fromClass)); + } + + public static Properties toProperties(Properties props, String pfx, + Object fromObj, Class fromClass) { + + if (fromObj == null) { + return (props); + } + + + String simpleName = fromClass.getSimpleName(); + + //LOG.debug("Extracting properties from " + fromClass.getName() + // + " class"); + if (fromObj instanceof List) { + + // Class is a List. List should contain yang-generated classes. + //LOG.debug(fromClass.getName() + " is a List"); + + List fromList = (List) fromObj; + + for (int i = 0; i < fromList.size(); i++) { + toProperties(props, pfx + "[" + i + "]", fromList.get(i), fromClass); + } + props.setProperty(pfx + "_length", "" + fromList.size()); + + } else if (isYangGenerated(fromClass)) { + // Class is yang generated. + //LOG.debug(fromClass.getName() + " is a Yang-generated class"); + + String propNamePfx = null; + + // If called from a list (so prefix ends in ']'), don't + // add class name again + if (pfx.endsWith("]")) { + propNamePfx = pfx; + } else { + if ((pfx != null) && (pfx.length() > 0)) { + propNamePfx = pfx ; + } else { + propNamePfx = toLowerHyphen(fromClass.getSimpleName()); + } + + if (propNamePfx.endsWith("-builder")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() + - "-builder".length()); + } + + if (propNamePfx.endsWith("-impl")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() + - "-impl".length()); + } + } + + // Iterate through getter methods to figure out values we need to + // save from + + for (Method m : fromClass.getMethods()) { + // LOG.debug("Checking " + m.getName() + " method"); + if (isGetter(m)) { + // LOG.debug(m.getName() + " is a getter"); + Class returnType = m.getReturnType(); + String fieldName = toLowerHyphen(m.getName().substring(3)); + if(m != null && m.getName().matches("^is[A-Z].*")){ + fieldName = toLowerHyphen(m.getName().substring(2)); + } + + fieldName = fieldName.substring(0, 1).toLowerCase() + + fieldName.substring(1); + + // Is the return type a yang generated class? + if (isYangGenerated(returnType)) { + // Is it an enum? + if (returnType.isEnum()) { + // Return type is a typedef. Save its value. + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + + Object retValue = m.invoke(fromObj); + + if (!isAccessible) { + m.setAccessible(isAccessible); + } + if (retValue != null) { + String propName = propNamePfx + "." + + fieldName; + String propVal = retValue.toString(); + String yangProp = "yang." + fieldName + "." + propVal; + if ( properties.containsKey(yangProp)) { + propVal = properties.getProperty(yangProp); + //LOG.debug("Adjusting property " + yangProp + " " + propVal); + } + //LOG.debug("Setting property " + propName + // + " to " + propVal); + props.setProperty(propName, propVal); + } + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert Yang-generated enum returned by " + + fromClass.getName() + "." + + m.getName() + + "() to Properties entry", e); + } + } else if (isIpv4Address(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Ipv4Address retValue = (Ipv4Address) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + String propVal = retValue.getValue().toString(); + //LOG.debug("Setting property " + propName + // + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert value returned by " + + fromClass.getName() + "." + + m.getName() + + "() to Properties entry", e); + } + } else if (isIpv6Address(returnType)) { + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Ipv6Address retValue = (Ipv6Address) m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (retValue != null) { + String propVal = retValue.getValue().toString(); + //LOG.debug("Setting property " + propName + // + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert value returned by " + + fromClass.getName() + "." + + m.getName() + + "() to Properties entry", e); + } + } else { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Object retValue = m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + if (retValue != null) { + toProperties(props, propNamePfx + "." + fieldName, retValue, returnType); + } + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert Yang-generated class returned by" + + fromClass.getName() + "." + + m.getName() + + "() to Properties entry", e); + } + } + } else if (returnType.equals(Class.class)) { + + //LOG.debug(m.getName() + // + " returns a Class object - not interested"); + + } else if (List.class.isAssignableFrom(returnType)) { + + // This getter method returns a list. + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Object retList = m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + // Figure out what type of elements are stored in this array. + Type paramType = m.getGenericReturnType(); + Type elementType = ((ParameterizedType) paramType) + .getActualTypeArguments()[0]; + toProperties(props, propNamePfx + "." + fieldName, + retList, (Class)elementType); + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert List returned by " + + fromClass.getName() + "." + + m.getName() + + "() to Properties entry", e); + } + + } else { + + // Method returns something that is not a List and not + // yang-generated. + // Save its value + try { + String propName = propNamePfx + "." + fieldName; + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + Object propValObj = m.invoke(fromObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + + if (propValObj != null) { + String propVal = propValObj.toString(); + //LOG.debug("Setting property " + propName + // + " to " + propVal); + props.setProperty(propName, propVal); + + } + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert value returned by " + + fromClass.getName() + "." + + m.getName() + + "() to Properties entry", e); + } + } + + } + } + + } else { + // Class is not yang generated and not a list + // Do nothing. + + } + + return (props); + } + + public static Object toBuilder(Properties props, Object toObj) { + + return (toBuilder(props, "", toObj)); + } + + public static List toList(Properties props, String pfx, List toObj, + Class elemType) { + + int maxIdx = -1; + boolean foundValue = false; + + //LOG.debug("Saving properties to List<" + elemType.getName() + // + "> from " + pfx); + + // Figure out array size + for (Object pNameObj : props.keySet()) { + String key = (String) pNameObj; + + if (key.startsWith(pfx + "[")) { + String idxStr = key.substring(pfx.length() + 1); + int endloc = idxStr.indexOf("]"); + if (endloc != -1) { + idxStr = idxStr.substring(0, endloc); + } + + try { + int curIdx = Integer.parseInt(idxStr); + if (curIdx > maxIdx) { + maxIdx = curIdx; + } + } catch (Exception e) { + LOG.error("Illegal subscript in property " + key); + } + + } + } + + //LOG.debug(pfx + " has max index of " + maxIdx); + for (int i = 0; i <= maxIdx; i++) { + + String curBase = pfx + "[" + i + "]"; + + if (isYangGenerated(elemType)) { + String builderName = elemType.getName() + "Builder"; + try { + Class builderClass = Class.forName(builderName); + Object builderObj = builderClass.newInstance(); + Method buildMethod = builderClass.getMethod("build"); + builderObj = toBuilder(props, curBase, builderObj, true); + if (builderObj != null) { + //LOG.debug("Calling " + builderObj.getClass().getName() + // + "." + buildMethod.getName() + "()"); + Object builtObj = buildMethod.invoke(builderObj); + toObj.add(builtObj); + foundValue = true; + } + + } catch (ClassNotFoundException e) { + LOG.warn("Could not find builder class " + builderName, e); + } catch (Exception e) { + LOG.error("Caught exception trying to populate list from " + + pfx); + } + } + + } + + if (foundValue) { + return (toObj); + } else { + return (null); + } + + } + + public static Object toBuilder(Properties props, String pfx, Object toObj) { + return(toBuilder(props, pfx, toObj, false)); + } + + public static Object toBuilder(Properties props, String pfx, Object toObj, boolean preservePfx) { + Class toClass = toObj.getClass(); + boolean foundValue = false; + + //LOG.debug("Saving properties to " + toClass.getName() + " class from " + // + pfx); + + Ipv4Address addr; + + if (isYangGenerated(toClass)) { + // Class is yang generated. + //LOG.debug(toClass.getName() + " is a Yang-generated class"); + + String propNamePfx = null; + if (preservePfx) { + propNamePfx = pfx; + } else { + + if ((pfx != null) && (pfx.length() > 0)) { + propNamePfx = pfx + "." + + toLowerHyphen(toClass.getSimpleName()); + } else { + propNamePfx = toLowerHyphen(toClass.getSimpleName()); + } + + if (propNamePfx.endsWith("-builder")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() + - "-builder".length()); + } + + if (propNamePfx.endsWith("-impl")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() + - "-impl".length()); + } + } + + if (toObj instanceof Identifier) { + //LOG.debug(toClass.getName() + " is a Key - skipping"); + return (toObj); + } + + // Iterate through getter methods to figure out values we need to + // set + + for (Method m : toClass.getMethods()) { + // LOG.debug("Is " + m.getName() + " method a setter?"); + if (isSetter(m)) { + // LOG.debug(m.getName() + " is a setter"); + Class paramTypes[] = m.getParameterTypes(); + Class paramClass = paramTypes[0]; + + String fieldName = toLowerHyphen(m.getName().substring(3)); + fieldName = fieldName.substring(0, 1).toLowerCase() + + fieldName.substring(1); + + String propName = propNamePfx + "." + fieldName; + + String paramValue = props.getProperty(propName); + if (paramValue == null) { + //LOG.debug(propName + " is unset"); + } else { + //LOG.debug(propName + " = " + paramValue); + } + + // Is the return type a yang generated class? + if (isYangGenerated(paramClass)) { + // Is it an enum? + if (paramClass.isEnum()) { + + //LOG.debug(m.getName() + " expects an Enum"); + // Param type is a typedef. + if (paramValue != null) { + Object paramObj = null; + + try { + paramObj = Enum.valueOf(paramClass, + toUpperCamelCase(paramValue)); + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert field " + + propName + " to enum " + + paramClass.getName(), e); + } + + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + + //LOG.debug("Calling " + // + toObj.getClass().getName() + "." + // + m.getName() + "(" + paramValue + // + ")"); + m.invoke(toObj, paramObj); + + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error( + "Caught exception trying to create Yang-generated enum expected by" + + toClass.getName() + + "." + + m.getName() + + "() from Properties entry", + e); + } + } + } else { + + String simpleName = paramClass.getSimpleName(); + + if ("Ipv4Address".equals(simpleName) + || "Ipv6Address".equals(simpleName)) { + + if (paramValue != null) { + try { + IpAddress ipAddr = IpAddressBuilder + .getDefaultInstance(paramValue); + + + if ("Ipv4Address".equals(simpleName)) + { + m.invoke(toObj, ipAddr.getIpv4Address()); + } + else + { + m.invoke(toObj, ipAddr.getIpv6Address()); + + } + foundValue = true; + } catch (Exception e) { + LOG.error( + "Caught exception calling " + + toClass.getName() + "." + + m.getName() + "(" + + paramValue + ")", e); + + } + } + + } else { + // setter expects a yang-generated class. Need + // to + // create a builder to set it. + + String builderName = paramClass.getName() + + "Builder"; + Class builderClass = null; + Object builderObj = null; + Object paramObj = null; + + //LOG.debug(m.getName() + // + " expects a yang-generated class - looking for builder " + // + builderName); + try { + builderClass = Class.forName(builderName); + builderObj = builderClass.newInstance(); + paramObj = toBuilder(props, propNamePfx, + builderObj); + } catch (ClassNotFoundException e) { + Object constObj = null; + try { + // See if I can find a constructor I can + // use + Constructor[] constructors = paramClass + .getConstructors(); + // Is there a String constructor? + for (Constructor c : constructors) { + Class[] cParms = c + .getParameterTypes(); + if ((cParms != null) + && (cParms.length == 1)) { + if (String.class + .isAssignableFrom(cParms[0])) { + constObj = c + .newInstance(paramValue); + } + } + } + + if (constObj == null) { + // Is there a Long constructor? + for (Constructor c : constructors) { + Class[] cParms = c + .getParameterTypes(); + if ((cParms != null) + && (cParms.length == 1)) { + if (Long.class + .isAssignableFrom(cParms[0])) { + constObj = c + .newInstance(Long + .parseLong(paramValue)); + } + } + } + + } + + if (constObj != null) { + try { + m.invoke(toObj, constObj); + foundValue = true; + } catch (Exception e2) { + LOG.error( + "Caught exception trying to call " + + m.getName(), + e2); + } + } + } catch (Exception e1) { + LOG.warn( + "Could not find a suitable constructor for " + + paramClass.getName(), + e1); + } + + if (paramObj == null) { + LOG.warn("Could not find builder class " + + builderName + + " and could not find a String or Long constructor - trying just to set passing paramValue"); + + } + + } catch (Exception e) { + LOG.error( + "Caught exception trying to create builder " + + builderName, e); + } + + if (paramObj != null) { + + try { + + Method buildMethod = builderClass + .getMethod("build"); + //LOG.debug("Calling " + // + paramObj.getClass().getName() + // + "." + buildMethod.getName() + // + "()"); + Object builtObj = buildMethod + .invoke(paramObj); + + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + + //LOG.debug("Calling " + // + toObj.getClass().getName() + // + "." + m.getName() + "()"); + m.invoke(toObj, builtObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error( + "Caught exception trying to set Yang-generated class expected by" + + toClass.getName() + + "." + + m.getName() + + "() from Properties entry", + e); + } + } else { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + //LOG.debug("Calling " + // + toObj.getClass().getName() + // + "." + m.getName() + "(" + // + paramValue + ")"); + m.invoke(toObj, paramValue); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert value returned by" + + toClass.getName() + + "." + + m.getName() + + "() to Properties entry", + e); + } + } + } + } + } else { + + // Setter's argument is not a yang-generated class. See + // if it is a List. + + if (List.class.isAssignableFrom(paramClass)) { + + //LOG.debug("Parameter class " + paramClass.getName() + // + " is a List"); + + // Figure out what type of args are in List and pass + // that to toList(). + + Type paramType = m.getGenericParameterTypes()[0]; + Type elementType = ((ParameterizedType) paramType) + .getActualTypeArguments()[0]; + Object paramObj = new LinkedList(); + try { + paramObj = toList(props, propName, + (List) paramObj, (Class) elementType); + } catch (Exception e) { + LOG.error("Caught exception trying to create list expected as argument to " + + toClass.getName() + "." + m.getName()); + } + + if (paramObj != null) { + try { + boolean isAccessible = m.isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + //LOG.debug("Calling " + // + toObj.getClass().getName() + "." + // + m.getName() + "(" + paramValue + // + ")"); + m.invoke(toObj, paramObj); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert List returned by" + + toClass.getName() + "." + + m.getName() + + "() to Properties entry", + e); + } + } + } else { + + // Setter expects something that is not a List and + // not yang-generated. Just pass the parameter value + + //LOG.debug("Parameter class " + // + paramClass.getName() + // + " is not a yang-generated class or a List"); + + if (paramValue != null) { + + Object constObj = null; + + try { + // See if I can find a constructor I can use + Constructor[] constructors = paramClass + .getConstructors(); + // Is there a String constructor? + for (Constructor c : constructors) { + Class[] cParms = c.getParameterTypes(); + if ((cParms != null) + && (cParms.length == 1)) { + if (String.class + .isAssignableFrom(cParms[0])) { + constObj = c + .newInstance(paramValue); + } + } + } + + if (constObj == null) { + // Is there a Long constructor? + for (Constructor c : constructors) { + Class[] cParms = c + .getParameterTypes(); + if ((cParms != null) + && (cParms.length == 1)) { + if (Long.class + .isAssignableFrom(cParms[0])) { + constObj = c + .newInstance(Long + .parseLong(paramValue)); + } + } + } + + } + + if (constObj != null) { + try { + //LOG.debug("Calling " + // + toObj.getClass() + // .getName() + "." + // + m.getName() + "(" + // + constObj + ")"); + m.invoke(toObj, constObj); + foundValue = true; + } catch (Exception e2) { + LOG.error( + "Caught exception trying to call " + + m.getName(), e2); + } + } else { + try { + boolean isAccessible = m + .isAccessible(); + if (!isAccessible) { + m.setAccessible(true); + } + //LOG.debug("Calling " + // + toObj.getClass() + // .getName() + "." + // + m.getName() + "(" + // + paramValue + ")"); + m.invoke(toObj, paramValue); + if (!isAccessible) { + m.setAccessible(isAccessible); + } + foundValue = true; + + } catch (Exception e) { + LOG.error( + "Caught exception trying to convert value returned by" + + toClass.getName() + + "." + + m.getName() + + "() to Properties entry", + e); + } + } + } catch (Exception e1) { + LOG.warn( + "Could not find a suitable constructor for " + + paramClass.getName(), e1); + } + + /* + * try { boolean isAccessible = + * m.isAccessible(); if (!isAccessible) { + * m.setAccessible(true); } LOG.debug("Calling " + * + toObj.getClass().getName() + "." + + * m.getName() + "(" + paramValue + ")"); + * m.invoke(toObj, paramValue); if + * (!isAccessible) { + * m.setAccessible(isAccessible); } foundValue = + * true; + * + * } catch (Exception e) { LOG.error( + * "Caught exception trying to convert value returned by" + * + toClass.getName() + "." + m.getName() + + * "() to Properties entry", e); } + */ + } + } + } + } // End of section handling "setter" method + } // End of loop through Methods + } // End of section handling yang-generated class + + if (foundValue) { + return (toObj); + } else { + return (null); + } + } + +/* + public static void printPropertyList(PrintStream pstr, String pfx, + Class toClass) { + boolean foundValue = false; + + //LOG.debug("Analyzing " + toClass.getName() + " class : pfx " + pfx); + + if (isYangGenerated(toClass) + && (!Identifier.class.isAssignableFrom(toClass))) { + // Class is yang generated. + //LOG.debug(toClass.getName() + " is a Yang-generated class"); + + if (toClass.getName().endsWith("Key")) { + if (Identifier.class.isAssignableFrom(toClass)) { + //LOG.debug(Identifier.class.getName() + // + " is assignable from " + toClass.getName()); + } else { + + //LOG.debug(Identifier.class.getName() + // + " is NOT assignable from " + toClass.getName()); + } + } + + String propNamePfx = null; + if (pfx.endsWith("]")) { + propNamePfx = pfx; + } else { + + if ((pfx != null) && (pfx.length() > 0)) { + propNamePfx = pfx + "." + + toLowerHyphen(toClass.getSimpleName()); + } else { + propNamePfx = toLowerHyphen(toClass.getSimpleName()); + } + + if (propNamePfx.endsWith("-builder")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() + - "-builder".length()); + } + + if (propNamePfx.endsWith("-impl")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() + - "-impl".length()); + } + } + + // Iterate through getter methods to figure out values we need to + // set + + for (Method m : toClass.getMethods()) { + //LOG.debug("Is " + m.getName() + " method a getter?"); + if (isGetter(m)) { + //LOG.debug(m.getName() + " is a getter"); + Class returnClass = m.getReturnType(); + + String fieldName = toLowerHyphen(m.getName().substring(3)); + fieldName = fieldName.substring(0, 1).toLowerCase() + + fieldName.substring(1); + + String propName = propNamePfx + "." + fieldName; + + // Is the return type a yang generated class? + if (isYangGenerated(returnClass)) { + // Is it an enum? + if (returnClass.isEnum()) { + //System.out.println(returnClass.getSimpleName()); + //System.out.println(Arrays.asList(returnClass.getEnumConstants())); + + //LOG.debug(m.getName() + " is an Enum"); + pstr.print("\n" + propName + ":Enum:" + Arrays.asList(returnClass.getEnumConstants()) + "\n"); + + } else { + + String simpleName = returnClass.getSimpleName(); + + if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName)) { + //LOG.debug(m.getName()+" is an "+simpleName); + pstr.print("\n" + propName + ":" + simpleName + "\n"); + } else { + printPropertyList(pstr, propNamePfx, returnClass); + } + + } + } else { + + // Setter's argument is not a yang-generated class. See + // if it is a List. + + if (List.class.isAssignableFrom(returnClass)) { + + //LOG.debug("Parameter class " + //+ returnClass.getName() + " is a List"); + + // Figure out what type of args are in List and pass + // that to toList(). + + Type returnType = m.getGenericReturnType(); + Type elementType = ((ParameterizedType) returnType) + .getActualTypeArguments()[0]; + Class elementClass = (Class) elementType; + //LOG.debug("Calling printPropertyList on list type (" + //+ elementClass.getName() + //+ "), pfx is (" + // + pfx + // + "), toClass is (" + // + toClass.getName() + ")"); + printPropertyList( + pstr, + propNamePfx + + "." + + toLowerHyphen(elementClass + .getSimpleName()) + "[]", + elementClass); + + } else if (!returnClass.equals(Class.class)) { + + // Setter expects something that is not a List and + // not yang-generated. Just pass the parameter value + + //LOG.debug("Parameter class " + // + returnClass.getName() + // + " is not a yang-generated class or a List"); + String className=returnClass.getName(); + + //"org.opendaylight.yangtools.yang.binding.Identifier" + int nClassNameIndex = className.lastIndexOf('.'); + String nClassName = className; + if(nClassNameIndex != -1){ + nClassName=className.substring(nClassNameIndex+1); + } + pstr.print("\n" + propName +":" + nClassName +"\n"); + + } + } + } // End of section handling "setter" method + } // End of loop through Methods + } // End of section handling yang-generated class + + } +*/ + + public static Properties prop = new Properties(); + public static ArrayList<String> propList = new ArrayList<String>(); + public static Properties getProperties(PrintStream pstr, String pfx, + Class toClass) { + boolean foundValue = false; + + //LOG.debug("Analyzing " + toClass.getName() + " class : pfx " + pfx); + + if (isYangGenerated(toClass) + && (!Identifier.class.isAssignableFrom(toClass))) { + // Class is yang generated. + //LOG.debug(toClass.getName() + " is a Yang-generated class"); + + if (toClass.getName().endsWith("Key")) { + if (Identifier.class.isAssignableFrom(toClass)) { + //LOG.debug(Identifier.class.getName() + // + " is assignable from " + toClass.getName()); + } else { + + //LOG.debug(Identifier.class.getName() + // + " is NOT assignable from " + toClass.getName()); + } + } + + String propNamePfx = null; + if (pfx.endsWith("]")) { + propNamePfx = pfx; + }else if(pfx.indexOf(".CLASS_FOUND") != -1){ + pfx = pfx.replace(".CLASS_FOUND",""); + propNamePfx = pfx + "." + + toLowerHyphen(toClass.getSimpleName()); + } else { + + if ((pfx != null) && (pfx.length() > 0)) { + propNamePfx = pfx + "." + + toLowerHyphen(toClass.getSimpleName()); + } else { + propNamePfx = toLowerHyphen(toClass.getSimpleName()); + } + + if (propNamePfx.endsWith("-builder")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() + - "-builder".length()); + } + + if (propNamePfx.endsWith("-impl")) { + propNamePfx = propNamePfx.substring(0, propNamePfx.length() + - "-impl".length()); + } + } + + // Iterate through getter methods to figure out values we need to + // set + + for (Method m : toClass.getMethods()) { + //LOG.debug("Is " + m.getName() + " method a getter?"); + if (isGetter(m)) { + // LOG.debug(m.getName() + " is a getter"); + Class returnClass = m.getReturnType(); + + String fieldName = toLowerHyphen(m.getName().substring(3)); + if(m != null && m.getName().matches("^is[A-Z].*")){ + fieldName = toLowerHyphen(m.getName().substring(2)); + } + fieldName = fieldName.substring(0, 1).toLowerCase() + + fieldName.substring(1); + + String propName = propNamePfx + "." + fieldName; + //System.out.println("****" + propName); + + // Is the return type a yang generated class? + if (isYangGenerated(returnClass)) { + // Is it an enum? + if (returnClass.isEnum()) { + + //LOG.debug(m.getName() + " is an Enum"); + //pstr.print("\n" + propName); + //pstr.print("\n" + propName + ":Enum:" + Arrays.asList(returnClass.getEnumConstants()) + "\n"); + pstr.print("\"" + propName + ":Enum:" + Arrays.asList(returnClass.getEnumConstants()) + "\","); + prop.setProperty(propName,""); + propList.add(propName); + + } else { + + String simpleName = returnClass.getSimpleName(); + //System.out.println("simpleName:" + simpleName); + + if ("Ipv4Address".equals(simpleName) || "Ipv6Address".equals(simpleName) || "IpAddress".equals(simpleName)) { + //LOG.debug(m.getName()+" is an "+simpleName); + //pstr.print("\n" + propName); + //pstr.print("\n" + propName + ":" + simpleName + "\n"); + pstr.print("\"" + propName + ":" + simpleName + "\","); + prop.setProperty(propName,""); + propList.add(propName); + } else { + boolean isString = false; + boolean isNumber = false; + boolean isBoolean = false; + boolean isIdentifier = false; + //System.out.println("simpleName:" + simpleName); + //System.out.println("propName:" + propName); + for(Method mthd : returnClass.getMethods()){ + String methodName = mthd.getName(); + //System.out.println("methodName:" + methodName); + if(methodName.equals("getValue")){ + Class retType = mthd.getReturnType(); + //System.out.println("retType:" + retType); + isString = String.class.isAssignableFrom(retType); + isNumber = Number.class.isAssignableFrom(retType); + isBoolean = Boolean.class.isAssignableFrom(retType); + isIdentifier = Identifier.class.isAssignableFrom(retType); + //System.out.println("isString:" + isString); + //System.out.println("isNumber:" + isNumber); + //System.out.println("isNumber:" + isNumber); + break; + } + } + + if(isString){ + pstr.print("\"" + propName + ":String\","); + prop.setProperty(propName,""); + propList.add(propName); + }else if(isNumber){ + pstr.print("\"" + propName + ":Number\","); + prop.setProperty(propName,""); + propList.add(propName); + }else if(isBoolean){ + pstr.print("\"" + propName + ":Boolean\","); + prop.setProperty(propName,""); + propList.add(propName); + }else if(isIdentifier){ + //System.out.println("isIdentifier"); + //isIdentifer so skipping + continue; + }else{ + /* + System.out.println("fieldName:" + fieldName); + System.out.println("simpleName:" + simpleName); + System.out.println("returnClass:" + returnClass); + System.out.println("pstr:" + pstr); + System.out.println("propNamePfx:" + propNamePfx); + */ + getProperties(pstr, propNamePfx + ".CLASS_FOUND", returnClass); + } + } + + } + } else { + + // Setter's argument is not a yang-generated class. See + // if it is a List. + + if (List.class.isAssignableFrom(returnClass)) { + + //LOG.debug("Parameter class " + // + returnClass.getName() + " is a List"); + + // Figure out what type of args are in List and pass + // that to toList(). + + Type returnType = m.getGenericReturnType(); + Type elementType = ((ParameterizedType) returnType) + .getActualTypeArguments()[0]; + Class elementClass = (Class) elementType; + //LOG.debug("Calling printPropertyList on list type (" + //+ elementClass.getName() + // + "), pfx is (" + // + pfx + // + "), toClass is (" + // + toClass.getName() + ")"); + //System.out.println("List propNamePfx:" + propNamePfx+ "." + toLowerHyphen(elementClass.getSimpleName()) + "[]"); + if(String.class.isAssignableFrom(elementClass)){ + pstr.print("\"" + propName + ":[String,String,...]\","); + prop.setProperty(propName,""); + propList.add(propName); + }else if(Number.class.isAssignableFrom(elementClass)){ + pstr.print("\"" + propName + ":[Number,Number,...]\","); + prop.setProperty(propName,""); + propList.add(propName); + }else if(Boolean.class.isAssignableFrom(elementClass)){ + pstr.print("\"" + propName + ":[Boolean,Boolean,...]\","); + prop.setProperty(propName,""); + propList.add(propName); + }else if(Identifier.class.isAssignableFrom(elementClass)){ + continue; + }else{ + getProperties( + pstr, + propNamePfx + + "." + + toLowerHyphen(elementClass + .getSimpleName()) + "[]", + elementClass); + } + + } else if (!returnClass.equals(Class.class)) { + + // Setter expects something that is not a List and + // not yang-generated. Just pass the parameter value + + //LOG.debug("Parameter class " + // + returnClass.getName() + // + " is not a yang-generated class or a List"); + + //pstr.print("\n" + propName); + String className=returnClass.getName(); + int nClassNameIndex = className.lastIndexOf('.'); + String nClassName = className; + if(nClassNameIndex != -1){ + nClassName=className.substring(nClassNameIndex+1); + } + boolean isString = String.class.isAssignableFrom(returnClass); + boolean isNumber = Number.class.isAssignableFrom(returnClass); + boolean isBoolean = Boolean.class.isAssignableFrom(returnClass); + //pstr.print("\n" + propName +":" + nClassName +"\n"); + boolean isIdentifier = Identifier.class.isAssignableFrom(returnClass); + if(!isIdentifier && !nClassName.equals("[C")){ + if(isNumber){ + pstr.print("\"" + propName +":Number\","); + }else if(isBoolean){ + pstr.print("\"" + propName +":Boolean\","); + }else{ + if(nClassName.equals("[B")){ + pstr.print("\"" + propName +":Binary\","); + }else{ + pstr.print("\"" + propName +":" + nClassName +"\","); + } + } + prop.setProperty(propName,""); + propList.add(propName); + } + + } + } + } // End of section handling "setter" method + } // End of loop through Methods + } // End of section handling yang-generated class + + return prop; + } + + public static boolean isYangGenerated(Class c) { + if (c == null) { + return (false); + } else { + //System.out.println(c.getName()); + return (c.getName().startsWith("org.opendaylight.yang.gen.")); + } + } + + public static boolean isIpv4Address(Class c) { + + if (c == null ) { + return (false); + } + String simpleName = c.getSimpleName(); + return ("Ipv4Address".equals(simpleName)) ; + } + + public static boolean isIpv6Address(Class c) { + + if (c == null ) { + return (false); + } + String simpleName = c.getSimpleName(); + return ("Ipv6Address".equals(simpleName)) ; + } + + public static String toLowerHyphen(String inStr) { + if (inStr == null) { + return (null); + } + + String str = inStr.substring(0, 1).toLowerCase(); + if (inStr.length() > 1) { + str = str + inStr.substring(1); + } + + String regex = "(([a-z0-9])([A-Z]))"; + String replacement = "$2-$3"; + + String retval = str.replaceAll(regex, replacement).toLowerCase(); + + //LOG.debug("Converting " + inStr + " => " + str + " => " + retval); + return (retval); + } + + public static String toUpperCamelCase(String inStr) { + if (inStr == null) { + return (null); + } + + String[] terms = inStr.split("-"); + StringBuffer sbuff = new StringBuffer(); + // Check if string begins with a digit + if (Character.isDigit(inStr.charAt(0))) { + sbuff.append('_'); + } + for (String term : terms) { + sbuff.append(term.substring(0, 1).toUpperCase()); + if (term.length() > 1) { + sbuff.append(term.substring(1)); + } + } + return (sbuff.toString()); + + } + + public static boolean isGetter(Method m) { + //System.out.println(m); + if (m == null) { + return (false); + } + + if (Modifier.isPublic(m.getModifiers()) + && (m.getParameterTypes().length == 0)) { + if ((m.getName().matches("^is[A-Z].*") || m.getName().matches("^get[A-Z].*")) + && m.getReturnType().equals(Boolean.class)) { + return (true); + } + if (m.getName().matches("^get[A-Z].*") + && !m.getReturnType().equals(void.class)) { + return (true); + } + + } + + return (false); + } + + public static boolean isSetter(Method m) { + if (m == null) { + return (false); + } + + if (Modifier.isPublic(m.getModifiers()) + && (m.getParameterTypes().length == 1)) { + if (m.getName().matches("^set[A-Z].*")) { + Class[] paramTypes = m.getParameterTypes(); + if (paramTypes[0].isAssignableFrom(Identifier.class) + || Identifier.class.isAssignableFrom(paramTypes[0])) { + return (false); + } else { + return (true); + } + } + + } + + return (false); + } + + public static void main(String[] args){ + try{ + PrintStream ps = new PrintStream(new FileOutputStream(FileDescriptor.out)); + PrintYangToProp printYangToProp = new PrintYangToProp(); + String className = args[0]; + //ClassLoader classLoader = PrintYangToProp.class.getClassLoader(); + //Class aClass = classLoader.loadClass(className); + Class cl = Class.forName(className); + //printPropertyList(ps,"",cl); + //JsonObject jsonObj = Json.createObjectBuilder().build(); + Properties p = getProperties(ps,"",cl); + //System.out.println(p); + + }catch(Exception e){ + e.printStackTrace(); + } + } + + +} diff --git a/dgbuilder/tools/auto_app.sh b/dgbuilder/tools/auto_app.sh new file mode 100755 index 00000000..a3e0f2e9 --- /dev/null +++ b/dgbuilder/tools/auto_app.sh @@ -0,0 +1,24 @@ +toolsDir=$PROJECT_HOME/tools +if [ "$#" != "1" ] +then + echo "Usage: $0 appName" + exit +fi +appName="$1" +mkdir tmpws +cd tmpws +mkdir logs +mvn archetype:generate -DarchetypeGroupId=com.brocade.developer -DarchetypeArtifactId=brocade.dev.plugin.ext.archetype -DarchetypeVersion=1.2.0.100-SNAPSHOT >${toolsDir}/tmpws/logs/mvn_gen_archetype.log 2>&1 <<EOF +org.openecomp.sdnc.app +${appName} +1.0.0-SNAPSHOT +org.openecomp.sdnc.app +Y +EOF +if [ "$?" == "0" ] +then + echo "App created successfully" +else + echo "App creation failed" +fi +${toolsDir}/update_app_impl_yang.sh "${appName}" $1 diff --git a/dgbuilder/tools/dot_to_json.js b/dgbuilder/tools/dot_to_json.js new file mode 100644 index 00000000..7ff80e8b --- /dev/null +++ b/dgbuilder/tools/dot_to_json.js @@ -0,0 +1,138 @@ +var obj={}; +function dotToJson(str,value,obj){ + //var objArr = path.split("."), part; + var objArr = str.split("."); + var prevStr; + var currObj; + var prevObj; + //console.log(str); + var isArray = false; + var prevObjIsArray = false; + for(var i=0;i<objArr.length -1;i++){ + var subStr= objArr[i] ; + if(isArray){ + prevObjIsArray = true; + } + isArray = false; + if(subStr.indexOf(']') == subStr.length -1){ + subStr = subStr.substring(0,subStr.length -2); + isArray = true; + } + //console.log("subStr:" + subStr + isArray); + //console.dir(prevObj); + if(isArray){ + if(i==0 && obj[subStr] == undefined ){ + //console.log("i==0 && obj[subStr] "); + obj[subStr]=[]; + }else if(i==0 && obj[subStr][0] == undefined ){ + obj[subStr][0]={}; + }else if(i==0 && obj[subStr][0] != undefined ){ + currObj= obj[subStr][0]; + }else{ + if(i == 1){ + //console.log("i==1 && obj[prevStr] "); + prevObj=obj[prevStr]; + if(prevObj[subStr] != undefined && prevObj[subStr][0] == undefined){ + prevObj[subStr] = []; + prevObj[subStr][0] = {}; + currObj = prevObj[subStr][0]; + }else if(prevObj[subStr] != undefined && prevObj[subStr][0] != undefined){ + currObj = prevObj[subStr][0]; + }else if(prevObj[subStr] == undefined){ + prevObj[subStr] = []; + prevObj[subStr][0] = {}; + currObj = prevObj[subStr][0]; + } + }else{ + if(prevObj[subStr] == undefined){ + prevObj[subStr]=[]; + prevObj[subStr][0]={}; + currObj = prevObj[subStr][0]; + }else{ + currObj = prevObj[subStr][0]; + } + } + } + }else{ + if(i==0 && obj[subStr] == undefined ){ + obj[subStr] = {}; + currObj= obj[subStr]; + }else if(i==0 && obj[subStr] != undefined ){ + currObj=obj[subStr]; + //console.log("in gkjgjkg"); + }else{ + if(i == 1){ + prevObj=obj[prevStr]; + if(prevObj[subStr] == undefined){ + prevObj[subStr] = {}; + currObj = prevObj[subStr]; + }else{ + currObj = prevObj[subStr]; + } + }else{ + if(prevObj[subStr] == undefined){ + prevObj[subStr] = {}; + currObj = prevObj[subStr]; + }else{ + currObj = prevObj[subStr]; + } + } + } + } + prevStr=subStr; + if(i <objArr.length-2){ + //console.dir(currObj); + prevObj=currObj; + } + } + var lastStr = objArr[objArr.length-1]; + if(isArray){ + currObj[lastStr] = value; + }else{ + currObj[lastStr] = value; + } + //prevObj[lastStr] = value; + //console.dir(currObj); + return obj; +} +function printObj(obj){ +for( j in obj){ + console.log(j + ":" + obj[j]); + if(typeof obj[j] == "object" ){ + printObj(obj[j]); + } + +} +} + +/* +var nObj={}; +for(var i=0;i<a.length;i++){ + dotToJson(a[i],'',nObj); +} +*/ +var sliValuesObj = require(process.argv[2]); +var moduleName = process.argv[3]; +//console.dir(sliValuesObj); +var a= sliValuesObj[moduleName + "_VALUES"]; +var rpcs= sliValuesObj[moduleName + "_RPCS"]; +var nObj={}; +nObj['moduleName'] = moduleName; +console.log("module.exports = "); +for(var i=0;i<a.length;i++){ + var key =a[i].substring(0,a[i].indexOf(':')); + //console.log(key); + var value =a[i].substring(a[i].indexOf(':') +1); + if(value == undefined) value =""; + dotToJson(key,value,nObj); +} + +nObj[moduleName + "_PROPS"] =[]; +for(var i=0;i<a.length;i++){ + var key =a[i].substring(0,a[i].indexOf(':')); + nObj[moduleName + "_PROPS"].push(key); +} + +nObj[moduleName + "_RPCS"] = rpcs; + +console.log(JSON.stringify(nObj,null,4)); diff --git a/dgbuilder/tools/format_json.sh b/dgbuilder/tools/format_json.sh new file mode 100755 index 00000000..f86ad3cf --- /dev/null +++ b/dgbuilder/tools/format_json.sh @@ -0,0 +1,6 @@ +if [ "$#" != "1" ] +then + echo "Usage: $0 jsonFileFullPath" + exit +fi +cat $1|python -m json.tool diff --git a/dgbuilder/tools/format_xml.sh b/dgbuilder/tools/format_xml.sh new file mode 100755 index 00000000..f0074e67 --- /dev/null +++ b/dgbuilder/tools/format_xml.sh @@ -0,0 +1,17 @@ +if [ "$#" != "1" ] +then + echo "Usage: $0 xmlFileFullPath" + exit +fi + +if [ -z "$PROJECT_HOME" ] +then + export PROJECT_HOME=$(pwd)/.. +fi +export CLASSPATH=$CLASSPATH:. +if [ -e "$1" ] +then + java FormatXml $1 +else + echo "File $1 does not exist" +fi diff --git a/dgbuilder/tools/generate_props_from_yang.sh b/dgbuilder/tools/generate_props_from_yang.sh new file mode 100755 index 00000000..4ce93af5 --- /dev/null +++ b/dgbuilder/tools/generate_props_from_yang.sh @@ -0,0 +1,28 @@ +if [ -z "$PROJECT_HOME" ] +then + export PROJECT_HOME=$(pwd)/.. +fi + +toolsDir=$PROJECT_HOME/tools +rm -rf ${toolsDir}/tmpws +mkdir ${toolsDir}/tmpws +mkdir ${toolsDir}/tmpws/logs +if [ "$#" != "1" ] +then + echo "Command line:$0 $*" >${toolsDir}/tmpws/logs/err.log + echo "Usage: $0 yangFile" >>${toolsDir}/tmpws/logs/err.log + exit +fi + +appName="yangApp" +cd ${toolsDir}/tmpws +mvn archetype:generate -DarchetypeGroupId=com.brocade.developer -DarchetypeArtifactId=brocade.dev.plugin.ext.archetype -DarchetypeVersion=1.2.0.100-SNAPSHOT >${toolsDir}/tmpws/logs/mvn_gen_archetype.log 2>&1 <<EOF +org.openecomp.sdnc.app +${appName} +1.0.0-SNAPSHOT +org.openecomp.sdnc.app +Y +EOF +${toolsDir}/update_app_impl_yang.sh "${appName}" $1 +echo "Done..." + diff --git a/dgbuilder/tools/generate_props_from_yangs.sh b/dgbuilder/tools/generate_props_from_yangs.sh new file mode 100755 index 00000000..8867cea3 --- /dev/null +++ b/dgbuilder/tools/generate_props_from_yangs.sh @@ -0,0 +1,28 @@ +if [ -z "$PROJECT_HOME" ] +then + export PROJECT_HOME=$(pwd)/.. +fi + +toolsDir=$PROJECT_HOME/tools +rm -rf ${toolsDir}/tmpws +mkdir ${toolsDir}/tmpws +mkdir ${toolsDir}/tmpws/logs +if [ "$#" != "2" ] +then + echo "Command line:$0 $*" >${toolsDir}/tmpws/logs/err.log + echo "Usage: $0 yangFilesdirectoryFullPath baseYangFile" >>${toolsDir}/tmpws/logs/err.log + exit +fi + +appName="yangApp" +cd ${toolsDir}/tmpws +mvn archetype:generate -DarchetypeGroupId=com.brocade.developer -DarchetypeArtifactId=brocade.dev.plugin.ext.archetype -DarchetypeVersion=1.2.0.100-SNAPSHOT >${toolsDir}/tmpws/logs/mvn_gen_archetype.log 2>&1 <<EOF +org.openecomp.sdnc.app +${appName} +1.0.0-SNAPSHOT +org.openecomp.sdnc.app +Y +EOF +${toolsDir}/update_app_impl_yangs.sh "${appName}" $1 $2 +echo "Done..." + diff --git a/dgbuilder/tools/generate_props_from_yangs_zip.sh b/dgbuilder/tools/generate_props_from_yangs_zip.sh new file mode 100755 index 00000000..39607110 --- /dev/null +++ b/dgbuilder/tools/generate_props_from_yangs_zip.sh @@ -0,0 +1,36 @@ +if [ "$PROJECT_HOME" == "" ] +then + export PROJECT_HOME=$(pwd)/.. +fi + +toolsDir=$PROJECT_HOME/tools +if [ "$#" != "1" ] +then + echo "Usage: $0 yangFilesZipFullPath" + exit +fi +yangFilesZipFullPath="$1" +rm -rf $PROJECT_HOME/tools/tmp +mkdir $PROJECT_HOME/tools/tmp +mv ${yangFilesZipFullPath} $PROJECT_HOME/tools/tmp +cd $PROJECT_HOME/tools/tmp +zipFile=$(basename $yangFilesZipFullPath) +unzip $PROJECT_HOME/tools/tmp/$zipFile +rm ${zipFile} +for i in $(ls *.yang) +do + fName="$i" + extension="${fName##*.}" + moduleName="${fName%.*}" + count=$(grep -w "import $moduleName" *.yang|wc -l) + if [ "$count" -eq "0" ] + then + rm -rf $PROJECT_HOME/yangFiles/$moduleName + mkdir $PROJECT_HOME/yangFiles/$moduleName + mv *.yang $PROJECT_HOME/yangFiles/$moduleName + cd $PROJECT_HOME/tools + echo ./generate_props_from_yangs.sh "$PROJECT_HOME/yangFiles/$moduleName" "$fName" + ./generate_props_from_yangs.sh "$PROJECT_HOME/yangFiles/$moduleName" "$fName" + exit + fi +done diff --git a/dgbuilder/tools/getModuleName.sh b/dgbuilder/tools/getModuleName.sh new file mode 100755 index 00000000..cf0db193 --- /dev/null +++ b/dgbuilder/tools/getModuleName.sh @@ -0,0 +1,2 @@ +module=$(cat $1|egrep "module .*{"|awk '{print $2}'|sed -e 's/{//g') +echo $module diff --git a/dgbuilder/tools/getRpcsClassFromYang.sh b/dgbuilder/tools/getRpcsClassFromYang.sh new file mode 100755 index 00000000..d7fc213e --- /dev/null +++ b/dgbuilder/tools/getRpcsClassFromYang.sh @@ -0,0 +1,85 @@ +toolsDir=$PROJECT_HOME/tools +. ${toolsDir}/setClasspath +if [ "$#" != "2" ] +then + echo "Usage $0 yang_file generated_jar_file" + echo "example $0 /home/users/sdnc/src/aic-homing/model/src/main/yang/AicHoming.yang /home/users/sdnc/src/aic-homing/model/target/aicHoming.model-2.0.0.jar" + exit +fi +yangFile="$1" +jarFile="$2" +module=$(cat $yangFile|egrep "module .*{"|awk '{print $2}'|sed -e 's/{//g') +#echo " \"$module\" : [" +rpcs=$(grep rpc $yangFile|grep -v leaf|sed -e 's/^\s\+rpc//g'|awk '{print $1}') +#echo ${rpcs} +for i in `find ${toolsDir}/yangToolsJars -name "*.jar" -print` +do +#echo $i +export CLASSPATH=$CLASSPATH:$i +done +export CLASSPATH=$2:$CLASSPATH:.:${toolsDir}/slf4j-api-1.7.2.jar:${toolsDir}/guava-14.0.1.jar:${toolsDir}/printYangToProp.jar +allProps="" +for rpc in $rpcs +do +rpcVal=$(echo $rpc|sed -e "s/\b\(.\)/\u\1/g"|sed s/\-//g) +className=$(jar -tvf ${jarFile}|grep "org/opendaylight/yang/gen/"|grep -w "${rpcVal}Input.class"|grep -v grep|awk '{print $NF}'|sed -e 's/\//./g'|sed -e 's/.class$//g') +inputProps="" +if [ "$className" != "" ] +then + #java -cp $CLASSPATH PrintYangToProp $className 2>/dev/null|grep '*' |cut -d'*' -f2|sed -e "s/^[ \t]*//g"|sed -e "s/^/\t\t\"/g"|sed -e "s/$/\",/g" + inputProps=$(java -cp $CLASSPATH PrintYangToProp $className 2>${toolsDir}/tmpws/logs/err.log) +fi +className=$(jar -tvf ${jarFile}|grep "org/opendaylight/yang/gen/"|grep -w "${rpcVal}Output"|grep -v grep|awk '{print $NF}'|sed -e 's/\//./g'|sed -e 's/.class$//g') +#echo $inputProps +#echo $className +outputProps="" +if [ "$className" != "" ] +then + #java -cp $CLASSPATH PrintYangToProp $className 2>/dev/null|grep '*' |cut -d'*' -f2|sed -e "s/^[ \t]*//g"|sed -e "s/^/\t\t\"/g"|sed -e "s/$/\",/g" + outputProps=$(java -cp $CLASSPATH PrintYangToProp $className 2>${toolsDir}/tmpws/logs/err.log) +fi +if [ -z "$allProps" ] +then + allProps=$(echo ${inputProps}${outputProps}|sed -e s/,$//g) +else + allProps=$(echo ${allProps},${inputProps}${outputProps}|sed -e s/,$//g) +fi +done +#allProps=$(echo ${inputProps}${outputProps}|sed -e s/,$//g) +#echo $allProps +#OIFS=$IFS +#IFS=',' +#arr2=$allProps +#for x in $arr2 +#do +# echo "$x" +#done +#IFS=$OIFS +#echo " ]" +echo "module.exports = {" +echo "\"moduleName\" : \"${module}\"," +echo "'${module}_VALUES' : " +echo "[ $allProps ]"|python -m json.tool +echo "," +echo "'${module}_RPCS' : [" + +cnt=0 +#numOfRpcs=${#rpcs[@]} +numOfRpcs=0; +for rpc in $rpcs +do + numOfRpcs=$((numOfRpcs+1)) +done + +for rpc in $rpcs +do + cnt=$((cnt+1)) + if [ $cnt -eq $numOfRpcs ] + then + echo " \"$rpc\"" + else + echo " \"$rpc\"," + fi +done +echo " ]" +echo "}" diff --git a/dgbuilder/tools/getRpcsClassFromYangs.sh b/dgbuilder/tools/getRpcsClassFromYangs.sh new file mode 100755 index 00000000..f3ce4c81 --- /dev/null +++ b/dgbuilder/tools/getRpcsClassFromYangs.sh @@ -0,0 +1,85 @@ +toolsDir=$PROJECT_HOME/tools +. ${toolsDir}/setClasspath +if [ "$#" != "2" ] +then + echo "Usage $0 yang_file generated_jar_file" + echo "example $0 /home/users/sdnc/src/appName/model/src/main/yang/app.yang /home/users/sdnc/src/appName/model/target/appName.model-2.0.0.jar" + exit +fi +yangFile="$1" +jarFile="$2" +module=$(cat $yangFile|egrep "module .*{"|awk '{print $2}'|sed -e 's/{//g') +#echo " \"$module\" : [" +rpcs=$(grep rpc $yangFile|grep -v leaf|sed -e 's/^\s\+rpc//g'|awk '{print $1}') +for i in `find ${toolsDir}/yangToolsJars -name "*.jar" -print` +do +#echo $i +export CLASSPATH=$CLASSPATH:$i +done +export CLASSPATH=$2:$CLASSPATH:.:${toolsDir}/slf4j-api-1.7.2.jar:${toolsDir}/guava-14.0.1.jar:${toolsDir}/printYangToProp.jar +allProps="" +for rpc in $rpcs +do +rpcVal=$(echo $rpc|sed -e "s/\b\(.\)/\u\1/g"|sed s/\-//g) +#echo $rpcVal +className=$(jar -tvf ${jarFile}|grep "org/opendaylight/yang/gen/"|grep -w "${rpcVal}Input.class"|grep -v grep|awk '{print $NF}'|sed -e 's/\//./g'|sed -e 's/.class$//g') +#echo $className +inputProps="" +if [ "$className" != "" ] +then + #java -cp $CLASSPATH PrintYangToProp $className 2>/dev/null|grep '*' |cut -d'*' -f2|sed -e "s/^[ \t]*//g"|sed -e "s/^/\t\t\"/g"|sed -e "s/$/\",/g" + inputProps=$(java -cp $CLASSPATH PrintYangToProp $className 2>${toolsDir}/tmpws/logs/err.log) +fi +className=$(jar -tvf ${jarFile}|grep "org/opendaylight/yang/gen/"|grep -w "${rpcVal}Output"|grep -v grep|awk '{print $NF}'|sed -e 's/\//./g'|sed -e 's/.class$//g') +#echo $inputProps +#echo $className +outputProps="" +if [ "$className" != "" ] +then + #java -cp $CLASSPATH PrintYangToProp $className 2>/dev/null|grep '*' |cut -d'*' -f2|sed -e "s/^[ \t]*//g"|sed -e "s/^/\t\t\"/g"|sed -e "s/$/\",/g" + outputProps=$(java -cp $CLASSPATH PrintYangToProp $className 2>${toolsDir}/tmpws/logs/err.log) +fi +if [ -z "$allProps" ] +then + allProps=$(echo ${inputProps}${outputProps}|sed -e s/,$//g) +else + allProps=$(echo ${allProps},${inputProps}${outputProps}|sed -e s/,$//g) +fi +done +#echo $allProps +#OIFS=$IFS +#IFS=',' +#arr2=$allProps +#for x in $arr2 +#do +# echo "$x" +#done +#IFS=$OIFS +#echo " ]" +echo "module.exports = {" +echo "\"moduleName\" : \"${module}\"," +echo "'${module}_VALUES' : " +echo "[ $allProps ]"|python -m json.tool +echo "," +echo "'${module}_RPCS' : [" + +cnt=0 +#numOfRpcs=${#rpcs[@]} +numOfRpcs=0; +for rpc in $rpcs +do + numOfRpcs=$((numOfRpcs+1)) +done + +for rpc in $rpcs +do + cnt=$((cnt+1)) + if [ $cnt -eq $numOfRpcs ] + then + echo " \"$rpc\"" + else + echo " \"$rpc\"," + fi +done +echo " ]" +echo "}" diff --git a/dgbuilder/tools/guava-14.0.1.jar b/dgbuilder/tools/guava-14.0.1.jar Binary files differnew file mode 100644 index 00000000..3a3d9258 --- /dev/null +++ b/dgbuilder/tools/guava-14.0.1.jar diff --git a/dgbuilder/tools/javax.json-api-1.0.jar b/dgbuilder/tools/javax.json-api-1.0.jar Binary files differnew file mode 100644 index 00000000..d276c793 --- /dev/null +++ b/dgbuilder/tools/javax.json-api-1.0.jar diff --git a/dgbuilder/tools/jsonTool.js b/dgbuilder/tools/jsonTool.js new file mode 100644 index 00000000..b4ed21f0 --- /dev/null +++ b/dgbuilder/tools/jsonTool.js @@ -0,0 +1,377 @@ +var obj={}; +function dotToJson(str,value,obj){ + //var objArr = path.split("."), part; + var objArr = str.split("."); + var prevStr; + var currObj; + var prevObj; + //console.log(str); + var isArray = false; + var prevObjIsArray = false; + for(var i=0;i<objArr.length -1;i++){ + var subStr= objArr[i] ; + if(isArray){ + prevObjIsArray = true; + } + isArray = false; + if(subStr.indexOf(']') == subStr.length -1){ + subStr = subStr.substring(0,subStr.length -2); + isArray = true; + } + //console.log("subStr:" + subStr + isArray); + //console.dir(prevObj); + if(isArray){ + if(i==0 && obj[subStr] == undefined ){ + //console.log("i==0 && obj[subStr] "); + obj[subStr]=[]; + }else if(i==0 && obj[subStr][0] == undefined ){ + obj[subStr][0]={}; + }else if(i==0 && obj[subStr][0] != undefined ){ + currObj= obj[subStr][0]; + }else{ + if(i == 1){ + //console.log("i==1 && obj[prevStr] "); + prevObj=obj[prevStr]; + if(prevObj[subStr][0] == undefined){ + prevObj[subStr] = []; + prevObj[subStr][0] = {}; + currObj = prevObj[subStr][0]; + }else{ + currObj = prevObj[subStr][0]; + } + }else{ + if(prevObj[subStr] == undefined){ + prevObj[subStr]=[]; + prevObj[subStr][0]={}; + currObj = prevObj[subStr][0]; + }else{ + currObj = prevObj[subStr][0]; + } + } + } + }else{ + if(i==0 && obj[subStr] == undefined ){ + obj[subStr] = {}; + currObj= obj[subStr]; + }else if(i==0 && obj[subStr] != undefined ){ + currObj=obj[subStr]; + //console.log("in gkjgjkg"); + }else{ + if(i == 1){ + prevObj=obj[prevStr]; + if(prevObj[subStr] == undefined){ + prevObj[subStr] = {}; + currObj = prevObj[subStr]; + }else{ + currObj = prevObj[subStr]; + } + }else{ + if(prevObj[subStr] == undefined){ + prevObj[subStr] = {}; + currObj = prevObj[subStr]; + }else{ + currObj = prevObj[subStr]; + } + } + } + } + prevStr=subStr; + if(i <objArr.length-2){ + //console.dir(currObj); + prevObj=currObj; + } + } + var lastStr = objArr[objArr.length-1]; + if(isArray){ + currObj[lastStr] = value; + }else{ + currObj[lastStr] = value; + } + //prevObj[lastStr] = value; + //console.dir(currObj); + return obj; +} +function printObj(obj){ +for( j in obj){ + console.log(j + ":" + obj[j]); + if(typeof obj[j] == "object" ){ + printObj(obj[j]); + } + +} +} + +a=[ +'service-configuration-operation-input.service-information.service-instance-id', +'service-configuration-operation-input.service-information.subscriber-name', +'service-configuration-operation-input.service-information.service-type', +'service-configuration-operation-input.svc-config-additional-data.management-ip', +'service-configuration-operation-input.sdnc-request-header.svc-request-id', +'service-configuration-operation-input.sdnc-request-header.svc-notification-url', +'service-configuration-operation-input.sdnc-request-header.svc-action', +'service-configuration-operation-input.vr-lan.routing-protocol', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-vr-lan-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].vr-designation', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-vr-lan-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-vr-lan-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-vr-lan-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-defaulted-v6-vrlan', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-vce-loopback-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-vce-wan-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-server-enabled', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-server-enabled', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].use-v4-default-pool', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-default-pool-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-default-pool-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].excluded-v4-dhcp-addresses-from-default-pool[].excluded-v4-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].excluded-v4-dhcp-addresses-from-default-pool[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].use-v6-default-pool', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-default-pool-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-default-pool-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].excluded-v6-dhcp-addresses-from-default-pool[].excluded-v6-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].excluded-v6-dhcp-addresses-from-default-pool[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-pools[].v6-dhcp-pool-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-pools[].v6-dhcp-pool-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-pools[].v6-dhcp-relay-gateway-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-pools[].v6-dhcp-relay-next-hop-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-pools[].excluded-v6-addresses[].excluded-v6-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-pools[].excluded-v6-addresses[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-dhcp-pools[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-pools[].v4-dhcp-relay-next-hop-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-pools[].v4-dhcp-pool-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-pools[].v4-dhcp-pool-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-pools[].v4-dhcp-relay-gateway-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-pools[].excluded-v4-addresses[].excluded-v4-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-pools[].excluded-v4-addresses[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-dhcp-pools[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-nat-enabled', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-nat-mapping-entries[].v4-nat-internal', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-nat-mapping-entries[].v4-nat-next-hop-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-nat-mapping-entries[].v4-nat-external', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-nat-mapping-entries[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v6-lan-public-prefixes[].request-index', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v6-lan-public-prefixes[].v6-next-hop-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v6-lan-public-prefixes[].v6-lan-public-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v6-lan-public-prefixes[].v6-lan-public-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v6-lan-public-prefixes[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v4-lan-public-prefixes[].request-index', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v4-lan-public-prefixes[].v4-lan-public-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v4-lan-public-prefixes[].v4-next-hop-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v4-lan-public-prefixes[].v4-lan-public-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].t-provided-v4-lan-public-prefixes[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-static-routes[].v6-static-route-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-static-routes[].v6-next-hop-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-static-routes[].v6-static-route-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-static-routes[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-static-routes[].v4-static-route-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-static-routes[].v4-next-hop-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-static-routes[].v4-static-route-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-static-routes[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-pat-enabled', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-pat-default-pool-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].use-v4-default-pool', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-pat-default-pool-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-pat-pools[].v4-pat-pool-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-pat-pools[].v4-pat-pool-next-hop-address', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-pat-pools[].v4-pat-pool-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-pat-pools[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-firewall-packet-filters[].v6-firewall-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-firewall-packet-filters[].v6-firewall-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-firewall-packet-filters[].allow-icmp-ping', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-firewall-packet-filters[].udp-port-list[].port-number', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-firewall-packet-filters[].udp-port-list[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-firewall-packet-filters[].tcp-port-list[].port-number', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-firewall-packet-filters[].tcp-port-list[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v6-firewall-packet-filters[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].stateful-firewall-lite-v4-enabled', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].stateful-firewall-lite-v6-enabled', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].allow-icmp-ping', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].udp-port-list[].port-number', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].udp-port-list[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].tcp-port-list[].port-number', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].tcp-port-list[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].v4-firewall-prefix', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].v4-firewall-prefix-length', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].key', +'service-configuration-operation-input.vr-lan.vr-lan-interface[].key', +'service-configuration-operation-input.internet-evc-access-information.internet-evc-speed-value', +'service-configuration-operation-input.internet-evc-access-information.ip-version', +'service-configuration-operation-input.internet-evc-access-information.internet-evc-speed-units', +'service-configuration-operation-input.l2-homing-information.preferred-aic-clli', +'service-configuration-operation-input.l2-homing-information.evc-name', +'service-configuration-operation-input.l2-homing-information.topology', +'service-configuration-operation-input.internet-service-change-details.internet-evc-speed-value', +'service-configuration-operation-input.internet-service-change-details.internet-evc-speed-units', +'service-configuration-operation-input.internet-service-change-details.t-provided-v4-lan-public-prefixes[].request-index', +'service-configuration-operation-input.internet-service-change-details.t-provided-v4-lan-public-prefixes[].v4-lan-public-prefix', +'service-configuration-operation-input.internet-service-change-details.t-provided-v4-lan-public-prefixes[].v4-lan-public-prefix-length', +'service-configuration-operation-input.internet-service-change-details.t-provided-v4-lan-public-prefixes[].key', +'service-configuration-operation-input.internet-service-change-details.t-provided-v6-lan-public-prefixes[].request-index', +'service-configuration-operation-input.internet-service-change-details.t-provided-v6-lan-public-prefixes[].v6-lan-public-prefix', +'service-configuration-operation-input.internet-service-change-details.t-provided-v6-lan-public-prefixes[].v6-lan-public-prefix-length', +'service-configuration-operation-input.internet-service-change-details.t-provided-v6-lan-public-prefixes[].key' +]; + +a=[ + "service-configuration-operation-input.sdnc-request-header.svc-notification-url", + "service-configuration-operation-input.sdnc-request-header.svc-request-id", + "service-configuration-operation-input.sdnc-request-header.svc-action", + "service-configuration-operation-input.vpe-vpn-service.route-target", + "service-configuration-operation-input.vpe-vpn-service.e2e-vpn-key", + "service-configuration-operation-input.vpe-vpn-service.vpn-id", + "service-configuration-operation-input.vpe-vpn-service.vpn-vame", + "service-configuration-operation-input.vpe-vpn-service.spoke-routes.route-target", + "service-configuration-operation-input.vpe-vpn-service.spoke-routes.max-threshold", + "service-configuration-operation-input.vpe-vpn-service.spoke-routes.max-routes-limit", + "service-configuration-operation-input.vpe-vpn-service.v4-max-routes.max-routes-limit-warning", + "service-configuration-operation-input.vpe-vpn-service.v4-max-routes.max-routes-limit", + "service-configuration-operation-input.vpe-vpn-service.v6-max-routes.max-routes-limit-warning", + "service-configuration-operation-input.vpe-vpn-service.v6-max-routes.max-routes-limit", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.vpn-multicast-planned-region[].regions", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.vpn-multicast-planned-region[].key", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.vpn-v4-multicast-enabled", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.max-routes-limit-warning", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.max-routes-limit", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-data-mdt", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].rp-address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].c-groups[].group-address-prefix-length", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].c-groups[].c-group-address-prefix", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].c-groups[].key", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].key", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-sm-static-override", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-ssm-default-range", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-ssm-groups[].v4-pim-ssm-group-address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-ssm-groups[].v4-pim-ssm-group-address-prefix-length", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-ssm-groups[].key", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-default-mdt", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-data-mdt-wildcard-mask", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.vpn-v6-multicast-enabled", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.max-routes-limit-warning", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.max-routes-limit", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].rp-address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].c-groups[].group-address-prefix-length", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].c-groups[].c-group-address-prefix", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].c-groups[].key", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].key", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-sm-static-override", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-ssm-default-range", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-ssm-groups[].v6-pim-ssm-group-address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-ssm-groups[].v6-pim-ssm-group-address-prefix-length", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-ssm-groups[].key", + "service-configuration-operation-input.vpe-vpn-service.customer-id", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].router-distinguisher", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vpe-name", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-import-details[].vrf-import", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-import-details[].key", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].member", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].name", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-name", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-export-details[].vrf-export", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-export-details[].key", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].apply-group-template[].apply-group", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].apply-group-template[].key", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].key", + "service-configuration-operation-input.service-information.subscriber-name", + "service-configuration-operation-input.service-information.subscriber-global-id", + "service-configuration-operation-input.service-information.service-type", + "service-configuration-operation-input.service-information.service-instance-id", + "service-configuration-operation-input.request-information.notification-url", + "service-configuration-operation-input.request-information.order-number", + "service-configuration-operation-input.request-information.order-version", + "service-configuration-operation-input.request-information.request-action", + "service-configuration-operation-input.request-information.request-sub-action", + "service-configuration-operation-input.request-information.source", + "service-configuration-operation-input.request-information.request-id", + "service-configuration-operation-output.configuration-response-common.svc-request-id", + "service-configuration-operation-output.configuration-response-common.response-message", + "service-configuration-operation-output.configuration-response-common.ack-final-indicator", + "service-configuration-operation-output.configuration-response-common.response-code" +]; +var nObj={}; +for(var i=0;i<a.length;i++){ + dotToJson(a[i],'',nObj); +} +var a = [ + "service-configuration-operation-input.sdnc-request-header.svc-notification-url:String", + "service-configuration-operation-input.sdnc-request-header.svc-request-id:String", + "service-configuration-operation-input.sdnc-request-header.svc-action:Enum:[Createupdatevpn]", + "service-configuration-operation-input.vpe-vpn-service.route-target:String", + "service-configuration-operation-input.vpe-vpn-service.e2e-vpn-key:String", + "service-configuration-operation-input.vpe-vpn-service.vpn-id:Integer", + "service-configuration-operation-input.vpe-vpn-service.vpn-vame:String", + "service-configuration-operation-input.vpe-vpn-service.spoke-routes.route-target:String", + "service-configuration-operation-input.vpe-vpn-service.spoke-routes.max-threshold:Short", + "service-configuration-operation-input.vpe-vpn-service.spoke-routes.max-routes-limit:BigInteger", + "service-configuration-operation-input.vpe-vpn-service.v4-max-routes.max-routes-limit-warning:Short", + "service-configuration-operation-input.vpe-vpn-service.v4-max-routes.max-routes-limit:BigInteger", + "service-configuration-operation-input.vpe-vpn-service.v6-max-routes.max-routes-limit-warning:Short", + "service-configuration-operation-input.vpe-vpn-service.v6-max-routes.max-routes-limit:BigInteger", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.vpn-multicast-planned-region[].regions:Enum:[EMEA, US, AP, LA, Canada]", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.vpn-multicast-planned-region[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.vpn-v4-multicast-enabled:Enum:[Y, N]", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.max-routes-limit-warning:Short", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.max-routes-limit:BigInteger", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-data-mdt:Ipv4Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].rp-address:Ipv4Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].c-groups[].group-address-prefix-length:Short", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].c-groups[].c-group-address-prefix:Ipv4Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].c-groups[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-static-rp-triplet[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-sm-static-override:Enum:[Y, N]", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-ssm-default-range:Enum:[Y, N]", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-ssm-groups[].v4-pim-ssm-group-address:Ipv4Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-ssm-groups[].v4-pim-ssm-group-address-prefix-length:Short", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-pim-ssm-groups[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-default-mdt:Ipv4Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v4-multicast.v4-data-mdt-wildcard-mask:Ipv4Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.vpn-v6-multicast-enabled:Enum:[Y, N]", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.max-routes-limit-warning:Short", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.max-routes-limit:BigInteger", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].rp-address:Ipv6Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].c-groups[].group-address-prefix-length:Short", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].c-groups[].c-group-address-prefix:Ipv6Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].c-groups[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-static-rp-triplet[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-sm-static-override:Enum:[Y, N]", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-ssm-default-range:Enum:[Y, N]", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-ssm-groups[].v6-pim-ssm-group-address:Ipv6Address", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-ssm-groups[].v6-pim-ssm-group-address-prefix-length:Short", + "service-configuration-operation-input.vpe-vpn-service.multicast-parameters.v6-multicast.v6-pim-ssm-groups[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.customer-id:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].router-distinguisher:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vpe-name:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-import-details[].vrf-import:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-import-details[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].member:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].name:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-name:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-export-details[].vrf-export:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].vrf-export-details[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].apply-group-template[].apply-group:String", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].apply-group-template[].key:Identifier", + "service-configuration-operation-input.vpe-vpn-service.vrf-details[].key:Identifier", + "service-configuration-operation-input.service-information.subscriber-name:String", + "service-configuration-operation-input.service-information.subscriber-global-id:String", + "service-configuration-operation-input.service-information.service-type:Enum:[NBIPVPN]", + "service-configuration-operation-input.service-information.service-instance-id:String", + "service-configuration-operation-input.request-information.notification-url:String", + "service-configuration-operation-input.request-information.order-number:String", + "service-configuration-operation-input.request-information.order-version:String", + "service-configuration-operation-input.request-information.request-action:Enum:[Layer3ServiceVPNRequest]", + "service-configuration-operation-input.request-information.request-sub-action:Enum:[ACTIVATE, COMPLETE, CANCEL, SUPP]", + "service-configuration-operation-input.request-information.source:String", + "service-configuration-operation-input.request-information.request-id:String" +] +var nObj={}; +for(var i=0;i<a.length;i++){ + var key =a[i].substring(0,a[i].indexOf(':')); + console.log(key); + var value =a[i].substring(a[i].indexOf(':') +1); + if(value == undefined) value =""; + dotToJson(key,value,nObj); +} +//nObj={};, +//var a1='service-configuration-operation-input[].vr-lan.vr-lan-interface[].v4-firewall-packet-filters[].v4-firewall-prefix-length';, + //dotToJson(a1,'',nObj); +console.log(JSON.stringify(nObj,null,4)); +//console.log (stringToObj('abc.ebg.h',"",{})); diff --git a/dgbuilder/tools/json_to_html b/dgbuilder/tools/json_to_html new file mode 100644 index 00000000..51afe452 --- /dev/null +++ b/dgbuilder/tools/json_to_html @@ -0,0 +1,139 @@ +try{ +var jsonStr='{}'; +jsonObj=JSON.parse(jsonStr); +var objectId =0; +var level=0; +var htmlStr="" +htmlStr += "<html>"; +htmlStr += "<head>"; +htmlStr += "<script>"; +htmlStr += "function show(idVal){"; +htmlStr += " var val = \"<table border='1'>\" + document.getElementById(idVal).value + \"</table>\";"; +htmlStr += " document.getElementById('displayId').innerHTML = val;"; +htmlStr += "document.getElementById('displayId').style.display = \"block\";"; +//htmlStr += "alert(idVal);"; +//htmlStr += "alert(val);"; +htmlStr += "}"; +htmlStr += "</script>"; +htmlStr += "</head>"; +htmlStr += "<div id='displayId' style='display:none'></div>"; +htmlStr += "<div>\n<table border='1'>\n"; +printObjectValues(jsonObj,level); +htmlStr += "\n</table>\n</div>"; +//var pattern = new RegExp("\\n","g"); +//htmlstr =htmlStr.replace(pattern,''); +htmlStr += "</html>"; +console.log(htmlStr); + +function tabs(level){ +return ''; +} +function tabsOrig(level){ + var tabs=""; + for(var i=0;i<level;i++){ + tabs += "\t"; + } + return tabs; +} + +function printObjectValues(jsonObj,level){ +var output=""; +var objectHtmlStr=""; +try{ +for (var key in jsonObj) { +//console.log(key +":" + jsonObj.hasOwnProperty(key)); + if (jsonObj.hasOwnProperty(key)) { + var v = jsonObj[key]; + if(typeof v === 'object' && Array.isArray(v) === false){ + var idVal = objectId++; + level++; + objectHtmlStr += tabs(level) + "<div>\n" ; + objectHtmlStr += tabs(level+1 ) +"<table border='1'>\n" ; + + var str=printObjectValues(v,level+2); + if(str != null && str != ''){ + htmlStr += tabs(level+2) + objectHtmlStr + "<tr><td style='background-color:green'><a href=\"javascript:show('obj_" + idVal + "')\">" + key + "</a>\n"; + htmlStr +="<input id='obj_" + idVal + "' type='hidden' value='" + str.trim() + "'>\n"; + } + + htmlStr += tabs(level+1) + "</table>\n" ; + htmlStr += tabs(level) + "</div>\n"; + }else if(typeof v === 'object' && Array.isArray(v) === true){ + var idVal = objectId++; + level++; + objectHtmlStr += tabs(level) + "<div>\n"; + objectHtmlStr += tabs(level+1) + "<table border='1'>\n"; + + var str = printArrayValues(v,key,level+2); + if(str != null && str != ''){ + htmlStr += tabs(level+2) + objectHtmlStr + "<tr><td style='background-color:blue'><a href=\"javascript:show('obj_" + idVal + "')\">" + key + "</a>\n"; + htmlStr+="<input id='obj_" + objectId + "' type='hidden' value='" + str.trim() + "'>\n"; + } + + htmlStr += tabs(level+1) + "</table>\n" ; + htmlStr += tabs(level) + "</div>\n"; + }else{ + output += tabs(level) +"<tr><td>" + key + "</td><td>" + printValue(v) + "</td></tr>\n"; + } + } +} +}catch(err){ + console.log(err); +} +return output; +} + +}catch(err){ +console.log( err ); +} + +function printArrayValues(arrObj,key,level){ +var output =""; +var arrayHtmlStr =""; +try{ + for(var i=0;arrObj != null && i<arrObj.length;i++){ + var o=arrObj[i]; + if(typeof o === 'object' && Array.isArray(o) === false){ + var idVal = objectId++; + level++; + arrayHtmlStr += tabs(level) + "<div>\n" ; + arrayHtmlStr += tabs(level+1 ) +"<table border='1'>\n" ; + + var str = printObjectValues(o,level+2); + if(str != null && str != ''){ + htmlStr += tabs(level+2 ) + arrayHtmlStr + "<tr><td><a href=\"javascript:show('obj_" + idVal + "')\">" +key + "[" + i + "]" + "</a>\n"; + htmlStr+="<input id='obj_" + idVal + "' type='hidden' value='" +str.trim() + "'>\n"; + } + htmlStr += tabs(level+1) + "</table>\n"; + htmlStr += tabs(level) + "</div>\n"; + }else if(typeof o === 'object' && Array.isArray(v) === true){ + var idVal = objectId++; + level++; + arrayHtmlStr += tabs(level) + "<div>\n" ; + arrayHtmlStr += tabs(level+1 ) +"<table border='1'>\n" ; + + var str = printArrayValues(o,key,level); + if(str != null && str != ''){ + htmlStr += tabs(level+2 ) + arrayHtmlStr + "<tr><td><a href=\"javascript:show('obj_" + idVal + "')\">Array</a>\n"; + htmlStr+="<input id='obj_" + idVal + "' type='hidden' value='" +str.trim() + "'>\n"; + } + + htmlStr += tabs(level+1) + "</table>\n"; + htmlStr += tabs(level) + "</div>\n"; + }else{ + output += tabs(level) + "<tr><td>" + printValue(o) + "</td></tr>\n"; + } + } +}catch(err){ + console.log(err); +} +return output; +} + +function printValue(obj){ + if(obj != undefined){ + return obj; + }else{ + return ""; + } +} diff --git a/dgbuilder/tools/json_to_html_table b/dgbuilder/tools/json_to_html_table new file mode 100755 index 00000000..20c9cfeb --- /dev/null +++ b/dgbuilder/tools/json_to_html_table @@ -0,0 +1,144 @@ +try{ +var jsonStr='{}'; +jsonObj=JSON.parse(jsonStr); +var htmlObj ={}; +var objectId =0; +var level=0; +var htmlStr="" +htmlStr += "<html>"; +htmlStr += "<head>"; +htmlStr += "<script>"; +htmlStr += "function show(idVal){"; +htmlStr += " var val = \"<table border='1'>\" + document.getElementById(idVal).value + \"</table>\";"; +htmlStr += " document.getElementById('displayId').innerHTML = val;"; +htmlStr += "document.getElementById('displayId').style.display = \"block\";"; +//htmlStr += "alert(idVal);"; +//htmlStr += "alert(val);"; +htmlStr += "}"; +htmlStr += "</script>"; +htmlStr += "</head>"; +htmlStr += "<div id='displayId' style='display:none'></div>"; +htmlStr += "<div>\n<table border='1'>\n"; +console.log("<html><table border='1'>"); +printObjectValues(jsonObj,null,level); +console.log("</table></html>"); +htmlStr += "\n</table>\n</div>"; +//var pattern = new RegExp("\\n","g"); +//htmlstr =htmlStr.replace(pattern,''); +htmlStr += "</html>"; +//console.log(htmlStr); + +//console.dir(htmlObj); +var keyObj={}; +for (var key in htmlObj) { + var idx = key.lastIndexOf("."); + if(idx != -1){ + var str = key.substr(0,idx); + keyObj[str] =''; + }else{ + keyObj[key] =''; + } + //console.log(str); +} + +console.dir(keyObj); +console.log("<ul>"); +for (var key in keyObj) { + console.log("<li>" + key + "</li>"); +} +console.log("</ul>"); + +function tabs(level){ +return ''; +} +function tabsOrig(level){ + var tabs=""; + for(var i=0;i<level;i++){ + tabs += "\t"; + } + return tabs; +} + +function printObjectValues(jsonObj,pkey,level){ +var output=""; +var objectHtmlStr=""; +try{ +for (var key in jsonObj) { + if (jsonObj.hasOwnProperty(key)) { + var v = jsonObj[key]; + if(typeof v === 'object' && Array.isArray(v) === false){ + var nkey=""; + if(pkey != null){ + nkey = pkey + "." + key; + }else{ + nkey = key; + } + var str=printObjectValues(v,nkey,level+2); + }else if(typeof v === 'object' && Array.isArray(v) === true){ + var nkey=""; + if(pkey != null){ + nkey = pkey + "." + key; + }else{ + nkey = key; + } + var str = printArrayValues(v,nkey,level+2); + }else{ + if(pkey != null){ + //console.log(pkey + "." + key + ":" +printValue(v) ); + console.log("<tr><td>" + pkey + "." + key + "</td><td>" +printValue(v) + "</td></tr>" ); + htmlObj[pkey + "." + key ] = printValue(v); + }else{ + //console.log( key + ":" +printValue(v) ); + console.log("<tr><td>" + key + "</td><td>" +printValue(v) + "</td></tr>" ); + htmlObj[key ] = printValue(v); + } + //printValue(v); + } + } +} +}catch(err){ + console.log(err); +} +return output; +} + +}catch(err){ +console.log( err ); +} + +function printArrayValues(arrObj,pkey,level){ +var output =""; +var arrayHtmlStr =""; +try{ + for(var i=0;arrObj != null && i<arrObj.length;i++){ + var o=arrObj[i]; + if(typeof o === 'object' && Array.isArray(o) === false){ + var nkey = pkey +"[" + i + "]" ; + var str = printObjectValues(o,nkey,level+2); + }else if(typeof o === 'object' && Array.isArray(v) === true){ + var nkey = pkey +"[" + i + "]" ; + var str = printArrayValues(o,nkey,level); + }else{ + console.log("<tr><td>" + pkey + "." + key + "</td><td>" +printValue(o) + "</td></tr>" ); + htmlObj[pkey + "." + key ] = printValue(o); + //console.log(pkey + ":" +printValue(o) ); + //output += tabs(level) + "<tr><td>" + printValue(o) + "</td></tr>\n"; + } + } +}catch(err){ + console.log(err); +} +return output; +} + +function printValue(obj){ + if(obj != undefined){ + if(typeof obj == 'string'){ + return "'" + obj + "'"; + }else{ + return obj; + } + }else{ + return ""; + } +} diff --git a/dgbuilder/tools/json_to_prop b/dgbuilder/tools/json_to_prop new file mode 100755 index 00000000..f8830f38 --- /dev/null +++ b/dgbuilder/tools/json_to_prop @@ -0,0 +1,116 @@ +try{ +var jsonStr='{}'; +jsonObj=JSON.parse(jsonStr); +var htmlObj ={}; +var objectId =0; +var level=0; +var htmlStr="" +htmlStr += "<html>"; +htmlStr += "<head>"; +htmlStr += "<script>"; +htmlStr += "function show(idVal){"; +htmlStr += " var val = \"<table border='1'>\" + document.getElementById(idVal).value + \"</table>\";"; +htmlStr += " document.getElementById('displayId').innerHTML = val;"; +htmlStr += "document.getElementById('displayId').style.display = \"block\";"; +//htmlStr += "alert(idVal);"; +//htmlStr += "alert(val);"; +htmlStr += "}"; +htmlStr += "</script>"; +htmlStr += "</head>"; +htmlStr += "<div id='displayId' style='display:none'></div>"; +htmlStr += "<div>\n<table border='1'>\n"; +printObjectValues(jsonObj,null,level); +htmlStr += "\n</table>\n</div>"; +//var pattern = new RegExp("\\n","g"); +//htmlstr =htmlStr.replace(pattern,''); +htmlStr += "</html>"; +//console.log(htmlStr); + +function tabs(level){ +return ''; +} +function tabsOrig(level){ + var tabs=""; + for(var i=0;i<level;i++){ + tabs += "\t"; + } + return tabs; +} + +function printObjectValues(jsonObj,pkey,level){ +var output=""; +var objectHtmlStr=""; +try{ +for (var key in jsonObj) { + if (jsonObj.hasOwnProperty(key)) { + var v = jsonObj[key]; + if(typeof v === 'object' && Array.isArray(v) === false){ + var nkey=""; + if(pkey != null){ + nkey = pkey + "." + key; + }else{ + nkey = key; + } + var str=printObjectValues(v,nkey,level+2); + }else if(typeof v === 'object' && Array.isArray(v) === true){ + var nkey=""; + if(pkey != null){ + nkey = pkey + "." + key; + }else{ + nkey = key; + } + var str = printArrayValues(v,nkey,level+2); + }else{ + if(pkey != null){ + console.log(pkey + "." + key + ":" +printValue(v) ); + }else{ + console.log(key + ":" +printValue(v) ); + } + //printValue(v); + } + } +} +}catch(err){ + console.log(err); +} +return output; +} + +}catch(err){ +console.log( err ); +} + +function printArrayValues(arrObj,pkey,level){ +var output =""; +var arrayHtmlStr =""; +try{ + for(var i=0;arrObj != null && i<arrObj.length;i++){ + var o=arrObj[i]; + if(typeof o === 'object' && Array.isArray(o) === false){ + var nkey = pkey +"[" + i + "]" ; + var str = printObjectValues(o,nkey,level+2); + }else if(typeof o === 'object' && Array.isArray(v) === true){ + var nkey = pkey +"[" + i + "]" ; + var str = printArrayValues(o,nkey,level); + }else{ + console.log(pkey + ":" +printValue(o) ); + //output += tabs(level) + "<tr><td>" + printValue(o) + "</td></tr>\n"; + } + } +}catch(err){ + console.log(err); +} +return output; +} + +function printValue(obj){ + if(obj != undefined){ + if(typeof obj == 'string'){ + return "'" + obj + "'"; + }else{ + return obj; + } + }else{ + return ""; + } +} diff --git a/dgbuilder/tools/module-provider-impl.yang b/dgbuilder/tools/module-provider-impl.yang new file mode 100644 index 00000000..62059104 --- /dev/null +++ b/dgbuilder/tools/module-provider-impl.yang @@ -0,0 +1,61 @@ +module yangApp-provider-impl { + + yang-version 1; + namespace "brocade:training:yangApp:provider:impl"; + prefix "yangApp-provider-impl"; + + import config { prefix config; revision-date 2013-04-05; } + import opendaylight-md-sal-binding { prefix mdsal; revision-date 2013-10-28; } + + description + "This module contains the base YANG definitions for + yangApp-provider impl implementation."; + + revision "2014-05-23" { + description + "Initial revision."; + } + + // This is the definition of the service implementation as a module identity. + identity yangApp-provider-impl { + base config:module-type; + + // Specifies the prefix for generated java classes. + config:java-name-prefix yangAppProvider; + } + + // Augments the 'configuration' choice node under modules/module. + // We consume the three main services, RPCs, DataStore, and Notifications + augment "/config:modules/config:module/config:configuration" { + case yangApp-provider-impl { + when "/config:modules/config:module/config:type = 'yangApp-provider-impl'"; + + container rpc-registry { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity mdsal:binding-rpc-registry; + } + } + } + + container notification-service { + uses config:service-ref { + refine type { + mandatory true; + config:required-identity mdsal:binding-notification-service; + } + } + } + + container data-broker { + uses config:service-ref { + refine type { + mandatory false; + config:required-identity mdsal:binding-async-data-broker; + } + } + } + } + } +} diff --git a/dgbuilder/tools/module-provider-impl.yang.bak b/dgbuilder/tools/module-provider-impl.yang.bak new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/dgbuilder/tools/module-provider-impl.yang.bak diff --git a/dgbuilder/tools/output_js/.gitignore b/dgbuilder/tools/output_js/.gitignore new file mode 100644 index 00000000..d6b7ef32 --- /dev/null +++ b/dgbuilder/tools/output_js/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/dgbuilder/tools/printYangProps.sh b/dgbuilder/tools/printYangProps.sh new file mode 100755 index 00000000..7d1d0faf --- /dev/null +++ b/dgbuilder/tools/printYangProps.sh @@ -0,0 +1,8 @@ +toolsDir=$PROJECT_HOME/tools +. ${toolsDir}/setClasspath +if [ "$#" != "1" ] +then + echo "Usage $0 className_without_the_dot_class_ext" + exit +fi + java PrintYangToProp $1 diff --git a/dgbuilder/tools/printYangToProp.jar b/dgbuilder/tools/printYangToProp.jar Binary files differnew file mode 100644 index 00000000..01b73107 --- /dev/null +++ b/dgbuilder/tools/printYangToProp.jar diff --git a/dgbuilder/tools/rs b/dgbuilder/tools/rs new file mode 100755 index 00000000..3d92b627 --- /dev/null +++ b/dgbuilder/tools/rs @@ -0,0 +1,2 @@ +#replaces / with a . +echo $1|sed -e s%/%.%g diff --git a/dgbuilder/tools/setClasspath b/dgbuilder/tools/setClasspath new file mode 100755 index 00000000..082d31a2 --- /dev/null +++ b/dgbuilder/tools/setClasspath @@ -0,0 +1,10 @@ +toolsDir=${PROJECT_HOME}/tools +export CLASSPATH= +export CLASSPATH=${toolsDir}/guava-14.0.1.jar:$CLASSPATH +export CLASSPATH=${toolsDir}/javax.json-api-1.0.jar:$CLASSPATH +export CLASSPATH=${toolsDir}/slf4j-api-1.7.2.jar:$CLASSPATH + +for i in `find ${toolsDir}/tmpws/jars -name "*.jar" -print` +do +export CLASSPATH=$CLASSPATH:$i +done diff --git a/dgbuilder/tools/slf4j-api-1.7.2.jar b/dgbuilder/tools/slf4j-api-1.7.2.jar Binary files differnew file mode 100644 index 00000000..1a887083 --- /dev/null +++ b/dgbuilder/tools/slf4j-api-1.7.2.jar diff --git a/dgbuilder/tools/update_app_impl_yang.sh b/dgbuilder/tools/update_app_impl_yang.sh new file mode 100755 index 00000000..9ae5610b --- /dev/null +++ b/dgbuilder/tools/update_app_impl_yang.sh @@ -0,0 +1,45 @@ +toolsDir=$PROJECT_HOME/tools +appRootDir=$1 +yangFileFullPath=$2 +yangFile=$(basename $yangFileFullPath) + +if [ "$#" != "2" ] +then + echo "Usage: $0 appRootDir yangModuleName example:$0 bwcal bwcal" + exit +fi +cd ${toolsDir}/tmpws +#cp ${toolsDir}/module-provider-impl.yang ${toolsDir}/tmpws + +if [ ! -e "${toolsDir}/module-provider-impl.yang" ] +then + echo "${toolsDir}/module-provider-impl.yang should exist" + exit +fi + +#echo "appRootDir:$appRootDir" +#echo "yangFileFullPath:$yangFileFullPath" +#echo "yangFile:$yangFile" + +cp ${yangFileFullPath} ${appRootDir}/model/src/main/yang/${yangFile} +if [ "$?" != "0" ] +then + echo "Could not copy the yang file. Exiting ..." + exit +fi + +moduleName=$(cat $yangFileFullPath|egrep "module .*{"|cut -d' ' -f2|cut -d'{' -f1) +#echo $moduleName +sed -i.bak s/\$MODULE/$1/g ${toolsDir}/module-provider-impl.yang +cp ${toolsDir}/module-provider-impl.yang ${appRootDir}/provider/src/main/yang/${appRootDir}-provider-impl.yang +cd $appRootDir +mvn clean install >${toolsDir}/tmpws/logs/mvn_install.log 2>&1 +mkdir ${toolsDir}/tmpws/jars +cp ./model/target/${appRootDir}.model-1.0.0-SNAPSHOT.jar ${toolsDir}/tmpws/jars + +mv ${toolsDir}/output_js/${moduleName}_inputs.js ${toolsDir}/output_js/${moduleName}_inputs_prev.js >/dev/null 2>&1 + +${toolsDir}/getRpcsClassFromYang.sh ${yangFileFullPath} ${toolsDir}/tmpws/${appRootDir}/model/target/${appRootDir}.model-1.0.0-SNAPSHOT.jar > ${toolsDir}/output_js/${moduleName}.js + +node ${toolsDir}/dot_to_json.js ${toolsDir}/output_js/${moduleName}.js $moduleName >${toolsDir}/output_js/${moduleName}_inputs.js +cp ${toolsDir}/output_js/${moduleName}_inputs.js $PROJECT_HOME/generatedJS diff --git a/dgbuilder/tools/update_app_impl_yangs.sh b/dgbuilder/tools/update_app_impl_yangs.sh new file mode 100755 index 00000000..612f97d3 --- /dev/null +++ b/dgbuilder/tools/update_app_impl_yangs.sh @@ -0,0 +1,51 @@ +toolsDir=$PROJECT_HOME/tools +appRootDir=$1 +yangFilesDirFullPath=$2 +baseYangFile=$3 + +#echo ${appRootDir} +#echo ${yangFilesDirFullPath} +#echo ${baseYangFile} +if [ "$#" -lt "3" ] +then + echo "Usage: $0 appRootDir yangFilesDirectoryFullPath baseYangFile example:$0 asdcApi /home/brocade/sdnc/asdcApi ASDC-API.yang" + exit +fi +cd ${toolsDir}/tmpws +#cp ${toolsDir}/module-provider-impl.yang ${toolsDir}/tmpws + +if [ ! -e "${toolsDir}/module-provider-impl.yang" ] +then + echo "module-provider-impl.yang should exist in the current directory" + exit +fi + +#echo "appRootDir:$appRootDir" +#echo "yangFileFullPath:$yangFileFullPath" +#echo "yangFile:$yangFile" +cp ${yangFilesDirFullPath}/*.yang ${appRootDir}/model/src/main/yang +if [ "$?" != "0" ] +then + echo "Could not copy the yang file. Exiting ..." + exit +fi + +moduleName=$(cat ${yangFilesDirFullPath}/${baseYangFile}|egrep "module .*{"|cut -d' ' -f2|cut -d'{' -f1) +sed -i.bak s/\$MODULE/$1/g ${toolsDir}/module-provider-impl.yang +cp ${toolsDir}/module-provider-impl.yang ${appRootDir}/provider/src/main/yang/${appRootDir}-provider-impl.yang +cd $appRootDir +mvn clean install >${toolsDir}/tmpws/logs/mvn_install.log 2>&1 +if [ "$?" != "0" ] +then + echo "mvn compile failed" + exit 1 +fi +mkdir ${toolsDir}/tmpws/jars +cp ./model/target/${appRootDir}.model-1.0.0-SNAPSHOT.jar ${toolsDir}/tmpws/jars + +mv ${toolsDir}/output_js/${moduleName}.js ${toolsDir}/output_js/${moduleName}.js_prev >/dev/null 2>&1 +${toolsDir}/getRpcsClassFromYangs.sh ${yangFilesDirFullPath}/${baseYangFile} ${toolsDir}/tmpws/${appRootDir}/model/target/${appRootDir}.model-1.0.0-SNAPSHOT.jar > ${toolsDir}/output_js/${moduleName}.js + +mv ${toolsDir}/output_js/${moduleName}_inputs.js ${toolsDir}/output_js/${moduleName}_inputs_prev.js >/dev/null 2>&1 +node ${toolsDir}/dot_to_json.js ${toolsDir}/output_js/${moduleName}.js $moduleName >>${toolsDir}/output_js/${moduleName}_inputs.js +cp ${toolsDir}/output_js/${moduleName}_inputs.js $PROJECT_HOME/generatedJS |