diff options
author | 2017-07-04 17:30:27 +0800 | |
---|---|---|
committer | 2017-07-04 17:30:27 +0800 | |
commit | 308af7411c9f9cdb065da07b6d77e32f5911e7a1 (patch) | |
tree | 37e42ceddc177a6dc1a69bac096c80f506ea8d22 /juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src | |
parent | 381a045ffca7ee96cf63a919220c619b0aafe8ed (diff) |
add gvnfm codes
NFVO-127
Change-Id: I447ff20ed2559d6b77041879f6abc15710acb501
Signed-off-by: Quan-Zhong <quanzhong@huawei.com>
Diffstat (limited to 'juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src')
153 files changed, 20274 insertions, 0 deletions
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITConfigRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITConfigRoaTest.java new file mode 100644 index 0000000..1495ad9 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITConfigRoaTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest; + +import java.io.File; + +import org.junit.Assert; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.sdno.testframework.checker.IChecker; +import org.openo.sdno.testframework.http.model.HttpResponse; +import org.openo.sdno.testframework.testmanager.TestManager; + +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Sep 29, 2016 + */ +public class ITConfigRoaTest extends TestManager { + private static final String GET_SUCCESS_PATH = "testcase/configroa/setDebugModelTestSuccess.json"; + private static final String GET_FAIL_PATH = "testcase/configroa/setDebugModelTestFail.json"; + + @Test + public void setDebugModelTestSuccess() throws ServiceException{ + execTestCase(new File(getClassPath()+File.separator+GET_SUCCESS_PATH), new IChecker(){ + + @Override + public boolean check(HttpResponse paramHttpResponse) { + int status = paramHttpResponse.getStatus(); + if(status == 200){ + String data = paramHttpResponse.getData(); + JSONObject dataObj = JSONObject.fromObject(data); + Assert.assertNotNull(dataObj); + return true; + } + + return false; + } + + }); + } + @Test + public void setDebugModelTestFail() throws ServiceException{ + execTestCase(new File(getClassPath()+File.separator+GET_FAIL_PATH), new IChecker(){ + + @Override + public boolean check(HttpResponse paramHttpResponse) { + int status = paramHttpResponse.getStatus(); + if(status != 200){ + return true; + } + return false; + } + + }); + } + + public static String getClassPath(){ + String path = ClassLoader.getSystemClassLoader().getResource("./").getPath(); + if(path.endsWith("/")){ + path = path.substring(0, path.length()-1); + } + return path; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITJujuClientRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITJujuClientRoaTest.java new file mode 100644 index 0000000..363e85e --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITJujuClientRoaTest.java @@ -0,0 +1,92 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest; + +import java.io.File; + +import org.junit.Assert; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.sdno.testframework.checker.IChecker; +import org.openo.sdno.testframework.http.model.HttpResponse; +import org.openo.sdno.testframework.testmanager.TestManager; + +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Sep 29, 2016 + */ +public class ITJujuClientRoaTest extends TestManager { + private static final String GETVNFSTATUS_PATH = "testcase/jujuclientroa/getVnfStatus.json"; + private static final String DEPLOYSERIVCE_PATH = "testcase/jujuclientroa/deploySerivce.json"; +// private static final String GETVNFSTATUS_PATH = "testcase/jujuclientroa/getVnfStatus.json"; + + @Test + public void getVnfStatus() throws ServiceException{ + execTestCase(new File(getClassPath()+File.separator+GETVNFSTATUS_PATH), new IChecker(){ + + @Override + public boolean check(HttpResponse paramHttpResponse) { + int status = paramHttpResponse.getStatus(); + if(status == 200){ + String data = paramHttpResponse.getData(); + JSONObject dataObj = JSONObject.fromObject(data); + Assert.assertEquals(dataObj.get(EntityUtils.RESULT_CODE_KEY),"0"); + return true; + } + + return false; + } + + }); + } + + @Test + public void deploySerivce() throws ServiceException{ + execTestCase(new File(getClassPath()+File.separator+DEPLOYSERIVCE_PATH), new IChecker(){ + + @Override + public boolean check(HttpResponse paramHttpResponse) { + int status = paramHttpResponse.getStatus(); + if(status == 200){ + String data = paramHttpResponse.getData(); + JSONObject dataObj = JSONObject.fromObject(data); + Assert.assertNotNull(dataObj); + return true; + } + + return false; + } + + }); + } + + + public static String getClassPath(){ + String path = ClassLoader.getSystemClassLoader().getResource("./").getPath(); + if(path.endsWith("/")){ + path = path.substring(0, path.length()-1); + } + return path; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITVnfRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITVnfRoaTest.java new file mode 100644 index 0000000..bb5ff7d --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ITVnfRoaTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest; + +import java.io.File; + +import org.junit.Assert; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.sdno.testframework.checker.IChecker; +import org.openo.sdno.testframework.http.model.HttpResponse; +import org.openo.sdno.testframework.testmanager.TestManager; + +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Sep 29, 2016 + */ +public class ITVnfRoaTest extends TestManager { + private static final String GET_SUCCESS_PATH = "testcase/configroa/setDebugModelTestSuccess.json"; + private static final String GET_FAIL_PATH = "testcase/configroa/setDebugModelTestFail.json"; + + @Test + public void addVnfTestSuccess() throws ServiceException{ + execTestCase(new File(getClassPath()+File.separator+GET_SUCCESS_PATH), new IChecker(){ + + @Override + public boolean check(HttpResponse paramHttpResponse) { + int status = paramHttpResponse.getStatus(); + if(status == 200){ + String data = paramHttpResponse.getData(); + JSONObject dataObj = JSONObject.fromObject(data); + Assert.assertNotNull(dataObj); + return true; + } + + return false; + } + + }); + } + @Test + public void addVnfTestFail() throws ServiceException{ + execTestCase(new File(getClassPath()+File.separator+GET_FAIL_PATH), new IChecker(){ + + @Override + public boolean check(HttpResponse paramHttpResponse) { + int status = paramHttpResponse.getStatus(); + if(status != 200){ + return true; + } + return false; + } + + }); + } + + public static String getClassPath(){ + String path = ClassLoader.getSystemClassLoader().getResource("./").getPath(); + if(path.endsWith("/")){ + path = path.substring(0, path.length()-1); + } + return path; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/server.properties b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/server.properties new file mode 100644 index 0000000..55d99f6 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/server.properties @@ -0,0 +1,29 @@ +############################################################################### +# Copyright 2016 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. +############################################################################### + +## Integration Test Server Configuration File + +## Server IpAddress +serverip=127.0.0.1 + +## Server Port +serverport=8080 + +## Http Moco Server Port +mocohttpport=12306 + +## Https Moco Server Port +mocohttpsport=12307
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/configroa/setDebugModelTestFail.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/configroa/setDebugModelTestFail.json new file mode 100644 index 0000000..258a256 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/configroa/setDebugModelTestFail.json @@ -0,0 +1,16 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/config/debug/1r", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + } + }, + "response": { + "status": 500, + "json": { + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/configroa/setDebugModelTestSuccess.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/configroa/setDebugModelTestSuccess.json new file mode 100644 index 0000000..2ba2bc4 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/configroa/setDebugModelTestSuccess.json @@ -0,0 +1,16 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/config", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": {} + }, + "response": { + "status": 200, + "json": { + "debugModel":false + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/deploySerivce.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/deploySerivce.json new file mode 100644 index 0000000..e9f9b4d --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/deploySerivce.json @@ -0,0 +1,16 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/openoapi/juju/v1/vnfms/deploy", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": {"appName":"testApp"} + }, + "response": { + "status": 200, + "json": { + "debugModel":false + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/destroySerivce.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/destroySerivce.json new file mode 100644 index 0000000..5a978a2 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/destroySerivce.json @@ -0,0 +1,16 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/openoapi/juju/v1/vnfms/", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": {} + }, + "response": { + "status": 200, + "json": { + "debugModel":false + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/getVnfStatus.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/getVnfStatus.json new file mode 100644 index 0000000..1b07b65 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/java/testcase/jujuclientroa/getVnfStatus.json @@ -0,0 +1,18 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/openoapi/juju/v1/vnfms/testabc/status", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "appName":"testApp" + } + }, + "response": { + "status": 200, + "json": { + "debugModel":false + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/server.properties b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/server.properties new file mode 100644 index 0000000..55d99f6 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/server.properties @@ -0,0 +1,29 @@ +############################################################################### +# Copyright 2016 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. +############################################################################### + +## Integration Test Server Configuration File + +## Server IpAddress +serverip=127.0.0.1 + +## Server Port +serverport=8080 + +## Http Moco Server Port +mocohttpport=12306 + +## Https Moco Server Port +mocohttpsport=12307
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/configroa/setDebugModelTestFail.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/configroa/setDebugModelTestFail.json new file mode 100644 index 0000000..258a256 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/configroa/setDebugModelTestFail.json @@ -0,0 +1,16 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/config/debug/1r", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + } + }, + "response": { + "status": 500, + "json": { + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/configroa/setDebugModelTestSuccess.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/configroa/setDebugModelTestSuccess.json new file mode 100644 index 0000000..2ba2bc4 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/configroa/setDebugModelTestSuccess.json @@ -0,0 +1,16 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/config", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": {} + }, + "response": { + "status": 200, + "json": { + "debugModel":false + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/deploySerivce.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/deploySerivce.json new file mode 100644 index 0000000..e9f9b4d --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/deploySerivce.json @@ -0,0 +1,16 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/openoapi/juju/v1/vnfms/deploy", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": {"appName":"testApp"} + }, + "response": { + "status": 200, + "json": { + "debugModel":false + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/destroySerivce.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/destroySerivce.json new file mode 100644 index 0000000..5a978a2 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/destroySerivce.json @@ -0,0 +1,16 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/openoapi/juju/v1/vnfms/", + "method": "get", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": {} + }, + "response": { + "status": 200, + "json": { + "debugModel":false + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/getVnfStatus.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/getVnfStatus.json new file mode 100644 index 0000000..1b07b65 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/integration-test/resources/testcase/jujuclientroa/getVnfStatus.json @@ -0,0 +1,18 @@ +{ + "request": { + "uri": "/juju-vnfmadapter-service/rest/openoapi/juju/v1/vnfms/testabc/status", + "method": "post", + "headers": { + "Content-Type": "application/json;charset=UTF-8" + }, + "json": { + "appName":"testApp" + } + }, + "response": { + "status": 200, + "json": { + "debugModel":false + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/AsyncCallback.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/AsyncCallback.java new file mode 100644 index 0000000..2369d18 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/AsyncCallback.java @@ -0,0 +1,46 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * Async Callback class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class AsyncCallback implements RestfulAsyncCallback { + + private static final Logger LOGGER = LoggerFactory.getLogger(AsyncCallback.class); + + @Override + public void callback(RestfulResponse response) { + LOGGER.warn("function=callback, msg=status={}, content={}.", response.getStatus(), response.getResponseContent()); + } + + @Override + public void handleExcepion(Throwable e) { + LOGGER.error("function=callback, msg= e is {}.", e); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/BaseTimeJob.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/BaseTimeJob.java new file mode 100644 index 0000000..1698702 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/BaseTimeJob.java @@ -0,0 +1,85 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import java.util.Calendar; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +/** + * + * Base time job class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public abstract class BaseTimeJob implements Runnable { + + private ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); + + private long initialDelay = 1; + + private long period = 1; + + private String startTime = ""; + + @Override + public abstract void run(); + + /** + * + * Stop method.<br> + * + * @since NFVO 0.5 + */ + public void stop() { + service.shutdown(); + } + + public void setInitialDelay(long initialDelay) { + this.initialDelay = initialDelay; + } + + public void setPeriod(long period) { + this.period = period; + } + + /** + * + * Start method.<br> + * + * @since NFVO 0.5 + */ + public void start() { + if(startTime.length() != 0) { + String[] vnfTime = startTime.split(":"); + if(vnfTime.length == 2) { + int minute = Integer.parseInt(vnfTime[0]) * 60 + Integer.parseInt(vnfTime[1]); + Calendar calendar = Calendar.getInstance(); + int curMinute = calendar.get(Calendar.HOUR_OF_DAY) * 60 + calendar.get(Calendar.MINUTE); + if(curMinute <= minute) { + initialDelay = (minute - curMinute) * 60L; + } else { + initialDelay = (minute + 24 * 60 - curMinute) * 60L; + } + } + } + service.scheduleAtFixedRate(this, initialDelay, period, TimeUnit.SECONDS); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/CryptUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/CryptUtil.java new file mode 100644 index 0000000..9582f52 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/CryptUtil.java @@ -0,0 +1,63 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +/** + * + * Cryptographic utility class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public final class CryptUtil { + + /** + * Constructor<br/> + * <p> + * </p> + * + */ + private CryptUtil() { + //Empty Constructor + } + + /** + * + * Decription.<br> + * + * @param pwd + * @return + * @since NFVO 0.5 + */ + public static String deCrypt(String pwd) { + return pwd; + } + + /** + * + * Encryption.<br> + * + * @param pwd + * @return + * @since NFVO 0.5 + */ + public static String enCrypt(String pwd) { + return pwd; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/DownloadCsarManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/DownloadCsarManager.java new file mode 100644 index 0000000..dd21809 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/DownloadCsarManager.java @@ -0,0 +1,240 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.http.Header; +import org.apache.http.HeaderElement; +import org.apache.http.HttpEntity; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * Utility class to download CSAR + * + * @author + * @version NFVO 0.5 Sep 5, 2016 + * + */ +public class DownloadCsarManager { + + private static final Logger LOG = LoggerFactory.getLogger(DownloadCsarManager.class); + + public static final int CACHE = 100 * 1024; + + private DownloadCsarManager(){ + //private constructor + } + + /** + * Download from given URL. + * @param url String + * @return + */ + public static String download(String url) { + return download(url, null); + } + + /** + * Download from given URL to given file location. + * @param url String + * @param filepath String + * @return + */ + public static String download(String url, String filepath) { + String status = ""; + try { + CloseableHttpClient client = HttpClients.createDefault(); + HttpGet httpget = new HttpGet(url); + CloseableHttpResponse response = client.execute(httpget); + + HttpEntity entity = response.getEntity(); + InputStream is = entity.getContent(); + if (filepath == null){ + filepath = getFilePath(response); //NOSONAR + } + + File file = new File(filepath); + file.getParentFile().mkdirs(); + FileOutputStream fileout = new FileOutputStream(file); + + byte[] buffer = new byte[CACHE]; + int ch; + while ((ch = is.read(buffer)) != -1) { + fileout.write(buffer,0,ch); + } + is.close(); + fileout.flush(); + fileout.close(); + status = Constant.DOWNLOADCSAR_SUCCESS; + + } catch (Exception e) { + status = Constant.DOWNLOADCSAR_FAIL; + LOG.error("Download csar file failed! "+ e.getMessage(), e); + } + return status; + } + + /** + * Retrieve file path from given response. + * @param response HttpResponse + * @return + */ + public static String getFilePath(HttpResponse response) { + String filepath = System.getProperty("java.home"); + String filename = getFileName(response); + + if (filename != null) { + filepath += filename; + } else { + filepath += getRandomFileName(); + } + return filepath; + } + + /** + * Retrieve file name from given response. + * @param response HttpResponse + * @return + */ + public static String getFileName(HttpResponse response) { + Header contentHeader = response.getFirstHeader("Content-Disposition"); + String filename = null; + if (contentHeader != null) { + HeaderElement[] values = contentHeader.getElements(); + if (values.length == 1) { + NameValuePair param = values[0].getParameterByName("filename"); + if (param != null) { + try { + filename = param.getValue(); + } catch (Exception e) { + LOG.error("getting filename failed! "+ e.getMessage(), e); + } + } + } + } + return filename; + } + + /** + * Provides random file name. + * @return + */ + public static String getRandomFileName() { + return String.valueOf(System.currentTimeMillis()); + } + + /** + * unzip CSAR packge + * @param fileName filePath + * @return + */ + public static int unzipCSAR(String fileName,String filePath){ + final int BUFFER = 2048; + int status=0; + + try { + ZipFile zipFile = new ZipFile(fileName); + Enumeration emu = zipFile.entries(); + int i=0; + while(emu.hasMoreElements()){ + ZipEntry entry = (ZipEntry)emu.nextElement(); + //read directory as file first,so only need to create directory + if (entry.isDirectory()) + { + new File(filePath + entry.getName()).mkdirs(); + continue; + } + BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); + File file = new File(filePath + entry.getName()); + //Because that is random to read zipfile,maybe the file is read first + //before the directory is read,so we need to create directory first. + File parent = file.getParentFile(); + if(parent != null && (!parent.exists())){ + parent.mkdirs(); + } + FileOutputStream fos = new FileOutputStream(file); + BufferedOutputStream bos = new BufferedOutputStream(fos,BUFFER); + + int count; + byte data[] = new byte[BUFFER]; + while ((count = bis.read(data, 0, BUFFER)) != -1) + { + bos.write(data, 0, count); + } + bos.flush(); + bos.close(); + bis.close(); + + if(entry.getName().endsWith(".zip")){ + File subFile = new File(filePath+entry.getName()); + if(subFile.exists()){ + int subStatus = unzipCSAR(filePath+entry.getName(),subFile.getParent()+"/"); + if(subStatus != 0){ + LOG.error("sub file unzip fail!"+subFile.getName()); + status=Constant.UNZIP_FAIL; + return status; + } + } + } + } + status=Constant.UNZIP_SUCCESS; + zipFile.close(); + } catch (Exception e) { + status=Constant.UNZIP_FAIL; + e.printStackTrace(); + } + return status; + } + + private static String getImagesPath(String csarfilepath){ + File imageFile = new File(csarfilepath+"SoftwareImages"); + if(imageFile.exists()){ + File[] charmFiles = imageFile.listFiles(); + for(File file : charmFiles){ + if(!file.getName().endsWith(".zip")){ + return file.getAbsolutePath(); + } + } + } + return csarfilepath; + } + public static void main(String[] args) { + System.out.println(getImagesPath("e:/juju/csar2/")); + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/EntityUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/EntityUtils.java new file mode 100644 index 0000000..9899c34 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/EntityUtils.java @@ -0,0 +1,297 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import java.io.File; +import java.io.InputStream; +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeoutException; + +import org.apache.commons.lang3.StringUtils; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 30, 2016 + */ +public class EntityUtils { + + private static final Logger LOG = LoggerFactory.getLogger(EntityUtils.class); + + public static final String RESULT_CODE_KEY = "retCode"; + + public static final String MSG_KEY = "msg"; + + public static final String DATA_KEY = "data"; + + public static final String STATUS = "status"; + + /** + * Constructor<br/> + * <p> + * </p> + */ + private EntityUtils() { + // Empty Constructor + } + + /** + * <br> + * + * @param jsonObject + * @param clazz + * @return T + * @throws Exception + */ + @SuppressWarnings("unchecked") + public static <T> T toEntity(JSONObject jsonObject, Class<?> clazz) throws Exception { // NOSONAR + T instance = (T)clazz.newInstance(); + Field[] fields = clazz.getDeclaredFields(); + for(int i = 0; i < fields.length; i++) { + fields[i].setAccessible(true); + fields[i].set(instance, jsonObject.get(fields[i].getName())); + } + return instance; + } + + /** + * format the obj to str style as json format. + * <br/> + * + * @param obj + * @param clazz + * @return + * @since NFVO 0.5 + */ + public static String toString(Object obj, Class<?> clazz) { + JSONObject jsonObj = new JSONObject(); + try { + Field[] fields = clazz.getDeclaredFields(); + for(int i = 0; i < fields.length; i++) { + fields[i].setAccessible(true); + jsonObj.put(fields[i].getName(), obj != null ? fields[i].get(obj) : ""); + } + } catch(Exception e) { + LOG.error("to string error:", e); + } + return jsonObj.toString(); + } + + /** + * <br> + * <p> + * </p> + * + * @author + */ + public static class ExeRes { + + public static final int SUCCESS = 0; + + public static final int FAILURE = -1; + + private int code; + + private String body; + + /** + * @return Returns the code. + */ + public int getCode() { + return code; + } + + /** + * @param code The code to set. + */ + public void setCode(int code) { + this.code = code; + } + + /** + * @return Returns the body. + */ + public String getBody() { + return body; + } + + /** + * @param body The body to set. + */ + public void setBody(String body) { + this.body = body; + } + + @Override + public String toString() { + try { + return EntityUtils.toString(this, this.getClass()); + } catch(Exception e) { + LOG.error("to string error:", e); + return "code:" + this.getCode() + ",body:" + this.getBody(); + } + } + + } + + /** + * <br> + * + * @param command + * @return String + */ + public static String formatCommand(List<String> command) { + StringBuilder builder = new StringBuilder(); + if(command != null) { + for(String cmd : command) { + builder.append(cmd).append(" "); // NOSONAR + } + } + return builder.toString(); + + } + + /** + * <br> + * + * @param dir + * @param command + * @return + */ + public static ExeRes execute(String dir, String... command) { + List<String> commands = new ArrayList<>(command.length); + for(String arg : command) { + commands.add(arg); + } + return execute(dir, commands); + + } + + /** + * execute local command + * <br/> + * + * @param dir the command path + * @param command + * @return response msg + * @since NFVO 0.5 + */ + public static ExeRes execute(String dir, List<String> command) { + ExeRes er = new ExeRes(); + StringBuilder sb = new StringBuilder(); + try { + if(SwitchController.isDebugModel()) { + String resContent = new String(FileUtils.readFile(new File(JujuConfigUtil.getValue("juju_cmd_res_file")), "UTF-8")); + er.setBody(resContent); + return er; + } + ProcessBuilder pb = new ProcessBuilder(command); + if(StringUtils.isNotBlank(dir)) { + pb.directory(new File(dir)); + } + pb.redirectErrorStream(true); + Process p = pb.start(); + + // wait the process result + buildProcessResult(er, p); + + InputStream in = p.getInputStream(); + byte[] buffer = new byte[1024]; + int length; + while((length = in.read(buffer)) > 0) { + sb.append(new String(buffer, 0, length)); + } + in.close(); + er.setBody(sb.toString()); + } catch(Exception e) { + er.setCode(ExeRes.FAILURE); + er.setBody(e.getMessage()); + LOG.error("execute the command failed:{}", command, e); + } + return er; + } + + /** + * <br/> + * + * @param er + * @param p + * @throws TimeoutException + * @throws InterruptedException + * @since NFVO 0.5 + */ + private static void buildProcessResult(ExeRes er, Process p) throws TimeoutException, InterruptedException { + Worker worker = new Worker(p); + worker.start(); + try { + worker.join(Constant.PROCESS_WAIT_MILLIS); + if(worker.exitValue != null) { + int exit = worker.exitValue; + if(exit != 0) { + er.setCode(ExeRes.FAILURE); + LOG.warn("the process exit non-normal"); + } else { + er.setCode(ExeRes.SUCCESS); + } + } else { + er.setCode(ExeRes.FAILURE); + LOG.warn("the process execute timeout."); + throw new TimeoutException(); + } + } catch(InterruptedException e) { + worker.interrupt(); + Thread.currentThread().interrupt(); + throw e; + } + } + + private static class Worker extends Thread { + + private final Process process; + + private Integer exitValue; + + private Worker(Process process) { + this.process = process; + } + + /** + * <br/> + * + * @since NFVO 0.5 + */ + @Override + public void run() { + try { + exitValue = process.waitFor(); + } catch(InterruptedException e) { + return; + } + } + + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtils.java new file mode 100644 index 0000000..cb68a5b --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtils.java @@ -0,0 +1,501 @@ +/* + * Copyright (c) 2016, 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.nfvo.jujuvnfmadapter.common; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.List; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * FileUtils + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Sep 23, 2016 + */ +public class FileUtils { + + public static final String UTF8 = "UTF-8"; + + public static final String GBK = "GBK"; + + private static Logger log = LoggerFactory.getLogger(FileUtils.class); + + private FileUtils(){ + + } + /** + * get current classPath as str. and the trailing slash will be remove + * <br/> + * + * @return + * @since NFVO 0.5 + */ + public static String getClassPath(){ + String path = ClassLoader.getSystemClassLoader().getResource("./").getPath(); + if(path.endsWith("/")){ + path = path.substring(0, path.length()-1); + } + return path; + } + /** + * read data from the file + * <br/> + * + * @param file + * @param charsetName + * @return + * @throws IOException + * @since NFVO 0.5 + */ + public static byte[] readFile(File file, String charsetName) throws IOException { + if(file != null) { + FileReader reader = new FileReader(file); + StringBuilder buffer = new StringBuilder(); + char[] cbuf = new char[1024]; + int legth; + while((legth = reader.read(cbuf)) != -1) { + buffer.append(new String(cbuf, 0, legth)); + } + reader.close(); + return buffer.toString().getBytes(charsetName); + } + return new byte[]{}; + } + + /** + * write data as file to the filePath + * <br/> + * + * @param data + * @param filePath + * @return + * @since NFVO 0.5 + */ + public static int writeFile(byte[] data, String filePath) { + try { + OutputStream out = new FileOutputStream(filePath); + out.write(data, 0, data.length); + out.close(); + return 0; + } catch (Exception e) { + log.error("write file fail,filePath:"+filePath, e); + } + return -1; + } + + /** + * List all files in directory + * @param file + * @return + * @throws FileNotFoundException + */ + public static List<File> listFiles(File file) throws FileNotFoundException{ + List<File> list = new ArrayList<>(); + list(file, list); + return list; + } + /** + * List all files in directory + * @param file + * @param list + * @throws FileNotFoundException + */ + private static void list(File file, List<File> list) throws FileNotFoundException{ + if(!file.exists()){ + throw new FileNotFoundException(file.getAbsolutePath()); + } + File[] files = file.listFiles(); + if(files != null && files.length > 0 ){ + for(File f : files){ + if(f.isFile()){ + list.add(f); + }else{ + list(f, list); + } + } + } + } + + + /** + * createDirs (cycle create) + * <br/> + * + * @param file + * @since NFVO 0.5 + */ + public static void createDirs(File file){ + if(file.getParentFile().exists()){ + file.mkdir(); + }else{ + createDirs(file.getParentFile()); + file.mkdir(); + } + } + + /** + *mkDirs + * <br/> + * + * @param path + * @since NFVO 0.5 + */ + public static void mkDirs(String path){ + File file = new File(path); + createDirs(file); + } + + + + public static String getSuperUrl(String file) { + return new File(file).getParentFile().getAbsolutePath(); + + } + + /** + * absolute url + * + * @author sunny.sun + * @return file this application absolute url + */ + public static String getAppAbsoluteUrl() { + + // ��ȡ��class���ڵľ���·�� + String file = UnCompressUtil.class.getClassLoader().getResource("/") == null ? null + : UnCompressUtil.class.getClassLoader().getResource("/").toString(); + if (file == null) { + file = UnCompressUtil.class.getProtectionDomain().getCodeSource() + .getLocation().getFile().substring(1); + } + // ��class�ļ���war��ʱ������"zip:D:/ ..."����·�� + if (file.startsWith("zip")) { + file = file.substring(4); + + // ��class�ļ���class�ļ���ʱ������"file:/F:/ ..."����·�� + } else if (file.startsWith("file")) { + file = file.substring(6); + + // ��class�ļ���jar�ļ���ʱ������"jar:file:/F:/ ..."����·�� + } else if (file.startsWith("jar")) { + file = file.substring(10); + } + + if (!isWindows()) + return ("/" + file).replace("%20", " "); + + return file.replace("%20", " "); + } + + public static String getWEBClassAbsoluteUrl() { + + return getAppAbsoluteUrl(); + } + + /** + * @param floder + * @return + */ + public static File newFloder(String floder) { + File file = new File(floder); + if (!file.exists()) { + file.mkdirs(); + } + return file; + } + + + + public static void copyFile(String oldPath, String newPath, boolean flag) + throws Exception { + int byteread = 0; + File oldfile = new File(oldPath); + if (oldfile.exists()) { // �ļ�����ʱ + if (flag == false) { + delFiles(newPath); + } + if (new File(newPath).exists() && flag == true) { + return; + } + newFile(newPath); + FileInputStream fis = new FileInputStream(oldPath); // ����ԭ�ļ� + FileOutputStream fos = new FileOutputStream(newPath); + byte[] buffer = new byte[1024]; + while ((byteread = fis.read(buffer)) != -1) { + fos.write(buffer, 0, byteread); + } + fos.close(); + fis.close(); + } else { + throw new FileNotFoundException("the " + oldfile + " is not exits "); + } + + } + + /** + * @param filePathAndName + * String exp c:/fqf.txt + * @param fileContent + * String + * @return boolean + */ + public static boolean delFiles(String filePathAndName) { + + boolean flag = false; + File myDelFile = new File(filePathAndName); + if (!myDelFile.exists()) + return true; + if (myDelFile.isDirectory()) { + File[] fs = myDelFile.listFiles(); + for (int i = 0; i < fs.length; i++) { + if (fs[i].isFile()) + flag = fs[i].delete(); + if (fs[i].isDirectory()) { + flag = delFiles(fs[i].getAbsolutePath()); + flag = fs[i].delete(); + } + } + } + flag = myDelFile.delete(); + return flag; + } + + /** + * create new file + * + * @param filePathAndName + * String + * @return + * @throws IOException + */ + public static File newFile(String fileName) throws IOException { + File file = new File(fileName); + + newFloder(file.getParentFile().toString()); + + if (!file.exists()) { + file.createNewFile(); + } + return file; + } + + /** + * the file down all the hidden files + * + * @author sunny.sun + * */ + public static List<File> getFiles(String path) { + + List<File> list = new ArrayList<File>(); + File file = new File(path); + if (!file.exists()) { + + file.mkdirs(); + } + + File[] files = file.listFiles(); + for (int i = 0; i < files.length; i++) { + if (files[i].isFile() && !files[i].isHidden()) { + list.add(files[i]); + } + if (files[i].isDirectory() && !files[i].isHidden()) { + List<File> list2 = getFiles(files[i].getPath());// use myself + list.addAll(list2); + } + } + return list; + } + + /** + * causes the os of this computer is Windows + * + * @author sunny.sun + * */ + public static boolean isWindows() { + + String os = System.getProperty("os.name").toLowerCase(); + // windows + return (os.indexOf("win") >= 0); + + } + + public static void copy(String oldfile, String newfile, boolean flag) + throws Exception { + File oldf = new File(oldfile); + File newf = new File(newfile); + boolean oisd = (oldfile.endsWith("/") || oldfile.endsWith("\\")); + boolean nisd = (newfile.endsWith("/") || newfile.endsWith("\\")); + + // Դ�ļ������� + if (!oldf.exists()) { + throw new Exception("the from data is not exists "); + } + // ����ļ����У������� + if (oldf.exists() && !newf.exists()) { + if (newfile.endsWith("/") || newfile.endsWith("\\")) { + newFloder(newfile); + } else { + newFile(newfile); + } + } + // Ŀ�����ļ�����Դ���ļ��� + if (oldf.exists() && oisd && !nisd) { + throw new Exception( + "the from data is directory,but the to data is a file"); + } + // Դ�Ǹ��ļ�,Ŀ�����ļ� + if (!oisd && !nisd) { + copyFile(oldf.getAbsolutePath(), newf.getAbsolutePath(), flag); + } + // Դ�Ǹ��ļ��У�Ŀ�����ļ��� + if (oisd && nisd) { + newFloder(newf.getAbsolutePath()); + List<File> list = getFiles(oldf.getAbsolutePath()); + for (int i = 0; i < list.size(); i++) { + copyFile(list.get(i).getAbsolutePath(), newf.getAbsolutePath() + + "/" + list.get(i).getName(), flag); + } + } + // Դ�Ǹ��ļ���Ŀ���Ǹ��ļ��� + if (!oisd && nisd) { + newFloder(newf.getAbsolutePath()); + copyFile(oldf.getAbsolutePath(), newf.getAbsolutePath() + "/" + + oldf.getName(), flag); + } + + } + + /** + * causes the os of this computer is mac + * + * @author sunny.sun + * */ + public static boolean isMac() { + + String os = System.getProperty("os.name").toLowerCase(); + // Mac + return (os.indexOf("mac") >= 0); + + } + + /** + * causes the os of this computer is unix + * + * @author sunny.sun + * */ + public static boolean isUnix() { + + String os = System.getProperty("os.name").toLowerCase(); + // linux or unix + return (os.indexOf("nix") >= 0 || os.indexOf("nux") >= 0); + + } + + /** + * @param file + * @return + * @throws Exception + */ + public static boolean isUsed(String file) throws Exception { + File f = new File(file); + if (!f.exists()) { + throw new Exception("the file is not exists .."); + } + File f1 = new File(file + ".temp"); + f.renameTo(f1); + if (f.exists()) { + return true; + } else { + f1.renameTo(f); + return false; + } + + } + /** + * Remove the file name's extension (only remove the last) + * <br/> + * + * @param file + * @return + * @since NFVO 0.5 + */ + public static String getBaseFileName(File file){ + if(file.getName().lastIndexOf(".") > 0){ + return file.getName().substring(0,file.getName().lastIndexOf(".")); + }else{ + return file.getName(); + } + + } + + /** + * fix file path to linux seperate,and remove the head and end slash + * <br/> + * + * @param path + * @return + * @since NFVO 0.5 + */ + public static String fixPath(String path){ + String newPath = path; + if(path == null){ + return newPath; + } + newPath = newPath.replaceAll("\\\\", "/"); + if(newPath.startsWith("/")){ + newPath = newPath.substring(1, newPath.length()); + } + if(newPath.endsWith("/")){ + newPath = newPath.substring(0, newPath.length()-1); + } + return newPath; + } + + /** + * fix file path to linux seperate,and add the head and end slash + * <br/> + * + * @param path + * @return + * @since NFVO 0.5 + */ + public static String getFriendlyPath(String path){ + String newPath = path; + if(path == null){ + return newPath; + } + newPath = newPath.replaceAll("\\\\", "/"); + if(!newPath.startsWith("/")){ + newPath = "/"+newPath; + } + if(!newPath.endsWith("/")){ + newPath = newPath + "/"; + } + return newPath; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/JujuConfigUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/JujuConfigUtil.java new file mode 100644 index 0000000..26ef602 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/JujuConfigUtil.java @@ -0,0 +1,49 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import java.util.ResourceBundle; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class JujuConfigUtil { + + private static ResourceBundle bundle = ResourceBundle.getBundle("juju-config"); + + private JujuConfigUtil() { + // private constructor + } + + /** + * read the juju-config.properties file + * <br/> + * + * @param key + * @return + * @since NFVO 0.5 + */ + public static String getValue(String key){ + return bundle.getString(key); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/LocalComandUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/LocalComandUtils.java new file mode 100644 index 0000000..31886e4 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/LocalComandUtils.java @@ -0,0 +1,263 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import java.io.File; +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeoutException; + +import org.apache.commons.lang3.StringUtils; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * For execute local command + * (support control overtime) + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Sep 19, 2016 + */ +public class LocalComandUtils { + private LocalComandUtils(){ + + } + + private static final Logger log = LoggerFactory.getLogger(LocalComandUtils.class); + + + /** + * <br> + * + * @param command + * @return String + */ + public static String formatCommand(List<String> command) { + StringBuilder builder = new StringBuilder(); + if(command != null) { + for(String cmd : command) { + builder.append(cmd).append(" "); // NOSONAR + } + } + return builder.toString(); + + } + + /** + * <br> + * + * @param dir + * @param command + * @return + */ + public static ExeRes execute(String dir, String... command) { + List<String> commands = new ArrayList<>(command.length); + for(String arg : command) { + commands.add(arg); + } + return execute(dir, commands); + + } + + /** + * execute local command + * <br/> + * + * @param dir the command path + * @param command + * @param timeout millis + * @return response msg + * @since NFVO 0.5 + */ + public static ExeRes execute(String dir, List<String> command,long timeout) { + ExeRes er = new ExeRes(); + StringBuilder sb = new StringBuilder(); + try { + if(SwitchController.isDebugModel()) { + command.set(0, "juju.bat"); + } + ProcessBuilder pb = new ProcessBuilder(command); + if(StringUtils.isNotBlank(dir)) { + pb.directory(new File(dir)); + } + pb.redirectErrorStream(true); + Process p = pb.start(); + + // wait the process result + buildProcessResult(er, p, timeout); + + InputStream in = p.getInputStream(); + byte[] buffer = new byte[1024]; + int length; + while((length = in.read(buffer)) > 0) { + sb.append(new String(buffer, 0, length)); + } + in.close(); + er.setBody(sb.toString()); + } catch(Exception e) { + er.setCode(ExeRes.FAILURE); + er.setBody(e.getMessage()); + log.error("execute the command failed:{}", command, e); + } + return er; + } + + /** + * execute local command + * <br/> + * + * @param dir the command path + * @param command + * @return response msg + * @since NFVO 0.5 + */ + public static ExeRes execute(String dir, List<String> command) { + return execute(dir,command,Constant.PROCESS_WAIT_MILLIS); + } + + /** + * <br/> + * + * @param er + * @param p + * @param timeout millis + * @throws TimeoutException + * @throws InterruptedException + * @since NFVO 0.5 + */ + private static void buildProcessResult(ExeRes er, Process p,long timeout) throws TimeoutException, InterruptedException { + Worker worker = new Worker(p); + worker.start(); + try { + worker.join(timeout); + if(worker.exitValue != null) { + int exit = worker.exitValue; + if(exit != 0) { + er.setCode(ExeRes.FAILURE); + log.warn("the process exit non-normal"); + } else { + er.setCode(ExeRes.SUCCESS); + } + } else { + er.setCode(ExeRes.FAILURE); + log.warn("the process execute timeout."); + throw new TimeoutException(); + } + } catch(InterruptedException e) { + worker.interrupt(); + Thread.currentThread().interrupt(); + throw e; + } + } + + /** + * + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Sep 19, 2016 + */ + private static class Worker extends Thread { + + private final Process process; + + private Integer exitValue; + + private Worker(Process process) { + this.process = process; + } + + /** + * <br/> + * + * @since NFVO 0.5 + */ + @Override + public void run() { + try { + exitValue = process.waitFor(); + } catch(InterruptedException e) { + return; + } + } + + } + + /** + * <br> + * <p> + * </p> + * + * @author + */ + public static class ExeRes { + + public static final int SUCCESS = 0; + + public static final int FAILURE = -1; + + private int code; + + private String body; + + /** + * @return Returns the code. + */ + public int getCode() { + return code; + } + + /** + * @param code The code to set. + */ + public void setCode(int code) { + this.code = code; + } + + /** + * @return Returns the body. + */ + public String getBody() { + return body; + } + + /** + * @param body The body to set. + */ + public void setBody(String body) { + this.body = body; + } + + @Override + public String toString() { + try { + return EntityUtils.toString(this, this.getClass()); + } catch(Exception e) { + log.error("to string error:", e); + return "code:" + this.getCode() + ",body:" + this.getBody(); + } + } + + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/ResourceUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/ResourceUtil.java new file mode 100644 index 0000000..ccfa31a --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/ResourceUtil.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +/** + * + * Resource utility class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class ResourceUtil { + + private ResourceUtil() { + + } + + /** + * + * Get message.<br> + * + * @param key + * @return + * @since NFVO 0.5 + */ + public static String getMessage(String key) { + return key; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/SpringContextHolder.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/SpringContextHolder.java new file mode 100644 index 0000000..118f3e4 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/SpringContextHolder.java @@ -0,0 +1,107 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; + +/** + * + * Spring context holder class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class SpringContextHolder implements ApplicationContextAware { + + private static final Logger LOG = LoggerFactory.getLogger(SpringContextHolder.class); + + private static ApplicationContext appContext; + + /** + * application context<br/> + * + * @param applicationContext + */ + @Override + public void setApplicationContext(ApplicationContext applicationContext) { + setAppContext(applicationContext); + } + + /** + * <br> + * + * @return applicationContext + */ + public static ApplicationContext getApplicationContext() { + checkApplicationContext(); + return appContext; + } + + /** + * + * Get spring bean.<br> + * + * @param name + * @return + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public static <T> T getSpringBean(String name) { + checkApplicationContext(); + return (T)appContext.getBean(name); + } + + /** + * + * Get spring bean.<br> + * + * @param requiredType + * @return + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public static <T> T getSpringBean(Class<T> requiredType) { + checkApplicationContext(); + return (T)appContext.getBeansOfType(requiredType); + } + + private static void checkApplicationContext() { + if(appContext == null) { + LOG.error("spring appContext do not insert."); + throw new IllegalStateException("spring appContext is null."); + } + } + + /** + * + * Clean application context.<br> + * + * @since NFVO 0.5 + */ + public static void cleanApplicationContext() { + appContext = null; + } + + private static void setAppContext(ApplicationContext applicationContext) { + SpringContextHolder.appContext = applicationContext; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/StringUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/StringUtil.java new file mode 100644 index 0000000..0e819d3 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/StringUtil.java @@ -0,0 +1,148 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import java.io.IOException; +import java.io.InputStream; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.io.IOUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; +import net.sf.json.util.JSONTokener; + +/** + * + * String utility class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public final class StringUtil { + + private static final Logger LOG = LoggerFactory.getLogger(StringUtil.class); + + private StringUtil() { + + } + + /** + * + * Check whther the string is valid or not.<br> + * + * @param str + * @return + * @since NFVO 0.5 + */ + public static boolean isValidString(String str) { + return str != null && !"".equals(str.trim()); + } + + /** + * + * Check whether the Url is valid or not.<br> + * + * @param url + * @return + * @since NFVO 0.5 + */ + public static boolean isValidUrl(String url) { + String reg = + "http[s]?://(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)){3}:[0-9]{2,5}"; + Pattern pattern = Pattern.compile(reg); + Matcher matcher = pattern.matcher(url); + return matcher.matches(); + } + + /** + * + * Get the JSON string from input http context.<br> + * + * @param vnfReq + * @return + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public static <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + try { + InputStream vnfInput = vnfReq.getInputStream(); + String vnfJsonStr = IOUtils.toString(vnfInput); + JSONTokener vnfJsonTokener = new JSONTokener(vnfJsonStr); + + if(vnfJsonTokener.nextClean() == Character.codePointAt("{", 0)) { + return (T)JSONObject.fromObject(vnfJsonStr); + } + + vnfJsonTokener.back(); + + if(vnfJsonTokener.nextClean() == Character.codePointAt("[", 0)) { + return (T)JSONArray.fromObject(vnfJsonStr); + } + } catch(IOException e) { + LOG.error("function=getJsonFromContext, msg=IOException occurs, e={}.", e); + } catch(JSONException e) { + LOG.error("function=getJsonFromContext, msg=JSONException occurs, e={}.", e); + } + + return null; + } + + /** + * + * Translate sites to site array.<br> + * + * @param sites + * @return + * @since NFVO 0.5 + */ + public static JSONArray transSitesToArray(String sites) { + String[] siteList = sites.split("&"); + int siteSize = siteList.length; + JSONArray siteArray = new JSONArray(); + for(int i = 0; i < siteSize; i++) { + siteArray.add(siteList[i]); + } + + return siteArray; + } + + /** + * + * Check whether the string is valid or not.<br> + * + * @param fields + * @return + * @since NFVO 0.5 + */ + public static boolean isValidAnyString(String... fields) { + for(String str : fields) { + if(!isValidString(str)) { + return false; + } + } + return true; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/SwitchController.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/SwitchController.java new file mode 100644 index 0000000..dbcdcf5 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/SwitchController.java @@ -0,0 +1,55 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.common; + +/** + * <br/> + * <p> + * to assist debug + * </p> + * + * @author + * @version NFVO 0.5 Sep 13, 2016 + */ +public class SwitchController { + + /** + * turn debug model + */ + private static boolean debugModel = false; + public static String vnfmServiceUrl = null; + + public SwitchController() { //NOSONAR + //Constructor + } + + /** + * @return Returns the debugModel. + */ + public static boolean isDebugModel() { + return debugModel; + } + + + /** + * @param debugModel The debugModel to set. + */ + public static void setDebugModel(boolean debugModel) { + SwitchController.debugModel = debugModel; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/UnCompressUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/UnCompressUtil.java new file mode 100644 index 0000000..eda6b78 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/UnCompressUtil.java @@ -0,0 +1,301 @@ +/* + * Copyright (c) 2016, 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.nfvo.jujuvnfmadapter.common; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.zip.GZIPInputStream; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import org.apache.commons.compress.archivers.ArchiveInputStream; +import org.apache.commons.compress.archivers.ArchiveStreamFactory; +import org.apache.commons.compress.archivers.tar.TarArchiveEntry; +import org.apache.commons.compress.compressors.CompressorStreamFactory; +import org.apache.commons.compress.compressors.xz.XZCompressorInputStream; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Oct 28, 2016 + */ +public class UnCompressUtil { + + private static Logger log = LoggerFactory.getLogger(UnCompressUtil.class); + + public static Map<String, String> archiveMap = new HashMap<String, String>(); + + public static Map<String, String> compressorMap = new HashMap<String, String>(); + + static { + // archive type + archiveMap.put(ArchiveStreamFactory.AR, ArchiveStreamFactory.AR); + archiveMap.put(ArchiveStreamFactory.ARJ, ArchiveStreamFactory.ARJ); + archiveMap.put(ArchiveStreamFactory.CPIO, ArchiveStreamFactory.CPIO); + archiveMap.put(ArchiveStreamFactory.DUMP, ArchiveStreamFactory.DUMP); + archiveMap.put(ArchiveStreamFactory.JAR, ArchiveStreamFactory.JAR); + archiveMap.put(ArchiveStreamFactory.SEVEN_Z, ArchiveStreamFactory.SEVEN_Z); + archiveMap.put(ArchiveStreamFactory.TAR, ArchiveStreamFactory.TAR); + archiveMap.put(ArchiveStreamFactory.ZIP, ArchiveStreamFactory.ZIP); + + // compressor type + compressorMap.put(CompressorStreamFactory.BZIP2, CompressorStreamFactory.BZIP2); + compressorMap.put(CompressorStreamFactory.DEFLATE, CompressorStreamFactory.DEFLATE); + compressorMap.put(CompressorStreamFactory.GZIP, CompressorStreamFactory.GZIP); + compressorMap.put(CompressorStreamFactory.LZMA, CompressorStreamFactory.LZMA); + compressorMap.put(CompressorStreamFactory.PACK200, CompressorStreamFactory.PACK200); + compressorMap.put(CompressorStreamFactory.SNAPPY_FRAMED, CompressorStreamFactory.SNAPPY_FRAMED); + compressorMap.put(CompressorStreamFactory.SNAPPY_RAW, CompressorStreamFactory.SNAPPY_RAW); + compressorMap.put(CompressorStreamFactory.XZ, CompressorStreamFactory.XZ); + compressorMap.put(CompressorStreamFactory.Z, CompressorStreamFactory.Z); + } + + /** + * tar.gz + * <br/> + * + * @param zipfileName + * @param outputDirectory + * @param fileNames + * @return + * @since NFVO 0.5 + */ + public static boolean unCompressGzip(String zipfileName, String outputDirectory, List<String> fileNames) { + FileInputStream fis = null; + ArchiveInputStream in = null; + BufferedInputStream bis = null; + try { + fis = new FileInputStream(zipfileName); + GZIPInputStream gis = new GZIPInputStream(new BufferedInputStream(fis)); + in = new ArchiveStreamFactory().createArchiveInputStream("tar", gis); + bis = new BufferedInputStream(in); + TarArchiveEntry entry = (TarArchiveEntry)in.getNextEntry(); + while(entry != null) { + String name = entry.getName(); + String[] names = name.split("/"); + String fileName = outputDirectory; + for(int i = 0; i < names.length; i++) { + String str = names[i]; + fileName = fileName + File.separator + str; + } + if(name.endsWith("/")) { + FileUtils.mkDirs(fileName); + } else { + File file = getRealFileName(outputDirectory, name); + if(null != fileNames) { + fileNames.add(file.getName()); + } + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); + int b = -1; + while((b = bis.read()) != -1) { + bos.write(b); + } + log.debug("ungzip to:" + file.getCanonicalPath()); + bos.flush(); + bos.close(); + } + entry = (TarArchiveEntry)in.getNextEntry(); + } + return true; + } catch(Exception e) { + log.error("UnCompressGZip faield:", e); + return false; + } finally { + try { + if(null != bis) { + bis.close(); + } + } catch(IOException e) { + log.error("UnCompressGZip faield:", e); + } + } + } + + public static void unCompressAllZip(String sourcePath, String targetPath) throws FileNotFoundException { + for(File file : FileUtils.listFiles(new File(sourcePath))) { + unCompressZip(file.getAbsolutePath(), + targetPath + File.separator + file.getName().substring(0, file.getName().lastIndexOf(".")),new ArrayList<String>()); + } + } + + /** + * zip + * <br/> + * + * @param sourceFile unzipPath + * @param targetPath zippath + * @param fileNames + * @since NFVO 0.5 + */ + public static boolean unCompressZip(String sourceFile, String targetPath,List<String> fileNames) { + try { + BufferedOutputStream dest = null; + FileInputStream fis = new FileInputStream(sourceFile); + ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis)); + ZipEntry entry = null; + while((entry = zis.getNextEntry()) != null) { + String name = entry.getName(); + String[] names = name.split("/"); + String fileName = targetPath; + for(int i = 0; i < names.length; i++) { + String str = names[i]; + fileName = fileName + File.separator + str; + } + if(name.endsWith("/")) { + FileUtils.mkDirs(fileName); + } else { + int count; + byte data[] = new byte[2048]; + File file = getRealFileName(targetPath, name); + fileNames.add(file.getName()); + dest = new BufferedOutputStream(new FileOutputStream(file)); + + while((count = zis.read(data, 0, 2048)) != -1) { + dest.write(data, 0, count); + } + log.debug("unzip to:" + file.getCanonicalPath()); + dest.flush(); + dest.close(); + } + } + zis.close(); + return true; + } catch(Exception e) { + log.error("UnCompressZip faield:", e); + } + return false; + } + + private static File getRealFileName(String zippath, String absFileName) { + String[] dirs = absFileName.split("/", absFileName.length()); + + File ret = new File(zippath); + + if(dirs.length > 1) { + for(int i = 0; i < dirs.length - 1; i++) { + ret = new File(ret, dirs[i]); + } + } + + if(!ret.exists()) { + ret.mkdirs(); + } + + ret = new File(ret, dirs[dirs.length - 1]); + + return ret; + } + + /** + * tar.xz + * <br/> + * + * @param zipfileName + * @param outputDirectory + * @param fileNames + * @return + * @since NFVO 0.5 + */ + public static boolean unCompressTarXZ(String zipfileName, String outputDirectory, List<String> fileNames) { + ArchiveInputStream in = null; + BufferedInputStream bis = null; + try { + XZCompressorInputStream xzis = + new XZCompressorInputStream(new BufferedInputStream(new FileInputStream(zipfileName))); + in = new ArchiveStreamFactory().createArchiveInputStream("tar", xzis); + bis = new BufferedInputStream(in); + TarArchiveEntry entry = (TarArchiveEntry)in.getNextEntry(); + while(entry != null) { + String name = entry.getName(); + String[] names = name.split("/"); + String fileName = outputDirectory; + for(int i = 0; i < names.length; i++) { + String str = names[i]; + fileName = fileName + File.separator + str; + } + if(name.endsWith("/")) { + FileUtils.mkDirs(fileName); + } else { + File file = getRealFileName(outputDirectory, name); + if(null != fileNames) { + fileNames.add(file.getName()); + } + BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file)); + int b = -1; + while((b = bis.read()) != -1) { + bos.write(b); + } + log.debug("ungzip to:" + file.getCanonicalPath()); + bos.flush(); + bos.close(); + } + entry = (TarArchiveEntry)in.getNextEntry(); + } + return true; + } catch(Exception e) { + log.error("unCompressTarXZ faield:", e); + } finally { + try { + if(null != bis) { + bis.close(); + } + } catch(IOException e) { + log.error("unCompressTarXZ faield:", e); + } + } + return false; + } + + /** + * only support .zip/.tar.gz/.tar.xz + * <br/> + * + * @param zipfileName + * @param outputDirectory + * @param fileNames + * @return + * @since NFVO 0.5 + */ + public static boolean unCompress(String zipfileName, String outputDirectory, List<String> fileNames) { + if(zipfileName.endsWith(".zip")){ + return unCompressZip(zipfileName,outputDirectory,fileNames); + }else if(zipfileName.endsWith(".tar.gz")){ + return unCompressGzip(zipfileName,outputDirectory,fileNames); + }else if(zipfileName.endsWith(".tar.xz")){ + return unCompressTarXZ(zipfileName,outputDirectory,fileNames); + }else{ + log.error("not supprot file type:->"+zipfileName); + return false; + } + } + + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VNFJsonUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VNFJsonUtil.java new file mode 100644 index 0000000..57e7202 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VNFJsonUtil.java @@ -0,0 +1,420 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import java.io.IOException; +import java.io.InputStream; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.io.IOUtils; +import org.codehaus.jackson.map.ObjectMapper; +import org.codehaus.jackson.type.TypeReference; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.ezmorph.object.DateMorpher; +import net.sf.json.JSON; +import net.sf.json.JSONArray; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; +import net.sf.json.JsonConfig; +import net.sf.json.processors.JsonValueProcessor; +import net.sf.json.util.CycleDetectionStrategy; +import net.sf.json.util.JSONTokener; +import net.sf.json.util.JSONUtils; + +/** + * + * Virtual Network Function Json Utility class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public final class VNFJsonUtil { + + private static final Logger LOG = LoggerFactory.getLogger(VNFJsonUtil.class); + + private static final ObjectMapper VNFMAPPER = new ObjectMapper(); + + private static final String ERROR = "error"; + static { + VNFMAPPER.setDeserializationConfig(VNFMAPPER.getDeserializationConfig() + .without(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES)); + } + + private VNFJsonUtil() { + } + + /** + * + * UnMarshal method.<br> + * + * @param vnfJsonstr + * @param type + * @return + * @throws IOException + * @since NFVO 0.5 + */ + public static <T> T unMarshal(String vnfJsonstr, Class<T> type) throws IOException { + return VNFMAPPER.readValue(vnfJsonstr, type); + } + + /** + * + * UnMarshal method.<br> + * + * @param vnfJsonstr + * @param type + * @return + * @throws IOException + * @since NFVO 0.5 + */ + public static <T> T unMarshal(String vnfJsonstr, TypeReference<T> type) throws IOException { + return VNFMAPPER.readValue(vnfJsonstr, type); + } + + /** + * + * Marshal method.<br> + * + * @param srcObj + * @return + * @throws IOException + * @since NFVO 0.5 + */ + public static String marshal(Object srcObj) throws IOException { + if(srcObj instanceof JSON) { + return srcObj.toString(); + } + return VNFMAPPER.writeValueAsString(srcObj); + } + + public static ObjectMapper getMapper() { + return VNFMAPPER; + } + + /** + * + * Get Json field string.<br> + * + * @param vnfJsonObj + * @param fieldName + * @return + * @since NFVO 0.5 + */ + public static String getJsonFieldStr(JSONObject vnfJsonObj, String fieldName) { + if(null == vnfJsonObj || null == vnfJsonObj.get(fieldName) || "null".equals(vnfJsonObj.getString(fieldName))) { + LOG.warn("getJsonFieldStr: VNFJson object field(" + fieldName + ") is null."); + return ""; + } + + return vnfJsonObj.getString(fieldName); + } + + /** + * + * Get Json field integer.<br> + * + * @param vnfJsonObj + * @param fieldName + * @return + * @since NFVO 0.5 + */ + public static Integer getJsonFieldInt(JSONObject vnfJsonObj, String fieldName) { + if(null == vnfJsonObj || null == vnfJsonObj.get(fieldName)) { + LOG.warn("getJsonFieldInt: VNFJson object field(" + fieldName + ") is Null"); + return 0; + } + return vnfJsonObj.getInt(fieldName); + } + + /** + * + * Get Json field long.<br> + * + * @param vnfJsonObj + * @param fieldName + * @return + * @since NFVO 0.5 + */ + public static Long getJsonFieldLong(JSONObject vnfJsonObj, String fieldName) { + if(null == vnfJsonObj || null == vnfJsonObj.get(fieldName)) { + LOG.warn("getJsonFieldLong: VNFJson object field(" + fieldName + ") is null"); + return 0L; + } + return vnfJsonObj.getLong(fieldName); + } + + /** + * + * Parse error information.<br> + * + * @param errorInfo + * @return + * @since NFVO 0.5 + */ + public static String parseErrorInfo(String errorInfo) { + if((errorInfo != null) && (!errorInfo.isEmpty())) { + JSONObject errorInfoJst = JSONObject.fromObject(errorInfo); + if(errorInfoJst.has(ERROR) && errorInfoJst.getJSONObject(ERROR).has("message")) { + return errorInfoJst.getJSONObject(ERROR).getString("message"); + } + } + return "System Error!"; + } + + static { + VNFMAPPER.setDeserializationConfig(VNFMAPPER.getDeserializationConfig() + .without(org.codehaus.jackson.map.DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES)); + } + + /** + * + * Convert VNF Json to objects.<br> + * + * @param vnfJsonString + * @param pojoCalss + * @return + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public static <T> T vnfJsonToObjects(String vnfJsonString, Class<T> pojoCalss) { + JSONObject vnfJsonObject = JSONObject.fromObject(vnfJsonString); + return (T)JSONObject.toBean(vnfJsonObject, pojoCalss); + } + + /** + * + * Convert VNF Json to objects.<br> + * + * @param vnfJsonString + * @param vnfJsonConfig + * @return + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public static <T> T vnfJsonToObjects(String vnfJsonString, JsonConfig vnfJsonConfig) { + JSONObject vnfJsonObject = JSONObject.fromObject(vnfJsonString); + return (T)JSONObject.toBean(vnfJsonObject, vnfJsonConfig); + } + + /** + * + * Convert VNF Json to lists.<br> + * + * @param vnfJsonString + * @param pojoClass + * @return + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public static <T> List<T> vnfJsonToLists(String vnfJsonString, Class<T> pojoClass) { + JSONArray vnfJsonVNFArray = JSONArray.fromObject(vnfJsonString); + JSONObject vnfJsonObject; + List<T> list = new ArrayList<>(20); + for(int i = 0; i < vnfJsonVNFArray.size(); i++) { + vnfJsonObject = vnfJsonVNFArray.getJSONObject(i); + list.add((T)JSONObject.toBean(vnfJsonObject, pojoClass)); + } + return list; + } + + /** + * + * Convert VNF Json to list.<br> + * + * @param vnfJsonString + * @param pojoClass + * @param dataFormat + * @return + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public static <T> List<T> vnfJsonToList(String vnfJsonString, Class<T> pojoClass, String dataFormat) { + JsonConfig vnfJsonConfig = configJson(dataFormat); + JSONArray vnfJsonVNFArray = JSONArray.fromObject(vnfJsonString, vnfJsonConfig); + JSONObject vnfJsonObject; + List<T> list = new ArrayList<>(20); + for(int i = 0; i < vnfJsonVNFArray.size(); i++) { + vnfJsonObject = vnfJsonVNFArray.getJSONObject(i); + list.add((T)JSONObject.toBean(vnfJsonObject, pojoClass)); + } + return list; + } + + /** + * + * Object to json string.<br> + * + * @param javaObj + * @return + * @since NFVO 0.5 + */ + public static String objectToJsonStr(Object javaObj) { + JSONObject vnfJson = JSONObject.fromObject(javaObj); + return vnfJson.toString(); + } + + /** + * + * object to json.<br> + * + * @param javaObj + * @return + * @since NFVO 0.5 + */ + public static JSONObject objectToJson(Object javaObj) { + return JSONObject.fromObject(javaObj); + } + + /** + * + * Object to json.<br> + * + * @param javaObj + * @param vnfJsonConfig + * @return + * @since NFVO 0.5 + */ + public static String objectToJson(Object javaObj, JsonConfig vnfJsonConfig) { + JSONObject vnfJson = JSONObject.fromObject(javaObj, vnfJsonConfig); + return vnfJson.toString(); + } + + /** + * + * Object to json.<br> + * + * @param javaObj + * @param dataFormat + * @return + * @since NFVO 0.5 + */ + public static String objectToJson(Object javaObj, String dataFormat) { + JsonConfig vnfJsonConfig = configJson(dataFormat); + JSONObject vnfJson = JSONObject.fromObject(javaObj, vnfJsonConfig); + return vnfJson.toString(); + + } + + /** + * + * List to json.<br> + * + * @param list + * @return + * @since NFVO 0.5 + */ + public static <T> String listToJson(List<T> list) { + JSONArray vnfJson = JSONArray.fromObject(list); + return vnfJson.toString(); + } + + /** + * + * List to json.<br> + * + * @param list + * @param dataFormat + * @return + * @since NFVO 0.5 + */ + public static <T> String listToJson(List<T> list, String dataFormat) { + JsonConfig vnfJsonConfig = configJson(dataFormat); + JSONArray vnfJson = JSONArray.fromObject(list, vnfJsonConfig); + return vnfJson.toString(); + } + + /** + * + * Config json.<br> + * + * @param datePattern + * @return + * @since NFVO 0.5 + */ + public static JsonConfig configJson(final String datePattern) { + + JSONUtils.getMorpherRegistry().registerMorpher(new DateMorpher(new String[] {datePattern})); + + JsonConfig vnfJsonConfig = new JsonConfig(); + vnfJsonConfig.setIgnoreDefaultExcludes(false); + vnfJsonConfig.setCycleDetectionStrategy(CycleDetectionStrategy.LENIENT); + vnfJsonConfig.registerJsonValueProcessor(Date.class, new JsonValueProcessor() { + @Override + public Object processObjectValue(String key, Object value, JsonConfig vnfJsonConfig) { + if(value instanceof Date) { + return new SimpleDateFormat(datePattern).format((Date)value); + } + return value == null ? null : value.toString(); + } + @Override + public Object processArrayValue(Object value, JsonConfig vnfJsonConfig) { + String[] vnfObj = {}; + SimpleDateFormat vnfSf = new SimpleDateFormat(datePattern); + if(value instanceof Date[]) { + Date[] dates = (Date[])value; + vnfObj = new String[dates.length]; + for(int i = 0; i < dates.length; i++) { + vnfObj[i] = vnfSf.format(dates[i]); + } + } + return vnfObj; + } + }); + return vnfJsonConfig; + } + + /** + * @param context the HttpContext + * @param <T> JSONObject or JSONArray + * @return + */ + @SuppressWarnings("unchecked") + public static <T> T getJsonFromContext(HttpServletRequest context) { + try { + InputStream input = context.getInputStream(); + String vnfJsonStr = IOUtils.toString(input); + JSONTokener vnfVnfJsonTokener = new JSONTokener(vnfJsonStr); + + // "{" + if(vnfVnfJsonTokener.nextClean() == Character.codePointAt("{", 0)) { + return (T)JSONObject.fromObject(vnfJsonStr); + } + + vnfVnfJsonTokener.back(); + + // "[" + if(vnfVnfJsonTokener.nextClean() == Character.codePointAt("[", 0)) { + return (T)JSONArray.fromObject(vnfJsonStr); + } + } catch(IOException e) { + LOG.error("function=getJsonFromContext,msg= IOException occurs. exception=" + e); + } catch(JSONException e) { + LOG.error("function=getJsonFromContext,msg= JSONException occurs, exception=" + e); + } + return null; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmException.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmException.java new file mode 100644 index 0000000..3517442 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmException.java @@ -0,0 +1,84 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +/** + * + * Vnfm exception class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class VnfmException extends Exception { + + private static final long serialVersionUID = 1L; + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @since NFVO 0.5 + */ + public VnfmException() { + super(); + } + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @param message + * @param cause + * @since NFVO 0.5 + */ + public VnfmException(String message, Throwable cause) { + super(message, cause); + } + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @param message + * @since NFVO 0.5 + */ + public VnfmException(String message) { + super(message); + } + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @param cause + * @since NFVO 0.5 + */ + public VnfmException(Throwable cause) { + super(cause); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmUtil.java new file mode 100644 index 0000000..9817156 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmUtil.java @@ -0,0 +1,95 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.constant.UrlConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; +/** + * Provide function of getting vnfmInfo + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public final class VnfmUtil { + + private static final Logger LOG = LoggerFactory.getLogger(VnfmUtil.class); + private VnfmUtil() { + + } + + /** + * Get vnfmInfo by ip + * <br/> + * + * @param vnfmId + * @return + * @since NFVO 0.5 + */ + public static JSONObject getVnfmById(String vnfmId) { + if(SwitchController.isDebugModel()){ + JSONObject json = new JSONObject(); + json.put("vnfmId", vnfmId); + json.put("vnfdId","testVnfdId"); + json.put("vnfPackageId", "testPackageId"); + json.put("version", "1"); + json.put("url",JujuConfigUtil.getValue("jujuvnfm_server_url")); + return json; + } + RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(String.format(UrlConstant.REST_ESRINFO_GET, vnfmId), JujuVnfmRestfulUtil.GET_TYPE, null); + if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) { + return null; + } + LOG.error("funtion=getVnfmById, status={}", rsp.getStatus()); + return JSONObject.fromObject(rsp.getResponseContent()); + } + + /** + * Get vnfmInfo by id + * <br/> + * + * @param ip + * @return + * @since NFVO 0.5 + */ + public static String getVnfmIdByIp(String ip) { + RestfulResponse rsp = + VnfmRestfulUtil.getRemoteResponse(UrlConstant.REST_ESRINFO_GET, VnfmRestfulUtil.TYPE_GET, null); + if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) { + return ""; + } + + JSONArray vnfmList = JSONArray.fromObject(rsp.getResponseContent()); + for(int i = 0; i < vnfmList.size(); i++) { + if(vnfmList.getJSONObject(i).getString("url").contains(ip)) { + return vnfmList.getJSONObject(i).getString("vnfmId"); + } + } + + return ""; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/YamlUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/YamlUtil.java new file mode 100644 index 0000000..52235f2 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/YamlUtil.java @@ -0,0 +1,125 @@ +/* + * Copyright (c) 2016, 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.nfvo.jujuvnfmadapter.common; + +import java.io.*; +import java.util.ArrayList; +import java.util.Map; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.yaml.snakeyaml.Yaml; +import org.yaml.snakeyaml.parser.ParserException; + +import net.sf.json.JSON; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Oct 25, 2016 + */ +public class YamlUtil { + private static Logger log = LoggerFactory.getLogger(YamlUtil.class); + + + + /** + * + * <br/> + * + * @param yamlName + * @return + * @since NFVO 0.5 + */ + public static JSON yamlToJson(String yamlName){ + Object res = parseYaml(yamlName); + if(res instanceof ArrayList){ + return JSONArray.fromObject(res); + } + return JSONObject.fromObject(res); + } + + /** + * + * <br/> + * + * @param yamlName + * @return + * @since NFVO 0.5 + */ + public static String loadYaml(String yamlName){ + String res = null; + try { + Yaml yaml = new Yaml(); + File file =new File(yamlName); + + Object obj = yaml.load(new FileInputStream(file)); + if(obj != null){ + res = obj.toString(); + } + log.debug("yaml-> "+res); + }catch(ParserException e){ + log.error("error format:",e); + }catch(FileNotFoundException e) { + log.error("the yaml file not exist {}",yamlName,e); + } + return res; + } + + /** + * + * <br/> + * + * @param yamlName + * @return + * @since NFVO 0.5 + */ + public static Object parseYaml(String yamlName){ + Object obj = null; + try { + File file =new File(yamlName); + obj = new Yaml().load(new FileInputStream(file)); + }catch(ParserException e){ + log.error("error format:",e); + + }catch(FileNotFoundException e) { + log.error("the yaml file not exist {}",yamlName,e); + } + return obj; + } + + public static void main(String[] args) throws IOException { + + + Map config = new Yaml().loadAs(new FileInputStream("C:\\Users\\z00292420\\Desktop\\juju\\config2.yaml"), Map.class); + Map options = (Map)config.get("options"); + Map name = (Map)options.get("name"); + name.put("default","hello,it's me"); +// new Yaml().dump(config, new FileWriter("C:\\Users\\z00292420\\Desktop\\juju\\config2.yaml")); + String newYaml = new Yaml().dumpAsMap(config); + Writer w = new FileWriter(new File("C:\\Users\\z00292420\\Desktop\\juju")); + w.write(newYaml); + w.flush(); + w.close(); + System.out.println(newYaml); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestHelp.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestHelp.java new file mode 100644 index 0000000..1c0da4f --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestHelp.java @@ -0,0 +1,79 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken; + +import java.util.HashMap; +import java.util.Map; + +import org.openo.baseservice.roa.util.restclient.HttpRest; +import org.openo.baseservice.roa.util.restclient.Restful; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * Http rest help class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class HttpRestHelp { + + public static final String PROTO_HTTP = "http"; + + private static final Logger LOG = LoggerFactory.getLogger(HttpRestHelp.class); + + private static final Map<String, Restful> INSTANCES = new HashMap<>(2); + + private HttpRestHelp() { + // constructor + } + + private static Restful createHttpsRest(String ssloptionfile, String restoptionfile, boolean isHttps) { + + HttpRest rest = new HttpRest(); + setHttpsRestOption(rest, restoptionfile); + return rest; + } + + /** + * + * Get rest instance class.<br> + * + * @param ssloptionfile + * @param restoptionfile + * @param isHttps + * @return + * @since NFVO 0.5 + */ + public static synchronized Restful getRestInstance(String ssloptionfile, String restoptionfile, boolean isHttps) { + Restful rest = INSTANCES.get(PROTO_HTTP); + if(null != rest) { + return rest; + } + rest = createHttpsRest(ssloptionfile, restoptionfile, isHttps); + INSTANCES.put(PROTO_HTTP, rest); + return rest; + } + + private static void setHttpsRestOption(HttpRest httpRest, String restoptfile) { + LOG.info("setHttpsRestOption"); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestfulHelp.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestfulHelp.java new file mode 100644 index 0000000..b1f66e9 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestfulHelp.java @@ -0,0 +1,69 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken; + +import java.util.HashMap; +import java.util.Map; + +import org.openo.baseservice.roa.util.restclient.HttpRest; +import org.openo.baseservice.roa.util.restclient.Restful; + +/** + * + * Http restful help class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class HttpRestfulHelp { + + public static final String PROTO_HTTPS = "https"; + + public static final String PROTO_HTTP = "http"; + + private static final Map<String, Restful> INSTANCES = new HashMap<>(2); + + private HttpRestfulHelp() { + // constructor + } + + /** + * + * Get rest instance.<br> + * + * @param ssloptionfile + * @param restoptionfile + * @return + * @since NFVO 0.5 + */ + public static synchronized Restful getRestInstance(String ssloptionfile, String restoptionfile) { + Restful rest = INSTANCES.get(PROTO_HTTP); + if(rest != null) { + return rest; + } + rest = createHttpsRest(ssloptionfile, restoptionfile); + INSTANCES.put(PROTO_HTTP, rest); + return rest; + } + + private static Restful createHttpsRest(String ssloptionfile, String restoptionfile) { + return new HttpRest(); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/JujuVnfmRestfulUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/JujuVnfmRestfulUtil.java new file mode 100644 index 0000000..238e7ad --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/JujuVnfmRestfulUtil.java @@ -0,0 +1,315 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken; + +import java.util.HashMap; +import java.util.Map; + +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; + +/** + * + * Juju VNFM restful utility class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public final class JujuVnfmRestfulUtil { + + public static final String GET_TYPE = "get"; + + public static final String ADD_TYPE = "add"; + + public static final String POST_TYPE = "post"; + + public static final String PUT_TYPE = "put"; + + public static final String DEL_TYPE = "delete"; + + public static final String METHOD_TYPE = "methodType"; + + public static final int ERROR_STATUS_CODE = -1; + + public static final String CONTENT_TYPE = "Content-type"; + + public static final String APPLICATION = "application/json"; + + public static final String HEADER_AUTH_TOKEN = "X-Auth-Token"; + + private static final Logger LOG = LoggerFactory.getLogger(JujuVnfmRestfulUtil.class); + + private JujuVnfmRestfulUtil() { + // constructor + } + + /** + * + * Get Vim response content.<br> + * + * @param url + * @param restParametes + * @param type + * @return + * @since NFVO 0.5 + */ + public static String getVimResponseContent(String url, RestfulParametes restParametes, String type) { + Map<String, Object> resMap = getVimResponseContent(url, restParametes, null, type); + + return resMap.get("responseContent").toString(); + + } + + /** + * + * Get Vim response content.<br> + * + * @param url + * @param restParametes + * @param opt + * @param type + * @return + * @since NFVO 0.5 + */ + public static Map<String, Object> getVimResponseContent(String url, RestfulParametes restParametes, + RestfulOptions opt, String type) { + Map<String, Object> resMap = new HashMap<>(2); + + try { + Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); + RestfulResponse rsp = null; + if (rest != null) { + if (GET_TYPE.equals(type)) { + rsp = rest.get(url, restParametes, opt); + } else if (ADD_TYPE.equals(type)) { + rsp = rest.post(url, restParametes, opt); + } else if (PUT_TYPE.equals(type)) { + rsp = rest.put(url, restParametes, opt); + } else if (DEL_TYPE.equals(type)) { + rsp = rest.delete(url, restParametes, opt); + } + if (null != rsp) { + resMap.put("responseContent", rsp.getResponseContent()); + resMap.put("statusCode", rsp.getStatus()); + } + } + LOG.info("get response data success!"); + } catch (ServiceException e) { + LOG.error("get response data catch exception {}.", e); + } + + return resMap; + } + + /** + * + * Get Vim response result.<br> + * + * @param url + * @param type + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getVimResponseResult(String url, String type) { + RestfulParametes restParametes = new RestfulParametes(); + return getVimResponseResult(url, restParametes, type); + } + + /** + * + * Get Vim response result.<br> + * + * @param url + * @param restParametes + * @param type + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getVimResponseResult(String url, RestfulParametes restParametes, String type) { + return vimRestfulResponse(url, restParametes, null, type); + } + + /** + * + * Get Vim response.<br> + * + * @param url + * @param restParametes + * @param opt + * @param type + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse vimRestfulResponse(String url, RestfulParametes restParametes, RestfulOptions opt, + String type) { + RestfulResponse rsp = null; + try { + Map<String, String> headerMap = new HashMap<>(2); + headerMap.put(CONTENT_TYPE, APPLICATION); + restParametes.setHeaderMap(headerMap); + Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); + + if (rest != null) { + if (GET_TYPE.equals(type)) { + rsp = rest.get(url, restParametes, opt); + } else if (ADD_TYPE.equals(type)) { + rsp = rest.post(url, restParametes, opt); + } else if (PUT_TYPE.equals(type)) { + rsp = rest.put(url, restParametes, opt); + } else if (DEL_TYPE.equals(type)) { + rsp = rest.delete(url, restParametes, opt); + } + } + LOG.info("get response data success!"); + } catch (ServiceException e) { + LOG.error("get response data catch ServiceException {}.", e); + } + return rsp; + } + + /** + * + * Get remote response.<br> + * + * @param paramsMap + * @param params + * @param domainTokens + * @param isHttps + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens, + boolean isHttps) { + String url = paramsMap.get("url"); + String methodType = paramsMap.get(METHOD_TYPE); + String path = paramsMap.get("path"); + + RestfulResponse rsp = null; + Restful rest = null; + String sslOptionFile = ""; + try { + String restClientFile = "restclient.json"; + + if (isHttps) { + sslOptionFile = "ssl.nfvo.properties"; + + } + + rest = HttpRestHelp.getRestInstance(sslOptionFile, restClientFile, isHttps); + + RestfulOptions opt = new RestfulOptions(); + String[] strs = path.split("(http(s)?://)|:"); + + opt.setHost(strs[1]); + opt.setPort(Integer.parseInt(strs[2])); + + RestfulParametes restfulParametes = new RestfulParametes(); + Map<String, String> headerMap = new HashMap<>(3); + headerMap.put(CONTENT_TYPE, APPLICATION); + headerMap.put(HEADER_AUTH_TOKEN, domainTokens); + restfulParametes.setHeaderMap(headerMap); + restfulParametes.setRawData(params); + + if (rest != null) { + if (GET_TYPE.equalsIgnoreCase(methodType)) { + rsp = rest.get(url, restfulParametes, opt); + } else if (POST_TYPE.equalsIgnoreCase(methodType)) { + rsp = rest.post(url, restfulParametes, opt); + } else if (PUT_TYPE.equalsIgnoreCase(methodType)) { + rsp = rest.put(url, restfulParametes, opt); + } else if (DEL_TYPE.equalsIgnoreCase(methodType)) { + rsp = rest.delete(url, restfulParametes, opt); + } + } + } catch (ServiceException e) { + LOG.error("function=restfulResponse, get restful response catch exception {}", e); + } + return rsp; + } + + /** + * + * Get remote response.<br> + * + * @param paramsMap + * @param params + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params) { + if(null == paramsMap){ + return null; + } + String url = paramsMap.get("url"); + String methodType = paramsMap.get(METHOD_TYPE); + + 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 (GET_TYPE.equalsIgnoreCase(methodType)) { + rsp = rest.get(url, restfulParametes); + } else if (POST_TYPE.equalsIgnoreCase(methodType)) { + rsp = rest.post(url, restfulParametes); + } else if (PUT_TYPE.equalsIgnoreCase(methodType)) { + rsp = rest.put(url, restfulParametes); + } else if (DEL_TYPE.equalsIgnoreCase(methodType)) { + rsp = rest.delete(url, restfulParametes); + } + } + } catch (ServiceException e) { + LOG.error("function=getRemoteResponse, get restful response catch exception {}", e); + } + return rsp; + } + + /** + * + * Generate parameter map.<br> + * + * @param url + * @param methodType + * @param path + * @param authMode + * @return + * @since NFVO 0.5 + */ + public static Map<String, String> generateParametesMap(String url, String methodType, String path, + String authMode) { + Map<String, String> paramsMap = new HashMap<>(6); + paramsMap.put("url", url); + paramsMap.put(METHOD_TYPE, methodType); + paramsMap.put("path", path); + paramsMap.put("authMode", authMode); + return paramsMap; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFAuthConfigInfo.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFAuthConfigInfo.java new file mode 100644 index 0000000..4e7c13e --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFAuthConfigInfo.java @@ -0,0 +1,147 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * Vnf Authentication configuration information class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class VNFAuthConfigInfo { + + private static final Logger LOG = LoggerFactory.getLogger(VNFAuthConfigInfo.class); + + private static final String AUTH_CONFIG_FILE = "identity.VNFProperties"; + + private static VNFAuthConfigInfo authConfig = new VNFAuthConfigInfo(); + + private static long lastModify = 0L; + + private String vnfUserName; + + private String vnfEncryptedPW; + + private String vnfDomain; + + private String vnfResourceDomain; + + private String defaultDomain; + + private VNFAuthConfigInfo() { + Properties vnfProp = new Properties(); + InputStream authIn = null; + + try { + if(isVNFProModified(getAuthCofigPath())) { + authIn = new FileInputStream(getAuthCofigPath()); + + vnfProp.load(authIn); + vnfUserName = vnfProp.getProperty("name"); + vnfEncryptedPW = vnfProp.getProperty("value"); + vnfDomain = vnfProp.getProperty("vnfDomain"); + vnfResourceDomain = vnfProp.getProperty("vnfResourceDomain"); + defaultDomain = vnfProp.getProperty("defaultDomain"); + authIn.close(); + } + + } catch(IOException e) { + LOG.error("loadAuthConfig can't find config file>> e = {}", e); + } finally { + try { + if(authIn != null) { + + authIn.close(); + } + } catch(IOException e) { + LOG.error("loadAuthConfig can't find config file>> e = {}", e); + } + + } + + } + + private String getAuthCofigPath() { + return AUTH_CONFIG_FILE; + } + + public static VNFAuthConfigInfo getInstance() { + return authConfig; + } + + public String getUserName() { + return vnfUserName; + } + + public String getEncryptedPW() { + return vnfEncryptedPW; + } + + public String getDomain() { + return vnfDomain; + } + + public void setUserName(String vnfuserName) { + this.vnfUserName = vnfuserName; + } + + public void setEncryptedPW(String vnfencryptedPW) { + this.vnfEncryptedPW = vnfencryptedPW; + } + + public void setDomain(String vnfDomain) { + this.vnfDomain = vnfDomain; + } + + public String getResourceDomain() { + return vnfResourceDomain; + } + + public void setResourceDomain(String vnfResourceDomain) { + this.vnfResourceDomain = vnfResourceDomain; + } + + public String getDefaultDomain() { + return defaultDomain; + } + + public void setDefaultDomain(String defaultDomain) { + this.defaultDomain = defaultDomain; + } + + private static boolean isVNFProModified(String filename) { + boolean returnValue = false; + File inputFile = new File(filename); + if(inputFile.lastModified() > lastModify) { + lastModify = inputFile.lastModified(); + returnValue = true; + } + return returnValue; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFRestfulUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFRestfulUtil.java new file mode 100644 index 0000000..b7eee2c --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFRestfulUtil.java @@ -0,0 +1,437 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.Restful; +import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback; +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.openo.nfvo.jujuvnfmadapter.common.AsyncCallback; +import org.openo.nfvo.jujuvnfmadapter.common.VnfmException; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * + * VNF Restful utility class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public final class VNFRestfulUtil { + + public static final String TYPE_GET = "get"; + + public static final String TYPE_ADD = "add"; + + public static final String TYPE_POST = "post"; + + public static final String TYPE_PUT = "put"; + + public static final String TYPE_DEL = "delete"; + + public static final int ERROR_STATUS_CODE = -1; + + private static final Logger LOG = LoggerFactory.getLogger(VNFRestfulUtil.class); + + private VNFRestfulUtil() { + + } + + /** + * + * within our module, we support a default method to invoke.<br> + * + * @param path, rest service url + * @param methodNames, [post, delete, put, get, asyncPost, asyncDelete, asyncPut,asyncGet] + * @param bodyParam, rest body msg + * @return + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public static RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulParametes restParametes = new RestfulParametes(); + Map<String, String> headerMap = new HashMap<>(2); + headerMap.put(Constant.CONTENT_TYPE, Constant.APPLICATION); + restParametes.setHeaderMap(headerMap); + + if(Constant.GET.equals(methodNames) || Constant.DELETE.equals(methodNames)) { + if(null != bodyParam) { + Map<String, String> vnfparamsMap = new HashMap<>(Constant.DEFAULT_COLLECTION_SIZE); + if(path.contains("?")) { + String[] vnfUtlList = path.split("\\?"); + String[] vnfParams = vnfUtlList[1].split("&"); + int paramsSize = vnfParams.length; + + for(int i = 0; i < paramsSize; i++) { + vnfparamsMap.put(vnfParams[i].split("=")[0], vnfParams[i].split("=")[1]); + } + } + + String vnfParamKey; + Iterator<String> nameItr = bodyParam.keys(); + while(nameItr.hasNext()) { + vnfParamKey = nameItr.next(); + vnfparamsMap.put(vnfParamKey, bodyParam.get(vnfParamKey).toString()); + + } + LOG.warn("method is GET or DEL,and paramsMap = " + vnfparamsMap); + restParametes.setParamMap(vnfparamsMap); + } + } else { + restParametes.setRawData(bodyParam == null ? null : bodyParam.toString()); + } + return getRestRes(methodNames, path, restParametes); + } + + /** + * send restful notification to other module + * + * @param path + * service url + * @param methodName + * [post, delete, put, get, asyncPost, asyncDelete, asyncPut, + * asyncGet] + * @param bodyParam + * rest body msg + */ + public static void sentEvtByRest(String path, String methodName, JSONObject bodyParam) { + RestfulParametes restParametes = new RestfulParametes(); + Map<String, String> headerMap = new HashMap<>(2); + headerMap.put(Constant.CONTENT_TYPE, Constant.APPLICATION); + restParametes.setHeaderMap(headerMap); + restParametes.setRawData(bodyParam == null ? null : bodyParam.toString()); + getRestRes(methodName, path, restParametes, new AsyncCallback()); + } + + /** + * encapsulate the java reflect exception + * + * @param methodName + * Restful's method + * @param objects + * method param array + * @return + */ + private static boolean isAnyNull(Object... objects) { + for(int i = 0; i < objects.length; i++) { + if(objects[i] == null) { + return true; + } + } + return false; + + } + + private static Class<?>[] formArray(Object[] objects) { + Class<?>[] vnfClasses = new Class[objects.length]; + for(int i = 0; i < objects.length; i++) { + vnfClasses[i] = objects[i].getClass(); + } + return vnfClasses; + + } + + /** + * + * Get restful resource.<br> + * + * @param methodName + * @param objects + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRestRes(String methodName, Object... objects) { + Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); + try { + if(isAnyNull(objects, rest)) { + return null; + } + + Class<?>[] vnfClasses = formArray(objects); + + if(methodName.startsWith("async")) { + vnfClasses[vnfClasses.length - 1] = RestfulAsyncCallback.class; + } + + Class<?> rtType = methodName.startsWith("async") ? void.class : RestfulResponse.class; + MethodType mt = MethodType.methodType(rtType, vnfClasses); + Object reuslt = MethodHandles.lookup().findVirtual(rest.getClass(), methodName, mt).bindTo(rest) + .invokeWithArguments(objects); + if(reuslt != null) { + return (RestfulResponse)reuslt; + } + LOG.warn("function=getRestRes, msg: invoke Restful async {} method which return type is Void.", methodName); + return null; + } catch(ReflectiveOperationException e) { + LOG.error("function=getRestRes, msg=error occurs, e={}.", e); + } catch(ServiceException e) { + + LOG.error("function=getRestRes, msg=ServiceException occurs, status={}", e.getHttpCode()); + LOG.error("function=getRestRes, msg=ServiceException occurs, reason={}.", e.getCause().getMessage()); + LOG.error("function=getRestRes, msg=ServiceException occurs, e={}.", e); + RestfulResponse response = new RestfulResponse(); + response.setStatus(e.getHttpCode()); + response.setResponseJson(e.getCause().getMessage()); + return response; + + } catch(Throwable e) {//NOSONAR + try { + throw (VnfmException)new VnfmException().initCause(e.getCause()); + } catch(VnfmException e1) { + LOG.error("function=getRestRes, msg=VnfmException occurs, e={},e1={}.", e1, e); + } + + } + return null; + } + + /** + * + * Send request to application.<br> + * + * @param path + * @param methodName + * @param paraJson + * @return + * @since NFVO 0.5 + */ + public static JSONObject sendReqToApp(String path, String methodName, JSONObject paraJson) { + JSONObject retJson = new JSONObject(); + retJson.put(Constant.RETURN_CODE, Constant.REST_FAIL); + String abPath = null; + String vnfmId = null; + if(paraJson != null && paraJson.containsKey("vnfmInfo")) { + JSONObject vnfmObj = paraJson.getJSONObject("vnfmInfo"); + vnfmId = vnfmObj.getString("id"); + } else { + abPath = path; + } + LOG.warn("function=sendReqToApp, msg=url to send to app is: " + abPath); + + RestfulResponse restfulResponse = VNFRestfulUtil.getRestResByDefault(path, methodName, paraJson); + if(restfulResponse == null || abPath == null) { + LOG.error("function=sendReqToApp, msg=data from app is null"); + retJson.put("data", "get null result"); + } else if(restfulResponse.getStatus() == Constant.HTTP_OK) { + JSONObject object = JSONObject.fromObject(restfulResponse.getResponseContent()); + if(!abPath.contains("vnfdmgr/v1")) { + LOG.warn("function=sendReqToApp, msg=result from app is: " + object.toString()); + } + if(object.getInt(Constant.RETURN_CODE) == Constant.REST_SUCCESS) { + retJson.put(Constant.RETURN_CODE, Constant.REST_SUCCESS); + retJson.put("data", withVnfmIdSuffix(vnfmId, object.get("data"))); + return retJson; + } else { + retJson.put(Constant.RETURN_CODE, Constant.REST_FAIL); + if(object.containsKey("msg")) { + retJson.put("data", object.getString("msg")); + return retJson; + } else { + return object; + } + } + } else { + LOG.error("function=sendReqToApp, msg=status from app is: " + restfulResponse.getStatus()); + LOG.error("function=sendReqToApp, msg=result from app is: " + restfulResponse.getResponseContent()); + retJson.put("data", "send to app get error status: " + restfulResponse.getStatus()); + } + return retJson; + } + + /** + * append suffix to result with vnfmId + * + * @param vnfmId + * @param dataJson + * @return + */ + private static Object withVnfmIdSuffix(String vnfmId, Object dataJson) { + Object result = new Object(); + if(vnfmId == null) { + return dataJson; + } + + if(dataJson instanceof JSONObject) { + JSONObject jsonObject = (JSONObject)dataJson; + jsonObject.put("vnfmId", vnfmId); + result = jsonObject; + } else if(dataJson instanceof JSONArray) { + JSONArray dataArray = (JSONArray)dataJson; + JSONArray resultArray = new JSONArray(); + + for(Object obj : dataArray) { + JSONObject jsonObject = JSONObject.fromObject(obj); + jsonObject.put("vnfmId", vnfmId); + resultArray.add(jsonObject); + } + result = resultArray; + } + return result; + } + + /** + * + * Get remote response.<br> + * + * @param paramsMap + * @param params + * @param domainTokens + * @param isNfvoApp + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens, + boolean isNfvoApp) { + String utilUrl = paramsMap.get("url"); + String utilMethodType = paramsMap.get(Constant.METHOD_TYPE); + String utilPath = paramsMap.get("path"); + String authMode = paramsMap.get(Constant.AUTH_MODE); + + RestfulResponse rsp = null; + Restful rest = null; + String sslOptionFile = ""; + try { + String restClientFile = "restclient.json"; + + if(isNfvoApp) { + sslOptionFile = "ssl.nfvo.properties"; + } else { + sslOptionFile = "ssl.vcmm.properties"; + } + + LOG.warn("function=getRemoteResponse,AuthenticationMode=" + authMode); + + rest = HttpRestfulHelp.getRestInstance(sslOptionFile, restClientFile); + + RestfulOptions opt = new RestfulOptions(); + String[] strs = utilPath.split("(http(s)?://)|:"); + + opt.setHost(strs[1]); + opt.setPort(Integer.parseInt(strs[2])); + + RestfulParametes restfulParametes = new RestfulParametes(); + Map<String, String> headerMap = new HashMap<>(3); + headerMap.put(Constant.CONTENT_TYPE, Constant.APPLICATION); + headerMap.put(Constant.HEADER_AUTH_TOKEN, domainTokens); + restfulParametes.setHeaderMap(headerMap); + restfulParametes.setRawData(params); + + if(rest != null) { + if(TYPE_GET.equalsIgnoreCase(utilMethodType)) { + rsp = rest.get(utilUrl, restfulParametes, opt); + } else if(TYPE_POST.equalsIgnoreCase(utilMethodType)) { + rsp = rest.post(utilUrl, restfulParametes, opt); + } else if(TYPE_PUT.equalsIgnoreCase(utilMethodType)) { + rsp = rest.put(utilUrl, restfulParametes, opt); + } else if(TYPE_DEL.equalsIgnoreCase(utilMethodType)) { + rsp = rest.delete(utilUrl, restfulParametes, opt); + } + } + } catch(ServiceException e) { + LOG.error("function=restfulResponse, get restful response catch exception {}", e); + } + return rsp; + } + + /** + * + * Generate parameters map.<br> + * + * @param url + * @param methodType + * @param path + * @param authMode + * @return + * @since NFVO 0.5 + */ + public static Map<String, String> generateParamsMap(String url, String methodType, String path, String authMode) { + Map<String, String> utilParamsMap = new HashMap<>(6); + utilParamsMap.put("url", url); + utilParamsMap.put("methodType", methodType); + utilParamsMap.put("path", path); + utilParamsMap.put("authMode", authMode); + return utilParamsMap; + } + + /** + * + * Generate parameters map.<br> + * + * @param url + * @param methodType + * @param path + * @return + * @since NFVO 0.5 + */ + public static Map<String, String> generateParamsMap(String url, String methodType, String path) { + Map<String, String> paramsMap = new HashMap<>(6); + paramsMap.put("url", url); + paramsMap.put("methodType", methodType); + paramsMap.put("path", path); + paramsMap.put("authMode", "Certificate"); + return paramsMap; + } + + /** + * + * Get result to vnfm.<br> + * + * @param vnfmInfo + * @param vnfmId + * @return + * @since NFVO 0.5 + */ + public static JSONObject getResultToVnfm(JSONObject vnfmInfo, String vnfmId) { + JSONObject retJson = new JSONObject(); + retJson.put(Constant.RETURN_CODE, Constant.REST_FAIL); + if(vnfmInfo == null) { + LOG.error("function=getResultToVnfm, msg=data from vnfm is null"); + retJson.put("data", "get null result"); + return retJson; + } + + if(vnfmInfo.getInt(Constant.RETURN_CODE) == Constant.REST_SUCCESS) { + retJson.put(Constant.RETURN_CODE, Constant.REST_SUCCESS); + retJson.put("data", withVnfmIdSuffix(vnfmId, vnfmInfo.get("data"))); + return retJson; + } else { + retJson.put(Constant.RETURN_CODE, Constant.REST_FAIL); + if(vnfmInfo.containsKey("msg")) { + retJson.put("data", vnfmInfo.getString("msg")); + return retJson; + } else { + return vnfmInfo; + } + } + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VnfmRestfulUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VnfmRestfulUtil.java new file mode 100644 index 0000000..3e3f793 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VnfmRestfulUtil.java @@ -0,0 +1,401 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken; + +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.Restful; +import org.openo.baseservice.roa.util.restclient.RestfulAsyncCallback; +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.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.nfvo.jujuvnfmadapter.common.VnfmException; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +/** + * <br> + * <p> + * </p> + * + * @author + */ +public final class VnfmRestfulUtil { + + public static final String TYPE_GET = "get"; + + public static final String TYPE_ADD = "add"; + + public static final String TYPE_POST = "post"; + + public static final String TYPE_PUT = "put"; + + public static final String TYPE_DEL = "delete"; + + public static final int ERROR_STATUS_CODE = -1; + + private static final Logger LOG = LoggerFactory.getLogger(VnfmRestfulUtil.class); + + /** + * Constructor<br/> + * <p> + * </p> + * + */ + private VnfmRestfulUtil() { + // Default Constructor + } + + /** + * within our module, we support a default method to invoke + * + * @param path + * rest service url + * @param methodNames + * [post, delete, put, get, asyncPost, asyncDelete, asyncPut, + * asyncGet] + * @param bodyParam + * rest body msg + * @return + */ + @SuppressWarnings("unchecked") + public static RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulParametes restParametes = new RestfulParametes(); + Map<String, String> headerMap = new HashMap<>(2); + headerMap.put(Constant.CONTENT_TYPE, Constant.APPLICATION); + restParametes.setHeaderMap(headerMap); + + if(Constant.GET.equals(methodNames) || Constant.DELETE.equals(methodNames)) { + if(null != bodyParam) { + Map<String, String> vnfParamsMap = new HashMap<>(Constant.DEFAULT_COLLECTION_SIZE); + if(path.contains("?")) { + String[] vnfUtlList = path.split("\\?"); + String[] vnfParams = vnfUtlList[1].split("&"); + int paramsSize = vnfParams.length; + + for(int i = 0; i < paramsSize; i++) { + vnfParamsMap.put(vnfParams[i].split("=")[0], vnfParams[i].split("=")[1]); + } + } + + String vnfParamKey = null; + Iterator<String> nameItr = bodyParam.keys(); + while(nameItr.hasNext()) { + vnfParamKey = nameItr.next(); + vnfParamsMap.put(vnfParamKey, bodyParam.get(vnfParamKey).toString()); + + } + LOG.warn("method is GET or DEL,and paramsMap = " + vnfParamsMap); + restParametes.setParamMap(vnfParamsMap); + } + } else { + restParametes.setRawData(bodyParam == null ? null : bodyParam.toString()); + } + return getRestRes(methodNames, path, restParametes); + } + + /** + * encapsulate the java reflect exception + * + * @param objects + * method param array + * @return + */ + private static boolean isAnyNull(Object... objects) { + for(int i = 0; i < objects.length; i++) { + if(objects[i] == null) { + return true; + } + } + return false; + + } + + private static Class<?>[] formArray(Object[] objects) { + Class<?>[] vnfclasses = new Class[objects.length]; + for(int i = 0; i < objects.length; i++) { + vnfclasses[i] = objects[i].getClass(); + } + return vnfclasses; + + } + + /** + * <br> + * + * @param methodName + * @param objects + * @return + */ + public static RestfulResponse getRestRes(String methodName, Object... objects) { + Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); + try { + if(isAnyNull(objects, rest)) { + return null; + } + + Class<?>[] vnfClasses = formArray(objects); + + if(methodName.startsWith("async")) { + vnfClasses[vnfClasses.length - 1] = RestfulAsyncCallback.class; + } + + Class<?> rtType = methodName.startsWith("async") ? void.class : RestfulResponse.class; + MethodType mt = MethodType.methodType(rtType, vnfClasses); + Object reuslt = MethodHandles.lookup().findVirtual(rest.getClass(), methodName, mt).bindTo(rest) + .invokeWithArguments(objects); + if(reuslt != null) { + return (RestfulResponse)reuslt; + } + LOG.warn("function=getRestRes, msg: invoke Restful async {} method which return type is Void.", methodName); + return null; + } catch(ReflectiveOperationException e) { + LOG.error("function=getRestRes, msg=error occurs, e={}.", e); + } catch(ServiceException e) { + + LOG.error("function=getRestRes, msg=ServiceException occurs, status={}", e.getHttpCode()); + LOG.error("function=getRestRes, msg=ServiceException occurs, reason={}.", e.getCause().getMessage()); + LOG.error("function=getRestRes, msg=ServiceException occurs, e={}.", e); + RestfulResponse response = new RestfulResponse(); + response.setStatus(e.getHttpCode()); + response.setResponseJson(e.getCause().getMessage()); + return response; + + } catch(Throwable e) {//NOSONAR + try { + throw (VnfmException)new VnfmException().initCause(e.getCause()); + } catch(VnfmException e1) { + LOG.error("function=getRestRes, msg=VnfmException occurs, e={},e1={}.", e1, e); + } + + } + return null; + } + + /** + * <br> + * + * @param path + * @param methodName + * @param paraJson + * @return + */ + public static JSONObject sendReqToApp(String path, String methodName, JSONObject paraJson) { + JSONObject retJson = new JSONObject(); + retJson.put(Constant.RETURN_CODE, Constant.REST_FAIL); + String abPath = null; + String vnfmId = null; + if(paraJson != null && paraJson.containsKey("vnfmInfo")) { + JSONObject vnfmObj = paraJson.getJSONObject("vnfmInfo"); + vnfmId = vnfmObj.getString("id"); + } else { + abPath = path; + } + LOG.warn("function=sendReqToApp, msg=url to send to app is: " + abPath); + + RestfulResponse restfulResponse = VnfmRestfulUtil.getRestResByDefault(path, methodName, paraJson); + if(restfulResponse == null || abPath == null) { + LOG.error("function=sendReqToApp, msg=data from app is null"); + retJson.put("data", "get null result"); + } else if(restfulResponse.getStatus() == Constant.HTTP_OK) { + JSONObject object = JSONObject.fromObject(restfulResponse.getResponseContent()); + if(!abPath.contains("vnfdmgr/v1")) { + LOG.warn("function=sendReqToApp, msg=result from app is: " + object.toString()); + } + if(object.getInt(Constant.RETURN_CODE) == Constant.REST_SUCCESS) { + retJson.put(Constant.RETURN_CODE, Constant.REST_SUCCESS); + retJson.put("data", withVnfmIdSuffix(vnfmId, object.get("data"))); + return retJson; + } else { + retJson.put(Constant.RETURN_CODE, Constant.REST_FAIL); + if(object.containsKey("msg")) { + retJson.put("data", object.getString("msg")); + return retJson; + } else { + return object; + } + } + } else { + LOG.error("function=sendReqToApp, msg=status from app is: " + restfulResponse.getStatus()); + LOG.error("function=sendReqToApp, msg=result from app is: " + restfulResponse.getResponseContent()); + retJson.put("data", "send to app get error status: " + restfulResponse.getStatus()); + } + return retJson; + } + + /** + * append suffix to result with vnfmId + * + * @param vnfmId + * @param dataJson + * @return + */ + private static Object withVnfmIdSuffix(String vnfmId, Object dataJson) { + Object result = new Object(); + if(vnfmId == null) { + return dataJson; + } + + if(dataJson instanceof JSONObject) { + JSONObject jsonObject = (JSONObject)dataJson; + jsonObject.put("vnfmId", vnfmId); + result = jsonObject; + } else if(dataJson instanceof JSONArray) { + JSONArray dataArray = (JSONArray)dataJson; + JSONArray resultArray = new JSONArray(); + + for(Object obj : dataArray) { + JSONObject jsonObject = JSONObject.fromObject(obj); + jsonObject.put("vnfmId", vnfmId); + resultArray.add(jsonObject); + } + result = resultArray; + } + return result; + } + /** + * + * Method to get Remote Response.<br/> + * + * @param paramsMap + * @param params + * @param domainTokens + * @param isHttps + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens) { + String path = paramsMap.get("path"); + String methodType = paramsMap.get(Constant.METHOD_TYPE); + String url = paramsMap.get("url"); + + RestfulResponse rsp = null; + Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); + try { + + RestfulOptions opt = new RestfulOptions(); + String[] strs = url.split("(http(s)?://)|:|/"); + + opt.setHost(strs[1]); + if(strs.length > 0){ + opt.setPort(Integer.parseInt(strs[2])); + }else{ + opt.setPort(80); + } + + for(int i=strs.length-1;i>=0;i--){ + if(i > 2){ + path = "/"+strs[i]+path; + } + } + LOG.info("restfull options:"+EntityUtils.toString(opt, RestfulOptions.class)); + RestfulParametes restfulParametes = new RestfulParametes(); + Map<String, String> headerMap = new HashMap<>(3); + headerMap.put(Constant.CONTENT_TYPE, Constant.APPLICATION); + headerMap.put(Constant.HEADER_AUTH_TOKEN, domainTokens); + restfulParametes.setHeaderMap(headerMap); + restfulParametes.setRawData(params); + + if(rest != null) { + if(TYPE_GET.equalsIgnoreCase(methodType)) { + rsp = rest.get(path, restfulParametes, opt); + } else if(TYPE_POST.equalsIgnoreCase(methodType)) { + rsp = rest.post(path, restfulParametes, opt); + } else if(TYPE_PUT.equalsIgnoreCase(methodType)) { + rsp = rest.put(path, restfulParametes, opt); + } else if(TYPE_DEL.equalsIgnoreCase(methodType)) { + rsp = rest.delete(path, restfulParametes, opt); + } + } + } catch(ServiceException e) { + LOG.error("function=getRemoteResponse, get restful response catch exception {}", e); + } + LOG.info("request :{},response:{}",params,EntityUtils.toString(rsp, RestfulResponse.class)); + return rsp; + } + + + /** + * read DEFAULT config + * <br/> + * + * @param url + * @param methodType + * @param params + * @return + * @since NFVO 0.5 + */ + public static RestfulResponse getRemoteResponse(String url, String methodType, String params) { + RestfulResponse rsp = null; + Restful rest = RestfulFactory.getRestInstance(RestfulFactory.PROTO_HTTP); + try { + + RestfulParametes restfulParametes = new RestfulParametes(); + Map<String, String> headerMap = new HashMap<>(3); + headerMap.put(Constant.CONTENT_TYPE, Constant.APPLICATION); + restfulParametes.setHeaderMap(headerMap); + if(params != null) { + 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) { + LOG.error("function=getRemoteResponse, get restful response catch exception {}", e); + } + return rsp; + } + + /** + * <br> + * + * @param url + * @param methodType + * @param path + * @param authMode + * @return Map<String, String> + */ + public static Map<String, String> generateParamsMap(String url, String methodType, String path, String authMode) { + Map<String, String> utilParamsMap = new HashMap<>(6); + utilParamsMap.put("url", url); + utilParamsMap.put(Constant.METHOD_TYPE, methodType); + utilParamsMap.put("path", path); + utilParamsMap.put("authMode", authMode); + return utilParamsMap; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/AccessTokens.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/AccessTokens.java new file mode 100644 index 0000000..edbfd05 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/AccessTokens.java @@ -0,0 +1,136 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken.module; + +import net.sf.json.JSONObject; + +import org.apache.commons.lang3.StringUtils; +import org.openo.nfvo.jujuvnfmadapter.common.VNFJsonUtil; + +/** + * + * Access tokens class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class AccessTokens { + + private String accesTokens; + + private int expire; + + private long createTime; + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @since NFVO 0.5 + */ + public AccessTokens() { + throw new UnsupportedOperationException(); + } + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @param token + * @param ttl + * @since NFVO 0.5 + */ + public AccessTokens(String token, int ttl) { + this.accesTokens = token; + this.expire = ttl; + this.createTime = System.currentTimeMillis(); + } + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @param accessToken + * @param expire + * @param createTime + * @since NFVO 0.5 + */ + public AccessTokens(String accessToken, Integer expire, Long createTime) { + this.accesTokens = accessToken; + this.expire = expire == null ? 0 : expire; + this.createTime = createTime == null ? 0 : createTime; + } + + public String getAccessToken() { + return this.accesTokens; + } + + public void setAccessToken(String token) { + this.accesTokens = token; + } + + public int getExpire() { + return this.expire; + } + + public long getCreateTime() { + return this.createTime; + } + + /** + * + * Check time validity.<br> + * + * @return + * @since NFVO 0.5 + */ + public boolean valid() { + if(this.expire == 0) { + return true; + } + return System.currentTimeMillis() - this.createTime <= 1000L * this.expire; + } + + @Override + public String toString() { + return '{'+ StringUtils.trimToEmpty(this.getAccessToken()) + '\'' + ",'expire': '" + this.getExpire() + '\'' + + ",'createTime': '" + this.getCreateTime() + '\'' + '}'; + } + + /** + * + * To entity.<br> + * + * @param jsonObject + * @return + * @since NFVO 0.5 + */ + public static AccessTokens toEntity(JSONObject jsonObject) { + String token = VNFJsonUtil.getJsonFieldStr(jsonObject, "accessToken"); + Integer expire = VNFJsonUtil.getJsonFieldInt(jsonObject, "expire"); + Long createTime = VNFJsonUtil.getJsonFieldLong(jsonObject, "createTime"); + return new AccessTokens(token, expire, createTime); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/activator/ROAJujuServicePostProcessor.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/activator/ROAJujuServicePostProcessor.java new file mode 100644 index 0000000..3013150 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/activator/ROAJujuServicePostProcessor.java @@ -0,0 +1,61 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.activator; + +import org.openo.nfvo.jujuvnfmadapter.service.api.internalsvc.inf.IJujuAdapterMgrService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.DestructionAwareBeanPostProcessor; +import org.springframework.stereotype.Service; + +/** + * + * ROA juju service post processor class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class ROAJujuServicePostProcessor implements DestructionAwareBeanPostProcessor{ + private static final Logger LOG = LoggerFactory.getLogger(ROAJujuServicePostProcessor.class); + + @Override + public Object postProcessAfterInitialization(Object bean, String name) throws BeansException { + if(bean instanceof IJujuAdapterMgrService){ + IJujuAdapterMgrService jujuAdapterSvc = (IJujuAdapterMgrService)bean; + jujuAdapterSvc.register(); + LOG.info("Successfully Registered to Microservice BUS!", ROAJujuServicePostProcessor.class); + } + + return bean; + } + + @Override + public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException { + // TODO Auto-generated method stub + return bean; + } + + @Override + public void postProcessBeforeDestruction(Object bean, String name) throws BeansException { + // TODO Auto-generated method stub + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/AdapterResourceManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/AdapterResourceManager.java new file mode 100644 index 0000000..5dc8184 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/AdapterResourceManager.java @@ -0,0 +1,302 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.impl; + +import java.io.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.baseservice.util.impl.SystemEnvVariablesFactory; +import org.openo.nfvo.jujuvnfmadapter.common.DownloadCsarManager; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IResourceManager; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.constant.UrlConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import net.sf.json.JSONObject; + +/** + * + * Adapter resource manager class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +@Service +public class AdapterResourceManager implements IResourceManager { + + private static final Logger LOG = LoggerFactory.getLogger(AdapterResourceManager.class); + + + @Override + public JSONObject getJujuVnfmInfo(Map<String, String> paramsMap) { + JSONObject resultObj = new JSONObject(); + //verify url,reserve + + RestfulResponse rsp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap,""); + if(null == rsp) { + LOG.error("function=getJujuVnfmInfo, RestfulResponse is null"); + resultObj.put(Constant.REASON, "RestfulResponse is null."); + resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE); + return resultObj; + } + String resultCreate = rsp.getResponseContent(); + + if(rsp.getStatus() == Constant.HTTP_OK) { + LOG.warn("function=getJujuVnfmInfo, msg= status={}, result={}.", rsp.getStatus(), resultCreate); + resultObj = JSONObject.fromObject(resultCreate); + resultObj.put(Constant.RETURN_CODE, Constant.HTTP_OK); + return resultObj; + } else { + LOG.error("function=getJujuVnfmInfo, msg=ESR return fail,status={}, result={}.", rsp.getStatus(), + resultCreate); + resultObj.put(Constant.REASON, "ESR return fail."); + } + resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE); + return resultObj; + } + + @Override + public JSONObject getVnfdInfo(String csarId) { + JSONObject resultObj = new JSONObject(); + JSONObject csarPkgInfoObj = new JSONObject(); + + if(null == csarId || "".equals(csarId)) { + resultObj.put("reason", "csarId is null."); + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + String downloadUri = this.fetchDownloadUrlFromCatalog(csarId); + if(downloadUri == null){ + LOG.error("fetchDownloadUrlFromCatalog return null,csarId="+csarId); + resultObj.put(Constant.REASON, "fetchDownloadUrlFromCatalog is null."); + resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE); + return resultObj; + } + String csarPkgInfo; + try { + csarPkgInfo = readCsarPkgInfo(); + csarPkgInfoObj = JSONObject.fromObject(csarPkgInfo); //NOSONAR + } catch (IOException e) { + e.printStackTrace(); + } + + String csarfilepath = csarPkgInfoObj.getString("csar_file_path"); + String csarfilename = csarPkgInfoObj.getString("csar_file_name"); + + // download csar package and save in location. + JSONObject downloadObject = downloadCsar(downloadUri, csarfilepath+ System.getProperty("file.separator") +csarfilename); + + if (Integer.valueOf(downloadObject.get("retCode").toString()) != Constant.REST_SUCCESS) { + LOG.error("download CSAR fail.", downloadObject.get("retCode")); + resultObj.put("reason", downloadObject.get("reason").toString()); + resultObj.put("retCode", downloadObject.get("retCode").toString()); + return resultObj; + } + LOG.info("download CSAR successful.", downloadObject.get("retCode")); + + // unzip csar package to location. + JSONObject unzipObject = unzipCSAR(csarfilepath+ System.getProperty("file.separator") +csarfilename, csarfilepath); + + if (Integer.valueOf(unzipObject.get("retCode").toString()) != Constant.REST_SUCCESS) { + LOG.error("unzip CSAR fail.", unzipObject.get("retCode")); + resultObj.put("reason", unzipObject.get("reason").toString()); + resultObj.put("retCode", unzipObject.get("retCode").toString()); + return resultObj; + } + LOG.info("unzip CSAR successful.", unzipObject.get("retCode")); + + resultObj.put(Constant.RETURN_CODE, Constant.HTTP_OK); + resultObj.put("csarFilePath", getImagesPath(csarfilepath)); + + return resultObj; + } + private String getImagesPath(String csarfilepath){ + File imageFile = new File(csarfilepath+"SoftwareImages"); + if(imageFile.exists()){ + File[] charmFiles = imageFile.listFiles(); + for(File file : charmFiles){ + if(!file.getName().endsWith(".zip")){ + return file.getAbsolutePath()+"/"; + } + } + } + return csarfilepath; + } + + public String fetchDownloadUrlFromCatalog(String csarId){ + String downloadUri = null; + try { + Map paramsMap = new HashMap(); + + paramsMap.put("url", String.format(UrlConstant.REST_CSARINFO_GET, csarId)); + paramsMap.put("methodType", Constant.GET); + + RestfulResponse rsp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap,""); + if(null == rsp) { + LOG.error("function=getVnfdInfo, RestfulResponse is null"); + return null; + } + String resultCreate = rsp.getResponseContent(); + + if(rsp.getStatus() != Constant.HTTP_OK) { + LOG.error("function=getVnfdInfo, msg=catalog return fail,status={}, result={}.", rsp.getStatus(), + resultCreate); + return null; + } + JSONObject csarObj = JSONObject.fromObject(resultCreate); + downloadUri = csarObj.getString("downloadUri"); + } catch (Exception e) { + LOG.error("fetchDownloadUrlFromCatalog error",e); + } + return downloadUri; + } + + /** + * Get csar package information.<br> + * + * @return + * @throws IOException + * @since NFVO 0.5 + */ + public static String readCsarPkgInfo() throws IOException { + InputStream ins = null; + BufferedInputStream bins = null; + String fileContent = ""; + + String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator") + + "etc" + System.getProperty("file.separator") + "csarInfo" + System.getProperty("file.separator") + + Constant.CSARINFO; + + try { + ins = new FileInputStream(fileName); + bins = new BufferedInputStream(ins); + + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); + + if (num > 0) { + fileContent = new String(contentByte); + } + } catch (FileNotFoundException e) { + LOG.error(fileName + "is not found!", e); + } finally { + if (ins != null) { + ins.close(); + } + if (bins != null) { + bins.close(); + } + } + return fileContent; + } + + /** + * download CSAR.<br> + * @return + * @throws IOException + * @since NFVO 0.5 + */ + public JSONObject downloadCsar(String url, String filePath) { + JSONObject resultObj = new JSONObject(); + + if(url == null || "".equals(url)) { + resultObj.put("reason", "url is null."); + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + if(filePath == null || "".equals(filePath)) { + resultObj.put("reason", "downloadUrl filePath is null."); + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + + String status = DownloadCsarManager.download(url, filePath); + + if (Constant.DOWNLOADCSAR_SUCCESS.equals(status)) { + resultObj.put("reason", "download csar file successfully."); + resultObj.put("retCode", Constant.REST_SUCCESS); + } else { + resultObj.put("reason", "download csar file failed."); + resultObj.put("retCode", Constant.REST_FAIL); + } + return resultObj; + } + + /* + * unzip CSAR packge + * @param fileName filePath + * @return + */ + public JSONObject unzipCSAR(String fileName,String filePath) { + JSONObject resultObj = new JSONObject(); + + if(fileName == null || "".equals(fileName)) { + resultObj.put("reason", "fileName is null."); + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + if(filePath == null || "".equals(filePath)) { + resultObj.put("reason", "unzipCSAR filePath is null."); + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + + int status = DownloadCsarManager.unzipCSAR(fileName, filePath); + + + if (Constant.UNZIP_SUCCESS == status) { + resultObj.put("reason", "unzip csar file successfully."); + resultObj.put("retCode", Constant.REST_SUCCESS); + chmodToFiles(filePath); + } else { + resultObj.put("reason", "unzip csar file failed."); + resultObj.put("retCode", Constant.REST_FAIL); + } + return resultObj; + } + + + +private void chmodToFiles(String filePath) { + try { + List<String> commands = new ArrayList<String>(); + commands.add("chmod"); + commands.add("-R"); + commands.add("777"); + commands.add(filePath); + EntityUtils.ExeRes exeRes = EntityUtils.execute(null, commands); + if (exeRes.getCode() == EntityUtils.ExeRes.SUCCESS) { + LOG.info("chmod success:" + EntityUtils.formatCommand(commands)); + } else { + LOG.error("dchmod fail" + EntityUtils.formatCommand(commands) + "\n" + exeRes); + } + } catch (Exception e) { + LOG.error("chmod error:",e); + } +} +} + diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2DriverManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2DriverManager.java new file mode 100644 index 0000000..a9680ff --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2DriverManager.java @@ -0,0 +1,111 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.adapter.impl; + +import net.sf.json.JSONObject; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IJujuAdapter2DriverManager; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Map; + +/** + * <br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Jan 24, 2017 + */ +public class JujuAdapter2DriverManager implements IJujuAdapter2DriverManager { + + private static final Logger LOG = LoggerFactory.getLogger(JujuAdapter2DriverManager.class); + + @Override + public JSONObject registerDriver(Map<String, String> paramsMap, JSONObject driverInfo) { + JSONObject resultObj = new JSONObject(); + + RestfulResponse rsp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap, driverInfo.toString()); + if(null == rsp) { + LOG.error("function=registerDriver, RestfulResponse is null"); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + String resultCreate = rsp.getResponseContent(); + + if(rsp.getStatus() == Constant.HTTP_CREATED) { + LOG.warn("function=registerDriver, msg= status={}, result={}.", rsp.getStatus(), resultCreate); + resultObj = JSONObject.fromObject(resultCreate); + resultObj.put("retCode", Constant.HTTP_CREATED); + return resultObj; + } else if(rsp.getStatus() == Constant.INVALID_PARAMETERS) { + LOG.error("function=registerDriver, msg=DriverManager return fail,invalid parameters,status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "DriverManager return fail,invalid parameters."); + } else if(rsp.getStatus() == Constant.HTTP_INNERERROR) { + LOG.error( + "function=registerDriver, msg=DriverManager return fail,internal system error,status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "DriverManager return fail,internal system error."); + } + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + + @Override + public JSONObject unregisterDriver(Map<String, String> paramsMap) { + JSONObject resultObj = new JSONObject(); + + RestfulResponse rsp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap, ""); + if(null == rsp) { + LOG.error("function=unregisterDriver, RestfulResponse is null"); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + String resultCreate = rsp.getResponseContent(); + + if(rsp.getStatus() == Constant.UNREG_SUCCESS) { + LOG.warn("function=unregisterDriver, msg= status={}, result={}.", rsp.getStatus(), resultCreate); + resultObj = JSONObject.fromObject(resultCreate); + resultObj.put("retCode", Constant.UNREG_SUCCESS); + return resultObj; + } else if(rsp.getStatus() == Constant.HTTP_NOTFOUND) { + LOG.error( + "function=unregisterDriver, msg=DriverManager return fail,can't find the service instance.status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "DriverManager return fail,can't find the service instance."); + } else if(rsp.getStatus() == Constant.INVALID_PARAMETERS) { + LOG.error( + "function=unregisterDriver, msg=DriverManager return fail,invalid parameters,status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "DriverManager return fail,invalid parameters."); + } else if(rsp.getStatus() == Constant.HTTP_INNERERROR) { + LOG.error( + "function=unregisterDriver, msg=DriverManager return fail,internal system error,status={}, result={}.", + rsp.getStatus(), resultCreate); + resultObj.put("reason", "DriverManager return fail,internal system error."); + } + resultObj.put("retCode", Constant.REST_FAIL); + return resultObj; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2MSBManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2MSBManager.java new file mode 100644 index 0000000..0a96792 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2MSBManager.java @@ -0,0 +1,110 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.impl; + +import java.util.Map; + +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IJujuAdapter2MSBManager; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * + * Juju adapter to msb manager class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class JujuAdapter2MSBManager implements IJujuAdapter2MSBManager { + + private static final Logger LOG = LoggerFactory.getLogger(JujuAdapter2MSBManager.class); + + @Override + public JSONObject registerJujuAdapter(Map<String, String> paramsMap, JSONObject adapterInfo) { + JSONObject resultObj = new JSONObject(); + //verify url,reserve + + RestfulResponse rsp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap,adapterInfo.toString()); + if(null == rsp) { + LOG.error("function=registerJujuAdapter, RestfulResponse is null"); + resultObj.put(Constant.REASON, "RestfulResponse is null."); + resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE); + return resultObj; + } + String resultCreate = rsp.getResponseContent(); + + if(rsp.getStatus() == Constant.HTTP_CREATED) { + LOG.warn("function=registerJujuAdapter, msg= status={}, result={}.", rsp.getStatus(), resultCreate); + resultObj = JSONObject.fromObject(resultCreate); + resultObj.put(Constant.RETURN_CODE, Constant.HTTP_CREATED); + return resultObj; + } else if(rsp.getStatus() == Constant.INVALID_PARAMETERS){ + LOG.error("function=registerJujuAdapter, msg=MSB return fail,invalid parameters,status={}, result={}.", rsp.getStatus(), + resultCreate); + resultObj.put(Constant.REASON, "MSB return fail,invalid parameters."); + } else if(rsp.getStatus() == Constant.HTTP_INNERERROR){ + LOG.error("function=registerJujuAdapter, msg=MSB return fail,internal system error,status={}, result={}.", rsp.getStatus(), + resultCreate); + resultObj.put(Constant.REASON, "MSB return fail,internal system error."); + } + resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE); + return resultObj; + } + + @Override + public JSONObject unregisterJujuAdapter(Map<String, String> paramsMap) { + JSONObject resultObj = new JSONObject(); + //verify url,reserve + + RestfulResponse rsp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap,""); + if(null == rsp) { + LOG.error("function=unregisterJujuAdapter, RestfulResponse is null"); + resultObj.put(Constant.REASON, "RestfulResponse is null."); + resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE); + return resultObj; + } + String resultCreate = rsp.getResponseContent(); + + if(rsp.getStatus() == Constant.UNREG_SUCCESS) { + LOG.warn("function=unregisterJujuAdapter, msg= status={}, result={}.", rsp.getStatus(), resultCreate); + resultObj = JSONObject.fromObject(resultCreate); + resultObj.put(Constant.RETURN_CODE, Constant.UNREG_SUCCESS); + return resultObj; + } else if(rsp.getStatus() == Constant.HTTP_NOTFOUND){ + LOG.error("function=unregisterJujuAdapter, msg=MSB return fail,can't find the service instance.status={}, result={}.", rsp.getStatus(), + resultCreate); + resultObj.put(Constant.REASON, "MSB return fail,can't find the service instance."); + } else if(rsp.getStatus() == Constant.INVALID_PARAMETERS){ + LOG.error("function=unregisterJujuAdapter, msg=MSB return fail,invalid parameters,status={}, result={}.", rsp.getStatus(), + resultCreate); + resultObj.put(Constant.REASON, "MSB return fail,invalid parameters."); + } else if(rsp.getStatus() == Constant.HTTP_INNERERROR){ + LOG.error("function=unregisterJujuAdapter, msg=MSB return fail,internal system error,status={}, result={}.", rsp.getStatus(), + resultCreate); + resultObj.put(Constant.REASON, "MSB return fail,internal system error."); + } + resultObj.put(Constant.RETURN_CODE, Constant.ERROR_STATUS_CODE); + return resultObj; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuClientManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuClientManager.java new file mode 100644 index 0000000..efd72d6 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuClientManager.java @@ -0,0 +1,449 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.impl; + +import java.io.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.commons.lang3.StringUtils; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.baseservice.util.impl.SystemEnvVariablesFactory; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils.ExeRes; +import org.openo.nfvo.jujuvnfmadapter.common.FileUtils; +import org.openo.nfvo.jujuvnfmadapter.common.JujuConfigUtil; +import org.openo.nfvo.jujuvnfmadapter.common.YamlUtil; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IJujuClientManager; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.constant.UrlConstant; +import org.openo.nfvo.jujuvnfmadapter.service.juju.JujuHelper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSON; +import net.sf.json.JSONObject; + + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 7, 2016 + */ +public class JujuClientManager implements IJujuClientManager { + private static final Logger LOG = LoggerFactory.getLogger(JujuClientManager.class); + + public static final String ADDRESOURCE="addResource"; + public static final String REMOVERESOURCE = "removeResource"; + + /** + * <br/> + * + * @param charmPath + * @param appName + * @return + * @since NFVO 0.5 + */ + @Override + public JSONObject deploy(String charmPath, String appName) { + JSONObject result = new JSONObject(); + if(charmPath == null || appName == null){ + String msg = "the 'charmPath' or 'appName' can not be null"; + result.put(EntityUtils.RESULT_CODE_KEY, -1); + result.put(EntityUtils.MSG_KEY, msg); + LOG.error(msg); + return result; + } + String modelName = JujuHelper.getModelName(appName); + //add-model + this.addModel(modelName);//use appName as modelName + //switch model + this.switchModel(modelName); + //deploy service + List<String> commands = new ArrayList<>(); + commands.add("juju"); + commands.add("deploy"); + if(StringUtils.isNotBlank(charmPath)){ + String fullPath = charmPath+appName; + commands.add(fullPath); + }else{ + commands.add(appName); + } + commands.add("-m"); + commands.add(modelName); + ExeRes exeRes = EntityUtils.execute(charmPath,commands); + if(exeRes.getCode() == ExeRes.SUCCESS){ + LOG.info("deploy success. command:"+EntityUtils.formatCommand(commands)); + result.put(EntityUtils.RESULT_CODE_KEY, 0); + result.put(EntityUtils.DATA_KEY, exeRes.getBody()); + }else{ + LOG.error("deploy failed. command:"+EntityUtils.formatCommand(commands)+"\n"+exeRes); + result.put(EntityUtils.RESULT_CODE_KEY, -1); + result.put(EntityUtils.MSG_KEY, "deploy failed:"+exeRes.getBody()); + } + + return result; + } + + /** + * + * <br/> + * + * @param modelName + * @return + * @since NFVO 0.5 + */ + private JSONObject addModel(String modelName) { + JSONObject result = new JSONObject(); + List<String> commands = new ArrayList<>(); + commands.add("juju"); + commands.add("add-model"); + commands.add(modelName); + getExtraParam(commands); + ExeRes exeRes = EntityUtils.execute(null,commands); + if(exeRes.getCode() == ExeRes.SUCCESS){ + LOG.info("addModel success. command:"+EntityUtils.formatCommand(commands)); + result.put(EntityUtils.RESULT_CODE_KEY, 0); + result.put(EntityUtils.DATA_KEY, exeRes.getBody()); + }else{ + LOG.error("addModel failed. command:"+EntityUtils.formatCommand(commands)+"\n"+exeRes); + result.put(EntityUtils.RESULT_CODE_KEY, -1); + result.put(EntityUtils.MSG_KEY, "addModel failed:"+exeRes.getBody()); + } + + return result; + } + + /** + * getExtraParam + * add model + juju add-model <model-name> --config image-metadata-url=http://192.168.20.106/images --config network=demo-net --config use-floating-ip=True --config use-default-secgroup=True + * @return + */ + private void getExtraParam(List<String> commands){ + try { + String configInfo = readJujuConfigInfo(); + if(configInfo != null){ + JSONObject json = JSONObject.fromObject(configInfo); + commands.add("--config"); + commands.add("image-metadata-url="+json.getString("image-metadata-url")); + commands.add("--config"); + commands.add("network="+json.getString("network")); + commands.add("--config"); + commands.add("use-floating-ip="+json.getString("use-floating-ip")); + commands.add("--config"); + commands.add("use-default-secgroup="+json.getString("use-default-secgroup")); + } + } catch (Exception e) { + LOG.error("read juju command config error:",e); + } + } + + /** + * Get csar package information.<br> + * + * @return + * @throws IOException + * @since NFVO 0.5 + */ + public static String readJujuConfigInfo() { + InputStream ins = null; + + BufferedInputStream bins = null; + String fileContent = null; + String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator") + + "etc" + System.getProperty("file.separator") + "conf" + System.getProperty("file.separator") + + "juju_conf.json"; + try { + ins = new FileInputStream(fileName); + bins = new BufferedInputStream(ins); + + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); + + if (num > 0) { + fileContent = new String(contentByte); + } + } catch (Exception e) { + LOG.error(fileName + "is not found!", e); + } finally { + try { + if (ins != null) { + ins.close(); + } + if (bins != null) { + bins.close(); + } + } catch (IOException e) { + } + } + return fileContent; + } + private JSONObject changeDir(String charmPath) { + JSONObject result = new JSONObject(); + List<String> commands = new ArrayList<>(); + commands.add("cd"); + commands.add(charmPath); + ExeRes exeRes = EntityUtils.execute(null,commands); + if(exeRes.getCode() == ExeRes.SUCCESS){ + LOG.info("changeDir success. command:"+EntityUtils.formatCommand(commands)); + result.put(EntityUtils.RESULT_CODE_KEY, 0); + result.put(EntityUtils.DATA_KEY, exeRes.getBody()); + }else{ + LOG.error("changeDir failed. command:"+EntityUtils.formatCommand(commands)+"\n"+exeRes); + result.put(EntityUtils.RESULT_CODE_KEY, -1); + result.put(EntityUtils.MSG_KEY, "addModel failed:"+exeRes.getBody()); + } + + return result; + } + + /** + * + * <br/> + * + * @param modelName + * @return + * @since NFVO 0.5 + */ + private JSONObject switchModel(String modelName) { + JSONObject result = new JSONObject(); + List<String> commands = new ArrayList<>(); + commands.add("juju"); + commands.add("switch"); + commands.add(modelName); + ExeRes exeRes = EntityUtils.execute(null,commands); + if(exeRes.getCode() == ExeRes.SUCCESS){ + LOG.info("switchModel success. command:"+EntityUtils.formatCommand(commands)); + result.put(EntityUtils.RESULT_CODE_KEY, 0); + result.put(EntityUtils.DATA_KEY, exeRes.getBody()); + }else{ + LOG.error("switchModel failed. command:"+EntityUtils.formatCommand(commands)+"\n"+exeRes); + result.put(EntityUtils.RESULT_CODE_KEY, -1); + result.put(EntityUtils.MSG_KEY, "addModel failed:"+exeRes.getBody()); + } + + return result; + } + + /** + * <br/> + * + * @param appName + * @return + * @since NFVO 0.5 + */ + @Override + public JSONObject destroy(String appName) { + String modelName = JujuHelper.getModelName(appName); + JSONObject result = new JSONObject(); + List<String> commands = new ArrayList<>(); + commands.add("juju"); + commands.add("destroy-model"); + commands.add("-y"); + commands.add(modelName); + + ExeRes exeRes = EntityUtils.execute(null,commands); + if(exeRes.getCode() == ExeRes.SUCCESS){ + LOG.info("remove success. command:"+EntityUtils.formatCommand(commands)); + result.put(EntityUtils.RESULT_CODE_KEY, 0); + result.put(EntityUtils.DATA_KEY, exeRes.getBody()); + }else{ + LOG.error("remove failed. command:"+EntityUtils.formatCommand(commands)+"\n"+exeRes); + result.put(EntityUtils.RESULT_CODE_KEY, -1); + result.put(EntityUtils.MSG_KEY, "remove failed:"+exeRes.getBody()); + } + + return result; + + } + + /** + * <br/> + * + * @param appName + * @return + * @since NFVO 0.5 + */ + @Override + public JSONObject getStatus(String appName) { + String modelName = JujuHelper.getModelName(appName); + JSONObject result = new JSONObject(); + List<String> commands = new ArrayList<>(); + commands.add("juju"); + commands.add("status"); + if(StringUtils.isNotBlank(modelName)){ + commands.add("-m"); + commands.add(modelName); + } + commands.add("--format=json"); + + ExeRes exeRes = EntityUtils.execute(null,commands); + if(exeRes.getCode() == ExeRes.SUCCESS){ + LOG.info("getStatus success. command:"+EntityUtils.formatCommand(commands)); + result.put(EntityUtils.RESULT_CODE_KEY, 0); + JSONObject dataObj = buildDataObj(exeRes); + result.put(EntityUtils.DATA_KEY, dataObj); + }else{ + LOG.error("getStatus failed. command:"+EntityUtils.formatCommand(commands)+"\n"+exeRes); + result.put(EntityUtils.RESULT_CODE_KEY, -1); + result.put(EntityUtils.MSG_KEY, "getStatus failed:"+exeRes.getBody()); + } + + return result; + } + + /** + * <br/> + * + * @param exeRes + * @return + * @since NFVO 0.5 + */ + private JSONObject buildDataObj(ExeRes exeRes) { + JSONObject dataObj = null; + if(StringUtils.isNotBlank(exeRes.getBody())){ + dataObj = JSONObject.fromObject(exeRes.getBody()); + //according to appName to select + } + return dataObj; + } + + + /** + * call the juju vnfm to grant resource(disk,mem,cpu) + * <br/> + * (fields:cpu,mem,disk,action(addResource/removeResource)) + * @param vnfId + * @param appName + * @param action + * @since NFVO 0.5 + * @return + */ + @Override + public boolean grantResource(String charmPath, String appName,String action , String vnfId){ + //1.parse yaml file + JSONObject params; + try { + params = this.parseYaml(charmPath, appName, action); + } catch(Exception e) { + LOG.error("ParseYaml error,please check it.",e); + return false; + } + if(params == null){ + LOG.error("ParseYaml fail,please check it."); + return false; + } + + //2. call grant service + String url = JujuConfigUtil.getValue("grant_jujuvnfm_url"); + Map<String, String> paramsMap = new HashMap<>(6); + paramsMap.put("url", url); + paramsMap.put(Constant.METHOD_TYPE, Constant.PUT); + paramsMap.put("path", String.format(UrlConstant.REST_JUJU_VNFM_GRANT_URL,vnfId)); + paramsMap.put(Constant.AUTH_MODE, Constant.AuthenticationMode.ANONYMOUS); + RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(paramsMap, params.toString(), null); + if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) { + LOG.error("function=grantResource, msg=send grantResource msg to juju-vnfm get wrong results"); + return false; + } + //3.process result + String response = rsp.getResponseContent(); + LOG.info("grant resource result:"+response); + return true; + } + + /** + * + * <br/> + * "constraints":"arch=amd64 cpu-cores=1 cpu-power=100 mem=1740 root-disk=8192" + * @param charmPath + * @param appName + * @param action + * @return + * @since NFVO 0.5 + */ + public JSONObject parseYaml(String charmPath, String appName,String action){ + JSONObject compute = new JSONObject(); + compute.put("action", action); + if(StringUtils.isBlank(charmPath)){ + LOG.error("the charmPath can't be null! [in unzipFileAndParseYaml]"); + return null; + } + //set default values for non 'yaml' type + if(!appName.endsWith(".yaml")){ + compute.put("cpu", 4); + compute.put("mem", 2); + compute.put("disk", 40); + return compute; + } + String yaml = FileUtils.getFriendlyPath(charmPath)+appName; + File yamlFile = new File(yaml); + if(yamlFile.exists()){ + JSON json = YamlUtil.yamlToJson(yamlFile.getAbsolutePath()); + LOG.info(yaml+":\n"+json); + if(json.isArray()){ + LOG.error("the yaml file has error format,please check it!"+yamlFile); + return null; + } + JSONObject jsonObj = (JSONObject)json; + JSONObject services = jsonObj.getJSONObject("services"); + int cpu = 0; + int mem = 0; + int disk = 0; + for(Object key: services.keySet()){ + JSONObject app = services.getJSONObject(key.toString()); + if(app.containsKey("constraints")){ + String constraints = app.getString("constraints"); + String[] vals = constraints.split("\\s+"); + LOG.info(key+"="+constraints); + for(String val : vals){ + String[] kv = val.split("="); + if("cpu-cores".equals(kv[0]) && StringUtils.isNotBlank(kv[1])){ + cpu+=Integer.valueOf(kv[1]); + }else if("mem".equals(kv[0]) && StringUtils.isNotBlank(kv[1])){ + mem+=Integer.valueOf(kv[1]); + }else if("root-disk".equals(kv[0]) && StringUtils.isNotBlank(kv[1])){ + disk+=Integer.valueOf(kv[1]); + } + } + } + } + compute.put("cpu", cpu); + compute.put("mem", mem); + compute.put("disk", disk); + }else{ + LOG.error("the yaml file not exist!file="+yamlFile); + return null; + } + LOG.info("parse yaml result-->"+compute); + return compute; + } + + + public static void main(String[] args) { + JujuClientManager jujuClientManager = new JujuClientManager(); + jujuClientManager.parseYaml("E:/workspace/openo-common-utils/src/org/openo/common/yaml", "test.yaml", "addResource"); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuAdapter2DriverManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuAdapter2DriverManager.java new file mode 100644 index 0000000..30f92e4 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuAdapter2DriverManager.java @@ -0,0 +1,52 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.adapter.inf; + +import java.util.Map; + +import net.sf.json.JSONObject; + +/** + * <br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Jan 24, 2017 + */ +public interface IJujuAdapter2DriverManager { + + /** + * Method to Register Driver.<br/> + * + * @param paramsMap + * @param driverInfo + * @return + * @since NFVO 0.5 + */ + JSONObject registerDriver(Map<String, String> paramsMap, JSONObject driverInfo); + + /** + * Method to Unregister Driver.<br/> + * + * @param paramsMap + * @return + * @since NFVO 0.5 + */ + JSONObject unregisterDriver(Map<String, String> paramsMap); + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuAdapter2MSBManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuAdapter2MSBManager.java new file mode 100644 index 0000000..03a9cf7 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuAdapter2MSBManager.java @@ -0,0 +1,56 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.inf; + +import java.util.Map; + + +import net.sf.json.JSONObject; + +/** + * + * iJuju adapter to msb manager class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public interface IJujuAdapter2MSBManager{ + + /** + * + * Register juju adapter.<br> + * + * @param paramsMap + * @param driverInfo + * @return + * @since NFVO 0.5 + */ + JSONObject registerJujuAdapter(Map<String,String> paramsMap, JSONObject driverInfo); + + /** + * + * Unregister juju adapter.<br> + * + * @param paramsMap + * @return + * @since NFVO 0.5 + */ + JSONObject unregisterJujuAdapter(Map<String,String> paramsMap); + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuClientManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuClientManager.java new file mode 100644 index 0000000..fab61a8 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IJujuClientManager.java @@ -0,0 +1,84 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.inf; + +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 7, 2016 + */ +public interface IJujuClientManager { + + /** + * * deploy juju charm from local filesystem. The charm will get deployed on a trusty instance + * with at least 2 GB RAM + * juju deploy $HOME/charms/example --series trusty --constraints mem=2G --config + * /path/to/custom/charm-config.yaml + * <br/> + * + * @param charmPath + * @param mem (at least 2 GB RAM) unit/GB + * @param appName + * @return + * @since NFVO 0.5 + */ + JSONObject deploy(String charmPath, String appName); + + /** + * * remove a charm completely + * juju remove-application example + * juju destroy-model model-name + * <br/> + * + * @param appName + * @return + * @since NFVO 0.5 + */ + JSONObject destroy(String appName); + + /** + * juju status --format=json + * juju status -m model-name --format=json + * get the status of a single charm + * juju status example --format=json + * Here is an example output from juju status --format=json + * http://paste.ubuntu.com/23113992/ + * <br/> + * + * @param modelName + * @return + * @since NFVO 0.5 + */ + JSONObject getStatus(String modelName); + /** + * + * <br/> + * + * @param charmPath + * @param appName + * @param action + * @param vnfId + * @return + * @since NFVO 0.5 + */ + public boolean grantResource(String charmPath, String appName,String action , String vnfId); +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IResourceManager.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IResourceManager.java new file mode 100644 index 0000000..7c05fd3 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/inf/IResourceManager.java @@ -0,0 +1,53 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.inf; + +import java.util.Map; +import net.sf.json.JSONObject; + +/** + * + * iResource manager interface.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public interface IResourceManager { + + /** + * + * Get juju vnfm information.<br> + * + * @param paramsMap + * @return + * @since NFVO 0.5 + */ + JSONObject getJujuVnfmInfo(Map<String,String> paramsMap); + + /** + * + * Get vfnfd information.<br> + * + * @param paramsMap + * @return + * @since NFVO 0.5 + */ + JSONObject getVnfdInfo(String csarId); + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapter2DriverMgrService.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapter2DriverMgrService.java new file mode 100644 index 0000000..a297110 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapter2DriverMgrService.java @@ -0,0 +1,183 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.api.internalsvc.impl; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executors; + +import org.openo.baseservice.util.impl.SystemEnvVariablesFactory; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.impl.JujuAdapter2DriverManager; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IJujuAdapter2DriverManager; +import org.openo.nfvo.jujuvnfmadapter.service.api.internalsvc.inf.IJujuAdapter2DriverMgrService; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.constant.UrlConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * <br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Jan 24, 2017 + */ +public class JujuAdapter2DriverMgrService implements IJujuAdapter2DriverMgrService { + + private static final Logger LOG = LoggerFactory.getLogger(JujuAdapter2DriverMgrService.class); + + public static final String VIMADAPTER2DRIVERMGR = "vimadapter2drivermgr.json"; + + @Override + public void register() { + // set URL and mothedtype + Map<String, String> paramsMap = new HashMap<>(); + paramsMap.put("url", UrlConstant.REST_DRIVERMGR_REGISTER); + paramsMap.put("methodType", Constant.POST); + + // get vim adapter info and raise registration + try { + String adapterInfo = readVimAdapterInfoFromJson(); + if(!"".equals(adapterInfo)) { + JSONObject adapterObject = JSONObject.fromObject(adapterInfo); + RegisterVnfm2DriverMgrThread vnfmAdapterThread = + new RegisterVnfm2DriverMgrThread(paramsMap, adapterObject); + Executors.newSingleThreadExecutor().submit(vnfmAdapterThread); + } else { + LOG.error("vnfmadapter2drivermgr info is null,please check!"); + } + + } catch(IOException e) { + LOG.error("Failed to read vnfmadapter2drivermgr info! " + e.getMessage(), e); + } + + } + + /** + * Retrieve VIM driver information. + * + * @return + * @throws IOException + */ + public static String readVimAdapterInfoFromJson() throws IOException { + InputStream ins = null; + BufferedInputStream bins = null; + String fileContent = ""; + + String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty("file.separator") + + "etc" + System.getProperty("file.separator") + "adapterInfo" + System.getProperty("file.separator") + + VIMADAPTER2DRIVERMGR; + + try { + ins = new FileInputStream(fileName); + bins = new BufferedInputStream(ins); + + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); + + if(num > 0) { + fileContent = new String(contentByte); + } + } catch(FileNotFoundException e) { + LOG.error(fileName + "is not found!", e); + } finally { + if(ins != null) { + ins.close(); + } + if(bins != null) { + bins.close(); + } + } + + return fileContent; + } + + private static class RegisterVnfm2DriverMgrThread implements Runnable { + + // Thread lock Object + private final Object lockObject = new Object(); + + private IJujuAdapter2DriverManager adapter2DriverMgr = new JujuAdapter2DriverManager(); + + // url and mothedtype + private Map<String, String> paramsMap; + + // driver body + private JSONObject adapterInfo; + + public RegisterVnfm2DriverMgrThread(Map<String, String> paramsMap, JSONObject adapterInfo) { + this.paramsMap = paramsMap; + this.adapterInfo = adapterInfo; + } + + @Override + public void run() { + LOG.info("start register vnfmadapter to Driver Manager", RegisterVnfm2DriverMgrThread.class); + + if(paramsMap == null || adapterInfo == null) { + LOG.error("parameter is null,please check!", RegisterVnfm2DriverMgrThread.class); + return; + } + + // catch Runtime Exception + try { + sendRequest(paramsMap, adapterInfo); + } catch(RuntimeException e) { + LOG.error(e.getMessage(), e); + } + + } + + private void sendRequest(Map<String, String> paramsMap, JSONObject driverInfo) { + JSONObject resultObj = adapter2DriverMgr.registerDriver(paramsMap, driverInfo); + + if(Integer.valueOf(resultObj.get("retCode").toString()) == Constant.HTTP_CREATED) { + LOG.info("Vnfmadapter has now Successfully Registered to the Driver Manager!"); + } else { + LOG.error("Vnfmadapter failed to Register to the Driver Manager! Reason:" + + resultObj.get("reason").toString() + " retCode:" + resultObj.get("retCode").toString()); + + // if registration fails,wait one minute and try again + try { + synchronized(lockObject) { + lockObject.wait(Constant.REPEAT_REG_TIME); + } + } catch(InterruptedException e) { + LOG.error(e.getMessage(), e); + } + + sendRequest(this.paramsMap, this.adapterInfo); + } + + } + + } + + @Override + public void unregister() { + // unregister + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrService.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrService.java new file mode 100644 index 0000000..58b9c23 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrService.java @@ -0,0 +1,196 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.api.internalsvc.impl; + +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Executors; + +import org.openo.baseservice.util.impl.SystemEnvVariablesFactory; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.impl.JujuAdapter2MSBManager; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IJujuAdapter2MSBManager; +import org.openo.nfvo.jujuvnfmadapter.service.api.internalsvc.inf.IJujuAdapterMgrService; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.constant.UrlConstant; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * Juju adapter manager service class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class JujuAdapterMgrService implements IJujuAdapterMgrService { + + private static final Logger LOG = LoggerFactory.getLogger(JujuAdapterMgrService.class); + + @Override + public void register() { + // set BUS URL and mothedtype + Map<String, String> paramsMap = new HashMap<>(); + paramsMap.put("url", UrlConstant.REST_MSB_REGISTER); + paramsMap.put("methodType", Constant.POST); + + // get juju adapter info and raise registration + try { + String adapterInfo = readJujuAdapterInfoFromJson(); + if(!"".equals(adapterInfo)) { + JSONObject adapterObject = JSONObject.fromObject(adapterInfo); + RegisterJujuAdapterThread jujuAdapterThread = new RegisterJujuAdapterThread(paramsMap, adapterObject); + Executors.newSingleThreadExecutor().submit(jujuAdapterThread); + } else { + LOG.error("JujuVnfmAdapter info is null,please check!", JujuAdapterMgrService.class); + } + + } catch(IOException e) { + LOG.error("Failed to read JujuVnfmAdapter info!" + e, JujuAdapterMgrService.class); + } + + } + + /** + * Read juju adapter information from Json.<br> + * + * @return + * @throws IOException + * @since NFVO 0.5 + */ + public static String readJujuAdapterInfoFromJson() throws IOException { + InputStream ins = null; + BufferedInputStream bins = null; + String fileContent = ""; + + String fileName = SystemEnvVariablesFactory.getInstance().getAppRoot() + + System.getProperty(Constant.FILE_SEPARATOR) + "etc" + System.getProperty(Constant.FILE_SEPARATOR) + + "adapterInfo" + System.getProperty(Constant.FILE_SEPARATOR) + Constant.JUJUADAPTERINFO; + + try { + ins = new FileInputStream(fileName); + bins = new BufferedInputStream(ins); + + byte[] contentByte = new byte[ins.available()]; + int num = bins.read(contentByte); + + if(num > 0) { + fileContent = new String(contentByte); + } + } catch(FileNotFoundException e) { + LOG.error(fileName + "is not found!", e, JujuAdapterMgrService.class); + } finally { + if(null != ins) { + ins.close(); + } + + if(null != bins) { + bins.close(); + } + } + + return fileContent; + } + + private static class RegisterJujuAdapterThread implements Runnable { + + // Thread lock Object + private final Object lockObject = new Object(); + + private IJujuAdapter2MSBManager adapter2MSBMgr = new JujuAdapter2MSBManager(); + + // url and mothedtype + private Map<String, String> paramsMap; + + // driver body + private JSONObject adapterInfo; + + public RegisterJujuAdapterThread(Map<String, String> paramsMap, JSONObject adapterInfo) { + this.paramsMap = paramsMap; + this.adapterInfo = adapterInfo; + } + + @Override + public void run() { + LOG.info("start register jujuvnfmadapter", RegisterJujuAdapterThread.class); + + if(paramsMap == null || adapterInfo == null) { + LOG.error("parameter is null,please check!", RegisterJujuAdapterThread.class); + return; + } + + // catch Runtime Exception + try { + sendRequest(paramsMap, adapterInfo); + } catch(RuntimeException e) { + LOG.error(e.getMessage(), e); + } + + } + + private void sendRequest(Map<String, String> paramsMap, JSONObject driverInfo) { + JSONObject resultObj = adapter2MSBMgr.registerJujuAdapter(paramsMap, driverInfo); + + if(Integer.valueOf(resultObj.get("retCode").toString()) == Constant.HTTP_CREATED) { + LOG.info("JujuVnfmAdapter has now Successfully Registered to the Microservice BUS!", + JujuAdapterMgrService.class); + } else { + LOG.error("JujuVnfmAdapter failed to Register to the Microservice BUS! Reason:" + + resultObj.get("reason").toString() + " retCode:" + resultObj.get("retCode").toString()); + + // if registration fails,wait one minute and try again + try { + synchronized(lockObject) { + lockObject.wait(Constant.REPEAT_REG_TIME); + } + } catch(InterruptedException e) { + LOG.error("sendRequest error", e); + } + + sendRequest(this.paramsMap, this.adapterInfo); + } + + } + + } + + @Override + public void unregister() { + // Not implemented + + } + + /** + * Main method.<br> + * + * @param args + * @since NFVO 0.5 + */ + public static void main(String[] args) { + LOG.info(SystemEnvVariablesFactory.getInstance().getAppRoot() + System.getProperty(Constant.FILE_SEPARATOR) + + "etc" + System.getProperty(Constant.FILE_SEPARATOR) + "adapterInfo" + + System.getProperty(Constant.FILE_SEPARATOR) + Constant.JUJUADAPTERINFO); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/inf/IJujuAdapter2DriverMgrService.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/inf/IJujuAdapter2DriverMgrService.java new file mode 100644 index 0000000..ab8b839 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/inf/IJujuAdapter2DriverMgrService.java @@ -0,0 +1,43 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.api.internalsvc.inf; + +/** + * <br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Jan 24, 2017 + */ +public interface IJujuAdapter2DriverMgrService { + + /** + * VimAdapter register interface.<br> + * + * @since NFVO 0.5 + */ + void register(); + + /** + * VimAdapter unregister interface.<br> + * + * @since NFVO 0.5 + */ + void unregister(); + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/inf/IJujuAdapterMgrService.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/inf/IJujuAdapterMgrService.java new file mode 100644 index 0000000..c3c0f12 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/inf/IJujuAdapterMgrService.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.api.internalsvc.inf; + +/** + * + * Ijuju adapter manager service interface.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public interface IJujuAdapterMgrService { + + /** + * + * JujuVnfmAdapter register interface.<br> + * + * @since NFVO 0.5 + */ + void register(); + + /** + * + * JujuVnfmAdapter unregister interface.<br> + * + * @since NFVO 0.5 + */ + void unregister(); +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/Constant.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/Constant.java new file mode 100644 index 0000000..0ae5c7f --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/Constant.java @@ -0,0 +1,219 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.constant; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Constant class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class Constant { + + public static final String VNFM_APP = "VnfmDriver"; + + public static final String VNFM_DB = "vnfmdb"; + + public static final String VNFM_ID = "vnfmId"; + + public static final String POST = "post"; + + public static final String PUT = "put"; + + public static final String DELETE = "delete"; + + public static final String GET = "get"; + + public static final String HEAD = "head"; + + public static final String ASYNCPOST = "asyncPost"; + + public static final String ASYNCGET = "asyncGet"; + + public static final String ASYNCPUT = "asyncPut"; + + public static final String ASYNCDELETE = "asyncDelete"; + + public static final String RESPONSE_CONTENT = "responseContent"; + + public static final String STATUS_CODE = "statusCode"; + + public static final String RETURN_CODE = "retCode"; + + public static final String REASON = "reason"; + + public static final int ERROR_STATUS_CODE = -1; + + public static final String ENCODEING = "utf-8"; + + public static final String COOKIE = "Cookie"; + + public static final String ACCESSSESSION = "bspsession="; + + public static final String CONTENT_TYPE = "Content-Type"; + + public static final String METHOD_TYPE = "methodType"; + + public static final String AUTH_MODE = "authMode"; + + public static final String APPLICATION = "application/json"; + + public static final String APP_NAME = "appName"; + + public static final String HEADER_SUBJECT_TOKEN = "X-Subject-Token"; + + public static final String HEADER_AUTH_TOKEN = "X-Auth-Token"; + + public static final String CSM = "csm"; + + public static final int ERROR_CODE = -1; + + public static final int HTTP_OK = 200; + + public static final int HTTP_CREATED = 201; + + public static final int HTTP_ACCEPTED = 202; + + public static final int UNREG_SUCCESS = 204; + + public static final int HTTP_BAD_REQUEST = 400; + + public static final int HTTP_UNAUTHORIZED = 401; + + public static final int HTTP_NOTFOUND = 404; + + public static final int HTTP_CONFLICT = 409; + + public static final int INVALID_PARAMETERS = 415; + + public static final int HTTP_INNERERROR = 500; + + public static final int REPEAT_REG_TIME = 60 * 1000; + + public static final String JUJUADAPTERINFO = "jujuadapterinfo.json"; + + public static final String FILE_SEPARATOR = "file.separator"; + + public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss"; + + public static final List<String> AUTHLIST = + Collections.unmodifiableList(Arrays.asList(AuthenticationMode.ANONYMOUS, AuthenticationMode.CERTIFICATE)); + + public static final int INTERNAL_EXCEPTION = 600; + + public static final int TOKEN_HEAD_NULL = 601; + + public static final int TOKEN_USER_NULL = 602; + + public static final int SERVICE_URL_ERROR = 603; + + public static final int ACCESS_OBJ_NULL = 604; + + public static final int CONNECT_NOT_FOUND = 605; + + public static final int VCENTER_PARA_ERROR = 606; + + public static final int TYPE_PARA_ERROR = 607; + + public static final int CONNECT_FAIL = 608; + + public static final int DIS_CONNECT_FAIL = 609; + + public static final int HANDSHAKE_FAIL = 610; + + public static final int MIN_PWD_LENGTH = 6; + + public static final int MAX_PWD_LENGTH = 160; + + public static final int MIN_URL_LENGTH = 7; + + public static final int MAX_VNFM_NAME_LENGTH = 64; + + public static final int MIN_VNFM_NAME_LENGTH = 1; + + public static final int MAX_URL_LENGTH = 256; + + public static final int MAX_SAMPLE_NUM = 1; + + public static final int MAX_VERSION_LENGTH = 160; + + public static final int MIN_VERSION_LENGTH = 1; + + public static final String HANDSHAKE = "handShake"; + + public static final String INACTIVE = "inactive"; + + public static final String ACTIVE = "active"; + + public static final String RESOURCE_PATH = ""; + + public static final int REST_SUCCESS = 1; + + public static final int REST_PART_SUCCESS = 0; + + public static final int DEFAULT_COLLECTION_SIZE = 10; + + public static final int REST_FAIL = -1; + + public static final String ROARAND = "?roarand=%s"; + + public static final long PROCESS_WAIT_MILLIS = 30000; + + public static final String CSARINFO="csarinfo.json"; + + public static final String DOWNLOADCSAR_SUCCESS = "Success"; + + public static final String DOWNLOADCSAR_FAIL = "FAIL"; + + public static final int UNZIP_SUCCESS = 0; + + public static final int UNZIP_FAIL = -1; + + /** + * Constructor<br/> + * <p> + * </p> + */ + private Constant() { + // Private Constructor + } + + /** + * Authentication mode.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ + public static class AuthenticationMode { + + public static final String ANONYMOUS = "Anonymous"; + + public static final String CERTIFICATE = "Certificate"; + + private AuthenticationMode() { + + } + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ParamConstants.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ParamConstants.java new file mode 100644 index 0000000..fc734ce --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ParamConstants.java @@ -0,0 +1,144 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.constant; + +/** + * + * Parameter constants class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class ParamConstants { + + public static final String GET_TOKENS_V1 = "{\"grantType\": \"password\", \"userName\": \"%s\",\"value\": \"%s\"}"; + + public static final String GET_TOKENS_V2 = + "{\"auth\":{\"identity\": {\"methods\": [\"password\"],\"password\": {\"user\": {\"name\": \"%s\",\"password\": \"%s\"}}}}}"; + + public static final String GET_IAM_TOKENS = + "{\"auth\": {\"identity\": {\"methods\": [\"password\"],\"password\": {\"user\": {\"name\": " + + "\"%s\",\"password\": \"%s\",\"domain\": {\"name\": \"%s\"}}}},\"scope\": {\"domain\": {\"name\": \"%s\"}}}}"; + + public static final String GET_TOKEN_SUC_RESP = + "{\"token\": {\"methods\": [\"password\"],\"expires_at\": \"\",\"user\": {\"id\": \"%s\"," + + "\"name\": \"%s\"},\"roa_rand\": \"%s\"}}"; + + public static final String GET_TOKEN_FAIL_RESP = "{\"Information\": \"%s\"}"; + + public static final String REST_3RD_CONNECTION = "/rest/plat/smapp/v1/oauth/token"; + + public static final String REST_3RD_DISCONNECT = "/rest/plat/smapp/v1/sessions?roarand=%s"; + + public static final String REST_3RD_HANDSHAKE = "/rest/plat/ssm/v1/sessions/verify"; + + public static final String IAM_AUTH = "/v3/auth/tokens"; + + public static final String CSM_AUTH_CONNECT = "/v2/auth/tokens"; + + public static final String CSM_AUTH_DISCONNECT = "/v2/auth/tokens/%s/%s"; + + public static final String CSM_AUTH_HANDSHAKE = "/v2/nfvo/shakehand?roattr=status"; + + public static final String VNFMMED = "/rest/vnfmmed/"; + + public static final String CONNECTMGR_CONNECT = "/connectmgr/v1/connect"; + + public static final String CONNECTMGR_DISCONNECT = "/connectmgr/v1/disconnect"; + + public static final String CONNECTMGR_HANDSHAKE = "/connectmgr/v1/handshake"; + + public static final String CREATE_VNF_PERF = "/staticsmgr/v1/vnfperformance"; + + public static final String VNFMGR_INSTANCE = "/vnfmgr/v1/instances"; + + public static final String VNF_SCALE = "/vnfmgr/v1/instances/%s/scale"; + + public static final String VNFD_FLAVOR = "/vnfdmgr/v1/flavor"; + + public static final String VNFDGR_INSTALL = "/vnfdmgr/v1/vnfd/%s/install"; + + public static final String VNFDGR_DETAIL = "/vnfdmgr/v1/vnfd/%s"; + + public static final String VNFDGR_DETAILS = "/vnfdmgr/v1/vnfd"; + + public static final String VNFDGR_TOPOLOGY = "/vnfdmgr/v1/topology/%s"; + + public static final String UPDATE_RESOURCE = "/rest/v1/resmanage/resuse/updateres"; + + public static final String VNFDGR_INSTANCE = "/vnfmmed/v1/vnfdm/"; + + public static final String VNF_QUERY = "/resmgr/v1/vnfs"; + + public static final String VMS_QUERY = "/resmgr/v1/vms"; + + public static final String REST_EVENT_ADD = "/rest/v1/resmanage/vnfm/site"; + + public static final String REST_EVENT_DEL = "/rest/v1/resmanage/vnfm/site/%s"; + + public static final String VNFMGR_VNFKPI = "/staticsmgr/v1/vnfkpi"; + + public static final String RES_VNF = "/rest/v1/resmanage/vappvm"; + + public static final String NOTIFY_VNF_PERF = "/rest/v1/resmanage/vappvm"; + + public static final String PARAM_MODULE = "VnfmDriver"; + + public static final String GET_ALL_SITES = "/rest/v1/resmanage/sites"; + + public static final String GET_ALL_SOS = "/rest/sodriver/v1/sos"; + + public static final String OPERATION_LOG_PATH = "/rest/plat/audit/v1/logs"; + + public static final String SYSTEM_LOG_PATH = "/rest/plat/audit/v1/systemlogs"; + + public static final String SECURITY_LOG_PATH = "/rest/plat/audit/v1/seculogs"; + + public static final String SCALINGPOLICY_QUERY = "/policymgr/v1/scalingpolicy"; + + public static final String SCALINGPOLICY_OPERATE = "/policymgr/v1/scalingpolicy/%s/%s"; + + public static final String ACTIVE_POLICY = "/policymgr/v1/activepolicy"; + + public static final String DEACTIVE_POLICY = "/policymgr/v1/deactivepolicy"; + + public static final String GET_VNFM_VNF = "/rest/v1/resmanage/vapps?vnfmId=%s"; + + public static final String GET_RES_NET = "/rest/v1/resmanage/virtualnetworks?id=%s"; + + public static final String GET_JOB_STATUS = "/vnfmgr/v1/jobs/%s"; + + public static final String CREATE_POLICY = "/policymgr/v1/vnfs/%s/policies"; + + public static final String REST_FOR_VNFD_PLANS = "/v2/vapps/templates/%s/plans"; + + public static final String REST_GET_VNFDS = "/v2/vapps/templates"; + + public static final String REST_FOR_VNFD_BASIC = "/v2/vapps/templates?type=basic&vendor=%s&vnfdID=%s&version=%s"; + + public static final String REST_TOPOLOGY = "/v1/vapps/templates/%s?type=templatetopology"; + + public static final String VNF_INSTANCE = "/v2/vapps/instances"; + + public static final String VNF_INSTANCE_DEL = "/v2/vapps/instances/%s"; + + private ParamConstants() { + //Constructor + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/UrlConstant.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/UrlConstant.java new file mode 100644 index 0000000..1074209 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/constant/UrlConstant.java @@ -0,0 +1,54 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.constant; + +/** + * Url constant class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class UrlConstant { + + public static final String REST_DRIVERMGR_REGISTER = "/openoapi/drivermgr/v1/drivers"; + + public static final String REST_MSB_REGISTER = "/api/microservices/v1/services"; + + public static final String REST_ESRINFO_GET = "/openoapi/extsys/v1/vnfms/%s"; + + public static final String REST_VNFDINFO_GET = + "/openoapi/catalog/v1/csars/%s/files?relativePath=%s&relativePath=%s"; + + public static final String REST_MSB_UNREGISTER = "/openoapi/microservices/v1/services/%s/version/%s/nodes/%s/%s"; + + public static final String REST_JUJU_CLIENT_DEPLOY = "/openoapi/jujuvnfm/v1/vnfms/deploy"; + + public static final String REST_JUJU_CLIENT_DESTORY = "/openoapi/jujuvnfm/v1/vnfms/destroy"; + + public static final String REST_JUJU_CLIENT_GET = "/openoapi/jujuvnfm/v1/vnfms/status?modelName=%s"; + + public static final String RES_VNF = "/openoapi/nslcm/v1/ns/grantvnf"; + public static final String REST_JUJU_VNFM_GRANT_URL = "/openoapi/jujuvnfm/v1/instances/%s/grant"; + + public static final String REST_CSARINFO_GET = "/openoapi/catalog/v1/csars/%s"; + + private UrlConstant() { + // Constructor + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuDriver.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuDriver.java new file mode 100644 index 0000000..d4b4f50 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuDriver.java @@ -0,0 +1,203 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import java.util.List; + +import net.sf.json.JSONObject; + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * + * Juju Driver Class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class JujuDriver { + + private String serviceName; + + private String protocol; + + private String version; + + private String visualRange; + + private String url; + + private List nodes; + + private String ip; + + private String port; + + private String ttl; + + private String status; + + public static final String NOTES = "notes"; + + public JujuDriver() { + // Default Constructor + } + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @param jujuJsonObject + * @since NFVO 0.5 + */ + public JujuDriver(JSONObject jujuJsonObject) { + this.serviceName = jujuJsonObject.getString("serviceName"); + this.protocol = jujuJsonObject.getString("protocol"); + this.version = jujuJsonObject.getString("version"); + this.visualRange = jujuJsonObject.getString("visualRange"); + this.url = jujuJsonObject.getString("url"); + this.nodes = jujuJsonObject.getJSONArray("nodes"); + this.ip = jujuJsonObject.getJSONArray(NOTES).getString(0); + this.port = jujuJsonObject.getJSONArray(NOTES).getString(1); + this.ttl = jujuJsonObject.getJSONArray(NOTES).getString(2); + this.status = jujuJsonObject.getString("status"); + } + + public String getServiceName() { + return serviceName; + } + + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + public String getVisualRange() { + return visualRange; + } + + public void setVisualRange(String visualRange) { + this.visualRange = visualRange; + } + + public String getProtocol() { + return protocol; + } + + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public List getNodes() { + return nodes; + } + + public void setNodes(List nodes) { + this.nodes = nodes; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getIP() { + return ip; + } + + public void setIP(String ip) { + this.ip = ip; + } + + public String getPort() { + return port; + } + + public void setPort(String port) { + this.port = port; + } + + public String getTtl() { + return ttl; + } + + public void setTtl(String ttl) { + this.ttl = ttl; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((serviceName == null) ? 0 : serviceName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) { + return true; + } + if(obj == null) { + return false; + } + if(!(obj instanceof JujuDriver)) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + JujuDriver other = (JujuDriver)obj; + if(serviceName == null) { + if(other.serviceName != null) { + return false; + } + } else if(!serviceName.equals(other.serviceName)) { + return false; + } + return true; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfd.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfd.java new file mode 100644 index 0000000..bab793a --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfd.java @@ -0,0 +1,93 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + + +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; + +/** + * + * Juju vnfd class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class JujuVnfd { + + private String downloadUri; + + private String localPath; + + public String getDownloadUri() { + return downloadUri; + } + + public void setDownloadUri(String downloadUri) { + this.downloadUri = downloadUri; + } + + public String getLocalPath() { + return localPath; + } + + public void setLocalPath(String localPath) { + this.localPath = localPath; + } + + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((downloadUri == null) ? 0 : downloadUri.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) { + return true; + } + if(obj == null) { + return false; + } + if(!(obj instanceof JujuVnfd)) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + JujuVnfd other = (JujuVnfd)obj; + if(downloadUri == null) { + if(other.downloadUri != null) { + return false; + } + } else if(!downloadUri.equals(other.downloadUri)) { + return false; + } + return true; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfm.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfm.java new file mode 100644 index 0000000..4a15e46 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfm.java @@ -0,0 +1,366 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import net.sf.json.JSONObject; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.openo.nfvo.jujuvnfmadapter.common.CryptUtil; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; + +/** + * + * Juju vnfm Class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class JujuVnfm { + + private String id; + + private String name; + + private String type; + + private String version; + + private String userName; + + private String pwd; + + private String url; + + private String vendor; + + private String extraInfo; + + private String status; + + private String createAt; + + private String updateAt; + + /** + * <br> + * + * @return String + */ + public String getId() { + return id; + } + + /** + * <br> + * + * @param id + */ + public void setId(String id) { + this.id = id; + } + + /** + * <br> + * + * @return String + */ + public String getType() { + return type; + } + + /** + * <br> + * + * @param type + */ + public void setType(String type) { + this.type = type; + } + + /** + * <br> + * + * @return String + */ + public String getName() { + return name; + } + + /** + * <br> + * + * @param name + */ + public void setName(String name) { + this.name = name; + } + + /** + * <br> + * + * @return String + */ + public String getVersion() { + return version; + } + + /** + * <br> + * + * @param version + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * <br> + * + * @return String + */ + public String getUserName() { + return userName; + } + + /** + * <br> + * + * @param userName + */ + public void setUserName(String userName) { + this.userName = userName; + } + + /** + * <br> + * + * @return String + */ + public String getUrl() { + return url; + } + + /** + * <br> + * + * @param url + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * <br> + * + * @return String + */ + public String getPwd() { + return pwd; + } + + /** + * <br> + * + * @param pwd + */ + public void setPwd(String pwd) { + this.pwd = pwd; + } + + /** + * <br> + * + * @return String + */ + public String getVendor() { + return vendor; + } + + /** + * <br> + * + * @param vendor + */ + public void setVendor(String vendor) { + this.vendor = vendor; + } + + /** + * <br> + * + * @return String + */ + public String getExtraInfo() { + return extraInfo; + } + + /** + * <br> + * + * @param extraInfo + */ + public void setExtraInfo(String extraInfo) { + this.extraInfo = extraInfo; + } + + /** + * <br> + * + * @return + */ + public String getStatus() { + return status; + } + + /** + * <br> + * + * @param status + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * <br> + * + * @return + */ + public String getCreateAt() { + return createAt; + } + + /** + * <br> + * + * @param createAt + */ + public void setCreateAt(String createAt) { + this.createAt = createAt; + } + + /** + * <br> + * + * @return + */ + public String getUpdateAt() { + return updateAt; + } + + /** + * <br> + * + * @param updateAt + */ + public void setUpdateAt(String updateAt) { + this.updateAt = updateAt; + } + + /** + * <br/> + * + * @return + */ + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } + + /** + * <br/> + * + * @return + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + /** + * <br/> + * + * @param obj + * @return + */ + @Override + public boolean equals(Object obj) { + if(this == obj) { + return true; + } + if(obj == null) { + return false; + } + if(!(obj instanceof JujuVnfm)) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + JujuVnfm other = (JujuVnfm)obj; + if(id == null) { + if(other.id != null) { + return false; + } + } else if(!id.equals(other.id)) { + return false; + } + return true; + } + + /** + * + * Update Vnfm.<br> + * + * @param otherVnfm + * @since NFVO 0.5 + */ + public void updateVnfm(JSONObject otherVnfm) { + String vnfmName = otherVnfm.getString("name"); + String vnfmUserName = otherVnfm.getString("userName"); + String vnfmPwd = CryptUtil.enCrypt(otherVnfm.getString("pwd")); + + if(!StringUtils.isEmpty(vnfmName)) { + this.name = vnfmName; + } + + if(!StringUtils.isEmpty(vnfmUserName)) { + this.userName = vnfmUserName; + } + + if(!StringUtils.isEmpty(vnfmPwd)) { + this.pwd = vnfmPwd; + } + + String vnfmExtraInfo = otherVnfm.get("extraInfo").toString(); + if(!StringUtils.isEmpty(vnfmExtraInfo)) { + this.extraInfo = vnfmExtraInfo; + } + + this.updateAt = new SimpleDateFormat(Constant.DATE_FORMAT).format(new Date()); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfo.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfo.java new file mode 100644 index 0000000..d3844fa --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfo.java @@ -0,0 +1,141 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import java.io.Serializable; +import java.util.Date; + +/** + * + * + * @author z00292420 + * @date 2016-9-12* + + */ +public class JujuVnfmInfo implements Serializable { + /** */ + private String id; + + /** */ + private String vnfmId; + + /** */ + private String vnfId; + + /** */ + private String appName; + + /** */ + private String jobId; + + /** */ + private Integer status; + + /** */ + private Date createTime; + + /** */ + private Date modifyTime; + + /** */ + private Date deleteTime; + + /** */ + private String extend; + + private static final long serialVersionUID = 1L; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getVnfmId() { + return vnfmId; + } + + public void setVnfmId(String vnfmId) { + this.vnfmId = vnfmId; + } + + public String getVnfId() { + return vnfId; + } + + public void setVnfId(String vnfId) { + this.vnfId = vnfId; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getJobId() { + return jobId; + } + + public void setJobId(String jobId) { + this.jobId = jobId; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public Date getCreateTime() { + return createTime; + } + + public void setCreateTime(Date createTime) { + this.createTime = createTime; + } + + public Date getModifyTime() { + return modifyTime; + } + + public void setModifyTime(Date modifyTime) { + this.modifyTime = modifyTime; + } + + public Date getDeleteTime() { + return deleteTime; + } + + public void setDeleteTime(Date deleteTime) { + this.deleteTime = deleteTime; + } + + public String getExtend() { + return extend; + } + + public void setExtend(String extend) { + this.extend = extend; + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoExample.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoExample.java new file mode 100644 index 0000000..560aee8 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoExample.java @@ -0,0 +1,1682 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * JUJU VNFM Information example + * .</br> + * + * @author + * @version NFVO 0.5 Sep 14, 2016 + */ +public class JujuVnfmInfoExample { + protected String orderByClause; + + protected boolean distinct; + + protected List<Criteria> oredCriteria; + + protected int limitStart = -1; + + protected int limitEnd = -1; + + public static final String VNFM_ID = "vnfmId"; + + public static final String VNF_ID = "vnfId"; + + public static final String APP_NAME = "appName"; + + public static final String JOB_ID = "jobId"; + + public static final String STATUS = "status"; + + public static final String CREATE_TIME = "createTime"; + + public static final String MODIFY_TIME = "modifyTime"; + + public static final String DELETE_TIME = "deleteTime"; + + /** + * Constructor<br/> + * <p> + * </p> + */ + public JujuVnfmInfoExample() { + oredCriteria = new ArrayList<>(); + } + + public void setOrderByClause(String orderByClause) { + this.orderByClause = orderByClause; + } + + public String getOrderByClause() { + return orderByClause; + } + + public void setDistinct(boolean distinct) { + this.distinct = distinct; + } + + public boolean isDistinct() { + return distinct; + } + + public List<Criteria> getOredCriteria() { + return oredCriteria; + } + + /** + * <br> + * + * @param criteria + */ + public void or(Criteria criteria) { + oredCriteria.add(criteria); + } + + /** + * <br> + * + * @return + */ + public Criteria or() { + Criteria criteria = createCriteriaInternal(); + oredCriteria.add(criteria); + return criteria; + } + + /** + * <br> + * + * @return + */ + public Criteria createCriteria() { + Criteria criteria = createCriteriaInternal(); + if (oredCriteria.isEmpty()) { + oredCriteria.add(criteria); + } + return criteria; + } + + protected Criteria createCriteriaInternal() { + return new Criteria(); + } + + /** + * <br> + * + */ + public void clear() { + oredCriteria.clear(); + orderByClause = null; + distinct = false; + } + + public void setLimitStart(int limitStart) { + this.limitStart=limitStart; + } + + public int getLimitStart() { + return limitStart; + } + + public void setLimitEnd(int limitEnd) { + this.limitEnd=limitEnd; + } + + public int getLimitEnd() { + return limitEnd; + } + + protected static class GeneratedCriteria { + protected List<Criterion> criteria; + + protected GeneratedCriteria() { + super(); + criteria = new ArrayList<>(); + } + + public boolean isValid() { + return !criteria.isEmpty(); + } + + public List<Criterion> getAllCriteria() { + return criteria; + } + + public List<Criterion> getCriteria() { + return criteria; + } + + protected void addCriterion(String condition) { + if (condition == null) { + throw new RuntimeException("Value for condition cannot be null"); //NOSONAR + } + criteria.add(new Criterion(condition)); + } + + protected void addCriterion(String condition, Object value, String property) { + if (value == null) { + throw new RuntimeException("Value for " + property + " cannot be null"); //NOSONARr + } + criteria.add(new Criterion(condition, value)); + } + + protected void addCriterion(String condition, Object value1, Object value2, String property) { + if (value1 == null || value2 == null) { + throw new RuntimeException("Between values for " + property + " cannot be null"); //NOSONAR + } + criteria.add(new Criterion(condition, value1, value2)); + } + + /** + * <br> + * + * @return + */ + public Criteria andIdIsNull() { + addCriterion("ID is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andIdIsNotNull() { + addCriterion("ID is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andIdEqualTo(String value) { + addCriterion("ID =", value, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andIdNotEqualTo(String value) { + addCriterion("ID <>", value, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andIdGreaterThan(String value) { + addCriterion("ID >", value, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andIdGreaterThanOrEqualTo(String value) { + addCriterion("ID >=", value, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andIdLessThan(String value) { + addCriterion("ID <", value, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andIdLessThanOrEqualTo(String value) { + addCriterion("ID <=", value, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andIdLike(String value) { + addCriterion("ID like", value, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andIdNotLike(String value) { + addCriterion("ID not like", value, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andIdIn(List<String> values) { + addCriterion("ID in", values, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andIdNotIn(List<String> values) { + addCriterion("ID not in", values, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andIdBetween(String value1, String value2) { + addCriterion("ID between", value1, value2, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andIdNotBetween(String value1, String value2) { + addCriterion("ID not between", value1, value2, "id"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andVnfmIdIsNull() { + addCriterion("VNFM_ID is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andVnfmIdIsNotNull() { + addCriterion("VNFM_ID is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfmIdEqualTo(String value) { + addCriterion("VNFM_ID =", value, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfmIdNotEqualTo(String value) { + addCriterion("VNFM_ID <>", value, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfmIdGreaterThan(String value) { + addCriterion("VNFM_ID >", value, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfmIdGreaterThanOrEqualTo(String value) { + addCriterion("VNFM_ID >=", value, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfmIdLessThan(String value) { + addCriterion("VNFM_ID <", value, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfmIdLessThanOrEqualTo(String value) { + addCriterion("VNFM_ID <=", value, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfmIdLike(String value) { + addCriterion("VNFM_ID like", value, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfmIdNotLike(String value) { + addCriterion("VNFM_ID not like", value, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andVnfmIdIn(List<String> values) { + addCriterion("VNFM_ID in", values, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andVnfmIdNotIn(List<String> values) { + addCriterion("VNFM_ID not in", values, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andVnfmIdBetween(String value1, String value2) { + addCriterion("VNFM_ID between", value1, value2, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andVnfmIdNotBetween(String value1, String value2) { + addCriterion("VNFM_ID not between", value1, value2, VNFM_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andVnfIdIsNull() { + addCriterion("VNF_ID is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andVnfIdIsNotNull() { + addCriterion("VNF_ID is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfIdEqualTo(String value) { + addCriterion("VNF_ID =", value, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfIdNotEqualTo(String value) { + addCriterion("VNF_ID <>", value, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfIdGreaterThan(String value) { + addCriterion("VNF_ID >", value, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfIdGreaterThanOrEqualTo(String value) { + addCriterion("VNF_ID >=", value, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfIdLessThan(String value) { + addCriterion("VNF_ID <", value, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfIdLessThanOrEqualTo(String value) { + addCriterion("VNF_ID <=", value, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfIdLike(String value) { + addCriterion("VNF_ID like", value, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andVnfIdNotLike(String value) { + addCriterion("VNF_ID not like", value, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andVnfIdIn(List<String> values) { + addCriterion("VNF_ID in", values, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andVnfIdNotIn(List<String> values) { + addCriterion("VNF_ID not in", values, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andVnfIdBetween(String value1, String value2) { + addCriterion("VNF_ID between", value1, value2, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andVnfIdNotBetween(String value1, String value2) { + addCriterion("VNF_ID not between", value1, value2, VNF_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andAppNameIsNull() { + addCriterion("APP_NAME is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andAppNameIsNotNull() { + addCriterion("APP_NAME is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andAppNameEqualTo(String value) { + addCriterion("APP_NAME =", value, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andAppNameNotEqualTo(String value) { + addCriterion("APP_NAME <>", value, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andAppNameGreaterThan(String value) { + addCriterion("APP_NAME >", value, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andAppNameGreaterThanOrEqualTo(String value) { + addCriterion("APP_NAME >=", value, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andAppNameLessThan(String value) { + addCriterion("APP_NAME <", value, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andAppNameLessThanOrEqualTo(String value) { + addCriterion("APP_NAME <=", value, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andAppNameLike(String value) { + addCriterion("APP_NAME like", value, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andAppNameNotLike(String value) { + addCriterion("APP_NAME not like", value, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andAppNameIn(List<String> values) { + addCriterion("APP_NAME in", values, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andAppNameNotIn(List<String> values) { + addCriterion("APP_NAME not in", values, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andAppNameBetween(String value1, String value2) { + addCriterion("APP_NAME between", value1, value2, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andAppNameNotBetween(String value1, String value2) { + addCriterion("APP_NAME not between", value1, value2, APP_NAME); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andJobIdIsNull() { + addCriterion("JOB_ID is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andJobIdIsNotNull() { + addCriterion("JOB_ID is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andJobIdEqualTo(String value) { + addCriterion("JOB_ID =", value, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andJobIdNotEqualTo(String value) { + addCriterion("JOB_ID <>", value, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andJobIdGreaterThan(String value) { + addCriterion("JOB_ID >", value, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andJobIdGreaterThanOrEqualTo(String value) { + addCriterion("JOB_ID >=", value, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andJobIdLessThan(String value) { + addCriterion("JOB_ID <", value, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andJobIdLessThanOrEqualTo(String value) { + addCriterion("JOB_ID <=", value, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andJobIdLike(String value) { + addCriterion("JOB_ID like", value, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andJobIdNotLike(String value) { + addCriterion("JOB_ID not like", value, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andJobIdIn(List<String> values) { + addCriterion("JOB_ID in", values, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andJobIdNotIn(List<String> values) { + addCriterion("JOB_ID not in", values, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andJobIdBetween(String value1, String value2) { + addCriterion("JOB_ID between", value1, value2, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andJobIdNotBetween(String value1, String value2) { + addCriterion("JOB_ID not between", value1, value2, JOB_ID); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andStatusIsNull() { + addCriterion("STATUS is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andStatusIsNotNull() { + addCriterion("STATUS is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andStatusEqualTo(Integer value) { + addCriterion("STATUS =", value, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andStatusNotEqualTo(Integer value) { + addCriterion("STATUS <>", value, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andStatusGreaterThan(Integer value) { + addCriterion("STATUS >", value, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andStatusGreaterThanOrEqualTo(Integer value) { + addCriterion("STATUS >=", value, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andStatusLessThan(Integer value) { + addCriterion("STATUS <", value, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andStatusLessThanOrEqualTo(Integer value) { + addCriterion("STATUS <=", value, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andStatusIn(List<Integer> values) { + addCriterion("STATUS in", values, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andStatusNotIn(List<Integer> values) { + addCriterion("STATUS not in", values, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andStatusBetween(Integer value1, Integer value2) { + addCriterion("STATUS between", value1, value2, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andStatusNotBetween(Integer value1, Integer value2) { + addCriterion("STATUS not between", value1, value2, STATUS); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andCreateTimeIsNull() { + addCriterion("CREATE_TIME is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andCreateTimeIsNotNull() { + addCriterion("CREATE_TIME is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andCreateTimeEqualTo(Date value) { + addCriterion("CREATE_TIME =", value, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andCreateTimeNotEqualTo(Date value) { + addCriterion("CREATE_TIME <>", value, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andCreateTimeGreaterThan(Date value) { + addCriterion("CREATE_TIME >", value, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andCreateTimeGreaterThanOrEqualTo(Date value) { + addCriterion("CREATE_TIME >=", value, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andCreateTimeLessThan(Date value) { + addCriterion("CREATE_TIME <", value, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andCreateTimeLessThanOrEqualTo(Date value) { + addCriterion("CREATE_TIME <=", value, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andCreateTimeIn(List<Date> values) { + addCriterion("CREATE_TIME in", values, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andCreateTimeNotIn(List<Date> values) { + addCriterion("CREATE_TIME not in", values, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andCreateTimeBetween(Date value1, Date value2) { + addCriterion("CREATE_TIME between", value1, value2, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andCreateTimeNotBetween(Date value1, Date value2) { + addCriterion("CREATE_TIME not between", value1, value2, CREATE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andModifyTimeIsNull() { + addCriterion("MODIFY_TIME is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andModifyTimeIsNotNull() { + addCriterion("MODIFY_TIME is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andModifyTimeEqualTo(Date value) { + addCriterion("MODIFY_TIME =", value, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andModifyTimeNotEqualTo(Date value) { + addCriterion("MODIFY_TIME <>", value, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andModifyTimeGreaterThan(Date value) { + addCriterion("MODIFY_TIME >", value, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andModifyTimeGreaterThanOrEqualTo(Date value) { + addCriterion("MODIFY_TIME >=", value, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andModifyTimeLessThan(Date value) { + addCriterion("MODIFY_TIME <", value, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andModifyTimeLessThanOrEqualTo(Date value) { + addCriterion("MODIFY_TIME <=", value, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andModifyTimeIn(List<Date> values) { + addCriterion("MODIFY_TIME in", values, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andModifyTimeNotIn(List<Date> values) { + addCriterion("MODIFY_TIME not in", values, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andModifyTimeBetween(Date value1, Date value2) { + addCriterion("MODIFY_TIME between", value1, value2, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andModifyTimeNotBetween(Date value1, Date value2) { + addCriterion("MODIFY_TIME not between", value1, value2, MODIFY_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andDeleteTimeIsNull() { + addCriterion("DELETE_TIME is null"); + return (Criteria) this; + } + + /** + * <br> + * + * @return + */ + public Criteria andDeleteTimeIsNotNull() { + addCriterion("DELETE_TIME is not null"); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andDeleteTimeEqualTo(Date value) { + addCriterion("DELETE_TIME =", value, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andDeleteTimeNotEqualTo(Date value) { + addCriterion("DELETE_TIME <>", value, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andDeleteTimeGreaterThan(Date value) { + addCriterion("DELETE_TIME >", value, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andDeleteTimeGreaterThanOrEqualTo(Date value) { + addCriterion("DELETE_TIME >=", value, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andDeleteTimeLessThan(Date value) { + addCriterion("DELETE_TIME <", value, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value + * @return + */ + public Criteria andDeleteTimeLessThanOrEqualTo(Date value) { + addCriterion("DELETE_TIME <=", value, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andDeleteTimeIn(List<Date> values) { + addCriterion("DELETE_TIME in", values, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param values + * @return + */ + public Criteria andDeleteTimeNotIn(List<Date> values) { + addCriterion("DELETE_TIME not in", values, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andDeleteTimeBetween(Date value1, Date value2) { + addCriterion("DELETE_TIME between", value1, value2, DELETE_TIME); + return (Criteria) this; + } + + /** + * <br> + * + * @param value1 + * @param value2 + * @return + */ + public Criteria andDeleteTimeNotBetween(Date value1, Date value2) { + addCriterion("DELETE_TIME not between", value1, value2, DELETE_TIME); + return (Criteria) this; + } + } + + /** + * <br> + * <p> + * </p> + * + * @author z00292420 + * @date 2016-9-14 + */ + public static class Criteria extends GeneratedCriteria { + + protected Criteria() { + super(); + } + } + + /** + * Criterion + * .</br> + * + * @author + * @version NFVO 0.5 Sep 14, 2016 + */ + public static class Criterion { + private String condition; + + private Object value; + + private Object secondValue; + + private boolean noValue; + + private boolean singleValue; + + private boolean betweenValue; + + private boolean listValue; + + private String typeHandler; + + + + /** + * Constructor<br/> + * <p> + * </p> + * + * @param condition + */ + protected Criterion(String condition) { + super(); + this.condition = condition; + this.typeHandler = null; + this.noValue = true; + } + + /** + * Constructor<br/> + * <p> + * </p> + * + * @param condition + * @param value + * @param typeHandler + */ + protected Criterion(String condition, Object value, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.typeHandler = typeHandler; + if (value instanceof List<?>) { + this.listValue = true; + } else { + this.singleValue = true; + } + } + + /** + * Constructor<br/> + * <p> + * </p> + * + * @param condition + * @param value + */ + protected Criterion(String condition, Object value) { + this(condition, value, null); + } + + /** + * Constructor<br/> + * <p> + * </p> + * + * @param condition + * @param value + * @param secondValue + * @param typeHandler + */ + protected Criterion(String condition, Object value, Object secondValue, String typeHandler) { + super(); + this.condition = condition; + this.value = value; + this.secondValue = secondValue; + this.typeHandler = typeHandler; + this.betweenValue = true; + } + + /** + * Constructor<br/> + * <p> + * </p> + * + * @param condition + * @param value + * @param secondValue + */ + protected Criterion(String condition, Object value, Object secondValue) { + this(condition, value, secondValue, null); + } + + + /** + * <br> + * + * @return + */ + public String getCondition() { + return condition; + } + + /** + * <br> + * + * @return + */ + public Object getValue() { + return value; + } + + /** + * <br> + * + * @return + */ + public Object getSecondValue() { + return secondValue; + } + + /** + * <br> + * + * @return + */ + public boolean isNoValue() { + return noValue; + } + + /** + * <br> + * + * @return + */ + public boolean isSingleValue() { + return singleValue; + } + + /** + * <br> + * + * @return + */ + public boolean isBetweenValue() { + return betweenValue; + } + + /** + * <br> + * + * @return + */ + public boolean isListValue() { + return listValue; + } + + /** + * <br> + * + * @return + */ + public String getTypeHandler() { + return typeHandler; + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/MSBRequestEntity.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/MSBRequestEntity.java new file mode 100644 index 0000000..4ac27f2 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/MSBRequestEntity.java @@ -0,0 +1,370 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import java.io.Serializable; +import java.util.List; + +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; + +/** + * <br/> + * <p> + * The request parameters of Register service to the Microservice Bus + * URL-path: /openoapi/microservices/v1/services + * example: + * { + * "serviceName": "catalog", + * "version": "v1", + * "url": "/openoapi/catalog/v1", + * "protocol": "REST", + * "visualRange": ["1"], + * "nodes": [ + * { + * "ip": "10.74.56.36", + * "port": "8988", + * "ttl": 0 + * } + * ] + * } + * </p> + * <p> + * the response example: + * { + * "serviceName": "catalog", + * "version": "v1", + * "url": "/openoapi/catalog/v1", + * "protocol": "REST", + * "visualRange": ["1"], + * "nodes": [ + * { + * "ip": "10.74.55.66", + * "port": "6666", + * "ttl": 0, + * "expiration": "2016-02-18T16:19:40+08:00", + * "created_at": "2016-02-18T16:03:00+08:00", + * "updated_at": "2016-02-18T16:03:00+08:00" + * }, + * { + * "ip": "10.74.56.37", + * "port": "8989", + * "ttl": 0, + * "expiration": "2016-02-18T16:13:00+08:00", + * "created_at": "2016-02-18T16:03:00+08:00", + * "updated_at": "2016-02-18T16:03:00+08:00" + * }, + * { + * "ip": "10.74.56.36", + * "port": "8988", + * "ttl": 0, + * "expiration": "2016-02-18T17:04:36+08:00", + * "created_at": "2016-02-18T16:03:00+08:00", + * "updated_at": "2016-02-18T16:03:00+08:00" + * } + * ], + * "status": "1" + * } + * the params description: + * serviceName: service name + * version: version + * url: url of the created service instance + * protocol: supported protocols: 'REST', 'UI' + * nodes: the service instance nodes list to register + * ip: the ip of the service instance node, it could also be a hostname like catalog.openo.org + * port: the port of the service instance node + * ttl: time to live, this parameter is reserved for later use + * status: service status, 1: eanbled, 0:disabled + * </p> + * + * @author + * @version NFVO 0.5 Aug 18, 2016 + */ +public class MSBRequestEntity implements Serializable { + + /** + * + */ + private static final long serialVersionUID = -4548158998952436572L; + + private String serviceName; + + private String version; + + /** + * the actual URL of the service to be registered + */ + private String url; + + /** + * supported protocols: 'REST', 'UI' + */ + private String protocol = "REST"; + + /** + * Visibility of the service. + * External(can be accessed by external systems):0 + * Internal(can only be accessed by OPEN-O consumers):1 + */ + private String visualRange = "1"; + + /** + * only exist in response; + * status: service status, 1: eanbled, 0:disabled + */ + private String status; + + /** + * ip: the ip of the service instance node, it could also be a hostname like catalog.openo.org + * port: the port of the service instance node + * ttl: time to live, this parameter is reserved for later use + */ + private List<Node> nodes; + + /** + * @return Returns the serviceName. + */ + public String getServiceName() { + return serviceName; + } + + /** + * @param serviceName The serviceName to set. + */ + public void setServiceName(String serviceName) { + this.serviceName = serviceName; + } + + /** + * @return Returns the version. + */ + public String getVersion() { + return version; + } + + /** + * @param version The version to set. + */ + public void setVersion(String version) { + this.version = version; + } + + /** + * @return Returns the url. + */ + public String getUrl() { + return url; + } + + /** + * @param url The url to set. + */ + public void setUrl(String url) { + this.url = url; + } + + /** + * @return Returns the protocol. + */ + public String getProtocol() { + return protocol; + } + + /** + * @param protocol The protocol to set. + */ + public void setProtocol(String protocol) { + this.protocol = protocol; + } + + /** + * @return Returns the visualRange. + */ + public String getVisualRange() { + return visualRange; + } + + /** + * @param visualRange The visualRange to set. + */ + public void setVisualRange(String visualRange) { + this.visualRange = visualRange; + } + + /** + * @return Returns the status. + */ + public String getStatus() { + return status; + } + + /** + * @param status The status to set. + */ + public void setStatus(String status) { + this.status = status; + } + + /** + * @return Returns the nodes. + */ + public List<Node> getNodes() { + return nodes; + } + + /** + * @param nodes The nodes to set. + */ + public void setNodes(List<Node> nodes) { + this.nodes = nodes; + } + + /** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 18, 2016 + */ + public static class Node implements Serializable { + + /** + * + */ + private static final long serialVersionUID = 7618395945064516270L; + + private String ip; + + private String port; + + private String ttl; + + private String expiration; + + private String createdAt; + + private String updatedAt; + + /** + * @return Returns the ip. + */ + public String getIp() { + return ip; + } + + /** + * @param ip The ip to set. + */ + public void setIp(String ip) { + this.ip = ip; + } + + /** + * @return Returns the port. + */ + public String getPort() { + return port; + } + + /** + * @param port The port to set. + */ + public void setPort(String port) { + this.port = port; + } + + /** + * @return Returns the ttl. + */ + public String getTtl() { + return ttl; + } + + /** + * @param ttl The ttl to set. + */ + public void setTtl(String ttl) { + this.ttl = ttl; + } + + /** + * @return Returns the expiration. + */ + public String getExpiration() { + return expiration; + } + + /** + * @param expiration The expiration to set. + */ + public void setExpiration(String expiration) { + this.expiration = expiration; + } + + /** + * @return Returns the created_at. + */ + public String getCreatedAt() { + return createdAt; + } + + /** + * @param createdAt The created_at to set. + */ + public void setCreatedAt(String createdAt) { + this.createdAt = createdAt; + } + + /** + * @return Returns the updated_at. + */ + public String getUpdatedAt() { + return updatedAt; + } + + /** + * @param updatedAt The updated_at to set. + */ + public void setUpdatedAt(String updatedAt) { + this.updatedAt = updatedAt; + } + + /** + * <br/> + * + * @return + * @since NFVO 0.5 + */ + @Override + public String toString() { + return EntityUtils.toString(this, Node.class); + } + + } + + /** + * <br/> + * + * @return + * @since NFVO 0.5 + */ + @Override + public String toString() { + return EntityUtils.toString(this, MSBRequestEntity.class); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/Vnfm.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/Vnfm.java new file mode 100644 index 0000000..b08b2f5 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/Vnfm.java @@ -0,0 +1,232 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import java.text.SimpleDateFormat; +import java.util.Date; + +import net.sf.json.JSONObject; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.builder.ToStringBuilder; +import org.apache.commons.lang3.builder.ToStringStyle; +import org.openo.nfvo.jujuvnfmadapter.common.CryptUtil; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; + +/** + * + * VNFM class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 12, 2016 + */ +public class Vnfm { + + private String id; + + private String name; + + private String type; + + private String version; + + private String userName; + + private String pwd; + + private String url; + + private String sites; + + private String extraInfo; + + private String status; + + private String createAt; + + private String updateAt; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public String getPwd() { + return pwd; + } + + public void setPwd(String pwd) { + this.pwd = pwd; + } + + public String getSites() { + return sites; + } + + public void setSites(String sites) { + this.sites = sites; + } + + public String getExtraInfo() { + return extraInfo; + } + + public void setExtraInfo(String extraInfo) { + this.extraInfo = extraInfo; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getCreateAt() { + return createAt; + } + + public void setCreateAt(String createAt) { + this.createAt = createAt; + } + + public String getUpdateAt() { + return updateAt; + } + + public void setUpdateAt(String updateAt) { + this.updateAt = updateAt; + } + + + + @Override + public String toString() { + return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((id == null) ? 0 : id.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if(this == obj) { + return true; + } + if(obj == null) { + return false; + } + if(!(obj instanceof Vnfm)) { + return false; + } + if(getClass() != obj.getClass()) { + return false; + } + Vnfm other = (Vnfm)obj; + if(id == null) { + if(other.id != null) { + return false; + } + } else if(!id.equals(other.id)) { + return false; + } + return true; + } + + /** + * + * Update Vnfm.<br> + * + * @param otherVnfm + * @since NFVO 0.5 + */ + public void updateVnfm(JSONObject otherVnfm) { + String vnfmName = otherVnfm.getString("name"); + String vnfmUserName = otherVnfm.getString("userName"); + String vnfmPwd = CryptUtil.enCrypt(otherVnfm.getString("pwd")); + + if(!StringUtils.isEmpty(vnfmName)) { + this.name = vnfmName; + } + + if(!StringUtils.isEmpty(vnfmUserName)) { + this.userName = vnfmUserName; + } + + if(!StringUtils.isEmpty(vnfmPwd)) { + this.pwd = vnfmPwd; + } + + String vnfmExtraInfo = otherVnfm.get("extraInfo").toString(); + if(!StringUtils.isEmpty(vnfmExtraInfo)) { + this.extraInfo = vnfmExtraInfo; + } + + this.updateAt = new SimpleDateFormat(Constant.DATE_FORMAT).format(new Date()); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmOpResult.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmOpResult.java new file mode 100644 index 0000000..9c3e626 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmOpResult.java @@ -0,0 +1,125 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import java.util.ArrayList; +import java.util.List; + +/** + * + * Vnfm operation result class.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ +public class VnfmOpResult { + + private String errorMessage; + + /** + * + * Task status enumerator.<br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 10, 2016 + */ + public enum TaskStatus { + INIT, SUCCESS, FAIL, PART_SUCCESS, RUNNING, TIMEOUT + } + + private TaskStatus operateStatus; + + private List<Object> results = new ArrayList<>(10); + + private int errorCode; + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @since NFVO 0.5 + */ + public VnfmOpResult() { + operateStatus = TaskStatus.INIT; + errorMessage = ""; + errorCode = 0; + } + + /** + * + * Constructor<br> + * <p> + * </p> + * + * @param operateStatus + * @param errorMessage + * @since NFVO 0.5 + */ + public VnfmOpResult(TaskStatus operateStatus, String errorMessage) { + this.operateStatus = operateStatus; + this.errorMessage = errorMessage; + errorCode = 0; + } + + public void setOperateStatus(TaskStatus operateStatus) { + this.operateStatus = operateStatus; + } + + public TaskStatus getOperateStatus() { + return operateStatus; + } + + public List<Object> getResult() { + return results; + } + + /** + * + * Add Result.<br> + * + * @param result + * @since NFVO 0.5 + */ + @SuppressWarnings("unchecked") + public void addResult(Object result) { + if(result instanceof List<?>) { + this.results.addAll((List<Object>)result); + } else { + this.results.add(result); + } + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public String getErrorMessage() { + return errorMessage; + } + + @Override + public String toString() { + return getClass().getName() + "@[" + "operateStatus=" + operateStatus + ", " + "errorCode=" + errorCode + ", " + + "errorMessage=" + errorMessage + "]"; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/exception/UnsupportedOperationException.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/exception/UnsupportedOperationException.java new file mode 100644 index 0000000..4d213e5 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/exception/UnsupportedOperationException.java @@ -0,0 +1,34 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.exception; + +/** + * <br/> + * <p> + * + * </p> + * + * @author + * @version NFVO 0.5 Aug 18, 2016 + */ +public class UnsupportedOperationException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = 7599989642681309581L; +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/JujuClientUtils.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/JujuClientUtils.java new file mode 100644 index 0000000..1e72f04 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/JujuClientUtils.java @@ -0,0 +1,97 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.juju; + +import org.python.core.PyInteger; +import org.python.core.PyObject; +import org.python.core.PyString; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 22, 2016 + */ +public class JujuClientUtils { + + private static PyObjectFactory factory ; + + + private JujuClientUtils() { + // private constructor + } + + /** + * call this to connect JUJU VNFM + * <br/> + * + * @param envName + * @since NFVO 0.5 + */ + public static void init(String envName){ + factory = PyObjectFactory.build(envName); + } + + /** + * <br> + * + * @param serviceName + * @param charmUrl + * @return pyObject + */ + public static PyObject setCharm(String serviceName,String charmUrl){ + return factory.execute("set_charm", new PyString(serviceName), new PyString(charmUrl)); + } + /** + * <br> + * + * @param vnfInstanceId + * @param vnfmId + * @return pyObject + */ + public static PyObject getVnfStatus(String vnfInstanceId,String vnfmId){ + return null; + } + + /** + * <br> + * + * @param serviceName + * @param charmUrl + * @param numUnits + * @return pyObject + */ + public static PyObject deployService(String serviceName,String charmUrl, int numUnits){ + PyObject[] arrys = new PyObject[]{new PyString(serviceName), new PyString(charmUrl), new PyInteger(numUnits)}; + return factory.execute("deploy", arrys); + } + /** + * Destory a service and all of it's units. + * <br/> + * + * @param serviceName + * @param charmUrl + * @param numUnits + * @return + * @since NFVO 0.5 + */ + public static PyObject destoryService(String serviceName){ + return factory.execute("deploy",new PyString(serviceName)); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/JujuHelper.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/JujuHelper.java new file mode 100644 index 0000000..ae0bffa --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/JujuHelper.java @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2016, 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.nfvo.jujuvnfmadapter.service.juju; + +import org.apache.commons.lang3.StringUtils; + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Nov 4, 2016 + */ +public class JujuHelper { + + /** + * 1\ toLowerCase + * 2\remove the extension + * 3\remove the underline + * <br/> + * + * @param appName + * @return + * @since NFVO 0.5 + */ + public static String getModelName(String appName){ + if(StringUtils.isBlank(appName)){ + return appName; + } + char c = '.'; + String modelName = appName; + modelName = modelName.toLowerCase(); + if(modelName.indexOf(c) > -1){ + modelName = modelName.substring(0,modelName.indexOf(c)); + } + return modelName.replaceAll("_", ""); + + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/PyObjectFactory.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/PyObjectFactory.java new file mode 100644 index 0000000..2d98290 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/PyObjectFactory.java @@ -0,0 +1,104 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.juju; + +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.util.PythonInterpreter; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 22, 2016 + */ +public class PyObjectFactory { + + private static PyObject environmentClass; + + private static PyObject environmentObj; + + /** + * <br> + * + * @param envName + * @return + * @since NFVO 0.5 + */ + public static PyObjectFactory build(String envName) { + PythonInterpreter interpreter = new PythonInterpreter(); + + interpreter.exec("from jujuclient import Environment"); + + environmentClass = interpreter.get("Environment"); + PyObject env = environmentClass.__call__(); + environmentObj = env.invoke("connect", new PyString(envName)); + return new PyObjectFactory(); + } + + /** + * <br> + * + * @param methodName + * @return + * @since NFVO 0.5 + */ + public PyObject execute(String methodName) { + environmentObj.toString(); + return environmentObj.invoke(methodName); + } + + /** + * <br> + * + * @param methodName + * @param args + * @return + * @since NFVO 0.5 + */ + public PyObject execute(String methodName, PyObject args) { + return environmentObj.invoke(methodName, args); + } + + /** + * <br> + * + * @param methodName + * @param arg1 + * @param arg2 + * @return + * @since NFVO 0.5 + */ + public PyObject execute(String methodName, PyObject arg1, PyObject arg2) { + return environmentObj.invoke(methodName, arg1, arg2); + } + + /** + * <br> + * + * @param methodName + * @param args + * @return + * @since NFVO 0.5 + */ + public PyObject execute(String methodName, PyObject[] args) { + return environmentObj.invoke(methodName, args); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/Config.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/Config.java new file mode 100644 index 0000000..21c0cbc --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/Config.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.juju.config; + +import java.util.Map; + +/** + * Created by QuanZhong on 2016/12/1. + */ +public class Config { + public Config(Map<String, ConfigItem> options) { + this.options = options; + } + + private Map<String,ConfigItem> options; + + public Map<String, ConfigItem> getOptions() { + return options; + } + + public void setOptions(Map<String, ConfigItem> options) { + this.options = options; + } + + @Override + public String toString() { + return "Config{" + + "options=" + options + + '}'; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigItem.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigItem.java new file mode 100644 index 0000000..7edf0b5 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigItem.java @@ -0,0 +1,60 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.juju.config; + +/** + * Created by QuanZhong on 2016/12/1. + */ +public class ConfigItem { + + private String defaults; + private String description; + private String type; + + public String getDefaults() { + return defaults; + } + + public void setDefaults(String defaults) { + this.defaults = defaults; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + @Override + public String toString() { + return "ConfigItem{" + + "defaults='" + defaults + '\'' + + ", description='" + description + '\'' + + ", type='" + type + '\'' + + '}'; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/Options.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/Options.java new file mode 100644 index 0000000..110b9a2 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/Options.java @@ -0,0 +1,23 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.juju.config; + +/** + * Created by QuanZhong on 2016/12/1. + */ +public class Options { +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/mapper/JujuVnfmInfoMapper.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/mapper/JujuVnfmInfoMapper.java new file mode 100644 index 0000000..2b2da41 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/mapper/JujuVnfmInfoMapper.java @@ -0,0 +1,149 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.mapper; + +import java.util.List; + + +import org.apache.ibatis.annotations.Param; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample; + +/** + * <br> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 14, 2016 + */ +public interface JujuVnfmInfoMapper { + /** + * <br> + * + * @param example + * @return int + */ + int countByExample(JujuVnfmInfoExample example); + + /** + * <br> + * + * @param example + * @return int + */ + int deleteByExample(JujuVnfmInfoExample example); + + /** + * <br> + * + * @param id + * @return int + */ + int deleteByPrimaryKey(String id); + + /** + * <br> + * + * @param record + * @return int + */ + int insert(JujuVnfmInfo record); + + /** + * <br> + * + * @param record + * @return int + */ + int insertSelective(JujuVnfmInfo record); + + /** + * <br> + * + * @param example + * @return list + */ + List<JujuVnfmInfo> selectByExampleWithBLOBs(JujuVnfmInfoExample example); + + /** + * <br> + * + * @param example + * @return list + */ + List<JujuVnfmInfo> selectByExample(JujuVnfmInfoExample example); + + /** + * <br> + * + * @param id + * @return jujuVnfmInfo + */ + JujuVnfmInfo selectByPrimaryKey(String id); + + /** + * <br> + * + * @param record + * @param example + * @return int + */ + int updateByExampleSelective(@Param("record") JujuVnfmInfo record, @Param("example") JujuVnfmInfoExample example); + + /** + * <br> + * + * @param record + * @param example + * @return int + */ + int updateByExampleWithBLOBs(@Param("record") JujuVnfmInfo record, @Param("example") JujuVnfmInfoExample example); + + /** + * <br> + * + * @param record + * @param example + * @return int + */ + int updateByExample(@Param("record") JujuVnfmInfo record, @Param("example") JujuVnfmInfoExample example); + + /** + * <br> + * + * @param record + * @return int + */ + int updateByPrimaryKeySelective(JujuVnfmInfo record); + + /** + * <br> + * + * @param record + * @return int + */ + int updateByPrimaryKeyWithBLOBs(JujuVnfmInfo record); + + /** + * <br> + * + * @param record + * @return int + */ + int updateByPrimaryKey(JujuVnfmInfo record); +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfMgr.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfMgr.java new file mode 100644 index 0000000..8dc6070 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfMgr.java @@ -0,0 +1,403 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.service.process; + +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang.StringUtils; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.nfvo.jujuvnfmadapter.common.SwitchController; +import org.openo.nfvo.jujuvnfmadapter.common.VnfmUtil; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IResourceManager; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.constant.UrlConstant; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample; +import org.openo.nfvo.jujuvnfmadapter.service.mapper.JujuVnfmInfoMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONException; +import net.sf.json.JSONObject; + +/** + * Provide function for instantiate or terminate VNF + * <br/> + * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +public class VnfMgr { + + private static final Logger LOG = LoggerFactory.getLogger(VnfMgr.class); + private JujuVnfmInfoMapper jujuVnfmInfoMapper; + private IResourceManager resourceManager; + + public IResourceManager getResourceManager() { + return resourceManager; + } + + public void setResourceManager(IResourceManager resourceManager) { + this.resourceManager = resourceManager; + } + + /** + * @return Returns the jujuVnfmInfoMapper. + */ + public JujuVnfmInfoMapper getJujuVnfmInfoMapper() { + return jujuVnfmInfoMapper; + } + + + /** + * @param jujuVnfmInfoMapper The jujuVnfmInfoMapper to set. + */ + public void setJujuVnfmInfoMapper(JujuVnfmInfoMapper jujuVnfmInfoMapper) { + this.jujuVnfmInfoMapper = jujuVnfmInfoMapper; + } + + /** + * Provide function for instantiate VNF + * <br/> + * + * @param vnfObject + * @param vnfmId + * @return + * @since NFVO 0.5 + */ + public JSONObject addVnf(JSONObject vnfObject, String vnfmId) { + JSONObject restJson = new JSONObject(); + restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_FAIL); + try { + + if(vnfObject.isNullObject() || vnfObject.isEmpty()) { + return restJson; + } + String vnfInstanceName = vnfObject.getString("vnfInstanceName"); + String csarId = vnfObject.getString("vnfPackageId"); + String url = null; + try { + url = vnfObject.getString("vnfmServiceUrl"); + } catch (Exception e) { + LOG.warn("the value 'vnfmServiceUrl' not exist."+e.getMessage()); + } + if (StringUtils.isBlank(url)) { + url = SwitchController.vnfmServiceUrl; + } + if (StringUtils.isBlank(url)) { + JSONObject vnfmObject = VnfmUtil.getVnfmById(vnfmId); + + if(vnfmObject == null || vnfmObject.isNullObject()) { + LOG.error("function=addVnf, msg=Unable to get the jujuvnfm info from the 'ESR', vnfmId: {}", vnfmId); + return restJson; + } + url = vnfmObject.getString("url"); + } + //call juju-cliento deploy + JSONObject params = new JSONObject(); + params.put(Constant.VNFM_ID, vnfmId); + params.put("appName", vnfInstanceName); + params.put("csarId", csarId); + + + Map<String, String> paramsMap = new HashMap<>(6); + paramsMap.put("url", url); + paramsMap.put(Constant.METHOD_TYPE, Constant.POST); + paramsMap.put("path", UrlConstant.REST_JUJU_CLIENT_DEPLOY); + paramsMap.put(Constant.AUTH_MODE, Constant.AuthenticationMode.ANONYMOUS); + RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(paramsMap, params.toString(), null); + if(rsp == null) { + LOG.error("function=addVnf, msg=send create vnf msg to csm get wrong results"); + return restJson; + } + + int statusCode = rsp.getStatus(); + if(statusCode == Constant.HTTP_CREATED || statusCode == Constant.HTTP_OK) { + JSONObject res = JSONObject.fromObject(rsp.getResponseContent()); + String vnfId = res.getString("vnfId"); + saveJujuVnfmInfo(vnfInstanceName,vnfId,vnfId,vnfmId,vnfObject); + restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_SUCCESS); + JSONObject resultObj = new JSONObject(); + resultObj.put("vnfInstanceId", vnfId); + resultObj.put("jobId", vnfId + "_" + Constant.POST); + restJson.put("data", resultObj); + } else { + LOG.error("function=createVnf, msg=send create vnf msg to csm get wrong status: " + statusCode); + } + + } catch(JSONException e) { + LOG.error("function=addVnf, msg=JSONException occurs, e={}.", e); + } + LOG.info("request:{},response:{}", vnfmId, restJson.toString()); + return restJson; + } + + /** + * + * <br/> + * + * @param csarId + * @return + * @since NFVO 0.5 + */ + public String getCharmPath(String csarId){ + try { + JSONObject res = resourceManager.getVnfdInfo(csarId); + if(res != null && res.getString("csarFilePath") != null){ + return res.getString("csarFilePath"); + } + } catch(Exception e) { + LOG.error("get charmPath fail:csarId="+csarId,e); + } + LOG.warn("get charmPath fail:csarId="+csarId); + return null; + } + /** + * save object to db + * <br/> + * + * @param appName + * @param jobId + * @param vnfId + * @param vnfmId + * @since NFVO 0.5 + */ + private void saveJujuVnfmInfo(String appName,String jobId,String vnfId,String vnfmId, JSONObject vnfObject){ + JujuVnfmInfo record = new JujuVnfmInfo(); + record.setId(UUID.randomUUID().toString()); + record.setAppName(appName); + record.setJobId(jobId); + record.setVnfId(vnfId); + record.setVnfmId(vnfmId); + record.setStatus(0); + record.setCreateTime(new Date()); + record.setModifyTime(new Date()); + record.setExtend(vnfObject.toString()); + jujuVnfmInfoMapper.insert(record); + } + /** + * delete the object by vnfid + * <br/> + * + * @param vnfId + * @since NFVO 0.5 + */ + private void delJujuVnfmInfo(String vnfId){ + JujuVnfmInfoExample example = new JujuVnfmInfoExample(); + example.createCriteria().andVnfIdEqualTo(vnfId); + jujuVnfmInfoMapper.deleteByExample(example); + } + + /** + * findByVnfId from db + * <br/> + * + * @param vnfId + * @return + * @since NFVO 0.5 + */ + private JujuVnfmInfo findByVnfId(String vnfId){ + JujuVnfmInfoExample example = new JujuVnfmInfoExample(); + example.createCriteria().andVnfIdEqualTo(vnfId); + List<JujuVnfmInfo> list = jujuVnfmInfoMapper.selectByExample(example); + if(CollectionUtils.isNotEmpty(list) && !list.isEmpty()){ + return list.get(0); + } + return null; + } + + /** + * Provide function for terminate VNF + * <br/> + * + * @param vnfId + * @param vnfmId + * @param vnfObject + * @return + * @since NFVO 0.5 + */ + public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) { + LOG.warn("function=deleteVnf ,msg=enter to delete a vnf, vnfId:{}, vnfmId:{}", vnfId, vnfmId); + JSONObject restJson = new JSONObject(); + restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_FAIL); + try { + String url = SwitchController.vnfmServiceUrl; + + if (StringUtils.isBlank(url)) { + JSONObject vnfmObject = VnfmUtil.getVnfmById(vnfmId); + if(vnfmObject==null || vnfmObject.isNullObject()) { + LOG.error("function=deleteVnf, msg=Unable to get the jujuvnfm info from the 'ESR', vnfmId: {}", vnfmId); + return restJson; + } + url = vnfmObject.getString("url"); + } + + String vnfInstanceName = ""; + JujuVnfmInfo jujuInfo = findByVnfId(vnfId); + if(jujuInfo != null){ + vnfInstanceName = jujuInfo.getAppName(); + } + JSONObject params = new JSONObject(); + params.put(Constant.VNFM_ID, vnfmId); + params.put("appName", vnfInstanceName); + params.put("vnfId", vnfId); + + Map<String, String> paramsMap = new HashMap<>(6); + paramsMap.put("url", url); + paramsMap.put(Constant.METHOD_TYPE, Constant.POST); + paramsMap.put("path", UrlConstant.REST_JUJU_CLIENT_DESTORY); + paramsMap.put(Constant.AUTH_MODE, Constant.AuthenticationMode.ANONYMOUS); + RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(paramsMap, params.toString(), null); + if(rsp == null) { + LOG.error("function=deleteVnf, msg=send create vnf msg to csm get wrong results"); + return restJson; + } + + int statusCode = rsp.getStatus(); + if(statusCode == Constant.UNREG_SUCCESS) { + restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_SUCCESS); + JSONObject resultObj = new JSONObject(); + resultObj.put("jobId", vnfId + "_" + Constant.DELETE); + restJson.put("data", resultObj); + delJujuVnfmInfo(vnfId); + } else { + LOG.error("function=removeVnf, msg=send remove vnf msg to csm get wrong status: {}", statusCode); + } + + } catch(JSONException e) { + LOG.error("function=deleteVnf, msg=JSONException occurs, e={}.", e); + } + return restJson; + } + + /** + * Provide function for get VNF + * <br/> + * + * @param vnfId + * @param vnfmId + * @return + * @since NFVO 0.5 + */ + public JSONObject getVnf(String vnfId, String vnfmId) { + LOG.warn("function=getVnf ,msg=enter to get a vnf, vnfId:{}, vnfmId:{}", vnfId, vnfmId); + JSONObject restJson = new JSONObject(); + restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_FAIL); + try { + String url = SwitchController.vnfmServiceUrl; + JSONObject vnfmObject = null; + if (StringUtils.isBlank(url)) { + // call the ESR to get jujuvnfm server url + vnfmObject = VnfmUtil.getVnfmById(vnfmId); + if(vnfmObject==null || vnfmObject.isNullObject()) { + LOG.error("Unable to get jujuvnfm url info from the 'ESR', vnfmId: {}", vnfmId); + return restJson; + } + url = vnfmObject.getString("url"); + } + + String appName = ""; + JujuVnfmInfo jujuInfo = findByVnfId(vnfId); + if(jujuInfo != null){ + appName = jujuInfo.getAppName(); + } + JSONObject params = new JSONObject(); + params.put(Constant.VNFM_ID, vnfmId); + params.put("vnfId", vnfId); + + + Map<String, String> paramsMap = new HashMap<>(6); + paramsMap.put("url", url); + paramsMap.put(Constant.METHOD_TYPE, Constant.GET); + paramsMap.put("path", String.format(UrlConstant.REST_JUJU_CLIENT_GET,appName)); + paramsMap.put(Constant.AUTH_MODE, Constant.AuthenticationMode.ANONYMOUS); + RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse(paramsMap, params.toString(), null); + if(rsp == null) { + LOG.error("function=getVnf, msg=send create vnf msg to csm get wrong results"); + return restJson; + } + JSONObject queryResult = JSONObject.fromObject(rsp.getResponseContent()); + int statusCode = rsp.getStatus(); + if(statusCode == Constant.HTTP_OK || statusCode == Constant.HTTP_CREATED) { + if(null == (queryResult.get("data"))) { + LOG.warn("function=getVnf, msg=query is null {}", queryResult.get("data")); + return restJson; + } + restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_SUCCESS); + restJson.put("data", JSONObject.fromObject(queryResult.getString("data"))); + } else { + LOG.error("function=getVnf, msg=send get vnf msg to csm get wrong status: {}", statusCode); + } + return restJson.getInt(EntityUtils.RESULT_CODE_KEY) == Constant.REST_FAIL ? restJson + : getVnfBody(vnfId,appName, vnfmObject); + + } catch(JSONException e) { + LOG.error("function=getVnf, msg=JSONException occurs, e={}.", e); + restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_FAIL); + } + return restJson; + } + + private JSONObject getVnfBody(String vnfId,String appName, JSONObject vnfmObject) { + JSONObject vnfInfoJson = new JSONObject(); + JSONObject basicInfoJson = new JSONObject(); + + basicInfoJson.put("vnfInstanceId", vnfId); + basicInfoJson.put("vnfInstanceName", appName); + basicInfoJson.put("vnfInstanceDescription", "vFW"); + basicInfoJson.put("vnfdId", vnfmObject == null ? "" : vnfmObject.getString("vnfdId")); + basicInfoJson.put("vnfdPackageId", vnfmObject == null ? "" : vnfmObject.getString("vnfPackageId")); + basicInfoJson.put("version", vnfmObject == null ? "" : vnfmObject.getString("version")); + basicInfoJson.put("vnfProvider", "hw"); + basicInfoJson.put("vnfType", appName); + basicInfoJson.put("vnfStatus", "activie"); + + vnfInfoJson.put("vnfInfo", basicInfoJson); + vnfInfoJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_SUCCESS); + return vnfInfoJson; + } + + /** + * Provide function for get job + * <br/> + * + * @param jobId + * @param vnfmId + * @return + * @since NFVO 0.5 + */ + public JSONObject getJob(String jobId, String vnfmId) { + LOG.info("getJob->jobId="+jobId+",vnfmId="+vnfmId); + JSONObject jobInfoJson = new JSONObject(); + JSONObject responseJson = new JSONObject(); + jobInfoJson.put("jobId",jobId); + responseJson.put("progress","100"); + responseJson.put("status","finished"); + responseJson.put("errorCode","null"); + responseJson.put("responseId",(Math.random()*10+1)); + jobInfoJson.put("responseDescriptor",responseJson); + LOG.info("get job response:"+jobInfoJson); + return jobInfoJson; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfResourceMgr.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfResourceMgr.java new file mode 100644 index 0000000..434817e --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfResourceMgr.java @@ -0,0 +1,240 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.process; + +import java.util.List; +import java.util.UUID; + +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.openo.nfvo.jujuvnfmadapter.common.SwitchController; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.constant.UrlConstant; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample; +import org.openo.nfvo.jujuvnfmadapter.service.mapper.JujuVnfmInfoMapper; +import org.python.jline.internal.Log; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONArray; +import net.sf.json.JSONException; +import net.sf.json.JSONObject; + +/** + * Provide function of resource for VNFM. + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 25, 2016 + */ +public class VnfResourceMgr { + + private static final Logger LOG = LoggerFactory.getLogger(VnfResourceMgr.class); + + private JujuVnfmInfoMapper jujuVnfmInfoMapper; + + /** + * @return Returns the jujuVnfmInfoMapper. + */ + public JujuVnfmInfoMapper getJujuVnfmInfoMapper() { + return jujuVnfmInfoMapper; + } + + /** + * @param jujuVnfmInfoMapper The jujuVnfmInfoMapper to set. + */ + public void setJujuVnfmInfoMapper(JujuVnfmInfoMapper jujuVnfmInfoMapper) { + this.jujuVnfmInfoMapper = jujuVnfmInfoMapper; + } + + /** + * Provide function of grant resource for VNFM. + * <br/> + * + * @param vnfId + * @return + * @since NFVO 0.5 + */ + public JSONObject grantVnfResource(JSONObject compute, String vnfId) { + LOG.warn("function=grantVnfResource, msg=call LCM to grant vnf resource, params: {}", compute); + JSONObject resultJson = new JSONObject(); + resultJson.put("retCode", Constant.REST_FAIL); + try { + if(SwitchController.isDebugModel()){ + resultJson.put("retCode", Constant.REST_SUCCESS); + resultJson.put("data", "{'mock_result':true}"); + return resultJson; + } + JujuVnfmInfo vnfmInfo = findByVnfId(vnfId); + String vimId = getVimId(vnfmInfo); + JSONObject reqParams = this.buildGrantReq(vimId, vnfId,compute); + + resultJson = VnfmRestfulUtil.sendReqToApp(UrlConstant.RES_VNF, Constant.POST, reqParams); + } catch(JSONException e) { + LOG.error("function=grantVnfResource, msg=parse params occoured JSONException e={}.", e); + resultJson.put("errorMsg", "params parse exception"); + } + + return resultJson; + } + + /** + * { + "vnfInstanceId": 1, + "addResource": [ + { + "resourceDefinitionId": "11111", + "resourceTemplate": { + "VirtualComputeDescriptor": { + "virtualCpu": { + "numVirtualCpu": 1 + }, + "virtualMemory": { + "virtualMemSize": 1//mem in MB + } + }, + "VirtualStorageDescriptor": { + "typeOfStorage": "", + "sizeOfStorage": 111, //disk in GB + "swImageDescriptor": "" + } + }, + "type": "vdu", + "vdu": "vdu_name" + } + ], + "vimId":"", + "removeResource": [], + "additionalParam": {} +} + * + * <br/> + * + * @return + * @since NFVO 0.5 + */ + private JSONObject buildGrantReq(String vimId, String vnfInstanceId,JSONObject compute){ + JSONObject obj = new JSONObject(); + obj.put("vnfInstanceId", vnfInstanceId); + obj.put("vimId", vimId); + obj.put("additionalParam", new JSONObject()); + JSONArray array = new JSONArray(); + JSONObject resource = new JSONObject(); + resource.put("resourceDefinitionId", UUID.randomUUID().toString()); + resource.put("type", "vdu"); + resource.put("vdu", "vdu_name");//vdu_name? + JSONObject resourceTemplate = new JSONObject(); + JSONObject virtualComputeDescriptor = new JSONObject(); + JSONObject virtualCpu = new JSONObject(); + JSONObject virtualMemory = new JSONObject(); + virtualCpu.put("numVirtualCpu", compute.get("cpu") !=null?compute.get("cpu"):0); + virtualMemory.put("virtualMemSize", compute.get("mem") !=null?compute.get("mem"):0); + virtualComputeDescriptor.put("virtualCpu", virtualCpu); + virtualComputeDescriptor.put("virtualMemory", virtualMemory); + JSONObject virtualStorageDescriptor = new JSONObject(); + virtualStorageDescriptor.put("typeOfStorage", ""); + virtualStorageDescriptor.put("swImageDescriptor", ""); + virtualStorageDescriptor.put("sizeOfStorage", compute.get("disk") !=null?compute.get("disk"):0); + resourceTemplate.put("VirtualComputeDescriptor", virtualComputeDescriptor); + resourceTemplate.put("VirtualStorageDescriptor", virtualStorageDescriptor); + resource.put("resourceTemplate", resourceTemplate); + array.add(resource); + if("addResource".equals(compute.getString("action"))){ + obj.put("addResource", array); + obj.put("removeResource", new JSONArray()); + }else{ + obj.put("removeResource", array); + obj.put("addResource", new JSONArray()); + } + Log.info("buildGrantReq->result="+obj); + return obj; + } + + /** + * { + * “vnfInstanceName”:”vFW”, + * “vnfPackageId”:”1”, + * “vnfDescriptorId”:”1”, + * “vnfInstanceDescription”:”vFW_1”, + * “extVirtualLinks”:[ + * { + * ”vlInstanceId”:”1”, + * “resourceId”:”1246”, + * ” cpdId”:”11111”, + * ”vim”: + * { + * “vimInfoId”:”1”, + * “vimid”:”1”, + * “interfaceInfo”:{ + * "vimType":”vim”, + * "apiVersion":”v2”, + * "protocolType":”http” + * } + * “accessInfo”:{ + * "tenant":”tenant_vCPE”, + * "username":”vCPE”, + * "password":”vCPE_321” + * } + * “interfaceEndpoint”:”http://10.43.21.105:80/” + * } + * } + * ] + * “additionalParam”:{ + * …… + * } + * } + * <br/> + * + * @return + * @since NFVO 0.5 + */ + private String getVimId(JujuVnfmInfo vnfmInfo) { + try { + if(vnfmInfo != null && StringUtils.isNotBlank(vnfmInfo.getExtend())){ + JSONObject json = JSONObject.fromObject(vnfmInfo.getExtend()); + JSONObject extVirtualLinkLink = json.getJSONArray("extVirtualLinks").getJSONObject(0); + String vimId = extVirtualLinkLink.getJSONObject("vim").getString("vimid"); + return vimId; + } + } catch(Exception e) { + LOG.error("vnfmInfo.getExtend() format error!please check it",e); + } + return null; + } + + /** + * findByVnfId from db + * <br/> + * + * @param vnfId + * @return + * @since NFVO 0.5 + */ + private JujuVnfmInfo findByVnfId(String vnfId) { + JujuVnfmInfoExample example = new JujuVnfmInfoExample(); + example.createCriteria().andVnfIdEqualTo(vnfId); + List<JujuVnfmInfo> list = jujuVnfmInfoMapper.selectByExample(example); + if(CollectionUtils.isNotEmpty(list) && !list.isEmpty()) { + return list.get(0); + } + return null; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ConfigRoa.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ConfigRoa.java new file mode 100644 index 0000000..38c12fa --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ConfigRoa.java @@ -0,0 +1,193 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest; + +import java.io.File; +import java.io.IOException; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +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.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.nfvo.jujuvnfmadapter.common.FileUtils; +import org.openo.nfvo.jujuvnfmadapter.common.JujuConfigUtil; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils.ExeRes; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.impl.AdapterResourceManager; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.constant.UrlConstant; +import org.openo.nfvo.jujuvnfmadapter.common.SwitchController; +import org.openo.nfvo.jujuvnfmadapter.common.VnfmUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Sep 13, 2016 + */ +@Path("/v1/config") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class ConfigRoa { + + private static final Logger LOG = LoggerFactory.getLogger(ConfigRoa.class); + + /** + * <br/> + * + * @param context + * @param resp + * @return + * @since NFVO 0.5 + */ + @GET + @Path("/") + public String initUI(@Context HttpServletRequest context, @Context HttpServletResponse resp) { + return EntityUtils.toString(new SwitchController(), SwitchController.class); + } + + /** + * <br/> + * + * @param type + * @param context + * @param resp + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/debug/{type}") + public boolean setDebugModel(@PathParam("type") int type, @Context HttpServletRequest context, + @Context HttpServletResponse resp) throws ServiceException { + if(type == 1) { + SwitchController.setDebugModel(true); + } else { + SwitchController.setDebugModel(false); + } + LOG.debug("change to debug model:" + SwitchController.isDebugModel()); + return SwitchController.isDebugModel(); + } + + /** + * <br/> + * + * @param methodName + * @param context + * @param resp + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/mock/{methodName}") + public boolean mock(@PathParam("methodName") String methodName, @Context HttpServletRequest context, + @Context HttpServletResponse resp) throws ServiceException { + if("getVnfmById".equals(methodName)) { + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject json = new JSONObject(); + json.put("vnfmId", vnfmId); + json.put("vnfdId", "testVnfdId"); + json.put("vnfPackageId", "testPackageId"); + json.put("version", "1"); + json.put("url", JujuConfigUtil.getValue("jujuvnfm_server_url")); + return json; + } + }; + } else if("execute".equals(methodName)) { + new MockUp<EntityUtils>() { + + @Mock + public ExeRes execute(String dir, List<String> command) { + ExeRes er = new ExeRes(); + String resContent = null; + try { + resContent = new String( + FileUtils.readFile(new File(JujuConfigUtil.getValue("juju_cmd_res_file")), "UTF-8")); + } catch(Exception e) { + LOG.error("mock fail",e); + resContent = "mock fail"; + } + er.setBody(resContent); + return er; + } + }; + }else if("fetchDownloadUrlFromCatalog".equals(methodName)) { + new MockUp<AdapterResourceManager>() { + @Mock + public String fetchDownloadUrlFromCatalog(String csarId){ + return JujuConfigUtil.getValue("catalog_download_url"); + } + }; + } + return true; + } + + /** + * <br/> + * + * @param methodName + * @param context + * @param resp + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/unmock/{methodName}") + public boolean unmock(@PathParam("methodName") String methodName, @Context HttpServletRequest context, + @Context HttpServletResponse resp) throws ServiceException { + if("getVnfmById".equals(methodName)) { + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + RestfulResponse rsp = VnfmRestfulUtil.getRemoteResponse( + String.format(UrlConstant.REST_ESRINFO_GET, vnfmId), JujuVnfmRestfulUtil.GET_TYPE, null); + if(rsp == null || rsp.getStatus() != Constant.HTTP_OK) { + return null; + } + LOG.error("funtion=getVnfmById, status={}", rsp.getStatus()); + return JSONObject.fromObject(rsp.getResponseContent()); + } + }; + } + return true; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/JujuClientRoa.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/JujuClientRoa.java new file mode 100644 index 0000000..d6e7569 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/JujuClientRoa.java @@ -0,0 +1,252 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest; + +import java.util.UUID; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.apache.commons.lang3.StringUtils; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.nfvo.jujuvnfmadapter.common.JujuConfigUtil; +import org.openo.nfvo.jujuvnfmadapter.common.StringUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.impl.JujuClientManager; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IJujuClientManager; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.process.VnfMgr; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 18, 2016 + */ +@Path("/v1/vnfms") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class JujuClientRoa { + + private static final Logger LOG = LoggerFactory.getLogger(JujuClientRoa.class); + + private IJujuClientManager jujuClientManager; + private VnfMgr vnfMgr; + + /** + * @return Returns the jujuClientManager. + */ + public IJujuClientManager getJujuClientManager() { + return jujuClientManager; + } + + /** + * @param jujuClientManager The jujuClientManager to set. + */ + public void setJujuClientManager(IJujuClientManager jujuClientManager) { + this.jujuClientManager = jujuClientManager; + } + + /** + * + * @return + */ + public VnfMgr getVnfMgr() { + return vnfMgr; + } + + /** + * + * @param vnfMgr + */ + public void setVnfMgr(VnfMgr vnfMgr) { + this.vnfMgr = vnfMgr; + } + + /** + * Set Charm url for juju deployment + * <br/> + * + * @param resp + * @param context + * parameter : charmUrl + * @return "{"charmUrl":"http://dld_url"} + * @since NFVO 0.5 + */ + @POST + @Path("/setCharmUrl") + public String setCharmUrl(@Context HttpServletRequest context, @Context HttpServletResponse resp) + throws ServiceException { + JSONObject result = new JSONObject(); + result.put("retCode", Constant.REST_FAIL); + JSONObject reqJsonObject = StringUtil.getJsonFromContexts(context); + + LOG.debug(reqJsonObject + ":"); + return result.toString(); + } + + /** + * Get VNF status + * parameter: vnfInstanceId + * <br/> + * + * @param modelName + * @param resp + * @param context + * @return Depends on juju's return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/status") + public String getVnfStatus(@QueryParam("modelName") String modelName, @Context HttpServletRequest context, + @Context HttpServletResponse resp) throws ServiceException { + String appName = processAppName(modelName); + JSONObject result = jujuClientManager.getStatus(appName); + LOG.debug("status json str:"+result.toString()); + return result.toString(); + + + } + + /** + * Instance VNF to juju-client + * <br/> + * deployParam: depend on juju require + * + * @param resp + * @param context + * @return status: deplay result <br> + * the return data must be include "{ + * app_info:{"vnfId":123344} + * }" + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + @Path("/deploy") + public String deploySerivce(@Context HttpServletRequest context, @Context HttpServletResponse resp) + throws ServiceException { + JSONObject result = new JSONObject(); + String msg = null; + try { + result.put(EntityUtils.RESULT_CODE_KEY, EntityUtils.ExeRes.FAILURE); + JSONObject reqJsonObject = StringUtil.getJsonFromContexts(context); + LOG.info("deploySerivce request data-->"+reqJsonObject); + if(reqJsonObject == null || reqJsonObject.get(Constant.APP_NAME) == null){ + result.put(EntityUtils.MSG_KEY, "the param 'appName' can't be null"); + resp.setStatus(Constant.HTTP_INNERERROR); + return result.toString(); + } + String csarId = (String)reqJsonObject.get("csarId"); + + String appName = reqJsonObject.getString(Constant.APP_NAME); + appName = processAppName(appName); + //1、download the catalog,unzip file and get the charmPath + String charmPath = vnfMgr.getCharmPath(csarId); + if(StringUtils.isBlank(charmPath)) { + charmPath = JujuConfigUtil.getValue("charmPath"); + } + String vnfId = UUID.randomUUID().toString(); + //2、grant resource + boolean grantRes = jujuClientManager.grantResource(charmPath, appName, JujuClientManager.ADDRESOURCE, vnfId); + LOG.info("grantResource result:"+grantRes); + //3、deploy service + if(grantRes){ + result = jujuClientManager.deploy(charmPath,appName); + if(result.getInt(EntityUtils.RESULT_CODE_KEY) == EntityUtils.ExeRes.SUCCESS){ + resp.setStatus(Constant.HTTP_CREATED); + } + result.put("vnfId", vnfId);//return vnfId + return result.toString(); + }else{ + msg = "Grant resource fail:"+vnfId; + } + } catch(Exception e) { + msg = e.getMessage(); + LOG.error("deploy fail in method deployService",e); + } + resp.setStatus(Constant.HTTP_INNERERROR); + result.put(EntityUtils.MSG_KEY, msg); + return result.toString(); + } + + /** + * <br/> + * here appName equals modelName + * @param resp + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + @Path("/destroy") + public String destroySerivce(@Context HttpServletRequest context, @Context HttpServletResponse resp) + throws ServiceException { + JSONObject result = new JSONObject(); + result.put(EntityUtils.RESULT_CODE_KEY, EntityUtils.ExeRes.FAILURE); + String msg; + try { + JSONObject reqJsonObject = StringUtil.getJsonFromContexts(context); + if(reqJsonObject == null || reqJsonObject.get(Constant.APP_NAME) == null){ + result.put(EntityUtils.MSG_KEY, "the param 'appName' can't be null"); + resp.setStatus(Constant.HTTP_INNERERROR); + return result.toString(); + } + String appName = reqJsonObject.getString(Constant.APP_NAME); + appName = processAppName(appName); + String vnfId=""; + if(reqJsonObject.containsKey("vnfId")) { + vnfId = reqJsonObject.getString("vnfId"); + } + result = jujuClientManager.destroy(appName); + resp.setStatus(Constant.UNREG_SUCCESS); + LOG.info("destroy service success!!!"+appName+vnfId); + return result.toString(); + } catch(Exception e) { + msg = e.getMessage(); + LOG.error("destory fail in method destroyService",e); + + } + resp.setStatus(Constant.HTTP_INNERERROR); + result.put(EntityUtils.MSG_KEY, msg); + return result.toString(); + } + + private static String processAppName(String appName){ + if(appName != null && appName.indexOf(".yaml") > 0){//remove zte's attach + return appName.substring(0,appName.indexOf(".yaml"))+".yaml"; + } + return appName; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/SwaggerRoa.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/SwaggerRoa.java new file mode 100644 index 0000000..06e461a --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/SwaggerRoa.java @@ -0,0 +1,49 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest; + +import java.io.IOException; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +import org.apache.commons.io.IOUtils; + +/** + * Swagger API Doc.<br/> + * + * @author + * @version NFVO 0.5 Oct 24, 2016 + */ +@Path("/v1") +@Produces({MediaType.APPLICATION_JSON}) +public class SwaggerRoa { + /** + * API doc. + * @param filename + * @return + * @throws IOException + */ + @GET + @Path("/swagger.json") + public String apidoc() throws IOException{ + ClassLoader classLoader = getClass().getClassLoader(); + return IOUtils.toString(classLoader.getResourceAsStream("swagger.json")); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfResourceRoa.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfResourceRoa.java new file mode 100644 index 0000000..7510e0e --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfResourceRoa.java @@ -0,0 +1,102 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest; + +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.Consumes; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.nfvo.jujuvnfmadapter.common.StringUtil; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.process.VnfResourceMgr; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * Provide interfaces of resource for juju VNFM to call. + * <br/> + * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +@Path("/v1") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class VnfResourceRoa { + + private static final Logger LOG = LoggerFactory.getLogger(VnfResourceRoa.class); + + private VnfResourceMgr vnfResourceMgr; + + public void setVnfResourceMgr(VnfResourceMgr vnfResourceMgr) { + this.vnfResourceMgr = vnfResourceMgr; + } + + /** + * Provide function of grant resource. + * <br/> + *JSONObject compute : + * field:(cpu,mem,disk,action(addResource/removeResource)) + * @param context + * @param vnfId + * @return + * @since NFVO 0.5 + */ + @PUT + @Path("/instances/{vnfId}/grant") + public String grantVnfRes(@Context HttpServletRequest context, @PathParam("vnfId") String vnfId) { + LOG.info("function=grantVnfRes, msg=enter to grant vnf resource"); + JSONObject restJson = new JSONObject(); + restJson.put(EntityUtils.RESULT_CODE_KEY, Constant.REST_FAIL); + + JSONObject compute = StringUtil.getJsonFromContexts(context); + if(null == compute) { + LOG.error("function=grantVnfRes, msg=param request content can't be null!"); + restJson.put("data", "param request content can't be null!"); + return restJson.toString(); + } + + JSONObject resultObj = vnfResourceMgr.grantVnfResource(compute, vnfId); + handleResult(resultObj, restJson); + + return restJson.toString(); + } + + private void handleResult(JSONObject resultObj, JSONObject restJson) { + if(resultObj.getInt("retCode") == Constant.REST_SUCCESS) { + restJson.put("retCode", Constant.REST_SUCCESS); + restJson.put("data", resultObj.getJSONObject("data")); + } else { + if(resultObj.containsKey("data")) { + String errorMsg = resultObj.getString("data"); + LOG.error("function=handleResult, msg={}", errorMsg); + restJson.put("data", errorMsg); + } else { + LOG.error("function=handleResult, msg=Vnf Resource dispose fail"); + restJson.put("data", "Vnf Resource dispose fail"); + } + } + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfRoa.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfRoa.java new file mode 100644 index 0000000..df29ba3 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfRoa.java @@ -0,0 +1,256 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.service.rest; + +import java.util.HashMap; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MediaType; + +import org.apache.commons.collections.map.UnmodifiableMap; +import org.apache.commons.lang3.StringUtils; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.openo.nfvo.jujuvnfmadapter.common.StringUtil; +import org.openo.nfvo.jujuvnfmadapter.common.SwitchController; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.process.VnfMgr; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import net.sf.json.JSONObject; + +/** + * Provide interfaces for instantiate or terminate VNF. + * <br/> + * + * @author + * @version NFVO 0.5 Aug 24, 2016 + */ +@SuppressWarnings("unchecked") +@Path("/v1") +@Consumes(MediaType.APPLICATION_JSON) +@Produces(MediaType.APPLICATION_JSON) +public class VnfRoa { + + private static final Logger LOG = LoggerFactory.getLogger(VnfRoa.class); + + private VnfMgr vnfMgr; + + private static Map<String, String> progressItem; + + private static Map<String, String> jobStatusitem; + + static { + Map<String, String> map = new HashMap<>(); + map.put("Building", "50"); + map.put("Active", "100"); + map.put("Stopped", "50"); + map.put("Error", "100"); + progressItem = UnmodifiableMap.decorate(map); + + map = new HashMap<>(); + map.put("Building", "processing"); + map.put("Active", "finished"); + map.put("Stopped", "processing"); + map.put("Error", "error"); + jobStatusitem = UnmodifiableMap.decorate(map); + } + + public void setVnfMgr(VnfMgr vnfMgr) { + this.vnfMgr = vnfMgr; + } + + + @POST + @Path("/vnfminfo") + public String setVNFMInfo(@Context HttpServletRequest context, @Context HttpServletResponse resp) + throws ServiceException { + JSONObject result = new JSONObject(); + result.put("retCode", Constant.REST_SUCCESS); + JSONObject reqJsonObject = StringUtil.getJsonFromContexts(context); + String vnfmServiceUrl = reqJsonObject.getString("url"); + SwitchController.vnfmServiceUrl = vnfmServiceUrl; + LOG.info(reqJsonObject + ":setVNFMInfo success!"); + return result.toString(); + } + + /** + * Provide function for instantiate VNF + * <br/> + * + * @param context + * @param resp + * @param vnfmId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + @Path("/{vnfmId}/vnfs") + public String addVnf(@Context HttpServletRequest context, @Context HttpServletResponse resp, + @PathParam("vnfmId") String vnfmId) throws ServiceException { + LOG.warn("function=addVnf, msg=enter to add a vnf"); + JSONObject subJsonObject = StringUtil.getJsonFromContexts(context); + LOG.info("request context:"+subJsonObject); + JSONObject restJson = new JSONObject(); + + if(null == subJsonObject) { + LOG.error("function=addVnf, msg=params are insufficient"); + resp.setStatus(Constant.HTTP_INNERERROR); + return restJson.toString(); + } + + restJson = vnfMgr.addVnf(subJsonObject, vnfmId); + + if(restJson.getInt(EntityUtils.RESULT_CODE_KEY) == Constant.REST_FAIL) { + LOG.error("function=addVnf, msg=addvnf fail"); + resp.setStatus(Constant.HTTP_INNERERROR); + return restJson.toString(); + } + + return JSONObject.fromObject(restJson.getJSONObject("data")).toString(); + } + + /** + * Provide function for terminate VNF + * <br/> + * + * @param vnfmId + * @param resp + * @param vnfInstanceId + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @DELETE + @Path("/{vnfmId}/vnfs/{vnfInstanceId}/terminate") + public String delVnfDel(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp, + @PathParam("vnfInstanceId") String vnfInstanceId, @Context HttpServletRequest context) + throws ServiceException { + + return this.delVnf(vnfmId, resp, vnfInstanceId, context); + } + + /** + * Provide function for terminate VNF + * <br/> + * + * @param vnfmId + * @param resp + * @param vnfInstanceId + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @POST + @Path("/{vnfmId}/vnfs/{vnfInstanceId}/terminate") + public String delVnf(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp, + @PathParam("vnfInstanceId") String vnfInstanceId, @Context HttpServletRequest context) + throws ServiceException { + LOG.warn("function=delVnf, msg=enter to delete a vnf: vnfInstanceId: {}, vnfmId: {}", vnfInstanceId, vnfmId); + JSONObject vnfObject = StringUtil.getJsonFromContexts(context); + LOG.info("request context:"+vnfObject); + JSONObject restJson = new JSONObject(); + + if(StringUtils.isEmpty(vnfInstanceId) || StringUtils.isEmpty(vnfmId)) { + resp.setStatus(Constant.HTTP_INNERERROR); + return restJson.toString(); + } + + restJson = vnfMgr.deleteVnf(vnfInstanceId, vnfmId, vnfObject); + if(restJson.getInt(EntityUtils.RESULT_CODE_KEY) == Constant.REST_FAIL) { + LOG.error("function=delVnf, msg=delVnf fail"); + resp.setStatus(Constant.HTTP_INNERERROR); + return restJson.toString(); + } + + return JSONObject.fromObject(restJson.getJSONObject("data")).toString(); + } + + /** + * Provide function for get VNF + * <br/> + * + * @param vnfmId + * @param resp + * @param vnfInstanceId + * @param context + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/{vnfmId}/vnfs/{vnfInstanceId}") + public String getVnf(@PathParam("vnfmId") String vnfmId, @Context HttpServletResponse resp, + @PathParam("vnfInstanceId") String vnfInstanceId, @Context HttpServletRequest context) + throws ServiceException { + LOG.warn("function=getVnf, msg=enter to get a vnf: vnfInstanceId: {}, vnfmId: {}", vnfInstanceId, vnfmId); + JSONObject restJson = new JSONObject(); + + if(StringUtils.isEmpty(vnfInstanceId) || StringUtils.isEmpty(vnfmId)) { + resp.setStatus(Constant.HTTP_INNERERROR); + return restJson.toString(); + } + + restJson = vnfMgr.getVnf(vnfInstanceId, vnfmId); + if(restJson.getInt(EntityUtils.RESULT_CODE_KEY) == Constant.REST_FAIL) { + LOG.error("function=getVnf, msg=getVnf fail"); + resp.setStatus(Constant.HTTP_INNERERROR); + return restJson.toString(); + } + + restJson.remove(EntityUtils.RESULT_CODE_KEY); + return restJson.toString(); + } + + /** + * Provide function for get job + * <br/> + * + * @param jobId + * @param vnfmId + * @param resp + * @param responseId + * @return + * @throws ServiceException + * @since NFVO 0.5 + */ + @GET + @Path("/{vnfmId}/jobs/{jobId}") + public String getJob(@PathParam("jobId") String jobId, @PathParam("vnfmId") String vnfmId, + @Context HttpServletResponse resp, @QueryParam("@responseId") String responseId) throws ServiceException { + LOG.warn("function=getJob, msg=enter to get a job: jobId: {}", jobId); + JSONObject restJson = new JSONObject(); + restJson = vnfMgr.getJob(jobId, vnfmId); + + return restJson.toString(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ExceptionMessage.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ExceptionMessage.java new file mode 100644 index 0000000..3069c11 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ExceptionMessage.java @@ -0,0 +1,64 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest.exceptionmapper; + +import org.apache.http.HttpStatus; + +/** + * Exception response model.<br> + * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +public class ExceptionMessage { + + private String errorCode = "unknown.error"; + + private int httpCode = HttpStatus.SC_INTERNAL_SERVER_ERROR; + + private String message; + + @Override + public String toString() { + return "Error {errorCode=" + this.errorCode + ", httpCode=" + this.httpCode + ", message=" + + this.message + "}"; + } + + public String getErrorCode() { + return this.errorCode; + } + + public void setErrorCode(String errorCode) { + this.errorCode = errorCode; + } + + public String getMessage() { + return this.message; + } + + public void setMessage(String message) { + this.message = message; + } + + public int getHttpCode() { + return this.httpCode; + } + + public void setHttpCode(int httpCode) { + this.httpCode = httpCode; + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/GenericExceptionMapper.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/GenericExceptionMapper.java new file mode 100644 index 0000000..908a0f1 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/GenericExceptionMapper.java @@ -0,0 +1,41 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest.exceptionmapper; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +/** + * Generic exception response provider.<br> + * + * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +@Provider +public class GenericExceptionMapper implements ExceptionMapper<Exception>{ + + @Override + public Response toResponse(Exception exception) { + ExceptionMessage message = new ExceptionMessage(); + message.setMessage(exception.getMessage()); + return Response.status(message.getHttpCode()).type( + MediaType.APPLICATION_JSON).entity(message).build(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapper.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapper.java new file mode 100644 index 0000000..ffddd99 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapper.java @@ -0,0 +1,45 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest.exceptionmapper; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import javax.ws.rs.ext.ExceptionMapper; +import javax.ws.rs.ext.Provider; + +import org.openo.baseservice.remoteservice.exception.ServiceException; + +/** + * ServiceException response provider.<br> + * + * @author + * @version NFVO 0.5 Sep 27, 2016 + */ +@Provider +public class ServiceExceptionMapper implements ExceptionMapper<ServiceException>{ + + @Override + public Response toResponse(ServiceException exception) { + ExceptionMessage message = new ExceptionMessage(); + message.setErrorCode(exception.getId()); + message.setHttpCode(exception.getHttpCode()); + message.setMessage(exception.getMessage()); + return Response.status(message.getHttpCode()). + type(MediaType.APPLICATION_JSON).entity(message).build(); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/db.properties b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/db.properties new file mode 100644 index 0000000..8f9dbb4 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/db.properties @@ -0,0 +1,20 @@ +# +# Copyright 2016 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. +# + +jdbc.username=root +jdbc.password=rootpass +jdbc.url=jdbc:mysql://127.0.0.1:3306/jujuvnfmdb +jdbc.driverClassName=com.mysql.jdbc.Driver
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/juju-config.properties b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/juju-config.properties new file mode 100644 index 0000000..1141561 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/juju-config.properties @@ -0,0 +1,26 @@ +############################################################################### +# Copyright 2016 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. +############################################################################### +catalog_download_url=http://127.0.0.1:8080/abc.csar +charmPath=/opt/csar/ +jujuvnfm_server_url=http://127.0.0.1:8080/juju-vnfmadapter-service +grant_jujuvnfm_url=http://127.0.0.1:8080/juju-vnfmadapter-service +juju_cmd_res_file=E:/juju/response/result.json + +juju_add_model_cmd= +juju_switch_model_cmd= +juju_deploy_cmd= +juju_status_cmd= +juju_destroy_model= diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/log4j.properties b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/log4j.properties new file mode 100644 index 0000000..7fc5d67 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/log4j.properties @@ -0,0 +1,28 @@ +############################################################################### +# Copyright 2016 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. +############################################################################### +log4j.rootLogger=INFO,root +log4j.logger.org.openo.nfvo=DEBUG,stdout +log4j.appender.root.Append=true +log4j.appender.root.File=${catalina.base}/logs/jujuvnfmadapterservice.log +log4j.appender.root.layout.ConversionPattern=%d %-5p [%t][%X{moduleID}][%C %L] %m%n +log4j.appender.root.layout=org.apache.log4j.PatternLayout +log4j.appender.root.MaxBackupIndex=50 +log4j.appender.root.MaxFileSize=20MB +log4j.appender.root=org.apache.log4j.RollingFileAppender + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t][%X{moduleID}][%C %L] %m%n
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/mybatis/mysql/JujuVnfmInfoMapper.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/mybatis/mysql/JujuVnfmInfoMapper.xml new file mode 100644 index 0000000..39d76b7 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/mybatis/mysql/JujuVnfmInfoMapper.xml @@ -0,0 +1,382 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<!-- + Copyright 2016 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. + --> + +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" > +<mapper + namespace="org.openo.nfvo.jujuvnfmadapter.service.mapper.JujuVnfmInfoMapper"> + <resultMap id="BaseResultMap" + type="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo"> + <id column="ID" property="id" jdbcType="VARCHAR" /> + <result column="VNFM_ID" property="vnfmId" jdbcType="VARCHAR" /> + <result column="VNF_ID" property="vnfId" jdbcType="VARCHAR" /> + <result column="APP_NAME" property="appName" jdbcType="VARCHAR" /> + <result column="JOB_ID" property="jobId" jdbcType="VARCHAR" /> + <result column="STATUS" property="status" jdbcType="INTEGER" /> + <result column="CREATE_TIME" property="createTime" jdbcType="TIMESTAMP" /> + <result column="MODIFY_TIME" property="modifyTime" jdbcType="TIMESTAMP" /> + <result column="DELETE_TIME" property="deleteTime" jdbcType="TIMESTAMP" /> + </resultMap> + <resultMap id="ResultMapWithBLOBs" + type="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo" + extends="BaseResultMap"> + <result column="EXTEND" property="extend" jdbcType="LONGVARCHAR" /> + </resultMap> + <sql id="Example_Where_Clause"> + <where> + <foreach collection="oredCriteria" item="criteria" separator="or"> + <if test="criteria.valid"> + <trim prefix="(" suffix=")" prefixOverrides="and"> + <foreach collection="criteria.criteria" item="criterion"> + <choose> + <when test="criterion.noValue"> + and ${criterion.condition} + </when> + <when test="criterion.singleValue"> + and ${criterion.condition} #{criterion.value} + </when> + <when test="criterion.betweenValue"> + and ${criterion.condition} #{criterion.value} and + #{criterion.secondValue} + </when> + <when test="criterion.listValue"> + and ${criterion.condition} + <foreach collection="criterion.value" item="listItem" + open="(" close=")" separator=","> + #{listItem} + </foreach> + </when> + </choose> + </foreach> + </trim> + </if> + </foreach> + </where> + </sql> + <sql id="Update_By_Example_Where_Clause"> + <where> + <foreach collection="example.oredCriteria" item="criteria" + separator="or"> + <if test="criteria.valid"> + <trim prefix="(" suffix=")" prefixOverrides="and"> + <foreach collection="criteria.criteria" item="criterion"> + <choose> + <when test="criterion.noValue"> + and ${criterion.condition} + </when> + <when test="criterion.singleValue"> + and ${criterion.condition} #{criterion.value} + </when> + <when test="criterion.betweenValue"> + and ${criterion.condition} #{criterion.value} and + #{criterion.secondValue} + </when> + <when test="criterion.listValue"> + and ${criterion.condition} + <foreach collection="criterion.value" item="listItem" + open="(" close=")" separator=","> + #{listItem} + </foreach> + </when> + </choose> + </foreach> + </trim> + </if> + </foreach> + </where> + </sql> + <sql id="Base_Column_List"> + ID, VNFM_ID, VNF_ID, APP_NAME, JOB_ID, STATUS, CREATE_TIME, MODIFY_TIME, + DELETE_TIME + </sql> + <sql id="Blob_Column_List"> + EXTEND + </sql> + <select id="selectByExampleWithBLOBs" resultMap="ResultMapWithBLOBs" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample"> + select + <if test="distinct"> + distinct + </if> + <include refid="Base_Column_List" /> + , + <include refid="Blob_Column_List" /> + from jujuvnfm + <if test="_parameter != null"> + <include refid="Example_Where_Clause" /> + </if> + <if test="orderByClause != null"> + order by ${orderByClause} + </if> + </select> + <select id="selectByExample" resultMap="BaseResultMap" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample"> + select + <if test="distinct"> + distinct + </if> + <include refid="Base_Column_List" /> + from jujuvnfm + <if test="_parameter != null"> + <include refid="Example_Where_Clause" /> + </if> + <if test="orderByClause != null"> + order by ${orderByClause} + </if> + <if test="limitStart >= 0"> + limit ${limitStart} , ${limitEnd} + </if> + </select> + <select id="selectByPrimaryKey" resultMap="ResultMapWithBLOBs" + parameterType="java.lang.String"> + select + <include refid="Base_Column_List" /> + , + <include refid="Blob_Column_List" /> + from jujuvnfm + where ID = #{id,jdbcType=VARCHAR} + </select> + <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> + delete from jujuvnfm + where ID = #{id,jdbcType=VARCHAR} + </delete> + <delete id="deleteByExample" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample"> + delete from jujuvnfm + <if test="_parameter != null"> + <include refid="Example_Where_Clause" /> + </if> + </delete> + <insert id="insert" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo"> + insert into jujuvnfm (ID, VNFM_ID, VNF_ID, + APP_NAME, JOB_ID, STATUS, + CREATE_TIME, MODIFY_TIME, DELETE_TIME, + EXTEND) + values (#{id,jdbcType=VARCHAR}, #{vnfmId,jdbcType=VARCHAR}, + #{vnfId,jdbcType=VARCHAR}, + #{appName,jdbcType=VARCHAR}, #{jobId,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, + #{createTime,jdbcType=TIMESTAMP}, #{modifyTime,jdbcType=TIMESTAMP}, + #{deleteTime,jdbcType=TIMESTAMP}, + #{extend,jdbcType=LONGVARCHAR}) + </insert> + <insert id="insertSelective" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo"> + insert into jujuvnfm + <trim prefix="(" suffix=")" suffixOverrides=","> + <if test="id != null"> + ID, + </if> + <if test="vnfmId != null"> + VNFM_ID, + </if> + <if test="vnfId != null"> + VNF_ID, + </if> + <if test="appName != null"> + APP_NAME, + </if> + <if test="jobId != null"> + JOB_ID, + </if> + <if test="status != null"> + STATUS, + </if> + <if test="createTime != null"> + CREATE_TIME, + </if> + <if test="modifyTime != null"> + MODIFY_TIME, + </if> + <if test="deleteTime != null"> + DELETE_TIME, + </if> + <if test="extend != null"> + EXTEND, + </if> + </trim> + <trim prefix="values (" suffix=")" suffixOverrides=","> + <if test="id != null"> + #{id,jdbcType=VARCHAR}, + </if> + <if test="vnfmId != null"> + #{vnfmId,jdbcType=VARCHAR}, + </if> + <if test="vnfId != null"> + #{vnfId,jdbcType=VARCHAR}, + </if> + <if test="appName != null"> + #{appName,jdbcType=VARCHAR}, + </if> + <if test="jobId != null"> + #{jobId,jdbcType=VARCHAR}, + </if> + <if test="status != null"> + #{status,jdbcType=INTEGER}, + </if> + <if test="createTime != null"> + #{createTime,jdbcType=TIMESTAMP}, + </if> + <if test="modifyTime != null"> + #{modifyTime,jdbcType=TIMESTAMP}, + </if> + <if test="deleteTime != null"> + #{deleteTime,jdbcType=TIMESTAMP}, + </if> + <if test="extend != null"> + #{extend,jdbcType=LONGVARCHAR}, + </if> + </trim> + </insert> + <select id="countByExample" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample" + resultType="java.lang.Integer"> + select count(*) from jujuvnfm + <if test="_parameter != null"> + <include refid="Example_Where_Clause" /> + </if> + </select> + <update id="updateByExampleSelective" parameterType="map"> + update jujuvnfm + <set> + <if test="record.id != null"> + ID = #{record.id,jdbcType=VARCHAR}, + </if> + <if test="record.vnfmId != null"> + VNFM_ID = #{record.vnfmId,jdbcType=VARCHAR}, + </if> + <if test="record.vnfId != null"> + VNF_ID = #{record.vnfId,jdbcType=VARCHAR}, + </if> + <if test="record.appName != null"> + APP_NAME = #{record.appName,jdbcType=VARCHAR}, + </if> + <if test="record.jobId != null"> + JOB_ID = #{record.jobId,jdbcType=VARCHAR}, + </if> + <if test="record.status != null"> + STATUS = #{record.status,jdbcType=INTEGER}, + </if> + <if test="record.createTime != null"> + CREATE_TIME = #{record.createTime,jdbcType=TIMESTAMP}, + </if> + <if test="record.modifyTime != null"> + MODIFY_TIME = #{record.modifyTime,jdbcType=TIMESTAMP}, + </if> + <if test="record.deleteTime != null"> + DELETE_TIME = #{record.deleteTime,jdbcType=TIMESTAMP}, + </if> + <if test="record.extend != null"> + EXTEND = #{record.extend,jdbcType=LONGVARCHAR}, + </if> + </set> + <if test="_parameter != null"> + <include refid="Update_By_Example_Where_Clause" /> + </if> + </update> + <update id="updateByExampleWithBLOBs" parameterType="map"> + update jujuvnfm + set ID = #{record.id,jdbcType=VARCHAR}, + VNFM_ID = #{record.vnfmId,jdbcType=VARCHAR}, + VNF_ID = #{record.vnfId,jdbcType=VARCHAR}, + APP_NAME = #{record.appName,jdbcType=VARCHAR}, + JOB_ID = #{record.jobId,jdbcType=VARCHAR}, + STATUS = #{record.status,jdbcType=INTEGER}, + CREATE_TIME = #{record.createTime,jdbcType=TIMESTAMP}, + MODIFY_TIME = #{record.modifyTime,jdbcType=TIMESTAMP}, + DELETE_TIME = #{record.deleteTime,jdbcType=TIMESTAMP}, + EXTEND = #{record.extend,jdbcType=LONGVARCHAR} + <if test="_parameter != null"> + <include refid="Update_By_Example_Where_Clause" /> + </if> + </update> + <update id="updateByExample" parameterType="map"> + update jujuvnfm + set ID = #{record.id,jdbcType=VARCHAR}, + VNFM_ID = #{record.vnfmId,jdbcType=VARCHAR}, + VNF_ID = #{record.vnfId,jdbcType=VARCHAR}, + APP_NAME = #{record.appName,jdbcType=VARCHAR}, + JOB_ID = #{record.jobId,jdbcType=VARCHAR}, + STATUS = #{record.status,jdbcType=INTEGER}, + CREATE_TIME = #{record.createTime,jdbcType=TIMESTAMP}, + MODIFY_TIME = #{record.modifyTime,jdbcType=TIMESTAMP}, + DELETE_TIME = #{record.deleteTime,jdbcType=TIMESTAMP} + <if test="_parameter != null"> + <include refid="Update_By_Example_Where_Clause" /> + </if> + </update> + <update id="updateByPrimaryKeySelective" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo"> + update jujuvnfm + <set> + <if test="vnfmId != null"> + VNFM_ID = #{vnfmId,jdbcType=VARCHAR}, + </if> + <if test="vnfId != null"> + VNF_ID = #{vnfId,jdbcType=VARCHAR}, + </if> + <if test="appName != null"> + APP_NAME = #{appName,jdbcType=VARCHAR}, + </if> + <if test="jobId != null"> + JOB_ID = #{jobId,jdbcType=VARCHAR}, + </if> + <if test="status != null"> + STATUS = #{status,jdbcType=INTEGER}, + </if> + <if test="createTime != null"> + CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}, + </if> + <if test="modifyTime != null"> + MODIFY_TIME = #{modifyTime,jdbcType=TIMESTAMP}, + </if> + <if test="deleteTime != null"> + DELETE_TIME = #{deleteTime,jdbcType=TIMESTAMP}, + </if> + <if test="extend != null"> + EXTEND = #{extend,jdbcType=LONGVARCHAR}, + </if> + </set> + where ID = #{id,jdbcType=VARCHAR} + </update> + <update id="updateByPrimaryKeyWithBLOBs" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo"> + update jujuvnfm + set VNFM_ID = #{vnfmId,jdbcType=VARCHAR}, + VNF_ID = #{vnfId,jdbcType=VARCHAR}, + APP_NAME = #{appName,jdbcType=VARCHAR}, + JOB_ID = #{jobId,jdbcType=VARCHAR}, + STATUS = #{status,jdbcType=INTEGER}, + CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}, + MODIFY_TIME = #{modifyTime,jdbcType=TIMESTAMP}, + DELETE_TIME = #{deleteTime,jdbcType=TIMESTAMP}, + EXTEND = #{extend,jdbcType=LONGVARCHAR} + where ID = #{id,jdbcType=VARCHAR} + </update> + <update id="updateByPrimaryKey" + parameterType="org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo"> + update jujuvnfm + set VNFM_ID = #{vnfmId,jdbcType=VARCHAR}, + VNF_ID = #{vnfId,jdbcType=VARCHAR}, + APP_NAME = #{appName,jdbcType=VARCHAR}, + JOB_ID = #{jobId,jdbcType=VARCHAR}, + STATUS = #{status,jdbcType=INTEGER}, + CREATE_TIME = #{createTime,jdbcType=TIMESTAMP}, + MODIFY_TIME = #{modifyTime,jdbcType=TIMESTAMP}, + DELETE_TIME = #{deleteTime,jdbcType=TIMESTAMP} + where ID = #{id,jdbcType=VARCHAR} + </update> +</mapper>
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/spring/JujuVnfmadapter/services.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/spring/JujuVnfmadapter/services.xml new file mode 100644 index 0000000..cc7e016 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/spring/JujuVnfmadapter/services.xml @@ -0,0 +1,125 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2016 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. + --> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" + xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" + xmlns:ctx="http://www.springframework.org/schema/context" xmlns:jaxrs="http://cxf.apache.org/jaxrs" + xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/osgi + http://www.springframework.org/schema/osgi/spring-osgi.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/osgi-compendium + http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd + http://cxf.apache.org/jaxrs + http://cxf.apache.org/schemas/jaxrs.xsd + http://cxf.apache.org/transports/http/configuration + http://cxf.apache.org/schemas/configuration/http-conf.xsd + http://www.springframework.org/schema/aop + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd + http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> + + <context:annotation-config + proxy-target-class="true" /> + <context:component-scan base-package="org.openo.nfvo.jujuvnfmadapter" /> + + <!-- these are included in the dependency jar --> + <import resource="classpath:META-INF/cxf/cxf.xml" /> + <import resource="classpath:META-INF/cxf/cxf-servlet.xml" /> + + <bean id="jsonProvider" class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" /> + + <bean id="db" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> + <property name="location" value="classpath:db.properties"/> + </bean> + + <bean id="source" + class="org.springframework.jdbc.datasource.DriverManagerDataSource"> + <property name="driverClassName" value="${jdbc.driverClassName}" /> + <property name="url" value="${jdbc.url}" /> + <property name="username" value="${jdbc.username}" /> + <property name="password" value="${jdbc.password}" /> + </bean> + + <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean"> + <property name="dataSource" ref="source" /> + <property name="mapperLocations" value="classpath*:mybatis/mysql/*.xml" /> + </bean> + + <bean id="session" class="org.mybatis.spring.SqlSessionTemplate"> + <constructor-arg index="0" ref="sessionFactory" /> + </bean> + + + <bean id="transactionManager" + class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> + <property name="dataSource" ref="source" /> + </bean> + <bean id="jujuVnfmInfoMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> + <property name="mapperInterface" + value="org.openo.nfvo.jujuvnfmadapter.service.mapper.JujuVnfmInfoMapper"/> + <property name="sqlSessionFactory" ref="sessionFactory"/> + </bean> + + + <bean id="vnfMgr" class="org.openo.nfvo.jujuvnfmadapter.service.process.VnfMgr"> + <property name="jujuVnfmInfoMapper" ref="jujuVnfmInfoMapper"/> + <property name="resourceManager" ref="resourceManager"/> + </bean> + <bean id="vnfResourceMgr" class="org.openo.nfvo.jujuvnfmadapter.service.process.VnfResourceMgr"> + <property name="jujuVnfmInfoMapper" ref="jujuVnfmInfoMapper"/> + + </bean> + <bean id="jujuClientManager" + class="org.openo.nfvo.jujuvnfmadapter.service.adapter.impl.JujuClientManager"/> + <bean id="resourceManager" + class="org.openo.nfvo.jujuvnfmadapter.service.adapter.impl.AdapterResourceManager"/> + + <!-- --> + <bean id="jujuClientRoa" + class="org.openo.nfvo.jujuvnfmadapter.service.rest.JujuClientRoa"> + <property name="jujuClientManager" ref="jujuClientManager"/> + <property name="vnfMgr" ref="vnfMgr"/> + </bean> + <bean id="vnfRoa" class="org.openo.nfvo.jujuvnfmadapter.service.rest.VnfRoa"> + <property name="vnfMgr" ref="vnfMgr"/> + </bean> + <bean id="configRoa" class="org.openo.nfvo.jujuvnfmadapter.service.rest.ConfigRoa"/> + + <bean id="SwaggerRoa" class="org.openo.nfvo.jujuvnfmadapter.service.rest.SwaggerRoa"/> + <bean id="vnfResourceRoa" class="org.openo.nfvo.jujuvnfmadapter.service.rest.VnfResourceRoa"> + <property name="vnfResourceMgr" ref="vnfResourceMgr"/> + </bean> + + <jaxrs:server id="restContainer" address="/"> + <jaxrs:serviceBeans> + <ref bean="jujuClientRoa" /> + <ref bean="vnfRoa" /> + <ref bean="configRoa" /> + <ref bean="SwaggerRoa" /> + <ref bean="vnfResourceRoa"/> + </jaxrs:serviceBeans> + <jaxrs:providers> + <ref bean="jsonProvider" /> + </jaxrs:providers> + </jaxrs:server> +</beans>
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/spring/JujuVnfmadapter/svc_register.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/spring/JujuVnfmadapter/svc_register.xml new file mode 100644 index 0000000..27e8c27 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/spring/JujuVnfmadapter/svc_register.xml @@ -0,0 +1,42 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2016 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. + --> + +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:osgi="http://www.springframework.org/schema/osgi" + xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" + xmlns:ctx="http://www.springframework.org/schema/context" xmlns:jaxrs="http://cxf.apache.org/jaxrs" + xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" + xmlns:context="http://www.springframework.org/schema/context" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/osgi + http://www.springframework.org/schema/osgi/spring-osgi.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/osgi-compendium + http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd + http://cxf.apache.org/jaxrs + http://cxf.apache.org/schemas/jaxrs.xsd + http://cxf.apache.org/transports/http/configuration + http://cxf.apache.org/schemas/configuration/http-conf.xsd + http://www.springframework.org/schema/aop + http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd + http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> + <bean class="org.openo.nfvo.jujuvnfmadapter.service.activator.ROAJujuServicePostProcessor"></bean> + <bean class="org.openo.nfvo.jujuvnfmadapter.service.api.internalsvc.impl.JujuAdapterMgrService"></bean> +</beans>
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/swagger.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/swagger.json new file mode 100644 index 0000000..cfd1307 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/resources/swagger.json @@ -0,0 +1,608 @@ +{ + "swagger": "2.0", + "info": { + "title": "Juju VNFM Driver API", + "description": "VNF service provider.", + "version": "1.0.0" + }, + "host": "nfvo.openo.org", + "schemes": [ + "https", + "http" + ], + "basePath": "/openoapi", + "paths": { + "/{vnfmtype}/v1/{vnfmid}/vnfs": { + "post": { + "summary": "Instantiate VNF", + "description": "Add VNF", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfmtype", + "in": "path", + "description": "vnfm type", + "required": true, + "type": "string" + }, + { + "name": "vnfmid", + "in": "path", + "description": "vnfm id", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "vnfmid", + "description": "Provide required properties of VNF.", + "required": true, + "schema": { + "$ref": "#/definitions/Vnf" + } + } + ], + "responses": { + "200": { + "description": "VNF Response", + "schema": { + "$ref": "#/definitions/VnfResponse" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Not Found" + }, + "500": { + "description": "VNF service failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/{vnfmtype}/v1/{vnfmid}/vnfs/{vnfInstanceId}/terminate": { + "post": { + "summary": "Instantiate VNF", + "description": "Add VNF", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfmtype", + "in": "path", + "description": "vnfm type", + "required": true, + "type": "string" + }, + { + "name": "vnfmid", + "in": "path", + "description": "vnfm id", + "required": true, + "type": "string" + }, + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnfm instance id", + "required": true, + "type": "string" + }, + { + "in": "body", + "name": "vnfmTerminate", + "description": "Provide required properties of VNF.", + "required": true, + "schema": { + "$ref": "#/definitions/VnfTerminate" + } + } + ], + "responses": { + "200": { + "description": "VNF Response", + "schema": { + "$ref": "#/definitions/VnfTerminateResponse" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Not Found" + }, + "500": { + "description": "VNF service failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/{vnfmtype}/v1/{vnfmid}/vnfs/{vnfInstanceId}": { + "get": { + "summary": "Query VNF", + "description": "Get VNF Details", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfmtype", + "in": "path", + "description": "vnfm type", + "required": true, + "type": "string" + }, + { + "name": "vnfmid", + "in": "path", + "description": "vnfm id", + "required": true, + "type": "string" + }, + { + "name": "vnfInstanceId", + "in": "path", + "description": "vnfm instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "VNF Response", + "schema": { + "$ref": "#/definitions/VnfInfoResponse" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Not Found" + }, + "500": { + "description": "VNF service failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + }, + "/{vnfmtype}/v1/jobs/{jobid}&responseId={responseId}": { + "get": { + "summary": "Get VNF operational status", + "description": "VNF operational status", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "parameters": [ + { + "name": "vnfmtype", + "in": "path", + "description": "vnfm type", + "required": true, + "type": "string" + }, + { + "name": "jobid", + "in": "path", + "description": "jobid", + "required": true, + "type": "string" + }, + { + "name": "responseId", + "in": "path", + "description": "vnfm instance id", + "required": true, + "type": "string" + } + ], + "responses": { + "200": { + "description": "VNF Response", + "schema": { + "$ref": "#/definitions/VnfStatusResponse" + } + }, + "401": { + "description": "Unauthorized" + }, + "404": { + "description": "VNF Not Found" + }, + "500": { + "description": "VNF service failed to process the request", + "schema": { + "$ref": "#/definitions/Error" + } + } + } + } + } + }, + "definitions": { + "VnfStatusResponse": { + "type": "object", + "description": "Operational Status Response.", + "required": [ + "jobId", + "responseDescriptor", + "status", + "progress", + "statusDescription", + "errorCode", + "responseId", + "responseHistoryList" + ], + "properties": { + "jobId": { + "type": "string", + "description": "Job ID" + }, + "responseDescriptor": { + "type": "string", + "description": "Including vnfStatus,statusDescription,errorCode,progress, responseHistoryList, responseId." + }, + "status": { + "type": "string", + "description": "JOB status started processing finished error" + }, + "progress": { + "type": "integer", + "description": "Progress (1 - 100)" + }, + "statusDescription": { + "type": "string", + "description": "Progress Description" + }, + "errorCode": { + "type": "integer", + "description": "Errorcode" + }, + "responseId": { + "type": "integer", + "description": "Response Identifier" + }, + "responseHistoryList": { + "type": "array", + "items": { + "$ref": "#/definitions/HistoryDetails" + } + } + } + }, + "HistoryDetails": { + "type": "object", + "description": "InitiateVnfResponse.", + "required": [ + "vnfStatus", + "statusDescription", + "errorCode", + "progress", + "responseId" + ], + "properties": { + "vnfStatus": { + "type": "string", + "description": "Vnf Job Status." + }, + "statusDescription": { + "type": "string", + "description": "Progress Description." + }, + "errorCode": { + "type": "integer", + "description": "Error code." + }, + "progress": { + "type": "integer", + "description": "progress (1-100)." + }, + "responseId": { + "type": "integer", + "description": "Response Identifier." + } + } + }, + "VnfResponse": { + "type": "object", + "description": "InitiateVnfResponse.", + "required": [ + "jobId", + "vnfInstanceId" + ], + "properties": { + "jobId": { + "type": "string", + "description": "Identifier of the VNF lifecycle operation occurrence." + }, + "vnfInstanceId": { + "type": "string", + "description": "Identifier of the VNF instance." + } + } + }, + "VnfTerminateResponse": { + "type": "object", + "description": "TerminateVnfResponse.", + "required": [ + "jobId" + ], + "properties": { + "jobId": { + "type": "string", + "description": "Identifier of the VNF lifecycle operation occurrence." + } + } + }, + "VnfInfoResponse": { + "type": "object", + "description": "The information items about the selected VNF instance(s) that are returned..", + "required": [ + "VnfInfo" + ], + "properties": { + "VnfInfo": { + "$ref": "#/definitions/VnfInfo" + } + } + }, + "VnfInfo": { + "type": "object", + "description": "The information items about the selected VNF instance(s) that are returned..", + "required": [ + "vnfInstanceId", + "vnfInstanceName", + "vnfInstanceDescription", + "vnfdId", + "vnfPackageId", + "version", + "vnfProvider", + "vnfType", + "vnfStatus" + ], + "properties": { + "vnfInstanceId": { + "type": "string", + "description": "VNF instance identifier." + }, + "vnfInstanceName": { + "type": "string", + "description": "VNF instance name." + }, + "vnfInstanceDescription": { + "type": "string", + "description": "Human-readable description of the VNF instance." + }, + "vnfdId": { + "type": "string", + "description": "Identifier of the VNFD on which the VNF instance is based." + }, + "vnfPackageId": { + "type": "string", + "description": "Identifier of the VNF Package used to manage the lifecycle of the VNF instance." + }, + "version": { + "type": "string", + "description": "Version of the VNF." + }, + "vnfProvider": { + "type": "string", + "description": "Name of the person or company providing the VNF." + }, + "vnfType": { + "type": "string", + "description": "VNF Application Type." + }, + "vnfStatus": { + "default": "active", + "enum": [ + "inactive", + "active" + ], + "description": "The instantiation state of the VNF. Possible values:INACTIVE (Vnf is terminated or not instantiated ), ACTIVE (Vnf is instantiated). [instantiationState]." + } + } + }, + "VnfTerminate": { + "type": "object", + "description": "Terminate VNF.", + "required": [ + "terminationType", + "gracefulTerminationTimeout" + ], + "properties": { + "terminationType": { + "default": "forceful", + "enum": [ + "forceful", + "graceful" + ], + "description": "Signals whether forceful or graceful termination is requested.." + }, + "gracefulTerminationTimeout": { + "type": "integer", + "format": "int32", + "description": "The time interval (second) to wait for the VNF to be taken out of service during graceful termination, before shutting down the VNF and releasing the resources.." + } + } + }, + "Vnf": { + "type": "object", + "description": "VNF encapsulate an external IP for the given project in a domain. Each property description is provided with 1. required 2. update allowed 3. format. whenever its needs to be mentioned explicitly.", + "required": [ + "vnfInstanceName", + "vnfPackageId", + "vnfDescriptorId", + "flavourId", + "vnfInstanceDescription", + "extVirtualLink" + ], + "properties": { + "vnfInstanceName": { + "type": "string", + "description": "Human-readable name of the VNF instance to be created.." + }, + "vnfPackageId": { + "type": "string", + "description": "VNF packageId." + }, + "vnfDescriptorId": { + "type": "string", + "description": "Information sufficient to identify the VNF Descriptor which defines the VNF to be created." + }, + "flavourId": { + "type": "string", + "description": "verify." + }, + "vnfInstanceDescription": { + "type": "string", + "description": "Human-readable description of the VNF instance to be created." + }, + "extVirtualLink": { + "$ref": "#/definitions/ExtVirtualLinkData" + } + } + }, + "ExtVirtualLinkData": { + "type": "object", + "description": "References to external virtual links to connect the VNF to.", + "required": [ + "vlInstanceId", + "vim", + "networkId", + "cpdId" + ], + "properties": { + "vlInstanceId": { + "type": "string", + "description": "Identifier of the VL instance." + }, + "vim": { + "$ref": "#/definitions/VimInfo" + }, + "networkId": { + "type": "string", + "description": "The network UUID of VIM" + }, + "cpdId": { + "type": "string", + "description": "Identifier of the external CPD in VNFD" + } + } + }, + "VimInfo": { + "type": "object", + "description": "Information about the VIM that manages this resource.", + "required": [ + "vimInfoId", + "vimId", + "interfaceInfo", + "accessInfo", + "interfaceEndpoint" + ], + "properties": { + "vimInfoId": { + "type": "string", + "description": "The identifier of this VimInfo instance, for the purpose of referencing it from other information elements." + }, + "vimId": { + "type": "string", + "description": "The identifier of the VIM.." + }, + "interfaceInfo": { + "$ref": "#/definitions/interfaceInfo" + }, + "accessInfo": { + "$ref": "#/definitions/accessInfo" + }, + "interfaceEndpoint": { + "type": "string", + "description": "Information about the interface endpoint. An example is a URL." + } + } + }, + "interfaceInfo": { + "type": "object", + "description": "Information about the interface to the VIM, including VIM provider type, API version, and protocol type..", + "required": [ + "vimType", + "apiVersion", + "protocolType" + ], + "properties": { + "vimType": { + "type": "string", + "description": "vim" + }, + "apiVersion": { + "type": "string", + "description": "api version" + }, + "protocolType": { + "type": "string", + "description": "Type of the protocol" + } + } + }, + "accessInfo": { + "type": "object", + "description": "Authentication credentials for accessing the VIM. Examples may include those to support different authentication schemes, e.g., OAuth, Token, etc..", + "required": [ + "tenant", + "username", + "password" + ], + "properties": { + "tenant": { + "type": "string", + "description": "Tenant Name of tenant" + }, + "username": { + "type": "string", + "description": "Username for login" + }, + "password": { + "type": "string", + "description": "Password of login user" + } + } + }, + "Error": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "message": { + "type": "string" + } + } + } + } +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/webapp/WEB-INF/web.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..95bce6b --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,51 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2016 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. + --> + +<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee + http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + <servlet> + <servlet-name>CXFServlet</servlet-name> + <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class> + <load-on-startup>1</load-on-startup> + </servlet> + <servlet-mapping> + <servlet-name>CXFServlet</servlet-name> + <url-pattern>/openoapi/jujuvnfm/*</url-pattern> + </servlet-mapping> + <listener> + <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> + </listener> + <context-param> + <param-name>contextConfigLocation</param-name> + <param-value>WEB-INF/classes/spring/JujuVnfmadapter/*.xml + </param-value> + </context-param> + + <session-config> + <session-timeout>10000000</session-timeout> + </session-config> + + <display-name>juju-vnfmadapter-service</display-name> + + + <welcome-file-list> + <welcome-file>index.html</welcome-file> + </welcome-file-list> + +</web-app>
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/AsyncCallbackTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/AsyncCallbackTest.java new file mode 100644 index 0000000..ea01d2b --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/AsyncCallbackTest.java @@ -0,0 +1,44 @@ +/* + * 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.nfvo.jujuvnfmadapter.common; + +import org.apache.log4j.Logger; +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.service.rest.fullstack.JujuClientRoaTest; + +public class AsyncCallbackTest { + Logger logger = Logger.getLogger(JujuClientRoaTest.class); + + AsyncCallback Async; + RestfulResponse response = new RestfulResponse(); + + @Before + public void setUp() { + Async = new AsyncCallback(); + + } + + @Test + public void testhandleExcepion() { + + logger.warn("function=callback, msg=status={}, content={}."); + Async.callback(response); + Async.handleExcepion(null); + + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/CryptUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/CryptUtilTest.java new file mode 100644 index 0000000..28350b4 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/CryptUtilTest.java @@ -0,0 +1,42 @@ +/* + * 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +public class CryptUtilTest { + + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = CryptUtil.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } + @Test + public void testdeCryptenCrypt(){ + String pwd ="admin"; + String c=CryptUtil.deCrypt(pwd); + String c1=CryptUtil.enCrypt(pwd); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/DownloadCsarManagerTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/DownloadCsarManagerTest.java new file mode 100644 index 0000000..d4eee79 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/DownloadCsarManagerTest.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +public class DownloadCsarManagerTest { + DownloadCsarManager mgr; + @Test + public void test() { + String url=""; + String filepath=""; + mgr.download(url); + mgr.download(url, filepath); + mgr.getRandomFileName(); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = DownloadCsarManager.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/EntityUtilsTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/EntityUtilsTest.java new file mode 100644 index 0000000..0fed60d --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/EntityUtilsTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils.ExeRes; + +import net.sf.json.JSONObject; + +public class EntityUtilsTest { + + @Test + public void formatCommandTest(){ + List<String> command = new ArrayList<>(); + command.add("test"); + String result = EntityUtils.formatCommand(command); + assertTrue(result.contains("test")); + } + @Test + public void formatCommandTestNull(){ + List<String> command = null; + String result = EntityUtils.formatCommand(command); + assertTrue(result.equals("")); + } + @Test + public void executeTest(){ + ExeRes res = EntityUtils.execute("test", "test","test2"); + assertNotNull(res); + } + @Test(expected = Exception.class) + public void toEntity() throws Exception{ + JSONObject jsonObject = new JSONObject(); + HashMap map = EntityUtils.toEntity(jsonObject, HashMap.class); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = EntityUtils.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtil.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtil.java new file mode 100644 index 0000000..6e03e32 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtil.java @@ -0,0 +1,50 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +public class FileUtil { + + public static String ReadFile(String path) { + File file = new File(path); + BufferedReader reader = null; + String laststr = ""; + try { + reader = new BufferedReader(new FileReader(file)); + String tempString = null; + while((tempString = reader.readLine()) != null) { + laststr = laststr + tempString; + } + reader.close(); + } catch(IOException e) { + e.printStackTrace(); + } finally { + if(reader != null) { + try { + reader.close(); + } catch(IOException e1) { + } + } + } + return laststr; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtilsTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtilsTest.java new file mode 100644 index 0000000..d41824c --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/FileUtilsTest.java @@ -0,0 +1,94 @@ +/* + * 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import java.io.File; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.List; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class FileUtilsTest { + + FileUtils fileUtils; + @Before + public void setUp(){ + fileUtils.getAppAbsoluteUrl(); + } + + @Test + public void testWriteFile() throws Exception { + ClassLoader classLoader = getClass().getClassLoader(); + File file = new File(classLoader.getResource("").getFile()); + String filePath = ""; + byte[] bytes = new byte[] {40,50}; + int b = fileUtils.writeFile(bytes, filePath); + assertNotNull(b); + } + @Test + @Ignore + public void testReadFile() throws Exception { + ClassLoader classLoader = getClass().getClassLoader(); + File f = new File(classLoader.getResource("").getFile()); + System.out.println(f.isAbsolute()); + String charsetName = "UTF-8"; + byte[] b = fileUtils.readFile(f, charsetName); + assertNotNull(b); + } + @Test + public void testListFiles() throws Exception { + String file = "."; + File f = new File(file); + List<File> files = fileUtils.listFiles(f); + assertNotNull(files); + + } + @Test + public void testMkDirs() throws Exception { + File resourcesDirectory = new File("src/test/resources"); + String path = resourcesDirectory.getAbsolutePath()+"/TestDir"; + resourcesDirectory.getAbsolutePath(); + fileUtils.mkDirs(path); + } + @Test + public void testDelFiles() throws Exception { + File resourcesDirectory = new File("src/test/resources/TestDir/Test.txt"); + assertTrue(fileUtils.delFiles(resourcesDirectory.getAbsolutePath())); + } + @Test + public void testgetFiles() throws Exception { + File resourcesDirectory = new File("src/test/resources"); + List<File> files = fileUtils.getFiles(resourcesDirectory.getAbsolutePath()); + assertNotNull(files); + } + @Test + public void testCopy() throws Exception { + File oldfile = new File(""); + File newfile = new File(""); + fileUtils.copy(oldfile.getAbsolutePath(), newfile.getAbsolutePath(), true); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = FileUtils.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/JujuConfigUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/JujuConfigUtilTest.java new file mode 100644 index 0000000..1175fe8 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/JujuConfigUtilTest.java @@ -0,0 +1,35 @@ +/* + * 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +public class JujuConfigUtilTest { + + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = JujuConfigUtil.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/LocalComandUtilsTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/LocalComandUtilsTest.java new file mode 100644 index 0000000..61b84d5 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/LocalComandUtilsTest.java @@ -0,0 +1,57 @@ +/* + * 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.LocalComandUtils.ExeRes; + +import mockit.Mock; +import mockit.MockUp; + +public class LocalComandUtilsTest { + + @Test + public void testformatCommand(){ + new MockUp<LocalComandUtils>(){ + @Mock + public String formatCommand(List<String> command){ + return null; + } + }; + List<String> command =new ArrayList<String> (); + command.add("test1"); + command.add("test2"); + String s=LocalComandUtils.formatCommand(command); + + + } + + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = LocalComandUtils.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/ResourceUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/ResourceUtilTest.java new file mode 100644 index 0000000..ce6e755 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/ResourceUtilTest.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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + + +public class ResourceUtilTest { + + @Test + public void testformatCommand(){ + String key="key"; + String r=ResourceUtil.getMessage(key); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = ResourceUtil.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/SpringContextHolderTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/SpringContextHolderTest.java new file mode 100644 index 0000000..34c8c72 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/SpringContextHolderTest.java @@ -0,0 +1,44 @@ +/* + * 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.ApplicationContext; + + +public class SpringContextHolderTest { + + SpringContextHolder contextholder; + @Before + public void setUp() { + contextholder = new SpringContextHolder(); + } + @Autowired + ApplicationContext context; + @Test + public void test() { + SpringContextHolder ctx=new SpringContextHolder(); + ctx.setApplicationContext(context); + contextholder.cleanApplicationContext(); + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/StringUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/StringUtilTest.java new file mode 100644 index 0000000..ea95a8a --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/StringUtilTest.java @@ -0,0 +1,122 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import net.sf.json.JSONArray; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.StringUtil; + +public class StringUtilTest { + + @Test + public void testIsValidString() { + boolean result = StringUtil.isValidString("abc"); + assertTrue(result); + } + + @Test + public void testIsValidString1() { + boolean result = StringUtil.isValidString(" abc "); + assertTrue(result); + } + + @Test + public void testIsValidString2() { + boolean result = StringUtil.isValidString(" "); + assertFalse(result); + } + + @Test + public void testIsValidString3() { + boolean result = StringUtil.isValidString(""); + assertFalse(result); + } + + @Test + public void testIsValidString4() { + boolean result = StringUtil.isValidString(null); + assertFalse(result); + } + + @Test + public void testIsValidUrl() { + boolean result = StringUtil.isValidUrl("https://127.0.0.1:31943"); + assertTrue(result); + } + + @Test + public void testIsValidUrl1() { + boolean result = StringUtil.isValidUrl("http://255.250.255.1:31943"); + assertTrue(result); + } + + @Test + public void testIsValidUrl2() { + boolean result = StringUtil.isValidUrl("http:"); + assertFalse(result); + } + + @Test + public void testIsValidUrl3() { + boolean result = StringUtil.isValidUrl("http://255.250"); + assertFalse(result); + } + + @Test + public void testIsValidUrl4() { + boolean result = StringUtil.isValidUrl(""); + assertFalse(result); + } + + @Test + public void testIsValidAnyString() { + boolean result = StringUtil.isValidAnyString("abc", "aaa", "bbb"); + assertTrue(result); + } + + @Test + public void testIsValidAnyString1() { + boolean result = StringUtil.isValidAnyString("abc", "", "bbb"); + assertFalse(result); + } + + @Test + public void testTransSitesToArray() { + String sites = "Beijing&Shanghai"; + JSONArray result = StringUtil.transSitesToArray(sites); + + JSONArray siteArray = new JSONArray(); + siteArray.add("Beijing"); + siteArray.add("Shanghai"); + assertEquals(siteArray, result); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = StringUtil.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/TestPojo.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/TestPojo.java new file mode 100644 index 0000000..04c3bcc --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/TestPojo.java @@ -0,0 +1,47 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestPojo { + String name; + String id; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + @Test + public void test(){ + assertTrue(true); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/UnCompressUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/UnCompressUtilTest.java new file mode 100644 index 0000000..c821cbf --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/UnCompressUtilTest.java @@ -0,0 +1,78 @@ +/* + * 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.nfvo.jujuvnfmadapter.common; + +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +public class UnCompressUtilTest { + + UnCompressUtil util; + + FileInputStream fis; + + @Before + public void setUp(){ + util = new UnCompressUtil(); + + } + + @Test + + public void unCompressGzipTest() { + String zipfileName = ""; + String outputDirectory = ""; + List<String> fileNames = new ArrayList<String>(); + //fileNames.add("test1"); + util.unCompressGzip(zipfileName, outputDirectory, fileNames); + } + + @Test + + public void unCompressZipTest() { + String zipfileName = ""; + String outputDirectory = ""; + List<String> fileNames = new ArrayList<String>(); + util.unCompressZip(zipfileName, outputDirectory, fileNames); + } + + + @Test + + public void unCompressTarXZTest() { + String zipfileName = ""; + String outputDirectory = ""; + List<String> fileNames = new ArrayList<String>(); + util.unCompressTarXZ(zipfileName, outputDirectory, fileNames); + } + + @Test + + public void unCompressTest() { + String zipfileName = ""; + String outputDirectory = "src//test//resources"; + List<String> fileNames = new ArrayList<String>(); + util.unCompress(zipfileName, outputDirectory, fileNames); + } + + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/VNFJsonUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/VNFJsonUtilTest.java new file mode 100644 index 0000000..38aa3b9 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/VNFJsonUtilTest.java @@ -0,0 +1,250 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import net.sf.json.JSONObject; +import net.sf.json.JsonConfig; + +import org.codehaus.jackson.map.ObjectMapper; +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.VNFJsonUtil; + +import mockit.Mock; +import mockit.MockUp; +import org.codehaus.jackson.map.type.TypeFactory; +import org.codehaus.jackson.type.TypeReference; +public class VNFJsonUtilTest { + + @Test + public void testGetJsonFieldStr() { + JSONObject VNFJsonObj = new JSONObject(); + VNFJsonObj.put("name", "testName"); + String result = VNFJsonUtil.getJsonFieldStr(VNFJsonObj, "name"); + assertEquals("testName", result); + } + + @Test + public void testGetJsonFieldStrByNull() { + String result = VNFJsonUtil.getJsonFieldStr(null, "name"); + assertEquals("", result); + } + + @Test + public void testGetJsonFieldStrByFieldNameNull() { + JSONObject VNFJsonObj = new JSONObject(); + VNFJsonObj.put("names", "testName"); + String result = VNFJsonUtil.getJsonFieldStr(VNFJsonObj, "name"); + assertEquals("", result); + } + + @Test + public void testGetJsonFieldStrByNameNull() { + JSONObject VNFJsonObj = new JSONObject(); + VNFJsonObj.put("name", "null"); + String result = VNFJsonUtil.getJsonFieldStr(VNFJsonObj, "name"); + assertEquals("", result); + } + + @Test + public void testGetJsonFieldInt() { + JSONObject VNFJsonObj = new JSONObject(); + VNFJsonObj.put("name", 5); + Integer result = VNFJsonUtil.getJsonFieldInt(VNFJsonObj, "name"); + assertEquals((Integer)5, result); + } + + @Test + public void testGetJsonFieldIntByNull() { + Integer result = VNFJsonUtil.getJsonFieldInt(null, "name"); + assertEquals((Integer)0, result); + } + + @Test + public void testGetJsonFieldIntByNameNull() { + JSONObject VNFJsonObj = new JSONObject(); + VNFJsonObj.put("name", 5); + Integer result = VNFJsonUtil.getJsonFieldInt(VNFJsonObj, "names"); + assertEquals((Integer)0, result); + } + + @Test + public void testGetJsonFieldLong() { + JSONObject VNFJsonObj = new JSONObject(); + VNFJsonObj.put("name", 5L); + Long result = VNFJsonUtil.getJsonFieldLong(VNFJsonObj, "name"); + assertEquals((Long)5L, result); + } + + @Test + public void testGetJsonFieldLongByNull() { + Long result = VNFJsonUtil.getJsonFieldLong(null, "name"); + assertEquals((Long)0L, result); + } + + @Test + public void testGetJsonFieldLongByNameNull() { + JSONObject VNFJsonObj = new JSONObject(); + VNFJsonObj.put("name", 5L); + Long result = VNFJsonUtil.getJsonFieldLong(VNFJsonObj, "names"); + assertEquals((Long)0L, result); + } + + @Test + public void testParseErrorInfo() { + String errorInfo = "{\"error\":{\"message\":\"errorMessage\"}}"; + String result = VNFJsonUtil.parseErrorInfo(errorInfo); + assertEquals("errorMessage", result); + } + + @Test + public void testParseErrorInfoByNull() { + String result = VNFJsonUtil.parseErrorInfo(null); + assertEquals("System Error!", result); + } + + @Test + public void testParseErrorInfoByEmpty() { + String errorInfo = ""; + String result = VNFJsonUtil.parseErrorInfo(errorInfo); + assertEquals("System Error!", result); + } + + @Test + public void testParseErrorInfoByNoError() { + String errorInfo = "{\"errors\":{\"message\":\"errorMessage\"}}"; + String result = VNFJsonUtil.parseErrorInfo(errorInfo); + assertEquals("System Error!", result); + } + + @Test + public void testParseErrorInfoByNoMessage() { + String errorInfo = "{\"error\":{\"messages\":\"errorMessage\"}}"; + String result = VNFJsonUtil.parseErrorInfo(errorInfo); + assertEquals("System Error!", result); + } + + @Test + public void testObjectToJsonStr() { + String data = "{\"vnf1\":{\"id\":\"id\"}}"; + String result = VNFJsonUtil.objectToJsonStr(data); + assertEquals(data, result); + } + + @Test + public void testObjectToJson() { + String data = "{\"vnf1\":{\"id\":\"id\"}}"; + JSONObject result = VNFJsonUtil.objectToJson(data); + assertEquals(JSONObject.fromObject(data), result); + } + @Test + public void marshalTest() throws IOException{ + net.sf.json.JSON json = new JSONObject(); + String res = VNFJsonUtil.marshal(json); + assertTrue(res.equals("{}")); + } + + @Test + public void marshalTestException() throws IOException{ + String str="test"; + String res = VNFJsonUtil.marshal(str); + assertTrue(res != null); + } + + @Test + public void VNFJsonToListsTest(){ + List<TestPojo> pojoList = VNFJsonUtil.vnfJsonToLists("[{\"name\":\"test\",\"id\":\"123\"}]",TestPojo.class); + assertTrue(pojoList.size()==1); + } + + @Test + public void VNFJsonToListTest(){ + List<TestPojo> pojoList = VNFJsonUtil.vnfJsonToList("[{\"name\":\"test\",\"id\":\"123\"}]", TestPojo.class, "test"); + assertTrue(pojoList.size()==1); + } + + @Test + public void VNFJsonToObjectsTest(){ + TestPojo pojo = VNFJsonUtil.vnfJsonToObjects("{\"name\":\"test\",\"id\":\"123\"}", TestPojo.class); + assertTrue("test".equals(pojo.getName()) && "123".equals(pojo.getId())); + } + + @Test(expected = Exception.class) + public void VNFJsonToObjectsTestException(){ + JsonConfig VNFJsonConfig = new JsonConfig(); + TestPojo pojo = VNFJsonUtil.vnfJsonToObjects("{\"id\":\"123\",\"name\":\"test\"}", VNFJsonConfig); + } + + @Test + public void objectToJsonTest(){ + JsonConfig VNFJsonConfig = new JsonConfig(); + TestPojo pojo = new TestPojo(); + pojo.setName("test"); + pojo.setId("123"); + String res = VNFJsonUtil.objectToJson(pojo, VNFJsonConfig); + assertTrue("{\"id\":\"123\",\"name\":\"test\"}".equals(res)); + } + + @Test + public void objectToJsonTest2(){ + TestPojo pojo = new TestPojo(); + pojo.setName("test"); + pojo.setId("123"); + String res = VNFJsonUtil.objectToJson(pojo, ""); + assertTrue("{\"id\":\"123\",\"name\":\"test\"}".equals(res)); + } + + @Test + public void listToJsonTest(){ + List<TestPojo> pojoList = new ArrayList<TestPojo>(); + TestPojo pojo = new TestPojo(); + pojo.setName("test"); + pojo.setId("123"); + pojoList.add(pojo); + String res = VNFJsonUtil.listToJson(pojoList); + assertTrue("[{\"id\":\"123\",\"name\":\"test\"}]".equals(res)); + } + + @Test + public void listToJsonTest2(){ + List<TestPojo> pojoList = new ArrayList<TestPojo>(); + TestPojo pojo = new TestPojo(); + pojo.setName("test"); + pojo.setId("123"); + pojoList.add(pojo); + String res = VNFJsonUtil.listToJson(pojoList,""); + assertTrue("[{\"id\":\"123\",\"name\":\"test\"}]".equals(res)); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = VNFJsonUtil.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmUtilTest.java new file mode 100644 index 0000000..414218b --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/VnfmUtilTest.java @@ -0,0 +1,123 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +public class VnfmUtilTest { + + @Test + public void getVnfmByIdTestNull(){ + JSONObject resp = VnfmUtil.getVnfmById("vnfmId"); + assertNull(resp); + } + @Test + public void getVnfmByIdTest(){ + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(String url, String methodType, String params) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(200); + JSONObject json = new JSONObject(); + json.put("id", "1234"); + resp.setResponseJson(json.toString()); + return resp; + } + }; + JSONObject resp = VnfmUtil.getVnfmById("vnfmId"); + assertNotNull(resp); + } + @Test + public void getVnfmByIdTest2(){ + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(String url, String methodType, String params) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(500); + return resp; + } + }; + JSONObject resp = VnfmUtil.getVnfmById("vnfmId"); + assertNull(resp); + } + @Test + public void getVnfmIdByIpNullResp(){ + String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1"); + assertEquals(resp,""); + } + @Test + public void getVnfmIdByIpInternalError(){ + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(String url, String methodType, String params) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(500); + return resp; + } + }; + String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1"); + assertEquals(resp,""); + } + @Test + public void getVnfmIdByIp(){ + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(String url, String methodType, String params) { + RestfulResponse resp = new RestfulResponse(); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonobj = new JSONObject(); + jsonobj.put("url", "1.1.1.1"); + jsonobj.put("vnfmId", "1111"); + jsonArray.add(jsonobj); + resp.setResponseJson(jsonArray.toString()); + resp.setStatus(200); + return resp; + } + }; + String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1"); + assertEquals(resp,"1111"); + } + + @Test + public void getVnfmIdByIpInvalidIP(){ + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(String url, String methodType, String params) { + RestfulResponse resp = new RestfulResponse(); + JSONArray jsonArray = new JSONArray(); + JSONObject jsonobj = new JSONObject(); + jsonobj.put("url", "1.1.1.1"); + jsonobj.put("vnfmId", "1111"); + jsonArray.add(jsonobj); + resp.setResponseJson(jsonArray.toString()); + resp.setStatus(200); + return resp; + } + }; + String resp = VnfmUtil.getVnfmIdByIp("1.1.1.2"); + assertEquals(resp,""); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/YamlUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/YamlUtilTest.java new file mode 100644 index 0000000..193961a --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/YamlUtilTest.java @@ -0,0 +1,48 @@ +/* + * Copyright (c) 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.nfvo.jujuvnfmadapter.common; + +import java.io.File; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.yaml.snakeyaml.Yaml; + +import net.sf.json.JSON; + +public class YamlUtilTest { + YamlUtil yaml; + + @Before + public void setUp() { + yaml = new YamlUtil(); + + } + + @Test + public void test() throws ServiceException { + String yamlName = "src/test/resources/test.yaml"; + + JSON json=yaml.yamlToJson(yamlName); + + String S=yaml.loadYaml(yamlName); + Yaml yaml = new Yaml(); + File file =new File(yamlName); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestHelpTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestHelpTest.java new file mode 100644 index 0000000..93d715b --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestHelpTest.java @@ -0,0 +1,58 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; +import org.openo.baseservice.roa.util.restclient.Restful; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.HttpRestHelp; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 10, 2016 + */ +public class HttpRestHelpTest { + + @Test + public void testGetRestInstance() { + Restful rest = HttpRestHelp.getRestInstance(null, null, false); + assertNotNull(rest); + } + + @Test + public void testGetRestInstance1() { + HttpRestHelp.getRestInstance(null, null, false); + Restful rest = HttpRestHelp.getRestInstance(null, null, false); + assertNotNull(rest); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = HttpRestHelp.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestfulHelpTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestfulHelpTest.java new file mode 100644 index 0000000..4167c7b --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/HttpRestfulHelpTest.java @@ -0,0 +1,58 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.common.servicetoken; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; +import org.openo.baseservice.roa.util.restclient.Restful; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.HttpRestfulHelp; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 10, 2016 + */ +public class HttpRestfulHelpTest { + + @Test + public void testGetRestInstance() { + Restful rest = HttpRestfulHelp.getRestInstance(null, null); + assertNotNull(rest); + } + + @Test + public void testGetRestInstance1() { + HttpRestfulHelp.getRestInstance(null, null); + Restful rest = HttpRestfulHelp.getRestInstance(null, null); + assertNotNull(rest); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = HttpRestfulHelp.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/JujuVnfmRestfulUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/JujuVnfmRestfulUtilTest.java new file mode 100644 index 0000000..0c34643 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/JujuVnfmRestfulUtilTest.java @@ -0,0 +1,247 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.common.servicetoken; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VNFRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 10, 2016 + */ +public class JujuVnfmRestfulUtilTest { + + + @Test + public void testGetRemoteResponseByVnfmInfoNull() { + RestfulResponse result = JujuVnfmRestfulUtil.getRemoteResponse(new HashMap(), null); + assertEquals(null, result); + } + + @Test + public void testGetRemoteResponseByPost() { + Map testMap = new HashMap(); + testMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + testMap.put("methodType","post"); + RestfulResponse result = JujuVnfmRestfulUtil.getRemoteResponse(testMap, ""); + + assertEquals(null, result); + } + + @Test + public void testGetRemoteResponseByVnfmInfo() { + Map testMap = new HashMap(); + testMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + testMap.put("methodType","get"); + RestfulResponse result = JujuVnfmRestfulUtil.getRemoteResponse(testMap, ""); + + assertEquals(null, result); + } + + @Test + public void testGetRemoteResponseByVnfmInfoPut() { + Map testMap = new HashMap(); + testMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + testMap.put("methodType","put"); + RestfulResponse result = JujuVnfmRestfulUtil.getRemoteResponse(testMap, ""); + + assertEquals(null, result); + } + + @Test + public void testGetRemoteResponseByVnfmInfoDelete() { + Map testMap = new HashMap(); + testMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + testMap.put("methodType","delete"); + RestfulResponse result = JujuVnfmRestfulUtil.getRemoteResponse(testMap, ""); + + assertEquals(null, result); + } + + @Test + public void getVimResponseContentGetInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + Map<String, Object> result = JujuVnfmRestfulUtil.getVimResponseContent("http://127.0.0.1:8080", restParametes, null, "put"); + assertTrue(result.isEmpty()); + } + @Test + public void getVimResponseContentAddInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + Map<String, Object> result = JujuVnfmRestfulUtil.getVimResponseContent("http://127.0.0.1:8080", restParametes, null, "add"); + assertTrue(result.isEmpty()); + } + + @Test + public void getVimResponseContentPutInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + Map<String, Object> result = JujuVnfmRestfulUtil.getVimResponseContent("http://127.0.0.1:8080", restParametes, null, "put"); + assertTrue(result.isEmpty()); + } + @Test + public void getVimResponseContentDeleteInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + Map<String, Object> result = JujuVnfmRestfulUtil.getVimResponseContent("http://127.0.0.1:8080", restParametes, null, "delete"); + assertTrue(result.isEmpty()); + } + + @Test + public void getVimResponseContentPatchInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + Map<String, Object> result = JujuVnfmRestfulUtil.getVimResponseContent("http://127.0.0.1:8080", restParametes, null, "patch"); + assertTrue(result.isEmpty()); + } + + @Test + public void testGetResultToVnfmByVnfmInfoErrorMsg() { + JSONObject vnfmInfo = new JSONObject(); + vnfmInfo.put("retCode", Constant.REST_FAIL); + vnfmInfo.put("msg", "ErrorMsg"); + JSONObject result = VNFRestfulUtil.getResultToVnfm(vnfmInfo, "vnfmId"); + + JSONObject retJson = new JSONObject(); + retJson.put("retCode", Constant.REST_FAIL); + retJson.put("data", "ErrorMsg"); + assertEquals(retJson, result); + } + + @Test + public void testGetResultToVnfmByVnfmInfoError() { + JSONObject vnfmInfo = new JSONObject(); + vnfmInfo.put("retCode", Constant.REST_FAIL); + JSONObject result = VNFRestfulUtil.getResultToVnfm(vnfmInfo, "vnfmId"); + + JSONObject retJson = new JSONObject(); + retJson.put("retCode", Constant.REST_FAIL); + assertEquals(retJson, result); + } + + @Test + public void vimRestfulResponseTestGetInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + RestfulResponse resp = JujuVnfmRestfulUtil.vimRestfulResponse("http://127.0.0.1:8080", restParametes, null, "get"); + assertTrue(resp == null); + } + @Test + public void vimRestfulResponseTestAddInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + RestfulResponse resp = JujuVnfmRestfulUtil.vimRestfulResponse("http://127.0.0.1:8080", restParametes, null, "add"); + assertTrue(resp == null); + } + + @Test + public void vimRestfulResponseTestPutInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + RestfulResponse resp = JujuVnfmRestfulUtil.vimRestfulResponse("http://127.0.0.1:8080", restParametes, null, "put"); + assertTrue(resp == null); + } + + @Test + public void vimRestfulResponseTestDeleteInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + RestfulResponse resp = JujuVnfmRestfulUtil.vimRestfulResponse("http://127.0.0.1:8080", restParametes, null, "delete"); + assertTrue(resp == null); + } + + @Test + public void vimRestfulResponseTestPatchInvalid(){ + RestfulParametes restParametes = new RestfulParametes(); + RestfulResponse resp = JujuVnfmRestfulUtil.vimRestfulResponse("http://127.0.0.1:8080", restParametes, null, "patch"); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponseTestGetInvalid(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("methodType","get"); + RestfulResponse resp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test", false); + assertNull(resp); + + } + + @Test + public void getRemoteResponseTestGetHttpsInvalid(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("methodType","get"); + RestfulResponse resp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test", true); + assertNull(resp); + + } + + @Test + public void getRemoteResponseTestPostInvalid(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("methodType","post"); + RestfulResponse resp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test", false); + assertNull(resp); + + } + + @Test + public void getRemoteResponseTestPutInvalid(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("methodType","put"); + RestfulResponse resp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test", false); + assertNull(resp); + + } + + @Test + public void getRemoteResponseTestDeleteInvalid(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("methodType","delete"); + RestfulResponse resp = JujuVnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test", false); + assertNull(resp); + + } + @Test + public void generateParametesMapTest(){ + Map<String, String> paramsMap = JujuVnfmRestfulUtil.generateParametesMap("http://localhost:8080", "get", "openoapi/test", "test"); + assertTrue("http://localhost:8080".equals(paramsMap.get("url")) && "get".equals(paramsMap.get("methodType")) + && "openoapi/test".equals(paramsMap.get("path")) && "test".equals(paramsMap.get("authMode"))); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = JujuVnfmRestfulUtil.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFAuthConfigInfoTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFAuthConfigInfoTest.java new file mode 100644 index 0000000..23ed850 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFAuthConfigInfoTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VNFAuthConfigInfo; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 10, 2016 + */ +public class VNFAuthConfigInfoTest { + + @Test + public void testGetDomain() { + VNFAuthConfigInfo authConfig = VNFAuthConfigInfo.getInstance(); + authConfig.setDomain("vnfDomain"); + assertEquals("vnfDomain", authConfig.getDomain()); + } + + @Test + public void testGetResourceDomain() { + VNFAuthConfigInfo authConfig = VNFAuthConfigInfo.getInstance(); + authConfig.setResourceDomain("vnfResourceDomain"); + assertEquals("vnfResourceDomain", authConfig.getResourceDomain()); + } + + @Test + public void testGetDefaultDomain() { + VNFAuthConfigInfo authConfig = VNFAuthConfigInfo.getInstance(); + authConfig.setDefaultDomain("defaultDomain"); + assertEquals("defaultDomain", authConfig.getDefaultDomain()); + } + + @Test + public void testGetUserName() { + VNFAuthConfigInfo authConfig = VNFAuthConfigInfo.getInstance(); + authConfig.setUserName("vnfuserName"); + assertEquals("vnfuserName", authConfig.getUserName()); + } + + @Test + public void testGetEncryptedPW() { + VNFAuthConfigInfo authConfig = VNFAuthConfigInfo.getInstance(); + authConfig.setEncryptedPW("vnfencryptedPW"); + assertEquals("vnfencryptedPW", authConfig.getEncryptedPW()); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFRestfulUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFRestfulUtilTest.java new file mode 100644 index 0000000..37c6c0b --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VNFRestfulUtilTest.java @@ -0,0 +1,257 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.common.servicetoken; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; + +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author + * @version NFVO 0.5 Aug 10, 2016 + */ +public class VNFRestfulUtilTest { + + @Test + public void testGetRestResByDefaultByNull() { + RestfulResponse result = VNFRestfulUtil.getRestResByDefault("path", "methodNames", new JSONObject()); + assertNull(result); + } + + @Test + public void testGetRestResByDefaultByGet() { + RestfulResponse result = VNFRestfulUtil.getRestResByDefault("path", "get", new JSONObject()); + assertNotNull(result); + } + + @Test + public void testGetRestResByDefaultByPut() { + RestfulResponse result = VNFRestfulUtil.getRestResByDefault("path", "put", new JSONObject()); + assertNotNull(result); + } + + /*@Test + public void testSendReqToApp() { + new MockUp<VNFRestfulUtil>() { + + @Mock + public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulResponse restfulResponse = new RestfulResponse(); + restfulResponse.setStatus(Constant.HTTP_OK); + String responseString = "{\"retCode\":1,\"data\":\"success\"}"; + restfulResponse.setResponseJson(responseString); + return restfulResponse; + } + }; + JSONObject result = VNFRestfulUtil.sendReqToApp("path", "put", new JSONObject()); + assertEquals(Constant.REST_SUCCESS, result.get("retCode")); + }*/ + + /*@Test(expected = ExceptionInInitializerError.class) + public void testSendReqToAppByErrorMsg() { + new MockUp<VNFRestfulUtil>() { + + @Mock + public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulResponse restfulResponse = new RestfulResponse(); + restfulResponse.setStatus(Constant.HTTP_OK); + String responseString = "{\"retCode\":-1,\"data\":\"fail\",\"msg\":\"fail\"}"; + restfulResponse.setResponseJson(responseString); + return restfulResponse; + } + }; + JSONObject result = VNFRestfulUtil.sendReqToApp("path", "put", new JSONObject()); + assertEquals(Constant.REST_FAIL, result.get("retCode")); + }*/ + + /*@Test + public void testSendReqToAppByError() { + new MockUp<VNFRestfulUtil>() { + + @Mock + public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulResponse restfulResponse = new RestfulResponse(); + restfulResponse.setStatus(Constant.HTTP_OK); + String responseString = "{\"retCode\":-1,\"data\":\"fail\"}"; + restfulResponse.setResponseJson(responseString); + return restfulResponse; + } + }; + JSONObject result = VNFRestfulUtil.sendReqToApp("path", "put", new JSONObject()); + assertEquals(Constant.REST_FAIL, result.get("retCode")); + }*/ + + @Test + public void testSendReqToAppByFail() { + JSONObject result = VNFRestfulUtil.sendReqToApp("path", "put", new JSONObject()); + assertEquals(Constant.REST_FAIL, result.get("retCode")); + } + + @Test + public void testSendReqToAppByVnfmInfoPut() { + JSONObject paraJson = new JSONObject(); + JSONObject vnfmObj = new JSONObject(); + vnfmObj.put("id", "id"); + paraJson.put("vnfmInfo", vnfmObj); + JSONObject result = VNFRestfulUtil.sendReqToApp("path", "put", paraJson); + assertEquals(Constant.REST_FAIL, result.get("retCode")); + } + + @Test + public void testGenerateParamsMap() { + Map<String, String> result = VNFRestfulUtil.generateParamsMap("url", "methodType", "path"); + Map<String, String> paramsMap = new HashMap<String, String>(6); + paramsMap.put("url", "url"); + paramsMap.put("methodType", "methodType"); + paramsMap.put("path", "path"); + paramsMap.put("authMode", "Certificate"); + assertEquals(paramsMap, result); + } + + @Test + public void testGenerateParamsMap2() { + Map<String, String> result = VNFRestfulUtil.generateParamsMap("url", "methodType", "path", "authMode"); + Map<String, String> paramsMap = new HashMap<String, String>(6); + paramsMap.put("url", "url"); + paramsMap.put("methodType", "methodType"); + paramsMap.put("path", "path"); + paramsMap.put("authMode", "authMode"); + assertEquals(paramsMap, result); + } + + @Test + public void testGetResultToVnfmByVnfmInfoNull() { + JSONObject result = VNFRestfulUtil.getResultToVnfm(null, null); + + JSONObject retJson = new JSONObject(); + retJson.put("retCode", Constant.REST_FAIL); + retJson.put("data", "get null result"); + assertEquals(retJson, result); + } + + @Test + public void testGetResultToVnfmByVnfmInfoErrorMsg() { + JSONObject vnfmInfo = new JSONObject(); + vnfmInfo.put("retCode", Constant.REST_FAIL); + vnfmInfo.put("msg", "ErrorMsg"); + JSONObject result = VNFRestfulUtil.getResultToVnfm(vnfmInfo, "vnfmId"); + + JSONObject retJson = new JSONObject(); + retJson.put("retCode", Constant.REST_FAIL); + retJson.put("data", "ErrorMsg"); + assertEquals(retJson, result); + } + + @Test + public void testGetResultToVnfmByVnfmInfoError() { + JSONObject vnfmInfo = new JSONObject(); + vnfmInfo.put("retCode", Constant.REST_FAIL); + JSONObject result = VNFRestfulUtil.getResultToVnfm(vnfmInfo, "vnfmId"); + + JSONObject retJson = new JSONObject(); + retJson.put("retCode", Constant.REST_FAIL); + assertEquals(retJson, result); + } + @Test + public void getRemoteResponseTestInvalidGet(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("url", "/openoapi/test"); + paramsMap.put("methodType","get"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, null, "test123", true); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponseTestInvalidPut(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("url", "/openoapi/test"); + paramsMap.put("methodType","put"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, null, "test123", true); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponseTestInvalidPost(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("url", "/openoapi/test"); + paramsMap.put("methodType","post"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, null, "test123", true); + assertTrue(resp == null); + } + @Test + public void getRemoteResponseTestInvalidDelete(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("url", "/openoapi/test"); + paramsMap.put("methodType","delete"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, null, "test123", true); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponseTestFalseNfvoApp(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "http://localhost:8080"); + paramsMap.put("url", "/openoapi/test"); + paramsMap.put("methodType","delete"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VNFRestfulUtil.getRemoteResponse(paramsMap, null, "test123", false); + assertTrue(resp == null); + } + + @Test + public void sentEvtByRestTest(){ + VNFRestfulUtil.sentEvtByRest("http://localhost:8080", "get", null); + assertTrue(true); + } + @Test + public void sentEvtByRestTest2(){ + JSONObject bodyParam = new JSONObject(); + VNFRestfulUtil.sentEvtByRest("http://localhost:8080", "get",bodyParam); + assertTrue(true); + } + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = VNFRestfulUtil.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java new file mode 100644 index 0000000..f0123ed --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java @@ -0,0 +1,224 @@ +/* + * 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. + */ +package org.openo.nfvo.jujuvnfmadapter.common.servicetoken; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class VnfmRestfulUtilTest { + + @Test + public void testGetRestResByDefaultByNull() { + RestfulResponse result = VnfmRestfulUtil.getRestResByDefault("path", "methodNames", new JSONObject()); + assertNull(result); + } + @Test + public void testGetRestResByDefaultByGet() { + RestfulResponse result = VnfmRestfulUtil.getRestResByDefault("path", "get", new JSONObject()); + assertNotNull(result); + } + + @Test + public void testGetRestResByDefaultByPut() { + RestfulResponse result = VnfmRestfulUtil.getRestResByDefault("path", "put", new JSONObject()); + assertNotNull(result); + } + + //// + @Test + public void testSendReqToAppByFail() { + JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject()); + assertEquals(Constant.REST_FAIL, result.get("retCode")); + } + + @Test + public void testSendReqToAppByVnfmInfoPut() { + JSONObject paraJson = new JSONObject(); + JSONObject vnfmObj = new JSONObject(); + vnfmObj.put("id", "id"); + paraJson.put("vnfmInfo", vnfmObj); + JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", paraJson); + assertEquals(Constant.REST_FAIL, result.get("retCode")); + } + + @Test + public void testSendReqToAppByVnfmInfoPutNormal() { + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(200); + JSONObject obj = new JSONObject(); + obj.put("retCode", 1); + obj.put("data", new JSONObject()); + resp.setResponseJson(obj.toString()); + return resp; + } + }; + JSONObject paraJson = new JSONObject(); + JSONObject vnfmObj = new JSONObject(); + vnfmObj.put("id", "id"); + JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", paraJson); + assertEquals(Constant.REST_SUCCESS, result.get("retCode")); + } + @Test + public void testSendReqToAppByVnfmInfoPutNormal2() { + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(200); + JSONObject obj = new JSONObject(); + obj.put("retCode", -1); + obj.put("data", new JSONObject()); + resp.setResponseJson(obj.toString()); + return resp; + } + }; + JSONObject paraJson = new JSONObject(); + JSONObject vnfmObj = new JSONObject(); + vnfmObj.put("id", "id"); + JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", paraJson); + assertEquals(Constant.REST_FAIL, result.get("retCode")); + } + + @Test + public void testGenerateParamsMap() { + Map<String, String> result = VnfmRestfulUtil.generateParamsMap("url", "methodType", "path","auth"); + Map<String, String> paramsMap = new HashMap<String, String>(6); + paramsMap.put("url", "url"); + paramsMap.put("methodType", "methodType"); + paramsMap.put("path", "path"); + paramsMap.put("authMode", "auth"); + assertEquals(paramsMap, result); + } + @Test + public void getRemoteResponseTestInvalidGet(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "/test/abc"); + paramsMap.put("url", "http://localhost:8080"); + paramsMap.put("methodType","get"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test123"); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponseTestInvalidPut(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "/test/abc"); + paramsMap.put("url", "http://localhost:8080"); + paramsMap.put("methodType","put"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test123"); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponseTestInvalidPost(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "/openoapi/test"); + paramsMap.put("url", "http://localhost:8080"); + paramsMap.put("methodType","post"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test123"); + assertTrue(resp == null); + } + @Test + public void getRemoteResponseTestInvalidDelete(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "/openoapi/test"); + paramsMap.put("url", "http://localhost:8080"); + paramsMap.put("methodType","delete"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test123"); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponse2TestInvalidGet(){ + String url = "http://localhost:8080"; + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(url, "get", "test123"); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponse2TestInvalidPut(){ + String url = "http://localhost:8080"; + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(url, "put", "test123"); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponse2TestInvalidPost(){ + String url = "http://localhost:8080"; + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(url, "post", "test123"); + assertTrue(resp == null); + } + @Test + public void getRemoteResponse2TestInvalidDelete(){ + + String url = "http://localhost:8080"; + + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(url, "delete", "test123"); + assertTrue(resp == null); + } + + @Test + public void getRemoteResponseTestFalseNfvoApp(){ + Map<String,String> paramsMap = new HashMap<>(); + paramsMap.put("path", "/openoapi/test"); + paramsMap.put("url", "http://localhost:8080"); + paramsMap.put("methodType","delete"); + paramsMap.put("authMode","test"); + RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse(paramsMap, null, "test123"); + assertTrue(resp == null); + } + + /* @Test + public void sentEvtByRestTest(){ + VnfmRestfulUtil.sentEvtByRest("http://localhost:8080", "get", null); + assertTrue(true); + } + @Test + public void sentEvtByRestTest2(){ + JSONObject bodyParam = new JSONObject(); + VnfmRestfulUtil.sentEvtByRest("http://localhost:8080", "get",bodyParam); + assertTrue(true); + }*/ + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = VnfmRestfulUtil.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/AccessTokensTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/AccessTokensTest.java new file mode 100644 index 0000000..f033984 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/AccessTokensTest.java @@ -0,0 +1,98 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken.module; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import net.sf.json.JSONObject; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.module.AccessTokens; + +public class AccessTokensTest { + + @Test + public void testVimAccessTokens() { + AccessTokens accessTokens = new AccessTokens("accessToken", 123); + assertEquals("accessToken", accessTokens.getAccessToken()); + assertEquals(123, accessTokens.getExpire()); + } + + @Test + public void testAccessTokens1() { + AccessTokens accessTokens = new AccessTokens("accessToken", null, null); + assertEquals("accessToken", accessTokens.getAccessToken()); + assertEquals(0, accessTokens.getExpire()); + assertEquals(0, accessTokens.getCreateTime()); + } + + @Test + public void testAccessTokens2() { + Integer vimExpire = (Integer)123; + Long createTime = (Long)1L; + AccessTokens accessTokens = new AccessTokens("accessToken", vimExpire, createTime); + assertEquals("accessToken", accessTokens.getAccessToken()); + assertEquals(123, accessTokens.getExpire()); + assertEquals(1L, accessTokens.getCreateTime()); + } + + @Test(expected = UnsupportedOperationException.class) + public void testVimAccessTokens3() { + AccessTokens accessTokens = new AccessTokens(); + } + + @Test + public void testSetVimAccessToken() { + AccessTokens accessTokens = new AccessTokens("accessToken", 123); + accessTokens.setAccessToken("anotherToken"); + assertEquals("anotherToken", accessTokens.getAccessToken()); + } + + @Test + public void testValidExpire() { + AccessTokens accessTokens = new AccessTokens("accessToken", 0); + assertTrue(accessTokens.valid()); + } + + @Test + public void testValidExpire1() { + AccessTokens accessTokens = new AccessTokens("accessToken", 123); + assertTrue(accessTokens.valid()); + } + + @Test + public void testValidExpire2() { + AccessTokens accessTokens = new AccessTokens("accessToken", 123, 1L); + assertFalse(accessTokens.valid()); + } + + @Test + public void testToString() { + AccessTokens accessTokens = new AccessTokens("accessToken", 123, 1L); + assertEquals("{accessToken','expire': '123','createTime': '1'}", accessTokens.toString()); + } + + @Test + public void testToEntity() { + String data = "{'accessToken': 'accessToken','expire': '123','createTime': '1'}"; + JSONObject jsonObject = JSONObject.fromObject(data); + AccessTokens accessTokens = new AccessTokens("accessToken", 123, 1L); + assertEquals(accessTokens.toString(), AccessTokens.toEntity(jsonObject).toString()); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/ServiceTokenHelpTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/ServiceTokenHelpTest.java new file mode 100644 index 0000000..afb0f91 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/common/servicetoken/module/ServiceTokenHelpTest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.common.servicetoken.module; + +import org.junit.Test; + +public class ServiceTokenHelpTest { + + @Test + public void testCreateServiceToken() { + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/activator/ROAJujuServicePostProcessorTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/activator/ROAJujuServicePostProcessorTest.java new file mode 100644 index 0000000..ad379ae --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/activator/ROAJujuServicePostProcessorTest.java @@ -0,0 +1,34 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.activator; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ROAJujuServicePostProcessorTest { + ROAJujuServicePostProcessor postprocessor=new ROAJujuServicePostProcessor(); + + @Test + public void test() { + Object bean ="IJujuAdapterMgrService"; + String name=""; + postprocessor.postProcessAfterInitialization(bean, name); + postprocessor.postProcessBeforeDestruction(bean, name); + postprocessor.postProcessBeforeInitialization(bean, name); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java new file mode 100644 index 0000000..d4e6eba --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/AdapterResourceManagerTest.java @@ -0,0 +1,212 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.impl; + +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.HttpRest; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class AdapterResourceManagerTest { + + private AdapterResourceManager adapterResManager; + + private JSONObject jsonObj; + + /* + * @Test public void testGetJujuVnfmInfo() throws Exception { Map paramsMap + * = new HashMap(); JSONObject resultObj = new JSONObject(); + * resultObj.put("reason", "RestfulResponse is null."); + * resultObj.put("retCode", Constant.ERROR_STATUS_CODE); + * + * paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + * paramsMap.put("methodType","get"); + * + * new MockUp<JujuVnfmRestfulUtil>(){ + * + * @Mock public RestfulResponse getRemoteResponse(Map paramsMap,String str) + * { return null; } }; adapterResManager = new AdapterResourceManager(); + * jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap); + * assertEquals(resultObj,jsonObj); } + */ + + /* + * @Test public void testGetVnfdInfo() throws Exception { Map paramsMap = + * new HashMap(); JSONObject resultObj = new JSONObject(); + * resultObj.put("reason", "RestfulResponse is null."); + * resultObj.put("retCode", Constant.ERROR_STATUS_CODE); + * + * paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + * paramsMap.put("methodType","get"); + * + * new MockUp<JujuVnfmRestfulUtil>(){ + * + * @Mock public RestfulResponse getRemoteResponse(Map paramsMap,String str) + * { return null; } }; adapterResManager = new AdapterResourceManager(); + * jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap); + * assertEquals(resultObj,jsonObj); } + */ + + @Test + public void getJujuVnfmInfoTest() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(200); + return rsp; + } + }; + new MockUp<JSONObject>() { + @Mock + public JSONObject fromObject(Object object) { + JSONObject json = new JSONObject(); + return json; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.ERROR_STATUS_CODE); + + paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + paramsMap.put("methodType", "get"); + adapterResManager = new AdapterResourceManager(); + jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap); + assertTrue(jsonObj != null); + } + + @Test + public void getJujuVnfmInfoTest1() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(504); + return rsp; + } + }; + new MockUp<JSONObject>() { + @Mock + public JSONObject fromObject(Object object) { + JSONObject json = new JSONObject(); + return json; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.ERROR_STATUS_CODE); + + paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + paramsMap.put("methodType", "get"); + adapterResManager = new AdapterResourceManager(); + jsonObj = adapterResManager.getJujuVnfmInfo(paramsMap); + assertTrue(jsonObj != null); + } + + @Test + public void getJujuVnfmInfoTestFalse() { + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.ERROR_STATUS_CODE); + + paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + paramsMap.put("methodType", "get"); + adapterResManager = new AdapterResourceManager(); + jsonObj = adapterResManager.getJujuVnfmInfo(null); + assertTrue(jsonObj.get("reason").equals("RestfulResponse is null.")); + } + + @Test + public void getVnfdInfoTest() { + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.ERROR_STATUS_CODE); + + paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + paramsMap.put("methodType", "get"); + adapterResManager = new AdapterResourceManager(); +// jsonObj = adapterResManager.getVnfdInfo("1111"); +// assertTrue(jsonObj.get("reason").equals("RestfulResponse is null.")); + } + + @Test + public void getVnfdInfoTest1() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(200); + return rsp; + } + }; + new MockUp<JSONObject>() { + @Mock + public JSONObject fromObject(Object object) { + JSONObject json = new JSONObject(); + return json; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.ERROR_STATUS_CODE); + + paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + paramsMap.put("methodType", "get"); + adapterResManager = new AdapterResourceManager(); +// jsonObj = adapterResManager.getVnfdInfo("1111"); +// assertTrue(jsonObj != null); + } + + @Test + public void getVnfdInfoTest2() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse get(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(504); + return rsp; + } + }; + + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + resultObj.put("reason", "RestfulResponse is null."); + resultObj.put("retCode", Constant.ERROR_STATUS_CODE); + + paramsMap.put("url", "/openoapi/extsys/v1/vnfms/11111"); + paramsMap.put("methodType", "get"); + adapterResManager = new AdapterResourceManager(); +// jsonObj = adapterResManager.getVnfdInfo("1111"); +// assertTrue(jsonObj != null); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2MSBManagerTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2MSBManagerTest.java new file mode 100644 index 0000000..5814a18 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuAdapter2MSBManagerTest.java @@ -0,0 +1,267 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.impl; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.HttpRest; +import org.openo.baseservice.roa.util.restclient.RestfulParametes; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.JujuVnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class JujuAdapter2MSBManagerTest { + + private JujuAdapter2MSBManager adapter2MSBManager; + + private JSONObject jsonObj; + + @Test + public void registerJujuAdapterTest() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(200); + return rsp; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.registerJujuAdapter(paramsMap, resultObj); + assertTrue(resp != null); + } + + @Test + public void registerJujuAdapterTest2() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(500); + return rsp; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.registerJujuAdapter(paramsMap, resultObj); + assertTrue(resp != null); + } + + @Test + public void registerJujuAdapterTest3() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(415); + return rsp; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.registerJujuAdapter(paramsMap, resultObj); + assertTrue(resp != null); + } + + @Test + public void registerJujuAdapterTest4() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(201); + return rsp; + } + }; + new MockUp<JSONObject>() { + @Mock + public JSONObject fromObject(Object object) { + JSONObject json = new JSONObject(); + return json; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.registerJujuAdapter(paramsMap, resultObj); + assertTrue(resp != null); + } + + @Test + public void registerJujuAdapterTest1() { + Map<String, String> paramsMap = new HashMap<>(); + JSONObject resultObj = new JSONObject(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.registerJujuAdapter(null, resultObj); + assertTrue(resp.get("reason").equals("RestfulResponse is null.")); + } + + @Test + public void unregisterJujuAdapterTest() { + Map<String, String> paramsMap = new HashMap<>(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.unregisterJujuAdapter(paramsMap); + assertTrue(resp.get("reason").equals("RestfulResponse is null.")); + } + + @Test + public void unregisterJujuAdapterTest1() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(204); + return rsp; + } + }; + new MockUp<JSONObject>() { + @Mock + public JSONObject fromObject(Object object) { + JSONObject json = new JSONObject(); + return json; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.unregisterJujuAdapter(paramsMap); + assertTrue(resp != null); + } + + @Test + public void unregisterJujuAdapterTest2() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(404); + return rsp; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.unregisterJujuAdapter(paramsMap); + assertTrue(resp != null); + } + + @Test + public void unregisterJujuAdapterTest3() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(415); + return rsp; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.unregisterJujuAdapter(paramsMap); + assertTrue(resp != null); + } + + @Test + public void unregisterJujuAdapterTest4() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(500); + return rsp; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.unregisterJujuAdapter(paramsMap); + assertTrue(resp != null); + } + + @Test + public void unregisterJujuAdapterTest5() { + new MockUp<HttpRest>() { + @Mock + RestfulResponse post(String arg0, RestfulParametes arg1) throws ServiceException { + RestfulResponse rsp = new RestfulResponse(); + rsp.setStatus(200); + return rsp; + } + }; + Map<String, String> paramsMap = new HashMap<>(); + + paramsMap.put("url", "/openoapi/microservices/v1/services"); + paramsMap.put("methodType", "post"); + + JujuAdapter2MSBManager mgr = new JujuAdapter2MSBManager(); + JSONObject resp = mgr.unregisterJujuAdapter(paramsMap); + assertTrue(resp != null); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuClientManagerTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuClientManagerTest.java new file mode 100644 index 0000000..8fc108c --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/JujuClientManagerTest.java @@ -0,0 +1,126 @@ +/* + * 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. + */ +package org.openo.nfvo.jujuvnfmadapter.service.adapter.impl; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.junit.Ignore; +import org.junit.Test; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class JujuClientManagerTest { + + @Test + public void testdeploy() { + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.deploy("charmPath", "appName"); + assertTrue(json != null); + } + + @Test + public void testdeploy3() { + new MockUp<ProcessBuilder>() { + @Mock + public Process start() throws IOException { + Process process = new ProcessMockImpl(); + return process; + } + }; + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.deploy("charmPath","appName"); + assertTrue(json != null); + } + + @Test + public void testdeploy1() { + + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.deploy("charmPath", null); + assertTrue(json != null); + } + + @Test + public void testdeploy2() { + + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.deploy(null, null); + assertTrue(json != null); + } + + @Test +@Ignore + public void testdestroy() { + + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.destroy("appName"); + assertTrue(json != null); + } + + @Test + public void testdestroy1() { + new MockUp<ProcessBuilder>() { + @Mock + public Process start() throws IOException { + Process process = new ProcessMockImpl(); + return process; + } + }; + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.destroy("appName"); + assertTrue(json != null); + } + + @Test + public void testgetStatus() { + + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.getStatus("appName"); + assertTrue(json != null); + } + + @Test + public void testgetStatus1() { + + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.getStatus(""); + assertTrue(json != null); + } + + @Test + public void testgetStatus2() { + new MockUp<ProcessBuilder>() { + @Mock + public Process start() throws IOException { + Process process = new ProcessMockImpl(); + return process; + } + }; + + JujuClientManager jujuClientManager = new JujuClientManager(); + JSONObject json = jujuClientManager.getStatus(""); + assertTrue(json != null); + } + @Test + public void testParseYaml(){ + JujuClientManager jujuClientManager = new JujuClientManager(); + jujuClientManager.parseYaml("abc/efg", "mediawiki.yaml", "addResource"); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/ProcessMockImpl.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/ProcessMockImpl.java new file mode 100644 index 0000000..da75931 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/adapter/impl/ProcessMockImpl.java @@ -0,0 +1,76 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.adapter.impl; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.ObjectOutputStream; +import java.io.OutputStream; + +public class ProcessMockImpl extends Process { + + @Override + public OutputStream getOutputStream() { + // TODO Auto-generated method stub + return null; + } + + @Override + public InputStream getInputStream() { + // TODO Auto-generated method stub + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + ObjectOutputStream oos; + /*try { + oos = new ObjectOutputStream(baos); + oos.writeObject(new Object()); + oos.flush(); + oos.close(); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + }*/ + + InputStream is = new ByteArrayInputStream(baos.toByteArray()); + return is; + } + + @Override + public InputStream getErrorStream() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int waitFor() throws InterruptedException { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int exitValue() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public void destroy() { + // TODO Auto-generated method stub + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrServiceTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrServiceTest.java new file mode 100644 index 0000000..e2ef790 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/api/internalsvc/impl/JujuAdapterMgrServiceTest.java @@ -0,0 +1,28 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.api.internalsvc.impl; + +import org.junit.Test; + +public class JujuAdapterMgrServiceTest { + + @Test + public void registerTest(){ + JujuAdapterMgrService service = new JujuAdapterMgrService(); + service.register(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ConstantTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ConstantTest.java new file mode 100644 index 0000000..dff3c2b --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ConstantTest.java @@ -0,0 +1,42 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.constant; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant.AuthenticationMode; + +public class ConstantTest { + + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = Constant.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + @Test + public void testPrivateConstructor1() throws Exception { + Constructor constructor = Constant.AuthenticationMode.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ParamConstantsTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ParamConstantsTest.java new file mode 100644 index 0000000..2ef3dea --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/ParamConstantsTest.java @@ -0,0 +1,35 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.constant; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +public class ParamConstantsTest { + + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = ParamConstants.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/UrlConstantTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/UrlConstantTest.java new file mode 100644 index 0000000..4e6b1ac --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/constant/UrlConstantTest.java @@ -0,0 +1,34 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.constant; + +import static org.junit.Assert.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Modifier; + +import org.junit.Test; + +public class UrlConstantTest { + + @Test + public void testPrivateConstructor() throws Exception { + Constructor constructor = UrlConstant.class.getDeclaredConstructor(); + assertTrue("Constructor private", Modifier.isPrivate(constructor.getModifiers())); + constructor.setAccessible(true); + constructor.newInstance(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuDriverTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuDriverTest.java new file mode 100644 index 0000000..cfef8bf --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuDriverTest.java @@ -0,0 +1,309 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.CryptUtil; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuDriver; +import org.openo.nfvo.jujuvnfmadapter.service.entity.VnfmOpResult; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONArray; +import net.sf.json.JSONObject; + +public class JujuDriverTest { + + @Test + public void testGetServiceName() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getServiceName(); + assertNull(result); + } + + @Test + public void testSetServiceName() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setServiceName("testServiceName"); + String result = jujudriver.getServiceName(); + assertEquals("testServiceName", result); + } + + @Test + public void testGetProtocol() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getProtocol(); + assertNull(result); + } + + @Test + public void testSetProtocol() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setProtocol("protocol"); + String result = jujudriver.getProtocol(); + assertEquals("protocol", result); + } + + @Test + public void testGetVisualRange() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getVisualRange(); + assertNull(result); + } + + @Test + public void testSetVisualRange() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setVisualRange("getVisualRange"); + String result = jujudriver.getVisualRange(); + assertEquals("getVisualRange", result); + } + + @Test + public void testGetVersion() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getVersion(); + assertNull(result); + } + + @Test + public void testSetVersion() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setVersion("testVersion"); + String result = jujudriver.getVersion(); + assertEquals("testVersion", result); + } + + @Test + public void testGetUrl() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getUrl(); + assertNull(result); + } + + @Test + public void testSetUrl() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setUrl("testUrl"); + String result = jujudriver.getUrl(); + assertEquals("testUrl", result); + } + + @Test + public void testGetIP() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getIP(); + assertNull(result); + } + + @Test + public void testSetIP() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setIP("testIP"); + String result = jujudriver.getIP(); + assertEquals("testIP", result); + } + + + @Test + public void testGetPort() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getPort(); + assertNull(result); + } + + @Test + public void testSetPort() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setPort("testPort"); + String result = jujudriver.getPort(); + assertEquals("testPort", result); + } + + @Test + public void testGetTtl() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getTtl(); + assertNull(result); + } + + @Test + public void testSetTtl() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setTtl("testTtl"); + String result = jujudriver.getTtl(); + assertEquals("testTtl", result); + } + + @Test + public void testGetStatus() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.getStatus(); + assertNull(result); + } + + @Test + public void testSetStatus() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setStatus("testStatus"); + String result = jujudriver.getStatus(); + assertEquals("testStatus", result); + } + + + @Test + public void testToString() { + JujuDriver jujudriver = new JujuDriver(); + String result = jujudriver.toString(); + assertEquals( + "JujuDriver[serviceName=<null>,protocol=<null>,version=<null>,visualRange=<null>,url=<null>,nodes=<null>,ip=<null>,port=<null>,ttl=<null>,status=<null>]", + result); + } + + @Test + public void testToString1() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setServiceName("serviceName"); + jujudriver.setProtocol("protocol"); + jujudriver.setVersion("version"); + jujudriver.setVisualRange("visualRange"); + jujudriver.setUrl("testUrl"); + jujudriver.setIP("testIP"); + jujudriver.setPort("testPort"); + jujudriver.setTtl("testTtl"); + jujudriver.setStatus("testStatus"); + String result = jujudriver.toString(); + assertEquals( + "JujuDriver[serviceName=serviceName,protocol=protocol,version=version,visualRange=visualRange,url=testUrl,nodes=<null>,ip=testIP,port=testPort,ttl=testTtl,status=testStatus]", + result); + } + + @Test + public void testHashCode() { + JujuDriver jujudriver = new JujuDriver(); + int result = jujudriver.hashCode(); + assertEquals(31, result); + } + + @Test + public void testHashCode1() { + JujuDriver jujudriver = new JujuDriver(); + jujudriver.setServiceName("serviceName"); + int result = jujudriver.hashCode(); + assertEquals(-1928572161, result); + } + + @Test + public void testEquals() { + boolean result = new JujuDriver().equals(new JujuDriver()); + assertTrue(result); + } + + @Test + public void testEquals1() { + boolean result = new JujuDriver().equals(""); + assertFalse(result); + } + + @Test + public void testEquals2() { + JujuVnfd obj = new JujuVnfd(); + boolean result = new JujuDriver().equals(obj); + assertFalse(result); + } + + @Test + public void testEquals3() { + JujuDriver obj = new JujuDriver(); + obj.setServiceName("serviceName"); + boolean result = new JujuDriver().equals(obj); + assertFalse(result); + } + + @Test + public void testEquals4() { + JujuDriver obj = new JujuDriver(); + boolean result = obj.equals(obj); + assertTrue(result); + } + + @Test + public void testEquals5() { + boolean result = new JujuDriver().equals(null); + assertFalse(result); + } + + @Test + public void testEquals6() { + JujuDriver jujudriver = new JujuDriver(); + JujuDriver jujudriver2 = new JujuDriver(); + jujudriver.setPort(""); + jujudriver2.setPort(""); + boolean result = jujudriver.equals(jujudriver2); + assertTrue(result); + } + + @Test + public void testEquals7() { + JujuDriver jujudriver = new JujuDriver(); + JujuDriver jujudriver2 = new JujuDriver(); + jujudriver.setServiceName("serviceName"); + jujudriver2.setServiceName("serName"); + boolean result = jujudriver.equals(jujudriver2); + assertFalse(result); + } + @Test + public void JujuDriverConsTest(){ + JSONObject jujuJsonObject = new JSONObject(); + JSONArray array= new JSONArray(); + array.add("1.1.1.1"); + array.add("8080"); + array.add("ttl"); + jujuJsonObject.put("serviceName", "test123"); + jujuJsonObject.put("protocol", "http"); + jujuJsonObject.put("version", "v1"); + jujuJsonObject.put("visualRange", "10"); + jujuJsonObject.put("url", "/test"); + jujuJsonObject.put("nodes", "[]"); + jujuJsonObject.put("notes", array); + jujuJsonObject.put("status", "active"); + JujuDriver driver = new JujuDriver(jujuJsonObject); + assertTrue("test123".equals(driver.getServiceName())); + } + @Test + public void testsetNodes() { + JujuDriver jujudriver = new JujuDriver(); + List<String> nodes = new ArrayList<String>(); + nodes.add("nodes"); + jujudriver.setNodes(nodes); + } + @Test + public void testgetNodes() { + JujuDriver jujudriver = new JujuDriver(); + List<String> nodes = new ArrayList<String>(); + nodes.add("nodes"); + jujudriver.getNodes(); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfdTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfdTest.java new file mode 100644 index 0000000..b01e6c5 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfdTest.java @@ -0,0 +1,154 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +public class JujuVnfdTest { + + @Test + public void testGetDownloadUri() { + JujuVnfd jujuvnfd = new JujuVnfd(); + String result = jujuvnfd.getDownloadUri(); + assertNull(result); + } + + @Test + public void testSetDownloadUri() { + JujuVnfd jujuvnfd = new JujuVnfd(); + jujuvnfd.setDownloadUri("testDownloadUri"); + String result = jujuvnfd.getDownloadUri(); + assertEquals("testDownloadUri", result); + } + + @Test + public void testGetLocalPath() { + JujuVnfd jujuvnfd = new JujuVnfd(); + String result = jujuvnfd.getLocalPath(); + assertNull(result); + } + + @Test + public void testSetProtocol() { + JujuVnfd jujuvnfd = new JujuVnfd(); + jujuvnfd.setLocalPath("testLocalPath"); + String result = jujuvnfd.getLocalPath(); + assertEquals("testLocalPath", result); + } + + + @Test + public void testToString() { + JujuVnfd jujuvnfd = new JujuVnfd(); + String result = jujuvnfd.toString(); + assertEquals( + "JujuVnfd[downloadUri=<null>,localPath=<null>]", + result); + } + + @Test + public void testToString1() { + JujuVnfd jujuvnfd = new JujuVnfd(); + jujuvnfd.setDownloadUri("testDownloadUri"); + jujuvnfd.setLocalPath("testLocalPath"); + String result = jujuvnfd.toString(); + assertEquals( + "JujuVnfd[downloadUri=testDownloadUri,localPath=testLocalPath]", + result); + } + + @Test + public void testHashCode() { + JujuVnfd jujuvnfd = new JujuVnfd(); + int result = jujuvnfd.hashCode(); + assertEquals(31, result); + } + + @Test + public void testHashCode1() { + JujuVnfd jujuvnfd = new JujuVnfd(); + jujuvnfd.setDownloadUri("testDownloadUri"); + int result = jujuvnfd.hashCode(); + assertEquals(-1870623759, result); + } + + @Test + public void testEquals() { + boolean result = new JujuVnfd().equals(new JujuVnfd()); + assertTrue(result); + } + + @Test + public void testEquals1() { + boolean result = new JujuVnfd().equals(""); + assertFalse(result); + } + + @Test + public void testEquals2() { + JujuDriver obj = new JujuDriver(); + boolean result = new JujuVnfd().equals(obj); + assertFalse(result); + } + + @Test + public void testEquals3() { + JujuVnfd obj = new JujuVnfd(); + obj.setDownloadUri("testDownloadUri"); + boolean result = new JujuVnfd().equals(obj); + assertFalse(result); + } + + @Test + public void testEquals4() { + JujuVnfd obj = new JujuVnfd(); + boolean result = obj.equals(obj); + assertTrue(result); + } + + @Test + public void testEquals5() { + boolean result = new JujuVnfd().equals(null); + assertFalse(result); + } + + @Test + public void testEquals6() { + JujuVnfd jujuvnfd = new JujuVnfd(); + JujuVnfd jujudriver2 = new JujuVnfd(); + jujuvnfd.setDownloadUri(""); + jujudriver2.setDownloadUri(""); + boolean result = jujuvnfd.equals(jujudriver2); + assertTrue(result); + } + + @Test + public void testEquals7() { + JujuVnfd jujuvnfd = new JujuVnfd(); + JujuVnfd jujudriver2 = new JujuVnfd(); + jujuvnfd.setDownloadUri("testDownloadUri"); + jujudriver2.setDownloadUri("DownloadUri"); + boolean result = jujuvnfd.equals(jujudriver2); + assertFalse(result); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoExampleTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoExampleTest.java new file mode 100644 index 0000000..bf5f464 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoExampleTest.java @@ -0,0 +1,165 @@ +/* + * 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. + */ +package org.openo.nfvo.jujuvnfmadapter.service.entity; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample.Criteria; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample.Criterion; + +public class JujuVnfmInfoExampleTest { + + JujuVnfmInfoExample jujuexample = new JujuVnfmInfoExample(); + protected List<Criterion> criteria; + @Test + public void createCriteriaTest(){ + Criteria criteria = jujuexample.createCriteria(); + String condition = ""; + String value = ""; + String property = ""; + String value1 = ""; + String value2 = ""; + Date d1 =new Date(); + Date d2 =new Date(); + List<String> values = new ArrayList<String>(); + criteria.addCriterion(condition); + criteria.addCriterion(condition, value, property); + criteria.addCriterion(condition, value1, value2, property); + criteria.andDeleteTimeBetween(d1, d2); + criteria.andAppNameBetween(value1, value2); + criteria.andAppNameEqualTo(value); + criteria.andAppNameGreaterThan(value); + criteria.andAppNameGreaterThanOrEqualTo(value); + criteria.andAppNameIn(values); + criteria.andAppNameLessThan(value); + criteria.andIdLessThanOrEqualTo(value); + criteria.andAppNameLike(value2); + criteria.andAppNameNotBetween(value1, value2); + criteria.andAppNameNotEqualTo(value2); + criteria.andAppNameNotIn(values); + criteria.andIdNotLike(value2); + criteria.andCreateTimeBetween(d1, d2); + criteria.andCreateTimeNotBetween(d1, d2); + criteria.andJobIdBetween(value1, value2); + criteria.andJobIdNotBetween(value1, value2); + criteria.andModifyTimeBetween(d1, d2); + criteria.andJobIdEqualTo(value2); + criteria.andJobIdGreaterThan(value2); + criteria.andJobIdGreaterThanOrEqualTo(value2); + criteria.andJobIdIn(values); + criteria.andJobIdLessThan(value2); + criteria.andJobIdLessThanOrEqualTo(value2); + criteria.andJobIdLike(value2); + criteria.andJobIdNotBetween(value1, value2); + criteria.andJobIdNotEqualTo(value2); + criteria.andJobIdNotIn(values); + criteria.andJobIdNotLike(value2); + assertNotNull(criteria); + } + @Test + public void orTest(){ + Criteria criteria = jujuexample.or(); + assertNotNull(criteria); + } + @Test + public void clearTest(){ + jujuexample.clear(); + assertTrue(true); + } + @Test + public void CriteriaTest(){ + JujuVnfmInfoExample.Criteria criteria = new JujuVnfmInfoExample.Criteria(); + boolean isValid = criteria.isValid(); + assertTrue(!isValid); + } + + @Test + public void CriterionTest(){ + String condition=""; + String value=""; + String secondValue=""; + String typeHandler=""; + + Criterion c = new Criterion(condition, value, secondValue, typeHandler); + assertEquals(c.getCondition(), ""); + assertEquals(c.getValue(), ""); + assertEquals(c.getSecondValue(), ""); + assertEquals(c.getTypeHandler(), ""); + assertEquals(c.isSingleValue(), false); + assertEquals(c.isBetweenValue(), true); + assertEquals(c.isListValue(), false); + + } + + @Test + public void generatedCriteriaTest(){ + JujuVnfmInfoExample.Criteria criteria = new JujuVnfmInfoExample.Criteria(); + boolean isValid = criteria.isValid(); + + assertTrue(!isValid); + } + + @Test + public void andIdIsNullTest(){ + JujuVnfmInfoExample.Criteria criteria = new JujuVnfmInfoExample.Criteria(); + Criteria c= criteria.andIdIsNull(); + assertNotNull(c); + } + @Test + public void getConditionCroterionTest(){ + JujuVnfmInfoExample.Criterion criterion = new JujuVnfmInfoExample.Criterion("test",new Object(),"typeHandler"); + String condition = criterion.getCondition(); + assertEquals(condition,"test"); + } + @Test + public void testLimitStart() { + JujuVnfmInfoExample jujuVnfmInfoExample=new JujuVnfmInfoExample(); + jujuVnfmInfoExample.setLimitStart(-1); + + int result = jujuVnfmInfoExample.getLimitStart(); + assertEquals(-1, result); + } + @Test + public void testLimitEnd() { + JujuVnfmInfoExample jujuVnfmInfoExample=new JujuVnfmInfoExample(); + jujuVnfmInfoExample.setLimitEnd(-1); + + int result = jujuVnfmInfoExample.getLimitEnd(); + assertEquals(-1, result); + } + @Test + public void testOrderByClause() { + JujuVnfmInfoExample jujuVnfmInfoExample=new JujuVnfmInfoExample(); + jujuVnfmInfoExample.setOrderByClause("order"); + + String result = jujuVnfmInfoExample.getOrderByClause(); + assertEquals("order", result); + } + @Test + public void testsetDistinct() { + JujuVnfmInfoExample jujuVnfmInfoExample=new JujuVnfmInfoExample(); + jujuVnfmInfoExample.setDistinct(true); + + boolean result=jujuVnfmInfoExample.isDistinct(); + assertEquals(true,result); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoTest.java new file mode 100644 index 0000000..6707a3d --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmInfoTest.java @@ -0,0 +1,182 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; + +import java.util.Date; + +public class JujuVnfmInfoTest { + + @Test + public void testSetId() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setId("testSetId"); + String result = jujuVnfmInfo.getId(); + assertEquals("testSetId", result); + } + + @Test + public void testGetId() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + String result = jujuVnfmInfo.getId(); + assertNull(result); + } + + @Test + public void testSetVnfmId() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setVnfmId("testSetVnfmId"); + String result = jujuVnfmInfo.getVnfmId(); + assertEquals("testSetVnfmId", result); + } + + @Test + public void testGetVnfmId() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + String result = jujuVnfmInfo.getVnfmId(); + assertNull(result); + } + + @Test + public void testSetVnfId() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setVnfId("testSetVnfId"); + String result = jujuVnfmInfo.getVnfId(); + assertEquals("testSetVnfId", result); + } + + @Test + public void testGetVnfId() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + String result = jujuVnfmInfo.getVnfId(); + assertNull(result); + } + + @Test + public void testSetAppName() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setAppName("testSetAppName"); + String result = jujuVnfmInfo.getAppName(); + assertEquals("testSetAppName", result); + } + + @Test + public void testGetAppName() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + String result = jujuVnfmInfo.getAppName(); + assertNull(result); + } + + @Test + public void testSetJobId() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setJobId("testSetJobId"); + String result = jujuVnfmInfo.getJobId(); + assertEquals("testSetJobId", result); + } + + @Test + public void testGetJobId() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + String result = jujuVnfmInfo.getJobId(); + assertNull(result); + } + + @Test + public void testSetStatus() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setStatus(0); + Integer result = jujuVnfmInfo.getStatus(); + assertEquals(Integer.valueOf(0), result); + } + + @Test + public void testGetStatus() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + Integer result = jujuVnfmInfo.getStatus(); + assertNull(result); + } + + @Test + public void testSetCreateTime() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setCreateTime(new Date()); + Date result = jujuVnfmInfo.getCreateTime(); + assertEquals(new Date(), result); + } + + @Test + public void testGetCreateTime() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + Date result = jujuVnfmInfo.getCreateTime(); + assertNull(result); + } + + @Test + public void testSetModifyTime() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setModifyTime(new Date()); + Date result = jujuVnfmInfo.getModifyTime(); + assertEquals(new Date(), result); + } + + @Test + public void testGetModifyTime() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + Date result = jujuVnfmInfo.getModifyTime(); + assertNull(result); + } + + @Test + public void testSetDeleteTime() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setDeleteTime(new Date()); + Date result = jujuVnfmInfo.getDeleteTime(); + assertEquals(new Date(), result); + } + + @Test + public void testGetDeleteTime() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + Date result = jujuVnfmInfo.getDeleteTime(); + assertNull(result); + } + + @Test + public void testSetExtend() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + jujuVnfmInfo.setExtend("testSetExtend"); + String result = jujuVnfmInfo.getExtend(); + assertEquals("testSetExtend", result); + } + + @Test + public void testGetExtend() { + JujuVnfmInfo jujuVnfmInfo = new JujuVnfmInfo(); + String result = jujuVnfmInfo.getExtend(); + assertNull(result); + } + + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmTest.java new file mode 100644 index 0000000..744aeef --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/JujuVnfmTest.java @@ -0,0 +1,347 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.CryptUtil; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfm; +import org.openo.nfvo.jujuvnfmadapter.service.entity.VnfmOpResult; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class JujuVnfmTest { + + @Test + public void testGetId() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getId(); + assertNull(result); + } + + @Test + public void testSetId() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setId("testId"); + String result = jujuvnfm.getId(); + assertEquals("testId", result); + } + + @Test + public void testGetType() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getType(); + assertNull(result); + } + + @Test + public void testSetType() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setType("testType"); + String result = jujuvnfm.getType(); + assertEquals("testType", result); + } + + @Test + public void testGetName() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getName(); + assertNull(result); + } + + @Test + public void testSetName() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setName("testName"); + String result = jujuvnfm.getName(); + assertEquals("testName", result); + } + + @Test + public void testGetVersion() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getVersion(); + assertNull(result); + } + + @Test + public void testSetVersion() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setVersion("testVersion"); + String result = jujuvnfm.getVersion(); + assertEquals("testVersion", result); + } + + @Test + public void testGetUserName() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getUserName(); + assertNull(result); + } + + @Test + public void testSetUserName() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setUserName("testUserName"); + String result = jujuvnfm.getUserName(); + assertEquals("testUserName", result); + } + + @Test + public void testGetUrl() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getUrl(); + assertNull(result); + } + + @Test + public void testSetUrl() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setUrl("testUrl"); + String result = jujuvnfm.getUrl(); + assertEquals("testUrl", result); + } + + @Test + public void testGetPwd() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getPwd(); + assertNull(result); + } + + @Test + public void testSetPwd() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setPwd("testPwd"); + String result = jujuvnfm.getPwd(); + assertEquals("testPwd", result); + } + + @Test + public void testGetVender() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getVendor(); + assertNull(result); + } + + @Test + public void testSetVender() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setVendor("testVendor"); + String result = jujuvnfm.getVendor(); + assertEquals("testVendor", result); + } + + @Test + public void testGetExtraInfo() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getExtraInfo(); + assertNull(result); + } + + @Test + public void testSetExtraInfo() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setExtraInfo("testExtraInfo"); + String result = jujuvnfm.getExtraInfo(); + assertEquals("testExtraInfo", result); + } + + @Test + public void testGetStatus() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getStatus(); + assertNull(result); + } + + @Test + public void testSetStatus() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setStatus("testStatus"); + String result = jujuvnfm.getStatus(); + assertEquals("testStatus", result); + } + + @Test + public void testGetCreateAt() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getCreateAt(); + assertNull(result); + } + + @Test + public void testSetCreateAt() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setCreateAt("testCreateAt"); + String result = jujuvnfm.getCreateAt(); + assertEquals("testCreateAt", result); + } + + @Test + public void testGetUpdateAt() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.getUpdateAt(); + assertNull(result); + } + + @Test + public void testSetUpdateAt() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setUpdateAt("testUpdateAt"); + String result = jujuvnfm.getUpdateAt(); + assertEquals("testUpdateAt", result); + } + + @Test + public void testToString() { + JujuVnfm jujuvnfm = new JujuVnfm(); + String result = jujuvnfm.toString(); + assertEquals( + "JujuVnfm[id=<null>,name=<null>,type=<null>,version=<null>,userName=<null>,pwd=<null>,url=<null>,vendor=<null>,extraInfo=<null>,status=<null>,createAt=<null>,updateAt=<null>]", + result); + } + + @Test + public void testToString1() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setId("testId"); + jujuvnfm.setType("testType"); + jujuvnfm.setName("testName"); + jujuvnfm.setVersion("testVersion"); + jujuvnfm.setUserName("testUserName"); + jujuvnfm.setUrl("testUrl"); + jujuvnfm.setPwd("testPwd"); + jujuvnfm.setVendor("testVendor"); + jujuvnfm.setExtraInfo("testExtraInfo"); + jujuvnfm.setStatus("testStatus"); + jujuvnfm.setCreateAt("testCreateAt"); + jujuvnfm.setUpdateAt("testUpdateAt"); + String result = jujuvnfm.toString(); + assertEquals( + "JujuVnfm[id=testId,name=testName,type=testType,version=testVersion,userName=testUserName,pwd=testPwd,url=testUrl,vendor=testVendor,extraInfo=testExtraInfo,status=testStatus,createAt=testCreateAt,updateAt=testUpdateAt]", + result); + } + + @Test + public void testHashCode() { + JujuVnfm jujuvnfm = new JujuVnfm(); + int result = jujuvnfm.hashCode(); + assertEquals(31, result); + } + + @Test + public void testHashCode1() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setId("testId"); + int result = jujuvnfm.hashCode(); + assertEquals(-877170324, result); + } + + @Test + public void testEquals() { + boolean result = new JujuVnfm().equals(new JujuVnfm()); + assertTrue(result); + } + + @Test + public void testEquals1() { + boolean result = new JujuVnfm().equals(""); + assertFalse(result); + } + + @Test + public void testEquals2() { + JujuVnfm jujuvnfm = new JujuVnfm(); + jujuvnfm.setId("testId"); + VnfmOpResult obj = new VnfmOpResult(); + boolean result = new JujuVnfm().equals(obj); + assertFalse(result); + } + + @Test + public void testEquals3() { + JujuVnfm obj = new JujuVnfm(); + obj.setId("testId"); + boolean result = new JujuVnfm().equals(obj); + assertFalse(result); + } + + @Test + public void testEquals4() { + JujuVnfm obj = new JujuVnfm(); + boolean result = obj.equals(obj); + assertTrue(result); + } + + @Test + public void testEquals5() { + boolean result = new JujuVnfm().equals(null); + assertFalse(result); + } + + @Test + public void testEquals6() { + JujuVnfm jujuvnfm = new JujuVnfm(); + JujuVnfm vnfm2 = new JujuVnfm(); + jujuvnfm.setId(""); + vnfm2.setId(""); + boolean result = jujuvnfm.equals(vnfm2); + assertTrue(result); + } + + @Test + public void testEquals7() { + JujuVnfm jujuvnfm = new JujuVnfm(); + JujuVnfm vnfm2 = new JujuVnfm(); + jujuvnfm.setId("vnfmId"); + vnfm2.setId("vnfm2Id"); + boolean result = jujuvnfm.equals(vnfm2); + assertFalse(result); + } + + @Test + public void testUpdateVnfm() { + JujuVnfm jujuvnfm = new JujuVnfm(); + JSONObject obj = new JSONObject(); + obj.put("name", "name"); + obj.put("userName", "userName"); + obj.put("pwd", "pwd"); + obj.put("extraInfo", "extraInfo"); + jujuvnfm.updateVnfm(obj); + assertEquals("name", jujuvnfm.getName()); + assertEquals("userName", jujuvnfm.getUserName()); + } + + @Test + public void testUpdateVnfmByEmpty() { + JujuVnfm jujuvnfm = new JujuVnfm(); + JSONObject obj = new JSONObject(); + obj.put("name", ""); + obj.put("userName", ""); + obj.put("pwd", ""); + obj.put("extraInfo", ""); + jujuvnfm.updateVnfm(obj); + assertNull(jujuvnfm.getName()); + assertNull(jujuvnfm.getUserName()); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/MSBRequestEntityTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/MSBRequestEntityTest.java new file mode 100644 index 0000000..2f3ec92 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/MSBRequestEntityTest.java @@ -0,0 +1,79 @@ +/* + * 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. + */ +package org.openo.nfvo.jujuvnfmadapter.service.entity; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.service.entity.MSBRequestEntity.Node; + +public class MSBRequestEntityTest { + MSBRequestEntity msbRequestEntity = new MSBRequestEntity(); + + @Test + public void testMSBRequestEntity() { + List<Node> nodes = new ArrayList<>(); + msbRequestEntity.setNodes(nodes); + String protocol = "protocol"; + msbRequestEntity.setProtocol(protocol); + String serviceName = "serviceName"; + msbRequestEntity.setServiceName(serviceName); + String status = "status"; + msbRequestEntity.setStatus(status); + String url = "url"; + msbRequestEntity.setUrl(url); + String version = "version"; + msbRequestEntity.setVersion(version); + String visualRange = " visualRange"; + msbRequestEntity.setVisualRange(visualRange); + msbRequestEntity.toString(); + assertEquals(msbRequestEntity.getNodes(), nodes);; + assertEquals(msbRequestEntity.getNodes(), nodes); + assertEquals(msbRequestEntity.getProtocol(), protocol); + assertEquals(msbRequestEntity.getServiceName(), serviceName); + assertEquals(msbRequestEntity.getStatus(), status); + assertEquals(msbRequestEntity.getUrl(), url); + assertEquals(msbRequestEntity.getVersion(), version); + assertEquals(msbRequestEntity.getVisualRange(), visualRange); + } + + @Test + public void testNode() { + Node n = new Node(); + String createdAt = "Test"; + n.setCreatedAt(createdAt); + String ip = "192.168.4.47"; + n.setIp(ip); + String expiration = ""; + n.setExpiration(expiration); + String port = "80"; + n.setPort(port); + String updatedAt = ""; + n.setUpdatedAt(updatedAt); + String ttl = ""; + n.setTtl(ttl); + + assertEquals(n.getCreatedAt(), "Test"); + assertEquals(n.getIp(), "192.168.4.47"); + assertEquals(n.getExpiration(), ""); + assertEquals(n.getPort(),"80"); + assertEquals(n.getUpdatedAt(), ""); + assertEquals(n.getTtl(), ""); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmOpResultTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmOpResultTest.java new file mode 100644 index 0000000..5089682 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmOpResultTest.java @@ -0,0 +1,129 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.service.entity.VnfmOpResult; +import org.openo.nfvo.jujuvnfmadapter.service.entity.VnfmOpResult.TaskStatus; + +public class VnfmOpResultTest { + + @Test + public void testVnfmOpResult() { + VnfmOpResult result = new VnfmOpResult(); + assertEquals(TaskStatus.INIT, result.getOperateStatus()); + assertEquals("", result.getErrorMessage()); + } + + @Test + public void testVnfmOpResult1() { + VnfmOpResult result = new VnfmOpResult(TaskStatus.SUCCESS, "success"); + assertEquals(TaskStatus.SUCCESS, result.getOperateStatus()); + assertEquals("success", result.getErrorMessage()); + } + + @Test + public void testSotOperateStatus() { + VnfmOpResult result = new VnfmOpResult(); + result.setOperateStatus(TaskStatus.SUCCESS); + assertEquals(TaskStatus.SUCCESS, result.getOperateStatus()); + } + + @Test + public void testSotOperateStatusByNull() { + VnfmOpResult result = new VnfmOpResult(); + result.setOperateStatus(null); + assertNull(result.getOperateStatus()); + } + + @Test + public void testSotErrorMessage() { + VnfmOpResult result = new VnfmOpResult(); + result.setErrorMessage("Fail!"); + assertEquals("Fail!", result.getErrorMessage()); + } + + @Test + public void testSotErrorMessageByNull() { + VnfmOpResult result = new VnfmOpResult(); + result.setErrorMessage(null); + assertNull(result.getErrorMessage()); + } + + @Test + public void testAddResult() { + VnfmOpResult result = new VnfmOpResult(); + result.addResult("Result"); + List<String> arr = new ArrayList<String>(); + arr.add("Result"); + assertEquals(arr, result.getResult()); + } + + @Test + public void testAddResultByList() { + VnfmOpResult result = new VnfmOpResult(); + List<String> arr = new ArrayList<String>(); + arr.add("Result"); + arr.add("Test"); + result.addResult(arr); + assertEquals(arr, result.getResult()); + } + + @Test + public void testAddResultByNull() { + VnfmOpResult result = new VnfmOpResult(); + List<String> arr = new ArrayList<String>(); + arr.add(null); + result.addResult(null); + assertEquals(arr, result.getResult()); + } + + @Test + public void testToString() { + VnfmOpResult result = new VnfmOpResult(); + assertEquals( + "org.openo.nfvo.jujuvnfmadapter.service.entity.VnfmOpResult@[operateStatus=INIT, errorCode=0, errorMessage=]", + result.toString()); + } + + @Test + public void testToString1() { + VnfmOpResult result = new VnfmOpResult(TaskStatus.SUCCESS, "success"); + assertEquals( + "org.openo.nfvo.jujuvnfmadapter.service.entity.VnfmOpResult@[operateStatus=SUCCESS, errorCode=0, errorMessage=success]", + result.toString()); + } + + @Test + public void testTaskStatus() { + VnfmOpResult result=new VnfmOpResult(); + assertEquals(TaskStatus.INIT, TaskStatus.valueOf("INIT")); + assertEquals(TaskStatus.SUCCESS, TaskStatus.valueOf("SUCCESS")); + assertEquals(TaskStatus.PART_SUCCESS, TaskStatus.valueOf("PART_SUCCESS")); + assertEquals(TaskStatus.RUNNING, TaskStatus.valueOf("RUNNING")); + assertEquals(TaskStatus.TIMEOUT, TaskStatus.valueOf("TIMEOUT")); + assertEquals(TaskStatus.FAIL, TaskStatus.valueOf("FAIL")); + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmTest.java new file mode 100644 index 0000000..5eaf230 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/entity/VnfmTest.java @@ -0,0 +1,347 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.entity; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.CryptUtil; +import org.openo.nfvo.jujuvnfmadapter.service.entity.Vnfm; +import org.openo.nfvo.jujuvnfmadapter.service.entity.VnfmOpResult; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class VnfmTest { + + @Test + public void testGetId() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getId(); + assertNull(result); + } + + @Test + public void testSetId() { + Vnfm vnfm = new Vnfm(); + vnfm.setId("testId"); + String result = vnfm.getId(); + assertEquals("testId", result); + } + + @Test + public void testGetType() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getType(); + assertNull(result); + } + + @Test + public void testSetType() { + Vnfm vnfm = new Vnfm(); + vnfm.setType("testType"); + String result = vnfm.getType(); + assertEquals("testType", result); + } + + @Test + public void testGetName() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getName(); + assertNull(result); + } + + @Test + public void testSetName() { + Vnfm vnfm = new Vnfm(); + vnfm.setName("testName"); + String result = vnfm.getName(); + assertEquals("testName", result); + } + + @Test + public void testGetVersion() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getVersion(); + assertNull(result); + } + + @Test + public void testSetVersion() { + Vnfm vnfm = new Vnfm(); + vnfm.setVersion("testVersion"); + String result = vnfm.getVersion(); + assertEquals("testVersion", result); + } + + @Test + public void testGetUserName() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getUserName(); + assertNull(result); + } + + @Test + public void testSetUserName() { + Vnfm vnfm = new Vnfm(); + vnfm.setUserName("testUserName"); + String result = vnfm.getUserName(); + assertEquals("testUserName", result); + } + + @Test + public void testGetUrl() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getUrl(); + assertNull(result); + } + + @Test + public void testSetUrl() { + Vnfm vnfm = new Vnfm(); + vnfm.setUrl("testUrl"); + String result = vnfm.getUrl(); + assertEquals("testUrl", result); + } + + @Test + public void testGetPwd() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getPwd(); + assertNull(result); + } + + @Test + public void testSetPwd() { + Vnfm vnfm = new Vnfm(); + vnfm.setPwd("testPwd"); + String result = vnfm.getPwd(); + assertEquals("testPwd", result); + } + + @Test + public void testGetSites() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getSites(); + assertNull(result); + } + + @Test + public void testSetSites() { + Vnfm vnfm = new Vnfm(); + vnfm.setSites("testSites"); + String result = vnfm.getSites(); + assertEquals("testSites", result); + } + + @Test + public void testGetExtraInfo() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getExtraInfo(); + assertNull(result); + } + + @Test + public void testSetExtraInfo() { + Vnfm vnfm = new Vnfm(); + vnfm.setExtraInfo("testExtraInfo"); + String result = vnfm.getExtraInfo(); + assertEquals("testExtraInfo", result); + } + + @Test + public void testGetStatus() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getStatus(); + assertNull(result); + } + + @Test + public void testSetStatus() { + Vnfm vnfm = new Vnfm(); + vnfm.setStatus("testStatus"); + String result = vnfm.getStatus(); + assertEquals("testStatus", result); + } + + @Test + public void testGetCreateAt() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getCreateAt(); + assertNull(result); + } + + @Test + public void testSetCreateAt() { + Vnfm vnfm = new Vnfm(); + vnfm.setCreateAt("testCreateAt"); + String result = vnfm.getCreateAt(); + assertEquals("testCreateAt", result); + } + + @Test + public void testGetUpdateAt() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.getUpdateAt(); + assertNull(result); + } + + @Test + public void testSetUpdateAt() { + Vnfm vnfm = new Vnfm(); + vnfm.setUpdateAt("testUpdateAt"); + String result = vnfm.getUpdateAt(); + assertEquals("testUpdateAt", result); + } + + @Test + public void testToString() { + Vnfm vnfm = new Vnfm(); + String result = vnfm.toString(); + assertEquals( + "Vnfm[id=<null>,name=<null>,type=<null>,version=<null>,userName=<null>,pwd=<null>,url=<null>,sites=<null>,extraInfo=<null>,status=<null>,createAt=<null>,updateAt=<null>]", + result); + } + + @Test + public void testToString1() { + Vnfm vnfm = new Vnfm(); + vnfm.setId("testId"); + vnfm.setType("testType"); + vnfm.setName("testName"); + vnfm.setVersion("testVersion"); + vnfm.setUserName("testUserName"); + vnfm.setUrl("testUrl"); + vnfm.setPwd("testPwd"); + vnfm.setSites("testSites"); + vnfm.setExtraInfo("testExtraInfo"); + vnfm.setStatus("testStatus"); + vnfm.setCreateAt("testCreateAt"); + vnfm.setUpdateAt("testUpdateAt"); + String result = vnfm.toString(); + assertEquals( + "Vnfm[id=testId,name=testName,type=testType,version=testVersion,userName=testUserName,pwd=testPwd,url=testUrl,sites=testSites,extraInfo=testExtraInfo,status=testStatus,createAt=testCreateAt,updateAt=testUpdateAt]", + result); + } + + @Test + public void testHashCode() { + Vnfm vnfm = new Vnfm(); + int result = vnfm.hashCode(); + assertEquals(31, result); + } + + @Test + public void testHashCode1() { + Vnfm vnfm = new Vnfm(); + vnfm.setId("testId"); + int result = vnfm.hashCode(); + assertEquals(-877170324, result); + } + + @Test + public void testEquals() { + boolean result = new Vnfm().equals(new Vnfm()); + assertTrue(result); + } + + @Test + public void testEquals1() { + boolean result = new Vnfm().equals(""); + assertFalse(result); + } + + @Test + public void testEquals2() { + Vnfm vnfm = new Vnfm(); + vnfm.setId("testId"); + VnfmOpResult obj = new VnfmOpResult(); + boolean result = new Vnfm().equals(obj); + assertFalse(result); + } + + @Test + public void testEquals3() { + Vnfm obj = new Vnfm(); + obj.setId("testId"); + boolean result = new Vnfm().equals(obj); + assertFalse(result); + } + + @Test + public void testEquals4() { + Vnfm obj = new Vnfm(); + boolean result = obj.equals(obj); + assertTrue(result); + } + + @Test + public void testEquals5() { + boolean result = new Vnfm().equals(null); + assertFalse(result); + } + + @Test + public void testEquals6() { + Vnfm vnfm = new Vnfm(); + Vnfm vnfm2 = new Vnfm(); + vnfm.setId(""); + vnfm2.setId(""); + boolean result = vnfm.equals(vnfm2); + assertTrue(result); + } + + @Test + public void testEquals7() { + Vnfm vnfm = new Vnfm(); + Vnfm vnfm2 = new Vnfm(); + vnfm.setId("vnfmId"); + vnfm2.setId("vnfm2Id"); + boolean result = vnfm.equals(vnfm2); + assertFalse(result); + } + + @Test + public void testUpdateVnfm() { + Vnfm vnfm = new Vnfm(); + JSONObject obj = new JSONObject(); + obj.put("name", "name"); + obj.put("userName", "userName"); + obj.put("pwd", "pwd"); + obj.put("extraInfo", "extraInfo"); + vnfm.updateVnfm(obj); + assertEquals("name", vnfm.getName()); + assertEquals("userName", vnfm.getUserName()); + } + + @Test + public void testUpdateVnfmByEmpty() { + Vnfm vnfm = new Vnfm(); + JSONObject obj = new JSONObject(); + obj.put("name", ""); + obj.put("userName", ""); + obj.put("pwd", ""); + obj.put("extraInfo", ""); + vnfm.updateVnfm(obj); + //assertNull(vnfm.getName()); + //assertNull(vnfm.getUserName()); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/exception/UnsupportedOperationExceptionTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/exception/UnsupportedOperationExceptionTest.java new file mode 100644 index 0000000..6baaf57 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/exception/UnsupportedOperationExceptionTest.java @@ -0,0 +1,36 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.exception; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class UnsupportedOperationExceptionTest { + UnsupportedOperationException mess; + + @Before + public void setUp(){ + mess = new UnsupportedOperationException(); + } + + @Test + public void test() { + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigItemTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigItemTest.java new file mode 100644 index 0000000..84dc214 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigItemTest.java @@ -0,0 +1,45 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.juju.config; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class ConfigItemTest { + + @Test + public void testsetDefaults() { + ConfigItem configItem = new ConfigItem(); + configItem.setDefaults(""); + String result = configItem.getDefaults(); + assertEquals("", result); + } + @Test + public void testsetdescription() { + ConfigItem configItem = new ConfigItem(); + configItem.setDescription(""); + String result = configItem.getDescription(); + assertEquals("", result); + } + @Test + public void testsettype() { + ConfigItem configItem = new ConfigItem(); + configItem.setType(""); + String result = configItem.getType(); + assertEquals("", result); + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigTest.java new file mode 100644 index 0000000..ee3faee --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/ConfigTest.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.nfvo.jujuvnfmadapter.service.juju.config; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class ConfigTest { + @Test + public void testsetDefaults() { + + Map<String,ConfigItem> options=new HashMap<String,ConfigItem> (); + ConfigItem configItem=new ConfigItem(); + configItem.setDescription(""); + options.put("", configItem); + Config config=new Config(options); + config.setOptions(options); + Map map=config.getOptions(); + assertEquals(options, map); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/OptionsTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/OptionsTest.java new file mode 100644 index 0000000..76e5b3e --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/juju/config/OptionsTest.java @@ -0,0 +1,35 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.juju.config; + +import static org.junit.Assert.*; + +import org.junit.Test; + +import mockit.MockUp; + +public class OptionsTest { + + @Test + public void test() { + Options o=new Options(); + new MockUp<Options>() { + + }; + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfMgrTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfMgrTest.java new file mode 100644 index 0000000..1a9ae6e --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfMgrTest.java @@ -0,0 +1,404 @@ +/* + * 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.service.process; + +import static org.junit.Assert.*; + +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.VnfmUtil; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IResourceManager; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class VnfMgrTest { + + VnfMgr mgr; + @Before + public void setUp() { + mgr = new VnfMgr(); + mgr.getJujuVnfmInfoMapper(); + mgr.getResourceManager(); + + } + + @Test + public void addVnfTestNullJson() { + JSONObject vnfObject = new JSONObject(); + String vnfmId = "1234"; + JSONObject resp = mgr.addVnf(vnfObject, vnfmId); + assertEquals(resp.get("retCode"), -1); + } + + @Test + public void addVnfTestOk() { + + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject vnfmObject = new JSONObject(); + vnfmObject.put("url", "http://localhost:8080"); + return vnfmObject; + } + }; + new MockUp<VnfmRestfulUtil>() { + + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, + String domainTokens) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(200); + return resp; + } + }; + JSONObject vnfObject = new JSONObject(); + vnfObject.put("vnfInstanceName", "test123"); + vnfObject.put("vnfPackageId", "123"); + String vnfmId = "1234"; + JSONObject resp = mgr.addVnf(vnfObject, vnfmId); + assertEquals(resp.get("retCode"), -1); + } + + @Test + public void addVnfTestNull() { + + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject vnfmObject = new JSONObject(); + return vnfmObject; + } + }; + JSONObject vnfObject = new JSONObject(); + vnfObject.put("vnfInstanceName", "test123"); + String vnfmId = "1234"; + JSONObject resp = mgr.addVnf(vnfObject, vnfmId); + assertEquals(resp.get("retCode"), -1); + } + + @Test + public void addVnfTestNullRes() { + + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject vnfmObject = new JSONObject(); + vnfmObject.put("url", "http://localhost:8080"); + return vnfmObject; + } + }; + new MockUp<VnfmRestfulUtil>() { + + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, + String domainTokens) { + + return null; + } + }; + JSONObject vnfObject = new JSONObject(); + vnfObject.put("vnfInstanceName", "test123"); + String vnfmId = "1234"; + JSONObject resp = mgr.addVnf(vnfObject, vnfmId); + assertEquals(resp.get("retCode"), -1); + } + + @Test + public void deleteVnfTestNullJson() { + + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + return null; + } + }; + JSONObject vnfObject = new JSONObject(); + vnfObject.put("vnfInstanceName", "test123"); + String vnfmId = "1234"; + JSONObject resp = mgr.deleteVnf("vnfId", "vnfmId", vnfObject); + assertEquals(resp.get("retCode"), -1); + } + + @Test + public void deleteVnfTestValidJson() { + + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject obj = new JSONObject(); + obj.put("url", "http://localhost:8080"); + return obj; + } + }; + new MockUp<VnfMgr>(){ + @Mock + private JujuVnfmInfo findByVnfId(String vnfId){ + JujuVnfmInfo info = new JujuVnfmInfo(); + info.setVnfmId("1234"); + return info; + } + }; + JSONObject vnfObject = new JSONObject(); + vnfObject.put("vnfInstanceName", "test123"); + String vnfmId = "1234"; + JSONObject resp = mgr.deleteVnf("vnfId", "vnfmId", vnfObject); + assertEquals(resp.get("retCode"), -1); + } + + @Test + public void deleteVnf2TestNormal() { + + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject obj = new JSONObject(); + obj.put("url", "http://localhost:8080"); + return obj; + } + }; + new MockUp<VnfMgr>(){ + @Mock + private JujuVnfmInfo findByVnfId(String vnfId){ + JujuVnfmInfo info = new JujuVnfmInfo(); + info.setVnfmId("1234"); + return info; + } + @Mock + private void delJujuVnfmInfo(String vnfId){ + return; + } + }; + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(204); + return resp; + } + }; + JSONObject vnfObject = new JSONObject(); + vnfObject.put("vnfInstanceName", "test123"); + String vnfmId = "1234"; + JSONObject resp = mgr.deleteVnf("vnfId", "vnfmId", vnfObject); + assertEquals(resp.get("retCode"), 1); + } + + @Test + public void getVnfTestNullResp() { + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + return null; + } + }; + JSONObject resp = mgr.getVnf("vnfId", "vnfmId"); + assertEquals(resp.get("retCode"), -1); + } + + @Test + public void getVnfTestValidJson() { + new MockUp<VnfmUtil>() { + + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject obj = new JSONObject(); + obj.put("url", "http://localhost:8080"); + return obj; + } + }; + new MockUp<VnfMgr>(){ + @Mock + private JujuVnfmInfo findByVnfId(String vnfId){ + JujuVnfmInfo info = new JujuVnfmInfo(); + info.setVnfmId("1234"); + return info; + } + @Mock + private void delJujuVnfmInfo(String vnfId){ + return; + } + }; + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens) { + RestfulResponse resp = new RestfulResponse(); + resp.setStatus(201); + JSONObject obj = new JSONObject(); + obj.put("data", new JSONObject()); + resp.setResponseJson(obj.toString()); + return resp; + } + }; + JSONObject resp = mgr.getVnf("vnfId", "vnfmId"); + assertEquals(resp.get("retCode"), -1); + } + + @Test + public void getJobTestNullResp(){ + new MockUp<VnfmUtil>() { + @Mock + public JSONObject getVnfmById(String vnfmId) { + return null; + } + }; + JSONObject resp = mgr.getJob("jobId", "vnfmId"); + assertEquals(resp.get("retCode"), null); + } + + @Test + public void getJobTestNullHttpResp(){ + new MockUp<VnfmUtil>() { + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject ret = new JSONObject(); + ret.put("url", "http://localhost:8080"); + return ret; + } + }; + JSONObject resp = mgr.getJob("jobId", "vnfmId"); + assertEquals(resp.get("retCode"), null); + } + @Test + public void getJobTestSuccessWithNullData(){ + new MockUp<VnfmUtil>() { + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject ret = new JSONObject(); + ret.put("url", "http://localhost:8080"); + return ret; + } + }; + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens) { + RestfulResponse res = new RestfulResponse(); + res.setStatus(201); + + return res; + } + }; + JSONObject resp = mgr.getJob("jobId", "vnfmId"); + assertEquals(resp.get("retCode"), null); + } + @Test + public void getJobTestOkWithNullData(){ + new MockUp<VnfmUtil>() { + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject ret = new JSONObject(); + ret.put("url", "http://localhost:8080"); + return ret; + } + }; + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens) { + RestfulResponse res = new RestfulResponse(); + res.setStatus(200); + + return res; + } + }; + JSONObject resp = mgr.getJob("jobId", "vnfmId"); + assertEquals(resp.get("retCode"), null); + } + @Test + public void getJobTestInternalError(){ + new MockUp<VnfmUtil>() { + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject ret = new JSONObject(); + ret.put("url", "http://localhost:8080"); + return ret; + } + }; + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens) { + RestfulResponse res = new RestfulResponse(); + res.setStatus(500); + + return res; + } + }; + JSONObject resp = mgr.getJob("jobId", "vnfmId"); + assertEquals(resp.get("retCode"), null); + } + @Test + public void getJobTestNormal(){ + new MockUp<VnfmUtil>() { + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject ret = new JSONObject(); + ret.put("url", "http://localhost:8080"); + return ret; + } + }; + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens) { + RestfulResponse res = new RestfulResponse(); + JSONObject jsonData = new JSONObject(); + jsonData.put("data", new JSONObject()); + res.setStatus(200); + res.setResponseJson(jsonData.toString()); + return res; + } + }; + JSONObject resp = mgr.getJob("jobId", "vnfmId"); + assertEquals(resp.get("retCode"), null); + } + @Test + public void getJobTestNullData(){ + new MockUp<VnfmUtil>() { + @Mock + public JSONObject getVnfmById(String vnfmId) { + JSONObject ret = new JSONObject(); + ret.put("url", "http://localhost:8080"); + return ret; + } + }; + new MockUp<VnfmRestfulUtil>(){ + @Mock + public RestfulResponse getRemoteResponse(Map<String, String> paramsMap, String params, String domainTokens) { + RestfulResponse res = new RestfulResponse(); + JSONObject jsonData = new JSONObject(); + jsonData.put("data", null); + res.setStatus(200); + res.setResponseJson(jsonData.toString()); + return res; + } + }; + JSONObject resp = mgr.getJob("jobId", "vnfmId"); + assertEquals(resp.get("retCode"),null); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfResourceMgrTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfResourceMgrTest.java new file mode 100644 index 0000000..013ecd7 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/process/VnfResourceMgrTest.java @@ -0,0 +1,80 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.process; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.jujuvnfmadapter.service.constant.Constant; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample.Criteria; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfoExample.Criterion; +import org.openo.nfvo.jujuvnfmadapter.service.mapper.JujuVnfmInfoMapper; + +import mockit.Expectations; +import mockit.Mock; +import mockit.MockUp; +import mockit.Mocked; +import mockit.integration.junit4.JMockit; +import net.sf.json.JSONObject; +import static mockit.Deencapsulation.*; + + +@RunWith(JMockit.class) + +public class VnfResourceMgrTest { + VnfResourceMgr vnfMgr; + JujuVnfmInfoMapper jujuVnfmInfoMapper; + JujuVnfmInfoExample jujuexample = new JujuVnfmInfoExample(); + Criteria criteria = jujuexample.createCriteria(); + + @Before + public void setUp() { + vnfMgr = new VnfResourceMgr(); + vnfMgr.setJujuVnfmInfoMapper(jujuVnfmInfoMapper); + vnfMgr.getJujuVnfmInfoMapper(); + } + + @Test + public void grantVnfResourceTest() throws ServiceException { + + String vnfId = "1"; + new Expectations(vnfMgr) { + { + invoke(vnfMgr, "findByVnfId", "1"); + JujuVnfmInfo info = new JujuVnfmInfo(); + info.setId("1"); + info.setAppName("Test"); + info.setJobId("1"); + info.setVnfId(vnfId); + returns(info); + } + }; + JSONObject compute = new JSONObject(); + JSONObject res = vnfMgr.grantVnfResource(compute, vnfId); + assertEquals(res.get("retCode"), -1); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ConfigRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ConfigRoaTest.java new file mode 100644 index 0000000..53893a5 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/ConfigRoaTest.java @@ -0,0 +1,85 @@ +/* + * 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. + */ +package org.openo.nfvo.jujuvnfmadapter.service.rest; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.baseservice.roa.util.restclient.RestfulResponse; +import org.openo.nfvo.jujuvnfmadapter.common.JujuConfigUtil; +import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil; +import org.springframework.mock.web.MockHttpServletResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class ConfigRoaTest { + ConfigRoa roa; + + @Before + public void setUp() { + roa = new ConfigRoa(); + } + + @Test + public void initUITest() { + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.initUI(context, resp); + assertNotNull(res); + } + + @Test + public void setDebugModelTest() throws ServiceException { + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + boolean res = roa.setDebugModel(1, context, resp); + assertTrue(res); + } + + @Test + public void setDebug2ModelTest() throws ServiceException { + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + boolean res = roa.setDebugModel(2, context, resp); + assertFalse(res); + } + + @Test + public void testmock() throws ServiceException { + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String methodName = "getVnfmById"; + JSONObject json = new JSONObject(); + + new MockUp<JujuConfigUtil>() { + @Mock + public String getValue(String key) { + return null; + } + + }; + roa.mock(methodName, context, resp); + roa.unmock(methodName, context, resp); + + } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/JujuClientRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/JujuClientRoaTest.java new file mode 100644 index 0000000..4f02669 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/JujuClientRoaTest.java @@ -0,0 +1,132 @@ +/* + * 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. + */ +package org.openo.nfvo.jujuvnfmadapter.service.rest; + +import static org.junit.Assert.assertNotNull; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.jujuvnfmadapter.common.StringUtil; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.impl.JujuClientManager; +import org.openo.nfvo.jujuvnfmadapter.service.process.VnfMgr; +import org.springframework.mock.web.MockHttpServletResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class JujuClientRoaTest { + + JujuClientRoa roa; + + + @Before + public void setUp(){ + roa = new JujuClientRoa(); + roa.setJujuClientManager(new JujuClientManager()); + roa.getJujuClientManager(); + + } + + @Test + public void setCharmUrlTest() throws ServiceException { + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest context) { + String reqJsonObject = "{}"; + return (T)JSONObject.fromObject(reqJsonObject); + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.setCharmUrl(context, resp); + assertNotNull(res); + } + @Test + public void getVnfStatusTest() throws ServiceException { + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.getVnfStatus("appName", context,resp); + assertNotNull(res); + } + @Test + public void deploySerivceTestFail() throws ServiceException { + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + return null; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.deploySerivce(context,resp); + assertNotNull(res); + } + @Test + public void deploySerivceTest() throws ServiceException { + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + JSONObject reqJsonObject = new JSONObject(); + reqJsonObject.put("charmPath", "/abc/xyz"); + reqJsonObject.put("mem", "100"); + reqJsonObject.put("appName", "test"); + return (T)reqJsonObject; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.deploySerivce(context,resp); + assertNotNull(res); + } + + @Test + public void destroySerivceTestFail() throws ServiceException { + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + JSONObject reqJsonObject = new JSONObject(); + reqJsonObject.put("charmPath", "/abc/xyz"); + reqJsonObject.put("mem", "100"); + reqJsonObject.put("appName", "test"); + return (T)reqJsonObject; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.destroySerivce(context,resp); + assertNotNull(res); + } +// @Test +// public void destroySerivce2TestFail() throws ServiceException { +// new MockUp<StringUtil>(){ +// @Mock +// public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { +// JSONObject reqJsonObject = new JSONObject(); +// reqJsonObject.put("appName", "test"); +// return (T)reqJsonObject; +// } +// }; +// HttpServletRequest context = null; +// HttpServletResponse resp = new MockHttpServletResponse(); +// String res = roa.destroySerivce(context,resp); +// assertNotNull(res); +// } +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/TestMockUp.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/TestMockUp.java new file mode 100644 index 0000000..0fd6300 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/TestMockUp.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 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. + */ + +package org.openo.nfvo.jujuvnfmadapter.service.rest; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.openo.nfvo.jujuvnfmadapter.common.StringUtil; + +import mockit.Mock; +import mockit.MockUp; + + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Nov 2, 2016 + */ +public class TestMockUp { + ConfigRoa roa; + /** + * <br/> + * + * @throws java.lang.Exception + * @since NFVO 0.5 + */ + @Before + public void setUp() throws Exception { + roa = new ConfigRoa(); + } + + @Test + public void test() { + new MockUp<StringUtil>(){ + @Mock + public boolean isValidUrl(String url) { + return true; + } + + }; + Assert.assertTrue(StringUtil.isValidUrl("abc")); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfResourceRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfResourceRoaTest.java new file mode 100644 index 0000000..4732233 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfResourceRoaTest.java @@ -0,0 +1,59 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.rest; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.jujuvnfmadapter.common.StringUtil; +import org.openo.nfvo.jujuvnfmadapter.service.process.VnfResourceMgr; +import org.springframework.mock.web.MockHttpServletResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class VnfResourceRoaTest { + + VnfResourceRoa roa = new VnfResourceRoa(); + + @Before + public void setUp(){ + roa.setVnfResourceMgr(new VnfResourceMgr()); + } + + @Test + public void grantVnfResTest() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest context) { + String reqJsonObject = "{}"; + return (T)JSONObject.fromObject(reqJsonObject); + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfId = "1234"; + String res = roa.grantVnfRes(context, vnfId); + assertNotNull(res); + } + +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfRoaTest.java new file mode 100644 index 0000000..e88054f --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/VnfRoaTest.java @@ -0,0 +1,215 @@ +/* + * Copyright 2016 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.nfvo.jujuvnfmadapter.service.rest; + +import static org.junit.Assert.*; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Context; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; +import org.openo.nfvo.jujuvnfmadapter.common.StringUtil; +import org.openo.nfvo.jujuvnfmadapter.service.entity.JujuVnfmInfo; +import org.openo.nfvo.jujuvnfmadapter.service.process.VnfMgr; +import org.springframework.mock.web.MockHttpServletResponse; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +public class VnfRoaTest { + + VnfRoa roa = new VnfRoa(); + @Before + public void setUp(){ + roa.setVnfMgr(new VnfMgr()); + } + + @Test + public void addVnfTestNull() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + return null; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfmId = "1234"; + String res = roa.addVnf(context, resp, vnfmId); + assertNotNull(res); + } + + @Test + public void addVnfTest() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + String vnfJsonStr = "{}"; + return (T)JSONObject.fromObject(vnfJsonStr); + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfmId = "1234"; + String res = roa.addVnf(context, resp, vnfmId); + assertNotNull(res); + } + @Test + public void delVnfTestNull() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + return null; + } + }; + new MockUp<VnfMgr>(){ + @Mock + private JujuVnfmInfo findByVnfId(String vnfId){ + JujuVnfmInfo info = new JujuVnfmInfo(); + info.setVnfmId("1234"); + return info; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfmId = "1234"; + String res = roa.delVnf("vnfmId", resp, "vnfInstanceId",context); + assertNotNull(res); + } + @Test + public void delVnf2TestNull() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + return null; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfmId = "1234"; + String res = roa.delVnf(null, resp, "vnfInstanceId",context); + assertNotNull(res); + } + @Test + public void delVnf3TestNull() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + return null; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfmId = "1234"; + String res = roa.delVnf(vnfmId, resp, null,context); + assertNotNull(res); + } + @Test + public void getVnf1TestNull() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + return null; + } + }; + new MockUp<VnfMgr>(){ + @Mock + private JujuVnfmInfo findByVnfId(String vnfId){ + JujuVnfmInfo info = new JujuVnfmInfo(); + info.setVnfmId("1234"); + return info; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfmId = "1234"; + String res = roa.getVnf(vnfmId, resp, "vnfInstanceId",context); + assertNotNull(res); + } + @Test + public void getVnf2TestNull() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + return null; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfmId = "1234"; + String res = roa.getVnf(null, resp, "vnfInstanceId",context); + assertNotNull(res); + } + @Test + public void getVnf3TestNull() throws ServiceException{ + new MockUp<StringUtil>(){ + @Mock + public <T> T getJsonFromContexts(HttpServletRequest vnfReq) { + return null; + } + }; + HttpServletRequest context = null; + HttpServletResponse resp = new MockHttpServletResponse(); + String vnfmId = "1234"; + String res = roa.getVnf(vnfmId, resp, null,context); + assertNotNull(res); + } + @Test + public void getJobTestNull() throws ServiceException{ + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.getJob("jobId", "vnfmId", resp,"responseId"); + assertNotNull(res); + } + @Test + public void getJobTest2Null() throws ServiceException{ + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.getJob(null, "vnfmId", resp,"responseId"); + assertNotNull(res); + } + @Test + public void getJobTest3Null() throws ServiceException{ + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.getJob("jobId", null, resp,"responseId"); + assertNotNull(res); + } + + @Test + public void getJobTestNormal() throws ServiceException{ + new MockUp<VnfMgr>(){ + @Mock + public JSONObject getJob(String jobId, String vnfmId) { + JSONObject obj = new JSONObject(); + JSONObject dataObj = new JSONObject(); + dataObj.put("id", "1234"); + dataObj.put("status", "Success"); + obj.put("data", dataObj); + obj.put("retCode", 1); + return obj; + } + + }; + HttpServletResponse resp = new MockHttpServletResponse(); + String res = roa.getJob("jobId", "vnfmId", resp,"responseId"); + assertNotNull(res); + } + + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java new file mode 100644 index 0000000..1b497bf --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ExceptionMessageTest.java @@ -0,0 +1,45 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.rest.exceptionmapper; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; + +public class ExceptionMessageTest { + + ExceptionMessage mess; + + @Before + public void setUp(){ + mess = new ExceptionMessage(); + } + + @Test + public void getErrorCodeTest() { + String errorCode = "404"; + String message = "success"; + int httpCode = 200; + mess.setErrorCode(errorCode); + mess.setMessage(message); + mess.setHttpCode(httpCode); + assertEquals(mess.getErrorCode(), errorCode); + assertEquals(mess.getHttpCode(),httpCode); + assertEquals(mess.getMessage(),message); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java new file mode 100644 index 0000000..9582f9d --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/GenericExceptionMapperTest.java @@ -0,0 +1,43 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.rest.exceptionmapper; + +import static org.junit.Assert.*; + +import javax.ws.rs.core.Response; + +import org.junit.Before; +import org.junit.Test; + +public class GenericExceptionMapperTest { + + GenericExceptionMapper genericExpMess; + + + @Before + public void setUp(){ + genericExpMess = new GenericExceptionMapper(); + } + + + @Test + public void toResponseTest() { + Response resp = genericExpMess.toResponse(new Exception("Testing")); + assertEquals(resp.getStatus(),500); + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java new file mode 100644 index 0000000..14c027a --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/exceptionmapper/ServiceExceptionMapperTest.java @@ -0,0 +1,44 @@ +/* + * 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.nfvo.jujuvnfmadapter.service.rest.exceptionmapper; + +import static org.junit.Assert.*; + +import javax.ws.rs.core.Response; + +import org.junit.Before; +import org.junit.Test; +import org.openo.baseservice.remoteservice.exception.ServiceException; + +public class ServiceExceptionMapperTest { + + ServiceExceptionMapper serviceExMapper; + + + @Before + public void setUp(){ + serviceExMapper = new ServiceExceptionMapper(); + } + + + @Test + public void toResponseTest() { + Response resp = serviceExMapper.toResponse(new ServiceException("Testing")); + assertEquals(resp.getStatus(),500); + + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/fullstack/JujuClientRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/fullstack/JujuClientRoaTest.java new file mode 100644 index 0000000..959f374 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/fullstack/JujuClientRoaTest.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2016, 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.nfvo.jujuvnfmadapter.service.rest.fullstack; + +import java.util.List; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils; +import org.apache.log4j.Logger; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.openo.nfvo.jujuvnfmadapter.common.EntityUtils.ExeRes; +import org.openo.nfvo.jujuvnfmadapter.service.adapter.inf.IResourceManager; +import org.openo.nfvo.jujuvnfmadapter.service.rest.JujuClientRoa; +import org.python.jline.internal.Log; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import mockit.Mock; +import mockit.MockUp; +import net.sf.json.JSONObject; + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Nov 3, 2016 + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration({"classpath:test.xml"}) +public class JujuClientRoaTest { + + Logger logger = Logger.getLogger(JujuClientRoaTest.class); + + @Resource + private JujuClientRoa jujuClientRoa; + @Resource + private IResourceManager resourceManager; + + + /** + * <br/> + * + * @throws java.lang.Exception + * @since NFVO 0.5 + */ + @Before + public void setUp() throws Exception { + } + + @Test + public void test() { + Assert.assertNotNull(jujuClientRoa); + } + + @Test + public void testSetCharmUrl() { + HttpServletResponse resp = new MockHttpServletResponse(); + HttpServletRequest request; + String result = null; + try { + request = TestHelper.buildDefaultRequest("setCharmUrl.json"); + result = jujuClientRoa.setCharmUrl(request, resp); + + } catch(Exception e) { + logger.error("error:",e); + + } + Assert.assertNotNull(result); + } + + @Test + public void testGetVnfStatus() { + + //mock method EntityUtils#execute + new MockUp<EntityUtils>(){ + @Mock + public ExeRes execute(String dir, List<String> command) { + ExeRes res = new ExeRes(); + res.setCode(ExeRes.SUCCESS); + res.setBody(null); + return res; + } + }; + + HttpServletResponse resp = new MockHttpServletResponse(); + MockHttpServletRequest request; + String result = null; + try { + request = TestHelper.buildDefaultRequest(null); + String modelName = "mediawiki.yaml"; + request.setParameter("modelName", modelName); + result = jujuClientRoa.getVnfStatus(modelName, request, resp); + Log.info(result); + } catch(Exception e) { + logger.error("error:",e); + + } + JSONObject jr = JSONObject.fromObject(result); + Assert.assertNotNull(result); + Assert.assertEquals(0, jr.getInt("retCode")); + } + + // @Test + public void testDeploySerivce() { + HttpServletResponse resp = new MockHttpServletResponse(); + HttpServletRequest request; + String result = null; + try { + request = TestHelper.buildDefaultRequest("deployService.json"); + result = jujuClientRoa.deploySerivce(request, resp); + Assert.assertNotNull(result); + JSONObject json = JSONObject.fromObject(result); + logger.info(json); + Assert.assertEquals(json.getInt(EntityUtils.RESULT_CODE_KEY),EntityUtils.ExeRes.SUCCESS); + + } catch(Exception e) { + logger.error("error:",e); + + } + + } + +// @Test + public void testDestroySerivce() { + HttpServletResponse resp = new MockHttpServletResponse(); + HttpServletRequest request; + String result = null; + try { + request = TestHelper.buildDefaultRequest("destroySerivce.json"); + result = jujuClientRoa.setCharmUrl(request, resp); + + } catch(Exception e) { + logger.error("error:",e); + + } + Assert.assertNotNull(result); + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/fullstack/TestHelper.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/fullstack/TestHelper.java new file mode 100644 index 0000000..cf8bc30 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/openo/nfvo/jujuvnfmadapter/service/rest/fullstack/TestHelper.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2016, 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.nfvo.jujuvnfmadapter.service.rest.fullstack; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.io.IOUtils; +import org.openo.nfvo.jujuvnfmadapter.common.FileUtils; +import org.springframework.mock.web.MockHttpServletRequest; + +/** + * <br/> + * <p> + * </p> + * + * @author quanzhong@huawei.com + * @version NFVO 0.5 Nov 3, 2016 + */ +public class TestHelper { + + @SuppressWarnings("deprecation") + public static MockHttpServletRequest buildMockRequest(File file) throws FileNotFoundException, IOException { + + String contnet = IOUtils.toString(new FileInputStream(file)); + byte[] content = contnet.getBytes(); + MockHttpServletRequest context = new MockHttpServletRequest(); + context.setContentType("application/json"); + context.setContent(content); + return context; + } + + public static MockHttpServletRequest buildMockRequest(String content) throws FileNotFoundException, IOException { + MockHttpServletRequest context = new MockHttpServletRequest(); + context.setContentType("application/json"); + context.setContent(content.getBytes()); + return context; + } + + public static MockHttpServletRequest buildDefaultRequest(String fileName) + throws FileNotFoundException, IOException { + MockHttpServletRequest context = new MockHttpServletRequest(); + context.setContentType("application/json"); + if(fileName != null) { + String file = FileUtils.getClassPath() + File.separator + fileName; + InputStream input = new FileInputStream(file); + @SuppressWarnings("deprecation") + String contnet = IOUtils.toString(input); + byte[] content = contnet.getBytes(); + context.setContent(content); + } + return context; + } + +} diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/deployService.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/deployService.json new file mode 100644 index 0000000..6dc211e --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/deployService.json @@ -0,0 +1,4 @@ +{ +"appName":"test.yaml", +"charmPath":"E:/workspace/openo-common-utils/src/org/openo/common/yaml" +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/destroyService.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/destroyService.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/destroyService.json @@ -0,0 +1,2 @@ +{ +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/example.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/example.json new file mode 100644 index 0000000..5fefaa8 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/example.json @@ -0,0 +1 @@ +{"InstallTime": "1295768962", "Comments": "Will test without extension.", "Theme": "classic/1.0", "Version": "4.0b10pre", "id": "ec8030f7-c20a-464f-9b0e-13a3a9e97384", "Vendor": "Mozilla", "EMCheckCompatibility": "false", "Throttleable": "1", "Email": "deinspanjer@mozilla.com", "URL": "http://nighthacks.com/roller/jag/entry/the_shit_finally_hits_the", "version": "4.0b10pre", "CrashTime": "1295903735", "ReleaseChannel": "nightly", "submitted_timestamp": "2011-01-24T13:15:48.550858", "buildid": "20110121153230", "timestamp": 1295903748.551002, "Notes": "Renderers: 0x22600,0x22600,0x20400", "StartupTime": "1295768964", "FramePoisonSize": "4096", "FramePoisonBase": "7ffffffff0dea000", "AdapterRendererIDs": "0x22600,0x22600,0x20400", "Add-ons": "compatibility@addons.mozilla.org:0.7,enter.selects@agadak.net:6,{d10d0bf8-f5b5-c8b4-a8b2-2b9879e08c5d}:1.3.3,sts-ui@sidstamm.com:0.1,masspasswordreset@johnathan.nightingale:1.04,support@lastpass.com:1.72.0,{972ce4c6-7e08-4474-a285-3208198ce6fd}:4.0b10pre", "BuildID": "20110121153230", "SecondsSinceLastCrash": "810473", "ProductName": "Firefox", "legacy_processing": 0}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/setCharmUrl.json b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/setCharmUrl.json new file mode 100644 index 0000000..7a73a41 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/setCharmUrl.json @@ -0,0 +1,2 @@ +{ +}
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/test.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/test.xml new file mode 100644 index 0000000..0663c14 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/test.xml @@ -0,0 +1,41 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright 2016 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. + --> + +<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xmlns:osgi="http://www.springframework.org/schema/osgi" xmlns:osgix="http://www.springframework.org/schema/osgi-compendium" + xmlns:ctx="http://www.springframework.org/schema/context" + xmlns:jaxrs="http://cxf.apache.org/jaxrs" + xmlns:http-conf="http://cxf.apache.org/transports/http/configuration" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans + http://www.springframework.org/schema/beans/spring-beans.xsd + http://www.springframework.org/schema/osgi + http://www.springframework.org/schema/osgi/spring-osgi.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context.xsd + http://www.springframework.org/schema/osgi-compendium + http://www.springframework.org/schema/osgi-compendium/spring-osgi-compendium.xsd + http://cxf.apache.org/jaxrs + http://cxf.apache.org/schemas/jaxrs.xsd + http://cxf.apache.org/transports/http/configuration + http://cxf.apache.org/schemas/configuration/http-conf.xsd + http://www.springframework.org/schema/aop + http://www.springframework.org/schema/aop/spring-aop-3.0.xsd" > + + <import resource="classpath:spring/JujuVnfmadapter/services.xml"/> + +</beans>
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/test.yaml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/test.yaml new file mode 100644 index 0000000..00c532d --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/test.yaml @@ -0,0 +1,10 @@ +name: Test User + +address: + line1: My Address Line 1 + line2: Address line 2 + city: Washington D.C. + zip: 20000 +roles: + - User + - Editor
\ No newline at end of file diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/webapp/webtest.xml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/webapp/webtest.xml new file mode 100644 index 0000000..dd71a96 --- /dev/null +++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/webapp/webtest.xml @@ -0,0 +1,15 @@ +<!-- + Copyright 2016 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. + --> |