import org.opendaylight.netconf.sal.rest.doc.swagger.ResourceList;
/**
- * This service generates swagger (See <a
- * href="https://helloreverb.com/developers/swagger"
+ * This service generates swagger (See
+ * <a href="https://helloreverb.com/developers/swagger"
* >https://helloreverb.com/developers/swagger</a>) compliant documentation for
* RESTCONF APIs. The output of this is used by embedded Swagger UI.
*
- * <p>NOTE: These API's need to be synchronized due to bug 1198. Thread access to
+ * <p>
+ * NOTE: These API's need to be synchronized due to bug 1198. Thread access to
* the SchemaContext is not synchronized properly and thus you can end up with
* missing definitions without this synchronization. There are likely otherways
* to work around this limitation, but given that this API is a dev only tool
*/
@Override
public synchronized Response getApiExplorer(final UriInfo uriInfo) {
- return Response
- .seeOther(uriInfo.getBaseUriBuilder().path("../explorer/index.html").build())
- .build();
+ return Response.seeOther(uriInfo.getBaseUriBuilder().path("../explorer/index.html").build()).build();
}
@Override
try (OutputStreamWriter streamWriter = new OutputStreamWriter(baos, StandardCharsets.UTF_8)) {
final JSONWriter writer = new JSONWriter(streamWriter);
writer.array();
- for (final Entry<String, Long> entry : MountPointSwagger.getInstance()
- .getInstanceIdentifiers().entrySet()) {
+ for (final Entry<String, Long> entry : MountPointSwagger.getInstance().getInstanceIdentifiers()
+ .entrySet()) {
writer.object();
writer.key("instance").value(entry.getKey());
writer.key("id").value(entry.getValue());
public synchronized Response getMountRootDoc(final String instanceNum, final UriInfo uriInfo) {
final ResourceList resourceList;
if (isNew(uriInfo)) {
- resourceList = MountPointSwagger.getInstanceDraft17().getResourceList(uriInfo,
- Long.parseLong(instanceNum));
+ resourceList = MountPointSwagger.getInstanceDraft18().getResourceList(uriInfo, Long.parseLong(instanceNum));
} else {
- resourceList = MountPointSwagger.getInstance().getResourceList(uriInfo,
- Long.parseLong(instanceNum));
+ resourceList = MountPointSwagger.getInstance().getResourceList(uriInfo, Long.parseLong(instanceNum));
}
return Response.ok(resourceList).build();
}
@Override
public synchronized Response getMountDocByModule(final String instanceNum, final String module,
- final String revision, final UriInfo uriInfo) {
+ final String revision, final UriInfo uriInfo) {
final ApiDeclaration api;
if (isNew(uriInfo)) {
- api = MountPointSwagger.getInstanceDraft17().getMountPointApi(uriInfo,
- Long.parseLong(instanceNum), module, revision);
+ api = MountPointSwagger.getInstanceDraft18().getMountPointApi(uriInfo, Long.parseLong(instanceNum), module,
+ revision);
} else {
- api = MountPointSwagger.getInstance().getMountPointApi(uriInfo,
- Long.parseLong(instanceNum), module, revision);
+ api = MountPointSwagger.getInstance().getMountPointApi(uriInfo, Long.parseLong(instanceNum), module,
+ revision);
}
return Response.ok(api).build();
}
private static boolean isNew(final UriInfo uriInfo) {
- return uriInfo.getBaseUri().toString().contains("/17/");
+ return uriInfo.getBaseUri().toString().contains("/18/");
}
}
protected static final String API_VERSION = "1.0.0";
protected static final String SWAGGER_VERSION = "1.2";
protected static final String RESTCONF_CONTEXT_ROOT = "restconf";
- private static final String RESTCONF_DRAFT = "17";
+ private static final String RESTCONF_DRAFT = "18";
static final String MODULE_NAME_SUFFIX = "_module";
protected static final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
private static boolean newDraft;
protected BaseYangSwaggerGenerator() {
- mapper.registerModule(new JsonOrgModule());
- mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
+ this.mapper.registerModule(new JsonOrgModule());
+ this.mapper.configure(SerializationFeature.INDENT_OUTPUT, true);
}
/**
* Return list of modules converted to swagger compliant resource list.
*/
- public ResourceList getResourceListing(final UriInfo uriInfo, final SchemaContext schemaContext, final String context) {
+ public ResourceList getResourceListing(final UriInfo uriInfo, final SchemaContext schemaContext,
+ final String context) {
final ResourceList resourceList = createResourceList();
final String revisionString = SIMPLE_DATE_FORMAT.format(module.getRevision());
final Resource resource = new Resource();
LOG.debug("Working on [{},{}]...", module.getName(), revisionString);
- final ApiDeclaration doc = getApiDeclaration(module.getName(), revisionString, uriInfo, schemaContext, context);
+ final ApiDeclaration doc =
+ getApiDeclaration(module.getName(), revisionString, uriInfo, schemaContext, context);
if (doc != null) {
resource.setPath(generatePath(uriInfo, module.getName(), revisionString));
return uri.toASCIIString();
}
- public ApiDeclaration getApiDeclaration(final String moduleName, final String revision, final UriInfo uriInfo, final SchemaContext schemaContext, final String context) {
+ public ApiDeclaration getApiDeclaration(final String moduleName, final String revision, final UriInfo uriInfo,
+ final SchemaContext schemaContext, final String context) {
Date rev = null;
try {
- if (revision != null && !revision.equals("0000-00-00")) {
+ if ((revision != null) && !revision.equals("0000-00-00")) {
rev = SIMPLE_DATE_FORMAT.parse(revision);
}
} catch (final ParseException e) {
return getApiDeclaration(module, rev, uriInfo, context, schemaContext);
}
- public ApiDeclaration getApiDeclaration(final Module module, final Date revision, final UriInfo uriInfo, final String context, final SchemaContext schemaContext) {
+ public ApiDeclaration getApiDeclaration(final Module module, final Date revision, final UriInfo uriInfo,
+ final String context, final SchemaContext schemaContext) {
final String basePath = createBasePathFromUriInfo(uriInfo);
final ApiDeclaration doc = getSwaggerDocSpec(module, basePath, context, schemaContext);
if (port != -1) {
portPart = ":" + port;
}
- final String basePath = new StringBuilder(uriInfo.getBaseUri().getScheme()).append("://")
- .append(uriInfo.getBaseUri().getHost()).append(portPart).append("/").append(RESTCONF_CONTEXT_ROOT)
- .toString();
+ final String basePath =
+ new StringBuilder(uriInfo.getBaseUri().getScheme()).append("://").append(uriInfo.getBaseUri().getHost())
+ .append(portPart).append("/").append(RESTCONF_CONTEXT_ROOT).toString();
return basePath;
}
- public ApiDeclaration getSwaggerDocSpec(final Module m, final String basePath, final String context, final SchemaContext schemaContext) {
+ public ApiDeclaration getSwaggerDocSpec(final Module m, final String basePath, final String context,
+ final SchemaContext schemaContext) {
final ApiDeclaration doc = createApiDeclaration(basePath);
final List<Api> apis = new ArrayList<>();
String resourcePath;
/*
- * Only when the node's config statement is true, such apis as GET/PUT/POST/DELETE config
- * are added for this node.
+ * Only when the node's config statement is true, such apis as
+ * GET/PUT/POST/DELETE config are added for this node.
*/
- if (node.isConfiguration()) { // This node's config statement is true.
+ if (node.isConfiguration()) { // This node's config statement is
+ // true.
resourcePath = getDataStorePath("config", context);
/*
- * When there are two or more top container or list nodes whose config statement is true in module,
- * make sure that only one root post link is added for this module.
+ * When there are two or more top container or list nodes
+ * whose config statement is true in module, make sure that
+ * only one root post link is added for this module.
*/
if (!hasAddRootPostLink) {
LOG.debug("Has added root post link for module {}", m.getName());
JSONObject models = null;
try {
- models = jsonConverter.convertToJsonSchema(m, schemaContext);
+ models = this.jsonConverter.convertToJsonSchema(m, schemaContext);
doc.setModels(models);
if (LOG.isDebugEnabled()) {
- LOG.debug(mapper.writeValueAsString(doc));
+ LOG.debug(this.mapper.writeValueAsString(doc));
}
} catch (IOException | JSONException e) {
LOG.error("Exception occured in ModelGenerator", e);
}
private void addRootPostLink(final Module module, final DataNodeContainer node, final List<Parameter> pathParams,
- final String resourcePath, final String dataStore, final List<Api> apis) {
+ final String resourcePath, final String dataStore, final List<Api> apis) {
if (containsListOrContainer(module.getChildNodes())) {
final Api apiForRootPostUri = new Api();
apiForRootPostUri.setPath(resourcePath.concat(getContent(dataStore)));
return module + "(" + revision + ")";
}
- private void addApis(final DataSchemaNode node, final List<Api> apis, final String parentPath, final List<Parameter> parentPathParams,
- final SchemaContext schemaContext, final boolean addConfigApi, final String parentName, final String dataStore) {
+ private void addApis(final DataSchemaNode node, final List<Api> apis, final String parentPath,
+ final List<Parameter> parentPathParams, final SchemaContext schemaContext, final boolean addConfigApi,
+ final String parentName, final String dataStore) {
final Api api = new Api();
final List<Parameter> pathParams = new ArrayList<>(parentPathParams);
LOG.debug("Adding path: [{}]", resourcePath);
api.setPath(resourcePath.concat(getContent(dataStore)));
- Iterable<DataSchemaNode> childSchemaNodes = Collections.<DataSchemaNode>emptySet();
+ Iterable<DataSchemaNode> childSchemaNodes = Collections.<DataSchemaNode> emptySet();
if ((node instanceof ListSchemaNode) || (node instanceof ContainerSchemaNode)) {
final DataNodeContainer dataNodeContainer = (DataNodeContainer) node;
childSchemaNodes = dataNodeContainer.getChildNodes();
apis.add(api);
for (final DataSchemaNode childNode : childSchemaNodes) {
- if (childNode instanceof ListSchemaNode || childNode instanceof ContainerSchemaNode) {
+ if ((childNode instanceof ListSchemaNode) || (childNode instanceof ContainerSchemaNode)) {
// keep config and operation attributes separate.
if (childNode.isConfiguration() == addConfigApi) {
final String newParent = parentName + "/" + node.getQName().getLocalName();
- addApis(childNode, apis, resourcePath, pathParams, schemaContext, addConfigApi, newParent, dataStore);
+ addApis(childNode, apis, resourcePath, pathParams, schemaContext, addConfigApi, newParent,
+ dataStore);
}
}
}
return "";
}
}
+
private boolean containsListOrContainer(final Iterable<DataSchemaNode> nodes) {
for (final DataSchemaNode child : nodes) {
- if (child instanceof ListSchemaNode || child instanceof ContainerSchemaNode) {
+ if ((child instanceof ListSchemaNode) || (child instanceof ContainerSchemaNode)) {
return true;
}
}
return false;
}
- private List<Operation> operation(final DataSchemaNode node, final List<Parameter> pathParams, final boolean isConfig,
- final Iterable<DataSchemaNode> childSchemaNodes, final String parentName) {
+ private List<Operation> operation(final DataSchemaNode node, final List<Parameter> pathParams,
+ final boolean isConfig, final Iterable<DataSchemaNode> childSchemaNodes, final String parentName) {
final List<Operation> operations = new ArrayList<>();
final Get getBuilder = new Get(node, isConfig);
return operations;
}
- private List<Operation> operationPost(final String name, final String description, final DataNodeContainer dataNodeContainer,
- final List<Parameter> pathParams, final boolean isConfig, final String parentName) {
+ private List<Operation> operationPost(final String name, final String description,
+ final DataNodeContainer dataNodeContainer, final List<Parameter> pathParams, final boolean isConfig,
+ final String parentName) {
final List<Operation> operations = new ArrayList<>();
if (isConfig) {
final Post postBuilder = new Post(name, parentName + name, description, dataNodeContainer);
return operations;
}
- private String createPath(final DataSchemaNode schemaNode, final List<Parameter> pathParams, final SchemaContext schemaContext) {
+ private String createPath(final DataSchemaNode schemaNode, final List<Parameter> pathParams,
+ final SchemaContext schemaContext) {
final ArrayList<LeafSchemaNode> pathListParams = new ArrayList<>();
final StringBuilder path = new StringBuilder();
final String localName = resolvePathArgumentsName(schemaNode, schemaContext);
pathListParams.add(((LeafSchemaNode) dataChildByName));
final String pathParamIdentifier;
if (newDraft) {
- pathParamIdentifier = keyBuilder.append("{").append(listKey.getLocalName()).append("}")
- .toString();
+ pathParamIdentifier = keyBuilder.append("{").append(listKey.getLocalName()).append("}").toString();
} else {
pathParamIdentifier = "/{" + listKey.getLocalName() + "}";
}
return path.toString();
}
- protected void addRpcs(final RpcDefinition rpcDefn, final List<Api> apis, final String parentPath, final SchemaContext schemaContext) {
+ protected void addRpcs(final RpcDefinition rpcDefn, final List<Api> apis, final String parentPath,
+ final SchemaContext schemaContext) {
final Api rpc = new Api();
final String resourcePath = parentPath + "/" + resolvePathArgumentsName(rpcDefn, schemaContext);
rpc.setPath(resourcePath);
private static final String DATASTORES_REVISION = "-";
private static final String DATASTORES_LABEL = "Datastores";
- private static final String RESTCONF_DRAFT = "17";
+ private static final String RESTCONF_DRAFT = "18";
private DOMMountPointService mountService;
- private final Map<YangInstanceIdentifier, Long> instanceIdToLongId = new TreeMap<>(
- (o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
+ private final Map<YangInstanceIdentifier, Long> instanceIdToLongId =
+ new TreeMap<>((o1, o2) -> o1.toString().compareToIgnoreCase(o2.toString()));
private final Map<Long, YangInstanceIdentifier> longIdToInstanceId = new HashMap<>();
private final Object lock = new Object();
private static final AtomicReference<MountPointSwagger> selfRef = new AtomicReference<>();
private SchemaService globalSchema;
private static boolean newDraft;
+
public Map<String, Long> getInstanceIdentifiers() {
final Map<String, Long> urlToId = new HashMap<>();
- synchronized (lock) {
- final SchemaContext context = globalSchema.getGlobalContext();
- for (final Entry<YangInstanceIdentifier, Long> entry : instanceIdToLongId.entrySet()) {
+ synchronized (this.lock) {
+ final SchemaContext context = this.globalSchema.getGlobalContext();
+ for (final Entry<YangInstanceIdentifier, Long> entry : this.instanceIdToLongId.entrySet()) {
final String modName = findModuleName(entry.getKey(), context);
- urlToId.put(generateUrlPrefixFromInstanceID(entry.getKey(), modName),
- entry.getValue());
+ urlToId.put(generateUrlPrefixFromInstanceID(entry.getKey(), modName), entry.getValue());
}
}
return urlToId;
final StringBuilder builder = new StringBuilder();
builder.append("/");
if (moduleName != null) {
- builder.append(moduleName)
- .append(':');
+ builder.append(moduleName).append(':');
}
for (final PathArgument arg : key.getPathArguments()) {
final String name = arg.getNodeType().getLocalName();
final NodeIdentifierWithPredicates nodeId = (NodeIdentifierWithPredicates) arg;
for (final Entry<QName, Object> entry : nodeId.getKeyValues().entrySet()) {
if (newDraft) {
- builder.deleteCharAt(builder.length() - 1)
- .append("=")
- .append(entry.getValue())
- .append('/');
+ builder.deleteCharAt(builder.length() - 1).append("=").append(entry.getValue()).append('/');
} else {
- builder.append(entry.getValue())
- .append('/');
+ builder.append(entry.getValue()).append('/');
}
}
} else {
- builder.append(name)
- .append('/');
+ builder.append(name).append('/');
}
}
return builder.toString();
}
private String getYangMountUrl(final YangInstanceIdentifier key) {
- final String modName = findModuleName(key, globalSchema.getGlobalContext());
+ final String modName = findModuleName(key, this.globalSchema.getGlobalContext());
return generateUrlPrefixFromInstanceID(key, modName) + "yang-ext:mount";
}
private YangInstanceIdentifier getInstanceId(final Long id) {
final YangInstanceIdentifier instanceId;
- synchronized (lock) {
- instanceId = longIdToInstanceId.get(id);
+ synchronized (this.lock) {
+ instanceId = this.longIdToInstanceId.get(id);
}
return instanceId;
}
return null;
}
- final Optional<DOMMountPoint> mountPoint = mountService.getMountPoint(id);
+ final Optional<DOMMountPoint> mountPoint = this.mountService.getMountPoint(id);
if (!mountPoint.isPresent()) {
return null;
}
return context;
}
- public ApiDeclaration getMountPointApi(final UriInfo uriInfo, final Long id, final String module, final String revision) {
+ public ApiDeclaration getMountPointApi(final UriInfo uriInfo, final Long id, final String module,
+ final String revision) {
final YangInstanceIdentifier iid = getInstanceId(id);
final SchemaContext context = getSchemaContext(iid);
final String urlPrefix = getYangMountUrl(iid);
private ApiDeclaration generateDataStoreApiDoc(final UriInfo uriInfo, final String context) {
final List<Api> apis = new LinkedList<>();
- apis.add(createGetApi("config",
- "Queries the config (startup) datastore on the mounted hosted.", context));
- apis.add(createGetApi("operational",
- "Queries the operational (running) datastore on the mounted hosted.", context));
- apis.add(createGetApi("operations",
- "Queries the available operations (RPC calls) on the mounted hosted.", context));
+ apis.add(createGetApi("config", "Queries the config (startup) datastore on the mounted hosted.", context));
+ apis.add(createGetApi("operational", "Queries the operational (running) datastore on the mounted hosted.",
+ context));
+ apis.add(createGetApi("operations", "Queries the available operations (RPC calls) on the mounted hosted.",
+ context));
final ApiDeclaration declaration = super.createApiDeclaration(createBasePathFromUriInfo(uriInfo));
declaration.setApis(apis);
@Override
public void onMountPointCreated(final YangInstanceIdentifier path) {
- synchronized (lock) {
- final Long idLong = idKey.incrementAndGet();
- instanceIdToLongId.put(path, idLong);
- longIdToInstanceId.put(idLong, path);
+ synchronized (this.lock) {
+ final Long idLong = this.idKey.incrementAndGet();
+ this.instanceIdToLongId.put(path, idLong);
+ this.longIdToInstanceId.put(idLong, path);
}
}
@Override
public void onMountPointRemoved(final YangInstanceIdentifier path) {
- synchronized (lock) {
- final Long id = instanceIdToLongId.remove(path);
- longIdToInstanceId.remove(id);
+ synchronized (this.lock) {
+ final Long id = this.instanceIdToLongId.remove(path);
+ this.longIdToInstanceId.remove(id);
}
}
return swagger;
}
- public static MountPointSwagger getInstanceDraft17() {
+ public static MountPointSwagger getInstanceDraft18() {
MountPointSwagger swagger = selfRef.get();
if (swagger == null) {
selfRef.compareAndSet(null, new MountPointSwagger());
<script src='../../explorer/lib/odl/swagger.js' type='text/javascript'></script>\r
\r
<script type="text/javascript">\r
- \r
- //reloads the swagger UI documentation for the specified mount.\r
- var loadMount = function(mountIndex, mountPath) {\r
- $("#message").empty();\r
- $("#message").append( "<p>Loading...</p>" );\r
- loadSwagger("/apidoc/17/apis/mounts/" + mountIndex,\r
- "swagger-ui-container");\r
- $("#message").empty();\r
- $("#message").append( "<h2><b>Showing mount points for " + mountPath + "</b></h2>");\r
- }\r
-\r
- //clears the swagger UI and adds text prompting use to select a mount point.\r
+\r
+ //reloads the swagger UI documentation for the specified mount.\r
+ var loadMount = function(mountIndex, mountPath) {\r
+ $("#message").empty();\r
+ $("#message").append( "<p>Loading...</p>" );\r
+ loadSwagger("/apidoc/18/apis/mounts/" + mountIndex,\r
+ "swagger-ui-container");\r
+ $("#message").empty();\r
+ $("#message").append( "<h2><b>Showing mount points for " + mountPath + "</b></h2>");\r
+ }\r
+\r
+ //clears the swagger UI and adds text prompting use to select a mount point.\r
var selectAMount = function(string) {\r
$("#swagger-ui-container").empty();\r
$("#message").empty();\r
$("#message").append("<p>Select a mount point.</p>");\r
}\r
- \r
- //loads the root swagger documenation (which comes from RestConf)\r
- var loadRootSwagger = function() {\r
- $("#message").empty();\r
- loadSwagger("/apidoc/17/apis", "swagger-ui-container");\r
- }\r
\r
- //main method to initialize the mount list / swagger docs / tabs on page load\r
- $(function() {\r
- $("#tabs").tabs();\r
+ //loads the root swagger documenation (which comes from RestConf)\r
+ var loadRootSwagger = function() {\r
+ $("#message").empty();\r
+ loadSwagger("/apidoc/18/apis", "swagger-ui-container");\r
+ }\r
+\r
+ //main method to initialize the mount list / swagger docs / tabs on page load\r
+ $(function() {\r
+ $("#tabs").tabs();\r
\r
- loadMountList($("#mountlist"));\r
+ loadMountList($("#mountlist"));\r
\r
- loadRootSwagger();\r
- });\r
+ loadRootSwagger();\r
+ });\r
</script>\r
</head>\r
\r
dom.empty();
dom.append( "<p>Loading. Please wait...</p>" );
$.ajax( {
- url: "/apidoc/17/apis/mounts",
+ url: "/apidoc/18/apis/mounts",
datatype: 'jsonp',
success: function( strData ){
var myData = strData;
var list = $( "<table></table>" );
for( var key in myData )
{
- list.append( "<tr><td><a href=\"#\" onclick=\"loadMount(" +
- myData[key].id + ", '" + myData[key].instance + "')\">" +
- myData[key].instance + "</a></td></tr>");
+ list.append( "<tr><td><a href=\"#\" onclick=\"loadMount(" +
+ myData[key].id + ", '" + myData[key].instance + "')\">" +
+ myData[key].instance + "</a></td></tr>");
}
dom.empty();
dom.append( list );
<servlet-mapping>
<servlet-name>JAXRSApiDoc</servlet-name>
- <url-pattern>/17/apis/*</url-pattern>
+ <url-pattern>/18/apis/*</url-pattern>
</servlet-mapping>
<filter>
</filter-mapping>
<filter-mapping>
<filter-name>cross-origin-api-doc</filter-name>
- <url-pattern>/17/apis/*</url-pattern>
+ <url-pattern>/18/apis/*</url-pattern>
</filter-mapping>
<security-constraint>