aboutsummaryrefslogtreecommitdiffstats
path: root/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org')
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java153
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java126
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java65
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommonMethods.java72
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java45
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java261
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java81
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/CommandRequest.java89
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/LCMCommandRequest.java32
-rw-r--r--appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/LCMReadOnlyCommandRequest.java33
10 files changed, 957 insertions, 0 deletions
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java
new file mode 100644
index 000000000..60a951722
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandExecutorImpl.java
@@ -0,0 +1,153 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+/**
+ *
+ */
+package org.openecomp.appc.executor.impl;
+
+
+import java.util.Date;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.commons.lang.ObjectUtils;
+import org.openecomp.appc.exceptions.APPCException;
+import org.openecomp.appc.executionqueue.ExecutionQueueService;
+import org.openecomp.appc.executionqueue.impl.ExecutionQueueServiceFactory;
+import org.openecomp.appc.executor.CommandExecutor;
+import org.openecomp.appc.executor.impl.objects.CommandRequest;
+import org.openecomp.appc.executor.impl.objects.LCMCommandRequest;
+import org.openecomp.appc.executor.impl.objects.LCMReadOnlyCommandRequest;
+import org.openecomp.appc.executor.objects.CommandExecutorInput;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+
+public class CommandExecutorImpl implements CommandExecutor {
+
+ private CommandTaskFactory executionTaskFactory ;
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandExecutorImpl.class);
+
+ private ExecutionQueueService executionQueueService;
+ private ExpiredMessageHandler expiredMessageHandler;
+
+ public CommandExecutorImpl(){
+
+ }
+
+ public void setExecutionQueueService(ExecutionQueueService executionQueueService) {
+ this.executionQueueService = executionQueueService;
+ }
+
+ public void setExpiredMessageHandler(ExpiredMessageHandler expiredMessageHandler) {
+ this.expiredMessageHandler = expiredMessageHandler;
+ }
+
+ public void initialize() {
+ logger.info("initialization started of CommandExecutorImpl");
+ executionQueueService = ExecutionQueueServiceFactory.getExecutionQueueService();
+ executionQueueService.registerMessageExpirationListener(expiredMessageHandler);
+ }
+
+ public void setExecutionTaskFactory(CommandTaskFactory executionTaskFactory) {
+ this.executionTaskFactory = executionTaskFactory;
+ }
+
+ /**
+ * Execute given command
+ * Create command request and enqueue it for execution.
+ * @param commandExecutorInput Contains CommandHeader, command , target Id , payload and conf ID (optional)
+ * @throws APPCException in case of error.
+ */
+ @Override
+ public void executeCommand (CommandExecutorInput commandExecutorInput) throws APPCException{
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to executeCommand with CommandExecutorInput = "+ ObjectUtils.toString(commandExecutorInput));
+ }
+ CommandRequest request = getCommandRequest(commandExecutorInput);
+ enqueRequest(request);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exiting from executeCommand");
+ }
+ }
+
+ private CommandRequest getCommandRequest(CommandExecutorInput commandExecutorInput){
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to getCommandRequest with CommandExecutorInput = "+ ObjectUtils.toString(commandExecutorInput));
+ }
+ CommandRequest commandRequest;
+
+ switch(commandExecutorInput.getRuntimeContext().getRequestContext().getAction()){
+ case Sync:
+ commandRequest = new LCMReadOnlyCommandRequest(commandExecutorInput);
+ break;
+ case Audit:
+ commandRequest = new LCMReadOnlyCommandRequest(commandExecutorInput);
+ break;
+ default:
+ commandRequest = new LCMCommandRequest(commandExecutorInput);
+ break;
+ }
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exiting from getCommandRequest with (CommandRequest = "+ ObjectUtils.toString(commandRequest)+")");
+ }
+ return commandRequest;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void enqueRequest(CommandRequest request) throws APPCException{
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to enqueRequest with CommandRequest = "+ ObjectUtils.toString(request));
+ }
+ try {
+ CommandTask commandTask = getMessageExecutor(request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getAction().name());
+ commandTask.setCommandRequest(request);
+ long remainingTTL = getRemainingTTL(request);
+ executionQueueService.putMessage(commandTask,remainingTTL, TimeUnit.MILLISECONDS);
+ } catch (Exception e) {
+ logger.error("Exception: "+e.getMessage());
+ throw new APPCException(e);
+ }
+
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exiting from enqueRequest");
+ }
+ }
+
+ private long getRemainingTTL(CommandRequest request) {
+ Date requestTimestamp = request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader().getTimeStamp();
+ int ttl = request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader().getFlags().getTtl();
+ return ttl*1000 + requestTimestamp.getTime() - System.currentTimeMillis();
+ }
+
+ private CommandTask getMessageExecutor(String action){
+ if (logger.isTraceEnabled()) {
+ logger.trace("Entering to getMessageExecutor with command = "+ action);
+ }
+ CommandTask executionTask = executionTaskFactory.getExecutionTask(action);
+ if (logger.isTraceEnabled()) {
+ logger.trace("Exiting from getMessageExecutor");
+ }
+ return executionTask;
+ }
+
+
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java
new file mode 100644
index 000000000..6418002c2
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTask.java
@@ -0,0 +1,126 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl;
+
+import static com.att.eelf.configuration.Configuration.MDC_ALERT_SEVERITY;
+import static com.att.eelf.configuration.Configuration.MDC_INSTANCE_UUID;
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
+import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID;
+import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
+
+import java.net.InetAddress;
+
+import org.openecomp.appc.domainmodel.lcm.RuntimeContext;
+import org.openecomp.appc.domainmodel.lcm.Status;
+import org.openecomp.appc.executor.impl.objects.CommandRequest;
+import org.openecomp.appc.executor.objects.CommandResponse;
+import org.openecomp.appc.executor.objects.LCMCommandStatus;
+import org.openecomp.appc.executor.objects.Params;
+import org.openecomp.appc.logging.LoggingConstants;
+import org.openecomp.appc.requesthandler.RequestHandler;
+import org.openecomp.appc.workflow.WorkFlowManager;
+import org.openecomp.appc.workflow.objects.WorkflowRequest;
+import org.openecomp.appc.workflow.objects.WorkflowResponse;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.slf4j.MDC;
+
+/**
+ * This abstract class is base class for all Command tasks. All command task must inherit this class.
+ */
+
+public abstract class CommandTask<M> implements Runnable {
+
+ protected RequestHandler requestHandler;
+ protected WorkFlowManager workflowManager;
+
+ private CommandRequest commandRequest;
+
+ public CommandRequest getCommandRequest() {
+ return commandRequest;
+ }
+
+ public void setCommandRequest(CommandRequest commandRequest) {
+ this.commandRequest = commandRequest;
+ }
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(CommandTask.class);
+
+ public void setWorkflowManager(WorkFlowManager workflowManager) {
+ this.workflowManager = workflowManager;
+ }
+
+ public void setRequestHandler(RequestHandler requestHandler) {
+ this.requestHandler = requestHandler;
+ }
+
+ CommandTask(){
+ }
+
+ public void onRequestCompletion(CommandRequest request, CommandResponse response , boolean isAAIUpdated) {
+ logger.debug("Entry: onRequestCompletion()");
+ requestHandler.onRequestExecutionEnd(request.getCommandExecutorInput().getRuntimeContext(), isAAIUpdated);
+ }
+
+ public abstract void onRequestCompletion(CommandRequest request, CommandResponse response);
+
+ protected CommandResponse buildCommandResponse(CommandRequest request, WorkflowResponse response) {
+
+ CommandResponse commandResponse = new CommandResponse();
+ commandResponse.setRuntimeContext(request.getCommandExecutorInput().getRuntimeContext());
+ return commandResponse;
+ }
+
+
+ public void execute() {
+ final RuntimeContext runtimeContext = commandRequest.getCommandExecutorInput().getRuntimeContext();
+ MDC.put(MDC_KEY_REQUEST_ID, runtimeContext.getRequestContext().getCommonHeader().getRequestId());
+ if (runtimeContext.getRequestContext().getActionIdentifiers().getServiceInstanceId() != null)
+ MDC.put(MDC_SERVICE_INSTANCE_ID, runtimeContext.getRequestContext().getActionIdentifiers().getServiceInstanceId());
+ MDC.put(LoggingConstants.MDCKeys.PARTNER_NAME, runtimeContext.getRequestContext().getCommonHeader().getOriginatorId());
+ MDC.put(MDC_SERVICE_NAME, runtimeContext.getRequestContext().getAction().name());
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getCanonicalHostName()); //Don't change it to a .getLocalHostName() again please. It's wrong!
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ }catch(Exception e){
+ logger.debug(e.getMessage());
+ }
+ MDC.put(MDC_INSTANCE_UUID, ""); //TODO make instanse_UUID generation once during APPC-instanse deploying
+
+ WorkflowRequest workflowRequest = new WorkflowRequest();
+ workflowRequest.setRequestContext(runtimeContext.getRequestContext());
+ workflowRequest.setResponseContext(runtimeContext.getResponseContext());
+ workflowRequest.setVnfContext(runtimeContext.getVnfContext());
+
+ WorkflowResponse response = workflowManager.executeWorkflow(workflowRequest);
+
+ CommandResponse commandResponse = buildCommandResponse(commandRequest, response);
+ this.onRequestCompletion(commandRequest,commandResponse);
+ }
+
+ public static void fillStatus(Status status, LCMCommandStatus lcmCommandStatus, Params params) {
+ status.setCode(lcmCommandStatus.getResponseCode());
+ status.setMessage(lcmCommandStatus.getFormattedMessage(params));
+ }
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java
new file mode 100644
index 000000000..610f0bca3
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommandTaskFactory.java
@@ -0,0 +1,65 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl;
+
+
+import org.openecomp.appc.domainmodel.lcm.VNFOperation;
+import org.openecomp.appc.lifecyclemanager.LifecycleManager;
+import org.openecomp.appc.requesthandler.RequestHandler;
+import org.openecomp.appc.workflow.WorkFlowManager;
+
+
+
+
+public class CommandTaskFactory {
+
+// private LCMCommandTask lcmCommandTask;
+// private LCMReadonlyCommandTask LCMReadonlyCommandTask;
+
+ private RequestHandler requestHandler;
+ private WorkFlowManager workflowManager;
+ private LifecycleManager lifecyclemanager;
+
+
+ public void setWorkflowManager(WorkFlowManager workflowManager) {
+ this.workflowManager = workflowManager;
+ }
+
+ public void setRequestHandler(RequestHandler requestHandler) {
+ this.requestHandler = requestHandler;
+ }
+
+ public void setLifecyclemanager(LifecycleManager lifecyclemanager) {
+ this.lifecyclemanager = lifecyclemanager;
+ }
+
+
+ public synchronized CommandTask getExecutionTask(String action){
+ if (VNFOperation.Sync.toString().equals(action) || VNFOperation.Audit.toString().equals(action)){
+ return new LCMReadonlyCommandTask(requestHandler,workflowManager);
+ }else {
+ return new LCMCommandTask(requestHandler,workflowManager,
+ lifecyclemanager);
+ }
+ }
+
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommonMethods.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommonMethods.java
new file mode 100644
index 000000000..6ecf76c3a
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/CommonMethods.java
@@ -0,0 +1,72 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashMap;
+
+
+class CommonMethods {
+
+ private static final HashMap m = new HashMap();
+
+ static {
+ m.put(34, "&quot;"); // < - less-than
+ m.put(60, "&lt;"); // < - less-than
+ m.put(62, "&gt;"); // > - greater-than
+ m.put(38, "&amp;"); // & - Ampersand
+ }
+
+ static String escapeHtml(String source) {
+ try {
+ StringWriter writer = new StringWriter((int) (source.length() * 1.5));
+ escape(writer, source);
+ return writer.toString();
+ } catch (IOException ioe) {
+ ioe.printStackTrace();
+ return null;
+ }
+ }
+
+ private static void escape(Writer writer, String str) throws IOException {
+ int len = str.length();
+ for (int i = 0; i < len; i++) {
+ char c = str.charAt(i);
+ int ascii = (int) c;
+ String entityName = (String) m.get(ascii);
+ if (entityName == null) {
+ if (c > 0x7F) {
+ writer.write("&#");
+ writer.write(Integer.toString(c, 10));
+ writer.write(';');
+ } else {
+ writer.write(c);
+ }
+ } else {
+ writer.write(entityName);
+ }
+ }
+ }
+
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java
new file mode 100644
index 000000000..fc79c461f
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/ExpiredMessageHandler.java
@@ -0,0 +1,45 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl;
+
+import org.openecomp.appc.executionqueue.MessageExpirationListener;
+import org.openecomp.appc.executor.impl.objects.CommandRequest;
+import org.openecomp.appc.requesthandler.RequestHandler;
+
+
+public class ExpiredMessageHandler<M> implements MessageExpirationListener<M>{
+ private RequestHandler requestHandler;
+
+ public ExpiredMessageHandler(){
+
+ }
+
+ public void setRequestHandler(RequestHandler requestHandler) {
+ this.requestHandler = requestHandler;
+ }
+
+ @Override
+ public void onMessageExpiration(M message) {
+ CommandRequest commandRequest = (CommandRequest)message;
+ requestHandler.onRequestTTLEnd(commandRequest.getCommandExecutorInput().getRuntimeContext(), true);
+ }
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java
new file mode 100644
index 000000000..6e64a546b
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMCommandTask.java
@@ -0,0 +1,261 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl;
+
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.appc.domainmodel.lcm.CommonHeader;
+import org.openecomp.appc.domainmodel.lcm.Status;
+import org.openecomp.appc.domainmodel.lcm.VNFOperation;
+import org.openecomp.appc.executor.UnstableVNFException;
+import org.openecomp.appc.executor.impl.objects.CommandRequest;
+import org.openecomp.appc.executor.impl.objects.LCMCommandRequest;
+import org.openecomp.appc.executor.objects.CommandResponse;
+import org.openecomp.appc.executor.objects.LCMCommandStatus;
+import org.openecomp.appc.executor.objects.Params;
+import org.openecomp.appc.executor.objects.UniqueRequestIdentifier;
+import org.openecomp.appc.lifecyclemanager.LifecycleManager;
+import org.openecomp.appc.lifecyclemanager.objects.LifecycleException;
+import org.openecomp.appc.lifecyclemanager.objects.NoTransitionDefinedException;
+import org.openecomp.appc.lifecyclemanager.objects.VNFOperationOutcome;
+import org.openecomp.appc.requesthandler.RequestHandler;
+import org.openecomp.appc.workflow.WorkFlowManager;
+import org.openecomp.appc.workflow.objects.WorkflowResponse;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.openecomp.sdnc.sli.SvcLogicResource;
+import org.openecomp.sdnc.sli.aai.AAIService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+public class LCMCommandTask extends CommandTask<LCMCommandRequest> {
+
+ private AAIService aaiService;
+ private LifecycleManager lifecyclemanager;
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMCommandTask.class);
+
+ public LCMCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager,
+ LifecycleManager lifecyclemanager){
+ setRequestHandler(requestHandler);
+ setWorkflowManager(workflowManager);
+ setLifecyclemanager(lifecyclemanager);
+ getAAIservice();
+ }
+
+ public void setLifecyclemanager(LifecycleManager lifecyclemanager) {
+ this.lifecyclemanager = lifecyclemanager;
+ }
+
+
+ private void getAAIservice() {
+ BundleContext bctx = FrameworkUtil.getBundle(AAIService.class).getBundleContext();
+ // Get AAIadapter reference
+ ServiceReference sref = bctx.getServiceReference(AAIService.class.getName());
+ if (sref != null) {
+ logger.info("AAIService from bundlecontext");
+ aaiService = (AAIService) bctx.getService(sref);
+
+ } else {
+ logger.info("AAIService error from bundlecontext");
+ logger.warn("Cannot find service reference for org.openecomp.sdnc.sli.aai.AAIService");
+
+ }
+ }
+
+
+ @Override
+ public void onRequestCompletion(CommandRequest request, CommandResponse response) {
+
+ boolean isAAIUpdated = false;
+ try {
+
+ final int statusCode = request.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus().getCode();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("Workflow Execution Status = "+ statusCode);
+ }
+
+ boolean isSuccess = statusCode == 100 || statusCode == 400;
+
+ if (isSuccess && VNFOperation.Terminate == request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getAction()) {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx = getVnfdata(request.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId(), "vnf", ctx);
+ isAAIUpdated = aaiService.deleteGenericVnfData(request.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId(), ctx.getAttribute("vnf.resource-version"));
+ }
+ else{
+ isAAIUpdated = updateAAI(request.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId() , false, isSuccess);
+ }
+ logger.debug("isAAIUpdated = " + isAAIUpdated);
+ }
+ catch(Exception e1) {
+ logger.error("Exception = " + e1);
+ throw new RuntimeException(e1);
+ }
+ finally {
+ super.onRequestCompletion(request, response , isAAIUpdated);
+ }
+ }
+
+ @Override
+ public void run() {
+ LCMCommandRequest request = (LCMCommandRequest)getCommandRequest();
+ boolean isAAIUpdated;
+ final String vnfId = request.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId();
+ final String vnfType = request.getCommandExecutorInput().getRuntimeContext().getVnfContext().getType();
+ try {
+ final CommonHeader commonHeader = request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader();
+ final boolean forceFlag = commonHeader.getFlags().isForce();
+ UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(),
+ commonHeader.getRequestId(), commonHeader.getSubRequestId());
+ String requestIdentifierString = requestIdentifier.toIdentifierString();
+ requestHandler.onRequestExecutionStart(vnfId,false, requestIdentifierString, forceFlag);
+
+ final String currentStatus = request.getCommandExecutorInput().getRuntimeContext().getVnfContext().getStatus();
+ final VNFOperation action = request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getAction();
+
+ final String nextState = lifecyclemanager.getNextState(vnfType, currentStatus, action.name());
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx=getVnfdata(vnfId, "onRequestExecutionStart", ctx);
+ isAAIUpdated= postVnfdata(vnfId, nextState,"onRequestExecutionStart",ctx);
+ } catch (NoTransitionDefinedException e) {
+ logger.error("Error getting Next State for AAI Update: " + e.getMessage(), e);
+ Status status = request.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus();
+ Params params = new Params().addParam("actionName",e.event).addParam("currentState",e.currentState);
+ fillStatus(status, LCMCommandStatus.NO_TRANSITION_DEFINE_FAILURE, params);
+ isAAIUpdated = false;
+ } catch (UnstableVNFException e) {
+ logger.error(e.getMessage(), e);
+ Status status = request.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus();
+ Params params = new Params().addParam("vnfId",vnfId);
+ fillStatus(status, LCMCommandStatus.UNSTABLE_VNF_FAILURE, params);
+ isAAIUpdated = false;
+ }catch (Exception e) {
+ logger.error("Error before Request Execution starts.", e);
+ Status status = request.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus();
+ String errorMsg = StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage();
+ Params params = new Params().addParam("errorMsg",errorMsg);
+ fillStatus(status, LCMCommandStatus.UNEXPECTED_FAILURE, params);
+ isAAIUpdated = false;
+ }
+
+ if (isAAIUpdated){
+ super.execute();
+ }else{
+ String errorMsg = "Error updating A& AI before Workflow execution";
+ logger.error(errorMsg);
+ WorkflowResponse response = new WorkflowResponse();
+ response.setResponseContext(request.getCommandExecutorInput().getRuntimeContext().getResponseContext());
+ CommandResponse commandResponse = super.buildCommandResponse(request, response);
+ this.onRequestCompletion(request,commandResponse);
+ }
+ }
+
+
+
+ private boolean updateAAI(String vnf_id , boolean isTTLEnd , boolean executionStatus)
+ {
+ String orchestrationStatus = null;
+ String nextState;
+ boolean callbackResponse;
+ VNFOperationOutcome outcome;
+ SvcLogicContext ctx = new SvcLogicContext();
+ try {
+ ctx=getVnfdata(vnf_id, "onRequestExecutionEnd",ctx);
+ orchestrationStatus=ctx.getAttribute("onRequestExecutionEnd.orchestration-status");
+
+ if(isTTLEnd){
+ outcome = VNFOperationOutcome.FAILURE;
+ }
+ else if(executionStatus){
+ outcome = VNFOperationOutcome.SUCCESS;
+ }
+ else{
+ outcome = VNFOperationOutcome.FAILURE;
+ }
+ nextState = lifecyclemanager.getNextState(null,orchestrationStatus, outcome.toString()) ;
+ callbackResponse= postVnfdata(vnf_id, nextState,"onRequestExecutionEnd",ctx);
+ logger.debug("AAI posting status: " + callbackResponse);
+
+ } catch (NoTransitionDefinedException e) {
+ logger.debug("Transition not defined for State = " + orchestrationStatus);
+ callbackResponse =false;
+ } catch (LifecycleException e) {
+ logger.debug("State or command not registered with State Machine. State = " + orchestrationStatus);
+ callbackResponse =false;
+ }
+ return callbackResponse;
+ }
+
+
+ private SvcLogicContext getVnfdata(String vnf_id, String prefix,SvcLogicContext ctx) {
+ String key="vnf-id = '"+ vnf_id+"'";
+ logger.debug("inside getVnfdata=== "+key);
+ try {
+ SvcLogicResource.QueryStatus response = aaiService.query("generic-vnf", false, null, key,prefix, null, ctx);
+ if(SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)){
+ logger.warn("VNF " + vnf_id + " not found while updating A&AI");
+ throw new RuntimeException("VNF not found for vnf_id = "+ vnf_id);
+ }
+ else if(SvcLogicResource.QueryStatus.FAILURE.equals(response)){
+ throw new RuntimeException("Error Querying AAI with vnfID = " +vnf_id);
+ }
+ logger.info("AAIResponse: " + response.toString());
+ } catch (SvcLogicException e) {
+ logger.error("Error in getVnfdata "+ e);
+ throw new RuntimeException(e);
+ }
+ return ctx;
+ }
+
+ private boolean postVnfdata(String vnf_id, String status,String prefix,SvcLogicContext ctx) {
+ String key="vnf-id = '"+ vnf_id+"'";
+ logger.debug("inside postVnfdata=== "+key);
+ Map<String, String> data = new HashMap<>();
+ data.put("orchestration-status", status);
+ try {
+ SvcLogicResource.QueryStatus response = aaiService.update("generic-vnf", key, data, prefix, ctx);
+ if(SvcLogicResource.QueryStatus.NOT_FOUND.equals(response)){
+ logger.warn("VNF " + vnf_id + " not found while updating A&AI");
+ return false;
+ }
+ logger.info("AAIResponse: " + response.toString());
+ if(response.toString().equals("SUCCESS"))
+ {
+ return true;
+ }
+ } catch (SvcLogicException e) {
+ logger.error("Error in postVnfdata "+ e);
+ throw new RuntimeException(e);
+ }
+ return false;
+ }
+
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java
new file mode 100644
index 000000000..137a2e4b5
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/LCMReadonlyCommandTask.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl;
+
+
+import org.apache.commons.lang3.StringUtils;
+import org.openecomp.appc.domainmodel.lcm.CommonHeader;
+import org.openecomp.appc.domainmodel.lcm.Status;
+import org.openecomp.appc.executor.UnstableVNFException;
+import org.openecomp.appc.executor.impl.objects.CommandRequest;
+import org.openecomp.appc.executor.impl.objects.LCMCommandRequest;
+import org.openecomp.appc.executor.impl.objects.LCMReadOnlyCommandRequest;
+import org.openecomp.appc.executor.objects.CommandResponse;
+import org.openecomp.appc.executor.objects.LCMCommandStatus;
+import org.openecomp.appc.executor.objects.Params;
+import org.openecomp.appc.executor.objects.UniqueRequestIdentifier;
+import org.openecomp.appc.requesthandler.RequestHandler;
+import org.openecomp.appc.workflow.WorkFlowManager;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class LCMReadonlyCommandTask extends CommandTask<LCMReadOnlyCommandRequest> {
+
+ private static final EELFLogger logger = EELFManager.getInstance().getLogger(LCMReadonlyCommandTask.class);
+
+ public LCMReadonlyCommandTask(RequestHandler requestHandler, WorkFlowManager workflowManager){
+
+ setRequestHandler(requestHandler);
+ setWorkflowManager(workflowManager);
+ }
+
+
+ @Override
+ public void onRequestCompletion(CommandRequest request, CommandResponse response) {
+ super.onRequestCompletion(request, response, true);
+ }
+
+ @Override
+ public void run() {
+ LCMReadOnlyCommandRequest request = (LCMReadOnlyCommandRequest)getCommandRequest();
+ final CommonHeader commonHeader = request.getCommandExecutorInput().getRuntimeContext().getRequestContext().getCommonHeader();
+ final boolean forceFlag = commonHeader.getFlags().isForce();
+ UniqueRequestIdentifier requestIdentifier = new UniqueRequestIdentifier(commonHeader.getOriginatorId(), commonHeader.getRequestId(), commonHeader.getSubRequestId());
+ String requestIdentifierString = requestIdentifier.toIdentifierString();
+ final String vnfId = request.getCommandExecutorInput().getRuntimeContext().getVnfContext().getId();
+ try {
+ requestHandler.onRequestExecutionStart(vnfId,true, requestIdentifierString, forceFlag);
+ super.execute();
+ } catch (UnstableVNFException e) {
+ logger.error(e.getMessage(), e);
+ Status status = request.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus();
+ Params params = new Params().addParam("vnfId",vnfId);
+ fillStatus(status, LCMCommandStatus.UNSTABLE_VNF_FAILURE, params);
+ }catch (Exception e) {
+ logger.error("Error during runing LCMReadonlyCommandTask.", e);
+ Status status = request.getCommandExecutorInput().getRuntimeContext().getResponseContext().getStatus();
+ String errorMsg = StringUtils.isEmpty(e.getMessage()) ? e.toString() : e.getMessage();
+ Params params = new Params().addParam("errorMsg",errorMsg);
+ fillStatus(status, LCMCommandStatus.UNEXPECTED_FAILURE, params);
+ }
+ }
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/CommandRequest.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/CommandRequest.java
new file mode 100644
index 000000000..a1384c7bb
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/CommandRequest.java
@@ -0,0 +1,89 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl.objects;
+
+import java.util.Date;
+
+import org.openecomp.appc.executor.objects.CommandExecutorInput;
+
+@SuppressWarnings("unused")
+public class CommandRequest {
+
+
+ private CommandExecutorInput commandExecutorInput;
+ private Date commandInTimeStamp;
+
+ public CommandRequest(CommandExecutorInput commandExecutorInput) {
+ this.commandExecutorInput = commandExecutorInput;
+ }
+
+
+ public CommandExecutorInput getCommandExecutorInput() {
+ return commandExecutorInput;
+ }
+
+ public void setCommandExecutorInput(CommandExecutorInput commandExecutorInput) {
+ this.commandExecutorInput = commandExecutorInput;
+ }
+
+ public Date getCommandInTimeStamp() {
+ return commandInTimeStamp;
+ }
+
+ public void setCommandInTimeStamp(Date commandInTimeStamp) {
+ this.commandInTimeStamp = commandInTimeStamp;
+ }
+
+ // @Override
+ // public boolean isTTLExpired() {
+ // Calendar tempTimeStamp = addTTLToRequestTime();
+ // long currentTime = System.currentTimeMillis();
+ // long tempTimeStampWithTTL = tempTimeStamp.getTimeInMillis() ;
+ // return currentTime > tempTimeStampWithTTL;
+ // }
+ //
+ // @Override
+ // public int getRemainingTTL(TimeUnit timeunit) {
+ // long tempTimeStampWithTTL = addTTLToRequestTime().getTimeInMillis() ;
+ // long currentTime = System.currentTimeMillis();
+ // long remainingTTL = tempTimeStampWithTTL - currentTime;
+ // return (int)(tempTimeStampWithTTL - currentTime);
+ // }
+ // private Calendar addTTLToRequestTime()
+ // {
+ // Date timeInRequest = this.getCommandInTimeStamp();
+ // int ttlValue = this.getCommandContext().getTtl();
+ // Calendar tempTimeStamp = Calendar.getInstance();
+ // tempTimeStamp.setTime(timeInRequest);
+ // tempTimeStamp.add(Calendar.SECOND, ttlValue);
+ // return tempTimeStamp;
+ // }
+
+
+ @Override
+ public String toString() {
+ return "CommandRequest{" +
+ "commandExecutorInput=" + commandExecutorInput +
+ ", commandInTimeStamp=" + commandInTimeStamp +
+ '}';
+ }
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/LCMCommandRequest.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/LCMCommandRequest.java
new file mode 100644
index 000000000..45111d6c1
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/LCMCommandRequest.java
@@ -0,0 +1,32 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl.objects;
+
+import org.openecomp.appc.executor.objects.CommandExecutorInput;
+
+
+public class LCMCommandRequest extends CommandRequest {
+
+ public LCMCommandRequest(CommandExecutorInput commandExecutorInput) {
+ super(commandExecutorInput);
+ }
+}
diff --git a/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/LCMReadOnlyCommandRequest.java b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/LCMReadOnlyCommandRequest.java
new file mode 100644
index 000000000..4d76973e2
--- /dev/null
+++ b/appc-dispatcher/appc-command-executor/appc-command-executor-core/src/main/java/org/openecomp/appc/executor/impl/objects/LCMReadOnlyCommandRequest.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : APP-C
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights
+ * reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.openecomp.appc.executor.impl.objects;
+
+import org.openecomp.appc.executor.objects.CommandExecutorInput;
+
+
+
+public class LCMReadOnlyCommandRequest extends CommandRequest {
+
+ public LCMReadOnlyCommandRequest(CommandExecutorInput commandExecutorInput) {
+ super(commandExecutorInput);
+ }
+}