Merge "First real draft of YangIDE user guide."
[docs.git] / manuals / user-guide / src / main / asciidoc / yangide / yangide-user.adoc
1 == YANG IDE User Guide
2
3 === Overview
4
5 The YANG IDE project provides an Eclipse plugin that is used to create,
6 view, and edit Yang model files.  It currently supports version 1.0 of
7 the Yang specification.
8
9 The YANG IDE project uses components from the OpenDaylight project for
10 parsing and verifying Yang model files.  The "yangtools" parser in
11 OpenDaylight is generally used for generating Java code associated
12 with Yang models.  If you are just using the YANG IDE to view and edit
13 Yang models, you do not need to know any more about this.
14
15 Although the YANG IDE plugin is used in Eclipse, it is not necessary to
16 be familiar with the Java programming language to use it effectively.
17
18 The YANG IDE also uses the Maven build tool, but you do not have to be
19 a Maven expert to use it, or even know that much about it.  Very
20 little configuration of Maven files will have to be done by you.  In
21 fact, about the only thing you will likely ever need to change can be
22 done entirely in the Eclipse GUI forms, without even seeing the
23 internal structure of the Maven POM file (Project Object Model).
24
25 The YANG IDE plugin provides features that are similar to other
26 programming language plugins in the Eclipse ecosystem.
27
28 For instance, you will find support for the following:
29
30 * Immediate "as-you-type" display of syntactic and semantic errors
31 * Intelligent completion of language tokens, limited to only choices
32 valid in the current scope and namespace
33 * Consistent (and customizable) color-coding of syntactic and semantic symbols
34 * Provides access to remote Yang models by specifying dependency on
35 Maven artifact containing models (or by manual inclusion in project)
36 * One-click navigation to referenced symbols in external files
37 * Mouse hovers display descriptions of referenced components
38 * Tools for refactoring or renaming components respect namespaces
39 * Code templates can be entered for common conventions
40
41 Forthcoming sections of this manual will step through how to utilize
42 these features.
43
44 === Creating a Yang Project
45
46 After the plugin is installed, the next thing you have to do is create
47 a Yang Project.  This is done from the "File" menu, selecting "New",
48 and navigating to the "Yang" section and selecting "YANG Project", and
49 then clicking "Next" for more items to configure.
50
51 Some shortcuts for these steps are the following:
52
53 * Typically, the key sequence "Ctrl+n" (press "n" while holding down
54 one of the "ctrl" keys) is bound to the "new" function
55 * In the "New" wizard dialog, the initial focus is in the filter
56 field, where you can enter "yang" to limit the choices to only the
57 functions provided by the YANG IDE plugin
58 * On the "New" wizard dialog, instead of clicking the "Next" button
59 with your mouse, you can press "Alt+n" (you will see a hint for this
60 with the "N" being underlined)
61
62 ==== First Yang Project Wizard Page
63
64 After the "Next" button is pressed, it goes to the first wizard page
65 that is specific to creating Yang projects.  you will see a subtitle on
66 this page of "YANG Tools Configuration".  In almost all cases, you
67 should be able to click "Next" again on this page to go to the next
68 wizard page.
69
70 However, some information about the fields on this page would be helpful.
71
72 You will see the following labeled fields and sections:
73
74 ===== Yang Files Root Directory
75
76 This defaults to "src/main/yang".  Except when creating your first
77 Yang file, you, you do not even have to know this, as Eclipse presents
78 the same interface to view your Yang files no matter what you set
79 this to.
80
81 ===== Source Code Generators
82
83 If you do not know what this is, you do not need to know about it.  The
84 "yangtools" Yang parser from OpenDaylight uses a "code generator"
85 component to generate specific kinds of Java classes from the Yang
86 models.  Again, if you do not need to work with the generated Java
87 code, you do not need to change this.
88
89 ===== Create Example YANG File
90
91 This is likely the only field you will ever have any reason to change.
92 If this checkbox is set, when the YANG IDE creates the Yang project,
93 it will create a sample "acme-system.yang" file which you can view and
94 edit to demonstrate the features of the tool to yourself.  If you
95 do not need this file, then either delete it from the project or
96 uncheck the checkbox to prevent its creation.
97
98 When done with the fields on this page, click the "Next" button to go
99 to the next wizard page.
100
101 ==== Second Yang Project Wizard Page
102
103 This page has a subtitle of "New Maven project".  There are several
104 fields on this page, but you will only ever have to see and change the
105 setting of the first field, the "Create a simple project" checkbox.
106 You should always set this ON to avoid the selection of a Maven
107 archetype, which is something you do not need to do for creating a
108 Yang project.
109
110 Click "Next" at the bottom of the page to move to the next wizard page.
111
112 ==== Third Yang Project Wizard Page
113
114 This also has a subtitle of "New Maven project", but with different
115 fields to set.  You will likely only ever set the first two fields,
116 and completely ignore everything else.
117
118 The first field is labeled "Group id" in the "Artifact" section.  It
119 really does not matter what you set this to, but it does have to be set
120 to something.  For consistency, you might set this to the name or
121 nickname of your organization.  Otherwise, there are no constraints on
122 the value of this field.
123
124 The second field is labeled "Artifact id".  The value of this field
125 will be used as the name of the project you create, so you will have
126 to think about what you want the project to be called.  Also note that
127 this name has to be unique in the Eclipse workspace.  You cannot have
128 two projects with the same name.
129
130 After you have set this field, you will notice that the "Next" button is
131 insensitive, but now the "Finish" button is sensitive.  You can click
132 "Finish" now (or use the keyboard shortcut of "Alt+f"), and the Yang
133 IDE will finally create your project.
134
135 === Creating a Yang File
136
137 Now that you have created your project, it is time to create your first Yang file.
138
139 When you created the Yang project, you might have noticed the other
140 option next to "YANG Project", which was "YANG File".  That is what
141 you will select now.  Click "Next" to go to the first wizard page.
142
143 ==== First Yang File Wizard Page
144
145 This wizard page lets you specify where the new file will be located, and its name.
146
147 You have to select the particular project you want the file to go
148 into, and it needs to go into the "src/main/yang" folder (or a
149 different location if you changed that field when creating the
150 project).
151
152 You then enter the desired name of the file in the "File name".  The
153 file name should have no spaces or "special characters" in it.  You
154 can specify a ".yang" extent if you want.  If you do not specify an
155 extent, the YANG IDE will create it with the ".yang" extent.
156
157 Click "Next" to go to the next wizard page.
158
159 ==== Second Yang File Wizard Page
160
161 On this wizard page, you set some metadata about the module that is
162 used to initialize the contents of the Yang file.
163
164 It has the following fields:
165
166 ===== Module Name
167
168 This will default to the "base name" of the file name you created.
169 For instance, if the file name you created was "network-setup.yang",
170 this field will default to "network-setup".  You should leave this
171 value as is.  There is no good reason to define a model with a name
172 different from the file name.
173
174 ===== Namespace
175
176 This defaults to "urn:opendaylight:xxx", where "xxx" is the "base
177 name" of the file name you created.  You should put a lot of thought
178 into designing a namespace naming scheme that is used throughout your
179 organization.  It is quite common for this namespace value to look like
180 a "http" URL, but note that that is just a convention, and will not
181 necessarily imply that there is a web page residing at that HTTP
182 address.
183
184 ===== Prefix
185
186 This defaults to the "base name" of the file name you created.  It
187 mostly does not technically matter what you set this to, as long as
188 it is not empty.  Conventionally, it should be a "nickname" that is
189 used to refer to the given namespace in an abbreviated form, when
190 referenced in an "import" statement in another Yang model file.
191
192 ===== Revision
193
194 This has to be a date value in the form of "yyyy-mm-dd", representing
195 the last modified date of this Yang model.  The value will default to
196 the current date.
197
198 ===== Revision Description
199
200 This is just human-readable text, which will go into the "description"
201 field underneath the Yang "revision" field, which will describe what
202 went into this revision.
203
204 When all the fields have the content you want, click the "Finish"
205 button to set the YANG IDE create the file in the specified location.
206 It will then present the new file in the editor view for additional
207 modifications.
208
209 === Accessing Artifacts for Yang Model Imports
210
211 You might be working on Yang models that are "abstract" or are
212 intended to be imported by other Yang models.  You might also, and
213 more likely, be working on Yang models that import other "abstract"
214 Yang models.
215
216 Assuming you are in that latter more common group, you need to consider
217 for yourself, and for your organization, how you are going to get
218 access to those models that you import.
219
220 You could use a very simple and primitive approach of somehow
221 obtaining those models from some source as plain files and just
222 copying them into the "src/main/yang" folder of your project.  For a
223 simple demo or a "one-off" very short project, that might be
224 sufficient.
225
226 A more robust and maintainable approach would be to reference
227 "coordinates" of the artifacts containing Yang models to import.  When
228 you specify unique coordinates associated with that artifact, the Yang
229 IDE can retrieve the artifact in the background and make it available
230 for your "import" statements.
231
232 Those "coordinates" that I speak of refer to the Maven concepts of
233 "group id", "artifact id", and "version".  you may remember "group id"
234 and "artifact id" from the wizard page for creating a Yang project.
235 It is the same idea.  If you ever produce Yang model artifacts that
236 other people are going to import, you will want to think more about what
237 you set those values to when you created the project.
238
239 For example, the OpenDaylight project produces several importable
240 artifacts that you can specify to get access to common Yang models.
241
242 ==== Turning on Indexing for Maven Repositories
243
244 Before we talk about how to add dependencies to Maven artifacts with
245 Yang models for import, I need to explain how to make it easier to
246 find those artifacts.
247
248 In the Yang project that you have created, the "pom.xml" file (also
249 called a "POM file") is the file that Maven uses to specify
250 dependencies.  We will talk about that in a minute, but first we need to
251 talk about "repositories".  These are where artifacts are stored.
252
253 We are going to have Eclipse show us the "Maven Repositories" view.
254 In the main menu, select "Window" and then "Show View", and then
255 "Other".  Like in the "New" dialog, you can enter "maven" in the
256 filter field to limit the list to views with "maven" in the name.
257 Click on the "Maven Repositories" entry and click OK.
258
259 This will usually create the view in the bottom panel of the window.
260
261 The view presents an outline view of four principal elements: 
262
263 * Local Repositories
264 * Global Repositories
265 * Project Repositories
266 * Custom Repositories
267
268 For this purpose, the only section you care about is "Project
269 Repositories", being the repositories that are only specified in the
270 POM for the project.  There should be a "right-pointing arrow" icon on
271 the line.  Click that to expand the entry.
272
273 You should see two entries there:
274
275 * opendaylight-release
276 * opendaylight-snapshot
277
278 You will also see internet URLs associated with each of those repositories.
279
280 For this purpose, you only care about the first one.  Right-click on
281 that entry and select "Full Index Enabled".  The first time you do
282 this on the first project you create, it will spend several minutes
283 walking the entire tree of artifacts available at that repository and
284 "indexing" all of those components.  When this is done, searching for
285 available artifacts in that repository will go very quickly.
286
287 === Adding Dependencies Containing Yang Models
288
289 Double-click the "pom.xml" file in your project.  Instead of just
290 bringing up the view of an XML file (although you can see that if you
291 like), it presents a GUI form editor with a handful of tabs.
292
293 The first tab, "Overview", shows things like the "Group Id", "Artifact
294 Id", and "Version", which represents the "Maven coordinate" of your
295 project, which I have mentioned before.
296
297 Now click on the "Dependencies" tab.  You will now see two list
298 components, labeled "Dependencies" and "Dependency Management".  You
299 only care about the "Dependencies" section.
300
301 In the "Dependencies" section, you should see one dependency for an
302 artifact called "yang-binding".  This artifact is part of
303 OpenDaylight, but you do not need to know anything about it.
304
305 Now click the "Add" button.
306
307 This brings up a dialog titled "Select Dependency".  It has three
308 fields at the top labeled "Group Id", "Artifact Id", and "Version",
309 with a "Scope" dropdown.  You will never have a need to change the
310 "Scope" dropdown, so ignore it.  Despite the fact that you will need to
311 get values into these fields, in general usage, you will never have to
312 manually enter values into them, but you will see values being inserted
313 into these fields by the next steps I describe.
314
315 Below those fields is a field labeled "Enter groupId, artifactId ...".
316 This is effectively a "filter field", like on the "New" dialog, but
317 instead of limiting the list from a short list of choices, the value
318 you enter there will be matched against all of the artifacts that were
319 indexed in the "opendaylight-release" repository (and others).  It
320 will match the string you enter as a substring of any groupId or
321 artifactId.
322
323 For all of the entries that match that substring, it will list an
324 entry showing the groupId and artifactId, with an expansion arrow.  If
325 you open it by clicking on the arrow, you will see individual entries
326 corresponding to each available version of that artifact, along with
327 some metadata about the artifacts between square brackets, mostly
328 indicating what "type" of artifact is.
329
330 For your purposes, you only ever want to use "bundle" or "jar" artifacts.
331
332 Let us consider an example that many people will probably be using.
333
334 In the filter field, enter "ietf-yang-types".  Depending on what
335 versions are available, you should see a small handful of "groupId,
336 artifactId" entries there.  One of them should be groupId
337 "org.opendaylight.mdsal.model" and artifactId "ietf-yang-types".
338 Click on the expansion arrow to open that.
339
340 What you will see at this point depends on what versions are
341 available.  You will likely want to select the newest one (most likely
342 top of the list) that is also either a "bundle" or "jar" type
343 artifact.
344
345 If you click on that resulting version entry, you should notice at
346 this point that the "Group Id", "Artifact Id", and "Version" fields at
347 the top of the dialog are now filled in with the values corresponding
348 to this artifact and version.
349
350 If this is the version that you want, click OK and this artifact will
351 be added to the dependencies in the POM.
352
353 This will now make the Yang models found in that artifact available in
354 "import" statements in Yang models, not to mention the completion
355 choices for that "import" statement.