summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/rest/ProxyRoa.java289
-rw-r--r--service/src/main/resources/swagger.json195
2 files changed, 345 insertions, 139 deletions
diff --git a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/rest/ProxyRoa.java b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/rest/ProxyRoa.java
index 1e15740..e69b5b7 100644
--- a/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/rest/ProxyRoa.java
+++ b/service/src/main/java/org/onap/vfc/nfvo/multivimproxy/service/rest/ProxyRoa.java
@@ -16,6 +16,7 @@
package org.onap.vfc.nfvo.multivimproxy.service.rest;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -31,165 +32,175 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
-import org.onap.vfc.nfvo.multivimproxy.common.util.RestfulUtil;
-import org.onap.vfc.nfvo.multivimproxy.common.util.restclient.RestfulParametes;
-import org.onap.vfc.nfvo.multivimproxy.common.util.restclient.RestfulResponse;
+import org.apache.commons.io.IOUtils;
+import org.onap.vfc.nfvo.multivimproxy.common.conf.Config;
import org.onap.vfc.nfvo.multivimproxy.common.constant.Constant;
import org.onap.vfc.nfvo.multivimproxy.common.constant.ParamConstant;
import org.onap.vfc.nfvo.multivimproxy.common.constant.UrlConstant;
-import org.onap.vfc.nfvo.multivimproxy.common.conf.Config;
+import org.onap.vfc.nfvo.multivimproxy.common.util.RestfulUtil;
import org.onap.vfc.nfvo.multivimproxy.common.util.request.RequestUtil;
+import org.onap.vfc.nfvo.multivimproxy.common.util.restclient.RestfulParametes;
+import org.onap.vfc.nfvo.multivimproxy.common.util.restclient.RestfulResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
-
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class ProxyRoa {
- private static final Logger LOGGER = LoggerFactory.getLogger(ProxyRoa.class);
- private static final String vimId = Config.getCloudRegionId() + "_" + Config.getCloudRegionId();
-
- @POST
- @Path("/v3/auth/tokens")
- public String createTokens(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
- JSONObject object = RequestUtil.getJsonRequestBody(context);
- if (null == object) {
- LOGGER.error("function=createTokens; msg=add error, because createTokens is null.");
- String resultStr = "Login params insufficient";
- rsp.setStatus(Constant.HTTP_BAD_REQUEST);
+ private static final Logger LOGGER = LoggerFactory.getLogger(ProxyRoa.class);
+
+ private static final String vimId = Config.getCloudRegionId() + "_" + Config.getCloudRegionId();
+
+ /**
+ * API doc.
+ *
+ * @return
+ * @throws IOException
+ */
+ @GET
+ @Path("/api/multivimproxy/v1/swagger.json")
+ public String apidoc() throws IOException {
+ ClassLoader classLoader = getClass().getClassLoader();
+ return IOUtils.toString(classLoader.getResourceAsStream("swagger.json"));
+ }
+
+ @POST
+ @Path("/v3/auth/tokens")
+ public String createTokens(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
+ JSONObject object = RequestUtil.getJsonRequestBody(context);
+ if(null == object) {
+ LOGGER.error("function=createTokens; msg=add error, because createTokens is null.");
+ String resultStr = "Login params insufficient";
+ rsp.setStatus(Constant.HTTP_BAD_REQUEST);
return resultStr;
- }
-
- LOGGER.info("IdentityRoa::createTokens:{}", object.toString());
-
- // transfer to MultiVim
- RestfulParametes restfulParametes = new RestfulParametes();
- Map<String, String> headerMap = new HashMap<>(3);
- headerMap.put("Content-Type", "application/json");
- restfulParametes.setHeaderMap(headerMap);
- restfulParametes.setRawData(object.toString());
- String identityUrl = UrlConstant.MULTI_VIM_PREFIX + vimId + "/v3/auth/tokens";
-
- RestfulResponse rest = RestfulUtil.getResponse(identityUrl, restfulParametes, null, ParamConstant.PARAM_POST);
-
- String result = rest.getResponseContent();
- if (null != result) {
- JSONObject ret = JSONObject.fromObject(result);
- JSONArray catalog = ret.getJSONArray("catalog");
-
- for (int i = 0; i < catalog.size(); i++) {
- JSONArray endpoints = catalog.getJSONObject(i).getJSONArray("endpoints");
- for (int j = 0; j < endpoints.size(); j++) {
- String newUrl = "";
- JSONObject endpoint = endpoints.getJSONObject(j);
- String url = endpoint.getString("url");
- for (int k = 6; k < url.split("/").length; k++) {
- newUrl += "/" + url.split("/")[k];
- }
- newUrl += Config.getOpenstackPrefix();
- endpoint.replace("url", newUrl);
- }
- }
-
- rsp.setStatus(rest.getStatus());
-
- } else {
- LOGGER.error("function=createTokens; msg=add error, because multivim return null.");
- }
-
- return result;
- }
-
- @POST
- @Path("{var:.*}")
- public String proxyPost(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
- JSONObject object = RequestUtil.getJsonRequestBody(context);
- if (null == object) {
- LOGGER.error("function=proxyPost; msg=Post error, because proxyPost is null.");
- String resultStr = "POST params insufficient";
- rsp.setStatus(Constant.HTTP_BAD_REQUEST);
+ }
+
+ LOGGER.info("IdentityRoa::createTokens:{}", object.toString());
+
+ // transfer to MultiVim
+ RestfulParametes restfulParametes = new RestfulParametes();
+ Map<String, String> headerMap = new HashMap<>(3);
+ headerMap.put("Content-Type", "application/json");
+ restfulParametes.setHeaderMap(headerMap);
+ restfulParametes.setRawData(object.toString());
+ String identityUrl = UrlConstant.MULTI_VIM_PREFIX + vimId + "/v3/auth/tokens";
+
+ RestfulResponse rest = RestfulUtil.getResponse(identityUrl, restfulParametes, null, ParamConstant.PARAM_POST);
+
+ String result = rest.getResponseContent();
+ if(null != result) {
+ JSONObject ret = JSONObject.fromObject(result);
+ JSONArray catalog = ret.getJSONArray("catalog");
+
+ for(int i = 0; i < catalog.size(); i++) {
+ JSONArray endpoints = catalog.getJSONObject(i).getJSONArray("endpoints");
+ for(int j = 0; j < endpoints.size(); j++) {
+ String newUrl = "";
+ JSONObject endpoint = endpoints.getJSONObject(j);
+ String url = endpoint.getString("url");
+ for(int k = 6; k < url.split("/").length; k++) {
+ newUrl += "/" + url.split("/")[k];
+ }
+ newUrl += Config.getOpenstackPrefix();
+ endpoint.replace("url", newUrl);
+ }
+ }
+
+ rsp.setStatus(rest.getStatus());
+
+ } else {
+ LOGGER.error("function=createTokens; msg=add error, because multivim return null.");
+ }
+
+ return result;
+ }
+
+ @POST
+ @Path("{var:.*}")
+ public String proxyPost(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
+ JSONObject object = RequestUtil.getJsonRequestBody(context);
+ if(null == object) {
+ LOGGER.error("function=proxyPost; msg=Post error, because proxyPost is null.");
+ String resultStr = "POST params insufficient";
+ rsp.setStatus(Constant.HTTP_BAD_REQUEST);
return resultStr;
- }
- // transfer to MultiVim
- RestfulParametes restfulParametes = new RestfulParametes();
- Map<String, String> headerMap = new HashMap<>(3);
- headerMap.put("Content-Type", "application/json");
- restfulParametes.setHeaderMap(headerMap);
- restfulParametes.setRawData(object.toString());
- String Url = UrlConstant.MULTI_VIM_PREFIX + vimId + context.getRequestURI();
-
- RestfulResponse rest = RestfulUtil.getResponse(Url, restfulParametes, null, ParamConstant.PARAM_POST);
- String result = rest.getResponseContent();
- rsp.setStatus(rest.getStatus());
- return result;
- }
-
- @GET
- @Path("{var:.*}")
- public String porxyGet(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
+ }
+ // transfer to MultiVim
+ RestfulParametes restfulParametes = new RestfulParametes();
+ Map<String, String> headerMap = new HashMap<>(3);
+ headerMap.put("Content-Type", "application/json");
+ restfulParametes.setHeaderMap(headerMap);
+ restfulParametes.setRawData(object.toString());
+ String Url = UrlConstant.MULTI_VIM_PREFIX + vimId + context.getRequestURI();
+
+ RestfulResponse rest = RestfulUtil.getResponse(Url, restfulParametes, null, ParamConstant.PARAM_POST);
+ String result = rest.getResponseContent();
+ rsp.setStatus(rest.getStatus());
+ return result;
+ }
+
+ @GET
+ @Path("{var:.*}")
+ public String porxyGet(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
+
+ // transfer to MultiVim
+ RestfulParametes restfulParametes = new RestfulParametes();
+ Map<String, String> headerMap = new HashMap<>(3);
+ headerMap.put("Content-Type", "application/json");
+ restfulParametes.setHeaderMap(headerMap);
+ String Url = UrlConstant.MULTI_VIM_PREFIX + vimId + context.getRequestURI();
+
+ RestfulResponse rest = RestfulUtil.getResponse(Url, restfulParametes, null, ParamConstant.PARAM_GET);
+ String result = rest.getResponseContent();
+ rsp.setStatus(rest.getStatus());
+ return result;
+ }
+
+ @PUT
+ @Path("{var:.*}")
+ public String porxyPut(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
JSONObject object = RequestUtil.getJsonRequestBody(context);
-
- // transfer to MultiVim
- RestfulParametes restfulParametes = new RestfulParametes();
- Map<String, String> headerMap = new HashMap<>(3);
- headerMap.put("Content-Type", "application/json");
- restfulParametes.setHeaderMap(headerMap);
- restfulParametes.setRawData(object.toString());
- String Url = UrlConstant.MULTI_VIM_PREFIX + vimId + context.getRequestURI();
-
- RestfulResponse rest = RestfulUtil.getResponse(Url, restfulParametes, null, ParamConstant.PARAM_GET);
- String result = rest.getResponseContent();
- rsp.setStatus(rest.getStatus());
- return result;
- }
-
- @PUT
- @Path("{var:.*}")
- public String porxyPut(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
- JSONObject object = RequestUtil.getJsonRequestBody(context);
- if (null == object) {
- LOGGER.error("function=proxyPost; msg=PUT error, because porxyPut is null.");
- String resultStr = "update params insufficient";
- rsp.setStatus(Constant.HTTP_BAD_REQUEST);
+ if(null == object) {
+ LOGGER.error("function=proxyPost; msg=PUT error, because porxyPut is null.");
+ String resultStr = "update params insufficient";
+ rsp.setStatus(Constant.HTTP_BAD_REQUEST);
return resultStr;
- }
- // transfer to MultiVim
- RestfulParametes restfulParametes = new RestfulParametes();
- Map<String, String> headerMap = new HashMap<>(3);
- headerMap.put("Content-Type", "application/json");
- restfulParametes.setHeaderMap(headerMap);
- restfulParametes.setRawData(object.toString());
- String Url = UrlConstant.MULTI_VIM_PREFIX + vimId + context.getRequestURI();
- RestfulResponse rest = RestfulUtil.getResponse(Url, restfulParametes, null, RestfulUtil.TYPE_PUT);
- String result = rest.getResponseContent();
- rsp.setStatus(rest.getStatus());
- return result;
- }
-
- @DELETE
- @Path("{var:.*}")
- public String porxyDelete(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
- JSONObject object = RequestUtil.getJsonRequestBody(context);
-
- // transfer to MultiVim
- RestfulParametes restfulParametes = new RestfulParametes();
- Map<String, String> headerMap = new HashMap<>(3);
- headerMap.put("Content-Type", "application/json");
- restfulParametes.setHeaderMap(headerMap);
- restfulParametes.setRawData(object.toString());
- String Url = UrlConstant.MULTI_VIM_PREFIX + vimId + context.getRequestURI();
-
- RestfulResponse rest = RestfulUtil.getResponse(Url, restfulParametes, null, RestfulUtil.TYPE_DEL);
- String result = rest.getResponseContent();
- rsp.setStatus(rest.getStatus());
- return result;
- }
+ }
+ // transfer to MultiVim
+ RestfulParametes restfulParametes = new RestfulParametes();
+ Map<String, String> headerMap = new HashMap<>(3);
+ headerMap.put("Content-Type", "application/json");
+ restfulParametes.setHeaderMap(headerMap);
+ restfulParametes.setRawData(object.toString());
+ String Url = UrlConstant.MULTI_VIM_PREFIX + vimId + context.getRequestURI();
+ RestfulResponse rest = RestfulUtil.getResponse(Url, restfulParametes, null, RestfulUtil.TYPE_PUT);
+ String result = rest.getResponseContent();
+ rsp.setStatus(rest.getStatus());
+ return result;
+ }
+
+ @DELETE
+ @Path("{var:.*}")
+ public String porxyDelete(@Context HttpServletRequest context, @Context HttpServletResponse rsp) {
+
+ // transfer to MultiVim
+ RestfulParametes restfulParametes = new RestfulParametes();
+ Map<String, String> headerMap = new HashMap<>(3);
+ headerMap.put("Content-Type", "application/json");
+ restfulParametes.setHeaderMap(headerMap);
+ String Url = UrlConstant.MULTI_VIM_PREFIX + vimId + context.getRequestURI();
+
+ RestfulResponse rest = RestfulUtil.getResponse(Url, restfulParametes, null, RestfulUtil.TYPE_DEL);
+ String result = rest.getResponseContent();
+ rsp.setStatus(rest.getStatus());
+ return result;
+ }
}
diff --git a/service/src/main/resources/swagger.json b/service/src/main/resources/swagger.json
new file mode 100644
index 0000000..9a1bf31
--- /dev/null
+++ b/service/src/main/resources/swagger.json
@@ -0,0 +1,195 @@
+{
+ "swagger": "2.0",
+ "info": {
+ "title": "Multivimproxy API",
+ "description": "Multivimproxy API",
+ "version": "1.0.0"
+ },
+ "tags": [
+ {
+ "name": "Multivimproxy services"
+ }
+ ],
+ "basePath": "/api/multivimproxy/v1",
+ "paths": {
+ "/v3/auth/tokens": {
+ "post": {
+ "summary": "Password authentication",
+ "description": "Password authentication",
+ "consumes": [
+ "application/json"
+ ],
+ "produces": [
+ "application/json"
+ ],
+ "parameters": [
+ {
+ "name": "onap",
+ "in": "body",
+ "description": "Authentication info",
+ "required": true,
+ "schema": {
+ "$ref": "#/definitions/AuthInfo"
+ }
+ }
+ ],
+ "responses": {
+ "201": {
+ "description": "Resource was created and is ready to use.",
+ "schema": {
+ "$ref": "#/definitions/tokens"
+ }
+ },
+ "401": {
+ "description": "User must authenticate before making a request."
+ },
+ "404": {
+ "description": "The requested resource could not be found."
+ },
+ "500": {
+ "description": "Failed to process the request",
+ "schema": {
+ "$ref": "#/definitions/Error"
+ }
+ }
+ }
+ }
+ }
+ },
+ "definitions": {
+ "AuthInfo": {
+ "type": "object",
+ "description": "Authentication info.",
+ "required": [
+ "auth"
+ ],
+ "properties": {
+ "auth": {
+ "$ref": "#/definitions/auth"
+ }
+ }
+ },
+ "auth": {
+ "type": "object",
+ "description": "Authentication info.",
+ "required": [
+ "identity"
+ ],
+ "properties": {
+ "identity": {
+ "$ref": "#/definitions/identity"
+ }
+ }
+ },
+ "identity": {
+ "type": "object",
+ "description": "Authentication info.",
+ "required": [
+ "methods",
+ "password"
+ ],
+ "properties": {
+ "methods": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "password": {
+ "$ref": "#/definitions/user"
+ }
+ }
+ },
+ "user": {
+ "type": "object",
+ "description": "Authentication info.",
+ "required": [
+ "name",
+ "domain",
+ "password"
+ ],
+ "properties": {
+ "name": {
+ "type": "string"
+ },
+ "domain": {
+ "$ref": "#/definitions/domain"
+ },
+ "password": {
+ "type": "string"
+ }
+ }
+ },
+ "domain": {
+ "type": "object",
+ "description": "Authentication info.",
+ "required": [
+ "name"
+ ],
+ "properties": {
+ "name": {
+ "type": "string"
+ }
+ }
+ },
+ "tokens": {
+ "type": "object",
+ "description": "Tokens info.",
+ "required": [
+ "token"
+ ],
+ "properties": {
+ "auth": {
+ "$ref": "#/definitions/token"
+ }
+ }
+ },
+ "token": {
+ "type": "object",
+ "description": "Tokens info.",
+ "required": [
+ "methods",
+ "user"
+ ],
+ "properties": {
+ "methods": {
+ "type": "array",
+ "items": {
+ "type": "string"
+ }
+ },
+ "user": {
+ "$ref": "#/definitions/users"
+ }
+ }
+ },
+ "users": {
+ "type": "object",
+ "description": "Tokens info.",
+ "required": [
+ "id",
+ "name"
+ ],
+ "properties": {
+ "id": {
+ "type": "string"
+ },
+ "name": {
+ "type": "string"
+ }
+ }
+ },
+ "Error": {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "format": "int32"
+ },
+ "message": {
+ "type": "string"
+ }
+ }
+ }
+ }
+} \ No newline at end of file