aboutsummaryrefslogtreecommitdiffstats
path: root/appc-provider/appc-provider-bundle/src/main/java/org/onap
diff options
context:
space:
mode:
Diffstat (limited to 'appc-provider/appc-provider-bundle/src/main/java/org/onap')
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProvider.java261
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java120
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java1208
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/ResponseHeaderBuilder.java91
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/LCMConstants.java38
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java162
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java94
-rw-r--r--appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java800
8 files changed, 2774 insertions, 0 deletions
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProvider.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProvider.java
new file mode 100644
index 000000000..990576422
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProvider.java
@@ -0,0 +1,261 @@
+/*-
+ * ============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.provider;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.google.common.util.concurrent.Futures;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.EvacuateInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.EvacuateOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.MigrateInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.MigrateOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.ModifyConfigInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.ModifyConfigOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RebuildInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RebuildOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RestartInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RestartOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.SnapshotInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.SnapshotOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.VmstatuscheckInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.VmstatuscheckOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.common.request.header.CommonRequestHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.config.payload.ConfigPayload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.vnf.resource.VnfResource;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.onap.appc.Constants;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.provider.topology.TopologyService;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+/* ADDED FOR FUSION SERVICE CODE */
+
+@SuppressWarnings("JavaDoc")
+/**
+ * Defines the APPC service provider.
+ * <p>
+ * The rpc definition in the YANG model is shown below. This model is used to generate code to manage the inputs and
+ * outputs of the RPC service. For example, the input is defined by a class named {@link ConfigurationOperationInput},
+ * which is generated from the name of the RPC and the "input" definition of the RPC. This class encapsulates the
+ * various objects that are passed to the RPC and is used to obtain values from the input parameters.
+ * </p>
+ * <p>
+ * Likewise, the outputs are defined by a class named {@link ConfigurationOperationOutput}. This class encapsulates the
+ * defined outputs. To make construction of the outputs easier, there are also generated builder classes that are named
+ * for the various elements of the output they "build", such as {@link ConfigurationResponseBuilder}.
+ * </p>
+ *
+ * <pre>
+ * rpc configuration-operation {
+ * description "An operation to view, change, or audit the configuration of a VM";
+ * input {
+ * uses configuration-request-header;
+ * uses configuration-request;
+ * }
+ * output {
+ * uses common-response-header;
+ * uses configuration-response;
+ * }
+ * }
+ * </pre>
+ *
+ */
+public class AppcProvider implements AutoCloseable, AppcProviderService {
+
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderClient.class);
+
+ private final ExecutorService executor;
+
+ /**
+ * The ODL data store broker. Provides access to a conceptual data tree store and also provides the ability to
+ * subscribe for changes to data under a given branch of the tree.
+ */
+ protected DataBroker dataBroker;
+
+ /**
+ * ODL Notification Service that provides publish/subscribe capabilities for YANG modeled notifications.
+ */
+ protected NotificationProviderService notificationService;
+
+ /**
+ * Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
+ */
+ protected RpcProviderRegistry rpcRegistry;
+
+ /**
+ * Represents our RPC implementation registration
+ */
+ protected BindingAwareBroker.RpcRegistration<AppcProviderService> rpcRegistration;
+
+ /**
+ * The configuration
+ */
+ private Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ /**
+ * @param dataBroker2
+ * @param notificationProviderService
+ * @param rpcProviderRegistry
+ */
+ @SuppressWarnings({
+ "javadoc", "nls"
+ })
+ public AppcProvider(DataBroker dataBroker2, NotificationProviderService notificationProviderService,
+ RpcProviderRegistry rpcProviderRegistry) {
+
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ logger.info(Msg.COMPONENT_INITIALIZING, appName, "provider");
+
+ executor = Executors.newFixedThreadPool(1);
+ dataBroker = dataBroker2;
+ notificationService = notificationProviderService;
+ rpcRegistry = rpcProviderRegistry;
+
+ if (rpcRegistry != null) {
+ rpcRegistration = rpcRegistry.addRpcImplementation(AppcProviderService.class, this);
+ }
+
+ logger.info(Msg.COMPONENT_INITIALIZED, appName, "provider");
+ }
+
+ /**
+ * Implements the close of the service
+ *
+ * @see java.lang.AutoCloseable#close()
+ */
+ @SuppressWarnings("nls")
+ @Override
+ public void close() throws Exception {
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ logger.info(Msg.COMPONENT_TERMINATING, appName, "provider");
+ executor.shutdown();
+ if (rpcRegistration != null) {
+ rpcRegistration.close();
+ }
+ logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
+ }
+
+ public Future<RpcResult<ModifyConfigOutput>> modifyConfig(ModifyConfigInput input) {
+ CommonRequestHeader hdr = input.getCommonRequestHeader();
+ ConfigPayload data = input.getConfigPayload();
+ RpcResult<ModifyConfigOutput> result = getTopologyService().modifyConfig(hdr, data);
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Rebuilds a specific VNF
+ *
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#rebuild(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RebuildInput)
+ */
+ @Override
+ public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
+
+ CommonRequestHeader hdr = input.getCommonRequestHeader();
+ VnfResource vnf = input.getVnfResource();
+
+ RpcResult<RebuildOutput> result = getTopologyService().rebuild(hdr, vnf);
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Restarts a specific VNF
+ *
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#restart(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RestartInput)
+ */
+ @Override
+ public Future<RpcResult<RestartOutput>> restart(RestartInput input) {
+ CommonRequestHeader hdr = input.getCommonRequestHeader();
+ VnfResource vnf = input.getVnfResource();
+
+ RpcResult<RestartOutput> result = getTopologyService().restart(hdr, vnf);
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Migrates a specific VNF
+ *
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#migrate(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.MigrateInput)
+ */
+ @Override
+ public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
+ CommonRequestHeader hdr = input.getCommonRequestHeader();
+ VnfResource vnf = input.getVnfResource();
+
+ RpcResult<MigrateOutput> result = getTopologyService().migrate(hdr, vnf);
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Evacuates a specific VNF
+ *
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.EvacuateInput)
+ */
+ @Override
+ public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
+
+ return null;
+ }
+
+ /**
+ * Evacuates a specific VNF
+ *
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.AppcProviderService#evacuate(org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.EvacuateInput)
+ */
+ @Override
+ public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
+ CommonRequestHeader hdr = input.getCommonRequestHeader();
+ VnfResource vnf = input.getVnfResource();
+
+ RpcResult<SnapshotOutput> result = getTopologyService().snapshot(hdr, vnf);
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Checks status of a VM
+ */
+ @Override
+ public Future<RpcResult<VmstatuscheckOutput>> vmstatuscheck(VmstatuscheckInput input) {
+ CommonRequestHeader hdr = input.getCommonRequestHeader();
+ VnfResource vnf = input.getVnfResource();
+
+ TopologyService topology = getTopologyService();
+ RpcResult<VmstatuscheckOutput> result = getTopologyService().vmstatuscheck(hdr, vnf);
+ return Futures.immediateFuture(result);
+ }
+
+ TopologyService getTopologyService() {
+ return new TopologyService(this);
+ }
+} \ No newline at end of file
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java
new file mode 100644
index 000000000..6195521be
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderClient.java
@@ -0,0 +1,120 @@
+/*-
+ * ============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.provider;
+
+import org.onap.appc.util.StringHelper;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.MDC;
+
+import static com.att.eelf.configuration.Configuration.*;
+
+import java.util.Properties;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+public class AppcProviderClient {
+
+ private static EELFLogger LOG = EELFManager.getInstance().getApplicationLogger();
+ private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+
+ private SvcLogicService svcLogic = null;
+
+ public AppcProviderClient() {
+ BundleContext bctx = FrameworkUtil.getBundle(SvcLogicService.class).getBundleContext();
+ //Handle BundleContext returning null
+ if (bctx == null){
+ LOG.warn("Cannot find bundle context for " + SvcLogicService.NAME);
+ }
+ else{
+ // Get SvcLogicService reference
+ ServiceReference sref = bctx.getServiceReference(SvcLogicService.NAME);
+ if (sref != null) {
+ svcLogic = (SvcLogicService) bctx.getService(sref);
+
+ } else {
+ LOG.warn("Cannot find service reference for " + SvcLogicService.NAME);
+
+ }
+ }
+ }
+
+ public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException {
+ LOG.debug(String.format("Checking for graph. %s %s %s %s", module, rpc, version, mode));
+ return (svcLogic.hasGraph(module, rpc, version, mode));
+ }
+
+ public Properties execute(String module, String rpc, String version, String mode, Properties parms)
+ throws SvcLogicException {
+
+ /*
+ * Set End time for Metrics Logger
+ */
+ long startTime = System.currentTimeMillis();
+ TimeZone tz = TimeZone.getTimeZone("UTC");
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
+ df.setTimeZone(tz);
+ String startTimeStr = df.format(new Date());
+ long endTime = System.currentTimeMillis();
+ long duration = endTime - startTime;
+ String endTimeStr = String.valueOf(endTime);
+ String durationStr = String.valueOf(duration);
+ String endTimeStrUTC = df.format(new Date());
+ MDC.put("EndTimestamp", endTimeStrUTC);
+ MDC.put("ElapsedTime", durationStr);
+ MDC.put("TargetEntity", "sli");
+ MDC.put("TargetServiceName", "execute");
+ MDC.put("ClassName", "org.onap.appc.provider.AppcProviderClient");
+
+ LOG.debug("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
+ metricsLogger.info("Parameters passed to SLI: " + StringHelper.propertiesToString(parms));
+
+ Properties respProps = svcLogic.execute(module, rpc, version, mode, parms);
+
+ /*
+ * Set End time for Metrics Logger
+ */
+ endTime = System.currentTimeMillis();
+ duration = endTime - startTime;
+ endTimeStr = String.valueOf(endTime);
+ durationStr = String.valueOf(duration);
+ endTimeStrUTC = df.format(new Date());
+ MDC.put("EndTimestamp", endTimeStrUTC);
+ MDC.put("ElapsedTime", durationStr);
+
+ LOG.debug("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
+ metricsLogger.info("Parameters returned by SLI: " + StringHelper.propertiesToString(respProps));
+
+ return respProps;
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java
new file mode 100644
index 000000000..66e8909bd
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/AppcProviderLcm.java
@@ -0,0 +1,1208 @@
+/*-
+ * ============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.provider;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import com.google.common.util.concurrent.Futures;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
+import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AuditInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AuditOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AuditOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.CheckLockInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.CheckLockOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.CheckLockOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigBackupDeleteInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigBackupDeleteOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigBackupDeleteOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigBackupInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigBackupOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigBackupOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigExportInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigExportOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigExportOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigModifyInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigModifyOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigModifyOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigRestoreInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigRestoreOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigRestoreOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleoutInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleoutOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigScaleoutOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.ConfigureOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.EvacuateInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.EvacuateOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.EvacuateOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.HealthCheckInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.HealthCheckOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.HealthCheckOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LiveUpgradeInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LiveUpgradeOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LiveUpgradeOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LockInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LockOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.LockOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.MigrateInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.MigrateOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.MigrateOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebuildInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebuildOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RebuildOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RestartInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RestartOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RestartOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RollbackInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RollbackOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.RollbackOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SnapshotInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SnapshotOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SnapshotOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SoftwareUploadInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SoftwareUploadOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SoftwareUploadOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SyncInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SyncOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.SyncOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.TerminateInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.TerminateOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.TerminateOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.TestInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.TestOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.TestOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UnlockInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UnlockOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.UnlockOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StartApplicationInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.StopApplicationInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.StatusBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.onap.appc.Constants;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.domainmodel.lcm.ActionLevel;
+import org.onap.appc.domainmodel.lcm.ResponseContext;
+import org.onap.appc.exceptions.APPCException;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.executor.objects.Params;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.logging.LoggingConstants;
+import org.onap.appc.logging.LoggingUtils;
+import org.onap.appc.provider.lcm.util.RequestInputBuilder;
+import org.onap.appc.provider.lcm.util.ValidationService;
+import org.onap.appc.requesthandler.RequestHandler;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import org.onap.appc.requesthandler.objects.RequestHandlerOutput;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.framework.ServiceReference;
+
+import java.text.ParseException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.Collection;
+
+public class AppcProviderLcm implements AutoCloseable, AppcProviderLcmService {
+
+ private Configuration configuration = ConfigurationFactory.getConfiguration();
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(AppcProviderLcm.class);
+
+ private final ExecutorService executor;
+
+ private final String COMMON_ERROR_MESSAGE_TEMPLATE = "Error processing %s input : %s";
+
+ /**
+ * The ODL data store broker. Provides access to a conceptual data tree store and also provides the ability to
+ * subscribe for changes to data under a given branch of the tree.
+ */
+ protected DataBroker dataBroker;
+
+ /**
+ * ODL Notification Service that provides publish/subscribe capabilities for YANG modeled notifications.
+ */
+ protected NotificationProviderService notificationService;
+
+ /**
+ * Provides a registry for Remote Procedure Call (RPC) service implementations. The RPCs are defined in YANG models.
+ */
+ protected RpcProviderRegistry rpcRegistry;
+
+ /**
+ * Represents our RPC implementation registration
+ */
+ protected BindingAwareBroker.RpcRegistration<AppcProviderLcmService> rpcRegistration;
+
+
+ /**
+ * @param dataBroker
+ * @param notificationProviderService
+ * @param rpcProviderRegistry
+ */
+ @SuppressWarnings({
+ "javadoc", "nls"
+ })
+ public AppcProviderLcm(DataBroker dataBroker, NotificationProviderService notificationProviderService,
+ RpcProviderRegistry rpcProviderRegistry) {
+
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ logger.info(Msg.COMPONENT_INITIALIZING, appName, "provider-lcm");
+
+ executor = Executors.newFixedThreadPool(1);
+ this.dataBroker = dataBroker;
+ this.notificationService = notificationProviderService;
+ this.rpcRegistry = rpcProviderRegistry;
+
+ if (this.rpcRegistry != null) {
+ rpcRegistration = rpcRegistry.addRpcImplementation(AppcProviderLcmService.class, this);
+ }
+
+ logger.info(Msg.COMPONENT_INITIALIZED, appName, "provider");
+ }
+
+ /**
+ * Implements the close of the service
+ *
+ * @see java.lang.AutoCloseable#close()
+ */
+ @SuppressWarnings("nls")
+ @Override
+ public void close() throws Exception {
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ logger.info(Msg.COMPONENT_TERMINATING, appName, "provider");
+ executor.shutdown();
+ if (rpcRegistration != null) {
+ rpcRegistration.close();
+ }
+ logger.info(Msg.COMPONENT_TERMINATED, appName, "provider");
+ }
+
+
+ /**
+ * Rebuilds a specific VNF
+ *
+ * @see AppcProviderLcmService#rebuild(RebuildInput)
+ */
+ @Override
+ public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ RebuildOutputBuilder outputBuilder = new RebuildOutputBuilder();
+ String action = Action.Rebuild.toString() ;
+ String rpcName = Action.Rebuild.name().toLowerCase();
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<RebuildOutput> result = RpcResultBuilder.<RebuildOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Restarts a specific VNF
+ *
+ * @see org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.AppcProviderLcmService#restart(RestartInput)
+ */
+ @Override
+ public Future<RpcResult<RestartOutput>> restart(RestartInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ RestartOutputBuilder outputBuilder = new RestartOutputBuilder();
+ String action = Action.Restart.toString() ;
+ String rpcName = Action.Restart.name().toLowerCase();
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload())
+ .action(action)
+ .rpcName(rpcName)
+ .build();
+
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<RestartOutput> result = RpcResultBuilder.<RestartOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Migrates a specific VNF
+ *
+ * @see AppcProviderLcmService#migrate(MigrateInput)
+ */
+ @Override
+ public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ MigrateOutputBuilder outputBuilder = new MigrateOutputBuilder();
+ String action = Action.Migrate.toString() ;
+ String rpcName = Action.Migrate.name().toLowerCase();
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<MigrateOutput> result = RpcResultBuilder.<MigrateOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Evacuates a specific VNF
+ *
+ * @see AppcProviderLcmService#evacuate(EvacuateInput)
+ */
+ @Override
+ public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ EvacuateOutputBuilder outputBuilder = new EvacuateOutputBuilder();
+ String action = Action.Evacuate.toString() ;
+ String rpcName = Action.Evacuate.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<EvacuateOutput> result = RpcResultBuilder.<EvacuateOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+
+ /**
+ * Evacuates a specific VNF
+ *
+ * @see AppcProviderLcmService#snapshot(SnapshotInput)
+ */
+ @Override
+ public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ SnapshotOutputBuilder outputBuilder = new SnapshotOutputBuilder();
+ String action = Action.Snapshot.toString() ;
+ String rpcName = Action.Snapshot.name().toLowerCase();
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ String identityUrl = input.getIdentityUrl();
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName)
+ .additionalContext("identity-url", identityUrl).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<SnapshotOutput> result = RpcResultBuilder.<SnapshotOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<RollbackOutput>> rollback(RollbackInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ RollbackOutputBuilder outputBuilder = new RollbackOutputBuilder();
+ String rpcName = Action.Rollback.toString() ;
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), rpcName);
+ String identityUrl = input.getIdentityUrl();
+ String snapshotId = input.getSnapshotId();
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).additionalContext("identity-url", identityUrl)
+ .additionalContext("snapshot-id", snapshotId).action(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, rpcName, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<RollbackOutput> result = RpcResultBuilder.<RollbackOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<SyncOutput>> sync(SyncInput input) {
+ logger.debug("Input received : " + input.toString());
+ SyncOutputBuilder outputBuilder = new SyncOutputBuilder();
+ String action = Action.Sync.toString() ;
+ String rpcName = Action.Sync.name().toLowerCase();
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<SyncOutput> result = RpcResultBuilder.<SyncOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ private Status buildParsingErrorStatus(ParseException e){
+ LCMCommandStatus requestParsingFailure = LCMCommandStatus.REQUEST_PARSING_FAILED;
+ String errorMessage = e.getMessage() != null ? e.getMessage() : e.toString();
+ Params params = new Params().addParam("errorMsg", errorMessage);
+ return buildStatus(requestParsingFailure.getResponseCode(), requestParsingFailure.getFormattedMessage(params));
+ }
+
+ private Status buildStatus(Integer code,String message){
+ StatusBuilder status = new StatusBuilder();
+ status.setCode(code);
+ status.setMessage(message);
+ return status.build();
+ }
+
+ private Status buildStatusWithDispatcherOutput(RequestHandlerOutput requestHandlerOutput){
+ Integer statusCode = requestHandlerOutput.getResponseContext().getStatus().getCode();
+ String statusMessage = requestHandlerOutput.getResponseContext().getStatus().getMessage();
+ return buildStatus(statusCode, statusMessage);
+ }
+
+ private RequestHandlerOutput createErrorRequestHandlerObj(RequestHandlerInput request,
+ LCMCommandStatus cmdStatus,
+ Msg msg,
+ Exception e) {
+ final String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ final String reason = EELFResourceManager.format(msg, e,
+ appName, e.getClass().getSimpleName(), "", e.getMessage());
+
+ RequestHandlerOutput requestHandlerOutput = new RequestHandlerOutput();
+ final ResponseContext responseContext = new ResponseContext();
+ requestHandlerOutput.setResponseContext(responseContext);
+ responseContext.setCommonHeader(request.getRequestContext().getCommonHeader());
+
+ String errorMessage = e.getMessage() != null ? e.getMessage() : e.toString();
+ Params params = new Params().addParam("errorMsg", errorMessage);
+ responseContext.setStatus(cmdStatus.toStatus(params));
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ reason,
+ this.getClass().getName());
+
+ return requestHandlerOutput;
+ }
+
+ private RequestHandler getRequestHandler(ActionLevel actionLevel){
+ final BundleContext context = FrameworkUtil.getBundle(RequestHandler.class).getBundleContext();
+ if (context != null) {
+ String filter = null;
+ try {
+ filter = "(level=" + actionLevel.name() + ")";
+ Collection<ServiceReference<RequestHandler>> serviceReferences = context.getServiceReferences(RequestHandler.class, filter);
+ if (serviceReferences.size() != 1) {
+ logger.error("Cannot find service reference for " + RequestHandler.class.getName());
+ throw new RuntimeException();
+ }
+ ServiceReference<RequestHandler> serviceReference = serviceReferences.iterator().next();
+ return context.getService(serviceReference);
+ } catch (InvalidSyntaxException e) {
+ logger.error("Cannot find service reference for " + RequestHandler.class.getName() + ": Invalid Syntax " + filter, e);
+ throw new RuntimeException(e);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public Future<RpcResult<TerminateOutput>> terminate(TerminateInput input) {
+ logger.debug("Input received : " + input.toString());
+ TerminateOutputBuilder outputBuilder = new TerminateOutputBuilder();
+ String action = Action.Terminate.toString() ;
+ String rpcName = Action.Terminate.name().toLowerCase();
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<TerminateOutput> result =
+ RpcResultBuilder.<TerminateOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<ConfigureOutput>> configure(ConfigureInput input) {
+ logger.debug("Input received : " + input.toString());
+ ConfigureOutputBuilder outputBuilder = new ConfigureOutputBuilder();
+ String action = Action.Configure.toString() ;
+ String rpcName = "configure";
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<ConfigureOutput> result =
+ RpcResultBuilder.<ConfigureOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<ConfigModifyOutput>> configModify(ConfigModifyInput input) {
+ logger.debug("Input received : " + input.toString());
+ ConfigModifyOutputBuilder outputBuilder = new ConfigModifyOutputBuilder();
+ String action = Action.ConfigModify.toString() ;
+ String rpcName = "config-modify";
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<ConfigModifyOutput> result =
+ RpcResultBuilder.<ConfigModifyOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<ConfigScaleoutOutput>> configScaleout(ConfigScaleoutInput input) {
+ logger.debug("Input received : " + input.toString());
+ ConfigScaleoutOutputBuilder outputBuilder = new ConfigScaleoutOutputBuilder();
+ String action = Action.ConfigScaleOut.toString() ;
+ String rpcName = "config-scaleout";
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<ConfigScaleoutOutput> result =
+ RpcResultBuilder.<ConfigScaleoutOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<ConfigRestoreOutput>> configRestore(ConfigRestoreInput input) {
+ logger.debug("Input received : " + input.toString());
+ ConfigRestoreOutputBuilder outputBuilder = new ConfigRestoreOutputBuilder();
+ String action = Action.ConfigRestore.toString() ;
+ String rpcName = "config-restore";
+ Status status =
+ ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<ConfigRestoreOutput> result =
+ RpcResultBuilder.<ConfigRestoreOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<TestOutput>> test(TestInput input) {
+ logger.debug("Input received : " + input.toString());
+ TestOutputBuilder outputBuilder = new TestOutputBuilder();
+ String action = Action.Test.toString() ;
+ String rpcName = Action.Test.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<TestOutput> result = RpcResultBuilder.<TestOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+
+ @Override
+ public Future<RpcResult<StopOutput>> stop(StopInput input) {
+ logger.debug("Input received : " + input.toString());
+ StopOutputBuilder outputBuilder = new StopOutputBuilder();
+ String action = Action.Stop.toString() ;
+ String rpcName = Action.Stop.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<StopOutput> result = RpcResultBuilder.<StopOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ /**
+ * Starts a specific VNF
+ *
+ * @see AppcProviderLcmService#start(StartInput)
+ */
+ @Override
+ public Future<RpcResult<StartOutput>> start(StartInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ StartOutputBuilder outputBuilder = new StartOutputBuilder();
+ String action = Action.Start.toString() ;
+ String rpcName = Action.Start.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload())
+ .action(action)
+ .rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<StartOutput> result = RpcResultBuilder.<StartOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+
+ @Override
+ public Future<RpcResult<AuditOutput>> audit(AuditInput input) {
+ logger.debug("Input received : " + input.toString());
+ AuditOutputBuilder outputBuilder = new AuditOutputBuilder();
+ String action = Action.Audit.toString();
+ String rpcName = Action.Audit.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<AuditOutput> result = RpcResultBuilder.<AuditOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<SoftwareUploadOutput>> softwareUpload(SoftwareUploadInput input) {
+ logger.debug("Input received : " + input.toString());
+ SoftwareUploadOutputBuilder outputBuilder = new SoftwareUploadOutputBuilder();
+ String action = Action.SoftwareUpload.toString() ;
+ String rpcName = convertActionNameToUrl(action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().
+ requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<SoftwareUploadOutput> result = RpcResultBuilder.<SoftwareUploadOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<HealthCheckOutput>> healthCheck(HealthCheckInput input) {
+ logger.debug("Input received : " + input.toString());
+ HealthCheckOutputBuilder outputBuilder = new HealthCheckOutputBuilder();
+ String action = Action.HealthCheck.toString() ;
+ String rpcName = convertActionNameToUrl(action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<HealthCheckOutput> result = RpcResultBuilder.<HealthCheckOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<LiveUpgradeOutput>> liveUpgrade(LiveUpgradeInput input) {
+ logger.debug("Input received : " + input.toString());
+ LiveUpgradeOutputBuilder outputBuilder = new LiveUpgradeOutputBuilder();
+ String action = Action.LiveUpgrade.toString() ;
+ String rpcName = convertActionNameToUrl(action);
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<LiveUpgradeOutput> result = RpcResultBuilder.<LiveUpgradeOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+
+ @Override
+ public Future<RpcResult<LockOutput>> lock(LockInput input) {
+ logger.debug("Input received : " + input.toString());
+ LockOutputBuilder outputBuilder = new LockOutputBuilder();
+ String action = Action.Lock.toString() ;
+ String rpcName = Action.Lock.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<LockOutput> result = RpcResultBuilder.<LockOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+
+ @Override
+ public Future<RpcResult<UnlockOutput>> unlock(UnlockInput input) {
+ logger.debug("Input received : " + input.toString());
+ UnlockOutputBuilder outputBuilder = new UnlockOutputBuilder();
+ String action = Action.Unlock.toString() ;
+ String rpcName = Action.Unlock.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<UnlockOutput> result = RpcResultBuilder.<UnlockOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<CheckLockOutput>> checkLock(CheckLockInput input) {
+ logger.debug("Input received : " + input.toString());
+ CheckLockOutputBuilder outputBuilder = new CheckLockOutputBuilder();
+ String action = Action.CheckLock.toString();
+ String rpcName = Action.CheckLock.name().toLowerCase();
+ RequestHandlerOutput requestHandlerOutput = null;
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(),
+ input.getAction(), action);
+ if (null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input
+ .getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action)
+ .rpcName(rpcName).build();
+ requestHandlerOutput = executeRequest(request);
+
+ status = buildStatusWithDispatcherOutput(requestHandlerOutput);
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s",
+ input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ if (requestHandlerOutput != null && requestHandlerOutput.getResponseContext().getStatus().getCode() == 400) {
+ outputBuilder.setLocked(CheckLockOutput.Locked.valueOf(requestHandlerOutput.getResponseContext()
+ .getAdditionalContext().get("locked").toUpperCase()));
+ }
+ RpcResult<CheckLockOutput> result = RpcResultBuilder.<CheckLockOutput>status(true)
+ .withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ @Override
+ public Future<RpcResult<ConfigBackupOutput>> configBackup(ConfigBackupInput input) {
+ logger.debug("Input received : " + input.toString());
+ ConfigBackupOutputBuilder outputBuilder = new ConfigBackupOutputBuilder();
+ String action = Action.ConfigBackup.toString() ;
+ String rpcName = Action.ConfigBackup.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<ConfigBackupOutput> result = RpcResultBuilder.<ConfigBackupOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+
+ @Override
+ public Future<RpcResult<ConfigBackupDeleteOutput>> configBackupDelete(ConfigBackupDeleteInput input) {
+ logger.debug("Input received : " + input.toString());
+ ConfigBackupDeleteOutputBuilder outputBuilder = new ConfigBackupDeleteOutputBuilder();
+ String action = Action.ConfigBackupDelete.toString() ;
+ String rpcName = Action.ConfigBackupDelete.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<ConfigBackupDeleteOutput> result = RpcResultBuilder.<ConfigBackupDeleteOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+
+ @Override
+ public Future<RpcResult<ConfigExportOutput>> configExport(ConfigExportInput input) {
+ logger.debug("Input received : " + input.toString());
+ ConfigExportOutputBuilder outputBuilder = new ConfigExportOutputBuilder();
+ String action = Action.ConfigExport.toString() ;
+ String rpcName = Action.ConfigExport.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<ConfigExportOutput> result = RpcResultBuilder.<ConfigExportOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+ @Override
+ public Future<RpcResult<StartApplicationOutput>> startApplication(StartApplicationInput input) {
+ logger.debug("Input received : " + input.toString());
+
+ StartApplicationOutputBuilder outputBuilder = new StartApplicationOutputBuilder();
+ String action = Action.StartApplication.toString() ;
+ String rpcName = Action.StartApplication.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext()
+ .commonHeader(input.getCommonHeader())
+ .actionIdentifiers(input.getActionIdentifiers())
+ .payload(input.getPayload())
+ .action(action)
+ .rpcName(rpcName)
+ .build();
+
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<StartApplicationOutput> result = RpcResultBuilder.<StartApplicationOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+ @Override
+ public Future<RpcResult<StopApplicationOutput>> stopApplication(StopApplicationInput input){
+ logger.debug("Input received : " + input.toString());
+ StopApplicationOutputBuilder outputBuilder = new StopApplicationOutputBuilder();
+ String action = Action.StopApplication.toString() ;
+ String rpcName = Action.StopApplication.name().toLowerCase();
+ Status status = ValidationService.getInstance().validateInput(input.getCommonHeader(), input.getAction(), action);
+ if(null == status) {
+ try {
+ RequestHandlerInput request = new RequestInputBuilder().requestContext().commonHeader(input.getCommonHeader()).actionIdentifiers(input.getActionIdentifiers()).payload(input.getPayload()).action(action).rpcName(rpcName).build();
+ status = buildStatusWithDispatcherOutput(executeRequest(request));
+ logger.info(String.format("Execute of '%s' finished with status %s. Reason: %s", input.getActionIdentifiers(), status.getCode(), status.getMessage()));
+ } catch (ParseException e) {
+ status = buildParsingErrorStatus(e);
+
+ LoggingUtils.logErrorMessage(
+ LoggingConstants.TargetNames.APPC_PROVIDER,
+ String.format(COMMON_ERROR_MESSAGE_TEMPLATE, action, e.getMessage()),
+ this.getClass().getName());
+
+ }
+ }
+ outputBuilder.setCommonHeader(input.getCommonHeader());
+ outputBuilder.setStatus(status);
+ RpcResult<StopApplicationOutput> result = RpcResultBuilder.<StopApplicationOutput> status(true).withResult(outputBuilder.build()).build();
+ return Futures.immediateFuture(result);
+ }
+
+ private String convertActionNameToUrl(String action) {
+ String regex = "([a-z])([A-Z]+)";
+ String replacement = "$1-$2";
+ return action.replaceAll(regex, replacement)
+ .toLowerCase();
+ }
+
+ RequestHandlerOutput executeRequest(RequestHandlerInput request){
+ RequestHandler handler = getRequestHandler(request.getRequestContext().getActionLevel());
+ RequestHandlerOutput requestHandlerOutput;
+ if (handler != null) {
+ try {
+ requestHandlerOutput = handler.handleRequest(request);
+ } catch (Exception e) {
+ logger.info("UNEXPECTED FAILURE while executing " + request.getRequestContext().getAction().name());
+ requestHandlerOutput = createErrorRequestHandlerObj(request,
+ LCMCommandStatus.UNEXPECTED_ERROR, Msg.EXCEPTION_CALLING_DG, e);
+ }
+ } else {
+ String errorMsg = "LCM request cannot be processed at the moment because APPC isn't running";
+ requestHandlerOutput = createErrorRequestHandlerObj(request,
+ LCMCommandStatus.REJECTED, Msg.REQUEST_HANDLER_UNAVAILABLE, new APPCException(errorMsg));
+ }
+ return requestHandlerOutput;
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/ResponseHeaderBuilder.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/ResponseHeaderBuilder.java
new file mode 100644
index 000000000..7c479ddc0
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/ResponseHeaderBuilder.java
@@ -0,0 +1,91 @@
+/*-
+ * ============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.provider;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.TIMESTAMP;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.common.response.header.CommonResponseHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.common.response.header.CommonResponseHeaderBuilder;
+import org.onap.appc.util.Time;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+
+
+/**
+ * Builds the responses from the APP-C services according to the YANG domainmodel
+ *
+ * @since Nov 16, 2015
+ * @version $Id$
+ */
+public class ResponseHeaderBuilder {
+
+ /**
+ * The date/time formatter to format timestamps.
+ */
+ @SuppressWarnings("nls")
+ public static final DateFormat FORMATTER = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSSSS");
+ public static final DateFormat ZULU_FORMATTER = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SS'Z'");
+
+ /**
+ * Private default constructor prevents instantiation
+ */
+ private ResponseHeaderBuilder() {
+ }
+
+ /**
+ * This method builds the common response header and returns it to the caller for integration into the response
+ *
+ * @param success
+ * True or false indicating the outcome of the operation. True indicates that the operation was
+ * successful, false indicates it failed.
+ * @param requestId
+ * The original request id for the service
+ * @param reason
+ * The reason for the failure if the success flag is false. If success is true, the reason is not used.
+ * @param duration
+ * The duration of the request processing
+ * @return The common response header to be returned to the caller.
+ */
+ @SuppressWarnings("nls")
+ public static CommonResponseHeader buildHeader(Boolean success, String requestId, String reason, long duration) {
+ CommonResponseHeaderBuilder builder = new CommonResponseHeaderBuilder();
+
+ TIMESTAMP timestamp = new TIMESTAMP(FORMATTER.format(Time.utcDate()));
+ builder.setServiceRequestId(requestId);
+ builder.setCompleted(timestamp);
+ builder.setDuration(duration);
+ builder.setSuccess(success);
+
+ if (success.equals(Boolean.TRUE)) {
+ builder.setReason("Success");
+ } else {
+ builder.setReason(reason);
+ }
+
+ return builder.build();
+ }
+
+
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/LCMConstants.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/LCMConstants.java
new file mode 100644
index 000000000..40e632e7f
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/LCMConstants.java
@@ -0,0 +1,38 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Copyright (C) 2017 Amdocs
+ * =============================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.appc.provider.lcm.util;
+
+public final class LCMConstants {
+ private LCMConstants() {
+ }
+
+ public static final String CODE = "Status";
+ public static final String VALUE = "Value";
+ //flags
+ public static final String FORCE = "FORCE";
+ public static final String MODE = "MODE";
+ public static final String TTL = "TTL";
+
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java
new file mode 100644
index 000000000..979c834de
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/RequestInputBuilder.java
@@ -0,0 +1,162 @@
+/*-
+ * ============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.provider.lcm.util;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
+
+import org.apache.commons.lang.StringUtils;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Payload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.action.identifiers.ActionIdentifiers;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.common.header.Flags;
+import org.onap.appc.domainmodel.lcm.Flags.Mode;
+import org.onap.appc.domainmodel.lcm.ActionLevel;
+import org.onap.appc.domainmodel.lcm.RequestContext;
+import org.onap.appc.domainmodel.lcm.VNFOperation;
+import org.onap.appc.requesthandler.objects.RequestHandlerInput;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+
+
+public class RequestInputBuilder {
+ private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
+
+ private static final String FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+
+ private RequestContext requestContext;
+ private String rpcName;
+
+ public RequestInputBuilder() {
+ }
+
+
+ public RequestInputBuilder requestContext() {
+ this.requestContext = new RequestContext();
+ return this;
+ }
+
+ public RequestInputBuilder action(String action) {
+ this.requestContext.setAction(VNFOperation.findByString(action));
+ return this;
+ }
+
+
+ public RequestInputBuilder additionalContext(String key, String value) {
+ this.requestContext.addKeyValueToAdditionalContext(key, value);
+ return this;
+ }
+
+ public RequestInputBuilder payload(Payload payload) {
+ if (payload != null) {
+ this.requestContext.setPayload(payload.getValue());
+ }
+ return this;
+ }
+
+ public RequestHandlerInput build (){
+ RequestHandlerInput request = new RequestHandlerInput();
+ request.setRequestContext(this.requestContext);
+ request.setRpcName(rpcName);
+ return request;
+ }
+
+ public RequestInputBuilder rpcName(String rpcName) {
+ this.rpcName = rpcName;
+ return this;
+ }
+
+ public RequestInputBuilder commonHeader(CommonHeader commonHeader) throws ParseException {
+ org.onap.appc.domainmodel.lcm.CommonHeader header = new org.onap.appc.domainmodel.lcm.CommonHeader();
+ this.requestContext.setCommonHeader(header);
+
+ try {
+ if(null != commonHeader.getTimestamp()) {
+ SimpleDateFormat format = new SimpleDateFormat(FORMAT);
+ format.setLenient(false);
+ format.setTimeZone(TimeZone.getTimeZone("UTC"));
+ header.setTimestamp(format.parse(commonHeader.getTimestamp().getValue()).toInstant());
+ }else{
+ throw new ParseException("Missing mandatory parameter : timestamp " , 0);
+ }
+ } catch (ParseException e) {
+ logger.error(String.format("DATE format is incorrect: %s", e.getMessage()));
+ throw e;
+ }
+ header.setApiVer(commonHeader.getApiVer());
+ header.setRequestId(commonHeader.getRequestId());
+ header.setOriginatorId(commonHeader.getOriginatorId());
+ header.setSubRequestId(commonHeader.getSubRequestId());
+
+ Flags inFlags = commonHeader.getFlags();
+ boolean force = false;
+ Mode mode = null;
+ int ttl = 0;
+ if (inFlags != null) {
+
+ if (null != inFlags.getForce()) {
+ force = Boolean.parseBoolean(inFlags.getForce().toString().toLowerCase());
+ }
+ if (null != inFlags.getMode()) {
+ mode = Mode.valueOf(inFlags.getMode().name());
+ }
+ if (null != inFlags.getTtl()) {
+ ttl = inFlags.getTtl();
+ }
+
+ }
+ this.requestContext.getCommonHeader().setFlags(new org.onap.appc.domainmodel.lcm.Flags(mode, force, ttl));
+ return this;
+ }
+
+ public RequestInputBuilder actionIdentifiers(ActionIdentifiers actionIdentifiers) throws ParseException {
+ if(null!= actionIdentifiers) {
+ org.onap.appc.domainmodel.lcm.ActionIdentifiers actionIds = new org.onap.appc.domainmodel.lcm.ActionIdentifiers();
+ actionIds.setServiceInstanceId(actionIdentifiers.getServiceInstanceId());
+ actionIds.setVnfcName(actionIdentifiers.getVnfcName());
+ actionIds.setvServerId(actionIdentifiers.getVserverId());
+ actionIds.setVnfId(actionIdentifiers.getVnfId());
+ actionIds.setVfModuleId(actionIdentifiers.getVfModuleId());
+ this.requestContext.setActionIdentifiers(actionIds);
+
+ ActionLevel actionLevel = readActionLevel(actionIds);
+ this.requestContext.setActionLevel(actionLevel);
+ return this;
+ }else{
+ throw new ParseException("Missing action identifier" , 0);
+ }
+ }
+
+ private ActionLevel readActionLevel(org.onap.appc.domainmodel.lcm.ActionIdentifiers actionIds) {
+ if(!StringUtils.isEmpty(actionIds.getVserverId())){
+ return ActionLevel.VM;
+ }
+ return ActionLevel.VNF;
+ }
+
+
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java
new file mode 100644
index 000000000..69e100b57
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/lcm/util/ValidationService.java
@@ -0,0 +1,94 @@
+/*-
+ * ============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.provider.lcm.util;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.Action;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.common.header.CommonHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.Status;
+import org.opendaylight.yang.gen.v1.org.onap.appc.lcm.rev160108.status.StatusBuilder;
+import org.onap.appc.Constants;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.executor.objects.LCMCommandStatus;
+import org.onap.appc.executor.objects.Params;
+import org.onap.appc.i18n.Msg;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+
+import javax.swing.*;
+
+
+
+public class ValidationService {
+
+ private static class ValidationServiceHolder {
+ private static final ValidationService INSTANCE = new ValidationService();
+ }
+
+ private final EELFLogger logger = EELFManager.getInstance().getLogger(ValidationService.class);
+
+ private Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ public static ValidationService getInstance(){
+ return ValidationServiceHolder.INSTANCE;
+ }
+
+ public Status validateInput (CommonHeader commonHeader, Action action , String rpcName) {
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ String reason ;
+ StringBuilder paramName = new StringBuilder("");
+ if (!isEmpty(commonHeader) && !isEmpty(commonHeader.getApiVer())&& !isEmpty(commonHeader.getTimestamp()) && !isEmpty(commonHeader.getRequestId()) && !isEmpty(action) && !isEmpty(commonHeader.getOriginatorId())){
+ if(!action.toString().equalsIgnoreCase(rpcName)) logger.warn("action in input request '" + action.toString() + "' is different from endpoint '" + rpcName + "'");
+ return null;
+ } else{
+ if(isEmpty(commonHeader)){
+ paramName.append("common-header");
+ }else{
+ if (isEmpty(commonHeader.getApiVer())) paramName.append("api-ver");
+ if (isEmpty(commonHeader.getTimestamp())) paramName.append(isEmpty(paramName) ? "timestamp" : " , timestamp" );
+ if (isEmpty(commonHeader.getRequestId())) paramName.append(isEmpty(paramName) ? "request-id" : " , request-id" );
+ if (isEmpty(commonHeader.getOriginatorId())) paramName.append(isEmpty(paramName) ? "originator-id" : " , originator-id" );
+ }
+ if (isEmpty(action)) paramName.append(isEmpty(paramName) ? "action" : " , action" );
+ }
+
+
+
+ reason = EELFResourceManager.format(Msg.NULL_OR_INVALID_ARGUMENT, appName, rpcName, paramName.toString() , "");
+ logger.info("Mandatory parameter/s" + paramName.toString() + " is/are missing");
+ logger.error(reason);
+ LCMCommandStatus lcmCommandStatus = LCMCommandStatus.MISSING_MANDATORY_PARAMETER;
+ Params params = new Params().addParam("paramName", paramName.toString());
+ StatusBuilder status = new StatusBuilder();
+ status.setCode(lcmCommandStatus.getResponseCode());
+ status.setMessage(lcmCommandStatus.getFormattedMessage(params));
+ return status.build();
+ }
+
+ private boolean isEmpty (Object object){
+ return (null == object || "".equalsIgnoreCase(object.toString()));
+ }
+}
diff --git a/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java
new file mode 100644
index 000000000..ea1d3f1ee
--- /dev/null
+++ b/appc-provider/appc-provider-bundle/src/main/java/org/onap/appc/provider/topology/TopologyService.java
@@ -0,0 +1,800 @@
+/*-
+ * ============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.provider.topology;
+
+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_REMOTE_HOST;
+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 java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.Properties;
+import java.util.TimeZone;
+
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.MigrateOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.ModifyConfigOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.ModifyConfigOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.MigrateOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RebuildOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RebuildOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RestartOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.RestartOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.SnapshotOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.SnapshotOutputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.UUID;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.common.request.header.CommonRequestHeader;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.vnf.resource.VnfResource;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.config.payload.ConfigPayload;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.VmstatuscheckOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.rev160104.VmstatuscheckOutputBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.onap.appc.Constants;
+import org.onap.appc.configuration.Configuration;
+import org.onap.appc.configuration.ConfigurationFactory;
+import org.onap.appc.i18n.Msg;
+import org.onap.appc.provider.AppcProvider;
+import org.onap.appc.provider.AppcProviderClient;
+import org.onap.appc.provider.ResponseHeaderBuilder;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.att.eelf.i18n.EELFResourceManager;
+import org.slf4j.MDC;
+
+/**
+ * This class is used to implement the topology services API and invoke the appropriate directed graphs based on the
+ * service being requested.
+ *
+ */
+public class TopologyService {
+
+ /**
+ * The loggers we are using
+ */
+ // private static EELFLogger logger = LoggerFactory.getLogger(TopologyService.class);
+ private static EELFLogger logger = EELFManager.getInstance().getApplicationLogger();
+ private static EELFLogger securityLogger = EELFManager.getInstance().getSecurityLogger();
+ private static EELFLogger auditLogger = EELFManager.getInstance().getAuditLogger();
+ private static EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
+ private static EELFLogger performanceLogger = EELFManager.getInstance().getPerformanceLogger();
+
+ /**
+ * The provider we are servicing
+ */
+ private AppcProvider provider;
+
+ /**
+ * The reason associated with the last DG call
+ */
+ private String reason;
+
+ /**
+ * The APPC configuration properties
+ */
+ private Configuration configuration = ConfigurationFactory.getConfiguration();
+
+ /**
+ * Create the topology services implementation for the specific appc provider (api) implementation
+ *
+ * @param provider
+ * The provider we are servicing
+ */
+ public TopologyService(AppcProvider provider) {
+ this.provider = provider;
+ }
+
+ // /**
+ // * Processes the topology request
+ // *
+ // * @param input
+ // * The request to be processed
+ // * @return The result of processing
+ // */
+ // public RpcResult<TopologyOperationOutput> process(TopologyOperationInput input) {
+ // RpcResult<TopologyOperationOutput> response;
+ //
+ // String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ // logger.info(String.format("%s:topology operations called...", appName));
+ //
+ // /*
+ // * Properties used to pass information to the DG
+ // */
+ // Properties properties = new Properties();
+ //
+ // if (input == null || input.getTopologyRequest().getVmId() == null) {
+ // String msg =
+ // String.format("%s: topology operation failed, invalid input. Null or empty argument '%s'", appName,
+ // "vm_id");
+ // logger.debug(msg);
+ // response = generateTopologyOperationResponse(Boolean.FALSE, "UNKNOWN", msg, "UNDEFINED");
+ // } else {
+ // // CommonRequestHeader crh = input.getCommonRequestHeader();
+ // TopologyHeader hdr = input.getTopologyHeader();
+ // TopologyRequest req = input.getTopologyRequest();
+ //
+ // // String requestId = crh.getServiceRequestId();
+ // String requestId = hdr.getSvcRequestId();
+ // properties.put(Constants.CONTEXT_REQID, requestId);
+ //
+ // String infomsg = String.format("Topology request '%s' (%s) received.", requestId, hdr.getSvcAction());
+ //
+ // // switch (req.getSvcAction()) {
+ // switch (hdr.getSvcAction()) {
+ // case Restart:
+ // properties.put(Constants.CONTEXT_SERVICE, Constants.SERVICE_RESTART);
+ // response = restart(input, properties);
+ // logger.info(infomsg);
+ // break;
+ //
+ // case Rebuild:
+ // properties.put(Constants.CONTEXT_SERVICE, Constants.SERVICE_REBUILD);
+ // response = rebuild(input, properties);
+ // logger.info(infomsg);
+ // break;
+ //
+ // default:
+ // String msg = String.format("Invalid request type [%s] for request id [%s]", req, requestId);
+ // response = generateTopologyOperationResponse(Boolean.FALSE, requestId, msg, "N/A");
+ // }
+ // }
+ //
+ // return response;
+ // }
+
+ /**
+ * Restart a VM
+ *
+ * @param hdr
+ * The common request header
+ * @param vnf
+ * The identification of the VNF resource to be operated upon
+ * @return The rpc result of the restart operation
+ */
+ public RpcResult<ModifyConfigOutput> modifyConfig(CommonRequestHeader hdr, ConfigPayload data) {
+ long startTime = System.currentTimeMillis();
+ TimeZone tz = TimeZone.getTimeZone("UTC");
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
+ df.setTimeZone(tz);
+ // String startTimeStr = String.valueOf(startTime);
+ String startTimeStr = df.format(new Date());
+ String requestId = hdr.getServiceRequestId();
+
+ //MDC.clear();
+ MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ MDC.put(MDC_SERVICE_NAME, "App-C Provider:Restart");
+ MDC.put(MDC_SERVICE_INSTANCE_ID, "");
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ MDC.put(MDC_INSTANCE_UUID, java.util.UUID.randomUUID().toString());
+ MDC.put(MDC_ALERT_SEVERITY, "0");
+ MDC.put("startTime", Long.toString(startTime));
+ MDC.put("target", "appc");
+ logger.info(String.format("Starting RESTART for request with id [%s]", requestId));
+ metricsLogger.info(String.format("Metrics Logger: App-C Restart initiated. Start Time: [%s]. Request ID: [%s]",
+ startTime, requestId));
+
+ /*
+ * Copy any needed inputs or other values into the properties to be passed to the DG model
+ */
+ //UUID vmId = vnf.getVmId();
+ Properties properties = new Properties();
+ properties.put(Constants.CONTEXT_ACTION, "modifyConfig");
+ properties.put(Constants.CONTEXT_REQID, requestId);
+ //properties.put(Constants.CONTEXT_VMID, vmId.getValue());
+ String url = configuration.getProperty("appc.provider.vfodl.url");
+ try{
+ if(url.contains("NODE_NAME")){
+ url = url.replace("NODE_NAME", data.getConfigUrl());
+ }
+ }catch(Exception e){
+ url = configuration.getProperty("appc.provider.vfodl.url");
+ }
+ logger.trace("Final URL to VF ODL: "+url);
+ properties.put("org.onap.appc.configURL", url);
+ properties.put("org.onap.appc.configJson", data.getConfigJson());
+
+ //UUID identityUrl = vnf.getIdentityUrl();
+ //if (identityUrl != null) {
+ // properties.put(Constants.CONTEXT_IDENTITY_URL, identityUrl.getValue());
+ //}
+ /*
+ * Attempt to call the DG with the appropriate properties
+ */
+ boolean success = callGraph(properties);
+
+
+ MDC.put("target", "appc");
+ String statusStr = success ? "SUCCESS" : "FAILURE";
+ String infomsg =
+ String.format("APPC0119I ModifyConfig '%s' finished with status %s. Reason: %s", requestId, statusStr, reason);
+ logger.info(infomsg);
+
+ ModifyConfigOutputBuilder rob = new ModifyConfigOutputBuilder();
+ long endTime = System.currentTimeMillis();
+ long duration = endTime - startTime;
+ String endTimeStr = String.valueOf(endTime);
+ String durationStr = String.valueOf(duration);
+ MDC.put("endTime", endTimeStr);
+ MDC.put("duration", durationStr);
+ rob.setCommonResponseHeader(ResponseHeaderBuilder.buildHeader(success, requestId, reason, duration));
+ //rob.setVmId(new UUID(vmId));
+
+ auditLogger.info(String.format(
+ "Audit Logger: APPC0119I Restart '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+ metricsLogger.info(String.format(
+ "Metrics Logger: APPC0119I Restart '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+
+ // Status must be set to true to indicate that our return is expected
+ RpcResult<ModifyConfigOutput> rpcResult =
+ RpcResultBuilder.<ModifyConfigOutput> status(true).withResult(rob.build()).build();
+ return rpcResult;
+
+ }
+
+
+
+
+ /**
+ * Restart a VM
+ *
+ * @param hdr
+ * The common request header
+ * @param vnf
+ * The identification of the VNF resource to be operated upon
+ * @return The rpc result of the restart operation
+ */
+ public RpcResult<MigrateOutput> migrate(CommonRequestHeader hdr, VnfResource vnf) {
+ long startTime = System.currentTimeMillis();
+ TimeZone tz = TimeZone.getTimeZone("UTC");
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
+ df.setTimeZone(tz);
+ // String startTimeStr = String.valueOf(startTime);
+ String startTimeStr = df.format(new Date());
+ String requestId = hdr.getServiceRequestId();
+
+ //MDC.clear();
+ MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ MDC.put(MDC_SERVICE_NAME, "App-C Provider:Migrate");
+ MDC.put(MDC_SERVICE_INSTANCE_ID, "");
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ MDC.put(MDC_INSTANCE_UUID, java.util.UUID.randomUUID().toString());
+ MDC.put(MDC_ALERT_SEVERITY, "0");
+ MDC.put("startTime", startTimeStr);
+ MDC.put("target", "appc");
+ logger.info(String.format("Starting ANY for request with id [%s]", requestId));
+ metricsLogger.info(String.format("Metrics Logger: App-C Restart initiated. Start Time: [%s]. Request ID: [%s]",
+ startTime, requestId));
+
+ /*
+ * Copy any needed inputs or other values into the properties to be passed to the DG model
+ */
+ UUID vmId = vnf.getVmId();
+ Properties properties = new Properties();
+ properties.put(Constants.CONTEXT_ACTION, "migrate");
+ properties.put(Constants.CONTEXT_REQID, requestId);
+ properties.put(Constants.CONTEXT_VMID, vmId.getValue());
+
+ UUID identityUrl = vnf.getIdentityUrl();
+ if (identityUrl != null) {
+ properties.put(Constants.CONTEXT_IDENTITY_URL, identityUrl.getValue());
+ }
+
+ /*
+ * Attempt to call the DG with the appropriate properties
+ */
+ boolean success = callGraph(properties);
+
+ /*
+ * Generate the appropriate response
+ */
+ MDC.put("target", "appc");
+ String statusStr = success ? "SUCCESS" : "FAILURE";
+ String infomsg =
+ String.format("APPC0118I Migrate '%s' finished with status %s. Reason: %s", requestId, statusStr, reason);
+ logger.info(infomsg);
+
+ MigrateOutputBuilder mob = new MigrateOutputBuilder();
+
+ long endTime = System.currentTimeMillis();
+ long duration = endTime - startTime;
+ String endTimeStr = String.valueOf(endTime);
+ String durationStr = String.valueOf(duration);
+ MDC.put("endTime", endTimeStr);
+ MDC.put("duration", durationStr);
+ mob.setCommonResponseHeader(ResponseHeaderBuilder.buildHeader(success, requestId, reason, duration));
+ mob.setVmId(new UUID(vmId));
+
+ auditLogger.info(String.format(
+ "Audit Logger: APPC0118I Migrate '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+ metricsLogger.info(String.format(
+ "Metrics Logger: APPC0118I Migrate '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+
+ // Status must be set to true to indicate that our return is expected
+ RpcResult<MigrateOutput> rpcResult =
+ RpcResultBuilder.<MigrateOutput> status(true).withResult(mob.build()).build();
+ return rpcResult;
+ }
+
+ /**
+ * Restart a VM
+ *
+ * @param hdr
+ * The common request header
+ * @param vnf
+ * The identification of the VNF resource to be operated upon
+ * @return The rpc result of the restart operation
+ */
+ public RpcResult<RestartOutput> restart(CommonRequestHeader hdr, VnfResource vnf) {
+ long startTime = System.currentTimeMillis();
+ TimeZone tz = TimeZone.getTimeZone("UTC");
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
+ df.setTimeZone(tz);
+ // String startTimeStr = String.valueOf(startTime);
+ String startTimeStr = df.format(new Date());
+ String requestId = hdr.getServiceRequestId();
+
+ //MDC.clear();
+ MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ MDC.put(MDC_SERVICE_NAME, "App-C Provider:Restart");
+ MDC.put(MDC_SERVICE_INSTANCE_ID, "");
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ MDC.put(MDC_INSTANCE_UUID, java.util.UUID.randomUUID().toString());
+ MDC.put(MDC_ALERT_SEVERITY, "0");
+ MDC.put("startTime", Long.toString(startTime));
+ MDC.put("target", "appc");
+ logger.info(String.format("Starting RESTART for request with id [%s]", requestId));
+ metricsLogger.info(String.format("Metrics Logger: App-C Restart initiated. Start Time: [%s]. Request ID: [%s]",
+ startTime, requestId));
+
+ /*
+ * Copy any needed inputs or other values into the properties to be passed to the DG model
+ */
+ UUID vmId = vnf.getVmId();
+ Properties properties = new Properties();
+ properties.put(Constants.CONTEXT_ACTION, "restart");
+ properties.put(Constants.CONTEXT_REQID, requestId);
+ properties.put(Constants.CONTEXT_VMID, vmId.getValue());
+
+ UUID identityUrl = vnf.getIdentityUrl();
+ if (identityUrl != null) {
+ properties.put(Constants.CONTEXT_IDENTITY_URL, identityUrl.getValue());
+ }
+ /*
+ * Attempt to call the DG with the appropriate properties
+ */
+ boolean success = callGraph(properties);
+
+ /*
+ * Generate the appropriate response
+ */
+ MDC.put("target", "appc");
+ String statusStr = success ? "SUCCESS" : "FAILURE";
+ String infomsg =
+ String.format("APPC0119I Restart '%s' finished with status %s. Reason: %s", requestId, statusStr, reason);
+ logger.info(infomsg);
+
+ RestartOutputBuilder rob = new RestartOutputBuilder();
+ long endTime = System.currentTimeMillis();
+ long duration = endTime - startTime;
+ String endTimeStr = String.valueOf(endTime);
+ String durationStr = String.valueOf(duration);
+ MDC.put("endTime", endTimeStr);
+ MDC.put("duration", durationStr);
+ rob.setCommonResponseHeader(ResponseHeaderBuilder.buildHeader(success, requestId, reason, duration));
+ rob.setVmId(new UUID(vmId));
+
+ auditLogger.info(String.format(
+ "Audit Logger: APPC0119I Restart '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+ metricsLogger.info(String.format(
+ "Metrics Logger: APPC0119I Restart '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+
+ // Status must be set to true to indicate that our return is expected
+ RpcResult<RestartOutput> rpcResult =
+ RpcResultBuilder.<RestartOutput> status(true).withResult(rob.build()).build();
+ return rpcResult;
+ }
+
+ /**
+ * Rebuild a VM
+ *
+ * @param hdr
+ * The common request header
+ * @param vnf
+ * The identification of the VNF resource to be operated upon
+ * @return The rpc result of the rebuild operation
+ */
+ public RpcResult<RebuildOutput> rebuild(CommonRequestHeader hdr, VnfResource vnf) {
+ long startTime = System.currentTimeMillis();
+ TimeZone tz = TimeZone.getTimeZone("UTC");
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
+ df.setTimeZone(tz);
+ // String startTimeStr = String.valueOf(startTime);
+ String startTimeStr = df.format(new Date());
+ String requestId = hdr.getServiceRequestId();
+
+ //MDC.clear();
+ MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ MDC.put(MDC_SERVICE_NAME, "App-C Provider:Rebuild");
+ MDC.put(MDC_SERVICE_INSTANCE_ID, "");
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ MDC.put(MDC_INSTANCE_UUID, java.util.UUID.randomUUID().toString());
+ MDC.put(MDC_ALERT_SEVERITY, "0");
+ MDC.put("startTime", startTimeStr);
+ MDC.put("target", "appc");
+ logger.info(String.format("Starting REBUILD for request with id [%s]", requestId));
+ metricsLogger.info(String.format("Metrics Logger: App-C Restart initiated. Start Time: [%s]. Request ID: [%s]",
+ startTime, requestId));
+
+ /*
+ * Copy any needed inputs or other values into the properties to be passed to the DG model
+ */
+ UUID vmId = vnf.getVmId();
+ Properties properties = new Properties();
+ properties.put(Constants.CONTEXT_ACTION, "rebuild");
+ properties.put(Constants.CONTEXT_REQID, requestId);
+ properties.put(Constants.CONTEXT_VMID, vmId.getValue());
+
+ UUID identityUrl = vnf.getIdentityUrl();
+ if (identityUrl != null) {
+ properties.put(Constants.CONTEXT_IDENTITY_URL, identityUrl.getValue());
+ }
+
+ /*
+ * Attempt to call the DG with the appropriate properties
+ */
+ boolean success = callGraph(properties);
+
+ /*
+ * Generate the appropriate response
+ */
+ MDC.put("target", "appc");
+ String statusStr = success ? "SUCCESS" : "FAILURE";
+ String infomsg =
+ String.format("APPC0120I Rebuild '%s' finished with status %s. Reason: %s", requestId, statusStr, reason);
+ logger.info(infomsg);
+
+ RebuildOutputBuilder rob = new RebuildOutputBuilder();
+ long endTime = System.currentTimeMillis();
+ long duration = endTime - startTime;
+ String endTimeStr = String.valueOf(endTime);
+ String durationStr = String.valueOf(duration);
+ MDC.put("endTime", endTimeStr);
+ MDC.put("duration", durationStr);
+ rob.setCommonResponseHeader(ResponseHeaderBuilder.buildHeader(success, requestId, reason, duration));
+ rob.setOriginalVmId(new UUID(vmId));
+ rob.setNewVmId(new UUID(vmId));
+
+ auditLogger.info(String.format(
+ "Audit Logger: APPC0120I Rebuild '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+ metricsLogger.info(String.format(
+ "Metrics Logger: APPC0120I Rebuild '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+
+ // Status must be set to true to indicate that our return is expected
+ RpcResult<RebuildOutput> rpcResult =
+ RpcResultBuilder.<RebuildOutput> status(true).withResult(rob.build()).build();
+ return rpcResult;
+ }
+
+ /**
+ * Snapshot a VM
+ *
+ * @param hdr
+ * The common request header
+ * @param vnf
+ * The identification of the VNF resource to be operated upon
+ * @return The rpc result of the restart operation
+ */
+ public RpcResult<SnapshotOutput> snapshot(CommonRequestHeader hdr, VnfResource vnf) {
+ long startTime = System.currentTimeMillis();
+ TimeZone tz = TimeZone.getTimeZone("UTC");
+ DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssX");
+ df.setTimeZone(tz);
+ // String startTimeStr = String.valueOf(startTime);
+ String startTimeStr = df.format(new Date());
+ String requestId = hdr.getServiceRequestId();
+
+ //MDC.clear();
+ MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ MDC.put(MDC_SERVICE_NAME, "App-C Provider:Snapshot");
+ MDC.put(MDC_SERVICE_INSTANCE_ID, "");
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ MDC.put(MDC_INSTANCE_UUID, java.util.UUID.randomUUID().toString());
+ MDC.put(MDC_ALERT_SEVERITY, "0");
+ MDC.put("startTime", Long.toString(startTime));
+ MDC.put("target", "appc");
+ logger.info(String.format("Starting SNAPSHOT for request with id [%s]", requestId));
+ metricsLogger.info(String.format("Metrics Logger: App-C Snapshot initiated. Start Time: [%s]. Request ID: [%s]",
+ startTime, requestId));
+
+ /*
+ * Copy any needed inputs or other values into the properties to be passed to the DG model
+ */
+ UUID vmId = vnf.getVmId();
+ Properties properties = new Properties();
+ properties.put(Constants.CONTEXT_ACTION, "snapshot");
+ properties.put(Constants.CONTEXT_REQID, requestId);
+ properties.put(Constants.CONTEXT_VMID, vmId.getValue());
+
+ UUID identityUrl = vnf.getIdentityUrl();
+ if (identityUrl != null) {
+ properties.put(Constants.CONTEXT_IDENTITY_URL, identityUrl.getValue());
+ }
+ /*
+ * Attempt to call the DG with the appropriate properties
+ */
+ boolean success = callGraph(properties);
+
+ /*
+ * Generate the appropriate response
+ */
+ MDC.put("target", "appc");
+ String statusStr = success ? "SUCCESS" : "FAILURE";
+ String infomsg =
+ String.format("APPC0119I Snapshot '%s' finished with status %s. Reason: %s", requestId, statusStr, reason);
+ logger.info(infomsg);
+
+ SnapshotOutputBuilder sob = new SnapshotOutputBuilder();
+ long endTime = System.currentTimeMillis();
+ long duration = endTime - startTime;
+ String endTimeStr = String.valueOf(endTime);
+ String durationStr = String.valueOf(duration);
+ MDC.put("endTime", endTimeStr);
+ MDC.put("duration", durationStr);
+ sob.setCommonResponseHeader(ResponseHeaderBuilder.buildHeader(success, requestId, reason, duration));
+ sob.setVmId(new UUID(vmId));
+
+ auditLogger.info(String.format(
+ "Audit Logger: APPC0119I Snapshot '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+ metricsLogger.info(String.format(
+ "Metrics Logger: APPC0119I Snapshot '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Duration: [%s]. Request ID: [%s]. Reason:%s",
+ requestId, statusStr, startTime, endTime, duration, requestId, reason));
+
+ // Status must be set to true to indicate that our return is expected
+ RpcResult<SnapshotOutput> rpcResult =
+ RpcResultBuilder.<SnapshotOutput> status(true).withResult(sob.build()).build();
+ return rpcResult;
+ }
+
+/**************************************************/
+
+ public RpcResult<VmstatuscheckOutput> vmstatuscheck(CommonRequestHeader hdr, VnfResource vnf) {
+ long startTime = System.currentTimeMillis();
+ String requestId = hdr.getServiceRequestId();
+
+ MDC.clear();
+ MDC.put(MDC_REMOTE_HOST, "");
+ MDC.put(MDC_KEY_REQUEST_ID, requestId);
+ MDC.put(MDC_SERVICE_NAME, "App-C Provider:vmstatuscheck");
+ MDC.put(MDC_SERVICE_INSTANCE_ID, "");
+ try {
+ MDC.put(MDC_SERVER_FQDN, InetAddress.getLocalHost().getHostName());
+ MDC.put(MDC_SERVER_IP_ADDRESS, InetAddress.getLocalHost().getHostAddress());
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ MDC.put(MDC_INSTANCE_UUID, java.util.UUID.randomUUID().toString());
+ MDC.put(MDC_ALERT_SEVERITY, "0");
+ logger.info(String.format("Starting VMSTATUSCHECK for request with id [%s]", requestId));
+
+ performanceLogger.info(String.format("Performance Logger: App-C vmstatuscheck initiated. Start Time: [%s]. Request ID: [%s]", startTime, requestId));
+ auditLogger.info(String.format("Audit Logger: App-C vmstatuscheck initiated. Start Time: [%s]. Request ID: [%s]", startTime, requestId));
+ metricsLogger.info(String.format("Metrics Logger: App-C vmstatuscheck initiated. Start Time: [%s]. Request ID: [%s]", startTime, requestId));
+
+ /*
+ * Copy any needed inputs or other values into the properties to be passed to the DG model
+ */
+ UUID vmId = vnf.getVmId();
+ Properties properties = new Properties();
+ properties.put(Constants.CONTEXT_ACTION, "vmstatuschecking");
+ properties.put(Constants.CONTEXT_REQID, requestId);
+ properties.put(Constants.CONTEXT_VMID, vmId.getValue());
+ properties.put(Constants.STATUS_GETTER, "checking");
+
+
+
+
+ UUID identityUrl = vnf.getIdentityUrl();
+ if (identityUrl != null) {
+ properties.put(Constants.CONTEXT_IDENTITY_URL, identityUrl.getValue());
+ }
+ /*
+ * Attempt to call the DG with the appropriate properties
+ */
+ boolean success = callGraph(properties);
+
+ /*
+ * Generate the appropriate response
+ */
+ String statusStr = success ? "SUCCESS" : "FAILURE";
+ String infomsg =
+ String.format("VMSTATUSCHECK '%s' finished with status %s. Reason: %s", requestId, statusStr, reason);
+ logger.info(infomsg);
+ long endTime = System.currentTimeMillis();
+ auditLogger.info(String.format("Audit Logger: VMSTATUSCHECK '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Request ID: [%s]. Reason:%s", requestId, statusStr, startTime, endTime, requestId, reason));
+ metricsLogger.info(String.format("Metrics Logger: VMSTATUSCHECK '%s' finished with status %s. Start Time: [%s]. End Time: [%s]. Request ID: [%s]. Reason:%s", requestId, statusStr, startTime, endTime, requestId, reason));
+ //logger.info(String.format("Step1 [%s]", Constants.STATUS_GETTER));
+ String tempstring2 = properties.getProperty(Constants.STATUS_GETTER).trim();
+ //logger.info(String.format("Step2 [%s]", tempstring2));
+
+
+ VmstatuscheckOutputBuilder vob = new VmstatuscheckOutputBuilder();
+ long duration = System.currentTimeMillis() - startTime;
+ vob.setCommonResponseHeader(ResponseHeaderBuilder.buildHeader(success, requestId, reason, duration));
+ vob.setStatMsg(tempstring2);
+
+ // Status must be set to true to indicate that our return is expected
+ RpcResult<VmstatuscheckOutput> rpcResult =
+ RpcResultBuilder.<VmstatuscheckOutput> status(true).withResult(vob.build()).build();
+ return rpcResult;
+ }
+
+ /*************************************************/
+
+
+
+ private boolean callGraph(Properties props) {
+ String moduleName = configuration.getProperty(Constants.PROPERTY_MODULE_NAME);
+ String methodName = configuration.getProperty(Constants.PROPERTY_TOPOLOGY_METHOD);
+ String version = configuration.getProperty(Constants.PROPERTY_TOPOLOGY_VERSION);
+ String mode = Constants.SYNC_MODE;
+ return callGraph(moduleName, methodName, version, mode, props);
+ }
+
+ /**
+ * Calls a specified directed graph with the specified properties and returns the response
+ *
+ * @param module
+ * The module name to be used to locate the graph
+ * @param method
+ * The method name to be executed (rpc)
+ * @param version
+ * The version of the graph to be used, or null for the latest
+ * @param mode
+ * the execution mode of the graph, sync or async
+ * @param props
+ * A set of name-value properties to be passed to the graph for context variables.
+ */
+ private boolean callGraph(String module, String method, String version, String mode, Properties props) {
+ String graphName = String.format(("%s:%s:%s"), module, method, version);
+ logger.debug(String.format("Calling Graph %s", graphName));
+ metricsLogger.info(String.format("Calling Graph %s", graphName));
+
+ boolean success = false;
+ String appName = configuration.getProperty(Constants.PROPERTY_APPLICATION_NAME);
+ AppcProviderClient svcLogicClient = new AppcProviderClient();
+ try {
+ if (svcLogicClient.hasGraph(module, method, version, mode)) {
+ try {
+ Properties respProps = svcLogicClient.execute(module, method, version, mode, props);
+ success = false; // Assume it failed unless proven otherwise
+ reason = "Failed"; // Assume it failed unless proven otherwise
+
+ logger.debug(EELFResourceManager.format(Msg.DEBUG_GRAPH_RESPONSE_HEADER, appName, graphName,
+ Integer.toString(respProps.size())));
+ for (String key : respProps.stringPropertyNames()) {
+ logger.debug(EELFResourceManager.format(Msg.DEBUG_GRAPH_RESPONSE_DETAIL, appName, graphName,
+ key, (String) respProps.get(key)));
+ }
+
+ // TODO - Find docs and see if there is a better way to handle this
+ // Bad requests have errors
+ if (respProps.containsKey(Constants.ATTRIBUTE_ERROR_CODE)) {
+ // || respProps.containsKey(Constants.ATTRIBUTE_ERROR_MESSAGE)) {
+ String errorCodeProperty = respProps.getProperty(Constants.ATTRIBUTE_ERROR_CODE).trim();
+ int errorCode = 200;
+ try {
+ errorCode = Integer.parseInt(errorCodeProperty);
+ if (errorCode >= 300) {
+ reason = EELFResourceManager.format(Msg.DG_FAILED_RESPONSE, appName, graphName,
+ errorCodeProperty, respProps.getProperty(Constants.ATTRIBUTE_ERROR_MESSAGE));
+ logger.error(reason);
+ success = false;
+ } else {
+ success = true;
+ reason = "Success";
+ }
+ } catch (NumberFormatException e) {
+ reason = EELFResourceManager.format(Msg.PARAMETER_NOT_NUMERIC, appName, graphName,
+ Constants.ATTRIBUTE_ERROR_CODE, errorCodeProperty);
+ logger.error(reason);
+ success = false;
+ }
+ } else {
+ /*
+ * Added code that requires error code to now be defined in ALL cases. If not, it is an error
+ * and the response will be set to failed regardless if the DG worked or not.
+ */
+ reason = EELFResourceManager.format(Msg.PARAMETER_IS_MISSING, appName, graphName,
+ Constants.ATTRIBUTE_ERROR_CODE);
+ logger.error(reason);
+ success = false;
+ }
+ } catch (Exception e) {
+ success = false;
+ reason = EELFResourceManager.format(Msg.EXCEPTION_CALLING_DG, e, appName,
+ e.getClass().getSimpleName(), graphName, e.getMessage());
+ logger.error(reason);
+ }
+ } else {
+ success = false;
+ reason = EELFResourceManager.format(Msg.GRAPH_NOT_FOUND, appName, graphName);
+ logger.error(reason);
+ }
+ } catch (Exception e) {
+ success = false;
+ reason = EELFResourceManager.format(Msg.EXCEPTION_CALLING_DG, e, appName, e.getClass().getSimpleName(),
+ graphName, e.getMessage());
+ logger.error(reason);
+ }
+
+ return success;
+ }
+
+}