aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhekeguang <hekeguang@chinamobile.com>2023-03-22 15:59:14 +0800
committerzhen zhang <781953240@qq.com>2023-03-22 09:28:53 +0000
commit4a90df529431588f3228c236aa17d2c11116328f (patch)
tree01670374593745f7a18bb430c0a2d07245946779
parent765575b67283f0d71327bcd27d8fa4e921061a56 (diff)
Merge Event and Thread code.
Issue-ID: USECASEUI-784 Change-Id: I0cdef6c490f96c45e77013b0da5c372decdef6a1 Signed-off-by: hekeguang <hekeguang@chinamobile.com>
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/CreateCallable.java58
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java51
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/IntentEventRecord.java29
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/event/IntentCreateEvent.java44
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/event/IntentDeleteEvent.java39
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/listener/IntentEventListener.java56
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentEventRecord/IntentEventRecordService.java38
-rw-r--r--intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentEventRecordMapper.java26
-rw-r--r--intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml17
9 files changed, 358 insertions, 0 deletions
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/CreateCallable.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/CreateCallable.java
new file mode 100644
index 0000000..b91eb63
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/CreateCallable.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2023 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.intentanalysis.Thread;
+
+import org.onap.usecaseui.intentanalysis.bean.enums.IntentGoalType;
+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.springframework.context.ApplicationContext;
+
+import java.util.concurrent.Callable;
+
+public class CreateCallable implements Callable<String> {
+ private Intent originalIntent;
+ private IntentGoalBean intentGoalBean;
+ private IntentManagementFunction handler;
+ private ApplicationContext applicationContext;
+
+ public CreateCallable() {
+ }
+ public CreateCallable(Intent originalIntent, IntentGoalBean intentGoalBean, IntentManagementFunction handler, ApplicationContext applicationContext) {
+ this.originalIntent = originalIntent;
+ this.intentGoalBean = intentGoalBean;
+ this.handler = handler;
+ this.applicationContext = applicationContext;
+ }
+
+ @Override
+ public String call() throws Exception {
+ ActuationModule actuationModule = handler.getActuationModule();
+ IntentGoalType type = intentGoalBean.getIntentGoalType();
+ if (type == IntentGoalType.CREATE) {
+ actuationModule.saveIntentToDb(intentGoalBean.getIntent());
+ }else if (type==IntentGoalType.UPDATE){
+ actuationModule.updateIntentToDb(intentGoalBean.getIntent());
+ }else if (type == IntentGoalType.DELETE) {
+ actuationModule.deleteIntentToDb(intentGoalBean.getIntent());
+ }
+ actuationModule.fulfillIntent(intentGoalBean, handler);
+ //update origin intent if need
+ actuationModule.updateIntentOperationInfo(originalIntent, intentGoalBean);
+ return intentGoalBean.getIntent().getIntentName() +" Intent operate finished";
+ }
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java
new file mode 100644
index 0000000..e1f0af7
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/Thread/ThreadPoolConfig.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2023 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.intentanalysis.Thread;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
+
+import java.util.concurrent.Executor;
+import java.util.concurrent.ThreadPoolExecutor;
+
+@Configuration
+//@EnableAsync
+public class ThreadPoolConfig {
+
+ @Bean("intentTaskExecutor")
+ public Executor asyncServiceExecutor() {
+ ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
+ // corePoolSize
+ executor.setCorePoolSize(2);
+ // maxPoolSize
+ executor.setMaxPoolSize(10);
+ //queueCapacity
+ executor.setQueueCapacity(60);
+ //set destroy time (seconds)
+ executor.setKeepAliveSeconds(60);
+ // thread name
+ executor.setThreadNamePrefix("Intent_Thread_Excutor-");
+ // Wait for all tasks to finish before closing the thread pool
+ executor.setWaitForTasksToCompleteOnShutdown(true);
+ //rejectPolicy
+ executor.setRejectedExecutionHandler(new ThreadPoolExecutor.AbortPolicy());
+ //init pool
+ executor.initialize();
+ return executor;
+ }
+}
+
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/IntentEventRecord.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/IntentEventRecord.java
new file mode 100644
index 0000000..6f75863
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/bean/models/IntentEventRecord.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2023 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.intentanalysis.bean.models;
+
+import lombok.Data;
+
+@Data
+public class IntentEventRecord {
+ private String id;
+ private String intentId;
+ private String intentName;
+ private String intentStatus;
+ private String operateType;
+
+
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/event/IntentCreateEvent.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/event/IntentCreateEvent.java
new file mode 100644
index 0000000..ec9b4c7
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/event/IntentCreateEvent.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2023 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.intentanalysis.eventAndPublish.event;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+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.springframework.context.ApplicationEvent;
+
+@Setter
+@Getter
+@ToString
+public class IntentCreateEvent extends ApplicationEvent {
+ private Intent originalIntent;
+ private IntentGoalBean intentGoalBean;
+ private IntentManagementFunction handler;
+ private String intentStatus;
+ public IntentCreateEvent(Object source, Intent originalIntent, IntentGoalBean intentGoalBean,
+ IntentManagementFunction handler,String intentStatus) {
+ super(source);
+ this.originalIntent = originalIntent;
+ this.intentGoalBean = intentGoalBean;
+ this.handler = handler;
+ this.intentStatus=intentStatus;
+
+
+ }
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/event/IntentDeleteEvent.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/event/IntentDeleteEvent.java
new file mode 100644
index 0000000..3708f87
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/event/IntentDeleteEvent.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2023 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.intentanalysis.eventAndPublish.event;
+
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.usecaseui.intentanalysis.bean.models.Intent;
+import org.springframework.context.ApplicationEvent;
+
+@Setter
+@Getter
+@ToString
+public class IntentDeleteEvent extends ApplicationEvent {
+ private String ownerName;
+ private Intent originalIntent;
+
+ public IntentDeleteEvent(Object source, String ownerName, Intent originalIntent) {
+ super(source);
+ this.ownerName= ownerName;
+ this.originalIntent = originalIntent;
+ }
+
+
+
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/listener/IntentEventListener.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/listener/IntentEventListener.java
new file mode 100644
index 0000000..045a75b
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/eventAndPublish/listener/IntentEventListener.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2023 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.intentanalysis.eventAndPublish.listener;
+
+import org.apache.commons.lang.StringUtils;
+import org.onap.usecaseui.intentanalysis.bean.models.Context;
+import org.onap.usecaseui.intentanalysis.bean.models.Intent;
+import org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord;
+import org.onap.usecaseui.intentanalysis.bean.models.IntentGoalBean;
+import org.onap.usecaseui.intentanalysis.eventAndPublish.event.IntentCreateEvent;
+import org.onap.usecaseui.intentanalysis.intentBaseService.intentEventRecord.IntentEventRecordService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.event.EventListener;
+import org.springframework.stereotype.Component;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+@Component
+public class IntentEventListener {
+ @Autowired
+ private IntentEventRecordService intentEventRecordService;
+
+ @EventListener
+ public void listenIntentCreateEvent(IntentCreateEvent intentCreateEvent){
+ String intentStatus = intentCreateEvent.getIntentStatus();//create status
+ IntentGoalBean intentGoalBean = intentCreateEvent.getIntentGoalBean();//current operate intent
+ Intent currentIntent = intentGoalBean.getIntent();
+ List<Context> owner_info = currentIntent.getIntentContexts().stream().filter(x ->
+ StringUtils.equals(x.getContextName(), "owner info")).collect(Collectors.toList());
+ List<Context> handler_info = currentIntent.getIntentContexts().stream().filter(x ->
+ StringUtils.equals(x.getContextName(), "handler info")).collect(Collectors.toList());
+ String owner = owner_info.get(0).getContextConditions().get(0).getConditionValue();
+ String handler = handler_info.get(0).getContextConditions().get(0).getConditionValue();
+
+ IntentEventRecord intentEventRecord = new IntentEventRecord();
+ intentEventRecord.setIntentId(currentIntent.getIntentId());
+ intentEventRecord.setIntentName(currentIntent.getIntentName());
+ intentEventRecord.setIntentStatus(intentStatus);
+ intentEventRecord.setOperateType(intentGoalBean.getIntentGoalType().name());
+ intentEventRecordService.createIntentEventRecord(intentEventRecord);
+ }
+}
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentEventRecord/IntentEventRecordService.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentEventRecord/IntentEventRecordService.java
new file mode 100644
index 0000000..454d6bd
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/intentBaseService/intentEventRecord/IntentEventRecordService.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2023 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.intentanalysis.intentBaseService.intentEventRecord;
+
+import org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord;
+import org.onap.usecaseui.intentanalysis.mapper.IntentEventRecordMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class IntentEventRecordService {
+ @Autowired
+ IntentEventRecordMapper intentEventRecordMapper;
+
+ // insert into record table
+ public void createIntentEventRecord(IntentEventRecord intentEventRecord){
+ intentEventRecordMapper.insertIntentRecord(intentEventRecord);
+
+ }
+ // get record by intent nameid, status
+ public IntentEventRecord getIntentEventRecordByntentId(String intentId,String operateType){
+ return intentEventRecordMapper.getIntentEventRecordByntentId(intentId,operateType);
+ }
+}
+
diff --git a/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentEventRecordMapper.java b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentEventRecordMapper.java
new file mode 100644
index 0000000..c5415aa
--- /dev/null
+++ b/intentanalysis/src/main/java/org/onap/usecaseui/intentanalysis/mapper/IntentEventRecordMapper.java
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2023 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.intentanalysis.mapper;
+
+import org.apache.ibatis.annotations.Param;
+import org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord;
+
+public interface IntentEventRecordMapper {
+ int insertIntentRecord(@Param(value = "intentEventRecord") IntentEventRecord intentEventRecord);
+
+ IntentEventRecord getIntentEventRecordByntentId(@Param(value = "intentId") String intentId,
+ @Param(value = "operateType") String operateType);
+}
diff --git a/intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml b/intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml
new file mode 100644
index 0000000..296fc43
--- /dev/null
+++ b/intentanalysis/src/main/resources/mybatis/sql/IntentEventRecordMapper.xml
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE mapper
+ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+ "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="org.onap.usecaseui.intentanalysis.mapper.IntentEventRecordMapper">
+
+ <insert id="insertIntentRecord">
+ insert into intent_Event_Record(intentId, intentName, intentStatus, operateType)
+ values(#{intentEventRecord.intentId}, #{intentEventRecord.intentName},
+ #{intentEventRecord.intentStatus},#{intentEventRecord.operateType})
+ </insert>
+
+
+ <select id="getIntentEventRecordByntentId" resultType="org.onap.usecaseui.intentanalysis.bean.models.IntentEventRecord">
+ select * from intent_Event_Record where intentId = #{intentId};
+ </select>
+</mapper>