aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-workflow-management/appc-workflow-management-core
diff options
context:
space:
mode:
authorAnand <ac204h@att.com>2018-01-04 19:35:51 -0500
committerSkip Wonnell <skip@att.com>2018-01-08 22:09:50 +0000
commit36bcd566167f2f91c0e8e7a304fce5f6bc150776 (patch)
tree7ba7acfee7e520da83a2b6286ea464285bc8cf67 /appc-dispatcher/appc-workflow-management/appc-workflow-management-core
parent38d293d605b42f88c9c82319ba848b4b81e45b64 (diff)
Include impacted changes for APPC-346,APPC-348
Issue-ID: APPC-347 Change-Id: I399bc2a1e0dfd481e103032a373bb80fce5baf41 Signed-off-by: Anand <ac204h@att.com>
Diffstat (limited to 'appc-dispatcher/appc-workflow-management/appc-workflow-management-core')
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/pom.xml101
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java158
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionRecorderServiceNotFoundException.java32
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/WorkflowManagerActivator.java49
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java311
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolver.java13
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/onap/appc/default.properties4
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkFlowManager.java189
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkflowActivator.java38
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/MockTransactionAbortedMarker.java52
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java225
-rw-r--r--appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/onap/appc/default.properties4
12 files changed, 778 insertions, 398 deletions
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/pom.xml b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/pom.xml
index 51ab9f95c..5e66580b1 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/pom.xml
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/pom.xml
@@ -1,62 +1,74 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<!--
+ ============LICENSE_START=======================================================
+ ONAP : APPC
+ ================================================================================
+ Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ ================================================================================
+ Copyright (C) 2017 Amdocs
+ =============================================================================
+ 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
- Licensed to the Apache Software Foundation (ASF) under one or more
- contributor license agreements. See the NOTICE file distributed with
- this work for additional information regarding copyright ownership.
- The ASF licenses this file to You 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.
- -->
+ 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.
+ ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ ============LICENSE_END=========================================================
+ -->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.appc</groupId>
- <artifactId>appc-workflow-management</artifactId>
- <version>1.3.0-SNAPSHOT</version>
- </parent>
+ <parent>
+ <groupId>org.onap.appc</groupId>
+ <artifactId>appc-workflow-management</artifactId>
+ <version>1.3.0-SNAPSHOT</version>
+ </parent>
+
<artifactId>appc-workflow-management-core</artifactId>
<packaging>bundle</packaging>
-
- <name>appc-workflow-management-core Bundle</name>
+ <name>APPC Workflow Management - Core</name>
<description>appc-workflow-management-core OSGi bundle project.</description>
+
<dependencies>
<dependency>
- <groupId>org.onap.appc</groupId>
- <artifactId>appc-common</artifactId>
- <version>${project.version}</version>
- </dependency>
+ <groupId>org.onap.appc</groupId>
+ <artifactId>appc-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.appc</groupId>
+ <artifactId>appc-data-access-lib</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.onap.appc</groupId>
+ <artifactId>appc-workflow-management-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
<dependency>
- <groupId>org.onap.appc</groupId>
- <artifactId>appc-data-access-lib</artifactId>
- <version>${project.version}</version>
+ <groupId>org.onap.appc</groupId>
+ <artifactId>appc-ranking-framework-lib</artifactId>
+ <version>${project.version}</version>
</dependency>
<dependency>
- <groupId>org.onap.appc</groupId>
- <artifactId>appc-workflow-management-api</artifactId>
- <version>${project.version}</version>
+ <groupId>equinoxSDK381</groupId>
+ <artifactId>org.eclipse.osgi</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
- <groupId>org.onap.appc</groupId>
- <artifactId>appc-ranking-framework-lib</artifactId>
- <version>${project.version}</version>
+ <groupId>org.onap.appc</groupId>
+ <artifactId>transaction-recorder</artifactId>
+ <version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>equinoxSDK381</groupId>
- <artifactId>org.eclipse.osgi</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
@@ -68,11 +80,14 @@
<instructions>
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
+ <Bundle-Activator>org.onap.appc.workflow.activator.WorkflowManagerActivator</Bundle-Activator>
<Embed-Dependency>javax.json;scope=compile|runtime;inline=false</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
<Export-Service>org.onap.appc.workflow.WorkFlowManager</Export-Service>
<Import-Package>
- org.onap.appc.workflow,org.onap.appc.workflow.objects, org.onap.appc.configuration,
+ org.onap.appc.transactionrecorder,org.onap.appc.transactionrecorder.objects,
+ org.onap.appc.workflow,org.onap.appc.workflow.objects,
+ org.onap.appc.configuration,
org.onap.appc.util,com.att.eelf.configuration, org.onap.appc.dao.util,
*;resolution:=optional
</Import-Package>
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java
new file mode 100644
index 000000000..6e061e15a
--- /dev/null
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionAbortedMarker.java
@@ -0,0 +1,158 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.workflow.activator;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.onap.appc.transactionrecorder.TransactionRecorder;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+import java.io.*;
+import java.util.UUID;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+public class TransactionAbortedMarker implements Runnable {
+
+ private ScheduledExecutorService executor = null;
+
+ public static final String PREFIX = "APPC";
+ public static final String SUFFIX = "VM";
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(TransactionAbortedMarker.class);
+
+ public TransactionAbortedMarker(ScheduledExecutorService executor){
+ this.executor = executor;
+ }
+
+ @Override
+ public void run() {
+ try {
+ TransactionRecorder recorder = lookupTransactionRecorder();
+
+ File newAppcInstanceIdFile = File.createTempFile(PREFIX, SUFFIX);
+ File parentDirectory = newAppcInstanceIdFile.getParentFile();
+ if (logger.isDebugEnabled()) {
+ logger.debug("New instance id file path" + newAppcInstanceIdFile.getAbsolutePath());
+ }
+
+ File[] allInstanceIdFiles = getAllInstanceIdFiles(parentDirectory);
+
+ if (allInstanceIdFiles.length > 0) {
+ File lastModifiedFile = getLastModifiedFile(allInstanceIdFiles);
+ if (logger.isDebugEnabled()) {
+ logger.debug("Last Modified File" + lastModifiedFile.getName());
+ }
+ String prevAppcInstanceId = readInstanceId(lastModifiedFile);
+ recorder.markTransactionsAborted(prevAppcInstanceId);
+ boolean isFileDeleted = lastModifiedFile.delete();
+ logger.debug("Previous file deleted " + isFileDeleted);
+ }
+ String newAppcInstanceId = writeNewInstanceId(newAppcInstanceIdFile);
+ recorder.setAppcInstanceId(newAppcInstanceId);
+ } catch (TransactionRecorderServiceNotFoundException e) {
+ logger.warn("Transaction Recorder Service Not Found, Next attempt after 30 seconds");
+ executor.schedule(this,30, TimeUnit.SECONDS);
+ } catch (Exception e) {
+ logger.error("Error on workflow manager bundle start-up" + e.getMessage(), e);
+ throw new RuntimeException(e);
+ }
+ }
+
+
+
+ protected TransactionRecorder lookupTransactionRecorder() throws TransactionRecorderServiceNotFoundException {
+ String message = null;
+ BundleContext bctx = FrameworkUtil.getBundle(TransactionRecorder.class).getBundleContext();
+ if(bctx!=null){
+ ServiceReference sref= bctx.getServiceReference(TransactionRecorder.class.getName());
+ TransactionRecorder transactionRecorder;
+ if (sref != null) {
+ transactionRecorder = (TransactionRecorder) bctx.getService(sref);
+ if (transactionRecorder != null) {
+ return transactionRecorder;
+ }
+ }
+ }
+ message = "Cannot find service org.onap.appc.transactionrecorder.TransactionRecorder";
+ logger.warn(message);
+ throw new TransactionRecorderServiceNotFoundException(message);
+ }
+
+ private String writeNewInstanceId(File newInstanceIdFile) throws IOException {
+ String newAppcInstanceId = UUID.randomUUID().toString();
+ try (FileWriter writer = new FileWriter(newInstanceIdFile)) {
+ writer.write(newAppcInstanceId);
+ }
+ catch (IOException e){
+ String message = "Error writing appc-instance-id";
+ logger.error(message,e);
+ throw new RuntimeException(message);
+ }
+ logger.debug("new appc-instance-id = " + newAppcInstanceId);
+ return newAppcInstanceId;
+ }
+
+ private String readInstanceId(File lastModifiedFile) {
+ String prevAppcInstanceId = null;
+ BufferedReader buffReader;
+ try (FileReader reader = new FileReader(lastModifiedFile)) {
+ buffReader = new BufferedReader(reader);
+ prevAppcInstanceId = buffReader.readLine();
+ }
+ catch (IOException e){
+ String message ="Error reading previous appc-instance-id";
+ logger.error(message,e);
+ throw new RuntimeException(message);
+ }
+ logger.debug("previous appc-instance-id " + prevAppcInstanceId);
+ return prevAppcInstanceId;
+ }
+
+ private File[] getAllInstanceIdFiles(File directory) {
+ return directory.listFiles(pathname -> {
+ if (pathname.getName().startsWith(PREFIX)
+ && pathname.getName().endsWith(SUFFIX)
+ && pathname.length()>0)
+ return true;
+ return false;
+ });
+ }
+
+ private File getLastModifiedFile(File[] allInstanceIdFiles) {
+ File lastModifiedFile = allInstanceIdFiles[0];
+ long lastModified = allInstanceIdFiles[0].lastModified();
+ for(File file:allInstanceIdFiles){
+ if(file.lastModified() > lastModified){
+ lastModified = file.lastModified();
+ lastModifiedFile = file;
+ }
+ }
+ return lastModifiedFile;
+ }
+}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionRecorderServiceNotFoundException.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionRecorderServiceNotFoundException.java
new file mode 100644
index 000000000..f8b0a8426
--- /dev/null
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/TransactionRecorderServiceNotFoundException.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.workflow.activator;
+
+public class TransactionRecorderServiceNotFoundException extends Exception {
+
+ public TransactionRecorderServiceNotFoundException(String message){
+ super(message);
+ }
+}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/WorkflowManagerActivator.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/WorkflowManagerActivator.java
new file mode 100644
index 000000000..b91a8f7ed
--- /dev/null
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/activator/WorkflowManagerActivator.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.workflow.activator;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+public class WorkflowManagerActivator implements BundleActivator{
+
+ private ScheduledExecutorService executor = null;
+
+ @Override
+ public void start(BundleContext bundleContext) {
+ executor = Executors.newSingleThreadScheduledExecutor();
+ TransactionAbortedMarker runnable = new TransactionAbortedMarker(executor);
+ executor.schedule(runnable, 30, TimeUnit.SECONDS);
+ }
+
+ @Override
+ public void stop(BundleContext bundleContext) throws Exception {
+ executor.shutdown();
+ }
+}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
index ceae5677c..483668031 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java
@@ -31,7 +31,6 @@ import org.onap.appc.configuration.Configuration;
import org.onap.appc.configuration.ConfigurationFactory;
import org.onap.appc.domainmodel.lcm.RequestContext;
import org.onap.appc.domainmodel.lcm.ResponseContext;
-import org.onap.appc.domainmodel.lcm.Status;
import org.onap.appc.util.ObjectMapper;
import org.onap.appc.workflow.WorkFlowManager;
import org.onap.appc.workflow.objects.WorkflowExistsOutput;
@@ -43,71 +42,74 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
import java.text.SimpleDateFormat;
-import java.util.Date;
+import java.util.Arrays;
import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;
public class WorkFlowManagerImpl implements WorkFlowManager{
- private SvcLogicService svcLogic = null;
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(WorkFlowManagerImpl.class);
- private static final Configuration configuration = ConfigurationFactory.getConfiguration();
-
- private final WorkflowResolver workflowResolver = new WorkflowResolver(
- configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300)
- );
-
- public void setSvcLogicServiceRef(SvcLogicService svcLogic) {
- this.svcLogic = svcLogic;
- }
-
- /**
- * Execute workflow and return response.
- * This method execute workflow with following steps.
- * Retrieve workflow(DG) details - module, version and mode from database based on command and vnf Type from incoming request.
- * Execute workflow (DG) using SVC Logic Service reference
- * Return response of workflow (DG) to caller.
+ private SvcLogicService svcLogic = null;
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(WorkFlowManagerImpl.class);
+ private final Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ private WorkflowResolver workflowResolver = new WorkflowResolver(
+ configuration.getIntegerProperty("org.onap.appc.workflow.resolver.refresh_interval", 300)
+ );
+
+ public void setWorkflowResolver(WorkflowResolver workflowResolver){
+ this.workflowResolver=workflowResolver;
+ }
+
+ public void setSvcLogicServiceRef(SvcLogicService svcLogic) {
+ this.svcLogic = svcLogic;
+ }
+
+ /**
+ * Execute workflow and return response.
+ * This method execute workflow with following steps.
+ * Retrieve workflow(DG) details - module, version and mode from database based on command and vnf Type from incoming request.
+ * Execute workflow (DG) using SVC Logic Service reference
+ * Return response of workflow (DG) to caller.
*
- * @param workflowRequest workflow execution request which contains vnfType, command, requestId, targetId, payload and (optional) confID;
- * @return Workflow Response which contains execution status and payload from DG if any
- */
-
- @Override
- public WorkflowResponse executeWorkflow(WorkflowRequest workflowRequest) {
- if (logger.isTraceEnabled()) {
- logger.trace("Entering to executeWorkflow with WorkflowRequest = "+ ObjectUtils.toString(workflowRequest.toString()));
- }
- WorkflowResponse workflowResponse = new WorkflowResponse();
+ * @param workflowRequest workflow execution request which contains vnfType, command, requestId, targetId, payload and (optional) confID;
+ * @return Workflow Response which contains execution status and payload from DG if any
+ */
+
+ @Override
+ public WorkflowResponse executeWorkflow(WorkflowRequest workflowRequest) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to executeWorkflow with WorkflowRequest = "+ ObjectUtils.toString(workflowRequest.toString()));
+ }
+ WorkflowResponse workflowResponse = new WorkflowResponse();
workflowResponse.setResponseContext(workflowRequest.getResponseContext());
- try {
+ try {
WorkflowKey workflowKey = workflowResolver.resolve(workflowRequest.getRequestContext().getAction().name(), workflowRequest.getVnfContext().getType(), null,workflowRequest.getRequestContext().getCommonHeader().getApiVer());
- Properties workflowParams = new Properties();
- String actionProperty = null;
- String requestIdProperty=null;
- String vfIdProperty =null;
+ Properties workflowParams = new Properties();
+ String actionProperty;
+ String requestIdProperty;
+ String vfIdProperty;
if(!workflowRequest.getRequestContext().getCommonHeader().getApiVer().startsWith("1.")){
- /*
- The following method call (populateDGContext) populates DG context with the
- request parameters to maintain backward compatibility with old DGs,
- we are not altering the old way of passing (org.onap.appc.vnfId and so on..)
- This is still a temporary solution, the end solution should be agreed with
- all stakeholders and implemented.
- */
- populateDGContext(workflowParams,workflowRequest);
+ /*
+ The following method call (populateDGContext) populates DG context with the
+ request parameters to maintain backward compatibility with old DGs,
+ we are not altering the old way of passing (org.onap.appc.vnfId and so on..)
+ This is still a temporary solution, the end solution should be agreed with
+ all stakeholders and implemented.
+ */
+ populateDGContext(workflowParams,workflowRequest);
} else {
- actionProperty = configuration.getProperty("org.onap.appc.workflow.action", String.valueOf(Constants.ACTION));
- requestIdProperty = configuration.getProperty("org.onap.appc.workflow.request.id", String.valueOf(Constants.REQUEST_ID));
- vfIdProperty = configuration.getProperty("org.onap.appc.workflow.vfid", String.valueOf(Constants.VF_ID));
- String payloadProperty = configuration.getProperty("org.onap.appc.workflow.payload", String.valueOf(Constants.PAYLOAD));
- String vfTypeProperty = configuration.getProperty("org.onap.appc.workflow.vftype", String.valueOf(Constants.VF_TYPE));
- String apiVerProperty = configuration.getProperty("org.onap.appc.workflow.apiVersion", String.valueOf(Constants.API_VERSION));
- String originatorIdProperty = configuration.getProperty("org.onap.appc.workflow.originatorId",Constants.ORIGINATOR_ID);
- String subRequestId = configuration.getProperty("org.onap.appc.workflow.subRequestId",Constants.SUB_REQUEST_ID);
+ actionProperty = configuration.getProperty("org.onap.appc.workflow.action", String.valueOf(Constants.ACTION));
+ requestIdProperty = configuration.getProperty("org.onap.appc.workflow.request.id", String.valueOf(Constants.REQUEST_ID));
+ vfIdProperty = configuration.getProperty("org.onap.appc.workflow.vfid", String.valueOf(Constants.VF_ID));
+ String vfTypeProperty = configuration.getProperty("org.onap.appc.workflow.vftype", String.valueOf(Constants.VF_TYPE));
+ String apiVerProperty = configuration.getProperty("org.onap.appc.workflow.apiVersion", String.valueOf(Constants.API_VERSION));
+ String originatorIdProperty = configuration.getProperty("org.onap.appc.workflow.originatorId",Constants.ORIGINATOR_ID);
+ String subRequestId = configuration.getProperty("org.onap.appc.workflow.subRequestId",Constants.SUB_REQUEST_ID);
workflowParams.put(actionProperty,workflowRequest.getRequestContext().getAction().name());
workflowParams.put(requestIdProperty, workflowRequest.getRequestContext().getCommonHeader().getRequestId());
@@ -118,33 +120,33 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
workflowParams.put(subRequestId,workflowRequest.getRequestContext().getCommonHeader().getSubRequestId());
Object payloadJson = workflowRequest.getRequestContext().getPayload();
- if(payloadJson!=null) {
- try {
- Map<String, String> payloadProperties = ObjectMapper.map(payloadJson);
- workflowParams.putAll(payloadProperties);
-
- if (logger.isDebugEnabled()) {
- logger.debug("DG properties: " + workflowParams);
- }
- } catch (Exception e) {
- logger.error("Error parsing payload json string", e);
- Properties workflowPrp = new Properties();
- workflowPrp.setProperty("error-message", "Error parsing payload json string");
+ if(payloadJson!=null) {
+ try {
+ Map<String, String> payloadProperties = ObjectMapper.map(payloadJson);
+ workflowParams.putAll(payloadProperties);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("DG properties: " + workflowParams);
+ }
+ } catch (Exception e) {
+ logger.error("Error parsing payload json string", e);
+ Properties workflowPrp = new Properties();
+ workflowPrp.setProperty("error-message", "Error parsing payload json string");
fillStatus(501, "Error parsing payload json string: "+e.getMessage(), workflowRequest.getResponseContext());
- if (logger.isTraceEnabled()) {
- logger.trace("Exiting from executeWorkflow with (workflowResponse = "+ObjectUtils.toString(workflowResponse)+")");
- }
- return workflowResponse;
- }
- }
- if (logger.isDebugEnabled()) {
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exiting from executeWorkflow with (workflowResponse = "+ObjectUtils.toString(workflowResponse)+")");
+ }
+ return workflowResponse;
+ }
+ }
+ if (logger.isDebugEnabled()) {
logger.debug("DG parameters "+ actionProperty +":"+ workflowRequest.getRequestContext().getAction().name()+", "+
requestIdProperty +":"+ workflowRequest.getRequestContext().getCommonHeader().getRequestId()+", "+
vfIdProperty +":"+ workflowRequest.getVnfContext().getId());
logger.debug("Starting DG Execution for request "+workflowRequest.getRequestContext().getCommonHeader().getRequestId());
- }
- }
+ }
+ }
if (workflowRequest.getRequestContext().getCommonHeader().getApiVer().startsWith("1.")){
workflowParams.put("isBwcMode","true");
} else {
@@ -152,21 +154,21 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
}
SVCLogicServiceExecute(workflowKey, workflowRequest.getRequestContext(), workflowParams , workflowResponse);
- if (logger.isTraceEnabled()) {
+ if (logger.isTraceEnabled()) {
logger.trace("Completed DG Execution for Request id: " + workflowRequest.getRequestContext().getCommonHeader().getRequestId() + "with response code: " + workflowResponse.getResponseContext().getStatus().getCode());
- }
- }catch (Exception e){
- logger.error("Error Executing DG " +e.getMessage());
+ }
+ }catch (Exception e){
+ logger.error("Error Executing DG " +e.getMessage(),e);
fillStatus(501, "Error Executing DG "+e.getMessage(), workflowRequest.getResponseContext());
- }
- if (logger.isTraceEnabled()) {
+ }
+ if (logger.isTraceEnabled()) {
logger.trace("Exiting from executeWorkflow with (workflowResponse = "+ ObjectUtils.toString(workflowResponse.getResponseContext().getStatus().getMessage())+")");
- }
- return workflowResponse;
- }
+ }
+ return workflowResponse;
+ }
- private void populateDGContext(Properties workflowParams, WorkflowRequest workflowRequest) {
- workflowParams.put("input.common-header.timestamp",new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(Date.from(workflowRequest.getRequestContext().getCommonHeader().getTimeStamp())));
+ private void populateDGContext(Properties workflowParams, WorkflowRequest workflowRequest) {
+ workflowParams.put("input.common-header.timestamp",new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(workflowRequest.getRequestContext().getCommonHeader().getTimeStamp()));
workflowParams.put("input.common-header.api-ver",workflowRequest.getRequestContext().getCommonHeader().getApiVer());
workflowParams.put("input.common-header.request-id",workflowRequest.getRequestContext().getCommonHeader().getRequestId());
workflowParams.put("input.common-header.originator-id",workflowRequest.getRequestContext().getCommonHeader().getOriginatorId());
@@ -176,86 +178,86 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
workflowParams.put("input.action-identifiers.vnf-id",workflowRequest.getVnfContext().getId());
workflowParams.put("input.action-identifiers.vnfc-name",workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getVnfcName():"");
workflowParams.put("input.action-identifiers.service-instance-id",workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getServiceInstanceId():"");
- workflowParams.put("input.action-identifiers.vf-module-id",workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId():"");
- workflowParams.put("input.action-identifiers.vserver-id",workflowRequest.getRequestContext().getActionIdentifiers().getVserverId()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getVserverId():"");
+ workflowParams.put("input.action-identifiers.vserver-id",workflowRequest.getRequestContext().getActionIdentifiers().getVserverId()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getVserverId():"");
+ workflowParams.put("input.action-identifiers.vf-module-id",workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId()!=null?workflowRequest.getRequestContext().getActionIdentifiers().getVfModuleId():"");
final Map<String, String> additionalContext;
if ((additionalContext = workflowRequest.getRequestContext().getAdditionalContext())!=null) {
for (Map.Entry<String, String> entry : additionalContext.entrySet()) {
workflowParams.put("input." + entry.getKey(), null != entry.getValue() ? entry.getValue() : "");
- }
+ }
}
}
- /**
- * Check if workflow (DG) exists in database
+ /**
+ * Check if workflow (DG) exists in database
*
- * @param workflowQueryParams workflow request with command and vnf Type
- * @return True if workflow exists else False.
- */
- @Override
- public WorkflowExistsOutput workflowExists(WorkflowRequest workflowQueryParams) {
- WorkflowExistsOutput workflowExistsOutput = new WorkflowExistsOutput(false,false);
- if (logger.isTraceEnabled()) {
- logger.trace("Entering to workflowExists with WorkflowRequest = "+ObjectUtils.toString(workflowQueryParams.toString()));
- }
-
- try {
+ * @param workflowQueryParams workflow request with command and vnf Type
+ * @return True if workflow exists else False.
+ */
+ @Override
+ public WorkflowExistsOutput workflowExists(WorkflowRequest workflowQueryParams) {
+ WorkflowExistsOutput workflowExistsOutput = new WorkflowExistsOutput(false,false);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to workflowExists with WorkflowRequest = "+ObjectUtils.toString(workflowQueryParams.toString()));
+ }
+
+ try {
WorkflowKey workflowKey = workflowResolver.resolve(
workflowQueryParams.getRequestContext().getAction().name(),
workflowQueryParams.getVnfContext().getType(),
workflowQueryParams.getVnfContext().getVersion(),
workflowQueryParams.getRequestContext().getCommonHeader().getApiVer());
- if (workflowKey != null) {
- workflowExistsOutput.setMappingExist(true);
- workflowExistsOutput.setWorkflowModule(workflowKey.module());
- workflowExistsOutput.setWorkflowName(workflowKey.name());
- workflowExistsOutput.setWorkflowVersion(workflowKey.version());
- if (isDGExists(workflowKey)) {
- workflowExistsOutput.setDgExist(true);
- }else{
- logger.warn(
- String.format("SLI doesn't have DG for resolved mapping entry: DG module - '%s', DG name - '%s', DG version - '%s'",
- workflowKey.module(), workflowKey.name(), workflowKey.version()));
- }
- }else{
- logger.warn(
- String.format("Unable to resolve recipe matching action '%s', VNF type '%s' and VNF version '%s'",
+ if (workflowKey != null) {
+ workflowExistsOutput.setMappingExist(true);
+ workflowExistsOutput.setWorkflowModule(workflowKey.module());
+ workflowExistsOutput.setWorkflowName(workflowKey.name());
+ workflowExistsOutput.setWorkflowVersion(workflowKey.version());
+ if (isDGExists(workflowKey)) {
+ workflowExistsOutput.setDgExist(true);
+ }else{
+ logger.warn(
+ String.format("SLI doesn't have DG for resolved mapping entry: DG module - '%s', DG name - '%s', DG version - '%s'",
+ workflowKey.module(), workflowKey.name(), workflowKey.version()));
+ }
+ }else{
+ logger.warn(
+ String.format("Unable to resolve recipe matching action '%s', VNF type '%s' and VNF version '%s'",
workflowQueryParams.getRequestContext().getAction().name(), workflowQueryParams.getVnfContext().getType(), null));
- }
- } catch (RuntimeException e) {
- logger.error("Error querying workflow from database"+e.getMessage());
- throw e;
- }catch (SvcLogicException e) {
- logger.error("Error querying workflow from database"+e.getMessage());
- throw new RuntimeException(e);
- }
- if (logger.isTraceEnabled()) {
- logger.trace("Exiting workflowExists");
- }
- return workflowExistsOutput;
- }
-
-
- private boolean isDGExists(WorkflowKey workflowKey) throws SvcLogicException {
- return svcLogic.hasGraph(workflowKey.module(), workflowKey.name(), workflowKey.version(), "sync");
- }
+ }
+ } catch (RuntimeException e) {
+ logger.error("Error querying workflow from database"+e.getMessage());
+ throw e;
+ }catch (SvcLogicException e) {
+ logger.error("Error querying workflow from database"+e.getMessage());
+ throw new RuntimeException(e);
+ }
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exiting workflowExists");
+ }
+ return workflowExistsOutput;
+ }
+
+
+ private boolean isDGExists(WorkflowKey workflowKey) throws SvcLogicException {
+ return svcLogic.hasGraph(workflowKey.module(), workflowKey.name(), workflowKey.version(), "sync");
+ }
private void SVCLogicServiceExecute(WorkflowKey workflowKey, RequestContext requestContext, Properties workflowParams, WorkflowResponse workflowResponse) {
- if (logger.isTraceEnabled()) {
- logger.trace("Entering SVCLogicServiceExecute");
- }
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering SVCLogicServiceExecute");
+ }
Properties respProps = null;
- try {
+ try {
respProps = svcLogic.execute(workflowKey.module(), workflowKey.name(), workflowKey.version(), "sync", workflowParams);
} catch (Exception e) {
setWorkFlowResponseStatus(workflowResponse.getResponseContext(), "failure", "Unexpected SLI Adapter failure", 200);
- if (logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("Error while executing DG " + e.getMessage() + e.getStackTrace());
}
- logger.error("Error in DG", e.getMessage()+e.getStackTrace().toString());
+ logger.error("Error in DG", e.getMessage()+ Arrays.toString(e.getStackTrace()),e);
}
if (respProps != null) {
@@ -269,19 +271,19 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
int specificStatusCode = 0;
if (dgOutputStatusCode != null) {
specificStatusCode = Integer.parseInt(dgOutputStatusCode);
- }
+ }
setWorkFlowResponseStatus(workflowResponse.getResponseContext(), commonStatus, specificStatusMessage, specificStatusCode);
- if (logger.isDebugEnabled()) {
+ if (logger.isDebugEnabled()) {
logger.debug("DG Execution Status: " + commonStatus);
- }
- }
+ }
+ }
- if (logger.isTraceEnabled()) {
- logger.trace("Exiting from SVCLogicServiceExecute");
- }
- }
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exiting from SVCLogicServiceExecute");
+ }
+ }
/**
* Filling response context by output.* fields from DG context. Works only for 2.* API version
@@ -301,7 +303,7 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
responseContext.setPayload(respProps.getProperty(key));
} else {
responseContext.addKeyValueToAdditionalContext(key, respProps.getProperty(key));
- }
+ }
}
}
}
@@ -316,22 +318,21 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
* @param specificStatusCode specific status code from specific DG node
*/
private void setWorkFlowResponseStatus(ResponseContext responseContext, String commonStatus, String specificStatusMessage, int specificStatusCode) {
- if (null == specificStatusMessage) { specificStatusMessage = ""; }
- if (commonStatus.equalsIgnoreCase(Constants.DG_STATUS_SUCCESS)){
- if (specificStatusCode != 0 ){
+ if (null == specificStatusMessage) { specificStatusMessage = ""; }
+ if (commonStatus.equalsIgnoreCase(Constants.DG_STATUS_SUCCESS)){
+ if (specificStatusCode != 0 ){
fillStatus(specificStatusCode, specificStatusMessage, responseContext);
} else {
fillStatus(400, commonStatus, responseContext);
}
} else {
- String errorMsg = StringUtils.isEmpty(specificStatusMessage) ? "DG execution failure" : specificStatusMessage;
if (specificStatusCode != 0){
fillStatus(specificStatusCode, specificStatusMessage, responseContext);
} else {
fillStatus(401, specificStatusMessage, responseContext);
}
- }
- }
+ }
+ }
/**
* filling responseContext by status code and status message
@@ -341,7 +342,9 @@ public class WorkFlowManagerImpl implements WorkFlowManager{
* @param responceContext response context which will be store status code and status message
*/
private void fillStatus(int code, String message, ResponseContext responceContext) {
- responceContext.setStatus(new Status(code, message));
+ responceContext.getStatus().setCode(code);
+ responceContext.getStatus().setMessage(message);
}
+
}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolver.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolver.java
index 1f4a5b406..3dabb5404 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolver.java
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolver.java
@@ -33,17 +33,17 @@ import com.att.eelf.configuration.EELFManager;
class WorkflowResolver {
- private static final EELFLogger logger = EELFManager.getInstance().getLogger(WorkFlowManagerImpl.class);
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(WorkFlowManagerImpl.class);
private long interval;
- private volatile long lastUpdate = 0l;
+ private volatile long lastUpdate = 0L;
private volatile boolean isUpdateInProgress = false;
private volatile RankedAttributesResolver<WorkflowKey> dgResolver;
private final ReentrantLock INIT_LOCK = new ReentrantLock();
- WorkflowResolver(long interval) {
+ WorkflowResolver(int interval) {
this.interval = interval * 1000;
}
@@ -96,8 +96,7 @@ class WorkflowResolver {
logger.info("DG resolver configuration data has expired - initiating refresh");
try {
- RankedAttributesResolver<WorkflowKey> temp = createResolver();
- dgResolver = temp;
+ dgResolver = createResolver();
lastUpdate = System.currentTimeMillis();
logger.info("DG resolver configuration data has been refreshed successfully");
@@ -135,8 +134,6 @@ class WorkflowResolver {
}
};
- WorkflowKey wfKey = resolver().resolve(context);
-
- return wfKey;
+ return resolver().resolve(context);
}
}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/onap/appc/default.properties b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/onap/appc/default.properties
index 3dd30a87b..fce3e2122 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/onap/appc/default.properties
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/onap/appc/default.properties
@@ -33,8 +33,8 @@ appc.LCM.poolMembers=<DMAAP_IP>:3904
appc.LCM.service=dmaap
appc.LCM.topic.write=APPC-TEST2
appc.LCM.client.name=APPC-TEST-CLIENT-WF-MGMT-MAIN
-appc.LCM.provider.user=test
-appc.LCM.provider.pass=test
+appc.LCM.provider.user=admin
+appc.LCM.provider.pass=admin
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkFlowManager.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkFlowManager.java
deleted file mode 100644
index 74828a5d2..000000000
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkFlowManager.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP : APPC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Copyright (C) 2017 Amdocs
- * =============================================================================
- * 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.
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.appc.workflow;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.onap.appc.workflow.impl.WorkFlowManagerImpl;
-import org.onap.appc.workflow.objects.WorkflowRequest;
-import org.onap.ccsdk.sli.core.sli.SvcLogicException;
-import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
-import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
-import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
-import org.onap.ccsdk.sli.core.sli.provider.SvcLogicActivator;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.ServiceReference;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest( {SvcLogicActivator.class, FrameworkUtil.class, WorkFlowManagerImpl.class} )
-public class TestWorkFlowManager {
- public TestWorkFlowManager() {
- }
-
- private WorkFlowManagerImpl workflowManger ;
- private String command="Configure";
- protected SvcLogicGraph svcLogicGraph=null;
-
-
- //
- private final SvcLogicStore svcLogicStore= Mockito.mock(SvcLogicStore.class);
- private final BundleContext bundleContext=Mockito.mock(BundleContext.class);
- private final Bundle bundleSvcLogicService=Mockito.mock(Bundle.class);
- private final ServiceReference serviceReferenceSvcLogicService=Mockito.mock(ServiceReference.class);
-
-
-
- @Before
- public void setupMock() throws Exception {
- /*
- // DAO Mock
- dao = Mockito.mock(AppcDAOImpl.class);
- PowerMockito.whenNew(AppcDAOImpl.class).withNoArguments().thenReturn(dao);
-
- // SVC Logic Mock
- SvcLogicServiceImpl svcLogicService=new SvcLogicServiceImpl();
- PowerMockito.mockStatic(SvcLogicActivator.class);
- PowerMockito.mockStatic(FrameworkUtil.class);
- PowerMockito.when(SvcLogicActivator.getStore()).thenReturn(svcLogicStore);
- PowerMockito.when(FrameworkUtil.getBundle(SvcLogicService.class)).thenReturn(bundleSvcLogicService);
- PowerMockito.when(bundleSvcLogicService.getBundleContext()).thenReturn(bundleContext);
- PowerMockito.when(bundleContext.getServiceReference(SvcLogicService.NAME)).thenReturn(serviceReferenceSvcLogicService);
- PowerMockito.when(bundleContext.getService(serviceReferenceSvcLogicService)).thenReturn(svcLogicService);
-
- try {
- PowerMockito.when(svcLogicStore.fetch(anyString(), eq("FIREWALL_Configure"), anyString(), anyString())).thenReturn(createGraph("FIREWALL_Configure"));
- PowerMockito.when(svcLogicStore.fetch(anyString(), eq("FIREWALL_Restart"), anyString(), anyString())).thenReturn(createGraph("FIREWALL_Restart"));
- PowerMockito.when(svcLogicStore.fetch(anyString(), eq("FIREWALL_Test"), anyString(), anyString())).thenReturn(createGraph("FIREWALL_Test"));
- PowerMockito.when(svcLogicStore.fetch(anyString(), eq("FIREWALL_Rebuild"), anyString(), anyString())).thenReturn(createGraph("FIREWALL_Rebuild"));
- PowerMockito.when(svcLogicStore.fetch(anyString(), eq("FIREWALL_Terminate"), anyString(), anyString())).thenReturn(createGraph("FIREWALL_Terminate"));
- PowerMockito.when(svcLogicStore.fetch(anyString(), eq("FIREWALL_Start"), anyString(), anyString())).thenReturn(createGraph("FIREWALL_Start"));
- svcLogicService.registerExecutor("switch", new SwitchNodeExecutor());
- svcLogicService.registerExecutor("execute",new ReturnNodeExecutor());
- svcLogicService.registerExecutor("return",new ReturnNodeExecutor());
- } catch (SvcLogicException e) {
- e.printStackTrace();
- }
-
- workflowManger = new WorkFlowManagerImpl();
-
- PowerMockito.when(getDao().retrieveWorkflowDetails("FIREWALL","Configure")).thenReturn(getWorkflow());
- PowerMockito.when(getDao().retrieveWorkflowDetails("FIREWALL","")).thenThrow(new DAOException());
- PowerMockito.when(getDao().retrieveWorkflowDetails("","Configure")).thenThrow(new DAOException());
- */
- }
-
- @Test
- public void testEmptyVnfTypeFlow(){
- /*
- WorkflowRequest workflowRequest = getWorkflowRequest("","1","1",command);
- setSvcLogicGraph(createGraph(""+"_"+command));
- WorkflowResponse response =workflowManger.executeWorkflow(workflowRequest);
- assertFalse(response.isExecutionSuccess());
- */
- }
-
- /*
- @Test
- public void testExecuteWorkflow(){
- //PowerMockito.when(getDao().retrieveWorkflowDetails(anyString(),anyString())).thenReturn(getWorkflow());
- WorkflowRequest workflowRequest = getWorkflowRequest("FIREWALL","1","1",command);
- setSvcLogicGraph(createGraph("FIREWALL"+"_"+command));
- WorkflowResponse response =workflowManger.executeWorkflow(workflowRequest);
- assertFalse(response.isExecutionSuccess());
- }
-
- @Test
- public void testExecuteWorkflowEmptyPayload(){
- //PowerMockito.when(getDao().retrieveWorkflowDetails(anyString(),anyString())).thenReturn(getWorkflow());
- WorkflowRequest workflowRequest = getWorkflowRequest("FIREWALL","1","1",command);
- workflowRequest.setPayload("{payload:\"payload\"}");
- setSvcLogicGraph(createGraph(""+"_"+command));
- WorkflowResponse response =workflowManger.executeWorkflow(workflowRequest);
- assertFalse(response.isExecutionSuccess());
- }
-
- @Test
- public void testWorkflowExist(){
- //PowerMockito.when(getDao().queryWorkflow(anyString(),anyString())).thenReturn(true);
- WorkflowRequest workflowRequest = getWorkflowRequest("FIREWALL","1","1",command);
- boolean success = workflowManger.workflowExists(workflowRequest);
- assertTrue(success);
- }
-
- @Test
- public void testWorkflowExistFalse(){
- //PowerMockito.when(getDao().queryWorkflow(anyString(),anyString())).thenReturn(false);
- WorkflowRequest workflowRequest = getWorkflowRequest("FIREWALL","1","1",command);
- setSvcLogicGraph(createGraph(""+"_"+command));
- boolean success = workflowManger.workflowExists(workflowRequest);
- assertFalse(success);
- }
-
-
- @Test
- public void testEmptyCommandFlow(){
- WorkflowRequest workflowRequest = getWorkflowRequest("FIREWALL","1","1","");
- WorkflowResponse response =workflowManger.executeWorkflow(workflowRequest);
- assertFalse(response.isExecutionSuccess());
- }
- */
-
-
- public void setSvcLogicGraph(SvcLogicGraph svcLogicGraph) {
- this.svcLogicGraph = svcLogicGraph;
- }
-
- public SvcLogicGraph getSvcLogicGraph() {
- return svcLogicGraph;
- }
-
- protected SvcLogicGraph createGraph(String rpc) {
- SvcLogicGraph svcLogicGraph = new SvcLogicGraph();
- svcLogicGraph.setModule("APPC");
- svcLogicGraph.setRpc(rpc);
- svcLogicGraph.setMode("sync");
- svcLogicGraph.setVersion("2.0.0");
- SvcLogicNode svcLogicRootNode = new SvcLogicNode(1, "switch", svcLogicGraph);
- SvcLogicNode svcLogicConfigureNode = new SvcLogicNode(2, "return", svcLogicGraph);
- SvcLogicNode svcLogicOtherNode = new SvcLogicNode(3, "return", svcLogicGraph);
- try {
- svcLogicConfigureNode.setAttribute("status", "success");
- svcLogicOtherNode.setAttribute("status", "failure");
- svcLogicRootNode.setAttribute("test", "$org.onap.appc.action");
- svcLogicRootNode.addOutcome("Configure", svcLogicConfigureNode);
- svcLogicRootNode.addOutcome("Other", svcLogicOtherNode);
- } catch (SvcLogicException e) {
- e.printStackTrace();
- }
- svcLogicGraph.setRootNode(svcLogicRootNode);
- return svcLogicGraph;
- }
-}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkflowActivator.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkflowActivator.java
new file mode 100644
index 000000000..c70bec446
--- /dev/null
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkflowActivator.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.workflow;
+
+import org.junit.Test;
+import org.onap.appc.workflow.impl.MockTransactionAbortedMarker;
+
+public class TestWorkflowActivator {
+
+ @Test
+ public void testActivator(){
+ MockTransactionAbortedMarker mockTransactionAbortedMarker = new MockTransactionAbortedMarker(null);
+ mockTransactionAbortedMarker.run();
+ }
+
+}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/MockTransactionAbortedMarker.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/MockTransactionAbortedMarker.java
new file mode 100644
index 000000000..eb8710515
--- /dev/null
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/MockTransactionAbortedMarker.java
@@ -0,0 +1,52 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.workflow.impl;
+
+import org.junit.Assert;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.onap.appc.transactionrecorder.TransactionRecorder;
+import org.onap.appc.workflow.activator.TransactionAbortedMarker;
+
+import java.util.concurrent.ScheduledExecutorService;
+
+public class MockTransactionAbortedMarker extends TransactionAbortedMarker{
+
+ public MockTransactionAbortedMarker(ScheduledExecutorService executor){
+ super(executor);
+ }
+
+ @Override
+ public TransactionRecorder lookupTransactionRecorder(){
+ TransactionRecorder transactionRecorder = Mockito.mock(TransactionRecorder.class);
+ Mockito.doNothing().when(transactionRecorder).markTransactionsAborted(Matchers.anyString());
+ Mockito.doAnswer((InvocationOnMock invocationOnMock) -> {
+ Assert.assertNotNull(invocationOnMock.getArguments()[0]);
+ return null;
+ }).when(transactionRecorder).setAppcInstanceId(Matchers.anyString());
+ return transactionRecorder;
+ }
+}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
new file mode 100644
index 000000000..af7005365
--- /dev/null
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/impl/TestWorkFlowManager.java
@@ -0,0 +1,225 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * 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.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.workflow.impl;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mockito;
+import org.onap.appc.domainmodel.lcm.*;
+import org.onap.appc.workflow.impl.WorkFlowManagerImpl;
+import org.onap.appc.workflow.impl.WorkflowKey;
+import org.onap.appc.workflow.impl.WorkflowResolver;
+import org.onap.appc.workflow.objects.WorkflowExistsOutput;
+import org.onap.appc.workflow.objects.WorkflowRequest;
+import org.onap.appc.workflow.objects.WorkflowResponse;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
+import org.onap.ccsdk.sli.core.sli.SvcLogicNode;
+import org.onap.ccsdk.sli.core.sli.SvcLogicStore;
+import org.onap.ccsdk.sli.core.sli.provider.SvcLogicActivator;
+import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
+import org.osgi.framework.Bundle;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+import java.util.Date;
+import java.util.Properties;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest( { WorkflowResolver.class,WorkFlowManagerImpl.class} )
+public class TestWorkFlowManager {
+ public TestWorkFlowManager() {
+ }
+
+ @InjectMocks
+ public WorkFlowManagerImpl workflowManger;
+
+ WorkflowResolver workflowResolver;
+ public SvcLogicService svcLogicService;
+
+ @Before
+ public void init(){
+
+ this.workflowResolver= Mockito.mock(WorkflowResolver.class);
+ this.svcLogicService=Mockito.mock(SvcLogicService.class);
+ workflowManger.setWorkflowResolver(workflowResolver);
+ workflowManger.setSvcLogicServiceRef(svcLogicService);
+
+ }
+ @Test
+ public void testExecuteWorkFlow() throws SvcLogicException{
+
+ Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.execute(anyString(),anyString(), anyString(),anyString(),anyObject())).thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowRequest workflowRequest =getWorkflowRequest("vSCP",300,new Date(), "2.00" ,"ST_249","O1652", "uid34", VNFOperation.Lock,"mj13","Payload");
+
+ WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
+ Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("success"));
+
+
+ }
+
+ @Test
+ public void testExecuteWorkFlowFalse() throws SvcLogicException{
+
+ Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.execute(anyString(),anyString(), anyString(),anyString(),anyObject())).thenReturn(createSvcExexuteFailureResponse());
+
+ WorkflowRequest workflowRequest =getWorkflowRequest("vSCP",300,new Date(), "2.00" ,"ST_249","O1652", "uid34", VNFOperation.Lock,"mj13","Payload");
+
+ WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
+ Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("failure"));
+
+ }
+
+ @Test
+ public void testExecuteWorkFlowAPIVersionStartWithOne() throws SvcLogicException{
+ Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.execute(anyString(),anyString(), anyString(),anyString(),anyObject())).thenReturn(createSvcExexuteSuccessResponse());
+
+ WorkflowRequest workflowRequest =getWorkflowRequest("vSCP",300,new Date(), "1.00" ,"ST_249","O1652", "uid34", VNFOperation.Lock,"mj13","Payload");
+
+ WorkflowResponse response=workflowManger.executeWorkflow(workflowRequest);
+ Assert.assertTrue(response.getResponseContext().getStatus().getMessage().equals("success"));
+ }
+
+ @Test
+ public void testWorkFlowExist() throws SvcLogicException{
+ Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.hasGraph(anyString(),anyString(), anyString(),anyString())).thenReturn(true);
+
+ WorkflowRequest workflowRequest =getWorkflowRequest("vSCP",300,new Date(), "2.00" ,"ST_249","O1652", "uid34", VNFOperation.Lock,"mj13","Payload");
+
+ WorkflowExistsOutput response=workflowManger.workflowExists(workflowRequest);
+
+ Assert.assertTrue(response.isMappingExist());
+ }
+
+ @Test
+ public void testWorkFlowNotExist() throws SvcLogicException{
+ Mockito.when(workflowResolver.resolve(anyString(),anyString(),anyString(),anyString())).thenReturn(getWorkFlowKey());
+ Mockito.when(svcLogicService.hasGraph(anyString(),anyString(), anyString(),anyString())).thenReturn(false);
+
+ WorkflowRequest workflowRequest =getWorkflowRequest("vSCP",300,new Date(), "2.00" ,"ST_249","O1652", "uid34", VNFOperation.Lock,"mj13","Payload");
+
+ WorkflowExistsOutput response=workflowManger.workflowExists(workflowRequest);
+
+ Assert.assertTrue(response.isMappingExist());
+ }
+
+ private WorkflowRequest getWorkflowRequest(String vnfType, int ttl, Date timeStamp, String apiVersion, String requestId, String originatorID, String subRequestID, VNFOperation action, String vnfId ,String payload){
+ WorkflowRequest workflowRequest=new WorkflowRequest();
+ RuntimeContext runtimeContext=createRuntimeContext();
+
+ runtimeContext.getRequestContext().getCommonHeader().getFlags().setTtl(ttl);
+ runtimeContext.getRequestContext().getCommonHeader().setApiVer(apiVersion);
+ runtimeContext.getRequestContext().getCommonHeader().setTimestamp(timeStamp);
+ runtimeContext.getRequestContext().getCommonHeader().setRequestId(requestId);
+ runtimeContext.getRequestContext().getCommonHeader().setSubRequestId(subRequestID);
+ runtimeContext.getRequestContext().getCommonHeader().setOriginatorId(originatorID);
+ runtimeContext.getRequestContext().setAction(action);
+ runtimeContext.getRequestContext().getActionIdentifiers().setVnfId(vnfId);
+ runtimeContext.getRequestContext().setPayload(payload);
+
+ runtimeContext.getVnfContext().setType(vnfType);
+ runtimeContext.getVnfContext().setId(vnfId);
+
+ workflowRequest.setRequestContext(runtimeContext.getRequestContext());
+ workflowRequest.setResponseContext(runtimeContext.getResponseContext());
+ workflowRequest.setVnfContext(runtimeContext.getVnfContext());
+
+ return workflowRequest;
+ }
+
+ private RequestContext creatRequestContext(){
+ RequestContext requestContext=new RequestContext();
+ CommonHeader commonHeader = new CommonHeader();
+ Flags flags = new Flags();
+ ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
+ commonHeader.setFlags(flags);
+ requestContext.setCommonHeader(commonHeader);
+ requestContext.setActionIdentifiers(actionIdentifiers);
+
+ return requestContext;
+ }
+ private ResponseContext createResponseContext(){
+ ResponseContext responseContext=new ResponseContext();
+ CommonHeader commonHeader = new CommonHeader();
+ Flags flags = new Flags();
+ Status status = new Status();
+ responseContext.setCommonHeader(commonHeader);
+ responseContext.setStatus(status);
+ commonHeader.setFlags(flags);
+
+ return responseContext;
+ }
+ private RuntimeContext createRuntimeContext(){
+ RuntimeContext runtimeContext=new RuntimeContext();
+ RequestContext requestContext=creatRequestContext();
+ ResponseContext responseContext=createResponseContext();
+ runtimeContext.setRequestContext(requestContext);
+ runtimeContext.setResponseContext(responseContext);
+ VNFContext vnfContext=new VNFContext();
+ runtimeContext.setVnfContext(vnfContext);
+
+ return runtimeContext;
+ }
+
+ public WorkflowKey getWorkFlowKey(){
+ WorkflowKey workflowKey=new WorkflowKey("APPCDG","2.0.0.0","dgModule");
+
+ return workflowKey;
+ }
+
+ private Properties createSvcExexuteSuccessResponse(){
+ Properties properties=new Properties();
+ properties.setProperty("output.payload","success");
+ properties.setProperty("SvcLogic.status","success");
+ properties.setProperty("output.status.code","400");
+ properties.setProperty("output.status.message","success");
+
+ return properties;
+ }
+
+ private Properties createSvcExexuteFailureResponse(){
+ Properties properties=new Properties();
+ properties.setProperty("output.payload","failure");
+ properties.setProperty("SvcLogic.status","failure");
+ properties.setProperty("output.status.message","failure");
+
+ return properties;
+ }
+
+}
diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/onap/appc/default.properties b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/onap/appc/default.properties
index e48b7b66a..28b45df11 100644
--- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/onap/appc/default.properties
+++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/onap/appc/default.properties
@@ -38,6 +38,7 @@ org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},.
org.onap.ccsdk.sli.adaptors.aai.host.certificate.ignore=true
org.onap.ccsdk.sli.adaptors.aai.certificate.trust.all=true
+
#
# Configuration file for A&AI Adapter
#
@@ -71,7 +72,6 @@ org.onap.ccsdk.sli.adaptors.aai.param.vnf_type=vnf-type
org.onap.ccsdk.sli.adaptors.aai.param.physical.location.id=physical-location-id
org.onap.ccsdk.sli.adaptors.aai.param.service.type=service-type
-
org.onap.appc.logging.path=${user.home},etc,../etc,.
org.onap.appc.logging.file=logback.xml
@@ -84,7 +84,7 @@ appc.LCM.provider.url=https://localhost:8443/restconf/operations/appc-provider-l
appc.LCM.poolMembers=<DMAAP_IP>:3904
appc.LCM.service=dmaap
appc.LCM.topic.write=APPC-TEST2
-appc.LCM.client.name=APPC-TEST-CLIENT-WF-MGMT-MAIN
+appc.LCM.client.name=APPC-TEST-CLIENT-CMD-EXECUTOR-TEST
appc.LCM.provider.user=test
appc.LCM.provider.pass=test