feat: add ccvpn instance manage 86/123486/2
author’zhaoyh6‘ <zhaoyh6@asiainfo.com>
Tue, 24 Aug 2021 08:09:07 +0000 (16:09 +0800)
committerzhao yehua <zhaoyh6@asiainfo.com>
Tue, 24 Aug 2021 08:18:49 +0000 (08:18 +0000)
Issue-ID: USECASEUI-525
Signed-off-by: ’zhaoyh6‘ <zhaoyh6@asiainfo.com>
Change-Id: I2962d5814f3db1867995043141d7f1e1a902933a

server/src/main/java/org/onap/usecaseui/server/bean/intent/InstancePerformance.java [new file with mode: 0644]
server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentInstance.java [new file with mode: 0644]
server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentResponseBody.java [new file with mode: 0644]
server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentResultData.java [new file with mode: 0644]
server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java [new file with mode: 0644]
server/src/main/java/org/onap/usecaseui/server/controller/IntentController.java
server/src/main/java/org/onap/usecaseui/server/service/intent/IntentApiService.java [new file with mode: 0644]
server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java [new file with mode: 0644]
server/src/main/java/org/onap/usecaseui/server/service/intent/IntentResponseAOP.java [new file with mode: 0644]
server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java [new file with mode: 0644]

diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/intent/InstancePerformance.java b/server/src/main/java/org/onap/usecaseui/server/bean/intent/InstancePerformance.java
new file mode 100644 (file)
index 0000000..677f86f
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2017 CTC, Inc. and others. All rights reserved.
+ *
+ * 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.server.bean.intent;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+
+@Entity
+@Table(name="instance_performance")
+public class InstancePerformance implements Serializable {
+
+    @Id
+    @GeneratedValue(strategy= GenerationType.IDENTITY)
+    @Column(name = "id")
+    private int id;
+
+    @Column(name = "job_id")
+    private String jobId;
+
+    @Column(name = "resource_instance_id")
+    private String resourceInstanceId;
+
+    @Column(name = "bandwidth")
+    private String bandwidth;
+
+    @Temporal(TemporalType.DATE)
+    @Column(name = "date")
+    private Date date;
+
+    @Column(name = "max_bandwidth")
+    private String maxBandwidth;
+
+
+    public InstancePerformance() {
+
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getJobId() {
+        return jobId;
+    }
+
+    public void setJobId(String jobId) {
+        this.jobId = jobId;
+    }
+
+    public String getResourceInstanceId() {
+        return resourceInstanceId;
+    }
+
+    public void setResourceInstanceId(String resourceInstanceId) {
+        this.resourceInstanceId = resourceInstanceId;
+    }
+
+    public String getBandwidth() {
+        return bandwidth;
+    }
+
+    public void setBandwidth(String bandwidth) {
+        this.bandwidth = bandwidth;
+    }
+
+    public Date getDate() {
+        return date;
+    }
+
+    public void setDate(Date date) {
+        this.date = date;
+    }
+
+    public String getMaxBandwidth() {
+        return maxBandwidth;
+    }
+
+    public void setMaxBandwidth(String maxBandwidth) {
+        this.maxBandwidth = maxBandwidth;
+    }
+}
\ No newline at end of file
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentInstance.java b/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentInstance.java
new file mode 100644 (file)
index 0000000..521f28c
--- /dev/null
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2017 CTC, Inc. and others. All rights reserved.
+ *
+ * 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.server.bean.intent;
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Entity
+@Table(name="intent_instance")
+public class IntentInstance 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;
+
+    public IntentInstance() {
+
+    }
+
+    public int getId() {
+        return id;
+    }
+
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    public String getInstanceId() {
+        return instanceId;
+    }
+
+    public void setInstanceId(String instanceId) {
+        this.instanceId = instanceId;
+    }
+
+    public String getJobId() {
+        return jobId;
+    }
+
+    public void setJobId(String jobId) {
+        this.jobId = jobId;
+    }
+
+    public int getProgress() {
+        return progress;
+    }
+
+    public void setProgress(int progress) {
+        this.progress = progress;
+    }
+
+    public String getStatus() {
+        return status;
+    }
+
+    public void setStatus(String status) {
+        this.status = status;
+    }
+
+    public String getResourceInstanceId() {
+        return resourceInstanceId;
+    }
+
+    public void setResourceInstanceId(String resourceInstanceId) {
+        this.resourceInstanceId = resourceInstanceId;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getCloudPointName() {
+        return cloudPointName;
+    }
+
+    public void setCloudPointName(String cloudPointName) {
+        this.cloudPointName = cloudPointName;
+    }
+
+    public String getAccessPointOneName() {
+        return accessPointOneName;
+    }
+
+    public void setAccessPointOneName(String accessPointOneName) {
+        this.accessPointOneName = accessPointOneName;
+    }
+
+    public int getAccessPointOneBandWidth() {
+        return accessPointOneBandWidth;
+    }
+
+    public void setAccessPointOneBandWidth(int accessPointOneBandWidth) {
+        this.accessPointOneBandWidth = accessPointOneBandWidth;
+    }
+
+    public String getLineNum() {
+        return lineNum;
+    }
+
+    public void setLineNum(String lineNum) {
+        this.lineNum = lineNum;
+    }
+}
\ No newline at end of file
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentResponseBody.java b/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentResponseBody.java
new file mode 100644 (file)
index 0000000..bc931bb
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.server.bean.intent;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.TYPE,ElementType.METHOD})
+public @interface IntentResponseBody {
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentResultData.java b/server/src/main/java/org/onap/usecaseui/server/bean/intent/IntentResultData.java
new file mode 100644 (file)
index 0000000..fa99391
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.server.bean.intent;
+
+import com.alibaba.fastjson.JSONObject;
+import lombok.Data;
+import java.io.Serializable;
+
+@Data
+public class IntentResultData implements Serializable {
+    private static final long serialVersionUID = 4238217913168412725L;
+
+    private Integer code;
+
+    private String message;
+
+    private Object data;
+
+    public String toString() {
+        return JSONObject.toJSONString(this);
+    }
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java b/server/src/main/java/org/onap/usecaseui/server/conf/intent/IntentScheduleTask.java
new file mode 100644 (file)
index 0000000..f35edf4
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved.
+ *
+ * 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.server.conf.intent;
+
+import org.onap.usecaseui.server.service.intent.IntentInstanceService;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+
+@Configuration
+@EnableScheduling
+public class IntentScheduleTask {
+
+
+    @Resource(name = "IntentInstanceService")
+    private IntentInstanceService intentInstanceService;
+
+//    @Scheduled(cron = "0/20 * * * * ?")
+    public void getIntentInstanceCompleteness() {
+        intentInstanceService.getIntentInstanceProgress();
+    }
+//    @Scheduled(cron = "0/20 * * * * ?")
+    public void getIntentInstanceBandwidth() throws IOException {
+        intentInstanceService.getIntentInstanceBandwidth();
+    }
+}
index 5347a4e..428965c 100644 (file)
 package org.onap.usecaseui.server.controller;
 
 import java.io.File;
+import java.io.IOException;
 import java.text.ParseException;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import javax.annotation.Resource;
 
+import org.apache.commons.collections.MapUtils;
 import org.onap.usecaseui.server.bean.HttpResponseResult;
+import org.onap.usecaseui.server.bean.csmf.SlicingOrder;
+import org.onap.usecaseui.server.bean.csmf.SlicingOrderDetail;
+import org.onap.usecaseui.server.bean.intent.IntentInstance;
 import org.onap.usecaseui.server.bean.intent.IntentModel;
+import org.onap.usecaseui.server.bean.intent.IntentResponseBody;
+import org.onap.usecaseui.server.bean.nsmf.common.ServiceResult;
+import org.onap.usecaseui.server.controller.csmf.SlicingController;
+import org.onap.usecaseui.server.service.csmf.SlicingService;
+import org.onap.usecaseui.server.service.intent.IntentApiService;
+import org.onap.usecaseui.server.service.intent.IntentInstanceService;
 import org.onap.usecaseui.server.service.intent.IntentService;
-import org.onap.usecaseui.server.util.DateUtils;
-import org.onap.usecaseui.server.util.HttpUtil;
+import org.onap.usecaseui.server.util.*;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.context.annotation.EnableAspectJAutoProxy;
 import org.springframework.http.MediaType;
-import org.springframework.web.bind.annotation.CrossOrigin;
-import org.springframework.web.bind.annotation.DeleteMapping;
-import org.springframework.web.bind.annotation.GetMapping;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RequestParam;
-import org.springframework.web.bind.annotation.ResponseBody;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
+import retrofit2.Call;
+import retrofit2.Response;
 
 @RestController
 @org.springframework.context.annotation.Configuration
@@ -62,8 +62,23 @@ public class IntentController {
     @Resource(name = "IntentService")
     private IntentService intentService;
 
+    @Resource(name = "IntentInstanceService")
+    private IntentInstanceService intentInstanceService;
+
+    private IntentApiService intentApiService;
+
     private ObjectMapper omAlarm = new ObjectMapper();
 
+    @Resource(name = "SlicingService")
+    private SlicingService slicingService;
+
+    public IntentController() {
+        this(RestfulServices.create(IntentApiService.class));
+    }
+    public IntentController(IntentApiService intentApiService) {
+        this.intentApiService = intentApiService;
+    }
+
     @GetMapping(value="/listModel",produces = "application/json;charset=utf8")
     public String getModels() throws JsonProcessingException {
         List<IntentModel> listModels = intentService.listModels();
@@ -255,4 +270,108 @@ public class IntentController {
         ret = map.get(key.trim());
         return ret;
     }
+
+    @IntentResponseBody
+    @ResponseBody
+    @GetMapping(value = {"/getInstanceId"},
+            produces = "application/json")
+    public JSONObject getInstanceId() {
+        int first = new Random(10).nextInt(8) + 1;
+        System.out.println(first);
+        int hashCodeV = UUID.randomUUID().toString().hashCode();
+        if (hashCodeV < 0) {//有可能是负数
+            hashCodeV = -hashCodeV;
+        }
+        String instanceId = first + String.format("%015d", hashCodeV);
+        JSONObject result = new JSONObject();
+        result.put("instanceId", instanceId);
+        return result;
+    }
+    @IntentResponseBody
+    @GetMapping(value = {"/getInstanceList/{currentPage}/{pageSize}"},
+            produces = "application/json")
+    public Object getInstanceList(@PathVariable String currentPage, @PathVariable String pageSize) {
+        return intentInstanceService.queryIntentInstance(null, Integer.parseInt(currentPage), Integer.parseInt(pageSize));
+    }
+    @IntentResponseBody
+    @ResponseBody
+    @PostMapping(value = {"/createIntentInstance"}, consumes = MediaType.APPLICATION_JSON_VALUE,
+            produces = "application/json; charset=utf-8")
+    public Object createIntentInstance(@RequestBody Object body) throws IOException {
+        String intentInstanceId = (String) ((Map)body).get("instanceId");
+        String name = (String) ((Map)body).get("name");
+        String lineNum = (String) ((Map)body).get("lineNum");
+        String cloudPointName = (String) ((Map)body).get("cloudPointName");
+        Map<String, Object> accessPointOne = (Map) ((Map)body).get("accessPointOne");
+        String accessPointOneName = MapUtils.getString(accessPointOne, "name");
+        int accessPointOneBandWidth = MapUtils.getIntValue(accessPointOne, "bandwidth");
+
+        IntentInstance intentInstance = new IntentInstance();
+        intentInstance.setInstanceId(intentInstanceId);
+        intentInstance.setName(name);
+        intentInstance.setLineNum(lineNum);
+        intentInstance.setCloudPointName(cloudPointName);
+        intentInstance.setAccessPointOneName(accessPointOneName);
+        intentInstance.setAccessPointOneBandWidth(accessPointOneBandWidth);
+
+        int flag = intentInstanceService.createIntentInstance(intentInstance);
+
+        if(flag == 1) {
+            return "OK";
+        }
+        else {
+            throw new RuntimeException("create Instance error");
+        }
+    }
+
+    @IntentResponseBody
+    @GetMapping(value = {"/getFinishedInstanceInfo"},
+            produces = "application/json")
+    public Object getFinishedInstanceInfo() {
+        List<IntentInstance> instanceList = intentInstanceService.getFinishedInstanceInfo();
+        List<Map<String, Object>> result = new ArrayList<>();
+        for (IntentInstance instance : instanceList) {
+            Map<String, Object> instanceInfo = new HashMap<>();
+            instanceInfo.put("instanceId", instance.getInstanceId());
+            instanceInfo.put("name", instance.getName());
+            result.add(instanceInfo);
+        }
+        return result;
+    }
+
+    @IntentResponseBody
+    @DeleteMapping(value = {"/deleteIntentInstance"},
+            produces = "application/json")
+    public Object deleteIntentInstance(@RequestParam(value = "instanceId") String instanceId) {
+        intentInstanceService.deleteIntentInstance(instanceId);
+        return "ok";
+    }
+    @IntentResponseBody
+    @PutMapping(value = {"/activeIntentInstance"},
+            produces = "application/json")
+    public Object activeIntentInstance(@RequestParam(value = "instanceId") String instanceId) {
+        intentInstanceService.activeIntentInstance(instanceId);
+        return "ok";
+    }
+    @IntentResponseBody
+    @PutMapping(value = {"/invalidIntentInstance"},
+            produces = "application/json")
+    public Object invalidIntentInstance(@RequestParam(value = "instanceId") String instanceId) {
+        intentInstanceService.invalidIntentInstance(instanceId);
+        return "ok";
+    }
+
+    @IntentResponseBody
+    @PutMapping(value = {"/queryInstancePerformanceData"},
+            produces = "application/json")
+    public Object queryInstancePerformanceData(@RequestParam(value = "instanceId") String instanceId) {
+        return intentInstanceService.queryInstancePerformanceData(instanceId);
+    }
+
+    @IntentResponseBody
+    @GetMapping(value = {"/queryAccessNodeInfo"},
+            produces = "application/json")
+    public Object queryAccessNodeInfo() throws IOException{
+        return intentInstanceService.queryAccessNodeInfo();
+    }
 }
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentApiService.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentApiService.java
new file mode 100644 (file)
index 0000000..7601434
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2017 CTC, Inc. and others. All rights reserved.
+ *
+ * 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.server.service.intent;
+
+
+import com.alibaba.fastjson.JSONObject;
+import okhttp3.RequestBody;
+import retrofit2.Call;
+import retrofit2.http.*;
+
+public interface IntentApiService {
+
+    @Headers({
+            "X-TransactionId: 9999",
+            "X-FromAppId: MSO",
+            "Authorization: Basic QUFJOkFBSQ==",
+            "Accept: application/json"
+    })
+    @POST("/so/infra/serviceIntent/v1/create")
+    Call<JSONObject> createIntentInstance(@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}?depth=all")
+    Call<JSONObject> getInstanceNetworkInfo(@Path("resource-service-id") String resourceServiceId);
+
+    @Headers({
+            "X-TransactionId: 9999",
+            "X-FromAppId: MSO",
+            "Authorization: Basic QUFJOkFBSQ==",
+            "Accept: application/json"
+    })
+    @GET("/aai/v24/network/network-policies/network-policy/{networkPolicyId}?depth=all")
+    Call<JSONObject> getInstanceNetworkPolicyInfo(@Path("networkPolicyId") String networkPolicyId);
+
+    @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}/metadata")
+    Call<JSONObject> getInstanceBandwidth(@Path("resource-service-id") String resourceServiceId);
+
+    @Headers({
+            "X-TransactionId: 9999",
+            "X-FromAppId: MSO",
+            "Authorization: Basic QUFJOkFBSQ==",
+            "Accept: application/json"
+    })
+    @POST("/so/infra/serviceIntent/v1/delete")
+    Call<JSONObject> deleteIntentInstance(@Body RequestBody body);
+
+    @Headers({
+            "X-TransactionId: 9999",
+            "X-FromAppId: MSO",
+            "Authorization: Basic QUFJOkFBSQ==",
+            "Accept: application/json"
+    })
+    @POST("/aai/v24/network/network-routes")
+    Call<JSONObject> queryNetworkRoute();
+
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentInstanceService.java
new file mode 100644 (file)
index 0000000..dfc8683
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2017 CTC, Inc. and others. All rights reserved.
+ *
+ * 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.server.service.intent;
+
+import org.onap.usecaseui.server.bean.intent.IntentInstance;
+import org.onap.usecaseui.server.util.Page;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+public interface IntentInstanceService {
+    Page<IntentInstance> queryIntentInstance(IntentInstance intentInstance, int currentPage, int pageSize);
+    int createIntentInstance(IntentInstance intentInstance);
+    void getIntentInstanceProgress();
+    List<IntentInstance> getFinishedInstanceInfo();
+    void getIntentInstanceBandwidth() throws IOException;
+
+    void deleteIntentInstance(String instanceId);
+
+    void activeIntentInstance(String instanceId);
+
+    void invalidIntentInstance(String instanceId);
+
+    Map<String, Object> queryInstancePerformanceData(String instanceId);
+
+    Object queryAccessNodeInfo() throws IOException;
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentResponseAOP.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/IntentResponseAOP.java
new file mode 100644 (file)
index 0000000..aad3c6c
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2017 CTC, Inc. and others. All rights reserved.
+ *
+ * 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.server.service.intent;
+
+import com.alibaba.fastjson.JSONObject;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.onap.usecaseui.server.bean.intent.IntentResultData;
+import org.springframework.stereotype.Component;
+
+@Component
+@Aspect
+public class IntentResponseAOP {
+
+    @Around(value = "@annotation(org.onap.usecaseui.server.bean.intent.IntentResponseBody)")
+    public JSONObject pressResultData(ProceedingJoinPoint joinPoint) throws Throwable {
+
+        IntentResultData resultData = new IntentResultData();
+        try {
+            Object proceed = joinPoint.proceed();
+            resultData.setCode(200);
+            resultData.setMessage("OK");
+            resultData.setData(proceed);
+        }
+        catch (Exception e) {
+            resultData.setData(500);
+            resultData.setMessage("Error:" + e.getMessage());
+        }
+        return JSONObject.parseObject(resultData.toString());
+    }
+}
diff --git a/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java b/server/src/main/java/org/onap/usecaseui/server/service/intent/impl/IntentInstanceServiceImpl.java
new file mode 100644 (file)
index 0000000..d62150d
--- /dev/null
@@ -0,0 +1,511 @@
+/*
+ * Copyright (C) 2017 CTC, Inc. and others. All rights reserved.
+ *
+ * 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.server.service.intent.impl;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import org.hibernate.Query;
+import org.hibernate.Session;
+import org.hibernate.SessionFactory;
+import org.hibernate.Transaction;
+import org.onap.usecaseui.server.bean.intent.InstancePerformance;
+import org.onap.usecaseui.server.bean.intent.IntentInstance;
+import org.onap.usecaseui.server.service.intent.IntentApiService;
+import org.onap.usecaseui.server.service.intent.IntentInstanceService;
+import org.onap.usecaseui.server.service.lcm.domain.so.SOService;
+import org.onap.usecaseui.server.service.lcm.domain.so.bean.OperationProgressInformation;
+import org.onap.usecaseui.server.util.Page;
+import org.onap.usecaseui.server.util.RestfulServices;
+import org.onap.usecaseui.server.util.UuiCommonUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.EnableAspectJAutoProxy;
+import org.springframework.stereotype.Service;
+import retrofit2.Response;
+
+import javax.transaction.Transactional;
+import java.io.IOException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+
+@Service("IntentInstanceService")
+@Transactional
+@org.springframework.context.annotation.Configuration
+@EnableAspectJAutoProxy
+public class IntentInstanceServiceImpl implements IntentInstanceService {
+    private static final Logger logger = LoggerFactory.getLogger(IntentInstanceServiceImpl.class);
+
+    @Autowired
+    private SessionFactory sessionFactory;
+
+
+    private IntentApiService intentApiService;
+
+    private SOService soService;
+
+    public IntentInstanceServiceImpl() {
+        this(RestfulServices.create(IntentApiService.class),RestfulServices.create(SOService.class));
+    }
+    public IntentInstanceServiceImpl(IntentApiService intentApiService, SOService soService) {
+        this.intentApiService = intentApiService;
+        this.soService = soService;
+    }
+
+    private Session getSession() {
+        return sessionFactory.openSession();
+    }
+
+    @Override
+    public Page<IntentInstance> queryIntentInstance(IntentInstance intentInstance, int currentPage, int pageSize) {
+        Page<IntentInstance> page = new Page<IntentInstance>();
+        int allRow =this.getAllCount(intentInstance,currentPage,pageSize);
+        int offset = page.countOffset(currentPage, pageSize);
+        Session session = getSession();
+        try{
+            StringBuffer hql =new StringBuffer("from IntentInstance a where 1=1");
+            if (null != intentInstance) {
+                if(UuiCommonUtil.isNotNullOrEmpty(intentInstance.getInstanceId())) {
+                    String ver =intentInstance.getInstanceId();
+                    hql.append(" and a.instance_id = '"+ver+"'");
+                }
+                if(UuiCommonUtil.isNotNullOrEmpty(intentInstance.getJobId())) {
+                    String ver =intentInstance.getJobId();
+                    hql.append(" and a.job_id = '"+ver+"'");
+                }
+                if(UuiCommonUtil.isNotNullOrEmpty(intentInstance.getStatus())) {
+                    String ver =intentInstance.getStatus();
+                    hql.append(" and a.status = '"+ver+"'");
+                }
+            }
+            hql.append(" order by id");
+            logger.info("AlarmsHeaderServiceImpl queryIntentInstance: intentInstance={}", intentInstance);
+            Query query = session.createQuery(hql.toString());
+            query.setFirstResult(offset);
+            query.setMaxResults(pageSize);
+            List<IntentInstance> list= query.list();
+            page.setPageNo(currentPage);
+            page.setPageSize(pageSize);
+            page.setTotalRecords(allRow);
+            page.setList(list);
+            return page;
+        } catch (Exception e) {
+            logger.error("exception occurred while performing AlarmsHeaderServiceImpl queryAlarmsHeader. Details:" + e.getMessage());
+            return null;
+        }
+    }
+
+
+    public int getAllCount(IntentInstance intentInstance,int currentPage,int pageSize) {
+        Session session = getSession();
+        try{
+            StringBuffer count=new StringBuffer("select count(*) from IntentInstance a where 1=1");
+            if (null != intentInstance) {
+                if(UuiCommonUtil.isNotNullOrEmpty(intentInstance.getInstanceId())) {
+                    String ver =intentInstance.getInstanceId();
+                    count.append(" and a.instance_id = '"+ver+"'");
+                }
+                if(UuiCommonUtil.isNotNullOrEmpty(intentInstance.getJobId())) {
+                    String ver =intentInstance.getJobId();
+                    count.append(" and a.job_id = '"+ver+"'");
+                }
+                if(UuiCommonUtil.isNotNullOrEmpty(intentInstance.getStatus())) {
+                    String ver =intentInstance.getStatus();
+                    count.append(" and a.status = '"+ver+"'");
+                }
+            }
+            count.append(" order by id");
+            Query query = session.createQuery(count.toString());
+            long q=(long)query.uniqueResult();
+            return (int)q;
+        } catch (Exception e) {
+            logger.error("exception occurred while performing IntentInstanceServiceImpl getAllCount. Details:" + e.getMessage());
+            return -1;
+        }
+    }
+
+    @Override
+    public int createIntentInstance(IntentInstance intentInstance) {
+        try{
+
+            if (null == intentInstance){
+                logger.error("intentInstance is null!");
+                return 0;
+            }
+            String jobId = createIntentInstanceToSO(intentInstance);
+            intentInstance.setJobId(jobId);
+            intentInstance.setResourceInstanceId("cll-"+intentInstance.getInstanceId());
+            Session session = getSession();
+            Transaction tx = session.beginTransaction();
+            session.save(intentInstance);
+            tx.commit();
+//            session.flush();
+            return 1;
+        } catch (Exception e) {
+            logger.error("Details:" + e.getMessage());
+            return 0;
+        }
+    }
+
+    private String createIntentInstanceToSO(IntentInstance intentInstance) throws IOException {
+        Map<String, Object> params = new HashMap<>();
+        params.put("name", intentInstance.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");
+        Map<String, Object> additionalProperties = new HashMap<>();
+        additionalProperties.put("enableSdnc", "false");
+        additionalProperties.put("serviceInstanceID", "cll-" + intentInstance.getInstanceId());
+        List<Map<String, Object>> transportNetworks = new ArrayList<>();
+        Map<String, Object> transportNetwork = new HashMap<>();
+        transportNetwork.put("id", "");
+        Map<String, Object> sla = new HashMap<>();
+        sla.put("latency", "2");
+        sla.put("maxBandwidth", intentInstance.getAccessPointOneBandWidth());
+        List<Map<String, Object>> connectionLinks = new ArrayList<>();
+        Map<String, Object> connectionLink = new HashMap<>();
+        connectionLink.put("name", "");
+        connectionLink.put("transportEndpointA", intentInstance.getAccessPointOneName());
+        connectionLink.put("transportEndpointB", intentInstance.getCloudPointName());
+        connectionLinks.add(connectionLink);
+        transportNetwork.put("sla", sla);
+        transportNetwork.put("connectionLinks", connectionLinks);
+        transportNetworks.add(transportNetwork);
+        additionalProperties.put("transportNetworks", transportNetworks);
+        params.put("additionalProperties",additionalProperties);
+
+        okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params));
+        Response<JSONObject> response = intentApiService.createIntentInstance(requestBody).execute();
+        if (response.isSuccessful()) {
+            return response.body().getString("jobId");
+        }
+        return null;
+    }
+
+    @Override
+    public void getIntentInstanceProgress() {
+        List<IntentInstance> instanceList = getInstanceByFinishedFlag("0");
+        for (IntentInstance instance: instanceList) {
+            try {
+
+                int progress = getProgressByJobId(instance);
+                if (progress >=100) {
+                    instance.setStatus("1");
+                }
+                instance.setProgress(progress);
+            }
+            catch (Exception e) {
+                logger.info("get progress exception:"+e);
+            }
+        }
+        saveProgress(instanceList);
+
+    }
+
+    private void saveProgress(List<IntentInstance> instanceList) {
+        Transaction tx = null;
+        if(instanceList == null || instanceList.isEmpty()) {
+            return;
+        }
+        try(Session session = getSession()) {
+            tx = session.beginTransaction();
+            for (IntentInstance instance : instanceList) {
+                session.save(instance);
+            }
+            tx.commit();
+            logger.info("update progress ok");
+
+        } catch (Exception e) {
+            if(tx!=null){
+                tx.rollback();
+            }
+            logger.error("update progress exception:"+e);
+
+        }
+    }
+
+    private int getProgressByJobId(IntentInstance instance) throws IOException {
+        Response<OperationProgressInformation> response = soService.queryOperationProgress(instance.getResourceInstanceId(), instance.getJobId()).execute();
+        return response.body().getOperationStatus().getProgress();
+    }
+
+    private List<IntentInstance> getInstanceByFinishedFlag(String flag) {
+        Session session = getSession();
+        try{
+            StringBuffer sql=new StringBuffer("from IntentInstance where status = '" + flag + "'");
+
+            Query query = session.createQuery(sql.toString());
+            List<IntentInstance> q=(List<IntentInstance>) query.list();
+            logger.debug(q.toString());
+            return q;
+        } catch (Exception e) {
+            logger.error("exception occurred while performing IntentInstanceServiceImpl getNotFinishedJobId. Details:" + e.getMessage());
+            return null;
+        }
+    }
+
+
+    @Override
+    public List<IntentInstance> getFinishedInstanceInfo() {
+        Session session = getSession();
+        try{
+            StringBuffer count=new StringBuffer("from IntentInstance where status = '1'");
+
+            Query query = session.createQuery(count.toString());
+            List<IntentInstance> q=(List<IntentInstance>) query.list();
+            logger.debug(q.toString());
+            return q;
+        } catch (Exception e) {
+            logger.error("exception occurred while performing IntentInstanceServiceImpl getNotFinishedJobId. Details:" + e.getMessage());
+            return null;
+        }
+    }
+
+    @Override
+    public void getIntentInstanceBandwidth() throws IOException {
+        List<IntentInstance> instanceList = getInstanceByFinishedFlag("1");
+        for (IntentInstance instance : instanceList) {
+            String serviceInstanceId = instance.getResourceInstanceId();
+            Response<JSONObject> response = intentApiService.getInstanceNetworkInfo(serviceInstanceId).execute();
+            JSONObject responseBody = response.body();
+            JSONObject allottedResource = responseBody.getJSONObject("allotted-resources").getJSONArray("allotted-resource").getJSONObject(0);
+            JSONArray relationshipList = allottedResource.getJSONObject("relationship-list").getJSONArray("relationship");
+            String networkPolicyId = null;
+            for (int i = 0; i<relationshipList.size();i++) {
+                if ("network-policy".equals(relationshipList.getJSONObject(i).getString("related-to"))) {
+                    JSONArray datas = relationshipList.getJSONObject(i).getJSONArray("relationship-data");
+                    for (int j = 0; j<relationshipList.size();j++) {
+                        if ("network-policy.network-policy-id".equals(datas.getJSONObject(j).getString("relationship-key"))) {
+                            networkPolicyId = datas.getJSONObject(j).getString("relationship-value");
+                            break;
+                        }
+                    }
+                    break;
+                }
+            }
+            if (networkPolicyId== null) {
+                logger.error("get network Policy Id exception. serviceInstanceId:" + instance.getResourceInstanceId());
+                continue;
+            }
+            JSONObject networkPolicyInfo = intentApiService.getInstanceNetworkPolicyInfo(networkPolicyId).execute().body();
+            String maxBandwidth =  networkPolicyInfo.getString("max-bandwidth");
+            InstancePerformance instancePerformance = new InstancePerformance();
+            instancePerformance.setMaxBandwidth(maxBandwidth);
+            instancePerformance.setResourceInstanceId(instance.getResourceInstanceId());
+            instancePerformance.setJobId(instance.getJobId());
+            instancePerformance.setDate(new Date());
+
+            JSONObject metadatum = intentApiService.getInstanceBandwidth(serviceInstanceId).execute().body();
+            String metaval = metadatum.getJSONArray("metadatum").getJSONObject(0).getString("metaval");
+            instancePerformance.setBandwidth(metaval);
+
+            try{
+                Session session = getSession();
+                Transaction tx = session.beginTransaction();
+                session.save(instancePerformance);
+                tx.commit();
+            } catch (Exception e) {
+                logger.error("Details:" + e.getMessage());
+            }
+
+
+        }
+    }
+
+    @Override
+    public void deleteIntentInstance(String instanceId) {
+        IntentInstance result = null;
+
+        try(Session session = getSession()) {
+
+            result = (IntentInstance)session.createQuery("from IntentInstance where instanceId = :instanceId")
+                    .setParameter("instanceId", instanceId).uniqueResult();
+            logger.info("get IntentInstance OK, id=" + instanceId);
+
+        } catch (Exception e) {
+            logger.error("getodel occur exception:"+e);
+
+        }
+        try {
+            String serviceInstanceId = result.getResourceInstanceId();
+            deleteInstanceToSO(serviceInstanceId);
+            deleteInstance(serviceInstanceId);
+        }catch (Exception e) {
+            logger.error("delete instance to SO error :" + e);
+        }
+    }
+
+
+    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", "false");
+        params.put("additionalProperties", additionalProperties);
+        okhttp3.RequestBody requestBody = okhttp3.RequestBody.create(okhttp3.MediaType.parse("application/json"), JSON.toJSONString(params));
+        intentApiService.deleteIntentInstance(requestBody).execute();
+    }
+    private String deleteInstance(String serviceInstanceId) {
+        Transaction tx = null;
+        String result="0";
+        if(serviceInstanceId==null || serviceInstanceId.trim().equals(""))
+            return  result;
+
+        try(Session session = getSession()) {
+            tx = session.beginTransaction();
+
+            IntentInstance instance = new IntentInstance();
+            instance.setInstanceId(serviceInstanceId);
+            session.delete(instance);
+            tx.commit();
+            logger.info("delete instance OK, id=" + serviceInstanceId);
+
+            result="1";
+        } catch (Exception e) {
+            if(tx!=null){
+                tx.rollback();
+            }
+            logger.error("delete instance occur exception:"+e);
+
+        }
+        return result;
+    }
+
+    @Override
+    public void activeIntentInstance(String instanceId) {
+        IntentInstance instance = null;
+
+        try(Session session = getSession()) {
+
+            instance = (IntentInstance)session.createQuery("from IntentInstance where instanceId = :instanceId and status = :status")
+                    .setParameter("instanceId", instanceId).setParameter("status", "3").uniqueResult();
+            logger.info("get instance OK, id=" + instanceId);
+
+        } catch (Exception e) {
+            logger.error("getodel occur exception:"+e);
+
+        }
+        if (null == instance) {
+            logger.error("intentInstance is null!");
+            return;
+        }
+        try {
+            String jobId = createIntentInstanceToSO(instance);
+            instance.setStatus("0");
+            instance.setJobId(jobId);
+            Session session = getSession();
+            Transaction tx = session.beginTransaction();
+            session.save(instance);
+            tx.commit();
+
+        }catch (Exception e) {
+            logger.error("active instance to SO error :" + e);
+        }
+    }
+
+    public void invalidIntentInstance(String instanceId) {
+        IntentInstance instance = null;
+
+        try(Session session = getSession()) {
+            instance = (IntentInstance)session.createQuery("from IntentInstance where instanceId = :instanceId")
+                    .setParameter("instanceId", instanceId).uniqueResult();
+            logger.info("get instance OK, id=" + instanceId);
+
+        } catch (Exception e) {
+            logger.error("get instance occur exception:"+e);
+
+        }
+        if (null == instance) {
+            logger.error("intentInstance is null!");
+            return;
+        }
+        try {
+            deleteInstanceToSO(instance.getInstanceId());
+            instance.setStatus("3");
+            Session session = getSession();
+            Transaction tx = session.beginTransaction();
+            session.save(instance);
+            tx.commit();
+
+        }catch (Exception e) {
+            logger.error("invalid instance to SO error :" + e);
+        }
+    }
+
+    @Override
+    public Map<String, Object> queryInstancePerformanceData(String instanceId) {
+        try(Session session = getSession()) {
+            String hql = "from IntentInstance i, InstancePerformance p where i.resourceInstanceId = p.resourceInstanceId order by p.date";
+            Query query = session.createQuery(hql);
+            List<Object[]> queryResult= query.list();
+            List<String> date = new ArrayList<>();
+            List<String> bandwidth = new ArrayList<>();
+            List<String> maxBandwidth = new ArrayList<>();
+            SimpleDateFormat ft = new SimpleDateFormat("yyyy-MM-dd");
+            for (Object[] o : queryResult) {
+                InstancePerformance performance = (InstancePerformance) o[1];
+                date.add(ft.format(performance.getDate()));
+                bandwidth.add(performance.getBandwidth());
+                maxBandwidth.add(performance.getMaxBandwidth());
+            }
+            Map<String, Object> xAxis = new HashMap<>();
+            xAxis.put("data",date);
+            Map<String, Object> bandwidthData = new HashMap<>();
+            bandwidthData.put("data",bandwidth);
+            Map<String, Object> maxBandwidthData = new HashMap<>();
+            maxBandwidthData.put("data",maxBandwidth);
+            List<Map<String, Object>> series = new ArrayList<>();
+            series.add(bandwidthData);
+            series.add(maxBandwidthData);
+
+            Map<String, Object> result = new HashMap<>();
+            result.put("xAxis", xAxis);
+            result.put("series", series);
+
+            return result;
+        }catch (Exception e) {
+            logger.error("invalid instance to SO error :" + e);
+            throw e;
+        }
+    }
+
+    @Override
+    public Object queryAccessNodeInfo() throws IOException {
+        Map<String, Object> result = new HashMap<>();
+        List<String> accessNodeList = new ArrayList<>();
+        List<String> cloudAccessNodeList = new ArrayList<>();
+        JSONObject body = intentApiService.queryNetworkRoute().execute().body();
+        JSONArray data = body.getJSONArray("data");
+        for (int i = 0; i<data.size(); i++) {
+            JSONObject nodeInfo = data.getJSONObject(i);
+            if ("ROOT".equals(nodeInfo.getString("type"))) {
+                cloudAccessNodeList.add(nodeInfo.getString("route-id"));
+            }
+            else {
+                accessNodeList.add(nodeInfo.getString("route-id"));
+            }
+        }
+        result.put("accessNodeList",accessNodeList);
+        result.put("cloudAccessNodeList",cloudAccessNodeList);
+        return result;
+    }
+}