diff options
author | Timoney, Dan (dt5972) <dt5972@att.com> | 2018-04-12 19:13:59 -0400 |
---|---|---|
committer | Timoney, Dan (dt5972) <dt5972@att.com> | 2018-04-12 19:19:16 -0400 |
commit | b039682a6805507445139e2b2430144f92724b09 (patch) | |
tree | cb2f59555e25bc1beccd76e53b7054e5b5d7d107 /lcm/provider/src/main | |
parent | 3d57947b10a193fbdfd3137fdd8fd712eb243980 (diff) |
Copy LCM interface from APP-C
Change-Id: Idc18aa00bcbcee3f51473339b6b4ad90f6b4bffc
Issue-ID: CCSDK-219
Signed-off-by: Timoney, Dan (dt5972) <dt5972@att.com>
Diffstat (limited to 'lcm/provider/src/main')
6 files changed, 1554 insertions, 0 deletions
diff --git a/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmProvider.java b/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmProvider.java new file mode 100644 index 000000000..14d3d9e53 --- /dev/null +++ b/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmProvider.java @@ -0,0 +1,1037 @@ +package org.onap.ccsdk.sli.northbound; +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.Properties; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService; +import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.binding.impl.AbstractForwardedDataBroker; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.opendaylight.controller.sal.binding.api.BindingAwareBroker; +import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.*; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.common.header.CommonHeaderBuilder; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.status.Status; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.status.StatusBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; +import com.google.common.util.concurrent.Futures; + +import org.onap.ccsdk.sli.northbound.LcmResponseCode.*; + +/** + * Defines a base implementation for your provider. This class extends from a + * helper class which provides storage for the most commonly used components of + * the MD-SAL. Additionally the base class provides some basic logging and + * initialization / clean up methods. + * + */ +public class LcmProvider implements AutoCloseable, LCMService { + + private class CommonLcmFields { + private StatusBuilder statusBuilder; + private CommonHeaderBuilder commonHeaderBuilder; + + public CommonLcmFields(StatusBuilder statusBuilder, CommonHeaderBuilder commonHeaderBuilder) { + this.statusBuilder = statusBuilder; + this.commonHeaderBuilder = commonHeaderBuilder; + } + + public StatusBuilder getStatusBuilder() { + return statusBuilder; + } + + public CommonHeaderBuilder getCommonHeaderBuilder() { + return commonHeaderBuilder; + } + } + + private static final Logger LOG = LoggerFactory.getLogger(LcmProvider.class); + + private static final String ACTIVE_VERSION = "active"; + + private static final String APPLICATION_NAME = "LCM"; + + private final ExecutorService executor; + protected DataBroker dataBroker; + protected DOMDataBroker domDataBroker; + protected NotificationPublishService notificationService; + protected RpcProviderRegistry rpcRegistry; + private final LcmSliClient lcmSliClient; + + protected BindingAwareBroker.RpcRegistration<LCMService> rpcRegistration; + + public LcmProvider(final DataBroker dataBroker, final NotificationPublishService notificationPublishService, + final RpcProviderRegistry rpcProviderRegistry, final LcmSliClient lcmSliClient) { + + LOG.info("Creating provider for {}", APPLICATION_NAME); + executor = Executors.newFixedThreadPool(1); + this.dataBroker = dataBroker; + if (dataBroker instanceof AbstractForwardedDataBroker) { + domDataBroker = ((AbstractForwardedDataBroker) dataBroker).getDelegate(); + } + notificationService = notificationPublishService; + rpcRegistry = rpcProviderRegistry; + this.lcmSliClient = lcmSliClient; + initialize(); + } + + public void initialize() { + LOG.info("Initializing {} for {}", this.getClass().getName(), APPLICATION_NAME); + + if (rpcRegistration == null) { + if (rpcRegistry != null) { + rpcRegistration = rpcRegistry.addRpcImplementation(LCMService.class, this); + LOG.info("Initialization complete for {}", APPLICATION_NAME); + } else { + LOG.warn("Error initializing {} : rpcRegistry unset", APPLICATION_NAME); + } + } + } + + protected void initializeChild() { + // Override if you have custom initialization intelligence + } + + @Override + public void close() throws Exception { + LOG.info("Closing provider for " + APPLICATION_NAME); + executor.shutdown(); + rpcRegistration.close(); + LOG.info("Successfully closed provider for " + APPLICATION_NAME); + } + + + + @Override + public Future<RpcResult<CheckLockOutput>> checkLock(CheckLockInput input) { + CheckLockInputBuilder iBuilder = new CheckLockInputBuilder(input); + CheckLockOutputBuilder oBuilder = new CheckLockOutputBuilder(); + + try { + CommonLcmFields retval = callDG("CheckLock", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<CheckLockOutput> rpcResult = + RpcResultBuilder.<CheckLockOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + + } + + @Override + public Future<RpcResult<RebootOutput>> reboot(RebootInput input) { + RebootInputBuilder iBuilder = new RebootInputBuilder(input); + RebootOutputBuilder oBuilder = new RebootOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Reboot", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<RebootOutput> rpcResult = + RpcResultBuilder.<RebootOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<UpgradeBackupOutput>> upgradeBackup(UpgradeBackupInput input) { + UpgradeBackupInputBuilder iBuilder = new UpgradeBackupInputBuilder(input); + UpgradeBackupOutputBuilder oBuilder = new UpgradeBackupOutputBuilder(); + + try { + CommonLcmFields retval = callDG("UpgradeBackup", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<UpgradeBackupOutput> rpcResult = + RpcResultBuilder.<UpgradeBackupOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<RollbackOutput>> rollback(RollbackInput input) { + RollbackInputBuilder iBuilder = new RollbackInputBuilder(input); + RollbackOutputBuilder oBuilder = new RollbackOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Rollback", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<RollbackOutput> rpcResult = + RpcResultBuilder.<RollbackOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<SyncOutput>> sync(SyncInput input) { + SyncInputBuilder iBuilder = new SyncInputBuilder(input); + SyncOutputBuilder oBuilder = new SyncOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Sync", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<SyncOutput> rpcResult = + RpcResultBuilder.<SyncOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<QueryOutput>> query(QueryInput input) { + QueryInputBuilder iBuilder = new QueryInputBuilder(input); + QueryOutputBuilder oBuilder = new QueryOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Query", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<QueryOutput> rpcResult = + RpcResultBuilder.<QueryOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ConfigExportOutput>> configExport(ConfigExportInput input) { + ConfigExportInputBuilder iBuilder = new ConfigExportInputBuilder(input); + ConfigExportOutputBuilder oBuilder = new ConfigExportOutputBuilder(); + + try { + CommonLcmFields retval = callDG("ConfigExport", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ConfigExportOutput> rpcResult = + RpcResultBuilder.<ConfigExportOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<StopApplicationOutput>> stopApplication(StopApplicationInput input) { + StopApplicationInputBuilder iBuilder = new StopApplicationInputBuilder(input); + StopApplicationOutputBuilder oBuilder = new StopApplicationOutputBuilder(); + + try { + CommonLcmFields retval = callDG("StopApplication", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<StopApplicationOutput> rpcResult = + RpcResultBuilder.<StopApplicationOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<SoftwareUploadOutput>> softwareUpload(SoftwareUploadInput input) { + SoftwareUploadInputBuilder iBuilder = new SoftwareUploadInputBuilder(input); + SoftwareUploadOutputBuilder oBuilder = new SoftwareUploadOutputBuilder(); + + try { + CommonLcmFields retval = callDG("SoftwareUpload", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<SoftwareUploadOutput> rpcResult = + RpcResultBuilder.<SoftwareUploadOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ResumeTrafficOutput>> resumeTraffic(ResumeTrafficInput input) { + ResumeTrafficInputBuilder iBuilder = new ResumeTrafficInputBuilder(input); + ResumeTrafficOutputBuilder oBuilder = new ResumeTrafficOutputBuilder(); + + try { + CommonLcmFields retval = callDG("ResumeTraffic", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ResumeTrafficOutput> rpcResult = + RpcResultBuilder.<ResumeTrafficOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ConfigureOutput>> configure(ConfigureInput input) { + ConfigureInputBuilder iBuilder = new ConfigureInputBuilder(input); + ConfigureOutputBuilder oBuilder = new ConfigureOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Configure", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ConfigureOutput> rpcResult = + RpcResultBuilder.<ConfigureOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ActionStatusOutput>> actionStatus(ActionStatusInput input) { + ActionStatusInputBuilder iBuilder = new ActionStatusInputBuilder(input); + ActionStatusOutputBuilder oBuilder = new ActionStatusOutputBuilder(); + + try { + CommonLcmFields retval = callDG("ActionStatus", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ActionStatusOutput> rpcResult = + RpcResultBuilder.<ActionStatusOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<UpgradePreCheckOutput>> upgradePreCheck(UpgradePreCheckInput input) { + UpgradePreCheckInputBuilder iBuilder = new UpgradePreCheckInputBuilder(input); + UpgradePreCheckOutputBuilder oBuilder = new UpgradePreCheckOutputBuilder(); + + try { + CommonLcmFields retval = callDG("UpgradePreCheck", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<UpgradePreCheckOutput> rpcResult = + RpcResultBuilder.<UpgradePreCheckOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<LiveUpgradeOutput>> liveUpgrade(LiveUpgradeInput input) { + LiveUpgradeInputBuilder iBuilder = new LiveUpgradeInputBuilder(input); + LiveUpgradeOutputBuilder oBuilder = new LiveUpgradeOutputBuilder(); + + try { + CommonLcmFields retval = callDG("LiveUpgrade", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<LiveUpgradeOutput> rpcResult = + RpcResultBuilder.<LiveUpgradeOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ConfigModifyOutput>> configModify(ConfigModifyInput input) { + ConfigModifyInputBuilder iBuilder = new ConfigModifyInputBuilder(input); + ConfigModifyOutputBuilder oBuilder = new ConfigModifyOutputBuilder(); + + try { + CommonLcmFields retval = callDG("ConfigModify", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ConfigModifyOutput> rpcResult = + RpcResultBuilder.<ConfigModifyOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<RestartOutput>> restart(RestartInput input) { + RestartInputBuilder iBuilder = new RestartInputBuilder(input); + RestartOutputBuilder oBuilder = new RestartOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Restart", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<RestartOutput> rpcResult = + RpcResultBuilder.<RestartOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<HealthCheckOutput>> healthCheck(HealthCheckInput input) { + HealthCheckInputBuilder iBuilder = new HealthCheckInputBuilder(input); + HealthCheckOutputBuilder oBuilder = new HealthCheckOutputBuilder(); + + try { + CommonLcmFields retval = callDG("HealthCheck", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<HealthCheckOutput> rpcResult = + RpcResultBuilder.<HealthCheckOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<LockOutput>> lock(LockInput input) { + LockInputBuilder iBuilder = new LockInputBuilder(input); + LockOutputBuilder oBuilder = new LockOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Lock", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<LockOutput> rpcResult = + RpcResultBuilder.<LockOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<TerminateOutput>> terminate(TerminateInput input) { + TerminateInputBuilder iBuilder = new TerminateInputBuilder(input); + TerminateOutputBuilder oBuilder = new TerminateOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Terminate", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<TerminateOutput> rpcResult = + RpcResultBuilder.<TerminateOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<AttachVolumeOutput>> attachVolume(AttachVolumeInput input) { + AttachVolumeInputBuilder iBuilder = new AttachVolumeInputBuilder(input); + AttachVolumeOutputBuilder oBuilder = new AttachVolumeOutputBuilder(); + + try { + CommonLcmFields retval = callDG("AttachVolume", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<AttachVolumeOutput> rpcResult = + RpcResultBuilder.<AttachVolumeOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<MigrateOutput>> migrate(MigrateInput input) { + MigrateInputBuilder iBuilder = new MigrateInputBuilder(input); + MigrateOutputBuilder oBuilder = new MigrateOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Migrate", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<MigrateOutput> rpcResult = + RpcResultBuilder.<MigrateOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<QuiesceTrafficOutput>> quiesceTraffic(QuiesceTrafficInput input) { + QuiesceTrafficInputBuilder iBuilder = new QuiesceTrafficInputBuilder(input); + QuiesceTrafficOutputBuilder oBuilder = new QuiesceTrafficOutputBuilder(); + + try { + CommonLcmFields retval = callDG("QuiesceTraffic", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<QuiesceTrafficOutput> rpcResult = + RpcResultBuilder.<QuiesceTrafficOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ConfigRestoreOutput>> configRestore(ConfigRestoreInput input) { + ConfigRestoreInputBuilder iBuilder = new ConfigRestoreInputBuilder(input); + ConfigRestoreOutputBuilder oBuilder = new ConfigRestoreOutputBuilder(); + + try { + CommonLcmFields retval = callDG("ConfigRestore", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ConfigRestoreOutput> rpcResult = + RpcResultBuilder.<ConfigRestoreOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<UpgradeBackoutOutput>> upgradeBackout(UpgradeBackoutInput input) { + UpgradeBackoutInputBuilder iBuilder = new UpgradeBackoutInputBuilder(input); + UpgradeBackoutOutputBuilder oBuilder = new UpgradeBackoutOutputBuilder(); + + try { + CommonLcmFields retval = callDG("UpgradeBackout", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<UpgradeBackoutOutput> rpcResult = + RpcResultBuilder.<UpgradeBackoutOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<EvacuateOutput>> evacuate(EvacuateInput input) { + EvacuateInputBuilder iBuilder = new EvacuateInputBuilder(input); + EvacuateOutputBuilder oBuilder = new EvacuateOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Evacuate", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<EvacuateOutput> rpcResult = + RpcResultBuilder.<EvacuateOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<UnlockOutput>> unlock(UnlockInput input) { + UnlockInputBuilder iBuilder = new UnlockInputBuilder(input); + UnlockOutputBuilder oBuilder = new UnlockOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Unlock", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<UnlockOutput> rpcResult = + RpcResultBuilder.<UnlockOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ConfigBackupDeleteOutput>> configBackupDelete(ConfigBackupDeleteInput input) { + ConfigBackupDeleteInputBuilder iBuilder = new ConfigBackupDeleteInputBuilder(input); + ConfigBackupDeleteOutputBuilder oBuilder = new ConfigBackupDeleteOutputBuilder(); + + try { + CommonLcmFields retval = callDG("ConfigBackupDelete", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ConfigBackupDeleteOutput> rpcResult = + RpcResultBuilder.<ConfigBackupDeleteOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<UpgradeSoftwareOutput>> upgradeSoftware(UpgradeSoftwareInput input) { + UpgradeSoftwareInputBuilder iBuilder = new UpgradeSoftwareInputBuilder(input); + UpgradeSoftwareOutputBuilder oBuilder = new UpgradeSoftwareOutputBuilder(); + + try { + CommonLcmFields retval = callDG("UpgradeSoftware", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<UpgradeSoftwareOutput> rpcResult = + RpcResultBuilder.<UpgradeSoftwareOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<StopOutput>> stop(StopInput input) { + StopInputBuilder iBuilder = new StopInputBuilder(input); + StopOutputBuilder oBuilder = new StopOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Stop", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<StopOutput> rpcResult = + RpcResultBuilder.<StopOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<DetachVolumeOutput>> detachVolume(DetachVolumeInput input) { + DetachVolumeInputBuilder iBuilder = new DetachVolumeInputBuilder(input); + DetachVolumeOutputBuilder oBuilder = new DetachVolumeOutputBuilder(); + + try { + CommonLcmFields retval = callDG("DetachVolume", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<DetachVolumeOutput> rpcResult = + RpcResultBuilder.<DetachVolumeOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ConfigScaleOutOutput>> configScaleOut(ConfigScaleOutInput input) { + ConfigScaleOutInputBuilder iBuilder = new ConfigScaleOutInputBuilder(input); + ConfigScaleOutOutputBuilder oBuilder = new ConfigScaleOutOutputBuilder(); + + try { + CommonLcmFields retval = callDG("ConfigScaleOut", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ConfigScaleOutOutput> rpcResult = + RpcResultBuilder.<ConfigScaleOutOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<UpgradePostCheckOutput>> upgradePostCheck(UpgradePostCheckInput input) { + UpgradePostCheckInputBuilder iBuilder = new UpgradePostCheckInputBuilder(input); + UpgradePostCheckOutputBuilder oBuilder = new UpgradePostCheckOutputBuilder(); + + try { + CommonLcmFields retval = callDG("UpgradePostCheck", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<UpgradePostCheckOutput> rpcResult = + RpcResultBuilder.<UpgradePostCheckOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<TestOutput>> test(TestInput input) { + TestInputBuilder iBuilder = new TestInputBuilder(input); + TestOutputBuilder oBuilder = new TestOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Test", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<TestOutput> rpcResult = + RpcResultBuilder.<TestOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<StartApplicationOutput>> startApplication(StartApplicationInput input) { + StartApplicationInputBuilder iBuilder = new StartApplicationInputBuilder(input); + StartApplicationOutputBuilder oBuilder = new StartApplicationOutputBuilder(); + + try { + CommonLcmFields retval = callDG("StartApplication", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<StartApplicationOutput> rpcResult = + RpcResultBuilder.<StartApplicationOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<ConfigBackupOutput>> configBackup(ConfigBackupInput input) { + ConfigBackupInputBuilder iBuilder = new ConfigBackupInputBuilder(input); + ConfigBackupOutputBuilder oBuilder = new ConfigBackupOutputBuilder(); + + try { + CommonLcmFields retval = callDG("ConfigBackup", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<ConfigBackupOutput> rpcResult = + RpcResultBuilder.<ConfigBackupOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<RebuildOutput>> rebuild(RebuildInput input) { + RebuildInputBuilder iBuilder = new RebuildInputBuilder(input); + RebuildOutputBuilder oBuilder = new RebuildOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Rebuild", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<RebuildOutput> rpcResult = + RpcResultBuilder.<RebuildOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<AuditOutput>> audit(AuditInput input) { + AuditInputBuilder iBuilder = new AuditInputBuilder(input); + AuditOutputBuilder oBuilder = new AuditOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Audit", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<AuditOutput> rpcResult = + RpcResultBuilder.<AuditOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<StartOutput>> start(StartInput input) { + StartInputBuilder iBuilder = new StartInputBuilder(input); + StartOutputBuilder oBuilder = new StartOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Start", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<StartOutput> rpcResult = + RpcResultBuilder.<StartOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + @Override + public Future<RpcResult<SnapshotOutput>> snapshot(SnapshotInput input) { + SnapshotInputBuilder iBuilder = new SnapshotInputBuilder(input); + SnapshotOutputBuilder oBuilder = new SnapshotOutputBuilder(); + + try { + CommonLcmFields retval = callDG("Snapshot", iBuilder.build()); + oBuilder.setStatus(retval.getStatusBuilder().build()); + oBuilder.setCommonHeader(retval.getCommonHeaderBuilder().build()); + } catch (LcmRpcInvocationException e) { + LOG.debug("Caught exception", e); + oBuilder.setCommonHeader(e.getCommonHeader()); + oBuilder.setStatus(e.getStatus()); + } + + RpcResult<SnapshotOutput> rpcResult = + RpcResultBuilder.<SnapshotOutput> status(true).withResult(oBuilder.build()).build(); + // return error + return Futures.immediateFuture(rpcResult); + } + + private CommonLcmFields callDG(String rpcName, Object input) throws LcmRpcInvocationException { + + StatusBuilder statusBuilder = new StatusBuilder(); + + if (input == null) { + LOG.debug("Rejecting " +rpcName+ " because of invalid input"); + statusBuilder.setCode(LcmResponseCode.REJECT_INVALID_INPUT.getValue()); + statusBuilder.setMessage("REJECT - INVALID INPUT. Missing input"); + CommonHeaderBuilder hBuilder = new CommonHeaderBuilder(); + hBuilder.setApiVer("1"); + hBuilder.setOriginatorId("unknown"); + hBuilder.setRequestId("unset"); + hBuilder.setTimestamp(new ZULU(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new Date()))); + throw new LcmRpcInvocationException(statusBuilder.build(), hBuilder.build()); + } + + CommonHeaderBuilder hBuilder = new CommonHeaderBuilder(((CommonHeader)input).getCommonHeader()); + + // add input to parms + LOG.info("Adding INPUT data for "+ rpcName +" input: " + input.toString()); + Properties inputProps = new Properties(); + MdsalHelper.toProperties(inputProps, input); + + Properties respProps = new Properties(); + + // Call SLI sync method + try + { + if (lcmSliClient.hasGraph("LCM", rpcName , null, "sync")) + { + try + { + respProps = lcmSliClient.execute("LCM", rpcName, null, "sync", inputProps, domDataBroker); + } + catch (Exception e) + { + LOG.error("Caught exception executing service logic for "+ rpcName, e); + statusBuilder.setCode(LcmResponseCode.FAILURE_DG_FAILURE.getValue()); + statusBuilder.setMessage("FAILURE - DG FAILURE ("+e.getMessage()+")"); + throw new LcmRpcInvocationException(statusBuilder.build(), hBuilder.build()); + } + } else { + LOG.error("No service logic active for LCM: '" + rpcName + "'"); + + statusBuilder.setCode(LcmResponseCode.REJECT_DG_NOT_FOUND.getValue()); + statusBuilder.setMessage("FAILURE - DG not found for action "+rpcName); + throw new LcmRpcInvocationException(statusBuilder.build(), hBuilder.build()); + } + } + catch (Exception e) + { + LOG.error("Caught exception looking for service logic", e); + + statusBuilder.setCode(LcmResponseCode.FAILURE_DG_FAILURE.getValue()); + statusBuilder.setMessage("FAILURE - Unexpected error looking for DG ("+e.getMessage()+")"); + throw new LcmRpcInvocationException(statusBuilder.build(), hBuilder.build()); + } + + + StatusBuilder sBuilder = new StatusBuilder(); + MdsalHelper.toBuilder(respProps, sBuilder); + MdsalHelper.toBuilder(respProps, hBuilder); + + String statusCode = sBuilder.getCode().toString(); + + if (!"400".equals(statusCode)) { + LOG.error("Returned FAILED for "+rpcName+" error code: '" + statusCode + "'"); + } else { + LOG.info("Returned SUCCESS for "+rpcName+" "); + } + + return new CommonLcmFields(sBuilder,hBuilder); + + } + +} diff --git a/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmResponseCode.java b/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmResponseCode.java new file mode 100644 index 000000000..76001c860 --- /dev/null +++ b/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmResponseCode.java @@ -0,0 +1,51 @@ +package org.onap.ccsdk.sli.northbound; + +public enum LcmResponseCode { + + // Accepted category + ACCEPT_ACCEPTED(100), + // Error category + ERROR_UNEXPECTED_ERROR(200), + // Rejected category + REJECT_REJECTED(300), + REJECT_INVALID_INPUT(301), + REJECT_MISSING_PARAM(302), + REJECT_PARSING_FAILED(303), + REJECT_NO_TRANSITION(304), + REJECT_ACTION_NOT_SUPPORTED(305), + REJECT_VNF_NOT_FOUND(306), + REJECT_DG_NOT_FOUND(307), + REJECT_WORKFLOW_NOT_FOUND(308), + REJECT_UNSTABLE_VNF(309), + REJECT_LOCKING_FAILURE(310), + REJECT_EXPIRED_REQUEST(311), + REJECT_DUPLICATE_REQUEST(312), + REJECT_MISSING_AAI_DATA(313), + REJECT_MULTIPLE_REQUESTS_FOR_SEARCH(315), + REJECT_POLICY_VALIDATION_FAILURE(316), + // Success category + SUCCESS(400), + // Failure category + FAILURE_DG_FAILURE(401), + FAILURE_NO_TRANSITION(402), + FAILURE_AAI_FAILURE(403), + FAILURE_EXPIRED_REQUEST(404), + FAILURE_UNEXPECTED_FAILURE(405), + FAILURE_UNSTABLE_VNF(406), + FAILURE_REQUEST_NOT_SUPPORTED(450), + // Partial success + PARTIAL_SUCCESS(500); + + + + private int value; + private LcmResponseCode(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + +} diff --git a/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmRpcInvocationException.java b/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmRpcInvocationException.java new file mode 100644 index 000000000..2ae2200a8 --- /dev/null +++ b/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmRpcInvocationException.java @@ -0,0 +1,25 @@ +package org.onap.ccsdk.sli.northbound; + +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.common.header.CommonHeader; +import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.northbound.lcm.rev180329.status.Status; + +public class LcmRpcInvocationException extends SvcLogicException { + + private Status status; + private CommonHeader commonHeader; + + public LcmRpcInvocationException(Status status, CommonHeader commonHeader) { + this.status = status; + this.commonHeader = commonHeader; + } + + public Status getStatus() { + return status; + } + + public CommonHeader getCommonHeader() { + return commonHeader; + } + +} diff --git a/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmSliClient.java b/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmSliClient.java new file mode 100644 index 000000000..9fcc92c88 --- /dev/null +++ b/lcm/provider/src/main/java/org/onap/ccsdk/sli/northbound/LcmSliClient.java @@ -0,0 +1,96 @@ +package org.onap.ccsdk.sli.northbound; +/*- + * ============LICENSE_START======================================================= + * openECOMP : SDN-C + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights + * reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + + +import java.util.Properties; + +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.core.sli.provider.SvcLogicService; +import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LcmSliClient { + + private static final Logger LOG = LoggerFactory.getLogger(LcmSliClient.class); + + private final SvcLogicService svcLogicService; + + public LcmSliClient(final SvcLogicService svcLogicService) { + this.svcLogicService = svcLogicService; + } + + public boolean hasGraph(String module, String rpc, String version, String mode) throws SvcLogicException + { + return svcLogicService.hasGraph(module, rpc, version, mode); + } + + + public Properties execute(String module, String rpc, String version, String mode, Properties parms, DOMDataBroker dataBroker) + throws SvcLogicException { + + + if (LOG.isDebugEnabled()) + { + LOG.debug("Parameters passed to SLI"); + + for (Object key : parms.keySet()) { + String parmName = (String) key; + String parmValue = parms.getProperty(parmName); + + LOG.debug(parmName+" = "+parmValue); + + } + } + + Properties respProps = svcLogicService.execute(module, rpc, version, mode, parms, dataBroker); + + if (LOG.isDebugEnabled()) + { + LOG.debug("Parameters returned by SLI"); + + for (Object key : respProps.keySet()) { + String parmName = (String) key; + String parmValue = respProps.getProperty(parmName); + + LOG.debug(parmName+" = "+parmValue); + + } + } + + if ("failure".equalsIgnoreCase(respProps.getProperty("SvcLogic.status"))) { + + if (!respProps.containsKey("error-code")) { + respProps.setProperty("error-code", "500"); + } + } else { + if (!respProps.containsKey("error-code")) { + respProps.setProperty("error-code", "200"); + } + } + + + return respProps; + } + +} diff --git a/lcm/provider/src/main/resources/org/onap/appc/default.properties b/lcm/provider/src/main/resources/org/onap/appc/default.properties new file mode 100644 index 000000000..693cd37a8 --- /dev/null +++ b/lcm/provider/src/main/resources/org/onap/appc/default.properties @@ -0,0 +1,58 @@ +### +# ============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========================================================= +### + +# +# This property file supplies the configuration defaults for the APP-C controller +# +# Default values are supplied so that all defined properties have well-known values and are +# valid even if a configuration file is not supplied. This is done to ensure that a runnable, +# stable, and defined configuration exists at all times. The reason the defaults are supplied +# via this property file and not in the code is so that the properties can be changed +# easily if needed in the future. Use of the "getProperty(name, default)" method is +# discouraged because if the default value needs to be changed, everywhere in the code it +# is used would have to be changed. By loading the defaults in this property file, all +# values can be defined in one place and support is easier. This does mean that all +# properties that are defined must have a default value supplied here. Which also means +# this file documents all defined properties (not a bad thing either). +# +#-------------------------------------------------------------------------------------------- +# The path and file used to load user-supplied configuration settings, if any +org.onap.appc.bootstrap.file=appc.properties +org.onap.appc.bootstrap.path=/opt/onap/appc/data/properties,${user.home},. + +appc.application.name=APPC + +# +# The path to search for logging configuration document, and the name of the document +# +org.onap.appc.logging.path=${user.home},etc,../etc,. +org.onap.appc.logging.file=logback.xml + +# +# The DG properties +# +appc.service.logic.module.name=APPC +appc.topology.dg.method=topology-operation-all +appc.topology.dg.version=2.0.0 + diff --git a/lcm/provider/src/main/resources/org/onap/appc/logback.xml b/lcm/provider/src/main/resources/org/onap/appc/logback.xml new file mode 100644 index 000000000..0dffe75e0 --- /dev/null +++ b/lcm/provider/src/main/resources/org/onap/appc/logback.xml @@ -0,0 +1,287 @@ +<!-- + ============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========================================================= + --> + +<configuration scan="true" scanPeriod="3 seconds" debug="true"> + <!--<jmxConfigurator /> --> + <property name="logDirectory" value="logs" /> + <property name="debugLogDirectory" value="debug-logs" /> + <!-- Example evaluator filter applied against console appender --> + <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{MM/dd-HH:mm:ss.SSS} [%-16thread] %.-5level + %-36.36logger - %msg%n</pattern> + </encoder> + </appender> + + <!-- ============================================================================ --> + <!-- CDP Appenders --> + <!-- ============================================================================ --> + + <!-- The CDPAppender is used to record events to the general CDP application + log. This is the log file used by default as the application root log, if + no other log is defined or the application creates specialized loggers of + the form com.att.cdp.x.y.z where the name occupied by the "x" is NOT security, + perf, server, coordinator, gui, or policy. These are defined as specialization + loggers for various business purposes. --> + <appender name="CDP" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/cdp.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/cdp.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - + %msg%n"</pattern> --> + <pattern>%d{MM/dd-HH:mm:ss.SSS} [%-16thread] %.-5level + %-36.36logger [%X{User} %X{RemoteHost} %X{RequestId} %X{Method} + %X{Path}] - %msg%n</pattern> + </encoder> + </appender> + <appender name="asyncCDP" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="CDP" /> + </appender> + + <!-- CDP Security Appender. This appender is used to record security events + to the security log file. Security events are separate from other loggers + in CDP so that security log records can be captured and managed in a secure + way separate from the other logs. This appender is set to never discard any + events. --> + <appender name="CDPSecurity" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/cdp-security.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/cdp-security.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - + %msg%n"</pattern> --> + <pattern>%d{MM/dd-HH:mm:ss.SSS} [%-16thread] %.-5level + %-36.36logger [%X{User} %X{RemoteHost} %X{RequestId} %X{Method} + %X{Path}] - %msg%n</pattern> + </encoder> + </appender> + <appender name="asyncCDPSecurity" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <discardingThreshold>0</discardingThreshold> + <appender-ref ref="CDPSecurity" /> + </appender> + + <!-- CDP Performance Appender. This appender is used to record performance + records. --> + <appender name="CDPPerformance" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/cdp-performance.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/cdp-performance.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <outputPatternAsHeader>true</outputPatternAsHeader> + <pattern>%d{MM/dd-HH:mm:ss.SSS} [%-16thread] %.-5level + %-36.36logger [%X{User} %X{RemoteHost} %X{RequestId} %X{Method} + %X{Path}] - %msg%n</pattern> + </encoder> + </appender> + <appender name="asyncCDPPerformance" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="CDPPerformance" /> + </appender> + + <!-- CDP Server Appender. This appender is used to record Server related + logging events. The Server logger and appender are specializations of the + CDP application root logger and appender. This can be used to segregate Server + events from other components, or it can be eliminated to record these events + as part of the application root log. --> + <appender name="CDPServer" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/cdp-server.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/cdp-server.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - + %msg%n"</pattern> --> + <pattern>%d{MM/dd-HH:mm:ss.SSS} [%-16thread] %.-5level + %-36.36logger [%X{User} %X{RemoteHost} %X{RequestId} %X{Method} + %X{Path}] - %msg%n</pattern> + </encoder> + </appender> + <appender name="asyncCDPServer" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="CDPServer" /> + </appender> + + <!-- CDP Coordinator Appender. This appender is used to record Coordinator + related logging events. The Coordinator logger and appender are specializations + of the CDP application root logger and appender. This can be used to segregate + Coordinator events from other components, or it can be eliminated to record + these events as part of the application root log. --> + <appender name="CDPCoordinator" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/cdp-coordinator.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/cdp-coordinator.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - + %msg%n"</pattern> --> + <pattern>%d{MM/dd-HH:mm:ss.SSS} [%-16thread] %.-5level + %-36.36logger - %msg%n</pattern> + </encoder> + </appender> + <appender name="asyncCDPCoordinator" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="CDPCoordinator" /> + </appender> + + <!-- CDP Policy Appender. This appender is used to record Policy engine + related logging events. The Policy logger and appender are specializations + of the CDP application root logger and appender. This can be used to segregate + Policy engine events from other components, or it can be eliminated to record + these events as part of the application root log. --> + <appender name="CDPPolicy" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${logDirectory}/cdp-policy.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/cdp-policy.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <!-- <pattern>"%d{HH:mm:ss.SSS} [%thread] %-5level %logger{1024} - + %msg%n"</pattern> --> + <pattern>%d{MM/dd-HH:mm:ss.SSS} [%-16thread] %.-5level + %-36.36logger - %msg%n</pattern> + </encoder> + </appender> + <appender name="asyncCDPPolicy" class="ch.qos.logback.classic.AsyncAppender"> + <queueSize>256</queueSize> + <appender-ref ref="CDPPolicy" /> + </appender> + <appender name="CommandExecutor" + class="ch.qos.logback.core.rolling.RollingFileAppender"> + <file>${debugLogDirectory}/appc-debug.log</file> + <rollingPolicy + class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy"> + <fileNamePattern>${logDirectory}/command-executor.%i.log.zip + </fileNamePattern> + <minIndex>1</minIndex> + <maxIndex>9</maxIndex> + </rollingPolicy> + <triggeringPolicy + class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy"> + <maxFileSize>5MB</maxFileSize> + </triggeringPolicy> + <encoder> + <!--<Pattern> + %d{yyyy-MM-dd'T'HH:mm:ss.SSSZ}|%X{RequestID}|%X{ServiceInstanceID}|%thread|%X{ServerName}|%X{ServiceName}|%X{UUID}|%-5.5p|%X{Severity}|%X{ServerIPAddress}|%X{Server}|%X{IPAddress}|[%c{3}]|%X{Timer}| - %msg%n + </Pattern>--> + <Pattern> + %d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%t|%X{ServiceName} - %X{bundle.id} - %X{bundle.name} - %X{bundle.version}|%X{InstanceUUID}|%-5.5p|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|[%c{3}]|%m%n + </Pattern> + </encoder> + </appender> + + <logger name="org.onap.appc" level="DEBUG" additivity="false"> + <appender-ref ref="CommandExecutor" /> + </logger> + + <!-- ============================================================================ --> + <!-- CDP loggers --> + <!-- ============================================================================ --> + <logger name="com.att.cdp" level="info" additivity="false"> + <appender-ref ref="asyncCDP" /> + </logger> + <logger name="com.att.cdp.security" level="info" additivity="false"> + <appender-ref ref="asyncCDPSecurity" /> + </logger> + <logger name="com.att.cdp.perf" level="info" additivity="false"> + <appender-ref ref="asyncCDPPerformance" /> + </logger> + <logger name="com.att.cdp.server" level="debug" additivity="false"> + <appender-ref ref="asyncCDPServer" /> + </logger> + <logger name="com.att.cdp.coordinator" level="info" additivity="false"> + <appender-ref ref="asyncCDPCoordinator" /> + </logger> + <logger name="com.att.cdp.policy" level="info" additivity="false"> + <appender-ref ref="asyncCDPPolicy" /> + </logger> + + <!-- The OpenStack connector logger --> + <logger name="os" level="debug" additivity="false"> + <appender-ref ref="asyncCDPServer" /> + </logger> + + <root level="WARN"> + <appender-ref ref="STDOUT" /> + </root> + +</configuration> |