From 2e5b5e2b815b3dcb25e1909f1caa3f8ae3ae239d Mon Sep 17 00:00:00 2001 From: Boyuan Yan Date: Tue, 16 Jul 2019 15:06:39 -0700 Subject: [PATCH] enable service creation/deletion/query. --- .../tapi2.1-javaServer/README.md | 45 +++++++- .../swagger/api/impl/DataApiServiceImpl.java | 109 +++++++++++------- 2 files changed, 111 insertions(+), 43 deletions(-) diff --git a/emulator-tapi-2.1/tapi2.1-javaServer/README.md b/emulator-tapi-2.1/tapi2.1-javaServer/README.md index b02ee0f..339e4c1 100644 --- a/emulator-tapi-2.1/tapi2.1-javaServer/README.md +++ b/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: @@ -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: @@ -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")` \ No newline at end of file +are replaced by `@JsonProperty("tapi-photonic-media:media-channel-service-interface-point-spec")` diff --git a/emulator-tapi-2.1/tapi2.1-javaServer/src/main/java/io/swagger/api/impl/DataApiServiceImpl.java b/emulator-tapi-2.1/tapi2.1-javaServer/src/main/java/io/swagger/api/impl/DataApiServiceImpl.java index f8aec36..321a7ee 100644 --- a/emulator-tapi-2.1/tapi2.1-javaServer/src/main/java/io/swagger/api/impl/DataApiServiceImpl.java +++ b/emulator-tapi-2.1/tapi2.1-javaServer/src/main/java/io/swagger/api/impl/DataApiServiceImpl.java @@ -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; @@ -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 tccs = - tapiConnectivityContextConnectivityContextBodyParam.getConnectivityService(); - List tcc = - tapiConnectivityContextConnectivityContextBodyParam.getConnection(); - // Merge List - if (tccs != null && !tccs.isEmpty()) { - if (cc.getConnectivityService() == null || cc.getConnectivityService().isEmpty()) { - cc.setConnectivityService(tccs); - } else { - Set 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 tccs = + tapiConnectivityContextConnectivityContextBodyParam.getConnectivityService(); + List tcc = + tapiConnectivityContextConnectivityContextBodyParam.getConnection(); + + // check if List contains conflicting entity. + boolean conflict = false; + if (tccs != null && !tccs.isEmpty()) { + if (cc.getConnectivityService() == null) { + cc.setConnectivityService(Lists.newArrayList()); + } else { + Set 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 - if (tcc != null && !tcc.isEmpty()) { - if (cc.getConnection() == null || cc.getConnection().isEmpty()) { - cc.setConnection(tcc); + // check if List contains conflicting entity. + if (tcc != null && !tcc.isEmpty()) { + if (cc.getConnection() == null) { + cc.setConnection(Lists.newArrayList()); + } else { + Set 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 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