Skip to content

Commit

Permalink
enable service creation/deletion/query.
Browse files Browse the repository at this point in the history
  • Loading branch information
BoyuanYan committed Jul 16, 2019
1 parent 57c31ab commit 2e5b5e2
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 43 deletions.
45 changes: 43 additions & 2 deletions emulator-tapi-2.1/tapi2.1-javaServer/README.md
@@ -1,10 +1,12 @@
# Swagger Jersey generated server

## Overview
## 1. Overview
This server was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the
[OpenAPI-Spec](https://github.com/swagger-api/swagger-core/wiki) from a remote server, you can easily generate a server stub. This
is an example of building a swagger-enabled JAX-RS server.

You can also visit https://github.com/BoyuanYan/tapi2.1-javaServer to find the latest version of this project.

This example uses the [JAX-RS](https://jax-rs-spec.java.net/) framework.

To run the server, please execute the following:
Expand All @@ -22,6 +24,45 @@ http://localhost:1234/swagger.json
Note that if you have configured the `host` to be something other than localhost, the calls through
swagger-ui will be directed to that host and not localhost!

## 2. Debug

For other extension based on this project, the command `mvnDebug clean package jetty:run` is used to run it in debugging
mode. The default debugging port is 8000.

## 3. RestClient Test

Firstly, you need a restClient tool. If you use Chrome browser, you can use its applications to simulate a restful client,
for example, YARC (Yet Another REST Client).

#### 3.1 service creation test

The HTTP request of service creation test contains
* URL: http://localhost:1234/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/
* Method: POST
* Headers:
* Accept: application/json
* Content-Type: application/json
* Payload:
```json
{"tapi-connectivity:connectivity-service":[{"uuid":"f6447f09-64b9-46b7-b386-47dc71a2876d","service-layer":"PHOTONIC_MEDIA",
"service-type":"POINT_TO_POINT_CONNECTIVITY","end-point":[{"local-id":"22112233-5535-6677-8899-100000035182",
"layer-protocol-name":"PHOTONIC_MEDIA","layer-protocol-qualifier":"tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC",
"service-interface-point":{"service-interface-point-uuid":"22112233-5535-6677-8899-100000035182"}},
{"local-id":"22112233-5535-6677-8899-100000035178","layer-protocol-name":"PHOTONIC_MEDIA",
"layer-protocol-qualifier":"tapi-photonic-media:PHOTONIC_LAYER_QUALIFIER_NMC","service-interface-point":
{"service-interface-point-uuid":"22112233-5535-6677-8899-100000035178"}}]}]}
```
The response is:`201 - Created`


## 4. Service-related interface

| Service operation | URL | HTTP Request |
| ---- | ---- | ---- |
| Service Creation | http://localhost:1234/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/ | POST |
| Service Deletion | http://localhost:1234/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/ | DELETE |
| Service Query | http://localhost:1234/restconf/data/tapi-common:context/tapi-connectivity:connectivity-context/ | GET |

## Notifications
The codes is generated automatically as listed:

Expand Down Expand Up @@ -85,4 +126,4 @@ The codes is generated automatically as listed:

3. The response json should also contains the namespace prefix as 2. mentioned.
For device/port discovery, all Java annotations `@JsonProperty("media-channel-service-interface-point-spec")`
are replaced by `@JsonProperty("tapi-photonic-media:media-channel-service-interface-point-spec")`
are replaced by `@JsonProperty("tapi-photonic-media:media-channel-service-interface-point-spec")`
@@ -1,5 +1,6 @@
package io.swagger.api.impl;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.swagger.api.ApiResponseMessage;
import io.swagger.api.DataApiService;
Expand Down Expand Up @@ -1453,57 +1454,83 @@ public Response dataContextConnectivityContextGet(SecurityContext securityContex

@Override
public Response dataContextConnectivityContextPost(TapiConnectivityConnectivityContext tapiConnectivityContextConnectivityContextBodyParam, SecurityContext securityContext) throws NotFoundException {
log.info("method dataContextConnectivityContextPost is called.");
try {
/** Merge into tapi-common:context **/
TapiConnectivityConnectivityContext cc = context.getConnectivityContext();
if (cc == null) {
context.setConnectivityContext(tapiConnectivityContextConnectivityContextBodyParam);
} else {
List<TapiConnectivityConnectivityService> tccs =
tapiConnectivityContextConnectivityContextBodyParam.getConnectivityService();
List<TapiConnectivityConnection> tcc =
tapiConnectivityContextConnectivityContextBodyParam.getConnection();
// Merge List<TapiConnectivityConnectivityService>
if (tccs != null && !tccs.isEmpty()) {
if (cc.getConnectivityService() == null || cc.getConnectivityService().isEmpty()) {
cc.setConnectivityService(tccs);
} else {
Set<String> uuids = Sets.newHashSet();
cc.getConnectivityService().stream().forEach(action -> uuids.add(action.getUuid()));
tccs.stream().forEach(action -> {
if (!uuids.contains(action.getUuid())) {
cc.getConnectivityService().add(action);
} else {
log.warn("insert conflict of tapi-connectivity:connectivity-service with uuid {}.",
action.getUuid());
synchronized (this) {
log.info("method dataContextConnectivityContextPost is called.");
try {
/** Merge into tapi-common:context **/
TapiConnectivityConnectivityContext cc = context.getConnectivityContext();
if (cc == null) {
context.setConnectivityContext(tapiConnectivityContextConnectivityContextBodyParam);
} else {
List<TapiConnectivityConnectivityService> tccs =
tapiConnectivityContextConnectivityContextBodyParam.getConnectivityService();
List<TapiConnectivityConnection> tcc =
tapiConnectivityContextConnectivityContextBodyParam.getConnection();

// check if List<TapiConnectivityConnectivityService> contains conflicting entity.
boolean conflict = false;
if (tccs != null && !tccs.isEmpty()) {
if (cc.getConnectivityService() == null) {
cc.setConnectivityService(Lists.newArrayList());
} else {
Set<String> uuids = Sets.newHashSet();
cc.getConnectivityService().stream().forEach(action -> uuids.add(action.getUuid()));
for (TapiConnectivityConnectivityService tmp : tccs) {
if (uuids.contains(tmp.getUuid())) {
log.warn("insert conflict of tapi-connectivity:connectivity-service with uuid {}.",
tmp.getUuid());
conflict = true;
break;
}
}
});
if (conflict) {
return Response.status(Response.Status.CONFLICT).build();
}
}
} else {
log.warn("The list of TapiConnectivityConnectivityService shouldn't be null or empty");
return Response.notAcceptable(null).build();
}
}
// Merge List<TapiConnectivityConnection>
if (tcc != null && !tcc.isEmpty()) {
if (cc.getConnection() == null || cc.getConnection().isEmpty()) {
cc.setConnection(tcc);
// check if List<TapiConnectivityConnection> contains conflicting entity.
if (tcc != null && !tcc.isEmpty()) {
if (cc.getConnection() == null) {
cc.setConnection(Lists.newArrayList());
} else {
Set<String> uuids = Sets.newHashSet();
cc.getConnection().stream().forEach(action -> uuids.add(action.getUuid()));
for (TapiConnectivityConnection tmp : tcc) {
if (uuids.contains(tmp.getUuid())) {
log.warn("insert conflict of tapi-connectivity:connection with uuid {}.",
tmp.getUuid());
conflict = true;
break;
}
}
if (conflict) {
return Response.status(Response.Status.CONFLICT).build();
}
}
} else {
Set<String> uuids = Sets.newHashSet();
cc.getConnection().stream().forEach(action -> uuids.add(action.getUuid()));
log.warn("The list of TapiConnectivityConnection shouldn't be null or empty");
// return Response.notAcceptable(null).build();
}
// Merge two lists.
tccs.stream().forEach(action -> {
cc.getConnectivityService().add(action);
});
if (tcc != null) {
tcc.stream().forEach(action -> {
if (!uuids.contains(action.getUuid())) {
cc.getConnection().add(action);
} else {
log.warn("insert conflict of tapi-connectivity:connection with uuid {}.",
action.getUuid());
}
cc.getConnection().add(action);
});
}
}
} catch (Exception e) {
e.printStackTrace();
return Response.serverError().build();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return Response.created(null).build();
}

}

@Override
Expand Down

0 comments on commit 2e5b5e2

Please sign in to comment.