diff options
11 files changed, 503 insertions, 424 deletions
diff --git a/deployment/pom.xml b/deployment/pom.xml index 372f610..f160a42 100644 --- a/deployment/pom.xml +++ b/deployment/pom.xml @@ -16,13 +16,13 @@ --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> - <groupId>org.openo.vnf-sdk.validate-lc-test</groupId> + <groupId>org.onap.vnfsdk.lctest</groupId> <artifactId>vnf-sdk-validate-lc-test</artifactId> - <version>1.1.0-SNAPSHOT</version> + <version>1.0.0-SNAPSHOT</version> </parent> <modelVersion>4.0.0</modelVersion> <artifactId>lifecycle-test-deployment</artifactId> - <version>1.1.0-SNAPSHOT</version> + <version>1.0.0-SNAPSHOT</version> <name>vnf-sdk-validate-lc-test/deployment</name> <packaging>pom</packaging> diff --git a/lifecycle-test/pom.xml b/lifecycle-test/pom.xml index b1e999c..a43cde7 100644 --- a/lifecycle-test/pom.xml +++ b/lifecycle-test/pom.xml @@ -1,161 +1,180 @@ <?xml version="1.0" encoding="UTF-8"?> -<!-- - Copyright 2016-2017 Huawei Technologies Co., Ltd. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. ---> +<!-- Copyright 2016-2017 Huawei Technologies Co., Ltd. Licensed under the + Apache License, Version 2.0 (the "License"); you may not use this file except + in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed + under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES + OR CONDITIONS OF ANY KIND, either express or implied. See the License for + the specific language governing permissions and limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <parent> - <groupId>org.openo.vnf-sdk.validate-lc-test</groupId> - <artifactId>vnf-sdk-validate-lc-test</artifactId> - <version>1.1.0-SNAPSHOT</version> - </parent> - <modelVersion>4.0.0</modelVersion> - <artifactId>lifecycle-test-service</artifactId> - <version>1.1.0-SNAPSHOT</version> - <name>vnf-sdk-validate-lc-test/lifecycle-test-service</name> - <packaging>war</packaging> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.onap.vnfsdk.lctest</groupId> + <artifactId>vnf-sdk-validate-lc-test</artifactId> + <version>1.0.0-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + <artifactId>lifecycle-test-service</artifactId> + <version>1.0.0-SNAPSHOT</version> + <name>vnf-sdk-validate-lc-test/lifecycle-test-service</name> + <packaging>war</packaging> - <dependencies> - <dependency> - <groupId>mysql</groupId> - <artifactId>mysql-connector-java</artifactId> - <version>5.1.36</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-tx</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.mybatis</groupId> - <artifactId>mybatis-spring</artifactId> - <version>1.2.0</version> - </dependency> - <dependency> - <groupId>org.mybatis</groupId> - <artifactId>mybatis</artifactId> - <version>3.2.7</version> - </dependency> - <dependency> - <groupId>org.yaml</groupId> - <artifactId>snakeyaml</artifactId> - <version>1.15</version> - </dependency> - <dependency> - <groupId>org.openo.common-services.common-utilities</groupId> - <artifactId>commonlib-cbb</artifactId> - <version>1.1.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.openo.common-services.common-utilities</groupId> - <artifactId>commonlib-restclient</artifactId> - <version>1.1.0-SNAPSHOT</version> - </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-log4j12</artifactId> - <version>1.6.1</version> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-api-mockito</artifactId> - <version>1.5.4</version> - </dependency> - <dependency> - <groupId>org.mockito</groupId> - <artifactId>mockito-all</artifactId> - <version>1.9.5</version> - </dependency> - <dependency> - <groupId>org.powermock</groupId> - <artifactId>powermock-module-junit4</artifactId> - <version>1.5.4</version> - <type>jar</type> - <scope>compile</scope> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-core</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-aop</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-beans</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-context</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-jdbc</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-web</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-asm</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-expression</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> - <dependency> - <groupId>org.springframework</groupId> - <artifactId>spring-test</artifactId> - <version>3.1.0.RELEASE</version> - </dependency> + <dependencies> + <dependency> + <groupId>mysql</groupId> + <artifactId>mysql-connector-java</artifactId> + <version>5.1.36</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-tx</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.mybatis</groupId> + <artifactId>mybatis-spring</artifactId> + <version>1.2.0</version> + </dependency> + <dependency> + <groupId>org.mybatis</groupId> + <artifactId>mybatis</artifactId> + <version>3.2.7</version> + </dependency> + <dependency> + <groupId>org.yaml</groupId> + <artifactId>snakeyaml</artifactId> + <version>1.15</version> + </dependency> + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + <version>1.6.1</version> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-api-mockito</artifactId> + <version>1.5.4</version> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-all</artifactId> + <version>1.9.5</version> + </dependency> + <dependency> + <groupId>org.powermock</groupId> + <artifactId>powermock-module-junit4</artifactId> + <version>1.5.4</version> + <type>jar</type> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-core</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-aop</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-beans</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-context</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-jdbc</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-web</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-asm</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-expression</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> + <dependency> + <groupId>org.springframework</groupId> + <artifactId>spring-test</artifactId> + <version>3.1.0.RELEASE</version> + </dependency> - <dependency> - <groupId>org.apache.cxf</groupId> - <artifactId>cxf-rt-frontend-jaxrs</artifactId> - <version>3.1.6</version> - </dependency> + <dependency> + <groupId>org.apache.cxf</groupId> + <artifactId>cxf-rt-frontend-jaxrs</artifactId> + <version>3.1.6</version> + </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-jaxrs</artifactId> + <version>1.9.2</version> + </dependency> + <dependency> + <groupId>org.codehaus.jackson</groupId> + <artifactId>jackson-mapper-asl</artifactId> + <version>1.9.2</version> + </dependency> + <dependency> + <groupId>net.sf.json-lib</groupId> + <artifactId>json-lib</artifactId> + <version>2.4</version> + <classifier>jdk15</classifier> + </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-io</artifactId> + <version>1.3.2</version> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.4</version> + </dependency> + <dependency> + <groupId>javax.servlet</groupId> + <artifactId>javax.servlet-api</artifactId> + <version>3.1.0</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>org.apache.httpcomponents</groupId> + <artifactId>httpmime</artifactId> + <version>4.5.2</version> + </dependency> - <!-- UT coverage dependency start --> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <version>4.12</version> - </dependency> - <dependency> - <groupId>org.jmockit</groupId> - <artifactId>jmockit</artifactId> - <version>1.19</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.jmockit</groupId> - <artifactId>jmockit-coverage</artifactId> - <version>1.19</version> - <scope>test</scope> - </dependency> - <!-- UT coverage dependency end --> - </dependencies> + <!-- UT coverage dependency start --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jmockit</groupId> + <artifactId>jmockit-coverage</artifactId> + <version>1.19</version> + <scope>test</scope> + </dependency> + <!-- UT coverage dependency end --> + </dependencies> </project> diff --git a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestConstant.java b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestConstant.java new file mode 100644 index 0000000..cd1c6e4 --- /dev/null +++ b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestConstant.java @@ -0,0 +1,83 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openo.vnfsdk.lctest.common.util; + + +public class RestConstant { + + public static final String UNAME_KEY = "UNAME_KEY"; + + public static final String PWD_KEY = "PWD_KEY"; + + public static final String NETCONF = "NETCONF"; + + public static final String ASYNC = "ASYNC"; + + public static final String SYNC = "SYNC"; + + public static final String HEADERMAP_TYPE = "HEADERMAP_TYPE"; + + public static final String HEADERMAP_VALUE = "HEADERMAP_VALUE"; + + public static final String AUTH_TOKEN = "AUTH_TOKEN"; + + public static final String DEFAULT_HOST_ADDRESS = "localhost"; + + public static final int DEFAULT_PORT = 8080; + + public static final int DEFAULT_MAX_CONNECTION_PER_CONTROLLER = 10; + + public static final int DEFAULT_STRING_LENGTH_64 = 64; + + public static final int DEFAULT_STRING_LENGTH_128 = 128; + + public static final int RESPONSE_CODE_200 = 200; + + public static final int RESPONSE_CODE_201 = 201; + + public static class HttpContext { + + public static final String CONTENT_TYPE = "Content-Type"; + + public static final String MEDIA_TYPE_JSON = "application/json;charset=UTF-8"; + + public static final String URL = "url"; + + public static final String METHOD_TYPE = "methodType"; + + private HttpContext() { + } + } + + + public static class MethodType { + + public static final String POST = "post"; + + public static final String DELETE = "delete"; + + public static final String PUT = "put"; + + public static final String GET = "get"; + + private MethodType() { + } + } + + private RestConstant() { + } +} diff --git a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestResponse.java b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestResponse.java new file mode 100644 index 0000000..8125898 --- /dev/null +++ b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestResponse.java @@ -0,0 +1,40 @@ +/** + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.vnfsdk.lctest.common.util; + + +public class RestResponse { + + public Integer getStatusCode() { + return statusCode; + } + + public void setStatusCode(Integer statusCode) { + this.statusCode = statusCode; + } + + public String getResult() { + return result; + } + + public void setResult(String result) { + this.result = result; + } + + private Integer statusCode; + + private String result; +} diff --git a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestfulClient.java b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestfulClient.java new file mode 100644 index 0000000..594cde1 --- /dev/null +++ b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestfulClient.java @@ -0,0 +1,168 @@ +/** + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.openo.vnfsdk.lctest.common.util; + +import java.io.File; +import java.io.IOException; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.HttpRequest; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.HttpClient; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.HttpDelete; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.utils.URIBuilder; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.DefaultHttpClient; +import org.apache.http.impl.client.HttpClientBuilder; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class RestfulClient { + private static final String HTTP = "http"; + private static final Logger logger = LoggerFactory.getLogger(RestfulClient.class); + + enum HttpMethod { + GET, POST, PUT, DELETE + } + + /** + * execute http. + * @param method http method + * @param ip ip + * @param port port + * @param url url + * @param body http body + * @return RestResponse + */ + public static RestResponse executeHttp(HttpMethod method, String ip, int port, String url, + HttpEntity body) { + CloseableHttpClient httpclient = HttpClients.createDefault(); + HttpResponse httpResponse = null; + RestResponse result = new RestResponse(); + try { + // specify the host, protocol, and port + HttpHost target = new HttpHost(ip, port, HTTP); + // specify the get request + HttpRequest request = getRequest(method, url, body); + httpResponse = httpclient.execute(target, request); + HttpEntity entity = httpResponse.getEntity(); + if (entity != null) { + result.setStatusCode(httpResponse.getStatusLine().getStatusCode()); + result.setResult(EntityUtils.toString(entity)); + } + } catch (Exception e1) { + logger.error("send get rest request error:", e1.getMessage()); + } finally { + if (httpclient != null) { + try { + httpclient.close(); + } catch (IOException e2) { + logger.error("close httpclient error:", e2.getMessage()); + } + } + } + return result; + } + + private static HttpRequest getRequest(HttpMethod method, String url, HttpEntity body) { + HttpRequest request = null; + switch (method) { + case GET: + request = new HttpGet(url); + break; + case POST: + request = new HttpPost(url); + ((HttpPost) request).setEntity(body); + break; + case PUT: + request = new HttpPut(url); + ((HttpPut) request).setEntity(body); + break; + case DELETE: + request = new HttpDelete(url); + break; + default: + break; + } + return request; + } + + public static RestResponse get(String ip, int port, String url) { + return executeHttp(HttpMethod.GET, ip, port, url, null); + } + + public static RestResponse delete(String ip, int port, String url) { + return executeHttp(HttpMethod.DELETE, ip, port, url, null); + } + + public static RestResponse post(String ip, int port, String url, HttpEntity requestBody) { + return executeHttp(HttpMethod.POST, ip, port, url, requestBody); + } + + public static RestResponse sendPostRequest(String ip, String port, String url, String strJson) + { + RestResponse result = new RestResponse(); + CloseableHttpClient httpClient = HttpClientBuilder.create().build(); + HttpResponse httpResponse = null; + try + { + String urlPost = "http://" + ip + ":" + port + url; + logger.info("URL formed for Post, URL :" + urlPost); + logger.info("URL formed for Post, JSON :" + strJson); + + HttpPost request = new HttpPost(urlPost); + + StringEntity params = new StringEntity(strJson); + request.addHeader("content-type", "application/json"); + request.setEntity(params); + + httpResponse = httpClient.execute(request); + HttpEntity entity = httpResponse.getEntity(); + if (entity != null) + { + result.setStatusCode(httpResponse.getStatusLine().getStatusCode()); + result.setResult(EntityUtils.toString(entity)); + } + } + catch (Exception ex) + { + logger.error("Send Post request error:", ex.getMessage()); + } + finally + { + try { + if(null != httpClient) { + httpClient.close(); + } + } + catch(IOException e){ + logger.error("IOException :Send Post request error:", e.getMessage()); + } + } + return result; + } +} diff --git a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestfulUtil.java b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestfulUtil.java deleted file mode 100644 index c42c66a..0000000 --- a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/common/util/RestfulUtil.java +++ /dev/null @@ -1,237 +0,0 @@ -/*
- * Copyright 2017 Huawei Technologies Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.openo.vnfsdk.lctest.common.util;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.servlet.http.HttpServletResponse;
-
-import org.apache.commons.lang3.StringUtils;
-import org.openo.baseservice.remoteservice.exception.ServiceException;
-import org.openo.baseservice.roa.util.restclient.Restful;
-import org.openo.baseservice.roa.util.restclient.RestfulFactory;
-import org.openo.baseservice.roa.util.restclient.RestfulOptions;
-import org.openo.baseservice.roa.util.restclient.RestfulParametes;
-import org.openo.baseservice.roa.util.restclient.RestfulResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import net.sf.json.JSONException;
-import net.sf.json.JSONObject;
-
-/**
- * <br>
- * <p>
- * </p>
- *
- * @author
- * @version NFVO 0.5 Mar 14, 2017
- */
-public class RestfulUtil {
-
- public static final String TYPE_GET = "get";
-
- public static final String TYPE_PUT = "put";
-
- public static final String TYPE_POST = "post";
-
- public static final String TYPE_DEL = "delete";
-
- public static final String CONTENT_TYPE = "Content-type";
-
- public static final String APPLICATION = "application/json";
-
- private static final Logger LOGGER = LoggerFactory.getLogger(RestfulUtil.class);
-
- private static final Restful REST_CLIENT = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP);
-
- private RestfulUtil() {
- }
-
- /**
- * Get response object.<br>
- *
- * @param url
- * @param type
- * @return
- * @since NFVO 0.5
- */
- public static JSONObject getResponseObj(String url, String type) {
- return getResponseObj(url, new RestfulParametes(), type);
- }
-
- /**
- * Get response object.<br>
- *
- * @param url
- * @param parametes
- * @param type
- * @return
- * @since NFVO 0.5
- */
- public static JSONObject getResponseObj(String url, RestfulParametes parametes, String type) {
- try {
- String content = RestfulUtil.getResponseContent(url, parametes, null, type);
- LOGGER.error("function=getResponseObj, content : {}", content);
- if(StringUtils.isEmpty(content)) {
- return null;
- }
- return JSONObject.fromObject(content);
- } catch(JSONException e) {
- LOGGER.error("function=getResponseObj, exception : {}", e);
- return null;
- }
- }
-
- /**
- * Get response content.<br>
- *
- * @param url
- * @param restParametes
- * @param type
- * @return
- * @since NFVO 0.5
- */
- public static String getResponseContent(String url, RestfulParametes restParametes, String type) {
- return getResponseContent(url, restParametes, null, type);
- }
-
- /**
- * Get response content.<br>
- *
- * @param url
- * @param restParametes
- * @param opt
- * @param type
- * @return
- * @since NFVO 0.5
- */
- public static String getResponseContent(String url, RestfulParametes restParametes, RestfulOptions opt,
- String type) {
- String responseContent = null;
- RestfulResponse rsp = restfulResponse(url, restParametes, opt, type);
- if(rsp != null) {
- int httpStatus = rsp.getStatus();
- LOGGER.warn("function=getResponseContent, get response httpStatusCode : {} ", httpStatus);
- if(httpStatus < HttpServletResponse.SC_BAD_REQUEST && httpStatus > 0) {
- responseContent = rsp.getResponseContent();
- LOGGER.warn("function=getResponseContent, get response data success!responseContent={}",
- responseContent);
- }
- }
- return responseContent;
- }
-
- /**
- * Get restful response.<br>
- *
- * @param url
- * @param restParametes
- * @param type
- * @return
- * @since NFVO 0.5
- */
- public static RestfulResponse getRestfulResponse(String url, RestfulParametes restParametes, String type) {
- return restfulResponse(url, restParametes, null, type);
- }
-
- private static RestfulResponse restfulResponse(String url, RestfulParametes restParametes, RestfulOptions opt,
- String type) {
- RestfulResponse rsp = new RestfulResponse();
- try {
-
- if(REST_CLIENT != null) {
- if(TYPE_GET.equals(type)) {
- rsp = REST_CLIENT.get(url, restParametes, opt);
- } else if(TYPE_POST.equals(type)) {
- rsp = REST_CLIENT.post(url, restParametes, opt);
- } else if(TYPE_PUT.equals(type)) {
- rsp = REST_CLIENT.put(url, restParametes, opt);
- } else if(TYPE_DEL.equals(type)) {
- rsp = REST_CLIENT.delete(url, restParametes, opt);
- }
- }
- } catch(ServiceException e) {
- LOGGER.error("function=restfulResponse, get restful response catch exception {} ", e);
- }
- LOGGER.warn("function=restfulResponse, response status is {} ", rsp.getStatus());
- return rsp;
- }
-
- /**
- * <br>
- *
- * @param paramsMap
- * @param params
- * @return
- * @since NFVO 0.5
- */
- public static String getRemoteResponseContent(Map<String, String> paramsMap, String params) {
- String responseContent = null;
- RestfulResponse rsp = getRemoteResponse(paramsMap, params);
- if(rsp != null) {
- int httpStatus = rsp.getStatus();
- LOGGER.warn("function=getResponseContent, get response httpStatusCode : {} ", httpStatus);
- if(httpStatus < HttpServletResponse.SC_BAD_REQUEST && httpStatus > 0) {
- responseContent = rsp.getResponseContent();
- LOGGER.warn("function=getResponseContent, get response data success!responseContent={}",
- responseContent);
- }
- }
- return responseContent;
- }
-
- /**
- * <br>
- *
- * @param paramsMap
- * @param params
- * @return
- * @since NFVO 0.5
- */
- public static RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) {
- String url = paramsMap.get("url");
- String methodType = paramsMap.get("methodType");
-
- RestfulResponse rsp = null;
- Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP);
- try {
-
- RestfulParametes restfulParametes = new RestfulParametes();
- Map<String, String> headerMap = new HashMap<>(3);
- headerMap.put(CONTENT_TYPE, APPLICATION);
- restfulParametes.setHeaderMap(headerMap);
- restfulParametes.setRawData(params);
-
- if(rest != null) {
- if(TYPE_GET.equalsIgnoreCase(methodType)) {
- rsp = rest.get(url, restfulParametes);
- } else if(TYPE_POST.equalsIgnoreCase(methodType)) {
- rsp = rest.post(url, restfulParametes);
- } else if(TYPE_PUT.equalsIgnoreCase(methodType)) {
- rsp = rest.put(url, restfulParametes);
- } else if(TYPE_DEL.equalsIgnoreCase(methodType)) {
- rsp = rest.delete(url, restfulParametes);
- }
- }
- } catch(ServiceException e) {
- LOGGER.error("function=getRemoteResponse, get restful response catch exception {}", e);
- }
- return rsp;
- }
-}
diff --git a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/adapter/impl/LifecycleTestAdapter2MSBManager.java b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/adapter/impl/LifecycleTestAdapter2MSBManager.java index 5e9a7b6..f9d21d8 100644 --- a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/adapter/impl/LifecycleTestAdapter2MSBManager.java +++ b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/adapter/impl/LifecycleTestAdapter2MSBManager.java @@ -18,9 +18,9 @@ package org.openo.vnfsdk.lctest.service.adapter.impl; import java.util.Map; -import org.openo.baseservice.roa.util.restclient.RestfulResponse; + import org.openo.vnfsdk.lctest.common.constant.Constant; -import org.openo.vnfsdk.lctest.common.util.RestfulUtil; +import org.openo.vnfsdk.lctest.common.util.RestResponse; import org.openo.vnfsdk.lctest.service.adapter.inf.ILifecycleTestAdapter2MSBManager; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,28 +43,28 @@ public class LifecycleTestAdapter2MSBManager implements ILifecycleTestAdapter2MS public JSONObject registerLifecycleTest(Map<String, String> paramsMap, JSONObject driverInfo) { JSONObject resultObj = new JSONObject(); - RestfulResponse rsp = RestfulUtil.getRemoteResponse(paramsMap, driverInfo.toString()); + RestResponse rsp = new RestResponse();// = RestfulUtil.getRemoteResponse(paramsMap, driverInfo.toString()); if(null == rsp) { LOG.error("function=registerLifecycleTest, RestfulResponse is null"); resultObj.put(Constant.REASON, "RestfulResponse is null."); resultObj.put(Constant.RETCODE, Constant.ERROR_CODE); return resultObj; } - LOG.warn("function=registerLifecycleTest, status={}, content={}.", rsp.getStatus(), rsp.getResponseContent()); - String resultCreate = rsp.getResponseContent(); + LOG.warn("function=registerLifecycleTest, status={}, content={}.", rsp.getStatusCode(), rsp.getResult()); + String resultCreate = rsp.getResult(); - if(rsp.getStatus() == Constant.HTTP_CREATED) { + if(rsp.getStatusCode() == Constant.HTTP_CREATED) { LOG.warn("function=registerLifecycleTest, result={}.", resultCreate); resultObj = JSONObject.fromObject(resultCreate); resultObj.put("retCode", Constant.HTTP_CREATED); return resultObj; - } else if(rsp.getStatus() == Constant.HTTP_INVALID_PARAMETERS) { + } else if(rsp.getStatusCode() == Constant.HTTP_INVALID_PARAMETERS) { LOG.error("function=registerLifecycleTest, msg=MSB return fail,invalid parameters,status={}, result={}.", - rsp.getStatus(), resultCreate); + rsp.getStatusCode(), resultCreate); resultObj.put("reason", "MSB return fail,invalid parameters."); - } else if(rsp.getStatus() == Constant.HTTP_INNERERROR_CODE) { + } else if(rsp.getStatusCode() == Constant.HTTP_INNERERROR_CODE) { LOG.error("function=registerLifecycleTest, msg=MSB return fail,internal system error,status={}, result={}.", - rsp.getStatus(), resultCreate); + rsp.getStatusCode(), resultCreate); resultObj.put("reason", "MSB return fail,internal system error."); } resultObj.put("retCode", Constant.ERROR_CODE); diff --git a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/adapter/impl/LifecycleTestAdapterMgrService.java b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/adapter/impl/LifecycleTestAdapterMgrService.java index 3c0b627..a9efae3 100644 --- a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/adapter/impl/LifecycleTestAdapterMgrService.java +++ b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/adapter/impl/LifecycleTestAdapterMgrService.java @@ -25,10 +25,11 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.Executors; -import org.openo.baseservice.util.impl.SystemEnvVariablesFactory; + import org.openo.vnfsdk.lctest.common.constant.Constant; import org.openo.vnfsdk.lctest.common.constant.UrlConstant; -import org.openo.vnfsdk.lctest.common.util.RestfulUtil; +import org.openo.vnfsdk.lctest.common.util.RestConstant; + import org.openo.vnfsdk.lctest.service.adapter.inf.ILifecycleTestAdapter2MSBManager; import org.openo.vnfsdk.lctest.service.adapter.inf.ILifecycleTestAdapterMgrService; import org.slf4j.Logger; @@ -57,7 +58,7 @@ public class LifecycleTestAdapterMgrService implements ILifecycleTestAdapterMgrS // set MSB URL and mothedtype Map<String, String> paramsMap = new HashMap<>(); paramsMap.put("url", UrlConstant.REST_MSB_REGISTER); - paramsMap.put("methodType", RestfulUtil.TYPE_POST); + paramsMap.put("methodType", RestConstant.MethodType.POST); // get LifecycleTest info and raise registration try { @@ -87,7 +88,7 @@ public class LifecycleTestAdapterMgrService implements ILifecycleTestAdapterMgrS BufferedInputStream bins = null; String fileContent = ""; - String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty(Constant.SEPARATOR) + String fileName = "./" + System.getProperty(Constant.SEPARATOR) + "etc" + System.getProperty(Constant.SEPARATOR) + "adapterInfo" + System.getProperty(Constant.SEPARATOR) + LIFECYCLETESTINFO; diff --git a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/business/impl/VnfpackageServiceImpl.java b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/business/impl/VnfpackageServiceImpl.java index e566577..9a6a959 100644 --- a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/business/impl/VnfpackageServiceImpl.java +++ b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/business/impl/VnfpackageServiceImpl.java @@ -20,7 +20,8 @@ import java.util.HashMap; import java.util.Map;
import org.openo.vnfsdk.lctest.common.constant.UrlConstant;
-import org.openo.vnfsdk.lctest.common.util.RestfulUtil;
+import org.openo.vnfsdk.lctest.common.util.RestConstant;
+import org.openo.vnfsdk.lctest.common.util.RestfulClient;
import org.openo.vnfsdk.lctest.service.business.inf.VnfpackageService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,6 +39,9 @@ import net.sf.json.JSONObject; public class VnfpackageServiceImpl implements VnfpackageService {
private static final Logger LOGGER = LoggerFactory.getLogger(VnfpackageServiceImpl.class);
+
+ private static String MsbIpAddress = "127.0.0.1";
+ private static int MsbPort = 80;
/**
* <br>
@@ -51,8 +55,8 @@ public class VnfpackageServiceImpl implements VnfpackageService { LOGGER.info("VnfpackageServiceImpl::onboarding:{}", object.toString());
Map<String, String> paramsMap = new HashMap<>(3);
paramsMap.put("url", UrlConstant.NSLCM_VNFPACKAGE_URL);
- paramsMap.put("methodType", RestfulUtil.TYPE_POST);
- String rsp = RestfulUtil.getRemoteResponseContent(paramsMap, object.toString());
+ paramsMap.put("methodType", RestConstant.MethodType.POST);
+ String rsp = null; //RestfulUtil.getRemoteResponseContent(paramsMap, object.toString());
if(null == rsp) {
JSONObject resJson = new JSONObject();
resJson.put("message", "NS LCM response Error.");
@@ -72,7 +76,8 @@ public class VnfpackageServiceImpl implements VnfpackageService { @Override
public JSONObject queryVnfpackage(String csarId) {
String url = String.format(UrlConstant.QUERY_VNFPACKAGE_URL, csarId);
- JSONObject rsp = RestfulUtil.getResponseObj(url, RestfulUtil.TYPE_GET);
+ JSONObject rsp = null;//RestfulClient.get(MsbIpAddress, MsbPort, url).getResult();
+
if(null == rsp) {
JSONObject resJson = new JSONObject();
resJson.put("message", "NS LCM response Error.");
@@ -94,8 +99,8 @@ public class VnfpackageServiceImpl implements VnfpackageService { LOGGER.info("VnfpackageServiceImpl::updatestatus:{}", object.toString());
Map<String, String> paramsMap = new HashMap<>(3);
paramsMap.put("url", UrlConstant.MARKETPLACE_UPDATE_STATUS_URL);
- paramsMap.put("methodType", RestfulUtil.TYPE_POST);
- String rsp = RestfulUtil.getRemoteResponseContent(paramsMap, object.toString());
+ paramsMap.put("methodType", RestConstant.MethodType.POST);
+ String rsp = null; //RestfulUtil.getRemoteResponseContent(paramsMap, object.toString());
if(null == rsp) {
JSONObject resJson = new JSONObject();
resJson.put("message", "Marketplace response Error.");
diff --git a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/rest/VnfpackageRoa.java b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/rest/VnfpackageRoa.java index e1d271d..f59a6be 100644 --- a/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/rest/VnfpackageRoa.java +++ b/lifecycle-test/src/main/java/org/openo/vnfsdk/lctest/service/rest/VnfpackageRoa.java @@ -26,7 +26,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
-import org.openo.baseservice.remoteservice.exception.ServiceException;
+
import org.openo.vnfsdk.lctest.common.util.RequestUtil;
import org.openo.vnfsdk.lctest.service.business.inf.VnfpackageService;
import org.slf4j.Logger;
@@ -60,11 +60,11 @@ public class VnfpackageRoa { * @since NFVO 0.5
*/
@POST
- public JSONObject onboarding(@Context HttpServletRequest context) throws ServiceException {
+ public JSONObject onboarding(@Context HttpServletRequest context) {
JSONObject object = RequestUtil.getJsonRequestBody(context);
if(null == object) {
LOGGER.error("function=onboarding; msg=context is null.");
- throw new ServiceException("org.openo.vnfsdk.lctest.service.rest.VnfpackageRoa.onboarding.null");
+ //throw new ServiceException("org.openo.vnfsdk.lctest.service.rest.VnfpackageRoa.onboarding.null");
}
LOGGER.info("VnfpackageRoa::onboarding:{}", object.toString());
@@ -73,11 +73,11 @@ public class VnfpackageRoa { @POST
@Path("/updatestatus")
- public JSONObject updatestatus(@Context HttpServletRequest context) throws ServiceException {
+ public JSONObject updatestatus(@Context HttpServletRequest context) {
JSONObject object = RequestUtil.getJsonRequestBody(context);
if(null == object) {
LOGGER.error("function=onboarding; msg=context is null.");
- throw new ServiceException("org.openo.vnfsdk.lctest.service.rest.VnfpackageRoa.onboarding.null");
+ //throw new ServiceException("org.openo.vnfsdk.lctest.service.rest.VnfpackageRoa.onboarding.null");
}
LOGGER.info("VnfpackageRoa::updatestatus:{}", object.toString());
@@ -96,7 +96,7 @@ public class VnfpackageRoa { @GET
@Path("/{csarId}")
public JSONObject queryVnfpackage(@Context HttpServletRequest context, @PathParam("csarId") String csarId)
- throws ServiceException {
+ {
LOGGER.warn("function=queryVnfpackage, csarId={}", csarId);
return vnfpackageService.queryVnfpackage(csarId);
}
@@ -16,15 +16,15 @@ --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <parent> - <groupId>org.openo.oparent</groupId> + <groupId>org.onap.oparent</groupId> <artifactId>oparent</artifactId> - <version>1.1.0-SNAPSHOT</version> + <version>0.1.1</version> <relativePath>../oparent</relativePath> </parent> <modelVersion>4.0.0</modelVersion> - <groupId>org.openo.vnf-sdk.validate-lc-test</groupId> + <groupId>org.onap.vnfsdk.lctest</groupId> <artifactId>vnf-sdk-validate-lc-test</artifactId> - <version>1.1.0-SNAPSHOT</version> + <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <name>vnfsdk-lctest</name> |