From 781b1a6df324419c846c84ea983c18fc8362bfd3 Mon Sep 17 00:00:00 2001 From: Patrick Brady Date: Wed, 13 Dec 2017 11:19:06 -0800 Subject: Third part of onap rename This part of the commit changes the folder structure on all other folders of appc. Change-Id: I8acfa11cdfcdcd36be0e137245d1dd7324f1abd3 Signed-off-by: Patrick Brady Issue-ID: APPC-13 --- .../org/onap/appc/workflow/WorkFlowManager.java | 50 +++ .../workflow/objects/WorkflowExistsOutput.java | 97 ++++++ .../appc/workflow/objects/WorkflowRequest.java | 70 +++++ .../appc/workflow/objects/WorkflowResponse.java | 50 +++ .../openecomp/appc/workflow/WorkFlowManager.java | 50 --- .../workflow/objects/WorkflowExistsOutput.java | 97 ------ .../appc/workflow/objects/WorkflowRequest.java | 70 ----- .../appc/workflow/objects/WorkflowResponse.java | 50 --- .../org/onap/appc/common/constant/Constants.java | 70 +++++ .../appc/workflow/impl/WorkFlowManagerImpl.java | 347 +++++++++++++++++++++ .../org/onap/appc/workflow/impl/WorkflowKey.java | 62 ++++ .../onap/appc/workflow/impl/WorkflowResolver.java | 142 +++++++++ .../workflow/impl/WorkflowResolverDataReader.java | 131 ++++++++ .../openecomp/appc/common/constant/Constants.java | 70 ----- .../appc/workflow/impl/WorkFlowManagerImpl.java | 347 --------------------- .../openecomp/appc/workflow/impl/WorkflowKey.java | 62 ---- .../appc/workflow/impl/WorkflowResolver.java | 142 --------- .../workflow/impl/WorkflowResolverDataReader.java | 131 -------- .../resources/org/onap/appc/default.properties | 43 +++ .../org/openecomp/appc/default.properties | 43 --- .../onap/appc/workflow/TestWorkFlowManager.java | 189 +++++++++++ .../appc/workflow/TestWorkFlowManager.java | 189 ----------- .../resources/org/onap/appc/default.properties | 90 ++++++ .../org/openecomp/appc/default.properties | 90 ------ 24 files changed, 1341 insertions(+), 1341 deletions(-) create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/WorkFlowManager.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowExistsOutput.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowRequest.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowResponse.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/WorkFlowManager.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowExistsOutput.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowRequest.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowResponse.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/common/constant/Constants.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowKey.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolver.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolverDataReader.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/common/constant/Constants.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkFlowManagerImpl.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowKey.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowResolver.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowResolverDataReader.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/onap/appc/default.properties delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/openecomp/appc/default.properties create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkFlowManager.java delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/openecomp/appc/workflow/TestWorkFlowManager.java create mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/onap/appc/default.properties delete mode 100644 appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/openecomp/appc/default.properties (limited to 'appc-dispatcher/appc-workflow-management') diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/WorkFlowManager.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/WorkFlowManager.java new file mode 100644 index 000000000..c0cb8f48e --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/WorkFlowManager.java @@ -0,0 +1,50 @@ +/*- + * ============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.onap.appc.workflow.objects.WorkflowExistsOutput; +import org.onap.appc.workflow.objects.WorkflowRequest; +import org.onap.appc.workflow.objects.WorkflowResponse; + +public interface WorkFlowManager { + /** + * 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 + */ + WorkflowResponse executeWorkflow(WorkflowRequest workflowRequest); + + /** + * Check if workflow (DG) exists in database + * @param workflowQueryParams workflow request with command and vnf Type + * @return WorkflowExistsOutput.mappingExist True if workflow mapping exists else False. WorkflowExistsOutput.dgExist True if DG workflow exists else False. + */ + WorkflowExistsOutput workflowExists(WorkflowRequest workflowQueryParams); + +} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowExistsOutput.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowExistsOutput.java new file mode 100644 index 000000000..37d33d286 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowExistsOutput.java @@ -0,0 +1,97 @@ +/*- + * ============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.objects; + +public class WorkflowExistsOutput { + + private boolean mappingExist ; + private boolean dgExist; + private String workflowModule; + private String workflowName; + private String workflowVersion; + + + public WorkflowExistsOutput() { + } + + public WorkflowExistsOutput(boolean mappingExist, boolean dgExist) { + this.mappingExist = mappingExist; + this.dgExist = dgExist; + } + + public boolean isMappingExist() { + return mappingExist; + } + + public void setMappingExist(boolean mappingExist) { + this.mappingExist = mappingExist; + } + + public boolean isDgExist() { + return dgExist; + } + + public void setDgExist(boolean dgExist) { + this.dgExist = dgExist; + } + + public String getWorkflowName() { + return workflowName; + } + + public void setWorkflowName(String workflowName) { + this.workflowName = workflowName; + } + + public String getWorkflowVersion() { + return workflowVersion; + } + + public void setWorkflowVersion(String workflowVersion) { + this.workflowVersion = workflowVersion; + } + + public String getWorkflowModule() { + return workflowModule; + } + + public void setWorkflowModule(String workflowModule) { + this.workflowModule = workflowModule; + } + public boolean exists(){ + return mappingExist && dgExist; + } + + @Override + public String toString() { + return "WorkflowExistsOutput{" + + "mappingExist=" + mappingExist + + ", dgExist=" + dgExist + + ", workflowModule='" + workflowModule + '\'' + + ", workflowName='" + workflowName + '\'' + + ", workflowVersion='" + workflowVersion + '\'' + + '}'; + } +} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowRequest.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowRequest.java new file mode 100644 index 000000000..6cdbc7146 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowRequest.java @@ -0,0 +1,70 @@ +/*- + * ============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.objects; + +import org.onap.appc.domainmodel.lcm.RequestContext; +import org.onap.appc.domainmodel.lcm.ResponseContext; +import org.onap.appc.domainmodel.lcm.VNFContext; + + +public class WorkflowRequest { + + private RequestContext requestContext; + private ResponseContext responseContext; + private VNFContext vnfContext; + + public RequestContext getRequestContext() { + return requestContext; + } + + public void setRequestContext(RequestContext requestContext) { + this.requestContext = requestContext; + } + + public ResponseContext getResponseContext() { + return responseContext; + } + + public void setResponseContext(ResponseContext responseContext) { + this.responseContext = responseContext; + } + + public VNFContext getVnfContext() { + return vnfContext; + } + + public void setVnfContext(VNFContext vnfContext) { + this.vnfContext = vnfContext; + } + + @Override + public String toString() { + return "WorkflowRequest{" + + "requestContext=" + requestContext + + ", responseContext=" + responseContext + + ", vnfContext=" + vnfContext + + '}'; + } +} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowResponse.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowResponse.java new file mode 100644 index 000000000..f8d2997c5 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/onap/appc/workflow/objects/WorkflowResponse.java @@ -0,0 +1,50 @@ +/*- + * ============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.objects; + +import java.util.Properties; + +import org.onap.appc.domainmodel.lcm.ResponseContext; + + +public class WorkflowResponse { + + private ResponseContext responseContext; + + public ResponseContext getResponseContext() { + return responseContext; + } + + public void setResponseContext(ResponseContext responseContext) { + this.responseContext = responseContext; + } + + @Override + public String toString() { + return "WorkflowResponse{" + + "responseContext=" + responseContext + + '}'; + } +} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/WorkFlowManager.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/WorkFlowManager.java deleted file mode 100644 index c0cb8f48e..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/WorkFlowManager.java +++ /dev/null @@ -1,50 +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.onap.appc.workflow.objects.WorkflowExistsOutput; -import org.onap.appc.workflow.objects.WorkflowRequest; -import org.onap.appc.workflow.objects.WorkflowResponse; - -public interface WorkFlowManager { - /** - * 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 - */ - WorkflowResponse executeWorkflow(WorkflowRequest workflowRequest); - - /** - * Check if workflow (DG) exists in database - * @param workflowQueryParams workflow request with command and vnf Type - * @return WorkflowExistsOutput.mappingExist True if workflow mapping exists else False. WorkflowExistsOutput.dgExist True if DG workflow exists else False. - */ - WorkflowExistsOutput workflowExists(WorkflowRequest workflowQueryParams); - -} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowExistsOutput.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowExistsOutput.java deleted file mode 100644 index 37d33d286..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowExistsOutput.java +++ /dev/null @@ -1,97 +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.objects; - -public class WorkflowExistsOutput { - - private boolean mappingExist ; - private boolean dgExist; - private String workflowModule; - private String workflowName; - private String workflowVersion; - - - public WorkflowExistsOutput() { - } - - public WorkflowExistsOutput(boolean mappingExist, boolean dgExist) { - this.mappingExist = mappingExist; - this.dgExist = dgExist; - } - - public boolean isMappingExist() { - return mappingExist; - } - - public void setMappingExist(boolean mappingExist) { - this.mappingExist = mappingExist; - } - - public boolean isDgExist() { - return dgExist; - } - - public void setDgExist(boolean dgExist) { - this.dgExist = dgExist; - } - - public String getWorkflowName() { - return workflowName; - } - - public void setWorkflowName(String workflowName) { - this.workflowName = workflowName; - } - - public String getWorkflowVersion() { - return workflowVersion; - } - - public void setWorkflowVersion(String workflowVersion) { - this.workflowVersion = workflowVersion; - } - - public String getWorkflowModule() { - return workflowModule; - } - - public void setWorkflowModule(String workflowModule) { - this.workflowModule = workflowModule; - } - public boolean exists(){ - return mappingExist && dgExist; - } - - @Override - public String toString() { - return "WorkflowExistsOutput{" + - "mappingExist=" + mappingExist + - ", dgExist=" + dgExist + - ", workflowModule='" + workflowModule + '\'' + - ", workflowName='" + workflowName + '\'' + - ", workflowVersion='" + workflowVersion + '\'' + - '}'; - } -} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowRequest.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowRequest.java deleted file mode 100644 index 6cdbc7146..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowRequest.java +++ /dev/null @@ -1,70 +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.objects; - -import org.onap.appc.domainmodel.lcm.RequestContext; -import org.onap.appc.domainmodel.lcm.ResponseContext; -import org.onap.appc.domainmodel.lcm.VNFContext; - - -public class WorkflowRequest { - - private RequestContext requestContext; - private ResponseContext responseContext; - private VNFContext vnfContext; - - public RequestContext getRequestContext() { - return requestContext; - } - - public void setRequestContext(RequestContext requestContext) { - this.requestContext = requestContext; - } - - public ResponseContext getResponseContext() { - return responseContext; - } - - public void setResponseContext(ResponseContext responseContext) { - this.responseContext = responseContext; - } - - public VNFContext getVnfContext() { - return vnfContext; - } - - public void setVnfContext(VNFContext vnfContext) { - this.vnfContext = vnfContext; - } - - @Override - public String toString() { - return "WorkflowRequest{" + - "requestContext=" + requestContext + - ", responseContext=" + responseContext + - ", vnfContext=" + vnfContext + - '}'; - } -} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowResponse.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowResponse.java deleted file mode 100644 index f8d2997c5..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-api/src/main/java/org/openecomp/appc/workflow/objects/WorkflowResponse.java +++ /dev/null @@ -1,50 +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.objects; - -import java.util.Properties; - -import org.onap.appc.domainmodel.lcm.ResponseContext; - - -public class WorkflowResponse { - - private ResponseContext responseContext; - - public ResponseContext getResponseContext() { - return responseContext; - } - - public void setResponseContext(ResponseContext responseContext) { - this.responseContext = responseContext; - } - - @Override - public String toString() { - return "WorkflowResponse{" + - "responseContext=" + responseContext + - '}'; - } -} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/common/constant/Constants.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/common/constant/Constants.java new file mode 100644 index 000000000..ebac2d001 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/common/constant/Constants.java @@ -0,0 +1,70 @@ +/*- + * ============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.common.constant; + +public class Constants { + + public static final String DG_ATTRIBUTE_STATUS = "SvcLogic.status"; + public static final String DG_STATUS_SUCCESS = "success"; + public static final String DG_ATTRIBUTE_STATUS_CODE = "SvcLogic.status.code"; + public static final String DG_OUTPUT_STATUS_CODE = "output.status.code"; + public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message"; + + + /** + * The name of the property that contains the VM id value in the graph's context + */ + public static final String VF_ID = "org.onap.appc.vfid"; + + /** + * The name of the property that contains the VF Type value in the graph's context + */ + public static final String VF_TYPE = "org.onap.appc.vftype"; + + /** + * The name of the property that contains the service request id value in the graph's context + */ + public static final String REQUEST_ID = "org.onap.appc.reqid"; + + /** + * The name of the property that indicates which method of the IaaS adapter to call + */ + public static final String ACTION = "org.onap.appc.action"; + + public static final String PAYLOAD = "payload"; + + public static final String CONF_ID = "org.onap.appc.confid"; + + public static final String API_VERSION = "org.onap.appc.apiversion"; + + public static final String ORIGINATOR_ID = "org.onap.appc.originatorid"; + + public static final String OBJECT_ID ="org.onap.appc.objectid"; + + public static final String SUB_REQUEST_ID = "org.onap.appc.subrequestid"; + + public static final String ERROR_MESSAGE = "error-message"; + +} 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 new file mode 100644 index 000000000..ceae5677c --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkFlowManagerImpl.java @@ -0,0 +1,347 @@ +/*- + * ============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.apache.commons.lang.ObjectUtils; +import org.apache.commons.lang3.StringUtils; +import org.onap.appc.common.constant.Constants; +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; +import org.onap.appc.workflow.objects.WorkflowRequest; +import org.onap.appc.workflow.objects.WorkflowResponse; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +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.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. + * + * @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 { + + + 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; + 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); + } 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); + + workflowParams.put(actionProperty,workflowRequest.getRequestContext().getAction().name()); + workflowParams.put(requestIdProperty, workflowRequest.getRequestContext().getCommonHeader().getRequestId()); + workflowParams.put(vfIdProperty, workflowRequest.getVnfContext().getId()); + workflowParams.put(vfTypeProperty,workflowRequest.getVnfContext().getType()); + workflowParams.put(apiVerProperty,workflowRequest.getRequestContext().getCommonHeader().getApiVer()); + workflowParams.put(originatorIdProperty,workflowRequest.getRequestContext().getCommonHeader().getOriginatorId()); + workflowParams.put(subRequestId,workflowRequest.getRequestContext().getCommonHeader().getSubRequestId()); + + Object payloadJson = workflowRequest.getRequestContext().getPayload(); + if(payloadJson!=null) { + try { + Map 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()) { + 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 { + workflowParams.put("isBwcMode", "false"); + } + + SVCLogicServiceExecute(workflowKey, workflowRequest.getRequestContext(), workflowParams , workflowResponse); + 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()); + fillStatus(501, "Error Executing DG "+e.getMessage(), workflowRequest.getResponseContext()); + } + if (logger.isTraceEnabled()) { + logger.trace("Exiting from executeWorkflow with (workflowResponse = "+ ObjectUtils.toString(workflowResponse.getResponseContext().getStatus().getMessage())+")"); + } + 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()))); + 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()); + workflowParams.put("input.common-header.sub-request-id",workflowRequest.getRequestContext().getCommonHeader().getSubRequestId()!=null ? workflowRequest.getRequestContext().getCommonHeader().getSubRequestId():""); + workflowParams.put("input.action",workflowRequest.getRequestContext().getAction().toString()); + workflowParams.put("input.payload",null != workflowRequest.getRequestContext().getPayload() ? workflowRequest.getRequestContext().getPayload() : ""); + 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():""); + final Map additionalContext; + if ((additionalContext = workflowRequest.getRequestContext().getAdditionalContext())!=null) { + for (Map.Entry entry : additionalContext.entrySet()) { + workflowParams.put("input." + entry.getKey(), null != entry.getValue() ? entry.getValue() : ""); + } + } + } + + /** + * 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 { + 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'", + 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"); + } + + private void SVCLogicServiceExecute(WorkflowKey workflowKey, RequestContext requestContext, Properties workflowParams, WorkflowResponse workflowResponse) { + if (logger.isTraceEnabled()) { + logger.trace("Entering SVCLogicServiceExecute"); + } + + Properties respProps = null; + + 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()) { + logger.debug("Error while executing DG " + e.getMessage() + e.getStackTrace()); + } + logger.error("Error in DG", e.getMessage()+e.getStackTrace().toString()); + } + + if (respProps != null) { + if (!requestContext.getCommonHeader().getApiVer().startsWith("1.")) { + fillResponseContextByOutputFieldsFromDgContext(workflowResponse.getResponseContext(), respProps); + } + + final String commonStatus = respProps.getProperty(Constants.DG_ATTRIBUTE_STATUS); + final String specificStatusMessage = respProps.getProperty(Constants.DG_OUTPUT_STATUS_MESSAGE); + String dgOutputStatusCode = respProps.getProperty(Constants.DG_OUTPUT_STATUS_CODE); + int specificStatusCode = 0; + if (dgOutputStatusCode != null) { + specificStatusCode = Integer.parseInt(dgOutputStatusCode); + } + + setWorkFlowResponseStatus(workflowResponse.getResponseContext(), commonStatus, specificStatusMessage, specificStatusCode); + + if (logger.isDebugEnabled()) { + logger.debug("DG Execution Status: " + commonStatus); + } + } + + if (logger.isTraceEnabled()) { + logger.trace("Exiting from SVCLogicServiceExecute"); + } + } + + /** + * Filling response context by output.* fields from DG context. Works only for 2.* API version + * + * @param responseContext response context which you need to fill + * @param respProps DG context in a properties format + */ + private void fillResponseContextByOutputFieldsFromDgContext(ResponseContext responseContext, Properties respProps) { + + Enumeration e = respProps.propertyNames(); + while (e.hasMoreElements()){ + String key = (String) e.nextElement(); + if (key.startsWith("output.")){ + if (!key.startsWith("output.common-header.") && !key.startsWith("output.status.")){ + + if (key.equalsIgnoreCase("output.payload")){ + responseContext.setPayload(respProps.getProperty(key)); + } else { + responseContext.addKeyValueToAdditionalContext(key, respProps.getProperty(key)); + } + } + } + } + } + + /** + * Filling responceContext status code amd message according to responce messages and codes from DG. + * + * @param responseContext response cotext + * @param commonStatus common status message from DG ("success" or "failure") + * @param specificStatusMessage specific status message from specific DG node + * @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 ){ + 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 + * + * @param code 3-digit status code + * @param message explanation of a status code + * @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)); + } + +} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowKey.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowKey.java new file mode 100644 index 000000000..d61628fc9 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowKey.java @@ -0,0 +1,62 @@ +/*- + * ============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; + +class WorkflowKey { + private final String name; + private final String version; + private final String module; + + WorkflowKey(String name, String version, String module) { + this.name = name; + this.version = version; + this.module = module; + } + + String name() { + return name; + } + + String version() { + return version; + } + + String module() { + return module; + } + + @Override + public String toString() { + StringBuilder buff = new StringBuilder(128); + buff.append("{"); + buff.append("module = ").append(module); + buff.append(", "); + buff.append("name = ").append(name); + buff.append(", "); + buff.append("version = ").append(version); + buff.append("}"); + return buff.toString(); + } +} 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 new file mode 100644 index 000000000..1f4a5b406 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolver.java @@ -0,0 +1,142 @@ +/*- + * ============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 java.util.concurrent.locks.ReentrantLock; + +import org.onap.appc.rankingframework.RankedAttributesContext; +import org.onap.appc.rankingframework.RankedAttributesResolver; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +class WorkflowResolver { + + private static final EELFLogger logger = EELFManager.getInstance().getLogger(WorkFlowManagerImpl.class); + + private long interval; + + private volatile long lastUpdate = 0l; + private volatile boolean isUpdateInProgress = false; + private volatile RankedAttributesResolver dgResolver; + + private final ReentrantLock INIT_LOCK = new ReentrantLock(); + + WorkflowResolver(long interval) { + this.interval = interval * 1000; + } + + private RankedAttributesResolver createResolver() { + WorkflowResolverDataReader reader = new WorkflowResolverDataReader(); + return reader.read(); + } + + private boolean isExpired() { + return (System.currentTimeMillis() - lastUpdate) > interval; + } + + private RankedAttributesResolver resolver() { + + /* + * In general case, the method implementation is non-blocking. The first + * thread that identifies data expiration will be used to refresh it. In + * meanwhile, any other thread will get the old instance without waiting + * for the updated one. The only exception is the very first time when + * previous instance doesn't exist - in such a cases all the threads + * will be waiting on INIT_LOCK while one of them initializes the + * resolver instance. NOTE: The initialization is intentionally + * implemented in lazy manner to make sure the bundle is initialized + * properly on startup regardless whether or not the data is correct. + * Afterwards, the resolver may be instantiated as many times as needed. + */ + + try { + + if (dgResolver == null) { + INIT_LOCK.lock(); + if (dgResolver != null) { + INIT_LOCK.unlock(); + } + } + + if (!isUpdateInProgress && isExpired()) { + + boolean doUpgrade = false; + + synchronized (this) { + if (!isUpdateInProgress) { + isUpdateInProgress = true; + doUpgrade = true; + } + } + + if (doUpgrade) { + + logger.info("DG resolver configuration data has expired - initiating refresh"); + + try { + RankedAttributesResolver temp = createResolver(); + dgResolver = temp; + lastUpdate = System.currentTimeMillis(); + + logger.info("DG resolver configuration data has been refreshed successfully"); + } finally { + isUpdateInProgress = false; + } + } + } + } finally { + if (INIT_LOCK.isHeldByCurrentThread()) { + INIT_LOCK.unlock(); + } + } + + return dgResolver; + } + + WorkflowKey resolve(final String action, final String vnfType, final String vnfVersion,final String apiVersion) { + + RankedAttributesContext context = new RankedAttributesContext() { + @Override + public Object getAttributeValue(String name) { + switch (name) { + case "action": + return action; + case "api_version": + return apiVersion; + case "vnf_type": + return vnfType; + case "vnf_version": + return vnfVersion; + default: + throw new IllegalStateException(name); + } + } + }; + + WorkflowKey wfKey = resolver().resolve(context); + + return wfKey; + } +} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolverDataReader.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolverDataReader.java new file mode 100644 index 000000000..9cb04c42a --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/onap/appc/workflow/impl/WorkflowResolverDataReader.java @@ -0,0 +1,131 @@ +/*- + * ============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 java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; + +import org.onap.appc.dao.util.DBUtils; +import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; +import org.onap.appc.rankingframework.ConfigurationEntry; +import org.onap.appc.rankingframework.ConfigurationSet; +import org.onap.appc.rankingframework.RankedAttributesResolver; + +class WorkflowResolverDataReader { + + private static final String QUERY_STMT = "SELECT action,api_version,vnf_type,vnf_version,dg_name,dg_version,dg_module FROM VNF_DG_MAPPING"; + + private static final Collection ATTRIBUTE_NAMES = Arrays.asList("action","api_version", "vnf_type", "vnf_version"); + + private static class ConfigurationSetAdaptor implements ConfigurationSet { + + private final ResultSet resultSet; + + private class ResultSetIterator implements Iterator>, ConfigurationEntry { + @Override + public boolean hasNext() { + try { + return resultSet.next(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Override + public ConfigurationEntry next() { + return this; + } + + @Override + public void remove() { + throw new UnsupportedOperationException(); + } + + @Override + public Object getAttributeValue(String name) { + try { + return resultSet.getObject(name); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + @Override + public WorkflowKey getResult() { + try { + return new WorkflowKey(resultSet.getString("dg_name"), resultSet.getString("dg_version"), resultSet.getString("dg_module")); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + } + + ConfigurationSetAdaptor(ResultSet resultSet) { + this.resultSet = resultSet; + } + + @Override + public Iterable> getEntries() { + return new Iterable>() { + + @Override + public Iterator> iterator() { + return new ResultSetIterator(); + } + }; + } + + @Override + public Collection getRankedAttributeNames() { + return ATTRIBUTE_NAMES; + } + } + + RankedAttributesResolver read() { + try { + try (Connection conn = DBUtils.getConnection("sdnctl")) { + try (PreparedStatement stmt = conn.prepareStatement(QUERY_STMT)) { + try (ResultSet res = stmt.executeQuery()) { + if (res.next()) { + res.beforeFirst(); + ConfigurationSet resolverConfig = new ConfigurationSetAdaptor(res); + return AbstractRankedAttributesResolverFactory.getInstance().create(resolverConfig); + } else { + // TODO: Return empty object + throw new IllegalStateException(); + } + } + } + } + } catch (SQLException e) { + throw new RuntimeException(e); + } + } +} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/common/constant/Constants.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/common/constant/Constants.java deleted file mode 100644 index ebac2d001..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/common/constant/Constants.java +++ /dev/null @@ -1,70 +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.common.constant; - -public class Constants { - - public static final String DG_ATTRIBUTE_STATUS = "SvcLogic.status"; - public static final String DG_STATUS_SUCCESS = "success"; - public static final String DG_ATTRIBUTE_STATUS_CODE = "SvcLogic.status.code"; - public static final String DG_OUTPUT_STATUS_CODE = "output.status.code"; - public static final String DG_OUTPUT_STATUS_MESSAGE = "output.status.message"; - - - /** - * The name of the property that contains the VM id value in the graph's context - */ - public static final String VF_ID = "org.onap.appc.vfid"; - - /** - * The name of the property that contains the VF Type value in the graph's context - */ - public static final String VF_TYPE = "org.onap.appc.vftype"; - - /** - * The name of the property that contains the service request id value in the graph's context - */ - public static final String REQUEST_ID = "org.onap.appc.reqid"; - - /** - * The name of the property that indicates which method of the IaaS adapter to call - */ - public static final String ACTION = "org.onap.appc.action"; - - public static final String PAYLOAD = "payload"; - - public static final String CONF_ID = "org.onap.appc.confid"; - - public static final String API_VERSION = "org.onap.appc.apiversion"; - - public static final String ORIGINATOR_ID = "org.onap.appc.originatorid"; - - public static final String OBJECT_ID ="org.onap.appc.objectid"; - - public static final String SUB_REQUEST_ID = "org.onap.appc.subrequestid"; - - public static final String ERROR_MESSAGE = "error-message"; - -} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkFlowManagerImpl.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkFlowManagerImpl.java deleted file mode 100644 index ceae5677c..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkFlowManagerImpl.java +++ /dev/null @@ -1,347 +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.impl; - -import org.apache.commons.lang.ObjectUtils; -import org.apache.commons.lang3.StringUtils; -import org.onap.appc.common.constant.Constants; -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; -import org.onap.appc.workflow.objects.WorkflowRequest; -import org.onap.appc.workflow.objects.WorkflowResponse; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; -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.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. - * - * @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 { - - - 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; - 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); - } 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); - - workflowParams.put(actionProperty,workflowRequest.getRequestContext().getAction().name()); - workflowParams.put(requestIdProperty, workflowRequest.getRequestContext().getCommonHeader().getRequestId()); - workflowParams.put(vfIdProperty, workflowRequest.getVnfContext().getId()); - workflowParams.put(vfTypeProperty,workflowRequest.getVnfContext().getType()); - workflowParams.put(apiVerProperty,workflowRequest.getRequestContext().getCommonHeader().getApiVer()); - workflowParams.put(originatorIdProperty,workflowRequest.getRequestContext().getCommonHeader().getOriginatorId()); - workflowParams.put(subRequestId,workflowRequest.getRequestContext().getCommonHeader().getSubRequestId()); - - Object payloadJson = workflowRequest.getRequestContext().getPayload(); - if(payloadJson!=null) { - try { - Map 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()) { - 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 { - workflowParams.put("isBwcMode", "false"); - } - - SVCLogicServiceExecute(workflowKey, workflowRequest.getRequestContext(), workflowParams , workflowResponse); - 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()); - fillStatus(501, "Error Executing DG "+e.getMessage(), workflowRequest.getResponseContext()); - } - if (logger.isTraceEnabled()) { - logger.trace("Exiting from executeWorkflow with (workflowResponse = "+ ObjectUtils.toString(workflowResponse.getResponseContext().getStatus().getMessage())+")"); - } - 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()))); - 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()); - workflowParams.put("input.common-header.sub-request-id",workflowRequest.getRequestContext().getCommonHeader().getSubRequestId()!=null ? workflowRequest.getRequestContext().getCommonHeader().getSubRequestId():""); - workflowParams.put("input.action",workflowRequest.getRequestContext().getAction().toString()); - workflowParams.put("input.payload",null != workflowRequest.getRequestContext().getPayload() ? workflowRequest.getRequestContext().getPayload() : ""); - 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():""); - final Map additionalContext; - if ((additionalContext = workflowRequest.getRequestContext().getAdditionalContext())!=null) { - for (Map.Entry entry : additionalContext.entrySet()) { - workflowParams.put("input." + entry.getKey(), null != entry.getValue() ? entry.getValue() : ""); - } - } - } - - /** - * 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 { - 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'", - 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"); - } - - private void SVCLogicServiceExecute(WorkflowKey workflowKey, RequestContext requestContext, Properties workflowParams, WorkflowResponse workflowResponse) { - if (logger.isTraceEnabled()) { - logger.trace("Entering SVCLogicServiceExecute"); - } - - Properties respProps = null; - - 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()) { - logger.debug("Error while executing DG " + e.getMessage() + e.getStackTrace()); - } - logger.error("Error in DG", e.getMessage()+e.getStackTrace().toString()); - } - - if (respProps != null) { - if (!requestContext.getCommonHeader().getApiVer().startsWith("1.")) { - fillResponseContextByOutputFieldsFromDgContext(workflowResponse.getResponseContext(), respProps); - } - - final String commonStatus = respProps.getProperty(Constants.DG_ATTRIBUTE_STATUS); - final String specificStatusMessage = respProps.getProperty(Constants.DG_OUTPUT_STATUS_MESSAGE); - String dgOutputStatusCode = respProps.getProperty(Constants.DG_OUTPUT_STATUS_CODE); - int specificStatusCode = 0; - if (dgOutputStatusCode != null) { - specificStatusCode = Integer.parseInt(dgOutputStatusCode); - } - - setWorkFlowResponseStatus(workflowResponse.getResponseContext(), commonStatus, specificStatusMessage, specificStatusCode); - - if (logger.isDebugEnabled()) { - logger.debug("DG Execution Status: " + commonStatus); - } - } - - if (logger.isTraceEnabled()) { - logger.trace("Exiting from SVCLogicServiceExecute"); - } - } - - /** - * Filling response context by output.* fields from DG context. Works only for 2.* API version - * - * @param responseContext response context which you need to fill - * @param respProps DG context in a properties format - */ - private void fillResponseContextByOutputFieldsFromDgContext(ResponseContext responseContext, Properties respProps) { - - Enumeration e = respProps.propertyNames(); - while (e.hasMoreElements()){ - String key = (String) e.nextElement(); - if (key.startsWith("output.")){ - if (!key.startsWith("output.common-header.") && !key.startsWith("output.status.")){ - - if (key.equalsIgnoreCase("output.payload")){ - responseContext.setPayload(respProps.getProperty(key)); - } else { - responseContext.addKeyValueToAdditionalContext(key, respProps.getProperty(key)); - } - } - } - } - } - - /** - * Filling responceContext status code amd message according to responce messages and codes from DG. - * - * @param responseContext response cotext - * @param commonStatus common status message from DG ("success" or "failure") - * @param specificStatusMessage specific status message from specific DG node - * @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 ){ - 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 - * - * @param code 3-digit status code - * @param message explanation of a status code - * @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)); - } - -} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowKey.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowKey.java deleted file mode 100644 index d61628fc9..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowKey.java +++ /dev/null @@ -1,62 +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.impl; - -class WorkflowKey { - private final String name; - private final String version; - private final String module; - - WorkflowKey(String name, String version, String module) { - this.name = name; - this.version = version; - this.module = module; - } - - String name() { - return name; - } - - String version() { - return version; - } - - String module() { - return module; - } - - @Override - public String toString() { - StringBuilder buff = new StringBuilder(128); - buff.append("{"); - buff.append("module = ").append(module); - buff.append(", "); - buff.append("name = ").append(name); - buff.append(", "); - buff.append("version = ").append(version); - buff.append("}"); - return buff.toString(); - } -} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowResolver.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowResolver.java deleted file mode 100644 index 1f4a5b406..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowResolver.java +++ /dev/null @@ -1,142 +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.impl; - -import java.util.concurrent.locks.ReentrantLock; - -import org.onap.appc.rankingframework.RankedAttributesContext; -import org.onap.appc.rankingframework.RankedAttributesResolver; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -class WorkflowResolver { - - private static final EELFLogger logger = EELFManager.getInstance().getLogger(WorkFlowManagerImpl.class); - - private long interval; - - private volatile long lastUpdate = 0l; - private volatile boolean isUpdateInProgress = false; - private volatile RankedAttributesResolver dgResolver; - - private final ReentrantLock INIT_LOCK = new ReentrantLock(); - - WorkflowResolver(long interval) { - this.interval = interval * 1000; - } - - private RankedAttributesResolver createResolver() { - WorkflowResolverDataReader reader = new WorkflowResolverDataReader(); - return reader.read(); - } - - private boolean isExpired() { - return (System.currentTimeMillis() - lastUpdate) > interval; - } - - private RankedAttributesResolver resolver() { - - /* - * In general case, the method implementation is non-blocking. The first - * thread that identifies data expiration will be used to refresh it. In - * meanwhile, any other thread will get the old instance without waiting - * for the updated one. The only exception is the very first time when - * previous instance doesn't exist - in such a cases all the threads - * will be waiting on INIT_LOCK while one of them initializes the - * resolver instance. NOTE: The initialization is intentionally - * implemented in lazy manner to make sure the bundle is initialized - * properly on startup regardless whether or not the data is correct. - * Afterwards, the resolver may be instantiated as many times as needed. - */ - - try { - - if (dgResolver == null) { - INIT_LOCK.lock(); - if (dgResolver != null) { - INIT_LOCK.unlock(); - } - } - - if (!isUpdateInProgress && isExpired()) { - - boolean doUpgrade = false; - - synchronized (this) { - if (!isUpdateInProgress) { - isUpdateInProgress = true; - doUpgrade = true; - } - } - - if (doUpgrade) { - - logger.info("DG resolver configuration data has expired - initiating refresh"); - - try { - RankedAttributesResolver temp = createResolver(); - dgResolver = temp; - lastUpdate = System.currentTimeMillis(); - - logger.info("DG resolver configuration data has been refreshed successfully"); - } finally { - isUpdateInProgress = false; - } - } - } - } finally { - if (INIT_LOCK.isHeldByCurrentThread()) { - INIT_LOCK.unlock(); - } - } - - return dgResolver; - } - - WorkflowKey resolve(final String action, final String vnfType, final String vnfVersion,final String apiVersion) { - - RankedAttributesContext context = new RankedAttributesContext() { - @Override - public Object getAttributeValue(String name) { - switch (name) { - case "action": - return action; - case "api_version": - return apiVersion; - case "vnf_type": - return vnfType; - case "vnf_version": - return vnfVersion; - default: - throw new IllegalStateException(name); - } - } - }; - - WorkflowKey wfKey = resolver().resolve(context); - - return wfKey; - } -} diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowResolverDataReader.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowResolverDataReader.java deleted file mode 100644 index 9cb04c42a..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/java/org/openecomp/appc/workflow/impl/WorkflowResolverDataReader.java +++ /dev/null @@ -1,131 +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.impl; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; - -import org.onap.appc.dao.util.DBUtils; -import org.onap.appc.rankingframework.AbstractRankedAttributesResolverFactory; -import org.onap.appc.rankingframework.ConfigurationEntry; -import org.onap.appc.rankingframework.ConfigurationSet; -import org.onap.appc.rankingframework.RankedAttributesResolver; - -class WorkflowResolverDataReader { - - private static final String QUERY_STMT = "SELECT action,api_version,vnf_type,vnf_version,dg_name,dg_version,dg_module FROM VNF_DG_MAPPING"; - - private static final Collection ATTRIBUTE_NAMES = Arrays.asList("action","api_version", "vnf_type", "vnf_version"); - - private static class ConfigurationSetAdaptor implements ConfigurationSet { - - private final ResultSet resultSet; - - private class ResultSetIterator implements Iterator>, ConfigurationEntry { - @Override - public boolean hasNext() { - try { - return resultSet.next(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - @Override - public ConfigurationEntry next() { - return this; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public Object getAttributeValue(String name) { - try { - return resultSet.getObject(name); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - @Override - public WorkflowKey getResult() { - try { - return new WorkflowKey(resultSet.getString("dg_name"), resultSet.getString("dg_version"), resultSet.getString("dg_module")); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - } - - ConfigurationSetAdaptor(ResultSet resultSet) { - this.resultSet = resultSet; - } - - @Override - public Iterable> getEntries() { - return new Iterable>() { - - @Override - public Iterator> iterator() { - return new ResultSetIterator(); - } - }; - } - - @Override - public Collection getRankedAttributeNames() { - return ATTRIBUTE_NAMES; - } - } - - RankedAttributesResolver read() { - try { - try (Connection conn = DBUtils.getConnection("sdnctl")) { - try (PreparedStatement stmt = conn.prepareStatement(QUERY_STMT)) { - try (ResultSet res = stmt.executeQuery()) { - if (res.next()) { - res.beforeFirst(); - ConfigurationSet resolverConfig = new ConfigurationSetAdaptor(res); - return AbstractRankedAttributesResolverFactory.getInstance().create(resolverConfig); - } else { - // TODO: Return empty object - throw new IllegalStateException(); - } - } - } - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - } -} 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 new file mode 100644 index 000000000..55249d0f9 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/onap/appc/default.properties @@ -0,0 +1,43 @@ +### +# ============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========================================================= +### + +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded +# to supply configuration options +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + +#Property below provided by appc.properties +appc.LCM.provider.url=https://localhost:8443/restconf/operations/appc-provider-lcm +appc.LCM.poolMembers=: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 + + + +# Tolerance interval (in seconds) between invalidation of DG resolver configuration +org.onap.appc.workflow.resolver.refresh_interval=300 + diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/openecomp/appc/default.properties b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/openecomp/appc/default.properties deleted file mode 100644 index 55249d0f9..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/main/resources/org/openecomp/appc/default.properties +++ /dev/null @@ -1,43 +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========================================================= -### - -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded -# to supply configuration options -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. - -#Property below provided by appc.properties -appc.LCM.provider.url=https://localhost:8443/restconf/operations/appc-provider-lcm -appc.LCM.poolMembers=: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 - - - -# Tolerance interval (in seconds) between invalidation of DG resolver configuration -org.onap.appc.workflow.resolver.refresh_interval=300 - 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 new file mode 100644 index 000000000..74828a5d2 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/onap/appc/workflow/TestWorkFlowManager.java @@ -0,0 +1,189 @@ +/*- + * ============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/openecomp/appc/workflow/TestWorkFlowManager.java b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/java/org/openecomp/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/openecomp/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/resources/org/onap/appc/default.properties b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..227a83753 --- /dev/null +++ b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/onap/appc/default.properties @@ -0,0 +1,90 @@ +### +# ============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========================================================= +### + +# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded to supply configuration options +#org.onap.appc.bootstrap.file=executor-test.properties +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. + + +# +# Certificate keystore and truststore +# +#org.openecomp.sdnc.sli.aai.ssl.trust= +#org.openecomp.sdnc.sli.aai.ssl.trust.psswd=adminadmin +#org.openecomp.sdnc.sli.aai.ssl.key= +#org.openecomp.sdnc.sli.aai.ssl.key.psswd=adminadmin +org.openecomp.sdnc.sli.aai.host.certificate.ignore=true +org.openecomp.sdnc.sli.aai.certificate.trust.all=true + +# +# Configuration file for A&AI Adapter +# + +# OPEN SOURCE - EXTERNAL A&AI INSTANCE IN TEST ENVIRONMENT +org.openecomp.sdnc.sli.aai.uri=https://10.0.1.1:8443 + +org.openecomp.sdnc.sli.aai.path.query=/aai/v8/search/sdn-zone-query + +# service instance +org.openecomp.sdnc.sli.aai.path.svcinst=/aai/v8/business/customers/customer/{customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances +org.openecomp.sdnc.sli.aai.path.svcinst.query=/aai/v8/search/generic-query?key=service-instance.service-instance-id:{svc-instance-id}&start-node-type=service-instance&include=service-instance + +# complex +org.openecomp.sdnc.sli.aai.path.complexes=/aai/v8/cloud-infrastructure/complexes +org.openecomp.sdnc.sli.aai.path.complex=/aai/v8/cloud-infrastructure/complexes/complex/{physical-location-id} + +# vservers +org.openecomp.sdnc.sli.aai.path.vservers=/aai/v8/cloud-infrastructure/tenants/tenant/{tenant-id}/vservers +org.openecomp.sdnc.sli.aai.path.vserver =/aai/v8/cloud-infrastructure/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id} + +# generic-vnf +org.openecomp.sdnc.sli.aai.path.generic.vnfs=/aai/v8/network/generic-vnfs/generic-vnf/ +org.openecomp.sdnc.sli.aai.path.generic.vnf=/aai/v8/network/generic-vnfs/generic-vnf/{vnf-id} + +# +# Formatting +# +org.openecomp.sdnc.sli.aai.param.format=filter=%s:%s +org.openecomp.sdnc.sli.aai.param.vnf_type=vnf-type +org.openecomp.sdnc.sli.aai.param.physical.location.id=physical-location-id +org.openecomp.sdnc.sli.aai.param.service.type=service-type + + +org.onap.appc.logging.path=${user.home},etc,../etc,. +org.onap.appc.logging.file=logback.xml + +org.onap.appc.db.url.%s", schema), ""); +org.onap.appc.db.user.%s", schema), ""); +org.onap.appc.db.pass.%s", schema), ""); + +#Property below provided by appc.properties +appc.LCM.provider.url=https://localhost:8443/restconf/operations/appc-provider-lcm +appc.LCM.poolMembers=: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 + diff --git a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/openecomp/appc/default.properties b/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/openecomp/appc/default.properties deleted file mode 100644 index 227a83753..000000000 --- a/appc-dispatcher/appc-workflow-management/appc-workflow-management-core/src/test/resources/org/openecomp/appc/default.properties +++ /dev/null @@ -1,90 +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========================================================= -### - -# Define the name and path of any user-provided configuration (bootstrap) file that can be loaded to supply configuration options -#org.onap.appc.bootstrap.file=executor-test.properties -org.onap.appc.bootstrap.file=appc.properties -org.onap.appc.bootstrap.path=/opt/openecomp/appc/data/properties,${user.home},. - - -# -# Certificate keystore and truststore -# -#org.openecomp.sdnc.sli.aai.ssl.trust= -#org.openecomp.sdnc.sli.aai.ssl.trust.psswd=adminadmin -#org.openecomp.sdnc.sli.aai.ssl.key= -#org.openecomp.sdnc.sli.aai.ssl.key.psswd=adminadmin -org.openecomp.sdnc.sli.aai.host.certificate.ignore=true -org.openecomp.sdnc.sli.aai.certificate.trust.all=true - -# -# Configuration file for A&AI Adapter -# - -# OPEN SOURCE - EXTERNAL A&AI INSTANCE IN TEST ENVIRONMENT -org.openecomp.sdnc.sli.aai.uri=https://10.0.1.1:8443 - -org.openecomp.sdnc.sli.aai.path.query=/aai/v8/search/sdn-zone-query - -# service instance -org.openecomp.sdnc.sli.aai.path.svcinst=/aai/v8/business/customers/customer/{customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances -org.openecomp.sdnc.sli.aai.path.svcinst.query=/aai/v8/search/generic-query?key=service-instance.service-instance-id:{svc-instance-id}&start-node-type=service-instance&include=service-instance - -# complex -org.openecomp.sdnc.sli.aai.path.complexes=/aai/v8/cloud-infrastructure/complexes -org.openecomp.sdnc.sli.aai.path.complex=/aai/v8/cloud-infrastructure/complexes/complex/{physical-location-id} - -# vservers -org.openecomp.sdnc.sli.aai.path.vservers=/aai/v8/cloud-infrastructure/tenants/tenant/{tenant-id}/vservers -org.openecomp.sdnc.sli.aai.path.vserver =/aai/v8/cloud-infrastructure/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id} - -# generic-vnf -org.openecomp.sdnc.sli.aai.path.generic.vnfs=/aai/v8/network/generic-vnfs/generic-vnf/ -org.openecomp.sdnc.sli.aai.path.generic.vnf=/aai/v8/network/generic-vnfs/generic-vnf/{vnf-id} - -# -# Formatting -# -org.openecomp.sdnc.sli.aai.param.format=filter=%s:%s -org.openecomp.sdnc.sli.aai.param.vnf_type=vnf-type -org.openecomp.sdnc.sli.aai.param.physical.location.id=physical-location-id -org.openecomp.sdnc.sli.aai.param.service.type=service-type - - -org.onap.appc.logging.path=${user.home},etc,../etc,. -org.onap.appc.logging.file=logback.xml - -org.onap.appc.db.url.%s", schema), ""); -org.onap.appc.db.user.%s", schema), ""); -org.onap.appc.db.pass.%s", schema), ""); - -#Property below provided by appc.properties -appc.LCM.provider.url=https://localhost:8443/restconf/operations/appc-provider-lcm -appc.LCM.poolMembers=: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 - -- cgit 1.2.3-korg