aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShuhaoCai <caishuhao@huawei.com>2022-08-31 17:27:03 +0800
committerShuhaoCai <caishuhao@huawei.com>2022-08-31 17:27:03 +0800
commit0699e877538e8ee6179750112a4414848058fe09 (patch)
tree3ade998d622bfce6e58db05501d043d93b759a7a
parent938d71a7adbfa2d7221ee37ce44f9e2ca8e5213a (diff)
Create intent to SO
Issue-ID: USECASEUI-717 Signed-off-by: ShuhaoCai <caishuhao@huawei.com> Change-Id: Ibade884474b96885730ffcb9e4268a1e607d0016
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAPICall.java25
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java10
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAPICall.java47
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java176
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/CCVPNInstance.java58
5 files changed, 315 insertions, 1 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAPICall.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAPICall.java
new file mode 100644
index 0000000..ead4d2c
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/aai/apicall/AAIAPICall.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2022 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.onap.usecaseui.intentanalysis.adapters.aai.apicall;
+
+import com.alibaba.fastjson.JSONObject;
+import retrofit2.Call;
+import retrofit2.http.GET;
+
+public interface AAIAPICall {
+ @GET("/aai/v24/network/network-routes")
+ Call<JSONObject> queryNetworkRoute();
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java
index 92ef65c..4129b8e 100644
--- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/SOService.java
@@ -15,4 +15,12 @@
*/
package org.onap.usecaseui.intentanalysis.adapters.so;
-public interface SOService { }
+import org.onap.usecaseui.intentanalysis.bean.models.CCVPNInstance;
+
+public interface SOService {
+
+ int createCCVPNInstance(CCVPNInstance instance);
+
+ void deleteIntentInstance(String instanceId);
+
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAPICall.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAPICall.java
new file mode 100644
index 0000000..11fae26
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/apicall/SOAPICall.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2022 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.onap.usecaseui.intentanalysis.adapters.so.apicall;
+
+import com.alibaba.fastjson.JSONObject;
+import okhttp3.RequestBody;
+import retrofit2.Call;
+import retrofit2.http.*;
+
+public interface SOAPICall {
+ @Headers({
+ "Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==",
+ "Accept: application/json"
+ })
+ @POST("/so/infra/serviceIntent/v1/create")
+ Call<JSONObject> createIntentInstance(@Body RequestBody body);
+
+ @Headers({
+ "Authorization: Basic SW5mcmFQb3J0YWxDbGllbnQ6cGFzc3dvcmQxJA==",
+ "Accept: application/json"
+ })
+ @HTTP(method="DELETE", path="/so/infra/serviceIntent/v1/delete", hasBody = true)
+ Call<JSONObject> deleteIntentInstance(@Body RequestBody body);
+
+ @Headers({
+ "X-TransactionId: 9999",
+ "X-FromAppId: MSO",
+ "Authorization: Basic QUFJOkFBSQ==",
+ "Accept: application/json"
+ })
+ @GET("/aai/v24/business/customers/customer/IBNCustomer/service-subscriptions/service-subscription/IBN/service-instances/service-instance/{resource-service-id}")
+ Call<JSONObject> getInstanceInfo(@Path("resource-service-id") String resourceServiceId);
+
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java
new file mode 100644
index 0000000..7f34584
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/adapters/so/impl/SOServiceImpl.java
@@ -0,0 +1,176 @@
+/*
+ * Copyright 2022 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.onap.usecaseui.intentanalysis.adapters.so.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import org.onap.usecaseui.intentanalysis.adapters.so.SOService;
+import org.onap.usecaseui.intentanalysis.adapters.so.apicall.SOAPICall;
+import org.onap.usecaseui.intentanalysis.bean.models.CCVPNInstance;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import retrofit2.Response;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class SOServiceImpl implements SOService {
+
+ private static final Logger logger = LoggerFactory.getLogger(SOServiceImpl.class);
+
+
+ private SOAPICall soapiCall;
+
+ @Override
+ public int createCCVPNInstance(CCVPNInstance ccvpnInstance) {
+ try{
+ if (null == ccvpnInstance){
+ logger.error("CCVPN instance is null!");
+ return 0;
+ }
+ String jobId = createIntentInstanceToSO(ccvpnInstance);
+ if (null == jobId){
+ logger.error("CCVPN instance creation error:jobId is null");
+ return 0;
+ }
+ ccvpnInstance.setJobId(jobId);
+ ccvpnInstance.setResourceInstanceId("cll-"+ccvpnInstance.getInstanceId());
+
+ long startTime = System.currentTimeMillis();
+ long maxWaitingPeriod = 30 * 1000; // wait for 30s
+ while (getCreateStatus(ccvpnInstance) != 1){
+ if((System.currentTimeMillis() - startTime) > maxWaitingPeriod) {
+ logger.error("CCVPN instance creation error: failed to send to so within time frame");
+ return 0;
+ }
+ }
+ // creation status equals to 1
+ return 1;
+ } catch (Exception e) {
+ logger.error("Details:" + e.getMessage());
+ return 0;
+ }
+ }
+
+ @Override
+ public void deleteIntentInstance(String serviceInstanceId) {
+ try {
+ deleteInstanceToSO(serviceInstanceId);
+ }catch (Exception e) {
+ logger.error("delete instance to SO error :" + e);
+ }
+ }
+
+ public String createIntentInstanceToSO(CCVPNInstance ccvpnInstance) throws IOException {
+ Map<String, Object> params = paramsSetUp(ccvpnInstance);
+ params.put("additionalProperties",additionalPropertiesSetUp(ccvpnInstance));
+ okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params));
+ Response<JSONObject> response = soapiCall.createIntentInstance(requestBody).execute();
+ if (response.isSuccessful()) {
+ return response.body().getString("jobId");
+ }
+ return null;
+ }
+
+ private void deleteInstanceToSO(String serviceInstanceId) throws IOException {
+ JSONObject params = new JSONObject();
+ params.put("serviceInstanceID", serviceInstanceId);
+ params.put("globalSubscriberId", "IBNCustomer");
+ params.put("subscriptionServiceType", "IBN");
+ params.put("serviceType", "CLL");
+ JSONObject additionalProperties = new JSONObject();
+ additionalProperties.put("enableSdnc", "true");
+ params.put("additionalProperties", additionalProperties);
+ okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params));
+ soapiCall.deleteIntentInstance(requestBody).execute();
+ }
+
+ private int getCreateStatus(CCVPNInstance ccvpnInstance) throws IOException {
+ if (ccvpnInstance == null || ccvpnInstance.getResourceInstanceId() == null) {
+ return -1;
+ }
+ Response<JSONObject> response = soapiCall.getInstanceInfo(ccvpnInstance.getResourceInstanceId()).execute();
+ logger.debug(response.toString());
+ if (response.isSuccessful()) {
+ String status = response.body().getString("orchestration-status");
+ if ("created".equals(status)) {
+ return 1;
+ }
+ }
+ logger.error("getIntentInstance Create Statue Error:" + response.toString());
+ return -1;
+ }
+
+ /**
+ * parameter set up for ccpvpn instance creation
+ * @param ccvpnInstance
+ * @return
+ */
+ private Map<String, Object> paramsSetUp(CCVPNInstance ccvpnInstance) {
+ Map<String, Object> params = new HashMap<>();
+ params.put("name", ccvpnInstance.getName());
+ params.put("modelInvariantUuid", "6790ab0e-034f-11eb-adc1-0242ac120002");
+ params.put("modelUuid", "6790ab0e-034f-11eb-adc1-0242ac120002");
+ params.put("globalSubscriberId", "IBNCustomer");
+ params.put("subscriptionServiceType", "IBN");
+ params.put("serviceType", "CLL");
+ return params;
+ }
+
+ /**
+ * additional properties set up for ccvpn instance creation
+ * @param ccvpnInstance
+ * @return
+ */
+ private Map<String, Object> additionalPropertiesSetUp(CCVPNInstance ccvpnInstance) {
+ Map<String, Object> additionalProperties = new HashMap<>();
+ additionalProperties.put("enableSdnc", "true");
+ additionalProperties.put("serviceInstanceID", "cll-" + ccvpnInstance.getInstanceId());
+
+ // create connection link
+ Map<String, Object> connectionLink = new HashMap<>();
+ connectionLink.put("name", "");
+ connectionLink.put("transportEndpointA", ccvpnInstance.getAccessPointOneName());
+ connectionLink.put("transportEndpointB", ccvpnInstance.getCloudPointName());
+
+ // create sla
+ Map<String, Object> sla = new HashMap<>();
+ sla.put("latency", "2");
+ sla.put("maxBandwidth", ccvpnInstance.getAccessPointOneBandWidth());
+
+ // configuration for sla and connection link
+ if (ccvpnInstance.getProtectStatus() == 1) {
+ sla.put("protectionType", ccvpnInstance.getProtectionType());
+ connectionLink.put("transportEndpointBProtection", ccvpnInstance.getProtectionCloudPointName());
+ }
+
+ List<Map<String, Object>> connectionLinks = new ArrayList<>();
+ connectionLinks.add(connectionLink);
+
+ Map<String, Object> transportNetwork = new HashMap<>();
+ transportNetwork.put("id", "");
+ transportNetwork.put("sla", sla);
+ transportNetwork.put("connectionLinks", connectionLinks);
+
+ List<Map<String, Object>> transportNetworks = new ArrayList<>();
+ transportNetworks.add(transportNetwork);
+ additionalProperties.put("transportNetworks", transportNetworks);
+ return additionalProperties;
+ }
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/CCVPNInstance.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/CCVPNInstance.java
new file mode 100644
index 0000000..b5d73f1
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/CCVPNInstance.java
@@ -0,0 +1,58 @@
+package org.onap.usecaseui.intentanalysis.bean.models;
+
+import lombok.Data;
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Entity
+@Table(name="ccvpn_instance")
+@Data
+
+public class CCVPNInstance implements Serializable {
+ @Id
+ @GeneratedValue(strategy= GenerationType.IDENTITY)
+ @Column(name = "id")
+ private int id;
+
+ @Column(name = "instance_id")
+ private String instanceId;
+
+ @Column(name = "job_id")
+ private String jobId;
+
+ @Column(name = "progress")
+ private int progress;
+
+ @Column(name = "status")
+ private String status;
+
+ @Column(name = "resource_instance_id")
+ private String resourceInstanceId;
+
+ @Column(name = "name")
+ private String name;
+
+ @Column(name = "cloud_point_name")
+ private String cloudPointName;
+
+ @Column(name = "access_point_one_name")
+ private String accessPointOneName;
+
+ @Column(name = "access_point_one_band_width")
+ private int accessPointOneBandWidth;
+
+ @Column(name = "line_num")
+ private String lineNum;
+
+ @Column(name = "protect_status")
+ private int protectStatus;
+
+ @Column(name = "delete_state")
+ private int deleteState;
+
+ @Column(name = "protection_cloud_point_name")
+ private String protectionCloudPointName;
+
+ @Column(name = "protection_type")
+ private String protectionType;
+}