diff options
19 files changed, 419 insertions, 9 deletions
diff --git a/ChangeLog.md b/ChangeLog.md new file mode 100644 index 0000000..7a8634a --- /dev/null +++ b/ChangeLog.md @@ -0,0 +1,8 @@ +# Change Log
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/)
+and this project adheres to [Semantic Versioning](http://semver.org/).
+
+## [0.0.1] - 2022/08/30
+ - [USECASEUI-714](https://jira.onap.org/browse/USECASEUI-714) - Add policy models for bandwidth assurance intent.
\ No newline at end of file diff --git a/intentanalysis/pom.xml b/intentanalysis/pom.xml index 0c34071..fc3e624 100644 --- a/intentanalysis/pom.xml +++ b/intentanalysis/pom.xml @@ -196,6 +196,16 @@ <artifactId>commons-lang</artifactId> <version>2.6</version> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.8.6</version> + </dependency> + <dependency> + <groupId>com.mikesamuel</groupId> + <artifactId>json-sanitizer</artifactId> + <version>1.2.2</version> + </dependency> </dependencies> <build> <plugins> diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/handler/JsonCollectionTypeHandler.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/handler/JsonCollectionTypeHandler.java new file mode 100644 index 0000000..55796d2 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/handler/JsonCollectionTypeHandler.java @@ -0,0 +1,61 @@ +/* + * Copyright 2020 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.bean.handler; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.google.json.JsonSanitizer; +import java.lang.reflect.Type; +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Collection; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +public class JsonCollectionTypeHandler<T extends Collection<?>> extends BaseTypeHandler<T> { + + Gson gson = new Gson(); + + Type collectionType = new TypeToken<T>() { }.getType(); + + @Override + public void setNonNullParameter(PreparedStatement preparedStatement, int i, T o, JdbcType jdbcType) + throws SQLException { + preparedStatement.setString(i, gson.toJson(o, collectionType)); + } + + @Override + public T getNullableResult(ResultSet resultSet, String s) throws SQLException { + String text = resultSet.getString(s); + return gson.fromJson(text, collectionType); + } + + @Override + public T getNullableResult(ResultSet resultSet, int i) throws SQLException { + String text = resultSet.getString(i); + return gson.fromJson(text, collectionType); + } + + @Override + public T getNullableResult(CallableStatement callableStatement, int i) throws SQLException { + String text = callableStatement.getString(i); + text = JsonSanitizer.sanitize(text); + return gson.fromJson(text, collectionType); + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/handler/JsonTypeHandler.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/handler/JsonTypeHandler.java new file mode 100644 index 0000000..dc30684 --- /dev/null +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/handler/JsonTypeHandler.java @@ -0,0 +1,68 @@ +/* + * Copyright 2020 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.bean.handler; + +import com.google.gson.Gson; +import com.google.json.JsonSanitizer; +import java.sql.CallableStatement; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import org.apache.ibatis.type.BaseTypeHandler; +import org.apache.ibatis.type.JdbcType; + +public class JsonTypeHandler<T extends Object> extends BaseTypeHandler<T> { + + Gson gson = new Gson(); + + private Class<T> clazz; + + /** + * handle json. + */ + public JsonTypeHandler(Class<T> clazz) { + if (clazz == null) { + throw new IllegalArgumentException("Type argument cannot be null"); + } + this.clazz = clazz; + } + + @Override + public void setNonNullParameter(PreparedStatement preparedStatement, int i, Object o, JdbcType jdbcType) + throws SQLException { + preparedStatement.setString(i, gson.toJson(o)); + } + + @Override + public T getNullableResult(ResultSet resultSet, String s) throws SQLException { + String text = resultSet.getString(s); + return gson.fromJson(text, clazz); + } + + @Override + public T getNullableResult(ResultSet resultSet, int i) throws SQLException { + String text = resultSet.getString(i); + return gson.fromJson(text, clazz); + } + + @Override + public T getNullableResult(CallableStatement callableStatement, int i) throws SQLException { + String text = callableStatement.getString(i); + text = JsonSanitizer.sanitize(text); + return gson.fromJson(text, clazz); + } +} diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java index 1612090..4209c1b 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/cllBusinessIntentMgt/cllBusinessModule/CLLBusinessActuationModule.java @@ -17,24 +17,33 @@ package org.onap.usecaseui.intentanalysis.cllBusinessIntentMgt.cllBusinessModule import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentHandleService; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService.IntentProcessService; +import org.onap.usecaseui.intentanalysis.service.IntentService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + @Service public class CLLBusinessActuationModule implements ActuationModule { @Autowired IntentProcessService processService; @Autowired IntentHandleService intentHandleService; + @Autowired + IntentService intentService; @Override public void sendToIntentHandler(IntentManagementFunction IntentHandler) { - } @Override @@ -48,7 +57,16 @@ public class CLLBusinessActuationModule implements ActuationModule { } @Override - public void saveIntentToDb() { + public void saveIntentToDb(List<Map<IntentGoalBean,IntentManagementFunction>> intentMapList) { + List<IntentGoalBean> subIntentGoalLit = new ArrayList<>(); + for (Map<IntentGoalBean,IntentManagementFunction> map:intentMapList) { + subIntentGoalLit.addAll(map.keySet()); + } + List<Intent> subIntentList = subIntentGoalLit.stream().map(IntentGoalBean::getIntent) + .collect(Collectors.toList()); + for (Intent subIntent:subIntentList) { + intentService.createIntent(subIntent); + } } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java index 34ae57c..2800c1e 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentModule/ActuationModule.java @@ -15,14 +15,18 @@ */ package org.onap.usecaseui.intentanalysis.intentBaseService.intentModule; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; +import java.util.List; +import java.util.Map; + public interface ActuationModule { //actuationModel & knownledgeModel interact void sendToIntentHandler(IntentManagementFunction IntentHandler); void sendToNonIntentHandler();//直接操作 void interactWithIntentHandle(); //Save intent information to the intent instance database - void saveIntentToDb(); + void saveIntentToDb(List<Map<IntentGoalBean,IntentManagementFunction>> intentMapList); } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionService.java index 9407f91..a75701d 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentDefinitionService.java @@ -16,11 +16,16 @@ package org.onap.usecaseui.intentanalysis.intentBaseService.intentProcessService; +import org.onap.usecaseui.intentanalysis.bean.models.Intent; +import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean; import org.onap.usecaseui.intentanalysis.intentBaseService.IntentManagementFunction; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.ActuationModule; import org.onap.usecaseui.intentanalysis.intentBaseService.intentModule.DecisionModule; import org.springframework.stereotype.Service; +import java.util.List; +import java.util.Map; + @Service public class IntentDefinitionService { @@ -36,10 +41,10 @@ public class IntentDefinitionService { } } - public void definitionPorcess() { + public void definitionPorcess(List<Map<IntentGoalBean,IntentManagementFunction>> intentMapList) { DecisionModule intentDecisionModule = intentOwner.getDecisionModule(); ActuationModule intentActuationModule = intentOwner.getActuationModule(); intentDecisionModule.intentDefinition(); - intentActuationModule.saveIntentToDb(); + intentActuationModule.saveIntentToDb(intentMapList);//id type } } diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentOperationService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentOperationService.java index 6ffbc2d..47fe679 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentOperationService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentOperationService.java @@ -38,9 +38,9 @@ public class IntentOperationService { public void operationProcess() { DecisionModule intentDecisionModule = intentOwner.getDecisionModule(); - ActuationModule intentActuationModule = intentOwner.getActuationModule(); + ActuationModule intentActuationModule = intentHandler.getActuationModule(); - intentDecisionModule.interactWithTemplateDb(); + //intentDecisionModule.interactWithTemplateDb(); intentActuationModule.interactWithIntentHandle(); intentActuationModule.sendToIntentHandler(intentHandler); diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java index 6bff142..ec4037e 100644 --- a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java +++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentProcessService/IntentProcessService.java @@ -60,9 +60,9 @@ public class IntentProcessService { for (Map<IntentGoalBean,IntentManagementFunction> map : intentListMap) { - //definition process + //definition process save subintent intentDefinitionService.setIntentRole(intentOwner,intentHandler); - intentDefinitionService.definitionPorcess(); + intentDefinitionService.definitionPorcess(intentListMap); //distribution process intentDistributionService.setIntentRole(intentOwner,intentHandler); diff --git a/intentanalysis/src/main/resources/intentPolicy/deploy_intent_configs.json b/intentanalysis/src/main/resources/intentPolicy/deploy_intent_configs.json new file mode 100644 index 0000000..1e22ce4 --- /dev/null +++ b/intentanalysis/src/main/resources/intentPolicy/deploy_intent_configs.json @@ -0,0 +1,8 @@ +{ + "policies": [ + { + "policy-id": "onap.dcae.slicems.config", + "policy-version": 1 + } + ] +} diff --git a/intentanalysis/src/main/resources/intentPolicy/deploy_modifycll.json b/intentanalysis/src/main/resources/intentPolicy/deploy_modifycll.json new file mode 100644 index 0000000..c8685cf --- /dev/null +++ b/intentanalysis/src/main/resources/intentPolicy/deploy_modifycll.json @@ -0,0 +1,9 @@ +{
+ "policies":[
+ {
+ "policy-id":"operational.modifycll",
+ "policy-version":1
+ }
+ ]
+}
+
diff --git a/intentanalysis/src/main/resources/intentPolicy/intent_configs_policy.json b/intentanalysis/src/main/resources/intentPolicy/intent_configs_policy.json new file mode 100644 index 0000000..a9d1e79 --- /dev/null +++ b/intentanalysis/src/main/resources/intentPolicy/intent_configs_policy.json @@ -0,0 +1,23 @@ +{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "onap.dcae.slicems.config": {
+ "type": "onap.policies.monitoring.docker.slicems.app",
+ "type_version": "1.0.0",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "onap.dcae.slicems.config",
+ "policy-version": 1
+ },
+ "properties": {
+ "cllId": "cll-01",
+ "closedLoopStatus": "on",
+ "originalBw": "1000"
+ }
+ }
+ }
+ ]
+ }
+}
diff --git a/intentanalysis/src/main/resources/intentPolicy/intent_configs_policy_type.json b/intentanalysis/src/main/resources/intentPolicy/intent_configs_policy_type.json new file mode 100644 index 0000000..318b098 --- /dev/null +++ b/intentanalysis/src/main/resources/intentPolicy/intent_configs_policy_type.json @@ -0,0 +1,28 @@ +{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "policy_types": {
+ "onap.policies.monitoring.docker.slicems.app": {
+ "version": "1.0.0",
+ "description": "son handler policy type",
+ "derived_from": "onap.policies.Monitoring:1.0.0",
+ "description": "Runtime Configuration of Slice MS",
+ "properties": {
+ "cllId": {
+ "type": "string",
+ "required": true,
+ "description": "cll id"
+ },
+ "closedLoopStatus": {
+ "type": "string",
+ "required": true,
+ "description": "whether provide closed loop assurance for one cll"
+ },
+ "originalBw": {
+ "type": "string",
+ "required": true,
+ "description": "original bw of one cll"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/intentanalysis/src/main/resources/intentPolicy/modifycll.json b/intentanalysis/src/main/resources/intentPolicy/modifycll.json new file mode 100644 index 0000000..778a669 --- /dev/null +++ b/intentanalysis/src/main/resources/intentPolicy/modifycll.json @@ -0,0 +1,50 @@ +{
+
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "operational.modifycll": {
+ "type": "onap.policies.controlloop.operational.common.Drools",
+ "type_version": "1.0.0",
+ "version": "1.0.0",
+ "name": "operational.modifycll",
+ "metadata": {
+ "policy_id": "operational.modifycll"
+ },
+ "properties": {
+ "id": "ControlLoop-CCVPN-CLL-227e8b00-dbeb-4d03-8719-d0a658fb846c",
+ "timeout": 1200,
+ "abatement": false,
+ "trigger": "unique-policy-id-1-modify-cll",
+ "operations": [
+ {
+ "id": "unique-policy-id-1-modify-cll",
+ "description": "Modify resource allocation for a slice subnet instance",
+ "operation": {
+ "actor": "SO",
+ "operation": "ModifyCloudLeasedLine",
+ "target": {
+ "targetType": "VNF"
+ }
+ },
+ "timeout": 1200,
+ "retries": 0,
+ "success": "final_success",
+ "failure": "final_failure",
+ "failure_timeout": "final_failure_timeout",
+ "failure_retries": "final_failure_retires",
+ "failure_exception": "final_failure_exception",
+ "failure_guard": "final_failure_guard"
+ }
+ ],
+ "controllerName": "usecases"
+ }
+
+ }
+
+ }
+ ]
+ }
+
+}
\ No newline at end of file diff --git a/intentanalysis/src/test/resources/intentPolicy/deploy_intent_configs.json b/intentanalysis/src/test/resources/intentPolicy/deploy_intent_configs.json new file mode 100644 index 0000000..1e22ce4 --- /dev/null +++ b/intentanalysis/src/test/resources/intentPolicy/deploy_intent_configs.json @@ -0,0 +1,8 @@ +{ + "policies": [ + { + "policy-id": "onap.dcae.slicems.config", + "policy-version": 1 + } + ] +} diff --git a/intentanalysis/src/test/resources/intentPolicy/deploy_modifycll.json b/intentanalysis/src/test/resources/intentPolicy/deploy_modifycll.json new file mode 100644 index 0000000..c8685cf --- /dev/null +++ b/intentanalysis/src/test/resources/intentPolicy/deploy_modifycll.json @@ -0,0 +1,9 @@ +{
+ "policies":[
+ {
+ "policy-id":"operational.modifycll",
+ "policy-version":1
+ }
+ ]
+}
+
diff --git a/intentanalysis/src/test/resources/intentPolicy/intent_configs_policy.json b/intentanalysis/src/test/resources/intentPolicy/intent_configs_policy.json new file mode 100644 index 0000000..a9d1e79 --- /dev/null +++ b/intentanalysis/src/test/resources/intentPolicy/intent_configs_policy.json @@ -0,0 +1,23 @@ +{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "onap.dcae.slicems.config": {
+ "type": "onap.policies.monitoring.docker.slicems.app",
+ "type_version": "1.0.0",
+ "version": "1.0.0",
+ "metadata": {
+ "policy-id": "onap.dcae.slicems.config",
+ "policy-version": 1
+ },
+ "properties": {
+ "cllId": "cll-01",
+ "closedLoopStatus": "on",
+ "originalBw": "1000"
+ }
+ }
+ }
+ ]
+ }
+}
diff --git a/intentanalysis/src/test/resources/intentPolicy/intent_configs_policy_type.json b/intentanalysis/src/test/resources/intentPolicy/intent_configs_policy_type.json new file mode 100644 index 0000000..318b098 --- /dev/null +++ b/intentanalysis/src/test/resources/intentPolicy/intent_configs_policy_type.json @@ -0,0 +1,28 @@ +{
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "policy_types": {
+ "onap.policies.monitoring.docker.slicems.app": {
+ "version": "1.0.0",
+ "description": "son handler policy type",
+ "derived_from": "onap.policies.Monitoring:1.0.0",
+ "description": "Runtime Configuration of Slice MS",
+ "properties": {
+ "cllId": {
+ "type": "string",
+ "required": true,
+ "description": "cll id"
+ },
+ "closedLoopStatus": {
+ "type": "string",
+ "required": true,
+ "description": "whether provide closed loop assurance for one cll"
+ },
+ "originalBw": {
+ "type": "string",
+ "required": true,
+ "description": "original bw of one cll"
+ }
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/intentanalysis/src/test/resources/intentPolicy/modifycll.json b/intentanalysis/src/test/resources/intentPolicy/modifycll.json new file mode 100644 index 0000000..778a669 --- /dev/null +++ b/intentanalysis/src/test/resources/intentPolicy/modifycll.json @@ -0,0 +1,50 @@ +{
+
+ "tosca_definitions_version": "tosca_simple_yaml_1_1_0",
+ "topology_template": {
+ "policies": [
+ {
+ "operational.modifycll": {
+ "type": "onap.policies.controlloop.operational.common.Drools",
+ "type_version": "1.0.0",
+ "version": "1.0.0",
+ "name": "operational.modifycll",
+ "metadata": {
+ "policy_id": "operational.modifycll"
+ },
+ "properties": {
+ "id": "ControlLoop-CCVPN-CLL-227e8b00-dbeb-4d03-8719-d0a658fb846c",
+ "timeout": 1200,
+ "abatement": false,
+ "trigger": "unique-policy-id-1-modify-cll",
+ "operations": [
+ {
+ "id": "unique-policy-id-1-modify-cll",
+ "description": "Modify resource allocation for a slice subnet instance",
+ "operation": {
+ "actor": "SO",
+ "operation": "ModifyCloudLeasedLine",
+ "target": {
+ "targetType": "VNF"
+ }
+ },
+ "timeout": 1200,
+ "retries": 0,
+ "success": "final_success",
+ "failure": "final_failure",
+ "failure_timeout": "final_failure_timeout",
+ "failure_retries": "final_failure_retires",
+ "failure_exception": "final_failure_exception",
+ "failure_guard": "final_failure_guard"
+ }
+ ],
+ "controllerName": "usecases"
+ }
+
+ }
+
+ }
+ ]
+ }
+
+}
\ No newline at end of file |